* src/z80/gen.h,
authorepetrich <epetrich@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 3 Oct 2003 07:08:11 +0000 (07:08 +0000)
committerepetrich <epetrich@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 3 Oct 2003 07:08:11 +0000 (07:08 +0000)
* src/z80/gen.c (aopOp, aopGet, aopPut, genDummyRead),
* src/mcs51/gen.h
* src/mcs51/gen.c (aopOp, aopGet, aopPut, genDummyRead),
* src/ds390/gen.h
* src/ds390/gen.c (aopOp, aopGet, aopPut, genDummyRead),
* src/SDCCicode.c (ast2iCode, geniCodeDummyRead): Fixed bug #663539
* src/SDCCopt.c (killDeadCode): Fixed bugs #663539 & #816705

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2918 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
src/SDCCicode.c
src/SDCCopt.c
src/ds390/gen.c
src/ds390/gen.h
src/mcs51/gen.c
src/mcs51/gen.h
src/z80/gen.c
src/z80/gen.h

index cd097e3b86104ad46ecdc5c6c6a3f801e92f9736..6f865770272fa382935e622f56971ab0a2655fba 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2003-10-03  Erik Petrich <epetrich@ivorytower.norman.ok.us>
+
+       * src/z80/gen.h,
+       * src/z80/gen.c (aopOp, aopGet, aopPut, genDummyRead),
+       * src/mcs51/gen.h
+       * src/mcs51/gen.c (aopOp, aopGet, aopPut, genDummyRead),
+       * src/ds390/gen.h
+       * src/ds390/gen.c (aopOp, aopGet, aopPut, genDummyRead),
+       * src/SDCCicode.c (ast2iCode, geniCodeDummyRead): Fixed bug #663539
+       * src/SDCCopt.c (killDeadCode): Fixed bugs #663539 & #816705
+
 2003-10-02  Erik Petrich <epetrich@ivorytower.norman.ok.us>
 
        * src/z80/gen.c (genRet): fixed bug #524753
@@ -8,7 +19,6 @@
        * src/z80/gen.c (genZ80code, _vemit2, _emit2): added support
        for tracking iCodes in the peephole optimizer for z80
 
-
 2003-10-01  Erik Petrich <epetrich@ivorytower.norman.ok.us>
 
        * src/SDCCicode.c (geniCodeJumpTable, geniCodeSwitch): fixed
index a59ed4ef99c591daa9a79c57fcc3a5636d358913..960a6964ac563891238a9eaef7a24b8d8cce2946 100644 (file)
@@ -2862,6 +2862,24 @@ geniCodeAssign (operand * left, operand * right, int nosupdate)
   return left;
 }
 
+/*-----------------------------------------------------------------*/
+/* geniCodeDummyRead - generate code for dummy read                */
+/*-----------------------------------------------------------------*/
+static void
+geniCodeDummyRead (operand * op)
+{
+  iCode *ic;
+  sym_link *type = operandType (op);
+
+  if (!IS_VOLATILE(type))
+    return;
+    
+  ic = newiCode (DUMMY_READ_VOLATILE, NULL, op);
+  ADDTOCHAIN (ic);
+
+  ic->nosupdate = 1;
+}
+
 /*-----------------------------------------------------------------*/
 /* geniCodeSEParms - generate code for side effecting fcalls       */
 /*-----------------------------------------------------------------*/
@@ -3503,8 +3521,14 @@ ast2iCode (ast * tree,int lvl)
      (tree->opval.op == NULLOP ||
      tree->opval.op == BLOCK))
     {
-      ast2iCode (tree->left,lvl+1);
-      ast2iCode (tree->right,lvl+1);
+      if (tree->left && tree->left->type == EX_VALUE)
+        geniCodeDummyRead (ast2iCode (tree->left,lvl+1));
+      else
+        ast2iCode (tree->left,lvl+1);
+      if (tree->right && tree->right->type == EX_VALUE)
+        geniCodeDummyRead (ast2iCode (tree->right,lvl+1));
+      else
+        ast2iCode (tree->right,lvl+1);
       return NULL;
     }
 
