Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NFC][RISCV] Remove CFIIndex argument from allocateStack #117871

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rzinsly
Copy link
Contributor

@rzinsly rzinsly commented Nov 27, 2024

Calculates CFIIndex inside RISCVFrameLowering::allocateStack instead of sending it by argument.

…teStack

Calculates CFIIndex inside RISCVFrameLowering::allocateStack instead of
sending it by argument.
@llvmbot
Copy link
Member

llvmbot commented Nov 27, 2024

@llvm/pr-subscribers-backend-risc-v

Author: Raphael Moreira Zinsly (rzinsly)

Changes

Calculates CFIIndex inside RISCVFrameLowering::allocateStack instead of sending it by argument.


Full diff: https://github.com/llvm/llvm-project/pull/117871.diff

2 Files Affected:

  • (modified) llvm/lib/Target/RISCV/RISCVFrameLowering.cpp (+10-13)
  • (modified) llvm/lib/Target/RISCV/RISCVFrameLowering.h (+2-1)
diff --git a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
index 2da32fece061bb..073ccbdf8d0c1c 100644
--- a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
@@ -582,8 +582,9 @@ static MCCFIInstruction createDefCFAOffset(const TargetRegisterInfo &TRI,
 
 void RISCVFrameLowering::allocateStack(MachineBasicBlock &MBB,
                                        MachineBasicBlock::iterator MBBI,
-                                       StackOffset Offset, bool EmitCFI,
-                                       unsigned CFIIndex) const {
+                                       MachineFunction &MF, StackOffset Offset,
+                                       uint64_t RealStackSize,
+                                       bool EmitCFI) const {
   DebugLoc DL;
   const RISCVRegisterInfo *RI = STI.getRegisterInfo();
   const RISCVInstrInfo *TII = STI.getInstrInfo();
@@ -592,7 +593,9 @@ void RISCVFrameLowering::allocateStack(MachineBasicBlock &MBB,
                 getStackAlign());
 
   if (EmitCFI) {
-    // Emit ".cfi_def_cfa_offset StackSize"
+    // Emit ".cfi_def_cfa_offset RealStackSize"
+    unsigned CFIIndex = MF.addFrameInst(
+        MCCFIInstruction::cfiDefCfaOffset(nullptr, RealStackSize));
     BuildMI(MBB, MBBI, DL, TII->get(TargetOpcode::CFI_INSTRUCTION))
         .addCFIIndex(CFIIndex)
         .setMIFlag(MachineInstr::FrameSetup);
@@ -715,10 +718,8 @@ void RISCVFrameLowering::emitPrologue(MachineFunction &MF,
 
   if (StackSize != 0) {
     // Allocate space on the stack if necessary.
-    unsigned CFIIndex = MF.addFrameInst(
-        MCCFIInstruction::cfiDefCfaOffset(nullptr, RealStackSize));
-    allocateStack(MBB, MBBI, StackOffset::getFixed(-StackSize),
-		  /*EmitCFI=*/ true, CFIIndex);
+    allocateStack(MBB, MBBI, MF, StackOffset::getFixed(-StackSize),
+                  RealStackSize, /*EmitCFI=*/true);
   }
 
   // The frame pointer is callee-saved, and code has been generated for us to
@@ -760,12 +761,8 @@ void RISCVFrameLowering::emitPrologue(MachineFunction &MF,
     assert(SecondSPAdjustAmount > 0 &&
            "SecondSPAdjustAmount should be greater than zero");
 
-    // If we are using a frame-pointer, and thus emitted ".cfi_def_cfa fp, 0",
-    // don't emit an sp-based .cfi_def_cfa_offset
-    unsigned CFIIndex = MF.addFrameInst(MCCFIInstruction::cfiDefCfaOffset(
-        nullptr, getStackSizeWithRVVPadding(MF)));
-    allocateStack(MBB, MBBI, StackOffset::getFixed(-SecondSPAdjustAmount),
-                  !hasFP(MF), CFIIndex);
+    allocateStack(MBB, MBBI, MF, StackOffset::getFixed(-SecondSPAdjustAmount),
+                  getStackSizeWithRVVPadding(MF), !hasFP(MF));
   }
 
   if (RVVStackSize) {
diff --git a/llvm/lib/Target/RISCV/RISCVFrameLowering.h b/llvm/lib/Target/RISCV/RISCVFrameLowering.h
index 84a8fbd117a225..ac0c805c744d63 100644
--- a/llvm/lib/Target/RISCV/RISCVFrameLowering.h
+++ b/llvm/lib/Target/RISCV/RISCVFrameLowering.h
@@ -79,7 +79,8 @@ class RISCVFrameLowering : public TargetFrameLowering {
   }
 
   void allocateStack(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
-                     StackOffset Offset, bool EmitCFI, unsigned CFIIndex) const;
+                     MachineFunction &MF, StackOffset Offset,
+                     uint64_t RealStackSize, bool EmitCFI) const;
 
 protected:
   const RISCVSubtarget &STI;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants