org.jikesrvm.compilers.opt
Class LocalCastOptimization

java.lang.Object
  extended by org.jikesrvm.compilers.opt.driver.CompilerPhase
      extended by org.jikesrvm.compilers.opt.LocalCastOptimization

public final class LocalCastOptimization
extends CompilerPhase

Perform simple peephole optimizations to reduce the overhead of checking casts. This code was inspired by some special cases in handling checkcast in HIR2LIR, but the actual code is all different.

There are currently the following optimizations:


Field Summary
 
Fields inherited from class org.jikesrvm.compilers.opt.driver.CompilerPhase
container
 
Constructor Summary
LocalCastOptimization()
           
 
Method Summary
 String getName()
           
private  boolean invertNullAndTypeChecks(Instruction s)
          If there's a checkcast followed by a null check, move the checkcast after the null check, since the null pointer exception must be thrown anyway.
 CompilerPhase newExecution(IR ir)
          Return this instance of this phase.
 void perform(IR ir)
          Main routine: perform the transformation.
private  boolean pushTypeCheckBelowIf(Instruction s, IR ir)
          Where legal, move a type check below an if instruction.
 void reportAdditionalStats()
          Called when printing a measure compilation report to enable a phase to report additional phase-specific statistics.
 
Methods inherited from class org.jikesrvm.compilers.opt.driver.CompilerPhase
dumpIR, dumpIR, getClassConstructor, getCompilerPhaseConstructor, getCompilerPhaseConstructor, performPhase, printingEnabled, setContainer, shouldPerform, verify
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LocalCastOptimization

public LocalCastOptimization()
Method Detail

getName

public String getName()
Specified by:
getName in class CompilerPhase
Returns:
a String which is the name of the phase.

reportAdditionalStats

public void reportAdditionalStats()
Description copied from class: CompilerPhase
Called when printing a measure compilation report to enable a phase to report additional phase-specific statistics.

Overrides:
reportAdditionalStats in class CompilerPhase

newExecution

public CompilerPhase newExecution(IR ir)
Return this instance of this phase. This phase contains no per-compilation instance fields.

Overrides:
newExecution in class CompilerPhase
Parameters:
ir - not used
Returns:
this

perform

public void perform(IR ir)
Main routine: perform the transformation.

Specified by:
perform in class CompilerPhase
Parameters:
ir - the IR to transform

invertNullAndTypeChecks

private boolean invertNullAndTypeChecks(Instruction s)
If there's a checkcast followed by a null check, move the checkcast after the null check, since the null pointer exception must be thrown anyway.

Parameters:
s - the potential checkcast instruction
Returns:
true iff the transformation happened

pushTypeCheckBelowIf

private boolean pushTypeCheckBelowIf(Instruction s,
                                     IR ir)
Where legal, move a type check below an if instruction.

Parameters:
s - the potential typecheck instruction
ir - the governing IR