Top Description Inners Fields Constructors Methods
org.jruby.ir.representations

public Class CFG

extends Object
Class Inheritance
Imports
org.jruby.dirgra.DirectedGraph, .Edge, org.jruby.ir.IRManager, .IRScope, .Operation, org.jruby.ir.instructions.*, org.jruby.ir.operands.Label, .Operand, .Variable, .WrappedIRClosure, org.jruby.ir.transformations.inlining.CloneInfo, org.jruby.util.log.Logger, .LoggerFactory, java.util.*

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.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum

Field Summary

Modifier and TypeField and Description
private final Map<Label, BasicBlock>
private BasicBlock
entryBB

Entry BB

private BasicBlock
exitBB

Exit BB

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.)

private final DirectedGraph<BasicBlock, CFG.EdgeType>
graph

The graph itself

private static final Logger
private int
pack-priv LinkedList<BasicBlock>
private final Map<BasicBlock, BasicBlock>
pack-priv List<BasicBlock>
returnBBs

List of bbs that have a 'return' instruction

private final IRScope

Constructor Summary

AccessConstructor and Description
public
CFG(IRScope scope)

Method Summary

Modifier and TypeMethod and Description
public void
public void
addEdge(BasicBlock source, BasicBlock destination, CFG.EdgeType type)

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

public void
public boolean
public DirectedGraph<BasicBlock, CFG.EdgeType>
build(Instr[] instrs)

Build the Control Flow Graph

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.

private LinkedList<BasicBlock>
public CFG

Returns:

a newly cloned CFG
clone
(CloneInfo
context object to perform the clone
info
,
IRScope
already cloned IRScope which this new CFG will belong to
clonedScope
)

Clone this CFG and return a new one.

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

private BasicBlock
createBB(Stack<ExceptionRegion> nestedExceptionRegions)

private void
public void
public Collection<BasicBlock>
public BasicBlock
public BasicBlock
public BasicBlock
public BasicBlock
public Iterable<Edge<BasicBlock, CFG.EdgeType>>
public BasicBlock
public Iterable<BasicBlock>
public IRManager
public int
public int
public BasicBlock
public Iterable<BasicBlock>
public Iterable<BasicBlock>
public Iterable<BasicBlock>
public Collection<Edge<BasicBlock, CFG.EdgeType>>
public Iterator<BasicBlock>
public BasicBlock
public Iterator<BasicBlock>
public IRScope
public Collection<BasicBlock>
public int
private boolean
public void
public int
public LinkedList<BasicBlock>
private void
printError(String message)

public void
public void
public void
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.

public void
setRescuerBB(BasicBlock block, BasicBlock rescuerBlock)

public int
size()

How many BasicBlocks are there in this CFG?

public String
public String
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bbMapback to summary
private final Map<Label, BasicBlock> bbMap
entryBBback to summary
private BasicBlock entryBB

Entry BB

exitBBback to summary
private BasicBlock exitBB

Exit BB

globalEnsureBBback to summary
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.)

graphback to summary
private final DirectedGraph<BasicBlock, CFG.EdgeType> graph

The graph itself

LOGback to summary
private static final Logger LOG
nextBBIdback to summary
private int nextBBId
postOrderListback to summary
pack-priv LinkedList<BasicBlock> postOrderList
rescuerMapback to summary
private final Map<BasicBlock, BasicBlock> rescuerMap
returnBBsback to summary
pack-priv List<BasicBlock> returnBBs

List of bbs that have a 'return' instruction

scopeback to summary
private final IRScope scope

Constructor Detail

CFGback to summary
public CFG(IRScope scope)

Method Detail

addBasicBlockback to summary
public void addBasicBlock(BasicBlock bb)
addEdgeback to summary
public void addEdge(BasicBlock source, BasicBlock destination, CFG.EdgeType type)
addEdgeback to summary
private void addEdge(BasicBlock src, Label targetLabel, Map<Label, List<BasicBlock>> forwardRefs)
addGlobalEnsureBBback to summary
public void addGlobalEnsureBB(BasicBlock geb)
bbIsProtectedback to summary
public boolean bbIsProtected(BasicBlock b)
buildback to summary
public DirectedGraph<BasicBlock, CFG.EdgeType> build(Instr[] instrs)

Build the Control Flow Graph

buildExitBasicBlockback to summary
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

buildPostOrderListback to summary
private LinkedList<BasicBlock> buildPostOrderList()
cloneback to summary
public CFG clone(CloneInfo info, IRScope clonedScope)

Clone this CFG and return a new one.

Parameters
info:CloneInfo

context object to perform the clone

clonedScope:IRScope

already cloned IRScope which this new CFG will belong to

