use of org.graalvm.compiler.nodes.java.TypeSwitchNode in project graal by oracle.
the class MultiTypeGuardInlineInfo method createDispatchOnTypeBeforeInvoke.
private boolean createDispatchOnTypeBeforeInvoke(StructuredGraph graph, AbstractBeginNode[] successors, boolean invokeIsOnlySuccessor, StampProvider stampProvider, ConstantReflectionProvider constantReflection) {
assert ptypes.size() >= 1;
ValueNode nonNullReceiver = InliningUtil.nonNullReceiver(invoke);
LoadHubNode hub = graph.unique(new LoadHubNode(stampProvider, nonNullReceiver));
graph.getDebug().log("Type switch with %d types", concretes.size());
ResolvedJavaType[] keys = new ResolvedJavaType[ptypes.size()];
double[] keyProbabilities = new double[ptypes.size() + 1];
int[] keySuccessors = new int[ptypes.size() + 1];
double totalProbability = notRecordedTypeProbability;
for (int i = 0; i < ptypes.size(); i++) {
keys[i] = ptypes.get(i).getType();
keyProbabilities[i] = ptypes.get(i).getProbability();
totalProbability += keyProbabilities[i];
keySuccessors[i] = invokeIsOnlySuccessor ? 0 : typesToConcretes.get(i);
assert keySuccessors[i] < successors.length - 1 : "last successor is the unknownTypeSux";
}
keyProbabilities[keyProbabilities.length - 1] = notRecordedTypeProbability;
keySuccessors[keySuccessors.length - 1] = successors.length - 1;
// Normalize the probabilities.
for (int i = 0; i < keyProbabilities.length; i++) {
keyProbabilities[i] /= totalProbability;
}
TypeSwitchNode typeSwitch = graph.add(new TypeSwitchNode(hub, successors, keys, keyProbabilities, keySuccessors, constantReflection));
FixedWithNextNode pred = (FixedWithNextNode) invoke.asNode().predecessor();
pred.setNext(typeSwitch);
return false;
}
use of org.graalvm.compiler.nodes.java.TypeSwitchNode in project graal by oracle.
the class DefaultLoopPolicies method shouldUnswitch.
@Override
public boolean shouldUnswitch(LoopEx loop, List<ControlSplitNode> controlSplits) {
int phis = 0;
StructuredGraph graph = loop.loopBegin().graph();
DebugContext debug = graph.getDebug();
NodeBitMap branchNodes = graph.createNodeBitMap();
for (ControlSplitNode controlSplit : controlSplits) {
for (Node successor : controlSplit.successors()) {
AbstractBeginNode branch = (AbstractBeginNode) successor;
// this may count twice because of fall-through in switches
loop.nodesInLoopBranch(branchNodes, branch);
}
Block postDomBlock = loop.loopsData().getCFG().blockFor(controlSplit).getPostdominator();
if (postDomBlock != null) {
IsolatedInitialization.UNSWITCH_SPLIT_WITH_PHIS.increment(debug);
phis += ((MergeNode) postDomBlock.getBeginNode()).phis().count();
}
}
int inBranchTotal = branchNodes.count();
CountingClosure stateNodesCount = new CountingClosure();
double loopFrequency = loop.loopBegin().loopFrequency();
OptionValues options = loop.loopBegin().getOptions();
int maxDiff = Options.LoopUnswitchTrivial.getValue(options) + (int) (Options.LoopUnswitchFrequencyBoost.getValue(options) * (loopFrequency - 1.0 + phis));
maxDiff = Math.min(maxDiff, Options.LoopUnswitchMaxIncrease.getValue(options));
int remainingGraphSpace = MaximumDesiredSize.getValue(options) - graph.getNodeCount();
maxDiff = Math.min(maxDiff, remainingGraphSpace);
loop.loopBegin().stateAfter().applyToVirtual(stateNodesCount);
int loopTotal = loop.size() - loop.loopBegin().phis().count() - stateNodesCount.count - 1;
int actualDiff = (loopTotal - inBranchTotal);
ControlSplitNode firstSplit = controlSplits.get(0);
if (firstSplit instanceof TypeSwitchNode) {
int copies = firstSplit.successors().count() - 1;
for (Node succ : firstSplit.successors()) {
FixedNode current = (FixedNode) succ;
while (current instanceof FixedWithNextNode) {
current = ((FixedWithNextNode) current).next();
}
if (current instanceof DeoptimizeNode) {
copies--;
}
}
actualDiff = actualDiff * copies;
}
debug.log("shouldUnswitch(%s, %s) : delta=%d (%.2f%% inside of branches), max=%d, f=%.2f, phis=%d -> %b", loop, controlSplits, actualDiff, (double) (inBranchTotal) / loopTotal * 100, maxDiff, loopFrequency, phis, actualDiff <= maxDiff);
if (actualDiff <= maxDiff) {
// check whether we're allowed to unswitch this loop
return loop.canDuplicateLoop();
} else {
return false;
}
}
Aggregations