changeset 5809:cb5fd04e95b3

Merge
author Gilles Duboscq <duboscq@ssw.jku.at>
date Wed, 04 Jul 2012 15:27:28 +0200
parents f043ecb70d3e (current diff) 7bc36486ef27 (diff)
children bc237d8b6f99
files graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/CanonicalizerPhase.java
diffstat 9 files changed, 61 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/CanonicalizerPhase.java	Wed Jul 04 14:57:12 2012 +0200
+++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/CanonicalizerPhase.java	Wed Jul 04 15:27:28 2012 +0200
@@ -22,6 +22,9 @@
  */
 package com.oracle.graal.compiler.phases;
 
+import java.util.*;
+import java.util.concurrent.*;
+
 import com.oracle.graal.api.code.*;
 import com.oracle.graal.api.meta.*;
 import com.oracle.graal.debug.*;
@@ -51,6 +54,7 @@
 
     private NodeWorkList workList;
     private Tool tool;
+    private List<Node> snapshotTemp;
 
     public CanonicalizerPhase(TargetDescription target, MetaAccessProvider runtime, Assumptions assumptions) {
         this(target, runtime, assumptions, null, 0, null);
@@ -82,6 +86,7 @@
         this.runtime = runtime;
         this.immutabilityPredicate = immutabilityPredicate;
         this.initWorkingSet = workingSet;
+        this.snapshotTemp = new ArrayList<>();
     }
 
     @Override
@@ -97,14 +102,6 @@
         }
         tool = new Tool(workList, runtime, target, assumptions, immutabilityPredicate);
         processWorkSet(graph);
-
-        while (graph.getUsagesDroppedNodesCount() > 0) {
-            for (Node n : graph.getAndCleanUsagesDroppedNodes()) {
-                if (!n.isDeleted() && n.usages().size() == 0 && GraphUtil.isFloatingNode().apply(n)) {
-                    n.safeDelete();
-                }
-            }
-        }
     }
 
     public interface IsImmutablePredicate {
@@ -138,8 +135,19 @@
                 return;
             }
             int mark = graph.getMark();
-            tryCanonicalize(node, graph, tool);
-            tryInferStamp(node, graph);
+            if (!tryKillUnused(node)) {
+                node.inputs().filter(GraphUtil.isFloatingNode()).snapshotTo(snapshotTemp);
+                if (!tryCanonicalize(node, graph, tool)) {
+                    tryInferStamp(node, graph);
+                } else {
+                    for (Node in : snapshotTemp) {
+                        if (in.isAlive() && in.usages().isEmpty()) {
+                            GraphUtil.killWithUnusedFloatingInputs(in);
+                        }
+                    }
+                }
+                snapshotTemp.clear();
+            }
 
             for (Node newNode : graph.getNewNodes(mark)) {
                 workList.add(newNode);
@@ -147,6 +155,14 @@
         }
     }
 
