- //
- MachineFunction& mcInfo = MachineFunction::get(&F);
- unsigned int staticStackSize = mcInfo.getStaticStackSize();
-
- if (staticStackSize < (unsigned) frameInfo.getMinStackFrameSize())
- staticStackSize = (unsigned) frameInfo.getMinStackFrameSize();
-
- if (unsigned padsz = (staticStackSize %
- (unsigned) frameInfo.getStackFrameSizeAlignment()))
- staticStackSize += frameInfo.getStackFrameSizeAlignment() - padsz;
-
- if (Target.getInstrInfo().constantFitsInImmedField(SAVE, staticStackSize))
- {
- M = new MachineInstr(SAVE);
- M->SetMachineOperandReg(0, Target.getRegInfo().getStackPointer());
- M->SetMachineOperandConst(1, MachineOperand::MO_SignExtendedImmed,
- - (int) staticStackSize);
- M->SetMachineOperandReg(2, Target.getRegInfo().getStackPointer());
- mvec.push_back(M);
- }
- else
- {
- // We have to put the stack size value into a register before SAVE.
- // Use register %g1 since it is volatile across calls. Note that the
- // local (%l) and in (%i) registers cannot be used before the SAVE!
- // Do this by creating a code sequence equivalent to:
- // SETSW -(stackSize), %g1
- int32_t C = - (int) staticStackSize;
- int uregNum = Target.getRegInfo().getUnifiedRegNum(
- Target.getRegInfo().getRegClassIDOfType(Type::IntTy),
- SparcIntRegClass::g1);
-
- M = new MachineInstr(SETHI);
- M->SetMachineOperandConst(0, MachineOperand::MO_SignExtendedImmed, C);
- M->SetMachineOperandReg(1, uregNum);
- M->setOperandHi32(0);
- mvec.push_back(M);
-
- M = new MachineInstr(OR);
- M->SetMachineOperandReg(0, uregNum);
- M->SetMachineOperandConst(1, MachineOperand::MO_SignExtendedImmed, C);
- M->SetMachineOperandReg(2, uregNum);
- M->setOperandLo32(1);
- mvec.push_back(M);
-
- M = new MachineInstr(SRA);
- M->SetMachineOperandReg(0, uregNum);
- M->SetMachineOperandConst(1, MachineOperand::MO_UnextendedImmed, 0);
- M->SetMachineOperandReg(2, uregNum);
- mvec.push_back(M);
-
- // Now generate the SAVE using the value in register %g1
- M = new MachineInstr(SAVE);
- M->SetMachineOperandReg(0, Target.getRegInfo().getStackPointer());
- M->SetMachineOperandReg(1, uregNum);
- M->SetMachineOperandReg(2, Target.getRegInfo().getStackPointer());
- mvec.push_back(M);
+ unsigned staticStackSize = getStaticStackSize (MF);
+ int32_t C = - (int) staticStackSize;
+ int SP = TM.getRegInfo()->getStackPointer();
+ if (TM.getInstrInfo()->constantFitsInImmedField(V9::SAVEi,staticStackSize)) {
+ mvec.push_back(BuildMI(V9::SAVEi, 3).addMReg(SP).addSImm(C)
+ .addMReg(SP, MachineOperand::Def));
+ } else {
+ // We have to put the stack size value into a register before SAVE.
+ // Use register %g1 since it is volatile across calls. Note that the
+ // local (%l) and in (%i) registers cannot be used before the SAVE!
+ // Do this by creating a code sequence equivalent to:
+ // SETSW -(stackSize), %g1
+ int uregNum = TM.getRegInfo()->getUnifiedRegNum(
+ TM.getRegInfo()->getRegClassIDOfType(Type::IntTy),
+ SparcV9IntRegClass::g1);
+
+ MachineInstr* M = BuildMI(V9::SETHI, 2).addSImm(C)
+ .addMReg(uregNum, MachineOperand::Def);
+ M->getOperand(0).markHi32();
+ mvec.push_back(M);
+
+ M = BuildMI(V9::ORi, 3).addMReg(uregNum).addSImm(C)
+ .addMReg(uregNum, MachineOperand::Def);
+ M->getOperand(1).markLo32();
+ mvec.push_back(M);
+
+ M = BuildMI(V9::SRAi5, 3).addMReg(uregNum).addZImm(0)
+ .addMReg(uregNum, MachineOperand::Def);
+ mvec.push_back(M);
+
+ // Now generate the SAVE using the value in register %g1
+ M = BuildMI(V9::SAVEr,3).addMReg(SP).addMReg(uregNum)
+ .addMReg(SP,MachineOperand::Def);
+ mvec.push_back(M);
+ }
+
+ // For varargs function bodies, insert instructions to copy incoming
+ // register arguments for the ... list to the stack.
+ // The first K=6 arguments are always received via int arg regs
+ // (%i0 ... %i5 if K=6) .
+ // By copying the varargs arguments to the stack, va_arg() then can
+ // simply assume that all vararg arguments are in an array on the stack.
+ if (MF.getFunction()->getFunctionType()->isVarArg()) {
+ int numFixedArgs = MF.getFunction()->getFunctionType()->getNumParams();
+ int numArgRegs = TM.getRegInfo()->getNumOfIntArgRegs();
+ if (numFixedArgs < numArgRegs) {
+ const TargetFrameInfo &FI = *TM.getFrameInfo();
+ int firstArgReg = TM.getRegInfo()->getUnifiedRegNum(
+ TM.getRegInfo()->getRegClassIDOfType(Type::IntTy),
+ SparcV9IntRegClass::i0);
+ int fpReg = SparcV9::i6;
+ int argSize = 8;
+ int firstArgOffset= SparcV9FrameInfo::FirstIncomingArgOffsetFromFP;
+ int nextArgOffset = firstArgOffset + numFixedArgs * argSize;
+
+ for (int i=numFixedArgs; i < numArgRegs; ++i) {
+ mvec.push_back(BuildMI(V9::STXi, 3).addMReg(firstArgReg+i).
+ addMReg(fpReg).addSImm(nextArgOffset));
+ nextArgOffset += argSize;
+ }