[PATCH] D12349: [SPARC] Fix stupid oversight in stack realignment support.

James Y Knight via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 26 10:59:06 PDT 2015


This revision was automatically updated to reflect the committed changes.
Closed by commit rL246042: [SPARC] Fix stupid oversight in stack realignment support. (authored by jyknight).

Changed prior to commit:
  http://reviews.llvm.org/D12349?vs=33163&id=33225#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D12349

Files:
  llvm/trunk/lib/Target/Sparc/SparcFrameLowering.cpp
  llvm/trunk/lib/Target/Sparc/SparcFrameLowering.h
  llvm/trunk/lib/Target/Sparc/SparcSubtarget.cpp
  llvm/trunk/test/CodeGen/SPARC/stack-align.ll

Index: llvm/trunk/test/CodeGen/SPARC/stack-align.ll
===================================================================
--- llvm/trunk/test/CodeGen/SPARC/stack-align.ll
+++ llvm/trunk/test/CodeGen/SPARC/stack-align.ll
@@ -12,7 +12,7 @@
 ;; CHECK:      andn %sp, 63, %sp
 ;; CHECK-NEXT: ld [%fp+92], %o0
 ;; CHECK-NEXT: call stack_realign_helper
-;; CHECK-NEXT: add %sp, 96, %o1
+;; CHECK-NEXT: add %sp, 128, %o1
 
 define void @stack_realign(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e, i32 %f, i32 %g) {
 entry:
Index: llvm/trunk/lib/Target/Sparc/SparcFrameLowering.cpp
===================================================================
--- llvm/trunk/lib/Target/Sparc/SparcFrameLowering.cpp
+++ llvm/trunk/lib/Target/Sparc/SparcFrameLowering.cpp
@@ -118,8 +118,37 @@
     SAVErr = SP::ADDrr;
   }
 
+  // The SPARC ABI is a bit odd in that it requires a reserved 92-byte
+  // (128 in v9) area in the user's stack, starting at %sp. Thus, the
+  // first part of the stack that can actually be used is located at
+  // %sp + 92.
+  //
+  // We therefore need to add that offset to the total stack size
+  // after all the stack objects are placed by
+  // PrologEpilogInserter calculateFrameObjectOffsets. However, since the stack needs to be
+  // aligned *after* the extra size is added, we need to disable
+  // calculateFrameObjectOffsets's built-in stack alignment, by having
+  // targetHandlesStackFrameRounding return true.
+
+
+  // Add the extra call frame stack size, if needed. (This is the same
+  // code as in PrologEpilogInserter, but also gets disabled by
+  // targetHandlesStackFrameRounding)
+  if (MFI->adjustsStack() && hasReservedCallFrame(MF))
+    NumBytes += MFI->getMaxCallFrameSize();
+
+  // Adds the SPARC subtarget-specific spill area to the stack
+  // size. Also ensures target-required alignment.
   NumBytes = MF.getSubtarget<SparcSubtarget>().getAdjustedFrameSize(NumBytes);
-  MFI->setStackSize(NumBytes); // Update stack size with corrected value.
+
+  // Finally, ensure that the size is sufficiently aligned for the
+  // data on the stack.
+  if (MFI->getMaxAlignment() > 0) {
+    NumBytes = RoundUpToAlignment(NumBytes, MFI->getMaxAlignment());
+  }
+
+  // Update stack size with corrected value.
+  MFI->setStackSize(NumBytes);
 
   emitSPAdjustment(MF, MBB, MBBI, -NumBytes, SAVErr, SAVEri);
 
Index: llvm/trunk/lib/Target/Sparc/SparcSubtarget.cpp
===================================================================
--- llvm/trunk/lib/Target/Sparc/SparcSubtarget.cpp
+++ llvm/trunk/lib/Target/Sparc/SparcSubtarget.cpp
@@ -64,7 +64,7 @@
     frameSize += 128;
     // Frames with calls must also reserve space for 6 outgoing arguments
     // whether they are used or not. LowerCall_64 takes care of that.
-    assert(frameSize % 16 == 0 && "Stack size not 16-byte aligned");
+    frameSize = RoundUpToAlignment(frameSize, 16);
   } else {
     // Emit the correct save instruction based on the number of bytes in
     // the frame. Minimum stack frame size according to V8 ABI is:
Index: llvm/trunk/lib/Target/Sparc/SparcFrameLowering.h
===================================================================
--- llvm/trunk/lib/Target/Sparc/SparcFrameLowering.h
+++ llvm/trunk/lib/Target/Sparc/SparcFrameLowering.h
@@ -41,6 +41,12 @@
 
   int getFrameIndexReference(const MachineFunction &MF, int FI,
                              unsigned &FrameReg) const override;
+
+  /// targetHandlesStackFrameRounding - Returns true if the target is
+  /// responsible for rounding up the stack frame (probably at emitPrologue
+  /// time).
+  bool targetHandlesStackFrameRounding() const override { return true; }
+
 private:
   // Remap input registers to output registers for leaf procedure.
   void remapRegsForLeafProc(MachineFunction &MF) const;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12349.33225.patch
Type: text/x-patch
Size: 3781 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150826/15fda250/attachment.bin>


More information about the llvm-commits mailing list