@@ -42,10 +42,19 @@ RISCVFrameLowering::RISCVFrameLowering(const RISCVSubtarget &STI)
42
42
/* TransientStackAlignment=*/ getABIStackAlignment(STI.getTargetABI())),
43
43
STI(STI) {}
44
44
45
+ // The register used to hold the frame pointer.
46
+ static constexpr Register FPReg = RISCV::X8;
47
+
48
+ // The register used to hold the stack pointer.
49
+ static constexpr Register SPReg = RISCV::X2;
50
+
51
+ // The register used to hold the return address.
52
+ static constexpr Register RAReg = RISCV::X1;
53
+
45
54
// Offsets which need to be scale by XLen representing locations of CSRs which
46
55
// are given a fixed location by save/restore libcalls or Zcmp Push/Pop.
47
56
static const std::pair<MCPhysReg, int8_t > FixedCSRFIMap[] = {
48
- {/* ra*/ RISCV::X1 , -1 }, {/* s0*/ RISCV::X8 , -2 },
57
+ {/* ra*/ RAReg , -1 }, {/* s0*/ FPReg , -2 },
49
58
{/* s1*/ RISCV::X9, -3 }, {/* s2*/ RISCV::X18, -4 },
50
59
{/* s3*/ RISCV::X19, -5 }, {/* s4*/ RISCV::X20, -6 },
51
60
{/* s5*/ RISCV::X21, -7 }, {/* s6*/ RISCV::X22, -8 },
@@ -187,6 +196,7 @@ static int getLibCallID(const MachineFunction &MF,
187
196
switch (MaxReg) {
188
197
default :
189
198
llvm_unreachable (" Something has gone wrong!" );
199
+ // clang-format off
190
200
case /* s11*/ RISCV::X27: return 12 ;
191
201
case /* s10*/ RISCV::X26: return 11 ;
192
202
case /* s9*/ RISCV::X25: return 10 ;
@@ -198,8 +208,9 @@ static int getLibCallID(const MachineFunction &MF,
198
208
case /* s3*/ RISCV::X19: return 4 ;
199
209
case /* s2*/ RISCV::X18: return 3 ;
200
210
case /* s1*/ RISCV::X9: return 2 ;
201
- case /* s0*/ RISCV::X8: return 1 ;
202
- case /* ra*/ RISCV::X1: return 0 ;
211
+ case /* s0*/ FPReg: return 1 ;
212
+ case /* ra*/ RAReg: return 0 ;
213
+ // clang-format on
203
214
}
204
215
}
205
216
@@ -284,9 +295,9 @@ getPushPopEncodingAndNum(const Register MaxReg) {
284
295
return std::make_pair (llvm::RISCVZC::RLISTENCODE::RA_S0_S2, 4 );
285
296
case RISCV::X9: /* s1*/
286
297
return std::make_pair (llvm::RISCVZC::RLISTENCODE::RA_S0_S1, 3 );
287
- case RISCV::X8 : /* s0*/
298
+ case FPReg : /* s0*/
288
299
return std::make_pair (llvm::RISCVZC::RLISTENCODE::RA_S0, 2 );
289
- case RISCV::X1 : /* ra*/
300
+ case RAReg : /* ra*/
290
301
return std::make_pair (llvm::RISCVZC::RLISTENCODE::RA, 1 );
291
302
}
292
303
}
@@ -372,12 +383,6 @@ uint64_t RISCVFrameLowering::getStackSizeWithRVVPadding(
372
383
return alignTo (MFI.getStackSize () + RVFI->getRVVPadding (), getStackAlign ());
373
384
}
374
385
375
- // Returns the register used to hold the frame pointer.
376
- static Register getFPReg (const RISCVSubtarget &STI) { return RISCV::X8; }
377
-
378
- // Returns the register used to hold the stack pointer.
379
- static Register getSPReg (const RISCVSubtarget &STI) { return RISCV::X2; }
380
-
381
386
static SmallVector<CalleeSavedInfo, 8 >
382
387
getUnmanagedCSI (const MachineFunction &MF,
383
388
const std::vector<CalleeSavedInfo> &CSI) {
@@ -415,8 +420,6 @@ void RISCVFrameLowering::adjustStackForRVV(MachineFunction &MF,
415
420
MachineInstr::MIFlag Flag) const {
416
421
assert (Amount != 0 && " Did not need to adjust stack pointer for RVV." );
417
422
418
- const Register SPReg = getSPReg (STI);
419
-
420
423
// Optimize compile time offset case
421
424
StackOffset Offset = StackOffset::getScalable (Amount);
422
425
if (auto VLEN = STI.getRealVLen ()) {
@@ -479,7 +482,7 @@ static MCCFIInstruction createDefCFAExpression(const TargetRegisterInfo &TRI,
479
482
unsigned DwarfReg = TRI.getDwarfRegNum (Reg, true );
480
483
Expr.push_back ((uint8_t )(dwarf::DW_OP_breg0 + DwarfReg));
481
484
Expr.push_back (0 );
482
- if (Reg == RISCV::X2 )
485
+ if (Reg == SPReg )
483
486
Comment << " sp" ;
484
487
else
485
488
Comment << printReg (Reg, &TRI);
@@ -530,8 +533,6 @@ void RISCVFrameLowering::emitPrologue(MachineFunction &MF,
530
533
const RISCVInstrInfo *TII = STI.getInstrInfo ();
531
534
MachineBasicBlock::iterator MBBI = MBB.begin ();
532
535
533
- Register FPReg = getFPReg (STI);
534
- Register SPReg = getSPReg (STI);
535
536
Register BPReg = RISCVABI::getBPReg ();
536
537
537
538
// Debug location must be unknown since the first debug location is used
@@ -762,8 +763,6 @@ void RISCVFrameLowering::deallocateStack(MachineFunction &MF,
762
763
int64_t CFAOffset) const {
763
764
const RISCVRegisterInfo *RI = STI.getRegisterInfo ();
764
765
765
- Register SPReg = getSPReg (STI);
766
-
767
766
RI->adjustReg (MBB, MBBI, DL, SPReg, SPReg, StackOffset::getFixed (StackSize),
768
767
MachineInstr::FrameDestroy, getStackAlign ());
769
768
}
@@ -773,8 +772,6 @@ void RISCVFrameLowering::emitEpilogue(MachineFunction &MF,
773
772
const RISCVRegisterInfo *RI = STI.getRegisterInfo ();
774
773
MachineFrameInfo &MFI = MF.getFrameInfo ();
775
774
auto *RVFI = MF.getInfo <RISCVMachineFunctionInfo>();
776
- Register FPReg = getFPReg (STI);
777
- Register SPReg = getSPReg (STI);
778
775
779
776
// All calls are tail calls in GHC calling conv, and functions have no
780
777
// prologue/epilogue.
@@ -922,7 +919,7 @@ RISCVFrameLowering::getFrameIndexReference(const MachineFunction &MF, int FI,
922
919
}
923
920
924
921
if (FI >= MinCSFI && FI <= MaxCSFI) {
925
- FrameReg = RISCV::X2 ;
922
+ FrameReg = SPReg ;
926
923
927
924
if (FirstSPAdjustAmount)
928
925
Offset += StackOffset::getFixed (FirstSPAdjustAmount);
@@ -969,13 +966,13 @@ RISCVFrameLowering::getFrameIndexReference(const MachineFunction &MF, int FI,
969
966
} else {
970
967
// VarSize objects must be empty in this case!
971
968
assert (!MFI.hasVarSizedObjects ());
972
- FrameReg = RISCV::X2 ;
969
+ FrameReg = SPReg ;
973
970
}
974
971
} else {
975
972
FrameReg = RI->getFrameRegister (MF);
976
973
}
977
974
978
- if (FrameReg == getFPReg (STI) ) {
975
+ if (FrameReg == FPReg ) {
979
976
Offset += StackOffset::getFixed (RVFI->getVarArgsSaveSize ());
980
977
// When using FP to access scalable vector objects, we need to minus
981
978
// the frame size.
@@ -1067,8 +1064,8 @@ void RISCVFrameLowering::determineCalleeSaves(MachineFunction &MF,
1067
1064
// Unconditionally spill RA and FP only if the function uses a frame
1068
1065
// pointer.
1069
1066
if (hasFP (MF)) {
1070
- SavedRegs.set (RISCV::X1 );
1071
- SavedRegs.set (RISCV::X8 );
1067
+ SavedRegs.set (RAReg );
1068
+ SavedRegs.set (FPReg );
1072
1069
}
1073
1070
// Mark BP as used if function has dedicated base pointer.
1074
1071
if (hasBP (MF))
@@ -1328,7 +1325,6 @@ bool RISCVFrameLowering::hasReservedCallFrame(const MachineFunction &MF) const {
1328
1325
MachineBasicBlock::iterator RISCVFrameLowering::eliminateCallFramePseudoInstr (
1329
1326
MachineFunction &MF, MachineBasicBlock &MBB,
1330
1327
MachineBasicBlock::iterator MI) const {
1331
- Register SPReg = RISCV::X2;
1332
1328
DebugLoc DL = MI->getDebugLoc ();
1333
1329
1334
1330
if (!hasReservedCallFrame (MF)) {
0 commit comments