Update of /cvsroot/monetdb/MonetDB5/src/mal
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv13502/mal

Modified Files:
        mal_instruction.mx mal_recycle.mx 
Log Message:
Variable trimming is moved into the kernel, because recycle needs it too


Index: mal_recycle.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB5/src/mal/mal_recycle.mx,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -d -r1.39 -r1.40
--- mal_recycle.mx      12 Mar 2008 12:39:02 -0000      1.39
+++ mal_recycle.mx      12 Mar 2008 19:31:45 -0000      1.40
@@ -284,6 +284,7 @@
                                        
BBPdecref(getVarConstant(recycleBlk,i).val.bval,TRUE);
                        recyclerUsedMemory -= recycleBlk->profiler[max].obytes;
                        
removeInstruction(recycleBlk,getInstrPtr(recycleBlk,max));
+                       trimMalVariables(recycleBlk);
                        if (monitorRecycler)
                                fprintf(stderr, "memory=%lld, stop=%d, 
recycled=%d(%d), saved=%d\n",
                                        recyclerUsedMemory, recycleBlk->stop,

Index: mal_instruction.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB5/src/mal/mal_instruction.mx,v
retrieving revision 1.308
retrieving revision 1.309
diff -u -d -r1.308 -r1.309
--- mal_instruction.mx  12 Mar 2008 12:39:00 -0000      1.308
+++ mal_instruction.mx  12 Mar 2008 19:31:44 -0000      1.309
@@ -505,6 +505,7 @@
 mal_export MalBlkPtr getMalBlkMarker(MalBlkPtr mb, str marker);
 mal_export void expandMalBlk(MalBlkPtr mb, int lines);
 mal_export void trimMalBlk(MalBlkPtr mb);
+mal_export void trimMalVariables(MalBlkPtr mb);
 mal_export void moveInstruction(MalBlkPtr mb, int pc, int target);
 mal_export void insertInstruction(MalBlkPtr mb, InstrPtr p, int pc);
 mal_export void removeInstruction(MalBlkPtr mb, InstrPtr p);
@@ -1575,6 +1576,82 @@
        getVar(mb, varid) = NULL;
 }
 
[EMAIL PROTECTED]
+A special action is to reduce the variable space by removing
+all that do not contribute.
[EMAIL PROTECTED]
+void
+trimMalVariables(MalBlkPtr mb)
+{
+       int *vars, *used;
+       int cnt = 0, i, j;
+       InstrPtr q;
+       int actions = 0;
+
+       vars= (int *) alloca(mb->vtop * sizeof(int));
+       used= (int *) alloca(mb->vtop * sizeof(int));
+       memset((char*) vars, 0, mb->vtop * sizeof(int));
+       memset((char*) used, 0, mb->vtop * sizeof(int));
+
+       /* build the use table */
+       for(i=0; i<mb->stop; i++){
+               q= getInstrPtr(mb,i);
+
+               for(j=0; j<q->argc; j++)
+                       used[getArg(q,j)] = 1;
+       }
+       for (i=0; i<mb->ptop; i++) {
+               if (mb->prps[i].var)
+                       used[mb->prps[i].var] = 1;
+       }
+       /* build the alias table */
+       for (i = 0; i < mb->vtop; i++) {
+               if (used[i] == 0){
+                       clearVariable(mb, i);
+                       continue;
+               }
+
+               /* valgrind finds a leak when we move these variable 
+                  record pointers around. */
+               if (i>cnt) {
+                       /* remap temporary variables */
+                       VarRecord *t = mb->var[cnt];
+                       if (isTmpVar(mb,i))
+                               getVarTmp(mb,i) = cnt;
+                       mb->var[cnt] = mb->var[i];
+                       mb->var[i] = t;
+                       t = NULL;
+                       resetVarName(mb,cnt);
+               }
+               vars[i] = cnt;
+               cnt++;
+       }
+#ifdef DEBUG_MAL_INSTR
+       stream_printf(GDKout, "Variable reduction %d -> %d\n", mb->vtop, cnt);
+       for(i=0; i<mb->vtop;i++)
+               stream_printf(GDKout,"map %d->%d\n",i, vars[i]);
+#endif
+
+       /* remap all variable references to their new position. */
+       if (actions) {
+               for (i = 1; i < mb->stop; i++) {
+                       q = getInstrPtr(mb, i);
+                       for (j = 0; j < q->argc; j++)
+                               getArg(q, j) = vars[getArg(q, j)];
+               }
+               for( i=0; i< mb->ptop; i++){
+                       MalProp *p= mb->prps+i;
+
+                       if (p->var)
+                               p->var = vars[p->var];
+               }
+       }
+#ifdef DEBUG_MAL_INSTR
+       stream_printf(GDKout, "After reduction \n");
+       printFunction(GDKout,mb,0);
+#endif
+       mb->vtop = cnt;
+}
 @+ MAL constants
 Constants are stored in the symbol table and referenced
 by a variable identifier.


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Monetdb-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-checkins

Reply via email to