Changeset: e082d1a6e22a for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=e082d1a6e22a Modified Files: monetdb5/scheduler/mut_pack.c monetdb5/scheduler/mut_pack.h monetdb5/scheduler/mut_policy.c monetdb5/scheduler/mut_select.c Branch: mutation Log Message:
Another round - the policy will apply the mutation against expensive target then tries to push the mat.packs down the plan - mUt_pack will shuffle mat.pack instructions until it hits a target for mutation. -deadcode is eliminated diffs (truncated from 693 to 300 lines): diff --git a/monetdb5/scheduler/mut_pack.c b/monetdb5/scheduler/mut_pack.c --- a/monetdb5/scheduler/mut_pack.c +++ b/monetdb5/scheduler/mut_pack.c @@ -26,7 +26,8 @@ #include "mut_pack.h" #include "mut_util.h" #include "opt_prelude.h" -#include "opt_support.h" +#include "opt_deadcode.h" +#include "opt_garbageCollector.h" /* * A mat.pack propagation aims at simply replacing the pack with the next @@ -59,13 +60,24 @@ validswitch(InstrPtr p, InstrPtr q) return 1; } +static int +nextUsage(InstrPtr *old, int start, int limit, int mvar){ + int i; + InstrPtr p; + for( i = start; i< limit; i++){ + p= old[i]; + if( getArgPos(p,mvar) >= p->retc) + return i; + } + return 0; +} + int mutationPack(Client cntxt, Mutant m){ MalBlkPtr mb = m->src; MalStkPtr stk= m->stk; - int pc = m->target, i, j, mvar, limit, packpc=0, pos=0; - int newtarget1 = 0, newtarget2= 0; - InstrPtr p=0, *old= mb->stmt, q, newpack = 0, newpack1=0, newpack2 = 0; + int pc = m->target, i, j, mvar, limit, pos=0; + InstrPtr p=0, *old= mb->stmt, q, newpack=0, newpack1=0, newpack2 = 0; int profiler=0, modified= 0; (void) cntxt; @@ -74,207 +86,225 @@ mutationPack(Client cntxt, Mutant m){ return -1; pushInstruction(mb,old[0]);//needed for debugging + // replace a single (!) mat.pack // first phase, see if we need to undo a bat.partition mvar = -1; for (i = 1; i < limit; i++) { p= old[i]; if ( i == pc){ - if ( m->stk->stksize < mb->vtop + p->argc) + // we found the target + if ( m->stk->stksize < mb->vtop + p->argc){ + pushInstruction(mb,p); continue; + } + old[i] = 0; + q= old[i+1]; + newpack = p; mvar = getArg(p,0); - DEBUG_MULTICORE mnstr_printf(cntxt->fdout,"#MUTATIONPACK move %d ",pc); // move ahead to first candidate for consolidation - for(i++ ; i < limit && validswitch(p,old[i]); i++){ - old[pc] = old[i]; - old[i] = p; - pc = i; + if ( validswitch(p,q) ){ + DEBUG_MULTICORE { + mnstr_printf(cntxt->fdout,"#MUTATIONPACK SWITCH %d\n",i); + printInstruction(cntxt->fdout,mb,0,q,LIST_MAL_DEBUG); + printInstruction(cntxt->fdout,mb,0,p,LIST_MAL_DEBUG); + } + pushInstruction(mb,q); + old[i+1]= p; + pc = i+1; + continue; } - DEBUG_MULTICORE{ - mnstr_printf(cntxt->fdout," to %d\n",i-1); - printInstruction(cntxt->fdout,mb,0,old[i],LIST_MAL_ALL); + + DEBUG_MULTICORE { + mnstr_printf(cntxt->fdout,"#MUTATIONPACK MORPH %d\n",i); + printInstruction(cntxt->fdout,mb,0,newpack,LIST_MAL_DEBUG); + printInstruction(cntxt->fdout,mb,0,q,LIST_MAL_DEBUG); } - packpc = pc; - newpack = p; - old[pc]= 0; - - q = old[i]; - if (getModuleId(q) == batRef && getFunctionId(q) == partitionRef && getArgPos(q,mvar) >=0){ + if( getModuleId(q) == batRef && getFunctionId(q) == partitionRef && getArgPos(q,mvar) > 0){ // we bounced upon a partition over a packed variable // this means we replace the partitions by the matpack components + // This would be sufficient for this sequence + // Beware that a mat.pack can be used multiple times int partitions = getVarConstant(mb,getArg(q,2)).val.ival; DEBUG_MULTICORE mnstr_printf(cntxt->fdout,"#MUTATIONPACK PARTITION %d %d partitions %d\n",pc,i,partitions); - for(j =i; j< limit; j++) - if (getModuleId(q= old[j]) == batRef && getFunctionId(q) == partitionRef && getArgPos(q,mvar) >=0){ + for(j = i+1; j< limit; j++) + if ((q=old[j]) && getModuleId(q) == batRef && getFunctionId(q) == partitionRef && getArgPos(q,mvar) >=0){ partitions --; - if ( partitions == 0 && p->argc > p->retc){ - getArg(p,0)= getArg(q,0); - old[j] = p; + DEBUG_MULTICORE{ + mnstr_printf(cntxt->fdout,"Partition step %d\n",partitions); + printInstruction(cntxt->fdout,mb,0,q,LIST_MAL_DEBUG); + printInstruction(cntxt->fdout,mb,0,newpack,LIST_MAL_DEBUG); + } + if ( partitions == 0 && newpack->argc > newpack->retc){ + getArg(newpack,0)= getArg(q,0); freeInstruction(q); + old[j] =0; + pushInstruction(mb,newpack); } else - if ( partitions > 0 && p->argc > p->retc){ + if ( partitions > 0 && newpack->argc > newpack->retc){ + // introduce alias clrFunction(q); q->argc= q->retc; - q = pushArgument(mb, q, getArg(p,1)); - delArgument(p,1); + q = pushArgument(mb, q, getArg(newpack,1)); + pushInstruction(mb,q); + delArgument(newpack,1); } else{ // inject an empty partition clrFunction(q); - q = pushArgument(mb,q,newTmpVariable(mb,getArgType(mb,q,0))); - stk->stk[getArg(q,0)].vtype= getVarGDKType(mb,getArg(q,0)); - } - packpc = 0; - newpack = 0; - } - modified++; - } - m->comment = GDKstrdup("mutationPack"); - } - } - - DEBUG_MULTICORE{ - mnstr_printf(cntxt->fdout,"#MUTATIONPACK mvar %d packpc %d newpack %s\n", mvar,packpc, (newpack?"available" : "")); - if( newpack) - printInstruction(cntxt->fdout,mb,0,newpack,LIST_MAL_ALL); - } - - // second phase, replace matpack with its successor - for (i = 1; i < limit; i++) - if ( (p= old[i])){ - if (newpack && (pos = getArgPos(p, mvar)) >=0 ) - { - profiler = mb->profiler[i].trace; - if (getModuleId(p) == algebraRef) - { - if (getFunctionId(p) == joinRef || getFunctionId(p)== leftjoinRef || getFunctionId(p) == subselectRef || getFunctionId(p) == thetasubselectRef){ - DEBUG_MULTICORE mnstr_printf(cntxt->fdout,"#MUTATIONPACK [*JOIN][[THETA]SUBSELECT] \n"); - newpack1 = copyInstruction(newpack); - getArg(newpack1,0) = getArg(p,0); - setArgType(mb, newpack1, 0, getArgType(mb,p,0)); - if( getFunctionId(p) == joinRef ){ - newpack2 = copyInstruction(newpack); - getArg(newpack2,0) = getArg(p,1); - setArgType(mb, newpack2,0, getArgType(mb,p,1)); - } - - for( j= newpack->retc; j <newpack->argc; j++){ - q= copyInstruction(p); - getArg(q,getArgPos(q,mvar)) = getArg(newpack,j); - getArg(q,0) = newTmpVariable(mb, getArgType(mb, q, 0)); - stk->stk[getArg(q,0)].vtype= getVarGDKType(mb,getArg(q,0)); - getArg(newpack1,j)= getArg(q,0); - if ( newpack2){ - getArg(q,1) = newTmpVariable(mb, getArgType(mb, q, 1)); - stk->stk[getArg(q,1)].vtype= getVarGDKType(mb,getArg(q,1)); - getArg(newpack2,j)= getArg(q,1); - } - pushInstruction(mb,q); - mb->profiler[mb->stop-1].trace = profiler; - } - if ( pos == 2 && getFunctionId(p) == subselectRef) - setFunctionId(newpack1, putName("mergepack",9)); - pushInstruction(mb, newpack1); - newtarget1 = mb->stop-1; - if ( newpack2){ - pushInstruction(mb, newpack2); - newtarget2 = mb->stop-1; - } - newpack1 = 0; - newpack2 = 0; - modified++; - continue; - } - } - if( getModuleId(p) == sqlRef && - (getFunctionId(p) == subdeltaRef || getFunctionId(p) == projectdeltaRef)){ - DEBUG_MULTICORE mnstr_printf(cntxt->fdout,"#MUTATIONPACK [PROJECT][SUB]DELTA \n"); - getArg(newpack,0) = getArg(p,0); - newpack1 = copyInstruction(newpack); - - for( j= newpack->retc; j <newpack->argc; j++){ - q= copyInstruction(p); - getArg(q,getArgPos(q,mvar)) = getArg(newpack,j); - getArg(newpack1,j)= getArg(q,0) = newTmpVariable(mb, getArgType(mb, p, 0)); + q = pushArgument(mb,q,newTmpVariable(mb,getArgType(mb,newpack,0))); + setVarFixed(mb, getArg(q, q->argc-1)); stk->stk[getArg(q,0)].vtype= getVarGDKType(mb,getArg(q,0)); pushInstruction(mb,q); - mb->profiler[mb->stop-1].trace = profiler; } - if ( getArgType(mb,newpack1,0) == TYPE_oid) - setFunctionId(newpack1, putName("mergepack",9)); - else - setFunctionId(newpack1, putName("pack",4)); - pushInstruction(mb, newpack1); - newtarget1 = mb->stop-1; - modified++; - continue; - } - if( getModuleId(p) == matRef && (getFunctionId(p) == packRef || getFunctionId(p) == mergepackRef) && getFunctionId(newpack) == getFunctionId(p)){ - DEBUG_MULTICORE mnstr_printf(cntxt->fdout,"#MUTATIONPACK [MERGE]PACK\n"); - delArgument(p,pos); - for( j = newpack->retc; j < newpack->argc; j++) - p = setArgument(mb, p, pos, getArg(newpack,j)); - pushInstruction(mb, p); + } modified++; + i++; continue; - } - if ( i == packpc+1 && newpack){ - pushInstruction(mb, newpack); - newpack = 0; - } - pushInstruction(mb, p); - } else - if ( newpack && packpc == i-1 && getArgPos(p,mvar) < 0){ - pushInstruction(mb,newpack); - pushInstruction(mb,p); - modified++; - } else - // handle non-partitioned operators + } else + if ((pos = getArgPos(q, mvar)) >= q->retc ) + { + if (getModuleId(q) == algebraRef) + { + profiler = mb->profiler[i].trace; + if (getFunctionId(q) == joinRef || getFunctionId(q)== leftjoinRef || getFunctionId(q) == subselectRef || getFunctionId(q) == thetasubselectRef){ + DEBUG_MULTICORE { + mnstr_printf(cntxt->fdout,"#MUTATIONPACK [*JOIN][[THETA]SUBSELECT] %d\n",i); + printInstruction(cntxt->fdout,mb,0,newpack,LIST_MAL_DEBUG); + printInstruction(cntxt->fdout,mb,0,q,LIST_MAL_DEBUG); + } + newpack1 = copyInstruction(newpack); + getArg(newpack1,0) = getArg(q,0); + setArgType(mb, newpack1, 0, getArgType(mb,q,0)); + if( getFunctionId(q) == joinRef ){ + newpack2 = copyInstruction(newpack); + getArg(newpack2,0) = getArg(q,1); + setArgType(mb, newpack2,0, getArgType(mb,q,1)); + } + + for( j= newpack->retc; j <newpack->argc; j++){ + q= copyInstruction(q); + getArg(q,0) = newTmpVariable(mb, getArgType(mb, q, 0)); + stk->stk[getArg(q,0)].vtype= getVarGDKType(mb,getArg(q,0)); + getArg(q,pos) = getArg(newpack,j); + getArg(newpack1,j)= getArg(q,0); + if ( newpack2){ + getArg(q,1) = newTmpVariable(mb, getArgType(mb, q, 1)); + stk->stk[getArg(q,1)].vtype= getVarGDKType(mb,getArg(q,1)); + getArg(newpack2,j)= getArg(q,1); + } + pushInstruction(mb,q); + mb->profiler[mb->stop-1].trace = profiler; + } + if ( pos == 2 && getFunctionId(q) == subselectRef) + setFunctionId(newpack1, putName("mergepack",9)); + pushInstruction(mb, newpack1); + if ( newpack2){ + pushInstruction(mb, newpack2); + } + modified++; + i++; + // if the target variable is used more often then we should retain the pack + if( nextUsage(old,i+1,limit,mvar)) + pushInstruction(mb,newpack); + continue; + } + } else + if( getModuleId(q) == sqlRef && + (getFunctionId(q) == subdeltaRef || getFunctionId(q) == projectdeltaRef)){ + int tpe = getTailType(getArgType(mb,q,0)); + profiler = mb->profiler[i].trace; _______________________________________________ checkin-list mailing list checkin-list@monetdb.org http://mail.monetdb.org/mailman/listinfo/checkin-list