Skip to content

Commit d340ccc

Browse files
committed
Add a new optimization option -Og
Summary: 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 Reviewers: echristo, dberlin, dblaikie, keith.walker.arm, rengolin Subscribers: aprantl, friss, mehdi_amini, RKSimon, probinson, majnemer, cfe-commits Differential Revision: https://reviews.llvm.org/D24998 llvm-svn: 286602
1 parent 31ee813 commit d340ccc

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

clang/docs/CommandGuide/clang.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ number of cross compilers, or may only support a native target.
226226
Code Generation Options
227227
~~~~~~~~~~~~~~~~~~~~~~~
228228

229-
.. option:: -O0, -O1, -O2, -O3, -Ofast, -Os, -Oz, -O, -O4
229+
.. option:: -O0, -O1, -O2, -O3, -Ofast, -Os, -Oz, -Og, -O, -O4
230230

231231
Specify which optimization level to use:
232232

@@ -252,6 +252,9 @@ Code Generation Options
252252
:option:`-Oz` Like :option:`-Os` (and thus :option:`-O2`), but reduces code
253253
size further.
254254

255+
:option:`-Og` Like :option:`-O1`. In future versions, this option might
256+
disable different optimizations in order to improve debuggability.
257+
255258
:option:`-O` Equivalent to :option:`-O2`.
256259

257260
:option:`-O4` and higher

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ static unsigned getOptimizationLevel(ArgList &Args, InputKind IK,
9898
if (S == "s" || S == "z" || S.empty())
9999
return 2;
100100

101+
if (S == "g")
102+
return 1;
103+
101104
return getLastArgIntValue(Args, OPT_O, DefaultOpt, Diags);
102105
}
103106

clang/test/Preprocessor/init.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,12 @@
205205
// O1:#define __OPTIMIZE__ 1
206206
//
207207
//
208+
// RUN: %clang_cc1 -Og -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix Og %s
209+
//
210+
// Og-NOT:#define __OPTIMIZE_SIZE__
211+
// Og :#define __OPTIMIZE__ 1
212+
//
213+
//
208214
// RUN: %clang_cc1 -Os -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix Os %s
209215
//
210216
// Os:#define __OPTIMIZE_SIZE__ 1

0 commit comments

Comments
 (0)