[llvm] r247450 - Use function attribute "stackrealign" to decide whether stack

Akira Hatanaka via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 11 11:54:39 PDT 2015


Author: ahatanak
Date: Fri Sep 11 13:54:38 2015
New Revision: 247450

URL: http://llvm.org/viewvc/llvm-project?rev=247450&view=rev
Log:
Use function attribute "stackrealign" to decide whether stack
realignment should be forced.

With this commit, we can now force stack realignment when doing LTO and
do so on a per-function basis. Also, add a new cl::opt option
"stackrealign" to CommandFlags.h which is used to force stack
realignment via llc's command line.

Out-of-tree projects currently using -force-align-stack to force stack
realignment should make changes to attach the attribute to the functions
in the IR.

Differential Revision: http://reviews.llvm.org/D11814

Modified:
    llvm/trunk/include/llvm/CodeGen/CommandFlags.h
    llvm/trunk/include/llvm/Target/TargetRegisterInfo.h
    llvm/trunk/lib/CodeGen/TargetRegisterInfo.cpp
    llvm/trunk/lib/Target/X86/X86FrameLowering.cpp
    llvm/trunk/test/CodeGen/Generic/ForceStackAlign.ll
    llvm/trunk/test/CodeGen/X86/dynamic-allocas-VLAs.ll
    llvm/trunk/test/CodeGen/X86/force-align-stack-alloca.ll
    llvm/trunk/test/CodeGen/X86/force-align-stack.ll
    llvm/trunk/test/CodeGen/X86/inline-asm-sp-clobber-memcpy.ll
    llvm/trunk/test/CodeGen/X86/movtopush.ll
    llvm/trunk/test/CodeGen/X86/pr11468.ll
    llvm/trunk/test/CodeGen/X86/stack-align-memcpy.ll
    llvm/trunk/test/CodeGen/X86/unaligned-spill-folding.ll
    llvm/trunk/test/CodeGen/X86/x86-64-baseptr.ll

Modified: llvm/trunk/include/llvm/CodeGen/CommandFlags.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/CommandFlags.h?rev=247450&r1=247449&r2=247450&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/CommandFlags.h (original)
+++ llvm/trunk/include/llvm/CodeGen/CommandFlags.h Fri Sep 11 13:54:38 2015
@@ -182,6 +182,11 @@ OverrideStackAlignment("stack-alignment"
                        cl::desc("Override default stack alignment"),
                        cl::init(0));
 
+cl::opt<bool>
+StackRealign("stackrealign",
+             cl::desc("Force align the stack to the minimum alignment"),
+             cl::init(false));
+
 cl::opt<std::string>
 TrapFuncName("trap-func", cl::Hidden,
         cl::desc("Emit a call to trap function rather than a trap instruction"),
@@ -330,6 +335,10 @@ static inline void setFunctionAttributes
                                        "disable-tail-calls",
                                        toStringRef(DisableTailCalls));
 
+    if (StackRealign)
+      NewAttrs = NewAttrs.addAttribute(Ctx, AttributeSet::FunctionIndex,
+                                       "stackrealign");
+
     if (TrapFuncName.getNumOccurrences() > 0)
       for (auto &B : F)
         for (auto &I : B)

Modified: llvm/trunk/include/llvm/Target/TargetRegisterInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetRegisterInfo.h?rev=247450&r1=247449&r2=247450&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/TargetRegisterInfo.h (original)
+++ llvm/trunk/include/llvm/Target/TargetRegisterInfo.h Fri Sep 11 13:54:38 2015
@@ -35,8 +35,6 @@ class VirtRegMap;
 class raw_ostream;
 class LiveRegMatrix;
 
