Mercurial > lcfOS
comparison python/registerallocator.py @ 173:c1d2b6b9f9a7
Rework into passes
author | Windel Bouwman |
---|---|
date | Fri, 19 Apr 2013 12:42:21 +0200 |
parents | |
children | a51b3c956386 |
comparison
equal
deleted
inserted
replaced
172:5a7d37d615ee | 173:c1d2b6b9f9a7 |
---|---|
1 | |
2 class RegisterAllocator: | |
3 def live_analyze(self): | |
4 # Determine liveness: | |
5 for i in self.Instructions: | |
6 i.live_in = set() | |
7 i.live_out = set() | |
8 for z in range(50): | |
9 # TODO iterate until converge | |
10 for i in self.Instructions: | |
11 lo_mk = i.live_out.difference(i.defs) | |
12 i.live_in = i.uses.union(lo_mk) | |
13 lo = set() | |
14 for s in i.succ: | |
15 lo = lo.union(s.live_in) | |
16 i.live_out = lo | |
17 def registerAllocate(self, ir, regs): | |
18 print(regs) | |
19 allVals = [] | |
20 # construct interference: | |
21 for i in ir.Instructions: | |
22 for v in i.live_in: | |
23 allVals.append(v) | |
24 for v2 in i.live_in: | |
25 if v != v2: | |
26 v.interferes.add(v2) | |
27 # assign random registers: | |
28 print(allVals) | |
29 regs = set(regs) | |
30 for v in allVals: | |
31 takenregs = set([iv.reg for iv in v.interferes]) | |
32 r2 = list(regs.difference(takenregs)) | |
33 # Pick next available: | |
34 v.reg = r2[0] | |
35 |