org.jikesrvm.compilers.opt.driver
Class CompilerPhase

java.lang.Object
  extended by org.jikesrvm.compilers.opt.driver.CompilerPhase
Direct Known Subclasses:
AdjustBCIndexes, AdjustBranchProbabilities, AssemblerDriver, BranchOptimizationDriver, BuildLST, CFGTransformations, CoalesceMoves, ConvertALUOperators, ConvertBCtoHIR, ConvertHIRtoLIR, ConvertLIRtoMIR.ComplexOperators, ConvertLIRtoMIR.DoBURS, ConvertLIRtoMIR.DoLiveness, ConvertLIRtoMIR.NormalizeConstantsPhase, ConvertLIRtoMIR.ReduceOperators, DominanceFrontier, DominatorsPhase, DominatorTreePhase, EnterSSA, EscapeTransformations, EstimateBlockFrequencies, ExpandCallingConvention, ExpandFPRStackConvention, ExpandRuntimeServices, FieldAnalysis, FinalMIRExpansionDriver, GCP.GCPFinalization, GCP.GCPPreparation, GlobalCSE, GlobalValueNumber, IndexPropagation, InsertInstructionCounters, InsertMethodInvocationCounter, InsertYieldpointCounters, InstrumentationSamplingFramework, IRPrinter, LeaveSSA, LICM, LinearScan.IntervalAnalysis, LinearScan.LinearScanPhase, LinearScan.RegisterRestrictionsPhase, LinearScan.SpillCode, LinearScan.UpdateGCMaps1, LinearScan.UpdateGCMaps2, LinearScan.UpdateOSRMaps, LiveAnalysis, LiveRangeSplitting.LiveRangeSplittingPhase, LiveRangeSplitting.RenamePreparation, LoadElimination.GVNPreparation, LoadElimination.LoadEliminationPreparation, LoadElimination.LoadEliminator, LocalCastOptimization, LocalConstantProp, LocalCopyProp, LocalCSE, LoopAnalysis, LoopUnrolling, LoopVersioning, LowerInstrumentation, MIRSplitRanges, MutateSplits, NullCheckCombining, OsrPointConstructor, PiNodes, PostDominatorsPhase, PrePassScheduler, PrologueEpilogueCreator, RedundantBranchElimination.EnsureSSA, RedundantBranchElimination.RBE, RegisterAllocator.RegisterAllocPreparation, ReorderingPhase, Simple, SimpleEscape, SplitBasicBlock, SSATuneUp.FoldingDriver, SSATuneUp.TuneUpPreparation, StaticSplitting, TailRecursionElimination, YieldPoints

public abstract class CompilerPhase
extends Object

Compiler phases all extend this abstract class. All compiler phases must provide implementations of two abstract methods:

By default, a new instance of the phase is created each time shouldPerform is called. This instance is discarded as soon as shouldPerform completes. Therefore, it is allowable (and is suggested when necessary) for subclasses to use their instance fields to hold per-compilation state. To be more concrete, the pattern of use is:

  newExecution(ir).performPhase(ir).
 

See Also:

NOTE: compiler phases that do not need to use instance fields to hold per-compilation state may override newExecution() to return this. Doing so may lead to memory leaks and concurrent access problems, so this should be done with great care!


Field Summary
protected  OptimizationPlanAtomicElement container
          The plan element that contains this phase.
private  Object[] initargs
          Arguments to constructor that copies this phase
 
Constructor Summary
CompilerPhase()
          Constructor
CompilerPhase(Object[] initargs)
          Constructor
 
Method Summary
static void dumpIR(IR ir, String tag)
          Prints the IR, optionally including the CFG
static void dumpIR(IR ir, String tag, boolean forceCFG)
          Prints the IR, optionally including the CFG
 Constructor<CompilerPhase> getClassConstructor()
          Get a constructor object for this compiler phase
protected static Constructor<CompilerPhase> getCompilerPhaseConstructor(Class<? extends CompilerPhase> klass)
          Given the name of a compiler phase return the default (no argument) constructor for it.
