6#include "mlir/IR/BuiltinTypes.h"
21 builder(cgm.
getBuilder()), theCXXABI(cgm.getCXXABI()),
22 theABIInfo(cgm.getTargetCIRGenInfo().
getABIInfo()) {}
25 for (
auto i = functionInfos.begin(), e = functionInfos.end(); i != e;)
30 return *builder.getContext();
50 return !
tagType->isIncompleteType();
62 if (
const auto *fpt = dyn_cast<FunctionProtoType>(ft))
63 for (
unsigned i = 0, e = fpt->getNumParams(); i != e; i++)
70mlir::Type CIRGenTypes::convertFunctionTypeInternal(
QualType qft) {
83 if (
const auto *fpt = dyn_cast<FunctionProtoType>(ft)) {
102 llvm::raw_svector_ostream outStream(typeName);
113 .
print(outStream, policy);
117 outStream << builder.getUniqueAnonRecordName();
122 return builder.getUniqueRecordName(std::string(typeName));
127 const auto it = recordDeclTypes.find(ty);
128 return it != recordDeclTypes.end() && it->second.isComplete();
135 llvm::SmallPtrSetImpl<const RecordDecl *> &alreadyChecked);
142 llvm::SmallPtrSetImpl<const RecordDecl *> &alreadyChecked) {
145 if (!alreadyChecked.insert(rd).second)
149 "Expect RecordDecl to be CompleteDefinition");
170 if (
const CXXRecordDecl *crd = dyn_cast<CXXRecordDecl>(rd)) {
173 ->castAs<RecordType>()
175 ->getDefinitionOrSelf(),
176 cgt, alreadyChecked))
198 llvm::SmallPtrSetImpl<const RecordDecl *> &alreadyChecked) {
201 qt = at->getValueType();
234 return astContext.getTypeSize(
type) !=
235 astContext.getTypeSize(
type->getValueType());
242 const Type *key = astContext.getCanonicalTagType(rd).getTypePtr();
250 entry = builder.getIncompleteRecordTy(name, rd);
251 recordDeclTypes[key] = entry;
260 deferredRecords.push_back(rd);
265 bool insertResult = recordsBeingLaidOut.insert(key).second;
267 assert(insertResult &&
"isSafeToCovert() should have caught this.");
270 safeToConvertCache.clear();
273 if (
const auto *
cxxRecordDecl = dyn_cast<CXXRecordDecl>(rd)) {
275 if (base.isVirtual())
283 recordDeclTypes[key] = entry;
284 cirGenRecordLayouts[key] = std::move(layout);
287 bool eraseResult = recordsBeingLaidOut.erase(key);
289 assert(eraseResult &&
"record not in RecordsBeingLaidOut set?");
292 safeToConvertCache.clear();
296 if (recordsBeingLaidOut.empty())
297 while (!deferredRecords.empty())
304 type = astContext.getCanonicalType(
type);
312 TypeCacheTy::iterator tci =
typeCache.find(ty);
319 mlir::Type resultType =
nullptr;
322 llvm_unreachable(
"Should have been handled above");
324 case Type::Builtin: {
327 case BuiltinType::Void:
328 resultType = cgm.voidTy;
332 case BuiltinType::Bool:
337 case BuiltinType::Char_S:
338 case BuiltinType::Int:
339 case BuiltinType::Int128:
340 case BuiltinType::Long:
341 case BuiltinType::LongLong:
342 case BuiltinType::SChar:
343 case BuiltinType::Short:
344 case BuiltinType::WChar_S:
345 case BuiltinType::Accum:
346 case BuiltinType::Fract:
347 case BuiltinType::LongAccum:
348 case BuiltinType::LongFract:
349 case BuiltinType::ShortAccum:
350 case BuiltinType::ShortFract:
352 case BuiltinType::SatAccum:
353 case BuiltinType::SatFract:
354 case BuiltinType::SatLongAccum:
355 case BuiltinType::SatLongFract:
356 case BuiltinType::SatShortAccum:
357 case BuiltinType::SatShortFract:
364 case BuiltinType::SveInt8:
366 cir::VectorType::get(builder.getSInt8Ty(), 16,
true);
368 case BuiltinType::SveUint8:
370 cir::VectorType::get(builder.getUInt8Ty(), 16,
true);
372 case BuiltinType::SveInt16:
374 cir::VectorType::get(builder.getSInt16Ty(), 8,
true);
376 case BuiltinType::SveUint16:
378 cir::VectorType::get(builder.getUInt16Ty(), 8,
true);
380 case BuiltinType::SveFloat16:
381 resultType = cir::VectorType::get(builder.getFp16Ty(), 8,
384 case BuiltinType::SveBFloat16:
385 resultType = cir::VectorType::get(builder.getFp16Ty(), 8,
388 case BuiltinType::SveInt32:
390 cir::VectorType::get(builder.getSInt32Ty(), 4,
true);
392 case BuiltinType::SveUint32:
394 cir::VectorType::get(builder.getUInt32Ty(), 4,
true);
396 case BuiltinType::SveFloat32:
397 resultType = cir::VectorType::get(builder.getSingleTy(), 4,
400 case BuiltinType::SveInt64:
402 cir::VectorType::get(builder.getSInt64Ty(), 2,
true);
404 case BuiltinType::SveUint64:
406 cir::VectorType::get(builder.getUInt64Ty(), 2,
true);
408 case BuiltinType::SveFloat64:
409 resultType = cir::VectorType::get(builder.getDoubleTy(), 2,
412 case BuiltinType::SveBool:
413 resultType = cir::VectorType::get(builder.getUIntNTy(1), 16,
418 case BuiltinType::Char8:
419 case BuiltinType::Char16:
420 case BuiltinType::Char32:
421 case BuiltinType::Char_U:
422 case BuiltinType::UChar:
423 case BuiltinType::UInt:
424 case BuiltinType::UInt128:
425 case BuiltinType::ULong:
426 case BuiltinType::ULongLong:
427 case BuiltinType::UShort:
428 case BuiltinType::WChar_U:
429 case BuiltinType::UAccum:
430 case BuiltinType::UFract:
431 case BuiltinType::ULongAccum:
432 case BuiltinType::ULongFract:
433 case BuiltinType::UShortAccum:
434 case BuiltinType::UShortFract:
436 case BuiltinType::SatUAccum:
437 case BuiltinType::SatUFract:
438 case BuiltinType::SatULongAccum:
439 case BuiltinType::SatULongFract:
440 case BuiltinType::SatUShortAccum:
441 case BuiltinType::SatUShortFract:
448 case BuiltinType::Float16:
449 resultType = cgm.fP16Ty;
451 case BuiltinType::Half:
452 if (astContext.getLangOpts().NativeHalfType ||
453 !astContext.getTargetInfo().useFP16ConversionIntrinsics()) {
454 resultType = cgm.fP16Ty;
457 resultType = cgm.sInt32Ty;
460 case BuiltinType::BFloat16:
461 resultType = cgm.bFloat16Ty;
463 case BuiltinType::MFloat8:
464 resultType = cgm.uInt8Ty;
466 case BuiltinType::Float:
467 assert(&astContext.getFloatTypeSemantics(
type) ==
468 &llvm::APFloat::IEEEsingle() &&
469 "ClangIR NYI: 'float' in a format other than IEEE 32-bit");
470 resultType = cgm.floatTy;
472 case BuiltinType::Double:
473 assert(&astContext.getFloatTypeSemantics(
type) ==
474 &llvm::APFloat::IEEEdouble() &&
475 "ClangIR NYI: 'double' in a format other than IEEE 64-bit");
476 resultType = cgm.doubleTy;
478 case BuiltinType::LongDouble:
480 builder.getLongDoubleTy(astContext.getFloatTypeSemantics(
type));
482 case BuiltinType::Float128:
483 resultType = cgm.fP128Ty;
485 case BuiltinType::Ibm128:
487 resultType = cgm.sInt32Ty;
490 case BuiltinType::NullPtr:
495 resultType = builder.getVoidPtrTy();
498#define AMDGPU_OPAQUE_PTR_TYPE(Name, Id, SingletonId, Width, Align, AS) \
499 case BuiltinType::Id: { \
500 if (BuiltinType::Id == BuiltinType::AMDGPUTexture) { \
501 resultType = cir::VectorType::get(builder.getSInt32Ty(), 8); \
503 resultType = builder.getPointerTo(cgm.voidTy); \
507#define AMDGPU_NAMED_BARRIER_TYPE(Name, Id, SingletonId, Width, Align, Scope) \
508 case BuiltinType::Id: \
509 llvm_unreachable("NYI");
510#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) \
511 case BuiltinType::Id: \
512 llvm_unreachable("NYI");
513#include "clang/Basic/AMDGPUTypes.def"
517 resultType = cgm.sInt32Ty;
523 case Type::Complex: {
525 mlir::Type elementTy =
convertType(ct->getElementType());
526 resultType = cir::ComplexType::get(elementTy);
530 case Type::LValueReference:
531 case Type::RValueReference: {
535 resultType = builder.getPointerTo(pointeeType, elemTy.
getAddressSpace());
536 assert(resultType &&
"Cannot get pointer type?");
540 case Type::Pointer: {
547 resultType = builder.getPointerTo(pointeeType, elemTy.
getAddressSpace());
551 case Type::VariableArray: {
561 case Type::IncompleteArray: {
570 elemTy = cgm.sInt8Ty;
573 resultType = cir::ArrayType::get(elemTy, 0);
577 case Type::ConstantArray: {
585 resultType = cir::ArrayType::get(elemTy, arrTy->
getSize().getZExtValue());
589 case Type::ExtVector:
599 if (
auto integerType = ed->getIntegerType(); !integerType.isNull())
604 resultType = cgm.uInt32Ty;
608 case Type::MemberPointer: {
612 auto clsTy = mlir::cast<cir::RecordType>(
614 if (mpt->isMemberDataPointer()) {
615 mlir::Type memberTy =
convertType(mpt->getPointeeType());
616 resultType = cir::DataMemberType::get(memberTy, clsTy);
618 auto memberFuncTy =
getFunctionType(cgm.getTypes().arrangeCXXMethodType(
622 resultType = cir::MethodType::get(memberFuncTy, clsTy);
627 case Type::FunctionNoProto:
628 case Type::FunctionProto:
629 resultType = convertFunctionTypeInternal(
type);
634 unsigned numBits = bitIntTy->getNumBits();
635 assert(numBits <= cir::IntType::maxBitwidth() &&
636 "_BitInt width exceeds CIR IntType maximum");
638 cir::IntType::get(&
getMLIRContext(), numBits, bitIntTy->isSigned(),
648 uint64_t valueSize = astContext.getTypeSize(valueType);
649 uint64_t atomicSize = astContext.getTypeSize(ty);
650 if (valueSize != atomicSize) {
651 assert(valueSize < atomicSize);
653 cir::ArrayType::get(cgm.sInt8Ty, (atomicSize - valueSize) / 8);
654 mlir::Type elements[] = {resultType, paddingArray};
665 type->getTypeClassName());
666 resultType = cgm.sInt32Ty;
670 assert(resultType &&
"Type conversion not yet implemented");
678 if (
qualType->isConstantMatrixType()) {
679 cgm.errorNYI(
"Matrix type conversion");
685 assert(!forBitField &&
"Bit fields NYI");
689 if (forBitField &&
qualType->isBitIntType())
690 assert(!
qualType->isBitIntType() &&
"Bit field with type _BitInt NYI");
692 return convertedType;
698 const auto *key = astContext.getCanonicalTagType(rd).getTypePtr();
701 auto it = cirGenRecordLayouts.find(key);
702 if (it != cirGenRecordLayouts.end())
709 it = cirGenRecordLayouts.find(key);
711 assert(it != cirGenRecordLayouts.end() &&
712 "Unable to find record layout information for type");
718 return astContext.getTargetNullPointerValue(t) == 0;
720 if (
const auto *at = astContext.getAsArrayType(t)) {
724 if (
const auto *cat = dyn_cast<ConstantArrayType>(at))
725 if (astContext.getConstantArrayElementCount(cat) == 0)
733 return theCXXABI.isZeroInitializable(mpt);
735 if (t->
getAs<HLSLInlineSpirvType>())
737 "isZeroInitializable for HLSLInlineSpirvType");
750 assert(llvm::all_of(argTypes,
753 llvm::FoldingSetNodeID id;
757 void *insertPos =
nullptr;
765 "Bad match based on CIRGenFunctionInfo folding set id");
774 functionInfos.InsertNode(fi, insertPos);
780 assert(!dyn_cast<ObjCMethodDecl>(gd.
getDecl()) &&
781 "This is reported as a FIXME in LLVM codegen");
797 if ([[maybe_unused]]
const auto *ed = dyn_cast<EnumDecl>(td)) {
805 ed->getASTContext().getCanonicalTagType(ed)->getTypePtr()) ||
807 typeCache[ed->getASTContext().getCanonicalTagType(ed)->getTypePtr()]));
817 if (rd->isDependentType())
822 if (recordDeclTypes.count(astContext.getCanonicalTagType(rd).getTypePtr()))
836 ? cgm.getDataLayout().getProgramAddressSpace()
Defines the clang::ASTContext interface.
static bool isSafeToConvert(QualType qt, CIRGenTypes &cgt, llvm::SmallPtrSetImpl< const RecordDecl * > &alreadyChecked)
Return true if it is safe to convert this field type, which requires the record elements contained by...
static Decl::Kind getKind(const Decl *D)
C Language Family Type Representation.
C++ view class that accepts both !cir.struct and !cir.union types.
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
CanQualType getCanonicalTagType(const TagDecl *TD) const
unsigned getTargetAddressSpace(LangAS AS) const
QualType getElementType() const
unsigned getIndexTypeCVRQualifiers() const
CanQualType getReturnType() const
const_arg_iterator argTypesEnd() const
static CIRGenFunctionInfo * create(FunctionType::ExtInfo info, bool instanceMethod, CanQualType resultType, llvm::ArrayRef< CanQualType > argTypes, RequiredArgs required)
static void Profile(llvm::FoldingSetNodeID &id, bool instanceMethod, FunctionType::ExtInfo info, RequiredArgs required, CanQualType resultType, llvm::ArrayRef< CanQualType > argTypes)
const_arg_iterator argTypesBegin() const
This class organizes the cross-function state that is used while generating CIR code.
bool isPaddedAtomicType(QualType type)
This class handles record and union layout info while lowering AST types to CIR types.
bool isZeroInitializable() const
Check whether this struct can be C++ zero-initialized with a zeroinitializer.
This class organizes the cross-module state that is used while lowering AST types to CIR types.
const CIRGenFunctionInfo & arrangeGlobalDeclaration(GlobalDecl gd)
unsigned getTargetAddressSpace(QualType ty) const
const CIRGenFunctionInfo & arrangeCXXStructorDeclaration(clang::GlobalDecl gd)
const CIRGenFunctionInfo & arrangeCIRFunctionInfo(CanQualType returnType, bool isInstanceMethod, llvm::ArrayRef< CanQualType > argTypes, FunctionType::ExtInfo info, RequiredArgs required)
const CIRGenFunctionInfo & arrangeFreeFunctionType(CanQual< FunctionProtoType > fpt)
bool isZeroInitializable(clang::QualType ty)
Return whether a type can be zero-initialized (in the C++ sense) with an LLVM zeroinitializer.
bool isFuncTypeConvertible(const clang::FunctionType *ft)
Utility to check whether a function type can be converted to a CIR type (i.e.
CIRGenTypes(CIRGenModule &cgm)
bool isRecordBeingLaidOut(const clang::Type *ty) const
CIRGenBuilderTy & getBuilder() const
mlir::MLIRContext & getMLIRContext() const
bool isCachedSafeToConvert(const clang::Type *key) const
Check if a record type key is in the safe-to-convert cache.
cir::FuncType getFunctionType(const CIRGenFunctionInfo &info)
Get the CIR function type for.
bool isFuncParamTypeConvertible(clang::QualType type)
Return true if the specified type in a function parameter or result position can be converted to a CI...
void updateCompletedType(const clang::TagDecl *td)
UpdateCompletedType - when we find the full definition for a TagDecl, replace the 'opaque' type we pr...
std::string getRecordTypeName(const clang::RecordDecl *, llvm::StringRef suffix)
bool noRecordsBeingLaidOut() const
const ABIInfo & getABIInfo() const
const CIRGenFunctionInfo & arrangeFunctionDeclaration(const clang::FunctionDecl *fd)
Free functions are functions that are compatible with an ordinary C function pointer type.
clang::ASTContext & getASTContext() const
bool isRecordLayoutComplete(const clang::Type *ty) const
Return true if the specified type is already completely laid out.
mlir::Type convertType(clang::QualType type)
Convert a Clang type into a mlir::Type.
const CIRGenRecordLayout & getCIRGenRecordLayout(const clang::RecordDecl *rd)
Return record layout info for the given record decl.
std::unique_ptr< CIRGenRecordLayout > computeRecordLayout(const clang::RecordDecl *rd, cir::RecordType *ty)
mlir::Type convertRecordDeclType(const clang::RecordDecl *recordDecl)
Lay out a tagged decl type like struct or union.
void cacheSafeToConvert(const clang::Type *key)
Add a record type key to the safe-to-convert cache.
mlir::Type convertTypeForMem(clang::QualType, bool forBitField=false)
Convert type T into an mlir::Type.
A class for recording the number of arguments that a function signature requires.
Represents a base class of a C++ class.
Represents a C++ struct/union/class.
static CanQual< T > CreateUnsafe(QualType Other)
Builds a canonical type from a QualType.
bool isCanonicalAsParam() const
Determines if this canonical type is furthermore canonical as a parameter.
const T * getTypePtr() const
Retrieve the underlying type pointer, which refers to a canonical type.
Represents the canonical version of C arrays with a specified constant size.
llvm::APInt getSize() const
Return the constant array size as an APInt.
Represents a member of a struct/union/class.
Represents a K&R-style 'int foo()' function, which has no information available about its arguments.
Represents a prototype with parameter type info, e.g.
A class which abstracts out some details necessary for making a call.
FunctionType - C99 6.7.5.3 - Function Declarators.
QualType getReturnType() const
GlobalDecl - represents a global declaration.
const Decl * getDecl() const
Represents a C array with an unspecified size.
A pointer to member type per C++ 8.3.3 - Pointers to members.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
CXXRecordDecl * getAsRecordDecl() const
Retrieve the record declaration stored in this nested name specifier, or null.
const Type * getAsType() const
PointerType - C99 6.7.5.1 - Pointer Declarators.
QualType getPointeeType() const
A (possibly-)qualified type.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
LangAS getAddressSpace() const
Return the address space of this type.
void print(raw_ostream &OS, const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
bool hasAddressSpace() const
Check if this type has any address space qualifier.
Represents a struct/union/class.
field_range fields() const
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
Base for LValueReferenceType and RValueReferenceType.
QualType getPointeeType() const
Encodes a location in the source.
Represents the declaration of a struct/union/class/enum.
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
The base class of the type hierarchy.
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
bool isConstantMatrixType() const
EnumDecl * castAsEnumDecl() const
bool isFunctionType() const
TypeClass getTypeClass() const
const T * getAs() const
Member-template getAs<specific type>'.
Represents a C array with a specified size that is not an integer-constant-expression.
Represents a GCC generic vector type.
unsigned getNumElements() const
QualType getElementType() const
Defines the clang::TargetInfo interface.
bool isSized(mlir::Type ty)
Returns true if the type is a CIR sized type.
@ Type
The l-value was considered opaque, so the alignment was determined from a type.
const internal::VariadicDynCastAllOfMatcher< Decl, TypedefNameDecl > typedefNameDecl
Matches typedef name declarations.
const AstTypeMatcher< TagType > tagType
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const AstTypeMatcher< RecordType > recordType
const internal::VariadicDynCastAllOfMatcher< Decl, CXXRecordDecl > cxxRecordDecl
Matches C++ class declarations.
const internal::VariadicDynCastAllOfMatcher< Decl, RecordDecl > recordDecl
Matches class, struct, and union declarations.
const internal::VariadicAllOfMatcher< QualType > qualType
Matches QualTypes in the clang AST.
The JSON file list parser is used to communicate input to InstallAPI.
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
bool isa(CodeGen::Address addr)
bool isInstanceMethod(const Decl *D)
U cast(CodeGen::Address addr)
static bool opCallCallConv()
static bool generateDebugInfo()
Describes how types, statements, expressions, and declarations should be printed.
unsigned SuppressTagKeyword
Whether type printing should skip printing the tag keyword.
unsigned AlwaysIncludeTypeForTemplateArgument
Whether to use type suffixes (eg: 1U) on integral non-type template parameters.
unsigned SuppressInlineNamespace
Suppress printing parts of scope specifiers that correspond to inline namespaces.
unsigned PrintAsCanonical
Whether to print entities as written or canonically.