Index: include/llvm/CodeGen/MachinePassRegistry.h =================================================================== --- include/llvm/CodeGen/MachinePassRegistry.h +++ include/llvm/CodeGen/MachinePassRegistry.h @@ -122,11 +122,11 @@ class RegisterPassParser : public MachinePassRegistryListener, public cl::parser { public: - RegisterPassParser() {} + RegisterPassParser(cl::Option* O) : cl::parser(O) {} ~RegisterPassParser() { RegistryClass::setListener(nullptr); } - void initialize(cl::Option &O) { - cl::parser::initialize(O); + void initialize() { + cl::parser::initialize(); // Add existing passes to option. for (RegistryClass *Node = RegistryClass::getList(); Index: include/llvm/IR/LegacyPassNameParser.h =================================================================== --- include/llvm/IR/LegacyPassNameParser.h +++ include/llvm/IR/LegacyPassNameParser.h @@ -41,14 +41,12 @@ // class PassNameParser : public PassRegistrationListener, public cl::parser { - cl::Option *Opt; public: - PassNameParser(); + PassNameParser(cl::Option* O); virtual ~PassNameParser(); - void initialize(cl::Option &O) { - Opt = &O; - cl::parser::initialize(O); + void initialize() { + cl::parser::initialize(); // Add all of the passes to the map that got initialized before 'this' did. enumeratePasses(); @@ -69,7 +67,7 @@ // Implement the PassRegistrationListener callbacks used to populate our map // void passRegistered(const PassInfo *P) override { - if (ignorablePass(P) || !Opt) return; + if (ignorablePass(P) || !Owner) return; if (findOption(P->getPassArgument()) != getNumOptions()) { errs() << "Two passes with the same argument (-" << P->getPassArgument() << ") attempted to be registered!\n"; Index: include/llvm/Support/CommandLine.h =================================================================== --- include/llvm/Support/CommandLine.h +++ include/llvm/Support/CommandLine.h @@ -72,9 +72,6 @@ // (Currently not perfect, but best-effort.) void PrintOptionValues(); -// MarkOptionsChanged - Internal helper function. -void MarkOptionsChanged(); - //===----------------------------------------------------------------------===// // Flags permitted to be passed to command line arguments // @@ -529,8 +526,11 @@ const char *Name; const char *HelpStr; }; + Option *Owner; public: + generic_parser_base(Option *O) : Owner(O){}; + virtual ~generic_parser_base() {} // Base class should have virtual-dtor // getNumOptions - Virtual function implemented by generic subclass to @@ -569,18 +569,13 @@ printGenericOptionDiff(O, V, Default, GlobalWidth); } - void initialize(Option &O) { - // All of the modifiers for the option have been processed by now, so the - // argstr field should be stable, copy it down now. - // - hasArgStr = O.hasArgStr(); - } + void initialize() {} void getExtraOptionNames(SmallVectorImpl &OptionNames) { // If there has been no argstr specified, that means that we need to add an // argument for every possible option. This ensures that our options are // vectored to us. - if (!hasArgStr) + if (!Owner->hasArgStr()) for (unsigned i = 0, e = getNumOptions(); i != e; ++i) OptionNames.push_back(getOption(i)); } @@ -597,7 +592,7 @@ // // If this is the case, we cannot allow a value. // - if (hasArgStr) + if (Owner->hasArgStr()) return ValueRequired; else return ValueDisallowed; @@ -607,9 +602,6 @@ // argument string. If the option is not found, getNumOptions() is returned. // unsigned findOption(const char *Name); - -protected: - bool hasArgStr; }; // Default parser implementation - This implementation depends on having a @@ -629,6 +621,7 @@ SmallVector Values; public: + parser(Option *O) : generic_parser_base(O){}; typedef DataType parser_data_type; // Implement virtual functions needed by generic_parser_base @@ -646,7 +639,7 @@ // parse - Return true on error. bool parse(Option &O, StringRef ArgName, StringRef Arg, DataType &V) { StringRef ArgVal; - if (hasArgStr) + if (Owner->hasArgStr()) ArgVal = Arg; else ArgVal = ArgName; @@ -667,7 +660,7 @@ assert(findOption(Name) == Values.size() && "Option already exists!"); OptionInfo X(Name, static_cast(V), HelpStr); Values.push_back(X); - MarkOptionsChanged(); + AddLiteralOption(Owner, Name); } /// removeLiteralOption - Remove the specified option. @@ -684,6 +677,8 @@ // class basic_parser_impl { // non-template implementation of basic_parser public: + basic_parser_impl(Option *O) : Owner(O){}; + virtual ~basic_parser_impl() {} enum ValueExpected getValueExpectedFlagDefault() const { @@ -692,7 +687,7 @@ void getExtraOptionNames(SmallVectorImpl &) {} - void initialize(Option &) {} + void initialize() {} // Return the width of the option tag for printing... size_t getOptionWidth(const Option &O) const; @@ -715,6 +710,8 @@ protected: // A helper for basic_parser::printOptionDiff. void printOptionName(const Option &O, size_t GlobalWidth) const; + + Option *Owner; }; // basic_parser - The real basic parser is just a template wrapper that provides @@ -722,6 +719,7 @@ // template class basic_parser : public basic_parser_impl { public: + basic_parser(Option *O) : basic_parser_impl(O){}; typedef DataType parser_data_type; typedef OptionValue OptVal; }; @@ -733,10 +731,12 @@ const char *ArgStr; public: + parser(Option *O) : basic_parser(O){}; + // parse - Return true on error. bool parse(Option &O, StringRef ArgName, StringRef Arg, bool &Val); - template void initialize(Opt &O) { ArgStr = O.ArgStr; } + void initialize() { ArgStr = Owner->ArgStr; } enum ValueExpected getValueExpectedFlagDefault() const { return ValueOptional; @@ -758,6 +758,8 @@ // parser template <> class parser : public basic_parser { public: + parser(Option *O) : basic_parser(O){}; + // parse - Return true on error. bool parse(Option &O, StringRef ArgName, StringRef Arg, boolOrDefault &Val); @@ -782,6 +784,8 @@ // template <> class parser : public basic_parser { public: + parser(Option *O) : basic_parser(O){}; + // parse - Return true on error. bool parse(Option &O, StringRef ArgName, StringRef Arg, int &Val); @@ -802,6 +806,8 @@ // template <> class parser : public basic_parser { public: + parser(Option *O) : basic_parser(O){}; + // parse - Return true on error. bool parse(Option &O, StringRef ArgName, StringRef Arg, unsigned &Val); @@ -823,6 +829,8 @@ template <> class parser : public basic_parser { public: + parser(Option *O) : basic_parser(O){}; + // parse - Return true on error. bool parse(Option &O, StringRef ArgName, StringRef Arg, unsigned long long &Val); @@ -844,6 +852,8 @@ // template <> class parser : public basic_parser { public: + parser(Option *O) : basic_parser(O){}; + // parse - Return true on error. bool parse(Option &O, StringRef ArgName, StringRef Arg, double &Val); @@ -864,6 +874,8 @@ // template <> class parser : public basic_parser { public: + parser(Option *O) : basic_parser(O){}; + // parse - Return true on error. bool parse(Option &O, StringRef ArgName, StringRef Arg, float &Val); @@ -884,6 +896,8 @@ // template <> class parser : public basic_parser { public: + parser(Option *O) : basic_parser(O){}; + // parse - Return true on error. bool parse(Option &, StringRef, StringRef Arg, std::string &Value) { Value = Arg.str(); @@ -907,6 +921,8 @@ // template <> class parser : public basic_parser { public: + parser(Option *O) : basic_parser(O){}; + // parse - Return true on error. bool parse(Option &, StringRef, StringRef Arg, char &Value) { Value = Arg[0]; @@ -1166,7 +1182,7 @@ void done() { addArgument(); - Parser.initialize(*this); + Parser.initialize(); } public: @@ -1183,7 +1199,7 @@ // One option... template explicit opt(const M0t &M0) - : Option(Optional, NotHidden) { + : Option(Optional, NotHidden), Parser(this) { apply(M0, this); done(); } @@ -1191,7 +1207,7 @@ // Two options... template opt(const M0t &M0, const M1t &M1) - : Option(Optional, NotHidden) { + : Option(Optional, NotHidden), Parser(this) { apply(M0, this); apply(M1, this); done(); @@ -1200,7 +1216,7 @@ // Three options... template opt(const M0t &M0, const M1t &M1, const M2t &M2) - : Option(Optional, NotHidden) { + : Option(Optional, NotHidden), Parser(this) { apply(M0, this); apply(M1, this); apply(M2, this); @@ -1209,7 +1225,7 @@ // Four options... template opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3) - : Option(Optional, NotHidden) { + : Option(Optional, NotHidden), Parser(this) { apply(M0, this); apply(M1, this); apply(M2, this); @@ -1219,7 +1235,7 @@ // Five options... template opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3, const M4t &M4) - : Option(Optional, NotHidden) { + : Option(Optional, NotHidden), Parser(this) { apply(M0, this); apply(M1, this); apply(M2, this); @@ -1231,7 +1247,7 @@ template opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3, const M4t &M4, const M5t &M5) - : Option(Optional, NotHidden) { + : Option(Optional, NotHidden), Parser(this) { apply(M0, this); apply(M1, this); apply(M2, this); @@ -1245,7 +1261,7 @@ class M6t> opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3, const M4t &M4, const M5t &M5, const M6t &M6) - : Option(Optional, NotHidden) { + : Option(Optional, NotHidden), Parser(this) { apply(M0, this); apply(M1, this); apply(M2, this); @@ -1260,7 +1276,7 @@ class M6t, class M7t> opt(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3, const M4t &M4, const M5t &M5, const M6t &M6, const M7t &M7) - : Option(Optional, NotHidden) { + : Option(Optional, NotHidden), Parser(this) { apply(M0, this); apply(M1, this); apply(M2, this); @@ -1361,7 +1377,7 @@ void done() { addArgument(); - Parser.initialize(*this); + Parser.initialize(); } public: @@ -1377,14 +1393,14 @@ // One option... template explicit list(const M0t &M0) - : Option(ZeroOrMore, NotHidden) { + : Option(ZeroOrMore, NotHidden), Parser(this) { apply(M0, this); done(); } // Two options... template list(const M0t &M0, const M1t &M1) - : Option(ZeroOrMore, NotHidden) { + : Option(ZeroOrMore, NotHidden), Parser(this) { apply(M0, this); apply(M1, this); done(); @@ -1392,7 +1408,7 @@ // Three options... template list(const M0t &M0, const M1t &M1, const M2t &M2) - : Option(ZeroOrMore, NotHidden) { + : Option(ZeroOrMore, NotHidden), Parser(this) { apply(M0, this); apply(M1, this); apply(M2, this); @@ -1401,7 +1417,7 @@ // Four options... template list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3) - : Option(ZeroOrMore, NotHidden) { + : Option(ZeroOrMore, NotHidden), Parser(this) { apply(M0, this); apply(M1, this); apply(M2, this); @@ -1412,7 +1428,7 @@ template list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3, const M4t &M4) - : Option(ZeroOrMore, NotHidden) { + : Option(ZeroOrMore, NotHidden), Parser(this) { apply(M0, this); apply(M1, this); apply(M2, this); @@ -1424,7 +1440,7 @@ template list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3, const M4t &M4, const M5t &M5) - : Option(ZeroOrMore, NotHidden) { + : Option(ZeroOrMore, NotHidden), Parser(this) { apply(M0, this); apply(M1, this); apply(M2, this); @@ -1438,7 +1454,7 @@ class M6t> list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3, const M4t &M4, const M5t &M5, const M6t &M6) - : Option(ZeroOrMore, NotHidden) { + : Option(ZeroOrMore, NotHidden), Parser(this) { apply(M0, this); apply(M1, this); apply(M2, this); @@ -1453,7 +1469,7 @@ class M6t, class M7t> list(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3, const M4t &M4, const M5t &M5, const M6t &M6, const M7t &M7) - : Option(ZeroOrMore, NotHidden) { + : Option(ZeroOrMore, NotHidden), Parser(this) { apply(M0, this); apply(M1, this); apply(M2, this); @@ -1581,7 +1597,7 @@ void done() { addArgument(); - Parser.initialize(*this); + Parser.initialize(); } public: @@ -1595,14 +1611,14 @@ // One option... template explicit bits(const M0t &M0) - : Option(ZeroOrMore, NotHidden) { + : Option(ZeroOrMore, NotHidden), Parser(this) { apply(M0, this); done(); } // Two options... template bits(const M0t &M0, const M1t &M1) - : Option(ZeroOrMore, NotHidden) { + : Option(ZeroOrMore, NotHidden), Parser(this) { apply(M0, this); apply(M1, this); done(); @@ -1610,7 +1626,7 @@ // Three options... template bits(const M0t &M0, const M1t &M1, const M2t &M2) - : Option(ZeroOrMore, NotHidden) { + : Option(ZeroOrMore, NotHidden), Parser(this) { apply(M0, this); apply(M1, this); apply(M2, this); @@ -1619,7 +1635,7 @@ // Four options... template bits(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3) - : Option(ZeroOrMore, NotHidden) { + : Option(ZeroOrMore, NotHidden), Parser(this) { apply(M0, this); apply(M1, this); apply(M2, this); @@ -1630,7 +1646,7 @@ template bits(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3, const M4t &M4) - : Option(ZeroOrMore, NotHidden) { + : Option(ZeroOrMore, NotHidden), Parser(this) { apply(M0, this); apply(M1, this); apply(M2, this); @@ -1642,7 +1658,7 @@ template bits(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3, const M4t &M4, const M5t &M5) - : Option(ZeroOrMore, NotHidden) { + : Option(ZeroOrMore, NotHidden), Parser(this) { apply(M0, this); apply(M1, this); apply(M2, this); @@ -1656,7 +1672,7 @@ class M6t> bits(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3, const M4t &M4, const M5t &M5, const M6t &M6) - : Option(ZeroOrMore, NotHidden) { + : Option(ZeroOrMore, NotHidden), Parser(this) { apply(M0, this); apply(M1, this); apply(M2, this); @@ -1671,7 +1687,7 @@ class M6t, class M7t> bits(const M0t &M0, const M1t &M1, const M2t &M2, const M3t &M3, const M4t &M4, const M5t &M5, const M6t &M6, const M7t &M7) - : Option(ZeroOrMore, NotHidden) { + : Option(ZeroOrMore, NotHidden), Parser(this) { apply(M0, this); apply(M1, this); apply(M2, this); @@ -1818,7 +1834,11 @@ /// This interface is useful for modifying options in libraries that are out of /// the control of the client. The options should be modified before calling /// llvm::cl::ParseCommandLineOptions(). -void getRegisteredOptions(StringMap