📄 opt_constantexpression.c
字号:
#line 63 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_constantExpression.mx"#include "mal_config.h"#include "opt_constantExpression.h"#include "opt_aliases.h"static intOPTallConstant(MalBlkPtr mb, InstrPtr p){ int i; for( i= p->retc; i < p->argc; i++) if( isConstant(mb, getArg(p,i)) == FALSE) return FALSE; return ( getModuleId(p) == calcRef || getModuleId(p) == mmathRef);}static intOPTconstantExpressionImplementation(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci){ InstrPtr p; int first=0, nxt, i, j, k, limit, done=0, again=0; Client c= MCgetClient(); MalStkPtr env; (void) stk; (void) pci;#ifdef DEBUG_OPT_CX stream_printf(GDKout,"Constant expression optimizer started\n");#endif do{ again = 0; limit = mb->stop; env= prepareMALstack(mb); env->keepAlive= TRUE; nxt= first; for (k=i= first ; i < limit; i++) { p = getInstrPtr(mb,i); if( p->argc - p->retc > 0 ) j = OPTallConstant(mb,p); else j = 0; if(j && nxt == first) nxt=i;#ifdef DEBUG_OPT_CX stream_printf(GDKout,"Constants:%d\n",j); printInstruction(GDKout, mb, p, LIST_OPT_ALL); #endif if( j && p->retc== 1 && p->barrier == 0 && getLastUpdate(mb,getArg(p,0)) == i && reenterMAL(c,mb,i,i+1,env,0,0) == MAL_SUCCEED){#line 114 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_constantExpression.mx" isConstant(mb,getArg(p,0))= TRUE; setFixed(mb,getArg(p,0)); getVarConstant(mb,getArg(p,0)) = env->stk[getArg(p,0)]; env->stk[getArg(p,0)].vtype= TYPE_int; /* no garbage */ freeInstruction(p);#ifdef DEBUG_OPT_CX stream_printf(GDKout,"Evaluated new constant=%d\n",getArg(p,0));#endif done++; again++; } else mb->stmt[k++]=p; } if( k != mb->stop){ mb->stop= k; setLifespan(mb); /* the lastUpdate property changes */ } else mb->stop= k; first= nxt; } while( again ); clearStack(env); /* garbage collect */ freeStack(env); return 1;}#line 141 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_constantExpression.mx"#line 139 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_constantExpression.mx"/* #define _DEBUG_OPTIMIZER_*/str OPTconstantExpression(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 constantExpression\n"); printFunction(GDKout,mb,LIST_MAL_ALL);#endif if( p && p->argc > 1 && getFunctionId(p) != multiplexRef){#ifdef _DEBUG_OPTIMIZER_ stream_printf(GDKout,"locate function constantExpression\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.constantExpression",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.constantExpression",buf); }#ifdef _DEBUG_OPTIMIZER_ stream_printf(GDKout,"constantExpression %s %d\n",modnme,fcnnme);#endif mb = s->def; stk= 0; } if( mb->errors ) return MAL_SUCCEED; addtoMalBlkHistory(mb); actions= OPTconstantExpressionImplementation(mb,stk,p);#ifdef _DEBUG_OPTIMIZER_ stream_printf(GDKout,"finished constantExpression %d\n",actions); printFunction(GDKout,mb,LIST_MAL_ALL);#endif optimizerCheck(mb, "optimizer.constantExpression", actions, GDKusec() - clk,OPT_CHECK_ALL); return MAL_SUCCEED;}#line 141 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_constantExpression.mx"#line 143 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/optimizer/opt_constantExpression.mx"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -