[Mlir-commits] [mlir] [mlir] Remove deprecated cast member functions (PR #135556)
Jakub Kuderski
llvmlistbot at llvm.org
Sun Apr 13 11:41:37 PDT 2025
https://github.com/kuhar created https://github.com/llvm/llvm-project/pull/135556
These have been deprecated for over two years now in favor of free functions.
See the relevant discourse thread:
https://discourse.llvm.org/t/preferred-casting-style-going-forward/68443 and the deprecation notice: https://mlir.llvm.org/deprecation/.
>From f174d3e6c763d60feecd604a2f03183a29fd9d71 Mon Sep 17 00:00:00 2001
From: Jakub Kuderski <jakub at nod-labs.com>
Date: Sun, 13 Apr 2025 14:38:48 -0400
Subject: [PATCH] [mlir] Remove deprecated cast member functions
These have been deprecated for over two years now in favor of free
functions.
See the relevant discourse thread:
https://discourse.llvm.org/t/preferred-casting-style-going-forward/68443
and the deprecation notice: https://mlir.llvm.org/deprecation/.
---
mlir/include/mlir/IR/AffineExpr.h | 37 --------------------
mlir/include/mlir/IR/Attributes.h | 43 ------------------------
mlir/include/mlir/IR/Location.h | 17 ----------
mlir/include/mlir/IR/Types.h | 41 ----------------------
mlir/include/mlir/IR/Value.h | 24 -------------
mlir/include/mlir/Tools/PDLL/AST/Types.h | 29 ----------------
6 files changed, 191 deletions(-)
diff --git a/mlir/include/mlir/IR/AffineExpr.h b/mlir/include/mlir/IR/AffineExpr.h
index a93e74b449cee..94eacdb4735f8 100644
--- a/mlir/include/mlir/IR/AffineExpr.h
+++ b/mlir/include/mlir/IR/AffineExpr.h
@@ -81,19 +81,6 @@ class AffineExpr {
bool operator!() const { return expr == nullptr; }
- template <typename U>
- [[deprecated("Use llvm::isa<U>() instead")]] constexpr bool isa() const;
-
- template <typename U>
- [[deprecated("Use llvm::dyn_cast<U>() instead")]] U dyn_cast() const;
-
- template <typename U>
- [[deprecated("Use llvm::dyn_cast_or_null<U>() instead")]] U
- dyn_cast_or_null() const;
-
- template <typename U>
- [[deprecated("Use llvm::cast<U>() instead")]] U cast() const;
-
MLIRContext *getContext() const;
/// Return the classification for this type.
@@ -288,30 +275,6 @@ AffineExpr getAffineExprFromFlatForm(ArrayRef<int64_t> flatExprs,
raw_ostream &operator<<(raw_ostream &os, AffineExpr expr);
-template <typename U>
-constexpr bool AffineExpr::isa() const {
- if constexpr (std::is_same_v<U, AffineBinaryOpExpr>)
- return getKind() <= AffineExprKind::LAST_AFFINE_BINARY_OP;
- if constexpr (std::is_same_v<U, AffineDimExpr>)
- return getKind() == AffineExprKind::DimId;
- if constexpr (std::is_same_v<U, AffineSymbolExpr>)
- return getKind() == AffineExprKind::SymbolId;
- if constexpr (std::is_same_v<U, AffineConstantExpr>)
- return getKind() == AffineExprKind::Constant;
-}
-template <typename U>
-U AffineExpr::dyn_cast() const {
- return llvm::dyn_cast<U>(*this);
-}
-template <typename U>
-U AffineExpr::dyn_cast_or_null() const {
- return llvm::dyn_cast_or_null<U>(*this);
-}
-template <typename U>
-U AffineExpr::cast() const {
- return llvm::cast<U>(*this);
-}
-
/// Simplify an affine expression by flattening and some amount of simple
/// analysis. This has complexity linear in the number of nodes in 'expr'.
/// Returns the simplified expression, which is the same as the input expression
diff --git a/mlir/include/mlir/IR/Attributes.h b/mlir/include/mlir/IR/Attributes.h
index 262d31b20ab08..6eef0e3f79bae 100644
--- a/mlir/include/mlir/IR/Attributes.h
+++ b/mlir/include/mlir/IR/Attributes.h
@@ -47,24 +47,6 @@ class Attribute {
bool operator!() const { return impl == nullptr; }
- /// Casting utility functions. These are deprecated and will be removed,
- /// please prefer using the `llvm` namespace variants instead.
- template <typename... Tys>
- [[deprecated("Use mlir::isa<U>() instead")]]
- bool isa() const;
- template <typename... Tys>
- [[deprecated("Use mlir::isa_and_nonnull<U>() instead")]]
- bool isa_and_nonnull() const;
- template <typename U>
- [[deprecated("Use mlir::dyn_cast<U>() instead")]]
- U dyn_cast() const;
- template <typename U>
- [[deprecated("Use mlir::dyn_cast_or_null<U>() instead")]]
- U dyn_cast_or_null() const;
- template <typename U>
- [[deprecated("Use mlir::cast<U>() instead")]]
- U cast() const;
-
/// Return a unique identifier for the concrete attribute type. This is used
/// to support dynamic type casting.
TypeID getTypeID() { return impl->getAbstractAttribute().getTypeID(); }
@@ -170,31 +152,6 @@ inline raw_ostream &operator<<(raw_ostream &os, Attribute attr) {
return os;
}
-template <typename... Tys>
-bool Attribute::isa() const {
- return llvm::isa<Tys...>(*this);
-}
-
-template <typename... Tys>
-bool Attribute::isa_and_nonnull() const {
- return llvm::isa_and_present<Tys...>(*this);
-}
-
-template <typename U>
-U Attribute::dyn_cast() const {
- return llvm::dyn_cast<U>(*this);
-}
-
-template <typename U>
-U Attribute::dyn_cast_or_null() const {
- return llvm::dyn_cast_if_present<U>(*this);
-}
-
-template <typename U>
-U Attribute::cast() const {
- return llvm::cast<U>(*this);
-}
-
inline ::llvm::hash_code hash_value(Attribute arg) {
return DenseMapInfo<const Attribute::ImplType *>::getHashValue(arg.impl);
}
diff --git a/mlir/include/mlir/IR/Location.h b/mlir/include/mlir/IR/Location.h
index 8ce36ed415ac1..5b1cf300295e5 100644
--- a/mlir/include/mlir/IR/Location.h
+++ b/mlir/include/mlir/IR/Location.h
@@ -79,23 +79,6 @@ class Location {
operator LocationAttr() const { return impl; }
LocationAttr *operator->() const { return const_cast<LocationAttr *>(&impl); }
- /// Type casting utilities on the underlying location.
- template <typename U>
- [[deprecated("Use mlir::isa<U>() instead")]]
- bool isa() const {
- return llvm::isa<U>(*this);
- }
- template <typename U>
- [[deprecated("Use mlir::dyn_cast<U>() instead")]]
- U dyn_cast() const {
- return llvm::dyn_cast<U>(*this);
- }
- template <typename U>
- [[deprecated("Use mlir::cast<U>() instead")]]
- U cast() const {
- return llvm::cast<U>(*this);
- }
-
/// Comparison operators.
bool operator==(Location rhs) const { return impl == rhs.impl; }
bool operator!=(Location rhs) const { return !(*this == rhs); }
diff --git a/mlir/include/mlir/IR/Types.h b/mlir/include/mlir/IR/Types.h
index e60f19a1ca585..4ffdbfa5b1224 100644
--- a/mlir/include/mlir/IR/Types.h
+++ b/mlir/include/mlir/IR/Types.h
@@ -96,22 +96,6 @@ class Type {
bool operator!() const { return impl == nullptr; }
- template <typename... Tys>
- [[deprecated("Use mlir::isa<U>() instead")]]
- bool isa() const;
- template <typename... Tys>
- [[deprecated("Use mlir::isa_and_nonnull<U>() instead")]]
- bool isa_and_nonnull() const;
- template <typename U>
- [[deprecated("Use mlir::dyn_cast<U>() instead")]]
- U dyn_cast() const;
- template <typename U>
- [[deprecated("Use mlir::dyn_cast_or_null<U>() instead")]]
- U dyn_cast_or_null() const;
- template <typename U>
- [[deprecated("Use mlir::cast<U>() instead")]]
- U cast() const;
-
/// Return a unique identifier for the concrete type. This is used to support
/// dynamic type casting.
TypeID getTypeID() { return impl->getAbstractType().getTypeID(); }
@@ -319,31 +303,6 @@ inline ::llvm::hash_code hash_value(Type arg) {
return DenseMapInfo<const Type::ImplType *>::getHashValue(arg.impl);
}
-template <typename... Tys>
-bool Type::isa() const {
- return llvm::isa<Tys...>(*this);
-}
-
-template <typename... Tys>
-bool Type::isa_and_nonnull() const {
- return llvm::isa_and_present<Tys...>(*this);
-}
-
-template <typename U>
-U Type::dyn_cast() const {
- return llvm::dyn_cast<U>(*this);
-}
-
-template <typename U>
-U Type::dyn_cast_or_null() const {
- return llvm::dyn_cast_or_null<U>(*this);
-}
-
-template <typename U>
-U Type::cast() const {
- return llvm::cast<U>(*this);
-}
-
} // namespace mlir
namespace llvm {
diff --git a/mlir/include/mlir/IR/Value.h b/mlir/include/mlir/IR/Value.h
index a7344c64e6730..d54e3c0ad26dd 100644
--- a/mlir/include/mlir/IR/Value.h
+++ b/mlir/include/mlir/IR/Value.h
@@ -97,30 +97,6 @@ class Value {
public:
constexpr Value(detail::ValueImpl *impl = nullptr) : impl(impl) {}
- template <typename U>
- [[deprecated("Use mlir::isa<U>() instead")]]
- bool isa() const {
- return llvm::isa<U>(*this);
- }
-
- template <typename U>
- [[deprecated("Use mlir::dyn_cast<U>() instead")]]
- U dyn_cast() const {
- return llvm::dyn_cast<U>(*this);
- }
-
- template <typename U>
- [[deprecated("Use mlir::dyn_cast_or_null<U>() instead")]]
- U dyn_cast_or_null() const {
- return llvm::dyn_cast_or_null<U>(*this);
- }
-
- template <typename U>
- [[deprecated("Use mlir::cast<U>() instead")]]
- U cast() const {
- return llvm::cast<U>(*this);
- }
-
explicit operator bool() const { return impl; }
bool operator==(const Value &other) const { return impl == other.impl; }
bool operator!=(const Value &other) const { return !(*this == other); }
diff --git a/mlir/include/mlir/Tools/PDLL/AST/Types.h b/mlir/include/mlir/Tools/PDLL/AST/Types.h
index 08d15bd764dfe..57161db5fdbad 100644
--- a/mlir/include/mlir/Tools/PDLL/AST/Types.h
+++ b/mlir/include/mlir/Tools/PDLL/AST/Types.h
@@ -62,35 +62,6 @@ class Type {
bool operator!=(const Type &other) const { return !(*this == other); }
explicit operator bool() const { return impl; }
- /// Provide type casting support.
- template <typename U>
- [[deprecated("Use mlir::isa<U>() instead")]]
- bool isa() const {
- assert(impl && "isa<> used on a null type.");
- return U::classof(*this);
- }
- template <typename U, typename V, typename... Others>
- [[deprecated("Use mlir::isa<U>() instead")]]
- bool isa() const {
- return isa<U>() || isa<V, Others...>();
- }
- template <typename U>
- [[deprecated("Use mlir::dyn_cast<U>() instead")]]
- U dyn_cast() const {
- return isa<U>() ? U(impl) : U(nullptr);
- }
- template <typename U>
- [[deprecated("Use mlir::dyn_cast_or_null<U>() instead")]]
- U dyn_cast_or_null() const {
- return (impl && isa<U>()) ? U(impl) : U(nullptr);
- }
- template <typename U>
- [[deprecated("Use mlir::cast<U>() instead")]]
- U cast() const {
- assert(isa<U>());
- return U(impl);
- }
-
/// Return the internal storage instance of this type.
Storage *getImpl() const { return impl; }
More information about the Mlir-commits
mailing list