Skip to content

Commit 18dbe68

Browse files
committed
[ARM][NFC] Tidy up subtarget frame pointer routines
getFramePointerReg only depends on information in ARMSubtarget, so move it in there so it can be accessed from more places. Make use of ARMSubtarget::getFramePointerReg to remove duplicated code. The main use of useR7AsFramePointer is getFramePointerReg, so inline it. Differential Revision: https://reviews.llvm.org/D104476
1 parent 9abaf5c commit 18dbe68

5 files changed

+24
-26
lines changed

llvm/lib/Target/ARM/ARMAsmPrinter.cpp

+12-13
Original file line numberDiff line numberDiff line change
@@ -1293,7 +1293,6 @@ void ARMAsmPrinter::emitInstruction(const MachineInstr *MI) {
12931293

12941294
const MachineFunction &MF = *MI->getParent()->getParent();
12951295
const ARMSubtarget &STI = MF.getSubtarget<ARMSubtarget>();
1296-
unsigned FramePtr = STI.useR7AsFramePointer() ? ARM::R7 : ARM::R11;
12971296

12981297
// If we just ended a constant pool, mark it as such.
12991298
if (InConstantPool && MI->getOpcode() != ARM::CONSTPOOL_ENTRY) {
@@ -2039,12 +2038,12 @@ void ARMAsmPrinter::emitInstruction(const MachineInstr *MI) {
20392038
if (STI.isTargetDarwin() || STI.isTargetWindows()) {
20402039
// These platforms always use the same frame register
20412040
EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::LDRi12)
2042-
.addReg(FramePtr)
2043-
.addReg(SrcReg)
2044-
.addImm(0)
2045-
// Predicate.
2046-
.addImm(ARMCC::AL)
2047-
.addReg(0));
2041+
.addReg(STI.getFramePointerReg())
2042+
.addReg(SrcReg)
2043+
.addImm(0)
2044+
// Predicate.
2045+
.addImm(ARMCC::AL)
2046+
.addReg(0));
20482047
} else {
20492048
// If the calling code might use either R7 or R11 as
20502049
// frame pointer register, restore it into both.
@@ -2109,12 +2108,12 @@ void ARMAsmPrinter::emitInstruction(const MachineInstr *MI) {
21092108
if (STI.isTargetDarwin() || STI.isTargetWindows()) {
21102109
// These platforms always use the same frame register
21112110
EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tLDRi)
2112-
.addReg(FramePtr)
2113-
.addReg(SrcReg)
2114-
.addImm(0)
2115-
// Predicate.
2116-
.addImm(ARMCC::AL)
2117-
.addReg(0));
2111+
.addReg(STI.getFramePointerReg())
2112+
.addReg(SrcReg)
2113+
.addImm(0)
2114+
// Predicate.
2115+
.addImm(ARMCC::AL)
2116+
.addReg(0));
21182117
} else {
21192118
// If the calling code might use either R7 or R11 as
21202119
// frame pointer register, restore it into both.

llvm/lib/Target/ARM/ARMBaseRegisterInfo.cpp

+5-8
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,6 @@ ARMBaseRegisterInfo::ARMBaseRegisterInfo()
5959
ARM_MC::initLLVMToCVRegMapping(this);
6060
}
6161

