Added some heuristic for register spilling
authorsandeep <sandeep@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 29 Apr 2001 22:31:59 +0000 (22:31 +0000)
committersandeep <sandeep@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 29 Apr 2001 22:31:59 +0000 (22:31 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@763 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/avr/ralloc.c
src/ds390/ralloc.c
src/mcs51/ralloc.c
src/pic/ralloc.c
src/z80/ralloc.c

index f8dbb9a1b278e8c22297f71fc9d4ed20cbaa10de..f800cde64a11e40689c6815c68e057f7c929fb48 100644 (file)
@@ -1161,13 +1161,21 @@ serialRegAssign (eBBlock ** ebbs, int count)
 
                                /* if it has a spillocation & is used less than
                                   all other live ranges then spill this */
-                               if (willCS && sym->usl.spillLoc) {
-
-                                       symbol *leastUsed = leastUsedLR (liveRangesWith (spillable,
-                                                                                        allLRs, ebbs[i], ic));
-                                       if (leastUsed && leastUsed->used > sym->used) {
-                                               spillThis (sym);
-                                               continue;
+                               if (willCS) {
+                                       if (sym->usl.spillLoc) {
+                                               symbol *leastUsed = leastUsedLR (liveRangesWith (spillable,
+                                                                                                allLRs, ebbs[i], ic));
+                                               if (leastUsed && leastUsed->used > sym->used) {
+                                                       spillThis (sym);
+                                                       continue;
+                                               }
+                                       } else {
+                                               /* if none of the liveRanges have a spillLocation then better
+                                                  to spill this one than anything else already assigned to registers */
+                                               if (liveRangesWith(spillable,noSpilLoc,ebbs[i],ic)) {
+                                                       spillThis (sym);
+                                                       continue;
+                                               }
                                        }
                                }
 
index 0ba02dd0db8eceddb431249d8aec84e58f398615..55b2e22282412b9c398c52e94b8f1a4604e673a4 100644 (file)
@@ -1149,19 +1149,21 @@ serialRegAssign (eBBlock ** ebbs, int count)
 
              /* if it has a spillocation & is used less than
                 all other live ranges then spill this */
-             if (willCS && sym->usl.spillLoc)
-               {
-
-                 symbol *leastUsed =
-                 leastUsedLR (liveRangesWith (spillable,
-                                              allLRs,
-                                              ebbs[i],
-                                              ic));
-                 if (leastUsed &&
-                     leastUsed->used > sym->used)
-                   {
-                     spillThis (sym);
-                     continue;
+               if (willCS) {
+                   if (sym->usl.spillLoc) {
+                       symbol *leastUsed = leastUsedLR (liveRangesWith (spillable,
+                                                                        allLRs, ebbs[i], ic));
+                       if (leastUsed && leastUsed->used > sym->used) {
+                           spillThis (sym);
+                           continue;
+                       }
+                   } else {
+                       /* if none of the liveRanges have a spillLocation then better
+                          to spill this one than anything else already assigned to registers */
+                       if (liveRangesWith(spillable,noSpilLoc,ebbs[i],ic)) {
+                           spillThis (sym);
+                           continue;
+                       }
                    }
                }
 
index 9d42ffeae9cf0befafa9a052dd09473cbe9fdf8c..e5ab738986d8fef553f37bbc66271784027076df 100644 (file)
@@ -455,8 +455,7 @@ spillLRWithPtrReg (symbol * forSym)
     {
       int j;
 
-      /* if no registers assigned to it or
-         spilt */
+      /* if no registers assigned to it or spilt */
       /* if it does not overlap with this then 
          not need to spill it */
 
@@ -1074,146 +1073,138 @@ xchgPositions:
 static void
 serialRegAssign (eBBlock ** ebbs, int count)
 {
-  int i;
+    int i;
 
-  /* for all blocks */
-  for (i = 0; i < count; i++)
-    {
+    /* for all blocks */
+    for (i = 0; i < count; i++) {
 
-      iCode *ic;
+       iCode *ic;
 
-      if (ebbs[i]->noPath &&
-         (ebbs[i]->entryLabel != entryLabel &&
-          ebbs[i]->entryLabel != returnLabel))
-       continue;
+       if (ebbs[i]->noPath &&
+           (ebbs[i]->entryLabel != entryLabel &&
+            ebbs[i]->entryLabel != returnLabel))
+           continue;
 
-      /* of all instructions do */
-      for (ic = ebbs[i]->sch; ic; ic = ic->next)
-       {
+       /* of all instructions do */
+       for (ic = ebbs[i]->sch; ic; ic = ic->next) {
 
-         /* if this is an ipop that means some live
-            range will have to be assigned again */
-         if (ic->op == IPOP)
-           reassignLR (IC_LEFT (ic));
-
-         /* if result is present && is a true symbol */
-         if (IC_RESULT (ic) && ic->op != IFX &&
-             IS_TRUE_SYMOP (IC_RESULT (ic)))
-           OP_SYMBOL (IC_RESULT (ic))->allocreq = 1;
-
-         /* take away registers from live
-            ranges that end at this instruction */
-         deassignLRs (ic, ebbs[i]);
-
-         /* some don't need registers */
-         if (SKIP_IC2 (ic) ||
-             ic->op == JUMPTABLE ||
-             ic->op == IFX ||
-             ic->op == IPUSH ||
-             ic->op == IPOP ||
-             (IC_RESULT (ic) && POINTER_SET (ic)))
-           continue;
+           /* if this is an ipop that means some live
+              range will have to be assigned again */
+           if (ic->op == IPOP)
+               reassignLR (IC_LEFT (ic));
 
-         /* now we need to allocate registers
-            only for the result */
-         if (IC_RESULT (ic))
-           {
-             symbol *sym = OP_SYMBOL (IC_RESULT (ic));
-             bitVect *spillable;
-             int willCS;
-             int j;
-             int ptrRegSet = 0;
-
-             /* if it does not need or is spilt 
-                or is already assigned to registers
-                or will not live beyond this instructions */
-             if (!sym->nRegs ||
-                 sym->isspilt ||
-                 bitVectBitValue (_G.regAssigned, sym->key) ||
-                 sym->liveTo <= ic->seq)
-               continue;
+           /* if result is present && is a true symbol */
+           if (IC_RESULT (ic) && ic->op != IFX &&
+               IS_TRUE_SYMOP (IC_RESULT (ic)))
+               OP_SYMBOL (IC_RESULT (ic))->allocreq = 1;
 
-             /* if some liverange has been spilt at the block level
-                and this one live beyond this block then spil this
-                to be safe */
-             if (_G.blockSpil && sym->liveTo > ebbs[i]->lSeq)
-               {
-                 spillThis (sym);
-                 continue;
-               }
-             /* if trying to allocate this will cause
-                a spill and there is nothing to spill 
-                or this one is rematerializable then
-                spill this one */
-             willCS = willCauseSpill (sym->nRegs, sym->regType);
-             spillable = computeSpillable (ic);
-             if (sym->remat ||
-                 (willCS && bitVectIsZero (spillable)))
-               {
+           /* take away registers from live
+              ranges that end at this instruction */
+           deassignLRs (ic, ebbs[i]);
 
-                 spillThis (sym);
-                 continue;
+           /* some don't need registers */
+           if (SKIP_IC2 (ic) ||
+               ic->op == JUMPTABLE ||
+               ic->op == IFX ||
+               ic->op == IPUSH ||
+               ic->op == IPOP ||
+               (IC_RESULT (ic) && POINTER_SET (ic)))
+               continue;
 
+           /* now we need to allocate registers
+              only for the result */
+           if (IC_RESULT (ic)) {
+               symbol *sym = OP_SYMBOL (IC_RESULT (ic));
+               bitVect *spillable;
+               int willCS;
+               int j;
+               int ptrRegSet = 0;
+
+               /* if it does not need or is spilt 
+                  or is already assigned to registers
+                  or will not live beyond this instructions */
+               if (!sym->nRegs ||
+                   sym->isspilt ||
+                   bitVectBitValue (_G.regAssigned, sym->key) ||
+                   sym->liveTo <= ic->seq)
+                   continue;
+
+               /* if some liverange has been spilt at the block level
+                  and this one live beyond this block then spil this
+                  to be safe */
+               if (_G.blockSpil && sym->liveTo > ebbs[i]->lSeq) {
+                   spillThis (sym);
+                   continue;
+               }
+               /* if trying to allocate this will cause
+                  a spill and there is nothing to spill 
+                  or this one is rematerializable then
+                  spill this one */
+               willCS = willCauseSpill (sym->nRegs, sym->regType);
+               spillable = computeSpillable (ic);
+               if (sym->remat || (willCS && bitVectIsZero (spillable))) {                    
+                   spillThis (sym);
+                   continue;                 
                }
 
-             /* if it has a spillocation & is used less than
-                all other live ranges then spill this */
-             if (willCS && sym->usl.spillLoc)
-               {
-
-                 symbol *leastUsed =
-                 leastUsedLR (liveRangesWith (spillable,
-                                              allLRs,
-                                              ebbs[i],
-                                              ic));
-                 if (leastUsed &&
-                     leastUsed->used > sym->used)
-                   {
-                     spillThis (sym);
-                     continue;
+               /* if it has a spillocation & is used less than
+                  all other live ranges then spill this */
+               if (willCS) {
+                   if (sym->usl.spillLoc) {
+                       symbol *leastUsed = leastUsedLR (liveRangesWith (spillable,
+                                                                        allLRs, ebbs[i], ic));
+                       if (leastUsed && leastUsed->used > sym->used) {
+                           spillThis (sym);
+                           continue;
+                       }
+                   } else {
+                       /* if none of the liveRanges have a spillLocation then better
+                          to spill this one than anything else already assigned to registers */
+                       if (liveRangesWith(spillable,noSpilLoc,ebbs[i],ic)) {
+                           spillThis (sym);
+                           continue;
+                       }
                    }
                }
-
-             /* if we need ptr regs for the right side
-                then mark it */
-             if (POINTER_GET (ic) && IS_SYMOP (IC_LEFT (ic))
-                 && getSize (OP_SYMBOL (IC_LEFT (ic))->type)
-                 <= (unsigned int) PTRSIZE)
-               {
-                 mcs51_ptrRegReq++;
-                 ptrRegSet = 1;
+               /* if we need ptr regs for the right side
+                  then mark it */
+               if (POINTER_GET (ic) && IS_SYMOP (IC_LEFT (ic))
+                   && getSize (OP_SYMBOL (IC_LEFT (ic))->type) <= (unsigned int) PTRSIZE) {
+                   mcs51_ptrRegReq++;
+                   ptrRegSet = 1;
+               }
+               /* else we assign registers to it */
+               _G.regAssigned = bitVectSetBit (_G.regAssigned, sym->key);
+
+               for (j = 0; j < sym->nRegs; j++) {
+                   if (sym->regType == REG_PTR)
+                       sym->regs[j] = getRegPtr (ic, ebbs[i], sym);
+                   else
+                       sym->regs[j] = getRegGpr (ic, ebbs[i], sym);
+
+                   /* if the allocation falied which means
+                      this was spilt then break */
+                   if (!sym->regs[j])
+                       break;
                }
-             /* else we assign registers to it */
-             _G.regAssigned = bitVectSetBit (_G.regAssigned, sym->key);
-
-             for (j = 0; j < sym->nRegs; j++)
-               {
-                 if (sym->regType == REG_PTR)
-                   sym->regs[j] = getRegPtr (ic, ebbs[i], sym);
-                 else
-                   sym->regs[j] = getRegGpr (ic, ebbs[i], sym);
 
-                 /* if the allocation falied which means
-                    this was spilt then break */
-                 if (!sym->regs[j])
-                   break;
+               /* if it shares registers with operands make sure
+                  that they are in the same position */
+               if (IC_LEFT (ic) && IS_SYMOP (IC_LEFT (ic)) &&
+                   OP_SYMBOL (IC_LEFT (ic))->nRegs && ic->op != '=') {
+                   positionRegs (OP_SYMBOL (IC_RESULT (ic)),
+                                 OP_SYMBOL (IC_LEFT (ic)), ic->lineno);
                }
-             /* if it shares registers with operands make sure
-                that they are in the same position */
-             if (IC_LEFT (ic) && IS_SYMOP (IC_LEFT (ic)) &&
-                 OP_SYMBOL (IC_LEFT (ic))->nRegs && ic->op != '=')
-               positionRegs (OP_SYMBOL (IC_RESULT (ic)),
-                             OP_SYMBOL (IC_LEFT (ic)), ic->lineno);
-             /* do the same for the right operand */
-             if (IC_RIGHT (ic) && IS_SYMOP (IC_RIGHT (ic)) &&
-                 OP_SYMBOL (IC_RIGHT (ic))->nRegs)
-               positionRegs (OP_SYMBOL (IC_RESULT (ic)),
-                             OP_SYMBOL (IC_RIGHT (ic)), ic->lineno);
-
-             if (ptrRegSet)
-               {
-                 mcs51_ptrRegReq--;
-                 ptrRegSet = 0;
+               /* do the same for the right operand */
+               if (IC_RIGHT (ic) && IS_SYMOP (IC_RIGHT (ic)) &&
+                   OP_SYMBOL (IC_RIGHT (ic))->nRegs) {
+                   positionRegs (OP_SYMBOL (IC_RESULT (ic)),
+                                 OP_SYMBOL (IC_RIGHT (ic)), ic->lineno);
+               }
+
+               if (ptrRegSet) {
+                   mcs51_ptrRegReq--;
+                   ptrRegSet = 0;
                }
 
            }
index 47f44544a40ba9a9e07ec2192384fb6af06f33c8..af761485bf0f19e7a3eb070e818d1a4b521041da 100644 (file)
@@ -1554,19 +1554,21 @@ serialRegAssign (eBBlock ** ebbs, int count)
 
              /* if it has a spillocation & is used less than
                 all other live ranges then spill this */
-             if (willCS && sym->usl.spillLoc)
-               {
-
-                 symbol *leastUsed =
-                 leastUsedLR (liveRangesWith (spillable,
-                                              allLRs,
-                                              ebbs[i],
-                                              ic));
-                 if (leastUsed &&
-                     leastUsed->used > sym->used)
-                   {
-                     spillThis (sym);
-                     continue;
+               if (willCS) {
+                   if (sym->usl.spillLoc) {
+                       symbol *leastUsed = leastUsedLR (liveRangesWith (spillable,
+                                                                        allLRs, ebbs[i], ic));
+                       if (leastUsed && leastUsed->used > sym->used) {
+                           spillThis (sym);
+                           continue;
+                       }
+                   } else {
+                       /* if none of the liveRanges have a spillLocation then better
+                          to spill this one than anything else already assigned to registers */
+                       if (liveRangesWith(spillable,noSpilLoc,ebbs[i],ic)) {
+                           spillThis (sym);
+                           continue;
+                       }
                    }
                }
 
index 6dfca4cdf759663e5a65378a88e3b1c307c3a41c..a46ae56f197c034a89bbe03e6860fde654b3961d 100644 (file)
@@ -1094,21 +1094,23 @@ serialRegAssign (eBBlock ** ebbs, int count)
 
              /* if it has a spillocation & is used less than
                 all other live ranges then spill this */
-             if (willCS && sym->usl.spillLoc)
-               {
-
-                 symbol *leastUsed =
-                 leastUsedLR (liveRangesWith (spillable,
-                                              allLRs,
-                                              ebbs[i],
-                                              ic));
-                 if (leastUsed &&
-                     leastUsed->used > sym->used)
-                   {
-                     spillThis (sym);
-                     continue;
-                   }
-               }
+             if (willCS) {
+                     if (sym->usl.spillLoc) {
+                             symbol *leastUsed = leastUsedLR (liveRangesWith (spillable,
+                                                                              allLRs, ebbs[i], ic));
+                             if (leastUsed && leastUsed->used > sym->used) {
+                                     spillThis (sym);
+                                     continue;
+                             }
+                     } else {
+                             /* if none of the liveRanges have a spillLocation then better
+                                to spill this one than anything else already assigned to registers */
+                             if (liveRangesWith(spillable,noSpilLoc,ebbs[i],ic)) {
+                                     spillThis (sym);
+                                     continue;
+                             }
+                     }
+             }
 
              /* else we assign registers to it */
              regAssigned = bitVectSetBit (regAssigned, sym->key);