47 #include "llvm/ADT/StringSwitch.h" 48 #include "llvm/ADT/Triple.h" 49 #include "llvm/Analysis/TargetLibraryInfo.h" 50 #include "llvm/Frontend/OpenMP/OMPIRBuilder.h" 51 #include "llvm/IR/CallingConv.h" 52 #include "llvm/IR/DataLayout.h" 53 #include "llvm/IR/Intrinsics.h" 54 #include "llvm/IR/LLVMContext.h" 55 #include "llvm/IR/Module.h" 56 #include "llvm/IR/ProfileSummary.h" 57 #include "llvm/ProfileData/InstrProfReader.h" 58 #include "llvm/Support/CodeGen.h" 59 #include "llvm/Support/CommandLine.h" 60 #include "llvm/Support/ConvertUTF.h" 61 #include "llvm/Support/ErrorHandling.h" 62 #include "llvm/Support/MD5.h" 63 #include "llvm/Support/TimeProfiler.h" 65 using namespace clang;
66 using namespace CodeGen;
69 "limited-coverage-experimental", llvm::cl::ZeroOrMore, llvm::cl::Hidden,
70 llvm::cl::desc(
"Emit limited coverage mapping information (experimental)"),
71 llvm::cl::init(
false));
91 llvm_unreachable(
"invalid C++ ABI kind");
99 : Context(C), LangOpts(C.getLangOpts()), HeaderSearchOpts(HSO),
100 PreprocessorOpts(PPO), CodeGenOpts(CGO), TheModule(M), Diags(diags),
102 VMContext(M.getContext()), Types(*this), VTables(*this),
106 llvm::LLVMContext &LLVMContext = M.getContext();
107 VoidTy = llvm::Type::getVoidTy(LLVMContext);
108 Int8Ty = llvm::Type::getInt8Ty(LLVMContext);
109 Int16Ty = llvm::Type::getInt16Ty(LLVMContext);
110 Int32Ty = llvm::Type::getInt32Ty(LLVMContext);
111 Int64Ty = llvm::Type::getInt64Ty(LLVMContext);
112 HalfTy = llvm::Type::getHalfTy(LLVMContext);
113 FloatTy = llvm::Type::getFloatTy(LLVMContext);
114 DoubleTy = llvm::Type::getDoubleTy(LLVMContext);
123 IntPtrTy = llvm::IntegerType::get(LLVMContext,
128 M.getDataLayout().getAllocaAddrSpace());
136 createOpenCLRuntime();
138 createOpenMPRuntime();
143 if (LangOpts.
Sanitize.
has(SanitizerKind::Thread) ||
144 (!CodeGenOpts.RelaxedAliasing && CodeGenOpts.OptimizationLevel > 0))
151 CodeGenOpts.EmitGcovArcs || CodeGenOpts.EmitGcovNotes)
154 Block.GlobalUniqueCount = 0;
162 if (
auto E = ReaderOrErr.takeError()) {
164 "Could not read profile %0: %1");
165 llvm::handleAllErrors(std::move(E), [&](
const llvm::ErrorInfoBase &EI) {
170 PGOReader = std::move(ReaderOrErr.get());
175 if (CodeGenOpts.CoverageMapping)
181 void CodeGenModule::createObjCRuntime() {
198 llvm_unreachable(
"bad runtime kind");
201 void CodeGenModule::createOpenCLRuntime() {
205 void CodeGenModule::createOpenMPRuntime() {
209 case llvm::Triple::nvptx:
210 case llvm::Triple::nvptx64:
212 "OpenMP NVPTX is only prepared to deal with device code.");
216 if (LangOpts.OpenMPSimd)
226 if (LangOpts.OpenMPIRBuilder) {
227 OMPBuilder.reset(
new llvm::OpenMPIRBuilder(TheModule));
228 OMPBuilder->initialize();
232 void CodeGenModule::createCUDARuntime() {
237 Replacements[Name] = C;
240 void CodeGenModule::applyReplacements() {
241 for (
auto &I : Replacements) {
242 StringRef MangledName = I.first();
243 llvm::Constant *Replacement = I.second;
247 auto *OldF = cast<llvm::Function>(Entry);
248 auto *NewF = dyn_cast<llvm::Function>(Replacement);
250 if (
auto *Alias = dyn_cast<llvm::GlobalAlias>(Replacement)) {
251 NewF = dyn_cast<llvm::Function>(Alias->getAliasee());
253 auto *CE = cast<llvm::ConstantExpr>(Replacement);
254 assert(CE->getOpcode() == llvm::Instruction::BitCast ||
255 CE->getOpcode() == llvm::Instruction::GetElementPtr);
256 NewF = dyn_cast<llvm::Function>(CE->getOperand(0));
261 OldF->replaceAllUsesWith(Replacement);
263 NewF->removeFromParent();
264 OldF->getParent()->getFunctionList().insertAfter(OldF->getIterator(),
267 OldF->eraseFromParent();
272 GlobalValReplacements.push_back(std::make_pair(GV, C));
275 void CodeGenModule::applyGlobalValReplacements() {
276 for (
auto &I : GlobalValReplacements) {
277 llvm::GlobalValue *GV = I.first;
278 llvm::Constant *C = I.second;
280 GV->replaceAllUsesWith(C);
281 GV->eraseFromParent();
288 const llvm::GlobalIndirectSymbol &GIS) {
289 llvm::SmallPtrSet<const llvm::GlobalIndirectSymbol*, 4> Visited;
290 const llvm::Constant *C = &GIS;
292 C = C->stripPointerCasts();
293 if (
auto *GO = dyn_cast<llvm::GlobalObject>(C))
296 auto *GIS2 = dyn_cast<llvm::GlobalIndirectSymbol>(C);
299 if (!Visited.insert(GIS2).second)
301 C = GIS2->getIndirectSymbol();
305 void CodeGenModule::checkAliases() {
312 const auto *D = cast<ValueDecl>(GD.getDecl());
314 bool IsIFunc = D->hasAttr<IFuncAttr>();
315 if (
const Attr *A = D->getDefiningAttr())
316 Location = A->getLocation();
318 llvm_unreachable(
"Not an alias or ifunc?");
321 auto *Alias = cast<llvm::GlobalIndirectSymbol>(Entry);
325 Diags.
Report(Location, diag::err_cyclic_alias) << IsIFunc;
326 }
else if (GV->isDeclaration()) {
328 Diags.
Report(Location, diag::err_alias_to_undefined)
329 << IsIFunc << IsIFunc;
330 }
else if (IsIFunc) {
332 llvm::FunctionType *FTy = dyn_cast<llvm::FunctionType>(
333 GV->getType()->getPointerElementType());
335 if (!FTy->getReturnType()->isPointerTy())
336 Diags.
Report(Location, diag::err_ifunc_resolver_return);
339 llvm::Constant *Aliasee = Alias->getIndirectSymbol();
340 llvm::GlobalValue *AliaseeGV;
341 if (
auto CE = dyn_cast<llvm::ConstantExpr>(Aliasee))
342 AliaseeGV = cast<llvm::GlobalValue>(CE->getOperand(0));
344 AliaseeGV = cast<llvm::GlobalValue>(Aliasee);
346 if (
const SectionAttr *SA = D->getAttr<SectionAttr>()) {
347 StringRef AliasSection = SA->getName();
348 if (AliasSection != AliaseeGV->getSection())
349 Diags.
Report(SA->getLocation(), diag::warn_alias_with_section)
350 << AliasSection << IsIFunc << IsIFunc;
358 if (
auto GA = dyn_cast<llvm::GlobalIndirectSymbol>(AliaseeGV)) {
359 if (GA->isInterposable()) {
360 Diags.
Report(Location, diag::warn_alias_to_weak_alias)
361 << GV->getName() << GA->getName() << IsIFunc;
362 Aliasee = llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast(
363 GA->getIndirectSymbol(), Alias->getType());
364 Alias->setIndirectSymbol(Aliasee);
374 auto *Alias = dyn_cast<llvm::GlobalIndirectSymbol>(Entry);
375 Alias->replaceAllUsesWith(llvm::UndefValue::get(Alias->getType()));
376 Alias->eraseFromParent();
381 DeferredDeclsToEmit.clear();
383 OpenMPRuntime->clear();
387 StringRef MainFile) {
388 if (!hasDiagnostics())
390 if (VisitedInMainFile > 0 && VisitedInMainFile == MissingInMainFile) {
391 if (MainFile.empty())
392 MainFile =
"<stdin>";
393 Diags.
Report(diag::warn_profile_data_unprofiled) << MainFile;
396 Diags.
Report(diag::warn_profile_data_out_of_date) << Visited << Mismatched;
399 Diags.
Report(diag::warn_profile_data_missing) << Visited << Missing;
405 EmitVTablesOpportunistically();
406 applyGlobalValReplacements();
409 emitMultiVersionFunctions();
410 EmitCXXGlobalInitFunc();
411 EmitCXXGlobalDtorFunc();
412 registerGlobalDtorsWithAtExit();
413 EmitCXXThreadLocalInitFunc();
415 if (llvm::Function *ObjCInitFunction =
ObjCRuntime->ModuleInitFunction())
416 AddGlobalCtor(ObjCInitFunction);
419 if (llvm::Function *CudaCtorFunction =
420 CUDARuntime->makeModuleCtorFunction())
421 AddGlobalCtor(CudaCtorFunction);
424 if (llvm::Function *OpenMPRequiresDirectiveRegFun =
425 OpenMPRuntime->emitRequiresDirectiveRegFun()) {
426 AddGlobalCtor(OpenMPRequiresDirectiveRegFun, 0);
428 OpenMPRuntime->createOffloadEntriesAndInfoMetadata();
429 OpenMPRuntime->clear();
433 PGOReader->getSummary(
false).getMD(VMContext),
434 llvm::ProfileSummary::PSK_Instr);
438 EmitCtorList(GlobalCtors,
"llvm.global_ctors");
439 EmitCtorList(GlobalDtors,
"llvm.global_dtors");
441 EmitStaticExternCAliases();
444 CoverageMapping->emit();
445 if (CodeGenOpts.SanitizeCfiCrossDso) {
449 emitAtAvailableLinkGuard();
454 if (CodeGenOpts.Autolink &&
455 (Context.
getLangOpts().Modules || !LinkerOptionsMetadata.empty())) {
456 EmitModuleLinkOptions();
471 if (!ELFDependentLibraries.empty() && !Context.
getLangOpts().CUDAIsDevice) {
472 auto *NMD =
getModule().getOrInsertNamedMetadata(
"llvm.dependent-libraries");
473 for (
auto *MD : ELFDependentLibraries)
480 CodeGenOpts.NumRegisterParameters);
482 if (CodeGenOpts.DwarfVersion) {
483 getModule().addModuleFlag(llvm::Module::Max,
"Dwarf Version",
484 CodeGenOpts.DwarfVersion);
486 if (CodeGenOpts.EmitCodeView) {
490 if (CodeGenOpts.CodeViewGHash) {
493 if (CodeGenOpts.ControlFlowGuard) {
496 }
else if (CodeGenOpts.ControlFlowGuardNoChecks) {
500 if (CodeGenOpts.OptimizationLevel > 0 && CodeGenOpts.StrictVTablePointers) {
507 llvm::Metadata *Ops[2] = {
508 llvm::MDString::get(VMContext,
"StrictVTablePointers"),
509 llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
510 llvm::Type::getInt32Ty(VMContext), 1))};
512 getModule().addModuleFlag(llvm::Module::Require,
513 "StrictVTablePointersRequirement",
514 llvm::MDNode::get(VMContext, Ops));
521 llvm::DEBUG_METADATA_VERSION);
526 uint64_t WCharWidth =
531 if ( Arch == llvm::Triple::arm
532 || Arch == llvm::Triple::armeb
533 || Arch == llvm::Triple::thumb
534 || Arch == llvm::Triple::thumbeb) {
536 uint64_t EnumWidth = Context.
getLangOpts().ShortEnums ? 1 : 4;
540 if (Arch == llvm::Triple::riscv32 || Arch == llvm::Triple::riscv64) {
541 StringRef ABIStr = Target.
getABI();
542 llvm::LLVMContext &Ctx = TheModule.getContext();
544 llvm::MDString::get(Ctx, ABIStr));
547 if (CodeGenOpts.SanitizeCfiCrossDso) {
549 getModule().addModuleFlag(llvm::Module::Override,
"Cross-DSO CFI", 1);
552 if (LangOpts.
Sanitize.
has(SanitizerKind::CFIICall)) {
553 getModule().addModuleFlag(llvm::Module::Override,
554 "CFI Canonical Jump Tables",
555 CodeGenOpts.SanitizeCfiCanonicalJumpTables);
558 if (CodeGenOpts.CFProtectionReturn &&
561 getModule().addModuleFlag(llvm::Module::Override,
"cf-protection-return",
565 if (CodeGenOpts.CFProtectionBranch &&
568 getModule().addModuleFlag(llvm::Module::Override,
"cf-protection-branch",
572 if (LangOpts.CUDAIsDevice &&
getTriple().isNVPTX()) {
576 getModule().addModuleFlag(llvm::Module::Override,
"nvvm-reflect-ftz",
577 CodeGenOpts.FlushDenorm ? 1 : 0);
581 if (LangOpts.OpenCL) {
582 EmitOpenCLMetadata();
588 auto Version = LangOpts.OpenCLCPlusPlus ? 200 : LangOpts.OpenCLVersion;
589 llvm::Metadata *SPIRVerElts[] = {
590 llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
592 llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
593 Int32Ty, (Version / 100 > 1) ? 0 : 2))};
594 llvm::NamedMDNode *SPIRVerMD =
595 TheModule.getOrInsertNamedMetadata(
"opencl.spir.version");
596 llvm::LLVMContext &Ctx = TheModule.getContext();
597 SPIRVerMD->addOperand(llvm::MDNode::get(Ctx, SPIRVerElts));
601 if (uint32_t PLevel = Context.
getLangOpts().PICLevel) {
602 assert(PLevel < 3 &&
"Invalid PIC Level");
603 getModule().setPICLevel(static_cast<llvm::PICLevel::Level>(PLevel));
605 getModule().setPIELevel(static_cast<llvm::PIELevel::Level>(PLevel));
610 .Case(
"tiny", llvm::CodeModel::Tiny)
611 .Case(
"small", llvm::CodeModel::Small)
612 .Case(
"kernel", llvm::CodeModel::Kernel)
613 .Case(
"medium", llvm::CodeModel::Medium)
614 .Case(
"large", llvm::CodeModel::Large)
617 llvm::CodeModel::Model codeModel =
static_cast<llvm::CodeModel::Model
>(CM);
622 if (CodeGenOpts.NoPLT)
625 SimplifyPersonality();
634 DebugInfo->finalize();
637 EmitVersionIdentMetadata();
640 EmitCommandLineMetadata();
642 EmitTargetMetadata();
645 void CodeGenModule::EmitOpenCLMetadata() {
650 auto Version = LangOpts.OpenCLCPlusPlus ? 200 : LangOpts.OpenCLVersion;
651 llvm::Metadata *OCLVerElts[] = {
652 llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
654 llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
655 Int32Ty, (Version % 100) / 10))};
656 llvm::NamedMDNode *OCLVerMD =
657 TheModule.getOrInsertNamedMetadata(
"opencl.ocl.version");
658 llvm::LLVMContext &Ctx = TheModule.getContext();
659 OCLVerMD->addOperand(llvm::MDNode::get(Ctx, OCLVerElts));
675 return TBAA->getTypeInfo(QTy);
681 return TBAA->getAccessInfo(AccessType);
688 return TBAA->getVTablePtrAccessInfo(VTablePtrType);
694 return TBAA->getTBAAStructInfo(QTy);
700 return TBAA->getBaseTypeInfo(QTy);
706 return TBAA->getAccessTagInfo(Info);
713 return TBAA->mergeTBAAInfoForCast(SourceInfo, TargetInfo);
721 return TBAA->mergeTBAAInfoForConditionalOperator(InfoA, InfoB);
729 return TBAA->mergeTBAAInfoForConditionalOperator(DestInfo, SrcInfo);
735 Inst->setMetadata(llvm::LLVMContext::MD_tbaa, Tag);
740 I->setMetadata(llvm::LLVMContext::MD_invariant_group,
753 "cannot compile this %0 yet");
754 std::string Msg =
Type;
763 "cannot compile this %0 yet");
764 std::string Msg =
Type;
774 if (GV->hasDLLImportStorageClass())
777 if (GV->hasLocalLinkage()) {
787 !GV->isDeclarationForLinker())
792 llvm::GlobalValue *GV) {
793 if (GV->hasLocalLinkage())
796 if (!GV->hasDefaultVisibility() && !GV->hasExternalWeakLinkage())
800 if (GV->hasDLLImportStorageClass())
803 const llvm::Triple &TT = CGM.
getTriple();
804 if (TT.isWindowsGNUEnvironment()) {
808 if (GV->isDeclarationForLinker() && isa<llvm::GlobalVariable>(GV) &&
809 !GV->isThreadLocal())
816 if (TT.isOSBinFormatCOFF() && GV->hasExternalWeakLinkage())
824 if (TT.isOSBinFormatCOFF() || (TT.isOSWindows() && TT.isOSBinFormatMachO()))
828 if (!TT.isOSBinFormatELF())
835 if (RM != llvm::Reloc::Static && !LOpts.PIE)
839 if (!GV->isDeclarationForLinker())
845 if (RM == llvm::Reloc::PIC_ && GV->hasExternalWeakLinkage())
849 llvm::Triple::ArchType Arch = TT.getArch();
850 if (Arch == llvm::Triple::ppc || Arch == llvm::Triple::ppc64 ||
851 Arch == llvm::Triple::ppc64le)
855 if (
auto *Var = dyn_cast<llvm::GlobalVariable>(GV))
856 if (!Var->isThreadLocal() &&
857 (RM == llvm::Reloc::Static || CGOpts.PIECopyRelocations))
863 if (isa<llvm::Function>(GV) && !CGOpts.NoPLT && RM == llvm::Reloc::Static)
878 if (
const auto *Dtor = dyn_cast_or_null<CXXDestructorDecl>(D)) {
888 if (D->
hasAttr<DLLImportAttr>())
889 GV->setDLLStorageClass(llvm::GlobalVariable::DLLImportStorageClass);
890 else if (D->
hasAttr<DLLExportAttr>() && !GV->isDeclarationForLinker())
891 GV->setDLLStorageClass(llvm::GlobalVariable::DLLExportStorageClass);
915 return llvm::StringSwitch<llvm::GlobalVariable::ThreadLocalMode>(S)
916 .Case(
"global-dynamic", llvm::GlobalVariable::GeneralDynamicTLSModel)
917 .Case(
"local-dynamic", llvm::GlobalVariable::LocalDynamicTLSModel)
918 .Case(
"initial-exec", llvm::GlobalVariable::InitialExecTLSModel)
919 .Case(
"local-exec", llvm::GlobalVariable::LocalExecTLSModel);
926 return llvm::GlobalVariable::GeneralDynamicTLSModel;
928 return llvm::GlobalVariable::LocalDynamicTLSModel;
930 return llvm::GlobalVariable::InitialExecTLSModel;
932 return llvm::GlobalVariable::LocalExecTLSModel;
934 llvm_unreachable(
"Invalid TLS model!");
938 assert(D.
getTLSKind() &&
"setting TLS mode on non-TLS var!");
940 llvm::GlobalValue::ThreadLocalMode TLM;
944 if (
const TLSModelAttr *
Attr = D.
getAttr<TLSModelAttr>()) {
948 GV->setThreadLocalMode(TLM);
958 const CPUSpecificAttr *
Attr,
970 const TargetAttr *
Attr, raw_ostream &Out) {
971 if (Attr->isDefaultVersion())
977 Attr->parse([&Target](StringRef LHS, StringRef RHS) {
980 assert(LHS.startswith(
"+") && RHS.startswith(
"+") &&
981 "Features should always have a prefix.");
993 for (StringRef Feat : Info.
Features) {
997 Out << Feat.substr(1);
1003 bool OmitMultiVersionMangling =
false) {
1005 llvm::raw_svector_ostream Out(Buffer);
1008 llvm::raw_svector_ostream Out(Buffer);
1009 if (
const auto *D = dyn_cast<CXXConstructorDecl>(ND))
1011 else if (
const auto *D = dyn_cast<CXXDestructorDecl>(ND))
1017 assert(II &&
"Attempt to mangle unnamed decl.");
1022 llvm::raw_svector_ostream Out(Buffer);
1023 Out <<
"__regcall3__" << II->
getName();
1029 if (
const auto *FD = dyn_cast<FunctionDecl>(ND))
1030 if (FD->isMultiVersion() && !OmitMultiVersionMangling) {
1031 switch (FD->getMultiVersionKind()) {
1035 FD->getAttr<CPUSpecificAttr>(),
1042 llvm_unreachable(
"None multiversion type isn't valid here");
1049 void CodeGenModule::UpdateMultiVersionNames(
GlobalDecl GD,
1057 std::string NonTargetName =
1065 "Other GD should now be a multiversioned function");
1075 if (OtherName != NonTargetName) {
1078 const auto ExistingRecord = Manglings.find(NonTargetName);
1079 if (ExistingRecord != std::end(Manglings))
1080 Manglings.remove(&(*ExistingRecord));
1081 auto Result = Manglings.insert(std::make_pair(OtherName, OtherGD));
1084 Entry->setName(OtherName);
1094 if (
const auto *CD = dyn_cast<CXXConstructorDecl>(CanonicalGD.
getDecl())) {
1103 auto FoundName = MangledDeclNames.find(CanonicalGD);
1104 if (FoundName != MangledDeclNames.end())
1105 return FoundName->second;
1108 const auto *ND = cast<NamedDecl>(GD.
getDecl());
1113 if (
auto *FD = dyn_cast<FunctionDecl>(GD.
getDecl()))
1117 auto Result = Manglings.insert(std::make_pair(MangledName, GD));
1118 return MangledDeclNames[CanonicalGD] = Result.first->first();
1127 llvm::raw_svector_ostream Out(Buffer);
1130 dyn_cast_or_null<VarDecl>(initializedGlobalDecl.
getDecl()), Out);
1131 else if (
const auto *CD = dyn_cast<CXXConstructorDecl>(D))
1133 else if (
const auto *DD = dyn_cast<CXXDestructorDecl>(D))
1136 MangleCtx.
mangleBlock(cast<DeclContext>(D), BD, Out);
1138 auto Result = Manglings.insert(std::make_pair(Out.str(), BD));
1139 return Result.first->first();
1148 void CodeGenModule::AddGlobalCtor(llvm::Function *Ctor,
int Priority,
1149 llvm::Constant *AssociatedData) {
1151 GlobalCtors.push_back(
Structor(Priority, Ctor, AssociatedData));
1156 void CodeGenModule::AddGlobalDtor(llvm::Function *Dtor,
int Priority) {
1157 if (CodeGenOpts.RegisterGlobalDtorsWithAtExit) {
1158 DtorsUsingAtExit[
Priority].push_back(Dtor);
1163 GlobalDtors.push_back(
Structor(Priority, Dtor,
nullptr));
1166 void CodeGenModule::EmitCtorList(
CtorList &Fns,
const char *GlobalName) {
1167 if (Fns.empty())
return;
1170 llvm::FunctionType* CtorFTy = llvm::FunctionType::get(
VoidTy,
false);
1171 llvm::Type *CtorPFTy = llvm::PointerType::get(CtorFTy,
1172 TheModule.getDataLayout().getProgramAddressSpace());
1175 llvm::StructType *CtorStructTy = llvm::StructType::get(
1180 auto ctors = builder.
beginArray(CtorStructTy);
1181 for (
const auto &I : Fns) {
1182 auto ctor = ctors.beginStruct(CtorStructTy);
1183 ctor.addInt(
Int32Ty, I.Priority);
1184 ctor.add(llvm::ConstantExpr::getBitCast(I.Initializer, CtorPFTy));
1185 if (I.AssociatedData)
1186 ctor.add(llvm::ConstantExpr::getBitCast(I.AssociatedData,
VoidPtrTy));
1189 ctor.finishAndAddTo(ctors);
1195 llvm::GlobalValue::AppendingLinkage);
1204 llvm::GlobalValue::LinkageTypes
1206 const auto *D = cast<FunctionDecl>(GD.
getDecl());
1210 if (
const auto *Dtor = dyn_cast<CXXDestructorDecl>(D))
1213 if (isa<CXXConstructorDecl>(D) &&
1214 cast<CXXConstructorDecl>(D)->isInheritingConstructor() &&
1226 llvm::MDString *MDS = dyn_cast<llvm::MDString>(MD);
1227 if (!MDS)
return nullptr;
1229 return llvm::ConstantInt::get(
Int64Ty, llvm::MD5Hash(MDS->getString()));
1234 llvm::Function *F) {
1236 llvm::AttributeList PAL;
1238 F->setAttributes(PAL);
1239 F->setCallingConv(static_cast<llvm::CallingConv::ID>(CallingConv));
1243 std::string ReadOnlyQual(
"__read_only");
1244 std::string::size_type ReadOnlyPos = TyName.find(ReadOnlyQual);
1245 if (ReadOnlyPos != std::string::npos)
1247 TyName.erase(ReadOnlyPos, ReadOnlyQual.size() + 1);
1249 std::string WriteOnlyQual(
"__write_only");
1250 std::string::size_type WriteOnlyPos = TyName.find(WriteOnlyQual);
1251 if (WriteOnlyPos != std::string::npos)
1252 TyName.erase(WriteOnlyPos, WriteOnlyQual.size() + 1);
1254 std::string ReadWriteQual(
"__read_write");
1255 std::string::size_type ReadWritePos = TyName.find(ReadWriteQual);
1256 if (ReadWritePos != std::string::npos)
1257 TyName.erase(ReadWritePos, ReadWriteQual.size() + 1);
1282 assert(((FD && CGF) || (!FD && !CGF)) &&
1283 "Incorrect use - FD and CGF should either be both null or not!");
1309 for (
unsigned i = 0, e = FD->
getNumParams(); i != e; ++i) {
1312 std::string typeQuals;
1318 addressQuals.push_back(
1319 llvm::ConstantAsMetadata::get(CGF->
Builder.getInt32(
1323 std::string typeName =
1327 std::string::size_type pos = typeName.find(
"unsigned");
1328 if (pointeeTy.
isCanonical() && pos != std::string::npos)
1329 typeName.erase(pos + 1, 8);
1331 argTypeNames.push_back(llvm::MDString::get(VMContext, typeName));
1333 std::string baseTypeName =
1339 pos = baseTypeName.find(
"unsigned");
1340 if (pos != std::string::npos)
1341 baseTypeName.erase(pos + 1, 8);
1343 argBaseTypeNames.push_back(
1344 llvm::MDString::get(VMContext, baseTypeName));
1348 typeQuals =
"restrict";
1351 typeQuals += typeQuals.empty() ?
"const" :
" const";
1353 typeQuals += typeQuals.empty() ?
"volatile" :
" volatile";
1355 uint32_t AddrSpc = 0;
1360 addressQuals.push_back(
1361 llvm::ConstantAsMetadata::get(CGF->
Builder.getInt32(AddrSpc)));
1364 std::string typeName;
1369 .getAsString(Policy);
1374 std::string::size_type pos = typeName.find(
"unsigned");
1376 typeName.erase(pos + 1, 8);
1378 std::string baseTypeName;
1384 .getAsString(Policy);
1398 argTypeNames.push_back(llvm::MDString::get(VMContext, typeName));
1401 pos = baseTypeName.find(
"unsigned");
1402 if (pos != std::string::npos)
1403 baseTypeName.erase(pos + 1, 8);
1405 argBaseTypeNames.push_back(
1406 llvm::MDString::get(VMContext, baseTypeName));
1412 argTypeQuals.push_back(llvm::MDString::get(VMContext, typeQuals));
1416 const Decl *PDecl = parm;
1417 if (
auto *TD = dyn_cast<TypedefType>(ty))
1418 PDecl = TD->getDecl();
1419 const OpenCLAccessAttr *A = PDecl->
getAttr<OpenCLAccessAttr>();
1420 if (A && A->isWriteOnly())
1421 accessQuals.push_back(llvm::MDString::get(VMContext,
"write_only"));
1422 else if (A && A->isReadWrite())
1423 accessQuals.push_back(llvm::MDString::get(VMContext,
"read_write"));
1425 accessQuals.push_back(llvm::MDString::get(VMContext,
"read_only"));
1427 accessQuals.push_back(llvm::MDString::get(VMContext,
"none"));
1430 argNames.push_back(llvm::MDString::get(VMContext, parm->
getName()));
1433 Fn->setMetadata(
"kernel_arg_addr_space",
1434 llvm::MDNode::get(VMContext, addressQuals));
1435 Fn->setMetadata(
"kernel_arg_access_qual",
1436 llvm::MDNode::get(VMContext, accessQuals));
1437 Fn->setMetadata(
"kernel_arg_type",
1438 llvm::MDNode::get(VMContext, argTypeNames));
1439 Fn->setMetadata(
"kernel_arg_base_type",
1440 llvm::MDNode::get(VMContext, argBaseTypeNames));
1441 Fn->setMetadata(
"kernel_arg_type_qual",
1442 llvm::MDNode::get(VMContext, argTypeQuals));
1444 Fn->setMetadata(
"kernel_arg_name",
1445 llvm::MDNode::get(VMContext, argNames));
1455 if (!LangOpts.Exceptions)
return false;
1458 if (LangOpts.CXXExceptions)
return true;
1461 if (LangOpts.ObjCExceptions) {
1478 !isa<CXXDestructorDecl>(MD);
1481 std::vector<const CXXRecordDecl *>
1483 llvm::SetVector<const CXXRecordDecl *> MostBases;
1485 std::function<void (const CXXRecordDecl *)> CollectMostBases;
1488 MostBases.insert(RD);
1490 CollectMostBases(B.getType()->getAsCXXRecordDecl());
1492 CollectMostBases(RD);
1493 return MostBases.takeVector();
1497 llvm::Function *F) {
1498 llvm::AttrBuilder B;
1500 if (CodeGenOpts.UnwindTables)
1501 B.addAttribute(llvm::Attribute::UWTable);
1504 B.addAttribute(llvm::Attribute::NoUnwind);
1506 if (!D || !D->
hasAttr<NoStackProtectorAttr>()) {
1508 B.addAttribute(llvm::Attribute::StackProtect);
1510 B.addAttribute(llvm::Attribute::StackProtectStrong);
1512 B.addAttribute(llvm::Attribute::StackProtectReq);
1519 if (!F->hasFnAttribute(llvm::Attribute::AlwaysInline) &&
1521 B.addAttribute(llvm::Attribute::NoInline);
1523 F->addAttributes(llvm::AttributeList::FunctionIndex, B);
1529 bool ShouldAddOptNone =
1530 !CodeGenOpts.DisableO0ImplyOptNone && CodeGenOpts.OptimizationLevel == 0;
1532 ShouldAddOptNone &= !D->
hasAttr<MinSizeAttr>();
1533 ShouldAddOptNone &= !D->
hasAttr<AlwaysInlineAttr>();
1536 if ((ShouldAddOptNone || D->
hasAttr<OptimizeNoneAttr>()) &&
1537 !F->hasFnAttribute(llvm::Attribute::AlwaysInline)) {
1538 B.addAttribute(llvm::Attribute::OptimizeNone);
1541 B.addAttribute(llvm::Attribute::NoInline);
1546 B.addAttribute(llvm::Attribute::Naked);
1549 F->removeFnAttr(llvm::Attribute::OptimizeForSize);
1550 F->removeFnAttr(llvm::Attribute::MinSize);
1551 }
else if (D->
hasAttr<NakedAttr>()) {
1553 B.addAttribute(llvm::Attribute::Naked);
1554 B.addAttribute(llvm::Attribute::NoInline);
1555 }
else if (D->
hasAttr<NoDuplicateAttr>()) {
1556 B.addAttribute(llvm::Attribute::NoDuplicate);
1557 }
else if (D->
hasAttr<NoInlineAttr>() && !F->hasFnAttribute(llvm::Attribute::AlwaysInline)) {
1559 B.addAttribute(llvm::Attribute::NoInline);
1560 }
else if (D->
hasAttr<AlwaysInlineAttr>() &&
1561 !F->hasFnAttribute(llvm::Attribute::NoInline)) {
1563 B.addAttribute(llvm::Attribute::AlwaysInline);
1567 if (!F->hasFnAttribute(llvm::Attribute::AlwaysInline))
1568 B.addAttribute(llvm::Attribute::NoInline);
1572 if (
auto *FD = dyn_cast<FunctionDecl>(D)) {
1575 auto CheckRedeclForInline = [](
const FunctionDecl *Redecl) {
1576 return Redecl->isInlineSpecified();
1578 if (any_of(FD->
redecls(), CheckRedeclForInline))
1583 return any_of(Pattern->
redecls(), CheckRedeclForInline);
1585 if (CheckForInline(FD)) {
1586 B.addAttribute(llvm::Attribute::InlineHint);
1587 }
else if (CodeGenOpts.getInlining() ==
1590 !F->hasFnAttribute(llvm::Attribute::AlwaysInline)) {
1591 B.addAttribute(llvm::Attribute::NoInline);
1598 if (!D->
hasAttr<OptimizeNoneAttr>()) {
1600 if (!ShouldAddOptNone)
1601 B.addAttribute(llvm::Attribute::OptimizeForSize);
1602 B.addAttribute(llvm::Attribute::Cold);
1605 if (D->
hasAttr<MinSizeAttr>())
1606 B.addAttribute(llvm::Attribute::MinSize);
1609 F->addAttributes(llvm::AttributeList::FunctionIndex, B);
1613 F->setAlignment(llvm::Align(alignment));
1615 if (!D->
hasAttr<AlignedAttr>())
1616 if (LangOpts.FunctionAlignment)
1617 F->setAlignment(llvm::Align(1ull << LangOpts.FunctionAlignment));
1624 if (F->getAlignment() < 2 && isa<CXXMethodDecl>(D))
1625 F->setAlignment(llvm::Align(2));
1630 if (CodeGenOpts.SanitizeCfiCrossDso &&
1631 CodeGenOpts.SanitizeCfiCanonicalJumpTables) {
1632 if (
auto *FD = dyn_cast<FunctionDecl>(D)) {
1646 llvm::Metadata *
Id =
1649 F->addTypeMetadata(0, Id);
1656 if (dyn_cast_or_null<NamedDecl>(D))
1661 if (D && D->
hasAttr<UsedAttr>())
1664 if (CodeGenOpts.KeepStaticConsts && D && isa<VarDecl>(D)) {
1665 const auto *VD = cast<VarDecl>(D);
1666 if (VD->getType().isConstQualified() &&
1672 bool CodeGenModule::GetCPUAndFeaturesAttributes(
GlobalDecl GD,
1673 llvm::AttrBuilder &Attrs) {
1678 std::vector<std::string> Features;
1679 const auto *FD = dyn_cast_or_null<FunctionDecl>(GD.
getDecl());
1681 const auto *TD = FD ? FD->
getAttr<TargetAttr>() :
nullptr;
1682 const auto *SD = FD ? FD->getAttr<CPUSpecificAttr>() :
nullptr;
1683 bool AddedAttr =
false;
1685 llvm::StringMap<bool> FeatureMap;
1689 for (
const llvm::StringMap<bool>::value_type &Entry : FeatureMap)
1690 Features.push_back((Entry.getValue() ?
"+" :
"-") + Entry.getKey().str());
1708 if (TargetCPU !=
"") {
1709 Attrs.addAttribute(
"target-cpu", TargetCPU);
1712 if (!Features.empty()) {
1713 llvm::sort(Features);
1714 Attrs.addAttribute(
"target-features", llvm::join(Features,
","));
1721 void CodeGenModule::setNonAliasAttributes(
GlobalDecl GD,
1722 llvm::GlobalObject *GO) {
1727 if (
auto *GV = dyn_cast<llvm::GlobalVariable>(GO)) {
1728 if (
auto *SA = D->
getAttr<PragmaClangBSSSectionAttr>())
1729 GV->addAttribute(
"bss-section", SA->getName());
1730 if (
auto *SA = D->
getAttr<PragmaClangDataSectionAttr>())
1731 GV->addAttribute(
"data-section", SA->getName());
1732 if (
auto *SA = D->
getAttr<PragmaClangRodataSectionAttr>())
1733 GV->addAttribute(
"rodata-section", SA->getName());
1734 if (
auto *SA = D->
getAttr<PragmaClangRelroSectionAttr>())
1735 GV->addAttribute(
"relro-section", SA->getName());
1738 if (
auto *F = dyn_cast<llvm::Function>(GO)) {
1739 if (
auto *SA = D->
getAttr<PragmaClangTextSectionAttr>())
1740 if (!D->
getAttr<SectionAttr>())
1741 F->addFnAttr(
"implicit-section-name", SA->getName());
1743 llvm::AttrBuilder Attrs;
1744 if (GetCPUAndFeaturesAttributes(GD, Attrs)) {
1748 F->removeFnAttr(
"target-cpu");
1749 F->removeFnAttr(
"target-features");
1750 F->addAttributes(llvm::AttributeList::FunctionIndex, Attrs);
1754 if (
const auto *CSA = D->
getAttr<CodeSegAttr>())
1755 GO->setSection(CSA->getName());
1756 else if (
const auto *SA = D->
getAttr<SectionAttr>())
1757 GO->setSection(SA->getName());
1772 setNonAliasAttributes(GD, F);
1783 GV->
setLinkage(llvm::GlobalValue::ExternalWeakLinkage);
1787 llvm::Function *F) {
1789 if (!LangOpts.
Sanitize.
has(SanitizerKind::CFIICall))
1794 if (isa<CXXMethodDecl>(FD) && !cast<CXXMethodDecl>(FD)->isStatic())
1798 F->addTypeMetadata(0, MD);
1802 if (CodeGenOpts.SanitizeCfiCrossDso)
1804 F->addTypeMetadata(0, llvm::ConstantAsMetadata::get(CrossDsoTypeId));
1807 void CodeGenModule::SetFunctionAttributes(
GlobalDecl GD, llvm::Function *F,
1808 bool IsIncompleteFunction,
1814 F->setAttributes(llvm::Intrinsic::getAttributes(
getLLVMContext(), IID));
1818 const auto *FD = cast<FunctionDecl>(GD.
getDecl());
1820 if (!IsIncompleteFunction)
1826 if (!IsThunk &&
getCXXABI().HasThisReturn(GD) &&
1828 assert(!F->arg_empty() &&
1829 F->arg_begin()->getType()
1830 ->canLosslesslyBitCastTo(F->getReturnType()) &&
1831 "unexpected this return");
1832 F->addAttribute(1, llvm::Attribute::Returned);
1842 if (!IsIncompleteFunction && F->isDeclaration())
1845 if (
const auto *CSA = FD->
getAttr<CodeSegAttr>())
1846 F->setSection(CSA->getName());
1847 else if (
const auto *SA = FD->
getAttr<SectionAttr>())
1848 F->setSection(SA->getName());
1851 F->addAttribute(llvm::AttributeList::FunctionIndex,
1852 llvm::Attribute::NoBuiltin);
1858 F->addAttribute(llvm::AttributeList::FunctionIndex,
1859 llvm::Attribute::NoBuiltin);
1866 (
Kind == OO_New ||
Kind == OO_Array_New))
1867 F->addAttribute(llvm::AttributeList::ReturnIndex,
1868 llvm::Attribute::NoAlias);
1871 if (isa<CXXConstructorDecl>(FD) || isa<CXXDestructorDecl>(FD))
1872 F->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
1873 else if (
const auto *MD = dyn_cast<CXXMethodDecl>(FD))
1874 if (MD->isVirtual())
1875 F->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
1881 if (!CodeGenOpts.SanitizeCfiCrossDso ||
1882 !CodeGenOpts.SanitizeCfiCanonicalJumpTables)
1888 if (
const auto *CB = FD->
getAttr<CallbackAttr>()) {
1892 llvm::LLVMContext &Ctx = F->getContext();
1893 llvm::MDBuilder MDB(Ctx);
1897 int CalleeIdx = *CB->encoding_begin();
1898 ArrayRef<int> PayloadIndices(CB->encoding_begin() + 1, CB->encoding_end());
1899 F->addMetadata(llvm::LLVMContext::MD_callback,
1900 *llvm::MDNode::get(Ctx, {MDB.createCallbackEncoding(
1901 CalleeIdx, PayloadIndices,
1907 assert(!GV->isDeclaration() &&
1908 "Only globals with definition can force usage.");
1909 LLVMUsed.emplace_back(GV);
1913 assert(!GV->isDeclaration() &&
1914 "Only globals with definition can force usage.");
1915 LLVMCompilerUsed.emplace_back(GV);
1919 std::vector<llvm::WeakTrackingVH> &List) {
1926 UsedArray.resize(List.size());
1927 for (
unsigned i = 0, e = List.size(); i != e; ++i) {
1929 llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast(
1930 cast<llvm::Constant>(&*List[i]), CGM.
Int8PtrTy);
1933 if (UsedArray.empty())
1935 llvm::ArrayType *ATy = llvm::ArrayType::get(CGM.
Int8PtrTy, UsedArray.size());
1937 auto *GV =
new llvm::GlobalVariable(
1938 CGM.
getModule(), ATy,
false, llvm::GlobalValue::AppendingLinkage,
1939 llvm::ConstantArray::get(ATy, UsedArray), Name);
1941 GV->setSection(
"llvm.metadata");
1944 void CodeGenModule::emitLLVMUsed() {
1945 emitUsed(*
this,
"llvm.used", LLVMUsed);
1946 emitUsed(*
this,
"llvm.compiler.used", LLVMCompilerUsed);
1951 LinkerOptionsMetadata.push_back(llvm::MDNode::get(
getLLVMContext(), MDOpts));
1960 LinkerOptionsMetadata.push_back(llvm::MDNode::get(
getLLVMContext(), MDOpts));
1966 ELFDependentLibraries.push_back(
1967 llvm::MDNode::get(C, llvm::MDString::get(C, Lib)));
1974 LinkerOptionsMetadata.push_back(llvm::MDNode::get(C, MDOpts));
1981 llvm::SmallPtrSet<Module *, 16> &Visited) {
1983 if (Mod->
Parent && Visited.insert(Mod->
Parent).second) {
1988 for (
unsigned I = Mod->
Imports.size(); I > 0; --I) {
1989 if (Visited.insert(Mod->
Imports[I - 1]).second)
2007 llvm::Metadata *Args[2] = {
2008 llvm::MDString::get(Context,
"-framework"),
2009 llvm::MDString::get(Context, Mod->
LinkLibraries[I - 1].Library)};
2011 Metadata.push_back(llvm::MDNode::get(Context, Args));
2017 llvm::Metadata *Args[2] = {
2018 llvm::MDString::get(Context,
"lib"),
2019 llvm::MDString::get(Context, Mod->
LinkLibraries[I - 1].Library),
2021 Metadata.push_back(llvm::MDNode::get(Context, Args));
2026 auto *OptString = llvm::MDString::get(Context, Opt);
2027 Metadata.push_back(llvm::MDNode::get(Context, OptString));
2032 void CodeGenModule::EmitModuleLinkOptions() {
2036 llvm::SetVector<clang::Module *> LinkModules;
2037 llvm::SmallPtrSet<clang::Module *, 16> Visited;
2041 for (
Module *M : ImportedModules) {
2047 if (Visited.insert(M).second)
2053 while (!Stack.empty()) {
2056 bool AnyChildren =
false;
2065 if (Visited.insert(
SM).second) {
2066 Stack.push_back(
SM);
2074 LinkModules.insert(Mod);
2083 for (
Module *M : LinkModules)
2084 if (Visited.insert(M).second)
2086 std::reverse(MetadataArgs.begin(), MetadataArgs.end());
2087 LinkerOptionsMetadata.append(MetadataArgs.begin(), MetadataArgs.end());
2090 auto *NMD =
getModule().getOrInsertNamedMetadata(
"llvm.linker.options");
2091 for (
auto *MD : LinkerOptionsMetadata)
2092 NMD->addOperand(MD);
2095 void CodeGenModule::EmitDeferred() {
2104 if (!DeferredVTables.empty()) {
2105 EmitDeferredVTables();
2110 assert(DeferredVTables.empty());
2114 if (DeferredDeclsToEmit.empty())
2119 std::vector<GlobalDecl> CurDeclsToEmit;
2120 CurDeclsToEmit.swap(DeferredDeclsToEmit);
2127 llvm::GlobalValue *GV = dyn_cast<llvm::GlobalValue>(
2145 if (!GV->isDeclaration())
2149 if (LangOpts.OpenMP && OpenMPRuntime && OpenMPRuntime->emitTargetGlobal(D))
2153 EmitGlobalDefinition(D, GV);
2158 if (!DeferredVTables.empty() || !DeferredDeclsToEmit.empty()) {
2160 assert(DeferredVTables.empty() && DeferredDeclsToEmit.empty());
2165 void CodeGenModule::EmitVTablesOpportunistically() {
2171 assert((OpportunisticVTables.empty() || shouldOpportunisticallyEmitVTables())
2172 &&
"Only emit opportunistic vtables with optimizations");
2176 "This queue should only contain external vtables");
2177 if (
getCXXABI().canSpeculativelyEmitVTable(RD))
2180 OpportunisticVTables.clear();
2184 if (Annotations.empty())
2188 llvm::Constant *Array = llvm::ConstantArray::get(llvm::ArrayType::get(
2189 Annotations[0]->getType(), Annotations.size()), Annotations);
2190 auto *gv =
new llvm::GlobalVariable(
getModule(), Array->getType(),
false,
2191 llvm::GlobalValue::AppendingLinkage,
2192 Array,
"llvm.global.annotations");
2193 gv->setSection(AnnotationSection);
2197 llvm::Constant *&AStr = AnnotationStrings[Str];
2202 llvm::Constant *s = llvm::ConstantDataArray::getString(
getLLVMContext(), Str);
2204 new llvm::GlobalVariable(
getModule(), s->getType(),
true,
2205 llvm::GlobalValue::PrivateLinkage, s,
".str");
2206 gv->setSection(AnnotationSection);
2207 gv->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
2225 return llvm::ConstantInt::get(
Int32Ty, LineNo);
2229 const AnnotateAttr *AA,
2236 llvm::Constant *ASZeroGV = GV;
2237 if (GV->getAddressSpace() != 0) {
2238 ASZeroGV = llvm::ConstantExpr::getAddrSpaceCast(
2239 GV, GV->getValueType()->getPointerTo(0));
2243 llvm::Constant *Fields[4] = {
2244 llvm::ConstantExpr::getBitCast(ASZeroGV,
Int8PtrTy),
2245 llvm::ConstantExpr::getBitCast(AnnoGV,
Int8PtrTy),
2246 llvm::ConstantExpr::getBitCast(UnitGV,
Int8PtrTy),
2249 return llvm::ConstantStruct::getAnon(Fields);
2253 llvm::GlobalValue *GV) {
2254 assert(D->
hasAttr<AnnotateAttr>() &&
"no annotate attribute");
2265 if (SanitizerBL.isBlacklistedFunction(Kind, Fn->getName()))
2274 return SanitizerBL.isBlacklistedFile(Kind, MainFile->getName());
2285 (SanitizerKind::Address | SanitizerKind::KernelAddress |
2286 SanitizerKind::HWAddress | SanitizerKind::KernelHWAddress |
2287 SanitizerKind::MemTag);
2288 if (!EnabledAsanMask)
2291 if (SanitizerBL.isBlacklistedGlobal(EnabledAsanMask, GV->getName(),
Category))
2293 if (SanitizerBL.isBlacklistedLocation(EnabledAsanMask, Loc, Category))
2299 while (
auto AT = dyn_cast<ArrayType>(Ty.
getTypePtr()))
2300 Ty = AT->getElementType();
2305 if (SanitizerBL.isBlacklistedType(EnabledAsanMask, TypeStr, Category))
2316 auto Attr = ImbueAttr::NONE;
2318 Attr = XRayFilter.shouldImbueLocation(Loc, Category);
2319 if (
Attr == ImbueAttr::NONE)
2320 Attr = XRayFilter.shouldImbueFunction(Fn->getName());
2322 case ImbueAttr::NONE:
2324 case ImbueAttr::ALWAYS:
2325 Fn->addFnAttr(
"function-instrument",
"xray-always");
2327 case ImbueAttr::ALWAYS_ARG1:
2328 Fn->addFnAttr(
"function-instrument",
"xray-always");
2329 Fn->addFnAttr(
"xray-log-args",
"1");
2331 case ImbueAttr::NEVER:
2332 Fn->addFnAttr(
"function-instrument",
"xray-never");
2338 bool CodeGenModule::MustBeEmitted(
const ValueDecl *Global) {
2340 if (LangOpts.EmitAllDecls)
2343 if (CodeGenOpts.KeepStaticConsts) {
2344 const auto *VD = dyn_cast<
VarDecl>(Global);
2345 if (VD && VD->getType().isConstQualified() &&
2353 bool CodeGenModule::MayBeEmittedEagerly(
const ValueDecl *Global) {
2354 if (
const auto *FD = dyn_cast<FunctionDecl>(Global)) {
2362 if (LangOpts.OpenMP >= 50 && !LangOpts.OpenMPSimd &&
2363 !LangOpts.OpenMPIsDevice &&
2364 !OMPDeclareTargetDeclAttr::getDeviceType(FD) &&
2368 if (
const auto *VD = dyn_cast<VarDecl>(Global))
2376 if (LangOpts.OpenMP && LangOpts.OpenMPUseTLS &&
2379 !OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(Global))
2390 std::string Name =
"_GUID_" + Uuid.lower();
2391 std::replace(Name.begin(), Name.end(),
'-',
'_');
2397 if (llvm::GlobalVariable *GV =
getModule().getNamedGlobal(Name))
2400 llvm::Constant *Init = EmitUuidofInitializer(Uuid);
2401 assert(Init &&
"failed to initialize as constant");
2403 auto *GV =
new llvm::GlobalVariable(
2405 true, llvm::GlobalValue::LinkOnceODRLinkage, Init, Name);
2407 GV->setComdat(TheModule.getOrInsertComdat(GV->getName()));
2413 const AliasAttr *AA = VD->
getAttr<AliasAttr>();
2414 assert(AA &&
"No alias?");
2423 auto Ptr = llvm::ConstantExpr::getBitCast(Entry, DeclTy->getPointerTo(AS));
2427 llvm::Constant *Aliasee;
2428 if (isa<llvm::FunctionType>(DeclTy))
2429 Aliasee = GetOrCreateLLVMFunction(AA->getAliasee(),
DeclTy,
2433 Aliasee = GetOrCreateLLVMGlobal(AA->getAliasee(),
2434 llvm::PointerType::getUnqual(DeclTy),
2437 auto *F = cast<llvm::GlobalValue>(Aliasee);
2438 F->setLinkage(llvm::Function::ExternalWeakLinkage);
2439 WeakRefReferences.insert(F);
2445 const auto *Global = cast<ValueDecl>(GD.
getDecl());
2448 if (Global->
hasAttr<WeakRefAttr>())
2453 if (Global->
hasAttr<AliasAttr>())
2454 return EmitAliasDefinition(GD);
2457 if (Global->
hasAttr<IFuncAttr>())
2458 return emitIFuncDefinition(GD);
2461 if (Global->
hasAttr<CPUDispatchAttr>())
2462 return emitCPUDispatchDefinition(GD);
2465 if (LangOpts.CUDA) {
2466 if (LangOpts.CUDAIsDevice) {
2467 if (!Global->
hasAttr<CUDADeviceAttr>() &&
2468 !Global->
hasAttr<CUDAGlobalAttr>() &&
2469 !Global->
hasAttr<CUDAConstantAttr>() &&
2470 !Global->
hasAttr<CUDASharedAttr>() &&
2471 !(LangOpts.HIP && Global->
hasAttr<HIPPinnedShadowAttr>()))
2480 if (isa<FunctionDecl>(Global) && !Global->
hasAttr<CUDAHostAttr>() &&
2481 Global->
hasAttr<CUDADeviceAttr>())
2484 assert((isa<FunctionDecl>(Global) || isa<VarDecl>(Global)) &&
2485 "Expected Variable or Function");
2489 if (LangOpts.OpenMP) {
2491 if (OpenMPRuntime && OpenMPRuntime->emitTargetGlobal(GD))
2493 if (
auto *DRD = dyn_cast<OMPDeclareReductionDecl>(Global)) {
2494 if (MustBeEmitted(Global))
2497 }
else if (
auto *DMD = dyn_cast<OMPDeclareMapperDecl>(Global)) {
2498 if (MustBeEmitted(Global))
2505 if (
const auto *FD = dyn_cast<FunctionDecl>(Global)) {
2517 GetOrCreateLLVMFunction(MangledName, Ty, GD,
false,
2522 const auto *VD = cast<VarDecl>(Global);
2523 assert(VD->isFileVarDecl() &&
"Cannot emit local var decl as global.");
2526 if (LangOpts.OpenMP) {
2529 OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(VD)) {
2530 bool UnifiedMemoryEnabled =
2532 if (*Res == OMPDeclareTargetDeclAttr::MT_To &&
2533 !UnifiedMemoryEnabled) {
2536 assert(((*Res == OMPDeclareTargetDeclAttr::MT_Link) ||
2537 (*Res == OMPDeclareTargetDeclAttr::MT_To &&
2538 UnifiedMemoryEnabled)) &&
2539 "Link clause or to clause with unified memory expected.");
2558 if (MustBeEmitted(Global) && MayBeEmittedEagerly(Global)) {
2560 EmitGlobalDefinition(GD);
2565 if (LangOpts.OpenMP && isa<FunctionDecl>(Global) && OpenMPRuntime &&
2566 OpenMPRuntime->emitDeclareVariant(GD,
false))
2571 if (
getLangOpts().CPlusPlus && isa<VarDecl>(Global) &&
2572 cast<VarDecl>(Global)->hasInit()) {
2573 DelayedCXXInitPosition[Global] = CXXGlobalInits.size();
2574 CXXGlobalInits.push_back(
nullptr);
2580 addDeferredDeclToEmit(GD);
2581 }
else if (MustBeEmitted(Global)) {
2583 assert(!MayBeEmittedEagerly(Global));
2584 addDeferredDeclToEmit(GD);
2589 DeferredDecls[MangledName] = GD;
2596 if (
CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(RT->getDecl()))
2597 if (RD->getDestructor() && !RD->getDestructor()->hasAttr<DLLImportAttr>())
2604 struct FunctionIsDirectlyRecursive
2606 const StringRef Name;
2611 bool VisitCallExpr(
const CallExpr *E) {
2616 if (Attr && Name == Attr->getLabel())
2621 StringRef BuiltinName = BI.
getName(BuiltinID);
2622 if (BuiltinName.startswith(
"__builtin_") &&
2623 Name == BuiltinName.slice(strlen(
"__builtin_"), StringRef::npos)) {
2629 bool VisitStmt(
const Stmt *S) {
2631 if (Child && this->Visit(Child))
2638 struct DLLImportFunctionVisitor
2640 bool SafeToInline =
true;
2642 bool shouldVisitImplicitCode()
const {
return true; }
2644 bool VisitVarDecl(
VarDecl *VD) {
2647 SafeToInline =
false;
2648 return SafeToInline;
2655 return SafeToInline;
2660 SafeToInline = D->hasAttr<DLLImportAttr>();
2661 return SafeToInline;
2666 if (isa<FunctionDecl>(VD))
2667 SafeToInline = VD->
hasAttr<DLLImportAttr>();
2668 else if (
VarDecl *
V = dyn_cast<VarDecl>(VD))
2669 SafeToInline = !
V->hasGlobalStorage() ||
V->hasAttr<DLLImportAttr>();
2670 return SafeToInline;
2675 return SafeToInline;
2682 SafeToInline =
true;
2684 SafeToInline = M->
hasAttr<DLLImportAttr>();
2686 return SafeToInline;
2691 return SafeToInline;
2696 return SafeToInline;
2705 CodeGenModule::isTriviallyRecursive(
const FunctionDecl *FD) {
2707 if (
getCXXABI().getMangleContext().shouldMangleDeclName(FD)) {
2712 Name = Attr->getLabel();
2717 FunctionIsDirectlyRecursive Walker(Name, Context.
BuiltinInfo);
2719 return Body ? Walker.Visit(Body) :
false;
2722 bool CodeGenModule::shouldEmitFunction(
GlobalDecl GD) {
2725 const auto *F = cast<FunctionDecl>(GD.
getDecl());
2726 if (CodeGenOpts.OptimizationLevel == 0 && !F->hasAttr<AlwaysInlineAttr>())
2729 if (F->hasAttr<DLLImportAttr>()) {
2731 DLLImportFunctionVisitor Visitor;
2732 Visitor.TraverseFunctionDecl(const_cast<FunctionDecl*>(F));
2733 if (!Visitor.SafeToInline)
2739 for (
const Decl *Member : Dtor->getParent()->decls())
2740 if (isa<FieldDecl>(Member))
2754 return !isTriviallyRecursive(F);
2757 bool CodeGenModule::shouldOpportunisticallyEmitVTables() {
2758 return CodeGenOpts.OptimizationLevel > 0;
2761 void CodeGenModule::EmitMultiVersionFunctionDefinition(
GlobalDecl GD,
2762 llvm::GlobalValue *GV) {
2763 const auto *FD = cast<FunctionDecl>(GD.
getDecl());
2766 auto *Spec = FD->
getAttr<CPUSpecificAttr>();
2767 for (
unsigned I = 0; I < Spec->cpus_size(); ++I)
2771 EmitGlobalFunctionDefinition(GD, GV);
2777 OpenMPRuntime &&
"Expected OpenMP device mode.");
2778 const auto *D = cast<FunctionDecl>(OldGD.
getDecl());
2785 if (!GV || (GV->getType()->getElementType() != Ty)) {
2786 GV = cast<llvm::GlobalValue>(GetOrCreateLLVMFunction(
2788 true,
false, llvm::AttributeList(),
2790 SetFunctionAttributes(OldGD, cast<llvm::Function>(GV),
2798 auto *Fn = cast<llvm::Function>(GV);
2811 setNonAliasAttributes(OldGD, Fn);
2814 if (D->hasAttr<AnnotateAttr>())
2818 void CodeGenModule::EmitGlobalDefinition(
GlobalDecl GD, llvm::GlobalValue *GV) {
2819 const auto *D = cast<ValueDecl>(GD.
getDecl());
2823 "Generating code for declaration");
2825 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
2828 if (!shouldEmitFunction(GD))
2831 llvm::TimeTraceScope TimeScope(
"CodeGen Function", [&]() {
2833 llvm::raw_string_ostream OS(Name);
2839 if (
const auto *Method = dyn_cast<CXXMethodDecl>(D)) {
2842 if (isa<CXXConstructorDecl>(Method) || isa<CXXDestructorDecl>(Method))
2843 ABI->emitCXXStructor(GD);
2845 EmitMultiVersionFunctionDefinition(GD, GV);
2847 EmitGlobalFunctionDefinition(GD, GV);
2849 if (Method->isVirtual())
2856 return EmitMultiVersionFunctionDefinition(GD, GV);
2857 return EmitGlobalFunctionDefinition(GD, GV);
2860 if (
const auto *VD = dyn_cast<VarDecl>(D))
2861 return EmitGlobalVarDefinition(VD, !VD->hasDefinition());
2863 llvm_unreachable(
"Invalid argument to EmitGlobalDefinition()");
2867 llvm::Function *NewFn);
2872 unsigned Priority = 0;
2882 void CodeGenModule::emitMultiVersionFunctions() {
2894 EmitGlobalFunctionDefinition(CurGD,
nullptr);
2903 assert(Func &&
"This should have just been created");
2906 const auto *TA = CurFD->
getAttr<TargetAttr>();
2908 TA->getAddedFeatures(Feats);
2910 Options.emplace_back(cast<llvm::Function>(Func),
2911 TA->getArchitecture(), Feats);
2914 llvm::Function *ResolverFunc;
2918 ResolverFunc = cast<llvm::Function>(
2920 ResolverFunc->setLinkage(llvm::Function::WeakODRLinkage);
2926 ResolverFunc->setComdat(
2927 getModule().getOrInsertComdat(ResolverFunc->getName()));
2935 CGF.EmitMultiVersionResolver(ResolverFunc, Options);
2939 void CodeGenModule::emitCPUDispatchDefinition(
GlobalDecl GD) {
2940 const auto *FD = cast<FunctionDecl>(GD.
getDecl());
2941 assert(FD &&
"Not a FunctionDecl?");
2942 const auto *DD = FD->
getAttr<CPUDispatchAttr>();
2943 assert(DD &&
"Not a cpu_dispatch Function?");
2946 if (
const auto *CXXFD = dyn_cast<CXXMethodDecl>(FD)) {
2956 ResolverType = llvm::FunctionType::get(
2957 llvm::PointerType::get(DeclTy,
2965 auto *ResolverFunc = cast<llvm::Function>(GetOrCreateLLVMFunction(
2966 ResolverName, ResolverType, ResolverGD,
false));
2967 ResolverFunc->setLinkage(llvm::Function::WeakODRLinkage);
2969 ResolverFunc->setComdat(
2970 getModule().getOrInsertComdat(ResolverFunc->getName()));
2983 GlobalDecl ExistingDecl = Manglings.lookup(MangledName);
2986 EmitGlobalFunctionDefinition(ExistingDecl,
nullptr);
2992 Func = GetOrCreateLLVMFunction(
2993 MangledName, DeclTy, ExistingDecl,
3001 llvm::transform(Features, Features.begin(),
3002 [](StringRef Str) {
return Str.substr(1); });
3003 Features.erase(std::remove_if(
3004 Features.begin(), Features.end(), [&Target](StringRef Feat) {
3006 }), Features.end());
3007 Options.emplace_back(cast<llvm::Function>(Func), StringRef{}, Features);
3022 while (Options.size() > 1 &&
3024 (Options.end() - 2)->Conditions.Features) == 0) {
3025 StringRef LHSName = (Options.end() - 2)->Function->getName();
3026 StringRef RHSName = (Options.end() - 1)->Function->getName();
3027 if (LHSName.compare(RHSName) < 0)
3028 Options.erase(Options.end() - 2);
3030 Options.erase(Options.end() - 1);
3038 *
this, GD, FD,
true);
3041 auto *IFunc = cast<llvm::GlobalIFunc>(GetOrCreateLLVMFunction(
3042 AliasName, DeclTy, GD,
false,
true,
3046 GA->setLinkage(llvm::Function::WeakODRLinkage);
3054 llvm::Constant *CodeGenModule::GetOrCreateMultiVersionResolver(
3056 std::string MangledName =
3061 std::string ResolverName = MangledName;
3063 ResolverName +=
".ifunc";
3065 ResolverName +=
".resolver";
3068 if (llvm::GlobalValue *ResolverGV =
GetGlobalValue(ResolverName))
3075 MultiVersionFuncs.push_back(GD);
3078 llvm::Type *ResolverType = llvm::FunctionType::get(
3079 llvm::PointerType::get(
3082 llvm::Constant *Resolver = GetOrCreateLLVMFunction(
3083 MangledName +
".resolver", ResolverType,
GlobalDecl{},
3086 DeclTy, 0, llvm::Function::WeakODRLinkage,
"", Resolver, &
getModule());
3087 GIF->setName(ResolverName);
3093 llvm::Constant *Resolver = GetOrCreateLLVMFunction(
3095 assert(isa<llvm::GlobalValue>(Resolver) &&
3096 "Resolver should be created for the first time");
3108 llvm::Constant *CodeGenModule::GetOrCreateLLVMFunction(
3110 bool DontDefer,
bool IsThunk, llvm::AttributeList ExtraAttrs,
3116 if (
const FunctionDecl *FD = cast_or_null<FunctionDecl>(D)) {
3118 if (
getLangOpts().OpenMPIsDevice && OpenMPRuntime &&
3119 !OpenMPRuntime->markAsGlobalTarget(GD) && FD->
isDefined() &&
3120 !DontDefer && !IsForDefinition) {
3123 if (
const auto *CD = dyn_cast<CXXConstructorDecl>(FDDef))
3125 else if (
const auto *DD = dyn_cast<CXXDestructorDecl>(FDDef))
3134 if (LangOpts.OpenMP && OpenMPRuntime)
3135 (void)OpenMPRuntime->emitDeclareVariant(GD,
true);
3138 const auto *TA = FD->
getAttr<TargetAttr>();
3139 if (TA && TA->isDefaultVersion())
3140 UpdateMultiVersionNames(GD, FD);
3141 if (!IsForDefinition)
3142 return GetOrCreateMultiVersionResolver(GD, Ty, FD);
3149 if (WeakRefReferences.erase(Entry)) {
3150 const FunctionDecl *FD = cast_or_null<FunctionDecl>(D);
3151 if (FD && !FD->
hasAttr<WeakAttr>())
3156 if (D && !D->
hasAttr<DLLImportAttr>() && !D->
hasAttr<DLLExportAttr>()) {
3157 Entry->setDLLStorageClass(llvm::GlobalValue::DefaultStorageClass);
3163 if (IsForDefinition && !Entry->isDeclaration()) {
3170 DiagnosedConflictingDefinitions.insert(GD).second) {
3174 diag::note_previous_definition);
3178 if ((isa<llvm::Function>(Entry) || isa<llvm::GlobalAlias>(Entry)) &&
3179 (Entry->getType()->getElementType() == Ty)) {
3186 if (!IsForDefinition)
3187 return llvm::ConstantExpr::getBitCast(Entry, Ty->getPointerTo());
3193 bool IsIncompleteFunction =
false;
3195 llvm::FunctionType *FTy;
3196 if (isa<llvm::FunctionType>(Ty)) {
3197 FTy = cast<llvm::FunctionType>(Ty);
3199 FTy = llvm::FunctionType::get(
VoidTy,
false);
3200 IsIncompleteFunction =
true;
3205 Entry ? StringRef() : MangledName, &
getModule());
3222 if (!Entry->use_empty()) {
3224 Entry->removeDeadConstantUsers();
3227 llvm::Constant *BC = llvm::ConstantExpr::getBitCast(
3228 F, Entry->getType()->getElementType()->getPointerTo());
3232 assert(F->getName() == MangledName &&
"name was uniqued!");
3234 SetFunctionAttributes(GD, F, IsIncompleteFunction, IsThunk);
3235 if (ExtraAttrs.hasAttributes(llvm::AttributeList::FunctionIndex)) {
3236 llvm::AttrBuilder B(ExtraAttrs, llvm::AttributeList::FunctionIndex);
3237 F->addAttributes(llvm::AttributeList::FunctionIndex, B);
3244 if (D && isa<CXXDestructorDecl>(D) &&
3245 getCXXABI().useThunkForDtorVariant(cast<CXXDestructorDecl>(D),
3247 addDeferredDeclToEmit(GD);
3252 auto DDI = DeferredDecls.find(MangledName);
3253 if (DDI != DeferredDecls.end()) {
3257 addDeferredDeclToEmit(DDI->second);
3258 DeferredDecls.erase(DDI);
3273 for (
const auto *FD = cast<FunctionDecl>(D)->getMostRecentDecl(); FD;
3286 if (!IsIncompleteFunction) {
3287 assert(F->getType()->getElementType() == Ty);
3291 llvm::Type *PTy = llvm::PointerType::getUnqual(Ty);
3292 return llvm::ConstantExpr::getBitCast(F, PTy);
3305 const auto *FD = cast<FunctionDecl>(GD.
getDecl());
3312 if (
const auto *DD = dyn_cast<CXXDestructorDecl>(GD.
getDecl())) {
3315 DD->getParent()->getNumVBases() == 0)
3320 return GetOrCreateLLVMFunction(MangledName, Ty, GD, ForVTable, DontDefer,
3321 false, llvm::AttributeList(),
3331 for (
const auto &Result : DC->
lookup(&CII))
3332 if (
const auto FD = dyn_cast<FunctionDecl>(Result))
3340 (Name ==
"_ZSt9terminatev" || Name ==
"?terminate@@YAXXZ")
3344 for (
const auto &N : {
"__cxxabiv1",
"std"}) {
3346 for (
const auto &Result : DC->
lookup(&NS)) {
3348 if (
auto LSD = dyn_cast<LinkageSpecDecl>(Result))
3349 for (
const auto &Result : LSD->lookup(&NS))
3350 if ((ND = dyn_cast<NamespaceDecl>(Result)))
3354 for (
const auto &Result : ND->
lookup(&CXXII))
3355 if (
const auto *FD = dyn_cast<FunctionDecl>(Result))
3365 llvm::FunctionCallee
3367 llvm::AttributeList ExtraAttrs,
bool Local,
3368 bool AssumeConvergent) {
3369 if (AssumeConvergent) {
3371 ExtraAttrs.addAttribute(VMContext, llvm::AttributeList::FunctionIndex,
3372 llvm::Attribute::Convergent);
3376 GetOrCreateLLVMFunction(Name, FTy,
GlobalDecl(),
false,
3380 if (
auto *F = dyn_cast<llvm::Function>(C)) {
3389 if (!Local &&
getTriple().isWindowsItaniumEnvironment() &&
3392 if (!FD || FD->
hasAttr<DLLImportAttr>()) {
3393 F->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass);
3417 return ExcludeCtor && !Record->hasMutableFields() &&
3418 Record->hasTrivialDestructor();
3436 CodeGenModule::GetOrCreateLLVMGlobal(StringRef MangledName,
3437 llvm::PointerType *Ty,
3443 if (WeakRefReferences.erase(Entry)) {
3444 if (D && !D->
hasAttr<WeakAttr>())
3449 if (D && !D->
hasAttr<DLLImportAttr>() && !D->
hasAttr<DLLExportAttr>())
3450 Entry->setDLLStorageClass(llvm::GlobalValue::DefaultStorageClass);
3452 if (LangOpts.OpenMP && !LangOpts.OpenMPSimd && D)
3455 if (Entry->getType() == Ty)
3460 if (IsForDefinition && !Entry->isDeclaration()) {
3468 (OtherD = dyn_cast<VarDecl>(OtherGD.
getDecl())) &&
3470 DiagnosedConflictingDefinitions.insert(D).second) {
3474 diag::note_previous_definition);
3479 if (Entry->getType()->getAddressSpace() != Ty->getAddressSpace())
3480 return llvm::ConstantExpr::getAddrSpaceCast(Entry, Ty);
3484 if (!IsForDefinition)
3485 return llvm::ConstantExpr::getBitCast(Entry, Ty);
3491 auto *GV =
new llvm::GlobalVariable(
3492 getModule(), Ty->getElementType(),
false,
3494 llvm::GlobalVariable::NotThreadLocal, TargetAddrSpace);
3499 GV->takeName(Entry);
3501 if (!Entry->use_empty()) {
3502 llvm::Constant *NewPtrForOldDecl =
3503 llvm::ConstantExpr::getBitCast(GV, Entry->getType());
3504 Entry->replaceAllUsesWith(NewPtrForOldDecl);
3507 Entry->eraseFromParent();
3513 auto DDI = DeferredDecls.find(MangledName);
3514 if (DDI != DeferredDecls.end()) {
3517 addDeferredDeclToEmit(DDI->second);
3518 DeferredDecls.erase(DDI);
3523 if (LangOpts.OpenMP && !LangOpts.OpenMPSimd)
3536 CXXThreadLocals.push_back(D);
3544 if (
getContext().isMSStaticDataMemberInlineDefinition(D)) {
3545 EmitGlobalVarDefinition(D);
3550 if (
const SectionAttr *SA = D->
getAttr<SectionAttr>())
3551 GV->setSection(SA->getName());
3555 if (
getTriple().getArch() == llvm::Triple::xcore &&
3559 GV->setSection(
".cp.rodata");
3564 if (Context.
getLangOpts().CPlusPlus && GV->hasExternalLinkage() &&
3567 const auto *Record =
3569 bool HasMutableFields = Record && Record->hasMutableFields();
3570 if (!HasMutableFields) {
3577 auto *InitType = Init->getType();
3578 if (GV->getType()->getElementType() != InitType) {
3583 GV->setName(StringRef());
3586 auto *NewGV = cast<llvm::GlobalVariable>(
3588 ->stripPointerCasts());
3591 GV->eraseFromParent();
3594 GV->setInitializer(Init);
3595 GV->setConstant(
true);
3596 GV->setLinkage(llvm::GlobalValue::AvailableExternallyLinkage);
3605 if (GV->isDeclaration())
3611 assert(
getContext().getTargetAddressSpace(ExpectedAS) ==
3612 Ty->getPointerAddressSpace());
3613 if (AddrSpace != ExpectedAS)
3624 if (isa<CXXConstructorDecl>(D) || isa<CXXDestructorDecl>(D))
3626 false, IsForDefinition);
3627 else if (isa<CXXMethodDecl>(D)) {
3629 cast<CXXMethodDecl>(D));
3633 }
else if (isa<FunctionDecl>(D)) {
3645 unsigned Alignment) {
3646 llvm::GlobalVariable *GV =
getModule().getNamedGlobal(Name);
3647 llvm::GlobalVariable *OldGV =
nullptr;
3651 if (GV->getType()->getElementType() == Ty)
3656 assert(GV->isDeclaration() &&
"Declaration has wrong type!");
3661 GV =
new llvm::GlobalVariable(
getModule(), Ty,
true,
3662 Linkage,
nullptr, Name);
3666 GV->takeName(OldGV);
3668 if (!OldGV->use_empty()) {
3669 llvm::Constant *NewPtrForOldDecl =
3670 llvm::ConstantExpr::getBitCast(GV, OldGV->getType());
3671 OldGV->replaceAllUsesWith(NewPtrForOldDecl);
3674 OldGV->eraseFromParent();
3678 !GV->hasAvailableExternallyLinkage())
3679 GV->setComdat(TheModule.getOrInsertComdat(GV->getName()));
3681 GV->setAlignment(llvm::MaybeAlign(Alignment));
3700 llvm::PointerType *PTy =
3701 llvm::PointerType::get(Ty,
getContext().getTargetAddressSpace(ASTTy));
3704 return GetOrCreateLLVMGlobal(MangledName, PTy, D, IsForDefinition);
3714 ? llvm::PointerType::get(
3716 : llvm::PointerType::getUnqual(Ty);
3717 auto *
Ret = GetOrCreateLLVMGlobal(Name, PtrTy,
nullptr);
3723 assert(!D->
getInit() &&
"Cannot emit definite definitions here!");
3731 if (GV && !GV->isDeclaration())
3736 if (!MustBeEmitted(D) && !GV) {
3737 DeferredDecls[MangledName] = D;
3742 EmitGlobalVarDefinition(D);
3746 EmitExternalVarDeclaration(D);
3756 if (LangOpts.OpenCL) {
3765 if (LangOpts.CUDA && LangOpts.CUDAIsDevice) {
3766 if (D && D->
hasAttr<CUDAConstantAttr>())
3768 else if (D && D->
hasAttr<CUDASharedAttr>())
3770 else if (D && D->
hasAttr<CUDADeviceAttr>())
3778 if (LangOpts.OpenMP) {
3780 if (OpenMPRuntime->hasAllocateAttributeForGlobalVar(D, AS))
3788 if (LangOpts.OpenCL)
3790 if (
auto AS =
getTarget().getConstantAddressSpace())
3791 return AS.getValue();
3803 static llvm::Constant *
3805 llvm::GlobalVariable *GV) {
3806 llvm::Constant *
Cast = GV;
3812 GV->getValueType()->getPointerTo(
3819 template<
typename SomeDecl>
3821 llvm::GlobalValue *GV) {
3827 if (!D->template hasAttr<UsedAttr>())
3836 const SomeDecl *
First = D->getFirstDecl();
3837 if (First->getDeclContext()->isRecord() || !First->isInExternCContext())
3843 std::pair<StaticExternCMap::iterator, bool> R =
3844 StaticExternCValues.insert(std::make_pair(D->getIdentifier(), GV));
3849 R.first->second =
nullptr;
3858 if (D.
hasAttr<CUDAGlobalAttr>())
3861 if (D.
hasAttr<SelectAnyAttr>())
3865 if (
auto *VD = dyn_cast<VarDecl>(&D))
3879 llvm_unreachable(
"No such linkage");
3883 llvm::GlobalObject &GO) {
3886 GO.setComdat(TheModule.getOrInsertComdat(GO.getName()));
3890 void CodeGenModule::EmitGlobalVarDefinition(
const VarDecl *D,
3900 if (LangOpts.OpenMPIsDevice && OpenMPRuntime &&
3901 OpenMPRuntime->emitTargetGlobalVariable(D))
3904 llvm::Constant *Init =
nullptr;
3905 bool NeedsGlobalCtor =
false;
3906 bool NeedsGlobalDtor =
3917 bool IsCUDASharedVar =
3921 bool IsCUDAShadowVar =
3923 (D->
hasAttr<CUDAConstantAttr>() || D->
hasAttr<CUDADeviceAttr>() ||
3924 D->
hasAttr<CUDASharedAttr>());
3927 bool IsHIPPinnedShadowVar =
3930 (IsCUDASharedVar || IsCUDAShadowVar || IsHIPPinnedShadowVar))
3931 Init = llvm::UndefValue::get(
getTypes().ConvertType(ASTTy));
3932 else if (!InitExpr) {
3946 emitter.emplace(*
this);
3947 Init = emitter->tryEmitForInitializer(*InitDecl);
3956 NeedsGlobalCtor =
true;
3959 Init = llvm::UndefValue::get(
getTypes().ConvertType(T));
3966 DelayedCXXInitPosition.erase(D);
3971 llvm::Constant *Entry =
3975 Entry = Entry->stripPointerCasts();
3978 auto *GV = dyn_cast<llvm::GlobalVariable>(Entry);
3989 if (!GV || GV->getType()->getElementType() != InitType ||
3990 GV->getType()->getAddressSpace() !=
3994 Entry->setName(StringRef());
3997 GV = cast<llvm::GlobalVariable>(
3999 ->stripPointerCasts());
4002 llvm::Constant *NewPtrForOldDecl =
4003 llvm::ConstantExpr::getBitCast(GV, Entry->getType());
4004 Entry->replaceAllUsesWith(NewPtrForOldDecl);
4007 cast<llvm::GlobalValue>(Entry)->eraseFromParent();
4012 if (D->
hasAttr<AnnotateAttr>())
4016 llvm::GlobalValue::LinkageTypes
Linkage =
4026 if (GV && LangOpts.CUDA) {
4027 if (LangOpts.CUDAIsDevice) {
4029 (D->
hasAttr<CUDADeviceAttr>() || D->
hasAttr<CUDAConstantAttr>()))
4030 GV->setExternallyInitialized(
true);
4036 if (D->
hasAttr<CUDADeviceAttr>() || D->
hasAttr<CUDAConstantAttr>() ||
4037 D->
hasAttr<HIPPinnedShadowAttr>()) {
4045 if (D->
hasAttr<CUDAConstantAttr>())
4051 }
else if (D->
hasAttr<CUDASharedAttr>())
4061 if (!IsHIPPinnedShadowVar)
4062 GV->setInitializer(Init);
4063 if (emitter) emitter->finalize(GV);
4066 GV->setConstant(!NeedsGlobalCtor && !NeedsGlobalDtor &&
4070 if (
const SectionAttr *SA = D->
getAttr<SectionAttr>()) {
4073 GV->setConstant(
true);
4087 !llvm::GlobalVariable::isLinkOnceLinkage(Linkage) &&
4088 !llvm::GlobalVariable::isWeakLinkage(Linkage))
4091 GV->setLinkage(Linkage);
4092 if (D->
hasAttr<DLLImportAttr>())
4093 GV->setDLLStorageClass(llvm::GlobalVariable::DLLImportStorageClass);
4094 else if (D->
hasAttr<DLLExportAttr>())
4095 GV->setDLLStorageClass(llvm::GlobalVariable::DLLExportStorageClass);
4097 GV->setDLLStorageClass(llvm::GlobalVariable::DefaultStorageClass);
4099 if (Linkage == llvm::GlobalVariable::CommonLinkage) {
4101 GV->setConstant(
false);
4106 if (!GV->getInitializer()->isNullValue())
4107 GV->setLinkage(llvm::GlobalVariable::WeakAnyLinkage);
4110 setNonAliasAttributes(D, GV);
4112 if (D->
getTLSKind() && !GV->isThreadLocal()) {
4114 CXXThreadLocals.push_back(D);
4121 if (NeedsGlobalCtor || NeedsGlobalDtor)
4122 EmitCXXGlobalVarDeclInitFunc(D, GV, NeedsGlobalCtor);
4124 SanitizerMD->reportGlobalToASan(GV, *D, NeedsGlobalCtor);
4129 DI->EmitGlobalVariable(GV, D);
4132 void CodeGenModule::EmitExternalVarDeclaration(
const VarDecl *D) {
4137 llvm::PointerType *PTy =
4138 llvm::PointerType::get(Ty,
getContext().getTargetAddressSpace(ASTTy));
4139 llvm::Constant *GV = GetOrCreateLLVMGlobal(D->
getName(), PTy, D);
4140 DI->EmitExternalVariable(
4141 cast<llvm::GlobalVariable>(GV->stripPointerCasts()), D);
4150 if ((NoCommon || D->
hasAttr<NoCommonAttr>()) && !D->
hasAttr<CommonAttr>())
4161 if (D->
hasAttr<SectionAttr>())
4167 if (D->
hasAttr<PragmaClangBSSSectionAttr>() ||
4168 D->
hasAttr<PragmaClangDataSectionAttr>() ||
4169 D->
hasAttr<PragmaClangRelroSectionAttr>() ||
4170 D->
hasAttr<PragmaClangRodataSectionAttr>())
4178 if (D->
hasAttr<WeakImportAttr>())
4188 if (D->
hasAttr<AlignedAttr>())
4197 if (FD->isBitField())
4199 if (FD->
hasAttr<AlignedAttr>())
4227 if (IsConstantVariable)
4228 return llvm::GlobalVariable::WeakODRLinkage;
4230 return llvm::GlobalVariable::WeakAnyLinkage;
4235 return llvm::GlobalVariable::LinkOnceAnyLinkage;
4240 return llvm::GlobalValue::AvailableExternallyLinkage;
4254 return !Context.
getLangOpts().AppleKext ? llvm::Function::LinkOnceODRLinkage
4271 return llvm::Function::WeakODRLinkage;
4276 if (!
getLangOpts().CPlusPlus && isa<VarDecl>(D) &&
4278 CodeGenOpts.NoCommon))
4279 return llvm::GlobalVariable::CommonLinkage;
4285 if (D->
hasAttr<SelectAnyAttr>())
4286 return llvm::GlobalVariable::WeakODRLinkage;
4294 const VarDecl *VD,
bool IsConstant) {
4302 llvm::Function *newFn) {
4304 if (old->use_empty())
return;
4306 llvm::Type *newRetTy = newFn->getReturnType();
4310 for (llvm::Value::use_iterator ui = old->use_begin(), ue = old->use_end();
4312 llvm::Value::use_iterator use = ui++;
4313 llvm::User *user = use->getUser();
4317 if (
auto *bitcast = dyn_cast<llvm::ConstantExpr>(user)) {
4318 if (bitcast->getOpcode() == llvm::Instruction::BitCast)
4324 llvm::CallBase *callSite = dyn_cast<llvm::CallBase>(user);
4325 if (!callSite)
continue;
4326 if (!callSite->isCallee(&*use))
4331 if (callSite->getType() != newRetTy && !callSite->use_empty())
4336 llvm::AttributeList oldAttrs = callSite->getAttributes();
4339 unsigned newNumArgs = newFn->arg_size();
4340 if (callSite->arg_size() < newNumArgs)
4346 bool dontTransform =
false;
4347 for (llvm::Argument &A : newFn->args()) {
4348 if (callSite->getArgOperand(argNo)->getType() != A.getType()) {
4349 dontTransform =
true;
4354 newArgAttrs.push_back(oldAttrs.getParamAttributes(argNo));
4362 newArgs.append(callSite->arg_begin(), callSite->arg_begin() + argNo);
4365 callSite->getOperandBundlesAsDefs(newBundles);
4367 llvm::CallBase *newCall;
4368 if (dyn_cast<llvm::CallInst>(callSite)) {
4372 auto *oldInvoke = cast<llvm::InvokeInst>(callSite);
4374 oldInvoke->getUnwindDest(), newArgs,
4375 newBundles,
"", callSite);
4379 if (!newCall->getType()->isVoidTy())
4380 newCall->takeName(callSite);
4381 newCall->setAttributes(llvm::AttributeList::get(
4382 newFn->getContext(), oldAttrs.getFnAttributes(),
4383 oldAttrs.getRetAttributes(), newArgAttrs));
4384 newCall->setCallingConv(callSite->getCallingConv());
4387 if (!callSite->use_empty())
4388 callSite->replaceAllUsesWith(newCall);
4391 if (callSite->getDebugLoc())
4392 newCall->setDebugLoc(callSite->getDebugLoc());
4394 callSite->eraseFromParent();
4408 llvm::Function *NewFn) {
4410 if (!isa<llvm::Function>(Old))
return;
4429 void CodeGenModule::EmitGlobalFunctionDefinition(
GlobalDecl GD,
4430 llvm::GlobalValue *GV) {
4432 if (LangOpts.OpenMP && OpenMPRuntime &&
4433 OpenMPRuntime->emitDeclareVariant(GD,
true))
4436 const auto *D = cast<FunctionDecl>(GD.
getDecl());
4443 if (!GV || (GV->getType()->getElementType() != Ty))
4449 if (!GV->isDeclaration())
4456 auto *Fn = cast<llvm::Function>(GV);
4469 setNonAliasAttributes(GD, Fn);
4472 if (
const ConstructorAttr *CA = D->
getAttr<ConstructorAttr>())
4473 AddGlobalCtor(Fn, CA->getPriority());
4474 if (
const DestructorAttr *DA = D->
getAttr<DestructorAttr>())
4475 AddGlobalDtor(Fn, DA->getPriority());
4476 if (D->
hasAttr<AnnotateAttr>())
4480 void CodeGenModule::EmitAliasDefinition(
GlobalDecl GD) {
4481 const auto *D = cast<ValueDecl>(GD.
getDecl());
4482 const AliasAttr *AA = D->
getAttr<AliasAttr>();
4483 assert(AA &&
"Not an alias?");
4487 if (AA->getAliasee() == MangledName) {
4488 Diags.Report(AA->getLocation(), diag::err_cyclic_alias) << 0;
4495 if (Entry && !Entry->isDeclaration())
4498 Aliases.push_back(GD);
4504 llvm::Constant *Aliasee;
4505 llvm::GlobalValue::LinkageTypes
LT;
4506 if (isa<llvm::FunctionType>(DeclTy)) {
4507 Aliasee = GetOrCreateLLVMFunction(AA->getAliasee(),
DeclTy, GD,
4511 Aliasee = GetOrCreateLLVMGlobal(AA->getAliasee(),
4512 llvm::PointerType::getUnqual(DeclTy),
4523 if (GA->getAliasee() == Entry) {
4524 Diags.Report(AA->getLocation(), diag::err_cyclic_alias) << 0;
4528 assert(Entry->isDeclaration());
4537 GA->takeName(Entry);
4539 Entry->replaceAllUsesWith(llvm::ConstantExpr::getBitCast(GA,
4541 Entry->eraseFromParent();
4543 GA->setName(MangledName);
4551 GA->setLinkage(llvm::Function::WeakAnyLinkage);
4554 if (
const auto *VD = dyn_cast<VarDecl>(D))
4555 if (VD->getTLSKind())
4561 void CodeGenModule::emitIFuncDefinition(
GlobalDecl GD) {
4562 const auto *D = cast<ValueDecl>(GD.
getDecl());
4563 const IFuncAttr *IFA = D->
getAttr<IFuncAttr>();
4564 assert(IFA &&
"Not an ifunc?");
4568 if (IFA->getResolver() == MangledName) {
4569 Diags.Report(IFA->getLocation(), diag::err_cyclic_alias) << 1;
4575 if (Entry && !Entry->isDeclaration()) {
4578 DiagnosedConflictingDefinitions.insert(GD).second) {
4579 Diags.Report(D->
getLocation(), diag::err_duplicate_mangled_name)
4582 diag::note_previous_definition);
4587 Aliases.push_back(GD);
4590 llvm::Constant *Resolver =
4591 GetOrCreateLLVMFunction(IFA->getResolver(),
DeclTy, GD,
4593 llvm::GlobalIFunc *GIF =
4597 if (GIF->getResolver() == Entry) {
4598 Diags.Report(IFA->getLocation(), diag::err_cyclic_alias) << 1;
4601 assert(Entry->isDeclaration());
4610 GIF->takeName(Entry);
4612 Entry->replaceAllUsesWith(llvm::ConstantExpr::getBitCast(GIF,
4614 Entry->eraseFromParent();
4616 GIF->setName(MangledName);
4627 static llvm::StringMapEntry<llvm::GlobalVariable *> &
4630 bool &IsUTF16,
unsigned &StringLength) {
4631 StringRef String = Literal->
getString();
4632 unsigned NumBytes = String.size();
4636 StringLength = NumBytes;
4637 return *Map.insert(std::make_pair(String,
nullptr)).first;
4644 const llvm::UTF8 *FromPtr = (
const llvm::UTF8 *)String.data();
4645 llvm::UTF16 *ToPtr = &ToBuf[0];
4647 (void)llvm::ConvertUTF8toUTF16(&FromPtr, FromPtr + NumBytes, &ToPtr,
4648 ToPtr + NumBytes, llvm::strictConversion);
4651 StringLength = ToPtr - &ToBuf[0];
4655 return *Map.insert(std::make_pair(
4656 StringRef(reinterpret_cast<const char *>(ToBuf.data()),
4657 (StringLength + 1) * 2),
4663 unsigned StringLength = 0;
4664 bool isUTF16 =
false;
4665 llvm::StringMapEntry<llvm::GlobalVariable *> &Entry =
4670 if (
auto *C = Entry.second)
4673 llvm::Constant *
Zero = llvm::Constant::getNullValue(
Int32Ty);
4674 llvm::Constant *Zeros[] = {
Zero, Zero };
4677 const llvm::Triple &Triple =
getTriple();
4680 const bool IsSwiftABI =
4681 static_cast<unsigned>(CFRuntime) >=
4686 if (!CFConstantStringClassRef) {
4687 const char *CFConstantStringClassName =
"__CFConstantStringClassReference";
4689 Ty = llvm::ArrayType::get(Ty, 0);
4691 switch (CFRuntime) {
4695 CFConstantStringClassName =
4696 Triple.isOSDarwin() ?
"$s15SwiftFoundation19_NSCFConstantStringCN" 4697 :
"$s10Foundation19_NSCFConstantStringCN";
4701 CFConstantStringClassName =
4702 Triple.isOSDarwin() ?
"$S15SwiftFoundation19_NSCFConstantStringCN" 4703 :
"$S10Foundation19_NSCFConstantStringCN";
4707 CFConstantStringClassName =
4708 Triple.isOSDarwin() ?
"__T015SwiftFoundation19_NSCFConstantStringCN" 4709 :
"__T010Foundation19_NSCFConstantStringCN";
4716 if (Triple.isOSBinFormatELF() || Triple.isOSBinFormatCOFF()) {
4717 llvm::GlobalValue *GV =
nullptr;
4719 if ((GV = dyn_cast<llvm::GlobalValue>(C))) {
4725 for (
const auto &Result : DC->
lookup(&II))
4726 if ((VD = dyn_cast<VarDecl>(Result)))
4729 if (Triple.isOSBinFormatELF()) {
4734 if (!VD || !VD->
hasAttr<DLLExportAttr>())
4735 GV->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass);
4737 GV->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass);
4745 CFConstantStringClassRef =
4746 IsSwiftABI ? llvm::ConstantExpr::getPtrToInt(C, Ty)
4747 : llvm::ConstantExpr::getGetElementPtr(Ty, C, Zeros);
4755 auto Fields = Builder.beginStruct(STy);
4758 Fields.add(cast<llvm::ConstantExpr>(CFConstantStringClassRef));
4762 Fields.addInt(
IntPtrTy, IsSwift4_1 ? 0x05 : 0x01);
4763 Fields.addInt(
Int64Ty, isUTF16 ? 0x07d0 : 0x07c8);
4765 Fields.addInt(
IntTy, isUTF16 ? 0x07d0 : 0x07C8);
4769 llvm::Constant *C =
nullptr;
4771 auto Arr = llvm::makeArrayRef(
4772 reinterpret_cast<uint16_t *>(const_cast<char *>(Entry.first().data())),
4773 Entry.first().size() / 2);
4774 C = llvm::ConstantDataArray::get(VMContext, Arr);
4776 C = llvm::ConstantDataArray::getString(VMContext, Entry.first());
4782 new llvm::GlobalVariable(
getModule(), C->getType(),
true,
4783 llvm::GlobalValue::PrivateLinkage, C,
".str");
4784 GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
4794 if (Triple.isOSBinFormatMachO())
4795 GV->setSection(isUTF16 ?
"__TEXT,__ustring" 4796 :
"__TEXT,__cstring,cstring_literals");
4799 else if (Triple.isOSBinFormatELF())
4800 GV->setSection(
".rodata");
4803 llvm::Constant *Str =
4804 llvm::ConstantExpr::getGetElementPtr(GV->getValueType(), GV, Zeros);
4808 Str = llvm::ConstantExpr::getBitCast(Str,
Int8PtrTy);
4812 llvm::IntegerType *LengthTy =
4822 Fields.addInt(LengthTy, StringLength);
4830 GV = Fields.finishAndCreateGlobal(
"_unnamed_cfstring_", Alignment,
4832 llvm::GlobalVariable::PrivateLinkage);
4833 GV->addAttribute(
"objc_arc_inert");
4834 switch (Triple.getObjectFormat()) {
4835 case llvm::Triple::UnknownObjectFormat:
4836 llvm_unreachable(
"unknown file format");
4837 case llvm::Triple::XCOFF:
4838 llvm_unreachable(
"XCOFF is not yet implemented");
4839 case llvm::Triple::COFF:
4840 case llvm::Triple::ELF:
4841 case llvm::Triple::Wasm:
4842 GV->setSection(
"cfstring");
4844 case llvm::Triple::MachO:
4845 GV->setSection(
"__DATA,__cfstring");
4854 return !CodeGenOpts.EmitCodeView || CodeGenOpts.DebugColumnInfo;
4858 if (ObjCFastEnumerationStateType.isNull()) {
4870 for (
size_t i = 0; i < 4; ++i) {
4875 FieldTypes[i],
nullptr,
4887 return ObjCFastEnumerationStateType;
4901 Str.resize(CAT->getSize().getZExtValue());
4902 return llvm::ConstantDataArray::getString(VMContext, Str,
false);
4906 llvm::Type *ElemTy = AType->getElementType();
4907 unsigned NumElements = AType->getNumElements();
4910 if (ElemTy->getPrimitiveSizeInBits() == 16) {
4912 Elements.reserve(NumElements);
4914 for(
unsigned i = 0, e = E->
getLength(); i != e; ++i)
4916 Elements.resize(NumElements);
4917 return llvm::ConstantDataArray::get(VMContext, Elements);
4920 assert(ElemTy->getPrimitiveSizeInBits() == 32);
4922 Elements.reserve(NumElements);
4924 for(
unsigned i = 0, e = E->
getLength(); i != e; ++i)
4926 Elements.resize(NumElements);
4927 return llvm::ConstantDataArray::get(VMContext, Elements);
4930 static llvm::GlobalVariable *
4939 auto *GV =
new llvm::GlobalVariable(
4940 M, C->getType(), !CGM.
getLangOpts().WritableStrings,
LT, C, GlobalName,
4941 nullptr, llvm::GlobalVariable::NotThreadLocal, AddrSpace);
4943 GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
4944 if (GV->isWeakForLinker()) {
4945 assert(CGM.
supportsCOMDAT() &&
"Only COFF uses weak string literals");
4946 GV->setComdat(M.getOrInsertComdat(GV->getName()));
4961 llvm::GlobalVariable **Entry =
nullptr;
4962 if (!LangOpts.WritableStrings) {
4963 Entry = &ConstantStringMap[C];
4964 if (
auto GV = *Entry) {
4973 StringRef GlobalVariableName;
4974 llvm::GlobalValue::LinkageTypes
LT;
4979 if (
getCXXABI().getMangleContext().shouldMangleStringLiteral(S) &&
4980 !LangOpts.WritableStrings) {
4981 llvm::raw_svector_ostream Out(MangledNameBuffer);
4983 LT = llvm::GlobalValue::LinkOnceODRLinkage;
4984 GlobalVariableName = MangledNameBuffer;
4986 LT = llvm::GlobalValue::PrivateLinkage;
4987 GlobalVariableName = Name;
4994 SanitizerMD->reportGlobalToASan(GV, S->
getStrTokenLoc(0),
"<string literal>",
5015 const std::string &Str,
const char *GlobalName) {
5016 StringRef StrWithNull(Str.c_str(), Str.size() + 1);
5021 llvm::ConstantDataArray::getString(
getLLVMContext(), StrWithNull,
false);
5024 llvm::GlobalVariable **Entry =
nullptr;
5025 if (!LangOpts.WritableStrings) {
5026 Entry = &ConstantStringMap[C];
5027 if (
auto GV = *Entry) {
5028 if (Alignment.getQuantity() > GV->getAlignment())
5029 GV->setAlignment(Alignment.getAsAlign());
5037 GlobalName =
".str";
5040 GlobalName, Alignment);
5058 MaterializedType = E->
getType();
5062 if (llvm::Constant *Slot = MaterializedGlobalTemporaryMap[E])
5069 llvm::raw_svector_ostream Out(Name);
5071 VD, E->getManglingNumber(), Out);
5074 if (E->getStorageDuration() ==
SD_Static && VD && VD->evaluateValue()) {
5080 Value = E->getOrCreateValue(
false);
5087 Value = &EvalResult.
Val;
5093 llvm::Constant *InitialValue =
nullptr;
5094 bool Constant =
false;
5098 emitter.emplace(*
this);
5099 InitialValue = emitter->emitForInitializer(*Value, AddrSpace,
5102 Type = InitialValue->getType();
5110 llvm::GlobalValue::LinkageTypes
Linkage =
5114 if (VD->isStaticDataMember() && VD->getAnyInitializer(InitVD) &&
5118 Linkage = llvm::GlobalVariable::LinkOnceODRLinkage;
5126 auto *GV =
new llvm::GlobalVariable(
5127 getModule(), Type, Constant, Linkage, InitialValue, Name.c_str(),
5128 nullptr, llvm::GlobalVariable::NotThreadLocal, TargetAS);
5129 if (emitter) emitter->finalize(GV);
5133 GV->setComdat(TheModule.getOrInsertComdat(GV->getName()));
5134 if (VD->getTLSKind())
5136 llvm::Constant *CV = GV;
5142 MaterializedGlobalTemporaryMap[E] = CV;
5148 void CodeGenModule::EmitObjCPropertyImplementations(
const 5161 if (!Getter || Getter->isSynthesizedAccessorStub())
5163 const_cast<ObjCImplementationDecl *>(D), PID);
5164 auto *Setter = PID->getSetterMethodDecl();
5165 if (!PD->
isReadOnly() && (!Setter || Setter->isSynthesizedAccessorStub()))
5167 const_cast<ObjCImplementationDecl *>(D), PID);
5176 if (ivar->getType().isDestructedType())
5243 EmitDeclContext(LSD);
5246 void CodeGenModule::EmitDeclContext(
const DeclContext *DC) {
5247 for (
auto *I : DC->
decls()) {
5253 if (
auto *OID = dyn_cast<ObjCImplDecl>(I)) {
5254 for (
auto *M : OID->methods())
5269 case Decl::CXXConversion:
5270 case Decl::CXXMethod:
5278 case Decl::CXXDeductionGuide:
5283 case Decl::Decomposition:
5284 case Decl::VarTemplateSpecialization:
5286 if (
auto *DD = dyn_cast<DecompositionDecl>(D))
5287 for (
auto *B : DD->bindings())
5288 if (
auto *HD = B->getHoldingVar())
5294 case Decl::IndirectField:
5298 case Decl::Namespace:
5299 EmitDeclContext(cast<NamespaceDecl>(D));
5301 case Decl::ClassTemplateSpecialization: {
5302 const auto *Spec = cast<ClassTemplateSpecializationDecl>(D);
5305 Spec->hasDefinition())
5306 DebugInfo->completeTemplateDefinition(*Spec);
5308 case Decl::CXXRecord:
5312 DebugInfo->completeUnusedClass(cast<CXXRecordDecl>(*D));
5315 for (
auto *I : cast<CXXRecordDecl>(D)->decls())
5316 if (isa<VarDecl>(I) || isa<CXXRecordDecl>(I))
5320 case Decl::UsingShadow:
5321 case Decl::ClassTemplate:
5322 case Decl::VarTemplate:
5324 case Decl::VarTemplatePartialSpecialization:
5325 case Decl::FunctionTemplate:
5326 case Decl::TypeAliasTemplate:
5333 DI->EmitUsingDecl(cast<UsingDecl>(*D));
5335 case Decl::NamespaceAlias:
5337 DI->EmitNamespaceAlias(cast<NamespaceAliasDecl>(*D));
5339 case Decl::UsingDirective:
5341 DI->EmitUsingDirective(cast<UsingDirectiveDecl>(*D));
5343 case Decl::CXXConstructor:
5346 case Decl::CXXDestructor:
5350 case Decl::StaticAssert:
5357 case Decl::ObjCInterface:
5358 case Decl::ObjCCategory:
5361 case Decl::ObjCProtocol: {
5362 auto *Proto = cast<ObjCProtocolDecl>(D);
5363 if (Proto->isThisDeclarationADefinition())
5368 case Decl::ObjCCategoryImpl:
5371 ObjCRuntime->GenerateCategory(cast<ObjCCategoryImplDecl>(D));
5374 case Decl::ObjCImplementation: {
5375 auto *OMD = cast<ObjCImplementationDecl>(D);
5376 EmitObjCPropertyImplementations(OMD);
5377 EmitObjCIvarInitializations(OMD);
5382 DI->getOrCreateInterfaceType(
getContext().getObjCInterfaceType(
5383 OMD->getClassInterface()), OMD->getLocation());
5386 case Decl::ObjCMethod: {
5387 auto *OMD = cast<ObjCMethodDecl>(D);
5393 case Decl::ObjCCompatibleAlias:
5394 ObjCRuntime->RegisterAlias(cast<ObjCCompatibleAliasDecl>(D));
5397 case Decl::PragmaComment: {
5398 const auto *PCD = cast<PragmaCommentDecl>(D);
5399 switch (PCD->getCommentKind()) {
5401 llvm_unreachable(
"unexpected pragma comment kind");
5416 case Decl::PragmaDetectMismatch: {
5417 const auto *PDMD = cast<PragmaDetectMismatchDecl>(D);
5422 case Decl::LinkageSpec:
5423 EmitLinkageSpec(cast<LinkageSpecDecl>(D));
5426 case Decl::FileScopeAsm: {
5428 if (LangOpts.CUDA && LangOpts.CUDAIsDevice)
5431 if (LangOpts.OpenMPIsDevice)
5433 auto *AD = cast<FileScopeAsmDecl>(D);
5434 getModule().appendModuleInlineAsm(AD->getAsmString()->getString());
5438 case Decl::Import: {
5439 auto *Import = cast<ImportDecl>(D);
5442 if (!ImportedModules.insert(Import->getImportedModule()))
5446 if (!Import->getImportedOwningModule()) {
5448 DI->EmitImportDecl(*Import);
5452 llvm::SmallPtrSet<clang::Module *, 16> Visited;
5454 Visited.insert(Import->getImportedModule());
5455 Stack.push_back(Import->getImportedModule());
5457 while (!Stack.empty()) {
5459 if (!EmittedModuleInitializers.insert(Mod).second)
5471 if ((*Sub)->IsExplicit)
5474 if (Visited.insert(*Sub).second)
5475 Stack.push_back(*
Sub);
5482 EmitDeclContext(cast<ExportDecl>(D));
5485 case Decl::OMPThreadPrivate:
5489 case Decl::OMPAllocate:
5492 case Decl::OMPDeclareReduction:
5496 case Decl::OMPDeclareMapper:
5500 case Decl::OMPRequires:
5508 assert(isa<TypeDecl>(D) &&
"Unsupported decl kind");
5515 if (!CodeGenOpts.CoverageMapping)
5518 case Decl::CXXConversion:
5519 case Decl::CXXMethod:
5521 case Decl::ObjCMethod:
5522 case Decl::CXXConstructor:
5523 case Decl::CXXDestructor: {
5524 if (!cast<FunctionDecl>(D)->doesThisDeclarationHaveABody())
5529 auto I = DeferredEmptyCoverageMappingDecls.find(D);
5530 if (I == DeferredEmptyCoverageMappingDecls.end())
5531 DeferredEmptyCoverageMappingDecls[D] =
true;
5541 if (!CodeGenOpts.CoverageMapping)
5543 if (
const auto *Fn = dyn_cast<FunctionDecl>(D)) {
5544 if (Fn->isTemplateInstantiation())
5547 auto I = DeferredEmptyCoverageMappingDecls.find(D);
5548 if (I == DeferredEmptyCoverageMappingDecls.end())
5549 DeferredEmptyCoverageMappingDecls[D] =
false;
5559 for (
const auto &Entry : DeferredEmptyCoverageMappingDecls.takeVector()) {
5562 const Decl *D = Entry.first;
5564 case Decl::CXXConversion:
5565 case Decl::CXXMethod:
5567 case Decl::ObjCMethod: {
5574 case Decl::CXXConstructor: {
5581 case Decl::CXXDestructor: {
5598 llvm::Type *i64 = llvm::Type::getInt64Ty(Context);
5599 return llvm::ConstantInt::get(i64, PtrInt);
5603 llvm::NamedMDNode *&GlobalMetadata,
5605 llvm::GlobalValue *Addr) {
5606 if (!GlobalMetadata)
5608 CGM.
getModule().getOrInsertNamedMetadata(
"clang.global.decl.ptrs");
5611 llvm::Metadata *Ops[] = {llvm::ConstantAsMetadata::get(Addr),
5614 GlobalMetadata->addOperand(llvm::MDNode::get(CGM.
getLLVMContext(), Ops));
5622 void CodeGenModule::EmitStaticExternCAliases() {
5625 for (
auto &I : StaticExternCValues) {
5627 llvm::GlobalValue *Val = I.second;
5635 auto Res = Manglings.find(MangledName);
5636 if (Res == Manglings.end())
5638 Result = Res->getValue();
5649 void CodeGenModule::EmitDeclMetadata() {
5650 llvm::NamedMDNode *GlobalMetadata =
nullptr;
5652 for (
auto &I : MangledDeclNames) {
5653 llvm::GlobalValue *Addr =
getModule().getNamedValue(I.second);
5663 void CodeGenFunction::EmitDeclMetadata() {
5664 if (LocalDeclMap.empty())
return;
5669 unsigned DeclPtrKind = Context.getMDKindID(
"clang.decl.ptr");
5671 llvm::NamedMDNode *GlobalMetadata =
nullptr;
5673 for (
auto &I : LocalDeclMap) {
5674 const Decl *D = I.first;
5676 if (
auto *Alloca = dyn_cast<llvm::AllocaInst>(Addr)) {
5678 Alloca->setMetadata(
5679 DeclPtrKind, llvm::MDNode::get(
5680 Context, llvm::ValueAsMetadata::getConstant(DAddr)));
5681 }
else if (
auto *GV = dyn_cast<llvm::GlobalValue>(Addr)) {
5688 void CodeGenModule::EmitVersionIdentMetadata() {
5689 llvm::NamedMDNode *IdentMetadata =
5690 TheModule.getOrInsertNamedMetadata(
"llvm.ident");
5692 llvm::LLVMContext &Ctx = TheModule.getContext();
5694 llvm::Metadata *IdentNode[] = {llvm::MDString::get(Ctx, Version)};
5695 IdentMetadata->addOperand(llvm::MDNode::get(Ctx, IdentNode));
5698 void CodeGenModule::EmitCommandLineMetadata() {
5699 llvm::NamedMDNode *CommandLineMetadata =
5700 TheModule.getOrInsertNamedMetadata(
"llvm.commandline");
5702 llvm::LLVMContext &Ctx = TheModule.getContext();
5704 llvm::Metadata *CommandLineNode[] = {llvm::MDString::get(Ctx, CommandLine)};
5705 CommandLineMetadata->addOperand(llvm::MDNode::get(Ctx, CommandLineNode));
5708 void CodeGenModule::EmitTargetMetadata() {
5715 for (
unsigned I = 0; I != MangledDeclNames.size(); ++I) {
5716 auto Val = *(MangledDeclNames.begin() + I);
5723 void CodeGenModule::EmitCoverageFile() {
5728 llvm::NamedMDNode *CUNode = TheModule.getNamedMetadata(
"llvm.dbg.cu");
5732 llvm::NamedMDNode *GCov = TheModule.getOrInsertNamedMetadata(
"llvm.gcov");
5733 llvm::LLVMContext &Ctx = TheModule.getContext();
5734 auto *CoverageDataFile =
5736 auto *CoverageNotesFile =
5738 for (
int i = 0, e = CUNode->getNumOperands(); i != e; ++i) {
5739 llvm::MDNode *CU = CUNode->getOperand(i);
5740 llvm::Metadata *Elts[] = {CoverageNotesFile, CoverageDataFile, CU};
5741 GCov->addOperand(llvm::MDNode::get(Ctx, Elts));
5745 llvm::Constant *CodeGenModule::EmitUuidofInitializer(StringRef Uuid) {
5748 assert(Uuid.size() == 36);
5749 for (
unsigned i = 0; i < 36; ++i) {
5750 if (i == 8 || i == 13 || i == 18 || i == 23) assert(Uuid[i] ==
'-');
5755 const unsigned Field3ValueOffsets[8] = { 19, 21, 24, 26, 28, 30, 32, 34 };
5757 llvm::Constant *Field3[8];
5758 for (
unsigned Idx = 0; Idx < 8; ++Idx)
5759 Field3[Idx] = llvm::ConstantInt::get(
5760 Int8Ty, Uuid.substr(Field3ValueOffsets[Idx], 2), 16);
5762 llvm::Constant *Fields[4] = {
5763 llvm::ConstantInt::get(
Int32Ty, Uuid.substr(0, 8), 16),
5764 llvm::ConstantInt::get(
Int16Ty, Uuid.substr(9, 4), 16),
5765 llvm::ConstantInt::get(
Int16Ty, Uuid.substr(14, 4), 16),
5766 llvm::ConstantArray::get(llvm::ArrayType::get(
Int8Ty, 8), Field3)
5769 return llvm::ConstantStruct::getAnon(Fields);
5778 return llvm::Constant::getNullValue(
Int8PtrTy);
5781 LangOpts.ObjCRuntime.isGNUFamily())
5789 if (LangOpts.OpenMP && LangOpts.OpenMPSimd)
5791 for (
auto RefExpr : D->
varlists()) {
5792 auto *VD = cast<VarDecl>(cast<DeclRefExpr>(RefExpr)->getDecl());
5794 VD->getAnyInitializer() &&
5795 !VD->getAnyInitializer()->isConstantInitializer(
getContext(),
5800 VD, Addr, RefExpr->getBeginLoc(), PerformInit))
5801 CXXGlobalInits.push_back(InitFunction);
5806 CodeGenModule::CreateMetadataIdentifierImpl(
QualType T, MetadataTypeMap &Map,
5813 std::string OutName;
5814 llvm::raw_string_ostream Out(OutName);
5828 return CreateMetadataIdentifierImpl(T, MetadataIdMap,
"");
5833 return CreateMetadataIdentifierImpl(T, VirtualMetadataIdMap,
".virtual");
5853 for (
auto &Param : FnType->param_types())
5858 GeneralizedParams, FnType->getExtProtoInfo());
5865 llvm_unreachable(
"Encountered unknown FunctionType");
5870 GeneralizedMetadataIdMap,
".generalized");
5877 return ((LangOpts.Sanitize.has(SanitizerKind::CFIVCall) &&
5878 !CodeGenOpts.SanitizeTrap.has(SanitizerKind::CFIVCall)) ||
5879 (LangOpts.Sanitize.has(SanitizerKind::CFINVCall) &&
5880 !CodeGenOpts.SanitizeTrap.has(SanitizerKind::CFINVCall)) ||
5881 (LangOpts.Sanitize.has(SanitizerKind::CFIDerivedCast) &&
5882 !CodeGenOpts.SanitizeTrap.has(SanitizerKind::CFIDerivedCast)) ||
5883 (LangOpts.Sanitize.has(SanitizerKind::CFIUnrelatedCast) &&
5884 !CodeGenOpts.SanitizeTrap.has(SanitizerKind::CFIUnrelatedCast)));
5890 llvm::Metadata *MD =
5892 VTable->addTypeMetadata(Offset.
getQuantity(), MD);
5894 if (CodeGenOpts.SanitizeCfiCrossDso)
5897 llvm::ConstantAsMetadata::get(CrossDsoTypeId));
5900 llvm::Metadata *MD = llvm::MDString::get(
getLLVMContext(),
"all-vtables");
5901 VTable->addTypeMetadata(Offset.
getQuantity(), MD);
5907 SanStats = std::make_unique<llvm::SanitizerStatReport>(&
getModule());
5916 auto FTy = llvm::FunctionType::get(SamplerT, {C->getType()},
false);
5918 "__translate_sampler_initializer"),
void setLinkage(Linkage L)
std::string CoverageNotesFile
The filename with path we use for coverage notes files.
llvm::PointerType * Int8PtrPtrTy
RecordDecl * buildImplicitRecord(StringRef Name, RecordDecl::TagKind TK=TTK_Struct) const
Create a new implicit TU-level CXXRecordDecl or RecordDecl declaration.
const llvm::DataLayout & getDataLayout() const
virtual bool checkCFProtectionReturnSupported(DiagnosticsEngine &Diags) const
Check if the target supports CFProtection branch.
std::string ProfileInstrumentUsePath
Name of the profile file to use as input for -fprofile-instr-use.
CGOpenCLRuntime & getOpenCLRuntime()
Return a reference to the configured OpenCL runtime.
std::vector< std::string > Features
Defines the clang::ASTContext interface.
The generic AArch64 ABI is also a modified version of the Itanium ABI, but it has fewer divergences t...
llvm::Metadata * CreateMetadataIdentifierForVirtualMemPtrType(QualType T)
Create a metadata identifier that is intended to be used to check virtual calls via a member function...
FunctionDecl * getDefinition()
Get the definition for this declaration.
TargetOptions & getTargetOpts() const
Retrieve the target options.
const CXXDestructorDecl * getDestructor() const
Represents a function declaration or definition.
llvm::IntegerType * IntTy
int
void CreateFunctionTypeMetadataForIcall(const FunctionDecl *FD, llvm::Function *F)
Create and attach type metadata to the given function.
Expr * getInit() const
Get the initializer.
bool Cast(InterpState &S, CodePtr OpPC)
External linkage, which indicates that the entity can be referred to from other translation units...
LanguageLinkage getLanguageLinkage() const
Compute the language linkage.
void EmitDeferredUnusedCoverageMappings()
Emit all the deferred coverage mappings for the uninstrumented functions.
std::vector< const CXXRecordDecl * > getMostBaseClasses(const CXXRecordDecl *RD)
Return a vector of most-base classes for RD.
Smart pointer class that efficiently represents Objective-C method names.
QualType getObjCIdType() const
Represents the Objective-CC id type.
void SetLLVMFunctionAttributes(GlobalDecl GD, const CGFunctionInfo &Info, llvm::Function *F)
Set the LLVM function attributes (sext, zext, etc).
void DecorateInstructionWithInvariantGroup(llvm::Instruction *I, const CXXRecordDecl *RD)
Adds !invariant.barrier !tag to instruction.
Holds information about both target-independent and target-specific builtins, allowing easy queries b...
void EmitOMPDeclareMapper(const OMPDeclareMapperDecl *D, CodeGenFunction *CGF=nullptr)
Emit a code for declare mapper construct.
unsigned llvm::PointerUnion< const Decl *, const Expr * > DeclTy
A (possibly-)qualified type.
The iOS 64-bit ABI is follows ARM's published 64-bit ABI more closely, but we don't guarantee to foll...
CodeGenTypes & getTypes()
static QualType GeneralizeFunctionType(ASTContext &Ctx, QualType Ty)
std::vector< Module * >::iterator submodule_iterator
const CodeGenOptions & getCodeGenOpts() const
GlobalDecl getWithDecl(const Decl *D)
static llvm::cl::opt< bool > LimitedCoverage("limited-coverage-experimental", llvm::cl::ZeroOrMore, llvm::cl::Hidden, llvm::cl::desc("Emit limited coverage mapping information (experimental)"), llvm::cl::init(false))
unsigned getNumBases() const
Retrieves the number of base classes of this class.
void UpdateCompletedType(const TagDecl *TD)
UpdateCompletedType - When we find the full definition for a TagDecl, replace the 'opaque' type we pr...
unsigned getLongWidth() const
getLongWidth/Align - Return the size of 'signed long' and 'unsigned long' for this target...
ConstStmtVisitor - This class implements a simple visitor for Stmt subclasses.
llvm::LLVMContext & getLLVMContext()
GlobalDecl getWithMultiVersionIndex(unsigned Index)
std::string getClangFullVersion()
Retrieves a string representing the complete clang version, which includes the clang version number...
CXXDtorType getDtorType() const
ConstantAddress GetAddrOfConstantStringFromObjCEncode(const ObjCEncodeExpr *)
Return a pointer to a constant array for the given ObjCEncodeExpr node.
submodule_iterator submodule_begin()
bool containsNonAsciiOrNull() const
The standard implementation of ConstantInitBuilder used in Clang.
Stmt - This represents one statement.
FunctionType - C99 6.7.5.3 - Function Declarators.
SanitizerSet Sanitize
Set of enabled sanitizers.
virtual void mangleCXXDtor(const CXXDestructorDecl *D, CXXDtorType Type, raw_ostream &)=0
llvm::Constant * tryEmitForInitializer(const VarDecl &D)
Try to emit the initiaizer of the given declaration as an abstract constant.
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
StringRef getBufferName(SourceLocation Loc, bool *Invalid=nullptr) const
Return the filename or buffer identifier of the buffer the location is in.
Defines the SourceManager interface.
CharUnits getAlignOfGlobalVarInChars(QualType T) const
Return the alignment in characters that should be given to a global variable with type T...
virtual void setCXXDestructorDLLStorage(llvm::GlobalValue *GV, const CXXDestructorDecl *Dtor, CXXDtorType DT) const
bool isRecordType() const
unsigned getTypeAlignIfKnown(QualType T) const
Return the ABI-specified alignment of a type, in bits, or 0 if the type is incomplete and we cannot d...
virtual void mangleCXXCtor(const CXXConstructorDecl *D, CXXCtorType Type, raw_ostream &)=0
const Type * getTypeForDecl() const
CoreFoundationABI CFRuntime
Decl - This represents one declaration (or definition), e.g.
llvm::MDNode * getTBAAStructInfo(QualType QTy)
llvm::Constant * getAddrOfCXXStructor(GlobalDecl GD, const CGFunctionInfo *FnInfo=nullptr, llvm::FunctionType *FnType=nullptr, bool DontDefer=false, ForDefinition_t IsForDefinition=NotForDefinition)
Return the address of the constructor/destructor of the given type.
SourceLocation getBeginLoc() const LLVM_READONLY
FunctionDecl * getOperatorNew() const
VarDecl * getDefinition(ASTContext &)
Get the real (not just tentative) definition for this declaration.
LangAS GetGlobalVarAddressSpace(const VarDecl *D)
Return the AST address space of the underlying global variable for D, as determined by its declaratio...
Defines the C++ template declaration subclasses.
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
GlobalDecl getCanonicalDecl() const
static ObjCMethodDecl * Create(ASTContext &C, SourceLocation beginLoc, SourceLocation endLoc, Selector SelInfo, QualType T, TypeSourceInfo *ReturnTInfo, DeclContext *contextDecl, bool isInstance=true, bool isVariadic=false, bool isPropertyAccessor=false, bool isSynthesizedAccessorStub=false, bool isImplicitlyDeclared=false, bool isDefined=false, ImplementationControl impControl=None, bool HasRelatedResultType=false)
LangAS ASTAllocaAddressSpace
The base class of the type hierarchy.
void setFunctionLinkage(GlobalDecl GD, llvm::Function *F)
Stores additional source code information like skipped ranges which is required by the coverage mappi...
void GenerateObjCSetter(ObjCImplementationDecl *IMP, const ObjCPropertyImplDecl *PID)
GenerateObjCSetter - Synthesize an Objective-C property setter function for the given property...
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
const ABIInfo & getABIInfo() const
getABIInfo() - Returns ABI info helper for the target.
void GenerateCode(GlobalDecl GD, llvm::Function *Fn, const CGFunctionInfo &FnInfo)
bool isCompilingModule() const
Are we compiling a module interface (.cppm or module map)?
bool isBlacklistedLocation(SanitizerMask Mask, SourceLocation Loc, StringRef Category=StringRef()) const
Represent a C++ namespace.
Represents a call to a C++ constructor.
bool isRestrictQualified() const
Determine whether this type is restrict-qualified.
virtual void completeDefinition()
Note that the definition of this type is now complete.
const TargetInfo & getTargetInfo() const
void EmitCfiCheckFail()
Emit a cross-DSO CFI failure handling function.
bool imbueXRayAttrs(llvm::Function *Fn, SourceLocation Loc, StringRef Category=StringRef()) const
Imbue XRay attributes to a function, applying the always/never attribute lists in the process...
Interoperability with the latest known version of the Swift runtime.
constexpr XRayInstrMask Function
static const llvm::GlobalObject * getAliasedGlobal(const llvm::GlobalIndirectSymbol &GIS)
bool HasHiddenLTOVisibility(const CXXRecordDecl *RD)
Returns whether the given record has hidden LTO visibility and therefore may participate in (single-m...
Linkage getLinkage() const
Determine the linkage of this type.
bool isDefined(const FunctionDecl *&Definition) const
Returns true if the function has a definition that does not need to be instantiated.
PreprocessorOptions - This class is used for passing the various options used in preprocessor initial...
void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const override
Appends a human-readable name for this declaration into the given stream.
const Expr * getAnyInitializer() const
Get the initializer for this variable, no matter which declaration it is attached to...
llvm::IntegerType * Int8Ty
i8, i16, i32, and i64
Represents a prvalue temporary that is written into memory so that a reference can bind to it...
static llvm::GlobalValue::VisibilityTypes GetLLVMVisibility(Visibility V)
static llvm::Constant * castStringLiteralToDefaultAddressSpace(CodeGenModule &CGM, llvm::GlobalVariable *GV)
'gcc' is the Objective-C runtime shipped with GCC, implementing a fragile Objective-C ABI ...
void HandleCXXStaticMemberVarInstantiation(VarDecl *VD)
Tell the consumer that this variable has been instantiated.
Represents a variable declaration or definition.
QualType getCFConstantStringType() const
Return the C structure type used to represent constant CFStrings.
const T * getAs() const
Member-template getAs<specific type>'.
Visibility getVisibility() const
CGDebugInfo * getModuleDebugInfo()
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
bool supportsCOMDAT() const
LangAS
Defines the address space values used by the address space qualifier of QualType. ...
Class supports emissionof SIMD-only code.
bool isInlineBuiltinDeclaration() const
Determine if this function provides an inline implementation of a builtin.
This class gathers all debug information during compilation and is responsible for emitting to llvm g...
static llvm::GlobalVariable * GenerateStringLiteral(llvm::Constant *C, llvm::GlobalValue::LinkageTypes LT, CodeGenModule &CGM, StringRef GlobalName, CharUnits Alignment)
ObjCMethodDecl - Represents an instance or class method declaration.
DiagnosticsEngine & getDiags() const
QualType getMemberPointerType(QualType T, const Type *Cls) const
Return the uniqued reference to the type for a member pointer to the specified type in the specified ...
Describes how types, statements, expressions, and declarations should be printed. ...
void setGlobalVisibility(llvm::GlobalValue *GV, const NamedDecl *D) const
Set the visibility for the given LLVM GlobalValue.
llvm::Type * ConvertTypeForMem(QualType T)
ConvertTypeForMem - Convert type T into a llvm::Type.
Don't generate debug info.
bool supportsIFunc() const
Identify whether this target supports IFuncs.
Represents a parameter to a function.
virtual void getDetectMismatchOption(llvm::StringRef Name, llvm::StringRef Value, llvm::SmallString< 32 > &Opt) const
Gets the linker options necessary to detect object file mismatches on this platform.
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have...
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Represents a struct/union/class.
LanguageIDs getLanguage() const
Return the language specified by this linkage specification.
uint64_t getPointerWidth(unsigned AddrSpace) const
Return the width of pointers on this target, for the specified address space.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
static const FunctionDecl * GetRuntimeFunctionDecl(ASTContext &C, StringRef Name)
TBAAAccessInfo mergeTBAAInfoForCast(TBAAAccessInfo SourceInfo, TBAAAccessInfo TargetInfo)
mergeTBAAInfoForCast - Get merged TBAA information for the purposes of type casts.
One of these records is kept for each identifier that is lexed.
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
'macosx-fragile' is the Apple-provided NeXT-derived runtime on Mac OS X platforms that use the fragil...
unsigned getIntAlign() const
QualType::DestructionKind needsDestruction(const ASTContext &Ctx) const
Would the destruction of this variable have any effect, and if so, what kind?
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
llvm::Type * ConvertType(QualType T)
ConvertType - Convert type T into a llvm::Type.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
llvm::IntegerType * Int64Ty
field_range fields() const
SourceLocation getBeginLoc() const LLVM_READONLY
The generic Mips ABI is a modified version of the Itanium ABI.
Represents a member of a struct/union/class.
static CGCXXABI * createCXXABI(CodeGenModule &CGM)
llvm::IntegerType * SizeTy
bool Zero(InterpState &S, CodePtr OpPC)
void startDefinition()
Starts the definition of this tag declaration.
bool isReferenceType() const
Interoperability with the Swift 4.1 runtime.
SanitizerMask Mask
Bitmask of enabled sanitizers.
This declaration is definitely a definition.
void GenerateObjCCtorDtorMethod(ObjCImplementationDecl *IMP, ObjCMethodDecl *MD, bool ctor)
__DEVICE__ int max(int __a, int __b)
static std::string getCPUSpecificMangling(const CodeGenModule &CGM, StringRef Name)
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
unsigned getCharByteWidth() const
llvm::CallingConv::ID RuntimeCC
std::string CodeModel
The code model to use (-mcmodel).
Describes a module or submodule.
bool shouldMangleDeclName(const NamedDecl *D)
void EmitExternalDeclaration(const VarDecl *D)
CharUnits GetTargetTypeStoreSize(llvm::Type *Ty) const
Return the store size, in character units, of the given LLVM type.
Objects with "default" visibility are seen by the dynamic linker and act like normal objects...
llvm::Constant * GetConstantArrayFromStringLiteral(const StringLiteral *E)
Return a constant array for the given string.
bool isReplaceableGlobalAllocationFunction(bool *IsAligned=nullptr) const
Determines whether this function is one of the replaceable global allocation functions: void *operato...
static void EmitGlobalDeclMetadata(CodeGenModule &CGM, llvm::NamedMDNode *&GlobalMetadata, GlobalDecl D, llvm::GlobalValue *Addr)
static void AppendTargetMangling(const CodeGenModule &CGM, const TargetAttr *Attr, raw_ostream &Out)
virtual StringRef getABI() const
Get the ABI currently in use.
CGCUDARuntime & getCUDARuntime()
Return a reference to the configured CUDA runtime.
unsigned getLength() const
bool isLibFunction(unsigned ID) const
Return true if this is a builtin for a libc/libm function, with a "__builtin_" prefix (e...
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
FunctionDecl * getOperatorDelete() const
bool isReferenced() const
Whether any declaration of this entity was referenced.
CharUnits - This is an opaque type for sizes expressed in character units.
APValue Val
Val - This is the value the expression can be folded to.
void EmitOMPRequiresDecl(const OMPRequiresDecl *D)
Emit a code for requires directive.
void setDSOLocal(llvm::GlobalValue *GV) const
llvm::Align getAsAlign() const
getAsAlign - Returns Quantity as a valid llvm::Align, Beware llvm::Align assumes power of two 8-bit b...
The Microsoft ABI is the ABI used by Microsoft Visual Studio (and compatible compilers).
bool hasConstructorVariants() const
Does this ABI have different entrypoints for complete-object and base-subobject constructors?
void EmitOMPDeclareReduction(const OMPDeclareReductionDecl *D, CodeGenFunction *CGF=nullptr)
Emit a code for declare reduction construct.
virtual void mangleReferenceTemporary(const VarDecl *D, unsigned ManglingNumber, raw_ostream &)=0
TBAAAccessInfo getTBAAAccessInfo(QualType AccessType)
getTBAAAccessInfo - Get TBAA information that describes an access to an object of the given type...
void emitOpenMPDeviceFunctionRedefinition(GlobalDecl OldGD, GlobalDecl NewGD, llvm::GlobalValue *GV)
Emits the definition of OldGD function with body from NewGD.
unsigned char PointerWidthInBits
The width of a pointer into the generic address space.
llvm::PointerType * VoidPtrTy
Concrete class used by the front-end to report problems and issues.
const clang::PrintingPolicy & getPrintingPolicy() const
TemplateSpecializationKind getTemplateSpecializationKind() const
If this variable is an instantiation of a variable template or a static data member of a class templa...
CGObjCRuntime * CreateMacObjCRuntime(CodeGenModule &CGM)
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
CXXCtorType getCtorType() const
void ConstructAttributeList(StringRef Name, const CGFunctionInfo &Info, CGCalleeInfo CalleeInfo, llvm::AttributeList &Attrs, unsigned &CallingConv, bool AttrOnCallSite)
Get the LLVM attributes and calling convention to use for a particular function type.
GVALinkage GetGVALinkageForFunction(const FunctionDecl *FD) const
Module * Parent
The parent of this module.
bool isReadOnly() const
isReadOnly - Return true iff the property has a setter.
Defines the Diagnostic-related interfaces.
CharUnits getDeclAlign(const Decl *D, bool ForAlignof=false) const
Return a conservative estimate of the alignment of the specified decl D.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
bool isTargetMultiVersion() const
True if this function is a multiversioned dispatch function as a part of the target functionality...
submodule_iterator submodule_end()
void addCompilerUsedGlobal(llvm::GlobalValue *GV)
Add a global to a list to be added to the llvm.compiler.used metadata.
bool isCPUSpecificMultiVersion() const
True if this function is a multiversioned processor specific function as a part of the cpu_specific/c...
Represents binding an expression to a temporary.
llvm::Constant * CreateRuntimeVariable(llvm::Type *Ty, StringRef Name)
Create a new runtime global variable with the specified type and name.
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC)...
CXXTemporary * getTemporary()
const CGFunctionInfo & arrangeCXXMethodDeclaration(const CXXMethodDecl *MD)
C++ methods have some special rules and also have implicit parameters.
CharUnits getPointerAlign() const
void EmitTentativeDefinition(const VarDecl *D)
void addInstanceMethod(ObjCMethodDecl *method)
bool isAlignmentRequired(const Type *T) const
Determine if the alignment the type has was required using an alignment attribute.
llvm::SanitizerStatReport & getSanStats()
A class that does preorder or postorder depth-first traversal on the entire Clang AST and visits each...
Represents an ObjC class declaration.
Represents a linkage specification.
unsigned getBuiltinID(bool ConsiderWrapperFunctions=false) const
Returns a value indicating whether this function corresponds to a builtin function.
The iOS ABI is a partial implementation of the ARM ABI.
Interoperability with the Swift 5.0 runtime.
virtual llvm::GlobalValue::LinkageTypes getCXXDestructorLinkage(GVALinkage Linkage, const CXXDestructorDecl *Dtor, CXXDtorType DT) const
const CGFunctionInfo & arrangeGlobalDeclaration(GlobalDecl GD)
void mangleName(const NamedDecl *D, raw_ostream &)
virtual llvm::Value * performAddrSpaceCast(CodeGen::CodeGenFunction &CGF, llvm::Value *V, LangAS SrcAddr, LangAS DestAddr, llvm::Type *DestTy, bool IsNonNull=false) const
Perform address space cast of an expression of pointer type.
bool lookupRepresentativeDecl(StringRef MangledName, GlobalDecl &Result) const
bool hasProfileClangUse() const
Check if Clang profile use is on.
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
bool isTypeConstant(QualType QTy, bool ExcludeCtorDtor)
isTypeConstant - Determine whether an object of this type can be emitted as a constant.
llvm::PointerType * getSamplerType(const Type *T)
Represents a K&R-style 'int foo()' function, which has no information available about its arguments...
llvm::MDNode * getTBAAAccessTagInfo(TBAAAccessInfo Info)
getTBAAAccessTagInfo - Get TBAA tag for a given memory access.
const XRayFunctionFilter & getXRayFilter() const
'watchos' is a variant of iOS for Apple's watchOS.
llvm::StringMap< SectionInfo > SectionInfos
llvm::Type * HalfTy
float, double
StringRef getString() const
std::string ProfileRemappingFile
Name of the profile remapping file to apply to the profile data supplied by -fprofile-sample-use or -...
static bool hasUnwindExceptions(const LangOptions &LangOpts)
Determines whether the language options require us to model unwind exceptions.
virtual bool checkCFProtectionBranchSupported(DiagnosticsEngine &Diags) const
Check if the target supports CFProtection branch.
Contains information gathered from parsing the contents of TargetAttr.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Represents a prototype with parameter type info, e.g.
static bool AllTrivialInitializers(CodeGenModule &CGM, ObjCImplementationDecl *D)
The generic ARM ABI is a modified version of the Itanium ABI proposed by ARM for use on ARM-based pla...
std::string CurrentModule
The name of the current module, of which the main source file is a part.
void setHasDestructors(bool val)
ValueDecl * getExtendingDecl()
Get the declaration which triggered the lifetime-extension of this temporary, if any.
const TargetCodeGenInfo & getTargetCodeGenInfo()
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
void AddDetectMismatch(StringRef Name, StringRef Value)
Appends a detect mismatch command to the linker options.
Represents a ValueDecl that came out of a declarator.
llvm::SmallSetVector< Module *, 2 > Imports
The set of modules imported by this module, and on which this module depends.
virtual void getDependentLibraryOption(llvm::StringRef Lib, llvm::SmallString< 24 > &Opt) const
Gets the linker options necessary to link a dependent library on this platform.
static void setLinkageForGV(llvm::GlobalValue *GV, const NamedDecl *ND)
bool isInSanitizerBlacklist(SanitizerMask Kind, llvm::Function *Fn, SourceLocation Loc) const
const char * getName(unsigned ID) const
Return the identifier name for the specified builtin, e.g.
StringRef getBlockMangledName(GlobalDecl GD, const BlockDecl *BD)
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
llvm::CallingConv::ID getRuntimeCC() const
Exposes information about the current target.
llvm::SmallVector< StringRef, 8 > Features
llvm::Constant * EmitAnnotationUnit(SourceLocation Loc)
Emit the annotation's translation unit.
static void addLinkOptionsPostorder(CodeGenModule &CGM, Module *Mod, SmallVectorImpl< llvm::MDNode *> &Metadata, llvm::SmallPtrSet< Module *, 16 > &Visited)
Add link options implied by the given module, including modules it depends on, using a postorder walk...
virtual void EmitCXXConstructors(const CXXConstructorDecl *D)=0
Emit constructor variants required by this ABI.
Represents a block literal declaration, which is like an unnamed FunctionDecl.
bool isMultiVersion() const
True if this function is considered a multiversioned function.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
This represents one expression.
'macosx' is the Apple-provided NeXT-derived runtime on Mac OS X platforms that use the non-fragile AB...
virtual void EmitCXXDestructors(const CXXDestructorDecl *D)=0
Emit destructor variants required by this ABI.
void AddGlobalAnnotations(const ValueDecl *D, llvm::GlobalValue *GV)
Add global annotations that are set on D, for the global GV.
const FileEntry * getFileEntryForID(FileID FID) const
Returns the FileEntry record for the provided FileID.
unsigned getIntWidth() const
getIntWidth/Align - Return the size of 'signed int' and 'unsigned int' for this target, in bits.
void GenerateObjCMethod(const ObjCMethodDecl *OMD)
Generate an Objective-C method.
llvm::Constant * GetAddrOfGlobalVar(const VarDecl *D, llvm::Type *Ty=nullptr, ForDefinition_t IsForDefinition=NotForDefinition)
Return the llvm::Constant for the address of the given global variable.
unsigned getLine() const
Return the presumed line number of this location.
Organizes the cross-function state that is used while generating code coverage mapping data...
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
Represents a C++ destructor within a class.
bool UseExportAsModuleLinkName
Autolinking uses the framework name for linking purposes when this is false and the export_as name ot...
void reportDiagnostics(DiagnosticsEngine &Diags, StringRef MainFile)
Report potential problems we've found to Diags.
Defines version macros and version-related utility functions for Clang.
static QualType GeneralizeType(ASTContext &Ctx, QualType Ty)
QualType getTagDeclType(const TagDecl *Decl) const
Return the unique reference to the type for the specified TagDecl (struct/union/class/enum) decl...
static uint64_t GetX86CpuSupportsMask(ArrayRef< StringRef > FeatureStrs)
Linkage getLinkage() const
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
uint32_t getCodeUnit(size_t i) const
bool isCPUDispatchMultiVersion() const
True if this function is a multiversioned dispatch function as a part of the cpu_specific/cpu_dispatc...
TLSKind getTLSKind() const
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
CGOpenMPRuntime(CodeGenModule &CGM)
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return null.
llvm::SmallVector< LinkLibrary, 2 > LinkLibraries
The set of libraries or frameworks to link against when an entity from this module is used...
static bool requiresMemberFunctionPointerTypeMetadata(CodeGenModule &CGM, const CXXMethodDecl *MD)
void GenOpenCLArgMetadata(llvm::Function *FN, const FunctionDecl *FD=nullptr, CodeGenFunction *CGF=nullptr)
OpenCL v1.2 s5.6.4.6 allows the compiler to store kernel argument information in the program executab...
llvm::IntegerType * Int32Ty
llvm::GlobalValue::LinkageTypes getLLVMLinkageVarDefinition(const VarDecl *VD, bool IsConstant)
Returns LLVM linkage for a declarator.
DefinitionKind hasDefinition(ASTContext &) const
Check whether this variable is defined in this translation unit.
virtual bool validateCpuSupports(StringRef Name) const
clang::ObjCRuntime ObjCRuntime
propimpl_range property_impls() const
unsigned getMaxAlignment() const
getMaxAlignment - return the maximum alignment specified by attributes on this decl, 0 if there are none.
llvm::Constant * EmitAnnotationString(StringRef Str)
Emit an annotation string.
StorageDuration getStorageDuration() const
Retrieve the storage duration for the materialized temporary.
QualType getEncodedType() const
llvm::PointerType * AllocaInt8PtrTy
bool isExternallyVisible(Linkage L)
ConstantAddress GetAddrOfUuidDescriptor(const CXXUuidofExpr *E)
Get the address of a uuid descriptor .
llvm::GlobalVariable::LinkageTypes getFunctionLinkage(GlobalDecl GD)
QualType getRecordType(const RecordDecl *Decl) const
Represents an unpacked "presumed" location which can be presented to the user.
CXXMethodDecl * getMethodDecl() const
Retrieve the declaration of the called method.
QualType getFunctionType(QualType ResultTy, ArrayRef< QualType > Args, const FunctionProtoType::ExtProtoInfo &EPI) const
Return a normal function type with a typed argument list.
virtual void getCPUSpecificCPUDispatchFeatures(StringRef Name, llvm::SmallVectorImpl< StringRef > &Features) const
static bool isVarDeclStrongDefinition(const ASTContext &Context, CodeGenModule &CGM, const VarDecl *D, bool NoCommon)
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
const TargetInfo & getTarget() const
void SetCommonAttributes(GlobalDecl GD, llvm::GlobalValue *GV)
Set attributes which are common to any form of a global definition (alias, Objective-C method...
static bool shouldAssumeDSOLocal(const CodeGenModule &CGM, llvm::GlobalValue *GV)
This template specialization was implicitly instantiated from a template.
'gnustep' is the modern non-fragile GNUstep runtime.
unsigned getExpansionLineNumber(SourceLocation Loc, bool *Invalid=nullptr) const
const LangOptions & getLangOpts() const
void setGVPropertiesAux(llvm::GlobalValue *GV, const NamedDecl *D) const
ASTContext & getContext() const
bool isNull() const
Return true if this QualType doesn't point to a type yet.
void AddVTableTypeMetadata(llvm::GlobalVariable *VTable, CharUnits Offset, const CXXRecordDecl *RD)
Create and attach type metadata for the given vtable.
CallingConv
CallingConv - Specifies the calling convention that a function uses.
VarDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
const SanitizerBlacklist & getSanitizerBlacklist() const
GlobalDecl - represents a global declaration.
TBAAAccessInfo mergeTBAAInfoForConditionalOperator(TBAAAccessInfo InfoA, TBAAAccessInfo InfoB)
mergeTBAAInfoForConditionalOperator - Get merged TBAA information for the purposes of conditional ope...
llvm::Constant * EmitAnnotateAttr(llvm::GlobalValue *GV, const AnnotateAttr *AA, SourceLocation L)
Generate the llvm::ConstantStruct which contains the annotation information for a given GlobalValue...
init_iterator init_begin()
init_begin() - Retrieve an iterator to the first initializer.
unsigned getCVRQualifiers() const
Retrieve the set of CVR (const-volatile-restrict) qualifiers applied to this type.
ConstantAddress GetAddrOfGlobalTemporary(const MaterializeTemporaryExpr *E, const Expr *Inner)
Returns a pointer to a global variable representing a temporary with static or thread storage duratio...
WatchOS is a modernisation of the iOS ABI, which roughly means it's the iOS64 ABI ported to 32-bits...
bool isConstQualified() const
Determine whether this type is const-qualified.
std::string CPU
If given, the name of the target CPU to generate code for.
The l-value was considered opaque, so the alignment was determined from a type.
const char * getFilename() const
Return the presumed filename of this location.
QualType getWideCharType() const
Return the type of wide characters.
unsigned char IntAlignInBytes
static std::string getMangledNameImpl(const CodeGenModule &CGM, GlobalDecl GD, const NamedDecl *ND, bool OmitMultiVersionMangling=false)
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...
static void emitUsed(CodeGenModule &CGM, StringRef Name, std::vector< llvm::WeakTrackingVH > &List)
SelectorTable & Selectors
void RefreshTypeCacheForClass(const CXXRecordDecl *Class)
QualType getCanonicalType() const
decl_type * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
void MaybeHandleStaticInExternC(const SomeDecl *D, llvm::GlobalValue *GV)
If the declaration has internal linkage but is inside an extern "C" linkage specification, prepare to emit an alias for it to the expected name.
FunctionDecl * getAsFunction() LLVM_READONLY
Returns the function itself, or the templated function if this is a function template.
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
Encodes a location in the source.
static DeclContext * castToDeclContext(const TranslationUnitDecl *D)
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
LangAS getAddressSpace() const
Return the address space of this type.
void setTLSMode(llvm::GlobalValue *GV, const VarDecl &D) const
Set the TLS mode for the given LLVM GlobalValue for the thread-local variable declaration D...
'objfw' is the Objective-C runtime included in ObjFW
ConstantAddress GetAddrOfConstantCFString(const StringLiteral *Literal)
Return a pointer to a constant CFString object for the given string.
static bool Ret(InterpState &S, CodePtr &PC, APValue &Result)
TBAAAccessInfo getTBAAVTablePtrAccessInfo(llvm::Type *VTablePtrType)
getTBAAVTablePtrAccessInfo - Get the TBAA information that describes an access to a virtual table poi...
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)"...
Represents the declaration of a struct/union/class/enum.
void setGVProperties(llvm::GlobalValue *GV, GlobalDecl GD) const
Set visibility, dllimport/dllexport and dso_local.
Represents a call to a member function that may be written either with member call syntax (e...
ASTContext & getASTContext() const LLVM_READONLY
llvm::Metadata * CreateMetadataIdentifierForType(QualType T)
Create a metadata identifier for the given type.
bool hasUnwindExceptions() const
Does this runtime use zero-cost exceptions?
llvm::IntegerType * Int16Ty
const Decl * getDecl() const
virtual void registerDeviceVar(const VarDecl *VD, llvm::GlobalVariable &Var, unsigned Flags)=0
void mangleDtorBlock(const CXXDestructorDecl *CD, CXXDtorType DT, const BlockDecl *BD, raw_ostream &Out)
ParsedAttr - Represents a syntactic attribute.
static void removeImageAccessQualifier(std::string &TyName)
LangAS getStringLiteralAddressSpace() const
Return the AST address space of string literal, which is used to emit the string literal as global va...
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
virtual llvm::Function * emitThreadPrivateVarDefinition(const VarDecl *VD, Address VDAddr, SourceLocation Loc, bool PerformInit, CodeGenFunction *CGF=nullptr)
Emit a code for initialization of threadprivate variable.
Represents a static or instance method of a struct/union/class.
MangleContext - Context for tracking state which persists across multiple calls to the C++ name mangl...
const ConstantArrayType * getAsConstantArrayType(QualType T) const
SourceLocation getStrTokenLoc(unsigned TokNum) const
Get one of the string literal token.
ConstantAddress GetAddrOfConstantStringFromLiteral(const StringLiteral *S, StringRef Name=".str")
Return a pointer to a constant array for the given string literal.
Weak for now, might become strong later in this TU.
bool hasGlobalStorage() const
Returns true for all variables that do not have local storage.
llvm::Metadata * CreateMetadataIdentifierGeneralized(QualType T)
Create a metadata identifier for the generalization of the given type.
const ParmVarDecl * getParamDecl(unsigned i) const
llvm::Constant * GetAddrOfRTTIDescriptor(QualType Ty, bool ForEH=false)
Get the address of the RTTI descriptor for the given type.
std::vector< std::string > Features
The list of target specific features to enable or disable – this should be a list of strings startin...
bool doesDeclarationForceExternallyVisibleDefinition() const
For a function declaration in C or C++, determine whether this declaration causes the definition to b...
bool isTrivialInitializer(const Expr *Init)
Determine whether the given initializer is trivial in the sense that it requires no code to be genera...
llvm::Constant * emitAbstract(const Expr *E, QualType T)
Emit the result of the given expression as an abstract constant, asserting that it succeeded...
void addGlobalValReplacement(llvm::GlobalValue *GV, llvm::Constant *C)
bool isObjCObjectPointerType() const
llvm::MDNode * getTBAATypeInfo(QualType QTy)
getTBAATypeInfo - Get metadata used to describe accesses to objects of the given type.
ConstantAddress GetWeakRefReference(const ValueDecl *VD)
Get a reference to the target of VD.
Defines the clang::Module class, which describes a module in the source code.
init_iterator init_end()
init_end() - Retrieve an iterator past the last initializer.
Represents one property declaration in an Objective-C interface.
void SetLLVMFunctionAttributesForDefinition(const Decl *D, llvm::Function *F)
Set the LLVM function attributes which only apply to a function definition.
The generic Itanium ABI is the standard ABI of most open-source and Unix-like platforms.
unsigned getCustomDiagID(Level L, const char(&FormatString)[N])
Return an ID for a diagnostic with the specified format string and level.
void EmitTopLevelDecl(Decl *D)
Emit code for a single top level declaration.
MangleContext & getMangleContext()
Gets the mangle context.
This template specialization was instantiated from a template due to an explicit instantiation defini...
bool isUsed(bool CheckUsedAttr=true) const
Whether any (re-)declaration of the entity was used, meaning that a definition is required...
CGCXXABI * CreateMicrosoftCXXABI(CodeGenModule &CGM)
Creates a Microsoft-family ABI.
static unsigned TargetMVPriority(const TargetInfo &TI, const CodeGenFunction::MultiVersionResolverOption &RO)
llvm::Constant * EmitAnnotationLineNo(SourceLocation L)
Emit the annotation line number.
void Error(SourceLocation loc, StringRef error)
Emit a general error that something can't be done.
llvm::CallingConv::ID getRuntimeCC() const
Return the calling convention to use for system runtime functions.
std::vector< Structor > CtorList
TBAAAccessInfo mergeTBAAInfoForMemoryTransfer(TBAAAccessInfo DestInfo, TBAAAccessInfo SrcInfo)
mergeTBAAInfoForMemoryTransfer - Get merged TBAA information for the purposes of memory transfer call...
bool isWeakImported() const
Determine whether this is a weak-imported symbol.
static unsigned ArgInfoAddressSpace(LangAS AS)
virtual void mangleTypeName(QualType T, raw_ostream &)=0
Generates a unique string for an externally visible type for use with TBAA or type uniquing...
CXXCtorType
C++ constructor types.
The WebAssembly ABI is a modified version of the Itanium ABI.
void addReplacement(StringRef Name, llvm::Constant *C)
ConstantAddress GetAddrOfConstantCString(const std::string &Str, const char *GlobalName=nullptr)
Returns a pointer to a character array containing the literal and a terminating '\0' character...
llvm::Constant * GetAddrOfGlobal(GlobalDecl GD, ForDefinition_t IsForDefinition=NotForDefinition)
ArrayRef< Decl * > getModuleInitializers(Module *M)
Get the initializations to perform when importing a module, if any.
StringRef getName() const
Return the actual identifier string.
void addUsedGlobal(llvm::GlobalValue *GV)
Add a global to a list to be added to the llvm.used metadata.
ObjCIvarDecl * getNextIvar()
TLS with a dynamic initializer.
void ErrorUnsupported(const Stmt *S, const char *Type)
Print out an error that codegen doesn't support the specified stmt yet.
CGFunctionInfo - Class to encapsulate the information about a function definition.
This class organizes the cross-function state that is used while generating LLVM code.
CGOpenMPRuntime & getOpenMPRuntime()
Return a reference to the configured OpenMP runtime.
const ObjCInterfaceDecl * getClassInterface() const
llvm::GlobalValue * GetGlobalValue(StringRef Ref)
void mangleGlobalBlock(const BlockDecl *BD, const NamedDecl *ID, raw_ostream &Out)
void mangleBlock(const DeclContext *DC, const BlockDecl *BD, raw_ostream &Out)
Dataflow Directional Tag Classes.
bool isValid() const
Return true if this is a valid SourceLocation object.
bool hasSideEffects() const
virtual LangAS getGlobalVarAddressSpace(CodeGenModule &CGM, const VarDecl *D) const
Get target favored AST address space of a global variable for languages other than OpenCL and CUDA...
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
virtual char CPUSpecificManglingCharacter(StringRef Name) const
EvalResult is a struct with detailed info about an evaluated expression.
void forEachMultiversionedFunctionVersion(const FunctionDecl *FD, llvm::function_ref< void(FunctionDecl *)> Pred) const
Visits all versions of a multiversioned function with the passed predicate.
Represents a delete expression for memory deallocation and destructor calls, e.g. ...
void GenerateObjCGetter(ObjCImplementationDecl *IMP, const ObjCPropertyImplDecl *PID)
GenerateObjCGetter - Synthesize an Objective-C property getter function.
unsigned char PointerAlignInBytes
bool isVisibilityExplicit() const
The basic abstraction for the target Objective-C runtime.
llvm::MDNode * getTBAABaseTypeInfo(QualType QTy)
getTBAABaseTypeInfo - Get metadata that describes the given base access type.
bool NeedAllVtablesTypeId() const
Returns whether this module needs the "all-vtables" type identifier.
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template instantiation this function represents.
llvm::iterator_range< submodule_iterator > submodules()
std::string SymbolPartition
The name of the partition that symbols are assigned to, specified with -fsymbol-partition (see https:...
void EmitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D)
Emit a code for threadprivate directive.
const Expr * getInit() const
FileID getMainFileID() const
Returns the FileID of the main source file.
std::unique_ptr< DiagnosticConsumer > create(StringRef OutputFile, DiagnosticOptions *Diags, bool MergeChildRecords=false)
Returns a DiagnosticConsumer that serializes diagnostics to a bitcode file.
llvm::IntegerType * IntPtrTy
FunctionDecl * getTemplateInstantiationPattern() const
Retrieve the function declaration from which this function could be instantiated, if it is an instant...
bool isMSStaticDataMemberInlineDefinition(const VarDecl *VD) const
Returns true if this is an inline-initialized static data member which is treated as a definition for...
llvm::Reloc::Model RelocationModel
The name of the relocation model to use.
static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined...
QualType getFunctionNoProtoType(QualType ResultTy, const FunctionType::ExtInfo &Info) const
Return a K&R style C function type like 'int()'.
The Fuchsia ABI is a modified version of the Itanium ABI.
llvm::Constant * EmitNullConstant(QualType T)
Return the result of value-initializing the given type, i.e.
PresumedLoc getPresumedLoc(SourceLocation Loc, bool UseLineDirectives=true) const
Returns the "presumed" location of a SourceLocation specifies.
void UpdateCompletedType(const TagDecl *TD)
llvm::Function * getIntrinsic(unsigned IID, ArrayRef< llvm::Type *> Tys=None)
llvm::FunctionCallee CreateRuntimeFunction(llvm::FunctionType *Ty, StringRef Name, llvm::AttributeList ExtraAttrs=llvm::AttributeList(), bool Local=false, bool AssumeConvergent=false)
Create or return a runtime function declaration with the specified type and name. ...
static bool needsDestructMethod(ObjCImplementationDecl *impl)
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
static llvm::GlobalVariable::ThreadLocalMode GetLLVMTLSModel(StringRef S)
llvm::Module & getModule() const
void maybeSetTrivialComdat(const Decl &D, llvm::GlobalObject &GO)
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any...
void EmitThunks(GlobalDecl GD)
EmitThunks - Emit the associated thunks for the given global decl.
void AddDeferredUnusedCoverageMapping(Decl *D)
Stored a deferred empty coverage mapping for an unused and thus uninstrumented top level declaration...
LLVM_READONLY bool isHexDigit(unsigned char c)
Return true if this character is an ASCII hex digit: [0-9a-fA-F].
GVALinkage GetGVALinkageForVariable(const VarDecl *VD)
'ios' is the Apple-provided NeXT-derived runtime on iOS or the iOS simulator; it is always non-fragil...
unsigned getMultiVersionIndex() const
void emitEmptyCounterMapping(const Decl *D, StringRef FuncName, llvm::GlobalValue::LinkageTypes Linkage)
Emit a coverage mapping range with a counter zero for an unused declaration.
FileID getFileID(SourceLocation SpellingLoc) const
Return the FileID for a SourceLocation.
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
virtual void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const
setTargetAttributes - Provides a convenient hook to handle extra target-specific attributes for the g...
virtual llvm::Optional< LangAS > getConstantAddressSpace() const
Return an AST address space which can be used opportunistically for constant global memory...
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
LinkageInfo getLinkageAndVisibility() const
Determines the linkage and visibility of this entity.
void AppendLinkerOptions(StringRef Opts)
Appends Opts to the "llvm.linker.options" metadata value.
void DecorateInstructionWithTBAA(llvm::Instruction *Inst, TBAAAccessInfo TBAAInfo)
DecorateInstructionWithTBAA - Decorate the instruction with a TBAA tag.
void setHasNonZeroConstructors(bool val)
Represents a C++ base or member initializer.
virtual llvm::Constant * getAddrOfRTTIDescriptor(QualType Ty)=0
CanQualType UnsignedLongTy
Implements C++ ABI-specific code generation functions.
ObjCEncodeExpr, used for @encode in Objective-C.
static llvm::StringMapEntry< llvm::GlobalVariable * > & GetConstantCFStringEntry(llvm::StringMap< llvm::GlobalVariable *> &Map, const StringLiteral *Literal, bool TargetIsLSB, bool &IsUTF16, unsigned &StringLength)
Selector getSelector(unsigned NumArgs, IdentifierInfo **IIV)
Can create any sort of selector.
std::string RecordCommandLine
The string containing the commandline for the llvm.commandline metadata, if non-empty.
virtual unsigned multiVersionSortPriority(StringRef Name) const
uint64_t getCharWidth() const
Return the size of the character type, in bits.
static void AppendCPUSpecificCPUDispatchMangling(const CodeGenModule &CGM, const CPUSpecificAttr *Attr, unsigned CPUIndex, raw_ostream &Out)
bool hasDiagnostics()
Whether or not the stats we've gathered indicate any potential problems.
virtual void emitTargetMD(const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const
emitTargetMD - Provides a convenient hook to handle extra target-specific metadata for the given glob...
void getObjCEncodingForType(QualType T, std::string &S, const FieldDecl *Field=nullptr, QualType *NotEncodedT=nullptr) const
Emit the Objective-CC type encoding for the given type T into S.
llvm::PointerType * Int8PtrTy
bool isStaticLocal() const
Returns true if a variable with function scope is a static local variable.
void GenerateClassData(const CXXRecordDecl *RD)
GenerateClassData - Generate all the class data required to be generated upon definition of a KeyFunc...
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
static void ReplaceUsesOfNonProtoTypeWithRealFunction(llvm::GlobalValue *Old, llvm::Function *NewFn)
ReplaceUsesOfNonProtoTypeWithRealFunction - This function is called when we implement a function with...
virtual uint64_t getMaxPointerWidth() const
Return the maximum width of pointers on this target.
llvm::Constant * GetAddrOfFunction(GlobalDecl GD, llvm::Type *Ty=nullptr, bool ForVTable=false, bool DontDefer=false, ForDefinition_t IsForDefinition=NotForDefinition)
Return the address of the given function.
void SetInternalFunctionAttributes(GlobalDecl GD, llvm::Function *F, const CGFunctionInfo &FI)
Set the attributes on the LLVM function for the given decl and function info.
StringRef getMangledName(GlobalDecl GD)
QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize, const Expr *SizeExpr, ArrayType::ArraySizeModifier ASM, unsigned IndexTypeQuals) const
Return the unique reference to the type for a constant array of the specified element type...
Internal linkage, which indicates that the entity can be referred to from within the translation unit...
llvm::Value * createOpenCLIntToSamplerConversion(const Expr *E, CodeGenFunction &CGF)
void addDecl(Decl *D)
Add the declaration D into this context.
CGCUDARuntime * CreateNVCUDARuntime(CodeGenModule &CGM)
Creates an instance of a CUDA runtime class.
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat]...
CodeGenTBAA - This class organizes the cross-module state that is used while lowering AST types to LL...
Represents a base class of a C++ class.
static const char AnnotationSection[]
SourceManager & getSourceManager()
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types...
llvm::ConstantInt * getSize(CharUnits numChars)
Emit the given number of characters as a value of type size_t.
bool isInlined() const
Determine whether this function should be inlined, because it is either marked "inline" or "constexpr...
QualType withCVRQualifiers(unsigned CVR) const
llvm::iterator_range< specific_attr_iterator< T > > specific_attrs() const
ArrayBuilder beginArray(llvm::Type *eltTy=nullptr)
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
StringRef getUuidStr() const
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
int64_t toBits(CharUnits CharSize) const
Convert a size in characters to a size in bits.
TranslationUnitDecl * getTranslationUnitDecl() const
virtual LangAS getASTAllocaAddressSpace() const
Get the AST address space for alloca.
Interoperability with the Swift 4.2 runtime.
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Represents a C++ struct/union/class.
CGCXXABI * CreateItaniumCXXABI(CodeGenModule &CGM)
Creates an Itanium-family ABI.
bool isTLSSupported() const
Whether the target supports thread-local storage.
A specialization of Address that requires the address to be an LLVM Constant.
ObjCIvarDecl - Represents an ObjC instance variable.
static bool HasNonDllImportDtor(QualType T)
void Release()
Finalize LLVM code generation.
static bool shouldBeInCOMDAT(CodeGenModule &CGM, const Decl &D)
void ClearUnusedCoverageMapping(const Decl *D)
Remove the deferred empty coverage mapping as this declaration is actually instrumented.
ASTImporterLookupTable & LT
Builtin::Context & BuiltinInfo
virtual void mangleStringLiteral(const StringLiteral *SL, raw_ostream &)=0
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
void EmitGlobalAnnotations()
Emit all the global annotations.
bool hasExternalStorage() const
Returns true if a variable has extern or private_extern storage.
llvm::ConstantInt * CreateCrossDsoCfiTypeId(llvm::Metadata *MD)
Generate a cross-DSO type identifier for MD.
void getFunctionFeatureMap(llvm::StringMap< bool > &FeatureMap, const FunctionDecl *) const
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
bool has(SanitizerMask K) const
Check if a certain (single) sanitizer is enabled.
uint64_t getPointerAlign(unsigned AddrSpace) const
StringLiteral - This represents a string literal expression, e.g.
Defines the clang::TargetInfo interface.
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
void finalize(llvm::GlobalVariable *global)
bool isMicrosoft() const
Is this ABI an MSVC-compatible ABI?
bool getExpressionLocationsEnabled() const
Return true if we should emit location information for expressions.
void RefreshTypeCacheForClass(const CXXRecordDecl *RD)
Remove stale types from the type cache when an inheritance model gets assigned to a class...
void EmitMultiVersionResolver(llvm::Function *Resolver, ArrayRef< MultiVersionResolverOption > Options)
bool doesThisDeclarationHaveABody() const
Returns whether this specific declaration of the function has a body.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
CGCXXABI & getCXXABI() const
llvm::GlobalVariable * CreateOrReplaceCXXRuntimeVariable(StringRef Name, llvm::Type *Ty, llvm::GlobalValue::LinkageTypes Linkage, unsigned Alignment)
Will return a global variable of the given type.
QualType getObjCFastEnumerationStateType()
Retrieve the record type that describes the state of an Objective-C fast enumeration loop (for...
decl_type * getMostRecentDecl()
Returns the most recent (re)declaration of this declaration.
The top declaration context.
unsigned char SizeSizeInBytes
A reference to a declared variable, function, enum, etc.
NamedDecl * getMostRecentDecl()
GVALinkage
A more specific kind of linkage than enum Linkage.
bool isPointerType() const
struct clang::CodeGen::CodeGenFunction::MultiVersionResolverOption::Conds Conditions
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
DefinitionKind isThisDeclarationADefinition(ASTContext &) const
Check whether this declaration is a definition.
static llvm::Constant * GetPointerConstant(llvm::LLVMContext &Context, const void *Ptr)
Turns the given pointer into a constant.
CodeGenVTables & getVTables()
ObjCMethodDecl * getGetterMethodDecl() const
This represents a decl that may have a name.
ObjCIvarDecl * all_declared_ivar_begin()
all_declared_ivar_begin - return first ivar declared in this class, its extensions and its implementa...
void setAccess(AccessSpecifier AS)
static void replaceUsesOfNonProtoConstant(llvm::Constant *old, llvm::Function *newFn)
Replace the uses of a function that was declared with a non-proto type.
bool DeclMustBeEmitted(const Decl *D)
Determines if the decl can be CodeGen'ed or deserialized from PCH lazily, only when used; this is onl...
A Microsoft C++ __uuidof expression, which gets the _GUID that corresponds to the supplied type or ex...
bool isConstant(const ASTContext &Ctx) const
unsigned getTargetAddressSpace(QualType T) const
void EmitCfiCheckStub()
Emit a stub for the cross-DSO CFI check function.
void mangleCtorBlock(const CXXConstructorDecl *CD, CXXCtorType CT, const BlockDecl *BD, raw_ostream &Out)
static FieldDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, Expr *BW, bool Mutable, InClassInitStyle InitStyle)
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
Expr * getSubExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue...
const LangOptions & getLangOpts() const
unsigned getNumIvarInitializers() const
getNumArgs - Number of ivars which must be initialized.
FullSourceLoc getFullLoc(SourceLocation Loc) const
This represents '#pragma omp threadprivate ...' directive.
bool isTemplated() const
Determine whether this declaration is a templated entity (whether it is.
Represents the canonical version of C arrays with a specified constant size.
This class handles loading and caching of source files into memory.
void EmitGlobal(GlobalDecl D)
Emit code for a single global function or var decl.
Defines enum values for all the target-independent builtin functions.
bool Sub(InterpState &S, CodePtr OpPC)
void AddDependentLib(StringRef Lib)
Appends a dependent lib to the appropriate metadata value.
llvm::GlobalValue::LinkageTypes getLLVMLinkageForDeclarator(const DeclaratorDecl *D, GVALinkage Linkage, bool IsConstantVariable)
Returns LLVM linkage for a declarator.
Attr - This represents one attribute.
InlineVariableDefinitionKind getInlineVariableDefinitionKind(const VarDecl *VD) const
Determine whether a definition of this inline variable should be treated as a weak or strong definiti...
SourceLocation getLocation() const
bool isExternallyVisible() const
virtual std::string getDeviceStubName(llvm::StringRef Name) const =0
Construct and return the stub name of a kernel.
static OMPLinearClause * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef< Expr *> VL, ArrayRef< Expr *> PL, ArrayRef< Expr *> IL, Expr *Step, Expr *CalcStep, Stmt *PreInit, Expr *PostUpdate)
Creates clause with a list of variables VL and a linear step Step.
PrettyStackTraceDecl - If a crash occurs, indicate that it happened when doing something to a specifi...
void setDLLImportDLLExport(llvm::GlobalValue *GV, GlobalDecl D) const
static CharUnits getDeclAlign(Expr *E, CharUnits TypeAlign, ASTContext &Context)
A helper function to get the alignment of a Decl referred to by DeclRefExpr or MemberExpr.
CGObjCRuntime * CreateGNUObjCRuntime(CodeGenModule &CGM)
Creates an instance of an Objective-C runtime class.
llvm::FunctionType * GetFunctionType(const CGFunctionInfo &Info)
GetFunctionType - Get the LLVM function type for.
const llvm::Triple & getTriple() const