[Mlir-commits] [mlir] 7b226fd - [MLIR] Add an Op util which returns its name with the dialect stripped.

Lucy Fox llvmlistbot at llvm.org
Tue Jun 16 16:48:56 PDT 2020


Author: Lucy Fox
Date: 2020-06-16T16:47:24-07:00
New Revision: 7b226fde6781aea59400aef880764c4632ee3b64

URL: https://github.com/llvm/llvm-project/commit/7b226fde6781aea59400aef880764c4632ee3b64
DIFF: https://github.com/llvm/llvm-project/commit/7b226fde6781aea59400aef880764c4632ee3b64.diff

LOG: [MLIR] Add an Op util which returns its name with the dialect stripped.

Differential Revision: https://reviews.llvm.org/D81435

Added: 
    

Modified: 
    mlir/include/mlir/IR/OperationSupport.h
    mlir/lib/IR/MLIRContext.cpp
    mlir/lib/IR/Operation.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/IR/OperationSupport.h b/mlir/include/mlir/IR/OperationSupport.h
index cf1dabff2841..aa75c57db1ff 100644
--- a/mlir/include/mlir/IR/OperationSupport.h
+++ b/mlir/include/mlir/IR/OperationSupport.h
@@ -302,6 +302,9 @@ class OperationName {
   /// Return the name of the dialect this operation is registered to.
   StringRef getDialect() const;
 
+  /// Return the operation name with dialect name stripped, if it has one.
+  StringRef stripDialect() const;
+
   /// Return the name of this operation.  This always succeeds.
   StringRef getStringRef() const;
 

diff  --git a/mlir/lib/IR/MLIRContext.cpp b/mlir/lib/IR/MLIRContext.cpp
index e72330b8eadd..2beb1a91dbae 100644
--- a/mlir/lib/IR/MLIRContext.cpp
+++ b/mlir/lib/IR/MLIRContext.cpp
@@ -554,8 +554,7 @@ bool MLIRContext::isOperationRegistered(StringRef name) {
 }
 
 void Dialect::addOperation(AbstractOperation opInfo) {
-  assert((getNamespace().empty() ||
-          opInfo.name.split('.').first == getNamespace()) &&
+  assert((getNamespace().empty() || opInfo.dialect.name == getNamespace()) &&
          "op name doesn't start with dialect namespace");
   assert(&opInfo.dialect == this && "Dialect object mismatch");
   auto &impl = context->getImpl();

diff  --git a/mlir/lib/IR/Operation.cpp b/mlir/lib/IR/Operation.cpp
index f83bc0a3b970..eb66d225638b 100644
--- a/mlir/lib/IR/Operation.cpp
+++ b/mlir/lib/IR/Operation.cpp
@@ -38,6 +38,12 @@ StringRef OperationName::getDialect() const {
   return getStringRef().split('.').first;
 }
 
+/// Return the operation name with dialect name stripped, if it has one.
+StringRef OperationName::stripDialect() const {
+  auto splitName = getStringRef().split(".");
+  return splitName.second.empty() ? splitName.first : splitName.second;
+}
+
 /// Return the name of this operation.  This always succeeds.
 StringRef OperationName::getStringRef() const {
   if (auto *op = representation.dyn_cast<const AbstractOperation *>())


        


More information about the Mlir-commits mailing list