Commit 82759127 authored by Richard Torenvliet's avatar Richard Torenvliet

tried to implement gen and kill set, commented implementation

parent 870d25ee
...@@ -25,38 +25,38 @@ class BasicBlock(Block): ...@@ -25,38 +25,38 @@ class BasicBlock(Block):
if block not in self.dominates: if block not in self.dominates:
self.dominates.append(block) self.dominates.append(block)
block.dominated_by.append(self) block.dominated_by.append(self)
def get_gen(self):
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):
# 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 # def get_gen(self):
return self.kill_set # for s in self.statements:
# if s.is_arith():
def get_in(self): # self.gen_set.add(s[0])
for backw in self.edges_from: # print 'added: ', s[0]
self.in_set = self.in_set | backw.get_out() #
print 'in_set', self.in_set # return self.gen_set
return self.in_set #
# def get_kill(self):
def get_out(self): ## if self.edges_from != []:
print 'gen_set', self.gen_set #
print 'get_in', self.get_in() # for backw in self.edges_from:
print 'get_kill', self.get_kill() # self.kill_set = self.gen_set & backw.kill_set
self.out_set = self.gen_set | (self.get_in() - self.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):
# for backw in self.edges_from:
# self.in_set = self.in_set | backw.out_set
# print 'in_set', self.in_set
# return self.in_set
# def get_out(self):
# 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)
......
...@@ -55,7 +55,7 @@ def eliminate_common_subexpressions(block): ...@@ -55,7 +55,7 @@ def eliminate_common_subexpressions(block):
block.reverse_statements() block.reverse_statements()
return found return found
def to_hex(value): def to_hex(value):
"""Create the hexadecimal string of an integer.""" """Create the hexadecimal string of an integer."""
......
...@@ -43,14 +43,21 @@ class TestDataflow(unittest.TestCase): ...@@ -43,14 +43,21 @@ class TestDataflow(unittest.TestCase):
# #
# blocks = [b1, b2] # blocks = [b1, b2]
# #
# # initialize out[B] = gen[B] for every block
# for block in blocks: # for block in blocks:
# block.out_set = block.get_gen() # block.out_set = block.get_gen()
# print 'block.out_set', block.out_set # print 'block.out_set', block.out_set
#
# generate_flow_graph(blocks) # generate_flow_graph(blocks)
# print b1.get_gen()
# print b2.get_gen() # change = True
# print b2.get_out() # while change:
# for i, block in enumerate(blocks):
# block.get_in()
# oldout = block.out_set
# newout = block.get_out()
# if (block.out_set == block.get_out()):
# change = False
def test_generate_flow_graph_simple(self): def test_generate_flow_graph_simple(self):
......
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