Skip to content

Commit 5ef029d

Browse files
committed
[flang][fir][NFC] Move ComplexType to TableGen type definition
This patch is a follow up of D96422 and move ComplexType to TableGen. Reviewed By: schweitz Differential Revision: https://reviews.llvm.org/D96575
1 parent 61b8a3e commit 5ef029d

File tree

4 files changed

+37
-65
lines changed

4 files changed

+37
-65
lines changed

flang/include/flang/Optimizer/Dialect/FIROps.td

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ def fir_Type : Type<CPred<"fir::isa_fir_or_std_type($_self)">,
3333
"FIR dialect type">;
3434

3535
// Fortran intrinsic types
36-
def fir_ComplexType : Type<CPred<"$_self.isa<fir::ComplexType>()">,
37-
"FIR complex type">;
3836
def fir_IntegerType : Type<CPred<"$_self.isa<fir::IntegerType>()">,
3937
"FIR integer type">;
4038
def fir_LogicalType : Type<CPred<"$_self.isa<fir::LogicalType>()">,

flang/include/flang/Optimizer/Dialect/FIRType.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ class FIROpsDialect;
4242
using KindTy = unsigned;
4343

4444
namespace detail {
45-
struct ComplexTypeStorage;
4645
struct HeapTypeStorage;
4746
struct IntegerTypeStorage;
4847
struct LenTypeStorage;
@@ -95,21 +94,6 @@ mlir::Type dyn_cast_ptrEleTy(mlir::Type t);
9594

9695
// Intrinsic types
9796

98-
/// Model of a Fortran COMPLEX intrinsic type, including the KIND type
99-
/// parameter. COMPLEX is a floating point type with a real and imaginary
100-
/// member.
101-
class ComplexType : public mlir::Type::TypeBase<fir::ComplexType, mlir::Type,
102-
detail::ComplexTypeStorage> {
103-
public:
104-
using Base::Base;
105-
static fir::ComplexType get(mlir::MLIRContext *ctxt, KindTy kind);
106-
107-
/// Get the corresponding fir.real<k> type.
108-
mlir::Type getElementType() const;
109-
110-
KindTy getFKind() const;
111-
};
112-
11397
/// Model of a Fortran INTEGER intrinsic type, including the KIND type
11498
/// parameter.
11599
class IntegerType : public mlir::Type::TypeBase<fir::IntegerType, mlir::Type,

flang/include/flang/Optimizer/Dialect/FIRTypes.td

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,30 @@ def fir_FieldType : FIR_Type<"Field", "field"> {
8383
let parser = [{
8484
return get(context);
8585
}];
86+
}
87+
88+
def fir_ComplexType : FIR_Type<"Complex", "complex"> {
89+
let summary = "Complex type";
90+
91+
let description = [{
92+
Model of a Fortran COMPLEX intrinsic type, including the KIND type
93+
parameter. COMPLEX is a floating point type with a real and imaginary
94+
member.
95+
}];
96+
97+
let parameters = (ins "KindTy":$fKind);
8698

99+
let printer = [{
100+
$_printer << "complex<" << getFKind() << '>';
101+
}];
102+
103+
let genAccessors = 1;
104+
105+
let extraClassDeclaration = [{
106+
using KindTy = unsigned;
107+
108+
mlir::Type getElementType() const;
109+
}];
87110
}
88111

89112
def ShapeType : FIR_Type<"Shape", "shape"> {

flang/lib/Optimizer/Dialect/FIRType.cpp

Lines changed: 14 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,6 @@ TYPE parseTypeSingleton(mlir::DialectAsmParser &parser, mlir::Location) {
5858
return TYPE::get(ty);
5959
}
6060

61-
// `complex` `<` kind `>`
62-
fir::ComplexType parseComplex(mlir::DialectAsmParser &parser) {
63-
return parseKindSingleton<fir::ComplexType>(parser);
64-
}
65-
6661
// `slice` `<` rank `>`
6762
SliceType parseSlice(mlir::DialectAsmParser &parser) {
6863
return parseRankSingleton<SliceType>(parser);
@@ -309,7 +304,7 @@ mlir::Type fir::parseFirType(FIROpsDialect *dialect,
309304
if (typeNameLit == "char")
310305
return generatedTypeParser(dialect->getContext(), parser, typeNameLit);
311306
if (typeNameLit == "complex")
312-
return parseComplex(parser);
307+
return generatedTypeParser(dialect->getContext(), parser, typeNameLit);
313308
if (typeNameLit == "field")
314309
return generatedTypeParser(dialect->getContext(), parser, typeNameLit);
315310
if (typeNameLit == "heap")
@@ -440,30 +435,6 @@ struct IntegerTypeStorage : public mlir::TypeStorage {
440435
explicit IntegerTypeStorage(KindTy kind) : kind{kind} {}
441436
};
442437

443-
/// `COMPLEX` storage
444-
struct ComplexTypeStorage : public mlir::TypeStorage {
445-
using KeyTy = KindTy;
446-
447-
static unsigned hashKey(const KeyTy &key) { return llvm::hash_combine(key); }
448-
449-
bool operator==(const KeyTy &key) const { return key == getFKind(); }
450-
451-
static ComplexTypeStorage *construct(mlir::TypeStorageAllocator &allocator,
452-
KindTy kind) {
453-
auto *storage = allocator.allocate<ComplexTypeStorage>();
454-
return new (storage) ComplexTypeStorage{kind};
455-
}
456-
457-
KindTy getFKind() const { return kind; }
458-
459-
protected:
460-
KindTy kind;
461-
462-
private:
463-
ComplexTypeStorage() = delete;
464-
explicit ComplexTypeStorage(KindTy kind) : kind{kind} {}
465-
};
466-
467438
/// `REAL` storage (for reals of unsupported sizes)
468439
struct RealTypeStorage : public mlir::TypeStorage {
469440
using KeyTy = KindTy;
@@ -779,18 +750,6 @@ fir::IntegerType fir::IntegerType::get(mlir::MLIRContext *ctxt, KindTy kind) {
779750

780751
KindTy fir::IntegerType::getFKind() const { return getImpl()->getFKind(); }
781752

782-
// COMPLEX
783-
784-
fir::ComplexType fir::ComplexType::get(mlir::MLIRContext *ctxt, KindTy kind) {
785-
return Base::get(ctxt, kind);
786-
}
787-
788-
mlir::Type fir::ComplexType::getElementType() const {
789-
return fir::RealType::get(getContext(), getFKind());
790-
}
791-
792-
KindTy fir::ComplexType::getFKind() const { return getImpl()->getFKind(); }
793-
794753
// REAL
795754

796755
RealType fir::RealType::get(mlir::MLIRContext *ctxt, KindTy kind) {
@@ -1081,11 +1040,6 @@ void fir::verifyIntegralType(mlir::Type type) {
10811040
void fir::printFirType(FIROpsDialect *, mlir::Type ty,
10821041
mlir::DialectAsmPrinter &p) {
10831042
auto &os = p.getStream();
1084-
if (auto type = ty.dyn_cast<fir::ComplexType>()) {
1085-
// Fortran intrinsic type COMPLEX
1086-
os << "complex<" << type.getFKind() << '>';
1087-
return;
1088-
}
10891043
if (auto type = ty.dyn_cast<RecordType>()) {
10901044
// Fortran derived type
10911045
os << "type<" << type.getName();
@@ -1328,3 +1282,16 @@ void fir::CharacterType::print(::mlir::DialectAsmPrinter &printer) const {
13281282
}
13291283
printer << '>';
13301284
}
1285+
1286+
//===----------------------------------------------------------------------===//
1287+
// ComplexType
1288+
//===----------------------------------------------------------------------===//
1289+
1290+
mlir::Type fir::ComplexType::parse(mlir::MLIRContext *context,
1291+
mlir::DialectAsmParser &parser) {
1292+
return parseKindSingleton<fir::ComplexType>(parser);
1293+
}
1294+
1295+
mlir::Type fir::ComplexType::getElementType() const {
1296+
return fir::RealType::get(getContext(), getFKind());
1297+
}

0 commit comments

Comments
 (0)