[flang-commits] [flang] 5ef029d - [flang][fir][NFC] Move ComplexType to TableGen type definition
via flang-commits
flang-commits at lists.llvm.org
Tue Feb 16 18:52:47 PST 2021
Author: Valentin Clement
Date: 2021-02-16T21:52:38-05:00
New Revision: 5ef029d2671914ee8065a878a076eee1caae9ab1
URL: https://github.com/llvm/llvm-project/commit/5ef029d2671914ee8065a878a076eee1caae9ab1
DIFF: https://github.com/llvm/llvm-project/commit/5ef029d2671914ee8065a878a076eee1caae9ab1.diff
LOG: [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
Added:
Modified:
flang/include/flang/Optimizer/Dialect/FIROps.td
flang/include/flang/Optimizer/Dialect/FIRType.h
flang/include/flang/Optimizer/Dialect/FIRTypes.td
flang/lib/Optimizer/Dialect/FIRType.cpp
Removed:
################################################################################
diff --git a/flang/include/flang/Optimizer/Dialect/FIROps.td b/flang/include/flang/Optimizer/Dialect/FIROps.td
index c628371c4971..afc1fa5994ea 100644
--- a/flang/include/flang/Optimizer/Dialect/FIROps.td
+++ b/flang/include/flang/Optimizer/Dialect/FIROps.td
@@ -33,8 +33,6 @@ def fir_Type : Type<CPred<"fir::isa_fir_or_std_type($_self)">,
"FIR dialect type">;
// Fortran intrinsic types
-def fir_ComplexType : Type<CPred<"$_self.isa<fir::ComplexType>()">,
- "FIR complex type">;
def fir_IntegerType : Type<CPred<"$_self.isa<fir::IntegerType>()">,
"FIR integer type">;
def fir_LogicalType : Type<CPred<"$_self.isa<fir::LogicalType>()">,
diff --git a/flang/include/flang/Optimizer/Dialect/FIRType.h b/flang/include/flang/Optimizer/Dialect/FIRType.h
index f23c075026e4..7198a98837d5 100644
--- a/flang/include/flang/Optimizer/Dialect/FIRType.h
+++ b/flang/include/flang/Optimizer/Dialect/FIRType.h
@@ -42,7 +42,6 @@ class FIROpsDialect;
using KindTy = unsigned;
namespace detail {
-struct ComplexTypeStorage;
struct HeapTypeStorage;
struct IntegerTypeStorage;
struct LenTypeStorage;
@@ -95,21 +94,6 @@ mlir::Type dyn_cast_ptrEleTy(mlir::Type t);
// 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<fir::ComplexType, mlir::Type,
- detail::ComplexTypeStorage> {
-public:
- using Base::Base;
- static fir::ComplexType get(mlir::MLIRContext *ctxt, KindTy kind);
-
- /// Get the corresponding fir.real<k> 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<fir::IntegerType, mlir::Type,
diff --git a/flang/include/flang/Optimizer/Dialect/FIRTypes.td b/flang/include/flang/Optimizer/Dialect/FIRTypes.td
index 28b388115639..75bf89fa16e4 100644
--- a/flang/include/flang/Optimizer/Dialect/FIRTypes.td
+++ b/flang/include/flang/Optimizer/Dialect/FIRTypes.td
@@ -83,7 +83,30 @@ def fir_FieldType : FIR_Type<"Field", "field"> {
let parser = [{
return get(context);
}];
+}
+
+def fir_ComplexType : FIR_Type<"Complex", "complex"> {
+ 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
index 4889fa11056f..77a6d95e7406 100644
--- a/flang/lib/Optimizer/Dialect/FIRType.cpp
+++ b/flang/lib/Optimizer/Dialect/FIRType.cpp
@@ -58,11 +58,6 @@ TYPE parseTypeSingleton(mlir::DialectAsmParser &parser, mlir::Location) {
return TYPE::get(ty);
}
-// `complex` `<` kind `>`
-fir::ComplexType parseComplex(mlir::DialectAsmParser &parser) {
- return parseKindSingleton<fir::ComplexType>(parser);
-}
-
// `slice` `<` rank `>`
SliceType parseSlice(mlir::DialectAsmParser &parser) {
return parseRankSingleton<SliceType>(parser);
@@ -309,7 +304,7 @@ mlir::Type fir::parseFirType(FIROpsDialect *dialect,
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 @@ struct IntegerTypeStorage : public mlir::TypeStorage {
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<ComplexTypeStorage>();
- 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 @@ fir::IntegerType fir::IntegerType::get(mlir::MLIRContext *ctxt, KindTy kind) {
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::verifyIntegralType(mlir::Type type) {
void fir::printFirType(FIROpsDialect *, mlir::Type ty,
mlir::DialectAsmPrinter &p) {
auto &os = p.getStream();
- if (auto type = ty.dyn_cast<fir::ComplexType>()) {
- // Fortran intrinsic type COMPLEX
- os << "complex<" << type.getFKind() << '>';
- return;
- }
if (auto type = ty.dyn_cast<RecordType>()) {
// Fortran derived type
os << "type<" << type.getName();
@@ -1328,3 +1282,16 @@ void fir::CharacterType::print(::mlir::DialectAsmPrinter &printer) const {
}
printer << '>';
}
+
+//===----------------------------------------------------------------------===//
+// ComplexType
+//===----------------------------------------------------------------------===//
+
+mlir::Type fir::ComplexType::parse(mlir::MLIRContext *context,
+ mlir::DialectAsmParser &parser) {
+ return parseKindSingleton<fir::ComplexType>(parser);
+}
+
+mlir::Type fir::ComplexType::getElementType() const {
+ return fir::RealType::get(getContext(), getFKind());
+}
More information about the flang-commits
mailing list