[cfe-commits] r145909 - in /cfe/trunk: include/clang/Driver/Options.td include/clang/Frontend/CodeGenOptions.h lib/CodeGen/BackendUtil.cpp lib/Driver/Tools.cpp lib/Frontend/CompilerInvocation.cpp test/Driver/stackrealign.c

Nick Lewycky nicholas at mxc.ca
Mon Dec 5 19:33:03 PST 2011


Author: nicholas
Date: Mon Dec  5 21:33:03 2011
New Revision: 145909

URL: http://llvm.org/viewvc/llvm-project?rev=145909&view=rev
Log:
Stack realignment is a tristate. Add -mno-stackrealign to turn off all stack
realignment, even with locals with alignment exceeding the ABI guarantee.

Added:
    cfe/trunk/test/Driver/stackrealign.c
Modified:
    cfe/trunk/include/clang/Driver/Options.td
    cfe/trunk/include/clang/Frontend/CodeGenOptions.h
    cfe/trunk/lib/CodeGen/BackendUtil.cpp
    cfe/trunk/lib/Driver/Tools.cpp
    cfe/trunk/lib/Frontend/CompilerInvocation.cpp

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=145909&r1=145908&r2=145909&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Mon Dec  5 21:33:03 2011
@@ -583,6 +583,7 @@
 def mno_relax_all : Flag<"-mno-relax-all">, Group<m_Group>;
 def mno_rtd: Flag<"-mno-rtd">, Group<m_Group>;
 def mno_soft_float : Flag<"-mno-soft-float">, Group<m_Group>;
+def mno_stackrealign : Flag<"-mno-stackrealign">, Group<m_Group>;
 def mno_sse2 : Flag<"-mno-sse2">, Group<m_x86_Features_Group>;
 def mno_sse3 : Flag<"-mno-sse3">, Group<m_x86_Features_Group>;
 def mno_sse4a : Flag<"-mno-sse4a">, Group<m_x86_Features_Group>;

Modified: cfe/trunk/include/clang/Frontend/CodeGenOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CodeGenOptions.h?rev=145909&r1=145908&r2=145909&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/CodeGenOptions.h (original)
+++ cfe/trunk/include/clang/Frontend/CodeGenOptions.h Mon Dec  5 21:33:03 2011
@@ -105,8 +105,8 @@
   unsigned VerifyModule      : 1; /// Control whether the module should be run
                                   /// through the LLVM Verifier.
 
-  unsigned RealignStack       : 1; /// Controls whether stack frame should be
-                                  /// readjusted to the desired alignment.
+  unsigned StackRealignment  : 1; /// Control whether to permit stack
+                                  /// realignment.
   unsigned StackAlignment;        /// Overrides default stack alignment,
                                   /// if not 0.
 

Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=145909&r1=145908&r2=145909&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Mon Dec  5 21:33:03 2011
@@ -289,11 +289,6 @@
 
   llvm::TargetOptions Options;
 
-  if (CodeGenOpts.RealignStack)
-    Options.RealignStack = true;
-  if (CodeGenOpts.StackAlignment)
-    Options.StackAlignmentOverride = CodeGenOpts.StackAlignment;
-
   // Set frame pointer elimination mode.
   if (!CodeGenOpts.DisableFPElim) {
     Options.NoFramePointerElim = false;
@@ -322,6 +317,8 @@
   Options.NoZerosInBSS = CodeGenOpts.NoZeroInitializedInBSS;
   Options.UnsafeFPMath = CodeGenOpts.UnsafeFPMath;
   Options.UseSoftFloat = CodeGenOpts.SoftFloat;
+  Options.StackAlignmentOverride = CodeGenOpts.StackAlignment;
+  Options.RealignStack = CodeGenOpts.StackRealignment;
 
   TargetMachine *TM = TheTarget->createTargetMachine(Triple, TargetOpts.CPU,
                                                      FeaturesStr, Options,

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=145909&r1=145908&r2=145909&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Mon Dec  5 21:33:03 2011
@@ -1796,8 +1796,17 @@
     CmdArgs.push_back(Args.MakeArgString(Twine(StackProtectorLevel)));
   }
 
-  if (Args.hasArg(options::OPT_mstackrealign))
-    CmdArgs.push_back("-mstackrealign");
+  // Translate -mstackrealign
+  if (Args.hasFlag(options::OPT_mstackrealign, options::OPT_mno_stackrealign,
+                   false)) {
+    CmdArgs.push_back("-backend-option");
+    CmdArgs.push_back("-force-align-stack");
+  }
+  if (!Args.hasFlag(options::OPT_mno_stackrealign, options::OPT_mstackrealign,
+                   false)) {
+    CmdArgs.push_back(Args.MakeArgString("-mstackrealign"));
+  }
+
   if (Args.hasArg(options::OPT_mstack_alignment)) {
     StringRef alignment = Args.getLastArgValue(options::OPT_mstack_alignment);
     CmdArgs.push_back(Args.MakeArgString("-mstack-alignment=" + alignment));

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=145909&r1=145908&r2=145909&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Mon Dec  5 21:33:03 2011
@@ -1114,7 +1114,7 @@
   Opts.CoverageFile = Args.getLastArgValue(OPT_coverage_file);
   Opts.DebugCompilationDir = Args.getLastArgValue(OPT_fdebug_compilation_dir);
   Opts.LinkBitcodeFile = Args.getLastArgValue(OPT_mlink_bitcode_file);
-  Opts.RealignStack = Args.hasArg(OPT_mstackrealign);
+  Opts.StackRealignment = Args.hasArg(OPT_mstackrealign);
   if (Arg *A = Args.getLastArg(OPT_mstack_alignment)) {
     StringRef Val = A->getValue(Args);
     Val.getAsInteger(10, Opts.StackAlignment);

Added: cfe/trunk/test/Driver/stackrealign.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/stackrealign.c?rev=145909&view=auto
==============================================================================
--- cfe/trunk/test/Driver/stackrealign.c (added)
+++ cfe/trunk/test/Driver/stackrealign.c Mon Dec  5 21:33:03 2011
@@ -0,0 +1,12 @@
+// RUN: %clang -### %s 2>&1 | FileCheck %s -check-prefix=NORMAL
+// NORMAL-NOT: -force-align-stack
+// NORMAL: -mstackrealign
+
+// RUN: %clang -### -mstackrealign %s 2>&1 | FileCheck %s -check-prefix=MREALIGN
+// MREALIGN: -force-align-stack
+// MREALIGN: -mstackrealign
+
+// RUN: %clang -### -mno-stackrealign %s 2>&1 | \
+// RUN: FileCheck %s -check-prefix=MNOREALIGN
+// MNOREALIGN-NOT: -force-align-stack
+// MNOREALIGN-NOT: -mstackrealign





More information about the cfe-commits mailing list