Skip to content

Commit 4dcc159

Browse files
authored
[utils][TableGen] Implement clause aliases as alternative spellings (#141765)
Use the spellings in the generated clause parser. The functions `get<lang>ClauseKind` and `get<lang>ClauseName` are not yet updated. The definitions of both clauses and directives now take a list of "Spelling"s instead of a single string. For example ``` def ACCC_Copyin : Clause<[Spelling<"copyin">, Spelling<"present_or_copyin">, Spelling<"pcopyin">]> { ... } ``` A "Spelling" is a versioned string, defaulting to "all versions". For background information see https://discourse.llvm.org/t/rfc-alternative-spellings-of-openmp-directives/85507
1 parent 1be7c6f commit 4dcc159

File tree

9 files changed

+580
-436
lines changed

9 files changed

+580
-436
lines changed

llvm/include/llvm/Frontend/Directive/DirectiveBase.td

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,20 @@ class DirectiveLanguage {
5151
string flangClauseBaseClass = "";
5252
}
5353

54+
// Base class for versioned entities.
55+
class Versioned<int min = 1, int max = 0x7FFFFFFF> {
56+
// Mininum version number where this object is valid.
57+
int minVersion = min;
58+
59+
// Maximum version number where this object is valid.
60+
int maxVersion = max;
61+
}
62+
63+
class Spelling<string s, int min = 1, int max = 0x7FFFFFFF>
64+
: Versioned<min, max> {
65+
string spelling = s;
66+
}
67+
5468
// Some clauses take an argument from a predefined list of allowed keyword
5569
// values. For example, assume a clause "someclause" with an argument from
5670
// the list "foo", "bar", "baz". In the user source code this would look
@@ -81,12 +95,9 @@ class EnumVal<string n, int v, bit uv> {
8195
}
8296

8397
// Information about a specific clause.
84-
class Clause<string c> {
85-
// Name of the clause.
86-
string name = c;
87-
88-
// Define aliases used in the parser.
89-
list<string> aliases = [];
98+
class Clause<list<Spelling> ss> {
99+
// Spellings of the clause.
100+
list<Spelling> spellings = ss;
90101

91102
// Optional class holding value of the clause in clang AST.
92103
string clangClass = "";
@@ -134,15 +145,9 @@ class Clause<string c> {
134145
}
135146

136147
// Hold information about clause validity by version.
137-
class VersionedClause<Clause c, int min = 1, int max = 0x7FFFFFFF> {
138-
// Actual clause.
148+
class VersionedClause<Clause c, int min = 1, int max = 0x7FFFFFFF>
149+
: Versioned<min, max> {
139150
Clause clause = c;
140-
141-
// Mininum version number where this clause is valid.
142-
int minVersion = min;
143-
144-
// Maximum version number where this clause is valid.
145-
int maxVersion = max;
146151
}
147152

148153
// Kinds of directive associations.
@@ -190,15 +195,15 @@ class SourceLanguage<string n> {
190195
string name = n; // Name of the enum value in enum class Association.
191196
}
192197

193-
// The C languages also implies C++ until there is a reason to add C++
198+
// The C language also implies C++ until there is a reason to add C++
194199
// separately.
195200
def L_C : SourceLanguage<"C"> {}
196201
def L_Fortran : SourceLanguage<"Fortran"> {}
197202

198203
// Information about a specific directive.
199-
class Directive<string d> {
200-
// Name of the directive. Can be composite directive sepearted by whitespace.
201-
string name = d;
204+
class Directive<list<Spelling> ss> {
205+
// Spellings of the directive.
206+
list<Spelling> spellings = ss;
202207

203208
// Clauses cannot appear twice in the three allowed lists below. Also, since
204209
// required implies allowed, the same clause cannot appear in both the

0 commit comments

Comments
 (0)