changeset 16545:c667378e4699

extract methods in PartialEvaluator
author Christian Wirth <christian.wirth@oracle.com>
date Thu, 17 Jul 2014 11:40:58 +0200
parents 1e8b758800fb
children d5e6c3793309
files graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/PartialEvaluator.java
diffstat 1 files changed, 41 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/PartialEvaluator.java	Thu Jul 17 11:25:56 2014 +0200
+++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/PartialEvaluator.java	Thu Jul 17 11:40:58 2014 +0200
@@ -122,20 +122,7 @@
             new VerifyFrameDoesNotEscapePhase().apply(graph, false);
 
             if (TraceTruffleCompilationHistogram.getValue() && constantReceivers != null) {
-                DebugHistogram histogram = Debug.createHistogram("Expanded Truffle Nodes");
-                for (Constant c : constantReceivers) {
-                    String javaName = providers.getMetaAccess().lookupJavaType(c).toJavaName(false);
-
-                    // The DSL uses nested classes with redundant names - only show the inner class
-                    int index = javaName.indexOf('$');
-                    if (index != -1) {
-                        javaName = javaName.substring(index + 1);
-                    }
-
-                    histogram.add(javaName);
-
-                }
-                new DebugHistogramAsciiPrinter(TTY.out().out()).print(histogram);
+                createHistogram();
             }
 
             canonicalizer.apply(graph, baseContext);
@@ -176,6 +163,23 @@
         return graph;
     }
 
+    private void createHistogram() {
+        DebugHistogram histogram = Debug.createHistogram("Expanded Truffle Nodes");
+        for (Constant c : constantReceivers) {
+            String javaName = providers.getMetaAccess().lookupJavaType(c).toJavaName(false);
+
+            // The DSL uses nested classes with redundant names - only show the inner class
+            int index = javaName.indexOf('$');
+            if (index != -1) {
+                javaName = javaName.substring(index + 1);
+            }
+
+            histogram.add(javaName);
+
+        }
+        new DebugHistogramAsciiPrinter(TTY.out().out()).print(histogram);
+    }
+
     private void expandTree(StructuredGraph graph, Assumptions assumptions) {
         PhaseContext phaseContext = new PhaseContext(providers, assumptions);
         TruffleExpansionLogger expansionLogger = null;
@@ -207,26 +211,7 @@
                         }
 
                         if (inlineGraph != null) {
-                            try (Indent indent = Debug.logAndIndent("inline graph %s", methodCallTargetNode.targetMethod())) {
-
-                                int nodeCountBefore = graph.getNodeCount();
-                                if (TraceTruffleExpansion.getValue()) {
-                                    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.postExpand(inlined);
-                                }
-                                if (Debug.isDumpEnabled()) {
-                                    int nodeCountAfter = graph.getNodeCount();
-                                    Debug.dump(graph, "After inlining %s %+d (%d)", methodCallTargetNode.targetMethod().toString(), nodeCountAfter - nodeCountBefore, nodeCountAfter);
-                                }
-                                AbstractInlineInfo.getInlinedParameterUsages(canonicalizedNodes, inlineGraph, inlined);
-                                canonicalizer.applyIncremental(graph, phaseContext, canonicalizedNodes);
-
-                                changed = true;
-                            }
+                            changed = expandTreeInline(graph, phaseContext, expansionLogger, methodCallTargetNode, inlineGraph);
                         }
                     }
                 }
@@ -242,6 +227,28 @@
         }
     }
 
+    private boolean expandTreeInline(StructuredGraph graph, PhaseContext phaseContext, TruffleExpansionLogger expansionLogger, MethodCallTargetNode methodCallTargetNode, StructuredGraph inlineGraph) {
+        try (Indent indent = Debug.logAndIndent("inline graph %s", methodCallTargetNode.targetMethod())) {
+            int nodeCountBefore = graph.getNodeCount();
+            if (TraceTruffleExpansion.getValue()) {
+                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.postExpand(inlined);
+            }
+            if (Debug.isDumpEnabled()) {
+                int nodeCountAfter = graph.getNodeCount();
+                Debug.dump(graph, "After inlining %s %+d (%d)", methodCallTargetNode.targetMethod().toString(), nodeCountAfter - nodeCountBefore, nodeCountAfter);
+            }
+            AbstractInlineInfo.getInlinedParameterUsages(canonicalizedNodes, inlineGraph, inlined);
+            canonicalizer.applyIncremental(graph, phaseContext, canonicalizedNodes);
+
+            return true;
+        }
+    }
+
     private StructuredGraph parseGraph(final ResolvedJavaMethod targetMethod, final NodeInputList<ValueNode> arguments, final Assumptions assumptions, final PhaseContext phaseContext,
                     boolean ignoreSlowPath) {