changeset 4411:cd2b68ef8e23

cleanup around filter and predicates : remove duplicate compiler.util.NodeIterators add contains to NodeIterable support isNotA(Class).nor(Class) filtering support filtering on interfaces remove and/or(Class) from FilteredNodeIterable replace with isA(Class).or(Class) lower the cost on extending NodeIterable (remove the until field) NodeList is a NodeIterable Use NodeIterable functions where possible
author Gilles Duboscq <duboscq@ssw.jku.at>
date Mon, 30 Jan 2012 13:06:11 +0100
parents b801d2f9e2b0
children ccbdd90bf356
files graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/BoxingEliminationPhase.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/CanonicalizerPhase.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/EscapeAnalysisPhase.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/InliningPhase.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/PhiStampPhase.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/SafepointPollingEliminationPhase.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/SnippetIntrinsificationPhase.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/schedule/IdentifyBlocksPhase.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/util/InliningUtil.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/util/NodeIterators.java graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/Graph.java graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/NodeInputsIterable.java graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/NodeList.java graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/NodeSuccessorsIterable.java graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/NodeUsagesList.java graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/iterators/FilteredNodeIterable.java graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/iterators/NodeIterable.java graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/iterators/NodeIterator.java graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/iterators/NodePredicate.java graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/iterators/NodePredicates.java graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/iterators/PredicatedProxyNodeIterator.java graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/iterators/TypePredicate.java graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/EndNode.java graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/FrameState.java graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/LoopBeginNode.java graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/MergeNode.java graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/java/MethodCallTargetNode.java graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/spi/EscapeOp.java graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/util/NodeIterators.java graal/com.oracle.max.graal.printer/src/com/oracle/max/graal/printer/IdealGraphPrinter.java graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/BoxingEliminationTest.java graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/DegeneratedLoopsTest.java graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/IfCanonicalizerTest.java graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/InvokeTest.java graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/MonitorTest.java
diffstat 36 files changed, 427 insertions(+), 395 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java	Fri Jan 27 00:40:26 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java	Mon Jan 30 13:06:11 2012 +0100
@@ -394,7 +394,7 @@
         }
         if (block.numberOfSux() >= 1 && !block.endsWithJump()) {
             NodeSuccessorsIterable successors = block.lastNode().successors();
-            assert successors.explicitCount() >= 1 : "should have at least one successor : " + block.lastNode();
+            assert successors.count() >= 1 : "should have at least one successor : " + block.lastNode();
 
             emitJump(getLIRBlock((FixedNode) successors.first()), null);
         }
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/BoxingEliminationPhase.java	Fri Jan 27 00:40:26 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/BoxingEliminationPhase.java	Mon Jan 30 13:06:11 2012 +0100
@@ -22,11 +22,14 @@
  */
 package com.oracle.max.graal.compiler.phases;
 
+import static com.oracle.max.graal.graph.iterators.NodePredicates.*;
+
 import java.util.*;
 
 import com.oracle.max.cri.ci.*;
 import com.oracle.max.cri.ri.*;
 import com.oracle.max.graal.graph.*;
+import com.oracle.max.graal.graph.iterators.*;
 import com.oracle.max.graal.nodes.*;
 import com.oracle.max.graal.nodes.PhiNode.*;
 import com.oracle.max.graal.nodes.extended.*;
@@ -106,11 +109,9 @@
 
         virtualizeUsages(boxNode, boxNode.source(), boxNode.exactType());
 
