[flang-commits] [flang] ceff415 - [flang] Introduce BaseBoxType
Valentin Clement via flang-commits
flang-commits at lists.llvm.org
Sun Oct 2 11:09:13 PDT 2022
Author: Valentin Clement
Date: 2022-10-02T20:08:54+02:00
New Revision: ceff415a1a19dc7039965437382d3f36cb94f08e
URL: https://github.com/llvm/llvm-project/commit/ceff415a1a19dc7039965437382d3f36cb94f08e
DIFF: https://github.com/llvm/llvm-project/commit/ceff415a1a19dc7039965437382d3f36cb94f08e.diff
LOG: [flang] Introduce BaseBoxType
Introduce a BaseBoxType to be used by BoxType and
the a new ClassType that is introduced in a follow up patch.
This patch is part of the implementation of the poltymorphic
entities.
https://github.com/llvm/llvm-project/blob/main/flang/docs/PolymorphicEntities.md
Reviewed By: PeteSteinfeld
Differential Revision: https://reviews.llvm.org/D134956
Added:
Modified:
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/FIRType.h b/flang/include/flang/Optimizer/Dialect/FIRType.h
index 067a04976a50f..304a5267bcdf1 100644
--- a/flang/include/flang/Optimizer/Dialect/FIRType.h
+++ b/flang/include/flang/Optimizer/Dialect/FIRType.h
@@ -24,6 +24,26 @@ class KindMapping;
using KindTy = unsigned;
} // namespace fir
+//===----------------------------------------------------------------------===//
+// BaseBoxType
+//===----------------------------------------------------------------------===//
+
+namespace fir {
+
+/// This class provides a shared interface for box and class types.
+class BaseBoxType : public mlir::Type {
+public:
+ using mlir::Type::Type;
+
+ /// Returns the element type of this box type.
+ mlir::Type getEleTy() const;
+
+ /// Methods for support type inquiry through isa, cast, and dyn_cast.
+ static bool classof(mlir::Type type);
+};
+
+} // namespace fir
+
#define GET_TYPEDEF_CLASSES
#include "flang/Optimizer/Dialect/FIROpsTypes.h.inc"
@@ -283,6 +303,10 @@ bool hasAbstractResult(mlir::FunctionType ty);
mlir::Type fromRealTypeID(mlir::MLIRContext *context, llvm::Type::TypeID typeID,
fir::KindTy kind);
+inline bool BaseBoxType::classof(mlir::Type type) {
+ return type.isa<fir::BoxType>();
+}
+
} // namespace fir
#endif // FORTRAN_OPTIMIZER_DIALECT_FIRTYPE_H
diff --git a/flang/include/flang/Optimizer/Dialect/FIRTypes.td b/flang/include/flang/Optimizer/Dialect/FIRTypes.td
index de310a9972ac3..d5e47b4018d6d 100644
--- a/flang/include/flang/Optimizer/Dialect/FIRTypes.td
+++ b/flang/include/flang/Optimizer/Dialect/FIRTypes.td
@@ -20,7 +20,9 @@ include "flang/Optimizer/Dialect/FIRDialect.td"
// FIR Types
//===----------------------------------------------------------------------===//
-class FIR_Type<string name, string typeMnemonic> : TypeDef<fir_Dialect, name> {
+class FIR_Type<string name, string typeMnemonic, list<Trait> traits = [],
+ string baseCppClass = "::mlir::Type">
+ : TypeDef<fir_Dialect, name, traits, baseCppClass> {
let mnemonic = typeMnemonic;
}
@@ -66,7 +68,7 @@ def fir_BoxProcType : FIR_Type<"BoxProc", "boxproc"> {
let hasCustomAssemblyFormat = 1;
}
-def fir_BoxType : FIR_Type<"Box", "box"> {
+def fir_BoxType : FIR_Type<"Box", "box", [], "BaseBoxType"> {
let summary = "The type of a Fortran descriptor";
let description = [{
diff --git a/flang/lib/Optimizer/Dialect/FIRType.cpp b/flang/lib/Optimizer/Dialect/FIRType.cpp
index 2fb542582bccb..0a01a65ab1b4d 100644
--- a/flang/lib/Optimizer/Dialect/FIRType.cpp
+++ b/flang/lib/Optimizer/Dialect/FIRType.cpp
@@ -924,6 +924,15 @@ mlir::Type fir::fromRealTypeID(mlir::MLIRContext *context,
}
}
+//===----------------------------------------------------------------------===//
+// BaseBoxType
+//===----------------------------------------------------------------------===//
+
+mlir::Type BaseBoxType::getEleTy() const {
+ return llvm::TypeSwitch<fir::BaseBoxType, mlir::Type>(*this)
+ .Case<fir::BoxType>([](auto type) { return type.getEleTy(); });
+}
+
//===----------------------------------------------------------------------===//
// FIROpsDialect
//===----------------------------------------------------------------------===//
More information about the flang-commits
mailing list