Package com.ibm.wala.ssa
Class IR
- java.lang.Object
-
- com.ibm.wala.ssa.IR
-
- Direct Known Subclasses:
AstIRFactory.AstIR,SyntheticIR
public abstract class IR extends Object
An SSA IR. 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceIR.SSA2LocalMapA 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.
-
Constructor Summary
Constructors Modifier Constructor Description protectedIR(IMethod method, SSAInstruction[] instructions, SymbolTable symbolTable, SSACFG cfg, SSAOptions options)Simple constructor when someone else has already computed the symbol table and cfg.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description ISSABasicBlockgetBasicBlockForCatch(SSAGetCaughtExceptionInstruction instruction)Return theISSABasicBlockcorresponding to a particular catch instructionISSABasicBlockgetBasicBlockForInstruction(SSAInstruction s)This is space-inefficient.ISSABasicBlock[]getBasicBlocksForCall(CallSiteReference site)IntSetgetCallInstructionIndices(CallSiteReference site)Return the instruction indices corresponding to a call site.SSAAbstractInvokeInstruction[]getCalls(CallSiteReference site)Return the invoke instructions corresponding to a call site Note that Shrike may inline JSRS.SSACFGgetControlFlowGraph()SSACFG.BasicBlockgetExitBlock()protected abstract <T extends SSAIndirectionData.Name>
SSAIndirectionData<T>getIndirectionData()subclasses must provide information about indirect use of values, if appropriate, and otherwise nullSSAInstruction[]getInstructions()Returns the normal instructions.protected abstract IR.SSA2LocalMapgetLocalMap()subclasses must provide a source name mapping, if they want one (or null otherwise)String[]getLocalNames(int index, int vn)IMethodgetMethod()SSANewInstructiongetNew(NewSiteReference site)Return the new instruction corresponding to an allocation siteintgetNewInstructionIndex(NewSiteReference site)Return the instruction index corresponding to an allocation siteintgetNumberOfParameters()SSAOptionsgetOptions()intgetParameter(int i)TypeReferencegetParameterType(int i)Get theTypeReferencethat describes the ith parameter to this method.int[]getParameterValueNumbers()SSAInstructiongetPEI(ProgramCounter pc)SymbolTablegetSymbolTable()protected abstract StringinstructionPosition(int instructionIndex)booleanisEmptyIR()TODO: why do we need this? We should enforce instructions == null if necessary, I think.Iterator<SSAInstruction>iterateAllInstructions()Iterator<CallSiteReference>iterateCallSites()Iterator<SSAInstruction>iterateCatchInstructions()Iterator<NewSiteReference>iterateNewSites()Iterator<SSAInstruction>iterateNormalInstructions()Iterator<? extends SSAInstruction>iteratePhis()Return anIteratorof allSSAPhiInstructions for this IR.Iterator<? extends SSAInstruction>iteratePis()Return anIteratorof allSSAPiInstructions for this IR.protected voidsetupLocationMap()create mappings from call sites, new sites, and PEIs to instruction indexStringtoString()voidvisitAllInstructions(SSAInstruction.Visitor v)visit each instruction in this IRvoidvisitNormalInstructions(SSAInstruction.Visitor v)visit each normal (non-phi, non-pi, non-catch) instruction in this IR
-
-
-
Constructor Detail
-
IR
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.
-
-
Method Detail
-
getLocalMap
protected abstract IR.SSA2LocalMap getLocalMap()
subclasses must provide a source name mapping, if they want one (or null otherwise)
-
getIndirectionData
protected abstract <T extends SSAIndirectionData.Name> SSAIndirectionData<T> getIndirectionData()
subclasses must provide information about indirect use of values, if appropriate, and otherwise null
-
setupLocationMap
protected void setupLocationMap()
create mappings from call sites, new sites, and PEIs to instruction index
-
instructionPosition
protected abstract String instructionPosition(int instructionIndex)
- Returns:
- a String which is a readable representation of the instruction position corresponding to an instruction index
-
getInstructions
public SSAInstruction[] getInstructions()
Returns the normal instructions. Does not includeSSAPhiInstruction,SSAPiInstruction, orSSAGetCaughtExceptionInstructions, which are currently managed bySSACFG.BasicBlock. Entries in the returned array might be null. This may go away someday.
-
getSymbolTable
public SymbolTable getSymbolTable()
- Returns:
- the
SymbolTablemanaging attributes for values in this method
-
getControlFlowGraph
public SSACFG getControlFlowGraph()
- Returns:
- the underlying
ControlFlowGraphwhich defines this IR.
-
iteratePhis
public Iterator<? extends SSAInstruction> iteratePhis()
Return anIteratorof allSSAPhiInstructions for this IR.
-
iteratePis
public Iterator<? extends SSAInstruction> iteratePis()
Return anIteratorof allSSAPiInstructions for this IR.
-
getParameterValueNumbers
public int[] getParameterValueNumbers()
- Returns:
- array of value numbers representing parameters to this method
-
getParameter
public int getParameter(int i)
- Returns:
- the value number of the ith parameter
-
getParameterType
public TypeReference getParameterType(int i)
Get theTypeReferencethat describes the ith parameter to this method. By convention, for a non-static method, the 0th parameter is "this".
-
getNumberOfParameters
public int getNumberOfParameters()
- Returns:
- number of parameters to this method, including "this"
-
getMethod
public IMethod getMethod()
- Returns:
- the method this IR represents
-
iterateCatchInstructions
public Iterator<SSAInstruction> iterateCatchInstructions()
- Returns:
- iterator of the catch instructions in this IR
-
visitNormalInstructions
public void visitNormalInstructions(SSAInstruction.Visitor v)
visit each normal (non-phi, non-pi, non-catch) instruction in this IR
-
visitAllInstructions
public void visitAllInstructions(SSAInstruction.Visitor v)
visit each instruction in this IR
-
iterateNormalInstructions
public Iterator<SSAInstruction> iterateNormalInstructions()
- Returns:
- an
Iteratorof all "normal" instructions on this IR
-
iterateAllInstructions
public Iterator<SSAInstruction> iterateAllInstructions()
- Returns:
- an
Iteratorof all instructions (Normal, Phi, and Catch)
-
getExitBlock
public SSACFG.BasicBlock getExitBlock()
- Returns:
- the exit basic block
-
getCalls
public SSAAbstractInvokeInstruction[] getCalls(CallSiteReference site)
Return the invoke instructions corresponding to a call 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.
-
getCallInstructionIndices
public IntSet getCallInstructionIndices(CallSiteReference site)
Return the instruction indices corresponding to a call 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.
-
getNew
public SSANewInstruction getNew(NewSiteReference site)
Return the new instruction corresponding to an allocation site
-
getNewInstructionIndex
public int getNewInstructionIndex(NewSiteReference site)
Return the instruction index corresponding to an allocation site
-
getPEI
public SSAInstruction getPEI(ProgramCounter pc)
- Parameters:
pc- a program counter- Returns:
- the instruction (a PEI) at this program counter
-
iterateNewSites
public Iterator<NewSiteReference> iterateNewSites()
- Returns:
- an
Iteratorof all the allocation sites (NewSiteReferences ) in this IR
-
iterateCallSites
public Iterator<CallSiteReference> iterateCallSites()
- Returns:
- an
Iteratorof all the call sites (CallSiteReferences ) in this IR
-
getBasicBlocksForCall
public ISSABasicBlock[] getBasicBlocksForCall(CallSiteReference site)
- Parameters:
site- a call site in this method- Returns:
- the basic block corresponding to this instruction
- Throws:
IllegalArgumentException- if site is null
-
getBasicBlockForInstruction
public ISSABasicBlock getBasicBlockForInstruction(SSAInstruction s)
This is space-inefficient. Use with care. Be very careful; note the strange identity semantics of SSAInstruction, using ==. You can't mix SSAInstructions and IRs freely.
-
isEmptyIR
public boolean isEmptyIR()
TODO: why do we need this? We should enforce instructions == null if necessary, I think.- Returns:
- true iff every instruction is null
-
getLocalNames
public String[] getLocalNames(int index, int vn)
- Parameters:
index- an index into the IR instruction arrayvn- a value number- Returns:
- if we know that immediately after the given program counter, v_vn corresponds to one or more locals and local variable names are available, the name of the locals which v_vn represents. Otherwise, null.
-
getBasicBlockForCatch
public ISSABasicBlock getBasicBlockForCatch(SSAGetCaughtExceptionInstruction instruction)
Return theISSABasicBlockcorresponding to a particular catch instruction
-
getOptions
public SSAOptions getOptions()
- Returns:
- the
SSAOptionswhich controlled how thisIRwas built
-
-