Changeset: 1b0afe61c338 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=1b0afe61c338
Modified Files:
        monetdb5/extras/crackers/60_crackers.mal
        monetdb5/extras/crackers/crackers_holistic.c
        monetdb5/extras/crackers/crackers_holistic.h
        monetdb5/extras/crackers/opt_selcrack.mx
        monetdb5/extras/crackers/opt_selcrackhol.mx
        monetdb5/extras/crackers/opt_selcrackst.mx
        monetdb5/optimizer/opt_pipes.c
Branch: holindex
Log Message:

crackers: load optimiser pipes dynamically

Since crackers is an optional component, we cannot hardcode its
optimiser pipelines in opt_pipes.  Instead, we load them upon crackers
modules load dynamically.  Fix misc other calling things to make sure
the optimisers are actually used when the pipes are active.


diffs (truncated from 571 to 300 lines):

diff --git a/monetdb5/extras/crackers/60_crackers.mal 
b/monetdb5/extras/crackers/60_crackers.mal
--- a/monetdb5/extras/crackers/60_crackers.mal
+++ b/monetdb5/extras/crackers/60_crackers.mal
@@ -22,4 +22,3 @@ include opt_selcrackst;
 include opt_selcrackhol;
 include crackers;
 include crackers_holistic;
-
diff --git a/monetdb5/extras/crackers/crackers_holistic.c 
b/monetdb5/extras/crackers/crackers_holistic.c
--- a/monetdb5/extras/crackers/crackers_holistic.c
+++ b/monetdb5/extras/crackers/crackers_holistic.c
@@ -22,6 +22,7 @@
 #include "crackers.h"
 #include "gdk.h"
 #include "mal_exception.h"
+#include "opt_pipes.h"
 #include "mutils.h"
 
 static FrequencyNode *_InternalFrequencyStructA = NULL;
@@ -32,6 +33,7 @@ str
 CRKinitHolistic(int *ret)
 {
        MT_lock_init(&frequencylock, "FrequencyStruct");
+
        *ret = 0;
        return MAL_SUCCEED;
 }
diff --git a/monetdb5/extras/crackers/crackers_holistic.h 
b/monetdb5/extras/crackers/crackers_holistic.h
--- a/monetdb5/extras/crackers/crackers_holistic.h
+++ b/monetdb5/extras/crackers/crackers_holistic.h
@@ -20,7 +20,8 @@
 #ifndef _CRACKERS_HOLISTIC_H_
 #define _CRACKERS_HOLISTIC_H_
 
-#include <mal.h>
+#include "mal.h"
+#include "mal_client.h"
 
 
 #ifdef WIN32
diff --git a/monetdb5/extras/crackers/opt_selcrack.mx 
b/monetdb5/extras/crackers/opt_selcrack.mx
--- a/monetdb5/extras/crackers/opt_selcrack.mx
+++ b/monetdb5/extras/crackers/opt_selcrack.mx
@@ -31,6 +31,10 @@ pattern optimizer.selcrack(mod:str, fcn:
 address OPTselcrack
 comment "Selection cracking";
 
+module crackers;
+pattern crackers.selcrackprelude():void
+address SCprelude;
+crackers.selcrackprelude();
 @h
 #ifndef _OPT_SELCRACK_
 #define _OPT_SELCRACK_
@@ -38,8 +42,9 @@ comment "Selection cracking";
 
 #define maxTables 10
 
-opt_export int OPTselcrackImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr 
stk, InstrPtr pci);
 #define OPTDEBUGselcrack  if ( optDebug & ((lng)1 <<DEBUG_OPT_SELCRACK) )
+opt_export str SCprelude(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr 
pci);
+opt_export str OPTselcrack(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr 
pci);
 
 #endif
 @c
@@ -47,14 +52,47 @@ opt_export int OPTselcrackImplementation
 #include "opt_selcrack.h"
 #include "mal_interpreter.h"   /* for showErrors() */
 #include "opt_prelude.h"
+#include "opt_pipes.h"
+#include "opt_statistics.h"
 #include "mtime.h"
 
 #define match2(X,M,F) ( (X) && getFunctionId(X) && getFunctionId(X)==F && \
        getModuleId(X) && getModuleId(X)==M)
 
