Search in sources :

Example 1 with ParameterNode

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

the class AArch64HotSpotNodeLIRBuilder method emitPrologue.

@Override
protected void emitPrologue(StructuredGraph graph) {
    CallingConvention incomingArguments = gen.getResult().getCallingConvention();
    Value[] params = new Value[incomingArguments.getArgumentCount() + 2];
    for (int i = 0; i < incomingArguments.getArgumentCount(); i++) {
        params[i] = incomingArguments.getArgument(i);
        if (isStackSlot(params[i])) {
            StackSlot slot = ValueUtil.asStackSlot(params[i]);
            if (slot.isInCallerFrame() && !gen.getResult().getLIR().hasArgInCallerFrame()) {
                gen.getResult().getLIR().setHasArgInCallerFrame();
            }
        }
    }
    params[params.length - 2] = fp.asValue(LIRKind.value(AArch64Kind.QWORD));
    params[params.length - 1] = lr.asValue(LIRKind.value(AArch64Kind.QWORD));
    gen.emitIncomingValues(params);
    for (ParameterNode param : graph.getNodes(ParameterNode.TYPE)) {
        Value paramValue = params[param.index()];
        assert paramValue.getValueKind().equals(getLIRGeneratorTool().getLIRKind(param.stamp(NodeView.DEFAULT))) : paramValue.getValueKind() + " != " + param.stamp(NodeView.DEFAULT);
        setResult(param, gen.emitMove(paramValue));
    }
}
Also used : CallingConvention(jdk.vm.ci.code.CallingConvention) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) RegisterValue(jdk.vm.ci.code.RegisterValue) Value(jdk.vm.ci.meta.Value) AllocatableValue(jdk.vm.ci.meta.AllocatableValue) ValueUtil.isStackSlot(jdk.vm.ci.code.ValueUtil.isStackSlot) StackSlot(jdk.vm.ci.code.StackSlot)

Example 2 with ParameterNode

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

the class AMD64HotSpotNodeLIRBuilder method emitPrologue.

@Override
protected void emitPrologue(StructuredGraph graph) {
    CallingConvention incomingArguments = gen.getResult().getCallingConvention();
    Value[] params = new Value[incomingArguments.getArgumentCount() + 1];
    for (int i = 0; i < params.length - 1; i++) {
        params[i] = incomingArguments.getArgument(i);
        if (isStackSlot(params[i])) {
            StackSlot slot = ValueUtil.asStackSlot(params[i]);
            if (slot.isInCallerFrame() && !gen.getResult().getLIR().hasArgInCallerFrame()) {
                gen.getResult().getLIR().setHasArgInCallerFrame();
            }
        }
    }
    params[params.length - 1] = rbp.asValue(LIRKind.value(AMD64Kind.QWORD));
    gen.emitIncomingValues(params);
    getGen().emitSaveRbp();
    getGen().append(((HotSpotDebugInfoBuilder) getDebugInfoBuilder()).lockStack());
    for (ParameterNode param : graph.getNodes(ParameterNode.TYPE)) {
        Value paramValue = params[param.index()];
        assert paramValue.getValueKind().equals(getLIRGeneratorTool().getLIRKind(param.stamp(NodeView.DEFAULT))) : paramValue.getValueKind() + " != " + param.stamp(NodeView.DEFAULT);
        setResult(param, gen.emitMove(paramValue));
    }
}
Also used : CallingConvention(jdk.vm.ci.code.CallingConvention) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) RegisterValue(jdk.vm.ci.code.RegisterValue) Value(jdk.vm.ci.meta.Value) AllocatableValue(jdk.vm.ci.meta.AllocatableValue) ValueUtil.isStackSlot(jdk.vm.ci.code.ValueUtil.isStackSlot) StackSlot(jdk.vm.ci.code.StackSlot)

Example 3 with ParameterNode

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

the class ObjectCloneNode method getLoweredSnippetGraph.

@Override
@SuppressWarnings("try")
protected StructuredGraph getLoweredSnippetGraph(LoweringTool tool) {
    ResolvedJavaType type = StampTool.typeOrNull(getObject());
    if (type != null) {
        if (type.isArray()) {
            Method method = ObjectCloneSnippets.arrayCloneMethods.get(type.getComponentType().getJavaKind());
            if (method != null) {
                final ResolvedJavaMethod snippetMethod = tool.getMetaAccess().lookupJavaMethod(method);
                final Replacements replacements = tool.getReplacements();
                StructuredGraph snippetGraph = null;
                DebugContext debug = getDebug();
                try (DebugContext.Scope s = debug.scope("ArrayCloneSnippet", snippetMethod)) {
                    snippetGraph = replacements.getSnippet(snippetMethod, null, graph().trackNodeSourcePosition(), this.getNodeSourcePosition());
                } catch (Throwable e) {
                    throw debug.handle(e);
                }
                assert snippetGraph != null : "ObjectCloneSnippets should be installed";
                assert getConcreteType(stamp(NodeView.DEFAULT)) != null;
                return lowerReplacement((StructuredGraph) snippetGraph.copy(getDebug()), tool);
            }
            assert false : "unhandled array type " + type.getComponentType().getJavaKind();
        } else {
            Assumptions assumptions = graph().getAssumptions();
            type = getConcreteType(getObject().stamp(NodeView.DEFAULT));
            if (type != null) {
                StructuredGraph newGraph = new StructuredGraph.Builder(graph().getOptions(), graph().getDebug(), AllowAssumptions.ifNonNull(assumptions)).build();
                ParameterNode param = newGraph.addWithoutUnique(new ParameterNode(0, StampPair.createSingle(getObject().stamp(NodeView.DEFAULT))));
                NewInstanceNode newInstance = newGraph.add(new NewInstanceNode(type, true));
                newGraph.addAfterFixed(newGraph.start(), newInstance);
                ReturnNode returnNode = newGraph.add(new ReturnNode(newInstance));
                newGraph.addAfterFixed(newInstance, returnNode);
                for (ResolvedJavaField field : type.getInstanceFields(true)) {
                    LoadFieldNode load = newGraph.add(LoadFieldNode.create(newGraph.getAssumptions(), param, field));
                    newGraph.addBeforeFixed(returnNode, load);
                    newGraph.addBeforeFixed(returnNode, newGraph.add(new StoreFieldNode(newInstance, field, load)));
                }
                assert getConcreteType(stamp(NodeView.DEFAULT)) != null;
                return lowerReplacement(newGraph, tool);
            }
        }
    }
    assert getConcreteType(stamp(NodeView.DEFAULT)) == null;
    return null;
}
Also used : StoreFieldNode(org.graalvm.compiler.nodes.java.StoreFieldNode) Replacements(org.graalvm.compiler.nodes.spi.Replacements) NewInstanceNode(org.graalvm.compiler.nodes.java.NewInstanceNode) Method(java.lang.reflect.Method) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) DebugContext(org.graalvm.compiler.debug.DebugContext) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) AllowAssumptions(org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions) Assumptions(jdk.vm.ci.meta.Assumptions) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 4 with ParameterNode

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

the class ForeignCallStub method createParameters.

private ParameterNode[] createParameters(GraphKit kit, Class<?>[] args) {
    ParameterNode[] params = new ParameterNode[args.length];
    ResolvedJavaType accessingClass = providers.getMetaAccess().lookupJavaType(getClass());
    for (int i = 0; i < args.length; i++) {
        ResolvedJavaType type = providers.getMetaAccess().lookupJavaType(args[i]).resolve(accessingClass);
        StampPair stamp = StampFactory.forDeclaredType(kit.getGraph().getAssumptions(), type, false);
        ParameterNode param = kit.unique(new ParameterNode(i, stamp));
        params[i] = param;
    }
    return params;
}
Also used : ParameterNode(org.graalvm.compiler.nodes.ParameterNode) StampPair(org.graalvm.compiler.core.common.type.StampPair) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Example 5 with ParameterNode

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

the class ForeignCallStub method getGraph.

/**
 * Creates a graph for this stub.
 * <p>
 * If the stub returns an object, the graph created corresponds to this pseudo code:
 *
 * <pre>
 *     Object foreignFunctionStub(args...) {
 *         foreignFunction(currentThread,  args);
 *         if (clearPendingException(thread())) {
 *             getAndClearObjectResult(thread());
 *             DeoptimizeCallerNode.deopt(InvalidateReprofile, RuntimeConstraint);
 *         }
 *         return verifyObject(getAndClearObjectResult(thread()));
 *     }
 * </pre>
 *
 * If the stub returns a primitive or word, the graph created corresponds to this pseudo code
 * (using {@code int} as the primitive return type):
 *
 * <pre>
 *     int foreignFunctionStub(args...) {
 *         int result = foreignFunction(currentThread,  args);
 *         if (clearPendingException(thread())) {
 *             DeoptimizeCallerNode.deopt(InvalidateReprofile, RuntimeConstraint);
 *         }
 *         return result;
 *     }
 * </pre>
 *
 * If the stub is void, the graph created corresponds to this pseudo code:
 *
 * <pre>
 *     void foreignFunctionStub(args...) {
 *         foreignFunction(currentThread,  args);
 *         if (clearPendingException(thread())) {
 *             DeoptimizeCallerNode.deopt(InvalidateReprofile, RuntimeConstraint);
 *         }
 *     }
 * </pre>
 *
 * In each example above, the {@code currentThread} argument is the C++ JavaThread value (i.e.,
 * %r15 on AMD64) and is only prepended if {@link #prependThread} is true.
 */
@Override
@SuppressWarnings("try")
protected StructuredGraph getGraph(DebugContext debug, CompilationIdentifier compilationId) {
    WordTypes wordTypes = providers.getWordTypes();
    Class<?>[] args = linkage.getDescriptor().getArgumentTypes();
    boolean isObjectResult = !LIRKind.isValue(linkage.getOutgoingCallingConvention().getReturn());
    try {
        ResolvedJavaMethod thisMethod = providers.getMetaAccess().lookupJavaMethod(ForeignCallStub.class.getDeclaredMethod("getGraph", DebugContext.class, CompilationIdentifier.class));
        GraphKit kit = new GraphKit(debug, thisMethod, providers, wordTypes, providers.getGraphBuilderPlugins(), compilationId, toString());
        StructuredGraph graph = kit.getGraph();
        ParameterNode[] params = createParameters(kit, args);
        ReadRegisterNode thread = kit.append(new ReadRegisterNode(providers.getRegisters().getThreadRegister(), wordTypes.getWordKind(), true, false));
        ValueNode result = createTargetCall(kit, params, thread);
        kit.createInvoke(StubUtil.class, "handlePendingException", thread, ConstantNode.forBoolean(isObjectResult, graph));
        if (isObjectResult) {
            InvokeNode object = kit.createInvoke(HotSpotReplacementsUtil.class, "getAndClearObjectResult", thread);
            result = kit.createInvoke(StubUtil.class, "verifyObject", object);
        }
        kit.append(new ReturnNode(linkage.getDescriptor().getResultType() == void.class ? null : result));
        debug.dump(DebugContext.VERBOSE_LEVEL, graph, "Initial stub graph");
        kit.inlineInvokes();
        new RemoveValueProxyPhase().apply(graph);
        debug.dump(DebugContext.VERBOSE_LEVEL, graph, "Stub graph before compilation");
        return graph;
    } catch (Exception e) {
        throw GraalError.shouldNotReachHere(e);
    }
}
Also used : CompilationIdentifier(org.graalvm.compiler.core.common.CompilationIdentifier) RemoveValueProxyPhase(org.graalvm.compiler.phases.common.RemoveValueProxyPhase) WordTypes(org.graalvm.compiler.word.WordTypes) DebugContext(org.graalvm.compiler.debug.DebugContext) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) GraphKit(org.graalvm.compiler.replacements.GraphKit) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) ReadRegisterNode(org.graalvm.compiler.replacements.nodes.ReadRegisterNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Aggregations

ParameterNode (org.graalvm.compiler.nodes.ParameterNode)46 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)19 ValueNode (org.graalvm.compiler.nodes.ValueNode)19 Node (org.graalvm.compiler.graph.Node)13 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)13 ReturnNode (org.graalvm.compiler.nodes.ReturnNode)13 Test (org.junit.Test)10 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)9 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)8 DebugContext (org.graalvm.compiler.debug.DebugContext)7 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)7 FrameState (org.graalvm.compiler.nodes.FrameState)7 InvokeWithExceptionNode (org.graalvm.compiler.nodes.InvokeWithExceptionNode)7 FixedNode (org.graalvm.compiler.nodes.FixedNode)6 CanonicalizerPhase (org.graalvm.compiler.phases.common.CanonicalizerPhase)6 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)5 InvokeNode (org.graalvm.compiler.nodes.InvokeNode)5 PhiNode (org.graalvm.compiler.nodes.PhiNode)5 ArrayList (java.util.ArrayList)4 JavaConstant (jdk.vm.ci.meta.JavaConstant)4