changeset 19075:336adcd0070b

Clean ups in partial evaluator. New development-only option FastPE.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Tue, 03 Feb 2015 04:17:06 +0100
parents c8b2315651d3
children 5e33637f5e5a
files graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/PartialEvaluator.java graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerOptions.java graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleInlining.java graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/nodes/asserts/NeverPartOfCompilationNode.java graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/phases/VerifyNoIntrinsicsLeftPhase.java
diffstat 5 files changed, 40 insertions(+), 80 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/PartialEvaluator.java	Sun Feb 01 19:25:27 2015 +0100
+++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/PartialEvaluator.java	Tue Feb 03 04:17:06 2015 +0100
@@ -137,49 +137,20 @@
             HighTierContext tierContext = new HighTierContext(providers, assumptions, graphCache, new PhaseSuite<HighTierContext>(), OptimisticOptimizations.NONE);
 
             // EA frame and clean up.
-            try (Scope pe = Debug.scope("TrufflePartialEscape", graph)) {
-                new PartialEscapePhase(true, canonicalizer).apply(graph, tierContext);
-                new IncrementalCanonicalizerPhase<>(canonicalizer, new ConditionalEliminationPhase()).apply(graph, tierContext);
-            } catch (Throwable t) {
-                Debug.handle(t);
-            }
-
-            // to make frame propagations visible retry expandTree
-            while (expandTree(graph, assumptions, expansionLogger)) {
+            do {
                 try (Scope pe = Debug.scope("TrufflePartialEscape", graph)) {
                     new PartialEscapePhase(true, canonicalizer).apply(graph, tierContext);
                     new IncrementalCanonicalizerPhase<>(canonicalizer, new ConditionalEliminationPhase()).apply(graph, tierContext);
                 } catch (Throwable t) {
                     Debug.handle(t);
                 }
-            }
+            } while (expandTree(graph, assumptions, expansionLogger));
 
             if (expansionLogger != null) {
                 expansionLogger.print(callTarget);
             }
 
-            for (NeverPartOfCompilationNode neverPartOfCompilationNode : graph.getNodes(NeverPartOfCompilationNode.class)) {
-                Throwable exception = new VerificationError(neverPartOfCompilationNode.getMessage());
-                throw GraphUtil.approxSourceException(neverPartOfCompilationNode, exception);
-            }
-
-            new VerifyNoIntrinsicsLeftPhase().apply(graph, false);
-            for (MaterializeFrameNode materializeNode : graph.getNodes(MaterializeFrameNode.class).snapshot()) {
-                materializeNode.replaceAtUsages(materializeNode.getFrame());
-                graph.removeFixed(materializeNode);
-            }
-            for (VirtualObjectNode virtualObjectNode : graph.getNodes(VirtualObjectNode.class)) {
-                if (virtualObjectNode instanceof VirtualOnlyInstanceNode) {
-                    VirtualOnlyInstanceNode virtualOnlyInstanceNode = (VirtualOnlyInstanceNode) virtualObjectNode;
-                    virtualOnlyInstanceNode.setAllowMaterialization(true);
-                } else if (virtualObjectNode instanceof VirtualInstanceNode) {
-                    VirtualInstanceNode virtualInstanceNode = (VirtualInstanceNode) virtualObjectNode;
-                    ResolvedJavaType type = virtualInstanceNode.type();
-                    if (type.getAnnotation(CompilerDirectives.ValueType.class) != null) {
-                        virtualInstanceNode.setIdentity(false);
-                    }
-                }
-            }
+            postPartialEvaluation(graph);
 
         } catch (Throwable e) {
             throw Debug.handle(e);
@@ -188,6 +159,26 @@
         return graph;
     }
 
