31 #include "llvm/ADT/StringExtras.h" 32 #include "llvm/Transforms/Utils/Local.h" 33 #include "llvm/Analysis/ValueTracking.h" 34 #include "llvm/IR/Attributes.h" 35 #include "llvm/IR/CallSite.h" 36 #include "llvm/IR/CallingConv.h" 37 #include "llvm/IR/DataLayout.h" 38 #include "llvm/IR/InlineAsm.h" 39 #include "llvm/IR/IntrinsicInst.h" 40 #include "llvm/IR/Intrinsics.h" 41 using namespace clang;
42 using namespace CodeGen;
53 case CC_Win64:
return llvm::CallingConv::Win64;
55 case CC_AAPCS:
return llvm::CallingConv::ARM_AAPCS;
56 case CC_AAPCS_VFP:
return llvm::CallingConv::ARM_AAPCS_VFP;
67 case CC_Swift:
return llvm::CallingConv::Swift;
111 unsigned totalArgs) {
113 assert(paramInfos.size() <= prefixArgs);
114 assert(proto->
getNumParams() + prefixArgs <= totalArgs);
116 paramInfos.reserve(totalArgs);
119 paramInfos.resize(prefixArgs);
123 paramInfos.push_back(ParamInfo);
125 if (ParamInfo.hasPassObjectSize())
126 paramInfos.emplace_back();
129 assert(paramInfos.size() <= totalArgs &&
130 "Did we forget to insert pass_object_size args?");
132 paramInfos.resize(totalArgs);
142 if (!FPT->hasExtParameterInfos()) {
143 assert(paramInfos.empty() &&
144 "We have paramInfos, but the prototype doesn't?");
145 prefix.append(FPT->param_type_begin(), FPT->param_type_end());
149 unsigned PrefixSize = prefix.size();
153 prefix.reserve(prefix.size() + FPT->getNumParams());
155 auto ExtInfos = FPT->getExtParameterInfos();
156 assert(ExtInfos.size() == FPT->getNumParams());
157 for (
unsigned I = 0, E = FPT->getNumParams(); I != E; ++I) {
158 prefix.push_back(FPT->getParamType(I));
159 if (ExtInfos[I].hasPassObjectSize())
174 SmallVector<FunctionProtoType::ExtParameterInfo, 16> paramInfos;
183 FTP->getExtInfo(), paramInfos,
202 if (D->
hasAttr<FastCallAttr>())
208 if (D->
hasAttr<ThisCallAttr>())
211 if (D->
hasAttr<VectorCallAttr>())
217 if (PcsAttr *PCS = D->
getAttr<PcsAttr>())
220 if (D->
hasAttr<AArch64VectorPcsAttr>())
223 if (D->
hasAttr<IntelOclBiccAttr>())
232 if (D->
hasAttr<PreserveMostAttr>())
235 if (D->
hasAttr<PreserveAllAttr>())
260 *
this,
true, argTypes,
267 if (FD->
hasAttr<CUDAGlobalAttr>()) {
280 assert(!isa<CXXConstructorDecl>(MD) &&
"wrong method for constructors!");
281 assert(!isa<CXXDestructorDecl>(MD) &&
"wrong method for destructors!");
313 bool PassParams =
true;
316 if (
auto *CD = dyn_cast<CXXConstructorDecl>(MD)) {
321 if (
auto Inherited = CD->getInheritedConstructor())
336 if (!paramInfos.empty()) {
339 paramInfos.insert(paramInfos.begin() + 1, AddedArgs.
Prefix,
342 paramInfos.append(AddedArgs.
Suffix,
357 false, argTypes, extInfo,
358 paramInfos, required);
363 SmallVector<CanQualType, 16> argTypes;
364 for (
auto &arg : args)
369 static SmallVector<CanQualType, 16>
371 SmallVector<CanQualType, 16> argTypes;
372 for (
auto &arg : args)
379 unsigned prefixArgs,
unsigned totalArgs) {
399 unsigned ExtraPrefixArgs,
400 unsigned ExtraSuffixArgs,
401 bool PassProtoArgs) {
404 for (
const auto &Arg : args)
408 unsigned TotalPrefixArgs = 1 + ExtraPrefixArgs;
424 if (PassProtoArgs && FPT->hasExtParameterInfos()) {
430 false, ArgTypes, Info,
431 ParamInfos, Required);
439 if (MD->isInstance())
444 assert(isa<FunctionType>(FTy));
451 noProto->getReturnType(),
false,
484 I->hasAttr<NoEscapeAttr>());
485 extParamInfos.push_back(extParamInfo);
492 if (
getContext().getLangOpts().ObjCAutoRefCount &&
493 MD->
hasAttr<NSReturnsRetainedAttr>())
501 false, argTys, einfo, extParamInfos, required);
536 assert(MD->
isVirtual() &&
"only methods have thunks");
554 ArgTys.push_back(*FTP->param_type_begin());
556 ArgTys.push_back(Context.
IntTy);
572 unsigned numExtraRequiredArgs,
574 assert(args.size() >= numExtraRequiredArgs);
584 if (proto->isVariadic())
585 required =
RequiredArgs(proto->getNumParams() + numExtraRequiredArgs);
587 if (proto->hasExtParameterInfos())
597 cast<FunctionNoProtoType>(fnType))) {
602 SmallVector<CanQualType, 16> argTypes;
603 for (
const auto &arg : args)
620 chainCall ? 1 : 0, chainCall);
640 false,
false, argTypes,
650 for (
const auto &Arg : args)
672 resultType,
false,
false,
684 unsigned numPrefixArgs) {
685 assert(numPrefixArgs + 1 <= args.size() &&
686 "Emitting a call with less args than the required prefix?");
698 false, argTypes, info, paramInfos, required);
710 assert(signature.
arg_size() <= args.size());
711 if (signature.
arg_size() == args.size())
716 if (!sigParamInfos.empty()) {
717 paramInfos.append(sigParamInfos.begin(), sigParamInfos.end());
718 paramInfos.resize(args.size());
750 assert(llvm::all_of(argTypes,
754 llvm::FoldingSetNodeID
ID;
756 required, resultType, argTypes);
758 void *insertPos =
nullptr;
759 CGFunctionInfo *FI = FunctionInfos.FindNodeOrInsertPos(ID, insertPos);
767 paramInfos, resultType, argTypes, required);
768 FunctionInfos.InsertNode(FI, insertPos);
770 bool inserted = FunctionsBeingProcessed.insert(FI).second;
772 assert(inserted &&
"Recursively being processed?");
775 if (CC == llvm::CallingConv::SPIR_KERNEL) {
792 for (
auto &I : FI->arguments())
793 if (I.info.canHaveCoerceToType() && I.info.getCoerceToType() ==
nullptr)
796 bool erased = FunctionsBeingProcessed.erase(FI); (void)erased;
797 assert(erased &&
"Not in set?");
810 assert(paramInfos.empty() || paramInfos.size() == argTypes.size());
813 operator new(totalSizeToAlloc<ArgInfo, ExtParameterInfo>(
814 argTypes.size() + 1, paramInfos.size()));
817 FI->CallingConvention = llvmCC;
818 FI->EffectiveCallingConvention = llvmCC;
819 FI->ASTCallingConvention = info.
getCC();
820 FI->InstanceMethod = instanceMethod;
821 FI->ChainCall = chainCall;
826 FI->Required = required;
829 FI->ArgStruct =
nullptr;
830 FI->ArgStructAlign = 0;
831 FI->NumArgs = argTypes.size();
832 FI->HasExtParameterInfos = !paramInfos.empty();
833 FI->getArgsBuffer()[0].
type = resultType;
834 for (
unsigned i = 0, e = argTypes.size(); i != e; ++i)
835 FI->getArgsBuffer()[i + 1].
type = argTypes[i];
836 for (
unsigned i = 0, e = paramInfos.size(); i != e; ++i)
837 FI->getExtParameterInfosBuffer()[i] = paramInfos[i];
847 struct TypeExpansion {
848 enum TypeExpansionKind {
860 const TypeExpansionKind
Kind;
862 TypeExpansion(TypeExpansionKind K) :
Kind(K) {}
863 virtual ~TypeExpansion() {}
866 struct ConstantArrayExpansion : TypeExpansion {
870 ConstantArrayExpansion(
QualType EltTy, uint64_t NumElts)
871 : TypeExpansion(TEK_ConstantArray), EltTy(EltTy), NumElts(NumElts) {}
872 static bool classof(
const TypeExpansion *TE) {
873 return TE->Kind == TEK_ConstantArray;
877 struct RecordExpansion : TypeExpansion {
884 : TypeExpansion(TEK_Record), Bases(std::move(Bases)),
885 Fields(std::move(Fields)) {}
886 static bool classof(
const TypeExpansion *TE) {
887 return TE->Kind == TEK_Record;
891 struct ComplexExpansion : TypeExpansion {
895 static bool classof(
const TypeExpansion *TE) {
900 struct NoExpansion : TypeExpansion {
901 NoExpansion() : TypeExpansion(TEK_None) {}
902 static bool classof(
const TypeExpansion *TE) {
903 return TE->Kind == TEK_None;
908 static std::unique_ptr<TypeExpansion>
911 return llvm::make_unique<ConstantArrayExpansion>(
912 AT->getElementType(), AT->getSize().getZExtValue());
915 SmallVector<const CXXBaseSpecifier *, 1> Bases;
916 SmallVector<const FieldDecl *, 1> Fields;
919 "Cannot expand structure with flexible array.");
926 for (
const auto *FD : RD->
fields()) {
927 if (FD->isZeroLengthBitField(Context))
929 assert(!FD->isBitField() &&
930 "Cannot expand structure with bit-field members.");
932 if (UnionSize < FieldSize) {
933 UnionSize = FieldSize;
938 Fields.push_back(LargestFD);
940 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
941 assert(!CXXRD->isDynamicClass() &&
942 "cannot expand vtable pointers in dynamic classes");
944 Bases.push_back(&BS);
947 for (
const auto *FD : RD->
fields()) {
948 if (FD->isZeroLengthBitField(Context))
950 assert(!FD->isBitField() &&
951 "Cannot expand structure with bit-field members.");
952 Fields.push_back(FD);
955 return llvm::make_unique<RecordExpansion>(std::move(Bases),
959 return llvm::make_unique<ComplexExpansion>(CT->getElementType());
961 return llvm::make_unique<NoExpansion>();
966 if (
auto CAExp = dyn_cast<ConstantArrayExpansion>(Exp.get())) {
969 if (
auto RExp = dyn_cast<RecordExpansion>(Exp.get())) {
971 for (
auto BS : RExp->Bases)
973 for (
auto FD : RExp->Fields)
977 if (isa<ComplexExpansion>(Exp.get()))
979 assert(isa<NoExpansion>(Exp.get()));
987 if (
auto CAExp = dyn_cast<ConstantArrayExpansion>(Exp.get())) {
988 for (
int i = 0, n = CAExp->NumElts; i < n; i++) {
991 }
else if (
auto RExp = dyn_cast<RecordExpansion>(Exp.get())) {
992 for (
auto BS : RExp->Bases)
994 for (
auto FD : RExp->Fields)
996 }
else if (
auto CExp = dyn_cast<ComplexExpansion>(Exp.get())) {
1001 assert(isa<NoExpansion>(Exp.get()));
1007 ConstantArrayExpansion *CAE,
1009 llvm::function_ref<
void(
Address)> Fn) {
1014 for (
int i = 0, n = CAE->NumElts; i < n; i++) {
1017 Fn(
Address(EltAddr, EltAlign));
1021 void CodeGenFunction::ExpandTypeFromArgs(
1024 "Unexpected non-simple lvalue during struct expansion.");
1027 if (
auto CAExp = dyn_cast<ConstantArrayExpansion>(Exp.get())) {
1030 LValue LV = MakeAddrLValue(EltAddr, CAExp->EltTy);
1031 ExpandTypeFromArgs(CAExp->EltTy, LV, AI);
1033 }
else if (
auto RExp = dyn_cast<RecordExpansion>(Exp.get())) {
1043 ExpandTypeFromArgs(BS->getType(), SubLV, AI);
1045 for (
auto FD : RExp->Fields) {
1047 LValue SubLV = EmitLValueForFieldInitialization(LV, FD);
1048 ExpandTypeFromArgs(FD->getType(), SubLV, AI);
1050 }
else if (isa<ComplexExpansion>(Exp.get())) {
1051 auto realValue = *AI++;
1052 auto imagValue = *AI++;
1053 EmitStoreOfComplex(
ComplexPairTy(realValue, imagValue), LV,
true);
1055 assert(isa<NoExpansion>(Exp.get()));
1060 void CodeGenFunction::ExpandTypeToArgs(
1064 if (
auto CAExp = dyn_cast<ConstantArrayExpansion>(Exp.get())) {
1068 *
this, CAExp, Addr, [&](
Address EltAddr) {
1072 ExpandTypeToArgs(CAExp->EltTy, EltArg, IRFuncTy, IRCallArgs,
1075 }
else if (
auto RExp = dyn_cast<RecordExpansion>(Exp.get())) {
1086 ExpandTypeToArgs(BS->getType(), BaseArg, IRFuncTy, IRCallArgs,
1090 LValue LV = MakeAddrLValue(This, Ty);
1091 for (
auto FD : RExp->Fields) {
1094 ExpandTypeToArgs(FD->getType(), FldArg, IRFuncTy, IRCallArgs,
1097 }
else if (isa<ComplexExpansion>(Exp.get())) {
1099 IRCallArgs[IRCallArgPos++] = CV.first;
1100 IRCallArgs[IRCallArgPos++] = CV.second;
1102 assert(isa<NoExpansion>(Exp.get()));
1104 assert(RV.isScalar() &&
1105 "Unexpected non-scalar rvalue during struct expansion.");
1109 if (IRCallArgPos < IRFuncTy->getNumParams() &&
1110 V->getType() != IRFuncTy->getParamType(IRCallArgPos))
1111 V = Builder.CreateBitCast(V, IRFuncTy->getParamType(IRCallArgPos));
1113 IRCallArgs[IRCallArgPos++] = V;
1133 llvm::StructType *SrcSTy,
1136 if (SrcSTy->getNumElements() == 0)
return SrcPtr;
1138 llvm::Type *FirstElt = SrcSTy->getElementType(0);
1144 uint64_t FirstEltSize =
1146 if (FirstEltSize < DstSize &&
1155 if (llvm::StructType *SrcSTy = dyn_cast<llvm::StructType>(SrcTy))
1171 if (Val->getType() == Ty)
1174 if (isa<llvm::PointerType>(Val->getType())) {
1176 if (isa<llvm::PointerType>(Ty))
1184 if (isa<llvm::PointerType>(DestIntTy))
1187 if (Val->getType() != DestIntTy) {
1189 if (DL.isBigEndian()) {
1192 uint64_t SrcSize = DL.getTypeSizeInBits(Val->getType());
1193 uint64_t DstSize = DL.getTypeSizeInBits(DestIntTy);
1195 if (SrcSize > DstSize) {
1196 Val = CGF.
Builder.CreateLShr(Val, SrcSize - DstSize,
"coerce.highbits");
1197 Val = CGF.
Builder.CreateTrunc(Val, DestIntTy,
"coerce.val.ii");
1199 Val = CGF.
Builder.CreateZExt(Val, DestIntTy,
"coerce.val.ii");
1200 Val = CGF.
Builder.CreateShl(Val, DstSize - SrcSize,
"coerce.highbits");
1204 Val = CGF.
Builder.CreateIntCast(Val, DestIntTy,
false,
"coerce.val.ii");
1208 if (isa<llvm::PointerType>(Ty))
1209 Val = CGF.
Builder.CreateIntToPtr(Val, Ty,
"coerce.val.ip");
1232 if (llvm::StructType *SrcSTy = dyn_cast<llvm::StructType>(SrcTy)) {
1234 SrcTy = Src.
getType()->getElementType();
1241 if ((isa<llvm::IntegerType>(Ty) || isa<llvm::PointerType>(Ty)) &&
1242 (isa<llvm::IntegerType>(SrcTy) || isa<llvm::PointerType>(SrcTy))) {
1248 if (SrcSize >= DstSize) {
1265 llvm::ConstantInt::get(CGF.
IntPtrTy, SrcSize),
1275 Address Dest,
bool DestIsVolatile) {
1277 if (llvm::StructType *STy =
1278 dyn_cast<llvm::StructType>(Val->getType())) {
1279 const llvm::StructLayout *Layout =
1282 for (
unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
1305 if (SrcTy == DstTy) {
1312 if (llvm::StructType *DstSTy = dyn_cast<llvm::StructType>(DstTy)) {
1314 DstTy = Dst.
getType()->getElementType();
1319 if ((isa<llvm::IntegerType>(SrcTy) || isa<llvm::PointerType>(SrcTy)) &&
1320 (isa<llvm::IntegerType>(DstTy) || isa<llvm::PointerType>(DstTy))) {
1329 if (SrcSize <= DstSize) {
1347 llvm::ConstantInt::get(CGF.
IntPtrTy, DstSize),
1367 class ClangToLLVMArgMapping {
1368 static const unsigned InvalidIndex = ~0U;
1369 unsigned InallocaArgNo;
1371 unsigned TotalIRArgs;
1375 unsigned PaddingArgIndex;
1378 unsigned FirstArgIndex;
1379 unsigned NumberOfArgs;
1382 : PaddingArgIndex(InvalidIndex), FirstArgIndex(InvalidIndex),
1386 SmallVector<IRArgs, 8> ArgInfo;
1390 bool OnlyRequiredArgs =
false)
1391 : InallocaArgNo(InvalidIndex), SRetArgNo(InvalidIndex), TotalIRArgs(0),
1393 construct(Context, FI, OnlyRequiredArgs);
1396 bool hasInallocaArg()
const {
return InallocaArgNo != InvalidIndex; }
1397 unsigned getInallocaArgNo()
const {
1398 assert(hasInallocaArg());
1399 return InallocaArgNo;
1402 bool hasSRetArg()
const {
return SRetArgNo != InvalidIndex; }
1403 unsigned getSRetArgNo()
const {
1404 assert(hasSRetArg());
1408 unsigned totalIRArgs()
const {
return TotalIRArgs; }
1410 bool hasPaddingArg(
unsigned ArgNo)
const {
1411 assert(ArgNo < ArgInfo.size());
1412 return ArgInfo[ArgNo].PaddingArgIndex != InvalidIndex;
1414 unsigned getPaddingArgNo(
unsigned ArgNo)
const {
1415 assert(hasPaddingArg(ArgNo));
1416 return ArgInfo[ArgNo].PaddingArgIndex;
1421 std::pair<unsigned, unsigned> getIRArgs(
unsigned ArgNo)
const {
1422 assert(ArgNo < ArgInfo.size());
1423 return std::make_pair(ArgInfo[ArgNo].FirstArgIndex,
1424 ArgInfo[ArgNo].NumberOfArgs);
1429 bool OnlyRequiredArgs);
1432 void ClangToLLVMArgMapping::construct(
const ASTContext &Context,
1434 bool OnlyRequiredArgs) {
1435 unsigned IRArgNo = 0;
1436 bool SwapThisWithSRet =
false;
1441 SRetArgNo = SwapThisWithSRet ? 1 : IRArgNo++;
1452 auto &IRArgs = ArgInfo[ArgNo];
1455 IRArgs.PaddingArgIndex = IRArgNo++;
1461 llvm::StructType *STy = dyn_cast<llvm::StructType>(AI.
getCoerceToType());
1463 IRArgs.NumberOfArgs = STy->getNumElements();
1465 IRArgs.NumberOfArgs = 1;
1470 IRArgs.NumberOfArgs = 1;
1475 IRArgs.NumberOfArgs = 0;
1485 if (IRArgs.NumberOfArgs > 0) {
1486 IRArgs.FirstArgIndex = IRArgNo;
1487 IRArgNo += IRArgs.NumberOfArgs;
1492 if (IRArgNo == 1 && SwapThisWithSRet)
1495 assert(ArgNo == ArgInfo.size());
1498 InallocaArgNo = IRArgNo++;
1500 TotalIRArgs = IRArgNo;
1508 return RI.
isIndirect() || (RI.isInAlloca() && RI.getInAllocaSRet());
1512 return ReturnTypeUsesSRet(FI) &&
1513 getTargetCodeGenInfo().doesReturnSlotInterfereWithArgs();
1518 switch (BT->getKind()) {
1521 case BuiltinType::Float:
1523 case BuiltinType::Double:
1525 case BuiltinType::LongDouble:
1536 if (BT->getKind() == BuiltinType::LongDouble)
1549 llvm::FunctionType *
1552 bool Inserted = FunctionsBeingProcessed.insert(&FI).second;
1554 assert(Inserted &&
"Recursively being processed?");
1560 llvm_unreachable(
"Invalid ABI kind for return argument");
1573 resultType = llvm::PointerType::get(ty, addressSpace);
1589 ClangToLLVMArgMapping IRFunctionArgs(
getContext(), FI,
true);
1593 if (IRFunctionArgs.hasSRetArg()) {
1597 ArgTypes[IRFunctionArgs.getSRetArgNo()] =
1598 llvm::PointerType::get(Ty, AddressSpace);
1602 if (IRFunctionArgs.hasInallocaArg()) {
1605 ArgTypes[IRFunctionArgs.getInallocaArgNo()] = ArgStruct->getPointerTo();
1612 for (; it != ie; ++it, ++ArgNo) {
1616 if (IRFunctionArgs.hasPaddingArg(ArgNo))
1617 ArgTypes[IRFunctionArgs.getPaddingArgNo(ArgNo)] =
1620 unsigned FirstIRArg, NumIRArgs;
1621 std::tie(FirstIRArg, NumIRArgs) = IRFunctionArgs.getIRArgs(ArgNo);
1626 assert(NumIRArgs == 0);
1630 assert(NumIRArgs == 1);
1633 ArgTypes[FirstIRArg] = LTy->getPointerTo(
1634 CGM.getDataLayout().getAllocaAddrSpace());
1643 llvm::StructType *st = dyn_cast<llvm::StructType>(argType);
1645 assert(NumIRArgs == st->getNumElements());
1646 for (
unsigned i = 0, e = st->getNumElements(); i != e; ++i)
1647 ArgTypes[FirstIRArg + i] = st->getElementType(i);
1649 assert(NumIRArgs == 1);
1650 ArgTypes[FirstIRArg] = argType;
1656 auto ArgTypesIter = ArgTypes.begin() + FirstIRArg;
1658 *ArgTypesIter++ = EltTy;
1660 assert(ArgTypesIter == ArgTypes.begin() + FirstIRArg + NumIRArgs);
1665 auto ArgTypesIter = ArgTypes.begin() + FirstIRArg;
1667 assert(ArgTypesIter == ArgTypes.begin() + FirstIRArg + NumIRArgs);
1672 bool Erased = FunctionsBeingProcessed.erase(&FI); (void)Erased;
1673 assert(Erased &&
"Not in set?");
1675 return llvm::FunctionType::get(resultType, ArgTypes, FI.
isVariadic());
1686 if (isa<CXXDestructorDecl>(MD))
1695 llvm::AttrBuilder &FuncAttrs,
1702 FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
1705 void CodeGenModule::ConstructDefaultFnAttrList(StringRef Name,
bool HasOptnone,
1706 bool AttrOnCallSite,
1707 llvm::AttrBuilder &FuncAttrs) {
1710 if (CodeGenOpts.OptimizeSize)
1711 FuncAttrs.addAttribute(llvm::Attribute::OptimizeForSize);
1712 if (CodeGenOpts.OptimizeSize == 2)
1713 FuncAttrs.addAttribute(llvm::Attribute::MinSize);
1716 if (CodeGenOpts.DisableRedZone)
1717 FuncAttrs.addAttribute(llvm::Attribute::NoRedZone);
1718 if (CodeGenOpts.IndirectTlsSegRefs)
1719 FuncAttrs.addAttribute(
"indirect-tls-seg-refs");
1720 if (CodeGenOpts.NoImplicitFloat)
1721 FuncAttrs.addAttribute(llvm::Attribute::NoImplicitFloat);
1723 if (AttrOnCallSite) {
1725 if (!CodeGenOpts.SimplifyLibCalls ||
1726 CodeGenOpts.isNoBuiltinFunc(Name.data()))
1727 FuncAttrs.addAttribute(llvm::Attribute::NoBuiltin);
1728 if (!CodeGenOpts.TrapFuncName.empty())
1729 FuncAttrs.addAttribute(
"trap-func-name", CodeGenOpts.TrapFuncName);
1732 if (!CodeGenOpts.DisableFPElim) {
1733 FuncAttrs.addAttribute(
"no-frame-pointer-elim",
"false");
1734 }
else if (CodeGenOpts.OmitLeafFramePointer) {
1735 FuncAttrs.addAttribute(
"no-frame-pointer-elim",
"false");
1736 FuncAttrs.addAttribute(
"no-frame-pointer-elim-non-leaf");
1738 FuncAttrs.addAttribute(
"no-frame-pointer-elim",
"true");
1739 FuncAttrs.addAttribute(
"no-frame-pointer-elim-non-leaf");
1742 FuncAttrs.addAttribute(
"less-precise-fpmad",
1743 llvm::toStringRef(CodeGenOpts.LessPreciseFPMAD));
1745 if (CodeGenOpts.NullPointerIsValid)
1746 FuncAttrs.addAttribute(
"null-pointer-is-valid",
"true");
1747 if (!CodeGenOpts.FPDenormalMode.empty())
1748 FuncAttrs.addAttribute(
"denormal-fp-math", CodeGenOpts.FPDenormalMode);
1750 FuncAttrs.addAttribute(
"no-trapping-math",
1751 llvm::toStringRef(CodeGenOpts.NoTrappingMath));
1755 if (!CodeGenOpts.StrictFloatCastOverflow)
1756 FuncAttrs.addAttribute(
"strict-float-cast-overflow",
"false");
1760 FuncAttrs.addAttribute(
"no-infs-fp-math",
1761 llvm::toStringRef(CodeGenOpts.NoInfsFPMath));
1762 FuncAttrs.addAttribute(
"no-nans-fp-math",
1763 llvm::toStringRef(CodeGenOpts.NoNaNsFPMath));
1764 FuncAttrs.addAttribute(
"unsafe-fp-math",
1765 llvm::toStringRef(CodeGenOpts.UnsafeFPMath));
1766 FuncAttrs.addAttribute(
"use-soft-float",
1767 llvm::toStringRef(CodeGenOpts.SoftFloat));
1768 FuncAttrs.addAttribute(
"stack-protector-buffer-size",
1769 llvm::utostr(CodeGenOpts.SSPBufferSize));
1770 FuncAttrs.addAttribute(
"no-signed-zeros-fp-math",
1771 llvm::toStringRef(CodeGenOpts.NoSignedZeros));
1772 FuncAttrs.addAttribute(
1773 "correctly-rounded-divide-sqrt-fp-math",
1774 llvm::toStringRef(CodeGenOpts.CorrectlyRoundedDivSqrt));
1776 if (getLangOpts().OpenCL)
1777 FuncAttrs.addAttribute(
"denorms-are-zero",
1778 llvm::toStringRef(CodeGenOpts.FlushDenorm));
1781 const std::vector<std::string> &Recips = CodeGenOpts.Reciprocals;
1782 if (!Recips.empty())
1783 FuncAttrs.addAttribute(
"reciprocal-estimates",
1784 llvm::join(Recips,
","));
1786 if (!CodeGenOpts.PreferVectorWidth.empty() &&
1787 CodeGenOpts.PreferVectorWidth !=
"none")
1788 FuncAttrs.addAttribute(
"prefer-vector-width",
1789 CodeGenOpts.PreferVectorWidth);
1791 if (CodeGenOpts.StackRealignment)
1792 FuncAttrs.addAttribute(
"stackrealign");
1793 if (CodeGenOpts.Backchain)
1794 FuncAttrs.addAttribute(
"backchain");
1798 if (CodeGenOpts.SpeculativeLoadHardening)
1799 FuncAttrs.addAttribute(llvm::Attribute::SpeculativeLoadHardening);
1802 if (getLangOpts().assumeFunctionsAreConvergent()) {
1808 FuncAttrs.addAttribute(llvm::Attribute::Convergent);
1811 if (getLangOpts().CUDA && getLangOpts().CUDAIsDevice) {
1813 FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
1816 if (CodeGenOpts.FlushDenorm)
1817 FuncAttrs.addAttribute(
"nvptx-f32ftz",
"true");
1820 for (StringRef
Attr : CodeGenOpts.DefaultFunctionAttrs) {
1821 StringRef Var,
Value;
1822 std::tie(Var, Value) = Attr.split(
'=');
1823 FuncAttrs.addAttribute(Var, Value);
1828 llvm::AttrBuilder FuncAttrs;
1829 ConstructDefaultFnAttrList(F.getName(),
1830 F.hasFnAttribute(llvm::Attribute::OptimizeNone),
1832 F.addAttributes(llvm::AttributeList::FunctionIndex, FuncAttrs);
1837 llvm::AttributeList &AttrList,
unsigned &
CallingConv,
bool AttrOnCallSite) {
1838 llvm::AttrBuilder FuncAttrs;
1839 llvm::AttrBuilder RetAttrs;
1843 FuncAttrs.addAttribute(llvm::Attribute::NoReturn);
1852 bool HasOptnone =
false;
1855 if (TargetDecl->hasAttr<ReturnsTwiceAttr>())
1856 FuncAttrs.addAttribute(llvm::Attribute::ReturnsTwice);
1857 if (TargetDecl->hasAttr<NoThrowAttr>())
1858 FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
1859 if (TargetDecl->hasAttr<NoReturnAttr>())
1860 FuncAttrs.addAttribute(llvm::Attribute::NoReturn);
1861 if (TargetDecl->hasAttr<ColdAttr>())
1862 FuncAttrs.addAttribute(llvm::Attribute::Cold);
1863 if (TargetDecl->hasAttr<NoDuplicateAttr>())
1864 FuncAttrs.addAttribute(llvm::Attribute::NoDuplicate);
1865 if (TargetDecl->hasAttr<ConvergentAttr>())
1866 FuncAttrs.addAttribute(llvm::Attribute::Convergent);
1867 if (TargetDecl->hasAttr<SpeculativeLoadHardeningAttr>())
1868 FuncAttrs.addAttribute(llvm::Attribute::SpeculativeLoadHardening);
1870 if (
const FunctionDecl *Fn = dyn_cast<FunctionDecl>(TargetDecl)) {
1876 if (Fn->isNoReturn() && !(AttrOnCallSite && MD && MD->
isVirtual()))
1877 FuncAttrs.addAttribute(llvm::Attribute::NoReturn);
1881 if (TargetDecl->hasAttr<ConstAttr>()) {
1882 FuncAttrs.addAttribute(llvm::Attribute::ReadNone);
1883 FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
1884 }
else if (TargetDecl->hasAttr<PureAttr>()) {
1885 FuncAttrs.addAttribute(llvm::Attribute::ReadOnly);
1886 FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
1887 }
else if (TargetDecl->hasAttr<NoAliasAttr>()) {
1888 FuncAttrs.addAttribute(llvm::Attribute::ArgMemOnly);
1889 FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
1891 if (TargetDecl->hasAttr<RestrictAttr>())
1892 RetAttrs.addAttribute(llvm::Attribute::NoAlias);
1893 if (TargetDecl->hasAttr<ReturnsNonNullAttr>() &&
1894 !CodeGenOpts.NullPointerIsValid)
1895 RetAttrs.addAttribute(llvm::Attribute::NonNull);
1896 if (TargetDecl->hasAttr<AnyX86NoCallerSavedRegistersAttr>())
1897 FuncAttrs.addAttribute(
"no_caller_saved_registers");
1898 if (TargetDecl->hasAttr<AnyX86NoCfCheckAttr>())
1899 FuncAttrs.addAttribute(llvm::Attribute::NoCfCheck);
1901 HasOptnone = TargetDecl->
hasAttr<OptimizeNoneAttr>();
1902 if (
auto *AllocSize = TargetDecl->getAttr<AllocSizeAttr>()) {
1904 if (AllocSize->getNumElemsParam().isValid())
1905 NumElemsParam = AllocSize->getNumElemsParam().getLLVMIndex();
1906 FuncAttrs.addAllocSizeAttr(AllocSize->getElemSizeParam().getLLVMIndex(),
1911 ConstructDefaultFnAttrList(Name, HasOptnone, AttrOnCallSite, FuncAttrs);
1913 if (CodeGenOpts.EnableSegmentedStacks &&
1914 !(TargetDecl && TargetDecl->hasAttr<NoSplitStackAttr>()))
1915 FuncAttrs.addAttribute(
"split-stack");
1919 if (TargetDecl && CodeGenOpts.NoPLT) {
1920 if (
auto *Fn = dyn_cast<FunctionDecl>(TargetDecl)) {
1921 if (!Fn->isDefined() && !AttrOnCallSite) {
1922 FuncAttrs.addAttribute(llvm::Attribute::NonLazyBind);
1927 if (TargetDecl && TargetDecl->hasAttr<OpenCLKernelAttr>()) {
1928 if (getLangOpts().OpenCLVersion <= 120) {
1930 FuncAttrs.addAttribute(
"uniform-work-group-size",
"true");
1937 FuncAttrs.addAttribute(
"uniform-work-group-size",
1938 llvm::toStringRef(CodeGenOpts.UniformWGSize));
1942 if (!AttrOnCallSite) {
1943 bool DisableTailCalls =
false;
1945 if (CodeGenOpts.DisableTailCalls)
1946 DisableTailCalls =
true;
1947 else if (TargetDecl) {
1948 if (TargetDecl->hasAttr<DisableTailCallsAttr>() ||
1949 TargetDecl->hasAttr<AnyX86InterruptAttr>())
1950 DisableTailCalls =
true;
1951 else if (CodeGenOpts.NoEscapingBlockTailCalls) {
1952 if (
const auto *BD = dyn_cast<BlockDecl>(TargetDecl))
1953 if (!BD->doesNotEscape())
1954 DisableTailCalls =
true;
1958 FuncAttrs.addAttribute(
"disable-tail-calls",
1959 llvm::toStringRef(DisableTailCalls));
1960 GetCPUAndFeaturesAttributes(CalleeInfo.
getCalleeDecl(), FuncAttrs);
1963 ClangToLLVMArgMapping IRFunctionArgs(
getContext(), FI);
1970 RetAttrs.addAttribute(llvm::Attribute::SExt);
1972 RetAttrs.addAttribute(llvm::Attribute::ZExt);
1976 RetAttrs.addAttribute(llvm::Attribute::InReg);
1984 FuncAttrs.removeAttribute(llvm::Attribute::ReadOnly)
1985 .removeAttribute(llvm::Attribute::ReadNone);
1993 llvm_unreachable(
"Invalid ABI kind for return argument");
1999 RetAttrs.addDereferenceableAttr(
getContext().getTypeSizeInChars(PTy)
2001 else if (
getContext().getTargetAddressSpace(PTy) == 0 &&
2002 !CodeGenOpts.NullPointerIsValid)
2003 RetAttrs.addAttribute(llvm::Attribute::NonNull);
2006 bool hasUsedSRet =
false;
2010 if (IRFunctionArgs.hasSRetArg()) {
2011 llvm::AttrBuilder SRETAttrs;
2013 SRETAttrs.addAttribute(llvm::Attribute::StructRet);
2016 SRETAttrs.addAttribute(llvm::Attribute::InReg);
2017 ArgAttrs[IRFunctionArgs.getSRetArgNo()] =
2022 if (IRFunctionArgs.hasInallocaArg()) {
2023 llvm::AttrBuilder Attrs;
2024 Attrs.addAttribute(llvm::Attribute::InAlloca);
2025 ArgAttrs[IRFunctionArgs.getInallocaArgNo()] =
2032 I != E; ++I, ++ArgNo) {
2035 llvm::AttrBuilder Attrs;
2038 if (IRFunctionArgs.hasPaddingArg(ArgNo)) {
2040 ArgAttrs[IRFunctionArgs.getPaddingArgNo(ArgNo)] =
2041 llvm::AttributeSet::get(
2043 llvm::AttrBuilder().addAttribute(llvm::Attribute::InReg));
2053 Attrs.addAttribute(llvm::Attribute::SExt);
2055 Attrs.addAttribute(llvm::Attribute::ZExt);
2059 Attrs.addAttribute(llvm::Attribute::Nest);
2061 Attrs.addAttribute(llvm::Attribute::InReg);
2066 Attrs.addAttribute(llvm::Attribute::InReg);
2069 Attrs.addAttribute(llvm::Attribute::ByVal);
2091 FuncAttrs.removeAttribute(llvm::Attribute::ReadOnly)
2092 .removeAttribute(llvm::Attribute::ReadNone);
2102 FuncAttrs.removeAttribute(llvm::Attribute::ReadOnly)
2103 .removeAttribute(llvm::Attribute::ReadNone);
2110 Attrs.addDereferenceableAttr(
getContext().getTypeSizeInChars(PTy)
2112 else if (
getContext().getTargetAddressSpace(PTy) == 0 &&
2113 !CodeGenOpts.NullPointerIsValid)
2114 Attrs.addAttribute(llvm::Attribute::NonNull);
2125 Attrs.addAttribute(llvm::Attribute::StructRet);
2130 Attrs.addAttribute(llvm::Attribute::NoAlias);
2134 if (!PTy->isIncompleteType() && PTy->isConstantSizeType()) {
2136 Attrs.addDereferenceableAttr(info.first.getQuantity());
2137 Attrs.addAttribute(llvm::Attribute::getWithAlignment(
getLLVMContext(),
2138 info.second.getQuantity()));
2144 Attrs.addAttribute(llvm::Attribute::SwiftError);
2148 Attrs.addAttribute(llvm::Attribute::SwiftSelf);
2153 Attrs.addAttribute(llvm::Attribute::NoCapture);
2155 if (Attrs.hasAttributes()) {
2156 unsigned FirstIRArg, NumIRArgs;
2157 std::tie(FirstIRArg, NumIRArgs) = IRFunctionArgs.getIRArgs(ArgNo);
2158 for (
unsigned i = 0; i < NumIRArgs; i++)
2159 ArgAttrs[FirstIRArg + i] =
2165 AttrList = llvm::AttributeList::get(
2179 if (value->getType() == varType)
return value;
2181 assert((varType->isIntegerTy() || varType->isFloatingPointTy())
2182 &&
"unexpected promotion type");
2184 if (isa<llvm::IntegerType>(varType))
2185 return CGF.
Builder.CreateTrunc(value, varType,
"arg.unpromote");
2187 return CGF.
Builder.CreateFPCast(value, varType,
"arg.unpromote");
2193 QualType ArgType,
unsigned ArgNo) {
2205 if (
auto ParmNNAttr = PVD->
getAttr<NonNullAttr>())
2212 if (NNAttr->isNonNull(ArgNo))
2222 CopyBackSwiftError(
Address temp,
Address arg) : Temp(temp), Arg(arg) {}
2233 if (CurCodeDecl && CurCodeDecl->hasAttr<NakedAttr>())
2241 if (
const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(CurCodeDecl)) {
2242 if (FD->hasImplicitReturnZero()) {
2243 QualType RetTy = FD->getReturnType().getUnqualifiedType();
2244 llvm::Type* LLVMTy = CGM.getTypes().ConvertType(RetTy);
2245 llvm::Constant* Zero = llvm::Constant::getNullValue(LLVMTy);
2246 Builder.CreateStore(Zero, ReturnValue);
2253 ClangToLLVMArgMapping IRFunctionArgs(CGM.getContext(), FI);
2256 FnArgs.reserve(IRFunctionArgs.totalIRArgs());
2257 for (
auto &Arg : Fn->args()) {
2258 FnArgs.push_back(&Arg);
2260 assert(FnArgs.size() == IRFunctionArgs.totalIRArgs());
2265 const llvm::StructLayout *ArgStructLayout =
nullptr;
2266 if (IRFunctionArgs.hasInallocaArg()) {
2267 ArgStructLayout = CGM.getDataLayout().getStructLayout(FI.
getArgStruct());
2268 ArgStruct =
Address(FnArgs[IRFunctionArgs.getInallocaArgNo()],
2271 assert(ArgStruct.getType() == FI.
getArgStruct()->getPointerTo());
2275 if (IRFunctionArgs.hasSRetArg()) {
2276 auto AI = cast<llvm::Argument>(FnArgs[IRFunctionArgs.getSRetArgNo()]);
2277 AI->setName(
"agg.result");
2278 AI->addAttr(llvm::Attribute::NoAlias);
2285 ArgVals.reserve(Args.size());
2291 assert(FI.
arg_size() == Args.size() &&
2292 "Mismatch between function signature & arguments.");
2295 for (FunctionArgList::const_iterator i = Args.begin(), e = Args.end();
2296 i != e; ++i, ++info_it, ++ArgNo) {
2301 isa<ParmVarDecl>(Arg) && cast<ParmVarDecl>(Arg)->isKNRPromoted();
2306 assert(hasScalarEvaluationKind(Ty) ==
2307 hasScalarEvaluationKind(Arg->
getType()));
2309 unsigned FirstIRArg, NumIRArgs;
2310 std::tie(FirstIRArg, NumIRArgs) = IRFunctionArgs.getIRArgs(ArgNo);
2314 assert(NumIRArgs == 0);
2318 Address V = Builder.CreateStructGEP(ArgStruct, FieldIndex, FieldOffset,
2320 ArgVals.push_back(ParamValue::forIndirect(V));
2325 assert(NumIRArgs == 1);
2328 if (!hasScalarEvaluationKind(Ty)) {
2333 Address AlignedTemp = CreateMemTemp(Ty,
"coerce");
2341 auto SizeVal = llvm::ConstantInt::get(IntPtrTy, Size.
getQuantity());
2342 Address Dst = Builder.CreateBitCast(AlignedTemp, Int8PtrTy);
2343 Address Src = Builder.CreateBitCast(ParamAddr, Int8PtrTy);
2344 Builder.CreateMemCpy(Dst, Src, SizeVal,
false);
2347 ArgVals.push_back(ParamValue::forIndirect(V));
2351 EmitLoadOfScalar(ParamAddr,
false, Ty, Arg->
getBeginLoc());
2355 ArgVals.push_back(ParamValue::forDirect(V));
2367 assert(NumIRArgs == 1);
2369 auto AI = cast<llvm::Argument>(V);
2371 if (
const ParmVarDecl *PVD = dyn_cast<ParmVarDecl>(Arg)) {
2373 PVD->getFunctionScopeIndex()) &&
2374 !CGM.getCodeGenOpts().NullPointerIsValid)
2375 AI->addAttr(llvm::Attribute::NonNull);
2377 QualType OTy = PVD->getOriginalType();
2378 if (
const auto *ArrTy =
2385 QualType ETy = ArrTy->getElementType();
2386 uint64_t ArrSize = ArrTy->getSize().getZExtValue();
2389 llvm::AttrBuilder Attrs;
2390 Attrs.addDereferenceableAttr(
2391 getContext().getTypeSizeInChars(ETy).getQuantity()*ArrSize);
2392 AI->addAttrs(Attrs);
2393 }
else if (
getContext().getTargetAddressSpace(ETy) == 0 &&
2394 !CGM.getCodeGenOpts().NullPointerIsValid) {
2395 AI->addAttr(llvm::Attribute::NonNull);
2398 }
else if (
const auto *ArrTy =
2405 !CGM.getCodeGenOpts().NullPointerIsValid)
2406 AI->addAttr(llvm::Attribute::NonNull);
2409 const auto *AVAttr = PVD->getAttr<AlignValueAttr>();
2411 if (
const auto *TOTy = dyn_cast<TypedefType>(OTy))
2412 AVAttr = TOTy->getDecl()->getAttr<AlignValueAttr>();
2413 if (AVAttr && !SanOpts.has(SanitizerKind::Alignment)) {
2418 EmitScalarExpr(AVAttr->getAlignment());
2419 llvm::ConstantInt *AlignmentCI =
2420 cast<llvm::ConstantInt>(AlignmentValue);
2421 unsigned Alignment =
std::min((
unsigned)AlignmentCI->getZExtValue(),
2422 +llvm::Value::MaximumAlignment);
2423 AI->addAttrs(llvm::AttrBuilder().addAlignmentAttr(Alignment));
2428 AI->addAttr(llvm::Attribute::NoAlias);
2437 CreateMemTemp(pointeeTy, getPointerAlign(),
"swifterror.temp");
2439 llvm::Value *incomingErrorValue = Builder.CreateLoad(arg);
2440 Builder.CreateStore(incomingErrorValue, temp);
2441 V = temp.getPointer();
2446 EHStack.pushCleanup<CopyBackSwiftError>(
NormalCleanup, temp, arg);
2461 if (V->getType() != LTy)
2462 V = Builder.CreateBitCast(V, LTy);
2464 ArgVals.push_back(ParamValue::forDirect(V));
2476 llvm::StructType *STy = dyn_cast<llvm::StructType>(ArgI.
getCoerceToType());
2478 STy->getNumElements() > 1) {
2479 auto SrcLayout = CGM.getDataLayout().getStructLayout(STy);
2480 uint64_t SrcSize = CGM.getDataLayout().getTypeAllocSize(STy);
2482 uint64_t DstSize = CGM.getDataLayout().getTypeAllocSize(DstTy);
2485 if (SrcSize <= DstSize) {
2486 AddrToStoreInto = Builder.CreateElementBitCast(Ptr, STy);
2489 CreateTempAlloca(STy, Alloca.
getAlignment(),
"coerce");
2492 assert(STy->getNumElements() == NumIRArgs);
2493 for (
unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
2494 auto AI = FnArgs[FirstIRArg + i];
2495 AI->setName(Arg->
getName() +
".coerce" + Twine(i));
2498 Builder.CreateStructGEP(AddrToStoreInto, i,
Offset);
2499 Builder.CreateStore(AI, EltPtr);
2502 if (SrcSize > DstSize) {
2503 Builder.CreateMemCpy(Ptr, AddrToStoreInto, DstSize);
2508 assert(NumIRArgs == 1);
2509 auto AI = FnArgs[FirstIRArg];
2510 AI->setName(Arg->
getName() +
".coerce");
2517 EmitLoadOfScalar(Alloca,
false, Ty, Arg->
getBeginLoc());
2520 ArgVals.push_back(ParamValue::forDirect(V));
2522 ArgVals.push_back(ParamValue::forIndirect(Alloca));
2530 ArgVals.push_back(ParamValue::forIndirect(alloca));
2533 alloca = Builder.CreateElementBitCast(alloca, coercionType);
2534 auto layout = CGM.getDataLayout().getStructLayout(coercionType);
2536 unsigned argIndex = FirstIRArg;
2537 for (
unsigned i = 0, e = coercionType->getNumElements(); i != e; ++i) {
2538 llvm::Type *eltType = coercionType->getElementType(i);
2542 auto eltAddr = Builder.CreateStructGEP(alloca, i, layout);
2543 auto elt = FnArgs[argIndex++];
2544 Builder.CreateStore(elt, eltAddr);
2546 assert(argIndex == FirstIRArg + NumIRArgs);
2555 LValue LV = MakeAddrLValue(Alloca, Ty);
2556 ArgVals.push_back(ParamValue::forIndirect(Alloca));
2558 auto FnArgIter = FnArgs.begin() + FirstIRArg;
2559 ExpandTypeFromArgs(Ty, LV, FnArgIter);
2560 assert(FnArgIter == FnArgs.begin() + FirstIRArg + NumIRArgs);
2561 for (
unsigned i = 0, e = NumIRArgs; i != e; ++i) {
2562 auto AI = FnArgs[FirstIRArg + i];
2563 AI->setName(Arg->
getName() +
"." + Twine(i));
2569 assert(NumIRArgs == 0);
2571 if (!hasScalarEvaluationKind(Ty)) {
2572 ArgVals.push_back(ParamValue::forIndirect(CreateMemTemp(Ty)));
2575 ArgVals.push_back(ParamValue::forDirect(U));
2582 for (
int I = Args.size() - 1; I >= 0; --I)
2583 EmitParmDecl(*Args[I], ArgVals[I], I + 1);
2585 for (
unsigned I = 0, E = Args.size(); I != E; ++I)
2586 EmitParmDecl(*Args[I], ArgVals[I], I + 1);
2591 while (insn->use_empty()) {
2592 llvm::BitCastInst *bitcast = dyn_cast<llvm::BitCastInst>(insn);
2593 if (!bitcast)
return;
2596 insn = cast<llvm::Instruction>(bitcast->getOperand(0));
2597 bitcast->eraseFromParent();
2605 llvm::BasicBlock *BB = CGF.
Builder.GetInsertBlock();
2606 if (BB->empty())
return nullptr;
2607 if (&BB->back() != result)
return nullptr;
2612 llvm::Instruction *generator = cast<llvm::Instruction>(result);
2614 SmallVector<llvm::Instruction *, 4> InstsToKill;
2618 while (llvm::BitCastInst *bitcast = dyn_cast<llvm::BitCastInst>(generator)) {
2621 generator = cast<llvm::Instruction>(bitcast->getOperand(0));
2624 if (generator->getNextNode() != bitcast)
2627 InstsToKill.push_back(bitcast);
2634 llvm::CallInst *call = dyn_cast<llvm::CallInst>(generator);
2635 if (!call)
return nullptr;
2637 bool doRetainAutorelease;
2640 doRetainAutorelease =
true;
2643 doRetainAutorelease =
false;
2651 llvm::Instruction *prev = call->getPrevNode();
2653 if (isa<llvm::BitCastInst>(prev)) {
2654 prev = prev->getPrevNode();
2657 assert(isa<llvm::CallInst>(prev));
2658 assert(cast<llvm::CallInst>(prev)->getCalledValue() ==
2660 InstsToKill.push_back(prev);
2666 result = call->getArgOperand(0);
2667 InstsToKill.push_back(call);
2671 while (llvm::BitCastInst *bitcast = dyn_cast<llvm::BitCastInst>(result)) {
2672 if (!bitcast->hasOneUse())
break;
2673 InstsToKill.push_back(bitcast);
2674 result = bitcast->getOperand(0);
2678 for (
auto *I : InstsToKill)
2679 I->eraseFromParent();
2682 if (doRetainAutorelease)
2694 dyn_cast_or_null<ObjCMethodDecl>(CGF.
CurCodeDecl);
2695 if (!method)
return nullptr;
2697 if (!self->getType().isConstQualified())
return nullptr;
2700 llvm::CallInst *retainCall =
2701 dyn_cast<llvm::CallInst>(result->stripPointerCasts());
2707 llvm::Value *retainedValue = retainCall->getArgOperand(0);
2708 llvm::LoadInst *load =
2709 dyn_cast<llvm::LoadInst>(retainedValue->stripPointerCasts());
2710 if (!load || load->isAtomic() || load->isVolatile() ||
2719 assert(retainCall->use_empty());
2720 retainCall->eraseFromParent();
2751 auto GetStoreIfValid = [&CGF](llvm::User *U) -> llvm::StoreInst * {
2752 auto *SI = dyn_cast<llvm::StoreInst>(U);
2757 assert(!SI->isAtomic() && !SI->isVolatile());
2765 llvm::BasicBlock *IP = CGF.
Builder.GetInsertBlock();
2766 if (IP->empty())
return nullptr;
2767 llvm::Instruction *I = &IP->back();
2770 for (llvm::BasicBlock::reverse_iterator II = IP->rbegin(),
2773 if (llvm::IntrinsicInst *Intrinsic =
2774 dyn_cast<llvm::IntrinsicInst>(&*II)) {
2775 if (Intrinsic->getIntrinsicID() == llvm::Intrinsic::lifetime_end) {
2776 const llvm::Value *CastAddr = Intrinsic->getArgOperand(1);
2780 if (isa<llvm::BitCastInst>(&*II) && (CastAddr == &*II))
2788 return GetStoreIfValid(I);
2791 llvm::StoreInst *store =
2793 if (!store)
return nullptr;
2797 llvm::BasicBlock *StoreBB = store->getParent();
2798 llvm::BasicBlock *IP = CGF.
Builder.GetInsertBlock();
2799 while (IP != StoreBB) {
2800 if (!(IP = IP->getSinglePredecessor()))
2814 EmitUnreachable(EndLoc);
2818 if (CurCodeDecl && CurCodeDecl->hasAttr<NakedAttr>()) {
2820 Builder.CreateUnreachable();
2825 if (!ReturnValue.isValid()) {
2826 Builder.CreateRetVoid();
2830 llvm::DebugLoc RetDbgLoc;
2839 assert(hasAggregateEvaluationKind(RetTy));
2841 llvm::Function::arg_iterator EI = CurFn->arg_end();
2846 RV = Builder.CreateAlignedLoad(SRet, getPointerAlign(),
"sret");
2851 auto AI = CurFn->arg_begin();
2854 switch (getEvaluationKind(RetTy)) {
2857 EmitLoadOfComplex(MakeAddrLValue(ReturnValue, RetTy), EndLoc);
2858 EmitStoreOfComplex(RT, MakeNaturalAlignAddrLValue(&*AI, RetTy),
2866 EmitStoreOfScalar(Builder.CreateLoad(ReturnValue),
2867 MakeNaturalAlignAddrLValue(&*AI, RetTy),
2883 if (llvm::StoreInst *SI =
2888 if (EmitRetDbgLoc && !AutoreleaseResult)
2889 RetDbgLoc = SI->getDebugLoc();
2891 RV = SI->getValueOperand();
2892 SI->eraseFromParent();
2895 auto returnValueInst = ReturnValue.getPointer();
2896 if (returnValueInst->use_empty()) {
2897 if (
auto alloca = dyn_cast<llvm::AllocaInst>(returnValueInst)) {
2898 alloca->eraseFromParent();
2905 RV = Builder.CreateLoad(ReturnValue);
2916 if (AutoreleaseResult) {
2924 if (
auto *FD = dyn_cast<FunctionDecl>(CurCodeDecl))
2925 RT = FD->getReturnType();
2926 else if (
auto *MD = dyn_cast<ObjCMethodDecl>(CurCodeDecl))
2927 RT = MD->getReturnType();
2928 else if (isa<BlockDecl>(CurCodeDecl))
2929 RT = BlockInfo->BlockExpression->getFunctionType()->getReturnType();
2931 llvm_unreachable(
"Unexpected function/method type");
2933 assert(getLangOpts().ObjCAutoRefCount &&
2947 auto layout = CGM.getDataLayout().getStructLayout(coercionType);
2951 Address addr = Builder.CreateElementBitCast(ReturnValue, coercionType);
2952 for (
unsigned i = 0, e = coercionType->getNumElements(); i != e; ++i) {
2953 auto coercedEltType = coercionType->getElementType(i);
2957 auto eltAddr = Builder.CreateStructGEP(addr, i, layout);
2958 auto elt = Builder.CreateLoad(eltAddr);
2959 results.push_back(elt);
2963 if (results.size() == 1) {
2971 RV = llvm::UndefValue::get(returnType);
2972 for (
unsigned i = 0, e = results.size(); i != e; ++i) {
2973 RV = Builder.CreateInsertValue(RV, results[i], i);
2980 llvm_unreachable(
"Invalid ABI kind for return argument");
2983 llvm::Instruction *Ret;
2985 EmitReturnValueCheck(RV);
2986 Ret = Builder.CreateRet(RV);
2988 Ret = Builder.CreateRetVoid();
2992 Ret->setDebugLoc(std::move(RetDbgLoc));
3000 ReturnsNonNullAttr *RetNNAttr =
nullptr;
3001 if (SanOpts.has(SanitizerKind::ReturnsNonnullAttribute))
3002 RetNNAttr = CurCodeDecl->getAttr<ReturnsNonNullAttr>();
3004 if (!RetNNAttr && !requiresReturnValueNullabilityCheck())
3012 assert(!requiresReturnValueNullabilityCheck() &&
3013 "Cannot check nullability and the nonnull attribute");
3014 AttrLoc = RetNNAttr->getLocation();
3015 CheckKind = SanitizerKind::ReturnsNonnullAttribute;
3016 Handler = SanitizerHandler::NonnullReturn;
3018 if (
auto *DD = dyn_cast<DeclaratorDecl>(CurCodeDecl))
3019 if (
auto *TSI = DD->getTypeSourceInfo())
3021 AttrLoc = FTL.getReturnLoc().findNullabilityLoc();
3022 CheckKind = SanitizerKind::NullabilityReturn;
3023 Handler = SanitizerHandler::NullabilityReturn;
3030 llvm::BasicBlock *Check = createBasicBlock(
"nullcheck");
3031 llvm::BasicBlock *NoCheck = createBasicBlock(
"no.nullcheck");
3032 llvm::Value *SLocPtr = Builder.CreateLoad(ReturnLocation,
"return.sloc.load");
3033 llvm::Value *CanNullCheck = Builder.CreateIsNotNull(SLocPtr);
3034 if (requiresReturnValueNullabilityCheck())
3036 Builder.CreateAnd(CanNullCheck, RetValNullabilityPrecondition);
3037 Builder.CreateCondBr(CanNullCheck, Check, NoCheck);
3042 llvm::Constant *StaticData[] = {EmitCheckSourceLocation(AttrLoc)};
3044 EmitCheck(std::make_pair(Cond, CheckKind), Handler, StaticData, DynamicData);
3065 llvm::Value *Placeholder = llvm::UndefValue::get(IRPtrTy->getPointerTo());
3086 Address local = GetAddrOfLocalVar(param);
3091 CGM.ErrorUnsupported(param,
"forwarded non-trivially copyable parameter");
3104 }
else if (getLangOpts().ObjCAutoRefCount &&
3105 param->
hasAttr<NSConsumedAttr>() &&
3109 llvm::ConstantPointerNull::get(cast<llvm::PointerType>(ptr->getType()));
3110 Builder.CreateStore(null, local);
3116 args.
add(convertTempToRValue(local, type, loc), type);
3120 if (hasAggregateEvaluationKind(type) && !CurFuncIsThunk &&
3124 CalleeDestructedParamCleanups.lookup(cast<ParmVarDecl>(param));
3126 "cleanup for callee-destructed param not recorded");
3128 llvm::Instruction *isActive = Builder.CreateUnreachable();
3134 return isa<llvm::ConstantPointerNull>(addr);
3143 "shouldn't have writeback for provably null argument");
3145 llvm::BasicBlock *contBB =
nullptr;
3149 bool provablyNonNull = llvm::isKnownNonZero(srcAddr.
getPointer(),
3151 if (!provablyNonNull) {
3157 CGF.
Builder.CreateCondBr(isNull, contBB, writebackBB);
3166 "icr.writeback-cast");
3175 if (writeback.
ToUse) {
3200 if (!provablyNonNull)
3215 for (
const auto &I : llvm::reverse(Cleanups)) {
3217 I.IsActiveIP->eraseFromParent();
3223 if (uop->getOpcode() == UO_AddrOf)
3224 return uop->getSubExpr();
3254 llvm::PointerType *destType =
3278 llvm::ConstantPointerNull::get(
3279 cast<llvm::PointerType>(destType->getElementType()));
3283 llvm::BasicBlock *contBB =
nullptr;
3284 llvm::BasicBlock *originBB =
nullptr;
3289 bool provablyNonNull = llvm::isKnownNonZero(srcAddr.
getPointer(),
3291 if (provablyNonNull) {
3297 finalArgument = CGF.
Builder.CreateSelect(isNull,
3298 llvm::ConstantPointerNull::get(destType),
3304 originBB = CGF.
Builder.GetInsertBlock();
3307 CGF.
Builder.CreateCondBr(isNull, contBB, copyBB);
3309 condEval.
begin(CGF);
3339 if (shouldCopy && !provablyNonNull) {
3340 llvm::BasicBlock *copyBB = CGF.
Builder.GetInsertBlock();
3345 llvm::PHINode *phiToUse = CGF.
Builder.CreatePHI(valueToUse->getType(), 2,
3347 phiToUse->addIncoming(valueToUse, copyBB);
3348 phiToUse->addIncoming(llvm::UndefValue::get(valueToUse->getType()),
3350 valueToUse = phiToUse;
3365 StackBase = CGF.
Builder.CreateCall(F, {},
"inalloca.save");
3372 CGF.
Builder.CreateCall(F, StackBase);
3380 if (!AC.
getDecl() || !(SanOpts.has(SanitizerKind::NonnullAttribute) ||
3381 SanOpts.has(SanitizerKind::NullabilityArg)))
3389 const NonNullAttr *NNAttr =
nullptr;
3390 if (SanOpts.has(SanitizerKind::NonnullAttribute))
3393 bool CanCheckNullability =
false;
3394 if (SanOpts.has(SanitizerKind::NullabilityArg) && !NNAttr && PVD) {
3398 PVD->getTypeSourceInfo();
3401 if (!NNAttr && !CanCheckNullability)
3408 AttrLoc = NNAttr->getLocation();
3409 CheckKind = SanitizerKind::NonnullAttribute;
3410 Handler = SanitizerHandler::NonnullArg;
3412 AttrLoc = PVD->getTypeSourceInfo()->getTypeLoc().findNullabilityLoc();
3413 CheckKind = SanitizerKind::NullabilityArg;
3414 Handler = SanitizerHandler::NullabilityArg;
3421 Builder.CreateICmpNE(V, llvm::Constant::getNullValue(V->getType()));
3422 llvm::Constant *StaticData[] = {
3423 EmitCheckSourceLocation(ArgLoc), EmitCheckSourceLocation(AttrLoc),
3424 llvm::ConstantInt::get(Int32Ty, ArgNo + 1),
3426 EmitCheck(std::make_pair(Cond, CheckKind), Handler, StaticData, None);
3431 llvm::iterator_range<CallExpr::const_arg_iterator> ArgRange,
3433 assert((
int)ArgTypes.size() == (ArgRange.end() - ArgRange.begin()));
3441 CGM.getTarget().getCXXABI().areArgsDestroyedLeftToRightInCallee()
3442 ? Order == EvaluationOrder::ForceLeftToRight
3443 : Order != EvaluationOrder::ForceRightToLeft;
3445 auto MaybeEmitImplicitObjectSize = [&](
unsigned I,
const Expr *Arg,
3455 auto T = Builder.getIntNTy(Context.
getTypeSize(SizeTy));
3456 assert(EmittedArg.getScalarVal() &&
"We emitted nothing for the arg?");
3457 llvm::Value *V = evaluateOrEmitBuiltinObjectSize(Arg, PS->getType(), T,
3458 EmittedArg.getScalarVal());
3463 std::swap(Args.back(), *(&Args.back() - 1));
3467 bool HasInAllocaArgs =
false;
3468 if (CGM.getTarget().getCXXABI().isMicrosoft()) {
3470 I != E && !HasInAllocaArgs; ++I)
3472 if (HasInAllocaArgs) {
3473 assert(
getTarget().getTriple().getArch() == llvm::Triple::x86);
3479 size_t CallArgsStart = Args.size();
3480 for (
unsigned I = 0, E = ArgTypes.size(); I != E; ++I) {
3481 unsigned Idx = LeftToRight ? I : E - I - 1;
3483 unsigned InitialArgSize = Args.size();
3486 assert((!isa<ObjCIndirectCopyRestoreExpr>(*Arg) ||
3487 getContext().hasSameUnqualifiedType((*Arg)->getType(),
3489 (isa<ObjCMethodDecl>(AC.
getDecl()) &&
3490 isObjCMethodWithTypeParams(cast<ObjCMethodDecl>(AC.
getDecl())))) &&
3491 "Argument and parameter types don't match");
3492 EmitCallArg(Args, *Arg, ArgTypes[Idx]);
3495 assert(InitialArgSize + 1 == Args.size() &&
3496 "The code below depends on only adding one arg per EmitCallArg");
3497 (void)InitialArgSize;
3500 if (!Args.back().hasLValue()) {
3501 RValue RVArg = Args.back().getKnownRValue();
3502 EmitNonNullArgCheck(RVArg, ArgTypes[Idx], (*Arg)->getExprLoc(), AC,
3503 ParamsToSkip + Idx);
3507 MaybeEmitImplicitObjectSize(Idx, *Arg, RVArg);
3514 std::reverse(Args.begin() + CallArgsStart, Args.end());
3522 : Addr(Addr), Ty(Ty) {}
3540 struct DisableDebugLocationUpdates {
3542 bool disabledDebugInfo;
3544 if ((disabledDebugInfo = isa<CXXDefaultArgExpr>(E) && CGF.
getDebugInfo()))
3547 ~DisableDebugLocationUpdates() {
3548 if (disabledDebugInfo)
3567 if (!HasLV && RV.isScalar())
3569 else if (!HasLV && RV.isComplex())
3572 auto Addr = HasLV ? LV.
getAddress() : RV.getAggregateAddress();
3577 : RV.isVolatileQualified());
3584 DisableDebugLocationUpdates Dis(*
this, E);
3586 = dyn_cast<ObjCIndirectCopyRestoreExpr>(E)) {
3587 assert(getLangOpts().ObjCAutoRefCount);
3592 "reference binding to unmaterialized r-value!");
3596 return args.
add(EmitReferenceBindingToExpr(E), type);
3599 bool HasAggregateEvalKind = hasAggregateEvaluationKind(type);
3604 if (HasAggregateEvalKind &&
3612 Slot = CreateAggTemp(type,
"agg.tmp");
3614 bool DestroyedInCallee =
true, NeedsEHCleanup =
true;
3616 DestroyedInCallee = RD->hasNonTrivialDestructor();
3620 if (DestroyedInCallee)
3623 EmitAggExpr(E, Slot);
3627 if (DestroyedInCallee && NeedsEHCleanup) {
3634 llvm::Instruction *IsActive = Builder.CreateUnreachable();
3640 if (HasAggregateEvalKind && isa<ImplicitCastExpr>(E) &&
3641 cast<CastExpr>(E)->getCastKind() == CK_LValueToRValue) {
3642 LValue L = EmitLValue(cast<CastExpr>(E)->getSubExpr());
3648 args.
add(EmitAnyExprToTemp(E), type);
3651 QualType CodeGenFunction::getVarArgType(
const Expr *Arg) {
3655 if (!
getTarget().getTriple().isOSWindows())
3672 CodeGenFunction::AddObjCARCExceptionMetadata(llvm::Instruction *Inst) {
3673 if (CGM.getCodeGenOpts().OptimizationLevel != 0 &&
3674 !CGM.getCodeGenOpts().ObjCAutoRefCountExceptions)
3675 Inst->setMetadata(
"clang.arc.no_objc_arc_exceptions",
3676 CGM.getNoObjCARCExceptionsMetadata());
3682 const llvm::Twine &name) {
3683 return EmitNounwindRuntimeCall(callee, None, name);
3690 const llvm::Twine &name) {
3691 llvm::CallInst *call = EmitRuntimeCall(callee, args, name);
3692 call->setDoesNotThrow();
3700 const llvm::Twine &name) {
3701 return EmitRuntimeCall(callee, None, name);
3711 if (!CurrentFuncletPad)
3715 auto *CalleeFn = dyn_cast<llvm::Function>(Callee->stripPointerCasts());
3716 if (CalleeFn && CalleeFn->isIntrinsic() && CalleeFn->doesNotThrow())
3719 BundleList.emplace_back(
"funclet", CurrentFuncletPad);
3727 const llvm::Twine &name) {
3728 llvm::CallInst *call =
3729 Builder.CreateCall(callee, args, getBundlesForFunclet(callee), name);
3730 call->setCallingConv(getRuntimeCC());
3738 getBundlesForFunclet(callee);
3740 if (getInvokeDest()) {
3741 llvm::InvokeInst *invoke =
3742 Builder.CreateInvoke(callee,
3743 getUnreachableBlock(),
3747 invoke->setDoesNotReturn();
3748 invoke->setCallingConv(getRuntimeCC());
3750 llvm::CallInst *call = Builder.CreateCall(callee, args, BundleList);
3751 call->setDoesNotReturn();
3752 call->setCallingConv(getRuntimeCC());
3753 Builder.CreateUnreachable();
3760 const Twine &name) {
3761 return EmitRuntimeCallOrInvoke(callee, None, name);
3768 const Twine &name) {
3769 llvm::CallSite callSite = EmitCallOrInvoke(callee, args, name);
3770 callSite.setCallingConv(getRuntimeCC());
3779 const Twine &Name) {
3780 llvm::BasicBlock *InvokeDest = getInvokeDest();
3782 getBundlesForFunclet(Callee);
3784 llvm::Instruction *Inst;
3786 Inst = Builder.CreateCall(Callee, Args, BundleList, Name);
3788 llvm::BasicBlock *ContBB = createBasicBlock(
"invoke.cont");
3789 Inst = Builder.CreateInvoke(Callee, ContBB, InvokeDest, Args, BundleList,
3796 if (CGM.getLangOpts().ObjCAutoRefCount)
3797 AddObjCARCExceptionMetadata(Inst);
3799 return llvm::CallSite(Inst);
3802 void CodeGenFunction::deferPlaceholderReplacement(llvm::Instruction *Old,
3804 DeferredReplacements.push_back(std::make_pair(Old, New));
3811 llvm::Instruction **callOrInvoke,
3829 const llvm::StructLayout *ArgMemoryLayout =
nullptr;
3830 if (llvm::StructType *ArgStruct = CallInfo.
getArgStruct()) {
3831 const llvm::DataLayout &DL = CGM.getDataLayout();
3832 ArgMemoryLayout = DL.getStructLayout(ArgStruct);
3834 llvm::AllocaInst *AI;
3836 IP = IP->getNextNode();
3837 AI =
new llvm::AllocaInst(ArgStruct, DL.getAllocaAddrSpace(),
3840 AI = CreateTempAlloca(ArgStruct,
"argmem");
3843 AI->setAlignment(Align.getQuantity());
3844 AI->setUsedWithInAlloca(
true);
3845 assert(AI->isUsedWithInAlloca() && !AI->isStaticAlloca());
3846 ArgMemory =
Address(AI, Align);
3850 auto createInAllocaStructGEP = [&](
unsigned FieldIndex) ->
Address {
3853 return Builder.CreateStructGEP(ArgMemory, FieldIndex, FieldOffset);
3856 ClangToLLVMArgMapping IRFunctionArgs(CGM.getContext(), CallInfo);
3865 if (!ReturnValue.
isNull()) {
3868 SRetPtr = CreateMemTemp(RetTy,
"tmp", &SRetAlloca);
3869 if (HaveInsertPoint() && ReturnValue.
isUnused()) {
3872 UnusedReturnSizePtr = EmitLifetimeStart(size, SRetAlloca.
getPointer());
3875 if (IRFunctionArgs.hasSRetArg()) {
3876 IRCallArgs[IRFunctionArgs.getSRetArgNo()] = SRetPtr.getPointer();
3879 Builder.CreateStore(SRetPtr.getPointer(), Addr);
3887 assert(CallInfo.
arg_size() == CallArgs.size() &&
3888 "Mismatch between function signature & arguments.");
3891 for (CallArgList::const_iterator I = CallArgs.begin(), E = CallArgs.end();
3892 I != E; ++I, ++info_it, ++ArgNo) {
3896 if (IRFunctionArgs.hasPaddingArg(ArgNo))
3897 IRCallArgs[IRFunctionArgs.getPaddingArgNo(ArgNo)] =
3900 unsigned FirstIRArg, NumIRArgs;
3901 std::tie(FirstIRArg, NumIRArgs) = IRFunctionArgs.getIRArgs(ArgNo);
3905 assert(NumIRArgs == 0);
3906 assert(
getTarget().getTriple().getArch() == llvm::Triple::x86);
3907 if (I->isAggregate()) {
3910 ? I->getKnownLValue().getAddress()
3911 : I->getKnownRValue().getAggregateAddress();
3912 llvm::Instruction *Placeholder =
3914 CGBuilderTy::InsertPoint IP = Builder.saveIP();
3915 Builder.SetInsertPoint(Placeholder);
3917 Builder.restoreIP(IP);
3918 deferPlaceholderReplacement(Placeholder, Addr.
getPointer());
3922 unsigned AS = Addr.
getType()->getPointerAddressSpace();
3927 if (Addr.
getType() != MemType)
3928 Addr = Builder.CreateBitCast(Addr, MemType);
3929 I->copyInto(*
this, Addr);
3935 assert(NumIRArgs == 1);
3936 if (!I->isAggregate()) {
3938 Address Addr = CreateMemTempWithoutCast(
3942 I->copyInto(*
this, Addr);
3953 ? I->getKnownLValue().getAddress()
3954 : I->getKnownRValue().getAggregateAddress();
3957 const llvm::DataLayout *TD = &CGM.getDataLayout();
3959 assert((FirstIRArg >= IRFuncTy->getNumParams() ||
3960 IRFuncTy->getParamType(FirstIRArg)->getPointerAddressSpace() ==
3961 TD->getAllocaAddrSpace()) &&
3962 "indirect argument must be in alloca address space");
3964 bool NeedCopy =
false;
3967 llvm::getOrEnforceKnownAlignment(V, Align.
getQuantity(), *TD) <
3970 }
else if (I->hasLValue()) {
3971 auto LV = I->getKnownLValue();
3979 if (!getLangOpts().OpenCL) {
3982 AS != CGM.getASTAllocaAddressSpace()))) {
3989 Addr.
getType()->getAddressSpace() != IRFuncTy->
3997 Address AI = CreateMemTempWithoutCast(
4000 I->copyInto(*
this, AI);
4003 auto *T = V->getType()->getPointerElementType()->getPointerTo(
4004 CGM.getDataLayout().getAllocaAddrSpace());
4005 IRCallArgs[FirstIRArg] = getTargetHooks().performAddrSpaceCast(
4014 assert(NumIRArgs == 0);
4022 assert(NumIRArgs == 1);
4024 if (!I->isAggregate())
4025 V = I->getKnownRValue().getScalarVal();
4027 V = Builder.CreateLoad(
4028 I->hasLValue() ? I->getKnownLValue().getAddress()
4029 : I->getKnownRValue().getAggregateAddress());
4035 assert(!swiftErrorTemp.
isValid() &&
"multiple swifterror args");
4042 CreateMemTemp(pointeeTy, getPointerAlign(),
"swifterror.temp");
4044 cast<llvm::AllocaInst>(V)->setSwiftError(
true);
4046 llvm::Value *errorValue = Builder.CreateLoad(swiftErrorArg);
4047 Builder.CreateStore(errorValue, swiftErrorTemp);
4052 V->getType()->isIntegerTy())
4057 if (FirstIRArg < IRFuncTy->getNumParams() &&
4058 V->getType() != IRFuncTy->getParamType(FirstIRArg))
4059 V = Builder.CreateBitCast(V, IRFuncTy->getParamType(FirstIRArg));
4061 IRCallArgs[FirstIRArg] = V;
4067 if (!I->isAggregate()) {
4068 Src = CreateMemTemp(I->Ty,
"coerce");
4069 I->copyInto(*
this, Src);
4071 Src = I->hasLValue() ? I->getKnownLValue().getAddress()
4072 : I->getKnownRValue().getAggregateAddress();
4080 llvm::StructType *STy =
4084 uint64_t SrcSize = CGM.getDataLayout().getTypeAllocSize(SrcTy);
4085 uint64_t DstSize = CGM.getDataLayout().getTypeAllocSize(STy);
4091 if (SrcSize < DstSize) {
4095 Builder.CreateMemCpy(TempAlloca, Src, SrcSize);
4098 Src = Builder.CreateBitCast(Src,
4102 auto SrcLayout = CGM.getDataLayout().getStructLayout(STy);
4103 assert(NumIRArgs == STy->getNumElements());
4104 for (
unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
4108 IRCallArgs[FirstIRArg + i] = LI;
4112 assert(NumIRArgs == 1);
4113 IRCallArgs[FirstIRArg] =
4122 auto layout = CGM.getDataLayout().getStructLayout(coercionType);
4127 if (I->isAggregate()) {
4128 addr = I->hasLValue() ? I->getKnownLValue().getAddress()
4129 : I->getKnownRValue().getAggregateAddress();
4132 RValue RV = I->getKnownRValue();
4136 auto scalarSize = CGM.getDataLayout().getTypeAllocSize(scalarType);
4137 auto scalarAlign = CGM.getDataLayout().getPrefTypeAlignment(scalarType);
4142 layout->getAlignment(), scalarAlign)),
4144 nullptr, &AllocaAddr);
4145 tempSize = EmitLifetimeStart(scalarSize, AllocaAddr.
getPointer());
4150 addr = Builder.CreateElementBitCast(addr, coercionType);
4152 unsigned IRArgPos = FirstIRArg;
4153 for (
unsigned i = 0, e = coercionType->getNumElements(); i != e; ++i) {
4154 llvm::Type *eltType = coercionType->getElementType(i);
4156 Address eltAddr = Builder.CreateStructGEP(addr, i, layout);
4158 IRCallArgs[IRArgPos++] = elt;
4160 assert(IRArgPos == FirstIRArg + NumIRArgs);
4163 EmitLifetimeEnd(tempSize, AllocaAddr.
getPointer());
4170 unsigned IRArgPos = FirstIRArg;
4171 ExpandTypeToArgs(I->Ty, *I, IRFuncTy, IRCallArgs, IRArgPos);
4172 assert(IRArgPos == FirstIRArg + NumIRArgs);
4188 unsigned CalleeAS = CalleePtr->getType()->getPointerAddressSpace();
4189 auto FnTy = getTypes().GetFunctionType(CallInfo)->getPointerTo(CalleeAS);
4190 CalleePtr = Builder.CreateBitCast(CalleePtr, FnTy);
4193 IRFuncTy->getParamType(IRFuncTy->getNumParams() - 1);
4194 if (Arg->getType() != LastParamTy) {
4198 llvm::StructType *DeclaredTy = cast<llvm::StructType>(
4199 cast<llvm::PointerType>(LastParamTy)->getElementType());
4200 assert(DeclaredTy->getNumElements() == FullTy->getNumElements());
4201 for (llvm::StructType::element_iterator DI = DeclaredTy->element_begin(),
4202 DE = DeclaredTy->element_end(),
4203 FI = FullTy->element_begin();
4204 DI != DE; ++DI, ++FI)
4207 Arg = Builder.CreateBitCast(Arg, LastParamTy);
4210 assert(IRFunctionArgs.hasInallocaArg());
4211 IRCallArgs[IRFunctionArgs.getInallocaArgNo()] = Arg;
4223 llvm::FunctionType *CalleeFT =
4224 cast<llvm::FunctionType>(Ptr->getType()->getPointerElementType());
4225 if (!CalleeFT->isVarArg())
4228 llvm::ConstantExpr *CE = dyn_cast<llvm::ConstantExpr>(Ptr);
4229 if (!CE || CE->getOpcode() != llvm::Instruction::BitCast)
4232 llvm::Function *OrigFn = dyn_cast<llvm::Function>(CE->getOperand(0));
4236 llvm::FunctionType *OrigFT = OrigFn->getFunctionType();
4240 if (OrigFT->isVarArg() ||
4241 OrigFT->getNumParams() != CalleeFT->getNumParams() ||
4242 OrigFT->getReturnType() != CalleeFT->getReturnType())
4245 for (
unsigned i = 0, e = OrigFT->getNumParams(); i != e; ++i)
4246 if (OrigFT->getParamType(i) != CalleeFT->getParamType(i))
4251 CalleePtr = simplifyVariadicCallee(CalleePtr);
4265 assert(IRCallArgs.size() == IRFuncTy->getNumParams() || IRFuncTy->isVarArg());
4266 for (
unsigned i = 0; i < IRCallArgs.size(); ++i) {
4268 if (IRFunctionArgs.hasInallocaArg() &&
4269 i == IRFunctionArgs.getInallocaArgNo())
4271 if (i < IRFuncTy->getNumParams())
4272 assert(IRCallArgs[i]->getType() == IRFuncTy->getParamType(i));
4277 for (
unsigned i = 0; i < IRCallArgs.size(); ++i) {
4278 if (
auto *VT = dyn_cast<llvm::VectorType>(IRCallArgs[i]->getType()))
4279 LargestVectorWidth =
std::max(LargestVectorWidth,
4280 VT->getPrimitiveSizeInBits());
4285 llvm::AttributeList Attrs;
4286 CGM.ConstructAttributeList(CalleePtr->getName(), CallInfo,
4295 if (CurCodeDecl && CurCodeDecl->hasAttr<FlattenAttr>() &&
4302 Attrs.addAttribute(
getLLVMContext(), llvm::AttributeList::FunctionIndex,
4303 llvm::Attribute::AlwaysInline);
4307 if (isSEHTryScope()) {
4309 Attrs.addAttribute(
getLLVMContext(), llvm::AttributeList::FunctionIndex,
4310 llvm::Attribute::NoInline);
4315 if (currentFunctionUsesSEHTry()) {
4317 CannotThrow =
false;
4318 }
else if (isCleanupPadScope() &&
4326 CannotThrow = Attrs.hasAttribute(llvm::AttributeList::FunctionIndex,
4327 llvm::Attribute::NoUnwind);
4334 if (UnusedReturnSizePtr)
4336 UnusedReturnSizePtr);
4338 llvm::BasicBlock *InvokeDest = CannotThrow ? nullptr : getInvokeDest();
4341 getBundlesForFunclet(CalleePtr);
4346 CS = Builder.CreateCall(CalleePtr, IRCallArgs, BundleList);
4348 llvm::BasicBlock *Cont = createBasicBlock(
"invoke.cont");
4349 CS = Builder.CreateInvoke(CalleePtr, Cont, InvokeDest, IRCallArgs,
4353 llvm::Instruction *CI = CS.getInstruction();
4358 CS.setAttributes(Attrs);
4359 CS.setCallingConv(static_cast<llvm::CallingConv::ID>(CallingConv));
4363 if (!CI->getType()->isVoidTy())
4364 CI->setName(
"call");
4367 if (
auto *VT = dyn_cast<llvm::VectorType>(CI->getType()))
4368 LargestVectorWidth =
std::max(LargestVectorWidth,
4369 VT->getPrimitiveSizeInBits());
4374 if (!CS.getCalledFunction())
4375 PGO.valueProfile(Builder, llvm::IPVK_IndirectCallTarget,
4380 if (CGM.getLangOpts().ObjCAutoRefCount)
4381 AddObjCARCExceptionMetadata(CI);
4384 if (llvm::CallInst *Call = dyn_cast<llvm::CallInst>(CI)) {
4386 if (TargetDecl && TargetDecl->
hasAttr<NotTailCalledAttr>())
4387 Call->setTailCallKind(llvm::CallInst::TCK_NoTail);
4395 if (CS.doesNotReturn()) {
4396 if (UnusedReturnSizePtr)
4400 if (SanOpts.has(SanitizerKind::Unreachable)) {
4401 if (
auto *F = CS.getCalledFunction())
4402 F->removeFnAttr(llvm::Attribute::NoReturn);
4403 CS.removeAttribute(llvm::AttributeList::FunctionIndex,
4404 llvm::Attribute::NoReturn);
4407 EmitUnreachable(Loc);
4408 Builder.ClearInsertionPoint();
4413 EnsureInsertPoint();
4416 return GetUndefRValue(RetTy);
4420 if (swiftErrorTemp.
isValid()) {
4421 llvm::Value *errorResult = Builder.CreateLoad(swiftErrorTemp);
4422 Builder.CreateStore(errorResult, swiftErrorArg);
4439 auto layout = CGM.getDataLayout().getStructLayout(coercionType);
4442 addr = Builder.CreateElementBitCast(addr, coercionType);
4445 bool requiresExtract = isa<llvm::StructType>(CI->getType());
4447 unsigned unpaddedIndex = 0;
4448 for (
unsigned i = 0, e = coercionType->getNumElements(); i != e; ++i) {
4449 llvm::Type *eltType = coercionType->getElementType(i);
4451 Address eltAddr = Builder.CreateStructGEP(addr, i, layout);
4453 if (requiresExtract)
4454 elt = Builder.CreateExtractValue(elt, unpaddedIndex++);
4456 assert(unpaddedIndex == 0);
4457 Builder.CreateStore(elt, eltAddr);
4466 if (UnusedReturnSizePtr)
4474 return GetUndefRValue(RetTy);
4480 switch (getEvaluationKind(RetTy)) {
4482 llvm::Value *Real = Builder.CreateExtractValue(CI, 0);
4483 llvm::Value *Imag = Builder.CreateExtractValue(CI, 1);
4488 bool DestIsVolatile = ReturnValue.
isVolatile();
4491 DestPtr = CreateMemTemp(RetTy,
"agg.tmp");
4492 DestIsVolatile =
false;
4501 if (V->getType() != RetIRTy)
4502 V = Builder.CreateBitCast(V, RetIRTy);
4506 llvm_unreachable(
"bad evaluation kind");
4510 bool DestIsVolatile = ReturnValue.
isVolatile();
4513 DestPtr = CreateMemTemp(RetTy,
"coerce");
4514 DestIsVolatile =
false;
4525 llvm_unreachable(
"Invalid ABI kind for return argument");
4528 llvm_unreachable(
"Unhandled ABIArgInfo::Kind");
4533 if (Ret.
isScalar() && TargetDecl) {
4534 if (
const auto *AA = TargetDecl->
getAttr<AssumeAlignedAttr>()) {
4536 if (
const auto *
Offset = AA->getOffset())
4537 OffsetValue = EmitScalarExpr(
Offset);
4539 llvm::Value *Alignment = EmitScalarExpr(AA->getAlignment());
4540 llvm::ConstantInt *AlignmentCI = cast<llvm::ConstantInt>(Alignment);
4541 EmitAlignmentAssumption(Ret.
getScalarVal(), RetTy, Loc, AA->getLocation(),
4542 AlignmentCI->getZExtValue(), OffsetValue);
4543 }
else if (
const auto *AA = TargetDecl->
getAttr<AllocAlignAttr>()) {
4544 llvm::Value *AlignmentVal = CallArgs[AA->getParamIndex().getLLVMIndex()]
4547 EmitAlignmentAssumption(Ret.
getScalarVal(), RetTy, Loc, AA->getLocation(),
4557 const CallExpr *CE = getVirtualCallExpr();
4559 CGF, getVirtualMethodDecl(), getThisAddress(), getFunctionType(),
4574 return CGM.getTypes().getABIInfo().EmitMSVAArg(*
this, VAListAddr, Ty);
4575 return CGM.getTypes().getABIInfo().EmitVAArg(*
this, VAListAddr, Ty);
const CGFunctionInfo & arrangeBuiltinFunctionDeclaration(QualType resultType, const FunctionArgList &args)
A builtin function is a freestanding function using the default C conventions.
const llvm::DataLayout & getDataLayout() const
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 ...
CGCXXABI & getCXXABI() const
Ignore - Ignore the argument (treat as void).
ReturnValueSlot - Contains the address where the return value of a function can be stored...
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
QualType getAddrSpaceQualType(QualType T, LangAS AddressSpace) const
Return the uniqued reference to the type for an address space qualified type with the specified type ...
Represents a function declaration or definition.
Address getAddress() const
void end(CodeGenFunction &CGF)
const CGFunctionInfo & arrangeBlockFunctionDeclaration(const FunctionProtoType *type, const FunctionArgList &args)
Block invocation functions are C functions with an implicit parameter.
void EmitReturnValueCheck(llvm::Value *RV)
Emit a test that checks if the return value RV is nonnull.
PointerType - C99 6.7.5.1 - Pointer Declarators.
A (possibly-)qualified type.
bool isBlockPointerType() const
bool ReturnTypeUsesSRet(const CGFunctionInfo &FI)
Return true iff the given type uses 'sret' when used as a return type.
bool getNoCfCheck() const
llvm::Type * ConvertTypeForMem(QualType T)
const CodeGenOptions & getCodeGenOpts() const
bool isReturnsRetained() const
In ARC, whether this function retains its return value.
static void setCUDAKernelCallingConvention(CanQualType &FTy, CodeGenModule &CGM, const FunctionDecl *FD)
Set calling convention for CUDA/HIP kernel.
static CanQual< FunctionProtoType > GetFormalType(const CXXMethodDecl *MD)
Returns the canonical formal type of the given C++ method.
Address CreateMemTemp(QualType T, const Twine &Name="tmp", Address *Alloca=nullptr)
CreateMemTemp - Create a temporary memory object of the given type, with appropriate alignmen and cas...
static void emitWriteback(CodeGenFunction &CGF, const CallArgList::Writeback &writeback)
Emit the actual writing-back of a writeback.
static Address CreateTempAllocaForCoercion(CodeGenFunction &CGF, llvm::Type *Ty, CharUnits MinAlign)
Create a temporary allocation for the purposes of coercion.
CXXDtorType getDtorType() const
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...
const ABIInfo & getABIInfo() const
FunctionType - C99 6.7.5.3 - Function Declarators.
const CGFunctionInfo & arrangeFreeFunctionType(CanQual< FunctionProtoType > Ty, const FunctionDecl *FD)
Arrange the argument and result information for a value of the given freestanding function type...
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
bool hasExtParameterInfos() const
Is there any interesting extra information for any of the parameters of this function type...
unsigned getNumVBases() const
Retrieves the number of virtual base classes of this class.
Extend - Valid only for integer argument types.
Address EmitPointerWithAlignment(const Expr *Addr, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr)
EmitPointerWithAlignment - Given an expression with a pointer type, emit the value and compute our be...
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)
Decl - This represents one declaration (or definition), e.g.
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...
CGCallee prepareConcreteCallee(CodeGenFunction &CGF) const
If this is a delayed callee computation of some sort, prepare a concrete callee.
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...
const Expr * getSubExpr() const
void addUncopiedAggregate(LValue LV, QualType 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...
CanQual< T > getUnqualifiedType() const
Retrieve the unqualified form of this type.
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...
bool isRestrictQualified() const
Determine whether this type is restrict-qualified.
bool isZero() const
isZero - Test whether the quantity equals zero.
static int getExpansionSize(QualType Ty, const ASTContext &Context)
const TargetInfo & getTargetInfo() const
const ParmVarDecl * getParamDecl(unsigned I) const
bool isFuncTypeConvertible(const FunctionType *FT)
isFuncTypeConvertible - Utility to check whether a function type can be converted to an LLVM type (i...
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...
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.
virtual AddedStructorArgs 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...
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.
bool hasWritebacks() const
bool isCoerceAndExpand() const
Default closure variant of a ctor.
Address GetAddrOfLocalVar(const VarDecl *VD)
GetAddrOfLocalVar - Return the address of a local variable.
RValue EmitCall(const CGFunctionInfo &CallInfo, const CGCallee &Callee, ReturnValueSlot ReturnValue, const CallArgList &Args, llvm::Instruction **callOrInvoke, SourceLocation Loc)
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.
CanQualType getCanonicalParamType(QualType T) const
Return the canonical parameter type corresponding to the specific potentially non-canonical one...
Represents a variable declaration or definition.
static void addExtParameterInfosForCall(llvm::SmallVectorImpl< FunctionProtoType::ExtParameterInfo > ¶mInfos, const FunctionProtoType *proto, unsigned prefixArgs, unsigned totalArgs)
llvm::Instruction * getStackBase() const
unsigned getNumParams() const
RAII object to set/unset CodeGenFunction::IsSanitizerScope.
llvm::Value * getFunctionPointer() const
static llvm::Value * CreateCoercedLoad(Address Src, llvm::Type *Ty, CodeGenFunction &CGF)
CreateCoercedLoad - Create a load from.
const T * getAs() const
Member-template getAs<specific type>'.
void setCoerceToType(llvm::Type *T)
ExtInfo withProducesResult(bool producesResult) const
ObjCMethodDecl - Represents an instance or class method declaration.
void EmitNonNullArgCheck(RValue RV, QualType ArgType, SourceLocation ArgLoc, AbstractCallee AC, unsigned ParmNum)
Create a check for a function parameter that may potentially be declared as non-null.
Address CreateConstInBoundsByteGEP(Address Addr, CharUnits Offset, const llvm::Twine &Name="")
Given a pointer to i8, adjust it by a given constant offset.
llvm::Value * getPointer() const
bool shouldUseFusedARCCalls()
const CGFunctionInfo & arrangeCXXStructorDeclaration(const CXXMethodDecl *MD, StructorType Type)
llvm::Type * ConvertTypeForMem(QualType T)
ConvertTypeForMem - Convert type T into a llvm::Type.
Represents a parameter to a function.
bool hasFunctionDecl() const
unsigned getAddressSpace() const
Return the address space that this address resides in.
void add(RValue rvalue, QualType type)
unsigned ClangCallConvToLLVMCallConv(CallingConv CC)
Convert clang calling convention to LLVM callilng convention.
unsigned arg_size() const
virtual unsigned getOpenCLKernelCallingConv() const
Get LLVM calling convention for OpenCL kernel.
Represents a struct/union/class.
void freeArgumentMemory(CodeGenFunction &CGF) const
uint64_t getPointerWidth(unsigned AddrSpace) const
Return the width of pointers on this target, for the specified address space.
An object to manage conditionally-evaluated expressions.
Description of a constructor that was inherited from a base class.
bool usesInAlloca() const
Return true if this function uses inalloca arguments.
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
static void emitWritebacks(CodeGenFunction &CGF, const CallArgList &args)
void EmitFunctionEpilog(const CGFunctionInfo &FI, bool EmitRetDbgLoc, SourceLocation EndLoc)
EmitFunctionEpilog - Emit the target specific LLVM code to return the given temporary.
bool isNothrow(bool ResultIfDependent=false) const
Determine whether this function type has a non-throwing exception specification.
Address getAddress() const
unsigned getRegParm() const
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 ...
ArrayRef< ExtParameterInfo > getExtParameterInfos() const
llvm::Constant * objc_retainAutoreleasedReturnValue
id objc_retainAutoreleasedReturnValue(id);
field_range fields() const
bool isVolatileQualified() const
llvm::Value * EmitARCRetainAutoreleaseReturnValue(llvm::Value *value)
Do a fused retain/autorelease of the given object.
Represents a member of a struct/union/class.
CharUnits getAlignment() const
RequiredArgs getRequiredArgs() const
bool isUsingInAlloca() const
Returns if we're using an inalloca struct to pass arguments in memory.
unsigned getFunctionScopeIndex() const
Returns the index of this parameter in its prototype or method scope.
StructorType getFromDtorType(CXXDtorType T)
llvm::CallInst * EmitRuntimeCall(llvm::Value *callee, const Twine &name="")
Qualifiers::ObjCLifetime getObjCLifetime() const
CharUnits getArgStructAlignment() const
bool isReferenceType() 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.
static AggValueSlot forAddr(Address addr, Qualifiers quals, IsDestructed_t isDestructed, NeedsGCBarriers_t needsGC, IsAliased_t isAliased, Overlap_t mayOverlap, IsZeroed_t isZeroed=IsNotZeroed, IsSanitizerChecked_t isChecked=IsNotSanitizerChecked)
forAddr - Make a slot for an aggregate value.
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
static const EHPersonality & get(CodeGenModule &CGM, const FunctionDecl *FD)
SourceLocation getBeginLoc() const LLVM_READONLY
unsigned getNumParams() const
void EmitStoreOfScalar(llvm::Value *Value, Address Addr, bool Volatile, QualType Ty, AlignmentSource Source=AlignmentSource::Type, bool isInit=false, bool isNontemporal=false)
EmitStoreOfScalar - Store a scalar value to an address, taking care to appropriately convert from the...
void addArgCleanupDeactivation(EHScopeStack::stable_iterator Cleanup, llvm::Instruction *IsActiveIP)
bool getSuppressSRet() const
bool getProducesResult() const
llvm::FunctionType * getFunctionType() const
ARCPreciseLifetime_t isARCPreciseLifetime() const
This parameter (which must have pointer type) uses the special Swift context-pointer ABI treatment...
static bool hasScalarEvaluationKind(QualType T)
static llvm::Value * tryEmitFusedAutoreleaseOfResult(CodeGenFunction &CGF, llvm::Value *result)
Try to emit a fused autorelease of a return result.
void copyInto(CodeGenFunction &CGF, Address A) 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.
llvm::StructType * getCoerceAndExpandType() const
bool hasConstructorVariants() const
Does this ABI have different entrypoints for complete-object and base-subobject constructors?
Wrapper for source info for functions.
CharUnits getAlignment() const
Return the alignment of this pointer.
virtual bool hasMostDerivedReturn(GlobalDecl GD) const
unsigned getInAllocaFieldIndex() const
const_arg_iterator arg_begin() const
CXXCtorType getCtorType() const
const CGFunctionInfo & arrangeCXXConstructorCall(const CallArgList &Args, const CXXConstructorDecl *D, CXXCtorType CtorKind, unsigned ExtraPrefixArgs, unsigned ExtraSuffixArgs, bool PassProtoArgs=true)
Arrange a call to a C++ method, passing the given arguments.
LangAS getAddressSpace() const
void ConstructAttributeList(StringRef Name, const CGFunctionInfo &Info, CGCalleeInfo CalleeInfo, llvm::AttributeList &Attrs, unsigned &CallingConv, bool AttrOnCallSite)
Get the LLVM attributes and calling convention to use for a particular function type.
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 ...
static void appendParameterTypes(const CodeGenTypes &CGT, SmallVectorImpl< CanQualType > &prefix, SmallVectorImpl< FunctionProtoType::ExtParameterInfo > ¶mInfos, CanQual< FunctionProtoType > FPT)
Adds the formal parameters in FPT to the given prefix.
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 ...
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...
Values of this type can never be null.
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...
const CGFunctionInfo & arrangeCXXMethodDeclaration(const CXXMethodDecl *MD)
C++ methods have some special rules and also have implicit parameters.
CharUnits getPointerAlign() const
An ordinary object is located at an address in memory.
CXXDestructorDecl * getDestructor() const
Returns the destructor decl for this class.
llvm::AllocaInst * CreateTempAlloca(llvm::Type *Ty, const Twine &Name="tmp", llvm::Value *ArraySize=nullptr)
CreateTempAlloca - This creates an alloca and inserts it into the entry block if ArraySize is nullptr...
FunctionType::ExtInfo getExtInfo() const
QualType getReturnType() const
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.
const T * getTypePtr() const
Retrieve the underlying type pointer, which refers to a canonical type.
Address getAggregateAddress() const
getAggregateAddr() - Return the Value* of the address of the aggregate.
const Decl * getDecl() const
static CanQualType GetThisType(ASTContext &Context, const CXXRecordDecl *RD, const CXXMethodDecl *MD)
Derives the 'this' type for codegen purposes, i.e.
bool getNoCallerSavedRegs() 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)
virtual void setCUDAKernelCallingConvention(const FunctionType *&FT) const
ExtInfo withCallingConv(CallingConv cc) const
llvm::Value * EmitLoadOfScalar(Address Addr, bool Volatile, QualType Ty, SourceLocation Loc, AlignmentSource Source=AlignmentSource::Type, bool isNontemporal=false)
EmitLoadOfScalar - Load a scalar value from an address, taking care to appropriately convert from the...
const CGFunctionInfo & arrangeUnprototypedObjCMessageSend(QualType returnType, const CallArgList &args)
Represents a K&R-style 'int foo()' function, which has no information available about its arguments...
CanQualType getReturnType() const
Const iterator for iterating over Stmt * arrays that contain only Expr *.
std::pair< llvm::Value *, llvm::Value * > ComplexPairTy
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
ASTContext & getContext() const
Represents a prototype with parameter type info, e.g.
llvm::CallInst * EmitNounwindRuntimeCall(llvm::Value *callee, const Twine &name="")
bool isMicrosoftABI() const
Returns whether this is really a Win64 ABI va_arg expression.
bool allowsOptionalArgs() const
const TargetCodeGenInfo & getTargetCodeGenInfo()
bool getPaddingInReg() const
RValue - This trivial value class is used to represent the result of an expression that is evaluated...
writeback_const_range writebacks() const
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 ...
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
Represents a call to the builtin function __builtin_va_arg.
Address Temporary
The temporary alloca.
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...
llvm::Value * ToUse
A value to "use" after the writeback, or null.
ExtParameterInfo withIsNoEscape(bool NoEscape) const
static AggValueSlot createPlaceholderSlot(CodeGenFunction &CGF, QualType Ty)
This represents one expression.
bool isVariadic() const
Whether this function is variadic.
llvm::Type * getUnpaddedCoerceAndExpandType() const
static bool isInAllocaArgument(CGCXXABI &ABI, QualType type)
bool useObjCFPRetForRealType(RealType T) const
Check whether the given real type should use the "fpret" flavor of Objective-C message passing on thi...
static CanQualType GetReturnType(QualType RetTy)
Returns the "extra-canonicalized" return type, which discards qualifiers on the return type...
std::pair< llvm::Value *, llvm::Value * > getComplexVal() const
getComplexVal - Return the real/imag components of this complex value.
void EmitCallArgs(CallArgList &Args, const T *CallArgTypeInfo, llvm::iterator_range< CallExpr::const_arg_iterator > ArgRange, AbstractCallee AC=AbstractCallee(), unsigned ParamsToSkip=0, EvaluationOrder Order=EvaluationOrder::Default)
EmitCallArgs - Emit call arguments for a function.
const CGFunctionInfo & arrangeNullaryFunction()
A nullary function is a freestanding function of type 'void ()'.
bool getHasRegParm() const
const T * castAs() const
Member-template castAs<specific type>.
bool isObjCRetainableType() const
Represents a C++ destructor within a class.
llvm::Constant * objc_retain
id objc_retain(id);
QualType getTagDeclType(const TagDecl *Decl) const
Return the unique reference to the type for the specified TagDecl (struct/union/class/enum) decl...
llvm::PointerType * getType() const
Return the type of the pointer value.
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
static bool isPaddingForCoerceAndExpand(llvm::Type *eltType)
static SmallVector< CanQualType, 16 > getArgTypesForCall(ASTContext &ctx, const CallArgList &args)
static void eraseUnusedBitCasts(llvm::Instruction *insn)
SmallVector< llvm::OperandBundleDef, 1 > getBundlesForFunclet(llvm::Value *Callee)
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...
const CGFunctionInfo & arrangeBuiltinFunctionCall(QualType resultType, const CallArgList &args)
static Address emitAddressAtOffset(CodeGenFunction &CGF, Address addr, const ABIArgInfo &info)
Qualifiers getTypeQualifiers() const
const CGFunctionInfo & arrangeUnprototypedMustTailThunk(const CXXMethodDecl *MD)
Arrange a thunk that takes 'this' as the first parameter followed by varargs.
static llvm::StoreInst * findDominatingStoreToReturnValue(CodeGenFunction &CGF)
Heuristically search for a dominating store to the return-value slot.
bool canHaveCoerceToType() const
CharUnits alignmentOfArrayElement(CharUnits elementSize) const
Given that this is the alignment of the first element of an array, return the minimum alignment of an...
bool getIndirectByVal() const
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.
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
ASTContext & getContext() const
ImplicitParamDecl * getSelfDecl() const
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.
GlobalDecl - represents a global declaration.
static void BuildAggStore(CodeGenFunction &CGF, llvm::Value *Val, Address Dest, bool DestIsVolatile)
ExprObjectKind getObjectKind() const
getObjectKind - The object kind that this expression produces.
CanQualType getCanonicalTypeUnqualified() const
LValue getKnownLValue() const
The l-value was considered opaque, so the alignment was determined from a type.
RecordDecl * getDecl() const
unsigned getEffectiveCallingConvention() const
getEffectiveCallingConvention - Return the actual calling convention to use, which may depend on the ...
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="")
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.
CanProxy< U > castAs() const
static const Expr * maybeGetUnaryAddrOfOperand(const Expr *E)
NullPointerConstantKind isNullPointerConstant(ASTContext &Ctx, NullPointerConstantValueDependence NPC) const
isNullPointerConstant - C99 6.3.2.3p3 - Test if this reduces down to a Null pointer constant...
Encodes a location in the source.
QualType getReturnType() const
void EmitARCRelease(llvm::Value *value, ARCPreciseLifetime_t precise)
Release the given object.
bool isSRetAfterThis() const
A saved depth on the scope stack.
bool inheritingCtorHasParams(const InheritedConstructor &Inherited, CXXCtorType Type)
Determine if a C++ inheriting constructor should have parameters matching those of its inherited cons...
llvm::CallSite EmitRuntimeCallOrInvoke(llvm::Value *callee, ArrayRef< llvm::Value *> args, const Twine &name="")
Emits a call or invoke instruction to the given runtime function.
ParameterABI getABI() const
Return the ABI treatment of this parameter.
void DeactivateCleanupBlock(EHScopeStack::stable_iterator Cleanup, llvm::Instruction *DominatingIP)
DeactivateCleanupBlock - Deactivates the given cleanup block.
CallingConv getCC() const
const Decl * getDecl() const
QualType getObjCSelType() const
Retrieve the type that corresponds to the predefined Objective-C 'SEL' type.
virtual void computeInfo(CodeGen::CGFunctionInfo &FI) const =0
const CGFunctionInfo & arrangeObjCMethodDeclaration(const ObjCMethodDecl *MD)
Objective-C methods are C functions with some implicit parameters.
Represents a static or instance method of a struct/union/class.
void computeABIInfo(CodeGenModule &CGM, CGFunctionInfo &FI)
Compute the ABI information of a swiftcall function.
const ConstantArrayType * getAsConstantArrayType(QualType T) const
const_arg_iterator arg_end() const
llvm::StructType * getArgStruct() const
Get the struct type used to represent all the arguments in memory.
ObjCEntrypoints & getObjCEntrypoints() const
bool isInstanceMethod() const
CoerceAndExpand - Only valid for aggregate argument types.
void allocateArgumentMemory(CodeGenFunction &CGF)
Specifies that a value-dependent expression should be considered to never be a null pointer constant...
llvm::InlineAsm * retainAutoreleasedReturnValueMarker
A void(void) inline asm to use to mark that the return value of a call will be immediately retain...
bool isAnyPointerType() const
DestructionKind isDestructedType() const
Returns a nonzero value if objects of this type require non-trivial work to clean up after...
bool useObjCFP2RetForComplexLongDouble() const
Check whether _Complex long double should use the "fp2ret" flavor of Objective-C message passing on t...
llvm::LLVMContext & getLLVMContext()
All available information about a concrete callee.
static SmallVector< CanQualType, 16 > getArgTypesForDeclaration(ASTContext &ctx, const FunctionArgList &args)
InAlloca - Pass the argument directly using the LLVM inalloca attribute.
bool ReturnTypeUsesFP2Ret(QualType ResultType)
Return true iff the given type uses 'fp2ret' when used as a return type.
static void AddAttributesFromFunctionProtoType(ASTContext &Ctx, llvm::AttrBuilder &FuncAttrs, const FunctionProtoType *FPT)
bool hasFlexibleArrayMember() const
ExceptionSpecificationType getExceptionSpecType() const
Get the kind of exception specification on this function.
CXXCtorType
C++ constructor types.
CanProxy< U > getAs() const
Retrieve a canonical type pointer with a different static type, upcasting or downcasting as needed...
const CGFunctionInfo & arrangeBlockFunctionCall(const CallArgList &args, const FunctionType *type)
A block function is essentially a free function with an extra implicit argument.
std::pair< CharUnits, CharUnits > getTypeInfoInChars(const Type *T) const
llvm::Type * getPaddingType() const
void setExternallyDestructed(bool destructed=true)
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...
FunctionArgList - Type for representing both the decl and type of parameters to a function...
bool getInAllocaSRet() const
Return true if this field of an inalloca struct should be returned to implement a struct return calli...
llvm::Value * getScalarVal() const
getScalarVal() - Return the Value* of this scalar value.
CallingConv getDefaultCallingConvention(bool IsVariadic, bool IsCXXMethod) const
Retrieves the default calling convention for the current target.
const TargetInfo & getTarget() const
CGFunctionInfo - Class to encapsulate the information about a function definition.
This class organizes the cross-function state that is used while generating LLVM code.
Dataflow Directional Tag Classes.
void EmitCXXDestructorCall(const CXXDestructorDecl *D, CXXDtorType Type, bool ForVirtualBase, bool Delegating, Address This)
ExtInfo getExtInfo() const
static RValue getComplex(llvm::Value *V1, llvm::Value *V2)
CodeGenFunction::ComplexPairTy ComplexPairTy
Address CreateStructGEP(Address Addr, unsigned Index, CharUnits Offset, const llvm::Twine &Name="")
CXXDtorType toCXXDtorType(StructorType T)
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...
void EmitNoreturnRuntimeCallOrInvoke(llvm::Value *callee, ArrayRef< llvm::Value *> args)
Emits a call or invoke to the given noreturn runtime function.
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)
ArrayRef< ExtParameterInfo > getExtParameterInfos() const
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...
Interesting information about a specific parameter that can't simply be reflected in parameter's type...
void EmitARCIntrinsicUse(ArrayRef< llvm::Value *> values)
Given a number of pointers, inform the optimizer that they're being intrinsically used up until this ...
void callCStructDestructor(LValue Dst)
llvm::LoadInst * CreateLoad(Address Addr, const llvm::Twine &Name="")
llvm::IntegerType * IntPtrTy
const CXXRecordDecl * getParent() const
Returns the parent of this method declaration, which is the class in which this method is defined...
llvm::Function * getIntrinsic(unsigned IID, ArrayRef< llvm::Type *> Tys=None)
RValue getRValue(CodeGenFunction &CGF) const
static CGFunctionInfo * create(unsigned llvmCC, bool instanceMethod, bool chainCall, const FunctionType::ExtInfo &extInfo, ArrayRef< ExtParameterInfo > paramInfos, CanQualType resultType, ArrayRef< CanQualType > argTypes, RequiredArgs required)
llvm::StoreInst * CreateStore(llvm::Value *Val, Address Addr, bool IsVolatile=false)
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...
LValue MakeAddrLValue(Address Addr, QualType T, AlignmentSource Source=AlignmentSource::Type)
bool getCanBeFlattened() const
ArrayRef< llvm::Type * > getCoerceAndExpandTypeSequence() const
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)
static bool classof(const OMPClause *T)
bool isConstantSizeType() const
Return true if this is not a variable sized type, according to the rules of C99 6.7.5p3.
QualType getCanonicalTypeInternal() const
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
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.
CharUnits getIndirectAlign() const
Implements C++ ABI-specific code generation functions.
llvm::Type * getElementType() const
Return the type of the values stored in this address.
bool isMSVCXXPersonality() const
This class organizes the cross-module state that is used while lowering AST types to LLVM types...
llvm::StringRef getName() const
Return the IR name of the pointer value.
Expand - Only valid for aggregate argument types.
Base for LValueReferenceType and RValueReferenceType.
void getExpandedTypes(QualType Ty, SmallVectorImpl< llvm::Type *>::iterator &TI)
getExpandedTypes - Expand the type
static std::unique_ptr< TypeExpansion > getTypeExpansion(QualType Ty, const ASTContext &Context)
bool isParamDestroyedInCallee() const
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false)
EmitBlock - Emit the given block.
ABIArgInfo & getReturnInfo()
Represents a base class of a C++ class.
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types...
ASTContext & getContext() const
Pass it on the stack using its defined layout.
llvm::iterator_range< specific_attr_iterator< T > > specific_attrs() const
llvm::Type * GetFunctionTypeForVTable(GlobalDecl GD)
GetFunctionTypeForVTable - Get the LLVM function type for use in a vtable, given a CXXMethodDecl...
LangAS getAddressSpace() const
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
RValue getKnownRValue() const
Represents a C++ struct/union/class.
virtual const CXXRecordDecl * getThisArgumentTypeForMethod(const CXXMethodDecl *MD)
Get the type of the implicit "this" parameter used by a method.
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...
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
virtual RecordArgABI getRecordArgABI(const CXXRecordDecl *RD) const =0
Returns how an argument of the given record type should be passed.
const GlobalDecl getCalleeDecl() const
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.
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
This class is used for builtin types like 'int'.
bool shouldCopy() const
shouldCopy - True if we should do the 'copy' part of the copy-restore.
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.
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
static CallingConv getCallingConventionForDecl(const Decl *D, bool IsWindows)
bool isCanonicalAsParam() const
Determines if this canonical type is furthermore canonical as a parameter.
CGCXXABI & getCXXABI() const
const CGFunctionInfo & arrangeMSCtorClosure(const CXXConstructorDecl *CD, CXXCtorType CT)
__DEVICE__ int max(int __a, int __b)
bool constructsVirtualBase() const
Returns true if the constructed base class is a virtual base class subobject of this declaration's cl...
static void deactivateArgCleanupsBeforeCall(CodeGenFunction &CGF, const CallArgList &CallArgs)
void EmitAggregateCopy(LValue Dest, LValue Src, QualType EltTy, AggValueSlot::Overlap_t MayOverlap, bool isVolatile=false)
EmitAggregateCopy - Emit an aggregate copy.
const FunctionProtoType * getCalleeFunctionProtoType() const
QualType getIntPtrType() const
Return a type compatible with "intptr_t" (C99 7.18.1.4), as defined by the target.
static RValue get(llvm::Value *V)
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 isPointerType() const
__DEVICE__ int min(int __a, int __b)
unsigned getNumRequiredArgs() const
unsigned getDirectOffset() const
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...
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
CXXCtorType toCXXCtorType(StructorType T)
void computeSPIRKernelABIInfo(CodeGenModule &CGM, CGFunctionInfo &FI)
static RValue getAggregate(Address addr, bool isVolatile=false)
bool isUnresolvedExceptionSpec(ExceptionSpecificationType ESpecType)
ExtParameterInfo getExtParameterInfo(unsigned argIndex) const
LValue - This represents an lvalue references.
An abstract representation of regular/ObjC call/message targets.
SourceLocation getBeginLoc() const LLVM_READONLY
Information for lazily generating a cleanup.
virtual CGCallee getVirtualFunctionPointer(CodeGenFunction &CGF, GlobalDecl GD, Address This, llvm::Type *Ty, SourceLocation Loc)=0
Build a virtual function pointer in the ABI-specific way.
llvm::Type * getCoerceToType() const
CGCalleeInfo getAbstractInfo() const
Notes how many arguments were added to the beginning (Prefix) and ending (Suffix) of an arg list...
unsigned getTargetAddressSpace(QualType T) const
void AddDefaultFnAttrs(llvm::Function &F)
Adds attributes to F according to our CodeGenOptions and LangOptions, as though we had emitted it our...
CallArgList - Type for representing both the value and type of arguments in a call.
const CGFunctionInfo & arrangeCXXMethodCall(const CallArgList &args, const FunctionProtoType *type, RequiredArgs required, unsigned numPrefixArgs)
Arrange a call to a C++ method, passing the given arguments.
Represents the canonical version of C arrays with a specified constant size.
bool getIndirectRealign() const
Abstract information about a function or function prototype.
A class which abstracts out some details necessary for making a call.
Attr - This represents one attribute.
This parameter (which must have pointer type) is a Swift indirect result parameter.
static QualType getParamType(Sema &SemaRef, ArrayRef< ResultCandidate > Candidates, unsigned N)
Get the type of the Nth parameter from a given set of overload candidates.
ConstructorUsingShadowDecl * getShadowDecl() const
ArrayRef< ParmVarDecl * > parameters() const
Expr * IgnoreParens() LLVM_READONLY
IgnoreParens - Ignore parentheses.
ArrayRef< CallArgCleanup > getCleanupsToDeactivate() const
CanQualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
static CharUnits getDeclAlign(Expr *E, CharUnits TypeAlign, ASTContext &Context)
A helper function to get the alignment of a Decl referred to by DeclRefExpr or MemberExpr.
llvm::FunctionType * GetFunctionType(const CGFunctionInfo &Info)
GetFunctionType - Get the LLVM function type for.