Update Attribute::getDialect/Type::getDialect to return a non-const dialect refer...
authorRiver Riddle <riverriddle@google.com>
Wed, 22 May 2019 16:56:11 +0000 (09:56 -0700)
committerMehdi Amini <joker.eph@gmail.com>
Sun, 2 Jun 2019 02:56:13 +0000 (19:56 -0700)
--

PiperOrigin-RevId: 249467245

mlir/include/mlir/IR/AttributeSupport.h
mlir/include/mlir/IR/Attributes.h
mlir/include/mlir/IR/TypeSupport.h
mlir/include/mlir/IR/Types.h
mlir/lib/IR/Attributes.cpp
mlir/lib/IR/MLIRContext.cpp
mlir/lib/IR/Types.cpp

index 8c0e65d..50c55cf 100644 (file)
@@ -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 &>(*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.
index acc5e72..a73ce43 100644 (file)
@@ -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;
index cdfef92..86620da 100644 (file)
@@ -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 <typename T>
-  static const Dialect &lookupDialectForType(MLIRContext *ctx) {
+  template <typename T> 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
 
index 738fb5d..7f70ec2 100644 (file)
@@ -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.
index 5bb4554..ee56abe 100644 (file)
@@ -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();
index 9c11f05..c353fd5 100644 (file)
@@ -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);
 }
 
index 3932e94..b60e81d 100644 (file)
@@ -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(); }