[PATCH] D30920: Do not pass -Os and -Oz to the Gold plugin

Pirama Arumuga Nainar via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 14 09:27:00 PDT 2017


pirama updated this revision to Diff 91738.
pirama added a comment.

Explicitly pass -O2 instead of relying on the default opt level.


https://reviews.llvm.org/D30920

Files:
  lib/Driver/ToolChains/CommonArgs.cpp
  test/Driver/gold-lto.c


Index: test/Driver/gold-lto.c
===================================================================
--- test/Driver/gold-lto.c
+++ test/Driver/gold-lto.c
@@ -26,3 +26,12 @@
 // RUN: %clang -target i686-linux-android -### %t.o -flto 2>&1 \
 // RUN:     | FileCheck %s --check-prefix=CHECK-X86-ANDROID
 // CHECK-X86-ANDROID: "-plugin" "{{.*}}/LLVMgold.so"
+//
+// Test that -Os and -Oz are not passed to the plugin
+// RUN: %clang -### %t.o -flto -Os 2>&1 \
+// RUN:     | FileCheck %s --implicit-check-not "-plugin-opt=Os" \
+// RUN:           --check-prefix=CHECK-O2
+// RUN: %clang -### %t.o -flto -Oz 2>&1 \
+// RUN:     | FileCheck %s --implicit-check-not "-plugin-opt=Oz" \
+// RUN:           --check-prefix=CHECK-O2
+// CHECK-O2: "-plugin-opt=O2"
Index: lib/Driver/ToolChains/CommonArgs.cpp
===================================================================
--- lib/Driver/ToolChains/CommonArgs.cpp
+++ lib/Driver/ToolChains/CommonArgs.cpp
@@ -368,9 +368,16 @@
     if (A->getOption().matches(options::OPT_O4) ||
         A->getOption().matches(options::OPT_Ofast))
       OOpt = "3";
-    else if (A->getOption().matches(options::OPT_O))
-      OOpt = A->getValue();
-    else if (A->getOption().matches(options::OPT_O0))
+    else if (A->getOption().matches(options::OPT_O)) {
+      StringRef OptLevel = A->getValue();
+      // -Os and -Oz add corresponding attributes to functions.  Just use -O2
+      // for these optimization levels.  Pass other optimization levels through
+      // to the plugin.
+      if (OptLevel == "s" || OptLevel == "z")
+        OOpt = "2";
+      else
+        OOpt = OptLevel;
+    } else if (A->getOption().matches(options::OPT_O0))
       OOpt = "0";
     if (!OOpt.empty())
       CmdArgs.push_back(Args.MakeArgString(Twine("-plugin-opt=O") + OOpt));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30920.91738.patch
Type: text/x-patch
Size: 1794 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170314/19c21a00/attachment-0001.bin>


More information about the cfe-commits mailing list