-extern cl::opt<bool> ForceStackAlign;
-
 class TargetRegisterClass {
 public:
   typedef const MCPhysReg* iterator;

Modified: llvm/trunk/lib/CodeGen/TargetRegisterInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/TargetRegisterInfo.cpp?rev=247450&r1=247449&r2=247450&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/TargetRegisterInfo.cpp (original)
+++ llvm/trunk/lib/CodeGen/TargetRegisterInfo.cpp Fri Sep 11 13:54:38 2015
@@ -24,14 +24,6 @@
 
 #define DEBUG_TYPE "target-reg-info"
 
-namespace llvm {
-cl::opt<bool>
-    ForceStackAlign("force-align-stack",
-                    cl::desc("Force align the stack to the minimum alignment"
-                             " needed for the function."),
-                    cl::init(false), cl::Hidden);
-} // end namespace llvm
-
 using namespace llvm;
 
 TargetRegisterInfo::TargetRegisterInfo(const TargetRegisterInfoDesc *ID,
@@ -321,7 +313,7 @@ bool TargetRegisterInfo::needsStackReali
   unsigned StackAlign = TFI->getStackAlignment();
   bool requiresRealignment = ((MFI->getMaxAlignment() > StackAlign) ||
                               F->hasFnAttribute(Attribute::StackAlignment));
-  if (ForceStackAlign || requiresRealignment) {
+  if (MF.getFunction()->hasFnAttribute("stackrealign") || requiresRealignment) {
     if (canRealignStack(MF))
       return true;
     DEBUG(dbgs() << "Can't realign function's stack: " << F->getName() << "\n");

Modified: llvm/trunk/lib/Target/X86/X86FrameLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86FrameLowering.cpp?rev=247450&r1=247449&r2=247450&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86FrameLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86FrameLowering.cpp Fri Sep 11 13:54:38 2015
@@ -499,7 +499,7 @@ uint64_t X86FrameLowering::calculateMaxS
   const MachineFrameInfo *MFI = MF.getFrameInfo();
   uint64_t MaxAlign = MFI->getMaxAlignment(); // Desired stack alignment.
   unsigned StackAlign = getStackAlignment();
-  if (ForceStackAlign) {
+  if (MF.getFunction()->hasFnAttribute("stackrealign")) {
     if (MFI->hasCalls())
       MaxAlign = (StackAlign > MaxAlign) ? StackAlign : MaxAlign;
     else if (MaxAlign < SlotSize)

Modified: llvm/trunk/test/CodeGen/Generic/ForceStackAlign.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Generic/ForceStackAlign.ll?rev=247450&r1=247449&r2=247450&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/Generic/ForceStackAlign.ll (original)
+++ llvm/trunk/test/CodeGen/Generic/ForceStackAlign.ll Fri Sep 11 13:54:38 2015
@@ -1,7 +1,7 @@
 ; Check that stack alignment can be forced. Individual targets should test their
 ; specific implementation details.
 
-; RUN: llc < %s -force-align-stack -stack-alignment=32 | FileCheck %s
+; RUN: llc < %s -stackrealign -stack-alignment=32 | FileCheck %s
 ; CHECK-LABEL: @f
 ; CHECK-LABEL: @g
 

Modified: llvm/trunk/test/CodeGen/X86/dynamic-allocas-VLAs.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/dynamic-allocas-VLAs.ll?rev=247450&r1=247449&r2=247450&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/dynamic-allocas-VLAs.ll (original)
+++ llvm/trunk/test/CodeGen/X86/dynamic-allocas-VLAs.ll Fri Sep 11 13:54:38 2015
@@ -1,5 +1,5 @@
 ; RUN: llc < %s -mcpu=generic -march=x86-64 -mattr=+avx -mtriple=i686-apple-darwin10 | FileCheck %s
-; RUN: llc < %s -mcpu=generic -force-align-stack -stack-alignment=32 -march=x86-64 -mattr=+avx -mtriple=i686-apple-darwin10 | FileCheck %s -check-prefix=FORCE-ALIGN
+; RUN: llc < %s -mcpu=generic -stackrealign -stack-alignment=32 -march=x86-64 -mattr=+avx -mtriple=i686-apple-darwin10 | FileCheck %s -check-prefix=FORCE-ALIGN
 ; rdar://11496434
 
 ; no VLAs or dynamic alignment

Modified: llvm/trunk/test/CodeGen/X86/force-align-stack-alloca.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/force-align-stack-alloca.ll?rev=247450&r1=247449&r2=247450&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/force-align-stack-alloca.ll (original)
+++ llvm/trunk/test/CodeGen/X86/force-align-stack-alloca.ll Fri Sep 11 13:54:38 2015
@@ -3,7 +3,7 @@
 ; arbitrarily force alignment up to 32-bytes for i386 hoping that this will
 ; exceed any ABI provisions.
 ;
-; RUN: llc < %s -mcpu=generic -force-align-stack -stack-alignment=32 | FileCheck %s
+; RUN: llc < %s -mcpu=generic -stackrealign -stack-alignment=32 | FileCheck %s
 
 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S128"
 target triple = "i386-unknown-linux-gnu"

Modified: llvm/trunk/test/CodeGen/X86/force-align-stack.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/force-align-stack.ll?rev=247450&r1=247449&r2=247450&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/force-align-stack.ll (original)
+++ llvm/trunk/test/CodeGen/X86/force-align-stack.ll Fri Sep 11 13:54:38 2015
@@ -1,4 +1,4 @@
-; RUN: llc < %s -relocation-model=static -force-align-stack | FileCheck %s
+; RUN: llc < %s -relocation-model=static -stackrealign | FileCheck %s
 ; Tests to make sure that we always align the stack out to the minimum needed - 
 ; in this case 16-bytes.
 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128-n8:16:32"

Modified: llvm/trunk/test/CodeGen/X86/inline-asm-sp-clobber-memcpy.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/inline-asm-sp-clobber-memcpy.ll?rev=247450&r1=247449&r2=247450&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/inline-asm-sp-clobber-memcpy.ll (original)
+++ llvm/trunk/test/CodeGen/X86/inline-asm-sp-clobber-memcpy.ll Fri Sep 11 13:54:38 2015
@@ -1,4 +1,4 @@
-; RUN: llc < %s -force-align-stack -mtriple i386-apple-darwin -mcpu=i486 | FileCheck %s
+; RUN: llc < %s -stackrealign -mtriple i386-apple-darwin -mcpu=i486 | FileCheck %s
 
 %struct.foo = type { [88 x i8] }
 

Modified: llvm/trunk/test/CodeGen/X86/movtopush.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/movtopush.ll?rev=247450&r1=247449&r2=247450&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/movtopush.ll (original)
+++ llvm/trunk/test/CodeGen/X86/movtopush.ll Fri Sep 11 13:54:38 2015
@@ -1,6 +1,6 @@
 ; RUN: llc < %s -mtriple=i686-windows | FileCheck %s -check-prefix=NORMAL
 ; RUN: llc < %s -mtriple=x86_64-windows | FileCheck %s -check-prefix=X64
-; RUN: llc < %s -mtriple=i686-windows -force-align-stack -stack-alignment=32 | FileCheck %s -check-prefix=ALIGNED 
+; RUN: llc < %s -mtriple=i686-windows -stackrealign -stack-alignment=32 | FileCheck %s -check-prefix=ALIGNED
 
 %class.Class = type { i32 }
 %struct.s = type { i64 }

Modified: llvm/trunk/test/CodeGen/X86/pr11468.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/pr11468.ll?rev=247450&r1=247449&r2=247450&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/pr11468.ll (original)
+++ llvm/trunk/test/CodeGen/X86/pr11468.ll Fri Sep 11 13:54:38 2015
@@ -1,4 +1,4 @@
-; RUN: llc < %s -force-align-stack -stack-alignment=32 -march=x86-64 -mattr=+avx -mtriple=i686-apple-darwin10 | FileCheck %s
+; RUN: llc < %s -stackrealign -stack-alignment=32 -march=x86-64 -mattr=+avx -mtriple=i686-apple-darwin10 | FileCheck %s
 ; PR11468
 
 define void @f(i64 %sz) uwtable {

Modified: llvm/trunk/test/CodeGen/X86/stack-align-memcpy.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/stack-align-memcpy.ll?rev=247450&r1=247449&r2=247450&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/stack-align-memcpy.ll (original)
+++ llvm/trunk/test/CodeGen/X86/stack-align-memcpy.ll Fri Sep 11 13:54:38 2015
@@ -1,4 +1,4 @@
-; RUN: llc < %s -force-align-stack -mtriple i386-apple-darwin -mcpu=i486 | FileCheck %s
+; RUN: llc < %s -stackrealign -mtriple i386-apple-darwin -mcpu=i486 | FileCheck %s
 
 %struct.foo = type { [88 x i8] }
 

Modified: llvm/trunk/test/CodeGen/X86/unaligned-spill-folding.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/unaligned-spill-folding.ll?rev=247450&r1=247449&r2=247450&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/unaligned-spill-folding.ll (original)
+++ llvm/trunk/test/CodeGen/X86/unaligned-spill-folding.ll Fri Sep 11 13:54:38 2015
@@ -1,6 +1,6 @@
 ; RUN: llc -mtriple=i386-unknown-freebsd -mcpu=core2 -stack-alignment=4 -relocation-model=pic < %s | FileCheck %s -check-prefix=UNALIGNED
 ; RUN: llc -mtriple=i386-unknown-freebsd -mcpu=core2 -stack-alignment=16 -relocation-model=pic < %s | FileCheck %s -check-prefix=ALIGNED
-; RUN: llc -mtriple=i386-unknown-freebsd -mcpu=core2 -stack-alignment=4 -force-align-stack -relocation-model=pic < %s | FileCheck %s -check-prefix=FORCEALIGNED
+; RUN: llc -mtriple=i386-unknown-freebsd -mcpu=core2 -stack-alignment=4 -stackrealign -relocation-model=pic < %s | FileCheck %s -check-prefix=FORCEALIGNED
 
 @arr = internal unnamed_addr global [32 x i32] zeroinitializer, align 16
 

Modified: llvm/trunk/test/CodeGen/X86/x86-64-baseptr.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/x86-64-baseptr.ll?rev=247450&r1=247449&r2=247450&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/x86-64-baseptr.ll (original)
+++ llvm/trunk/test/CodeGen/X86/x86-64-baseptr.ll Fri Sep 11 13:54:38 2015
@@ -1,5 +1,5 @@
-; RUN: llc -mtriple=x86_64-pc-linux -force-align-stack -stack-alignment=32 < %s | FileCheck %s
-; RUN: llc -mtriple=x86_64-pc-linux-gnux32 -force-align-stack -stack-alignment=32 < %s | FileCheck -check-prefix=X32ABI %s
+; RUN: llc -mtriple=x86_64-pc-linux -stackrealign -stack-alignment=32 < %s | FileCheck %s
+; RUN: llc -mtriple=x86_64-pc-linux-gnux32 -stackrealign -stack-alignment=32 < %s | FileCheck -check-prefix=X32ABI %s
 ; This should run with NaCl as well ( -mtriple=x86_64-pc-nacl ) but currently doesn't due to PR22655
 
 ; Make sure the correct register gets set up as the base pointer




More information about the llvm-commits mailing list