Search in sources :

Example 1 with Condition

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

the class AMD64LIRGenerator method emitCompareBranchMemory.

public void emitCompareBranchMemory(AMD64Kind cmpKind, Value left, AMD64AddressValue right, LIRFrameState state, Condition cond, boolean unorderedIsTrue, LabelRef trueLabel, LabelRef falseLabel, double trueLabelProbability) {
    boolean mirrored = emitCompareMemory(cmpKind, left, right, state);
    Condition finalCondition = mirrored ? cond.mirror() : cond;
    if (cmpKind.isXMM()) {
        append(new FloatBranchOp(finalCondition, unorderedIsTrue, trueLabel, falseLabel, trueLabelProbability));
    } else {
        append(new BranchOp(finalCondition, trueLabel, falseLabel, trueLabelProbability));
    }
}
Also used : Condition(org.graalvm.compiler.core.common.calc.Condition) FloatBranchOp(org.graalvm.compiler.lir.amd64.AMD64ControlFlow.FloatBranchOp) BranchOp(org.graalvm.compiler.lir.amd64.AMD64ControlFlow.BranchOp) FloatBranchOp(org.graalvm.compiler.lir.amd64.AMD64ControlFlow.FloatBranchOp)

Example 2 with Condition

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

the class AMD64NodeMatchRules method emitCompareBranchMemory.

protected ComplexMatchResult emitCompareBranchMemory(IfNode ifNode, CompareNode compare, ValueNode value, LIRLowerableAccess access) {
    Condition cond = compare.condition().asCondition();
    AMD64Kind kind = getMemoryKind(access);
    // For assertion checking
    boolean matchedAsConstant = false;
    if (value.isConstant()) {
        JavaConstant constant = value.asJavaConstant();
        if (constant != null) {
            if (kind == AMD64Kind.QWORD && !constant.getJavaKind().isObject() && !NumUtil.isInt(constant.asLong())) {
                // Only imm32 as long
                return null;
            }
            // A QWORD that can be encoded as int can be embedded as a constant
            matchedAsConstant = kind == AMD64Kind.QWORD && !constant.getJavaKind().isObject() && NumUtil.isInt(constant.asLong());
        }
        if (kind == AMD64Kind.DWORD) {
            // Any DWORD value should be embeddable as a constant
            matchedAsConstant = true;
        }
        if (kind.isXMM()) {
            ifNode.getDebug().log("Skipping constant compares for float kinds");
            return null;
        }
    }
    boolean matchedAsConstantFinal = matchedAsConstant;
    /*
         * emitCompareBranchMemory expects the memory on the right, so mirror the condition if
         * that's not true. It might be mirrored again the actual compare is emitted but that's ok.
         */
    Condition finalCondition = GraphUtil.unproxify(compare.getX()) == access ? cond.mirror() : cond;
    return new ComplexMatchResult() {

        @Override
        public Value evaluate(NodeLIRBuilder builder) {
            LabelRef trueLabel = getLIRBlock(ifNode.trueSuccessor());
            LabelRef falseLabel = getLIRBlock(ifNode.falseSuccessor());
            boolean unorderedIsTrue = compare.unorderedIsTrue();
            double trueLabelProbability = ifNode.probability(ifNode.trueSuccessor());
            Value other = operand(value);
            /*
                 * Check that patterns which were matched as a constant actually end up seeing a
                 * constant in the LIR.
                 */
            assert !matchedAsConstantFinal || !LIRValueUtil.isVariable(other) : "expected constant value " + value;
            AMD64AddressValue address = (AMD64AddressValue) operand(access.getAddress());
            getLIRGeneratorTool().emitCompareBranchMemory(kind, other, address, getState(access), finalCondition, unorderedIsTrue, trueLabel, falseLabel, trueLabelProbability);
            return null;
        }
    };
}
Also used : Condition(org.graalvm.compiler.core.common.calc.Condition) CanonicalCondition(org.graalvm.compiler.core.common.calc.CanonicalCondition) AMD64AddressValue(org.graalvm.compiler.lir.amd64.AMD64AddressValue) AMD64Kind(jdk.vm.ci.amd64.AMD64Kind) ComplexMatchResult(org.graalvm.compiler.core.match.ComplexMatchResult) NodeLIRBuilder(org.graalvm.compiler.core.gen.NodeLIRBuilder) Value(jdk.vm.ci.meta.Value) AllocatableValue(jdk.vm.ci.meta.AllocatableValue) AMD64AddressValue(org.graalvm.compiler.lir.amd64.AMD64AddressValue) JavaConstant(jdk.vm.ci.meta.JavaConstant) LabelRef(org.graalvm.compiler.lir.LabelRef)

