Skip to content

Commit dcb6d21

Browse files
committed
Reapply "[Option] Add "Visibility" field and clone the OptTable APIs to use it"
This reverts commit 4e3b894, with fixes for places I'd missed updating in lld and lldb. I've also renamed OptionVisibility::Default to "DefaultVis" to avoid ambiguity since the undecorated name has to be available anywhere Options.inc is included. Original message follows: This splits OptTable's "Flags" field into "Flags" and "Visibility", updates the places where we instantiate Option tables, and adds variants of the OptTable APIs that use Visibility mask instead of Include/Exclude flags. We need to do this to clean up a bunch of complexity in the clang driver's option handling - there's a whole slew of flags like CoreOption, NoDriverOption, and FlangOnlyOption there today to try to handle all of the permutations of flags that the various drivers need, but it really doesn't scale well, as can be seen by things like the somewhat recently introduced CLDXCOption. Instead, we'll provide an additive model for visibility that's separate from the other flags. For things like "HelpHidden", which is used as a "subtractive" modifier for option visibility, we leave that in "Flags" and handle it as a special case. Note that we don't actually update the users of the Include/Exclude APIs here or change the flags that exist in clang at all - that will come in a follow up that refactors clang's Options.td to use the increased flexibility this change allows. Differential Revision: https://reviews.llvm.org/D157149
1 parent d60c3d0 commit dcb6d21

File tree

33 files changed

+349
-81
lines changed

33 files changed

+349
-81
lines changed

clang-tools-extra/clangd/CompileCommands.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ llvm::ArrayRef<ArgStripper::Rule> ArgStripper::rulesFor(llvm::StringRef Arg) {
494494
static constexpr llvm::ArrayRef<llvm::StringLiteral> NAME( \
495495
NAME##_init, std::size(NAME##_init) - 1);
496496
#define OPTION(PREFIX, PREFIXED_NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, \
497-
FLAGS, PARAM, HELP, METAVAR, VALUES) \
497+
FLAGS, VISIBILITY, PARAM, HELP, METAVAR, VALUES) \
498498
Prefixes[DriverID::OPT_##ID] = PREFIX;
499499
#include "clang/Driver/Options.inc"
500500
#undef OPTION
@@ -506,7 +506,7 @@ llvm::ArrayRef<ArgStripper::Rule> ArgStripper::rulesFor(llvm::StringRef Arg) {
506506
const void *AliasArgs;
507507
} AliasTable[] = {
508508
#define OPTION(PREFIX, PREFIXED_NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, \
509-
FLAGS, PARAM, HELP, METAVAR, VALUES) \
509+
FLAGS, VISIBILITY, PARAM, HELP, METAVAR, VALUES) \
510510
{DriverID::OPT_##ID, DriverID::OPT_##ALIAS, ALIASARGS},
511511
#include "clang/Driver/Options.inc"
512512
#undef OPTION

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -423,9 +423,9 @@ static T extractMaskValue(T KeyPath) {
423423

424424
#define PARSE_OPTION_WITH_MARSHALLING( \
425425
ARGS, DIAGS, PREFIX_TYPE, SPELLING, ID, KIND, GROUP, ALIAS, ALIASARGS, \
426-
FLAGS, PARAM, HELPTEXT, METAVAR, VALUES, SHOULD_PARSE, ALWAYS_EMIT, \
427-
KEYPATH, DEFAULT_VALUE, IMPLIED_CHECK, IMPLIED_VALUE, NORMALIZER, \
428-
DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX) \
426+
FLAGS, VISIBILITY, PARAM, HELPTEXT, METAVAR, VALUES, SHOULD_PARSE, \
427+
ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE, IMPLIED_CHECK, IMPLIED_VALUE, \
428+
NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX) \
429429
if ((FLAGS)&options::CC1Option) { \
430430
KEYPATH = MERGER(KEYPATH, DEFAULT_VALUE); \
431431
if (IMPLIED_CHECK) \
@@ -440,9 +440,9 @@ static T extractMaskValue(T KeyPath) {
440440
// with lifetime extension of the reference.
441441
#define GENERATE_OPTION_WITH_MARSHALLING( \
442442
CONSUMER, PREFIX_TYPE, SPELLING, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, \
443-
PARAM, HELPTEXT, METAVAR, VALUES, SHOULD_PARSE, ALWAYS_EMIT, KEYPATH, \
444-
DEFAULT_VALUE, IMPLIED_CHECK, IMPLIED_VALUE, NORMALIZER, DENORMALIZER, \
445-
MERGER, EXTRACTOR, TABLE_INDEX) \
443+
VISIBILKITY, PARAM, HELPTEXT, METAVAR, VALUES, SHOULD_PARSE, ALWAYS_EMIT, \
444+
KEYPATH, DEFAULT_VALUE, IMPLIED_CHECK, IMPLIED_VALUE, NORMALIZER, \
445+
DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX) \
446446
if ((FLAGS)&options::CC1Option) { \
447447
[&](const auto &Extracted) { \
448448
if (ALWAYS_EMIT || \

lld/COFF/DriverUtils.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include <optional>
3939

4040
using namespace llvm::COFF;
41+
using namespace llvm::opt;
4142
using namespace llvm;
4243
using llvm::sys::Process;
4344

lld/MachO/DriverUtils.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,13 @@ using namespace lld::macho;
4444

4545
// Create table mapping all options defined in Options.td
4646
static constexpr OptTable::Info optInfo[] = {
47-
#define OPTION(X1, X2, ID, KIND, GROUP, ALIAS, X7, X8, X9, X10, X11, X12) \
48-
{X1, X2, X10, X11, OPT_##ID, Option::KIND##Class, \
49-
X9, X8, OPT_##GROUP, OPT_##ALIAS, X7, X12},
47+
#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, \
48+
VISIBILITY, PARAM, HELPTEXT, METAVAR, VALUES) \
49+
{PREFIX, NAME, HELPTEXT, \
50+
METAVAR, OPT_##ID, opt::Option::KIND##Class, \
51+
PARAM, FLAGS, VISIBILITY, \
52+
OPT_##GROUP, OPT_##ALIAS, ALIASARGS, \
53+
VALUES},
5054
#include "Options.inc"
5155
#undef OPTION
5256
};

lld/MinGW/Driver.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#endif
5252

5353
using namespace lld;
54+
using namespace llvm::opt;
5455
using namespace llvm;
5556

5657
// Create OptTable
@@ -71,9 +72,13 @@ enum {
7172

7273
// Create table mapping all options defined in Options.td
7374
static constexpr opt::OptTable::Info infoTable[] = {
74-
#define OPTION(X1, X2, ID, KIND, GROUP, ALIAS, X7, X8, X9, X10, X11, X12) \
75-
{X1, X2, X10, X11, OPT_##ID, opt::Option::KIND##Class, \
76-
X9, X8, OPT_##GROUP, OPT_##ALIAS, X7, X12},
75+
#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, \
76+
VISIBILITY, PARAM, HELPTEXT, METAVAR, VALUES) \
77+
{PREFIX, NAME, HELPTEXT, \
78+
METAVAR, OPT_##ID, opt::Option::KIND##Class, \
79+
PARAM, FLAGS, VISIBILITY, \
80+
OPT_##GROUP, OPT_##ALIAS, ALIASARGS, \
81+
VALUES},
7782
#include "Options.inc"
7883
#undef OPTION
7984
};

lld/wasm/Driver.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
using namespace llvm;
4141
using namespace llvm::object;
42+
using namespace llvm::opt;
4243
using namespace llvm::sys;
4344
using namespace llvm::wasm;
4445

@@ -111,9 +112,13 @@ bool link(ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
111112

112113
// Create table mapping all options defined in Options.td
113114
static constexpr opt::OptTable::Info optInfo[] = {
114-
#define OPTION(X1, X2, ID, KIND, GROUP, ALIAS, X7, X8, X9, X10, X11, X12) \
115-
{X1, X2, X10, X11, OPT_##ID, opt::Option::KIND##Class, \
116-
X9, X8, OPT_##GROUP, OPT_##ALIAS, X7, X12},
115+
#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, \
116+
VISIBILITY, PARAM, HELPTEXT, METAVAR, VALUES) \
117+
{PREFIX, NAME, HELPTEXT, \
118+
METAVAR, OPT_##ID, opt::Option::KIND##Class, \
119+
PARAM, FLAGS, VISIBILITY, \
120+
OPT_##GROUP, OPT_##ALIAS, ALIASARGS, \
121+
VALUES},
117122
#include "Options.inc"
118123
#undef OPTION
119124
};

lldb/tools/driver/Driver.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ using namespace lldb;
5050
using namespace llvm;
5151

5252
namespace {
53+
using namespace llvm::opt;
54+
5355
enum ID {
5456
OPT_INVALID = 0, // This is not an option ID.
5557
#define OPTION(...) LLVM_MAKE_OPT_ID(__VA_ARGS__),

lldb/tools/lldb-server/lldb-gdbserver.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,8 @@ void ConnectToRemote(MainLoop &mainloop,
272272
}
273273

274274
namespace {
275+
using namespace llvm::opt;
276+
275277
enum ID {
276278
OPT_INVALID = 0, // This is not an option ID.
277279
#define OPTION(...) LLVM_MAKE_OPT_ID(__VA_ARGS__),

lldb/tools/lldb-vscode/lldb-vscode.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ typedef int socklen_t;
7676
using namespace lldb_vscode;
7777

7878
namespace {
79+
using namespace llvm::opt;
80+
7981
enum ID {
8082
OPT_INVALID = 0, // This is not an option ID.
8183
#define OPTION(...) LLVM_MAKE_OPT_ID(__VA_ARGS__),

llvm/include/llvm/Option/OptParser.td

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ def RenderJoined : OptionFlag;
7373
// (only sensible on joined options).
7474
def RenderSeparate : OptionFlag;
7575

76+
// Define Visibility categories
77+
78+
class OptionVisibility {}
79+
80+
// Explicit specifier for default visibility
81+
def DefaultVis : OptionVisibility;
82+
7683
// Define the option group class.
7784

7885
class OptionGroup<string name> {
@@ -81,6 +88,7 @@ class OptionGroup<string name> {
8188
string HelpText = ?;
8289
OptionGroup Group = ?;
8390
list<OptionFlag> Flags = [];
91+
list<OptionVisibility> Visibility = [];
8492
}
8593

8694
// Define the option class.
@@ -97,6 +105,7 @@ class Option<list<string> prefixes, string name, OptionKind kind> {
97105
string Values = ?;
98106
code ValuesCode = ?;
99107
list<OptionFlag> Flags = [];
108+
list<OptionVisibility> Visibility = [DefaultVis];
100109
OptionGroup Group = ?;
101110
Option Alias = ?;
102111
list<string> AliasArgs = [];
@@ -141,6 +150,9 @@ class Alias<Option alias> { Option Alias = alias; }
141150
class AliasArgs<list<string> aliasargs> { list<string> AliasArgs = aliasargs; }
142151
class EnumName<string name> { string EnumName = name; }
143152
class Flags<list<OptionFlag> flags> { list<OptionFlag> Flags = flags; }
153+
class Visibility<list<OptionVisibility> visibility> {
154+
list<OptionVisibility> Visibility = visibility;
155+
}
144156
class Group<OptionGroup group> { OptionGroup Group = group; }
145157
class HelpText<string text> { string HelpText = text; }
146158
class MetaVarName<string name> { string MetaVarName = name; }
@@ -239,7 +251,7 @@ class AlwaysEmit { bit ShouldAlwaysEmit = true; }
239251
class Normalizer<code normalizer> { code Normalizer = normalizer; }
240252
class Denormalizer<code denormalizer> { code Denormalizer = denormalizer; }
241253
class NormalizedValuesScope<code scope> { code NormalizedValuesScope = scope; }
242-
class NormalizedValues<list<code> definitions> { list<code> NormalizedValues = definitions; }
254+
class NormalizedValues<list<code> definitions> { list<code> NormalizedValues = definitions; }
243255
class ValueMerger<code merger> { code ValueMerger = merger; }
244256
class ValueExtractor<code extractor> { code ValueExtractor = extractor; }
245257

0 commit comments

Comments
 (0)