+str
+SCprelude(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
+{
+       (void) mb;
+       (void) stk;
+       (void) pci;
+
+       addPipeDefinition(cntxt, "cracker_pipe",
+                       "optimizer.inline();"
+                       "optimizer.remap();"
+                       "optimizer.evaluate();"
+                       "optimizer.costModel();"
+                       "optimizer.coercions();"
+                       "optimizer.emptySet();"
+                       "optimizer.aliases();"
+                       "optimizer.selcrack();"
+                       "optimizer.deadcode();"
+                       "optimizer.commonTerms();"
+                       "optimizer.groups();"
+                       "optimizer.joinPath();"
+                       "optimizer.reorder();"
+                       "optimizer.deadcode();"
+                       "optimizer.reduce();"
+                       "optimizer.dataflow();"
+                       "optimizer.history();"
+                       "optimizer.multiplex();"
+                       "optimizer.garbageCollector();");
+
+       return MAL_SUCCEED;
+}
+
 /* find all algebra select structions in a mal block mb and change them to the 
corresponding crackers command
     */
-int
+static int
 OPTselcrackImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr 
pci)
 {
        InstrPtr p, *old;
@@ -243,3 +281,67 @@ OPTselcrackImplementation(Client cntxt, 
 
        return actions;
 }
+
+str OPTselcrack(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p)
+{
+       str modnme;
+       str fcnnme;
+       str msg = MAL_SUCCEED;
+       Symbol s = NULL;
+       lng t, clk = GDKusec();
+       int actions = 0;
+       char optimizer[256];
+       InstrPtr q = copyInstruction(p);
+
+       optimizerInit();
+       snprintf(optimizer, 256, "%s", getFunctionId(p));
+       OPTDEBUGselcrack mnstr_printf(cntxt->fdout, "=APPLY OPTIMIZER %s\n", 
getModuleId(p));
+       if (p && p->argc > 1) {
+               if (getArgType(mb, p, 1) != TYPE_str ||
+                       getArgType(mb, p, 2) != TYPE_str ||
+                       !isVarConstant(mb, getArg(p, 1)) ||
+                       !isVarConstant(mb, getArg(p, 2))
+                       )
+                       throw(MAL, optimizer, ILLARG_CONSTANTS);
+
+               if (stk != 0) {
+                       modnme = *(str *) getArgReference(stk, p, 1);
+                       fcnnme = *(str *) getArgReference(stk, p, 2);
+               } else {
+                       modnme = getArgDefault(mb, p, 1);
+                       fcnnme = getArgDefault(mb, p, 2);
+               }
+               removeInstruction(mb, p);
+               s = findSymbol(cntxt->nspace, putName(modnme, strlen(modnme)), 
putName(fcnnme, strlen(fcnnme)));
+
+               if (s == NULL) {
+                       char buf[1024];
+                       snprintf(buf, 1024, "%s.%s", modnme, fcnnme);
+                       throw(MAL, optimizer, RUNTIME_OBJECT_UNDEFINED ":%s", 
buf);
+               }
+               mb = s->def;
+               stk = 0;
+       } else if (p)
+               removeInstruction(mb, p);
+       if (mb->errors) {
+               /* when we have errors, we still want to see them */
+               addtoMalBlkHistory(mb, getModuleId(q));
+               freeInstruction(q);
+               return MAL_SUCCEED;
+       }
+
+       actions = OPTselcrackImplementation(cntxt, mb, stk, p);
+
+       msg = optimizerCheck(cntxt, mb, optimizer, actions, t = (GDKusec() - 
clk), OPT_CHECK_ALL);
+       OPTDEBUGselcrack {
+               mnstr_printf(cntxt->fdout, "=FINISHED %s  %d\n", optimizer, 
actions);
+               printFunction(cntxt->fdout, mb, 0, LIST_MAL_STMT | LIST_MAPI);
+       }
+       DEBUGoptimizers
+       mnstr_printf(cntxt->fdout, "#opt_reduce: " LLFMT " ms\n", t);
+       QOTupdateStatistics(getModuleId(q), actions, t);
+       addtoMalBlkHistory(mb, getModuleId(q));
+       freeInstruction(q);
+       return msg;
+}
+
diff --git a/monetdb5/extras/crackers/opt_selcrackhol.mx 
b/monetdb5/extras/crackers/opt_selcrackhol.mx
--- a/monetdb5/extras/crackers/opt_selcrackhol.mx
+++ b/monetdb5/extras/crackers/opt_selcrackhol.mx
@@ -31,6 +31,10 @@ pattern optimizer.selcrackhol(mod:str, f
 address OPTselcrackhol
 comment "Holistic Selection Cracking";
 
+module crackers;
+pattern crackers.selcrackholprelude():void
+address SCHprelude;
+crackers.selcrackholprelude();
 @h
 #ifndef _OPT_SELCRACKHOL_
 #define _OPT_SELCRACKHOL_
@@ -38,8 +42,9 @@ comment "Holistic Selection Cracking";
 
 #define maxTables 10
 
-opt_export int OPTselcrackholImplementation(Client cntxt, MalBlkPtr mb, 
MalStkPtr stk, InstrPtr pci);
 #define OPTDEBUGselcrackhol  if ( optDebug & ((lng)1 <<DEBUG_OPT_SELCRACKHOL) )
+opt_export str SCHprelude(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr 
pci);
+opt_export str OPTselcrackhol(Client cntxt, MalBlkPtr mb, MalStkPtr stk, 
InstrPtr p);
 
 #endif
 @c
@@ -47,14 +52,47 @@ opt_export int OPTselcrackholImplementat
 #include "opt_selcrackhol.h"
 #include "mal_interpreter.h"   /* for showErrors() */
 #include "opt_prelude.h"
+#include "opt_pipes.h"
+#include "opt_statistics.h"
 #include "mtime.h"
 
 #define match2(X,M,F) ( (X) && getFunctionId(X) && getFunctionId(X)==F && \
        getModuleId(X) && getModuleId(X)==M)
 
+str
+SCHprelude(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
+{
+       (void) mb;
+       (void) stk;
+       (void) pci;
+
+       addPipeDefinition(cntxt, "crackerhol_pipe",
+         "optimizer.inline();"
+         "optimizer.remap();"
+         "optimizer.evaluate();"
+         "optimizer.costModel();"
+         "optimizer.coercions();"
+         "optimizer.emptySet();"
+         "optimizer.aliases();"
+         "optimizer.selcrackhol();"
+         "optimizer.deadcode();"
+         "optimizer.commonTerms();"
+         "optimizer.groups();"
+         "optimizer.joinPath();"
+         "optimizer.reorder();"
+         "optimizer.deadcode();"
+         "optimizer.reduce();"
+         "optimizer.dataflow();"
+         "optimizer.history();"
+         "optimizer.multiplex();"
+         "optimizer.garbageCollector();");
+
+       return MAL_SUCCEED;
+}
+
 /* find all algebra select structions in a mal block mb and change them to the 
corresponding crackers command
     */
-int
+static int
 OPTselcrackholImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, 
InstrPtr pci)
 {
        InstrPtr p, *old;
@@ -245,3 +283,67 @@ OPTselcrackholImplementation(Client cntx
 
        return actions;
 }
+
+str OPTselcrackhol(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p)
+{
+       str modnme;
+       str fcnnme;
+       str msg = MAL_SUCCEED;
+       Symbol s = NULL;
+       lng t, clk = GDKusec();
+       int actions = 0;
+       char optimizer[256];
+       InstrPtr q = copyInstruction(p);
+
+       optimizerInit();
+       snprintf(optimizer, 256, "%s", getFunctionId(p));
+       OPTDEBUGselcrackhol mnstr_printf(cntxt->fdout, "=APPLY OPTIMIZER %s\n", 
getModuleId(p));
+       if (p && p->argc > 1) {
+               if (getArgType(mb, p, 1) != TYPE_str ||
+                       getArgType(mb, p, 2) != TYPE_str ||
+                       !isVarConstant(mb, getArg(p, 1)) ||
+                       !isVarConstant(mb, getArg(p, 2))
+                       )
+                       throw(MAL, optimizer, ILLARG_CONSTANTS);
+
+               if (stk != 0) {
+                       modnme = *(str *) getArgReference(stk, p, 1);
+                       fcnnme = *(str *) getArgReference(stk, p, 2);
+               } else {
+                       modnme = getArgDefault(mb, p, 1);
+                       fcnnme = getArgDefault(mb, p, 2);
+               }
+               removeInstruction(mb, p);
+               s = findSymbol(cntxt->nspace, putName(modnme, strlen(modnme)), 
putName(fcnnme, strlen(fcnnme)));
+
+               if (s == NULL) {
+                       char buf[1024];
+                       snprintf(buf, 1024, "%s.%s", modnme, fcnnme);
+                       throw(MAL, optimizer, RUNTIME_OBJECT_UNDEFINED ":%s", 
buf);
+               }
+               mb = s->def;
+               stk = 0;
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to