# HG changeset patch # User Gilles Duboscq # Date 1337760579 -7200 # Node ID 1d63466ba795776d08e318a9b03f73f190cfe081 # Parent 86478955e54cca50f3c3e77451ccf55a9da6e06d Add distinct filter diff -r 86478955e54c -r 1d63466ba795 graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/FloatingReadPhase.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/FloatingReadPhase.java Tue May 22 14:34:18 2012 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/FloatingReadPhase.java Wed May 23 10:09:39 2012 +0200 @@ -158,7 +158,7 @@ if (anchor == null) { anchor = graph.add(new ValueAnchorNode()); } - anchor.addAnchoredValue(guard); + anchor.addAnchoredNode(guard); } if (anchor != null) { graph.addAfterFixed(readNode, anchor); diff -r 86478955e54c -r 1d63466ba795 graal/com.oracle.graal.graph/src/com/oracle/graal/graph/iterators/DistinctPredicatedProxyNodeIterator.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/iterators/DistinctPredicatedProxyNodeIterator.java Wed May 23 10:09:39 2012 +0200 @@ -0,0 +1,59 @@ +/* + * 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.graal.graph.iterators; + +import java.util.*; + +import com.oracle.graal.graph.*; + + +public class DistinctPredicatedProxyNodeIterator extends PredicatedProxyNodeIterator { + private NodeBitMap visited; + + public DistinctPredicatedProxyNodeIterator(NodePredicate until, Iterator iterator, NodePredicate predicate) { + super(until, iterator, predicate); + } + + @Override + protected void forward() { + if (current == null) { + super.forward(); + while (!accept(current)) { + current = null; + super.forward(); + } + } + } + + private boolean accept(T n) { + if (n == null) { + return true; + } + if (visited == null) { + visited = n.graph().createNodeBitMap(true); + } + boolean accept = !visited.isMarked(n); + visited.mark(n); + return accept; + } +} diff -r 86478955e54c -r 1d63466ba795 graal/com.oracle.graal.graph/src/com/oracle/graal/graph/iterators/FilteredNodeIterable.java --- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/iterators/FilteredNodeIterable.java Tue May 22 14:34:18 2012 +0200 +++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/iterators/FilteredNodeIterable.java Wed May 23 10:09:39 2012 +0200 @@ -30,6 +30,7 @@ private final NodeIterable nodeIterable; private NodePredicate predicate = NodePredicates.alwaysTrue(); private NodePredicate until = NodePredicates.isNull(); + private boolean distinct; public FilteredNodeIterable(NodeIterable nodeIterable) { this.nodeIterable = nodeIterable; } @@ -52,9 +53,23 @@ return this; } @Override + public FilteredNodeIterable nonNull() { + this.predicate = this.predicate.or(NodePredicates.isNotNull()); + return this; + } + @Override + public FilteredNodeIterable distinct() { + distinct = true; + return this; + } + @Override public Iterator iterator() { final Iterator iterator = nodeIterable.iterator(); - return new PredicatedProxyNodeIterator<>(until, iterator, predicate); + if (distinct) { + return new DistinctPredicatedProxyNodeIterator<>(until, iterator, predicate); + } else { + return new PredicatedProxyNodeIterator<>(until, iterator, predicate); + } } @SuppressWarnings("unchecked") diff -r 86478955e54c -r 1d63466ba795 graal/com.oracle.graal.graph/src/com/oracle/graal/graph/iterators/NodeIterable.java --- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/iterators/NodeIterable.java Tue May 22 14:34:18 2012 +0200 +++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/iterators/NodeIterable.java Wed May 23 10:09:39 2012 +0200 @@ -46,6 +46,9 @@ public FilteredNodeIterable nonNull() { return new FilteredNodeIterable<>(this).and(NodePredicates.isNotNull()); } + public FilteredNodeIterable distinct() { + return new FilteredNodeIterable<>(this).distinct(); + } public List snapshot() { ArrayList list = new ArrayList<>(); for (T n : this) { diff -r 86478955e54c -r 1d63466ba795 graal/com.oracle.graal.graph/src/com/oracle/graal/graph/iterators/PredicatedProxyNodeIterator.java --- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/iterators/PredicatedProxyNodeIterator.java Tue May 22 14:34:18 2012 +0200 +++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/iterators/PredicatedProxyNodeIterator.java Wed May 23 10:09:39 2012 +0200 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 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 @@ -26,7 +26,7 @@ import com.oracle.graal.graph.*; -public final class PredicatedProxyNodeIterator extends NodeIterator { +public class PredicatedProxyNodeIterator extends NodeIterator { private final Iterator iterator; private final NodePredicate predicate; private final NodePredicate until; diff -r 86478955e54c -r 1d63466ba795 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ValueAnchorNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ValueAnchorNode.java Tue May 22 14:34:18 2012 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ValueAnchorNode.java Wed May 23 10:09:39 2012 +0200 @@ -44,8 +44,10 @@ // Nothing to emit, since this node is used for structural purposes only. } - public void addAnchoredValue(ValueNode value) { - this.dependencies().add(value); + public void addAnchoredNode(Node value) { + if (!this.dependencies().contains(value)) { + this.dependencies().add(value); + } } @Override @@ -53,8 +55,8 @@ if (this.predecessor() instanceof ValueAnchorNode) { // transfer values and remove ValueAnchorNode previousAnchor = (ValueAnchorNode) this.predecessor(); - for (Node node : dependencies().nonNull()) { - previousAnchor.dependencies().add(node); + for (Node node : dependencies().nonNull().distinct()) { + previousAnchor.addAnchoredNode(node); } return null; }