[mlir] Update cast/isa method calls to function calls
authorTres Popp <tpopp@google.com>
Thu, 25 May 2023 14:35:45 +0000 (16:35 +0200)
committerTres Popp <tpopp@google.com>
Fri, 26 May 2023 05:47:03 +0000 (07:47 +0200)
This updates the rest (at implementation) of MLIR's use of cast/isa
method calls where function calls are possible and automatic refactoring
is not. These changes occured in .td files or in macros.

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

mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td
mlir/include/mlir/IR/BuiltinAttributes.td
mlir/include/mlir/IR/EnumAttr.td
mlir/include/mlir/IR/FunctionInterfaces.td
mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp
mlir/lib/Dialect/EmitC/IR/EmitC.cpp
mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
mlir/lib/Dialect/Tosa/Utils/QuantUtils.cpp
mlir/test/python/python_test_ops.td

index 281f009..6f83c05 100644 (file)
@@ -158,7 +158,7 @@ def OffloadModuleInterface : OpInterface<"OffloadModuleInterface"> {
       /*methodName=*/"getFlags",
       (ins), [{}], [{
         if (Attribute flags = $_op->getAttr("omp.flags"))
-          return flags.dyn_cast_or_null<mlir::omp::FlagsAttr>();
+          return ::llvm::dyn_cast_or_null<mlir::omp::FlagsAttr>(flags);
         return nullptr;
       }]>,
       InterfaceMethod<
@@ -188,7 +188,7 @@ def OffloadModuleInterface : OpInterface<"OffloadModuleInterface"> {
       /*methodName=*/"getTarget",
       (ins), [{}], [{
         if (Attribute flags = $_op->getAttr("omp.target"))
-          return flags.dyn_cast_or_null<mlir::omp::TargetAttr>();
+          return ::llvm::dyn_cast_or_null<mlir::omp::TargetAttr>(flags);
         return nullptr;
       }]>,
     InterfaceMethod<
index 3273485..075eee4 100644 (file)
@@ -562,8 +562,8 @@ def Builtin_DictionaryAttr : Builtin_Attr<"Dictionary"> {
     /// `AttrClass`, null otherwise.
     template<typename AttrClass, typename NameClass>
     AttrClass getAs(NameClass &&name) const {
-      return get(std::forward<NameClass>(name))
-        .template dyn_cast_or_null<AttrClass>();
+      return llvm::dyn_cast_or_null<AttrClass>(
+               get(std::forward<NameClass>(name)));
     }
 
   private:
index 64a2ea1..485c526 100644 (file)
@@ -168,7 +168,7 @@ class EnumAttrInfo<
 
   // Override Attr class fields for specialized class
   let predicate = !if(genSpecializedAttr,
-    CPred<"$_self.isa<" # cppNamespace # "::" # specializedAttrClassName # ">()">,
+    CPred<"::llvm::isa<" # cppNamespace # "::" # specializedAttrClassName # ">($_self)">,
     baseAttrClass.predicate);
   let storageType = !if(genSpecializedAttr,
     cppNamespace # "::" # specializedAttrClassName,
index 17bbdcc..48145e5 100644 (file)
@@ -445,11 +445,11 @@ def FunctionOpInterface : OpInterface<"FunctionOpInterface", [Symbol]> {
 
     template <typename AttrClass>
     AttrClass getArgAttrOfType(unsigned index, StringAttr name) {
-      return getArgAttr(index, name).template dyn_cast_or_null<AttrClass>();
+      return ::llvm::dyn_cast_or_null<AttrClass>(getArgAttr(index, name));
     }
     template <typename AttrClass>
     AttrClass getArgAttrOfType(unsigned index, StringRef name) {
-      return getArgAttr(index, name).template dyn_cast_or_null<AttrClass>();
+      return ::llvm::dyn_cast_or_null<AttrClass>(getArgAttr(index, name));
     }
 
     /// Set the attributes held by the argument at 'index'.
@@ -534,11 +534,11 @@ def FunctionOpInterface : OpInterface<"FunctionOpInterface", [Symbol]> {
 
     template <typename AttrClass>
     AttrClass getResultAttrOfType(unsigned index, StringAttr name) {
-      return getResultAttr(index, name).template dyn_cast_or_null<AttrClass>();
+      return ::llvm::dyn_cast_or_null<AttrClass>(getResultAttr(index, name));
     }
     template <typename AttrClass>
     AttrClass getResultAttrOfType(unsigned index, StringRef name) {
-      return getResultAttr(index, name).template dyn_cast_or_null<AttrClass>();
+      return ::llvm::dyn_cast_or_null<AttrClass>(getResultAttr(index, name));
     }
 
     /// Set the attributes held by the result at 'index'.
index a4f20c6..2bc1e36 100644 (file)
@@ -350,10 +350,10 @@ struct VectorReductionPattern final
 
 #define INT_AND_FLOAT_CASE(kind, iop, fop)                                     \
   case vector::CombiningKind::kind:                                            \
-    if (resultType.isa<IntegerType>()) {                                       \
+    if (llvm::isa<IntegerType>(resultType)) {                                  \
       result = rewriter.create<spirv::iop>(loc, resultType, result, next);     \
     } else {                                                                   \
-      assert(resultType.isa<FloatType>());                                     \
+      assert(llvm::isa<FloatType>(resultType));                                \
       result = rewriter.create<spirv::fop>(loc, resultType, result, next);     \
     }                                                                          \
     break
index cbf615a..fc2e17a 100644 (file)
@@ -100,7 +100,7 @@ LogicalResult emitc::CallOp::verify() {
 
         // Args with elements of type ArrayAttr must have a type.
       } else if (llvm::isa<ArrayAttr>(
-                     arg) /*&& arg.getType().isa<NoneType>()*/) {
+                     arg) /*&& llvm::isa<NoneType>(arg.getType())*/) {
         // FIXME: Array attributes never have types
         return emitOpError("array argument has no type");
       }
index a70749e..e95e628 100644 (file)
@@ -826,7 +826,7 @@ OpFoldResult ConstOp::fold(FoldAdaptor adaptor) { return getValueAttr(); }
 
 #define REDUCE_FOLDER(OP)                                                      \
   OpFoldResult OP::fold(FoldAdaptor adaptor) {                                 \
-    ShapedType inputTy = getInput().getType().cast<ShapedType>();              \
+    ShapedType inputTy = llvm::cast<ShapedType>(getInput().getType());         \
     if (!inputTy.hasRank())                                                    \
       return {};                                                               \
     if (inputTy.getDimSize(getAxis()) == 1)                                    \
index d2c732c..69bce52 100644 (file)
@@ -154,7 +154,7 @@ LogicalResult tosa::AvgPool2dOp::verify() {
     resultETy = quantType.getStorageType();
 
   auto accType = getAccType();
-  if (inputETy.isa<IntegerType>() && !accType.isInteger(32))
+  if (llvm::isa<IntegerType>(inputETy) && !accType.isInteger(32))
     return emitOpError("accumulator type for integer tensor is not i32");
 
   if ((inputETy.isBF16() || inputETy.isF16()) &&
@@ -984,7 +984,7 @@ static LogicalResult ReduceInferReturnTypes(
       OpaqueProperties properties, RegionRange regions,                        \
       SmallVectorImpl<ShapedTypeComponents> &inferredReturnShapes) {           \
     Type inputType =                                                           \
-        operands.getType()[0].cast<TensorType>().getElementType();             \
+        llvm::cast<TensorType>(operands.getType()[0]).getElementType();        \
     return ReduceInferReturnTypes(operands.getShape(0), inputType,             \
                                   properties.as<Properties *>()->axis,         \
                                   inferredReturnShapes);                       \
index a164135..eb81446 100644 (file)
@@ -108,9 +108,9 @@ void mlir::tosa::computeMultiplierAndShift(double scale, int32_t &multiplier,
 }
 
 #define GET_UQTYPE(input_type)                                                 \
-  ((input_type).getElementType().dyn_cast<quant::UniformQuantizedType>())
+  (llvm::dyn_cast<quant::UniformQuantizedType>((input_type).getElementType()))
 #define GET_QTYPE(input_type)                                                  \
-  ((input_type).getElementType().dyn_cast<quant::QuantizedType>())
+  (llvm::dyn_cast<quant::QuantizedType>((input_type).getElementType()))
 
 /// Method to build ConvOpQuantizationAttr, called from
 /// ConvOpQuantInfoBuilder/TransConvOpQuantInfoBuilder:
index 1be8415..21bb95d 100644 (file)
@@ -122,7 +122,7 @@ def InferShapedTypeComponentsOp : TestOp<"infer_shaped_type_components_op",
         ::mlir::ShapedTypeComponents>& inferredShapedTypeComponents) {
       $cppClass::Adaptor adaptor(operands, attributes, properties, regions);
       auto operandType =
-          adaptor.getOperand().getType().cast<::mlir::ShapedType>();
+          ::llvm::cast<::mlir::ShapedType>(adaptor.getOperand().getType());
       if (operandType.hasRank()) {
         inferredShapedTypeComponents.emplace_back(operandType.getShape(),
             operandType.getElementType());