Search in sources :

Example 1 with SnippetParameterInfo

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

the class EncodedSnippets method getSnippetParameterInfo.

public SnippetParameterInfo getSnippetParameterInfo(ResolvedJavaMethod method) {
    GraphData data = null;
    if (graphDatas != null) {
        data = graphDatas.get(methodKey(method));
    }
    assert data != null : method + " " + methodKey(method);
    SnippetParameterInfo info = data.info;
    assert info != null;
    return info;
}
Also used : SnippetParameterInfo(org.graalvm.compiler.nodes.spi.SnippetParameterInfo)

Example 2 with SnippetParameterInfo

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

the class SnippetStub method getGraph.

@Override
@SuppressWarnings("try")
protected StructuredGraph getGraph(DebugContext debug, CompilationIdentifier compilationId) {
    // Stubs cannot have optimistic assumptions since they have
    // to be valid for the entire run of the VM.
    SnippetParameterInfo info = providers.getReplacements().getSnippetParameterInfo(method);
    final StructuredGraph graph = buildInitialGraph(debug, compilationId, makeConstArgs(info), SnippetParameterInfo.getNonNullParameters(info));
    try (DebugContext.Scope outer = debug.scope("SnippetStub", graph)) {
        for (ParameterNode param : graph.getNodes(ParameterNode.TYPE)) {
            int index = param.index();
            if (info.isNonNullParameter(index)) {
                param.setStamp(param.stamp(NodeView.DEFAULT).join(StampFactory.objectNonNull()));
            }
        }
        graph.setGuardsStage(GuardsStage.FLOATING_GUARDS);
        CanonicalizerPhase canonicalizer = CanonicalizerPhase.create();
        canonicalizer.apply(graph, providers);
        new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, providers);
    } catch (Throwable e) {
        throw debug.handle(e);
    }
    return graph;
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) SnippetParameterInfo(org.graalvm.compiler.nodes.spi.SnippetParameterInfo) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) DebugContext(org.graalvm.compiler.debug.DebugContext)

Example 3 with SnippetParameterInfo

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

the class SymbolicSnippetEncoder method registerSnippet.

synchronized void registerSnippet(ResolvedJavaMethod method, ResolvedJavaMethod original, Object receiver, boolean trackNodeSourcePosition) {
    if (HotSpotReplacementsImpl.snippetsAreEncoded()) {
        throw new GraalError("Snippet encoding has already been done");
    }
    assert method.getAnnotation(Snippet.class) != null : "Snippet must be annotated with @" + Snippet.class.getSimpleName();
    SnippetKey key = new SnippetKey(method, original, receiver);
    findSnippetMethod(method);
    if (!pendingSnippetGraphs.containsKey(key)) {
        if (original != null) {
            originalMethods.put(key.keyString(), methodKey(original));
        }
        SnippetParameterInfo info = new SnippetParameterInfo(method);
        snippetParameterInfos.put(key.keyString(), info);
        int i = 0;
        int offset = 0;
        if (!method.isStatic()) {
            assert info.isConstantParameter(0) : "receiver is always constant";
            ensureSnippetTypeAvailable(method.getDeclaringClass());
            i++;
            offset = 1;
        }
        for (; i < info.getParameterCount(); i++) {
            if (info.isConstantParameter(i) || info.isVarargsParameter(i)) {
                JavaType type = method.getSignature().getParameterType(i - offset, method.getDeclaringClass());
                if (type instanceof ResolvedJavaType) {
                    ResolvedJavaType resolvedJavaType = (ResolvedJavaType) type;
                    if (info.isVarargsParameter(i)) {
                        resolvedJavaType = resolvedJavaType.getElementalType();
                    }
                    assert resolvedJavaType.isPrimitive() || isGraalClass(resolvedJavaType) : method + ": only Graal classes can be @ConstantParameter or @VarargsParameter: " + type;
                    ensureSnippetTypeAvailable(resolvedJavaType);
                } else {
                    throw new InternalError(type.toString());
                }
            }
        }
        pendingSnippetGraphs.put(key, new BiFunction<>() {

            @Override
            public StructuredGraph apply(OptionValues cmopileOptions, HotSpotSnippetReplacementsImpl snippetReplacements) {
                return buildGraph(method, original, receiver, SnippetParameterInfo.getNonNullParameters(info), trackNodeSourcePosition, cmopileOptions, snippetReplacements);
            }
        });
    }
}
Also used : OptionValues(org.graalvm.compiler.options.OptionValues) SnippetParameterInfo(org.graalvm.compiler.nodes.spi.SnippetParameterInfo) Snippet(org.graalvm.compiler.api.replacements.Snippet) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) HotSpotResolvedJavaType(jdk.vm.ci.hotspot.HotSpotResolvedJavaType) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaType(jdk.vm.ci.meta.JavaType) HotSpotResolvedJavaType(jdk.vm.ci.hotspot.HotSpotResolvedJavaType) UnresolvedJavaType(jdk.vm.ci.meta.UnresolvedJavaType) GraalError(org.graalvm.compiler.debug.GraalError) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph)

Aggregations

SnippetParameterInfo (org.graalvm.compiler.nodes.spi.SnippetParameterInfo)3 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)2 HotSpotResolvedJavaType (jdk.vm.ci.hotspot.HotSpotResolvedJavaType)1 JavaType (jdk.vm.ci.meta.JavaType)1 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)1 UnresolvedJavaType (jdk.vm.ci.meta.UnresolvedJavaType)1 Snippet (org.graalvm.compiler.api.replacements.Snippet)1 DebugContext (org.graalvm.compiler.debug.DebugContext)1 GraalError (org.graalvm.compiler.debug.GraalError)1 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)1 OptionValues (org.graalvm.compiler.options.OptionValues)1 CanonicalizerPhase (org.graalvm.compiler.phases.common.CanonicalizerPhase)1 LoweringPhase (org.graalvm.compiler.phases.common.LoweringPhase)1