fixed an aggregate initialization bug
[fw/sdcc] / src / ds390 / ralloc.c
index 27b8c1e4b5940dc8a429a7911c91585e5a77797f..527ffeb81fe9271031efea44ec6dc4b906d862d8 100644 (file)
@@ -36,6 +36,8 @@
 /* since the pack the registers depending strictly on the MCU      */
 /*-----------------------------------------------------------------*/
 
+#define D(x)
+
 /* Global data */
 static struct
   {
@@ -66,16 +68,16 @@ regs regs390[] =
   {REG_GPR, R7_IDX, REG_GPR, "r7", "ar7", "0", 7, 1, 1},
   {REG_PTR, R0_IDX, REG_PTR, "r0", "ar0", "0", 0, 1, 1},
   {REG_PTR, R1_IDX, REG_PTR, "r1", "ar1", "0", 1, 1, 1},
+  {REG_GPR, DPL_IDX, REG_GPR, "dpl", "dpl", "dpl", 0, 0, 0},
+  {REG_GPR, DPH_IDX, REG_GPR, "dph", "dph", "dph", 0, 0, 0},
+  {REG_GPR, DPX_IDX, REG_GPR, "dpx", "dpx", "dpx", 0, 0, 0},
+  {REG_GPR, B_IDX, REG_GPR, "b", "b", "b", 0, 0, 0},
   {REG_GPR, X8_IDX, REG_GPR, "x8", "x8", "xreg", 0, 0, 0},
   {REG_GPR, X9_IDX, REG_GPR, "x9", "x9", "xreg", 1, 0, 0},
   {REG_GPR, X10_IDX, REG_GPR, "x10", "x10", "xreg", 2, 0, 0},
   {REG_GPR, X11_IDX, REG_GPR, "x11", "x11", "xreg", 3, 0, 0},
   {REG_GPR, X12_IDX, REG_GPR, "x12", "x12", "xreg", 4, 0, 0},
   {REG_CND, CND_IDX, REG_GPR, "C", "C", "xreg", 0, 0, 0},
-  {REG_GPR, DPL_IDX, REG_GPR, "dpl", "dpl", "dpl", 0, 0, 0},
-  {REG_GPR, DPH_IDX, REG_GPR, "dph", "dph", "dph", 0, 0, 0},
-  {REG_GPR, DPX_IDX, REG_GPR, "dpx", "dpx", "dpx", 0, 0, 0},
-  {REG_GPR, B_IDX, REG_GPR, "b", "b", "b", 0, 0, 0},
 };
 int ds390_nRegs = 13;
 static void spillThis (symbol *);
@@ -1300,14 +1302,16 @@ static void fillGaps()
     
     /* First try to do DPTRuse once more since now we know what got into
        registers */
-#if 1
+
     for (sym = hTabFirstItem(liveRanges,&key) ; sym ; 
         sym = hTabNextItem(liveRanges,&key)) {
 
        if (sym->uptr && !sym->ruonly && getSize(sym->type) < 4) {
            if (packRegsDPTRuse(operandFromSymbol(sym))) {
 
-               printf("FILL GAPS: found more DPTR use for %s in func %s\n",sym->name, currFunc ? currFunc->name : "UNKNOWN");
+                D (fprintf (stderr, "FILL GAPS: found more DPTR use for "
+                           "%s in func %s\n",
+                           sym->name, currFunc ? currFunc->name : "UNKNOWN"));
                /* if this was ssigned to registers then */
                if (bitVectBitValue(_G.totRegAssigned,sym->key)) {
 
@@ -1320,7 +1324,7 @@ static void fillGaps()
            }
        }
     }
-#endif    
+
     /* look for livernages that was spilt by the allocator */
     for (sym = hTabFirstItem(liveRanges,&key) ; sym ; 
         sym = hTabNextItem(liveRanges,&key)) {
@@ -1392,10 +1396,13 @@ static void fillGaps()
                sym->regs[i] = NULL;
            }
            freeAllRegs();
-           printf("Fill Gap gave up due to positioning for %s in function %s\n",sym->name, currFunc ? currFunc->name : "UNKNOWN");
+           D (fprintf (stderr, "Fill Gap gave up due to positioning for "
+                       "%s in function %s\n",
+                       sym->name, currFunc ? currFunc->name : "UNKNOWN"));
            continue ;      
        }
-       printf("FILLED GAP for %s in function %s\n",sym->name, currFunc ? currFunc->name : "UNKNOWN");
+       D (fprintf (stderr, "FILLED GAP for %s in function %s\n",
+                   sym->name, currFunc ? currFunc->name : "UNKNOWN"));
        _G.totRegAssigned = bitVectSetBit(_G.totRegAssigned,sym->key);
        sym->isspilt = sym->spillA = 0 ;
        sym->usl.spillLoc->allocreq--;
