X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fmcs51%2Fralloc.c;h=2a627aade38fade32b735d965faa979edbcdd4f7;hb=bb226788dab3832b0ec0cda70874ce3fce4eebc6;hp=e1ea0943438b240ec7738c52d6e427a3c77a6110;hpb=f7ef003ee605816776f9984ea4109ad3d8f94b5f;p=fw%2Fsdcc diff --git a/src/mcs51/ralloc.c b/src/mcs51/ralloc.c index e1ea0943..2a627aad 100644 --- a/src/mcs51/ralloc.c +++ b/src/mcs51/ralloc.c @@ -527,12 +527,16 @@ createStackSpil (symbol * sym) { SPEC_SCLS (sloc->etype) = S_DATA; } + else if (SPEC_SCLS (sloc->etype) == S_SBIT) + { + SPEC_SCLS (sloc->etype) = S_BIT; + } SPEC_EXTR (sloc->etype) = 0; SPEC_STAT (sloc->etype) = 0; SPEC_VOLATILE(sloc->etype) = 0; SPEC_ABSA(sloc->etype) = 0; - /* we don't allow it to be allocated` + /* we don't allow it to be allocated onto the external stack since : so we temporarily turn it off ; we also turn off memory model to prevent @@ -574,6 +578,7 @@ createStackSpil (symbol * sym) /*-----------------------------------------------------------------*/ /* isSpiltOnStack - returns true if the spil location is on stack */ +/* or otherwise needs a pointer register */ /*-----------------------------------------------------------------*/ static bool isSpiltOnStack (symbol * sym) @@ -592,6 +597,9 @@ isSpiltOnStack (symbol * sym) if (!sym->usl.spillLoc) return FALSE; + if (sym->usl.spillLoc->onStack || sym->usl.spillLoc->iaccess) + return TRUE; + etype = getSpec (sym->usl.spillLoc->type); if (IN_STACK (etype)) return TRUE; @@ -660,7 +668,7 @@ selectSpil (iCode * ic, eBBlock * ebp, symbol * forSym) selectS = liveRangesWith (lrcs, bitType, ebp, ic); for (sym = setFirstItem (selectS); sym; sym = setNextItem (selectS)) - { + { bitVectUnSetBit (lrcs, sym->key); } } @@ -1502,6 +1510,10 @@ static void fillGaps() if (!sym->spillA || !sym->clashes || sym->remat) continue ; + /* if spilt in direct space the original rname is lost */ + if (sym->usl.spillLoc && (IN_DIRSPACE (SPEC_OCLS (sym->usl.spillLoc->etype)))) + continue; + /* find the liveRanges this one clashes with, that are still assigned to registers & mark the registers as used*/ for ( i = 0 ; i < sym->clashes->size ; i ++) { @@ -1910,6 +1922,8 @@ regTypeNum (eBBlock *ebbs) { if (IS_AGGREGATE (sym->type) || sym->isptr) sym->type = aggrToPtr (sym->type, FALSE); + else if (IS_BIT(sym->type)) + sym->regType = REG_CND; continue; } @@ -2112,10 +2126,10 @@ packRegsForAssign (iCode * ic, eBBlock * ebp) /* Don't move an assignment out of a critical block */ if (dic->op == CRITICAL) - { - dic = NULL; - break; - } + { + dic = NULL; + break; + } if (SKIP_IC2 (dic)) continue; @@ -2440,8 +2454,6 @@ packRegsForSupport (iCode * ic, eBBlock * ebp) return 0; } -#define IS_OP_RUONLY(x) (x && IS_SYMOP(x) && OP_SYMBOL(x)->ruonly) - /*-----------------------------------------------------------------*/ /* packRegsForOneuse : - will reduce some registers for single Use */ @@ -2472,8 +2484,8 @@ packRegsForOneuse (iCode * ic, operand * op, eBBlock * ebp) if (ic->op == SEND && ic->argreg != 1) return NULL; - /* this routine will mark the a symbol as used in one - instruction use only && if the defintion is local + /* this routine will mark the symbol as used in one + instruction use only && if the definition is local (ie. within the basic block) && has only one definition && that definition is either a return value from a function or does not contain any variables in @@ -2481,7 +2493,7 @@ packRegsForOneuse (iCode * ic, operand * op, eBBlock * ebp) if (bitVectnBitsOn (OP_USES (op)) > 1) return NULL; - /* if it has only one defintion */ + /* if it has only one definition */ if (bitVectnBitsOn (OP_DEFS (op)) > 1) return NULL; /* has more than one definition */ @@ -2519,25 +2531,25 @@ packRegsForOneuse (iCode * ic, operand * op, eBBlock * ebp) } else { - /* otherwise check that the definition does - not contain any symbols in far space */ - if (isOperandInFarSpace (IC_LEFT (dic)) || - isOperandInFarSpace (IC_RIGHT (dic)) || - IS_OP_RUONLY (IC_LEFT (ic)) || - IS_OP_RUONLY (IC_RIGHT (ic))) - { - return NULL; - } + /* otherwise check that the definition does + not contain any symbols in far space */ + if (isOperandInFarSpace (IC_LEFT (dic)) || + isOperandInFarSpace (IC_RIGHT (dic)) || + IS_OP_RUONLY (IC_LEFT (ic)) || + IS_OP_RUONLY (IC_RIGHT (ic))) + { + return NULL; + } - /* if pointer set then make sure the pointer - is one byte */ - if (POINTER_SET (dic) && - !IS_DATA_PTR (aggrToPtr (operandType (IC_RESULT (dic)), FALSE))) - return NULL; + /* if pointer set then make sure the pointer + is one byte */ + if (POINTER_SET (dic) && + !IS_DATA_PTR (aggrToPtr (operandType (IC_RESULT (dic)), FALSE))) + return NULL; - if (POINTER_GET (dic) && - !IS_DATA_PTR (aggrToPtr (operandType (IC_LEFT (dic)), FALSE))) - return NULL; + if (POINTER_GET (dic) && + !IS_DATA_PTR (aggrToPtr (operandType (IC_LEFT (dic)), FALSE))) + return NULL; } /* Make sure no overlapping liverange is already assigned to DPTR */ @@ -2559,11 +2571,10 @@ packRegsForOneuse (iCode * ic, operand * op, eBBlock * ebp) sic = dic; - /* also make sure the intervenening instructions - don't have any thing in far space */ + /* also make sure the intervening instructions + don't have anything in far space */ for (dic = dic->next; dic && dic != ic && sic != ic; dic = dic->next) { - /* if there is an intervening function call then no */ if (dic->op == CALL || dic->op == PCALL) return NULL; @@ -2657,7 +2668,7 @@ bool isCommutativeOp(unsigned int op) /* operandUsesAcc - determines whether the code generated for this */ /* operand will have to use the accumulator */ /*-----------------------------------------------------------------*/ -bool operandUsesAcc(operand *op) +bool operandUsesAcc(operand *op, bool allowBitspace) { if (!op) return FALSE; @@ -2687,7 +2698,7 @@ bool operandUsesAcc(operand *op) if (sym->iaccess && symspace->paged) return TRUE; /* must fetch paged indirect sym via accumulator */ - if (IN_BITSPACE(symspace)) + if (!allowBitspace && IN_BITSPACE(symspace)) return TRUE; /* fetching bit vars uses the accumulator */ if (IN_FARSPACE(symspace) || IN_CODESPACE(symspace)) @@ -2741,7 +2752,6 @@ packRegsForAccUse (iCode * ic) getSize (operandType (IC_RESULT (ic))) > 1) return; - /* has only one definition */ if (bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) > 1) return; @@ -2769,7 +2779,7 @@ packRegsForAccUse (iCode * ic) getSize (aggrToPtr (operandType (IC_RESULT (uic)), FALSE)) > 1) return; - /* if the usage is not is an assignment + /* if the usage is not an assignment or an arithmetic / bitwise / shift operation then not */ if (uic->op != '=' && !IS_ARITHMETIC_OP (uic) && @@ -2811,10 +2821,10 @@ packRegsForAccUse (iCode * ic) goto accuse; /* if the other operand uses the accumulator then we cannot */ - if ( (IC_LEFT(uic)->key == IC_RESULT(ic)->key && - operandUsesAcc(IC_RIGHT(uic))) || + if ( (IC_LEFT (uic)->key == IC_RESULT (ic)->key && + operandUsesAcc (IC_RIGHT (uic), IS_BIT (operandType (IC_LEFT (uic))))) || (IC_RIGHT(uic)->key == IC_RESULT(ic)->key && - operandUsesAcc(IC_LEFT(uic))) ) + operandUsesAcc (IC_LEFT (uic), IS_BIT (operandType (IC_RIGHT (uic))))) ) return; /* make sure this is on the left side if not commutative */ @@ -3005,6 +3015,7 @@ packRegisters (eBBlock ** ebpp, int blockno) IS_SYMOP (IC_RIGHT (ic)) && OP_SYMBOL (IC_RIGHT (ic))->remat && !IS_CAST_ICODE(OP_SYMBOL (IC_RIGHT (ic))->rematiCode) && + !isOperandGlobal(IC_RESULT(ic)) && /* due to bug 1618050 */ bitVectnBitsOn (OP_SYMBOL (IC_RESULT (ic))->defs) <= 1) { OP_SYMBOL (IC_RESULT (ic))->remat = @@ -3046,11 +3057,10 @@ packRegisters (eBBlock ** ebpp, int blockno) } /* mark the pointer usages */ - if (POINTER_SET (ic)) + if (POINTER_SET (ic) && IS_SYMOP (IC_RESULT (ic))) OP_SYMBOL (IC_RESULT (ic))->uptr = 1; - if (POINTER_GET (ic) && - IS_SYMOP(IC_LEFT (ic))) + if (POINTER_GET (ic) && IS_SYMOP (IC_LEFT (ic))) OP_SYMBOL (IC_LEFT (ic))->uptr = 1; if (!SKIP_IC2 (ic)) @@ -3135,6 +3145,7 @@ packRegisters (eBBlock ** ebpp, int blockno) /* if pointer set & left has a size more than one and right is not in far space */ if (POINTER_SET (ic) && + IS_SYMOP (IC_RESULT (ic)) && !isOperandInFarSpace (IC_RIGHT (ic)) && !OP_SYMBOL (IC_RESULT (ic))->remat && !IS_OP_RUONLY (IC_RIGHT (ic)) && @@ -3150,7 +3161,6 @@ packRegisters (eBBlock ** ebpp, int blockno) getSize (aggrToPtr (operandType (IC_LEFT (ic)), FALSE)) > 1) packRegsForOneuse (ic, IC_LEFT (ic), ebp); - /* if this is a cast for intergral promotion then check if it's the only use of the definition of the operand being casted/ if yes then replace @@ -3185,7 +3195,6 @@ packRegisters (eBBlock ** ebpp, int blockno) } else { - /* if the type from and type to are the same then if this is the only use then packit */ if (compareType (operandType (IC_RIGHT (ic)), @@ -3221,7 +3230,7 @@ packRegisters (eBBlock ** ebpp, int blockno) /* pack registers for accumulator use, when the result of an arithmetic or bit wise operation has only one use, that use is immediately following - the defintion and the using iCode has only one + the definition and the using iCode has only one operand or has two operands but one is literal & the result of that operation is not on stack then we can leave the result of this operation in acc:b @@ -3260,7 +3269,7 @@ mcs51_assignRegisters (ebbIndex * ebbi) } else { - mcs51_nRegs = 8; + mcs51_nRegs = 8; } _G.allBitregs = findAllBitregs ();