org.jikesrvm.compilers.opt.controlflow
Class BranchOptimizationDriver

java.lang.Object
  extended by org.jikesrvm.compilers.opt.driver.CompilerPhase
      extended by org.jikesrvm.compilers.opt.controlflow.BranchOptimizationDriver
Direct Known Subclasses:
BranchOptimizations, MIRBranchOptimizations

public abstract class BranchOptimizationDriver
extends CompilerPhase

IR level independent driver for simple peephole optimizations of branches.


Field Summary
private  int level
          Optimization level at which phase should be performed.
private  boolean simplify
          Optimization level at which phase should be performed.
 
Fields inherited from class org.jikesrvm.compilers.opt.driver.CompilerPhase
container
 
Constructor Summary
BranchOptimizationDriver(int level)
           
BranchOptimizationDriver(int level, boolean simplify)
           
 
Method Summary
protected  boolean applyPeepholeBranchOpts(IR ir)
          This pass performs peephole branch optimizations.
private static boolean applySimplify(IR ir)
          Perform branch simplifications.
protected  Instruction firstLabelFollowing(Instruction s)
          Given an instruction s, return the first LABEL instruction following s.
protected  Instruction firstRealInstructionFollowing(Instruction s)
          Given an instruction s, return the first real (non-label) instruction following s
 String getName()
           
protected  void maximizeBasicBlocks(IR ir)
          Merge adjacent basic blocks
 CompilerPhase newExecution(IR ir)
          This phase contains no per-compilation instance fields.
protected abstract  boolean optimizeBranchInstruction(IR ir, Instruction s, BasicBlock bb)
          This method actually does the work of attempting to peephole optimize a branch instruction.
 void perform(IR ir)
          Perform peephole branch optimizations.
 void perform(IR ir, boolean renumber)
           
 boolean printingEnabled(OptOptions options, boolean before)
          Returns true if the phase wants the IR dumped before and/or after it runs.
protected  boolean removeUnreachableCode(IR ir)
          Remove unreachable code
 boolean shouldPerform(OptOptions options)
          Interface
 
Methods inherited from class org.jikesrvm.compilers.opt.driver.CompilerPhase
dumpIR, dumpIR, getClassConstructor, getCompilerPhaseConstructor, getCompilerPhaseConstructor, performPhase, reportAdditionalStats, setContainer, verify
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

level

private final int level
Optimization level at which phase should be performed.


simplify

private final boolean simplify
Optimization level at which phase should be performed.

Constructor Detail

BranchOptimizationDriver

BranchOptimizationDriver(int level,
                         boolean simplify)
Parameters:
level - the minimum optimization level at which the branch optimizations should be performed.
simplify - perform simplification prior to optimization?

BranchOptimizationDriver

BranchOptimizationDriver(int level)
Parameters:
level - the minimum optimization level at which the branch optimizations should be performed.
Method Detail

shouldPerform

public final boolean shouldPerform(OptOptions options)
Interface

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

getName

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

printingEnabled

public final 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.

newExecution

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

Overrides:
newExecution in class CompilerPhase
Parameters:
ir - the IR that is about to be passed to performPhase
Returns:
an opt compiler phase on which performPhase may be invoked.

perform

public final void perform(IR ir)
Perform peephole branch optimizations.

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

perform

public final void perform(IR ir,
                          boolean renumber)

applySimplify

private static boolean applySimplify(IR ir)
Perform branch simplifications.

Parameters:
ir - the IR to optimize
Returns:
was something reduced

applyPeepholeBranchOpts

protected boolean applyPeepholeBranchOpts(IR ir)
This pass performs peephole branch optimizations. See Muchnick ~p.590

Parameters:
ir - the IR to optimize

optimizeBranchInstruction

protected abstract boolean optimizeBranchInstruction(IR ir,
                                                     Instruction s,
                                                     BasicBlock bb)
This method actually does the work of attempting to peephole optimize a branch instruction.

Parameters:
ir - the containing IR
s - the branch instruction to optimize
bb - the containing basic block
Returns:
true if an optimization was applied, false otherwise

removeUnreachableCode

protected final boolean removeUnreachableCode(IR ir)
Remove unreachable code

Parameters:
ir - the IR to optimize
Returns:
true if did something, false otherwise

maximizeBasicBlocks

protected final void maximizeBasicBlocks(IR ir)
Merge adjacent basic blocks

Parameters:
ir - the IR to optimize

firstLabelFollowing

protected final Instruction firstLabelFollowing(Instruction s)
Given an instruction s, return the first LABEL instruction following s.


firstRealInstructionFollowing

protected final Instruction firstRealInstructionFollowing(Instruction s)
Given an instruction s, return the first real (non-label) instruction following s