Class CFG

java.lang.Object
org.jruby.ir.representations.CFG

public class CFG extends Object
Represents the base build of a CFG. All information here is accessed via delegation from the CFG itself so this is meant as an internal organizational structure for a build.
  • Field Details

    • LOG

      private static final Logger LOG
    • scope

      private final IRScope scope
    • bbMap

      private final Map<Label,BasicBlock> bbMap
    • rescuerMap

      private final Map<BasicBlock,BasicBlock> rescuerMap
    • entryBB

      private BasicBlock entryBB
      Entry BB
    • exitBB

      private BasicBlock exitBB
      Exit BB
    • returnBBs

      List<BasicBlock> returnBBs
      List of bbs that have a 'return' instruction
    • globalEnsureBB

      private BasicBlock globalEnsureBB
      BB that traps all exception-edges out of the cfg where we could add any cleanup/ensure code (ex: pop frames, etc.)
    • graph

      private final org.jruby.dirgra.DirectedGraph<BasicBlock> graph
      The graph itself
    • nextBBId

      private int nextBBId
    • postOrderList

      LinkedList<BasicBlock> postOrderList
  • Constructor Details

  • Method Details

    • getNextBBID

      public int getNextBBID()
    • getManager

      public IRManager getManager()
    • getMaxNodeID

      public int getMaxNodeID()
    • bbIsProtected

      public boolean bbIsProtected(BasicBlock b)
    • getBBForLabel

      public BasicBlock getBBForLabel(Label label)
    • getEntryBB

      public BasicBlock getEntryBB()
    • getExitBB

      public BasicBlock getExitBB()
    • getGlobalEnsureBB

      public BasicBlock getGlobalEnsureBB()
    • postOrderList

      public LinkedList<BasicBlock> postOrderList()
    • getPostOrderTraverser

      public Iterator<BasicBlock> getPostOrderTraverser()
    • getReversePostOrderTraverser

      public Iterator<BasicBlock> getReversePostOrderTraverser()
    • resetState

      public void resetState()
    • getScope

      public IRScope getScope()
    • size

      public int size()
      How many BasicBlocks are there in this CFG?
    • getBasicBlocks

      public Collection<BasicBlock> getBasicBlocks()
    • getSortedBasicBlocks

      public Collection<BasicBlock> getSortedBasicBlocks()
    • addEdge

      public void addEdge(BasicBlock source, BasicBlock destination, Object type)
    • inDegree

      public int inDegree(BasicBlock b)
    • outDegree

      public int outDegree(BasicBlock b)
    • getIncomingSources

      public Iterable<BasicBlock> getIncomingSources(BasicBlock block)
    • getIncomingEdges

      public Iterable<org.jruby.dirgra.Edge<BasicBlock>> getIncomingEdges(BasicBlock block)
    • getIncomingSourceOfType

      public BasicBlock getIncomingSourceOfType(BasicBlock block, Object type)
    • getOutgoingDestinationOfType

      public BasicBlock getOutgoingDestinationOfType(BasicBlock block, Object type)
    • getOutgoingDestinations

      public Iterable<BasicBlock> getOutgoingDestinations(BasicBlock block)
    • getOutgoingDestinationsOfType

      public Iterable<BasicBlock> getOutgoingDestinationsOfType(BasicBlock block, Object type)
    • getOutgoingDestinationsNotOfType

      public Iterable<BasicBlock> getOutgoingDestinationsNotOfType(BasicBlock block, Object type)
    • getOutgoingEdges

      public Collection<org.jruby.dirgra.Edge<BasicBlock>> getOutgoingEdges(BasicBlock block)
    • getRescuerBBFor

      public BasicBlock getRescuerBBFor(BasicBlock block)
    • addGlobalEnsureBB

      public void addGlobalEnsureBB(BasicBlock geb)
    • setRescuerBB

      public void setRescuerBB(BasicBlock block, BasicBlock rescuerBlock)
    • build

      public org.jruby.dirgra.DirectedGraph<BasicBlock> build(Instr[] instrs)
      Build the Control Flow Graph
    • fixupEdges

      public void fixupEdges(BasicBlock bb)
    • addEdge

      private void addEdge(BasicBlock src, Label targetLabel, Map<Label,List<BasicBlock>> forwardRefs)
    • buildExitBasicBlock

      private BasicBlock buildExitBasicBlock(Stack<ExceptionRegion> nestedExceptionRegions, BasicBlock firstBB, List<BasicBlock> returnBBs, List<BasicBlock> exceptionBBs, boolean nextIsFallThrough, BasicBlock currBB, BasicBlock entryBB)
      Create special empty exit BasicBlock that all BasicBlocks will eventually flow into. All Edges to this 'dummy' BasicBlock will get marked with an edge type of EXIT. Special BasicBlocks worth noting: 1. Exceptions, Returns, Entry(why?) -> ExitBB 2. Returns -> ExitBB
    • createBB

      private BasicBlock createBB(Label label, Stack<ExceptionRegion> nestedExceptionRegions)
    • createBB

      private BasicBlock createBB(Stack<ExceptionRegion> nestedExceptionRegions)
    • addBasicBlock

      public void addBasicBlock(BasicBlock bb)
    • removeAllOutgoingEdgesForBB

      public void removeAllOutgoingEdgesForBB(BasicBlock b)
    • deleteOrphanedBlocks

      private void deleteOrphanedBlocks(org.jruby.dirgra.DirectedGraph<BasicBlock> graph)
    • mergeBBs

      private boolean mergeBBs(BasicBlock a, BasicBlock b)
    • removeBB

      public void removeBB(BasicBlock b)
    • removeNestedScopesFromBB

      private void removeNestedScopesFromBB(BasicBlock bb)
      Wrapped IRClosures in dead BB are lexically rooted to that dead BB so they can be removed from the parent scope if the BB they live in died.
    • collapseStraightLineBBs

      public void collapseStraightLineBBs()
    • optimize

      public void optimize()
    • toStringGraph

      public String toStringGraph()
    • toStringInstrs

      public String toStringInstrs()
    • removeEdge

      public void removeEdge(BasicBlock a, BasicBlock b)
    • buildPostOrderList

      private LinkedList<BasicBlock> buildPostOrderList()
    • clone

      public CFG clone(CloneInfo info, IRScope clonedScope)
      Clone this CFG and return a new one.
      Parameters:
      info - context object to perform the clone
      clonedScope - already cloned IRScope which this new CFG will belong to
      Returns:
      a newly cloned CFG
    • printError

      private void printError(String message)