[PATCH] D24998: Add a new optimization option -Og

Sylvestre Ledru via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 27 20:41:30 PDT 2016


sylvestre.ledru created this revision.
sylvestre.ledru added a reviewer: rengolin.
sylvestre.ledru added a subscriber: cfe-commits.

Just like gcc, we should have the -Og option as more and more software are using it:
https://llvm.org/bugs/show_bug.cgi?id=20765

https://reviews.llvm.org/D24998

Files:
  docs/CommandGuide/clang.rst
  lib/Frontend/CompilerInvocation.cpp
  test/Driver/debug-options.c
  test/Preprocessor/init.c

Index: test/Preprocessor/init.c
===================================================================
--- test/Preprocessor/init.c
+++ test/Preprocessor/init.c
@@ -205,6 +205,12 @@
 // O1:#define __OPTIMIZE__ 1
 //
 //
+// RUN: %clang_cc1 -Og -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix O1 %s
+//
+// Og-NOT:#define __OPTIMIZE_SIZE__
+// Og:#define __OPTIMIZE__ 1
+//
+//
 // RUN: %clang_cc1 -Os -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix Os %s
 //
 // Os:#define __OPTIMIZE_SIZE__ 1
Index: test/Driver/debug-options.c
===================================================================
--- test/Driver/debug-options.c
+++ test/Driver/debug-options.c
@@ -18,6 +18,9 @@
 // RUN: %clang -### -c -gsce %s -target x86_64-linux-gnu 2>&1 \
 // RUN:             | FileCheck -check-prefix=G -check-prefix=G_SCE %s
 
+// RUN: %clang -### -c -Og -g %s -target x86_64-linux-gnu 2>&1 \
+// RUN:             | FileCheck -check-prefix=G -check-prefix=G_GDB %s
+
 // RUN: %clang -### -c -g %s -target x86_64-apple-darwin 2>&1 \
 // RUN:             | FileCheck -check-prefix=G_DARWIN -check-prefix=G_LLDB %s
 // RUN: %clang -### -c -g2 %s -target x86_64-apple-darwin 2>&1 \
Index: lib/Frontend/CompilerInvocation.cpp
===================================================================
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -98,6 +98,10 @@
     if (S == "s" || S == "z" || S.empty())
       return 2;
 
+    if (S == "g") {
+        return 1;
+    }
+
     return getLastArgIntValue(Args, OPT_O, DefaultOpt, Diags);
   }
 
Index: docs/CommandGuide/clang.rst
===================================================================
--- docs/CommandGuide/clang.rst
+++ docs/CommandGuide/clang.rst
@@ -226,7 +226,7 @@
 Code Generation Options
 ~~~~~~~~~~~~~~~~~~~~~~~
 
-.. option:: -O0, -O1, -O2, -O3, -Ofast, -Os, -Oz, -O, -O4
+.. option:: -O0, -O1, -O2, -O3, -Ofast, -Os, -Oz, -Og, -O, -O4
 
   Specify which optimization level to use:
 
@@ -252,6 +252,8 @@
     :option:`-Oz` Like :option:`-Os` (and thus :option:`-O2`), but reduces code
     size further.
 
+    :option:`-Og` Like :option:`-O1`.
+
     :option:`-O` Equivalent to :option:`-O2`.
 
     :option:`-O4` and higher


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24998.72757.patch
Type: text/x-patch
Size: 2241 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160928/65dff38d/attachment-0001.bin>


More information about the cfe-commits mailing list