Esempio n. 1
0
 private void AssignColor()
 {
     while (SelectStack.Count != 0)
     {
         Node       n        = SelectStack.Pop();
         List <int> okColors = new List <int>();
         for (int i = 8; i <= 25; i++)
         {
             okColors.Add(i);
         }
         for (int i = 2; i <= 7; i++)
         {
             okColors.Add(i);
         }
         for (int i = 28; i <= 31; i++)
         {
             okColors.Add(i);
         }
         HashSet <Node> nodes = new HashSet <Node>(Precolored);
         nodes.UnionWith(ColoredNodes);
         foreach (Node w in n.AdjList)
         {
             if (nodes.Contains(GetAlias(w)))
             {
                 okColors.Remove(GetAlias(w).Color);
             }
         }
         if (okColors.Count == 0)
         {
             SpilledNodes.Add(n);
         }
         else
         {
             ColoredNodes.Add(n);
             int c = okColors[0];
             n.Color = c;
         }
     }
     foreach (Node n in CoalescedNodes)
     {
         n.Color = GetAlias(n).Color;
     }
 }
Esempio n. 2
0
            private void RewriteProgram(HashSet <Node> spilledNodes)
            {
                HashSet <Node> newTemps = new HashSet <Node>();

                foreach (Node v in spilledNodes)
                {
                    InFrame a = (InFrame)Frame.AllocLocal(true);
                    foreach (BasicBlock b in Blocks)
                    {
                        for (int i = 0; i < b.List.Count; i++)
                        {
                            TExp inst = b.List[i];
                            if (inst.LivenessNode == null)
                            {
                                continue;
                            }
                            if (inst.LivenessNode.Use.Contains(v.Temp))
                            {
                                Temp.Temp p = new Temp.Temp();
                                newTemps.Add(GetNodeByTemp(p));
                                GetNodeByTemp(p).IsNew = true;
                                b.List.Insert(i, new Load(Frame.FP(), a.Offset, p));
                                b.List[++i].ReplaceUse(v.Temp, p);
                            }
                            if (inst.LivenessNode.Def.Contains(v.Temp))
                            {
                                Temp.Temp p = new Temp.Temp();
                                newTemps.Add(GetNodeByTemp(p));
                                GetNodeByTemp(p).IsNew = true;
                                b.List.Insert(i + 1, new Store(Frame.FP(), a.Offset, p));
                                b.List[i++].ReplaceDef(v.Temp, p);
                            }
                        }
                    }
                }
                spilledNodes.Clear();
                Initial = newTemps;
                Initial.UnionWith(ColoredNodes);
                Initial.UnionWith(CoalescedNodes);
                ColoredNodes.Clear();
                CoalescedNodes.Clear();
            }