Added some heuristic for register spilling
[fw/sdcc] / src / avr / 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;
+                                               }
                                        }
                                }