Search in sources :

Example 41 with Operand

use of org.jikesrvm.compilers.opt.ir.operand.Operand in project JikesRVM by JikesRVM.

the class CallingConvention method expandSysCall.

/**
 * Calling convention to implement calls to native (C) routines
 * using the Linux linkage conventions.<p>
 *
 * @param s the call instruction
 * @param ir the IR that contains the call
 */
public static void expandSysCall(Instruction s, IR ir) {
    Operand ip = Call.getClearAddress(s);
    // Allocate space to save non-volatiles.
    allocateSpaceForSysCall(ir);
    // Make sure we allocate enough space for the parameters to this call.
    int numberParams = Call.getNumberOfParams(s);
    int parameterWords = 0;
    for (int i = 0; i < numberParams; i++) {
        parameterWords++;
        Operand op = Call.getParam(s, i);
        parameterWords += op.getType().getStackWords();
    }
    // allocate space for each parameter,
    // plus one word on the stack to hold the address of the callee,
    // plus one word on stack for alignment of x64 syscalls
    int alignWords = VM.BuildFor64Addr ? 1 : 0;
    int neededWords = parameterWords + alignWords + 1;
    ir.stackManager.allocateParameterSpace(neededWords * WORDSIZE);
    // Convert to a SYSCALL instruction with a null method operand.
    Call.mutate0(s, SYSCALL, Call.getClearResult(s), ip, null);
}
Also used : MethodOperand(org.jikesrvm.compilers.opt.ir.operand.MethodOperand) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) Operand(org.jikesrvm.compilers.opt.ir.operand.Operand) IA32ConditionOperand(org.jikesrvm.compilers.opt.ir.operand.ia32.IA32ConditionOperand) StackLocationOperand(org.jikesrvm.compilers.opt.ir.operand.StackLocationOperand) BranchProfileOperand(org.jikesrvm.compilers.opt.ir.operand.BranchProfileOperand) LocationOperand(org.jikesrvm.compilers.opt.ir.operand.LocationOperand) MemoryOperand(org.jikesrvm.compilers.opt.ir.operand.MemoryOperand)

Example 42 with Operand

use of org.jikesrvm.compilers.opt.ir.operand.Operand in project JikesRVM by JikesRVM.

the class RewriteMemoryOperandsWithOversizedDisplacements method perform.

@Override
public void perform(IR ir) {
    for (Instruction inst = ir.firstInstructionInCodeOrder(); inst != null; inst = inst.nextInstructionInCodeOrder()) {
        for (int i = 0; i < inst.getNumberOfOperands(); i++) {
            Operand op = inst.getOperand(i);
            if (op instanceof MemoryOperand) {
                MemoryOperand mo = (MemoryOperand) op;
                disp64MemOperandConversion(ir, inst, mo);
            }
        }
    }
}
Also used : MemoryOperand(org.jikesrvm.compilers.opt.ir.operand.MemoryOperand) Operand(org.jikesrvm.compilers.opt.ir.operand.Operand) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) LocationOperand(org.jikesrvm.compilers.opt.ir.operand.LocationOperand) MemoryOperand(org.jikesrvm.compilers.opt.ir.operand.MemoryOperand) Instruction(org.jikesrvm.compilers.opt.ir.Instruction)

Example 43 with Operand

use of org.jikesrvm.compilers.opt.ir.operand.Operand 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));
    }
}
Also used : GenericPhysicalRegisterSet(org.jikesrvm.compilers.opt.ir.GenericPhysicalRegisterSet) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) Operand(org.jikesrvm.compilers.opt.ir.operand.Operand) IA32ConditionOperand(org.jikesrvm.compilers.opt.ir.operand.ia32.IA32ConditionOperand) StackLocationOperand(org.jikesrvm.compilers.opt.ir.operand.StackLocationOperand) TrapCodeOperand(org.jikesrvm.compilers.opt.ir.operand.TrapCodeOperand) MemoryOperand(org.jikesrvm.compilers.opt.ir.operand.MemoryOperand) StackLocationOperand(org.jikesrvm.compilers.opt.ir.operand.StackLocationOperand)