Returns:CFG

a newly cloned CFG

collapseStraightLineBBsback to summary
public void collapseStraightLineBBs()
createBBback to summary
private BasicBlock createBB(Label label, Stack<ExceptionRegion> nestedExceptionRegions)
createBBback to summary
private BasicBlock createBB(Stack<ExceptionRegion> nestedExceptionRegions)
deleteOrphanedBlocksback to summary
private void deleteOrphanedBlocks(DirectedGraph<BasicBlock, CFG.EdgeType> graph)
fixupEdgesback to summary
public void fixupEdges(BasicBlock bb)
getBasicBlocksback to summary
public Collection<BasicBlock> getBasicBlocks()
getBBForLabelback to summary
public BasicBlock getBBForLabel(Label label)
getEntryBBback to summary
public BasicBlock getEntryBB()
getExitBBback to summary
public BasicBlock getExitBB()
getGlobalEnsureBBback to summary
public BasicBlock getGlobalEnsureBB()
getIncomingEdgesback to summary
public Iterable<Edge<BasicBlock, CFG.EdgeType>> getIncomingEdges(BasicBlock block)
getIncomingSourceOfTypeback to summary
public BasicBlock getIncomingSourceOfType(BasicBlock block, CFG.EdgeType type)
getIncomingSourcesback to summary
public Iterable<BasicBlock> getIncomingSources(BasicBlock block)
getManagerback to summary
public IRManager getManager()
getMaxNodeIDback to summary
public int getMaxNodeID()
getNextBBIDback to summary
public int getNextBBID()
getOutgoingDestinationOfTypeback to summary
public BasicBlock getOutgoingDestinationOfType(BasicBlock block, CFG.EdgeType type)
getOutgoingDestinationsback to summary
public Iterable<BasicBlock> getOutgoingDestinations(BasicBlock block)
getOutgoingDestinationsNotOfTypeback to summary
public Iterable<BasicBlock> getOutgoingDestinationsNotOfType(BasicBlock block, CFG.EdgeType type)
getOutgoingDestinationsOfTypeback to summary
public Iterable<BasicBlock> getOutgoingDestinationsOfType(BasicBlock block, CFG.EdgeType type)
getOutgoingEdgesback to summary
public Collection<Edge<BasicBlock, CFG.EdgeType>> getOutgoingEdges(BasicBlock block)
getPostOrderTraverserback to summary
public Iterator<BasicBlock> getPostOrderTraverser()
getRescuerBBForback to summary
public BasicBlock getRescuerBBFor(BasicBlock block)
getReversePostOrderTraverserback to summary
public Iterator<BasicBlock> getReversePostOrderTraverser()
getScopeback to summary
public IRScope getScope()
getSortedBasicBlocksback to summary
public Collection<BasicBlock> getSortedBasicBlocks()
inDegreeback to summary
public int inDegree(BasicBlock b)
mergeBBsback to summary
private boolean mergeBBs(BasicBlock a, BasicBlock b)
optimizeback to summary
public void optimize()
outDegreeback to summary
public int outDegree(BasicBlock b)
postOrderListback to summary
public LinkedList<BasicBlock> postOrderList()
printErrorback to summary
private void printError(String message)
removeAllOutgoingEdgesForBBback to summary
public void removeAllOutgoingEdgesForBB(BasicBlock b)
removeBBback to summary
public void removeBB(BasicBlock b)
removeEdgeback to summary
public void removeEdge(BasicBlock a, BasicBlock b)
removeNestedScopesFromBBback to summary
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.

setRescuerBBback to summary
public void setRescuerBB(BasicBlock block, BasicBlock rescuerBlock)
sizeback to summary
public int size()

How many BasicBlocks are there in this CFG?

toStringGraphback to summary
public String toStringGraph()
toStringInstrsback to summary
public String toStringInstrs()
org.jruby.ir.representations back to summary

public final Enum CFG.EdgeType

extends Enum<CFG.EdgeType>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final CFG.EdgeType
public static final CFG.EdgeType
public static final CFG.EdgeType
public static final CFG.EdgeType

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static CFG.EdgeType
public static CFG.EdgeType[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

EXCEPTIONback to summary
public static final CFG.EdgeType EXCEPTION
EXITback to summary
public static final CFG.EdgeType EXIT
FALL_THROUGHback to summary
public static final CFG.EdgeType FALL_THROUGH
REGULARback to summary
public static final CFG.EdgeType REGULAR

Constructor Detail

EdgeTypeback to summary
private EdgeType()

Method Detail

valueOfback to summary
public static CFG.EdgeType valueOf(String name)
valuesback to summary
public static CFG.EdgeType[] values()