Просмотр исходного кода

Fixed algorithm for liveness analysis.

Taddeus Kroes 14 лет назад
Родитель
Сommit
6dd921a75b
1 измененных файлов с 9 добавлено и 6 удалено
  1. 9 6
      src/liveness.py

+ 9 - 6
src/liveness.py

@@ -72,22 +72,25 @@ def create_in_out(blocks):
     # Start by analyzing the exit points
     # Start by analyzing the exit points
     work_list = set()
     work_list = set()
 
 
-    for b in blocks:
-        if b.edges_from and not b.edges_to:
-            work_list.add(b)
+    if len(blocks) == 1:
+        work_list.add(blocks[0])
+    else:
+        for b in blocks:
+            if b.edges_from and not b.edges_to:
+                work_list.add(b)
 
 
     while len(work_list):
     while len(work_list):
         b = work_list.pop()
         b = work_list.pop()
 
 
-        # in[B] = use[B] | (out[B] - def[B])
-        new_in = b.use_set | (b.live_out - b.def_set)
-
         # out[B] = union of in[S] for S in succ(B)
         # out[B] = union of in[S] for S in succ(B)
         b.live_out = set()
         b.live_out = set()
 
 
         for s in succ(b):
         for s in succ(b):
             b.live_out |= s.live_in
             b.live_out |= s.live_in
 
 
+        # in[B] = use[B] | (out[B] - def[B])
+        new_in = b.use_set | (b.live_out - b.def_set)
+
         # Check if the out set has changed. If so, add all predecessors to the
         # Check if the out set has changed. If so, add all predecessors to the
         # work list
         # work list
         if new_in != b.live_in:
         if new_in != b.live_in: