Skip to content

Commit 7ac1fb0

Browse files
authored
[mlir] Mark isa/dyn_cast/cast/... member functions deprecated. (#90413)
This also removes the member overload in TypeSwitch. All other users have been removed in fac349a and bd9fdce.
1 parent f78949a commit 7ac1fb0

File tree

5 files changed

+43
-22
lines changed

5 files changed

+43
-22
lines changed

llvm/include/llvm/ADT/TypeSwitch.h

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -61,29 +61,9 @@ template <typename DerivedT, typename T> class TypeSwitchBase {
6161
}
6262

6363
protected:
64-
/// Trait to check whether `ValueT` provides a 'dyn_cast' method with type
65-
/// `CastT`.
66-
template <typename ValueT, typename CastT>
67-
using has_dyn_cast_t =
68-
decltype(std::declval<ValueT &>().template dyn_cast<CastT>());
69-
70-
/// Attempt to dyn_cast the given `value` to `CastT`. This overload is
71-
/// selected if `value` already has a suitable dyn_cast method.
64+
/// Attempt to dyn_cast the given `value` to `CastT`.
7265
template <typename CastT, typename ValueT>
73-
static decltype(auto) castValue(
74-
ValueT &&value,
75-
std::enable_if_t<is_detected<has_dyn_cast_t, ValueT, CastT>::value> * =
76-
nullptr) {
77-
return value.template dyn_cast<CastT>();
78-
}
79-
80-
/// Attempt to dyn_cast the given `value` to `CastT`. This overload is
81-
/// selected if llvm::dyn_cast should be used.
82-
template <typename CastT, typename ValueT>
83-
static decltype(auto) castValue(
84-
ValueT &&value,
85-
std::enable_if_t<!is_detected<has_dyn_cast_t, ValueT, CastT>::value> * =
86-
nullptr) {
66+
static decltype(auto) castValue(ValueT &&value) {
8767
return dyn_cast<CastT>(value);
8868
}
8969

mlir/include/mlir/IR/Attributes.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,19 @@ class Attribute {
5050
/// Casting utility functions. These are deprecated and will be removed,
5151
/// please prefer using the `llvm` namespace variants instead.
5252
template <typename... Tys>
53+
[[deprecated("Use mlir::isa<U>() instead")]]
5354
bool isa() const;
5455
template <typename... Tys>
56+
[[deprecated("Use mlir::isa_and_nonnull<U>() instead")]]
5557
bool isa_and_nonnull() const;
5658
template <typename U>
59+
[[deprecated("Use mlir::dyn_cast<U>() instead")]]
5760
U dyn_cast() const;
5861
template <typename U>
62+
[[deprecated("Use mlir::dyn_cast_or_null<U>() instead")]]
5963
U dyn_cast_or_null() const;
6064
template <typename U>
65+
[[deprecated("Use mlir::cast<U>() instead")]]
6166
U cast() const;
6267

6368
/// Return a unique identifier for the concrete attribute type. This is used

mlir/include/mlir/IR/Location.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,17 @@ class Location {
7878

7979
/// Type casting utilities on the underlying location.
8080
template <typename U>
81+
[[deprecated("Use mlir::isa<U>() instead")]]
8182
bool isa() const {
8283
return llvm::isa<U>(*this);
8384
}
8485
template <typename U>
86+
[[deprecated("Use mlir::dyn_cast<U>() instead")]]
8587
U dyn_cast() const {
8688
return llvm::dyn_cast<U>(*this);
8789
}
8890
template <typename U>
91+
[[deprecated("Use mlir::cast<U>() instead")]]
8992
U cast() const {
9093
return llvm::cast<U>(*this);
9194
}

mlir/include/mlir/IR/Types.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,19 @@ class Type {
9797
bool operator!() const { return impl == nullptr; }
9898

9999
template <typename... Tys>
100+
[[deprecated("Use mlir::isa<U>() instead")]]
100101
bool isa() const;
101102
template <typename... Tys>
103+
[[deprecated("Use mlir::isa_and_nonnull<U>() instead")]]
102104
bool isa_and_nonnull() const;
103105
template <typename U>
106+
[[deprecated("Use mlir::dyn_cast<U>() instead")]]
104107
U dyn_cast() const;
105108
template <typename U>
109+
[[deprecated("Use mlir::dyn_cast_or_null<U>() instead")]]
106110
U dyn_cast_or_null() const;
107111
template <typename U>
112+
[[deprecated("Use mlir::cast<U>() instead")]]
108113
U cast() const;
109114

110115
/// Return a unique identifier for the concrete type. This is used to support

mlir/include/mlir/Tools/PDLL/AST/Types.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,23 +64,28 @@ class Type {
6464

6565
/// Provide type casting support.
6666
template <typename U>
67+
[[deprecated("Use mlir::isa<U>() instead")]]
6768
bool isa() const {
6869
assert(impl && "isa<> used on a null type.");
6970
return U::classof(*this);
7071
}
7172
template <typename U, typename V, typename... Others>
73+
[[deprecated("Use mlir::isa<U>() instead")]]
7274
bool isa() const {
7375
return isa<U>() || isa<V, Others...>();
7476
}
7577
template <typename U>
78+
[[deprecated("Use mlir::dyn_cast<U>() instead")]]
7679
U dyn_cast() const {
7780
return isa<U>() ? U(impl) : U(nullptr);
7881
}
7982
template <typename U>
83+
[[deprecated("Use mlir::dyn_cast_or_null<U>() instead")]]
8084
U dyn_cast_or_null() const {
8185
return (impl && isa<U>()) ? U(impl) : U(nullptr);
8286
}
8387
template <typename U>
88+
[[deprecated("Use mlir::cast<U>() instead")]]
8489
U cast() const {
8590
assert(isa<U>());
8691
return U(impl);
@@ -323,6 +328,29 @@ struct DenseMapInfo<mlir::pdll::ast::Type> {
323328
return lhs == rhs;
324329
}
325330
};
331+
332+
/// Add support for llvm style casts.
333+
/// We provide a cast between To and From if From is mlir::pdll::ast::Type or
334+
/// derives from it
335+
template <typename To, typename From>
336+
struct CastInfo<
337+
To, From,
338+
std::enable_if_t<
339+
std::is_same_v<mlir::pdll::ast::Type, std::remove_const_t<From>> ||
340+
std::is_base_of_v<mlir::pdll::ast::Type, From>>>
341+
: NullableValueCastFailed<To>,
342+
DefaultDoCastIfPossible<To, From, CastInfo<To, From>> {
343+
static inline bool isPossible(mlir::pdll::ast::Type ty) {
344+
/// Return a constant true instead of a dynamic true when casting to self or
345+
/// up the hierarchy.
346+
if constexpr (std::is_base_of_v<To, From>) {
347+
return true;
348+
} else {
349+
return To::classof(ty);
350+
};
351+
}
352+
static inline To doCast(mlir::pdll::ast::Type ty) { return To(ty.getImpl()); }
353+
};
326354
} // namespace llvm
327355

328356
#endif // MLIR_TOOLS_PDLL_AST_TYPES_H_

0 commit comments

Comments
 (0)