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 @@ -33,8 +33,6 @@ "FIR dialect type">; // Fortran intrinsic types -def fir_ComplexType : Type()">, - "FIR complex type">; def fir_IntegerType : Type()">, "FIR integer type">; def fir_LogicalType : 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 @@ -42,7 +42,6 @@ using KindTy = unsigned; namespace detail { -struct ComplexTypeStorage; struct HeapTypeStorage; struct IntegerTypeStorage; struct LenTypeStorage; @@ -95,21 +94,6 @@ // Intrinsic types -/// Model of a Fortran COMPLEX intrinsic type, including the KIND type -/// parameter. COMPLEX is a floating point type with a real and imaginary -/// member. -class ComplexType : public mlir::Type::TypeBase { -public: - using Base::Base; - static fir::ComplexType get(mlir::MLIRContext *ctxt, KindTy kind); - - /// Get the corresponding fir.real type. - mlir::Type getElementType() const; - - KindTy getFKind() const; -}; - /// Model of a Fortran INTEGER intrinsic type, including the KIND type /// parameter. class IntegerType : public mlir::Type::TypeBase { + let summary = "Complex type"; + + let description = [{ + Model of a Fortran COMPLEX intrinsic type, including the KIND type + parameter. COMPLEX is a floating point type with a real and imaginary + member. + }]; + + let parameters = (ins "KindTy":$fKind); + let printer = [{ + $_printer << "complex<" << getFKind() << '>'; + }]; + + let genAccessors = 1; + + let extraClassDeclaration = [{ + using KindTy = unsigned; + + mlir::Type getElementType() const; + }]; } def ShapeType : FIR_Type<"Shape", "shape"> { 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); } -// `complex` `<` kind `>` -fir::ComplexType parseComplex(mlir::DialectAsmParser &parser) { - return parseKindSingleton(parser); -} - // `slice` `<` rank `>` SliceType parseSlice(mlir::DialectAsmParser &parser) { return parseRankSingleton(parser); @@ -309,7 +304,7 @@ if (typeNameLit == "char") return generatedTypeParser(dialect->getContext(), parser, typeNameLit); if (typeNameLit == "complex") - return parseComplex(parser); + return generatedTypeParser(dialect->getContext(), parser, typeNameLit); if (typeNameLit == "field") return generatedTypeParser(dialect->getContext(), parser, typeNameLit); if (typeNameLit == "heap") @@ -440,30 +435,6 @@ explicit IntegerTypeStorage(KindTy kind) : kind{kind} {} }; -/// `COMPLEX` storage -struct ComplexTypeStorage : public mlir::TypeStorage { - using KeyTy = KindTy; - - static unsigned hashKey(const KeyTy &key) { return llvm::hash_combine(key); } - - bool operator==(const KeyTy &key) const { return key == getFKind(); } - - static ComplexTypeStorage *construct(mlir::TypeStorageAllocator &allocator, - KindTy kind) { - auto *storage = allocator.allocate(); - return new (storage) ComplexTypeStorage{kind}; - } - - KindTy getFKind() const { return kind; } - -protected: - KindTy kind; - -private: - ComplexTypeStorage() = delete; - explicit ComplexTypeStorage(KindTy kind) : kind{kind} {} -}; - /// `REAL` storage (for reals of unsupported sizes) struct RealTypeStorage : public mlir::TypeStorage { using KeyTy = KindTy; @@ -779,18 +750,6 @@ KindTy fir::IntegerType::getFKind() const { return getImpl()->getFKind(); } -// COMPLEX - -fir::ComplexType fir::ComplexType::get(mlir::MLIRContext *ctxt, KindTy kind) { - return Base::get(ctxt, kind); -} - -mlir::Type fir::ComplexType::getElementType() const { - return fir::RealType::get(getContext(), getFKind()); -} - -KindTy fir::ComplexType::getFKind() const { return getImpl()->getFKind(); } - // REAL RealType fir::RealType::get(mlir::MLIRContext *ctxt, KindTy kind) { @@ -1081,11 +1040,6 @@ void fir::printFirType(FIROpsDialect *, mlir::Type ty, mlir::DialectAsmPrinter &p) { auto &os = p.getStream(); - if (auto type = ty.dyn_cast()) { - // Fortran intrinsic type COMPLEX - os << "complex<" << type.getFKind() << '>'; - return; - } if (auto type = ty.dyn_cast()) { // Fortran derived type os << "type<" << type.getName(); @@ -1328,3 +1282,16 @@ } printer << '>'; } + +//===----------------------------------------------------------------------===// +// ComplexType +//===----------------------------------------------------------------------===// + +mlir::Type fir::ComplexType::parse(mlir::MLIRContext *context, + mlir::DialectAsmParser &parser) { + return parseKindSingleton(parser); +} + +mlir::Type fir::ComplexType::getElementType() const { + return fir::RealType::get(getContext(), getFKind()); +}