Search in sources :

Example 1 with UnboxNode

use of org.graalvm.compiler.nodes.extended.UnboxNode in project graal by oracle.

the class PEReadEliminationClosure method processNode.

@Override
protected boolean processNode(Node node, PEReadEliminationBlockState state, GraphEffectList effects, FixedWithNextNode lastFixedNode) {
    if (super.processNode(node, state, effects, lastFixedNode)) {
        return true;
    }
    if (node instanceof LoadFieldNode) {
        return processLoadField((LoadFieldNode) node, state, effects);
    } else if (node instanceof StoreFieldNode) {
        return processStoreField((StoreFieldNode) node, state, effects);
    } else if (node instanceof LoadIndexedNode) {
        return processLoadIndexed((LoadIndexedNode) node, state, effects);
    } else if (node instanceof StoreIndexedNode) {
        return processStoreIndexed((StoreIndexedNode) node, state, effects);
    } else if (node instanceof ArrayLengthNode) {
        return processArrayLength((ArrayLengthNode) node, state, effects);
    } else if (node instanceof UnboxNode) {
        return processUnbox((UnboxNode) node, state, effects);
    } else if (node instanceof RawLoadNode) {
        return processUnsafeLoad((RawLoadNode) node, state, effects);
    } else if (node instanceof RawStoreNode) {
        return processUnsafeStore((RawStoreNode) node, state, effects);
    } else if (node instanceof MemoryCheckpoint.Single) {
        COUNTER_MEMORYCHECKPOINT.increment(node.getDebug());
        LocationIdentity identity = ((MemoryCheckpoint.Single) node).getLocationIdentity();
        processIdentity(state, identity);
    } else if (node instanceof MemoryCheckpoint.Multi) {
        COUNTER_MEMORYCHECKPOINT.increment(node.getDebug());
        for (LocationIdentity identity : ((MemoryCheckpoint.Multi) node).getLocationIdentities()) {
            processIdentity(state, identity);
        }
    }
    return false;
}
Also used : RawStoreNode(org.graalvm.compiler.nodes.extended.RawStoreNode) StoreIndexedNode(org.graalvm.compiler.nodes.java.StoreIndexedNode) UnboxNode(org.graalvm.compiler.nodes.extended.UnboxNode) StoreFieldNode(org.graalvm.compiler.nodes.java.StoreFieldNode) MemoryCheckpoint(org.graalvm.compiler.nodes.memory.MemoryCheckpoint) LoadIndexedNode(org.graalvm.compiler.nodes.java.LoadIndexedNode) LocationIdentity(org.graalvm.word.LocationIdentity) FieldLocationIdentity(org.graalvm.compiler.nodes.FieldLocationIdentity) NamedLocationIdentity(org.graalvm.compiler.nodes.NamedLocationIdentity) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode) ArrayLengthNode(org.graalvm.compiler.nodes.java.ArrayLengthNode) RawLoadNode(org.graalvm.compiler.nodes.extended.RawLoadNode)

Example 2 with UnboxNode

use of org.graalvm.compiler.nodes.extended.UnboxNode in project graal by oracle.

the class IfNode method tryEliminateBoxedReferenceEquals.

/**
 * Attempts to replace the following pattern:
 *
 * <pre>
 * Integer x = ...;
 * Integer y = ...;
 * if ((x == y) || x.equals(y)) { ... }
 * </pre>
 *
 * with:
 *
 * <pre>
 * Integer x = ...;
 * Integer y = ...;
 * if (x.equals(y)) { ... }
 * </pre>
 *
 * whenever the probability that the reference check will pass is relatively small.
 *
 * See GR-1315 for more information.
 */
