Mercurial > lcfOS
diff python/interferencegraph.py @ 278:9fca39eebe50
First implementation of regalloc with coalsesc
author | Windel Bouwman |
---|---|
date | Sun, 29 Sep 2013 14:08:15 +0200 |
parents | 046017431c6a |
children | 2ccd57b1d78c |
line wrap: on
line diff
--- a/python/interferencegraph.py Thu Sep 26 21:14:25 2013 +0200 +++ b/python/interferencegraph.py Sun Sep 29 14:08:15 2013 +0200 @@ -4,10 +4,11 @@ class InterferenceGraphNode(graph.Node): def __init__(self, g, varname): super().__init__(g) - self.varname = varname + self.temps = [varname] + self.moves = set() def __repr__(self): - return '{}'.format(self.varname) + return 'IGN<{}>'.format(self.temps) class InterferenceGraph(graph.Graph): @@ -18,10 +19,7 @@ """ Create a new interference graph from a flowgraph """ - super().__init__(False) - # Mapping from node to live set - self.liveMap = {} - self.tempMap = {} + super().__init__() # Calculate liveness in CFG: ### # Liveness: @@ -55,15 +53,20 @@ self.addEdge(n1, n2) def getNode(self, tmp): - if tmp not in self.tempMap: - self.tempMap[tmp] = self.newNode(tmp) - return self.tempMap[tmp] - - def newNode(self, varname): - n = InterferenceGraphNode(self, varname) + # Linear search + # TODO: can be improved for speed! + for n in self.nodes: + if tmp in n.temps: + return n + n = InterferenceGraphNode(self, tmp) self.addNode(n) return n - def combine(self, n, m): - self.nodes.remove(m) - n.varnames.extend(m.varnames) + def Combine(self, n, m): + """ Combine n and m into n """ + n.temps.extend(m.temps) + n.moves.update(m.moves) + for t in m.Adjecent: + self.addEdge(n, t) + self.delNode(m) +