コード例 #1
0
            private void Combine(Node u, Node v)
            {
                if (FreezeWorklist.Contains(v))
                {
                    FreezeWorklist.Remove(v);
                }
                else
                {
                    SpillWorklist.Remove(v);
                }
                CoalescedNodes.Add(v);
                v.Alias = u;
                HashSet <Move> tmp = new HashSet <Move>(u.MoveList);

                tmp.UnionWith(v.MoveList);
                u.MoveList = new List <Move>(tmp);
                List <Node> vv = new List <Node>();

                vv.Add(v);
                EnableMoves(vv);
                foreach (Node t in Adjacent(v))
                {
                    AddEdge(t.Temp, u.Temp);
                    DecrementDegree(t);
                }
                if (u.Degree >= K && FreezeWorklist.Contains(u))
                {
                    FreezeWorklist.Remove(u);
                    SpillWorklist.Add(u);
                }
            }
コード例 #2
0
            private List <Node> Adjacent(Node node)
            {
                List <Node> res = new List <Node>(node.AdjList);

                res.RemoveAll(delegate(Node n) { return(SelectStack.Contains(n)); });
                res.RemoveAll(delegate(Node n) { return(CoalescedNodes.Contains(n)); });
                return(res);
            }
コード例 #3
0
 private Node GetAlias(Node n)
 {
     if (CoalescedNodes.Contains(n))
     {
         return(GetAlias(n.Alias));
     }
     else
     {
         return(n);
     }
 }
コード例 #4
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();
            }