|
@@ -2,7 +2,7 @@ import unittest
|
|
|
from copy import copy
|
|
from copy import copy
|
|
|
|
|
|
|
|
from src.optimize.advanced import eliminate_common_subexpressions, \
|
|
from src.optimize.advanced import eliminate_common_subexpressions, \
|
|
|
- fold_constants, copy_propagation, algebraic_transformations
|
|
|
|
|
|
|
+ fold_constants, copy_propagation
|
|
|
from src.statement import Statement as S
|
|
from src.statement import Statement as S
|
|
|
from src.dataflow import BasicBlock as B, generate_flow_graph
|
|
from src.dataflow import BasicBlock as B, generate_flow_graph
|
|
|
import src.liveness as liveness
|
|
import src.liveness as liveness
|
|
@@ -104,93 +104,93 @@ class TestOptimizeAdvanced(unittest.TestCase):
|
|
|
self.assertFalse(copy_propagation(block))
|
|
self.assertFalse(copy_propagation(block))
|
|
|
self.assertEqual(block.statements, arguments)
|
|
self.assertEqual(block.statements, arguments)
|
|
|
|
|
|
|
|
- def test_algebraic_transforms_add0(self):
|
|
|
|
|
- block = B([self.foo,
|
|
|
|
|
- S('command', 'addu', '$1', '$2', 0),
|
|
|
|
|
- self.bar])
|
|
|
|
|
- self.assertTrue(algebraic_transformations(block))
|
|
|
|
|
- self.assertEqual(block.statements, [self.foo,
|
|
|
|
|
- S('command', 'move', '$1', '$2'),
|
|
|
|
|
- self.bar])
|
|
|
|
|
-
|
|
|
|
|
- def test_algebraic_transforms_add1(self):
|
|
|
|
|
- arguments = [self.foo,
|
|
|
|
|
- S('command', 'addu', '$1', '$2', 1),
|
|
|
|
|
- self.bar]
|
|
|
|
|
- block = B(arguments)
|
|
|
|
|
-
|
|
|
|
|
- self.assertFalse(algebraic_transformations(block))
|
|
|
|
|
- self.assertEqual(block.statements, arguments)
|
|
|
|
|
-
|
|
|
|
|
- def test_algebraic_transforms_sub0(self):
|
|
|
|
|
- block = B([self.foo,
|
|
|
|
|
- S('command', 'subu', '$1', '$2', 0),
|
|
|
|
|
- self.bar])
|
|
|
|
|
-
|
|
|
|
|
- self.assertTrue(algebraic_transformations(block))
|
|
|
|
|
- self.assertEqual(block.statements, [self.foo,
|
|
|
|
|
- S('command', 'move', '$1', '$2'),
|
|
|
|
|
- self.bar])
|
|
|
|
|
-
|
|
|
|
|
- def test_algebraic_transforms_sub1(self):
|
|
|
|
|
- arguments = [self.foo,
|
|
|
|
|
- S('command', 'subu', '$1', '$2', 1),
|
|
|
|
|
- self.bar]
|
|
|
|
|
- block = B(arguments)
|
|
|
|
|
-
|
|
|
|
|
- self.assertFalse(algebraic_transformations(block))
|
|
|
|
|
- self.assertEqual(block.statements, arguments)
|
|
|
|
|
-
|
|
|
|
|
- def test_algebraic_transforms_mult0(self):
|
|
|
|
|
- block = B([self.foo,
|
|
|
|
|
- S('command', 'mult', '$2', 0),
|
|
|
|
|
- S('command', 'mflo', '$1'),
|
|
|
|
|
- self.bar])
|
|
|
|
|
-
|
|
|
|
|
- self.assertTrue(algebraic_transformations(block))
|
|
|
|
|
- self.assertEqual(block.statements, [self.foo,
|
|
|
|
|
- S('command', 'li', '$1', '0x00000000'),
|
|
|
|
|
- self.bar])
|
|
|
|
|
-
|
|
|
|
|
- def test_algebraic_transforms_mult1(self):
|
|
|
|
|
- block = B([self.foo,
|
|
|
|
|
- S('command', 'mult', '$2', 1),
|
|
|
|
|
- S('command', 'mflo', '$1'),
|
|
|
|
|
- self.bar])
|
|
|
|
|
-
|
|
|
|
|
- self.assertTrue(algebraic_transformations(block))
|
|
|
|
|
- self.assertEqual(block.statements, [self.foo,
|
|
|
|
|
- S('command', 'move', '$1', '$2'),
|
|
|
|
|
- self.bar])
|
|
|
|
|
-
|
|
|
|
|
- def test_algebraic_transforms_mult2(self):
|
|
|
|
|
- block = B([self.foo,
|
|
|
|
|
- S('command', 'mult', '$2', 2),
|
|
|
|
|
- S('command', 'mflo', '$1'),
|
|
|
|
|
- self.bar])
|
|
|
|
|
-
|
|
|
|
|
- self.assertTrue(algebraic_transformations(block))
|
|
|
|
|
- self.assertEqual(block.statements, [self.foo,
|
|
|
|
|
- S('command', 'sll', '$1', '$2', 1),
|
|
|
|
|
- self.bar])
|
|
|
|
|
-
|
|
|
|
|
- def test_algebraic_transforms_mult16(self):
|
|
|
|
|
- block = B([self.foo,
|
|
|
|
|
- S('command', 'mult', '$2', 16),
|
|
|
|
|
- S('command', 'mflo', '$1'),
|
|
|
|
|
- self.bar])
|
|
|
|
|
-
|
|
|
|
|
- self.assertTrue(algebraic_transformations(block))
|
|
|
|
|
- self.assertEqual(block.statements, [self.foo,
|
|
|
|
|
- S('command', 'sll', '$1', '$2', 4),
|
|
|
|
|
- self.bar])
|
|
|
|
|
-
|
|
|
|
|
- def test_algebraic_transforms_mult3(self):
|
|
|
|
|
- arguments = [self.foo,
|
|
|
|
|
- S('command', 'mult', '$2', 3),
|
|
|
|
|
- S('command', 'mflo', '$1'),
|
|
|
|
|
- self.bar]
|
|
|
|
|
- block = B(arguments)
|
|
|
|
|
-
|
|
|
|
|
- self.assertFalse(algebraic_transformations(block))
|
|
|
|
|
- self.assertEqual(block.statements, arguments)
|
|
|
|
|
|
|
+ #def test_algebraic_transforms_add0(self):
|
|
|
|
|
+ # block = B([self.foo,
|
|
|
|
|
+ # S('command', 'addu', '$1', '$2', 0),
|
|
|
|
|
+ # self.bar])
|
|
|
|
|
+ # self.assertTrue(algebraic_transformations(block))
|
|
|
|
|
+ # self.assertEqual(block.statements, [self.foo,
|
|
|
|
|
+ # S('command', 'move', '$1', '$2'),
|
|
|
|
|
+ # self.bar])
|
|
|
|
|
+
|
|
|
|
|
+ #def test_algebraic_transforms_add1(self):
|
|
|
|
|
+ # arguments = [self.foo,
|
|
|
|
|
+ # S('command', 'addu', '$1', '$2', 1),
|
|
|
|
|
+ # self.bar]
|
|
|
|
|
+ # block = B(arguments)
|
|
|
|
|
+
|
|
|
|
|
+ # self.assertFalse(algebraic_transformations(block))
|
|
|
|
|
+ # self.assertEqual(block.statements, arguments)
|
|
|
|
|
+
|
|
|
|
|
+ #def test_algebraic_transforms_sub0(self):
|
|
|
|
|
+ # block = B([self.foo,
|
|
|
|
|
+ # S('command', 'subu', '$1', '$2', 0),
|
|
|
|
|
+ # self.bar])
|
|
|
|
|
+
|
|
|
|
|
+ # self.assertTrue(algebraic_transformations(block))
|
|
|
|
|
+ # self.assertEqual(block.statements, [self.foo,
|
|
|
|
|
+ # S('command', 'move', '$1', '$2'),
|
|
|
|
|
+ # self.bar])
|
|
|
|
|
+
|
|
|
|
|
+ #def test_algebraic_transforms_sub1(self):
|
|
|
|
|
+ # arguments = [self.foo,
|
|
|
|
|
+ # S('command', 'subu', '$1', '$2', 1),
|
|
|
|
|
+ # self.bar]
|
|
|
|
|
+ # block = B(arguments)
|
|
|
|
|
+
|
|
|
|
|
+ # self.assertFalse(algebraic_transformations(block))
|
|
|
|
|
+ # self.assertEqual(block.statements, arguments)
|
|
|
|
|
+
|
|
|
|
|
+ #def test_algebraic_transforms_mult0(self):
|
|
|
|
|
+ # block = B([self.foo,
|
|
|
|
|
+ # S('command', 'mult', '$2', 0),
|
|
|
|
|
+ # S('command', 'mflo', '$1'),
|
|
|
|
|
+ # self.bar])
|
|
|
|
|
+
|
|
|
|
|
+ # self.assertTrue(algebraic_transformations(block))
|
|
|
|
|
+ # self.assertEqual(block.statements, [self.foo,
|
|
|
|
|
+ # S('command', 'li', '$1', '0x00000000'),
|
|
|
|
|
+ # self.bar])
|
|
|
|
|
+
|
|
|
|
|
+ #def test_algebraic_transforms_mult1(self):
|
|
|
|
|
+ # block = B([self.foo,
|
|
|
|
|
+ # S('command', 'mult', '$2', 1),
|
|
|
|
|
+ # S('command', 'mflo', '$1'),
|
|
|
|
|
+ # self.bar])
|
|
|
|
|
+
|
|
|
|
|
+ # self.assertTrue(algebraic_transformations(block))
|
|
|
|
|
+ # self.assertEqual(block.statements, [self.foo,
|
|
|
|
|
+ # S('command', 'move', '$1', '$2'),
|
|
|
|
|
+ # self.bar])
|
|
|
|
|
+
|
|
|
|
|
+ #def test_algebraic_transforms_mult2(self):
|
|
|
|
|
+ # block = B([self.foo,
|
|
|
|
|
+ # S('command', 'mult', '$2', 2),
|
|
|
|
|
+ # S('command', 'mflo', '$1'),
|
|
|
|
|
+ # self.bar])
|
|
|
|
|
+
|
|
|
|
|
+ # self.assertTrue(algebraic_transformations(block))
|
|
|
|
|
+ # self.assertEqual(block.statements, [self.foo,
|
|
|
|
|
+ # S('command', 'sll', '$1', '$2', 1),
|
|
|
|
|
+ # self.bar])
|
|
|
|
|
+
|
|
|
|
|
+ #def test_algebraic_transforms_mult16(self):
|
|
|
|
|
+ # block = B([self.foo,
|
|
|
|
|
+ # S('command', 'mult', '$2', 16),
|
|
|
|
|
+ # S('command', 'mflo', '$1'),
|
|
|
|
|
+ # self.bar])
|
|
|
|
|
+
|
|
|
|
|
+ # self.assertTrue(algebraic_transformations(block))
|
|
|
|
|
+ # self.assertEqual(block.statements, [self.foo,
|
|
|
|
|
+ # S('command', 'sll', '$1', '$2', 4),
|
|
|
|
|
+ # self.bar])
|
|
|
|
|
+
|
|
|
|
|
+ #def test_algebraic_transforms_mult3(self):
|
|
|
|
|
+ # arguments = [self.foo,
|
|
|
|
|
+ # S('command', 'mult', '$2', 3),
|
|
|
|
|
+ # S('command', 'mflo', '$1'),
|
|
|
|
|
+ # self.bar]
|
|
|
|
|
+ # block = B(arguments)
|
|
|
|
|
+
|
|
|
|
|
+ # self.assertFalse(algebraic_transformations(block))
|
|
|
|
|
+ # self.assertEqual(block.statements, arguments)
|