[llvm] r326610 - [SystemZ] Fix common-code users of stack size

Ulrich Weigand via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 2 12:38:41 PST 2018


Author: uweigand
Date: Fri Mar  2 12:38:41 2018
New Revision: 326610

URL: http://llvm.org/viewvc/llvm-project?rev=326610&view=rev
Log:
[SystemZ] Fix common-code users of stack size

On SystemZ we need to provide a register save area of 160 bytes to
any called function.  This size needs to be added when allocating
stack in the function prologue.  However, it was not accounted for
as part of MachineFrameInfo::getStackSize(); instead the back-end
used a private routine getAllocatedStackSize().

This is OK for code-gen purposes, but it breaks other users of
the getStackSize() routine, in particular it breaks the recently-
added -stack-size-section feature.

Fix this by updating the main stack size tracked by common code
(in emitPrologue) instead of using the private routine.

No change in code generation intended.


Added:
    llvm/trunk/test/CodeGen/SystemZ/stack-size-section.ll
Modified:
    llvm/trunk/lib/Target/SystemZ/SystemZFrameLowering.cpp
    llvm/trunk/lib/Target/SystemZ/SystemZFrameLowering.h

Modified: llvm/trunk/lib/Target/SystemZ/SystemZFrameLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/SystemZ/SystemZFrameLowering.cpp?rev=326610&r1=326609&r2=326610&view=diff
==============================================================================
--- llvm/trunk/lib/Target/SystemZ/SystemZFrameLowering.cpp (original)
+++ llvm/trunk/lib/Target/SystemZ/SystemZFrameLowering.cpp Fri Mar  2 12:38:41 2018
@@ -371,7 +371,15 @@ void SystemZFrameLowering::emitPrologue(
     }
   }
 
