[Mlir-commits] [mlir] 6de63b8 - [mlir] Move tblgen code generation to use functional forms of cast/isa

Tres Popp llvmlistbot at llvm.org
Thu May 25 22:47:53 PDT 2023


Author: Tres Popp
Date: 2023-05-26T07:47:03+02:00
New Revision: 6de63b82cc1d1a98151aa19fa8f65bd6888789b1

URL: https://github.com/llvm/llvm-project/commit/6de63b82cc1d1a98151aa19fa8f65bd6888789b1
DIFF: https://github.com/llvm/llvm-project/commit/6de63b82cc1d1a98151aa19fa8f65bd6888789b1.diff

LOG: [mlir] Move tblgen code generation to use functional forms of cast/isa

Summary:
The method forms are deprecated. This updates the rest of the tblgen
uses of methods where a function call is available.

Context:
- https://mlir.llvm.org/deprecation/ at "Use the free function variants for dyn_cast/cast/isa/…"
- Original discussion at https://discourse.llvm.org/t/preferred-casting-style-going-forward/68443

Reviewers: rriddle

Added: 
    

Modified: 
    mlir/test/mlir-linalg-ods-gen/test-linalg-ods-yaml-gen.yaml
    mlir/test/mlir-tblgen/attr-or-type-format.td
    mlir/test/mlir-tblgen/op-attribute.td
    mlir/test/mlir-tblgen/op-result.td
    mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-yaml-gen.cpp
    mlir/tools/mlir-tblgen/AttrOrTypeFormatGen.cpp
    mlir/tools/mlir-tblgen/EnumsGen.cpp
    mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
    mlir/tools/mlir-tblgen/OpFormatGen.cpp
    mlir/tools/mlir-tblgen/OpInterfacesGen.cpp
    mlir/tools/mlir-tblgen/SPIRVUtilsGen.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/test/mlir-linalg-ods-gen/test-linalg-ods-yaml-gen.yaml b/mlir/test/mlir-linalg-ods-gen/test-linalg-ods-yaml-gen.yaml
index de15df55c2bcf..5d7048d5d52bd 100644
--- a/mlir/test/mlir-linalg-ods-gen/test-linalg-ods-yaml-gen.yaml
+++ b/mlir/test/mlir-linalg-ods-gen/test-linalg-ods-yaml-gen.yaml
@@ -91,7 +91,7 @@ structured_op: !LinalgStructuredOpConfig
 #  IMPL-NEXT:  auto castIter = llvm::find_if(attrs, [&](const NamedAttribute &attr) {
 #  IMPL-NEXT:                                return attr.getName() == "cast"; });
 #  IMPL-NEXT:  if (castIter != attrs.end()) {
-#  IMPL-NEXT:    if (auto attr = castIter->getValue().dyn_cast<TypeFnAttr>())
+#  IMPL-NEXT:    if (auto attr = llvm::dyn_cast<TypeFnAttr>(castIter->getValue()))
 #  IMPL-NEXT:      castVal = attr.getValue();
 #  IMPL-NEXT:  }
 

