33 #include "llvm/IR/DataLayout.h"
34 #include "llvm/IR/Intrinsics.h"
35 #include "llvm/IR/MDBuilder.h"
36 #include "llvm/IR/Operator.h"
37 using namespace clang;
38 using namespace CodeGen;
40 CodeGenFunction::CodeGenFunction(
CodeGenModule &cgm,
bool suppressNewContext)
42 Builder(cgm, cgm.getModule().getContext(), llvm::ConstantFolder(),
44 CurFn(nullptr), ReturnValue(
Address::invalid()),
45 CapturedStmtInfo(nullptr),
46 SanOpts(CGM.getLangOpts().Sanitize), IsSanitizerScope(
false),
48 IsOutlinedSEHHelper(
false),
49 BlockInfo(nullptr), BlockPointer(nullptr),
50 LambdaThisCaptureField(nullptr), NormalCleanupDest(nullptr),
51 NextCleanupDestIndex(1), FirstBlockInfo(nullptr), EHResumeBlock(nullptr),
52 ExceptionSlot(nullptr), EHSelectorSlot(nullptr),
53 DebugInfo(CGM.getModuleDebugInfo()),
54 DisableDebugInfo(
false), DidCallStackSave(
false), IndirectBranch(nullptr),
55 PGO(cgm), SwitchInsn(nullptr), SwitchWeights(nullptr),
56 CaseRangeBlock(nullptr), UnreachableBlock(nullptr), NumReturnExprs(0),
57 NumSimpleReturnExprs(0), CXXABIThisDecl(nullptr),
58 CXXABIThisValue(nullptr), CXXThisValue(nullptr),
59 CXXStructorImplicitParamDecl(nullptr),
60 CXXStructorImplicitParamValue(nullptr), OutermostConditional(nullptr),
61 CurLexicalScope(nullptr), TerminateLandingPad(nullptr),
62 TerminateHandler(nullptr), TrapBB(nullptr) {
63 if (!suppressNewContext)
66 llvm::FastMathFlags FMF;
68 FMF.setUnsafeAlgebra();
77 FMF.setNoSignedZeros();
80 FMF.setAllowReciprocal();
107 bool forPointeeType) {
112 if (
auto Align = TT->getDecl()->getMaxAlignment()) {
136 if (
unsigned MaxAlign =
getLangOpts().MaxTypeAlign) {
174 #define TYPE(name, parent)
175 #define ABSTRACT_TYPE(name, parent)
176 #define NON_CANONICAL_TYPE(name, parent) case Type::name:
177 #define DEPENDENT_TYPE(name, parent) case Type::name:
178 #define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(name, parent) case Type::name:
179 #include "clang/AST/TypeNodes.def"
180 llvm_unreachable(
"non-canonical or dependent type in IR-generation");
183 llvm_unreachable(
"undeduced auto type in IR-generation");
188 case Type::BlockPointer:
189 case Type::LValueReference:
190 case Type::RValueReference:
191 case Type::MemberPointer:
193 case Type::ExtVector:
194 case Type::FunctionProto:
195 case Type::FunctionNoProto:
197 case Type::ObjCObjectPointer:
206 case Type::ConstantArray:
207 case Type::IncompleteArray:
208 case Type::VariableArray:
210 case Type::ObjCObject:
211 case Type::ObjCInterface:
216 type = cast<AtomicType>(
type)->getValueType();
219 llvm_unreachable(
"unknown type kind!");
226 llvm::BasicBlock *CurBB =
Builder.GetInsertBlock();
229 assert(!CurBB->getTerminator() &&
"Unexpected terminated block.");
238 return llvm::DebugLoc();
245 llvm::BranchInst *BI =
247 if (BI && BI->isUnconditional() &&
251 llvm::DebugLoc Loc = BI->getDebugLoc();
252 Builder.SetInsertPoint(BI->getParent());
253 BI->eraseFromParent();
264 return llvm::DebugLoc();
269 if (!BB->use_empty())
270 return CGF.
CurFn->getBasicBlockList().push_back(BB);
275 assert(BreakContinueStack.empty() &&
276 "mismatched push/pop in break/continue stack!");
278 bool OnlySimpleReturnStmts = NumSimpleReturnExprs > 0
279 && NumSimpleReturnExprs == NumReturnExprs
294 if (OnlySimpleReturnStmts)
295 DI->EmitLocation(
Builder, LastStopPoint);
297 DI->EmitLocation(
Builder, EndLoc);
305 bool HasOnlyLifetimeMarkers =
307 bool EmitRetDbgLoc = !HasCleanups || HasOnlyLifetimeMarkers;
312 if (OnlySimpleReturnStmts)
313 DI->EmitLocation(
Builder, EndLoc);
335 "did not remove all scopes from cleanup stack!");
339 if (IndirectBranch) {
346 if (!EscapedLocals.empty()) {
350 EscapeArgs.resize(EscapedLocals.size());
351 for (
auto &Pair : EscapedLocals)
352 EscapeArgs[Pair.second] = Pair.first;
353 llvm::Function *FrameEscapeFn = llvm::Intrinsic::getDeclaration(
361 Ptr->eraseFromParent();
365 if (IndirectBranch) {
366 llvm::PHINode *PN = cast<llvm::PHINode>(IndirectBranch->getAddress());
367 if (PN->getNumIncomingValues() == 0) {
368 PN->replaceAllUsesWith(llvm::UndefValue::get(PN->getType()));
369 PN->eraseFromParent();
382 I = DeferredReplacements.begin(),
383 E = DeferredReplacements.end();
385 I->first->replaceAllUsesWith(
I->second);
386 I->first->eraseFromParent();
412 llvm::PointerType *PointerTy =
Int8PtrTy;
413 llvm::Type *ProfileFuncArgs[] = { PointerTy, PointerTy };
414 llvm::FunctionType *FunctionTy =
415 llvm::FunctionType::get(
VoidTy, ProfileFuncArgs,
false);
418 llvm::CallInst *CallSite =
Builder.CreateCall(
420 llvm::ConstantInt::get(
Int32Ty, 0),
424 llvm::ConstantExpr::getBitCast(
CurFn, PointerTy),
432 llvm::FunctionType *FTy = llvm::FunctionType::get(
VoidTy,
false);
434 llvm::Constant *MCountFn =
469 for (
unsigned i = 0, e = FD->
getNumParams(); i != e; ++i) {
472 std::string typeQuals;
478 addressQuals.push_back(llvm::ConstantAsMetadata::get(Builder.getInt32(
482 std::string typeName =
486 std::string::size_type pos = typeName.find(
"unsigned");
487 if (pointeeTy.
isCanonical() && pos != std::string::npos)
488 typeName.erase(pos+1, 8);
490 argTypeNames.push_back(llvm::MDString::get(Context, typeName));
492 std::string baseTypeName =
498 pos = baseTypeName.find(
"unsigned");
499 if (pos != std::string::npos)
500 baseTypeName.erase(pos+1, 8);
502 argBaseTypeNames.push_back(llvm::MDString::get(Context, baseTypeName));
506 typeQuals =
"restrict";
509 typeQuals += typeQuals.empty() ?
"const" :
" const";
511 typeQuals += typeQuals.empty() ?
"volatile" :
" volatile";
513 uint32_t AddrSpc = 0;
519 addressQuals.push_back(
520 llvm::ConstantAsMetadata::get(Builder.getInt32(AddrSpc)));
523 std::string typeName;
526 .getAsString(Policy);
531 std::string::size_type pos = typeName.find(
"unsigned");
533 typeName.erase(pos+1, 8);
535 argTypeNames.push_back(llvm::MDString::get(Context, typeName));
537 std::string baseTypeName;
540 ->getElementType().getCanonicalType()
541 .getAsString(Policy);
547 pos = baseTypeName.find(
"unsigned");
548 if (pos != std::string::npos)
549 baseTypeName.erase(pos+1, 8);
551 argBaseTypeNames.push_back(llvm::MDString::get(Context, baseTypeName));
557 typeQuals += typeQuals.empty() ?
"volatile" :
" volatile";
562 argTypeQuals.push_back(llvm::MDString::get(Context, typeQuals));
566 const OpenCLAccessAttr *A = parm->getAttr<OpenCLAccessAttr>();
567 if (A && A->isWriteOnly())
568 accessQuals.push_back(llvm::MDString::get(Context,
"write_only"));
569 else if (A && A->isReadWrite())
570 accessQuals.push_back(llvm::MDString::get(Context,
"read_write"));
572 accessQuals.push_back(llvm::MDString::get(Context,
"read_only"));
574 accessQuals.push_back(llvm::MDString::get(Context,
"none"));
577 argNames.push_back(llvm::MDString::get(Context, parm->
getName()));
580 Fn->setMetadata(
"kernel_arg_addr_space",
581 llvm::MDNode::get(Context, addressQuals));
582 Fn->setMetadata(
"kernel_arg_access_qual",
583 llvm::MDNode::get(Context, accessQuals));
584 Fn->setMetadata(
"kernel_arg_type",
585 llvm::MDNode::get(Context, argTypeNames));
586 Fn->setMetadata(
"kernel_arg_base_type",
587 llvm::MDNode::get(Context, argBaseTypeNames));
588 Fn->setMetadata(
"kernel_arg_type_qual",
589 llvm::MDNode::get(Context, argTypeQuals));
591 Fn->setMetadata(
"kernel_arg_name",
592 llvm::MDNode::get(Context, argNames));
595 void CodeGenFunction::EmitOpenCLKernelMetadata(
const FunctionDecl *FD,
598 if (!FD->hasAttr<OpenCLKernelAttr>())
605 if (
const VecTypeHintAttr *A = FD->getAttr<VecTypeHintAttr>()) {
606 QualType hintQTy = A->getTypeHint();
608 bool isSignedInteger =
611 llvm::Metadata *attrMDArgs[] = {
612 llvm::ConstantAsMetadata::get(llvm::UndefValue::get(
614 llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
615 llvm::IntegerType::get(Context, 32),
616 llvm::APInt(32, (uint64_t)(isSignedInteger ? 1 : 0))))};
617 Fn->setMetadata(
"vec_type_hint", llvm::MDNode::get(Context, attrMDArgs));
620 if (
const WorkGroupSizeHintAttr *A = FD->getAttr<WorkGroupSizeHintAttr>()) {
621 llvm::Metadata *attrMDArgs[] = {
622 llvm::ConstantAsMetadata::get(
Builder.getInt32(A->getXDim())),
623 llvm::ConstantAsMetadata::get(
Builder.getInt32(A->getYDim())),
624 llvm::ConstantAsMetadata::get(
Builder.getInt32(A->getZDim()))};
625 Fn->setMetadata(
"work_group_size_hint", llvm::MDNode::get(Context, attrMDArgs));
628 if (
const ReqdWorkGroupSizeAttr *A = FD->getAttr<ReqdWorkGroupSizeAttr>()) {
629 llvm::Metadata *attrMDArgs[] = {
630 llvm::ConstantAsMetadata::get(
Builder.getInt32(A->getXDim())),
631 llvm::ConstantAsMetadata::get(
Builder.getInt32(A->getYDim())),
632 llvm::ConstantAsMetadata::get(
Builder.getInt32(A->getZDim()))};
633 Fn->setMetadata(
"reqd_work_group_size", llvm::MDNode::get(Context, attrMDArgs));
639 const Stmt *Body =
nullptr;
640 if (
auto *FD = dyn_cast_or_null<FunctionDecl>(F))
642 else if (
auto *OMD = dyn_cast_or_null<ObjCMethodDecl>(F))
643 Body = OMD->getBody();
645 if (
auto *CS = dyn_cast_or_null<CompoundStmt>(Body)) {
646 auto LastStmt = CS->body_rbegin();
647 if (LastStmt != CS->body_rend())
648 return isa<ReturnStmt>(*LastStmt);
661 "Do not use a CodeGenFunction object for more than one function");
665 DidCallStackSave =
false;
667 if (
const auto *FD = dyn_cast_or_null<FunctionDecl>(D))
670 CurFuncDecl = (D ? D->getNonClosureContext() :
nullptr);
674 assert(
CurFn->isDeclaration() &&
"Function already has body?");
681 for (
auto Attr : D->specific_attrs<NoSanitizeAttr>())
686 if (
SanOpts.
hasOneOf(SanitizerKind::Address | SanitizerKind::KernelAddress))
687 Fn->addFnAttr(llvm::Attribute::SanitizeAddress);
689 Fn->addFnAttr(llvm::Attribute::SanitizeThread);
691 Fn->addFnAttr(llvm::Attribute::SanitizeMemory);
693 Fn->addFnAttr(llvm::Attribute::SafeStack);
697 if (
const auto *XRayAttr = D->getAttr<XRayInstrumentAttr>()) {
698 if (XRayAttr->alwaysXRayInstrument())
699 Fn->addFnAttr(
"function-instrument",
"xray-always");
700 if (XRayAttr->neverXRayInstrument())
701 Fn->addFnAttr(
"function-instrument",
"xray-never");
704 "xray-instruction-threshold",
714 if (
const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D)) {
716 if (!CodeGenOpts.NoInline) {
718 if (RI->isInlineSpecified()) {
719 Fn->addFnAttr(llvm::Attribute::InlineHint);
723 !FD->
isInlined() && !Fn->hasFnAttribute(llvm::Attribute::InlineHint))
724 Fn->addFnAttr(llvm::Attribute::NoInline);
725 }
else if (!FD->hasAttr<AlwaysInlineAttr>())
726 Fn->addFnAttr(llvm::Attribute::NoInline);
727 if (
CGM.
getLangOpts().OpenMP && FD->hasAttr<OMPDeclareSimdDeclAttr>())
732 Fn->addFnAttr(
"no-jump-tables",
737 if (
const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D))
738 EmitOpenCLKernelMetadata(FD, Fn);
744 if (
const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D)) {
745 if (llvm::Constant *PrologueSig =
747 llvm::Constant *FTRTTIConst =
749 llvm::Constant *PrologueStructElems[] = { PrologueSig, FTRTTIConst };
750 llvm::Constant *PrologueStructConst =
751 llvm::ConstantStruct::getAnon(PrologueStructElems,
true);
752 Fn->setPrologueData(PrologueStructConst);
761 if (
const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D))
763 Fn->addFnAttr(llvm::Attribute::NoRecurse);
775 Builder.SetInsertPoint(EntryBB);
783 if (
auto *FD = dyn_cast_or_null<FunctionDecl>(D))
785 CC = SrcFnTy->getCallConv();
788 ArgTypes.push_back(VD->getType());
791 DI->EmitFunctionStart(GD, Loc, StartLoc, FnType,
CurFn,
Builder);
811 auto AI =
CurFn->arg_begin();
819 llvm::Function::arg_iterator EI =
CurFn->arg_end();
841 if (D && isa<CXXMethodDecl>(D) && cast<CXXMethodDecl>(D)->isInstance()) {
868 if (FD->hasCapturedVLAType()) {
871 auto VAT = FD->getCapturedVLAType();
872 VLASizeMap[VAT->getSizeExpr()] = ExprArg;
879 CXXThisValue = CXXABIThisValue;
885 for (FunctionArgList::const_iterator i = Args.begin(), e = Args.end();
893 if (
const ParmVarDecl *PVD = dyn_cast<ParmVarDecl>(VD))
894 Ty = PVD->getOriginalType();
903 DI->EmitLocation(
Builder, StartLoc);
921 llvm::BasicBlock *SkipCountBB =
nullptr;
943 if (F->isInterposable())
return;
945 for (llvm::BasicBlock &BB : *F)
946 for (llvm::Instruction &
I : BB)
950 F->setDoesNotThrow();
970 bool PassedParams =
true;
972 if (
auto Inherited = CD->getInheritedConstructor())
978 Args.push_back(Param);
979 if (!Param->hasAttr<PassObjectSizeAttr>())
984 getContext(), Param->getDeclContext(), Param->getLocation(), NoID,
986 SizeArguments[Param] = Implicit;
987 Args.push_back(Implicit);
991 if (MD && (isa<CXXConstructorDecl>(MD) || isa<CXXDestructorDecl>(MD)))
1006 if (FD->hasAttr<NoDebugAttr>())
1007 DebugInfo =
nullptr;
1010 if (
Stmt *Body = FD->
getBody()) BodyRange = Body->getSourceRange();
1011 CurEHLocation = BodyRange.
getEnd();
1023 if (SpecDecl->hasBody(SpecDecl))
1024 Loc = SpecDecl->getLocation();
1031 if (isa<CXXDestructorDecl>(FD))
1033 else if (isa<CXXConstructorDecl>(FD))
1037 FD->hasAttr<CUDAGlobalAttr>())
1039 else if (isa<CXXConversionDecl>(FD) &&
1040 cast<CXXConversionDecl>(FD)->isLambdaToBlockPointerConversion()) {
1044 }
else if (isa<CXXMethodDecl>(FD) &&
1045 cast<CXXMethodDecl>(FD)->isLambdaStaticInvoker()) {
1049 }
else if (FD->
isDefaulted() && isa<CXXMethodDecl>(FD) &&
1050 (cast<CXXMethodDecl>(FD)->isCopyAssignmentOperator() ||
1051 cast<CXXMethodDecl>(FD)->isMoveAssignmentOperator())) {
1058 llvm_unreachable(
"no definition for emitted function");
1071 EmitCheck(std::make_pair(IsFalse, SanitizerKind::Return),
1078 Builder.ClearInsertionPoint();
1086 if (!
CurFn->doesNotThrow())
1095 if (!S)
return false;
1102 if (isa<LabelStmt>(S))
1107 if (isa<SwitchCase>(S) && !IgnoreCaseStmts)
1111 if (isa<SwitchStmt>(S))
1112 IgnoreCaseStmts =
true;
1115 for (
const Stmt *SubStmt : S->children())
1127 if (!S)
return false;
1131 if (isa<SwitchStmt>(S) || isa<WhileStmt>(S) || isa<DoStmt>(S) ||
1135 if (isa<BreakStmt>(S))
1139 for (
const Stmt *SubStmt : S->children())
1153 llvm::APSInt ResultInt;
1157 ResultBool = ResultInt.getBoolValue();
1165 llvm::APSInt &ResultInt,
1187 llvm::BasicBlock *TrueBlock,
1188 llvm::BasicBlock *FalseBlock,
1189 uint64_t TrueCount) {
1192 if (
const BinaryOperator *CondBOp = dyn_cast<BinaryOperator>(Cond)) {
1195 if (CondBOp->getOpcode() == BO_LAnd) {
1198 bool ConstantBool =
false;
1241 if (CondBOp->getOpcode() == BO_LOr) {
1244 bool ConstantBool =
false;
1270 uint64_t RHSCount = TrueCount - LHSCount;
1292 if (
const UnaryOperator *CondUOp = dyn_cast<UnaryOperator>(Cond)) {
1294 if (CondUOp->getOpcode() == UO_LNot) {
1317 uint64_t LHSScaledTrueCount = 0;
1321 LHSScaledTrueCount = TrueCount * LHSRatio;
1330 LHSScaledTrueCount);
1337 TrueCount - LHSScaledTrueCount);
1343 if (
const CXXThrowExpr *Throw = dyn_cast<CXXThrowExpr>(Cond)) {
1356 llvm::MDNode *Unpredictable =
nullptr;
1357 auto *Call = dyn_cast<
CallExpr>(Cond);
1359 auto *FD = dyn_cast_or_null<FunctionDecl>(Call->getCalleeDecl());
1360 if (FD && FD->
getBuiltinID() == Builtin::BI__builtin_unpredictable) {
1362 Unpredictable = MDHelper.createUnpredictable();
1369 llvm::MDNode *Weights =
1370 createProfileWeights(TrueCount, CurrentCount - TrueCount);
1378 Builder.CreateCondBr(CondV, TrueBlock, FalseBlock, Weights, Unpredictable);
1406 Builder.CreateInBoundsGEP(begin.getPointer(), sizeInChars,
"vla.end");
1408 llvm::BasicBlock *originBB = CGF.
Builder.GetInsertBlock();
1416 llvm::PHINode *cur = Builder.CreatePHI(begin.getType(), 2,
"vla.cur");
1417 cur->addIncoming(begin.getPointer(), originBB);
1428 Builder.CreateInBoundsGEP(CGF.
Int8Ty, cur, baseSizeInChars,
"vla.next");
1431 llvm::Value *done = Builder.CreateICmpEQ(next, end,
"vla-init.isdone");
1432 Builder.CreateCondBr(done, contBB, loopBB);
1433 cur->addIncoming(next, loopBB);
1443 if (cast<CXXRecordDecl>(RT->getDecl())->isEmpty())
1462 dyn_cast_or_null<VariableArrayType>(
1466 std::tie(numElts, eltType) =
getVLASize(vlaType);
1470 if (!eltSize.
isOne())
1491 llvm::GlobalVariable *NullVariable =
1492 new llvm::GlobalVariable(
CGM.
getModule(), NullConstant->getType(),
1494 llvm::GlobalVariable::PrivateLinkage,
1495 NullConstant, Twine());
1497 NullVariable->setAlignment(NullAlign.getQuantity());
1516 if (!IndirectBranch)
1522 IndirectBranch->addDestination(BB);
1523 return llvm::BlockAddress::get(
CurFn, BB);
1528 if (IndirectBranch)
return IndirectBranch->getParent();
1534 "indirect.goto.dest");
1537 IndirectBranch = TmpBuilder.CreateIndirectBr(DestVal);
1538 return IndirectBranch->getParent();
1546 const ArrayType *arrayType = origArrayType;
1551 if (isa<VariableArrayType>(arrayType)) {
1552 numVLAElements =
getVLASize(cast<VariableArrayType>(arrayType)).first;
1562 baseType = elementType;
1563 return numVLAElements;
1565 }
while (isa<VariableArrayType>(arrayType));
1577 llvm::ConstantInt *zero =
Builder.getInt32(0);
1578 gepIndices.push_back(zero);
1580 uint64_t countFromCLAs = 1;
1583 llvm::ArrayType *llvmArrayType =
1585 while (llvmArrayType) {
1586 assert(isa<ConstantArrayType>(arrayType));
1587 assert(cast<ConstantArrayType>(arrayType)->getSize().getZExtValue()
1588 == llvmArrayType->getNumElements());
1590 gepIndices.push_back(zero);
1591 countFromCLAs *= llvmArrayType->getNumElements();
1595 dyn_cast<llvm::ArrayType>(llvmArrayType->getElementType());
1597 assert((!llvmArrayType || arrayType) &&
1598 "LLVM and Clang types are out-of-synch");
1607 cast<ConstantArrayType>(arrayType)->getSize().getZExtValue();
1617 gepIndices,
"array.begin"),
1624 = llvm::ConstantInt::get(
SizeTy, countFromCLAs);
1628 numElements =
Builder.CreateNUWMul(numVLAElements, numElements);
1633 std::pair<llvm::Value*, QualType>
1636 assert(vla &&
"type was not a variable array type!");
1640 std::pair<llvm::Value*, QualType>
1649 assert(vlaSize &&
"no size for VLA!");
1650 assert(vlaSize->getType() ==
SizeTy);
1653 numElements = vlaSize;
1657 numElements =
Builder.CreateNUWMul(numElements, vlaSize);
1659 }
while ((type =
getContext().getAsVariableArrayType(elementType)));
1661 return std::pair<llvm::Value*,QualType>(numElements, elementType);
1666 "Must pass variably modified type to EmitVLASizes!");
1676 switch (ty->getTypeClass()) {
1678 #define TYPE(Class, Base)
1679 #define ABSTRACT_TYPE(Class, Base)
1680 #define NON_CANONICAL_TYPE(Class, Base)
1681 #define DEPENDENT_TYPE(Class, Base) case Type::Class:
1682 #define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class, Base)
1683 #include "clang/AST/TypeNodes.def"
1684 llvm_unreachable(
"unexpected dependent type!");
1690 case Type::ExtVector:
1693 case Type::Elaborated:
1694 case Type::TemplateSpecialization:
1695 case Type::ObjCObject:
1696 case Type::ObjCInterface:
1697 case Type::ObjCObjectPointer:
1698 llvm_unreachable(
"type class is never variably-modified!");
1700 case Type::Adjusted:
1701 type = cast<AdjustedType>(ty)->getAdjustedType();
1705 type = cast<DecayedType>(ty)->getPointeeType();
1709 type = cast<PointerType>(ty)->getPointeeType();
1712 case Type::BlockPointer:
1713 type = cast<BlockPointerType>(ty)->getPointeeType();
1716 case Type::LValueReference:
1717 case Type::RValueReference:
1718 type = cast<ReferenceType>(ty)->getPointeeType();
1721 case Type::MemberPointer:
1722 type = cast<MemberPointerType>(ty)->getPointeeType();
1725 case Type::ConstantArray:
1726 case Type::IncompleteArray:
1728 type = cast<ArrayType>(ty)->getElementType();
1731 case Type::VariableArray: {
1749 size->getType()->isSignedIntegerType()) {
1751 llvm::Value *Zero = llvm::Constant::getNullValue(Size->getType());
1752 llvm::Constant *StaticArgs[] = {
1757 SanitizerKind::VLABound),
1758 "vla_bound_not_positive", StaticArgs, Size);
1770 case Type::FunctionProto:
1771 case Type::FunctionNoProto:
1772 type = cast<FunctionType>(ty)->getReturnType();
1777 case Type::UnaryTransform:
1778 case Type::Attributed:
1779 case Type::SubstTemplateTypeParm:
1780 case Type::PackExpansion:
1786 case Type::Decltype:
1791 case Type::TypeOfExpr:
1797 type = cast<AtomicType>(ty)->getValueType();
1801 type = cast<PipeType>(ty)->getElementType();
1808 if (
getContext().getBuiltinVaListType()->isArrayType())
1818 llvm::Constant *Init) {
1819 assert (Init &&
"Invalid DeclRefExpr initializer!");
1822 Dbg->EmitGlobalVariable(E->
getDecl(), Init);
1837 llvm::Instruction *inst =
new llvm::BitCastInst(value, value->getType(),
"",
1841 protection.Inst = inst;
1846 if (!protection.Inst)
return;
1849 protection.Inst->eraseFromParent();
1854 StringRef AnnotationStr,
1862 return Builder.CreateCall(AnnotationFn, Args);
1866 assert(D->hasAttr<AnnotateAttr>() &&
"no annotate attribute");
1869 for (
const auto *
I : D->specific_attrs<AnnotateAttr>())
1872 I->getAnnotation(), D->getLocation());
1877 assert(D->hasAttr<AnnotateAttr>() &&
"no annotate attribute");
1883 for (
const auto *
I : D->specific_attrs<AnnotateAttr>()) {
1905 CGF->IsSanitizerScope =
false;
1909 const llvm::Twine &
Name,
1910 llvm::BasicBlock *BB,
1918 llvm::Instruction *
I,
const llvm::Twine &
Name, llvm::BasicBlock *BB,
1920 llvm::IRBuilderDefaultInserter::InsertHelper(I, Name, BB, InsertPt);
1922 CGF->InsertHelper(I, Name, BB, InsertPt);
1927 std::string &FirstMissing) {
1929 if (ReqFeatures.empty())
1934 llvm::StringMap<bool> CallerFeatureMap;
1940 ReqFeatures.begin(), ReqFeatures.end(), [&](StringRef Feature) {
1942 Feature.split(OrFeatures,
"|");
1943 return std::any_of(OrFeatures.begin(), OrFeatures.end(),
1944 [&](StringRef Feature) {
1945 if (!CallerFeatureMap.lookup(Feature)) {
1946 FirstMissing = Feature.str();
1972 std::string MissingFeature;
1975 const char *FeatureList =
1978 if (!FeatureList || StringRef(FeatureList) ==
"")
1980 StringRef(FeatureList).split(ReqFeatures,
",");
1986 }
else if (TargetDecl->hasAttr<TargetAttr>()) {
1989 llvm::StringMap<bool> CalleeFeatureMap;
1991 for (
const auto &F : CalleeFeatureMap) {
1994 ReqFeatures.push_back(F.getKey());
2006 llvm::IRBuilder<> IRB(
Builder.GetInsertBlock(),
Builder.GetInsertPoint());
2007 IRB.SetCurrentDebugLocation(
Builder.getCurrentDebugLocation());
unsigned getAddressSpace() const
Return the address space of this type.
Defines the clang::ASTContext interface.
SourceLocation getEnd() const
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
LValue MakeNaturalAlignPointeeAddrLValue(llvm::Value *V, QualType T)
Given a value of type T* that may not be to a complete object, construct an l-value with the natural ...
void end(CodeGenFunction &CGF)
StringRef getName() const
getName - Get the name of identifier for this declaration as a StringRef.
A (possibly-)qualified type.
CodeGenTypes & getTypes()
llvm::Type * ConvertTypeForMem(QualType T)
void EmitBranchOnBoolExpr(const Expr *Cond, llvm::BasicBlock *TrueBlock, llvm::BasicBlock *FalseBlock, uint64_t TrueCount)
EmitBranchOnBoolExpr - Emit a branch on a boolean condition (e.g.
CanQualType getReturnType() const
CXXCtorType getCtorType() const
unsigned getInAllocaFieldIndex() const
llvm::Constant * EmitCheckTypeDescriptor(QualType T)
Emit a description of a type in a format suitable for passing to a runtime sanitizer handler...
llvm::Module & getModule() const
AlignmentSource
The source of the alignment of an l-value; an expression of confidence in the alignment actually matc...
void EmitFunctionInstrumentation(const char *Fn)
EmitFunctionInstrumentation - Emit LLVM code to call the specified instrumentation function with the ...
bool isOne() const
isOne - Test whether the quantity equals one.
virtual void addImplicitStructorParams(CodeGenFunction &CGF, QualType &ResTy, FunctionArgList &Params)=0
Insert any ABI-specific implicit parameters into the parameter list for a function.
CharUnits getClassPointerAlignment(const CXXRecordDecl *CD)
Returns the assumed alignment of an opaque pointer to the given class.
FunctionType - C99 6.7.5.3 - Function Declarators.
const TargetInfo & getTarget() const
bool isMain() const
Determines whether this function is "main", which is the entry point into an executable program...
CanQualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
static bool endsWithReturn(const Decl *F)
Determine whether the function F ends with a return stmt.
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
Address getAddress() const
const Decl * CurCodeDecl
CurCodeDecl - This is the inner-most code context, which includes blocks.
void InsertHelper(llvm::Instruction *I, const llvm::Twine &Name, llvm::BasicBlock *BB, llvm::BasicBlock::iterator InsertPt) const
This forwards to CodeGenFunction::InsertHelper.
bool isAlignmentRequired(const Type *T) const
Determine if the alignment the type has was required using an alignment attribute.
std::string getAsString() const
The base class of the type hierarchy.
bool ShouldInstrumentFunction()
ShouldInstrumentFunction - Return true if the current function should be instrumented with __cyg_prof...
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
void GenerateCode(GlobalDecl GD, llvm::Function *Fn, const CGFunctionInfo &FnInfo)
Represents an array type, per C99 6.7.5.2 - Array Declarators.
static bool hasRequiredFeatures(const SmallVectorImpl< StringRef > &ReqFeatures, CodeGenModule &CGM, const FunctionDecl *FD, std::string &FirstMissing)
const LangOptions & getLangOpts() const
llvm::IntegerType * Int8Ty
i8, i16, i32, and i64
Represents a C++ constructor within a class.
bool ConstantFoldsToSimpleInteger(const Expr *Cond, bool &Result, bool AllowLabels=false)
ConstantFoldsToSimpleInteger - If the specified expression does not fold to a constant, or if it does but contains a label, return false.
TypeEvaluationKind
The kind of evaluation to perform on values of a particular type.
VarDecl - An instance of this class is created to represent a variable declaration or definition...
llvm::Type * getElementType() const
Return the type of the values stored in this address.
RAII object to set/unset CodeGenFunction::IsSanitizerScope.
Extra information about a function prototype.
uint64_t getProfileCount(const Stmt *S)
Get the profiler's count for the given statement.
This class gathers all debug information during compilation and is responsible for emitting to llvm g...
QualType getThisType(ASTContext &C) const
Returns the type of the this pointer.
llvm::CallInst * EmitTrapCall(llvm::Intrinsic::ID IntrID)
Emit a call to trap or debugtrap and attach function attribute "trap-func-name" if specified...
void EmitVariablyModifiedType(QualType Ty)
EmitVLASize - Capture all the sizes for the VLA expressions in the given variably-modified type and s...
CharUnits getNaturalTypeAlignment(QualType T, AlignmentSource *Source=nullptr, bool forPointeeType=false)
void setCurrentProfileCount(uint64_t Count)
Set the profiler's current count.
bool IsSanitizerScope
True if CodeGen currently emits code implementing sanitizer checks.
Describes how types, statements, expressions, and declarations should be printed. ...
llvm::Type * ConvertTypeForMem(QualType T)
ConvertTypeForMem - Convert type T into a llvm::Type.
A C++ throw-expression (C++ [except.throw]).
ParmVarDecl - Represents a parameter to a function.
bool isObjCRetainableType() const
static void destroyBlockInfos(CGBlockInfo *info)
Destroy a chain of block layouts.
void emitImplicitAssignmentOperatorBody(FunctionArgList &Args)
EHScopeStack::stable_iterator PrologueCleanupDepth
PrologueCleanupDepth - The cleanup depth enclosing all the cleanups associated with the parameters...
virtual bool hasMostDerivedReturn(GlobalDecl GD) const
JumpDest getJumpDestForLabel(const LabelDecl *S)
getBasicBlockForLabel - Return the LLVM basicblock that the specified label maps to.
llvm::DenseMap< const VarDecl *, FieldDecl * > LambdaCaptureFields
An object to manage conditionally-evaluated expressions.
PeepholeProtection protectFromPeepholes(RValue rvalue)
protectFromPeepholes - Protect a value that we're intending to store to the side, but which will prob...
bool ShouldXRayInstrumentFunction() const
ShouldXRayInstrument - Return true if the current function should be instrumented with XRay nop sleds...
One of these records is kept for each identifier that is lexed.
CGBlockInfo * FirstBlockInfo
FirstBlockInfo - The head of a singly-linked-list of block layouts.
void EmitFunctionEpilog(const CGFunctionInfo &FI, bool EmitRetDbgLoc, SourceLocation EndLoc)
EmitFunctionEpilog - Emit the target specific LLVM code to return the given temporary.
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
Indirect - Pass the argument indirectly via a hidden pointer with the specified alignment (0 indicate...
CGDebugInfo * getDebugInfo()
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
Expr * getSizeExpr() const
llvm::Type * ConvertType(QualType T)
ConvertType - Convert type T into a llvm::Type.
bool isVariablyModifiedType() const
Whether this type is a variably-modified type (C99 6.7.5).
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
LValue EmitLValueForLambdaField(const FieldDecl *Field)
Given that we are currently emitting a lambda, emit an l-value for one of its members.
QualType getReturnType() const
FieldDecl - An instance of this class is created by Sema::ActOnField to represent a member of a struc...
llvm::IntegerType * SizeTy
const FunctionDecl * CurSEHParent
void InsertHelper(llvm::Instruction *I, const llvm::Twine &Name, llvm::BasicBlock *BB, llvm::BasicBlock::iterator InsertPt) const
CGBuilder insert helper.
SanitizerMask Mask
Bitmask of enabled sanitizers.
const Decl * getDecl() const
static ApplyDebugLocation CreateArtificial(CodeGenFunction &CGF)
Apply TemporaryLocation if it is valid.
Address CreateIRTemp(QualType T, const Twine &Name="tmp")
CreateIRTemp - Create a temporary IR object of the given type, with appropriate alignment.
virtual void EmitInstanceFunctionProlog(CodeGenFunction &CGF)=0
Emit the ABI-specific prolog for the function.
CGCUDARuntime & getCUDARuntime()
Return a reference to the configured CUDA runtime.
static bool hasScalarEvaluationKind(QualType T)
Address CreateElementBitCast(Address Addr, llvm::Type *Ty, const llvm::Twine &Name="")
Cast the element type of the given address to a different type, preserving information like the align...
CharUnits - This is an opaque type for sizes expressed in character units.
const CXXRecordDecl * getParent() const
Returns the parent of this method declaration, which is the class in which this method is defined...
bool isDefaulted() const
Whether this function is defaulted per C++0x.
virtual llvm::Constant * getUBSanFunctionSignature(CodeGen::CodeGenModule &CGM) const
Return a constant used by UBSan as a signature to identify functions possessing type information...
field_range fields() const
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
A builtin binary operation expression such as "x + y" or "x <= y".
The l-value was considered opaque, so the alignment was determined from a type, but that type was an ...
FunctionDecl * getTemplateInstantiationPattern() const
Retrieve the function declaration from which this function could be instantiated, if it is an instant...
llvm::CallInst * CreateMemCpy(Address Dest, Address Src, llvm::Value *Size, bool IsVolatile=false)
void incrementProfileCounter(const Stmt *S)
Increment the profiler's counter for the given statement.
void EmitStmt(const Stmt *S)
EmitStmt - Emit the code for the statement.
llvm::BasicBlock * createBasicBlock(const Twine &name="", llvm::Function *parent=nullptr, llvm::BasicBlock *before=nullptr)
createBasicBlock - Create an LLVM basic block.
void EmitIgnoredExpr(const Expr *E)
EmitIgnoredExpr - Emit an expression in a context which ignores the result.
void assignRegionCounters(GlobalDecl GD, llvm::Function *Fn)
Assign counters to regions and configure them for PGO of a given function.
TypeClass getTypeClass() const
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types...
GlobalDecl CurGD
CurGD - The GlobalDecl for the current function being compiled.
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
static bool ContainsLabel(const Stmt *S, bool IgnoreCaseStmts=false)
ContainsLabel - Return true if the statement contains a label in it.
llvm::SanitizerStatReport & getSanStats()
llvm::DebugLoc EmitReturnBlock()
Emit the unified return block, trying to avoid its emission when possible.
uint64_t getCurrentProfileCount()
Get the profiler's current count.
detail::InMemoryDirectory::const_iterator I
virtual void emitDeviceStub(CodeGenFunction &CGF, FunctionArgList &Args)=0
Emits a kernel launch stub.
void begin(CodeGenFunction &CGF)
void EmitDeclRefExprDbgValue(const DeclRefExpr *E, llvm::Constant *Init)
LValue MakeAddrLValue(Address Addr, QualType T, AlignmentSource AlignSource=AlignmentSource::Type)
ConditionalOperator - The ?: ternary operator.
static CharUnits One()
One - Construct a CharUnits quantity of one.
void EmitCheck(ArrayRef< std::pair< llvm::Value *, SanitizerMask >> Checked, StringRef CheckName, ArrayRef< llvm::Constant * > StaticArgs, ArrayRef< llvm::Value * > DynamicArgs)
Create a basic block that will call a handler function in a sanitizer runtime with the provided argum...
CompoundStmt - This represents a group of statements like { stmt stmt }.
llvm::CallInst * EmitNounwindRuntimeCall(llvm::Value *callee, const Twine &name="")
const TargetCodeGenInfo & getTargetCodeGenInfo()
void clear()
Disable all sanitizers.
RValue - This trivial value class is used to represent the result of an expression that is evaluated...
void EmitSanitizerStatReport(llvm::SanitizerStatKind SSK)
static void EmitIfUsed(CodeGenFunction &CGF, llvm::BasicBlock *BB)
bool usesSEHTry() const
Indicates the function uses __try.
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
void getFunctionFeatureMap(llvm::StringMap< bool > &FeatureMap, const FunctionDecl *FD)
static TypeEvaluationKind getEvaluationKind(QualType T)
hasAggregateLLVMType - Return true if the specified AST type will map into an aggregate LLVM type or ...
llvm::Constant * EmitAnnotationUnit(SourceLocation Loc)
Emit the annotation's translation unit.
llvm::Value * getPointer() const
llvm::BasicBlock * EHResumeBlock
EHResumeBlock - Unified block containing a call to llvm.eh.resume.
bool empty() const
Determines whether the exception-scopes stack is empty.
Expr - This represents one expression.
Emit only debug info necessary for generating line number tables (-gline-tables-only).
CGCXXABI & getCXXABI() const
CharUnits getIndirectAlign() const
const ParmVarDecl * getParamDecl(unsigned i) const
static void TryMarkNoThrow(llvm::Function *F)
Tries to mark the given function nounwind based on the non-existence of any throwing calls within it...
ASTContext & getContext() const
CharUnits getNaturalPointeeTypeAlignment(QualType T, AlignmentSource *Source=nullptr)
llvm::BasicBlock * getBlock() const
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
static LValue MakeAddr(Address address, QualType type, ASTContext &Context, AlignmentSource alignSource, llvm::MDNode *TBAAInfo=nullptr)
stable_iterator stable_begin() const
Create a stable reference to the top of the EH stack.
bool isInlined() const
Determine whether this function should be inlined, because it is either marked "inline" or "constexpr...
llvm::LLVMContext & getLLVMContext()
llvm::BasicBlock * GetIndirectGotoBlock()
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
llvm::IntegerType * Int32Ty
void EmitConstructorBody(FunctionArgList &Args)
EmitConstructorBody - Emits the body of the current constructor.
Address EmitPointerWithAlignment(const Expr *Addr, AlignmentSource *Source=nullptr)
EmitPointerWithAlignment - Given an expression with a pointer type, emit the value and compute our be...
llvm::Constant * EmitAnnotationString(StringRef Str)
Emit an annotation string.
bool EvaluateAsInt(llvm::APSInt &Result, const ASTContext &Ctx, SideEffectsKind AllowSideEffects=SE_NoSideEffects) const
EvaluateAsInt - Return true if this is a constant which we can fold and convert to an integer...
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...
LValue MakeNaturalAlignAddrLValue(llvm::Value *V, QualType T)
bool containsOnlyLifetimeMarkers(stable_iterator Old) const
llvm::CallInst * CreateMemSet(Address Dest, llvm::Value *Value, llvm::Value *Size, bool IsVolatile=false)
void EmitMCountInstrumentation()
EmitMCountInstrumentation - Emit call to .mcount.
An object which temporarily prevents a value from being destroyed by aggressive peephole optimization...
UnaryOperator - This represents the unary-expression's (except sizeof and alignof), the postinc/postdec operators from postfix-expression, and various extensions.
void EmitLambdaToBlockPointerBody(FunctionArgList &Args)
llvm::Function * getIntrinsic(unsigned IID, ArrayRef< llvm::Type * > Tys=None)
DeclarationName getDeclName() const
getDeclName - Get the actual, stored name of the declaration, which may be a special name...
QualType getElementType() const
virtual void startNewFunction()
CallingConv
CallingConv - Specifies the calling convention that a function uses.
GlobalDecl - represents a global declaration.
const clang::PrintingPolicy & getPrintingPolicy() const
SanitizerScope(CodeGenFunction *CGF)
The l-value was considered opaque, so the alignment was determined from a type.
Stmt * getBody(const FunctionDecl *&Definition) const
getBody - Retrieve the body (definition) of the function.
bool HaveInsertPoint() const
HaveInsertPoint - True if an insertion point is defined.
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
bool SawAsmBlock
Whether we processed a Microsoft-style asm block during CodeGen.
Address CreateBitCast(Address Addr, llvm::Type *Ty, const llvm::Twine &Name="")
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
bool hasOneOf(SanitizerMask K) const
Check if one or more sanitizers are enabled.
llvm::Constant * CreateRuntimeFunction(llvm::FunctionType *Ty, StringRef Name, llvm::AttributeSet ExtraAttrs=llvm::AttributeSet())
Create a new runtime function with the specified type and name.
ASTContext & getContext() const
Encodes a location in the source.
CharUnits getPointerAlign() const
void EnsureInsertPoint()
EnsureInsertPoint - Ensure that an insertion point is defined so that emitted IR has a place to go...
unsigned getNumParams() const
getNumParams - Return the number of parameters this function must have based on its FunctionType...
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
const TemplateArgument * iterator
llvm::Value * EvaluateExprAsBool(const Expr *E)
EvaluateExprAsBool - Perform the usual unary conversions on the specified expression and compare the ...
bool inheritingCtorHasParams(const InheritedConstructor &Inherited, CXXCtorType Type)
Determine if a C++ inheriting constructor should have parameters matching those of its inherited cons...
const char * getRequiredFeatures(unsigned ID) const
LabelDecl - Represents the declaration of a label.
A scoped helper to set the current debug location to the specified location or preferred location of ...
Represents a static or instance method of a struct/union/class.
bool isReturnsRetained() const
In ARC, whether this function retains its return value.
ArrayRef< ParmVarDecl * > parameters() const
SanitizerSet SanOpts
Sanitizers enabled for this function.
llvm::Constant * GetAddrOfRTTIDescriptor(QualType Ty, bool ForEH=false)
Get the address of the RTTI descriptor for the given type.
CharUnits alignmentOfArrayElement(CharUnits elementSize) const
Given that this is the alignment of the first element of an array, return the minimum alignment of an...
const CodeGenOptions & getCodeGenOpts() 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.
const LangOptions & getLangOpts() const
SourceLocation getBegin() const
MangleContext & getMangleContext()
Gets the mangle context.
void getCaptureFields(llvm::DenseMap< const VarDecl *, FieldDecl * > &Captures, FieldDecl *&ThisCapture) const
For a closure type, retrieve the mapping from captured variables and this to the non-static data memb...
JumpDest getJumpDestInCurrentScope(llvm::BasicBlock *Target)
The given basic block lies in the current EH scope, but may be a target of a potentially scope-crossi...
llvm::Constant * EmitAnnotationLineNo(SourceLocation L)
Emit the annotation line number.
unsigned getBuiltinID() const
Returns a value indicating whether this function corresponds to a builtin function.
InAlloca - Pass the argument directly using the LLVM inalloca attribute.
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
Address EmitMSVAListRef(const Expr *E)
Emit a "reference" to a __builtin_ms_va_list; this is always the value of the expression, because a __builtin_ms_va_list is a pointer to a char.
const CGFunctionInfo * CurFnInfo
void EmitStartEHSpec(const Decl *D)
EmitStartEHSpec - Emit the start of the exception spec.
void FinishFunction(SourceLocation EndLoc=SourceLocation())
FinishFunction - Complete IR generation of the current function.
QualType getFunctionType(QualType ResultTy, ArrayRef< QualType > Args, const FunctionProtoType::ExtProtoInfo &EPI) const
Return a normal function type with a typed argument list.
This is an IRBuilder insertion helper that forwards to CodeGenFunction::InsertHelper, which adds necessary metadata to instructions.
Address EmitVAListRef(const Expr *E)
llvm::Value * EmitScalarExpr(const Expr *E, bool IgnoreResultAssign=false)
EmitScalarExpr - Emit the computation of the specified expression of LLVM scalar type, returning the result.
bool isSRetAfterThis() const
FunctionArgList - Type for representing both the decl and type of parameters to a function...
Represents a template argument.
void ErrorUnsupported(const Stmt *S, const char *Type)
Print out an error that codegen doesn't support the specified stmt yet.
CGFunctionInfo - Class to encapsulate the information about a function definition.
CharUnits getAlignment() const
Return the alignment of this pointer.
This class organizes the cross-function state that is used while generating LLVM code.
CGOpenMPRuntime & getOpenMPRuntime()
Return a reference to the configured OpenMP runtime.
static void emitNonZeroVLAInit(CodeGenFunction &CGF, QualType baseType, Address dest, Address src, llvm::Value *sizeInChars)
emitNonZeroVLAInit - Emit the "zero" initialization of a variable-length array whose elements have a ...
Address EmitFieldAnnotations(const FieldDecl *D, Address V)
Emit field annotations for the given field & value.
bool isZero() const
isZero - Test whether the quantity equals zero.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
virtual ~CGCapturedStmtInfo()
llvm::Value * getScalarVal() const
getScalarVal() - Return the Value* of this scalar value.
Address CreateStructGEP(Address Addr, unsigned Index, CharUnits Offset, const llvm::Twine &Name="")
llvm::Value * EmitAnnotationCall(llvm::Value *AnnotationFn, llvm::Value *AnnotatedVal, StringRef AnnotationStr, SourceLocation Location)
Emit an annotation call (intrinsic or builtin).
llvm::LoadInst * CreateAlignedLoad(llvm::Value *Addr, CharUnits Align, const llvm::Twine &Name="")
llvm::IntegerType * IntPtrTy
void buildThisParam(CodeGenFunction &CGF, FunctionArgList &Params)
Build a parameter variable suitable for 'this'.
llvm::Constant * EmitNullConstant(QualType T)
Return the result of value-initializing the given type, i.e.
detail::InMemoryDirectory::const_iterator E
llvm::SmallVector< char, 256 > LifetimeExtendedCleanupStack
bool isLambda() const
Determine whether this class describes a lambda function object.
bool isInSanitizerBlacklist(llvm::Function *Fn, SourceLocation Loc) const
static void GenOpenCLArgMetadata(const FunctionDecl *FD, llvm::Function *Fn, CodeGenModule &CGM, llvm::LLVMContext &Context, CGBuilderTy &Builder, ASTContext &ASTCtx)
const VariableArrayType * getAsVariableArrayType(QualType T) const
JumpDest ReturnBlock
ReturnBlock - Unified return block.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
void EmitBlockWithFallThrough(llvm::BasicBlock *BB, const Stmt *S)
When instrumenting to collect profile data, the counts for some blocks such as switch cases need to n...
const T * getAs() const
Member-template getAs<specific type>'.
QualType getCanonicalType() const
static ImplicitParamDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id, QualType T)
llvm::PointerType * Int8PtrTy
void EmitLambdaStaticInvokeFunction(const CXXMethodDecl *MD)
SourceLocation getLocStart() const LLVM_READONLY
bool has(SanitizerMask K) const
Check if a certain (single) sanitizer is enabled.
llvm::AssertingVH< llvm::Instruction > AllocaInsertPt
AllocaInsertPoint - This is an instruction in the entry block before which we prefer to insert alloca...
ExtVectorType - Extended vector type.
QualType BuildFunctionArgList(GlobalDecl GD, FunctionArgList &Args)
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
bool hasProfileClangInstr() const
Check if Clang profile instrumenation is on.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
bool isRestrictQualified() const
Determine whether this type is restrict-qualified.
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false)
EmitBlock - Emit the given block.
void checkTargetFeatures(const CallExpr *E, const FunctionDecl *TargetDecl)
FieldDecl * LambdaThisCaptureField
ABIArgInfo & getReturnInfo()
char __ovld __cnfn max(char x, char y)
Returns y if x < y, otherwise it returns x.
void EmitFunctionBody(FunctionArgList &Args, const Stmt *Body)
llvm::ConstantInt * getSize(CharUnits numChars)
Emit the given number of characters as a value of type size_t.
const Decl * CurFuncDecl
CurFuncDecl - Holds the Decl for the current outermost non-closure context.
void InsertHelper(llvm::Instruction *I) const
Function called by the CodeGenFunction when an instruction is created.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
void unprotectFromPeepholes(PeepholeProtection protection)
DiagnosticsEngine & getDiags() const
void ErrorUnsupported(const Stmt *S, const char *Type)
ErrorUnsupported - Print out an error that codegen doesn't support the specified stmt yet...
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Represents a C++ struct/union/class.
BoundNodesTreeBuilder *const Builder
void EmitBranch(llvm::BasicBlock *Block)
EmitBranch - Emit a branch to the specified basic block from the current insert block, taking care to avoid creation of branches from dummy blocks.
llvm::Type * ConvertType(QualType T)
void EmitFunctionProlog(const CGFunctionInfo &FI, llvm::Function *Fn, const FunctionArgList &Args)
EmitFunctionProlog - Emit the target specific LLVM code to load the arguments for the given function...
void PopCleanupBlocks(EHScopeStack::stable_iterator OldCleanupStackSize)
Takes the old cleanup stack size and emits the cleanup blocks that have been added.
LValue EmitLValue(const Expr *E)
EmitLValue - Emit code to compute a designator that specifies the location of the expression...
Address ReturnValue
ReturnValue - The temporary alloca to hold the return value.
Builtin::Context & BuiltinInfo
bool AutoreleaseResult
In ARC, whether we should autorelease the return value.
RValue EmitLoadOfLValue(LValue V, SourceLocation Loc)
EmitLoadOfLValue - Given an expression that represents a value lvalue, this method emits the address ...
std::pair< llvm::Value *, QualType > getVLASize(const VariableArrayType *vla)
getVLASize - Returns an LLVM value that corresponds to the size, in non-variably-sized elements...
Defines the clang::TargetInfo interface.
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
llvm::MDNode * getTBAAInfo(QualType QTy)
unsigned getTargetAddressSpace(QualType T) const
A reference to a declared variable, function, enum, etc.
void EmitDestructorBody(FunctionArgList &Args)
EmitDestructorBody - Emits the body of the current destructor.
QualType getElementType() const
This structure provides a set of types that are commonly used during IR emission. ...
void EmitEndEHSpec(const Decl *D)
EmitEndEHSpec - Emit the end of the exception spec.
llvm::Constant * EmitCheckSourceLocation(SourceLocation Loc)
Emit a description of a source location in a format suitable for passing to a runtime sanitizer handl...
Address EmitCompoundStmtWithoutScope(const CompoundStmt &S, bool GetLast=false, AggValueSlot AVS=AggValueSlot::ignored())
CodeGenTypes & getTypes() const
A trivial tuple used to represent a source range.
LValue - This represents an lvalue references.
llvm::BlockAddress * GetAddrOfLabel(const LabelDecl *L)
void EmitVarAnnotations(const VarDecl *D, llvm::Value *V)
Emit local annotations for the local variable V, declared by D.
Represents a C array with a specified size that is not an integer-constant-expression.
SanitizerMetadata * getSanitizerMetadata()
bool isSignedIntegerType() const
Return true if this is an integer type that is signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], or an enum decl which has a signed representation.
bool isConstQualified() const
Determine whether this type is const-qualified.
bool hasImplicitReturnZero() const
Whether falling off this function implicitly returns null/zero.
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...
static bool containsBreak(const Stmt *S)
containsBreak - Return true if the statement contains a break out of it.
QualType getSingleStepDesugaredType(const ASTContext &Context) const
Return the specified type with one level of "sugar" removed from the type.
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
bool isZeroInitializable(QualType T)
IsZeroInitializable - Return whether a type can be zero-initialized (in the C++ sense) with an LLVM z...
Defines enum values for all the target-independent builtin functions.
void EmitCXXThrowExpr(const CXXThrowExpr *E, bool KeepInsertionPoint=true)
Attr - This represents one attribute.
void EmitNullInitialization(Address DestPtr, QualType Ty)
EmitNullInitialization - Generate code to set a value of the given type to null, If the type contains...
Expr * IgnoreParens() LLVM_READONLY
IgnoreParens - Ignore parentheses.
bool isPointerType() const
OverloadedOperatorKind getOverloadedOperator() const
getOverloadedOperator - Which C++ overloaded operator this function represents, if any...