[RFC] Declare library command line options in TableGen, one struct per library

Progress update.

Landed: OptTable size, making it a cheaper option representation (#224374, #224508, #224805, #224807, #224813, #224818, #224822)

  • Info is 24 bytes, down from 88.
  • The strings are string table offsets.
  • TableGen emits the tables in a function with no relocations.

Landed: cl:: features removed or restricted

  • #224953 Remove cl::Sink
  • #224959 Remove cl::multi_val
  • #224975 Accept only true, false, 1 and 0 for cl::opt<bool> (-flag= is now an error)
  • #225609 Remove cl::DefaultOption (-h is now --help)
  • #225870, #225628 Remove unneeded cl::Optional and cl::ZeroOrMore from named options. NFC
  • #224958 Remove cl::Grouping

Landed: tools moved to OptTable, so that the parser modes above no longer have users

  • #224955 llvm-cov gcov (the last explicit cl::Grouping user)
  • #224964 yaml2obj, #224965 obj2yaml, #224966 split-file (the last LongOptionsUseDoubleDash users)

In review

  • #226347 Remove LongOptionsUseDoubleDash from cl::ParseCommandLineOptions
  • #226359 [BOLT] Remove cl::callback uses
  • #226087 [CGData] Declare command line options in TableGen, one struct per library
    • This is the first library to migrate. It adds the TableGen support (OptionsStruct, BoolField, ValueField), cl::LibraryOptions for cl:: dispatch, and -help-hidden output.
    • Migrating a library takes one .td file, a small private header, and one static opt::RegisterLibraryOptions<T> line.
    • T::Global is constant-initialized: string members are StringRef, and the parser keeps its own copy of each value.
    • Bools accept -x, -no-x and -x=true|false|1|0, as cl::opt<bool> does today.
  • #224978 Accept -no-<name> for cl::opt<bool>. Parked, since the replies in Cl::opt<bool> spellings: accept -no-<name>? retire -<name>={0,1,false,true}? were split on -no-x.

Next

  • The remaining cl::callback users: 10 in libraries.
    • Two need a hook that runs after parsing: -print-debug-counter and -time-passes-per-run.
    • GISel’s -disable-rule and -only-enable-rule can merge by position.
  • std::optional<T> fields, for options whose code checks getNumOccurrences().
  • Enum fields, then LLVMPasses.
4 Likes