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

Modified Files:
        opt_deadcode.mx opt_macro.mx opt_pushranges.mx opt_reduce.mx 
        opt_remap.mx 
Log Message:
mal_resolve: cleaned up prepost macro 
        as bats could also be a constant we no longer handel the (incorrectly)
        seperate
mal_*/opt_*: ATOMcmp should use GDK types (not mal types)
opt_deadcode: fixed leak
opt_macro/opt_remap: fixed the multiplex push down, ie we can now inline 
multiplex calls

approved some output mostly because of the reintroduced nil values for
        return values of inlined functions.


Index: opt_pushranges.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB5/src/optimizer/opt_pushranges.mx,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- opt_pushranges.mx   3 Jan 2008 10:20:19 -0000       1.13
+++ opt_pushranges.mx   7 Jan 2008 21:44:45 -0000       1.14
@@ -152,7 +152,7 @@
                        y= getArg(p,2);
                        if( range[x].lcst && isVarConstant(mb,y) ){
                                /* merge lowerbound */
-                               if( ATOMcmp( getVarType(mb,y), 
+                               if( ATOMcmp( getVarGDKType(mb,y), 
                                                VALptr( 
&getVarConstant(mb,range[x].lcst)), 
                                                VALptr( &getVarConstant(mb,y)) 
) > 0){
                                        getArg(p,2)= range[x].lcst;
@@ -165,10 +165,10 @@
                                }
                                y= getArg(p,3);
                                /* merge higherbound */
-                               if( ATOMcmp( getVarType(mb,y), 
+                               if( ATOMcmp( getVarGDKType(mb,y), 
                                                VALptr( 
&getVarConstant(mb,range[x].hcst)), 
                                                VALptr( &getVarConstant(mb,y)) 
) < 0 ||
-                                       ATOMcmp( getVarType(mb,y),
+                                       ATOMcmp( getVarGDKType(mb,y),
                                                VALptr( &getVarConstant(mb,y)),
                                                 ATOMnilptr(getVarType(mb,y)) ) 
== 0){
                                        getArg(p,3)= range[x].hcst;
@@ -202,7 +202,7 @@
                        y= getArg(p,3);
                        if( isVarConstant(mb, x)  &&
                                isVarConstant(mb, y)  ){
-                               z =ATOMcmp( getVarType(mb,y),
+                               z =ATOMcmp( getVarGDKType(mb,y),
                         VALptr( &getVarConstant(mb,x)),
                         VALptr( &getVarConstant(mb,y)));
                                x=  p->argc > 4;

Index: opt_deadcode.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB5/src/optimizer/opt_deadcode.mx,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- opt_deadcode.mx     2 Jan 2008 08:21:03 -0000       1.31
+++ opt_deadcode.mx     7 Jan 2008 21:44:45 -0000       1.32
@@ -139,17 +139,17 @@
                }
        }
        /* we may have uncovered new use-less operations */
-       if( actions) 
-               i= OPTdeadcodeImplementation(mb, stk, pci);
+       if (actions) 
+               actions += 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]);
+               if( old[i])
+                       freeInstruction(old[i]);
        GDKfree(old);
-       return actions+i;
+       return actions;
 }
 @include optimizerWrapper.mx
 @h

Index: opt_remap.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB5/src/optimizer/opt_remap.mx,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- opt_remap.mx        5 Jan 2008 09:48:11 -0000       1.21
+++ opt_remap.mx        7 Jan 2008 21:44:45 -0000       1.22
@@ -150,14 +150,17 @@
 find an instruction that does not have a multiplex
 counterpart.
 @c
-static int OPTmultiplexInline( MalBlkPtr mb, InstrPtr p, int pc ){
+static int 
+OPTmultiplexInline( MalBlkPtr mb, InstrPtr p, int pc )
+{
        MalBlkPtr mq;
        InstrPtr q,sig;
        char buf[1024];
-       int i,j,k, *upgrade;
+       int i,j,k;
+       bit *upgrade;
        Symbol s;
        s= findSymbol(  VALget(&getVar(mb, getArg(p, 1))->value),
-                                       VALget(&getVar(mb, getArg(p, 
2))->value));
+                       VALget(&getVar(mb, getArg(p, 2))->value));
 
        if( s== NULL || !isSideEffectFree(s->def)){
 #ifdef DEBUG_OPT_REMAP
@@ -178,11 +181,11 @@
                printFunction(GDKout,mq,LIST_MAL_ALL);
                printInstruction(GDKout,mb,p,LIST_MAL_ALL);
 #endif
-       upgrade= (int*) GDKzalloc(sizeof(int)*mq->vtop);
+       upgrade = (bit*) GDKzalloc(sizeof(bit)*mq->vtop);
 
        setVarType(mq, 0,newBatType(TYPE_oid, getArgType(mb,p,0)));
        clrVarFixed(mq,getArg(getInstrPtr(mq,0),0)); /* for typing */
-       upgrade[getArg(getInstrPtr(mq,0),0)]= TRUE;
+       upgrade[getArg(getInstrPtr(mq,0),0)] = TRUE;
 
        for(i=3; i<p->argc; i++){
                if( !isaBatType( getArgType(mq,sig,i-2)) &&
@@ -206,44 +209,65 @@
 to-be-inlined function for arguments that require
 an upgrade and resolve it afterwards.
 @c
+       for(i=1; i<mq->stop; i++) {
+               int fnd = 0;
+
+               q = getInstrPtr(mq,i);
+               if (q->token == ENDsymbol)
+                       break;
+               for(j=0; j<q->argc && !fnd; j++) 
+                       if (upgrade[getArg(q,j)]) {
+                               for(k=0; k<q->retc; k++){
+                                       //setVarType(mq,getArg(q,k),TYPE_any);
+                                       
setVarType(mq,getArg(q,j),newBatType(TYPE_oid,getArgType(mq, q, j)));
+                                       /* for typing */
+                                       clrVarFixed(mq,getArg(q,k)); 
+                                       if (!upgrade[getArg(q,k)]) {
+                                               upgrade[getArg(q,k)]= TRUE;
+                                               /* lets restart */
+                                               i = 0;
+                                       }
+                               }
+                               fnd = 1;
+                       }
+               /* nil:type -> nil:bat[:oid,:type] */
+               if (!getModuleId(q) && q->token == ASSIGNsymbol &&
+                   q->argc == 2 && isVarConstant(mq, getArg(q,1)) && 
+                   upgrade[getArg(q,0)] &&
+                   !isaBatType(getArgType(mq, q, 1)) &&
+                   ATOMcmp(getArgGDKType(mq, q, 1),
+                       VALget(&getVar(mq, getArg(q,1))->value),
+                       ATOMnilptr(getArgType(mq, q, 1))) == 0) {
+                       ValRecord cst;
+                       int tpe = newBatType(TYPE_oid,getArgType(mq, q, 1));
+
+                       setVarType(mq,getArg(q,0),tpe);
+                       cst.vtype = TYPE_bat;
+                       cst.val.bval = bat_nil;
+                       getArg(q,1) = defConstant(mq, tpe, &cst);
+                       setVarType(mq, getArg(q,1), tpe);
+               }
+       }
+
+       /* now upgrade the statements */
        for(i=1; i<mq->stop; i++){
                q= getInstrPtr(mq,i);
                if( q->token== ENDsymbol)
                        break;
-               k=0;
                for(j=0; j<q->argc; j++)
-               if( upgrade[getArg(q,j)] )
-                       k++;
-               if(k){
-#ifdef DEBUG_OPT_REMAP
-                       stream_printf(GDKout,"#Patch the instruction\n");
-                       printInstruction(GDKout,mq,q,LIST_MAL_ALL);
-#endif
-                       for(j=0;j<q->retc; j++){
-                               setVarType(mq,getArg(q,j),TYPE_any);
-                               clrVarFixed(mq,getArg(q,j)); /* for typing */
-                               upgrade[getArg(q,j)]= TRUE;
-                       }
-                       if( getModuleId(q)){
+                       if (upgrade[getArg(q,j)] && getModuleId(q)){
                                snprintf(buf,1024,"bat%s",getModuleId(q));
                                setModuleId(q,putName(buf,strlen(buf)));
+
+                               /* now see if we can resolve the instruction */
+                               typeChecker(MCgetClient()->nspace,mq,q,TRUE);
+                               if( q->typechk== TYPE_UNKNOWN)
+                                       goto terminateMX;
+                               break;
                        }
-                       /* now see if we can resolve the instruction */
-                       typeChecker(MCgetClient()->nspace,mq,q,TRUE);
-                       if( q->typechk== TYPE_UNKNOWN)
-                               goto terminateMX;
-#ifdef DEBUG_OPT_REMAP
-                       printInstruction(GDKout,mq,q,LIST_MAL_ALL);
-#endif
-               }
-#ifdef DEBUG_OPT_REMAP
-               else{
-                       stream_printf(GDKout,"#Don't patch the instruction\n");
-                       printInstruction(GDKout,mq,q,LIST_MAL_ALL);
-               }
-#endif
        }
 
+
        if(mq->errors){
 terminateMX:
                freeMalBlk(mq);

Index: opt_macro.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB5/src/optimizer/opt_macro.mx,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- opt_macro.mx        6 Jan 2008 19:01:40 -0000       1.31
+++ opt_macro.mx        7 Jan 2008 21:44:45 -0000       1.32
@@ -244,21 +244,19 @@
                if (isExceptionVariable(mc->var[n]->name)) {
                        nv[n] = 
newVariable(mb,GDKstrdup(mc->var[n]->name),TYPE_str);
                        /* keep the properties */
-                       if( isVarUDFtype(mc,n))
+                       if (isVarUDFtype(mc,n))
                                setVarUDFtype(mb,nv[n]);
-                       if( isVarUsed(mc,n))
+                       if (isVarUsed(mc,n))
                                setVarUsed(mb,nv[n]);
-               } else
-               if( isVarTypedef(mc,n) )
+               } else if (isVarTypedef(mc,n)) {
                        nv[n] = newTypeVariable(mb,getVarType(mc,n));
-               else
-               if ( isVarConstant(mc,n)){
+               } else if (isVarConstant(mc,n)) {
                        nv[n] = cpyConstant(mb,getVar(mc,n));
                } else {
                        nv[n] = newTmpVariable(mb, getVarType(mc, n));
-                       if( isVarUDFtype(mc,n))
+                       if (isVarUDFtype(mc,n))
                                setVarUDFtype(mb,nv[n]);
-                       if( isVarUsed(mc,n))
+                       if (isVarUsed(mc,n))
                                setVarUsed(mb,nv[n]);
                }
        }
@@ -284,10 +282,12 @@
 
        /* make result variable(s) known, ie assign a nil value */
        for (n = 0; n < p->retc; n++) {
-               q = ns[k++] = newInstruction(NULL, ASSIGNsymbol);
-               q->argc = q->retc = 0;
-               q = pushArgument(mb, q, getArg(p, n)); q->retc++;
-               q = pushNil(mb, q, getArgType(mb, p, n));
+               if (getArgType(mb, p, n)) {
+                       q = ns[k++] = newInstruction(NULL, ASSIGNsymbol);
+                       q->argc = q->retc = 0;
+                       q = pushArgument(mb, q, getArg(p, n)); q->retc++;
+                       q = pushNil(mb, q, getArgType(mb, p, n));
+               }
        }
 
        for (i = 1; i < mc->stop - 1; i++) {

Index: opt_reduce.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB5/src/optimizer/opt_reduce.mx,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- opt_reduce.mx       2 Jan 2008 08:21:18 -0000       1.18
+++ opt_reduce.mx       7 Jan 2008 21:44:45 -0000       1.19
@@ -66,11 +66,11 @@
        alias= (int*) alloca(mb->vtop *sizeof(int));
 
        for(i = 0; i< mb->vtop; i++)
-       if (isVarConstant(mb,i)){
+       if (isVarConstant(mb,i)) {
                alias[i] = i;
                for(j=0; j<top; j++) {
                        if (getVarType(mb,i) == getVarType(mb,cst[j]) &&
-                           ATOMcmp(getVarType(mb,i),
+                           ATOMcmp(getVarGDKType(mb,i),
                             VALget(&getVar(mb,i)->value),
                             VALget(&getVar(mb,cst[j])->value)) == 0) {
                                alias[i] = cst[j];


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Monetdb-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-checkins

Reply via email to