Search in sources :

Example 6 with LabelRef

use of org.graalvm.compiler.lir.LabelRef in project graal by oracle.

the class AMD64NodeMatchRules method ifCompareLogicCas.

@MatchRule("(If (ObjectEquals=compare value LogicCompareAndSwap=cas))")
@MatchRule("(If (PointerEquals=compare value LogicCompareAndSwap=cas))")
@MatchRule("(If (FloatEquals=compare value LogicCompareAndSwap=cas))")
@MatchRule("(If (IntegerEquals=compare value LogicCompareAndSwap=cas))")
public ComplexMatchResult ifCompareLogicCas(IfNode root, CompareNode compare, ValueNode value, LogicCompareAndSwapNode cas) {
    JavaConstant constant = value.asJavaConstant();
    assert compare.condition() == CanonicalCondition.EQ;
    if (constant != null && cas.usages().count() == 1) {
        long constantValue = constant.asLong();
        boolean successIsTrue;
        if (constantValue == 0) {
            successIsTrue = false;
        } else if (constantValue == 1) {
            successIsTrue = true;
        } else {
            return null;
        }
        return builder -> {
            LIRKind kind = getLirKind(cas);
            LabelRef trueLabel = getLIRBlock(root.trueSuccessor());
            LabelRef falseLabel = getLIRBlock(root.falseSuccessor());
            double trueLabelProbability = root.probability(root.trueSuccessor());
            Value expectedValue = operand(cas.getExpectedValue());
            Value newValue = operand(cas.getNewValue());
            AMD64AddressValue address = (AMD64AddressValue) operand(cas.getAddress());
            Condition condition = successIsTrue ? Condition.EQ : Condition.NE;
            getLIRGeneratorTool().emitCompareAndSwapBranch(kind, address, expectedValue, newValue, condition, trueLabel, falseLabel, trueLabelProbability);
            return null;
        };
    }
    return null;
}
Also used : OperandSize(org.graalvm.compiler.asm.amd64.AMD64Assembler.OperandSize) AMD64RMOp(org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64RMOp) AVXOp(org.graalvm.compiler.asm.amd64.AMD64Assembler.AVXOp) AMD64BinaryConsumer(org.graalvm.compiler.lir.amd64.AMD64BinaryConsumer) NarrowNode(org.graalvm.compiler.nodes.calc.NarrowNode) LabelRef(org.graalvm.compiler.lir.LabelRef) UnsignedRightShiftNode(org.graalvm.compiler.nodes.calc.UnsignedRightShiftNode) SUB(org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64BinaryArithmetic.SUB) SignExtendNode(org.graalvm.compiler.nodes.calc.SignExtendNode) FloatConvertNode(org.graalvm.compiler.nodes.calc.FloatConvertNode) ZeroExtendNode(org.graalvm.compiler.nodes.calc.ZeroExtendNode) AMD64Kind(jdk.vm.ci.amd64.AMD64Kind) NumUtil(org.graalvm.compiler.core.common.NumUtil) IfNode(org.graalvm.compiler.nodes.IfNode) GraphUtil(org.graalvm.compiler.nodes.util.GraphUtil) NodeView(org.graalvm.compiler.nodes.NodeView) LIRLowerableAccess(org.graalvm.compiler.nodes.memory.LIRLowerableAccess) BranchOp(org.graalvm.compiler.lir.amd64.AMD64ControlFlow.BranchOp) MOVSX(org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64RMOp.MOVSX) NodeLIRBuilder(org.graalvm.compiler.core.gen.NodeLIRBuilder) DeoptimizingNode(org.graalvm.compiler.nodes.DeoptimizingNode) TargetDescription(jdk.vm.ci.code.TargetDescription) JavaConstant(jdk.vm.ci.meta.JavaConstant) PlatformKind(jdk.vm.ci.meta.PlatformKind) ValueNode(org.graalvm.compiler.nodes.ValueNode) Value(jdk.vm.ci.meta.Value) ComplexMatchResult(org.graalvm.compiler.core.match.ComplexMatchResult) Access(org.graalvm.compiler.nodes.memory.Access) ADD(org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64BinaryArithmetic.ADD) SS(org.graalvm.compiler.asm.amd64.AMD64Assembler.OperandSize.SS) DWORD(org.graalvm.compiler.asm.amd64.AMD64Assembler.OperandSize.DWORD) GraalError(org.graalvm.compiler.debug.GraalError) ValueKind(jdk.vm.ci.meta.ValueKind) MatchRule(org.graalvm.compiler.core.match.MatchRule) LogicCompareAndSwapNode(org.graalvm.compiler.nodes.java.LogicCompareAndSwapNode) AllocatableValue(jdk.vm.ci.meta.AllocatableValue) CompareNode(org.graalvm.compiler.nodes.calc.CompareNode) LeftShiftNode(org.graalvm.compiler.nodes.calc.LeftShiftNode) MOVSXB(org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64RMOp.MOVSXB) WriteNode(org.graalvm.compiler.nodes.memory.WriteNode) LIRFrameState(org.graalvm.compiler.lir.LIRFrameState) SD(org.graalvm.compiler.asm.amd64.AMD64Assembler.OperandSize.SD) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) ReinterpretNode(org.graalvm.compiler.nodes.calc.ReinterpretNode) AMD64RRMOp(org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64RRMOp) AMD64(jdk.vm.ci.amd64.AMD64) AMD64MIOp(org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64MIOp) ValueCompareAndSwapNode(org.graalvm.compiler.nodes.java.ValueCompareAndSwapNode) MOVSXD(org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64RMOp.MOVSXD) Condition(org.graalvm.compiler.core.common.calc.Condition) CPUFeature(jdk.vm.ci.amd64.AMD64.CPUFeature) LIRKind(org.graalvm.compiler.core.common.LIRKind) CanonicalCondition(org.graalvm.compiler.core.common.calc.CanonicalCondition) SSEOp(org.graalvm.compiler.asm.amd64.AMD64Assembler.SSEOp) OR(org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64BinaryArithmetic.OR) LIRValueUtil(org.graalvm.compiler.lir.LIRValueUtil) NodeMatchRules(org.graalvm.compiler.core.gen.NodeMatchRules) XOR(org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64BinaryArithmetic.XOR) LIRGeneratorTool(org.graalvm.compiler.lir.gen.LIRGeneratorTool) AND(org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64BinaryArithmetic.AND) AMD64AddressValue(org.graalvm.compiler.lir.amd64.AMD64AddressValue) QWORD(org.graalvm.compiler.asm.amd64.AMD64Assembler.OperandSize.QWORD) AMD64AddressValue(org.graalvm.compiler.lir.amd64.AMD64AddressValue) Condition(org.graalvm.compiler.core.common.calc.Condition) CanonicalCondition(org.graalvm.compiler.core.common.calc.CanonicalCondition) 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) LIRKind(org.graalvm.compiler.core.common.LIRKind) LabelRef(org.graalvm.compiler.lir.LabelRef) MatchRule(org.graalvm.compiler.core.match.MatchRule)

