@@ -1319,19 +1319,22 @@ void RISCVFrameLowering::emitEpilogue(MachineFunction &MF,
1319
1319
emitCFIForCSI<CFIRestoreRegisterEmitter>(
1320
1320
MBB, MBBI, getPushOrLibCallsSavedInfo (MF, CSI));
1321
1321
1322
- // Update CFA offset. After CM_POP SP should be equal to CFA, so CFA
1323
- // offset should be a zero.
1322
+ // Update CFA Offset. If this is a QCI interrupt function, there will be a
1323
+ // leftover offset which is deallocated by `QC.C.MILEAVERET`, otherwise
1324
+ // getQCIInterruptStackSize() will be 0.
1324
1325
unsigned CFIIndex =
1325
- MF.addFrameInst (MCCFIInstruction::cfiDefCfaOffset (nullptr , 0 ));
1326
+ MF.addFrameInst (MCCFIInstruction::cfiDefCfaOffset (nullptr , RVFI-> getQCIInterruptStackSize () ));
1326
1327
BuildMI (MBB, MBBI, DL, TII->get (TargetOpcode::CFI_INSTRUCTION))
1327
1328
.addCFIIndex (CFIIndex)
1328
1329
.setMIFlag (MachineInstr::FrameDestroy);
1329
1330
}
1330
1331
}
1331
1332
1332
- // Deallocate stack if StackSize isn't a zero yet
1333
+ // Deallocate stack if StackSize isn't a zero yet. If this is a QCI interrupt
1334
+ // function, there will be a leftover offset which is deallocated by
1335
+ // `QC.C.MILEAVERET`, otherwise getQCIInterruptStackSize() will be 0.
1333
1336
if (StackSize != 0 )
1334
- deallocateStack (MF, MBB, MBBI, DL, StackSize, RealStackSize - StackSize );
1337
+ deallocateStack (MF, MBB, MBBI, DL, StackSize, RVFI-> getQCIInterruptStackSize () );
1335
1338
1336
1339
// Emit epilogue for shadow call stack.
1337
1340
emitSCSEpilogue (MF, MBB, MBBI, DL);
@@ -1898,8 +1901,12 @@ bool RISCVFrameLowering::assignCalleeSavedSpillSlots(
1898
1901
if (RVFI->isPushable (MF)) {
1899
1902
// Determine how many GPRs we need to push and save it to RVFI.
1900
1903
unsigned PushedRegNum = getNumPushPopRegs (CSI);
1901
- unsigned PushMoreThan = RVFI->useQCIInterrupt (MF) ? 2 : 0 ;
1902
- if (PushedRegNum > PushMoreThan) {
1904
+
1905
+ // `QC.C.MIENTER(.NEST)` will save `ra` and `s0`, so we should only push if
1906
+ // we want to push more than 2 registers. Otherwise, we should push if we
1907
+ // want to push more than 0 registers.
1908
+ unsigned OnlyPushIfMoreThan = RVFI->useQCIInterrupt (MF) ? 2 : 0 ;
1909
+ if (PushedRegNum > OnlyPushIfMoreThan) {
1903
1910
RVFI->setRVPushRegs (PushedRegNum);
1904
1911
RVFI->setRVPushStackSize (alignTo ((STI.getXLen () / 8 ) * PushedRegNum, 16 ));
1905
1912
}
0 commit comments