private Dictionary <ILogicalConstruct, HashSet <ISingleEntrySubGraph> > GetValidCases(DominatorTree dominatorTree, ILogicalConstruct switchCFGBlock) { V_0 = new SwitchBuilder.u003cu003ec__DisplayClass9_0(); V_0.caseEntriesToDominatedNodesMap = new Dictionary <ILogicalConstruct, HashSet <ISingleEntrySubGraph> >(); V_1 = new HashSet <ISingleEntrySubGraph>(); dummyVar0 = V_1.Add(switchCFGBlock); V_4 = switchCFGBlock.get_SameParentSuccessors().GetEnumerator(); try { while (V_4.MoveNext()) { V_5 = (ILogicalConstruct)V_4.get_Current(); if (V_5 == switchCFGBlock || dominatorTree.GetImmediateDominator(V_5) != switchCFGBlock) { continue; } V_6 = dominatorTree.GetDominatedNodes(V_5); V_0.caseEntriesToDominatedNodesMap.Add(V_5, V_6); V_1.UnionWith(V_6); } } finally { ((IDisposable)V_4).Dispose(); } stackVariable34 = DFSTBuilder.BuildTree(switchCFGBlock.get_Parent(), switchCFGBlock).get_ReversePostOrder(); stackVariable35 = SwitchBuilder.u003cu003ec.u003cu003e9__9_0; if (stackVariable35 == null) { dummyVar1 = stackVariable35; stackVariable35 = new Func <DFSTNode, ILogicalConstruct>(SwitchBuilder.u003cu003ec.u003cu003e9.u003cGetValidCasesu003eb__9_0); SwitchBuilder.u003cu003ec.u003cu003e9__9_0 = stackVariable35; } V_2 = new List <ILogicalConstruct>(stackVariable34.Select <DFSTNode, ILogicalConstruct>(stackVariable35).Where <ILogicalConstruct>(new Func <ILogicalConstruct, bool>(V_0.u003cGetValidCasesu003eb__1))); do { V_3 = false; V_7 = V_2.GetEnumerator(); try { while (V_7.MoveNext()) { V_8 = V_7.get_Current(); if (!V_0.caseEntriesToDominatedNodesMap.TryGetValue(V_8, out V_9) || this.IsCaseValid(V_8, V_1)) { continue; } V_1.ExceptWith(V_9); dummyVar2 = V_0.caseEntriesToDominatedNodesMap.Remove(V_8); V_3 = true; } } finally { ((IDisposable)V_7).Dispose(); } }while (V_3); return(V_0.caseEntriesToDominatedNodesMap); }
private Dictionary <ILogicalConstruct, HashSet <ISingleEntrySubGraph> > GetValidCases(DominatorTree dominatorTree, ILogicalConstruct switchCFGBlock) { Dictionary <ILogicalConstruct, HashSet <ISingleEntrySubGraph> > caseEntriesToDominatedNodesMap = new Dictionary <ILogicalConstruct, HashSet <ISingleEntrySubGraph> >(); HashSet <ISingleEntrySubGraph> legalPredecessors = new HashSet <ISingleEntrySubGraph>(); legalPredecessors.Add(switchCFGBlock); foreach (ILogicalConstruct successor in switchCFGBlock.SameParentSuccessors) { if (successor != switchCFGBlock && dominatorTree.GetImmediateDominator(successor) == switchCFGBlock) { HashSet <ISingleEntrySubGraph> dominatedNodes = dominatorTree.GetDominatedNodes(successor); caseEntriesToDominatedNodesMap.Add(successor, dominatedNodes); legalPredecessors.UnionWith(dominatedNodes); } } DFSTree dfsTree = DFSTBuilder.BuildTree(switchCFGBlock.Parent, switchCFGBlock); List <ILogicalConstruct> orderedCaseEntries = new List <ILogicalConstruct>(dfsTree.ReversePostOrder.Select(node => node.Construct as ILogicalConstruct).Where(construct => caseEntriesToDominatedNodesMap.ContainsKey(construct))); bool changed; do { changed = false; foreach (ILogicalConstruct caseEntry in orderedCaseEntries) { HashSet <ISingleEntrySubGraph> dominatedNodes; if (caseEntriesToDominatedNodesMap.TryGetValue(caseEntry, out dominatedNodes) && !IsCaseValid(caseEntry, legalPredecessors)) { legalPredecessors.ExceptWith(dominatedNodes); caseEntriesToDominatedNodesMap.Remove(caseEntry); changed = true; } } } while (changed); return(caseEntriesToDominatedNodesMap); }
private HashSet <ILogicalConstruct> GetBlockBody(DominatorTree dominatorTree, ILogicalConstruct conditionSuccessor, ConditionLogicalConstruct theCondition) { if (conditionSuccessor == dominatorTree.get_RootConstruct()) { return(null); } V_0 = null; if (conditionSuccessor.get_AllPredecessors().get_Count() == 1) { V_0 = new HashSet <ILogicalConstruct>(); V_1 = dominatorTree.GetDominatedNodes(conditionSuccessor).GetEnumerator(); try { while (V_1.MoveNext()) { V_2 = (ILogicalConstruct)V_1.get_Current(); if (V_2 != theCondition) { dummyVar0 = V_0.Add(V_2); } else { V_3 = null; goto Label1; } } goto Label0; } finally { ((IDisposable)V_1).Dispose(); } Label1: return(V_3); } Label0: return(V_0); }
/// <summary> /// Gets the dominated nodes of the condition successor, only if they can form a legal block for the if construct. /// </summary> /// <param name="dominatorTree"></param> /// <param name="conditionSuccessor"></param> /// <returns>On success - a set of the nodes fo the block. Otherwise it returns null.</returns> private HashSet <ILogicalConstruct> GetBlockBody(DominatorTree dominatorTree, ILogicalConstruct conditionSuccessor, ConditionLogicalConstruct theCondition) { if (conditionSuccessor == dominatorTree.RootConstruct) //Corner case - the successor cannot be the entry of the construct. { return(null); } HashSet <ILogicalConstruct> body = null; if (conditionSuccessor.AllPredecessors.Count == 1) //The condition successor must have only one predecessor - the condition. { body = new HashSet <ILogicalConstruct>(); foreach (ILogicalConstruct node in dominatorTree.GetDominatedNodes(conditionSuccessor)) { if (node == theCondition) { return(null); } body.Add(node); } } return(body); }