The constant optimization phase.
A standard phase template
A standard phase template
The global environment; overridden by instantiation in Global.
The global environment; overridden by instantiation in Global.
Names of phases that must run before this phase.
Names of phases that must run before this phase.
Name of the phase that this phase must follow immediately.
Name of the phase that this phase must follow immediately.
Is this component enabled? Default is true.
Is this component enabled? Default is true.
SubComponent are added to a HashSet and two phases are the same if they have the same name
SubComponent are added to a HashSet and two phases are the same if they have the same name
True if this phase runs before all other phases.
True if this phase runs before all other phases. Usually, parser
.
True if this phase is not provided by a plug-in.
True if this phase is not provided by a plug-in.
Create a new phase
Create a new phase
The phase corresponding to this subcomponent in the current compiler run
The phase corresponding to this subcomponent in the current compiler run
The name of the phase
The name of the phase
New flags defined by the phase which are not valid before
New flags defined by the phase which are not valid before
New flags defined by the phase which are not valid until immediately after it
New flags defined by the phase which are not valid until immediately after it
Names of phases required by this component.
Names of phases required by this component. Default is Nil
.
Names of phases that must run after this phase.
Names of phases that must run after this phase. Default is Nil
.
True if this phase runs after all other phases.
True if this phase runs after all other phases. Usually, terminal
.
ConstantOptimization uses abstract interpretation to approximate for each instruction what constants a variable or stack slot might hold or cannot hold. From this it will eliminate unreachable conditionals where only one branch is reachable, e.g. to eliminate unnecessary null checks.
With some more work it could be extended to - cache stable values (final fields, modules) in locals - replace the copy propagation in ClosureElilmination - fold constants - eliminate unnecessary stores and loads - propagate knowledge gathered from conditionals for further optimization