[PATCH] D79088: [MLIR] Add isa<> support for Dialects.

Theodore Popp via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 29 06:56:59 PDT 2020


tpopp created this revision.
tpopp added a reviewer: rriddle.
Herald added subscribers: llvm-commits, Kayjukh, frgossen, grosul1, Joonsoo, liufengdb, aartbik, lucyrfox, mgester, arpith-jacob, nicolasvasilache, antiagainst, shauheen, jpienaar, mehdi_amini.
Herald added 1 blocking reviewer(s): rriddle.
Herald added a project: LLVM.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D79088

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


Index: mlir/include/mlir/IR/Dialect.h
===================================================================
--- mlir/include/mlir/IR/Dialect.h
+++ mlir/include/mlir/IR/Dialect.h
@@ -281,4 +281,15 @@
 
 } // 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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79088.260904.patch
Type: text/x-patch
Size: 514 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200429/35a29396/attachment.bin>


More information about the llvm-commits mailing list