Update of /cvsroot/monetdb/MonetDB5/src/optimizer
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv12484/src/optimizer
Modified Files:
opt_commonTerms.mx opt_deadcode.mx opt_emptySet.mx
opt_evaluate.mx opt_macro.mx opt_mergetable.mx opt_reduce.mx
Log Message:
added lots of small cleanup fixes to the optimizers (ie if we replace
the stmt's, we need to free all stmts of the old array, ie also those
after vtop)
Index: opt_deadcode.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB5/src/optimizer/opt_deadcode.mx,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- opt_deadcode.mx 26 Dec 2007 14:31:11 -0000 1.29
+++ opt_deadcode.mx 30 Dec 2007 18:14:22 -0000 1.30
@@ -86,7 +86,7 @@
static int
OPTdeadcodeImplementation(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
{
- int i, k, se,limit;
+ int i, k, se,limit, slimit;
InstrPtr p=0, *old= mb->stmt;
int actions = 0;
@@ -103,6 +103,7 @@
#endif
limit= mb->stop;
+ slimit = mb->ssize;
newMalBlkStmt(mb, mb->ssize); /* a new statement stack */
pushInstruction(mb, old[0]);
@@ -139,11 +140,13 @@
/* we may have uncovered new use-less operations */
if( actions)
i= OPTdeadcodeImplementation(mb, stk, pci);
-
#ifdef DEBUG_OPT_DEAD
stream_printf(GDKout,"LEAVING DEAD CODE ELIMINATION\n");
printFunction(GDKout,mb,LIST_MAL_ALL);
#endif
+ for(; i<slimit; i++)
+ if( old[i])
+ freeInstruction(old[i]);
GDKfree(old);
return actions+i;
}
Index: opt_emptySet.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB5/src/optimizer/opt_emptySet.mx,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -d -r1.43 -r1.44
--- opt_emptySet.mx 26 Dec 2007 14:31:11 -0000 1.43
+++ opt_emptySet.mx 30 Dec 2007 18:14:22 -0000 1.44
@@ -271,6 +271,9 @@
}
}
}
+ for(; i<slimit; i++)
+ if( old[i])
+ freeInstruction(old[i]);
GDKfree(old);
if( actions) {
clrAllTypes(mb); /* force a complete resolve */
Index: opt_mergetable.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB5/src/optimizer/opt_mergetable.mx,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- opt_mergetable.mx 21 Dec 2007 15:29:40 -0000 1.27
+++ opt_mergetable.mx 30 Dec 2007 18:14:22 -0000 1.28
@@ -1065,7 +1065,7 @@
{
InstrPtr *old=0, q, r;
mat_t *mat;
- int oldtop, fm, i, k, m, mtop=0, tpe;
+ int oldtop, fm, i, k, m, mtop=0, tpe, slimit;
int size, match, actions=0;
#ifdef DEBUG_OPT_MERGETABLE
@@ -1073,6 +1073,7 @@
#endif
old = mb->stmt;
oldtop= mb->stop;
+ slimit = mb->ssize;
size = (mb->stop * 1.2 < mb->ssize)? mb->ssize:(int)(mb->stop * 1.2);
mb->stmt = (InstrPtr *) GDKzalloc(size * sizeof(InstrPtr));
mb->ssize = size;
@@ -1357,6 +1358,9 @@
if (p->argc >= 2)
propagateProp(mb, p, getArg(p,1));
}
+ for(; i<slimit; i++)
+ if( old[i])
+ freeInstruction(old[i]);
GDKfree(old);
@-
As a final optimization, we could remove the mal.new definitions,
Index: opt_macro.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB5/src/optimizer/opt_macro.mx,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- opt_macro.mx 27 Dec 2007 17:27:08 -0000 1.27
+++ opt_macro.mx 30 Dec 2007 18:14:22 -0000 1.28
@@ -241,16 +241,14 @@
/* add all variables of the new block to the target environment */
for (n = 0; n < mc->vtop; n++) {
- if(isExceptionVariable(mc->var[n]->name) ){
+ if (isExceptionVariable(mc->var[n]->name)) {
nv[n] =
newVariable(mb,GDKstrdup(mc->var[n]->name),TYPE_str);
/* keep the properties */
getVar(mb,nv[n])->isudftype= getVar(mc,n)->isudftype;
getVar(mb,nv[n])->isused= getVar(mc,n)->isused;
- } else
- if( isTypeVar(mc,n) )
+ } else if (isTypeVar(mc,n))
nv[n] = newTypeVariable(mb,getVarType(mc,n));
- else
- if (mc->var[n]->isaconstant ){
+ else if (mc->var[n]->isaconstant) {
nv[n] = cpyConstant(mb,getVar(mc,n));
} else {
nv[n] = newTmpVariable(mb, getVarType(mc, n));
Index: opt_evaluate.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB5/src/optimizer/opt_evaluate.mx,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- opt_evaluate.mx 9 Dec 2007 16:21:10 -0000 1.11
+++ opt_evaluate.mx 30 Dec 2007 18:14:22 -0000 1.12
@@ -101,7 +101,7 @@
env= prepareMALstack(mb);
env->keepAlive= TRUE;
- do{
+ do {
again = 0;
limit = mb->stop;
nxt= first;
@@ -118,16 +118,17 @@
if( j && p->retc== 1 && p->barrier == 0 &&
getLastUpdate(mb,getArg(p,0)) == i &&
!isUnsafeFunction(p)){
- msg= reenterMAL(c,mb,i,i+1,env,0,0);
+ msg = reenterMAL(c,mb,i,i+1,env,0,0);
#ifdef DEBUG_OPT_CX
stream_printf(GDKout,"result:%s\n",msg==MAL_SUCCEED?"ok":msg);
#endif
- if( msg == MAL_SUCCEED){
+ if (msg == MAL_SUCCEED){
@-
The last assignment of a constant expression turns the variable into
a constant itself.
@c
isConstant(mb,getArg(p,0))= TRUE;
+ setVarCleanup(mb,getArg(p,0))= FALSE;
setFixed(mb,getArg(p,0));
getConstant(mb,getArg(p,0)) =
env->stk[getArg(p,0)];
env->stk[getArg(p,0)].vtype= TYPE_int;
/* no garbage */
@@ -156,7 +157,6 @@
}
first = nxt;
} while( again );
- clearStack(env); /* garbage collect */
freeStack(env);
c->itrace= debugstate;
return 1;
Index: opt_reduce.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB5/src/optimizer/opt_reduce.mx,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- opt_reduce.mx 28 Dec 2007 21:29:12 -0000 1.16
+++ opt_reduce.mx 30 Dec 2007 18:14:22 -0000 1.17
@@ -104,7 +104,7 @@
(void)stk;
(void) p;
- vars = (int *) alloca(mb->vtop * sizeof(int));
+ 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));
@@ -124,17 +124,21 @@
}
/* build the alias table */
for (i = 0; i < mb->vtop; i++) {
- if ( used[i]==0 ){
+ if (used[i] == 0){
clearVariable(mb, i);
continue;
}
+
+ /* valgrind finds a leak when we move these variable
+ record pointers around. */
if (i>cnt) {
- VarRecord *t = mb->var[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;
Index: opt_commonTerms.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB5/src/optimizer/opt_commonTerms.mx,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- opt_commonTerms.mx 26 Dec 2007 14:31:11 -0000 1.23
+++ opt_commonTerms.mx 30 Dec 2007 18:14:22 -0000 1.24
@@ -98,7 +98,7 @@
InstrPtr p, q;
int actions = 0;
int filter[1024];
- int *mask,*alias,limit;
+ int *mask,*alias,limit, slimit;
InstrPtr *old;
int c;
@@ -114,6 +114,7 @@
setLifespan(mb);
old = mb->stmt;
limit = mb->stop;
+ slimit = mb->ssize;
newMalBlkStmt(mb, mb->ssize); /* a new statement stack */
for ( n= i = 0; i < limit; i++) {
p = old[i];
@@ -231,6 +232,9 @@
}
filter[c ]= 1;
}
+ for(; i<slimit; i++)
+ if( old[i])
+ freeInstruction(old[i]);
GDKfree(old);
return actions;
}
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Monetdb-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-checkins