+    private static void postPartialEvaluation(final StructuredGraph graph) {
+        NeverPartOfCompilationNode.verifyNotFoundIn(graph);
+        for (MaterializeFrameNode materializeNode : graph.getNodes(MaterializeFrameNode.class).snapshot()) {
+            materializeNode.replaceAtUsages(materializeNode.getFrame());
+            graph.removeFixed(materializeNode);
+        }
+        for (VirtualObjectNode virtualObjectNode : graph.getNodes(VirtualObjectNode.class)) {
+            if (virtualObjectNode instanceof VirtualOnlyInstanceNode) {
+                VirtualOnlyInstanceNode virtualOnlyInstanceNode = (VirtualOnlyInstanceNode) virtualObjectNode;
+                virtualOnlyInstanceNode.setAllowMaterialization(true);
+            } else if (virtualObjectNode instanceof VirtualInstanceNode) {
+                VirtualInstanceNode virtualInstanceNode = (VirtualInstanceNode) virtualObjectNode;
+                ResolvedJavaType type = virtualInstanceNode.type();
+                if (type.getAnnotation(CompilerDirectives.ValueType.class) != null) {
+                    virtualInstanceNode.setIdentity(false);
+                }
+            }
+        }
+    }
+
     private void injectConstantCallTarget(final StructuredGraph graph, final OptimizedCallTarget constantCallTarget, PhaseContext baseContext) {
         ParameterNode thisNode = graph.getParameter(0);
 
--- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerOptions.java	Sun Feb 01 19:25:27 2015 +0100
+++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerOptions.java	Tue Feb 03 04:17:06 2015 +0100
@@ -176,5 +176,8 @@
 
     @Option(help = "Print additional more verbose Truffle compilation statistics at the end of a run.", type = OptionType.Debug)
     public static final OptionValue<Boolean> TruffleCompilationStatisticDetails = new OptionValue<>(false);
+
+    @Option(help = "Experimental new version of the partial evaluator.", type = OptionType.Debug)
+    public static final OptionValue<Boolean> FastPE = new OptionValue<>(false);
     // @formatter:on
 }
--- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleInlining.java	Sun Feb 01 19:25:27 2015 +0100
+++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleInlining.java	Tue Feb 03 04:17:06 2015 +0100
@@ -144,7 +144,12 @@
     }
 
     public TruffleInliningDecision findByCall(OptimizedDirectCallNode callNode) {
-        return getCallSites().stream().filter(c -> c.getProfile().getCallNode() == callNode).findFirst().orElse(null);
+        for (TruffleInliningDecision d : getCallSites()) {
+            if (d.getProfile().getCallNode() == callNode) {
+                return d;
+            }
+        }
+        return null;
     }
 
     /**
--- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/nodes/asserts/NeverPartOfCompilationNode.java	Sun Feb 01 19:25:27 2015 +0100
+++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/nodes/asserts/NeverPartOfCompilationNode.java	Tue Feb 03 04:17:06 2015 +0100
@@ -25,6 +25,7 @@
 import com.oracle.graal.graph.*;
 import com.oracle.graal.nodeinfo.*;
 import com.oracle.graal.nodes.*;
+import com.oracle.graal.nodes.util.*;
 import com.oracle.graal.replacements.nodes.*;
 
 @NodeInfo
@@ -44,4 +45,11 @@
     public final String getMessage() {
         return message + " " + arguments.toString();
     }
+
+    public static void verifyNotFoundIn(final StructuredGraph graph) {
+        for (NeverPartOfCompilationNode neverPartOfCompilationNode : graph.getNodes(NeverPartOfCompilationNode.class)) {
+            Throwable exception = new VerificationError(neverPartOfCompilationNode.getMessage());
+            throw GraphUtil.approxSourceException(neverPartOfCompilationNode, exception);
+        }
+    }
 }
--- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/phases/VerifyNoIntrinsicsLeftPhase.java	Sun Feb 01 19:25:27 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,47 +0,0 @@
-/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.oracle.graal.truffle.phases;
-
-import com.oracle.graal.graph.*;
-import com.oracle.graal.nodes.*;
-import com.oracle.graal.phases.*;
-import com.oracle.graal.truffle.*;
-import com.oracle.graal.truffle.nodes.frame.*;
-
-/**
- * Verification phase for checking that no frame intrinsic nodes introduced by the
- * {@link PartialEvaluator} are still in the graph.
- */
-public class VerifyNoIntrinsicsLeftPhase extends Phase {
-
-    @Override
-    protected void run(StructuredGraph graph) {
-        verifyNoInstanceLeft(graph, NewFrameNode.class);
-    }
-
-    public static <T extends Node & IterableNodeType> void verifyNoInstanceLeft(StructuredGraph graph, Class<T> clazz) {
-        if (graph.getNodes(clazz).count() != 0) {
-            throw new VerificationError("Found unexpected node(s): %s", graph.getNodes(clazz));
-        }
-    }
-}