# HG changeset patch # User Lukas Stadler # Date 1373899151 -7200 # Node ID c483912aaf70f8d39d224507b79da1f6f0411428 # Parent 9f5a4074e36b282a98c16a1d5962f86f0da173dd add ValueProxy interface and infrastructure diff -r 9f5a4074e36b -r c483912aaf70 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/GuardedValueNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/GuardedValueNode.java Mon Jul 15 13:36:59 2013 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/GuardedValueNode.java Mon Jul 15 16:39:11 2013 +0200 @@ -34,7 +34,7 @@ * * A GuardedValueNode will only go away if its guard is null or {@link StructuredGraph#start()}. */ -public class GuardedValueNode extends FloatingGuardedNode implements LIRLowerable, Virtualizable, Node.IterableNodeType, GuardingNode, Canonicalizable { +public class GuardedValueNode extends FloatingGuardedNode implements LIRLowerable, Virtualizable, Node.IterableNodeType, GuardingNode, Canonicalizable, ValueProxy { @Input private ValueNode object; @@ -81,4 +81,9 @@ } return this; } + + @Override + public ValueNode getOriginalValue() { + return object; + } } diff -r 9f5a4074e36b -r c483912aaf70 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/GuardingPiNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/GuardingPiNode.java Mon Jul 15 13:36:59 2013 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/GuardingPiNode.java Mon Jul 15 16:39:11 2013 +0200 @@ -34,7 +34,7 @@ * A node that changes the stamp of its input based on some condition being true. */ @NodeInfo(nameTemplate = "GuardingPi(!={p#negated}) {p#reason/s}") -public class GuardingPiNode extends FixedWithNextNode implements Lowerable, GuardingNode, Canonicalizable { +public class GuardingPiNode extends FixedWithNextNode implements Lowerable, GuardingNode, Canonicalizable, ValueProxy { @Input private ValueNode object; @Input private LogicNode condition; @@ -109,4 +109,9 @@ public ValueNode asNode() { return this; } + + @Override + public ValueNode getOriginalValue() { + return object; + } } diff -r 9f5a4074e36b -r c483912aaf70 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/PiNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/PiNode.java Mon Jul 15 13:36:59 2013 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/PiNode.java Mon Jul 15 16:39:11 2013 +0200 @@ -36,7 +36,7 @@ * is as narrow or narrower than the PiNode's type. The PiNode, and therefore also the scheduling * restriction enforced by the anchor, will go away. */ -public class PiNode extends FloatingGuardedNode implements LIRLowerable, Virtualizable, Node.IterableNodeType, GuardingNode, Canonicalizable { +public class PiNode extends FloatingGuardedNode implements LIRLowerable, Virtualizable, Node.IterableNodeType, GuardingNode, Canonicalizable, ValueProxy { @Input private ValueNode object; @@ -82,4 +82,9 @@ } return this; } + + @Override + public ValueNode getOriginalValue() { + return object; + } } diff -r 9f5a4074e36b -r c483912aaf70 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/ProxyNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/ProxyNode.java Mon Jul 15 13:36:59 2013 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/ProxyNode.java Mon Jul 15 16:39:11 2013 +0200 @@ -35,7 +35,7 @@ * loop. */ @NodeInfo(nameTemplate = "{p#type/s}Proxy") -public class ProxyNode extends FloatingNode implements Node.IterableNodeType, ValueNumberable, Canonicalizable, Virtualizable, LIRLowerable { +public class ProxyNode extends FloatingNode implements Node.IterableNodeType, ValueNumberable, Canonicalizable, Virtualizable, LIRLowerable, ValueProxy { @Input(notDataflow = true) private AbstractBeginNode proxyPoint; @Input private ValueNode value; @@ -116,4 +116,8 @@ return graph.unique(new ProxyNode(value, exit, PhiType.Memory, location)); } + @Override + public ValueNode getOriginalValue() { + return value; + } } diff -r 9f5a4074e36b -r c483912aaf70 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/TypeProfileProxyNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/TypeProfileProxyNode.java Mon Jul 15 13:36:59 2013 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/TypeProfileProxyNode.java Mon Jul 15 16:39:11 2013 +0200 @@ -32,7 +32,7 @@ /** * A node that attaches a type profile to a proxied input node. */ -public final class TypeProfileProxyNode extends FloatingNode implements Canonicalizable, Node.IterableNodeType { +public final class TypeProfileProxyNode extends FloatingNode implements Canonicalizable, Node.IterableNodeType, ValueProxy { @Input private ValueNode object; private final JavaTypeProfile profile; @@ -130,4 +130,9 @@ } assert graph.getNodes(TypeProfileProxyNode.class).count() == 0; } + + @Override + public ValueNode getOriginalValue() { + return object; + } } diff -r 9f5a4074e36b -r c483912aaf70 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/CheckCastNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/CheckCastNode.java Mon Jul 15 13:36:59 2013 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/CheckCastNode.java Mon Jul 15 16:39:11 2013 +0200 @@ -37,7 +37,7 @@ /** * Implements a type check against a compile-time known type. */ -public final class CheckCastNode extends FixedWithNextNode implements Canonicalizable, Lowerable, Node.IterableNodeType, Virtualizable { +public final class CheckCastNode extends FixedWithNextNode implements Canonicalizable, Lowerable, Node.IterableNodeType, Virtualizable, ValueProxy { @Input private ValueNode object; private final ResolvedJavaType type; @@ -193,4 +193,9 @@ } } } + + @Override + public ValueNode getOriginalValue() { + return object; + } } diff -r 9f5a4074e36b -r c483912aaf70 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/spi/ValueProxy.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/spi/ValueProxy.java Mon Jul 15 16:39:11 2013 +0200 @@ -0,0 +1,31 @@ +/* + * 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.nodes.spi; + +import com.oracle.graal.nodes.*; + +public interface ValueProxy { + + ValueNode getOriginalValue(); + +} diff -r 9f5a4074e36b -r c483912aaf70 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/util/GraphUtil.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/util/GraphUtil.java Mon Jul 15 13:36:59 2013 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/util/GraphUtil.java Mon Jul 15 16:39:11 2013 +0200 @@ -30,6 +30,7 @@ import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.calc.*; import com.oracle.graal.nodes.java.*; +import com.oracle.graal.nodes.spi.*; public class GraphUtil { @@ -257,14 +258,6 @@ return null; } - public static ValueNode unProxify(ValueNode proxy) { - ValueNode v = proxy; - while (v instanceof ProxyNode) { - v = ((ProxyNode) v).value(); - } - return v; - } - /** * Returns a string representation of the given collection of objects. * @@ -285,16 +278,31 @@ } /** + * Gets the original value by iterating through all {@link ValueProxy ValueProxies}. + * + * @param value The start value. + * @return The first non-proxy value encountered. + */ + public static ValueNode unproxify(ValueNode value) { + ValueNode result = value; + while (result instanceof ValueProxy) { + result = ((ValueProxy) result).getOriginalValue(); + } + return result; + } + + /** * Tries to find an original value of the given node by traversing through proxies and - * unambiguous phis. + * unambiguous phis. Note that this method will perform an exhaustive search through phis. It is + * intended to be used during graph building, when phi nodes aren't yet canonicalized. * * @param proxy The node whose original value should be determined. */ public static ValueNode originalValue(ValueNode proxy) { ValueNode v = proxy; do { - if (v instanceof ProxyNode) { - v = ((ProxyNode) v).value(); + if (v instanceof ValueProxy) { + v = ((ValueProxy) v).getOriginalValue(); } else if (v instanceof PhiNode) { v = ((PhiNode) v).singleValue(); } else { @@ -308,8 +316,8 @@ NodeWorkList worklist = proxy.graph().createNodeWorkList(); worklist.add(proxy); for (Node node : worklist) { - if (node instanceof ProxyNode) { - worklist.add(((ProxyNode) node).value()); + if (node instanceof ValueProxy) { + worklist.add(((ValueProxy) node).getOriginalValue()); } else if (node instanceof PhiNode) { worklist.addAll(((PhiNode) node).values()); } else {