Changeset: edd7390bdde9 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=edd7390bdde9
Modified Files:
        monetdb5/optimizer/opt_xid.c
Branch: xid
Log Message:

Deal with very long argument lists.

The wait instruction is incrementally built. If there are many arguments,
then the pushArgument instruction may not be able to locate it in the MALblock.
Splitting the code generation solves this issue.


diffs (93 lines):

diff --git a/monetdb5/optimizer/opt_xid.c b/monetdb5/optimizer/opt_xid.c
--- a/monetdb5/optimizer/opt_xid.c
+++ b/monetdb5/optimizer/opt_xid.c
@@ -30,7 +30,7 @@ OPTxidImplementation(Client cntxt, MalBl
        int type, i, j, se, limit, v;
        InstrPtr q, qs, p=0, *old= mb->stmt;
        int actions = 0, cnt;
-       int *compressed, *def;
+       int *compressed;
        Lifespan span;
 
        (void) pci;
@@ -39,11 +39,6 @@ OPTxidImplementation(Client cntxt, MalBl
        compressed = GDKzalloc( 2 * sizeof(int) * mb->vtop);
        if (compressed ==0)
                return 0;
-       def = GDKzalloc( 2 * sizeof(int) * mb->vtop);
-       if (def ==0) {
-               GDKfree(compressed);
-               return 0;
-       }
 
        span = setLifespan(mb);
        if ( span == NULL)
@@ -72,28 +67,37 @@ OPTxidImplementation(Client cntxt, MalBl
                 */
                cnt = 0;
                for ( j =p->retc; j< p->argc; j++)
-               if (compressed[getArg(p,j)] || 
isaBatType(getVarType(mb,getArg(p,j))) ) cnt++;
+               cnt+= compressed[getArg(p,j)] || 
isaBatType(getVarType(mb,getArg(p,j)));
 
                /* at least two BATs used, synchronise their access */
                if ( cnt >= 2 ){
                        qs = newStmt(mb, languageRef, waitRef);
                        qs->retc = qs->argc = 0;
+                       /* first construct the wait completely. Long 
decompressions my screw up
+                        * due to limited search backward for enlarged 
instructions. */
                        for ( j =p->retc; j< p->argc; j++)
                        if ( isaBatType(getVarType(mb, getArg(p,j))) ) {
                                v = newTmpVariable(mb, getVarType(mb, 
getArg(p,j)));
                                assert(v < 2* mb->vtop);
                                qs= pushReturn(mb, qs, v);
+                               if ( compressed[getArg(p,j)] )
+                                       qs= pushArgument(mb, qs, 
compressed[getArg(p,j)]);
+                                else
+                                       qs= pushArgument(mb, qs, getArg(p,j));
+                       }
+                       /* stage 2, decompress the list */
+                       cnt = 0;
+                       for ( j =p->retc; j< p->argc; j++)
+                       if ( isaBatType(getVarType(mb, getArg(p,j))) ) {
                                if ( compressed[getArg(p,j)] ){
-                                       qs= pushArgument(mb, qs, 
compressed[getArg(p,j)]);
                                        /* actually decompress when there is 
not a direct flow into the instruction */
                                        q = newStmt(mb,"xid","decompress");
-                                       q= pushArgument(mb, q, v);
+                                       q= pushArgument(mb, q, getArg(qs, cnt));
                                        setVarType(mb, getArg(q,0), 
getVarType(mb, getArg(p,j)));
                                        getArg(p,j) = getArg(q,0);
-                                } else {
-                                       qs= pushArgument(mb, qs, getArg(p,j));
-                                       getArg(p,j) = v;
-                               }
+                                } else 
+                                       getArg(p,j) = getArg(qs,cnt);
+                               cnt++;
                        }
                } else
                        for ( j =p->retc; j< p->argc; j++)
@@ -110,13 +114,13 @@ OPTxidImplementation(Client cntxt, MalBl
                /* compress the result, if at least one column is :oid */
                for (j = 0 ; j < p->retc ; j++) {
                        type= getVarType(mb,getArg(p,j));
-                       if ((getTailType(type) == TYPE_oid || getHeadType(type) 
== TYPE_oid) && compressed[getArg(p,j)] == 0) {
+                       if ((getTailType(type) == TYPE_oid || getHeadType(type) 
== TYPE_oid) ){
+                               assert(compressed[getArg(p,j)] == 0);
                                /* don't compress if you immediately eat the 
result */
                                if (getEndLifespan(span, getArg(p,j)) >= i + 
MIN_DISTANCE) {
                                        q = newStmt(mb,"xid","compress");
                                        q= pushArgument(mb,q, getArg(p,j));
                                        compressed [getArg(p,j)] = getArg(q,0);
-                                       def[getArg(p,j)] = i;
                                        mnstr_printf(GDKout,"#var %d def 
%d\n",getArg(p,j), i);
                                }
                        }
@@ -127,7 +131,6 @@ OPTxidImplementation(Client cntxt, MalBl
                mnstr_printf(cntxt->fdout,"#opt_xid: %d statements removed\n", 
actions);
        GDKfree(old);
        GDKfree(compressed);
-       GDKfree(def);
        /* we may have uncovered new use-less operations */
        return actions;
 }
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to