31 import org.graalvm.compiler.graph.spi.CanonicalizerTool; |
31 import org.graalvm.compiler.graph.spi.CanonicalizerTool; |
32 import org.graalvm.compiler.nodeinfo.NodeInfo; |
32 import org.graalvm.compiler.nodeinfo.NodeInfo; |
33 import org.graalvm.compiler.nodes.ConstantNode; |
33 import org.graalvm.compiler.nodes.ConstantNode; |
34 import org.graalvm.compiler.nodes.FixedWithNextNode; |
34 import org.graalvm.compiler.nodes.FixedWithNextNode; |
35 import org.graalvm.compiler.nodes.ValueNode; |
35 import org.graalvm.compiler.nodes.ValueNode; |
36 import org.graalvm.compiler.nodes.ValueProxyNode; |
36 import org.graalvm.compiler.nodes.spi.ArrayLengthProvider; |
37 import org.graalvm.compiler.nodes.spi.Lowerable; |
37 import org.graalvm.compiler.nodes.spi.Lowerable; |
38 import org.graalvm.compiler.nodes.spi.LoweringTool; |
38 import org.graalvm.compiler.nodes.spi.LoweringTool; |
39 import org.graalvm.compiler.nodes.spi.ValueProxy; |
|
40 import org.graalvm.compiler.nodes.spi.Virtualizable; |
39 import org.graalvm.compiler.nodes.spi.Virtualizable; |
41 import org.graalvm.compiler.nodes.spi.VirtualizerTool; |
40 import org.graalvm.compiler.nodes.spi.VirtualizerTool; |
42 import org.graalvm.compiler.nodes.util.GraphUtil; |
41 import org.graalvm.compiler.nodes.util.GraphUtil; |
43 import org.graalvm.compiler.nodes.virtual.VirtualArrayNode; |
42 import org.graalvm.compiler.nodes.virtual.VirtualArrayNode; |
44 |
43 |
89 } |
88 } |
90 return this; |
89 return this; |
91 } |
90 } |
92 |
91 |
93 /** |
92 /** |
94 * Replicate the {@link ValueProxyNode}s from {@code originalValue} onto {@code value}. |
|
95 * |
|
96 * @param originalValue a possibly proxied value |
|
97 * @param value a value needing proxies |
|
98 * @return proxies wrapping {@code value} |
|
99 */ |
|
100 private static ValueNode reproxyValue(ValueNode originalValue, ValueNode value) { |
|
101 if (value.isConstant()) { |
|
102 // No proxy needed |
|
103 return value; |
|
104 } |
|
105 if (originalValue instanceof ValueProxyNode) { |
|
106 ValueProxyNode proxy = (ValueProxyNode) originalValue; |
|
107 return new ValueProxyNode(reproxyValue(proxy.getOriginalNode(), value), proxy.proxyPoint()); |
|
108 } else if (originalValue instanceof ValueProxy) { |
|
109 ValueProxy proxy = (ValueProxy) originalValue; |
|
110 return reproxyValue(proxy.getOriginalNode(), value); |
|
111 } else { |
|
112 return value; |
|
113 } |
|
114 } |
|
115 |
|
116 /** |
|
117 * Gets the length of an array if possible. |
93 * Gets the length of an array if possible. |
118 * |
94 * |
119 * @return a node representing the length of {@code array} or null if it is not available |
95 * @return a node representing the length of {@code array} or null if it is not available |
120 */ |
96 */ |
121 public static ValueNode readArrayLength(ValueNode originalArray, ConstantReflectionProvider constantReflection) { |
97 public static ValueNode readArrayLength(ValueNode originalArray, ConstantReflectionProvider constantReflection) { |
122 ValueNode length = GraphUtil.arrayLength(originalArray); |
98 ValueNode length = GraphUtil.arrayLength(originalArray, ArrayLengthProvider.FindLengthMode.CANONICALIZE_READ); |
123 if (length != null) { |
99 if (length != null) { |
124 // Ensure that any proxies on the original value end up on the length value |
100 return length; |
125 return reproxyValue(originalArray, length); |
|
126 } |
101 } |
127 return readArrayLengthConstant(originalArray, constantReflection); |
102 return readArrayLengthConstant(originalArray, constantReflection); |
128 } |
103 } |
129 |
104 |
130 private static ValueNode readArrayLengthConstant(ValueNode originalArray, ConstantReflectionProvider constantReflection) { |
105 private static ValueNode readArrayLengthConstant(ValueNode originalArray, ConstantReflectionProvider constantReflection) { |