@@ -58,27 +58,6 @@ TYPE parseTypeSingleton(mlir::DialectAsmParser &parser, mlir::Location) {
5858 return TYPE::get (ty);
5959}
6060
61- // `box` `<` type (',' affine-map)? `>`
62- BoxType parseBox (mlir::DialectAsmParser &parser, mlir::Location loc) {
63- mlir::Type ofTy;
64- if (parser.parseLess () || parser.parseType (ofTy)) {
65- parser.emitError (parser.getCurrentLocation (), " expected type parameter" );
66- return {};
67- }
68-
69- mlir::AffineMapAttr map;
70- if (!parser.parseOptionalComma ())
71- if (parser.parseAttribute (map)) {
72- parser.emitError (parser.getCurrentLocation (), " expected affine map" );
73- return {};
74- }
75- if (parser.parseGreater ()) {
76- parser.emitError (parser.getCurrentLocation (), " expected '>'" );
77- return {};
78- }
79- return BoxType::get (ofTy, map);
80- }
81-
8261// `boxchar` `<` kind `>`
8362BoxCharType parseBoxChar (mlir::DialectAsmParser &parser) {
8463 return parseKindSingleton<BoxCharType>(parser);
@@ -355,7 +334,7 @@ mlir::Type fir::parseFirType(FIROpsDialect *dialect,
355334 if (typeNameLit == " array" )
356335 return parseSequence (parser, loc);
357336 if (typeNameLit == " box" )
358- return parseBox ( parser, loc );
337+ return generatedTypeParser (dialect-> getContext (), parser, typeNameLit );
359338 if (typeNameLit == " boxchar" )
360339 return parseBoxChar (parser);
361340 if (typeNameLit == " boxproc" )
@@ -594,41 +573,6 @@ struct RealTypeStorage : public mlir::TypeStorage {
594573 explicit RealTypeStorage (KindTy kind) : kind{kind} {}
595574};
596575
597- // / Boxed object (a Fortran descriptor)
598- struct BoxTypeStorage : public mlir ::TypeStorage {
599- using KeyTy = std::tuple<mlir::Type, mlir::AffineMapAttr>;
600-
601- static unsigned hashKey (const KeyTy &key) {
602- auto hashVal{llvm::hash_combine (std::get<mlir::Type>(key))};
603- return llvm::hash_combine (
604- hashVal, llvm::hash_combine (std::get<mlir::AffineMapAttr>(key)));
605- }
606-
607- bool operator ==(const KeyTy &key) const {
608- return std::get<mlir::Type>(key) == getElementType () &&
609- std::get<mlir::AffineMapAttr>(key) == getLayoutMap ();
610- }
611-
612- static BoxTypeStorage *construct (mlir::TypeStorageAllocator &allocator,
613- const KeyTy &key) {
614- auto *storage = allocator.allocate <BoxTypeStorage>();
615- return new (storage) BoxTypeStorage{std::get<mlir::Type>(key),
616- std::get<mlir::AffineMapAttr>(key)};
617- }
618-
619- mlir::Type getElementType () const { return eleTy; }
620- mlir::AffineMapAttr getLayoutMap () const { return map; }
621-
622- protected:
623- mlir::Type eleTy;
624- mlir::AffineMapAttr map;
625-
626- private:
627- BoxTypeStorage () = delete ;
628- explicit BoxTypeStorage (mlir::Type eleTy, mlir::AffineMapAttr map)
629- : eleTy{eleTy}, map{map} {}
630- };
631-
632576// / Boxed CHARACTER object type
633577struct BoxCharTypeStorage : public mlir ::TypeStorage {
634578 using KeyTy = KindTy;
@@ -1013,20 +957,6 @@ RealType fir::RealType::get(mlir::MLIRContext *ctxt, KindTy kind) {
1013957
1014958KindTy fir::RealType::getFKind () const { return getImpl ()->getFKind (); }
1015959
1016- // Box<T>
1017-
1018- BoxType fir::BoxType::get (mlir::Type elementType, mlir::AffineMapAttr map) {
1019- return Base::get (elementType.getContext (), elementType, map);
1020- }
1021-
1022- mlir::Type fir::BoxType::getEleTy () const {
1023- return getImpl ()->getElementType ();
1024- }
1025-
1026- mlir::AffineMapAttr fir::BoxType::getLayoutMap () const {
1027- return getImpl ()->getLayoutMap ();
1028- }
1029-
1030960mlir::LogicalResult
1031961fir::BoxType::verifyConstructionInvariants (mlir::Location, mlir::Type eleTy,
1032962 mlir::AffineMapAttr map) {
@@ -1340,16 +1270,6 @@ void fir::verifyIntegralType(mlir::Type type) {
13401270void fir::printFirType (FIROpsDialect *, mlir::Type ty,
13411271 mlir::DialectAsmPrinter &p) {
13421272 auto &os = p.getStream ();
1343- if (auto type = ty.dyn_cast <BoxType>()) {
1344- os << " box<" ;
1345- p.printType (type.getEleTy ());
1346- if (auto map = type.getLayoutMap ()) {
1347- os << " , " ;
1348- p.printAttribute (map);
1349- }
1350- os << ' >' ;
1351- return ;
1352- }
13531273 if (auto type = ty.dyn_cast <BoxCharType>()) {
13541274 os << " boxchar<" << type.getEleTy ().cast <fir::CharacterType>().getFKind ()
13551275 << ' >' ;
@@ -1500,3 +1420,44 @@ bool fir::isa_unknown_size_box(mlir::Type t) {
15001420 }
15011421 return false ;
15021422}
1423+
1424+ namespace fir {
1425+
1426+ // ===----------------------------------------------------------------------===//
1427+ // BoxType
1428+ // ===----------------------------------------------------------------------===//
1429+
1430+ // `box` `<` type (',' affine-map)? `>`
1431+ mlir::Type BoxType::parse (mlir::MLIRContext *context,
1432+ mlir::DialectAsmParser &parser) {
1433+ mlir::Type ofTy;
1434+ if (parser.parseLess () || parser.parseType (ofTy)) {
1435+ parser.emitError (parser.getCurrentLocation (), " expected type parameter" );
1436+ return Type ();
1437+ }
1438+
1439+ mlir::AffineMapAttr map;
1440+ if (!parser.parseOptionalComma ()) {
1441+ if (parser.parseAttribute (map)) {
1442+ parser.emitError (parser.getCurrentLocation (), " expected affine map" );
1443+ return Type ();
1444+ }
1445+ }
1446+ if (parser.parseGreater ()) {
1447+ parser.emitError (parser.getCurrentLocation (), " expected '>'" );
1448+ return Type ();
1449+ }
1450+ return get (ofTy, map);
1451+ }
1452+
1453+ void BoxType::print (::mlir::DialectAsmPrinter &printer) const {
1454+ printer << " box<" ;
1455+ printer.printType (getEleTy ());
1456+ if (auto map = getLayoutMap ()) {
1457+ printer << " , " ;
1458+ printer.printAttribute (map);
1459+ }
1460+ printer << ' >' ;
1461+ }
1462+
1463+ } // namespace fir
0 commit comments