+    private static boolean tryKillUnused(Node node) {
+        if (node.isAlive() && GraphUtil.isFloatingNode().apply(node) && node.usages().isEmpty()) {
+            GraphUtil.killWithUnusedFloatingInputs(node);
+            return true;
+        }
+        return false;
+    }
+
     public static boolean tryGlobalValueNumbering(Node node, StructuredGraph graph) {
         if (node.getNodeClass().valueNumberable()) {
             Node newNode = graph.findDuplicate(node);
@@ -162,11 +178,11 @@
         return false;
     }
 
-    public static void tryCanonicalize(final Node node, final StructuredGraph graph, final SimplifierTool tool) {
+    public static boolean tryCanonicalize(final Node node, final StructuredGraph graph, final SimplifierTool tool) {
         if (node instanceof Canonicalizable) {
             METRIC_CANONICALIZATION_CONSIDERED_NODES.increment();
-            Debug.scope("CanonicalizeNode", node, new Runnable() {
-                public void run() {
+            return Debug.scope("CanonicalizeNode", node, new Callable<Boolean>(){
+                public Boolean call() {
                     ValueNode canonical = ((Canonicalizable) node).canonical(tool);
 //     cases:                                           original node:
 //                                         |Floating|Fixed-unconnected|Fixed-connected|
@@ -182,9 +198,9 @@
 //       X: must not happen (checked with assertions)
                     if (canonical == node) {
                         Debug.log("Canonicalizer: work on %s", node);
+                        return false;
                     } else {
                         Debug.log("Canonicalizer: replacing %s with %s", node, canonical);
-
                         METRIC_CANONICALIZED_NODES.increment();
                         if (node instanceof FloatingNode) {
                             if (canonical == null) {
@@ -192,7 +208,7 @@
                                 graph.removeFloating((FloatingNode) node);
                             } else {
                                 // case 2
-                                assert !(canonical instanceof FixedNode) || canonical.predecessor() != null : node + " -> " + canonical +
+                                assert !(canonical instanceof FixedNode) || (canonical.predecessor() != null || canonical instanceof StartNode) : node + " -> " + canonical +
                                                 " : replacement should be floating or fixed and connected";
                                 graph.replaceFloating((FloatingNode) node, canonical);
                             }
@@ -218,6 +234,7 @@
                                 }
                             }
                         }
+                        return true;
                     }
                 }
             });
@@ -226,6 +243,7 @@
             METRIC_SIMPLIFICATION_CONSIDERED_NODES.increment();
             ((Simplifiable) node).simplify(tool);
         }
+        return false;
     }
 
     /**
--- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/EscapeAnalysisPhase.java	Wed Jul 04 14:57:12 2012 +0200
+++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/EscapeAnalysisPhase.java	Wed Jul 04 15:27:28 2012 +0200
@@ -169,7 +169,7 @@
 
             if (virtual.fieldsCount() > 0) {
                 final BlockExitState startState = new BlockExitState(escapeFields, virtual);
-                final PostOrderNodeIterator<?> iterator = new PostOrderNodeIterator<BlockExitState>(next, startState) {
+                new PostOrderNodeIterator<BlockExitState>(next, startState) {
                     @Override
                     protected void node(FixedNode curNode) {
                         op.updateState(virtual, curNode, fields, state.fieldState);
@@ -183,8 +183,7 @@
                             ((StateSplit) curNode).stateAfter().addVirtualObjectMapping(v);
                         }
                     }
-                };
-                iterator.apply();
+                }.apply();
             }
         }
     }
--- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Graph.java	Wed Jul 04 14:57:12 2012 +0200
+++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Graph.java	Wed Jul 04 15:27:28 2012 +0200
@@ -47,7 +47,6 @@
     private int deletedNodeCount;
     private GraphEventLog eventLog;
 
-    ArrayList<Node> usagesDropped = new ArrayList<>();
     InputChangedListener inputChanged;
     private final HashMap<CacheEntry, Node> cachedNodes = new HashMap<>();
 
@@ -149,16 +148,6 @@
         return node;
     }
 
-    public int getUsagesDroppedNodesCount() {
-        return usagesDropped.size();
-    }
-
-    public List<Node> getAndCleanUsagesDroppedNodes() {
-        ArrayList<Node> result = usagesDropped;
-        usagesDropped = new ArrayList<>();
-        return result;
-    }
-
     public interface InputChangedListener {
         void inputChanged(Node node);
     }
--- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Node.java	Wed Jul 04 14:57:12 2012 +0200
+++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Node.java	Wed Jul 04 15:27:28 2012 +0200
@@ -279,9 +279,6 @@
 
     private boolean removeThisFromUsages(Node n) {
         if (n.usages.remove(this)) {
-            if (n.usages.size() == 0) {
-                graph.usagesDropped.add(n);
-            }
             return true;
         } else {
             return false;
--- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeList.java	Wed Jul 04 14:57:12 2012 +0200
+++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeList.java	Wed Jul 04 15:27:28 2012 +0200
@@ -55,7 +55,7 @@
             this.nodes = new Node[elements.length];
             for (int i = 0; i < elements.length; i++) {
                 this.nodes[i] = elements[i];
-                assert this.nodes[i] == null || !this.nodes[i].isDeleted();
+                assert this.nodes[i] == null || !this.nodes[i].isDeleted() : "Initializing nodelist with deleted element : " + nodes[i];
             }
         }
     }
@@ -254,6 +254,13 @@
         return (List<T>) Arrays.asList(Arrays.copyOf(this.nodes, this.size));
     }
 
+    @Override
+    public void snapshotTo(List<T> to) {
+        for (int i = 0; i < size; i++) {
+            to.add(get(i));
+        }
+    }
+
     @SuppressWarnings("unchecked")
     public void setAll(NodeList<T> values) {
         incModCount();
--- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/iterators/AbstractNodeIterable.java	Wed Jul 04 14:57:12 2012 +0200
+++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/iterators/AbstractNodeIterable.java	Wed Jul 04 15:27:28 2012 +0200
@@ -65,6 +65,12 @@
         return list;
     }
     @Override
+    public void snapshotTo(List<T> to) {
+        for (T n : this) {
+            to.add(n);
+        }
+    }
+    @Override
     public T first() {
         Iterator<T> iterator = iterator();
         if (iterator.hasNext()) {
--- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/iterators/NodeIterable.java	Wed Jul 04 14:57:12 2012 +0200
+++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/iterators/NodeIterable.java	Wed Jul 04 15:27:28 2012 +0200
@@ -44,6 +44,8 @@
 
     List<T> snapshot();
 
+    void snapshotTo(List<T> to);
+
     T first();
 
     int count();
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/NewArrayNode.java	Wed Jul 04 14:57:12 2012 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/NewArrayNode.java	Wed Jul 04 15:27:28 2012 +0200
@@ -125,12 +125,13 @@
                 AccessIndexedNode x = (AccessIndexedNode) current;
                 if (GraphUtil.unProxify(x.array()) == node) {
                     int index = ((AccessIndexedNode) current).index().asConstant().asInt();
+                    StructuredGraph graph = (StructuredGraph) x.graph();
                     if (current instanceof LoadIndexedNode) {
                         x.replaceAtUsages(fieldState[index]);
-                        ((StructuredGraph) x.graph()).removeFixed(x);
+                        graph.removeFixed(x);
                     } else if (current instanceof StoreIndexedNode) {
                         fieldState[index] = ((StoreIndexedNode) x).value();
-                        ((StructuredGraph) x.graph()).removeFixed(x);
+                        graph.removeFixed(x);
                         return index;
                     }
                 }
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/util/GraphUtil.java	Wed Jul 04 14:57:12 2012 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/util/GraphUtil.java	Wed Jul 04 15:27:28 2012 +0200
@@ -22,21 +22,24 @@
  */
 package com.oracle.graal.nodes.util;
 
-import static com.oracle.graal.graph.iterators.NodePredicates.*;
-
 import java.util.*;
 
 import com.oracle.graal.api.meta.*;
 import com.oracle.graal.graph.*;
 import com.oracle.graal.graph.iterators.*;
-import com.oracle.graal.graph.iterators.NodePredicates.PositiveTypePredicate;
 import com.oracle.graal.nodes.*;
 import com.oracle.graal.nodes.calc.*;
 import com.oracle.graal.nodes.java.*;
 
 public class GraphUtil {
 
-    private static final PositiveTypePredicate FLOATING = isA(FloatingNode.class).or(VirtualState.class).or(CallTargetNode.class);
+    private static final NodePredicate FLOATING = new NodePredicate() {
+        @Override
+        public final boolean  apply(Node n) {
+            //isA(FloatingNode.class).or(VirtualState.class).or(CallTargetNode.class)
+            return n instanceof FloatingNode || n instanceof VirtualState || n instanceof CallTargetNode;
+        }
+    };
 
     public static void killCFG(FixedNode node) {
         assert node.isAlive();