changeset 17402:ce7058005115

Truffle: fix TraceTruffleExpansion for context sensitive inlining.
author Christian Humer <christian.humer@gmail.com>
date Thu, 09 Oct 2014 17:25:53 +0200
parents c0f71f81708a
children 79ac83ff7a99
files graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/PartialEvaluator.java graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleExpansionLogger.java
diffstat 2 files changed, 30 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- 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<Node> canonicalizedNodes = methodCallTargetNode.invoke().asNode().usages().snapshot();
 
             Map<Node, Node> 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);
--- 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);
     }