19#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
20#include "mlir/Dialect/OpenMP/Utils/Utils.h"
21#include "mlir/IR/SymbolTable.h"
24#include "clang/AST/Attrs.inc"
42#include "llvm/ADT/STLExtras.h"
43#include "llvm/ADT/StringExtras.h"
44#include "llvm/ADT/StringRef.h"
45#include "llvm/ADT/StringSwitch.h"
46#include "llvm/Support/raw_ostream.h"
50#include "mlir/Dialect/Ptr/IR/MemorySpaceInterfaces.h"
51#include "mlir/IR/Attributes.h"
52#include "mlir/IR/BuiltinOps.h"
53#include "mlir/IR/Location.h"
54#include "mlir/IR/MLIRContext.h"
55#include "mlir/IR/Operation.h"
56#include "mlir/IR/Verifier.h"
65 case TargetCXXABI::GenericItanium:
66 case TargetCXXABI::GenericAArch64:
67 case TargetCXXABI::AppleARM64:
68 case TargetCXXABI::GenericARM:
70 case TargetCXXABI::Microsoft:
73 case TargetCXXABI::Fuchsia:
74 case TargetCXXABI::iOS:
75 case TargetCXXABI::WatchOS:
76 case TargetCXXABI::GenericMIPS:
77 case TargetCXXABI::WebAssembly:
78 case TargetCXXABI::XL:
79 cgm.
errorNYI(
"createCXXABI: C++ ABI kind");
83 llvm_unreachable(
"invalid C++ ABI kind");
86CIRGenModule::CIRGenModule(mlir::MLIRContext &mlirContext,
90 : builder(mlirContext, *this), astContext(astContext),
93 theModule{
mlir::ModuleOp::create(
mlir::UnknownLoc::get(&mlirContext))},
94 diags(diags), target(astContext.getTargetInfo()),
95 abi(
createCXXABI(*this)), genTypes(*this), vtables(*this) {
102 langOpts.CPlusPlusModules &&
131 .toCharUnitsFromBits(
135 const unsigned charSize = target.getCharWidth();
138 const unsigned sizeTypeSize = target.getTypeWidth(target.getSizeType());
146 std::optional<cir::SourceLanguage> sourceLanguage = getCIRSourceLanguage();
149 cir::CIRDialect::getSourceLanguageAttrName(),
150 cir::SourceLanguageAttr::get(&mlirContext, *sourceLanguage));
151 if (langOpts.OpenCL || (langOpts.CUDAIsDevice &&
getTriple().isSPIRV())) {
154 langOpts.OpenCL ? langOpts.getOpenCLCompatibleVersion() : 200;
155 setOpenCLVersionAttr(cir::CIRDialect::getOpenCLVersionAttrName(), version);
156 if (langOpts.OpenCLCPlusPlus)
157 setOpenCLVersionAttr(cir::CIRDialect::getOpenCLCXXVersionAttrName(),
158 langOpts.OpenCLCPlusPlusVersion);
161 unsigned spirMajor = version / 100;
162 getModule()->setAttr(cir::CIRDialect::getOpenCLSPIRVersionAttrName(),
165 spirMajor > 1 ? 0 : 2));
168 getModule()->setAttr(cir::CIRDialect::getTripleAttrName(),
169 builder.getStringAttr(
getTriple().str()));
170 getModule()->setAttr(cir::CIRDialect::getTargetABIAttrName(),
171 builder.getStringAttr(
getTarget().getABI()));
176 llvm::StringMap<std::string> defaultCPUAndFeatures;
177 if (getCPUAndFeaturesAttributes(
GlobalDecl(), defaultCPUAndFeatures))
178 for (
const auto &[key, val] : defaultCPUAndFeatures)
179 getModule()->setAttr(key, builder.getStringAttr(val));
184 cir::CIRDialect::getCXXABIAttrName(),
187 if (llvm::VersionTuple sdkVersion =
getTarget().getSDKVersion();
189 getModule()->setAttr(cir::CIRDialect::getSDKVersionAttrName(),
190 builder.getStringAttr(sdkVersion.getAsString()));
191 if (langOpts.CUDA && !langOpts.CUID.empty())
192 getModule()->setAttr(cir::CIRDialect::getCUIDHashAttrName(),
193 builder.getStringAttr(astContext.getCUIDHash()));
196 getModule()->setAttr(cir::CIRDialect::getSizeTypeWidthAttrName(),
197 builder.getI32IntegerAttr(sizeTypeSize));
198 getModule()->setAttr(cir::CIRDialect::getIntTypeWidthAttrName(),
199 builder.getI32IntegerAttr(target.getIntWidth()));
205 cir::CIRDialect::getLoweringOptionsAttrName(),
206 cir::LoweringOptionsAttr::get(
209 langOpts.ThreadsafeStatics,
211 langOpts.CUDAIsDevice,
214 langOpts.SYCLIsDevice,
215 langOpts.GPURelocatableDeviceCode,
216 langOpts.OpenMP != 0,
217 langOpts.OpenMPIsTargetDevice,
219 static_cast<int32_t
>(langOpts.getClangABICompat()),
220 static_cast<int32_t
>(langOpts.LongDoubleSize),
221 cgo.EnableNoundefAttrs,
222 langOpts.getDefaultExceptionMode() ==
225 langOpts.RelativeCXXABIVTables));
227 if (cgo.OptimizationLevel > 0 || cgo.OptimizeSize > 0)
228 getModule()->setAttr(cir::CIRDialect::getOptInfoAttrName(),
229 cir::OptInfoAttr::get(&mlirContext,
230 cgo.OptimizationLevel,
234 cir::CIRDialect::getDefaultTlsModelAttrName(),
237 if (langOpts.OpenMP) {
238 mlir::omp::OffloadModuleOpts ompOpts(
239 langOpts.OpenMPTargetDebug, langOpts.OpenMPTeamSubscription,
240 langOpts.OpenMPThreadSubscription, langOpts.OpenMPNoThreadState,
241 langOpts.OpenMPNoNestedParallelism, langOpts.OpenMPIsTargetDevice,
242 getTriple().isGPU(), langOpts.OpenMPForceUSM, langOpts.OpenMP,
243 langOpts.OMPHostIRFile, langOpts.OMPTargetTriples, langOpts.NoGPULib);
244 mlir::omp::setOffloadModuleInterfaceAttributes(
getModule(), ompOpts);
245 mlir::omp::setOpenMPVersionAttribute(
getModule(), langOpts.OpenMP);
251 createOpenMPRuntime();
256 FileID mainFileId = astContext.getSourceManager().getMainFileID();
258 *astContext.getSourceManager().getFileEntryForID(mainFileId);
262 getModule()->setLoc(mlir::FileLineColLoc::get(&mlirContext, path,
270void CIRGenModule::setOpenCLVersionAttr(StringRef attrName,
unsigned version) {
272 attrName, cir::OpenCLVersionAttr::get(&
getMLIRContext(), version / 100,
273 (version % 100) / 10));
276void CIRGenModule::createCUDARuntime() {
280void CIRGenModule::createOpenMPRuntime() {
281 openMPRuntime = std::make_unique<CIRGenOpenMPRuntime>(*
this);
292 auto &layout = astContext.getASTRecordLayout(rd);
297 return layout.getAlignment();
300 return layout.getNonVirtualAlignment();
305 bool forPointeeType) {
315 if (
unsigned align = tt->getDecl()->getMaxAlignment()) {
318 return astContext.toCharUnitsFromBits(align);
326 t = astContext.getBaseElementType(t);
347 }
else if (forPointeeType && !alignForArray &&
351 alignment = astContext.getTypeAlignInChars(t);
356 if (
unsigned maxAlign = astContext.getLangOpts().MaxTypeAlign) {
358 !astContext.isAlignmentRequired(t))
372 if (theTargetCIRGenInfo)
373 return *theTargetCIRGenInfo;
376 switch (triple.getArch()) {
383 case llvm::Triple::x86_64: {
384 switch (triple.getOS()) {
391 case llvm::Triple::Linux:
393 return *theTargetCIRGenInfo;
396 case llvm::Triple::aarch64:
397 case llvm::Triple::aarch64_32:
398 case llvm::Triple::aarch64_be: {
400 return *theTargetCIRGenInfo;
402 case llvm::Triple::nvptx:
403 case llvm::Triple::nvptx64:
405 return *theTargetCIRGenInfo;
406 case llvm::Triple::amdgpu: {
408 return *theTargetCIRGenInfo;
410 case llvm::Triple::spir:
411 case llvm::Triple::spir64:
412 case llvm::Triple::spirv:
413 case llvm::Triple::spirv32:
414 case llvm::Triple::spirv64:
416 return *theTargetCIRGenInfo;
417 case llvm::Triple::systemz: {
420 if (triple.isOSzOS())
423 return *theTargetCIRGenInfo;
429 assert(cLoc.
isValid() &&
"expected valid source location");
433 return mlir::FileLineColLoc::get(builder.getStringAttr(filename),
438 assert(cRange.
isValid() &&
"expected a valid source range");
441 mlir::Attribute metadata;
442 return mlir::FusedLoc::get({begin, end}, metadata, builder.getContext());
451 false, isForDefinition);
485 assert(op &&
"expected a valid global op");
493 mlir::Operation *globalValueOp = op;
494 if (
auto gv = dyn_cast<cir::GetGlobalOp>(op)) {
496 assert(globalValueOp &&
"expected a valid global op");
499 if (
auto cirGlobalValue =
500 dyn_cast<cir::CIRGlobalValueInterface>(globalValueOp))
501 if (!cirGlobalValue.isDeclaration())
522 assert(deferredVTables.empty());
537 std::vector<GlobalDecl> curDeclsToEmit;
545 if (
const auto *fd = d.getDecl()->getAsFunction()) {
546 if (langOpts.SYCLIsDevice && fd->hasAttr<SYCLKernelEntryPointAttr>() &&
550 if (!fd->getAttr<SYCLKernelEntryPointAttr>()->isInvalidAttr()) {
579 os << (isa<VarDecl>(d) ?
".static." :
".intern.");
581 os << (isa<VarDecl>(d) ?
"__static__" :
"__intern__");
588 "printPostfixForExternalizedDecl: CUID is not specified");
597 if (!langOpts.OpenMPIsTargetDevice && !langOpts.CUDA)
600 const auto *aa = global->
getAttr<AliasAttr>();
608 const auto *aliaseeDecl = dyn_cast<ValueDecl>(aliaseeGD.getDecl());
609 if (langOpts.OpenMPIsTargetDevice)
610 return !aliaseeDecl ||
611 !OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(aliaseeDecl);
614 const bool hasDeviceAttr = global->
hasAttr<CUDADeviceAttr>();
615 const bool aliaseeHasDeviceAttr =
616 aliaseeDecl && aliaseeDecl->hasAttr<CUDADeviceAttr>();
618 if (langOpts.CUDAIsDevice)
619 return !hasDeviceAttr || !aliaseeHasDeviceAttr;
627 if (
const auto *cd = dyn_cast<clang::OpenACCConstructDecl>(gd.
getDecl())) {
635 if (global->hasAttr<WeakRefAttr>())
640 if (global->hasAttr<AliasAttr>()) {
648 if (langOpts.CUDA && !
getASTContext().shouldEmitCUDADecl(global))
651 if (langOpts.OpenMP) {
653 if (openMPRuntime && openMPRuntime->emitTargetGlobal(gd))
655 if (
auto *drd = dyn_cast<OMPDeclareReductionDecl>(global)) {
660 if (
auto *dmd = dyn_cast<OMPDeclareMapperDecl>(global)) {
667 if (
const auto *fd = dyn_cast<FunctionDecl>(global)) {
670 if (fd->hasAttr<AnnotateAttr>()) {
673 deferredAnnotations[mangledName] = fd;
675 if (!fd->doesThisDeclarationHaveABody()) {
676 if (!fd->doesDeclarationForceExternallyVisibleDefinition() &&
687 assert(vd->isFileVarDecl() &&
"Cannot emit local var decl as global.");
689 !astContext.isMSStaticDataMemberInlineDefinition(vd)) {
693 if (astContext.getInlineVariableDefinitionKind(vd) ==
708 if (
auto existing = dyn_cast_if_present<cir::CIRGlobalValueInterface>(
710 existing && !existing.isDeclaration())
738 mlir::Operation *op) {
742 cir::FuncOp funcOp = dyn_cast_if_present<cir::FuncOp>(op);
743 if (!funcOp || funcOp.getFunctionType() != funcType) {
749 if (!funcOp.isDeclaration())
761 mlir::OpBuilder::InsertionGuard guard(builder);
766 setNonAliasAttributes(gd, funcOp);
769 auto getPriority = [
this](
const auto *
attr) ->
int {
773 return attr->DefaultPriority;
776 if (
const ConstructorAttr *ca = funcDecl->getAttr<ConstructorAttr>())
778 if (
const DestructorAttr *da = funcDecl->getAttr<DestructorAttr>())
781 if (funcDecl->getAttr<AnnotateAttr>())
784 if (
getLangOpts().OpenMP && funcDecl->hasAttr<OMPDeclareTargetDeclAttr>())
790 std::optional<int> priority) {
799 ctor.setGlobalCtorPriority(priority);
804 std::optional<int> priority) {
805 if (codeGenOpts.RegisterGlobalDtorsWithAtExit &&
807 errorNYI(dtor.getLoc(),
"registerGlobalDtorsWithAtExit");
810 dtor.setGlobalDtorPriority(priority);
836 mlir::ptr::MemorySpaceAttrInterface addrSpace,
837 mlir::Operation *insertPoint) {
842 mlir::OpBuilder::InsertionGuard guard(builder);
848 builder.setInsertionPoint(insertPoint);
854 builder.setInsertionPointToStart(
getModule().getBody());
857 g = cir::GlobalOp::create(builder, loc, name, t, isConstant, addrSpace);
863 mlir::SymbolTable::setSymbolVisibility(
864 g, mlir::SymbolTable::Visibility::Private);
872 if (isa_and_nonnull<NamedDecl>(d))
876 if (
auto gvi = mlir::dyn_cast<cir::CIRGlobalValueInterface>(gv)) {
877 if (d && d->
hasAttr<UsedAttr>())
880 if (
const auto *vd = dyn_cast_if_present<VarDecl>(d);
881 vd && ((codeGenOpts.KeepPersistentStorageVariables &&
882 (vd->getStorageDuration() ==
SD_Static ||
883 vd->getStorageDuration() ==
SD_Thread)) ||
884 (codeGenOpts.KeepStaticConsts &&
886 vd->getType().isConstQualified())))
892static std::vector<std::string>
894 llvm::StringMap<bool> &featureMap) {
895 llvm::StringMap<bool> defaultFeatureMap;
899 std::vector<std::string> delta;
900 for (
const auto &[k, v] : featureMap) {
901 auto defaultIt = defaultFeatureMap.find(k);
902 if (defaultIt == defaultFeatureMap.end() || defaultIt->getValue() != v)
903 delta.push_back((v ?
"+" :
"-") + k.str());
909bool CIRGenModule::getCPUAndFeaturesAttributes(
910 GlobalDecl gd, llvm::StringMap<std::string> &attrs,
911 bool setTargetFeatures) {
917 std::vector<std::string> features;
921 const auto *fd = dyn_cast_or_null<FunctionDecl>(gd.
getDecl());
922 fd = fd ? fd->getMostRecentDecl() : fd;
923 const auto *td = fd ? fd->getAttr<TargetAttr>() :
nullptr;
924 const auto *tv = fd ? fd->getAttr<TargetVersionAttr>() :
nullptr;
925 assert((!td || !tv) &&
"both target_version and target specified");
926 const auto *sd = fd ? fd->getAttr<CPUSpecificAttr>() :
nullptr;
927 const auto *tc = fd ? fd->getAttr<TargetClonesAttr>() :
nullptr;
928 bool addedAttr =
false;
929 if (td || tv || sd || tc) {
930 llvm::StringMap<bool> featureMap;
931 astContext.getFunctionFeatureMap(featureMap, gd);
937 llvm::StringRef featureStr = td ? td->getFeaturesStr() : llvm::StringRef();
940 if (!featureStr.empty()) {
941 clang::ParsedTargetAttr parsedAttr =
943 if (!parsedAttr.
CPU.empty() &&
945 targetCPU = parsedAttr.
CPU;
948 if (!parsedAttr.
Tune.empty() &&
950 tuneCPU = parsedAttr.
Tune;
966 features.reserve(features.size() + featureMap.size());
967 for (
const auto &entry : featureMap)
968 features.push_back((entry.getValue() ?
"+" :
"-") +
969 entry.getKey().str());
974 llvm::StringMap<bool> featureMap;
976 astContext.getFunctionFeatureMap(featureMap, gd);
987 if (!targetCPU.empty()) {
988 attrs[cir::CIRDialect::getTargetCPUAttrName()] = targetCPU.str();
991 if (!tuneCPU.empty()) {
992 attrs[cir::CIRDialect::getTuneCPUAttrName()] = tuneCPU.str();
995 if (!features.empty() && setTargetFeatures) {
996 llvm::erase_if(features, [&](
const std::string &f) {
997 assert(!f.empty() && (f[0] ==
'+' || f[0] ==
'-') &&
998 "feature string must start with '+' or '-'");
1001 llvm::sort(features);
1002 attrs[cir::CIRDialect::getTargetFeaturesAttrName()] =
1003 llvm::join(features,
",");
1011void CIRGenModule::setNonAliasAttributes(GlobalDecl gd, mlir::Operation *op) {
1016 if (
auto gvi = mlir::dyn_cast<cir::CIRGlobalValueInterface>(op)) {
1017 if (
const auto *sa = d->
getAttr<SectionAttr>())
1018 gvi.setSection(builder.getStringAttr(sa->getName()));
1022 if (
auto func = dyn_cast<cir::FuncOp>(op)) {
1023 llvm::StringMap<std::string> attrs;
1024 if (getCPUAndFeaturesAttributes(gd, attrs)) {
1031 for (llvm::StringRef name :
1032 {cir::CIRDialect::getTargetCPUAttrName(),
1033 cir::CIRDialect::getTuneCPUAttrName(),
1034 cir::CIRDialect::getTargetFeaturesAttrName()})
1035 func->removeAttr(name);
1036 for (
const auto &[key, val] : attrs)
1037 func->setAttr(key, builder.getStringAttr(val));
1047std::optional<cir::SourceLanguage> CIRGenModule::getCIRSourceLanguage()
const {
1048 using ClangStd = clang::LangStandard;
1049 using CIRLang = cir::SourceLanguage;
1052 if (opts.OpenCLCPlusPlus)
1053 return CIRLang::OpenCLCXX;
1055 return CIRLang::OpenCLC;
1057 return CIRLang::CXX;
1058 if (opts.C99 || opts.C11 || opts.C17 || opts.C23 || opts.C2y ||
1059 opts.LangStd == ClangStd::lang_c89 ||
1060 opts.LangStd == ClangStd::lang_gnu89)
1065 errorNYI(
"CIR does not yet support the given source language");
1066 return std::nullopt;
1070 if (langOpts.OpenCL) {
1078 if (langOpts.SYCLIsDevice &&
1082 if (langOpts.CUDA && langOpts.CUDAIsDevice) {
1084 if (d->
hasAttr<CUDAConstantAttr>())
1086 if (d->
hasAttr<CUDASharedAttr>())
1088 if (d->
hasAttr<CUDADeviceAttr>())
1096 if (langOpts.OpenMP && d && d->
hasAttr<OMPAllocateDeclAttr>())
1110 gv.
setLinkage(cir::GlobalLinkageKind::ExternalWeakLinkage);
1119 auto linkage = cir::GlobalLinkageKind::ExternalWeakLinkage;
1120 func.setLinkage(linkage);
1121 func.setLinkageAttr(
1122 cir::GlobalLinkageKindAttr::get(&cgm.
getMLIRContext(), linkage));
1124 if (!func.isDeclaration())
1125 mlir::SymbolTable::setSymbolVisibility(
1132 for (mlir::Attribute i : indexes) {
1133 auto ind = mlir::cast<mlir::IntegerAttr>(i);
1134 inds.push_back(ind.getValue().getSExtValue());
1140 return view.getSymbol().getValue() == glob.getSymName();
1144 cir::GlobalOp newGlob,
1145 cir::GlobalViewAttr
attr,
1156 mlir::Type newTy = newGlob.getSymType();
1162 return cir::GlobalOffsetAttr::get(
attr.getType(),
attr.getSymbol(),
1163 static_cast<int64_t>(offset));
1165 cir::PointerType newPtrTy;
1168 newPtrTy = cir::PointerType::get(newTy);
1174 attr.getAddressPoint());
1178 cgm.
errorNYI(
"Unhandled type in createNewGlobalView");
1184 mlir::Attribute oldInit) {
1185 if (
auto oldView = mlir::dyn_cast<cir::GlobalViewAttr>(oldInit))
1190 if (mlir::isa<cir::GlobalOffsetAttr>(oldInit))
1193 auto getNewInitElements =
1194 [&](mlir::ArrayAttr oldElements) -> mlir::ArrayAttr {
1196 for (mlir::Attribute elt : oldElements) {
1197 if (
auto view = mlir::dyn_cast<cir::GlobalViewAttr>(elt))
1199 else if (mlir::isa<cir::ConstArrayAttr, cir::ConstRecordAttr>(elt))
1202 newElements.push_back(elt);
1204 return mlir::ArrayAttr::get(cgm.
getBuilder().getContext(), newElements);
1207 if (
auto oldArray = mlir::dyn_cast<cir::ConstArrayAttr>(oldInit)) {
1213 mlir::Attribute oldElts = oldArray.getElts();
1214 if (mlir::isa<mlir::StringAttr>(oldElts))
1216 mlir::Attribute newElements =
1217 getNewInitElements(mlir::cast<mlir::ArrayAttr>(oldElts));
1219 newElements, mlir::cast<cir::ArrayType>(oldArray.getType()));
1221 if (
auto oldRecord = mlir::dyn_cast<cir::ConstRecordAttr>(oldInit)) {
1222 mlir::ArrayAttr newMembers = getNewInitElements(oldRecord.getMembers());
1223 auto recordTy = mlir::cast<cir::RecordType>(oldRecord.getType());
1229 cgm.
errorNYI(
"Unhandled type in getNewInitValue");
1237 assert(oldGV.getSymName() == newGV.getSymName() &&
"symbol names must match");
1239 mlir::Type oldTy = oldGV.getSymType();
1240 mlir::Type newTy = newGV.getSymType();
1245 assert(oldTy != newTy &&
"expected type change in replaceGlobal");
1248 std::optional<mlir::SymbolTable::UseRange> oldSymUses =
1250 for (mlir::SymbolTable::SymbolUse use : *oldSymUses) {
1251 mlir::Operation *userOp = use.getUser();
1253 (mlir::isa<cir::GetGlobalOp, cir::GlobalOp, cir::ConstantOp>(userOp)) &&
1254 "Unexpected user for global op");
1256 if (
auto getGlobalOp = dyn_cast<cir::GetGlobalOp>(use.getUser())) {
1257 mlir::Value useOpResultValue = getGlobalOp.getAddr();
1258 useOpResultValue.setType(cir::PointerType::get(newTy));
1260 mlir::OpBuilder::InsertionGuard guard(builder);
1261 builder.setInsertionPointAfter(getGlobalOp);
1262 mlir::Type ptrTy = builder.getPointerTo(oldTy);
1264 builder.createBitcast(getGlobalOp->getLoc(), useOpResultValue, ptrTy);
1265 useOpResultValue.replaceAllUsesExcept(
cast,
cast.getDefiningOp());
1266 }
else if (
auto glob = dyn_cast<cir::GlobalOp>(userOp)) {
1267 if (
auto init = glob.getInitialValue()) {
1268 mlir::Attribute nw =
getNewInitValue(*
this, newGV, oldTy, init.value());
1269 glob.setInitialValueAttr(nw);
1271 }
else if (
auto c = dyn_cast<cir::ConstantOp>(userOp)) {
1272 mlir::Attribute init =
getNewInitValue(*
this, newGV, oldTy, c.getValue());
1273 auto typedAttr = mlir::cast<mlir::TypedAttr>(init);
1274 mlir::OpBuilder::InsertionGuard guard(builder);
1275 builder.setInsertionPointAfter(c);
1276 auto newUser = cir::ConstantOp::create(builder, c.getLoc(), typedAttr);
1277 c.replaceAllUsesWith(newUser.getOperation());
1308 StringRef mangledName, mlir::Type ty,
LangAS langAS, mlir::Location loc,
1312 cir::GlobalOp entry;
1315 errorNYI(loc,
"getOrCreateCIRGlobal: global with non-GlobalOp type");
1322 mlir::ptr::MemorySpaceAttrInterface entryCIRAS = entry.getAddrSpaceAttr();
1325 if (weakRefReferences.erase(entry) && d && !d->
hasAttr<WeakAttr>())
1326 entry.setLinkage(cir::GlobalLinkageKind::ExternalLinkage);
1330 if (langOpts.OpenMP && !langOpts.OpenMPSimd && d)
1333 if (entry.getSymType() == ty &&
1344 if (isForDefinition && !entry.isDeclaration()) {
1345 errorNYI(loc,
"getOrCreateCIRGlobal: global with conflicting type");
1353 if (!isForDefinition)
1360 bool isConstant =
false;
1362 QualType declType = d->
getType();
1377 mlir::ptr::MemorySpaceAttrInterface declCIRAS =
1382 cir::GlobalOp gv =
createGlobalOp(loc, mangledName, ty, isConstant, declCIRAS,
1383 entry.getOperation());
1403 if (langOpts.OpenMP && !langOpts.OpenMPSimd)
1406 gv.setAlignmentAttr(
getSize(astContext.getDeclAlign(d)));
1417 if (astContext.isMSStaticDataMemberInlineDefinition(d))
1419 "getOrCreateCIRGlobal: MS static data member inline definition");
1423 if (
const SectionAttr *sa = d->
getAttr<SectionAttr>())
1424 gv.setSectionAttr(builder.getStringAttr(sa->getName()));
1428 if (
getTriple().getArch() == llvm::Triple::xcore)
1430 "getOrCreateCIRGlobal: XCore specific ABI requirements");
1440 "getOrCreateCIRGlobal: external const declaration with initializer");
1459 const auto *aa = vd->
getAttr<AliasAttr>();
1460 assert(aa &&
"No alias?");
1467 if (
const auto *fd = dyn_cast<FunctionDecl>(vd)) {
1468 auto fn = dyn_cast<cir::FuncOp>(entry);
1470 if (fn && fn.getFunctionType() ==
convertType(fd->getType()))
1472 }
else if (
auto gv = dyn_cast<cir::GlobalOp>(entry)) {
1478 "weakref target already declared with a different type");
1482 mlir::Operation *aliasee;
1483 if (
const auto *fd = dyn_cast<FunctionDecl>(vd)) {
1487 fn.setLinkage(cir::GlobalLinkageKind::ExternalWeakLinkage);
1494 gv.setLinkage(cir::GlobalLinkageKind::ExternalWeakLinkage);
1498 weakRefReferences.insert(aliasee);
1530 mlir::Type ptrTy = builder.getPointerTo(g.getSymType(), g.getAddrSpaceAttr());
1531 mlir::Value addr = cir::GetGlobalOp::create(
1534 g.getDynamicInitGuard().has_value() &&
1544 auto ptrTy = mlir::cast<cir::PointerType>(addr.getType());
1545 mlir::ptr::MemorySpaceAttrInterface declAS =
1547 if (ptrTy.getAddrSpace() == declAS)
1549 return builder.createAddrSpaceCast(
1550 addr, builder.getPointerTo(ptrTy.getPointee(), declAS));
1558 cir::PointerType ptrTy =
1559 builder.getPointerTo(globalOp.getSymType(), globalOp.getAddrSpaceAttr());
1560 return builder.getGlobalViewAttr(ptrTy, globalOp);
1564 assert((mlir::isa<cir::FuncOp>(gv.getOperation()) ||
1565 !gv.isDeclarationForLinker()) &&
1566 "Only globals with definition can force usage.");
1571 assert(!gv.isDeclarationForLinker() &&
1572 "Only globals with definition can force usage.");
1577 cir::CIRGlobalValueInterface gv) {
1578 assert((mlir::isa<cir::FuncOp>(gv.getOperation()) ||
1579 !gv.isDeclarationForLinker()) &&
1580 "Only globals with definition can force usage.");
1588 std::vector<cir::CIRGlobalValueInterface> &list) {
1593 mlir::Location loc = builder.getUnknownLoc();
1598 usedArray.resize(list.size());
1599 for (
auto [i, op] : llvm::enumerate(list)) {
1600 usedArray[i] = cir::GlobalViewAttr::get(
1601 voidPtrTy, mlir::FlatSymbolRefAttr::get(op.getNameAttr()));
1604 cir::ArrayType arrayTy = cir::ArrayType::get(voidPtrTy, usedArray.size());
1606 cir::ConstArrayAttr initAttr = cir::ConstArrayAttr::get(
1607 arrayTy, mlir::ArrayAttr::get(&cgm.
getMLIRContext(), usedArray));
1610 loc, name, arrayTy,
false,
1612 gv.setLinkage(cir::GlobalLinkageKind::AppendingLinkage);
1613 gv.setInitialValueAttr(initAttr);
1614 gv.setSectionAttr(builder.getStringAttr(
"llvm.metadata"));
1631 "emitGlobalVarDefinition: emit OpenMP global variable");
1638 bool isDefinitionAvailableExternally =
1643 if (isDefinitionAvailableExternally &&
1651 mlir::Attribute init;
1652 bool needsGlobalCtor =
false;
1653 bool needsGlobalDtor =
1654 !isDefinitionAvailableExternally &&
1659 std::optional<ConstantEmitter> emitter;
1664 bool isCUDASharedVar =
1669 bool isCUDAShadowVar =
1671 (vd->
hasAttr<CUDAConstantAttr>() || vd->
hasAttr<CUDADeviceAttr>() ||
1672 vd->
hasAttr<CUDASharedAttr>());
1673 bool isCUDADeviceShadowVar =
1679 (isCUDASharedVar || isCUDAShadowVar || isCUDADeviceShadowVar)) {
1681 }
else if (vd->
hasAttr<LoaderUninitializedAttr>()) {
1683 "emitGlobalVarDefinition: loader uninitialized attribute");
1684 }
else if (!initExpr) {
1697 emitter.emplace(*
this);
1698 mlir::Attribute initializer = emitter->tryEmitForInitializer(*initDecl);
1707 "emitGlobalVarDefinition: flexible array initializer");
1709 if (!isDefinitionAvailableExternally)
1710 needsGlobalCtor =
true;
1713 "emitGlobalVarDefinition: static initializer");
1724 mlir::Type initType;
1725 if (mlir::isa<mlir::SymbolRefAttr>(init)) {
1728 "emitGlobalVarDefinition: global initializer is a symbol reference");
1731 assert(mlir::isa<mlir::TypedAttr>(init) &&
"This should have a type");
1732 auto typedInitAttr = mlir::cast<mlir::TypedAttr>(init);
1733 initType = typedInitAttr.getType();
1735 assert(!mlir::isa<mlir::NoneType>(initType) &&
"Should have a type by now");
1741 if (!gv || gv.getSymType() != initType) {
1743 "emitGlobalVarDefinition: global initializer with type mismatch");
1749 if (vd->
hasAttr<AnnotateAttr>())
1762 if (langOpts.CUDA) {
1763 if (langOpts.CUDAIsDevice) {
1766 if (linkage != cir::GlobalLinkageKind::InternalLinkage &&
1768 (vd->
hasAttr<CUDADeviceAttr>() || vd->
hasAttr<CUDAConstantAttr>() ||
1771 gv->setAttr(cir::CUDAExternallyInitializedAttr::getMnemonic(),
1784 emitter->finalize(gv);
1788 gv.setConstant((vd->
hasAttr<CUDAConstantAttr>() && langOpts.CUDAIsDevice) ||
1789 (!needsGlobalCtor && !needsGlobalDtor &&
1794 if (
const SectionAttr *sa = vd->
getAttr<SectionAttr>()) {
1797 gv.setConstant(
true);
1802 gv.setAlignmentAttr(
getSize(astContext.getDeclAlign(vd)));
1805 gv.setLinkage(linkage);
1809 if (linkage == cir::GlobalLinkageKind::CommonLinkage) {
1811 gv.setConstant(
false);
1816 std::optional<mlir::Attribute> initializer = gv.getInitialValue();
1817 if (initializer && !
getBuilder().isNullValue(*initializer))
1818 gv.setLinkage(cir::GlobalLinkageKind::WeakAnyLinkage);
1821 setNonAliasAttributes(vd, gv);
1829 if (needsGlobalCtor || needsGlobalDtor) {
1852 cir::GlobalLinkageKind::AvailableExternallyLinkage)
1858 if (fd->isInlineBuiltinDeclaration())
1861 if (codeGenOpts.OptimizationLevel == 0 && !fd->hasAttr<AlwaysInlineAttr>())
1866 if (
const Module *m = fd->getOwningModule();
1868 getASTContext().getCurrentNamedModule() != m->getTopLevelModule()) {
1878 if (!fd->isTemplateInstantiation() || !fd->hasAttr<AlwaysInlineAttr>()) {
1883 if (fd->hasAttr<NoInlineAttr>())
1894 mlir::Operation *op) {
1896 if (
const auto *fd = dyn_cast<FunctionDecl>(
decl)) {
1900 if (
const auto *method = dyn_cast<CXXMethodDecl>(
decl)) {
1904 abi->emitCXXStructor(gd);
1905 else if (fd->isMultiVersion())
1906 errorNYI(method->getSourceRange(),
"multiversion functions");
1910 if (method->isVirtual())
1916 if (fd->isMultiVersion())
1917 errorNYI(fd->getSourceRange(),
"multiversion functions");
1922 if (
const auto *vd = dyn_cast<VarDecl>(
decl))
1925 llvm_unreachable(
"Invalid argument to CIRGenModule::emitGlobalDefinition");
1939 astContext.getAsConstantArrayType(e->
getType());
1940 uint64_t finalSize = cat->getZExtSize();
1941 str.resize(finalSize);
1943 mlir::Type eltTy =
convertType(cat->getElementType());
1944 return builder.getString(str, eltTy, finalSize,
false);
1949 auto arrayEltTy = mlir::cast<cir::IntType>(arrayTy.getElementType());
1951 uint64_t arraySize = arrayTy.getSize();
1953 assert(arraySize > literalSize &&
1954 "wide string literal array size must have room for null terminator?");
1958 bool isAllZero =
true;
1959 for (
unsigned i = 0; i < literalSize; ++i) {
1967 return cir::ZeroAttr::get(arrayTy);
1971 elements.reserve(arraySize);
1972 for (
unsigned i = 0; i < literalSize; ++i)
1973 elements.push_back(cir::IntAttr::get(
1974 arrayEltTy, llvm::APInt(arrayEltTy.getWidth(), e->
getCodeUnit(i))));
1976 auto elementsAttr = mlir::ArrayAttr::get(&
getMLIRContext(), elements);
1977 return builder.getConstArray(elementsAttr, arrayTy);
1987 if (
auto globalOp = dyn_cast_or_null<cir::GlobalOp>(op)) {
1988 globalOp.setSelfComdat();
1991 funcOp.setSelfComdat();
1997 genTypes.updateCompletedType(td);
2001 replacements[name] = op;
2007 for (mlir::Operation *user : users) {
2008 auto call = mlir::dyn_cast<cir::CallOp>(user);
2012 for (
auto [argOp, fnArgType] :
2013 llvm::zip(call.getArgs(), newF.getFunctionType().getInputs())) {
2014 if (argOp.getType() != fnArgType)
2023void CIRGenModule::applyReplacements() {
2024 if (replacements.empty())
2030 llvm::DenseMap<mlir::StringAttr, llvm::SetVector<mlir::Operation *>> users;
2031 for (
auto &i : replacements)
2032 users.try_emplace(mlir::StringAttr::get(&
getMLIRContext(), i.first));
2035 module->walk<mlir::WalkOrder::PreOrder>([&](mlir::Operation *op) {
2036 auto collect = [&](mlir::Attribute attr) {
2037 attr.walk<mlir::WalkOrder::PreOrder>(
2038 [&](mlir::SymbolRefAttr ref) {
2039 auto it = users.find(ref.getRootReference());
2040 if (it != users.end())
2041 it->second.insert(op);
2042 return mlir::WalkResult::skip();
2044 [&](mlir::Type
type) {
2045 return mlir::isa<cir::CIRDialect>(
type.getDialect())
2046 ? mlir::WalkResult::skip()
2047 : mlir::WalkResult::
advance();
2050 collect(op->getRawDictionaryAttrs());
2051 op->getName().walkInherentAttrs(
2052 op, [&](llvm::StringRef, mlir::Attribute &attr) { collect(attr); });
2054 if (op != module.getOperation() &&
2055 op->hasTrait<mlir::OpTrait::SymbolTable>())
2056 return mlir::WalkResult::skip();
2057 return mlir::WalkResult::advance();
2060 for (
auto &i : replacements) {
2061 StringRef mangledName = i.first;
2062 mlir::Operation *replacement = i.second;
2063 mlir::Operation *entry = getGlobalValue(mangledName);
2068 auto newF = dyn_cast<cir::FuncOp>(replacement);
2071 errorNYI(replacement->getLoc(),
"replacement is not a function");
2075 auto oldIt = users.find(oldF.getSymNameAttr());
2076 assert(oldIt != users.end() &&
"replaced function was not collected");
2077 llvm::ArrayRef<mlir::Operation *> oldUsers = oldIt->second.getArrayRef();
2079 "call argument types do not match replacement function");
2082 for (mlir::Operation *user : oldUsers)
2083 (void)mlir::SymbolTable::replaceAllSymbolUses(oldF, newF.getSymNameAttr(),
2086 auto newIt = users.find(newF.getSymNameAttr());
2087 if (newIt != users.end())
2088 newIt->second.set_union(oldIt->second);
2090 newF->moveBefore(oldF);
2091 eraseGlobalSymbol(oldF);
2097 mlir::Location loc, StringRef name, mlir::Type ty,
2099 auto gv = mlir::dyn_cast_or_null<cir::GlobalOp>(
getGlobalValue(name));
2103 if (gv.getSymType() == ty)
2109 assert(gv.isDeclaration() &&
"Declaration has wrong type!");
2111 errorNYI(loc,
"createOrReplaceCXXRuntimeVariable: declaration exists with "
2122 mlir::SymbolTable::setSymbolVisibility(gv,
2126 !gv.hasAvailableExternallyLinkage()) {
2130 gv.setAlignmentAttr(
getSize(alignment));
2135cir::GlobalLinkageKind
2139 return cir::GlobalLinkageKind::InternalLinkage;
2142 return cir::GlobalLinkageKind::WeakAnyLinkage;
2146 return cir::GlobalLinkageKind::LinkOnceAnyLinkage;
2151 return cir::GlobalLinkageKind::AvailableExternallyLinkage;
2165 return !astContext.getLangOpts().AppleKext
2166 ? cir::GlobalLinkageKind::LinkOnceODRLinkage
2167 : cir::GlobalLinkageKind::InternalLinkage;
2181 return cir::GlobalLinkageKind::ExternalLinkage;
2184 return dd->
hasAttr<CUDAGlobalAttr>()
2185 ? cir::GlobalLinkageKind::ExternalLinkage
2186 : cir::GlobalLinkageKind::InternalLinkage;
2187 return cir::GlobalLinkageKind::WeakODRLinkage;
2195 return cir::GlobalLinkageKind::CommonLinkage;
2201 if (dd->
hasAttr<SelectAnyAttr>())
2202 return cir::GlobalLinkageKind::WeakODRLinkage;
2206 return cir::GlobalLinkageKind::ExternalLinkage;
2218 mlir::Operation *old, cir::FuncOp newFn) {
2220 auto oldFn = mlir::dyn_cast<cir::FuncOp>(old);
2233 newFn.setNoProto(oldFn.getNoProto());
2236 std::optional<mlir::SymbolTable::UseRange> symUses =
2237 oldFn.getSymbolUses(oldFn->getParentOp());
2242 for (
const mlir::SymbolTable::SymbolUse &use : symUses.value()) {
2243 mlir::OpBuilder::InsertionGuard guard(builder);
2245 if (
auto noProtoCallOp = mlir::dyn_cast<cir::CallOp>(use.getUser())) {
2246 builder.setInsertionPoint(noProtoCallOp);
2249 cir::FuncType newFnType = newFn.getFunctionType();
2250 mlir::OperandRange callOperands = noProtoCallOp.getOperands();
2251 bool returnTypeMatches =
2252 newFnType.hasVoidReturn()
2253 ? noProtoCallOp.getNumResults() == 0
2254 : noProtoCallOp.getNumResults() == 1 &&
2255 noProtoCallOp.getResultTypes().front() ==
2256 newFnType.getReturnType();
2257 bool typesMatch = !newFn.getNoProto() && returnTypeMatches &&
2258 callOperands.size() == newFnType.getNumInputs();
2259 for (
unsigned i = 0, e = newFnType.getNumInputs(); typesMatch && i != e;
2261 if (callOperands[i].
getType() != newFnType.getInput(i))
2265 cir::CallOp realCallOp;
2269 builder.createCallOp(noProtoCallOp.getLoc(), newFn, callOperands);
2277 cir::FuncType origFnType = oldFn.getFunctionType();
2278 cir::FuncType callFnType =
2280 ? cir::FuncType::get(llvm::to_vector(callOperands.getTypes()),
2281 origFnType.getReturnType(),
2284 mlir::Value addr = cir::GetGlobalOp::create(
2285 builder, noProtoCallOp.getLoc(), cir::PointerType::get(newFnType),
2286 newFn.getSymName());
2287 mlir::Value casted =
2288 builder.createBitcast(addr, cir::PointerType::get(callFnType));
2289 realCallOp = builder.createIndirectCallOp(
2290 noProtoCallOp.getLoc(), casted, callFnType, callOperands);
2294 for (mlir::NamedAttribute
attr : noProtoCallOp->getAttrs())
2295 if (
attr.getName() != cir::CIRDialect::getCalleeAttrName())
2296 realCallOp->setAttr(
attr.getName(),
attr.getValue());
2299 noProtoCallOp.replaceAllUsesWith(realCallOp);
2300 noProtoCallOp.erase();
2301 }
else if (
auto getGlobalOp =
2302 mlir::dyn_cast<cir::GetGlobalOp>(use.getUser())) {
2309 mlir::Value res = getGlobalOp.getAddr();
2310 const mlir::Type oldResTy = res.getType();
2311 const auto newPtrTy = cir::PointerType::get(
2312 newFn.getFunctionType(),
2313 mlir::cast<cir::PointerType>(oldResTy).getAddrSpace());
2314 if (oldResTy != newPtrTy) {
2315 res.setType(newPtrTy);
2316 builder.setInsertionPointAfter(getGlobalOp.getOperation());
2317 mlir::Value castRes =
2318 cir::CastOp::create(builder, getGlobalOp.getLoc(), oldResTy,
2319 cir::CastKind::bitcast, res);
2320 res.replaceAllUsesExcept(castRes, castRes.getDefiningOp());
2322 }
else if (mlir::isa<cir::GlobalOp>(use.getUser())) {
2328 "replaceUsesOfNonProtoTypeWithRealFunction: unexpected use type");
2333cir::GlobalLinkageKind
2335 GVALinkage linkage = astContext.GetGVALinkageForVariable(vd);
2342 GVALinkage linkage = astContext.GetGVALinkageForFunction(d);
2344 if (
const auto *dtor = dyn_cast<CXXDestructorDecl>(d))
2353 StringRef globalName,
CharUnits alignment) {
2356 mlir::ptr::MemorySpaceAttrInterface addrSpace =
2366 gv.setAlignmentAttr(cgm.
getSize(alignment));
2368 cir::GlobalLinkageKindAttr::get(cgm.
getBuilder().getContext(), lt));
2370 gv.setUnnamedAddr(
true);
2372 if (gv.isWeakForLinker()) {
2373 assert(cgm.
supportsCOMDAT() &&
"Only COFF uses weak string literals");
2376 cgm.
setDSOLocal(
static_cast<mlir::Operation *
>(gv));
2397 std::string result =
2408 astContext.getAlignOfGlobalVarInChars(s->
getType(),
nullptr);
2416 if (!gv.getAlignment() ||
2417 uint64_t(alignment.
getQuantity()) > *gv.getAlignment())
2418 gv.setAlignmentAttr(
getSize(alignment));
2423 if (
getCXXABI().getMangleContext().shouldMangleStringLiteral(s) &&
2426 "getGlobalForStringLiteral: mangle string literals");
2436 : builder.getUnknownLoc();
2437 auto typedC = llvm::cast<mlir::TypedAttr>(c);
2439 cir::GlobalLinkageKind::PrivateLinkage, *
this,
2440 uniqueName, alignment);
2454 auto arrayTy = mlir::dyn_cast<cir::ArrayType>(gv.getSymType());
2455 assert(arrayTy &&
"String literal must be array");
2457 arrayTy.getElementType(),
2460 return builder.getGlobalViewAttr(ptrTy, gv);
2464 StringRef str, StringRef name) {
2465 mlir::Attribute init = builder.getString(str,
convertType(astContext.CharTy),
2471 cir::GlobalLinkageKind::PrivateLinkage, *
this,
2476mlir::ptr::MemorySpaceAttrInterface
2507 "emitExplicitCastExprType");
2513 auto ty = mlir::cast<cir::MethodType>(
convertType(destTy));
2514 return builder.getNullMethodAttr(ty);
2517 auto ty = mlir::cast<cir::DataMemberType>(
convertType(destTy));
2518 return builder.getNullDataMemberAttr(ty);
2529 if (
const auto *methodDecl = dyn_cast<CXXMethodDecl>(
decl)) {
2531 if (methodDecl->isVirtual())
2532 return cir::ConstantOp::create(
2533 builder, loc,
getCXXABI().buildVirtualMethodAttr(ty, methodDecl));
2539 return cir::ConstantOp::create(builder, loc,
2540 builder.getMethodAttr(ty, methodFuncOp));
2555 assert(
fieldDecl->getParent() == destClass &&
2556 "scalar member pointer should be relative to the declaring class");
2558 astContext.toCharUnitsFromBits(astContext.getFieldOffset(
fieldDecl))
2560 return cir::ConstantOp::create(builder, loc,
2561 cir::DataMemberOffsetAttr::get(ty, offset));
2564 std::optional<llvm::SmallVector<int32_t>> path =
2568 return cir::ConstantOp::create(builder, loc,
2569 builder.getDataMemberAttr(ty, *path));
2572std::optional<llvm::SmallVector<int32_t>>
2580 if (
const auto *indirectField = dyn_cast<IndirectFieldDecl>(
decl)) {
2582 for (
const NamedDecl *nd : indirectField->chain()) {
2584 if (!findFieldMemberPath(currentClass, field, path))
2585 return std::nullopt;
2586 currentClass = field->getType()->getAsCXXRecordDecl();
2592 return std::nullopt;
2596bool CIRGenModule::findFieldMemberPath(
const CXXRecordDecl *currentClass,
2606 if (currentClass->
isUnion()) {
2612 "data member pointer for non-zero-initializable union");
2619 path.push_back(fieldIdx);
2627 for (
const CXXBaseSpecifier &base : currentClass->
bases()) {
2628 const auto *baseDecl =
2631 if (base.isVirtual()) {
2636 llvm::SmallVector<int32_t> discardedPath;
2637 if (findFieldMemberPath(baseDecl, field, discardedPath)) {
2639 "data member pointer through virtual base");
2652 path.push_back(baseFieldIdx);
2653 if (findFieldMemberPath(baseDecl, field, path))
2681 if (
auto *oid = dyn_cast<ObjCImplDecl>(
decl))
2682 errorNYI(oid->getSourceRange(),
"emitDeclConext: ObjCImplDecl");
2692 if (
decl->isTemplated())
2695 switch (
decl->getKind()) {
2698 decl->getDeclKindName());
2701 case Decl::CXXConversion:
2702 case Decl::CXXMethod:
2703 case Decl::Function: {
2706 if (!fd->isConsteval())
2711 case Decl::Import: {
2720 if (!importedModules.insert(mod))
2722 moduleImportLocs[mod] = importDecl->getLocation();
2739 visited.insert(mod);
2740 stack.push_back(mod);
2742 while (!stack.empty()) {
2744 if (!emittedModuleInitializers.insert(cur).second)
2747 for (
Decl *initializer : astContext.getModuleInitializers(cur))
2754 if (submodule->IsExplicit)
2757 if (visited.insert(submodule).second)
2758 stack.push_back(submodule);
2769 case Decl::Decomposition:
2770 case Decl::VarTemplateSpecialization: {
2772 if (
auto *decomp = dyn_cast<DecompositionDecl>(
decl))
2773 for (
auto *binding : decomp->flat_bindings())
2774 if (
auto *holdingVar = binding->getHoldingVar())
2778 case Decl::OpenACCRoutine:
2781 case Decl::OpenACCDeclare:
2784 case Decl::OMPThreadPrivate:
2787 case Decl::OMPGroupPrivate:
2790 case Decl::OMPAllocate:
2793 case Decl::OMPCapturedExpr:
2796 case Decl::OMPDeclareReduction:
2799 case Decl::OMPDeclareMapper:
2802 case Decl::OMPRequires:
2807 case Decl::UsingDirective:
2808 case Decl::UsingEnum:
2809 case Decl::NamespaceAlias:
2811 case Decl::TypeAlias:
2818 case Decl::IndirectField:
2822 case Decl::ClassTemplate:
2824 case Decl::CXXDeductionGuide:
2826 case Decl::ExplicitInstantiation:
2827 case Decl::FunctionTemplate:
2828 case Decl::StaticAssert:
2829 case Decl::TypeAliasTemplate:
2830 case Decl::UsingShadow:
2831 case Decl::VarTemplate:
2832 case Decl::VarTemplatePartialSpecialization:
2835 case Decl::CXXConstructor:
2838 case Decl::CXXDestructor:
2843 case Decl::LinkageSpec:
2844 case Decl::Namespace:
2848 case Decl::ClassTemplateSpecialization:
2849 case Decl::CXXRecord: {
2852 for (
auto *childDecl : crd->
decls())
2858 case Decl::FileScopeAsm:
2860 if (langOpts.CUDA && langOpts.CUDAIsDevice)
2863 if (langOpts.OpenMPIsTargetDevice)
2866 if (langOpts.SYCLIsDevice)
2869 std::string line = file_asm->getAsmString();
2870 globalScopeAsm.push_back(builder.getStringAttr(line));
2877 op.setInitialValueAttr(value);
2891 md->getParent()->getNumVBases() == 0)
2893 "getAddrAndTypeOfCXXStructor: MS ABI complete destructor");
2904 false, isForDefinition);
2906 return {fnType, fn};
2910 mlir::Type funcType,
bool forVTable,
2914 "consteval function should never be emitted");
2924 if (
const auto *dd = dyn_cast<CXXDestructorDecl>(gd.
getDecl())) {
2927 dd->getParent()->getNumVBases() == 0)
2929 "getAddrOfFunction: MS ABI complete destructor");
2935 false, isForDefinition);
2937 if (langOpts.CUDA && !langOpts.CUDAIsDevice &&
2943 bool isHIPHandle = mlir::isa<cir::GlobalOp>(*handle);
2944 if (isForDefinition || isHIPHandle)
2946 return mlir::dyn_cast<cir::FuncOp>(*handle);
2955 llvm::raw_svector_ostream
out(buffer);
2964 assert(ii &&
"Attempt to mangle unnamed decl.");
2966 const auto *fd = dyn_cast<FunctionDecl>(nd);
2970 }
else if (fd && fd->hasAttr<CUDAGlobalAttr>() &&
2974 DeviceKernelAttr::isOpenCLSpelling(
2975 fd->getAttr<DeviceKernelAttr>()) &&
2992 if (
const auto *fd = dyn_cast<FunctionDecl>(nd)) {
2993 if (fd->isMultiVersion()) {
2995 "getMangledName: multi-version functions");
3003 "getMangledName: GPU relocatable device code");
3005 return std::string(
out.str());
3008static FunctionDecl *
3023 if (
auto *methodDecl = dyn_cast<CXXMethodDecl>(protoFunc);
3024 methodDecl && methodDecl->isImplicitObjectMemberFunction()) {
3026 paramTypes.insert(paramTypes.begin(), methodDecl->getThisType());
3029 fpt->getExtProtoInfo());
3040 params.reserve(fpt->getNumParams());
3043 for (
unsigned i = 0, e = fpt->getNumParams(); i != e; ++i) {
3047 nullptr, fpt->getParamType(i),
nullptr,
3050 params.push_back(parm);
3053 tempFunc->setParams(params);
3078 if (
const auto *cd = dyn_cast<CXXConstructorDecl>(canonicalGd.
getDecl())) {
3081 "getMangledName: C++ constructor without variants");
3090 if (!langOpts.CUDAIsDevice || !astContext.mayExternalize(gd.
getDecl())) {
3091 auto foundName = mangledDeclNames.find(canonicalGd);
3092 if (foundName != mangledDeclNames.end())
3093 return foundName->second;
3100 auto result = manglings.insert(std::make_pair(mangledName, gd));
3101 return mangledDeclNames[canonicalGd] = result.first->first();
3105 assert(!d->
getInit() &&
"Cannot emit definite definitions here!");
3114 auto gvOp = dyn_cast<cir::GlobalOp>(gv);
3117 "emitTentativeDefinition: name already used by a non-global");
3120 if (!gvOp.isDeclaration())
3137 if (langOpts.EmitAllDecls)
3140 const auto *vd = dyn_cast<VarDecl>(global);
3142 ((codeGenOpts.KeepPersistentStorageVariables &&
3143 (vd->getStorageDuration() ==
SD_Static ||
3144 vd->getStorageDuration() ==
SD_Thread)) ||
3145 (codeGenOpts.KeepStaticConsts && vd->getStorageDuration() ==
SD_Static &&
3146 vd->getType().isConstQualified())))
3159 if (langOpts.OpenMP >= 50 && !langOpts.OpenMPSimd) {
3160 std::optional<OMPDeclareTargetDeclAttr *> activeAttr =
3161 OMPDeclareTargetDeclAttr::getActiveAttr(global);
3162 if (!activeAttr || (*activeAttr)->getLevel() != (
unsigned)-1)
3166 const auto *fd = dyn_cast<FunctionDecl>(global);
3173 if (fd->hasAttr<TargetVersionAttr>() && !fd->isMultiVersion())
3177 if (langOpts.SYCLIsDevice && fd->hasAttr<SYCLKernelEntryPointAttr>())
3180 const auto *vd = dyn_cast<VarDecl>(global);
3182 if (astContext.getInlineVariableDefinitionKind(vd) ==
3190 if (langOpts.OpenMP && langOpts.OpenMPUseTLS &&
3191 astContext.getTargetInfo().isTLSSupported() &&
isa<VarDecl>(global) &&
3193 !OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(global))
3196 assert((fd || vd) &&
3197 "Only FunctionDecl and VarDecl should hit this path so far.");
3202 cir::CIRGlobalValueInterface gv) {
3203 if (gv.hasLocalLinkage())
3206 if (!gv.hasDefaultVisibility() && !gv.hasExternalWeakLinkage())
3214 const llvm::Triple &tt = cgm.
getTriple();
3216 if (tt.isOSCygMing()) {
3225 cgm.
errorNYI(
"shouldAssumeDSOLocal: MinGW");
3231 if (tt.isOSBinFormatCOFF() && gv.hasExternalWeakLinkage())
3239 if (tt.isOSBinFormatCOFF() || (tt.isOSWindows() && tt.isOSBinFormatMachO()))
3243 if (!tt.isOSBinFormatELF())
3248 if (rm != llvm::Reloc::Static && !lOpts.PIE) {
3254 auto func = dyn_cast<cir::FuncOp>(gv.getOperation());
3255 if (!func || func.getAliasee() || !gv.canBenefitFromLocalAlias())
3257 return !(lOpts.SemanticInterposition || lOpts.HalfNoSemanticInterposition);
3261 if (!gv.isDeclarationForLinker())
3267 if (rm == llvm::Reloc::PIC_ && gv.hasExternalWeakLinkage())
3274 if (cgOpts.DirectAccessExternalData) {
3280 if (
auto globalOp = dyn_cast<cir::GlobalOp>(gv.getOperation())) {
3306 if (gv.hasLocalLinkage()) {
3307 gv.setGlobalVisibility(cir::VisibilityKind::Default);
3322 d->
hasAttr<OMPDeclareTargetDeclAttr>() &&
3323 d->
getAttr<OMPDeclareTargetDeclAttr>()->getDevType() !=
3324 OMPDeclareTargetDeclAttr::DT_NoHost &&
3326 llvm_unreachable(
"setGlobalVisibility: OpenMP is NYI");
3335 !d->
hasAttr<OMPDeclareTargetDeclAttr>()) {
3336 bool needsProtected =
false;
3340 }
else if (
const auto *vd = dyn_cast<VarDecl>(d)) {
3341 needsProtected = vd->hasAttr<CUDADeviceAttr>() ||
3342 vd->hasAttr<CUDAConstantAttr>() ||
3343 vd->getType()->isCUDADeviceBuiltinSurfaceType() ||
3344 vd->getType()->isCUDADeviceBuiltinTextureType();
3346 if (needsProtected) {
3347 gv.setGlobalVisibility(cir::VisibilityKind::Protected);
3353 gv.setGlobalVisibility(cir::VisibilityKind::Hidden);
3360 !gv.isDeclarationForLinker())
3369 if (
auto globalValue = dyn_cast<cir::CIRGlobalValueInterface>(op))
3388 auto res = manglings.find(mangledName);
3389 if (res == manglings.end())
3391 result = res->getValue();
3396 return llvm::StringSwitch<cir::TLSModel>(S)
3397 .Case(
"global-dynamic", cir::TLSModel::GeneralDynamic)
3398 .Case(
"local-dynamic", cir::TLSModel::LocalDynamic)
3399 .Case(
"initial-exec", cir::TLSModel::InitialExec)
3400 .Case(
"local-exec", cir::TLSModel::LocalExec);
3406 return cir::TLSModel::GeneralDynamic;
3408 return cir::TLSModel::LocalDynamic;
3410 return cir::TLSModel::InitialExec;
3412 return cir::TLSModel::LocalExec;
3414 llvm_unreachable(
"Invalid TLS model!");
3418 bool isExtendingDecl) {
3419 assert(d.
getTLSKind() &&
"setting TLS mode on non-TLS var!");
3428 global.setTlsModel(tlm);
3438 if (isExtendingDecl)
3446 cir::FuncOp func,
bool isThunk) {
3448 cir::CallingConv callingConv;
3455 mlir::NamedAttrList pal{};
3456 std::vector<mlir::NamedAttrList> argAttrs(info.arguments().size());
3457 mlir::NamedAttrList retAttrs{};
3459 retAttrs, callingConv,
3462 for (mlir::NamedAttribute
attr : pal)
3463 func->setAttr(
attr.getName(),
attr.getValue());
3465 llvm::for_each(llvm::enumerate(argAttrs), [func](
auto idx_arg_pair) {
3466 mlir::function_interface_impl::setArgAttrs(func, idx_arg_pair.index(),
3467 idx_arg_pair.value());
3469 if (!retAttrs.empty())
3470 mlir::function_interface_impl::setResultAttrs(func, 0, retAttrs);
3474 func.setCallingConv(callingConv);
3479 bool isIncompleteFunction,
3487 if (!isIncompleteFunction)
3489 getTypes().arrangeGlobalDeclaration(globalDecl),
3495 if (!isThunk &&
getCXXABI().hasThisReturn(globalDecl) &&
3497 func.setArgAttr(0, mlir::LLVM::LLVMDialect::getReturnedAttrName(),
3500 if (!isIncompleteFunction && func.isDeclaration())
3505 if (
const auto *errorAttr = funcDecl->getAttr<ErrorAttr>()) {
3506 if (errorAttr->isError())
3507 func->setAttr(cir::CIRDialect::getDontCallErrorAttrName(),
3509 errorAttr->getUserDiagnostic()));
3510 else if (errorAttr->isWarning())
3511 func->setAttr(cir::CIRDialect::getDontCallWarnAttrName(),
3513 errorAttr->getUserDiagnostic()));
3520 if (funcDecl->isInlineBuiltinDeclaration()) {
3522 bool hasBody = funcDecl->
hasBody(fdBody);
3524 assert(hasBody &&
"Inline builtin declarations should always have an "
3529 if (funcDecl->isReplaceableGlobalAllocationFunction()) {
3532 func->setAttr(cir::CIRDialect::getNoBuiltinAttrName(),
3537 func.setUnnamedAddr(
true);
3538 else if (
const auto *md = dyn_cast<CXXMethodDecl>(funcDecl))
3539 if (md->isVirtual())
3540 func.setUnnamedAddr(
true);
3546 if ((!
decl || !
decl->hasAttr<NoUwtableAttr>()) && codeGenOpts.UnwindTables)
3547 f.setUwtable(
static_cast<cir::UnwindTableKind
>(codeGenOpts.UnwindTables));
3552 f->setAttr(cir::CIRDialect::getNoThrowAttrName(),
3555 std::optional<cir::InlineKind> existingInlineKind = f.getInlineKind();
3557 existingInlineKind && *existingInlineKind == cir::InlineKind::NoInline;
3558 bool isAlwaysInline = existingInlineKind &&
3559 *existingInlineKind == cir::InlineKind::AlwaysInline;
3563 if (!isAlwaysInline &&
3568 f.setInlineKind(cir::InlineKind::NoInline);
3580 bool shouldAddOptNone =
3581 !codeGenOpts.DisableO0ImplyOptNone && codeGenOpts.OptimizationLevel == 0;
3583 shouldAddOptNone &= !
decl->hasAttr<MinSizeAttr>();
3584 shouldAddOptNone &= !
decl->hasAttr<AlwaysInlineAttr>();
3587 if ((shouldAddOptNone ||
decl->hasAttr<OptimizeNoneAttr>()) &&
3590 f->setAttr(cir::CIRDialect::getOptNoneAttrName(),
3594 f.setInlineKind(cir::InlineKind::NoInline);
3598 if (
decl->hasAttr<NakedAttr>())
3599 f->setAttr(cir::CIRDialect::getNakedAttrName(),
3603 f->removeAttr(cir::CIRDialect::getOptimizeForSizeAttrName());
3604 f->removeAttr(cir::CIRDialect::getMinSizeAttrName());
3605 }
else if (
decl->hasAttr<NakedAttr>()) {
3607 f->setAttr(cir::CIRDialect::getNakedAttrName(),
3609 f.setInlineKind(cir::InlineKind::NoInline);
3610 }
else if (
decl->hasAttr<NoDuplicateAttr>()) {
3611 f->setAttr(cir::CIRDialect::getNoDuplicatesAttrName(),
3613 }
else if (
decl->hasAttr<NoInlineAttr>() && !isAlwaysInline) {
3615 f.setInlineKind(cir::InlineKind::NoInline);
3616 }
else if (
decl->hasAttr<AlwaysInlineAttr>() && !isNoInline) {
3619 f.setInlineKind(cir::InlineKind::AlwaysInline);
3623 if (!isAlwaysInline)
3624 f.setInlineKind(cir::InlineKind::NoInline);
3629 if (
auto *fd = dyn_cast<FunctionDecl>(
decl)) {
3634 auto checkRedeclForInline = [](
const FunctionDecl *redecl) {
3635 return redecl->isInlineSpecified();
3637 if (any_of(
decl->redecls(), checkRedeclForInline))
3642 return any_of(pattern->
redecls(), checkRedeclForInline);
3644 if (checkForInline(fd)) {
3645 f.setInlineKind(cir::InlineKind::InlineHint);
3646 }
else if (codeGenOpts.getInlining() ==
3648 !fd->isInlined() && !isAlwaysInline) {
3649 f.setInlineKind(cir::InlineKind::NoInline);
3656 if (!
decl->hasAttr<OptimizeNoneAttr>()) {
3657 if (
decl->hasAttr<ColdAttr>()) {
3658 if (!shouldAddOptNone)
3659 f->setAttr(cir::CIRDialect::getOptimizeForSizeAttrName(),
3662 f->setAttr(cir::CIRDialect::getColdAttrName(),
3666 if (
decl->hasAttr<HotAttr>())
3667 f->setAttr(cir::CIRDialect::getHotAttrName(),
3670 if (
decl->hasAttr<MinSizeAttr>())
3671 f->setAttr(cir::CIRDialect::getMinSizeAttrName(),
3675 std::optional<uint64_t> explicitAlignment;
3676 if (
unsigned alignment =
3678 explicitAlignment = alignment;
3679 else if (langOpts.FunctionAlignment)
3680 explicitAlignment = 1ull << langOpts.FunctionAlignment;
3682 if (explicitAlignment) {
3683 f.setAlignment(*explicitAlignment);
3684 f.setPreferredAlignment(*explicitAlignment);
3685 }
else if (langOpts.PreferredFunctionAlignment) {
3686 f.setPreferredAlignment(langOpts.PreferredFunctionAlignment);
3708static cir::LangAddressSpace
3710 switch (addressSpace) {
3712 return cir::LangAddressSpace::OffloadGlobal;
3714 return cir::LangAddressSpace::OffloadConstant;
3716 return cir::LangAddressSpace::OffloadLocal;
3718 return cir::LangAddressSpace::OffloadGeneric;
3720 return cir::LangAddressSpace::OffloadGlobalDevice;
3722 return cir::LangAddressSpace::OffloadGlobalHost;
3726 return cir::LangAddressSpace::Default;
3732 assert(fd &&
"expected a kernel function declaration");
3745 argNames.push_back(builder.getStringAttr(param->getName()));
3748 std::string typeQuals;
3750 if (
type->isImageType() ||
type->isPipeType()) {
3752 "OpenCL kernel argument metadata for image and pipe types");
3756 accessQuals.push_back(builder.getStringAttr(
"none"));
3758 auto getTypeSpelling = [&](
QualType paramType) {
3759 std::string typeName = paramType.getUnqualifiedType().getAsString(policy);
3761 if (paramType.isCanonical()) {
3762 StringRef typeNameRef = typeName;
3763 if (typeNameRef.consume_front(
"unsigned "))
3764 return std::string(
"u") + typeNameRef.str();
3765 if (typeNameRef.consume_front(
"signed "))
3766 return typeNameRef.str();
3774 if (
type->isPointerType()) {
3776 addressQuals.push_back(cir::LangAddressSpaceAttr::get(
3780 argTypeNames.push_back(
3781 builder.getStringAttr(getTypeSpelling(
pointeeType) +
"*"));
3782 argBaseTypeNames.push_back(builder.getStringAttr(
3783 getTypeSpelling(
pointeeType.getCanonicalType()) +
"*"));
3785 if (
type.isRestrictQualified())
3786 typeQuals =
"restrict";
3789 typeQuals += typeQuals.empty() ?
"const" :
" const";
3791 typeQuals += typeQuals.empty() ?
"volatile" :
" volatile";
3793 addressQuals.push_back(cir::LangAddressSpaceAttr::get(
3796 argTypeNames.push_back(builder.getStringAttr(getTypeSpelling(
type)));
3797 argBaseTypeNames.push_back(
3798 builder.getStringAttr(getTypeSpelling(
type.getCanonicalType())));
3801 argTypeQuals.push_back(builder.getStringAttr(typeQuals));
3804 mlir::ArrayAttr names;
3806 names = builder.getArrayAttr(argNames);
3808 mlir::Attribute metadata = cir::OpenCLKernelArgMetadataAttr::get(
3809 func.getContext(), builder.getArrayAttr(addressQuals),
3810 builder.getArrayAttr(accessQuals), builder.getArrayAttr(argTypeNames),
3811 builder.getArrayAttr(argBaseTypeNames),
3812 builder.getArrayAttr(argTypeQuals), names);
3813 func->setAttr(cir::CIRDialect::getOpenCLKernelArgMetadataAttrName(),
3818 StringRef mangledName, mlir::Type funcType,
GlobalDecl gd,
bool forVTable,
3820 mlir::NamedAttrList extraAttrs) {
3823 if (
const auto *fd = cast_or_null<FunctionDecl>(d)) {
3825 if (
getLangOpts().OpenMPIsTargetDevice && openMPRuntime &&
3827 !dontDefer && !isForDefinition) {
3830 if (
const auto *cd = dyn_cast<CXXConstructorDecl>(fdDef))
3832 else if (
const auto *dd = dyn_cast<CXXDestructorDecl>(fdDef))
3842 if (fd->isMultiVersion())
3843 errorNYI(fd->getSourceRange(),
"getOrCreateCIRFunction: multi-version");
3849 assert(mlir::isa<cir::FuncOp>(entry));
3852 if (weakRefReferences.erase(entry)) {
3853 const auto *fd = cast_or_null<FunctionDecl>(d);
3854 if (fd && !fd->hasAttr<WeakAttr>())
3856 cir::GlobalLinkageKind::ExternalLinkage);
3860 if (d && !d->
hasAttr<DLLImportAttr>() && !d->
hasAttr<DLLExportAttr>()) {
3868 if (isForDefinition && fn && !fn.isDeclaration()) {
3875 diagnosedConflictingDefinitions.insert(gd).second) {
3879 diag::note_previous_definition);
3883 if (fn && fn.getFunctionType() == funcType) {
3887 if (!isForDefinition) {
3895 auto *funcDecl = llvm::cast_or_null<FunctionDecl>(gd.
getDecl());
3896 bool invalidLoc = !funcDecl ||
3897 funcDecl->getSourceRange().getBegin().isInvalid() ||
3898 funcDecl->getSourceRange().getEnd().isInvalid();
3900 invalidLoc ? theModule->getLoc() :
getLoc(funcDecl->getSourceRange()),
3901 mangledName, mlir::cast<cir::FuncType>(funcType), funcDecl);
3903 if (funcDecl && funcDecl->hasAttr<AnnotateAttr>())
3904 deferredAnnotations[mangledName] = funcDecl;
3915 auto symbolOp = mlir::cast<mlir::SymbolOpInterface>(entry);
3923 if (symbolOp.getSymbolUses(symbolOp->getParentOp()))
3933 if (!extraAttrs.empty())
3934 for (mlir::NamedAttribute attr : extraAttrs)
3935 if (!funcOp->hasDiscardableAttr(
attr.getName()))
3936 funcOp->setDiscardableAttr(
attr.getName(),
attr.getValue());
3942 assert(funcOp.getFunctionType() == funcType);
3949 if (isa_and_nonnull<CXXDestructorDecl>(d) &&
3979 fd = fd->getPreviousDecl()) {
3981 if (fd->doesThisDeclarationHaveABody()) {
3994 cir::FuncType funcType,
3998 mlir::OpBuilder::InsertionGuard guard(builder);
4003 builder.setInsertionPointToEnd(
getModule().getBody());
4005 func = cir::FuncOp::create(builder, loc, name, funcType);
4012 func.setNoProto(
true);
4014 assert(func.isDeclaration() &&
"expected empty body");
4018 func.setLinkageAttr(cir::GlobalLinkageKindAttr::get(
4020 mlir::SymbolTable::setSymbolVisibility(
4021 func, mlir::SymbolTable::Visibility::Private);
4032 for (
const auto *
attr :
4046 fnOp.setBuiltin(
true);
4052 return cir::CtorKind::Default;
4054 return cir::CtorKind::Copy;
4056 return cir::CtorKind::Move;
4057 return cir::CtorKind::Custom;
4062 return cir::AssignKind::Copy;
4064 return cir::AssignKind::Move;
4065 llvm_unreachable(
"not a copy or move assignment operator");
4073 if (
const auto *dtor = dyn_cast<CXXDestructorDecl>(funcDecl)) {
4074 auto cxxDtor = cir::CXXDtorAttr::get(
4077 funcOp.setFuncInfoAttr(cxxDtor);
4081 if (
const auto *ctor = dyn_cast<CXXConstructorDecl>(funcDecl)) {
4083 auto cxxCtor = cir::CXXCtorAttr::get(
4085 kind, ctor->isTrivial());
4086 funcOp.setFuncInfoAttr(cxxCtor);
4090 const auto *method = dyn_cast<CXXMethodDecl>(funcDecl);
4091 if (method && (method->isCopyAssignmentOperator() ||
4092 method->isMoveAssignmentOperator())) {
4094 auto cxxAssign = cir::CXXAssignAttr::get(
4096 assignKind, method->isTrivial());
4097 funcOp.setFuncInfoAttr(cxxAssign);
4107 bool inStdNamespace = method ? method->getParent()->isInStdNamespace()
4109 if (!inStdNamespace)
4115 std::optional<cir::KnownFuncKind>
kind;
4117 kind = llvm::StringSwitch<std::optional<cir::KnownFuncKind>>(
4119 .Case(cir::StdFindOp::getFunctionName(),
4120 cir::StdFindOp::getFuncKind())
4121 .Default(std::nullopt);
4130 cir::FuncOp funcOp, StringRef name) {
4146 mlir::NamedAttrList extraAttrs,
4148 bool assumeConvergent) {
4149 if (assumeConvergent)
4150 errorNYI(
"createRuntimeFunction: assumeConvergent");
4152 extraAttrs.set(cir::CIRDialect::getRuntimeFuncAttrName(),
4162 entry.setDSOLocal(
true);
4168mlir::SymbolTable::Visibility
4172 if (op.isDeclaration())
4173 return mlir::SymbolTable::Visibility::Private;
4177mlir::SymbolTable::Visibility
4180 case cir::GlobalLinkageKind::InternalLinkage:
4181 case cir::GlobalLinkageKind::PrivateLinkage:
4182 return mlir::SymbolTable::Visibility::Private;
4183 case cir::GlobalLinkageKind::ExternalLinkage:
4184 case cir::GlobalLinkageKind::ExternalWeakLinkage:
4185 case cir::GlobalLinkageKind::LinkOnceODRLinkage:
4186 case cir::GlobalLinkageKind::AvailableExternallyLinkage:
4187 case cir::GlobalLinkageKind::CommonLinkage:
4188 case cir::GlobalLinkageKind::WeakAnyLinkage:
4189 case cir::GlobalLinkageKind::WeakODRLinkage:
4190 return mlir::SymbolTable::Visibility::Public;
4192 llvm::errs() <<
"visibility not implemented for '"
4193 << stringifyGlobalLinkageKind(glk) <<
"'\n";
4194 assert(0 &&
"not implemented");
4197 llvm_unreachable(
"linkage should be handled above!");
4200std::string CIRGenModule::getModuleInitializerName(
clang::Module *mod) {
4202 llvm::raw_string_ostream
out(name);
4204 .mangleModuleInitializer(mod,
out);
4211 applyReplacements();
4213 getModule()->setAttr(cir::CIRDialect::getModuleLevelAsmAttrName(),
4214 builder.getArrayAttr(globalScopeAsm));
4216 emitGlobalAnnotations();
4218 if (std::optional<cir::FramePointerKind>
kind =
4221 cir::CIRDialect::getModuleFramePointerAttrName(),
4224 if (!recordLayoutEntries.empty())
4226 cir::CIRDialect::getRecordLayoutsAttrName(),
4227 mlir::DictionaryAttr::get(&
getMLIRContext(), recordLayoutEntries));
4236 std::string cuidName =
4239 auto loc = builder.getUnknownLoc();
4240 mlir::ptr::MemorySpaceAttrInterface addrSpace =
4245 gv.setLinkage(cir::GlobalLinkageKind::ExternalLinkage);
4247 auto zeroAttr = cir::IntAttr::get(int8Ty, 0);
4248 gv.setInitialValueAttr(zeroAttr);
4250 mlir::SymbolTable::setSymbolVisibility(
4251 gv, mlir::SymbolTable::Visibility::Public);
4256 if (astContext.getLangOpts().CUDA && cudaRuntime)
4269 if (cxx20ModuleInits) {
4270 clang::Module *primary = astContext.getCurrentNamedModule();
4272 if (isInterfaceUnit)
4274 cir::CIRDialect::getCXXModuleInitFnNameAttrName(),
4275 builder.getStringAttr(getModuleInitializerName(primary)));
4281 primary, importedModules.getArrayRef())) {
4284 auto importLoc = moduleImportLocs.find(mod);
4285 mlir::Location loc =
4286 getLoc(importLoc != moduleImportLocs.end() ? importLoc->second
4288 importedInits.push_back(cir::CXXModuleInitAttr::get(
4290 builder.getStringAttr(getModuleInitializerName(mod)), loc));
4292 if (!importedInits.empty())
4293 getModule()->setAttr(cir::CIRDialect::getCXXModuleImportedInitsAttrName(),
4294 builder.getArrayAttr(importedInits));
4310 const AliasAttr *aa = d->
getAttr<AliasAttr>();
4311 assert(aa &&
"Not an alias?");
4315 if (aa->getAliasee() == mangledName) {
4316 diags.Report(aa->getLocation(), diag::err_cyclic_alias) << 0;
4324 auto entryGV = mlir::dyn_cast<cir::CIRGlobalValueInterface>(entry);
4325 if (entryGV && entryGV.isDefinition())
4338 cir::GlobalLinkageKind linkage;
4350 cir::CIRGlobalValueInterface alias =
4351 isFunction ? mlir::cast<cir::CIRGlobalValueInterface>(
4353 mlir::cast<cir::FuncType>(declTy),
4356 : mlir::cast<cir::CIRGlobalValueInterface>(
4367 entry, mlir::cast<cir::FuncOp>(alias.getOperation()));
4375 linkage = cir::GlobalLinkageKind::WeakAnyLinkage;
4379 mlir::SymbolTable::Visibility visibility =
4382 alias.setAliasee(aa->getAliasee());
4383 alias.setLinkage(linkage);
4384 mlir::SymbolTable::setSymbolVisibility(alias, visibility);
4391 mlir::Operation *op,
4393 cir::FuncOp aliasee,
4394 cir::GlobalLinkageKind linkage) {
4396 auto *aliasFD = dyn_cast<FunctionDecl>(aliasGD.
getDecl());
4397 assert(aliasFD &&
"expected FunctionDecl");
4408 mangledName, fnType, aliasFD);
4409 alias.setAliasee(aliasee.getName());
4410 alias.setLinkage(linkage);
4414 mlir::SymbolTable::setSymbolVisibility(
4415 alias, mlir::SymbolTable::Visibility::Private);
4424 "declaration exists with different type");
4437 return genTypes.convertType(
type);
4444 return mlir::verify(
getModule()).succeeded();
4453 return builder.getConstNullPtrAttr(builder.getUInt8PtrTy());
4456 langOpts.ObjCRuntime.isGNUFamily()) {
4457 errorNYI(loc,
"getAddrOfRTTIDescriptor: Objc PtrType & Objc RT GUN");
4467 llvm::iterator_range<CastExpr::path_const_iterator> path) {
4474 assert(!base->isVirtual() &&
"Should not see virtual bases here!");
4479 const auto *baseDecl = base->getType()->castAsCXXRecordDecl();
4491 llvm::StringRef feature) {
4492 unsigned diagID = diags.getCustomDiagID(
4494 return diags.Report(loc, diagID) << feature;
4498 llvm::StringRef feature) {
4510 "cannot compile this %0 yet");
4511 diags.Report(astContext.getFullLoc(s->
getBeginLoc()), diagId)
4518 "cannot compile this %0 yet");
4519 diags.Report(astContext.getFullLoc(d->
getLocation()), diagId) <<
type;
4527 "not a global temporary");
4539 materializedType = mte->
getType();
4548 llvm::raw_svector_ostream
out(name);
4552 auto insertResult = materializedGlobalTemporaryMap.insert({mte,
nullptr});
4553 if (!insertResult.second) {
4557 if (!insertResult.first->second) {
4560 insertResult.first->second =
4563 return insertResult.first->second;
4580 value = &evalResult.
Val;
4584 std::optional<ConstantEmitter> emitter;
4585 mlir::Attribute initialValue =
nullptr;
4586 bool isConstant =
false;
4590 emitter.emplace(*
this);
4591 initialValue = emitter->emitForInitializer(*value, materializedType);
4596 type = mlir::cast<mlir::TypedAttr>(initialValue).getType();
4605 if (linkage == cir::GlobalLinkageKind::ExternalLinkage) {
4607 if (
varDecl->isStaticDataMember() &&
varDecl->getAnyInitializer(initVD) &&
4615 linkage = cir::GlobalLinkageKind::InternalLinkage;
4619 gv.setInitialValueAttr(initialValue);
4620 gv.setLinkage(linkage);
4624 emitter->finalize(gv);
4626 if (!gv.hasLocalLinkage()) {
4631 gv.setAlignment(align.getAsAlign().value());
4636 mlir::Operation *cv = gv;
4645 mlir::Operation *&entry = materializedGlobalTemporaryMap[mte];
4647 entry->replaceAllUsesWith(cv);
4662 return *globalOpEntry;
4669 "emitForInitializer should take gcd->getType().getAddressSpace()");
4671 auto typedInit = dyn_cast<mlir::TypedAttr>(init);
4675 "getAddrOfUnnamedGlobalConstantDecl: non-typed initializer");
4684 std::string name = numEntries == 0
4686 : (Twine(
".constant.") + Twine(numEntries)).str();
4688 typedInit.getType(),
true);
4689 globalOp.setLinkage(cir::GlobalLinkageKind::PrivateLinkage);
4692 globalOp.setAlignment(alignment.
getAsAlign().value());
4693 globalOp.setUnnamedAddr(
true);
4697 *globalOpEntry = globalOp;
4712 "emitForInitializer should take tpo->getType().getAddressSpace()");
4713 mlir::Attribute init =
4723 cir::GlobalLinkageKind linkage =
4725 ? cir::GlobalLinkageKind::LinkOnceODRLinkage
4726 : cir::GlobalLinkageKind::InternalLinkage;
4730 typedInit.getType(),
true);
4731 globalOp.setLinkage(linkage);
4732 globalOp.setAlignment(alignment.
getAsAlign().value());
4733 if (
supportsCOMDAT() && linkage == cir::GlobalLinkageKind::LinkOnceODRLinkage)
4734 globalOp.setSelfComdat();
4756 llvm::FoldingSetNodeID id;
4757 for (
Expr *e : exprs)
4760 mlir::ArrayAttr &lookup = annotationArgs[
id.computeHash()];
4765 args.reserve(exprs.size());
4766 for (
Expr *e : exprs) {
4767 if (
auto *strE = dyn_cast<clang::StringLiteral>(e->IgnoreParenCasts())) {
4768 args.push_back(builder.getStringAttr(strE->getString()));
4769 }
else if (
auto *intE =
4770 dyn_cast<clang::IntegerLiteral>(e->IgnoreParenCasts())) {
4771 auto intTy = builder.getIntegerType(intE->getValue().getBitWidth());
4772 args.push_back(builder.getIntegerAttr(intTy, intE->getValue()));
4774 errorNYI(e->getExprLoc(),
"annotation argument expression");
4778 return lookup = builder.getArrayAttr(args);
4782 mlir::StringAttr annoGV = builder.getStringAttr(aa->getAnnotation());
4784 return cir::AnnotationAttr::get(&
getMLIRContext(), annoGV, args);
4788 mlir::Operation *gv) {
4789 assert(d->
hasAttr<AnnotateAttr>() &&
"no annotate attribute");
4791 "annotation only on globals");
4795 if (
auto global = dyn_cast<cir::GlobalOp>(gv))
4796 global.setAnnotationsAttr(builder.getArrayAttr(annotations));
4797 else if (
auto func = dyn_cast<cir::FuncOp>(gv))
4798 func.setAnnotationsAttr(builder.getArrayAttr(annotations));
4801void CIRGenModule::emitGlobalAnnotations() {
4802 for (
const auto &[mangledName, vd] : deferredAnnotations) {
4807 deferredAnnotations.clear();
Defines the clang::ASTContext interface.
This file provides some common utility functions for processing Lambda related AST Constructs.
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 shouldSkipAliasEmission(const CIRGenModule &cgm, const ValueDecl *global)
static cir::LangAddressSpace getOpenCLKernelArgAddressSpace(LangAS addressSpace)
static mlir::Attribute getNewInitValue(CIRGenModule &cgm, cir::GlobalOp newGlob, mlir::Type oldTy, mlir::Attribute oldInit)
static bool verifyPointerTypeArgs(llvm::ArrayRef< mlir::Operation * > users, cir::FuncOp newF)
static void setWindowsItaniumDLLImport(CIRGenModule &cgm, bool isLocal, cir::FuncOp funcOp, StringRef name)
static std::string getMangledNameImpl(CIRGenModule &cgm, GlobalDecl gd, const NamedDecl *nd)
static llvm::SmallVector< int64_t > indexesOfArrayAttr(mlir::ArrayAttr indexes)
static bool isViewOnGlobal(cir::GlobalOp glob, cir::GlobalViewAttr view)
static void setLinkageForFunction(CIRGenModule &cgm, cir::FuncOp &func, const NamedDecl *nd)
static cir::GlobalOp generateStringLiteral(mlir::Location loc, mlir::TypedAttr c, cir::GlobalLinkageKind lt, CIRGenModule &cgm, StringRef globalName, CharUnits alignment)
static std::vector< std::string > getFeatureDeltaFromDefault(const CIRGenModule &cgm, llvm::StringRef targetCPU, llvm::StringMap< bool > &featureMap)
Get the feature delta from the default feature map for the given target CPU.
static CIRGenCXXABI * createCXXABI(CIRGenModule &cgm)
static void setLinkageForGV(cir::GlobalOp &gv, const NamedDecl *nd)
static mlir::Attribute createNewGlobalView(CIRGenModule &cgm, cir::GlobalOp newGlob, cir::GlobalViewAttr attr, mlir::Type oldTy)
static cir::CtorKind getCtorKindFromDecl(const CXXConstructorDecl *ctor)
static void emitUsed(CIRGenModule &cgm, StringRef name, std::vector< cir::CIRGlobalValueInterface > &list)
static cir::TLSModel getCIRTLSModel(StringRef S)
This file defines OpenACC nodes for declarative directives.
static constexpr bool needsDtor()
static unsigned getCharWidth(tok::TokenKind kind, const TargetInfo &Target)
Defines the clang::Module class, which describes a module in the source code.
*collection of selector each with an associated kind and an ordered *collection of selectors A selector has a kind
static ParseState advance(ParseState S, size_t N)
Defines the SourceManager interface.
This file defines OpenMP AST classes for executable directives and clauses.
cir::GlobalViewAttr getGlobalViewAttr(cir::GlobalOp globalOp, mlir::ArrayAttr indices={})
Get constant address of a global variable as an MLIR attribute.
cir::PointerType getPointerTo(mlir::Type ty)
cir::PointerType getVoidPtrTy(clang::LangAS langAS=clang::LangAS::Default)
mlir::ptr::MemorySpaceAttrInterface getDefaultGlobalsAddrSpace(mlir::MLIRContext *ctx) const
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
TranslationUnitDecl * getTranslationUnitDecl() const
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
@ Strong
Strong definition.
@ WeakUnknown
Weak for now, might become strong later in this TU.
bool shouldExternalize(const Decl *D) const
Whether a C++ static variable or CUDA/HIP kernel should be externalized.
bool DeclMustBeEmitted(const Decl *D)
Determines if the decl can be CodeGen'ed or deserialized from PCH lazily, only when used; this is onl...
StringRef getCUIDHash() const
void Deallocate(void *Ptr) const
bool isSameEntity(const NamedDecl *X, const NamedDecl *Y) const
Determine whether the two declarations refer to the same entity.
const clang::PrintingPolicy & getPrintingPolicy() const
QualType getFunctionType(QualType ResultTy, ArrayRef< QualType > Args, const FunctionProtoType::ExtProtoInfo &EPI) const
Return a normal function type with a typed argument list.
DiagnosticsEngine & getDiagnostics() 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.
bool computeGlobalViewIndicesFromFlatOffset(int64_t offset, mlir::Type ty, const cir::CIRDataLayout &layout, llvm::SmallVectorImpl< int64_t > &indices)
mlir::Attribute getConstRecordOrZeroAttr(mlir::ArrayAttr arrayAttr, cir::RecordType recordTy)
uint64_t computeOffsetFromGlobalViewIndices(const cir::CIRDataLayout &layout, mlir::Type ty, llvm::ArrayRef< int64_t > indices)
cir::ConstArrayAttr getConstArray(mlir::Attribute attrs, cir::ArrayType arrayTy) const
virtual void handleGlobalReplace(cir::GlobalOp oldGV, cir::GlobalOp newGV)
virtual mlir::Operation * getKernelHandle(cir::FuncOp fn, GlobalDecl gd)=0
virtual void finalizeModule()
Perform module finalization: on device side, mark ODR-used device variables as compiler-used.
virtual void internalizeDeviceSideVar(const VarDecl *d, cir::GlobalLinkageKind &linkage)=0
Adjust linkage of shadow variables in host compilation.
virtual void handleVarRegistration(const VarDecl *vd, cir::GlobalOp var)=0
Check whether a variable is a device variable and register it if true.
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)
This class organizes the cross-function state that is used while generating CIR code.
cir::GlobalOp getAddrOfUnnamedGlobalConstantDecl(const UnnamedGlobalConstantDecl *gcd)
void setGlobalVisibility(cir::CIRGlobalValueInterface gv, const NamedDecl *d) const
Set the visibility for the given global.
void addUsedOrCompilerUsedGlobal(cir::CIRGlobalValueInterface gv)
Add a global to a list to be added to the llvm.compiler.used metadata.
void setFuncInfoAttr(cir::FuncOp funcOp, const clang::FunctionDecl *funcDecl)
Record the func_info tag for a function, either a C++ special member form (constructor,...
void replaceUsesOfNonProtoTypeWithRealFunction(mlir::Operation *old, cir::FuncOp newFn)
This function is called when we implement a function with no prototype, e.g.
bool shouldEmitFunction(clang::GlobalDecl gd)
Check if fd ends up calling itself directly through asm label or builtin-pointer-to-self trickery (e....
llvm::StringRef getMangledName(clang::GlobalDecl gd)
CharUnits computeNonVirtualBaseClassOffset(const CXXRecordDecl *derivedClass, llvm::iterator_range< CastExpr::path_const_iterator > path)
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.
cir::GlobalLinkageKind getCIRLinkageVarDefinition(const VarDecl *vd)
clang::ASTContext & getASTContext() const
mlir::Operation * getWeakRefReference(const clang::ValueDecl *vd)
Return the symbol that a weakref declaration refers to: the cir.func or cir.global named by its alias...
void insertGlobalSymbol(mlir::Operation *op)
cir::FuncOp getAddrOfCXXStructor(clang::GlobalDecl gd, const CIRGenFunctionInfo *fnInfo=nullptr, cir::FuncType fnType=nullptr, bool dontDefer=false, ForDefinition_t isForDefinition=NotForDefinition)
CIRGenCUDARuntime & getCUDARuntime()
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 addSYCLModuleIdAttr(cir::FuncOp fn)
std::vector< cir::CIRGlobalValueInterface > llvmUsed
List of global values which are required to be present in the object file; This is used for forcing v...
void emitOMPCapturedExpr(const OMPCapturedExprDecl *d)
std::optional< llvm::SmallVector< int32_t > > buildMemberPath(const CXXRecordDecl *destClass, const ValueDecl *decl)
Build a GEP-style field-index path from destClass to decl.
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)
cir::TLSModel getDefaultCIRTLSModel() const
Get TLS mode from CodeGenOptions.
void setGlobalTlsReferences(const VarDecl &vd, cir::GlobalOp globalOp)
void emitOpenCLKernelArgMetadata(cir::FuncOp func, const clang::FunctionDecl *fd)
Generate OpenCL kernel argument metadata for a kernel function.
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::FuncOp createCIRBuiltinFunction(mlir::Location loc, llvm::StringRef name, cir::FuncType ty, const clang::FunctionDecl *fd)
Create a CIR function with builtin attribute set.
cir::GlobalOp getAddrOfTemplateParamObject(const TemplateParamObjectDecl *tpo)
Get the GlobalOp of a template parameter object.
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.
llvm::DenseMap< const UnnamedGlobalConstantDecl *, cir::GlobalOp > unnamedGlobalConstantDeclMap
std::vector< cir::CIRGlobalValueInterface > llvmCompilerUsed
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.
void emitOMPRequiresDecl(const OMPRequiresDecl *d)
void emitGlobalDefinition(clang::GlobalDecl gd, mlir::Operation *op=nullptr)
clang::DiagnosticsEngine & getDiags() const
cir::GlobalLinkageKind getCIRLinkageForDeclarator(const DeclaratorDecl *dd, GVALinkage linkage)
mlir::Attribute getAddrOfRTTIDescriptor(mlir::Location loc, QualType ty, bool forEH=false)
Get the address of the RTTI descriptor for the given type.
cir::GlobalOp createGlobalString(mlir::Location loc, llvm::StringRef str, llvm::StringRef name)
Create a private constant global holding the null-terminated string str, mirroring llvm::IRBuilder::C...
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
static mlir::SymbolTable::Visibility getMLIRVisibility(cir::GlobalOp op)
void setCIRFunctionAttributes(GlobalDecl gd, const CIRGenFunctionInfo &info, cir::FuncOp func, bool isThunk)
Set the CIR function attributes (Sext, zext, etc).
const llvm::Triple & getTriple() const
void emitTentativeDefinition(const VarDecl *d)
const cir::CIRDataLayout & getDataLayout() const
void emitAliasDefinition(GlobalDecl gd)
Emit a definition for an __attribute__((alias)) declaration.
void addUsedGlobal(cir::CIRGlobalValueInterface gv)
Add a global value to the llvmUsed list.
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 error(SourceLocation loc, llvm::StringRef error)
Emit a general error that something can't be done.
void emitGlobalDecl(const clang::GlobalDecl &d)
Helper for emitDeferred to apply actual codegen.
void emitGlobalVarDefinition(const clang::VarDecl *vd, bool isTentative=false)
static std::optional< cir::FramePointerKind > getFramePointerKind(CodeGenOptions::FramePointerKind kind)
Returns the frame pointer kind to record on functions and on the module, or std::nullopt when kind is...
cir::FuncOp createRuntimeFunction(cir::FuncType ty, llvm::StringRef name, mlir::NamedAttrList extraAttrs={}, bool isLocal=false, bool assumeConvergent=false)
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.
mlir::TypedAttr emitNullConstantAttr(QualType t)
void emitLLVMUsed()
Emit llvm.used and llvm.compiler.used globals.
mlir::Value emitMemberPointerConstant(const UnaryOperator *e)
void emitGlobalOpenACCDecl(const clang::OpenACCConstructDecl *cd)
bool verifyModule() const
LangAS getGlobalVarAddressSpace(const VarDecl *decl)
Return the AST address space of the underlying global variable for D, as determined by its declaratio...
void setTLSMode(mlir::Operation *op, const VarDecl &d, bool isExtendingDecl=false)
Set TLS mode for the given operation based on the given variable declaration.
void emitExplicitCastExprType(const ExplicitCastExpr *e, CIRGenFunction *cgf=nullptr)
Emit type info if type of an expression is a variably modified type.
void eraseGlobalSymbol(mlir::Operation *op)
mlir::Operation * getAddrOfGlobalTemporary(const MaterializeTemporaryExpr *mte, const Expr *init)
Returns a pointer to a global variable representing a temporary with static or thread storage duratio...
std::map< llvm::StringRef, clang::GlobalDecl > deferredDecls
This contains all the decls which have definitions but which are deferred for emission and therefore ...
void errorUnsupported(const Stmt *s, llvm::StringRef type)
Print out an error that codegen doesn't support the specified stmt yet.
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.
llvm::StringMap< mlir::Operation * > symbolLookupCache
Cache for O(1) symbol lookups by name, replacing the O(N) linear scan in SymbolTable::lookupSymbolIn ...
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.
mlir::ArrayAttr getOrCreateAnnotationArgs(const clang::AnnotateAttr *attr)
Build (or fetch from the dedup cache) the args ArrayAttr for an annotation.
cir::GlobalLinkageKind getFunctionLinkage(GlobalDecl gd)
void updateCompletedType(const clang::TagDecl *td)
const clang::CodeGenOptions & getCodeGenOpts() const
void emitDeferredVTables()
Emit any vtables which we deferred and still have a use for.
const clang::LangOptions & getLangOpts() const
void printPostfixForExternalizedDecl(llvm::raw_ostream &os, const Decl *d)
Print the postfix for externalized static variable or kernels for single source offloading languages ...
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::NamedAttrList extraAttrs={})
void emitOpenACCRoutineDecl(const clang::FunctionDecl *funcDecl, cir::FuncOp func, SourceLocation pragmaLoc, ArrayRef< const OpenACCClause * > clauses)
void emitVTablesOpportunistically()
Try to emit external vtables as available_externally if they have emitted all inlined virtual functio...
cir::GlobalOp createGlobalOp(mlir::Location loc, llvm::StringRef name, mlir::Type t, bool isConstant=false, mlir::ptr::MemorySpaceAttrInterface addrSpace={}, mlir::Operation *insertPoint=nullptr)
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.
mlir::Value castGlobalToDeclAddrSpace(mlir::Value addr, const VarDecl &vd)
Cast addr, the address of the global vd, to the address space of the declared type of vd if they diff...
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)
static cir::VisibilityKind getCIRVisibilityKind(Visibility v)
void setGVPropertiesAux(mlir::Operation *op, const NamedDecl *d) const
LangAS getLangTempAllocaAddressSpace() const
Returns the address space for temporary allocations in the language.
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
void setCIRFunctionAttributesForDefinition(const clang::Decl *decl, cir::FuncOp f)
Set extra attributes (inline, etc.) for a function.
void replaceGlobal(cir::GlobalOp oldGV, cir::GlobalOp newGV)
Replace all uses of the old global with the new global, updating types and references as needed.
llvm::StringMap< unsigned > cgGlobalNames
mlir::TypedAttr emitNullMemberAttr(QualType t, const MemberPointerType *mpt)
Returns a null attribute to represent either a null method or null data member, depending on the type...
mlir::Operation * getGlobalValue(llvm::StringRef ref)
void emitOMPDeclareReduction(const OMPDeclareReductionDecl *d)
mlir::ModuleOp getModule() const
bool supportsCOMDAT() const
void addCompilerUsedGlobal(cir::CIRGlobalValueInterface gv)
Add a global value to the llvmCompilerUsed list.
clang::CharUnits getNaturalTypeAlignment(clang::QualType t, LValueBaseInfo *baseInfo=nullptr, bool forPointeeType=false)
FIXME: this could likely be a common helper and not necessarily related with codegen.
mlir::MLIRContext & getMLIRContext()
void emitSYCLKernelCaller(const clang::FunctionDecl *kernelEntryPointFn, clang::ASTContext &ctx)
Emit the SYCL kernel caller offload entry point function generated for a function declared with the s...
mlir::Operation * getAddrOfGlobal(clang::GlobalDecl gd, ForDefinition_t isForDefinition=NotForDefinition)
void maybeSetTrivialComdat(const clang::Decl &d, mlir::Operation *op)
bool isEmptyFieldForMemberPointer(const FieldDecl *field)
Returns true if field is a potentially-overlapping field with no CIR field index (e....
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.
bool lookupRepresentativeDecl(llvm::StringRef mangledName, clang::GlobalDecl &gd) const
void emitDeclContext(const DeclContext *dc)
mlir::ptr::MemorySpaceAttrInterface getGlobalCIRAddressSpace(LangAS as)
Return the CIR address space attribute for a global in as, honoring the target address space map wher...
clang::CharUnits getNaturalPointeeTypeAlignment(clang::QualType t, LValueBaseInfo *baseInfo=nullptr)
void emitGlobal(clang::GlobalDecl gd)
Emit code for a single global function or variable declaration.
bool mayBeEmittedEagerly(const clang::ValueDecl *d)
Determine whether the definition can be emitted eagerly, or should be delayed until the end of the tr...
void constructAttributeList(llvm::StringRef name, const CIRGenFunctionInfo &info, CIRGenCalleeInfo calleeInfo, mlir::NamedAttrList &attrs, llvm::MutableArrayRef< mlir::NamedAttrList > argAttrs, mlir::NamedAttrList &retAttrs, cir::CallingConv &callingConv, bool attrOnCallSite, bool isThunk)
Get the CIR attributes and calling convention to use for a particular function type.
void addGlobalAnnotations(const clang::ValueDecl *d, mlir::Operation *gv)
Add global annotations for a global value (GlobalOp or FuncOp).
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)
cir::GlobalOp getOrCreateCIRGlobal(llvm::StringRef mangledName, mlir::Type ty, LangAS langAS, mlir::Location loc, const VarDecl *d, ForDefinition_t isForDefinition)
If the specified mangled name is not in the module, create and return an mlir::GlobalOp value.
std::vector< clang::GlobalDecl > deferredDeclsToEmit
cir::AnnotationAttr emitAnnotateAttr(const clang::AnnotateAttr *aa)
Create cir::AnnotationAttr for a single AnnotateAttr.
void emitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *d)
CIRGenOpenMPRuntime & getOpenMPRuntime()
void emitAMDGPUMetadata()
Emits AMDGPU specific Metadata.
void emitOMPGroupPrivateDecl(const OMPGroupPrivateDecl *d)
mlir::Attribute getConstantArrayFromStringLiteral(const StringLiteral *e)
Return a constant array for the given string.
void setCommonAttributes(GlobalDecl gd, mlir::Operation *op)
Set attributes which are common to any form of a global definition (alias, Objective-C method,...
void emitDeclareTargetFunction(const FunctionDecl *fd, cir::FuncOp funcOp)
If the function has an OMPDeclareTargetDeclAttr, set the corresponding omp.declare_target attribute o...
void registerTargetGlobalVariable(const VarDecl *vd)
Register a global variable that may need an offload entry.
This class handles record and union layout info while lowering AST types to CIR types.
bool hasNonVirtualBaseCIRField(const CXXRecordDecl *rd) const
unsigned getCIRFieldNo(const clang::FieldDecl *fd) const
Return cir::RecordType element number that corresponds to the field FD.
bool hasCIRField(const clang::FieldDecl *fd) const
bool isZeroInitializable() const
Check whether this struct can be C++ zero-initialized with a zeroinitializer.
unsigned getNonVirtualBaseCIRFieldNo(const CXXRecordDecl *rd) const
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)
mlir::ptr::MemorySpaceAttrInterface getPointerAddressSpace(clang::QualType pointeeTy) const
Returns the CIR address space for a pointer/reference to pointeeTy, or a null attribute for the defau...
cir::FuncType getFunctionType(const CIRGenFunctionInfo &info)
Get the CIR function type for.
const CIRGenRecordLayout & getCIRGenRecordLayout(const clang::RecordDecl *rd)
Return record layout info for the given record decl.
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.
void finalize(cir::GlobalOp gv)
mlir::Attribute emitForInitializer(const APValue &value, QualType destType)
virtual clang::LangAS getGlobalVarAddressSpace(CIRGenModule &cgm, const clang::VarDecl *d) const
Get target favored AST address space of a global variable for languages other than OpenCL and CUDA.
virtual mlir::ptr::MemorySpaceAttrInterface getGlobalCIRAddressSpace(clang::LangAS as) const
Get the CIR address space attribute for a global in AST address space as.
virtual mlir::ptr::MemorySpaceAttrInterface getCIRAllocaAddressSpace() const
Get the address space for alloca.
virtual void setTargetAttributes(const clang::Decl *decl, mlir::Operation *global, CIRGenModule &module) const
Provides a convenient hook to handle extra target-specific attributes for the given global.
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.
CXXRecordDecl * getMostRecentDecl()
bool hasDefinition() const
This is an opaque type for sizes expressed in character units.
llvm::Align getAsAlign() const
Returns Quantity as a valid llvm::Align, Beware llvm::Align assumes power of two 8-bit bytes.
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.
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 isInStdNamespace() const
bool isWeakImported() const
Determine whether this is a weak-imported symbol.
bool isInExportDeclContext() const
Whether this declaration was exported in a lexical context.
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
SourceLocation getLocation() const
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
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.
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
unsigned getCustomDiagID(Level L, const char(&FormatString)[N])
Return an ID for a diagnostic with the specified format string and level.
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.
bool EvaluateAsRValue(EvalResult &Result, const ASTContext &Ctx, bool InConstantContext=false) const
EvaluateAsRValue - Return true if this is a constant which we can fold to an rvalue using any crazy t...
Represents a member of a struct/union/class.
unsigned getFieldIndex() const
Returns the index of this field within its record, as appropriate for passing to ASTRecordLayout::get...
const RecordDecl * getParent() const
Returns the parent of this field declaration, which is the struct in which this field is defined.
bool isPotentiallyOverlapping() const
Determine if this field is of potentially-overlapping class type, that is, subobject with the [[no_un...
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={})
ArrayRef< ParmVarDecl * > parameters() const
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.
FunctionDecl * getDefinition()
Get the definition for this declaration.
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.
CXXCtorType getCtorType() const
GlobalDecl getCanonicalDecl() const
KernelReferenceKind getKernelReferenceKind() const
GlobalDecl getWithDecl(const Decl *D)
unsigned getMultiVersionIndex() const
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.
@ FPE_Ignore
Assume that floating-point exceptions are masked.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
std::string CUID
The user provided compilation unit ID, if non-empty.
Visibility getVisibility() const
void setLinkage(Linkage L)
Linkage getLinkage() const
bool isVisibilityExplicit() const
MangleContext - Context for tracking state which persists across multiple calls to the C++ name mangl...
bool isTriviallyRecursive(const FunctionDecl *FD)
Return true if FD's body contains a direct call back to the symbol it links as, through an asm label ...
bool shouldMangleDeclName(const NamedDecl *D)
void mangleName(GlobalDecl GD, raw_ostream &)
ManglerKind getKind() const
virtual void mangleReferenceTemporary(const VarDecl *D, unsigned ManglingNumber, raw_ostream &)=0
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
StorageDuration getStorageDuration() const
Retrieve the storage duration for the materialized temporary.
APValue * getOrCreateValue(bool MayCreate) const
Get the storage for the constant value of a materialized temporary of static storage duration.
ValueDecl * getExtendingDecl()
Get the declaration which triggered the lifetime-extension of this temporary, if any.
unsigned getManglingNumber() const
A pointer to member type per C++ 8.3.3 - Pointers to members.
CXXRecordDecl * getMostRecentCXXRecordDecl() const
Note: this can trigger extra deserialization when external AST sources are used.
Describes a module or submodule.
SourceLocation DefinitionLoc
The location of the module definition.
llvm::iterator_range< submodule_iterator > submodules()
bool isModuleImplementation() const
Is this a module implementation.
bool isNamedModule() const
Does this Module is a named module of a standard named module?
Module * getTopLevelModule()
Retrieve the top-level module for this (sub)module, which may be this module.
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.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
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
Represents a struct/union/class.
RecordDecl * getMostRecentDecl()
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
Stmt - This represents one statement.
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
SourceLocation getBeginLoc() const LLVM_READONLY
StringLiteral - This represents a string literal expression, e.g.
SourceLocation getBeginLoc() const LLVM_READONLY
unsigned getLength() const
uint32_t getCodeUnit(size_t I) const
Return the code unit at the given position.
StringRef getString() const
unsigned getCharByteWidth() const
Represents the declaration of a struct/union/class/enum.
static const auto & getSpelling(Kind ABIKind)
TargetOptions & getTargetOpts() const
Retrieve the target options.
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
bool isReadOnlyFeature(StringRef Feature) const
Determine whether the given target feature is read only.
virtual ParsedTargetAttr parseTargetAttr(StringRef Str) const
virtual bool initFeatureMap(llvm::StringMap< bool > &Features, DiagnosticsEngine &Diags, StringRef CPU, const std::vector< std::string > &FeatureVec) const
Initialize the map with the default set of target features for the CPU this should include all legal ...
std::vector< std::string > Features
The list of target specific features to enable or disable – this should be a list of strings starting...
std::string TuneCPU
If given, the name of the target CPU to tune code for.
std::string CPU
If given, the name of the target CPU to generate code for.
A template parameter object.
const APValue & getValue() const
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
bool isPointerType() const
const T * castAs() const
Member-template castAs<specific type>.
bool isReferenceType() const
bool isCUDADeviceBuiltinSurfaceType() const
Check if the type is the CUDA device builtin surface type.
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool isVariablyModifiedType() const
Whether this type is a variably-modified type (C99 6.7.5).
bool isCUDADeviceBuiltinTextureType() const
Check if the type is the CUDA device builtin texture type.
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...
bool isObjCObjectPointerType() const
bool isMemberFunctionPointerType() const
const T * getAs() const
Member-template getAs<specific type>'.
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Expr * getSubExpr() const
An artificial decl, representing a global anonymous constant value which is uniquified by value withi...
const APValue & getValue() 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.
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
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.
bool isStaticLocal() const
Returns true if a variable with function scope is a static local variable.
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_None
Not a TLS variable.
@ DeclarationOnly
This declaration is only a declaration.
@ Definition
This declaration is definitely a definition.
DefinitionKind hasDefinition(ASTContext &) const
Check whether this variable is defined in this translation unit.
bool isLocalVarDecl() const
Returns true for local variable declarations other than parameters.
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.
mlir::ptr::MemorySpaceAttrInterface normalizeDefaultAddressSpace(mlir::ptr::MemorySpaceAttrInterface addrSpace)
Normalize LangAddressSpace::Default to null (empty attribute).
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 ...
std::unique_ptr< TargetCIRGenInfo > createAMDGPUTargetCIRGenInfo(CIRGenTypes &cgt)
std::unique_ptr< TargetCIRGenInfo > createNVPTXTargetCIRGenInfo(CIRGenTypes &cgt)
CIRGenCXXABI * CreateCIRGenItaniumCXXABI(CIRGenModule &cgm)
Creates and Itanium-family ABI.
std::unique_ptr< TargetCIRGenInfo > createX8664TargetCIRGenInfo(CIRGenTypes &cgt)
std::unique_ptr< TargetCIRGenInfo > createCommonSPIRTargetCIRGenInfo(CIRGenTypes &cgt)
std::unique_ptr< TargetCIRGenInfo > createSystemZTargetCIRGenInfo(CIRGenTypes &cgt)
std::unique_ptr< TargetCIRGenInfo > createAArch64TargetCIRGenInfo(CIRGenTypes &cgt)
CIRGenCXXABI * CreateCIRGenMicrosoftCXXABI(CIRGenModule &cgm)
Creates Microsoft ABI.
CIRGenCUDARuntime * createNVCUDARuntime(CIRGenModule &cgm)
LangAS getGlobalConstantAddressSpace(const LangOptions &LangOpts, const TargetInfo &Target)
Determines whether the language options require us to model unwind exceptions.
bool isVarDeclStrongDefinition(const ASTContext &Ctx, const VarDecl *D, bool NoCommon)
Check whether D is a strong definition, and thus must not be given common linkage.
bool isEmptyFieldForLayout(const ASTContext &Ctx, const FieldDecl *FD)
Return true iff the field is "empty", that is, either a zero-width bit-field or an isEmptyRecordForLa...
llvm::SmallVector< Module *, 8 > importedModulesToInitialize(Module *Primary, llvm::ArrayRef< Module * > Imported)
The C++20 named modules whose Itanium initializer function the global init function of a translation ...
bool hasUnwindExceptions(const LangOptions &LangOpts)
bool shouldBeInCOMDAT(const ASTContext &Ctx, const Decl &D)
Check whether D should be emitted into a COMDAT group.
const internal::VariadicDynCastAllOfMatcher< Decl, VarDecl > varDecl
Matches variable declarations.
const internal::VariadicAllOfMatcher< Attr > attr
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.
Top level wrappers for InstallAPI frontend operations.
bool isa(CodeGen::Address addr)
GVALinkage
A more specific kind of linkage than enum Linkage.
@ GVA_AvailableExternally
QualType pointeeType(QualType T)
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
@ 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.
@ FirstTargetAddressSpace
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)
@ HiddenVisibility
Objects with "hidden" visibility are not seen by the dynamic linker.
__builtin_elementwise_add_sat __builtin_elementwise_sub_sat __builtin_riscv_ssha_i32 __builtin_riscv_sshl_u32 __builtin_riscv_nclipu_u32 int64_t
__builtin_elementwise_add_sat __builtin_elementwise_sub_sat __builtin_riscv_ssha_i32 __builtin_riscv_sshl_u32 uint64_t
__builtin_elementwise_add_sat __builtin_elementwise_sub_sat int32_t
static bool globalCtorLexOrder()
static bool opFuncArmNewAttr()
static bool getRuntimeFunctionDecl()
static bool addressSpace()
static bool opGlobalThreadLocal()
static bool opFuncMultiVersioning()
static bool sourceLanguageCases()
static bool opFuncAstDeclAttr()
static bool stackProtector()
static bool moduleNameHash()
static bool opGlobalVisibility()
static bool setDLLStorageClass()
static bool opFuncParameterAttributes()
static bool targetCIRGenInfoArch()
static bool opFuncExtraAttrs()
static bool attributeNoBuiltin()
static bool opGlobalDLLImportExport()
static bool opGlobalPartition()
static bool opGlobalPragmaClangSection()
static bool deferredCXXGlobalInit()
static bool opFuncOperandBundles()
static bool opFuncCallingConv()
static bool globalCtorAssociatedData()
static bool defaultVisibility()
static bool opFuncExceptions()
static bool opFuncArmStreamingAttr()
static bool opFuncMaybeHandleStaticInExternC()
static bool checkAliases()
static bool generateDebugInfo()
static bool emitModuleLinkOptions()
static bool targetCIRGenInfoOS()
static bool maybeHandleStaticInExternC()
static bool setLLVMFunctionFEnvAttributes()
mlir::Type uCharTy
ClangIR char.
unsigned char SizeSizeInBytes
unsigned char PointerAlignInBytes
cir::PointerType allocaInt8PtrTy
void* in alloca address space
cir::PointerType uInt8PtrTy
mlir::ptr::MemorySpaceAttrInterface cirAllocaAddressSpace
cir::PointerType voidPtrTy
void* in address space 0
EvalResult is a struct with detailed info about an evaluated expression.
APValue Val
Val - This is the value the expression can be folded to.
bool hasSideEffects() const
Return true if the evaluated expression has side effects.
Describes how types, statements, expressions, and declarations should be printed.