Changeset: c9012ea1987d for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=c9012ea1987d
Modified Files:
        MonetDB5/src/optimizer/opt_tarantula.mx
Branch: default
Log Message:

Keep track of re-used variables
And make sure they become part of the leg output vector.


diffs (118 lines):

diff -r 394707c186c7 -r c9012ea1987d MonetDB5/src/optimizer/opt_tarantula.mx
--- a/MonetDB5/src/optimizer/opt_tarantula.mx   Mon Aug 23 16:53:50 2010 +0200
+++ b/MonetDB5/src/optimizer/opt_tarantula.mx   Mon Aug 23 22:32:19 2010 +0200
@@ -428,7 +428,7 @@
                        mnstr_printf(cntxt->fdout,"%d, ", output[i]);
                mnstr_printf(cntxt->fdout,"\n");
        }
-       alias= (int*) GDKzalloc(mb->vtop * sizeof(int));
+       alias= (int*) GDKzalloc(2 * mb->vtop * sizeof(int));
 
        snprintf(buf,BUFSIZ,"%s_%d_%d", getFunctionId(getInstrPtr(mb,0)), 
getArg(old[pc],0), idx-old[pc]->retc);
        putName(buf,strlen(buf));
@@ -808,8 +808,7 @@
        int tn=0, ta =0, vtop=0;
        MalBlkPtr *leg;
        char fcn[BUFSIZ];
-       Lifespan span;
-       int *map, top;
+       int *map, *used, top;
        int itop = 0, *input;
        int otop = 0, *output;
        InstrPtr *list;
@@ -826,6 +825,8 @@
     if ( TARnrpeers == 0 )
         TARdiscover(cntxt);
     mal_unset_lock(mal_contextLock,"tarantula.register");
+       OPTDEBUGtarantula
+               printFunction(cntxt->fdout, mb, 0, LIST_MAL_STMT | LIST_MAPI);
 @-
 All tarantula leg code is collected in a separate module
 to ease future distribution and scheduling.
@@ -842,6 +843,7 @@
 
        limit = mb->stop;
        old = mb->stmt;
+       vtop= mb->vtop;
 
        if ( newMalBlkStmt(mb, mb->ssize) < 0){
                GDKfree(leg);
@@ -849,11 +851,19 @@
        }
        pushInstruction(mb, old[0]);
 
-       span = newLifespan(mb);
-       map= (int*) GDKzalloc(2 * mb->vtop * sizeof(int));
-       vtop= mb->vtop;
-       for ( i = 0; i < mb->vtop; i++)
+       map= (int*) GDKzalloc(2 * vtop * sizeof(int));
+       used= (int*) GDKzalloc(2 * vtop * sizeof(int));
+       for ( i = 0; i <2 * vtop; i++)
                map[i] = i;
+       for (i = 1; i < limit; i++) {
+               p = old[i];
+               if ( getModuleId(p) != sqlRef)
+               for( j= p->retc; j<p->argc; j++){
+                       int a= getArg(p,j);
+                       assert(a < vtop);
+                       used[a]++;
+               }
+       }
 
        sig= old[0];
        for (i = 1; i < limit; i++) {
@@ -912,12 +922,20 @@
                                                                input[itop++] = 
getArg(pp,j);
                                                        if (getArg(pp,j) >= 
vtop ) /* new variables are never re-assigned */
                                                                continue;
-                                                       if ( 
getEndLifespan(span, getArg(pp,j)) > i)
-                                                               output[otop++]= 
getArg(pp,j);
                                                }
                                                list[top++] = pp;
                                        }
                                }
+                               /* for all variables assigned, check if they 
are needed outside */
+                               for ( l=0; l< top; l++){
+                                       pp = list[l];
+                                       if ( getModuleId(pp) != sqlRef)
+                                       for ( j = 0; j<pp->retc; j++){
+                                               if (used[getArg(pp,j)] > 1)
+                                                       output[otop++]= 
getArg(pp,j);
+                                       }
+                                       assert(otop < vtop);
+                               }
 @-
 All legs should have the same input/output variable sequence.
 @c
@@ -968,8 +986,6 @@
                                for (k = 0; k < tn; k++)
                                        if (old[j] && old[j]->token != 
REMsymbol)
                                                q =newStmt(leg[k], 
getModuleId(old[j]), getFunctionId(old[j]));
-                       OPTDEBUGtarantula for (k = 0; k < tn; k++)
-                               printFunction(cntxt->fdout, leg[k], 0, 
LIST_MAL_STMT | LIST_MAPI);
                        GDKfree(input);
                        GDKfree(output);
                        GDKfree(list);
@@ -977,8 +993,13 @@
                        continue;
                } 
                wrapup:
-               for ( j=0; j< p->argc; j++)
+               if ( getModuleId(p) != sqlRef)
+               for ( j=0; j< p->argc; j++){
+                       int a= getArg(p,j);
+                       assert(a<vtop);
+                       used[a]--;
                        getArg(p,j)= map[getArg(p,j)];
+               }
                pushInstruction(mb,p);
                if (p->token == ENDsymbol){
                        last= i;
@@ -997,6 +1018,7 @@
        GDKfree(old);
        GDKfree(leg);
        GDKfree(map);
+       GDKfree(used);
        (void) stk;
        return actions;
 }
_______________________________________________
Checkin-list mailing list
Checkin-list@monetdb.org
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to