Class IR
- All Implemented Interfaces:
IRView
- Direct Known Subclasses:
AstIRFactory.AstIR
,SyntheticIR
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.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
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. -
Constructor Summary
ModifierConstructorDescriptionprotected
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 Summary
Modifier and TypeMethodDescriptiongetBasicBlockForCatch
(SSAGetCaughtExceptionInstruction instruction) Return theISSABasicBlock
corresponding to a particular catch instructionThis is space-inefficient.Return the instruction indices corresponding to a call site.getCalls
(CallSiteReference site) Return the invoke instructions corresponding to a call siteprotected abstract <T extends SSAIndirectionData.Name>
SSAIndirectionData<T> subclasses must provide information about indirect use of values, if appropriate, and otherwise nullReturns the normal instructions.protected abstract IR.SSA2LocalMap
subclasses must provide a source name mapping, if they want one (or null otherwise)String[]
getLocalNames
(int index, int vn) getNew
(NewSiteReference site) Return the new instruction corresponding to an allocation siteint
Return the instruction index corresponding to an allocation siteint
int
getParameter
(int i) getParameterType
(int i) Get theTypeReference
that describes the ith parameter to this method.int[]
getPEI
(ProgramCounter pc) protected abstract String
instructionPosition
(int instructionIndex) boolean
TODO: why do we need this? We should enforce instructions == null if necessary, I think.Iterator
<? extends SSAInstruction> Return anIterator
of allSSAPhiInstruction
s for this IR.Iterator
<? extends SSAInstruction> Return anIterator
of allSSAPiInstruction
s for this IR.protected void
create mappings from call sites, new sites, and PEIs to instruction indextoString()
void
visit each instruction in this IRvoid
visit each normal (non-phi, non-pi, non-catch) instruction in this IR
-
Constructor Details
-
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 Details
-
getLocalMap
subclasses must provide a source name mapping, if they want one (or null otherwise) -
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
- Returns:
- a String which is a readable representation of the instruction position corresponding to an instruction index
-
toString
-
getInstructions
Returns the normal instructions. Does not includeSSAPhiInstruction
,SSAPiInstruction
, orSSAGetCaughtExceptionInstruction
s, which are currently managed bySSACFG.BasicBlock
. Entries in the returned array might be null.This may go away someday.
- Specified by:
getInstructions
in interfaceIRView
-
getSymbolTable
- Specified by:
getSymbolTable
in interfaceIRView
- Returns:
- the
SymbolTable
managing attributes for values in this method
-
getControlFlowGraph
- Specified by:
getControlFlowGraph
in interfaceIRView
- Returns:
- the underlying
ControlFlowGraph
which defines this IR.
-
getBlocks
-
iteratePhis
Return anIterator
of allSSAPhiInstruction
s for this IR. -
iteratePis
Return anIterator
of allSSAPiInstruction
s 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
Get theTypeReference
that 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
-
iterateCatchInstructions
- Returns:
- iterator of the catch instructions in this IR
-
visitNormalInstructions
visit each normal (non-phi, non-pi, non-catch) instruction in this IR -
visitAllInstructions
visit each instruction in this IR -
iterateNormalInstructions
- Returns:
- an
Iterator
of all "normal" instructions on this IR
-
iterateAllInstructions
- Returns:
- an
Iterator
of all instructions (Normal, Phi, and Catch)
-
getExitBlock
- Specified by:
getExitBlock
in interfaceIRView
- Returns:
- the exit basic block
-
getCalls
Return the invoke instructions corresponding to a call siteNote 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
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
Return the new instruction corresponding to an allocation site -
getNewInstructionIndex
Return the instruction index corresponding to an allocation site -
getPEI
-
iterateNewSites
- Specified by:
iterateNewSites
in interfaceIRView
- Returns:
- an
Iterator
of all the allocation sites (NewSiteReference
s ) in this IR
-
iterateCallSites
- Specified by:
iterateCallSites
in interfaceIRView
- Returns:
- an
Iterator
of all the call sites (CallSiteReference
s ) in this IR
-
getBasicBlocksForCall
- Specified by:
getBasicBlocksForCall
in interfaceIRView
- Parameters:
site
- a call site in this method- Returns:
- the basic block corresponding to this instruction
- Throws:
IllegalArgumentException
- if site is null
-
getBasicBlockForInstruction
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
- Specified by:
getLocalNames
in interfaceIRView
- 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
Return theISSABasicBlock
corresponding to a particular catch instruction -
getOptions
- Returns:
- the
SSAOptions
which controlled how thisIR
was built
-