Changeset: 1c3ab5db4831 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=1c3ab5db4831
Modified Files:
monetdb5/optimizer/opt_commonTerms.c
monetdb5/optimizer/opt_mitosis.c
Branch: default
Log Message:
Improve the commonterm hash structure.
diffs (90 lines):
diff --git a/monetdb5/optimizer/opt_commonTerms.c
b/monetdb5/optimizer/opt_commonTerms.c
--- a/monetdb5/optimizer/opt_commonTerms.c
+++ b/monetdb5/optimizer/opt_commonTerms.c
@@ -14,11 +14,21 @@
* at the surface level. It requires the constant optimizer to be ran first.
*/
-/* This hash is simplistic, it links all instructions in which a variable is
used.
- * Merge table could duplicate an instruction many times, which means that the
last argument becomes a long list.
- * Then hashing over the other arguments does not help.
+/* The key for finding common terms is that they share variables.
+ * Therefore we skip all constants, except for a constant only situation.
*/
-#define HASHinstruction(X) getArg((X), (X)->argc-1)
+
+static int
+hashInstruction(MalBlkPtr mb, InstrPtr p)
+{
+ int i;
+ for ( i = p->argc - 1 ; i >= p->retc; i--)
+ if (! isVarConstant(mb,getArg(p,i)) )
+ return getArg(p,i);
+ if (isVarConstant(mb,getArg(p, p->retc)) )
+ return p->retc;
+ return -1;
+}
str
OPTcommonTermsImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk,
InstrPtr pci)
@@ -29,7 +39,7 @@ OPTcommonTermsImplementation(Client cntx
int limit, slimit;
int duplicate;
int *alias;
- int *hash;
+ int *hash, h;
int *list;
InstrPtr *old = NULL;
@@ -115,15 +125,19 @@ OPTcommonTermsImplementation(Client cntx
/* from here we have a candidate to look for a match */
+ h = hashInstruction(mb, p);
if( OPTdebug & OPTcommonterms){
- fprintf(stderr,"#CANDIDATE[%d] look at list[%d]=>%d\n",
- i, HASHinstruction(p),
hash[HASHinstruction(p)]);
+ fprintf(stderr,"#CANDIDATE[%d] look at list[%d]=>%d\n",
i, h, hash[h]);
fprintInstruction(stderr, mb, 0, p, LIST_MAL_ALL);
}
+ if( h < 0){
+ pushInstruction(mb,p);
+ continue;
+ }
bailout = 1024 ; // don't run over long collision list
/* Look into the hash structure for matching instructions */
- for (j = hash[HASHinstruction(p)]; j > 0 && bailout-- > 0 ; j
= list[j])
+ for (j = hash[h]; j > 0 && bailout-- > 0 ; j = list[j])
if ( (q= getInstrPtr(mb,j)) && getFunctionId(q) ==
getFunctionId(p) && getModuleId(q) == getModuleId(p) ){
if( OPTdebug & OPTcommonterms){
@@ -191,13 +205,13 @@ OPTcommonTermsImplementation(Client cntx
if( OPTdebug & OPTcommonterms){
fprintf(stderr,"#UPDATE HASH[%d] look at arg %d hash
%d list %d\n",
- i, getArg(p,p->argc-1), HASHinstruction(p),
hash[HASHinstruction(p)]);
+ i, getArg(p,p->argc-1), h, hash[h]);
fprintInstruction(stderr, mb, 0, p, LIST_MAL_ALL);
}
if ( !mayhaveSideEffects(cntxt, mb, p, TRUE) && p->argc !=
p->retc && isLinearFlow(p) && !isUnsafeFunction(p) && !isUpdateInstruction(p)){
- list[i] = hash[HASHinstruction(p)];
- hash[HASHinstruction(p)] = i;
+ list[i] = hash[h];
+ hash[h] = i;
pushInstruction(mb,p);
}
}
diff --git a/monetdb5/optimizer/opt_mitosis.c b/monetdb5/optimizer/opt_mitosis.c
--- a/monetdb5/optimizer/opt_mitosis.c
+++ b/monetdb5/optimizer/opt_mitosis.c
@@ -283,7 +283,7 @@ OPTmitosisImplementation(Client cntxt, M
/* keep all actions taken as a post block comment */
bailout:
usec = GDKusec()- usec;
- snprintf(buf,256,"%-20s actions=1 time=" LLFMT " usec","mitosis", usec);
+ snprintf(buf,256,"%-20s actions=%d time=" LLFMT " usec","mitosis", pieces,
usec);
newComment(mb,buf);
addtoMalBlkHistory(mb);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list