package org.graalvm.compiler.hotspot.amd64;
import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.REG;
import static jdk.vm.ci.amd64.AMD64.rsp;
import static jdk.vm.ci.code.ValueUtil.asRegister;
import org.graalvm.compiler.asm.amd64.AMD64Address;
import org.graalvm.compiler.asm.amd64.AMD64MacroAssembler;
import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig;
import org.graalvm.compiler.lir.LIRInstructionClass;
import org.graalvm.compiler.lir.Opcode;
import org.graalvm.compiler.lir.amd64.AMD64LIRInstruction;
import org.graalvm.compiler.lir.asm.CompilationResultBuilder;
import jdk.vm.ci.code.Register;
import jdk.vm.ci.meta.AllocatableValue;
@Opcode("PUSH_INTERPRETER_FRAME")
final class AMD64HotSpotPushInterpreterFrameOp extends AMD64LIRInstruction {
public static final LIRInstructionClass<AMD64HotSpotPushInterpreterFrameOp> TYPE = LIRInstructionClass.create(AMD64HotSpotPushInterpreterFrameOp.class);
@Alive(REG) AllocatableValue frameSize;
@Alive(REG) AllocatableValue framePc;
@Alive(REG) AllocatableValue senderSp;
@Alive(REG) AllocatableValue initialInfo;
private final GraalHotSpotVMConfig config;
AMD64HotSpotPushInterpreterFrameOp(AllocatableValue frameSize, AllocatableValue framePc, AllocatableValue senderSp, AllocatableValue initialInfo, GraalHotSpotVMConfig config) {
super(TYPE);
this.frameSize = frameSize;
this.framePc = framePc;
this.senderSp = senderSp;
this.initialInfo = initialInfo;
this.config = config;
}
@Override
public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) {
final Register frameSizeRegister = asRegister(frameSize);
final Register framePcRegister = asRegister(framePc);
final Register senderSpRegister = asRegister(senderSp);
final Register initialInfoRegister = asRegister(initialInfo);
final int wordSize = 8;
masm.subq(frameSizeRegister, 2 * wordSize);
masm.push(framePcRegister);
masm.push(initialInfoRegister);
masm.movq(initialInfoRegister, rsp);
masm.subq(rsp, frameSizeRegister);
masm.movptr(new AMD64Address(initialInfoRegister, config.frameInterpreterFrameLastSpOffset * wordSize), 0);
masm.movq(new AMD64Address(initialInfoRegister, config.frameInterpreterFrameSenderSpOffset * wordSize), senderSpRegister);
}
}