use of org.graalvm.compiler.nodes.debug.OpaqueNode in project graal by oracle.
the class LongNodeChainTest method longAddChain.
private void longAddChain(boolean reverse) {
HighTierContext context = getDefaultHighTierContext();
OptionValues options = getInitialOptions();
StructuredGraph graph = new StructuredGraph.Builder(options, DebugContext.create(options, DebugHandlersFactory.LOADER)).build();
ValueNode constant = graph.unique(ConstantNode.forPrimitive(JavaConstant.INT_1));
ValueNode value = null;
if (reverse) {
// Make sure the constant's stamp is not used to infer the add node's stamp.
OpaqueNode opaque = graph.unique(new OpaqueNode(constant));
constant = opaque;
AddNode addNode = graph.unique(new AddNode(constant, constant));
value = addNode;
for (int i = 1; i < N; ++i) {
AddNode newAddNode = graph.addWithoutUnique(new AddNode(constant, constant));
addNode.setY(newAddNode);
addNode = newAddNode;
}
opaque.replaceAndDelete(opaque.getValue());
} else {
value = constant;
for (int i = 0; i < N; ++i) {
value = graph.unique(new AddNode(constant, value));
}
}
ReturnNode returnNode = graph.add(new ReturnNode(value));
graph.start().setNext(returnNode);
for (SchedulingStrategy s : Strategies) {
new SchedulePhase(s).apply(graph);
}
new CanonicalizerPhase().apply(graph, context);
JavaConstant asConstant = (JavaConstant) returnNode.result().asConstant();
Assert.assertEquals(N + 1, asConstant.asInt());
}
use of org.graalvm.compiler.nodes.debug.OpaqueNode in project graal by oracle.
the class GuardedIntrinsicTest method registerInvocationPlugins.
@Override
protected void registerInvocationPlugins(InvocationPlugins invocationPlugins) {
Registration r = new Registration(invocationPlugins, Super.class);
r.register1("getAge", Receiver.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
ConstantNode res = b.add(ConstantNode.forInt(new Super().getAge()));
b.add(new OpaqueNode(res));
b.push(JavaKind.Int, res);
return true;
}
});
super.registerInvocationPlugins(invocationPlugins);
}
use of org.graalvm.compiler.nodes.debug.OpaqueNode in project graal by oracle.
the class DataPatchTest method registerInvocationPlugins.
@Override
protected void registerInvocationPlugins(InvocationPlugins invocationPlugins) {
Registration r = new Registration(invocationPlugins, DataPatchTest.class);
r.register1("compressUncompress", Object.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode arg) {
CompressEncoding encoding = runtime().getVMConfig().getOopEncoding();
ValueNode compressed = b.add(HotSpotCompressionNode.compress(arg, encoding));
ValueNode proxy = b.add(new OpaqueNode(compressed));
b.addPush(JavaKind.Object, HotSpotCompressionNode.uncompress(proxy, encoding));
return true;
}
});
super.registerInvocationPlugins(invocationPlugins);
}
use of org.graalvm.compiler.nodes.debug.OpaqueNode 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.OpaqueNode in project graal by oracle.
the class ReplacementsParseTest method testGraph.
@SuppressWarnings("try")
private void testGraph(String name) {
StructuredGraph graph = parseEager(name, StructuredGraph.AllowAssumptions.YES);
try (DebugContext.Scope s0 = graph.getDebug().scope(name, graph)) {
for (OpaqueNode node : graph.getNodes().filter(OpaqueNode.class)) {
node.replaceAndDelete(node.getValue());
}
HighTierContext context = getDefaultHighTierContext();
CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
new FloatingReadPhase().apply(graph);
canonicalizer.apply(graph, context);
new DeadCodeEliminationPhase().apply(graph);
new GuardLoweringPhase().apply(graph, getDefaultMidTierContext());
new FrameStateAssignmentPhase().apply(graph);
} catch (Throwable e) {
throw graph.getDebug().handle(e);
}
}
Aggregations