30#include "llvm/ADT/SmallString.h"
31#include "llvm/Support/ErrorHandling.h"
32#include "llvm/Support/raw_ostream.h"
42 llvm::DenseMap<const CXXRecordDecl *, cir::GlobalOp> vtables;
45 CIRGenItaniumCXXABI(CIRGenModule &cgm) : CIRGenCXXABI(cgm) {
50 AddedStructorArgs getImplicitConstructorArgs(CIRGenFunction &cgf,
51 const CXXConstructorDecl *d,
54 bool delegating)
override;
56 bool needsVTTParameter(clang::GlobalDecl gd)
override;
58 AddedStructorArgCounts
59 buildStructorSignature(GlobalDecl gd,
60 llvm::SmallVectorImpl<CanQualType> &argTys)
override;
62 void emitInstanceFunctionProlog(SourceLocation loc,
63 CIRGenFunction &cgf)
override;
65 void addImplicitStructorParams(CIRGenFunction &cgf, QualType &resTy,
66 FunctionArgList ¶ms)
override;
68 const CXXDestructorDecl *dd,
71 bool delegating)
override;
72 void emitCXXConstructors(
const clang::CXXConstructorDecl *d)
override;
73 void emitCXXDestructors(
const clang::CXXDestructorDecl *d)
override;
74 void emitCXXStructor(clang::GlobalDecl gd)
override;
76 void emitDestructorCall(CIRGenFunction &cgf,
const CXXDestructorDecl *dd,
78 bool delegating, Address thisAddr,
79 QualType thisTy)
override;
80 void registerGlobalDtor(
const VarDecl *vd, cir::FuncOp dtor,
81 mlir::Value addr)
override;
82 void emitVirtualObjectDelete(CIRGenFunction &cgf,
const CXXDeleteExpr *de,
83 Address ptr, QualType elementType,
84 const CXXDestructorDecl *dtor)
override;
86 void emitRethrow(CIRGenFunction &cgf,
bool isNoReturn)
override;
87 void emitThrow(CIRGenFunction &cgf,
const CXXThrowExpr *e)
override;
89 bool useThunkForDtorVariant(
const CXXDestructorDecl *dtor,
97 bool isVirtualOffsetNeededForVTableField(CIRGenFunction &cgf,
98 CIRGenFunction::VPtr vptr)
override;
100 cir::GlobalOp getAddrOfVTable(
const CXXRecordDecl *rd,
101 CharUnits vptrOffset)
override;
102 CIRGenCallee getVirtualFunctionPointer(CIRGenFunction &cgf,
103 clang::GlobalDecl gd, Address thisAddr,
105 SourceLocation loc)
override;
106 mlir::Value emitVirtualDestructorCall(CIRGenFunction &cgf,
107 const CXXDestructorDecl *dtor,
109 DeleteOrMemberCallExpr e)
override;
111 bool canSpeculativelyEmitVTable(
const CXXRecordDecl *RD)
const override;
112 bool canSpeculativelyEmitVTableAsBaseClass(
const CXXRecordDecl *RD)
const;
114 mlir::Value getVTableAddressPoint(BaseSubobject base,
115 const CXXRecordDecl *vtableClass)
override;
117 getVTableAddressPointAttr(BaseSubobject base,
118 const CXXRecordDecl *vtableClass)
override;
119 mlir::Value getVTableAddressPointInStructorWithVTT(
120 CIRGenFunction &cgf,
const CXXRecordDecl *vtableClass, BaseSubobject base,
121 const CXXRecordDecl *nearestVBase);
123 mlir::Value getVTableAddressPointInStructor(
124 CIRGenFunction &cgf,
const clang::CXXRecordDecl *vtableClass,
125 clang::BaseSubobject base,
126 const clang::CXXRecordDecl *nearestVBase)
override;
127 void emitVTableDefinitions(CIRGenVTables &cgvt,
128 const CXXRecordDecl *rd)
override;
129 void emitVirtualInheritanceTables(
const CXXRecordDecl *rd)
override;
131 void setThunkLinkage(cir::FuncOp thunk,
bool forVTable, GlobalDecl gd,
132 bool returnAdjustment)
override {
133 if (forVTable && !thunk.hasLocalLinkage())
134 thunk.setLinkage(cir::GlobalLinkageKind::AvailableExternallyLinkage);
139 bool exportThunk()
override {
return true; }
141 mlir::Value performThisAdjustment(CIRGenFunction &cgf, Address thisAddr,
142 const CXXRecordDecl *unadjustedClass,
143 const ThunkInfo &ti)
override;
146 const CXXRecordDecl *unadjustedClass,
147 const ReturnAdjustment &ra)
override;
149 bool shouldTypeidBeNullChecked(QualType srcTy)
override;
150 mlir::Value emitTypeid(CIRGenFunction &cgf, QualType SrcRecordTy,
151 Address thisPtr, mlir::Type StdTypeInfoPtrTy)
override;
152 void emitBadTypeidCall(CIRGenFunction &cgf, mlir::Location loc)
override;
154 mlir::Attribute getAddrOfRTTIDescriptor(mlir::Location loc,
155 QualType ty)
override;
157 StringRef getPureVirtualCallName()
override {
return "__cxa_pure_virtual"; }
158 StringRef getDeletedVirtualCallName()
override {
159 return "__cxa_deleted_virtual";
163 getAddrOfCXXCatchHandlerType(mlir::Location loc, QualType ty,
164 QualType catchHandlerType)
override {
165 auto rtti = dyn_cast<cir::GlobalViewAttr>(getAddrOfRTTIDescriptor(loc, ty));
166 assert(rtti &&
"expected GlobalViewAttr");
167 return CatchTypeInfo{rtti, 0};
170 bool doStructorsInitializeVPtrs(
const CXXRecordDecl *vtableClass)
override {
174 size_t getSrcArgforCopyCtor(
const CXXConstructorDecl *,
175 FunctionArgList &args)
const override {
176 assert(!args.empty() &&
"expected the arglist to not be empty!");
177 return args.size() - 1;
180 void emitBadCastCall(CIRGenFunction &cgf, mlir::Location loc)
override;
183 getVirtualBaseClassOffset(mlir::Location loc, CIRGenFunction &cgf,
184 Address thisAddr,
const CXXRecordDecl *classDecl,
185 const CXXRecordDecl *baseClassDecl)
override;
192 mlir::Value emitDynamicCast(CIRGenFunction &cgf, mlir::Location loc,
193 QualType srcRecordTy, QualType destRecordTy,
194 cir::PointerType destCIRTy,
bool isRefCast,
195 Address src)
override;
197 cir::MethodAttr buildVirtualMethodAttr(cir::MethodType methodTy,
198 const CXXMethodDecl *md)
override;
200 Address initializeArrayCookie(CIRGenFunction &cgf, Address newPtr,
201 mlir::Value numElements,
const CXXNewExpr *e,
202 QualType elementType)
override;
204 bool isZeroInitializable(
const MemberPointerType *MPT)
override;
207 CharUnits getArrayCookieSizeImpl(QualType elementType)
override;
212 virtual bool shouldRTTIBeUnique()
const {
return true; }
216 enum RTTIUniquenessKind {
234 classifyRTTIUniqueness(QualType canTy, cir::GlobalLinkageKind linkage)
const;
237 bool hasAnyUnusedVirtualInlineFunction(
const CXXRecordDecl *rd)
const;
238 bool isVTableHidden(
const CXXRecordDecl *rd)
const;
243void CIRGenItaniumCXXABI::emitInstanceFunctionProlog(
SourceLocation loc,
248 "emitInstanceFunctionProlog: Naked");
253 setCXXABIThisValue(cgf, loadIncomingCXXThis(cgf));
256 if (getStructorImplicitParamDecl(cgf)) {
260 setStructorImplicitParamValue(cgf, val);
271 if (hasThisReturn(cgf.
curGD))
276CIRGenCXXABI::AddedStructorArgCounts
277CIRGenItaniumCXXABI::buildStructorSignature(
278 GlobalDecl gd, llvm::SmallVectorImpl<CanQualType> &argTys) {
290 argTys.insert(argTys.begin() + 1,
292 return AddedStructorArgCounts::withPrefix(1);
295 return AddedStructorArgCounts{};
300enum class StructorCIRGen { Emit, RAUW, Alias, COMDAT };
306 return StructorCIRGen::Emit;
311 return StructorCIRGen::Emit;
314 if (
const auto *dd = dyn_cast<CXXDestructorDecl>(md)) {
324 return StructorCIRGen::RAUW;
328 return StructorCIRGen::RAUW;
334 return StructorCIRGen::COMDAT;
335 return StructorCIRGen::Emit;
338 return StructorCIRGen::Alias;
348 auto globalValue = dyn_cast_or_null<cir::CIRGlobalValueInterface>(
350 if (globalValue && !globalValue.isDeclaration())
353 auto entry = cast_or_null<cir::FuncOp>(cgm.
getGlobalValue(mangledName));
363 alias.setUnnamedAddr(
true);
366void CIRGenItaniumCXXABI::emitCXXStructor(GlobalDecl gd) {
369 const auto *cd = dyn_cast<CXXConstructorDecl>(md);
374 GlobalDecl baseDecl =
378 if (cirGenType == StructorCIRGen::Alias ||
379 cirGenType == StructorCIRGen::COMDAT) {
384 if (cirGenType == StructorCIRGen::RAUW) {
394 if (cirGenType == StructorCIRGen::COMDAT) {
395 llvm::SmallString<256> comdatKey;
396 llvm::raw_svector_ostream
out(comdatKey);
397 ItaniumMangleContext &mangler =
403 fn.setComdat(llvm::StringRef(comdatKey));
409void CIRGenItaniumCXXABI::addImplicitStructorParams(CIRGenFunction &cgf,
411 FunctionArgList ¶ms) {
416 if (needsVTTParameter(cgf.
curGD)) {
424 astContext,
nullptr, md->getLocation(),
425 &astContext.
Idents.
get(
"vtt"), t, ImplicitParamKind::CXXVTT);
426 params.insert(params.begin() + 1, vttDecl);
427 getStructorImplicitParamDecl(cgf) = vttDecl;
431void CIRGenItaniumCXXABI::emitCXXConstructors(
const CXXConstructorDecl *d) {
447void CIRGenItaniumCXXABI::emitCXXDestructors(
const CXXDestructorDecl *d) {
463CIRGenCXXABI::AddedStructorArgs CIRGenItaniumCXXABI::getImplicitConstructorArgs(
465 bool forVirtualBase,
bool delegating) {
466 if (!needsVTTParameter(GlobalDecl(d,
type)))
467 return AddedStructorArgs{};
478 return AddedStructorArgs::withPrefix({{vtt, vttTy}});
484bool CIRGenItaniumCXXABI::needsVTTParameter(GlobalDecl gd) {
488 if (!md->getParent()->getNumVBases())
502void CIRGenItaniumCXXABI::emitVTableDefinitions(CIRGenVTables &cgvt,
503 const CXXRecordDecl *rd) {
504 cir::GlobalOp vtable = getAddrOfVTable(rd, CharUnits());
505 if (vtable.hasInitializer())
511 mlir::Attribute rtti =
524 vtable.setLinkage(linkage);
525 mlir::SymbolTable::setSymbolVisibility(
529 vtable.setUnnamedAddr(
true);
532 vtable.setSelfComdat();
547 "emitVTableDefinitions: __fundamental_type_info");
550 [[maybe_unused]]
auto vtableAsGlobalValue =
551 dyn_cast<cir::CIRGlobalValueInterface>(*vtable);
552 assert(vtableAsGlobalValue &&
"VTable must support CIRGlobalValueInterface");
562 "emitVTableDefinitions: WholeProgramVTables");
571mlir::Value CIRGenItaniumCXXABI::emitVirtualDestructorCall(
572 CIRGenFunction &cgf,
const CXXDestructorDecl *dtor,
CXXDtorType dtorType,
573 Address thisAddr, DeleteOrMemberCallExpr
expr) {
574 auto *
callExpr = dyn_cast<const CXXMemberCallExpr *>(
expr);
575 auto *delExpr = dyn_cast<const CXXDeleteExpr *>(
expr);
576 assert((
callExpr !=
nullptr) ^ (delExpr !=
nullptr));
580 GlobalDecl globalDecl(dtor, dtorType);
581 const CIRGenFunctionInfo *fnInfo =
590 thisTy,
nullptr, QualType(),
nullptr);
594void CIRGenItaniumCXXABI::emitVirtualInheritanceTables(
595 const CXXRecordDecl *rd) {
602class CIRGenItaniumRTTIBuilder {
604 const CIRGenItaniumCXXABI &cxxABI;
607 SmallVector<mlir::Attribute, 16> fields;
610 cir::GlobalOp getAddrOfTypeName(mlir::Location loc, QualType ty,
611 cir::GlobalLinkageKind linkage);
614 mlir::Attribute getAddrOfExternalRTTIDescriptor(mlir::Location loc,
618 void buildVTablePointer(mlir::Location loc,
const Type *ty);
622 void buildSIClassTypeInfo(mlir::Location loc,
const CXXRecordDecl *rd);
627 void buildVMIClassTypeInfo(mlir::Location loc,
const CXXRecordDecl *rd);
631 void buildPointerTypeInfo(mlir::Location loc, QualType ty);
638 void buildPointerToMemberTypeInfo(mlir::Location loc,
639 const MemberPointerType *ty);
642 CIRGenItaniumRTTIBuilder(
const CIRGenItaniumCXXABI &abi, CIRGenModule &cgm)
643 : cgm(cgm), cxxABI(abi) {}
647 mlir::Attribute buildTypeInfo(mlir::Location loc, QualType ty);
650 mlir::Attribute buildTypeInfo(mlir::Location loc, QualType ty,
651 cir::GlobalLinkageKind linkage,
652 cir::VisibilityKind globalVisibility);
659static bool shouldUseExternalRttiDescriptor(CIRGenModule &cgm, QualType ty) {
667 if (
const auto *recordTy = dyn_cast<RecordType>(ty)) {
680 bool isDLLImport = rd->
hasAttr<DLLImportAttr>();
690 return !isDLLImport || cgm.
getTriple().isWindowsItaniumEnvironment();
700const char *vTableClassNameForType(
const CIRGenModule &cgm,
const Type *ty) {
702 static const char *
const classTypeInfo =
703 "_ZTVN10__cxxabiv117__class_type_infoE";
705 static const char *
const siClassTypeInfo =
706 "_ZTVN10__cxxabiv120__si_class_type_infoE";
708 static const char *
const vmiClassTypeInfo =
709 "_ZTVN10__cxxabiv121__vmi_class_type_infoE";
712#define TYPE(Class, Base)
713#define ABSTRACT_TYPE(Class, Base)
714#define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class, Base) case Type::Class:
715#define NON_CANONICAL_TYPE(Class, Base) case Type::Class:
716#define DEPENDENT_TYPE(Class, Base) case Type::Class:
717#include "clang/AST/TypeNodes.inc"
718 llvm_unreachable(
"Non-canonical and dependent types shouldn't get here");
720 case Type::LValueReference:
721 case Type::RValueReference:
722 llvm_unreachable(
"References shouldn't get here");
725 case Type::DeducedTemplateSpecialization:
726 llvm_unreachable(
"Undeduced type shouldn't get here");
729 llvm_unreachable(
"Pipe types shouldn't get here");
731 case Type::ArrayParameter:
732 llvm_unreachable(
"Array Parameter types should not get here.");
736 case Type::OverflowBehavior:
739 case Type::ExtVector:
740 case Type::ConstantMatrix:
744 case Type::BlockPointer:
745 return "_ZTVN10__cxxabiv123__fundamental_type_infoE";
746 case Type::ConstantArray:
747 case Type::IncompleteArray:
748 case Type::VariableArray:
750 return "_ZTVN10__cxxabiv117__array_type_infoE";
752 case Type::FunctionNoProto:
753 case Type::FunctionProto:
755 return "_ZTVN10__cxxabiv120__function_type_infoE";
758 return "_ZTVN10__cxxabiv116__enum_type_infoE";
762 ->getDefinitionOrSelf();
765 return classTypeInfo;
769 return siClassTypeInfo;
772 return vmiClassTypeInfo;
775 case Type::ObjCObject:
776 cgm.
errorNYI(
"VTableClassNameForType: ObjCObject");
779 case Type::ObjCInterface:
780 cgm.
errorNYI(
"VTableClassNameForType: ObjCInterface");
783 case Type::ObjCObjectPointer:
786 return "_ZTVN10__cxxabiv119__pointer_type_infoE";
788 case Type::MemberPointer:
790 return "_ZTVN10__cxxabiv129__pointer_to_member_type_infoE";
792 case Type::HLSLAttributedResource:
793 case Type::HLSLInlineSpirv:
794 llvm_unreachable(
"HLSL doesn't support virtual functions");
814 return cir::GlobalLinkageKind::InternalLinkage;
818 llvm_unreachable(
"Linkage hasn't been computed!");
823 return cir::GlobalLinkageKind::InternalLinkage;
831 return cir::GlobalLinkageKind::LinkOnceODRLinkage;
833 if (
const RecordType *record = dyn_cast<RecordType>(ty)) {
837 return cir::GlobalLinkageKind::WeakODRLinkage;
839 if (cgm.
getTriple().isWindowsItaniumEnvironment())
840 if (rd->
hasAttr<DLLImportAttr>() &&
841 shouldUseExternalRttiDescriptor(cgm, ty))
842 return cir::GlobalLinkageKind::ExternalLinkage;
848 .isWindowsGNUEnvironment())
852 return cir::GlobalLinkageKind::LinkOnceODRLinkage;
855 llvm_unreachable(
"Invalid linkage!");
859CIRGenItaniumRTTIBuilder::getAddrOfTypeName(mlir::Location loc, QualType ty,
860 cir::GlobalLinkageKind linkage) {
862 SmallString<256>
name;
863 llvm::raw_svector_ostream
out(name);
869 mlir::Attribute init = builder.
getString(
882 loc, name, initStr.getType(), linkage, align);
888CIRGenItaniumRTTIBuilder::getAddrOfExternalRTTIDescriptor(mlir::Location loc,
891 SmallString<256>
name;
892 llvm::raw_svector_ostream
out(name);
897 cir::GlobalOp gv = dyn_cast_or_null<cir::GlobalOp>(cgm.
getGlobalValue(name));
912 cgm.
errorNYI(
"getAddrOfExternalRTTIDescriptor: hasPS4DLLImportExport");
919void CIRGenItaniumRTTIBuilder::buildVTablePointer(mlir::Location loc,
922 const char *vTableName = vTableClassNameForType(cgm, ty);
926 cgm.
errorNYI(
"buildVTablePointer: isRelativeLayout");
933 loc, vTableName, vtableGlobalTy, cir::GlobalLinkageKind::ExternalLinkage,
939 vTable.setConstant(
false);
942 mlir::Attribute field{};
944 cgm.
errorNYI(
"buildVTablePointer: isRelativeLayout");
946 SmallVector<mlir::Attribute, 4> offsets{
948 auto indices = mlir::ArrayAttr::get(builder.getContext(), offsets);
953 assert(field &&
"expected attribute");
954 fields.push_back(field);
959void CIRGenItaniumRTTIBuilder::buildSIClassTypeInfo(mlir::Location loc,
960 const CXXRecordDecl *rd) {
964 mlir::Attribute baseTypeInfo =
965 CIRGenItaniumRTTIBuilder(cxxABI, cgm)
967 fields.push_back(baseTypeInfo);
973void CIRGenItaniumRTTIBuilder::buildVMIClassTypeInfo(mlir::Location loc,
974 const CXXRecordDecl *rd) {
975 mlir::Type unsignedIntLTy =
983 fields.push_back(cir::IntAttr::get(unsignedIntLTy, flags));
988 fields.push_back(cir::IntAttr::get(unsignedIntLTy, rd->
getNumBases()));
1021 mlir::Type offsetFlagsLTy = cgm.
convertType(offsetFlagsTy);
1023 for (
const CXXBaseSpecifier &base : rd->
bases()) {
1025 fields.push_back(CIRGenItaniumRTTIBuilder(cxxABI, cgm)
1026 .buildTypeInfo(loc, base.getType()));
1028 CXXRecordDecl *baseDecl = base.getType()->castAsCXXRecordDecl();
1036 if (base.isVirtual())
1040 const ASTRecordLayout &layout =
1048 if (base.isVirtual())
1050 if (base.getAccessSpecifier() ==
AS_public)
1053 fields.push_back(cir::IntAttr::get(offsetFlagsLTy, offsetFlags));
1057void CIRGenItaniumRTTIBuilder::buildPointerTypeInfo(mlir::Location loc,
1078 const unsigned int flags =
1082 mlir::Attribute flagsAttr = cir::IntAttr::get(unsignedIntTy, flags);
1083 fields.push_back(flagsAttr);
1085 mlir::Attribute pointeeTypeInfo =
1086 CIRGenItaniumRTTIBuilder(cxxABI, cgm).buildTypeInfo(loc, ty);
1087 fields.push_back(pointeeTypeInfo);
1090void CIRGenItaniumRTTIBuilder::buildPointerToMemberTypeInfo(
1091 mlir::Location loc,
const MemberPointerType *ty) {
1110 mlir::Attribute flagsAttr = cir::IntAttr::get(unsignedIntTy, flags);
1111 fields.push_back(flagsAttr);
1113 mlir::Attribute pointeeTypeInfo =
1114 CIRGenItaniumRTTIBuilder(cxxABI, cgm).buildTypeInfo(loc, pointeeTy);
1115 fields.push_back(pointeeTypeInfo);
1118 mlir::Attribute classTypeInfo =
1119 CIRGenItaniumRTTIBuilder(cxxABI, cgm).buildTypeInfo(loc, contextTy);
1120 fields.push_back(classTypeInfo);
1123mlir::Attribute CIRGenItaniumRTTIBuilder::buildTypeInfo(mlir::Location loc,
1129 SmallString<256>
name;
1130 llvm::raw_svector_ostream
out(name);
1133 auto oldGV = dyn_cast_or_null<cir::GlobalOp>(cgm.
getGlobalValue(name));
1135 if (oldGV && !oldGV.isDeclaration()) {
1136 assert(!oldGV.hasAvailableExternallyLinkage() &&
1137 "available_externally typeinfos not yet implemented");
1144 shouldUseExternalRttiDescriptor(cgm, ty))
1145 return getAddrOfExternalRTTIDescriptor(loc, ty);
1152 cir::VisibilityKind globalVisibility;
1155 globalVisibility = cir::VisibilityKind::Default;
1156 }
else if (cxxABI.classifyRTTIUniqueness(ty, linkage) ==
1157 CIRGenItaniumCXXABI::RUK_NonUniqueHidden) {
1159 "buildTypeInfo: classifyRTTIUniqueness == RUK_NonUniqueHidden");
1160 globalVisibility = cir::VisibilityKind::Hidden;
1165 return buildTypeInfo(loc, ty, linkage, globalVisibility);
1169CIRGenItaniumRTTIBuilder::buildTypeInfo(mlir::Location loc, QualType ty,
1170 cir::GlobalLinkageKind linkage,
1171 cir::VisibilityKind globalVisibility) {
1180 cir::GlobalOp typeName = getAddrOfTypeName(loc, ty, linkage);
1181 mlir::Attribute typeNameField;
1185 CIRGenItaniumCXXABI::RTTIUniquenessKind rttiUniqueness =
1186 cxxABI.classifyRTTIUniqueness(ty, linkage);
1187 if (rttiUniqueness != CIRGenItaniumCXXABI::RUK_Unique) {
1191 "buildTypeInfo: rttiUniqueness != CIRGenItaniumCXXABI::RUK_Unique");
1197 fields.push_back(typeNameField);
1200#define TYPE(Class, Base)
1201#define ABSTRACT_TYPE(Class, Base)
1202#define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class, Base) case Type::Class:
1203#define NON_CANONICAL_TYPE(Class, Base) case Type::Class:
1204#define DEPENDENT_TYPE(Class, Base) case Type::Class:
1205#include "clang/AST/TypeNodes.inc"
1206 llvm_unreachable(
"Non-canonical and dependent types shouldn't get here");
1211 case Type::ExtVector:
1212 case Type::ConstantMatrix:
1214 case Type::BlockPointer:
1219 case Type::LValueReference:
1220 case Type::RValueReference:
1221 llvm_unreachable(
"References shouldn't get here");
1224 case Type::DeducedTemplateSpecialization:
1225 llvm_unreachable(
"Undeduced type shouldn't get here");
1233 case Type::OverflowBehavior:
1236 case Type::ConstantArray:
1237 case Type::IncompleteArray:
1238 case Type::VariableArray:
1239 case Type::ArrayParameter:
1244 case Type::FunctionNoProto:
1245 case Type::FunctionProto:
1255 case Type::Record: {
1257 ->getDefinitionOrSelf();
1264 buildSIClassTypeInfo(loc, rd);
1266 buildVMIClassTypeInfo(loc, rd);
1272 case Type::ObjCObject:
1273 case Type::ObjCInterface:
1274 cgm.
errorNYI(
"buildTypeInfo: ObjCObject & ObjCInterface");
1277 case Type::ObjCObjectPointer:
1278 cgm.
errorNYI(
"buildTypeInfo: ObjCObjectPointer");
1286 case Type::MemberPointer:
1294 case Type::HLSLAttributedResource:
1295 case Type::HLSLInlineSpirv:
1296 llvm_unreachable(
"HLSL doesn't support RTTI");
1300 cir::TypeInfoAttr init = builder.
getTypeInfo(builder.getArrayAttr(fields));
1302 SmallString<256>
name;
1303 llvm::raw_svector_ostream
out(name);
1307 auto oldGV = dyn_cast_or_null<cir::GlobalOp>(cgm.
getGlobalValue(name));
1311 gv.setLinkage(linkage);
1316 cgm.
errorNYI(
"buildTypeInfo: target hasPS4DLLImportExport");
1323 gv.setName(oldGV.getName());
1324 if (!oldGV->use_empty()) {
1325 cgm.
errorNYI(
"buildTypeInfo: old GV !use_empty");
1337 gv.setAlignmentAttr(cgm.
getSize(align));
1354 mlir::SymbolTable::setSymbolVisibility(
1356 typeName.setGlobalVisibility(globalVisibility);
1359 cgm.
setDSOLocal(
static_cast<mlir::Operation *
>(typeName));
1361 mlir::SymbolTable::setSymbolVisibility(
1363 gv.setGlobalVisibility(globalVisibility);
1366 cgm.
setDSOLocal(
static_cast<mlir::Operation *
>(gv));
1372bool CIRGenItaniumCXXABI::shouldTypeidBeNullChecked(QualType srcTy) {
1376void CIRGenItaniumCXXABI::emitBadTypeidCall(CIRGenFunction &cgf,
1377 mlir::Location loc) {
1379 cir::FuncType fnTy =
1381 mlir::NamedAttrList attrs;
1382 attrs.set(cir::CIRDialect::getNoReturnAttrName(),
1388 cir::UnreachableOp::create(cgf.
getBuilder(), loc);
1391mlir::Value CIRGenItaniumCXXABI::emitTypeid(CIRGenFunction &cgf, QualType srcTy,
1393 mlir::Type typeInfoPtrTy) {
1395 mlir::Location loc = cgm.
getLoc(classDecl->getSourceRange());
1396 mlir::Value vptr = cgf.
getVTablePtr(loc, thisPtr, classDecl);
1397 return cir::VTableGetTypeInfoOp::create(cgf.
getBuilder(), loc, typeInfoPtrTy,
1401mlir::Attribute CIRGenItaniumCXXABI::getAddrOfRTTIDescriptor(mlir::Location loc,
1403 return CIRGenItaniumRTTIBuilder(*
this, cgm).buildTypeInfo(loc, ty);
1408CIRGenItaniumCXXABI::RTTIUniquenessKind
1409CIRGenItaniumCXXABI::classifyRTTIUniqueness(
1410 QualType canTy, cir::GlobalLinkageKind linkage)
const {
1411 if (shouldRTTIBeUnique())
1415 if (linkage != cir::GlobalLinkageKind::LinkOnceODRLinkage &&
1416 linkage != cir::GlobalLinkageKind::WeakODRLinkage)
1424 if (linkage == cir::GlobalLinkageKind::LinkOnceODRLinkage)
1425 return RUK_NonUniqueHidden;
1430 assert(linkage == cir::GlobalLinkageKind::WeakODRLinkage);
1431 return RUK_NonUniqueVisible;
1434void CIRGenItaniumCXXABI::emitDestructorCall(
1436 bool forVirtualBase,
bool delegating, Address thisAddr, QualType thisTy) {
1437 GlobalDecl gd(dd,
type);
1443 CIRGenCallee callee =
1450void CIRGenItaniumCXXABI::registerGlobalDtor(
const VarDecl *vd,
1466mlir::Value CIRGenItaniumCXXABI::getCXXDestructorImplicitParam(
1468 bool forVirtualBase,
bool delegating) {
1469 GlobalDecl gd(dd,
type);
1477 mlir::Value exceptionPtr = {},
1478 mlir::FlatSymbolRefAttr typeInfo = {},
1479 mlir::FlatSymbolRefAttr dtor = {}) {
1480 mlir::Block *currentBlock = builder.getInsertionBlock();
1481 mlir::Region *region = currentBlock->getParent();
1483 if (currentBlock->empty()) {
1484 cir::ThrowOp::create(builder, loc, exceptionPtr, typeInfo, dtor);
1485 cir::UnreachableOp::create(builder, loc);
1487 mlir::Block *throwBlock = builder.createBlock(region);
1489 cir::ThrowOp::create(builder, loc, exceptionPtr, typeInfo, dtor);
1490 cir::UnreachableOp::create(builder, loc);
1492 builder.setInsertionPointToEnd(currentBlock);
1493 cir::BrOp::create(builder, loc, throwBlock);
1496 (void)builder.createBlock(region);
1499void CIRGenItaniumCXXABI::emitRethrow(CIRGenFunction &cgf,
bool isNoReturn) {
1503 assert(cgf.
currSrcLoc &&
"expected source location");
1507 cgm.
errorNYI(
"emitRethrow with isNoReturn false");
1511void CIRGenItaniumCXXABI::emitThrow(CIRGenFunction &cgf,
1512 const CXXThrowExpr *e) {
1520 cir::PointerType throwTy =
1527 mlir::TypedValue<cir::PointerType> exceptionPtr =
1528 cir::AllocExceptionOp::create(builder, subExprLoc, throwTy,
1529 builder.getI64IntegerAttr(typeSize))
1537 auto typeInfo = mlir::cast<cir::GlobalViewAttr>(
1540 assert(!typeInfo.getIndices() &&
"expected no indirection");
1550 mlir::FlatSymbolRefAttr dtor{};
1551 if (cxxrd && !cxxrd->hasTrivialDestructor()) {
1556 CXXDestructorDecl *dtorD = cxxrd->getDestructor();
1557 dtor = mlir::FlatSymbolRefAttr::get(
1569 case TargetCXXABI::GenericItanium:
1570 case TargetCXXABI::GenericAArch64:
1571 case TargetCXXABI::GenericARM:
1572 return new CIRGenItaniumCXXABI(cgm);
1574 case TargetCXXABI::AppleARM64:
1578 return new CIRGenItaniumCXXABI(cgm);
1581 llvm_unreachable(
"bad or NYI ABI kind");
1585cir::GlobalOp CIRGenItaniumCXXABI::getAddrOfVTable(
const CXXRecordDecl *rd,
1587 assert(vptrOffset.
isZero() &&
"Itanium ABI only supports zero vptr offsets");
1588 cir::GlobalOp &vtable = vtables[rd];
1596 llvm::raw_svector_ostream
out(name);
1597 getMangleContext().mangleCXXVTable(rd,
out);
1606 unsigned ptrAlign = cgm.
getLangOpts().RelativeCXXABIVTables
1612 cir::GlobalLinkageKind::ExternalLinkage,
1615 vtable.setUnnamedAddr(
true);
1626 "getAddrOfVTable: PS4 DLL import/export");
1632CIRGenCallee CIRGenItaniumCXXABI::getVirtualFunctionPointer(
1636 mlir::Location loc = cgf.
getLoc(srcLoc);
1639 mlir::Value vtable = cgf.
getVTablePtr(loc, thisAddr, methodDecl->getParent());
1642 mlir::Value vfunc{};
1644 cgm.
errorNYI(loc,
"getVirtualFunctionPointer: emitVTableTypeCheckedLoad");
1648 auto vfuncOp = cir::VTableGetVirtualFnOp::create(builder, loc, tyPtr,
1649 vtable, vtableIndex);
1659 vfuncOp.setInvariant(
true);
1664 CIRGenCallee callee(gd, vfunc.getDefiningOp());
1668mlir::Value CIRGenItaniumCXXABI::getVTableAddressPointInStructorWithVTT(
1669 CIRGenFunction &cgf,
const CXXRecordDecl *vtableClass, BaseSubobject base,
1670 const CXXRecordDecl *nearestVBase) {
1672 needsVTTParameter(cgf.
curGD) &&
"This class doesn't have VTT");
1683 virtualPointerIndex);
1685 auto vptrType = cir::VPtrType::get(cgf.
getBuilder().getContext());
1691CIRGenItaniumCXXABI::getVTableAddressPoint(BaseSubobject base,
1692 const CXXRecordDecl *vtableClass) {
1693 cir::GlobalOp vtable = getAddrOfVTable(vtableClass, CharUnits());
1697 VTableLayout::AddressPointLocation addressPoint =
1703 auto vtablePtrTy = cir::VPtrType::get(builder.getContext());
1705 return cir::VTableAddrPointOp::create(
1707 mlir::FlatSymbolRefAttr::get(vtable.getSymNameAttr()),
1708 cir::AddressPointAttr::get(cgm.
getBuilder().getContext(),
1713cir::GlobalViewAttr CIRGenItaniumCXXABI::getVTableAddressPointAttr(
1714 BaseSubobject base,
const CXXRecordDecl *vtableClass) {
1715 cir::GlobalOp vtable = getAddrOfVTable(vtableClass, CharUnits());
1719 VTableLayout::AddressPointLocation addressPoint =
1725 mlir::ArrayAttr indices = builder.getArrayAttr(
1726 {builder.getI32IntegerAttr(addressPoint.
VTableIndex),
1728 return cir::GlobalViewAttr::get(
1729 cir::VPtrType::get(builder.getContext()),
1730 mlir::FlatSymbolRefAttr::get(vtable.getSymNameAttr()), indices,
1734mlir::Value CIRGenItaniumCXXABI::getVTableAddressPointInStructor(
1735 CIRGenFunction &cgf,
const clang::CXXRecordDecl *vtableClass,
1736 clang::BaseSubobject base,
const clang::CXXRecordDecl *nearestVBase) {
1739 needsVTTParameter(cgf.
curGD)) {
1740 return getVTableAddressPointInStructorWithVTT(cgf, vtableClass, base,
1743 return getVTableAddressPoint(base, vtableClass);
1746bool CIRGenItaniumCXXABI::isVirtualOffsetNeededForVTableField(
1747 CIRGenFunction &cgf, CIRGenFunction::VPtr vptr) {
1750 return needsVTTParameter(cgf.
curGD);
1756 assert(byteOffset % entrySize == 0 &&
"unaligned vtable entry offset");
1757 return byteOffset / entrySize;
1760mlir::Value CIRGenItaniumCXXABI::getVirtualBaseClassOffset(
1761 mlir::Location loc, CIRGenFunction &cgf, Address thisAddr,
1762 const CXXRecordDecl *classDecl,
const CXXRecordDecl *baseClassDecl) {
1764 mlir::Value vtablePtr = cgf.
getVTablePtr(loc, thisAddr, classDecl);
1765 CharUnits vbaseOffsetOffset =
1768 return cir::VTableGetOffsetOp::create(
1779 cir::FuncType fnTy =
1788 mlir::NamedAttrList attrs;
1789 attrs.set(cir::CIRDialect::getNoReturnAttrName(),
1793 cir::UnreachableOp::create(cgf.
getBuilder(), loc);
1797void CIRGenItaniumCXXABI::emitBadCastCall(CIRGenFunction &cgf,
1798 mlir::Location loc) {
1821 {voidPtrTy, rttiPtrTy, rttiPtrTy, ptrDiffTy}, voidPtrTy);
1823 fn->setAttr(cir::CIRDialect::getNoThrowAttrName(),
1824 mlir::UnitAttr::get(cgf.
getBuilder().getContext()));
1838 cir::PointerType destCIRTy,
1839 bool isRefCast,
Address src) {
1849 std::optional<CharUnits> offset;
1859 pathElement.Base->getType()->getAsCXXRecordDecl();
1860 if (pathElement.Base->isVirtual()) {
1874 offset = pathOffset;
1875 }
else if (offset != pathOffset) {
1891 mlir::Value nullPtrValue = builder.
getNullPtr(destCIRTy, loc);
1893 mlir::Region *currentRegion = builder.getBlock()->getParent();
1898 builder.createBlock(currentRegion, currentRegion->end());
1901 return nullPtrValue;
1909 mlir::Value expectedVPtr =
1914 mlir::Type vptrTy = expectedVPtr.getType();
1918 mlir::Value srcVPtr = builder.
createLoad(loc, srcVPtrPtr);
1923 mlir::Value success =
1924 builder.
createCompare(loc, cir::CmpOpKind::eq, srcVPtr, expectedVPtr);
1926 auto emitCastResult = [&] {
1927 if (offset->isZero())
1934 mlir::Value strideToApply =
1937 mlir::Value resultU8Ptr = cir::PtrStrideOp::create(builder, loc, u8PtrTy,
1938 srcU8Ptr, strideToApply);
1943 mlir::Value failed = builder.
createNot(success);
1944 cir::IfOp::create(builder, loc, failed,
false,
1945 [&](mlir::OpBuilder &, mlir::Location) {
1948 return emitCastResult();
1951 return cir::TernaryOp::create(
1952 builder, loc, success,
1953 [&](mlir::OpBuilder &, mlir::Location) {
1954 auto result = emitCastResult();
1957 [&](mlir::OpBuilder &, mlir::Location) {
1958 mlir::Value nullPtrValue = builder.
getNullPtr(destCIRTy, loc);
1968 auto srcRtti = mlir::cast<cir::GlobalViewAttr>(
1970 auto destRtti = mlir::cast<cir::GlobalViewAttr>(
1975 auto runtimeFuncRef = mlir::FlatSymbolRefAttr::get(runtimeFuncOp);
1976 auto badCastFuncRef = mlir::FlatSymbolRefAttr::get(badCastFuncOp);
1984 auto offsetHintAttr = cir::IntAttr::get(ptrdiffTy, offsetHint.
getQuantity());
1986 return cir::DynamicCastInfoAttr::get(srcRtti, destRtti, runtimeFuncRef,
1987 badCastFuncRef, offsetHintAttr);
1990mlir::Value CIRGenItaniumCXXABI::emitDynamicCast(CIRGenFunction &cgf,
1992 QualType srcRecordTy,
1993 QualType destRecordTy,
1994 cir::PointerType destCIRTy,
1995 bool isRefCast, Address src) {
1996 bool isCastToVoid = destRecordTy.
isNull();
1997 assert((!isCastToVoid || !isRefCast) &&
"cannot cast to void reference");
2010 return cir::TernaryOp::create(
2011 builder, loc, srcPtrIsNull,
2012 [&](mlir::OpBuilder, mlir::Location) {
2014 loc, builder.
getNullPtr(destCIRTy, loc).getResult());
2016 [&](mlir::OpBuilder &, mlir::Location) {
2018 *
this, cgf, loc, srcRecordTy, destRecordTy, destCIRTy,
2026 destCIRTy, isRefCast, src);
2029 cir::DynamicCastInfoAttr castInfo =
2032 isRefCast, castInfo);
2036CIRGenItaniumCXXABI::buildVirtualMethodAttr(cir::MethodType methodTy,
2037 const CXXMethodDecl *md) {
2038 assert(md->
isVirtual() &&
"only deal with virtual member functions");
2041 return cir::MethodAttr::get(methodTy, index);
2045void CIRGenItaniumCXXABI::emitVirtualObjectDelete(
2046 CIRGenFunction &cgf,
const CXXDeleteExpr *delExpr, Address ptr,
2047 QualType elementType,
const CXXDestructorDecl *dtor) {
2049 if (useGlobalDelete) {
2051 "emitVirtualObjectDelete: global delete");
2055 emitVirtualDestructorCall(cgf, dtor, dtorType, ptr, delExpr);
2060CharUnits CIRGenItaniumCXXABI::getArrayCookieSizeImpl(QualType elementType) {
2068Address CIRGenItaniumCXXABI::initializeArrayCookie(CIRGenFunction &cgf,
2070 mlir::Value numElements,
2071 const CXXNewExpr *e,
2072 QualType elementType) {
2073 assert(requiresArrayCookie(e));
2084 CharUnits cookieSize =
2086 assert(cookieSize == getArrayCookieSizeImpl(elementType));
2089 mlir::Value baseBytePtr =
2093 CharUnits cookieOffset = cookieSize - sizeSize;
2094 mlir::Value cookiePtrValue = baseBytePtr;
2095 if (!cookieOffset.
isZero()) {
2104 Address cookiePtr(cookiePtrValue, u8Ty, cookiePtrAlignment);
2113 mlir::Value dataOffset =
2116 mlir::Value dataPtr =
2118 mlir::Value finalPtr =
2124bool CIRGenItaniumCXXABI::hasAnyUnusedVirtualInlineFunction(
2125 const CXXRecordDecl *rd)
const {
2128 for (
const auto &vtableComponent : vtableLayout.vtable_components()) {
2130 if (!vtableComponent.isUsedFunctionPointerKind())
2133 const CXXMethodDecl *method = vtableComponent.getFunctionDecl();
2135 const bool isInlined =
2141 vtableComponent.getGlobalDecl(
false));
2142 auto entry = dyn_cast_or_null<cir::GlobalOp>(cgm.
getGlobalValue(name));
2148 if (!entry || entry.isDeclaration())
2154bool CIRGenItaniumCXXABI::isVTableHidden(
const CXXRecordDecl *rd)
const {
2157 for (
const auto &vtableComponent : vtableLayout.vtable_components()) {
2158 if (vtableComponent.isRTTIKind()) {
2159 const CXXRecordDecl *rttiDecl = vtableComponent.getRTTIDecl();
2160 if (rttiDecl->
getVisibility() == Visibility::HiddenVisibility)
2162 }
else if (vtableComponent.isUsedFunctionPointerKind()) {
2163 const CXXMethodDecl *method = vtableComponent.getFunctionDecl();
2164 if (method->
getVisibility() == Visibility::HiddenVisibility &&
2172bool CIRGenItaniumCXXABI::canSpeculativelyEmitVTableAsBaseClass(
2173 const CXXRecordDecl *rd)
const {
2181 if (isVTableHidden(rd))
2201 if (hasAnyUnusedVirtualInlineFunction(rd))
2209 for (
const auto &b : rd->
bases()) {
2210 auto *brd = b.getType()->getAsCXXRecordDecl();
2211 assert(brd &&
"no class for base specifier");
2212 if (b.isVirtual() || !brd->isDynamicClass())
2214 if (!canSpeculativelyEmitVTableAsBaseClass(brd))
2222bool CIRGenItaniumCXXABI::canSpeculativelyEmitVTable(
2223 const CXXRecordDecl *rd)
const {
2224 if (!canSpeculativelyEmitVTableAsBaseClass(rd))
2232 for (
const auto &b : rd->
vbases()) {
2233 auto *brd = b.getType()->getAsCXXRecordDecl();
2234 assert(brd &&
"no class for base specifier");
2235 if (!brd->isDynamicClass())
2237 if (!canSpeculativelyEmitVTableAsBaseClass(brd))
2249 bool isReturnAdjustment) {
2250 if (!nonVirtualAdjustment && !virtualAdjustment)
2254 mlir::Location loc = builder.getUnknownLoc();
2257 auto i8PtrTy = mlir::cast<cir::PointerType>(v.getType());
2260 if (nonVirtualAdjustment && !isReturnAdjustment) {
2261 cir::ConstantOp offsetConst = builder.
getSInt64(nonVirtualAdjustment, loc);
2262 v = cir::PtrStrideOp::create(builder, loc, i8PtrTy, v, offsetConst);
2266 mlir::Value resultPtr;
2267 if (virtualAdjustment) {
2271 mlir::Value offset = cir::VTableGetOffsetOp::create(
2275 resultPtr = cir::PtrStrideOp::create(builder, loc, i8PtrTy, v, offset);
2282 if (nonVirtualAdjustment && isReturnAdjustment) {
2283 cir::ConstantOp offsetConst = builder.
getSInt64(nonVirtualAdjustment, loc);
2285 cir::PtrStrideOp::create(builder, loc, i8PtrTy, resultPtr, offsetConst);
2292mlir::Value CIRGenItaniumCXXABI::performThisAdjustment(
2293 CIRGenFunction &cgf, Address thisAddr,
const CXXRecordDecl *unadjustedClass,
2294 const ThunkInfo &ti) {
2301mlir::Value CIRGenItaniumCXXABI::performReturnAdjustment(
2302 CIRGenFunction &cgf, Address ret,
const CXXRecordDecl *unadjustedClass,
2303 const ReturnAdjustment &ra) {
2309bool CIRGenItaniumCXXABI::isZeroInitializable(
const MemberPointerType *mpt) {
static void emitConstructorDestructorAlias(CIRGenModule &cgm, GlobalDecl aliasDecl, GlobalDecl targetDecl)
static void insertThrowAndSplit(mlir::OpBuilder &builder, mlir::Location loc, mlir::Value exceptionPtr={}, mlir::FlatSymbolRefAttr typeInfo={}, mlir::FlatSymbolRefAttr dtor={})
static Address emitDynamicCastToVoid(CIRGenFunction &cgf, mlir::Location loc, QualType srcRecordTy, Address src)
static cir::DynamicCastInfoAttr emitDynamicCastInfo(CIRGenFunction &cgf, mlir::Location loc, QualType srcRecordTy, QualType destRecordTy)
static int64_t getVTableEntryIndex(CIRGenModule &cgm, int64_t byteOffset)
static cir::GlobalLinkageKind getTypeInfoLinkage(CIRGenModule &cgm, QualType ty)
Return the linkage that the type info and type info name constants should have for the given type.
static mlir::Value performTypeAdjustment(CIRGenFunction &cgf, Address initialPtr, const CXXRecordDecl *unadjustedClass, int64_t nonVirtualAdjustment, int64_t virtualAdjustment, bool isReturnAdjustment)
static mlir::Value emitExactDynamicCast(CIRGenItaniumCXXABI &abi, CIRGenFunction &cgf, mlir::Location loc, QualType srcRecordTy, QualType destRecordTy, cir::PointerType destCIRTy, bool isRefCast, Address src)
static void emitCallToBadCast(CIRGenFunction &cgf, mlir::Location loc)
static cir::FuncOp getItaniumDynamicCastFn(CIRGenFunction &cgf)
static StructorCIRGen getCIRGenToUse(CIRGenModule &cgm, const CXXMethodDecl *md)
static cir::FuncOp getBadCastFn(CIRGenFunction &cgf)
static RValue performReturnAdjustment(CIRGenFunction &cgf, QualType resultType, RValue rv, const ThunkInfo &thunk)
Defines the clang::Expr interface and subclasses for C++ expressions.
static QualType getPointeeType(const MemRegion *R)
C Language Family Type Representation.
cir::GlobalViewAttr getGlobalViewAttr(cir::GlobalOp globalOp, mlir::ArrayAttr indices={})
Get constant address of a global variable as an MLIR attribute.
mlir::Value createPtrIsNull(mlir::Value ptr)
cir::PtrStrideOp createPtrStride(mlir::Location loc, mlir::Value base, mlir::Value stride)
cir::PointerType getPointerTo(mlir::Type ty)
cir::ConstantOp getNullPtr(mlir::Type ty, mlir::Location loc)
mlir::Value createPtrBitcast(mlir::Value src, mlir::Type newPointeeTy)
mlir::Value getSignedInt(mlir::Location loc, int64_t val, unsigned numBits)
mlir::Value createBitcast(mlir::Value src, mlir::Type newTy)
cir::CmpOp createCompare(mlir::Location loc, cir::CmpOpKind kind, mlir::Value lhs, mlir::Value rhs)
mlir::Value createNot(mlir::Location loc, mlir::Value value)
cir::PointerType getVoidPtrTy(clang::LangAS langAS=clang::LangAS::Default)
cir::YieldOp createYield(mlir::Location loc, mlir::ValueRange value={})
Create a yield operation.
llvm::Align getABITypeAlign(mlir::Type ty) const
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
const ASTRecordLayout & getASTRecordLayout(const RecordDecl *D) const
Get or compute information about the layout of the specified record (struct/union/class) D,...
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
const LangOptions & getLangOpts() const
QualType getPointerDiffType() const
Return the unique type for "ptrdiff_t" (C99 7.17) defined in <stddef.h>.
CharUnits getExnObjectAlignment() const
Return the alignment (in bytes) of the thrown exception object.
CharUnits getPreferredTypeAlignInChars(QualType T) const
Return the PreferredAlignment of a (complete) type T, in characters.
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
CanQualType UnsignedIntTy
const TargetInfo & getTargetInfo() const
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
TargetCXXABI::Kind getCXXABIKind() const
Return the C++ ABI kind that should be used.
QualType getAddrSpaceQualType(QualType T, LangAS AddressSpace) const
Return the uniqued reference to the type for an address space qualified type with the specified type ...
CanQualType getCanonicalTagType(const TagDecl *TD) const
ASTRecordLayout - This class contains layout information for one RecordDecl, which is a struct/union/...
CharUnits getBaseClassOffset(const CXXRecordDecl *Base) const
getBaseClassOffset - Get the offset, in chars, for the given base class.
CharUnits getVBaseClassOffset(const CXXRecordDecl *VBase) const
getVBaseClassOffset - Get the offset, in chars, for the given base class.
const CXXRecordDecl * getBase() const
getBase - Returns the base class declaration.
mlir::Value getPointer() const
mlir::Type getElementType() const
clang::CharUnits getAlignment() const
mlir::Type getType() const
mlir::Value emitRawPointer() const
Return the pointer contained in this class after authenticating it and adding offset to it if necessa...
cir::IntType getUInt64Ty()
cir::IntType getUInt8Ty()
cir::TypeInfoAttr getTypeInfo(mlir::ArrayAttr fieldsAttr)
cir::ConstantOp getSInt64(uint64_t c, mlir::Location loc)
cir::PointerType getUInt8PtrTy()
cir::LoadOp createLoad(mlir::Location loc, Address addr, bool isVolatile=false, bool isNontemporal=false)
cir::StoreOp createStore(mlir::Location loc, mlir::Value val, Address dst, bool isVolatile=false, bool isNontemporal=false, mlir::IntegerAttr align={}, cir::SyncScopeKindAttr scope={}, cir::MemOrderAttr order={})
cir::LoadOp createAlignedLoad(mlir::Location loc, mlir::Type ty, mlir::Value ptr, llvm::MaybeAlign align)
cir::FuncType getFuncType(llvm::ArrayRef< mlir::Type > params, mlir::Type retTy, bool isVarArg=false)
mlir::Value createDynCast(mlir::Location loc, mlir::Value src, cir::PointerType destType, bool isRefCast, cir::DynamicCastInfoAttr info)
mlir::Attribute getString(llvm::StringRef str, mlir::Type eltTy, std::optional< size_t > size, bool ensureNullTerm=true)
Get a cir::ConstArrayAttr for a string literal.
cir::ConstantOp getConstInt(mlir::Location loc, llvm::APSInt intVal)
mlir::Value createVTTAddrPoint(mlir::Location loc, mlir::Type retTy, mlir::Value addr, uint64_t offset)
mlir::Value createDynCastToVoid(mlir::Location loc, mlir::Value src)
Implements C++ ABI-specific code generation functions.
clang::MangleContext & getMangleContext()
Gets the mangle context.
static CIRGenCallee forDirect(mlir::Operation *funcPtr, const CIRGenCalleeInfo &abstractInfo=CIRGenCalleeInfo())
static CIRGenCallee forVirtual(const clang::CallExpr *ce, clang::GlobalDecl md, Address addr, cir::FuncType fTy)
mlir::Type convertType(clang::QualType t)
clang::GlobalDecl curGD
The GlobalDecl for the current function being compiled or the global variable currently being initial...
const clang::Decl * curFuncDecl
Address getAddrOfLocalVar(const clang::VarDecl *vd)
Return the address of a local variable.
void emitAnyExprToExn(const Expr *e, Address addr)
mlir::Value getVTTParameter(GlobalDecl gd, bool forVirtualBase, bool delegating)
Return the VTT parameter that should be passed to a base constructor/destructor with virtual bases.
mlir::Location getLoc(clang::SourceLocation srcLoc)
Helpers to convert Clang's SourceLocation to a MLIR Location.
mlir::Value loadCXXVTT()
Load the VTT parameter to base constructors/destructors have virtual bases.
Address returnValue
The temporary alloca to hold the return value.
mlir::Value getVTablePtr(mlir::Location loc, Address thisAddr, const clang::CXXRecordDecl *vtableClass)
Return the Value of the vtable pointer member pointed to by thisAddr.
bool shouldEmitVTableTypeCheckedLoad(const CXXRecordDecl *rd)
Returns whether we should perform a type checked load when loading a virtual function for virtual cal...
CIRGenBuilderTy & getBuilder()
mlir::Value emitRuntimeCall(mlir::Location loc, cir::FuncOp callee, llvm::ArrayRef< mlir::Value > args={}, mlir::NamedAttrList attrs={})
std::optional< SourceRange > currSrcLoc
Use to track source locations across nested visitor traversals.
void emitCXXDestructorCall(const CXXDestructorDecl *dd, CXXDtorType type, bool forVirtualBase, bool delegating, Address thisAddr, QualType thisTy)
clang::ASTContext & getContext() const
mlir::Value cxxabiThisValue
This class organizes the cross-function state that is used while generating CIR code.
llvm::StringRef getMangledName(clang::GlobalDecl gd)
DiagnosticBuilder errorNYI(SourceLocation, llvm::StringRef)
Helpers to emit "not yet implemented" error diagnostics.
clang::ASTContext & getASTContext() const
cir::FuncOp getAddrOfCXXStructor(clang::GlobalDecl gd, const CIRGenFunctionInfo *fnInfo=nullptr, cir::FuncType fnType=nullptr, bool dontDefer=false, ForDefinition_t isForDefinition=NotForDefinition)
void addReplacement(llvm::StringRef name, mlir::Operation *op)
mlir::Type convertType(clang::QualType type)
bool shouldEmitRTTI(bool forEH=false)
mlir::IntegerAttr getSize(CharUnits size)
CIRGenBuilderTy & getBuilder()
void setDSOLocal(mlir::Operation *op) const
ItaniumVTableContext & getItaniumVTableContext()
void setGVProperties(mlir::Operation *op, const NamedDecl *d) const
Set visibility, dllimport/dllexport and dso_local.
cir::FuncOp emitAliasForGlobal(llvm::StringRef mangledName, mlir::Operation *op, GlobalDecl aliasGD, cir::FuncOp aliasee, cir::GlobalLinkageKind linkage)
Emit aliasGD as an alias of aliasee, replacing any existing declaration op, and return the alias.
mlir::Attribute getAddrOfRTTIDescriptor(mlir::Location loc, QualType ty, bool forEH=false)
Get the address of the RTTI descriptor for the given type.
static mlir::SymbolTable::Visibility getMLIRVisibilityFromCIRLinkage(cir::GlobalLinkageKind GLK)
const clang::TargetInfo & getTarget() const
static mlir::SymbolTable::Visibility getMLIRVisibility(cir::GlobalOp op)
const llvm::Triple & getTriple() const
const cir::CIRDataLayout & getDataLayout() const
cir::GlobalOp createOrReplaceCXXRuntimeVariable(mlir::Location loc, llvm::StringRef name, mlir::Type ty, cir::GlobalLinkageKind linkage, clang::CharUnits alignment)
Will return a global variable of the given type.
cir::FuncOp createRuntimeFunction(cir::FuncType ty, llvm::StringRef name, mlir::NamedAttrList extraAttrs={}, bool isLocal=false, bool assumeConvergent=false)
LangAS getGlobalVarAddressSpace(const VarDecl *decl)
Return the AST address space of the underlying global variable for D, as determined by its declaratio...
void eraseGlobalSymbol(mlir::Operation *op)
static void setInitializer(cir::GlobalOp &op, mlir::Attribute value)
cir::GlobalLinkageKind getFunctionLinkage(GlobalDecl gd)
const clang::CodeGenOptions & getCodeGenOpts() const
const clang::LangOptions & getLangOpts() const
bool mayVTableBeDuplicated(cir::GlobalLinkageKind linkage) const
Return true if a vtable with the given linkage may have more than one address in the program,...
cir::GlobalOp createGlobalOp(mlir::Location loc, llvm::StringRef name, mlir::Type t, bool isConstant=false, mlir::ptr::MemorySpaceAttrInterface addrSpace={}, mlir::Operation *insertPoint=nullptr)
static cir::VisibilityKind getCIRVisibilityKind(Visibility v)
void addDeferredVTable(const CXXRecordDecl *rd)
cir::FuncOp codegenCXXStructor(clang::GlobalDecl gd)
mlir::Location getLoc(clang::SourceLocation cLoc)
Helpers to convert the presumed location of Clang's SourceLocation to an MLIR Location.
mlir::Operation * getGlobalValue(llvm::StringRef ref)
mlir::ModuleOp getModule() const
bool supportsCOMDAT() const
mlir::MLIRContext & getMLIRContext()
mlir::Operation * getAddrOfGlobal(clang::GlobalDecl gd, ForDefinition_t isForDefinition=NotForDefinition)
void maybeSetTrivialComdat(const clang::Decl &d, mlir::Operation *op)
CIRGenCXXABI & getCXXABI() const
void emitGlobal(clang::GlobalDecl gd)
Emit code for a single global function or variable declaration.
CIRGenVTables & getVTables()
cir::GlobalLinkageKind getVTableLinkage(const CXXRecordDecl *rd)
Return the appropriate linkage for the vtable, VTT, and type information of the given class.
const CIRGenFunctionInfo & arrangeCXXStructorDeclaration(clang::GlobalDecl gd)
cir::FuncType getFunctionType(const CIRGenFunctionInfo &info)
Get the CIR function type for.
cir::RecordType getVTableType(const clang::VTableLayout &layout)
Returns the type of a vtable with the given layout.
void createVTableInitializer(cir::GlobalOp &vtable, const clang::VTableLayout &layout, mlir::Attribute rtti, bool vtableHasLocalLinkage)
Add vtable components for the given vtable layout to the given global initializer.
void emitVTTDefinition(cir::GlobalOp vttOp, cir::GlobalLinkageKind linkage, const CXXRecordDecl *rd)
Emit the definition of the given vtable.
cir::GlobalOp getAddrOfVTT(const CXXRecordDecl *rd)
Get the address of the VTT for the given record decl.
bool isVTableExternal(const clang::CXXRecordDecl *rd)
At this point in the translation unit, does it appear that can we rely on the vtable being defined el...
uint64_t getSecondaryVirtualPointerIndex(const CXXRecordDecl *rd, BaseSubobject base)
Return the index in the VTT where the virtual pointer for the given subobject is located.
Represents a path from a specific derived class (which is not represented as part of the path) to a p...
BasePaths - Represents the set of paths from a derived class to one of its (direct or indirect) bases...
QualType getType() const
Retrieves the type of the base class.
bool isGlobalDelete() const
Represents a static or instance method of a struct/union/class.
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined.
CXXMethodDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
SourceRange getSourceRange() const
Represents a C++ struct/union/class.
bool isEffectivelyFinal() const
Determine whether it's impossible for a class to be derived from this class.
unsigned getNumBases() const
Retrieves the number of base classes of this class.
base_class_iterator bases_begin()
base_class_range vbases()
bool isAbstract() const
Determine whether this class has a pure virtual function.
bool isDynamicClass() const
bool hasDefinition() const
unsigned getNumVBases() const
Retrieves the number of virtual base classes of this class.
bool isDerivedFrom(const CXXRecordDecl *Base) const
Determine whether this class is derived from the class Base.
const Expr * getSubExpr() const
static CanQual< Type > CreateUnsafe(QualType Other)
This is an opaque type for sizes expressed in character units.
CharUnits alignmentAtOffset(CharUnits offset) const
Given that this is a non-zero alignment value, what is the alignment at the given offset?
bool isZero() const
Test whether the quantity equals zero.
QuantityType getQuantity() const
Get the raw integer representation of this quantity.
static CharUnits One()
Construct a CharUnits quantity of one.
static CharUnits fromQuantity(QuantityType Quantity)
Construct a CharUnits quantity from a raw integer type.
static CharUnits Zero()
Construct a CharUnits quantity of zero.
DeclContext * getParent()
getParent - Returns the containing DeclContext.
bool isTranslationUnit() const
SourceLocation getLocation() const
DeclContext * getDeclContext()
bool shouldEmitInExternalSource() const
Whether the definition of the declaration should be emitted in external sources.
bool isInlined() const
Determine whether this function should be inlined, because it is either marked "inline" or "constexpr...
FunctionDecl * getDefinition()
Get the definition for this declaration.
bool isDefined(const FunctionDecl *&Definition, bool CheckForPendingFriendDefinition=false) const
Returns true if the function has a definition that does not need to be instantiated.
GlobalDecl - represents a global declaration.
GlobalDecl getWithCtorType(CXXCtorType Type)
CXXCtorType getCtorType() const
GlobalDecl getWithDtorType(CXXDtorType Type)
CXXDtorType getDtorType() const
const Decl * getDecl() const
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
static ImplicitParamDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, ImplicitParamKind ParamKind)
Create implicit parameter.
virtual void mangleCXXCtorComdat(const CXXConstructorDecl *D, raw_ostream &)=0
virtual void mangleCXXDtorComdat(const CXXDestructorDecl *D, raw_ostream &)=0
uint64_t getMethodVTableIndex(GlobalDecl GD)
Locate a virtual function in the vtable.
const VTableLayout & getVTableLayout(const CXXRecordDecl *RD)
CharUnits getVirtualBaseOffsetOffset(const CXXRecordDecl *RD, const CXXRecordDecl *VBase)
Return the offset in chars (relative to the vtable address point) where the offset of the virtual bas...
virtual void mangleCXXRTTI(QualType T, raw_ostream &)=0
virtual void mangleCXXRTTIName(QualType T, raw_ostream &, bool NormalizeIntegers=false)=0
CXXRecordDecl * getMostRecentCXXRecordDecl() const
Note: this can trigger extra deserialization when external AST sources are used.
QualType getPointeeType() const
bool isMemberFunctionPointer() const
Returns true if the member type (i.e.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Visibility getVisibility() const
Determines the visibility of this entity.
A (possibly-)qualified type.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
QualType getCanonicalType() const
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Encodes a location in the source.
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
bool hasConstructorVariants() const
Does this ABI have different entrypoints for complete-object and base-subobject constructors?
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
uint64_t getPointerWidth(LangAS AddrSpace) const
Return the width of pointers on this target, for the specified address space.
virtual bool hasPS4DLLImportExport() const
uint64_t getPointerAlign(LangAS AddrSpace) const
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
unsigned getLongWidth() const
getLongWidth/Align - Return the size of 'signed long' and 'unsigned long' for this target,...
SourceLocation getBeginLoc() const LLVM_READONLY
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
CXXRecordDecl * castAsCXXRecordDecl() const
Visibility getVisibility() const
Determine the visibility of this type.
Linkage getLinkage() const
Determine the linkage of this type.
TypeClass getTypeClass() const
AddressPointLocation getAddressPoint(BaseSubobject Base) const
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
bool isNoDestroy(const ASTContext &) const
Is destruction of this variable entirely suppressed?
static bool isLocalLinkage(GlobalLinkageKind linkage)
static bool isValidLinkage(GlobalLinkageKind gl)
uint64_t getVTableEntrySize(mlir::ModuleOp mod, const mlir::DataLayout &dataLayout)
The size in bytes of an entry of a C++ vtable in module.
static bool isWeakForLinker(GlobalLinkageKind linkage)
Whether the definition of this global may be replaced at link time.
static bool isDiscardableIfUnused(GlobalLinkageKind linkage)
Whether the definition of this global may be discarded if it is not used in its compilation unit.
CIRGenCXXABI * CreateCIRGenItaniumCXXABI(CIRGenModule &cgm)
Creates and Itanium-family ABI.
unsigned extractPBaseFlags(const ASTContext &Ctx, QualType &Type)
Compute the flags for a __pbase_type_info, and remove the corresponding pieces from Type.
bool containsIncompleteClassType(QualType Ty)
Returns whether the given type contains an incomplete class type.
bool canUseSingleInheritance(const CXXRecordDecl *RD)
Return whether the given record decl has a "single, public, non-virtual base at offset zero (i....
unsigned computeVMIClassTypeInfoFlags(const CXXRecordDecl *RD)
Compute the value of the flags member in abi::__vmi_class_type_info.
CharUnits computeOffsetHint(ASTContext &Ctx, const CXXRecordDecl *Src, const CXXRecordDecl *Dst)
Compute the src2dst_offset hint as described in the Itanium C++ ABI [2.9.7].
bool isStandardLibraryRTTIDescriptor(QualType Ty)
Returns whether the type information for the given type exists in the standard library.
@ BCTI_Virtual
BCTI_Virtual - Base class is virtual.
@ BCTI_Public
BCTI_Public - Base class is public.
@ PTI_ContainingClassIncomplete
PTI_ContainingClassIncomplete - Containing class is incomplete.
llvm::Value * getCXXDestructorImplicitParam(CodeGenModule &CGM, llvm::BasicBlock *InsertBlock, llvm::BasicBlock::iterator InsertPoint, const CXXDestructorDecl *D, CXXDtorType Type, bool ForVirtualBase, bool Delegating)
const internal::VariadicDynCastAllOfMatcher< Stmt, CallExpr > callExpr
Matches call expressions.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const internal::VariadicDynCastAllOfMatcher< Stmt, Expr > expr
Matches expressions.
constexpr size_t align(size_t Size)
Aligns a size to the pointer alignment.
@ Address
A pointer to a ValueDecl.
Top level wrappers for InstallAPI frontend operations.
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
CXXCtorType
C++ constructor types.
@ Ctor_Base
Base object ctor.
@ Ctor_Complete
Complete object ctor.
bool isa(CodeGen::Address addr)
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
@ VisibleNone
No linkage according to the standard, but is visible from other translation units because of types de...
@ None
No linkage, which means that the entity is unique and can only be referred to from within its scope.
@ UniqueExternal
External linkage within a unique namespace.
@ Internal
Internal linkage, which indicates that the entity can be referred to from within the translation unit...
@ External
External linkage, which indicates that the entity can be referred to from other translation units.
@ Module
Module linkage, which indicates that the entity can be referred to from other translation units withi...
CXXDtorType
C++ destructor types.
@ Dtor_Base
Base object dtor.
@ Dtor_Complete
Complete object dtor.
@ Dtor_Deleting
Deleting dtor.
LangAS
Defines the address space values used by the address space qualifier of QualType.
U cast(CodeGen::Address addr)
@ DefaultVisibility
Objects with "default" visibility are seen by the dynamic linker and act like normal objects.
__builtin_elementwise_add_sat __builtin_elementwise_sub_sat uint32_t int64_t
__builtin_elementwise_add_sat __builtin_elementwise_sub_sat uint32_t uint64_t __builtin_riscv_ssha_i32 __builtin_riscv_sshl_u32 uint64_t
static bool addressSpace()
static bool vtableEmitMetadata()
static bool emitTypeMetadataCodeForVCall()
static bool opFuncReadOnly()
static bool setDLLStorageClass()
static bool cxxabiAppleARM64CXXABI()
static bool opGlobalDLLImportExport()
static bool opGlobalPartition()
static bool pointerAuthentication()
static bool opFuncCallingConv()
static bool opFuncWillReturn()
static bool cxxabiUseARMGuardVarABI()
static bool cxxabiUseARMMethodPtrABI()
static bool vtableRelativeLayout()
const clang::CXXRecordDecl * nearestVBase
clang::CharUnits getPointerAlign() const
clang::CharUnits getSizeSize() const
Represents an element in a path from a derived class to a base class.
union clang::ReturnAdjustment::VirtualAdjustment Virtual
int64_t NonVirtual
The non-virtual adjustment from the derived object to its nearest virtual base.
union clang::ThisAdjustment::VirtualAdjustment Virtual
int64_t NonVirtual
The non-virtual adjustment from the derived object to its nearest virtual base.
ThisAdjustment This
The this pointer adjustment.
unsigned AddressPointIndex
struct clang::ReturnAdjustment::VirtualAdjustment::@103031170252120233124322035264172076254313213024 Itanium
int64_t VBaseOffsetOffset
The offset (in bytes), relative to the address point of the virtual base class offset.
struct clang::ThisAdjustment::VirtualAdjustment::@106065375072164260365214033034320247050276346205 Itanium
int64_t VCallOffsetOffset
The offset (in bytes), relative to the address point, of the virtual call offset.