Search in sources :

Example 1 with NeverStripMineNode

use of org.graalvm.compiler.nodes.debug.NeverStripMineNode in project graal by oracle.

the class StandardGraphBuilderPlugins method registerGraalDirectivesPlugins.

private static void registerGraalDirectivesPlugins(InvocationPlugins plugins, SnippetReflectionProvider snippetReflection) {
    Registration r = new Registration(plugins, GraalDirectives.class);
    r.register(new DeoptimizePlugin(snippetReflection, None, TransferToInterpreter, false, "deoptimize"));
    r.register(new DeoptimizePlugin(snippetReflection, InvalidateReprofile, TransferToInterpreter, false, "deoptimizeAndInvalidate"));
    r.register(new DeoptimizePlugin(snippetReflection, null, null, null, "deoptimize", DeoptimizationAction.class, DeoptimizationReason.class, boolean.class));
    r.register(new DeoptimizePlugin(snippetReflection, null, null, null, "deoptimize", DeoptimizationAction.class, DeoptimizationReason.class, SpeculationReason.class));
    r.register(new RequiredInlineOnlyInvocationPlugin("inCompiledCode") {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            b.addPush(JavaKind.Boolean, ConstantNode.forBoolean(true));
            return true;
        }
    });
    r.register(new RequiredInlineOnlyInvocationPlugin("inIntrinsic") {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            b.addPush(JavaKind.Boolean, ConstantNode.forBoolean(b.parsingIntrinsic()));
            return true;
        }
    });
    r.register(new RequiredInlineOnlyInvocationPlugin("controlFlowAnchor") {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            b.add(new ControlFlowAnchorNode());
            return true;
        }
    });
    r.register(new RequiredInlineOnlyInvocationPlugin("neverStripMine") {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            b.add(new NeverStripMineNode());
            return true;
        }
    });
    r.register(new RequiredInlineOnlyInvocationPlugin("sideEffect") {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            b.add(new SideEffectNode());
            return true;
        }
    });
    r.register(new RequiredInlineOnlyInvocationPlugin("sideEffect", int.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode a) {
            b.addPush(JavaKind.Int, new SideEffectNode(a));
            return true;
        }
    });
    r.register(new RequiredInlineOnlyInvocationPlugin("trustedBox", Object.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode a) {
            b.addPush(JavaKind.Object, new TrustedBoxedValue(a));
            return true;
        }
    });
    r.register(new RequiredInlineOnlyInvocationPlugin("assumeStableDimension", Object.class, int.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode array, ValueNode dimension) {
            if (array instanceof ConstantNode && b.getMetaAccess().lookupJavaType(array.asJavaConstant()).isArray()) {
                if (dimension instanceof ConstantNode && dimension.stamp(NodeView.DEFAULT) instanceof IntegerStamp) {
                    int stableDim = dimension.asJavaConstant().asInt();
                    ConstantNode c = ConstantNode.forConstant(array.asJavaConstant(), stableDim, false, b.getMetaAccess());
                    b.addPush(JavaKind.Object, c);
                    return true;
                }
            }
            throw GraalError.shouldNotReachHere("Illegal usage of stable array intrinsic assumeStableDimension(array, dimension): " + "This compiler intrinsic can only be used iff array is a constant node (i.e., constant field) and iff " + "dimension is a constant int. It will replace the constant array with a new constant that additionally sets the stable" + "dimensions to the int parameter supplied.");
        }
    });
    r.register(new RequiredInlineOnlyInvocationPlugin("injectBranchProbability", double.class, boolean.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode probability, ValueNode condition) {
            b.addPush(JavaKind.Boolean, new BranchProbabilityNode(probability, condition));
            return true;
        }
    });
    r.register(new RequiredInlineOnlyInvocationPlugin("injectIterationCount", double.class, boolean.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode iterations, ValueNode condition) {
            // injectBranchProbability(1. - 1. / iterations, condition)
            if (iterations.isJavaConstant()) {
                double iterationsConstant;
                if (iterations.stamp(NodeView.DEFAULT) instanceof IntegerStamp) {
                    iterationsConstant = iterations.asJavaConstant().asLong();
                } else if (iterations.stamp(NodeView.DEFAULT) instanceof FloatStamp) {
                    iterationsConstant = iterations.asJavaConstant().asDouble();
                } else {
                    return false;
                }
                double probability = 1. - 1. / iterationsConstant;
                ValueNode probabilityNode = b.add(ConstantNode.forDouble(probability));
                b.addPush(JavaKind.Boolean, new BranchProbabilityNode(probabilityNode, condition));
                return true;
            }
            return false;
        }
    });
    for (JavaKind kind : JavaKind.values()) {
        if ((kind.isPrimitive() && kind != JavaKind.Void) || kind == JavaKind.Object) {
            Class<?> javaClass = getJavaClass(kind);
            r.register(new RequiredInlineOnlyInvocationPlugin("blackhole", javaClass) {

                @Override
                public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
                    b.add(new BlackholeNode(value));
                    return true;
                }
            });
            r.register(new RequiredInlineOnlyInvocationPlugin("bindToRegister", javaClass) {

                @Override
                public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
                    b.add(new BindToRegisterNode(value));
                    return true;
                }
            });
            r.register(new RequiredInvocationPlugin("opaque", javaClass) {

                @Override
                public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
                    b.addPush(kind, new OpaqueNode(value));
                    return true;
                }
            });
        }
    }
    r.register(new RequiredInlineOnlyInvocationPlugin("spillRegisters") {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            b.add(new SpillRegistersNode());
            return true;
        }
    });
    r.register(new RequiredInlineOnlyInvocationPlugin("guardingNonNull", Object.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
            b.addPush(value.getStackKind(), b.nullCheckedValue(value));
            return true;
        }
    });
    r.register(new RequiredInlineOnlyInvocationPlugin("ensureVirtualized", Object.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object) {
            b.add(new EnsureVirtualizedNode(object, false));
            return true;
        }
    });
    r.register(new RequiredInlineOnlyInvocationPlugin("ensureVirtualizedHere", Object.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object) {
            b.add(new EnsureVirtualizedNode(object, true));
            return true;
        }
    });
    r.register(new RequiredInvocationPlugin("breakpoint") {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            b.add(new BreakpointNode());
            return true;
        }
    });
    for (JavaKind kind : JavaKind.values()) {
        if ((kind.isPrimitive() && kind != JavaKind.Void) || kind == JavaKind.Object) {
            Class<?> javaClass = getJavaClass(kind);
            r.register(new RequiredInlineOnlyInvocationPlugin("isCompilationConstant", javaClass) {

                @Override
                public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
                    b.addPush(JavaKind.Boolean, ConstantNode.forBoolean(value.isJavaConstant()));
                    return true;
                }
            });
        }
    }
}
Also used : EnsureVirtualizedNode(org.graalvm.compiler.nodes.virtual.EnsureVirtualizedNode) SpillRegistersNode(org.graalvm.compiler.nodes.debug.SpillRegistersNode) RequiredInvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.RequiredInvocationPlugin) BreakpointNode(org.graalvm.compiler.nodes.BreakpointNode) OpaqueNode(org.graalvm.compiler.nodes.extended.OpaqueNode) SideEffectNode(org.graalvm.compiler.nodes.debug.SideEffectNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) DeoptimizationReason(jdk.vm.ci.meta.DeoptimizationReason) NeverStripMineNode(org.graalvm.compiler.nodes.debug.NeverStripMineNode) JavaKind(jdk.vm.ci.meta.JavaKind) BindToRegisterNode(org.graalvm.compiler.nodes.debug.BindToRegisterNode) RequiredInlineOnlyInvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.RequiredInlineOnlyInvocationPlugin) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) BranchProbabilityNode(org.graalvm.compiler.nodes.extended.BranchProbabilityNode) FloatStamp(org.graalvm.compiler.core.common.type.FloatStamp) SpeculationReason(jdk.vm.ci.meta.SpeculationLog.SpeculationReason) TrustedBoxedValue(org.graalvm.compiler.nodes.extended.BoxNode.TrustedBoxedValue) BlackholeNode(org.graalvm.compiler.nodes.debug.BlackholeNode) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) ControlFlowAnchorNode(org.graalvm.compiler.nodes.debug.ControlFlowAnchorNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) DeoptimizationAction(jdk.vm.ci.meta.DeoptimizationAction) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Aggregations

