From 70619fa82ddbe951d1b2d3dd224a131ff104edeb Mon Sep 17 00:00:00 2001 From: Tres Popp Date: Wed, 29 Apr 2020 15:45:50 +0200 Subject: [PATCH] [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 --- mlir/include/mlir/IR/Dialect.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mlir/include/mlir/IR/Dialect.h b/mlir/include/mlir/IR/Dialect.h index 292c14d..73d55c2 100644 --- a/mlir/include/mlir/IR/Dialect.h +++ b/mlir/include/mlir/IR/Dialect.h @@ -281,4 +281,14 @@ template struct DialectRegistration { } // namespace mlir +namespace llvm { +/// Provide isa functionality for Dialects. +template +struct isa_impl { + static inline bool doit(const ::mlir::Dialect &dialect) { + return T::getDialectNamespace() == dialect.getNamespace(); + } +}; +} // namespace llvm + #endif -- 2.7.4