diff --git a/mlir/include/mlir/IR/OperationSupport.h b/mlir/include/mlir/IR/OperationSupport.h --- a/mlir/include/mlir/IR/OperationSupport.h +++ b/mlir/include/mlir/IR/OperationSupport.h @@ -302,6 +302,9 @@ /// 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 --- a/mlir/lib/IR/MLIRContext.cpp +++ b/mlir/lib/IR/MLIRContext.cpp @@ -554,8 +554,7 @@ } 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 --- a/mlir/lib/IR/Operation.cpp +++ b/mlir/lib/IR/Operation.cpp @@ -38,6 +38,12 @@ 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())