Search in sources :

Example 6 with IsNullNode

use of org.graalvm.compiler.nodes.calc.IsNullNode in project graal by oracle.

the class UseTrappingNullChecksPhase method checkPredecessor.

private static void checkPredecessor(AbstractDeoptimizeNode deopt, Node predecessor, DeoptimizationReason deoptimizationReason, long implicitNullCheckLimit) {
    Node current = predecessor;
    AbstractBeginNode branch = null;
    while (current instanceof AbstractBeginNode) {
        branch = (AbstractBeginNode) current;
        if (branch.anchored().isNotEmpty()) {
            // some input of the deopt framestate is anchored to this branch
            return;
        }
        current = current.predecessor();
    }
    if (current instanceof IfNode) {
        IfNode ifNode = (IfNode) current;
        if (branch != ifNode.trueSuccessor()) {
            return;
        }
        LogicNode condition = ifNode.condition();
        if (condition instanceof IsNullNode) {
            replaceWithTrappingNullCheck(deopt, ifNode, condition, deoptimizationReason, implicitNullCheckLimit);
        }
    }
}
Also used : IsNullNode(org.graalvm.compiler.nodes.calc.IsNullNode) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) DynamicDeoptimizeNode(org.graalvm.compiler.nodes.DynamicDeoptimizeNode) FixedAccessNode(org.graalvm.compiler.nodes.memory.FixedAccessNode) DeoptimizingFixedWithNextNode(org.graalvm.compiler.nodes.DeoptimizingFixedWithNextNode) BeginNode(org.graalvm.compiler.nodes.BeginNode) DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) IfNode(org.graalvm.compiler.nodes.IfNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) CompressionNode(org.graalvm.compiler.nodes.CompressionNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) AbstractDeoptimizeNode(org.graalvm.compiler.nodes.AbstractDeoptimizeNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) IsNullNode(org.graalvm.compiler.nodes.calc.IsNullNode) NullCheckNode(org.graalvm.compiler.nodes.extended.NullCheckNode) Node(org.graalvm.compiler.graph.Node) LogicNode(org.graalvm.compiler.nodes.LogicNode) IfNode(org.graalvm.compiler.nodes.IfNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode)

Example 7 with IsNullNode

use of org.graalvm.compiler.nodes.calc.IsNullNode in project graal by oracle.

the class UseTrappingNullChecksPhase method replaceWithTrappingNullCheck.

private static void replaceWithTrappingNullCheck(AbstractDeoptimizeNode deopt, IfNode ifNode, LogicNode condition, DeoptimizationReason deoptimizationReason, long implicitNullCheckLimit) {
    DebugContext debug = deopt.getDebug();
    counterTrappingNullCheck.increment(debug);
    if (deopt instanceof DynamicDeoptimizeNode) {
        counterTrappingNullCheckDynamicDeoptimize.increment(debug);
    }
    if (deoptimizationReason == DeoptimizationReason.UnreachedCode) {
        counterTrappingNullCheckUnreached.increment(debug);
    }
    IsNullNode isNullNode = (IsNullNode) condition;
    AbstractBeginNode nonTrappingContinuation = ifNode.falseSuccessor();
    AbstractBeginNode trappingContinuation = ifNode.trueSuccessor();
    DeoptimizingFixedWithNextNode trappingNullCheck = null;
    FixedNode nextNonTrapping = nonTrappingContinuation.next();
    ValueNode value = isNullNode.getValue();
    if (OptImplicitNullChecks.getValue(ifNode.graph().getOptions()) && implicitNullCheckLimit > 0) {
        if (nextNonTrapping instanceof FixedAccessNode) {
            FixedAccessNode fixedAccessNode = (FixedAccessNode) nextNonTrapping;
            if (fixedAccessNode.canNullCheck()) {
                AddressNode address = fixedAccessNode.getAddress();
                ValueNode base = address.getBase();
                ValueNode index = address.getIndex();
                // intervening uncompress out of the address chain
                if (base != null && base instanceof CompressionNode) {
                    base = ((CompressionNode) base).getValue();
                }
                if (index != null && index instanceof CompressionNode) {
                    index = ((CompressionNode) index).getValue();
                }
                if (((base == value && index == null) || (base == null && index == value)) && address.getMaxConstantDisplacement() < implicitNullCheckLimit) {
                    // Opportunity for implicit null check as part of an existing read found!
                    fixedAccessNode.setStateBefore(deopt.stateBefore());
                    fixedAccessNode.setNullCheck(true);
                    deopt.graph().removeSplit(ifNode, nonTrappingContinuation);
                    trappingNullCheck = fixedAccessNode;
                    counterTrappingNullCheckExistingRead.increment(debug);
                }
            }
        }
    }
    if (trappingNullCheck == null) {
        // Need to add a null check node.
        trappingNullCheck = deopt.graph().add(new NullCheckNode(value));
        deopt.graph().replaceSplit(ifNode, trappingNullCheck, nonTrappingContinuation);
    }
    trappingNullCheck.setStateBefore(deopt.stateBefore());
    /*
         * We now have the pattern NullCheck/BeginNode/... It's possible some node is using the
         * BeginNode as a guard input, so replace guard users of the Begin with the NullCheck and
         * then remove the Begin from the graph.
         */
    nonTrappingContinuation.replaceAtUsages(InputType.Guard, trappingNullCheck);
    if (nonTrappingContinuation instanceof BeginNode) {
        GraphUtil.unlinkFixedNode(nonTrappingContinuation);
        nonTrappingContinuation.safeDelete();
    }
    GraphUtil.killCFG(trappingContinuation);
    GraphUtil.tryKillUnused(isNullNode);
}
Also used : FixedAccessNode(org.graalvm.compiler.nodes.memory.FixedAccessNode) DeoptimizingFixedWithNextNode(org.graalvm.compiler.nodes.DeoptimizingFixedWithNextNode) CompressionNode(org.graalvm.compiler.nodes.CompressionNode) IsNullNode(org.graalvm.compiler.nodes.calc.IsNullNode) NullCheckNode(org.graalvm.compiler.nodes.extended.NullCheckNode) BeginNode(org.graalvm.compiler.nodes.BeginNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) DynamicDeoptimizeNode(org.graalvm.compiler.nodes.DynamicDeoptimizeNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) DebugContext(org.graalvm.compiler.debug.DebugContext) FixedNode(org.graalvm.compiler.nodes.FixedNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode)

Aggregations

IsNullNode (org.graalvm.compiler.nodes.calc.IsNullNode)7 ValueNode (org.graalvm.compiler.nodes.ValueNode)5 DebugContext (org.graalvm.compiler.debug.DebugContext)4 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)4 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)3 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)3 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)3 HostedProviders (com.oracle.graal.pointsto.meta.HostedProviders)2 UserError (com.oracle.svm.core.util.UserError)2 NativeLibraries (com.oracle.svm.hosted.c.NativeLibraries)2 ElementInfo (com.oracle.svm.hosted.c.info.ElementInfo)2 EnumInfo (com.oracle.svm.hosted.c.info.EnumInfo)2 EnumValueInfo (com.oracle.svm.hosted.c.info.EnumValueInfo)2 CInterfaceEnumTool (com.oracle.svm.hosted.phases.CInterfaceEnumTool)2 HostedGraphKit (com.oracle.svm.hosted.phases.HostedGraphKit)2 Arrays (java.util.Arrays)2 Iterator (java.util.Iterator)2 JavaKind (jdk.vm.ci.meta.JavaKind)2 JavaType (jdk.vm.ci.meta.JavaType)2 MetaAccessProvider (jdk.vm.ci.meta.MetaAccessProvider)2