瀏覽代碼

streamline worklist algorithm

Peter Thiemann 3 年之前
父節點
當前提交
0044f7edfd
共有 1 個文件被更改,包括 4 次插入9 次删除
  1. 4 9
      book.tex

+ 4 - 9
book.tex

@@ -10176,21 +10176,16 @@ function with the transpose of the control-flow graph.
 {\if\edition\pythonEd
 {\if\edition\pythonEd
 \begin{lstlisting}
 \begin{lstlisting}
 def analyze_dataflow(G, transfer, bottom, join):
 def analyze_dataflow(G, transfer, bottom, join):
-    trans_G = transpose(G)
-    mapping = {}
-    for v in G.vertices():
-        mapping[v] = bottom
-    worklist = deque()
-    for v in G.vertices():
-        worklist.append(v)
+    trans_G  = transpose(G)
+    mapping  = dict((v, bottom) for v in G.vertices())
+    worklist = deque(G.vertices)
     while worklist:
     while worklist:
         node = worklist.pop()
         node = worklist.pop()
         input = reduce(join, [mapping[v] for v in trans_G.adjacent(node)], bottom)
         input = reduce(join, [mapping[v] for v in trans_G.adjacent(node)], bottom)
         output = transfer(node, input)
         output = transfer(node, input)
         if output != mapping[node]:
         if output != mapping[node]:
             mapping[node] = output
             mapping[node] = output
-            for v in G.adjacent(node):
-                worklist.append(v)
+            worklist.extend(G.adjacent(node))
 \end{lstlisting}
 \end{lstlisting}
 \fi}
 \fi}
 \caption{Generic work list algorithm for dataflow analysis}
 \caption{Generic work list algorithm for dataflow analysis}