17
17
18
18
using namespace mlir ;
19
19
using namespace mlir ::tblgen;
20
+ using llvm::DefInit;
21
+ using llvm::Init;
22
+ using llvm::ListInit;
23
+ using llvm::Record;
24
+ using llvm::RecordVal;
25
+ using llvm::StringInit;
20
26
21
27
// ===----------------------------------------------------------------------===//
22
28
// AttrOrTypeBuilder
@@ -35,14 +41,13 @@ bool AttrOrTypeBuilder::hasInferredContextParameter() const {
35
41
// AttrOrTypeDef
36
42
// ===----------------------------------------------------------------------===//
37
43
38
- AttrOrTypeDef::AttrOrTypeDef (const llvm:: Record *def) : def(def) {
44
+ AttrOrTypeDef::AttrOrTypeDef (const Record *def) : def(def) {
39
45
// Populate the builders.
40
- auto *builderList =
41
- dyn_cast_or_null<llvm:: ListInit>(def->getValueInit (" builders" ));
46
+ const auto *builderList =
47
+ dyn_cast_or_null<ListInit>(def->getValueInit (" builders" ));
42
48
if (builderList && !builderList->empty ()) {
43
- for (const llvm::Init *init : builderList->getValues ()) {
44
- AttrOrTypeBuilder builder (cast<llvm::DefInit>(init)->getDef (),
45
- def->getLoc ());
49
+ for (const Init *init : builderList->getValues ()) {
50
+ AttrOrTypeBuilder builder (cast<DefInit>(init)->getDef (), def->getLoc ());
46
51
47
52
// Ensure that all parameters have names.
48
53
for (const AttrOrTypeBuilder::Parameter ¶m :
@@ -56,16 +61,16 @@ AttrOrTypeDef::AttrOrTypeDef(const llvm::Record *def) : def(def) {
56
61
57
62
// Populate the traits.
58
63
if (auto *traitList = def->getValueAsListInit (" traits" )) {
59
- SmallPtrSet<const llvm:: Init *, 32 > traitSet;
64
+ SmallPtrSet<const Init *, 32 > traitSet;
60
65
traits.reserve (traitSet.size ());
61
- llvm::unique_function<void (const llvm:: ListInit *)> processTraitList =
62
- [&](const llvm:: ListInit *traitList) {
66
+ llvm::unique_function<void (const ListInit *)> processTraitList =
67
+ [&](const ListInit *traitList) {
63
68
for (auto *traitInit : *traitList) {
64
69
if (!traitSet.insert (traitInit).second )
65
70
continue ;
66
71
67
72
// If this is an interface, add any bases to the trait list.
68
- auto *traitDef = cast<llvm:: DefInit>(traitInit)->getDef ();
73
+ auto *traitDef = cast<DefInit>(traitInit)->getDef ();
69
74
if (traitDef->isSubClassOf (" Interface" )) {
70
75
if (auto *bases = traitDef->getValueAsListInit (" baseInterfaces" ))
71
76
processTraitList (bases);
@@ -111,7 +116,7 @@ AttrOrTypeDef::AttrOrTypeDef(const llvm::Record *def) : def(def) {
111
116
}
112
117
113
118
Dialect AttrOrTypeDef::getDialect () const {
114
- auto *dialect = dyn_cast<llvm:: DefInit>(def->getValue (" dialect" )->getValue ());
119
+ const auto *dialect = dyn_cast<DefInit>(def->getValue (" dialect" )->getValue ());
115
120
return Dialect (dialect ? dialect->getDef () : nullptr );
116
121
}
117
122
@@ -126,17 +131,17 @@ StringRef AttrOrTypeDef::getCppBaseClassName() const {
126
131
}
127
132
128
133
bool AttrOrTypeDef::hasDescription () const {
129
- const llvm:: RecordVal *desc = def->getValue (" description" );
130
- return desc && isa<llvm:: StringInit>(desc->getValue ());
134
+ const RecordVal *desc = def->getValue (" description" );
135
+ return desc && isa<StringInit>(desc->getValue ());
131
136
}
132
137
133
138
StringRef AttrOrTypeDef::getDescription () const {
134
139
return def->getValueAsString (" description" );
135
140
}
136
141
137
142
bool AttrOrTypeDef::hasSummary () const {
138
- const llvm:: RecordVal *summary = def->getValue (" summary" );
139
- return summary && isa<llvm:: StringInit>(summary->getValue ());
143
+ const RecordVal *summary = def->getValue (" summary" );
144
+ return summary && isa<StringInit>(summary->getValue ());
140
145
}
141
146
142
147
StringRef AttrOrTypeDef::getSummary () const {
@@ -249,9 +254,9 @@ StringRef TypeDef::getTypeName() const {
249
254
template <typename InitT>
250
255
auto AttrOrTypeParameter::getDefValue (StringRef name) const {
251
256
std::optional<decltype (std::declval<InitT>().getValue ())> result;
252
- if (auto *param = dyn_cast<llvm:: DefInit>(getDef ()))
253
- if (auto *init = param->getDef ()->getValue (name))
254
- if (auto *value = dyn_cast_or_null<InitT>(init->getValue ()))
257
+ if (const auto *param = dyn_cast<DefInit>(getDef ()))
258
+ if (const auto *init = param->getDef ()->getValue (name))
259
+ if (const auto *value = dyn_cast_or_null<InitT>(init->getValue ()))
255
260
result = value->getValue ();
256
261
return result;
257
262
}
@@ -270,20 +275,20 @@ std::string AttrOrTypeParameter::getAccessorName() const {
270
275
}
271
276
272
277
std::optional<StringRef> AttrOrTypeParameter::getAllocator () const {
273
- return getDefValue<llvm:: StringInit>(" allocator" );
278
+ return getDefValue<StringInit>(" allocator" );
274
279
}
275
280
276
281
StringRef AttrOrTypeParameter::getComparator () const {
277
- return getDefValue<llvm:: StringInit>(" comparator" ).value_or (" $_lhs == $_rhs" );
282
+ return getDefValue<StringInit>(" comparator" ).value_or (" $_lhs == $_rhs" );
278
283
}
279
284
280
285
StringRef AttrOrTypeParameter::getCppType () const {
281
- if (auto *stringType = dyn_cast<llvm:: StringInit>(getDef ()))
286
+ if (auto *stringType = dyn_cast<StringInit>(getDef ()))
282
287
return stringType->getValue ();
283
- auto cppType = getDefValue<llvm:: StringInit>(" cppType" );
288
+ auto cppType = getDefValue<StringInit>(" cppType" );
284
289
if (cppType)
285
290
return *cppType;
286
- if (auto *init = dyn_cast<llvm:: DefInit>(getDef ()))
291
+ if (const auto *init = dyn_cast<DefInit>(getDef ()))
287
292
llvm::PrintFatalError (
288
293
init->getDef ()->getLoc (),
289
294
Twine (" Missing `cppType` field in Attribute/Type parameter: " ) +
@@ -295,52 +300,48 @@ StringRef AttrOrTypeParameter::getCppType() const {
295
300
}
296
301
297
302
StringRef AttrOrTypeParameter::getCppAccessorType () const {
298
- return getDefValue<llvm::StringInit>(" cppAccessorType" )
299
- .value_or (getCppType ());
303
+ return getDefValue<StringInit>(" cppAccessorType" ).value_or (getCppType ());
300
304
}
301
305
302
306
StringRef AttrOrTypeParameter::getCppStorageType () const {
303
- return getDefValue<llvm:: StringInit>(" cppStorageType" ).value_or (getCppType ());
307
+ return getDefValue<StringInit>(" cppStorageType" ).value_or (getCppType ());
304
308
}
305
309
306
310
StringRef AttrOrTypeParameter::getConvertFromStorage () const {
307
- return getDefValue<llvm:: StringInit>(" convertFromStorage" ).value_or (" $_self" );
311
+ return getDefValue<StringInit>(" convertFromStorage" ).value_or (" $_self" );
308
312
}
309
313
310
314
std::optional<StringRef> AttrOrTypeParameter::getParser () const {
311
- return getDefValue<llvm:: StringInit>(" parser" );
315
+ return getDefValue<StringInit>(" parser" );
312
316
}
313
317
314
318
std::optional<StringRef> AttrOrTypeParameter::getPrinter () const {
315
- return getDefValue<llvm:: StringInit>(" printer" );
319
+ return getDefValue<StringInit>(" printer" );
316
320
}
317
321
318
322
std::optional<StringRef> AttrOrTypeParameter::getSummary () const {
319
- return getDefValue<llvm:: StringInit>(" summary" );
323
+ return getDefValue<StringInit>(" summary" );
320
324
}
321
325
322
326
StringRef AttrOrTypeParameter::getSyntax () const {
323
- if (auto *stringType = dyn_cast<llvm:: StringInit>(getDef ()))
327
+ if (auto *stringType = dyn_cast<StringInit>(getDef ()))
324
328
return stringType->getValue ();
325
- return getDefValue<llvm:: StringInit>(" syntax" ).value_or (getCppType ());
329
+ return getDefValue<StringInit>(" syntax" ).value_or (getCppType ());
326
330
}
327
331
328
332
bool AttrOrTypeParameter::isOptional () const {
329
333
return getDefaultValue ().has_value ();
330
334
}
331
335
332
336
std::optional<StringRef> AttrOrTypeParameter::getDefaultValue () const {
333
- std::optional<StringRef> result =
334
- getDefValue<llvm::StringInit>(" defaultValue" );
337
+ std::optional<StringRef> result = getDefValue<StringInit>(" defaultValue" );
335
338
return result && !result->empty () ? result : std::nullopt;
336
339
}
337
340
338
- const llvm::Init *AttrOrTypeParameter::getDef () const {
339
- return def->getArg (index);
340
- }
341
+ const Init *AttrOrTypeParameter::getDef () const { return def->getArg (index); }
341
342
342
343
std::optional<Constraint> AttrOrTypeParameter::getConstraint () const {
343
- if (auto *param = dyn_cast<llvm:: DefInit>(getDef ()))
344
+ if (const auto *param = dyn_cast<DefInit>(getDef ()))
344
345
if (param->getDef ()->isSubClassOf (" Constraint" ))
345
346
return Constraint (param->getDef ());
346
347
return std::nullopt;
@@ -351,8 +352,8 @@ std::optional<Constraint> AttrOrTypeParameter::getConstraint() const {
351
352
// ===----------------------------------------------------------------------===//
352
353
353
354
bool AttributeSelfTypeParameter::classof (const AttrOrTypeParameter *param) {
354
- const llvm:: Init *paramDef = param->getDef ();
355
- if (auto *paramDefInit = dyn_cast<llvm:: DefInit>(paramDef))
355
+ const Init *paramDef = param->getDef ();
356
+ if (const auto *paramDefInit = dyn_cast<DefInit>(paramDef))
356
357
return paramDefInit->getDef ()->isSubClassOf (" AttributeSelfTypeParameter" );
357
358
return false ;
358
359
}
0 commit comments