Search in sources :

Example 81 with JavaConstant

use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.

the class IntegerAddExactNode method canonicalXconstant.

private static ConstantNode canonicalXconstant(ValueNode forX, ValueNode forY) {
    JavaConstant xConst = forX.asJavaConstant();
    JavaConstant yConst = forY.asJavaConstant();
    if (xConst != null && yConst != null) {
        assert xConst.getJavaKind() == yConst.getJavaKind();
        try {
            if (xConst.getJavaKind() == JavaKind.Int) {
                return ConstantNode.forInt(Math.addExact(xConst.asInt(), yConst.asInt()));
            } else {
                assert xConst.getJavaKind() == JavaKind.Long;
                return ConstantNode.forLong(Math.addExact(xConst.asLong(), yConst.asLong()));
            }
        } catch (ArithmeticException ex) {
        // The operation will result in an overflow exception, so do not canonicalize.
        }
    }
    return null;
}
Also used : JavaConstant(jdk.vm.ci.meta.JavaConstant)

Example 82 with JavaConstant

use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.

the class IntegerMulExactNode method canonicalXconstant.

private ValueNode canonicalXconstant(ValueNode forX, ValueNode forY) {
    JavaConstant xConst = forX.asJavaConstant();
    JavaConstant yConst = forY.asJavaConstant();
    assert xConst.getJavaKind() == yConst.getJavaKind();
    try {
        if (xConst.getJavaKind() == JavaKind.Int) {
            return ConstantNode.forInt(Math.multiplyExact(xConst.asInt(), yConst.asInt()));
        } else {
            assert xConst.getJavaKind() == JavaKind.Long;
            return ConstantNode.forLong(Math.multiplyExact(xConst.asLong(), yConst.asLong()));
        }
    } catch (ArithmeticException ex) {
    // The operation will result in an overflow exception, so do not canonicalize.
    }
    return this;
}
Also used : JavaConstant(jdk.vm.ci.meta.JavaConstant)

Example 83 with JavaConstant

use of jdk.vm.ci.meta.JavaConstant 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 84 with JavaConstant

use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.

the class AArch64AddressLoweringByUse method improve.

protected boolean improve(AArch64Kind kind, AArch64AddressNode ret) {
    AArch64Address.AddressingMode mode = ret.getAddressingMode();
    // if we have already set a displacement or set to base only mode then we are done
    if (isDisplacementMode(mode) || isBaseOnlyMode(mode)) {
        return false;
    }
    ValueNode base = ret.getBase();
    ValueNode index = ret.getIndex();
    // avoid a constant or null base if possible
    if (base == null) {
        ret.setBase(index);
        ret.setIndex(base);
        return true;
    }
    // as we ought not to see two JavaConstant values
    if (base.isJavaConstant() && base.asJavaConstant().getJavaKind().isNumericInteger() && index != null && !index.isJavaConstant()) {
        ret.setBase(index);
        ret.setIndex(base);
        return true;
    }
    // if the base is an add then move it up
    if (index == null && base instanceof AddNode) {
        AddNode add = (AddNode) base;
        ret.setBase(add.getX());
        ret.setIndex(add.getY());
        return true;
    }
    // we can try to fold a JavaConstant index into a displacement
    if (index != null && index.isJavaConstant()) {
        JavaConstant javaConstant = index.asJavaConstant();
        if (javaConstant.getJavaKind().isNumericInteger()) {
            long disp = javaConstant.asLong();
            mode = immediateMode(kind, disp);
            if (isDisplacementMode(mode)) {
                index = null;
                // we can fold this in as a displacement
                // but first see if we can pull up any additional
                // constants added into the base
                boolean tryNextBase = (base instanceof AddNode);
                while (tryNextBase) {
                    AddNode add = (AddNode) base;
                    tryNextBase = false;
                    ValueNode child = add.getX();
                    if (child.isJavaConstant() && child.asJavaConstant().getJavaKind().isNumericInteger()) {
                        long newDisp = disp + child.asJavaConstant().asLong();
                        AArch64Address.AddressingMode newMode = immediateMode(kind, newDisp);
                        if (newMode != AArch64Address.AddressingMode.REGISTER_OFFSET) {
                            disp = newDisp;
                            mode = newMode;
                            base = add.getY();
                            ret.setBase(base);
                            tryNextBase = (base instanceof AddNode);
                        }
                    } else {
                        child = add.getY();
                        if (child.isJavaConstant() && child.asJavaConstant().getJavaKind().isNumericInteger()) {
                            long newDisp = disp + child.asJavaConstant().asLong();
                            AArch64Address.AddressingMode newMode = immediateMode(kind, newDisp);
                            if (newMode != AArch64Address.AddressingMode.REGISTER_OFFSET) {
                                disp = newDisp;
                                mode = newMode;
                                base = add.getX();
                                ret.setBase(base);
                                tryNextBase = (base instanceof AddNode);
                            }
                        }
                    }
                }
                if (disp != 0) {
                    // ok now set the displacement in place of an index
                    ret.setIndex(null);
                    int scaleFactor = computeScaleFactor(kind, mode);
                    ret.setDisplacement(disp, scaleFactor, mode);
                } else {
                    // reset to base register only
                    ret.setIndex(null);
                    ret.setDisplacement(0, 1, AArch64Address.AddressingMode.BASE_REGISTER_ONLY);
                }
                return true;
            }
        }
    }
    // nope cannot improve this any more
    return false;
}
Also used : ValueNode(org.graalvm.compiler.nodes.ValueNode) JavaConstant(jdk.vm.ci.meta.JavaConstant) AArch64Address(org.graalvm.compiler.asm.aarch64.AArch64Address) AddNode(org.graalvm.compiler.nodes.calc.AddNode)

