annotate python/testregalloc.py @ 279:2ccd57b1d78c

Fix register allocator to do burn2 OK
author Windel Bouwman
date Sat, 12 Oct 2013 09:56:23 +0200
parents
children 02385f62f250
rev   line source
279
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
1 import unittest
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
2 import os
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
3 import sys
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
4 import irmach
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
5 import registerallocator
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
6 import ir
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
7
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
8
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
9 class RegAllocTestCase(unittest.TestCase):
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
10 def setUp(self):
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
11 self.ra = registerallocator.RegisterAllocator()
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
12
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
13 def testRegAlloc(self):
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
14 f = irmach.Frame('tst')
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
15 f.regs = [1,2,3,4,5,6] # for test use numbers!
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
16 f.tempMap = {}
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
17 t1 = ir.Temp('t1')
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
18 t2 = ir.Temp('t2')
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
19 t3 = ir.Temp('t3')
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
20 t4 = ir.Temp('t4')
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
21 t5 = ir.Temp('t5')
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
22 f.instructions.append(irmach.makeIns('ld %d0', dst=[t1]))
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
23 f.instructions.append(irmach.makeIns('ld %d0', dst=[t2]))
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
24 f.instructions.append(irmach.makeIns('ld %d0', dst=[t3]))
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
25 f.instructions.append(irmach.makeIns('add %d0, %s0, %s1', dst=[t4], src=[t1, t2]))
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
26 f.instructions.append(irmach.makeIns('add %d0, %s0, %s1', dst=[t5], src=[t4, t3]))
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
27 f.instructions.append(irmach.makeIns('st %s0', src=[t5]))
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
28 self.ra.allocFrame(f)
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
29 self.conflict(t1, t2)
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
30 self.conflict(t2, t3)
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
31
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
32 def conflict(self, ta, tb):
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
33 self.assertNotEqual(self.ra.Node(ta).color, self.ra.Node(tb).color)
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
34
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
35 def testRegCoalesc(self):
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
36 f = irmach.Frame('tst')
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
37 f.regs = [1,2,3,4,5,6] # for test use numbers!
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
38 f.tempMap = {}
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
39 t1 = ir.Temp('t1')
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
40 t2 = ir.Temp('t2')
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
41 t3 = ir.Temp('t3')
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
42 t4 = ir.Temp('t4')
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
43 t5 = ir.Temp('t5')
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
44 t6 = ir.Temp('t6')
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
45 f.instructions.append(irmach.makeIns('ld %d0', dst=[t1]))
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
46 f.instructions.append(irmach.makeIns('ld %d0', dst=[t2]))
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
47 f.instructions.append(irmach.makeIns('ld %d0', dst=[t3]))
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
48 f.instructions.append(irmach.makeIns('lsl %s0, %s1', dst=[t4], src=[t2, t1]))
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
49 f.instructions.append(irmach.makeIns('mov %d0, %s0', dst=[t5], src=[t3]))
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
50 f.instructions.append(irmach.makeIns('orr %s0, %s1', dst=[t5], src=[t4, t5]))
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
51 f.instructions.append(irmach.makeIns('mov %d0, %s0', dst=[t6], src=[t5]))
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
52 f.instructions.append(irmach.makeIns('st %s0', src=[t6]))
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
53 self.ra.allocFrame(f)
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
54 f.ig.to_txt()
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
55 for i in f.instructions:
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
56 print(i)
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
57 self.conflict(t1, t2)
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
58 self.conflict(t2, t3)
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
59 self.conflict(t1, t3)
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
60
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
61 if __name__ == '__main__':
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
62 unittest.main()
2ccd57b1d78c Fix register allocator to do burn2 OK
Windel Bouwman
parents:
diff changeset
63