Search in sources :

Example 26 with LogicNode

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

the class ShortCircuitOrNodeTest method registerInvocationPlugins.

@Override
protected void registerInvocationPlugins(InvocationPlugins invocationPlugins) {
    Registration r = new Registration(invocationPlugins, ShortCircuitOrNodeTest.class);
    r.register2("shortCircuitOr", boolean.class, boolean.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode b1, ValueNode b2) {
            LogicNode x = b.add(new IntegerEqualsNode(b1, b.add(ConstantNode.forInt(1))));
            LogicNode y = b.add(new IntegerEqualsNode(b2, b.add(ConstantNode.forInt(1))));
            ShortCircuitOrNode compare = b.add(new ShortCircuitOrNode(x, false, y, false, 0.5));
            b.addPush(JavaKind.Boolean, new ConditionalNode(compare, b.add(ConstantNode.forBoolean(true)), b.add(ConstantNode.forBoolean(false))));
            return true;
        }
    });
    super.registerInvocationPlugins(invocationPlugins);
}
Also used : ConditionalNode(org.graalvm.compiler.nodes.calc.ConditionalNode) IntegerEqualsNode(org.graalvm.compiler.nodes.calc.IntegerEqualsNode) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) ShortCircuitOrNode(org.graalvm.compiler.nodes.ShortCircuitOrNode) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) ValueNode(org.graalvm.compiler.nodes.ValueNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) LogicNode(org.graalvm.compiler.nodes.LogicNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 27 with LogicNode

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

the class LoopEx method detectCounted.

public boolean detectCounted() {
    LoopBeginNode loopBegin = loopBegin();
    FixedNode next = loopBegin.next();
    while (next instanceof FixedGuardNode || next instanceof ValueAnchorNode || next instanceof FullInfopointNode) {
        next = ((FixedWithNextNode) next).next();
    }
    if (next instanceof IfNode) {
        IfNode ifNode = (IfNode) next;
        boolean negated = false;
        if (!loopBegin.isLoopExit(ifNode.falseSuccessor())) {
            if (!loopBegin.isLoopExit(ifNode.trueSuccessor())) {
                return false;
            }
            negated = true;
        }
        LogicNode ifTest = ifNode.condition();
        if (!(ifTest instanceof IntegerLessThanNode) && !(ifTest instanceof IntegerEqualsNode)) {
            if (ifTest instanceof IntegerBelowNode) {
                ifTest.getDebug().log("Ignored potential Counted loop at %s with |<|", loopBegin);
            }
            return false;
        }
        CompareNode lessThan = (CompareNode) ifTest;
        Condition condition = null;
        InductionVariable iv = null;
        ValueNode limit = null;
        if (isOutsideLoop(lessThan.getX())) {
            iv = getInductionVariables().get(lessThan.getY());
            if (iv != null) {
                condition = lessThan.condition().asCondition().mirror();
                limit = lessThan.getX();
            }
        } else if (isOutsideLoop(lessThan.getY())) {
            iv = getInductionVariables().get(lessThan.getX());
            if (iv != null) {
                condition = lessThan.condition().asCondition();
                limit = lessThan.getY();
            }
        }
        if (condition == null) {
            return false;
        }
        if (negated) {
            condition = condition.negate();
        }
        boolean oneOff = false;
        switch(condition) {
            case EQ:
                return false;
            case NE:
                {
                    if (!iv.isConstantStride() || Math.abs(iv.constantStride()) != 1) {
                        return false;
                    }
                    IntegerStamp initStamp = (IntegerStamp) iv.initNode().stamp(NodeView.DEFAULT);
                    IntegerStamp limitStamp = (IntegerStamp) limit.stamp(NodeView.DEFAULT);
                    if (iv.direction() == Direction.Up) {
                        if (initStamp.upperBound() > limitStamp.lowerBound()) {
                            return false;
                        }
                    } else if (iv.direction() == Direction.Down) {
                        if (initStamp.lowerBound() < limitStamp.upperBound()) {
                            return false;
                        }
                    } else {
                        return false;
                    }
                    break;
                }
            case LE:
                oneOff = true;
                if (iv.direction() != Direction.Up) {
                    return false;
                }
                break;
            case LT:
                if (iv.direction() != Direction.Up) {
                    return false;
                }
                break;
            case GE:
                oneOff = true;
                if (iv.direction() != Direction.Down) {
                    return false;
                }
                break;
            case GT:
                if (iv.direction() != Direction.Down) {
                    return false;
                }
                break;
            default:
                throw GraalError.shouldNotReachHere();
        }
        counted = new CountedLoopInfo(this, iv, ifNode, limit, oneOff, negated ? ifNode.falseSuccessor() : ifNode.trueSuccessor());
        return true;
    }
    return false;
}
Also used : Condition(org.graalvm.compiler.core.common.calc.Condition) IntegerEqualsNode(org.graalvm.compiler.nodes.calc.IntegerEqualsNode) IntegerBelowNode(org.graalvm.compiler.nodes.calc.IntegerBelowNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) IfNode(org.graalvm.compiler.nodes.IfNode) FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) FullInfopointNode(org.graalvm.compiler.nodes.FullInfopointNode) CompareNode(org.graalvm.compiler.nodes.calc.CompareNode) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) ValueAnchorNode(org.graalvm.compiler.nodes.extended.ValueAnchorNode) IntegerLessThanNode(org.graalvm.compiler.nodes.calc.IntegerLessThanNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) LogicNode(org.graalvm.compiler.nodes.LogicNode)