Example 85 with JavaConstant

use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.

the class SPARCOP3Op method emitOp3.

public static void emitOp3(SPARCMacroAssembler masm, Op3s op3, Value rs1, Value rs2, Value rd) {
    assert isRegister(rs1) : rs1;
    if (isJavaConstant(rs2)) {
        JavaConstant constant = asJavaConstant(rs2);
        long simm13;
        if (constant.isNull()) {
            simm13 = 0;
        } else {
            // Cast is safe, as isSimm13 assertion is done
            simm13 = constant.asLong();
        }
        assert isSimm13(constant);
        SPARCAssembler.Op3Op.emit(masm, op3, asRegister(rs1), (int) simm13, asRegister(rd));
    } else if (isRegister(rs2)) {
        SPARCAssembler.Op3Op.emit(masm, op3, asRegister(rs1), asRegister(rs2), asRegister(rd));
    } else {
        throw shouldNotReachHere(String.format("Got values a: %s b: %s", rs1, rs2));
    }
}
Also used : LIRValueUtil.asJavaConstant(org.graalvm.compiler.lir.LIRValueUtil.asJavaConstant) LIRValueUtil.isJavaConstant(org.graalvm.compiler.lir.LIRValueUtil.isJavaConstant) JavaConstant(jdk.vm.ci.meta.JavaConstant)

Aggregations

JavaConstant (jdk.vm.ci.meta.JavaConstant)122 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)33 ValueNode (org.graalvm.compiler.nodes.ValueNode)24 Test (org.junit.Test)19 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)17 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)15 Stamp (org.graalvm.compiler.core.common.type.Stamp)11 LIRValueUtil.asJavaConstant (org.graalvm.compiler.lir.LIRValueUtil.asJavaConstant)11 LIRValueUtil.isJavaConstant (org.graalvm.compiler.lir.LIRValueUtil.isJavaConstant)11 JavaKind (jdk.vm.ci.meta.JavaKind)10 Constant (jdk.vm.ci.meta.Constant)9 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)8 AllocatableValue (jdk.vm.ci.meta.AllocatableValue)7 Condition (org.graalvm.compiler.core.common.calc.Condition)7 IntegerStamp (org.graalvm.compiler.core.common.type.IntegerStamp)6 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)6 LogicNode (org.graalvm.compiler.nodes.LogicNode)6 FixedNode (org.graalvm.compiler.nodes.FixedNode)5 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)5 ReturnNode (org.graalvm.compiler.nodes.ReturnNode)5