Skip to content
Snippets Groups Projects
Commit 0af52ab8 authored by Taddeus Kroes's avatar Taddeus Kroes
Browse files

Reverted CSE fix.

parent 69316316
No related branches found
No related tags found
No related merge requests found
...@@ -33,88 +33,55 @@ def eliminate_common_subexpressions(block): ...@@ -33,88 +33,55 @@ def eliminate_common_subexpressions(block):
occurrences to a move instruction from that address. occurrences to a move instruction from that address.
""" """
changed = False changed = False
prev = False
block.reset() block.reset()
while not block.end(): while not block.end():
s = block.read() s = block.read()
args = s[1:]
mult = False
if s.is_command('mflo') and prev and prev.name == 'mult':
mult = prev
args = mult.args
elif not s.is_arith():
prev = s
continue
pointer = block.pointer
occurrences = [pointer - 1]
# Collect similar statements if s.is_arith():
while not block.end(): pointer = block.pointer
s2 = block.read() occurrences = [pointer - 1]
args = s[1:]
if not s2.is_command(): # Collect similar statements
continue while not block.end():
s2 = block.read()
# Stop if one of the arguments is assigned if not s2.is_command():
assign = False continue
for reg in s2.get_def(): # Stop if one of the arguments is assigned
if reg in args: if len(s2) and s2[0] in args:
assign = True
break break
if assign: # Replace a similar expression by a move instruction
break if s2.name == s.name and s2[1:] == args:
occurrences.append(block.pointer - 1)
# Replace a similar expression by a move instruction
if mult: if len(occurrences) > 1:
# Multiplication has two instructions: mult and mflo new_reg = find_free_reg(block, occurrences[0])
if s2.name == 'mult' and s2.args == args:
mflo = block.peek() # Replace each occurrence with a move statement
message = 'Common subexpression reference: %s %s' \
if mflo.is_command('mflo'): % (s.name, ','.join(map(str, [new_reg] + s[1:])))
occurrences.append(block.pointer - 1)
elif s2.name == s.name and s2[1:] == args: for occurrence in occurrences:
# Regular arithmetic command rd = block[occurrence][0]
occurrences.append(block.pointer - 1) block.replace(1, [S('command', 'move', rd, new_reg)], \
start=occurrence, message=message)
if len(occurrences) > 1:
new_reg = find_free_reg(block, occurrences[0]) # Insert the calculation before the original with the new
# destination address
# Replace each occurrence with a move statement
message = 'Common subexpression reference: %s %s' \
% (s.name, ','.join(map(str, [new_reg] + s[1:])))
for occurrence in occurrences:
rd = block[occurrence][0]
block.replace(1, [S('command', 'move', rd, new_reg)], \
start=occurrence, message=message)
# Insert the calculation before the original with the new
# destination address
if mult:
message = 'Common subexpression: mult ' \
+ ','.join(map(str, args))
block.insert(S('command', 'mult', *args), \
index=occurrences[0], message=message)
block.insert(S('command', 'mflo', new_reg), \
index=occurrences[0], message=' |')
else:
message = 'Common subexpression: %s %s' \ message = 'Common subexpression: %s %s' \
% (s.name, ','.join(map(str, s))) % (s.name, ','.join(map(str, s)))
block.insert(S('command', s.name, *([new_reg] + args)), \ block.insert(S('command', s.name, *([new_reg] + args)), \
index=occurrences[0], message=message) index=occurrences[0], message=message)
changed = True changed = True
prev = s
# Reset pointer to continue from the original statement # Reset pointer to continue from the original statement
block.pointer = pointer block.pointer = pointer
return changed return changed
...@@ -489,7 +456,6 @@ def propagate_copies(block): ...@@ -489,7 +456,6 @@ def propagate_copies(block):
# definition reaching it -> s in in[B_use] # definition reaching it -> s in in[B_use]
if s.sid in block.reach_out: if s.sid in block.reach_out:
for b in filter(lambda b: (x, y) in b.copy_in, succ(block)): for b in filter(lambda b: (x, y) in b.copy_in, succ(block)):
print b
for s2 in b: for s2 in b:
# Determine if for each of those uses this is the only # Determine if for each of those uses this is the only
# definition reaching it -> s in in[B_use] # definition reaching it -> s in in[B_use]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment