use of org.jikesrvm.compilers.opt.ir.operand.StackLocationOperand in project JikesRVM by JikesRVM.
the class AssemblerBase method isQuad.
/**
* Does the given instruction operate upon quad-sized data
* <em>for the purposes of assembling the instruction</em>?
* The opt compiler does not represent the size of register data, so
* it is necessary to determine whether to emit a quad instruction.
* As described above, this method is only concerned with quad data
* that changes the instruction. For example, this method will return
* {@code false} for {@code FSTP}. {@code FSTP} operates on quad-data
* but the instruction's operation is the same for 32-bit and 64-bit
* mode, so it is not a quad instruction for the purposes of this method.
* <p>
* This method typically looks at the memory operand, if any, and
* checks whether that is a byte. This method also recognizes
* the operator convention that __q on the end of the operator
* name means operate upon quad data. Moreover, it looks at data types
* for x64.
*
* @param inst the instruction being queried
* @return {@code true} if instruction operates upon quad data <b>AND</b>
* is treated as a quad instruction for the purpose of assembling the
* machine code
*/
boolean isQuad(Instruction inst) {
for (Operator opr : quadSizeOperators) {
if (opr == inst.operator()) {
return true;
}
}
if (VM.BuildFor32Addr) {
for (int i = 0; i < inst.getNumberOfOperands(); i++) {
Operand op = inst.getOperand(i);
if (op instanceof MemoryOperand) {
return ((MemoryOperand) op).size == 8;
}
}
} else {
// 64-bit
for (int i = 0; i < inst.getNumberOfOperands(); i++) {
Operand op = inst.getOperand(i);
if (op == null) {
// The operand may only be null for a few cases.
if (VM.VerifyAssertions) {
// Return has 2 return operands on IA32 because it
// must be able to return a 64-bit value. On x64, only
// one of the operands is needed, the other one is null.
boolean isReturn = MIR_Return.conforms(inst);
if (isReturn) {
VM._assert(i == MIR_Return.indexOfVal2(inst));
}
// Guards may be null for divides
boolean isDivide = MIR_Divide.conforms(inst);
if (isDivide) {
VM._assert(i == MIR_Divide.indexOfGuard(inst));
}
// For all other cases, all operands must be non null
String msg = inst.toString();
VM._assert(isReturn || isDivide, msg);
}
continue;
}
if (op.isLong() || op.isRef() || op.isAddress()) {
return true;
}
boolean quadMemOp = false;
if (op instanceof MemoryOperand) {
quadMemOp = op.asMemory().size == 8;
} else if (op instanceof StackLocationOperand) {
quadMemOp = op.asStackLocation().getSize() == 8;
}
// even if this one won't
if (quadMemOp) {
return true;
}
}
}
return false;
}
use of org.jikesrvm.compilers.opt.ir.operand.StackLocationOperand in project JikesRVM by JikesRVM.
the class CallingConvention method expandPrologue.
private static void expandPrologue(IR ir) {
boolean useDU = ir.options.getOptLevel() >= 1;
if (useDU) {
// set up register lists for dead code elimination.
DefUse.computeDU(ir);
}
Instruction p = ir.firstInstructionInCodeOrder().nextInstructionInCodeOrder();
if (VM.VerifyAssertions)
VM._assert(p.operator() == IR_PROLOGUE);
Instruction start = p.nextInstructionInCodeOrder();
PhysicalRegisterSet phys = ir.regpool.getPhysicalRegisterSet().asIA32();
int gprIndex = 0;
int fprIndex = 0;
int paramByteOffset = ir.incomingParameterBytes() + 2 * WORDSIZE;
// count the number of FPR params in a pre-pass
int FPRRegisterParams = countFPRParamsInPrologue(p);
FPRRegisterParams = Math.min(FPRRegisterParams, PhysicalRegisterSet.getNumberOfFPRParams());
ir.MIRInfo.fpStackHeight = Math.max(ir.MIRInfo.fpStackHeight, FPRRegisterParams);
// deal with each parameter
for (Enumeration<Operand> e = p.getDefs(); e.hasMoreElements(); ) {
RegisterOperand symbOp = (RegisterOperand) e.nextElement();
TypeReference rType = symbOp.getType();
if (rType.isFloatingPointType()) {
int size;
if (rType.isFloatType()) {
size = BYTES_IN_FLOAT;
paramByteOffset -= WORDSIZE;
} else {
size = BYTES_IN_DOUBLE;
paramByteOffset -= 2 * WORDSIZE;
}
// if optimizing, only define the register if it has uses
if (!useDU || symbOp.getRegister().useList != null) {
if (fprIndex < PhysicalRegisterSet.getNumberOfFPRParams()) {
// the 2nd goes in F(k-2), etc...
if (SSE2_FULL) {
Register param = phys.getFPRParam(fprIndex);
if (rType.isFloatType()) {
start.insertBefore(MIR_Move.create(IA32_MOVSS, symbOp.copyRO(), F(param)));
} else {
start.insertBefore(MIR_Move.create(IA32_MOVSD, symbOp.copyRO(), D(param)));
}
} else {
Register param = phys.getFPRParam(FPRRegisterParams - fprIndex - 1);
start.insertBefore(MIR_Move.create(IA32_FMOV, symbOp.copyRO(), D(param)));
}
} else {
Operand M = new StackLocationOperand(true, paramByteOffset, size);
if (SSE2_FULL) {
if (rType.isFloatType()) {
start.insertBefore(MIR_Move.create(IA32_MOVSS, symbOp.copyRO(), M));
} else {
start.insertBefore(MIR_Move.create(IA32_MOVSD, symbOp.copyRO(), M));
}
} else {
start.insertBefore(MIR_Move.create(IA32_FMOV, symbOp.copyRO(), M));
}
}
}
fprIndex++;
} else {
// if optimizing, only define the register if it has uses
paramByteOffset -= WORDSIZE;
if (paramIsNativeLongOn64Bit(symbOp)) {
paramByteOffset -= WORDSIZE;
}
if (!useDU || symbOp.getRegister().useList != null) {
// t is object, 1/2 of a long, int, short, char, byte, or boolean
if (gprIndex < PhysicalRegisterSet.getNumberOfGPRParams()) {
// to give the register allocator more freedom, we
// insert two move instructions to get the physical into
// the symbolic. First a move from the physical to a fresh temp
// before start and second a move from the temp to the
// 'real' parameter symbolic after start.
RegisterOperand tmp = ir.regpool.makeTemp(rType);
Register param = phys.getGPRParam(gprIndex);
RegisterOperand pOp = new RegisterOperand(param, rType);
start.insertBefore(PhysicalRegisterTools.makeMoveInstruction(tmp, pOp));
Instruction m2 = PhysicalRegisterTools.makeMoveInstruction(symbOp.copyRO(), tmp.copyD2U());
start.insertBefore(m2);
start = m2;
} else {
int stackLocSize = WORDSIZE;
if (VM.BuildFor64Addr && rType.getMemoryBytes() <= BYTES_IN_INT) {
stackLocSize = BYTES_IN_INT;
}
Operand M = new StackLocationOperand(true, paramByteOffset, stackLocSize);
start.insertBefore(MIR_Move.create(IA32_MOV, symbOp.copyRO(), M));
}
}
gprIndex++;
}
}
if (VM.VerifyAssertions && paramByteOffset != 2 * WORDSIZE) {
String msg = "pb = " + paramByteOffset + "; expected " + 2 * WORDSIZE;
VM._assert(VM.NOT_REACHED, msg);
}
removeDefsFromPrologue(p);
}
use of org.jikesrvm.compilers.opt.ir.operand.StackLocationOperand in project JikesRVM by JikesRVM.
the class CallingConvention method expandParametersToSysCall.
/**
* Explicitly copy parameters to a system call into the appropriate physical
* registers as defined by the calling convention. Note that for a system
* call (ie., a call to C), the order of parameters on the stack is
* <em> reversed </em> compared to the normal RVM calling convention<p>
*
* Note: Assumes that ESP points to the word before the slot where the
* first parameter should be stored.<p>
*
* TODO: much of this code is exactly the same as in expandParametersToCall().
* factor out the common code.
*
* @param call the call instruction
* @param ir the IR that contains the call
* @return the number of bytes necessary to hold the parameters
*/
private static int expandParametersToSysCall(Instruction call, IR ir) {
int nGPRParams = 0;
int nFPRParams = 0;
int parameterBytes = 0;
int numParams = MIR_Call.getNumberOfParams(call);
if (VM.BuildFor32Addr) {
// NOTE: All params to syscall are passed on the stack!
for (int i = numParams - 1; i >= 0; i--) {
Operand param = MIR_Call.getClearParam(call, i);
MIR_Call.setParam(call, i, null);
TypeReference paramType = param.getType();
if (paramType.isFloatingPointType()) {
nFPRParams++;
int size;
if (paramType.isFloatType()) {
size = BYTES_IN_FLOAT;
parameterBytes -= WORDSIZE;
} else {
size = BYTES_IN_DOUBLE;
parameterBytes -= 2 * WORDSIZE;
}
Operand M = new StackLocationOperand(false, parameterBytes, size);
if (SSE2_FULL) {
if (paramType.isFloatType()) {
call.insertBefore(MIR_Move.create(IA32_MOVSS, M, param));
} else {
call.insertBefore(MIR_Move.create(IA32_MOVSD, M, param));
}
} else {
call.insertBefore(MIR_Move.create(IA32_FMOV, M, param));
}
} else {
nGPRParams++;
parameterBytes -= WORDSIZE;
call.insertBefore(MIR_UnaryNoRes.create(REQUIRE_ESP, IC(parameterBytes + WORDSIZE)));
call.insertBefore(MIR_UnaryNoRes.create(IA32_PUSH, param));
}
}
return parameterBytes;
} else {
if (VM.VerifyAssertions)
VM._assert(SSE2_FULL, "x64 builds must have SSE2_FULL enabled");
PhysicalRegisterSet phys = ir.regpool.getPhysicalRegisterSet().asIA32();
// count the number FPR parameters in a pre-pass
int FPRRegisterParams = countFPRParams(call);
FPRRegisterParams = Math.min(FPRRegisterParams, PhysicalRegisterSet.getNumberOfNativeFPRParams());
// offset, in bytes, from the SP, for the next parameter slot on the
// stack
parameterBytes = -2 * WORDSIZE;
RegisterOperand fpCount = new RegisterOperand(phys.getEAX(), TypeReference.Int);
// Save count of vector parameters (= XMM) in EAX as defined by
// the ABI for varargs convention
call.insertBefore(MIR_Move.create(IA32_MOV, fpCount, IC(FPRRegisterParams)));
// Save volatiles to non-volatiles that are currently not used
call.insertBefore(MIR_Move.create(IA32_MOV, new RegisterOperand(phys.getGPR(R14), TypeReference.Long), new RegisterOperand(phys.getESI(), TypeReference.Long)));
call.insertBefore(MIR_Move.create(IA32_MOV, new RegisterOperand(phys.getGPR(R13), TypeReference.Long), new RegisterOperand(phys.getEDI(), TypeReference.Long)));
// Restore volatiles from non-volatiles
call.insertAfter(MIR_Move.create(IA32_MOV, new RegisterOperand(phys.getESI(), TypeReference.Long), new RegisterOperand(phys.getGPR(R14), TypeReference.Long)));
call.insertAfter(MIR_Move.create(IA32_MOV, new RegisterOperand(phys.getEDI(), TypeReference.Long), new RegisterOperand(phys.getGPR(R13), TypeReference.Long)));
if (VM.BuildFor64Addr) {
// Add a marker instruction. When processing x64 syscalls, the block of the syscall
// needs to be split up to copy the code for the call. Copying has to occur
// to be able to ensure stack alignment for the x64 ABI. This instruction
// marks the border for the copy: everything before this instruction isn't duplicated.
call.insertBefore(MIR_UnaryNoRes.create(REQUIRE_ESP, IC(MARKER)));
}
// Require ESP to be at bottom of frame before a call,
call.insertBefore(MIR_UnaryNoRes.create(REQUIRE_ESP, IC(0)));
// Determine if a parameter is in a register or not
boolean[] inRegister = new boolean[numParams];
nFPRParams = 0;
nGPRParams = 0;
for (int i = 0; i < numParams; i++) {
Operand param = MIR_Call.getParam(call, i);
TypeReference paramType = param.getType();
if (paramType.isFloatingPointType()) {
nFPRParams++;
inRegister[i] = nFPRParams <= PhysicalRegisterSet.getNumberOfNativeFPRParams();
} else {
nGPRParams++;
inRegister[i] = nGPRParams <= PhysicalRegisterSet.getNumberOfNativeGPRParams();
}
}
// Walk over non-register parameters from right-to-left and assign stack slots
int[] stackSlot = new int[numParams];
for (int i = numParams - 1; i >= 0; i--) {
if (!inRegister[i]) {
parameterBytes -= BYTES_IN_STACKSLOT;
stackSlot[i] = parameterBytes;
}
}
// Pass stack slot parameters from right-to-left
for (int i = numParams - 1; i >= 0; i--) {
if (!inRegister[i]) {
Operand param = MIR_Call.getClearParam(call, i);
TypeReference paramType = param.getType();
if (paramType.isFloatingPointType()) {
// pass the FP parameter on the stack
Operand M = new StackLocationOperand(false, stackSlot[i], BYTES_IN_STACKSLOT);
if (paramType.isFloatType()) {
call.insertBefore(MIR_Move.create(IA32_MOVSS, M, param));
} else {
call.insertBefore(MIR_Move.create(IA32_MOVSD, M, param));
}
} else {
// Write the parameter into the appropriate stack frame location.
call.insertBefore(MIR_UnaryNoRes.create(REQUIRE_ESP, IC(stackSlot[i] + BYTES_IN_STACKSLOT)));
call.insertBefore(MIR_UnaryNoRes.create(IA32_PUSH, param));
}
}
}
// Pass register parameters from left-to-right
int nParamsInRegisters = 0;
nFPRParams = 0;
nGPRParams = 0;
for (int i = 0; i < numParams; i++) {
if (inRegister[i]) {
Operand param = MIR_Call.getClearParam(call, i);
TypeReference paramType = param.getType();
if (paramType.isFloatingPointType()) {
// Pass the parameter in a register.
RegisterOperand real = new RegisterOperand(phys.getNativeFPRParam(nFPRParams), paramType);
nFPRParams++;
if (paramType.isFloatType()) {
call.insertBefore(MIR_Move.create(IA32_MOVSS, real, param));
} else {
call.insertBefore(MIR_Move.create(IA32_MOVSD, real, param));
}
// Record that the call now has a use of the real register.
MIR_Call.setParam(call, nParamsInRegisters++, real.copy());
} else {
Register phy = phys.getNativeGPRParam(nGPRParams);
nGPRParams++;
RegisterOperand real = new RegisterOperand(phy, paramType);
call.insertBefore(MIR_Move.create(IA32_MOV, real, param));
// Record that the call now has a use of the real register.
MIR_Call.setParam(call, nParamsInRegisters++, real.copy());
}
}
}
return parameterBytes;
}
}
use of org.jikesrvm.compilers.opt.ir.operand.StackLocationOperand in project JikesRVM by JikesRVM.
the class CallingConvention method saveNonvolatilesBeforeSysCall.
/**
* Save all nonvolatile registers before a syscall.
* We do this in case the sys call does not respect our
* register conventions.<p>
*
* We save/restore all nonvolatiles and the PR, whether
* or not this routine uses them. This may be a tad inefficient, but if
* you're making a system call, you probably don't care.
*
* @param call the sys call
* @param ir the IR that contains the call
*/
static void saveNonvolatilesBeforeSysCall(Instruction call, IR ir) {
GenericPhysicalRegisterSet phys = ir.regpool.getPhysicalRegisterSet();
StackManager sm = (StackManager) ir.stackManager;
// get the offset into the stack frame of where to stash the first
// nonvolatile for this case.
int location = sm.getOffsetForSysCall();
// save each non-volatile
for (Enumeration<Register> e = phys.enumerateNonvolatileGPRs(); e.hasMoreElements(); ) {
Register r = e.nextElement();
Operand M = new StackLocationOperand(true, -location, (byte) WORDSIZE);
call.insertBefore(MIR_Move.create(IA32_MOV, M, new RegisterOperand(r, wordType)));
location += WORDSIZE;
}
// save the thread register
Operand M = new StackLocationOperand(true, -location, (byte) WORDSIZE);
call.insertBefore(MIR_Move.create(IA32_MOV, M, ir.regpool.makeTROp()));
// save the JTOC, if present
if (JTOC_REGISTER != null) {
location += WORDSIZE;
Operand jtocSave = new StackLocationOperand(true, -location, (byte) WORDSIZE);
call.insertBefore(MIR_Move.create(IA32_MOV, jtocSave, ir.regpool.makeTocOp()));
}
}
use of org.jikesrvm.compilers.opt.ir.operand.StackLocationOperand in project JikesRVM by JikesRVM.
the class StackManager method saveFloatingPointState.
/**
* Insert code into the prologue to save the floating point state.
*
* @param inst the first instruction after the prologue.
*/
private void saveFloatingPointState(Instruction inst) {
if (SSE2_FULL) {
GenericPhysicalRegisterSet phys = ir.regpool.getPhysicalRegisterSet();
for (int i = 0; i < 8; i++) {
inst.insertBefore(MIR_Move.create(IA32_MOVQ, new StackLocationOperand(true, -fsaveLocation + (i * BYTES_IN_DOUBLE), BYTES_IN_DOUBLE), new RegisterOperand(phys.getFPR(i), TypeReference.Double)));
}
} else {
Operand M = new StackLocationOperand(true, -fsaveLocation, 4);
inst.insertBefore(MIR_FSave.create(IA32_FNSAVE, M));
}
}
Aggregations