13#ifndef FORTRAN_OPTIMIZER_DIALECT_FIRTYPE_H
14#define FORTRAN_OPTIMIZER_DIALECT_FIRTYPE_H
16#include "mlir/IR/BuiltinAttributes.h"
17#include "mlir/IR/BuiltinTypes.h"
18#include "mlir/Interfaces/DataLayoutInterfaces.h"
19#include "llvm/ADT/SmallVector.h"
20#include "llvm/IR/Type.h"
25using KindTy = unsigned;
42 using mlir::Type::Type;
45 enum class Attribute { None, Allocatable, Pointer };
59 mlir::Type getElementOrSequenceType()
const;
88 bool polymorphic)
const;
94 static bool classof(mlir::Type type);
99#define GET_TYPEDEF_CLASSES
100#include "flang/Optimizer/Dialect/FIROpsTypes.h.inc"
111class DialectAsmParser;
112class DialectAsmPrinter;
120struct RecordTypeStorage;
136 return mlir::isa<fir::ReferenceType, fir::PointerType, fir::HeapType,
137 fir::LLVMPointerType>(t);
142 return mlir::isa<fir::BaseBoxType, fir::BoxCharType, fir::BoxProcType>(t);
149 return mlir::isa<fir::ReferenceType, mlir::FunctionType>(t) ||
161inline bool isa_derived(mlir::Type t) {
return mlir::isa<fir::RecordType>(t); }
165 if (
auto recTy = mlir::dyn_cast_or_null<fir::RecordType>(t))
166 return recTy.getName().ends_with(
"T__builtin_c_ptr") ||
167 recTy.getName().ends_with(
"T__builtin_c_funptr") ||
168 recTy.getName().ends_with(
"T__builtin_c_devptr");
173inline bool isa_builtin_c_devptr_type(mlir::Type t) {
174 if (
auto recTy = mlir::dyn_cast_or_null<fir::RecordType>(t))
175 return recTy.getName().ends_with(
"T__builtin_c_devptr");
181 if (
auto recTy = mlir::dyn_cast_or_null<fir::RecordType>(t))
182 return recTy.getName().ends_with(
"T__builtin_c_devptr");
200inline bool isa_real(mlir::Type t) {
return mlir::isa<mlir::FloatType>(t); }
204 return mlir::isa<mlir::IndexType, mlir::IntegerType, fir::IntegerType>(t);
209 return mlir::isa<mlir::VectorType, fir::VectorType>(t);
212mlir::Type parseFirType(FIROpsDialect *, mlir::DialectAsmParser &parser);
214void printFirType(FIROpsDialect *, mlir::Type ty, mlir::DialectAsmPrinter &p);
222 return mlir::isa<mlir::ComplexType>(t) &&
223 mlir::isa<mlir::FloatType>(
224 mlir::cast<mlir::ComplexType>(t).getElementType());
228inline bool isa_char(mlir::Type t) {
return mlir::isa<fir::CharacterType>(t); }
234 mlir::isa<fir::LogicalType>(t);
239 if (
auto ct = mlir::dyn_cast_or_null<fir::CharacterType>(t))
240 return ct.getLen() != fir::CharacterType::singleton();
257 if (
auto charTy = mlir::dyn_cast<fir::CharacterType>(t))
258 return charTy.hasDynamicLen();
265 return seqTy.hasUnknownShape() || seqTy.hasDynamicExtents();
271inline unsigned getRankOfShapeType(mlir::Type t) {
272 if (
auto shTy = mlir::dyn_cast<fir::ShapeType>(t))
273 return shTy.getRank();
274 if (
auto shTy = mlir::dyn_cast<fir::ShapeShiftType>(t))
275 return shTy.getRank();
276 if (
auto shTy = mlir::dyn_cast<fir::ShiftType>(t))
277 return shTy.getRank();
284 if (!mlir::isa<fir::PointerType, fir::HeapType>(eleTy))
285 eleTy = fir::ReferenceType::get(t);
291 if (
auto seqTy = mlir::dyn_cast<fir::SequenceType>(t))
292 return seqTy.getEleTy();
299inline mlir::Type unwrapRefType(mlir::Type t) {
344 if (
auto seqTy = mlir::dyn_cast<fir::SequenceType>(t))
353 return mlir::dyn_cast<fir::RecordType>(
360 return recTy && recTy.getNumLenParams() > 0;
371inline bool singleIndirectionLevel(mlir::Type ty) {
446 if (
auto recTy = mlir::dyn_cast_or_null<fir::RecordType>(ty))
447 return recTy.isDependentType();
464mlir::Type
fromRealTypeID(mlir::MLIRContext *context, llvm::Type::TypeID typeID,
467int getTypeCode(mlir::Type ty,
const KindMapping &kindMap);
470 return mlir::isa<fir::BoxType, fir::ClassType>(type);
475 if (
auto seqTy = mlir::dyn_cast<fir::SequenceType>(type))
476 return mlir::isa<mlir::NoneType>(seqTy.getEleTy());
477 return mlir::isa<mlir::NoneType>(type);
483 bool isPolymorphic =
false,
485 unsigned corank = 0) {
487 return fir::ClassType::get(eleTy,
false, corank);
488 return fir::BoxType::get(eleTy,
false, corank);
502 if (
auto seqTy = mlir::dyn_cast<fir::SequenceType>(ty))
503 return fir::SequenceType::get(
505 if (
auto heapTy = mlir::dyn_cast<fir::HeapType>(ty))
506 return fir::HeapType::get(
508 if (
auto pointerTy = mlir::dyn_cast<fir::PointerType>(ty))
509 return fir::PointerType::get(
511 if (!mlir::isa<mlir::NoneType, fir::RecordType>(ty))
512 return mlir::NoneType::get(ty.getContext());
525 bool turnBoxIntoClass);
530 mlir::isa<fir::BaseBoxType>(fir::unwrapRefType(t));
535 return mlir::isa<fir::BaseBoxType>(fir::unwrapRefType(t));
541 return t && mlir::isa<fir::BoxProcType>(t);
544inline bool isRefOfConstantSizeAggregateType(mlir::Type t) {
547 mlir::isa<fir::CharacterType, fir::RecordType, fir::SequenceType>(t) &&
556 llvm::StringRef prefix =
"");
566std::pair<std::uint64_t, unsigned short>
568 const mlir::DataLayout &dl,
569 const fir::KindMapping &kindMap);
572std::optional<std::pair<uint64_t, unsigned short>>
574 const mlir::DataLayout &dl,
575 const fir::KindMapping &kindMap);
This class provides a shared interface for box and class types.
Definition FIRType.h:40
Attribute
Box attributes.
Definition FIRType.h:45
mlir::Type getBaseAddressType(bool dropHeapOrPtr=false) const
Definition FIRType.cpp:1470
BaseBoxType getBoxTypeWithNewAttr(Attribute attr) const
Return the same type, except for the attribute (fir.heap/fir.ptr).
Definition FIRType.cpp:1553
BaseBoxType getBoxTypeWithNewElementType(mlir::Type elementType, bool polymorphic) const
Definition FIRType.cpp:1546
bool isVolatile() const
Is this a box describing volatile memory?
Definition FIRType.cpp:1590
bool isPointer() const
Is this a box for a pointer?
Definition FIRType.cpp:1582
bool isAssumedRank() const
Is this the box for an assumed rank?
Definition FIRType.cpp:1575
mlir::Type unwrapInnerType() const
Unwrap element type from fir.heap, fir.ptr and fir.array.
Definition FIRType.cpp:1477
mlir::Type getEleTy() const
Returns the element type of this box type.
Definition FIRType.cpp:1464
bool isCoarray() const
Is this a box describing a coarray?
Definition FIRType.cpp:1596
bool isPointerOrAllocatable() const
Does this box for a pointer or allocatable?
Definition FIRType.cpp:1586
BaseBoxType getBoxTypeWithNewShape(mlir::Type shapeMold) const
Definition FIRType.cpp:1526
static bool classof(mlir::Type type)
Methods for support type inquiry through isa, cast, and dyn_cast.
Definition FIRType.h:469
bool isArray() const
Is this a box describing an array or assumed-rank?
Definition FIRType.cpp:1592
Definition KindMapping.h:48
Definition AbstractConverter.h:37
bool isa_box_type(mlir::Type t)
Is t a boxed type?
Definition FIRType.h:141
int getTypeCode(mlir::Type ty, const KindMapping &kindMap)
Return the ISO_C_BINDING intrinsic module value of type ty.
Definition FIRType.cpp:489
bool isScalarBoxedRecordType(mlir::Type ty)
Definition FIRType.cpp:352
mlir::Type applyPathToType(mlir::Type rootTy, mlir::ValueRange path)
Definition FIROps.cpp:6017
std::string getTypeAsString(mlir::Type ty, const KindMapping &kindMap, llvm::StringRef prefix="")
Definition FIRType.cpp:586
fir::SequenceType unwrapUntilSeqType(mlir::Type t)
Definition FIRType.h:336
bool sequenceWithNonConstantShape(fir::SequenceType seqTy)
Definition FIRType.h:264
bool isa_ref_type(mlir::Type t)
Is t a FIR dialect type that implies a memory (de)reference?
Definition FIRType.h:135
bool isBoxAddressOrValue(mlir::Type t)
Is t a fir.box or class address or value type?
Definition FIRType.h:534
bool conformsWithPassByRef(mlir::Type t)
Definition FIRType.h:156
bool isa_volatile_type(mlir::Type t)
Definition FIRType.cpp:760
bool isa_builtin_cdevptr_type(mlir::Type t)
Is t type(c_devptr)?
Definition FIRType.h:180
mlir::Type updateTypeWithVolatility(mlir::Type type, bool isVolatile)
Definition FIRType.cpp:238
mlir::Type fromRealTypeID(mlir::MLIRContext *context, llvm::Type::TypeID typeID, fir::KindTy kind)
Convert llvm::Type::TypeID to mlir::Type.
Definition FIRType.cpp:1438
bool isUnlimitedPolymorphicType(mlir::Type ty)
Definition FIRType.cpp:412
bool isa_vector(mlir::Type t)
Is t a vector type?
Definition FIRType.h:208
mlir::Type unwrapPassByRefType(mlir::Type t)
Definition FIRType.h:307
bool isDerivedType(fir::BaseBoxType boxTy)
Return true iff boxTy wraps a fir::RecordType.
Definition FIRType.h:364
bool isa_char(mlir::Type t)
Is t a CHARACTER type? Does not check the length.
Definition FIRType.h:228
bool isBoxedRecordType(mlir::Type ty)
Definition FIRType.cpp:331
bool isBoxNone(mlir::Type ty)
Return true iff ty is !fir.box<none>.
Definition FIRType.cpp:325
mlir::Type unwrapSeqOrBoxedSeqType(mlir::Type ty)
Definition FIRType.cpp:464
bool isBoxAddress(mlir::Type t)
Is t an address to fir.box or class type?
Definition FIRType.h:528
mlir::Type updateTypeForUnlimitedPolymorphic(mlir::Type ty)
Definition FIRType.h:501
bool isa_derived(mlir::Type t)
Is t a derived (record) type?
Definition FIRType.h:161
bool isa_aggregate(mlir::Type t)
Is t a FIR dialect aggregate type?
Definition FIRType.h:187
bool isDerivedTypeWithLenParams(fir::BaseBoxType boxTy)
Return true iff boxTy wraps a fir::RecordType with length parameters.
Definition FIRType.h:358
bool isAssumedShape(mlir::Type ty)
Return true iff ty is the type of an assumed shape array.
Definition FIRType.cpp:379
bool isCharacterProcedureTuple(mlir::Type type, bool acceptRawFunc=true)
Is this tuple type holding a character function and its result length?
Definition FIRType.cpp:1420
mlir::Type dyn_cast_ptrEleTy(mlir::Type t)
Definition FIRType.cpp:251
mlir::Type getDerivedType(mlir::Type ty)
Return the nested RecordType if one if found. Return ty otherwise.
Definition FIRType.cpp:227
bool isa_fir_or_std_type(mlir::Type t)
Is t any of the FIR dialect or Standard dialect types?
Definition FIRType.cpp:220
mlir::Type getFortranElementType(mlir::Type ty)
Definition FIRType.cpp:459
bool isNoneOrSeqNone(mlir::Type type)
Return true iff ty is none or fir.array<none>.
Definition FIRType.h:474
std::optional< std::pair< uint64_t, unsigned short > > getTypeSizeAndAlignment(mlir::Location loc, mlir::Type ty, const mlir::DataLayout &dl, const fir::KindMapping &kindMap)
This variant returns std::nullopt if an unsupported type is passed.
Definition FIRType.cpp:1624
fir::RecordType unwrapIfDerived(fir::BaseBoxType boxTy)
Definition FIRType.h:352
bool boxHasAddendum(fir::BaseBoxType boxTy)
Definition FIRType.h:426
bool isRecordWithAllocatableMember(mlir::Type ty)
Return true iff ty is a RecordType with members that are allocatable.
Definition FIRType.cpp:420
unsigned getBoxRank(mlir::Type boxTy)
Get the rank from a !fir.box type.
Definition FIRType.cpp:475
bool isClassStarType(mlir::Type ty)
Return true if CLASS(*)
Definition FIRType.cpp:343
mlir::Type wrapInClassOrBoxType(mlir::Type eleTy, bool isPolymorphic=false, bool isAssumedType=false, unsigned corank=0)
Definition FIRType.h:482
mlir::Type dyn_cast_ptrOrBoxEleTy(mlir::Type t)
Definition FIRType.cpp:258
bool isPointerType(mlir::Type ty)
Definition FIRType.cpp:309
bool isTypeWithDescriptor(mlir::Type ty)
Return true iff ty is a type that contains descriptor information.
Definition FIRType.cpp:398
bool characterWithDynamicLen(mlir::Type t)
Returns true iff t is a fir.char type and has an unknown length.
Definition FIRType.h:256
bool isAllocatableType(mlir::Type ty)
Return true iff ty is the type of an ALLOCATABLE entity or value.
Definition FIRType.cpp:317
mlir::Type changeElementType(mlir::Type type, mlir::Type newElementType, bool turnBoxIntoClass)
Definition FIRType.cpp:723
bool isPolymorphicType(mlir::Type ty)
Definition FIRType.cpp:404
bool isa_builtin_cptr_type(mlir::Type t)
Is t type(c_ptr), type(c_funptr), or type(c_devptr)?
Definition FIRType.h:164
mlir::Type unwrapAllRefAndSeqType(mlir::Type ty)
Definition FIRType.cpp:448
unsigned getBoxCorank(mlir::Type boxTy)
Get the corank from a !fir.box type.
Definition FIRType.cpp:482
bool hasAbstractResult(mlir::FunctionType ty)
Definition FIRType.cpp:1428
bool isAllocatableOrPointerArray(mlir::Type ty)
Return true iff ty is the type of an allocatable array.
Definition FIRType.cpp:386
bool isa_integer(mlir::Type t)
Is t an integral type?
Definition FIRType.h:203
mlir::Type extractSequenceType(mlir::Type ty)
Return the nested sequence type if any.
Definition FIRType.cpp:297
bool isa_char_string(mlir::Type t)
Is t a CHARACTER type with a LEN other than 1?
Definition FIRType.h:238
bool isRecordWithDescriptorMember(mlir::Type ty)
Definition FIRType.cpp:434
bool isBoxProcAddressType(mlir::Type t)
Is this a fir.boxproc address type?
Definition FIRType.h:539
bool isa_std_type(mlir::Type t)
Is t any of the Standard dialect types?
Definition FIRType.cpp:216
bool isa_passbyref_type(mlir::Type t)
Definition FIRType.h:148
std::pair< std::uint64_t, unsigned short > getTypeSizeAndAlignmentOrCrash(mlir::Location loc, mlir::Type ty, const mlir::DataLayout &dl, const fir::KindMapping &kindMap)
This variant terminates the compilation if an unsupported type is passed.
Definition FIRType.cpp:1678
bool hasDynamicSize(mlir::Type t)
Returns true iff the type t does not have a constant size.
Definition FIRType.cpp:284
mlir::Type boxMemRefType(fir::BaseBoxType t)
Get the memory reference type of the data pointer from the box type,.
Definition FIRType.h:282
bool isRecordWithTypeParameters(mlir::Type ty)
Return true iff ty is a RecordType with type parameters.
Definition FIRType.h:445
bool isAssumedType(mlir::Type ty)
Definition FIRType.cpp:366
void verifyIntegralType(mlir::Type type)
Definition FIRType.cpp:738
bool isa_complex(mlir::Type t)
Is t a floating point complex type?
Definition FIRType.h:221
bool isa_fir_type(mlir::Type t)
Is t any of the FIR dialect types?
Definition FIRType.cpp:212
bool isa_trivial(mlir::Type t)
Definition FIRType.h:232
mlir::Type unwrapSequenceType(mlir::Type t)
If t is a SequenceType return its element type, otherwise return t.
Definition FIRType.h:290
bool isa_unknown_size_box(mlir::Type t)
Definition FIRType.cpp:750
bool isa_real(mlir::Type t)
Is t a real type?
Definition FIRType.h:200
Definition AbstractConverter.h:32
Derived type storage.
Definition FIRType.cpp:151