llvm.org GIT mirror llvm / acdfa44
bugfix: SP wasn't updated for varargs when frame pointer was eliminated. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34537 91177308-0d34-0410-b5e6-96231b3b80d8 Lauro Ramos Venancio 13 years ago
2 changed file(s) with 70 addition(s) and 70 deletion(s). Raw diff Collapse all Expand all
10851085 // belongs to which callee-save spill areas.
10861086 unsigned GPRCS1Size = 0, GPRCS2Size = 0, DPRCSSize = 0;
10871087 int FramePtrSpillFI = 0;
1088
1089 if (VARegSaveSize)
1090 emitSPUpdate(MBB, MBBI, -VARegSaveSize, isThumb, TII);
1091
10881092 if (!AFI->hasStackFrame()) {
10891093 if (NumBytes != 0)
10901094 emitSPUpdate(MBB, MBBI, -NumBytes, isThumb, TII);
10911095 return;
10921096 }
1093
1094 if (VARegSaveSize)
1095 emitSPUpdate(MBB, MBBI, -VARegSaveSize, isThumb, TII);
10961097
10971098 for (unsigned i = 0, e = CSI.size(); i != e; ++i) {
10981099 unsigned Reg = CSI[i].getReg();
12071208 if (!AFI->hasStackFrame()) {
12081209 if (NumBytes != 0)
12091210 emitSPUpdate(MBB, MBBI, NumBytes, isThumb, TII);
1210 return;
1211 }
1212
1213 // Unwind MBBI to point to first LDR / FLDD.
1214 const unsigned *CSRegs = getCalleeSavedRegs();
1215 if (MBBI != MBB.begin()) {
1216 do
1217 --MBBI;
1218 while (MBBI != MBB.begin() && isCSRestore(MBBI, CSRegs));
1219 if (!isCSRestore(MBBI, CSRegs))
1220 ++MBBI;
1221 }
1222
1223 // Move SP to start of FP callee save spill area.
1224 NumBytes -= (AFI->getGPRCalleeSavedArea1Size() +
1225 AFI->getGPRCalleeSavedArea2Size() +
1226 AFI->getDPRCalleeSavedAreaSize());
1227 if (isThumb) {
1228 if (hasFP(MF)) {
1229 NumBytes = AFI->getFramePtrSpillOffset() - NumBytes;
1230 // Reset SP based on frame pointer only if the stack frame extends beyond
1231 // frame pointer stack slot or target is ELF and the function has FP.
1232 if (NumBytes)
1233 emitThumbRegPlusImmediate(MBB, MBBI, ARM::SP, FramePtr, -NumBytes, TII);
1234 else
1235 BuildMI(MBB, MBBI, TII.get(ARM::tMOVrr), ARM::SP).addReg(FramePtr);
1211 } else {
1212 // Unwind MBBI to point to first LDR / FLDD.
1213 const unsigned *CSRegs = getCalleeSavedRegs();
1214 if (MBBI != MBB.begin()) {
1215 do
1216 --MBBI;
1217 while (MBBI != MBB.begin() && isCSRestore(MBBI, CSRegs));
1218 if (!isCSRestore(MBBI, CSRegs))
1219 ++MBBI;
1220 }
1221
1222 // Move SP to start of FP callee save spill area.
1223 NumBytes -= (AFI->getGPRCalleeSavedArea1Size() +
1224 AFI->getGPRCalleeSavedArea2Size() +
1225 AFI->getDPRCalleeSavedAreaSize());
1226 if (isThumb) {
1227 if (hasFP(MF)) {
1228 NumBytes = AFI->getFramePtrSpillOffset() - NumBytes;
1229 // Reset SP based on frame pointer only if the stack frame extends beyond
1230 // frame pointer stack slot or target is ELF and the function has FP.
1231 if (NumBytes)
1232 emitThumbRegPlusImmediate(MBB, MBBI, ARM::SP, FramePtr, -NumBytes, TII);
1233 else
1234 BuildMI(MBB, MBBI, TII.get(ARM::tMOVrr), ARM::SP).addReg(FramePtr);
1235 } else {
1236 if (MBBI->getOpcode() == ARM::tBX_RET &&
1237 &MBB.front() != MBBI &&
1238 prior(MBBI)->getOpcode() == ARM::tPOP) {
1239 MachineBasicBlock::iterator PMBBI = prior(MBBI);
1240 emitSPUpdate(MBB, PMBBI, NumBytes, isThumb, TII);
1241 } else
1242 emitSPUpdate(MBB, MBBI, NumBytes, isThumb, TII);
1243 }
12361244 } else {
1237 if (MBBI->getOpcode() == ARM::tBX_RET &&
1238 &MBB.front() != MBBI &&
1239 prior(MBBI)->getOpcode() == ARM::tPOP) {
1240 MachineBasicBlock::iterator PMBBI = prior(MBBI);
1241 emitSPUpdate(MBB, PMBBI, NumBytes, isThumb, TII);
1242 } else
1243 emitSPUpdate(MBB, MBBI, NumBytes, isThumb, TII);
1244 }
1245 } else {
1246 // Darwin ABI requires FP to point to the stack slot that contains the
1247 // previous FP.
1248 if (STI.isTargetDarwin() || hasFP(MF)) {
1249 NumBytes = AFI->getFramePtrSpillOffset() - NumBytes;
1250 // Reset SP based on frame pointer only if the stack frame extends beyond
1251 // frame pointer stack slot or target is ELF and the function has FP.
1252 if (AFI->getGPRCalleeSavedArea2Size() ||
1253 AFI->getDPRCalleeSavedAreaSize() ||
1254 AFI->getDPRCalleeSavedAreaOffset()||
1255 hasFP(MF))
1256 if (NumBytes)
1257 BuildMI(MBB, MBBI, TII.get(ARM::SUBri), ARM::SP).addReg(FramePtr)
1258 .addImm(NumBytes);
1259 else
1260 BuildMI(MBB, MBBI, TII.get(ARM::MOVrr), ARM::SP).addReg(FramePtr);
1261 } else if (NumBytes) {
1262 emitSPUpdate(MBB, MBBI, NumBytes, false, TII);
1263 }
1264
1265 // Move SP to start of integer callee save spill area 2.
1266 movePastCSLoadStoreOps(MBB, MBBI, ARM::FLDD, 3, STI);
1267 emitSPUpdate(MBB, MBBI, AFI->getDPRCalleeSavedAreaSize(), false, TII);
1268
1269 // Move SP to start of integer callee save spill area 1.
1270 movePastCSLoadStoreOps(MBB, MBBI, ARM::LDR, 2, STI);
1271 emitSPUpdate(MBB, MBBI, AFI->getGPRCalleeSavedArea2Size(), false, TII);
1272
1273 // Move SP to SP upon entry to the function.
1274 movePastCSLoadStoreOps(MBB, MBBI, ARM::LDR, 1, STI);
1275 emitSPUpdate(MBB, MBBI, AFI->getGPRCalleeSavedArea1Size(), false, TII);
1245 // Darwin ABI requires FP to point to the stack slot that contains the
1246 // previous FP.
1247 if (STI.isTargetDarwin() || hasFP(MF)) {
1248 NumBytes = AFI->getFramePtrSpillOffset() - NumBytes;
1249 // Reset SP based on frame pointer only if the stack frame extends beyond
1250 // frame pointer stack slot or target is ELF and the function has FP.
1251 if (AFI->getGPRCalleeSavedArea2Size() ||
1252 AFI->getDPRCalleeSavedAreaSize() ||
1253 AFI->getDPRCalleeSavedAreaOffset()||
1254 hasFP(MF))
1255 if (NumBytes)
1256 BuildMI(MBB, MBBI, TII.get(ARM::SUBri), ARM::SP).addReg(FramePtr)
1257 .addImm(NumBytes);
1258 else
1259 BuildMI(MBB, MBBI, TII.get(ARM::MOVrr), ARM::SP).addReg(FramePtr);
1260 } else if (NumBytes) {
1261 emitSPUpdate(MBB, MBBI, NumBytes, false, TII);
1262 }
1263
1264 // Move SP to start of integer callee save spill area 2.
1265 movePastCSLoadStoreOps(MBB, MBBI, ARM::FLDD, 3, STI);
1266 emitSPUpdate(MBB, MBBI, AFI->getDPRCalleeSavedAreaSize(), false, TII);
1267
1268 // Move SP to start of integer callee save spill area 1.
1269 movePastCSLoadStoreOps(MBB, MBBI, ARM::LDR, 2, STI);
1270 emitSPUpdate(MBB, MBBI, AFI->getGPRCalleeSavedArea2Size(), false, TII);
1271
1272 // Move SP to SP upon entry to the function.
1273 movePastCSLoadStoreOps(MBB, MBBI, ARM::LDR, 1, STI);
1274 emitSPUpdate(MBB, MBBI, AFI->getGPRCalleeSavedArea1Size(), false, TII);
1275 }
12761276 }
12771277
12781278 if (VARegSaveSize) {
0 ; RUN: llvm-as < %s | llc -march=arm &&
1 ; RUN: llvm-as < %s | llc -march=arm -mtriple=arm-linux-gnueabi -disable-fp-elim | grep "add sp, sp, #16" &&
2 ; RUN: llvm-as < %s | llc -march=arm -mtriple=arm-linux-gnu -disable-fp-elim | grep "add sp, sp, #12"
1 ; RUN: llvm-as < %s | llc -march=arm -mtriple=arm-linux-gnueabi | grep "add sp, sp, #16" | wc -l | grep 1 &&
2 ; RUN: llvm-as < %s | llc -march=arm -mtriple=arm-linux-gnu | grep "add sp, sp, #12" | wc -l | grep 2
33
44 define i32 @f(i32 %a, ...) {
55 entry: