}
-/*-----------------------------------------------------------------*/
-/* allDefsOutOfRange - all definitions are out of a range */
-/*-----------------------------------------------------------------*/
-static bool
-allDefsOutOfRange (bitVect * defs, int fseq, int toseq)
-{
- int i;
-
- if (!defs)
- return TRUE;
-
- for (i = 0; i < defs->size; i++)
- {
- iCode *ic;
-
- if (bitVectBitValue (defs, i) &&
- (ic = hTabItemWithKey (iCodehTab, i)) &&
- (ic->seq >= fseq && ic->seq <= toseq))
-
- return FALSE;
-
- }
-
- return TRUE;
-}
/*-----------------------------------------------------------------*/
/* isOperandInReg - returns true if operand is currently in regs */
return sym->remat;
}
-/*-----------------------------------------------------------------*/
-/* notUsedInBlock - not used in this block */
-/*-----------------------------------------------------------------*/
-static int
-notUsedInBlock (symbol * sym, eBBlock * ebp, iCode * ic)
-{
- return (!bitVectBitsInCommon (sym->defs, ebp->usesDefs) &&
- allDefsOutOfRange (sym->defs, ebp->fSeq, ebp->lSeq) &&
- allDefsOutOfRange (sym->uses, ebp->fSeq, ebp->lSeq));
-/* return (!bitVectBitsInCommon(sym->defs,ebp->usesDefs)); */
-}
-
/*-----------------------------------------------------------------*/
/* notUsedInRemaining - not used or defined in remain of the block */
/*-----------------------------------------------------------------*/
we need to allocate this on the stack : this is really a
hack!! but cannot think of anything better at this time */
- if (sprintf (slocBuffer, "sloc%d", _G.slocNum++) >= sizeof (slocBuffer))
+ if (SNPRINTF (slocBuffer, sizeof(slocBuffer),
+ "sloc%d", _G.slocNum++) >= sizeof (slocBuffer))
{
fprintf (stderr, "***Internal error: slocBuffer overflowed: %s:%d\n",
__FILE__, __LINE__);
if ((selectS = liveRangesWith (lrcs, directSpilLoc, ebp, ic)))
{
sym = leastUsedLR (selectS);
- strcpy (sym->rname, (sym->usl.spillLoc->rname[0] ?
- sym->usl.spillLoc->rname :
- sym->usl.spillLoc->name));
+ strncpyz (sym->rname,
+ sym->usl.spillLoc->rname[0] ?
+ sym->usl.spillLoc->rname : sym->usl.spillLoc->name,
+ sizeof(sym->rname));
sym->spildir = 1;
/* mark it as allocation required */
sym->usl.spillLoc->allocreq++;
return reg;
assert(0);
+
+ /* just to make the compiler happy */
+ return 0;
}
/*-----------------------------------------------------------------*/
return reg;
assert(0);
+
+ /* just to make the compiler happy */
+ return 0;
}
/*-----------------------------------------------------------------*/
return change ;
}
+/*-----------------------------------------------------------------*/
+/* unusedLRS - returns a bitVector of liveranges not used in 'ebp' */
+/*-----------------------------------------------------------------*/
+bitVect *unusedLRs (eBBlock *ebp)
+{
+ bitVect *ret = NULL;
+ symbol *sym;
+ int key;
+
+ if (!ebp) return NULL;
+ for (sym = hTabFirstItem(liveRanges,&key); sym ;
+ sym = hTabNextItem(liveRanges,&key)) {
+
+ if (notUsedInBlock(sym,ebp,NULL)) {
+ ret = bitVectSetBit(ret,sym->key);
+ }
+ }
+
+ return ret;
+}
+
+/*-----------------------------------------------------------------*/
+/* deassignUnsedLRs - if this baisc block ends in a return then */
+/* deassign symbols not used in this block */
+/*-----------------------------------------------------------------*/
+bitVect *deassignUnsedLRs(eBBlock *ebp)
+{
+ bitVect *unused = NULL;
+ int i;
+
+ switch (returnAtEnd(ebp)) {
+ case 2: /* successor block ends in a return */
+ unused = unusedLRs((eBBlock *) setFirstItem(ebp->succList));
+ /* fall thru */
+ case 1: /* this block ends in a return */
+ unused = bitVectIntersect(unused,unusedLRs(ebp));
+ break;
+ }
+
+ if (unused) {
+ for (i = 0 ; i < unused->size ; i++ ) {
+
+ /* if unused */
+ if (bitVectBitValue(unused,i)) {
+
+ /* if assigned to registers */
+ if (bitVectBitValue(_G.regAssigned,i)) {
+ symbol *sym;
+ int j;
+
+ sym = hTabItemWithKey(liveRanges,i);
+ /* remove it from regassigned & mark the
+ register free */
+ bitVectUnSetBit(_G.regAssigned,i);
+ for (j = 0 ; j < sym->nRegs; j++)
+ freeReg(sym->regs[j]);
+ } else {
+ /* not assigned to registers : remove from set*/
+ bitVectUnSetBit(unused,i);
+ }
+ }
+ }
+ }
+ return unused;
+}
+
+/*-----------------------------------------------------------------*/
+/* reassignUnusedLRs - put registers to unused Live ranges */
+/*-----------------------------------------------------------------*/
+void reassignUnusedLRs (bitVect *unused)
+{
+ int i;
+ if (!unused) return ;
+
+ for (i = 0 ; i < unused->size ; i++ ) {
+ /* if unused : means it was assigned to registers before */
+ if (bitVectBitValue(unused,i)) {
+ symbol *sym;
+ int j;
+
+ /* put it back into reg set*/
+ bitVectSetBit(_G.regAssigned,i) ;
+
+ sym = hTabItemWithKey(liveRanges,i);
+ /* makr registers busy */
+ for (j = 0 ; j < sym->nRegs; j++)
+ sym->regs[j]->isFree = 0;
+ }
+ }
+}
+
/*-----------------------------------------------------------------*/
/* serialRegAssign - serially allocate registers to the variables */
/*-----------------------------------------------------------------*/
/* for all blocks */
for (i = 0; i < count; i++)
- {
+ { /* ebbs */
iCode *ic;
+ bitVect *unusedLRs = NULL;
if (ebbs[i]->noPath &&
(ebbs[i]->entryLabel != entryLabel &&
ebbs[i]->entryLabel != returnLabel))
continue;
-/* if (returnsAtEnd(ebbs[i])) */
+ unusedLRs = deassignUnsedLRs(ebbs[i]);
/* of all instructions do */
for (ic = ebbs[i]->sch; ic; ic = ic->next)
}
}
+ reassignUnusedLRs(unusedLRs);
}
}
sym->usl.spillLoc->allocreq--;
sym->usl.spillLoc = NULL;
}
-/* printf("Allocated %s in function %s to DPTR1\n",sym->name,currFunc->name); */
sym->nRegs = 0;
sym->isspilt = sym->spillA = 0;
}
bitVectBitValue(_G.totRegAssigned,i) == 0) /* and are still assigned to registers */
continue ;
- assert (clr = hTabItemWithKey(liveRanges,i));
+ clr = hTabItemWithKey(liveRanges,i);
+ assert(clr);
/* mark these registers as used */
for (k = 0 ; k < clr->nRegs ; k++ )
char *s = buffer;
iCode *ic = sym->rematiCode;
+ *s = 0;
+
while (1)
{
/* if plus or minus print the right hand side */
if (ic->op == '+' || ic->op == '-')
{
- sprintf (s, "0x%04x %c ", (int) operandLitValue (IC_RIGHT (ic)),
- ic->op);
+ SNPRINTF (s, sizeof(buffer) - strlen(buffer),
+ "0x%04x %c ", (int) operandLitValue (IC_RIGHT (ic)),
+ ic->op);
s += strlen (s);
ic = OP_SYMBOL (IC_LEFT (ic))->rematiCode;
continue;
continue;
}
/* we reached the end */
- sprintf (s, "%s", OP_SYMBOL (IC_LEFT (ic))->rname);
+ SNPRINTF (s, sizeof(buffer) - strlen(buffer),
+ "%s", OP_SYMBOL (IC_LEFT (ic))->rname);
break;
}
}
/* if the symbol has only one definition &
- that definition is a get_pointer and the
- pointer we are getting is rematerializable and
- in "data" space */
-
+ that definition is a get_pointer */
if (bitVectnBitsOn (sym->defs) == 1 &&
(ic = hTabItemWithKey (iCodehTab,
bitVectFirstBit (sym->defs))) &&
!sym->noSpilLoc &&
!IS_BITVAR (sym->etype))
{
-
-
- /* if remat in data space */
+ /* and that pointer is remat in data space */
if (OP_SYMBOL (IC_LEFT (ic))->remat &&
!IS_CAST_ICODE(OP_SYMBOL (IC_LEFT (ic))->rematiCode) &&
- DCL_TYPE (aggrToPtr (sym->type, FALSE)) == POINTER)
+ DCL_TYPE (aggrToPtr (operandType(IC_LEFT(ic)), FALSE)) == POINTER)
{
/* create a psuedo symbol & force a spil */
symbol *psym = newSymbol (rematStr (OP_SYMBOL (IC_LEFT (ic))), 1);
psym->type = sym->type;
psym->etype = sym->etype;
- strcpy (psym->rname, psym->name);
+ strncpyz (psym->rname, psym->name, sizeof(psym->rname));
sym->isspilt = 1;
sym->usl.spillLoc = psym;
continue;
remiCodeFromeBBlock (ebp, ic);
bitVectUnSetBit(OP_SYMBOL(IC_RESULT(ic))->defs,ic->key);
hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL);
- OP_DEFS (IC_RESULT (dic)) = bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key);
+ OP_DEFS_SET ((IC_RESULT (dic)), bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key));
return 1;
}
continue ;
if (ic->op == SEND ) {
- if (ic->argreg != 1) return 0;
+ if (ic->argreg != 1 ) return 0;
else continue ;
}
/* two special cases first */
nfs++;
}
+ if (nfs && IC_RESULT(ic) && IS_SYMOP(IC_RESULT(ic)) &&
+ OP_SYMBOL(IC_RESULT(ic))->ruonly) return 0;
+
if (nfs > 1) return 0;
}
OP_SYMBOL(op)->dptr = dptr;
if (ic->op == PCALL) return NULL;
/* if SEND & not the first parameter then giveup */
- if (ic->op == SEND && ic->argreg != 1) return NULL;
+ if (ic->op == SEND && ic->argreg != 1 &&
+ ((isOperandInFarSpace(IC_LEFT(ic)) && !isOperandInReg(IC_LEFT(ic))) ||
+ isOperandEqual(op,IC_LEFT(ic)))) return NULL;
/* if CALL then make sure it is VOID || return value not used
or the return value is assigned to this one */
if (IC_LEFT(ic) && IS_SYMOP(IC_LEFT(ic)) &&
!isOperandEqual(IC_LEFT(ic),op) &&
- (OP_SYMBOL(IC_LEFT(ic))->liveTo > ic->seq ||
+ (OP_SYMBOL(IC_LEFT(ic))->liveTo >= ic->seq ||
IS_TRUE_SYMOP(IC_LEFT(ic)) ||
OP_SYMBOL(IC_LEFT(ic))->ruonly) &&
( ( isOperandInFarSpace(IC_LEFT(ic)) || OP_SYMBOL(IC_LEFT(ic))->onStack) &&
return NULL;
}
OP_SYMBOL(op)->ruonly = 1;
+ if (OP_SYMBOL(op)->usl.spillLoc) {
+ if (OP_SYMBOL(op)->spillA)
+ OP_SYMBOL(op)->usl.spillLoc->allocreq--;
+ OP_SYMBOL(op)->usl.spillLoc = NULL;
+ }
return dic;
}
if (dic->op != '=' || POINTER_SET (dic))
return;
+
+ if (dic->eBBlockNum != ic->eBBlockNum) return ;
/* make sure the right side does not have any definitions
inbetween */
return;
}
/* extend the live range of replaced operand if needed */
- if (OP_SYMBOL(IC_RIGHT(dic))->liveTo < ic->seq) {
- OP_SYMBOL(IC_RIGHT(dic))->liveTo = ic->seq;
+ if (OP_SYMBOL(IC_RIGHT(dic))->liveTo < OP_SYMBOL(IC_LEFT(ic))->liveTo) {
+ OP_SYMBOL(IC_RIGHT(dic))->liveTo = OP_SYMBOL(IC_LEFT(ic))->liveTo;
+ OP_SYMBOL(IC_RIGHT(dic))->clashes =
+ bitVectUnion(OP_SYMBOL(IC_RIGHT(dic))->clashes,
+ OP_SYMBOL(IC_LEFT(ic))->clashes);
}
for (lic = ic; lic && lic != dic; lic = lic->prev)
{
getSize (operandType(IC_RESULT(ic))) <= 3)
OP_SYMBOL (IC_RESULT(ic))->uptr = 1;
+ if (ic->op == SEND && ic->argreg == 1 &&
+ getSize (aggrToPtr(operandType(IC_LEFT(ic)),FALSE)) <= 3)
+ OP_SYMBOL (IC_LEFT(ic))->uptr = 1;
+
if (!SKIP_IC2 (ic))
{
/* if we are using a symbol on the stack
remiCodeFromeBBlock (ebp, ic);
bitVectUnSetBit(OP_SYMBOL(IC_RESULT(ic))->defs,ic->key);
hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL);
- OP_DEFS (IC_RESULT (dic)) = bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key);
+ OP_DEFS_SET ((IC_RESULT (dic)), bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key));
ic = ic->prev;
}
else
remiCodeFromeBBlock (ebp, ic);
bitVectUnSetBit(OP_SYMBOL(IC_RESULT(ic))->defs,ic->key);
hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL);
- OP_DEFS (IC_RESULT (dic)) = bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key);
+ OP_DEFS_SET ((IC_RESULT (dic)), bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key));
ic = ic->prev;
}
}