hTab *iCodehTab = NULL;
hTab *iCodeSeqhTab = NULL;
+/*-----------------------------------------------------------------*/
+/* hashiCodeKeys - add all iCodes to the hash table */
+/*-----------------------------------------------------------------*/
+void
+hashiCodeKeys (eBBlock ** ebbs, int count)
+{
+ int i;
+
+ for (i = 0; i < count; i++)
+ {
+ iCode *ic;
+ for (ic = ebbs[i]->sch; ic; ic = ic->next)
+ hTabAddItem (&iCodehTab, ic->key, ic);
+ }
+}
+
/*-----------------------------------------------------------------*/
/* sequenceiCode - creates a sequence number for the iCode & add */
/*-----------------------------------------------------------------*/
{
ic->seq = ++iCodeSeq;
ic->depth = ebbs[i]->depth;
- hTabAddItem (&iCodehTab, ic->key, ic);
+ //hTabAddItem (&iCodehTab, ic->key, ic);
hTabAddItem (&iCodeSeqhTab, ic->seq, ic);
}
ebbs[i]->lSeq = iCodeSeq;
if (ebp->visited)
return 0;
- ebp->visited = 1;
+ if (ic == ebp->sch)
+ ebp->visited = 1;
/* for all remaining instructions in current block */
for (uic = ic; uic; uic = uic->next)
if (retval)
{
- markAlive (ic, ebp->ech, sym->key);
+ if (ic) markAlive (ic, ebp->ech, sym->key);
return 1;
}
OP_SYMBOL (op)->used += 1;
}
+/*-----------------------------------------------------------------*/
+/* rliveClear - clears the rlive bitVectors */
+/*-----------------------------------------------------------------*/
+void
+rliveClear (eBBlock ** ebbs, int count)
+{
+ int i;
+
+ /* for all blocks do */
+ for (i = 0; i < count; i++)
+ {
+ iCode *ic;
+
+ /* for all instructions in this block do */
+ for (ic = ebbs[i]->sch; ic; ic = ic->next)
+ {
+ freeBitVect (ic->rlive);
+ ic->rlive = NULL;
+ }
+ }
+}
+
/*-----------------------------------------------------------------*/
/* rlivePoint - for each point compute the ranges that are alive */
/*-----------------------------------------------------------------*/
iCode *lic;
for (lic = ic; lic; lic = lic->next)
{
- if (lic->op == CALL)
+ if (lic->op == CALL || lic->op == PCALL)
{
markAlive (ic, lic->prev, IC_LEFT (ic)->key);
break;
}
}
+ if (POINTER_SET(ic) && IS_SYMOP(IC_RESULT(ic)))
+ incUsed (ic, IC_RESULT(ic));
+
if (IS_ITEMP(IC_RESULT(ic)))
{
unvisitBlocks(ebbs, count);
alive = succ->sch->rlive;
while ((succ = setNextItem (ebbs[i]->succList)))
{
- alive = bitVectIntersect (alive, succ->sch->rlive);
+ if (succ->sch)
+ alive = bitVectIntersect (alive, succ->sch->rlive);
}
- alive = bitVectCplAnd ( bitVectCopy (ebbs[i]->ech->rlive), alive);
+ if (ebbs[i]->ech)
+ alive = bitVectCplAnd ( bitVectCopy (ebbs[i]->ech->rlive), alive);
for (key = 1; key < alive->size; key++)
{
IS_ITEMP(IC_RESULT(ic)) &&
(IS_ITEMP(IC_LEFT(ic)) || IS_ITEMP(IC_RIGHT(ic))))
{
- if (OP_SYMBOL(IC_RESULT(ic))->key == key1)
+ if (OP_SYMBOL(IC_RESULT(ic))->key == key1
+ && sym1->liveFrom == ic->seq
+ && sym2->liveTo == ic->seq)
{
if (IS_SYMOP(IC_LEFT(ic)))
if (OP_SYMBOL(IC_LEFT(ic))->key == key2)
continue;
}
- if (OP_SYMBOL(IC_RESULT(ic))->key == key2)
+ if (OP_SYMBOL(IC_RESULT(ic))->key == key2
+ && sym2->liveFrom == ic->seq
+ && sym1->liveTo == ic->seq)
{
if (IS_SYMOP(IC_LEFT(ic)))
if (OP_SYMBOL(IC_LEFT(ic))->key == key1)
continue;
ic = ebbs[i]->sch;
+
+ /* is there any code for this eBBlock? (e.g. ROM assignment) */
+ if(!ic)continue;
+
while (ic->prev)
ic = ic->prev;
ebbs[i]->sch = ic;
iCodeSeq = 0;
setToNull ((void *) &iCodehTab);
iCodehTab = newHashTable (iCodeKey);
+ hashiCodeKeys (ebbs, count);
setToNull ((void *) &iCodeSeqhTab);
iCodeSeqhTab = newHashTable (iCodeKey);
sequenceiCode (ebbs, count);
computeClash(ebbs, count);
}
+/*-----------------------------------------------------------------*/
+/* recomputeLiveRanges - recomputes the live ranges for variables */
+/*-----------------------------------------------------------------*/
+void
+recomputeLiveRanges (eBBlock ** ebbs, int count)
+{
+ symbol * sym;
+ int key;
+
+ /* clear all rlive bitVectors */
+ rliveClear (ebbs, count);
+
+ sym = hTabFirstItem (liveRanges, &key);
+ if (sym)
+ {
+ do {
+ sym->used = 0;
+ sym->liveFrom = 0;
+ sym->liveTo = 0;
+ freeBitVect (sym->clashes);
+ sym->clashes = NULL;
+ } while ( (sym = hTabNextItem (liveRanges, &key)));
+ }
+
+ /* do the LR computation again */
+ computeLiveRanges (ebbs, count);
+}
+