37#include "llvm/Analysis/ConstantFolding.h"
38#include "llvm/Analysis/ValueTracking.h"
39#include "llvm/IR/DataLayout.h"
40#include "llvm/IR/GlobalVariable.h"
41#include "llvm/IR/Instructions.h"
42#include "llvm/IR/Intrinsics.h"
43#include "llvm/IR/Type.h"
47using namespace CodeGen;
50 "Clang max alignment greater than what LLVM supports?");
54 case Decl::BuiltinTemplate:
55 case Decl::TranslationUnit:
56 case Decl::ExternCContext:
58 case Decl::UnresolvedUsingTypename:
59 case Decl::ClassTemplateSpecialization:
60 case Decl::ClassTemplatePartialSpecialization:
61 case Decl::VarTemplateSpecialization:
62 case Decl::VarTemplatePartialSpecialization:
63 case Decl::TemplateTypeParm:
64 case Decl::UnresolvedUsingValue:
65 case Decl::NonTypeTemplateParm:
66 case Decl::CXXDeductionGuide:
68 case Decl::CXXConstructor:
69 case Decl::CXXDestructor:
70 case Decl::CXXConversion:
72 case Decl::MSProperty:
73 case Decl::IndirectField:
75 case Decl::ObjCAtDefsField:
77 case Decl::ImplicitParam:
78 case Decl::ClassTemplate:
79 case Decl::VarTemplate:
80 case Decl::FunctionTemplate:
81 case Decl::TypeAliasTemplate:
82 case Decl::TemplateTemplateParm:
83 case Decl::ObjCMethod:
84 case Decl::ObjCCategory:
85 case Decl::ObjCProtocol:
86 case Decl::ObjCInterface:
87 case Decl::ObjCCategoryImpl:
88 case Decl::ObjCImplementation:
89 case Decl::ObjCProperty:
90 case Decl::ObjCCompatibleAlias:
91 case Decl::PragmaComment:
92 case Decl::PragmaDetectMismatch:
93 case Decl::AccessSpec:
94 case Decl::LinkageSpec:
96 case Decl::ObjCPropertyImpl:
97 case Decl::FileScopeAsm:
98 case Decl::TopLevelStmt:
100 case Decl::FriendTemplate:
102 case Decl::OutlinedFunction:
104 case Decl::UsingShadow:
105 case Decl::ConstructorUsingShadow:
106 case Decl::ObjCTypeParam:
108 case Decl::UnresolvedUsingIfExists:
109 case Decl::HLSLBuffer:
110 case Decl::HLSLRootSignature:
111 llvm_unreachable(
"Declaration should not be in declstmts!");
113 case Decl::CXXRecord:
116 DI->EmitAndRetainType(
117 getContext().getCanonicalTagType(cast<RecordDecl>(&
D)));
122 DI->EmitAndRetainType(
123 getContext().getCanonicalTagType(cast<EnumDecl>(&
D)));
126 case Decl::EnumConstant:
127 case Decl::StaticAssert:
131 case Decl::UnnamedGlobalConstant:
132 case Decl::TemplateParamObject:
133 case Decl::OMPThreadPrivate:
134 case Decl::OMPAllocate:
135 case Decl::OMPCapturedExpr:
136 case Decl::OMPRequires:
139 case Decl::ImplicitConceptSpecialization:
140 case Decl::LifetimeExtendedTemporary:
141 case Decl::RequiresExprBody:
145 case Decl::NamespaceAlias:
147 DI->EmitNamespaceAlias(cast<NamespaceAliasDecl>(
D));
151 DI->EmitUsingDecl(cast<UsingDecl>(
D));
153 case Decl::UsingEnum:
155 DI->EmitUsingEnumDecl(cast<UsingEnumDecl>(
D));
157 case Decl::UsingPack:
158 for (
auto *Using : cast<UsingPackDecl>(
D).expansions())
159 EmitDecl(*Using, EvaluateConditionDecl);
161 case Decl::UsingDirective:
163 DI->EmitUsingDirective(cast<UsingDirectiveDecl>(
D));
166 case Decl::Decomposition: {
167 const VarDecl &VD = cast<VarDecl>(
D);
169 "Should not see file-scope variables inside a function!");
171 if (EvaluateConditionDecl)
177 case Decl::OMPDeclareReduction:
180 case Decl::OMPDeclareMapper:
183 case Decl::OpenACCDeclare:
185 case Decl::OpenACCRoutine:
189 case Decl::TypeAlias: {
190 QualType Ty = cast<TypedefNameDecl>(
D).getUnderlyingType();
192 DI->EmitAndRetainType(Ty);
203 if (
D.hasExternalStorage())
212 if (
D.getType()->isSamplerT())
215 llvm::GlobalValue::LinkageTypes
Linkage =
228 assert(
D.hasLocalStorage());
237 assert(!
D.isExternallyVisible() &&
"name shouldn't matter");
238 std::string ContextName;
240 if (
auto *CD = dyn_cast<CapturedDecl>(DC))
241 DC = cast<DeclContext>(CD->getNonClosureContext());
242 if (
const auto *FD = dyn_cast<FunctionDecl>(DC))
244 else if (
const auto *BD = dyn_cast<BlockDecl>(DC))
246 else if (
const auto *OMD = dyn_cast<ObjCMethodDecl>(DC))
247 ContextName = OMD->getSelector().getAsString();
249 llvm_unreachable(
"Unknown context for static var decl");
251 ContextName +=
"." +
D.getNameAsString();
261 if (llvm::Constant *ExistingGV = StaticLocalDeclMap[&
D])
280 llvm::Constant *
Init =
nullptr;
283 Init = llvm::UndefValue::get(LTy);
287 llvm::GlobalVariable *GV =
new llvm::GlobalVariable(
289 nullptr, llvm::GlobalVariable::NotThreadLocal, TargetAS);
290 GV->setAlignment(
getContext().getDeclAlign(&
D).getAsAlign());
293 GV->setComdat(TheModule.getOrInsertComdat(GV->getName()));
303 llvm::Constant *
Addr = GV;
304 if (AS != ExpectedAS) {
308 getContext().getTargetAddressSpace(ExpectedAS)));
319 if (isa<BlockDecl>(DC) || isa<CapturedDecl>(DC)) {
327 if (
const auto *CD = dyn_cast<CXXConstructorDecl>(DC))
329 else if (
const auto *DD = dyn_cast<CXXDestructorDecl>(DC))
331 else if (
const auto *FD = dyn_cast<FunctionDecl>(DC))
336 assert(isa<ObjCMethodDecl>(DC) &&
"unexpected parent code decl");
351llvm::GlobalVariable *
353 llvm::GlobalVariable *GV) {
367 GV->setConstant(
false);
374 PGO->markStmtMaybeUsed(
D.getInit());
381 assert(VarSize == CstSize &&
"Emitted constant has unexpected size");
388 D.getType().isConstantStorage(
getContext(),
true, !NeedsDtor));
389 GV->replaceInitializer(
Init);
404 llvm::GlobalValue::LinkageTypes
Linkage) {
414 setAddrOfLocalVar(&
D,
Address(addr, elemTy, alignment));
419 if (
D.getType()->isVariablyModifiedType())
423 llvm::Type *expectedType = addr->getType();
425 llvm::GlobalVariable *var =
426 cast<llvm::GlobalVariable>(addr->stripPointerCasts());
435 if (
D.getInit() && !isCudaSharedVar) {
445 if (
auto *SA =
D.
getAttr<PragmaClangBSSSectionAttr>())
446 var->addAttribute(
"bss-section", SA->getName());
447 if (
auto *SA =
D.
getAttr<PragmaClangDataSectionAttr>())
448 var->addAttribute(
"data-section", SA->getName());
449 if (
auto *SA =
D.
getAttr<PragmaClangRodataSectionAttr>())
450 var->addAttribute(
"rodata-section", SA->getName());
451 if (
auto *SA =
D.
getAttr<PragmaClangRelroSectionAttr>())
452 var->addAttribute(
"relro-section", SA->getName());
454 if (
const SectionAttr *SA =
D.
getAttr<SectionAttr>())
455 var->setSection(SA->getName());
470 llvm::Constant *castedAddr =
471 llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast(var, expectedType);
472 LocalDeclMap.find(&
D)->second =
Address(castedAddr, elemTy, alignment);
489 bool useEHCleanupForArray)
490 : addr(addr),
type(
type), destroyer(destroyer),
491 useEHCleanupForArray(useEHCleanupForArray) {}
496 bool useEHCleanupForArray;
500 bool useEHCleanupForArray =
501 flags.isForNormalCleanup() && this->useEHCleanupForArray;
507 template <
class Derived>
510 : NRVOFlag(NRVOFlag),
Loc(addr), Ty(
type) {}
512 llvm::Value *NRVOFlag;
518 bool NRVO = flags.isForNormalCleanup() && NRVOFlag;
520 llvm::BasicBlock *SkipDtorBB =
nullptr;
525 llvm::Value *DidNRVO =
527 CGF.
Builder.CreateCondBr(DidNRVO, SkipDtorBB, RunDtorBB);
531 static_cast<Derived *
>(
this)->emitDestructorCall(CGF);
536 virtual ~DestroyNRVOVariable() =
default;
539 struct DestroyNRVOVariableCXX final
540 : DestroyNRVOVariable<DestroyNRVOVariableCXX> {
543 : DestroyNRVOVariable<DestroyNRVOVariableCXX>(addr,
type, NRVOFlag),
555 struct DestroyNRVOVariableC final
556 : DestroyNRVOVariable<DestroyNRVOVariableC> {
558 : DestroyNRVOVariable<DestroyNRVOVariableC>(addr, Ty, NRVOFlag) {}
567 CallStackRestore(
Address Stack) : Stack(Stack) {}
568 bool isRedundantBeforeReturn()
override {
return true; }
576 std::pair<llvm::Value *, llvm::Value *> AddrSizePair;
577 KmpcAllocFree(
const std::pair<llvm::Value *, llvm::Value *> &AddrSizePair)
578 : AddrSizePair(AddrSizePair) {}
587 ExtendGCLifetime(
const VarDecl *var) : Var(*
var) {}
601 llvm::Constant *CleanupFn;
604 const CleanupAttr *Attribute;
606 CallCleanupFunction(llvm::Constant *CleanupFn,
const CGFunctionInfo *Info,
608 : CleanupFn(CleanupFn), FnInfo(*Info), Var(*Var), Attribute(
Attr) {}
634 Attribute->getLoc());
646 llvm_unreachable(
"present but none");
654 (var.hasAttr<ObjCPreciseLifetimeAttr>()
659 CGF.
pushDestroy(cleanupKind, addr, var.getType(), destroyer,
678 if (
const Expr *e = dyn_cast<Expr>(
s)) {
681 s = e = e->IgnoreParenCasts();
683 if (
const DeclRefExpr *ref = dyn_cast<DeclRefExpr>(e))
684 return (ref->getDecl() == &var);
685 if (
const BlockExpr *be = dyn_cast<BlockExpr>(e)) {
686 const BlockDecl *block = be->getBlockDecl();
687 for (
const auto &I : block->
captures()) {
688 if (I.getVariable() == &var)
694 for (
const Stmt *SubStmt :
s->children())
703 if (!
decl)
return false;
704 if (!isa<VarDecl>(
decl))
return false;
711 bool needsCast =
false;
718 case CK_BlockPointerToObjCPointerCast:
724 case CK_LValueToRValue: {
766 if (!
SanOpts.
has(SanitizerKind::NullabilityAssign))
775 auto CheckOrdinal = SanitizerKind::SO_NullabilityAssign;
776 auto CheckHandler = SanitizerHandler::TypeMismatch;
779 llvm::Constant *StaticData[] = {
781 llvm::ConstantInt::get(
Int8Ty, 0),
787 LValue lvalue,
bool capturedByInit) {
805 init = DIE->getExpr();
809 if (
auto *EWC = dyn_cast<ExprWithCleanups>(init)) {
818 bool accessedByInit =
false;
821 if (accessedByInit) {
824 if (capturedByInit) {
845 llvm::Value *value =
nullptr;
849 llvm_unreachable(
"present but none");
852 if (!
D || !isa<VarDecl>(
D) || !cast<VarDecl>(
D)->isARCPseudoStrong()) {
911 unsigned &NumStores) {
913 if (isa<llvm::ConstantAggregateZero>(
Init) ||
914 isa<llvm::ConstantPointerNull>(
Init) ||
915 isa<llvm::UndefValue>(
Init))
917 if (isa<llvm::ConstantInt>(
Init) || isa<llvm::ConstantFP>(
Init) ||
918 isa<llvm::ConstantVector>(
Init) || isa<llvm::BlockAddress>(
Init) ||
919 isa<llvm::ConstantExpr>(
Init))
920 return Init->isNullValue() || NumStores--;
923 if (isa<llvm::ConstantArray>(
Init) || isa<llvm::ConstantStruct>(
Init)) {
924 for (
unsigned i = 0, e =
Init->getNumOperands(); i != e; ++i) {
925 llvm::Constant *Elt = cast<llvm::Constant>(
Init->getOperand(i));
932 if (llvm::ConstantDataSequential *CDS =
933 dyn_cast<llvm::ConstantDataSequential>(
Init)) {
934 for (
unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) {
935 llvm::Constant *Elt = CDS->getElementAsConstant(i);
948void CodeGenFunction::emitStoresForInitAfterBZero(llvm::Constant *
Init,
951 assert(!
Init->isNullValue() && !isa<llvm::UndefValue>(
Init) &&
952 "called emitStoresForInitAfterBZero for zero or undef value.");
954 if (isa<llvm::ConstantInt>(
Init) || isa<llvm::ConstantFP>(
Init) ||
955 isa<llvm::ConstantVector>(
Init) || isa<llvm::BlockAddress>(
Init) ||
956 isa<llvm::ConstantExpr>(
Init)) {
960 I->addAnnotationMetadata(
"auto-init");
964 if (llvm::ConstantDataSequential *CDS =
965 dyn_cast<llvm::ConstantDataSequential>(
Init)) {
966 for (
unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) {
967 llvm::Constant *Elt = CDS->getElementAsConstant(i);
970 if (!Elt->isNullValue() && !isa<llvm::UndefValue>(Elt))
971 emitStoresForInitAfterBZero(
978 assert((isa<llvm::ConstantStruct>(
Init) || isa<llvm::ConstantArray>(
Init)) &&
979 "Unknown value type!");
981 for (
unsigned i = 0, e =
Init->getNumOperands(); i != e; ++i) {
982 llvm::Constant *Elt = cast<llvm::Constant>(
Init->getOperand(i));
985 if (!Elt->isNullValue() && !isa<llvm::UndefValue>(Elt))
986 emitStoresForInitAfterBZero(Elt,
988 isVolatile, IsAutoInit);
996 uint64_t GlobalSize) {
998 if (isa<llvm::ConstantAggregateZero>(
Init))
return true;
1004 unsigned StoreBudget = 6;
1005 uint64_t SizeLimit = 32;
1007 return GlobalSize > SizeLimit &&
1017 uint64_t GlobalSize,
1018 const llvm::DataLayout &DL) {
1019 uint64_t SizeLimit = 32;
1020 if (GlobalSize <= SizeLimit)
1022 return llvm::isBytewiseValue(
Init, DL);
1029 uint64_t GlobalByteSize) {
1031 uint64_t ByteSizeLimit = 64;
1034 if (GlobalByteSize <= ByteSizeLimit)
1044 if (isPattern == IsPattern::Yes)
1047 return llvm::Constant::getNullValue(Ty);
1051 llvm::Constant *constant);
1056 llvm::StructType *STy,
1057 llvm::Constant *constant) {
1059 const llvm::StructLayout *Layout = DL.getStructLayout(STy);
1060 llvm::Type *Int8Ty = llvm::IntegerType::getInt8Ty(CGM.
getLLVMContext());
1061 unsigned SizeSoFar = 0;
1063 bool NestedIntact =
true;
1064 for (
unsigned i = 0, e = STy->getNumElements(); i != e; i++) {
1065 unsigned CurOff = Layout->getElementOffset(i);
1066 if (SizeSoFar < CurOff) {
1067 assert(!STy->isPacked());
1068 auto *PadTy = llvm::ArrayType::get(Int8Ty, CurOff - SizeSoFar);
1071 llvm::Constant *CurOp;
1072 if (constant->isZeroValue())
1073 CurOp = llvm::Constant::getNullValue(STy->getElementType(i));
1075 CurOp = cast<llvm::Constant>(constant->getAggregateElement(i));
1078 NestedIntact =
false;
1079 Values.push_back(NewOp);
1080 SizeSoFar = CurOff + DL.getTypeAllocSize(CurOp->getType());
1082 unsigned TotalSize = Layout->getSizeInBytes();
1083 if (SizeSoFar < TotalSize) {
1084 auto *PadTy = llvm::ArrayType::get(Int8Ty, TotalSize - SizeSoFar);
1087 if (NestedIntact && Values.size() == STy->getNumElements())
1089 return llvm::ConstantStruct::getAnon(Values, STy->isPacked());
1095 llvm::Constant *constant) {
1096 llvm::Type *OrigTy = constant->getType();
1097 if (
const auto STy = dyn_cast<llvm::StructType>(OrigTy))
1099 if (
auto *ArrayTy = dyn_cast<llvm::ArrayType>(OrigTy)) {
1101 uint64_t Size = ArrayTy->getNumElements();
1104 llvm::Type *ElemTy = ArrayTy->getElementType();
1105 bool ZeroInitializer = constant->isNullValue();
1106 llvm::Constant *OpValue, *PaddedOp;
1107 if (ZeroInitializer) {
1108 OpValue = llvm::Constant::getNullValue(ElemTy);
1111 for (
unsigned Op = 0; Op != Size; ++Op) {
1112 if (!ZeroInitializer) {
1113 OpValue = constant->getAggregateElement(Op);
1116 Values.push_back(PaddedOp);
1118 auto *NewElemTy = Values[0]->getType();
1119 if (NewElemTy == ElemTy)
1121 auto *NewArrayTy = llvm::ArrayType::get(NewElemTy, Size);
1122 return llvm::ConstantArray::get(NewArrayTy, Values);
1131 llvm::Constant *Constant,
1133 auto FunctionName = [&](
const DeclContext *DC) -> std::string {
1134 if (
const auto *FD = dyn_cast<FunctionDecl>(DC)) {
1135 if (
const auto *CC = dyn_cast<CXXConstructorDecl>(FD))
1136 return CC->getNameAsString();
1137 if (
const auto *CD = dyn_cast<CXXDestructorDecl>(FD))
1138 return CD->getNameAsString();
1140 }
else if (
const auto *OM = dyn_cast<ObjCMethodDecl>(DC)) {
1141 return OM->getNameAsString();
1142 }
else if (isa<BlockDecl>(DC)) {
1144 }
else if (isa<CapturedDecl>(DC)) {
1145 return "<captured>";
1147 llvm_unreachable(
"expected a function or method");
1153 llvm::GlobalVariable *&CacheEntry = InitializerConstants[&
D];
1154 if (!CacheEntry || CacheEntry->getInitializer() != Constant) {
1155 auto *Ty = Constant->getType();
1156 bool isConstant =
true;
1157 llvm::GlobalVariable *InsertBefore =
nullptr;
1161 if (
D.hasGlobalStorage())
1164 Name = (
"__const." + FunctionName(DC) +
"." +
D.getName()).str();
1166 llvm_unreachable(
"local variable has no parent function or method");
1167 llvm::GlobalVariable *GV =
new llvm::GlobalVariable(
1168 getModule(), Ty, isConstant, llvm::GlobalValue::PrivateLinkage,
1169 Constant, Name, InsertBefore, llvm::GlobalValue::NotThreadLocal, AS);
1171 GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
1173 }
else if (CacheEntry->getAlignment() < uint64_t(Align.
getQuantity())) {
1174 CacheEntry->setAlignment(Align.
getAsAlign());
1177 return Address(CacheEntry, CacheEntry->getValueType(), Align);
1183 llvm::Constant *Constant,
1191 llvm::Constant *constant,
1193 auto *Ty = constant->getType();
1198 bool canDoSingleStore = Ty->isIntOrIntVectorTy() ||
1199 Ty->isPtrOrPtrVectorTy() || Ty->isFPOrFPVectorTy();
1200 if (canDoSingleStore) {
1204 I->addAnnotationMetadata(
"auto-init");
1208 auto *SizeVal = llvm::ConstantInt::get(
CGM.
IntPtrTy, ConstantSize);
1214 SizeVal, isVolatile);
1218 I->addAnnotationMetadata(
"auto-init");
1220 bool valueAlreadyCorrect =
1221 constant->isNullValue() || isa<llvm::UndefValue>(constant);
1222 if (!valueAlreadyCorrect) {
1223 Loc =
Loc.withElementType(Ty);
1224 emitStoresForInitAfterBZero(constant,
Loc, isVolatile, IsAutoInit);
1230 llvm::Value *Pattern =
1234 if (!isa<llvm::UndefValue>(Pattern)) {
1235 const llvm::APInt &AP = cast<llvm::ConstantInt>(Pattern)->getValue();
1236 assert(AP.getBitWidth() <= 8);
1237 Value = AP.getLimitedValue();
1243 I->addAnnotationMetadata(
"auto-init");
1249 bool IsTrivialAutoVarInitPattern =
1253 if (
auto *STy = dyn_cast<llvm::StructType>(Ty)) {
1254 if (STy ==
Loc.getElementType() ||
1255 (STy !=
Loc.getElementType() && IsTrivialAutoVarInitPattern)) {
1256 const llvm::StructLayout *Layout =
1258 for (
unsigned i = 0; i != constant->getNumOperands(); i++) {
1263 emitStoresForConstant(
D, EltPtr, isVolatile,
1264 constant->getAggregateElement(i), IsAutoInit);
1268 }
else if (
auto *ATy = dyn_cast<llvm::ArrayType>(Ty)) {
1269 if (ATy ==
Loc.getElementType() ||
1270 (ATy !=
Loc.getElementType() && IsTrivialAutoVarInitPattern)) {
1271 for (
unsigned i = 0; i != ATy->getNumElements(); i++) {
1273 Loc.withElementType(ATy->getElementType()), i);
1274 emitStoresForConstant(
D, EltPtr, isVolatile,
1275 constant->getAggregateElement(i), IsAutoInit);
1287 SizeVal, isVolatile);
1291 I->addAnnotationMetadata(
"auto-init");
1296 llvm::Type *ElTy =
Loc.getElementType();
1297 llvm::Constant *constant =
1299 emitStoresForConstant(
D,
Loc, isVolatile, constant,
1305 llvm::Type *ElTy =
Loc.getElementType();
1308 assert(!isa<llvm::UndefValue>(constant));
1309 emitStoresForConstant(
D,
Loc, isVolatile, constant,
1314 auto *Ty = constant->getType();
1315 if (isa<llvm::UndefValue>(constant))
1317 if (Ty->isStructTy() || Ty->isArrayTy() || Ty->isVectorTy())
1318 for (llvm::Use &Op : constant->operands())
1325 llvm::Constant *constant) {
1326 auto *Ty = constant->getType();
1327 if (isa<llvm::UndefValue>(constant))
1329 if (!(Ty->isStructTy() || Ty->isArrayTy() || Ty->isVectorTy()))
1334 for (
unsigned Op = 0, NumOp = constant->getNumOperands(); Op != NumOp; ++Op) {
1335 auto *OpValue = cast<llvm::Constant>(constant->getOperand(Op));
1338 if (Ty->isStructTy())
1339 return llvm::ConstantStruct::get(cast<llvm::StructType>(Ty), Values);
1340 if (Ty->isArrayTy())
1341 return llvm::ConstantArray::get(cast<llvm::ArrayType>(Ty), Values);
1342 assert(Ty->isVectorTy());
1343 return llvm::ConstantVector::get(Values);
1358 if (!ShouldEmitLifetimeMarkers)
1361 assert(
Addr->getType()->getPointerAddressSpace() ==
1363 "Pointer should be in alloca address space");
1365 C->setDoesNotThrow();
1370 if (!ShouldEmitLifetimeMarkers)
1373 assert(
Addr->getType()->getPointerAddressSpace() ==
1375 "Pointer should be in alloca address space");
1377 C->setDoesNotThrow();
1384 C->setDoesNotThrow();
1385 C->setTailCallKind(llvm::CallInst::TCK_NoTail);
1397 while (
getContext().getAsVariableArrayType(Type1D)) {
1399 if (
auto *
C = dyn_cast<llvm::ConstantInt>(VlaSize.NumElts))
1403 Twine Name = Twine(
"__vla_expr") + Twine(VLAExprCounter++);
1405 StringRef NameRef = Name.toStringRef(Buffer);
1407 VLAExprNames.push_back(&Ident);
1411 Dimensions.emplace_back(SizeExprAddr.getPointer(),
1414 Type1D = VlaSize.Type;
1423 unsigned NameIdx = 0;
1424 for (
auto &VlaSize : Dimensions) {
1426 if (
auto *
C = dyn_cast<llvm::ConstantInt>(VlaSize.NumElts))
1427 MD = llvm::ConstantAsMetadata::get(
C);
1432 SizeTy->getScalarSizeInBits(),
false);
1437 ArtificialDecl->setImplicit();
1442 assert(MD &&
"No Size expression debug node created");
1450 return 4 *
C.getTypeSize(
C.UnsignedIntTy);
1475 if (FuncDecl->
hasAttr<NoDebugAttr>() || FuncDecl->
hasAttr<OptimizeNoneAttr>())
1491 bool isEscapingByRef =
D.isEscapingByref();
1492 emission.IsEscapingByRef = isEscapingByRef;
1514 bool NRVO =
getLangOpts().ElideConstructors &&
D.isNRVOVariable();
1517 address = OpenMPLocalAddr;
1518 AllocaAddr = OpenMPLocalAddr;
1531 getContext().getBaseElementType(Ty)->isObjCObjectPointerType()) &&
1532 D.getInit()->isConstantInitializer(
getContext(),
false)))) {
1550 assert(emission.wasEmittedAsGlobal());
1555 emission.IsConstantAggregate =
true;
1569 address = MaybeCastStackAddressSpace(AllocaAddr, Ty.
getAddressSpace());
1572 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD);
1573 (CXXRD && !CXXRD->hasTrivialDestructor()) ||
1574 RD->isNonTrivialToPrimitiveDestroy()) {
1591 llvm::Type *allocaTy;
1592 if (isEscapingByRef) {
1594 allocaTy = byrefInfo.Type;
1595 allocaAlignment = byrefInfo.ByrefAlignment;
1598 allocaAlignment = alignment;
1605 allocaAlignment,
D.getName(),
1606 nullptr, &AllocaAddr);
1611 bool IsMSCatchParam =
1632 emission.UseLifetimeMarkers =
1647 bool VarAllocated =
false;
1650 if (RT.isDelayedVariableLengthDecl(*
this, &
D)) {
1652 std::pair<llvm::Value *, llvm::Value *> AddrSizePair =
1659 address =
Base.getAddress();
1667 VarAllocated =
true;
1671 if (!VarAllocated) {
1672 if (!DidCallStackSave) {
1677 llvm::Value *
V =
Builder.CreateStackSave();
1681 DidCallStackSave =
true;
1702 setAddrOfLocalVar(&
D, address);
1703 emission.Addr = address;
1704 emission.AllocaAddr = AllocaAddr;
1713 if (UsePointerValue) {
1749 if (
const Expr *
E = dyn_cast<Expr>(S))
1751 for (
const Stmt *SubStmt : S->children())
1764 if (
const BlockExpr *BE = dyn_cast<BlockExpr>(
E)) {
1766 for (
const auto &I :
Block->captures()) {
1767 if (I.getVariable() == &Var)
1775 if (
const StmtExpr *SE = dyn_cast<StmtExpr>(
E)) {
1777 for (
const auto *BI : CS->
body())
1778 if (
const auto *BIE = dyn_cast<Expr>(BI)) {
1782 else if (
const auto *DS = dyn_cast<DeclStmt>(BI)) {
1784 for (
const auto *I : DS->decls()) {
1785 if (
const auto *VD = dyn_cast<VarDecl>((I))) {
1816 !Construct->requiresZeroInitialization())
1822void CodeGenFunction::emitZeroOrPatternForAutoVarInit(
QualType type,
1826 auto trivialAutoVarInitMaxSize =
1829 bool isVolatile =
type.isVolatileQualified();
1830 if (!Size.isZero()) {
1837 switch (trivialAutoVarInit) {
1839 llvm_unreachable(
"Uninitialized handled by caller");
1843 if (trivialAutoVarInitMaxSize > 0 &&
1844 allocSize > trivialAutoVarInitMaxSize)
1846 emitStoresForZeroInit(
D,
Loc, isVolatile);
1851 if (trivialAutoVarInitMaxSize > 0 &&
1852 allocSize > trivialAutoVarInitMaxSize)
1854 emitStoresForPatternInit(
D,
Loc, isVolatile);
1869 auto SizeVal = VlaSize.NumElts;
1871 switch (trivialAutoVarInit) {
1873 llvm_unreachable(
"Uninitialized handled by caller");
1878 if (!EltSize.
isOne())
1881 SizeVal, isVolatile);
1882 I->addAnnotationMetadata(
"auto-init");
1889 llvm::Type *ElTy =
Loc.getElementType();
1896 llvm::Value *IsZeroSizedVLA =
Builder.CreateICmpEQ(
1897 SizeVal, llvm::ConstantInt::get(SizeVal->getType(), 0),
1899 Builder.CreateCondBr(IsZeroSizedVLA, ContBB, SetupBB);
1901 if (!EltSize.
isOne())
1903 llvm::Value *BaseSizeInChars =
1907 Begin.emitRawPointer(*
this),
1908 SizeVal,
"vla.end");
1909 llvm::BasicBlock *OriginBB =
Builder.GetInsertBlock();
1911 llvm::PHINode *Cur =
Builder.CreatePHI(
Begin.getType(), 2,
"vla.cur");
1912 Cur->addIncoming(
Begin.emitRawPointer(*
this), OriginBB);
1913 CharUnits CurAlign =
Loc.getAlignment().alignmentOfArrayElement(EltSize);
1918 BaseSizeInChars, isVolatile);
1919 I->addAnnotationMetadata(
"auto-init");
1922 llvm::Value *Done =
Builder.CreateICmpEQ(Next, End,
"vla-init.isdone");
1923 Builder.CreateCondBr(Done, ContBB, LoopBB);
1924 Cur->addIncoming(Next, LoopBB);
1931 assert(emission.Variable &&
"emission was not valid!");
1934 if (emission.wasEmittedAsGlobal())
return;
1936 const VarDecl &
D = *emission.Variable;
1948 PGO->markStmtMaybeUsed(
Init);
1955 if (emission.IsEscapingByRef)
1962 type.isNonTrivialToPrimitiveDefaultInitialize() ==
1965 if (emission.IsEscapingByRef)
1974 bool capturedByInit =
1977 bool locIsByrefHeader = !capturedByInit;
1981 auto hasNoTrivialAutoVarInitAttr = [&](
const Decl *
D) {
1982 return D &&
D->
hasAttr<NoTrivialAutoVarInitAttr>();
1986 ((
D.isConstexpr() ||
D.
getAttr<UninitializedAttr>() ||
1987 hasNoTrivialAutoVarInitAttr(
type->getAsTagDecl()) ||
1992 auto initializeWhatIsTechnicallyUninitialized = [&](
Address Loc) {
1993 if (trivialAutoVarInit ==
1998 if (emission.IsEscapingByRef && !locIsByrefHeader)
2001 return emitZeroOrPatternForAutoVarInit(
type,
D,
Loc);
2005 return initializeWhatIsTechnicallyUninitialized(
Loc);
2007 llvm::Constant *constant =
nullptr;
2008 if (emission.IsConstantAggregate ||
2009 D.mightBeUsableInConstantExpressions(
getContext())) {
2010 assert(!capturedByInit &&
"constant init contains a capturing block?");
2012 if (constant && !constant->isZeroValue() &&
2013 (trivialAutoVarInit !=
2029 if (constant &&
type->isBitIntType() &&
2034 llvm::Type *LoadType =
2036 constant = llvm::ConstantFoldLoadFromConst(
2042 if (trivialAutoVarInit !=
2053 initializeWhatIsTechnicallyUninitialized(
Loc);
2061 PGO->markStmtMaybeUsed(
Init);
2063 if (!emission.IsConstantAggregate) {
2071 type.isVolatileQualified(), constant,
2076 if (
auto *DD = dyn_cast_if_present<DecompositionDecl>(VD)) {
2077 for (
auto *B : DD->flat_bindings())
2078 if (
auto *HD = B->getHoldingVar())
2094 LValue lvalue,
bool capturedByInit) {
2097 if (
type->isReferenceType()) {
2116 if (
type->isAtomicType()) {
2120 if (isa<VarDecl>(
D))
2122 else if (
auto *FD = dyn_cast<FieldDecl>(
D))
2132 llvm_unreachable(
"bad evaluation kind");
2145 const VarDecl *var = emission.Variable;
2153 llvm_unreachable(
"no cleanup for trivially-destructible variable");
2158 if (emission.NRVOFlag) {
2159 assert(!
type->isArrayType());
2161 EHStack.pushCleanup<DestroyNRVOVariableCXX>(cleanupKind, addr,
type, dtor,
2169 if (var->isARCPseudoStrong())
return;
2175 if (!var->hasAttr<ObjCPreciseLifetimeAttr>())
2184 if (emission.NRVOFlag) {
2185 assert(!
type->isArrayType());
2186 EHStack.pushCleanup<DestroyNRVOVariableC>(cleanupKind, addr,
2187 emission.NRVOFlag,
type);
2198 bool useEHCleanup = (cleanupKind &
EHCleanup);
2199 EHStack.pushCleanup<DestroyObject>(cleanupKind, addr,
type, destroyer,
2204 assert(emission.Variable &&
"emission was not valid!");
2207 if (emission.wasEmittedAsGlobal())
return;
2213 const VarDecl &
D = *emission.Variable;
2221 D.
hasAttr<ObjCPreciseLifetimeAttr>()) {
2226 if (
const CleanupAttr *CA =
D.
getAttr<CleanupAttr>()) {
2230 assert(F &&
"Could not find function!");
2240 if (emission.IsEscapingByRef &&
2264 llvm_unreachable(
"Unknown DestructionKind");
2271 assert(dtorKind &&
"cannot push destructor for trivial type");
2281 assert(dtorKind &&
"cannot push destructor for trivial type");
2297 bool useEHCleanupForArray) {
2298 pushFullExprCleanup<DestroyObject>(cleanupKind, addr,
type, destroyer,
2299 useEHCleanupForArray);
2306 assert(dtorKind &&
"cannot push destructor for trivial type");
2315 bool useEHCleanupForArray) {
2316 llvm::Instruction *DominatingIP =
2318 pushDestroy(cleanupKind, addr,
type, destroyer, useEHCleanupForArray);
2324 EHStack.pushCleanup<CallStackRestore>(Kind, SPMem);
2328 CleanupKind Kind, std::pair<llvm::Value *, llvm::Value *> AddrSizePair) {
2329 EHStack.pushCleanup<KmpcAllocFree>(Kind, AddrSizePair);
2334 Destroyer *destroyer,
2335 bool useEHCleanupForArray) {
2345 useEHCleanupForArray);
2349 return pushCleanupAfterFullExprWithActiveFlag<DestroyObject>(
2351 useEHCleanupForArray);
2356 using ConditionalCleanupType =
2366 pushCleanupAndDeferDeactivation<ConditionalCleanupType>(
2367 cleanupKind, SavedAddr,
type, destroyer, useEHCleanupForArray);
2371 cleanup.AddAuxAllocas(std::move(DeactivationAllocas).Take());
2379 pushCleanupAfterFullExprWithActiveFlag<ConditionalCleanupType>(
2380 cleanupKind, ActiveFlagForLifetimeExt, SavedAddr,
type, destroyer,
2381 useEHCleanupForArray);
2396 Destroyer *destroyer,
2397 bool useEHCleanupForArray) {
2400 return destroyer(*
this, addr,
type);
2409 bool checkZeroLength =
true;
2412 if (llvm::ConstantInt *constLength = dyn_cast<llvm::ConstantInt>(
length)) {
2414 if (constLength->isZero())
return;
2415 checkZeroLength =
false;
2422 checkZeroLength, useEHCleanupForArray);
2439 Destroyer *destroyer,
2440 bool checkZeroLength,
2441 bool useEHCleanup) {
2449 if (checkZeroLength) {
2450 llvm::Value *isEmpty =
Builder.CreateICmpEQ(begin, end,
2451 "arraydestroy.isempty");
2452 Builder.CreateCondBr(isEmpty, doneBB, bodyBB);
2456 llvm::BasicBlock *entryBB =
Builder.GetInsertBlock();
2458 llvm::PHINode *elementPast =
2459 Builder.CreatePHI(begin->getType(), 2,
"arraydestroy.elementPast");
2460 elementPast->addIncoming(end, entryBB);
2463 llvm::Value *negativeOne = llvm::ConstantInt::get(
SizeTy, -1,
true);
2466 llvmElementType, elementPast, negativeOne,
"arraydestroy.element");
2473 destroyer(*
this,
Address(element, llvmElementType, elementAlign),
2480 llvm::Value *done =
Builder.CreateICmpEQ(element, begin,
"arraydestroy.done");
2481 Builder.CreateCondBr(done, doneBB, bodyBB);
2482 elementPast->addIncoming(element,
Builder.GetInsertBlock());
2491 llvm::Value *begin, llvm::Value *end,
2497 unsigned arrayDepth = 0;
2506 llvm::Value *zero = llvm::ConstantInt::get(CGF.
SizeTy, 0);
2510 elemTy, begin, gepIndices,
"pad.arraybegin");
2512 elemTy, end, gepIndices,
"pad.arrayend");
2527 llvm::Value *ArrayBegin;
2528 llvm::Value *ArrayEnd;
2533 RegularPartialArrayDestroy(llvm::Value *arrayBegin, llvm::Value *arrayEnd,
2536 : ArrayBegin(arrayBegin), ArrayEnd(arrayEnd),
2537 ElementType(elementType), Destroyer(destroyer),
2538 ElementAlign(elementAlign) {}
2542 ElementType, ElementAlign, Destroyer);
2550 llvm::Value *ArrayBegin;
2556 IrregularPartialArrayDestroy(llvm::Value *arrayBegin,
2561 : ArrayBegin(arrayBegin), ArrayEndPointer(arrayEndPointer),
2562 ElementType(elementType), Destroyer(destroyer),
2563 ElementAlign(elementAlign) {}
2568 ElementType, ElementAlign, Destroyer);
2583 Destroyer *destroyer) {
2584 pushFullExprCleanup<IrregularPartialArrayDestroy>(
2586 elementAlign, destroyer);
2596 llvm::Value *arrayEnd,
2599 Destroyer *destroyer) {
2600 pushFullExprCleanup<RegularPartialArrayDestroy>(
EHCleanup,
2601 arrayBegin, arrayEnd,
2602 elementType, elementAlign,
2608 if (LifetimeStartFn)
2609 return LifetimeStartFn;
2610 LifetimeStartFn = llvm::Intrinsic::getOrInsertDeclaration(
2612 return LifetimeStartFn;
2618 return LifetimeEndFn;
2619 LifetimeEndFn = llvm::Intrinsic::getOrInsertDeclaration(
2621 return LifetimeEndFn;
2628 FakeUseFn = llvm::Intrinsic::getOrInsertDeclaration(
2629 &
getModule(), llvm::Intrinsic::fake_use);
2639 ConsumeARCParameter(llvm::Value *param,
2641 : Param(param), Precise(precise) {}
2656 bool NoDebugInfo =
false;
2658 assert((isa<ParmVarDecl>(
D) || isa<ImplicitParamDecl>(
D)) &&
2659 "Invalid argument to EmitParmDecl");
2669 if (
auto IPD = dyn_cast<ImplicitParamDecl>(&
D)) {
2687 bool DoStore =
false;
2689 bool UseIndirectDebugAddress =
false;
2706 if (UseIndirectDebugAddress) {
2709 D.getName() +
".indirect_addr");
2716 if (SrcLangAS != DestLangAS) {
2717 assert(
getContext().getTargetAddressSpace(SrcLangAS) ==
2735 "unexpected destructor type");
2737 CalleeDestructedParamCleanups[cast<ParmVarDecl>(&
D)] =
2748 DeclPtr = OpenMPLocalAddr;
2749 AllocaPtr = DeclPtr;
2753 D.getName() +
".addr", &AllocaPtr);
2758 llvm::Value *ArgVal = (DoStore ? Arg.
getDirectValue() :
nullptr);
2768 bool isConsumed =
D.
hasAttr<NSConsumedAttr>();
2771 if (
D.isARCPseudoStrong()) {
2773 "pseudo-strong variable isn't strong?");
2774 assert(qs.
hasConst() &&
"pseudo-strong variable should be const!");
2823 setAddrOfLocalVar(&
D, DeclPtr);
2832 &
D == CXXABIThisDecl)) {
2841 llvm::DILocalVariable *DILocalVar = DI->EmitDeclareOfArgVariable(
2843 if (
const auto *Var = dyn_cast_or_null<ParmVarDecl>(&
D))
2844 DI->getParamDbgMappings().insert({Var, DILocalVar});
2854 if (requiresReturnValueNullabilityCheck()) {
2858 RetValNullabilityPrecondition =
2859 Builder.CreateAnd(RetValNullabilityPrecondition,
2867 if (!LangOpts.OpenMP || (!LangOpts.EmitAllDecls && !
D->
isUsed()))
2874 if (!LangOpts.OpenMP || LangOpts.OpenMPSimd ||
2875 (!LangOpts.EmitAllDecls && !
D->
isUsed()))
2895 for (
const Expr *
E :
D->varlist()) {
2896 const auto *DE = cast<DeclRefExpr>(
E);
2897 const auto *VD = cast<VarDecl>(DE->getDecl());
2900 if (!VD->hasGlobalStorage())
2919 if (Entry->getType()->getAddressSpace() == TargetAS)
2922 llvm::PointerType *PTy = llvm::PointerType::get(
getLLVMContext(), TargetAS);
2927 llvm::GlobalVariable *DummyGV =
new llvm::GlobalVariable(
2928 getModule(), Entry->getValueType(),
false,
2929 llvm::GlobalValue::CommonLinkage,
nullptr,
"dummy",
nullptr,
2930 llvm::GlobalVariable::NotThreadLocal, Entry->getAddressSpace());
2931 Entry->replaceAllUsesWith(DummyGV);
2933 Entry->mutateType(PTy);
2934 llvm::Constant *NewPtrForOldDecl =
2935 llvm::ConstantExpr::getAddrSpaceCast(Entry, DummyGV->getType());
2939 DummyGV->replaceAllUsesWith(NewPtrForOldDecl);
2940 DummyGV->eraseFromParent();
2944std::optional<CharUnits>
2946 if (
const auto *AA = VD->
getAttr<OMPAllocateDeclAttr>()) {
2947 if (
Expr *Alignment = AA->getAlignment()) {
2948 unsigned UserAlign =
2949 Alignment->EvaluateKnownConstInt(
getContext()).getExtValue();
2957 std::max<unsigned>(UserAlign, NaturalAlign.
getQuantity()));
2960 return std::nullopt;
Defines the clang::ASTContext interface.
static bool isCapturedBy(const VarDecl &, const Expr *)
Determines whether the given __block variable is potentially captured by the given expression.
static void emitPartialArrayDestroy(CodeGenFunction &CGF, llvm::Value *begin, llvm::Value *end, QualType type, CharUnits elementAlign, CodeGenFunction::Destroyer *destroyer)
Perform partial array destruction as if in an EH cleanup.
static bool canEmitInitWithFewStoresAfterBZero(llvm::Constant *Init, unsigned &NumStores)
Decide whether we can emit the non-zero parts of the specified initializer with equal or fewer than N...
static llvm::Constant * patternOrZeroFor(CodeGenModule &CGM, IsPattern isPattern, llvm::Type *Ty)
Generate a constant filled with either a pattern or zeroes.
static llvm::Constant * constWithPadding(CodeGenModule &CGM, IsPattern isPattern, llvm::Constant *constant)
Replace all padding bytes in a given constant with either a pattern byte or 0x00.
static llvm::Value * shouldUseMemSetToInitialize(llvm::Constant *Init, uint64_t GlobalSize, const llvm::DataLayout &DL)
Decide whether we should use memset to initialize a local variable instead of using a memcpy from a c...
static bool shouldSplitConstantStore(CodeGenModule &CGM, uint64_t GlobalByteSize)
Decide whether we want to split a constant structure or array store into a sequence of its fields' st...
static llvm::Constant * replaceUndef(CodeGenModule &CGM, IsPattern isPattern, llvm::Constant *constant)
static bool shouldExtendLifetime(const ASTContext &Context, const Decl *FuncDecl, const VarDecl &D, ImplicitParamDecl *CXXABIThisDecl)
static bool tryEmitARCCopyWeakInit(CodeGenFunction &CGF, const LValue &destLV, const Expr *init)
static bool shouldUseBZeroPlusStoresToInitialize(llvm::Constant *Init, uint64_t GlobalSize)
Decide whether we should use bzero plus some stores to initialize a local variable instead of using a...
static llvm::Constant * constStructWithPadding(CodeGenModule &CGM, IsPattern isPattern, llvm::StructType *STy, llvm::Constant *constant)
Helper function for constWithPadding() to deal with padding in structures.
static bool containsUndef(llvm::Constant *constant)
static uint64_t maxFakeUseAggregateSize(const ASTContext &C)
Return the maximum size of an aggregate for which we generate a fake use intrinsic when -fextend-vari...
static bool isAccessedBy(const VarDecl &var, const Stmt *s)
static void EmitAutoVarWithLifetime(CodeGenFunction &CGF, const VarDecl &var, Address addr, Qualifiers::ObjCLifetime lifetime)
EmitAutoVarWithLifetime - Does the setup required for an automatic variable with lifetime.
static Address createUnnamedGlobalForMemcpyFrom(CodeGenModule &CGM, const VarDecl &D, CGBuilderTy &Builder, llvm::Constant *Constant, CharUnits Align)
static void drillIntoBlockVariable(CodeGenFunction &CGF, LValue &lvalue, const VarDecl *var)
static std::string getStaticDeclName(CIRGenModule &cgm, const VarDecl &d)
This file defines OpenACC nodes for declarative directives.
This file defines OpenMP nodes for declarative directives.
static const NamedDecl * getDefinition(const Decl *D)
__device__ __2f16 float __ockl_bool s
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
const LangOptions & getLangOpts() const
QualType getIntTypeForBitwidth(unsigned DestWidth, unsigned Signed) const
getIntTypeForBitwidth - sets integer QualTy according to specified details: bitwidth,...
CharUnits getDeclAlign(const Decl *D, bool ForAlignof=false) const
Return a conservative estimate of the alignment of the specified decl D.
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
const VariableArrayType * getAsVariableArrayType(QualType T) const
unsigned getTargetAddressSpace(LangAS AS) const
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Attr - This represents one attribute.
Represents a block literal declaration, which is like an unnamed FunctionDecl.
ArrayRef< Capture > captures() const
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
Represents a call to a C++ constructor.
Represents a C++ constructor within a class.
A use of a default initializer in a constructor or in aggregate initialization.
Represents a C++ destructor within a 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...
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
static CharUnits One()
One - Construct a CharUnits quantity of one.
CharUnits alignmentOfArrayElement(CharUnits elementSize) const
Given that this is the alignment of the first element of an array, return the minimum alignment of an...
bool isOne() const
isOne - Test whether the quantity equals one.
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
bool hasReducedDebugInfo() const
Check if type and variable info should be emitted.
ABIArgInfo - Helper class to encapsulate information about how a specific C type should be passed to ...
bool getIndirectByVal() const
Like RawAddress, an abstract representation of an aligned address, but the pointer contained in this ...
llvm::Value * emitRawPointer(CodeGenFunction &CGF) const
Return the pointer contained in this class after authenticating it and adding offset to it if necessa...
CharUnits getAlignment() const
llvm::Type * getElementType() const
Return the type of the values stored in this address.
Address withPointer(llvm::Value *NewPointer, KnownNonNull_t IsKnownNonNull) const
Return address with different pointer, but same element type and alignment.
Address withElementType(llvm::Type *ElemTy) const
Return address with different element type, but same pointer and alignment.
KnownNonNull_t isKnownNonNull() const
Whether the pointer is known not to be null.
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)
A scoped helper to set the current source atom group for CGDebugInfo::addInstToCurrentSourceAtom.
static ApplyDebugLocation CreateDefaultArtificial(CodeGenFunction &CGF, SourceLocation TemporaryLocation)
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)
Address CreateConstInBoundsByteGEP(Address Addr, CharUnits Offset, const llvm::Twine &Name="")
Given a pointer to i8, adjust it by a given constant offset.
Address CreateConstInBoundsGEP2_32(Address Addr, unsigned Idx0, unsigned Idx1, const llvm::Twine &Name="")
llvm::CallInst * CreateMemSet(Address Dest, llvm::Value *Value, llvm::Value *Size, bool IsVolatile=false)
llvm::LoadInst * CreateLoad(Address Addr, const llvm::Twine &Name="")
llvm::LoadInst * CreateFlagLoad(llvm::Value *Addr, const llvm::Twine &Name="")
Emit a load from an i1 flag variable.
llvm::CallInst * CreateMemCpy(Address Dest, Address Src, llvm::Value *Size, bool IsVolatile=false)
Address CreateConstGEP(Address Addr, uint64_t Index, const llvm::Twine &Name="")
Given addr = T* ... produce name = getelementptr inbounds addr, i64 index where i64 is actually the t...
Address CreateInBoundsGEP(Address Addr, ArrayRef< llvm::Value * > IdxList, llvm::Type *ElementType, CharUnits Align, const Twine &Name="")
Abstract information about a function or function prototype.
static CGCallee forDirect(llvm::Constant *functionPtr, const CGCalleeInfo &abstractInfo=CGCalleeInfo())
This class gathers all debug information during compilation and is responsible for emitting to llvm g...
void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl)
Emit information about a global variable.
llvm::DILocalVariable * EmitDeclareOfAutoVariable(const VarDecl *Decl, llvm::Value *AI, CGBuilderTy &Builder, const bool UsePointerValue=false)
Emit call to llvm.dbg.declare for an automatic variable declaration.
void setLocation(SourceLocation Loc)
Update the current source location.
void registerVLASizeExpression(QualType Ty, llvm::Metadata *SizeExpr)
Register VLA size expression debug node with the qualified type.
CGFunctionInfo - Class to encapsulate the information about a function definition.
const_arg_iterator arg_begin() const
MutableArrayRef< ArgInfo > arguments()
virtual void EmitWorkGroupLocalVarDecl(CodeGenFunction &CGF, const VarDecl &D)
Emit the IR required for a work-group-local variable declaration, and add an entry to CGF's LocalDecl...
Allows to disable automatic handling of functions used in target regions as those marked as omp decla...
virtual void getKmpcFreeShared(CodeGenFunction &CGF, const std::pair< llvm::Value *, llvm::Value * > &AddrSizePair)
Get call to __kmpc_free_shared.
void emitUserDefinedMapper(const OMPDeclareMapperDecl *D, CodeGenFunction *CGF=nullptr)
Emit the function for the user defined mapper construct.
virtual void processRequiresDirective(const OMPRequiresDecl *D)
Perform check on requires decl to ensure that target architecture supports unified addressing.
virtual std::pair< llvm::Value *, llvm::Value * > getKmpcAllocShared(CodeGenFunction &CGF, const VarDecl *VD)
Get call to __kmpc_alloc_shared.
virtual void emitUserDefinedReduction(CodeGenFunction *CGF, const OMPDeclareReductionDecl *D)
Emit code for the specified user defined reduction construct.
virtual Address getAddressOfLocalVariable(CodeGenFunction &CGF, const VarDecl *VD)
Gets the OpenMP-specific address of the local variable.
CallArgList - Type for representing both the value and type of arguments in a call.
void add(RValue rvalue, QualType type)
Address getAllocatedAddress() const
Returns the raw, allocated address, which is not necessarily the address of the object itself.
bool useLifetimeMarkers() const
RawAddress getOriginalAllocatedAddress() const
Returns the address for the original alloca instruction.
Address getObjectAddress(CodeGenFunction &CGF) const
Returns the address of the object within this declaration.
llvm::Value * getDirectValue() const
Address getIndirectAddress() const
llvm::Value * getAnyValue() const
Enters a new scope for capturing cleanups, all of which will be executed once the scope is exited.
RAII object to set/unset CodeGenFunction::IsSanitizerScope.
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
void emitArrayDestroy(llvm::Value *begin, llvm::Value *end, QualType elementType, CharUnits elementAlign, Destroyer *destroyer, bool checkZeroLength, bool useEHCleanup)
emitArrayDestroy - Destroys all the elements of the given array, beginning from last to first.
void EmitCXXGuardedInit(const VarDecl &D, llvm::GlobalVariable *DeclPtr, bool PerformInit)
Emit code in this function to perform a guarded variable initialization.
void EmitARCMoveWeak(Address dst, Address src)
void @objc_moveWeak(i8** dest, i8** src) Disregards the current value in dest.
void emitDestroy(Address addr, QualType type, Destroyer *destroyer, bool useEHCleanupForArray)
emitDestroy - Immediately perform the destruction of the given object.
static Destroyer destroyNonTrivialCStruct
AggValueSlot::Overlap_t getOverlapForFieldInit(const FieldDecl *FD)
Determine whether a field initialization may overlap some other object.
void emitByrefStructureInit(const AutoVarEmission &emission)
Initialize the structural components of a __block variable, i.e.
llvm::Value * EmitARCUnsafeUnretainedScalarExpr(const Expr *expr)
EmitARCUnsafeUnretainedScalarExpr - Semantically equivalent to immediately releasing the resut of Emi...
SanitizerSet SanOpts
Sanitizers enabled for this function.
void pushStackRestore(CleanupKind kind, Address SPMem)
llvm::DenseMap< const VarDecl *, llvm::Value * > NRVOFlags
A mapping from NRVO variables to the flags used to indicate when the NRVO has been applied to this va...
void EmitARCInitWeak(Address addr, llvm::Value *value)
i8* @objc_initWeak(i8** addr, i8* value) Returns value.
static bool ContainsLabel(const Stmt *S, bool IgnoreCaseStmts=false)
ContainsLabel - Return true if the statement contains a label in it.
static bool hasScalarEvaluationKind(QualType T)
llvm::Type * ConvertType(QualType T)
void EmitFakeUse(Address Addr)
static Destroyer destroyARCWeak
void pushEHDestroy(QualType::DestructionKind dtorKind, Address addr, QualType type)
pushEHDestroy - Push the standard destructor for the given type as an EH-only cleanup.
llvm::Value * EmitPointerAuthQualify(PointerAuthQualifier Qualifier, llvm::Value *Pointer, QualType ValueType, Address StorageAddress, bool IsKnownNonNull)
CleanupKind getARCCleanupKind()
Retrieves the default cleanup kind for an ARC cleanup.
llvm::Value * EmitARCRetainAutoreleaseScalarExpr(const Expr *expr)
bool CurFuncIsThunk
In C++, whether we are code generating a thunk.
void EmitAtomicInit(Expr *E, LValue lvalue)
void pushRegularPartialArrayCleanup(llvm::Value *arrayBegin, llvm::Value *arrayEnd, QualType elementType, CharUnits elementAlignment, Destroyer *destroyer)
pushRegularPartialArrayCleanup - Push an EH cleanup to destroy already-constructed elements of the gi...
void EmitAutoVarDecl(const VarDecl &D)
EmitAutoVarDecl - Emit an auto variable declaration.
llvm::Constant * EmitCheckSourceLocation(SourceLocation Loc)
Emit a description of a source location in a format suitable for passing to a runtime sanitizer handl...
void enterByrefCleanup(CleanupKind Kind, Address Addr, BlockFieldFlags Flags, bool LoadBlockVarAddr, bool CanThrow)
Enter a cleanup to destroy a __block variable.
void EmitAutoVarInit(const AutoVarEmission &emission)
llvm::SmallVector< DeferredDeactivateCleanup > DeferredDeactivationCleanupStack
llvm::BasicBlock * createBasicBlock(const Twine &name="", llvm::Function *parent=nullptr, llvm::BasicBlock *before=nullptr)
createBasicBlock - Create an LLVM basic block.
void addInstToCurrentSourceAtom(llvm::Instruction *KeyInstruction, llvm::Value *Backup)
See CGDebugInfo::addInstToCurrentSourceAtom.
const LangOptions & getLangOpts() const
RValue EmitReferenceBindingToExpr(const Expr *E)
Emits a reference binding to the passed in expression.
AutoVarEmission EmitAutoVarAlloca(const VarDecl &var)
EmitAutoVarAlloca - Emit the alloca and debug information for a local variable.
void EmitVarAnnotations(const VarDecl *D, llvm::Value *V)
Emit local annotations for the local variable V, declared by D.
void pushDestroy(QualType::DestructionKind dtorKind, Address addr, QualType type)
pushDestroy - Push the standard destructor for the given type as at least a normal cleanup.
void EmitScalarInit(const Expr *init, const ValueDecl *D, LValue lvalue, bool capturedByInit)
void EmitNullabilityCheck(LValue LHS, llvm::Value *RHS, SourceLocation Loc)
Given an assignment *LHS = RHS, emit a test that checks if RHS is nonnull, if LHS is marked _Nonnull.
const CodeGen::CGBlockInfo * BlockInfo
static Destroyer destroyCXXObject
@ TCK_NonnullAssign
Checking the value assigned to a _Nonnull pointer. Must not be null.
void EmitCXXDestructorCall(const CXXDestructorDecl *D, CXXDtorType Type, bool ForVirtualBase, bool Delegating, Address This, QualType ThisTy)
const BlockByrefInfo & getBlockByrefInfo(const VarDecl *var)
BuildByrefInfo - This routine changes a __block variable declared as T x into:
void pushIrregularPartialArrayCleanup(llvm::Value *arrayBegin, Address arrayEndPointer, QualType elementType, CharUnits elementAlignment, Destroyer *destroyer)
pushIrregularPartialArrayCleanup - Push a NormalAndEHCleanup to destroy already-constructed elements ...
const Decl * CurCodeDecl
CurCodeDecl - This is the inner-most code context, which includes blocks.
Destroyer * getDestroyer(QualType::DestructionKind destructionKind)
void EmitARCRelease(llvm::Value *value, ARCPreciseLifetime_t precise)
Release the given object.
DominatingValue< T >::saved_type saveValueInCond(T value)
static bool cxxDestructorCanThrow(QualType T)
Check if T is a C++ class that has a destructor that can throw.
llvm::Constant * EmitCheckTypeDescriptor(QualType T)
Emit a description of a type in a format suitable for passing to a runtime sanitizer handler.
void initFullExprCleanupWithFlag(RawAddress ActiveFlag)
RawAddress CreateDefaultAlignTempAlloca(llvm::Type *Ty, const Twine &Name="tmp")
CreateDefaultAlignedTempAlloca - This creates an alloca with the default ABI alignment of the given L...
const TargetInfo & getTarget() const
void defaultInitNonTrivialCStructVar(LValue Dst)
void EmitStaticVarDecl(const VarDecl &D, llvm::GlobalValue::LinkageTypes Linkage)
bool isInConditionalBranch() const
isInConditionalBranch - Return true if we're currently emitting one branch or the other of a conditio...
void pushKmpcAllocFree(CleanupKind Kind, std::pair< llvm::Value *, llvm::Value * > AddrSizePair)
void pushDestroyAndDeferDeactivation(QualType::DestructionKind dtorKind, Address addr, QualType type)
VlaSizePair getVLAElements1D(const VariableArrayType *vla)
Return the number of elements for a single dimension for the given array type.
static Destroyer destroyARCStrongImprecise
void EmitCheck(ArrayRef< std::pair< llvm::Value *, SanitizerKind::SanitizerOrdinal > > Checked, SanitizerHandler Check, ArrayRef< llvm::Constant * > StaticArgs, ArrayRef< llvm::Value * > DynamicArgs, const TrapReason *TR=nullptr)
Create a basic block that will either trap or call a handler function in the UBSan runtime with the p...
void EmitExtendGCLifetime(llvm::Value *object)
EmitExtendGCLifetime - Given a pointer to an Objective-C object, make sure it survives garbage collec...
LValue EmitDeclRefLValue(const DeclRefExpr *E)
llvm::Value * emitArrayLength(const ArrayType *arrayType, QualType &baseType, Address &addr)
emitArrayLength - Compute the length of an array, even if it's a VLA, and drill down to the base elem...
bool HaveInsertPoint() const
HaveInsertPoint - True if an insertion point is defined.
CGDebugInfo * getDebugInfo()
llvm::Value * EmitARCRetainScalarExpr(const Expr *expr)
EmitARCRetainScalarExpr - Semantically equivalent to EmitARCRetainObject(e->getType(),...
bool EmitLifetimeStart(llvm::Value *Addr)
Emit a lifetime.begin marker if some criteria are satisfied.
Address emitBlockByrefAddress(Address baseAddr, const VarDecl *V, bool followForward=true)
BuildBlockByrefAddress - Computes the location of the data in a variable which is declared as __block...
llvm::AllocaInst * CreateTempAlloca(llvm::Type *Ty, const Twine &Name="tmp", llvm::Value *ArraySize=nullptr)
CreateTempAlloca - This creates an alloca and inserts it into the entry block if ArraySize is nullptr...
ComplexPairTy EmitComplexExpr(const Expr *E, bool IgnoreReal=false, bool IgnoreImag=false)
EmitComplexExpr - Emit the computation of the specified expression of complex type,...
RValue EmitCall(const CGFunctionInfo &CallInfo, const CGCallee &Callee, ReturnValueSlot ReturnValue, const CallArgList &Args, llvm::CallBase **CallOrInvoke, bool IsMustTail, SourceLocation Loc, bool IsVirtualFunctionPointerThunk=false)
EmitCall - Generate a call of the given function, expecting the given result type,...
const TargetCodeGenInfo & getTargetHooks() const
void EmitLifetimeEnd(llvm::Value *Addr)
VlaSizePair getVLASize(const VariableArrayType *vla)
Returns an LLVM value that corresponds to the size, in non-variably-sized elements,...
ASTContext & getContext() const
llvm::Value * EmitLoadOfScalar(Address Addr, bool Volatile, QualType Ty, SourceLocation Loc, AlignmentSource Source=AlignmentSource::Type, bool isNontemporal=false)
EmitLoadOfScalar - Load a scalar value from an address, taking care to appropriately convert from the...
void emitAutoVarTypeCleanup(const AutoVarEmission &emission, QualType::DestructionKind dtorKind)
Enter a destroy cleanup for the given local variable.
void Destroyer(CodeGenFunction &CGF, Address addr, QualType ty)
void EmitStoreOfComplex(ComplexPairTy V, LValue dest, bool isInit)
EmitStoreOfComplex - Store a complex number into the specified l-value.
const Decl * CurFuncDecl
CurFuncDecl - Holds the Decl for the current outermost non-closure context.
void EmitAutoVarCleanups(const AutoVarEmission &emission)
void EmitAndRegisterVariableArrayDimensions(CGDebugInfo *DI, const VarDecl &D, bool EmitDebugInfo)
Emits the alloca and debug information for the size expressions for each dimension of an array.
void EmitStoreThroughLValue(RValue Src, LValue Dst, bool isInit=false)
EmitStoreThroughLValue - Store the specified rvalue into the specified lvalue, where both are guarant...
void pushLifetimeExtendedDestroy(CleanupKind kind, Address addr, QualType type, Destroyer *destroyer, bool useEHCleanupForArray)
void EmitParmDecl(const VarDecl &D, ParamValue Arg, unsigned ArgNo)
EmitParmDecl - Emit a ParmVarDecl or an ImplicitParamDecl.
Address ReturnValuePointer
ReturnValuePointer - The temporary alloca to hold a pointer to sret.
bool needsEHCleanup(QualType::DestructionKind kind)
Determines whether an EH cleanup is required to destroy a type with the given destruction kind.
llvm::GlobalVariable * AddInitializerToStaticVarDecl(const VarDecl &D, llvm::GlobalVariable *GV)
AddInitializerToStaticVarDecl - Add the initializer for 'D' to the global variable that has already b...
CleanupKind getCleanupKind(QualType::DestructionKind kind)
llvm::Value * EmitARCRetainNonBlock(llvm::Value *value)
Retain the given object, with normal retain semantics.
llvm::Type * ConvertTypeForMem(QualType T)
static TypeEvaluationKind getEvaluationKind(QualType T)
getEvaluationKind - Return the TypeEvaluationKind of QualType T.
RawAddress CreateMemTemp(QualType T, const Twine &Name="tmp", RawAddress *Alloca=nullptr)
CreateMemTemp - Create a temporary memory object of the given type, with appropriate alignmen and cas...
void setBlockContextParameter(const ImplicitParamDecl *D, unsigned argNum, llvm::Value *ptr)
void EmitVarDecl(const VarDecl &D)
EmitVarDecl - Emit a local variable declaration.
void EmitAggExpr(const Expr *E, AggValueSlot AS)
EmitAggExpr - Emit the computation of the specified expression of aggregate type.
VarBypassDetector Bypasses
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)
llvm::Value * EmitARCStoreStrongCall(Address addr, llvm::Value *value, bool resultIgnored)
Store into a strong object.
RawAddress createCleanupActiveFlag()
const CGFunctionInfo * CurFnInfo
void EmitDecl(const Decl &D, bool EvaluateConditionDecl=false)
EmitDecl - Emit a declaration.
std::pair< llvm::Value *, llvm::Value * > ComplexPairTy
Address ReturnValue
ReturnValue - The temporary alloca to hold the return value.
LValue EmitLValue(const Expr *E, KnownNonNull_t IsKnownNonNull=NotKnownNonNull)
EmitLValue - Emit code to compute a designator that specifies the location of the expression.
llvm::Value * EmitARCStoreWeak(Address addr, llvm::Value *value, bool ignored)
i8* @objc_storeWeak(i8** addr, i8* value) Returns value.
void EnsureInsertPoint()
EnsureInsertPoint - Ensure that an insertion point is defined so that emitted IR has a place to go.
llvm::LLVMContext & getLLVMContext()
static Destroyer destroyARCStrongPrecise
void EmitARCCopyWeak(Address dst, Address src)
void @objc_copyWeak(i8** dest, i8** src) Disregards the current value in dest.
void EmitVariablyModifiedType(QualType Ty)
EmitVLASize - Capture all the sizes for the VLA expressions in the given variably-modified type and s...
void MaybeEmitDeferredVarDeclInit(const VarDecl *var)
bool isTrivialInitializer(const Expr *Init)
Determine whether the given initializer is trivial in the sense that it requires no code to be genera...
void PopCleanupBlock(bool FallThroughIsBranchThrough=false, bool ForDeactivation=false)
PopCleanupBlock - Will pop the cleanup entry on the stack and process all branch fixups.
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...
bool hasLabelBeenSeenInCurrentScope() const
Return true if a label was seen in the current scope.
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false)
EmitBlock - Emit the given block.
void EmitExprAsInit(const Expr *init, const ValueDecl *D, LValue lvalue, bool capturedByInit)
EmitExprAsInit - Emits the code necessary to initialize a location in memory with the given initializ...
This class organizes the cross-function state that is used while generating LLVM code.
StringRef getBlockMangledName(GlobalDecl GD, const BlockDecl *BD)
void setGVProperties(llvm::GlobalValue *GV, GlobalDecl GD) const
Set visibility, dllimport/dllexport and dso_local.
llvm::Module & getModule() const
void setStaticLocalDeclAddress(const VarDecl *D, llvm::Constant *C)
llvm::Function * getLLVMLifetimeStartFn()
Lazily declare the @llvm.lifetime.start intrinsic.
llvm::Constant * GetAddrOfFunction(GlobalDecl GD, llvm::Type *Ty=nullptr, bool ForVTable=false, bool DontDefer=false, ForDefinition_t IsForDefinition=NotForDefinition)
Return the address of the given function.
Address createUnnamedGlobalFrom(const VarDecl &D, llvm::Constant *Constant, CharUnits Align)
llvm::Constant * getNullPointer(llvm::PointerType *T, QualType QT)
Get target specific null pointer.
void ErrorUnsupported(const Stmt *S, const char *Type)
Print out an error that codegen doesn't support the specified stmt yet.
void EmitOpenACCDeclare(const OpenACCDeclareDecl *D, CodeGenFunction *CGF=nullptr)
const LangOptions & getLangOpts() const
CharUnits getNaturalTypeAlignment(QualType T, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr, bool forPointeeType=false)
CodeGenTypes & getTypes()
CGOpenCLRuntime & getOpenCLRuntime()
Return a reference to the configured OpenCL runtime.
llvm::Function * getLLVMFakeUseFn()
Lazily declare the @llvm.fake.use intrinsic.
void addUsedGlobal(llvm::GlobalValue *GV)
Add a global to a list to be added to the llvm.used metadata.
void EmitOMPAllocateDecl(const OMPAllocateDecl *D)
Emit a code for the allocate directive.
llvm::GlobalValue::LinkageTypes getLLVMLinkageVarDefinition(const VarDecl *VD)
Returns LLVM linkage for a declarator.
const llvm::DataLayout & getDataLayout() const
void addUsedOrCompilerUsedGlobal(llvm::GlobalValue *GV)
Add a global to a list to be added to the llvm.compiler.used metadata.
CGOpenMPRuntime & getOpenMPRuntime()
Return a reference to the configured OpenMP runtime.
SanitizerMetadata * getSanitizerMetadata()
llvm::Constant * getOrCreateStaticVarDecl(const VarDecl &D, llvm::GlobalValue::LinkageTypes Linkage)
llvm::Constant * GetAddrOfGlobal(GlobalDecl GD, ForDefinition_t IsForDefinition=NotForDefinition)
void AddGlobalAnnotations(const ValueDecl *D, llvm::GlobalValue *GV)
Add global annotations that are set on D, for the global GV.
void setTLSMode(llvm::GlobalValue *GV, const VarDecl &D) const
Set the TLS mode for the given LLVM GlobalValue for the thread-local variable declaration D.
ASTContext & getContext() const
void EmitOMPDeclareMapper(const OMPDeclareMapperDecl *D, CodeGenFunction *CGF=nullptr)
Emit a code for declare mapper construct.
llvm::Function * getLLVMLifetimeEndFn()
Lazily declare the @llvm.lifetime.end intrinsic.
bool supportsCOMDAT() const
void EmitOMPRequiresDecl(const OMPRequiresDecl *D)
Emit a code for requires directive.
const TargetCodeGenInfo & getTargetCodeGenInfo()
const CodeGenOptions & getCodeGenOpts() const
StringRef getMangledName(GlobalDecl GD)
std::optional< CharUnits > getOMPAllocateAlignment(const VarDecl *VD)
Return the alignment specified in an allocate directive, if present.
llvm::LLVMContext & getLLVMContext()
llvm::GlobalValue * GetGlobalValue(StringRef Ref)
void EmitOMPDeclareReduction(const OMPDeclareReductionDecl *D, CodeGenFunction *CGF=nullptr)
Emit a code for declare reduction construct.
llvm::Constant * EmitNullConstant(QualType T)
Return the result of value-initializing the given type, i.e.
LangAS GetGlobalConstantAddressSpace() const
Return the AST address space of constant literal, which is used to emit the constant literal as globa...
LangAS GetGlobalVarAddressSpace(const VarDecl *D)
Return the AST address space of the underlying global variable for D, as determined by its declaratio...
void EmitOpenACCRoutine(const OpenACCRoutineDecl *D, CodeGenFunction *CGF=nullptr)
llvm::ConstantInt * getSize(CharUnits numChars)
Emit the given number of characters as a value of type size_t.
llvm::Type * convertTypeForLoadStore(QualType T, llvm::Type *LLVMTy=nullptr)
Given that T is a scalar type, return the IR type that should be used for load and store operations.
llvm::Type * ConvertTypeForMem(QualType T)
ConvertTypeForMem - Convert type T into a llvm::Type.
bool typeRequiresSplitIntoByteArray(QualType ASTTy, llvm::Type *LLVMTy=nullptr)
Check whether the given type needs to be laid out in memory using an opaque byte-array type because i...
const CGFunctionInfo & arrangeFunctionDeclaration(const GlobalDecl GD)
Free functions are functions that are compatible with an ordinary C function pointer type.
llvm::Constant * tryEmitForInitializer(const VarDecl &D)
Try to emit the initiaizer of the given declaration as an abstract constant.
void finalize(llvm::GlobalVariable *global)
llvm::Constant * tryEmitAbstractForInitializer(const VarDecl &D)
Try to emit the initializer of the given declaration as an abstract constant.
A cleanup scope which generates the cleanup blocks lazily.
Information for lazily generating a cleanup.
ConditionalCleanup stores the saved form of its parameters, then restores them and performs the clean...
stable_iterator stable_begin() const
Create a stable reference to the top of the EH stack.
iterator begin() const
Returns an iterator pointing to the innermost EH scope.
LValue - This represents an lvalue references.
llvm::Value * getPointer(CodeGenFunction &CGF) const
const Qualifiers & getQuals() const
Address getAddress() const
void setNonGC(bool Value)
void setAddress(Address address)
Qualifiers::ObjCLifetime getObjCLifetime() const
RValue - This trivial value class is used to represent the result of an expression that is evaluated.
static RValue get(llvm::Value *V)
An abstract representation of an aligned address.
llvm::Value * getPointer() const
static RawAddress invalid()
ReturnValueSlot - Contains the address where the return value of a function can be stored,...
Address performAddrSpaceCast(CodeGen::CodeGenFunction &CGF, Address Addr, LangAS SrcAddr, llvm::Type *DestTy, bool IsNonNull=false) const
virtual void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const
setTargetAttributes - Provides a convenient hook to handle extra target-specific attributes for the g...
bool IsBypassed(const VarDecl *D) const
Returns true if the variable declaration was by bypassed by any goto or switch statement.
CompoundStmt - This represents a group of statements like { stmt stmt }.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
A reference to a declared variable, function, enum, etc.
Decl - This represents one declaration (or definition), e.g.
const DeclContext * getParentFunctionOrMethod(bool LexicalParent=false) const
If this decl is defined inside a function/method/block it returns the corresponding DeclContext,...
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Decl * getNonClosureContext()
Find the innermost non-closure ancestor of this declaration, walking up through blocks,...
SourceLocation getLocation() const
bool isUsed(bool CheckUsedAttr=true) const
Whether any (re-)declaration of the entity was used, meaning that a definition is required.
DeclContext * getDeclContext()
This represents one expression.
Expr * IgnoreParenCasts() LLVM_READONLY
Skip past any parentheses and casts which might surround this expression until reaching a fixed point...
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
bool isLValue() const
isLValue - True if this expression is an "l-value" according to the rules of the current language.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Represents a function declaration or definition.
GlobalDecl - represents a global declaration.
const Decl * getDecl() const
One of these records is kept for each identifier that is lexed.
IdentifierInfo & getOwn(StringRef Name)
Gets an IdentifierInfo for the given name without consulting external sources.
This represents '#pragma omp allocate ...' directive.
This represents '#pragma omp declare mapper ...' directive.
This represents '#pragma omp declare reduction ...' directive.
This represents '#pragma omp requires...' directive.
Pointer-authentication qualifiers.
A (possibly-)qualified type.
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
@ DK_objc_strong_lifetime
@ PDIK_Struct
The type is a struct containing a field whose type is not PCK_Trivial.
LangAS getAddressSpace() const
Return the address space of this type.
bool isConstant(const ASTContext &Ctx) const
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Qualifiers::ObjCLifetime getObjCLifetime() const
Returns lifetime attribute of this type.
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
bool isObjCGCWeak() const
true when Type is objc's weak.
bool isConstantStorage(const ASTContext &Ctx, bool ExcludeCtor, bool ExcludeDtor)
bool isPODType(const ASTContext &Context) const
Determine whether this is a Plain Old Data (POD) type (C++ 3.9p10).
The collection of all-type qualifiers we support.
@ OCL_Strong
Assigning into this object requires the old value to be released and the new value to be retained.
@ OCL_ExplicitNone
This object can be modified without requiring retains or releases.
@ OCL_None
There is no lifetime qualification on this type.
@ OCL_Weak
Reading or writing from this object requires a barrier call.
@ OCL_Autoreleasing
Assigning into this object requires a lifetime extension.
PointerAuthQualifier getPointerAuth() const
ObjCLifetime getObjCLifetime() const
bool isParamDestroyedInCallee() const
Scope - A scope is a transient data structure that is used while parsing the program.
static const uint64_t MaximumAlignment
Encodes a location in the source.
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
Stmt - This represents one statement.
bool isMicrosoft() const
Is this ABI an MSVC-compatible ABI?
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
bool isConstantSizeType() const
Return true if this is not a variable sized type, according to the rules of C99 6....
RecordDecl * castAsRecordDecl() const
bool isVariablyModifiedType() const
Whether this type is a variably-modified type (C99 6.7.5).
bool isRecordType() const
std::optional< NullabilityKind > getNullability() const
Determine the nullability of the given type.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Represents a variable declaration or definition.
static VarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S)
bool isLocalVarDecl() const
Returns true for local variable declarations other than parameters.
Defines the clang::TargetInfo interface.
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
llvm::Constant * initializationPatternFor(CodeGenModule &, llvm::Type *)
@ NormalCleanup
Denotes a cleanup that should run when a scope is exited using normal control flow (falling off the e...
@ EHCleanup
Denotes a cleanup that should run when a scope is exited using exceptional control flow (a throw stat...
ARCPreciseLifetime_t
Does an ARC strong l-value have precise lifetime?
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const AstTypeMatcher< ArrayType > arrayType
Matches all kinds of arrays.
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
const internal::VariadicDynCastAllOfMatcher< Stmt, CastExpr > castExpr
Matches any cast nodes of Clang's AST.
constexpr Variable var(Literal L)
Returns the variable of L.
The JSON file list parser is used to communicate input to InstallAPI.
@ Ctor_Base
Base object ctor.
@ NonNull
Values of this type can never be null.
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have.
@ SD_Automatic
Automatic storage duration (most local variables).
@ Dtor_Base
Base object dtor.
@ Dtor_Complete
Complete object dtor.
LangAS
Defines the address space values used by the address space qualifier of QualType.
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
const FunctionProtoType * T
@ ThreadPrivateVar
Parameter for Thread private variable.
float __ovld __cnfn length(float)
Return the length of vector p, i.e., sqrt(p.x2 + p.y 2 + ...)
static Address getAddressOfLocalVariable(CodeGenFunction &CGF, const VarDecl *VD)
Gets the OpenMP-specific address of the local variable /p VD.
llvm::IntegerType * Int8Ty
i8, i16, i32, and i64
llvm::IntegerType * SizeTy
llvm::IntegerType * IntPtrTy
llvm::PointerType * Int8PtrTy
llvm::PointerType * AllocaInt8PtrTy
LangAS getASTAllocaAddressSpace() const
bool has(SanitizerMask K) const
Check if a certain (single) sanitizer is enabled.