Remove all references to the GC library, replacing GC_malloc
[fw/sdcc] / src / SDCCopt.c
index 25b44b9b83fa416011784a56d93b7e285ef5faca..1f12948b8edb3a961cb27fdc5573c902ce4d9493 100644 (file)
@@ -158,29 +158,24 @@ static void cnvToFloatCast (iCode *ic, eBBlock *ebp)
 {    
     iCode *ip, *newic;    
     symbol *func;
-    link *type = operandType(IC_RIGHT(ic));
+    sym_link *type = operandType(IC_RIGHT(ic));
     int linenno = ic->lineno;
+    int bwd, su;
 
     ip = ic->next ;
     /* remove it from the iCode */
     remiCodeFromeBBlock (ebp,ic);
     /* depending on the type */
-    if (checkType(type,charType) == 1)
-       func = __char2fs ;
-    else
-       if (checkType(type,ucharType) == 1)
-           func = __uchar2fs;
-       else
-           if (checkType(type,intType) == 1)
-               func = __int2fs;
-           else
-               if (checkType(type,uintType) == 1)
-                   func = __uint2fs ;
-               else
-                   if (checkType(type,longType) == 1)
-                       func = __long2fs;
-                   else
-                       func = __ulong2fs ;
+    for (bwd = 0; bwd < 3; bwd++) {
+       for (su = 0; su < 2; su++) {
+           if (checkType(type, __multypes[bwd][su]) == 1) {
+               func = __conv[0][bwd][su];
+               goto found;
+           }
+       }
+    }
+    assert(0);
+ found:
 
     /* if float support routines NOT compiled as reentrant */
     if (! options.float_rent) {
@@ -222,30 +217,25 @@ static void cnvFromFloatCast (iCode *ic, eBBlock *ebp)
 {
     iCode *ip, *newic;    
     symbol *func;
-    link *type = operandType(IC_LEFT(ic));
+    sym_link *type = operandType(IC_LEFT(ic));
     int lineno = ic->lineno ;
+    int bwd, su;
 
     ip = ic->next ;
     /* remove it from the iCode */
     remiCodeFromeBBlock (ebp,ic);
 
     /* depending on the type */
-    if (checkType(type,charType) == 1)
-       func = __fs2char ;
-    else
-       if (checkType(type,ucharType) == 1)
-           func = __fs2uchar;
-       else
-           if (checkType(type,intType) == 1)
-               func = __fs2int;
-           else
-               if (checkType(type,uintType) == 1)
-                   func = __fs2uint ;
-               else
-                   if (checkType(type,longType) == 1)
-                       func = __fs2long;
-                   else
-                       func = __fs2ulong ;
+    for (bwd = 0; bwd < 3; bwd++) {
+       for (su = 0; su < 2; su++) {
+           if (checkType(type, __multypes[bwd][su]) == 1) {
+               func = __conv[1][bwd][su];
+               goto found;
+           }
+       }
+    }
+    assert(0);
+ found:
 
     /* if float support routines NOT compiled as reentrant */
     if (! options.float_rent) {        
@@ -284,31 +274,34 @@ static void cnvFromFloatCast (iCode *ic, eBBlock *ebp)
 /*-----------------------------------------------------------------*/
 /* convilong - converts int or long mults or divs to fcalls        */
 /*-----------------------------------------------------------------*/
-static void convilong (iCode *ic, eBBlock *ebp, link *type, int op)
+static void convilong (iCode *ic, eBBlock *ebp, sym_link *type, int op)
 {    
-    symbol *func;
+    symbol *func = NULL;
     iCode *ip = ic->next;
     iCode *newic ;
     int lineno = ic->lineno;
-
+    int bwd;
+    int su;
     remiCodeFromeBBlock (ebp,ic);
 
     /* depending on the type */
-    if (checkType(type,intType) == 1)
-       func = (op == '*' ? __mulsint : 
-               (op == '%' ? __modsint :__divsint));
-    else
-       if (checkType(type,uintType) == 1)
-           func = (op == '*' ? __muluint : 
-                   (op == '%' ? __moduint : __divuint));
-       else
-           if (checkType(type,longType) == 1)
-               func = (op == '*' ? __mulslong : 
-                       (op == '%' ? __modslong : __divslong));
-           else
-               func = (op == '*'?  __mululong : 
-                       (op == '%' ? __modulong : __divulong));
-
+    for (bwd = 0; bwd < 3; bwd++) {
+       for (su = 0; su < 2; su++) {
+           if (checkType(type, __multypes[bwd][su]) == 1) {
+               if (op == '*')
+                   func = __muldiv[0][bwd][su];
+               else if (op == '/')
+                   func = __muldiv[1][bwd][su];
+               else if (op == '%')
+                   func = __muldiv[2][bwd][su];
+               else
+                   assert(0);
+               goto found;
+           }
+       }
+    }
+    assert(0);
+ found:
     /* if int & long support routines NOT compiled as reentrant */
     if (! options.intlong_rent) {
        /* first one */
@@ -400,8 +393,8 @@ static void convertToFcall (eBBlock **ebbs, int count)
            /* if long / int mult or divide or mod */
            if (ic->op == '*' || ic->op == '/' || ic->op == '%' ) {
 
-               link *type = operandType(IC_LEFT(ic));
-               if (IS_INTEGRAL(type) && getSize(type) > 1)
+               sym_link *type = operandType(IC_LEFT(ic));
+               if (IS_INTEGRAL(type) && getSize(type) > port->muldiv.native_below)
                    convilong (ic,ebbs[i],type,ic->op);
            }
        }
@@ -621,38 +614,37 @@ static void printCyclomatic (eBBlock **ebbs, int count)
 }
 
 /*-----------------------------------------------------------------*/
-/* canOverlayLocals - returns true if the local variables can overlayed */
+/* discardDeadParamReceives - remove any RECEIVE opcodes which     */
+/* refer to dead variables.                                       */
 /*-----------------------------------------------------------------*/
-static bool canOverlayLocals (eBBlock **ebbs, int count)
+static void discardDeadParamReceives(eBBlock **ebbs, int count)
 {
-    int i;
-    /* if staticAuto is in effect or the current function
-       being compiled is reentrant or the overlay segment
-       is empty or no overlay option is in effect then */
-    if (options.noOverlay ||
-       options.stackAuto ||
-       (currFunc &&
-        (IS_RENT(currFunc->etype) ||
-         IS_ISR(currFunc->etype))) ||
-       elementsInSet(overlay->syms) == 0)
-       
-       return FALSE;
+    int        i;
+    iCode      *ic;
+    iCode      dummyIcode;
 
-    /* otherwise do thru the blocks and see if there
-       any function calls if found then return false */
-    for (i = 0; i < count ; i++ ) {
-       iCode *ic;
-
-       for (ic = ebbs[i]->sch; ic ; ic = ic->next)
-           if (ic && ( ic->op == CALL || ic->op == PCALL))
-               return FALSE;
+    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;
+               }
+            }
+        }
     }
-
-    /* no function calls found return TRUE */
-    return TRUE;
 }
 
-
 /*-----------------------------------------------------------------*/
 /* eBBlockFromiCode - creates extended basic blocks from iCode     */
 /*                    will return an array of eBBlock pointers     */
@@ -709,7 +701,7 @@ eBBlock **eBBlockFromiCode (iCode *ic)
     /* dumpraw if asked for */
     if (options.dump_raw)
        dumpEbbsToFileExt(".dumpcse",ebbs,count);
+    
     /* compute the data flow */
     computeDataFlow (ebbs,saveCount); 
 
@@ -774,19 +766,6 @@ eBBlock **eBBlockFromiCode (iCode *ic)
        operations to be as they are for optimzations */
     convertToFcall (ebbs,count);
 
-    /* check if the parameters and local variables
-       of this function can be put in the overlay segment
-       This check is essentially to see if the function
-       calls any other functions if yes then we cannot
-       overlay */
-    if (canOverlayLocals(ebbs,count))
-       /* if we can then put the parameters &
-          local variables in the overlay set */
-       overlay2Set();       
-    else
-       /* otherwise put them into data where
-          they belong */
-       overlay2data();
 
     /* compute the live ranges */
     computeLiveRanges (ebbs,count);
@@ -794,6 +773,11 @@ eBBlock **eBBlockFromiCode (iCode *ic)
     if (options.dump_range)
        dumpEbbsToFileExt(".dumprange",ebbs,count);
 
+    /* Now that we have the live ranges, discard parameter
+     * receives for unused parameters.
+     */
+    discardDeadParamReceives(ebbs,count);
+
     /* allocate registers & generate code */   
     port->assignRegisters(ebbs,count);      
     
@@ -804,4 +788,6 @@ eBBlock **eBBlockFromiCode (iCode *ic)
 
     return NULL;
 }
+
+
 /* (add-hook 'c-mode-hook (lambda () (setq c-basic-offset 4))) */