[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
This commit is contained in:
Tres Popp 2020-04-29 15:45:50 +02:00
parent 3acf62f3ad
commit 70619fa82d
1 changed files with 10 additions and 0 deletions

View File

@ -281,4 +281,14 @@ template <typename ConcreteDialect> struct DialectRegistration {
} // namespace mlir
namespace llvm {
/// Provide isa functionality for Dialects.
template <typename T>
struct isa_impl<T, ::mlir::Dialect> {
static inline bool doit(const ::mlir::Dialect &dialect) {
return T::getDialectNamespace() == dialect.getNamespace();
}
};
} // namespace llvm
#endif