char *fReturnAVR[] = { "r16", "r17", "r18", "r19" };
unsigned fAVRReturnSize = 4; /* shared with ralloc.c */
char **fAVRReturn = fReturnAVR;
-static short rbank = -1;
static char *larray[4] = { "lo8", "hi8", "hlo8", "hhi8" };
+
+#if 0
+// PENDING: Unused
+static short rbank = -1;
static char *tscr[4] = { "r0", "r1", "r24", "r25" };
+static unsigned char SLMask[] = { 0xFF, 0xFE, 0xFC, 0xF8, 0xF0,
+ 0xE0, 0xC0, 0x80, 0x00
+};
+static unsigned char SRMask[] = { 0xFF, 0x7F, 0x3F, 0x1F, 0x0F,
+ 0x07, 0x03, 0x01, 0x00
+};
+
+#endif
+
static struct {
short xPushed;
short zPushed;
extern int avr_ptrRegReq;
extern int avr_nRegs;
extern FILE *codeOutFile;
-static void saverbank (int, iCode *, bool);
#define RESULTONSTACK(x) \
(IC_RESULT(x) && IC_RESULT(x)->aop && \
IC_RESULT(x)->aop->type == AOP_STK )
static lineNode *lineHead = NULL;
static lineNode *lineCurr = NULL;
-static unsigned char SLMask[] = { 0xFF, 0xFE, 0xFC, 0xF8, 0xF0,
- 0xE0, 0xC0, 0x80, 0x00
-};
-static unsigned char SRMask[] = { 0xFF, 0x7F, 0x3F, 0x1F, 0x0F,
- 0x07, 0x03, 0x01, 0x00
-};
-
#define LSB 0
#define MSB16 1
#define MSB24 2
#define MSB32 3
+#if 0
+// PENDING: Unused.
+/*-----------------------------------------------------------------*/
+/* reAdjustPreg - points a register back to where it should */
+/*-----------------------------------------------------------------*/
+static void
+reAdjustPreg (asmop * aop)
+{
+ int size;
+
+ aop->coff = 0;
+ if ((size = aop->size) <= 1)
+ return;
+ size--;
+ switch (aop->type) {
+ case AOP_X:
+ case AOP_Z:
+ emitcode ("sbiw", "%s,%d", aop->aopu.aop_ptr->name, size);
+ break;
+ }
+
+}
+
+/*-----------------------------------------------------------------*/
+/* outBitC - output a bit C */
+/*-----------------------------------------------------------------*/
+static void
+outBitC (operand * result)
+{
+ emitcode ("clr", "r0");
+ emitcode ("rol", "r0");
+ outAcc (result);
+}
+
+/*-----------------------------------------------------------------*/
+/* inExcludeList - return 1 if the string is in exclude Reg list */
+/*-----------------------------------------------------------------*/
+static bool
+inExcludeList (char *s)
+{
+ int i = 0;
+
+ if (options.excludeRegs[i] &&
+ STRCASECMP (options.excludeRegs[i], "none") == 0)
+ return FALSE;
+
+ for (i = 0; options.excludeRegs[i]; i++) {
+ if (options.excludeRegs[i] &&
+ STRCASECMP (s, options.excludeRegs[i]) == 0)
+ return TRUE;
+ }
+ return FALSE;
+}
+
+/*-----------------------------------------------------------------*/
+/* findLabelBackwards: walks back through the iCode chain looking */
+/* for the given label. Returns number of iCode instructions */
+/* between that label and given ic. */
+/* Returns zero if label not found. */
+/*-----------------------------------------------------------------*/
+static int
+findLabelBackwards (iCode * ic, int key)
+{
+ int count = 0;
+
+ while (ic->prev) {
+ ic = ic->prev;
+ count++;
+
+ if (ic->op == LABEL && IC_LABEL (ic)->key == key) {
+ /* printf("findLabelBackwards = %d\n", count); */
+ return count;
+ }
+ }
+
+ return 0;
+}
+
+/*-----------------------------------------------------------------*/
+/* addSign - complete with sign */
+/*-----------------------------------------------------------------*/
+static void
+addSign (operand * result, int offset, int sign)
+{
+ int size = (getDataSize (result) - offset);
+ if (size > 0) {
+ if (sign) {
+ emitcode ("rlc", "a");
+ emitcode ("subb", "a,acc");
+ while (size--)
+ aopPut (AOP (result), "a", offset++);
+ }
+ else
+ while (size--)
+ aopPut (AOP (result), zero, offset++);
+ }
+}
+
+/*-----------------------------------------------------------------*/
+/* isLiteralBit - test if lit == 2^n */
+/*-----------------------------------------------------------------*/
+static int
+isLiteralBit (unsigned long lit)
+{
+ unsigned long pw[32] = { 1L, 2L, 4L, 8L, 16L, 32L, 64L, 128L,
+ 0x100L, 0x200L, 0x400L, 0x800L,
+ 0x1000L, 0x2000L, 0x4000L, 0x8000L,
+ 0x10000L, 0x20000L, 0x40000L, 0x80000L,
+ 0x100000L, 0x200000L, 0x400000L, 0x800000L,
+ 0x1000000L, 0x2000000L, 0x4000000L, 0x8000000L,
+ 0x10000000L, 0x20000000L, 0x40000000L, 0x80000000L
+ };
+ int idx;
+
+ for (idx = 0; idx < 32; idx++)
+ if (lit == pw[idx])
+ return idx + 1;
+ return 0;
+}
+#endif // End Unused code section
+
/*-----------------------------------------------------------------*/
/* emitcode - writes the code into a file : for now it is simple */
/*-----------------------------------------------------------------*/
}
-/*-----------------------------------------------------------------*/
-/* reAdjustPreg - points a register back to where it should */
-/*-----------------------------------------------------------------*/
-static void
-reAdjustPreg (asmop * aop)
-{
- int size;
-
- aop->coff = 0;
- if ((size = aop->size) <= 1)
- return;
- size--;
- switch (aop->type) {
- case AOP_X:
- case AOP_Z:
- emitcode ("sbiw", "%s,%d", aop->aopu.aop_ptr->name, size);
- break;
- }
-
-}
-
#define AOP(op) op->aop
#define AOP_TYPE(op) AOP(op)->type
#define AOP_SIZE(op) AOP(op)->size
}
}
-/*-----------------------------------------------------------------*/
-/* outBitC - output a bit C */
-/*-----------------------------------------------------------------*/
-static void
-outBitC (operand * result)
-{
- emitcode ("clr", "r0");
- emitcode ("rol", "r0");
- outAcc (result);
-}
-
/*-----------------------------------------------------------------*/
/* toBoolean - emit code for orl a,operator(sizeop) */
/*-----------------------------------------------------------------*/
#define STRCASECMP strcasecmp
#endif
-/*-----------------------------------------------------------------*/
-/* inExcludeList - return 1 if the string is in exclude Reg list */
-/*-----------------------------------------------------------------*/
-static bool
-inExcludeList (char *s)
-{
- int i = 0;
-
- if (options.excludeRegs[i] &&
- STRCASECMP (options.excludeRegs[i], "none") == 0)
- return FALSE;
-
- for (i = 0; options.excludeRegs[i]; i++) {
- if (options.excludeRegs[i] &&
- STRCASECMP (s, options.excludeRegs[i]) == 0)
- return TRUE;
- }
- return FALSE;
-}
-
/*-----------------------------------------------------------------*/
/* genFunction - generated code for function entry */
/*-----------------------------------------------------------------*/
emitcode ("rjmp", "L%05d", (IC_LABEL (ic)->key + 100));
}
-/*-----------------------------------------------------------------*/
-/* findLabelBackwards: walks back through the iCode chain looking */
-/* for the given label. Returns number of iCode instructions */
-/* between that label and given ic. */
-/* Returns zero if label not found. */
-/*-----------------------------------------------------------------*/
-static int
-findLabelBackwards (iCode * ic, int key)
-{
- int count = 0;
-
- while (ic->prev) {
- ic = ic->prev;
- count++;
-
- if (ic->op == LABEL && IC_LABEL (ic)->key == key) {
- /* printf("findLabelBackwards = %d\n", count); */
- return count;
- }
- }
-
- return 0;
-}
-
/*-----------------------------------------------------------------*/
/* genPlusIncr :- does addition with increment if possible */
/*-----------------------------------------------------------------*/
}
-/*-----------------------------------------------------------------*/
-/* addSign - complete with sign */
-/*-----------------------------------------------------------------*/
-static void
-addSign (operand * result, int offset, int sign)
-{
- int size = (getDataSize (result) - offset);
- if (size > 0) {
- if (sign) {
- emitcode ("rlc", "a");
- emitcode ("subb", "a,acc");
- while (size--)
- aopPut (AOP (result), "a", offset++);
- }
- else
- while (size--)
- aopPut (AOP (result), zero, offset++);
- }
-}
-
/*-----------------------------------------------------------------*/
/* genMinus - generates code for subtraction */
/*-----------------------------------------------------------------*/
freeAsmop (result, NULL, ic, TRUE);
}
-/*-----------------------------------------------------------------*/
-/* isLiteralBit - test if lit == 2^n */
-/*-----------------------------------------------------------------*/
-static int
-isLiteralBit (unsigned long lit)
-{
- unsigned long pw[32] = { 1L, 2L, 4L, 8L, 16L, 32L, 64L, 128L,
- 0x100L, 0x200L, 0x400L, 0x800L,
- 0x1000L, 0x2000L, 0x4000L, 0x8000L,
- 0x10000L, 0x20000L, 0x40000L, 0x80000L,
- 0x100000L, 0x200000L, 0x400000L, 0x800000L,
- 0x1000000L, 0x2000000L, 0x4000000L, 0x8000000L,
- 0x10000000L, 0x20000000L, 0x40000000L, 0x80000000L
- };
- int idx;
-
- for (idx = 0; idx < 32; idx++)
- if (lit == pw[idx])
- return idx + 1;
- return 0;
-}
-
enum {
AVR_AND = 0, AVR_OR, AVR_XOR
};
}
else {
/* we need to extend the sign :{ */
+ // PENDING: Does nothing on avr
+#if 0
char *l = aopGet (AOP (right), AOP_SIZE (right) - 1);
MOVA (l);
+#endif
emitcode ("rlc", "a");
emitcode ("subb", "a,acc");
while (size--)
static char *recvregs[8] = {
"r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23"
};
-static recvCnt = 0;
+
+static int recvCnt = 0;
/*-----------------------------------------------------------------*/
/* genReceive - generate code for a receive iCode */
static void spillThis (symbol *);
+#if 0
+// PENDING: Unused
+/*-----------------------------------------------------------------*/
+/* findAssignToSym : scanning backwards looks for first assig found */
+/*-----------------------------------------------------------------*/
+static iCode *
+findAssignToSym (operand * op, iCode * ic)
+{
+ iCode *dic;
+
+ for (dic = ic->prev; dic; dic = dic->prev) {
+
+ /* if definition by assignment */
+ if (dic->op == '=' &&
+ !POINTER_SET (dic) && IC_RESULT (dic)->key == op->key
+/* && IS_TRUE_SYMOP(IC_RIGHT(dic)) */
+ ) {
+
+ /* we are interested only if defined in far space */
+ /* or in stack space in case of + & - */
+
+ /* if assigned to a non-symbol then return
+ true */
+ if (!IS_SYMOP (IC_RIGHT (dic)))
+ break;
+
+ /* if the symbol is in far space then
+ we should not */
+ if (isOperandInFarSpace (IC_RIGHT (dic)))
+ return NULL;
+
+ /* for + & - operations make sure that
+ if it is on the stack it is the same
+ as one of the three operands */
+ if ((ic->op == '+' || ic->op == '-') &&
+ OP_SYMBOL (IC_RIGHT (dic))->onStack) {
+
+ if (IC_RESULT (ic)->key != IC_RIGHT (dic)->key
+ && IC_LEFT (ic)->key !=
+ IC_RIGHT (dic)->key
+ && IC_RIGHT (ic)->key !=
+ IC_RIGHT (dic)->key) return NULL;
+ }
+
+ break;
+
+ }
+
+ /* if we find an usage then we cannot delete it */
+ if (IC_LEFT (dic) && IC_LEFT (dic)->key == op->key)
+ return NULL;
+
+ if (IC_RIGHT (dic) && IC_RIGHT (dic)->key == op->key)
+ return NULL;
+
+ if (POINTER_SET (dic) && IC_RESULT (dic)->key == op->key)
+ return NULL;
+ }
+
+ /* now make sure that the right side of dic
+ is not defined between ic & dic */
+ if (dic) {
+ iCode *sic = dic->next;
+
+ for (; sic != ic; sic = sic->next)
+ if (IC_RESULT (sic) &&
+ IC_RESULT (sic)->key == IC_RIGHT (dic)->key)
+ return NULL;
+ }
+
+ return dic;
+
+
+}
+
+/*-----------------------------------------------------------------*/
+/* packForPush - hueristics to reduce iCode for pushing */
+/*-----------------------------------------------------------------*/
+static void
+packForPush (iCode * ic, eBBlock * ebp)
+{
+ iCode *dic;
+
+ if (ic->op != IPUSH || !IS_ITEMP (IC_LEFT (ic)))
+ return;
+
+ /* must have only definition & one usage */
+ if (bitVectnBitsOn (OP_DEFS (IC_LEFT (ic))) != 1 ||
+ bitVectnBitsOn (OP_USES (IC_LEFT (ic))) != 1)
+ return;
+
+ /* find the definition */
+ if (!(dic = hTabItemWithKey (iCodehTab,
+ bitVectFirstBit (OP_DEFS
+ (IC_LEFT (ic))))))
+ return;
+
+ if (dic->op != '=' || POINTER_SET (dic))
+ return;
+
+ /* we now we know that it has one & only one def & use
+ and the that the definition is an assignment */
+ IC_LEFT (ic) = IC_RIGHT (dic);
+
+ remiCodeFromeBBlock (ebp, dic);
+ hTabDeleteItem (&iCodehTab, dic->key, dic, DELETE_ITEM, NULL);
+}
+
+/*-----------------------------------------------------------------*/
+/* packRegsForSupport :- reduce some registers for support calls */
+/*-----------------------------------------------------------------*/
+static int
+packRegsForSupport (iCode * ic, eBBlock * ebp)
+{
+ int change = 0;
+ /* for the left & right operand :- look to see if the
+ left was assigned a true symbol in far space in that
+ case replace them */
+ if (IS_ITEMP (IC_LEFT (ic)) &&
+ OP_SYMBOL (IC_LEFT (ic))->liveTo <= ic->seq) {
+ iCode *dic = findAssignToSym (IC_LEFT (ic), ic);
+ iCode *sic;
+
+ if (!dic)
+ goto right;
+
+ /* found it we need to remove it from the
+ block */
+ for (sic = dic; sic != ic; sic = sic->next)
+ bitVectUnSetBit (sic->rlive, IC_LEFT (ic)->key);
+
+ IC_LEFT (ic)->operand.symOperand =
+ IC_RIGHT (dic)->operand.symOperand;
+ IC_LEFT (ic)->key = IC_RIGHT (dic)->operand.symOperand->key;
+ remiCodeFromeBBlock (ebp, dic);
+ hTabDeleteItem (&iCodehTab, dic->key, dic, DELETE_ITEM, NULL);
+ change++;
+ }
+
+ /* do the same for the right operand */
+ right:
+ if (!change &&
+ IS_ITEMP (IC_RIGHT (ic)) &&
+ OP_SYMBOL (IC_RIGHT (ic))->liveTo <= ic->seq) {
+ iCode *dic = findAssignToSym (IC_RIGHT (ic), ic);
+ iCode *sic;
+
+ if (!dic)
+ return change;
+
+ /* if this is a subtraction & the result
+ is a true symbol in far space then don't pack */
+ if (ic->op == '-' && IS_TRUE_SYMOP (IC_RESULT (dic))) {
+ sym_link *etype =
+ getSpec (operandType (IC_RESULT (dic)));
+ if (IN_FARSPACE (SPEC_OCLS (etype)))
+ return change;
+ }
+ /* found it we need to remove it from the
+ block */
+ for (sic = dic; sic != ic; sic = sic->next)
+ bitVectUnSetBit (sic->rlive, IC_RIGHT (ic)->key);
+
+ IC_RIGHT (ic)->operand.symOperand =
+ IC_RIGHT (dic)->operand.symOperand;
+ IC_RIGHT (ic)->key = IC_RIGHT (dic)->operand.symOperand->key;
+
+ remiCodeFromeBBlock (ebp, dic);
+ hTabDeleteItem (&iCodehTab, dic->key, dic, DELETE_ITEM, NULL);
+ change++;
+ }
+
+ return change;
+}
+
+/*-----------------------------------------------------------------*/
+/* farSpacePackable - returns the packable icode for far variables */
+/*-----------------------------------------------------------------*/
+static iCode *
+farSpacePackable (iCode * ic)
+{
+ iCode *dic;
+
+ /* go thru till we find a definition for the
+ symbol on the right */
+ for (dic = ic->prev; dic; dic = dic->prev) {
+
+ /* if the definition is a call then no */
+ if ((dic->op == CALL || dic->op == PCALL) &&
+ IC_RESULT (dic)->key == IC_RIGHT (ic)->key) {
+ return NULL;
+ }
+
+ /* if shift by unknown amount then not */
+ if ((dic->op == LEFT_OP || dic->op == RIGHT_OP) &&
+ IC_RESULT (dic)->key == IC_RIGHT (ic)->key)
+ return NULL;
+
+ /* if pointer get and size > 1 */
+ if (POINTER_GET (dic) &&
+ getSize (aggrToPtr (operandType (IC_LEFT (dic)), FALSE)) >
+ 1) return NULL;
+
+ if (POINTER_SET (dic) &&
+ getSize (aggrToPtr (operandType (IC_RESULT (dic)), FALSE))
+ > 1)
+ return NULL;
+
+ /* if any three is a true symbol in far space */
+ if (IC_RESULT (dic) &&
+ IS_TRUE_SYMOP (IC_RESULT (dic)) &&
+ isOperandInFarSpace (IC_RESULT (dic)))
+ return NULL;
+
+ if (IC_RIGHT (dic) &&
+ IS_TRUE_SYMOP (IC_RIGHT (dic)) &&
+ isOperandInFarSpace (IC_RIGHT (dic)) &&
+ !isOperandEqual (IC_RIGHT (dic), IC_RESULT (ic)))
+ return NULL;
+
+ if (IC_LEFT (dic) &&
+ IS_TRUE_SYMOP (IC_LEFT (dic)) &&
+ isOperandInFarSpace (IC_LEFT (dic)) &&
+ !isOperandEqual (IC_LEFT (dic), IC_RESULT (ic)))
+ return NULL;
+
+ if (isOperandEqual (IC_RIGHT (ic), IC_RESULT (dic))) {
+ if ((dic->op == LEFT_OP ||
+ dic->op == RIGHT_OP ||
+ dic->op == '-') &&
+ IS_OP_LITERAL (IC_RIGHT (dic))) return NULL;
+ else
+ return dic;
+ }
+ }
+
+ return NULL;
+}
+
+/*-----------------------------------------------------------------*/
+/* rematStr - returns the rematerialized string for a remat var */
+/*-----------------------------------------------------------------*/
+static char *
+rematStr (symbol * sym)
+{
+ char *s = buffer;
+ iCode *ic = sym->rematiCode;
+
+ 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);
+ s += strlen (s);
+ ic = OP_SYMBOL (IC_LEFT (ic))->rematiCode;
+ continue;
+ }
+
+ /* we reached the end */
+ sprintf (s, "%s", OP_SYMBOL (IC_LEFT (ic))->rname);
+ break;
+ }
+
+ return buffer;
+}
+
+/*-----------------------------------------------------------------*/
+/* isSpiltOnStack - returns true if the spil location is on stack */
+/*-----------------------------------------------------------------*/
+static bool
+isSpiltOnStack (symbol * sym)
+{
+ sym_link *etype;
+
+ if (!sym)
+ return FALSE;
+
+ if (!sym->isspilt)
+ return FALSE;
+
+
+ if (!sym->usl.spillLoc)
+ return FALSE;
+
+ etype = getSpec (sym->usl.spillLoc->type);
+ if (IN_STACK (etype))
+ return TRUE;
+
+ return FALSE;
+}
+
+/*-----------------------------------------------------------------*/
+/* spillLRWithPtrReg :- will spil those live ranges which use PTR */
+/*-----------------------------------------------------------------*/
+static void
+spillLRWithPtrReg (symbol * forSym)
+{
+ symbol *lrsym;
+ regs *X, *Z, *X1, *Z1;
+ int k;
+
+ if (!_G.regAssigned || bitVectIsZero (_G.regAssigned))
+ return;
+
+ X = avr_regWithIdx (R26_IDX);
+ X1= avr_regWithIdx (R27_IDX);
+ Z = avr_regWithIdx (R30_IDX);
+ Z1= avr_regWithIdx (R31_IDX);
+
+ /* for all live ranges */
+ for (lrsym = hTabFirstItem (liveRanges, &k); lrsym;
+ lrsym = hTabNextItem (liveRanges, &k)) {
+ int j;
+
+ /* if no registers assigned to it or
+ spilt */
+ /* if it does not overlap with this then
+ not need to spill it */
+
+ if (lrsym->isspilt || !lrsym->nRegs ||
+ (lrsym->liveTo < forSym->liveFrom)) continue;
+
+ /* go thru the registers : if it is either
+ r0 or r1 then spil it */
+ for (j = 0; j < lrsym->nRegs; j++)
+ if (lrsym->regs[j] == X || lrsym->regs[j] == Z ||
+ lrsym->regs[j] == X1 || lrsym->regs[j] == Z1) {
+ spillThis (lrsym);
+ break;
+ }
+ }
+
+}
+#endif
+
/*-----------------------------------------------------------------*/
/* allocReg - allocates register of given type */
/*-----------------------------------------------------------------*/
return 0;
}
-/*-----------------------------------------------------------------*/
-/* spillLRWithPtrReg :- will spil those live ranges which use PTR */
-/*-----------------------------------------------------------------*/
-static void
-spillLRWithPtrReg (symbol * forSym)
-{
- symbol *lrsym;
- regs *X, *Z, *X1, *Z1;
- int k;
-
- if (!_G.regAssigned || bitVectIsZero (_G.regAssigned))
- return;
-
- X = avr_regWithIdx (R26_IDX);
- X1= avr_regWithIdx (R27_IDX);
- Z = avr_regWithIdx (R30_IDX);
- Z1= avr_regWithIdx (R31_IDX);
-
- /* for all live ranges */
- for (lrsym = hTabFirstItem (liveRanges, &k); lrsym;
- lrsym = hTabNextItem (liveRanges, &k)) {
- int j;
-
- /* if no registers assigned to it or
- spilt */
- /* if it does not overlap with this then
- not need to spill it */
-
- if (lrsym->isspilt || !lrsym->nRegs ||
- (lrsym->liveTo < forSym->liveFrom)) continue;
-
- /* go thru the registers : if it is either
- r0 or r1 then spil it */
- for (j = 0; j < lrsym->nRegs; j++)
- if (lrsym->regs[j] == X || lrsym->regs[j] == Z ||
- lrsym->regs[j] == X1 || lrsym->regs[j] == Z1) {
- spillThis (lrsym);
- break;
- }
- }
-
-}
-
/*-----------------------------------------------------------------*/
/* createStackSpil - create a location on the stack to spil */
/*-----------------------------------------------------------------*/
return sym;
}
-/*-----------------------------------------------------------------*/
-/* isSpiltOnStack - returns true if the spil location is on stack */
-/*-----------------------------------------------------------------*/
-static bool
-isSpiltOnStack (symbol * sym)
-{
- sym_link *etype;
-
- if (!sym)
- return FALSE;
-
- if (!sym->isspilt)
- return FALSE;
-
-
- if (!sym->usl.spillLoc)
- return FALSE;
-
- etype = getSpec (sym->usl.spillLoc->type);
- if (IN_STACK (etype))
- return TRUE;
-
- return FALSE;
-}
-
/*-----------------------------------------------------------------*/
/* spillThis - spils a specific operand */
/*-----------------------------------------------------------------*/
if (!sym->nRegs || sym->isspilt)
continue;
- /* for all the registers allocated to it */
- for (k = 0; k < sym->nRegs; k++) {
- if (sym->regs[k]) {
- ic->rMask = bitVectSetBit (ic-> rMask, sym->regs[k]->rIdx);
- /* special case for X & Z registers */
- if (k == R26_IDX || k == R27_IDX)
- ic->rMask = bitVectSetBit (ic->rMask, X_IDX);
- if (k == R30_IDX || k == R31_IDX)
- ic->rMask = bitVectSetBit (ic->rMask, Z_IDX);
- }
- }
- }
- }
- }
-}
-
-/*-----------------------------------------------------------------*/
-/* rematStr - returns the rematerialized string for a remat var */
-/*-----------------------------------------------------------------*/
-static char *
-rematStr (symbol * sym)
-{
- char *s = buffer;
- iCode *ic = sym->rematiCode;
-
- 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);
- s += strlen (s);
- ic = OP_SYMBOL (IC_LEFT (ic))->rematiCode;
- continue;
- }
-
- /* we reached the end */
- sprintf (s, "%s", OP_SYMBOL (IC_LEFT (ic))->rname);
- break;
+ /* for all the registers allocated to it */
+ for (k = 0; k < sym->nRegs; k++) {
+ if (sym->regs[k]) {
+ ic->rMask = bitVectSetBit (ic-> rMask, sym->regs[k]->rIdx);
+ /* special case for X & Z registers */
+ if (k == R26_IDX || k == R27_IDX)
+ ic->rMask = bitVectSetBit (ic->rMask, X_IDX);
+ if (k == R30_IDX || k == R31_IDX)
+ ic->rMask = bitVectSetBit (ic->rMask, Z_IDX);
+ }
+ }
+ }
+ }
}
-
- return buffer;
}
+
/*-----------------------------------------------------------------*/
/* regTypeNum - computes the type & number of registers required */
/*-----------------------------------------------------------------*/
return 0;
}
-/*-----------------------------------------------------------------*/
-/* farSpacePackable - returns the packable icode for far variables */
-/*-----------------------------------------------------------------*/
-static iCode *
-farSpacePackable (iCode * ic)
-{
- iCode *dic;
-
- /* go thru till we find a definition for the
- symbol on the right */
- for (dic = ic->prev; dic; dic = dic->prev) {
-
- /* if the definition is a call then no */
- if ((dic->op == CALL || dic->op == PCALL) &&
- IC_RESULT (dic)->key == IC_RIGHT (ic)->key) {
- return NULL;
- }
-
- /* if shift by unknown amount then not */
- if ((dic->op == LEFT_OP || dic->op == RIGHT_OP) &&
- IC_RESULT (dic)->key == IC_RIGHT (ic)->key)
- return NULL;
-
- /* if pointer get and size > 1 */
- if (POINTER_GET (dic) &&
- getSize (aggrToPtr (operandType (IC_LEFT (dic)), FALSE)) >
- 1) return NULL;
-
- if (POINTER_SET (dic) &&
- getSize (aggrToPtr (operandType (IC_RESULT (dic)), FALSE))
- > 1)
- return NULL;
-
- /* if any three is a true symbol in far space */
- if (IC_RESULT (dic) &&
- IS_TRUE_SYMOP (IC_RESULT (dic)) &&
- isOperandInFarSpace (IC_RESULT (dic)))
- return NULL;
-
- if (IC_RIGHT (dic) &&
- IS_TRUE_SYMOP (IC_RIGHT (dic)) &&
- isOperandInFarSpace (IC_RIGHT (dic)) &&
- !isOperandEqual (IC_RIGHT (dic), IC_RESULT (ic)))
- return NULL;
-
- if (IC_LEFT (dic) &&
- IS_TRUE_SYMOP (IC_LEFT (dic)) &&
- isOperandInFarSpace (IC_LEFT (dic)) &&
- !isOperandEqual (IC_LEFT (dic), IC_RESULT (ic)))
- return NULL;
-
- if (isOperandEqual (IC_RIGHT (ic), IC_RESULT (dic))) {
- if ((dic->op == LEFT_OP ||
- dic->op == RIGHT_OP ||
- dic->op == '-') &&
- IS_OP_LITERAL (IC_RIGHT (dic))) return NULL;
- else
- return dic;
- }
- }
-
- return NULL;
-}
-
/*-----------------------------------------------------------------*/
/* packRegsForAssign - register reduction for assignment */
/*-----------------------------------------------------------------*/
}
-/*-----------------------------------------------------------------*/
-/* findAssignToSym : scanning backwards looks for first assig found */
-/*-----------------------------------------------------------------*/
-static iCode *
-findAssignToSym (operand * op, iCode * ic)
-{
- iCode *dic;
-
- for (dic = ic->prev; dic; dic = dic->prev) {
-
- /* if definition by assignment */
- if (dic->op == '=' &&
- !POINTER_SET (dic) && IC_RESULT (dic)->key == op->key
-/* && IS_TRUE_SYMOP(IC_RIGHT(dic)) */
- ) {
-
- /* we are interested only if defined in far space */
- /* or in stack space in case of + & - */
-
- /* if assigned to a non-symbol then return
- true */
- if (!IS_SYMOP (IC_RIGHT (dic)))
- break;
-
- /* if the symbol is in far space then
- we should not */
- if (isOperandInFarSpace (IC_RIGHT (dic)))
- return NULL;
-
- /* for + & - operations make sure that
- if it is on the stack it is the same
- as one of the three operands */
- if ((ic->op == '+' || ic->op == '-') &&
- OP_SYMBOL (IC_RIGHT (dic))->onStack) {
-
- if (IC_RESULT (ic)->key != IC_RIGHT (dic)->key
- && IC_LEFT (ic)->key !=
- IC_RIGHT (dic)->key
- && IC_RIGHT (ic)->key !=
- IC_RIGHT (dic)->key) return NULL;
- }
-
- break;
-
- }
-
- /* if we find an usage then we cannot delete it */
- if (IC_LEFT (dic) && IC_LEFT (dic)->key == op->key)
- return NULL;
-
- if (IC_RIGHT (dic) && IC_RIGHT (dic)->key == op->key)
- return NULL;
-
- if (POINTER_SET (dic) && IC_RESULT (dic)->key == op->key)
- return NULL;
- }
-
- /* now make sure that the right side of dic
- is not defined between ic & dic */
- if (dic) {
- iCode *sic = dic->next;
-
- for (; sic != ic; sic = sic->next)
- if (IC_RESULT (sic) &&
- IC_RESULT (sic)->key == IC_RIGHT (dic)->key)
- return NULL;
- }
-
- return dic;
-
-
-}
-
-/*-----------------------------------------------------------------*/
-/* packRegsForSupport :- reduce some registers for support calls */
-/*-----------------------------------------------------------------*/
-static int
-packRegsForSupport (iCode * ic, eBBlock * ebp)
-{
- int change = 0;
- /* for the left & right operand :- look to see if the
- left was assigned a true symbol in far space in that
- case replace them */
- if (IS_ITEMP (IC_LEFT (ic)) &&
- OP_SYMBOL (IC_LEFT (ic))->liveTo <= ic->seq) {
- iCode *dic = findAssignToSym (IC_LEFT (ic), ic);
- iCode *sic;
-
- if (!dic)
- goto right;
-
- /* found it we need to remove it from the
- block */
- for (sic = dic; sic != ic; sic = sic->next)
- bitVectUnSetBit (sic->rlive, IC_LEFT (ic)->key);
-
- IC_LEFT (ic)->operand.symOperand =
- IC_RIGHT (dic)->operand.symOperand;
- IC_LEFT (ic)->key = IC_RIGHT (dic)->operand.symOperand->key;
- remiCodeFromeBBlock (ebp, dic);
- hTabDeleteItem (&iCodehTab, dic->key, dic, DELETE_ITEM, NULL);
- change++;
- }
-
- /* do the same for the right operand */
- right:
- if (!change &&
- IS_ITEMP (IC_RIGHT (ic)) &&
- OP_SYMBOL (IC_RIGHT (ic))->liveTo <= ic->seq) {
- iCode *dic = findAssignToSym (IC_RIGHT (ic), ic);
- iCode *sic;
-
- if (!dic)
- return change;
-
- /* if this is a subtraction & the result
- is a true symbol in far space then don't pack */
- if (ic->op == '-' && IS_TRUE_SYMOP (IC_RESULT (dic))) {
- sym_link *etype =
- getSpec (operandType (IC_RESULT (dic)));
- if (IN_FARSPACE (SPEC_OCLS (etype)))
- return change;
- }
- /* found it we need to remove it from the
- block */
- for (sic = dic; sic != ic; sic = sic->next)
- bitVectUnSetBit (sic->rlive, IC_RIGHT (ic)->key);
-
- IC_RIGHT (ic)->operand.symOperand =
- IC_RIGHT (dic)->operand.symOperand;
- IC_RIGHT (ic)->key = IC_RIGHT (dic)->operand.symOperand->key;
-
- remiCodeFromeBBlock (ebp, dic);
- hTabDeleteItem (&iCodehTab, dic->key, dic, DELETE_ITEM, NULL);
- change++;
- }
-
- return change;
-}
-
#define IS_OP_RUONLY(x) (x && IS_SYMOP(x) && OP_SYMBOL(x)->ruonly)
return FALSE;
}
-/*-----------------------------------------------------------------*/
-/* packForPush - hueristics to reduce iCode for pushing */
-/*-----------------------------------------------------------------*/
-static void
-packForPush (iCode * ic, eBBlock * ebp)
-{
- iCode *dic;
-
- if (ic->op != IPUSH || !IS_ITEMP (IC_LEFT (ic)))
- return;
-
- /* must have only definition & one usage */
- if (bitVectnBitsOn (OP_DEFS (IC_LEFT (ic))) != 1 ||
- bitVectnBitsOn (OP_USES (IC_LEFT (ic))) != 1)
- return;
-
- /* find the definition */
- if (!(dic = hTabItemWithKey (iCodehTab,
- bitVectFirstBit (OP_DEFS
- (IC_LEFT (ic))))))
- return;
-
- if (dic->op != '=' || POINTER_SET (dic))
- return;
-
- /* we now we know that it has one & only one def & use
- and the that the definition is an assignment */
- IC_LEFT (ic) = IC_RIGHT (dic);
-
- remiCodeFromeBBlock (ebp, dic);
- hTabDeleteItem (&iCodehTab, dic->key, dic, DELETE_ITEM, NULL);
-}
-
/*-----------------------------------------------------------------*/
/* packRegisters - does some transformations to reduce register */
/* pressure */