fix unused parameter receive bug (fix ifdef'd out right now)
[fw/sdcc] / src / SDCCopt.c
index 5e5afb9a15250529d7a396e2ac7ae66ebf53ce4f..89fc4a150ac5222f07f757c4a890f8877e276ac3 100644 (file)
@@ -613,6 +613,40 @@ static void printCyclomatic (eBBlock **ebbs, int count)
     werror(I_CYCLOMATIC,currFunc->name,nEdges,nNodes, nEdges - nNodes + 2);
 }
 
+#ifdef POST_2_2_1
+/* Turn this on when it's safe to destablize */     
+/*-----------------------------------------------------------------*/
+/* discardDeadParamReceives - remove any RECEIVE opcodes which     */
+/* refer to dead variables.                                       */
+/*-----------------------------------------------------------------*/
+static void discardDeadParamReceives(eBBlock **ebbs, int count)
+{
+    int        i;
+    iCode      *ic;
+    iCode      dummyIcode;
+
+    for (i = 0 ; i < count ; i++)
+    {
+        for ( ic = ebbs[i]->sch ; ic ; ic = ic->next )
+        {
+            if (ic->op == RECEIVE)
+            {
+               if (IC_RESULT(ic) && OP_SYMBOL(IC_RESULT(ic))
+                && !OP_SYMBOL(IC_RESULT(ic))->used)
+               {
+#if 0                      
+                   fprintf(stderr, "discarding dead receive for %s\n", 
+                           OP_SYMBOL(IC_RESULT(ic))->name);
+#endif                             
+                   dummyIcode.next = ic->next;
+                   remiCodeFromeBBlock(ebbs[i], ic);
+                   ic = &dummyIcode;
+               }
+            }
+        }
+    }
+}
+#endif
 
 /*-----------------------------------------------------------------*/
 /* eBBlockFromiCode - creates extended basic blocks from iCode     */
@@ -742,6 +776,14 @@ eBBlock **eBBlockFromiCode (iCode *ic)
     if (options.dump_range)
        dumpEbbsToFileExt(".dumprange",ebbs,count);
 
+#ifdef POST_2_2_1
+    /* Turn this on when it's safe to destablize */    
+    /* Now that we have the live ranges, discard parameter
+     * receives for unused parameters.
+     */
+    discardDeadParamReceives(ebbs,count);
+#endif
+
     /* allocate registers & generate code */   
     port->assignRegisters(ebbs,count);