Search in sources :

Example 61 with Registration

use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration in project graal by oracle.

the class TruffleGraphBuilderPlugins method registerOptimizedCallTargetPlugins.

public static void registerOptimizedCallTargetPlugins(InvocationPlugins plugins, MetaAccessProvider metaAccess, boolean canDelayIntrinsification, KnownTruffleTypes types) {
    final ResolvedJavaType optimizedCallTargetType = getRuntime().resolveType(metaAccess, "org.graalvm.compiler.truffle.runtime.OptimizedCallTarget");
    Registration r = new Registration(plugins, new ResolvedJavaSymbol(optimizedCallTargetType));
    r.register2("createFrame", new ResolvedJavaSymbol(types.classFrameDescriptor), Object[].class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode descriptor, ValueNode args) {
            if (canDelayIntrinsification) {
                return false;
            }
            if (!descriptor.isJavaConstant()) {
                throw b.bailout("Parameter 'descriptor' is not a compile-time constant");
            }
            ValueNode nonNullArguments = b.add(PiNode.create(args, StampFactory.objectNonNull(StampTool.typeReferenceOrNull(args))));
            b.addPush(JavaKind.Object, new NewFrameNode(b, descriptor, nonNullArguments, types));
            return true;
        }
    });
    r.register2("castArrayFixedLength", Object[].class, int.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode args, ValueNode length) {
            b.addPush(JavaKind.Object, new PiArrayNode(args, length, args.stamp(NodeView.DEFAULT)));
            return true;
        }
    });
    registerUnsafeCast(r, canDelayIntrinsification);
}
Also used : NewFrameNode(org.graalvm.compiler.truffle.compiler.nodes.frame.NewFrameNode) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) ValueNode(org.graalvm.compiler.nodes.ValueNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) PiArrayNode(org.graalvm.compiler.nodes.PiArrayNode) ResolvedJavaSymbol(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.ResolvedJavaSymbol) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 62 with Registration

use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration 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);
}
Also used : GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) TruffleAssumption(org.graalvm.compiler.truffle.compiler.nodes.TruffleAssumption) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) JavaConstant(jdk.vm.ci.meta.JavaConstant) DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode) ResolvedJavaSymbol(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.ResolvedJavaSymbol) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 63 with Registration

use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration 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");
            }
        }
    });
}
Also used : ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) RawLoadNode(org.graalvm.compiler.nodes.extended.RawLoadNode) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) ForceMaterializeNode(org.graalvm.compiler.truffle.compiler.nodes.frame.ForceMaterializeNode) DynamicPiNode(org.graalvm.compiler.nodes.DynamicPiNode) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) BoxNode(org.graalvm.compiler.nodes.extended.BoxNode) CallTargetNode(org.graalvm.compiler.nodes.CallTargetNode) EnsureVirtualizedNode(org.graalvm.compiler.nodes.virtual.EnsureVirtualizedNode) VirtualFrameIsNode(org.graalvm.compiler.truffle.compiler.nodes.frame.VirtualFrameIsNode) RawStoreNode(org.graalvm.compiler.nodes.extended.RawStoreNode) FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) PiNode(org.graalvm.compiler.nodes.PiNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) NewFrameNode(org.graalvm.compiler.truffle.compiler.nodes.frame.NewFrameNode) CompareNode(org.graalvm.compiler.nodes.calc.CompareNode) UnsafeAccessNode(org.graalvm.compiler.nodes.extended.UnsafeAccessNode) AllowMaterializeNode(org.graalvm.compiler.truffle.compiler.nodes.frame.AllowMaterializeNode) LogicConstantNode(org.graalvm.compiler.nodes.LogicConstantNode) BranchProbabilityNode(org.graalvm.compiler.nodes.extended.BranchProbabilityNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) ConditionAnchorNode(org.graalvm.compiler.nodes.ConditionAnchorNode) InstanceOfDynamicNode(org.graalvm.compiler.nodes.java.InstanceOfDynamicNode) UnsignedMulHighNode(org.graalvm.compiler.replacements.nodes.arithmetic.UnsignedMulHighNode) VirtualFrameGetNode(org.graalvm.compiler.truffle.compiler.nodes.frame.VirtualFrameGetNode) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) GuardedUnsafeLoadNode(org.graalvm.compiler.nodes.extended.GuardedUnsafeLoadNode) DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode) NeverPartOfCompilationNode(org.graalvm.compiler.truffle.compiler.nodes.asserts.NeverPartOfCompilationNode) PiArrayNode(org.graalvm.compiler.nodes.PiArrayNode) VirtualFrameSetNode(org.graalvm.compiler.truffle.compiler.nodes.frame.VirtualFrameSetNode) IntegerMulHighNode(org.graalvm.compiler.replacements.nodes.arithmetic.IntegerMulHighNode) Node(org.graalvm.compiler.graph.Node) IsCompilationConstantNode(org.graalvm.compiler.truffle.compiler.nodes.IsCompilationConstantNode) BoxNode(org.graalvm.compiler.nodes.extended.BoxNode) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) ResolvedJavaSymbol(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.ResolvedJavaSymbol) NeverPartOfCompilationNode(org.graalvm.compiler.truffle.compiler.nodes.asserts.NeverPartOfCompilationNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) ValueNode(org.graalvm.compiler.nodes.ValueNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 64 with Registration

use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration in project graal by oracle.

the class TruffleGraphBuilderPlugins method registerFrameWithBoxingPlugins.

public static void registerFrameWithBoxingPlugins(InvocationPlugins plugins, MetaAccessProvider metaAccess, boolean canDelayIntrinsification) {
    ResolvedJavaType frameWithBoxingType = getRuntime().resolveType(metaAccess, "org.graalvm.compiler.truffle.runtime.FrameWithBoxing");
    Registration r = new Registration(plugins, new ResolvedJavaSymbol(frameWithBoxingType));
    registerFrameMethods(r);
    registerUnsafeCast(r, canDelayIntrinsification);
}
Also used : Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) ResolvedJavaSymbol(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.ResolvedJavaSymbol) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Example 65 with Registration

use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration in project graal by oracle.

the class TruffleGraphBuilderPlugins method registerFrameWithoutBoxingPlugins.

public static void registerFrameWithoutBoxingPlugins(InvocationPlugins plugins, MetaAccessProvider metaAccess, boolean canDelayIntrinsification, ConstantReflectionProvider constantReflection, KnownTruffleTypes types) {
    ResolvedJavaType frameWithoutBoxingType = getRuntime().resolveType(metaAccess, "org.graalvm.compiler.truffle.runtime.FrameWithoutBoxing");
    Registration r = new Registration(plugins, new ResolvedJavaSymbol(frameWithoutBoxingType));
    registerFrameMethods(r);
    registerUnsafeCast(r, canDelayIntrinsification);
    registerUnsafeLoadStorePlugins(r, canDelayIntrinsification, null, JavaKind.Int, JavaKind.Long, JavaKind.Float, JavaKind.Double, JavaKind.Object);
    if (TruffleCompilerOptions.getValue(Options.TruffleIntrinsifyFrameAccess)) {
        registerFrameAccessors(r, JavaKind.Object, constantReflection, types);
        registerFrameAccessors(r, JavaKind.Long, constantReflection, types);
        registerFrameAccessors(r, JavaKind.Int, constantReflection, types);
        registerFrameAccessors(r, JavaKind.Double, constantReflection, types);
        registerFrameAccessors(r, JavaKind.Float, constantReflection, types);
        registerFrameAccessors(r, JavaKind.Boolean, constantReflection, types);
        registerFrameAccessors(r, JavaKind.Byte, constantReflection, types);
    }
}
Also used : Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) ResolvedJavaSymbol(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.ResolvedJavaSymbol) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Aggregations

Registration (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration)88 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)66 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)66 InvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin)66 ValueNode (org.graalvm.compiler.nodes.ValueNode)60 Receiver (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver)52 ConvertUnknownValueNode (com.oracle.graal.pointsto.nodes.ConvertUnknownValueNode)13 StackValueNode (com.oracle.svm.core.graal.stackvalue.StackValueNode)13 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)10 LogicNode (org.graalvm.compiler.nodes.LogicNode)9 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)7 ResolvedJavaSymbol (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.ResolvedJavaSymbol)7 JavaKind (jdk.vm.ci.meta.JavaKind)5 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)5 DeoptimizeNode (org.graalvm.compiler.nodes.DeoptimizeNode)5 ConditionalNode (org.graalvm.compiler.nodes.calc.ConditionalNode)5 GetClassNode (org.graalvm.compiler.nodes.extended.GetClassNode)4 AnalysisArraysCopyOfNode (com.oracle.graal.pointsto.nodes.AnalysisArraysCopyOfNode)3 JavaConstant (jdk.vm.ci.meta.JavaConstant)3 BlackholeNode (org.graalvm.compiler.nodes.debug.BlackholeNode)3