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

Differential Revision: https://reviews.llvm.org/D81435
This commit is contained in:
Lucy Fox 2020-06-16 15:23:10 -07:00
parent 8e204f807b
commit 7b226fde67
3 changed files with 10 additions and 2 deletions

View File

@ -302,6 +302,9 @@ public:
/// 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;

View File

@ -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();

View File

@ -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 *>())