}
/*-----------------------------------------------------------------*/
-/* appendDumpFile - if not already created, create the dump file */
+/* createDumpFile - create the dump file */
/*-----------------------------------------------------------------*/
-FILE *appendDumpFile (int id) {
+FILE *createDumpFile (int id) {
struct _dumpFiles *dumpFilesPtr=dumpFiles;
while (dumpFilesPtr->id) {
}
if (!dumpFilesPtr->id) {
- fprintf (stdout, "internal error: appendDumpFile: unknown dump file.\n");
+ fprintf (stdout, "internal error: createDumpFile: unknown dump file.\n");
exit (1);
}
for (dumpFilesPtr=dumpFiles; dumpFilesPtr->id; dumpFilesPtr++) {
if (dumpFilesPtr->filePtr) {
fclose (dumpFilesPtr->filePtr);
- //dprintf ("closed %s\n", dumpFilesPtr->ext);
}
}
}
int k;
if (id) {
- file=appendDumpFile(id);
+ file=createDumpFile(id);
} else {
file = stdout;
}
int i;
if (id) {
- of=appendDumpFile(id);
+ of=createDumpFile(id);
} else {
of = stdout;
}
for (i = 0; i < count; i++)
{
fprintf (of, "\n----------------------------------------------------------------\n");
- fprintf (of, "Basic Block %s : loop Depth(lSeq) = %d(%d) noPath = %d , lastinLoop = %d\n",
+ fprintf (of, "Basic Block %d %s : loop Depth = %d noPath = %d lastinLoop = %d\n",
+ ebbs[i]->dfnum,
ebbs[i]->entryLabel->name,
ebbs[i]->depth,
- (0 /* for now */ &
- ebbs[i]->depth) ? findLoopEndSeq(ebbs[i]->partOfLoop) : 0,
ebbs[i]->noPath,
ebbs[i]->isLastInLoop);
fprintf (of, "\ndefines bitVector :");
iCode2eBBlock (iCode * ic)
{
iCode *loop;
- eBBlock *ebb = neweBBlock (); /* a llocate an entry */
+ eBBlock *ebb = neweBBlock (); /* allocate an entry */
/* put the first one unconditionally */
ebb->sch = ic;
/* if this is a label then */
if (ic->op == LABEL)
- ebb->entryLabel = ic->argLabel.label;
+ ebb->entryLabel = ic->label;
else
{
SNPRINTF (buffer, sizeof(buffer), "_eBBlock%d", eBBNum++);
{
bitVectUnSetBit (OP_USES (IC_COND (ic)), ic->key);
IC_COND (ic) = operandFromOperand (dest);
- OP_USES_SET ((dest), bitVectSetBit (OP_USES (dest), ic->key));
+ OP_USES(dest)=bitVectSetBit (OP_USES (dest), ic->key);
continue;
}
bitVectUnSetBit (OP_USES (IC_RIGHT (ic)), ic->key);
IC_RIGHT (ic) = operandFromOperand (dest);
IC_RIGHT (ic)->isaddr = 0;
- OP_USES_SET ((dest), bitVectSetBit (OP_USES (dest), ic->key));
+ OP_USES(dest)=bitVectSetBit (OP_USES (dest), ic->key);
}
if (isOperandEqual (IC_LEFT (ic), src))
IC_LEFT (ic) = operandFromOperand (dest);
IC_LEFT (ic)->isaddr = 0;
}
- OP_USES_SET ((dest), bitVectSetBit (OP_USES (dest), ic->key));
+ OP_USES(dest)=bitVectSetBit (OP_USES (dest), ic->key);
}
/* special case for pointer sets */
bitVectUnSetBit (OP_USES (IC_RESULT (ic)), ic->key);
IC_RESULT (ic) = operandFromOperand (dest);
IC_RESULT (ic)->isaddr = 1;
- OP_USES_SET ((dest), bitVectSetBit (OP_USES (dest), ic->key));
+ OP_USES(dest)=bitVectSetBit (OP_USES (dest), ic->key);
}
}
}
static int localLbl = 0;
symbol *localLabel;
- SNPRINTF(buffer, sizeof(buffer), "_and_%d", localLbl++);
+ SNPRINTF(buffer, sizeof(buffer), "_andif_%d", localLbl++);
localLabel = newSymbol (buffer, NestLevel);
tree->left = backPatchLabels (tree->left, localLabel, falseLabel);
static int localLbl = 0;
symbol *localLabel;
- SNPRINTF(buffer, sizeof(buffer), "_or_%d", localLbl++);
+ SNPRINTF(buffer, sizeof(buffer), "_orif_%d", localLbl++);
localLabel = newSymbol (buffer, NestLevel);
tree->left = backPatchLabels (tree->left, trueLabel, localLabel);
switch (ic->op)
{
case GOTO: /* goto has edge to label */
- succ = eBBWithEntryLabel (ebbs, ic->argLabel.label, count);
+ succ = eBBWithEntryLabel (ebbs, ic->label, count);
break;
case IFX: /* conditional jump */
{
bitVectUnSetBit (OP_USES (from), lic->key);
- OP_USES_SET ((to), bitVectSetBit (OP_USES (to), lic->key));
+ OP_USES(to)=bitVectSetBit (OP_USES (to), lic->key);
siaddr = IC_COND (lic)->isaddr;
IC_COND (lic) = operandFromOperand (to);
IC_COND (lic)->isaddr = siaddr;
{
bitVectUnSetBit (OP_USES (from), lic->key);
- OP_USES_SET ((to), bitVectSetBit (OP_USES (to), lic->key));
+ OP_USES(to)=bitVectSetBit (OP_USES (to), lic->key);
siaddr = IC_COND (lic)->isaddr;
IC_JTCOND (lic) = operandFromOperand (to);
IC_JTCOND (lic)->isaddr = siaddr;
if (POINTER_SET (lic))
{
bitVectUnSetBit (OP_USES (from), lic->key);
- OP_USES_SET ((to), bitVectSetBit (OP_USES (to), lic->key));
+ OP_USES(to)=bitVectSetBit (OP_USES (to), lic->key);
/* also check if the "from" was in the non-dominating
pointer sets and replace it with "to" in the bitVector */
else
{
bitVectUnSetBit (OP_DEFS (from), lic->key);
- OP_DEFS_SET ((to), bitVectSetBit (OP_DEFS (to), lic->key));
+ OP_DEFS(to)=bitVectSetBit (OP_DEFS (to), lic->key);
}
siaddr = IC_RESULT (lic)->isaddr;
IC_RESULT (lic) = operandFromOperand (to);
IC_RIGHT (lic) && IC_RIGHT (lic)->key == from->key)
{
bitVectUnSetBit (OP_USES (from), lic->key);
- OP_USES_SET ((to), bitVectSetBit (OP_USES (to), lic->key));
+ OP_USES(to)=bitVectSetBit (OP_USES (to), lic->key);
siaddr = IC_RIGHT (lic)->isaddr;
IC_RIGHT (lic) = operandFromOperand (to);
IC_RIGHT (lic)->isaddr = siaddr;
IC_LEFT (lic) && IC_LEFT (lic)->key == from->key)
{
bitVectUnSetBit (OP_USES (from), lic->key);
- OP_USES_SET ((to), bitVectSetBit (OP_USES (to), lic->key));
+ OP_USES(to)=bitVectSetBit (OP_USES (to), lic->key);
siaddr = IC_LEFT (lic)->isaddr;
IC_LEFT (lic) = operandFromOperand (to);
IC_LEFT (lic)->isaddr = siaddr;
/* if it remains an IFX the update the use Set */
- OP_USES_SET ((IC_COND (ic)), bitVectSetBit (OP_USES (IC_COND (ic)), ic->key));
+ OP_USES(IC_COND (ic))=bitVectSetBit (OP_USES (IC_COND (ic)), ic->key);
setUsesDefs (IC_COND (ic), ebb->defSet, ebb->outDefs, &ebb->usesDefs);
return;
}
/* for all the instructions in this block do */
for (ic = ebb->sch; ic; ic = ic->next)
{
-
iCode *pdic;
operand *pdop;
iCode *defic;
if (ic->op == PCALL || ic->op == CALL || ic->op == RECEIVE)
{
/* add to defSet of the symbol */
- OP_DEFS_SET ((IC_RESULT (ic)),
- bitVectSetBit (OP_DEFS (IC_RESULT (ic)), ic->key));
+ OP_DEFS(IC_RESULT (ic))=
+ bitVectSetBit (OP_DEFS (IC_RESULT (ic)), ic->key);
/* add to the definition set of this block */
ebb->defSet = bitVectSetBit (ebb->defSet, ic->key);
ebb->ldefs = bitVectSetBit (ebb->ldefs, ic->key);
/* the lookup could have changed it */
if (IS_SYMOP (IC_LEFT (ic)))
{
- OP_USES_SET ((IC_LEFT (ic)),
- bitVectSetBit (OP_USES (IC_LEFT (ic)), ic->key));
+ OP_USES(IC_LEFT (ic))=
+ bitVectSetBit (OP_USES (IC_LEFT (ic)), ic->key);
setUsesDefs (IC_LEFT (ic), ebb->defSet,
ebb->outDefs, &ebb->usesDefs);
}
/* if jumptable then mark the usage */
if (ic->op == JUMPTABLE)
{
- OP_USES_SET ((IC_JTCOND (ic)),
- bitVectSetBit (OP_USES (IC_JTCOND (ic)), ic->key));
+ OP_USES(IC_JTCOND (ic))=
+ bitVectSetBit (OP_USES (IC_JTCOND (ic)), ic->key);
setUsesDefs (IC_JTCOND (ic), ebb->defSet,
ebb->outDefs, &ebb->usesDefs);
continue;
/* add the left & right to the defUse set */
if (IC_LEFT (ic) && IS_SYMOP (IC_LEFT (ic)))
{
- OP_USES_SET ((IC_LEFT (ic)),
- bitVectSetBit (OP_USES (IC_LEFT (ic)), ic->key));
+ OP_USES(IC_LEFT (ic))=
+ bitVectSetBit (OP_USES (IC_LEFT (ic)), ic->key);
setUsesDefs (IC_LEFT (ic), ebb->defSet, ebb->outDefs, &ebb->usesDefs);
}
if (IC_RIGHT (ic) && IS_SYMOP (IC_RIGHT (ic)))
{
- OP_USES_SET ((IC_RIGHT (ic)),
- bitVectSetBit (OP_USES (IC_RIGHT (ic)), ic->key));
+ OP_USES(IC_RIGHT (ic))=
+ bitVectSetBit (OP_USES (IC_RIGHT (ic)), ic->key);
setUsesDefs (IC_RIGHT (ic), ebb->defSet, ebb->outDefs, &ebb->usesDefs);
}
/* in the defuseSet if it a pointer or array access */
if (POINTER_SET (defic))
{
- OP_USES_SET ((IC_RESULT (ic)),
- bitVectSetBit (OP_USES (IC_RESULT (ic)), ic->key));
+ OP_USES(IC_RESULT (ic))=
+ bitVectSetBit (OP_USES (IC_RESULT (ic)), ic->key);
setUsesDefs (IC_RESULT (ic), ebb->defSet, ebb->outDefs, &ebb->usesDefs);
deleteItemIf (&cseSet, ifPointerGet, IC_RESULT (ic));
ebb->ptrsSet = bitVectSetBit (ebb->ptrsSet, IC_RESULT (ic)->key);
else
/* add the result to defintion set */ if (IC_RESULT (ic))
{
- OP_DEFS_SET ((IC_RESULT (ic)),
- bitVectSetBit (OP_DEFS (IC_RESULT (ic)), ic->key));
+ OP_DEFS(IC_RESULT (ic))=
+ bitVectSetBit (OP_DEFS (IC_RESULT (ic)), ic->key);
ebb->defSet = bitVectSetBit (ebb->defSet, ic->key);
ebb->outDefs = bitVectCplAnd (ebb->outDefs, OP_DEFS (IC_RESULT (ic)));
ebb->ldefs = bitVectSetBit (ebb->ldefs, ic->key);
{ARRAYINIT, "arrayInit", picGenericOne, NULL},
};
-// this makes it more easy to catch bugs
-struct bitVect *OP_DEFS(struct operand *op) {
- wassert (IS_SYMOP(op));
- return OP_SYMBOL(op)->defs;
-}
-struct bitVect *OP_DEFS_SET(struct operand *op, struct bitVect *bv) {
- wassert (IS_SYMOP(op));
- OP_SYMBOL(op)->defs=bv;
- return bv;
-}
-struct bitVect *OP_USES(struct operand *op) {
- wassert (IS_SYMOP(op));
- return OP_SYMBOL(op)->uses;
-}
-struct bitVect *OP_USES_SET(struct operand *op, struct bitVect *bv) {
- wassert (IS_SYMOP(op));
- OP_SYMBOL(op)->uses=bv;
- return bv;
-}
-
/*-----------------------------------------------------------------*/
/* checkConstantRange: check a constant against the type */
/*-----------------------------------------------------------------*/
ic = newiCode (op, NULL, NULL);
ic->op = op;
- ic->argLabel.label = label;
+ ic->label = label;
IC_LEFT (ic) = NULL;
IC_RIGHT (ic) = NULL;
IC_RESULT (ic) = NULL;
/* assign */
operand *top = operandFromSymbol (argVals->sym);
/* clear useDef and other bitVectors */
- OP_USES_SET ((top), OP_DEFS_SET ((top), OP_SYMBOL(top)->clashes = NULL));
+ OP_USES(top)=OP_DEFS(top)=OP_SYMBOL(top)->clashes = NULL;
geniCodeAssign (top, pval, 1);
}
else
#define IC_COND(x) (x)->ulrrcnd.cnd.condition
#define IC_TRUE(x) (x)->ulrrcnd.cnd.trueLabel
#define IC_FALSE(x) (x)->ulrrcnd.cnd.falseLabel
-#define IC_LABEL(x) (x)->argLabel.label
-// jwk #define IC_ARGS(x) (x)->argLabel.args
+#define IC_LABEL(x) (x)->label
#define IC_JTCOND(x) (x)->ulrrcnd.jmpTab.condition
#define IC_JTLABELS(x) (x)->ulrrcnd.jmpTab.labels
#define IC_INLINE(x) (x)->inlineAsm
}
ulrrcnd;
- union
- {
- symbol *label; /* for a goto statement */
- // jwk value *args; /* for a function */
- }
- argLabel;
+ symbol *label; /* for a goto statement */
char *inlineAsm; /* pointer to inline assembler code */
literalList *arrayInitList; /* point to array initializer list. */
#define SET_RESULT_RIGHT(ic) {SET_ISADDR(IC_RIGHT(ic),0); SET_ISADDR(IC_RESULT(ic),0);}
#define IS_ASSIGN_ICODE(ic) (ASSIGNMENT(ic) && !POINTER_SET(ic))
-#if 0 // this causes too much, extremely difficult to find, bugs
- #define OP_DEFS(op) op->operand.symOperand->defs
- #define OP_USES(op) op->operand.symOperand->uses
-#else
- struct bitVect *OP_DEFS(struct operand *);
- struct bitVect *OP_DEFS_SET(struct operand *, struct bitVect *);
- struct bitVect *OP_USES(struct operand *);
- struct bitVect *OP_USES_SET(struct operand *, struct bitVect *);
-#endif
+#define OP_DEFS(op) validateOpType(op, "OP_DEFS", #op, SYMBOL, __FILE__, __LINE__)->operand.symOperand->defs
+#define OP_USES(op) validateOpType(op, "OP_USES", #op, SYMBOL, __FILE__, __LINE__)->operand.symOperand->uses
/*-----------------------------------------------------------------*/
/* forward references for functions */
/*-----------------------------------------------------------------*/
hTab *labelDef = NULL;
/*-----------------------------------------------------------------*/
-/* buildLabelRefTable - creates an hashTable of label referneces */
+/* buildLabelRefTable - creates an hashTable of label references */
/*-----------------------------------------------------------------*/
void
buildLabelRefTable (iCode * ic)
if (loop->op == GOTO && /* if this is a goto */
loop->next && /* and we have a next one */
loop->next->op == LABEL && /* next one is a label */
- loop->next->argLabel.label->key == loop->argLabel.label->key) /* same label */
+ loop->next->label->key == loop->label->key) /* same label */
{
loop->prev->next = loop->next; /* get this out of the chain */
loop->next->prev = loop->prev;
stat->next != loop)
{
- symbol *repLabel = stat->next->argLabel.label; /* replace with label */
+ symbol *repLabel = stat->next->label; /* replace with label */
/* if they are the same then continue */
if (repLabel->key == sLabel->key)
case GOTO: /* for a goto statement */
hTabDeleteItem (&labelRef, (IC_LABEL (loop))->key, loop, DELETE_ITEM, NULL);
- loop->argLabel.label = repLabel;
+ loop->label = repLabel;
hTabAddItem (&labelRef, repLabel->key, loop);
break;
}
/*-----------------------------------------------------------------*/
-/* labelUnrefLabel - remove unreferneced labels */
+/* labelUnrefLabel - remove unreferenced labels */
/*-----------------------------------------------------------------*/
int
labelUnrefLabel (iCode * ic)
/* if this is a label */
if (loop->op == LABEL)
{
- set *refs;
-
- refs = NULL;
if (((IC_LABEL (loop))->key == returnLabel->key) ||
((IC_LABEL (loop))->key == entryLabel->key))
continue;
if (ebbs[i]->dfnum > dfMin &&
ebbs[i]->dfnum < dfMax &&
!isinSet(aloop->regBlocks,ebbs[i])) {
- if (!ebbs[i]->partOfLoop) ebbs[i]->partOfLoop = aloop;
+ if (!ebbs[i]->partOfLoop) {
+#if !defined(LIVERANGEHUNT)
+ ebbs[i]->partOfLoop = aloop;
+#else
+ loopInsert(&aloop->regBlocks,ebbs[i]);
+#endif
+ }
}
- LRH(printf("****** %d %d %d %x %s\n", ebbs[i]->dfnum, dfMin, dfMax, ebbs[i]->partOfLoop, ebbs[i]->entryLabel->name));
}
+#ifdef LIVERANGEHUNT
+ printf ("================\n");
+ printf (" loop with entry -- > ");
+ printEntryLabel (aloop->entry, ap);
+ printf ("\n");
+ printf (" loop body --> ");
+ applyToSet (aloop->regBlocks, printEntryLabel);
+ printf ("\n");
+ printf (" loop exits --> ");
+ applyToSet (aloop->exits, printEntryLabel);
+ printf ("\n");
+#endif
+
/* and if this is a conditional block, the other side of the IFX
(if any, that could have a greater dfnum) is too */
{
!IS_OP_VOLATILE (op) &&
assignmentsToSym (theLoop->regBlocks, op) == 0)
opin = 1;
+ LRH(if (opin && IS_SYMOP(op)) {
+ printf("isOperandInvariant: %s\n", OP_SYMBOL(op)->name);
+ });
}
else
opin++;
iCode *newic = newiCode ('=', NULL,
operandFromOperand (IC_RIGHT (ic)));
IC_RESULT (newic) = operandFromOperand (IC_RESULT (ic));
- OP_DEFS_SET ((IC_RESULT (newic)),
- bitVectSetBit (OP_DEFS (IC_RESULT (newic)), newic->key));
- OP_USES_SET ((IC_RIGHT (newic)),
- bitVectSetBit (OP_USES (IC_RIGHT (newic)), newic->key));
+ OP_DEFS(IC_RESULT (newic))=
+ bitVectSetBit (OP_DEFS (IC_RESULT (newic)), newic->key);
+ OP_USES(IC_RIGHT (newic))=
+ bitVectSetBit (OP_USES (IC_RIGHT (newic)), newic->key);
/* and add it */
if (eblock->sch && eblock->sch->op == LABEL)
addiCodeToeBBlock (eblock, newic, eblock->sch->next);
int maxDepth = 0;
region *lp;
- LRH(printf ("createLoopRegions: %x\n", ebbs));
+ LRH(printf ("createLoopRegions: %p\n", ebbs));
/* get all the back edges in the graph */
if (!applyToSet (graphEdges, backEdges, &bEdges))
return 0; /* found no loops */
#define OPTION_DATA_LOC "--data-loc"
#define OPTION_CODE_LOC "--code-loc"
#define OPTION_IDATA_LOC "--idata-loc"
+#define OPTION_NO_LABEL_OPT "--nolabelopt"
#define OPTION_NO_LOOP_INV "--noinvariant"
#define OPTION_NO_LOOP_IND "--noinduction"
#define OPTION_LESS_PEDANTIC "--lesspedantic"
{ 0, "--stack-10bit", &options.stack10bit, "use the 10bit stack for ds390 (default)" },
{ 0, "--xstack", &options.useXstack, "Use external stack" },
{ 0, OPTION_NO_GCSE, NULL, "Disable the GCSE optimisation" },
+ { 0, OPTION_NO_LABEL_OPT, NULL, "Disable label optimisation" },
{ 0, OPTION_NO_LOOP_INV, NULL, "Disable optimisation of invariants" },
{ 0, OPTION_NO_LOOP_IND, NULL, NULL },
{ 0, "--nojtbound", &optimize.noJTabBoundary, "Don't generate boundary check for jump tables" },
continue;
}
+ if (strcmp (argv[i], OPTION_NO_LABEL_OPT) == 0)
+ {
+ optimize.label4 = 0;
+ continue;
+ }
+
if (strcmp (argv[i], OPTION_NO_LOOP_IND) == 0)
{
optimize.loopInduction = 0;