jansvoboda11 updated this revision to Diff 307034. jansvoboda11 added a comment. Herald added a project: LLVM. Herald added a subscriber: llvm-commits.
Reduce template instantiations, remove names of unused parameters Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D83694/new/ https://reviews.llvm.org/D83694 Files: clang/include/clang/Driver/Options.td clang/lib/Frontend/CompilerInvocation.cpp llvm/include/llvm/Option/OptParser.td
Index: llvm/include/llvm/Option/OptParser.td =================================================================== --- llvm/include/llvm/Option/OptParser.td +++ llvm/include/llvm/Option/OptParser.td @@ -170,7 +170,7 @@ 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#">)"; } Index: clang/lib/Frontend/CompilerInvocation.cpp =================================================================== --- clang/lib/Frontend/CompilerInvocation.cpp +++ clang/lib/Frontend/CompilerInvocation.cpp @@ -134,20 +134,45 @@ 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(std::uint64_t) && + std::is_trivially_constructible<T, std::uint64_t>::value && + std::is_trivially_constructible<std::uint64_t, T>::value; +} + +template <typename T, std::enable_if_t<is_int_convertible<T>(), bool> = false> +static FlagToValueNormalizer<std::uint64_t> makeFlagToValueNormalizer(T Value) { + return FlagToValueNormalizer<std::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, @@ -1552,13 +1577,8 @@ 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. @@ -1573,8 +1593,6 @@ 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. Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -429,7 +429,8 @@ "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 @@ 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]>;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits