use of org.graalvm.compiler.nodes.spi.ArrayLengthProvider in project graal by oracle.
the class GraphUtil method arrayLength.
private static ValueNode arrayLength(ValueNode value, FindLengthMode mode, ConstantReflectionProvider constantReflection, EconomicMap<ValueNode, ValueNode> visitedPhiInputs) {
Objects.requireNonNull(mode);
EconomicMap<ValueNode, ValueNode> visitedPhiInputMap = visitedPhiInputs;
ValueNode current = value;
do {
/*
* PiArrayNode implements ArrayLengthProvider and ValueProxy. We want to treat it as an
* ArrayLengthProvider, therefore we check this case first.
*/
if (current instanceof ArrayLengthProvider) {
return ((ArrayLengthProvider) current).findLength(mode, constantReflection);
} else if (current instanceof ValuePhiNode) {
if (visitedPhiInputMap == null) {
visitedPhiInputMap = EconomicMap.create();
}
return phiArrayLength((ValuePhiNode) current, mode, constantReflection, visitedPhiInputMap);
} else if (current instanceof ValueProxyNode) {
ValueProxyNode proxy = (ValueProxyNode) current;
ValueNode length = arrayLength(proxy.getOriginalNode(), mode, constantReflection);
if (mode == ArrayLengthProvider.FindLengthMode.CANONICALIZE_READ && length != null && !length.isConstant()) {
length = new ValueProxyNode(length, proxy.proxyPoint());
}
return length;
} else if (current instanceof ValueProxy) {
/* Written as a loop instead of a recursive call to reduce recursion depth. */
current = ((ValueProxy) current).getOriginalNode();
} else {
return null;
}
} while (true);
}
Aggregations