/// <summary> /// Perform data-flow analysis to get dead definitions for each basic block. /// </summary> /// <param name="Graph">HlGraph.</param> /// <returns>Data flow results.</returns> /// <remarks>Dead definitions is an all-paths reverse data flow problem described by the /// following equations: /// /// <code> /// InitFn(n) := ( (n == CanonicalExit) ? ALL_STACK | ALL_LOCAL | ALL_ARG : TOP, TOP ) /// NodeFn(n, l) := l + n.DAD - n.UEU /// EdgeFn(s, t, l) := l /// MergeFn(l, r) := (l & r) /// </code> /// </remarks> public static DataFlow <LocationList> .Result DoDF(HlGraph Graph) { DataFlow <LocationList> .Result DfResult = DataFlow <LocationList> .Reverse( Graph.BasicBlocks, delegate(BasicBlock BasicBlock, out LocationList Entry, out LocationList Exit) { if (Graph.CanonicalExitBlock == BasicBlock) { Entry = new LocationList(); for (int i = 0; i < Graph.m_MaxStack; i++) { Entry.Add(new StackLocation(i)); } foreach (LocalVariableLocation LocVar in Graph.LocalVariables) { Entry.Add(LocVar); } foreach (ArgumentLocation Arg in Graph.Arguments) { Entry.Add(Arg); } Exit = null; } else { Entry = Exit = null; } }, delegate(BasicBlock BasicBlock, LocationList DeadDefinitionList) { return(BeforeInstruction(BasicBlock, 0, DeadDefinitionList)); }, delegate(BasicBlock Source, BasicBlock Target, LocationList DeadDefinitionList) { return(DeadDefinitionList); }, LocationList.MergeInlineAnd ); return(DfResult); }