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 @@ -34,8 +34,6 @@ // Fortran intrinsic types def fir_CharacterType : Type()">, "FIR character type">; -def fir_ComplexType : Type()">, - "FIR complex type">; def fir_IntegerType : Type()">, "FIR integer type">; def fir_LogicalType : Type()">, @@ -64,7 +62,7 @@ // Composable types def AnyCompositeLike : TypeConstraint, "any composite">; // Reference to an entity type @@ -2359,7 +2357,7 @@ the standard dialect. }]; - let results = (outs fir_ComplexType); + let results = (outs ComplexType); let parser = [{ fir::RealAttr realp; @@ -2406,13 +2404,13 @@ class ComplexUnaryArithmeticOp traits = []> : fir_UnaryArithmeticOp, - Arguments<(ins fir_ComplexType:$operand)>; + Arguments<(ins ComplexType:$operand)>; def fir_NegcOp : ComplexUnaryArithmeticOp<"negc">; class ComplexArithmeticOp traits = []> : fir_ArithmeticOp, - Arguments<(ins fir_ComplexType:$lhs, fir_ComplexType:$rhs)>; + Arguments<(ins ComplexType:$lhs, ComplexType:$rhs)>; def fir_AddcOp : ComplexArithmeticOp<"addc", [Commutative]>; def fir_SubcOp : ComplexArithmeticOp<"subc">; @@ -2428,7 +2426,7 @@ A complex comparison to handle complex types found in FIR. }]; - let arguments = (ins fir_ComplexType:$lhs, fir_ComplexType:$rhs); + let arguments = (ins ComplexType:$lhs, ComplexType:$rhs); let results = (outs AnyLogicalLike); 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 @@ -45,7 +45,6 @@ struct BoxCharTypeStorage; struct BoxProcTypeStorage; struct CharacterTypeStorage; -struct ComplexTypeStorage; struct FieldTypeStorage; struct HeapTypeStorage; struct IntegerTypeStorage; @@ -130,21 +129,6 @@ LenType getLen() const; }; -/// 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":$kind); + + let printer = [{ + $_printer << "complex<" << getFKind() << '>'; + }]; + + let genAccessors = 1; + + let extraClassDeclaration = [{ + using KindTy = unsigned; + + KindTy getFKind() const { return getKind(); } + + mlir::Type getElementType() const; + }]; +} + def ShapeType : FIR_Type<"Shape", "shape"> { let summary = "shape of a multidimensional array object"; 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 @@ -89,11 +89,6 @@ return CharacterType::get(parser.getBuilder().getContext(), kind, len); } -// `complex` `<` kind `>` -fir::ComplexType parseComplex(mlir::DialectAsmParser &parser) { - return parseKindSingleton(parser); -} - // `slice` `<` rank `>` SliceType parseSlice(mlir::DialectAsmParser &parser) { return parseRankSingleton(parser); @@ -342,7 +337,7 @@ if (typeNameLit == "char") return parseCharacter(parser); if (typeNameLit == "complex") - return parseComplex(parser); + return generatedTypeParser(dialect->getContext(), parser, typeNameLit); if (typeNameLit == "field") return parseField(parser); if (typeNameLit == "heap") @@ -525,30 +520,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; @@ -937,18 +908,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) { @@ -1295,11 +1254,6 @@ os << '>'; return; } - 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(); @@ -1460,4 +1414,17 @@ printer << '>'; } +//===----------------------------------------------------------------------===// +// ComplexType +//===----------------------------------------------------------------------===// + +mlir::Type ComplexType::parse(mlir::MLIRContext *context, + mlir::DialectAsmParser &parser) { + return parseKindSingleton(parser); +} + +mlir::Type ComplexType::getElementType() const { + return fir::RealType::get(getContext(), getFKind()); +} + } // namespace fir