public abstract class IR extends java.lang.Object implements IRView
The IR (Intermediate Representation) is the central data structure that represents the instructions of a particular method. The IR represents a method's instructions in a language close to JVM bytecode, but in an SSA-based register transfer language which eliminates the stack abstraction, relying instead on a set of symbolic registers. The IR organizes instructions in a control-flow graph of basic blocks, as typical in compiler textbooks.
See http://wala.sourceforge.net/wiki/index.php/UserGuide:IR for more details on the IR API.
| Modifier and Type | Class and Description |
|---|---|
static interface |
IR.SSA2LocalMap
A Map that gives the names of the local variables corresponding to SSA value numbers at
particular IR instruction indices, if such information is available from source code mapping.
|
| Modifier | Constructor and Description |
|---|---|
protected |
IR(IMethod method,
SSAInstruction[] instructions,
SymbolTable symbolTable,
SSACFG cfg,
SSAOptions options)
Simple constructor when someone else has already computed the symbol table and cfg.
|
| Modifier and Type | Method and Description |
|---|---|
ISSABasicBlock |
getBasicBlockForCatch(SSAGetCaughtExceptionInstruction instruction)
Return the
ISSABasicBlock corresponding to a particular catch instruction |
ISSABasicBlock |
getBasicBlockForInstruction(SSAInstruction s)
This is space-inefficient.
|
ISSABasicBlock[] |
getBasicBlocksForCall(CallSiteReference site) |
java.util.Iterator<ISSABasicBlock> |
getBlocks() |
com.ibm.wala.util.intset.IntSet |
getCallInstructionIndices(CallSiteReference site)
Return the instruction indices corresponding to a call site.
|
SSAAbstractInvokeInstruction[] |
getCalls(CallSiteReference site)
Return the invoke instructions corresponding to a call site
|
SSACFG |
getControlFlowGraph() |
SSACFG.BasicBlock |
getExitBlock() |
protected abstract <T extends SSAIndirectionData.Name> |
getIndirectionData()
subclasses must provide information about indirect use of values, if appropriate, and otherwise
null
|
SSAInstruction[] |
getInstructions()
Returns the normal instructions.
|
protected abstract IR.SSA2LocalMap |
getLocalMap()
subclasses must provide a source name mapping, if they want one (or null otherwise)
|
java.lang.String[] |
getLocalNames(int index,
int vn) |
IMethod |
getMethod() |
SSANewInstruction |
getNew(NewSiteReference site)
Return the new instruction corresponding to an allocation site
|
int |
getNewInstructionIndex(NewSiteReference site)
Return the instruction index corresponding to an allocation site
|
int |
getNumberOfParameters() |
SSAOptions |
getOptions() |
int |
getParameter(int i) |
TypeReference |
getParameterType(int i)
Get the
TypeReference that describes the ith parameter to this method. |
int[] |
getParameterValueNumbers() |
SSAInstruction |
getPEI(ProgramCounter pc) |
SymbolTable |
getSymbolTable() |
protected abstract java.lang.String |
instructionPosition(int instructionIndex) |
boolean |
isEmptyIR()
TODO: why do we need this? We should enforce instructions == null if necessary, I think.
|
java.util.Iterator<SSAInstruction> |
iterateAllInstructions() |
java.util.Iterator<CallSiteReference> |
iterateCallSites() |
java.util.Iterator<SSAInstruction> |
iterateCatchInstructions() |
java.util.Iterator<NewSiteReference> |
iterateNewSites() |
java.util.Iterator<SSAInstruction> |
iterateNormalInstructions() |
java.util.Iterator<? extends SSAInstruction> |
iteratePhis()
Return an
Iterator of all SSAPhiInstructions for this IR. |
java.util.Iterator<? extends SSAInstruction> |
iteratePis()
Return an
Iterator of all SSAPiInstructions for this IR. |
protected void |
setupLocationMap()
create mappings from call sites, new sites, and PEIs to instruction index
|
java.lang.String |
toString() |
void |
visitAllInstructions(SSAInstruction.IVisitor v)
visit each instruction in this IR
|
void |
visitNormalInstructions(SSAInstruction.IVisitor v)
visit each normal (non-phi, non-pi, non-catch) instruction in this IR
|
protected IR(IMethod method, SSAInstruction[] instructions, SymbolTable symbolTable, SSACFG cfg, SSAOptions options)
protected abstract IR.SSA2LocalMap getLocalMap()
protected abstract <T extends SSAIndirectionData.Name> SSAIndirectionData<T> getIndirectionData()
protected void setupLocationMap()
protected abstract java.lang.String instructionPosition(int instructionIndex)
public java.lang.String toString()
toString in class java.lang.Objectpublic SSAInstruction[] getInstructions()
SSAPhiInstruction, SSAPiInstruction, or SSAGetCaughtExceptionInstructions, which are currently managed by
SSACFG.BasicBlock. Entries in the returned array might be null.
This may go away someday.
getInstructions in interface IRViewpublic SymbolTable getSymbolTable()
getSymbolTable in interface IRViewSymbolTable managing attributes for values in this methodpublic SSACFG getControlFlowGraph()
getControlFlowGraph in interface IRViewControlFlowGraph which defines this IR.public java.util.Iterator<ISSABasicBlock> getBlocks()
public java.util.Iterator<? extends SSAInstruction> iteratePhis()
Iterator of all SSAPhiInstructions for this IR.public java.util.Iterator<? extends SSAInstruction> iteratePis()
Iterator of all SSAPiInstructions for this IR.public int[] getParameterValueNumbers()
public int getParameter(int i)
public TypeReference getParameterType(int i)
TypeReference that describes the ith parameter to this method. By convention,
for a non-static method, the 0th parameter is "this".public int getNumberOfParameters()
public IMethod getMethod()
public java.util.Iterator<SSAInstruction> iterateCatchInstructions()
public void visitNormalInstructions(SSAInstruction.IVisitor v)
public void visitAllInstructions(SSAInstruction.IVisitor v)
public java.util.Iterator<SSAInstruction> iterateNormalInstructions()
Iterator of all "normal" instructions on this IRpublic java.util.Iterator<SSAInstruction> iterateAllInstructions()
Iterator of all instructions (Normal, Phi, and Catch)public SSACFG.BasicBlock getExitBlock()
getExitBlock in interface IRViewpublic SSAAbstractInvokeInstruction[] getCalls(CallSiteReference site)
Note that Shrike may inline JSRS. This can lead to multiple copies of a single bytecode instruction in a particular IR. So we may have more than one instruction index for a particular call site from bytecode.
public com.ibm.wala.util.intset.IntSet getCallInstructionIndices(CallSiteReference site)
Note that Shrike may inline JSRS. This can lead to multiple copies of a single bytecode instruction in a particular IR. So we may have more than one instruction index for a particular call site from bytecode.
public SSANewInstruction getNew(NewSiteReference site)
public int getNewInstructionIndex(NewSiteReference site)
public SSAInstruction getPEI(ProgramCounter pc)
public java.util.Iterator<NewSiteReference> iterateNewSites()
iterateNewSites in interface IRViewIterator of all the allocation sites ( NewSiteReferences ) in this
IRpublic java.util.Iterator<CallSiteReference> iterateCallSites()
iterateCallSites in interface IRViewIterator of all the call sites ( CallSiteReferences ) in this IRpublic ISSABasicBlock[] getBasicBlocksForCall(CallSiteReference site)
getBasicBlocksForCall in interface IRViewsite - a call site in this methodjava.lang.IllegalArgumentException - if site is nullpublic ISSABasicBlock getBasicBlockForInstruction(SSAInstruction s)
Be very careful; note the strange identity semantics of SSAInstruction, using ==. You can't mix SSAInstructions and IRs freely.
public boolean isEmptyIR()
public java.lang.String[] getLocalNames(int index,
int vn)
getLocalNames in interface IRViewindex - an index into the IR instruction arrayvn - a value numberpublic ISSABasicBlock getBasicBlockForCatch(SSAGetCaughtExceptionInstruction instruction)
ISSABasicBlock corresponding to a particular catch instructionpublic SSAOptions getOptions()
SSAOptions which controlled how this IR was built