Ejemplo n.º 1
0
    def test_propagate_copies_false(self):
        arguments = [self.foo,
                   S('command', 'move', '$1', '$2'),
                   S('command', 'move', '$10', '$20'),
                   S('command', 'addu', '$1', '$5', 1),
                   S('command', 'addu', '$3', '$1', '$4'),
                   self.bar]
        block = B(arguments)

        find_basic_blocks([block])
        generate_flow_graph([block])
        reaching_definitions.create_in_out([block])
        copy_propagation.create_in_out([block])

        self.assertFalse(propagate_copies(block))
        self.assertEqual(block.statements, arguments)
Ejemplo n.º 2
0
    def test_propagate_copies_other_arg(self):
        block = B([self.foo,
                   S('command', 'move', '$1', '$2'),
                   self.foo,
                   S('command', 'addu', '$3', '$4', '$1'),
                   self.bar])

        find_basic_blocks([block])
        generate_flow_graph([block])
        reaching_definitions.create_in_out([block])
        copy_propagation.create_in_out([block])

        self.assertTrue(propagate_copies(block))
        self.assertEqual(block.statements, [self.foo,
                   S('command', 'move', '$1', '$2'),
                   self.foo,
                   S('command', 'addu', '$3', '$4', '$2'),
                   self.bar])
Ejemplo n.º 3
0
    def test_create_in_out(self):
        s11 = S('command', 'li', 'a', 3)
        s12 = S('command', 'li', 'b', 5)
        s13 = S('command', 'li', 'd', 4)
        s14 = S('command', 'li', 'x', 100)
        s15 = S('command', 'beq', 'a', 'b', 'L1')

        s21 = S('command', 'addu', 'c', 'a', 'b')
        s22 = S('command', 'li', 'd', 2)

        s31 = S('label', 'L1')
        s32 = S('command', 'li', 'c', 4)
        s33 = S('command', 'mult', 'b', 'd')
        s34 = S('command', 'mflo', 'temp')
        s35 = S('command', 'addu', 'return', 'temp', 'c')

        b1, b2, b3 = find_basic_blocks([s11, s12, s13, s14, s15, s21, s22, \
                                        s31, s32, s33, s34, s35])

        generate_flow_graph([b1, b2, b3])
        create_in_out([b1, b2, b3])

        self.assertEqual(b1.gen_set, set([s11.sid, s12.sid, s13.sid, s14.sid]))
        self.assertEqual(b1.kill_set, set([s22.sid]))
        self.assertEqual(b2.gen_set, set([s21.sid, s22.sid]))
        self.assertEqual(b2.kill_set, set([s13.sid, s32.sid]))
        self.assertEqual(b3.gen_set, set([s32.sid, s34.sid, s35.sid]))
        self.assertEqual(b3.kill_set, set([s21.sid]))

        self.assertEqual(b1.reach_in, set())
        self.assertEqual(b1.reach_out, set([s11.sid, s12.sid, s13.sid,
                                            s14.sid]))
        self.assertEqual(b2.reach_in, set([s11.sid, s12.sid, s13.sid,
                                            s14.sid]))
        self.assertEqual(b2.reach_out, set([s21.sid, s22.sid, s11.sid, \
                                            s12.sid, s14.sid]))
        self.assertEqual(b3.reach_in, set([s21.sid, s22.sid, s11.sid, \
                                            s12.sid, s13.sid, s14.sid]))
        self.assertEqual(b3.reach_out, set([s32.sid, s34.sid, s35.sid, \
                                            s22.sid, s11.sid, s12.sid, \
                                            s13.sid, s14.sid]))
Ejemplo n.º 4
0
    def test_create_in_out(self):
        s11 = S('command', 'li', 'a', 3)
        s12 = S('command', 'li', 'b', 5)
        s13 = S('command', 'li', 'd', 4)
        s14 = S('command', 'li', 'x', 100)
        s15 = S('command', 'beq', 'a', 'b', 'L1')

        s21 = S('command', 'addu', 'c', 'a', 'b')
        s22 = S('command', 'li', 'd', 2)

        s31 = S('label', 'L1')
        s32 = S('command', 'li', 'c', 4)
        s33 = S('command', 'mult', 'b', 'd')
        s34 = S('command', 'mflo', 'temp')
        s35 = S('command', 'addu', 'return', 'temp', 'c')

        b1, b2, b3 = find_basic_blocks([s11, s12, s13, s14, s15, s21, s22,
                                        s31, s32, s33, s34, s35])

        generate_flow_graph([b1, b2, b3])
        create_in_out([b1, b2, b3])

        self.assertEqual(b1.use_set, set())
        self.assertEqual(b1.def_set, set(['a', 'b', 'd', 'x']))

        self.assertEqual(b2.use_set, set(['a', 'b']))
        self.assertEqual(b2.def_set, set(['c', 'd']))

        self.assertEqual(b3.use_set, set(['b', 'd']))
        self.assertEqual(b3.def_set, set(['c', 'temp', 'return']))

        self.assertEqual(b1.live_in, set())
        self.assertEqual(b1.live_out, set(['a', 'b', 'd']))
        self.assertEqual(b2.live_in, set(['a', 'b']))
        self.assertEqual(b2.live_out, set(['b', 'd']))
        self.assertEqual(b3.live_in, set(['b', 'd']))
        self.assertEqual(b3.live_out, set())
Ejemplo n.º 5
0
 def test_find_basic_blocks(self):
     s = self.statements
     statements = map(lambda b: b.statements, find_basic_blocks(s))
     self.assertEqual(statements, [s[:2], s[2:4], s[4:]])