Changeset: ec6083b4565b for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=ec6083b4565b
Modified Files:
clients/Tests/MAL-signatures.stable.out
clients/Tests/MAL-signatures.stable.out.int128
clients/Tests/exports.stable.out
monetdb5/mal/mal.h
monetdb5/mal/mal_dataflow.c
monetdb5/mal/mal_debugger.c
monetdb5/mal/mal_debugger.h
monetdb5/mal/mal_function.c
monetdb5/mal/mal_function.h
monetdb5/mal/mal_instruction.h
monetdb5/mal/mal_interpreter.c
monetdb5/mal/mal_profiler.c
monetdb5/modules/mal/mdb.c
monetdb5/modules/mal/mdb.h
monetdb5/modules/mal/mdb.mal
monetdb5/optimizer/opt_aliases.c
monetdb5/optimizer/opt_candidates.c
monetdb5/optimizer/opt_constants.c
monetdb5/optimizer/opt_costModel.c
monetdb5/optimizer/opt_evaluate.c
monetdb5/optimizer/opt_factorize.c
monetdb5/optimizer/opt_garbageCollector.c
monetdb5/optimizer/opt_profiler.c
monetdb5/optimizer/opt_projectionpath.c
monetdb5/optimizer/opt_remap.c
monetdb5/optimizer/opt_reorder.c
Branch: default
Log Message:
Rework scope administration and optimizer checks
The variable scope information is now stored in the VarRecord
iso malloced. Some optimizers already avoid the expensive checks.
diffs (truncated from 790 to 300 lines):
diff --git a/clients/Tests/MAL-signatures.stable.out
b/clients/Tests/MAL-signatures.stable.out
--- a/clients/Tests/MAL-signatures.stable.out
+++ b/clients/Tests/MAL-signatures.stable.out
@@ -30615,10 +30615,6 @@ pattern mdb.inspect(mod:str,fcn:str):voi
address MDBinspect;
comment Run the debugger on a specific function
-pattern mdb.lifespan(M:str,F:str):void
-address MDBlifespan;
-comment Dump the current routine lifespan information on standard out.
-
pattern mdb.list(M:str,F:str):void
address MDBlist3;
comment Dump the routine M.F on standard out.
diff --git a/clients/Tests/MAL-signatures.stable.out.int128
b/clients/Tests/MAL-signatures.stable.out.int128
--- a/clients/Tests/MAL-signatures.stable.out.int128
+++ b/clients/Tests/MAL-signatures.stable.out.int128
@@ -40032,10 +40032,6 @@ pattern mdb.inspect(mod:str,fcn:str):voi
address MDBinspect;
comment Run the debugger on a specific function
-pattern mdb.lifespan(M:str,F:str):void
-address MDBlifespan;
-comment Dump the current routine lifespan information on standard out.
-
pattern mdb.list(M:str,F:str):void
address MDBlist3;
comment Dump the routine M.F on standard out.
diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out
--- a/clients/Tests/exports.stable.out
+++ b/clients/Tests/exports.stable.out
@@ -1363,7 +1363,6 @@ str MDBgetStackFrame(Client cntxt, MalBl
str MDBgetStackFrameN(Client cntxt, MalBlkPtr m, MalStkPtr s, InstrPtr p);
str MDBgrapTrappedProcess(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr
pci);
str MDBinspect(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p);
-str MDBlifespan(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p);
str MDBlist(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p);
str MDBlist3(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p);
str MDBlist3Detail(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p);
@@ -2024,7 +2023,6 @@ int daytime_tz_fromstr(const char *buf,
str dblRef;
str deblockdataflow(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);
void debugFunction(stream *fd, MalBlkPtr mb, MalStkPtr stk, int flg, int
first, int size);
-void debugLifespan(Client cntxt, MalBlkPtr mb, Lifespan span);
str debugOptimizers(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);
str debugScheduler(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);
int defConstant(MalBlkPtr mb, int type, ValPtr cst);
@@ -2454,7 +2452,6 @@ str setAccessRef;
void setArgType(MalBlkPtr mb, InstrPtr p, int i, int tpe);
InstrPtr setArgument(MalBlkPtr mb, InstrPtr p, int idx, int varid);
void setHeartbeat(int delay);
-Lifespan setLifespan(MalBlkPtr mb);
void setModuleJump(str nme, Module cur);
void setPolymorphic(InstrPtr p, int tpe, int force);
void setReturnArgument(InstrPtr p, int varid);
@@ -2462,6 +2459,7 @@ str setScenario(Client c, str nme);
void setVarName(MalBlkPtr mb, int i, str nme);
void setVarType(MalBlkPtr mb, int i, int tpe);
str setVariableRef;
+void setVariableScope(MalBlkPtr mb);
str setWriteModeRef;
str setprofilerpoolsize(int size);
str shortStmtRendering(MalBlkPtr mb, MalStkPtr stl, InstrPtr p);
diff --git a/monetdb5/mal/mal.h b/monetdb5/mal/mal.h
--- a/monetdb5/mal/mal.h
+++ b/monetdb5/mal/mal.h
@@ -149,7 +149,10 @@ typedef struct VARRECORD {
int flags; /* see below, reserve
some space */
int tmpindex; /* temporary variable */
ValRecord value;
+ int declared; /* pc index when it was first
assigned */
+ int updated; /* pc index when it was first
updated */
int eolife; /* pc index when it
should be garbage collected */
+ int depth; /* scope block depth */
int worker; /* tread id of last
worker producing it */
str stc; /* rendering
schema.table.column */
BUN rowcnt; /* estimated row count*/
diff --git a/monetdb5/mal/mal_dataflow.c b/monetdb5/mal/mal_dataflow.c
--- a/monetdb5/mal/mal_dataflow.c
+++ b/monetdb5/mal/mal_dataflow.c
@@ -600,7 +600,7 @@ DFLOWinitBlk(DataFlow flow, MalBlkPtr mb
if (!isVarConstant(mb, getArg(p, j))) {
/* be careful, watch out for garbage collection
interference */
/* those should be scheduled after all its
other uses */
- l = getEndOfLife(mb, getArg(p, j));
+ l = getEndScope(mb, getArg(p, j));
if (l != pc && l < flow->stop && l >
flow->start) {
/* add edge to the target instruction
for wakeup call */
PARDEBUG fprintf(stderr, "#endoflife
for %s is %d -> %d\n", getVarName(mb, getArg(p, j)), n + flow->start, l);
diff --git a/monetdb5/mal/mal_debugger.c b/monetdb5/mal/mal_debugger.c
--- a/monetdb5/mal/mal_debugger.c
+++ b/monetdb5/mal/mal_debugger.c
@@ -484,14 +484,7 @@ retryRead:
case 'f': /* finish */
case 'n': /* next */
case 's': /* step */
- if (strncmp("span", b, 4) == 0) {
- Lifespan span = setLifespan(mb);
- if ( span){
- debugLifespan(cntxt, mb, span);
- GDKfree(span);
- }
- continue;
- } else if (strncmp("scenarios", b, 9) == 0) {
+ if (strncmp("scenarios", b, 9) == 0) {
showAllScenarios(out);
continue;
} else if (strncmp("scenario", b, 3) == 0) {
@@ -1247,7 +1240,8 @@ printStackHdr(stream *f, MalBlkPtr mb, V
nme = nmebuf;
} else
nme = n->name;
- mnstr_printf(f, "#[%d] %5s = ", index, nme);
+ mnstr_printf(f, "#[%2d] %5s", index, nme);
+ mnstr_printf(f, " (%d,%d,%d) = ", getBeginScope(mb,index),
getLastUpdate(mb,index),getEndScope(mb, index));
if (v)
ATOMprint(v->vtype, VALptr(v), f);
}
@@ -1286,8 +1280,6 @@ printStackElm(stream *f, MalBlkPtr mb, V
mnstr_printf(f, " %s", (isVarConstant(mb, index) ? " constant" : ""));
/* mnstr_printf(f, " %s", (isVarUsed(mb,index) ? "": " not used" ));*/
mnstr_printf(f, " %s", (isVarTypedef(mb, index) ? " type variable" :
""));
- if (getEndOfLife(mb, index))
- mnstr_printf(f, " eolife=%d ", getEndOfLife(mb, index));
GDKfree(nme);
mnstr_printf(f, "\n");
GDKfree(nmeOnStk);
@@ -1435,26 +1427,3 @@ debugOptimizers(Client cntxt, MalBlkPtr
removeInstruction(mb, pci);
return MAL_SUCCEED;
}
-
-void
-debugLifespan(Client cntxt, MalBlkPtr mb, Lifespan span)
-{
- int i;
- char name[BUFSIZ];
-
- for (i = 0; i < mb->vtop; i++) {
- if (isTmpVar(mb, i))
- snprintf(name, BUFSIZ, "%c%d ", TMPMARKER, getVar(mb,
i)->tmpindex);
- else
- snprintf(name, BUFSIZ, "%s ", getVar(mb, i)->name);
- mnstr_printf(cntxt->fdout, "#%8s eolife=%4d range %4d - %4d ",
- name,
- getEndOfLife(mb,i),
- getBeginLifespan(span, i),
- getEndLifespan(span, i));
- if (getLastUpdate(span, i))
- mnstr_printf(cntxt->fdout, "last update %d \n",
getLastUpdate(span, i));
- else
- mnstr_printf(cntxt->fdout, "constant \n");
- }
-}
diff --git a/monetdb5/mal/mal_debugger.h b/monetdb5/mal/mal_debugger.h
--- a/monetdb5/mal/mal_debugger.h
+++ b/monetdb5/mal/mal_debugger.h
@@ -31,5 +31,4 @@ mal_export void printStack(stream *f, Ma
mal_export str runMALDebugger(Client cntxt, MalBlkPtr mb);
mal_export str debugOptimizers(Client cntxt, MalBlkPtr mb, MalStkPtr stk,
InstrPtr pci);
-mal_export void debugLifespan(Client cntxt, MalBlkPtr mb, Lifespan span);
#endif /* _MAL_DEBUGGER_h */
diff --git a/monetdb5/mal/mal_function.c b/monetdb5/mal/mal_function.c
--- a/monetdb5/mal/mal_function.c
+++ b/monetdb5/mal/mal_function.c
@@ -530,23 +530,24 @@ void printFunction(stream *fd, MalBlkPtr
listFunction(fd,mb,stk,flg,0,mb->stop);
}
-Lifespan
-setLifespan(MalBlkPtr mb)
+/* initialize the static scope boundaries for all variables */
+void
+setVariableScope(MalBlkPtr mb)
{
int pc, k, depth=0, dflow= -1;
InstrPtr p;
- int *blk;
- Lifespan span= newLifespan(mb);
str lang = putName("language"), dataflow= putName("dataflow");
- if (span == NULL)
- return NULL;
-
- blk= (int *) GDKzalloc(sizeof(int)*mb->vtop);
- if( blk == NULL){
- GDKerror("setLifeSpan" MAL_MALLOC_FAIL);
- GDKfree(span);
- return NULL;
+ /* reset the scope admin */
+ for (k = 0; k < mb->vtop; k++)
+ if( isVarConstant(mb,k)){
+ mb->var[k]->depth = 0;
+ mb->var[k]->declared = 0;
+ mb->var[k]->eolife = mb->stop;
+ } else {
+ mb->var[k]->depth = 0;
+ mb->var[k]->declared = 0;
+ mb->var[k]->eolife = 0;
}
for (pc = 0; pc < mb->stop; pc++) {
@@ -567,18 +568,20 @@ setLifespan(MalBlkPtr mb)
for (k = 0; k < p->argc; k++) {
int v = getArg(p,k);
+ if( isVarConstant(mb,v) && mb->var[v]->updated == 0)
+ mb->var[v]->updated= pc;
- if (span[v].beginLifespan == 0 ){
- span[v].beginLifespan = pc;
- blk[v]= depth;
+ if (mb->var[v]->declared == 0 ){
+ mb->var[v]->declared = pc;
+ mb->var[v]->depth = depth;
}
if (k < p->retc )
- span[v].lastUpdate= pc;
- if ( blk[v] == depth )
- span[v].endLifespan = pc;
+ mb->var[v]->updated= pc;
+ if ( mb->var[v]->depth == depth )
+ mb->var[v]->eolife = pc;
- if ( k >= p->retc && blk[v] < depth )
- span[v].endLifespan = -1; /* declared in
outer scope*/
+ if ( k >= p->retc && mb->var[v]->depth < depth )
+ mb->var[v]->eolife = -1;
}
/*
* At a block exit we can finalize all variables defined within
that block.
@@ -587,21 +590,19 @@ setLifespan(MalBlkPtr mb)
*/
if( blockExit(p) ){
for (k = 0; k < mb->vtop; k++)
- if ( span[k].endLifespan == -1 )
- span[k].endLifespan = pc;
- else
- if ( span[k].endLifespan == 0 && blk[k]==depth )
- span[k].endLifespan = pc;
+ if ( mb->var[k]->eolife == 0 &&
mb->var[k]->depth==depth )
+ mb->var[k]->eolife = pc;
+ else if ( mb->var[k]->eolife == -1 )
+ mb->var[k]->eolife = pc;
+
if( dflow == depth)
dflow= -1;
else depth--;
}
}
for (k = 0; k < mb->vtop; k++)
- if ( span[k].endLifespan == 0 )
- span[k].endLifespan = pc-2;/* generate them before the end */
- GDKfree(blk);
- return span;
+ if( mb->var[k]->eolife == 0)
+ mb->var[k]->eolife = mb->stop-1;
}
int
@@ -669,18 +670,14 @@ void
malGarbageCollector(MalBlkPtr mb)
{
int i;
- Lifespan span;
- span = setLifespan(mb);
- if ( span == NULL)
- return ;
+ setVariableScope(mb);
for (i = 0; i < mb->vtop; i++)
- if( isVarCleanup(mb,i) && getEndLifespan(span,i) >= 0) {
- mb->var[i]->eolife = getEndLifespan(span,i);
+ if( isVarCleanup(mb,i) && getEndScope(mb,i) >= 0) {
+ mb->var[i]->eolife = getEndScope(mb,i);
mb->stmt[mb->var[i]->eolife]->gc |= GARBAGECONTROL;
}
- GDKfree(span);
}
/*
* Variable declaration
diff --git a/monetdb5/mal/mal_function.h b/monetdb5/mal/mal_function.h
--- a/monetdb5/mal/mal_function.h
+++ b/monetdb5/mal/mal_function.h
@@ -13,13 +13,9 @@
#include "mal_module.h"
#include "mal_resolve.h"
-typedef struct lifespan {
- int beginLifespan, endLifespan, lastUpdate;
-} *Lifespan, LifespanRecord;
-
-#define getLastUpdate(L,I) (L[I].lastUpdate)
-#define getEndLifespan(L,I) (L[I].endLifespan)
-#define getBeginLifespan(L,I) (L[I].beginLifespan)
+#define getLastUpdate(L,I) ((L)->var[I]->updated)
+#define getEndScope(L,I) ((L)->var[I]->eolife)
+#define getBeginScope(L,I) ((L)->var[I]->declared)
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list