Rename the 'namePrefix' field in the Dialect class to 'name' and tidy some comments to make it clear that 'name' refers to the dialect namespace.

--

PiperOrigin-RevId: 241103116
This commit is contained in:
River Riddle 2019-03-29 22:30:54 -07:00 committed by Mehdi Amini
parent 0fb905c070
commit dfc58742a2
6 changed files with 19 additions and 17 deletions

View File

@ -47,7 +47,7 @@ class Dialect {
public:
MLIRContext *getContext() const { return context; }
StringRef getNamespace() const { return namePrefix; }
StringRef getNamespace() const { return name; }
/// Registered fallback constant fold hook for the dialect. Like the constant
/// fold hook of each operation, it attempts to constant fold the operation
@ -127,12 +127,14 @@ public:
static bool isValidNamespace(StringRef str);
protected:
/// Note: The namePrefix must not contain '.' characters.
/// Note: All operations belonging to this dialect will need to have names
/// starting with the namePrefix followed by '.'.
/// The constructor takes a unique namespace for this dialect as well as the
/// context to bind to.
/// Note: The namespace must not contain '.' characters.
/// Note: All operations belonging to this dialect must have names starting
/// with the namespace followed by '.'.
/// Example:
/// - "tf" for the TensorFlow ops like "tf.add".
Dialect(StringRef namePrefix, MLIRContext *context);
Dialect(StringRef name, MLIRContext *context);
/// This method is used by derived classes to add their operations to the set.
///
@ -194,8 +196,8 @@ private:
/// takes ownership of the heap allocated dialect.
void registerDialect(MLIRContext *context);
/// This is the namespace used as a prefix for IR defined by this dialect.
StringRef namePrefix;
/// The namespace of this dialect.
StringRef name;
/// This is the context that owns this Dialect object.
MLIRContext *context;

View File

@ -36,7 +36,7 @@ using llvm::dbgs;
//===----------------------------------------------------------------------===//
AffineOpsDialect::AffineOpsDialect(MLIRContext *context)
: Dialect(/*namePrefix=*/"affine", context) {
: Dialect(/*name=*/"affine", context) {
addOperations<AffineApplyOp, AffineForOp, AffineIfOp, AffineTerminatorOp>();
}

View File

@ -59,9 +59,9 @@ void mlir::registerAllDialects(MLIRContext *context) {
}
}
Dialect::Dialect(StringRef namePrefix, MLIRContext *context)
: namePrefix(namePrefix), context(context) {
assert(isValidNamespace(namePrefix) && "invalid dialect namespace");
Dialect::Dialect(StringRef name, MLIRContext *context)
: name(name), context(context) {
assert(isValidNamespace(name) && "invalid dialect namespace");
registerDialect(context);
}

View File

@ -103,7 +103,7 @@ namespace {
/// A builtin dialect to define types/etc that are necessary for the
/// validity of the IR.
struct BuiltinDialect : public Dialect {
BuiltinDialect(MLIRContext *context) : Dialect(/*namePrefix=*/"", context) {
BuiltinDialect(MLIRContext *context) : Dialect(/*name=*/"", context) {
addTypes<FunctionType, UnknownType, FloatType, IndexType, IntegerType,
VectorType, RankedTensorType, UnrankedTensorType, MemRefType,
ComplexType, TupleType>();
@ -742,15 +742,15 @@ std::vector<AbstractOperation *> MLIRContext::getRegisteredOperations() {
}
void Dialect::addOperation(AbstractOperation opInfo) {
assert(opInfo.name.split('.').first == namePrefix &&
"op name doesn't start with dialect prefix");
assert(opInfo.name.split('.').first == getNamespace() &&
"op name doesn't start with dialect namespace");
assert(&opInfo.dialect == this && "Dialect object mismatch");
auto &impl = context->getImpl();
// Lock access to the context registry.
llvm::sys::SmartScopedWriter<true> registryLock(impl.contextMutex);
if (!impl.registeredOperations.insert({opInfo.name, opInfo}).second) {
llvm::errs() << "error: ops named '" << opInfo.name
llvm::errs() << "error: operation named '" << opInfo.name
<< "' is already registered.\n";
abort();
}

View File

@ -58,7 +58,7 @@ void detail::printStandardBinaryOp(Operation *op, OpAsmPrinter *p) {
}
StandardOpsDialect::StandardOpsDialect(MLIRContext *context)
: Dialect(/*namePrefix=*/"std", context) {
: Dialect(/*name=*/"std", context) {
addOperations<AllocOp, BranchOp, CallOp, CallIndirectOp, CmpIOp, CondBranchOp,
ConstantOp, DeallocOp, DimOp, DmaStartOp, DmaWaitOp,
ExtractElementOp, LoadOp, MemRefCastOp, ReturnOp, SelectOp,

View File

@ -23,7 +23,7 @@ using namespace mlir::detail;
namespace {
struct TestDialect : public Dialect {
TestDialect(MLIRContext *context) : Dialect(/*namePrefix=*/"test", context) {}
TestDialect(MLIRContext *context) : Dialect(/*name=*/"test", context) {}
};
TEST(DialectDeathTest, MultipleDialectsWithSameNamespace) {