Mercurial > lcfOS
annotate test/testregalloc.py @ 355:c2ddc8a36f5e
Enabled optimization
author | Windel Bouwman |
---|---|
date | Fri, 14 Mar 2014 10:30:13 +0100 |
parents | 3bb7dcfe5529 |
children |
rev | line source |
---|---|
279 | 1 import unittest |
2 import os | |
3 import sys | |
346 | 4 from ppci.irmach import AbstractInstruction as makeIns, Frame |
301 | 5 from ppci.codegen.registerallocator import RegisterAllocator |
6 from ppci import ir | |
342 | 7 from ppci.target import Nop |
279 | 8 |
9 | |
10 class RegAllocTestCase(unittest.TestCase): | |
11 def setUp(self): | |
296 | 12 self.ra = RegisterAllocator() |
279 | 13 |
14 def testRegAlloc(self): | |
280
02385f62f250
Rework from str interface to Instruction interface
Windel Bouwman
parents:
279
diff
changeset
|
15 f = Frame('tst') |
279 | 16 f.regs = [1,2,3,4,5,6] # for test use numbers! |
17 f.tempMap = {} | |
18 t1 = ir.Temp('t1') | |
19 t2 = ir.Temp('t2') | |
20 t3 = ir.Temp('t3') | |
21 t4 = ir.Temp('t4') | |
22 t5 = ir.Temp('t5') | |
280
02385f62f250
Rework from str interface to Instruction interface
Windel Bouwman
parents:
279
diff
changeset
|
23 f.instructions.append(makeIns(Nop, dst=[t1])) |
02385f62f250
Rework from str interface to Instruction interface
Windel Bouwman
parents:
279
diff
changeset
|
24 f.instructions.append(makeIns(Nop, dst=[t2])) |
02385f62f250
Rework from str interface to Instruction interface
Windel Bouwman
parents:
279
diff
changeset
|
25 f.instructions.append(makeIns(Nop, dst=[t3])) |
02385f62f250
Rework from str interface to Instruction interface
Windel Bouwman
parents:
279
diff
changeset
|
26 f.instructions.append(makeIns(Nop, dst=[t4], src=[t1, t2])) |
02385f62f250
Rework from str interface to Instruction interface
Windel Bouwman
parents:
279
diff
changeset
|
27 f.instructions.append(makeIns(Nop, dst=[t5], src=[t4, t3])) |
02385f62f250
Rework from str interface to Instruction interface
Windel Bouwman
parents:
279
diff
changeset
|
28 f.instructions.append(makeIns(Nop, src=[t5])) |
279 | 29 self.ra.allocFrame(f) |
30 self.conflict(t1, t2) | |
31 self.conflict(t2, t3) | |
32 | |
33 def conflict(self, ta, tb): | |
34 self.assertNotEqual(self.ra.Node(ta).color, self.ra.Node(tb).color) | |
35 | |
36 def testRegCoalesc(self): | |
280
02385f62f250
Rework from str interface to Instruction interface
Windel Bouwman
parents:
279
diff
changeset
|
37 f = Frame('tst') |
279 | 38 f.regs = [1,2,3,4,5,6] # for test use numbers! |
39 f.tempMap = {} | |
40 t1 = ir.Temp('t1') | |
41 t2 = ir.Temp('t2') | |
42 t3 = ir.Temp('t3') | |
43 t4 = ir.Temp('t4') | |
44 t5 = ir.Temp('t5') | |
45 t6 = ir.Temp('t6') | |
280
02385f62f250
Rework from str interface to Instruction interface
Windel Bouwman
parents:
279
diff
changeset
|
46 f.instructions.append(makeIns(Nop, dst=[t1])) |
02385f62f250
Rework from str interface to Instruction interface
Windel Bouwman
parents:
279
diff
changeset
|
47 f.instructions.append(makeIns(Nop, dst=[t2])) |
02385f62f250
Rework from str interface to Instruction interface
Windel Bouwman
parents:
279
diff
changeset
|
48 f.instructions.append(makeIns(Nop, dst=[t3])) |
02385f62f250
Rework from str interface to Instruction interface
Windel Bouwman
parents:
279
diff
changeset
|
49 f.instructions.append(makeIns(Nop, dst=[t4], src=[t2, t1])) |
02385f62f250
Rework from str interface to Instruction interface
Windel Bouwman
parents:
279
diff
changeset
|
50 f.instructions.append(makeIns(Nop, dst=[t5], src=[t3])) |
02385f62f250
Rework from str interface to Instruction interface
Windel Bouwman
parents:
279
diff
changeset
|
51 f.instructions.append(makeIns(Nop, dst=[t5], src=[t4, t5])) |
02385f62f250
Rework from str interface to Instruction interface
Windel Bouwman
parents:
279
diff
changeset
|
52 f.instructions.append(makeIns(Nop, dst=[t6], src=[t5])) |
02385f62f250
Rework from str interface to Instruction interface
Windel Bouwman
parents:
279
diff
changeset
|
53 f.instructions.append(makeIns(Nop, src=[t6])) |
279 | 54 self.ra.allocFrame(f) |
55 self.conflict(t1, t2) | |
56 self.conflict(t2, t3) | |
57 self.conflict(t1, t3) | |
58 | |
59 if __name__ == '__main__': | |
60 unittest.main() | |
61 |