|
@@ -149,7 +149,7 @@ def fold_constants(block):
|
|
|
register[s[0]] = constants[s[1]]
|
|
register[s[0]] = constants[s[1]]
|
|
|
elif s.name in ['addu', 'subu', 'mult', 'div']:
|
|
elif s.name in ['addu', 'subu', 'mult', 'div']:
|
|
|
# Calculation with constants
|
|
# Calculation with constants
|
|
|
- rd, rs, rt = s
|
|
|
|
|
|
|
+ rd, rs, rt = s[0], s[1], s[2]
|
|
|
rs_known = rs in register
|
|
rs_known = rs in register
|
|
|
rt_known = rt in register
|
|
rt_known = rt in register
|
|
|
|
|
|
|
@@ -223,11 +223,13 @@ def copy_propagation(block):
|
|
|
if moves_to[i] == s[0]:
|
|
if moves_to[i] == s[0]:
|
|
|
moves_from[i] = s[1]
|
|
moves_from[i] = s[1]
|
|
|
break
|
|
break
|
|
|
- elif len(s) == 3 and s[0] in moves_to:
|
|
|
|
|
- # The result gets overwritten, so remove the data from the list.
|
|
|
|
|
|
|
+ elif (len(s) == 3 or s.is_command('mlfo') or s.is_load()) \
|
|
|
|
|
+ and (s[0] in moves_to or s[0] in moves_from):
|
|
|
|
|
+ # One of the registers gets overwritten, so remove the data from
|
|
|
|
|
+ # the list.
|
|
|
i = 0
|
|
i = 0
|
|
|
while i < len(moves_to):
|
|
while i < len(moves_to):
|
|
|
- if moves_to[i] == s[0]:
|
|
|
|
|
|
|
+ if moves_to[i] == s[0] or moves_to[i] == s[1]:
|
|
|
del moves_to[i]
|
|
del moves_to[i]
|
|
|
del moves_from[i]
|
|
del moves_from[i]
|
|
|
else:
|
|
else:
|
|
@@ -251,7 +253,7 @@ def copy_propagation(block):
|
|
|
|
|
|
|
|
def algebraic_transformations(block):
|
|
def algebraic_transformations(block):
|
|
|
"""
|
|
"""
|
|
|
- Change ineffective or useless algebraic transformations. Handled are:
|
|
|
|
|
|
|
+ Change ineffective or useless algebraic expressions. Handled are:
|
|
|
- x = y + 0 -> x = y
|
|
- x = y + 0 -> x = y
|
|
|
- x = y - 0 -> x = y
|
|
- x = y - 0 -> x = y
|
|
|
- x = y * 1 -> x = y
|
|
- x = y * 1 -> x = y
|
|
@@ -266,17 +268,22 @@ def algebraic_transformations(block):
|
|
|
if (s.is_command('addu') or s.is_command('subu')) and s[2] == 0:
|
|
if (s.is_command('addu') or s.is_command('subu')) and s[2] == 0:
|
|
|
block.replace(1, [S('command', 'move', s[0], s[1])])
|
|
block.replace(1, [S('command', 'move', s[0], s[1])])
|
|
|
changed = True
|
|
changed = True
|
|
|
- elif s.is_command('mult') and s[2] == 1:
|
|
|
|
|
- block.replace(1, [S('command', 'move', s[0], s[1])])
|
|
|
|
|
- changed = True
|
|
|
|
|
- elif s.is_command('mult') and s[2] == 0:
|
|
|
|
|
- block.replace(1, [S('command', 'li', '$1', to_hex(0))])
|
|
|
|
|
- changed = True
|
|
|
|
|
elif s.is_command('mult'):
|
|
elif s.is_command('mult'):
|
|
|
- shift_amount = log(s[2], 2)
|
|
|
|
|
- if shift_amount.is_integer():
|
|
|
|
|
- new_command = S('command', 'sll', s[0], s[1], shift_amount)
|
|
|
|
|
- block.replace(1, [new_command])
|
|
|
|
|
- changed = True
|
|
|
|
|
|
|
+ next = block.peek()
|
|
|
|
|
+ if next.is_command('mflo'):
|
|
|
|
|
+ if s[1] == 1:
|
|
|
|
|
+ block.replace(2, [S('command', 'move', next[0], s[0])])
|
|
|
|
|
+ changed = True
|
|
|
|
|
+ break
|
|
|
|
|
+ elif s[1] == 0:
|
|
|
|
|
+ block.replace(2, [S('command', 'li', '$1', to_hex(0))])
|
|
|
|
|
+ changed = True
|
|
|
|
|
+ break
|
|
|
|
|
+
|
|
|
|
|
+ shift_amount = log(s[1], 2)
|
|
|
|
|
+ if shift_amount.is_integer():
|
|
|
|
|
+ new_command = S('command', 'sll', next[0], s[0], int(shift_amount))
|
|
|
|
|
+ block.replace(2, [new_command])
|
|
|
|
|
+ changed = True
|
|
|
|
|
|
|
|
return changed
|
|
return changed
|