1717
1818using namespace mlir ;
1919using 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;
2026
2127// ===----------------------------------------------------------------------===//
2228// AttrOrTypeBuilder
@@ -35,14 +41,13 @@ bool AttrOrTypeBuilder::hasInferredContextParameter() const {
3541// AttrOrTypeDef
3642// ===----------------------------------------------------------------------===//
3743
38- AttrOrTypeDef::AttrOrTypeDef (const llvm:: Record *def) : def(def) {
44+ AttrOrTypeDef::AttrOrTypeDef (const Record *def) : def(def) {
3945 // 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" ));
4248 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 ());
4651
4752 // Ensure that all parameters have names.
4853 for (const AttrOrTypeBuilder::Parameter ¶m :
@@ -56,16 +61,16 @@ AttrOrTypeDef::AttrOrTypeDef(const llvm::Record *def) : def(def) {
5661
5762 // Populate the traits.
5863 if (auto *traitList = def->getValueAsListInit (" traits" )) {
59- SmallPtrSet<const llvm:: Init *, 32 > traitSet;
64+ SmallPtrSet<const Init *, 32 > traitSet;
6065 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) {
6368 for (auto *traitInit : *traitList) {
6469 if (!traitSet.insert (traitInit).second )
6570 continue ;
6671
6772 // 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 ();
6974 if (traitDef->isSubClassOf (" Interface" )) {
7075 if (auto *bases = traitDef->getValueAsListInit (" baseInterfaces" ))
7176 processTraitList (bases);
@@ -111,7 +116,7 @@ AttrOrTypeDef::AttrOrTypeDef(const llvm::Record *def) : def(def) {
111116}
112117
113118Dialect 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 ());
115120 return Dialect (dialect ? dialect->getDef () : nullptr );
116121}
117122
@@ -126,17 +131,17 @@ StringRef AttrOrTypeDef::getCppBaseClassName() const {
126131}
127132
128133bool 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 ());
131136}
132137
133138StringRef AttrOrTypeDef::getDescription () const {
134139 return def->getValueAsString (" description" );
135140}
136141
137142bool 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 ());
140145}
141146
142147StringRef AttrOrTypeDef::getSummary () const {
@@ -249,9 +254,9 @@ StringRef TypeDef::getTypeName() const {
249254template <typename InitT>
250255auto AttrOrTypeParameter::getDefValue (StringRef name) const {
251256 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 ()))
255260 result = value->getValue ();
256261 return result;
257262}
@@ -270,20 +275,20 @@ std::string AttrOrTypeParameter::getAccessorName() const {
270275}
271276
272277std::optional<StringRef> AttrOrTypeParameter::getAllocator () const {
273- return getDefValue<llvm:: StringInit>(" allocator" );
278+ return getDefValue<StringInit>(" allocator" );
274279}
275280
276281StringRef AttrOrTypeParameter::getComparator () const {
277- return getDefValue<llvm:: StringInit>(" comparator" ).value_or (" $_lhs == $_rhs" );
282+ return getDefValue<StringInit>(" comparator" ).value_or (" $_lhs == $_rhs" );
278283}
279284
280285StringRef AttrOrTypeParameter::getCppType () const {
281- if (auto *stringType = dyn_cast<llvm:: StringInit>(getDef ()))
286+ if (auto *stringType = dyn_cast<StringInit>(getDef ()))
282287 return stringType->getValue ();
283- auto cppType = getDefValue<llvm:: StringInit>(" cppType" );
288+ auto cppType = getDefValue<StringInit>(" cppType" );
284289 if (cppType)
285290 return *cppType;
286- if (auto *init = dyn_cast<llvm:: DefInit>(getDef ()))
291+ if (const auto *init = dyn_cast<DefInit>(getDef ()))
287292 llvm::PrintFatalError (
288293 init->getDef ()->getLoc (),
289294 Twine (" Missing `cppType` field in Attribute/Type parameter: " ) +
@@ -295,52 +300,48 @@ StringRef AttrOrTypeParameter::getCppType() const {
295300}
296301
297302StringRef AttrOrTypeParameter::getCppAccessorType () const {
298- return getDefValue<llvm::StringInit>(" cppAccessorType" )
299- .value_or (getCppType ());
303+ return getDefValue<StringInit>(" cppAccessorType" ).value_or (getCppType ());
300304}
301305
302306StringRef AttrOrTypeParameter::getCppStorageType () const {
303- return getDefValue<llvm:: StringInit>(" cppStorageType" ).value_or (getCppType ());
307+ return getDefValue<StringInit>(" cppStorageType" ).value_or (getCppType ());
304308}
305309
306310StringRef AttrOrTypeParameter::getConvertFromStorage () const {
307- return getDefValue<llvm:: StringInit>(" convertFromStorage" ).value_or (" $_self" );
311+ return getDefValue<StringInit>(" convertFromStorage" ).value_or (" $_self" );
308312}
309313
310314std::optional<StringRef> AttrOrTypeParameter::getParser () const {
311- return getDefValue<llvm:: StringInit>(" parser" );
315+ return getDefValue<StringInit>(" parser" );
312316}
313317
314318std::optional<StringRef> AttrOrTypeParameter::getPrinter () const {
315- return getDefValue<llvm:: StringInit>(" printer" );
319+ return getDefValue<StringInit>(" printer" );
316320}
317321
318322std::optional<StringRef> AttrOrTypeParameter::getSummary () const {
319- return getDefValue<llvm:: StringInit>(" summary" );
323+ return getDefValue<StringInit>(" summary" );
320324}
321325
322326StringRef AttrOrTypeParameter::getSyntax () const {
323- if (auto *stringType = dyn_cast<llvm:: StringInit>(getDef ()))
327+ if (auto *stringType = dyn_cast<StringInit>(getDef ()))
324328 return stringType->getValue ();
325- return getDefValue<llvm:: StringInit>(" syntax" ).value_or (getCppType ());
329+ return getDefValue<StringInit>(" syntax" ).value_or (getCppType ());
326330}
327331
328332bool AttrOrTypeParameter::isOptional () const {
329333 return getDefaultValue ().has_value ();
330334}
331335
332336std::optional<StringRef> AttrOrTypeParameter::getDefaultValue () const {
333- std::optional<StringRef> result =
334- getDefValue<llvm::StringInit>(" defaultValue" );
337+ std::optional<StringRef> result = getDefValue<StringInit>(" defaultValue" );
335338 return result && !result->empty () ? result : std::nullopt ;
336339}
337340
338- const llvm::Init *AttrOrTypeParameter::getDef () const {
339- return def->getArg (index);
340- }
341+ const Init *AttrOrTypeParameter::getDef () const { return def->getArg (index); }
341342
342343std::optional<Constraint> AttrOrTypeParameter::getConstraint () const {
343- if (auto *param = dyn_cast<llvm:: DefInit>(getDef ()))
344+ if (const auto *param = dyn_cast<DefInit>(getDef ()))
344345 if (param->getDef ()->isSubClassOf (" Constraint" ))
345346 return Constraint (param->getDef ());
346347 return std::nullopt ;
@@ -351,8 +352,8 @@ std::optional<Constraint> AttrOrTypeParameter::getConstraint() const {
351352// ===----------------------------------------------------------------------===//
352353
353354bool 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))
356357 return paramDefInit->getDef ()->isSubClassOf (" AttributeSelfTypeParameter" );
357358 return false ;
358359}
0 commit comments