@@ -1406,8 +1413,8 @@ static void fillGaps()
 /*-----------------------------------------------------------------*/
 /* rUmaskForOp :- returns register mask for an operand             */
 /*-----------------------------------------------------------------*/
-static bitVect *
-rUmaskForOp (operand * op)
+bitVect *
+ds390_rUmaskForOp (operand * op)
 {
   bitVect *rumask;
   symbol *sym;
@@ -1447,7 +1454,7 @@ regsUsedIniCode (iCode * ic)
   if (ic->op == IFX)
     {
       rmask = bitVectUnion (rmask,
-                           rUmaskForOp (IC_COND (ic)));
+                           ds390_rUmaskForOp (IC_COND (ic)));
       goto ret;
     }
 
@@ -1455,7 +1462,7 @@ regsUsedIniCode (iCode * ic)
   if (ic->op == JUMPTABLE)
     {
       rmask = bitVectUnion (rmask,
-                           rUmaskForOp (IC_JTCOND (ic)));
+                           ds390_rUmaskForOp (IC_JTCOND (ic)));
 
       goto ret;
     }
@@ -1463,16 +1470,16 @@ regsUsedIniCode (iCode * ic)
   /* of all other cases */
   if (IC_LEFT (ic))
     rmask = bitVectUnion (rmask,
-                         rUmaskForOp (IC_LEFT (ic)));
+                         ds390_rUmaskForOp (IC_LEFT (ic)));
 
 
   if (IC_RIGHT (ic))
     rmask = bitVectUnion (rmask,
-                         rUmaskForOp (IC_RIGHT (ic)));
+                         ds390_rUmaskForOp (IC_RIGHT (ic)));
 
   if (IC_RESULT (ic))
     rmask = bitVectUnion (rmask,
-                         rUmaskForOp (IC_RESULT (ic)));
+                         ds390_rUmaskForOp (IC_RESULT (ic)));
 
 ret:
   return rmask;
@@ -2108,20 +2115,23 @@ packRegsDPTRuse (operand * op)
        /* if PCALL cannot be sure give up */
        if (ic->op == PCALL) return NULL;
 
-       /* if CALL then make sure it is VOID || return value not used */
+       /* if CALL then make sure it is VOID || return value not used 
+          or the return value is assigned to this one */
        if (ic->op == CALL) {
            if (OP_SYMBOL(IC_RESULT(ic))->liveTo == 
                OP_SYMBOL(IC_RESULT(ic))->liveFrom) continue ;
            etype = getSpec(type = operandType(IC_RESULT(ic)));
-           if (getSize(type) == 0) continue ;
+           //if (getSize(type) == 0 || isOperandEqual(op,IC_RESULT(ic))) 
+           if (getSize(type) == 0) 
+             continue ;
            return NULL ;
        }
 
        /* special case of add with a [remat] */
        if (ic->op == '+' && 
            OP_SYMBOL(IC_LEFT(ic))->remat &&
-           (!isOperandInFarSpace(IC_RIGHT(ic)) || 
-            isOperandInReg(IC_RIGHT(ic)))) continue ;
+           (isOperandInFarSpace(IC_RIGHT(ic)) &&
+            !isOperandInReg(IC_RIGHT(ic)))) return NULL ;
 
        /* special cases  */
        /* pointerGet */
@@ -2504,6 +2514,9 @@ packRegisters (eBBlock * ebp)
       if (POINTER_GET (ic))
        OP_SYMBOL (IC_LEFT (ic))->uptr = 1;
 
+      if (ic->op == RETURN && IS_SYMOP (IC_LEFT(ic)))
+         OP_SYMBOL (IC_LEFT (ic))->uptr = 1;
+
       if (!SKIP_IC2 (ic))
        {
          /* if we are using a symbol on the stack
@@ -2700,7 +2713,7 @@ ds390_assignRegisters (eBBlock ** ebbs, int count)
   setToNull ((void *) &_G.totRegAssigned);  
   setToNull ((void *) &_G.funcrUsed);  
   ds390_ptrRegReq = _G.stackExtend = _G.dataExtend = 0;
-  ds390_nRegs = 18;
+  ds390_nRegs = 12;
   if (options.model != MODEL_FLAT24) options.stack10bit = 0;
   /* change assignments this will remove some
      live ranges reducing some register pressure */
@@ -2720,7 +2733,7 @@ ds390_assignRegisters (eBBlock ** ebbs, int count)
   ds390_nRegs = 8;
   freeAllRegs ();
   fillGaps();
-  ds390_nRegs = 18;
+  ds390_nRegs = 12;
 
   /* if stack was extended then tell the user */
   if (_G.stackExtend)