19#include "mlir/Dialect/OpenMP/OpenMPOffloadUtils.h"
20#include "mlir/IR/SymbolTable.h"
23#include "clang/AST/Attrs.inc"
37#include "llvm/ADT/STLExtras.h"
38#include "llvm/ADT/StringExtras.h"
39#include "llvm/ADT/StringRef.h"
40#include "llvm/Support/raw_ostream.h"
44#include "mlir/Dialect/Ptr/IR/MemorySpaceInterfaces.h"
45#include "mlir/IR/Attributes.h"
46#include "mlir/IR/BuiltinOps.h"
47#include "mlir/IR/Location.h"
48#include "mlir/IR/MLIRContext.h"
49#include "mlir/IR/Operation.h"
50#include "mlir/IR/Verifier.h"
59 case TargetCXXABI::GenericItanium:
60 case TargetCXXABI::GenericAArch64:
61 case TargetCXXABI::AppleARM64:
62 case TargetCXXABI::GenericARM:
65 case TargetCXXABI::Fuchsia:
66 case TargetCXXABI::iOS:
67 case TargetCXXABI::WatchOS:
68 case TargetCXXABI::GenericMIPS:
69 case TargetCXXABI::WebAssembly:
70 case TargetCXXABI::XL:
71 case TargetCXXABI::Microsoft:
72 cgm.
errorNYI(
"createCXXABI: C++ ABI kind");
76 llvm_unreachable(
"invalid C++ ABI kind");
79CIRGenModule::CIRGenModule(mlir::MLIRContext &mlirContext,
83 : builder(mlirContext, *this), astContext(astContext),
84 langOpts(astContext.
getLangOpts()), codeGenOpts(cgo),
85 theModule{
mlir::ModuleOp::create(
mlir::UnknownLoc::get(&mlirContext))},
86 diags(diags), target(astContext.getTargetInfo()),
87 abi(
createCXXABI(*this)), genTypes(*this), vtables(*this) {
115 .toCharUnitsFromBits(
119 const unsigned charSize = astContext.getTargetInfo().getCharWidth();
123 const unsigned sizeTypeSize =
124 astContext.getTypeSize(astContext.getSignedSizeType());
125 SizeSizeInBytes = astContext.toCharUnitsFromBits(sizeTypeSize).getQuantity();
132 std::optional<cir::SourceLanguage> sourceLanguage = getCIRSourceLanguage();
135 cir::CIRDialect::getSourceLanguageAttrName(),
136 cir::SourceLanguageAttr::get(&mlirContext, *sourceLanguage));
137 theModule->setAttr(cir::CIRDialect::getTripleAttrName(),
138 builder.getStringAttr(
getTriple().str()));
140 if (cgo.OptimizationLevel > 0 || cgo.OptimizeSize > 0)
141 theModule->setAttr(cir::CIRDialect::getOptInfoAttrName(),
142 cir::OptInfoAttr::get(&mlirContext,
143 cgo.OptimizationLevel,
146 if (langOpts.OpenMP) {
147 mlir::omp::OffloadModuleOpts ompOpts(
148 langOpts.OpenMPTargetDebug, langOpts.OpenMPTeamSubscription,
149 langOpts.OpenMPThreadSubscription, langOpts.OpenMPNoThreadState,
150 langOpts.OpenMPNoNestedParallelism, langOpts.OpenMPIsTargetDevice,
151 getTriple().isGPU(), langOpts.OpenMPForceUSM, langOpts.OpenMP,
152 langOpts.OMPHostIRFile, langOpts.OMPTargetTriples, langOpts.NoGPULib);
153 mlir::omp::setOffloadModuleInterfaceAttributes(theModule, ompOpts);
159 createOpenMPRuntime();
164 FileID mainFileId = astContext.getSourceManager().getMainFileID();
166 *astContext.getSourceManager().getFileEntryForID(mainFileId);
169 theModule.setSymName(path);
170 theModule->setLoc(mlir::FileLineColLoc::get(&mlirContext, path,
177 llvm::StringRef cudaBinaryName = codeGenOpts.CudaGpuBinaryFileName;
178 if (!cudaBinaryName.empty()) {
179 theModule->setAttr(cir::CIRDialect::getCUDABinaryHandleAttrName(),
180 cir::CUDABinaryHandleAttr::get(
181 &mlirContext, mlir::StringAttr::get(
182 &mlirContext, cudaBinaryName)));
189void CIRGenModule::createCUDARuntime() {
193void CIRGenModule::createOpenMPRuntime() {
194 openMPRuntime = std::make_unique<CIRGenOpenMPRuntime>(*
this);
205 auto &layout = astContext.getASTRecordLayout(rd);
210 return layout.getAlignment();
213 return layout.getNonVirtualAlignment();
218 bool forPointeeType) {
228 if (
unsigned align = tt->getDecl()->getMaxAlignment()) {
231 return astContext.toCharUnitsFromBits(align);
239 t = astContext.getBaseElementType(t);
260 }
else if (forPointeeType && !alignForArray &&
264 alignment = astContext.getTypeAlignInChars(t);
269 if (
unsigned maxAlign = astContext.getLangOpts().MaxTypeAlign) {
271 !astContext.isAlignmentRequired(t))
285 if (theTargetCIRGenInfo)
286 return *theTargetCIRGenInfo;
289 switch (triple.getArch()) {
296 case llvm::Triple::x86_64: {
297 switch (triple.getOS()) {
304 case llvm::Triple::Linux:
306 return *theTargetCIRGenInfo;
309 case llvm::Triple::nvptx:
310 case llvm::Triple::nvptx64:
312 return *theTargetCIRGenInfo;
313 case llvm::Triple::amdgcn: {
315 return *theTargetCIRGenInfo;
317 case llvm::Triple::spirv:
318 case llvm::Triple::spirv32:
319 case llvm::Triple::spirv64:
321 return *theTargetCIRGenInfo;
326 assert(cLoc.
isValid() &&
"expected valid source location");
330 return mlir::FileLineColLoc::get(builder.getStringAttr(filename),
335 assert(cRange.
isValid() &&
"expected a valid source range");
338 mlir::Attribute metadata;
339 return mlir::FusedLoc::get({begin, end}, metadata, builder.getContext());
348 false, isForDefinition);
382 assert(op &&
"expected a valid global op");
390 mlir::Operation *globalValueOp = op;
391 if (
auto gv = dyn_cast<cir::GetGlobalOp>(op)) {
393 assert(globalValueOp &&
"expected a valid global op");
396 if (
auto cirGlobalValue =
397 dyn_cast<cir::CIRGlobalValueInterface>(globalValueOp))
398 if (!cirGlobalValue.isDeclaration())
419 assert(deferredVTables.empty());
429 std::vector<GlobalDecl> curDeclsToEmit;
448 if (
auto *
attr =
decl->getAttr<AttrT>())
449 return attr->isImplicit();
450 return decl->isImplicit();
455 assert(langOpts.CUDA &&
"Should not be called by non-CUDA languages");
460 return !langOpts.CUDAIsDevice || global->
hasAttr<CUDADeviceAttr>() ||
461 global->
hasAttr<CUDAConstantAttr>() ||
462 global->
hasAttr<CUDASharedAttr>() ||
472 os << (isa<VarDecl>(d) ?
".static." :
".intern.");
474 os << (isa<VarDecl>(d) ?
"__static__" :
"__intern__");
481 "printPostfixForExternalizedDecl: CUID is not specified");
488 if (
const auto *cd = dyn_cast<clang::OpenACCConstructDecl>(gd.
getDecl())) {
496 if (global->hasAttr<WeakRefAttr>())
501 if (global->hasAttr<AliasAttr>()) {
514 "Expected Variable or Function");
515 if (
const auto *
varDecl = dyn_cast<VarDecl>(global)) {
519 }
else if (langOpts.CUDAIsDevice) {
520 const auto *
functionDecl = dyn_cast<FunctionDecl>(global);
521 if ((!global->hasAttr<CUDADeviceAttr>() ||
522 (langOpts.OffloadImplicitHostDeviceTemplates &&
527 !
getASTContext().CUDAImplicitHostDeviceFunUsedByDevice.count(
529 !global->hasAttr<CUDAGlobalAttr>() &&
531 !global->hasAttr<CUDAHostAttr>()))
534 }
else if (!global->hasAttr<CUDAHostAttr>() &&
535 global->hasAttr<CUDADeviceAttr>())
539 if (langOpts.OpenMP) {
541 if (openMPRuntime && openMPRuntime->emitTargetGlobal(gd))
543 if (
auto *drd = dyn_cast<OMPDeclareReductionDecl>(global)) {
548 if (
auto *dmd = dyn_cast<OMPDeclareMapperDecl>(global)) {
555 if (
const auto *fd = dyn_cast<FunctionDecl>(global)) {
558 if (fd->hasAttr<AnnotateAttr>()) {
561 deferredAnnotations[mangledName] = fd;
563 if (!fd->doesThisDeclarationHaveABody()) {
564 if (!fd->doesDeclarationForceExternallyVisibleDefinition() &&
575 assert(vd->isFileVarDecl() &&
"Cannot emit local var decl as global.");
577 !astContext.isMSStaticDataMemberInlineDefinition(vd)) {
581 if (astContext.getInlineVariableDefinitionKind(vd) ==
620 mlir::Operation *op) {
624 cir::FuncOp funcOp = dyn_cast_if_present<cir::FuncOp>(op);
625 if (!funcOp || funcOp.getFunctionType() != funcType) {
631 if (!funcOp.isDeclaration())
643 mlir::OpBuilder::InsertionGuard guard(builder);
648 setNonAliasAttributes(gd, funcOp);
651 auto getPriority = [
this](
const auto *
attr) ->
int {
655 return attr->DefaultPriority;
658 if (
const ConstructorAttr *ca = funcDecl->getAttr<ConstructorAttr>())
660 if (
const DestructorAttr *da = funcDecl->getAttr<DestructorAttr>())
663 if (funcDecl->getAttr<AnnotateAttr>())
666 if (
getLangOpts().OpenMP && funcDecl->hasAttr<OMPDeclareTargetDeclAttr>())
672 std::optional<int> priority) {
681 ctor.setGlobalCtorPriority(priority);
686 std::optional<int> priority) {
687 if (codeGenOpts.RegisterGlobalDtorsWithAtExit &&
689 errorNYI(dtor.getLoc(),
"registerGlobalDtorsWithAtExit");
692 dtor.setGlobalDtorPriority(priority);
717 mlir::ptr::MemorySpaceAttrInterface addrSpace,
718 mlir::Operation *insertPoint) {
723 mlir::OpBuilder::InsertionGuard guard(builder);
729 builder.setInsertionPoint(insertPoint);
735 builder.setInsertionPointToStart(
getModule().getBody());
738 g = cir::GlobalOp::create(builder, loc, name, t, isConstant, addrSpace);
744 mlir::SymbolTable::setSymbolVisibility(
745 g, mlir::SymbolTable::Visibility::Private);
753 if (isa_and_nonnull<NamedDecl>(d))
757 if (
auto gvi = mlir::dyn_cast<cir::CIRGlobalValueInterface>(gv)) {
758 if (d && d->
hasAttr<UsedAttr>())
761 if (
const auto *vd = dyn_cast_if_present<VarDecl>(d);
762 vd && ((codeGenOpts.KeepPersistentStorageVariables &&
763 (vd->getStorageDuration() ==
SD_Static ||
764 vd->getStorageDuration() ==
SD_Thread)) ||
765 (codeGenOpts.KeepStaticConsts &&
767 vd->getType().isConstQualified())))
773static std::vector<std::string>
775 llvm::StringMap<bool> &featureMap) {
776 llvm::StringMap<bool> defaultFeatureMap;
780 std::vector<std::string> delta;
781 for (
const auto &[k, v] : featureMap) {
782 auto defaultIt = defaultFeatureMap.find(k);
783 if (defaultIt == defaultFeatureMap.end() || defaultIt->getValue() != v)
784 delta.push_back((v ?
"+" :
"-") + k.str());
790bool CIRGenModule::getCPUAndFeaturesAttributes(
791 GlobalDecl gd, llvm::StringMap<std::string> &attrs,
792 bool setTargetFeatures) {
798 std::vector<std::string> features;
802 const auto *fd = dyn_cast_or_null<FunctionDecl>(gd.
getDecl());
803 fd = fd ? fd->getMostRecentDecl() : fd;
804 const auto *td = fd ? fd->getAttr<TargetAttr>() :
nullptr;
805 const auto *tv = fd ? fd->getAttr<TargetVersionAttr>() :
nullptr;
806 assert((!td || !tv) &&
"both target_version and target specified");
807 const auto *sd = fd ? fd->getAttr<CPUSpecificAttr>() :
nullptr;
808 const auto *tc = fd ? fd->getAttr<TargetClonesAttr>() :
nullptr;
809 bool addedAttr =
false;
810 if (td || tv || sd || tc) {
811 llvm::StringMap<bool> featureMap;
812 astContext.getFunctionFeatureMap(featureMap, gd);
818 llvm::StringRef featureStr = td ? td->getFeaturesStr() : llvm::StringRef();
821 if (!featureStr.empty()) {
822 clang::ParsedTargetAttr parsedAttr =
824 if (!parsedAttr.
CPU.empty() &&
826 targetCPU = parsedAttr.
CPU;
829 if (!parsedAttr.
Tune.empty() &&
831 tuneCPU = parsedAttr.
Tune;
847 features.reserve(features.size() + featureMap.size());
848 for (
const auto &entry : featureMap)
849 features.push_back((entry.getValue() ?
"+" :
"-") +
850 entry.getKey().str());
855 llvm::StringMap<bool> featureMap;
857 astContext.getFunctionFeatureMap(featureMap, gd);
868 if (!targetCPU.empty()) {
869 attrs[
"cir.target-cpu"] = targetCPU.str();
872 if (!tuneCPU.empty()) {
873 attrs[
"cir.tune-cpu"] = tuneCPU.str();
876 if (!features.empty() && setTargetFeatures) {
877 llvm::erase_if(features, [&](
const std::string &f) {
878 assert(!f.empty() && (f[0] ==
'+' || f[0] ==
'-') &&
879 "feature string must start with '+' or '-'");
882 llvm::sort(features);
883 attrs[
"cir.target-features"] = llvm::join(features,
",");
891void CIRGenModule::setNonAliasAttributes(GlobalDecl gd, mlir::Operation *op) {
896 if (
auto gvi = mlir::dyn_cast<cir::CIRGlobalValueInterface>(op)) {
897 if (
const auto *sa = d->
getAttr<SectionAttr>())
898 gvi.setSection(builder.getStringAttr(sa->getName()));
902 if (
auto func = dyn_cast<cir::FuncOp>(op)) {
903 llvm::StringMap<std::string> attrs;
904 if (getCPUAndFeaturesAttributes(gd, attrs)) {
908 for (
const auto &[key, val] : attrs)
909 func->setAttr(key, builder.getStringAttr(val));
919std::optional<cir::SourceLanguage> CIRGenModule::getCIRSourceLanguage()
const {
920 using ClangStd = clang::LangStandard;
921 using CIRLang = cir::SourceLanguage;
926 if (opts.C99 || opts.C11 || opts.C17 || opts.C23 || opts.C2y ||
927 opts.LangStd == ClangStd::lang_c89 ||
928 opts.LangStd == ClangStd::lang_gnu89)
933 errorNYI(
"CIR does not yet support the given source language");
937LangAS CIRGenModule::getGlobalVarAddressSpace(
const VarDecl *d) {
938 if (langOpts.OpenCL) {
946 if (langOpts.SYCLIsDevice &&
948 errorNYI(
"SYCL global address space");
950 if (langOpts.CUDA && langOpts.CUDAIsDevice) {
952 if (d->
hasAttr<CUDAConstantAttr>())
954 if (d->
hasAttr<CUDASharedAttr>())
956 if (d->
hasAttr<CUDADeviceAttr>())
965 errorNYI(
"OpenMP global address space");
978 gv.
setLinkage(cir::GlobalLinkageKind::ExternalWeakLinkage);
987 auto linkage = cir::GlobalLinkageKind::ExternalWeakLinkage;
988 func.setLinkage(linkage);
992 if (!func.isDeclaration())
993 mlir::SymbolTable::setSymbolVisibility(
1000 for (mlir::Attribute i : indexes) {
1001 auto ind = mlir::cast<mlir::IntegerAttr>(i);
1002 inds.push_back(ind.getValue().getSExtValue());
1008 return view.getSymbol().getValue() == glob.getSymName();
1012 cir::GlobalOp newGlob,
1013 cir::GlobalViewAttr
attr,
1024 mlir::Type newTy = newGlob.getSymType();
1029 cir::PointerType newPtrTy;
1032 newPtrTy = cir::PointerType::get(newTy);
1041 cgm.
errorNYI(
"Unhandled type in createNewGlobalView");
1047 mlir::Attribute oldInit) {
1048 if (
auto oldView = mlir::dyn_cast<cir::GlobalViewAttr>(oldInit))
1051 auto getNewInitElements =
1052 [&](mlir::ArrayAttr oldElements) -> mlir::ArrayAttr {
1054 for (mlir::Attribute elt : oldElements) {
1055 if (
auto view = mlir::dyn_cast<cir::GlobalViewAttr>(elt))
1057 else if (mlir::isa<cir::ConstArrayAttr, cir::ConstRecordAttr>(elt))
1060 newElements.push_back(elt);
1062 return mlir::ArrayAttr::get(cgm.
getBuilder().getContext(), newElements);
1065 if (
auto oldArray = mlir::dyn_cast<cir::ConstArrayAttr>(oldInit)) {
1066 mlir::Attribute newElements =
1067 getNewInitElements(mlir::cast<mlir::ArrayAttr>(oldArray.getElts()));
1069 newElements, mlir::cast<cir::ArrayType>(oldArray.getType()));
1071 if (
auto oldRecord = mlir::dyn_cast<cir::ConstRecordAttr>(oldInit)) {
1072 mlir::ArrayAttr newMembers = getNewInitElements(oldRecord.getMembers());
1073 auto recordTy = mlir::cast<cir::RecordType>(oldRecord.getType());
1075 newMembers, recordTy.getPacked(), recordTy.getPadded(), recordTy);
1080 cgm.
errorNYI(
"Unhandled type in getNewInitValue");
1088 assert(oldGV.getSymName() == newGV.getSymName() &&
"symbol names must match");
1090 mlir::Type oldTy = oldGV.getSymType();
1091 mlir::Type newTy = newGV.getSymType();
1096 assert(oldTy != newTy &&
"expected type change in replaceGlobal");
1099 std::optional<mlir::SymbolTable::UseRange> oldSymUses =
1100 oldGV.getSymbolUses(theModule);
1101 for (mlir::SymbolTable::SymbolUse use : *oldSymUses) {
1102 mlir::Operation *userOp = use.getUser();
1104 (mlir::isa<cir::GetGlobalOp, cir::GlobalOp, cir::ConstantOp>(userOp)) &&
1105 "Unexpected user for global op");
1107 if (
auto getGlobalOp = dyn_cast<cir::GetGlobalOp>(use.getUser())) {
1108 mlir::Value useOpResultValue = getGlobalOp.getAddr();
1109 useOpResultValue.setType(cir::PointerType::get(newTy));
1111 mlir::OpBuilder::InsertionGuard guard(builder);
1112 builder.setInsertionPointAfter(getGlobalOp);
1113 mlir::Type ptrTy = builder.getPointerTo(oldTy);
1115 builder.createBitcast(getGlobalOp->getLoc(), useOpResultValue, ptrTy);
1116 useOpResultValue.replaceAllUsesExcept(
cast,
cast.getDefiningOp());
1117 }
else if (
auto glob = dyn_cast<cir::GlobalOp>(userOp)) {
1118 if (
auto init = glob.getInitialValue()) {
1119 mlir::Attribute nw =
getNewInitValue(*
this, newGV, oldTy, init.value());
1120 glob.setInitialValueAttr(nw);
1122 }
else if (
auto c = dyn_cast<cir::ConstantOp>(userOp)) {
1123 mlir::Attribute init =
getNewInitValue(*
this, newGV, oldTy, c.getValue());
1124 auto typedAttr = mlir::cast<mlir::TypedAttr>(init);
1125 mlir::OpBuilder::InsertionGuard guard(builder);
1126 builder.setInsertionPointAfter(c);
1127 auto newUser = cir::ConstantOp::create(builder, c.getLoc(), typedAttr);
1128 c.replaceAllUsesWith(newUser.getOperation());
1164 cir::GlobalOp entry;
1168 "getOrCreateCIRGlobal: global with non-GlobalOp type");
1173 mlir::ptr::MemorySpaceAttrInterface entryCIRAS = entry.getAddrSpaceAttr();
1179 if (entry.getSymType() == ty &&
1189 if (isForDefinition && !entry.isDeclaration()) {
1191 "getOrCreateCIRGlobal: global with conflicting type");
1199 if (!isForDefinition)
1208 bool isConstant =
false;
1213 astContext,
true, !needsDtor);
1216 mlir::ptr::MemorySpaceAttrInterface declCIRAS =
1221 cir::GlobalOp gv =
createGlobalOp(loc, mangledName, ty, isConstant, declCIRAS,
1222 entry.getOperation());
1242 if (langOpts.OpenMP && !langOpts.OpenMPSimd)
1244 "getOrCreateCIRGlobal: OpenMP target global variable");
1246 gv.setAlignmentAttr(
getSize(astContext.getDeclAlign(d)));
1257 if (astContext.isMSStaticDataMemberInlineDefinition(d))
1259 "getOrCreateCIRGlobal: MS static data member inline definition");
1263 if (
const SectionAttr *sa = d->
getAttr<SectionAttr>())
1264 gv.setSectionAttr(builder.getStringAttr(sa->getName()));
1268 if (
getTriple().getArch() == llvm::Triple::xcore)
1270 "getOrCreateCIRGlobal: XCore specific ABI requirements");
1280 "getOrCreateCIRGlobal: external const declaration with initializer");
1292 "getOrCreateCIRGlobal: HIP managed attribute");
1327 mlir::Type ptrTy = builder.getPointerTo(g.getSymType(), g.getAddrSpaceAttr());
1328 return cir::GetGlobalOp::create(
1331 g.getStaticLocalGuard().has_value());
1339 cir::PointerType ptrTy =
1340 builder.getPointerTo(globalOp.getSymType(), globalOp.getAddrSpaceAttr());
1341 return builder.getGlobalViewAttr(ptrTy, globalOp);
1345 assert((mlir::isa<cir::FuncOp>(gv.getOperation()) ||
1346 !gv.isDeclarationForLinker()) &&
1347 "Only globals with definition can force usage.");
1352 assert(!gv.isDeclarationForLinker() &&
1353 "Only globals with definition can force usage.");
1358 cir::CIRGlobalValueInterface gv) {
1359 assert((mlir::isa<cir::FuncOp>(gv.getOperation()) ||
1360 !gv.isDeclarationForLinker()) &&
1361 "Only globals with definition can force usage.");
1369 std::vector<cir::CIRGlobalValueInterface> &list) {
1374 mlir::Location loc = builder.getUnknownLoc();
1376 usedArray.resize(list.size());
1377 for (
auto [i, op] : llvm::enumerate(list)) {
1378 usedArray[i] = cir::GlobalViewAttr::get(
1379 cgm.
voidPtrTy, mlir::FlatSymbolRefAttr::get(op.getNameAttr()));
1382 cir::ArrayType arrayTy = cir::ArrayType::get(cgm.
voidPtrTy, usedArray.size());
1384 cir::ConstArrayAttr initAttr = cir::ConstArrayAttr::get(
1385 arrayTy, mlir::ArrayAttr::get(&cgm.
getMLIRContext(), usedArray));
1389 gv.setLinkage(cir::GlobalLinkageKind::AppendingLinkage);
1390 gv.setInitialValueAttr(initAttr);
1391 gv.setSectionAttr(builder.getStringAttr(
"llvm.metadata"));
1403 "emitGlobalVarDefinition: emit OpenCL/OpenMP global variable");
1410 bool isDefinitionAvailableExternally =
1415 if (isDefinitionAvailableExternally &&
1423 mlir::Attribute init;
1424 bool needsGlobalCtor =
false;
1425 bool needsGlobalDtor =
1426 !isDefinitionAvailableExternally &&
1431 std::optional<ConstantEmitter> emitter;
1436 bool isCUDASharedVar =
1441 bool isCUDAShadowVar =
1443 (vd->
hasAttr<CUDAConstantAttr>() || vd->
hasAttr<CUDADeviceAttr>() ||
1444 vd->
hasAttr<CUDASharedAttr>());
1445 bool isCUDADeviceShadowVar =
1451 (isCUDASharedVar || isCUDAShadowVar || isCUDADeviceShadowVar)) {
1453 }
else if (vd->
hasAttr<LoaderUninitializedAttr>()) {
1455 "emitGlobalVarDefinition: loader uninitialized attribute");
1456 }
else if (!initExpr) {
1469 emitter.emplace(*
this);
1470 mlir::Attribute initializer = emitter->tryEmitForInitializer(*initDecl);
1479 "emitGlobalVarDefinition: flexible array initializer");
1481 if (!isDefinitionAvailableExternally)
1482 needsGlobalCtor =
true;
1485 "emitGlobalVarDefinition: static initializer");
1496 mlir::Type initType;
1497 if (mlir::isa<mlir::SymbolRefAttr>(init)) {
1500 "emitGlobalVarDefinition: global initializer is a symbol reference");
1503 assert(mlir::isa<mlir::TypedAttr>(init) &&
"This should have a type");
1504 auto typedInitAttr = mlir::cast<mlir::TypedAttr>(init);
1505 initType = typedInitAttr.getType();
1507 assert(!mlir::isa<mlir::NoneType>(initType) &&
"Should have a type by now");
1513 if (!gv || gv.getSymType() != initType) {
1515 "emitGlobalVarDefinition: global initializer with type mismatch");
1521 if (vd->
hasAttr<AnnotateAttr>())
1534 if (langOpts.CUDA) {
1535 if (langOpts.CUDAIsDevice) {
1538 if (linkage != cir::GlobalLinkageKind::InternalLinkage &&
1540 (vd->
hasAttr<CUDADeviceAttr>() || vd->
hasAttr<CUDAConstantAttr>() ||
1543 gv->setAttr(cir::CUDAExternallyInitializedAttr::getMnemonic(),
1556 emitter->finalize(gv);
1560 gv.setConstant((vd->
hasAttr<CUDAConstantAttr>() && langOpts.CUDAIsDevice) ||
1561 (!needsGlobalCtor && !needsGlobalDtor &&
1566 if (
const SectionAttr *sa = vd->
getAttr<SectionAttr>()) {
1569 gv.setConstant(
true);
1573 gv.setLinkage(linkage);
1577 if (linkage == cir::GlobalLinkageKind::CommonLinkage) {
1579 gv.setConstant(
false);
1584 std::optional<mlir::Attribute> initializer = gv.getInitialValue();
1585 if (initializer && !
getBuilder().isNullValue(*initializer))
1586 gv.setLinkage(cir::GlobalLinkageKind::WeakAnyLinkage);
1589 setNonAliasAttributes(vd, gv);
1597 if (needsGlobalCtor || needsGlobalDtor)
1602 mlir::Operation *op) {
1604 if (
const auto *fd = dyn_cast<FunctionDecl>(
decl)) {
1608 if (
const auto *method = dyn_cast<CXXMethodDecl>(
decl)) {
1612 abi->emitCXXStructor(gd);
1613 else if (fd->isMultiVersion())
1614 errorNYI(method->getSourceRange(),
"multiversion functions");
1618 if (method->isVirtual())
1624 if (fd->isMultiVersion())
1625 errorNYI(fd->getSourceRange(),
"multiversion functions");
1630 if (
const auto *vd = dyn_cast<VarDecl>(
decl))
1633 llvm_unreachable(
"Invalid argument to CIRGenModule::emitGlobalDefinition");
1647 astContext.getAsConstantArrayType(e->
getType());
1648 uint64_t finalSize = cat->getZExtSize();
1649 str.resize(finalSize);
1651 mlir::Type eltTy =
convertType(cat->getElementType());
1652 return builder.getString(str, eltTy, finalSize,
false);
1657 auto arrayEltTy = mlir::cast<cir::IntType>(arrayTy.getElementType());
1659 uint64_t arraySize = arrayTy.getSize();
1661 assert(arraySize > literalSize &&
1662 "wide string literal array size must have room for null terminator?");
1666 bool isAllZero =
true;
1667 for (
unsigned i = 0; i < literalSize; ++i) {
1675 return cir::ZeroAttr::get(arrayTy);
1679 elements.reserve(arraySize);
1680 for (
unsigned i = 0; i < literalSize; ++i)
1681 elements.push_back(cir::IntAttr::get(arrayEltTy, e->
getCodeUnit(i)));
1683 auto elementsAttr = mlir::ArrayAttr::get(&
getMLIRContext(), elements);
1684 return builder.getConstArray(elementsAttr, arrayTy);
1695 if (d.
hasAttr<SelectAnyAttr>())
1699 if (
auto *vd = dyn_cast<VarDecl>(&d))
1714 llvm_unreachable(
"No such linkage");
1720 if (
auto globalOp = dyn_cast_or_null<cir::GlobalOp>(op)) {
1721 globalOp.setComdat(
true);
1724 funcOp.setComdat(
true);
1730 genTypes.updateCompletedType(td);
1734 replacements[name] = op;
1739 mlir::SymbolUserMap &userMap) {
1740 for (mlir::Operation *user : userMap.getUsers(oldF)) {
1741 auto call = mlir::dyn_cast<cir::CallOp>(user);
1745 for (
auto [argOp, fnArgType] :
1746 llvm::zip(call.getArgs(), newF.getFunctionType().getInputs())) {
1747 if (argOp.getType() != fnArgType)
1756void CIRGenModule::applyReplacements() {
1757 if (replacements.empty())
1763 mlir::SymbolTableCollection symbolTableCollection;
1764 mlir::SymbolUserMap userMap(symbolTableCollection, theModule);
1766 for (
auto &i : replacements) {
1767 StringRef mangledName = i.first;
1768 mlir::Operation *replacement = i.second;
1774 auto newF = dyn_cast<cir::FuncOp>(replacement);
1777 errorNYI(replacement->getLoc(),
"replacement is not a function");
1782 "call argument types do not match replacement function");
1786 userMap.replaceAllUsesWith(oldF, newF.getSymNameAttr());
1787 newF->moveBefore(oldF);
1794 mlir::Location loc, StringRef name, mlir::Type ty,
1796 auto gv = mlir::dyn_cast_or_null<cir::GlobalOp>(
getGlobalValue(name));
1800 if (gv.getSymType() == ty)
1806 assert(gv.isDeclaration() &&
"Declaration has wrong type!");
1808 errorNYI(loc,
"createOrReplaceCXXRuntimeVariable: declaration exists with "
1819 mlir::SymbolTable::setSymbolVisibility(gv,
1823 !gv.hasAvailableExternallyLinkage()) {
1827 gv.setAlignmentAttr(
getSize(alignment));
1838 if ((noCommon || vd->
hasAttr<NoCommonAttr>()) && !vd->
hasAttr<CommonAttr>())
1849 if (vd->
hasAttr<SectionAttr>())
1855 if (vd->
hasAttr<PragmaClangBSSSectionAttr>() ||
1856 vd->
hasAttr<PragmaClangDataSectionAttr>() ||
1857 vd->
hasAttr<PragmaClangRelroSectionAttr>() ||
1858 vd->
hasAttr<PragmaClangRodataSectionAttr>())
1866 if (vd->
hasAttr<WeakImportAttr>())
1876 if (vd->
hasAttr<AlignedAttr>())
1883 for (
const FieldDecl *fd : rd->fields()) {
1884 if (fd->isBitField())
1886 if (fd->hasAttr<AlignedAttr>())
1908cir::GlobalLinkageKind
1912 return cir::GlobalLinkageKind::InternalLinkage;
1915 return cir::GlobalLinkageKind::WeakAnyLinkage;
1919 return cir::GlobalLinkageKind::LinkOnceAnyLinkage;
1924 return cir::GlobalLinkageKind::AvailableExternallyLinkage;
1938 return !astContext.getLangOpts().AppleKext
1939 ? cir::GlobalLinkageKind::LinkOnceODRLinkage
1940 : cir::GlobalLinkageKind::InternalLinkage;
1954 return cir::GlobalLinkageKind::ExternalLinkage;
1957 return dd->
hasAttr<CUDAGlobalAttr>()
1958 ? cir::GlobalLinkageKind::ExternalLinkage
1959 : cir::GlobalLinkageKind::InternalLinkage;
1960 return cir::GlobalLinkageKind::WeakODRLinkage;
1968 return cir::GlobalLinkageKind::CommonLinkage;
1974 if (dd->
hasAttr<SelectAnyAttr>())
1975 return cir::GlobalLinkageKind::WeakODRLinkage;
1979 return cir::GlobalLinkageKind::ExternalLinkage;
1991 mlir::Operation *old, cir::FuncOp newFn) {
1993 auto oldFn = mlir::dyn_cast<cir::FuncOp>(old);
2001 if (oldFn->getAttrs().size() <= 1)
2003 "replaceUsesOfNonProtoTypeWithRealFunction: Attribute forwarding");
2006 newFn.setNoProto(oldFn.getNoProto());
2009 std::optional<mlir::SymbolTable::UseRange> symUses =
2010 oldFn.getSymbolUses(oldFn->getParentOp());
2011 for (
const mlir::SymbolTable::SymbolUse &use : symUses.value()) {
2012 mlir::OpBuilder::InsertionGuard guard(builder);
2014 if (
auto noProtoCallOp = mlir::dyn_cast<cir::CallOp>(use.getUser())) {
2015 builder.setInsertionPoint(noProtoCallOp);
2018 cir::FuncType newFnType = newFn.getFunctionType();
2019 mlir::OperandRange callOperands = noProtoCallOp.getOperands();
2020 bool returnTypeMatches =
2021 newFnType.hasVoidReturn()
2022 ? noProtoCallOp.getNumResults() == 0
2023 : noProtoCallOp.getNumResults() == 1 &&
2024 noProtoCallOp.getResultTypes().front() ==
2025 newFnType.getReturnType();
2026 bool typesMatch = !newFn.getNoProto() && returnTypeMatches &&
2027 callOperands.size() == newFnType.getNumInputs();
2028 for (
unsigned i = 0, e = newFnType.getNumInputs(); typesMatch && i != e;
2030 if (callOperands[i].
getType() != newFnType.getInput(i))
2034 cir::CallOp realCallOp;
2038 builder.createCallOp(noProtoCallOp.getLoc(), newFn, callOperands);
2042 cir::FuncType origFnType = oldFn.getFunctionType();
2043 cir::FuncType callFnType =
2044 origFnType.isVarArg()
2045 ? cir::FuncType::get(origFnType.getInputs(),
2046 origFnType.getReturnType(),
2049 mlir::Value addr = cir::GetGlobalOp::create(
2050 builder, noProtoCallOp.getLoc(), cir::PointerType::get(newFnType),
2051 newFn.getSymName());
2052 mlir::Value casted =
2053 builder.createBitcast(addr, cir::PointerType::get(callFnType));
2054 realCallOp = builder.createIndirectCallOp(
2055 noProtoCallOp.getLoc(), casted, callFnType, callOperands);
2059 noProtoCallOp.replaceAllUsesWith(realCallOp);
2060 noProtoCallOp.erase();
2061 }
else if (
auto getGlobalOp =
2062 mlir::dyn_cast<cir::GetGlobalOp>(use.getUser())) {
2069 mlir::Value res = getGlobalOp.getAddr();
2070 const mlir::Type oldResTy = res.getType();
2071 const auto newPtrTy = cir::PointerType::get(newFn.getFunctionType());
2072 if (oldResTy != newPtrTy) {
2073 res.setType(newPtrTy);
2074 builder.setInsertionPointAfter(getGlobalOp.getOperation());
2075 mlir::Value castRes =
2076 cir::CastOp::create(builder, getGlobalOp.getLoc(), oldResTy,
2077 cir::CastKind::bitcast, res);
2078 res.replaceAllUsesExcept(castRes, castRes.getDefiningOp());
2080 }
else if (mlir::isa<cir::GlobalOp>(use.getUser())) {
2086 "replaceUsesOfNonProtoTypeWithRealFunction: unexpected use type");
2091cir::GlobalLinkageKind
2093 GVALinkage linkage = astContext.GetGVALinkageForVariable(vd);
2100 GVALinkage linkage = astContext.GetGVALinkageForFunction(d);
2102 if (
const auto *dtor = dyn_cast<CXXDestructorDecl>(d))
2111 StringRef globalName,
CharUnits alignment) {
2116 cir::GlobalOp gv = cgm.
createGlobalOp(loc, globalName, c.getType(),
2120 gv.setAlignmentAttr(cgm.
getSize(alignment));
2122 cir::GlobalLinkageKindAttr::get(cgm.
getBuilder().getContext(), lt));
2126 if (gv.isWeakForLinker()) {
2127 assert(cgm.
supportsCOMDAT() &&
"Only COFF uses weak string literals");
2130 cgm.
setDSOLocal(
static_cast<mlir::Operation *
>(gv));
2151 std::string result =
2162 astContext.getAlignOfGlobalVarInChars(s->
getType(),
nullptr);
2170 if (!gv.getAlignment() ||
2171 uint64_t(alignment.
getQuantity()) > *gv.getAlignment())
2172 gv.setAlignmentAttr(
getSize(alignment));
2177 if (
getCXXABI().getMangleContext().shouldMangleStringLiteral(s) &&
2180 "getGlobalForStringLiteral: mangle string literals");
2190 : builder.getUnknownLoc();
2191 auto typedC = llvm::cast<mlir::TypedAttr>(c);
2193 cir::GlobalLinkageKind::PrivateLinkage, *
this,
2194 uniqueName, alignment);
2208 auto arrayTy = mlir::dyn_cast<cir::ArrayType>(gv.getSymType());
2209 assert(arrayTy &&
"String literal must be array");
2213 return builder.getGlobalViewAttr(ptrTy, gv);
2230 errorNYI(
"SYCL temp address space");
2241 "emitExplicitCastExprType");
2247 auto ty = mlir::cast<cir::MethodType>(
convertType(destTy));
2248 return builder.getNullMethodAttr(ty);
2251 auto ty = mlir::cast<cir::DataMemberType>(
convertType(destTy));
2252 return builder.getNullDataMemberAttr(ty);
2263 if (
const auto *methodDecl = dyn_cast<CXXMethodDecl>(
decl)) {
2265 if (methodDecl->isVirtual())
2266 return cir::ConstantOp::create(
2267 builder, loc,
getCXXABI().buildVirtualMethodAttr(ty, methodDecl));
2273 return cir::ConstantOp::create(builder, loc,
2274 builder.getMethodAttr(ty, methodFuncOp));
2280 return cir::ConstantOp::create(
2281 builder, loc, builder.getDataMemberAttr(ty,
fieldDecl->getFieldIndex()));
2291 if (
auto *oid = dyn_cast<ObjCImplDecl>(
decl))
2292 errorNYI(oid->getSourceRange(),
"emitDeclConext: ObjCImplDecl");
2302 if (
decl->isTemplated())
2305 switch (
decl->getKind()) {
2308 decl->getDeclKindName());
2311 case Decl::CXXConversion:
2312 case Decl::CXXMethod:
2313 case Decl::Function: {
2316 if (!fd->isConsteval())
2325 case Decl::Decomposition:
2326 case Decl::VarTemplateSpecialization: {
2328 if (
auto *decomp = dyn_cast<DecompositionDecl>(
decl))
2329 for (
auto *binding : decomp->flat_bindings())
2330 if (
auto *holdingVar = binding->getHoldingVar())
2334 case Decl::OpenACCRoutine:
2337 case Decl::OpenACCDeclare:
2340 case Decl::OMPThreadPrivate:
2343 case Decl::OMPGroupPrivate:
2346 case Decl::OMPAllocate:
2349 case Decl::OMPCapturedExpr:
2352 case Decl::OMPDeclareReduction:
2355 case Decl::OMPDeclareMapper:
2358 case Decl::OMPRequires:
2363 case Decl::UsingDirective:
2364 case Decl::UsingEnum:
2365 case Decl::NamespaceAlias:
2367 case Decl::TypeAlias:
2373 case Decl::ClassTemplate:
2375 case Decl::CXXDeductionGuide:
2377 case Decl::ExplicitInstantiation:
2378 case Decl::FunctionTemplate:
2379 case Decl::StaticAssert:
2380 case Decl::TypeAliasTemplate:
2381 case Decl::UsingShadow:
2382 case Decl::VarTemplate:
2383 case Decl::VarTemplatePartialSpecialization:
2386 case Decl::CXXConstructor:
2389 case Decl::CXXDestructor:
2394 case Decl::LinkageSpec:
2395 case Decl::Namespace:
2399 case Decl::ClassTemplateSpecialization:
2400 case Decl::CXXRecord: {
2403 for (
auto *childDecl : crd->
decls())
2409 case Decl::FileScopeAsm:
2411 if (langOpts.CUDA && langOpts.CUDAIsDevice)
2414 if (langOpts.OpenMPIsTargetDevice)
2417 if (langOpts.SYCLIsDevice)
2420 std::string line = file_asm->getAsmString();
2421 globalScopeAsm.push_back(builder.getStringAttr(line));
2428 op.setInitialValueAttr(value);
2442 md->getParent()->getNumVBases() == 0)
2444 "getAddrAndTypeOfCXXStructor: MS ABI complete destructor");
2455 false, isForDefinition);
2457 return {fnType, fn};
2461 mlir::Type funcType,
bool forVTable,
2465 "consteval function should never be emitted");
2475 if (
const auto *dd = dyn_cast<CXXDestructorDecl>(gd.
getDecl())) {
2478 dd->getParent()->getNumVBases() == 0)
2480 "getAddrOfFunction: MS ABI complete destructor");
2486 false, isForDefinition);
2488 if (langOpts.CUDA && !langOpts.CUDAIsDevice &&
2494 bool isHIPHandle = mlir::isa<cir::GlobalOp>(*handle);
2495 if (isForDefinition || isHIPHandle)
2497 return mlir::dyn_cast<cir::FuncOp>(*handle);
2506 llvm::raw_svector_ostream
out(buffer);
2515 assert(ii &&
"Attempt to mangle unnamed decl.");
2517 const auto *fd = dyn_cast<FunctionDecl>(nd);
2521 }
else if (fd && fd->hasAttr<CUDAGlobalAttr>() &&
2525 DeviceKernelAttr::isOpenCLSpelling(
2526 fd->getAttr<DeviceKernelAttr>()) &&
2543 if (
const auto *fd = dyn_cast<FunctionDecl>(nd)) {
2544 if (fd->isMultiVersion()) {
2546 "getMangledName: multi-version functions");
2551 "getMangledName: GPU relocatable device code");
2554 return std::string(
out.str());
2557static FunctionDecl *
2572 if (
auto *methodDecl = dyn_cast<CXXMethodDecl>(protoFunc);
2573 methodDecl && methodDecl->isImplicitObjectMemberFunction()) {
2575 paramTypes.insert(paramTypes.begin(), methodDecl->getThisType());
2578 fpt->getExtProtoInfo());
2589 params.reserve(fpt->getNumParams());
2592 for (
unsigned i = 0, e = fpt->getNumParams(); i != e; ++i) {
2596 nullptr, fpt->getParamType(i),
nullptr,
2599 params.push_back(parm);
2602 tempFunc->setParams(params);
2627 if (
const auto *cd = dyn_cast<CXXConstructorDecl>(canonicalGd.
getDecl())) {
2630 "getMangledName: C++ constructor without variants");
2639 auto result = manglings.insert(std::make_pair(mangledName, gd));
2640 return mangledDeclNames[canonicalGd] = result.first->first();
2644 assert(!d->
getInit() &&
"Cannot emit definite definitions here!");
2652 if (gv && !mlir::cast<cir::GlobalOp>(gv).isDeclaration())
2668 if (langOpts.EmitAllDecls)
2671 const auto *vd = dyn_cast<VarDecl>(global);
2673 ((codeGenOpts.KeepPersistentStorageVariables &&
2674 (vd->getStorageDuration() ==
SD_Static ||
2675 vd->getStorageDuration() ==
SD_Thread)) ||
2676 (codeGenOpts.KeepStaticConsts && vd->getStorageDuration() ==
SD_Static &&
2677 vd->getType().isConstQualified())))
2690 if (langOpts.OpenMP >= 50 && !langOpts.OpenMPSimd) {
2691 std::optional<OMPDeclareTargetDeclAttr *> activeAttr =
2692 OMPDeclareTargetDeclAttr::getActiveAttr(global);
2693 if (!activeAttr || (*activeAttr)->getLevel() != (
unsigned)-1)
2697 const auto *fd = dyn_cast<FunctionDecl>(global);
2704 if (fd->hasAttr<TargetVersionAttr>() && !fd->isMultiVersion())
2706 if (langOpts.SYCLIsDevice) {
2707 errorNYI(fd->getSourceRange(),
"mayBeEmittedEagerly: SYCL");
2711 const auto *vd = dyn_cast<VarDecl>(global);
2713 if (astContext.getInlineVariableDefinitionKind(vd) ==
2721 if (langOpts.OpenMP && langOpts.OpenMPUseTLS &&
2722 astContext.getTargetInfo().isTLSSupported() &&
isa<VarDecl>(global) &&
2724 !OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(global))
2727 assert((fd || vd) &&
2728 "Only FunctionDecl and VarDecl should hit this path so far.");
2733 cir::CIRGlobalValueInterface gv) {
2734 if (gv.hasLocalLinkage())
2737 if (!gv.hasDefaultVisibility() && !gv.hasExternalWeakLinkage())
2745 const llvm::Triple &tt = cgm.
getTriple();
2747 if (tt.isOSCygMing()) {
2756 cgm.
errorNYI(
"shouldAssumeDSOLocal: MinGW");
2762 if (tt.isOSBinFormatCOFF() && gv.hasExternalWeakLinkage())
2770 if (tt.isOSBinFormatCOFF() || (tt.isOSWindows() && tt.isOSBinFormatMachO()))
2774 if (!tt.isOSBinFormatELF())
2779 if (rm != llvm::Reloc::Static && !lOpts.PIE) {
2787 return !(lOpts.SemanticInterposition || lOpts.HalfNoSemanticInterposition);
2791 if (!gv.isDeclarationForLinker())
2797 if (rm == llvm::Reloc::PIC_ && gv.hasExternalWeakLinkage())
2804 if (cgOpts.DirectAccessExternalData) {
2810 if (
auto globalOp = dyn_cast<cir::GlobalOp>(gv.getOperation())) {
2836 if (gv.hasLocalLinkage()) {
2837 gv.setGlobalVisibility(cir::VisibilityKind::Default);
2852 d->
hasAttr<OMPDeclareTargetDeclAttr>() &&
2853 d->
getAttr<OMPDeclareTargetDeclAttr>()->getDevType() !=
2854 OMPDeclareTargetDeclAttr::DT_NoHost &&
2856 llvm_unreachable(
"setGlobalVisibility: OpenMP is NYI");
2865 !d->
hasAttr<OMPDeclareTargetDeclAttr>()) {
2866 bool needsProtected =
false;
2870 }
else if (
const auto *vd = dyn_cast<VarDecl>(d)) {
2871 needsProtected = vd->hasAttr<CUDADeviceAttr>() ||
2872 vd->hasAttr<CUDAConstantAttr>() ||
2873 vd->getType()->isCUDADeviceBuiltinSurfaceType() ||
2874 vd->getType()->isCUDADeviceBuiltinTextureType();
2876 if (needsProtected) {
2877 gv.setGlobalVisibility(cir::VisibilityKind::Protected);
2883 gv.setGlobalVisibility(cir::VisibilityKind::Hidden);
2890 !gv.isDeclarationForLinker())
2899 if (
auto globalValue = dyn_cast<cir::CIRGlobalValueInterface>(op))
2918 auto res = manglings.find(mangledName);
2919 if (res == manglings.end())
2921 result = res->getValue();
2928 return cir::TLS_Model::GeneralDynamic;
2930 return cir::TLS_Model::LocalDynamic;
2932 return cir::TLS_Model::InitialExec;
2934 return cir::TLS_Model::LocalExec;
2936 llvm_unreachable(
"Invalid TLS model!");
2940 bool isExtendingDecl) {
2941 assert(d.
getTLSKind() &&
"setting TLS mode on non-TLS var!");
2946 if (d.
getAttr<TLSModelAttr>())
2950 global.setTlsModel(tlm);
2954 if (d.
isStaticLocal() || tlm != cir::TLS_Model::GeneralDynamic)
2960 if (isExtendingDecl)
2968 cir::FuncOp func,
bool isThunk) {
2970 cir::CallingConv callingConv;
2971 cir::SideEffect sideEffect;
2978 mlir::NamedAttrList pal{};
2979 std::vector<mlir::NamedAttrList> argAttrs(info.
arguments().size());
2980 mlir::NamedAttrList retAttrs{};
2982 retAttrs, callingConv, sideEffect,
2985 for (mlir::NamedAttribute
attr : pal)
2986 func->setAttr(
attr.getName(),
attr.getValue());
2988 llvm::for_each(llvm::enumerate(argAttrs), [func](
auto idx_arg_pair) {
2989 mlir::function_interface_impl::setArgAttrs(func, idx_arg_pair.index(),
2990 idx_arg_pair.value());
2992 if (!retAttrs.empty())
2993 mlir::function_interface_impl::setResultAttrs(func, 0, retAttrs);
3006 bool isIncompleteFunction,
3014 if (!isIncompleteFunction)
3016 getTypes().arrangeGlobalDeclaration(globalDecl),
3019 if (!isIncompleteFunction && func.isDeclaration())
3026 if (funcDecl->isInlineBuiltinDeclaration()) {
3028 bool hasBody = funcDecl->
hasBody(fdBody);
3030 assert(hasBody &&
"Inline builtin declarations should always have an "
3035 if (funcDecl->isReplaceableGlobalAllocationFunction()) {
3038 func->setAttr(cir::CIRDialect::getNoBuiltinAttrName(),
3050 if (!langOpts.Exceptions)
3053 if (langOpts.CXXExceptions)
3056 if (langOpts.ObjCExceptions)
3067 f->setAttr(cir::CIRDialect::getNoThrowAttrName(),
3070 std::optional<cir::InlineKind> existingInlineKind = f.getInlineKind();
3072 existingInlineKind && *existingInlineKind == cir::InlineKind::NoInline;
3073 bool isAlwaysInline = existingInlineKind &&
3074 *existingInlineKind == cir::InlineKind::AlwaysInline;
3078 if (!isAlwaysInline &&
3083 f.setInlineKind(cir::InlineKind::NoInline);
3098 if (
decl->hasAttr<NoInlineAttr>() && !isAlwaysInline) {
3100 f.setInlineKind(cir::InlineKind::NoInline);
3101 }
else if (
decl->hasAttr<AlwaysInlineAttr>() && !isNoInline) {
3104 f.setInlineKind(cir::InlineKind::AlwaysInline);
3108 if (!isAlwaysInline)
3109 f.setInlineKind(cir::InlineKind::NoInline);
3114 if (
auto *fd = dyn_cast<FunctionDecl>(
decl)) {
3119 auto checkRedeclForInline = [](
const FunctionDecl *redecl) {
3120 return redecl->isInlineSpecified();
3122 if (any_of(
decl->redecls(), checkRedeclForInline))
3127 return any_of(pattern->
redecls(), checkRedeclForInline);
3129 if (checkForInline(fd)) {
3130 f.setInlineKind(cir::InlineKind::InlineHint);
3131 }
else if (codeGenOpts.getInlining() ==
3133 !fd->isInlined() && !isAlwaysInline) {
3134 f.setInlineKind(cir::InlineKind::NoInline);
3143 StringRef mangledName, mlir::Type funcType,
GlobalDecl gd,
bool forVTable,
3145 mlir::NamedAttrList extraAttrs) {
3148 if (
const auto *fd = cast_or_null<FunctionDecl>(d)) {
3150 if (
getLangOpts().OpenMPIsTargetDevice && openMPRuntime &&
3152 !dontDefer && !isForDefinition) {
3155 if (
const auto *cd = dyn_cast<CXXConstructorDecl>(fdDef))
3157 else if (
const auto *dd = dyn_cast<CXXDestructorDecl>(fdDef))
3167 if (fd->isMultiVersion())
3168 errorNYI(fd->getSourceRange(),
"getOrCreateCIRFunction: multi-version");
3174 assert(mlir::isa<cir::FuncOp>(entry));
3179 if (d && !d->
hasAttr<DLLImportAttr>() && !d->
hasAttr<DLLExportAttr>()) {
3187 if (isForDefinition && fn && !fn.isDeclaration()) {
3194 diagnosedConflictingDefinitions.insert(gd).second) {
3198 diag::note_previous_definition);
3202 if (fn && fn.getFunctionType() == funcType) {
3206 if (!isForDefinition) {
3214 auto *funcDecl = llvm::cast_or_null<FunctionDecl>(gd.
getDecl());
3215 bool invalidLoc = !funcDecl ||
3216 funcDecl->getSourceRange().getBegin().isInvalid() ||
3217 funcDecl->getSourceRange().getEnd().isInvalid();
3219 invalidLoc ? theModule->getLoc() :
getLoc(funcDecl->getSourceRange()),
3220 mangledName, mlir::cast<cir::FuncType>(funcType), funcDecl);
3222 if (funcDecl && funcDecl->hasAttr<AnnotateAttr>())
3223 deferredAnnotations[mangledName] = funcDecl;
3234 auto symbolOp = mlir::cast<mlir::SymbolOpInterface>(entry);
3242 if (symbolOp.getSymbolUses(symbolOp->getParentOp()))
3252 if (!extraAttrs.empty()) {
3253 extraAttrs.append(funcOp->getAttrs());
3254 funcOp->setAttrs(extraAttrs);
3261 assert(funcOp.getFunctionType() == funcType);
3268 if (isa_and_nonnull<CXXDestructorDecl>(d) &&
3298 fd = fd->getPreviousDecl()) {
3300 if (fd->doesThisDeclarationHaveABody()) {
3313 cir::FuncType funcType,
3317 mlir::OpBuilder::InsertionGuard guard(builder);
3325 builder.setInsertionPoint(cgf->
curFn);
3327 func = cir::FuncOp::create(builder, loc, name, funcType);
3334 func.setNoProto(
true);
3336 assert(func.isDeclaration() &&
"expected empty body");
3340 func.setLinkageAttr(cir::GlobalLinkageKindAttr::get(
3342 mlir::SymbolTable::setSymbolVisibility(
3343 func, mlir::SymbolTable::Visibility::Private);
3351 theModule.push_back(func);
3356 for (
const auto *
attr :
3370 fnOp.setBuiltin(
true);
3376 return cir::CtorKind::Default;
3378 return cir::CtorKind::Copy;
3380 return cir::CtorKind::Move;
3381 return cir::CtorKind::Custom;
3386 return cir::AssignKind::Copy;
3388 return cir::AssignKind::Move;
3389 llvm_unreachable(
"not a copy or move assignment operator");
3397 if (
const auto *dtor = dyn_cast<CXXDestructorDecl>(funcDecl)) {
3398 auto cxxDtor = cir::CXXDtorAttr::get(
3401 funcOp.setCxxSpecialMemberAttr(cxxDtor);
3405 if (
const auto *ctor = dyn_cast<CXXConstructorDecl>(funcDecl)) {
3407 auto cxxCtor = cir::CXXCtorAttr::get(
3409 kind, ctor->isTrivial());
3410 funcOp.setCxxSpecialMemberAttr(cxxCtor);
3414 const auto *method = dyn_cast<CXXMethodDecl>(funcDecl);
3415 if (method && (method->isCopyAssignmentOperator() ||
3416 method->isMoveAssignmentOperator())) {
3418 auto cxxAssign = cir::CXXAssignAttr::get(
3420 assignKind, method->isTrivial());
3421 funcOp.setCxxSpecialMemberAttr(cxxAssign);
3427 cir::FuncOp funcOp, StringRef name) {
3443 mlir::NamedAttrList extraAttrs,
3445 bool assumeConvergent) {
3446 if (assumeConvergent)
3447 errorNYI(
"createRuntimeFunction: assumeConvergent");
3457 entry.setDSOLocal(
true);
3463mlir::SymbolTable::Visibility
3467 if (op.isDeclaration())
3468 return mlir::SymbolTable::Visibility::Private;
3472mlir::SymbolTable::Visibility
3475 case cir::GlobalLinkageKind::InternalLinkage:
3476 case cir::GlobalLinkageKind::PrivateLinkage:
3477 return mlir::SymbolTable::Visibility::Private;
3478 case cir::GlobalLinkageKind::ExternalLinkage:
3479 case cir::GlobalLinkageKind::ExternalWeakLinkage:
3480 case cir::GlobalLinkageKind::LinkOnceODRLinkage:
3481 case cir::GlobalLinkageKind::AvailableExternallyLinkage:
3482 case cir::GlobalLinkageKind::CommonLinkage:
3483 case cir::GlobalLinkageKind::WeakAnyLinkage:
3484 case cir::GlobalLinkageKind::WeakODRLinkage:
3485 return mlir::SymbolTable::Visibility::Public;
3487 llvm::errs() <<
"visibility not implemented for '"
3488 << stringifyGlobalLinkageKind(glk) <<
"'\n";
3489 assert(0 &&
"not implemented");
3492 llvm_unreachable(
"linkage should be handled above!");
3496 clang::VisibilityAttr::VisibilityType visibility) {
3497 switch (visibility) {
3498 case clang::VisibilityAttr::VisibilityType::Default:
3499 return cir::VisibilityKind::Default;
3500 case clang::VisibilityAttr::VisibilityType::Hidden:
3501 return cir::VisibilityKind::Hidden;
3502 case clang::VisibilityAttr::VisibilityType::Protected:
3503 return cir::VisibilityKind::Protected;
3505 llvm_unreachable(
"unexpected visibility value");
3510 const clang::VisibilityAttr *va =
decl->getAttr<clang::VisibilityAttr>();
3511 cir::VisibilityAttr cirVisibility =
3514 cirVisibility = cir::VisibilityAttr::get(
3518 return cirVisibility;
3524 applyReplacements();
3526 theModule->setAttr(cir::CIRDialect::getModuleLevelAsmAttrName(),
3527 builder.getArrayAttr(globalScopeAsm));
3529 emitGlobalAnnotations();
3531 if (!recordLayoutEntries.empty())
3533 cir::CIRDialect::getRecordLayoutsAttrName(),
3534 mlir::DictionaryAttr::get(&
getMLIRContext(), recordLayoutEntries));
3543 std::string cuidName =
3546 auto loc = builder.getUnknownLoc();
3547 mlir::ptr::MemorySpaceAttrInterface addrSpace =
3549 getGlobalVarAddressSpace(
nullptr));
3553 gv.setLinkage(cir::GlobalLinkageKind::ExternalLinkage);
3555 auto zeroAttr = cir::IntAttr::get(int8Ty, 0);
3556 gv.setInitialValueAttr(zeroAttr);
3558 mlir::SymbolTable::setSymbolVisibility(
3559 gv, mlir::SymbolTable::Visibility::Public);
3564 if (astContext.getLangOpts().CUDA && cudaRuntime)
3579 const AliasAttr *aa = d->
getAttr<AliasAttr>();
3580 assert(aa &&
"Not an alias?");
3584 if (aa->getAliasee() == mangledName) {
3585 diags.Report(aa->getLocation(), diag::err_cyclic_alias) << 0;
3593 auto entryGV = mlir::dyn_cast<cir::CIRGlobalValueInterface>(entry);
3594 if (entryGV && entryGV.isDefinition())
3607 cir::GlobalLinkageKind linkage;
3620 linkage = cir::GlobalLinkageKind::WeakAnyLinkage;
3632 mlir::SymbolTable::Visibility visibility =
3636 cir::CIRGlobalValueInterface alias =
3637 isFunction ? mlir::cast<cir::CIRGlobalValueInterface>(
3639 mlir::cast<cir::FuncType>(declTy),
3642 : mlir::cast<cir::CIRGlobalValueInterface>(
3644 alias.setAliasee(aa->getAliasee());
3645 alias.setLinkage(linkage);
3646 mlir::SymbolTable::setSymbolVisibility(alias, visibility);
3654 cir::FuncOp aliasee,
3655 cir::GlobalLinkageKind linkage) {
3657 auto *aliasFD = dyn_cast<FunctionDecl>(aliasGD.
getDecl());
3658 assert(aliasFD &&
"expected FunctionDecl");
3669 mangledName, fnType, aliasFD);
3670 alias.setAliasee(aliasee.getName());
3671 alias.setLinkage(linkage);
3675 mlir::SymbolTable::setSymbolVisibility(
3676 alias, mlir::SymbolTable::Visibility::Private);
3688 "declaration exists with different type");
3700 return genTypes.convertType(
type);
3707 return mlir::verify(theModule).succeeded();
3716 return builder.getConstNullPtrAttr(builder.getUInt8PtrTy());
3719 langOpts.ObjCRuntime.isGNUFamily()) {
3720 errorNYI(loc,
"getAddrOfRTTIDescriptor: Objc PtrType & Objc RT GUN");
3730 llvm::iterator_range<CastExpr::path_const_iterator> path) {
3737 assert(!base->isVirtual() &&
"Should not see virtual bases here!");
3742 const auto *baseDecl = base->getType()->castAsCXXRecordDecl();
3754 llvm::StringRef feature) {
3755 unsigned diagID = diags.getCustomDiagID(
3757 return diags.Report(loc, diagID) << feature;
3761 llvm::StringRef feature) {
3773 "cannot compile this %0 yet");
3774 diags.Report(astContext.getFullLoc(s->
getBeginLoc()), diagId)
3781 "cannot compile this %0 yet");
3782 diags.Report(astContext.getFullLoc(d->
getLocation()), diagId) <<
type;
3786 cir::LabelOp label) {
3787 [[maybe_unused]]
auto result =
3789 assert(result.second &&
3790 "attempting to map a blockaddress info that is already mapped");
3795 assert(result.second &&
3796 "attempting to map a blockaddress operation that is already mapped");
3800 cir::LabelOp label) {
3802 assert(result.second &&
3803 "attempting to map a blockaddress operation that is already mapped");
3807 cir::LabelOp newLabel) {
3810 "trying to update a blockaddress not previously mapped");
3811 assert(!it->second &&
"blockaddress already has a resolved label");
3813 it->second = newLabel;
3826 "not a global temporary");
3838 materializedType = mte->
getType();
3847 llvm::raw_svector_ostream
out(name);
3851 auto insertResult = materializedGlobalTemporaryMap.insert({mte,
nullptr});
3852 if (!insertResult.second) {
3856 if (!insertResult.first->second) {
3859 insertResult.first->second =
3862 return insertResult.first->second;
3879 value = &evalResult.
Val;
3883 std::optional<ConstantEmitter> emitter;
3884 mlir::Attribute initialValue =
nullptr;
3885 bool isConstant =
false;
3889 emitter.emplace(*
this);
3890 initialValue = emitter->emitForInitializer(*value, materializedType);
3895 type = mlir::cast<mlir::TypedAttr>(initialValue).getType();
3904 if (linkage == cir::GlobalLinkageKind::ExternalLinkage) {
3906 if (
varDecl->isStaticDataMember() &&
varDecl->getAnyInitializer(initVD) &&
3914 linkage = cir::GlobalLinkageKind::InternalLinkage;
3918 gv.setInitialValueAttr(initialValue);
3919 gv.setLinkage(linkage);
3923 emitter->finalize(gv);
3925 if (!gv.hasLocalLinkage()) {
3930 gv.setAlignment(align.getAsAlign().value());
3933 "Global temporary with comdat/weak linkage");
3936 mlir::Operation *cv = gv;
3945 mlir::Operation *&entry = materializedGlobalTemporaryMap[mte];
3947 entry->replaceAllUsesWith(cv);
3962 return *globalOpEntry;
3969 "emitForInitializer should take gcd->getType().getAddressSpace()");
3971 auto typedInit = dyn_cast<mlir::TypedAttr>(init);
3975 "getAddrOfUnnamedGlobalConstantDecl: non-typed initializer");
3984 std::string name = numEntries == 0
3986 : (Twine(
".constant.") + Twine(numEntries)).str();
3988 typedInit.getType(),
true);
3989 globalOp.setLinkage(cir::GlobalLinkageKind::PrivateLinkage);
3992 globalOp.setAlignment(alignment.
getAsAlign().value());
3996 *globalOpEntry = globalOp;
4011 "emitForInitializer should take tpo->getType().getAddressSpace()");
4012 mlir::Attribute init =
4022 cir::GlobalLinkageKind linkage =
4024 ? cir::GlobalLinkageKind::LinkOnceODRLinkage
4025 : cir::GlobalLinkageKind::InternalLinkage;
4029 typedInit.getType(),
true);
4030 globalOp.setLinkage(linkage);
4031 globalOp.setAlignment(alignment.
getAsAlign().value());
4033 linkage == cir::GlobalLinkageKind::LinkOnceODRLinkage);
4048CIRGenModule::getOrCreateAnnotationArgs(
const AnnotateAttr *
attr) {
4055 llvm::FoldingSetNodeID id;
4056 for (
Expr *e : exprs)
4059 mlir::ArrayAttr &lookup = annotationArgs[
id.ComputeHash()];
4064 args.reserve(exprs.size());
4065 for (
Expr *e : exprs) {
4066 if (
auto *strE = dyn_cast<clang::StringLiteral>(e->IgnoreParenCasts())) {
4067 args.push_back(builder.getStringAttr(strE->getString()));
4068 }
else if (
auto *intE =
4069 dyn_cast<clang::IntegerLiteral>(e->IgnoreParenCasts())) {
4070 auto intTy = builder.getIntegerType(intE->getValue().getBitWidth());
4071 args.push_back(builder.getIntegerAttr(intTy, intE->getValue()));
4073 errorNYI(e->getExprLoc(),
"annotation argument expression");
4077 return lookup = builder.getArrayAttr(args);
4080cir::AnnotationAttr CIRGenModule::emitAnnotateAttr(
const AnnotateAttr *aa) {
4081 mlir::StringAttr annoGV = builder.getStringAttr(aa->getAnnotation());
4082 mlir::ArrayAttr args = getOrCreateAnnotationArgs(aa);
4083 return cir::AnnotationAttr::get(&
getMLIRContext(), annoGV, args);
4087 mlir::Operation *gv) {
4088 assert(d->
hasAttr<AnnotateAttr>() &&
"no annotate attribute");
4090 "annotation only on globals");
4093 annotations.push_back(emitAnnotateAttr(i));
4094 if (
auto global = dyn_cast<cir::GlobalOp>(gv))
4095 global.setAnnotationsAttr(builder.getArrayAttr(annotations));
4096 else if (
auto func = dyn_cast<cir::FuncOp>(gv))
4097 func.setAnnotationsAttr(builder.getArrayAttr(annotations));
4100void CIRGenModule::emitGlobalAnnotations() {
4101 for (
const auto &[mangledName, vd] : deferredAnnotations) {
4106 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 shouldBeInCOMDAT(CIRGenModule &cgm, const Decl &d)
static mlir::Attribute getNewInitValue(CIRGenModule &cgm, cir::GlobalOp newGlob, mlir::Type oldTy, mlir::Attribute oldInit)
static bool hasUnwindExceptions(const LangOptions &langOpts)
Determines whether the language options require us to model unwind exceptions.
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 bool hasImplicitAttr(const ValueDecl *decl)
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 bool isVarDeclStrongDefinition(const ASTContext &astContext, CIRGenModule &cgm, const VarDecl *vd, bool noCommon)
static void setLinkageForGV(cir::GlobalOp &gv, const NamedDecl *nd)
static bool verifyPointerTypeArgs(cir::FuncOp oldF, cir::FuncOp newF, mlir::SymbolUserMap &userMap)
static cir::CtorKind getCtorKindFromDecl(const CXXConstructorDecl *ctor)
static void emitUsed(CIRGenModule &cgm, StringRef name, std::vector< cir::CIRGlobalValueInterface > &list)
static cir::GlobalViewAttr createNewGlobalView(CIRGenModule &cgm, cir::GlobalOp newGlob, cir::GlobalViewAttr attr, mlir::Type oldTy)
This file defines OpenACC nodes for declarative directives.
*collection of selector each with an associated kind and an ordered *collection of selectors A selector has a kind
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)
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 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
GVALinkage GetGVALinkageForFunction(const FunctionDecl *FD) const
bool isAlignmentRequired(const Type *T) const
Determine if the alignment the type has was required using an alignment attribute.
int64_t toBits(CharUnits CharSize) const
Convert a size in characters to a size in bits.
GVALinkage GetGVALinkageForVariable(const VarDecl *VD) const
unsigned getTypeAlignIfKnown(QualType T, bool NeedsPreferredAlignment=false) const
Return the alignment of a type, in bits, or 0 if the type is incomplete and we cannot determine the a...
QualType getFunctionType(QualType ResultTy, ArrayRef< QualType > Args, const FunctionProtoType::ExtProtoInfo &EPI) const
Return a normal function type with a typed argument list.
DiagnosticsEngine & getDiagnostics() const
const TargetInfo & getTargetInfo() const
TargetCXXABI::Kind getCXXABIKind() const
Return the C++ ABI kind that should be used.
ASTRecordLayout - This class contains layout information for one RecordDecl, which is a struct/union/...
CharUnits getBaseClassOffset(const CXXRecordDecl *Base) const
getBaseClassOffset - Get the offset, in chars, for the given base class.
mlir::Attribute getConstRecordOrZeroAttr(mlir::ArrayAttr arrayAttr, bool packed=false, bool padded=false, mlir::Type type={})
uint64_t computeOffsetFromGlobalViewIndices(const cir::CIRDataLayout &layout, mlir::Type ty, llvm::ArrayRef< int64_t > indices)
void computeGlobalViewIndicesFromFlatOffset(int64_t offset, mlir::Type ty, cir::CIRDataLayout layout, llvm::SmallVectorImpl< 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
llvm::ArrayRef< CanQualType > arguments() const
cir::FuncOp generateCode(clang::GlobalDecl gd, cir::FuncOp fn, cir::FuncType funcType)
void emitVariablyModifiedType(QualType ty)
mlir::Operation * curFn
The current function or global initializer that is generated code for.
This class organizes the cross-function state that is used while generating CIR code.
cir::GlobalOp getAddrOfUnnamedGlobalConstantDecl(const UnnamedGlobalConstantDecl *gcd)
void updateResolvedBlockAddress(cir::BlockAddressOp op, cir::LabelOp newLabel)
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 replaceUsesOfNonProtoTypeWithRealFunction(mlir::Operation *old, cir::FuncOp newFn)
This function is called when we implement a function with no prototype, e.g.
llvm::StringRef getMangledName(clang::GlobalDecl gd)
CharUnits computeNonVirtualBaseClassOffset(const CXXRecordDecl *derivedClass, llvm::iterator_range< CastExpr::path_const_iterator > path)
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
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()
llvm::DenseMap< cir::BlockAddrInfoAttr, cir::LabelOp > blockAddressInfoToLabel
Map BlockAddrInfoAttr (function name, label name) to the corresponding CIR LabelOp.
void emitTopLevelDecl(clang::Decl *decl)
void emitOMPDeclareMapper(const OMPDeclareMapperDecl *d)
void addReplacement(llvm::StringRef name, mlir::Operation *op)
mlir::Type convertType(clang::QualType type)
bool shouldEmitRTTI(bool forEH=false)
cir::GlobalOp getGlobalForStringLiteral(const StringLiteral *s, llvm::StringRef name=".str")
Return a global symbol reference to a constant array for the given string literal.
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)
void mapUnresolvedBlockAddress(cir::BlockAddressOp op)
bool mustBeEmitted(const clang::ValueDecl *d)
Determine whether the definition must be emitted; if this returns false, the definition can be emitte...
void emitGlobalOpenACCDeclareDecl(const clang::OpenACCDeclareDecl *cd)
mlir::IntegerAttr getSize(CharUnits size)
void setGlobalTlsReferences(const VarDecl &vd, cir::GlobalOp globalOp)
CIRGenBuilderTy & getBuilder()
void setDSOLocal(mlir::Operation *op) const
std::string getUniqueGlobalName(const std::string &baseName)
std::pair< cir::FuncType, cir::FuncOp > getAddrAndTypeOfCXXStructor(clang::GlobalDecl gd, const CIRGenFunctionInfo *fnInfo=nullptr, cir::FuncType fnType=nullptr, bool dontDefer=false, ForDefinition_t isForDefinition=NotForDefinition)
void setGVProperties(mlir::Operation *op, const NamedDecl *d) const
Set visibility, dllimport/dllexport and dso_local.
cir::GlobalOp getOrCreateCIRGlobal(llvm::StringRef mangledName, mlir::Type ty, LangAS langAS, const VarDecl *d, ForDefinition_t isForDefinition)
If the specified mangled name is not in the module, create and return an mlir::GlobalOp value.
cir::FuncOp createCIRBuiltinFunction(mlir::Location loc, llvm::StringRef name, cir::FuncType ty, const clang::FunctionDecl *fd)
Create a CIR function with builtin attribute set.
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
void emitOMPRequiresDecl(const OMPRequiresDecl *d)
void emitGlobalDefinition(clang::GlobalDecl gd, mlir::Operation *op=nullptr)
void mapResolvedBlockAddress(cir::BlockAddressOp op, cir::LabelOp)
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.
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
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
static mlir::SymbolTable::Visibility getMLIRVisibility(Visibility v)
void emitTentativeDefinition(const VarDecl *d)
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)
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.
void emitAliasForGlobal(llvm::StringRef mangledName, mlir::Operation *op, GlobalDecl aliasGD, cir::FuncOp aliasee, cir::GlobalLinkageKind linkage)
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
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.
const cir::CIRDataLayout getDataLayout() const
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.
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 ...
void constructAttributeList(llvm::StringRef name, const CIRGenFunctionInfo &info, CIRGenCalleeInfo calleeInfo, mlir::NamedAttrList &attrs, llvm::MutableArrayRef< mlir::NamedAttrList > argAttrs, mlir::NamedAttrList &retAttrs, cir::CallingConv &callingConv, cir::SideEffect &sideEffect, bool attrOnCallSite, bool isThunk)
Get the CIR attributes and calling convention to use for a particular function type.
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)
cir::TLS_Model getDefaultCIRTLSModel() const
Get TLS mode from CodeGenOptions.
void addGlobalDtor(cir::FuncOp dtor, std::optional< int > priority=std::nullopt)
Add a function to the list that will be called when the module is unloaded.
void addDeferredDeclToEmit(clang::GlobalDecl GD)
bool shouldEmitCUDAGlobalVar(const VarDecl *global) const
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.
llvm::DenseSet< cir::BlockAddressOp > unresolvedBlockAddressToLabel
Track CIR BlockAddressOps that cannot be resolved immediately because their LabelOp has not yet been ...
mlir::Location getLoc(clang::SourceLocation cLoc)
Helpers to convert the presumed location of Clang's SourceLocation to an MLIR Location.
llvm::DenseMap< mlir::Attribute, cir::GlobalOp > constantStringMap
mlir::Operation * lastGlobalOp
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.
static cir::VisibilityKind getGlobalVisibilityKindFromClangVisibility(clang::VisibilityAttr::VisibilityType visibility)
llvm::StringMap< unsigned > cgGlobalNames
void setCXXSpecialMemberAttr(cir::FuncOp funcOp, const clang::FunctionDecl *funcDecl)
Mark the function as a special member (e.g. constructor, destructor)
mlir::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()
mlir::Operation * getAddrOfGlobal(clang::GlobalDecl gd, ForDefinition_t isForDefinition=NotForDefinition)
void maybeSetTrivialComdat(const clang::Decl &d, mlir::Operation *op)
CIRGenCXXABI & getCXXABI() const
cir::GlobalViewAttr getAddrOfConstantStringFromLiteral(const StringLiteral *s, llvm::StringRef name=".str")
Return a global symbol reference to a constant array for the given string literal.
llvm::MapVector< cir::BlockAddressOp, cir::LabelOp > blockAddressToLabel
Map CIR BlockAddressOps directly to their resolved LabelOps.
bool lookupRepresentativeDecl(llvm::StringRef mangledName, clang::GlobalDecl &gd) const
void emitDeclContext(const DeclContext *dc)
clang::CharUnits getNaturalPointeeTypeAlignment(clang::QualType t, LValueBaseInfo *baseInfo=nullptr)
void emitGlobal(clang::GlobalDecl gd)
Emit code for a single global function or variable declaration.
cir::LabelOp lookupBlockAddressInfo(cir::BlockAddrInfoAttr blockInfo)
bool mayBeEmittedEagerly(const clang::ValueDecl *d)
Determine whether the definition can be emitted eagerly, or should be delayed until the end of the tr...
void mapBlockAddress(cir::BlockAddrInfoAttr blockInfo, cir::LabelOp label)
void addGlobalAnnotations(const clang::ValueDecl *d, mlir::Operation *gv)
Add global annotations for a global value (GlobalOp or FuncOp).
void setCIRFunctionAttributesForDefinition(const clang::FunctionDecl *fd, cir::FuncOp f)
Set extra attributes (inline, etc.) for a function.
std::string getOpenACCBindMangledName(const IdentifierInfo *bindName, const FunctionDecl *attachedFunction)
void emitGlobalFunctionDefinition(clang::GlobalDecl gd, mlir::Operation *op)
CIRGenVTables & getVTables()
void setFunctionLinkage(GlobalDecl gd, cir::FuncOp f)
std::vector< clang::GlobalDecl > deferredDeclsToEmit
void emitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *d)
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.
cir::VisibilityAttr getGlobalVisibilityAttrFromDecl(const Decl *decl)
void setCommonAttributes(GlobalDecl gd, mlir::Operation *op)
Set attributes which are common to any form of a global definition (alias, Objective-C method,...
void emitDeclareTargetFunction(const FunctionDecl *fd, cir::FuncOp funcOp)
If the function has an OMPDeclareTargetDeclAttr, set the corresponding omp.declare_target attribute o...
const CIRGenFunctionInfo & arrangeGlobalDeclaration(GlobalDecl gd)
const CIRGenFunctionInfo & arrangeCXXMethodDeclaration(const clang::CXXMethodDecl *md)
C++ methods have some special rules and also have implicit parameters.
const CIRGenFunctionInfo & arrangeCXXStructorDeclaration(clang::GlobalDecl gd)
cir::FuncType getFunctionType(const CIRGenFunctionInfo &info)
Get the CIR function type for.
mlir::Type convertTypeForMem(clang::QualType, bool forBitField=false)
Convert type T into an mlir::Type.
void emitThunks(GlobalDecl gd)
Emit the associated thunks for the given global decl.
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 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.
bool hasDefinition() const
CharUnits - This is an opaque type for sizes expressed in character units.
llvm::Align getAsAlign() const
getAsAlign - Returns Quantity as a valid llvm::Align, Beware llvm::Align assumes power of two 8-bit b...
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
static CharUnits One()
One - Construct a CharUnits quantity of one.
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
llvm::Reloc::Model RelocationModel
The name of the relocation model to use.
Represents the canonical version of C arrays with a specified constant size.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
Decl - This represents one declaration (or definition), e.g.
bool isWeakImported() const
Determine whether this is a weak-imported symbol.
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.
Cached information about one file (either on disk or in the virtual file system).
StringRef tryGetRealPathName() const
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Represents a function declaration or definition.
static FunctionDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation NLoc, DeclarationName N, QualType T, TypeSourceInfo *TInfo, StorageClass SC, bool UsesFPIntrin=false, bool isInlineSpecified=false, bool hasWrittenPrototype=true, ConstexprSpecKind ConstexprKind=ConstexprSpecKind::Unspecified, const AssociatedConstraint &TrailingRequiresClause={})
bool hasPrototype() const
Whether this function has a prototype, either because one was explicitly written or because it was "i...
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
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.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
clang::ObjCRuntime ObjCRuntime
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 shouldMangleDeclName(const NamedDecl *D)
void mangleName(GlobalDecl GD, raw_ostream &)
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.
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.
bool hasUnwindExceptions() const
Does this runtime use zero-cost exceptions?
Represents a parameter to a function.
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
static ParmVarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
Represents an unpacked "presumed" location which can be presented to the user.
unsigned getColumn() const
Return the presumed column number of this location.
const char * getFilename() const
Return the presumed filename of this location.
unsigned getLine() const
Return the presumed line number of this location.
A (possibly-)qualified type.
LangAS getAddressSpace() const
Return the address space of this type.
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
bool isConstQualified() const
Determine whether this type is const-qualified.
bool isConstantStorage(const ASTContext &Ctx, bool ExcludeCtor, bool ExcludeDtor)
bool hasUnaligned() const
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
This class handles loading and caching of source files into memory.
PresumedLoc getPresumedLoc(SourceLocation Loc, bool UseLineDirectives=true) const
Returns the "presumed" location of a SourceLocation specifies.
A trivial tuple used to represent a source range.
SourceLocation getEnd() const
SourceLocation getBegin() const
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
StringRef getString() const
unsigned getCharByteWidth() const
Represents the declaration of a struct/union/class/enum.
bool isMicrosoft() const
Is this ABI an MSVC-compatible ABI?
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.
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
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...
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
bool isPointerType() const
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.
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.
bool isMatchingAddressSpace(mlir::ptr::MemorySpaceAttrInterface cirAS, clang::LangAS as)
mlir::ptr::MemorySpaceAttrInterface toCIRAddressSpaceAttr(mlir::MLIRContext &ctx, clang::LangAS langAS)
Convert an AST LangAS to the appropriate CIR address space attribute interface.
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 > createSPIRVTargetCIRGenInfo(CIRGenTypes &cgt)
CIRGenCUDARuntime * createNVCUDARuntime(CIRGenModule &cgm)
const internal::VariadicDynCastAllOfMatcher< Decl, VarDecl > varDecl
Matches variable declarations.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const internal::VariadicDynCastAllOfMatcher< Decl, FieldDecl > fieldDecl
Matches field declarations.
const internal::VariadicDynCastAllOfMatcher< Decl, FunctionDecl > functionDecl
Matches function declarations.
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
GVALinkage
A more specific kind of linkage than enum Linkage.
@ GVA_AvailableExternally
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
@ SD_Thread
Thread storage duration.
@ SD_Static
Static storage duration.
bool isLambdaCallOperator(const CXXMethodDecl *MD)
@ 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.
static bool globalCtorLexOrder()
static bool opFuncArmNewAttr()
static bool getRuntimeFunctionDecl()
static bool weakRefReference()
static bool opFuncOptNoneAttr()
static bool addressSpace()
static bool opFuncMinSizeAttr()
static bool opGlobalUnnamedAddr()
static bool opGlobalThreadLocal()
static bool opFuncMultiVersioning()
static bool sourceLanguageCases()
static bool shouldSkipAliasEmission()
static bool opFuncAstDeclAttr()
static bool opFuncNoDuplicateAttr()
static bool stackProtector()
static bool moduleNameHash()
static bool opGlobalVisibility()
static bool setDLLStorageClass()
static bool opFuncUnwindTablesAttr()
static bool opFuncParameterAttributes()
static bool targetCIRGenInfoArch()
static bool opFuncExtraAttrs()
static bool opFuncNakedAttr()
static bool attributeNoBuiltin()
static bool opGlobalDLLImportExport()
static bool opGlobalPartition()
static bool opGlobalPragmaClangSection()
static bool opGlobalWeakRef()
static bool deferredCXXGlobalInit()
static bool opFuncOperandBundles()
static bool opFuncCallingConv()
static bool globalCtorAssociatedData()
static bool defaultVisibility()
static bool opFuncColdHotAttr()
static bool opFuncExceptions()
static bool opFuncArmStreamingAttr()
static bool cudaSupport()
static bool opFuncMaybeHandleStaticInExternC()
static bool checkAliases()
static bool generateDebugInfo()
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.