use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin in project graal by oracle.
the class TruffleGraphBuilderPlugins method registerOptimizedAssumptionPlugins.
public static void registerOptimizedAssumptionPlugins(InvocationPlugins plugins, MetaAccessProvider metaAccess, KnownTruffleTypes types) {
ResolvedJavaType optimizedAssumptionType = getRuntime().resolveType(metaAccess, "org.graalvm.compiler.truffle.runtime.OptimizedAssumption");
Registration r = new Registration(plugins, new ResolvedJavaSymbol(optimizedAssumptionType), null);
InvocationPlugin plugin = new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
if (receiver.isConstant() && b.getAssumptions() != null) {
JavaConstant assumption = (JavaConstant) receiver.get().asConstant();
if (b.getConstantReflection().readFieldValue(types.fieldOptimizedAssumptionIsValid, assumption).asBoolean()) {
if (targetMethod.getName().equals("isValid")) {
b.addPush(JavaKind.Boolean, ConstantNode.forBoolean(true));
} else {
assert targetMethod.getName().equals("check") : targetMethod;
}
b.getAssumptions().record(new TruffleAssumption(assumption));
} else {
if (targetMethod.getName().equals("isValid")) {
b.addPush(JavaKind.Boolean, ConstantNode.forBoolean(false));
} else {
assert targetMethod.getName().equals("check") : targetMethod;
b.add(new DeoptimizeNode(DeoptimizationAction.InvalidateRecompile, DeoptimizationReason.None));
}
}
return true;
} else {
return false;
}
}
};
r.register1("isValid", Receiver.class, plugin);
r.register1("check", Receiver.class, plugin);
}
use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin in project graal by oracle.
the class TruffleGraphBuilderPlugins method registerCompilerAssertsPlugins.
public static void registerCompilerAssertsPlugins(InvocationPlugins plugins, MetaAccessProvider metaAccess, boolean canDelayIntrinsification) {
final ResolvedJavaType compilerAssertsType = getRuntime().resolveType(metaAccess, "com.oracle.truffle.api.CompilerAsserts");
Registration r = new Registration(plugins, new ResolvedJavaSymbol(compilerAssertsType));
r.register1("partialEvaluationConstant", Object.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
ValueNode curValue = value;
if (curValue instanceof BoxNode) {
BoxNode boxNode = (BoxNode) curValue;
curValue = boxNode.getValue();
}
if (curValue.isConstant()) {
return true;
} else if (canDelayIntrinsification) {
return false;
} else {
StringBuilder sb = new StringBuilder();
sb.append(curValue);
if (curValue instanceof ValuePhiNode) {
ValuePhiNode valuePhi = (ValuePhiNode) curValue;
sb.append(" (");
for (Node n : valuePhi.inputs()) {
sb.append(n);
sb.append("; ");
}
sb.append(")");
}
value.getDebug().dump(DebugContext.VERBOSE_LEVEL, value.graph(), "Graph before bailout at node %s", sb);
throw b.bailout("Partial evaluation did not reduce value to a constant, is a regular compiler node: " + sb);
}
}
});
r.register0("neverPartOfCompilation", new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
b.add(new NeverPartOfCompilationNode("CompilerAsserts.neverPartOfCompilation()"));
return true;
}
});
r.register1("neverPartOfCompilation", String.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode message) {
if (message.isConstant()) {
String messageString = message.asConstant().toValueString();
b.add(new NeverPartOfCompilationNode(messageString));
return true;
} else {
throw b.bailout("message for never part of compilation is non-constant");
}
}
});
}
use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin in project graal by oracle.
the class HotSpotTruffleGraphBuilderPlugins method registerCompilationFinalReferencePlugins.
static void registerCompilationFinalReferencePlugins(InvocationPlugins plugins, boolean canDelayIntrinsification, HotSpotKnownTruffleTypes types) {
InvocationPlugins.Registration r = new InvocationPlugins.Registration(plugins, Reference.class);
r.register1("get", InvocationPlugin.Receiver.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
if (!canDelayIntrinsification && receiver.isConstant()) {
JavaConstant constant = (JavaConstant) receiver.get().asConstant();
if (constant.isNonNull()) {
if (types.classWeakReference.isInstance(constant) || types.classSoftReference.isInstance(constant)) {
JavaConstant referent = b.getConstantReflection().readFieldValue(types.referenceReferent, constant);
b.addPush(JavaKind.Object, ConstantNode.forConstant(referent, b.getMetaAccess()));
return true;
}
}
}
return false;
}
});
}
use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin in project graal by oracle.
the class MethodTypeFlowBuilder method parse.
@SuppressWarnings("try")
private boolean parse() {
OptionValues options = bb.getOptions();
DebugContext debug = DebugContext.create(options, new GraalDebugHandlersFactory(bb.getProviders().getSnippetReflection()));
try (Indent indent = debug.logAndIndent("parse graph %s", method)) {
boolean needParsing = false;
graph = method.buildGraph(debug, method, bb.getProviders(), Purpose.ANALYSIS);
if (graph == null) {
InvocationPlugin plugin = bb.getProviders().getGraphBuilderPlugins().getInvocationPlugins().lookupInvocation(method);
if (plugin != null && !plugin.inlineOnly()) {
Bytecode code = new ResolvedJavaMethodBytecode(method);
graph = new SubstrateIntrinsicGraphBuilder(options, debug, bb.getProviders().getMetaAccess(), bb.getProviders().getConstantReflection(), bb.getProviders().getConstantFieldProvider(), bb.getProviders().getStampProvider(), code).buildGraph(plugin);
}
}
if (graph == null) {
if (!method.hasBytecodes()) {
return false;
}
needParsing = true;
graph = new StructuredGraph.Builder(options, debug).method(method).build();
}
try (DebugContext.Scope s = debug.scope("ClosedWorldAnalysis", graph, method, this)) {
// enable this logging to get log output in compilation passes
try (Indent indent2 = debug.logAndIndent("parse graph phases")) {
if (needParsing) {
GraphBuilderConfiguration config = GraphBuilderConfiguration.getDefault(bb.getProviders().getGraphBuilderPlugins()).withEagerResolving(true).withUnresolvedIsError(PointstoOptions.UnresolvedIsError.getValue(bb.getOptions())).withNodeSourcePosition(true).withBytecodeExceptionMode(BytecodeExceptionMode.CheckAll);
bb.getHostVM().createGraphBuilderPhase(bb.getProviders(), config, OptimisticOptimizations.NONE, null).apply(graph);
}
} catch (PermanentBailoutException ex) {
bb.getUnsupportedFeatures().addMessage(method.format("%H.%n(%p)"), method, ex.getLocalizedMessage(), null, ex);
return false;
}
// Register used types and fields before canonicalization can optimize them.
registerUsedElements(bb, graph, methodFlow);
new CanonicalizerPhase().apply(graph, new PhaseContext(bb.getProviders()));
// Do it again after canonicalization changed type checks and field accesses.
registerUsedElements(bb, graph, methodFlow);
} catch (Throwable e) {
throw debug.handle(e);
}
}
return true;
}
use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin in project graal by oracle.
the class PointstoGraphBuilderPlugins method registerSystemPlugins.
public static void registerSystemPlugins(InvocationPlugins plugins) {
Registration r = new Registration(plugins, System.class).setAllowOverwrite(true);
r.register5("arraycopy", Object.class, int.class, Object.class, int.class, int.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode src, ValueNode srcPos, ValueNode dest, ValueNode destPos, ValueNode length) {
b.add(new BasicArrayCopyNode(BasicArrayCopyNode.TYPE, src, srcPos, dest, destPos, length, null, b.bci()));
return true;
}
});
}
Aggregations