public RegisterAllocate(MipsFrame frame, List <BasicBlock> blocks, Temp.Temp[] precolored) { Frame = frame; Blocks = blocks; for (int i = 0; i < precolored.Length; ++i) { Precolored.Add(GetNodeByTemp(precolored[i])); GetNodeByTemp(precolored[i]).Color = i; GetNodeByTemp(precolored[i]).Degree = Infinity; } foreach (BasicBlock b in blocks) { foreach (TExp i in b.List) { LivenessNode n = new LivenessNode(i); foreach (Temp.Temp t in n.Def) { if (!TempToNode.ContainsKey(t)) { Initial.Add(GetNodeByTemp(t)); } } foreach (Temp.Temp t in n.Use) { if (!TempToNode.ContainsKey(t)) { Initial.Add(GetNodeByTemp(t)); } } } } }
public Node(TExp e, int i, int j, Dictionary<Temp.Temp, HashSet<PairInt>> defs) { LivenessNode node = new LivenessNode(e); foreach (Temp.Temp t in node.Def) { Kill.UnionWith(defs[t]); } Kill.Remove(new PairInt(i, j)); if (node.Def.Count != 0) { Gen.Add(new PairInt(i, j)); } }
public Node(TExp e, int i, int j, Dictionary <Temp.Temp, HashSet <PairInt> > defs) { LivenessNode node = new LivenessNode(e); foreach (Temp.Temp t in node.Def) { Kill.UnionWith(defs[t]); } Kill.Remove(new PairInt(i, j)); if (node.Def.Count != 0) { Gen.Add(new PairInt(i, j)); } }
public void ReachingDefinitions() { Queue <BasicBlock> queue = new Queue <BasicBlock>(Blocks); do { BasicBlock b = queue.Dequeue(); HashSet <PairInt> old = new HashSet <PairInt>(b.ReachOut); b.ReachIn = new HashSet <PairInt>(); foreach (BasicBlock p in b.Prev) { b.ReachIn.UnionWith(p.ReachOut); } b.ReachOut = new HashSet <PairInt>(b.ReachIn); b.ReachOut.ExceptWith(b.ReachKill); b.ReachOut.UnionWith(b.ReachGen); if (!b.ReachOut.SetEquals(old)) { foreach (BasicBlock s in b.Next) { queue.Enqueue(s); } } }while (queue.Count != 0); for (int i = 0; i < Blocks.Count; ++i) { BasicBlock b = Blocks[i]; HashSet <PairInt> reachin = new HashSet <PairInt>(b.ReachIn); for (int j = 0; j < b.List.Count; ++j) { TExp inst = b.List[j]; LivenessNode node = inst.LivenessNode; PairInt q = new PairInt(i, j); foreach (Temp.Temp t in node.Use) { foreach (PairInt p in reachin) { if (Blocks[p.i].List[p.j].LivenessNode.Def.Contains(t)) { SetOf(DefineUseChain, t, p).Add(q); SetOf(UseDefineChain, t, q).Add(p); } } } reachin.ExceptWith(inst.ReachingDefinitionNode.Kill); reachin.UnionWith(inst.ReachingDefinitionNode.Gen); } } }
public ReachingDefinition(List <BasicBlock> blocks) { Blocks = blocks; for (int i = 0; i < Blocks.Count; ++i) { BasicBlock b = Blocks[i]; for (int j = 0; j < b.List.Count; ++j) { TExp inst = b.List[j]; LivenessNode node = inst.LivenessNode = new LivenessNode(inst); foreach (Temp.Temp t in node.Def) { if (Defs[t] == null) { Defs.Add(t, new HashSet <PairInt>()); } Defs[t].Add(new PairInt(i, j)); } } } for (int i = 0; i < Blocks.Count; ++i) { BasicBlock b = Blocks[i]; b.ReachIn.Clear(); b.ReachOut.Clear(); b.ReachGen.Clear(); b.ReachKill.Clear(); for (int j = 0; j < b.List.Count; ++j) { TExp inst = b.List[j]; Node node = inst.ReachingDefinitionNode = new Node(inst, i, j, Defs); b.ReachGen.ExceptWith(node.Kill); b.ReachGen.UnionWith(node.Gen); b.ReachKill.UnionWith(node.Kill); } } }