Skip to content

Commit d394ab6

Browse files
committed
[llvm] Extract common OptTable bits into macros
All command-line tools using `llvm::opt` create an enum of option IDs and a table of `OptTable::Info` object. Most of the tools use the same ID (`OPT_##ID`), kind (`Option::KIND##Class`), group ID (`OPT_##GROUP`) and alias ID (`OPT_##ALIAS`). This patch extracts that common code into canonical macros. This results in fewer changes when tweaking the `OPTION` macros emitted by the TableGen backend. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D157028
1 parent a5724e5 commit d394ab6

File tree

37 files changed

+113
-326
lines changed

37 files changed

+113
-326
lines changed

clang/include/clang/Driver/Options.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@
99
#ifndef LLVM_CLANG_DRIVER_OPTIONS_H
1010
#define LLVM_CLANG_DRIVER_OPTIONS_H
1111

12-
namespace llvm {
13-
namespace opt {
14-
class OptTable;
15-
}
16-
}
12+
#include "llvm/Option/OptTable.h"
1713

1814
namespace clang {
1915
namespace driver {
@@ -42,9 +38,7 @@ enum ClangFlags {
4238

4339
enum ID {
4440
OPT_INVALID = 0, // This is not an option ID.
45-
#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
46-
HELPTEXT, METAVAR, VALUES) \
47-
OPT_##ID,
41+
#define OPTION(...) LLVM_MAKE_OPT_ID(__VA_ARGS__),
4842
#include "clang/Driver/Options.inc"
4943
LastOption
5044
#undef OPTION

clang/lib/Driver/DriverOptions.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ using namespace llvm::opt;
2121
#undef PREFIX
2222

2323
static const OptTable::Info InfoTable[] = {
24-
#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
25-
HELPTEXT, METAVAR, VALUES) \
26-
{PREFIX, NAME, HELPTEXT, METAVAR, OPT_##ID, Option::KIND##Class, \
27-
PARAM, FLAGS, OPT_##GROUP, OPT_##ALIAS, ALIASARGS, VALUES},
24+
#define OPTION(...) LLVM_CONSTRUCT_OPT_INFO(__VA_ARGS__),
2825
#include "clang/Driver/Options.inc"
2926
#undef OPTION
3027
};

clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,7 @@ enum WrapperFlags {
112112

113113
enum ID {
114114
OPT_INVALID = 0, // This is not an option ID.
115-
#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
116-
HELPTEXT, METAVAR, VALUES) \
117-
OPT_##ID,
115+
#define OPTION(...) LLVM_MAKE_OPT_ID(__VA_ARGS__),
118116
#include "LinkerWrapperOpts.inc"
119117
LastOption
120118
#undef OPTION
@@ -125,10 +123,7 @@ enum ID {
125123
#undef PREFIX
126124

127125
static const OptTable::Info InfoTable[] = {
128-
#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
129-
HELPTEXT, METAVAR, VALUES) \
130-
{PREFIX, NAME, HELPTEXT, METAVAR, OPT_##ID, Option::KIND##Class, \
131-
PARAM, FLAGS, OPT_##GROUP, OPT_##ALIAS, ALIASARGS, VALUES},
126+
#define OPTION(...) LLVM_CONSTRUCT_OPT_INFO(__VA_ARGS__),
132127
#include "LinkerWrapperOpts.inc"
133128
#undef OPTION
134129
};

lld/COFF/Driver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ MemoryBufferRef convertResToCOFF(ArrayRef<MemoryBufferRef> mbs,
230230
// Create enum with OPT_xxx values for each option in Options.td
231231
enum {
232232
OPT_INVALID = 0,
233-
#define OPTION(_1, _2, ID, _4, _5, _6, _7, _8, _9, _10, _11, _12) OPT_##ID,
233+
#define OPTION(...) LLVM_MAKE_OPT_ID(__VA_ARGS__),
234234
#include "Options.inc"
235235
#undef OPTION
236236
};

lld/COFF/DriverUtils.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -778,9 +778,7 @@ MemoryBufferRef convertResToCOFF(ArrayRef<MemoryBufferRef> mbs,
778778

779779
// Create table mapping all options defined in Options.td
780780
static const llvm::opt::OptTable::Info infoTable[] = {
781-
#define OPTION(X1, X2, ID, KIND, GROUP, ALIAS, X7, X8, X9, X10, X11, X12) \
782-
{X1, X2, X10, X11, OPT_##ID, llvm::opt::Option::KIND##Class, \
783-
X9, X8, OPT_##GROUP, OPT_##ALIAS, X7, X12},
781+
#define OPTION(...) LLVM_CONSTRUCT_OPT_INFO(__VA_ARGS__),
784782
#include "Options.inc"
785783
#undef OPTION
786784
};

lld/ELF/Driver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ELFOptTable : public llvm::opt::OptTable {
2525
// Create enum with OPT_xxx values for each option in Options.td
2626
enum {
2727
OPT_INVALID = 0,
28-
#define OPTION(_1, _2, ID, _4, _5, _6, _7, _8, _9, _10, _11, _12) OPT_##ID,
28+
#define OPTION(...) LLVM_MAKE_OPT_ID(__VA_ARGS__),
2929
#include "Options.inc"
3030
#undef OPTION
3131
};

lld/ELF/DriverUtils.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ using namespace lld::elf;
4040

4141
// Create table mapping all options defined in Options.td
4242
static const opt::OptTable::Info optInfo[] = {
43-
#define OPTION(X1, X2, ID, KIND, GROUP, ALIAS, X7, X8, X9, X10, X11, X12) \
44-
{X1, X2, X10, X11, OPT_##ID, opt::Option::KIND##Class, \
45-
X9, X8, OPT_##GROUP, OPT_##ALIAS, X7, X12},
43+
#define OPTION(...) LLVM_CONSTRUCT_OPT_INFO(__VA_ARGS__),
4644
#include "Options.inc"
4745
#undef OPTION
4846
};

lld/MachO/Driver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class MachOOptTable : public llvm::opt::OptTable {
3535
// Create enum with OPT_xxx values for each option in Options.td
3636
enum {
3737
OPT_INVALID = 0,
38-
#define OPTION(_1, _2, ID, _4, _5, _6, _7, _8, _9, _10, _11, _12) OPT_##ID,
38+
#define OPTION(...) LLVM_MAKE_OPT_ID(__VA_ARGS__),
3939
#include "Options.inc"
4040
#undef OPTION
4141
};

lld/MinGW/Driver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ using namespace llvm;
5555
// Create OptTable
5656
enum {
5757
OPT_INVALID = 0,
58-
#define OPTION(_1, _2, ID, _4, _5, _6, _7, _8, _9, _10, _11, _12) OPT_##ID,
58+
#define OPTION(...) LLVM_MAKE_OPT_ID(__VA_ARGS__),
5959
#include "Options.inc"
6060
#undef OPTION
6161
};

lld/wasm/Driver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ namespace {
4949
// Create enum with OPT_xxx values for each option in Options.td
5050
enum {
5151
OPT_INVALID = 0,
52-
#define OPTION(_1, _2, ID, _4, _5, _6, _7, _8, _9, _10, _11, _12) OPT_##ID,
52+
#define OPTION(...) LLVM_MAKE_OPT_ID(__VA_ARGS__),
5353
#include "Options.inc"
5454
#undef OPTION
5555
};

0 commit comments

Comments
 (0)