Changeset: a8dceec7f530 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a8dceec7f530
Modified Files:
MonetDB5/src/optimizer/opt_datacyclotron.mx
Branch: default
Log Message:
When you need to extend an array use realloc and in case the original array was
allocated using
zalloc, use memset to initialize the extension with 0.
When the MAL plan optimization ends the instructions from the old plan which
are not used in the
new plan must be free.
In case of failure, you should revert the changes, i.e., you should go back to
the initial plan.
Furthermore, you should free the new created instructions.
It was tested for TPC-H query 1 and it passed the optimized compilation.
diffs (125 lines):
diff -r e930a3392ec5 -r a8dceec7f530 MonetDB5/src/optimizer/opt_datacyclotron.mx
--- a/MonetDB5/src/optimizer/opt_datacyclotron.mx Mon Nov 08 21:30:36
2010 +0100
+++ b/MonetDB5/src/optimizer/opt_datacyclotron.mx Tue Nov 09 01:00:32
2010 +0100
@@ -238,15 +238,27 @@
}
static int
+check_instr(InstrPtr *stmt, int stop, InstrPtr p)
+{
+ int i;
+
+ for (i = 0; i< stop; i++) {
+ if (stmt[i] == p)
+ return 1;
+ }
+ return 0;
+}
+
+static int
OPTdatacyclotronImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk,
InstrPtr p)
{
- int i=0, actions=0, k=0, z=0, j=0, num_regs=DCYREGS, *tpes=NULL;
+ int i=0, actions=0, k=0, z=0, j=0, num_regs=DCYREGS, *tpes=NULL,
oldtop=0,slimit=0;
DCYcatalog **regs=NULL, *reg = NULL;
VarRecord low,hgh,max_hgh;
InstrPtr *old=NULL, new, matq;
- int limit;
+ int limit=0, errors=0;
int (*newArg)[1000]=NULL;
- char *used = NULL, *old_used = NULL;
+ char *used = NULL;
(void) stk;
(void) cntxt;
@@ -270,6 +282,8 @@
}
limit= mb->stop;
old = mb->stmt;
+ oldtop= mb->stop;
+ slimit = mb->ssize;
newMalBlkStmt(mb, mb->ssize);
pushInstruction(mb,old[0]);
@@ -277,16 +291,22 @@
p = old[i];
if ( num_regs <= (mb->vtop + 1000) ) {
+#ifdef BIND_DATACYCLOTRON_OPT
+ if ( !(tpes = GDKrealloc(tpes, (num_regs + DCYREGS) *
sizeof(int))) ){
+ errors = 1;
+ goto out;
+ }
+#endif
regs = GDKrealloc(regs, (num_regs + DCYREGS) *
sizeof(*regs));
- old_used = used;
- used = GDKzalloc((num_regs + DCYREGS) * sizeof(char));
- memcpy(used,old_used,num_regs*sizeof(char));
- GDKfree(old_used);
- old_used = NULL;
-#ifdef BIND_DATACYCLOTRON_OPT
- tpes = GDKrealloc(tpes, (num_regs + DCYREGS) *
sizeof(int));
-#endif
newArg = GDKrealloc(newArg, (num_regs + DCYREGS) *
sizeof(*newArg));
+ used = GDKrealloc(used, (num_regs + DCYREGS) *
sizeof(char));
+
+ if ( (used == NULL) || (newArg == NULL) || (regs ==
NULL) ) {
+ errors = 1;
+ goto out;
+ }
+
+ memset(used+num_regs, 0, DCYREGS * sizeof(char));
num_regs += DCYREGS;
}
@@ -428,12 +448,35 @@
}
+out:
OPTDEBUGdatacyclotron {
- mnstr_printf(cntxt->fdout,"LEAVING DATA CYCLOTRON \n");
+ if (errors && mb->errors)
+ mnstr_printf(cntxt->fdout,"DATA CYCLOTRON FAILED\n");
+ else
+ mnstr_printf(cntxt->fdout,"LEAVING DATA CYCLOTRON \n");
chkProgram(cntxt->nspace,mb);
printFunction(cntxt->fdout,mb,0,LIST_MAL_ALL);
}
-out:
+
+ if (old && (errors || mb->errors) ) {
+ actions= 0;
+ for(i=0; i<mb->stop; i++)
+ if (mb->stmt[i])
+ if (!check_instr(old, limit, mb->stmt[i]))
+ freeInstruction(mb->stmt[i]);
+ GDKfree(mb->stmt);
+ mb->stmt = old;
+ mb->ssize = slimit;
+ mb->stop = oldtop;
+ }
+
+ if (old && errors == 0 && mb->errors == 0) {
+ for(i=0; i < limit; i++)
+ if (!check_instr(mb->stmt, mb->stop, old[i]))
+ freeInstruction(old[i]);
+ GDKfree(old);
+ }
+
if (tpes)
GDKfree(tpes);
if (used)
@@ -442,11 +485,10 @@
GDKfree(newArg);
if (regs)
GDKfree(regs);
- if (old)
- GDKfree(old);
return actions;
}
+
@include optimizerWrapper.mx
@h
@:exportOptimizer(datacyclotron)@
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list