Example 7 with LabelRef

use of org.graalvm.compiler.lir.LabelRef 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)

Example 8 with LabelRef

use of org.graalvm.compiler.lir.LabelRef in project graal by oracle.

the class NodeLIRBuilder method emitInvoke.

@Override
public void emitInvoke(Invoke x) {
    LoweredCallTargetNode callTarget = (LoweredCallTargetNode) x.callTarget();
    FrameMapBuilder frameMapBuilder = gen.getResult().getFrameMapBuilder();
    CallingConvention invokeCc = frameMapBuilder.getRegisterConfig().getCallingConvention(callTarget.callType(), x.asNode().stamp(NodeView.DEFAULT).javaType(gen.getMetaAccess()), callTarget.signature(), gen);
    frameMapBuilder.callsMethod(invokeCc);
    Value[] parameters = visitInvokeArguments(invokeCc, callTarget.arguments());
    LabelRef exceptionEdge = null;
    if (x instanceof InvokeWithExceptionNode) {
        exceptionEdge = getLIRBlock(((InvokeWithExceptionNode) x).exceptionEdge());
    }
    LIRFrameState callState = stateWithExceptionEdge(x, exceptionEdge);
    Value result = invokeCc.getReturn();
    if (callTarget instanceof DirectCallTargetNode) {
        emitDirectCall((DirectCallTargetNode) callTarget, result, parameters, AllocatableValue.NONE, callState);
    } else if (callTarget instanceof IndirectCallTargetNode) {
        emitIndirectCall((IndirectCallTargetNode) callTarget, result, parameters, AllocatableValue.NONE, callState);
    } else {
        throw GraalError.shouldNotReachHere();
    }
    if (isLegal(result)) {
        setResult(x.asNode(), gen.emitMove(result));
    }
    if (x instanceof InvokeWithExceptionNode) {
        gen.emitJump(getLIRBlock(((InvokeWithExceptionNode) x).next()));
    }
}
Also used : CallingConvention(jdk.vm.ci.code.CallingConvention) LIRFrameState(org.graalvm.compiler.lir.LIRFrameState) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) FrameMapBuilder(org.graalvm.compiler.lir.framemap.FrameMapBuilder) DirectCallTargetNode(org.graalvm.compiler.nodes.DirectCallTargetNode) ComplexMatchValue(org.graalvm.compiler.core.match.ComplexMatchValue) Value(jdk.vm.ci.meta.Value) AllocatableValue(jdk.vm.ci.meta.AllocatableValue) IndirectCallTargetNode(org.graalvm.compiler.nodes.IndirectCallTargetNode) LoweredCallTargetNode(org.graalvm.compiler.nodes.LoweredCallTargetNode) LabelRef(org.graalvm.compiler.lir.LabelRef)

Aggregations

LabelRef (org.graalvm.compiler.lir.LabelRef)8 Value (jdk.vm.ci.meta.Value)6 AllocatableValue (jdk.vm.ci.meta.AllocatableValue)5 JavaConstant (jdk.vm.ci.meta.JavaConstant)4 LIRKind (org.graalvm.compiler.core.common.LIRKind)4 CanonicalCondition (org.graalvm.compiler.core.common.calc.CanonicalCondition)4 Condition (org.graalvm.compiler.core.common.calc.Condition)4 ComplexMatchResult (org.graalvm.compiler.core.match.ComplexMatchResult)4 LIRFrameState (org.graalvm.compiler.lir.LIRFrameState)4 AMD64Kind (jdk.vm.ci.amd64.AMD64Kind)3 NodeLIRBuilder (org.graalvm.compiler.core.gen.NodeLIRBuilder)3 NodeMatchRules (org.graalvm.compiler.core.gen.NodeMatchRules)3 MatchRule (org.graalvm.compiler.core.match.MatchRule)3 AMD64 (jdk.vm.ci.amd64.AMD64)2 CPUFeature (jdk.vm.ci.amd64.AMD64.CPUFeature)2 TargetDescription (jdk.vm.ci.code.TargetDescription)2 PlatformKind (jdk.vm.ci.meta.PlatformKind)2 ValueKind (jdk.vm.ci.meta.ValueKind)2 ADD (org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64BinaryArithmetic.ADD)2 AND (org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64BinaryArithmetic.AND)2