aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/llvm/lib/Target/ARM/Thumb1FrameLowering.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Target/ARM/Thumb1FrameLowering.cpp')
-rw-r--r--contrib/llvm-project/llvm/lib/Target/ARM/Thumb1FrameLowering.cpp31
1 files changed, 15 insertions, 16 deletions
diff --git a/contrib/llvm-project/llvm/lib/Target/ARM/Thumb1FrameLowering.cpp b/contrib/llvm-project/llvm/lib/Target/ARM/Thumb1FrameLowering.cpp
index c2962c4857c3..0f4ece64bff5 100644
--- a/contrib/llvm-project/llvm/lib/Target/ARM/Thumb1FrameLowering.cpp
+++ b/contrib/llvm-project/llvm/lib/Target/ARM/Thumb1FrameLowering.cpp
@@ -40,7 +40,6 @@
#include "llvm/Support/Compiler.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MathExtras.h"
-#include <bitset>
#include <cassert>
#include <iterator>
#include <vector>
@@ -538,18 +537,30 @@ void Thumb1FrameLowering::emitEpilogue(MachineFunction &MF,
AFI->getDPRCalleeSavedAreaSize() +
ArgRegsSaveSize);
+ // We are likely to need a scratch register and we know all callee-save
+ // registers are free at this point in the epilogue, so pick one.
+ unsigned ScratchRegister = ARM::NoRegister;
+ bool HasFP = hasFP(MF);
+ for (auto &I : MFI.getCalleeSavedInfo()) {
+ Register Reg = I.getReg();
+ if (isARMLowRegister(Reg) && !(HasFP && Reg == FramePtr)) {
+ ScratchRegister = Reg;
+ break;
+ }
+ }
+
if (AFI->shouldRestoreSPFromFP()) {
NumBytes = AFI->getFramePtrSpillOffset() - NumBytes;
// Reset SP based on frame pointer only if the stack frame extends beyond
// frame pointer stack slot, the target is ELF and the function has FP, or
// the target uses var sized objects.
if (NumBytes) {
- assert(!MFI.getPristineRegs(MF).test(ARM::R4) &&
+ assert(ScratchRegister != ARM::NoRegister &&
"No scratch register to restore SP from FP!");
- emitThumbRegPlusImmediate(MBB, MBBI, dl, ARM::R4, FramePtr, -NumBytes,
+ emitThumbRegPlusImmediate(MBB, MBBI, dl, ScratchRegister, FramePtr, -NumBytes,
TII, *RegInfo, MachineInstr::FrameDestroy);
BuildMI(MBB, MBBI, dl, TII.get(ARM::tMOVr), ARM::SP)
- .addReg(ARM::R4)
+ .addReg(ScratchRegister)
.add(predOps(ARMCC::AL))
.setMIFlag(MachineInstr::FrameDestroy);
} else
@@ -558,18 +569,6 @@ void Thumb1FrameLowering::emitEpilogue(MachineFunction &MF,
.add(predOps(ARMCC::AL))
.setMIFlag(MachineInstr::FrameDestroy);
} else {
- // For a large stack frame, we might need a scratch register to store
- // the size of the frame. We know all callee-save registers are free
- // at this point in the epilogue, so pick one.
- unsigned ScratchRegister = ARM::NoRegister;
- bool HasFP = hasFP(MF);
- for (auto &I : MFI.getCalleeSavedInfo()) {
- Register Reg = I.getReg();
- if (isARMLowRegister(Reg) && !(HasFP && Reg == FramePtr)) {
- ScratchRegister = Reg;
- break;
- }
- }
if (MBBI != MBB.end() && MBBI->getOpcode() == ARM::tBX_RET &&
&MBB.front() != &*MBBI && std::prev(MBBI)->getOpcode() == ARM::tPOP) {
MachineBasicBlock::iterator PMBBI = std::prev(MBBI);