DeoptimizationAction (jdk.vm.ci.meta.DeoptimizationAction)1 DeoptimizationReason (jdk.vm.ci.meta.DeoptimizationReason)1 JavaKind (jdk.vm.ci.meta.JavaKind)1 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)1 SpeculationReason (jdk.vm.ci.meta.SpeculationLog.SpeculationReason)1 FloatStamp (org.graalvm.compiler.core.common.type.FloatStamp)1 IntegerStamp (org.graalvm.compiler.core.common.type.IntegerStamp)1 BreakpointNode (org.graalvm.compiler.nodes.BreakpointNode)1 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)1 ValueNode (org.graalvm.compiler.nodes.ValueNode)1 BindToRegisterNode (org.graalvm.compiler.nodes.debug.BindToRegisterNode)1 BlackholeNode (org.graalvm.compiler.nodes.debug.BlackholeNode)1 ControlFlowAnchorNode (org.graalvm.compiler.nodes.debug.ControlFlowAnchorNode)1 NeverStripMineNode (org.graalvm.compiler.nodes.debug.NeverStripMineNode)1 SideEffectNode (org.graalvm.compiler.nodes.debug.SideEffectNode)1 SpillRegistersNode (org.graalvm.compiler.nodes.debug.SpillRegistersNode)1 TrustedBoxedValue (org.graalvm.compiler.nodes.extended.BoxNode.TrustedBoxedValue)1 BranchProbabilityNode (org.graalvm.compiler.nodes.extended.BranchProbabilityNode)1 OpaqueNode (org.graalvm.compiler.nodes.extended.OpaqueNode)1 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)1