Class BlockGraph

    • Constructor Detail

      • BlockGraph

        protected BlockGraph​(UnitGraph unitGraph)
        Create a BlockGraph representing at the basic block level the control flow specified, at the Unit level, by a given UnitGraph.
        Parameters:
        unitGraph - A representation of the control flow at the level of individual Units.
    • Method Detail

      • computeLeaders

        protected Set<Unit> computeLeaders​(UnitGraph unitGraph)

        Utility method for computing the basic block leaders for a Body, given its UnitGraph (i.e., the instructions which begin new basic blocks).

        This implementation designates as basic block leaders :

        • Any Unit which has zero predecessors (e.g. the Unit following a return or unconditional branch) or more than one predecessor (e.g. a merge point).
        • Units which are the target of any branch (even if they have no other predecessors and the branch has no other successors, which is possible for the targets of unconditional branches or degenerate conditional branches which both branch and fall through to the same Unit).
        • All successors of any Unit which has more than one successor (this includes the successors of Units which may throw an exception that gets caught within the Body, as well the successors of conditional branches).
        • The first Unit in any Trap handler. (Strictly speaking, if unitGraph were a ExceptionalUnitGraph that included only a single unexceptional predecessor for some handler—because no trapped unit could possibly throw the exception that the handler catches, while the code preceding the handler fell through to the handler's code—then you could merge the handler into the predecessor's basic block; but such situations occur only in carefully contrived bytecode.)

        Parameters:
        unitGraph - is the Unit-level CFG which is to be split into basic blocks.
        Returns:
        the Set of Units in unitGraph which are block leaders.
      • buildBlocks

        protected Map<Unit,​Block> buildBlocks​(Set<Unit> leaders,
                                                    UnitGraph unitGraph)

        A utility method that does most of the work of constructing basic blocks, once the set of block leaders has been determined, and which designates the heads and tails of the graph.

        BlockGraph provides an implementation of buildBlocks() which splits the Units in unitGraph so that each Unit in the passed set of block leaders is the first unit in a block. It defines as heads the blocks which begin with Units which are heads in unitGraph, and defines as tails the blocks which end with Units which are tails in unitGraph. Subclasses might override this behavior.

        Parameters:
        leaders - Contains Units which are to be block leaders.
        unitGraph - Provides information about the predecessors and successors of each Unit in the Body, for determining the predecessors and successors of each created Block.
        Returns:
        a Map from Units which begin or end a block to the block which contains them.
      • getBlocks

        public List<Block> getBlocks()
        Returns a list of the Blocks composing this graph.
        Returns:
        A list of the blocks composing this graph in the same order as they partition underlying Body instance's unit chain.
        See Also:
        Block