📄 opt_strengthreduction.c
字号:
#line 78 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_strengthReduction.mx"#include "mal_config.h"#include "opt_strengthReduction.h"#include "mal_interpreter.h" /* for showErrors() */#line 91 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_strengthReduction.mx"static intSRoverwritten(InstrPtr p, int varid){ int i; for (i = p->retc; i < p->argc; i++) if (getArg(p, i) == varid) return 1; return 0;}static intisNewSource(InstrPtr p) { str mp= getModuleId(p); if( mp == calcRef) return 1; if( mp == batcalcRef) return 1; if( mp == strRef) return 1; if( mp == batstrRef) return 1; if( mp == getName("array",5)) return 1; if( mp == getName("url",3)) return 1; if( mp == getName("daytime",7)) return 1; if( mp == getName("day",3)) return 1; if( mp == getName("date",4)) return 1; if( mp == getName("time",4)) return 1; if( mp == getName("tzone",5)) return 1; if( mp == getName("color",4)) return 1; if( mp == getName("batcolor",8)) return 1; if( mp == getName("blob",4)) return 1; return 0;}static intOPTstrengthReductionImplementation(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci){ int i, j = 0, k, se= FALSE; InstrPtr p; int bk, ik, blk, blkbegin, blkexit, actions = 0; InstrPtr *before, *within; (void) pci; (void) stk; /* to fool compilers */ before = (InstrPtr *) alloca((mb->ssize + 1) * sizeof(InstrPtr)); within = (InstrPtr *) alloca((mb->ssize + 1) * sizeof(InstrPtr)); bk = 0; ik = 0; blk = 0; blkexit= blkbegin = 0; for (i = 0; i < mb->stop; i++) before[i] = within[i] = 0; before[bk++] = getInstrPtr(mb, 0); /* to become a factory */ setLifespan(mb); for (i = 1; i < mb->stop - 1; i++) { p = getInstrPtr(mb, i); if (blockStart(p)) { if (blkbegin == 0){ if( isLoopBarrier(mb,i) ){ blkbegin = i; blkexit = getBlockExit(mb,i); }#ifdef DEBUG_OPT_STRENGTHREDUCTION stream_printf(GDKout, "check block %d-%d\n", blkbegin, blkexit);#endif } within[ik++] = p; blk++; continue; } if (blockExit(p)) { blk--; if (blk == 0) blkexit= blkbegin = 0; /* move the saved instruction into place */#ifdef DEBUG_OPT_STRENGTHREDUCTION stream_printf(GDKout, "combine both %d %d\n", bk, ik);#endif for (k = 0; k < ik; k++) before[bk++] = within[k]; ik = 0; before[bk++] = p; continue; }#line 175 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_strengthReduction.mx" if( blkexit == 0) { within[ik++] = p; continue; }#line 182 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_strengthReduction.mx" if ( p->barrier != 0){ within[ik++] = p; continue; }#line 189 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_strengthReduction.mx" if( !isNewSource(p) ) { within[ik++] = p; continue; }#line 197 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_strengthReduction.mx" for (j = ik-1; j > 0; j--) { InstrPtr q = within[j]; for (k = 0; k < q->retc; k++) if (SRoverwritten(p, getArg(q, k))) { se = TRUE;#ifdef DEBUG_OPT_STRENGTHREDUCTION stream_printf(GDKout, "variable is set in loop %d\n", getArg(p, k));#endif goto noreduction; } }#line 213 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_strengthReduction.mx" for (k = 0; k < p->retc; k++) if ( getVar(mb, getArg(p, k))->beginLifespan <= blkbegin || getVar(mb, getArg(p, k))->endLifespan >= blkexit) { se = TRUE;#ifdef DEBUG_OPT_STRENGTHREDUCTION stream_printf(GDKout, "variable may not be used out %d\n", getArg(p, k));#endif goto noreduction; } noreduction:#ifdef DEBUG_OPT_STRENGTHREDUCTION stream_printf(GDKout,"move %d to stack %s\n", i, (se ?"within":"before")); printInstruction(GDKout, mb, p, LIST_MAL_ALL);#endif if (blkexit && se == FALSE && !hasSideEffects(p, TRUE) ) before[bk++] = p; else within[ik++] = p; } actions += ik; for (k = 0; k < ik; k++) before[bk++] = within[k]; before[bk++] = getInstrPtr(mb, i); GDKfree(mb->stmt); mb->stmt = (InstrPtr *) GDKzalloc((mb->ssize) * sizeof(InstrPtr)); mb->stop = 0;#ifdef DEBUG_OPT_STRENGTHREDUCTION stream_printf(GDKout,"stop= %d bk=%d\n",mb->stop,bk);#endif for (i = 0; i < bk; i++) if( before[i]) pushInstruction(mb, before[i]); return actions;}#line 253 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_strengthReduction.mx"#line 251 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_strengthReduction.mx"/* #define _DEBUG_OPTIMIZER_*/str OPTstrengthReduction(MalBlkPtr mb, MalStkPtr stk, InstrPtr p){ str modnme; str fcnnme; Module scope=NULL; Symbol s= NULL; lng clk= GDKusec(); int actions = 0; optimizerInit(); if( p ) removeInstruction(mb, p);#ifdef _DEBUG_OPTIMIZER_ stream_printf(GDKout,"apply strengthReduction\n"); printFunction(GDKout,mb,LIST_MAL_ALL);#endif if( p && p->argc > 1 && getFunctionId(p) != multiplexRef){#ifdef _DEBUG_OPTIMIZER_ stream_printf(GDKout,"locate function strengthReduction\n");#endif if( getArgType(mb,p,1) != TYPE_str || getArgType(mb,p,2) != TYPE_str || !isConstant(mb,getArg(p,1)) || !isConstant(mb,getArg(p,2)) ) { char buf[1024]; snprintf(buf,1024, "Optimizer requires constant string arguments\n"); throw(MAL, "optimizer.strengthReduction",buf); } if( stk != 0){ modnme= (str)getArgValue(stk,p,1); fcnnme= (str)getArgValue(stk,p,2); } else { modnme= getArgDefault(mb,p,1); fcnnme= getArgDefault(mb,p,2); } scope = findModule(MCgetClient()->nspace,putName(modnme,strlen(modnme)) ); if( scope) s= findSymbolInModule(scope,putName(fcnnme,strlen(fcnnme))); if( s == NULL) { char buf[1024]; snprintf(buf,1024, "Could not find %s.%s\n",modnme,fcnnme); throw(MAL, "optimizer.strengthReduction",buf); }#ifdef _DEBUG_OPTIMIZER_ stream_printf(GDKout,"strengthReduction %s %d\n",modnme,fcnnme);#endif mb = s->def; stk= 0; } if( mb->errors ) return MAL_SUCCEED; addtoMalBlkHistory(mb); actions= OPTstrengthReductionImplementation(mb,stk,p);#ifdef _DEBUG_OPTIMIZER_ stream_printf(GDKout,"finished strengthReduction %d\n",actions); printFunction(GDKout,mb,LIST_MAL_ALL);#endif optimizerCheck(mb, "optimizer.strengthReduction", actions, GDKusec() - clk,OPT_CHECK_ALL); return MAL_SUCCEED;}#line 253 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_strengthReduction.mx"#line 255 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_strengthReduction.mx"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -