summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Target/ARM/Thumb1FrameLowering.cpp
diff options
context:
space:
mode:
authorChad Rosier <mcrosier@apple.com>2011-10-01 02:03:18 +0000
committerChad Rosier <mcrosier@apple.com>2011-10-01 02:03:18 +0000
commit21360a4949b92dd45df822f97fc796d1081f57f8 (patch)
tree13df119f576e6d8c288b2363758b5fc3d2500fd1 /llvm/lib/Target/ARM/Thumb1FrameLowering.cpp
parentd74713b18c02a924c144910b275681cb7591923d (diff)
downloadbcm5719-llvm-21360a4949b92dd45df822f97fc796d1081f57f8.tar.gz
bcm5719-llvm-21360a4949b92dd45df822f97fc796d1081f57f8.zip
Attempt to fix dynamic stack realignment for thumb1 functions. It is in fact
useful if an optimization assumes the stack has been realigned. Credit to Eli for his assistance. rdar://10043857 llvm-svn: 140924
Diffstat (limited to 'llvm/lib/Target/ARM/Thumb1FrameLowering.cpp')
-rw-r--r--llvm/lib/Target/ARM/Thumb1FrameLowering.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/llvm/lib/Target/ARM/Thumb1FrameLowering.cpp b/llvm/lib/Target/ARM/Thumb1FrameLowering.cpp
index d4d59ea59da..9ff3ffcfa2b 100644
--- a/llvm/lib/Target/ARM/Thumb1FrameLowering.cpp
+++ b/llvm/lib/Target/ARM/Thumb1FrameLowering.cpp
@@ -155,6 +155,27 @@ void Thumb1FrameLowering::emitPrologue(MachineFunction &MF) const {
AFI->setGPRCalleeSavedArea2Size(GPRCS2Size);
AFI->setDPRCalleeSavedAreaSize(DPRCSSize);
+ if (RegInfo->needsStackRealignment(MF)) {
+ // We cannot use sp as source/dest register here, thus we're emitting the
+ // following sequence:
+ // mov r4, sp
+ // lsrs r4, r4, Log2MaxAlign
+ // lsls r4, r4, Log2MaxAlign
+ // mov sp, r4
+ unsigned MaxAlign = MFI->getMaxAlignment();
+ unsigned Log2MaxAlign = Log2_32(MaxAlign);
+ AddDefaultPred(BuildMI(MBB, MBBI, dl, TII.get(ARM::tMOVr), ARM::R4)
+ .addReg(ARM::SP, RegState::Kill));
+ AddDefaultPred(AddDefaultT1CC(BuildMI(MBB, MBBI, dl, TII.get(ARM::tLSRri), ARM::R4))
+ .addReg(ARM::R4, RegState::Kill)
+ .addImm(Log2MaxAlign));
+ AddDefaultPred(AddDefaultT1CC(BuildMI(MBB, MBBI, dl, TII.get(ARM::tLSLri), ARM::R4))
+ .addReg(ARM::R4, RegState::Kill)
+ .addImm(Log2MaxAlign));
+ AddDefaultPred(BuildMI(MBB, MBBI, dl, TII.get(ARM::tMOVr), ARM::SP)
+ .addReg(ARM::R4, RegState::Kill));
+ }
+
// If we need a base pointer, set it up here. It's whatever the value
// of the stack pointer is at this point. Any variable size objects
// will be allocated after this, so we can still use the base pointer
OpenPOWER on IntegriCloud