diff options
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp')
-rw-r--r-- | contrib/llvm-project/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/contrib/llvm-project/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp b/contrib/llvm-project/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp index ca2d9474d1ed..f312cc8129dd 100644 --- a/contrib/llvm-project/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp +++ b/contrib/llvm-project/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp @@ -262,22 +262,16 @@ static unsigned getPushPopEncoding(const Register MaxReg) { // Get the max reg of Push/Pop for restoring callee saved registers. static Register getMaxPushPopReg(const MachineFunction &MF, - const std::vector<CalleeSavedInfo> &CSI, - unsigned &PushPopRegs) { + const std::vector<CalleeSavedInfo> &CSI) { Register MaxPushPopReg = RISCV::NoRegister; - PushPopRegs = 0; for (auto &CS : CSI) { Register Reg = CS.getReg(); - if (RISCV::PGPRRegClass.contains(Reg)) { + if (RISCV::PGPRRegClass.contains(Reg)) MaxPushPopReg = std::max(MaxPushPopReg.id(), Reg.id()); - PushPopRegs += 1; - } } // if rlist is {rs, s0-s10}, then s11 will also be included - if (MaxPushPopReg == RISCV::X26) { + if (MaxPushPopReg == RISCV::X26) MaxPushPopReg = RISCV::X27; - PushPopRegs = 13; - } return MaxPushPopReg; } @@ -581,11 +575,18 @@ void RISCVFrameLowering::emitPrologue(MachineFunction &MF, int64_t Offset; // Offsets for objects with fixed locations (IE: those saved by libcall) are // simply calculated from the frame index. - if (FrameIdx < 0) - Offset = FrameIdx * (int64_t) STI.getXLen() / 8; - else + if (FrameIdx < 0) { + if (RVFI->isPushable(MF)) { + // Callee-saved register stored by Zcmp push is in reverse order. + Offset = -(FrameIdx + RVFI->getRVPushRegs() + 1) * + (int64_t)STI.getXLen() / 8; + } else { + Offset = FrameIdx * (int64_t)STI.getXLen() / 8; + } + } else { Offset = MFI.getObjectOffset(Entry.getFrameIdx()) - RVFI->getLibCallStackSize(); + } Register Reg = Entry.getReg(); unsigned CFIIndex = MF.addFrameInst(MCCFIInstruction::createOffset( nullptr, RI->getDwarfRegNum(Reg, true), Offset)); @@ -771,7 +772,8 @@ void RISCVFrameLowering::emitEpilogue(MachineFunction &MF, if (FirstSPAdjustAmount) StackSize = FirstSPAdjustAmount; - if (RVFI->isPushable(MF) && MBBI->getOpcode() == RISCV::CM_POP) { + if (RVFI->isPushable(MF) && MBBI != MBB.end() && + MBBI->getOpcode() == RISCV::CM_POP) { // Use available stack adjustment in pop instruction to deallocate stack // space. unsigned PushStack = RVFI->getRVPushRegs() * (STI.getXLen() / 8); @@ -1325,10 +1327,11 @@ bool RISCVFrameLowering::spillCalleeSavedRegisters( // Emit CM.PUSH with base SPimm & evaluate Push stack RISCVMachineFunctionInfo *RVFI = MF->getInfo<RISCVMachineFunctionInfo>(); if (RVFI->isPushable(*MF)) { - unsigned PushPopRegs = 0; - Register MaxReg = getMaxPushPopReg(*MF, CSI, PushPopRegs); - RVFI->setRVPushRegs(PushPopRegs); - RVFI->setRVPushStackSize(alignTo((STI.getXLen() / 8) * PushPopRegs, 16)); + Register MaxReg = getMaxPushPopReg(*MF, CSI); + unsigned PushedRegNum = + getPushPopEncoding(MaxReg) - llvm::RISCVZC::RLISTENCODE::RA + 1; + RVFI->setRVPushRegs(PushedRegNum); + RVFI->setRVPushStackSize(alignTo((STI.getXLen() / 8) * PushedRegNum, 16)); if (MaxReg != RISCV::NoRegister) { // Use encoded number to represent registers to spill. @@ -1340,7 +1343,7 @@ bool RISCVFrameLowering::spillCalleeSavedRegisters( PushBuilder.addImm((int64_t)RegEnc); PushBuilder.addImm(0); - for (unsigned i = 0; i < PushPopRegs; i++) + for (unsigned i = 0; i < PushedRegNum; i++) PushBuilder.addUse(AllPopRegs[i], RegState::Implicit); } } else if (const char *SpillLibCall = getSpillLibCallName(*MF, CSI)) { |