Mercurial > lcfOS
diff python/registerallocator.py @ 173:c1d2b6b9f9a7
Rework into passes
author | Windel Bouwman |
---|---|
date | Fri, 19 Apr 2013 12:42:21 +0200 |
parents | |
children | a51b3c956386 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/python/registerallocator.py Fri Apr 19 12:42:21 2013 +0200 @@ -0,0 +1,35 @@ + +class RegisterAllocator: + def live_analyze(self): + # Determine liveness: + for i in self.Instructions: + i.live_in = set() + i.live_out = set() + for z in range(50): + # TODO iterate until converge + for i in self.Instructions: + lo_mk = i.live_out.difference(i.defs) + i.live_in = i.uses.union(lo_mk) + lo = set() + for s in i.succ: + lo = lo.union(s.live_in) + i.live_out = lo + def registerAllocate(self, ir, regs): + print(regs) + allVals = [] + # construct interference: + for i in ir.Instructions: + for v in i.live_in: + allVals.append(v) + for v2 in i.live_in: + if v != v2: + v.interferes.add(v2) + # assign random registers: + print(allVals) + regs = set(regs) + for v in allVals: + takenregs = set([iv.reg for iv in v.interferes]) + r2 = list(regs.difference(takenregs)) + # Pick next available: + v.reg = r2[0] +