public InterProcGenKill(Implementation impl, Program program) { Contract.Requires(program != null); Contract.Requires(impl != null); this.program = program; procICFG = new Dictionary<string/*!*/, ICFG/*!*/>(); name2Proc = new Dictionary<string/*!*/, Procedure/*!*/>(); workList = new WorkList(); this.callers = new Dictionary<string/*!*/, List<WorkItem/*!*/>/*!*/>(); this.callGraph = new Graph<string/*!*/>(); this.procPriority = new Dictionary<string/*!*/, int>(); this.maxBlocksInProc = 0; this.mainImpl = impl; Dictionary<string/*!*/, Implementation/*!*/>/*!*/ name2Impl = new Dictionary<string/*!*/, Implementation/*!*/>(); varsLiveAtExit.Clear(); varsLiveAtEntry.Clear(); varsLiveSummary.Clear(); foreach (var decl in program.TopLevelDeclarations) { Contract.Assert(decl != null); if (decl is Implementation) { Implementation/*!*/ imp = (Implementation/*!*/)cce.NonNull(decl); name2Impl[imp.Name] = imp; } else if (decl is Procedure) { Procedure/*!*/ proc = cce.NonNull(decl as Procedure); name2Proc[proc.Name] = proc; } } ICFG/*!*/ mainICFG = new ICFG(mainImpl); Contract.Assert(mainICFG != null); procICFG.Add(mainICFG.impl.Name, mainICFG); callGraph.AddSource(mainICFG.impl.Name); List<ICFG/*!*/>/*!*/ procsToConsider = new List<ICFG/*!*/>(); procsToConsider.Add(mainICFG); while (procsToConsider.Count != 0) { ICFG/*!*/ p = procsToConsider[0]; Contract.Assert(p != null); procsToConsider.RemoveAt(0); foreach (string/*!*/ callee in p.procsCalled.Keys) { Contract.Assert(callee != null); if (!name2Impl.ContainsKey(callee)) continue; callGraph.AddEdge(p.impl.Name, callee); if (maxBlocksInProc < p.nodes.Count) { maxBlocksInProc = p.nodes.Count; } if (!callers.ContainsKey(callee)) { callers.Add(callee, new List<WorkItem/*!*/>()); } foreach (Block/*!*/ b in p.procsCalled[callee]) { Contract.Assert(b != null); callers[callee].Add(new WorkItem(p, b)); } if (procICFG.ContainsKey(callee)) continue; ICFG/*!*/ ncfg = new ICFG(name2Impl[callee]); Contract.Assert(ncfg != null); procICFG.Add(callee, ncfg); procsToConsider.Add(ncfg); } } bool acyclic; List<string>/*!*/ sortedNodes; callGraph.TarjanTopSort(out acyclic, out sortedNodes); Contract.Assert(acyclic); int cnt = 0; for (int i = sortedNodes.Count - 1; i >= 0; i--) { string s = sortedNodes[i]; if (s == null) continue; procPriority.Add(s, cnt); cnt++; } }
public WorkItem(ICFG cfg, Block block) { Contract.Requires(block != null); Contract.Requires(cfg != null); this.cfg = cfg; this.block = block; }