Search in sources :

Example 56 with LIRKind

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

the class ArithmeticLIRGenerator method emitAddOrSub.

private Variable emitAddOrSub(Value aVal, Value bVal, boolean setFlags, boolean isAdd) {
    LIRKind resultKind;
    Value a = aVal;
    Value b = bVal;
    if (isNumericInteger(a.getPlatformKind())) {
        LIRKind aKind = a.getValueKind(LIRKind.class);
        LIRKind bKind = b.getValueKind(LIRKind.class);
        assert a.getPlatformKind() == b.getPlatformKind() : a.getPlatformKind() + " vs. " + b.getPlatformKind();
        if (aKind.isUnknownReference()) {
            resultKind = aKind;
        } else if (bKind.isUnknownReference()) {
            resultKind = bKind;
        } else if (aKind.isValue() && bKind.isValue()) {
            resultKind = aKind;
        } else if (aKind.isValue()) {
            if (bKind.isDerivedReference()) {
                resultKind = bKind;
            } else {
                AllocatableValue allocatable = getLIRGen().asAllocatable(b);
                resultKind = bKind.makeDerivedReference(allocatable);
                b = allocatable;
            }
        } else if (bKind.isValue()) {
            if (aKind.isDerivedReference()) {
                resultKind = aKind;
            } else {
                AllocatableValue allocatable = getLIRGen().asAllocatable(a);
                resultKind = aKind.makeDerivedReference(allocatable);
                a = allocatable;
            }
        } else {
            resultKind = aKind.makeUnknownReference();
        }
    } else {
        resultKind = LIRKind.combine(a, b);
    }
    return isAdd ? emitAdd(resultKind, a, b, setFlags) : emitSub(resultKind, a, b, setFlags);
}
Also used : Value(jdk.vm.ci.meta.Value) AllocatableValue(jdk.vm.ci.meta.AllocatableValue) LIRKind(org.graalvm.compiler.core.common.LIRKind) AllocatableValue(jdk.vm.ci.meta.AllocatableValue)

Example 57 with LIRKind

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

the class NodeLIRBuilder method emitOverflowCheckBranch.

@Override
public void emitOverflowCheckBranch(AbstractBeginNode overflowSuccessor, AbstractBeginNode next, Stamp stamp, double probability) {
    LIRKind cmpKind = getLIRGeneratorTool().getLIRKind(stamp);
    gen.emitOverflowCheckBranch(getLIRBlock(overflowSuccessor), getLIRBlock(next), cmpKind, probability);
}
Also used : LIRKind(org.graalvm.compiler.core.common.LIRKind)

Example 58 with LIRKind

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

the class NodeLIRBuilder method emitNullCheckBranch.

private void emitNullCheckBranch(IsNullNode node, LabelRef trueSuccessor, LabelRef falseSuccessor, double trueSuccessorProbability) {
    LIRKind kind = gen.getLIRKind(node.getValue().stamp(NodeView.DEFAULT));
    Value nullValue = gen.emitConstant(kind, JavaConstant.NULL_POINTER);
    gen.emitCompareBranch(kind.getPlatformKind(), operand(node.getValue()), nullValue, Condition.EQ, false, trueSuccessor, falseSuccessor, trueSuccessorProbability);
}
Also used : ComplexMatchValue(org.graalvm.compiler.core.match.ComplexMatchValue) Value(jdk.vm.ci.meta.Value) AllocatableValue(jdk.vm.ci.meta.AllocatableValue) LIRKind(org.graalvm.compiler.core.common.LIRKind)

Example 59 with LIRKind

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

the class NodeLIRBuilder method emitConditional.

public Variable emitConditional(LogicNode node, Value trueValue, Value falseValue) {
    if (node instanceof IsNullNode) {
        IsNullNode isNullNode = (IsNullNode) node;
        LIRKind kind = gen.getLIRKind(isNullNode.getValue().stamp(NodeView.DEFAULT));
        Value nullValue = gen.emitConstant(kind, JavaConstant.NULL_POINTER);
        return gen.emitConditionalMove(kind.getPlatformKind(), operand(isNullNode.getValue()), nullValue, Condition.EQ, false, trueValue, falseValue);
    } else if (node instanceof CompareNode) {
        CompareNode compare = (CompareNode) node;
        PlatformKind kind = gen.getLIRKind(compare.getX().stamp(NodeView.DEFAULT)).getPlatformKind();
        return gen.emitConditionalMove(kind, operand(compare.getX()), operand(compare.getY()), compare.condition().asCondition(), compare.unorderedIsTrue(), trueValue, falseValue);
    } else if (node instanceof LogicConstantNode) {
        return gen.emitMove(((LogicConstantNode) node).getValue() ? trueValue : falseValue);
    } else if (node instanceof IntegerTestNode) {
        IntegerTestNode test = (IntegerTestNode) node;
        return gen.emitIntegerTestMove(operand(test.getX()), operand(test.getY()), trueValue, falseValue);
    } else {
        throw GraalError.unimplemented(node.toString());
    }
}
Also used : CompareNode(org.graalvm.compiler.nodes.calc.CompareNode) IsNullNode(org.graalvm.compiler.nodes.calc.IsNullNode) IntegerTestNode(org.graalvm.compiler.nodes.calc.IntegerTestNode) ComplexMatchValue(org.graalvm.compiler.core.match.ComplexMatchValue) Value(jdk.vm.ci.meta.Value) AllocatableValue(jdk.vm.ci.meta.AllocatableValue) LogicConstantNode(org.graalvm.compiler.nodes.LogicConstantNode) LIRKind(org.graalvm.compiler.core.common.LIRKind) PlatformKind(jdk.vm.ci.meta.PlatformKind)

