Skip to content

Commit cfb3ae3

Browse files
committed
added dataflow
1 parent b70508d commit cfb3ae3

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

dataflow_analysis.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from collections import deque
2+
from graph import transpose
3+
from functools import reduce
4+
from utils import trace
5+
6+
def analyze_dataflow(G, transfer, bottom, join):
7+
trans_G = transpose(G)
8+
mapping = {}
9+
for v in G.vertices():
10+
mapping[v] = bottom
11+
worklist = deque()
12+
for v in G.vertices():
13+
worklist.append(v)
14+
while worklist:
15+
node = worklist.pop()
16+
input = reduce(join, [mapping[v] for v in trans_G.adjacent(node)], bottom)
17+
output = transfer(node, input)
18+
if output != mapping[node]:
19+
mapping[node] = output
20+
for v in G.adjacent(node):
21+
worklist.append(v)
22+

0 commit comments

Comments
 (0)