Class SSACFG
- java.lang.Object
-
- com.ibm.wala.ssa.SSACFG
-
- All Implemented Interfaces:
ControlFlowGraph<SSAInstruction,ISSABasicBlock>
,MinimalCFG<ISSABasicBlock>
,com.ibm.wala.util.graph.EdgeManager<ISSABasicBlock>
,com.ibm.wala.util.graph.Graph<ISSABasicBlock>
,com.ibm.wala.util.graph.NodeManager<ISSABasicBlock>
,com.ibm.wala.util.graph.NumberedEdgeManager<ISSABasicBlock>
,com.ibm.wala.util.graph.NumberedGraph<ISSABasicBlock>
,com.ibm.wala.util.graph.NumberedNodeManager<ISSABasicBlock>
,java.lang.Iterable<ISSABasicBlock>
public class SSACFG extends java.lang.Object implements ControlFlowGraph<SSAInstruction,ISSABasicBlock>, MinimalCFG<ISSABasicBlock>
A control-flow graph for ssa form.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 whereIR
s and related structures were long-lived. In today's system, they are cached and reconstituted bySSACache
. Perhaps we should just extendAbstractCFG
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.BasicBlock
s and theSSAInstruction
array.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
SSACFG.BasicBlock
A Basic Block in an SSA IRclass
SSACFG.ExceptionHandlerBasicBlock
-
Field Summary
Fields Modifier and Type Field Description protected AbstractCFG<com.ibm.wala.shrike.shrikeBT.IInstruction,IBasicBlock<com.ibm.wala.shrike.shrikeBT.IInstruction>>
delegate
A delegate CFG, pre-built, which stores the graph structure of this CFG.protected SSAInstruction[]
instructions
The "normal" instructions which constitute the SSA form.protected IMethod
method
TheIMethod
thisControlFlowGraph
represents
-
Constructor Summary
Constructors Constructor Description SSACFG(IMethod method, AbstractCFG cfg, SSAInstruction[] instructions)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addEdge(ISSABasicBlock src, ISSABasicBlock dst)
void
addNode(ISSABasicBlock n)
boolean
containsNode(ISSABasicBlock N)
SSACFG.BasicBlock
entry()
Return the entry basic block in the CFGboolean
equals(java.lang.Object o)
SSACFG.BasicBlock
exit()
SSACFG.BasicBlock
getBasicBlock(int bb)
SSACFG.BasicBlock
getBlockForInstruction(int instructionIndex)
Get the basic block an instruction belongs to.com.ibm.wala.util.intset.BitVector
getCatchBlocks()
java.util.Collection<ISSABasicBlock>
getExceptionalPredecessors(ISSABasicBlock b)
The order of blocks returned should be arbitrary but deterministic.java.util.List<ISSABasicBlock>
getExceptionalSuccessors(ISSABasicBlock b)
The order of blocks returned must indicate the exception-handling scope.SSAInstruction[]
getInstructions()
NB: Use iterators such as IR.iterateAllInstructions() instead of this method.int
getMaxNumber()
IMethod
getMethod()
SSACFG.BasicBlock
getNode(int number)
java.util.Collection<ISSABasicBlock>
getNormalPredecessors(ISSABasicBlock b)
The order of blocks returned should be arbitrary but deterministic.java.util.Collection<ISSABasicBlock>
getNormalSuccessors(ISSABasicBlock b)
The order of blocks returned should be arbitrary but deterministic.int
getNumber(ISSABasicBlock b)
int
getNumberOfNodes()
int
getPredNodeCount(ISSABasicBlock b)
com.ibm.wala.util.intset.IntSet
getPredNodeNumbers(ISSABasicBlock node)
java.util.Iterator<ISSABasicBlock>
getPredNodes(ISSABasicBlock b)
int
getProgramCounter(int index)
TODO: move this into IR?int
getSuccNodeCount(ISSABasicBlock b)
com.ibm.wala.util.intset.IntSet
getSuccNodeNumbers(ISSABasicBlock b)
java.util.Iterator<ISSABasicBlock>
getSuccNodes(ISSABasicBlock b)
boolean
hasEdge(ISSABasicBlock src, ISSABasicBlock dst)
boolean
hasExceptionalEdge(SSACFG.BasicBlock src, SSACFG.BasicBlock dest)
has exceptional edge src -> destint
hashCode()
boolean
hasNormalEdge(SSACFG.BasicBlock src, SSACFG.BasicBlock dest)
has normal edge src -> destboolean
isCatchBlock(int i)
is the given i a catch block?java.util.Iterator<ISSABasicBlock>
iterateNodes(com.ibm.wala.util.intset.IntSet s)
java.util.Iterator<ISSABasicBlock>
iterator()
void
removeAllIncidentEdges(ISSABasicBlock node)
void
removeEdge(ISSABasicBlock src, ISSABasicBlock dst)
void
removeIncomingEdges(ISSABasicBlock node)
void
removeNode(ISSABasicBlock n)
void
removeNodeAndEdges(ISSABasicBlock N)
void
removeOutgoingEdges(ISSABasicBlock node)
java.util.stream.Stream<ISSABasicBlock>
stream()
java.lang.String
toString()
-
-
-
Field Detail
-
instructions
protected final SSAInstruction[] instructions
The "normal" instructions which constitute the SSA form. This does not includeSSAPhiInstruction
s, which dwell inSSACFG.BasicBlock
s instead.
-
method
protected final IMethod method
TheIMethod
thisControlFlowGraph
represents
-
delegate
protected final AbstractCFG<com.ibm.wala.shrike.shrikeBT.IInstruction,IBasicBlock<com.ibm.wala.shrike.shrikeBT.IInstruction>> delegate
A delegate CFG, pre-built, which stores the graph structure of this CFG.
-
-
Constructor Detail
-
SSACFG
public SSACFG(IMethod method, AbstractCFG cfg, SSAInstruction[] instructions)
- Throws:
java.lang.IllegalArgumentException
- if method is null
-
-
Method Detail
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
getBlockForInstruction
public SSACFG.BasicBlock getBlockForInstruction(int instructionIndex)
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:
getBlockForInstruction
in interfaceControlFlowGraph<SSAInstruction,ISSABasicBlock>
- Parameters:
instructionIndex
- an instruction index- Returns:
- the basic block which contains this instruction.
-
getInstructions
public SSAInstruction[] 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:
getInstructions
in interfaceControlFlowGraph<SSAInstruction,ISSABasicBlock>
- Returns:
- an array containing the SSA instructions.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getCatchBlocks
public com.ibm.wala.util.intset.BitVector getCatchBlocks()
- Specified by:
getCatchBlocks
in 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
public SSACFG.BasicBlock entry()
Description copied from interface:MinimalCFG
Return the entry basic block in the CFG- Specified by:
entry
in interfaceMinimalCFG<ISSABasicBlock>
-
exit
public SSACFG.BasicBlock exit()
- Specified by:
exit
in interfaceMinimalCFG<ISSABasicBlock>
- Returns:
- the synthetic exit block for the cfg
-
getNumber
public int getNumber(ISSABasicBlock b) throws java.lang.IllegalArgumentException
- Specified by:
getNumber
in interfacecom.ibm.wala.util.graph.NumberedNodeManager<ISSABasicBlock>
- Throws:
java.lang.IllegalArgumentException
-
getNode
public SSACFG.BasicBlock getNode(int number)
- Specified by:
getNode
in interfacecom.ibm.wala.util.graph.NumberedNodeManager<ISSABasicBlock>
- See Also:
NumberedNodeManager.getNode(int)
-
getMaxNumber
public int getMaxNumber()
- Specified by:
getMaxNumber
in interfacecom.ibm.wala.util.graph.NumberedNodeManager<ISSABasicBlock>
- See Also:
NumberedNodeManager.getMaxNumber()
-
iterator
public java.util.Iterator<ISSABasicBlock> iterator()
- Specified by:
iterator
in interfacejava.lang.Iterable<ISSABasicBlock>
- Specified by:
iterator
in interfacecom.ibm.wala.util.graph.NodeManager<ISSABasicBlock>
- See Also:
NodeManager.iterator()
-
stream
public java.util.stream.Stream<ISSABasicBlock> stream()
- Specified by:
stream
in interfacecom.ibm.wala.util.graph.NodeManager<ISSABasicBlock>
-
getNumberOfNodes
public int getNumberOfNodes()
- Specified by:
getNumberOfNodes
in interfacecom.ibm.wala.util.graph.NodeManager<ISSABasicBlock>
- See Also:
NodeManager.getNumberOfNodes()
-
getPredNodes
public java.util.Iterator<ISSABasicBlock> getPredNodes(ISSABasicBlock b) throws java.lang.IllegalArgumentException
- Specified by:
getPredNodes
in interfacecom.ibm.wala.util.graph.EdgeManager<ISSABasicBlock>
- Throws:
java.lang.IllegalArgumentException
- See Also:
EdgeManager.getPredNodes(Object)
-
getPredNodeCount
public int getPredNodeCount(ISSABasicBlock b) throws java.lang.IllegalArgumentException
- Specified by:
getPredNodeCount
in interfacecom.ibm.wala.util.graph.EdgeManager<ISSABasicBlock>
- Throws:
java.lang.IllegalArgumentException
- See Also:
EdgeManager.getPredNodeCount(Object)
-
getSuccNodes
public java.util.Iterator<ISSABasicBlock> getSuccNodes(ISSABasicBlock b) throws java.lang.IllegalArgumentException
- Specified by:
getSuccNodes
in interfacecom.ibm.wala.util.graph.EdgeManager<ISSABasicBlock>
- Throws:
java.lang.IllegalArgumentException
- See Also:
EdgeManager.getSuccNodes(Object)
-
getSuccNodeCount
public int getSuccNodeCount(ISSABasicBlock b) throws java.lang.IllegalArgumentException
- Specified by:
getSuccNodeCount
in interfacecom.ibm.wala.util.graph.EdgeManager<ISSABasicBlock>
- Throws:
java.lang.IllegalArgumentException
- See Also:
EdgeManager.getSuccNodeCount(Object)
-
addNode
public void addNode(ISSABasicBlock n) throws java.lang.UnsupportedOperationException
- Specified by:
addNode
in interfacecom.ibm.wala.util.graph.NodeManager<ISSABasicBlock>
- Throws:
java.lang.UnsupportedOperationException
- See Also:
NodeManager.addNode(Object)
-
addEdge
public void addEdge(ISSABasicBlock src, ISSABasicBlock dst) throws java.lang.UnsupportedOperationException
- Specified by:
addEdge
in interfacecom.ibm.wala.util.graph.EdgeManager<ISSABasicBlock>
- Throws:
java.lang.UnsupportedOperationException
-
removeEdge
public void removeEdge(ISSABasicBlock src, ISSABasicBlock dst) throws java.lang.UnsupportedOperationException
- Specified by:
removeEdge
in interfacecom.ibm.wala.util.graph.EdgeManager<ISSABasicBlock>
- Throws:
java.lang.UnsupportedOperationException
-
removeAllIncidentEdges
public void removeAllIncidentEdges(ISSABasicBlock node) throws java.lang.UnsupportedOperationException
- Specified by:
removeAllIncidentEdges
in interfacecom.ibm.wala.util.graph.EdgeManager<ISSABasicBlock>
- Throws:
java.lang.UnsupportedOperationException
- See Also:
EdgeManager.removeAllIncidentEdges(Object)
-
removeNodeAndEdges
public void removeNodeAndEdges(ISSABasicBlock N) throws java.lang.UnsupportedOperationException
- Specified by:
removeNodeAndEdges
in interfacecom.ibm.wala.util.graph.Graph<ISSABasicBlock>
- Throws:
java.lang.UnsupportedOperationException
- See Also:
NodeManager.removeNode(Object)
-
removeNode
public void removeNode(ISSABasicBlock n) throws java.lang.UnsupportedOperationException
- Specified by:
removeNode
in interfacecom.ibm.wala.util.graph.NodeManager<ISSABasicBlock>
- Throws:
java.lang.UnsupportedOperationException
- See Also:
NodeManager.removeNode(Object)
-
getProgramCounter
public int getProgramCounter(int index)
Description copied from interface:ControlFlowGraph
TODO: move this into IR?- Specified by:
getProgramCounter
in interfaceControlFlowGraph<SSAInstruction,ISSABasicBlock>
- Parameters:
index
- an instruction index- Returns:
- the program counter (bytecode index) corresponding to that instruction
-
containsNode
public boolean containsNode(ISSABasicBlock N)
- Specified by:
containsNode
in interfacecom.ibm.wala.util.graph.NodeManager<ISSABasicBlock>
- See Also:
NodeManager.containsNode(Object)
-
getMethod
public IMethod getMethod()
- Specified by:
getMethod
in interfaceControlFlowGraph<SSAInstruction,ISSABasicBlock>
- Returns:
- the Method this CFG represents
-
getExceptionalSuccessors
public java.util.List<ISSABasicBlock> getExceptionalSuccessors(ISSABasicBlock b)
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 interfaceMinimalCFG<ISSABasicBlock>
- Returns:
- the basic blocks which may be reached from b via exceptional control flow
-
getExceptionalPredecessors
public java.util.Collection<ISSABasicBlock> getExceptionalPredecessors(ISSABasicBlock b)
Description copied from interface:MinimalCFG
The order of blocks returned should be arbitrary but deterministic.- Specified by:
getExceptionalPredecessors
in interfaceMinimalCFG<ISSABasicBlock>
- Returns:
- the basic blocks from which b may be reached via exceptional control flow
- See Also:
MinimalCFG.getExceptionalSuccessors(Object)
-
hasExceptionalEdge
public boolean hasExceptionalEdge(SSACFG.BasicBlock src, SSACFG.BasicBlock dest)
has exceptional edge src -> dest- Throws:
java.lang.IllegalArgumentException
- if dest is null
-
hasNormalEdge
public boolean hasNormalEdge(SSACFG.BasicBlock src, SSACFG.BasicBlock dest)
has normal edge src -> dest- Throws:
java.lang.IllegalArgumentException
- if dest is null
-
getNormalSuccessors
public java.util.Collection<ISSABasicBlock> getNormalSuccessors(ISSABasicBlock b)
Description copied from interface:MinimalCFG
The order of blocks returned should be arbitrary but deterministic.- Specified by:
getNormalSuccessors
in interfaceMinimalCFG<ISSABasicBlock>
- Returns:
- the basic blocks which may be reached from b via normal control flow
-
getNormalPredecessors
public java.util.Collection<ISSABasicBlock> getNormalPredecessors(ISSABasicBlock b)
Description copied from interface:MinimalCFG
The order of blocks returned should be arbitrary but deterministic.- Specified by:
getNormalPredecessors
in interfaceMinimalCFG<ISSABasicBlock>
- Returns:
- the basic blocks from which b may be reached via normal control flow
- See Also:
MinimalCFG.getNormalSuccessors(Object)
-
iterateNodes
public java.util.Iterator<ISSABasicBlock> iterateNodes(com.ibm.wala.util.intset.IntSet s)
- Specified by:
iterateNodes
in interfacecom.ibm.wala.util.graph.NumberedNodeManager<ISSABasicBlock>
- See Also:
NumberedNodeManager.iterateNodes(com.ibm.wala.util.intset.IntSet)
-
removeIncomingEdges
public void removeIncomingEdges(ISSABasicBlock node) throws java.lang.UnsupportedOperationException
- Specified by:
removeIncomingEdges
in interfacecom.ibm.wala.util.graph.EdgeManager<ISSABasicBlock>
- Throws:
java.lang.UnsupportedOperationException
-
removeOutgoingEdges
public void removeOutgoingEdges(ISSABasicBlock node) throws java.lang.UnsupportedOperationException
- Specified by:
removeOutgoingEdges
in interfacecom.ibm.wala.util.graph.EdgeManager<ISSABasicBlock>
- Throws:
java.lang.UnsupportedOperationException
-
hasEdge
public boolean hasEdge(ISSABasicBlock src, ISSABasicBlock dst) throws com.ibm.wala.util.debug.UnimplementedError
- Specified by:
hasEdge
in interfacecom.ibm.wala.util.graph.EdgeManager<ISSABasicBlock>
- Throws:
com.ibm.wala.util.debug.UnimplementedError
-
getSuccNodeNumbers
public com.ibm.wala.util.intset.IntSet getSuccNodeNumbers(ISSABasicBlock b) throws java.lang.IllegalArgumentException
- Specified by:
getSuccNodeNumbers
in interfacecom.ibm.wala.util.graph.NumberedEdgeManager<ISSABasicBlock>
- Throws:
java.lang.IllegalArgumentException
-
getPredNodeNumbers
public com.ibm.wala.util.intset.IntSet getPredNodeNumbers(ISSABasicBlock node) throws com.ibm.wala.util.debug.UnimplementedError
- Specified by:
getPredNodeNumbers
in interfacecom.ibm.wala.util.graph.NumberedEdgeManager<ISSABasicBlock>
- Throws:
com.ibm.wala.util.debug.UnimplementedError
-
getBasicBlock
public SSACFG.BasicBlock getBasicBlock(int bb)
- Returns:
- the basic block with a particular number
-
-