31#include "mlir/IR/BuiltinOps.h"
32#include "mlir/IR/Location.h"
33#include "mlir/IR/MLIRContext.h"
34#include "mlir/IR/Verifier.h"
43 case TargetCXXABI::GenericItanium:
44 case TargetCXXABI::GenericAArch64:
45 case TargetCXXABI::AppleARM64:
48 case TargetCXXABI::Fuchsia:
49 case TargetCXXABI::GenericARM:
50 case TargetCXXABI::iOS:
51 case TargetCXXABI::WatchOS:
52 case TargetCXXABI::GenericMIPS:
53 case TargetCXXABI::WebAssembly:
54 case TargetCXXABI::XL:
55 case TargetCXXABI::Microsoft:
56 cgm.
errorNYI(
"C++ ABI kind not yet implemented");
60 llvm_unreachable(
"invalid C++ ABI kind");
63CIRGenModule::CIRGenModule(mlir::MLIRContext &mlirContext,
67 : builder(mlirContext, *this), astContext(astContext),
68 langOpts(astContext.
getLangOpts()), codeGenOpts(cgo),
69 theModule{
mlir::ModuleOp::create(
mlir::UnknownLoc::get(&mlirContext))},
70 diags(diags), target(astContext.getTargetInfo()),
71 abi(
createCXXABI(*this)), genTypes(*this), vtables(*this) {
103 const unsigned charSize = astContext.getTargetInfo().getCharWidth();
107 const unsigned sizeTypeSize =
108 astContext.getTypeSize(astContext.getSignedSizeType());
109 SizeSizeInBytes = astContext.toCharUnitsFromBits(sizeTypeSize).getQuantity();
116 std::optional<cir::SourceLanguage> sourceLanguage = getCIRSourceLanguage();
119 cir::CIRDialect::getSourceLanguageAttrName(),
120 cir::SourceLanguageAttr::get(&mlirContext, *sourceLanguage));
121 theModule->setAttr(cir::CIRDialect::getTripleAttrName(),
122 builder.getStringAttr(
getTriple().str()));
124 if (cgo.OptimizationLevel > 0 || cgo.OptimizeSize > 0)
125 theModule->setAttr(cir::CIRDialect::getOptInfoAttrName(),
126 cir::OptInfoAttr::get(&mlirContext,
127 cgo.OptimizationLevel,
132 FileID mainFileId = astContext.getSourceManager().getMainFileID();
134 *astContext.getSourceManager().getFileEntryForID(mainFileId);
137 theModule.setSymName(path);
138 theModule->setLoc(mlir::FileLineColLoc::get(&mlirContext, path,
154 auto &layout = astContext.getASTRecordLayout(rd);
159 return layout.getAlignment();
162 return layout.getNonVirtualAlignment();
176 if (
unsigned align = tt->getDecl()->getMaxAlignment()) {
179 return astContext.toCharUnitsFromBits(align);
185 t = astContext.getBaseElementType(t);
207 alignment = astContext.getTypeAlignInChars(t);
212 if (
unsigned maxAlign = astContext.getLangOpts().MaxTypeAlign) {
214 !astContext.isAlignmentRequired(t))
221 if (theTargetCIRGenInfo)
222 return *theTargetCIRGenInfo;
225 switch (triple.getArch()) {
232 case llvm::Triple::x86_64: {
233 switch (triple.getOS()) {
240 case llvm::Triple::Linux:
242 return *theTargetCIRGenInfo;
249 assert(cLoc.
isValid() &&
"expected valid source location");
253 return mlir::FileLineColLoc::get(builder.getStringAttr(filename),
258 assert(cRange.
isValid() &&
"expected a valid source range");
261 mlir::Attribute metadata;
262 return mlir::FusedLoc::get({begin, end}, metadata, builder.getContext());
271 false, isForDefinition);
305 assert(op &&
"expected a valid global op");
313 mlir::Operation *globalValueOp = op;
314 if (
auto gv = dyn_cast<cir::GetGlobalOp>(op))
316 mlir::SymbolTable::lookupSymbolIn(
getModule(), gv.getNameAttr());
318 if (
auto cirGlobalValue =
319 dyn_cast<cir::CIRGlobalValueInterface>(globalValueOp))
320 if (!cirGlobalValue.isDeclaration())
345 std::vector<GlobalDecl> curDeclsToEmit;
362 if (
const auto *cd = dyn_cast<clang::OpenACCConstructDecl>(gd.
getDecl())) {
375 if (
const auto *fd = dyn_cast<FunctionDecl>(global)) {
378 if (fd->hasAttr<AnnotateAttr>())
379 errorNYI(fd->getSourceRange(),
"deferredAnnotations");
380 if (!fd->doesThisDeclarationHaveABody()) {
381 if (!fd->doesDeclarationForceExternallyVisibleDefinition())
385 "function declaration that forces code gen");
390 assert(vd->isFileVarDecl() &&
"Cannot emit local var decl as global.");
392 !astContext.isMSStaticDataMemberInlineDefinition(vd)) {
396 if (astContext.getInlineVariableDefinitionKind(vd) ==
435 mlir::Operation *op) {
439 cir::FuncOp funcOp = dyn_cast_if_present<cir::FuncOp>(op);
440 if (!funcOp || funcOp.getFunctionType() != funcType) {
446 if (!funcOp.isDeclaration())
458 mlir::OpBuilder::InsertionGuard guard(builder);
463 setNonAliasAttributes(gd, funcOp);
466 auto getPriority = [
this](
const auto *
attr) ->
int {
470 return attr->DefaultPriority;
473 if (
const ConstructorAttr *ca = funcDecl->getAttr<ConstructorAttr>())
475 if (
const DestructorAttr *da = funcDecl->getAttr<DestructorAttr>())
478 if (funcDecl->getAttr<AnnotateAttr>())
479 errorNYI(funcDecl->getSourceRange(),
"deferredAnnotations");
484 std::optional<int> priority) {
493 ctor.setGlobalCtorPriority(priority);
498 std::optional<int> priority) {
499 if (codeGenOpts.RegisterGlobalDtorsWithAtExit &&
501 errorNYI(dtor.getLoc(),
"registerGlobalDtorsWithAtExit");
504 dtor.setGlobalDtorPriority(priority);
522 return mlir::SymbolTable::lookupSymbolIn(theModule, name);
526 mlir::Location loc, StringRef name,
527 mlir::Type t,
bool isConstant,
528 mlir::Operation *insertPoint) {
533 mlir::OpBuilder::InsertionGuard guard(builder);
539 builder.setInsertionPoint(insertPoint);
545 builder.setInsertionPointToStart(cgm.
getModule().getBody());
548 g = cir::GlobalOp::create(builder, loc, name, t, isConstant);
554 mlir::SymbolTable::setSymbolVisibility(
555 g, mlir::SymbolTable::Visibility::Private);
562 if (isa_and_nonnull<NamedDecl>(d))
568void CIRGenModule::setNonAliasAttributes(
GlobalDecl gd, mlir::Operation *op) {
579std::optional<cir::SourceLanguage> CIRGenModule::getCIRSourceLanguage()
const {
581 using CIRLang = cir::SourceLanguage;
586 if (opts.C99 || opts.C11 || opts.C17 || opts.C23 || opts.C2y ||
587 opts.LangStd == ClangStd::lang_c89 ||
588 opts.LangStd == ClangStd::lang_gnu89)
593 errorNYI(
"CIR does not yet support the given source language");
605 gv.
setLinkage(cir::GlobalLinkageKind::ExternalWeakLinkage);
624 LangAS langAS,
const VarDecl *d,
641 if (entry.getSymType() == ty)
650 if (isForDefinition && !entry.isDeclaration()) {
659 if (!isForDefinition)
669 entry.getOperation());
684 if (langOpts.OpenMP && !langOpts.OpenMPSimd)
687 gv.setAlignmentAttr(
getSize(astContext.getDeclAlign(d)));
691 astContext,
false,
false));
705 if (astContext.isMSStaticDataMemberInlineDefinition(d))
712 if (
getTriple().getArch() == llvm::Triple::xcore)
722 "external const declaration with initializer");
756 mlir::Type ptrTy = builder.getPointerTo(g.getSymType());
758 g.getSymNameAttr(), tlsAccess);
767 cir::PointerType ptrTy = builder.getPointerTo(globalOp.getSymType());
768 return builder.getGlobalViewAttr(ptrTy, globalOp);
781 bool isDefinitionAvailableExternally =
786 if (isDefinitionAvailableExternally &&
794 mlir::Attribute init;
795 bool needsGlobalCtor =
false;
796 bool needsGlobalDtor =
797 !isDefinitionAvailableExternally &&
802 std::optional<ConstantEmitter> emitter;
806 if (vd->
hasAttr<LoaderUninitializedAttr>()) {
809 }
else if (!initExpr) {
822 emitter.emplace(*
this);
823 mlir::Attribute initializer = emitter->tryEmitForInitializer(*initDecl);
833 if (!isDefinitionAvailableExternally)
834 needsGlobalCtor =
true;
848 if (mlir::isa<mlir::SymbolRefAttr>(init)) {
852 assert(mlir::isa<mlir::TypedAttr>(init) &&
"This should have a type");
853 auto typedInitAttr = mlir::cast<mlir::TypedAttr>(init);
854 initType = typedInitAttr.getType();
856 assert(!mlir::isa<mlir::NoneType>(initType) &&
"Should have a type by now");
862 if (!gv || gv.getSymType() != initType) {
869 if (vd->
hasAttr<AnnotateAttr>()) {
880 emitter->finalize(gv);
883 gv.setConstant((vd->
hasAttr<CUDAConstantAttr>() && langOpts.CUDAIsDevice) ||
884 (!needsGlobalCtor && !needsGlobalDtor &&
886 astContext,
true,
true)));
890 cir::GlobalLinkageKind linkage =
894 gv.setLinkage(linkage);
898 if (linkage == cir::GlobalLinkageKind::CommonLinkage) {
900 gv.setConstant(
false);
905 std::optional<mlir::Attribute> initializer = gv.getInitialValue();
906 if (initializer && !
getBuilder().isNullValue(*initializer))
907 gv.setLinkage(cir::GlobalLinkageKind::WeakAnyLinkage);
910 setNonAliasAttributes(vd, gv);
917 if (needsGlobalCtor || needsGlobalDtor)
922 mlir::Operation *op) {
924 if (
const auto *fd = dyn_cast<FunctionDecl>(
decl)) {
928 if (
const auto *method = dyn_cast<CXXMethodDecl>(
decl)) {
932 abi->emitCXXStructor(gd);
933 else if (fd->isMultiVersion())
934 errorNYI(method->getSourceRange(),
"multiversion functions");
938 if (method->isVirtual())
944 if (fd->isMultiVersion())
945 errorNYI(fd->getSourceRange(),
"multiversion functions");
950 if (
const auto *vd = dyn_cast<VarDecl>(
decl))
953 llvm_unreachable(
"Invalid argument to CIRGenModule::emitGlobalDefinition");
967 astContext.getAsConstantArrayType(e->
getType());
968 uint64_t finalSize = cat->getZExtSize();
969 str.resize(finalSize);
971 mlir::Type eltTy =
convertType(cat->getElementType());
972 return builder.getString(str, eltTy, finalSize);
977 auto arrayEltTy = mlir::cast<cir::IntType>(arrayTy.getElementType());
979 uint64_t arraySize = arrayTy.getSize();
981 assert(arraySize == literalSize + 1 &&
982 "wide string literal array size must be literal length plus null "
987 bool isAllZero =
true;
988 for (
unsigned i = 0; i < literalSize; ++i) {
996 return cir::ZeroAttr::get(arrayTy);
1000 elements.reserve(arraySize);
1001 for (
unsigned i = 0; i < literalSize; ++i)
1002 elements.push_back(cir::IntAttr::get(arrayEltTy, e->
getCodeUnit(i)));
1004 elements.push_back(cir::IntAttr::get(arrayEltTy, 0));
1006 auto elementsAttr = mlir::ArrayAttr::get(&
getMLIRContext(), elements);
1007 return builder.getConstArray(elementsAttr, arrayTy);
1018 if (d.
hasAttr<SelectAnyAttr>())
1022 if (
auto *vd = dyn_cast<VarDecl>(&d))
1037 llvm_unreachable(
"No such linkage");
1043 if (
auto globalOp = dyn_cast_or_null<cir::GlobalOp>(op)) {
1044 globalOp.setComdat(
true);
1047 funcOp.setComdat(
true);
1053 genTypes.updateCompletedType(td);
1057 replacements[name] = op;
1060void CIRGenModule::replacePointerTypeArgs(cir::FuncOp oldF, cir::FuncOp newF) {
1061 std::optional<mlir::SymbolTable::UseRange> optionalUseRange =
1062 oldF.getSymbolUses(theModule);
1063 if (!optionalUseRange)
1066 for (
const mlir::SymbolTable::SymbolUse &u : *optionalUseRange) {
1068 auto call = mlir::dyn_cast<cir::CallOp>(u.getUser());
1072 for (
const auto [argOp, fnArgType] :
1073 llvm::zip(call.getArgs(), newF.getFunctionType().getInputs())) {
1074 if (argOp.getType() == fnArgType)
1080 errorNYI(call.getLoc(),
"replace call with mismatched types");
1085void CIRGenModule::applyReplacements() {
1086 for (
auto &i : replacements) {
1087 StringRef mangledName = i.first();
1088 mlir::Operation *replacement = i.second;
1094 auto newF = dyn_cast<cir::FuncOp>(replacement);
1097 errorNYI(replacement->getLoc(),
"replacement is not a function");
1103 replacePointerTypeArgs(oldF, newF);
1106 if (oldF.replaceAllSymbolUses(newF.getSymNameAttr(), theModule).failed())
1107 llvm_unreachable(
"internal error, cannot RAUW symbol");
1109 newF->moveBefore(oldF);
1116 mlir::Location loc, StringRef name, mlir::Type ty,
1118 auto gv = mlir::dyn_cast_or_null<cir::GlobalOp>(
1119 mlir::SymbolTable::lookupSymbolIn(theModule, name));
1123 if (gv.getSymType() == ty)
1129 assert(gv.isDeclaration() &&
"Declaration has wrong type!");
1131 errorNYI(loc,
"createOrReplaceCXXRuntimeVariable: declaration exists with "
1142 mlir::SymbolTable::setSymbolVisibility(gv,
1146 !gv.hasAvailableExternallyLinkage()) {
1150 gv.setAlignmentAttr(
getSize(alignment));
1161 if ((noCommon || vd->
hasAttr<NoCommonAttr>()) && !vd->
hasAttr<CommonAttr>())
1172 if (vd->
hasAttr<SectionAttr>())
1178 if (vd->
hasAttr<PragmaClangBSSSectionAttr>() ||
1179 vd->
hasAttr<PragmaClangDataSectionAttr>() ||
1180 vd->
hasAttr<PragmaClangRelroSectionAttr>() ||
1181 vd->
hasAttr<PragmaClangRodataSectionAttr>())
1189 if (vd->
hasAttr<WeakImportAttr>())
1199 if (vd->
hasAttr<AlignedAttr>())
1206 for (
const FieldDecl *fd : rd->fields()) {
1207 if (fd->isBitField())
1209 if (fd->hasAttr<AlignedAttr>())
1234 return cir::GlobalLinkageKind::InternalLinkage;
1236 if (dd->
hasAttr<WeakAttr>()) {
1237 if (isConstantVariable)
1238 return cir::GlobalLinkageKind::WeakODRLinkage;
1239 return cir::GlobalLinkageKind::WeakAnyLinkage;
1244 return cir::GlobalLinkageKind::LinkOnceAnyLinkage;
1249 return cir::GlobalLinkageKind::AvailableExternallyLinkage;
1263 return !astContext.getLangOpts().AppleKext
1264 ? cir::GlobalLinkageKind::LinkOnceODRLinkage
1265 : cir::GlobalLinkageKind::InternalLinkage;
1279 return cir::GlobalLinkageKind::ExternalLinkage;
1282 return dd->
hasAttr<CUDAGlobalAttr>()
1283 ? cir::GlobalLinkageKind::ExternalLinkage
1284 : cir::GlobalLinkageKind::InternalLinkage;
1285 return cir::GlobalLinkageKind::WeakODRLinkage;
1293 return cir::GlobalLinkageKind::CommonLinkage;
1299 if (dd->
hasAttr<SelectAnyAttr>())
1300 return cir::GlobalLinkageKind::WeakODRLinkage;
1304 return cir::GlobalLinkageKind::ExternalLinkage;
1316 mlir::Operation *old, cir::FuncOp newFn) {
1318 auto oldFn = mlir::dyn_cast<cir::FuncOp>(old);
1326 if (oldFn->getAttrs().size() <= 1)
1328 "replaceUsesOfNonProtoTypeWithRealFunction: Attribute forwarding");
1331 newFn.setNoProto(oldFn.getNoProto());
1334 std::optional<mlir::SymbolTable::UseRange> symUses =
1335 oldFn.getSymbolUses(oldFn->getParentOp());
1336 for (
const mlir::SymbolTable::SymbolUse &use : symUses.value()) {
1337 mlir::OpBuilder::InsertionGuard guard(builder);
1339 if (
auto noProtoCallOp = mlir::dyn_cast<cir::CallOp>(use.getUser())) {
1340 builder.setInsertionPoint(noProtoCallOp);
1343 cir::CallOp realCallOp = builder.createCallOp(
1344 noProtoCallOp.getLoc(), newFn, noProtoCallOp.getOperands());
1347 noProtoCallOp.replaceAllUsesWith(realCallOp);
1348 noProtoCallOp.erase();
1349 }
else if (
auto getGlobalOp =
1350 mlir::dyn_cast<cir::GetGlobalOp>(use.getUser())) {
1352 getGlobalOp.getAddr().setType(
1353 cir::PointerType::get(newFn.getFunctionType()));
1356 "replaceUsesOfNonProtoTypeWithRealFunction: unexpected use");
1361cir::GlobalLinkageKind
1363 assert(!isConstant &&
"constant variables NYI");
1364 GVALinkage linkage = astContext.GetGVALinkageForVariable(vd);
1371 GVALinkage linkage = astContext.GetGVALinkageForFunction(d);
1373 if (
const auto *dtor = dyn_cast<CXXDestructorDecl>(d))
1382 StringRef globalName,
CharUnits alignment) {
1388 cgm, loc, globalName,
c.getType(), !cgm.
getLangOpts().WritableStrings);
1391 gv.setAlignmentAttr(cgm.
getSize(alignment));
1393 cir::GlobalLinkageKindAttr::get(cgm.
getBuilder().getContext(), lt));
1397 if (gv.isWeakForLinker()) {
1398 assert(cgm.
supportsCOMDAT() &&
"Only COFF uses weak string literals");
1401 cgm.
setDSOLocal(
static_cast<mlir::Operation *
>(gv));
1422 std::string result =
1425 assert(!mlir::SymbolTable::lookupSymbolIn(theModule, result));
1433 astContext.getAlignOfGlobalVarInChars(
s->getType(),
nullptr);
1441 if (!gv.getAlignment() ||
1442 uint64_t(alignment.
getQuantity()) > *gv.getAlignment())
1443 gv.setAlignmentAttr(
getSize(alignment));
1448 if (
getCXXABI().getMangleContext().shouldMangleStringLiteral(
s) &&
1451 "getGlobalForStringLiteral: mangle string literals");
1459 mlir::Location loc =
s->getBeginLoc().isValid()
1461 : builder.getUnknownLoc();
1462 auto typedC = llvm::cast<mlir::TypedAttr>(
c);
1464 cir::GlobalLinkageKind::PrivateLinkage, *
this,
1465 uniqueName, alignment);
1479 auto arrayTy = mlir::dyn_cast<cir::ArrayType>(gv.getSymType());
1480 assert(arrayTy &&
"String literal must be array");
1484 return builder.getGlobalViewAttr(ptrTy, gv);
1500 errorNYI(
"SYCL or OpenMP temp address space");
1510 "emitExplicitCastExprType");
1529 return cir::ConstantOp::create(
1530 builder, loc, builder.getDataMemberAttr(ty,
fieldDecl->getFieldIndex()));
1540 if (
auto *oid = dyn_cast<ObjCImplDecl>(
decl))
1541 errorNYI(oid->getSourceRange(),
"emitDeclConext: ObjCImplDecl");
1551 if (
decl->isTemplated())
1554 switch (
decl->getKind()) {
1557 decl->getDeclKindName());
1560 case Decl::CXXConversion:
1561 case Decl::CXXMethod:
1562 case Decl::Function: {
1565 if (!fd->isConsteval())
1571 case Decl::Decomposition:
1572 case Decl::VarTemplateSpecialization: {
1575 errorNYI(
decl->getSourceRange(),
"global variable decompositions");
1581 case Decl::OpenACCRoutine:
1584 case Decl::OpenACCDeclare:
1587 case Decl::OMPThreadPrivate:
1590 case Decl::OMPGroupPrivate:
1593 case Decl::OMPAllocate:
1596 case Decl::OMPCapturedExpr:
1599 case Decl::OMPDeclareReduction:
1602 case Decl::OMPDeclareMapper:
1605 case Decl::OMPRequires:
1610 case Decl::UsingDirective:
1611 case Decl::UsingEnum:
1612 case Decl::NamespaceAlias:
1614 case Decl::TypeAlias:
1620 case Decl::ClassTemplate:
1622 case Decl::CXXDeductionGuide:
1624 case Decl::FunctionTemplate:
1625 case Decl::StaticAssert:
1626 case Decl::TypeAliasTemplate:
1627 case Decl::UsingShadow:
1628 case Decl::VarTemplate:
1629 case Decl::VarTemplatePartialSpecialization:
1632 case Decl::CXXConstructor:
1635 case Decl::CXXDestructor:
1640 case Decl::LinkageSpec:
1641 case Decl::Namespace:
1645 case Decl::ClassTemplateSpecialization:
1646 case Decl::CXXRecord: {
1649 for (
auto *childDecl : crd->
decls())
1655 case Decl::FileScopeAsm:
1657 if (langOpts.CUDA && langOpts.CUDAIsDevice)
1660 if (langOpts.OpenMPIsTargetDevice)
1663 if (langOpts.SYCLIsDevice)
1666 std::string line = file_asm->getAsmString();
1667 globalScopeAsm.push_back(builder.getStringAttr(line));
1674 op.setInitialValueAttr(value);
1688 md->getParent()->getNumVBases() == 0)
1690 "getAddrAndTypeOfCXXStructor: MS ABI complete destructor");
1701 false, isForDefinition);
1703 return {fnType, fn};
1707 mlir::Type funcType,
bool forVTable,
1711 "consteval function should never be emitted");
1721 if (
const auto *dd = dyn_cast<CXXDestructorDecl>(gd.
getDecl())) {
1724 dd->getParent()->getNumVBases() == 0)
1726 "getAddrOfFunction: MS ABI complete destructor");
1732 false, isForDefinition);
1740 llvm::raw_svector_ostream
out(buffer);
1749 assert(ii &&
"Attempt to mangle unnamed decl.");
1751 const auto *fd = dyn_cast<FunctionDecl>(nd);
1755 }
else if (fd && fd->hasAttr<CUDAGlobalAttr>() &&
1771 if (
const auto *fd = dyn_cast<FunctionDecl>(nd)) {
1772 if (fd->isMultiVersion()) {
1774 "getMangledName: multi-version functions");
1779 "getMangledName: GPU relocatable device code");
1782 return std::string(
out.str());
1785static FunctionDecl *
1800 if (
auto *methodDecl = dyn_cast<CXXMethodDecl>(protoFunc);
1801 methodDecl && methodDecl->isImplicitObjectMemberFunction()) {
1803 paramTypes.insert(paramTypes.begin(), methodDecl->getThisType());
1806 fpt->getExtProtoInfo());
1817 params.reserve(fpt->getNumParams());
1820 for (
unsigned i = 0, e = fpt->getNumParams(); i != e; ++i) {
1824 nullptr, fpt->getParamType(i),
nullptr,
1827 params.push_back(parm);
1830 tempFunc->setParams(params);
1855 if (
const auto *cd = dyn_cast<CXXConstructorDecl>(canonicalGd.
getDecl())) {
1858 "getMangledName: C++ constructor without variants");
1867 auto result = manglings.insert(std::make_pair(mangledName, gd));
1868 return mangledDeclNames[canonicalGd] = result.first->first();
1872 assert(!d->
getInit() &&
"Cannot emit definite definitions here!");
1880 if (gv && !mlir::cast<cir::GlobalOp>(gv).isDeclaration())
1896 if (langOpts.EmitAllDecls)
1899 const auto *vd = dyn_cast<VarDecl>(global);
1901 ((codeGenOpts.KeepPersistentStorageVariables &&
1902 (vd->getStorageDuration() ==
SD_Static ||
1903 vd->getStorageDuration() ==
SD_Thread)) ||
1904 (codeGenOpts.KeepStaticConsts && vd->getStorageDuration() ==
SD_Static &&
1905 vd->getType().isConstQualified())))
1918 if (langOpts.OpenMP >= 50 && !langOpts.OpenMPSimd) {
1919 std::optional<OMPDeclareTargetDeclAttr *> activeAttr =
1920 OMPDeclareTargetDeclAttr::getActiveAttr(global);
1921 if (!activeAttr || (*activeAttr)->getLevel() != (
unsigned)-1)
1925 const auto *fd = dyn_cast<FunctionDecl>(global);
1932 if (fd->hasAttr<TargetVersionAttr>() && !fd->isMultiVersion())
1934 if (langOpts.SYCLIsDevice) {
1935 errorNYI(fd->getSourceRange(),
"mayBeEmittedEagerly: SYCL");
1939 const auto *vd = dyn_cast<VarDecl>(global);
1941 if (astContext.getInlineVariableDefinitionKind(vd) ==
1949 if (langOpts.OpenMP && langOpts.OpenMPUseTLS &&
1950 astContext.getTargetInfo().isTLSSupported() &&
isa<VarDecl>(global) &&
1952 !OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(global))
1955 assert((fd || vd) &&
1956 "Only FunctionDecl and VarDecl should hit this path so far.");
1961 cir::CIRGlobalValueInterface gv) {
1962 if (gv.hasLocalLinkage())
1965 if (!gv.hasDefaultVisibility() && !gv.hasExternalWeakLinkage())
1973 const llvm::Triple &tt = cgm.
getTriple();
1975 if (tt.isOSCygMing()) {
1984 cgm.
errorNYI(
"shouldAssumeDSOLocal: MinGW");
1990 if (tt.isOSBinFormatCOFF() && gv.hasExternalWeakLinkage())
1998 if (tt.isOSBinFormatCOFF() || (tt.isOSWindows() && tt.isOSBinFormatMachO()))
2002 if (!tt.isOSBinFormatELF())
2007 if (rm != llvm::Reloc::Static && !lOpts.PIE) {
2015 return !(lOpts.SemanticInterposition || lOpts.HalfNoSemanticInterposition);
2019 if (!gv.isDeclarationForLinker())
2025 if (rm == llvm::Reloc::PIC_ && gv.hasExternalWeakLinkage())
2032 if (cgOpts.DirectAccessExternalData) {
2038 if (
auto globalOp = dyn_cast<cir::GlobalOp>(gv.getOperation())) {
2071 if (
auto globalValue = dyn_cast<cir::CIRGlobalValueInterface>(op))
2091 return cir::TLS_Model::GeneralDynamic;
2093 return cir::TLS_Model::LocalDynamic;
2095 return cir::TLS_Model::InitialExec;
2097 return cir::TLS_Model::LocalExec;
2099 llvm_unreachable(
"Invalid TLS model!");
2103 assert(d.
getTLSKind() &&
"setting TLS mode on non-TLS var!");
2108 if (d.
getAttr<TLSModelAttr>())
2112 global.setTlsModel(tlm);
2117 bool isIncompleteFunction,
2137 if (fd->isInlineBuiltinDeclaration()) {
2139 bool hasBody = fd->
hasBody(fdBody);
2141 assert(hasBody &&
"Inline builtin declarations should always have an "
2152 std::optional<cir::InlineKind> existingInlineKind = f.getInlineKind();
2154 existingInlineKind && *existingInlineKind == cir::InlineKind::NoInline;
2155 bool isAlwaysInline = existingInlineKind &&
2156 *existingInlineKind == cir::InlineKind::AlwaysInline;
2160 if (!isAlwaysInline &&
2165 f.setInlineKind(cir::InlineKind::NoInline);
2180 if (
decl->hasAttr<NoInlineAttr>() && !isAlwaysInline) {
2182 f.setInlineKind(cir::InlineKind::NoInline);
2183 }
else if (
decl->hasAttr<AlwaysInlineAttr>() && !isNoInline) {
2186 f.setInlineKind(cir::InlineKind::AlwaysInline);
2190 if (!isAlwaysInline) {
2191 f.setInlineKind(cir::InlineKind::NoInline);
2197 if (
auto *fd = dyn_cast<FunctionDecl>(
decl)) {
2202 auto checkRedeclForInline = [](
const FunctionDecl *redecl) {
2203 return redecl->isInlineSpecified();
2205 if (any_of(
decl->redecls(), checkRedeclForInline))
2210 return any_of(pattern->
redecls(), checkRedeclForInline);
2212 if (checkForInline(fd)) {
2213 f.setInlineKind(cir::InlineKind::InlineHint);
2214 }
else if (codeGenOpts.getInlining() ==
2216 !fd->isInlined() && !isAlwaysInline) {
2217 f.setInlineKind(cir::InlineKind::NoInline);
2226 StringRef mangledName, mlir::Type funcType,
GlobalDecl gd,
bool forVTable,
2228 mlir::ArrayAttr extraAttrs) {
2237 if (
const auto *fd = cast_or_null<FunctionDecl>(d)) {
2239 if (
getLangOpts().OpenMPIsTargetDevice && fd->isDefined() && !dontDefer &&
2242 "getOrCreateCIRFunction: OpenMP target function");
2246 if (fd->isMultiVersion())
2247 errorNYI(fd->getSourceRange(),
"getOrCreateCIRFunction: multi-version");
2253 assert(mlir::isa<cir::FuncOp>(entry));
2258 if (d && !d->
hasAttr<DLLImportAttr>() && !d->
hasAttr<DLLExportAttr>()) {
2266 if (isForDefinition && fn && !fn.isDeclaration()) {
2269 if (fn && fn.getFunctionType() == funcType) {
2273 if (!isForDefinition) {
2281 auto *funcDecl = llvm::cast_or_null<FunctionDecl>(gd.
getDecl());
2282 bool invalidLoc = !funcDecl ||
2283 funcDecl->getSourceRange().getBegin().isInvalid() ||
2284 funcDecl->getSourceRange().getEnd().isInvalid();
2286 invalidLoc ? theModule->getLoc() :
getLoc(funcDecl->getSourceRange()),
2287 mangledName, mlir::cast<cir::FuncType>(funcType), funcDecl);
2298 auto symbolOp = mlir::cast<mlir::SymbolOpInterface>(entry);
2306 if (symbolOp.getSymbolUses(symbolOp->getParentOp()))
2320 assert(funcOp.getFunctionType() == funcType);
2327 if (isa_and_nonnull<CXXDestructorDecl>(d) &&
2357 fd = fd->getPreviousDecl()) {
2359 if (fd->doesThisDeclarationHaveABody()) {
2372 cir::FuncType funcType,
2376 mlir::OpBuilder::InsertionGuard guard(builder);
2384 builder.setInsertionPoint(cgf->
curFn);
2386 func = cir::FuncOp::create(builder, loc, name, funcType);
2391 func.setNoProto(
true);
2393 assert(func.isDeclaration() &&
"expected empty body");
2397 func.setLinkageAttr(cir::GlobalLinkageKindAttr::get(
2399 mlir::SymbolTable::setSymbolVisibility(
2400 func, mlir::SymbolTable::Visibility::Private);
2408 theModule.push_back(func);
2413 for (
const auto *
attr :
2427 fnOp.setBuiltin(
true);
2433 return cir::CtorKind::Default;
2435 return cir::CtorKind::Copy;
2437 return cir::CtorKind::Move;
2438 return cir::CtorKind::Custom;
2443 return cir::AssignKind::Copy;
2445 return cir::AssignKind::Move;
2446 llvm_unreachable(
"not a copy or move assignment operator");
2454 if (
const auto *dtor = dyn_cast<CXXDestructorDecl>(funcDecl)) {
2455 auto cxxDtor = cir::CXXDtorAttr::get(
2458 funcOp.setCxxSpecialMemberAttr(cxxDtor);
2462 if (
const auto *ctor = dyn_cast<CXXConstructorDecl>(funcDecl)) {
2464 auto cxxCtor = cir::CXXCtorAttr::get(
2466 kind, ctor->isTrivial());
2467 funcOp.setCxxSpecialMemberAttr(cxxCtor);
2471 const auto *method = dyn_cast<CXXMethodDecl>(funcDecl);
2472 if (method && (method->isCopyAssignmentOperator() ||
2473 method->isMoveAssignmentOperator())) {
2475 auto cxxAssign = cir::CXXAssignAttr::get(
2477 assignKind, method->isTrivial());
2478 funcOp.setCxxSpecialMemberAttr(cxxAssign);
2484 cir::FuncOp funcOp, StringRef name) {
2499 StringRef name, mlir::ArrayAttr,
2501 bool assumeConvergent) {
2502 if (assumeConvergent)
2503 errorNYI(
"createRuntimeFunction: assumeConvergent");
2513 entry.setDSOLocal(
true);
2519mlir::SymbolTable::Visibility
2523 if (op.isDeclaration())
2524 return mlir::SymbolTable::Visibility::Private;
2528mlir::SymbolTable::Visibility
2531 case cir::GlobalLinkageKind::InternalLinkage:
2532 case cir::GlobalLinkageKind::PrivateLinkage:
2533 return mlir::SymbolTable::Visibility::Private;
2534 case cir::GlobalLinkageKind::ExternalLinkage:
2535 case cir::GlobalLinkageKind::ExternalWeakLinkage:
2536 case cir::GlobalLinkageKind::LinkOnceODRLinkage:
2537 case cir::GlobalLinkageKind::AvailableExternallyLinkage:
2538 case cir::GlobalLinkageKind::CommonLinkage:
2539 case cir::GlobalLinkageKind::WeakAnyLinkage:
2540 case cir::GlobalLinkageKind::WeakODRLinkage:
2541 return mlir::SymbolTable::Visibility::Public;
2543 llvm::errs() <<
"visibility not implemented for '"
2544 << stringifyGlobalLinkageKind(glk) <<
"'\n";
2545 assert(0 &&
"not implemented");
2548 llvm_unreachable(
"linkage should be handled above!");
2552 clang::VisibilityAttr::VisibilityType visibility) {
2553 switch (visibility) {
2554 case clang::VisibilityAttr::VisibilityType::Default:
2555 return cir::VisibilityKind::Default;
2556 case clang::VisibilityAttr::VisibilityType::Hidden:
2557 return cir::VisibilityKind::Hidden;
2558 case clang::VisibilityAttr::VisibilityType::Protected:
2559 return cir::VisibilityKind::Protected;
2561 llvm_unreachable(
"unexpected visibility value");
2566 const clang::VisibilityAttr *va =
decl->getAttr<clang::VisibilityAttr>();
2567 cir::VisibilityAttr cirVisibility =
2570 cirVisibility = cir::VisibilityAttr::get(
2574 return cirVisibility;
2579 applyReplacements();
2581 theModule->setAttr(cir::CIRDialect::getModuleLevelAsmAttrName(),
2582 builder.getArrayAttr(globalScopeAsm));
2590 cir::FuncOp aliasee,
2591 cir::GlobalLinkageKind linkage) {
2593 auto *aliasFD = dyn_cast<FunctionDecl>(aliasGD.
getDecl());
2594 assert(aliasFD &&
"expected FunctionDecl");
2605 mangledName, fnType, aliasFD);
2606 alias.setAliasee(aliasee.getName());
2607 alias.setLinkage(linkage);
2611 mlir::SymbolTable::setSymbolVisibility(
2612 alias, mlir::SymbolTable::Visibility::Private);
2619 errorNYI(aliasFD->getSourceRange(),
"emitAliasForGlobal: previous uses");
2629 return genTypes.convertType(
type);
2636 return mlir::verify(theModule).succeeded();
2645 return builder.getConstNullPtrAttr(builder.getUInt8PtrTy());
2648 langOpts.ObjCRuntime.isGNUFamily()) {
2649 errorNYI(loc,
"getAddrOfRTTIDescriptor: Objc PtrType & Objc RT GUN");
2659 llvm::iterator_range<CastExpr::path_const_iterator> path) {
2666 assert(!base->isVirtual() &&
"Should not see virtual bases here!");
2671 const auto *baseDecl = base->getType()->castAsCXXRecordDecl();
2683 llvm::StringRef feature) {
2684 unsigned diagID = diags.getCustomDiagID(
2686 return diags.Report(loc, diagID) << feature;
2690 llvm::StringRef feature) {
2695 cir::LabelOp label) {
2696 [[maybe_unused]]
auto result =
2698 assert(result.second &&
2699 "attempting to map a blockaddress info that is already mapped");
2704 assert(result.second &&
2705 "attempting to map a blockaddress operation that is already mapped");
2709 cir::LabelOp label) {
2711 assert(result.second &&
2712 "attempting to map a blockaddress operation that is already mapped");
2716 cir::LabelOp newLabel) {
2719 "trying to update a blockaddress not previously mapped");
2720 assert(!it->second &&
"blockaddress already has a resolved label");
2722 it->second = newLabel;
Defines the clang::ASTContext interface.
static bool shouldAssumeDSOLocal(const CIRGenModule &cgm, cir::CIRGlobalValueInterface gv)
static cir::AssignKind getAssignKindFromDecl(const CXXMethodDecl *method)
static FunctionDecl * createOpenACCBindTempFunction(ASTContext &ctx, const IdentifierInfo *bindName, const FunctionDecl *protoFunc)
static bool shouldBeInCOMDAT(CIRGenModule &cgm, const Decl &d)
static void setWindowsItaniumDLLImport(CIRGenModule &cgm, bool isLocal, cir::FuncOp funcOp, StringRef name)
static std::string getMangledNameImpl(CIRGenModule &cgm, GlobalDecl gd, const NamedDecl *nd)
static cir::GlobalOp generateStringLiteral(mlir::Location loc, mlir::TypedAttr c, cir::GlobalLinkageKind lt, CIRGenModule &cgm, StringRef globalName, CharUnits alignment)
static CIRGenCXXABI * createCXXABI(CIRGenModule &cgm)
static bool isVarDeclStrongDefinition(const ASTContext &astContext, CIRGenModule &cgm, const VarDecl *vd, bool noCommon)
static void setLinkageForGV(cir::GlobalOp &gv, const NamedDecl *nd)
static cir::CtorKind getCtorKindFromDecl(const CXXConstructorDecl *ctor)
This file defines OpenACC nodes for declarative directives.
Defines the SourceManager interface.
__device__ __2f16 float __ockl_bool s
__device__ __2f16 float c
cir::PointerType getPointerTo(mlir::Type ty)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
TranslationUnitDecl * getTranslationUnitDecl() const
@ Strong
Strong definition.
@ WeakUnknown
Weak for now, might become strong later in this TU.
bool DeclMustBeEmitted(const Decl *D)
Determines if the decl can be CodeGen'ed or deserialized from PCH lazily, only when used; this is onl...
void Deallocate(void *Ptr) const
GVALinkage GetGVALinkageForFunction(const FunctionDecl *FD) const
bool isAlignmentRequired(const Type *T) const
Determine if the alignment the type has was required using an alignment attribute.
int64_t toBits(CharUnits CharSize) const
Convert a size in characters to a size in bits.
GVALinkage GetGVALinkageForVariable(const VarDecl *VD) const
unsigned getTypeAlignIfKnown(QualType T, bool NeedsPreferredAlignment=false) const
Return the alignment of a type, in bits, or 0 if the type is incomplete and we cannot determine the a...
QualType getFunctionType(QualType ResultTy, ArrayRef< QualType > Args, const FunctionProtoType::ExtProtoInfo &EPI) const
Return a normal function type with a typed argument list.
const TargetInfo & getTargetInfo() const
TargetCXXABI::Kind getCXXABIKind() const
Return the C++ ABI kind that should be used.
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.
Implements C++ ABI-specific code generation functions.
virtual mlir::Attribute getAddrOfRTTIDescriptor(mlir::Location loc, QualType ty)=0
virtual void emitCXXConstructors(const clang::CXXConstructorDecl *d)=0
Emit constructor variants required by this ABI.
virtual void emitCXXDestructors(const clang::CXXDestructorDecl *d)=0
Emit dtor variants required by this ABI.
clang::MangleContext & getMangleContext()
Gets the mangle context.
virtual cir::GlobalLinkageKind getCXXDestructorLinkage(GVALinkage linkage, const CXXDestructorDecl *dtor, CXXDtorType dt) const
cir::FuncOp generateCode(clang::GlobalDecl gd, cir::FuncOp fn, cir::FuncType funcType)
void emitVariablyModifiedType(QualType ty)
mlir::Operation * curFn
The current function or global initializer that is generated code for.
This class organizes the cross-function state that is used while generating CIR code.
void updateResolvedBlockAddress(cir::BlockAddressOp op, cir::LabelOp newLabel)
void replaceUsesOfNonProtoTypeWithRealFunction(mlir::Operation *old, cir::FuncOp newFn)
This function is called when we implement a function with no prototype, e.g.
llvm::StringRef getMangledName(clang::GlobalDecl gd)
CharUnits computeNonVirtualBaseClassOffset(const CXXRecordDecl *derivedClass, llvm::iterator_range< CastExpr::path_const_iterator > path)
void setGlobalVisibility(mlir::Operation *op, const NamedDecl *d) const
Set the visibility for the given global.
DiagnosticBuilder errorNYI(SourceLocation, llvm::StringRef)
Helpers to emit "not yet implemented" error diagnostics.
void emitDeferred()
Emit any needed decls for which code generation was deferred.
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)
cir::FuncOp createRuntimeFunction(cir::FuncType ty, llvm::StringRef name, mlir::ArrayAttr={}, bool isLocal=false, bool assumeConvergent=false)
llvm::DenseMap< cir::BlockAddrInfoAttr, cir::LabelOp > blockAddressInfoToLabel
Map BlockAddrInfoAttr (function name, label name) to the corresponding CIR LabelOp.
void emitTopLevelDecl(clang::Decl *decl)
void emitOMPDeclareMapper(const OMPDeclareMapperDecl *d)
void addReplacement(llvm::StringRef name, mlir::Operation *op)
mlir::Type convertType(clang::QualType type)
bool shouldEmitRTTI(bool forEH=false)
cir::GlobalOp getGlobalForStringLiteral(const StringLiteral *s, llvm::StringRef name=".str")
Return a global symbol reference to a constant array for the given string literal.
void emitOMPCapturedExpr(const OMPCapturedExprDecl *d)
void mapUnresolvedBlockAddress(cir::BlockAddressOp op)
bool mustBeEmitted(const clang::ValueDecl *d)
Determine whether the definition must be emitted; if this returns false, the definition can be emitte...
void emitGlobalOpenACCDeclareDecl(const clang::OpenACCDeclareDecl *cd)
mlir::IntegerAttr getSize(CharUnits size)
CIRGenBuilderTy & getBuilder()
void setDSOLocal(mlir::Operation *op) const
std::string getUniqueGlobalName(const std::string &baseName)
std::pair< cir::FuncType, cir::FuncOp > getAddrAndTypeOfCXXStructor(clang::GlobalDecl gd, const CIRGenFunctionInfo *fnInfo=nullptr, cir::FuncType fnType=nullptr, bool dontDefer=false, ForDefinition_t isForDefinition=NotForDefinition)
void setGVProperties(mlir::Operation *op, const NamedDecl *d) const
Set visibility, dllimport/dllexport and dso_local.
cir::GlobalOp getOrCreateCIRGlobal(llvm::StringRef mangledName, mlir::Type ty, LangAS langAS, const VarDecl *d, ForDefinition_t isForDefinition)
If the specified mangled name is not in the module, create and return an mlir::GlobalOp value.
cir::FuncOp createCIRBuiltinFunction(mlir::Location loc, llvm::StringRef name, cir::FuncType ty, const clang::FunctionDecl *fd)
Create a CIR function with builtin attribute set.
void emitGlobalOpenACCRoutineDecl(const clang::OpenACCRoutineDecl *cd)
clang::CharUnits getClassPointerAlignment(const clang::CXXRecordDecl *rd)
Return the best known alignment for an unknown pointer to a particular class.
void handleCXXStaticMemberVarInstantiation(VarDecl *vd)
Tell the consumer that this variable has been instantiated.
void emitOMPRequiresDecl(const OMPRequiresDecl *d)
void emitGlobalDefinition(clang::GlobalDecl gd, mlir::Operation *op=nullptr)
void mapResolvedBlockAddress(cir::BlockAddressOp op, cir::LabelOp)
mlir::Attribute getAddrOfRTTIDescriptor(mlir::Location loc, QualType ty, bool forEH=false)
Get the address of the RTTI descriptor for the given type.
clang::CharUnits getNaturalTypeAlignment(clang::QualType t, LValueBaseInfo *baseInfo)
FIXME: this could likely be a common helper and not necessarily related with codegen.
void setFunctionAttributes(GlobalDecl gd, cir::FuncOp f, bool isIncompleteFunction, bool isThunk)
Set function attributes for a function declaration.
static mlir::SymbolTable::Visibility getMLIRVisibilityFromCIRLinkage(cir::GlobalLinkageKind GLK)
const clang::TargetInfo & getTarget() const
const llvm::Triple & getTriple() const
static mlir::SymbolTable::Visibility getMLIRVisibility(Visibility v)
void emitTentativeDefinition(const VarDecl *d)
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.
void emitOMPAllocateDecl(const OMPAllocateDecl *d)
void emitGlobalDecl(const clang::GlobalDecl &d)
Helper for emitDeferred to apply actual codegen.
cir::FuncOp getOrCreateCIRFunction(llvm::StringRef mangledName, mlir::Type funcType, clang::GlobalDecl gd, bool forVTable, bool dontDefer=false, bool isThunk=false, ForDefinition_t isForDefinition=NotForDefinition, mlir::ArrayAttr extraAttrs={})
void emitGlobalVarDefinition(const clang::VarDecl *vd, bool isTentative=false)
void setTLSMode(mlir::Operation *op, const VarDecl &d)
Set TLS mode for the given operation based on the given variable declaration.
cir::FuncOp getAddrOfFunction(clang::GlobalDecl gd, mlir::Type funcType=nullptr, bool forVTable=false, bool dontDefer=false, ForDefinition_t isForDefinition=NotForDefinition)
Return the address of the given function.
void emitAliasForGlobal(llvm::StringRef mangledName, mlir::Operation *op, GlobalDecl aliasGD, cir::FuncOp aliasee, cir::GlobalLinkageKind linkage)
mlir::Value emitMemberPointerConstant(const UnaryOperator *e)
void emitGlobalOpenACCDecl(const clang::OpenACCConstructDecl *cd)
bool verifyModule() const
void emitExplicitCastExprType(const ExplicitCastExpr *e, CIRGenFunction *cgf=nullptr)
Emit type info if type of an expression is a variably modified type.
std::map< llvm::StringRef, clang::GlobalDecl > deferredDecls
This contains all the decls which have definitions but which are deferred for emission and therefore ...
mlir::Value getAddrOfGlobalVar(const VarDecl *d, mlir::Type ty={}, ForDefinition_t isForDefinition=NotForDefinition)
Return the mlir::Value for the address of the given global variable.
static void setInitializer(cir::GlobalOp &op, mlir::Attribute value)
cir::GlobalViewAttr getAddrOfGlobalVarAttr(const VarDecl *d)
Return the mlir::GlobalViewAttr for the address of the given global.
void addGlobalCtor(cir::FuncOp ctor, std::optional< int > priority=std::nullopt)
Add a global constructor or destructor to the module.
cir::GlobalLinkageKind getFunctionLinkage(GlobalDecl gd)
void updateCompletedType(const clang::TagDecl *td)
const clang::CodeGenOptions & getCodeGenOpts() const
const clang::LangOptions & getLangOpts() const
void emitOpenACCRoutineDecl(const clang::FunctionDecl *funcDecl, cir::FuncOp func, SourceLocation pragmaLoc, ArrayRef< const OpenACCClause * > clauses)
cir::TLS_Model getDefaultCIRTLSModel() const
Get TLS mode from CodeGenOptions.
void addGlobalDtor(cir::FuncOp dtor, std::optional< int > priority=std::nullopt)
Add a function to the list that will be called when the module is unloaded.
void addDeferredDeclToEmit(clang::GlobalDecl GD)
cir::FuncOp createCIRFunction(mlir::Location loc, llvm::StringRef name, cir::FuncType funcType, const clang::FunctionDecl *funcDecl)
const TargetCIRGenInfo & getTargetCIRGenInfo()
void emitCXXGlobalVarDeclInitFunc(const VarDecl *vd, cir::GlobalOp addr, bool performInit)
void setGVPropertiesAux(mlir::Operation *op, const NamedDecl *d) const
LangAS getLangTempAllocaAddressSpace() const
Returns the address space for temporary allocations in the language.
llvm::DenseSet< cir::BlockAddressOp > unresolvedBlockAddressToLabel
Track CIR BlockAddressOps that cannot be resolved immediately because their LabelOp has not yet been ...
mlir::Location getLoc(clang::SourceLocation cLoc)
Helpers to convert the presumed location of Clang's SourceLocation to an MLIR Location.
llvm::DenseMap< mlir::Attribute, cir::GlobalOp > constantStringMap
mlir::Operation * lastGlobalOp
static cir::VisibilityKind getGlobalVisibilityKindFromClangVisibility(clang::VisibilityAttr::VisibilityType visibility)
llvm::StringMap< unsigned > cgGlobalNames
void setCXXSpecialMemberAttr(cir::FuncOp funcOp, const clang::FunctionDecl *funcDecl)
Mark the function as a special member (e.g. constructor, destructor)
mlir::Operation * getGlobalValue(llvm::StringRef ref)
void emitOMPDeclareReduction(const OMPDeclareReductionDecl *d)
mlir::ModuleOp getModule() const
bool supportsCOMDAT() const
cir::GlobalLinkageKind getCIRLinkageForDeclarator(const DeclaratorDecl *dd, GVALinkage linkage, bool isConstantVariable)
mlir::MLIRContext & getMLIRContext()
mlir::Operation * getAddrOfGlobal(clang::GlobalDecl gd, ForDefinition_t isForDefinition=NotForDefinition)
static cir::GlobalOp createGlobalOp(CIRGenModule &cgm, mlir::Location loc, llvm::StringRef name, mlir::Type t, bool isConstant=false, mlir::Operation *insertPoint=nullptr)
void maybeSetTrivialComdat(const clang::Decl &d, mlir::Operation *op)
CIRGenCXXABI & getCXXABI() const
cir::GlobalViewAttr getAddrOfConstantStringFromLiteral(const StringLiteral *s, llvm::StringRef name=".str")
Return a global symbol reference to a constant array for the given string literal.
llvm::MapVector< cir::BlockAddressOp, cir::LabelOp > blockAddressToLabel
Map CIR BlockAddressOps directly to their resolved LabelOps.
void emitDeclContext(const DeclContext *dc)
void emitGlobal(clang::GlobalDecl gd)
Emit code for a single global function or variable declaration.
cir::LabelOp lookupBlockAddressInfo(cir::BlockAddrInfoAttr blockInfo)
bool mayBeEmittedEagerly(const clang::ValueDecl *d)
Determine whether the definition can be emitted eagerly, or should be delayed until the end of the tr...
cir::GlobalLinkageKind getCIRLinkageVarDefinition(const VarDecl *vd, bool isConstant)
void mapBlockAddress(cir::BlockAddrInfoAttr blockInfo, cir::LabelOp label)
void setCIRFunctionAttributesForDefinition(const clang::FunctionDecl *fd, cir::FuncOp f)
Set extra attributes (inline, etc.) for a function.
std::string getOpenACCBindMangledName(const IdentifierInfo *bindName, const FunctionDecl *attachedFunction)
void emitGlobalFunctionDefinition(clang::GlobalDecl gd, mlir::Operation *op)
CIRGenVTables & getVTables()
void setFunctionLinkage(GlobalDecl gd, cir::FuncOp f)
std::vector< clang::GlobalDecl > deferredDeclsToEmit
void emitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *d)
void emitOMPGroupPrivateDecl(const OMPGroupPrivateDecl *d)
mlir::Attribute getConstantArrayFromStringLiteral(const StringLiteral *e)
Return a constant array for the given string.
cir::VisibilityAttr getGlobalVisibilityAttrFromDecl(const Decl *decl)
void setCommonAttributes(GlobalDecl gd, mlir::Operation *op)
Set attributes which are common to any form of a global definition (alias, Objective-C method,...
const CIRGenFunctionInfo & arrangeGlobalDeclaration(GlobalDecl gd)
const CIRGenFunctionInfo & arrangeCXXMethodDeclaration(const clang::CXXMethodDecl *md)
C++ methods have some special rules and also have implicit parameters.
const CIRGenFunctionInfo & arrangeCXXStructorDeclaration(clang::GlobalDecl gd)
cir::FuncType getFunctionType(const CIRGenFunctionInfo &info)
Get the CIR function type for.
mlir::Type convertTypeForMem(clang::QualType, bool forBitField=false)
Convert type T into an mlir::Type.
void emitThunks(GlobalDecl gd)
Emit the associated thunks for the given global decl.
virtual cir::TargetAddressSpaceAttr getCIRAllocaAddressSpace() const
Get the address space for alloca.
Represents a base class of a C++ class.
Represents a C++ constructor within a class.
bool isMoveConstructor(unsigned &TypeQuals) const
Determine whether this constructor is a move constructor (C++11 [class.copy]p3), which can be used to...
bool isCopyConstructor(unsigned &TypeQuals) const
Whether this constructor is a copy constructor (C++ [class.copy]p2, which can be used to copy the cla...
bool isDefaultConstructor() const
Whether this constructor is a default constructor (C++ [class.ctor]p5), which can be used to default-...
Represents a static or instance method of a struct/union/class.
bool isMoveAssignmentOperator() const
Determine whether this is a move assignment operator.
bool isCopyAssignmentOperator() const
Determine whether this is a copy-assignment operator, regardless of whether it was declared implicitl...
Represents a C++ struct/union/class.
bool isEffectivelyFinal() const
Determine whether it's impossible for a class to be derived from this class.
bool hasDefinition() const
CharUnits - This is an opaque type for sizes expressed in character units.
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
static CharUnits One()
One - Construct a CharUnits quantity of one.
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
llvm::Reloc::Model RelocationModel
The name of the relocation model to use.
Represents the canonical version of C arrays with a specified constant size.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
Decl - This represents one declaration (or definition), e.g.
bool isWeakImported() const
Determine whether this is a weak-imported symbol.
FunctionDecl * getAsFunction() LLVM_READONLY
Returns the function itself, or the templated function if this is a function template.
static DeclContext * castToDeclContext(const Decl *)
llvm::iterator_range< specific_attr_iterator< T > > specific_attrs() const
virtual SourceRange getSourceRange() const LLVM_READONLY
Source range that this declaration covers.
Represents a ValueDecl that came out of a declarator.
A little helper class used to produce diagnostics.
Concrete class used by the front-end to report problems and issues.
ExplicitCastExpr - An explicit cast written in the source code.
This represents one expression.
llvm::APSInt EvaluateKnownConstInt(const ASTContext &Ctx) const
EvaluateKnownConstInt - Call EvaluateAsRValue and return the folded integer.
Represents a member of a struct/union/class.
Cached information about one file (either on disk or in the virtual file system).
StringRef tryGetRealPathName() const
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Represents a function declaration or definition.
static FunctionDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation NLoc, DeclarationName N, QualType T, TypeSourceInfo *TInfo, StorageClass SC, bool UsesFPIntrin=false, bool isInlineSpecified=false, bool hasWrittenPrototype=true, ConstexprSpecKind ConstexprKind=ConstexprSpecKind::Unspecified, const AssociatedConstraint &TrailingRequiresClause={})
bool hasPrototype() const
Whether this function has a prototype, either because one was explicitly written or because it was "i...
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
FunctionType - C99 6.7.5.3 - Function Declarators.
CallingConv getCallConv() const
GlobalDecl - represents a global declaration.
GlobalDecl getCanonicalDecl() const
KernelReferenceKind getKernelReferenceKind() const
GlobalDecl getWithDecl(const Decl *D)
CXXDtorType getDtorType() const
const Decl * getDecl() const
One of these records is kept for each identifier that is lexed.
StringRef getName() const
Return the actual identifier string.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
void setLinkage(Linkage L)
Linkage getLinkage() const
MangleContext - Context for tracking state which persists across multiple calls to the C++ name mangl...
bool shouldMangleDeclName(const NamedDecl *D)
void mangleName(GlobalDecl GD, raw_ostream &)
This represents a decl that may have a name.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
LinkageInfo getLinkageAndVisibility() const
Determines the linkage and visibility of this entity.
Represents a parameter to a function.
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
static ParmVarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
Represents an unpacked "presumed" location which can be presented to the user.
unsigned getColumn() const
Return the presumed column number of this location.
const char * getFilename() const
Return the presumed filename of this location.
unsigned getLine() const
Return the presumed line number of this location.
A (possibly-)qualified type.
LangAS getAddressSpace() const
Return the address space of this type.
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
bool isConstQualified() const
Determine whether this type is const-qualified.
bool isConstantStorage(const ASTContext &Ctx, bool ExcludeCtor, bool ExcludeDtor)
bool hasUnaligned() const
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
This class handles loading and caching of source files into memory.
PresumedLoc getPresumedLoc(SourceLocation Loc, bool UseLineDirectives=true) const
Returns the "presumed" location of a SourceLocation specifies.
A trivial tuple used to represent a source range.
SourceLocation getEnd() const
SourceLocation getBegin() const
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
StringLiteral - This represents a string literal expression, e.g.
unsigned getLength() const
uint32_t getCodeUnit(size_t i) const
StringRef getString() const
unsigned getCharByteWidth() const
Represents the declaration of a struct/union/class/enum.
bool isMicrosoft() const
Is this ABI an MSVC-compatible ABI?
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
bool isPointerType() const
bool isReferenceType() const
bool isVariablyModifiedType() const
Whether this type is a variably-modified type (C99 6.7.5).
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...
bool isObjCObjectPointerType() const
const T * getAs() const
Member-template getAs<specific type>'.
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Expr * getSubExpr() const
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Represents a variable declaration or definition.
TLSKind getTLSKind() const
DefinitionKind isThisDeclarationADefinition(ASTContext &) const
Check whether this declaration is a definition.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
bool hasFlexibleArrayInit(const ASTContext &Ctx) const
Whether this variable has a flexible array member initialized with one or more elements.
bool hasGlobalStorage() const
Returns true for all variables that do not have local storage.
bool hasConstantInitialization() const
Determine whether this variable has constant initialization.
VarDecl * getDefinition(ASTContext &)
Get the real (not just tentative) definition for this declaration.
QualType::DestructionKind needsDestruction(const ASTContext &Ctx) const
Would the destruction of this variable have any effect, and if so, what kind?
const Expr * getInit() const
bool hasExternalStorage() const
Returns true if a variable has extern or private_extern storage.
@ TLS_Dynamic
TLS with a dynamic initializer.
@ TLS_None
Not a TLS variable.
@ Definition
This declaration is definitely a definition.
DefinitionKind hasDefinition(ASTContext &) const
Check whether this variable is defined in this translation unit.
TemplateSpecializationKind getTemplateSpecializationKind() const
If this variable is an instantiation of a variable template or a static data member of a class templa...
const Expr * getAnyInitializer() const
Get the initializer for this variable, no matter which declaration it is attached to.
static bool isWeakForLinker(GlobalLinkageKind linkage)
Whether the definition of this global may be replaced at link time.
@ AttributedType
The l-value was considered opaque, so the alignment was determined from a type, but that type was an ...
@ Type
The l-value was considered opaque, so the alignment was determined from a type.
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
CIRGenCXXABI * CreateCIRGenItaniumCXXABI(CIRGenModule &cgm)
Creates and Itanium-family ABI.
std::unique_ptr< TargetCIRGenInfo > createX8664TargetCIRGenInfo(CIRGenTypes &cgt)
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const internal::VariadicDynCastAllOfMatcher< Decl, FieldDecl > fieldDecl
Matches field declarations.
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
GVALinkage
A more specific kind of linkage than enum Linkage.
@ GVA_AvailableExternally
@ SD_Thread
Thread storage duration.
@ SD_Static
Static storage duration.
@ Dtor_Complete
Complete object dtor.
LangAS
Defines the address space values used by the address space qualifier of QualType.
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
@ TSK_ExplicitInstantiationDefinition
This template specialization was instantiated from a template due to an explicit instantiation defini...
@ TSK_ImplicitInstantiation
This template specialization was implicitly instantiated from a template.
U cast(CodeGen::Address addr)
bool isExternallyVisible(Linkage L)
static bool globalCtorLexOrder()
static bool alignCXXRecordDecl()
static bool opFuncArmNewAttr()
static bool getRuntimeFunctionDecl()
static bool weakRefReference()
static bool opFuncOptNoneAttr()
static bool opGlobalSection()
static bool addressSpace()
static bool opFuncMinSizeAttr()
static bool opGlobalUnnamedAddr()
static bool opGlobalThreadLocal()
static bool sourceLanguageCases()
static bool opFuncAstDeclAttr()
static bool opFuncNoDuplicateAttr()
static bool opGlobalUsedOrCompilerUsed()
static bool stackProtector()
static bool moduleNameHash()
static bool opGlobalVisibility()
static bool setFunctionAttributes()
static bool setDLLStorageClass()
static bool opFuncUnwindTablesAttr()
static bool opFuncParameterAttributes()
static bool targetCIRGenInfoArch()
static bool opFuncExtraAttrs()
static bool opFuncNakedAttr()
static bool opFuncSection()
static bool attributeNoBuiltin()
static bool opGlobalDLLImportExport()
static bool opGlobalPartition()
static bool opGlobalWeakRef()
static bool setTargetAttributes()
static bool deferredCXXGlobalInit()
static bool opFuncOperandBundles()
static bool opFuncCallingConv()
static bool globalCtorAssociatedData()
static bool defaultVisibility()
static bool opFuncColdHotAttr()
static bool opFuncExceptions()
static bool opFuncArmStreamingAttr()
static bool deferredVtables()
static bool cudaSupport()
static bool opFuncMaybeHandleStaticInExternC()
static bool generateDebugInfo()
static bool targetCIRGenInfoOS()
static bool opFuncCPUAndFeaturesAttributes()
static bool maybeHandleStaticInExternC()
static bool setLLVMFunctionFEnvAttributes()
cir::TargetAddressSpaceAttr cirAllocaAddressSpace
mlir::Type uCharTy
ClangIR char.
unsigned char SizeSizeInBytes
unsigned char PointerAlignInBytes
cir::PointerType allocaInt8PtrTy
void* in alloca address space
cir::PointerType uInt8PtrTy
cir::PointerType voidPtrTy
void* in address space 0
LangStandard - Information about the properties of a particular language standard.