Search in sources :

Example 1 with ConditionalNode

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

the class StandardGraphBuilderPlugins method registerClassPlugins.

private static void registerClassPlugins(InvocationPlugins plugins) {
    Registration r = new Registration(plugins, Class.class);
    r.register2("isInstance", Receiver.class, Object.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver type, ValueNode object) {
            LogicNode condition = b.append(InstanceOfDynamicNode.create(b.getAssumptions(), b.getConstantReflection(), type.get(), object, false));
            b.push(JavaKind.Boolean, b.append(new ConditionalNode(condition).canonical(null)));
            return true;
        }
    });
    r.register2("isAssignableFrom", Receiver.class, Class.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver type, ValueNode otherType) {
            ClassIsAssignableFromNode condition = b.append(new ClassIsAssignableFromNode(type.get(), otherType));
            b.push(JavaKind.Boolean, b.append(new ConditionalNode(condition).canonical(null)));
            return true;
        }
    });
}
Also used : ClassIsAssignableFromNode(org.graalvm.compiler.nodes.java.ClassIsAssignableFromNode) ConditionalNode(org.graalvm.compiler.nodes.calc.ConditionalNode) 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) LogicNode(org.graalvm.compiler.nodes.LogicNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 2 with ConditionalNode

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

the class CountedLoopInfo method maxTripCountNode.

/**
 * Returns a node that computes the maximum trip count of this loop. That is the trip count of
 * this loop assuming it is not exited by an other exit than the {@linkplain #getLimitTest()
 * count check}.
 *
 * This count is exact if {@link #isExactTripCount()} returns true.
 *
 * THIS VALUE SHOULD BE TREATED AS UNSIGNED.
 *
 * @param assumePositive if true the check that the loop is entered at all will be omitted.
 */
public ValueNode maxTripCountNode(boolean assumePositive) {
    StructuredGraph graph = iv.valueNode().graph();
    Stamp stamp = iv.valueNode().stamp(NodeView.DEFAULT);
    ValueNode max;
    ValueNode min;
    ValueNode range;
    ValueNode absStride;
    if (iv.direction() == Direction.Up) {
        absStride = iv.strideNode();
        range = sub(graph, end, iv.initNode());
        max = end;
        min = iv.initNode();
    } else {
        assert iv.direction() == Direction.Down;
        absStride = graph.maybeAddOrUnique(NegateNode.create(iv.strideNode(), NodeView.DEFAULT));
        range = sub(graph, iv.initNode(), end);
        max = iv.initNode();
        min = end;
    }
    ConstantNode one = ConstantNode.forIntegerStamp(stamp, 1, graph);
    if (oneOff) {
        range = add(graph, range, one);
    }
    // round-away-from-zero divison: (range + stride -/+ 1) / stride
    ValueNode denominator = add(graph, range, sub(graph, absStride, one));
    ValueNode div = unsignedDivBefore(graph, loop.entryPoint(), denominator, absStride);
    if (assumePositive) {
        return div;
    }
    ConstantNode zero = ConstantNode.forIntegerStamp(stamp, 0, graph);
    return graph.unique(new ConditionalNode(graph.unique(new IntegerLessThanNode(max, min)), zero, div));
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) ConditionalNode(org.graalvm.compiler.nodes.calc.ConditionalNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) Stamp(org.graalvm.compiler.core.common.type.Stamp) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) ValueNode(org.graalvm.compiler.nodes.ValueNode) IntegerLessThanNode(org.graalvm.compiler.nodes.calc.IntegerLessThanNode)

Example 3 with ConditionalNode

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

the class CompareCanonicalizerTest method testIntegerTest.

@Test
public void testIntegerTest() {
    for (int i = 1; i <= 4; i++) {
        StructuredGraph graph = getCanonicalizedGraph("integerTest" + i);
        ReturnNode returnNode = (ReturnNode) graph.start().next();
        ConditionalNode conditional = (ConditionalNode) returnNode.result();
        IntegerTestNode test = (IntegerTestNode) conditional.condition();
        ParameterNode param0 = graph.getParameter(0);
        ParameterNode param1 = graph.getParameter(1);
        assertTrue((test.getX() == param0 && test.getY() == param1) || (test.getX() == param1 && test.getY() == param0));
    }
}
Also used : ReturnNode(org.graalvm.compiler.nodes.ReturnNode) ConditionalNode(org.graalvm.compiler.nodes.calc.ConditionalNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) IntegerTestNode(org.graalvm.compiler.nodes.calc.IntegerTestNode) Test(org.junit.Test)

Example 4 with ConditionalNode

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

the class WordOperationPlugin method comparisonOp.

