use of org.graalvm.compiler.nodes.debug.ControlFlowAnchorNode 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.nodes.debug.ControlFlowAnchorNode in project graal by oracle.
the class StandardGraphBuilderPlugins method registerGraalDirectivesPlugins.
private static void registerGraalDirectivesPlugins(InvocationPlugins plugins) {
Registration r = new Registration(plugins, GraalDirectives.class);
r.register0("deoptimize", new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
b.add(new DeoptimizeNode(DeoptimizationAction.None, DeoptimizationReason.TransferToInterpreter));
return true;
}
});
r.register0("deoptimizeAndInvalidate", new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
b.add(new DeoptimizeNode(DeoptimizationAction.InvalidateReprofile, DeoptimizationReason.TransferToInterpreter));
return true;
}
});
r.register0("deoptimizeAndInvalidateWithSpeculation", new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
GraalError.guarantee(b.getGraph().getSpeculationLog() != null, "A speculation log is need to use `deoptimizeAndInvalidateWithSpeculation`");
BytecodePosition pos = new BytecodePosition(null, b.getMethod(), b.bci());
DirectiveSpeculationReason reason = new DirectiveSpeculationReason(pos);
JavaConstant speculation;
if (b.getGraph().getSpeculationLog().maySpeculate(reason)) {
speculation = b.getGraph().getSpeculationLog().speculate(reason);
} else {
speculation = JavaConstant.defaultForKind(JavaKind.Object);
}
b.add(new DeoptimizeNode(DeoptimizationAction.InvalidateReprofile, DeoptimizationReason.TransferToInterpreter, speculation));
return true;
}
});
r.register0("inCompiledCode", new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
b.addPush(JavaKind.Boolean, ConstantNode.forBoolean(true));
return true;
}
});
r.register0("controlFlowAnchor", new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
b.add(new ControlFlowAnchorNode());
return true;
}
});
r.register2("injectBranchProbability", double.class, boolean.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode probability, ValueNode condition) {
b.addPush(JavaKind.Boolean, new BranchProbabilityNode(probability, condition));
return true;
}
});
InvocationPlugin blackholePlugin = new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
b.add(new BlackholeNode(value));
return true;
}
};
InvocationPlugin bindToRegisterPlugin = new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
b.add(new BindToRegisterNode(value));
return true;
}
};
for (JavaKind kind : JavaKind.values()) {
if ((kind.isPrimitive() && kind != JavaKind.Void) || kind == JavaKind.Object) {
Class<?> javaClass = kind == JavaKind.Object ? Object.class : kind.toJavaClass();
r.register1("blackhole", javaClass, blackholePlugin);
r.register1("bindToRegister", javaClass, bindToRegisterPlugin);
r.register1("opaque", javaClass, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
b.addPush(kind, new OpaqueNode(value));
return true;
}
});
}
}
InvocationPlugin spillPlugin = new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
b.add(new SpillRegistersNode());
return true;
}
};
r.register0("spillRegisters", spillPlugin);
r.register1("guardingNonNull", Object.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
b.addPush(value.getStackKind(), b.nullCheckedValue(value));
return true;
}
});
r.register1("ensureVirtualized", Object.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object) {
b.add(new EnsureVirtualizedNode(object, false));
return true;
}
});
r.register1("ensureVirtualizedHere", Object.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object) {
b.add(new EnsureVirtualizedNode(object, true));
return true;
}
});
}
use of org.graalvm.compiler.nodes.debug.ControlFlowAnchorNode in project graal by oracle.
the class ProbabilityDirectiveTest method returnValue.
private static int returnValue(AbstractBeginNode b) {
ControlFlowAnchorNode anchor = (ControlFlowAnchorNode) b.next();
ReturnNode returnNode = (ReturnNode) anchor.next();
return returnNode.result().asJavaConstant().asInt();
}
use of org.graalvm.compiler.nodes.debug.ControlFlowAnchorNode in project graal by oracle.
the class ControlFlowAnchorDirectiveTest method checkLowTierGraph.
@Override
protected boolean checkLowTierGraph(StructuredGraph graph) {
List<ControlFlowAnchorNode> anchors = graph.getNodes().filter(ControlFlowAnchorNode.class).snapshot();
for (int i = 0; i < anchors.size(); i++) {
ControlFlowAnchorNode a = anchors.get(i);
for (int j = i + 1; j < anchors.size(); j++) {
ControlFlowAnchorNode b = anchors.get(j);
if (a.valueEquals(b)) {
Assert.fail("found duplicated control flow anchors (" + a + " and " + b + ")");
}
}
}
for (NodeCount nodeCount : getNodeCountAnnotations(graph)) {
NodeIterable<? extends Node> nodes = graph.getNodes().filter(nodeCount.nodeClass());
Assert.assertEquals(nodeCount.nodeClass().getSimpleName(), nodeCount.expectedCount(), nodes.count());
}
return true;
}
Aggregations