Lines Matching +full:riscv +full:- +full:v +full:- +full:spec
1 //===--- CodeGenModule.cpp - Emit LLVM Code from ASTs for a Module --------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This coordinates the per-module state used while generating code.
11 //===----------------------------------------------------------------------===//
84 "limited-coverage-experimental", llvm::cl::Hidden,
150 else if (Target.getABI() == "aapcs-soft") in createTargetCodeGenInfo()
161 if (Target.getABI() == "experimental-mv") in createTargetCodeGenInfo()
175 if (ABIStr == "apcs-gnu") in createTargetCodeGenInfo()
212 assert(Triple.isOSBinFormatELF() && "PPC64 LE non-ELF not supported!"); in createTargetCodeGenInfo()
303 bool IsSoftFloat = !Target.hasFeature("hard-float-abi"); in createTargetCodeGenInfo()
524 NewF = dyn_cast<llvm::Function>(Alias->getAliasee()); in applyReplacements()
527 assert(CE->getOpcode() == llvm::Instruction::BitCast || in applyReplacements()
528 CE->getOpcode() == llvm::Instruction::GetElementPtr); in applyReplacements()
529 NewF = dyn_cast<llvm::Function>(CE->getOperand(0)); in applyReplacements()
534 OldF->replaceAllUsesWith(Replacement); in applyReplacements()
536 NewF->removeFromParent(); in applyReplacements()
537 OldF->getParent()->getFunctionList().insertAfter(OldF->getIterator(), in applyReplacements()
540 OldF->eraseFromParent(); in applyReplacements()
553 GV->replaceAllUsesWith(C); in applyGlobalValReplacements()
554 GV->eraseFromParent(); in applyGlobalValReplacements()
563 C = GA->getAliasee(); in getAliasedGlobal()
565 C = GI->getResolver(); in getAliasedGlobal()
569 const auto *AliaseeGV = dyn_cast<llvm::GlobalValue>(C->stripPointerCasts()); in getAliasedGlobal()
573 const llvm::GlobalValue *FinalGV = AliaseeGV->getAliaseeObject(); in getAliasedGlobal()
591 if (GV->hasCommonLinkage()) { in checkAliasedGlobal()
599 if (GV->isDeclaration()) { in checkAliasedGlobal()
607 if (ND->getName() == GV->getName()) { in checkAliasedGlobal()
629 llvm::FunctionType *FTy = F->getFunctionType(); in checkAliasedGlobal()
630 if (!FTy->getReturnType()->isPointerTy()) { in checkAliasedGlobal()
639 // Emit a warning if toc-data attribute is requested for global variables that
640 // have aliases and remove the toc-data attribute.
645 if (GVar->hasAttribute("toc-data")) { in checkAliasForTocData()
646 auto GVId = GVar->getName(); in checkAliasForTocData()
652 llvm::AttributeSet CurrAttributes = GVar->getAttributes(); in checkAliasForTocData()
654 CurrAttributes.removeAttribute(GVar->getContext(), "toc-data"); in checkAliasForTocData()
655 GVar->setAttributes(NewAttributes); in checkAliasForTocData()
669 bool IsIFunc = D->hasAttr<IFuncAttr>(); in checkAliases()
670 if (const Attr *A = D->getDefiningAttr()) { in checkAliases()
671 Location = A->getLocation(); in checkAliases()
672 Range = A->getRange(); in checkAliases()
692 IsIFunc ? cast<llvm::GlobalIFunc>(Alias)->getResolver() in checkAliases()
693 : cast<llvm::GlobalAlias>(Alias)->getAliasee(); in checkAliases()
697 AliaseeGV = cast<llvm::GlobalValue>(CE->getOperand(0)); in checkAliases()
701 if (const SectionAttr *SA = D->getAttr<SectionAttr>()) { in checkAliases()
702 StringRef AliasSection = SA->getName(); in checkAliases()
703 if (AliasSection != AliaseeGV->getSection()) in checkAliases()
704 Diags.Report(SA->getLocation(), diag::warn_alias_with_section) in checkAliases()
714 if (GA->isInterposable()) { in checkAliases()
716 << GV->getName() << GA->getName() << IsIFunc; in checkAliases()
718 GA->getAliasee(), Alias->getType()); in checkAliases()
721 cast<llvm::GlobalIFunc>(Alias)->setResolver(Aliasee); in checkAliases()
723 cast<llvm::GlobalAlias>(Alias)->setAliasee(Aliasee); in checkAliases()
729 cast<llvm::Function>(Aliasee)->addFnAttr( in checkAliases()
738 Alias->replaceAllUsesWith(llvm::UndefValue::get(Alias->getType())); in checkAliases()
739 Alias->eraseFromParent(); in checkAliases()
748 OpenMPRuntime->clear(); in clear()
785 std::optional<llvm::GlobalValue::VisibilityTypes> V) { in setLLVMVisibility() argument
786 if (!V) in setLLVMVisibility()
795 GV.setVisibility(*V); in setLLVMVisibility()
847 if (CXX20ModuleInits && Primary && !Primary->isHeaderLikeModule()) in Release()
861 GlobalTopLevelStmtBlockInFlight.first->FinishFunction(TLSD->getEndLoc()); in Release()
867 if (CXX20ModuleInits && Primary && Primary->isInterfaceOrPartition()) in Release()
875 if (llvm::Function *ObjCInitFunction = ObjCRuntime->ModuleInitFunction()) in Release()
878 if (llvm::Function *CudaCtorFunction = CUDARuntime->finalizeModule()) in Release()
882 OpenMPRuntime->createOffloadEntriesAndInfoMetadata(); in Release()
883 OpenMPRuntime->clear(); in Release()
887 PGOReader->getSummary(/* UseCS */ false).getMD(VMContext), in Release()
904 CoverageMapping->emit(); in Release()
926 // Currently, "-mprintf-kind" option is only supported for HIP in Release()
972 SanStats->finish(); in Release()
990 // Windows. Therefore emit llvm.dependent-libraries only for host. in Release()
992 auto *NMD = getModule().getOrInsertNamedMetadata("llvm.dependent-libraries"); in Release()
994 NMD->addOperand(MD); in Release()
1029 getModule().addModuleFlag(llvm::Module::Warning, "ms-kernel", 1); in Release()
1101 getModule().addModuleFlag(llvm::Module::Error, "target-abi", in Release()
1113 llvm::Module::AppendUnique, "riscv-isa", in Release()
1115 Ctx, llvm::MDString::get(Ctx, (*ParseResult)->toString()))); in Release()
1119 // Indicate that we want cross-DSO control flow integrity checks. in Release()
1120 getModule().addModuleFlag(llvm::Module::Override, "Cross-DSO CFI", 1); in Release()
1138 getModule().addModuleFlag(llvm::Module::Override, "cfi-normalize-integers", in Release()
1144 // KCFI assumes patchable-function-prefix is the same for all indirectly in Release()
1147 getModule().addModuleFlag(llvm::Module::Override, "kcfi-offset", in Release()
1154 getModule().addModuleFlag(llvm::Module::Min, "cf-protection-return", in Release()
1161 getModule().addModuleFlag(llvm::Module::Min, "cf-protection-branch", in Release()
1172 // non-leaf/all) and stack tagging. These are actually turned on by function in Release()
1184 "sign-return-address-buildattr", 1); in Release()
1187 "tag-stack-memory-buildattr", 1); in Release()
1191 getModule().addModuleFlag(llvm::Module::Min, "branch-target-enforcement", in Release()
1194 getModule().addModuleFlag(llvm::Module::Min, "branch-protection-pauth-lr", in Release()
1197 getModule().addModuleFlag(llvm::Module::Min, "guarded-control-stack", 1); in Release()
1199 getModule().addModuleFlag(llvm::Module::Min, "sign-return-address", 1); in Release()
1201 getModule().addModuleFlag(llvm::Module::Min, "sign-return-address-all", in Release()
1205 "sign-return-address-with-bkey", 1); in Release()
1230 "aarch64-elf-pauthabi-platform", in Release()
1233 "aarch64-elf-pauthabi-version", in Release()
1241 llvm::Module::Override, "probe-stack", in Release()
1242 llvm::MDString::get(TheModule.getContext(), "inline-asm")); in Release()
1245 getModule().addModuleFlag(llvm::Module::Min, "stack-probe-size", in Release()
1259 getModule().addModuleFlag(llvm::Module::Override, "nvvm-reflect-ftz", in Release()
1265 getModule().addModuleFlag(llvm::Module::Warning, "eh-asynch", 1); in Release()
1267 // Indicate whether this Module was compiled with -fopenmp in Release()
1271 getModule().addModuleFlag(llvm::Module::Max, "openmp-device", in Release()
1279 // SPIR v2.0 s2.12 - The SPIR version used by the module is stored in the in Release()
1292 SPIRVerMD->addOperand(llvm::MDNode::get(Ctx, SPIRVerElts)); in Release()
1363 DI->finalize(); in Release()
1411 if (!I.first->isDefined()) in Release()
1416 if (!Entry || Entry->isWeakForLinker() || in Release()
1417 Entry->isDeclarationForLinker()) in Release()
1425 // SPIR v2.0 s2.13 - The OpenCL version used by the module is stored in the in EmitOpenCLMetadata()
1438 OCLVerMD->addOperand(llvm::MDNode::get(Ctx, OCLVerElts)); in EmitOpenCLMetadata()
1469 return TBAA->getTypeInfo(QTy); in getTBAATypeInfo()
1478 if (AccessType->isCUDADeviceBuiltinSurfaceType()) { in getTBAAAccessInfo()
1482 } else if (AccessType->isCUDADeviceBuiltinTextureType()) { in getTBAAAccessInfo()
1488 return TBAA->getAccessInfo(AccessType); in getTBAAAccessInfo()
1495 return TBAA->getVTablePtrAccessInfo(VTablePtrType); in getTBAAVTablePtrAccessInfo()
1501 return TBAA->getTBAAStructInfo(QTy); in getTBAAStructInfo()
1507 return TBAA->getBaseTypeInfo(QTy); in getTBAABaseTypeInfo()
1513 return TBAA->getAccessTagInfo(Info); in getTBAAAccessTagInfo()
1520 return TBAA->mergeTBAAInfoForCast(SourceInfo, TargetInfo); in mergeTBAAInfoForCast()
1528 return TBAA->mergeTBAAInfoForConditionalOperator(InfoA, InfoB); in mergeTBAAInfoForConditionalOperator()
1536 return TBAA->mergeTBAAInfoForConditionalOperator(DestInfo, SrcInfo); in mergeTBAAInfoForMemoryTransfer()
1542 Inst->setMetadata(llvm::LLVMContext::MD_tbaa, Tag); in DecorateInstructionWithTBAA()
1547 I->setMetadata(llvm::LLVMContext::MD_invariant_group, in DecorateInstructionWithInvariantGroup()
1556 /// ErrorUnsupported - Print out an error that codegen doesn't support the
1562 getDiags().Report(Context.getFullLoc(S->getBeginLoc()), DiagID) in ErrorUnsupported()
1563 << Msg << S->getSourceRange(); in ErrorUnsupported()
1566 /// ErrorUnsupported - Print out an error that codegen doesn't support the
1572 getDiags().Report(Context.getFullLoc(D->getLocation()), DiagID) << Msg; in ErrorUnsupported()
1582 if (GV->hasLocalLinkage()) { in setGlobalVisibility()
1583 GV->setVisibility(llvm::GlobalValue::DefaultVisibility); in setGlobalVisibility()
1591 LinkageInfo LV = D->getLinkageAndVisibility(); in setGlobalVisibility()
1598 D->hasAttr<OMPDeclareTargetDeclAttr>() && in setGlobalVisibility()
1599 D->getAttr<OMPDeclareTargetDeclAttr>()->getDevType() != in setGlobalVisibility()
1602 GV->setVisibility(llvm::GlobalValue::ProtectedVisibility); in setGlobalVisibility()
1606 if (GV->hasDLLExportStorageClass() || GV->hasDLLImportStorageClass()) { in setGlobalVisibility()
1610 if (GV->hasDLLExportStorageClass()) { in setGlobalVisibility()
1612 getDiags().Report(D->getLocation(), in setGlobalVisibility()
1615 getDiags().Report(D->getLocation(), in setGlobalVisibility()
1622 !GV->isDeclarationForLinker()) in setGlobalVisibility()
1623 GV->setVisibility(GetLLVMVisibility(LV.getVisibility())); in setGlobalVisibility()
1628 if (GV->hasLocalLinkage()) in shouldAssumeDSOLocal()
1631 if (!GV->hasDefaultVisibility() && !GV->hasExternalWeakLinkage()) in shouldAssumeDSOLocal()
1635 if (GV->hasDLLImportStorageClass()) in shouldAssumeDSOLocal()
1649 if (GV->isDeclarationForLinker() && isa<llvm::GlobalVariable>(GV) && in shouldAssumeDSOLocal()
1650 (!GV->isThreadLocal() || CGM.getCodeGenOpts().EmulatedTLS) && in shouldAssumeDSOLocal()
1658 if (TT.isOSBinFormatCOFF() && GV->hasExternalWeakLinkage()) in shouldAssumeDSOLocal()
1663 // *-win32-macho triples. This (accidentally?) produced windows relocations in shouldAssumeDSOLocal()
1677 // On ELF, if -fno-semantic-interposition is specified and the target in shouldAssumeDSOLocal()
1679 // -fsemantic-interposition nor -fhalf-no-semantic-interposition. Set in shouldAssumeDSOLocal()
1682 if (!(isa<llvm::Function>(GV) && GV->canBenefitFromLocalAlias())) in shouldAssumeDSOLocal()
1689 if (!GV->isDeclarationForLinker()) in shouldAssumeDSOLocal()
1695 if (RM == llvm::Reloc::PIC_ && GV->hasExternalWeakLinkage()) in shouldAssumeDSOLocal()
1703 // If -fdirect-access-external-data (default for -fno-pic), set dso_local in shouldAssumeDSOLocal()
1704 // for non-thread-local variables. If the symbol is not defined in the in shouldAssumeDSOLocal()
1706 // excluded for thread-local variables because they generally don't support in shouldAssumeDSOLocal()
1709 if (!Var->isThreadLocal()) in shouldAssumeDSOLocal()
1712 // -fno-pic sets dso_local on a function declaration to allow direct in shouldAssumeDSOLocal()
1715 // needed at link time. -fno-direct-access-external-data can avoid the in shouldAssumeDSOLocal()
1716 // canonical PLT entry. We don't generalize this condition to -fpie/-fpic as in shouldAssumeDSOLocal()
1729 GV->setDSOLocal(shouldAssumeDSOLocal(*this, GV)); in setDSOLocal()
1745 if (D && D->isExternallyVisible()) { in setDLLImportDLLExport()
1746 if (D->hasAttr<DLLImportAttr>()) in setDLLImportDLLExport()
1747 GV->setDLLStorageClass(llvm::GlobalVariable::DLLImportStorageClass); in setDLLImportDLLExport()
1748 else if ((D->hasAttr<DLLExportAttr>() || in setDLLImportDLLExport()
1750 !GV->isDeclarationForLinker()) in setDLLImportDLLExport()
1751 GV->setDLLStorageClass(llvm::GlobalVariable::DLLExportStorageClass); in setDLLImportDLLExport()
1771 GV->setPartition(CodeGenOpts.SymbolPartition); in setGVPropertiesAux()
1776 .Case("global-dynamic", llvm::GlobalVariable::GeneralDynamicTLSModel) in GetLLVMTLSModel()
1777 .Case("local-dynamic", llvm::GlobalVariable::LocalDynamicTLSModel) in GetLLVMTLSModel()
1778 .Case("initial-exec", llvm::GlobalVariable::InitialExecTLSModel) in GetLLVMTLSModel()
1779 .Case("local-exec", llvm::GlobalVariable::LocalExecTLSModel); in GetLLVMTLSModel()
1798 assert(D.getTLSKind() && "setting TLS mode on non-TLS var!"); in setTLSMode()
1805 TLM = GetLLVMTLSModel(Attr->getModel()); in setTLSMode()
1808 GV->setThreadLocalMode(TLM); in setTLSMode()
1824 Out << getCPUSpecificMangling(CGM, Attr->getCPUName(CPUIndex)->getName()); in AppendCPUSpecificCPUDispatchMangling()
1850 IdentifierInfo *II = ND->getIdentifier(); in getMangledNameImpl()
1855 FD->getType()->castAs<FunctionType>()->getCallConv() == CC_X86RegCall) { in getMangledNameImpl()
1857 Out << "__regcall4__" << II->getName(); in getMangledNameImpl()
1859 Out << "__regcall3__" << II->getName(); in getMangledNameImpl()
1860 } else if (FD && FD->hasAttr<CUDAGlobalAttr>() && in getMangledNameImpl()
1862 Out << "__device_stub__" << II->getName(); in getMangledNameImpl()
1864 Out << II->getName(); in getMangledNameImpl()
1869 // symbols. This should come before multi-version target suffixes are in getMangledNameImpl()
1883 if (FD->isMultiVersion() && !OmitMultiVersionMangling) { in getMangledNameImpl()
1884 switch (FD->getMultiVersionKind()) { in getMangledNameImpl()
1888 FD->getAttr<CPUSpecificAttr>(), in getMangledNameImpl()
1892 auto *Attr = FD->getAttr<TargetAttr>(); in getMangledNameImpl()
1900 auto *Attr = FD->getAttr<TargetVersionAttr>(); in getMangledNameImpl()
1908 auto *Attr = FD->getAttr<TargetClonesAttr>(); in getMangledNameImpl()
1921 // Make unique name for device side static file-scope variable for HIP. in getMangledNameImpl()
1933 if (!FD->isMultiVersion()) in UpdateMultiVersionNames()
1945 ->getAsFunction() in UpdateMultiVersionNames()
1946 ->isMultiVersion() && in UpdateMultiVersionNames()
1952 ->getAsFunction() in UpdateMultiVersionNames()
1953 ->getMostRecentDecl(); in UpdateMultiVersionNames()
1965 Result.first->first(); in UpdateMultiVersionNames()
1970 Entry->setName(OtherName); in UpdateMultiVersionNames()
1989 // In CUDA/HIP device compilation with -fgpu-rdc, the mangled name of a in getMangledName()
1996 return FoundName->second; in getMangledName()
2007 // very important as the device kernel name being mangled in host-compilation in getMangledName()
2010 // directly between host- and device-compilations, the host- and in getMangledName()
2011 // device-mangling in host compilation could help catching certain ones. in getMangledName()
2012 assert(!isa<FunctionDecl>(ND) || !ND->hasAttr<CUDAGlobalAttr>() || in getMangledName()
2015 (getContext().getAuxTargetInfo()->getCXXABI() != in getMangledName()
2024 return MangledDeclNames[CanonicalGD] = Result.first->first(); in getMangledName()
2045 return Result.first->first(); in getBlockMangledName()
2051 if (it->second == Name) in getMangledNameDecl()
2052 return it->first; in getMangledNameDecl()
2062 /// AddGlobalCtor - Add a function to the list that will be called before
2071 /// AddGlobalDtor - Add a function to the list that will be called
2118 list->setAlignment(std::nullopt); in EmitCtorList()
2139 return llvm::ConstantInt::get(Int64Ty, llvm::MD5Hash(MDS->getString())); in CreateCrossDsoCfiTypeId()
2143 if (auto *FnType = T->getAs<FunctionProtoType>()) in CreateKCFITypeId()
2145 FnType->getReturnType(), FnType->getParamTypes(), in CreateKCFITypeId()
2146 FnType->getExtProtoInfo().withExceptionSpec(EST_None)); in CreateKCFITypeId()
2165 ConstructAttributeList(F->getName(), Info, GD, PAL, CallingConv, in SetLLVMFunctionAttributes()
2171 Loc = D->getLocation(); in SetLLVMFunctionAttributes()
2175 F->setAttributes(PAL); in SetLLVMFunctionAttributes()
2176 F->setCallingConv(static_cast<llvm::CallingConv::ID>(CallingConv)); in SetLLVMFunctionAttributes()
2228 "Incorrect use - FD and CGF should either be both null or not!"); in GenKernelArgMetadata()
2254 for (unsigned i = 0, e = FD->getNumParams(); i != e; ++i) { in GenKernelArgMetadata()
2255 const ParmVarDecl *parm = FD->getParamDecl(i); in GenKernelArgMetadata()
2257 argNames.push_back(llvm::MDString::get(VMContext, parm->getName())); in GenKernelArgMetadata()
2261 QualType ty = parm->getType(); in GenKernelArgMetadata()
2265 if (ty->isImageType() || ty->isPipeType()) { in GenKernelArgMetadata()
2267 if (const auto *TD = ty->getAs<TypedefType>()) in GenKernelArgMetadata()
2268 PDecl = TD->getDecl(); in GenKernelArgMetadata()
2269 const OpenCLAccessAttr *A = PDecl->getAttr<OpenCLAccessAttr>(); in GenKernelArgMetadata()
2270 if (A && A->isWriteOnly()) in GenKernelArgMetadata()
2272 else if (A && A->isReadWrite()) in GenKernelArgMetadata()
2294 if (ty->isPointerType()) { in GenKernelArgMetadata()
2295 QualType pointeeTy = ty->getPointeeType(); in GenKernelArgMetadata()
2299 llvm::ConstantAsMetadata::get(CGF->Builder.getInt32( in GenKernelArgMetadata()
2320 bool isPipe = ty->isPipeType(); in GenKernelArgMetadata()
2321 if (ty->isImageType() || isPipe) in GenKernelArgMetadata()
2325 llvm::ConstantAsMetadata::get(CGF->Builder.getInt32(AddrSpc))); in GenKernelArgMetadata()
2328 ty = isPipe ? ty->castAs<PipeType>()->getElementType() : ty; in GenKernelArgMetadata()
2334 // but OpenCL spec provides a special query to get access qualifier in GenKernelArgMetadata()
2336 if (ty->isImageType()) { in GenKernelArgMetadata()
2352 Fn->setMetadata("kernel_arg_addr_space", in GenKernelArgMetadata()
2354 Fn->setMetadata("kernel_arg_access_qual", in GenKernelArgMetadata()
2356 Fn->setMetadata("kernel_arg_type", in GenKernelArgMetadata()
2358 Fn->setMetadata("kernel_arg_base_type", in GenKernelArgMetadata()
2360 Fn->setMetadata("kernel_arg_type_qual", in GenKernelArgMetadata()
2365 Fn->setMetadata("kernel_arg_name", in GenKernelArgMetadata()
2370 /// unwind exceptions. We treat -fexceptions as mandating this
2372 /// enabled. This means, for example, that C with -fexceptions
2393 !CGM.HasHiddenLTOVisibility(MD->getParent())) in requiresMemberFunctionPointerTypeMetadata()
2398 return MD->isImplicitObjectMemberFunction() && !MD->isVirtual() && in requiresMemberFunctionPointerTypeMetadata()
2408 if (RD->getNumBases() == 0) in getMostBaseClasses()
2410 for (const CXXBaseSpecifier &B : RD->bases()) in getMostBaseClasses()
2411 CollectMostBases(B.getType()->getAsCXXRecordDecl()); in getMostBaseClasses()
2419 llvm::AttrBuilder B(F->getContext()); in SetLLVMFunctionAttributesForDefinition()
2421 if ((!D || !D->hasAttr<NoUwtableAttr>()) && CodeGenOpts.UnwindTables) in SetLLVMFunctionAttributesForDefinition()
2425 B.addAttribute("probe-stack", "inline-asm"); in SetLLVMFunctionAttributesForDefinition()
2428 B.addAttribute("stack-probe-size", in SetLLVMFunctionAttributesForDefinition()
2434 if (D && D->hasAttr<NoStackProtectorAttr>()) in SetLLVMFunctionAttributesForDefinition()
2436 else if (D && D->hasAttr<StrictGuardStackCheckAttr>() && in SetLLVMFunctionAttributesForDefinition()
2450 if (!F->hasFnAttribute(llvm::Attribute::AlwaysInline) && in SetLLVMFunctionAttributesForDefinition()
2454 F->addFnAttrs(B); in SetLLVMFunctionAttributesForDefinition()
2460 if (D->hasAttr<ArmLocallyStreamingAttr>()) in SetLLVMFunctionAttributesForDefinition()
2463 if (auto *Attr = D->getAttr<ArmNewAttr>()) { in SetLLVMFunctionAttributesForDefinition()
2464 if (Attr->isNewZA()) in SetLLVMFunctionAttributesForDefinition()
2466 if (Attr->isNewZT0()) in SetLLVMFunctionAttributesForDefinition()
2475 ShouldAddOptNone &= !D->hasAttr<MinSizeAttr>(); in SetLLVMFunctionAttributesForDefinition()
2476 ShouldAddOptNone &= !D->hasAttr<AlwaysInlineAttr>(); in SetLLVMFunctionAttributesForDefinition()
2479 if ((ShouldAddOptNone || D->hasAttr<OptimizeNoneAttr>()) && in SetLLVMFunctionAttributesForDefinition()
2480 !F->hasFnAttribute(llvm::Attribute::AlwaysInline)) { in SetLLVMFunctionAttributesForDefinition()
2488 if (D->hasAttr<NakedAttr>()) in SetLLVMFunctionAttributesForDefinition()
2492 F->removeFnAttr(llvm::Attribute::OptimizeForSize); in SetLLVMFunctionAttributesForDefinition()
2493 F->removeFnAttr(llvm::Attribute::MinSize); in SetLLVMFunctionAttributesForDefinition()
2494 } else if (D->hasAttr<NakedAttr>()) { in SetLLVMFunctionAttributesForDefinition()
2498 } else if (D->hasAttr<NoDuplicateAttr>()) { in SetLLVMFunctionAttributesForDefinition()
2500 } else if (D->hasAttr<NoInlineAttr>() && !F->hasFnAttribute(llvm::Attribute::AlwaysInline)) { in SetLLVMFunctionAttributesForDefinition()
2503 } else if (D->hasAttr<AlwaysInlineAttr>() && in SetLLVMFunctionAttributesForDefinition()
2504 !F->hasFnAttribute(llvm::Attribute::NoInline)) { in SetLLVMFunctionAttributesForDefinition()
2510 if (!F->hasFnAttribute(llvm::Attribute::AlwaysInline)) in SetLLVMFunctionAttributesForDefinition()
2519 return Redecl->isInlineSpecified(); in SetLLVMFunctionAttributesForDefinition()
2521 if (any_of(FD->redecls(), CheckRedeclForInline)) in SetLLVMFunctionAttributesForDefinition()
2523 const FunctionDecl *Pattern = FD->getTemplateInstantiationPattern(); in SetLLVMFunctionAttributesForDefinition()
2526 return any_of(Pattern->redecls(), CheckRedeclForInline); in SetLLVMFunctionAttributesForDefinition()
2532 !FD->isInlined() && in SetLLVMFunctionAttributesForDefinition()
2533 !F->hasFnAttribute(llvm::Attribute::AlwaysInline)) { in SetLLVMFunctionAttributesForDefinition()
2541 if (!D->hasAttr<OptimizeNoneAttr>()) { in SetLLVMFunctionAttributesForDefinition()
2542 if (D->hasAttr<ColdAttr>()) { in SetLLVMFunctionAttributesForDefinition()
2547 if (D->hasAttr<HotAttr>()) in SetLLVMFunctionAttributesForDefinition()
2549 if (D->hasAttr<MinSizeAttr>()) in SetLLVMFunctionAttributesForDefinition()
2553 F->addFnAttrs(B); in SetLLVMFunctionAttributesForDefinition()
2555 unsigned alignment = D->getMaxAlignment() / Context.getCharWidth(); in SetLLVMFunctionAttributesForDefinition()
2557 F->setAlignment(llvm::Align(alignment)); in SetLLVMFunctionAttributesForDefinition()
2559 if (!D->hasAttr<AlignedAttr>()) in SetLLVMFunctionAttributesForDefinition()
2561 F->setAlignment(llvm::Align(1ull << LangOpts.FunctionAlignment)); in SetLLVMFunctionAttributesForDefinition()
2563 // Some C++ ABIs require 2-byte alignment for member functions, in order to in SetLLVMFunctionAttributesForDefinition()
2564 // reserve a bit for differentiating between virtual and non-virtual member in SetLLVMFunctionAttributesForDefinition()
2568 if (isa<CXXMethodDecl>(D) && F->getPointerAlignment(getDataLayout()) < 2) in SetLLVMFunctionAttributesForDefinition()
2569 F->setAlignment(std::max(llvm::Align(2), F->getAlign().valueOrOne())); in SetLLVMFunctionAttributesForDefinition()
2572 // In the cross-dso CFI mode with canonical jump tables, we want !type in SetLLVMFunctionAttributesForDefinition()
2589 for (const CXXRecordDecl *Base : getMostBaseClasses(MD->getParent())) { in SetLLVMFunctionAttributesForDefinition()
2592 MD->getType(), Context.getRecordType(Base).getTypePtr())); in SetLLVMFunctionAttributesForDefinition()
2593 F->addTypeMetadata(0, Id); in SetLLVMFunctionAttributesForDefinition()
2603 GV->setVisibility(llvm::GlobalValue::DefaultVisibility); in SetCommonAttributes()
2605 if (D && D->hasAttr<UsedAttr>()) in SetCommonAttributes()
2611 (VD->getStorageDuration() == SD_Static || in SetCommonAttributes()
2612 VD->getStorageDuration() == SD_Thread)) || in SetCommonAttributes()
2613 (CodeGenOpts.KeepStaticConsts && VD->getStorageDuration() == SD_Static && in SetCommonAttributes()
2614 VD->getType().isConstQualified()))) in SetCommonAttributes()
2621 // Add target-cpu and target-features attributes to functions. If in GetCPUAndFeaturesAttributes()
2628 FD = FD ? FD->getMostRecentDecl() : FD; in GetCPUAndFeaturesAttributes()
2629 const auto *TD = FD ? FD->getAttr<TargetAttr>() : nullptr; in GetCPUAndFeaturesAttributes()
2630 const auto *TV = FD ? FD->getAttr<TargetVersionAttr>() : nullptr; in GetCPUAndFeaturesAttributes()
2632 const auto *SD = FD ? FD->getAttr<CPUSpecificAttr>() : nullptr; in GetCPUAndFeaturesAttributes()
2633 const auto *TC = FD ? FD->getAttr<TargetClonesAttr>() : nullptr; in GetCPUAndFeaturesAttributes()
2641 Features.push_back((Entry.getValue() ? "+" : "-") + Entry.getKey().str()); in GetCPUAndFeaturesAttributes()
2643 // Now add the target-cpu and target-features to the function. in GetCPUAndFeaturesAttributes()
2649 Target.parseTargetAttr(TD->getFeaturesStr()); in GetCPUAndFeaturesAttributes()
2661 // Apply the given CPU name as the 'tune-cpu' so that the optimizer can in GetCPUAndFeaturesAttributes()
2663 TuneCPU = SD->getCPUName(GD.getMultiVersionIndex())->getName(); in GetCPUAndFeaturesAttributes()
2672 Attrs.addAttribute("target-cpu", TargetCPU); in GetCPUAndFeaturesAttributes()
2676 Attrs.addAttribute("tune-cpu", TuneCPU); in GetCPUAndFeaturesAttributes()
2684 Attrs.addAttribute("target-features", llvm::join(Features, ",")); in GetCPUAndFeaturesAttributes()
2698 if (D->hasAttr<RetainAttr>()) in setNonAliasAttributes()
2700 if (auto *SA = D->getAttr<PragmaClangBSSSectionAttr>()) in setNonAliasAttributes()
2701 GV->addAttribute("bss-section", SA->getName()); in setNonAliasAttributes()
2702 if (auto *SA = D->getAttr<PragmaClangDataSectionAttr>()) in setNonAliasAttributes()
2703 GV->addAttribute("data-section", SA->getName()); in setNonAliasAttributes()
2704 if (auto *SA = D->getAttr<PragmaClangRodataSectionAttr>()) in setNonAliasAttributes()
2705 GV->addAttribute("rodata-section", SA->getName()); in setNonAliasAttributes()
2706 if (auto *SA = D->getAttr<PragmaClangRelroSectionAttr>()) in setNonAliasAttributes()
2707 GV->addAttribute("relro-section", SA->getName()); in setNonAliasAttributes()
2711 if (D->hasAttr<RetainAttr>()) in setNonAliasAttributes()
2713 if (auto *SA = D->getAttr<PragmaClangTextSectionAttr>()) in setNonAliasAttributes()
2714 if (!D->getAttr<SectionAttr>()) in setNonAliasAttributes()
2715 F->setSection(SA->getName()); in setNonAliasAttributes()
2717 llvm::AttrBuilder Attrs(F->getContext()); in setNonAliasAttributes()
2723 RemoveAttrs.addAttribute("target-cpu"); in setNonAliasAttributes()
2724 RemoveAttrs.addAttribute("target-features"); in setNonAliasAttributes()
2725 RemoveAttrs.addAttribute("tune-cpu"); in setNonAliasAttributes()
2726 F->removeFnAttrs(RemoveAttrs); in setNonAliasAttributes()
2727 F->addFnAttrs(Attrs); in setNonAliasAttributes()
2731 if (const auto *CSA = D->getAttr<CodeSegAttr>()) in setNonAliasAttributes()
2732 GO->setSection(CSA->getName()); in setNonAliasAttributes()
2733 else if (const auto *SA = D->getAttr<SectionAttr>()) in setNonAliasAttributes()
2734 GO->setSection(SA->getName()); in setNonAliasAttributes()
2747 F->setLinkage(llvm::Function::InternalLinkage); in SetInternalFunctionAttributes()
2754 LinkageInfo LV = ND->getLinkageAndVisibility(); in setLinkageForGV()
2759 (ND->hasAttr<WeakAttr>() || ND->isWeakImported())) in setLinkageForGV()
2760 GV->setLinkage(llvm::GlobalValue::ExternalWeakLinkage); in setLinkageForGV()
2769 // Non-static class methods are handled via vtable or member function pointer in CreateFunctionTypeMetadataForIcall()
2771 if (isa<CXXMethodDecl>(FD) && !cast<CXXMethodDecl>(FD)->isStatic()) in CreateFunctionTypeMetadataForIcall()
2774 llvm::Metadata *MD = CreateMetadataIdentifierForType(FD->getType()); in CreateFunctionTypeMetadataForIcall()
2775 F->addTypeMetadata(0, MD); in CreateFunctionTypeMetadataForIcall()
2776 F->addTypeMetadata(0, CreateMetadataIdentifierGeneralized(FD->getType())); in CreateFunctionTypeMetadataForIcall()
2778 // Emit a hash-based bit set entry for cross-DSO calls. in CreateFunctionTypeMetadataForIcall()
2781 F->addTypeMetadata(0, llvm::ConstantAsMetadata::get(CrossDsoTypeId)); in CreateFunctionTypeMetadataForIcall()
2785 llvm::LLVMContext &Ctx = F->getContext(); in setKCFIType()
2787 F->setMetadata(llvm::LLVMContext::MD_kcfi_type, in setKCFIType()
2789 Ctx, MDB.createConstant(CreateKCFITypeId(FD->getType())))); in setKCFIType()
2804 // Remove KCFI type metadata from non-address-taken local functions. in finalizeKCFITypes()
2810 // address-taken function declarations to support annotating indirectly in finalizeKCFITypes()
2817 Type = llvm::mdconst::extract<llvm::ConstantInt>(MD->getOperand(0)); in finalizeKCFITypes()
2826 Name + ", " + Twine(Type->getZExtValue()) + "\n") in finalizeKCFITypes()
2836 if (llvm::Intrinsic::ID IID = F->getIntrinsicID()) { in SetFunctionAttributes()
2839 F->setAttributes(llvm::Intrinsic::getAttributes(getLLVMContext(), IID)); in SetFunctionAttributes()
2854 assert(!F->arg_empty() && in SetFunctionAttributes()
2855 F->arg_begin()->getType() in SetFunctionAttributes()
2856 ->canLosslesslyBitCastTo(F->getReturnType()) && in SetFunctionAttributes()
2858 F->addParamAttr(0, llvm::Attribute::Returned); in SetFunctionAttributes()
2867 // Setup target-specific attributes. in SetFunctionAttributes()
2868 if (!IsIncompleteFunction && F->isDeclaration()) in SetFunctionAttributes()
2871 if (const auto *CSA = FD->getAttr<CodeSegAttr>()) in SetFunctionAttributes()
2872 F->setSection(CSA->getName()); in SetFunctionAttributes()
2873 else if (const auto *SA = FD->getAttr<SectionAttr>()) in SetFunctionAttributes()
2874 F->setSection(SA->getName()); in SetFunctionAttributes()
2876 if (const auto *EA = FD->getAttr<ErrorAttr>()) { in SetFunctionAttributes()
2877 if (EA->isError()) in SetFunctionAttributes()
2878 F->addFnAttr("dontcall-error", EA->getUserDiagnostic()); in SetFunctionAttributes()
2879 else if (EA->isWarning()) in SetFunctionAttributes()
2880 F->addFnAttr("dontcall-warn", EA->getUserDiagnostic()); in SetFunctionAttributes()
2884 if (FD->isInlineBuiltinDeclaration()) { in SetFunctionAttributes()
2886 bool HasBody = FD->hasBody(FDBody); in SetFunctionAttributes()
2891 F->addFnAttr(llvm::Attribute::NoBuiltin); in SetFunctionAttributes()
2894 if (FD->isReplaceableGlobalAllocationFunction()) { in SetFunctionAttributes()
2896 // default, only if it is invoked by a new-expression or delete-expression. in SetFunctionAttributes()
2897 F->addFnAttr(llvm::Attribute::NoBuiltin); in SetFunctionAttributes()
2901 F->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global); in SetFunctionAttributes()
2903 if (MD->isVirtual()) in SetFunctionAttributes()
2904 F->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global); in SetFunctionAttributes()
2906 // Don't emit entries for function declarations in the cross-DSO mode. This in SetFunctionAttributes()
2908 // are non-canonical then we need type metadata in order to produce the local in SetFunctionAttributes()
2917 if (getLangOpts().OpenMP && FD->hasAttr<OMPDeclareSimdDeclAttr>()) in SetFunctionAttributes()
2921 F->addFnAttr("inline-max-stacksize", llvm::utostr(CodeGenOpts.InlineMaxStackSize)); in SetFunctionAttributes()
2923 if (const auto *CB = FD->getAttr<CallbackAttr>()) { in SetFunctionAttributes()
2925 // - The callback callee (as argument number). in SetFunctionAttributes()
2926 // - The callback payloads (as argument numbers). in SetFunctionAttributes()
2927 llvm::LLVMContext &Ctx = F->getContext(); in SetFunctionAttributes()
2932 int CalleeIdx = *CB->encoding_begin(); in SetFunctionAttributes()
2933 ArrayRef<int> PayloadIndices(CB->encoding_begin() + 1, CB->encoding_end()); in SetFunctionAttributes()
2934 F->addMetadata(llvm::LLVMContext::MD_callback, in SetFunctionAttributes()
2942 assert((isa<llvm::Function>(GV) || !GV->isDeclaration()) && in addUsedGlobal()
2948 assert(!GV->isDeclaration() && in addCompilerUsedGlobal()
2954 assert((isa<llvm::Function>(GV) || !GV->isDeclaration()) && in addUsedOrCompilerUsedGlobal()
2985 GV->setSection("llvm.metadata"); in emitUsed()
3027 if (Mod->Parent && Visited.insert(Mod->Parent).second) { in addLinkOptionsPostorder()
3028 addLinkOptionsPostorder(CGM, Mod->Parent, Metadata, Visited); in addLinkOptionsPostorder()
3032 for (Module *Import : llvm::reverse(Mod->Imports)) { in addLinkOptionsPostorder()
3044 if (Mod->UseExportAsModuleLinkName) in addLinkOptionsPostorder()
3047 for (const Module::LinkLibrary &LL : llvm::reverse(Mod->LinkLibraries)) { in addLinkOptionsPostorder()
3051 llvm::Metadata *Args[2] = {llvm::MDString::get(Context, "-framework"), in addLinkOptionsPostorder()
3075 assert(Primary->isNamedModuleUnit() && in EmitModuleInitializers()
3078 // Emit the initializers in the order that sub-modules appear in the in EmitModuleInitializers()
3080 if (auto GMF = Primary->getGlobalModuleFragment()) { in EmitModuleInitializers()
3096 if (auto PMF = Primary->getPrivateModuleFragment()) { in EmitModuleInitializers()
3110 // non-explicit child modules. in EmitModuleLinkOptions()
3119 if (M->getTopLevelModuleName() == getLangOpts().CurrentModule && in EmitModuleLinkOptions()
3127 // non-leaf modules. in EmitModuleLinkOptions()
3134 for (const auto &SM : Mod->submodules()) { in EmitModuleLinkOptions()
3137 if (SM->IsExplicit) in EmitModuleLinkOptions()
3167 NMD->addOperand(MD); in EmitModuleLinkOptions()
3218 // Make sure GetGlobalValue returned non-null. in EmitDeferred()
3223 // deferred-decls queue multiple times, and second, decls can end in EmitDeferred()
3227 if (!GV->isDeclaration()) in EmitDeferred()
3231 if (LangOpts.OpenMP && OpenMPRuntime && OpenMPRuntime->emitTargetGlobal(D)) in EmitDeferred()
3278 Annotations[0]->getType(), Annotations.size()), Annotations); in EmitGlobalAnnotations()
3279 auto *gv = new llvm::GlobalVariable(getModule(), Array->getType(), false, in EmitGlobalAnnotations()
3282 gv->setSection(AnnotationSection); in EmitGlobalAnnotations()
3293 getModule(), s->getType(), true, llvm::GlobalValue::PrivateLinkage, s, in EmitAnnotationString()
3295 ConstGlobalsPtrTy->getAddressSpace()); in EmitAnnotationString()
3296 gv->setSection(AnnotationSection); in EmitAnnotationString()
3297 gv->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global); in EmitAnnotationString()
3319 ArrayRef<Expr *> Exprs = {Attr->args_begin(), Attr->args_size()}; in EmitAnnotationArgs()
3325 ID.Add(cast<clang::ConstantExpr>(E)->getAPValueResult()); in EmitAnnotationArgs()
3336 return ConstEmiter.emitAbstract(CE->getBeginLoc(), CE->getAPValueResult(), in EmitAnnotationArgs()
3337 CE->getType()); in EmitAnnotationArgs()
3340 auto *GV = new llvm::GlobalVariable(getModule(), Struct->getType(), true, in EmitAnnotationArgs()
3343 GV->setSection(AnnotationSection); in EmitAnnotationArgs()
3344 GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global); in EmitAnnotationArgs()
3354 llvm::Constant *AnnoGV = EmitAnnotationString(AA->getAnnotation()), in EmitAnnotateAttr()
3360 if (GV->getAddressSpace() != in EmitAnnotateAttr()
3365 GV->getContext(), getDataLayout().getDefaultGlobalsAddressSpace())); in EmitAnnotateAttr()
3377 assert(D->hasAttr<AnnotateAttr>() && "no annotate attribute"); in AddGlobalAnnotations()
3379 for (const auto *I : D->specific_attrs<AnnotateAttr>()) in AddGlobalAnnotations()
3380 Annotations.push_back(EmitAnnotateAttr(GV, I, D->getLocation())); in AddGlobalAnnotations()
3387 if (NoSanitizeL.containsFunction(Kind, Fn->getName())) in isInNoSanitizeList()
3398 // If location is unknown, this may be a compiler-generated function. Assume in isInNoSanitizeList()
3408 if (NoSanitizeL.containsGlobal(Kind, GV->getName(), Category)) in isInNoSanitizeList()
3412 Kind, SM.getFileEntryRefForID(SM.getMainFileID())->getName(), in isInNoSanitizeList()
3423 Ty = AT->getElementType(); in isInNoSanitizeList()
3426 if (Ty->isRecordType()) { in isInNoSanitizeList()
3443 Attr = XRayFilter.shouldImbueFunction(Fn->getName()); in imbueXRayAttrs()
3448 Fn->addFnAttr("function-instrument", "xray-always"); in imbueXRayAttrs()
3451 Fn->addFnAttr("function-instrument", "xray-always"); in imbueXRayAttrs()
3452 Fn->addFnAttr("xray-log-args", "1"); in imbueXRayAttrs()
3455 Fn->addFnAttr("function-instrument", "xray-never"); in imbueXRayAttrs()
3470 if (auto V = ProfileList.isFunctionExcluded(Fn->getName(), Kind)) in isFunctionBlockedByProfileList() local
3471 return *V; in isFunctionBlockedByProfileList()
3474 if (auto V = ProfileList.isLocationExcluded(Loc, Kind)) in isFunctionBlockedByProfileList() local
3475 return *V; in isFunctionBlockedByProfileList()
3476 // If location is unknown, this may be a compiler-generated function. Assume in isFunctionBlockedByProfileList()
3480 if (auto V = ProfileList.isFileExcluded(MainFile->getName(), Kind)) in isFunctionBlockedByProfileList() local
3481 return *V; in isFunctionBlockedByProfileList()
3488 auto V = isFunctionBlockedByProfileList(Fn, Loc); in isFunctionBlockedFromProfileInstr() local
3489 if (V != ProfileList::Allow) in isFunctionBlockedFromProfileInstr()
3490 return V; in isFunctionBlockedFromProfileInstr()
3494 auto Group = llvm::crc32(arrayRefFromStringRef(Fn->getName())) % NumGroups; in isFunctionBlockedFromProfileInstr()
3509 (VD->getStorageDuration() == SD_Static || in MustBeEmitted()
3510 VD->getStorageDuration() == SD_Thread)) || in MustBeEmitted()
3511 (CodeGenOpts.KeepStaticConsts && VD->getStorageDuration() == SD_Static && in MustBeEmitted()
3512 VD->getType().isConstQualified()))) in MustBeEmitted()
3523 // we have if the level of the declare target attribute is -1. Note that we in MayBeEmittedEagerly()
3528 if (!ActiveAttr || (*ActiveAttr)->getLevel() != (unsigned)-1) in MayBeEmittedEagerly()
3533 if (FD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation) in MayBeEmittedEagerly()
3538 if (FD->hasAttr<TargetVersionAttr>() && !FD->isMultiVersion()) in MayBeEmittedEagerly()
3547 if (CXX20ModuleInits && VD->getOwningModule() && in MayBeEmittedEagerly()
3548 !VD->getOwningModule()->isModuleMapModule()) { in MayBeEmittedEagerly()
3549 // For CXX20, module-owned initializers need to be deferred, since it is in MayBeEmittedEagerly()
3559 !Global->getType().isConstantStorage(getContext(), false, false) && in MayBeEmittedEagerly()
3574 return ConstantAddress(GV, GV->getValueType(), Alignment); in GetAddrOfMSGuidDecl()
3579 APValue &V = GD->getAsAPValue(); in GetAddrOfMSGuidDecl() local
3580 if (!V.isAbsent()) { in GetAddrOfMSGuidDecl()
3584 GD->getAsAPValue(), GD->getType().getAddressSpace(), GD->getType()); in GetAddrOfMSGuidDecl()
3590 MSGuidDecl::Parts Parts = GD->getParts(); in GetAddrOfMSGuidDecl()
3602 getModule(), Init->getType(), in GetAddrOfMSGuidDecl()
3605 GV->setComdat(TheModule.getOrInsertComdat(GV->getName())); in GetAddrOfMSGuidDecl()
3608 if (!V.isAbsent()) { in GetAddrOfMSGuidDecl()
3610 return ConstantAddress(GV, GV->getValueType(), Alignment); in GetAddrOfMSGuidDecl()
3613 llvm::Type *Ty = getTypes().ConvertTypeForMem(GD->getType()); in GetAddrOfMSGuidDecl()
3619 CharUnits Alignment = getContext().getTypeAlignInChars(GCD->getType()); in GetAddrOfUnnamedGlobalConstantDecl()
3624 return ConstantAddress(*Entry, (*Entry)->getValueType(), Alignment); in GetAddrOfUnnamedGlobalConstantDecl()
3629 const APValue &V = GCD->getValue(); in GetAddrOfUnnamedGlobalConstantDecl() local
3631 assert(!V.isAbsent()); in GetAddrOfUnnamedGlobalConstantDecl()
3632 Init = Emitter.emitForInitializer(V, GCD->getType().getAddressSpace(), in GetAddrOfUnnamedGlobalConstantDecl()
3633 GCD->getType()); in GetAddrOfUnnamedGlobalConstantDecl()
3635 auto *GV = new llvm::GlobalVariable(getModule(), Init->getType(), in GetAddrOfUnnamedGlobalConstantDecl()
3639 GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global); in GetAddrOfUnnamedGlobalConstantDecl()
3640 GV->setAlignment(Alignment.getAsAlign()); in GetAddrOfUnnamedGlobalConstantDecl()
3645 return ConstantAddress(GV, GV->getValueType(), Alignment); in GetAddrOfUnnamedGlobalConstantDecl()
3651 CharUnits Alignment = getNaturalTypeAlignment(TPO->getType()); in GetAddrOfTemplateParamObject()
3654 return ConstantAddress(GV, GV->getValueType(), Alignment); in GetAddrOfTemplateParamObject()
3658 TPO->getValue(), TPO->getType().getAddressSpace(), TPO->getType()); in GetAddrOfTemplateParamObject()
3666 isExternallyVisible(TPO->getLinkageAndVisibility().getLinkage()) in GetAddrOfTemplateParamObject()
3669 auto *GV = new llvm::GlobalVariable(getModule(), Init->getType(), in GetAddrOfTemplateParamObject()
3673 GV->setComdat(TheModule.getOrInsertComdat(GV->getName())); in GetAddrOfTemplateParamObject()
3676 return ConstantAddress(GV, GV->getValueType(), Alignment); in GetAddrOfTemplateParamObject()
3680 const AliasAttr *AA = VD->getAttr<AliasAttr>(); in GetWeakRefReference()
3684 llvm::Type *DeclTy = getTypes().ConvertTypeForMem(VD->getType()); in GetWeakRefReference()
3687 llvm::GlobalValue *Entry = GetGlobalValue(AA->getAliasee()); in GetWeakRefReference()
3693 Aliasee = GetOrCreateLLVMFunction(AA->getAliasee(), DeclTy, in GetWeakRefReference()
3697 Aliasee = GetOrCreateLLVMGlobal(AA->getAliasee(), DeclTy, LangAS::Default, in GetWeakRefReference()
3701 F->setLinkage(llvm::Function::ExternalWeakLinkage); in GetWeakRefReference()
3710 if (auto *A = D->getAttr<AttrT>()) in hasImplicitAttr()
3711 return A->isImplicit(); in hasImplicitAttr()
3712 return D->isImplicit(); in hasImplicitAttr()
3716 assert(LangOpts.CUDA && "Should not be called by non-CUDA languages"); in shouldEmitCUDAGlobalVar()
3717 // We need to emit host-side 'shadows' for all global in shouldEmitCUDAGlobalVar()
3718 // device-side variables because the CUDA runtime needs their in shouldEmitCUDAGlobalVar()
3719 // size and host-side address in order to provide access to in shouldEmitCUDAGlobalVar()
3720 // their device-side incarnations. in shouldEmitCUDAGlobalVar()
3721 return !LangOpts.CUDAIsDevice || Global->hasAttr<CUDADeviceAttr>() || in shouldEmitCUDAGlobalVar()
3722 Global->hasAttr<CUDAConstantAttr>() || in shouldEmitCUDAGlobalVar()
3723 Global->hasAttr<CUDASharedAttr>() || in shouldEmitCUDAGlobalVar()
3724 Global->getType()->isCUDADeviceBuiltinSurfaceType() || in shouldEmitCUDAGlobalVar()
3725 Global->getType()->isCUDADeviceBuiltinTextureType(); in shouldEmitCUDAGlobalVar()
3732 if (Global->hasAttr<WeakRefAttr>()) in EmitGlobal()
3737 if (Global->hasAttr<AliasAttr>()) in EmitGlobal()
3741 if (Global->hasAttr<IFuncAttr>()) in EmitGlobal()
3745 if (Global->hasAttr<CPUDispatchAttr>()) in EmitGlobal()
3749 // Non-constexpr non-lambda implicit host device functions are not emitted in EmitGlobal()
3759 if ((!Global->hasAttr<CUDADeviceAttr>() || in EmitGlobal()
3762 hasImplicitAttr<CUDADeviceAttr>(FD) && !FD->isConstexpr() && in EmitGlobal()
3765 !Global->hasAttr<CUDAGlobalAttr>() && in EmitGlobal()
3767 !Global->hasAttr<CUDAHostAttr>())) in EmitGlobal()
3769 // Device-only functions are the only things we skip. in EmitGlobal()
3770 } else if (!Global->hasAttr<CUDAHostAttr>() && in EmitGlobal()
3771 Global->hasAttr<CUDADeviceAttr>()) in EmitGlobal()
3777 if (OpenMPRuntime && OpenMPRuntime->emitTargetGlobal(GD)) in EmitGlobal()
3795 if (FD->hasAttr<AnnotateAttr>()) { in EmitGlobal()
3802 if (!FD->doesThisDeclarationHaveABody()) { in EmitGlobal()
3803 if (!FD->doesDeclarationForceExternallyVisibleDefinition() && in EmitGlobal()
3804 (!FD->isMultiVersion() || !getTarget().getTriple().isAArch64())) in EmitGlobal()
3819 assert(VD->isFileVarDecl() && "Cannot emit local var decl as global."); in EmitGlobal()
3820 if (VD->isThisDeclarationADefinition() != VarDecl::Definition && in EmitGlobal()
3823 // Emit declaration of the must-be-emitted declare target variable. in EmitGlobal()
3829 if (VD->hasExternalStorage() && in EmitGlobal()
3873 cast<VarDecl>(Global)->hasInit()) { in EmitGlobal()
3896 if (const auto *RT = T->getBaseElementTypeUnsafe()->getAs<RecordType>()) in HasNonDllImportDtor()
3897 if (CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(RT->getDecl())) in HasNonDllImportDtor()
3898 if (RD->getDestructor() && !RD->getDestructor()->hasAttr<DLLImportAttr>()) in HasNonDllImportDtor()
3913 const FunctionDecl *FD = E->getDirectCallee(); in VisitCallExpr()
3916 AsmLabelAttr *Attr = FD->getAttr<AsmLabelAttr>(); in VisitCallExpr()
3917 if (Attr && Name == Attr->getLabel()) in VisitCallExpr()
3919 unsigned BuiltinID = FD->getBuiltinID(); in VisitCallExpr()
3931 for (const Stmt *Child : S->children()) in VisitStmt()
3932 if (Child && this->Visit(Child)) in VisitStmt()
3938 // Make sure we're not referencing non-imported vars or functions.
3946 if (VD->getTLSKind()) { in VisitVarDecl()
3947 // A thread-local variable cannot be imported. in VisitVarDecl()
3953 if (VD->isThisDeclarationADefinition()) in VisitVarDecl()
3954 SafeToInline = !HasNonDllImportDtor(VD->getType()); in VisitVarDecl()
3960 if (const auto *D = E->getTemporary()->getDestructor()) in VisitCXXBindTemporaryExpr()
3961 SafeToInline = D->hasAttr<DLLImportAttr>(); in VisitCXXBindTemporaryExpr()
3966 ValueDecl *VD = E->getDecl(); in VisitDeclRefExpr()
3968 SafeToInline = VD->hasAttr<DLLImportAttr>(); in VisitDeclRefExpr()
3969 else if (VarDecl *V = dyn_cast<VarDecl>(VD)) in VisitDeclRefExpr() local
3970 SafeToInline = !V->hasGlobalStorage() || V->hasAttr<DLLImportAttr>(); in VisitDeclRefExpr()
3975 SafeToInline = E->getConstructor()->hasAttr<DLLImportAttr>(); in VisitCXXConstructExpr()
3980 CXXMethodDecl *M = E->getMethodDecl(); in VisitCXXMemberCallExpr()
3985 SafeToInline = M->hasAttr<DLLImportAttr>(); in VisitCXXMemberCallExpr()
3991 SafeToInline = E->getOperatorDelete()->hasAttr<DLLImportAttr>(); in VisitCXXDeleteExpr()
3996 SafeToInline = E->getOperatorNew()->hasAttr<DLLImportAttr>(); in VisitCXXNewExpr()
4002 // isTriviallyRecursive - Check if this function calls another
4010 AsmLabelAttr *Attr = FD->getAttr<AsmLabelAttr>(); in isTriviallyRecursive()
4013 Name = Attr->getLabel(); in isTriviallyRecursive()
4015 Name = FD->getName(); in isTriviallyRecursive()
4019 const Stmt *Body = FD->getBody(); in isTriviallyRecursive()
4028 if (CodeGenOpts.OptimizationLevel == 0 && !F->hasAttr<AlwaysInlineAttr>()) in shouldEmitFunction()
4033 if (const Module *M = F->getOwningModule(); in shouldEmitFunction()
4034 M && M->getTopLevelModule()->isNamedModule() && in shouldEmitFunction()
4035 getContext().getCurrentNamedModule() != M->getTopLevelModule()) { in shouldEmitFunction()
4036 // There are practices to mark template member function as always-inline in shouldEmitFunction()
4039 // from explicitly instantiation with always-inline. in shouldEmitFunction()
4041 // See https://github.com/llvm/llvm-project/issues/86893 for details. in shouldEmitFunction()
4043 // TODO: Maybe it is better to give it a warning if we call a non-inline in shouldEmitFunction()
4044 // function from other module units which is marked as always-inline. in shouldEmitFunction()
4045 if (!F->isTemplateInstantiation() || !F->hasAttr<AlwaysInlineAttr>()) { in shouldEmitFunction()
4050 if (F->hasAttr<NoInlineAttr>()) in shouldEmitFunction()
4053 if (F->hasAttr<DLLImportAttr>() && !F->hasAttr<AlwaysInlineAttr>()) { in shouldEmitFunction()
4063 for (const Decl *Member : Dtor->getParent()->decls()) in shouldEmitFunction()
4065 if (HasNonDllImportDtor(cast<FieldDecl>(Member)->getType())) in shouldEmitFunction()
4067 for (const CXXBaseSpecifier &B : Dtor->getParent()->bases()) in shouldEmitFunction()
4075 if (F->isInlineBuiltinDeclaration()) in shouldEmitFunction()
4094 if (FD->isCPUSpecificMultiVersion()) { in EmitMultiVersionFunctionDefinition()
4095 auto *Spec = FD->getAttr<CPUSpecificAttr>(); in EmitMultiVersionFunctionDefinition() local
4096 for (unsigned I = 0; I < Spec->cpus_size(); ++I) in EmitMultiVersionFunctionDefinition()
4098 } else if (auto *TC = FD->getAttr<TargetClonesAttr>()) { in EmitMultiVersionFunctionDefinition()
4099 for (unsigned I = 0; I < TC->featuresStrs_size(); ++I) in EmitMultiVersionFunctionDefinition()
4101 if ((!TC->isDefaultVersion(I) || !getTarget().getTriple().isAArch64()) && in EmitMultiVersionFunctionDefinition()
4102 TC->isFirstOfVersion(I)) in EmitMultiVersionFunctionDefinition()
4111 if (FD->isTargetVersionMultiVersion()) in EmitMultiVersionFunctionDefinition()
4118 PrettyStackTraceDecl CrashInfo(const_cast<ValueDecl *>(D), D->getLocation(), in EmitGlobalDefinition()
4123 // At -O0, don't generate IR for functions with available_externally in EmitGlobalDefinition()
4131 FD->getNameForDiagnostic(OS, getContext().getPrintingPolicy(), in EmitGlobalDefinition()
4140 ABI->emitCXXStructor(GD); in EmitGlobalDefinition()
4141 else if (FD->isMultiVersion()) in EmitGlobalDefinition()
4146 if (Method->isVirtual()) in EmitGlobalDefinition()
4152 if (FD->isMultiVersion()) in EmitGlobalDefinition()
4158 return EmitGlobalVarDefinition(VD, !VD->hasDefinition()); in EmitGlobalDefinition()
4193 if (FD->getFormalLinkage() == Linkage::Internal) in getMultiversionLinkage()
4206 GlobalDecl CurGD{Decl->isDefined() ? Decl->getDefinition() : Decl, MVIdx}; in emitMultiVersionFunctions()
4210 if (Decl->isDefined()) { in emitMultiVersionFunctions()
4233 bool IsDefined = CurFD->doesThisDeclarationHaveABody(); in emitMultiVersionFunctions()
4235 if (const auto *TA = CurFD->getAttr<TargetAttr>()) { in emitMultiVersionFunctions()
4236 TA->getAddedFeatures(Feats); in emitMultiVersionFunctions()
4238 Options.emplace_back(Func, TA->getArchitecture(), Feats); in emitMultiVersionFunctions()
4239 } else if (const auto *TVA = CurFD->getAttr<TargetVersionAttr>()) { in emitMultiVersionFunctions()
4240 if (TVA->isDefaultVersion() && IsDefined) in emitMultiVersionFunctions()
4242 TVA->getFeatures(Feats); in emitMultiVersionFunctions()
4245 } else if (const auto *TC = CurFD->getAttr<TargetClonesAttr>()) { in emitMultiVersionFunctions()
4248 for (unsigned I = 0; I < TC->featuresStrs_size(); ++I) { in emitMultiVersionFunctions()
4249 if (!TC->isFirstOfVersion(I)) in emitMultiVersionFunctions()
4256 TC->getFeatures(Feats, I); in emitMultiVersionFunctions()
4258 StringRef Version = TC->getFeatureStr(I); in emitMultiVersionFunctions()
4260 Architecture = Version.drop_front(sizeof("arch=") - 1); in emitMultiVersionFunctions()
4275 ResolverConstant = IFunc->getResolver(); in emitMultiVersionFunctions()
4276 if (FD->isTargetClonesMultiVersion() && in emitMultiVersionFunctions()
4295 ResolverFunc->setLinkage(getMultiversionLinkage(*this, GD)); in emitMultiVersionFunctions()
4297 if (!ResolverFunc->hasLocalLinkage() && supportsCOMDAT()) in emitMultiVersionFunctions()
4298 ResolverFunc->setComdat( in emitMultiVersionFunctions()
4299 getModule().getOrInsertComdat(ResolverFunc->getName())); in emitMultiVersionFunctions()
4325 assert(cast<llvm::Function>(Old)->isDeclaration() && "Not a declaration"); in replaceDeclarationWith()
4326 New->takeName(Old); in replaceDeclarationWith()
4327 Old->replaceAllUsesWith(New); in replaceDeclarationWith()
4328 Old->eraseFromParent(); in replaceDeclarationWith()
4334 assert(FD->isCPUDispatchMultiVersion() && "Not a multiversion function?"); in emitCPUDispatchDefinition()
4335 const auto *DD = FD->getAttr<CPUDispatchAttr>(); in emitCPUDispatchDefinition()
4349 getTypes().getTargetAddressSpace(FD->getType())), in emitCPUDispatchDefinition()
4359 ResolverFunc->setLinkage(getMultiversionLinkage(*this, GD)); in emitCPUDispatchDefinition()
4361 ResolverFunc->setComdat( in emitCPUDispatchDefinition()
4362 getModule().getOrInsertComdat(ResolverFunc->getName())); in emitCPUDispatchDefinition()
4367 for (const IdentifierInfo *II : DD->cpus()) { in emitCPUDispatchDefinition()
4370 getCPUSpecificMangling(*this, II->getName()); in emitCPUDispatchDefinition()
4377 ExistingDecl.getDecl()->getAsFunction()->isDefined()) { in emitCPUDispatchDefinition()
4392 Target.getCPUSpecificCPUDispatchFeatures(II->getName(), Features); in emitCPUDispatchDefinition()
4415 (Options.end() - 2)->Conditions.Features), in emitCPUDispatchDefinition()
4417 StringRef LHSName = (Options.end() - 2)->Function->getName(); in emitCPUDispatchDefinition()
4418 StringRef RHSName = (Options.end() - 1)->Function->getName(); in emitCPUDispatchDefinition()
4420 Options.erase(Options.end() - 2); in emitCPUDispatchDefinition()
4422 Options.erase(Options.end() - 1); in emitCPUDispatchDefinition()
4457 if (FD->isTargetVersionMultiVersion() || FD->isTargetClonesMultiVersion()) { in AddDeferredMultiVersionResolverToEmit()
4480 switch (FD->getMultiVersionKind()) { in GetOrCreateMultiVersionResolver()
4492 } else if (FD->isTargetMultiVersion()) { in GetOrCreateMultiVersionResolver()
4512 if (FD->isTargetMultiVersion() || FD->isTargetClonesMultiVersion()) in GetOrCreateMultiVersionResolver()
4517 if (getTarget().supportsIFunc() && !FD->isCPUSpecificMultiVersion()) { in GetOrCreateMultiVersionResolver()
4520 getTypes().getTargetAddressSpace(FD->getType())), in GetOrCreateMultiVersionResolver()
4528 GIF->setName(ResolverName); in GetOrCreateMultiVersionResolver()
4547 auto SC = GV->getDLLStorageClass(); in shouldDropDLLAttribute()
4550 const Decl *MRD = D->getMostRecentDecl(); in shouldDropDLLAttribute()
4552 !MRD->hasAttr<DLLImportAttr>()) || in shouldDropDLLAttribute()
4554 !MRD->hasAttr<DLLExportAttr>())) && in shouldDropDLLAttribute()
4558 /// GetOrCreateLLVMFunction - If the specified mangled name is not in the
4563 /// If D is non-null, it specifies a decl that correspond to this. This is used
4577 !OpenMPRuntime->markAsGlobalTarget(GD) && FD->isDefined() && in GetOrCreateLLVMFunction()
4579 if (const FunctionDecl *FDDef = FD->getDefinition()) { in GetOrCreateLLVMFunction()
4591 if (FD->isMultiVersion()) { in GetOrCreateLLVMFunction()
4616 if (FD && !FD->hasAttr<WeakAttr>()) in GetOrCreateLLVMFunction()
4617 Entry->setLinkage(llvm::Function::ExternalLinkage); in GetOrCreateLLVMFunction()
4622 Entry->setDLLStorageClass(llvm::GlobalValue::DefaultStorageClass); in GetOrCreateLLVMFunction()
4628 if (IsForDefinition && !Entry->isDeclaration()) { in GetOrCreateLLVMFunction()
4636 getDiags().Report(D->getLocation(), diag::err_duplicate_mangled_name) in GetOrCreateLLVMFunction()
4638 getDiags().Report(OtherGD.getDecl()->getLocation(), in GetOrCreateLLVMFunction()
4644 (Entry->getValueType() == Ty)) { in GetOrCreateLLVMFunction()
4674 if (D && D->hasAttr<AnnotateAttr>()) in GetOrCreateLLVMFunction()
4684 F->takeName(Entry); in GetOrCreateLLVMFunction()
4692 if (!Entry->use_empty()) { in GetOrCreateLLVMFunction()
4694 Entry->removeDeadConstantUsers(); in GetOrCreateLLVMFunction()
4700 assert(F->getName() == MangledName && "name was uniqued!"); in GetOrCreateLLVMFunction()
4704 llvm::AttrBuilder B(F->getContext(), ExtraAttrs.getFnAttrs()); in GetOrCreateLLVMFunction()
4705 F->addFnAttrs(B); in GetOrCreateLLVMFunction()
4710 // each other bottoming out with the base dtor. Therefore we emit non-base in GetOrCreateLLVMFunction()
4725 addDeferredDeclToEmit(DDI->second); in GetOrCreateLLVMFunction()
4730 // we might not find a top-level definition: in GetOrCreateLLVMFunction()
4731 // - member functions defined inline in their classes in GetOrCreateLLVMFunction()
4732 // - friend functions defined inline in some class in GetOrCreateLLVMFunction()
4733 // - special member functions with implicit definitions in GetOrCreateLLVMFunction()
4741 for (const auto *FD = cast<FunctionDecl>(D)->getMostRecentDecl(); FD; in GetOrCreateLLVMFunction()
4742 FD = FD->getPreviousDecl()) { in GetOrCreateLLVMFunction()
4743 if (isa<CXXRecordDecl>(FD->getLexicalDeclContext())) { in GetOrCreateLLVMFunction()
4744 if (FD->doesThisDeclarationHaveABody()) { in GetOrCreateLLVMFunction()
4755 assert(F->getFunctionType() == Ty); in GetOrCreateLLVMFunction()
4762 /// GetAddrOfFunction - Return the address of the given function. If Ty is
4763 /// non-null, then this function will use the specified type if it has to
4772 Ty = getTypes().ConvertType(FD->getType()); in GetAddrOfFunction()
4781 DD->getParent()->getNumVBases() == 0) in GetAddrOfFunction()
4791 cast<FunctionDecl>(GD.getDecl())->hasAttr<CUDAGlobalAttr>()) { in GetAddrOfFunction()
4793 cast<llvm::Function>(F->stripPointerCasts()), GD); in GetAddrOfFunction()
4803 cast<llvm::GlobalValue>(GetAddrOfFunction(Decl)->stripPointerCasts()); in GetFunctionStart()
4814 for (const auto *Result : DC->lookup(&CII)) in GetRuntimeFunctionDecl()
4829 for (const auto *Result : DC->lookup(&NS)) { in GetRuntimeFunctionDecl()
4832 for (const auto *Result : LSD->lookup(&NS)) in GetRuntimeFunctionDecl()
4837 for (const auto *Result : ND->lookup(&CXXII)) in GetRuntimeFunctionDecl()
4846 /// CreateRuntimeFunction - Create a new runtime function with the specified
4863 if (F->empty()) { in CreateRuntimeFunction()
4864 F->setCallingConv(getRuntimeCC()); in CreateRuntimeFunction()
4874 if (!FD || FD->hasAttr<DLLImportAttr>()) { in CreateRuntimeFunction()
4875 F->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass); in CreateRuntimeFunction()
4876 F->setLinkage(llvm::GlobalValue::ExternalLinkage); in CreateRuntimeFunction()
4890 /// GetOrCreateLLVMGlobal - If the specified mangled name is not in the module,
4895 /// If D is non-null, it specifies a decl that correspond to this. This is used
4910 if (D && !D->hasAttr<WeakAttr>()) in GetOrCreateLLVMGlobal()
4911 Entry->setLinkage(llvm::Function::ExternalLinkage); in GetOrCreateLLVMGlobal()
4916 Entry->setDLLStorageClass(llvm::GlobalValue::DefaultStorageClass); in GetOrCreateLLVMGlobal()
4921 if (Entry->getValueType() == Ty && Entry->getAddressSpace() == TargetAS) in GetOrCreateLLVMGlobal()
4926 if (IsForDefinition && !Entry->isDeclaration()) { in GetOrCreateLLVMGlobal()
4933 (D->getCanonicalDecl() != OtherGD.getCanonicalDecl().getDecl()) && in GetOrCreateLLVMGlobal()
4935 OtherD->hasInit() && in GetOrCreateLLVMGlobal()
4937 getDiags().Report(D->getLocation(), diag::err_duplicate_mangled_name) in GetOrCreateLLVMGlobal()
4939 getDiags().Report(OtherGD.getDecl()->getLocation(), in GetOrCreateLLVMGlobal()
4945 if (Entry->getType()->getAddressSpace() != TargetAS) in GetOrCreateLLVMGlobal()
4947 Entry, llvm::PointerType::get(Ty->getContext(), TargetAS)); in GetOrCreateLLVMGlobal()
4965 GV->takeName(Entry); in GetOrCreateLLVMGlobal()
4967 if (!Entry->use_empty()) { in GetOrCreateLLVMGlobal()
4968 Entry->replaceAllUsesWith(GV); in GetOrCreateLLVMGlobal()
4971 Entry->eraseFromParent(); in GetOrCreateLLVMGlobal()
4981 addDeferredDeclToEmit(DDI->second); in GetOrCreateLLVMGlobal()
4992 GV->setConstant(D->getType().isConstantStorage(getContext(), false, false)); in GetOrCreateLLVMGlobal()
4994 GV->setAlignment(getContext().getDeclAlign(D).getAsAlign()); in GetOrCreateLLVMGlobal()
4998 if (D->getTLSKind()) { in GetOrCreateLLVMGlobal()
4999 if (D->getTLSKind() == VarDecl::TLS_Dynamic) in GetOrCreateLLVMGlobal()
5013 if (D->hasExternalStorage()) { in GetOrCreateLLVMGlobal()
5014 if (const SectionAttr *SA = D->getAttr<SectionAttr>()) in GetOrCreateLLVMGlobal()
5015 GV->setSection(SA->getName()); in GetOrCreateLLVMGlobal()
5020 D->getLanguageLinkage() == CLanguageLinkage && in GetOrCreateLLVMGlobal()
5021 D->getType().isConstant(Context) && in GetOrCreateLLVMGlobal()
5022 isExternallyVisible(D->getLinkageAndVisibility().getLinkage())) in GetOrCreateLLVMGlobal()
5023 GV->setSection(".cp.rodata"); in GetOrCreateLLVMGlobal()
5026 if (const auto *CMA = D->getAttr<CodeModelAttr>()) in GetOrCreateLLVMGlobal()
5027 GV->setCodeModel(CMA->getModel()); in GetOrCreateLLVMGlobal()
5032 if (Context.getLangOpts().CPlusPlus && GV->hasExternalLinkage() && in GetOrCreateLLVMGlobal()
5033 D->getType().isConstQualified() && !GV->hasInitializer() && in GetOrCreateLLVMGlobal()
5034 !D->hasDefinition() && D->hasInit() && !D->hasAttr<DLLImportAttr>()) { in GetOrCreateLLVMGlobal()
5036 Context.getBaseElementType(D->getType())->getAsCXXRecordDecl(); in GetOrCreateLLVMGlobal()
5037 bool HasMutableFields = Record && Record->hasMutableFields(); in GetOrCreateLLVMGlobal()
5040 const Expr *InitExpr = D->getAnyInitializer(InitDecl); in GetOrCreateLLVMGlobal()
5045 auto *InitType = Init->getType(); in GetOrCreateLLVMGlobal()
5046 if (GV->getValueType() != InitType) { in GetOrCreateLLVMGlobal()
5051 GV->setName(StringRef()); in GetOrCreateLLVMGlobal()
5056 ->stripPointerCasts()); in GetOrCreateLLVMGlobal()
5059 GV->eraseFromParent(); in GetOrCreateLLVMGlobal()
5062 GV->setInitializer(Init); in GetOrCreateLLVMGlobal()
5063 GV->setConstant(true); in GetOrCreateLLVMGlobal()
5064 GV->setLinkage(llvm::GlobalValue::AvailableExternallyLinkage); in GetOrCreateLLVMGlobal()
5074 D->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly) { in GetOrCreateLLVMGlobal()
5078 if (getLangOpts().CUDA && D && D->hasAttr<HIPManagedAttr>() && in GetOrCreateLLVMGlobal()
5079 D->hasExternalStorage()) in GetOrCreateLLVMGlobal()
5084 SanitizerMD->reportGlobal(GV, *D); in GetOrCreateLLVMGlobal()
5087 D ? D->getType().getAddressSpace() in GetOrCreateLLVMGlobal()
5133 if (GV->getValueType() == Ty) in CreateOrReplaceCXXRuntimeVariable()
5138 assert(GV->isDeclaration() && "Declaration has wrong type!"); in CreateOrReplaceCXXRuntimeVariable()
5148 GV->takeName(OldGV); in CreateOrReplaceCXXRuntimeVariable()
5150 if (!OldGV->use_empty()) { in CreateOrReplaceCXXRuntimeVariable()
5151 OldGV->replaceAllUsesWith(GV); in CreateOrReplaceCXXRuntimeVariable()
5154 OldGV->eraseFromParent(); in CreateOrReplaceCXXRuntimeVariable()
5157 if (supportsCOMDAT() && GV->isWeakForLinker() && in CreateOrReplaceCXXRuntimeVariable()
5158 !GV->hasAvailableExternallyLinkage()) in CreateOrReplaceCXXRuntimeVariable()
5159 GV->setComdat(TheModule.getOrInsertComdat(GV->getName())); in CreateOrReplaceCXXRuntimeVariable()
5161 GV->setAlignment(Alignment); in CreateOrReplaceCXXRuntimeVariable()
5166 /// GetAddrOfGlobalVar - Return the llvm::Constant for the address of the
5167 /// given global variable. If Ty is non-null and if the global doesn't exist,
5175 assert(D->hasGlobalStorage() && "Not a global variable"); in GetAddrOfGlobalVar()
5176 QualType ASTTy = D->getType(); in GetAddrOfGlobalVar()
5185 /// CreateRuntimeVariable - Create a new runtime global variable with the
5193 setDSOLocal(cast<llvm::GlobalValue>(Ret->stripPointerCasts())); in CreateRuntimeVariable()
5198 assert(!D->getInit() && "Cannot emit definite definitions here!"); in EmitTentativeDefinition()
5206 if (GV && !GV->isDeclaration()) in EmitTentativeDefinition()
5221 if (auto const *V = dyn_cast<const VarDecl>(D)) in EmitExternalDeclaration() local
5222 EmitExternalVarDeclaration(V); in EmitExternalDeclaration()
5234 LangAS AS = D ? D->getType().getAddressSpace() : LangAS::opencl_global; in GetGlobalVarAddressSpace()
5245 (!D || D->getType().getAddressSpace() == LangAS::Default)) in GetGlobalVarAddressSpace()
5250 if (D->hasAttr<CUDAConstantAttr>()) in GetGlobalVarAddressSpace()
5252 if (D->hasAttr<CUDASharedAttr>()) in GetGlobalVarAddressSpace()
5254 if (D->hasAttr<CUDADeviceAttr>()) in GetGlobalVarAddressSpace()
5256 if (D->getType().isConstQualified()) in GetGlobalVarAddressSpace()
5264 if (OpenMPRuntime->hasAllocateAttributeForGlobalVar(D, AS)) in GetGlobalVarAddressSpace()
5277 // For HIPSPV map literals to cuda_device (maps to CrossWorkGroup in SPIR-V) in GetGlobalConstantAddressSpace()
5278 // instead of default AS (maps to Generic in SPIR-V). Otherwise, we end up in GetGlobalConstantAddressSpace()
5280 // allowed (SPIR-V V1.6 s3.42.8). Also, mapping literals to SPIR-V in GetGlobalConstantAddressSpace()
5321 if (!D->template hasAttr<UsedAttr>()) in MaybeHandleStaticInExternC()
5325 if (!D->getIdentifier() || D->getFormalLinkage() != Linkage::Internal) in MaybeHandleStaticInExternC()
5330 const SomeDecl *First = D->getFirstDecl(); in MaybeHandleStaticInExternC()
5331 if (First->getDeclContext()->isRecord() || !First->isInExternCContext()) in MaybeHandleStaticInExternC()
5338 StaticExternCValues.insert(std::make_pair(D->getIdentifier(), GV)); in MaybeHandleStaticInExternC()
5343 R.first->second = nullptr; in MaybeHandleStaticInExternC()
5391 QualType ASTTy = D->getType(); in EmitGlobalVarDefinition()
5392 if (getLangOpts().OpenCL && ASTTy->isSamplerT()) in EmitGlobalVarDefinition()
5398 OpenMPRuntime->emitTargetGlobalVariable(D)) in EmitGlobalVarDefinition()
5410 D->needsDestruction(getContext()) == QualType::DK_cxx_destructor; in EmitGlobalVarDefinition()
5417 (!D->hasConstantInitialization() || in EmitGlobalVarDefinition()
5420 D->needsDestruction(getContext()) || in EmitGlobalVarDefinition()
5421 !D->getType().isConstantStorage(getContext(), true, true))) in EmitGlobalVarDefinition()
5425 const Expr *InitExpr = D->getAnyInitializer(InitDecl); in EmitGlobalVarDefinition()
5433 getLangOpts().CUDAIsDevice && D->hasAttr<CUDASharedAttr>(); in EmitGlobalVarDefinition()
5434 // Shadows of initialized device-side global variables are also left in EmitGlobalVarDefinition()
5438 !getLangOpts().CUDAIsDevice && !D->hasAttr<HIPManagedAttr>() && in EmitGlobalVarDefinition()
5439 (D->hasAttr<CUDAConstantAttr>() || D->hasAttr<CUDADeviceAttr>() || in EmitGlobalVarDefinition()
5440 D->hasAttr<CUDASharedAttr>()); in EmitGlobalVarDefinition()
5442 getLangOpts().CUDAIsDevice && !D->hasAttr<HIPManagedAttr>() && in EmitGlobalVarDefinition()
5443 (D->getType()->isCUDADeviceBuiltinSurfaceType() || in EmitGlobalVarDefinition()
5444 D->getType()->isCUDADeviceBuiltinTextureType()); in EmitGlobalVarDefinition()
5448 else if (D->hasAttr<LoaderUninitializedAttr>()) in EmitGlobalVarDefinition()
5460 assert(!ASTTy->isIncompleteType() && "Unexpected incomplete type"); in EmitGlobalVarDefinition()
5461 Init = EmitNullConstant(D->getType()); in EmitGlobalVarDefinition()
5465 llvm::Constant *Initializer = emitter->tryEmitForInitializer(*InitDecl); in EmitGlobalVarDefinition()
5467 QualType T = InitExpr->getType(); in EmitGlobalVarDefinition()
5468 if (D->getType()->isReferenceType()) in EmitGlobalVarDefinition()
5469 T = D->getType(); in EmitGlobalVarDefinition()
5472 if (InitDecl->hasFlexibleArrayInit(getContext())) in EmitGlobalVarDefinition()
5492 InitDecl->getFlexibleArrayInitChars(getContext()); in EmitGlobalVarDefinition()
5494 getDataLayout().getTypeAllocSize(Init->getType())); in EmitGlobalVarDefinition()
5500 llvm::Type* InitType = Init->getType(); in EmitGlobalVarDefinition()
5505 Entry = Entry->stripPointerCasts(); in EmitGlobalVarDefinition()
5519 if (!GV || GV->getValueType() != InitType || in EmitGlobalVarDefinition()
5520 GV->getType()->getAddressSpace() != in EmitGlobalVarDefinition()
5524 Entry->setName(StringRef()); in EmitGlobalVarDefinition()
5529 ->stripPointerCasts()); in EmitGlobalVarDefinition()
5534 Entry->getType()); in EmitGlobalVarDefinition()
5535 Entry->replaceAllUsesWith(NewPtrForOldDecl); in EmitGlobalVarDefinition()
5538 cast<llvm::GlobalValue>(Entry)->eraseFromParent(); in EmitGlobalVarDefinition()
5543 if (D->hasAttr<AnnotateAttr>()) in EmitGlobalVarDefinition()
5559 (D->hasAttr<CUDADeviceAttr>() || D->hasAttr<CUDAConstantAttr>() || in EmitGlobalVarDefinition()
5560 D->getType()->isCUDADeviceBuiltinSurfaceType() || in EmitGlobalVarDefinition()
5561 D->getType()->isCUDADeviceBuiltinTextureType())) in EmitGlobalVarDefinition()
5562 GV->setExternallyInitialized(true); in EmitGlobalVarDefinition()
5569 GV->setInitializer(Init); in EmitGlobalVarDefinition()
5571 emitter->finalize(GV); in EmitGlobalVarDefinition()
5574 GV->setConstant(!NeedsGlobalCtor && !NeedsGlobalDtor && in EmitGlobalVarDefinition()
5575 D->getType().isConstantStorage(getContext(), true, true)); in EmitGlobalVarDefinition()
5577 // If it is in a read-only section, mark it 'constant'. in EmitGlobalVarDefinition()
5578 if (const SectionAttr *SA = D->getAttr<SectionAttr>()) { in EmitGlobalVarDefinition()
5579 const ASTContext::SectionInfo &SI = Context.SectionInfos[SA->getName()]; in EmitGlobalVarDefinition()
5581 GV->setConstant(true); in EmitGlobalVarDefinition()
5589 GV->setAlignment(AlignVal.getAsAlign()); in EmitGlobalVarDefinition()
5591 // On Darwin, unlike other Itanium C++ ABI platforms, the thread-wrapper in EmitGlobalVarDefinition()
5594 // thread-wrapper in order to ensure initialization has occurred, underlying in EmitGlobalVarDefinition()
5595 // variable will never be used other than the thread-wrapper, so it can be in EmitGlobalVarDefinition()
5599 // referenced directly, without calling the thread-wrapper, so the linkage in EmitGlobalVarDefinition()
5603 // weak or linkonce, the de-duplication semantics are important to preserve, in EmitGlobalVarDefinition()
5605 if (D->getTLSKind() == VarDecl::TLS_Dynamic && in EmitGlobalVarDefinition()
5608 !D->hasAttr<ConstInitAttr>()) in EmitGlobalVarDefinition()
5611 GV->setLinkage(Linkage); in EmitGlobalVarDefinition()
5612 if (D->hasAttr<DLLImportAttr>()) in EmitGlobalVarDefinition()
5613 GV->setDLLStorageClass(llvm::GlobalVariable::DLLImportStorageClass); in EmitGlobalVarDefinition()
5614 else if (D->hasAttr<DLLExportAttr>()) in EmitGlobalVarDefinition()
5615 GV->setDLLStorageClass(llvm::GlobalVariable::DLLExportStorageClass); in EmitGlobalVarDefinition()
5617 GV->setDLLStorageClass(llvm::GlobalVariable::DefaultStorageClass); in EmitGlobalVarDefinition()
5621 GV->setConstant(false); in EmitGlobalVarDefinition()
5623 // non-zero null pointers. In this case they should have weak linkage in EmitGlobalVarDefinition()
5625 // explicit section therefore cannot have non-zero initial value. in EmitGlobalVarDefinition()
5626 if (!GV->getInitializer()->isNullValue()) in EmitGlobalVarDefinition()
5627 GV->setLinkage(llvm::GlobalVariable::WeakAnyLinkage); in EmitGlobalVarDefinition()
5632 if (D->getTLSKind() && !GV->isThreadLocal()) { in EmitGlobalVarDefinition()
5633 if (D->getTLSKind() == VarDecl::TLS_Dynamic) in EmitGlobalVarDefinition()
5644 SanitizerMD->reportGlobal(GV, *D, NeedsGlobalCtor); in EmitGlobalVarDefinition()
5649 DI->EmitGlobalVariable(GV, D); in EmitGlobalVarDefinition()
5655 QualType ASTTy = D->getType(); in EmitExternalVarDeclaration()
5656 llvm::Type *Ty = getTypes().ConvertTypeForMem(D->getType()); in EmitExternalVarDeclaration()
5658 GetOrCreateLLVMGlobal(D->getName(), Ty, ASTTy.getAddressSpace(), D); in EmitExternalVarDeclaration()
5659 DI->EmitExternalVariable( in EmitExternalVarDeclaration()
5660 cast<llvm::GlobalVariable>(GV->stripPointerCasts()), D); in EmitExternalVarDeclaration()
5667 auto *Ty = getTypes().ConvertType(FD->getType()); in EmitExternalFunctionDeclaration()
5671 if (!Fn->getSubprogram()) in EmitExternalFunctionDeclaration()
5672 DI->EmitFunctionDecl(FD, FD->getLocation(), FD->getType(), Fn); in EmitExternalFunctionDeclaration()
5679 // Don't give variables common linkage if -fno-common was specified unless it in isVarDeclStrongDefinition()
5681 if ((NoCommon || D->hasAttr<NoCommonAttr>()) && !D->hasAttr<CommonAttr>()) in isVarDeclStrongDefinition()
5686 // an initializer, and without a storage-class specifier or with the in isVarDeclStrongDefinition()
5687 // storage-class specifier static, constitutes a tentative definition. in isVarDeclStrongDefinition()
5688 if (D->getInit() || D->hasExternalStorage()) in isVarDeclStrongDefinition()
5692 if (D->hasAttr<SectionAttr>()) in isVarDeclStrongDefinition()
5696 // We don't try to determine which is the right section in the front-end. in isVarDeclStrongDefinition()
5698 if (D->hasAttr<PragmaClangBSSSectionAttr>() || in isVarDeclStrongDefinition()
5699 D->hasAttr<PragmaClangDataSectionAttr>() || in isVarDeclStrongDefinition()
5700 D->hasAttr<PragmaClangRelroSectionAttr>() || in isVarDeclStrongDefinition()
5701 D->hasAttr<PragmaClangRodataSectionAttr>()) in isVarDeclStrongDefinition()
5705 if (D->getTLSKind()) in isVarDeclStrongDefinition()
5709 if (D->hasAttr<WeakImportAttr>()) in isVarDeclStrongDefinition()
5719 if (D->hasAttr<AlignedAttr>()) in isVarDeclStrongDefinition()
5721 QualType VarType = D->getType(); in isVarDeclStrongDefinition()
5725 if (const auto *RT = VarType->getAs<RecordType>()) { in isVarDeclStrongDefinition()
5726 const RecordDecl *RD = RT->getDecl(); in isVarDeclStrongDefinition()
5727 for (const FieldDecl *FD : RD->fields()) { in isVarDeclStrongDefinition()
5728 if (FD->isBitField()) in isVarDeclStrongDefinition()
5730 if (FD->hasAttr<AlignedAttr>()) in isVarDeclStrongDefinition()
5732 if (Context.isAlignmentRequired(FD->getType())) in isVarDeclStrongDefinition()
5741 // Other COFF linkers (ld.bfd and LLD) support arbitrary power-of-two in isVarDeclStrongDefinition()
5745 Context.getTypeAlignIfKnown(D->getType()) > in isVarDeclStrongDefinition()
5758 if (D->hasAttr<WeakAttr>()) in getLLVMLinkageForDeclarator()
5761 if (const auto *FD = D->getAsFunction()) in getLLVMLinkageForDeclarator()
5762 if (FD->isMultiVersion() && Linkage == GVA_AvailableExternally) in getLLVMLinkageForDeclarator()
5790 // CUDA/HIP: For -fno-gpu-rdc case, device code is limited to one TU, in getLLVMLinkageForDeclarator()
5792 // This lets llvm perform aggressive inter-procedural optimizations. For in getLLVMLinkageForDeclarator()
5793 // -fgpu-rdc case, device function calls across multiple TU's are allowed, in getLLVMLinkageForDeclarator()
5800 return D->hasAttr<CUDAGlobalAttr>() ? llvm::Function::ExternalLinkage in getLLVMLinkageForDeclarator()
5815 // http://msdn.microsoft.com/en-us/library/5tkz6s71.aspx in getLLVMLinkageForDeclarator()
5816 if (D->hasAttr<SelectAnyAttr>()) in getLLVMLinkageForDeclarator()
5830 /// Replace the uses of a function that was declared with a non-proto type.
5835 if (old->use_empty()) in replaceUsesOfNonProtoConstant()
5838 llvm::Type *newRetTy = newFn->getReturnType(); in replaceUsesOfNonProtoConstant()
5843 for (llvm::Value::use_iterator ui = old->use_begin(), ue = old->use_end(); in replaceUsesOfNonProtoConstant()
5845 llvm::User *user = ui->getUser(); in replaceUsesOfNonProtoConstant()
5850 if (bitcast->getOpcode() == llvm::Instruction::BitCast) in replaceUsesOfNonProtoConstant()
5859 if (!callSite->isCallee(&*ui)) in replaceUsesOfNonProtoConstant()
5864 if (callSite->getType() != newRetTy && !callSite->use_empty()) in replaceUsesOfNonProtoConstant()
5869 llvm::AttributeList oldAttrs = callSite->getAttributes(); in replaceUsesOfNonProtoConstant()
5872 unsigned newNumArgs = newFn->arg_size(); in replaceUsesOfNonProtoConstant()
5873 if (callSite->arg_size() < newNumArgs) in replaceUsesOfNonProtoConstant()
5880 for (llvm::Argument &A : newFn->args()) { in replaceUsesOfNonProtoConstant()
5881 if (callSite->getArgOperand(argNo)->getType() != A.getType()) { in replaceUsesOfNonProtoConstant()
5895 newArgs.append(callSite->arg_begin(), callSite->arg_begin() + argNo); in replaceUsesOfNonProtoConstant()
5899 callSite->getOperandBundlesAsDefs(newBundles); in replaceUsesOfNonProtoConstant()
5907 newCall = llvm::InvokeInst::Create(newFn, oldInvoke->getNormalDest(), in replaceUsesOfNonProtoConstant()
5908 oldInvoke->getUnwindDest(), newArgs, in replaceUsesOfNonProtoConstant()
5913 if (!newCall->getType()->isVoidTy()) in replaceUsesOfNonProtoConstant()
5914 newCall->takeName(callSite); in replaceUsesOfNonProtoConstant()
5915 newCall->setAttributes( in replaceUsesOfNonProtoConstant()
5916 llvm::AttributeList::get(newFn->getContext(), oldAttrs.getFnAttrs(), in replaceUsesOfNonProtoConstant()
5918 newCall->setCallingConv(callSite->getCallingConv()); in replaceUsesOfNonProtoConstant()
5921 if (!callSite->use_empty()) in replaceUsesOfNonProtoConstant()
5922 callSite->replaceAllUsesWith(newCall); in replaceUsesOfNonProtoConstant()
5925 if (callSite->getDebugLoc()) in replaceUsesOfNonProtoConstant()
5926 newCall->setDebugLoc(callSite->getDebugLoc()); in replaceUsesOfNonProtoConstant()
5932 callSite->eraseFromParent(); in replaceUsesOfNonProtoConstant()
5936 /// ReplaceUsesOfNonProtoTypeWithRealFunction - This function is called when we
5944 /// run at -O0.
5954 auto DK = VD->isThisDeclarationADefinition(); in HandleCXXStaticMemberVarInstantiation()
5955 if ((DK == VarDecl::Definition && VD->hasAttr<DLLImportAttr>()) || in HandleCXXStaticMemberVarInstantiation()
5959 TemplateSpecializationKind TSK = VD->getTemplateSpecializationKind(); in HandleCXXStaticMemberVarInstantiation()
5962 if (VD->getDefinition() && TSK == TSK_ExplicitInstantiationDefinition) in HandleCXXStaticMemberVarInstantiation()
5977 if (!GV || (GV->getValueType() != Ty)) in EmitGlobalFunctionDefinition()
5983 if (!GV->isDeclaration()) in EmitGlobalFunctionDefinition()
6005 if (const ConstructorAttr *CA = D->getAttr<ConstructorAttr>()) in EmitGlobalFunctionDefinition()
6006 AddGlobalCtor(Fn, CA->getPriority()); in EmitGlobalFunctionDefinition()
6007 if (const DestructorAttr *DA = D->getAttr<DestructorAttr>()) in EmitGlobalFunctionDefinition()
6008 AddGlobalDtor(Fn, DA->getPriority(), true); in EmitGlobalFunctionDefinition()
6009 if (getLangOpts().OpenMP && D->hasAttr<OMPDeclareTargetDeclAttr>()) in EmitGlobalFunctionDefinition()
6015 const AliasAttr *AA = D->getAttr<AliasAttr>(); in EmitAliasDefinition()
6020 if (AA->getAliasee() == MangledName) { in EmitAliasDefinition()
6021 Diags.Report(AA->getLocation(), diag::err_cyclic_alias) << 0; in EmitAliasDefinition()
6028 if (Entry && !Entry->isDeclaration()) in EmitAliasDefinition()
6033 llvm::Type *DeclTy = getTypes().ConvertTypeForMem(D->getType()); in EmitAliasDefinition()
6040 Aliasee = GetOrCreateLLVMFunction(AA->getAliasee(), DeclTy, GD, in EmitAliasDefinition()
6044 Aliasee = GetOrCreateLLVMGlobal(AA->getAliasee(), DeclTy, LangAS::Default, in EmitAliasDefinition()
6053 unsigned AS = Aliasee->getType()->getPointerAddressSpace(); in EmitAliasDefinition()
6058 if (GA->getAliasee() == Entry) { in EmitAliasDefinition()
6059 Diags.Report(AA->getLocation(), diag::err_cyclic_alias) << 0; in EmitAliasDefinition()
6063 assert(Entry->isDeclaration()); in EmitAliasDefinition()
6072 GA->takeName(Entry); in EmitAliasDefinition()
6074 Entry->replaceAllUsesWith(GA); in EmitAliasDefinition()
6075 Entry->eraseFromParent(); in EmitAliasDefinition()
6077 GA->setName(MangledName); in EmitAliasDefinition()
6083 if (D->hasAttr<WeakAttr>() || D->hasAttr<WeakRefAttr>() || in EmitAliasDefinition()
6084 D->isWeakImported()) { in EmitAliasDefinition()
6085 GA->setLinkage(llvm::Function::WeakAnyLinkage); in EmitAliasDefinition()
6089 if (VD->getTLSKind()) in EmitAliasDefinition()
6097 DI->EmitGlobalAlias(cast<llvm::GlobalValue>(GA->getAliasee()->stripPointerCasts()), GD); in EmitAliasDefinition()
6102 const IFuncAttr *IFA = D->getAttr<IFuncAttr>(); in emitIFuncDefinition()
6107 if (IFA->getResolver() == MangledName) { in emitIFuncDefinition()
6108 Diags.Report(IFA->getLocation(), diag::err_cyclic_alias) << 1; in emitIFuncDefinition()
6114 if (Entry && !Entry->isDeclaration()) { in emitIFuncDefinition()
6118 Diags.Report(D->getLocation(), diag::err_duplicate_mangled_name) in emitIFuncDefinition()
6120 Diags.Report(OtherGD.getDecl()->getLocation(), in emitIFuncDefinition()
6128 // The resolver might not be visited yet. Specify a dummy non-function type to in emitIFuncDefinition()
6133 GetOrCreateLLVMFunction(IFA->getResolver(), VoidTy, {}, in emitIFuncDefinition()
6135 llvm::Type *DeclTy = getTypes().ConvertTypeForMem(D->getType()); in emitIFuncDefinition()
6140 if (GIF->getResolver() == Entry) { in emitIFuncDefinition()
6141 Diags.Report(IFA->getLocation(), diag::err_cyclic_alias) << 1; in emitIFuncDefinition()
6144 assert(Entry->isDeclaration()); in emitIFuncDefinition()
6153 GIF->takeName(Entry); in emitIFuncDefinition()
6155 Entry->replaceAllUsesWith(GIF); in emitIFuncDefinition()
6156 Entry->eraseFromParent(); in emitIFuncDefinition()
6158 GIF->setName(MangledName); in emitIFuncDefinition()
6172 StringRef String = Literal->getString(); in GetConstantCFStringEntry()
6176 if (!Literal->containsNonAsciiOrNull()) { in GetConstantCFStringEntry()
6192 StringLength = ToPtr - &ToBuf[0]; in GetConstantCFStringEntry()
6213 C, C->getValueType(), CharUnits::fromQuantity(C->getAlignment())); in GetAddrOfConstantCFString()
6259 IdentifierInfo &II = Context.Idents.get(GV->getName()); in GetAddrOfConstantCFString()
6264 for (const auto *Result : DC->lookup(&II)) in GetAddrOfConstantCFString()
6270 GV->setLinkage(llvm::GlobalValue::ExternalLinkage); in GetAddrOfConstantCFString()
6272 GV->setLinkage(llvm::GlobalValue::ExternalLinkage); in GetAddrOfConstantCFString()
6273 if (!VD || !VD->hasAttr<DLLExportAttr>()) in GetAddrOfConstantCFString()
6274 GV->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass); in GetAddrOfConstantCFString()
6276 GV->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass); in GetAddrOfConstantCFString()
6283 // Decay array -> ptr in GetAddrOfConstantCFString()
6317 // Note: -fwritable-strings doesn't make the backing store strings of in GetAddrOfConstantCFString()
6320 new llvm::GlobalVariable(getModule(), C->getType(), /*isConstant=*/true, in GetAddrOfConstantCFString()
6322 GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global); in GetAddrOfConstantCFString()
6327 GV->setAlignment(Align.getAsAlign()); in GetAddrOfConstantCFString()
6333 GV->setSection(isUTF16 ? "__TEXT,__ustring" in GetAddrOfConstantCFString()
6336 // the static linker to adjust permissions to read-only later on. in GetAddrOfConstantCFString()
6338 GV->setSection(".rodata"); in GetAddrOfConstantCFString()
6356 // Swift ABI requires 8-byte alignment to ensure that the _Atomic(uint64_t) is in GetAddrOfConstantCFString()
6357 // properly aligned on 32-bit platforms. in GetAddrOfConstantCFString()
6365 GV->addAttribute("objc_arc_inert"); in GetAddrOfConstantCFString()
6377 GV->setSection("cfstring"); in GetAddrOfConstantCFString()
6380 GV->setSection("__DATA,__cfstring"); in GetAddrOfConstantCFString()
6385 return ConstantAddress(GV, GV->getValueType(), Alignment); in GetAddrOfConstantCFString()
6395 D->startDefinition(); in getObjCFastEnumerationStateType()
6412 Field->setAccess(AS_public); in getObjCFastEnumerationStateType()
6413 D->addDecl(Field); in getObjCFastEnumerationStateType()
6416 D->completeDefinition(); in getObjCFastEnumerationStateType()
6425 assert(!E->getType()->isPointerType() && "Strings are always arrays"); in GetConstantArrayFromStringLiteral()
6429 if (E->getCharByteWidth() == 1) { in GetConstantArrayFromStringLiteral()
6430 SmallString<64> Str(E->getString()); in GetConstantArrayFromStringLiteral()
6433 const ConstantArrayType *CAT = Context.getAsConstantArrayType(E->getType()); in GetConstantArrayFromStringLiteral()
6435 Str.resize(CAT->getZExtSize()); in GetConstantArrayFromStringLiteral()
6439 auto *AType = cast<llvm::ArrayType>(getTypes().ConvertType(E->getType())); in GetConstantArrayFromStringLiteral()
6440 llvm::Type *ElemTy = AType->getElementType(); in GetConstantArrayFromStringLiteral()
6441 unsigned NumElements = AType->getNumElements(); in GetConstantArrayFromStringLiteral()
6443 // Wide strings have either 2-byte or 4-byte elements. in GetConstantArrayFromStringLiteral()
6444 if (ElemTy->getPrimitiveSizeInBits() == 16) { in GetConstantArrayFromStringLiteral()
6448 for(unsigned i = 0, e = E->getLength(); i != e; ++i) in GetConstantArrayFromStringLiteral()
6449 Elements.push_back(E->getCodeUnit(i)); in GetConstantArrayFromStringLiteral()
6454 assert(ElemTy->getPrimitiveSizeInBits() == 32); in GetConstantArrayFromStringLiteral()
6458 for(unsigned i = 0, e = E->getLength(); i != e; ++i) in GetConstantArrayFromStringLiteral()
6459 Elements.push_back(E->getCodeUnit(i)); in GetConstantArrayFromStringLiteral()
6474 M, C->getType(), !CGM.getLangOpts().WritableStrings, LT, C, GlobalName, in GenerateStringLiteral()
6476 GV->setAlignment(Alignment.getAsAlign()); in GenerateStringLiteral()
6477 GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global); in GenerateStringLiteral()
6478 if (GV->isWeakForLinker()) { in GenerateStringLiteral()
6480 GV->setComdat(M.getOrInsertComdat(GV->getName())); in GenerateStringLiteral()
6487 /// GetAddrOfConstantStringFromLiteral - Return a pointer to a
6493 getContext().getAlignOfGlobalVarInChars(S->getType(), /*VD=*/nullptr); in GetAddrOfConstantStringFromLiteral()
6500 if (uint64_t(Alignment.getQuantity()) > GV->getAlignment()) in GetAddrOfConstantStringFromLiteral()
6501 GV->setAlignment(Alignment.getAsAlign()); in GetAddrOfConstantStringFromLiteral()
6503 GV->getValueType(), Alignment); in GetAddrOfConstantStringFromLiteral()
6529 DI->AddStringLiteralDebugInfo(GV, S); in GetAddrOfConstantStringFromLiteral()
6534 SanitizerMD->reportGlobal(GV, S->getStrTokenLoc(0), "<string literal>"); in GetAddrOfConstantStringFromLiteral()
6537 GV->getValueType(), Alignment); in GetAddrOfConstantStringFromLiteral()
6540 /// GetAddrOfConstantStringFromObjCEncode - Return a pointer to a constant
6545 getContext().getObjCEncodingForType(E->getEncodedType(), Str); in GetAddrOfConstantStringFromObjCEncode()
6550 /// GetAddrOfConstantCString - Returns a pointer to a character array containing
6567 if (uint64_t(Alignment.getQuantity()) > GV->getAlignment()) in GetAddrOfConstantCString()
6568 GV->setAlignment(Alignment.getAsAlign()); in GetAddrOfConstantCString()
6570 GV->getValueType(), Alignment); in GetAddrOfConstantCString()
6584 GV->getValueType(), Alignment); in GetAddrOfConstantCString()
6589 assert((E->getStorageDuration() == SD_Static || in GetAddrOfGlobalTemporary()
6590 E->getStorageDuration() == SD_Thread) && "not a global temporary"); in GetAddrOfGlobalTemporary()
6591 const auto *VD = cast<VarDecl>(E->getExtendingDecl()); in GetAddrOfGlobalTemporary()
6594 // cv-qualifiers from the type of the MaterializeTemporaryExpr. in GetAddrOfGlobalTemporary()
6595 QualType MaterializedType = Init->getType(); in GetAddrOfGlobalTemporary()
6596 if (Init == E->getSubExpr()) in GetAddrOfGlobalTemporary()
6597 MaterializedType = E->getType(); in GetAddrOfGlobalTemporary()
6605 if (!InsertResult.first->second) { in GetAddrOfGlobalTemporary()
6606 // We recursively re-entered this function, probably during emission of in GetAddrOfGlobalTemporary()
6610 InsertResult.first->second = new llvm::GlobalVariable( in GetAddrOfGlobalTemporary()
6614 return ConstantAddress(InsertResult.first->second, in GetAddrOfGlobalTemporary()
6616 InsertResult.first->second->stripPointerCasts()) in GetAddrOfGlobalTemporary()
6617 ->getValueType(), in GetAddrOfGlobalTemporary()
6621 // FIXME: If an externally-visible declaration extends multiple temporaries, in GetAddrOfGlobalTemporary()
6623 // we also need to make the temporaries externally-visible). in GetAddrOfGlobalTemporary()
6627 VD, E->getManglingNumber(), Out); in GetAddrOfGlobalTemporary()
6630 if (E->getStorageDuration() == SD_Static && VD->evaluateValue()) { in GetAddrOfGlobalTemporary()
6636 Value = E->getOrCreateValue(false); in GetAddrOfGlobalTemporary()
6641 if (!Value && Init->EvaluateAsRValue(EvalResult, getContext()) && in GetAddrOfGlobalTemporary()
6654 InitialValue = emitter->emitForInitializer(*Value, AddrSpace, in GetAddrOfGlobalTemporary()
6659 Type = InitialValue->getType(); in GetAddrOfGlobalTemporary()
6666 // Create a global variable for this lifetime-extended temporary. in GetAddrOfGlobalTemporary()
6670 if (VD->isStaticDataMember() && VD->getAnyInitializer(InitVD) && in GetAddrOfGlobalTemporary()
6671 isa<CXXRecordDecl>(InitVD->getLexicalDeclContext())) { in GetAddrOfGlobalTemporary()
6685 if (emitter) emitter->finalize(GV); in GetAddrOfGlobalTemporary()
6689 if (GV->getDLLStorageClass() == llvm::GlobalVariable::DLLExportStorageClass) in GetAddrOfGlobalTemporary()
6691 GV->setDLLStorageClass(llvm::GlobalVariable::DefaultStorageClass); in GetAddrOfGlobalTemporary()
6693 GV->setAlignment(Align.getAsAlign()); in GetAddrOfGlobalTemporary()
6694 if (supportsCOMDAT() && GV->isWeakForLinker()) in GetAddrOfGlobalTemporary()
6695 GV->setComdat(TheModule.getOrInsertComdat(GV->getName())); in GetAddrOfGlobalTemporary()
6696 if (VD->getTLSKind()) in GetAddrOfGlobalTemporary()
6710 Entry->replaceAllUsesWith(CV); in GetAddrOfGlobalTemporary()
6711 llvm::cast<llvm::GlobalVariable>(Entry)->eraseFromParent(); in GetAddrOfGlobalTemporary()
6718 /// EmitObjCPropertyImplementations - Emit information for synthesized
6722 for (const auto *PID : D->property_impls()) { in EmitObjCPropertyImplementations()
6723 // Dynamic is just for type-checking. in EmitObjCPropertyImplementations()
6724 if (PID->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize) { in EmitObjCPropertyImplementations()
6725 ObjCPropertyDecl *PD = PID->getPropertyDecl(); in EmitObjCPropertyImplementations()
6732 auto *Getter = PID->getGetterMethodDecl(); in EmitObjCPropertyImplementations()
6733 if (!Getter || Getter->isSynthesizedAccessorStub()) in EmitObjCPropertyImplementations()
6736 auto *Setter = PID->getSetterMethodDecl(); in EmitObjCPropertyImplementations()
6737 if (!PD->isReadOnly() && (!Setter || Setter->isSynthesizedAccessorStub())) in EmitObjCPropertyImplementations()
6745 const ObjCInterfaceDecl *iface = impl->getClassInterface(); in needsDestructMethod()
6746 for (const ObjCIvarDecl *ivar = iface->all_declared_ivar_begin(); in needsDestructMethod()
6747 ivar; ivar = ivar->getNextIvar()) in needsDestructMethod()
6748 if (ivar->getType().isDestructedType()) in needsDestructMethod()
6757 for (ObjCImplementationDecl::init_iterator B = D->init_begin(), in AllTrivialInitializers()
6758 E = D->init_end(); B != E; ++B) { in AllTrivialInitializers()
6760 Expr *Init = CtorInitExp->getInit(); in AllTrivialInitializers()
6767 /// EmitObjCIvarInitializations - Emit information for ivar initialization
6775 getContext(), D->getLocation(), D->getLocation(), cxxSelector, in EmitObjCIvarInitializations()
6781 D->addInstanceMethod(DTORMethod); in EmitObjCIvarInitializations()
6783 D->setHasDestructors(true); in EmitObjCIvarInitializations()
6788 if (D->getNumIvarInitializers() == 0 || in EmitObjCIvarInitializations()
6796 getContext(), D->getLocation(), D->getLocation(), cxxSelector, in EmitObjCIvarInitializations()
6802 D->addInstanceMethod(CTORMethod); in EmitObjCIvarInitializations()
6804 D->setHasNonZeroConstructors(true); in EmitObjCIvarInitializations()
6807 // EmitLinkageSpec - Emit all declarations in a linkage spec.
6809 if (LSD->getLanguage() != LinkageSpecLanguageIDs::C && in EmitLinkageSpec()
6810 LSD->getLanguage() != LinkageSpecLanguageIDs::CXX) { in EmitLinkageSpec()
6811 ErrorUnsupported(LSD, "linkage spec"); in EmitLinkageSpec()
6826 // We emitted a top-level stmt but after it there is initialization. in EmitTopLevelStmt()
6827 // Stop squashing the top-level stmts into a single function. in EmitTopLevelStmt()
6828 if (CurCGF && CXXGlobalInits.back() != CurCGF->CurFn) { in EmitTopLevelStmt()
6829 CurCGF->FinishFunction(D->getEndLoc()); in EmitTopLevelStmt()
6847 CurCGF->StartFunction(GlobalDecl(), RetTy, Fn, FnInfo, Args, in EmitTopLevelStmt()
6848 D->getBeginLoc(), D->getBeginLoc()); in EmitTopLevelStmt()
6852 CurCGF->EmitStmt(D->getStmt()); in EmitTopLevelStmt()
6856 for (auto *I : DC->decls()) { in EmitDeclContext()
6858 // are themselves considered "top-level", so EmitTopLevelDecl on an in EmitDeclContext()
6861 // ExportDecl) that does stop them from being considered "top-level". in EmitDeclContext()
6863 for (auto *M : OID->methods()) in EmitDeclContext()
6871 /// EmitTopLevelDecl - Emit code for a single top level declaration.
6874 if (D->isTemplated()) in EmitTopLevelDecl()
6878 if (auto *FD = dyn_cast<FunctionDecl>(D); FD && FD->isImmediateFunction()) in EmitTopLevelDecl()
6881 switch (D->getKind()) { in EmitTopLevelDecl()
6892 // Function-like, but does not result in code emission. in EmitTopLevelDecl()
6900 for (auto *B : DD->bindings()) in EmitTopLevelDecl()
6901 if (auto *HD = B->getHoldingVar()) in EmitTopLevelDecl()
6915 const auto *Spec = cast<ClassTemplateSpecializationDecl>(D); in EmitTopLevelDecl() local
6917 if (Spec->getSpecializationKind() == in EmitTopLevelDecl()
6919 Spec->hasDefinition()) in EmitTopLevelDecl()
6920 DI->completeTemplateDefinition(*Spec); in EmitTopLevelDecl()
6925 if (CRD->hasDefinition()) in EmitTopLevelDecl()
6926 DI->EmitAndRetainType(getContext().getRecordType(cast<RecordDecl>(D))); in EmitTopLevelDecl()
6927 if (auto *ES = D->getASTContext().getExternalSource()) in EmitTopLevelDecl()
6928 if (ES->hasExternalDefinitions(D) == ExternalASTSource::EK_Never) in EmitTopLevelDecl()
6929 DI->completeUnusedClass(*CRD); in EmitTopLevelDecl()
6932 for (auto *I : CRD->decls()) in EmitTopLevelDecl()
6951 DI->EmitUsingDecl(cast<UsingDecl>(*D)); in EmitTopLevelDecl()
6955 DI->EmitUsingEnumDecl(cast<UsingEnumDecl>(*D)); in EmitTopLevelDecl()
6959 DI->EmitNamespaceAlias(cast<NamespaceAliasDecl>(*D)); in EmitTopLevelDecl()
6963 DI->EmitUsingDirective(cast<UsingDirectiveDecl>(*D)); in EmitTopLevelDecl()
6976 // Objective-C Decls in EmitTopLevelDecl()
6985 if (Proto->isThisDeclarationADefinition()) in EmitTopLevelDecl()
6986 ObjCRuntime->GenerateProtocol(Proto); in EmitTopLevelDecl()
6993 ObjCRuntime->GenerateCategory(cast<ObjCCategoryImplDecl>(D)); in EmitTopLevelDecl()
7000 ObjCRuntime->GenerateClass(OMD); in EmitTopLevelDecl()
7004 DI->getOrCreateInterfaceType(getContext().getObjCInterfaceType( in EmitTopLevelDecl()
7005 OMD->getClassInterface()), OMD->getLocation()); in EmitTopLevelDecl()
7011 if (OMD->getBody()) in EmitTopLevelDecl()
7016 ObjCRuntime->RegisterAlias(cast<ObjCCompatibleAliasDecl>(D)); in EmitTopLevelDecl()
7021 switch (PCD->getCommentKind()) { in EmitTopLevelDecl()
7025 AppendLinkerOptions(PCD->getArg()); in EmitTopLevelDecl()
7028 AddDependentLib(PCD->getArg()); in EmitTopLevelDecl()
7040 AddDetectMismatch(PDMD->getName(), PDMD->getValue()); in EmitTopLevelDecl()
7049 // File-scope asm is ignored during device-side CUDA compilation. in EmitTopLevelDecl()
7052 // File-scope asm is ignored during device-side OpenMP compilation. in EmitTopLevelDecl()
7055 // File-scope asm is ignored during device-side SYCL compilation. in EmitTopLevelDecl()
7059 getModule().appendModuleInlineAsm(AD->getAsmString()->getString()); in EmitTopLevelDecl()
7071 if (!ImportedModules.insert(Import->getImportedModule())) in EmitTopLevelDecl()
7075 if (!Import->getImportedOwningModule()) { in EmitTopLevelDecl()
7077 DI->EmitImportDecl(*Import); in EmitTopLevelDecl()
7080 // For C++ standard modules we are done - we will call the module in EmitTopLevelDecl()
7083 if (CXX20ModuleInits && Import->getImportedModule() && in EmitTopLevelDecl()
7084 Import->getImportedModule()->isNamedModule()) in EmitTopLevelDecl()
7087 // For clang C++ module map modules the initializers for sub-modules are in EmitTopLevelDecl()
7093 Visited.insert(Import->getImportedModule()); in EmitTopLevelDecl()
7094 Stack.push_back(Import->getImportedModule()); in EmitTopLevelDecl()
7105 for (auto *Submodule : Mod->submodules()) { in EmitTopLevelDecl()
7108 if (Submodule->IsExplicit) in EmitTopLevelDecl()
7145 DI->EmitAndRetainType( in EmitTopLevelDecl()
7151 if (cast<RecordDecl>(D)->getDefinition()) in EmitTopLevelDecl()
7152 DI->EmitAndRetainType(getContext().getRecordType(cast<RecordDecl>(D))); in EmitTopLevelDecl()
7157 if (cast<EnumDecl>(D)->getDefinition()) in EmitTopLevelDecl()
7158 DI->EmitAndRetainType(getContext().getEnumType(cast<EnumDecl>(D))); in EmitTopLevelDecl()
7167 // non-top-level decl. FIXME: Would be nice to have an isTopLevelDeclKind in EmitTopLevelDecl()
7178 switch (D->getKind()) { in AddDeferredUnusedCoverageMapping()
7185 if (!cast<FunctionDecl>(D)->doesThisDeclarationHaveABody()) in AddDeferredUnusedCoverageMapping()
7188 if (LimitedCoverage && SM.getMainFileID() != SM.getFileID(D->getBeginLoc())) in AddDeferredUnusedCoverageMapping()
7191 SM.isInSystemHeader(D->getBeginLoc())) in AddDeferredUnusedCoverageMapping()
7206 if (Fn->isTemplateInstantiation()) in ClearUnusedCoverageMapping()
7207 ClearUnusedCoverageMapping(Fn->getTemplateInstantiationPattern()); in ClearUnusedCoverageMapping()
7213 // We call takeVector() here to avoid use-after-free. in EmitDeferredUnusedCoverageMappings()
7221 switch (D->getKind()) { in EmitDeferredUnusedCoverageMappings()
7254 // alias for "main" in the no-argument case so that libc can detect when in EmitMainVoidAlias()
7255 // new-style no-argument main is in used. in EmitMainVoidAlias()
7257 if (!F->isDeclaration() && F->arg_size() == 0 && !F->isVarArg() && in EmitMainVoidAlias()
7258 F->getReturnType()->isIntegerTy(Context.getTargetInfo().getIntWidth())) { in EmitMainVoidAlias()
7260 GA->setVisibility(llvm::GlobalValue::HiddenVisibility); in EmitMainVoidAlias()
7285 GlobalMetadata->addOperand(llvm::MDNode::get(CGM.getLLVMContext(), Ops)); in EmitGlobalDeclMetadata()
7296 // It isn't valid to replace the extern-C ifuncs if all we find is itself! in CheckAndReplaceExternCIFuncs()
7303 for (llvm::User *User : Elem->users()) { in CheckAndReplaceExternCIFuncs()
7308 if (ConstExpr->getOpcode() != llvm::Instruction::BitCast) in CheckAndReplaceExternCIFuncs()
7311 for (llvm::User *CEUser : ConstExpr->users()) { in CheckAndReplaceExternCIFuncs()
7333 IFunc->setResolver(nullptr); in CheckAndReplaceExternCIFuncs()
7335 ConstExpr->destroyConstant(); in CheckAndReplaceExternCIFuncs()
7339 Elem->eraseFromParent(); in CheckAndReplaceExternCIFuncs()
7342 // The type of the resolver is always just a function-type that returns the in CheckAndReplaceExternCIFuncs()
7346 llvm::FunctionType::get(IFunc->getType(), /*isVarArg*/ false); in CheckAndReplaceExternCIFuncs()
7348 CppFunc->getName(), ResolverTy, {}, /*ForVTable*/ false); in CheckAndReplaceExternCIFuncs()
7349 IFunc->setResolver(Resolver); in CheckAndReplaceExternCIFuncs()
7373 getModule().getNamedValue(Name->getName()); in EmitStaticExternCAliases()
7378 addCompilerUsedGlobal(llvm::GlobalAlias::create(Name->getName(), Val)); in EmitStaticExternCAliases()
7387 Result = Res->getValue(); in lookupRepresentativeDecl()
7427 Alloca->setMetadata( in EmitDeclMetadata()
7444 IdentMetadata->addOperand(llvm::MDNode::get(Ctx, IdentNode)); in EmitVersionIdentMetadata()
7454 CommandLineMetadata->addOperand(llvm::MDNode::get(Ctx, CommandLineNode)); in EmitCommandLineMetadata()
7468 for (int i = 0, e = CUNode->getNumOperands(); i != e; ++i) { in EmitCoverageFile()
7469 llvm::MDNode *CU = CUNode->getOperand(i); in EmitCoverageFile()
7471 GCov->addOperand(llvm::MDNode::get(Ctx, Elts)); in EmitCoverageFile()
7483 if (ForEH && Ty->isObjCObjectPointerType() && in GetAddrOfRTTIDescriptor()
7485 return ObjCRuntime->GetEHType(Ty); in GetAddrOfRTTIDescriptor()
7491 // Do not emit threadprivates in simd-only mode. in EmitOMPThreadPrivateDecl()
7494 for (auto RefExpr : D->varlists()) { in EmitOMPThreadPrivateDecl()
7495 auto *VD = cast<VarDecl>(cast<DeclRefExpr>(RefExpr)->getDecl()); in EmitOMPThreadPrivateDecl()
7497 VD->getAnyInitializer() && in EmitOMPThreadPrivateDecl()
7498 !VD->getAnyInitializer()->isConstantInitializer(getContext(), in EmitOMPThreadPrivateDecl()
7502 getTypes().ConvertTypeForMem(VD->getType()), in EmitOMPThreadPrivateDecl()
7505 VD, Addr, RefExpr->getBeginLoc(), PerformInit)) in EmitOMPThreadPrivateDecl()
7513 if (auto *FnType = T->getAs<FunctionProtoType>()) in CreateMetadataIdentifierImpl()
7515 FnType->getReturnType(), FnType->getParamTypes(), in CreateMetadataIdentifierImpl()
7516 FnType->getExtProtoInfo().withExceptionSpec(EST_None)); in CreateMetadataIdentifierImpl()
7522 if (isExternallyVisible(T->getLinkage())) { in CreateMetadataIdentifierImpl()
7552 // originally pointed-to type, e.g. 'const char *' and 'char * const *'
7556 if (!Ty->isPointerType()) in GeneralizeType()
7561 Ty->getPointeeType().getCVRQualifiers())); in GeneralizeType()
7566 if (auto *FnType = Ty->getAs<FunctionProtoType>()) { in GeneralizeFunctionType()
7568 for (auto &Param : FnType->param_types()) in GeneralizeFunctionType()
7572 GeneralizeType(Ctx, FnType->getReturnType()), in GeneralizeFunctionType()
7573 GeneralizedParams, FnType->getExtProtoInfo()); in GeneralizeFunctionType()
7576 if (auto *FnType = Ty->getAs<FunctionNoProtoType>()) in GeneralizeFunctionType()
7578 GeneralizeType(Ctx, FnType->getReturnType())); in GeneralizeFunctionType()
7588 /// Returns whether this module needs the "all-vtables" type identifier.
7590 // Returns true if at least one of vtable-based CFI checkers is enabled and in NeedAllVtablesTypeId()
7606 CreateMetadataIdentifierForType(QualType(RD->getTypeForDecl(), 0)); in AddVTableTypeMetadata()
7607 VTable->addTypeMetadata(Offset.getQuantity(), MD); in AddVTableTypeMetadata()
7611 VTable->addTypeMetadata(Offset.getQuantity(), in AddVTableTypeMetadata()
7615 llvm::Metadata *MD = llvm::MDString::get(getLLVMContext(), "all-vtables"); in AddVTableTypeMetadata()
7616 VTable->addTypeMetadata(Offset.getQuantity(), MD); in AddVTableTypeMetadata()
7630 llvm::Constant *C = ConstantEmitter(CGF).emitAbstract(E, E->getType()); in createOpenCLIntToSamplerConversion()
7631 auto *SamplerT = getOpenCLRuntime().getSamplerType(E->getType().getTypePtr()); in createOpenCLIntToSamplerConversion()
7632 auto *FTy = llvm::FunctionType::get(SamplerT, {C->getType()}, false); in createOpenCLIntToSamplerConversion()
7640 return getNaturalTypeAlignment(T->getPointeeType(), BaseInfo, TBAAInfo, in getNaturalPointeeTypeAlignment()
7657 if (auto TT = T->getAs<TypedefType>()) { in getNaturalTypeAlignment()
7658 if (auto Align = TT->getDecl()->getMaxAlignment()) { in getNaturalTypeAlignment()
7665 bool AlignForArray = T->isArrayType(); in getNaturalTypeAlignment()
7671 if (T->isIncompleteType()) { in getNaturalTypeAlignment()
7691 (RD = T->getAsCXXRecordDecl())) { in getNaturalTypeAlignment()
7694 // non-virtual alignment. in getNaturalTypeAlignment()
7713 // This number is positive only when -ftrivial-auto-var-init-stop-after=* is in stopAutoInit()
7721 "-ftrivial-auto-var-init-stop-after=%0 has been enabled to limit the " in stopAutoInit()
7722 "number of times ftrivial-auto-var-init=%1 gets applied."); in stopAutoInit()
7747 PresumedLoc PLoc = SM.getPresumedLoc(D->getLocation()); in printPostfixForExternalizedDecl()
7760 PLoc = SM.getPresumedLoc(D->getLocation(), /*UseLineDirectives=*/false); in printPostfixForExternalizedDecl()
7776 assert(NewBuilder->DeferredDecls.empty() && in moveLazyEmissionStates()
7778 NewBuilder->DeferredDecls = std::move(DeferredDecls); in moveLazyEmissionStates()
7782 assert(NewBuilder->DeferredVTables.empty() && in moveLazyEmissionStates()
7784 NewBuilder->DeferredVTables = std::move(DeferredVTables); in moveLazyEmissionStates()
7786 assert(NewBuilder->MangledDeclNames.empty() && in moveLazyEmissionStates()
7788 assert(NewBuilder->Manglings.empty() && in moveLazyEmissionStates()
7790 NewBuilder->Manglings = std::move(Manglings); in moveLazyEmissionStates()
7792 NewBuilder->WeakRefReferences = std::move(WeakRefReferences); in moveLazyEmissionStates()
7794 NewBuilder->ABI->MangleCtx = std::move(ABI->MangleCtx); in moveLazyEmissionStates()