31 #include "llvm/ADT/StringExtras.h"
32 #include "llvm/IR/Attributes.h"
33 #include "llvm/IR/CallingConv.h"
34 #include "llvm/IR/CallSite.h"
35 #include "llvm/IR/DataLayout.h"
36 #include "llvm/IR/InlineAsm.h"
37 #include "llvm/IR/Intrinsics.h"
38 #include "llvm/IR/IntrinsicInst.h"
39 #include "llvm/Transforms/Utils/Local.h"
40 using namespace clang;
41 using namespace CodeGen;
45 unsigned CodeGenTypes::ClangCallConvToLLVMCallConv(
CallingConv CC) {
53 case CC_AAPCS:
return llvm::CallingConv::ARM_AAPCS;
54 case CC_AAPCS_VFP:
return llvm::CallingConv::ARM_AAPCS_VFP;
64 case CC_Swift:
return llvm::CallingConv::Swift;
110 if (FPT->hasExtParameterInfos() || !paramInfos.empty()) {
111 assert(paramInfos.size() <= prefix.size());
112 auto protoParamInfos = FPT->getExtParameterInfos();
113 paramInfos.reserve(prefix.size() + protoParamInfos.size());
114 paramInfos.resize(prefix.size());
115 paramInfos.append(protoParamInfos.begin(), protoParamInfos.end());
120 prefix.append(FPT->param_type_begin(), FPT->param_type_end());
127 prefix.reserve(prefix.size() + FPT->getNumParams());
130 for (
unsigned I = 0,
E = FPT->getNumParams();
I !=
E; ++
I) {
131 prefix.push_back(FPT->getParamType(
I));
153 FTP->getExtInfo(), paramInfos,
169 if (D->hasAttr<StdCallAttr>())
172 if (D->hasAttr<FastCallAttr>())
175 if (D->hasAttr<ThisCallAttr>())
178 if (D->hasAttr<VectorCallAttr>())
181 if (D->hasAttr<PascalAttr>())
184 if (PcsAttr *PCS = D->getAttr<PcsAttr>())
187 if (D->hasAttr<IntelOclBiccAttr>())
190 if (D->hasAttr<MSABIAttr>())
193 if (D->hasAttr<SysVABIAttr>())
196 if (D->hasAttr<PreserveMostAttr>())
199 if (D->hasAttr<PreserveAllAttr>())
224 *
this,
true, argTypes,
234 assert(!isa<CXXConstructorDecl>(MD) &&
"wrong method for constructors!");
235 assert(!isa<CXXDestructorDecl>(MD) &&
"wrong method for destructors!");
265 bool PassParams =
true;
268 if (
auto *CD = dyn_cast<CXXConstructorDecl>(MD)) {
273 if (
auto Inherited = CD->getInheritedConstructor())
299 false, argTypes, extInfo,
300 paramInfos, required);
306 for (
auto &arg : args)
314 for (
auto &arg : args)
323 unsigned totalArgs) {
325 assert(paramInfos.size() <= prefixArgs);
326 assert(proto->
getNumParams() + prefixArgs <= totalArgs);
329 paramInfos.resize(prefixArgs);
333 paramInfos.append(protoInfos.begin(), protoInfos.end());
336 paramInfos.resize(totalArgs);
341 unsigned prefixArgs,
unsigned totalArgs) {
354 unsigned ExtraArgs) {
357 for (
const auto &Arg : args)
373 false, ArgTypes, Info,
374 ParamInfos, Required);
382 if (MD->isInstance())
387 assert(isa<FunctionType>(FTy));
391 if (isa<FunctionNoProtoType>(FTy)) {
394 noProto->getReturnType(),
false,
398 assert(isa<FunctionProtoType>(FTy));
432 if (
getContext().getLangOpts().ObjCAutoRefCount &&
433 MD->hasAttr<NSReturnsRetainedAttr>())
441 false, argTys, einfo, {}, required);
476 assert(MD->
isVirtual() &&
"only virtual memptrs have thunks");
494 ArgTys.push_back(*FTP->param_type_begin());
496 ArgTys.push_back(Context.
IntTy);
512 unsigned numExtraRequiredArgs,
514 assert(args.size() >= numExtraRequiredArgs);
524 if (proto->isVariadic())
525 required =
RequiredArgs(proto->getNumParams() + numExtraRequiredArgs);
527 if (proto->hasExtParameterInfos())
537 cast<FunctionNoProtoType>(fnType))) {
543 for (
const auto &arg : args)
560 chainCall ? 1 : 0, chainCall);
580 false,
false, argTypes,
590 for (
const auto &Arg : args)
612 resultType,
false,
false,
621 unsigned numRequiredArgs =
623 unsigned numPrefixArgs = numRequiredArgs - proto->
getNumParams();
633 false, argTypes, info, paramInfos, required);
645 assert(signature.
arg_size() <= args.size());
646 if (signature.
arg_size() == args.size())
651 if (!sigParamInfos.empty()) {
652 paramInfos.append(sigParamInfos.begin(), sigParamInfos.end());
653 paramInfos.resize(args.size());
679 assert(std::all_of(argTypes.begin(), argTypes.end(),
683 llvm::FoldingSetNodeID
ID;
685 required, resultType, argTypes);
687 void *insertPos =
nullptr;
688 CGFunctionInfo *FI = FunctionInfos.FindNodeOrInsertPos(ID, insertPos);
692 unsigned CC = ClangCallConvToLLVMCallConv(info.
getCC());
696 paramInfos, resultType, argTypes, required);
697 FunctionInfos.InsertNode(FI, insertPos);
699 bool inserted = FunctionsBeingProcessed.insert(FI).second;
701 assert(inserted &&
"Recursively being processed?");
717 for (
auto &
I : FI->arguments())
718 if (
I.info.canHaveCoerceToType() &&
I.info.getCoerceToType() ==
nullptr)
721 bool erased = FunctionsBeingProcessed.erase(FI); (void)erased;
722 assert(erased &&
"Not in set?");
735 assert(paramInfos.empty() || paramInfos.size() == argTypes.size());
738 operator new(totalSizeToAlloc<ArgInfo, ExtParameterInfo>(
739 argTypes.size() + 1, paramInfos.size()));
742 FI->CallingConvention = llvmCC;
743 FI->EffectiveCallingConvention = llvmCC;
744 FI->ASTCallingConvention = info.
getCC();
745 FI->InstanceMethod = instanceMethod;
746 FI->ChainCall = chainCall;
749 FI->Required = required;
752 FI->ArgStruct =
nullptr;
753 FI->ArgStructAlign = 0;
754 FI->NumArgs = argTypes.size();
755 FI->HasExtParameterInfos = !paramInfos.empty();
756 FI->getArgsBuffer()[0].
type = resultType;
757 for (
unsigned i = 0, e = argTypes.size(); i != e; ++i)
758 FI->getArgsBuffer()[i + 1].
type = argTypes[i];
759 for (
unsigned i = 0, e = paramInfos.size(); i != e; ++i)
760 FI->getExtParameterInfosBuffer()[i] = paramInfos[i];
770 struct TypeExpansion {
771 enum TypeExpansionKind {
783 const TypeExpansionKind
Kind;
785 TypeExpansion(TypeExpansionKind K) :
Kind(K) {}
786 virtual ~TypeExpansion() {}
789 struct ConstantArrayExpansion : TypeExpansion {
793 ConstantArrayExpansion(
QualType EltTy, uint64_t NumElts)
794 : TypeExpansion(TEK_ConstantArray), EltTy(EltTy), NumElts(NumElts) {}
795 static bool classof(
const TypeExpansion *TE) {
796 return TE->Kind == TEK_ConstantArray;
800 struct RecordExpansion : TypeExpansion {
807 : TypeExpansion(TEK_Record), Bases(std::move(Bases)),
808 Fields(std::move(Fields)) {}
809 static bool classof(
const TypeExpansion *TE) {
810 return TE->Kind == TEK_Record;
814 struct ComplexExpansion : TypeExpansion {
818 static bool classof(
const TypeExpansion *TE) {
823 struct NoExpansion : TypeExpansion {
824 NoExpansion() : TypeExpansion(TEK_None) {}
825 static bool classof(
const TypeExpansion *TE) {
826 return TE->Kind == TEK_None;
831 static std::unique_ptr<TypeExpansion>
834 return llvm::make_unique<ConstantArrayExpansion>(
835 AT->getElementType(), AT->getSize().getZExtValue());
842 "Cannot expand structure with flexible array.");
849 for (
const auto *FD : RD->
fields()) {
851 if (FD->isBitField() && FD->getBitWidthValue(Context) == 0)
853 assert(!FD->isBitField() &&
854 "Cannot expand structure with bit-field members.");
856 if (UnionSize < FieldSize) {
857 UnionSize = FieldSize;
862 Fields.push_back(LargestFD);
864 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
865 assert(!CXXRD->isDynamicClass() &&
866 "cannot expand vtable pointers in dynamic classes");
868 Bases.push_back(&BS);
871 for (
const auto *FD : RD->
fields()) {
873 if (FD->isBitField() && FD->getBitWidthValue(Context) == 0)
875 assert(!FD->isBitField() &&
876 "Cannot expand structure with bit-field members.");
877 Fields.push_back(FD);
880 return llvm::make_unique<RecordExpansion>(std::move(Bases),
884 return llvm::make_unique<ComplexExpansion>(CT->getElementType());
886 return llvm::make_unique<NoExpansion>();
891 if (
auto CAExp = dyn_cast<ConstantArrayExpansion>(Exp.get())) {
894 if (
auto RExp = dyn_cast<RecordExpansion>(Exp.get())) {
896 for (
auto BS : RExp->Bases)
898 for (
auto FD : RExp->Fields)
902 if (isa<ComplexExpansion>(Exp.get()))
904 assert(isa<NoExpansion>(Exp.get()));
912 if (
auto CAExp = dyn_cast<ConstantArrayExpansion>(Exp.get())) {
913 for (
int i = 0, n = CAExp->NumElts; i < n; i++) {
916 }
else if (
auto RExp = dyn_cast<RecordExpansion>(Exp.get())) {
917 for (
auto BS : RExp->Bases)
919 for (
auto FD : RExp->Fields)
921 }
else if (
auto CExp = dyn_cast<ComplexExpansion>(Exp.get())) {
926 assert(isa<NoExpansion>(Exp.get()));
932 ConstantArrayExpansion *CAE,
934 llvm::function_ref<
void(
Address)> Fn) {
939 for (
int i = 0, n = CAE->NumElts; i < n; i++) {
942 Fn(
Address(EltAddr, EltAlign));
946 void CodeGenFunction::ExpandTypeFromArgs(
949 "Unexpected non-simple lvalue during struct expansion.");
952 if (
auto CAExp = dyn_cast<ConstantArrayExpansion>(Exp.get())) {
956 ExpandTypeFromArgs(CAExp->EltTy, LV, AI);
958 }
else if (
auto RExp = dyn_cast<RecordExpansion>(Exp.get())) {
968 ExpandTypeFromArgs(BS->getType(), SubLV, AI);
970 for (
auto FD : RExp->Fields) {
973 ExpandTypeFromArgs(FD->getType(), SubLV, AI);
975 }
else if (isa<ComplexExpansion>(Exp.get())) {
976 auto realValue = *AI++;
977 auto imagValue = *AI++;
980 assert(isa<NoExpansion>(Exp.get()));
985 void CodeGenFunction::ExpandTypeToArgs(
989 if (
auto CAExp = dyn_cast<ConstantArrayExpansion>(Exp.get())) {
994 ExpandTypeToArgs(CAExp->EltTy, EltRV, IRFuncTy, IRCallArgs, IRCallArgPos);
996 }
else if (
auto RExp = dyn_cast<RecordExpansion>(Exp.get())) {
1006 ExpandTypeToArgs(BS->getType(), BaseRV, IRFuncTy, IRCallArgs,
1011 for (
auto FD : RExp->Fields) {
1013 ExpandTypeToArgs(FD->getType(), FldRV, IRFuncTy, IRCallArgs,
1016 }
else if (isa<ComplexExpansion>(Exp.get())) {
1018 IRCallArgs[IRCallArgPos++] = CV.first;
1019 IRCallArgs[IRCallArgPos++] = CV.second;
1021 assert(isa<NoExpansion>(Exp.get()));
1023 "Unexpected non-scalar rvalue during struct expansion.");
1027 if (IRCallArgPos < IRFuncTy->getNumParams() &&
1028 V->getType() != IRFuncTy->getParamType(IRCallArgPos))
1031 IRCallArgs[IRCallArgPos++] = V;
1051 llvm::StructType *SrcSTy,
1054 if (SrcSTy->getNumElements() == 0)
return SrcPtr;
1056 llvm::Type *FirstElt = SrcSTy->getElementType(0);
1062 uint64_t FirstEltSize =
1064 if (FirstEltSize < DstSize &&
1073 if (llvm::StructType *SrcSTy = dyn_cast<llvm::StructType>(SrcTy))
1089 if (Val->getType() == Ty)
1092 if (isa<llvm::PointerType>(Val->getType())) {
1094 if (isa<llvm::PointerType>(Ty))
1102 if (isa<llvm::PointerType>(DestIntTy))
1105 if (Val->getType() != DestIntTy) {
1107 if (DL.isBigEndian()) {
1110 uint64_t SrcSize = DL.getTypeSizeInBits(Val->getType());
1111 uint64_t DstSize = DL.getTypeSizeInBits(DestIntTy);
1113 if (SrcSize > DstSize) {
1114 Val = CGF.
Builder.CreateLShr(Val, SrcSize - DstSize,
"coerce.highbits");
1115 Val = CGF.
Builder.CreateTrunc(Val, DestIntTy,
"coerce.val.ii");
1117 Val = CGF.
Builder.CreateZExt(Val, DestIntTy,
"coerce.val.ii");
1118 Val = CGF.
Builder.CreateShl(Val, DstSize - SrcSize,
"coerce.highbits");
1122 Val = CGF.
Builder.CreateIntCast(Val, DestIntTy,
false,
"coerce.val.ii");
1126 if (isa<llvm::PointerType>(Ty))
1127 Val = CGF.
Builder.CreateIntToPtr(Val, Ty,
"coerce.val.ip");
1150 if (llvm::StructType *SrcSTy = dyn_cast<llvm::StructType>(SrcTy)) {
1152 SrcTy = Src.
getType()->getElementType();
1159 if ((isa<llvm::IntegerType>(Ty) || isa<llvm::PointerType>(Ty)) &&
1160 (isa<llvm::IntegerType>(SrcTy) || isa<llvm::PointerType>(SrcTy))) {
1166 if (SrcSize >= DstSize) {
1182 llvm::ConstantInt::get(CGF.
IntPtrTy, SrcSize),
1192 Address Dest,
bool DestIsVolatile) {
1194 if (llvm::StructType *STy =
1195 dyn_cast<llvm::StructType>(Val->getType())) {
1196 const llvm::StructLayout *Layout =
1199 for (
unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
1222 if (SrcTy == DstTy) {
1229 if (llvm::StructType *DstSTy = dyn_cast<llvm::StructType>(DstTy)) {
1231 DstTy = Dst.
getType()->getElementType();
1236 if ((isa<llvm::IntegerType>(SrcTy) || isa<llvm::PointerType>(SrcTy)) &&
1237 (isa<llvm::IntegerType>(DstTy) || isa<llvm::PointerType>(DstTy))) {
1246 if (SrcSize <= DstSize) {
1264 llvm::ConstantInt::get(CGF.
IntPtrTy, DstSize),
1284 class ClangToLLVMArgMapping {
1285 static const unsigned InvalidIndex = ~0U;
1286 unsigned InallocaArgNo;
1288 unsigned TotalIRArgs;
1292 unsigned PaddingArgIndex;
1295 unsigned FirstArgIndex;
1296 unsigned NumberOfArgs;
1299 : PaddingArgIndex(InvalidIndex), FirstArgIndex(InvalidIndex),
1307 bool OnlyRequiredArgs =
false)
1308 : InallocaArgNo(InvalidIndex), SRetArgNo(InvalidIndex), TotalIRArgs(0),
1309 ArgInfo(OnlyRequiredArgs ? FI.getNumRequiredArgs() : FI.arg_size()) {
1310 construct(Context, FI, OnlyRequiredArgs);
1313 bool hasInallocaArg()
const {
return InallocaArgNo != InvalidIndex; }
1314 unsigned getInallocaArgNo()
const {
1315 assert(hasInallocaArg());
1316 return InallocaArgNo;
1319 bool hasSRetArg()
const {
return SRetArgNo != InvalidIndex; }
1320 unsigned getSRetArgNo()
const {
1321 assert(hasSRetArg());
1325 unsigned totalIRArgs()
const {
return TotalIRArgs; }
1327 bool hasPaddingArg(
unsigned ArgNo)
const {
1328 assert(ArgNo < ArgInfo.size());
1329 return ArgInfo[ArgNo].PaddingArgIndex != InvalidIndex;
1331 unsigned getPaddingArgNo(
unsigned ArgNo)
const {
1332 assert(hasPaddingArg(ArgNo));
1333 return ArgInfo[ArgNo].PaddingArgIndex;
1338 std::pair<unsigned, unsigned> getIRArgs(
unsigned ArgNo)
const {
1339 assert(ArgNo < ArgInfo.size());
1340 return std::make_pair(ArgInfo[ArgNo].FirstArgIndex,
1341 ArgInfo[ArgNo].NumberOfArgs);
1346 bool OnlyRequiredArgs);
1351 bool OnlyRequiredArgs) {
1352 unsigned IRArgNo = 0;
1353 bool SwapThisWithSRet =
false;
1358 SRetArgNo = SwapThisWithSRet ? 1 : IRArgNo++;
1369 auto &IRArgs = ArgInfo[ArgNo];
1372 IRArgs.PaddingArgIndex = IRArgNo++;
1378 llvm::StructType *STy = dyn_cast<llvm::StructType>(AI.
getCoerceToType());
1380 IRArgs.NumberOfArgs = STy->getNumElements();
1382 IRArgs.NumberOfArgs = 1;
1387 IRArgs.NumberOfArgs = 1;
1392 IRArgs.NumberOfArgs = 0;
1402 if (IRArgs.NumberOfArgs > 0) {
1403 IRArgs.FirstArgIndex = IRArgNo;
1404 IRArgNo += IRArgs.NumberOfArgs;
1409 if (IRArgNo == 1 && SwapThisWithSRet)
1412 assert(ArgNo == ArgInfo.size());
1415 InallocaArgNo = IRArgNo++;
1417 TotalIRArgs = IRArgNo;
1434 switch (BT->getKind()) {
1437 case BuiltinType::Float:
1439 case BuiltinType::Double:
1441 case BuiltinType::LongDouble:
1452 if (BT->getKind() == BuiltinType::LongDouble)
1465 llvm::FunctionType *
1468 bool Inserted = FunctionsBeingProcessed.insert(&FI).second;
1470 assert(Inserted &&
"Recursively being processed?");
1476 llvm_unreachable(
"Invalid ABI kind for return argument");
1489 resultType = llvm::PointerType::get(ty, addressSpace);
1505 ClangToLLVMArgMapping IRFunctionArgs(
getContext(), FI,
true);
1509 if (IRFunctionArgs.hasSRetArg()) {
1513 ArgTypes[IRFunctionArgs.getSRetArgNo()] =
1514 llvm::PointerType::get(Ty, AddressSpace);
1518 if (IRFunctionArgs.hasInallocaArg()) {
1521 ArgTypes[IRFunctionArgs.getInallocaArgNo()] = ArgStruct->getPointerTo();
1528 for (; it != ie; ++it, ++ArgNo) {
1532 if (IRFunctionArgs.hasPaddingArg(ArgNo))
1533 ArgTypes[IRFunctionArgs.getPaddingArgNo(ArgNo)] =
1536 unsigned FirstIRArg, NumIRArgs;
1537 std::tie(FirstIRArg, NumIRArgs) = IRFunctionArgs.getIRArgs(ArgNo);
1542 assert(NumIRArgs == 0);
1546 assert(NumIRArgs == 1);
1549 ArgTypes[FirstIRArg] = LTy->getPointerTo();
1558 llvm::StructType *st = dyn_cast<llvm::StructType>(argType);
1560 assert(NumIRArgs == st->getNumElements());
1561 for (
unsigned i = 0, e = st->getNumElements(); i != e; ++i)
1562 ArgTypes[FirstIRArg + i] = st->getElementType(i);
1564 assert(NumIRArgs == 1);
1565 ArgTypes[FirstIRArg] = argType;
1571 auto ArgTypesIter = ArgTypes.begin() + FirstIRArg;
1573 *ArgTypesIter++ = EltTy;
1575 assert(ArgTypesIter == ArgTypes.begin() + FirstIRArg + NumIRArgs);
1580 auto ArgTypesIter = ArgTypes.begin() + FirstIRArg;
1582 assert(ArgTypesIter == ArgTypes.begin() + FirstIRArg + NumIRArgs);
1587 bool Erased = FunctionsBeingProcessed.erase(&FI); (void)Erased;
1588 assert(Erased &&
"Not in set?");
1590 return llvm::FunctionType::get(resultType, ArgTypes, FI.
isVariadic());
1601 if (isa<CXXDestructorDecl>(MD))
1610 llvm::AttrBuilder &FuncAttrs,
1617 FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
1623 llvm::AttrBuilder FuncAttrs;
1624 llvm::AttrBuilder RetAttrs;
1625 bool HasOptnone =
false;
1630 FuncAttrs.addAttribute(llvm::Attribute::NoReturn);
1639 bool HasAnyX86InterruptAttr =
false;
1642 if (TargetDecl->hasAttr<ReturnsTwiceAttr>())
1643 FuncAttrs.addAttribute(llvm::Attribute::ReturnsTwice);
1644 if (TargetDecl->hasAttr<NoThrowAttr>())
1645 FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
1646 if (TargetDecl->hasAttr<NoReturnAttr>())
1647 FuncAttrs.addAttribute(llvm::Attribute::NoReturn);
1648 if (TargetDecl->hasAttr<NoDuplicateAttr>())
1649 FuncAttrs.addAttribute(llvm::Attribute::NoDuplicate);
1651 if (
const FunctionDecl *Fn = dyn_cast<FunctionDecl>(TargetDecl)) {
1657 if (Fn->isNoReturn() && !(AttrOnCallSite && MD && MD->
isVirtual()))
1658 FuncAttrs.addAttribute(llvm::Attribute::NoReturn);
1662 if (TargetDecl->hasAttr<ConstAttr>()) {
1663 FuncAttrs.addAttribute(llvm::Attribute::ReadNone);
1664 FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
1665 }
else if (TargetDecl->hasAttr<PureAttr>()) {
1666 FuncAttrs.addAttribute(llvm::Attribute::ReadOnly);
1667 FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
1668 }
else if (TargetDecl->hasAttr<NoAliasAttr>()) {
1669 FuncAttrs.addAttribute(llvm::Attribute::ArgMemOnly);
1670 FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
1672 if (TargetDecl->hasAttr<RestrictAttr>())
1673 RetAttrs.addAttribute(llvm::Attribute::NoAlias);
1674 if (TargetDecl->hasAttr<ReturnsNonNullAttr>())
1675 RetAttrs.addAttribute(llvm::Attribute::NonNull);
1677 HasAnyX86InterruptAttr = TargetDecl->hasAttr<AnyX86InterruptAttr>();
1678 HasOptnone = TargetDecl->hasAttr<OptimizeNoneAttr>();
1683 if (CodeGenOpts.OptimizeSize)
1684 FuncAttrs.addAttribute(llvm::Attribute::OptimizeForSize);
1685 if (CodeGenOpts.OptimizeSize == 2)
1686 FuncAttrs.addAttribute(llvm::Attribute::MinSize);
1689 if (CodeGenOpts.DisableRedZone)
1690 FuncAttrs.addAttribute(llvm::Attribute::NoRedZone);
1691 if (CodeGenOpts.NoImplicitFloat)
1692 FuncAttrs.addAttribute(llvm::Attribute::NoImplicitFloat);
1693 if (CodeGenOpts.EnableSegmentedStacks &&
1694 !(TargetDecl && TargetDecl->hasAttr<NoSplitStackAttr>()))
1695 FuncAttrs.addAttribute(
"split-stack");
1697 if (AttrOnCallSite) {
1699 if (!CodeGenOpts.SimplifyLibCalls ||
1701 FuncAttrs.addAttribute(llvm::Attribute::NoBuiltin);
1703 FuncAttrs.addAttribute(
"trap-func-name", CodeGenOpts.
TrapFuncName);
1706 if (!CodeGenOpts.DisableFPElim) {
1707 FuncAttrs.addAttribute(
"no-frame-pointer-elim",
"false");
1708 }
else if (CodeGenOpts.OmitLeafFramePointer) {
1709 FuncAttrs.addAttribute(
"no-frame-pointer-elim",
"false");
1710 FuncAttrs.addAttribute(
"no-frame-pointer-elim-non-leaf");
1712 FuncAttrs.addAttribute(
"no-frame-pointer-elim",
"true");
1713 FuncAttrs.addAttribute(
"no-frame-pointer-elim-non-leaf");
1716 bool DisableTailCalls =
1717 CodeGenOpts.DisableTailCalls || HasAnyX86InterruptAttr ||
1718 (TargetDecl && TargetDecl->hasAttr<DisableTailCallsAttr>());
1719 FuncAttrs.addAttribute(
1720 "disable-tail-calls",
1721 llvm::toStringRef(DisableTailCalls));
1723 FuncAttrs.addAttribute(
"less-precise-fpmad",
1724 llvm::toStringRef(CodeGenOpts.LessPreciseFPMAD));
1725 FuncAttrs.addAttribute(
"no-infs-fp-math",
1726 llvm::toStringRef(CodeGenOpts.NoInfsFPMath));
1727 FuncAttrs.addAttribute(
"no-nans-fp-math",
1728 llvm::toStringRef(CodeGenOpts.NoNaNsFPMath));
1729 FuncAttrs.addAttribute(
"unsafe-fp-math",
1730 llvm::toStringRef(CodeGenOpts.UnsafeFPMath));
1731 FuncAttrs.addAttribute(
"use-soft-float",
1732 llvm::toStringRef(CodeGenOpts.SoftFloat));
1733 FuncAttrs.addAttribute(
"stack-protector-buffer-size",
1734 llvm::utostr(CodeGenOpts.SSPBufferSize));
1735 FuncAttrs.addAttribute(
"no-signed-zeros-fp-math",
1736 llvm::toStringRef(CodeGenOpts.NoSignedZeros));
1738 if (CodeGenOpts.StackRealignment)
1739 FuncAttrs.addAttribute(
"stackrealign");
1740 if (CodeGenOpts.Backchain)
1741 FuncAttrs.addAttribute(
"backchain");
1747 const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(TargetDecl);
1748 if (FD && FD->hasAttr<TargetAttr>()) {
1749 llvm::StringMap<bool> FeatureMap;
1753 std::vector<std::string> Features;
1754 for (llvm::StringMap<bool>::const_iterator it = FeatureMap.begin(),
1755 ie = FeatureMap.end();
1757 Features.push_back((it->second ?
"+" :
"-") + it->first().str());
1763 const auto *TD = FD->getAttr<TargetAttr>();
1764 TargetAttr::ParsedTargetAttr ParsedAttr = TD->parse();
1765 if (ParsedAttr.second !=
"")
1766 TargetCPU = ParsedAttr.second;
1767 if (TargetCPU !=
"")
1768 FuncAttrs.addAttribute(
"target-cpu", TargetCPU);
1769 if (!Features.empty()) {
1770 std::sort(Features.begin(), Features.end());
1771 FuncAttrs.addAttribute(
1773 llvm::join(Features.begin(), Features.end(),
","));
1779 if (TargetCPU !=
"")
1780 FuncAttrs.addAttribute(
"target-cpu", TargetCPU);
1781 if (!Features.empty()) {
1782 std::sort(Features.begin(), Features.end());
1783 FuncAttrs.addAttribute(
1785 llvm::join(Features.begin(), Features.end(),
","));
1795 FuncAttrs.addAttribute(llvm::Attribute::Convergent);
1799 FuncAttrs.addAttribute(
"nvptx-f32ftz",
"true");
1802 ClangToLLVMArgMapping IRFunctionArgs(
getContext(), FI);
1809 RetAttrs.addAttribute(llvm::Attribute::SExt);
1811 RetAttrs.addAttribute(llvm::Attribute::ZExt);
1815 RetAttrs.addAttribute(llvm::Attribute::InReg);
1823 FuncAttrs.removeAttribute(llvm::Attribute::ReadOnly)
1824 .removeAttribute(llvm::Attribute::ReadNone);
1832 llvm_unreachable(
"Invalid ABI kind for return argument");
1838 RetAttrs.addDereferenceableAttr(
getContext().getTypeSizeInChars(PTy)
1840 else if (
getContext().getTargetAddressSpace(PTy) == 0)
1841 RetAttrs.addAttribute(llvm::Attribute::NonNull);
1845 if (RetAttrs.hasAttributes()) {
1846 PAL.push_back(llvm::AttributeSet::get(
1850 bool hasUsedSRet =
false;
1853 if (IRFunctionArgs.hasSRetArg()) {
1854 llvm::AttrBuilder SRETAttrs;
1855 SRETAttrs.addAttribute(llvm::Attribute::StructRet);
1858 SRETAttrs.addAttribute(llvm::Attribute::InReg);
1859 PAL.push_back(llvm::AttributeSet::get(
1860 getLLVMContext(), IRFunctionArgs.getSRetArgNo() + 1, SRETAttrs));
1864 if (IRFunctionArgs.hasInallocaArg()) {
1865 llvm::AttrBuilder Attrs;
1866 Attrs.addAttribute(llvm::Attribute::InAlloca);
1867 PAL.push_back(llvm::AttributeSet::get(
1868 getLLVMContext(), IRFunctionArgs.getInallocaArgNo() + 1, Attrs));
1874 I !=
E; ++
I, ++ArgNo) {
1877 llvm::AttrBuilder Attrs;
1880 if (IRFunctionArgs.hasPaddingArg(ArgNo)) {
1882 PAL.push_back(llvm::AttributeSet::get(
1884 llvm::Attribute::InReg));
1893 Attrs.addAttribute(llvm::Attribute::SExt);
1896 Attrs.addAttribute(llvm::Attribute::SExt);
1898 Attrs.addAttribute(llvm::Attribute::ZExt);
1903 Attrs.addAttribute(llvm::Attribute::Nest);
1905 Attrs.addAttribute(llvm::Attribute::InReg);
1910 Attrs.addAttribute(llvm::Attribute::InReg);
1913 Attrs.addAttribute(llvm::Attribute::ByVal);
1935 FuncAttrs.removeAttribute(llvm::Attribute::ReadOnly)
1936 .removeAttribute(llvm::Attribute::ReadNone);
1946 FuncAttrs.removeAttribute(llvm::Attribute::ReadOnly)
1947 .removeAttribute(llvm::Attribute::ReadNone);
1954 Attrs.addDereferenceableAttr(
getContext().getTypeSizeInChars(PTy)
1956 else if (
getContext().getTargetAddressSpace(PTy) == 0)
1957 Attrs.addAttribute(llvm::Attribute::NonNull);
1968 Attrs.addAttribute(llvm::Attribute::StructRet);
1973 Attrs.addAttribute(llvm::Attribute::NoAlias);
1977 if (!PTy->isIncompleteType() && PTy->isConstantSizeType()) {
1979 Attrs.addDereferenceableAttr(info.first.getQuantity());
1980 Attrs.addAttribute(llvm::Attribute::getWithAlignment(
getLLVMContext(),
1981 info.second.getQuantity()));
1987 Attrs.addAttribute(llvm::Attribute::SwiftError);
1991 Attrs.addAttribute(llvm::Attribute::SwiftSelf);
1995 if (Attrs.hasAttributes()) {
1996 unsigned FirstIRArg, NumIRArgs;
1997 std::tie(FirstIRArg, NumIRArgs) = IRFunctionArgs.getIRArgs(ArgNo);
1998 for (
unsigned i = 0; i < NumIRArgs; i++)
2000 FirstIRArg + i + 1, Attrs));
2005 if (FuncAttrs.hasAttributes())
2006 PAL.push_back(llvm::
2008 llvm::AttributeSet::FunctionIndex,
2021 if (value->getType() == varType)
return value;
2023 assert((varType->isIntegerTy() || varType->isFloatingPointTy())
2024 &&
"unexpected promotion type");
2026 if (isa<llvm::IntegerType>(varType))
2027 return CGF.
Builder.CreateTrunc(value, varType,
"arg.unpromote");
2029 return CGF.
Builder.CreateFPCast(value, varType,
"arg.unpromote");
2035 QualType ArgType,
unsigned ArgNo) {
2047 if (
auto ParmNNAttr = PVD->getAttr<NonNullAttr>())
2053 for (
const auto *NNAttr : FD->specific_attrs<NonNullAttr>()) {
2054 if (NNAttr->isNonNull(ArgNo))
2064 CopyBackSwiftError(
Address temp,
Address arg) : Temp(temp), Arg(arg) {}
2084 if (FD->hasImplicitReturnZero()) {
2085 QualType RetTy = FD->getReturnType().getUnqualifiedType();
2087 llvm::Constant* Zero = llvm::Constant::getNullValue(LLVMTy);
2098 FnArgs.reserve(IRFunctionArgs.totalIRArgs());
2099 for (
auto &Arg : Fn->args()) {
2100 FnArgs.push_back(&Arg);
2102 assert(FnArgs.size() == IRFunctionArgs.totalIRArgs());
2107 const llvm::StructLayout *ArgStructLayout =
nullptr;
2108 if (IRFunctionArgs.hasInallocaArg()) {
2110 ArgStruct =
Address(FnArgs[IRFunctionArgs.getInallocaArgNo()],
2113 assert(ArgStruct.getType() == FI.
getArgStruct()->getPointerTo());
2117 if (IRFunctionArgs.hasSRetArg()) {
2118 auto AI = cast<llvm::Argument>(FnArgs[IRFunctionArgs.getSRetArgNo()]);
2119 AI->setName(
"agg.result");
2120 AI->addAttr(llvm::AttributeSet::get(
getLLVMContext(), AI->getArgNo() + 1,
2121 llvm::Attribute::NoAlias));
2128 ArgVals.reserve(Args.size());
2134 assert(FI.
arg_size() == Args.size() &&
2135 "Mismatch between function signature & arguments.");
2138 for (FunctionArgList::const_iterator i = Args.begin(), e = Args.end();
2139 i != e; ++i, ++info_it, ++ArgNo) {
2145 isa<ParmVarDecl>(Arg) && cast<ParmVarDecl>(Arg)->isKNRPromoted();
2147 unsigned FirstIRArg, NumIRArgs;
2148 std::tie(FirstIRArg, NumIRArgs) = IRFunctionArgs.getIRArgs(ArgNo);
2152 assert(NumIRArgs == 0);
2163 assert(NumIRArgs == 1);
2205 assert(NumIRArgs == 1);
2207 auto AI = cast<llvm::Argument>(V);
2209 if (
const ParmVarDecl *PVD = dyn_cast<ParmVarDecl>(Arg)) {
2211 PVD->getFunctionScopeIndex()))
2214 llvm::Attribute::NonNull));
2216 QualType OTy = PVD->getOriginalType();
2217 if (
const auto *ArrTy =
2224 QualType ETy = ArrTy->getElementType();
2225 uint64_t ArrSize = ArrTy->getSize().getZExtValue();
2228 llvm::AttrBuilder Attrs;
2229 Attrs.addDereferenceableAttr(
2230 getContext().getTypeSizeInChars(ETy).getQuantity()*ArrSize);
2232 AI->getArgNo() + 1, Attrs));
2236 llvm::Attribute::NonNull));
2239 }
else if (
const auto *ArrTy =
2248 llvm::Attribute::NonNull));
2251 const auto *AVAttr = PVD->getAttr<AlignValueAttr>();
2253 if (
const auto *TOTy = dyn_cast<TypedefType>(OTy))
2254 AVAttr = TOTy->getDecl()->getAttr<AlignValueAttr>();
2258 llvm::ConstantInt *AlignmentCI =
2259 cast<llvm::ConstantInt>(AlignmentValue);
2260 unsigned Alignment =
2261 std::min((
unsigned) AlignmentCI->getZExtValue(),
2262 +llvm::Value::MaximumAlignment);
2264 llvm::AttrBuilder Attrs;
2265 Attrs.addAlignmentAttr(Alignment);
2267 AI->getArgNo() + 1, Attrs));
2274 llvm::Attribute::NoAlias));
2287 V = temp.getPointer();
2304 if (MD->isVirtual() && Arg == CXXABIThisDecl)
2306 adjustThisParameterInVirtualFunctionPrologue(*
this,
CurGD, V);
2314 if (V->getType() != LTy)
2329 llvm::StructType *STy = dyn_cast<llvm::StructType>(ArgI.
getCoerceToType());
2331 STy->getNumElements() > 1) {
2338 if (SrcSize <= DstSize) {
2346 assert(STy->getNumElements() == NumIRArgs);
2347 for (
unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
2348 auto AI = FnArgs[FirstIRArg + i];
2349 AI->setName(Arg->
getName() +
".coerce" + Twine(i));
2356 if (SrcSize > DstSize) {
2362 assert(NumIRArgs == 1);
2363 auto AI = FnArgs[FirstIRArg];
2364 AI->setName(Arg->
getName() +
".coerce");
2390 unsigned argIndex = FirstIRArg;
2391 for (
unsigned i = 0, e = coercionType->getNumElements(); i != e; ++i) {
2392 llvm::Type *eltType = coercionType->getElementType(i);
2397 auto elt = FnArgs[argIndex++];
2400 assert(argIndex == FirstIRArg + NumIRArgs);
2412 auto FnArgIter = FnArgs.begin() + FirstIRArg;
2413 ExpandTypeFromArgs(Ty, LV, FnArgIter);
2414 assert(FnArgIter == FnArgs.begin() + FirstIRArg + NumIRArgs);
2415 for (
unsigned i = 0, e = NumIRArgs; i != e; ++i) {
2416 auto AI = FnArgs[FirstIRArg + i];
2417 AI->setName(Arg->
getName() +
"." + Twine(i));
2423 assert(NumIRArgs == 0);
2435 if (
getTarget().getCXXABI().areArgsDestroyedLeftToRightInCallee()) {
2436 for (
int I = Args.size() - 1;
I >= 0; --
I)
2439 for (
unsigned I = 0,
E = Args.size();
I !=
E; ++
I)
2445 while (insn->use_empty()) {
2446 llvm::BitCastInst *bitcast = dyn_cast<llvm::BitCastInst>(insn);
2447 if (!bitcast)
return;
2450 insn = cast<llvm::Instruction>(bitcast->getOperand(0));
2451 bitcast->eraseFromParent();
2459 llvm::BasicBlock *BB = CGF.
Builder.GetInsertBlock();
2460 if (BB->empty())
return nullptr;
2461 if (&BB->back() != result)
return nullptr;
2466 llvm::Instruction *generator = cast<llvm::Instruction>(result);
2472 while (llvm::BitCastInst *bitcast = dyn_cast<llvm::BitCastInst>(generator)) {
2475 generator = cast<llvm::Instruction>(bitcast->getOperand(0));
2478 if (generator->getNextNode() != bitcast)
2481 insnsToKill.push_back(bitcast);
2488 llvm::CallInst *call = dyn_cast<llvm::CallInst>(generator);
2489 if (!call)
return nullptr;
2491 bool doRetainAutorelease;
2494 doRetainAutorelease =
true;
2497 doRetainAutorelease =
false;
2505 llvm::Instruction *prev = call->getPrevNode();
2507 if (isa<llvm::BitCastInst>(prev)) {
2508 prev = prev->getPrevNode();
2511 assert(isa<llvm::CallInst>(prev));
2512 assert(cast<llvm::CallInst>(prev)->getCalledValue() ==
2514 insnsToKill.push_back(prev);
2520 result = call->getArgOperand(0);
2521 insnsToKill.push_back(call);
2525 while (llvm::BitCastInst *bitcast = dyn_cast<llvm::BitCastInst>(result)) {
2526 if (!bitcast->hasOneUse())
break;
2527 insnsToKill.push_back(bitcast);
2528 result = bitcast->getOperand(0);
2533 i = insnsToKill.begin(), e = insnsToKill.end(); i != e; ++i)
2534 (*i)->eraseFromParent();
2537 if (doRetainAutorelease)
2549 dyn_cast_or_null<ObjCMethodDecl>(CGF.
CurCodeDecl);
2550 if (!method)
return nullptr;
2552 if (!self->getType().isConstQualified())
return nullptr;
2555 llvm::CallInst *retainCall =
2556 dyn_cast<llvm::CallInst>(result->stripPointerCasts());
2562 llvm::Value *retainedValue = retainCall->getArgOperand(0);
2563 llvm::LoadInst *load =
2564 dyn_cast<llvm::LoadInst>(retainedValue->stripPointerCasts());
2565 if (!load || load->isAtomic() || load->isVolatile() ||
2574 assert(retainCall->use_empty());
2575 retainCall->eraseFromParent();
2606 auto GetStoreIfValid = [&CGF](llvm::User *U) -> llvm::StoreInst * {
2607 auto *SI = dyn_cast<llvm::StoreInst>(U);
2612 assert(!SI->isAtomic() && !SI->isVolatile());
2620 llvm::BasicBlock *IP = CGF.
Builder.GetInsertBlock();
2621 if (IP->empty())
return nullptr;
2622 llvm::Instruction *
I = &IP->back();
2625 for (llvm::BasicBlock::reverse_iterator II = IP->rbegin(),
2628 if (llvm::IntrinsicInst *Intrinsic =
2629 dyn_cast<llvm::IntrinsicInst>(&*II)) {
2630 if (Intrinsic->getIntrinsicID() == llvm::Intrinsic::lifetime_end) {
2631 const llvm::Value *CastAddr = Intrinsic->getArgOperand(1);
2635 if (isa<llvm::BitCastInst>(&*II) && (CastAddr == &*II))
2643 return GetStoreIfValid(I);
2646 llvm::StoreInst *store =
2648 if (!store)
return nullptr;
2652 llvm::BasicBlock *StoreBB = store->getParent();
2653 llvm::BasicBlock *IP = CGF.
Builder.GetInsertBlock();
2654 while (IP != StoreBB) {
2655 if (!(IP = IP->getSinglePredecessor()))
2679 llvm::DebugLoc RetDbgLoc;
2690 llvm::Function::arg_iterator EI =
CurFn->arg_end();
2700 auto AI =
CurFn->arg_begin();
2732 if (llvm::StoreInst *SI =
2738 RetDbgLoc = SI->getDebugLoc();
2740 RV = SI->getValueOperand();
2741 SI->eraseFromParent();
2745 if (returnValueInst->use_empty()) {
2746 if (
auto alloca = dyn_cast<llvm::AllocaInst>(returnValueInst)) {
2747 alloca->eraseFromParent();
2773 if (
auto *FD = dyn_cast<FunctionDecl>(
CurCodeDecl))
2774 RT = FD->getReturnType();
2775 else if (
auto *MD = dyn_cast<ObjCMethodDecl>(
CurCodeDecl))
2776 RT = MD->getReturnType();
2780 llvm_unreachable(
"Unexpected function/method type");
2801 for (
unsigned i = 0, e = coercionType->getNumElements(); i != e; ++i) {
2808 results.push_back(elt);
2812 if (results.size() == 1) {
2820 RV = llvm::UndefValue::get(returnType);
2821 for (
unsigned i = 0, e = results.size(); i != e; ++i) {
2822 RV =
Builder.CreateInsertValue(RV, results[i], i);
2829 llvm_unreachable(
"Invalid ABI kind for return argument");
2832 llvm::Instruction *Ret;
2835 if (
auto RetNNAttr =
CurCodeDecl->getAttr<ReturnsNonNullAttr>()) {
2838 RV, llvm::Constant::getNullValue(RV->getType()));
2839 llvm::Constant *StaticData[] = {
2843 EmitCheck(std::make_pair(Cond, SanitizerKind::ReturnsNonnullAttribute),
2844 "nonnull_return", StaticData,
None);
2849 Ret =
Builder.CreateRetVoid();
2853 Ret->setDebugLoc(std::move(RetDbgLoc));
2867 llvm::UndefValue::get(IRTy->getPointerTo()->getPointerTo());
2892 "cannot emit delegate call arguments for inalloca arguments!");
2903 return isa<llvm::ConstantPointerNull>(addr);
2907 return isa<llvm::AllocaInst>(addr);
2916 "shouldn't have writeback for provably null argument");
2918 llvm::BasicBlock *contBB =
nullptr;
2923 if (!provablyNonNull) {
2929 CGF.
Builder.CreateCondBr(isNull, contBB, writebackBB);
2938 "icr.writeback-cast");
2947 if (writeback.
ToUse) {
2972 if (!provablyNonNull)
2988 for (
const auto &
I : llvm::reverse(Cleanups)) {
2990 I.IsActiveIP->eraseFromParent();
2996 if (uop->getOpcode() == UO_AddrOf)
2997 return uop->getSubExpr();
3027 llvm::PointerType *destType =
3051 llvm::ConstantPointerNull::get(
3052 cast<llvm::PointerType>(destType->getElementType()));
3056 llvm::BasicBlock *contBB =
nullptr;
3057 llvm::BasicBlock *originBB =
nullptr;
3063 if (provablyNonNull) {
3069 finalArgument = CGF.
Builder.CreateSelect(isNull,
3070 llvm::ConstantPointerNull::get(destType),
3076 originBB = CGF.
Builder.GetInsertBlock();
3079 CGF.
Builder.CreateCondBr(isNull, contBB, copyBB);
3081 condEval.
begin(CGF);
3111 if (shouldCopy && !provablyNonNull) {
3112 llvm::BasicBlock *copyBB = CGF.
Builder.GetInsertBlock();
3117 llvm::PHINode *phiToUse = CGF.
Builder.CreatePHI(valueToUse->getType(), 2,
3119 phiToUse->addIncoming(valueToUse, copyBB);
3120 phiToUse->addIncoming(llvm::UndefValue::get(valueToUse->getType()),
3122 valueToUse = phiToUse;
3133 assert(!StackBase && !StackCleanup.isValid());
3137 StackBase = CGF.
Builder.CreateCall(F, {},
"inalloca.save");
3144 CGF.
Builder.CreateCall(F, StackBase);
3152 if (!
SanOpts.
has(SanitizerKind::NonnullAttribute) || !FD)
3155 unsigned ArgNo = PVD ? PVD->getFunctionScopeIndex() : ParmNum;
3163 Builder.CreateICmpNE(V, llvm::Constant::getNullValue(V->getType()));
3164 llvm::Constant *StaticData[] = {
3167 llvm::ConstantInt::get(
Int32Ty, ArgNo + 1),
3169 EmitCheck(std::make_pair(Cond, SanitizerKind::NonnullAttribute),
3170 "nonnull_arg", StaticData,
None);
3175 llvm::iterator_range<CallExpr::const_arg_iterator> ArgRange,
3176 const FunctionDecl *CalleeDecl,
unsigned ParamsToSkip) {
3177 assert((
int)ArgTypes.size() == (ArgRange.end() - ArgRange.begin()));
3179 auto MaybeEmitImplicitObjectSize = [&](
unsigned I,
const Expr *Arg) {
3180 if (CalleeDecl ==
nullptr || I >= CalleeDecl->
getNumParams())
3182 auto *PS = CalleeDecl->
getParamDecl(I)->getAttr<PassObjectSizeAttr>();
3189 llvm::Value *V = evaluateOrEmitBuiltinObjectSize(Arg, PS->getType(), T);
3197 bool HasInAllocaArgs =
false;
3199 I !=
E && !HasInAllocaArgs; ++
I)
3201 if (HasInAllocaArgs) {
3202 assert(
getTarget().getTriple().getArch() == llvm::Triple::x86);
3207 size_t CallArgsStart = Args.size();
3208 for (
int I = ArgTypes.size() - 1; I >= 0; --
I) {
3210 MaybeEmitImplicitObjectSize(I, *Arg);
3213 CalleeDecl, ParamsToSkip +
I);
3218 std::reverse(Args.begin() + CallArgsStart, Args.end());
3222 for (
unsigned I = 0,
E = ArgTypes.size(); I !=
E; ++
I) {
3224 assert(Arg != ArgRange.end());
3227 CalleeDecl, ParamsToSkip +
I);
3228 MaybeEmitImplicitObjectSize(I, *Arg);
3236 : Addr(Addr), Ty(Ty) {}
3249 struct DisableDebugLocationUpdates {
3251 bool disabledDebugInfo;
3253 if ((disabledDebugInfo = isa<CXXDefaultArgExpr>(E) && CGF.
getDebugInfo()))
3256 ~DisableDebugLocationUpdates() {
3257 if (disabledDebugInfo)
3266 DisableDebugLocationUpdates Dis(*
this, E);
3268 = dyn_cast<ObjCIndirectCopyRestoreExpr>(E)) {
3275 "reference binding to unmaterialized r-value!");
3287 if (HasAggregateEvalKind &&
3298 bool DestroyedInCallee =
3301 if (DestroyedInCallee)
3308 if (DestroyedInCallee) {
3315 llvm::Instruction *IsActive =
Builder.CreateUnreachable();
3321 if (HasAggregateEvalKind && isa<ImplicitCastExpr>(E) &&
3322 cast<CastExpr>(
E)->getCastKind() == CK_LValueToRValue) {
3340 QualType CodeGenFunction::getVarArgType(
const Expr *Arg) {
3344 if (!
getTarget().getTriple().isOSWindows())
3361 CodeGenFunction::AddObjCARCExceptionMetadata(llvm::Instruction *Inst) {
3364 Inst->setMetadata(
"clang.arc.no_objc_arc_exceptions",
3371 const llvm::Twine &name) {
3379 const llvm::Twine &name) {
3381 call->setDoesNotThrow();
3389 const llvm::Twine &name) {
3400 if (!CurrentFuncletPad)
3404 auto *CalleeFn = dyn_cast<llvm::Function>(Callee->stripPointerCasts());
3405 if (CalleeFn && CalleeFn->isIntrinsic() && CalleeFn->doesNotThrow())
3408 BundleList.emplace_back(
"funclet", CurrentFuncletPad);
3415 const llvm::Twine &name) {
3419 llvm::CallInst *call =
Builder.CreateCall(callee, args, BundleList, name);
3431 llvm::InvokeInst *invoke =
3437 invoke->setDoesNotReturn();
3440 llvm::CallInst *call =
Builder.CreateCall(callee, args, BundleList);
3441 call->setDoesNotReturn();
3450 const Twine &name) {
3458 const Twine &name) {
3469 const Twine &
Name) {
3474 llvm::Instruction *Inst;
3476 Inst =
Builder.CreateCall(Callee, Args, BundleList, Name);
3479 Inst =
Builder.CreateInvoke(Callee, ContBB, InvokeDest, Args, BundleList,
3487 AddObjCARCExceptionMetadata(Inst);
3489 return llvm::CallSite(Inst);
3502 void CodeGenFunction::deferPlaceholderReplacement(llvm::Instruction *Old,
3504 DeferredReplacements.push_back(std::make_pair(Old, New));
3512 llvm::Instruction **callOrInvoke) {
3520 llvm::FunctionType *IRFuncTy =
3521 cast<llvm::FunctionType>(
3522 cast<llvm::PointerType>(Callee->getType())->getElementType());
3527 const llvm::StructLayout *ArgMemoryLayout =
nullptr;
3528 if (llvm::StructType *ArgStruct = CallInfo.
getArgStruct()) {
3531 llvm::AllocaInst *AI;
3533 IP = IP->getNextNode();
3534 AI =
new llvm::AllocaInst(ArgStruct,
"argmem", IP);
3539 AI->setAlignment(Align.getQuantity());
3540 AI->setUsedWithInAlloca(
true);
3541 assert(AI->isUsedWithInAlloca() && !AI->isStaticAlloca());
3542 ArgMemory =
Address(AI, Align);
3546 auto createInAllocaStructGEP = [&](
unsigned FieldIndex) ->
Address {
3552 ClangToLLVMArgMapping IRFunctionArgs(
CGM.
getContext(), CallInfo);
3558 size_t UnusedReturnSize = 0;
3560 if (!ReturnValue.
isNull()) {
3568 UnusedReturnSize = size;
3571 if (IRFunctionArgs.hasSRetArg()) {
3572 IRCallArgs[IRFunctionArgs.getSRetArgNo()] = SRetPtr.getPointer();
3582 assert(CallInfo.
arg_size() == CallArgs.size() &&
3583 "Mismatch between function signature & arguments.");
3586 for (CallArgList::const_iterator
I = CallArgs.begin(), E = CallArgs.end();
3587 I !=
E; ++
I, ++info_it, ++ArgNo) {
3592 if (IRFunctionArgs.hasPaddingArg(ArgNo))
3593 IRCallArgs[IRFunctionArgs.getPaddingArgNo(ArgNo)] =
3596 unsigned FirstIRArg, NumIRArgs;
3597 std::tie(FirstIRArg, NumIRArgs) = IRFunctionArgs.getIRArgs(ArgNo);
3601 assert(NumIRArgs == 0);
3602 assert(
getTarget().getTriple().getArch() == llvm::Triple::x86);
3605 llvm::Instruction *Placeholder =
3607 CGBuilderTy::InsertPoint IP =
Builder.saveIP();
3608 Builder.SetInsertPoint(Placeholder);
3611 deferPlaceholderReplacement(Placeholder, Addr.
getPointer());
3615 unsigned AS = Addr.
getType()->getPointerAddressSpace();
3620 if (Addr.
getType() != MemType)
3629 assert(NumIRArgs == 1);
3649 const unsigned RVAddrSpace = Addr.
getType()->getAddressSpace();
3650 const unsigned ArgAddrSpace =
3651 (FirstIRArg < IRFuncTy->getNumParams()
3652 ? IRFuncTy->getParamType(FirstIRArg)->getPointerAddressSpace()
3656 llvm::getOrEnforceKnownAlignment(Addr.
getPointer(),
3673 assert(NumIRArgs == 0);
3681 assert(NumIRArgs == 1);
3692 assert(!swiftErrorTemp.
isValid() &&
"multiple swifterror args");
3694 QualType pointeeTy =
I->Ty->getPointeeType();
3701 cast<llvm::AllocaInst>(V)->setSwiftError(
true);
3709 V->getType()->isIntegerTy())
3714 if (FirstIRArg < IRFuncTy->getNumParams() &&
3715 V->getType() != IRFuncTy->getParamType(FirstIRArg))
3718 IRCallArgs[FirstIRArg] = V;
3737 llvm::StructType *STy =
3748 if (SrcSize < DstSize) {
3759 assert(NumIRArgs == STy->getNumElements());
3760 for (
unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
3764 IRCallArgs[FirstIRArg + i] = LI;
3768 assert(NumIRArgs == 1);
3769 IRCallArgs[FirstIRArg] =
3791 tempSize = llvm::ConstantInt::get(
CGM.
Int64Ty, scalarSize);
3804 unsigned IRArgPos = FirstIRArg;
3805 for (
unsigned i = 0, e = coercionType->getNumElements(); i != e; ++i) {
3806 llvm::Type *eltType = coercionType->getElementType(i);
3810 IRCallArgs[IRArgPos++] = elt;
3812 assert(IRArgPos == FirstIRArg + NumIRArgs);
3822 unsigned IRArgPos = FirstIRArg;
3823 ExpandTypeToArgs(
I->Ty, RV, IRFuncTy, IRCallArgs, IRArgPos);
3824 assert(IRArgPos == FirstIRArg + NumIRArgs);
3829 if (ArgMemory.isValid()) {
3837 cast<llvm::PointerType>(Callee->getType())->getAddressSpace();
3839 Callee,
getTypes().GetFunctionType(CallInfo)->getPointerTo(CalleeAS));
3842 IRFuncTy->getParamType(IRFuncTy->getNumParams() - 1);
3843 if (Arg->getType() != LastParamTy) {
3847 llvm::StructType *DeclaredTy = cast<llvm::StructType>(
3848 cast<llvm::PointerType>(LastParamTy)->getElementType());
3849 assert(DeclaredTy->getNumElements() == FullTy->getNumElements());
3850 for (llvm::StructType::element_iterator DI = DeclaredTy->element_begin(),
3851 DE = DeclaredTy->element_end(),
3852 FI = FullTy->element_begin();
3853 DI != DE; ++DI, ++FI)
3859 assert(IRFunctionArgs.hasInallocaArg());
3860 IRCallArgs[IRFunctionArgs.getInallocaArgNo()] = Arg;
3869 if (llvm::ConstantExpr *CE = dyn_cast<llvm::ConstantExpr>(Callee))
3870 if (llvm::Function *CalleeF = dyn_cast<llvm::Function>(CE->getOperand(0))) {
3871 llvm::PointerType *CurPT=cast<llvm::PointerType>(Callee->getType());
3872 llvm::FunctionType *CurFT =
3873 cast<llvm::FunctionType>(CurPT->getElementType());
3874 llvm::FunctionType *ActualFT = CalleeF->getFunctionType();
3876 if (CE->getOpcode() == llvm::Instruction::BitCast &&
3877 ActualFT->getReturnType() == CurFT->getReturnType() &&
3878 ActualFT->getNumParams() == CurFT->getNumParams() &&
3879 ActualFT->getNumParams() == IRCallArgs.size() &&
3880 (CurFT->isVarArg() || !ActualFT->isVarArg())) {
3881 bool ArgsMatch =
true;
3882 for (
unsigned i = 0, e = ActualFT->getNumParams(); i != e; ++i)
3883 if (ActualFT->getParamType(i) != CurFT->getParamType(i)) {
3896 assert(IRCallArgs.size() == IRFuncTy->getNumParams() || IRFuncTy->isVarArg());
3897 for (
unsigned i = 0; i < IRCallArgs.size(); ++i) {
3899 if (IRFunctionArgs.hasInallocaArg() &&
3900 i == IRFunctionArgs.getInallocaArgNo())
3902 if (i < IRFuncTy->getNumParams())
3903 assert(IRCallArgs[i]->getType() == IRFuncTy->getParamType(i));
3911 llvm::AttributeSet Attrs = llvm::AttributeSet::get(
getLLVMContext(),
3917 CannotThrow =
false;
3925 CannotThrow = Attrs.hasAttribute(llvm::AttributeSet::FunctionIndex,
3926 llvm::Attribute::NoUnwind);
3928 llvm::BasicBlock *InvokeDest = CannotThrow ?
nullptr :
getInvokeDest();
3935 CS =
Builder.CreateCall(Callee, IRCallArgs, BundleList);
3938 CS =
Builder.CreateInvoke(Callee, Cont, InvokeDest, IRCallArgs,
3943 *callOrInvoke = CS.getInstruction();
3946 !CS.hasFnAttr(llvm::Attribute::NoInline))
3948 Attrs.addAttribute(
getLLVMContext(), llvm::AttributeSet::FunctionIndex,
3949 llvm::Attribute::AlwaysInline);
3954 Attrs.addAttribute(
getLLVMContext(), llvm::AttributeSet::FunctionIndex,
3955 llvm::Attribute::NoInline);
3957 CS.setAttributes(Attrs);
3958 CS.setCallingConv(static_cast<llvm::CallingConv::ID>(CallingConv));
3963 if (!CS.getCalledFunction())
3965 CS.getInstruction(), Callee);
3970 AddObjCARCExceptionMetadata(CS.getInstruction());
3975 if (CS.doesNotReturn()) {
3976 if (UnusedReturnSize)
3978 SRetPtr.getPointer());
3981 Builder.ClearInsertionPoint();
3992 llvm::Instruction *CI = CS.getInstruction();
3993 if (!CI->getType()->isVoidTy())
3994 CI->setName(
"call");
3997 if (swiftErrorTemp.
isValid()) {
4011 if (llvm::CallInst *Call = dyn_cast<llvm::CallInst>(CI)) {
4012 const Decl *TargetDecl = CalleeInfo.getCalleeDecl();
4013 if (TargetDecl && TargetDecl->hasAttr<NotTailCalledAttr>())
4014 Call->setTailCallKind(llvm::CallInst::TCK_NoTail);
4027 bool requiresExtract = isa<llvm::StructType>(CI->getType());
4029 unsigned unpaddedIndex = 0;
4030 for (
unsigned i = 0, e = coercionType->getNumElements(); i != e; ++i) {
4031 llvm::Type *eltType = coercionType->getElementType(i);
4035 if (requiresExtract)
4036 elt =
Builder.CreateExtractValue(elt, unpaddedIndex++);
4038 assert(unpaddedIndex == 0);
4047 if (UnusedReturnSize)
4049 SRetPtr.getPointer());
4070 bool DestIsVolatile = ReturnValue.
isVolatile();
4074 DestIsVolatile =
false;
4083 if (V->getType() != RetIRTy)
4088 llvm_unreachable(
"bad evaluation kind");
4092 bool DestIsVolatile = ReturnValue.
isVolatile();
4096 DestIsVolatile =
false;
4107 llvm_unreachable(
"Invalid ABI kind for return argument");
4110 llvm_unreachable(
"Unhandled ABIArgInfo::Kind");
4113 const Decl *TargetDecl = CalleeInfo.getCalleeDecl();
4115 if (Ret.
isScalar() && TargetDecl) {
4116 if (
const auto *AA = TargetDecl->getAttr<AssumeAlignedAttr>()) {
4118 if (
const auto *
Offset = AA->getOffset())
4122 llvm::ConstantInt *AlignmentCI = cast<llvm::ConstantInt>(Alignment);
const CGFunctionInfo & arrangeBuiltinFunctionDeclaration(QualType resultType, const FunctionArgList &args)
A builtin function is a freestanding function using the default C conventions.
static CanQual< Type > CreateUnsafe(QualType Other)
Builds a canonical type from a QualType.
ObjCIndirectCopyRestoreExpr - Represents the passing of a function argument by indirect copy-restore ...
Ignore - Ignore the argument (treat as void).
ReturnValueSlot - Contains the address where the return value of a function can be stored...
bool useObjCFP2RetForComplexLongDouble() const
Check whether _Complex long double should use the "fp2ret" flavor of Objective-C message passing on t...
ExprObjectKind getObjectKind() const
getObjectKind - The object kind that this expression produces.
void getExpandedTypes(QualType Ty, SmallVectorImpl< llvm::Type * >::iterator &TI)
getExpandedTypes - Expand the type
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
void end(CodeGenFunction &CGF)
const CGFunctionInfo & arrangeBlockFunctionDeclaration(const FunctionProtoType *type, const FunctionArgList &args)
Block invocation functions are C functions with an implicit parameter.
void EmitCallArgs(CallArgList &Args, const T *CallArgTypeInfo, llvm::iterator_range< CallExpr::const_arg_iterator > ArgRange, const FunctionDecl *CalleeDecl=nullptr, unsigned ParamsToSkip=0)
EmitCallArgs - Emit call arguments for a function.
StringRef getName() const
getName - Get the name of identifier for this declaration as a StringRef.
ObjCEntrypoints & getObjCEntrypoints() const
PointerType - C99 6.7.5.1 - Pointer Declarators.
A (possibly-)qualified type.
bool useObjCFPRetForRealType(RealType T) const
Check whether the given real type should use the "fpret" flavor of Objective-C message passing on thi...
bool isCanonicalAsParam() const
Determines if this canonical type is furthermore canonical as a parameter.
bool ReturnTypeUsesSRet(const CGFunctionInfo &FI)
Return true iff the given type uses 'sret' when used as a return type.
CodeGenTypes & getTypes()
llvm::Type * ConvertTypeForMem(QualType T)
CanQualType getReturnType() const
ExtInfo withCallingConv(CallingConv cc) const
static CanQual< FunctionProtoType > GetFormalType(const CXXMethodDecl *MD)
Returns the canonical formal type of the given C++ method.
CXXCtorType getCtorType() const
unsigned getInAllocaFieldIndex() const
static void emitWriteback(CodeGenFunction &CGF, const CallArgList::Writeback &writeback)
Emit the actual writing-back of a writeback.
llvm::LLVMContext & getLLVMContext()
static Address CreateTempAllocaForCoercion(CodeGenFunction &CGF, llvm::Type *Ty, CharUnits MinAlign)
Create a temporary allocation for the purposes of coercion.
static llvm::Value * emitAutoreleaseOfResult(CodeGenFunction &CGF, llvm::Value *result)
Emit an ARC autorelease of the result of a function.
static const CGFunctionInfo & arrangeFreeFunctionLikeCall(CodeGenTypes &CGT, CodeGenModule &CGM, const CallArgList &args, const FunctionType *fnType, unsigned numExtraRequiredArgs, bool chainCall)
Arrange a call as unto a free function, except possibly with an additional number of formal parameter...
CanQual< T > getUnqualifiedType() const
Retrieve the unqualified form of this type.
FunctionType - C99 6.7.5.3 - Function Declarators.
const TargetInfo & getTarget() const
const CGFunctionInfo & arrangeFreeFunctionType(CanQual< FunctionProtoType > Ty, const FunctionDecl *FD)
Arrange the argument and result information for a value of the given freestanding function type...
CanQualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
std::pair< llvm::Value *, llvm::Value * > getComplexVal() const
getComplexVal - Return the real/imag components of this complex value.
bool isCoerceAndExpand() const
void EmitNonNullArgCheck(RValue RV, QualType ArgType, SourceLocation ArgLoc, const FunctionDecl *FD, unsigned ParmNum)
Create a check for a function parameter that may potentially be declared as non-null.
llvm::AllocaInst * CreateTempAlloca(llvm::Type *Ty, const Twine &Name="tmp")
CreateTempAlloca - This creates a alloca and inserts it into the entry block.
Extend - Valid only for integer argument types.
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
Address EmitVAArg(VAArgExpr *VE, Address &VAListAddr)
Generate code to get an argument from the passed in pointer and update it accordingly.
static bool isProvablyNull(llvm::Value *addr)
llvm::LoadInst * CreateDefaultAlignedLoad(llvm::Value *Addr, const llvm::Twine &Name="")
Address getAddress() const
const CGFunctionInfo & arrangeCXXMethodType(const CXXRecordDecl *RD, const FunctionProtoType *FTP, const CXXMethodDecl *MD)
Arrange the argument and result information for a call to an unknown C++ non-static member function o...
const Decl * CurCodeDecl
CurCodeDecl - This is the inner-most code context, which includes blocks.
Direct - Pass the argument directly using the normal converted LLVM type, or by coercing to another s...
bool hasNonTrivialDestructor() const
Determine whether this class has a non-trivial destructor (C++ [class.dtor]p3)
llvm::CallingConv::ID getRuntimeCC() const
bool hasFlexibleArrayMember() const
ASTContext & getContext() const
const llvm::DataLayout & getDataLayout() const
bool hasExtParameterInfos() const
Is there any interesting extra information for any of the parameters of this function type...
The base class of the type hierarchy.
void EmitStoreThroughLValue(RValue Src, LValue Dst, bool isInit=false)
EmitStoreThroughLValue - Store the specified rvalue into the specified lvalue, where both are guarant...
RValue asAggregateRValue() const
static const NonNullAttr * getNonNullAttr(const Decl *FD, const ParmVarDecl *PVD, QualType ArgType, unsigned ArgNo)
Returns the attribute (either parameter attribute, or function attribute), which declares argument Ar...
static int getExpansionSize(QualType Ty, const ASTContext &Context)
bool isFuncTypeConvertible(const FunctionType *FT)
isFuncTypeConvertible - Utility to check whether a function type can be converted to an LLVM type (i...
const LangOptions & getLangOpts() const
LValue EmitLValueForFieldInitialization(LValue Base, const FieldDecl *Field)
EmitLValueForFieldInitialization - Like EmitLValueForField, except that if the Field is a reference...
bool isBlockPointerType() const
llvm::Value * EmitARCRetainNonBlock(llvm::Value *value)
Retain the given object, with normal retain semantics.
static llvm::SmallVector< FunctionProtoType::ExtParameterInfo, 16 > getExtParameterInfosForCall(const FunctionProtoType *proto, unsigned prefixArgs, unsigned totalArgs)
llvm::IntegerType * Int8Ty
i8, i16, i32, and i64
Represents a C++ constructor within a class.
bool hasUnsignedIntegerRepresentation() const
Determine whether this type has an unsigned integer representation of some sort, e.g., it is an unsigned integer type or a vector.
static llvm::Value * emitArgumentDemotion(CodeGenFunction &CGF, const VarDecl *var, llvm::Value *value)
An argument came in as a promoted argument; demote it back to its declared type.
void freeArgumentMemory(CodeGenFunction &CGF) const
Default closure variant of a ctor.
virtual bool isNoProtoCallVariadic(const CodeGen::CallArgList &args, const FunctionNoProtoType *fnType) const
Determine whether a call to an unprototyped functions under the given calling convention should use t...
Address GetAddrOfLocalVar(const VarDecl *VD)
GetAddrOfLocalVar - Return the address of a local variable.
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.
static void addExtParameterInfosForCall(llvm::SmallVectorImpl< FunctionProtoType::ExtParameterInfo > ¶mInfos, const FunctionProtoType *proto, unsigned prefixArgs, unsigned totalArgs)
RAII object to set/unset CodeGenFunction::IsSanitizerScope.
bool areArgsDestroyedLeftToRightInCallee() const
Are arguments to a call destroyed left to right in the callee? This is a fundamental language change...
static llvm::Value * CreateCoercedLoad(Address Src, llvm::Type *Ty, CodeGenFunction &CGF)
CreateCoercedLoad - Create a load from.
const FunctionProtoType * getFunctionType() const
getFunctionType - Return the underlying function type for this block.
void setCoerceToType(llvm::Type *T)
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
ObjCMethodDecl - Represents an instance or class method declaration.
static void EmitInitStoreOfNonAggregate(CodeGenFunction &CGF, RValue Src, LValue Dst)
Store a non-aggregate value to an address to initialize it.
virtual bool shouldSignExtUnsignedType(QualType Ty) const
Address CreateConstInBoundsByteGEP(Address Addr, CharUnits Offset, const llvm::Twine &Name="")
Given a pointer to i8, adjust it by a given constant offset.
bool shouldUseFusedARCCalls()
const CGFunctionInfo & arrangeCXXStructorDeclaration(const CXXMethodDecl *MD, StructorType Type)
llvm::Type * ConvertTypeForMem(QualType T)
ConvertTypeForMem - Convert type T into a llvm::Type.
ParmVarDecl - Represents a parameter to a function.
bool isObjCRetainableType() const
NullPointerConstantKind isNullPointerConstant(ASTContext &Ctx, NullPointerConstantValueDependence NPC) const
isNullPointerConstant - C99 6.3.2.3p3 - Test if this reduces down to a Null pointer constant...
static bool isProvablyNonNull(llvm::Value *addr)
virtual bool hasMostDerivedReturn(GlobalDecl GD) const
unsigned getNumParams() const
RecordDecl - Represents a struct/union/class.
const_arg_iterator arg_end() const
An object to manage conditionally-evaluated expressions.
Description of a constructor that was inherited from a base class.
ExtInfo withProducesResult(bool producesResult) const
static void emitWritebacks(CodeGenFunction &CGF, const CallArgList &args)
ParameterABI getABI() const
Return the ABI treatment of this parameter.
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...
llvm::Type * ConvertType(QualType T)
ConvertType - Convert type T into a llvm::Type.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
llvm::IntegerType * Int64Ty
llvm::Constant * objc_retainAutoreleasedReturnValue
id objc_retainAutoreleasedReturnValue(id);
RValue EmitReferenceBindingToExpr(const Expr *E)
Emits a reference binding to the passed in expression.
bool isReferenceType() const
llvm::Value * EmitARCRetainAutoreleaseReturnValue(llvm::Value *value)
Do a fused retain/autorelease of the given object.
FieldDecl - An instance of this class is created by Sema::ActOnField to represent a member of a struc...
bool isAnyPointerType() const
llvm::IntegerType * SizeTy
StructorType getFromDtorType(CXXDtorType T)
llvm::CallInst * EmitRuntimeCall(llvm::Value *callee, const Twine &name="")
virtual unsigned getOpenCLKernelCallingConv() const
Get LLVM calling convention for OpenCL kernel.
bool getInAllocaSRet() const
Return true if this field of an inalloca struct should be returned to implement a struct return calli...
ArrayRef< ExtParameterInfo > getExtParameterInfos() const
Denotes a cleanup that should run when a scope is exited using exceptional control flow (a throw stat...
llvm::Value * EmitARCAutoreleaseReturnValue(llvm::Value *value)
Autorelease the given object.
static void emitWritebackArg(CodeGenFunction &CGF, CallArgList &args, const ObjCIndirectCopyRestoreExpr *CRE)
Emit an argument that's being passed call-by-writeback.
virtual CodeGen::Address EmitMSVAArg(CodeGen::CodeGenFunction &CGF, CodeGen::Address VAListAddr, QualType Ty) const
Emit the target dependent code to load a value of.
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
llvm::CallSite EmitCallOrInvoke(llvm::Value *Callee, ArrayRef< llvm::Value * > Args, const Twine &Name="")
Emits a call or invoke instruction to the given function, depending on the current state of the EH st...
static const EHPersonality & get(CodeGenModule &CGM, const FunctionDecl *FD)
llvm::StructType * getArgStruct() const
Get the struct type used to represent all the arguments in memory.
llvm::Type * getCoerceToType() const
bool getCanBeFlattened() const
RValue EmitCall(const CGFunctionInfo &FnInfo, llvm::Value *Callee, ReturnValueSlot ReturnValue, const CallArgList &Args, CGCalleeInfo CalleeInfo=CGCalleeInfo(), llvm::Instruction **callOrInvoke=nullptr)
EmitCall - Generate a call of the given function, expecting the given result type, and using the given argument list which specifies both the LLVM arguments and the types they were derived from.
unsigned getRegParm() const
const Decl * getDecl() const
RValue EmitAnyExprToTemp(const Expr *E)
EmitAnyExprToTemp - Similary to EmitAnyExpr(), however, the result will always be accessible even if ...
bool shouldCopy() const
shouldCopy - True if we should do the 'copy' part of the copy-restore.
ComplexPairTy EmitLoadOfComplex(LValue src, SourceLocation loc)
EmitLoadOfComplex - Load a complex number from the specified l-value.
void addArgCleanupDeactivation(EHScopeStack::stable_iterator Cleanup, llvm::Instruction *IsActiveIP)
unsigned getEffectiveCallingConvention() const
getEffectiveCallingConvention - Return the actual calling convention to use, which may depend on the ...
void EmitNoreturnRuntimeCallOrInvoke(llvm::Value *callee, ArrayRef< llvm::Value * > args)
Emits a call or invoke to the given noreturn runtime function.
CharUnits getArgStructAlignment() const
const FunctionProtoType * getCalleeFunctionProtoType()
This parameter (which must have pointer type) uses the special Swift context-pointer ABI treatment...
static bool hasScalarEvaluationKind(QualType T)
CharUnits getAlignment() const
static llvm::Value * tryEmitFusedAutoreleaseOfResult(CodeGenFunction &CGF, llvm::Value *result)
Try to emit a fused autorelease of a return result.
const TargetInfo & getTargetInfo() const
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.
Qualifiers::ObjCLifetime getObjCLifetime() const
CanProxy< U > getAs() const
Retrieve a canonical type pointer with a different static type, upcasting or downcasting as needed...
QualType getReturnType() const
const CXXRecordDecl * getParent() const
Returns the parent of this method declaration, which is the class in which this method is defined...
field_range fields() const
const Expr * getSubExpr() const
QualType getIntPtrType() const
Return a type compatible with "intptr_t" (C99 7.18.1.4), as defined by the target.
llvm::CallInst * CreateMemCpy(Address Dest, Address Src, llvm::Value *Size, bool IsVolatile=false)
ABIArgInfo - Helper class to encapsulate information about how a specific C type should be passed to ...
const CGFunctionInfo & arrangeObjCMessageSendSignature(const ObjCMethodDecl *MD, QualType receiverType)
Arrange the argument and result information for the function type through which to perform a send to ...
bool allowsOptionalArgs() const
const CGFunctionInfo & arrangeCall(const CGFunctionInfo &declFI, const CallArgList &args)
Given a function info for a declaration, return the function info for a call with the given arguments...
bool isVariadic() const
Whether this function is variadic.
llvm::BasicBlock * createBasicBlock(const Twine &name="", llvm::Function *parent=nullptr, llvm::BasicBlock *before=nullptr)
createBasicBlock - Create an LLVM basic block.
Denotes a cleanup that should run when a scope is exited using normal control flow (falling off the e...
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types...
const CGFunctionInfo & arrangeCXXMethodDeclaration(const CXXMethodDecl *MD)
C++ methods have some special rules and also have implicit parameters.
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.
An ordinary object is located at an address in memory.
RValue convertTempToRValue(Address addr, QualType type, SourceLocation Loc)
Given the address of a temporary variable, produce an r-value of its type.
const CGFunctionInfo & arrangeLLVMFunctionInfo(CanQualType returnType, bool instanceMethod, bool chainCall, ArrayRef< CanQualType > argTypes, FunctionType::ExtInfo info, ArrayRef< FunctionProtoType::ExtParameterInfo > paramInfos, RequiredArgs args)
"Arrange" the LLVM information for a call or type with the given signature.
detail::InMemoryDirectory::const_iterator I
llvm::StructType * getCoerceAndExpandType() const
QualType getCanonicalTypeInternal() const
std::pair< CharUnits, CharUnits > getTypeInfoInChars(const Type *T) const
This parameter (which must have pointer-to-pointer type) uses the special Swift error-result ABI trea...
void EmitCallArg(CallArgList &args, const Expr *E, QualType ArgType)
EmitCallArg - Emit a single call argument.
void begin(CodeGenFunction &CGF)
const CGFunctionInfo & arrangeGlobalDeclaration(GlobalDecl GD)
static CanQualType GetThisType(ASTContext &Context, const CXXRecordDecl *RD)
Derives the 'this' type for codegen purposes, i.e.
const BlockExpr * BlockExpression
virtual bool doesReturnSlotInterfereWithArgs() const
doesReturnSlotInterfereWithArgs - Return true if the target uses an argument slot for an 'sret' type...
const CGFunctionInfo & arrangeUnprototypedObjCMessageSend(QualType returnType, const CallArgList &args)
Represents a K&R-style 'int foo()' function, which has no information available about its arguments...
unsigned getNumRequiredArgs() const
llvm::CallSite EmitRuntimeCallOrInvoke(llvm::Value *callee, ArrayRef< llvm::Value * > args, const Twine &name="")
Emits a call or invoke instruction to the given runtime function.
LValue MakeAddrLValue(Address Addr, QualType T, AlignmentSource AlignSource=AlignmentSource::Type)
llvm::Type * getUnpaddedCoerceAndExpandType() const
ExtInfo getExtInfo() const
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...
CanQualType getCanonicalTypeUnqualified() const
std::pair< llvm::Value *, llvm::Value * > ComplexPairTy
Represents a prototype with parameter type info, e.g.
ExceptionSpecificationType getExceptionSpecType() const
Get the kind of exception specification on this function.
llvm::CallInst * EmitNounwindRuntimeCall(llvm::Value *callee, const Twine &name="")
const CodeGen::CGBlockInfo * BlockInfo
const TargetCodeGenInfo & getTargetCodeGenInfo()
writeback_const_range writebacks() const
const TargetInfo & getTarget() const
RValue - This trivial value class is used to represent the result of an expression that is evaluated...
ArrayRef< CallArgCleanup > getCleanupsToDeactivate() const
bool hasConstructorVariants() const
Does this ABI have different entrypoints for complete-object and base-subobject constructors?
void valueProfile(CGBuilderTy &Builder, uint32_t ValueKind, llvm::Instruction *ValueSite, llvm::Value *ValuePtr)
void addWriteback(LValue srcLV, Address temporary, llvm::Value *toUse)
void EmitDelegateCallArg(CallArgList &args, const VarDecl *param, SourceLocation loc)
EmitDelegateCallArg - We are performing a delegate call; that is, the current function is delegating ...
Represents a call to the builtin function __builtin_va_arg.
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
static void appendParameterTypes(const CodeGenTypes &CGT, SmallVectorImpl< CanQualType > &prefix, SmallVectorImpl< FunctionProtoType::ExtParameterInfo > ¶mInfos, CanQual< FunctionProtoType > FPT, const FunctionDecl *FD)
Adds the formal paramaters in FPT to the given prefix.
Address Temporary
The temporary alloca.
llvm::Value * ToUse
A value to "use" after the writeback, or null.
ArrayRef< llvm::Type * > getCoerceAndExpandTypeSequence() const
void getFunctionFeatureMap(llvm::StringMap< bool > &FeatureMap, const FunctionDecl *FD)
bool isSignedIntegerOrEnumerationType() const
Determines whether this is an integer type that is signed or an enumeration types whose underlying ty...
static TypeEvaluationKind getEvaluationKind(QualType T)
hasAggregateLLVMType - Return true if the specified AST type will map into an aggregate LLVM type or ...
llvm::Value * getPointer() const
static AggValueSlot createPlaceholderSlot(CodeGenFunction &CGF, QualType Ty)
Expr - This represents one expression.
CXXDtorType getDtorType() const
CGCXXABI & getCXXABI() const
static bool isInAllocaArgument(CGCXXABI &ABI, QualType type)
static CanQualType GetReturnType(QualType RetTy)
Returns the "extra-canonicalized" return type, which discards qualifiers on the return type...
void EmitStoreOfScalar(llvm::Value *Value, Address Addr, bool Volatile, QualType Ty, AlignmentSource AlignSource=AlignmentSource::Type, llvm::MDNode *TBAAInfo=nullptr, bool isInit=false, QualType TBAABaseTy=QualType(), uint64_t TBAAOffset=0, bool isNontemporal=false)
EmitStoreOfScalar - Store a scalar value to an address, taking care to appropriately convert from the...
static ParamValue forIndirect(Address addr)
const CGFunctionInfo & arrangeNullaryFunction()
A nullary function is a freestanding function of type 'void ()'.
bool usesInAlloca() const
Return true if this function uses inalloca arguments.
Represents a C++ destructor within a class.
llvm::Constant * objc_retain
id objc_retain(id);
CharUnits getIndirectAlign() const
bool isMSVCXXPersonality() const
const ParmVarDecl * getParamDecl(unsigned i) const
AggValueSlot CreateAggTemp(QualType T, const Twine &Name="tmp")
CreateAggTemp - Create a temporary memory object for the given aggregate type.
ASTContext & getContext() const
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
ImplicitParamDecl * getSelfDecl() const
static bool isPaddingForCoerceAndExpand(llvm::Type *eltType)
void add(RValue rvalue, QualType type, bool needscopy=false)
static SmallVector< CanQualType, 16 > getArgTypesForCall(ASTContext &ctx, const CallArgList &args)
static void eraseUnusedBitCasts(llvm::Instruction *insn)
char __ovld __cnfn min(char x, char y)
Returns y if y < x, otherwise it returns x.
llvm::LLVMContext & getLLVMContext()
A class for recording the number of arguments that a function signature requires. ...
bool ReturnSlotInterferesWithArgs(const CGFunctionInfo &FI)
Return true iff the given type uses an argument slot when 'sret' is used as a return type...
bool currentFunctionUsesSEHTry() const
const CGFunctionInfo & arrangeBuiltinFunctionCall(QualType resultType, const CallArgList &args)
llvm::IntegerType * Int32Ty
static Address emitAddressAtOffset(CodeGenFunction &CGF, Address addr, const ABIArgInfo &info)
Address EmitPointerWithAlignment(const Expr *Addr, AlignmentSource *Source=nullptr)
EmitPointerWithAlignment - Given an expression with a pointer type, emit the value and compute our be...
static llvm::StoreInst * findDominatingStoreToReturnValue(CodeGenFunction &CGF)
Heuristically search for a dominating store to the return-value slot.
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)
void Profile(llvm::FoldingSetNodeID &ID)
UnaryOperator - This represents the unary-expression's (except sizeof and alignof), the postinc/postdec operators from postfix-expression, and various extensions.
llvm::Function * getIntrinsic(unsigned IID, ArrayRef< llvm::Type * > Tys=None)
class LLVM_ALIGNAS(8) TemplateSpecializationType unsigned NumArgs
Represents a type template specialization; the template must be a class template, a type alias templa...
llvm::Type * getPaddingType() const
ARCPreciseLifetime_t isARCPreciseLifetime() const
static AggValueSlot forAddr(Address addr, Qualifiers quals, IsDestructed_t isDestructed, NeedsGCBarriers_t needsGC, IsAliased_t isAliased, IsZeroed_t isZeroed=IsNotZeroed)
forAddr - Make a slot for an aggregate value.
bool isUnsignedIntegerOrEnumerationType() const
Determines whether this is an integer type that is unsigned or an enumeration types whose underlying ...
static llvm::Value * CoerceIntOrPtrToIntOrPtr(llvm::Value *Val, llvm::Type *Ty, CodeGenFunction &CGF)
CoerceIntOrPtrToIntOrPtr - Convert a value Val to the specific Ty where both are either integers or p...
CallingConv
CallingConv - Specifies the calling convention that a function uses.
bool hasWritebacks() const
unsigned getNumRequiredArgs() const
GlobalDecl - represents a global declaration.
static void BuildAggStore(CodeGenFunction &CGF, llvm::Value *Val, Address Dest, bool DestIsVolatile)
std::string CPU
If given, the name of the target CPU to generate code for.
The l-value was considered opaque, so the alignment was determined from a type.
bool isNothrow(const ASTContext &Ctx, bool ResultIfDependent=false) const
Determine whether this function type has a non-throwing exception specification.
void EmitAlignmentAssumption(llvm::Value *PtrValue, unsigned Alignment, llvm::Value *OffsetValue=nullptr)
ArrayRef< ParmVarDecl * > parameters() const
bool HaveInsertPoint() const
HaveInsertPoint - True if an insertion point is defined.
static void CreateCoercedStore(llvm::Value *Src, Address Dst, bool DstIsVolatile, CodeGenFunction &CGF)
CreateCoercedStore - Create a store to.
Enumerates target-specific builtins in their own namespaces within namespace clang.
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.
Assigning into this object requires the old value to be released and the new value to be retained...
bool ReturnTypeUsesFPRet(QualType ResultType)
Return true iff the given type uses 'fpret' when used as a return type.
FunctionType::ExtInfo getExtInfo() const
ConstExprIterator const_arg_iterator
static const Expr * maybeGetUnaryAddrOfOperand(const Expr *E)
ASTContext & getContext() const
RequiredArgs getRequiredArgs() 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...
void EmitARCIntrinsicUse(ArrayRef< llvm::Value * > values)
Given a number of pointers, inform the optimizer that they're being intrinsically used up until this ...
unsigned getNumParams() const
getNumParams - Return the number of parameters this function must have based on its FunctionType...
void EmitARCRelease(llvm::Value *value, ARCPreciseLifetime_t precise)
Release the given object.
llvm::BasicBlock * getUnreachableBlock()
llvm::Value * EmitLoadOfScalar(Address Addr, bool Volatile, QualType Ty, SourceLocation Loc, AlignmentSource AlignSource=AlignmentSource::Type, llvm::MDNode *TBAAInfo=nullptr, QualType TBAABaseTy=QualType(), uint64_t TBAAOffset=0, bool isNontemporal=false)
EmitLoadOfScalar - Load a scalar value from an address, taking care to appropriately convert from the...
bool inheritingCtorHasParams(const InheritedConstructor &Inherited, CXXCtorType Type)
Determine if a C++ inheriting constructor should have parameters matching those of its inherited cons...
bool isConstantSizeType() const
Return true if this is not a variable sized type, according to the rules of C99 6.7.5p3.
bool isCleanupPadScope() const
Returns true while emitting a cleanuppad.
void DeactivateCleanupBlock(EHScopeStack::stable_iterator Cleanup, llvm::Instruction *DominatingIP)
DeactivateCleanupBlock - Deactivates the given cleanup block.
llvm::Value * EmitLifetimeStart(uint64_t Size, llvm::Value *Addr)
Emit a lifetime.begin marker if some criteria are satisfied.
virtual void computeInfo(CodeGen::CGFunctionInfo &FI) const =0
const CGFunctionInfo & arrangeObjCMethodDeclaration(const ObjCMethodDecl *MD)
Objective-C methods are C functions with some implicit parameters.
bool getPaddingInReg() const
Represents a static or instance method of a struct/union/class.
bool isReturnsRetained() const
In ARC, whether this function retains its return value.
void computeABIInfo(CodeGenModule &CGM, CGFunctionInfo &FI)
Compute the ABI information of a swiftcall function.
CanQualType getCanonicalParamType(QualType T) const
Return the canonical parameter type corresponding to the specific potentially non-canonical one...
SanitizerSet SanOpts
Sanitizers enabled for this function.
CoerceAndExpand - Only valid for aggregate argument types.
void allocateArgumentMemory(CodeGenFunction &CGF)
const ConstantArrayType * getAsConstantArrayType(QualType T) const
std::vector< std::string > Features
The list of target specific features to enable or disable – this should be a list of strings starting...
static bool classof(const EHScope *Scope)
Specifies that a value-dependent expression should be considered to never be a null pointer constant...
CharUnits alignmentOfArrayElement(CharUnits elementSize) const
Given that this is the alignment of the first element of an array, return the minimum alignment of an...
llvm::InlineAsm * retainAutoreleasedReturnValueMarker
A void(void) inline asm to use to mark that the return value of a call will be immediately retain...
const CodeGenOptions & getCodeGenOpts() const
const LangOptions & getLangOpts() const
llvm::LLVMContext & getLLVMContext()
QualType getReturnType() const
const T * castAs() const
Member-template castAs<specific type>.
static SmallVector< CanQualType, 16 > getArgTypesForDeclaration(ASTContext &ctx, const FunctionArgList &args)
llvm::Instruction * CurrentFuncletPad
InAlloca - Pass the argument directly using the LLVM inalloca attribute.
void EmitParmDecl(const VarDecl &D, ParamValue Arg, unsigned ArgNo)
EmitParmDecl - Emit a ParmVarDecl or an ImplicitParamDecl.
bool ReturnTypeUsesFP2Ret(QualType ResultType)
Return true iff the given type uses 'fp2ret' when used as a return type.
static ParamValue forDirect(llvm::Value *value)
static void AddAttributesFromFunctionProtoType(ASTContext &Ctx, llvm::AttrBuilder &FuncAttrs, const FunctionProtoType *FPT)
ConstructorUsingShadowDecl * getShadowDecl() const
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.
llvm::StringRef getName() const
Return the IR name of the pointer value.
const CGFunctionInfo & arrangeCXXMethodCall(const CallArgList &args, const FunctionProtoType *type, RequiredArgs required)
Arrange a call to a C++ method, passing the given arguments.
CXXCtorType
C++ constructor types.
const CGFunctionInfo & arrangeBlockFunctionCall(const CallArgList &args, const FunctionType *type)
A block function is essentially a free function with an extra implicit argument.
void setExternallyDestructed(bool destructed=true)
QualType getObjCSelType() const
Retrieve the type that corresponds to the predefined Objective-C 'SEL' type.
Address EmitVAListRef(const Expr *E)
static Address EnterStructPointerForCoercedAccess(Address SrcPtr, llvm::StructType *SrcSTy, uint64_t DstSize, CodeGenFunction &CGF)
EnterStructPointerForCoercedAccess - Given a struct pointer that we are accessing some number of byte...
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...
virtual CodeGen::Address EmitVAArg(CodeGen::CodeGenFunction &CGF, CodeGen::Address VAListAddr, QualType Ty) const =0
EmitVAArg - Emit the target dependent code to load a value of.
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.
bool canHaveCoerceToType() const
void EmitCXXDestructorCall(const CXXDestructorDecl *D, CXXDtorType Type, bool ForVirtualBase, bool Delegating, Address This)
llvm::Value * getAggregatePointer() const
static RValue getComplex(llvm::Value *V1, llvm::Value *V2)
bool isZero() const
isZero - Test whether the quantity equals zero.
unsigned getDirectOffset() const
Address CreateMemTemp(QualType T, const Twine &Name="tmp")
CreateMemTemp - Create a temporary memory object of the given type, with appropriate alignment...
CXXDestructorDecl * getDestructor() const
Returns the destructor decl for this class.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
llvm::Value * getScalarVal() const
getScalarVal() - Return the Value* of this scalar value.
CodeGenFunction::ComplexPairTy ComplexPairTy
bool isInstanceMethod() const
Address CreateStructGEP(Address Addr, unsigned Index, CharUnits Offset, const llvm::Twine &Name="")
CXXDtorType toCXXDtorType(StructorType T)
virtual void buildStructorSignature(const CXXMethodDecl *MD, StructorType T, SmallVectorImpl< CanQualType > &ArgTys)=0
Build the signature of the given constructor or destructor variant by adding any required parameters...
LValue Source
The original argument.
const CGFunctionInfo & arrangeFunctionDeclaration(const FunctionDecl *FD)
Free functions are functions that are compatible with an ordinary C function pointer type...
bool getProducesResult() const
llvm::LoadInst * CreateAlignedLoad(llvm::Value *Addr, CharUnits Align, const llvm::Twine &Name="")
static void forConstantArrayExpansion(CodeGenFunction &CGF, ConstantArrayExpansion *CAE, Address BaseAddr, llvm::function_ref< void(Address)> Fn)
static const CGFunctionInfo & arrangeLLVMFunctionInfo(CodeGenTypes &CGT, bool instanceMethod, SmallVectorImpl< CanQualType > &prefix, CanQual< FunctionProtoType > FTP, const FunctionDecl *FD)
Arrange the LLVM function layout for a value of the given function type, on top of any implicit param...
llvm::LoadInst * CreateLoad(Address Addr, const llvm::Twine &Name="")
llvm::IntegerType * IntPtrTy
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
CallingConv getCC() const
SourceLocation getLocStart() const LLVM_READONLY
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
detail::InMemoryDirectory::const_iterator E
static CGFunctionInfo * create(unsigned llvmCC, bool instanceMethod, bool chainCall, const FunctionType::ExtInfo &extInfo, ArrayRef< ExtParameterInfo > paramInfos, CanQualType resultType, ArrayRef< CanQualType > argTypes, RequiredArgs required)
void EmitAggregateCopy(Address DestPtr, Address SrcPtr, QualType EltTy, bool isVolatile=false, bool isAssignment=false)
EmitAggregateCopy - Emit an aggregate copy.
llvm::StoreInst * CreateStore(llvm::Value *Val, Address Addr, bool IsVolatile=false)
bool isSEHTryScope() const
Returns true inside SEH __try blocks.
static void getBundlesForFunclet(llvm::Value *Callee, llvm::Instruction *CurrentFuncletPad, SmallVectorImpl< llvm::OperandBundleDef > &BundleList)
void EmitAggExpr(const Expr *E, AggValueSlot AS)
EmitAggExpr - Emit the computation of the specified expression of aggregate type. ...
const VariableArrayType * getAsVariableArrayType(QualType T) const
static bool hasAggregateEvaluationKind(QualType T)
llvm::PointerType * getType() const
Return the type of the pointer value.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Complex values, per C99 6.2.5p11.
StructorType getFromCtorType(CXXCtorType T)
const T * getAs() const
Member-template getAs<specific type>'.
TargetOptions & getTargetOpts() const
Retrieve the target options.
Pass it using the normal C aggregate rules for the ABI, potentially introducing extra copies and pass...
void EmitStoreOfComplex(ComplexPairTy V, LValue dest, bool isInit)
EmitStoreOfComplex - Store a complex number into the specified l-value.
static llvm::Value * tryRemoveRetainOfSelf(CodeGenFunction &CGF, llvm::Value *result)
If this is a +1 of the value of an immutable 'self', remove it.
RValue GetUndefRValue(QualType Ty)
GetUndefRValue - Get an appropriate 'undef' rvalue for the given type.
Implements C++ ABI-specific code generation functions.
This class organizes the cross-module state that is used while lowering AST types to LLVM types...
RValue EmitRValueForField(LValue LV, const FieldDecl *FD, SourceLocation Loc)
llvm::PointerType * Int8PtrTy
bool has(SanitizerMask K) const
Check if a certain (single) sanitizer is enabled.
Expand - Only valid for aggregate argument types.
Address getAddress() const
const CGFunctionInfo & arrangeMSMemberPointerThunk(const CXXMethodDecl *MD)
Arrange a thunk that takes 'this' as the first parameter followed by varargs.
Base for LValueReferenceType and RValueReferenceType.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
static std::unique_ptr< TypeExpansion > getTypeExpansion(QualType Ty, const ASTContext &Context)
bool isRestrictQualified() const
Determine whether this type is restrict-qualified.
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false)
EmitBlock - Emit the given block.
QualType getTagDeclType(const TagDecl *Decl) const
Return the unique reference to the type for the specified TagDecl (struct/union/class/enum) decl...
ABIArgInfo & getReturnInfo()
Represents a base class of a C++ class.
char __ovld __cnfn max(char x, char y)
Returns y if x < y, otherwise it returns x.
llvm::MDNode * getNoObjCARCExceptionsMetadata()
Pass it on the stack using its defined layout.
uint64_t getPointerWidth(unsigned AddrSpace) const
Return the width of pointers on this target, for the specified address space.
const Decl * getCalleeDecl()
llvm::Type * GetFunctionTypeForVTable(GlobalDecl GD)
GetFunctionTypeForVTable - Get the LLVM function type for use in a vtable, given a CXXMethodDecl...
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
bool isNoBuiltinFunc(const char *Name) const
Is this a libc/libm function that is no longer recognized as a builtin because a -fno-builtin-* optio...
Represents a C++ struct/union/class.
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
virtual const CXXRecordDecl * getThisArgumentTypeForMethod(const CXXMethodDecl *MD)
Get the type of the implicit "this" parameter used by a method.
llvm::BasicBlock * getInvokeDest()
bool isUsingInAlloca() const
Returns if we're using an inalloca struct to pass arguments in memory.
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...
CallingConv getDefaultCallingConvention(bool isVariadic, bool IsCXXMethod) const
Retrieves the default calling convention for the current target.
ArrayRef< ExtParameterInfo > getExtParameterInfos() const
virtual RecordArgABI getRecordArgABI(const CXXRecordDecl *RD) const =0
Returns how an argument of the given record type should be passed.
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.
llvm::Instruction * getStackBase() const
This class is used for builtin types like 'int'.
Address getAggregateAddress() const
getAggregateAddr() - Return the Value* of the address of the aggregate.
const T * getTypePtr() const
Retrieve the underlying type pointer, which refers to a canonical type.
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 ...
Copying closure variant of a ctor.
Defines the clang::TargetInfo interface.
const_arg_iterator arg_begin() const
bool getIndirectByVal() const
stable_iterator getInnermostEHScope() const
static CallingConv getCallingConventionForDecl(const Decl *D, bool IsWindows)
bool getHasRegParm() const
const CGFunctionInfo & arrangeMSCtorClosure(const CXXConstructorDecl *CD, CXXCtorType CT)
std::string TrapFuncName
If not an empty string, trap intrinsics are lowered to calls to this function instead of to trap inst...
bool isMicrosoftABI() const
Returns whether this is really a Win64 ABI va_arg expression.
unsigned getTargetAddressSpace(QualType T) const
static void deactivateArgCleanupsBeforeCall(CodeGenFunction &CGF, const CallArgList &CallArgs)
const ABIInfo & getABIInfo() const
bool constructsVirtualBase() const
Returns true if the constructed base class is a virtual base class subobject of this declaration's cl...
static RValue get(llvm::Value *V)
unsigned arg_size() const
static RequiredArgs forPrototypePlus(const FunctionProtoType *prototype, unsigned additional, const FunctionDecl *FD)
Compute the arguments required by the given formal prototype, given that there may be some additional...
bool isVolatileQualified() const
void EmitLifetimeEnd(llvm::Value *Size, llvm::Value *Addr)
const CGFunctionInfo & arrangeFreeFunctionCall(const CallArgList &Args, const FunctionType *Ty, bool ChainCall)
Figure out the rules for calling a function with the given formal type using the given arguments...
CXXCtorType toCXXCtorType(StructorType T)
llvm::Constant * EmitCheckSourceLocation(SourceLocation Loc)
Emit a description of a source location in a format suitable for passing to a runtime sanitizer handl...
bool getIndirectRealign() const
static RValue getAggregate(Address addr, bool isVolatile=false)
bool isUnresolvedExceptionSpec(ExceptionSpecificationType ESpecType)
CodeGenTypes & getTypes() const
LValue - This represents an lvalue references.
unsigned getNumVBases() const
Retrieves the number of virtual base classes of this class.
Information for lazily generating a cleanup.
ExtParameterInfo getExtParameterInfo(unsigned argIndex) const
bool hasSignedIntegerRepresentation() const
Determine whether this type has an signed integer representation of some sort, e.g., it is an signed integer type or a vector.
void ConstructAttributeList(StringRef Name, const CGFunctionInfo &Info, CGCalleeInfo CalleeInfo, AttributeListType &PAL, unsigned &CallingConv, bool AttrOnCallSite)
Get the LLVM attributes and calling convention to use for a particular function type.
Address GetAddressOfBaseClass(Address Value, const CXXRecordDecl *Derived, CastExpr::path_const_iterator PathBegin, CastExpr::path_const_iterator PathEnd, bool NullCheckValue, SourceLocation Loc)
GetAddressOfBaseClass - This function will add the necessary delta to the load of 'this' and returns ...
CallArgList - Type for representing both the value and type of arguments in a call.
Represents the canonical version of C arrays with a specified constant size.
CGCalleeInfo - Class to encapsulate the information about a callee to be used during the generation o...
A class which abstracts out some details necessary for making a call.
This parameter (which must have pointer type) is a Swift indirect result parameter.
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
Expr * IgnoreParens() LLVM_READONLY
IgnoreParens - Ignore parentheses.
AttributeList - Represents a syntactic attribute.
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
const CGFunctionInfo & arrangeCXXConstructorCall(const CallArgList &Args, const CXXConstructorDecl *D, CXXCtorType CtorKind, unsigned ExtraArgs)
Arrange a call to a C++ method, passing the given arguments.
bool isPointerType() const
llvm::FunctionType * GetFunctionType(const CGFunctionInfo &Info)
GetFunctionType - Get the LLVM function type for.