62-
static unsigned getFramePointerReg(const ARMSubtarget &STI) {
63-
return STI.useR7AsFramePointer() ? ARM::R7 : ARM::R11;
64-
}
65-
6662
const MCPhysReg*
6763
ARMBaseRegisterInfo::getCalleeSavedRegs(const MachineFunction *MF) const {
6864
const ARMSubtarget &STI = MF->getSubtarget<ARMSubtarget>();
@@ -206,7 +202,7 @@ getReservedRegs(const MachineFunction &MF) const {
206202
markSuperRegs(Reserved, ARM::FPSCR);
207203
markSuperRegs(Reserved, ARM::APSR_NZCV);
208204
if (TFI->hasFP(MF))
209-
markSuperRegs(Reserved, getFramePointerReg(STI));
205+
markSuperRegs(Reserved, STI.getFramePointerReg());
210206
if (hasBasePointer(MF))
211207
markSuperRegs(Reserved, BasePtr);
212208
// Some targets reserve R9.
@@ -243,7 +239,7 @@ bool ARMBaseRegisterInfo::isInlineAsmReadOnlyReg(const MachineFunction &MF,
243239
BitVector Reserved(getNumRegs());
244240
markSuperRegs(Reserved, ARM::PC);
245241
if (TFI->hasFP(MF))
246-
markSuperRegs(Reserved, getFramePointerReg(STI));
242+
markSuperRegs(Reserved, STI.getFramePointerReg());
247243
if (hasBasePointer(MF))
248244
markSuperRegs(Reserved, BasePtr);
249245
assert(checkAllSuperRegsMarked(Reserved));
@@ -444,14 +440,15 @@ bool ARMBaseRegisterInfo::hasBasePointer(const MachineFunction &MF) const {
444440
bool ARMBaseRegisterInfo::canRealignStack(const MachineFunction &MF) const {
445441
const MachineRegisterInfo *MRI = &MF.getRegInfo();
446442
const ARMFrameLowering *TFI = getFrameLowering(MF);
443+
const ARMSubtarget &STI = MF.getSubtarget<ARMSubtarget>();
447444
// We can't realign the stack if:
448445
// 1. Dynamic stack realignment is explicitly disabled,
449446
// 2. There are VLAs in the function and the base pointer is disabled.
450447
if (!TargetRegisterInfo::canRealignStack(MF))
451448
return false;
452449
// Stack realignment requires a frame pointer. If we already started
453450
// register allocation with frame pointer elimination, it is too late now.
454-
if (!MRI->canReserveReg(getFramePointerReg(MF.getSubtarget<ARMSubtarget>())))
451+
if (!MRI->canReserveReg(STI.getFramePointerReg()))
455452
return false;
456453
// We may also need a base pointer if there are dynamic allocas or stack
457454
// pointer adjustments around calls.
@@ -477,7 +474,7 @@ ARMBaseRegisterInfo::getFrameRegister(const MachineFunction &MF) const {
477474
const ARMFrameLowering *TFI = getFrameLowering(MF);
478475

479476
if (TFI->hasFP(MF))
480-
return getFramePointerReg(STI);
477+
return STI.getFramePointerReg();
481478
return ARM::SP;
482479
}
483480

llvm/lib/Target/ARM/ARMFrameLowering.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
// or stores.
9595
//
9696
// The frame pointer might be chosen to be r7 or r11, depending on the target
97-
// architecture and operating system. See ARMSubtarget::useR7AsFramePointer for
97+
// architecture and operating system. See ARMSubtarget::getFramePointerReg for
9898
// details.
9999
//
100100
// Outgoing function arguments must be at the bottom of the stack frame when

llvm/lib/Target/ARM/ARMSubtarget.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -820,16 +820,18 @@ class ARMSubtarget : public ARMGenSubtargetInfo {
820820
return isTargetMachO() ? (ReserveR9 || !HasV6Ops) : ReserveR9;
821821
}
822822

823-
bool useR7AsFramePointer() const {
824-
return isTargetDarwin() || (!isTargetWindows() && isThumb());
823+
MCPhysReg getFramePointerReg() const {
824+
if (isTargetDarwin() || (!isTargetWindows() && isThumb()))
825+
return ARM::R7;
826+
return ARM::R11;
825827
}
826828

827829
/// Returns true if the frame setup is split into two separate pushes (first
828830
/// r0-r7,lr then r8-r11), principally so that the frame pointer is adjacent
829831
/// to lr. This is always required on Thumb1-only targets, as the push and
830832
/// pop instructions can't access the high registers.
831833
bool splitFramePushPop(const MachineFunction &MF) const {
832-
return (useR7AsFramePointer() &&
834+
return (getFramePointerReg() == ARM::R7 &&
833835
MF.getTarget().Options.DisableFramePointerElim(MF)) ||
834836
isThumb1Only();
835837
}

llvm/lib/Target/ARM/Thumb1FrameLowering.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ bool Thumb1FrameLowering::emitPopSpecialFixUp(MachineBasicBlock &MBB,
681681
// R7 may be used as a frame pointer, hence marked as not generally
682682
// allocatable, however there's no reason to not use it as a temporary for
683683
// restoring LR.
684-
if (STI.useR7AsFramePointer())
684+
if (STI.getFramePointerReg() == ARM::R7)
685685
PopFriendly.set(ARM::R7);
686686

687687
assert(PopFriendly.any() && "No allocatable pop-friendly register?!");

0 commit comments

Comments
 (0)