index 34e0e78a7a92ac95c82346bbe6ba9cf69b2ab409..345f8484bbe3afd793d5d4a7c325a0f6ceb128e6 100644 (file)
@@ -679,7 +679,8 @@ killDeadCode (eBBlock ** ebbs, int count)
 
              if (SKIP_IC (ic) ||
                  ic->op == IFX ||
-                 ic->op == RETURN)
+                 ic->op == RETURN ||
+                  ic->op == DUMMY_READ_VOLATILE)
                continue;
 
              /* if the result is volatile then continue */
@@ -689,6 +690,9 @@ killDeadCode (eBBlock ** ebbs, int count)
              /* if the result is a temp & isaddr then skip */
              if (IC_RESULT (ic) && POINTER_SET (ic))
                continue;
+              
+              if (POINTER_GET (ic) && IS_VOLATILE (operandType (IC_LEFT (ic))->next))
+                continue;
 
              /* if the result is used in the remainder of the */
              /* block then skip */
@@ -725,7 +729,7 @@ killDeadCode (eBBlock ** ebbs, int count)
                    continue;
 
                  kill = 1;
-               }
+                }
 
            kill:
              /* kill this one if required */
index 83ceb8bcf17d03a032babc9798fc0a5c13f42edd..99dba5b475767aa9516308518a7a4564bd8d78f1 100644 (file)
@@ -1006,13 +1006,22 @@ aopOp (operand * op, iCode * ic, bool result, bool useDP2)
          aop->aopu.dptr = sym->dptr;
          return ;
       }
-      /* else spill location  */
-      if (sym->usl.spillLoc && getSize(sym->type) != getSize(sym->usl.spillLoc->type)) {
-         /* force a new aop if sizes differ */
-         sym->usl.spillLoc->aop = NULL;
-      }
-      sym->aop = op->aop = aop =
-       aopForSym (ic, sym->usl.spillLoc, result, useDP2);
+      
+      if (sym->usl.spillLoc)
+        {
+          if (getSize(sym->type) != getSize(sym->usl.spillLoc->type))
+            {
+             /* force a new aop if sizes differ */
+             sym->usl.spillLoc->aop = NULL;
+           }
+         sym->aop = op->aop = aop =
+                    aopForSym (ic, sym->usl.spillLoc, result, useDP2);
+         aop->size = getSize (sym->type);
+         return;
+        }
+      
+      /* else must be a dummy iTemp */
+      sym->aop = op->aop = aop = newAsmop (AOP_DUMMY);
       aop->size = getSize (sym->type);
       return;
     }
@@ -1182,6 +1191,8 @@ aopGet (asmop *aop,
   /* depending on type */
   switch (aop->type)
     {
+    case AOP_DUMMY:
+      return zero;
 
     case AOP_R0:
     case AOP_R1:
@@ -1383,6 +1394,10 @@ aopPut (asmop * aop, char *s, int offset)
   /* depending on where it is ofcourse */
   switch (aop->type)
     {
+    case AOP_DUMMY:
+      MOVA (s);                /* read s in case it was volatile */
+      break;
+      
     case AOP_DIR:
         if (offset)
        {
@@ -12650,7 +12665,7 @@ genDummyRead (iCode * ic)
   offset = 0;
   while (size--)
     {
-      emitcode ("mov", "a,%s", aopGet (AOP (right), offset, FALSE, FALSE, FALSE));
+      MOVA (aopGet (AOP (right), offset, FALSE, FALSE, FALSE));
       offset++;
     }
 
index 04726f8b2ecda116d4580fdba852eb09bb08b99f..8f33d7122a5f97918ba6e6bf6b90bfb1f0a1b874 100644 (file)
@@ -31,7 +31,7 @@ enum
     AOP_REG, AOP_DIR,
     AOP_DPTR, AOP_DPTR2, AOP_R0, AOP_R1,
     AOP_STK, AOP_IMMD, AOP_STR,
-    AOP_CRY, AOP_ACC, AOP_DPTRn
+    AOP_CRY, AOP_ACC, AOP_DPTRn, AOP_DUMMY
   };
 
 /* type asmop : a homogenised type for 
@@ -54,6 +54,7 @@ typedef struct asmop
                                   AOP_STR    -  array of strings
                                   AOP_ACC    -  result is in the acc:b pair
                                   AOP_DPTRn  -  is in dptr(n)
+                                  AOP_DUMMY  -  read as 0, discard writes
                                 */
     short coff;                        /* current offset */
     short size;                        /* total size */
index 89a30529d41cc2d374c77d6f4040a25db6c2ad3f..fc821211b07c879bef1d98b844f5c674d375ce2f 100644 (file)
@@ -708,13 +708,21 @@ aopOp (operand * op, iCode * ic, bool result)
          return;
        }
 
-      /* else spill location  */
-      if (sym->usl.spillLoc && getSize(sym->type) != getSize(sym->usl.spillLoc->type)) {
-         /* force a new aop if sizes differ */
-         sym->usl.spillLoc->aop = NULL;
-      }
-      sym->aop = op->aop = aop =
-       aopForSym (ic, sym->usl.spillLoc, result);
+      if (sym->usl.spillLoc)
+        {
+          if (getSize(sym->type) != getSize(sym->usl.spillLoc->type))
+            {
+             /* force a new aop if sizes differ */
+             sym->usl.spillLoc->aop = NULL;
+           }
+         sym->aop = op->aop = aop =
+                    aopForSym (ic, sym->usl.spillLoc, result);
+         aop->size = getSize (sym->type);
+         return;
+        }
+      
+      /* else must be a dummy iTemp */
+      sym->aop = op->aop = aop = newAsmop (AOP_DUMMY);
       aop->size = getSize (sym->type);
       return;
     }
@@ -871,6 +879,8 @@ aopGetUsesAcc (asmop *aop, int offset)
       if (strcmp (aop->aopu.aop_str[offset], "a") == 0)
        return TRUE;
       return FALSE;
+    case AOP_DUMMY:
+      return FALSE;
     default:
       /* Error case --- will have been caught already */
       wassert(0);
@@ -896,7 +906,9 @@ aopGet (asmop * aop, int offset, bool bit16, bool dname)
   /* depending on type */
   switch (aop->type)
     {
-
+    case AOP_DUMMY:
+      return zero;
+      
     case AOP_R0:
     case AOP_R1:
       /* if we need to increment it */
@@ -1035,6 +1047,10 @@ aopPut (asmop * aop, const char *s, int offset, bool bvolatile)
   /* depending on where it is ofcourse */
   switch (aop->type)
     {
+    case AOP_DUMMY:
+      MOVA (s);                /* read s in case it was volatile */
+      break;
+      
     case AOP_DIR:
       if (offset)
        sprintf (d, "(%s + %d)",
@@ -8965,7 +8981,7 @@ genDummyRead (iCode * ic)
   offset = 0;
   while (size--)
     {
-      emitcode ("mov", "a,%s", aopGet (AOP (right), offset, FALSE, FALSE));
+      MOVA (aopGet (AOP (right), offset, FALSE, FALSE));
       offset++;
     }
 
index 12cc17d730fa29968bb6386782bb428df96c07d1..ada89d6acdd75b0ff18645416437d2c452c852e0 100644 (file)
@@ -31,7 +31,7 @@ enum
     AOP_REG, AOP_DIR,
     AOP_DPTR, AOP_R0, AOP_R1,
     AOP_STK, AOP_IMMD, AOP_STR,
-    AOP_CRY, AOP_ACC
+    AOP_CRY, AOP_ACC, AOP_DUMMY
   };
 
 /* type asmop : a homogenised type for 
@@ -53,6 +53,7 @@ typedef struct asmop
        AOP_CRY    -  carry contains the value of this
        AOP_STR    -  array of strings
        AOP_ACC    -  result is in the acc:b pair
+       AOP_DUMMY  -  read as 0, discard writes
     */
     short coff;                        /* current offset */
     short size;                        /* total size */
index dc7f19c5d44308cc62d82134a5febe015b4f0a69..263944333bdaaa71498bfe706485ceb4ab20ba9c 100644 (file)
@@ -262,7 +262,8 @@ static const char *aopNames[] = {
   "AOP_HLREG",
   "AOP_SIMPLELIT",
   "AOP_EXSTK",
-  "AOP_PAIRPT"
+  "AOP_PAIRPT",
+  "AOP_DUMMY"
 };
 
 static bool
@@ -1082,13 +1083,21 @@ aopOp (operand * op, iCode * ic, bool result, bool requires_a)
          return;
        }
 
-      /* else spill location  */
-      if (sym->usl.spillLoc && getSize(sym->type) != getSize(sym->usl.spillLoc->type)) {
-         /* force a new aop if sizes differ */
-         sym->usl.spillLoc->aop = NULL;
-      }
-      sym->aop = op->aop = aop =
-       aopForSym (ic, sym->usl.spillLoc, result, requires_a);
+      if (sym->usl.spillLoc)
+        {
+         if (getSize(sym->type) != getSize(sym->usl.spillLoc->type))
+            {
+             /* force a new aop if sizes differ */
+             sym->usl.spillLoc->aop = NULL;
+           }
+         sym->aop = op->aop = aop =
+                    aopForSym (ic, sym->usl.spillLoc, result, requires_a);
+         aop->size = getSize (sym->type);
+         return;
+        }
+      
+      /* else must be a dummy iTemp */
+      sym->aop = op->aop = aop = newAsmop (AOP_DUMMY);
       aop->size = getSize (sym->type);
       return;
     }
@@ -1584,6 +1593,10 @@ aopGet (asmop * aop, int offset, bool bit16)
   /* depending on type */
   switch (aop->type)
     {
+    case AOP_DUMMY:
+      tsprintf (buffer, sizeof(buffer), "!zero");
+      return traceAlloc(&_G.trace.aops, Safe_strdup(buffer));
+    
     case AOP_IMMD:
       /* PENDING: re-target */
       if (bit16)
@@ -1770,6 +1783,10 @@ aopPut (asmop * aop, const char *s, int offset)
   /* depending on where it is ofcourse */
   switch (aop->type)
     {
+    case AOP_DUMMY:
+      _moveA (s);  /* in case s is volatile */
+      break;
+      
     case AOP_DIR:
       /* Direct.  Hmmm. */
       wassert (IS_GB);
@@ -7099,9 +7116,24 @@ genReceive (iCode * ic)
 static void
 genDummyRead (iCode * ic)
 {
-  emit2 ("; genDummyRead not implemented");
+  operand *right;
+  int size, offset;
 
-  ic = ic;
+  right = IC_RIGHT (ic);
+  aopOp (right, ic, FALSE, FALSE);
+  
+  /* general case */
+  size = AOP_SIZE (right);
+  offset = 0;
+
+  while (size--)
+    {
+      _moveA (aopGet (AOP (right), offset, FALSE));
+      offset++;
+    }
+
+release:
+  freeAsmop (right, NULL, ic);
 }
 
 enum
@@ -7910,6 +7942,7 @@ genZ80Code (iCode * lic)
           break;
 
        case DUMMY_READ_VOLATILE:
+         emitDebug ("; genDummyRead");
          genDummyRead (ic);
          break;
 
index becc53adba735c71d4474dbc1703fdaca2f4e166..3e666177e8adf28cdb6461a2619f43928fa73df4 100644 (file)
@@ -57,7 +57,9 @@ typedef enum
     /* Is in the extended stack pointer (IY on the Z80) */
     AOP_EXSTK,
     /* Is referenced by a pointer in a register pair. */
-    AOP_PAIRPTR
+    AOP_PAIRPTR,
+    /* Read as 0, discard writes */
+    AOP_DUMMY
   }
 AOP_TYPE;