@@ -42,10 +42,16 @@ RISCVFrameLowering::RISCVFrameLowering(const RISCVSubtarget &STI)
42
42
/* TransientStackAlignment=*/ getABIStackAlignment(STI.getTargetABI())),
43
43
STI(STI) {}
44
44
45
- static const MCPhysReg AllPopRegs[] = {
46
- RISCV::X1, RISCV::X8, RISCV::X9, RISCV::X18, RISCV::X19,
47
- RISCV::X20, RISCV::X21, RISCV::X22, RISCV::X23, RISCV::X24,
48
- RISCV::X25, RISCV::X26, RISCV::X27};
45
+ // Offsets which need to be scale by XLen representing locations of CSRs which
46
+ // are given a fixed location by save/restore libcalls or Zcmp Push/Pop.
47
+ static const std::pair<MCPhysReg, int8_t > FixedCSRFIMap[] = {
48
+ {/* ra*/ RISCV::X1, -1 }, {/* s0*/ RISCV::X8, -2 },
49
+ {/* s1*/ RISCV::X9, -3 }, {/* s2*/ RISCV::X18, -4 },
50
+ {/* s3*/ RISCV::X19, -5 }, {/* s4*/ RISCV::X20, -6 },
51
+ {/* s5*/ RISCV::X21, -7 }, {/* s6*/ RISCV::X22, -8 },
52
+ {/* s7*/ RISCV::X23, -9 }, {/* s8*/ RISCV::X24, -10 },
53
+ {/* s9*/ RISCV::X25, -11 }, {/* s10*/ RISCV::X26, -12 },
54
+ {/* s11*/ RISCV::X27, -13 }};
49
55
50
56
// For now we use x3, a.k.a gp, as pointer to shadow call stack.
51
57
// User should not use x3 in their asm.
@@ -170,7 +176,7 @@ static int getLibCallID(const MachineFunction &MF,
170
176
171
177
Register MaxReg = RISCV::NoRegister;
172
178
for (auto &CS : CSI)
173
- // RISCVRegisterInfo::hasReservedSpillSlot assigns negative frame indexes to
179
+ // assignCalleeSavedSpillSlots assigns negative frame indexes to
174
180
// registers which can be saved by libcall.
175
181
if (CS.getFrameIdx () < 0 )
176
182
MaxReg = std::max (MaxReg.id (), CS.getReg ().id ());
@@ -291,7 +297,9 @@ static Register getMaxPushPopReg(const MachineFunction &MF,
291
297
const std::vector<CalleeSavedInfo> &CSI) {
292
298
Register MaxPushPopReg = RISCV::NoRegister;
293
299
for (auto &CS : CSI) {
294
- if (llvm::is_contained (AllPopRegs, CS.getReg ().id ()))
300
+ if (llvm::find_if (FixedCSRFIMap, [&](auto P) {
301
+ return P.first == CS.getReg ();
302
+ }) != std::end (FixedCSRFIMap))
295
303
MaxPushPopReg = std::max (MaxPushPopReg.id (), CS.getReg ().id ());
296
304
}
297
305
// if rlist is {rs, s0-s10}, then s11 will also be included
@@ -1385,17 +1393,6 @@ RISCVFrameLowering::getFirstSPAdjustAmount(const MachineFunction &MF) const {
1385
1393
return 0 ;
1386
1394
}
1387
1395
1388
- // Offsets which need to be scale by XLen representing locations of CSRs which
1389
- // are given a fixed location by save/restore libcalls or Zcmp Push/Pop.
1390
- static const std::pair<MCPhysReg, int8_t > FixedCSRFIMap[] = {
1391
- {/* ra*/ RISCV::X1, -1 }, {/* s0*/ RISCV::X8, -2 },
1392
- {/* s1*/ RISCV::X9, -3 }, {/* s2*/ RISCV::X18, -4 },
1393
- {/* s3*/ RISCV::X19, -5 }, {/* s4*/ RISCV::X20, -6 },
1394
- {/* s5*/ RISCV::X21, -7 }, {/* s6*/ RISCV::X22, -8 },
1395
- {/* s7*/ RISCV::X23, -9 }, {/* s8*/ RISCV::X24, -10 },
1396
- {/* s9*/ RISCV::X25, -11 }, {/* s10*/ RISCV::X26, -12 },
1397
- {/* s11*/ RISCV::X27, -13 }};
1398
-
1399
1396
bool RISCVFrameLowering::assignCalleeSavedSpillSlots (
1400
1397
MachineFunction &MF, const TargetRegisterInfo *TRI,
1401
1398
std::vector<CalleeSavedInfo> &CSI, unsigned &MinCSFrameIndex,
@@ -1498,7 +1495,7 @@ bool RISCVFrameLowering::spillCalleeSavedRegisters(
1498
1495
PushBuilder.addImm (0 );
1499
1496
1500
1497
for (unsigned i = 0 ; i < PushedRegNum; i++)
1501
- PushBuilder.addUse (AllPopRegs [i], RegState::Implicit);
1498
+ PushBuilder.addUse (FixedCSRFIMap [i]. first , RegState::Implicit);
1502
1499
}
1503
1500
} else if (const char *SpillLibCall = getSpillLibCallName (*MF, CSI)) {
1504
1501
// Add spill libcall via non-callee-saved register t0.
@@ -1611,7 +1608,7 @@ bool RISCVFrameLowering::restoreCalleeSavedRegisters(
1611
1608
PopBuilder.addImm (0 );
1612
1609
1613
1610
for (unsigned i = 0 ; i < RVFI->getRVPushRegs (); i++)
1614
- PopBuilder.addDef (AllPopRegs [i], RegState::ImplicitDefine);
1611
+ PopBuilder.addDef (FixedCSRFIMap [i]. first , RegState::ImplicitDefine);
1615
1612
}
1616
1613
} else {
1617
1614
const char *RestoreLibCall = getRestoreLibCallName (*MF, CSI);
0 commit comments