diff --git a/flang/include/flang/Optimizer/Dialect/FIROps.td b/flang/include/flang/Optimizer/Dialect/FIROps.td --- a/flang/include/flang/Optimizer/Dialect/FIROps.td +++ b/flang/include/flang/Optimizer/Dialect/FIROps.td @@ -101,10 +101,8 @@ fir_HeapType.predicate, fir_PointerType.predicate, fir_BoxType.predicate]>, "any reference or box">; -def fir_ShapeShiftType : Type()">, - "shape shift type">; def AnyShapeLike : TypeConstraint, "any legal shape type">; + ShapeShiftType.predicate]>, "any legal shape type">; def AnyShapeType : Type; def fir_SliceType : Type()">, "slice type">; diff --git a/flang/include/flang/Optimizer/Dialect/FIRType.h b/flang/include/flang/Optimizer/Dialect/FIRType.h --- a/flang/include/flang/Optimizer/Dialect/FIRType.h +++ b/flang/include/flang/Optimizer/Dialect/FIRType.h @@ -57,7 +57,6 @@ struct RecordTypeStorage; struct ReferenceTypeStorage; struct SequenceTypeStorage; -struct ShapeShiftTypeStorage; struct SliceTypeStorage; struct TypeDescTypeStorage; struct VectorTypeStorage; @@ -221,20 +220,6 @@ 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 { -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 --- a/flang/include/flang/Optimizer/Dialect/FIRTypes.td +++ b/flang/include/flang/Optimizer/Dialect/FIRTypes.td @@ -45,4 +45,32 @@ }]; } +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 --- a/flang/lib/Optimizer/Dialect/FIRType.cpp +++ b/flang/lib/Optimizer/Dialect/FIRType.cpp @@ -389,7 +389,7 @@ // 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 @@ : 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(); - 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 @@ 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 @@ return; } if (auto type = ty.dyn_cast()) { - os << "shapeshift<" << type.getRank() << '>'; + type.print(p); return; } if (auto type = ty.dyn_cast()) {