コード例 #1
0
        private void AssignColors()
        {
            while (stack.Count > 0)
            {
                var vertex    = stack.Pop();
                var forbidden = new HashSet <HardwareRegisterNode> ();

                foreach (Vertex neigh in vertex.NonCopyNeighbors)
                {
                    if (RegistersColoring.ContainsKey(neigh.Register))
                    {
                        forbidden.Add(RegistersColoring [neigh.Register]);
                    }
                }

                var occurs = new Dictionary <HardwareRegisterNode, int> ();

                foreach (Vertex neigh in vertex.CopyNeighbors)
                {
                    if (RegistersColoring.ContainsKey(neigh.Register))
                    {
                        if (!occurs.ContainsKey(RegistersColoring [neigh.Register]))
                        {
                            occurs [RegistersColoring [neigh.Register]] = 1;
                        }
                        else
                        {
                            occurs [RegistersColoring [neigh.Register]]++;
                        }
                    }
                }

                if (forbidden.Count >= registers.Count)
                {
                    SpilledRegisters.Add(vertex.Register);
                }
                else
                {
                    int mostOccurs = 0;
                    HardwareRegisterNode choice = null;

                    foreach (HardwareRegisterNode reg in registers)
                    {
                        if (!forbidden.Contains(reg))
                        {
                            var tmp = occurs.ContainsKey(reg) ? occurs[reg] : 0;
                            if (tmp >= mostOccurs)
                            {
                                mostOccurs = tmp;
                                choice     = reg;
                            }
                        }
                    }
                    RegistersColoring [vertex.Register] = choice;
                }
            }
        }
コード例 #2
0
		public virtual void Visit (HardwareRegisterNode node)
		{
			Visit (node as RegisterNode);
		}
コード例 #3
0
 public override void Visit(HardwareRegisterNode node)
 {
     Visit(node as RegisterNode);
 }