Class PrunedCFG<I, T extends IBasicBlock<I>>

All Implemented Interfaces:
ControlFlowGraph<I,T>, MinimalCFG<T>, EdgeManager<T>, Graph<T>, NodeManager<T>, NumberedEdgeManager<T>, NumberedGraph<T>, NumberedNodeManager<T>, Iterable<T>

public class PrunedCFG<I, T extends IBasicBlock<I>> extends AbstractNumberedGraph<T> implements ControlFlowGraph<I,T>
A view of a ControlFlowGraph restricted to paths from entry to exit that use edges accepted by an EdgeFilter.

A block is retained only if it is both reachable from entry and able to reach exit using accepted edges. The entry and exit blocks are always retained, even if no path connects them. Edges are retained only when accepted by the filter and both endpoints are retained.

For example, filtering all exceptional exits from a method that always throws can remove its entire body from the view, leaving only disconnected entry and exit blocks. Removed blocks may contain instructions that execute before the filtered exception is thrown; removal does not imply that those instructions are unreachable in the original CFG. This also removes reachable loops that have no path to exit.

  • Method Details

    • make

      public static <I, T extends IBasicBlock<I>> PrunedCFG<I,T> make(ControlFlowGraph<I,T> cfg, EdgeFilter<T> filter)
      Creates a view with the edge and block restrictions described by PrunedCFG.
      Parameters:
      cfg - the original CFG that you want a view of
      filter - an object that selectively filters edges in the original CFG
      Returns:
      a view containing blocks on accepted paths from entry to exit, plus entry and exit
      Throws:
      IllegalArgumentException - if cfg is null
    • getNodeManager

      protected NumberedNodeManager<T> getNodeManager()
      Specified by:
      getNodeManager in class AbstractNumberedGraph<T extends IBasicBlock<I>>
      Returns:
      the object which manages nodes in the graph
    • getEdgeManager

      protected NumberedEdgeManager<T> getEdgeManager()
      Specified by:
      getEdgeManager in class AbstractNumberedGraph<T extends IBasicBlock<I>>
      Returns:
      the object which manages edges in the graph
    • getExceptionalSuccessors

      public List<T> getExceptionalSuccessors(T N)
      Description copied from interface: MinimalCFG
      The order of blocks returned must indicate the exception-handling scope. So the first block is the first candidate catch block, and so on. With this invariant one can compute the exceptional control flow for a given exception type.
      Specified by:
      getExceptionalSuccessors in interface MinimalCFG<I>
      Returns:
      the basic blocks which may be reached from b via exceptional control flow
    • getNormalSuccessors

      public Collection<T> getNormalSuccessors(T N)
      Description copied from interface: MinimalCFG
      The order of blocks returned should be arbitrary but deterministic.
      Specified by:
      getNormalSuccessors in interface MinimalCFG<I>
      Returns:
      the basic blocks which may be reached from b via normal control flow
    • getExceptionalPredecessors

      public Collection<T> getExceptionalPredecessors(T N)
      Description copied from interface: MinimalCFG
      The order of blocks returned should be arbitrary but deterministic.
      Specified by:
      getExceptionalPredecessors in interface MinimalCFG<I>
      Returns:
      the basic blocks from which b may be reached via exceptional control flow
    • getNormalPredecessors

      public Collection<T> getNormalPredecessors(T N)
      Description copied from interface: MinimalCFG
      The order of blocks returned should be arbitrary but deterministic.
      Specified by:
      getNormalPredecessors in interface MinimalCFG<I>
      Returns:
      the basic blocks from which b may be reached via normal control flow
    • entry

      public T entry()
      Description copied from interface: MinimalCFG
      Return the entry basic block in the CFG
      Specified by:
      entry in interface MinimalCFG<I>
    • exit

      public T exit()
      Specified by:
      exit in interface MinimalCFG<I>
      Returns:
      the synthetic exit block for the cfg
    • getBlockForInstruction

      public T getBlockForInstruction(int index)
      Specified by:
      getBlockForInstruction in interface ControlFlowGraph<I, T extends IBasicBlock<I>>
      Parameters:
      index - an instruction index
      Returns:
      the basic block which contains this instruction.
    • getInstructions

      public I[] getInstructions()
      Specified by:
      getInstructions in interface ControlFlowGraph<I, T extends IBasicBlock<I>>
      Returns:
      the instructions of this CFG, as an array.
    • getProgramCounter

      public int getProgramCounter(int index)
      Description copied from interface: ControlFlowGraph
      TODO: move this into IR?
      Specified by:
      getProgramCounter in interface ControlFlowGraph<I, T extends IBasicBlock<I>>
      Parameters:
      index - an instruction index
      Returns:
      the program counter (bytecode index) corresponding to that instruction
    • getMethod

      public IMethod getMethod()
      Specified by:
      getMethod in interface ControlFlowGraph<I, T extends IBasicBlock<I>>
      Returns:
      the Method this CFG represents
    • getCatchBlocks

      public BitVector getCatchBlocks()
      Specified by:
      getCatchBlocks in interface ControlFlowGraph<I, T extends IBasicBlock<I>>
      Returns:
      the indices of the catch blocks, as a bit vector
    • getPhiIndices

      public IntSet getPhiIndices(T bb)