]> git.gag.com Git - fw/sdcc/commitdiff
Cast of a remat is also remat.
authorsandeep <sandeep@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 5 Nov 2001 15:18:07 +0000 (15:18 +0000)
committersandeep <sandeep@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 5 Nov 2001 15:18:07 +0000 (15:18 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1508 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/mcs51/gen.c
src/mcs51/gen.h
src/mcs51/ralloc.c

index 646faf856cc938390d7937c82a57d241d14d94d6..97509e80b464f07fbbe7590266a4251218d5ebd5 100644 (file)
@@ -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;
index c9bb7cc6893f4549c61a68c24844c201b7cd3564..12cc17d730fa29968bb6386782bb428df96c07d1 100644 (file)
@@ -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 */
       }
index 3c5f39dbebe0c11b4202412e46c41e19aae7a902..34a1210851dbaacaba3a3fd169c4247d675c7695 100644 (file)
@@ -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))))
        {