Class SSACFG
- All Implemented Interfaces:
ControlFlowGraph<SSAInstruction, ISSABasicBlock>, MinimalCFG<ISSABasicBlock>, EdgeManager<ISSABasicBlock>, Graph<ISSABasicBlock>, NodeManager<ISSABasicBlock>, NumberedEdgeManager<ISSABasicBlock>, NumberedGraph<ISSABasicBlock>, NumberedNodeManager<ISSABasicBlock>, Iterable<ISSABasicBlock>
This implementation is uglified in the name of performance. This implementation does not
directly track the graph structure, but instead delegates to a prebuilt ControlFlowGraph
which stores the structure. This decision from 2004 may have been premature optimization, left
over from a world where IRs and related structures were long-lived. In today's system,
they are cached and reconstituted by SSACache. Perhaps we should just extend AbstractCFG and not worry so much about space.
As the current implementation stands, the delegate graph stores the graph structure, and this
class additionally stores SSACFG.BasicBlocks and the SSAInstruction array.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassA Basic Block in an SSA IRclass -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final AbstractCFG<IInstruction, IBasicBlock<IInstruction>> A delegate CFG, pre-built, which stores the graph structure of this CFG.protected final SSAInstruction[]The "normal" instructions which constitute the SSA form.protected final IMethodTheIMethodthisControlFlowGraphrepresents -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddEdge(ISSABasicBlock src, ISSABasicBlock dst) voidadd a node to this graphbooleanentry()Return the entry basic block in the CFGbooleanexit()getBasicBlock(int bb) getBlockForInstruction(int instructionIndex) Get the basic block an instruction belongs to.The order of blocks returned should be arbitrary but deterministic.The order of blocks returned must indicate the exception-handling scope.NB: Use iterators such as IR.iterateAllInstructions() instead of this method.intgetNode(int number) The order of blocks returned should be arbitrary but deterministic.The order of blocks returned should be arbitrary but deterministic.intintintReturn the number ofimmediate predecessornodes of nReturn anIteratorover the immediate predecessor nodes of nintgetProgramCounter(int index) TODO: move this into IR?intReturn the number ofimmediate successornodes of this Node in the GraphReturn an Iterator over the immediate successor nodes of nbooleanhasEdge(ISSABasicBlock src, ISSABasicBlock dst) booleanhasExceptionalEdge(SSACFG.BasicBlock src, SSACFG.BasicBlock dest) has exceptional edge src -> destinthashCode()booleanhasNormalEdge(SSACFG.BasicBlock src, SSACFG.BasicBlock dest) has normal edge src -> destbooleanisCatchBlock(int i) is the given i a catch block?iterator()voidvoidremoveEdge(ISSABasicBlock src, ISSABasicBlock dst) voidvoidremove a node from this graphvoidremove a node and all its incident edgesvoidstream()toString()Methods inherited from interface Iterable
forEach, spliterator
-
Field Details
-
instructions
The "normal" instructions which constitute the SSA form. This does not includeSSAPhiInstructions, which dwell inSSACFG.BasicBlocks instead. -
method
TheIMethodthisControlFlowGraphrepresents -
delegate
A delegate CFG, pre-built, which stores the graph structure of this CFG.
-
-
Constructor Details
-
SSACFG
- Throws:
IllegalArgumentException- if method is null
-
-
Method Details
-
hashCode
-
equals
-
getBlockForInstruction
Get the basic block an instruction belongs to. Note: the instruction2Block array is filled in lazily. During initialization, the mapping is set up only for the first instruction of each basic block.- Specified by:
getBlockForInstructionin interfaceControlFlowGraph<SSAInstruction, ISSABasicBlock>- Parameters:
instructionIndex- an instruction index- Returns:
- the basic block which contains this instruction.
-
getInstructions
NB: Use iterators such as IR.iterateAllInstructions() instead of this method. This will probably be deprecated someday.Return the instructions. Note that the CFG is created from the Shrike CFG prior to creating the SSA instructions.
- Specified by:
getInstructionsin interfaceControlFlowGraph<SSAInstruction, ISSABasicBlock>- Returns:
- an array containing the SSA instructions.
-
toString
-
getCatchBlocks
- Specified by:
getCatchBlocksin interfaceControlFlowGraph<SSAInstruction, ISSABasicBlock>- Returns:
- the indices of the catch blocks, as a bit vector
-
isCatchBlock
public boolean isCatchBlock(int i) is the given i a catch block?- Returns:
- true if catch block, false otherwise
-
entry
Description copied from interface:MinimalCFGReturn the entry basic block in the CFG- Specified by:
entryin interfaceMinimalCFG<ISSABasicBlock>
-
exit
- Specified by:
exitin interfaceMinimalCFG<ISSABasicBlock>- Returns:
- the synthetic exit block for the cfg
-
getNumber
- Specified by:
getNumberin interfaceNumberedNodeManager<ISSABasicBlock>- Throws:
IllegalArgumentException
-
getNode
- Specified by:
getNodein interfaceNumberedNodeManager<ISSABasicBlock>- See Also:
-
getMaxNumber
public int getMaxNumber()- Specified by:
getMaxNumberin interfaceNumberedNodeManager<ISSABasicBlock>- See Also:
-
iterator
- Specified by:
iteratorin interfaceIterable<ISSABasicBlock>- Specified by:
iteratorin interfaceNodeManager<ISSABasicBlock>- Returns:
- an
Iteratorof the nodes in this graph - See Also:
-
stream
- Specified by:
streamin interfaceNodeManager<ISSABasicBlock>- Returns:
- a
Streamof the nodes in this graph
-
getNumberOfNodes
public int getNumberOfNodes()- Specified by:
getNumberOfNodesin interfaceNodeManager<ISSABasicBlock>- Returns:
- the number of nodes in this graph
- See Also:
-
getPredNodes
Description copied from interface:EdgeManagerReturn anIteratorover the immediate predecessor nodes of nThis method never returns
null.- Specified by:
getPredNodesin interfaceEdgeManager<ISSABasicBlock>- Returns:
- an
Iteratorover the immediate predecessor nodes of this Node. - Throws:
IllegalArgumentException- See Also:
-
getPredNodeCount
Description copied from interface:EdgeManagerReturn the number ofimmediate predecessornodes of n- Specified by:
getPredNodeCountin interfaceEdgeManager<ISSABasicBlock>- Returns:
- the number of immediate predecessors of n.
- Throws:
IllegalArgumentException- See Also:
-
getSuccNodes
Description copied from interface:EdgeManagerReturn an Iterator over the immediate successor nodes of nThis method never returns
null.- Specified by:
getSuccNodesin interfaceEdgeManager<ISSABasicBlock>- Returns:
- an Iterator over the immediate successor nodes of n
- Throws:
IllegalArgumentException- See Also:
-
getSuccNodeCount
Description copied from interface:EdgeManagerReturn the number ofimmediate successornodes of this Node in the Graph- Specified by:
getSuccNodeCountin interfaceEdgeManager<ISSABasicBlock>- Returns:
- the number of immediate successor Nodes of this Node in the Graph.
- Throws:
IllegalArgumentException- See Also:
-
addNode
Description copied from interface:NodeManageradd a node to this graph- Specified by:
addNodein interfaceNodeManager<ISSABasicBlock>- Throws:
UnsupportedOperationException- See Also:
-
addEdge
- Specified by:
addEdgein interfaceEdgeManager<ISSABasicBlock>- Throws:
UnsupportedOperationException
-
removeEdge
- Specified by:
removeEdgein interfaceEdgeManager<ISSABasicBlock>- Throws:
UnsupportedOperationException
-
removeAllIncidentEdges
- Specified by:
removeAllIncidentEdgesin interfaceEdgeManager<ISSABasicBlock>- Throws:
UnsupportedOperationException- See Also:
-
removeNodeAndEdges
Description copied from interface:Graphremove a node and all its incident edges- Specified by:
removeNodeAndEdgesin interfaceGraph<ISSABasicBlock>- Throws:
UnsupportedOperationException- if the graph implementation does not allow removal- See Also:
-
removeNode
Description copied from interface:NodeManagerremove a node from this graph- Specified by:
removeNodein interfaceNodeManager<ISSABasicBlock>- Throws:
UnsupportedOperationException- See Also:
-
getProgramCounter
public int getProgramCounter(int index) Description copied from interface:ControlFlowGraphTODO: move this into IR?- Specified by:
getProgramCounterin interfaceControlFlowGraph<SSAInstruction, ISSABasicBlock>- Parameters:
index- an instruction index- Returns:
- the program counter (bytecode index) corresponding to that instruction
-
containsNode
- Specified by:
containsNodein interfaceNodeManager<ISSABasicBlock>- Returns:
- true iff the graph contains the specified node
- See Also:
-
getMethod
- Specified by:
getMethodin interfaceControlFlowGraph<SSAInstruction, ISSABasicBlock>- Returns:
- the Method this CFG represents
-
getExceptionalSuccessors
Description copied from interface:MinimalCFGThe 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:
getExceptionalSuccessorsin interfaceMinimalCFG<ISSABasicBlock>- Returns:
- the basic blocks which may be reached from b via exceptional control flow
-
getExceptionalPredecessors
Description copied from interface:MinimalCFGThe order of blocks returned should be arbitrary but deterministic.- Specified by:
getExceptionalPredecessorsin interfaceMinimalCFG<ISSABasicBlock>- Returns:
- the basic blocks from which b may be reached via exceptional control flow
- See Also:
-
hasExceptionalEdge
has exceptional edge src -> dest- Throws:
IllegalArgumentException- if dest is null
-
hasNormalEdge
has normal edge src -> dest- Throws:
IllegalArgumentException- if dest is null
-
getNormalSuccessors
Description copied from interface:MinimalCFGThe order of blocks returned should be arbitrary but deterministic.- Specified by:
getNormalSuccessorsin interfaceMinimalCFG<ISSABasicBlock>- Returns:
- the basic blocks which may be reached from b via normal control flow
-
getNormalPredecessors
Description copied from interface:MinimalCFGThe order of blocks returned should be arbitrary but deterministic.- Specified by:
getNormalPredecessorsin interfaceMinimalCFG<ISSABasicBlock>- Returns:
- the basic blocks from which b may be reached via normal control flow
- See Also:
-
iterateNodes
- Specified by:
iterateNodesin interfaceNumberedNodeManager<ISSABasicBlock>- Returns:
- iterator of nodes with the numbers in set s
- See Also:
-
removeIncomingEdges
- Specified by:
removeIncomingEdgesin interfaceEdgeManager<ISSABasicBlock>- Throws:
UnsupportedOperationException
-
removeOutgoingEdges
- Specified by:
removeOutgoingEdgesin interfaceEdgeManager<ISSABasicBlock>- Throws:
UnsupportedOperationException
-
hasEdge
- Specified by:
hasEdgein interfaceEdgeManager<ISSABasicBlock>- Throws:
UnimplementedError
-
getSuccNodeNumbers
- Specified by:
getSuccNodeNumbersin interfaceNumberedEdgeManager<ISSABasicBlock>- Returns:
- the numbers identifying the immediate successors of node
- Throws:
IllegalArgumentException
-
getPredNodeNumbers
- Specified by:
getPredNodeNumbersin interfaceNumberedEdgeManager<ISSABasicBlock>- Returns:
- the numbers identifying the immediate predecessors of node
- Throws:
UnimplementedError
-
getBasicBlock
- Returns:
- the basic block with a particular number
-