Example 3 with Condition

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

the class AArch64LIRGenerator method emitCompareBranch.

@Override
public void emitCompareBranch(PlatformKind cmpKind, Value left, Value right, Condition cond, boolean unorderedIsTrue, LabelRef trueDestination, LabelRef falseDestination, double trueDestinationProbability) {
    boolean mirrored = emitCompare(cmpKind, left, right, cond, unorderedIsTrue);
    Condition finalCondition = mirrored ? cond.mirror() : cond;
    boolean finalUnorderedIsTrue = mirrored ? !unorderedIsTrue : unorderedIsTrue;
    ConditionFlag cmpCondition = toConditionFlag(((AArch64Kind) cmpKind).isInteger(), finalCondition, finalUnorderedIsTrue);
    append(new BranchOp(cmpCondition, trueDestination, falseDestination, trueDestinationProbability));
}
Also used : Condition(org.graalvm.compiler.core.common.calc.Condition) BranchOp(org.graalvm.compiler.lir.aarch64.AArch64ControlFlow.BranchOp) ConditionFlag(org.graalvm.compiler.asm.aarch64.AArch64Assembler.ConditionFlag)

Example 4 with Condition

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

the class AArch64LIRGenerator method emitConditionalMove.

/**
 * Conditionally move trueValue into new variable if cond + unorderedIsTrue is true, else
 * falseValue.
 *
 * @param left Arbitrary value. Has to have same type as right. Non null.
 * @param right Arbitrary value. Has to have same type as left. Non null.
 * @param cond condition that decides whether to move trueValue or falseValue into result. Non
 *            null.
 * @param unorderedIsTrue defines whether floating-point comparisons consider unordered true or
 *            not. Ignored for integer comparisons.
 * @param trueValue arbitrary value same type as falseValue. Non null.
 * @param falseValue arbitrary value same type as trueValue. Non null.
 * @return value containing trueValue if cond + unorderedIsTrue is true, else falseValue. Non
 *         null.
 */
@Override
public Variable emitConditionalMove(PlatformKind cmpKind, Value left, Value right, Condition cond, boolean unorderedIsTrue, Value trueValue, Value falseValue) {
    boolean mirrored = emitCompare(cmpKind, left, right, cond, unorderedIsTrue);
    Condition finalCondition = mirrored ? cond.mirror() : cond;
    boolean finalUnorderedIsTrue = mirrored ? !unorderedIsTrue : unorderedIsTrue;
    ConditionFlag cmpCondition = toConditionFlag(((AArch64Kind) cmpKind).isInteger(), finalCondition, finalUnorderedIsTrue);
    Variable result = newVariable(trueValue.getValueKind());
    append(new CondMoveOp(result, cmpCondition, loadReg(trueValue), loadReg(falseValue)));
    return result;
}
Also used : Condition(org.graalvm.compiler.core.common.calc.Condition) Variable(org.graalvm.compiler.lir.Variable) CondMoveOp(org.graalvm.compiler.lir.aarch64.AArch64ControlFlow.CondMoveOp) ConditionFlag(org.graalvm.compiler.asm.aarch64.AArch64Assembler.ConditionFlag)

Example 5 with Condition

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

the class SPARCLIRGenerator method emitCompareBranch.

@Override
public void emitCompareBranch(PlatformKind cmpKind, Value x, Value y, Condition cond, boolean unorderedIsTrue, LabelRef trueDestination, LabelRef falseDestination, double trueDestinationProbability) {
    AllocatableValue left;
    Value right;
    Condition actualCondition;
    if (isJavaConstant(x)) {
        left = load(y);
        right = loadSimm13(x);
        actualCondition = cond.mirror();
    } else {
        left = load(x);
        right = loadSimm13(y);
        actualCondition = cond;
    }
    SPARCKind actualCmpKind = (SPARCKind) cmpKind;
    if (actualCmpKind.isInteger()) {
        assert actualCmpKind.equals(XWORD) || actualCmpKind.equals(WORD) : "SPARC does not support compare of: " + actualCmpKind;
        append(new SPARCControlFlow.CompareBranchOp(left, right, actualCondition, trueDestination, falseDestination, actualCmpKind, unorderedIsTrue, trueDestinationProbability));
    } else if (actualCmpKind.isFloat()) {
        emitFloatCompare(actualCmpKind, x, y, Fcc0);
        ConditionFlag cf = SPARCControlFlow.fromCondition(false, cond, unorderedIsTrue);
        append(new SPARCControlFlow.BranchOp(cf, trueDestination, falseDestination, actualCmpKind, trueDestinationProbability));
    } else {
        throw GraalError.shouldNotReachHere();
    }
}
Also used : Condition(org.graalvm.compiler.core.common.calc.Condition) BranchOp(org.graalvm.compiler.lir.sparc.SPARCControlFlow.BranchOp) Value(jdk.vm.ci.meta.Value) AllocatableValue(jdk.vm.ci.meta.AllocatableValue) SPARCImmediateAddressValue(org.graalvm.compiler.lir.sparc.SPARCImmediateAddressValue) SPARCAddressValue(org.graalvm.compiler.lir.sparc.SPARCAddressValue) AllocatableValue(jdk.vm.ci.meta.AllocatableValue) SPARCKind(jdk.vm.ci.sparc.SPARCKind) SPARCControlFlow(org.graalvm.compiler.lir.sparc.SPARCControlFlow) ConditionFlag(org.graalvm.compiler.asm.sparc.SPARCAssembler.ConditionFlag)

Aggregations

Condition (org.graalvm.compiler.core.common.calc.Condition)12 JavaConstant (jdk.vm.ci.meta.JavaConstant)6 Value (jdk.vm.ci.meta.Value)5 AllocatableValue (jdk.vm.ci.meta.AllocatableValue)4 Random (java.util.Random)3 CanonicalCondition (org.graalvm.compiler.core.common.calc.CanonicalCondition)3 AMD64AddressValue (org.graalvm.compiler.lir.amd64.AMD64AddressValue)3 IfNode (org.graalvm.compiler.nodes.IfNode)3 ValueNode (org.graalvm.compiler.nodes.ValueNode)3 CompareNode (org.graalvm.compiler.nodes.calc.CompareNode)3 AMD64Kind (jdk.vm.ci.amd64.AMD64Kind)2 SPARCKind (jdk.vm.ci.sparc.SPARCKind)2 ConditionFlag (org.graalvm.compiler.asm.aarch64.AArch64Assembler.ConditionFlag)2 LIRKind (org.graalvm.compiler.core.common.LIRKind)2 ComplexMatchResult (org.graalvm.compiler.core.match.ComplexMatchResult)2 LabelRef (org.graalvm.compiler.lir.LabelRef)2 SPARCAddressValue (org.graalvm.compiler.lir.sparc.SPARCAddressValue)2 Test (org.junit.Test)2 AMD64 (jdk.vm.ci.amd64.AMD64)1 CPUFeature (jdk.vm.ci.amd64.AMD64.CPUFeature)1