Example 28 with LogicNode

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

the class StandardGraphBuilderPlugins method registerMethodHandleImplPlugins.

private static void registerMethodHandleImplPlugins(InvocationPlugins plugins, SnippetReflectionProvider snippetReflection, BytecodeProvider bytecodeProvider) {
    Registration r = new Registration(plugins, "java.lang.invoke.MethodHandleImpl", bytecodeProvider);
    r.register2("profileBoolean", boolean.class, int[].class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode result, ValueNode counters) {
            if (result.isConstant()) {
                b.push(JavaKind.Boolean, result);
                return true;
            }
            if (counters.isConstant()) {
                ValueNode newResult = result;
                int[] ctrs = snippetReflection.asObject(int[].class, (JavaConstant) counters.asConstant());
                if (ctrs != null && ctrs.length == 2) {
                    int falseCount = ctrs[0];
                    int trueCount = ctrs[1];
                    int totalCount = trueCount + falseCount;
                    if (totalCount == 0) {
                        b.add(new DeoptimizeNode(DeoptimizationAction.InvalidateReprofile, DeoptimizationReason.TransferToInterpreter));
                    } else if (falseCount == 0 || trueCount == 0) {
                        boolean expected = falseCount == 0;
                        LogicNode condition = b.addWithInputs(IntegerEqualsNode.create(b.getConstantReflection(), b.getMetaAccess(), b.getOptions(), null, result, b.add(ConstantNode.forBoolean(!expected)), NodeView.DEFAULT));
                        b.append(new FixedGuardNode(condition, DeoptimizationReason.UnreachedCode, DeoptimizationAction.InvalidateReprofile, true));
                        newResult = b.add(ConstantNode.forBoolean(expected));
                    } else {
                    // We cannot use BranchProbabilityNode here since there's no guarantee
                    // the result of MethodHandleImpl.profileBoolean() is used as the
                    // test in an `if` statement (as required by BranchProbabilityNode).
                    }
                }
                b.addPush(JavaKind.Boolean, newResult);
                return true;
            }
            return false;
        }
    });
}
Also used : FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) ValueNode(org.graalvm.compiler.nodes.ValueNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) JavaConstant(jdk.vm.ci.meta.JavaConstant) DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 29 with LogicNode

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

the class VirtualFrameGetNode method virtualize.

