Search in sources :

Example 1 with AMD64MIOp

use of org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64MIOp in project graal by oracle.

the class AMD64ArithmeticLIRGenerator method emitStoreConst.

protected void emitStoreConst(AMD64Kind kind, AMD64AddressValue address, ConstantValue value, LIRFrameState state) {
    Constant c = value.getConstant();
    if (JavaConstant.isNull(c)) {
        assert kind == AMD64Kind.DWORD || kind == AMD64Kind.QWORD;
        OperandSize size = kind == AMD64Kind.DWORD ? DWORD : QWORD;
        getLIRGen().append(new AMD64BinaryConsumer.MemoryConstOp(AMD64MIOp.MOV, size, address, 0, state));
        return;
    } else if (c instanceof VMConstant) {
        // only 32-bit constants can be patched
        if (kind == AMD64Kind.DWORD) {
            if (getLIRGen().target().inlineObjects || !(c instanceof JavaConstant)) {
                // if c is a JavaConstant, it's an oop, otherwise it's a metaspace constant
                assert !(c instanceof JavaConstant) || ((JavaConstant) c).getJavaKind() == JavaKind.Object;
                getLIRGen().append(new AMD64BinaryConsumer.MemoryVMConstOp(AMD64MIOp.MOV, address, (VMConstant) c, state));
                return;
            }
        }
    } else {
        JavaConstant jc = (JavaConstant) c;
        assert jc.getJavaKind().isPrimitive();
        AMD64MIOp op = AMD64MIOp.MOV;
        OperandSize size;
        long imm;
        switch(kind) {
            case BYTE:
                op = AMD64MIOp.MOVB;
                size = BYTE;
                imm = jc.asInt();
                break;
            case WORD:
                size = WORD;
                imm = jc.asInt();
                break;
            case DWORD:
                size = DWORD;
                imm = jc.asInt();
                break;
            case QWORD:
                size = QWORD;
                imm = jc.asLong();
                break;
            case SINGLE:
                size = DWORD;
                imm = Float.floatToRawIntBits(jc.asFloat());
                break;
            case DOUBLE:
                size = QWORD;
                imm = Double.doubleToRawLongBits(jc.asDouble());
                break;
            default:
                throw GraalError.shouldNotReachHere("unexpected kind " + kind);
        }
        if (NumUtil.isInt(imm)) {
            getLIRGen().append(new AMD64BinaryConsumer.MemoryConstOp(op, size, address, (int) imm, state));
            return;
        }
    }
    // fallback: load, then store
    emitStore(kind, address, getLIRGen().asAllocatable(value), state);
}
Also used : Constant(jdk.vm.ci.meta.Constant) JavaConstant(jdk.vm.ci.meta.JavaConstant) LIRValueUtil.asJavaConstant(org.graalvm.compiler.lir.LIRValueUtil.asJavaConstant) LIRValueUtil.isJavaConstant(org.graalvm.compiler.lir.LIRValueUtil.isJavaConstant) VMConstant(jdk.vm.ci.meta.VMConstant) VMConstant(jdk.vm.ci.meta.VMConstant) JavaConstant(jdk.vm.ci.meta.JavaConstant) LIRValueUtil.asJavaConstant(org.graalvm.compiler.lir.LIRValueUtil.asJavaConstant) LIRValueUtil.isJavaConstant(org.graalvm.compiler.lir.LIRValueUtil.isJavaConstant) AMD64MIOp(org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64MIOp) AMD64BinaryConsumer(org.graalvm.compiler.lir.amd64.AMD64BinaryConsumer) OperandSize(org.graalvm.compiler.asm.amd64.AMD64Assembler.OperandSize)

Aggregations

Constant (jdk.vm.ci.meta.Constant)1 JavaConstant (jdk.vm.ci.meta.JavaConstant)1 VMConstant (jdk.vm.ci.meta.VMConstant)1 AMD64MIOp (org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64MIOp)1 OperandSize (org.graalvm.compiler.asm.amd64.AMD64Assembler.OperandSize)1 LIRValueUtil.asJavaConstant (org.graalvm.compiler.lir.LIRValueUtil.asJavaConstant)1 LIRValueUtil.isJavaConstant (org.graalvm.compiler.lir.LIRValueUtil.isJavaConstant)1 AMD64BinaryConsumer (org.graalvm.compiler.lir.amd64.AMD64BinaryConsumer)1