Search in sources :

Example 61 with InvocationPlugin

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

the class StandardGraphBuilderPlugins method registerArrayPlugins.

private static void registerArrayPlugins(InvocationPlugins plugins, BytecodeProvider bytecodeProvider) {
    Registration r = new Registration(plugins, Array.class, bytecodeProvider);
    r.register2("newInstance", Class.class, int.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unused, ValueNode componentType, ValueNode length) {
            b.addPush(JavaKind.Object, new DynamicNewArrayNode(componentType, length, true));
            return true;
        }
    });
    r.registerMethodSubstitution(ArraySubstitutions.class, "getLength", Object.class);
}
Also used : 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) DynamicNewArrayNode(org.graalvm.compiler.nodes.java.DynamicNewArrayNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 62 with InvocationPlugin

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

the class StandardGraphBuilderPlugins method registerShortPlugins.

private static void registerShortPlugins(InvocationPlugins plugins) {
    Registration r = new Registration(plugins, Short.class);
    r.register1("reverseBytes", short.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
            // return (short) (Integer.reverse(i) >> 16);
            ReverseBytesNode reverse = b.add(new ReverseBytesNode(value));
            RightShiftNode rightShift = b.add(new RightShiftNode(reverse, b.add(ConstantNode.forInt(16))));
            SignExtendNode charCast = b.add(new SignExtendNode(b.add(new NarrowNode(rightShift, 16)), 32));
            b.push(JavaKind.Short, b.append(charCast.canonical(null)));
            return true;
        }
    });
}
Also used : SignExtendNode(org.graalvm.compiler.nodes.calc.SignExtendNode) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) ValueNode(org.graalvm.compiler.nodes.ValueNode) RightShiftNode(org.graalvm.compiler.nodes.calc.RightShiftNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) ReverseBytesNode(org.graalvm.compiler.replacements.nodes.ReverseBytesNode) NarrowNode(org.graalvm.compiler.nodes.calc.NarrowNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 63 with InvocationPlugin

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

the class ReplacementsImpl method getSubstitutionBytecode.

@Override
public Bytecode getSubstitutionBytecode(ResolvedJavaMethod method) {
    InvocationPlugin plugin = graphBuilderPlugins.getInvocationPlugins().lookupInvocation(method);
    if (plugin instanceof MethodSubstitutionPlugin) {
        MethodSubstitutionPlugin msPlugin = (MethodSubstitutionPlugin) plugin;
        ResolvedJavaMethod substitute = msPlugin.getSubstitute(providers.getMetaAccess());
        return msPlugin.getBytecodeProvider().getBytecode(substitute);
    }
    return null;
}
Also used : InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) GeneratedInvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.GeneratedInvocationPlugin) MethodSubstitutionPlugin(org.graalvm.compiler.nodes.graphbuilderconf.MethodSubstitutionPlugin) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 64 with InvocationPlugin

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

the class ReplacementsImpl method getSubstitution.

@Override
public StructuredGraph getSubstitution(ResolvedJavaMethod method, int invokeBci, boolean trackNodeSourcePosition, NodeSourcePosition replaceePosition) {
    StructuredGraph result;
    InvocationPlugin plugin = graphBuilderPlugins.getInvocationPlugins().lookupInvocation(method);
    if (plugin != null && (!plugin.inlineOnly() || invokeBci >= 0)) {
        MetaAccessProvider metaAccess = providers.getMetaAccess();
        if (plugin instanceof MethodSubstitutionPlugin) {
            MethodSubstitutionPlugin msPlugin = (MethodSubstitutionPlugin) plugin;
            ResolvedJavaMethod substitute = msPlugin.getSubstitute(metaAccess);
            StructuredGraph graph = UseSnippetGraphCache.getValue(options) ? graphs.get(substitute) : null;
            if (graph == null || graph.trackNodeSourcePosition() != trackNodeSourcePosition) {
                try (DebugContext debug = openDebugContext("Substitution_", method)) {
                    graph = makeGraph(debug, msPlugin.getBytecodeProvider(), substitute, null, method, trackNodeSourcePosition, replaceePosition);
                    if (!UseSnippetGraphCache.getValue(options)) {
                        return graph;
                    }
                    graph.freeze();
                    graphs.putIfAbsent(substitute, graph);
                    graph = graphs.get(substitute);
                }
            }
            assert graph.isFrozen();
            result = graph;
        } else {
            Bytecode code = new ResolvedJavaMethodBytecode(method);
            ConstantReflectionProvider constantReflection = providers.getConstantReflection();
            ConstantFieldProvider constantFieldProvider = providers.getConstantFieldProvider();
            StampProvider stampProvider = providers.getStampProvider();
            try (DebugContext debug = openDebugContext("Substitution_", method)) {
                result = new IntrinsicGraphBuilder(options, debug, metaAccess, constantReflection, constantFieldProvider, stampProvider, code, invokeBci).buildGraph(plugin);
            }
        }
    } else {
        result = null;
    }
    return result;
}
Also used : StampProvider(org.graalvm.compiler.nodes.spi.StampProvider) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ConstantReflectionProvider(jdk.vm.ci.meta.ConstantReflectionProvider) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) GeneratedInvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.GeneratedInvocationPlugin) ResolvedJavaMethodBytecode(org.graalvm.compiler.bytecode.ResolvedJavaMethodBytecode) Bytecode(org.graalvm.compiler.bytecode.Bytecode) DebugContext(org.graalvm.compiler.debug.DebugContext) MethodSubstitutionPlugin(org.graalvm.compiler.nodes.graphbuilderconf.MethodSubstitutionPlugin) ResolvedJavaMethodBytecode(org.graalvm.compiler.bytecode.ResolvedJavaMethodBytecode) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) ConstantFieldProvider(org.graalvm.compiler.core.common.spi.ConstantFieldProvider)

Example 65 with InvocationPlugin

use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin 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)

Aggregations

InvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin)92 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)89 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)83 ValueNode (org.graalvm.compiler.nodes.ValueNode)74 Registration (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration)66 Receiver (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver)57 ConvertUnknownValueNode (com.oracle.graal.pointsto.nodes.ConvertUnknownValueNode)13 StackValueNode (com.oracle.svm.core.graal.stackvalue.StackValueNode)13 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)9 LogicNode (org.graalvm.compiler.nodes.LogicNode)9 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)8 DeoptimizeNode (org.graalvm.compiler.nodes.DeoptimizeNode)7 JavaConstant (jdk.vm.ci.meta.JavaConstant)6 JavaKind (jdk.vm.ci.meta.JavaKind)6 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)6 ResolvedJavaSymbol (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.ResolvedJavaSymbol)6 InvocationPlugins (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins)5 GetClassNode (org.graalvm.compiler.nodes.extended.GetClassNode)4 AnalysisArraysCopyOfNode (com.oracle.graal.pointsto.nodes.AnalysisArraysCopyOfNode)3 Stamp (org.graalvm.compiler.core.common.type.Stamp)3