|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.jikesrvm.compilers.opt.driver.CompilerPhase org.jikesrvm.compilers.opt.ssa.LoopVersioning
public final class LoopVersioning
This optimisation works from the outer most loop inward, optimising
loops that conform to being regular AnnotatedLSTNode
s. The optimisations performs the following
operations:
Example:
Field Summary | |
---|---|
private static Constructor<CompilerPhase> |
constructor
Constructor for this compiler phase |
private static boolean |
DEBUG
Flag to optionally print verbose debugging messages |
private SSAOptions |
desiredSSAOptions
SSA options |
private CompilerPhase |
domPhase
Compiler phases called from this one |
private CompilerPhase |
enterSSA
Compiler phases called from this one |
private static boolean |
inSSAphase
Run inside SSA sub-phase |
private IR |
ir
IR for optimisation |
private CompilerPhase |
leaveSSA
Compiler phases called from this one |
private HashSet<Register> |
loopRegisterSet
Set used to store the loop related register |
private static int |
OPTIMIZED_LOOP_OPERAND
The phi instruction operand holding the optimized loop variable |
private static int |
UNOPTIMIZED_LOOP_OPERAND
The phi instruction operand holding the unoptimized loop variable |
private static boolean |
VERIFY
Flag to verify computed IR |
Fields inherited from class org.jikesrvm.compilers.opt.driver.CompilerPhase |
---|
container |
Constructor Summary | |
---|---|
LoopVersioning()
Constructor |
Method Summary | |
---|---|
private boolean |
createBranchBlocks(AnnotatedLSTNode loop,
BasicBlock block,
ArrayList<Instruction> checksToEliminate,
BasicBlock unoptimizedLoopEntry,
BasicBlock optimizedLoopEntry,
HashMap<Register,Register> optimalRegMap)
Create the block containing explict branches to either the optimized or unoptimized loops |
private HashMap<BasicBlock,BasicBlock> |
createCloneLoop(AnnotatedLSTNode loop,
HashMap<Register,Register> regMap,
HashMap<Register,BasicBlock> regToBlockMap)
Create a clone of the loop replacing definitions in the cloned loop with those found in the register map |
private HashMap<BasicBlock,BasicBlock> |
createOptimizedLoop(AnnotatedLSTNode loop,
HashMap<Register,Register> regMap,
ArrayList<Instruction> instrToEliminate,
HashMap<Register,BasicBlock> regToBlockMap)
Create a clone of the loop replacing definitions in the cloned loop with those found in the register map and eliminate unnecessary bound checks |
private boolean |
findLoopToOptimise(AnnotatedLSTNode loop)
Find an outermost loop to optimise and optimise it. |
private void |
fixUpPhiPredecessors(ArrayList<Instruction> phiInstructions,
BasicBlock unoptimizedLoopExit,
BasicBlock optimizedLoopExit)
When phi nodes were generated the basic blocks weren't known for the predecessors, fix this up now. |
private BasicBlock |
generateExplicitBoundCheck(Instruction boundCheckInstr,
Operand minIndexValue,
Operand maxIndexValue,
HashMap<Register,Register> optimalRegMap,
BasicBlock block,
BasicBlock unoptimizedLoopEntry)
Generate bound check branch blocks |
private BasicBlock |
generateNullCheckBranchBlocks(AnnotatedLSTNode loop,
ArrayList<Instruction> checksToEliminate,
HashMap<Register,Register> optimalRegMap,
BasicBlock block,
BasicBlock unoptimizedLoopEntry)
Generate null check branch blocks |
private void |
generatePhiNodes(AnnotatedLSTNode loop,
ArrayList<Register> registers,
ArrayList<TypeReference> types,
ArrayList<Instruction> phiInstructions,
HashMap<Register,Register> subOptimalRegMap,
HashMap<Register,Register> optimalRegMap)
Generate into a new block phi nodes that define the original register defined by the loop and use two newly created registers. |
Constructor<CompilerPhase> |
getClassConstructor()
Get a constructor object for this compiler phase |
private int |
getConstantAdjustedArrayLengthDistance(Operand op)
Get the distance from an array length by addding up instructions that adjust the array length result by a constant amount |
private Operand |
getConstantAdjustedArrayLengthRef(Operand op)
Get the array length reference ignoring instructions that adjust its result by a fixed amount |
private void |
getListOfChecksToEliminate(AnnotatedLSTNode loop,
ArrayList<Instruction> instrToEliminate)
Create a list of instructions to be eliminated |
String |
getName()
Return a string name for this phase. |
private void |
getRegistersDefinedInLoop(AnnotatedLSTNode loop,
ArrayList<Register> registers,
ArrayList<TypeReference> types,
ArrayList<Instruction> definingInstructions)
Get registers defined in the given loop. |
private boolean |
isOptimizedLoop(Register reg)
Check whether the loop that contain such iterator register had been optimized |
private void |
modifyOriginalLoop(AnnotatedLSTNode loop,
ArrayList<Instruction> phiInstructions,
ArrayList<Instruction> definingInstrInOriginalLoop,
HashMap<Register,Register> subOptimalRegMap,
HashMap<Register,Register> optimalRegMap)
Remove loop and replace register definitions in the original loop with phi instructions |
private RegisterOperand |
nullCheckPerformedInLoopPredecessors(BasicBlock header,
Instruction instr)
Can we eliminate a null check as it has lready been performed? |
void |
perform(IR _ir)
This is the method that actually does the work of the phase. |
private void |
removeUnoptimizedLoop(AnnotatedLSTNode loop,
HashMap<BasicBlock,BasicBlock> unoptimizedLoopMap)
Remove unreachable unoptimized loop |
private void |
renameOptimizedLoops(HashMap<Register,Register> subOptimalRegMap,
HashMap<Register,Register> optimalRegMap)
Rename the iterators for optimized loops so we can tell they are still optimized |
private static void |
report(String s)
Human readable report of what goes on |
private void |
setOptimizedLoop(Register reg)
Put the optimized loop's iterator register into the hash set |
boolean |
shouldPerform(OptOptions options)
Should loop versioning be performed? |
Methods inherited from class org.jikesrvm.compilers.opt.driver.CompilerPhase |
---|
dumpIR, dumpIR, getCompilerPhaseConstructor, getCompilerPhaseConstructor, newExecution, performPhase, printingEnabled, reportAdditionalStats, setContainer, verify |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final boolean DEBUG
private static final boolean VERIFY
private static final int OPTIMIZED_LOOP_OPERAND
private static final int UNOPTIMIZED_LOOP_OPERAND
private IR ir
private HashSet<Register> loopRegisterSet
private SSAOptions desiredSSAOptions
private CompilerPhase enterSSA
private CompilerPhase leaveSSA
private CompilerPhase domPhase
private static final boolean inSSAphase
private static final Constructor<CompilerPhase> constructor
Constructor Detail |
---|
public LoopVersioning()
Method Detail |
---|
private static void report(String s)
s
- String to printpublic String getName()
getName
in class CompilerPhase
public Constructor<CompilerPhase> getClassConstructor()
getClassConstructor
in class CompilerPhase
public boolean shouldPerform(OptOptions options)
shouldPerform
in class CompilerPhase
options
- the compiler options for the compilation
public void perform(IR _ir)
CompilerPhase
perform
in class CompilerPhase
_ir
- the IR to processprivate boolean findLoopToOptimise(AnnotatedLSTNode loop)
loop
- Loop to search
private void getListOfChecksToEliminate(AnnotatedLSTNode loop, ArrayList<Instruction> instrToEliminate)
loop
- the loop to examineinstrToEliminate
- the instructions to removeprivate void getRegistersDefinedInLoop(AnnotatedLSTNode loop, ArrayList<Register> registers, ArrayList<TypeReference> types, ArrayList<Instruction> definingInstructions)
loop
- - the loop to examineregisters
- - vector to which defined registers are addedprivate void generatePhiNodes(AnnotatedLSTNode loop, ArrayList<Register> registers, ArrayList<TypeReference> types, ArrayList<Instruction> phiInstructions, HashMap<Register,Register> subOptimalRegMap, HashMap<Register,Register> optimalRegMap)
registers
- - vector to which defined registers need to be
created registers.x used in creating phi nodestypes
- - vector of corresponding types of registers.phiInstructions
- - created phi instructionssubOptimalRegMap
- - mapping of orignal destination to the
newly created destination for the unoptimized loopoptimalRegMap
- - mapping of orignal destination to the
newly created destination for the optimized loopprivate HashMap<BasicBlock,BasicBlock> createCloneLoop(AnnotatedLSTNode loop, HashMap<Register,Register> regMap, HashMap<Register,BasicBlock> regToBlockMap)
loop
- - loop to cloneregMap
- - mapping of original definition to new
definition
private HashMap<BasicBlock,BasicBlock> createOptimizedLoop(AnnotatedLSTNode loop, HashMap<Register,Register> regMap, ArrayList<Instruction> instrToEliminate, HashMap<Register,BasicBlock> regToBlockMap)
loop
- - loop to cloneregMap
- - mapping of original definition to new
definitioninstrToEliminate
- - instructions to eliminateregToBlockMap
- - mapping of a register to its defining BB
private void fixUpPhiPredecessors(ArrayList<Instruction> phiInstructions, BasicBlock unoptimizedLoopExit, BasicBlock optimizedLoopExit)
private boolean createBranchBlocks(AnnotatedLSTNode loop, BasicBlock block, ArrayList<Instruction> checksToEliminate, BasicBlock unoptimizedLoopEntry, BasicBlock optimizedLoopEntry, HashMap<Register,Register> optimalRegMap)
optimalRegMap
- - mapping used to map eliminated bound and
null check guards toprivate BasicBlock generateNullCheckBranchBlocks(AnnotatedLSTNode loop, ArrayList<Instruction> checksToEliminate, HashMap<Register,Register> optimalRegMap, BasicBlock block, BasicBlock unoptimizedLoopEntry)
loop
- the current loop where checks are being eliminatedchecksToEliminate
- all of the checks that are being eliminated in the passoptimalRegMap
- a map from original register to the register used in the optimal loopblock
- the block to generate code intounoptimizedLoopEntry
- entry to the unoptimized loop for if the check fails
private BasicBlock generateExplicitBoundCheck(Instruction boundCheckInstr, Operand minIndexValue, Operand maxIndexValue, HashMap<Register,Register> optimalRegMap, BasicBlock block, BasicBlock unoptimizedLoopEntry)
boundCheckInstr
- the bound check instruction in questionminIndexValue
- the min value for an iterator a loop will generatemaxIndexValue
- the max value for an iterator a loop will generateoptimalRegMap
- a map from original register to the register used in the optimal loopblock
- the block to generate code intounoptimizedLoopEntry
- entry to the unoptimized loop for if the check fails
private RegisterOperand nullCheckPerformedInLoopPredecessors(BasicBlock header, Instruction instr)
instr
- null check instructionprivate Operand getConstantAdjustedArrayLengthRef(Operand op)
op
- operand to chase arraylength opcode to
constant value from an array lengthprivate int getConstantAdjustedArrayLengthDistance(Operand op)
op
- operand to chase arraylength opcode toprivate void modifyOriginalLoop(AnnotatedLSTNode loop, ArrayList<Instruction> phiInstructions, ArrayList<Instruction> definingInstrInOriginalLoop, HashMap<Register,Register> subOptimalRegMap, HashMap<Register,Register> optimalRegMap)
private void removeUnoptimizedLoop(AnnotatedLSTNode loop, HashMap<BasicBlock,BasicBlock> unoptimizedLoopMap)
private void setOptimizedLoop(Register reg)
reg
- registerprivate boolean isOptimizedLoop(Register reg)
reg
- register
private void renameOptimizedLoops(HashMap<Register,Register> subOptimalRegMap, HashMap<Register,Register> optimalRegMap)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |