[PATCH] D72822: [mlir] Replace AbstractOperation::classof with a ClassID instance.

River Riddle via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 15 19:48:08 PST 2020


rriddle created this revision.
rriddle added a reviewer: mehdi_amini.
Herald added subscribers: llvm-commits, liufengdb, lucyrfox, mgester, arpith-jacob, nicolasvasilache, antiagainst, shauheen, burmako, jpienaar.
Herald added a project: LLVM.

This field is currently not used by anything, and using a ClassID instance provides better support for more efficient classof.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72822

Files:
  mlir/include/mlir/IR/OpDefinition.h
  mlir/include/mlir/IR/OperationSupport.h


Index: mlir/include/mlir/IR/OperationSupport.h
===================================================================
--- mlir/include/mlir/IR/OperationSupport.h
+++ mlir/include/mlir/IR/OperationSupport.h
@@ -90,8 +90,8 @@
   /// This is the dialect that this operation belongs to.
   Dialect &dialect;
 
-  /// Return true if this "op class" can match against the specified operation.
-  bool (&classof)(Operation *op);
+  /// The unique identifier of the derived Op class.
+  ClassID *classID;
 
   /// Use the specified object to parse this ops custom assembly format.
   ParseResult (&parseAssembly)(OpAsmParser &parser, OperationState &result);
@@ -158,15 +158,16 @@
   /// operations they contain.
   template <typename T> static AbstractOperation get(Dialect &dialect) {
     return AbstractOperation(
-        T::getOperationName(), dialect, T::getOperationProperties(), T::classof,
-        T::parseAssembly, T::printAssembly, T::verifyInvariants, T::foldHook,
-        T::getCanonicalizationPatterns, T::getRawInterface, T::hasTrait);
+        T::getOperationName(), dialect, T::getOperationProperties(),
+        ClassID::getID<T>(), T::parseAssembly, T::printAssembly,
+        T::verifyInvariants, T::foldHook, T::getCanonicalizationPatterns,
+        T::getRawInterface, T::hasTrait);
   }
 
 private:
   AbstractOperation(
       StringRef name, Dialect &dialect, OperationProperties opProperties,
-      bool (&classof)(Operation *op),
+      ClassID *classID,
       ParseResult (&parseAssembly)(OpAsmParser &parser, OperationState &result),
       void (&printAssembly)(Operation *op, OpAsmPrinter &p),
       LogicalResult (&verifyInvariants)(Operation *op),
@@ -176,7 +177,7 @@
                                           MLIRContext *context),
       void *(&getRawInterface)(ClassID *interfaceID),
       bool (&hasTrait)(ClassID *traitID))
-      : name(name), dialect(dialect), classof(classof),
+      : name(name), dialect(dialect), classID(classID),
         parseAssembly(parseAssembly), printAssembly(printAssembly),
         verifyInvariants(verifyInvariants), foldHook(foldHook),
         getCanonicalizationPatterns(getCanonicalizationPatterns),
Index: mlir/include/mlir/IR/OpDefinition.h
===================================================================
--- mlir/include/mlir/IR/OpDefinition.h
+++ mlir/include/mlir/IR/OpDefinition.h
@@ -984,7 +984,7 @@
   /// Return true if this "op class" can match against the specified operation.
   static bool classof(Operation *op) {
     if (auto *abstractOp = op->getAbstractOperation())
-      return &classof == abstractOp->classof;
+      return ClassID::getID<ConcreteType>() == abstractOp->classID;
     return op->getName().getStringRef() == ConcreteType::getOperationName();
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72822.238409.patch
Type: text/x-patch
Size: 2764 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200116/9793a0a9/attachment.bin>


More information about the llvm-commits mailing list