str OPTorcam(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p){ Symbol t; str msg,mod,fcn; lng clk= GDKusec(); int actions = 0; if( p ==NULL ) return 0; removeInstruction(mb, p); if( p->argc == 3){ mod= getArgDefault(mb,p,1); fcn= getArgDefault(mb,p,2); } else { mod= getArgDefault(mb,p,3); fcn= getArgDefault(mb,p,4); } t= findSymbol(cntxt->nspace, putName(mod, strlen(mod)), fcn); if( t == 0) return 0; msg = MACROvalidate(t->def); if( msg) return msg; if( mb->errors == 0) actions= OPTorcamImplementation(cntxt,mb,stk,p); return optimizerCheck(cntxt,mb, "optimizer.orcam", actions, GDKusec() - clk, OPT_CHECK_ALL); }
str QOTshowFlowGraph(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p) { str fname; str modnme; str fcnnme; Symbol s = NULL; (void) cntxt; if (stk != 0) { modnme = *getArgReference_str(stk, p, 1); fcnnme = *getArgReference_str(stk, p, 2); fname = *getArgReference_str(stk, p, 3); } else { modnme = getArgDefault(mb, p, 1); fcnnme = getArgDefault(mb, p, 2); fname = getArgDefault(mb, p, 3); } s = findSymbol(cntxt->nspace,putName(modnme, strlen(modnme)), putName(fcnnme, strlen(fcnnme))); if (s == NULL) { char buf[1024]; snprintf(buf,1024, "%s.%s", modnme, fcnnme); throw(MAL, "optimizer.showFlowGraph", RUNTIME_OBJECT_UNDEFINED ":%s", buf); } showFlowGraph(s->def, stk, fname); return MAL_SUCCEED; }
str QOTshowPlan(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p) { str modnme; str fcnnme; Symbol s = NULL; if (stk != 0) { modnme = *getArgReference_str(stk, p, 1); fcnnme = *getArgReference_str(stk, p, 2); } else { modnme = getArgDefault(mb, p, 1); fcnnme = getArgDefault(mb, p, 2); } mnstr_printf(cntxt->fdout,"#showPlan()\n"); removeInstruction(mb, p); if( modnme ) { s = findSymbol(cntxt->nspace, putName(modnme, strlen(modnme)), putName(fcnnme, strlen(fcnnme))); if (s == NULL) { char buf[1024]; snprintf(buf,1024, "%s.%s", modnme, fcnnme); throw(MAL, "optimizer.showPlan", RUNTIME_OBJECT_UNDEFINED ":%s", buf); } mb= s->def; } printFunction(cntxt->fdout, mb, 0, LIST_INPUT); return MAL_SUCCEED; }
/* * Display routines */ str MDBlifespan(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p) { Lifespan span; str modnme; str fcnnme; Symbol s = NULL; (void) cntxt; if (stk != 0) { modnme = *getArgReference_str(stk, p, 1); fcnnme = *getArgReference_str(stk, p, 2); } else { modnme = getArgDefault(mb, p, 1); fcnnme = getArgDefault(mb, p, 2); } s = findSymbol(cntxt->nspace, putName(modnme), putName(fcnnme)); if (s == NULL) throw(MAL, "mdb.inspect", RUNTIME_SIGNATURE_MISSING); span = setLifespan(s->def); if( span == NULL) throw(MAL,"mdb.inspect", MAL_MALLOC_FAIL); debugLifespan(cntxt, s->def, span); GDKfree(span); (void) p; (void) stk; return MAL_SUCCEED; }
str OPTsql_append(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p){ str modnme; str fcnnme; str msg= MAL_SUCCEED; Symbol s= NULL; lng t,clk= GDKusec(); int actions = 0; if( p ) removeInstruction(mb, p); OPTDEBUGsql_append mnstr_printf(cntxt->fdout,"=APPLY OPTIMIZER sql_append\n"); if( p && p->argc > 1 ){ if( getArgType(mb,p,1) != TYPE_str || getArgType(mb,p,2) != TYPE_str || !isVarConstant(mb,getArg(p,1)) || !isVarConstant(mb,getArg(p,2)) ) { throw(MAL, "optimizer.sql_append", ILLARG_CONSTANTS); } if( stk != 0){ modnme= *getArgReference_str(stk,p,1); fcnnme= *getArgReference_str(stk,p,2); } else { modnme= getArgDefault(mb,p,1); fcnnme= getArgDefault(mb,p,2); } s= findSymbol(cntxt->nspace, putName(modnme,strlen(modnme)),putName(fcnnme,strlen(fcnnme))); if( s == NULL) { char buf[1024]; snprintf(buf,1024, "%s.%s",modnme,fcnnme); throw(MAL, "optimizer.sql_append", RUNTIME_OBJECT_UNDEFINED ":%s", buf); } mb = s->def; stk= 0; } if( mb->errors ){ /* when we have errors, we still want to see them */ addtoMalBlkHistory(mb,"sql_append"); return MAL_SUCCEED; } actions= OPTsql_appendImplementation(cntxt, mb,stk,p); msg= optimizerCheck(cntxt, mb, "optimizer.sql_append", actions, t=(GDKusec() - clk)); OPTDEBUGsql_append { mnstr_printf(cntxt->fdout,"=FINISHED sql_append %d\n",actions); printFunction(cntxt->fdout,mb,0,LIST_MAL_ALL ); } DEBUGoptimizers mnstr_printf(cntxt->fdout,"#opt_reduce: " LLFMT " ms\n",t); QOTupdateStatistics("sql_append",actions,t); addtoMalBlkHistory(mb,"sql_append"); return msg; }
str QOToptimize(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) { str modnme; str fcnnme; Symbol s; (void) stk; if (stk != 0) { modnme = *getArgReference_str(stk, pci, 1); fcnnme = *getArgReference_str(stk, pci, 2); } else { modnme = getArgDefault(mb, pci, 1); fcnnme = getArgDefault(mb, pci, 2); } s = findSymbol(cntxt->usermodule, putName(modnme), fcnnme); if (s == NULL) throw(MAL, "optimizer.optimize", SQLSTATE(HY002) SEMANTIC_OPERATION_MISSING); removeInstruction(mb, pci); addtoMalBlkHistory(s->def); return optimizeMALBlock(cntxt, s->def); }
str MDBshowFlowGraph(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p) { str fname; str modnme; str fcnnme; Symbol s = NULL; (void)cntxt; if (stk != 0) { if (p->argc == 2) { modnme = fcnnme = NULL; fname = *getArgReference_str(stk, p, 1); } else { modnme = *getArgReference_str(stk, p, 1); fcnnme = *getArgReference_str(stk, p, 2); fname = *getArgReference_str(stk, p, 3); } } else { modnme = getArgDefault(mb, p, 1); fcnnme = getArgDefault(mb, p, 2); fname = getArgDefault(mb, p, 3); } if (modnme != NULL) { s = findSymbol(cntxt->nspace, putName(modnme), putName(fcnnme)); if (s == NULL) { char buf[1024]; snprintf(buf,1024, "Could not find %s.%s\n", modnme, fcnnme); throw(MAL, "mdb.dot", "%s", buf); } showFlowGraph(s->def, stk, fname); } else { showFlowGraph(mb, stk, fname); } return MAL_SUCCEED; }
str MDBinspect(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p) { str modnme; str fcnnme; Symbol s = NULL; (void) cntxt; if (stk != 0) { modnme = *getArgReference_str(stk, p, 1); fcnnme = *getArgReference_str(stk, p, 2); } else { modnme = getArgDefault(mb, p, 1); fcnnme = getArgDefault(mb, p, 2); } s = findSymbol(cntxt->nspace, putName(modnme), putName(fcnnme)); if (s == NULL) throw(MAL, "mdb.inspect", RUNTIME_SIGNATURE_MISSING); return runMALDebugger(cntxt, s); }
int OPTorcamImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p) { MalBlkPtr target= mb; Module s; Symbol t; str mod,fcn; int j; str msg; (void) cntxt; (void) stk; if( p->argc == 3){ mod= getArgDefault(mb,p,1); fcn= getArgDefault(mb,p,2); } else { mod= getArgDefault(mb,p,1); fcn= getArgDefault(mb,p,2); t= findSymbol(cntxt->nspace, putName(mod, strlen(mod)), fcn); if( t == 0) return 0; target= t->def; mod= getArgDefault(mb,p,3); fcn= getArgDefault(mb,p,4); } s = findModule(cntxt->nspace, putName(mod, strlen(mod))); if (s == 0) return 0; if (s->subscope) { j = getSubScope(fcn); for (t = s->subscope[j]; t != NULL; t = t->peer) if (t->def->errors == 0) { if (getSignature(t)->token == FUNCTIONsymbol) { msg =ORCAMprocessor(cntxt, target, t); if( msg) GDKfree(msg); } } } return 1; }
str OPTwrapper (Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p){ str modnme = "(NONE)"; str fcnnme = 0; str msg= MAL_SUCCEED; Symbol s= NULL; lng t,clk= GDKusec(); int i, actions = 0; char optimizer[256]; InstrPtr q; if( p == NULL) throw(MAL, "opt_wrapper", "missing optimizer statement"); snprintf(optimizer,256,"%s", fcnnme = getFunctionId(p)); q= copyInstruction(p); OPTIMIZERDEBUG mnstr_printf(cntxt->fdout,"=APPLY OPTIMIZER %s\n",fcnnme); if( p && p->argc > 1 ){ if( getArgType(mb,p,1) != TYPE_str || getArgType(mb,p,2) != TYPE_str || !isVarConstant(mb,getArg(p,1)) || !isVarConstant(mb,getArg(p,2)) ) { freeInstruction(q); throw(MAL, optimizer, ILLARG_CONSTANTS); } if( stk != 0){ modnme= *getArgReference_str(stk,p,1); fcnnme= *getArgReference_str(stk,p,2); } else { modnme= getArgDefault(mb,p,1); fcnnme= getArgDefault(mb,p,2); } removeInstruction(mb, p); s= findSymbol(cntxt->nspace, putName(modnme,strlen(modnme)),putName(fcnnme,strlen(fcnnme))); if( s == NULL) { freeInstruction(q); throw(MAL, optimizer, RUNTIME_OBJECT_UNDEFINED ":%s.%s", modnme, fcnnme); } mb = s->def; stk= 0; } else if( p ) removeInstruction(mb, p); if( mb->errors ){ /* when we have errors, we still want to see them */ addtoMalBlkHistory(mb,getModuleId(q)); freeInstruction(q); return MAL_SUCCEED; } for ( i=0; codes[i].nme; i++) if ( strcmp(codes[i].nme, optimizer)== 0 ){ actions = (int)(*(codes[i].fcn))(cntxt, mb, stk,0); break; } if ( codes[i].nme == 0){ freeInstruction(q); throw(MAL, optimizer, RUNTIME_OBJECT_UNDEFINED ":%s.%s", modnme, fcnnme); } msg= optimizerCheck(cntxt, mb, optimizer, actions, t=(GDKusec() - clk)); OPTIMIZERDEBUG { mnstr_printf(cntxt->fdout,"=FINISHED %s %d\n",optimizer, actions); printFunction(cntxt->fdout,mb,0,LIST_MAL_DEBUG ); } DEBUGoptimizers mnstr_printf(cntxt->fdout,"#optimizer %-11s %3d actions %5d MAL instructions ("SZFMT" K) " LLFMT" usec\n", optimizer, actions, mb->stop, ((sizeof( MalBlkRecord) +mb->ssize * offsetof(InstrRecord, argv)+ mb->vtop * sizeof(int) /* argv estimate */ +mb->vtop* sizeof(VarRecord) + mb->vsize*sizeof(VarPtr)+1023)/1024), t); QOTupdateStatistics(getModuleId(q),actions,t); addtoMalBlkHistory(mb,getModuleId(q)); freeInstruction(q); return msg; }