public abstract class SwitchStrategy extends Object
SwitchStrategy.getBestStrategy(double[], JavaConstant[], LabelRef[]) method can be used to get
strategy with the smallest average effort (average number of comparisons until a decision is
reached). The strategy returned by this method will have its averageEffort set, while a strategy
constructed directly will not.| Modifier and Type | Class and Description |
|---|---|
static class |
SwitchStrategy.BaseSwitchClosure
Backends can subclass this abstract class and generate code for switch strategies by
implementing the
SwitchStrategy.BaseSwitchClosure.conditionalJump(int, Condition, Label) method. |
static class |
SwitchStrategy.BinaryStrategy
This strategy recursively subdivides the list of keys to create a binary search based on
probabilities.
|
static class |
SwitchStrategy.RangesStrategy
This strategy divides the keys into ranges of successive keys with the same target and
creates comparisons for these ranges.
|
static class |
SwitchStrategy.SequentialStrategy
This strategy orders the keys according to their probability and creates one equality
comparison per key.
|
| Modifier and Type | Field and Description |
|---|---|
double[] |
keyProbabilities |
| Constructor and Description |
|---|
SwitchStrategy(double[] keyProbabilities) |
| Modifier and Type | Method and Description |
|---|---|
double |
getAverageEffort() |
static SwitchStrategy |
getBestStrategy(double[] keyProbabilities,
JavaConstant[] keyConstants,
LabelRef[] keyTargets)
Creates all switch strategies for the given switch, evaluates them (based on average effort)
and returns the best one.
|
abstract Constant[] |
getKeyConstants() |
protected void |
registerDefaultEffort(int depth)
Tells the system that the default successor is reached after depth number of comparisons,
which is used to calculate average effort.
|
protected void |
registerEffort(int rangeStart,
int rangeEnd,
int depth)
Tells the system that the given (inclusive) range of keys is reached after depth number of
comparisons, which is used to calculate the average effort.
|
abstract void |
run(org.graalvm.compiler.lir.SwitchStrategy.SwitchClosure closure) |
String |
toString() |
public abstract Constant[] getKeyConstants()
public double getAverageEffort()
protected void registerEffort(int rangeStart,
int rangeEnd,
int depth)
protected void registerDefaultEffort(int depth)
public abstract void run(org.graalvm.compiler.lir.SwitchStrategy.SwitchClosure closure)
public static SwitchStrategy getBestStrategy(double[] keyProbabilities, JavaConstant[] keyConstants, LabelRef[] keyTargets)