From 84f1deb0a3d6511fb720149a11b12c373311d4d9 Mon Sep 17 00:00:00 2001 From: sandeep Date: Mon, 5 Nov 2001 15:18:07 +0000 Subject: [PATCH] Cast of a remat is also remat. git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1508 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- src/mcs51/gen.c | 35 +++++++++++++++++++++++++---------- src/mcs51/gen.h | 6 +++++- src/mcs51/ralloc.c | 22 ++++++++++++++++++++++ 3 files changed, 52 insertions(+), 11 deletions(-) diff --git a/src/mcs51/gen.c b/src/mcs51/gen.c index 646faf85..97509e80 100644 --- a/src/mcs51/gen.c +++ b/src/mcs51/gen.c @@ -350,8 +350,8 @@ aopForSym (iCode * ic, symbol * sym, bool result) if (IS_FUNC (sym->type)) { sym->aop = aop = newAsmop (AOP_IMMD); - aop->aopu.aop_immd = Safe_calloc (1, strlen (sym->rname) + 1); - strcpy (aop->aopu.aop_immd, sym->rname); + aop->aopu.aop_immd.aop_immd1 = Safe_calloc (1, strlen (sym->rname) + 1); + strcpy (aop->aopu.aop_immd.aop_immd1, sym->rname); aop->size = FPTRSIZE; return aop; } @@ -377,6 +377,7 @@ aopForRemat (symbol * sym) { iCode *ic = sym->rematiCode; asmop *aop = newAsmop (AOP_IMMD); + int ptr_type ; int val = 0; for (;;) @@ -385,8 +386,13 @@ aopForRemat (symbol * sym) val += (int) operandLitValue (IC_RIGHT (ic)); else if (ic->op == '-') val -= (int) operandLitValue (IC_RIGHT (ic)); - else - break; + else if (IS_CAST_ICODE(ic)) { + sym_link *from_type = operandType(IC_RIGHT(ic)); + aop->aopu.aop_immd.from_cast_remat = 1; + ic = OP_SYMBOL (IC_RIGHT (ic))->rematiCode; + ptr_type = DCL_TYPE(from_type); + continue ; + } else break; ic = OP_SYMBOL (IC_LEFT (ic))->rematiCode; } @@ -399,8 +405,15 @@ aopForRemat (symbol * sym) else strcpy (buffer, OP_SYMBOL (IC_LEFT (ic))->rname); - aop->aopu.aop_immd = Safe_calloc (1, strlen (buffer) + 1); - strcpy (aop->aopu.aop_immd, buffer); + aop->aopu.aop_immd.aop_immd1 = Safe_calloc (1, strlen (buffer) + 1); + strcpy (aop->aopu.aop_immd.aop_immd1, buffer); + /* set immd2 field if required */ + if (aop->aopu.aop_immd.from_cast_remat) { + sprintf(buffer,"#0x%02x",ptr_type); + aop->aopu.aop_immd.aop_immd2 = Safe_calloc (1, strlen (buffer) + 1); + strcpy (aop->aopu.aop_immd.aop_immd2, buffer); + } + return aop; } @@ -802,15 +815,17 @@ aopGet (asmop * aop, int offset, bool bit16, bool dname) case AOP_IMMD: - if (bit16) - sprintf (s, "#%s", aop->aopu.aop_immd); + if (aop->aopu.aop_immd.from_cast_remat && (offset == (aop->size-1))) { + sprintf(s,"%s",aop->aopu.aop_immd.aop_immd2); + } else if (bit16) + sprintf (s, "#%s", aop->aopu.aop_immd.aop_immd1); else if (offset) sprintf (s, "#(%s >> %d)", - aop->aopu.aop_immd, + aop->aopu.aop_immd.aop_immd1, offset * 8); else sprintf (s, "#%s", - aop->aopu.aop_immd); + aop->aopu.aop_immd.aop_immd1); rs = Safe_calloc (1, strlen (s) + 1); strcpy (rs, s); return rs; diff --git a/src/mcs51/gen.h b/src/mcs51/gen.h index c9bb7cc6..12cc17d7 100644 --- a/src/mcs51/gen.h +++ b/src/mcs51/gen.h @@ -65,7 +65,11 @@ typedef struct asmop regs *aop_reg[4]; /* array of registers */ char *aop_dir; /* if direct */ regs *aop_ptr; /* either -> to r0 or r1 */ - char *aop_immd; /* if immediate others are implied */ + struct { + int from_cast_remat; /* cast remat created this : immd2 field used for highest order*/ + char *aop_immd1; /* if immediate others are implied */ + char *aop_immd2; /* cast remat will generate this */ + } aop_immd; int aop_stk; /* stack offset when AOP_STK */ char *aop_str[4]; /* just a string array containing the location */ } diff --git a/src/mcs51/ralloc.c b/src/mcs51/ralloc.c index 3c5f39db..34a12108 100644 --- a/src/mcs51/ralloc.c +++ b/src/mcs51/ralloc.c @@ -1383,6 +1383,11 @@ rematStr (symbol * sym) continue; } + /* cast then continue */ + if (IS_CAST_ICODE(ic)) { + ic = OP_SYMBOL (IC_RIGHT (ic))->rematiCode; + continue; + } /* we reached the end */ sprintf (s, "%s", OP_SYMBOL (IC_LEFT (ic))->rname); break; @@ -1444,6 +1449,7 @@ regTypeNum () /* if 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) { @@ -2287,6 +2293,7 @@ packRegisters (eBBlock * ebp) !POINTER_SET (ic) && IS_SYMOP (IC_RIGHT (ic)) && OP_SYMBOL (IC_RIGHT (ic))->remat && + !IS_CAST_ICODE(OP_SYMBOL (IC_RIGHT (ic))->rematiCode) && bitVectnBitsOn (OP_SYMBOL (IC_RESULT (ic))->defs) <= 1) { @@ -2296,12 +2303,27 @@ packRegisters (eBBlock * ebp) OP_SYMBOL (IC_RIGHT (ic))->rematiCode; } + /* if cast to a generic pointer & the pointer being + cast is remat, then we can remat this cast as well */ + if (ic->op == CAST && + IS_SYMOP(IC_RIGHT(ic)) && + OP_SYMBOL(IC_RIGHT(ic))->remat ) { + sym_link *to_type = operandType(IC_LEFT(ic)); + sym_link *from_type = operandType(IC_RIGHT(ic)); + if (IS_GENPTR(to_type) && IS_PTR(from_type)) { + OP_SYMBOL (IC_RESULT (ic))->remat = 1; + OP_SYMBOL (IC_RESULT (ic))->rematiCode = ic; + OP_SYMBOL (IC_RESULT (ic))->usl.spillLoc = NULL; + } + } + /* if this is a +/- operation with a rematerizable then mark this as rematerializable as well */ if ((ic->op == '+' || ic->op == '-') && (IS_SYMOP (IC_LEFT (ic)) && IS_ITEMP (IC_RESULT (ic)) && OP_SYMBOL (IC_LEFT (ic))->remat && + !IS_CAST_ICODE(OP_SYMBOL (IC_RIGHT (ic))->rematiCode) && bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) == 1 && IS_OP_LITERAL (IC_RIGHT (ic)))) { -- 2.47.2