protected static Constructor<CompilerPhase> getCompilerPhaseConstructor(Class<? extends CompilerPhase> phaseType, Class<?>[] initTypes)
          Given the name of a compiler phase return the default (no argument) constructor for it.
abstract  String getName()
           
 CompilerPhase newExecution(IR ir)
          This method is called immediately before performPhase.
abstract  void perform(IR ir)
          This is the method that actually does the work of the phase.
 void performPhase(IR ir)
          Runs a phase by calling perform on the supplied IR surrounded by printing/messaging/debugging glue.
 boolean printingEnabled(OptOptions options, boolean before)
          Returns true if the phase wants the IR dumped before and/or after it runs.
 void reportAdditionalStats()
          Called when printing a measure compilation report to enable a phase to report additional phase-specific statistics.
 void setContainer(OptimizationPlanAtomicElement atomEl)
          Set the containing optimization plan element for this phase
 boolean shouldPerform(OptOptions options)
          This method determines if the phase should be run, based on the Options object it is passed.
 void verify(IR ir)
          Verify the IR.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

container

protected OptimizationPlanAtomicElement container
The plan element that contains this phase. Only useful if the phase wants to gather additional statistics for a measure compilation report.


initargs

private final Object[] initargs
Arguments to constructor that copies this phase

Constructor Detail

CompilerPhase

public CompilerPhase()
Constructor


CompilerPhase

public CompilerPhase(Object[] initargs)
Constructor

Parameters:
initargs - arguments used when constructing copies of this phase
Method Detail

getName

public abstract String getName()
Returns:
a String which is the name of the phase.

perform

public abstract void perform(IR ir)
This is the method that actually does the work of the phase.

Parameters:
ir - the IR on which to apply the phase

shouldPerform

public boolean shouldPerform(OptOptions options)
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.

Parameters:
options - the compiler options for the compilation
Returns:
true if the phase should be performed

printingEnabled

public boolean printingEnabled(OptOptions options,
                               boolean before)
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.

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.

reportAdditionalStats

public void reportAdditionalStats()
Called when printing a measure compilation report to enable a phase to report additional phase-specific statistics.


newExecution

public CompilerPhase newExecution(IR ir)
This method is called immediately before performPhase. Phases that do not need to create a new instance for each execution may override this method to return this, but this must be done carefully! Classes that don't override this method need to override getClassConstructor.

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

getClassConstructor

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

Returns:
exception/null as this phase can't be created

getCompilerPhaseConstructor

protected static Constructor<CompilerPhase> getCompilerPhaseConstructor(Class<? extends CompilerPhase> klass)
Given the name of a compiler phase return the default (no argument) constructor for it.


getCompilerPhaseConstructor

protected static Constructor<CompilerPhase> getCompilerPhaseConstructor(Class<? extends CompilerPhase> phaseType,
                                                                        Class<?>[] initTypes)
Given the name of a compiler phase return the default (no argument) constructor for it.


setContainer

public final void setContainer(OptimizationPlanAtomicElement atomEl)
Set the containing optimization plan element for this phase


performPhase

public final void performPhase(IR ir)
Runs a phase by calling perform on the supplied IR surrounded by printing/messaging/debugging glue.

Parameters:
ir - the IR object on which to do the work of the phase.

dumpIR

public static void dumpIR(IR ir,
                          String tag)
Prints the IR, optionally including the CFG

Parameters:
ir - the IR to print
tag - a String to use in the start/end message of the IR dump

dumpIR

public static void dumpIR(IR ir,
                          String tag,
                          boolean forceCFG)
Prints the IR, optionally including the CFG

Parameters:
ir - the IR to print
forceCFG - should the CFG be printed, independent of the value of ir.options.PRINT_CFG?
tag - a String to use in the start/end message of the IR dump

verify

public void verify(IR ir)
Verify the IR. Written as a non-final virtual method to allow late stages in the compilation pipeline (eg ConvertMIR2MC) to skip verification.

Parameters:
ir - the IR to verify