Commit 2bc283ea authored by Taddeus Kroes's avatar Taddeus Kroes

Added reaching definitions to optimizer, and cleaned up some code.

parent bca9684d
from src.dataflow import find_basic_blocks
from src.dataflow import find_basic_blocks, reaching_definitions
from redundancies import remove_redundant_jumps, move_1, move_2, move_3, \
move_4, load, shift, add
......@@ -45,9 +45,16 @@ def optimize(statements, verbose=0):
remove_redundant_jumps(statements)
g = len(statements)
# Optimize basic blocks
# Divide into basic blocks
blocks = find_basic_blocks(statements)
# Find reaching definitions
reaching_definitions(blocks)
# Optimize basic blocks
map(optimize_block, blocks)
# Concatenate optimized blocks to obtain
block_statements = map(lambda b: b.statements, blocks)
opt_blocks = reduce(lambda a, b: a + b, block_statements)
b = len(opt_blocks)
......
......@@ -18,7 +18,7 @@ def reg_can_be_used_in(reg, block, start, end):
elif s.defines(reg):
return True
return True
return reg not in block.out_set
def find_free_reg(block, start, end):
......@@ -348,13 +348,9 @@ def eliminate_dead_code(block):
"""
# TODO: Finish
changed = False
block.reverse_statements()
unused = set()
while not block.end():
s = block.read()
for s in reversed(block):
for reg in s.get_def():
if reg in unused:
# Statement is redefined later, so this statement is useless
......@@ -367,6 +363,5 @@ def eliminate_dead_code(block):
unused -= set(s.get_use())
block.apply_filter(lambda s: not hasattr(s, 'remove'))
block.reverse_statements()
return changed
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