[flang-commits] [flang] 550f251 - [flang][fir][NFC] Move ShapeShiftType to TableGen type definition

via flang-commits flang-commits at lists.llvm.org
Wed Feb 10 17:32:35 PST 2021


Author: Valentin Clement
Date: 2021-02-10T20:32:28-05:00
New Revision: 550f251e47e6132ff7cefaa7bb63420934d39c05

URL: https://github.com/llvm/llvm-project/commit/550f251e47e6132ff7cefaa7bb63420934d39c05
DIFF: https://github.com/llvm/llvm-project/commit/550f251e47e6132ff7cefaa7bb63420934d39c05.diff

LOG: [flang][fir][NFC] Move ShapeShiftType to TableGen type definition

This patch is a follow up of D96422 and move the ShapeShiftType to
TableGen.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D96442

Added: 
    

Modified: 
    flang/include/flang/Optimizer/Dialect/FIROps.td
    flang/include/flang/Optimizer/Dialect/FIRType.h
    flang/include/flang/Optimizer/Dialect/FIRTypes.td
    flang/lib/Optimizer/Dialect/FIRType.cpp

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Optimizer/Dialect/FIROps.td b/flang/include/flang/Optimizer/Dialect/FIROps.td
index a156ca4d4b9e..918fdd400c3c 100644
--- a/flang/include/flang/Optimizer/Dialect/FIROps.td
+++ b/flang/include/flang/Optimizer/Dialect/FIROps.td
@@ -101,10 +101,8 @@ def AnyRefOrBox : TypeConstraint<Or<[fir_ReferenceType.predicate,
     fir_HeapType.predicate, fir_PointerType.predicate, fir_BoxType.predicate]>,
     "any reference or box">;
 
-def fir_ShapeShiftType : Type<CPred<"$_self.isa<fir::ShapeShiftType>()">,
-    "shape shift type">;
 def AnyShapeLike : TypeConstraint<Or<[ShapeType.predicate,
-    fir_ShapeShiftType.predicate]>, "any legal shape type">;
+    ShapeShiftType.predicate]>, "any legal shape type">;
 def AnyShapeType : Type<AnyShapeLike.predicate, "any legal shape type">;
 def fir_SliceType : Type<CPred<"$_self.isa<fir::SliceType>()">, "slice type">;
 

diff  --git a/flang/include/flang/Optimizer/Dialect/FIRType.h b/flang/include/flang/Optimizer/Dialect/FIRType.h
index 487f8b0fe485..44e676ce9736 100644
--- a/flang/include/flang/Optimizer/Dialect/FIRType.h
+++ b/flang/include/flang/Optimizer/Dialect/FIRType.h
@@ -57,7 +57,6 @@ struct RealTypeStorage;
 struct RecordTypeStorage;
 struct ReferenceTypeStorage;
 struct SequenceTypeStorage;
-struct ShapeShiftTypeStorage;
 struct SliceTypeStorage;
 struct TypeDescTypeStorage;
 struct VectorTypeStorage;
@@ -221,20 +220,6 @@ class BoxProcType : public mlir::Type::TypeBase<BoxProcType, mlir::Type,
                                                           mlir::Type eleTy);
 };
 
-
-/// Type of a vector of runtime values that define the shape and the origin of a
-/// multidimensional array object. The vector is of pairs, origin offset and
-/// extent, of each array dimension. The rank of a ShapeShiftType must be at
-/// least 1.
-class ShapeShiftType
-    : public mlir::Type::TypeBase<ShapeShiftType, mlir::Type,
-                                  detail::ShapeShiftTypeStorage> {
-public:
-  using Base::Base;
-  static ShapeShiftType get(mlir::MLIRContext *ctx, unsigned rank);
-  unsigned getRank() const;
-};
-
 /// Type of a vector that represents an array slice operation on an array.
 /// Fortran slices are triples of lower bound, upper bound, and stride. The rank
 /// of a SliceType must be at least 1.