diff  --git a/mlir/test/mlir-tblgen/attr-or-type-format.td b/mlir/test/mlir-tblgen/attr-or-type-format.td
index 8ab622e6087ab..9017a639f268c 100644
--- a/mlir/test/mlir-tblgen/attr-or-type-format.td
+++ b/mlir/test/mlir-tblgen/attr-or-type-format.td
@@ -167,7 +167,7 @@ def AttrC : TestAttr<"TestF"> {
 
 // ATTR-LABEL: Attribute TestGAttr::parse
 // ATTR: if (odsType)
-// ATTR:   if (auto reqType = odsType.dyn_cast<::mlir::Type>())
+// ATTR:   if (auto reqType = ::llvm::dyn_cast<::mlir::Type>(odsType))
 // ATTR:     _result_type = reqType
 // ATTR: TestGAttr::get
 // ATTR-NEXT: *_result_a

diff  --git a/mlir/test/mlir-tblgen/op-attribute.td b/mlir/test/mlir-tblgen/op-attribute.td
index d39dc3e4841e9..cc7c1cd1abd42 100644
--- a/mlir/test/mlir-tblgen/op-attribute.td
+++ b/mlir/test/mlir-tblgen/op-attribute.td
@@ -97,25 +97,25 @@ def AOp : NS_Op<"a_op", []> {
 // ---
 
 // DEF:      some-attr-kind AOp::getAAttrAttr()
-// DEF-NEXT:   ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getAAttrAttrName()).cast<some-attr-kind>()
+// DEF-NEXT:   ::llvm::cast<some-attr-kind>(::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getAAttrAttrName()))
 // DEF:      some-return-type AOp::getAAttr() {
 // DEF-NEXT:   auto attr = getAAttrAttr()
 // DEF-NEXT:   return attr.some-convert-from-storage();
 
 // DEF:      some-attr-kind AOp::getBAttrAttr()
-// DEF-NEXT:   ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 0, getBAttrAttrName()).dyn_cast_or_null<some-attr-kind>()
+// DEF-NEXT:   ::llvm::dyn_cast_or_null<some-attr-kind>(::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 0, getBAttrAttrName()))
 // DEF:      some-return-type AOp::getBAttr() {
 // DEF-NEXT:   auto attr = getBAttrAttr();
 // DEF-NEXT:   return attr.some-convert-from-storage();
 
 // DEF:      some-attr-kind AOp::getCAttrAttr()
-// DEF-NEXT:   ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 0, getCAttrAttrName()).dyn_cast_or_null<some-attr-kind>()
+// DEF-NEXT:   ::llvm::dyn_cast_or_null<some-attr-kind>(::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 0, getCAttrAttrName()))
 // DEF:      ::std::optional<some-return-type> AOp::getCAttr() {
 // DEF-NEXT:   auto attr = getCAttrAttr()
 // DEF-NEXT:   return attr ? ::std::optional<some-return-type>(attr.some-convert-from-storage()) : (::std::nullopt);
 
 // DEF:      some-attr-kind AOp::getDAttrAttr()
-// DEF-NEXT:   ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 0, getDAttrAttrName()).dyn_cast_or_null<some-attr-kind>()
+// DEF-NEXT:   ::llvm::dyn_cast_or_null<some-attr-kind>(::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 0, getDAttrAttrName()))
 // DEF:      some-return-type AOp::getDAttr() {
 // DEF-NEXT:   auto attr = getDAttrAttr();
 // DEF-NEXT:   if (!attr)
@@ -232,13 +232,13 @@ def AgetOp : Op<Test2_Dialect, "a_get_op", []> {
 // ---
 
 // DEF:      some-attr-kind AgetOp::getAAttrAttr()
-// DEF-NEXT:   ::mlir::impl::getAttrFromSortedRange({{.*}}).cast<some-attr-kind>()
+// DEF-NEXT:   ::llvm::cast<some-attr-kind>(::mlir::impl::getAttrFromSortedRange({{.*}}))
 // DEF:      some-return-type AgetOp::getAAttr() {
 // DEF-NEXT:   auto attr = getAAttrAttr()
 // DEF-NEXT:   return attr.some-convert-from-storage();
 
 // DEF:      some-attr-kind AgetOp::getBAttrAttr()
-// DEF-NEXT:   return ::mlir::impl::getAttrFromSortedRange({{.*}}).dyn_cast_or_null<some-attr-kind>()
+// DEF-NEXT:   return ::llvm::dyn_cast_or_null<some-attr-kind>(::mlir::impl::getAttrFromSortedRange({{.*}}))
 // DEF:      some-return-type AgetOp::getBAttr() {
 // DEF-NEXT:   auto attr = getBAttrAttr();
 // DEF-NEXT:   if (!attr)
@@ -246,7 +246,7 @@ def AgetOp : Op<Test2_Dialect, "a_get_op", []> {
 // DEF-NEXT:   return attr.some-convert-from-storage();
 
 // DEF:      some-attr-kind AgetOp::getCAttrAttr()
-// DEF-NEXT:   return ::mlir::impl::getAttrFromSortedRange({{.*}}).dyn_cast_or_null<some-attr-kind>()
+// DEF-NEXT:   return ::llvm::dyn_cast_or_null<some-attr-kind>(::mlir::impl::getAttrFromSortedRange({{.*}}))
 // DEF:      ::std::optional<some-return-type> AgetOp::getCAttr() {
 // DEF-NEXT:   auto attr = getCAttrAttr()
 // DEF-NEXT:   return attr ? ::std::optional<some-return-type>(attr.some-convert-from-storage()) : (::std::nullopt);

diff  --git a/mlir/test/mlir-tblgen/op-result.td b/mlir/test/mlir-tblgen/op-result.td
index 606d4c250d88b..89cddc1b880e6 100644
--- a/mlir/test/mlir-tblgen/op-result.td
+++ b/mlir/test/mlir-tblgen/op-result.td
@@ -56,7 +56,7 @@ def OpD : NS_Op<"type_attr_as_result_type", [FirstAttrDerivedResultType]> {
 
 // CHECK-LABEL: OpD definitions
 // CHECK: void OpD::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes)
-// CHECK: odsState.addTypes({attr.getValue().cast<::mlir::TypeAttr>().getValue()});
+// CHECK: odsState.addTypes({::llvm::cast<::mlir::TypeAttr>(attr.getValue()).getValue()});
 
 def OpE : NS_Op<"value_attr_as_result_type", [FirstAttrDerivedResultType]> {
   let arguments = (ins I32:$x, F32Attr:$attr);
@@ -65,7 +65,7 @@ def OpE : NS_Op<"value_attr_as_result_type", [FirstAttrDerivedResultType]> {
 
 // CHECK-LABEL: OpE definitions
 // CHECK: void OpE::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes)
-// CHECK: odsState.addTypes({attr.getValue().cast<::mlir::TypedAttr>().getType()});
+// CHECK: odsState.addTypes({::llvm::cast<::mlir::TypedAttr>(attr.getValue()).getType()});
 
 def OpF : NS_Op<"one_variadic_result_op", []> {
   let results = (outs Variadic<I32>:$x);

diff  --git a/mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-yaml-gen.cpp b/mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-yaml-gen.cpp
index 35f901519920e..aeda1b8ba0258 100644
--- a/mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-yaml-gen.cpp
+++ b/mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-yaml-gen.cpp
@@ -378,7 +378,7 @@ static std::string generateCppExpression(SerializedAffineMap self,
   printedSs.flush();
 
   static const char exprFormat[] =
-      R"FMT(mlir::parseAttribute("{0}", {1}).cast<AffineMapAttr>().getValue())FMT";
+      R"FMT(llvm::cast<AffineMapAttr>(mlir::parseAttribute("{0}", {1})).getValue())FMT";
   return llvm::formatv(exprFormat, printedStr, contextName);
 }
 
@@ -1035,7 +1035,7 @@ void {0}::regionBuilder(ImplicitLocOpBuilder &b,
 auto {1}Iter = llvm::find_if(attrs, [&](const NamedAttribute &attr) {{
                               return attr.getName() == "{1}"; });
 if ({1}Iter != attrs.end()) {{
-  if (auto attr = {1}Iter->getValue().dyn_cast<{0}Attr>())
+  if (auto attr = llvm::dyn_cast<{0}Attr>({1}Iter->getValue()))
     {1}Val = attr.getValue();
 }
 )FMT";

diff  --git a/mlir/tools/mlir-tblgen/AttrOrTypeFormatGen.cpp b/mlir/tools/mlir-tblgen/AttrOrTypeFormatGen.cpp
index 4e248e2de57f1..f14be81467d85 100644
--- a/mlir/tools/mlir-tblgen/AttrOrTypeFormatGen.cpp
+++ b/mlir/tools/mlir-tblgen/AttrOrTypeFormatGen.cpp
@@ -259,7 +259,7 @@ static void genAttrSelfTypeParser(MethodBody &os, const FmtContext &ctx,
   // $1: The self type parameter name.
   const char *const selfTypeParser = R"(
 if ($_type) {
-  if (auto reqType = $_type.dyn_cast<$0>()) {
+  if (auto reqType = ::llvm::dyn_cast<$0>($_type)) {
     _result_$1 = reqType;
   } else {
     $_parser.emitError($_loc, "invalid kind of type specified");

diff  --git a/mlir/tools/mlir-tblgen/EnumsGen.cpp b/mlir/tools/mlir-tblgen/EnumsGen.cpp
index 6d325d4461a3e..65fa63636face 100644
--- a/mlir/tools/mlir-tblgen/EnumsGen.cpp
+++ b/mlir/tools/mlir-tblgen/EnumsGen.cpp
@@ -516,7 +516,7 @@ static void emitSpecializedAttrDef(const Record &enumDef, raw_ostream &os) {
   os << formatv("  ::mlir::IntegerAttr baseAttr = "
                 "::mlir::IntegerAttr::get(intType, static_cast<{0}>(val));\n",
                 underlyingType);
-  os << formatv("  return baseAttr.cast<{0}>();\n", attrClassName);
+  os << formatv("  return ::llvm::cast<{0}>(baseAttr);\n", attrClassName);
 
   os << "}\n";
 

diff  --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
index c287f5254c1f7..31b7504f7b859 100644
--- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
@@ -113,13 +113,13 @@ static const char *const attrSizedSegmentValueRangeCalcCode = R"(
 /// {0}: The code to get the attribute.
 static const char *const adapterSegmentSizeAttrInitCode = R"(
   assert({0} && "missing segment size attribute for op");
-  auto sizeAttr = {0}.cast<::mlir::DenseI32ArrayAttr>();
+  auto sizeAttr = ::llvm::cast<::mlir::DenseI32ArrayAttr>({0});
 )";
 /// The code snippet to initialize the sizes for the value range calculation.
 ///
 /// {0}: The code to get the attribute.
 static const char *const opSegmentSizeAttrInitCode = R"(
-  auto sizeAttr = {0}.cast<::mlir::DenseI32ArrayAttr>();
+  auto sizeAttr = ::llvm::cast<::mlir::DenseI32ArrayAttr>({0});
 )";
 
 /// The logic to calculate the actual value range for a declared operand
@@ -649,7 +649,7 @@ static void genNativeTraitAttrVerifier(MethodBody &body,
   // {3}: Emit error prefix.
   const char *const checkAttrSizedValueSegmentsCode = R"(
   {
-    auto sizeAttr = tblgen_{0}.cast<::mlir::DenseI32ArrayAttr>();
+    auto sizeAttr = ::llvm::cast<::mlir::DenseI32ArrayAttr>(tblgen_{0});
     auto numElements = sizeAttr.asArrayRef().size();
     if (numElements != {1})
       return {3}"'{0}' attribute for specifying {2} segments must have {1} "
@@ -1118,7 +1118,7 @@ void OpEmitter::genPropertiesSupport() {
   // TODO: properties might be optional as well.
   const char *propFromAttrFmt = R"decl(;
     {{
-      auto setFromAttr = [] (auto &propStorage, ::mlir::Attribute propAttr, 
+      auto setFromAttr = [] (auto &propStorage, ::mlir::Attribute propAttr,
                              ::mlir::InFlightDiagnostic *propDiag) {{
         {0};
       };
@@ -1213,7 +1213,7 @@ void OpEmitter::genPropertiesSupport() {
   getPropMethod << R"decl(
   if (!attrs.empty())
     return odsBuilder.getDictionaryAttr(attrs);
-  return {};    
+  return {};
 )decl";
 
   // Hashing for the property
@@ -1325,7 +1325,7 @@ void OpEmitter::genAttrGetters() {
     if (!method)
       return;
     method->body() << formatv(
-        "  return {0}.{1}<{2}>();", emitHelper.getAttr(attrName),
+        "  return ::llvm::{1}<{2}>({0});", emitHelper.getAttr(attrName),
         attr.isOptional() || attr.hasDefaultValue() ? "dyn_cast_or_null"
                                                     : "cast",
         attr.getStorageType());
@@ -2274,9 +2274,9 @@ void OpEmitter::genUseAttrAsResultTypeBuilder() {
           "  for (auto attr : attributes) {\n"
           "    if (attr.getName() != attrName) continue;\n";
   if (namedAttr.attr.isTypeAttr()) {
-    resultType = "attr.getValue().cast<::mlir::TypeAttr>().getValue()";
+    resultType = "::llvm::cast<::mlir::TypeAttr>(attr.getValue()).getValue()";
   } else {
-    resultType = "attr.getValue().cast<::mlir::TypedAttr>().getType()";
+    resultType = "::llvm::cast<::mlir::TypedAttr>(attr.getValue()).getType()";
   }
 
   // Operands
@@ -2960,11 +2960,14 @@ void OpEmitter::genTypeInterfaceMethods() {
           if (op.getDialect().usePropertiesForAttributes()) {
             body << "(properties ? properties.as<Properties *>()->"
                  << attr->name
-                 << " : attributes.get(\"" + attr->name +
-                        "\").dyn_cast_or_null<::mlir::TypedAttr>());\n";
+                 << " : "
+                    "::llvm::dyn_cast_or_null<::mlir::TypedAttr>(attributes."
+                    "get(\"" +
+                        attr->name + "\")));\n";
           } else {
-            body << "attributes.get(\"" + attr->name +
-                        "\").dyn_cast_or_null<::mlir::TypedAttr>();\n";
+            body << "::llvm::dyn_cast_or_null<::mlir::TypedAttr>(attributes."
+                    "get(\"" +
+                        attr->name + "\"));\n";
           }
           body << "  if (!odsInferredTypeAttr" << inferredTypeIdx
                << ") return ::mlir::failure();\n";
@@ -3502,7 +3505,7 @@ OpOperandAdaptorEmitter::OpOperandAdaptorEmitter(
         const char *accessorFmt = R"decl(
     auto get{0}() {
       auto &propStorage = this->{1};
-      return propStorage.{2}<{3}>();
+      return ::llvm::{2}<{3}>(propStorage);
     }
     void set{0}(const {3} &propValue) {
       this->{1} = propValue;
@@ -3629,11 +3632,11 @@ OpOperandAdaptorEmitter::OpOperandAdaptorEmitter(
     if (!useProperties)
       body << "assert(odsAttrs && \"no attributes when constructing "
               "adapter\");\n";
-    body << formatv("auto attr = {0}.{1}<{2}>();\n", emitHelper.getAttr(name),
-                    attr.hasDefaultValue() || attr.isOptional()
-                        ? "dyn_cast_or_null"
-                        : "cast",
-                    attr.getStorageType());
+    body << formatv(
+        "auto attr = ::llvm::{1}<{2}>({0});\n", emitHelper.getAttr(name),
+        attr.hasDefaultValue() || attr.isOptional() ? "dyn_cast_or_null"
+                                                    : "cast",
+        attr.getStorageType());
 
     if (attr.hasDefaultValue() && attr.isOptional()) {
       // Use the default value if attribute is not set.

diff  --git a/mlir/tools/mlir-tblgen/OpFormatGen.cpp b/mlir/tools/mlir-tblgen/OpFormatGen.cpp
index e0472926078d4..9f8fa4310334f 100644
--- a/mlir/tools/mlir-tblgen/OpFormatGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpFormatGen.cpp
@@ -2283,7 +2283,8 @@ void OperationFormat::genElementPrinter(FormatElement *element,
       body << "  {\n"
            << "    auto type = " << op.getGetterName(var->name)
            << "().getType();\n"
-           << "    if (auto validType = type.dyn_cast<" << cppClass << ">())\n"
+           << "    if (auto validType = ::llvm::dyn_cast<" << cppClass
+           << ">(type))\n"
            << "      _odsPrinter.printStrippedAttrOrType(validType);\n"
            << "   else\n"
            << "     _odsPrinter << type;\n"

diff  --git a/mlir/tools/mlir-tblgen/OpInterfacesGen.cpp b/mlir/tools/mlir-tblgen/OpInterfacesGen.cpp
index b9507b377afd5..7b83a1eb69753 100644
--- a/mlir/tools/mlir-tblgen/OpInterfacesGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpInterfacesGen.cpp
@@ -124,7 +124,7 @@ struct AttrInterfaceGenerator : public InterfaceGenerator {
     interfaceBaseType = "AttributeInterface";
     valueTemplate = "ConcreteAttr";
     substVar = "_attr";
-    StringRef castCode = "(tablegen_opaque_val.cast<ConcreteAttr>())";
+    StringRef castCode = "(::llvm::cast<ConcreteAttr>(tablegen_opaque_val))";
     nonStaticMethodFmt.addSubst(substVar, castCode).withSelf(castCode);
     traitMethodFmt.addSubst(substVar,
                             "(*static_cast<const ConcreteAttr *>(this))");
@@ -155,7 +155,7 @@ struct TypeInterfaceGenerator : public InterfaceGenerator {
     interfaceBaseType = "TypeInterface";
     valueTemplate = "ConcreteType";
     substVar = "_type";
-    StringRef castCode = "(tablegen_opaque_val.cast<ConcreteType>())";
+    StringRef castCode = "(::llvm::cast<ConcreteType>(tablegen_opaque_val))";
     nonStaticMethodFmt.addSubst(substVar, castCode).withSelf(castCode);
     traitMethodFmt.addSubst(substVar,
                             "(*static_cast<const ConcreteType *>(this))");

diff  --git a/mlir/tools/mlir-tblgen/SPIRVUtilsGen.cpp b/mlir/tools/mlir-tblgen/SPIRVUtilsGen.cpp
index 7489c3134fc73..4caaf1df23334 100644
--- a/mlir/tools/mlir-tblgen/SPIRVUtilsGen.cpp
+++ b/mlir/tools/mlir-tblgen/SPIRVUtilsGen.cpp
@@ -531,7 +531,7 @@ static void emitAttributeSerialization(const Attribute &attr,
     os << tabs
        << formatv("  {0}.push_back(prepareConstantInt({1}.getLoc(), "
                   "Builder({1}).getI32IntegerAttr(static_cast<uint32_t>("
-                  "attr.cast<{2}::{3}Attr>().getValue()))));\n",
+                  "::llvm::cast<{2}::{3}Attr>(attr).getValue()))));\n",
                   operandList, opVar, baseEnum.getCppNamespace(),
                   baseEnum.getEnumClassName());
   } else if (attr.isSubClassOf("SPIRV_BitEnumAttr") ||
@@ -539,26 +539,28 @@ static void emitAttributeSerialization(const Attribute &attr,
     EnumAttr baseEnum(attr.getDef().getValueAsDef("enum"));
     os << tabs
        << formatv("  {0}.push_back(static_cast<uint32_t>("
-                  "attr.cast<{1}::{2}Attr>().getValue()));\n",
+                  "::llvm::cast<{1}::{2}Attr>(attr).getValue()));\n",
                   operandList, baseEnum.getCppNamespace(),
                   baseEnum.getEnumClassName());
   } else if (attr.getAttrDefName() == "I32ArrayAttr") {
     // Serialize all the elements of the array
-    os << tabs << "  for (auto attrElem : attr.cast<ArrayAttr>()) {\n";
+    os << tabs << "  for (auto attrElem : llvm::cast<ArrayAttr>(attr)) {\n";
     os << tabs
        << formatv("    {0}.push_back(static_cast<uint32_t>("
-                  "attrElem.cast<IntegerAttr>().getValue().getZExtValue()));\n",
+                  "llvm::cast<IntegerAttr>(attrElem).getValue().getZExtValue())"
+                  ");\n",
                   operandList);
     os << tabs << "  }\n";
   } else if (attr.getAttrDefName() == "I32Attr") {
     os << tabs
-       << formatv("  {0}.push_back(static_cast<uint32_t>("
-                  "attr.cast<IntegerAttr>().getValue().getZExtValue()));\n",
-                  operandList);
+       << formatv(
+              "  {0}.push_back(static_cast<uint32_t>("
+              "llvm::cast<IntegerAttr>(attr).getValue().getZExtValue()));\n",
+              operandList);
   } else if (attr.isEnumAttr() || attr.getAttrDefName() == "TypeAttr") {
     os << tabs
        << formatv("  {0}.push_back(static_cast<uint32_t>("
-                  "getTypeID(attr.cast<TypeAttr>().getValue())));\n",
+                  "getTypeID(llvm::cast<TypeAttr>(attr).getValue())));\n",
                   operandList);
   } else {
     PrintFatalError(


        


More information about the Mlir-commits mailing list