Skip to content

Commit 3b00877

Browse files
Colin McEwanColin McEwan
authored andcommitted
NanoMips: Fix IPRA issue llvm#57482
This isn't a full fix on its own though since RA is not actually flagged as non-allocable, and there's nothing that denotes 'clobbered by the calller's call instruction itself'
1 parent eeeec5a commit 3b00877

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

llvm/include/llvm/CodeGen/TargetRegisterInfo.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,13 @@ class TargetRegisterInfo : public MCRegisterInfo {
565565
virtual bool isCalleeSavedPhysReg(MCRegister PhysReg,
566566
const MachineFunction &MF) const;
567567

568+
// Return true if the register is needed for returning from the
569+
// function and so must be preserved in the callee even if preserved
570+
// by the caller
571+
virtual bool isNeededForReturn(MCRegister PhysReg, const MachineFunction &MF) const {
572+
return false;
573+
}
574+
568575
/// Prior to adding the live-out mask to a stackmap or patchpoint
569576
/// instruction, provide the target the opportunity to adjust it (mainly to
570577
/// remove pseudo-registers that should be ignored).

llvm/lib/CodeGen/TargetFrameLoweringImpl.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,9 @@ void TargetFrameLowering::determineCalleeSaves(MachineFunction &MF,
8787

8888
// When interprocedural register allocation is enabled caller saved registers
8989
// are preferred over callee saved registers.
90-
if (MF.getTarget().Options.EnableIPRA &&
91-
isSafeForNoCSROpt(MF.getFunction()) &&
92-
isProfitableForNoCSROpt(MF.getFunction()))
93-
return;
90+
bool NoCSR = (MF.getTarget().Options.EnableIPRA &&
91+
isSafeForNoCSROpt(MF.getFunction()) &&
92+
isProfitableForNoCSROpt(MF.getFunction()));
9493

9594
// Get the callee saved register list...
9695
const MCPhysReg *CSRegs = MF.getRegInfo().getCalleeSavedRegs();
@@ -119,10 +118,12 @@ void TargetFrameLowering::determineCalleeSaves(MachineFunction &MF,
119118
// Functions which call __builtin_unwind_init get all their registers saved.
120119
bool CallsUnwindInit = MF.callsUnwindInit();
121120
const MachineRegisterInfo &MRI = MF.getRegInfo();
121+
const TargetRegisterInfo *RI = MF.getSubtarget().getRegisterInfo();
122122
for (unsigned i = 0; CSRegs[i]; ++i) {
123123
unsigned Reg = CSRegs[i];
124124
if (CallsUnwindInit || MRI.isPhysRegModified(Reg))
125-
SavedRegs.set(Reg);
125+
if (!NoCSR || !MRI.isAllocatable(Reg) || RI->isNeededForReturn(Reg, MF))
126+
SavedRegs.set(Reg);
126127
}
127128
}
128129

llvm/lib/Target/Mips/MipsRegisterInfo.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,11 @@ MipsRegisterInfo::requiresRegisterScavenging(const MachineFunction &MF) const {
267267
return true;
268268
}
269269

270+
bool MipsRegisterInfo::isNeededForReturn(MCRegister PhysReg, const MachineFunction &MF) const {
271+
return PhysReg == Mips::RA || PhysReg == Mips::RA_64 || PhysReg == Mips::RA_NM;
272+
}
273+
274+
270275
// FrameIndex represent objects inside a abstract stack.
271276
// We must replace FrameIndex with an stack/frame pointer
272277
// direct reference.

llvm/lib/Target/Mips/MipsRegisterInfo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ class MipsRegisterInfo : public MipsGenRegisterInfo {
7373
/// Return GPR register class.
7474
virtual const TargetRegisterClass *intRegClass(unsigned Size) const = 0;
7575

76+
virtual bool isNeededForReturn(MCRegister PhysReg, const MachineFunction &MF) const override;
77+
7678
private:
7779
virtual void eliminateFI(MachineBasicBlock::iterator II, unsigned OpNo,
7880
int FrameIndex, uint64_t StackSize,

0 commit comments

Comments
 (0)