21 #include "llvm/ADT/StringExtras.h"
22 #include "llvm/IR/Intrinsics.h"
23 #include "llvm/IR/MDBuilder.h"
24 #include "llvm/Support/Path.h"
26 using namespace clang;
27 using namespace CodeGen;
35 "VarDecl must have global or local (in the case of OpenCL and SYCL) "
38 "Should not call EmitDeclInit on a reference!");
68 llvm_unreachable(
"bad evaluation kind");
96 assert(!D.
getTLSKind() &&
"should have rejected this");
100 llvm::FunctionCallee
Func;
101 llvm::Constant *Argument;
111 bool CanRegisterDestructor =
119 if (
Record && (CanRegisterDestructor || UsingExternalHelper)) {
120 assert(!
Record->hasTrivialDestructor());
127 auto DestTy = llvm::PointerType::get(
135 Argument = llvm::ConstantPointerNull::get(DestTy);
145 Argument = llvm::Constant::getNullValue(CGF.
Int8PtrTy);
154 llvm::Constant *Addr) {
167 llvm::Type *ResTy = llvm::PointerType::get(
169 llvm::Type *ObjectPtr[1] = {ResTy};
170 llvm::Function *InvariantStart =
CGM.
getIntrinsic(InvStartID, ObjectPtr);
173 uint64_t Width = Size.getQuantity();
174 llvm::Value *Args[2] = {llvm::ConstantInt::getSigned(
Int64Ty, Width), Addr};
175 Builder.CreateCall(InvariantStart, Args);
179 llvm::GlobalVariable *GV,
201 unsigned ActualAddrSpace = GV->getAddressSpace();
202 llvm::Constant *DeclPtr = GV;
203 if (ActualAddrSpace != ExpectedAddrSpace) {
204 llvm::PointerType *PTy =
206 DeclPtr = llvm::ConstantExpr::getAddrSpaceCast(DeclPtr, PTy);
210 DeclPtr, GV->getValueType(),
getContext().getDeclAlign(&D));
214 D.
hasAttr<OMPThreadPrivateDeclAttr>()) {
216 &D, DeclAddr, D.
getAttr<OMPThreadPrivateDeclAttr>()->getLocation(),
230 assert(PerformInit &&
"cannot have constant initializer which needs "
231 "destruction for reference");
239 llvm::FunctionCallee dtor,
240 llvm::Constant *addr) {
242 llvm::FunctionType *ty = llvm::FunctionType::get(
CGM.
VoidTy,
false);
245 llvm::raw_svector_ostream Out(FnName);
261 llvm::CallInst *call = CGF.
Builder.CreateCall(dtor, addr);
264 if (
auto *dtorFn = dyn_cast<llvm::Function>(
265 dtor.getCallee()->stripPointerCastsAndAliases()))
266 call->setCallingConv(dtorFn->getCallingConv());
276 const VarDecl &D, llvm::FunctionCallee Dtor, llvm::Constant *Addr,
277 llvm::FunctionCallee &AtExit) {
280 llvm::raw_svector_ostream Out(FnName);
289 llvm::FunctionType *StubTy =
290 llvm::FunctionType::get(
CGM.
IntTy, {CGM.IntTy},
true);
300 Args.push_back(&IPD);
309 llvm::CallInst *call = CGF.
Builder.CreateCall(Dtor, Addr);
312 if (
auto *DtorFn = dyn_cast<llvm::Function>(
313 Dtor.getCallee()->stripPointerCastsAndAliases()))
314 call->setCallingConv(DtorFn->getCallingConv());
327 llvm::FunctionCallee dtor,
328 llvm::Constant *addr) {
336 llvm::FunctionCallee Dtor,
337 llvm::Constant *Addr) {
345 assert(dtorStub->getType() ==
346 llvm::PointerType::get(
347 llvm::FunctionType::get(
CGM.
VoidTy,
false),
348 dtorStub->getType()->getPointerAddressSpace()) &&
349 "Argument to atexit has a wrong type.");
351 llvm::FunctionType *atexitTy =
352 llvm::FunctionType::get(
IntTy, dtorStub->getType(),
false);
354 llvm::FunctionCallee atexit =
357 if (llvm::Function *atexitFn = dyn_cast<llvm::Function>(atexit.getCallee()))
358 atexitFn->setDoesNotThrow();
372 assert(dtorStub->getType() ==
373 llvm::PointerType::get(
374 llvm::FunctionType::get(
CGM.
VoidTy,
false),
375 dtorStub->getType()->getPointerAddressSpace()) &&
376 "Argument to unatexit has a wrong type.");
378 llvm::FunctionType *unatexitTy =
379 llvm::FunctionType::get(
IntTy, {dtorStub->getType()},
false);
381 llvm::FunctionCallee unatexit =
384 cast<llvm::Function>(unatexit.getCallee())->setDoesNotThrow();
390 llvm::GlobalVariable *DeclPtr,
397 "this initialization requires a guard variable, which "
398 "the kernel does not support");
404 llvm::BasicBlock *InitBlock,
405 llvm::BasicBlock *NoInitBlock,
412 static const uint64_t InitsPerTLSVar = 1024;
413 static const uint64_t InitsPerLocalVar = 1024 * 1024;
415 llvm::MDNode *Weights;
427 NumInits = InitsPerTLSVar;
429 NumInits = InitsPerLocalVar;
434 Weights = MDHelper.createBranchWeights(1, NumInits - 1);
437 Builder.CreateCondBr(NeedsInit, InitBlock, NoInitBlock, Weights);
441 llvm::FunctionType *FTy,
const Twine &Name,
const CGFunctionInfo &FI,
443 llvm::Function *Fn = llvm::Function::Create(FTy,
Linkage, Name, &
getModule());
447 if (
const char *Section =
getTarget().getStaticInitSectionSpecifier())
448 Fn->setSection(Section);
451 if (
Linkage == llvm::GlobalVariable::InternalLinkage)
457 Fn->setDoesNotThrow();
459 if (
getLangOpts().Sanitize.has(SanitizerKind::Address) &&
461 Fn->addFnAttr(llvm::Attribute::SanitizeAddress);
463 if (
getLangOpts().Sanitize.has(SanitizerKind::KernelAddress) &&
465 Fn->addFnAttr(llvm::Attribute::SanitizeAddress);
467 if (
getLangOpts().Sanitize.has(SanitizerKind::HWAddress) &&
469 Fn->addFnAttr(llvm::Attribute::SanitizeHWAddress);
471 if (
getLangOpts().Sanitize.has(SanitizerKind::KernelHWAddress) &&
473 Fn->addFnAttr(llvm::Attribute::SanitizeHWAddress);
475 if (
getLangOpts().Sanitize.has(SanitizerKind::MemtagStack) &&
477 Fn->addFnAttr(llvm::Attribute::SanitizeMemTag);
479 if (
getLangOpts().Sanitize.has(SanitizerKind::Thread) &&
481 Fn->addFnAttr(llvm::Attribute::SanitizeThread);
483 if (
getLangOpts().Sanitize.has(SanitizerKind::Memory) &&
485 Fn->addFnAttr(llvm::Attribute::SanitizeMemory);
487 if (
getLangOpts().Sanitize.has(SanitizerKind::KernelMemory) &&
489 Fn->addFnAttr(llvm::Attribute::SanitizeMemory);
491 if (
getLangOpts().Sanitize.has(SanitizerKind::SafeStack) &&
493 Fn->addFnAttr(llvm::Attribute::SafeStack);
495 if (
getLangOpts().Sanitize.has(SanitizerKind::ShadowCallStack) &&
497 Fn->addFnAttr(llvm::Attribute::ShadowCallStack);
505 void CodeGenModule::EmitPointerToInitFunc(
const VarDecl *D,
506 llvm::GlobalVariable *GV,
507 llvm::Function *InitFunc,
509 llvm::GlobalVariable *PtrArray =
new llvm::GlobalVariable(
510 TheModule, InitFunc->getType(),
true,
511 llvm::GlobalValue::PrivateLinkage, InitFunc,
"__cxx_init_fn_ptr");
512 PtrArray->setSection(ISA->getSection());
516 if (llvm::Comdat *C = GV->getComdat())
517 PtrArray->setComdat(C);
521 CodeGenModule::EmitCXXGlobalVarDeclInitFunc(
const VarDecl *D,
522 llvm::GlobalVariable *Addr,
531 (D->
hasAttr<CUDADeviceAttr>() || D->
hasAttr<CUDAConstantAttr>() ||
536 auto I = DelayedCXXInitPosition.find(D);
537 if (I != DelayedCXXInitPosition.end() && I->second == ~0
U)
540 llvm::FunctionType *FTy = llvm::FunctionType::get(
VoidTy,
false);
543 llvm::raw_svector_ostream Out(FnName);
551 auto *ISA = D->
getAttr<InitSegAttr>();
555 llvm::GlobalVariable *COMDATKey =
562 CXXThreadLocalInits.push_back(Fn);
563 CXXThreadLocalInitVars.push_back(D);
564 }
else if (PerformInit && ISA) {
568 if (ISA->getSection() ==
".CRT$XCC")
570 else if (ISA->getSection() ==
".CRT$XCL")
576 EmitPointerToInitFunc(D, Addr, Fn, ISA);
577 }
else if (
auto *IPA = D->
getAttr<InitPriorityAttr>()) {
579 PrioritizedCXXGlobalInits.size());
580 PrioritizedCXXGlobalInits.push_back(std::make_pair(Key, Fn));
600 I = DelayedCXXInitPosition.find(D);
608 I == DelayedCXXInitPosition.end() ? CXXGlobalInits.size() : I->second;
610 if (COMDATKey && (
getTriple().isOSBinFormatELF() ||
620 llvm::Comdat *
C = Addr->getComdat();
621 if (COMDATKey && C &&
627 I = DelayedCXXInitPosition.find(D);
628 if (I == DelayedCXXInitPosition.end()) {
629 CXXGlobalInits.push_back(Fn);
630 }
else if (I->second != ~0
U) {
631 assert(I->second < CXXGlobalInits.size() &&
632 CXXGlobalInits[I->second] ==
nullptr);
633 CXXGlobalInits[I->second] = Fn;
638 DelayedCXXInitPosition[D] = ~0
U;
641 void CodeGenModule::EmitCXXThreadLocalInitFunc() {
643 *
this, CXXThreadLocals, CXXThreadLocalInits, CXXThreadLocalInitVars);
645 CXXThreadLocalInits.clear();
646 CXXThreadLocalInitVars.clear();
647 CXXThreadLocals.clear();
665 void CodeGenModule::EmitCXXModuleInitFunc(
Module *Primary) {
667 "The function should only be called for C++20 named module interface"
670 while (!CXXGlobalInits.empty() && !CXXGlobalInits.back())
671 CXXGlobalInits.pop_back();
679 for (
auto I : Primary->
Exports)
680 AllImports.insert(I.getPointer());
683 AllImports.insert(M);
687 assert((SubM->isGlobalModule() || SubM->isPrivateModule()) &&
688 "The sub modules of C++20 module unit should only be global module "
689 "fragments or private module framents.");
690 assert(SubM->Exports.empty() &&
691 "The global mdoule fragments and the private module fragments are "
692 "not allowed to export import modules.");
694 AllImports.insert(M);
698 for (
Module *M : AllImports) {
706 llvm::FunctionType *FTy = llvm::FunctionType::get(
VoidTy,
false);
709 llvm::raw_svector_ostream Out(FnName);
710 cast<ItaniumMangleContext>(
getCXXABI().getMangleContext())
711 .mangleModuleInitializer(M, Out);
714 "We should only have one use of the initializer call");
715 llvm::Function *Fn = llvm::Function::Create(
716 FTy, llvm::Function::ExternalLinkage, FnName.str(), &
getModule());
717 ModuleInits.push_back(Fn);
722 if (!PrioritizedCXXGlobalInits.empty()) {
724 llvm::array_pod_sort(PrioritizedCXXGlobalInits.begin(),
725 PrioritizedCXXGlobalInits.end());
727 I = PrioritizedCXXGlobalInits.begin(),
728 E = PrioritizedCXXGlobalInits.end();
731 std::upper_bound(I + 1, E, *I, GlobalInitPriorityCmp());
733 for (; I < PrioE; ++I)
734 ModuleInits.push_back(I->second);
739 for (
auto *F : CXXGlobalInits)
740 ModuleInits.push_back(F);
742 llvm::FunctionType *FTy = llvm::FunctionType::get(
VoidTy,
false);
752 llvm::raw_svector_ostream Out(InitFnName);
753 cast<ItaniumMangleContext>(
getCXXABI().getMangleContext())
754 .mangleModuleInitializer(Primary, Out);
757 llvm::GlobalVariable::ExternalLinkage);
762 if (!ModuleInits.empty()) {
764 llvm::GlobalVariable *Guard =
new llvm::GlobalVariable(
766 llvm::GlobalVariable::InternalLinkage,
767 llvm::ConstantInt::get(
Int8Ty, 0), InitFnName.str() +
"__in_chrg");
786 Fn->setCallingConv(llvm::CallingConv::SPIR_KERNEL);
792 Fn->setCallingConv(llvm::CallingConv::AMDGPU_KERNEL);
793 Fn->addFnAttr(
"device-init");
798 PrioritizedCXXGlobalInits.clear();
799 CXXGlobalInits.clear();
809 for (
size_t i = 0; i <
FileName.size(); ++i) {
820 assert(
Priority <= 65535 &&
"Priority should always be <= 65535.");
824 std::string PrioritySuffix = llvm::utostr(
Priority);
825 PrioritySuffix = std::string(6 - PrioritySuffix.size(),
'0') + PrioritySuffix;
827 return PrioritySuffix;
831 CodeGenModule::EmitCXXGlobalInitFunc() {
832 while (!CXXGlobalInits.empty() && !CXXGlobalInits.back())
833 CXXGlobalInits.pop_back();
837 if (CXX20ModuleInits)
838 for (
Module *M : ImportedModules) {
842 llvm::FunctionType *FTy = llvm::FunctionType::get(
VoidTy,
false);
845 llvm::raw_svector_ostream Out(FnName);
846 cast<ItaniumMangleContext>(
getCXXABI().getMangleContext())
847 .mangleModuleInitializer(M, Out);
850 "We should only have one use of the initializer call");
851 llvm::Function *Fn = llvm::Function::Create(
852 FTy, llvm::Function::ExternalLinkage, FnName.str(), &
getModule());
853 ModuleInits.push_back(Fn);
856 if (ModuleInits.empty() && CXXGlobalInits.empty() &&
857 PrioritizedCXXGlobalInits.empty())
860 llvm::FunctionType *FTy = llvm::FunctionType::get(
VoidTy,
false);
864 if (!PrioritizedCXXGlobalInits.empty()) {
866 llvm::array_pod_sort(PrioritizedCXXGlobalInits.begin(),
867 PrioritizedCXXGlobalInits.end());
872 I = PrioritizedCXXGlobalInits.begin(),
873 E = PrioritizedCXXGlobalInits.end(); I != E; ) {
875 PrioE = std::upper_bound(I + 1, E, *I, GlobalInitPriorityCmp());
877 LocalCXXGlobalInits.clear();
879 unsigned int Priority = I->first.priority;
884 if (!ModuleInits.empty()) {
885 for (
auto *F : ModuleInits)
886 LocalCXXGlobalInits.push_back(F);
890 for (; I < PrioE; ++I)
891 LocalCXXGlobalInits.push_back(I->second);
896 PrioritizedCXXGlobalInits.clear();
899 if (
getCXXABI().useSinitAndSterm() && ModuleInits.empty() &&
900 CXXGlobalInits.empty())
903 for (
auto *F : CXXGlobalInits)
904 ModuleInits.push_back(F);
905 CXXGlobalInits.clear();
912 if (CXX20ModuleInits &&
getContext().getCurrentNamedModule() &&
913 !
getContext().getCurrentNamedModule()->isModuleImplementation()) {
915 llvm::raw_svector_ostream Out(InitFnName);
916 cast<ItaniumMangleContext>(
getCXXABI().getMangleContext())
917 .mangleModuleInitializer(
getContext().getCurrentNamedModule(), Out);
920 llvm::GlobalVariable::ExternalLinkage);
940 Fn->setCallingConv(llvm::CallingConv::SPIR_KERNEL);
946 Fn->setCallingConv(llvm::CallingConv::AMDGPU_KERNEL);
947 Fn->addFnAttr(
"device-init");
953 void CodeGenModule::EmitCXXGlobalCleanUpFunc() {
954 if (CXXGlobalDtorsOrStermFinalizers.empty() &&
955 PrioritizedCXXStermFinalizers.empty())
958 llvm::FunctionType *FTy = llvm::FunctionType::get(
VoidTy,
false);
962 if (!PrioritizedCXXStermFinalizers.empty()) {
964 llvm::array_pod_sort(PrioritizedCXXStermFinalizers.begin(),
965 PrioritizedCXXStermFinalizers.end());
970 I = PrioritizedCXXStermFinalizers.begin(),
971 E = PrioritizedCXXStermFinalizers.end();
974 std::upper_bound(I + 1, E, *I, StermFinalizerPriorityCmp());
976 LocalCXXStermFinalizers.clear();
978 unsigned int Priority = I->first.priority;
982 for (; I < PrioE; ++I) {
983 llvm::FunctionCallee DtorFn = I->second;
984 LocalCXXStermFinalizers.emplace_back(DtorFn.getFunctionType(),
985 DtorFn.getCallee(),
nullptr);
989 Fn, LocalCXXStermFinalizers);
992 PrioritizedCXXStermFinalizers.clear();
995 if (CXXGlobalDtorsOrStermFinalizers.empty())
1003 Fn, CXXGlobalDtorsOrStermFinalizers);
1005 CXXGlobalDtorsOrStermFinalizers.clear();
1011 llvm::GlobalVariable *Addr,
1015 DebugInfo =
nullptr;
1032 if (Addr->hasWeakLinkage() || Addr->hasLinkOnceLinkage() ||
1057 llvm::BasicBlock *ExitBlock =
nullptr;
1063 "guard.uninitialized");
1090 for (
unsigned i = 0, e = Decls.size(); i != e; ++i)
1094 Scope.ForceCleanup();
1107 ArrayRef<std::tuple<llvm::FunctionType *, llvm::WeakTrackingVH,
1109 DtorsOrStermFinalizers) {
1118 for (
unsigned i = 0, e = DtorsOrStermFinalizers.size(); i != e; ++i) {
1119 llvm::FunctionType *CalleeTy;
1120 llvm::Value *Callee;
1121 llvm::Constant *Arg;
1122 std::tie(CalleeTy, Callee, Arg) = DtorsOrStermFinalizers[e - i - 1];
1124 llvm::CallInst *CI =
nullptr;
1125 if (Arg ==
nullptr) {
1128 "Arg could not be nullptr unless using sinit and sterm functions.");
1129 CI =
Builder.CreateCall(CalleeTy, Callee);
1131 CI =
Builder.CreateCall(CalleeTy, Callee, Arg);
1134 if (llvm::Function *F = dyn_cast<llvm::Function>(Callee))
1135 CI->setCallingConv(F->getCallingConv());
1147 bool useEHCleanupForArray,
const VarDecl *VD) {
1151 args.push_back(&Dst);
1157 FTy,
"__cxx_global_array_dtor", FI, VD->
getLocation());
static std::string getPrioritySuffix(unsigned int Priority)
static void EmitDeclInit(CodeGenFunction &CGF, const VarDecl &D, ConstantAddress DeclPtr)
static void EmitDeclDestroy(CodeGenFunction &CGF, const VarDecl &D, ConstantAddress Addr)
Emit code to cause the destruction of the given variable with static storage duration.
static SmallString< 128 > getTransformedFileName(llvm::Module &M)
static void EmitDeclInvariant(CodeGenFunction &CGF, const VarDecl &D, llvm::Constant *Addr)
Emit code to cause the variable at the given address to be considered as constant from this point onw...
Defines the clang::LangOptions interface.
llvm::MachO::Record Record
const LangOptions & getLangOpts() const
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
unsigned getTargetAddressSpace(LangAS AS) const
Represents a C++ destructor within a class.
Represents a C++ struct/union/class.
CharUnits - This is an opaque type for sizes expressed in character units.
llvm::Align getAsAlign() const
getAsAlign - Returns Quantity as a valid llvm::Align, Beware llvm::Align assumes power of two 8-bit b...
static CharUnits One()
One - Construct a CharUnits quantity of one.
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
Like RawAddress, an abstract representation of an aligned address, but the pointer contained in this ...
static AggValueSlot forLValue(const LValue &LV, IsDestructed_t isDestructed, NeedsGCBarriers_t needsGC, IsAliased_t isAliased, Overlap_t mayOverlap, IsZeroed_t isZeroed=IsNotZeroed, IsSanitizerChecked_t isChecked=IsNotSanitizerChecked)
static ApplyDebugLocation CreateArtificial(CodeGenFunction &CGF)
Apply TemporaryLocation if it is valid.
static ApplyDebugLocation CreateEmpty(CodeGenFunction &CGF)
Set the IRBuilder to not attach debug locations.
llvm::StoreInst * CreateStore(llvm::Value *Val, Address Addr, bool IsVolatile=false)
llvm::Value * CreateIsNull(Address Addr, const Twine &Name="")
llvm::LoadInst * CreateLoad(Address Addr, const llvm::Twine &Name="")
virtual bool HasThisReturn(GlobalDecl GD) const
Returns true if the given constructor or destructor is one of the kinds that the ABI says returns 'th...
virtual bool useSinitAndSterm() const
virtual void EmitGuardedInit(CodeGenFunction &CGF, const VarDecl &D, llvm::GlobalVariable *DeclPtr, bool PerformInit)=0
Emits the guarded initializer and destructor setup for the given variable, given that it couldn't be ...
virtual void registerGlobalDtor(CodeGenFunction &CGF, const VarDecl &D, llvm::FunctionCallee Dtor, llvm::Constant *Addr)=0
Emit code to force the execution of a destructor during global teardown.
virtual bool canCallMismatchedFunctionType() const
Returns true if the target allows calling a function through a pointer with a different signature tha...
MangleContext & getMangleContext()
Gets the mangle context.
virtual void EmitThreadLocalInitFuncs(CodeGenModule &CGM, ArrayRef< const VarDecl * > CXXThreadLocals, ArrayRef< llvm::Function * > CXXThreadLocalInits, ArrayRef< const VarDecl * > CXXThreadLocalInitVars)=0
Emits ABI-required functions necessary to initialize thread_local variables in this translation unit.
CGFunctionInfo - Class to encapsulate the information about a function definition.
void annotateHLSLResource(const VarDecl *D, llvm::GlobalVariable *GV)
virtual void EmitObjCWeakAssign(CodeGen::CodeGenFunction &CGF, llvm::Value *src, Address dest)=0
virtual void EmitObjCGlobalAssign(CodeGen::CodeGenFunction &CGF, llvm::Value *src, Address dest, bool threadlocal=false)=0
virtual llvm::Function * emitThreadPrivateVarDefinition(const VarDecl *VD, Address VDAddr, SourceLocation Loc, bool PerformInit, CodeGenFunction *CGF=nullptr)
Emit a code for initialization of threadprivate variable.
Enters a new scope for capturing cleanups, all of which will be executed once the scope is exited.
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
llvm::Function * createAtExitStub(const VarDecl &VD, llvm::FunctionCallee Dtor, llvm::Constant *Addr)
Create a stub function, suitable for being passed to atexit, which passes the given address to the gi...
void EmitCXXGuardedInit(const VarDecl &D, llvm::GlobalVariable *DeclPtr, bool PerformInit)
Emit code in this function to perform a guarded variable initialization.
void emitDestroy(Address addr, QualType type, Destroyer *destroyer, bool useEHCleanupForArray)
emitDestroy - Immediately perform the destruction of the given object.
llvm::CallInst * EmitNounwindRuntimeCall(llvm::FunctionCallee callee, const Twine &name="")
llvm::Function * createTLSAtExitStub(const VarDecl &VD, llvm::FunctionCallee Dtor, llvm::Constant *Addr, llvm::FunctionCallee &AtExit)
Create a stub function, suitable for being passed to __pt_atexit_np, which passes the given address t...
void EmitComplexExprIntoLValue(const Expr *E, LValue dest, bool isInit)
EmitComplexExprIntoLValue - Emit the given expression of complex type and place its result into the s...
void registerGlobalDtorWithAtExit(const VarDecl &D, llvm::FunctionCallee fn, llvm::Constant *addr)
Call atexit() with a function that passes the given argument to the given function.
void EmitObjCAutoreleasePoolCleanup(llvm::Value *Ptr)
llvm::BasicBlock * createBasicBlock(const Twine &name="", llvm::Function *parent=nullptr, llvm::BasicBlock *before=nullptr)
createBasicBlock - Create an LLVM basic block.
llvm::LLVMContext & getLLVMContext()
RValue EmitReferenceBindingToExpr(const Expr *E)
Emits a reference binding to the passed in expression.
void EmitScalarInit(const Expr *init, const ValueDecl *D, LValue lvalue, bool capturedByInit)
Destroyer * getDestroyer(QualType::DestructionKind destructionKind)
void EmitCXXGlobalVarDeclInit(const VarDecl &D, llvm::GlobalVariable *GV, bool PerformInit)
EmitCXXGlobalVarDeclInit - Create the initializer for a C++ variable with global storage.
ASTContext & getContext() const
void StartFunction(GlobalDecl GD, QualType RetTy, llvm::Function *Fn, const CGFunctionInfo &FnInfo, const FunctionArgList &Args, SourceLocation Loc=SourceLocation(), SourceLocation StartLoc=SourceLocation())
Emit code for the start of a function.
void GenerateCXXGlobalInitFunc(llvm::Function *Fn, ArrayRef< llvm::Function * > CXXThreadLocals, ConstantAddress Guard=ConstantAddress::invalid())
GenerateCXXGlobalInitFunc - Generates code for initializing global variables.
void GenerateCXXGlobalVarDeclInitFunc(llvm::Function *Fn, const VarDecl *D, llvm::GlobalVariable *Addr, bool PerformInit)
Emit the code necessary to initialize the given global variable.
void EmitCXXGuardedInitBranch(llvm::Value *NeedsInit, llvm::BasicBlock *InitBlock, llvm::BasicBlock *NoInitBlock, GuardKind Kind, const VarDecl *D)
Emit a branch to select whether or not to perform guarded initialization.
void EmitInvariantStart(llvm::Constant *Addr, CharUnits Size)
llvm::CallInst * EmitRuntimeCall(llvm::FunctionCallee callee, const Twine &name="")
llvm::Value * unregisterGlobalDtorWithUnAtExit(llvm::Constant *dtorStub)
Call unatexit() with function dtorStub.
void registerGlobalDtorWithLLVM(const VarDecl &D, llvm::FunctionCallee fn, llvm::Constant *addr)
Registers the dtor using 'llvm.global_dtors' for platforms that do not support an 'atexit()' function...
bool needsEHCleanup(QualType::DestructionKind kind)
Determines whether an EH cleanup is required to destroy a type with the given destruction kind.
llvm::Type * ConvertTypeForMem(QualType T)
llvm::Value * EmitObjCAutoreleasePoolPush()
Produce the code to do a objc_autoreleasepool_push.
static TypeEvaluationKind getEvaluationKind(QualType T)
getEvaluationKind - Return the TypeEvaluationKind of QualType T.
void EmitAggExpr(const Expr *E, AggValueSlot AS)
EmitAggExpr - Emit the computation of the specified expression of aggregate type.
llvm::Value * EmitScalarExpr(const Expr *E, bool IgnoreResultAssign=false)
EmitScalarExpr - Emit the computation of the specified expression of LLVM scalar type,...
LValue MakeAddrLValue(Address Addr, QualType T, AlignmentSource Source=AlignmentSource::Type)
void FinishFunction(SourceLocation EndLoc=SourceLocation())
FinishFunction - Complete IR generation of the current function.
llvm::Function * generateDestroyHelper(Address addr, QualType type, Destroyer *destroyer, bool useEHCleanupForArray, const VarDecl *VD)
generateDestroyHelper - Generates a helper function which, when invoked, destroys the given object.
Address ReturnValue
ReturnValue - The temporary alloca to hold the return value.
CodeGenTypes & getTypes() const
void GenerateCXXGlobalCleanUpFunc(llvm::Function *Fn, ArrayRef< std::tuple< llvm::FunctionType *, llvm::WeakTrackingVH, llvm::Constant * >> DtorsOrStermFinalizers)
GenerateCXXGlobalCleanUpFunc - Generates code for cleaning up global variables.
void EmitStoreOfScalar(llvm::Value *Value, Address Addr, bool Volatile, QualType Ty, AlignmentSource Source=AlignmentSource::Type, bool isInit=false, bool isNontemporal=false)
EmitStoreOfScalar - Store a scalar value to an address, taking care to appropriately convert from the...
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false)
EmitBlock - Emit the given block.
const LangOptions & getLangOpts() const
This class organizes the cross-function state that is used while generating LLVM code.
CGOpenMPRuntime & getOpenMPRuntime()
Return a reference to the configured OpenMP runtime.
const TargetInfo & getTarget() const
void SetInternalFunctionAttributes(GlobalDecl GD, llvm::Function *F, const CGFunctionInfo &FI)
Set the attributes on the LLVM function for the given decl and function info.
llvm::FunctionCallee CreateRuntimeFunction(llvm::FunctionType *Ty, StringRef Name, llvm::AttributeList ExtraAttrs=llvm::AttributeList(), bool Local=false, bool AssumeConvergent=false)
Create or return a runtime function declaration with the specified type and name.
CodeGenTypes & getTypes()
CGObjCRuntime & getObjCRuntime()
Return a reference to the configured Objective-C runtime.
const llvm::DataLayout & getDataLayout() const
llvm::FunctionCallee getAddrAndTypeOfCXXStructor(GlobalDecl GD, const CGFunctionInfo *FnInfo=nullptr, llvm::FunctionType *FnType=nullptr, bool DontDefer=false, ForDefinition_t IsForDefinition=NotForDefinition)
bool isInNoSanitizeList(SanitizerMask Kind, llvm::Function *Fn, SourceLocation Loc) const
llvm::Module & getModule() const
const LangOptions & getLangOpts() const
void addUsedGlobal(llvm::GlobalValue *GV)
Add a global to a list to be added to the llvm.used metadata.
const llvm::Triple & getTriple() const
llvm::LLVMContext & getLLVMContext()
void Error(SourceLocation loc, StringRef error)
Emit a general error that something can't be done.
CGCXXABI & getCXXABI() const
CGHLSLRuntime & getHLSLRuntime()
Return a reference to the configured HLSL runtime.
void AddGlobalDtor(llvm::Function *Dtor, int Priority=65535, bool IsDtorAttrFunc=false)
AddGlobalDtor - Add a function to the list that will be called when the module is unloaded.
bool supportsCOMDAT() const
const TargetCodeGenInfo & getTargetCodeGenInfo()
ASTContext & getContext() const
llvm::GlobalValue * GetGlobalValue(StringRef Ref)
void GenKernelArgMetadata(llvm::Function *FN, const FunctionDecl *FD=nullptr, CodeGenFunction *CGF=nullptr)
OpenCL v1.2 s5.6.4.6 allows the compiler to store kernel argument information in the program executab...
const CodeGenOptions & getCodeGenOpts() const
void AddGlobalCtor(llvm::Function *Ctor, int Priority=65535, unsigned LexOrder=~0U, llvm::Constant *AssociatedData=nullptr)
AddGlobalCtor - Add a function to the list that will be called before main() runs.
llvm::Function * getIntrinsic(unsigned IID, ArrayRef< llvm::Type * > Tys=std::nullopt)
llvm::Function * CreateGlobalInitOrCleanUpFunction(llvm::FunctionType *ty, const Twine &name, const CGFunctionInfo &FI, SourceLocation Loc=SourceLocation(), bool TLS=false, llvm::GlobalVariable::LinkageTypes Linkage=llvm::GlobalVariable::InternalLinkage)
const CGFunctionInfo & arrangeLLVMFunctionInfo(CanQualType returnType, FnInfoOpts opts, ArrayRef< CanQualType > argTypes, FunctionType::ExtInfo info, ArrayRef< FunctionProtoType::ExtParameterInfo > paramInfos, RequiredArgs args)
"Arrange" the LLVM information for a call or type with the given signature.
llvm::FunctionType * GetFunctionType(const CGFunctionInfo &Info)
GetFunctionType - Get the LLVM function type for.
const CGFunctionInfo & arrangeBuiltinFunctionDeclaration(QualType resultType, const FunctionArgList &args)
A builtin function is a freestanding function using the default C conventions.
unsigned getTargetAddressSpace(QualType T) const
const CGFunctionInfo & arrangeNullaryFunction()
A nullary function is a freestanding function of type 'void ()'.
A specialization of Address that requires the address to be an LLVM Constant.
llvm::Constant * getPointer() const
ConstantAddress withElementType(llvm::Type *ElemTy) const
static ConstantAddress invalid()
FunctionArgList - Type for representing both the decl and type of parameters to a function.
LValue - This represents an lvalue references.
bool isObjCStrong() const
RValue - This trivial value class is used to represent the result of an expression that is evaluated.
llvm::Value * getScalarVal() const
getScalarVal() - Return the Value* of this scalar value.
virtual LangAS getAddrSpaceOfCxaAtexitPtrParam() const
Get address space of pointer parameter for __cxa_atexit.
SourceLocation getLocation() const
SourceLocation getBeginLoc() const LLVM_READONLY
This represents one expression.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
A class which abstracts out some details necessary for making a call.
GlobalDecl - represents a global declaration.
virtual void mangleDynamicAtExitDestructor(const VarDecl *D, raw_ostream &)=0
virtual void mangleDynamicInitializer(const VarDecl *D, raw_ostream &)=0
Describes a module or submodule.
SmallVector< ExportDecl, 2 > Exports
The set of export declarations.
bool isNamedModuleInterfaceHasInit() const
bool isInterfaceOrPartition() const
llvm::SmallSetVector< Module *, 2 > Imports
The set of modules imported by this module, and on which this module depends.
llvm::iterator_range< submodule_iterator > submodules()
bool isHeaderLikeModule() const
Is this module have similar semantics as headers.
bool isExternallyVisible() const
A (possibly-)qualified type.
@ DK_objc_strong_lifetime
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
bool isConstantStorage(const ASTContext &Ctx, bool ExcludeCtor, bool ExcludeDtor)
LangAS getAddressSpace() const
Scope - A scope is a transient data structure that is used while parsing the program.
Encodes a location in the source.
The base class of the type hierarchy.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
bool isReferenceType() const
Represents a variable declaration or definition.
TLSKind getTLSKind() const
bool hasGlobalStorage() const
Returns true for all variables that do not have local storage.
const Expr * getInit() const
QualType::DestructionKind needsDestruction(const ASTContext &Ctx) const
Would the destruction of this variable have any effect, and if so, what kind?
bool hasLocalStorage() const
Returns true if a variable with function scope is a non-static local variable.
@ TLS_Dynamic
TLS with a dynamic initializer.
bool isLocalVarDecl() const
Returns true for local variable declarations other than parameters.
TemplateSpecializationKind getTemplateSpecializationKind() const
If this variable is an instantiation of a variable template or a static data member of a class templa...
bool noSystemDebugInfo(const Decl *D, const CodeGenModule &CGM)
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
The JSON file list parser is used to communicate input to InstallAPI.
bool isTemplateInstantiation(TemplateSpecializationKind Kind)
Determine whether this template specialization kind refers to an instantiation of an entity (as oppos...
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have.
@ Dtor_Complete
Complete object dtor.
LLVM_READONLY bool isPreprocessingNumberBody(unsigned char c)
Return true if this is the body character of a C preprocessing number, which is [a-zA-Z0-9_.
const FunctionProtoType * T
@ Other
Other implicit parameter.
llvm::PointerType * VoidPtrTy
llvm::IntegerType * Int64Ty
llvm::IntegerType * Int8Ty
i8, i16, i32, and i64
llvm::CallingConv::ID getRuntimeCC() const
llvm::IntegerType * IntTy
int
llvm::PointerType * Int8PtrTy