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 @@ -82,10 +82,6 @@ def AnyReferenceLike : TypeConstraint, "any reference">; -// PROCEDURE POINTER descriptor. A pair that can capture a host closure. -def fir_BoxProcType : Type()">, - "box procedure type">; - def AnyBoxLike : TypeConstraint, "any box">; 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 @@ -42,7 +42,6 @@ using KindTy = unsigned; namespace detail { -struct BoxProcTypeStorage; struct ComplexTypeStorage; struct HeapTypeStorage; struct IntegerTypeStorage; @@ -143,20 +142,6 @@ // FIR support types -/// The type of a pair that describes a PROCEDURE reference. Pointers to -/// internal procedures must carry an additional reference to the host's -/// variables that are referenced. -class BoxProcType : public mlir::Type::TypeBase { -public: - using Base::Base; - static BoxProcType get(mlir::Type eleTy); - mlir::Type getEleTy() const; - - static mlir::LogicalResult verifyConstructionInvariants(mlir::Location, - mlir::Type eleTy); -}; - /// 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 @@ -21,6 +21,28 @@ let mnemonic = typeMnemonic; } +def fir_BoxProcType : FIR_Type<"BoxProc", "boxproc"> { + let summary = ""; + + let description = [{ + The type of a pair that describes a PROCEDURE reference. Pointers to + internal procedures must carry an additional reference to the host's + variables that are referenced. + }]; + + let parameters = (ins "mlir::Type":$eleTy); + + let printer = [{ + $_printer << "boxproc<"; + $_printer.printType(getEleTy()); + $_printer << '>'; + }]; + + let genAccessors = 1; + + let genVerifyInvariantsDecl = 1; +} + def BoxType : FIR_Type<"Box", "box"> { let summary = "The type of a Fortran descriptor"; @@ -41,6 +63,7 @@ }]; let genAccessors = 1; + let genVerifyInvariantsDecl = 1; } 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 @@ -58,11 +58,6 @@ return TYPE::get(ty); } -// `boxproc` `<` return-type `>` -BoxProcType parseBoxProc(mlir::DialectAsmParser &parser, mlir::Location loc) { - return parseTypeSingleton(parser, loc); -} - // `complex` `<` kind `>` fir::ComplexType parseComplex(mlir::DialectAsmParser &parser) { return parseKindSingleton(parser); @@ -310,7 +305,7 @@ if (typeNameLit == "boxchar") return generatedTypeParser(dialect->getContext(), parser, typeNameLit); if (typeNameLit == "boxproc") - return parseBoxProc(parser, loc); + return generatedTypeParser(dialect->getContext(), parser, typeNameLit); if (typeNameLit == "char") return generatedTypeParser(dialect->getContext(), parser, typeNameLit); if (typeNameLit == "complex") @@ -493,31 +488,6 @@ explicit RealTypeStorage(KindTy kind) : kind{kind} {} }; -/// Boxed PROCEDURE POINTER object type -struct BoxProcTypeStorage : public mlir::TypeStorage { - using KeyTy = mlir::Type; - - static unsigned hashKey(const KeyTy &key) { return llvm::hash_combine(key); } - - bool operator==(const KeyTy &key) const { return key == getElementType(); } - - static BoxProcTypeStorage *construct(mlir::TypeStorageAllocator &allocator, - mlir::Type eleTy) { - assert(eleTy && "element type is null"); - auto *storage = allocator.allocate(); - return new (storage) BoxProcTypeStorage{eleTy}; - } - - mlir::Type getElementType() const { return eleTy; } - -protected: - mlir::Type eleTy; - -private: - BoxProcTypeStorage() = delete; - explicit BoxProcTypeStorage(mlir::Type eleTy) : eleTy{eleTy} {} -}; - /// Pointer-like object storage struct ReferenceTypeStorage : public mlir::TypeStorage { using KeyTy = mlir::Type; @@ -836,27 +806,6 @@ return mlir::success(); } -// BoxProc - -BoxProcType fir::BoxProcType::get(mlir::Type elementType) { - return Base::get(elementType.getContext(), elementType); -} - -mlir::Type fir::BoxProcType::getEleTy() const { - return getImpl()->getElementType(); -} - -mlir::LogicalResult -fir::BoxProcType::verifyConstructionInvariants(mlir::Location loc, - mlir::Type eleTy) { - if (eleTy.isa()) - return mlir::success(); - if (auto refTy = eleTy.dyn_cast()) - if (refTy.isa()) - return mlir::success(); - return mlir::emitError(loc, "invalid type for boxproc") << eleTy << '\n'; -} - // Reference ReferenceType fir::ReferenceType::get(mlir::Type elementType) { @@ -1132,12 +1081,6 @@ void fir::printFirType(FIROpsDialect *, mlir::Type ty, mlir::DialectAsmPrinter &p) { auto &os = p.getStream(); - if (auto type = ty.dyn_cast()) { - os << "boxproc<"; - p.printType(type.getEleTy()); - os << '>'; - return; - } if (auto type = ty.dyn_cast()) { // Fortran intrinsic type COMPLEX os << "complex<" << type.getFKind() << '>'; @@ -1260,6 +1203,32 @@ return false; } +//===----------------------------------------------------------------------===// +// BoxProcType +//===----------------------------------------------------------------------===// + +// `boxproc` `<` return-type `>` +mlir::Type BoxProcType::parse(mlir::MLIRContext *context, + mlir::DialectAsmParser &parser) { + mlir::Type ty; + if (parser.parseLess() || parser.parseType(ty) || parser.parseGreater()) { + parser.emitError(parser.getCurrentLocation(), "type expected"); + return Type(); + } + return get(context, ty); +} + +mlir::LogicalResult +BoxProcType::verifyConstructionInvariants(mlir::Location loc, + mlir::Type eleTy) { + if (eleTy.isa()) + return mlir::success(); + if (auto refTy = eleTy.dyn_cast()) + if (refTy.isa()) + return mlir::success(); + return mlir::emitError(loc, "invalid type for boxproc") << eleTy << '\n'; +} + //===----------------------------------------------------------------------===// // BoxType //===----------------------------------------------------------------------===//