};
#else
+
+int Gstack_base_addr=0x38; /* The starting address of registers that
+ * are used to pass and return parameters */
regs regspic14[] =
{
{REG_GPR, PO_GPR_TEMP, 0x20, "r0x20", "r0x20", 0x20, 1, 0},
{REG_GPR, PO_GPR_TEMP, 0x35, "r0x35", "r0x35", 0x35, 1, 0},
{REG_GPR, PO_GPR_TEMP, 0x36, "r0x36", "r0x36", 0x36, 1, 0},
{REG_GPR, PO_GPR_TEMP, 0x37, "r0x37", "r0x37", 0x37, 1, 0},
+ {REG_STK, PO_GPR_TEMP, 0x38, "r0x38", "r0x38", 0x38, 1, 0},
+ {REG_STK, PO_GPR_TEMP, 0x39, "r0x39", "r0x39", 0x39, 1, 0},
+ {REG_STK, PO_GPR_TEMP, 0x3A, "r0x3A", "r0x3A", 0x3A, 1, 0},
+ {REG_STK, PO_GPR_TEMP, 0x3B, "r0x3B", "r0x3B", 0x3B, 1, 0},
+ {REG_STK, PO_GPR_TEMP, 0x3C, "r0x3C", "r0x3C", 0x3C, 1, 0},
+ {REG_STK, PO_GPR_TEMP, 0x3D, "r0x3D", "r0x3D", 0x3D, 1, 0},
+ {REG_STK, PO_GPR_TEMP, 0x3E, "r0x3E", "r0x3E", 0x3E, 1, 0},
+ {REG_STK, PO_GPR_TEMP, 0x3F, "r0x3F", "r0x3F", 0x3F, 1, 0},
+ {REG_STK, PO_GPR_TEMP, 0x40, "r0x40", "r0x40", 0x40, 1, 0},
+ {REG_STK, PO_GPR_TEMP, 0x41, "r0x41", "r0x41", 0x41, 1, 0},
+ {REG_STK, PO_GPR_TEMP, 0x42, "r0x42", "r0x42", 0x42, 1, 0},
+ {REG_STK, PO_GPR_TEMP, 0x43, "r0x43", "r0x43", 0x43, 1, 0},
+ {REG_STK, PO_GPR_TEMP, 0x44, "r0x44", "r0x44", 0x44, 1, 0},
+ {REG_STK, PO_GPR_TEMP, 0x45, "r0x45", "r0x45", 0x45, 1, 0},
+ {REG_STK, PO_GPR_TEMP, 0x46, "r0x46", "r0x46", 0x46, 1, 0},
+ {REG_STK, PO_GPR_TEMP, 0x47, "r0x47", "r0x47", 0x47, 1, 0},
+
+ {REG_SFR, PO_GPR_REGISTER, IDX_KZ, "KZ", "KZ", IDX_KZ, 1, 0}, /* Known zero */
+
+
+ {REG_STK, PO_FSR, IDX_FSR, "FSR", "FSR", IDX_FSR, 1, 0},
+ {REG_STK, PO_INDF, IDX_INDF, "INDF", "INDF", IDX_INDF, 1, 0},
- {REG_PTR, PO_FSR, 4, "FSR", "FSR", 4, 1, 0},
};
{
int i;
- debugLog ("%s\n", __FUNCTION__);
+ debugLog ("%s - requesting index = 0x%x\n", __FUNCTION__,idx);
for (i = 0; i < pic14_nRegs; i++)
if (regspic14[i].rIdx == idx)
return ®spic14[i];
- return ®spic14[0];
-
+ //return ®spic14[0];
+ fprintf(stderr,"%s %d - requested register: 0x%x\n",__FUNCTION__,__LINE__,idx);
werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
"regWithIdx not found");
exit (1);
}
/*-----------------------------------------------------------------*/
+/* pic14_regWithIdx - returns pointer to register wit index number */
/*-----------------------------------------------------------------*/
regs *
-pic14_findFreeReg(void)
+pic14_allocWithIdx (int idx)
{
int i;
+ debugLog ("%s - allocating with index = 0x%x\n", __FUNCTION__,idx);
+
for (i = 0; i < pic14_nRegs; i++)
- if (regspic14[i].isFree)
+ if (regspic14[i].rIdx == idx){
+ debugLog ("%s - alloc fount index = 0x%x\n", __FUNCTION__,idx);
+ regspic14[i].wasUsed = 1;
+ regspic14[i].isFree = 0;
return ®spic14[i];
+ }
+ //return ®spic14[0];
+ fprintf(stderr,"%s %d - requested register: 0x%x\n",__FUNCTION__,__LINE__,idx);
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "regWithIdx not found");
+ exit (1);
+}
+/*-----------------------------------------------------------------*/
+/*-----------------------------------------------------------------*/
+regs *
+pic14_findFreeReg(short type)
+{
+ int i;
+ for (i = 0; i < pic14_nRegs; i++) {
+ if (!type && regspic14[i].isFree)
+ return ®spic14[i];
+ if (regspic14[i].isFree &&
+ regspic14[i].type == type)
+ return ®spic14[i];
+ }
return NULL;
}
/*-----------------------------------------------------------------*/
sloc->etype = getSpec (sloc->type);
SPEC_SCLS (sloc->etype) = S_DATA;
SPEC_EXTR (sloc->etype) = 0;
+ SPEC_STAT (sloc->etype) = 0;
/* we don't allow it to be allocated`
onto the external stack since : so we
/* if none of the liveRanges have a spillLocation then better
to spill this one than anything else already assigned to registers */
if (liveRangesWith(spillable,noSpilLoc,ebbs[i],ic)) {
- spillThis (sym);
- continue;
+ /* if this is local to this block then we might find a block spil */
+ if (!(sym->liveFrom >= ebbs[i]->fSeq && sym->liveTo <= ebbs[i]->lSeq)) {
+ spillThis (sym);
+ continue;
+ }
}
}
}
_G.regAssigned = bitVectSetBit (_G.regAssigned, sym->key);
debugLog (" %d - \n", __LINE__);
+ if(debugF)
+ bitVectDebugOn(_G.regAssigned, debugF);
for (j = 0; j < sym->nRegs; j++)
{
debugLog ("%s\n", __FUNCTION__);
/* for each live range do */
for (sym = hTabFirstItem (liveRanges, &k); sym;
- sym = hTabNextItem (liveRanges, &k))
- {
-
- debugLog (" %d - %s\n", __LINE__, sym->rname);
-
- /* if used zero times then no registers needed */
- if ((sym->liveTo - sym->liveFrom) == 0)
- continue;
+ sym = hTabNextItem (liveRanges, &k)) {
+ debugLog (" %d - %s\n", __LINE__, sym->rname);
- /* if the live range is a temporary */
- if (sym->isitmp)
- {
+ /* if used zero times then no registers needed */
+ if ((sym->liveTo - sym->liveFrom) == 0)
+ continue;
- debugLog (" %d - \n", __LINE__);
- /* if the type is marked as a conditional */
- if (sym->regType == REG_CND)
- continue;
+ /* if the live range is a temporary */
+ if (sym->isitmp) {
- /* if used in return only then we don't
- need registers */
- if (sym->ruonly || sym->accuse)
- {
- if (IS_AGGREGATE (sym->type) || sym->isptr)
- sym->type = aggrToPtr (sym->type, FALSE);
- debugLog (" %d - \n", __LINE__);
+ debugLog (" %d - itemp register\n", __LINE__);
- continue;
- }
+ /* if the type is marked as a conditional */
+ if (sym->regType == REG_CND)
+ continue;
- /* 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 */
-
- if (bitVectnBitsOn (sym->defs) == 1 &&
- (ic = hTabItemWithKey (iCodehTab,
- bitVectFirstBit (sym->defs))) &&
- POINTER_GET (ic) &&
- !sym->noSpilLoc &&
- !IS_BITVAR (sym->etype))
- {
+ /* if used in return only then we don't
+ need registers */
+ if (sym->ruonly || sym->accuse) {
+ if (IS_AGGREGATE (sym->type) || sym->isptr)
+ sym->type = aggrToPtr (sym->type, FALSE);
+ debugLog (" %d - no reg needed - used as a return\n", __LINE__);
- debugLog (" %d - \n", __LINE__);
+ continue;
+ }
- /* if remat in data space */
- if (OP_SYMBOL (IC_LEFT (ic))->remat &&
- DCL_TYPE (aggrToPtr (sym->type, FALSE)) == POINTER)
- {
+ /* 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 */
+
+ if (bitVectnBitsOn (sym->defs) == 1 &&
+ (ic = hTabItemWithKey (iCodehTab,
+ bitVectFirstBit (sym->defs))) &&
+ POINTER_GET (ic) &&
+ !sym->noSpilLoc &&
+ !IS_BITVAR (sym->etype)) {
+
+
+ debugLog (" %d - \n", __LINE__);
+
+ /* if remat in data space */
+ if (OP_SYMBOL (IC_LEFT (ic))->remat &&
+ DCL_TYPE (aggrToPtr (sym->type, 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);
+ sym->isspilt = 1;
+ sym->usl.spillLoc = psym;
+ continue;
+ }
- /* 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);
- sym->isspilt = 1;
- sym->usl.spillLoc = psym;
- continue;
- }
+ /* if in data space or idata space then try to
+ allocate pointer register */
- /* if in data space or idata space then try to
- allocate pointer register */
+ }
- }
+ /* if not then we require registers */
+ sym->nRegs = ((IS_AGGREGATE (sym->type) || sym->isptr) ?
+ getSize (sym->type = aggrToPtr (sym->type, FALSE)) :
+ getSize (sym->type));
- /* if not then we require registers */
- sym->nRegs = ((IS_AGGREGATE (sym->type) || sym->isptr) ?
- getSize (sym->type = aggrToPtr (sym->type, FALSE)) :
- getSize (sym->type));
+ if (sym->nRegs > 4) {
+ fprintf (stderr, "allocated more than 4 or 0 registers for type ");
+ printTypeChain (sym->type, stderr);
+ fprintf (stderr, "\n");
+ }
- if (sym->nRegs > 4)
- {
- fprintf (stderr, "allocated more than 4 or 0 registers for type ");
- printTypeChain (sym->type, stderr);
- fprintf (stderr, "\n");
- }
+ /* determine the type of register required */
+ if (sym->nRegs == 1 &&
+ IS_PTR (sym->type) &&
+ sym->uptr)
+ sym->regType = REG_PTR;
+ else
+ sym->regType = REG_GPR;
- debugLog (" %d - \n", __LINE__);
- /* determine the type of register required */
- if (sym->nRegs == 1 &&
- IS_PTR (sym->type) &&
- sym->uptr)
- sym->regType = REG_PTR;
- else
- sym->regType = REG_GPR;
- debugLog (" reg type %s\n", debugLogRegType (sym->regType));
+ debugLog (" reg name %s, reg type %s\n", sym->rname, debugLogRegType (sym->regType));
- }
- else
- /* for the first run we don't provide */
- /* registers for true symbols we will */
- /* see how things go */
- sym->nRegs = 0;
}
+ else
+ /* for the first run we don't provide */
+ /* registers for true symbols we will */
+ /* see how things go */
+ sym->nRegs = 0;
+ }
}
debugLog ("%s\n", __FUNCTION__);
for (i = 0; i < pic14_nRegs; i++) {
- regspic14[i].isFree = 1;
- regspic14[i].wasUsed = 0;
+ if(regspic14[i].pc_type == PO_GPR_TEMP) {
+ regspic14[i].isFree = 1;
+ regspic14[i].wasUsed = 0;
+ }
}
}
OP_SYMBOL (IC_RIGHT (ic))->isind ||
OP_LIVETO (IC_RIGHT (ic)) > ic->seq)
{
+ debugLog (" %d - not packing - right side fails \n", __LINE__);
return 0;
}
if (IS_TRUE_SYMOP (IC_RESULT (dic)) &&
IS_OP_VOLATILE (IC_RESULT (dic)))
{
- debugLog (" %d - \n", __LINE__);
+ debugLog (" %d - dic is VOLATILE \n", __LINE__);
dic = NULL;
break;
}
if (IS_SYMOP (IC_RESULT (dic)) &&
IC_RESULT (dic)->key == IC_RIGHT (ic)->key)
{
- debugLog (" %d - dic key == ic key -- pointer set=%c\n", __LINE__, ((POINTER_SET (dic)) ? 'Y' : 'N'));
+ /* A previous result was assigned to the same register - we'll our definition */
+ debugLog (" %d - dic result key == ic right key -- pointer set=%c\n",
+ __LINE__, ((POINTER_SET (dic)) ? 'Y' : 'N'));
if (POINTER_SET (dic))
dic = NULL;
(IC_RIGHT (dic)->key == IC_RESULT (ic)->key ||
IC_RIGHT (dic)->key == IC_RIGHT (ic)->key))
{
- debugLog (" %d - \n", __LINE__);
+ debugLog (" %d - dic right key == ic rightor result key\n", __LINE__);
dic = NULL;
break;
}
(IC_LEFT (dic)->key == IC_RESULT (ic)->key ||
IC_LEFT (dic)->key == IC_RIGHT (ic)->key))
{
- debugLog (" %d - \n", __LINE__);
+ debugLog (" %d - dic left key == ic rightor result key\n", __LINE__);
dic = NULL;
break;
}
if (POINTER_SET (dic) &&
IC_RESULT (dic)->key == IC_RESULT (ic)->key)
{
- debugLog (" %d - \n", __LINE__);
+ debugLog (" %d - dic result key == ic result key -- pointer set=Y\n",
+ __LINE__);
dic = NULL;
break;
}
}
pack:
debugLog (" packing. removing %s\n", OP_SYMBOL (IC_RIGHT (ic))->rname);
+ debugLog (" replacing with %s\n", OP_SYMBOL (IC_RESULT (dic))->rname);
/* found the definition */
/* replace the result with the result of */
/* this assignment and remove this assignment */
+ bitVectUnSetBit(OP_SYMBOL(IC_RESULT(dic))->defs,dic->key);
IC_RESULT (dic) = IC_RESULT (ic);
if (IS_ITEMP (IC_RESULT (dic)) && OP_SYMBOL (IC_RESULT (dic))->liveFrom > dic->seq)
}
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);
return 1;
IC_RIGHT (dic)->operand.symOperand;
IC_LEFT (ic)->key = IC_RIGHT (dic)->operand.symOperand->key;
remiCodeFromeBBlock (ebp, dic);
+ bitVectUnSetBit(OP_SYMBOL(IC_RESULT(dic))->defs,dic->key);
hTabDeleteItem (&iCodehTab, dic->key, dic, DELETE_ITEM, NULL);
change++;
}
IC_RIGHT (ic)->key = IC_RIGHT (dic)->operand.symOperand->key;
remiCodeFromeBBlock (ebp, dic);
+ bitVectUnSetBit(OP_SYMBOL(IC_RESULT(dic))->defs,dic->key);
hTabDeleteItem (&iCodehTab, dic->key, dic, DELETE_ITEM, NULL);
change++;
}
a function call */
if (dic->op == CALL || dic->op == PCALL)
{
- if (ic->op != SEND && ic->op != RETURN)
+ if (ic->op != SEND && ic->op != RETURN &&
+ !POINTER_SET(ic) && !POINTER_GET(ic))
{
OP_SYMBOL (op)->ruonly = 1;
return dic;
iCode *uic;
debugLog ("%s\n", __FUNCTION__);
+
+ /* if this is an aggregate, e.g. a one byte char array */
+ if (IS_AGGREGATE(operandType(IC_RESULT(ic)))) {
+ return;
+ }
+
/* if + or - then it has to be one byte result */
if ((ic->op == '+' || ic->op == '-')
&& getSize (operandType (IC_RESULT (ic))) > 1)
IC_LEFT (ic) = IC_RIGHT (dic);
remiCodeFromeBBlock (ebp, dic);
+ bitVectUnSetBit(OP_SYMBOL(IC_RESULT(dic))->defs,dic->key);
hTabDeleteItem (&iCodehTab, dic->key, dic, DELETE_ITEM, NULL);
}
!OP_SYMBOL (IC_LEFT (ic))->onStack)
{
+ debugLog (" %d - %s. result is rematerializable\n", __LINE__,__FUNCTION__);
+
OP_SYMBOL (IC_RESULT (ic))->remat = 1;
OP_SYMBOL (IC_RESULT (ic))->rematiCode = ic;
OP_SYMBOL (IC_RESULT (ic))->usl.spillLoc = NULL;
OP_SYMBOL (IC_RIGHT (ic))->remat &&
bitVectnBitsOn (OP_SYMBOL (IC_RESULT (ic))->defs) <= 1)
{
+ debugLog (" %d - %s. straight rematerializable\n", __LINE__,__FUNCTION__);
OP_SYMBOL (IC_RESULT (ic))->remat =
OP_SYMBOL (IC_RIGHT (ic))->remat;
bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) == 1 &&
IS_OP_LITERAL (IC_RIGHT (ic))))
{
-
+ debugLog (" %d - %s. rematerializable because op is +/-\n", __LINE__,__FUNCTION__);
//int i =
operandLitValue (IC_RIGHT (ic));
OP_SYMBOL (IC_RESULT (ic))->remat = 1;
if (POINTER_SET (ic))
{
OP_SYMBOL (IC_RESULT (ic))->uptr = 1;
- debugLog (" marking as a pointer (set)\n");
+ debugLog (" marking as a pointer (set) =>");
+ debugAopGet (" result:", IC_RESULT (ic));
}
if (POINTER_GET (ic))
{
OP_SYMBOL (IC_LEFT (ic))->uptr = 1;
- debugLog (" marking as a pointer (get)\n");
+ debugLog (" marking as a pointer (get) =>");
+ debugAopGet (" left:", IC_LEFT (ic));
}
if (!SKIP_IC2 (ic))
{
if (IS_ARITHMETIC_OP (dic))
{
+ bitVectUnSetBit(OP_SYMBOL(IC_RESULT(dic))->defs,dic->key);
IC_RESULT (dic) = IC_RESULT (ic);
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);
ic = ic->prev;
iCode *dic = packRegsForOneuse (ic, IC_RIGHT (ic), ebp);
if (dic)
{
+ bitVectUnSetBit(OP_SYMBOL(IC_RESULT(dic))->defs,dic->key);
IC_RESULT (dic) = IC_RESULT (ic);
+ bitVectUnSetBit(OP_SYMBOL(IC_RESULT(ic))->defs,ic->key);
remiCodeFromeBBlock (ebp, ic);
hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL);
OP_DEFS (IC_RESULT (dic)) = bitVectSetBit (OP_DEFS (IC_RESULT (dic)), dic->key);
int i;
debugLog ("<><><><><><><><><><><><><><><><><>\nstarting\t%s:%s", __FILE__, __FUNCTION__);
- debugLog ("ebbs before optimizing:\n");
+ debugLog ("\nebbs before optimizing:\n");
dumpEbbsToDebug (ebbs, count);
setToNull ((void *) &_G.funcrUsed);