[llvm] [RISCV] Allocate the varargs GPR save area as a single object. (PR #74354)

Wang Pengcheng via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 4 23:12:22 PST 2023


================
@@ -436,60 +436,63 @@ void RISCVCallLowering::saveVarArgRegisters(
   const RISCVSubtarget &Subtarget = MF.getSubtarget<RISCVSubtarget>();
   unsigned XLenInBytes = Subtarget.getXLen() / 8;
   ArrayRef<MCPhysReg> ArgRegs(ArgGPRs);
+  MachineRegisterInfo &MRI = MF.getRegInfo();
   unsigned Idx = CCInfo.getFirstUnallocated(ArgRegs);
+  MachineFrameInfo &MFI = MF.getFrameInfo();
+  RISCVMachineFunctionInfo *RVFI = MF.getInfo<RISCVMachineFunctionInfo>();
 
-  // Offset of the first variable argument from stack pointer, and size of
-  // the vararg save area. For now, the varargs save area is either zero or
-  // large enough to hold a0-a7.
-  int VaArgOffset;
+  // Size of the vararg save area. For now, the varargs save area is either
+  // zero or large enough to hold a0-a7.
   int VarArgsSaveSize = XLenInBytes * (ArgRegs.size() - Idx);
+  int FI;
 
   // If all registers are allocated, then all varargs must be passed on the
   // stack and we don't need to save any argregs.
   if (VarArgsSaveSize == 0) {
-    VaArgOffset = Assigner.StackSize;
+    int VaArgOffset = Assigner.StackSize;
+    FI = MFI.CreateFixedObject(XLenInBytes, VaArgOffset, true);
   } else {
-    VaArgOffset = -VarArgsSaveSize;
+    int VaArgOffset = -VarArgsSaveSize;
+    FI = MFI.CreateFixedObject(VarArgsSaveSize, VaArgOffset, true);
+
+    // If saving an odd number of registers then create an extra stack slot to
+    // ensure that the frame pointer is 2*XLEN-aligned, which in turn ensures
+    // offsets to even-numbered registered remain 2*XLEN-aligned.
+    if (Idx % 2) {
+      MFI.CreateFixedObject(XLenInBytes,
+                            VaArgOffset - static_cast<int>(XLenInBytes), true);
+      VarArgsSaveSize += XLenInBytes;
+    }
+
+    const LLT p0 = LLT::pointer(MF.getDataLayout().getAllocaAddrSpace(),
----------------
wangpc-pp wrote:

Hmmm, but this is against LLVM coding style...whatever... 😵‍💫 

https://github.com/llvm/llvm-project/pull/74354


More information about the llvm-commits mailing list