Example #1
0
        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();
        }
Example #2
0
        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);
                }
            }
        }
Example #3
0
        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);
        }