Search in sources :

Example 31 with Graph

use of org.graalvm.compiler.graph.Graph in project graal by oracle.

the class UnsafeEATest method postEACanonicalizeGraph.

@Override
protected void postEACanonicalizeGraph() {
    // Simplify any UnpackEndianHalfNode so we end up with constants.
    Graph.Mark mark = graph.getMark();
    for (UnpackEndianHalfNode node : graph.getNodes().filter(UnpackEndianHalfNode.class)) {
        node.lower(getTarget().arch.getByteOrder());
    }
    new CanonicalizerPhase().applyIncremental(graph, context, mark);
}
Also used : Graph(org.graalvm.compiler.graph.Graph) UnpackEndianHalfNode(org.graalvm.compiler.nodes.calc.UnpackEndianHalfNode) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase)

Example 32 with Graph

use of org.graalvm.compiler.graph.Graph in project graal by oracle.

the class GraphPrinterDumpHandler method getInlineContext.

private List<String> getInlineContext(Graph graph) {
    List<String> result = inlineContextMap.get(graph);
    if (result == null) {
        result = new ArrayList<>();
        Object lastMethodOrGraph = null;
        boolean graphSeen = false;
        DebugContext debug = graph.getDebug();
        for (Object o : debug.context()) {
            if (o == graph) {
                graphSeen = true;
            }
            if (o instanceof DebugDumpScope) {
                DebugDumpScope debugDumpScope = (DebugDumpScope) o;
                if (debugDumpScope.decorator && !result.isEmpty()) {
                    result.set(result.size() - 1, debugDumpScope.name + ":" + result.get(result.size() - 1));
                } else {
                    result.add(debugDumpScope.name);
                }
            } else {
                addMethodContext(result, o, lastMethodOrGraph);
            }
            if (o instanceof JavaMethod || o instanceof Graph) {
                lastMethodOrGraph = o;
            }
        }
        if (result.size() == 2 && result.get(1).startsWith("TruffleGraal")) {
            result.clear();
            result.add("Graal Graphs");
        }
        if (result.isEmpty()) {
            result.add(graph.toString());
            graphSeen = true;
        }
        // Reverse list such that inner method comes after outer method.
        Collections.reverse(result);
        if (!graphSeen) {
            /*
                 * The graph isn't in any context but is being processed within another graph so add
                 * it to the end of the scopes.
                 */
            if (asJavaMethod(graph) != null) {
                addMethodContext(result, graph, lastMethodOrGraph);
            } else {
                result.add(graph.toString());
            }
        }
        inlineContextMap.put(graph, result);
    }
    return result;
}
Also used : Graph(org.graalvm.compiler.graph.Graph) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) DebugDumpScope(org.graalvm.compiler.debug.DebugDumpScope) JavaMethod(jdk.vm.ci.meta.JavaMethod) DebugConfig.asJavaMethod(org.graalvm.compiler.debug.DebugConfig.asJavaMethod) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) DebugContext(org.graalvm.compiler.debug.DebugContext)

Example 33 with Graph

use of org.graalvm.compiler.graph.Graph in project graal by oracle.

the class GraphPrinterDumpHandler method dump.

@Override
@SuppressWarnings("try")
public void dump(DebugContext debug, Object object, final String format, Object... arguments) {
    OptionValues options = debug.getOptions();
    if (object instanceof Graph && DebugOptions.PrintGraph.getValue(options)) {
        final Graph graph = (Graph) object;
        ensureInitialized(debug, graph);
        if (printer == null) {
            return;
        }
        // Get all current JavaMethod instances in the context.
        List<String> inlineContext = getInlineContext(graph);
        if (inlineContext != previousInlineContext) {
            Map<Object, Object> properties = new HashMap<>();
            properties.put("graph", graph.toString());
            addCompilationId(properties, graph);
            if (inlineContext.equals(previousInlineContext)) {
                /*
                     * two different graphs have the same inline context, so make sure they appear
                     * in different folders by closing and reopening the top scope.
                     */
                int inlineDepth = previousInlineContext.size() - 1;
                closeScope(debug, inlineDepth);
                openScope(debug, inlineContext.get(inlineDepth), inlineDepth, properties);
            } else {
                // Check for method scopes that must be closed since the previous dump.
                for (int i = 0; i < previousInlineContext.size(); ++i) {
                    if (i >= inlineContext.size() || !inlineContext.get(i).equals(previousInlineContext.get(i))) {
                        for (int inlineDepth = previousInlineContext.size() - 1; inlineDepth >= i; --inlineDepth) {
                            closeScope(debug, inlineDepth);
                        }
                        break;
                    }
                }
                // Check for method scopes that must be opened since the previous dump.
                for (int i = 0; i < inlineContext.size(); ++i) {
                    if (i >= previousInlineContext.size() || !inlineContext.get(i).equals(previousInlineContext.get(i))) {
                        for (int inlineDepth = i; inlineDepth < inlineContext.size(); ++inlineDepth) {
                            openScope(debug, inlineContext.get(inlineDepth), inlineDepth, inlineDepth == inlineContext.size() - 1 ? properties : null);
                        }
                        break;
                    }
                }
            }
        }
        // Save inline context for next dump.
        previousInlineContext = inlineContext;
        // Capture before creating the sandbox
        String currentScopeName = debug.getCurrentScopeName();
        try (DebugContext.Scope s = debug.sandbox("PrintingGraph", null)) {
            // Finally, output the graph.
            Map<Object, Object> properties = new HashMap<>();
            properties.put("graph", graph.toString());
            properties.put("scope", currentScopeName);
            if (graph instanceof StructuredGraph) {
                properties.put("compilationIdentifier", ((StructuredGraph) graph).compilationId());
                try {
                    int size = NodeCostUtil.computeGraphSize((StructuredGraph) graph);
                    properties.put("node-cost graph size", size);
                } catch (Throwable t) {
                    properties.put("node-cost-exception", t.getMessage());
                }
            }
            printer.print(debug, graph, properties, nextDumpId(), format, arguments);
        } catch (IOException e) {
            handleException(debug, e);
        } catch (Throwable e) {
            throw debug.handle(e);
        }
    }
}
Also used : OptionValues(org.graalvm.compiler.options.OptionValues) HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap) DebugContext(org.graalvm.compiler.debug.DebugContext) IOException(java.io.IOException) Graph(org.graalvm.compiler.graph.Graph) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph)

Aggregations

Graph (org.graalvm.compiler.graph.Graph)33 Test (org.junit.Test)22 OptionValues (org.graalvm.compiler.options.OptionValues)21 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)8 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)3 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)3 EndNode (org.graalvm.compiler.nodes.EndNode)3 FixedNode (org.graalvm.compiler.nodes.FixedNode)3 ValueNode (org.graalvm.compiler.nodes.ValueNode)3 DebugCloseable (org.graalvm.compiler.debug.DebugCloseable)2 DebugContext (org.graalvm.compiler.debug.DebugContext)2 DuplicationReplacement (org.graalvm.compiler.graph.Graph.DuplicationReplacement)2 Node (org.graalvm.compiler.graph.Node)2 LoopExitNode (org.graalvm.compiler.nodes.LoopExitNode)2 MergeNode (org.graalvm.compiler.nodes.MergeNode)2 Before (org.junit.Before)2 IOException (java.io.IOException)1 ArrayDeque (java.util.ArrayDeque)1 Collections (java.util.Collections)1 Deque (java.util.Deque)1