/// <summary> /// Gets the nodes that are dominated by this subgraph construct. /// </summary> /// <param name="construct"></param> /// <returns></returns> public HashSet <ISingleEntrySubGraph> GetDominatedNodes(ISingleEntrySubGraph construct) { DTNode node; if (!constructToNodeMap.TryGetValue(construct, out node)) { return(null); } //A node dominates all of the constructs that are in the subtree (of the dominator tree) rooted at this node. //So we get them via simplified bfs (no need to check if a node is traversed, since it's a tree). HashSet <ISingleEntrySubGraph> dominatedNodes = new HashSet <ISingleEntrySubGraph>(); Queue <DTNode> traversalQueue = new Queue <DTNode>(); traversalQueue.Enqueue(node); while (traversalQueue.Count > 0) { DTNode currnetNode = traversalQueue.Dequeue(); dominatedNodes.Add(currnetNode.Construct); foreach (DTNode successor in currnetNode.TreeEdgeSuccessors) { traversalQueue.Enqueue(successor); } } return(dominatedNodes); }
/// <summary> /// Computes the dominance frontier of each node. /// </summary> private void ComputeDominanceFrontiers() { //A dominance frontier of a specified node is the set of all nodes that are not dominated by the specified node, //but have a predecessor dominated by it. (If A dominates B which is a predecessor of C and A does not dominate C, then C is in the dominance //frontier of A.) //For each real predecessor of a specified node, we find the path from this predecessor to the immediate dominator of the specified node, and //we add the specified node to the dominance frontiers of all these nodes except to the dominance frontier of the immediate dominator. //e.g. If A is immediate dominator of B and D, B is immediate dominator of C and C is predecessor of D, then D is in the dominance frontier of C, //because C dominates C and D is not dominated by C (because it's not in its subtree in the dominance tree). D is also in the dominance frontier of B, //because B dominates C which is a predecessor of D. foreach (DTNode node in constructToNodeMap.Values) { HashSet <DTNode> realPredecessors = predecessorMap[node]; foreach (DTNode predecessor in realPredecessors) { DTNode currentDominator = predecessor; while (currentDominator != node.ImmediateDominator) { currentDominator.DominanceFrontier.Add(node); currentDominator = currentDominator.ImmediateDominator; } } } }
public void MergeNodes(HashSet <ISingleEntrySubGraph> constructs, ISingleEntrySubGraph originalEntry, ISingleEntrySubGraph newConstruct) { V_0 = this.constructToNodeMap.get_Item(originalEntry); stackVariable5 = new DTNode(newConstruct); stackVariable5.set_Predecessor(V_0.get_Predecessor()); V_1 = stackVariable5; V_1.get_DominanceFrontier().UnionWith(V_0.get_DominanceFrontier()); dummyVar0 = V_1.get_DominanceFrontier().Remove(V_0); if (V_1.get_Predecessor() != null) { dummyVar1 = V_1.get_Predecessor().get_TreeEdgeSuccessors().Remove(V_0); dummyVar2 = V_1.get_Predecessor().get_TreeEdgeSuccessors().Add(V_1); } V_2 = constructs.GetEnumerator(); try { while (V_2.MoveNext()) { V_3 = V_2.get_Current(); dummyVar3 = this.constructToNodeMap.Remove(V_3); } } finally { ((IDisposable)V_2).Dispose(); } V_4 = this.constructToNodeMap.GetEnumerator(); try { while (V_4.MoveNext()) { V_5 = V_4.get_Current(); if (V_5.get_Value().get_Predecessor() != null && constructs.Contains(V_5.get_Value().get_Predecessor().get_Construct())) { V_5.get_Value().set_Predecessor(V_1); dummyVar4 = V_1.get_TreeEdgeSuccessors().Add(V_5.get_Value()); } if (!V_5.get_Value().get_DominanceFrontier().Remove(V_0)) { continue; } dummyVar5 = V_5.get_Value().get_DominanceFrontier().Add(V_1); } } finally { ((IDisposable)V_4).Dispose(); } if (this.get_RootConstruct() == originalEntry) { this.set_RootConstruct(newConstruct); } this.constructToNodeMap.Add(newConstruct, V_1); return; }
protected override void FindImmediateDominators() { List <DFSTNode> reversePostOrderMap = DFSTBuilder.BuildTree(originalGraph).ReversePostOrder; List <DFSTNode>[] predecessorsCache = InitializePredecessors(reversePostOrderMap); int count = reversePostOrderMap.Count; InitializeDominators(count); bool changed; do { changed = false; for (int i = 1; i < count; i++) { List <DFSTNode> predecessors = predecessorsCache[i]; int newImmDom = GetPredecessor(predecessors, node => node.ReversePostOrderIndex != i && dominators[node.ReversePostOrderIndex] != -1); foreach (DFSTNode predecessor in predecessors) { int index = predecessor.ReversePostOrderIndex; if (index != i && dominators[index] != -1) { newImmDom = Intersect(index, newImmDom); } } if (dominators[i] != newImmDom) { dominators[i] = newImmDom; changed = true; } } }while (changed); for (int i = 1; i < count; i++) { DTNode node = constructToNodeMap[reversePostOrderMap[i].Construct]; DTNode immDom = constructToNodeMap[reversePostOrderMap[dominators[i]].Construct]; node.Predecessor = immDom; immDom.TreeEdgeSuccessors.Add(node); } }
public void MergeNodes(HashSet <ISingleEntrySubGraph> constructs, ISingleEntrySubGraph originalEntry, ISingleEntrySubGraph newConstruct) { DTNode oldNode = constructToNodeMap[originalEntry]; DTNode newNode = new DTNode(newConstruct) { Predecessor = oldNode.Predecessor }; newNode.DominanceFrontier.UnionWith(oldNode.DominanceFrontier); newNode.DominanceFrontier.Remove(oldNode); if (newNode.Predecessor != null) { newNode.Predecessor.TreeEdgeSuccessors.Remove(oldNode); newNode.Predecessor.TreeEdgeSuccessors.Add(newNode); } foreach (ISingleEntrySubGraph constructToRemove in constructs) { constructToNodeMap.Remove(constructToRemove); } foreach (KeyValuePair <ISingleEntrySubGraph, DTNode> pair in constructToNodeMap) { if (pair.Value.Predecessor != null && constructs.Contains(pair.Value.Predecessor.Construct)) { pair.Value.Predecessor = newNode; newNode.TreeEdgeSuccessors.Add(pair.Value); } if (pair.Value.DominanceFrontier.Remove(oldNode)) { pair.Value.DominanceFrontier.Add(newNode); } } if (RootConstruct == originalEntry) { RootConstruct = newConstruct; } constructToNodeMap.Add(newConstruct, newNode); }
public void MergeNodes(HashSet<ISingleEntrySubGraph> constructs, ISingleEntrySubGraph originalEntry, ISingleEntrySubGraph newConstruct) { DTNode oldNode = constructToNodeMap[originalEntry]; DTNode newNode = new DTNode(newConstruct) { Predecessor = oldNode.Predecessor }; newNode.DominanceFrontier.UnionWith(oldNode.DominanceFrontier); newNode.DominanceFrontier.Remove(oldNode); if (newNode.Predecessor != null) { newNode.Predecessor.TreeEdgeSuccessors.Remove(oldNode); newNode.Predecessor.TreeEdgeSuccessors.Add(newNode); } foreach (ISingleEntrySubGraph constructToRemove in constructs) { constructToNodeMap.Remove(constructToRemove); } foreach (KeyValuePair<ISingleEntrySubGraph, DTNode> pair in constructToNodeMap) { if (pair.Value.Predecessor != null && constructs.Contains(pair.Value.Predecessor.Construct)) { pair.Value.Predecessor = newNode; newNode.TreeEdgeSuccessors.Add(pair.Value); } if (pair.Value.DominanceFrontier.Remove(oldNode)) { pair.Value.DominanceFrontier.Add(newNode); } } if (RootConstruct == originalEntry) { RootConstruct = newConstruct; } constructToNodeMap.Add(newConstruct, newNode); }