-  uint64_t StackSize = getAllocatedStackSize(MF);
+  uint64_t StackSize = MFFrame.getStackSize();
+  // We need to allocate the ABI-defined 160-byte base area whenever
+  // we allocate stack space for our own use and whenever we call another
+  // function.
+  if (StackSize || MFFrame.hasVarSizedObjects() || MFFrame.hasCalls()) {
+    StackSize += SystemZMC::CallFrameSize;
+    MFFrame.setStackSize(StackSize);
+  }
+
   if (StackSize) {
     // Determine if we want to store a backchain.
     bool StoreBackchain = MF.getFunction().hasFnAttribute("backchain");
@@ -454,11 +462,12 @@ void SystemZFrameLowering::emitEpilogue(
   auto *ZII =
       static_cast<const SystemZInstrInfo *>(MF.getSubtarget().getInstrInfo());
   SystemZMachineFunctionInfo *ZFI = MF.getInfo<SystemZMachineFunctionInfo>();
+  MachineFrameInfo &MFFrame = MF.getFrameInfo();
 
   // Skip the return instruction.
   assert(MBBI->isReturn() && "Can only insert epilogue into returning blocks");
 
-  uint64_t StackSize = getAllocatedStackSize(MF);
+  uint64_t StackSize = MFFrame.getStackSize();
   if (ZFI->getLowSavedGPR()) {
     --MBBI;
     unsigned Opcode = MBBI->getOpcode();
@@ -495,46 +504,6 @@ bool SystemZFrameLowering::hasFP(const M
           MF.getInfo<SystemZMachineFunctionInfo>()->getManipulatesSP());
 }
 
-int SystemZFrameLowering::getFrameIndexReference(const MachineFunction &MF,
-                                                 int FI,
-                                                 unsigned &FrameReg) const {
-  const MachineFrameInfo &MFFrame = MF.getFrameInfo();
-  const TargetRegisterInfo *RI = MF.getSubtarget().getRegisterInfo();
-
-  // Fill in FrameReg output argument.
-  FrameReg = RI->getFrameRegister(MF);
-
-  // Start with the offset of FI from the top of the caller-allocated frame
-  // (i.e. the top of the 160 bytes allocated by the caller).  This initial
-  // offset is therefore negative.
-  int64_t Offset = (MFFrame.getObjectOffset(FI) +
-                    MFFrame.getOffsetAdjustment());
-
-  // Make the offset relative to the incoming stack pointer.
-  Offset -= getOffsetOfLocalArea();
-
-  // Make the offset relative to the bottom of the frame.
-  Offset += getAllocatedStackSize(MF);
-
-  return Offset;
-}
-
-uint64_t SystemZFrameLowering::
-getAllocatedStackSize(const MachineFunction &MF) const {
-  const MachineFrameInfo &MFFrame = MF.getFrameInfo();
-
-  // Start with the size of the local variables and spill slots.
-  uint64_t StackSize = MFFrame.getStackSize();
-
-  // We need to allocate the ABI-defined 160-byte base area whenever
-  // we allocate stack space for our own use and whenever we call another
-  // function.
-  if (StackSize || MFFrame.hasVarSizedObjects() || MFFrame.hasCalls())
-    StackSize += SystemZMC::CallFrameSize;
-
-  return StackSize;
-}
-
 bool
 SystemZFrameLowering::hasReservedCallFrame(const MachineFunction &MF) const {
   // The ABI requires us to allocate 160 bytes of stack space for the callee,

Modified: llvm/trunk/lib/Target/SystemZ/SystemZFrameLowering.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/SystemZ/SystemZFrameLowering.h?rev=326610&r1=326609&r2=326610&view=diff
==============================================================================
--- llvm/trunk/lib/Target/SystemZ/SystemZFrameLowering.h (original)
+++ llvm/trunk/lib/Target/SystemZ/SystemZFrameLowering.h Fri Mar  2 12:38:41 2018
@@ -43,16 +43,11 @@ public:
   void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
   void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
   bool hasFP(const MachineFunction &MF) const override;
-  int getFrameIndexReference(const MachineFunction &MF, int FI,
-                             unsigned &FrameReg) const override;
   bool hasReservedCallFrame(const MachineFunction &MF) const override;
   MachineBasicBlock::iterator
   eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
                                 MachineBasicBlock::iterator MI) const override;
 
-  // Return the number of bytes in the callee-allocated part of the frame.
-  uint64_t getAllocatedStackSize(const MachineFunction &MF) const;
-
   // Return the byte offset from the incoming stack pointer of Reg's
   // ABI-defined save slot.  Return 0 if no slot is defined for Reg.
   unsigned getRegSpillOffset(unsigned Reg) const {

Added: llvm/trunk/test/CodeGen/SystemZ/stack-size-section.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/SystemZ/stack-size-section.ll?rev=326610&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/SystemZ/stack-size-section.ll (added)
+++ llvm/trunk/test/CodeGen/SystemZ/stack-size-section.ll Fri Mar  2 12:38:41 2018
@@ -0,0 +1,38 @@
+; RUN: llc < %s -mtriple=s390x-linux-gnu -stack-size-section | FileCheck %s
+
+; CHECK-LABEL: func1:
+; CHECK: .section .stack_sizes,"", at progbits
+; CHECK-NEXT: .quad func1
+; CHECK-NEXT: .byte 0
+define void @func1(i32, i32) #0 {
+  ret void
+}
+
+; CHECK-LABEL: func2:
+; CHECK: .section .stack_sizes,"", at progbits
+; CHECK-NEXT: .quad func2
+; CHECK-NEXT: .ascii  "\250\001"
+define void @func2(i32, i32) #0 {
+  alloca i32, align 4
+  alloca i32, align 4
+  ret void
+}
+
+; CHECK-LABEL: func3:
+; CHECK: .section .stack_sizes,"", at progbits
+; CHECK-NEXT: .quad func3
+; CHECK-NEXT: .ascii  "\250\001"
+define void @func3() #0 {
+  alloca i32, align 4
+  call void @func1(i32 1, i32 2)
+  ret void
+}
+
+; CHECK-LABEL: dynalloc:
+; CHECK-NOT: .section .stack_sizes
+define void @dynalloc(i32 %N) #0 {
+  alloca i32, i32 %N
+  ret void
+}
+
+attributes #0 = { "no-frame-pointer-elim"="true" }




More information about the llvm-commits mailing list