@Override
public void virtualize(VirtualizerTool tool) {
    ValueNode tagAlias = tool.getAlias(frame.virtualFrameTagArray);
    ValueNode dataAlias = tool.getAlias(TruffleCompilerRuntime.getRuntime().getJavaKindForFrameSlotKind(accessTag) == JavaKind.Object ? frame.virtualFrameObjectArray : frame.virtualFramePrimitiveArray);
    if (tagAlias instanceof VirtualObjectNode && dataAlias instanceof VirtualObjectNode) {
        VirtualObjectNode tagVirtual = (VirtualObjectNode) tagAlias;
        VirtualObjectNode dataVirtual = (VirtualObjectNode) dataAlias;
        if (frameSlotIndex < tagVirtual.entryCount() && frameSlotIndex < dataVirtual.entryCount()) {
            ValueNode actualTag = tool.getEntry(tagVirtual, frameSlotIndex);
            if (!actualTag.isConstant() || actualTag.asJavaConstant().asInt() != accessTag) {
                /*
                     * We cannot constant fold the tag-check immediately, so we need to create a
                     * guard comparing the actualTag with the accessTag.
                     */
                LogicNode comparison = new IntegerEqualsNode(actualTag, getConstant(accessTag));
                tool.addNode(comparison);
                tool.addNode(new FixedGuardNode(comparison, DeoptimizationReason.RuntimeConstraint, DeoptimizationAction.InvalidateRecompile));
            }
            ValueNode dataEntry = tool.getEntry(dataVirtual, frameSlotIndex);
            if (dataEntry.getStackKind() == getStackKind()) {
                tool.replaceWith(dataEntry);
                return;
            }
        }
    }
    /*
         * We could "virtualize" to a UnsafeLoadNode here that remains a memory access. However,
         * that could prevent further escape analysis for parts of the method that actually matter.
         * So we just deoptimize.
         */
    insertDeoptimization(tool);
}
Also used : VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) IntegerEqualsNode(org.graalvm.compiler.nodes.calc.IntegerEqualsNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) LogicNode(org.graalvm.compiler.nodes.LogicNode)

Example 30 with LogicNode

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

the class VirtualFrameIsNode method virtualize.

@Override
public void virtualize(VirtualizerTool tool) {
    ValueNode tagAlias = tool.getAlias(frame.virtualFrameTagArray);
    if (tagAlias instanceof VirtualObjectNode) {
        VirtualObjectNode tagVirtual = (VirtualObjectNode) tagAlias;
        if (frameSlotIndex < tagVirtual.entryCount()) {
            ValueNode actualTag = tool.getEntry(tagVirtual, frameSlotIndex);
            if (actualTag.isConstant()) {
                tool.replaceWith(getConstant(actualTag.asJavaConstant().asInt() == accessTag ? 1 : 0));
            } else {
                LogicNode comparison = new IntegerEqualsNode(actualTag, getConstant(accessTag));
                tool.addNode(comparison);
                ConditionalNode result = new ConditionalNode(comparison, getConstant(1), getConstant(0));
                tool.addNode(result);
                tool.replaceWith(result);
            }
            return;
        }
    }
    /*
         * We could "virtualize" to a UnsafeLoadNode here that remains a memory access. But it is
         * simpler, and consistent with the get and set intrinsification, to deoptimize.
         */
    insertDeoptimization(tool);
}
Also used : VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) ConditionalNode(org.graalvm.compiler.nodes.calc.ConditionalNode) IntegerEqualsNode(org.graalvm.compiler.nodes.calc.IntegerEqualsNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) LogicNode(org.graalvm.compiler.nodes.LogicNode)

Aggregations

LogicNode (org.graalvm.compiler.nodes.LogicNode)48 ValueNode (org.graalvm.compiler.nodes.ValueNode)37 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)26 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)11 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)11 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)10 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)9 Stamp (org.graalvm.compiler.core.common.type.Stamp)9 IfNode (org.graalvm.compiler.nodes.IfNode)9 TypeReference (org.graalvm.compiler.core.common.type.TypeReference)8 LogicConstantNode (org.graalvm.compiler.nodes.LogicConstantNode)7 CompareNode (org.graalvm.compiler.nodes.calc.CompareNode)7 ConditionalNode (org.graalvm.compiler.nodes.calc.ConditionalNode)7 JavaConstant (jdk.vm.ci.meta.JavaConstant)6 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)6 FixedNode (org.graalvm.compiler.nodes.FixedNode)6 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)6 JavaKind (jdk.vm.ci.meta.JavaKind)5 ObjectStamp (org.graalvm.compiler.core.common.type.ObjectStamp)5 Node (org.graalvm.compiler.graph.Node)5