Commit d3dfaa10 authored by Taddeus Kroes's avatar Taddeus Kroes

Added dummy block to prevent DCE in library fucntion calls.

parent 5c33f2be
...@@ -2,7 +2,7 @@ from statement import Block ...@@ -2,7 +2,7 @@ from statement import Block
class BasicBlock(Block): class BasicBlock(Block):
def __init__(self, statements=[]): def __init__(self, statements=[], dummy=False):
Block.__init__(self, statements) Block.__init__(self, statements)
self.edges_to = [] self.edges_to = []
self.edges_from = [] self.edges_from = []
...@@ -10,6 +10,8 @@ class BasicBlock(Block): ...@@ -10,6 +10,8 @@ class BasicBlock(Block):
self.dominates = [] self.dominates = []
self.dominated_by = [] self.dominated_by = []
self.dummy = dummy
def add_edge_to(self, block): def add_edge_to(self, block):
if block not in self.edges_to: if block not in self.edges_to:
self.edges_to.append(block) self.edges_to.append(block)
...@@ -58,13 +60,18 @@ def find_basic_blocks(statements): ...@@ -58,13 +60,18 @@ def find_basic_blocks(statements):
blocks.append(BasicBlock(statements[leaders[-1]:])) blocks.append(BasicBlock(statements[leaders[-1]:]))
# Add a target block for unknown jump targets
blocks.append(BasicBlock([], dummy=True))
return blocks return blocks
def generate_flow_graph(blocks): def generate_flow_graph(blocks):
"""Add flow graph edge administration of an ordered sequence of basic """Add flow graph edge administration of an ordered sequence of basic
blocks.""" blocks."""
for i, b in enumerate(blocks): dummy_block = blocks[-1]
for i, b in enumerate(blocks[:-1]):
last_statement = b[-1] last_statement = b[-1]
if last_statement.is_jump(): if last_statement.is_jump():
...@@ -72,9 +79,17 @@ def generate_flow_graph(blocks): ...@@ -72,9 +79,17 @@ def generate_flow_graph(blocks):
# Compare the target to all leading labels, add an edge if the # Compare the target to all leading labels, add an edge if the
# label matches the jump target # label matches the jump target
for other in blocks: target_found = False
for other in blocks[:-1]:
if other[0].is_label(target): if other[0].is_label(target):
b.add_edge_to(other) b.add_edge_to(other)
target_found = True
# If the jump target is outside the program, add an edge to the
# dummy block
if not target_found:
b.add_edge_to(dummy_block)
# A branch and jump-and-line instruction also creates an edge to # A branch and jump-and-line instruction also creates an edge to
# the next block # the next block
......
...@@ -28,6 +28,11 @@ def create_use_def(block): ...@@ -28,6 +28,11 @@ def create_use_def(block):
used = set() used = set()
defined = set() defined = set()
if block.dummy:
block.use_set = set(['$4', '$5', '$6', '$7'])
block.def_set = set(['$2', '$3'])
return
# Get the last of each definition series and put in in the `def' set # Get the last of each definition series and put in in the `def' set
block.use_set = set() block.use_set = set()
block.def_set = set() block.def_set = set()
......
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