Search in sources :

Example 1 with EncodedGraph

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

the class GraalSupport method decodeGraph.

public static StructuredGraph decodeGraph(DebugContext debug, String name, CompilationIdentifier compilationId, SharedRuntimeMethod method) {
    // XXX
    EncodedGraph encodedGraph = encodedGraph(method, false);
    if (encodedGraph == null) {
        return null;
    }
    StructuredGraph graph = new StructuredGraph.Builder(debug.getOptions(), debug).name(name).method(method).compilationId(compilationId).build();
    GraphDecoder decoder = new GraphDecoder(ConfigurationValues.getTarget().arch, graph);
    decoder.decode(encodedGraph);
    return graph;
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) GraphDecoder(org.graalvm.compiler.nodes.GraphDecoder) EncodedGraph(org.graalvm.compiler.nodes.EncodedGraph)

Example 2 with EncodedGraph

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

the class SubstrateReplacements method getSnippet.

@Override
public StructuredGraph getSnippet(ResolvedJavaMethod method, ResolvedJavaMethod recursiveEntry, Object[] args, boolean trackNodeSourcePosition, NodeSourcePosition replaceePosition) {
    Integer startOffset = snippetStartOffsets.get(method);
    if (startOffset == null) {
        throw VMError.shouldNotReachHere("snippet not found: " + method.format("%H.%n(%p)"));
    }
    ParameterPlugin parameterPlugin = null;
    if (args != null) {
        parameterPlugin = new ConstantBindingParameterPlugin(args, providers.getMetaAccess(), snippetReflection);
    }
    EncodedGraph encodedGraph = new EncodedGraph(snippetEncoding, startOffset, snippetObjects, snippetNodeClasses, null, null, null, false, trackNodeSourcePosition);
    try (DebugContext debug = openDebugContext("SVMSnippet_", method)) {
        StructuredGraph result = new StructuredGraph.Builder(options, debug).method(method).trackNodeSourcePosition(trackNodeSourcePosition).build();
        PEGraphDecoder graphDecoder = new PEGraphDecoder(ConfigurationValues.getTarget().arch, result, providers.getMetaAccess(), providers.getConstantReflection(), providers.getConstantFieldProvider(), providers.getStampProvider(), null, snippetInvocationPlugins, new InlineInvokePlugin[0], parameterPlugin, null, null, null) {

            @Override
            protected EncodedGraph lookupEncodedGraph(ResolvedJavaMethod lookupMethod, ResolvedJavaMethod originalMethod, BytecodeProvider intrinsicBytecodeProvider, boolean track) {
                if (lookupMethod.equals(method)) {
                    assert !track || encodedGraph.trackNodeSourcePosition();
                    return encodedGraph;
                } else {
                    throw VMError.shouldNotReachHere(method.format("%H.%n(%p)"));
                }
            }
        };
        graphDecoder.decode(method, trackNodeSourcePosition);
        assert result.verify();
        return result;
    }
}
Also used : ConstantBindingParameterPlugin(org.graalvm.compiler.replacements.ConstantBindingParameterPlugin) ParameterPlugin(org.graalvm.compiler.nodes.graphbuilderconf.ParameterPlugin) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) EncodedGraph(org.graalvm.compiler.nodes.EncodedGraph) PEGraphDecoder(org.graalvm.compiler.replacements.PEGraphDecoder) BytecodeProvider(org.graalvm.compiler.bytecode.BytecodeProvider) DebugContext(org.graalvm.compiler.debug.DebugContext) ConstantBindingParameterPlugin(org.graalvm.compiler.replacements.ConstantBindingParameterPlugin) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 3 with EncodedGraph

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

the class CachingPEGraphDecoder method createGraph.