diff  --git a/flang/include/flang/Optimizer/Dialect/FIRTypes.td b/flang/include/flang/Optimizer/Dialect/FIRTypes.td
index 1ed16088c36b..99f1c179da87 100644
--- a/flang/include/flang/Optimizer/Dialect/FIRTypes.td
+++ b/flang/include/flang/Optimizer/Dialect/FIRTypes.td
@@ -45,4 +45,32 @@ def ShapeType : FIR_Type<"Shape", "shape"> {
   }];
 }
 
+def ShapeShiftType : FIR_Type<"ShapeShift", "shapeshift"> {
+  let summary = "shape and origin of a multidimensional array object";
+
+  let description = [{
+    Type of a vector of runtime values that define the shape and the origin of a
+    multidimensional array object. The vector is of pairs, origin offset and
+    extent, of each array dimension. The rank of a ShapeShiftType must be at
+    least 1.
+  }];
+
+  let parameters = (ins "unsigned":$rank);
+
+  let printer = [{
+    $_printer << "shapeshift<" << getImpl()->rank << ">";
+  }];
+
+  let parser = [{
+    if ($_parser.parseLess())
+      return Type();
+    int rank;
+    if ($_parser.parseInteger(rank))
+      return Type();
+    if ($_parser.parseGreater())
+      return Type();
+    return get(context, rank);
+  }];
+}
+
 #endif // FIR_DIALECT_FIR_TYPES

diff  --git a/flang/lib/Optimizer/Dialect/FIRType.cpp b/flang/lib/Optimizer/Dialect/FIRType.cpp
index d1e1a8c043fb..68b7bd3eafd9 100644
--- a/flang/lib/Optimizer/Dialect/FIRType.cpp
+++ b/flang/lib/Optimizer/Dialect/FIRType.cpp
@@ -389,7 +389,7 @@ mlir::Type fir::parseFirType(FIROpsDialect *dialect,
     // TODO move to generatedTypeParser when all types have been moved
     return ShapeType::parse(dialect->getContext(), parser);
   if (typeNameLit == "shapeshift")
-    return parseShapeShift(parser);
+    return ShapeShiftType::parse(dialect->getContext(), parser);
   if (typeNameLit == "slice")
     return parseSlice(parser);
   if (typeNameLit == "tdesc")
@@ -443,29 +443,6 @@ struct CharacterTypeStorage : public mlir::TypeStorage {
       : kind{kind}, len{len} {}
 };
 
-struct ShapeShiftTypeStorage : public mlir::TypeStorage {
-  using KeyTy = unsigned;
-
-  static unsigned hashKey(const KeyTy &key) { return llvm::hash_combine(key); }
-
-  bool operator==(const KeyTy &key) const { return key == getRank(); }
-
-  static ShapeShiftTypeStorage *construct(mlir::TypeStorageAllocator &allocator,
-                                          unsigned rank) {
-    auto *storage = allocator.allocate<ShapeShiftTypeStorage>();
-    return new (storage) ShapeShiftTypeStorage{rank};
-  }
-
-  unsigned getRank() const { return rank; }
-
-protected:
-  unsigned rank;
-
-private:
-  ShapeShiftTypeStorage() = delete;
-  explicit ShapeShiftTypeStorage(unsigned rank) : rank{rank} {}
-};
-
 struct SliceTypeStorage : public mlir::TypeStorage {
   using KeyTy = unsigned;
 
@@ -1249,15 +1226,6 @@ llvm::hash_code fir::hash_value(const SequenceType::Shape &sh) {
   return llvm::hash_combine(0);
 }
 
-// Shapeshift
-
-ShapeShiftType fir::ShapeShiftType::get(mlir::MLIRContext *ctxt,
-                                        unsigned rank) {
-  return Base::get(ctxt, rank);
-}
-
-unsigned fir::ShapeShiftType::getRank() const { return getImpl()->getRank(); }
-
 // Slice
 
 SliceType fir::SliceType::get(mlir::MLIRContext *ctxt, unsigned rank) {
@@ -1453,7 +1421,7 @@ void fir::printFirType(FIROpsDialect *, mlir::Type ty,
     return;
   }
   if (auto type = ty.dyn_cast<ShapeShiftType>()) {
-    os << "shapeshift<" << type.getRank() << '>';
+    type.print(p);
     return;
   }
   if (auto type = ty.dyn_cast<SliceType>()) {


        


More information about the flang-commits mailing list