Example 44 with Operand

use of org.jikesrvm.compilers.opt.ir.operand.Operand in project JikesRVM by JikesRVM.

the class StackManager method isScratchFreeMove.

/**
 * @param s the instruction to check
 * @return {@code true} if and only if the instruction is a MOVE instruction
 *  that can be generated without resorting to scratch registers
 */
private boolean isScratchFreeMove(Instruction s) {
    if (s.operator() != IA32_MOV)
        return false;
    // registers in these move instructions.
    if (!FLOAT_ESP)
        return false;
    Operand result = MIR_Move.getResult(s);
    Operand value = MIR_Move.getValue(s);
    // memory operands.
    if (result.isMemory()) {
        MemoryOperand M = result.asMemory();
        if (hasSymbolicRegister(M))
            return false;
        // disable these too.  What's left?  WORDSIZE only.
        if (M.size != WORDSIZE)
            return false;
    }
    if (value.isMemory()) {
        MemoryOperand M = value.asMemory();
        if (hasSymbolicRegister(M))
            return false;
        // disable these too.  What's left?  WORDSIZE only.
        if (M.size != WORDSIZE)
            return false;
    }
    // If we get here, all is kosher.
    return true;
}
Also used : RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) Operand(org.jikesrvm.compilers.opt.ir.operand.Operand) IA32ConditionOperand(org.jikesrvm.compilers.opt.ir.operand.ia32.IA32ConditionOperand) StackLocationOperand(org.jikesrvm.compilers.opt.ir.operand.StackLocationOperand) TrapCodeOperand(org.jikesrvm.compilers.opt.ir.operand.TrapCodeOperand) MemoryOperand(org.jikesrvm.compilers.opt.ir.operand.MemoryOperand) MemoryOperand(org.jikesrvm.compilers.opt.ir.operand.MemoryOperand)

Example 45 with Operand

use of org.jikesrvm.compilers.opt.ir.operand.Operand in project JikesRVM by JikesRVM.

the class StackManager method rewriteStackLocations.

/**
 * Walks through the IR.  For each StackLocationOperand, replace the
 * operand with the appropriate MemoryOperand.
 */
private void rewriteStackLocations() {
    // ESP is initially WORDSIZE above where the framepointer is going to be.
    ESPOffset = getFrameFixedSize() + WORDSIZE;
    Register ESP = ((PhysicalRegisterSet) ir.regpool.getPhysicalRegisterSet()).getESP();
    boolean seenReturn = false;
    for (Enumeration<Instruction> e = ir.forwardInstrEnumerator(); e.hasMoreElements(); ) {
        Instruction s = e.nextElement();
        if (s.isReturn()) {
            seenReturn = true;
            continue;
        }
        if (s.isBranch()) {
            // restore ESP to home location at end of basic block.
            moveESPBefore(s, 0);
            continue;
        }
        if (s.operator() == BBEND) {
            if (seenReturn) {
                // at a return ESP will be at FrameFixedSize,
                seenReturn = false;
                ESPOffset = 0;
            } else {
                moveESPBefore(s, 0);
            }
            continue;
        }
        if (s.operator() == ADVISE_ESP) {
            ESPOffset = MIR_UnaryNoRes.getVal(s).asIntConstant().value;
            continue;
        }
        if (s.operator() == REQUIRE_ESP) {
            // ESP is required to be at the given offset from the bottom of the frame
            moveESPBefore(s, MIR_UnaryNoRes.getVal(s).asIntConstant().value);
            continue;
        }
        if (s.operator() == YIELDPOINT_PROLOGUE || s.operator() == YIELDPOINT_BACKEDGE || s.operator() == YIELDPOINT_EPILOGUE) {
            moveESPBefore(s, 0);
            continue;
        }
        if (s.operator() == IA32_MOV) {
            rewriteMoveInstruction(s);
        }
        // stacklocation and memory operands.
        if (s.operator() == IA32_POP) {
            ESPOffset += WORDSIZE;
        }
        for (Enumeration<Operand> ops = s.getOperands(); ops.hasMoreElements(); ) {
            Operand op = ops.nextElement();
            if (op instanceof StackLocationOperand) {
                StackLocationOperand sop = (StackLocationOperand) op;
                int offset = sop.getOffset();
                if (sop.isFromTop()) {
                    offset = FPOffset2SPOffset(offset);
                }
                offset -= ESPOffset;
                byte size = sop.getSize();
                MemoryOperand M = MemoryOperand.BD(new RegisterOperand(ESP, PRIMITIVE_TYPE_FOR_WORD), Offset.fromIntSignExtend(offset), size, null, null);
                s.replaceOperand(op, M);
            } else if (op instanceof MemoryOperand) {
                MemoryOperand M = op.asMemory();
                if ((M.base != null && M.base.getRegister() == ESP) || (M.index != null && M.index.getRegister() == ESP)) {
                    M.disp = M.disp.minus(ESPOffset);
                }
            }
        }
        // stacklocation and memory operands.
        if (s.operator() == IA32_PUSH) {
            ESPOffset -= WORDSIZE;
        }
    }
}
Also used : RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) Register(org.jikesrvm.compilers.opt.ir.Register) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) Operand(org.jikesrvm.compilers.opt.ir.operand.Operand) IA32ConditionOperand(org.jikesrvm.compilers.opt.ir.operand.ia32.IA32ConditionOperand) StackLocationOperand(org.jikesrvm.compilers.opt.ir.operand.StackLocationOperand) TrapCodeOperand(org.jikesrvm.compilers.opt.ir.operand.TrapCodeOperand) MemoryOperand(org.jikesrvm.compilers.opt.ir.operand.MemoryOperand) MemoryOperand(org.jikesrvm.compilers.opt.ir.operand.MemoryOperand) GenericPhysicalRegisterSet(org.jikesrvm.compilers.opt.ir.GenericPhysicalRegisterSet) PhysicalRegisterSet(org.jikesrvm.compilers.opt.ir.ia32.PhysicalRegisterSet) Instruction(org.jikesrvm.compilers.opt.ir.Instruction) StackLocationOperand(org.jikesrvm.compilers.opt.ir.operand.StackLocationOperand)

Aggregations

Operand (org.jikesrvm.compilers.opt.ir.operand.Operand)355 RegisterOperand (org.jikesrvm.compilers.opt.ir.operand.RegisterOperand)328 IntConstantOperand (org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand)242 ConditionOperand (org.jikesrvm.compilers.opt.ir.operand.ConditionOperand)217 BranchProfileOperand (org.jikesrvm.compilers.opt.ir.operand.BranchProfileOperand)212 TrueGuardOperand (org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand)210 MethodOperand (org.jikesrvm.compilers.opt.ir.operand.MethodOperand)207 TrapCodeOperand (org.jikesrvm.compilers.opt.ir.operand.TrapCodeOperand)185 LongConstantOperand (org.jikesrvm.compilers.opt.ir.operand.LongConstantOperand)174 ConstantOperand (org.jikesrvm.compilers.opt.ir.operand.ConstantOperand)165 TypeOperand (org.jikesrvm.compilers.opt.ir.operand.TypeOperand)153 Instruction (org.jikesrvm.compilers.opt.ir.Instruction)144 AddressConstantOperand (org.jikesrvm.compilers.opt.ir.operand.AddressConstantOperand)143 NullConstantOperand (org.jikesrvm.compilers.opt.ir.operand.NullConstantOperand)141 ObjectConstantOperand (org.jikesrvm.compilers.opt.ir.operand.ObjectConstantOperand)128 TIBConstantOperand (org.jikesrvm.compilers.opt.ir.operand.TIBConstantOperand)121 UnreachableOperand (org.jikesrvm.compilers.opt.ir.operand.UnreachableOperand)117 LocationOperand (org.jikesrvm.compilers.opt.ir.operand.LocationOperand)102 CodeConstantOperand (org.jikesrvm.compilers.opt.ir.operand.CodeConstantOperand)98 Register (org.jikesrvm.compilers.opt.ir.Register)82