comparison 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
comparison
equal deleted inserted replaced
278:9fca39eebe50 279:2ccd57b1d78c
1 import unittest
2 import os
3 import sys
4 import irmach
5 import registerallocator
6 import ir
7
8
9 class RegAllocTestCase(unittest.TestCase):
10 def setUp(self):
11 self.ra = registerallocator.RegisterAllocator()
12
13 def testRegAlloc(self):
14 f = irmach.Frame('tst')
15 f.regs = [1,2,3,4,5,6] # for test use numbers!
16 f.tempMap = {}
17 t1 = ir.Temp('t1')
18 t2 = ir.Temp('t2')
19 t3 = ir.Temp('t3')
20 t4 = ir.Temp('t4')
21 t5 = ir.Temp('t5')
22 f.instructions.append(irmach.makeIns('ld %d0', dst=[t1]))
23 f.instructions.append(irmach.makeIns('ld %d0', dst=[t2]))
24 f.instructions.append(irmach.makeIns('ld %d0', dst=[t3]))
25 f.instructions.append(irmach.makeIns('add %d0, %s0, %s1', dst=[t4], src=[t1, t2]))
26 f.instructions.append(irmach.makeIns('add %d0, %s0, %s1', dst=[t5], src=[t4, t3]))
27 f.instructions.append(irmach.makeIns('st %s0', src=[t5]))
28 self.ra.allocFrame(f)
29 self.conflict(t1, t2)
30 self.conflict(t2, t3)
31
32 def conflict(self, ta, tb):
33 self.assertNotEqual(self.ra.Node(ta).color, self.ra.Node(tb).color)
34
35 def testRegCoalesc(self):
36 f = irmach.Frame('tst')
37 f.regs = [1,2,3,4,5,6] # for test use numbers!
38 f.tempMap = {}
39 t1 = ir.Temp('t1')
40 t2 = ir.Temp('t2')
41 t3 = ir.Temp('t3')
42 t4 = ir.Temp('t4')
43 t5 = ir.Temp('t5')
44 t6 = ir.Temp('t6')
45 f.instructions.append(irmach.makeIns('ld %d0', dst=[t1]))
46 f.instructions.append(irmach.makeIns('ld %d0', dst=[t2]))
47 f.instructions.append(irmach.makeIns('ld %d0', dst=[t3]))
48 f.instructions.append(irmach.makeIns('lsl %s0, %s1', dst=[t4], src=[t2, t1]))
49 f.instructions.append(irmach.makeIns('mov %d0, %s0', dst=[t5], src=[t3]))
50 f.instructions.append(irmach.makeIns('orr %s0, %s1', dst=[t5], src=[t4, t5]))
51 f.instructions.append(irmach.makeIns('mov %d0, %s0', dst=[t6], src=[t5]))
52 f.instructions.append(irmach.makeIns('st %s0', src=[t6]))
53 self.ra.allocFrame(f)
54 f.ig.to_txt()
55 for i in f.instructions:
56 print(i)
57 self.conflict(t1, t2)
58 self.conflict(t2, t3)
59 self.conflict(t1, t3)
60
61 if __name__ == '__main__':
62 unittest.main()
63