Search in sources :

Example 1 with ArrayLengthProvider

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);
}
Also used : LimitedValueProxy(org.graalvm.compiler.nodes.spi.LimitedValueProxy) ValueProxy(org.graalvm.compiler.nodes.spi.ValueProxy) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) ValueProxyNode(org.graalvm.compiler.nodes.ValueProxyNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) ArrayLengthProvider(org.graalvm.compiler.nodes.spi.ArrayLengthProvider)

Aggregations

ValueNode (org.graalvm.compiler.nodes.ValueNode)1 ValuePhiNode (org.graalvm.compiler.nodes.ValuePhiNode)1 ValueProxyNode (org.graalvm.compiler.nodes.ValueProxyNode)1 ArrayLengthProvider (org.graalvm.compiler.nodes.spi.ArrayLengthProvider)1 LimitedValueProxy (org.graalvm.compiler.nodes.spi.LimitedValueProxy)1 ValueProxy (org.graalvm.compiler.nodes.spi.ValueProxy)1