|
@@ -44,13 +44,68 @@ class TestOptimize(unittest.TestCase):
|
|
|
def test_optimize_global_movinst_false(self):
|
|
def test_optimize_global_movinst_false(self):
|
|
|
foo = S('command', 'foo')
|
|
foo = S('command', 'foo')
|
|
|
bar = S('command', 'bar')
|
|
bar = S('command', 'bar')
|
|
|
|
|
+ statements = [foo, \
|
|
|
|
|
+ S('command', 'move', '$regA', '$regB'), \
|
|
|
|
|
+ S('command', 'addu', '$regA', '$regC', 2), \
|
|
|
|
|
+ bar]
|
|
|
|
|
+
|
|
|
|
|
+ block = B(statements)
|
|
|
|
|
+ optimize_global(block)
|
|
|
|
|
+ self.assertEquals(block.statements, statements)
|
|
|
|
|
+
|
|
|
|
|
+ def test_optimize_global_instr_mov_jal_true(self):
|
|
|
|
|
+ foo = S('command', 'foo')
|
|
|
|
|
+ bar = S('command', 'bar')
|
|
|
|
|
|
|
|
block = B([foo,
|
|
block = B([foo,
|
|
|
- S('command', 'move', '$regA', '$regB'),
|
|
|
|
|
S('command', 'addu', '$regA', '$regC', 2),
|
|
S('command', 'addu', '$regA', '$regC', 2),
|
|
|
|
|
+ S('command', 'move', '$4', '$regA'),
|
|
|
|
|
+ S('command', 'jal', 'L1'),
|
|
|
bar])
|
|
bar])
|
|
|
optimize_global(block)
|
|
optimize_global(block)
|
|
|
|
|
+
|
|
|
self.assertEquals(block.statements, [foo,
|
|
self.assertEquals(block.statements, [foo,
|
|
|
- S('command', 'move', '$regA', '$regB'),
|
|
|
|
|
- S('command', 'addu', '$regA', '$regC', 2),
|
|
|
|
|
|
|
+ S('command', 'addu', '$4', '$regC', 2),
|
|
|
|
|
+ S('command', 'jal', 'L1'),
|
|
|
|
|
+ bar])
|
|
|
|
|
+
|
|
|
|
|
+ def test_optimize_global_instr_mov_jal_false(self):
|
|
|
|
|
+ foo = S('command', 'foo')
|
|
|
|
|
+ bar = S('command', 'bar')
|
|
|
|
|
+
|
|
|
|
|
+ arguments = [foo, \
|
|
|
|
|
+ S('command', 'addu', '$regA', '$regC', 2), \
|
|
|
|
|
+ S('command', 'move', '$3', '$regA'), \
|
|
|
|
|
+ S('command', 'jal', 'L1'), \
|
|
|
|
|
+ bar]
|
|
|
|
|
+ block = B(arguments)
|
|
|
|
|
+ optimize_global(block)
|
|
|
|
|
+
|
|
|
|
|
+ self.assertEquals(block.statements, arguments)
|
|
|
|
|
+
|
|
|
|
|
+ def test_optimize_global_sw_ld_true(self):
|
|
|
|
|
+ foo = S('command', 'foo')
|
|
|
|
|
+ bar = S('command', 'bar')
|
|
|
|
|
+
|
|
|
|
|
+ block = B([foo,
|
|
|
|
|
+ S('command', 'sw', '$regA', '$regB'),
|
|
|
|
|
+ S('command', 'ld', '$regA', '$regC'),
|
|
|
|
|
+ bar])
|
|
|
|
|
+ optimize_global(block)
|
|
|
|
|
+
|
|
|
|
|
+ self.assertEquals(block.statements, [foo,
|
|
|
|
|
+ S('command', 'sw', '$regA', '$regB'),
|
|
|
bar])
|
|
bar])
|
|
|
|
|
+
|
|
|
|
|
+ def test_optimize_global_sw_ld_false(self):
|
|
|
|
|
+ foo = S('command', 'foo')
|
|
|
|
|
+ bar = S('command', 'bar')
|
|
|
|
|
+
|
|
|
|
|
+ arguments = [foo, \
|
|
|
|
|
+ S('command', 'sw', '$regA', '$regB'), \
|
|
|
|
|
+ S('command', 'ld', '$regD', '$regC'), \
|
|
|
|
|
+ bar]
|
|
|
|
|
+ block = B(arguments)
|
|
|
|
|
+ optimize_global(block)
|
|
|
|
|
+
|
|
|
|
|
+ self.assertEquals(block.statements, arguments)
|