Search in sources :

Example 1 with NodeLIRBuilder

use of org.graalvm.compiler.core.gen.NodeLIRBuilder 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 2 with NodeLIRBuilder

use of org.graalvm.compiler.core.gen.NodeLIRBuilder in project graal by oracle.

the class AMD64NodeMatchRules method narrowRead.

@MatchRule("(Narrow Read=access)")
@MatchRule("(Narrow FloatingRead=access)")
public ComplexMatchResult narrowRead(NarrowNode root, LIRLowerableAccess access) {
    return new ComplexMatchResult() {

        @Override
        public Value evaluate(NodeLIRBuilder builder) {
            AMD64AddressValue address = (AMD64AddressValue) operand(access.getAddress());
            LIRKind addressKind = LIRKind.combineDerived(getLIRGeneratorTool().getLIRKind(root.asNode().stamp(NodeView.DEFAULT)), address.getBase(), address.getIndex());
            AMD64AddressValue newAddress = address.withKind(addressKind);
            LIRKind readKind = getLIRGeneratorTool().getLIRKind(root.stamp(NodeView.DEFAULT));
            return getArithmeticLIRGenerator().emitZeroExtendMemory((AMD64Kind) readKind.getPlatformKind(), root.getResultBits(), newAddress, getState(access));
        }
    };
}
Also used : AMD64AddressValue(org.graalvm.compiler.lir.amd64.AMD64AddressValue) ComplexMatchResult(org.graalvm.compiler.core.match.ComplexMatchResult) NodeLIRBuilder(org.graalvm.compiler.core.gen.NodeLIRBuilder) LIRKind(org.graalvm.compiler.core.common.LIRKind) MatchRule(org.graalvm.compiler.core.match.MatchRule)

Aggregations

NodeLIRBuilder (org.graalvm.compiler.core.gen.NodeLIRBuilder)2 ComplexMatchResult (org.graalvm.compiler.core.match.ComplexMatchResult)2 AMD64AddressValue (org.graalvm.compiler.lir.amd64.AMD64AddressValue)2 AMD64Kind (jdk.vm.ci.amd64.AMD64Kind)1 AllocatableValue (jdk.vm.ci.meta.AllocatableValue)1 JavaConstant (jdk.vm.ci.meta.JavaConstant)1 Value (jdk.vm.ci.meta.Value)1 LIRKind (org.graalvm.compiler.core.common.LIRKind)1 CanonicalCondition (org.graalvm.compiler.core.common.calc.CanonicalCondition)1 Condition (org.graalvm.compiler.core.common.calc.Condition)1 MatchRule (org.graalvm.compiler.core.match.MatchRule)1 LabelRef (org.graalvm.compiler.lir.LabelRef)1