Search in sources :

Example 26 with ResolvedJavaMethod

use of jdk.vm.ci.meta.ResolvedJavaMethod in project graal by oracle.

the class StandardGraphBuilderPlugins method registerFloatPlugins.

private static void registerFloatPlugins(InvocationPlugins plugins) {
    Registration r = new Registration(plugins, Float.class);
    r.register1("floatToRawIntBits", float.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
            b.push(JavaKind.Int, b.append(ReinterpretNode.create(JavaKind.Int, value, NodeView.DEFAULT)));
            return true;
        }
    });
    r.register1("intBitsToFloat", int.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
            b.push(JavaKind.Float, b.append(ReinterpretNode.create(JavaKind.Float, value, NodeView.DEFAULT)));
            return true;
        }
    });
}
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) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 27 with ResolvedJavaMethod

use of jdk.vm.ci.meta.ResolvedJavaMethod in project graal by oracle.

the class StandardGraphBuilderPlugins method registerStringPlugins.

private static void registerStringPlugins(InvocationPlugins plugins, BytecodeProvider bytecodeProvider, SnippetReflectionProvider snippetReflection) {
    final Registration r = new Registration(plugins, String.class, bytecodeProvider);
    r.register1("hashCode", Receiver.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            if (receiver.isConstant()) {
                String s = snippetReflection.asObject(String.class, (JavaConstant) receiver.get().asConstant());
                b.addPush(JavaKind.Int, b.add(ConstantNode.forInt(s.hashCode())));
                return true;
            }
            return false;
        }
    });
    if (Java8OrEarlier) {
        r.registerMethodSubstitution(StringSubstitutions.class, "equals", Receiver.class, Object.class);
        r.register7("indexOf", char[].class, int.class, int.class, char[].class, int.class, int.class, int.class, new StringIndexOfConstantPlugin());
        Registration sr = new Registration(plugins, StringSubstitutions.class);
        sr.register1("getValue", String.class, new InvocationPlugin() {

            @Override
            public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
                ResolvedJavaField field = b.getMetaAccess().lookupJavaField(STRING_VALUE_FIELD);
                b.addPush(JavaKind.Object, LoadFieldNode.create(b.getConstantFieldProvider(), b.getConstantReflection(), b.getMetaAccess(), b.getOptions(), b.getAssumptions(), value, field, false, false));
                return true;
            }
        });
    }
}
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) JavaConstant(jdk.vm.ci.meta.JavaConstant) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField)

Example 28 with ResolvedJavaMethod

use of jdk.vm.ci.meta.ResolvedJavaMethod in project graal by oracle.

the class StandardGraphBuilderPlugins method registerIntegerLongPlugins.

private static void registerIntegerLongPlugins(InvocationPlugins plugins, JavaKind kind) {
    Class<?> declaringClass = kind.toBoxedJavaClass();
    Class<?> type = kind.toJavaClass();
    Registration r = new Registration(plugins, declaringClass);
    r.register1("reverseBytes", type, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
            b.push(kind, b.append(new ReverseBytesNode(value).canonical(null)));
            return true;
        }
    });
    r.register2("divideUnsigned", type, type, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode dividend, ValueNode divisor) {
            b.push(kind, b.append(UnsignedDivNode.create(dividend, divisor, NodeView.DEFAULT)));
            return true;
        }
    });
    r.register2("remainderUnsigned", type, type, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode dividend, ValueNode divisor) {
            b.push(kind, b.append(UnsignedRemNode.create(dividend, divisor, NodeView.DEFAULT)));
            return true;
        }
    });
}
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) ReverseBytesNode(org.graalvm.compiler.replacements.nodes.ReverseBytesNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 29 with ResolvedJavaMethod

use of jdk.vm.ci.meta.ResolvedJavaMethod in project graal by oracle.

the class MacroNode method lower.

@Override
public void lower(LoweringTool tool) {
    StructuredGraph replacementGraph = getLoweredSnippetGraph(tool);
    InvokeNode invoke = replaceWithInvoke();
    assert invoke.verify();
    if (replacementGraph != null) {
        // receiver can be lowered if necessary
        if (!targetMethod.isStatic()) {
            ValueNode nonNullReceiver = InliningUtil.nonNullReceiver(invoke);
            if (nonNullReceiver instanceof Lowerable) {
                ((Lowerable) nonNullReceiver).lower(tool);
            }
        }
        InliningUtil.inline(invoke, replacementGraph, false, targetMethod);
        replacementGraph.getDebug().dump(DebugContext.DETAILED_LEVEL, graph(), "After inlining replacement %s", replacementGraph);
    } else {
        if (isPlaceholderBci(invoke.bci())) {
            throw new GraalError("%s: cannot lower to invoke with placeholder BCI: %s", graph(), this);
        }
        if (invoke.stateAfter() == null) {
            ResolvedJavaMethod method = graph().method();
            if (method.getAnnotation(MethodSubstitution.class) != null || method.getAnnotation(Snippet.class) != null) {
                // implementation in JDK9.
                throw new GraalError("%s macro created for call to %s in %s must be lowerable to a snippet or intrinsic graph. " + "Maybe a macro node is not needed for this method in the current JDK?", getClass().getSimpleName(), targetMethod.format("%h.%n(%p)"), graph());
            }
            throw new GraalError("%s: cannot lower to invoke without state: %s", graph(), this);
        }
        invoke.lower(tool);
    }
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) GraalError(org.graalvm.compiler.debug.GraalError) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) Lowerable(org.graalvm.compiler.nodes.spi.Lowerable) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 30 with ResolvedJavaMethod

use of jdk.vm.ci.meta.ResolvedJavaMethod in project graal by oracle.

the class PartialEvaluator method createGraph.

@SuppressWarnings("try")
public StructuredGraph createGraph(DebugContext debug, final CompilableTruffleAST compilable, TruffleInliningPlan inliningPlan, AllowAssumptions allowAssumptions, CompilationIdentifier compilationId, SpeculationLog log, Cancellable cancellable) {
    String name = compilable.toString();
    OptionValues options = TruffleCompilerOptions.getOptions();
    ResolvedJavaMethod rootMethod = rootForCallTarget(compilable);
    // @formatter:off
    final StructuredGraph graph = new StructuredGraph.Builder(options, debug, allowAssumptions).name(name).method(rootMethod).speculationLog(log).compilationId(compilationId).cancellable(cancellable).build();
    try (DebugContext.Scope s = debug.scope("CreateGraph", graph);
        Indent indent = debug.logAndIndent("createGraph %s", graph)) {
        PhaseContext baseContext = new PhaseContext(providers);
        HighTierContext tierContext = new HighTierContext(providers, new PhaseSuite<HighTierContext>(), OptimisticOptimizations.NONE);
        fastPartialEvaluation(compilable, inliningPlan, graph, baseContext, tierContext);
        if (cancellable != null && cancellable.isCancelled()) {
            return null;
        }
        new VerifyFrameDoesNotEscapePhase().apply(graph, false);
        postPartialEvaluation(graph);
    } catch (Throwable e) {
        throw debug.handle(e);
    }
    return graph;
}
Also used : Indent(org.graalvm.compiler.debug.Indent) VerifyFrameDoesNotEscapePhase(org.graalvm.compiler.truffle.compiler.phases.VerifyFrameDoesNotEscapePhase) OptionValues(org.graalvm.compiler.options.OptionValues) DebugContext(org.graalvm.compiler.debug.DebugContext) PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Aggregations

ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)331 ValueNode (org.graalvm.compiler.nodes.ValueNode)104 InvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin)92 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)89 Registration (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration)67 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)66 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)66 Receiver (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver)57 Test (org.junit.Test)54 DebugContext (org.graalvm.compiler.debug.DebugContext)35 OptionValues (org.graalvm.compiler.options.OptionValues)32 InstalledCode (jdk.vm.ci.code.InstalledCode)24 MetaAccessProvider (jdk.vm.ci.meta.MetaAccessProvider)23 GraalCompilerTest (org.graalvm.compiler.core.test.GraalCompilerTest)22 JavaKind (jdk.vm.ci.meta.JavaKind)21 MethodCallTargetNode (org.graalvm.compiler.nodes.java.MethodCallTargetNode)20 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)19 JavaConstant (jdk.vm.ci.meta.JavaConstant)17 LogicNode (org.graalvm.compiler.nodes.LogicNode)17 ArrayList (java.util.ArrayList)16