xref: /freebsd/contrib/llvm-project/llvm/include/llvm/Frontend/Directive/DirectiveBase.td (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
1//===-- DirectiveBase.td - Base directive definition file --*- tablegen -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This is the base definition file directives and clauses.
10//
11//===----------------------------------------------------------------------===//
12
13
14// General information about the directive language.
15class DirectiveLanguage {
16  // Name of the directive language such as omp or acc.
17  string name = ?;
18
19  // The C++ namespace that code of this directive language should be placed
20  // into. This namespace is nested in llvm namespace.
21  //
22  // By default, uses the name of the directive language as the only namespace.
23  // To avoid placing in any namespace, use "". To specify nested namespaces,
24  // use "::" as the delimiter, e.g., given "A::B", ops will be placed in
25  // `namespace A { namespace B { <directives-clauses> } }`.
26  string cppNamespace = name;
27
28  // Optional prefix used for the generation of the enumerator in the Directive
29  // enum.
30  string directivePrefix = "";
31
32  // Optional prefix used for the generation of the enumerator in the Clause
33  // enum.
34  string clausePrefix = "";
35
36  // Make the enum values available in the namespace. This allows us to
37  // write something like Enum_X if we have a `using namespace cppNamespace`.
38  bit makeEnumAvailableInNamespace = false;
39
40  // Generate include and macro to enable LLVM BitmaskEnum.
41  bit enableBitmaskEnumInNamespace = false;
42
43  // Header file included in the implementation code generated. Ususally the
44  // output file of the declaration code generation. Can be left blank.
45  string includeHeader = "";
46
47  // EnumSet class name used for clauses to generated the allowed clauses map.
48  string clauseEnumSetClass = "";
49
50  // Class holding the clauses in the flang parse-tree.
51  string flangClauseBaseClass = "";
52}
53
54// Information about values accepted by enum-like clauses
55class ClauseVal<string n, int v, bit uv> {
56  // Name of the clause value.
57  string name = n;
58
59  // Integer value of the clause.
60  int value = v;
61
62  // Can user specify this value?
63  bit isUserValue = uv;
64
65  // Set clause value used by default when unknown.
66  bit isDefault = false;
67}
68
69// Information about a specific clause.
70class Clause<string c> {
71  // Name of the clause.
72  string name = c;
73
74  // Define an alternative name return in get<LanguageName>ClauseName function.
75  string alternativeName = "";
76
77  // Define aliases used in the parser.
78  list<string> aliases = [];
79
80  // Optional class holding value of the clause in clang AST.
81  string clangClass = "";
82
83  // Optional class holding value of the clause in flang AST.
84  string flangClass = "";
85
86  // If set to true, value is optional. Not optional by default.
87  bit isValueOptional = false;
88
89  // Name of enum when there is a list of allowed clause values.
90  string enumClauseValue = "";
91
92  // List of allowed clause values
93  list<ClauseVal> allowedClauseValues = [];
94
95  // If set to true, value class is part of a list. Single class by default.
96  bit isValueList = false;
97
98  // Define a default value such as "*".
99  string defaultValue = "";
100
101  // Is clause implicit? If clause is set as implicit, the default kind will
102  // be return in get<LanguageName>ClauseKind instead of their own kind.
103  bit isImplicit = false;
104
105  // Set clause used by default when unknown. Function returning the kind
106  // of enumeration will use this clause as the default.
107  bit isDefault = false;
108
109  // Prefix before the actual value. Used in the parser generation.
110  // `clause(prefix: value)`
111  string prefix = "";
112
113  // Set the prefix as optional.
114  // `clause([prefix]: value)`
115  bit isPrefixOptional = true;
116}
117
118// Hold information about clause validity by version.
119class VersionedClause<Clause c, int min = 1, int max = 0x7FFFFFFF> {
120  // Actual clause.
121  Clause clause = c;
122
123  // Mininum version number where this clause is valid.
124  int minVersion = min;
125
126  // Maximum version number where this clause is valid.
127  int maxVersion = max;
128}
129
130// Kinds of directive associations.
131class Association<string n> {
132  string name = n;  // Name of the enum value in enum class Association.
133}
134// All of the AS_Xyz names are recognized by TableGen in order to calculate
135// the association in the AS_FromLeaves case.
136def AS_None : Association<"None"> {}              // No association
137def AS_Block : Association<"Block"> {}            // Block (incl. single
138                                                  // statement)
139def AS_Declaration : Association<"Declaration"> {}   // Declaration
140def AS_Delimited : Association<"Delimited"> {}    // Region delimited with
141                                                  // begin/end
142def AS_Loop : Association<"Loop"> {}              // Loop
143def AS_Separating : Association<"Separating"> {}  // Separates parts of a
144                                                  // construct
145
146def AS_FromLeaves : Association<"FromLeaves"> {}    // See below
147// AS_FromLeaves can be used for combined/composite directives, and the actual
148// association will be computed based on associations of the leaf constructs:
149//   (x + y) + z = x + (y + z)
150//   x + y = y + x
151//   x + x = x
152//   AS_None + x = x
153//   AS_Block + AS_Loop = AS_Loop
154// Other combinations are not allowed.
155// This association is not valid for leaf constructs.
156// The name "AS_FromLeaves" is recognized by TableGen, and there is no enum
157// generated for it.
158
159// Kinds of directive categories.
160class Category<string n> {
161  string name = n;  // Name of the enum value in enum class Category.
162}
163
164def CA_Declarative: Category<"Declarative"> {}
165def CA_Executable: Category<"Executable"> {}
166def CA_Informational: Category<"Informational"> {}
167def CA_Meta: Category<"Meta"> {}
168def CA_Subsidiary: Category<"Subsidiary"> {}
169def CA_Utility: Category<"Utility"> {}
170
171// Information about a specific directive.
172class Directive<string d> {
173  // Name of the directive. Can be composite directive sepearted by whitespace.
174  string name = d;
175
176  // Define an alternative name return in get<LanguageName>DirectiveName
177  // function.
178  string alternativeName = "";
179
180  // Clauses cannot appear twice in the three allowed lists below. Also, since
181  // required implies allowed, the same clause cannot appear in both the
182  // allowedClauses and requiredClauses lists.
183
184  // List of allowed clauses for the directive.
185  list<VersionedClause>  allowedClauses = [];
186
187  // List of clauses that are allowed to appear only once.
188  list<VersionedClause> allowedOnceClauses = [];
189
190  // List of clauses that are allowed but mutually exclusive.
191  list<VersionedClause> allowedExclusiveClauses = [];
192
193  // List of clauses that are required.
194  list<VersionedClause> requiredClauses = [];
195
196  // List of leaf constituent directives in the order in which they appear
197  // in the combined/composite directive.
198  list<Directive> leafConstructs = [];
199
200  // Set directive used by default when unknown.
201  bit isDefault = false;
202
203  // What the directive is associated with.
204  Association association = AS_FromLeaves;
205
206  // The category of the directive.
207  Category category = ?;
208}
209