use of org.graalvm.compiler.options.OptionValues 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;
}
}
use of org.graalvm.compiler.options.OptionValues in project graal by oracle.
the class DefaultLoopPolicies method shouldPartiallyUnroll.
@Override
public boolean shouldPartiallyUnroll(LoopEx loop) {
LoopBeginNode loopBegin = loop.loopBegin();
if (!loop.isCounted()) {
loopBegin.getDebug().log(DebugContext.VERBOSE_LEVEL, "shouldPartiallyUnroll %s isn't counted", loopBegin);
return false;
}
OptionValues options = loop.entryPoint().getOptions();
int maxNodes = Options.ExactPartialUnrollMaxNodes.getValue(options);
maxNodes = Math.min(maxNodes, Math.max(0, MaximumDesiredSize.getValue(options) - loop.loopBegin().graph().getNodeCount()));
int size = Math.max(1, loop.size() - 1 - loop.loopBegin().phis().count());
int unrollFactor = loopBegin.getUnrollFactor();
if (unrollFactor == 1) {
double loopFrequency = loopBegin.loopFrequency();
if (loopBegin.isSimpleLoop() && loopFrequency < 5.0) {
loopBegin.getDebug().log(DebugContext.VERBOSE_LEVEL, "shouldPartiallyUnroll %s frequency too low %s ", loopBegin, loopFrequency);
return false;
}
loopBegin.setLoopOrigFrequency(loopFrequency);
}
int maxUnroll = Options.UnrollMaxIterations.getValue(options);
// Now correct size for the next unroll. UnrollMaxIterations == 1 means perform the
// pre/main/post transformation but don't actually unroll the main loop.
size += size;
if (maxUnroll == 1 && loopBegin.isSimpleLoop() || size <= maxNodes && unrollFactor < maxUnroll) {
// Will the next unroll fit?
if ((int) loopBegin.loopOrigFrequency() < (unrollFactor * 2)) {
return false;
}
// Check whether we're allowed to unroll this loop
for (Node node : loop.inside().nodes()) {
if (node instanceof ControlFlowAnchorNode) {
return false;
}
if (node instanceof InvokeNode) {
return false;
}
}
return true;
} else {
loopBegin.getDebug().log(DebugContext.VERBOSE_LEVEL, "shouldPartiallyUnroll %s unrolled loop is too large %s ", loopBegin, size);
return false;
}
}
use of org.graalvm.compiler.options.OptionValues in project graal by oracle.
the class DefaultLoopPolicies method shouldFullUnroll.
@Override
public boolean shouldFullUnroll(LoopEx loop) {
if (!loop.isCounted() || !loop.counted().isConstantMaxTripCount()) {
return false;
}
OptionValues options = loop.entryPoint().getOptions();
CountedLoopInfo counted = loop.counted();
UnsignedLong maxTrips = counted.constantMaxTripCount();
if (maxTrips.equals(0)) {
return loop.canDuplicateLoop();
}
int maxNodes = (counted.isExactTripCount() && counted.isConstantExactTripCount()) ? Options.ExactFullUnrollMaxNodes.getValue(options) : Options.FullUnrollMaxNodes.getValue(options);
maxNodes = Math.min(maxNodes, Math.max(0, MaximumDesiredSize.getValue(options) - loop.loopBegin().graph().getNodeCount()));
int size = Math.max(1, loop.size() - 1 - loop.loopBegin().phis().count());
/* @formatter:off
* The check below should not throw ArithmeticException because:
* maxTrips is guaranteed to be >= 1 by the check above
* - maxTrips * size can not overfow because:
* - maxTrips <= FullUnrollMaxIterations <= Integer.MAX_VALUE
* - 1 <= size <= Integer.MAX_VALUE
* @formatter:on
*/
if (maxTrips.isLessOrEqualTo(Options.FullUnrollMaxIterations.getValue(options)) && maxTrips.minus(1).times(size).isLessOrEqualTo(maxNodes)) {
// check whether we're allowed to unroll this loop
return loop.canDuplicateLoop();
} else {
return false;
}
}
use of org.graalvm.compiler.options.OptionValues in project graal by oracle.
the class ReplacementsParseTest method testCallCopyFirstWithoutInlinePartialIntrinsicExit.
@Test
public void testCallCopyFirstWithoutInlinePartialIntrinsicExit() {
OptionValues options = new OptionValues(getInitialOptions(), InlinePartialIntrinsicExitDuringParsing, false);
inlineInvokeDecision = InlineInvokePlugin.InlineInfo.DO_NOT_INLINE_WITH_EXCEPTION;
try {
byte[] in = { 0, 1, 2, 3, 4 };
byte[] out = new byte[in.length];
test(options, "callCopyFirstWrapper", in, out, true);
test(options, "callCopyFirstWrapper", in, out, false);
} finally {
inlineInvokeDecision = null;
}
}
use of org.graalvm.compiler.options.OptionValues in project graal by oracle.
the class DeoptimizeOnExceptionTest method test3.
@Test
public void test3() {
Assume.assumeTrue("Only works on jdk8 right now", Java8OrEarlier);
ResolvedJavaMethod method = getResolvedJavaMethod("test3Snippet");
for (int i = 0; i < 2; i++) {
Result actual;
boolean expectedCompiledCode = (method.getProfilingInfo().getDeoptimizationCount(DeoptimizationReason.NotCompiledExceptionHandler) != 0);
InstalledCode code = getCode(method, null, false, true, new OptionValues(getInitialOptions(), HighTier.Options.Inline, false));
assertTrue(code.isValid());
try {
actual = new Result(code.executeVarargs(false), null);
} catch (Exception e) {
actual = new Result(null, e);
}
assertTrue(i > 0 == expectedCompiledCode, "expect compiled code to stay around after the first iteration");
assertEquals(new Result(expectedCompiledCode, null), actual);
assertTrue(expectedCompiledCode == code.isValid());
}
}
Aggregations