Example 60 with LIRKind

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

the class NodeLIRBuilder method emitSwitch.

/**
 * This method tries to create a switch implementation that is optimal for the given switch. It
 * will either generate a sequential if/then/else cascade, a set of range tests or a table
 * switch.
 *
 * If the given switch does not contain int keys, it will always create a sequential
 * implementation.
 */
@Override
public void emitSwitch(SwitchNode x) {
    assert x.defaultSuccessor() != null;
    LabelRef defaultTarget = getLIRBlock(x.defaultSuccessor());
    int keyCount = x.keyCount();
    if (keyCount == 0) {
        gen.emitJump(defaultTarget);
    } else {
        Variable value = gen.load(operand(x.value()));
        if (keyCount == 1) {
            assert defaultTarget != null;
            double probability = x.probability(x.keySuccessor(0));
            LIRKind kind = gen.getLIRKind(x.value().stamp(NodeView.DEFAULT));
            Value key = gen.emitConstant(kind, x.keyAt(0));
            gen.emitCompareBranch(kind.getPlatformKind(), gen.load(operand(x.value())), key, Condition.EQ, false, getLIRBlock(x.keySuccessor(0)), defaultTarget, probability);
        } else if (x instanceof IntegerSwitchNode && x.isSorted()) {
            IntegerSwitchNode intSwitch = (IntegerSwitchNode) x;
            LabelRef[] keyTargets = new LabelRef[keyCount];
            JavaConstant[] keyConstants = new JavaConstant[keyCount];
            double[] keyProbabilities = new double[keyCount];
            JavaKind keyKind = intSwitch.keyAt(0).getJavaKind();
            for (int i = 0; i < keyCount; i++) {
                keyTargets[i] = getLIRBlock(intSwitch.keySuccessor(i));
                keyConstants[i] = intSwitch.keyAt(i);
                keyProbabilities[i] = intSwitch.keyProbability(i);
                assert keyConstants[i].getJavaKind() == keyKind;
            }
            gen.emitStrategySwitch(keyConstants, keyProbabilities, keyTargets, defaultTarget, value);
        } else {
            // keyKind != JavaKind.Int || !x.isSorted()
            LabelRef[] keyTargets = new LabelRef[keyCount];
            Constant[] keyConstants = new Constant[keyCount];
            double[] keyProbabilities = new double[keyCount];
            for (int i = 0; i < keyCount; i++) {
                keyTargets[i] = getLIRBlock(x.keySuccessor(i));
                keyConstants[i] = x.keyAt(i);
                keyProbabilities[i] = x.keyProbability(i);
            }
            // hopefully only a few entries
            gen.emitStrategySwitch(new SwitchStrategy.SequentialStrategy(keyProbabilities, keyConstants), value, keyTargets, defaultTarget);
        }
    }
}
Also used : Variable(org.graalvm.compiler.lir.Variable) ComplexMatchValue(org.graalvm.compiler.core.match.ComplexMatchValue) Value(jdk.vm.ci.meta.Value) AllocatableValue(jdk.vm.ci.meta.AllocatableValue) LIRKind(org.graalvm.compiler.core.common.LIRKind) LabelRef(org.graalvm.compiler.lir.LabelRef) IntegerSwitchNode(org.graalvm.compiler.nodes.extended.IntegerSwitchNode) JavaKind(jdk.vm.ci.meta.JavaKind)

Aggregations

LIRKind (org.graalvm.compiler.core.common.LIRKind)60 AllocatableValue (jdk.vm.ci.meta.AllocatableValue)20 Variable (org.graalvm.compiler.lir.Variable)19 Value (jdk.vm.ci.meta.Value)15 RegisterValue (jdk.vm.ci.code.RegisterValue)11 TargetDescription (jdk.vm.ci.code.TargetDescription)7 PlatformKind (jdk.vm.ci.meta.PlatformKind)7 LIRGeneratorTool (org.graalvm.compiler.lir.gen.LIRGeneratorTool)7 AMD64Kind (jdk.vm.ci.amd64.AMD64Kind)6 JavaConstant (jdk.vm.ci.meta.JavaConstant)4 SPARCKind (jdk.vm.ci.sparc.SPARCKind)4 ComplexMatchValue (org.graalvm.compiler.core.match.ComplexMatchValue)4 AArch64AddressValue (org.graalvm.compiler.lir.aarch64.AArch64AddressValue)4 AMD64AddressValue (org.graalvm.compiler.lir.amd64.AMD64AddressValue)4 ComplexMatchResult (org.graalvm.compiler.core.match.ComplexMatchResult)3 MatchRule (org.graalvm.compiler.core.match.MatchRule)3 ConstantValue (org.graalvm.compiler.lir.ConstantValue)3 AMD64MulDivOp (org.graalvm.compiler.lir.amd64.AMD64MulDivOp)3 SubstrateRegisterConfig (com.oracle.svm.core.graal.meta.SubstrateRegisterConfig)2 Op3s (org.graalvm.compiler.asm.sparc.SPARCAssembler.Op3s)2