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 --- 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 @@ # 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()) +# IMPL-NEXT: if (auto attr = llvm::dyn_cast(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 --- a/mlir/test/mlir-tblgen/attr-or-type-format.td +++ b/mlir/test/mlir-tblgen/attr-or-type-format.td @@ -167,7 +167,7 @@ // 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 --- a/mlir/test/mlir-tblgen/op-attribute.td +++ b/mlir/test/mlir-tblgen/op-attribute.td @@ -97,25 +97,25 @@ // --- // DEF: some-attr-kind AOp::getAAttrAttr() -// DEF-NEXT: ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getAAttrAttrName()).cast() +// DEF-NEXT: ::llvm::cast(::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() +// DEF-NEXT: ::llvm::dyn_cast_or_null(::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() +// DEF-NEXT: ::llvm::dyn_cast_or_null(::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 0, getCAttrAttrName())) // DEF: ::std::optional AOp::getCAttr() { // DEF-NEXT: auto attr = getCAttrAttr() // DEF-NEXT: return attr ? ::std::optional(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() +// DEF-NEXT: ::llvm::dyn_cast_or_null(::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: some-attr-kind AgetOp::getAAttrAttr() -// DEF-NEXT: ::mlir::impl::getAttrFromSortedRange({{.*}}).cast() +// DEF-NEXT: ::llvm::cast(::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() +// DEF-NEXT: return ::llvm::dyn_cast_or_null(::mlir::impl::getAttrFromSortedRange({{.*}})) // DEF: some-return-type AgetOp::getBAttr() { // DEF-NEXT: auto attr = getBAttrAttr(); // DEF-NEXT: if (!attr) @@ -246,7 +246,7 @@ // DEF-NEXT: return attr.some-convert-from-storage(); // DEF: some-attr-kind AgetOp::getCAttrAttr() -// DEF-NEXT: return ::mlir::impl::getAttrFromSortedRange({{.*}}).dyn_cast_or_null() +// DEF-NEXT: return ::llvm::dyn_cast_or_null(::mlir::impl::getAttrFromSortedRange({{.*}})) // DEF: ::std::optional AgetOp::getCAttr() { // DEF-NEXT: auto attr = getCAttrAttr() // DEF-NEXT: return attr ? ::std::optional(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 --- a/mlir/test/mlir-tblgen/op-result.td +++ b/mlir/test/mlir-tblgen/op-result.td @@ -56,7 +56,7 @@ // 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 @@ // 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:$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 --- 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 @@ printedSs.flush(); static const char exprFormat[] = - R"FMT(mlir::parseAttribute("{0}", {1}).cast().getValue())FMT"; + R"FMT(llvm::cast(mlir::parseAttribute("{0}", {1})).getValue())FMT"; return llvm::formatv(exprFormat, printedStr, contextName); } @@ -1035,7 +1035,7 @@ 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 --- a/mlir/tools/mlir-tblgen/AttrOrTypeFormatGen.cpp +++ b/mlir/tools/mlir-tblgen/AttrOrTypeFormatGen.cpp @@ -259,7 +259,7 @@ // $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 --- a/mlir/tools/mlir-tblgen/EnumsGen.cpp +++ b/mlir/tools/mlir-tblgen/EnumsGen.cpp @@ -516,7 +516,7 @@ 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 --- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp +++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp @@ -113,13 +113,13 @@ /// {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 @@ // {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 @@ // 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 @@ getPropMethod << R"decl( if (!attrs.empty()) return odsBuilder.getDictionaryAttr(attrs); - return {}; + return {}; )decl"; // Hashing for the property @@ -1325,7 +1325,7 @@ 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 @@ " 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 @@ if (op.getDialect().usePropertiesForAttributes()) { body << "(properties ? properties.as()->" << 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"; @@ -3496,7 +3499,7 @@ 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; @@ -3616,11 +3619,11 @@ 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 --- a/mlir/tools/mlir-tblgen/OpFormatGen.cpp +++ b/mlir/tools/mlir-tblgen/OpFormatGen.cpp @@ -2283,7 +2283,8 @@ 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 --- a/mlir/tools/mlir-tblgen/OpInterfacesGen.cpp +++ b/mlir/tools/mlir-tblgen/OpInterfacesGen.cpp @@ -124,7 +124,7 @@ interfaceBaseType = "AttributeInterface"; valueTemplate = "ConcreteAttr"; substVar = "_attr"; - StringRef castCode = "(tablegen_opaque_val.cast())"; + StringRef castCode = "(::llvm::cast(tablegen_opaque_val))"; nonStaticMethodFmt.addSubst(substVar, castCode).withSelf(castCode); traitMethodFmt.addSubst(substVar, "(*static_cast(this))"); @@ -155,7 +155,7 @@ interfaceBaseType = "TypeInterface"; valueTemplate = "ConcreteType"; substVar = "_type"; - StringRef castCode = "(tablegen_opaque_val.cast())"; + StringRef castCode = "(::llvm::cast(tablegen_opaque_val))"; nonStaticMethodFmt.addSubst(substVar, castCode).withSelf(castCode); traitMethodFmt.addSubst(substVar, "(*static_cast(this))"); diff --git a/mlir/tools/mlir-tblgen/SPIRVUtilsGen.cpp b/mlir/tools/mlir-tblgen/SPIRVUtilsGen.cpp --- a/mlir/tools/mlir-tblgen/SPIRVUtilsGen.cpp +++ b/mlir/tools/mlir-tblgen/SPIRVUtilsGen.cpp @@ -531,7 +531,7 @@ os << tabs << formatv(" {0}.push_back(prepareConstantInt({1}.getLoc(), " "Builder({1}).getI32IntegerAttr(static_cast(" - "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 @@ EnumAttr baseEnum(attr.getDef().getValueAsDef("enum")); os << tabs << formatv(" {0}.push_back(static_cast(" - "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()) {\n"; + os << tabs << " for (auto attrElem : llvm::cast(attr)) {\n"; os << tabs << formatv(" {0}.push_back(static_cast(" - "attrElem.cast().getValue().getZExtValue()));\n", + "llvm::cast(attrElem).getValue().getZExtValue())" + ");\n", operandList); os << tabs << " }\n"; } else if (attr.getAttrDefName() == "I32Attr") { os << tabs - << formatv(" {0}.push_back(static_cast(" - "attr.cast().getValue().getZExtValue()));\n", - operandList); + << formatv( + " {0}.push_back(static_cast(" + "llvm::cast(attr).getValue().getZExtValue()));\n", + operandList); } else if (attr.isEnumAttr() || attr.getAttrDefName() == "TypeAttr") { os << tabs << formatv(" {0}.push_back(static_cast(" - "getTypeID(attr.cast().getValue())));\n", + "getTypeID(llvm::cast(attr).getValue())));\n", operandList); } else { PrintFatalError(