[PATCH] D11814: Define a subtarget feature to force stack realignment

Akira Hatanaka via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 19 12:00:10 PDT 2015


ahatanak updated this revision to Diff 32590.
ahatanak added a comment.

Use function attribute "force-align-stack" instead of defining a subtarget feature for each target and move cl::opt option ForceAlignStack to CommandFlags.h so that tools like llc can write the function attribute to the IR. It really should be an enum attribute because it's target independent, but I used a string attribute here to make it consistent with "no-realign-stack".


http://reviews.llvm.org/D11814

Files:
  include/llvm/CodeGen/CommandFlags.h
  include/llvm/Target/TargetRegisterInfo.h
  lib/CodeGen/TargetRegisterInfo.cpp
  lib/Target/X86/X86FrameLowering.cpp

Index: lib/Target/X86/X86FrameLowering.cpp
===================================================================
--- lib/Target/X86/X86FrameLowering.cpp
+++ lib/Target/X86/X86FrameLowering.cpp
@@ -498,7 +498,7 @@
   const MachineFrameInfo *MFI = MF.getFrameInfo();
   uint64_t MaxAlign = MFI->getMaxAlignment(); // Desired stack alignment.
   unsigned StackAlign = getStackAlignment();
-  if (ForceStackAlign) {
+  if (MF.getFunction()->hasFnAttribute("force-align-stack")) {
     if (MFI->hasCalls())
       MaxAlign = (StackAlign > MaxAlign) ? StackAlign : MaxAlign;
     else if (MaxAlign < SlotSize)
Index: lib/CodeGen/TargetRegisterInfo.cpp
===================================================================
--- lib/CodeGen/TargetRegisterInfo.cpp
+++ lib/CodeGen/TargetRegisterInfo.cpp
@@ -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,8 @@
   unsigned StackAlign = TFI->getStackAlignment();
   bool requiresRealignment = ((MFI->getMaxAlignment() > StackAlign) ||
                               F->hasFnAttribute(Attribute::StackAlignment));
-  if (ForceStackAlign || requiresRealignment) {
+  if (MF.getFunction()->hasFnAttribute("force-align-stack") ||
+      requiresRealignment) {
     if (canRealignStack(MF))
       return true;
     DEBUG(dbgs() << "Can't realign function's stack: " << F->getName() << "\n");
Index: include/llvm/Target/TargetRegisterInfo.h
===================================================================
--- include/llvm/Target/TargetRegisterInfo.h
+++ include/llvm/Target/TargetRegisterInfo.h
@@ -35,8 +35,6 @@
 class raw_ostream;
 class LiveRegMatrix;
 
-extern cl::opt<bool> ForceStackAlign;
-
 class TargetRegisterClass {
 public:
   typedef const MCPhysReg* iterator;
Index: include/llvm/CodeGen/CommandFlags.h
===================================================================
--- include/llvm/CodeGen/CommandFlags.h
+++ include/llvm/CodeGen/CommandFlags.h
@@ -182,6 +182,11 @@
                        cl::desc("Override default stack alignment"),
                        cl::init(0));
 
+cl::opt<bool>
+ForceAlignStack("force-align-stack",
+                cl::desc("Force align the stack to the minimum alignment "
+                         "needed for the function."), 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 @@
                                        "disable-tail-calls",
                                        toStringRef(DisableTailCalls));
 
+    if (ForceAlignStack)
+      NewAttrs = NewAttrs.addAttribute(Ctx, AttributeSet::FunctionIndex,
+                                       "force-align-stack");
+
     if (TrapFuncName.getNumOccurrences() > 0)
       for (auto &B : F)
         for (auto &I : B)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D11814.32590.patch
Type: text/x-patch
Size: 3212 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150819/b2e0e628/attachment-0001.bin>


More information about the llvm-commits mailing list