shithub: mc

Download patch

ref: a4f0e677a8cfbd95e0f47a0bb62b98a77c8946e6
parent: b0b32305ca510490c3edb78950655b26c9b22947
author: Ori Bernstein <[email protected]>
date: Tue Jun 10 17:58:03 EDT 2014

Check correct condition for worklists.

    The worklist invariant is not violated if we're already on
    wlsimp, so it's ok to not find it in wlfreeze.

--- a/6/ra.c
+++ b/6/ra.c
@@ -362,6 +362,12 @@
     l->list = wl;
 }
 
+static void wldel(Isel *s, Loc ***wl, size_t *nwl, size_t idx)
+{
+    (*wl)[idx]->list = NULL;
+    ldel(wl, nwl, idx);
+}
+
 static void wlputset(Bitset *bs, regid r)
 {
     bsput(bs, r);
@@ -547,8 +553,9 @@
             continue;
         else if (!istrivial(s, i))
             wlput(&s->wlspill, &s->nwlspill, locmap[i]);
-        else if (moverelated(s, i))
+        else if (moverelated(s, i)) {
             wlput(&s->wlfreeze, &s->nwlfreeze, locmap[i]);
+        }
         else
             wlput(&s->wlsimp, &s->nwlsimp, locmap[i]);
         locmap[i]->reg.colour = 0;
@@ -605,7 +612,7 @@
          */
         found = wlfind(s->wlspill, s->nwlspill, m, &idx);
         if (found)
-            ldel(&s->wlspill, &s->nwlspill, idx);
+            wldel(s, &s->wlspill, &s->nwlspill, idx);
         if (moverelated(s, m)) {
             if (!found)
                 assert(wlfind(s->wlfreeze, s->nwlfreeze, m, &idx));
@@ -656,8 +663,9 @@
     if (!istrivial(s, u))
         return;
 
-    assert(wlfind(s->wlfreeze, s->nwlfreeze, u, &i));
-    ldel(&s->wlfreeze, &s->nwlfreeze, i);
+    assert(locmap[u]->list == &s->wlfreeze || locmap[u]->list == &s->wlsimp);
+    if (wlfind(s->wlfreeze, s->nwlfreeze, u, &i))
+        wldel(s, &s->wlfreeze, &s->nwlfreeze, i);
     wlput(&s->wlsimp, &s->nwlsimp, locmap[u]);
 }
 
@@ -720,9 +728,9 @@
     if (debugopt['r'] > 2)
         printedge(stdout, "combining:", u, v);
     if (wlfind(s->wlfreeze, s->nwlfreeze, v, &idx))
-        ldel(&s->wlfreeze, &s->nwlfreeze, idx);
+        wldel(s, &s->wlfreeze, &s->nwlfreeze, idx);
     else if (wlfind(s->wlspill, s->nwlspill, v, &idx)) {
-        ldel(&s->wlspill, &s->nwlspill, idx);
+        wldel(s, &s->wlspill, &s->nwlspill, idx);
     }
     wlputset(s->coalesced, v);
     s->aliasmap[v] = locmap[u];
@@ -750,7 +758,7 @@
         decdegree(s, t);
     }
     if (!istrivial(s, u) && wlfind(s->wlfreeze, s->nwlfreeze, u, &idx)) {
-        ldel(&s->wlfreeze, &s->nwlfreeze, idx);
+        wldel(s, &s->wlfreeze, &s->nwlfreeze, idx);
         wlput(&s->wlspill, &s->nwlspill, locmap[u]);
     }
 }
@@ -822,7 +830,7 @@
         if (!nodemoves(s, v->reg.id, NULL) && istrivial(s, v->reg.id)) {
             if (!wlfind(s->wlfreeze, s->nwlfreeze, v->reg.id, &idx))
                 die("Reg %zd not in freeze wl\n", v->reg.id);
-            ldel(&s->wlfreeze, &s->nwlfreeze, idx);
+            wldel(s, &s->wlfreeze, &s->nwlfreeze, idx);
             wlput(&s->wlsimp, &s->nwlsimp, v);
         }
 
@@ -851,7 +859,7 @@
         if (!bshas(s->shouldspill, s->wlspill[i]->reg.id))
             continue;
         m = s->wlspill[i];
-        ldel(&s->wlspill, &s->nwlspill, i);
+        wldel(s, &s->wlspill, &s->nwlspill, i);
         break;
     }
     if (!m) {
@@ -861,7 +869,7 @@
                 continue;
             }
             m = s->wlspill[i];
-            ldel(&s->wlspill, &s->nwlspill, i);
+            wldel(s, &s->wlspill, &s->nwlspill, i);
             break;
         }
     }