Changeset: 66caa1d3304a for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=66caa1d3304a
Modified Files:
        monetdb5/optimizer/opt_constants.c
Branch: default
Log Message:

No need to fold constants in side-effect functions, they
can not be merged by the commonterms optimizer.


diffs (73 lines):

diff --git a/monetdb5/optimizer/opt_constants.c 
b/monetdb5/optimizer/opt_constants.c
--- a/monetdb5/optimizer/opt_constants.c
+++ b/monetdb5/optimizer/opt_constants.c
@@ -13,7 +13,9 @@
  * This makes it easier to search for statement duplicates
  * and alias their variables.
  */
-
+/* We should not look at constants in simple, side-effect functions, because
+ * they can not be removed later on.
+*/
 /*
  * We have to keep an alias table to reorganize the program
  * after the variable stack has changed.
@@ -29,21 +31,23 @@
 str
 OPTconstantsImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr 
p)
 {
-       int i, k = 1, n  = 0, fnd = 0, actions  = 0, limit = 0;
-       int *alias = NULL, *index = NULL;
+       int i, j, k = 1, n  = 0, fnd = 0, actions  = 0, limit = 0;
+       int *alias = NULL, *index = NULL, *cand = NULL;
        VarPtr x,y, *cst = NULL;
        char buf[256];
        lng usec = GDKusec();
        str msg = MAL_SUCCEED;
+       InstrPtr q;
 
        if( isSQLinsert(mb)){
                goto wrapup;
        }
        alias= (int*) GDKzalloc(sizeof(int) * mb->vtop);
+       cand= (int*) GDKzalloc(sizeof(int) * mb->vtop);
        cst= (VarPtr*) GDKzalloc(sizeof(VarPtr) * mb->vtop);
        index= (int*) GDKzalloc(sizeof(int) * mb->vtop);
 
-       if ( alias == NULL || cst == NULL || index == NULL){
+       if ( alias == NULL || cst == NULL || index == NULL || cand == NULL){
                msg = createException(MAL,"optimizer.constants", 
SQLSTATE(HY013) MAL_MALLOC_FAIL);
                goto wrapup;
        }
@@ -51,10 +55,22 @@ OPTconstantsImplementation(Client cntxt,
        (void) stk;
        (void) cntxt;
 
+       for(i=0; i<mb->stop; i++){
+               q = getInstrPtr(mb,i);
+               if( hasSideEffects(mb, q, 1) )
+                       continue;
+               for(k= q->retc; k < q->argc; k++){
+                       j = getArg(q,k);
+                       if( cand[j] == 0) {
+                               cand[j] = isVarConstant(mb, j)  && 
isVarFixed(mb, j)  && getVarType(mb, j) != TYPE_ptr;
+                       }
+               }
+       }
+
        for (i=0; i< mb->vtop; i++)
                alias[ i]= i;
        for (i=0; i< mb->vtop; i++)
-               if ( isVarConstant(mb,i)  && isVarFixed(mb,i)  && 
getVarType(mb,i) != TYPE_ptr){
+               if ( cand[i]) {
                        x= getVar(mb,i);
                        fnd = 0;
                        limit = n - 128; // don't look to far back
@@ -102,6 +118,7 @@ wrapup:
        if (actions > 0)
                addtoMalBlkHistory(mb);
 
+       if( cand) GDKfree(cand);
        if( alias) GDKfree(alias);
        if( cst) GDKfree(cst);
        if( index) GDKfree(index);
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to