private ValueNode comparisonOp(GraphBuilderContext graph, Condition condition, ValueNode left, ValueNode right) {
    assert left.getStackKind() == wordKind && right.getStackKind() == wordKind;
    CanonicalizedCondition canonical = condition.canonicalize();
    ValueNode a = canonical.mustMirror() ? right : left;
    ValueNode b = canonical.mustMirror() ? left : right;
    CompareNode comparison;
    if (canonical.getCanonicalCondition() == CanonicalCondition.EQ) {
        comparison = new IntegerEqualsNode(a, b);
    } else if (canonical.getCanonicalCondition() == CanonicalCondition.BT) {
        comparison = new IntegerBelowNode(a, b);
    } else {
        assert canonical.getCanonicalCondition() == CanonicalCondition.LT;
        comparison = new IntegerLessThanNode(a, b);
    }
    ConstantNode trueValue = graph.add(forInt(1));
    ConstantNode falseValue = graph.add(forInt(0));
    if (canonical.mustNegate()) {
        ConstantNode temp = trueValue;
        trueValue = falseValue;
        falseValue = temp;
    }
    return graph.add(new ConditionalNode(graph.add(comparison), trueValue, falseValue));
}
Also used : CanonicalizedCondition(org.graalvm.compiler.core.common.calc.Condition.CanonicalizedCondition) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) ConditionalNode(org.graalvm.compiler.nodes.calc.ConditionalNode) CompareNode(org.graalvm.compiler.nodes.calc.CompareNode) IntegerEqualsNode(org.graalvm.compiler.nodes.calc.IntegerEqualsNode) IntegerBelowNode(org.graalvm.compiler.nodes.calc.IntegerBelowNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) IntegerLessThanNode(org.graalvm.compiler.nodes.calc.IntegerLessThanNode)

Example 5 with ConditionalNode

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

the class SubstrateGraphBuilderPlugins method registerClassPlugins.

private static void registerClassPlugins(InvocationPlugins plugins) {
    /*
         * We have our own Java-level implementation of isAssignableFrom() in DynamicHub, so we do
         * not need to intrinsifiy that to a Graal node. Therefore, we overwrite and deactivate the
         * invocation plugin registered in StandardGraphBuilderPlugins.
         *
         * TODO we should remove the implementation from DynamicHub to a lowering of
         * ClassIsAssignableFromNode. Then we can remove this code.
         */
    Registration r = new Registration(plugins, Class.class).setAllowOverwrite(true);
    r.register2("isAssignableFrom", Receiver.class, Class.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver type, ValueNode otherType) {
            return false;
        }
    });
    r.register2("cast", Receiver.class, Object.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object) {
            ValueNode toType = receiver.get();
            LogicNode condition = b.append(InstanceOfDynamicNode.create(b.getAssumptions(), b.getConstantReflection(), toType, object, true));
            if (condition.isTautology()) {
                b.addPush(JavaKind.Object, object);
            } else {
                FixedGuardNode fixedGuard = b.add(new FixedGuardNode(condition, DeoptimizationReason.ClassCastException, DeoptimizationAction.InvalidateReprofile, false));
                b.addPush(JavaKind.Object, DynamicPiNode.create(b.getAssumptions(), b.getConstantReflection(), object, fixedGuard, toType));
            }
            return true;
        }
    });
    r.register2("isInstance", Receiver.class, Object.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object) {
            ValueNode type = receiver.get();
            LogicNode condition = b.append(InstanceOfDynamicNode.create(null, b.getConstantReflection(), type, object, false));
            b.push(JavaKind.Boolean.getStackKind(), b.append(new ConditionalNode(condition).canonical(null)));
            return true;
        }
    });
}
Also used : FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) ConditionalNode(org.graalvm.compiler.nodes.calc.ConditionalNode) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) StackValueNode(com.oracle.svm.core.graal.stackvalue.StackValueNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) ConvertUnknownValueNode(com.oracle.graal.pointsto.nodes.ConvertUnknownValueNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) LogicNode(org.graalvm.compiler.nodes.LogicNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Aggregations

ConditionalNode (org.graalvm.compiler.nodes.calc.ConditionalNode)16 ValueNode (org.graalvm.compiler.nodes.ValueNode)12 LogicNode (org.graalvm.compiler.nodes.LogicNode)7 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)7 IntegerEqualsNode (org.graalvm.compiler.nodes.calc.IntegerEqualsNode)6 IntegerLessThanNode (org.graalvm.compiler.nodes.calc.IntegerLessThanNode)4 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)3 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)3 InvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin)3 Registration (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration)3 Stamp (org.graalvm.compiler.core.common.type.Stamp)2 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)2 CompareNode (org.graalvm.compiler.nodes.calc.CompareNode)2 Receiver (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver)2 Test (org.junit.Test)2 ConvertUnknownValueNode (com.oracle.graal.pointsto.nodes.ConvertUnknownValueNode)1 StackValueNode (com.oracle.svm.core.graal.stackvalue.StackValueNode)1 JavaKind (jdk.vm.ci.meta.JavaKind)1 CanonicalizedCondition (org.graalvm.compiler.core.common.calc.Condition.CanonicalizedCondition)1 FloatConvert (org.graalvm.compiler.core.common.calc.FloatConvert)1