org.jikesrvm.compilers.opt
Class Simple

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

public final class Simple
extends CompilerPhase

Simple flow-insensitive optimizations.

Except for the "CompilerPhase" methods, all fields and methods in this class are declared static.


Field Summary
private  BranchOptimizations branchOpts
           
private static Constructor<CompilerPhase> constructor
          Constructor for this compiler phase
private  boolean foldBranches
          Fold conditional branches with constant operands?
private  boolean foldChecks
          Attempt to eliminate bounds and cast checks?
private  int level
          At what optimization level should this phase be run?
private  boolean sortRegisters
          Sort registers used by commutative operators
private  boolean typeProp
          Perform type propagation?
 
Fields inherited from class org.jikesrvm.compilers.opt.driver.CompilerPhase
container
 
Constructor Summary
Simple(int level, boolean typeProp, boolean foldChecks, boolean foldBranches, boolean sortRegisters)
          The constructor is used to specify what pieces of Simple will be enabled for this instance.
 
Method Summary
(package private) static void arrayPropagation(IR ir)
          Perform flow-insensitive propagation to eliminate bounds checks and arraylength for arrays with static lengths.
static void copyPropagation(IR ir)
          Perform flow-insensitive copy and constant propagation using register list information.
(package private) static void eliminateDeadInstructions(IR ir)
          Simple conservative dead code elimination.
static void eliminateDeadInstructions(IR ir, boolean preserveImplicitSSA)
          Simple conservative dead code elimination.
(package private) static Operand equivalentValforPHI(Instruction phi)
          Try to find an operand that is equivalent to the result of a given phi instruction.
(package private)  void foldConstants(IR ir)
          Perform constant folding.
 Constructor<CompilerPhase> getClassConstructor()
          Get a constructor object for this compiler phase
 String getName()
           
 void perform(IR ir)
          Main driver for the simple optimizations
 boolean printingEnabled(OptOptions options, boolean before)
          Returns true if the phase wants the IR dumped before and/or after it runs.
 boolean shouldPerform(OptOptions options)
          This method determines if the phase should be run, based on the Options object it is passed.
(package private)  void simplifyConstantBranches(IR ir)
          Simplify branches whose operands are constants.
private static void sortCommutativeRegisterUses(IR ir)
          Sort commutative use operands so that those defined most are on the lhs
(package private) static void typePropagation(IR ir)
          Perform flow-insensitive type propagation using register list information.
 
Methods inherited from class org.jikesrvm.compilers.opt.driver.CompilerPhase
dumpIR, dumpIR, getCompilerPhaseConstructor, getCompilerPhaseConstructor, newExecution, performPhase, reportAdditionalStats, setContainer, verify
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

branchOpts

private final BranchOptimizations branchOpts

level

private final int level
At what optimization level should this phase be run?


typeProp

private final boolean typeProp
Perform type propagation?


foldChecks

private final boolean foldChecks
Attempt to eliminate bounds and cast checks?


foldBranches

private final boolean foldBranches
Fold conditional branches with constant operands?


sortRegisters

private final boolean sortRegisters
Sort registers used by commutative operators


constructor

private static final Constructor<CompilerPhase> constructor
Constructor for this compiler phase

Constructor Detail

Simple

public Simple(int level,
              boolean typeProp,
              boolean foldChecks,
              boolean foldBranches,
              boolean sortRegisters)
The constructor is used to specify what pieces of Simple will be enabled for this instance. Some pieces are always enabled. Customizing can be useful because some of the optimizations are not valid/useful on LIR or even on "late stage" HIR.

Parameters:
level - at what optimization level should the phase be enabled?
typeProp - should type propagation be peformed?
foldChecks - should we attempt to eliminate boundscheck?
foldBranches - should we attempt to constant fold conditional
sortRegisters - should we sort use operands? branches?
Method Detail

shouldPerform

public boolean shouldPerform(OptOptions options)
Description copied from class: CompilerPhase
This method determines if the phase should be run, based on the Options object it is passed. By default, phases are always performed. Subclasses should override this method if they only want to be performed conditionally.

Overrides:
shouldPerform in class CompilerPhase
Parameters:
options - the compiler options for the compilation
Returns:
true if the phase should be performed

getName

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

printingEnabled

public boolean printingEnabled(OptOptions options,
                               boolean before)
Description copied from class: CompilerPhase
Returns true if the phase wants the IR dumped before and/or after it runs. By default, printing is not enabled. Subclasses should override this method if they want to provide IR dumping.

Overrides:
printingEnabled in class CompilerPhase
Parameters:
options - the compiler options for the compilation
before - true when invoked before perform, false otherwise.
Returns:
true if the IR should be printed, false otherwise.

getClassConstructor

public Constructor<CompilerPhase> getClassConstructor()
Get a constructor object for this compiler phase

Overrides:
getClassConstructor in class CompilerPhase
Returns:
compiler phase constructor

perform

public void perform(IR ir)
Main driver for the simple optimizations

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

sortCommutativeRegisterUses

private static void sortCommutativeRegisterUses(IR ir)
Sort commutative use operands so that those defined most are on the lhs

Parameters:
ir - the IR to work on

copyPropagation

public static void copyPropagation(IR ir)
Perform flow-insensitive copy and constant propagation using register list information.

Parameters:
ir - the IR in question

equivalentValforPHI

static Operand equivalentValforPHI(Instruction phi)
Try to find an operand that is equivalent to the result of a given phi instruction.

Parameters:
phi - the instruction to be simplified
Returns:
one of the phi's operands that is equivalent to the phi's result, or null if the phi can not be simplified.

typePropagation

static void typePropagation(IR ir)
Perform flow-insensitive type propagation using register list information. Note: register list MUST be initialized BEFORE calling this routine.

Kept separate from copyPropagation loop to enable clients more flexibility.

Parameters:
ir - the IR in question

arrayPropagation

static void arrayPropagation(IR ir)
Perform flow-insensitive propagation to eliminate bounds checks and arraylength for arrays with static lengths. Only useful on the HIR (because BOUNDS_CHECK is expanded in LIR into multiple instrs)

Note: this function incrementally maintains the register list.

Parameters:
ir - the IR in question

eliminateDeadInstructions

static void eliminateDeadInstructions(IR ir)
Simple conservative dead code elimination. An instruction is eliminated if:

Note: this function incrementally maintains the register list.

Parameters:
ir - the IR to optimize

eliminateDeadInstructions

public static void eliminateDeadInstructions(IR ir,
                                             boolean preserveImplicitSSA)
Simple conservative dead code elimination. An instruction is eliminated if:

Note: this function incrementally maintains the register list.

Parameters:
ir - IR to optimize
preserveImplicitSSA - if this is true, do not eliminate dead instructions that have implicit operands for heap array SSA form

foldConstants

void foldConstants(IR ir)
Perform constant folding.

Parameters:
ir - the IR to optimize

simplifyConstantBranches

void simplifyConstantBranches(IR ir)
Simplify branches whose operands are constants.

NOTE: This pass ensures that the register list is still valid after it is done.

Parameters:
ir - the IR to optimize