private boolean tryEliminateBoxedReferenceEquals(SimplifierTool tool) {
    if (!(condition instanceof ObjectEqualsNode)) {
        return false;
    }
    MetaAccessProvider meta = tool.getMetaAccess();
    ObjectEqualsNode equalsCondition = (ObjectEqualsNode) condition;
    ValueNode x = equalsCondition.getX();
    ValueNode y = equalsCondition.getY();
    ResolvedJavaType integerType = meta.lookupJavaType(Integer.class);
    // At least one argument for reference equal must be a boxed primitive.
    NodeView view = NodeView.from(tool);
    if (!x.stamp(view).javaType(meta).equals(integerType) && !y.stamp(view).javaType(meta).equals(integerType)) {
        return false;
    }
    // no sense to eliminate it.
    if (getTrueSuccessorProbability() > 0.4) {
        return false;
    }
    // True branch must be empty.
    if (trueSuccessor instanceof BeginNode || trueSuccessor instanceof LoopExitNode) {
        if (trueSuccessor.next() instanceof EndNode) {
        // Empty true branch.
        } else {
            return false;
        }
    } else {
        return false;
    }
    // False branch must only check the unboxed values.
    UnboxNode unbox = null;
    FixedGuardNode unboxCheck = null;
    for (FixedNode node : falseSuccessor.getBlockNodes()) {
        if (!(node instanceof BeginNode || node instanceof UnboxNode || node instanceof FixedGuardNode || node instanceof EndNode || node instanceof LoadFieldNode || node instanceof LoopExitNode)) {
            return false;
        }
        if (node instanceof UnboxNode) {
            if (unbox == null) {
                unbox = (UnboxNode) node;
            } else {
                return false;
            }
        }
        if (!(node instanceof FixedGuardNode)) {
            continue;
        }
        FixedGuardNode fixed = (FixedGuardNode) node;
        if (!(fixed.condition() instanceof IntegerEqualsNode)) {
            continue;
        }
        IntegerEqualsNode equals = (IntegerEqualsNode) fixed.condition();
        if ((isUnboxedFrom(meta, view, equals.getX(), x) && isUnboxedFrom(meta, view, equals.getY(), y)) || (isUnboxedFrom(meta, view, equals.getX(), y) && isUnboxedFrom(meta, view, equals.getY(), x))) {
            unboxCheck = fixed;
        }
    }
    if (unbox == null || unboxCheck == null) {
        return false;
    }
    // Falsify the reference check.
    setCondition(graph().addOrUniqueWithInputs(LogicConstantNode.contradiction()));
    return true;
}
Also used : IntegerEqualsNode(org.graalvm.compiler.nodes.calc.IntegerEqualsNode) ObjectEqualsNode(org.graalvm.compiler.nodes.calc.ObjectEqualsNode) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) UnboxNode(org.graalvm.compiler.nodes.extended.UnboxNode) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider)

Aggregations

UnboxNode (org.graalvm.compiler.nodes.extended.UnboxNode)2 LoadFieldNode (org.graalvm.compiler.nodes.java.LoadFieldNode)2 MetaAccessProvider (jdk.vm.ci.meta.MetaAccessProvider)1 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)1 FieldLocationIdentity (org.graalvm.compiler.nodes.FieldLocationIdentity)1 NamedLocationIdentity (org.graalvm.compiler.nodes.NamedLocationIdentity)1 IntegerEqualsNode (org.graalvm.compiler.nodes.calc.IntegerEqualsNode)1 ObjectEqualsNode (org.graalvm.compiler.nodes.calc.ObjectEqualsNode)1 RawLoadNode (org.graalvm.compiler.nodes.extended.RawLoadNode)1 RawStoreNode (org.graalvm.compiler.nodes.extended.RawStoreNode)1 ArrayLengthNode (org.graalvm.compiler.nodes.java.ArrayLengthNode)1 LoadIndexedNode (org.graalvm.compiler.nodes.java.LoadIndexedNode)1 StoreFieldNode (org.graalvm.compiler.nodes.java.StoreFieldNode)1 StoreIndexedNode (org.graalvm.compiler.nodes.java.StoreIndexedNode)1 MemoryCheckpoint (org.graalvm.compiler.nodes.memory.MemoryCheckpoint)1 LocationIdentity (org.graalvm.word.LocationIdentity)1