From: sandeep Date: Mon, 5 Nov 2001 15:19:24 +0000 (+0000) Subject: cast of a remat is also remat. X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=1a17f3f6c5f1c9adc604ad9b43bbe9530b896746;p=fw%2Fsdcc cast of a remat is also remat. git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1509 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/src/ds390/gen.c b/src/ds390/gen.c index ae0a0f2a..7c443247 100644 --- a/src/ds390/gen.c +++ b/src/ds390/gen.c @@ -4,6 +4,7 @@ Written By - Sandeep Dutta . sandeep.dutta@usa.net (1998) and - Jean-Louis VERN.jlvern@writeme.com (1999) Bug Fixes - Wojciech Stryjewski wstryj1@tiger.lsu.edu (1999 v2.1.9a) + DS390 adaptation by Kevin Vigor This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the @@ -510,8 +511,8 @@ aopForSym (iCode * ic, symbol * sym, bool result, bool useDP2) 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; } @@ -547,7 +548,7 @@ aopForRemat (symbol * sym) { iCode *ic = sym->rematiCode; asmop *aop = newAsmop (AOP_IMMD); - + int ptr_type ; int val = 0; for (;;) @@ -556,9 +557,14 @@ 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; } @@ -570,8 +576,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; } @@ -1030,15 +1043,17 @@ aopGet (asmop * aop, return (dname ? "acc" : "a"); 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/ds390/gen.h b/src/ds390/gen.h index 5ff118ec..0a470a33 100644 --- a/src/ds390/gen.h +++ b/src/ds390/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/ds390/ralloc.c b/src/ds390/ralloc.c index 40bc1c86..831612bd 100644 --- a/src/ds390/ralloc.c +++ b/src/ds390/ralloc.c @@ -1386,7 +1386,11 @@ rematStr (symbol * sym) ic = OP_SYMBOL (IC_LEFT (ic))->rematiCode; 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; @@ -1448,7 +1452,7 @@ regTypeNum () /* if remat in data space */ if (OP_SYMBOL (IC_LEFT (ic))->remat && - // sym->type && + !IS_CAST_ICODE(OP_SYMBOL (IC_LEFT (ic))->rematiCode) && DCL_TYPE (aggrToPtr (sym->type, FALSE)) == POINTER) { @@ -2300,6 +2304,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) { @@ -2308,6 +2313,20 @@ packRegisters (eBBlock * ebp) OP_SYMBOL (IC_RESULT (ic))->rematiCode = 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 */ @@ -2315,6 +2334,7 @@ packRegisters (eBBlock * ebp) (IS_SYMOP (IC_LEFT (ic)) && IS_ITEMP (IC_RESULT (ic)) && OP_SYMBOL (IC_LEFT (ic))->remat && + !IS_CAST_ICODE(OP_SYMBOL (IC_LEFT (ic))->rematiCode) && bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) == 1 && IS_OP_LITERAL (IC_RIGHT (ic)))) {