Commit eea69c60 authored by Richard Torenvliet's avatar Richard Torenvliet

Made progress with liveness analyses in dataflow.py

parent 13966882
......@@ -11,6 +11,10 @@ class BasicBlock(Block):
self.dominates = []
self.dominated_by = []
self.in_set = set([])
self.out_set = set([])
self.gen_set = set([])
self.kill_set = set([])
def add_edge_to(self, block):
if block not in self.edges_to:
......@@ -23,16 +27,37 @@ class BasicBlock(Block):
block.dominated_by.append(self)
def get_gen(self):
pass
for s in self.statements:
if s.is_arith():
self.gen_set.add(s[0])
print 'added: ', s[0]
return self.gen_set
def get_kill(self):
pass
# if self.edges_from != []:
for backw in self.edges_from:
self.kill_set = self.kill_set | backw.get_kill()
self.kill_set = self.kill_set - self.get_gen()
print 'get_kill_set', self.kill_set
return self.kill_set
def get_in(self):
pass
for backw in self.edges_from:
self.in_set = self.in_set | backw.get_out()
print 'in_set', self.in_set
return self.in_set
def get_out(self):
pass
print 'gen_set', self.gen_set
print 'get_in', self.get_in()
print 'get_kill', self.get_kill()
self.out_set = self.gen_set | (self.get_in() - self.get_kill())
def reaching_definition(blocks):
generate_flow_graph(blocks)
def find_leaders(statements):
......
......@@ -101,6 +101,9 @@ def optimize_blocks(blocks):
blocks = optimized
return reduce(lambda a, b: a + b, blocks, [])
......
......@@ -24,6 +24,35 @@ class TestDataflow(unittest.TestCase):
[B(s[:2]).statements, B(s[2:4]).statements, \
B(s[4:]).statements])
# def test_get_gen(self):
# b1 = B([S('command', 'add', '$1', '$2', '$3'), \
# S('command', 'add', '$2', '$3', '$4'), \
# S('command', 'add', '$1', '$4', '$5')])
#
# self.assertEqual(b1.get_gen(), ['$1', '$2'])
# def test_get_out(self):
# b1 = B([S('command', 'add', '$1', '$2', '$3'), \
# S('command', 'add', '$2', '$3', '$4'), \
# S('command', 'add', '$1', '$4', '$5'), \
# S('command', 'j', 'b2')])
#
# b2 = B([S('command', 'add', '$3', '$5', '$6'), \
# S('command', 'add', '$1', '$2', '$3'), \
# S('command', 'add', '$6', '$4', '$5')])
#
# blocks = [b1, b2]
#
# for block in blocks:
# block.out_set = block.get_gen()
# print 'block.out_set', block.out_set
# generate_flow_graph(blocks)
# print b1.get_gen()
# print b2.get_gen()
# print b2.get_out()
def test_generate_flow_graph_simple(self):
b1 = B([S('command', 'foo'), S('command', 'j', 'b2')])
b2 = B([S('label', 'b2'), S('command', 'bar')])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment