From d16b4708090157ff3aa7dab7a9963fcc9e64b244 Mon Sep 17 00:00:00 2001 From: River Riddle Date: Wed, 22 May 2019 09:56:11 -0700 Subject: [PATCH] Update Attribute::getDialect/Type::getDialect to return a non-const dialect reference. -- PiperOrigin-RevId: 249467245 --- mlir/include/mlir/IR/AttributeSupport.h | 8 ++++---- mlir/include/mlir/IR/Attributes.h | 2 +- mlir/include/mlir/IR/TypeSupport.h | 13 ++++++------- mlir/include/mlir/IR/Types.h | 2 +- mlir/lib/IR/Attributes.cpp | 2 +- mlir/lib/IR/MLIRContext.cpp | 4 ++-- mlir/lib/IR/Types.cpp | 2 +- 7 files changed, 16 insertions(+), 17 deletions(-) diff --git a/mlir/include/mlir/IR/AttributeSupport.h b/mlir/include/mlir/IR/AttributeSupport.h index 8c0e65d..50c55cf 100644 --- a/mlir/include/mlir/IR/AttributeSupport.h +++ b/mlir/include/mlir/IR/AttributeSupport.h @@ -54,9 +54,9 @@ public: Type getType() const; /// Get the dialect of this attribute. - const Dialect &getDialect() const { + Dialect &getDialect() const { assert(dialect && "Malformed attribute storage object."); - return *dialect; + return const_cast(*dialect); } protected: @@ -75,11 +75,11 @@ protected: // Set the dialect for this storage instance. This is used by the // AttributeUniquer when initializing a newly constructed storage object. - void initializeDialect(const Dialect &newDialect) { dialect = &newDialect; } + void initializeDialect(Dialect &newDialect) { dialect = &newDialect; } private: /// The dialect for this attribute. - const Dialect *dialect; + Dialect *dialect; /// This field is a pair of: /// - The type of the attribute value. diff --git a/mlir/include/mlir/IR/Attributes.h b/mlir/include/mlir/IR/Attributes.h index acc5e72..a73ce43 100644 --- a/mlir/include/mlir/IR/Attributes.h +++ b/mlir/include/mlir/IR/Attributes.h @@ -116,7 +116,7 @@ public: MLIRContext *getContext() const; /// Get the dialect this attribute is registered to. - const Dialect &getDialect() const; + Dialect &getDialect() const; /// Return true if this field is, or contains, a function attribute. bool isOrContainsFunction() const; diff --git a/mlir/include/mlir/IR/TypeSupport.h b/mlir/include/mlir/IR/TypeSupport.h index cdfef92..86620da 100644 --- a/mlir/include/mlir/IR/TypeSupport.h +++ b/mlir/include/mlir/IR/TypeSupport.h @@ -52,7 +52,7 @@ protected: public: /// Get the dialect that this type is registered to. - const Dialect &getDialect() const { + Dialect &getDialect() { assert(dialect && "Malformed type storage object."); return *dialect; } @@ -65,10 +65,10 @@ public: private: // Set the dialect for this storage instance. This is used by the TypeUniquer // when initializing a newly constructed type storage object. - void initializeDialect(const Dialect &newDialect) { dialect = &newDialect; } + void initializeDialect(Dialect &newDialect) { dialect = &newDialect; } /// The dialect for this type. - const Dialect *dialect; + Dialect *dialect; /// Space for subclasses to store data. unsigned subclassData; @@ -106,14 +106,13 @@ public: private: /// Get the dialect that the type 'T' was registered with. - template - static const Dialect &lookupDialectForType(MLIRContext *ctx) { + template static Dialect &lookupDialectForType(MLIRContext *ctx) { return lookupDialectForType(ctx, T::getClassID()); } /// Get the dialect that registered the type with the provided typeid. - static const Dialect &lookupDialectForType(MLIRContext *ctx, - const ClassID *const typeID); + static Dialect &lookupDialectForType(MLIRContext *ctx, + const ClassID *const typeID); }; } // namespace detail diff --git a/mlir/include/mlir/IR/Types.h b/mlir/include/mlir/IR/Types.h index 738fb5d..7f70ec2 100644 --- a/mlir/include/mlir/IR/Types.h +++ b/mlir/include/mlir/IR/Types.h @@ -144,7 +144,7 @@ public: MLIRContext *getContext(); /// Get the dialect this type is registered to. - const Dialect &getDialect(); + Dialect &getDialect(); // Convenience predicates. This is only for floating point types, // derived types should use isa/dyn_cast. diff --git a/mlir/lib/IR/Attributes.cpp b/mlir/lib/IR/Attributes.cpp index 5bb4554..ee56abe 100644 --- a/mlir/lib/IR/Attributes.cpp +++ b/mlir/lib/IR/Attributes.cpp @@ -59,7 +59,7 @@ Type Attribute::getType() const { return impl->getType(); } MLIRContext *Attribute::getContext() const { return getType().getContext(); } /// Get the dialect this attribute is registered to. -const Dialect &Attribute::getDialect() const { return impl->getDialect(); } +Dialect &Attribute::getDialect() const { return impl->getDialect(); } bool Attribute::isOrContainsFunction() const { return impl->isOrContainsFunctionCache(); diff --git a/mlir/lib/IR/MLIRContext.cpp b/mlir/lib/IR/MLIRContext.cpp index 9c11f05..c353fd5 100644 --- a/mlir/lib/IR/MLIRContext.cpp +++ b/mlir/lib/IR/MLIRContext.cpp @@ -695,8 +695,8 @@ static Dialect &lookupDialectForSymbol(MLIRContext *ctx, StorageUniquer &MLIRContext::getTypeUniquer() { return getImpl().typeUniquer; } /// Get the dialect that registered the type with the provided typeid. -const Dialect &TypeUniquer::lookupDialectForType(MLIRContext *ctx, - const ClassID *const typeID) { +Dialect &TypeUniquer::lookupDialectForType(MLIRContext *ctx, + const ClassID *const typeID) { return lookupDialectForSymbol(ctx, typeID); } diff --git a/mlir/lib/IR/Types.cpp b/mlir/lib/IR/Types.cpp index 3932e94..b60e81d 100644 --- a/mlir/lib/IR/Types.cpp +++ b/mlir/lib/IR/Types.cpp @@ -27,7 +27,7 @@ using namespace mlir::detail; unsigned Type::getKind() const { return impl->getKind(); } /// Get the dialect this type is registered to. -const Dialect &Type::getDialect() { return impl->getDialect(); } +Dialect &Type::getDialect() { return impl->getDialect(); } MLIRContext *Type::getContext() { return getDialect().getContext(); } -- 2.7.4