Author: Mehdi Amini Date: 2021-07-16T07:35:13Z New Revision: 8d051d854619956de633047409149cdab1e3319a
URL: https://github.com/llvm/llvm-project/commit/8d051d854619956de633047409149cdab1e3319a DIFF: https://github.com/llvm/llvm-project/commit/8d051d854619956de633047409149cdab1e3319a.diff LOG: Revert "Use ManagedStatic and lazy initialization of cl::opt in libSupport to make it free of global initializer" This reverts commit af9321739b20becf170e6bb5060b8d780e1dc8dd. Still some specific config broken in some way that requires more investigation. Added: Modified: clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp clang-tools-extra/clangd/indexer/IndexerMain.cpp clang/tools/clang-refactor/ClangRefactor.cpp llvm/docs/CommandLine.rst llvm/include/llvm/Support/ARMAttributeParser.h llvm/include/llvm/Support/ARMBuildAttributes.h llvm/include/llvm/Support/CommandLine.h llvm/include/llvm/Support/RISCVAttributeParser.h llvm/include/llvm/Support/RISCVAttributes.h llvm/include/llvm/Support/ScopedPrinter.h llvm/include/llvm/Support/WithColor.h llvm/lib/Support/ARMBuildAttrs.cpp llvm/lib/Support/CommandLine.cpp llvm/lib/Support/Debug.cpp llvm/lib/Support/DebugCounter.cpp llvm/lib/Support/ELFAttributeParser.cpp llvm/lib/Support/GraphWriter.cpp llvm/lib/Support/RISCVAttributes.cpp llvm/lib/Support/RandomNumberGenerator.cpp llvm/lib/Support/Signals.cpp llvm/lib/Support/Statistic.cpp llvm/lib/Support/TimeProfiler.cpp llvm/lib/Support/Timer.cpp llvm/lib/Support/TypeSize.cpp llvm/lib/Support/Windows/Signals.inc llvm/lib/Support/WithColor.cpp llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp llvm/unittests/Support/ARMAttributeParser.cpp llvm/unittests/Support/CommandLineTest.cpp llvm/unittests/Support/RISCVAttributeParserTest.cpp Removed: llvm/lib/Support/DebugOptions.h ################################################################################ diff --git a/clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp b/clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp index 581dae7557295..49f16e72be92a 100644 --- a/clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp +++ b/clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp @@ -91,7 +91,7 @@ class Command { // By resetting the parser options, we lost the standard -help flag. llvm::cl::opt<bool, false, llvm::cl::parser<bool>> Help{ "help", llvm::cl::desc("Display available options"), - llvm::cl::ValueDisallowed, llvm::cl::cat(llvm::cl::getGeneralCategory())}; + llvm::cl::ValueDisallowed, llvm::cl::cat(llvm::cl::GeneralCategory)}; // FIXME: Allow commands to signal failure. virtual void run() = 0; diff --git a/clang-tools-extra/clangd/indexer/IndexerMain.cpp b/clang-tools-extra/clangd/indexer/IndexerMain.cpp index 533334fcc1f28..fd8404be677a2 100644 --- a/clang-tools-extra/clangd/indexer/IndexerMain.cpp +++ b/clang-tools-extra/clangd/indexer/IndexerMain.cpp @@ -124,7 +124,7 @@ int main(int argc, const char **argv) { )"; auto Executor = clang::tooling::createExecutorFromCommandLineArgs( - argc, argv, llvm::cl::getGeneralCategory(), Overview); + argc, argv, llvm::cl::GeneralCategory, Overview); if (!Executor) { llvm::errs() << llvm::toString(Executor.takeError()) << "\n"; diff --git a/clang/tools/clang-refactor/ClangRefactor.cpp b/clang/tools/clang-refactor/ClangRefactor.cpp index eacd00a601dbe..01edad43164fb 100644 --- a/clang/tools/clang-refactor/ClangRefactor.cpp +++ b/clang/tools/clang-refactor/ClangRefactor.cpp @@ -38,11 +38,11 @@ namespace opts { static cl::OptionCategory CommonRefactorOptions("Refactoring options"); static cl::opt<bool> Verbose("v", cl::desc("Use verbose output"), - cl::cat(cl::getGeneralCategory()), + cl::cat(cl::GeneralCategory), cl::sub(*cl::AllSubCommands)); static cl::opt<bool> Inplace("i", cl::desc("Inplace edit <file>s"), - cl::cat(cl::getGeneralCategory()), + cl::cat(cl::GeneralCategory), cl::sub(*cl::AllSubCommands)); } // end namespace opts @@ -613,7 +613,7 @@ int main(int argc, const char **argv) { ClangRefactorTool RefactorTool; auto ExpectedParser = CommonOptionsParser::create( - argc, argv, cl::getGeneralCategory(), cl::ZeroOrMore, + argc, argv, cl::GeneralCategory, cl::ZeroOrMore, "Clang-based refactoring tool for C, C++ and Objective-C"); if (!ExpectedParser) { llvm::errs() << ExpectedParser.takeError(); diff --git a/llvm/docs/CommandLine.rst b/llvm/docs/CommandLine.rst index fef7e39ad86d2..e549d49bd90f5 100644 --- a/llvm/docs/CommandLine.rst +++ b/llvm/docs/CommandLine.rst @@ -661,7 +661,7 @@ declared, the command line option ``-help-list`` becomes visible which will print the command line options as uncategorized list. Note that Options that are not explicitly categorized will be placed in the -``cl::getGeneralCategory()`` category. +``cl::GeneralCategory`` category. .. _Reference Guide: diff --git a/llvm/include/llvm/Support/ARMAttributeParser.h b/llvm/include/llvm/Support/ARMAttributeParser.h index 5d12b7e08d580..bf85ea14cfe33 100644 --- a/llvm/include/llvm/Support/ARMAttributeParser.h +++ b/llvm/include/llvm/Support/ARMAttributeParser.h @@ -71,9 +71,9 @@ class ARMAttributeParser : public ELFAttributeParser { public: ARMAttributeParser(ScopedPrinter *sw) - : ELFAttributeParser(sw, ARMBuildAttrs::getARMAttributeTags(), "aeabi") {} + : ELFAttributeParser(sw, ARMBuildAttrs::ARMAttributeTags, "aeabi") {} ARMAttributeParser() - : ELFAttributeParser(ARMBuildAttrs::getARMAttributeTags(), "aeabi") {} + : ELFAttributeParser(ARMBuildAttrs::ARMAttributeTags, "aeabi") {} }; } diff --git a/llvm/include/llvm/Support/ARMBuildAttributes.h b/llvm/include/llvm/Support/ARMBuildAttributes.h index 37c37522fd266..5a06fd6ca7be7 100644 --- a/llvm/include/llvm/Support/ARMBuildAttributes.h +++ b/llvm/include/llvm/Support/ARMBuildAttributes.h @@ -23,7 +23,7 @@ namespace llvm { namespace ARMBuildAttrs { -const TagNameMap &getARMAttributeTags(); +extern const TagNameMap ARMAttributeTags; enum SpecialAttr { // This is for the .cpu asm attr. It translates into one or more diff --git a/llvm/include/llvm/Support/CommandLine.h b/llvm/include/llvm/Support/CommandLine.h index 14d7e21f78b23..bcbc4f993d513 100644 --- a/llvm/include/llvm/Support/CommandLine.h +++ b/llvm/include/llvm/Support/CommandLine.h @@ -202,7 +202,7 @@ class OptionCategory { }; // The general Option Category (used as default category). -OptionCategory &getGeneralCategory(); +extern OptionCategory GeneralCategory; //===----------------------------------------------------------------------===// // SubCommand class @@ -342,7 +342,7 @@ class Option { : NumOccurrences(0), Occurrences(OccurrencesFlag), Value(0), HiddenFlag(Hidden), Formatting(NormalFormatting), Misc(0), FullyInitialized(false), Position(0), AdditionalVals(0) { - Categories.push_back(&getGeneralCategory()); + Categories.push_back(&GeneralCategory); } inline void setNumAdditionalVals(unsigned n) { AdditionalVals = n; } diff --git a/llvm/include/llvm/Support/RISCVAttributeParser.h b/llvm/include/llvm/Support/RISCVAttributeParser.h index 305adffbe851e..3e629419a7e9b 100644 --- a/llvm/include/llvm/Support/RISCVAttributeParser.h +++ b/llvm/include/llvm/Support/RISCVAttributeParser.h @@ -27,9 +27,9 @@ class RISCVAttributeParser : public ELFAttributeParser { public: RISCVAttributeParser(ScopedPrinter *sw) - : ELFAttributeParser(sw, RISCVAttrs::getRISCVAttributeTags(), "riscv") {} + : ELFAttributeParser(sw, RISCVAttrs::RISCVAttributeTags, "riscv") {} RISCVAttributeParser() - : ELFAttributeParser(RISCVAttrs::getRISCVAttributeTags(), "riscv") {} + : ELFAttributeParser(RISCVAttrs::RISCVAttributeTags, "riscv") {} }; } // namespace llvm diff --git a/llvm/include/llvm/Support/RISCVAttributes.h b/llvm/include/llvm/Support/RISCVAttributes.h index a8ce8f4d8daf4..caded9519b668 100644 --- a/llvm/include/llvm/Support/RISCVAttributes.h +++ b/llvm/include/llvm/Support/RISCVAttributes.h @@ -22,7 +22,7 @@ namespace llvm { namespace RISCVAttrs { -const TagNameMap &getRISCVAttributeTags(); +extern const TagNameMap RISCVAttributeTags; enum AttrType : unsigned { // Attribute types in ELF/.riscv.attributes. diff --git a/llvm/include/llvm/Support/ScopedPrinter.h b/llvm/include/llvm/Support/ScopedPrinter.h index 0dfe1245f7d6e..fe800e3240470 100644 --- a/llvm/include/llvm/Support/ScopedPrinter.h +++ b/llvm/include/llvm/Support/ScopedPrinter.h @@ -32,9 +32,8 @@ template <typename T> struct EnumEntry { // "Advanced Micro Devices X86-64" on GNU style StringRef AltName; T Value; - constexpr EnumEntry(StringRef N, StringRef A, T V) - : Name(N), AltName(A), Value(V) {} - constexpr EnumEntry(StringRef N, T V) : Name(N), AltName(N), Value(V) {} + EnumEntry(StringRef N, StringRef A, T V) : Name(N), AltName(A), Value(V) {} + EnumEntry(StringRef N, T V) : Name(N), AltName(N), Value(V) {} }; struct HexNumber { diff --git a/llvm/include/llvm/Support/WithColor.h b/llvm/include/llvm/Support/WithColor.h index e772ea667f4f6..1908c6eb8ea32 100644 --- a/llvm/include/llvm/Support/WithColor.h +++ b/llvm/include/llvm/Support/WithColor.h @@ -20,7 +20,7 @@ namespace cl { class OptionCategory; } -extern cl::OptionCategory &getColorCategory(); +extern cl::OptionCategory ColorCategory; // Symbolic names for various syntax elements. enum class HighlightColor { diff --git a/llvm/lib/Support/ARMBuildAttrs.cpp b/llvm/lib/Support/ARMBuildAttrs.cpp index f20521f2a2d47..5aaf0a4e7c62e 100644 --- a/llvm/lib/Support/ARMBuildAttrs.cpp +++ b/llvm/lib/Support/ARMBuildAttrs.cpp @@ -63,7 +63,6 @@ static const TagNameItem tagData[] = { {ARMBuildAttrs::ABI_align_preserved, "Tag_ABI_align8_preserved"}, }; -constexpr TagNameMap ARMAttributeTags{tagData}; -const TagNameMap &llvm::ARMBuildAttrs::getARMAttributeTags() { - return ARMAttributeTags; -} +const TagNameMap llvm::ARMBuildAttrs::ARMAttributeTags(tagData, + sizeof(tagData) / + sizeof(TagNameItem)); diff --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp index 4ae3ad4c24535..8cf7d5b1e57e2 100644 --- a/llvm/lib/Support/CommandLine.cpp +++ b/llvm/lib/Support/CommandLine.cpp @@ -16,9 +16,6 @@ //===----------------------------------------------------------------------===// #include "llvm/Support/CommandLine.h" - -#include "DebugOptions.h" - #include "llvm-c/Support.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/Optional.h" @@ -465,7 +462,7 @@ void Option::addCategory(OptionCategory &C) { // Maintain backward compatibility by replacing the default GeneralCategory // if it's still set. Otherwise, just add the new one. The GeneralCategory // must be explicitly added if you want multiple categories that include it. - if (&C != &getGeneralCategory() && Categories[0] == &getGeneralCategory()) + if (&C != &GeneralCategory && Categories[0] == &GeneralCategory) Categories[0] = &C; else if (!is_contained(Categories, &C)) Categories.push_back(&C); @@ -478,6 +475,9 @@ void Option::reset() { removeArgument(); } +// Initialise the general option category. +OptionCategory llvm::cl::GeneralCategory("General options"); + void OptionCategory::registerCategory() { GlobalParser->registerCategory(this); } @@ -1293,12 +1293,10 @@ bool cl::readConfigFile(StringRef CfgFile, StringSaver &Saver, /*MarkEOLs=*/false, /*RelativeNames=*/true); } -static void initCommonOptions(); bool cl::ParseCommandLineOptions(int argc, const char *const *argv, StringRef Overview, raw_ostream *Errs, const char *EnvVar, bool LongOptionsUseDoubleDash) { - initCommonOptions(); SmallVector<const char *, 20> NewArgv; BumpPtrAllocator A; StringSaver Saver(A); @@ -1939,9 +1937,7 @@ unsigned generic_parser_base::findOption(StringRef Name) { static StringRef EqValue = "=<value>"; static StringRef EmptyOption = "<empty>"; static StringRef OptionPrefix = " ="; -static size_t getOptionPrefixesSize() { - return OptionPrefix.size() + ArgHelpPrefix.size(); -} +static size_t OptionPrefixesSize = OptionPrefix.size() + ArgHelpPrefix.size(); static bool shouldPrintOption(StringRef Name, StringRef Description, const Option &O) { @@ -1959,7 +1955,7 @@ size_t generic_parser_base::getOptionWidth(const Option &O) const { if (!shouldPrintOption(Name, getDescription(i), O)) continue; size_t NameSize = Name.empty() ? EmptyOption.size() : Name.size(); - Size = std::max(Size, NameSize + getOptionPrefixesSize()); + Size = std::max(Size, NameSize + OptionPrefixesSize); } return Size; } else { @@ -1998,7 +1994,7 @@ void generic_parser_base::printOptionInfo(const Option &O, StringRef Description = getDescription(i); if (!shouldPrintOption(OptionName, Description, O)) continue; - size_t FirstLineIndent = OptionName.size() + getOptionPrefixesSize(); + size_t FirstLineIndent = OptionName.size() + OptionPrefixesSize; outs() << OptionPrefix << OptionName; if (OptionName.empty()) { outs() << EmptyOption; @@ -2378,6 +2374,105 @@ class HelpPrinterWrapper { } // End anonymous namespace +// Declare the four HelpPrinter instances that are used to print out help, or +// help-hidden as an uncategorized list or in categories. +static HelpPrinter UncategorizedNormalPrinter(false); +static HelpPrinter UncategorizedHiddenPrinter(true); +static CategorizedHelpPrinter CategorizedNormalPrinter(false); +static CategorizedHelpPrinter CategorizedHiddenPrinter(true); + +// Declare HelpPrinter wrappers that will decide whether or not to invoke +// a categorizing help printer +static HelpPrinterWrapper WrappedNormalPrinter(UncategorizedNormalPrinter, + CategorizedNormalPrinter); +static HelpPrinterWrapper WrappedHiddenPrinter(UncategorizedHiddenPrinter, + CategorizedHiddenPrinter); + +// Define a category for generic options that all tools should have. +static cl::OptionCategory GenericCategory("Generic Options"); + +// Define uncategorized help printers. +// --help-list is hidden by default because if Option categories are being used +// then --help behaves the same as --help-list. +static cl::opt<HelpPrinter, true, parser<bool>> HLOp( + "help-list", + cl::desc("Display list of available options (--help-list-hidden for more)"), + cl::location(UncategorizedNormalPrinter), cl::Hidden, cl::ValueDisallowed, + cl::cat(GenericCategory), cl::sub(*AllSubCommands)); + +static cl::opt<HelpPrinter, true, parser<bool>> + HLHOp("help-list-hidden", cl::desc("Display list of all available options"), + cl::location(UncategorizedHiddenPrinter), cl::Hidden, + cl::ValueDisallowed, cl::cat(GenericCategory), + cl::sub(*AllSubCommands)); + +// Define uncategorized/categorized help printers. These printers change their +// behaviour at runtime depending on whether one or more Option categories have +// been declared. +static cl::opt<HelpPrinterWrapper, true, parser<bool>> + HOp("help", cl::desc("Display available options (--help-hidden for more)"), + cl::location(WrappedNormalPrinter), cl::ValueDisallowed, + cl::cat(GenericCategory), cl::sub(*AllSubCommands)); + +static cl::alias HOpA("h", cl::desc("Alias for --help"), cl::aliasopt(HOp), + cl::DefaultOption); + +static cl::opt<HelpPrinterWrapper, true, parser<bool>> + HHOp("help-hidden", cl::desc("Display all available options"), + cl::location(WrappedHiddenPrinter), cl::Hidden, cl::ValueDisallowed, + cl::cat(GenericCategory), cl::sub(*AllSubCommands)); + +static cl::opt<bool> PrintOptions( + "print-options", + cl::desc("Print non-default options after command line parsing"), + cl::Hidden, cl::init(false), cl::cat(GenericCategory), + cl::sub(*AllSubCommands)); + +static cl::opt<bool> PrintAllOptions( + "print-all-options", + cl::desc("Print all option values after command line parsing"), cl::Hidden, + cl::init(false), cl::cat(GenericCategory), cl::sub(*AllSubCommands)); + +void HelpPrinterWrapper::operator=(bool Value) { + if (!Value) + return; + + // Decide which printer to invoke. If more than one option category is + // registered then it is useful to show the categorized help instead of + // uncategorized help. + if (GlobalParser->RegisteredOptionCategories.size() > 1) { + // unhide --help-list option so user can have uncategorized output if they + // want it. + HLOp.setHiddenFlag(NotHidden); + + CategorizedPrinter = true; // Invoke categorized printer + } else + UncategorizedPrinter = true; // Invoke uncategorized printer +} + +// Print the value of each option. +void cl::PrintOptionValues() { GlobalParser->printOptionValues(); } + +void CommandLineParser::printOptionValues() { + if (!PrintOptions && !PrintAllOptions) + return; + + SmallVector<std::pair<const char *, Option *>, 128> Opts; + sortOpts(ActiveSubCommand->OptionsMap, Opts, /*ShowHidden*/ true); + + // Compute the maximum argument length... + size_t MaxArgLen = 0; + for (size_t i = 0, e = Opts.size(); i != e; ++i) + MaxArgLen = std::max(MaxArgLen, Opts[i].second->getOptionWidth()); + + for (size_t i = 0, e = Opts.size(); i != e; ++i) + Opts[i].second->printOptionValue(MaxArgLen, PrintAllOptions); +} + +static VersionPrinterTy OverrideVersionPrinter = nullptr; + +static std::vector<VersionPrinterTy> *ExtraVersionPrinters = nullptr; + #if defined(__GNUC__) // GCC and GCC-compatible compilers define __OPTIMIZE__ when optimizations are // enabled. @@ -2433,203 +2528,59 @@ class VersionPrinter { #endif OS << '\n'; } - void operator=(bool OptionWasSpecified); -}; - -struct CommandLineCommonOptions { - // Declare the four HelpPrinter instances that are used to print out help, or - // help-hidden as an uncategorized list or in categories. - HelpPrinter UncategorizedNormalPrinter{false}; - HelpPrinter UncategorizedHiddenPrinter{true}; - CategorizedHelpPrinter CategorizedNormalPrinter{false}; - CategorizedHelpPrinter CategorizedHiddenPrinter{true}; - // Declare HelpPrinter wrappers that will decide whether or not to invoke - // a categorizing help printer - HelpPrinterWrapper WrappedNormalPrinter{UncategorizedNormalPrinter, - CategorizedNormalPrinter}; - HelpPrinterWrapper WrappedHiddenPrinter{UncategorizedHiddenPrinter, - CategorizedHiddenPrinter}; - // Define a category for generic options that all tools should have. - cl::OptionCategory GenericCategory{"Generic Options"}; - - // Define uncategorized help printers. - // --help-list is hidden by default because if Option categories are being - // used then --help behaves the same as --help-list. - cl::opt<HelpPrinter, true, parser<bool>> HLOp{ - "help-list", - cl::desc( - "Display list of available options (--help-list-hidden for more)"), - cl::location(UncategorizedNormalPrinter), - cl::Hidden, - cl::ValueDisallowed, - cl::cat(GenericCategory), - cl::sub(*AllSubCommands)}; - - cl::opt<HelpPrinter, true, parser<bool>> HLHOp{ - "help-list-hidden", - cl::desc("Display list of all available options"), - cl::location(UncategorizedHiddenPrinter), - cl::Hidden, - cl::ValueDisallowed, - cl::cat(GenericCategory), - cl::sub(*AllSubCommands)}; - - // Define uncategorized/categorized help printers. These printers change their - // behaviour at runtime depending on whether one or more Option categories - // have been declared. - cl::opt<HelpPrinterWrapper, true, parser<bool>> HOp{ - "help", - cl::desc("Display available options (--help-hidden for more)"), - cl::location(WrappedNormalPrinter), - cl::ValueDisallowed, - cl::cat(GenericCategory), - cl::sub(*AllSubCommands)}; - - cl::alias HOpA{"h", cl::desc("Alias for --help"), cl::aliasopt(HOp), - cl::DefaultOption}; - - cl::opt<HelpPrinterWrapper, true, parser<bool>> HHOp{ - "help-hidden", - cl::desc("Display all available options"), - cl::location(WrappedHiddenPrinter), - cl::Hidden, - cl::ValueDisallowed, - cl::cat(GenericCategory), - cl::sub(*AllSubCommands)}; - - cl::opt<bool> PrintOptions{ - "print-options", - cl::desc("Print non-default options after command line parsing"), - cl::Hidden, - cl::init(false), - cl::cat(GenericCategory), - cl::sub(*AllSubCommands)}; - - cl::opt<bool> PrintAllOptions{ - "print-all-options", - cl::desc("Print all option values after command line parsing"), - cl::Hidden, - cl::init(false), - cl::cat(GenericCategory), - cl::sub(*AllSubCommands)}; - - VersionPrinterTy OverrideVersionPrinter = nullptr; - - std::vector<VersionPrinterTy> ExtraVersionPrinters; - - // Define the --version option that prints out the LLVM version for the tool - VersionPrinter VersionPrinterInstance; - - cl::opt<VersionPrinter, true, parser<bool>> VersOp{ - "version", cl::desc("Display the version of this program"), - cl::location(VersionPrinterInstance), cl::ValueDisallowed, - cl::cat(GenericCategory)}; -}; -} // End anonymous namespace - -// Lazy-initialized global instance of options controlling the command-line -// parser and general handling. -static ManagedStatic<CommandLineCommonOptions> CommonOptions; - -static void initCommonOptions() { - *CommonOptions; - initDebugCounterOptions(); - initGraphWriterOptions(); - initSignalsOptions(); - initStatisticOptions(); - initTimerOptions(); - initTypeSizeOptions(); - initWithColorOptions(); - initDebugOptions(); - initRandomSeedOptions(); -} - -OptionCategory &cl::getGeneralCategory() { - // Initialise the general option category. - static OptionCategory GeneralCategory{"General options"}; - return GeneralCategory; -} + void operator=(bool OptionWasSpecified) { + if (!OptionWasSpecified) + return; -void VersionPrinter::operator=(bool OptionWasSpecified) { - if (!OptionWasSpecified) - return; + if (OverrideVersionPrinter != nullptr) { + OverrideVersionPrinter(outs()); + exit(0); + } + print(); + + // Iterate over any registered extra printers and call them to add further + // information. + if (ExtraVersionPrinters != nullptr) { + outs() << '\n'; + for (const auto &I : *ExtraVersionPrinters) + I(outs()); + } - if (CommonOptions->OverrideVersionPrinter != nullptr) { - CommonOptions->OverrideVersionPrinter(outs()); exit(0); } - print(); - - // Iterate over any registered extra printers and call them to add further - // information. - if (!CommonOptions->ExtraVersionPrinters.empty()) { - outs() << '\n'; - for (const auto &I : CommonOptions->ExtraVersionPrinters) - I(outs()); - } - - exit(0); -} - -void HelpPrinterWrapper::operator=(bool Value) { - if (!Value) - return; - - // Decide which printer to invoke. If more than one option category is - // registered then it is useful to show the categorized help instead of - // uncategorized help. - if (GlobalParser->RegisteredOptionCategories.size() > 1) { - // unhide --help-list option so user can have uncategorized output if they - // want it. - CommonOptions->HLOp.setHiddenFlag(NotHidden); - - CategorizedPrinter = true; // Invoke categorized printer - } else - UncategorizedPrinter = true; // Invoke uncategorized printer -} - -// Print the value of each option. -void cl::PrintOptionValues() { GlobalParser->printOptionValues(); } - -void CommandLineParser::printOptionValues() { - if (!CommonOptions->PrintOptions && !CommonOptions->PrintAllOptions) - return; - - SmallVector<std::pair<const char *, Option *>, 128> Opts; - sortOpts(ActiveSubCommand->OptionsMap, Opts, /*ShowHidden*/ true); +}; +} // End anonymous namespace - // Compute the maximum argument length... - size_t MaxArgLen = 0; - for (size_t i = 0, e = Opts.size(); i != e; ++i) - MaxArgLen = std::max(MaxArgLen, Opts[i].second->getOptionWidth()); +// Define the --version option that prints out the LLVM version for the tool +static VersionPrinter VersionPrinterInstance; - for (size_t i = 0, e = Opts.size(); i != e; ++i) - Opts[i].second->printOptionValue(MaxArgLen, CommonOptions->PrintAllOptions); -} +static cl::opt<VersionPrinter, true, parser<bool>> + VersOp("version", cl::desc("Display the version of this program"), + cl::location(VersionPrinterInstance), cl::ValueDisallowed, + cl::cat(GenericCategory)); // Utility function for printing the help message. void cl::PrintHelpMessage(bool Hidden, bool Categorized) { if (!Hidden && !Categorized) - CommonOptions->UncategorizedNormalPrinter.printHelp(); + UncategorizedNormalPrinter.printHelp(); else if (!Hidden && Categorized) - CommonOptions->CategorizedNormalPrinter.printHelp(); + CategorizedNormalPrinter.printHelp(); else if (Hidden && !Categorized) - CommonOptions->UncategorizedHiddenPrinter.printHelp(); + UncategorizedHiddenPrinter.printHelp(); else - CommonOptions->CategorizedHiddenPrinter.printHelp(); + CategorizedHiddenPrinter.printHelp(); } /// Utility function for printing version number. -void cl::PrintVersionMessage() { - CommonOptions->VersionPrinterInstance.print(); -} +void cl::PrintVersionMessage() { VersionPrinterInstance.print(); } -void cl::SetVersionPrinter(VersionPrinterTy func) { - CommonOptions->OverrideVersionPrinter = func; -} +void cl::SetVersionPrinter(VersionPrinterTy func) { OverrideVersionPrinter = func; } void cl::AddExtraVersionPrinter(VersionPrinterTy func) { - CommonOptions->ExtraVersionPrinters.push_back(func); + if (!ExtraVersionPrinters) + ExtraVersionPrinters = new std::vector<VersionPrinterTy>; + + ExtraVersionPrinters->push_back(func); } StringMap<Option *> &cl::getRegisteredOptions(SubCommand &Sub) { @@ -2645,10 +2596,10 @@ cl::getRegisteredSubcommands() { } void cl::HideUnrelatedOptions(cl::OptionCategory &Category, SubCommand &Sub) { - initCommonOptions(); for (auto &I : Sub.OptionsMap) { for (auto &Cat : I.second->Categories) { - if (Cat != &Category && Cat != &CommonOptions->GenericCategory) + if (Cat != &Category && + Cat != &GenericCategory) I.second->setHiddenFlag(cl::ReallyHidden); } } @@ -2656,11 +2607,9 @@ void cl::HideUnrelatedOptions(cl::OptionCategory &Category, SubCommand &Sub) { void cl::HideUnrelatedOptions(ArrayRef<const cl::OptionCategory *> Categories, SubCommand &Sub) { - initCommonOptions(); for (auto &I : Sub.OptionsMap) { for (auto &Cat : I.second->Categories) { - if (!is_contained(Categories, Cat) && - Cat != &CommonOptions->GenericCategory) + if (!is_contained(Categories, Cat) && Cat != &GenericCategory) I.second->setHiddenFlag(cl::ReallyHidden); } } diff --git a/llvm/lib/Support/Debug.cpp b/llvm/lib/Support/Debug.cpp index b48045cc04d5c..19b40abdf0799 100644 --- a/llvm/lib/Support/Debug.cpp +++ b/llvm/lib/Support/Debug.cpp @@ -30,8 +30,6 @@ #include "llvm/Support/circular_raw_ostream.h" #include "llvm/Support/raw_ostream.h" -#include "DebugOptions.h" - #undef isCurrentDebugType #undef setCurrentDebugType #undef setCurrentDebugTypes @@ -81,32 +79,21 @@ void setCurrentDebugTypes(const char **Types, unsigned Count) { // All Debug.h functionality is a no-op in NDEBUG mode. #ifndef NDEBUG -namespace { -struct CreateDebug { - static void *call() { - return new cl::opt<bool, true>("debug", cl::desc("Enable debug output"), - cl::Hidden, cl::location(DebugFlag)); - } -}; +// -debug - Command line option to enable the DEBUG statements in the passes. +// This flag may only be enabled in debug builds. +static cl::opt<bool, true> +Debug("debug", cl::desc("Enable debug output"), cl::Hidden, + cl::location(DebugFlag)); // -debug-buffer-size - Buffer the last N characters of debug output //until program termination. -struct CreateDebugBufferSize { - static void *call() { - return new cl::opt<unsigned>( - "debug-buffer-size", - cl::desc("Buffer the last N characters of debug output " - "until program termination. " - "[default 0 -- immediate print-out]"), - cl::Hidden, cl::init(0)); - } -}; -} // namespace - -// -debug - Command line option to enable the DEBUG statements in the passes. -// This flag may only be enabled in debug builds. -static ManagedStatic<cl::opt<bool, true>, CreateDebug> Debug; -static ManagedStatic<cl::opt<unsigned>, CreateDebugBufferSize> DebugBufferSize; +static cl::opt<unsigned> +DebugBufferSize("debug-buffer-size", + cl::desc("Buffer the last N characters of debug output " + "until program termination. " + "[default 0 -- immediate print-out]"), + cl::Hidden, + cl::init(0)); namespace { @@ -121,33 +108,15 @@ struct DebugOnlyOpt { CurrentDebugType->push_back(std::string(dbgType)); } }; -} // namespace -static DebugOnlyOpt DebugOnlyOptLoc; - -namespace { -struct CreateDebugOnly { - static void *call() { - return new cl::opt<DebugOnlyOpt, true, cl::parser<std::string>>( - "debug-only", - cl::desc("Enable a specific type of debug output (comma separated list " - "of types)"), - cl::Hidden, cl::ZeroOrMore, cl::value_desc("debug string"), - cl::location(DebugOnlyOptLoc), cl::ValueRequired); - } -}; } // namespace -static ManagedStatic<cl::opt<DebugOnlyOpt, true, cl::parser<std::string>>, - CreateDebugOnly> - DebugOnly; - -void llvm::initDebugOptions() { - *Debug; - *DebugBufferSize; - *DebugOnly; -} +static DebugOnlyOpt DebugOnlyOptLoc; +static cl::opt<DebugOnlyOpt, true, cl::parser<std::string> > +DebugOnly("debug-only", cl::desc("Enable a specific type of debug output (comma separated list of types)"), + cl::Hidden, cl::ZeroOrMore, cl::value_desc("debug string"), + cl::location(DebugOnlyOptLoc), cl::ValueRequired); // Signal handlers - dump debug output on termination. static void debug_user_sig_handler(void *Cookie) { // This is a bit sneaky. Since this is under #ifndef NDEBUG, we @@ -165,10 +134,10 @@ raw_ostream &llvm::dbgs() { static struct dbgstream { circular_raw_ostream strm; - dbgstream() - : strm(errs(), "*** Debug Log Output ***\n", - (!EnableDebugBuffering || !DebugFlag) ? 0 : *DebugBufferSize) { - if (EnableDebugBuffering && DebugFlag && *DebugBufferSize != 0) + dbgstream() : + strm(errs(), "*** Debug Log Output ***\n", + (!EnableDebugBuffering || !DebugFlag) ? 0 : DebugBufferSize) { + if (EnableDebugBuffering && DebugFlag && DebugBufferSize != 0) // TODO: Add a handler for SIGUSER1-type signals so the user can // force a debug dump. sys::AddSignalHandler(&debug_user_sig_handler, nullptr); diff --git a/llvm/lib/Support/DebugCounter.cpp b/llvm/lib/Support/DebugCounter.cpp index f553463be8df2..7bb231c79239b 100644 --- a/llvm/lib/Support/DebugCounter.cpp +++ b/llvm/lib/Support/DebugCounter.cpp @@ -1,7 +1,4 @@ #include "llvm/Support/DebugCounter.h" - -#include "DebugOptions.h" - #include "llvm/Support/CommandLine.h" #include "llvm/Support/Format.h" #include "llvm/Support/ManagedStatic.h" @@ -43,29 +40,17 @@ class DebugCounterList : public cl::list<std::string, DebugCounter> { } } }; - -struct CreateDebugCounterOption { - static void *call() { - return new DebugCounterList( - "debug-counter", cl::Hidden, - cl::desc("Comma separated list of debug counter skip and count"), - cl::CommaSeparated, cl::ZeroOrMore, - cl::location(DebugCounter::instance())); - } -}; } // namespace -static ManagedStatic<DebugCounterList, CreateDebugCounterOption> - DebugCounterOption; -static bool PrintDebugCounter; +// Create our command line option. +static DebugCounterList DebugCounterOption( + "debug-counter", cl::Hidden, + cl::desc("Comma separated list of debug counter skip and count"), + cl::CommaSeparated, cl::ZeroOrMore, cl::location(DebugCounter::instance())); -void llvm::initDebugCounterOptions() { - *DebugCounterOption; - static cl::opt<bool, true> RegisterPrintDebugCounter( - "print-debug-counter", cl::Hidden, cl::location(PrintDebugCounter), - cl::init(false), cl::Optional, - cl::desc("Print out debug counter info after all counters accumulated")); -} +static cl::opt<bool> PrintDebugCounter( + "print-debug-counter", cl::Hidden, cl::init(false), cl::Optional, + cl::desc("Print out debug counter info after all counters accumulated")); static ManagedStatic<DebugCounter> DC; diff --git a/llvm/lib/Support/DebugOptions.h b/llvm/lib/Support/DebugOptions.h deleted file mode 100644 index 4d5250649f6a2..0000000000000 --- a/llvm/lib/Support/DebugOptions.h +++ /dev/null @@ -1,29 +0,0 @@ -//===-- DebugOptions.h - Global Command line opt for libSupport *- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -// -// This file defines the entry point to initialize the options registered on the -// command line for libSupport, this is internal to libSupport. -// -//===----------------------------------------------------------------------===// - -namespace llvm { - -// These are invoked internally before parsing command line options. -// This enables lazy-initialization of all the globals in libSupport, instead -// of eagerly loading everything on program startup. -void initDebugCounterOptions(); -void initGraphWriterOptions(); -void initSignalsOptions(); -void initStatisticOptions(); -void initTimerOptions(); -void initTypeSizeOptions(); -void initWithColorOptions(); -void initDebugOptions(); -void initRandomSeedOptions(); - -} // namespace llvm \ No newline at end of file diff --git a/llvm/lib/Support/ELFAttributeParser.cpp b/llvm/lib/Support/ELFAttributeParser.cpp index 1206553343efe..2a30794bc1e91 100644 --- a/llvm/lib/Support/ELFAttributeParser.cpp +++ b/llvm/lib/Support/ELFAttributeParser.cpp @@ -16,7 +16,7 @@ using namespace llvm; using namespace llvm::ELFAttrs; -static constexpr EnumEntry<unsigned> tagNames[] = { +static const EnumEntry<unsigned> tagNames[] = { {"Tag_File", ELFAttrs::File}, {"Tag_Section", ELFAttrs::Section}, {"Tag_Symbol", ELFAttrs::Symbol}, diff --git a/llvm/lib/Support/GraphWriter.cpp b/llvm/lib/Support/GraphWriter.cpp index 240f59748d137..f47a52a853f4e 100644 --- a/llvm/lib/Support/GraphWriter.cpp +++ b/llvm/lib/Support/GraphWriter.cpp @@ -11,9 +11,6 @@ //===----------------------------------------------------------------------===// #include "llvm/Support/GraphWriter.h" - -#include "DebugOptions.h" - #include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" @@ -32,21 +29,8 @@ using namespace llvm; -#ifdef __APPLE__ -namespace { -struct CreateViewBackground { - static void *call() { - return new cl::opt<bool>("view-background", cl::Hidden, - cl::desc("Execute graph viewer in the background. " - "Creates tmp file litter.")); - } -}; -} // namespace -static ManagedStatic<cl::opt<bool>, CreateViewBackground> ViewBackground; -void llvm::initGraphWriterOptions() { *ViewBackground; } -#else -void llvm::initGraphWriterOptions() {} -#endif +static cl::opt<bool> ViewBackground("view-background", cl::Hidden, + cl::desc("Execute graph viewer in the background. Creates tmp file litter.")); std::string llvm::DOT::EscapeString(const std::string &Label) { std::string Str(Label); diff --git a/llvm/lib/Support/RISCVAttributes.cpp b/llvm/lib/Support/RISCVAttributes.cpp index 9e629760d3d84..201048e03009b 100644 --- a/llvm/lib/Support/RISCVAttributes.cpp +++ b/llvm/lib/Support/RISCVAttributes.cpp @@ -11,7 +11,7 @@ using namespace llvm; using namespace llvm::RISCVAttrs; -static constexpr TagNameItem tagData[] = { +static const TagNameItem tagData[] = { {STACK_ALIGN, "Tag_stack_align"}, {ARCH, "Tag_arch"}, {UNALIGNED_ACCESS, "Tag_unaligned_access"}, @@ -20,7 +20,6 @@ static constexpr TagNameItem tagData[] = { {PRIV_SPEC_REVISION, "Tag_priv_spec_revision"}, }; -constexpr TagNameMap RISCVAttributeTags{tagData}; -const TagNameMap &llvm::RISCVAttrs::getRISCVAttributeTags() { - return RISCVAttributeTags; -} +const TagNameMap llvm::RISCVAttrs::RISCVAttributeTags(tagData, + sizeof(tagData) / + sizeof(TagNameItem)); diff --git a/llvm/lib/Support/RandomNumberGenerator.cpp b/llvm/lib/Support/RandomNumberGenerator.cpp index aea0132a93fe2..f9c41ee5eaaf0 100644 --- a/llvm/lib/Support/RandomNumberGenerator.cpp +++ b/llvm/lib/Support/RandomNumberGenerator.cpp @@ -13,9 +13,6 @@ //===----------------------------------------------------------------------===// #include "llvm/Support/RandomNumberGenerator.h" - -#include "DebugOptions.h" - #include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" @@ -28,20 +25,13 @@ using namespace llvm; #define DEBUG_TYPE "rng" -namespace { -struct CreateSeed { - static void *call() { - return new cl::opt<uint64_t>( - "rng-seed", cl::value_desc("seed"), cl::Hidden, - cl::desc("Seed for the random number generator"), cl::init(0)); - } -}; -} // namespace -static ManagedStatic<cl::opt<uint64_t>, CreateSeed> Seed; -void llvm::initRandomSeedOptions() { *Seed; } + +static cl::opt<uint64_t> Seed("rng-seed", cl::value_desc("seed"), cl::Hidden, + cl::desc("Seed for the random number generator"), + cl::init(0)); RandomNumberGenerator::RandomNumberGenerator(StringRef Salt) { - LLVM_DEBUG(if (*Seed == 0) dbgs() + LLVM_DEBUG(if (Seed == 0) dbgs() << "Warning! Using unseeded random number generator.\n"); // Combine seed and salts using std::seed_seq. @@ -51,8 +41,8 @@ RandomNumberGenerator::RandomNumberGenerator(StringRef Salt) { // twister constructor copies these correctly into its initial state. std::vector<uint32_t> Data; Data.resize(2 + Salt.size()); - Data[0] = *Seed; - Data[1] = *Seed >> 32; + Data[0] = Seed; + Data[1] = Seed >> 32; llvm::copy(Salt, Data.begin() + 2); diff --git a/llvm/lib/Support/Signals.cpp b/llvm/lib/Support/Signals.cpp index dd4dded4cd1d8..4e70eed28b862 100644 --- a/llvm/lib/Support/Signals.cpp +++ b/llvm/lib/Support/Signals.cpp @@ -12,9 +12,6 @@ //===----------------------------------------------------------------------===// #include "llvm/Support/Signals.h" - -#include "DebugOptions.h" - #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringRef.h" #include "llvm/Config/llvm-config.h" @@ -42,33 +39,15 @@ using namespace llvm; // Use explicit storage to avoid accessing cl::opt in a signal handler. static bool DisableSymbolicationFlag = false; -static ManagedStatic<std::string> CrashDiagnosticsDirectory; -namespace { -struct CreateDisableSymbolication { - static void *call() { - return new cl::opt<bool, true>( - "disable-symbolication", - cl::desc("Disable symbolizing crash backtraces."), - cl::location(DisableSymbolicationFlag), cl::Hidden); - } -}; -struct CreateCrashDiagnosticsDir { - static void *call() { - return new cl::opt<std::string, true>( - "crash-diagnostics-dir", cl::value_desc("directory"), - cl::desc("Directory for crash diagnostic files."), - cl::location(*CrashDiagnosticsDirectory), cl::Hidden); - } -}; -} // namespace -void llvm::initSignalsOptions() { - static ManagedStatic<cl::opt<bool, true>, CreateDisableSymbolication> - DisableSymbolication; - static ManagedStatic<cl::opt<std::string, true>, CreateCrashDiagnosticsDir> - CrashDiagnosticsDir; - *DisableSymbolication; - *CrashDiagnosticsDir; -} +static cl::opt<bool, true> + DisableSymbolication("disable-symbolication", + cl::desc("Disable symbolizing crash backtraces."), + cl::location(DisableSymbolicationFlag), cl::Hidden); +static std::string CrashDiagnosticsDirectory; +static cl::opt<std::string, true> + CrashDiagnosticsDir("crash-diagnostics-dir", cl::value_desc("directory"), + cl::desc("Directory for crash diagnostic files."), + cl::location(CrashDiagnosticsDirectory), cl::Hidden); constexpr char DisableSymbolizationEnv[] = "LLVM_DISABLE_SYMBOLIZATION"; constexpr char LLVMSymbolizerPathEnv[] = "LLVM_SYMBOLIZER_PATH"; diff --git a/llvm/lib/Support/Statistic.cpp b/llvm/lib/Support/Statistic.cpp index d95c8642c16e7..e9308ab575abe 100644 --- a/llvm/lib/Support/Statistic.cpp +++ b/llvm/lib/Support/Statistic.cpp @@ -21,9 +21,6 @@ //===----------------------------------------------------------------------===// #include "llvm/ADT/Statistic.h" - -#include "DebugOptions.h" - #include "llvm/ADT/StringExtras.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Compiler.h" @@ -41,22 +38,18 @@ using namespace llvm; /// -stats - Command line option to cause transformations to emit stats about /// what they did. /// -static bool EnableStats; -static bool StatsAsJSON; +static cl::opt<bool> EnableStats( + "stats", + cl::desc("Enable statistics output from program (available with Asserts)"), + cl::Hidden); + +static cl::opt<bool> StatsAsJSON("stats-json", + cl::desc("Display statistics as json data"), + cl::Hidden); + static bool Enabled; static bool PrintOnExit; -void llvm::initStatisticOptions() { - static cl::opt<bool, true> registerEnableStats{ - "stats", - cl::desc( - "Enable statistics output from program (available with Asserts)"), - cl::location(EnableStats), cl::Hidden}; - static cl::opt<bool, true> registerStatsAsJson{ - "stats-json", cl::desc("Display statistics as json data"), - cl::location(StatsAsJSON), cl::Hidden}; -} - namespace { /// This class is used in a ManagedStatic so that it is created on demand (when /// the first statistic is bumped) and destroyed only when llvm_shutdown is @@ -135,7 +128,9 @@ void llvm::EnableStatistics(bool DoPrintOnExit) { PrintOnExit = DoPrintOnExit; } -bool llvm::AreStatisticsEnabled() { return Enabled || EnableStats; } +bool llvm::AreStatisticsEnabled() { + return Enabled || EnableStats; +} void StatisticInfo::sort() { llvm::stable_sort( diff --git a/llvm/lib/Support/TimeProfiler.cpp b/llvm/lib/Support/TimeProfiler.cpp index 8f2544e9e26d1..c37c74c61f3ce 100644 --- a/llvm/lib/Support/TimeProfiler.cpp +++ b/llvm/lib/Support/TimeProfiler.cpp @@ -30,7 +30,7 @@ using namespace llvm; static std::mutex Mu; // List of all instances -static ManagedStatic<std::vector<TimeTraceProfiler *>> +static std::vector<TimeTraceProfiler *> ThreadTimeTraceProfilerInstances; // GUARDED_BY(Mu) // Per Thread instance static LLVM_THREAD_LOCAL TimeTraceProfiler *TimeTraceProfilerInstance = nullptr; @@ -128,7 +128,7 @@ struct llvm::TimeTraceProfiler { std::lock_guard<std::mutex> Lock(Mu); assert(Stack.empty() && "All profiler sections should be ended when calling write"); - assert(llvm::all_of(*ThreadTimeTraceProfilerInstances, + assert(llvm::all_of(ThreadTimeTraceProfilerInstances, [](const auto &TTP) { return TTP->Stack.empty(); }) && "All profiler sections should be ended when calling write"); @@ -156,7 +156,7 @@ struct llvm::TimeTraceProfiler { }; for (const Entry &E : Entries) writeEvent(E, this->Tid); - for (const TimeTraceProfiler *TTP : *ThreadTimeTraceProfilerInstances) + for (const TimeTraceProfiler *TTP : ThreadTimeTraceProfilerInstances) for (const Entry &E : TTP->Entries) writeEvent(E, TTP->Tid); @@ -164,7 +164,7 @@ struct llvm::TimeTraceProfiler { // longest one. // Find highest used thread id. uint64_t MaxTid = this->Tid; - for (const TimeTraceProfiler *TTP : *ThreadTimeTraceProfilerInstances) + for (const TimeTraceProfiler *TTP : ThreadTimeTraceProfilerInstances) MaxTid = std::max(MaxTid, TTP->Tid); // Combine all CountAndTotalPerName from threads into one. @@ -178,7 +178,7 @@ struct llvm::TimeTraceProfiler { }; for (const auto &Stat : CountAndTotalPerName) combineStat(Stat); - for (const TimeTraceProfiler *TTP : *ThreadTimeTraceProfilerInstances) + for (const TimeTraceProfiler *TTP : ThreadTimeTraceProfilerInstances) for (const auto &Stat : TTP->CountAndTotalPerName) combineStat(Stat); @@ -229,7 +229,7 @@ struct llvm::TimeTraceProfiler { writeMetadataEvent("process_name", Tid, ProcName); writeMetadataEvent("thread_name", Tid, ThreadName); - for (const TimeTraceProfiler *TTP : *ThreadTimeTraceProfilerInstances) + for (const TimeTraceProfiler *TTP : ThreadTimeTraceProfilerInstances) writeMetadataEvent("thread_name", TTP->Tid, TTP->ThreadName); J.arrayEnd(); @@ -273,16 +273,16 @@ void llvm::timeTraceProfilerInitialize(unsigned TimeTraceGranularity, void llvm::timeTraceProfilerCleanup() { delete TimeTraceProfilerInstance; std::lock_guard<std::mutex> Lock(Mu); - for (auto TTP : *ThreadTimeTraceProfilerInstances) + for (auto TTP : ThreadTimeTraceProfilerInstances) delete TTP; - ThreadTimeTraceProfilerInstances->clear(); + ThreadTimeTraceProfilerInstances.clear(); } // Finish TimeTraceProfilerInstance on a worker thread. // This doesn't remove the instance, just moves the pointer to global vector. void llvm::timeTraceProfilerFinishThread() { std::lock_guard<std::mutex> Lock(Mu); - ThreadTimeTraceProfilerInstances->push_back(TimeTraceProfilerInstance); + ThreadTimeTraceProfilerInstances.push_back(TimeTraceProfilerInstance); TimeTraceProfilerInstance = nullptr; } diff --git a/llvm/lib/Support/Timer.cpp b/llvm/lib/Support/Timer.cpp index f025ecd3d45c4..8d421db4f7b15 100644 --- a/llvm/lib/Support/Timer.cpp +++ b/llvm/lib/Support/Timer.cpp @@ -11,9 +11,6 @@ //===----------------------------------------------------------------------===// #include "llvm/Support/Timer.h" - -#include "DebugOptions.h" - #include "llvm/ADT/Statistic.h" #include "llvm/ADT/StringMap.h" #include "llvm/Config/config.h" @@ -56,41 +53,20 @@ static ManagedStatic<sys::SmartMutex<true> > TimerLock; static ManagedStatic<SignpostEmitter> Signposts; namespace { -struct CreateTrackSpace { - static void *call() { - return new cl::opt<bool>("track-memory", - cl::desc("Enable -time-passes memory " + static cl::opt<bool> + TrackSpace("track-memory", cl::desc("Enable -time-passes memory " "tracking (this may be slow)"), - cl::Hidden); - } -}; -static ManagedStatic<cl::opt<bool>, CreateTrackSpace> TrackSpace; -struct CreateInfoOutputFilename { - static void *call() { - return new cl::opt<std::string, true>( - "info-output-file", cl::value_desc("filename"), - cl::desc("File to append -stats and -timer output to"), cl::Hidden, - cl::location(getLibSupportInfoOutputFilename())); - } -}; -static ManagedStatic<cl::opt<std::string, true>, CreateInfoOutputFilename> - InfoOutputFilename; -struct CreateSortTimers { - static void *call() { - return new cl::opt<bool>( - "sort-timers", - cl::desc("In the report, sort the timers in each group " - "in wall clock time order"), - cl::init(true), cl::Hidden); - } -}; -ManagedStatic<cl::opt<bool>, CreateSortTimers> SortTimers; -} // namespace + cl::Hidden); + + static cl::opt<std::string, true> + InfoOutputFilename("info-output-file", cl::value_desc("filename"), + cl::desc("File to append -stats and -timer output to"), + cl::Hidden, cl::location(getLibSupportInfoOutputFilename())); -void llvm::initTimerOptions() { - *TrackSpace; - *InfoOutputFilename; - *SortTimers; + static cl::opt<bool> + SortTimers("sort-timers", cl::desc("In the report, sort the timers in each group " + "in wall clock time order"), + cl::init(true), cl::Hidden); } std::unique_ptr<raw_fd_ostream> llvm::CreateInfoOutputFile() { @@ -149,8 +125,7 @@ Timer::~Timer() { } static inline size_t getMemUsage() { - if (!*TrackSpace) - return 0; + if (!TrackSpace) return 0; return sys::Process::GetMallocUsage(); } @@ -356,7 +331,7 @@ void TimerGroup::addTimer(Timer &T) { void TimerGroup::PrintQueuedTimers(raw_ostream &OS) { // Perhaps sort the timers in descending order by amount of time taken. - if (*SortTimers) + if (SortTimers) llvm::sort(TimersToPrint); TimeRecord Total; diff --git a/llvm/lib/Support/TypeSize.cpp b/llvm/lib/Support/TypeSize.cpp index abb81016a0bad..83d40d9cb0edd 100644 --- a/llvm/lib/Support/TypeSize.cpp +++ b/llvm/lib/Support/TypeSize.cpp @@ -9,35 +9,19 @@ #include "llvm/Support/TypeSize.h" #include "llvm/Support/CommandLine.h" -#include "DebugOptions.h" - using namespace llvm; -#ifndef STRICT_FIXED_SIZE_VECTORS -namespace { -struct CreateScalableErrorAsWarning { - /// The ScalableErrorAsWarning is a temporary measure to suppress errors from - /// using the wrong interface on a scalable vector. - static void *call() { - return new cl::opt<bool>( - "treat-scalable-fixed-error-as-warning", cl::Hidden, cl::init(false), - cl::desc( - "Treat issues where a fixed-width property is requested from a " - "scalable type as a warning, instead of an error."), - cl::ZeroOrMore); - } -}; -} // namespace -static ManagedStatic<cl::opt<bool>, CreateScalableErrorAsWarning> - ScalableErrorAsWarning; -void llvm::initTypeSizeOptions() { *ScalableErrorAsWarning; } -#else -void llvm::initTypeSizeOptions() {} -#endif +/// The ScalableErrorAsWarning is a temporary measure to suppress errors from +/// using the wrong interface on a scalable vector. +cl::opt<bool> ScalableErrorAsWarning( + "treat-scalable-fixed-error-as-warning", cl::Hidden, cl::init(false), + cl::desc("Treat issues where a fixed-width property is requested from a " + "scalable type as a warning, instead of an error."), + cl::ZeroOrMore); void llvm::reportInvalidSizeRequest(const char *Msg) { #ifndef STRICT_FIXED_SIZE_VECTORS - if (*ScalableErrorAsWarning) { + if (ScalableErrorAsWarning) { WithColor::warning() << "Invalid size request on a scalable vector; " << Msg << "\n"; return; diff --git a/llvm/lib/Support/Windows/Signals.inc b/llvm/lib/Support/Windows/Signals.inc index 32186bbe51607..df5fcb1b151bc 100644 --- a/llvm/lib/Support/Windows/Signals.inc +++ b/llvm/lib/Support/Windows/Signals.inc @@ -773,7 +773,7 @@ WriteWindowsDumpFile(PMINIDUMP_EXCEPTION_INFORMATION ExceptionInfo) { // (GetDumpFolder will return false either if the key is NULL or if there is // no valid DumpFolder value at its location). bool ExplicitDumpDirectorySet = true; - SmallString<MAX_PATH> DumpDirectory(*CrashDiagnosticsDirectory); + SmallString<MAX_PATH> DumpDirectory(CrashDiagnosticsDirectory); if (DumpDirectory.empty()) if (!GetDumpFolder(AppSpecificKey, DumpDirectory)) if (!GetDumpFolder(DefaultLocalDumpsKey, DumpDirectory)) diff --git a/llvm/lib/Support/WithColor.cpp b/llvm/lib/Support/WithColor.cpp index b1aa709862d86..f8d2b01653073 100644 --- a/llvm/lib/Support/WithColor.cpp +++ b/llvm/lib/Support/WithColor.cpp @@ -7,31 +7,17 @@ //===----------------------------------------------------------------------===// #include "llvm/Support/WithColor.h" - -#include "DebugOptions.h" - #include "llvm/Support/CommandLine.h" #include "llvm/Support/Error.h" -#include "llvm/Support/ManagedStatic.h" using namespace llvm; -cl::OptionCategory &llvm::getColorCategory() { - static cl::OptionCategory ColorCategory("Color Options"); - return ColorCategory; -} -namespace { -struct CreateUseColor { - static void *call() { - return new cl::opt<cl::boolOrDefault>( - "color", cl::cat(getColorCategory()), - cl::desc("Use colors in output (default=autodetect)"), - cl::init(cl::BOU_UNSET)); - } -}; -} // namespace -static ManagedStatic<cl::opt<cl::boolOrDefault>, CreateUseColor> UseColor; -void llvm::initWithColorOptions() { *UseColor; } +cl::OptionCategory llvm::ColorCategory("Color Options"); + +static cl::opt<cl::boolOrDefault> + UseColor("color", cl::cat(ColorCategory), + cl::desc("Use colors in output (default=autodetect)"), + cl::init(cl::BOU_UNSET)); WithColor::WithColor(raw_ostream &OS, HighlightColor Color, ColorMode Mode) : OS(OS), Mode(Mode) { @@ -127,8 +113,8 @@ bool WithColor::colorsEnabled() { case ColorMode::Disable: return false; case ColorMode::Auto: - return *UseColor == cl::BOU_UNSET ? OS.has_colors() - : *UseColor == cl::BOU_TRUE; + return UseColor == cl::BOU_UNSET ? OS.has_colors() + : UseColor == cl::BOU_TRUE; } llvm_unreachable("All cases handled above."); } diff --git a/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp b/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp index 1ddbe944ec085..abecc9cc0c8af 100644 --- a/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp +++ b/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp @@ -11325,8 +11325,8 @@ bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) { TagLoc = Parser.getTok().getLoc(); if (Parser.getTok().is(AsmToken::Identifier)) { StringRef Name = Parser.getTok().getIdentifier(); - Optional<unsigned> Ret = ELFAttrs::attrTypeFromString( - Name, ARMBuildAttrs::getARMAttributeTags()); + Optional<unsigned> Ret = + ELFAttrs::attrTypeFromString(Name, ARMBuildAttrs::ARMAttributeTags); if (!Ret.hasValue()) { Error(TagLoc, "attribute name not recognised: " + Name); return false; diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp index 12076b8c49c14..d6a32b4e967c0 100644 --- a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp +++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp @@ -176,8 +176,8 @@ void ARMTargetAsmStreamer::switchVendor(StringRef Vendor) {} void ARMTargetAsmStreamer::emitAttribute(unsigned Attribute, unsigned Value) { OS << "\t.eabi_attribute\t" << Attribute << ", " << Twine(Value); if (IsVerboseAsm) { - StringRef Name = ELFAttrs::attrTypeAsString( - Attribute, ARMBuildAttrs::getARMAttributeTags()); + StringRef Name = + ELFAttrs::attrTypeAsString(Attribute, ARMBuildAttrs::ARMAttributeTags); if (!Name.empty()) OS << "\t@ " << Name; } @@ -194,7 +194,7 @@ void ARMTargetAsmStreamer::emitTextAttribute(unsigned Attribute, OS << "\t.eabi_attribute\t" << Attribute << ", \"" << String << "\""; if (IsVerboseAsm) { StringRef Name = ELFAttrs::attrTypeAsString( - Attribute, ARMBuildAttrs::getARMAttributeTags()); + Attribute, ARMBuildAttrs::ARMAttributeTags); if (!Name.empty()) OS << "\t@ " << Name; } @@ -215,7 +215,7 @@ void ARMTargetAsmStreamer::emitIntTextAttribute(unsigned Attribute, if (IsVerboseAsm) OS << "\t@ " << ELFAttrs::attrTypeAsString(Attribute, - ARMBuildAttrs::getARMAttributeTags()); + ARMBuildAttrs::ARMAttributeTags); break; } OS << "\n"; diff --git a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp index 4127dd786d203..6be4373e5fc58 100644 --- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp +++ b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp @@ -1970,7 +1970,7 @@ bool RISCVAsmParser::parseDirectiveAttribute() { if (Parser.getTok().is(AsmToken::Identifier)) { StringRef Name = Parser.getTok().getIdentifier(); Optional<unsigned> Ret = - ELFAttrs::attrTypeFromString(Name, RISCVAttrs::getRISCVAttributeTags()); + ELFAttrs::attrTypeFromString(Name, RISCVAttrs::RISCVAttributeTags); if (!Ret.hasValue()) { Error(TagLoc, "attribute name not recognised: " + Name); return false; diff --git a/llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp b/llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp index f4851bfb2a9cf..ca22cc45d063d 100644 --- a/llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp +++ b/llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp @@ -97,7 +97,7 @@ static Expected<std::unique_ptr<MemoryBuffer>> openBitcodeFile(StringRef Path) { int main(int argc, char **argv) { InitLLVM X(argc, argv); - cl::HideUnrelatedOptions({&BCAnalyzerCategory, &getColorCategory()}); + cl::HideUnrelatedOptions({&BCAnalyzerCategory, &ColorCategory}); cl::ParseCommandLineOptions(argc, argv, "llvm-bcanalyzer file analyzer\n"); ExitOnError ExitOnErr("llvm-bcanalyzer: "); diff --git a/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp b/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp index a324ff710af5d..1180e029f2553 100644 --- a/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp +++ b/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp @@ -623,8 +623,7 @@ int main(int argc, char **argv) { llvm::InitializeAllTargetInfos(); llvm::InitializeAllTargetMCs(); - HideUnrelatedOptions( - {&DwarfDumpCategory, &SectionCategory, &getColorCategory()}); + HideUnrelatedOptions({&DwarfDumpCategory, &SectionCategory, &ColorCategory}); cl::ParseCommandLineOptions( argc, argv, "pretty-print DWARF debug information in object files" diff --git a/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp b/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp index ef4aec58d2e67..9b01ff59afd63 100644 --- a/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp +++ b/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp @@ -571,7 +571,7 @@ static Expected<Config> parseCommandLine(int Argc, char **Argv) { int main(int Argc, char **Argv) { InitLLVM X(Argc, Argv); - cl::HideUnrelatedOptions({&LibtoolCategory, &getColorCategory()}); + cl::HideUnrelatedOptions({&LibtoolCategory, &ColorCategory}); Expected<Config> ConfigOrErr = parseCommandLine(Argc, Argv); if (!ConfigOrErr) { WithColor::defaultErrorHandler(ConfigOrErr.takeError()); diff --git a/llvm/unittests/Support/ARMAttributeParser.cpp b/llvm/unittests/Support/ARMAttributeParser.cpp index 61dfd6276e311..9a823ed1de7ee 100644 --- a/llvm/unittests/Support/ARMAttributeParser.cpp +++ b/llvm/unittests/Support/ARMAttributeParser.cpp @@ -48,7 +48,7 @@ void testParseError(ArrayRef<uint8_t> bytes, const char *msg) { } bool testTagString(unsigned Tag, const char *name) { - return ELFAttrs::attrTypeAsString(Tag, ARMBuildAttrs::getARMAttributeTags()) + return ELFAttrs::attrTypeAsString(Tag, ARMBuildAttrs::ARMAttributeTags) .str() == name; } diff --git a/llvm/unittests/Support/CommandLineTest.cpp b/llvm/unittests/Support/CommandLineTest.cpp index a0352bc8a4c5e..7d880464e2665 100644 --- a/llvm/unittests/Support/CommandLineTest.cpp +++ b/llvm/unittests/Support/CommandLineTest.cpp @@ -110,7 +110,7 @@ TEST(CommandLineTest, ModifyExisitingOption) { ASSERT_NE(Retrieved->Categories.end(), find_if(Retrieved->Categories, [&](const llvm::cl::OptionCategory *Cat) { - return Cat == &cl::getGeneralCategory(); + return Cat == &cl::GeneralCategory; })) << "Incorrect default option category."; @@ -152,10 +152,10 @@ TEST(CommandLineTest, UseOptionCategory) { TEST(CommandLineTest, UseMultipleCategories) { StackOption<int> TestOption2("test-option2", cl::cat(TestCategory), - cl::cat(cl::getGeneralCategory()), - cl::cat(cl::getGeneralCategory())); + cl::cat(cl::GeneralCategory), + cl::cat(cl::GeneralCategory)); - // Make sure cl::getGeneralCategory() wasn't added twice. + // Make sure cl::GeneralCategory wasn't added twice. ASSERT_EQ(TestOption2.Categories.size(), 2U); ASSERT_NE(TestOption2.Categories.end(), @@ -166,9 +166,9 @@ TEST(CommandLineTest, UseMultipleCategories) { << "Failed to assign Option Category."; ASSERT_NE(TestOption2.Categories.end(), find_if(TestOption2.Categories, - [&](const llvm::cl::OptionCategory *Cat) { - return Cat == &cl::getGeneralCategory(); - })) + [&](const llvm::cl::OptionCategory *Cat) { + return Cat == &cl::GeneralCategory; + })) << "Failed to assign General Category."; cl::OptionCategory AnotherCategory("Additional test Options", "Description"); @@ -176,9 +176,9 @@ TEST(CommandLineTest, UseMultipleCategories) { cl::cat(AnotherCategory)); ASSERT_EQ(TestOption.Categories.end(), find_if(TestOption.Categories, - [&](const llvm::cl::OptionCategory *Cat) { - return Cat == &cl::getGeneralCategory(); - })) + [&](const llvm::cl::OptionCategory *Cat) { + return Cat == &cl::GeneralCategory; + })) << "Failed to remove General Category."; ASSERT_NE(TestOption.Categories.end(), find_if(TestOption.Categories, diff --git a/llvm/unittests/Support/RISCVAttributeParserTest.cpp b/llvm/unittests/Support/RISCVAttributeParserTest.cpp index 02ffb366a8396..1458af604a5c5 100644 --- a/llvm/unittests/Support/RISCVAttributeParserTest.cpp +++ b/llvm/unittests/Support/RISCVAttributeParserTest.cpp @@ -49,7 +49,7 @@ static bool testAttribute(unsigned Tag, unsigned Value, unsigned ExpectedTag, } static bool testTagString(unsigned Tag, const char *name) { - return ELFAttrs::attrTypeAsString(Tag, RISCVAttrs::getRISCVAttributeTags()) + return ELFAttrs::attrTypeAsString(Tag, RISCVAttrs::RISCVAttributeTags) .str() == name; } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits