[llvm] [PATCH] [Xtensa] Implement FrameLowering methods and stack operation lowering. (PR #92960)
Andrei Safronov via llvm-commits
llvm-commits at lists.llvm.org
Tue May 28 16:22:36 PDT 2024
================
@@ -33,10 +34,153 @@ bool XtensaFrameLowering::hasFP(const MachineFunction &MF) const {
}
void XtensaFrameLowering::emitPrologue(MachineFunction &MF,
- MachineBasicBlock &MBB) const {}
+ MachineBasicBlock &MBB) const {
+ assert(&MBB == &MF.front() && "Shrink-wrapping not yet implemented");
+ MachineFrameInfo &MFI = MF.getFrameInfo();
+ MachineBasicBlock::iterator MBBI = MBB.begin();
+ DebugLoc DL = MBBI != MBB.end() ? MBBI->getDebugLoc() : DebugLoc();
+ MCRegister SP = Xtensa::SP;
+ MCRegister FP = TRI->getFrameRegister(MF);
+ MachineModuleInfo &MMI = MF.getMMI();
+ const MCRegisterInfo *MRI = MMI.getContext().getRegisterInfo();
+
+ // First, compute final stack size.
+ uint64_t StackSize = MFI.getStackSize();
+ uint64_t PrevStackSize = StackSize;
+
+ // Round up StackSize to 16*N
+ StackSize += (16 - StackSize) & 0xf;
+
+ // No need to allocate space on the stack.
+ if (StackSize == 0 && !MFI.adjustsStack())
+ return;
+
+ // Adjust stack.
+ TII.adjustStackPtr(SP, -StackSize, MBB, MBBI);
+
+ // emit ".cfi_def_cfa_offset StackSize"
+ unsigned CFIIndex =
+ MF.addFrameInst(MCCFIInstruction::cfiDefCfaOffset(nullptr, StackSize));
+ BuildMI(MBB, MBBI, DL, TII.get(TargetOpcode::CFI_INSTRUCTION))
+ .addCFIIndex(CFIIndex);
+
+ const std::vector<CalleeSavedInfo> &CSI = MFI.getCalleeSavedInfo();
+
+ if (CSI.size()) {
----------------
andreisfr wrote:
fixed
https://github.com/llvm/llvm-project/pull/92960
More information about the llvm-commits
mailing list