Search in sources :

Example 11 with ConditionalNode

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

the class CompareCanonicalizerTest method testIntegerTestCanonicalization.

@Test
public void testIntegerTestCanonicalization() {
    ValueNode result = getResult(getCanonicalizedGraph("integerTestCanonicalization1"));
    assertTrue(result.isConstant() && result.asJavaConstant().asLong() == 1);
    result = getResult(getCanonicalizedGraph("integerTestCanonicalization2"));
    assertTrue(result.isConstant() && result.asJavaConstant().asLong() == 1);
    StructuredGraph graph = getCanonicalizedGraph("integerTestCanonicalization3");
    assertDeepEquals(1, graph.getNodes(ReturnNode.TYPE).count());
    assertTrue(graph.getNodes(ReturnNode.TYPE).first().result() instanceof ConditionalNode);
}
Also used : ConditionalNode(org.graalvm.compiler.nodes.calc.ConditionalNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ValueNode(org.graalvm.compiler.nodes.ValueNode) Test(org.junit.Test)

Example 12 with ConditionalNode

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

the class HotSpotProfilingPlugin method profileIf.

@Override
public void profileIf(GraphBuilderContext builder, ResolvedJavaMethod method, int bci, LogicNode condition, int trueBranchBci, int falseBranchBci, FrameState frameState) {
    assert shouldProfile(builder, method);
    OptionValues options = builder.getOptions();
    if (Options.ProfileBackedges.getValue(options) && (falseBranchBci <= bci || trueBranchBci <= bci)) {
        boolean negate = false;
        int targetBci = trueBranchBci;
        if (falseBranchBci <= bci) {
            assert trueBranchBci > bci;
            negate = true;
            targetBci = falseBranchBci;
        } else {
            assert trueBranchBci <= bci && falseBranchBci > bci;
        }
        ValueNode trueValue = builder.append(ConstantNode.forBoolean(!negate));
        ValueNode falseValue = builder.append(ConstantNode.forBoolean(negate));
        ConditionalNode branchCondition = builder.append(new ConditionalNode(condition, trueValue, falseValue));
        ProfileNode p = builder.append(new ProfileBranchNode(method, backedgeNotifyFreqLog(options), backedgeProfilePobabilityLog(options), branchCondition, bci, targetBci));
        p.setStateBefore(frameState);
    }
}
Also used : ProfileBranchNode(org.graalvm.compiler.hotspot.nodes.profiling.ProfileBranchNode) ConditionalNode(org.graalvm.compiler.nodes.calc.ConditionalNode) OptionValues(org.graalvm.compiler.options.OptionValues) ProfileNode(org.graalvm.compiler.hotspot.nodes.profiling.ProfileNode) ValueNode(org.graalvm.compiler.nodes.ValueNode)

Example 13 with ConditionalNode

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

the class ExpandLogicPhase method processConditional.

@SuppressWarnings("try")
private static void processConditional(LogicNode x, boolean xNegated, LogicNode y, boolean yNegated, ConditionalNode conditional) {
    try (DebugCloseable context = conditional.withNodeSourcePosition()) {
        ValueNode trueTarget = conditional.trueValue();
        ValueNode falseTarget = conditional.falseValue();
        Graph graph = conditional.graph();
        ConditionalNode secondConditional = graph.unique(new ConditionalNode(y, yNegated ? falseTarget : trueTarget, yNegated ? trueTarget : falseTarget));
        ConditionalNode firstConditional = graph.unique(new ConditionalNode(x, xNegated ? secondConditional : trueTarget, xNegated ? trueTarget : secondConditional));
        conditional.replaceAndDelete(firstConditional);
    }
}
Also used : Graph(org.graalvm.compiler.graph.Graph) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ConditionalNode(org.graalvm.compiler.nodes.calc.ConditionalNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable)

Example 14 with ConditionalNode

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

the class ExpandLogicPhase method processNormalizeCompareNode.

private static void processNormalizeCompareNode(NormalizeCompareNode normalize) {
    LogicNode equalComp;
    LogicNode lessComp;
    StructuredGraph graph = normalize.graph();
    ValueNode x = normalize.getX();
    ValueNode y = normalize.getY();
    if (x.stamp(NodeView.DEFAULT) instanceof FloatStamp) {
        equalComp = graph.addOrUniqueWithInputs(FloatEqualsNode.create(x, y, NodeView.DEFAULT));
        lessComp = graph.addOrUniqueWithInputs(FloatLessThanNode.create(x, y, normalize.isUnorderedLess(), NodeView.DEFAULT));
    } else {
        equalComp = graph.addOrUniqueWithInputs(IntegerEqualsNode.create(x, y, NodeView.DEFAULT));
        lessComp = graph.addOrUniqueWithInputs(IntegerLessThanNode.create(x, y, NodeView.DEFAULT));
    }
    Stamp stamp = normalize.stamp(NodeView.DEFAULT);
    ConditionalNode equalValue = graph.unique(new ConditionalNode(equalComp, ConstantNode.forIntegerStamp(stamp, 0, graph), ConstantNode.forIntegerStamp(stamp, 1, graph)));
    ConditionalNode value = graph.unique(new ConditionalNode(lessComp, ConstantNode.forIntegerStamp(stamp, -1, graph), equalValue));
    normalize.replaceAtUsagesAndDelete(value);
}
Also used : ConditionalNode(org.graalvm.compiler.nodes.calc.ConditionalNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) FloatStamp(org.graalvm.compiler.core.common.type.FloatStamp) Stamp(org.graalvm.compiler.core.common.type.Stamp) ValueNode(org.graalvm.compiler.nodes.ValueNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) FloatStamp(org.graalvm.compiler.core.common.type.FloatStamp)

Example 15 with ConditionalNode

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

the class LoopTransformations method updatePreLoopLimit.

private static void updatePreLoopLimit(IfNode preLimit, InductionVariable preIv, CountedLoopInfo preCounted) {
    // Update the pre loops limit test
    StructuredGraph graph = preLimit.graph();
    LogicNode ifTest = preLimit.condition();
    CompareNode compareNode = (CompareNode) ifTest;
    ValueNode prePhi = preIv.valueNode();
    // Make new limit one iteration
    ValueNode initIv = preCounted.getStart();
    ValueNode newLimit = add(graph, initIv, preIv.strideNode());
    // Fetch the variable we are not replacing and configure the one we are
    ValueNode ub;
    if (compareNode.getX() == prePhi) {
        ub = compareNode.getY();
    } else if (compareNode.getY() == prePhi) {
        ub = compareNode.getX();
    } else {
        throw GraalError.shouldNotReachHere();
    }
    // Re-wire the condition with the new limit
    if (preIv.direction() == Direction.Up) {
        compareNode.replaceFirstInput(ub, graph.unique(new ConditionalNode(graph.unique(new IntegerLessThanNode(newLimit, ub)), newLimit, ub)));
    } else {
        compareNode.replaceFirstInput(ub, graph.unique(new ConditionalNode(graph.unique(new IntegerLessThanNode(ub, newLimit)), newLimit, ub)));
    }
}
Also used : ConditionalNode(org.graalvm.compiler.nodes.calc.ConditionalNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CompareNode(org.graalvm.compiler.nodes.calc.CompareNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) IntegerLessThanNode(org.graalvm.compiler.nodes.calc.IntegerLessThanNode) LogicNode(org.graalvm.compiler.nodes.LogicNode)

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