Skip to content

Commit 70619fa

Browse files
committed
[MLIR] Add isa<> support for Dialects.
Summary: The purpose of this is to aid in having code behave differently on Operations based on their Dialect without caring about the specific Op. Additionally this is consistent with most other types supporting isa<> and dyn_cast<>. A Dialect matches isa<> based only on its namespace and relies on each namespace being unique. Differential Revision: https://reviews.llvm.org/D79088
1 parent 3acf62f commit 70619fa

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

mlir/include/mlir/IR/Dialect.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,4 +281,14 @@ template <typename ConcreteDialect> struct DialectRegistration {
281281

282282
} // namespace mlir
283283

284+
namespace llvm {
285+
/// Provide isa functionality for Dialects.
286+
template <typename T>
287+
struct isa_impl<T, ::mlir::Dialect> {
288+
static inline bool doit(const ::mlir::Dialect &dialect) {
289+
return T::getDialectNamespace() == dialect.getNamespace();
290+
}
291+
};
292+
} // namespace llvm
293+
284294
#endif

0 commit comments

Comments
 (0)