# HG changeset patch # User Christian Humer # Date 1412868353 -7200 # Node ID ce70580051153e3a903e9078b7c50dfc3f125ea2 # Parent c0f71f81708a820807189494d7584170cf41ffcf Truffle: fix TraceTruffleExpansion for context sensitive inlining. diff -r c0f71f81708a -r ce7058005115 graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/PartialEvaluator.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/PartialEvaluator.java Thu Oct 09 17:25:47 2014 +0200 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/PartialEvaluator.java Thu Oct 09 17:25:53 2014 +0200 @@ -103,7 +103,12 @@ Debug.dump(graph, "Before expansion"); - expandTree(graph, assumptions); + TruffleExpansionLogger expansionLogger = null; + if (TraceTruffleExpansion.getValue()) { + expansionLogger = new TruffleExpansionLogger(providers, graph); + } + + expandTree(graph, assumptions, expansionLogger); TruffleInliningCache inliningCache = null; if (TruffleFunctionInlining.getValue()) { @@ -113,7 +118,7 @@ } } - expandDirectCalls(graph, assumptions, callTarget.getInlining(), inliningCache); + expandDirectCalls(graph, assumptions, expansionLogger, callTarget.getInlining(), inliningCache); if (Thread.currentThread().isInterrupted()) { return null; @@ -140,7 +145,7 @@ } // to make frame propagations visible retry expandTree - while (expandTree(graph, assumptions)) { + while (expandTree(graph, assumptions, expansionLogger)) { try (Scope pe = Debug.scope("TrufflePartialEscape", graph)) { new PartialEscapePhase(true, canonicalizer).apply(graph, tierContext); } catch (Throwable t) { @@ -148,6 +153,10 @@ } } + if (expansionLogger != null) { + expansionLogger.print(callTarget); + } + for (NeverPartOfCompilationNode neverPartOfCompilationNode : graph.getNodes(NeverPartOfCompilationNode.class)) { Throwable exception = new VerificationError(neverPartOfCompilationNode.getMessage()); throw GraphUtil.approxSourceException(neverPartOfCompilationNode, exception); @@ -210,12 +219,8 @@ new DebugHistogramAsciiPrinter(TTY.out().out()).print(histogram); } - private boolean expandTree(StructuredGraph graph, Assumptions assumptions) { + private boolean expandTree(StructuredGraph graph, Assumptions assumptions, TruffleExpansionLogger expansionLogger) { PhaseContext phaseContext = new PhaseContext(providers, assumptions); - TruffleExpansionLogger expansionLogger = null; - if (TraceTruffleExpansion.getValue()) { - expansionLogger = new TruffleExpansionLogger(providers, graph); - } boolean changed = false; boolean changedInIteration; do { @@ -256,22 +261,19 @@ } while (changedInIteration); - if (TraceTruffleExpansion.getValue()) { - expansionLogger.print(); - } return changed; } private void expandTreeInline(StructuredGraph graph, PhaseContext phaseContext, TruffleExpansionLogger expansionLogger, MethodCallTargetNode methodCallTargetNode, StructuredGraph inlineGraph) { try (Indent indent = Debug.logAndIndent("expand graph %s", methodCallTargetNode.targetMethod())) { int nodeCountBefore = graph.getNodeCount(); - if (TraceTruffleExpansion.getValue() && expansionLogger != null) { + if (expansionLogger != null) { expansionLogger.preExpand(methodCallTargetNode, inlineGraph); } List canonicalizedNodes = methodCallTargetNode.invoke().asNode().usages().snapshot(); Map inlined = InliningUtil.inline(methodCallTargetNode.invoke(), inlineGraph, false, canonicalizedNodes); - if (TraceTruffleExpansion.getValue() && expansionLogger != null) { + if (expansionLogger != null) { expansionLogger.postExpand(inlined); } if (Debug.isDumpEnabled()) { @@ -335,18 +337,18 @@ } } - private void expandDirectCalls(StructuredGraph graph, Assumptions assumptions, TruffleInlining inlining, TruffleInliningCache inliningCache) { + private void expandDirectCalls(StructuredGraph graph, Assumptions assumptions, TruffleExpansionLogger expansionLogger, TruffleInlining inlining, TruffleInliningCache inliningCache) { PhaseContext phaseContext = new PhaseContext(providers, assumptions); for (MethodCallTargetNode methodCallTargetNode : graph.getNodes(MethodCallTargetNode.class).snapshot()) { StructuredGraph inlineGraph = parseDirectCallGraph(phaseContext, assumptions, inlining, inliningCache, methodCallTargetNode); if (inlineGraph != null) { - expandTreeInline(graph, phaseContext, null, methodCallTargetNode, inlineGraph); + expandTreeInline(graph, phaseContext, expansionLogger, methodCallTargetNode, inlineGraph); } } // non inlined direct calls need to be expanded until TruffleCallBoundary. - expandTree(graph, assumptions); + expandTree(graph, assumptions, expansionLogger); assert noDirectCallsLeft(graph); } @@ -453,8 +455,16 @@ OptimizedCallTarget target = decision.getTarget(); StructuredGraph inlineGraph = truffleCache.createInlineGraph(target.toString()); injectConstantCallTarget(inlineGraph, decision.getTarget(), phaseContext); - expandTree(inlineGraph, assumptions); - expandDirectCalls(inlineGraph, assumptions, decision, cache); + TruffleExpansionLogger expansionLogger = null; + if (TraceTruffleExpansion.getValue()) { + expansionLogger = new TruffleExpansionLogger(providers, inlineGraph); + } + expandTree(inlineGraph, assumptions, expansionLogger); + expandDirectCalls(inlineGraph, assumptions, expansionLogger, decision, cache); + + if (expansionLogger != null) { + expansionLogger.print(target); + } return inlineGraph; } catch (Throwable e) { throw Debug.handle(e); diff -r c0f71f81708a -r ce7058005115 graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleExpansionLogger.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleExpansionLogger.java Thu Oct 09 17:25:47 2014 +0200 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleExpansionLogger.java Thu Oct 09 17:25:53 2014 +0200 @@ -89,7 +89,8 @@ } } - public void print() { + public void print(OptimizedCallTarget target) { + System.out.printf("Expansion tree for %s: %n", target); root.print(System.out); }