-        for (Node n : boxNode.usages()) {
-            if (!(n instanceof FrameState) && !(n instanceof VirtualObjectFieldNode)) {
-                // Elimination failed, because boxing object escapes.
-                return;
-            }
+        if (boxNode.usages().filter(isNotA(FrameState.class).nor(VirtualObjectFieldNode.class)).isNotEmpty()) {
+            // Elimination failed, because boxing object escapes.
+            return;
         }
 
         // TODO(ls) this seems weird: there might still be references to boxNode, yet it is deleted...
@@ -125,7 +126,7 @@
     private static void virtualizeUsages(ValueNode boxNode, ValueNode replacement, RiResolvedType exactType) {
         ValueNode virtualValueNode = null;
         VirtualObjectNode virtualObjectNode = null;
-        for (Node n : boxNode.usages().filter(FrameState.class).or(VirtualObjectFieldNode.class).snapshot()) {
+        for (Node n : boxNode.usages().filter(NodePredicates.isA(FrameState.class).or(VirtualObjectFieldNode.class)).snapshot()) {
             if (virtualValueNode == null) {
                 virtualObjectNode = n.graph().unique(new BoxedVirtualObjectNode(exactType, replacement));
             }
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/CanonicalizerPhase.java	Fri Jan 27 00:40:26 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/CanonicalizerPhase.java	Mon Jan 30 13:06:11 2012 +0100
@@ -22,6 +22,8 @@
  */
 package com.oracle.max.graal.compiler.phases;
 
+import static com.oracle.max.graal.graph.iterators.NodePredicates.*;
+
 import com.oracle.max.cri.ci.*;
 import com.oracle.max.cri.ri.*;
 import com.oracle.max.criutils.*;
@@ -235,8 +237,8 @@
             if (node instanceof PhiNode) {
                 node.replaceFirstInput(input, null);
             } else {
-                for (Node usage : node.usages().snapshot()) {
-                    if ((usage instanceof FloatingNode || usage instanceof CallTargetNode) && !usage.isDeleted()) {
+                for (Node usage : node.usages().filter(isA(FloatingNode.class).or(CallTargetNode.class)).snapshot()) {
+                    if (!usage.isDeleted()) {
                         killNonCFG(usage, node);
                     }
                 }
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/EscapeAnalysisPhase.java	Fri Jan 27 00:40:26 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/EscapeAnalysisPhase.java	Mon Jan 30 13:06:11 2012 +0100
@@ -305,7 +305,7 @@
     private static Node escape(EscapeRecord record, Node usage) {
         final Node node = record.node;
         if (usage instanceof FrameState) {
-            assert ((FrameState) usage).inputs().contains(node);
+            assert usage.inputs().contains(node);
             return null;
         } else {
             if (usage instanceof FixedNode) {
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/InliningPhase.java	Fri Jan 27 00:40:26 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/InliningPhase.java	Mon Jan 30 13:06:11 2012 +0100
@@ -133,11 +133,8 @@
                     Invoke invoke = (Invoke) node;
                     scanInvoke(invoke, level);
                 }
-                for (Node usage : node.usages().snapshot()) {
-                    if (usage instanceof Invoke) {
-                        Invoke invoke = (Invoke) usage;
-                        scanInvoke(invoke, level);
-                    }
+                for (Node usage : node.usages().filterInterface(Invoke.class).snapshot()) {
+                    scanInvoke((Invoke) usage, level);
                 }
             }
         }
@@ -149,7 +146,6 @@
             if (GraalOptions.Meter) {
                 currentContext.metrics.InlineConsidered++;
             }
-
             inlineCandidates.add(info);
         }
     }
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/PhiStampPhase.java	Fri Jan 27 00:40:26 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/PhiStampPhase.java	Mon Jan 30 13:06:11 2012 +0100
@@ -22,7 +22,6 @@
  */
 package com.oracle.max.graal.compiler.phases;
 
-import com.oracle.max.graal.graph.*;
 import com.oracle.max.graal.nodes.*;
 
 public class PhiStampPhase extends Phase {
@@ -45,22 +44,16 @@
 
     private void iterativeInferPhi(PhiNode phi) {
         if (phi.inferStamp()) {
-            for (Node n : phi.usages()) {
-                if (n instanceof PhiNode) {
-                    PhiNode phiUsage = (PhiNode) n;
-                    iterativeInferPhi(phiUsage);
-                }
+            for (PhiNode phiUsage : phi.usages().filter(PhiNode.class)) {
+                iterativeInferPhi(phiUsage);
             }
         }
     }
 
     private void inferPhi(PhiNode phi) {
-        for (ValueNode v : phi.values()) {
-            if (v instanceof PhiNode) {
-                PhiNode phiInput = (PhiNode) v;
-                if (!phiInput.isLoopPhi()) {
-                    inferPhi(phiInput);
-                }
+        for (PhiNode phiInput : phi.values().filter(PhiNode.class)) {
+            if (!phiInput.isLoopPhi()) {
+                inferPhi(phiInput);
             }
         }
         phi.inferStamp();
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/SafepointPollingEliminationPhase.java	Fri Jan 27 00:40:26 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/SafepointPollingEliminationPhase.java	Mon Jan 30 13:06:11 2012 +0100
@@ -22,9 +22,9 @@
  */
 package com.oracle.max.graal.compiler.phases;
 
-import com.oracle.max.graal.compiler.util.*;
 import com.oracle.max.graal.graph.iterators.*;
 import com.oracle.max.graal.nodes.*;
+import com.oracle.max.graal.util.*;
 
 public class SafepointPollingEliminationPhase extends Phase {
 
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/SnippetIntrinsificationPhase.java	Fri Jan 27 00:40:26 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/SnippetIntrinsificationPhase.java	Mon Jan 30 13:06:11 2012 +0100
@@ -169,36 +169,33 @@
     public void cleanUpReturnCheckCast(Node newInstance) {
         if (newInstance instanceof ValueNode && ((ValueNode) newInstance).kind() != CiKind.Object) {
             StructuredGraph graph = (StructuredGraph) newInstance.graph();
-            for (Node usage : newInstance.usages().snapshot()) {
-                if (usage instanceof CheckCastNode) {
-                    CheckCastNode checkCastNode = (CheckCastNode) usage;
-                    for (Node checkCastUsage : checkCastNode.usages().snapshot()) {
-                        if (checkCastUsage instanceof ValueAnchorNode) {
-                            ValueAnchorNode valueAnchorNode = (ValueAnchorNode) checkCastUsage;
-                            graph.removeFixed(valueAnchorNode);
-                        } else if (checkCastUsage instanceof MethodCallTargetNode) {
-                            MethodCallTargetNode checkCastCallTarget = (MethodCallTargetNode) checkCastUsage;
-                            assert pool.isUnboxingMethod(checkCastCallTarget.targetMethod());
-                            Invoke invokeNode = checkCastCallTarget.invoke();
-                            invokeNode.node().replaceAtUsages(newInstance);
-                            if (invokeNode instanceof InvokeWithExceptionNode) {
-                                // Destroy exception edge & clear stateAfter.
-                                InvokeWithExceptionNode invokeWithExceptionNode = (InvokeWithExceptionNode) invokeNode;
+            for (CheckCastNode checkCastNode : newInstance.usages().filter(CheckCastNode.class).snapshot()) {
+                for (Node checkCastUsage : checkCastNode.usages().snapshot()) {
+                    if (checkCastUsage instanceof ValueAnchorNode) {
+                        ValueAnchorNode valueAnchorNode = (ValueAnchorNode) checkCastUsage;
+                        graph.removeFixed(valueAnchorNode);
+                    } else if (checkCastUsage instanceof MethodCallTargetNode) {
+                        MethodCallTargetNode checkCastCallTarget = (MethodCallTargetNode) checkCastUsage;
+                        assert pool.isUnboxingMethod(checkCastCallTarget.targetMethod());
+                        Invoke invokeNode = checkCastCallTarget.invoke();
+                        invokeNode.node().replaceAtUsages(newInstance);
+                        if (invokeNode instanceof InvokeWithExceptionNode) {
+                            // Destroy exception edge & clear stateAfter.
+                            InvokeWithExceptionNode invokeWithExceptionNode = (InvokeWithExceptionNode) invokeNode;
 
-                                invokeWithExceptionNode.killExceptionEdge();
-                                graph.removeSplit(invokeWithExceptionNode, InvokeWithExceptionNode.NORMAL_EDGE);
-                            } else {
-                                graph.removeFixed((InvokeNode) invokeNode);
-                            }
-                            checkCastCallTarget.safeDelete();
-                        } else if (checkCastUsage instanceof FrameState) {
-                            checkCastUsage.replaceFirstInput(checkCastNode, null);
+                            invokeWithExceptionNode.killExceptionEdge();
+                            graph.removeSplit(invokeWithExceptionNode, InvokeWithExceptionNode.NORMAL_EDGE);
                         } else {
-                            assert false : "unexpected checkcast usage: " + checkCastUsage;
+                            graph.removeFixed((InvokeNode) invokeNode);
                         }
+                        checkCastCallTarget.safeDelete();
+                    } else if (checkCastUsage instanceof FrameState) {
+                        checkCastUsage.replaceFirstInput(checkCastNode, null);
+                    } else {
+                        assert false : "unexpected checkcast usage: " + checkCastUsage;
                     }
-                    checkCastNode.safeDelete();
                 }
+                checkCastNode.safeDelete();
             }
         }
     }
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/schedule/IdentifyBlocksPhase.java	Fri Jan 27 00:40:26 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/schedule/IdentifyBlocksPhase.java	Mon Jan 30 13:06:11 2012 +0100
@@ -179,10 +179,8 @@
         }
 
         if (n instanceof MergeNode) {
-            for (Node usage : n.usages()) {
-                if (usage instanceof PhiNode) {
-                    nodeToBlock.set(usage, b);
-                }
+            for (PhiNode phi : ((MergeNode) n).phis()) {
+                nodeToBlock.set(phi, b);
             }
         }
         if (n instanceof EndNode) {
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/util/InliningUtil.java	Fri Jan 27 00:40:26 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/util/InliningUtil.java	Mon Jan 30 13:06:11 2012 +0100
@@ -392,7 +392,7 @@
             InvokeWithExceptionNode invokeWithException = ((InvokeWithExceptionNode) invoke);
             if (unwindNode != null) {
                 assert unwindNode.predecessor() != null;
-                assert invokeWithException.exceptionEdge().successors().explicitCount() == 1;
+                assert invokeWithException.exceptionEdge().successors().count() == 1;
                 ExceptionObjectNode obj = (ExceptionObjectNode) invokeWithException.exceptionEdge().next();
                 stateAtExceptionEdge = obj.stateAfter();
                 UnwindNode unwindDuplicate = (UnwindNode) duplicates.get(unwindNode);
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/util/NodeIterators.java	Fri Jan 27 00:40:26 2012 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,54 +0,0 @@
-/*
- * Copyright (c) 2011, 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.max.graal.compiler.util;
-
-import java.util.*;
-
-import com.oracle.max.graal.graph.iterators.*;
-import com.oracle.max.graal.nodes.*;
-import com.oracle.max.graal.util.*;
-
-public class NodeIterators {
-
-    public static NodeIterable<FixedNode> dominators(final FixedNode n) {
-        return new NodeIterable<FixedNode>() {
-            @Override
-            public Iterator<FixedNode> iterator() {
-                return new NodeIterator<FixedNode>(until){
-                    FixedNode p = n;
-                    @Override
-                    protected void forward() {
-                        if (current == null) {
-                            if (p instanceof MergeNode) {
-                                current = new ComputeImmediateDominator((MergeNode) p).compute();
-                            } else {
-                                current = (FixedNode) p.predecessor();
-                            }
-                            p = current;
-                        }
-                    }
-                };
-            }
-        };
-    }
-}
--- a/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/Graph.java	Fri Jan 27 00:40:26 2012 +0100
+++ b/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/Graph.java	Mon Jan 30 13:06:11 2012 +0100
@@ -265,9 +265,9 @@
      * Returns an {@link Iterable} providing all nodes added since the last {@link Graph#mark() mark}.
      * @return an {@link Iterable} providing the new nodes
      */
-    public Iterable<Node> getNewNodes() {
+    public NodeIterable<Node> getNewNodes() {
         final int index = this.mark;
-        return new Iterable<Node>() {
+        return new NodeIterable<Node>() {
             @Override
             public Iterator<Node> iterator() {
                 return new NodeIterator(index);
--- a/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/NodeInputsIterable.java	Fri Jan 27 00:40:26 2012 +0100
+++ b/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/NodeInputsIterable.java	Mon Jan 30 13:06:11 2012 +0100
@@ -26,9 +26,6 @@
 import com.oracle.max.graal.graph.iterators.*;
 
 public abstract class NodeInputsIterable extends NodeIterable<Node> {
-
-    public abstract boolean contains(Node node);
-
     @Override
     public abstract NodeClassIterator iterator();
 }
--- a/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/NodeList.java	Fri Jan 27 00:40:26 2012 +0100
+++ b/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/NodeList.java	Mon Jan 30 13:06:11 2012 +0100
@@ -27,7 +27,9 @@
 import java.util.List;
 import java.util.ListIterator;
 
-public abstract class NodeList<T extends Node> implements Iterable<T>, List<T> {
+import com.oracle.max.graal.graph.iterators.*;
+
+public abstract class NodeList<T extends Node> extends NodeIterable<T> implements List<T> {
 
     protected static final Node[] EMPTY_NODE_ARRAY = new Node[0];
 
@@ -74,6 +76,16 @@
         return size == 0;
     }
 
+    @Override
+    public boolean isNotEmpty() {
+        return size > 0;
+    }
+
+    @Override
+    public int count() {
+        return size;
+    }
+
     protected final void incModCount() {
         modCount++;
     }
@@ -214,6 +226,7 @@
         };
     }
 
+    @Override
     public boolean contains(T other) {
         for (int i = 0; i < size; i++) {
             if (nodes[i] == other) {
@@ -223,33 +236,10 @@
         return false;
     }
 
-    public Iterable<T> snapshot() {
-        return new Iterable<T>() {
-
-            @Override
-            public Iterator<T> iterator() {
-                return new Iterator<T>() {
-                    private Node[] nodesCopy = Arrays.copyOf(NodeList.this.nodes, NodeList.this.size);
-                    private int index = 0;
-
-                    @Override
-                    public boolean hasNext() {
-                        return index < nodesCopy.length;
-                    }
-
-                    @SuppressWarnings("unchecked")
-                    @Override
-                    public T next() {
-                        return (T) nodesCopy[index++];
-                    }
-
-                    @Override
-                    public void remove() {
-                        throw new UnsupportedOperationException();
-                    }
-                };
-            }
-        };
+    @SuppressWarnings("unchecked")
+    @Override
+    public List<T> snapshot() {
+        return (List<T>) Arrays.asList(Arrays.copyOf(this.nodes, this.size));
     }
 
     @SuppressWarnings("unchecked")
--- a/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/NodeSuccessorsIterable.java	Fri Jan 27 00:40:26 2012 +0100
+++ b/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/NodeSuccessorsIterable.java	Mon Jan 30 13:06:11 2012 +0100
@@ -26,17 +26,6 @@
 import com.oracle.max.graal.graph.iterators.*;
 
 public abstract class NodeSuccessorsIterable extends NodeIterable<Node> {
-
-    public int explicitCount() {
-        int count = 0;
-        for (@SuppressWarnings("unused") Node node : this) {
-            count++;
-        }
-        return count;
-    }
-
-    public abstract boolean contains(Node node);
-
     @Override
     public abstract NodeClassIterator iterator();
 }
--- a/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/NodeUsagesList.java	Fri Jan 27 00:40:26 2012 +0100
+++ b/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/NodeUsagesList.java	Mon Jan 30 13:06:11 2012 +0100
@@ -58,6 +58,11 @@
         return size > 0;
     }
 
+    @Override
+    public int count() {
+        return size;
+    }
+
     protected void incModCount() {
         modCount++;
     }
@@ -140,6 +145,7 @@
         };
     }
 
+    @Override
     public boolean contains(Node other) {
         for (int i = 0; i < size; i++) {
             if (nodes[i] == other) {
--- a/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/iterators/FilteredNodeIterable.java	Fri Jan 27 00:40:26 2012 +0100
+++ b/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/iterators/FilteredNodeIterable.java	Mon Jan 30 13:06:11 2012 +0100
@@ -28,20 +28,10 @@
 
 public class FilteredNodeIterable<T extends Node> extends NodeIterable<T> {
     private final NodeIterable<T> nodeIterable;
-    private NodePredicate predicate = NodePredicate.TAUTOLOGY;
+    private NodePredicate predicate = NodePredicates.alwaysTrue();
+    private NodePredicate until = NodePredicates.isNull();
     public FilteredNodeIterable(NodeIterable<T> nodeIterable) {
         this.nodeIterable = nodeIterable;
-        this.until = nodeIterable.until;
-    }
-    @SuppressWarnings("unchecked")
-    public <F extends T> FilteredNodeIterable<F> and(Class<F> clazz) {
-        this.predicate = predicate.and(new TypePredicate(clazz));
-        return (FilteredNodeIterable<F>) this;
-    }
-    @SuppressWarnings("unchecked")
-    public FilteredNodeIterable<Node> or(Class<? extends Node> clazz) {
-        this.predicate = predicate.or(new TypePredicate(clazz));
-        return (FilteredNodeIterable<Node>) this;
     }
     public FilteredNodeIterable<T> and(NodePredicate nodePredicate) {
         this.predicate = this.predicate.and(nodePredicate);
@@ -52,8 +42,34 @@
         return this;
     }
     @Override
+    public NodeIterable<T> until(final T u) {
+        until = until.or(NodePredicates.equals(u));
+        return this;
+    }
+    @Override
+    public NodeIterable<T> until(final Class<? extends T> clazz) {
+        until = until.or(NodePredicates.isA(clazz));
+        return this;
+    }
+    @Override
     public Iterator<T> iterator() {
         final Iterator<T> iterator = nodeIterable.iterator();
         return new PredicatedProxyNodeIterator<>(until, iterator, predicate);
     }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public <F extends T> FilteredNodeIterable<F> filter(Class<F> clazz) {
+        return (FilteredNodeIterable<F>) this.and(NodePredicates.isA(clazz));
+    }
+
+    @Override
+    public FilteredNodeIterable<T> filter(NodePredicate p) {
+        return this.and(p);
+    }
+
+    @Override
+    public FilteredNodeIterable<T> filterInterface(Class< ? > iface) {
+        return this.and(NodePredicates.isAInterface(iface));
+    }
 }
--- a/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/iterators/NodeIterable.java	Fri Jan 27 00:40:26 2012 +0100
+++ b/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/iterators/NodeIterable.java	Mon Jan 30 13:06:11 2012 +0100
@@ -27,17 +27,18 @@
 import com.oracle.max.graal.graph.*;
 
 public abstract class NodeIterable<T extends Node> implements Iterable<T> {
-    protected NodePredicate until = NodePredicate.IS_NULL;
     public NodeIterable<T> until(final T u) {
-        until = until.or(NodePredicate.equals(u));
-        return this;
+        return new FilteredNodeIterable<>(this).until(u);
     }
     public NodeIterable<T> until(final Class<? extends T> clazz) {
-        until = until.or(new TypePredicate(clazz));
-        return this;
+        return new FilteredNodeIterable<>(this).until(clazz);
     }
+    @SuppressWarnings("unchecked")
     public <F extends T> FilteredNodeIterable<F> filter(Class<F> clazz) {
-        return new FilteredNodeIterable<>(this).and(clazz);
+        return (FilteredNodeIterable<F>) new FilteredNodeIterable<>(this).and(NodePredicates.isA(clazz));
+    }
+    public FilteredNodeIterable<T> filterInterface(Class<?> iface) {
+        return new FilteredNodeIterable<>(this).and(NodePredicates.isAInterface(iface));
     }
     public FilteredNodeIterable<T> filter(NodePredicate predicate) {
         return new FilteredNodeIterable<>(this).and(predicate);
@@ -71,4 +72,7 @@
     public boolean isNotEmpty() {
         return iterator().hasNext();
     }
+    public boolean contains(T node) {
+        return this.filter(NodePredicates.equals(node)).isNotEmpty();
+    }
 }
--- a/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/iterators/NodeIterator.java	Fri Jan 27 00:40:26 2012 +0100
+++ b/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/iterators/NodeIterator.java	Mon Jan 30 13:06:11 2012 +0100
@@ -28,21 +28,17 @@
 
 public abstract class NodeIterator<T extends Node> implements Iterator<T>{
     protected T current;
-    protected final NodePredicate until;
-    public NodeIterator(NodePredicate until) {
-        this.until = until;
-    }
     protected abstract void forward();
     @Override
     public boolean hasNext() {
         forward();
-        return current != null && !until.apply(current);
+        return current != null;
     }
     @Override
     public T next() {
         forward();
         T ret = current;
-        if (current == null || until.apply(current)) {
+        if (current == null) {
             throw new NoSuchElementException();
         }
         current = null;
--- a/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/iterators/NodePredicate.java	Fri Jan 27 00:40:26 2012 +0100
+++ b/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/iterators/NodePredicate.java	Mon Jan 30 13:06:11 2012 +0100
@@ -25,78 +25,18 @@
 import com.oracle.max.graal.graph.*;
 
 public abstract class NodePredicate {
-    public static final TautologyPredicate TAUTOLOGY = new TautologyPredicate();
-
-    public static final IsNullPredicate IS_NULL = new IsNullPredicate();
-
-    public static final class TautologyPredicate extends NodePredicate {
-        @Override
-        public boolean apply(Node n) {
-            return true;
-        }
-    }
-
-    public static final class AndPredicate extends NodePredicate {
-        private final NodePredicate a;
-        private final NodePredicate b;
-        private AndPredicate(NodePredicate np, NodePredicate thiz) {
-            this.a = np;
-            this.b = thiz;
-        }
-        @Override
-        public boolean apply(Node n) {
-            return b.apply(n) && a.apply(n);
-        }
-    }
-
-    public static final class OrPredicate extends NodePredicate {
-        private final NodePredicate a;
-        private final NodePredicate b;
-        private OrPredicate(NodePredicate np, NodePredicate thiz) {
-            this.a = np;
-            this.b = thiz;
-        }
-        @Override
-        public boolean apply(Node n) {
-            return b.apply(n) || a.apply(n);
-        }
-    }
-
-    public static final class IsNullPredicate extends NodePredicate {
-        @Override
-        public boolean apply(Node n) {
-            return n == null;
-        }
-    }
-
-    public static final class EqualsPredicate<T extends Node> extends NodePredicate {
-        private final T u;
-        public EqualsPredicate(T u) {
-            this.u = u;
-        }
-        @Override
-        public boolean apply(Node n) {
-            return u == n;
-        }
-    }
 
     public abstract boolean apply(Node n);
 
-    public NodePredicate and(final NodePredicate np) {
-        if (this instanceof TautologyPredicate) {
-            return np;
-        }
-        return new AndPredicate(this, np);
+    public NodePredicate and(NodePredicate np) {
+        return NodePredicates.and(this, np);
     }
 
-    public NodePredicate or(final NodePredicate np) {
-        if (this instanceof TautologyPredicate) {
-            return this;
-        }
-        return new OrPredicate(this, np);
+    public NodePredicate or(NodePredicate np) {
+        return NodePredicates.or(this, np);
     }
 
-    public static <T extends Node> EqualsPredicate<T> equals(T u) {
-        return new EqualsPredicate<>(u);
+    public NodePredicate negate() {
+        return NodePredicates.not(this);
     }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/iterators/NodePredicates.java	Mon Jan 30 13:06:11 2012 +0100
@@ -0,0 +1,266 @@
+/*
+ * Copyright (c) 2012, 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.max.graal.graph.iterators;
+
+import com.oracle.max.graal.graph.*;
+
+public abstract class NodePredicates {
+    private static final TautologyPredicate TAUTOLOGY = new TautologyPredicate();
+    private static final FalsePredicate FALSE = new FalsePredicate();
+    private static final IsNullPredicate IS_NULL = new IsNullPredicate();
+    private static final IsNotNullPredicate IS_NOT_NULL = new IsNotNullPredicate();
+
+    public static NodePredicate alwaysTrue() {
+        return TAUTOLOGY;
+    }
+
+    public static NodePredicate alwaysFalse() {
+        return FALSE;
+    }
+
+    public static NodePredicate isNull() {
+        return IS_NULL;
+    }
+
+    public static NodePredicate isNotNull() {
+        return IS_NOT_NULL;
+    }
+
+    public static NodePredicate equals(Node n) {
+        return new EqualsPredicate(n);
+    }
+
+    public static NodePredicate not(NodePredicate a) {
+        if (a == TAUTOLOGY) {
+            return FALSE;
+        }
+        if (a == FALSE) {
+            return TAUTOLOGY;
+        }
+        if (a == IS_NULL) {
+            return IS_NOT_NULL;
+        }
+        if (a == IS_NOT_NULL) {
+            return IS_NULL;
+        }
+        if (a instanceof NotPredicate) {
+            return ((NotPredicate) a).a;
+        }
+        if (a instanceof PositiveTypePredicate) {
+            return new NegativeTypePredicate((PositiveTypePredicate) a);
+        }
+        if (a instanceof NegativeTypePredicate) {
+            return new PositiveTypePredicate((NegativeTypePredicate) a);
+        }
+        if (a instanceof EqualsPredicate) {
+            return new NotEqualsPredicate(((EqualsPredicate) a).u);
+        }
+        if (a instanceof NotEqualsPredicate) {
+            return new EqualsPredicate(((NotEqualsPredicate) a).u);
+        }
+        return new NotPredicate(a);
+    }
+
+    public static NodePredicate and(NodePredicate a, NodePredicate b) {
+        if (a == TAUTOLOGY) {
+            return b;
+        }
+        if (b == TAUTOLOGY) {
+            return a;
+        }
+        if (a == FALSE || b == FALSE) {
+            return FALSE;
+        }
+        return new AndPredicate(a, b);
+    }
+
+    public static NodePredicate or(NodePredicate a, NodePredicate b) {
+        if (a == FALSE) {
+            return b;
+        }
+        if (b == FALSE) {
+            return a;
+        }
+        if (a == TAUTOLOGY || b == TAUTOLOGY) {
+            return TAUTOLOGY;
+        }
+        return new OrPredicate(a, b);
+    }
+
+    public static NegativeTypePredicate isNotA(Class<? extends Node> clazz) {
+        return new NegativeTypePredicate(clazz);
+    }
+
+    public static PositiveTypePredicate isA(Class<? extends Node> clazz) {
+        return new PositiveTypePredicate(clazz);
+    }
+
+    public static NodePredicate isAInterface(Class<?> iface) {
+        assert iface.isInterface();
+        return new PositiveTypePredicate(iface);
+    }
+
+    public static NodePredicate isNotAInterface(Class<?> iface) {
+        assert iface.isInterface();
+        return new NegativeTypePredicate(iface);
+    }
+
+    private static final class TautologyPredicate extends NodePredicate {
+        @Override
+        public boolean apply(Node n) {
+            return true;
+        }
+    }
+
+    private static final class FalsePredicate extends NodePredicate {
+        @Override
+        public boolean apply(Node n) {
+            return false;
+        }
+    }
+
+    private static final class AndPredicate extends NodePredicate {
+        private final NodePredicate a;
+        private final NodePredicate b;
+        private AndPredicate(NodePredicate pa, NodePredicate pb) {
+            this.a = pa;
+            this.b = pb;
+        }
+        @Override
+        public boolean apply(Node n) {
+            return b.apply(n) && a.apply(n);
+        }
+    }
+
+    private static final class NotPredicate extends NodePredicate {
+        private final NodePredicate a;
+        private NotPredicate(NodePredicate n) {
+            this.a = n;
+        }
+        @Override
+        public boolean apply(Node n) {
+            return !a.apply(n);
+        }
+    }
+
+    private static final class OrPredicate extends NodePredicate {
+        private final NodePredicate a;
+        private final NodePredicate b;
+        private OrPredicate(NodePredicate np, NodePredicate thiz) {
+            this.a = np;
+            this.b = thiz;
+        }
+        @Override
+        public boolean apply(Node n) {
+            return b.apply(n) || a.apply(n);
+        }
+    }
+
+    private static final class IsNullPredicate extends NodePredicate {
+        @Override
+        public boolean apply(Node n) {
+            return n == null;
+        }
+    }
+
+    private static final class IsNotNullPredicate extends NodePredicate {
+        @Override
+        public boolean apply(Node n) {
+            return n != null;
+        }
+    }
+
+    private static final class EqualsPredicate extends NodePredicate {
+        private final Node u;
+        public EqualsPredicate(Node u) {
+            this.u = u;
+        }
+        @Override
+        public boolean apply(Node n) {
+            return u == n;
+        }
+    }
+
+    private static final class NotEqualsPredicate extends NodePredicate {
+        private final Node u;
+        public NotEqualsPredicate(Node u) {
+            this.u = u;
+        }
+        @Override
+        public boolean apply(Node n) {
+            return u != n;
+        }
+    }
+
+    public static final class PositiveTypePredicate extends NodePredicate {
+        private final Class<?> type;
+        private PositiveTypePredicate or;
+        public PositiveTypePredicate(Class<?> type) {
+            this.type = type;
+        }
+        public PositiveTypePredicate(NegativeTypePredicate a) {
+            type = a.type;
+            if (a.nor != null) {
+                or = new PositiveTypePredicate(a.nor);
+            }
+        }
+        @Override
+        public boolean apply(Node n) {
+            return type.isInstance(n) || (or != null && or.apply(n));
+        }
+        public PositiveTypePredicate or(Class<? extends Node> clazz) {
+            if (or == null) {
+                or = new PositiveTypePredicate(clazz);
+            } else {
+                or.or(clazz);
+            }
+            return this;
+        }
+    }
+
+    public static final class NegativeTypePredicate extends NodePredicate {
+        private final Class<?> type;
+        private NegativeTypePredicate nor;
+        public NegativeTypePredicate(Class<?> type) {
+            this.type = type;
+        }
+        public NegativeTypePredicate(PositiveTypePredicate a) {
+            type = a.type;
+            if (a.or != null) {
+                nor = new NegativeTypePredicate(a.or);
+            }
+        }
+        @Override
+        public boolean apply(Node n) {
+            return !type.isInstance(n) && (nor == null || nor.apply(n));
+        }
+        public NegativeTypePredicate nor(Class<? extends Node> clazz) {
+            if (nor == null) {
+                nor = new NegativeTypePredicate(clazz);
+            } else {
+                nor.nor(clazz);
+            }
+            return this;
+        }
+    }
+}
--- a/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/iterators/PredicatedProxyNodeIterator.java	Fri Jan 27 00:40:26 2012 +0100
+++ b/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/iterators/PredicatedProxyNodeIterator.java	Mon Jan 30 13:06:11 2012 +0100
@@ -29,8 +29,9 @@
 public final class PredicatedProxyNodeIterator<T extends Node> extends NodeIterator<T> {
     private final Iterator<T> iterator;
     private final NodePredicate predicate;
+    private final NodePredicate until;
     public PredicatedProxyNodeIterator(NodePredicate until, Iterator<T> iterator, NodePredicate predicate) {
-        super(until);
+        this.until = until;
         this.iterator = iterator;
         this.predicate = predicate;
     }
@@ -39,7 +40,7 @@
         while ((current == null || !current.isAlive() || !predicate.apply(current)) && iterator.hasNext()) {
             current = iterator.next();
         }
-        if (current != null && (!current.isAlive() || !predicate.apply(current))) {
+        if (current != null && (!current.isAlive() || !predicate.apply(current) || until.apply(current))) {
             current = null;
         }
     }
--- a/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/iterators/TypePredicate.java	Fri Jan 27 00:40:26 2012 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,36 +0,0 @@
-/*
- * Copyright (c) 2011, 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.max.graal.graph.iterators;
-
-import com.oracle.max.graal.graph.*;
-
-public final class TypePredicate extends NodePredicate {
-    private final Class<? extends Node> type;
-    public TypePredicate(Class< ? extends Node> type) {
-        this.type = type;
-    }
-    @Override
-    public boolean apply(Node n) {
-        return type.isInstance(n);
-    }
-}
--- a/graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/EndNode.java	Fri Jan 27 00:40:26 2012 +0100
+++ b/graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/EndNode.java	Mon Jan 30 13:06:11 2012 +0100
@@ -40,12 +40,7 @@
     }
 
     public MergeNode merge() {
-        if (usages().size() == 0) {
-            return null;
-        } else {
-            assert usages().size() == 1;
-            return (MergeNode) usages().iterator().next();
-        }
+        return (MergeNode) usages().first();
     }
 
     @Override
--- a/graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/FrameState.java	Fri Jan 27 00:40:26 2012 +0100
+++ b/graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/FrameState.java	Mon Jan 30 13:06:11 2012 +0100
@@ -27,6 +27,7 @@
 import com.oracle.max.cri.ci.*;
 import com.oracle.max.cri.ri.*;
 import com.oracle.max.graal.graph.*;
+import com.oracle.max.graal.graph.iterators.*;
 import com.oracle.max.graal.nodes.PhiNode.PhiType;
 import com.oracle.max.graal.nodes.spi.*;
 import com.oracle.max.graal.nodes.virtual.*;
@@ -455,9 +456,8 @@
     public void deleteRedundantPhi(PhiNode redundantPhi, ValueNode phiValue) {
         Collection<PhiNode> phiUsages = redundantPhi.usages().filter(PhiNode.class).snapshot();
         ((StructuredGraph) graph()).replaceFloating(redundantPhi, phiValue);
-        for (Node n : phiUsages) {
-            PhiNode phiNode = (PhiNode) n;
-            checkRedundantPhi(phiNode);
+        for (PhiNode phi : phiUsages) {
+            checkRedundantPhi(phi);
         }
     }
 
@@ -488,48 +488,11 @@
     }
 
     public StateSplit stateSplit() {
-        for (Node n : usages()) {
-            if (n instanceof StateSplit) {
-                return (StateSplit) n;
-            }
-        }
-        return null;
+        return (StateSplit) usages().filterInterface(StateSplit.class).first();
     }
 
-    public Iterable<FrameState> innerFrameStates() {
-        final Iterator<Node> iterator = usages().iterator();
-        return new Iterable<FrameState>() {
-            @Override
-            public Iterator<FrameState> iterator() {
-                return new Iterator<FrameState>() {
-                    private Node next;
-                    @Override
-                    public void remove() {
-                        throw new UnsupportedOperationException();
-                    }
-                    @Override
-                    public FrameState next() {
-                        forward();
-                        if (!hasNext()) {
-                            throw new NoSuchElementException();
-                        }
-                        FrameState res = (FrameState) next;
-                        next = null;
-                        return res;
-                    }
-                    @Override
-                    public boolean hasNext() {
-                        forward();
-                        return next != null;
-                    }
-                    private void forward() {
-                        while (!(next instanceof FrameState) && iterator.hasNext()) {
-                            next = iterator.next();
-                        }
-                    }
-                };
-            }
-        };
+    public NodeIterable<FrameState> innerFrameStates() {
+        return usages().filter(FrameState.class);
     }
 
     /**
--- a/graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/LoopBeginNode.java	Fri Jan 27 00:40:26 2012 +0100
+++ b/graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/LoopBeginNode.java	Mon Jan 30 13:06:11 2012 +0100
@@ -45,12 +45,7 @@
     }
 
     public LoopEndNode loopEnd() {
-        for (LoopEndNode end : usages().filter(LoopEndNode.class)) {
-            if (end.loopBegin() == this) {
-                return end;
-            }
-        }
-        return null;
+        return usages().filter(LoopEndNode.class).first();
     }
 
     @Override
@@ -83,11 +78,6 @@
         throw ValueUtil.shouldNotReachHere();
     }
 
-    @Override
-    public Iterable<? extends Node> phiPredecessors() {
-        return Arrays.asList(new Node[]{this.forwardEdge(), this.loopEnd()});
-    }
-
     public EndNode forwardEdge() {
         return this.endAt(0);
     }
@@ -96,7 +86,7 @@
     public boolean verify() {
         assertTrue(loopEnd() != null, "missing loopEnd");
         assertTrue(forwardEdge() != null, "missing forwardEdge");
-        assertTrue(usages().filter(LoopEndNode.class).snapshot().size() == 1, "multiple loop ends");
+        assertTrue(usages().filter(LoopEndNode.class).count() == 1, "multiple loop ends");
         return super.verify();
     }
 
--- a/graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/MergeNode.java	Fri Jan 27 00:40:26 2012 +0100
+++ b/graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/MergeNode.java	Mon Jan 30 13:06:11 2012 +0100
@@ -59,12 +59,8 @@
         return ends.get(index);
     }
 
-    public Iterable<? extends Node> phiPredecessors() {
-        return ends;
-    }
-
     @Override
-    public Iterable<EndNode> cfgPredecessors() {
+    public NodeIterable<EndNode> cfgPredecessors() {
         return ends;
     }
 
--- a/graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/java/MethodCallTargetNode.java	Fri Jan 27 00:40:26 2012 +0100
+++ b/graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/java/MethodCallTargetNode.java	Mon Jan 30 13:06:11 2012 +0100
@@ -106,10 +106,7 @@
     }
 
     public Invoke invoke() {
-        if (this.usages().size() == 0) {
-            return null;
-        }
-        return (Invoke) this.usages().iterator().next();
+        return (Invoke) this.usages().first();
     }
 
 
--- a/graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/spi/EscapeOp.java	Fri Jan 27 00:40:26 2012 +0100
+++ b/graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/spi/EscapeOp.java	Mon Jan 30 13:06:11 2012 +0100
@@ -44,7 +44,7 @@
             assert ((IsTypeNode) usage).object() == node;
             return false;
         } else if (usage instanceof FrameState) {
-            assert ((FrameState) usage).inputs().contains(node);
+            assert usage.inputs().contains(node);
             return true;
         } else if (usage instanceof AccessMonitorNode) {
             assert ((AccessMonitorNode) usage).object() == node;
--- a/graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/util/NodeIterators.java	Fri Jan 27 00:40:26 2012 +0100
+++ b/graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/util/NodeIterators.java	Mon Jan 30 13:06:11 2012 +0100
@@ -33,7 +33,7 @@
         return new NodeIterable<FixedNode>() {
             @Override
             public Iterator<FixedNode> iterator() {
-                return new NodeIterator<FixedNode>(until){
+                return new NodeIterator<FixedNode>(){
                     FixedNode p = n;
                     @Override
                     protected void forward() {
--- a/graal/com.oracle.max.graal.printer/src/com/oracle/max/graal/printer/IdealGraphPrinter.java	Fri Jan 27 00:40:26 2012 +0100
+++ b/graal/com.oracle.max.graal.printer/src/com/oracle/max/graal/printer/IdealGraphPrinter.java	Mon Jan 30 13:06:11 2012 +0100
@@ -297,7 +297,7 @@
                 Position position = inputIter.nextPosition();
                 Node input = node.getNodeClass().get(node, position);
                 if (input != null && !omittedClasses.contains(input.getClass())) {
-                    edges.add(new Edge(input.toString(Verbosity.Id), input.successors().explicitCount(), node.toString(Verbosity.Id), toIndex, node.getNodeClass().getName(position)));
+                    edges.add(new Edge(input.toString(Verbosity.Id), input.successors().count(), node.toString(Verbosity.Id), toIndex, node.getNodeClass().getName(position)));
                 }
                 toIndex++;
             }
--- a/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/BoxingEliminationTest.java	Fri Jan 27 00:40:26 2012 +0100
+++ b/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/BoxingEliminationTest.java	Mon Jan 30 13:06:11 2012 +0100
@@ -22,6 +22,8 @@
  */
 package com.oracle.max.graal.compiler.tests;
 
+import static com.oracle.max.graal.graph.iterators.NodePredicates.*;
+
 import java.util.*;
 
 import org.junit.*;
@@ -96,12 +98,8 @@
         identifyBoxingPhase.apply(graph);
         LocalNode local = graph.getNodes(LocalNode.class).iterator().next();
         ConstantNode constant = ConstantNode.forInt(0, graph);
-        for (Node n : local.usages().snapshot()) {
-            if (n instanceof FrameState) {
-                // Do not replace.
-            } else {
-                n.replaceFirstInput(local, constant);
-            }
+        for (Node n : local.usages().filter(isNotA(FrameState.class)).snapshot()) {
+            n.replaceFirstInput(local, constant);
         }
         Collection<Invoke> hints = new ArrayList<>();
         for (Invoke invoke : graph.getInvokes()) {
--- a/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/DegeneratedLoopsTest.java	Fri Jan 27 00:40:26 2012 +0100
+++ b/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/DegeneratedLoopsTest.java	Mon Jan 30 13:06:11 2012 +0100
@@ -22,9 +22,10 @@
  */
 package com.oracle.max.graal.compiler.tests;
 
-import junit.framework.AssertionFailedError;
+import static com.oracle.max.graal.graph.iterators.NodePredicates.*;
+import junit.framework.*;
 
-import org.junit.*;
+import org.junit.Test;
 
 import com.oracle.max.graal.compiler.phases.*;
 import com.oracle.max.graal.graph.*;
@@ -83,12 +84,8 @@
         print(graph);
         LocalNode local = graph.getNodes(LocalNode.class).iterator().next();
         ConstantNode constant = ConstantNode.forInt(0, graph);
-        for (Node n : local.usages().snapshot()) {
-            if (n instanceof FrameState) {
-                // Do not replace.
-            } else {
-                n.replaceFirstInput(local, constant);
-            }
+        for (Node n : local.usages().filter(isNotA(FrameState.class)).snapshot()) {
+            n.replaceFirstInput(local, constant);
         }
         for (Invoke invoke : graph.getInvokes()) {
             invoke.intrinsify(null);
--- a/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/IfCanonicalizerTest.java	Fri Jan 27 00:40:26 2012 +0100
+++ b/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/IfCanonicalizerTest.java	Mon Jan 30 13:06:11 2012 +0100
@@ -22,6 +22,8 @@
  */
 package com.oracle.max.graal.compiler.tests;
 
+import static com.oracle.max.graal.graph.iterators.NodePredicates.*;
+
 import org.junit.*;
 
 import com.oracle.max.graal.compiler.phases.*;
@@ -136,12 +138,8 @@
         StructuredGraph graph = parse(snippet);
         LocalNode local = graph.getNodes(LocalNode.class).iterator().next();
         ConstantNode constant = ConstantNode.forInt(0, graph);
-        for (Node n : local.usages().snapshot()) {
-            if (n instanceof FrameState) {
-                // Do not replace.
-            } else {
-                n.replaceFirstInput(local, constant);
-            }
+        for (Node n : local.usages().filter(isNotA(FrameState.class)).snapshot()) {
+            n.replaceFirstInput(local, constant);
         }
         print(graph);
         new CanonicalizerPhase(null, runtime(), null).apply(graph);
--- a/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/InvokeTest.java	Fri Jan 27 00:40:26 2012 +0100
+++ b/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/InvokeTest.java	Mon Jan 30 13:06:11 2012 +0100
@@ -22,6 +22,8 @@
  */
 package com.oracle.max.graal.compiler.tests;
 
+import static com.oracle.max.graal.graph.iterators.NodePredicates.*;
+
 import java.util.*;
 
 import org.junit.*;
@@ -72,12 +74,8 @@
         StructuredGraph graph = parse(snippet);
         LocalNode local = graph.getNodes(LocalNode.class).iterator().next();
         ConstantNode constant = ConstantNode.forInt(0, graph);
-        for (Node n : local.usages().snapshot()) {
-            if (n instanceof FrameState) {
-                // Do not replace.
-            } else {
-                n.replaceFirstInput(local, constant);
-            }
+        for (Node n : local.usages().filter(isNotA(FrameState.class)).snapshot()) {
+            n.replaceFirstInput(local, constant);
         }
         Collection<Invoke> hints = new ArrayList<>();
         for (Invoke invoke : graph.getInvokes()) {
--- a/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/MonitorTest.java	Fri Jan 27 00:40:26 2012 +0100
+++ b/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/MonitorTest.java	Mon Jan 30 13:06:11 2012 +0100
@@ -22,6 +22,8 @@
  */
 package com.oracle.max.graal.compiler.tests;
 
+import static com.oracle.max.graal.graph.iterators.NodePredicates.*;
+
 import java.util.*;
 
 import junit.framework.AssertionFailedError;
@@ -30,6 +32,7 @@
 
 import com.oracle.max.graal.compiler.phases.*;
 import com.oracle.max.graal.graph.*;
+import com.oracle.max.graal.graph.iterators.*;
 import com.oracle.max.graal.nodes.*;
 import com.oracle.max.graal.nodes.java.*;
 
@@ -64,10 +67,9 @@
     @Test
     public void test2() {
         StructuredGraph graph = parseAndProcess("test2Snippet");
-        Collection<MonitorExitNode> monitors = graph.getNodes(MonitorExitNode.class).snapshot();
-        Assert.assertEquals(1, monitors.size());
-        MonitorExitNode monitor = monitors.iterator().next();
-        Assert.assertEquals(monitor.stateAfter().bci, 3);
+        NodeIterable<MonitorExitNode> monitors = graph.getNodes(MonitorExitNode.class);
+        Assert.assertEquals(1, monitors.count());
+        Assert.assertEquals(monitors.first().stateAfter().bci, 3);
     }
 
     @SuppressWarnings("all")
@@ -81,14 +83,10 @@
 
     private StructuredGraph parseAndProcess(String snippet) {
         StructuredGraph graph = parse(snippet);
-        LocalNode local = graph.getNodes(LocalNode.class).iterator().next();
+        LocalNode local = graph.getNodes(LocalNode.class).first();
         ConstantNode constant = ConstantNode.forInt(0, graph);
-        for (Node n : local.usages().snapshot()) {
-            if (n instanceof FrameState) {
-                // Do not replace.
-            } else {
-                n.replaceFirstInput(local, constant);
-            }
+        for (Node n : local.usages().filter(isNotA(FrameState.class)).snapshot()) {
+            n.replaceFirstInput(local, constant);
         }
         Collection<Invoke> hints = new ArrayList<>();
         for (Invoke invoke : graph.getInvokes()) {