From c5e9c6cbd25c3875eb596bc7513e3aeb980a9284 Mon Sep 17 00:00:00 2001 From: sandeep Date: Sun, 22 Apr 2001 20:50:55 +0000 Subject: [PATCH] more enhancements for avr & some bug fixes git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@752 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- src/avr/gen.c | 29 ++--- src/avr/ralloc.c | 276 +++++++++++++++++++++++++---------------------- src/avr/ralloc.h | 6 +- src/mcs51/gen.c | 12 +-- 4 files changed, 173 insertions(+), 150 deletions(-) diff --git a/src/avr/gen.c b/src/avr/gen.c index 28667c5d..731b98ca 100644 --- a/src/avr/gen.c +++ b/src/avr/gen.c @@ -537,7 +537,7 @@ sameRegs (asmop * aop1, asmop * aop2) static int isRegPair (asmop * aop) { - if (!aop || aop->size != 2) + if (!aop || aop->size < 2) return 0; if (aop->type == AOP_X || aop->type == AOP_Z) return 1; @@ -599,7 +599,7 @@ aopOp (operand * op, iCode * ic, bool result) /* if the type is a conditional */ - if (sym->regType == REG_CND) { + if (sym->regType & REG_CND) { aop = op->aop = sym->aop = newAsmop (AOP_CRY); aop->size = 0; return; @@ -1816,7 +1816,7 @@ genLabel (iCode * ic) static void genGoto (iCode * ic) { - emitcode ("rjmp", "L%05d:", (IC_LABEL (ic)->key + 100)); + emitcode ("rjmp", "L%05d", (IC_LABEL (ic)->key + 100)); } /*-----------------------------------------------------------------*/ @@ -4014,10 +4014,13 @@ genGenPointerGet (operand * left, operand * result, iCode * ic, iCode *pi) } else { aop = newAsmop(0); getFreePtr(ic,&aop,FALSE,TRUE); - - emitcode ("mov", "r30,%s", aopGet (AOP (left), 0)); - emitcode ("mov", "r31,%s", aopGet (AOP (left), 1)); - emitcode ("mov", "r0,%s", aopGet (AOP (left), 2)); + if (isRegPair(AOP(left))) { + emitcode ("movw", "r30,%s", aopGet (AOP (left), 0)); + } else { + emitcode ("mov", "r30,%s", aopGet (AOP (left), 0)); + emitcode ("mov", "r31,%s", aopGet (AOP (left), 1)); + } + emitcode ("mov", "r24,%s", aopGet (AOP (left), 2)); gotFreePtr=1; } @@ -4566,7 +4569,7 @@ genIfx (iCode * ic, iCode * popIc) } ic->generated = 1; } - +/* here */ /*-----------------------------------------------------------------*/ /* genAddrOf - generates code for address of */ /*-----------------------------------------------------------------*/ @@ -4607,7 +4610,7 @@ genAddrOf (iCode * ic) while (size--) { /* Yuck! */ if (options.stack10bit && offset == 2) { - aopPut (AOP (IC_RESULT (ic)), "#0x40", + aopPut (AOP (IC_RESULT (ic)), "0x40", offset++); } else { @@ -4625,9 +4628,9 @@ genAddrOf (iCode * ic) while (size--) { char s[SDCC_NAME_MAX]; if (offset) - sprintf (s, "#(%s >> %d)", sym->rname, offset * 8); + sprintf (s, "(%s >> %d)", sym->rname, offset * 8); else - sprintf (s, "#%s", sym->rname); + sprintf (s, "%s", sym->rname); aopPut (AOP (IC_RESULT (ic)), s, offset++); } @@ -4885,10 +4888,10 @@ genCast (iCode * ic) l = one; break; case CPOINTER: - l = "#0x02"; + l = "0x02"; break; case PPOINTER: - l = "#0x03"; + l = "0x03"; break; default: diff --git a/src/avr/ralloc.c b/src/avr/ralloc.c index 87b84ef7..433db84b 100644 --- a/src/avr/ralloc.c +++ b/src/avr/ralloc.c @@ -55,38 +55,38 @@ int avr_ptrRegReq; /* pointer register required */ /* AVR registers */ regs regsAVR[] = { - {REG_GPR, R0_IDX, REG_GPR, "r0", "r0", "", 0, 0, 0}, /* scratch */ - {REG_GPR, R1_IDX, REG_GPR, "r1", "r1", "", 0, 0, 0}, /* scratch */ - {REG_GPR, R2_IDX, REG_GPR, "r2", "r2", "", 0, 1, 1}, /* gpr */ - {REG_GPR, R3_IDX, REG_GPR, "r3", "r3", "", 0, 1, 1}, /* gpr */ - {REG_GPR, R4_IDX, REG_GPR, "r4", "r4", "", 0, 1, 1}, /* gpr */ - {REG_GPR, R5_IDX, REG_GPR, "r5", "r5", "", 0, 1, 1}, /* gpr */ - {REG_GPR, R6_IDX, REG_GPR, "r6", "r6", "", 0, 1, 1}, /* gpr */ - {REG_GPR, R7_IDX, REG_GPR, "r7", "r7", "", 0, 1, 1}, /* gpr */ - {REG_GPR, R8_IDX, REG_GPR, "r8", "r8", "", 0, 1, 1}, /* gpr */ - {REG_GPR, R9_IDX, REG_GPR, "r9", "r9", "", 0, 1, 1}, /* gpr */ - {REG_GPR, R10_IDX, REG_GPR, "r10", "r10", "", 0, 1, 1}, /* gpr */ - {REG_GPR, R11_IDX, REG_GPR, "r11", "r11", "", 0, 1, 1}, /* gpr */ - {REG_GPR, R12_IDX, REG_GPR, "r12", "r12", "", 0, 1, 1}, /* gpr */ - {REG_GPR, R13_IDX, REG_GPR, "r13", "r13", "", 0, 1, 1}, /* gpr */ - {REG_GPR, R14_IDX, REG_GPR, "r14", "r14", "", 0, 1, 1}, /* gpr */ - {REG_GPR, R15_IDX, REG_GPR, "r15", "r15", "", 0, 1, 1}, /* gpr */ - {REG_GPR, R16_IDX, REG_GPR, "r16", "r16", "", 0, 1, 0}, /* parm/gpr */ - {REG_GPR, R17_IDX, REG_GPR, "r17", "r17", "", 0, 1, 0}, /* parm/gpr */ - {REG_GPR, R18_IDX, REG_GPR, "r18", "r18", "", 0, 1, 0}, /* parm/gpr */ - {REG_GPR, R19_IDX, REG_GPR, "r19", "r19", "", 0, 1, 0}, /* parm/gpr */ - {REG_GPR, R20_IDX, REG_GPR, "r20", "r20", "", 0, 1, 0}, /* parm/gpr */ - {REG_GPR, R21_IDX, REG_GPR, "r21", "r21", "", 0, 1, 0}, /* parm/gpr */ - {REG_GPR, R22_IDX, REG_GPR, "r22", "r22", "", 0, 1, 0}, /* parm/gpr */ - {REG_GPR, R23_IDX, REG_GPR, "r23", "r23", "", 0, 1, 0}, /* parm/gpr */ - {REG_GPR, R24_IDX, REG_GPR, "r24", "r24", "", 0, 0, 0}, /* scratch */ - {REG_GPR, R25_IDX, REG_GPR, "r25", "r25", "", 0, 0, 0}, /* scratch */ - {REG_GPR, R26_IDX, REG_GPR, "r26", "r26", "", 0, 1, 1}, /* used as pointer reg X */ - {REG_GPR, R27_IDX, REG_GPR, "r27", "r27", "", 0, 1, 1}, /* used as pointer reg X */ - {REG_GPR, R28_IDX, REG_GPR, "r28", "r28", "", 0, 1, 0}, /* stack frame Y */ - {REG_GPR, R29_IDX, REG_GPR, "r29", "r29", "", 0, 1, 0}, /* stack frame Y */ - {REG_GPR, R30_IDX, REG_GPR, "r30", "r30", "", 0, 1, 1}, /* used as pointer reg Z */ - {REG_GPR, R31_IDX, REG_GPR, "r31", "r31", "", 0, 1, 1}, /* used as pointer reg Z */ + {REG_GPR|REG_PAIR, R0_IDX, REG_GPR|REG_PAIR, "r0", "r0", "", 0, 0, 0}, /* scratch */ + {REG_GPR, R1_IDX, REG_GPR , "r1", "r1", "", 0, 0, 0}, /* scratch */ + {REG_GPR|REG_PAIR, R2_IDX, REG_GPR|REG_PAIR, "r2", "r2", "", 0, 1, 1}, /* gpr */ + {REG_GPR, R3_IDX, REG_GPR , "r3", "r3", "", 0, 1, 1}, /* gpr */ + {REG_GPR|REG_PAIR, R4_IDX, REG_GPR|REG_PAIR, "r4", "r4", "", 0, 1, 1}, /* gpr */ + {REG_GPR, R5_IDX, REG_GPR , "r5", "r5", "", 0, 1, 1}, /* gpr */ + {REG_GPR|REG_PAIR, R6_IDX, REG_GPR|REG_PAIR, "r6", "r6", "", 0, 1, 1}, /* gpr */ + {REG_GPR, R7_IDX, REG_GPR , "r7", "r7", "", 0, 1, 1}, /* gpr */ + {REG_GPR|REG_PAIR, R8_IDX, REG_GPR|REG_PAIR, "r8", "r8", "", 0, 1, 1}, /* gpr */ + {REG_GPR, R9_IDX, REG_GPR , "r9", "r9", "", 0, 1, 1}, /* gpr */ + {REG_GPR|REG_PAIR, R10_IDX,REG_GPR|REG_PAIR, "r10", "r10","",0, 1, 1}, /* gpr */ + {REG_GPR, R11_IDX,REG_GPR , "r11", "r11","",0, 1, 1}, /* gpr */ + {REG_GPR|REG_PAIR, R12_IDX,REG_GPR|REG_PAIR, "r12", "r12","",0, 1, 1}, /* gpr */ + {REG_GPR, R13_IDX,REG_GPR , "r13", "r13","",0, 1, 1}, /* gpr */ + {REG_GPR|REG_PAIR, R14_IDX,REG_GPR|REG_PAIR, "r14", "r14","",0, 1, 1}, /* gpr */ + {REG_GPR, R15_IDX,REG_GPR , "r15", "r15","",0, 1, 1}, /* gpr */ + {REG_GPR|REG_PAIR, R16_IDX,REG_GPR|REG_PAIR, "r16", "r16","",0, 1, 0}, /* parm/gpr */ + {REG_GPR, R17_IDX,REG_GPR , "r17", "r17","",0, 1, 0}, /* parm/gpr */ + {REG_GPR|REG_PAIR, R18_IDX,REG_GPR|REG_PAIR, "r18", "r18","",0, 1, 0}, /* parm/gpr */ + {REG_GPR, R19_IDX,REG_GPR , "r19", "r19","",0, 1, 0}, /* parm/gpr */ + {REG_GPR|REG_PAIR, R20_IDX,REG_GPR|REG_PAIR, "r20", "r20","",0, 1, 0}, /* parm/gpr */ + {REG_GPR, R21_IDX,REG_GPR , "r21", "r21","",0, 1, 0}, /* parm/gpr */ + {REG_GPR|REG_PAIR, R22_IDX,REG_GPR|REG_PAIR, "r22", "r22","",0, 1, 0}, /* parm/gpr */ + {REG_GPR, R23_IDX,REG_GPR , "r23", "r23","",0, 1, 0}, /* parm/gpr */ + {REG_GPR|REG_PAIR, R24_IDX,REG_GPR|REG_PAIR, "r24", "r24","",0, 0, 0}, /* scratch */ + {REG_GPR, R25_IDX,REG_GPR , "r25", "r25","",0, 0, 0}, /* scratch */ + {REG_GPR|REG_PAIR, R26_IDX,REG_GPR|REG_PAIR, "r26", "r26","",0, 1, 1}, /* used as pointer reg X */ + {REG_GPR, R27_IDX,REG_GPR , "r27", "r27","",0, 1, 1}, /* used as pointer reg X */ + {REG_GPR|REG_PAIR, R28_IDX,REG_GPR|REG_PAIR, "r28", "r28","",0, 1, 0}, /* stack frame Y */ + {REG_GPR, R29_IDX,REG_GPR , "r29", "r29","",0, 1, 0}, /* stack frame Y */ + {REG_GPR|REG_PAIR, R30_IDX,REG_GPR|REG_PAIR, "r30", "r30","",0, 1, 1}, /* used as pointer reg Z */ + {REG_GPR, R31_IDX,REG_GPR , "r31", "r31","",0, 1, 1}, /* used as pointer reg Z */ {REG_PTR, X_IDX, REG_PTR, "X", "X", "", 0, 1, 0}, {REG_PTR, Z_IDX, REG_PTR, "Z", "Z", "", 0, 1, 0}, }; @@ -114,9 +114,10 @@ allocReg (short type) bitVectSetBit (currFunc->regsUsed, i); return ®sAVR[i]; } + /* other wise look for specific type of register */ - if (regsAVR[i].isFree && regsAVR[i].type == type) { + if (regsAVR[i].isFree && (regsAVR[i].type & type)) { regsAVR[i].isFree = 0; if (currFunc) currFunc->regsUsed = @@ -127,6 +128,34 @@ allocReg (short type) return NULL; } +/*-----------------------------------------------------------------*/ +/* allocRegPair - allocates register pair of given */ +/*-----------------------------------------------------------------*/ +static regs * +allocRegPair (short type) +{ + int i; + + for (i = avr_fReg; i < avr_nRegs; i++) { + + /* look for specific type of register pair */ + if (regsAVR[i].isFree && (regsAVR[i].type & type) + && (regsAVR[i].type & REG_PAIR) && regsAVR[i+1].isFree) { + + regsAVR[i].isFree = 0; + regsAVR[i+1].isFree = 0; + if (currFunc) { + currFunc->regsUsed = + bitVectSetBit (currFunc->regsUsed, i); + currFunc->regsUsed = + bitVectSetBit (currFunc->regsUsed, i+1); + } + return ®sAVR[i]; + } + } + return NULL; +} + /*-----------------------------------------------------------------*/ /* avr_regWithIdx - returns pointer to register wit index number */ /*-----------------------------------------------------------------*/ @@ -163,7 +192,7 @@ nFreeRegs (int type) int nfr = 0; for (i = avr_fReg; i < avr_nRegs; i++) - if (regsAVR[i].isFree && regsAVR[i].type == type) + if (regsAVR[i].isFree && regsAVR[i].type & type) nfr++; return nfr; } @@ -753,10 +782,14 @@ getRegPtr (iCode * ic, eBBlock * ebp, symbol * sym) tryAgain: /* try for a ptr type */ - if ((reg = allocReg (REG_PTR))) + if ((reg = allocReg (REG_PTR|REG_PAIR))) return reg; - /* try for gpr type */ + /* try for gpr type / pair */ + if ((reg = allocReg (REG_GPR|REG_PAIR))) + return reg; + + /* try for gpr type */ if ((reg = allocReg (REG_GPR))) return reg; @@ -778,11 +811,11 @@ getRegScr (iCode * ic, eBBlock * ebp, symbol * sym) regs *reg; tryAgain: - /* try for a ptr type */ + + /* try for a scratch non-pair */ if ((reg = allocReg (REG_SCR))) return reg; - - /* try for gpr type */ + if ((reg = allocReg (REG_GPR))) return reg; @@ -799,7 +832,7 @@ getRegScr (iCode * ic, eBBlock * ebp, symbol * sym) /* getRegGpr - will try for GPR if not spil */ /*-----------------------------------------------------------------*/ static regs * -getRegGpr (iCode * ic, eBBlock * ebp, symbol * sym) +getRegGpr (iCode * ic, eBBlock * ebp, symbol * sym ) { regs *reg; @@ -876,7 +909,7 @@ deassignLRs (iCode * ic, eBBlock * ebp) ic->prev->op == IPOP && !ic->prev->parmPush && !OP_SYMBOL (IC_LEFT (ic->prev))->isspilt) - psym = OP_SYMBOL (IC_LEFT (ic->prev)); + psym = OP_SYMBOL (IC_LEFT (ic->prev)); if (sym->nRegs) { int i = 0; @@ -903,25 +936,17 @@ deassignLRs (iCode * ic, eBBlock * ebp) !bitVectBitValue (_G.regAssigned, result->key) && /* the number of free regs + number of regs in this LR can accomodate the what result Needs */ - ((nfreeRegsType (result->regType) + - sym->nRegs) >= result->nRegs)) { - - for (i = 0; i < result->nRegs; i++) - if (i < sym->nRegs) - result->regs[i] = - sym->regs[i]; - else if (result->regType == REG_SCR) - result->regs[i] = - getRegScr (ic, ebp, - result); - else - result->regs[i] = - getRegGpr (ic, ebp, - result); + ((nfreeRegsType (result->regType) + sym->nRegs) >= result->nRegs)) { - _G.regAssigned = - bitVectSetBit (_G.regAssigned, - result->key); + for (i = 0; i < result->nRegs; i++) { + if (i < sym->nRegs) + result->regs[i] = sym->regs[i]; + else if (result->regType == REG_SCR) + result->regs[i] = getRegScr (ic, ebp, result); + else + result->regs[i] = getRegGpr (ic, ebp, result); + } + _G.regAssigned = bitVectSetBit (_G.regAssigned, result->key); } @@ -931,8 +956,7 @@ deassignLRs (iCode * ic, eBBlock * ebp) if (!symHasReg (psym, sym->regs[i])) freeReg (sym->regs[i]); } - else - freeReg (sym->regs[i]); + else freeReg (sym->regs[i]); } } } @@ -992,22 +1016,6 @@ willCauseSpill (int nr, int rt) return 1; } -/*-----------------------------------------------------------------*/ -/* makeRegPair - if two registers then try to make a pair */ -/*-----------------------------------------------------------------*/ -static void makeRegPair (operand *op) -{ - symbol *opsym = OP_SYMBOL(op); - - if (opsym->isspilt || opsym->nRegs != 2) - return; - if ((opsym->regs[0] - opsym->regs[1]) == 1) { - regs *tmp = opsym->regs[0]; - opsym->regs[0] = opsym->regs[1]; - opsym->regs[1] = tmp; - } -} - /*-----------------------------------------------------------------*/ /* positionRegs - the allocator can allocate same registers to res- */ /* ult and operand, if this happens make sure they are in the same */ @@ -1042,6 +1050,34 @@ positionRegs (symbol * result, symbol * opsym, int lineno) } } +/*-----------------------------------------------------------------*/ +/* needsPair - heuristic to determine if a pair would be good */ +/*-----------------------------------------------------------------*/ +static int needsPair (iCode *ic) +{ + symbol *sym = OP_SYMBOL(IC_RESULT(ic)); + bitVect *uses_defs = + bitVectUnion(OP_USES (IC_RESULT(ic)),OP_DEFS(IC_RESULT(ic))); + + /* if size is less than 2 then NO */ + if (sym->nRegs < 2) return 0; + /* if type Pointer then YES */ + if (IS_PTR(sym->type)) return 1; + + /* go thru the usages of this operand if used with + a constant then yes */ + while (!bitVectIsZero(uses_defs)) { + int ikey = bitVectFirstBit(uses_defs); + iCode *uic = hTabItemWithKey(iCodehTab,ikey); + sym_link *otype = NULL; + if (!uic) continue; + otype = (IC_RIGHT(uic) ? operandType(IC_RIGHT(uic)) : NULL); + if (otype && IS_LITERAL(otype)) return 1; + bitVectUnSetBit(uses_defs,ikey); + } + return 0; +} + /*-----------------------------------------------------------------*/ /* serialRegAssign - serially allocate registers to the variables */ /*-----------------------------------------------------------------*/ @@ -1091,7 +1127,7 @@ serialRegAssign (eBBlock ** ebbs, int count) symbol *sym = OP_SYMBOL (IC_RESULT (ic)); bitVect *spillable; int willCS; - int j; + int j=0; /* if it does not need or is spilt or is already assigned to registers @@ -1118,26 +1154,18 @@ serialRegAssign (eBBlock ** ebbs, int count) willCauseSpill (sym->nRegs, sym->regType); spillable = computeSpillable (ic); - if (sym->remat || - (willCS && bitVectIsZero (spillable))) { - + if (sym->remat || (willCS && bitVectIsZero (spillable))) { spillThis (sym); continue; - } /* if it has a spillocation & is used less than all other live ranges then spill this */ if (willCS && sym->usl.spillLoc) { - symbol *leastUsed = - leastUsedLR (liveRangesWith - (spillable, - allLRs, - ebbs[i], - ic)); - if (leastUsed && - leastUsed->used > sym->used) { + symbol *leastUsed = leastUsedLR (liveRangesWith (spillable, + allLRs, ebbs[i], ic)); + if (leastUsed && leastUsed->used > sym->used) { spillThis (sym); continue; } @@ -1145,22 +1173,29 @@ serialRegAssign (eBBlock ** ebbs, int count) /* we assign registers to it */ _G.regAssigned = bitVectSetBit (_G.regAssigned, sym->key); - - for (j = 0; j < sym->nRegs; j++) { + if (needsPair(ic)) { + int regtype ; + regs *preg; + if (sym->regType == REG_PTR) regtype = REG_PTR; + else if (sym->regType == REG_SCR) regtype = REG_SCR; + else regtype = REG_GPR; + preg = allocRegPair(regtype); + if (preg) { + sym->regs[j++] = preg; + sym->regs[j++] = ®sAVR[preg->rIdx+1]; + } + } + for (; j < sym->nRegs; j++) { if (sym->regType == REG_PTR) sym->regs[j] = getRegPtr (ic, ebbs[i], sym); else if (sym->regType == REG_SCR) sym->regs[j] = getRegScr (ic, ebbs[i], sym); else sym->regs[j] = getRegGpr (ic, ebbs[i], sym); - /* if the allocation falied which means this was spilt then break */ - if (!sym->regs[j]) - break; + if (!sym->regs[j]) break; } - /* make the registers a pair */ - makeRegPair(IC_RESULT(ic)); /* if it shares registers with operands make sure that they are in the same position */ @@ -1168,16 +1203,12 @@ serialRegAssign (eBBlock ** ebbs, int count) OP_SYMBOL (IC_LEFT (ic))->nRegs && ic->op != '=') positionRegs (OP_SYMBOL (IC_RESULT (ic)), - OP_SYMBOL (IC_LEFT - (ic)), - ic->lineno); + OP_SYMBOL (IC_LEFT (ic)), ic->lineno); /* do the same for the right operand */ if (IC_RIGHT (ic) && IS_SYMOP (IC_RIGHT (ic)) && OP_SYMBOL (IC_RIGHT (ic))->nRegs) positionRegs (OP_SYMBOL (IC_RESULT (ic)), - OP_SYMBOL (IC_RIGHT - (ic)), - ic->lineno); + OP_SYMBOL (IC_RIGHT (ic)), ic->lineno); } } @@ -1392,9 +1423,7 @@ regTypeNum () in "data" space */ if (bitVectnBitsOn (sym->defs) == 1 && - (ic = hTabItemWithKey (iCodehTab, - bitVectFirstBit (sym-> - defs))) + (ic = hTabItemWithKey (iCodehTab, bitVectFirstBit (sym-> defs))) && POINTER_GET (ic) && !IS_BITVAR (sym->etype)) { /* if in data space or idata space then try to @@ -2169,16 +2198,16 @@ setDefaultRegs (eBBlock ** ebbs, int count) regsAVR[R30_IDX].isFree = regsAVR[R31_IDX].isFree = 1; if (!avr_ptrRegReq) { - regsAVR[R26_IDX].type = - regsAVR[R27_IDX].type = - regsAVR[R30_IDX].type = - regsAVR[R31_IDX].type = REG_GPR; + regsAVR[R26_IDX].type = (regsAVR[R26_IDX].type & ~REG_MASK) | REG_GPR; + regsAVR[R27_IDX].type = (regsAVR[R27_IDX].type & ~REG_MASK) | REG_GPR; + regsAVR[R28_IDX].type = (regsAVR[R28_IDX].type & ~REG_MASK) | REG_GPR; + regsAVR[R29_IDX].type = (regsAVR[R29_IDX].type & ~REG_MASK) | REG_GPR; } else { - regsAVR[R26_IDX].type = - regsAVR[R27_IDX].type = - regsAVR[R30_IDX].type = - regsAVR[R31_IDX].type = REG_PTR; + regsAVR[R26_IDX].type = (regsAVR[R26_IDX].type & ~REG_MASK) | REG_PTR; + regsAVR[R27_IDX].type = (regsAVR[R27_IDX].type & ~REG_MASK) | REG_PTR; + regsAVR[R28_IDX].type = (regsAVR[R28_IDX].type & ~REG_MASK) | REG_PTR; + regsAVR[R29_IDX].type = (regsAVR[R29_IDX].type & ~REG_MASK) | REG_PTR; } /* registers 0-1 / 24-25 used as scratch */ @@ -2190,23 +2219,14 @@ setDefaultRegs (eBBlock ** ebbs, int count) to do something special a) pre-assign registers to parameters RECEIVE b) mark the remaining parameter regs as free */ + /* mark the parameter regs as SCRACH */ + for (i = R16_IDX; i <= R23_IDX; i++) { + regsAVR[i].type = (regsAVR[i].type & ~REG_MASK) | REG_SCR; + regsAVR[i].isFree = 1; + } if (!currFunc->hasFcall) { - /* mark the parameter regs as GPR */ - for (i = R16_IDX; i <= R23_IDX; i++) { - regsAVR[i].type = REG_SCR; - regsAVR[i].isFree = 1; - } preAssignParms (ebbs[0]->sch); } - else { - - /* otherwise mark them as free scratch */ - for (i = R16_IDX; i <= R23_IDX; i++) { - regsAVR[i].type = REG_SCR; - regsAVR[i].isFree = 1; - } - } - /* Y - is not allocated (it is the stack frame) */ regsAVR[R28_IDX].isFree = regsAVR[R28_IDX].isFree = 0; } diff --git a/src/avr/ralloc.h b/src/avr/ralloc.h index fe5e9165..b146bca6 100644 --- a/src/avr/ralloc.h +++ b/src/avr/ralloc.h @@ -41,8 +41,10 @@ enum #define REG_PTR 0x01 #define REG_GPR 0x02 -#define REG_SCR 0x03 -#define REG_CND 0x04 +#define REG_SCR 0x04 +#define REG_CND 0x08 +#define REG_MASK 0x0f +#define REG_PAIR 0x10 /* definition for the registers */ typedef struct regs diff --git a/src/mcs51/gen.c b/src/mcs51/gen.c index 8e96cc85..f4f069de 100644 --- a/src/mcs51/gen.c +++ b/src/mcs51/gen.c @@ -3620,7 +3620,7 @@ genIfxJump (iCode * ic, char *jval) /*-----------------------------------------------------------------*/ static void genCmp (operand * left, operand * right, - operand * result, iCode * ifx, int sign) + operand * result, iCode * ifx, int sign, iCode *ic) { int size, offset = 0; unsigned long lit = 0L; @@ -3704,6 +3704,8 @@ genCmp (operand * left, operand * right, } release: + freeAsmop (left, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE)); + freeAsmop (right, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE)); if (AOP_TYPE (result) == AOP_CRY && AOP_SIZE (result)) { outBitC (result); @@ -3743,10 +3745,8 @@ genCmpGt (iCode * ic, iCode * ifx) aopOp (right, ic, FALSE); aopOp (result, ic, TRUE); - genCmp (right, left, result, ifx, sign); + genCmp (right, left, result, ifx, sign,ic); - freeAsmop (left, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE)); - freeAsmop (right, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE)); freeAsmop (result, NULL, ic, TRUE); } @@ -3773,10 +3773,8 @@ genCmpLt (iCode * ic, iCode * ifx) aopOp (right, ic, FALSE); aopOp (result, ic, TRUE); - genCmp (left, right, result, ifx, sign); + genCmp (left, right, result, ifx, sign,ic); - freeAsmop (left, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE)); - freeAsmop (right, NULL, ic, (RESULTONSTACK (ic) ? FALSE : TRUE)); freeAsmop (result, NULL, ic, TRUE); } -- 2.30.2