Search in sources :

Example 1 with CanonicalizedCondition

use of org.graalvm.compiler.core.common.calc.Condition.CanonicalizedCondition in project graal by oracle.

the class BytecodeParser method genIf.

protected void genIf(ValueNode x, Condition cond, ValueNode y) {
    assert x.getStackKind() == y.getStackKind();
    assert currentBlock.getSuccessorCount() == 2;
    BciBlock trueBlock = currentBlock.getSuccessor(0);
    BciBlock falseBlock = currentBlock.getSuccessor(1);
    if (trueBlock == falseBlock) {
        // The target block is the same independent of the condition.
        appendGoto(trueBlock);
        return;
    }
    ValueNode a = x;
    ValueNode b = y;
    BciBlock trueSuccessor = trueBlock;
    BciBlock falseSuccessor = falseBlock;
    CanonicalizedCondition canonicalizedCondition = cond.canonicalize();
    // Check whether the condition needs to mirror the operands.
    if (canonicalizedCondition.mustMirror()) {
        a = y;
        b = x;
    }
    if (canonicalizedCondition.mustNegate()) {
        trueSuccessor = falseBlock;
        falseSuccessor = trueBlock;
    }
    // Create the logic node for the condition.
    LogicNode condition = createLogicNode(canonicalizedCondition.getCanonicalCondition(), a, b);
    double probability = -1;
    if (condition instanceof IntegerEqualsNode) {
        probability = extractInjectedProbability((IntegerEqualsNode) condition);
    // the probability coming from here is about the actual condition
    }
    if (probability == -1) {
        probability = getProfileProbability(canonicalizedCondition.mustNegate());
    }
    probability = clampProbability(probability);
    genIf(condition, trueSuccessor, falseSuccessor, probability);
}
Also used : CanonicalizedCondition(org.graalvm.compiler.core.common.calc.Condition.CanonicalizedCondition) IntegerEqualsNode(org.graalvm.compiler.nodes.calc.IntegerEqualsNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) BciBlock(org.graalvm.compiler.java.BciBlockMapping.BciBlock)

Example 2 with CanonicalizedCondition

use of org.graalvm.compiler.core.common.calc.Condition.CanonicalizedCondition 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)

Aggregations

CanonicalizedCondition (org.graalvm.compiler.core.common.calc.Condition.CanonicalizedCondition)2 ValueNode (org.graalvm.compiler.nodes.ValueNode)2 IntegerEqualsNode (org.graalvm.compiler.nodes.calc.IntegerEqualsNode)2 BciBlock (org.graalvm.compiler.java.BciBlockMapping.BciBlock)1 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)1 LogicNode (org.graalvm.compiler.nodes.LogicNode)1 CompareNode (org.graalvm.compiler.nodes.calc.CompareNode)1 ConditionalNode (org.graalvm.compiler.nodes.calc.ConditionalNode)1 IntegerBelowNode (org.graalvm.compiler.nodes.calc.IntegerBelowNode)1 IntegerLessThanNode (org.graalvm.compiler.nodes.calc.IntegerLessThanNode)1