Skip to content

Commit 0bca049

Browse files
committed
Also deprecate mlir::pdll::ast::Type cast members.
Remove member cast overload in TypeSwitch so we don't have to disable the warning.
1 parent 26c4c60 commit 0bca049

File tree

2 files changed

+30
-25
lines changed

2 files changed

+30
-25
lines changed

llvm/include/llvm/ADT/TypeSwitch.h

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -61,32 +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-
// Silence warnings about MLIR's deprecated dyn_cast member functions.
78-
LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_PUSH;
79-
return value.template dyn_cast<CastT>();
80-
LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_POP;
81-
}
82-
83-
/// Attempt to dyn_cast the given `value` to `CastT`. This overload is
84-
/// selected if llvm::dyn_cast should be used.
85-
template <typename CastT, typename ValueT>
86-
static decltype(auto) castValue(
87-
ValueT &&value,
88-
std::enable_if_t<!is_detected<has_dyn_cast_t, ValueT, CastT>::value> * =
89-
nullptr) {
66+
static decltype(auto) castValue(ValueT &&value) {
9067
return dyn_cast<CastT>(value);
9168
}
9269

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)