[llvm-branch-commits] [clang] 8e41a68 - [clang][cli] Port DependencyOutput option flags to new option parsing system
Jan Svoboda via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Dec 1 01:45:22 PST 2020
Author: Jan Svoboda
Date: 2020-12-01T10:36:12+01:00
New Revision: 8e41a688a5b1000b51c61b9d103545791c54af17
URL: https://github.com/llvm/llvm-project/commit/8e41a688a5b1000b51c61b9d103545791c54af17
DIFF: https://github.com/llvm/llvm-project/commit/8e41a688a5b1000b51c61b9d103545791c54af17.diff
LOG: [clang][cli] Port DependencyOutput option flags to new option parsing system
Depends on D91861.
Reviewed By: dexonsmith
Original patch by Daniel Grumberg.
Differential Revision: https://reviews.llvm.org/D83694
Added:
Modified:
clang/include/clang/Driver/Options.td
clang/lib/Frontend/CompilerInvocation.cpp
llvm/include/llvm/Option/OptParser.td
Removed:
################################################################################
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index a8ab5cc2494c..24662f15539d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -429,7 +429,8 @@ def G : JoinedOrSeparate<["-"], "G">, Flags<[NoXarchOption]>, Group<m_Group>,
"into small data section (MIPS / Hexagon)">;
def G_EQ : Joined<["-"], "G=">, Flags<[NoXarchOption]>, Group<m_Group>, Alias<G>;
def H : Flag<["-"], "H">, Flags<[CC1Option]>, Group<Preprocessor_Group>,
- HelpText<"Show header includes and nesting depth">;
+ HelpText<"Show header includes and nesting depth">,
+ MarshallingInfoFlag<"DependencyOutputOpts.ShowHeaderIncludes">;
def I_ : Flag<["-"], "I-">, Group<I_Group>,
HelpText<"Restrict all prior -I flags to double-quoted inclusion and "
"remove current directory from include path">;
@@ -455,17 +456,21 @@ def MF : JoinedOrSeparate<["-"], "MF">, Group<M_Group>,
HelpText<"Write depfile output from -MMD, -MD, -MM, or -M to <file>">,
MetaVarName<"<file>">;
def MG : Flag<["-"], "MG">, Group<M_Group>, Flags<[CC1Option]>,
- HelpText<"Add missing headers to depfile">;
+ HelpText<"Add missing headers to depfile">,
+ MarshallingInfoFlag<"DependencyOutputOpts.AddMissingHeaderDeps">;
def MJ : JoinedOrSeparate<["-"], "MJ">, Group<M_Group>,
HelpText<"Write a compilation database entry per input">;
def MP : Flag<["-"], "MP">, Group<M_Group>, Flags<[CC1Option]>,
- HelpText<"Create phony target for each dependency (other than main file)">;
+ HelpText<"Create phony target for each dependency (other than main file)">,
+ MarshallingInfoFlag<"DependencyOutputOpts.UsePhonyTargets">;
def MQ : JoinedOrSeparate<["-"], "MQ">, Group<M_Group>, Flags<[CC1Option]>,
HelpText<"Specify name of main file output to quote in depfile">;
def MT : JoinedOrSeparate<["-"], "MT">, Group<M_Group>, Flags<[CC1Option]>,
HelpText<"Specify name of main file output in depfile">;
def MV : Flag<["-"], "MV">, Group<M_Group>, Flags<[CC1Option]>,
- HelpText<"Use NMake/Jom format for the depfile">;
+ HelpText<"Use NMake/Jom format for the depfile">,
+ MarshallingInfoFlag<"DependencyOutputOpts.OutputFormat", "DependencyOutputFormat::Make">,
+ Normalizer<"makeFlagToValueNormalizer(DependencyOutputFormat::NMake)">;
def Mach : Flag<["-"], "Mach">, Group<Link_Group>;
def O0 : Flag<["-"], "O0">, Group<O_Group>, Flags<[CC1Option, HelpHidden]>;
def O4 : Flag<["-"], "O4">, Group<O_Group>, Flags<[CC1Option, HelpHidden]>;
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index f23d1e398a4a..761f9ebd2381 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -144,20 +144,44 @@ static Optional<bool> normalizeSimpleNegativeFlag(OptSpecifier Opt, unsigned,
return None;
}
-void denormalizeSimpleFlag(SmallVectorImpl<const char *> &Args,
- const char *Spelling,
- CompilerInvocation::StringAllocator SA,
- unsigned TableIndex, unsigned Value) {
+/// The tblgen-erated code passes in a fifth parameter of an arbitrary type, but
+/// denormalizeSimpleFlags never looks at it. Avoid bloating compile-time with
+/// unnecessary template instantiations and just ignore it with a variadic
+/// argument.
+static void denormalizeSimpleFlag(SmallVectorImpl<const char *> &Args,
+ const char *Spelling,
+ CompilerInvocation::StringAllocator, unsigned,
+ /*T*/...) {
Args.push_back(Spelling);
}
-template <typename T, T Value>
-static llvm::Optional<T>
-normalizeFlagToValue(OptSpecifier Opt, unsigned TableIndex, const ArgList &Args,
- DiagnosticsEngine &Diags) {
- if (Args.hasArg(Opt))
- return Value;
- return None;
+namespace {
+template <typename T> struct FlagToValueNormalizer {
+ T Value;
+
+ Optional<T> operator()(OptSpecifier Opt, unsigned, const ArgList &Args,
+ DiagnosticsEngine &) {
+ if (Args.hasArg(Opt))
+ return Value;
+ return None;
+ }
+};
+} // namespace
+
+template <typename T> static constexpr bool is_int_convertible() {
+ return sizeof(T) <= sizeof(uint64_t) &&
+ std::is_trivially_constructible<T, uint64_t>::value &&
+ std::is_trivially_constructible<uint64_t, T>::value;
+}
+
+template <typename T, std::enable_if_t<is_int_convertible<T>(), bool> = false>
+static FlagToValueNormalizer<uint64_t> makeFlagToValueNormalizer(T Value) {
+ return FlagToValueNormalizer<uint64_t>{Value};
+}
+
+template <typename T, std::enable_if_t<!is_int_convertible<T>(), bool> = false>
+static FlagToValueNormalizer<T> makeFlagToValueNormalizer(T Value) {
+ return FlagToValueNormalizer<T>{std::move(Value)};
}
static Optional<bool> normalizeBooleanFlag(OptSpecifier PosOpt,
@@ -1590,13 +1614,8 @@ static void ParseDependencyOutputArgs(DependencyOutputOptions &Opts,
ArgList &Args) {
Opts.OutputFile = std::string(Args.getLastArgValue(OPT_dependency_file));
Opts.Targets = Args.getAllArgValues(OPT_MT);
- Opts.IncludeSystemHeaders = Args.hasArg(OPT_sys_header_deps);
- Opts.IncludeModuleFiles = Args.hasArg(OPT_module_file_deps);
- Opts.UsePhonyTargets = Args.hasArg(OPT_MP);
- Opts.ShowHeaderIncludes = Args.hasArg(OPT_H);
Opts.HeaderIncludeOutputFile =
std::string(Args.getLastArgValue(OPT_header_include_file));
- Opts.AddMissingHeaderDeps = Args.hasArg(OPT_MG);
if (Args.hasArg(OPT_show_includes)) {
// Writing both /showIncludes and preprocessor output to stdout
// would produce interleaved output, so use stderr for /showIncludes.
@@ -1611,8 +1630,6 @@ static void ParseDependencyOutputArgs(DependencyOutputOptions &Opts,
Opts.DOTOutputFile = std::string(Args.getLastArgValue(OPT_dependency_dot));
Opts.ModuleDependencyOutputDir =
std::string(Args.getLastArgValue(OPT_module_dependency_dir));
- if (Args.hasArg(OPT_MV))
- Opts.OutputFormat = DependencyOutputFormat::NMake;
// Add sanitizer blacklists as extra dependencies.
// They won't be discovered by the regular preprocessor, so
// we let make / ninja to know about this implicit dependency.
diff --git a/llvm/include/llvm/Option/OptParser.td b/llvm/include/llvm/Option/OptParser.td
index 67bc73dbd016..717b5facf53e 100644
--- a/llvm/include/llvm/Option/OptParser.td
+++ b/llvm/include/llvm/Option/OptParser.td
@@ -170,7 +170,7 @@ class MarshallingInfoFlag<code keypath, code defaultvalue = "false">
class MarshallingInfoBitfieldFlag<code keypath, code value>
: MarshallingInfoFlag<keypath, "0u"> {
- code Normalizer = "(normalizeFlagToValue<unsigned, "#value#">)";
+ code Normalizer = "makeFlagToValueNormalizer("#value#")";
code ValueMerger = "mergeMaskValue";
code ValueExtractor = "(extractMaskValue<unsigned, decltype("#value#"), "#value#">)";
}
More information about the llvm-branch-commits
mailing list