[flang][fir][NFC] Move FieldType to TableGen type definition

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

Reviewed By: schweitz, mehdi_amini

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

GitOrigin-RevId: 8c1b63307f0696058bf4a9f7a54b012867f2457e
diff --git a/include/flang/Optimizer/Dialect/FIROps.td b/include/flang/Optimizer/Dialect/FIROps.td
index a0df05e..8966568 100644
--- a/include/flang/Optimizer/Dialect/FIROps.td
+++ b/include/flang/Optimizer/Dialect/FIROps.td
@@ -113,9 +113,6 @@
 def fir_TypeDescType : Type<CPred<"$_self.isa<fir::TypeDescType>()">,
     "type desc type">;
 
-// A field (in a RecordType) argument's type
-def fir_FieldType : Type<CPred<"$_self.isa<fir::FieldType>()">, "field type">;
-
 // A LEN parameter (in a RecordType) argument's type
 def fir_LenType : Type<CPred<"$_self.isa<fir::LenType>()">,
     "LEN parameter type">;
diff --git a/include/flang/Optimizer/Dialect/FIRType.h b/include/flang/Optimizer/Dialect/FIRType.h
index a531a51..a80c402 100644
--- a/include/flang/Optimizer/Dialect/FIRType.h
+++ b/include/flang/Optimizer/Dialect/FIRType.h
@@ -46,7 +46,6 @@
 struct BoxProcTypeStorage;
 struct CharacterTypeStorage;
 struct ComplexTypeStorage;
-struct FieldTypeStorage;
 struct HeapTypeStorage;
 struct IntegerTypeStorage;
 struct LenTypeStorage;
@@ -213,16 +212,6 @@
   unsigned getRank() const;
 };
 
-/// The type of a field name. Implementations may defer the layout of a Fortran
-/// derived type until runtime. This implies that the runtime must be able to
-/// determine the offset of fields within the entity.
-class FieldType : public mlir::Type::TypeBase<FieldType, mlir::Type,
-                                              detail::FieldTypeStorage> {
-public:
-  using Base::Base;
-  static FieldType get(mlir::MLIRContext *ctxt);
-};
-
 /// The type of a heap pointer. Fortran entities with the ALLOCATABLE attribute
 /// may be allocated on the heap at runtime. These pointers are explicitly
 /// distinguished to disallow the composition of multiple levels of
diff --git a/include/flang/Optimizer/Dialect/FIRTypes.td b/include/flang/Optimizer/Dialect/FIRTypes.td
index 7adef6b..ced993e 100644
--- a/include/flang/Optimizer/Dialect/FIRTypes.td
+++ b/include/flang/Optimizer/Dialect/FIRTypes.td
@@ -44,6 +44,25 @@
   let genVerifyInvariantsDecl = 1;
 }
 
+def fir_FieldType : FIR_Type<"Field", "field"> {
+  let summary = "A field (in a RecordType) argument's type";
+
+  let description = [{
+    The type of a field name. Implementations may defer the layout of a Fortran
+    derived type until runtime. This implies that the runtime must be able to
+    determine the offset of fields within the entity.
+  }];
+
+  let printer = [{
+    $_printer << "field";
+  }];
+
+  let parser = [{
+    return get(context);
+  }];
+
+}
+
 def ShapeType : FIR_Type<"Shape", "shape"> {
   let summary = "shape of a multidimensional array object";
 
diff --git a/lib/Optimizer/Dialect/FIRType.cpp b/lib/Optimizer/Dialect/FIRType.cpp
index 35e71a7..4001169 100644
--- a/lib/Optimizer/Dialect/FIRType.cpp
+++ b/lib/Optimizer/Dialect/FIRType.cpp
@@ -99,11 +99,6 @@
   return parseRankSingleton<SliceType>(parser);
 }
 
-// `field`
-FieldType parseField(mlir::DialectAsmParser &parser) {
-  return FieldType::get(parser.getBuilder().getContext());
-}
-
 // `heap` `<` type `>`
 HeapType parseHeap(mlir::DialectAsmParser &parser, mlir::Location loc) {
   return parseTypeSingleton<HeapType>(parser, loc);
@@ -344,7 +339,7 @@
   if (typeNameLit == "complex")
     return parseComplex(parser);
   if (typeNameLit == "field")
-    return parseField(parser);
+    return generatedTypeParser(dialect->getContext(), parser, typeNameLit);
   if (typeNameLit == "heap")
     return parseHeap(parser, loc);
   if (typeNameLit == "int")
@@ -439,25 +434,6 @@
   explicit SliceTypeStorage(unsigned rank) : rank{rank} {}
 };
 
-/// The type of a derived type part reference
-struct FieldTypeStorage : public mlir::TypeStorage {
-  using KeyTy = KindTy;
-
-  static unsigned hashKey(const KeyTy &) { return llvm::hash_combine(0); }
-
-  bool operator==(const KeyTy &) const { return true; }
-
-  static FieldTypeStorage *construct(mlir::TypeStorageAllocator &allocator,
-                                     KindTy) {
-    auto *storage = allocator.allocate<FieldTypeStorage>();
-    return new (storage) FieldTypeStorage{0};
-  }
-
-private:
-  FieldTypeStorage() = delete;
-  explicit FieldTypeStorage(KindTy) {}
-};
-
 /// The type of a derived type LEN parameter reference
 struct LenTypeStorage : public mlir::TypeStorage {
   using KeyTy = KindTy;
@@ -909,12 +885,6 @@
   return getImpl()->getLen();
 }
 
-// Field
-
-FieldType fir::FieldType::get(mlir::MLIRContext *ctxt) {
-  return Base::get(ctxt, 0);
-}
-
 // Len
 
 LenType fir::LenType::get(mlir::MLIRContext *ctxt) {
@@ -1332,10 +1302,6 @@
     os << "slice<" << type.getRank() << '>';
     return;
   }
-  if (ty.isa<FieldType>()) {
-    os << "field";
-    return;
-  }
   if (auto type = ty.dyn_cast<HeapType>()) {
     os << "heap<";
     p.printType(type.getEleTy());