public final class IR extends Object
IR
object (IR is short for Intermediate Representation)
contains all the per-compilation information associated with
a method that is being compiled.
IR
objects are intended to be transitory.
They are created to compile a particular method under a
given compilation plan
and are discarded once the compilation plan has been completed.
The primary component of the IR is the
FCFG
(factored control flow graph)
The FCFG contains
intermediate language instructions
grouped into factored basic blocks
.
In addition to the FCFG, an IR
object also
contains a variety of other supporting and derived data structures.
ControlFlowGraph
,
BasicBlock
,
Instruction
,
Operator
,
Operand
Modifier and Type | Class and Description |
---|---|
private static class |
IR.BitSetBBEnum |
Modifier and Type | Field and Description |
---|---|
SSAOptions |
actualSSAOptions
Options that define the SSA properties
currently carried by the IR. |
private BasicBlock[] |
basicBlockMap
Backing store for
getBasicBlock(int) . |
ControlFlowGraph |
cfg
The
FCFG (Factored Control Flow Graph) |
OptCompiledMethod |
compiledMethod
The compiled method created to hold the result of this compilation.
|
SSAOptions |
desiredSSAOptions
Options that define the SSA properties
desired the next time we enter SSA form. |
private Dominators |
dominators
Information about dominators as used for global code placement
during SSA.
|
GenerationContext |
gc
The root
generation context
for the current compilation. |
private boolean |
handlerLivenessComputed
Was liveness for handlers computed?
|
private boolean |
hasSysCall
Does this IR include a syscall?
|
static byte |
HIR
Part of an enumerated type used to encode IR Level
|
HIRInfo |
HIRInfo
Pointer to the HIRInfo for this method.
|
InlineOracle |
inlinePlan
The
inlining oracle to be used for the
current compilation. |
InstrumentationPlan |
instrumentationPlan
Information specifying what instrumentation should be performed
during compilation of this method.
|
byte |
IRStage
The IR is tagged to identify its level (stage).
|
static byte |
LIR
Part of an enumerated type used to encode IR Level
|
LIRInfo |
LIRInfo
Pointer to the LIRInfo for this method.
|
private LiveInterval |
livenessInformation
Information about liveness,
null if not yet computed. |
private LTDominators |
ltDominators
Information about dominators as used for leaving SSA form.
|
NormalMethod |
method
The
NormalMethod object corresponding to the
method being compiled. |
static byte |
MIR
Part of an enumerated type used to encode IR Level
|
MIRInfo |
MIRInfo
Pointer to the MIRInfo for this method.
|
OptOptions |
options
The compiler
options that apply
to the current compilation. |
TypeReference[] |
params
The specialized parameters to be used in place of those defined
in the NormalMethod.
|
static boolean |
PARANOID
Control for (dynamic) IR invariant checking.
|
GenericRegisterPool |
regpool
The
register pool |
static boolean |
SANITY_CHECK
Control for (dynamic) IR invariant checking.
|
GenericStackManager |
stackManager
The
stack manager . |
static byte |
UNFORMED
Part of an enumerated type used to encode IR Level
|
Constructor and Description |
---|
IR(NormalMethod m,
CompilationPlan cp) |
IR(NormalMethod m,
InlineOracle ip,
OptOptions opts) |
Modifier and Type | Method and Description |
---|---|
int |
countInstructions()
Counts all the instructions currently in this IR.
|
BasicBlock |
firstBasicBlockInCodeOrder()
Return the first basic block with respect to
the current code linearization order.
|
Instruction |
firstInstructionInCodeOrder()
Return the first instruction with respect to
the current code linearization order.
|
Enumeration<BasicBlock> |
forwardBlockEnumerator()
Forward (with respect to the current code linearization order)
iteration overal all the basic blocks in the IR.
|
Enumeration<Instruction> |
forwardInstrEnumerator()
Forward (with respect to the current code linearization order)
iteration over all the instructions in this IR.
|
BasicBlock |
getBasicBlock(int number)
Get the basic block with a given number.
|
Enumeration<BasicBlock> |
getBasicBlocks()
Enumerate the basic blocks in the IR in an arbitrary order.
|
Enumeration<BasicBlock> |
getBasicBlocks(BitVector bits)
Get an enumeration of all the basic blocks whose numbers
appear in the given BitSet.
|
Dominators |
getDominators() |
boolean |
getHandlerLivenessComputed() |
LiveInterval |
getLivenessInformation() |
LTDominators |
getLtDominators() |
int |
getMaxBasicBlockNumber() |
NormalMethod |
getMethod() |
int |
getNumberOfSymbolicRegisters()
Returns the number of symbolic registers for this IR.
|
Enumeration<Operand> |
getParameters()
Return an enumeration of the parameters to the IR
Warning: Only valid before register allocation (see CallingConvention)
|
private Object |
getVariableDef(String where,
Operand operand)
Get the variable defined by this operand
|
private Object |
getVariableUse(String where,
Operand operand)
Get the variable used by this operand
|
boolean |
hasReachableExceptionHandlers() |
boolean |
hasSysCall() |
int |
incomingParameterBytes()
How many bytes of parameters does this method take?
|
boolean |
inSSAForm() |
boolean |
inSSAFormAwaitingReEntry() |
boolean |
isParameter(Operand op)
Is the operand a parameter of the IR?
|
BasicBlock |
lastBasicBlockInCodeOrder()
Return the last basic block with respect to
the current code linearization order.
|
Instruction |
lastInstructionInCodeOrder()
Return the last instruction with respect to
the current code linearization order.
|
Map<Instruction,Integer> |
numberInstructionsViaMap()
Densely numbers all the instructions currently in this IR
from 0...numInstr-1.
|
void |
printInstructions()
Print the instructions in this IR to System.out.
|
void |
pruneExceptionalOut()
Prune the exceptional out edges for each basic block in the IR.
|
void |
resetBasicBlockMap()
Recompute the basic block map, so can use getBasicBlock(int)
to index into the basic blocks quickly.
|
Enumeration<BasicBlock> |
reverseBlockEnumerator()
Reverse (with respect to the current code linearization order)
iteration overal all the basic blocks in the IR.
|
Enumeration<Instruction> |
reverseInstrEnumerator()
Reverse (with respect to the current code linearization order)
iteration over all the instructions in this IR.
|
void |
setDominators(Dominators dominators) |
void |
setHandlerLivenessComputed(boolean value) |
void |
setHasSysCall(boolean b) |
void |
setLivenessInformation(LiveInterval liveInterval) |
void |
setLtDominators(LTDominators ltDominators) |
static boolean |
strictFP(Instruction... is)
Should
strictfp be adhered to for the given instructions? |
void |
unfactor()
Partially convert the FCFG into a more traditional
CFG by splitting all nodes that contain PEIs and that
have reachable exception handlers into multiple basic
blocks such that the instructions in the block have
the expected post-dominance relationship.
|
void |
verify(String where)
Verify that the IR is well-formed.
|
void |
verify(String where,
boolean checkCFG)
Verify that the IR is well-formed.
|
private void |
verifyAllBlocksAreReachable(String where)
Verify that every block in the CFG is reachable as failing to do
so will cause EnterSSA.insertPhiFunctions to possibly access
elements in DominanceFrontier.getIteratedDominanceFrontier
and then DominanceFrontier.getDominanceFrontier that aren't
defined.
|
private void |
verifyAllBlocksAreReachable(String where,
BasicBlock curBB,
BitVector visitedNormalBBs,
BitVector visitedExceptionalBBs,
boolean fromExceptionEdge)
Verify that every block in the CFG is reachable as failing to do
so will cause EnterSSA.insertPhiFunctions to possibly access
elements in DominanceFrontier.getIteratedDominanceFrontier
and then DominanceFrontier.getDominanceFrontier that aren't
defined.
|
private void |
verifyBBConstruction(String where)
Verify basic block construction from the basic block and
instruction information.
|
private void |
verifyCFG(String where)
Verify control flow graph construction
|
private void |
verifyInstructions(String where)
Verify that every instruction:
1) has operands that back reference it
2) is valid for its position in the basic block
3) if we are MIR, has no guard operands
4) test instruction is canonical
|
private void |
verifyRegisterDefs(String where)
Verify that every non-physical, non-parameter symbolic register
that has a use also has at least one def
|
private void |
verifyRegisterTypes(String where)
Verify that no register is used as a long type and an int type
PRECONDITION: register lists computed
|
private void |
verifyUseFollowsDef(String where)
Checks whether uses follow definitions and that in SSA form
variables aren't multiply defined
|
private void |
verifyUseFollowsDef(String where,
HashSet<Object> definedVariables,
BasicBlock curBB,
BitVector visitedBBs,
ArrayList<BasicBlock> path,
int maxPathLength,
boolean traceExceptionEdges)
Check whether uses follow definitions and in SSA form that
variables aren't multiply defined
|
private void |
verror(String where,
String msg)
Generate error
|
public static final boolean SANITY_CHECK
Configuration.VerifyAssertions
.
When SANITY_CHECK is true
, critical invariants
are checked by complex routines that depend on them,
and verify
is invoked several times
during compilation.public static final boolean PARANOID
false
.
PARANOID must not be true unless Configuration.VerifyAssertions
is also true
.
When PARANOID is true
many IR utility functions
check the invariants on which they depend, and
verify(String,boolean)
is invoked as each
compilation phase is
performed
.public static final byte UNFORMED
public static final byte HIR
public static final byte LIR
public static final byte MIR
public final NormalMethod method
NormalMethod
object corresponding to the
method being compiled. Other methods may have been inlined into
the IR during compilation, so method really only represents the
primary or outermost method being compiled.public final TypeReference[] params
public final OptCompiledMethod compiledMethod
public final OptOptions options
options
that apply
to the current compilation.public SSAOptions desiredSSAOptions
Options
that define the SSA properties
desired the next time we enter SSA form.public SSAOptions actualSSAOptions
Options
that define the SSA properties
currently carried by the IR. Compiler phases that are invoked
on SSA form should update this object to reflect transformations
on SSA form.public GenerationContext gc
generation context
for the current compilation.public final InlineOracle inlinePlan
inlining oracle
to be used for the
current compilation.
TODO: It would make more sense to have the inlining oracle be
a component of the generation context, but as things currently
stand the IR is created before the generation context. We might be
able to restructure things such that the generation context is
created in the IR constructor and then eliminate this field,
replacing all uses with gc.inlinePlan instead.public final InstrumentationPlan instrumentationPlan
public ControlFlowGraph cfg
FCFG
(Factored Control Flow Graph)public GenericRegisterPool regpool
register pool
public final GenericStackManager stackManager
stack manager
.public byte IRStage
private boolean handlerLivenessComputed
private LiveInterval livenessInformation
null
if not yet computed.private Dominators dominators
null
if the dominator information
was not computed yet.private LTDominators ltDominators
null
if the dominator information
was not computed yet.private BasicBlock[] basicBlockMap
getBasicBlock(int)
.private boolean hasSysCall
public IR(NormalMethod m, InlineOracle ip, OptOptions opts)
m
- The method to compileip
- The inlining oracle to use for the compilationopts
- The options to use for the compilationpublic IR(NormalMethod m, CompilationPlan cp)
m
- The method to compilecp
- The compilation plan to executepublic NormalMethod getMethod()
NormalMethod
object corresponding to the
method being compiled. Other methods may have been inlined into
the IR during compilation, so method really only represents the
primary or outermost method being compiled.public boolean inSSAForm()
public boolean inSSAFormAwaitingReEntry()
public boolean hasSysCall()
public void setHasSysCall(boolean b)
public void printInstructions()
public static boolean strictFP(Instruction... is)
strictfp
be adhered to for the given instructions?
Note: we currently don't support strictfp
at all, so this method
is unused.
is
- a sequence of instructiontrue
if any of the instructions requires
strictfp
public Instruction firstInstructionInCodeOrder()
public Instruction lastInstructionInCodeOrder()
public BasicBlock firstBasicBlockInCodeOrder()
public BasicBlock lastBasicBlockInCodeOrder()
public Enumeration<Instruction> forwardInstrEnumerator()
public Enumeration<Instruction> reverseInstrEnumerator()
public Enumeration<BasicBlock> getBasicBlocks()
BasicBlock
s that enumerates the
basic blocks in an arbitrary order.public Enumeration<BasicBlock> forwardBlockEnumerator()
BasicBlock
s that enumerates the
basic blocks in forward code order.public Enumeration<BasicBlock> reverseBlockEnumerator()
BasicBlock
s that enumerates the
basic blocks in reverse code order.public Enumeration<Operand> getParameters()
public boolean isParameter(Operand op)
op
- the operand to checktrue
if the op is a parameter to the IR, false
otherwisepublic int incomingParameterBytes()
this
parameter
if applicablepublic void resetBasicBlockMap()
public BasicBlock getBasicBlock(int number)
resetBasicBlockMap()
has been called
before calling this function, but after making any changes to
the set of basic blocks in the IR.number
- the number of the basic block to retrievepublic Enumeration<BasicBlock> getBasicBlocks(BitVector bits)
resetBasicBlockMap()
has been called
before calling this function, but after making any changes to
the set of basic blocks in the IR.bits
- The BitSet that defines which basic blocks to
enumerate.public int countInstructions()
public Map<Instruction,Integer> numberInstructionsViaMap()
public int getNumberOfSymbolicRegisters()
public int getMaxBasicBlockNumber()
public void pruneExceptionalOut()
public boolean hasReachableExceptionHandlers()
true
if it is possible that the IR contains
an exception handler, false
if it is not.
Note this method may conservatively return true
even if the IR does not actually contain a reachable
exception handler.public void unfactor()
see
.public boolean getHandlerLivenessComputed()
public void setHandlerLivenessComputed(boolean value)
public LiveInterval getLivenessInformation()
public void setLivenessInformation(LiveInterval liveInterval)
public Dominators getDominators()
public void setDominators(Dominators dominators)
public LTDominators getLtDominators()
public void setLtDominators(LTDominators ltDominators)
public void verify(String where)
NB: this is expensive -- be sure to guard invocations with debugging flags.
where
- phrase identifying invoking compilation phasepublic void verify(String where, boolean checkCFG)
NB: this is expensive -- be sure to guard invocations with debugging flags.
where
- phrase identifying invoking compilation phasecheckCFG
- should the CFG invariants be checked
(they can become invalid in "late" MIR).private void verifyBBConstruction(String where)
where
- phrase identifying invoking compilation phaseprivate void verifyCFG(String where)
where
- phrase identifying invoking compilation phaseprivate void verifyInstructions(String where)
where
- phrase identifying invoking compilation phaseprivate void verifyAllBlocksAreReachable(String where)
where
- phrase identifying invoking compilation phaseprivate void verifyAllBlocksAreReachable(String where, BasicBlock curBB, BitVector visitedNormalBBs, BitVector visitedExceptionalBBs, boolean fromExceptionEdge)
where
- location of verify in compilationcurBB
- the current BB to work onvisitedNormalBBs
- the blocks already visited (to avoid cycles) on normal out edgesvisitedExceptionalBBs
- the blocks already visited (to avoid cycles) on exceptional out edgesfromExceptionEdge
- should paths from exceptions be validated?private void verifyRegisterDefs(String where)
where
- phrase identifying invoking compilation phaseprivate void verifyRegisterTypes(String where)
where
- phrase identifying invoking compilation phaseprivate void verifyUseFollowsDef(String where)
where
- phrase identifying invoking compilation phaseprivate void verifyUseFollowsDef(String where, HashSet<Object> definedVariables, BasicBlock curBB, BitVector visitedBBs, ArrayList<BasicBlock> path, int maxPathLength, boolean traceExceptionEdges)
where
- location of verify in compilationdefinedVariables
- variables already defined on this pathcurBB
- the current BB to work onvisitedBBs
- the blocks already visited (to avoid cycles)path
- a record of the path taken to reach this basic blockmaxPathLength
- the maximum number of basic blocks that will be followedtraceExceptionEdges
- should paths from exceptions be validated?private Object getVariableUse(String where, Operand operand)
where
- the verification locationoperand
- the operand to pull a variable fromnull
if the variable should be ignored otherwise the variableprivate Object getVariableDef(String where, Operand operand)
where
- the verification locationoperand
- the operand to pull a variable fromnull
if the variable should be ignored otherwise the variable