changeset 10528:5fb4a450b7a7

PartialEvaluator: iterative version of expandTree
author Andreas Woess <andreas.woess@jku.at>
date Mon, 24 Jun 2013 17:16:04 +0200
parents 2b95d5b1958b
children 254fab64b343
files graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/PartialEvaluator.java
diffstat 1 files changed, 35 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/PartialEvaluator.java	Tue Jun 25 10:22:02 2013 +0200
+++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/PartialEvaluator.java	Mon Jun 24 17:16:04 2013 +0200
@@ -198,44 +198,47 @@
     }
 
     private void expandTree(GraphBuilderConfiguration config, StructuredGraph graph, NewFrameNode newFrameNode, Assumptions assumptions) {
-        for (Node usage : newFrameNode.usages().snapshot()) {
-            if (usage instanceof MethodCallTargetNode && !usage.isDeleted()) {
-                MethodCallTargetNode methodCallTargetNode = (MethodCallTargetNode) usage;
-                InvokeKind kind = methodCallTargetNode.invokeKind();
-                if (kind == InvokeKind.Special || kind == InvokeKind.Static) {
-                    if (TruffleInlinePrinter.getValue()) {
-                        InlinePrinterProcessor.addInlining(MethodHolder.getNewTruffleExecuteMethod(methodCallTargetNode));
-                    }
-                    if (TraceTruffleCompilationDetails.getValue() && kind == InvokeKind.Special && methodCallTargetNode.arguments().first() instanceof ConstantNode) {
-                        ConstantNode constantNode = (ConstantNode) methodCallTargetNode.arguments().first();
-                        constantReceivers.add(constantNode.asConstant());
-                    }
-                    StructuredGraph inlineGraph = replacements.getMethodSubstitution(methodCallTargetNode.targetMethod());
-                    NewFrameNode otherNewFrame = null;
-                    if (inlineGraph == null) {
-                        inlineGraph = parseGraph(config, methodCallTargetNode.targetMethod(), methodCallTargetNode.arguments(), assumptions, !AOTCompilation.getValue());
-                        otherNewFrame = inlineGraph.getNodes(NewFrameNode.class).first();
-                    }
-                    int nodeCountBefore = graph.getNodeCount();
-                    Map<Node, Node> mapping = InliningUtil.inline(methodCallTargetNode.invoke(), inlineGraph, false);
-                    if (Debug.isDumpEnabled()) {
-                        int nodeCountAfter = graph.getNodeCount();
-                        Debug.dump(graph, "After inlining %s %+d (%d)", methodCallTargetNode.targetMethod().toString(), nodeCountAfter - nodeCountBefore, nodeCountAfter);
-                    }
+        boolean changed;
+        do {
+            changed = false;
+            for (Node usage : newFrameNode.usages().snapshot()) {
+                if (usage instanceof MethodCallTargetNode && !usage.isDeleted()) {
+                    MethodCallTargetNode methodCallTargetNode = (MethodCallTargetNode) usage;
+                    InvokeKind kind = methodCallTargetNode.invokeKind();
+                    if (kind == InvokeKind.Special || kind == InvokeKind.Static) {
+                        if (TruffleInlinePrinter.getValue()) {
+                            InlinePrinterProcessor.addInlining(MethodHolder.getNewTruffleExecuteMethod(methodCallTargetNode));
+                        }
+                        if (TraceTruffleCompilationDetails.getValue() && kind == InvokeKind.Special && methodCallTargetNode.arguments().first() instanceof ConstantNode) {
+                            ConstantNode constantNode = (ConstantNode) methodCallTargetNode.arguments().first();
+                            constantReceivers.add(constantNode.asConstant());
+                        }
+                        StructuredGraph inlineGraph = replacements.getMethodSubstitution(methodCallTargetNode.targetMethod());
+                        NewFrameNode otherNewFrame = null;
+                        if (inlineGraph == null) {
+                            inlineGraph = parseGraph(config, methodCallTargetNode.targetMethod(), methodCallTargetNode.arguments(), assumptions, !AOTCompilation.getValue());
+                            otherNewFrame = inlineGraph.getNodes(NewFrameNode.class).first();
+                        }
 
-                    if (newFrameNode.isAlive() && newFrameNode.usages().isNotEmpty()) {
-                        expandTree(config, graph, newFrameNode, assumptions);
-                    }
+                        int nodeCountBefore = graph.getNodeCount();
+                        Map<Node, Node> mapping = InliningUtil.inline(methodCallTargetNode.invoke(), inlineGraph, false);
+                        if (Debug.isDumpEnabled()) {
+                            int nodeCountAfter = graph.getNodeCount();
+                            Debug.dump(graph, "After inlining %s %+d (%d)", methodCallTargetNode.targetMethod().toString(), nodeCountAfter - nodeCountBefore, nodeCountAfter);
+                        }
 
-                    if (otherNewFrame != null) {
-                        otherNewFrame = (NewFrameNode) mapping.get(otherNewFrame);
-                        if (otherNewFrame.isAlive() && otherNewFrame.usages().isNotEmpty()) {
-                            expandTree(config, graph, otherNewFrame, assumptions);
+                        changed = true;
+
+                        if (otherNewFrame != null) {
+                            otherNewFrame = (NewFrameNode) mapping.get(otherNewFrame);
+                            if (otherNewFrame.isAlive() && otherNewFrame.usages().isNotEmpty()) {
+                                expandTree(config, graph, otherNewFrame, assumptions);
+                            }
                         }
                     }
                 }
             }
-        }
+        } while (changed && newFrameNode.isAlive() && newFrameNode.usages().isNotEmpty());
     }
 
     private StructuredGraph parseGraph(final GraphBuilderConfiguration config, final ResolvedJavaMethod targetMethod, final NodeInputList<ValueNode> arguments, final Assumptions assumptions,