Author: hans Date: Tue Sep 25 07:10:26 2018 New Revision: 342977 URL: http://llvm.org/viewvc/llvm-project?rev=342977&view=rev Log: [clang-cl] Provide separate flags for all the /O variants
This provides better help text in "clang-cl /?". Also it cleans things up a bit: previously "/Od" could be handled either as a separate flag aliased to "-O0", or by the main optimization flag processing in TranslateOptArg. With this patch, all the flags get aliased back to /O so they're handled by TranslateOptArg. Thanks to Nico for the idea! Differential revision: https://reviews.llvm.org/D52266 Modified: cfe/trunk/include/clang/Driver/CLCompatOptions.td cfe/trunk/lib/Driver/ToolChains/MSVC.cpp cfe/trunk/test/Driver/Xarch.c Modified: cfe/trunk/include/clang/Driver/CLCompatOptions.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CLCompatOptions.td?rev=342977&r1=342976&r2=342977&view=diff ============================================================================== --- cfe/trunk/include/clang/Driver/CLCompatOptions.td (original) +++ cfe/trunk/include/clang/Driver/CLCompatOptions.td Tue Sep 25 07:10:26 2018 @@ -85,16 +85,19 @@ def _SLASH_GA : CLFlag<"GA">, Alias<ftls HelpText<"Assume thread-local variables are defined in the executable">; def _SLASH_GR : CLFlag<"GR">, HelpText<"Enable emission of RTTI data">; def _SLASH_GR_ : CLFlag<"GR-">, HelpText<"Disable emission of RTTI data">; +def _SLASH_GF : CLIgnoredFlag<"GF">, HelpText<"Enable string pooling (default)">; def _SLASH_GF_ : CLFlag<"GF-">, HelpText<"Disable string pooling">, Alias<fwritable_strings>; -def _SLASH_GS : CLFlag<"GS">, HelpText<"Enable buffer security check">; +def _SLASH_GS : CLFlag<"GS">, HelpText<"Enable buffer security check (default)">; def _SLASH_GS_ : CLFlag<"GS-">, HelpText<"Disable buffer security check">; -def _SLASH_Gs : CLJoined<"Gs">, HelpText<"Set stack probe size">, - Alias<mstack_probe_size>; +// FIXME: Not sure /Gs really means /Gs0 (see PR39074). +def : CLFlag<"Gs">, HelpText<"Same as /Gs0">, Alias<mstack_probe_size>, AliasArgs<["0"]>; +def _SLASH_Gs : CLJoined<"Gs">, + HelpText<"Set stack probe size (default 4096)">, Alias<mstack_probe_size>; def _SLASH_Gy : CLFlag<"Gy">, HelpText<"Put each function in its own section">, Alias<ffunction_sections>; def _SLASH_Gy_ : CLFlag<"Gy-">, - HelpText<"Don't put each function in its own section">, + HelpText<"Don't put each function in its own section (default)">, Alias<fno_function_sections>; def _SLASH_Gw : CLFlag<"Gw">, HelpText<"Put each data item in its own section">, Alias<fdata_sections>; @@ -109,18 +112,43 @@ def _SLASH_I : CLJoinedOrSeparate<"I">, Alias<I>; def _SLASH_J : CLFlag<"J">, HelpText<"Make char type unsigned">, Alias<funsigned_char>; -def _SLASH_O0 : CLFlag<"O0">, Alias<O0>; -// /Oy- is handled by the /O option because /Oy- only has an effect on 32-bit. -def _SLASH_O : CLJoined<"O">, HelpText<"Optimization level">; -def _SLASH_Od : CLFlag<"Od">, HelpText<"Disable optimization">, Alias<O0>; -def _SLASH_Oi : CLFlag<"Oi">, HelpText<"Enable use of builtin functions">, - Alias<fbuiltin>; -def _SLASH_Oi_ : CLFlag<"Oi-">, HelpText<"Disable use of builtin functions">, - Alias<fno_builtin>; -def _SLASH_Os : CLFlag<"Os">, HelpText<"Optimize for size">, Alias<O>, - AliasArgs<["s"]>; -def _SLASH_Ot : CLFlag<"Ot">, HelpText<"Optimize for speed">, Alias<O>, - AliasArgs<["2"]>; + +// The _SLASH_O option handles all the /O flags, but we also provide separate +// aliased options to provide separate help messages. +def _SLASH_O : CLJoined<"O">, + HelpText<"Set multiple /O flags at once; e.g. '/O2y-' is the same as '/O2 /y-'">, + MetaVarName<"<flags>">; +// FIXME: Not sure why we have -O0 here; MSVC doesn't support that. +def : CLFlag<"O0">, Alias<O0>, HelpText<"Disable optimization">; +def : CLFlag<"O1">, Alias<_SLASH_O>, AliasArgs<["1"]>, + HelpText<"Optimize for size (equivalent to /Og /Os /Oy /Ob2 /Gs /GF /Gy)">; +def : CLFlag<"O2">, Alias<_SLASH_O>, AliasArgs<["2"]>, + HelpText<"Optimize for speed (equivalent to /Og /Oi /Ot /Oy /Ob2 /Gs /GF /Gy)">; +def : CLFlag<"Ob0">, Alias<_SLASH_O>, AliasArgs<["b0"]>, + HelpText<"Disable function inlining">; +def : CLFlag<"Ob1">, Alias<_SLASH_O>, AliasArgs<["b1"]>, + HelpText<"Only inline functions which are (explicitly or implicitly) marked inline">; +def : CLFlag<"Ob2">, Alias<_SLASH_O>, AliasArgs<["b2"]>, + HelpText<"Inline functions as deemed beneficial by the compiler">; +def : CLFlag<"Od">, Alias<_SLASH_O>, AliasArgs<["d"]>, + HelpText<"Disable optimization">; +def : CLFlag<"Og">, Alias<_SLASH_O>, AliasArgs<["g"]>, + HelpText<"No effect">; +def : CLFlag<"Oi">, Alias<_SLASH_O>, AliasArgs<["i"]>, + HelpText<"Enable use of builtin functions">; +def : CLFlag<"Oi-">, Alias<_SLASH_O>, AliasArgs<["i-"]>, + HelpText<"Disable use of builtin functions">; +def : CLFlag<"Os">, Alias<_SLASH_O>, AliasArgs<["s"]>, + HelpText<"Optimize for size">; +def : CLFlag<"Ot">, Alias<_SLASH_O>, AliasArgs<["t"]>, + HelpText<"Optimize for speed">; +def : CLFlag<"Ox">, Alias<_SLASH_O>, AliasArgs<["x"]>, + HelpText<"Deprecated (equivalent to /Og /Oi /Ot /Oy /Ob2); use /O2 instead">; +def : CLFlag<"Oy">, Alias<_SLASH_O>, AliasArgs<["y"]>, + HelpText<"Enable frame pointer omission (x86 only)">; +def : CLFlag<"Oy-">, Alias<_SLASH_O>, AliasArgs<["y-"]>, + HelpText<"Disable frame pointer omission (x86 only, default)">; + def _SLASH_QUESTION : CLFlag<"?">, Alias<help>, HelpText<"Display available options">; def _SLASH_Qvec : CLFlag<"Qvec">, @@ -326,10 +354,8 @@ def _SLASH_errorReport : CLIgnoredJoined def _SLASH_FC : CLIgnoredFlag<"FC">; def _SLASH_Fd : CLIgnoredJoined<"Fd">; def _SLASH_FS : CLIgnoredFlag<"FS">; -def _SLASH_GF : CLIgnoredFlag<"GF">; def _SLASH_kernel_ : CLIgnoredFlag<"kernel-">; def _SLASH_nologo : CLIgnoredFlag<"nologo">; -def _SLASH_Og : CLIgnoredFlag<"Og">; def _SLASH_openmp_ : CLIgnoredFlag<"openmp-">; def _SLASH_permissive_ : CLIgnoredFlag<"permissive-">; def _SLASH_RTC : CLIgnoredJoined<"RTC">; Modified: cfe/trunk/lib/Driver/ToolChains/MSVC.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/MSVC.cpp?rev=342977&r1=342976&r2=342977&view=diff ============================================================================== --- cfe/trunk/lib/Driver/ToolChains/MSVC.cpp (original) +++ cfe/trunk/lib/Driver/ToolChains/MSVC.cpp Tue Sep 25 07:10:26 2018 @@ -1378,6 +1378,7 @@ static void TranslateOptArg(Arg *A, llvm } break; case 'g': + A->claim(); break; case 'i': if (I + 1 != E && OptStr[I + 1] == '-') { Modified: cfe/trunk/test/Driver/Xarch.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/Xarch.c?rev=342977&r1=342976&r2=342977&view=diff ============================================================================== --- cfe/trunk/test/Driver/Xarch.c (original) +++ cfe/trunk/test/Driver/Xarch.c Tue Sep 25 07:10:26 2018 @@ -1,10 +1,10 @@ -// RUN: %clang -target i386-apple-darwin9 -m32 -Xarch_i386 -O2 %s -S -### 2>&1 | FileCheck -check-prefix=O2ONCE %s -// O2ONCE: "-O2" -// O2ONCE-NOT: "-O2" +// RUN: %clang -target i386-apple-darwin9 -m32 -Xarch_i386 -O3 %s -S -### 2>&1 | FileCheck -check-prefix=O3ONCE %s +// O3ONCE: "-O3" +// O3ONCE-NOT: "-O3" -// RUN: %clang -target i386-apple-darwin9 -m64 -Xarch_i386 -O2 %s -S -### 2>&1 | FileCheck -check-prefix=O2NONE %s -// O2NONE-NOT: "-O2" -// O2NONE: argument unused during compilation: '-Xarch_i386 -O2' +// RUN: %clang -target i386-apple-darwin9 -m64 -Xarch_i386 -O3 %s -S -### 2>&1 | FileCheck -check-prefix=O3NONE %s +// O3NONE-NOT: "-O3" +// O3NONE: argument unused during compilation: '-Xarch_i386 -O3' // RUN: not %clang -target i386-apple-darwin9 -m32 -Xarch_i386 -o -Xarch_i386 -S %s -S -Xarch_i386 -o 2>&1 | FileCheck -check-prefix=INVALID %s // INVALID: error: invalid Xarch argument: '-Xarch_i386 -o' _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits