public void AllocateRegisters(InterferenceGraph graph) { SpilledRegisters.Clear(); RegistersColoring.Clear(); mapping = InterferenceGraph.copyGraph(graph); Initialize(graph); do { if (toSimplify.Count > 0) { Simplify(); } else if (toFreeze.Count > 0) { Freeze(); } else if (toSpill.Count > 0) { Spill(); } UpdateVertexPartition(graph); } while(toSimplify.Count > 0 || toSpill.Count > 0 || toFreeze.Count > 0); AssignColors(); }
private void Initialize(InterferenceGraph graph) { toSpill.Clear(); toSimplify.Clear(); toFreeze.Clear(); removed.Clear(); frozen.Clear(); stack.Clear(); foreach (Vertex vertex in graph.Vertices) { if (vertex.Register is HardwareRegisterNode) { RegistersColoring [vertex.Register] = vertex.Register as HardwareRegisterNode; continue; } if (vertex.NonCopyNeighbors.Count < registers.Count) { if (vertex.CopyNeighbors.Count > 0) { toFreeze.Add(vertex); } else { toSimplify.Add(vertex); } } else { toSpill.Add(vertex); } } }
private void UpdateVertexPartition(InterferenceGraph graph) { foreach (Vertex vertex in graph.Vertices) { if (removed.Contains(vertex)) { continue; } else if (mapping [vertex].NonCopyNeighbors.Count < registers.Count) { if (toSpill.Contains(vertex)) { toSpill.Remove(vertex); if (mapping [vertex].CopyNeighbors.Count > 0) { toFreeze.Add(vertex); } else { toSimplify.Add(vertex); } } } } foreach (Vertex vertex in graph.Vertices) { if (removed.Contains(vertex)) { continue; } else if (mapping [vertex].CopyNeighbors.Count == 0) { if (toFreeze.Contains(vertex)) { toFreeze.Remove(vertex); toSimplify.Add(vertex); } } } }
public static Dictionary <Vertex, Vertex> copyGraph(InterferenceGraph graph) { var mapping = new Dictionary <Vertex, Vertex> (); foreach (Vertex vertex in graph.Vertices) { mapping [vertex] = new Vertex(vertex.Register); } foreach (Vertex vertex in graph.Vertices) { foreach (Vertex neigh in vertex.CopyNeighbors) { mapping [vertex].CopyNeighbors.Add(mapping [neigh]); } foreach (Vertex neigh in vertex.NonCopyNeighbors) { mapping [vertex].NonCopyNeighbors.Add(mapping [neigh]); } } return(mapping); }