Mercurial > lcfOS
diff python/registerallocator.py @ 279:2ccd57b1d78c
Fix register allocator to do burn2 OK
author | Windel Bouwman |
---|---|
date | Sat, 12 Oct 2013 09:56:23 +0200 |
parents | 9fca39eebe50 |
children | 02385f62f250 |
line wrap: on
line diff
--- a/python/registerallocator.py Sun Sep 29 14:08:15 2013 +0200 +++ b/python/registerallocator.py Sat Oct 12 09:56:23 2013 +0200 @@ -34,10 +34,18 @@ self.activeMoves = set() self.worklistMoves = set() + def printLive(self): + print('Liveness:') + for i in self.f.instructions: + cfgn = self.f.cfg._map[i] + print(i, cfgn.live_in) + def Build(self): """ 1. Construct interference graph from instruction list """ self.f.cfg = FlowGraph(self.f.instructions) self.f.ig = InterferenceGraph(self.f.cfg) + self.printLive() + self.Node = self.f.ig.getNode # Divide nodes into pre-colored and initial: @@ -56,6 +64,7 @@ dict(self.f.tempMap) # start with pre-colored self.moves = [i for i in self.f.instructions if i.ismove] + print(self.moves) for mv in self.moves: self.Node(mv.src[0]).moves.add(mv) self.Node(mv.dst[0]).moves.add(mv) @@ -159,6 +168,7 @@ okColors = self.regs - takenregs if okColors: self.color[n] = first(okColors) + n.color = self.color[n] else: raise NotImplementedError('Spill required here!') @@ -166,6 +176,7 @@ # Remove coalesced moves: for mv in self.coalescedMoves: self.f.instructions.remove(mv) + # Use allocated registers: lookup = lambda t: self.color[self.Node(t)] for i in self.f.instructions: @@ -173,7 +184,7 @@ i.dst = tuple(map(lookup, i.dst)) def allocFrame(self, f): - """ Do register allocation for a single stack frame. """ + """ Do iterated register allocation for a single stack frame. """ self.InitData(f) self.Build() self.makeWorkList()