[cfe-commits] r146586 - in /cfe/trunk: lib/Driver/Tools.cpp test/Driver/frame-pointer.c

Rafael Espindola rafael.espindola at gmail.com
Wed Dec 14 13:02:23 PST 2011


Author: rafael
Date: Wed Dec 14 15:02:23 2011
New Revision: 146586

URL: http://llvm.org/viewvc/llvm-project?rev=146586&view=rev
Log:
Don't use the frame pointer on linux x86 and x86_64 if optimizing. This
matches gcc's behavior.

Fixes PR8186.

Added:
    cfe/trunk/test/Driver/frame-pointer.c
Modified:
    cfe/trunk/lib/Driver/Tools.cpp

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=146586&r1=146585&r2=146586&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Wed Dec 14 15:02:23 2011
@@ -1195,6 +1195,24 @@
   CmdArgs.push_back("-export-dynamic");
 }
 
+static bool shouldUseFramePointer(const ArgList &Args,
+                                  const llvm::Triple &Triple) {
+  if (Arg *A = Args.getLastArg(options::OPT_fno_omit_frame_pointer,
+                               options::OPT_fomit_frame_pointer))
+    return A->getOption().matches(options::OPT_fno_omit_frame_pointer);
+
+  // Don't use a frame poiter on liunx x86 and x86_64 if optimizing.
+  if ((Triple.getArch() == llvm::Triple::x86_64 ||
+       Triple.getArch() == llvm::Triple::x86) &&
+      Triple.getOS() == llvm::Triple::Linux) {
+    if (Arg *A = Args.getLastArg(options::OPT_O_Group))
+      if (!A->getOption().matches(options::OPT_O0))
+        return false;
+  }
+
+  return true;
+}
+
 void Clang::ConstructJob(Compilation &C, const JobAction &JA,
                          const InputInfo &Output,
                          const InputInfoList &Inputs,
@@ -1408,8 +1426,7 @@
     CmdArgs.push_back("-mrtd");
 
   // FIXME: Set --enable-unsafe-fp-math.
-  if (Args.hasFlag(options::OPT_fno_omit_frame_pointer,
-                   options::OPT_fomit_frame_pointer))
+  if (shouldUseFramePointer(Args, getToolChain().getTriple()))
     CmdArgs.push_back("-mdisable-fp-elim");
   if (!Args.hasFlag(options::OPT_fzero_initialized_in_bss,
                     options::OPT_fno_zero_initialized_in_bss))

Added: cfe/trunk/test/Driver/frame-pointer.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/frame-pointer.c?rev=146586&view=auto
==============================================================================
--- cfe/trunk/test/Driver/frame-pointer.c (added)
+++ cfe/trunk/test/Driver/frame-pointer.c Wed Dec 14 15:02:23 2011
@@ -0,0 +1,24 @@
+// RUN: %clang -ccc-host-triple i386-pc-linux -### -S -O0 %s -o %t.s 2>&1 | FileCheck -check-prefix=CHECK0-32 %s
+// RUN: %clang -ccc-host-triple i386-pc-linux -### -S -O1 %s -o %t.s 2>&1 | FileCheck -check-prefix=CHECK1-32 %s
+// RUN: %clang -ccc-host-triple i386-pc-linux -### -S -O2 %s -o %t.s 2>&1 | FileCheck -check-prefix=CHECK2-32 %s
+// RUN: %clang -ccc-host-triple i386-pc-linux -### -S -O3 %s -o %t.s 2>&1 | FileCheck -check-prefix=CHECK3-32 %s
+// RUN: %clang -ccc-host-triple i386-pc-linux -### -S -Os %s -o %t.s 2>&1 | FileCheck -check-prefix=CHECKs-32 %s
+
+
+// RUN: %clang -ccc-host-triple x86_64-pc-linux -### -S -O0 %s -o %t.s 2>&1 | FileCheck -check-prefix=CHECK0-64 %s
+// RUN: %clang -ccc-host-triple x86_64-pc-linux -### -S -O1 %s -o %t.s 2>&1 | FileCheck -check-prefix=CHECK1-64 %s
+// RUN: %clang -ccc-host-triple x86_64-pc-linux -### -S -O2 %s -o %t.s 2>&1 | FileCheck -check-prefix=CHECK2-64 %s
+// RUN: %clang -ccc-host-triple x86_64-pc-linux -### -S -O3 %s -o %t.s 2>&1 | FileCheck -check-prefix=CHECK3-64 %s
+// RUN: %clang -ccc-host-triple x86_64-pc-linux -### -S -Os %s -o %t.s 2>&1 | FileCheck -check-prefix=CHECKs-64 %s
+
+// CHECK0-32: -mdisable-fp-elim
+// CHECK1-32-NOT: -mdisable-fp-elim
+// CHECK2-32-NOT: -mdisable-fp-elim
+// CHECK3-32-NOT: -mdisable-fp-elim
+// CHECKs-32-NOT: -mdisable-fp-elim
+
+// CHECK0-64: -mdisable-fp-elim
+// CHECK1-64-NOT: -mdisable-fp-elim
+// CHECK2-64-NOT: -mdisable-fp-elim
+// CHECK3-64-NOT: -mdisable-fp-elim
+// CHECKs-64-NOT: -mdisable-fp-elim





More information about the cfe-commits mailing list