[Mlir-commits] [mlir] d46a135 - [mlir] Update cast/isa method calls to function calls

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


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

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

LOG: [mlir] Update cast/isa method calls to function calls

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

Added: 
    

Modified: 
    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

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td b/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td
index 281f00981bda3..6f83c053bdd5c 100644
--- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td
+++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td
@@ -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<

diff  --git a/mlir/include/mlir/IR/BuiltinAttributes.td b/mlir/include/mlir/IR/BuiltinAttributes.td
index 3273485d729f1..075eee456a7b5 100644
--- a/mlir/include/mlir/IR/BuiltinAttributes.td
+++ b/mlir/include/mlir/IR/BuiltinAttributes.td
@@ -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:

diff  --git a/mlir/include/mlir/IR/EnumAttr.td b/mlir/include/mlir/IR/EnumAttr.td
index 64a2ea13b557f..485c5266f3cfd 100644
--- a/mlir/include/mlir/IR/EnumAttr.td
+++ b/mlir/include/mlir/IR/EnumAttr.td
@@ -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,

diff  --git a/mlir/include/mlir/IR/FunctionInterfaces.td b/mlir/include/mlir/IR/FunctionInterfaces.td
index 17bbdcccaed29..48145e5d33d3b 100644
--- a/mlir/include/mlir/IR/FunctionInterfaces.td
+++ b/mlir/include/mlir/IR/FunctionInterfaces.td
@@ -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'.

diff  --git a/mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp b/mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp
index a4f20c610500c..2bc1e36855f1f 100644
--- a/mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp
+++ b/mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp
@@ -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

diff  --git a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
index cbf615a3972b7..fc2e17a209705 100644
--- a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
+++ b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
@@ -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");
       }

diff  --git a/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp b/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
index a70749e89a887..e95e6282049b1 100644
--- a/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
+++ b/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
@@ -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)                                    \

diff  --git a/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp b/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
index d2c732c778f10..69bce5209b871 100644
--- a/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
+++ b/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
@@ -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);                       \

diff  --git a/mlir/lib/Dialect/Tosa/Utils/QuantUtils.cpp b/mlir/lib/Dialect/Tosa/Utils/QuantUtils.cpp
index a164135aa0649..eb81446caacab 100644
--- a/mlir/lib/Dialect/Tosa/Utils/QuantUtils.cpp
+++ b/mlir/lib/Dialect/Tosa/Utils/QuantUtils.cpp
@@ -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:

diff  --git a/mlir/test/python/python_test_ops.td b/mlir/test/python/python_test_ops.td
index 1be8415733ffb..21bb95dd82783 100644
--- a/mlir/test/python/python_test_ops.td
+++ b/mlir/test/python/python_test_ops.td
@@ -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());


        


More information about the Mlir-commits mailing list