@SuppressWarnings("try")
private EncodedGraph createGraph(ResolvedJavaMethod method, ResolvedJavaMethod originalMethod, BytecodeProvider intrinsicBytecodeProvider) {
    StructuredGraph graphToEncode = new StructuredGraph.Builder(options, debug, allowAssumptions).useProfilingInfo(false).trackNodeSourcePosition(graphBuilderConfig.trackNodeSourcePosition()).method(method).build();
    try (DebugContext.Scope scope = debug.scope("createGraph", graphToEncode)) {
        IntrinsicContext initialIntrinsicContext = intrinsicBytecodeProvider != null ? new IntrinsicContext(originalMethod, method, intrinsicBytecodeProvider, INLINE_AFTER_PARSING) : null;
        GraphBuilderPhase.Instance graphBuilderPhaseInstance = createGraphBuilderPhaseInstance(initialIntrinsicContext);
        graphBuilderPhaseInstance.apply(graphToEncode);
        PhaseContext context = new PhaseContext(providers);
        new CanonicalizerPhase().apply(graphToEncode, context);
        /*
             * ConvertDeoptimizeToGuardPhase reduces the number of merges in the graph, so that
             * fewer frame states will be created. This significantly reduces the number of nodes in
             * the initial graph.
             */
        new ConvertDeoptimizeToGuardPhase().apply(graphToEncode, context);
        EncodedGraph encodedGraph = GraphEncoder.encodeSingleGraph(graphToEncode, architecture);
        graphCache.put(method, encodedGraph);
        return encodedGraph;
    } catch (Throwable ex) {
        throw debug.handle(ex);
    }
}
Also used : PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) EncodedGraph(org.graalvm.compiler.nodes.EncodedGraph) IntrinsicContext(org.graalvm.compiler.nodes.graphbuilderconf.IntrinsicContext) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) DebugContext(org.graalvm.compiler.debug.DebugContext) GraphBuilderPhase(org.graalvm.compiler.java.GraphBuilderPhase) ConvertDeoptimizeToGuardPhase(org.graalvm.compiler.phases.common.ConvertDeoptimizeToGuardPhase)

Example 4 with EncodedGraph

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

the class SubstratePEGraphDecoder method createGraph.

private EncodedGraph createGraph(ResolvedJavaMethod method, boolean trackNodeSourcePosition) {
    EncodedGraph result = GraalSupport.encodedGraph((SharedRuntimeMethod) method, trackNodeSourcePosition);
    if (result == null) {
        throw shouldNotReachHere("Graph not available for runtime compilation: " + method.format("%H.%n(%p)"));
    }
    graphCache.put(method, result);
    return result;
}
Also used : EncodedGraph(org.graalvm.compiler.nodes.EncodedGraph)

Example 5 with EncodedGraph

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

the class GraphEncoderTest method testStringMethods.

public void testStringMethods(boolean canonicalize) {
    /* Encode and decode all methods of java.lang.String. */
    List<StructuredGraph> originalGraphs = new ArrayList<>();
    for (Method method : String.class.getDeclaredMethods()) {
        ResolvedJavaMethod javaMethod = getMetaAccess().lookupJavaMethod(method);
        if (javaMethod.hasBytecodes()) {
            StructuredGraph originalGraph = parseEager(javaMethod, AllowAssumptions.YES);
            if (canonicalize) {
                PhaseContext context = new PhaseContext(getProviders());
                new CanonicalizerPhase().apply(originalGraph, context);
            }
            originalGraphs.add(originalGraph);
        }
    }
    GraphEncoder encoder = new GraphEncoder(getTarget().arch);
    for (StructuredGraph originalGraph : originalGraphs) {
        encoder.prepare(originalGraph);
    }
    encoder.finishPrepare();
    Map<StructuredGraph, Integer> startOffsets = new HashMap<>();
    for (StructuredGraph originalGraph : originalGraphs) {
        startOffsets.put(originalGraph, encoder.encode(originalGraph));
    }
    for (StructuredGraph originalGraph : originalGraphs) {
        EncodedGraph encodedGraph = new EncodedGraph(encoder.getEncoding(), startOffsets.get(originalGraph), encoder.getObjects(), encoder.getNodeClasses(), originalGraph);
        GraphEncoder.verifyEncoding(originalGraph, encodedGraph, getTarget().arch);
    }
}
Also used : PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) HashMap(java.util.HashMap) EncodedGraph(org.graalvm.compiler.nodes.EncodedGraph) ArrayList(java.util.ArrayList) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) Method(java.lang.reflect.Method) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) GraphEncoder(org.graalvm.compiler.nodes.GraphEncoder) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Aggregations

EncodedGraph (org.graalvm.compiler.nodes.EncodedGraph)6 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)4 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)3 DebugContext (org.graalvm.compiler.debug.DebugContext)2 CanonicalizerPhase (org.graalvm.compiler.phases.common.CanonicalizerPhase)2 PhaseContext (org.graalvm.compiler.phases.tiers.PhaseContext)2 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Assumptions (jdk.vm.ci.meta.Assumptions)1 ResolvedJavaField (jdk.vm.ci.meta.ResolvedJavaField)1 BytecodeProvider (org.graalvm.compiler.bytecode.BytecodeProvider)1 GraphBuilderPhase (org.graalvm.compiler.java.GraphBuilderPhase)1 DeoptimizeNode (org.graalvm.compiler.nodes.DeoptimizeNode)1 FixedNode (org.graalvm.compiler.nodes.FixedNode)1 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)1 GraphDecoder (org.graalvm.compiler.nodes.GraphDecoder)1 GraphEncoder (org.graalvm.compiler.nodes.GraphEncoder)1 Invoke (org.graalvm.compiler.nodes.Invoke)1 InlineInvokePlugin (org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin)1