[Mlir-commits] [mlir] 70619fa - [MLIR] Add isa<> support for Dialects.

Tres Popp llvmlistbot at llvm.org
Thu Apr 30 02:12:00 PDT 2020


Author: Tres Popp
Date: 2020-04-30T11:11:49+02:00
New Revision: 70619fa82ddbe951d1b2d3dd224a131ff104edeb

URL: https://github.com/llvm/llvm-project/commit/70619fa82ddbe951d1b2d3dd224a131ff104edeb
DIFF: https://github.com/llvm/llvm-project/commit/70619fa82ddbe951d1b2d3dd224a131ff104edeb.diff

LOG: [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

Added: 
    

Modified: 
    mlir/include/mlir/IR/Dialect.h

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/IR/Dialect.h b/mlir/include/mlir/IR/Dialect.h
index 292c14db3f1f..73d55c2260c0 100644
--- a/mlir/include/mlir/IR/Dialect.h
+++ b/mlir/include/mlir/IR/Dialect.h
@@ -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


        


More information about the Mlir-commits mailing list