31 #include "llvm/ADT/StringExtras.h" 32 #include "llvm/Analysis/ValueTracking.h" 33 #include "llvm/IR/Attributes.h" 34 #include "llvm/IR/CallingConv.h" 35 #include "llvm/IR/CallSite.h" 36 #include "llvm/IR/DataLayout.h" 37 #include "llvm/IR/InlineAsm.h" 38 #include "llvm/IR/Intrinsics.h" 39 #include "llvm/IR/IntrinsicInst.h" 40 #include "llvm/Transforms/Utils/Local.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;
66 case CC_Swift:
return llvm::CallingConv::Swift;
108 unsigned totalArgs) {
110 assert(paramInfos.size() <= prefixArgs);
111 assert(proto->
getNumParams() + prefixArgs <= totalArgs);
113 paramInfos.reserve(totalArgs);
116 paramInfos.resize(prefixArgs);
120 paramInfos.push_back(ParamInfo);
122 if (ParamInfo.hasPassObjectSize())
123 paramInfos.emplace_back();
126 assert(paramInfos.size() <= totalArgs &&
127 "Did we forget to insert pass_object_size args?");
129 paramInfos.resize(totalArgs);
139 if (!FPT->hasExtParameterInfos()) {
140 assert(paramInfos.empty() &&
141 "We have paramInfos, but the prototype doesn't?");
142 prefix.append(FPT->param_type_begin(), FPT->param_type_end());
146 unsigned PrefixSize = prefix.size();
150 prefix.reserve(prefix.size() + FPT->getNumParams());
152 auto ExtInfos = FPT->getExtParameterInfos();
153 assert(ExtInfos.size() == FPT->getNumParams());
154 for (
unsigned I = 0, E = FPT->getNumParams(); I != E; ++I) {
155 prefix.push_back(FPT->getParamType(I));
156 if (ExtInfos[I].hasPassObjectSize())
180 FTP->getExtInfo(), paramInfos,
199 if (D->
hasAttr<FastCallAttr>())
205 if (D->
hasAttr<ThisCallAttr>())
208 if (D->
hasAttr<VectorCallAttr>())
214 if (PcsAttr *PCS = D->
getAttr<PcsAttr>())
217 if (D->
hasAttr<IntelOclBiccAttr>())
226 if (D->
hasAttr<PreserveMostAttr>())
229 if (D->
hasAttr<PreserveAllAttr>())
254 *
this,
true, argTypes,
264 assert(!isa<CXXConstructorDecl>(MD) &&
"wrong method for constructors!");
265 assert(!isa<CXXDestructorDecl>(MD) &&
"wrong method for destructors!");
295 bool PassParams =
true;
298 if (
auto *CD = dyn_cast<CXXConstructorDecl>(MD)) {
303 if (
auto Inherited = CD->getInheritedConstructor())
318 if (!paramInfos.empty()) {
321 paramInfos.insert(paramInfos.begin() + 1, AddedArgs.
Prefix,
324 paramInfos.append(AddedArgs.
Suffix,
339 false, argTypes, extInfo,
340 paramInfos, required);
346 for (
auto &arg : args)
354 for (
auto &arg : args)
361 unsigned prefixArgs,
unsigned totalArgs) {
381 unsigned ExtraPrefixArgs,
382 unsigned ExtraSuffixArgs,
383 bool PassProtoArgs) {
386 for (
const auto &Arg : args)
390 unsigned TotalPrefixArgs = 1 + ExtraPrefixArgs;
406 if (PassProtoArgs && FPT->hasExtParameterInfos()) {
412 false, ArgTypes, Info,
413 ParamInfos, Required);
421 if (MD->isInstance())
426 assert(isa<FunctionType>(FTy));
432 noProto->getReturnType(),
false,
465 I->hasAttr<NoEscapeAttr>());
466 extParamInfos.push_back(extParamInfo);
473 if (
getContext().getLangOpts().ObjCAutoRefCount &&
474 MD->
hasAttr<NSReturnsRetainedAttr>())
482 false, argTys, einfo, extParamInfos, required);
517 assert(MD->
isVirtual() &&
"only virtual memptrs have thunks");
535 ArgTys.push_back(*FTP->param_type_begin());
537 ArgTys.push_back(Context.
IntTy);
553 unsigned numExtraRequiredArgs,
555 assert(args.size() >= numExtraRequiredArgs);
565 if (proto->isVariadic())
566 required =
RequiredArgs(proto->getNumParams() + numExtraRequiredArgs);
568 if (proto->hasExtParameterInfos())
578 cast<FunctionNoProtoType>(fnType))) {
584 for (
const auto &arg : args)
601 chainCall ? 1 : 0, chainCall);
621 false,
false, argTypes,
631 for (
const auto &Arg : args)
653 resultType,
false,
false,
665 unsigned numPrefixArgs) {
666 assert(numPrefixArgs + 1 <= args.size() &&
667 "Emitting a call with less args than the required prefix?");
679 false, argTypes, info, paramInfos, required);
691 assert(signature.
arg_size() <= args.size());
692 if (signature.
arg_size() == args.size())
697 if (!sigParamInfos.empty()) {
698 paramInfos.append(sigParamInfos.begin(), sigParamInfos.end());
699 paramInfos.resize(args.size());
731 assert(std::all_of(argTypes.begin(), argTypes.end(),
735 llvm::FoldingSetNodeID
ID;
737 required, resultType, argTypes);
739 void *insertPos =
nullptr;
740 CGFunctionInfo *FI = FunctionInfos.FindNodeOrInsertPos(ID, insertPos);
748 paramInfos, resultType, argTypes, required);
749 FunctionInfos.InsertNode(FI, insertPos);
751 bool inserted = FunctionsBeingProcessed.insert(FI).second;
753 assert(inserted &&
"Recursively being processed?");
756 if (CC == llvm::CallingConv::SPIR_KERNEL) {
773 for (
auto &I : FI->arguments())
774 if (I.info.canHaveCoerceToType() && I.info.getCoerceToType() ==
nullptr)
777 bool erased = FunctionsBeingProcessed.erase(FI); (void)erased;
778 assert(erased &&
"Not in set?");
791 assert(paramInfos.empty() || paramInfos.size() == argTypes.size());
794 operator new(totalSizeToAlloc<ArgInfo, ExtParameterInfo>(
795 argTypes.size() + 1, paramInfos.size()));
798 FI->CallingConvention = llvmCC;
799 FI->EffectiveCallingConvention = llvmCC;
800 FI->ASTCallingConvention = info.
getCC();
801 FI->InstanceMethod = instanceMethod;
802 FI->ChainCall = chainCall;
806 FI->Required = required;
809 FI->ArgStruct =
nullptr;
810 FI->ArgStructAlign = 0;
811 FI->NumArgs = argTypes.size();
812 FI->HasExtParameterInfos = !paramInfos.empty();
813 FI->getArgsBuffer()[0].
type = resultType;
814 for (
unsigned i = 0, e = argTypes.size(); i != e; ++i)
815 FI->getArgsBuffer()[i + 1].
type = argTypes[i];
816 for (
unsigned i = 0, e = paramInfos.size(); i != e; ++i)
817 FI->getExtParameterInfosBuffer()[i] = paramInfos[i];
827 struct TypeExpansion {
828 enum TypeExpansionKind {
840 const TypeExpansionKind
Kind;
842 TypeExpansion(TypeExpansionKind K) :
Kind(K) {}
843 virtual ~TypeExpansion() {}
846 struct ConstantArrayExpansion : TypeExpansion {
850 ConstantArrayExpansion(
QualType EltTy, uint64_t NumElts)
851 : TypeExpansion(TEK_ConstantArray), EltTy(EltTy), NumElts(NumElts) {}
852 static bool classof(
const TypeExpansion *TE) {
853 return TE->Kind == TEK_ConstantArray;
857 struct RecordExpansion : TypeExpansion {
864 : TypeExpansion(TEK_Record), Bases(std::move(Bases)),
865 Fields(std::move(Fields)) {}
866 static bool classof(
const TypeExpansion *TE) {
867 return TE->Kind == TEK_Record;
871 struct ComplexExpansion : TypeExpansion {
875 static bool classof(
const TypeExpansion *TE) {
880 struct NoExpansion : TypeExpansion {
881 NoExpansion() : TypeExpansion(TEK_None) {}
882 static bool classof(
const TypeExpansion *TE) {
883 return TE->Kind == TEK_None;
888 static std::unique_ptr<TypeExpansion>
891 return llvm::make_unique<ConstantArrayExpansion>(
892 AT->getElementType(), AT->getSize().getZExtValue());
899 "Cannot expand structure with flexible array.");
906 for (
const auto *FD : RD->
fields()) {
908 if (FD->isBitField() && FD->getBitWidthValue(Context) == 0)
910 assert(!FD->isBitField() &&
911 "Cannot expand structure with bit-field members.");
913 if (UnionSize < FieldSize) {
914 UnionSize = FieldSize;
919 Fields.push_back(LargestFD);
921 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
922 assert(!CXXRD->isDynamicClass() &&
923 "cannot expand vtable pointers in dynamic classes");
925 Bases.push_back(&BS);
928 for (
const auto *FD : RD->
fields()) {
930 if (FD->isBitField() && FD->getBitWidthValue(Context) == 0)
932 assert(!FD->isBitField() &&
933 "Cannot expand structure with bit-field members.");
934 Fields.push_back(FD);
937 return llvm::make_unique<RecordExpansion>(std::move(Bases),
941 return llvm::make_unique<ComplexExpansion>(CT->getElementType());
943 return llvm::make_unique<NoExpansion>();
948 if (
auto CAExp = dyn_cast<ConstantArrayExpansion>(Exp.get())) {
951 if (
auto RExp = dyn_cast<RecordExpansion>(Exp.get())) {
953 for (
auto BS : RExp->Bases)
955 for (
auto FD : RExp->Fields)
959 if (isa<ComplexExpansion>(Exp.get()))
961 assert(isa<NoExpansion>(Exp.get()));
969 if (
auto CAExp = dyn_cast<ConstantArrayExpansion>(Exp.get())) {
970 for (
int i = 0, n = CAExp->NumElts; i < n; i++) {
973 }
else if (
auto RExp = dyn_cast<RecordExpansion>(Exp.get())) {
974 for (
auto BS : RExp->Bases)
976 for (
auto FD : RExp->Fields)
978 }
else if (
auto CExp = dyn_cast<ComplexExpansion>(Exp.get())) {
983 assert(isa<NoExpansion>(Exp.get()));
989 ConstantArrayExpansion *CAE,
991 llvm::function_ref<
void(
Address)> Fn) {
996 for (
int i = 0, n = CAE->NumElts; i < n; i++) {
999 Fn(
Address(EltAddr, EltAlign));
1003 void CodeGenFunction::ExpandTypeFromArgs(
1006 "Unexpected non-simple lvalue during struct expansion.");
1009 if (
auto CAExp = dyn_cast<ConstantArrayExpansion>(Exp.get())) {
1012 LValue LV = MakeAddrLValue(EltAddr, CAExp->EltTy);
1013 ExpandTypeFromArgs(CAExp->EltTy, LV, AI);
1015 }
else if (
auto RExp = dyn_cast<RecordExpansion>(Exp.get())) {
1025 ExpandTypeFromArgs(BS->getType(), SubLV, AI);
1027 for (
auto FD : RExp->Fields) {
1029 LValue SubLV = EmitLValueForFieldInitialization(LV, FD);
1030 ExpandTypeFromArgs(FD->getType(), SubLV, AI);
1032 }
else if (isa<ComplexExpansion>(Exp.get())) {
1033 auto realValue = *AI++;
1034 auto imagValue = *AI++;
1035 EmitStoreOfComplex(
ComplexPairTy(realValue, imagValue), LV,
true);
1037 assert(isa<NoExpansion>(Exp.get()));
1042 void CodeGenFunction::ExpandTypeToArgs(
1046 if (
auto CAExp = dyn_cast<ConstantArrayExpansion>(Exp.get())) {
1051 ExpandTypeToArgs(CAExp->EltTy, EltRV, IRFuncTy, IRCallArgs, IRCallArgPos);
1053 }
else if (
auto RExp = dyn_cast<RecordExpansion>(Exp.get())) {
1063 ExpandTypeToArgs(BS->getType(), BaseRV, IRFuncTy, IRCallArgs,
1067 LValue LV = MakeAddrLValue(This, Ty);
1068 for (
auto FD : RExp->Fields) {
1070 ExpandTypeToArgs(FD->getType(), FldRV, IRFuncTy, IRCallArgs,
1073 }
else if (isa<ComplexExpansion>(Exp.get())) {
1075 IRCallArgs[IRCallArgPos++] = CV.first;
1076 IRCallArgs[IRCallArgPos++] = CV.second;
1078 assert(isa<NoExpansion>(Exp.get()));
1080 "Unexpected non-scalar rvalue during struct expansion.");
1084 if (IRCallArgPos < IRFuncTy->getNumParams() &&
1085 V->getType() != IRFuncTy->getParamType(IRCallArgPos))
1086 V = Builder.CreateBitCast(V, IRFuncTy->getParamType(IRCallArgPos));
1088 IRCallArgs[IRCallArgPos++] = V;
1108 llvm::StructType *SrcSTy,
1111 if (SrcSTy->getNumElements() == 0)
return SrcPtr;
1113 llvm::Type *FirstElt = SrcSTy->getElementType(0);
1119 uint64_t FirstEltSize =
1121 if (FirstEltSize < DstSize &&
1130 if (llvm::StructType *SrcSTy = dyn_cast<llvm::StructType>(SrcTy))
1146 if (Val->getType() == Ty)
1149 if (isa<llvm::PointerType>(Val->getType())) {
1151 if (isa<llvm::PointerType>(Ty))
1159 if (isa<llvm::PointerType>(DestIntTy))
1162 if (Val->getType() != DestIntTy) {
1164 if (DL.isBigEndian()) {
1167 uint64_t SrcSize = DL.getTypeSizeInBits(Val->getType());
1168 uint64_t DstSize = DL.getTypeSizeInBits(DestIntTy);
1170 if (SrcSize > DstSize) {
1171 Val = CGF.
Builder.CreateLShr(Val, SrcSize - DstSize,
"coerce.highbits");
1172 Val = CGF.
Builder.CreateTrunc(Val, DestIntTy,
"coerce.val.ii");
1174 Val = CGF.
Builder.CreateZExt(Val, DestIntTy,
"coerce.val.ii");
1175 Val = CGF.
Builder.CreateShl(Val, DstSize - SrcSize,
"coerce.highbits");
1179 Val = CGF.
Builder.CreateIntCast(Val, DestIntTy,
false,
"coerce.val.ii");
1183 if (isa<llvm::PointerType>(Ty))
1184 Val = CGF.
Builder.CreateIntToPtr(Val, Ty,
"coerce.val.ip");
1207 if (llvm::StructType *SrcSTy = dyn_cast<llvm::StructType>(SrcTy)) {
1209 SrcTy = Src.
getType()->getElementType();
1216 if ((isa<llvm::IntegerType>(Ty) || isa<llvm::PointerType>(Ty)) &&
1217 (isa<llvm::IntegerType>(SrcTy) || isa<llvm::PointerType>(SrcTy))) {
1223 if (SrcSize >= DstSize) {
1240 llvm::ConstantInt::get(CGF.
IntPtrTy, SrcSize),
1250 Address Dest,
bool DestIsVolatile) {
1252 if (llvm::StructType *STy =
1253 dyn_cast<llvm::StructType>(Val->getType())) {
1254 const llvm::StructLayout *Layout =
1257 for (
unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
1280 if (SrcTy == DstTy) {
1287 if (llvm::StructType *DstSTy = dyn_cast<llvm::StructType>(DstTy)) {
1289 DstTy = Dst.
getType()->getElementType();
1294 if ((isa<llvm::IntegerType>(SrcTy) || isa<llvm::PointerType>(SrcTy)) &&
1295 (isa<llvm::IntegerType>(DstTy) || isa<llvm::PointerType>(DstTy))) {
1304 if (SrcSize <= DstSize) {
1322 llvm::ConstantInt::get(CGF.
IntPtrTy, DstSize),
1342 class ClangToLLVMArgMapping {
1343 static const unsigned InvalidIndex = ~0U;
1344 unsigned InallocaArgNo;
1346 unsigned TotalIRArgs;
1350 unsigned PaddingArgIndex;
1353 unsigned FirstArgIndex;
1354 unsigned NumberOfArgs;
1357 : PaddingArgIndex(InvalidIndex), FirstArgIndex(InvalidIndex),
1365 bool OnlyRequiredArgs =
false)
1366 : InallocaArgNo(InvalidIndex), SRetArgNo(InvalidIndex), TotalIRArgs(0),
1368 construct(Context, FI, OnlyRequiredArgs);
1371 bool hasInallocaArg()
const {
return InallocaArgNo != InvalidIndex; }
1372 unsigned getInallocaArgNo()
const {
1373 assert(hasInallocaArg());
1374 return InallocaArgNo;
1377 bool hasSRetArg()
const {
return SRetArgNo != InvalidIndex; }
1378 unsigned getSRetArgNo()
const {
1379 assert(hasSRetArg());
1383 unsigned totalIRArgs()
const {
return TotalIRArgs; }
1385 bool hasPaddingArg(
unsigned ArgNo)
const {
1386 assert(ArgNo < ArgInfo.size());
1387 return ArgInfo[ArgNo].PaddingArgIndex != InvalidIndex;
1389 unsigned getPaddingArgNo(
unsigned ArgNo)
const {
1390 assert(hasPaddingArg(ArgNo));
1391 return ArgInfo[ArgNo].PaddingArgIndex;
1396 std::pair<unsigned, unsigned> getIRArgs(
unsigned ArgNo)
const {
1397 assert(ArgNo < ArgInfo.size());
1398 return std::make_pair(ArgInfo[ArgNo].FirstArgIndex,
1399 ArgInfo[ArgNo].NumberOfArgs);
1404 bool OnlyRequiredArgs);
1407 void ClangToLLVMArgMapping::construct(
const ASTContext &Context,
1409 bool OnlyRequiredArgs) {
1410 unsigned IRArgNo = 0;
1411 bool SwapThisWithSRet =
false;
1416 SRetArgNo = SwapThisWithSRet ? 1 : IRArgNo++;
1427 auto &IRArgs = ArgInfo[ArgNo];
1430 IRArgs.PaddingArgIndex = IRArgNo++;
1436 llvm::StructType *STy = dyn_cast<llvm::StructType>(AI.
getCoerceToType());
1438 IRArgs.NumberOfArgs = STy->getNumElements();
1440 IRArgs.NumberOfArgs = 1;
1445 IRArgs.NumberOfArgs = 1;
1450 IRArgs.NumberOfArgs = 0;
1460 if (IRArgs.NumberOfArgs > 0) {
1461 IRArgs.FirstArgIndex = IRArgNo;
1462 IRArgNo += IRArgs.NumberOfArgs;
1467 if (IRArgNo == 1 && SwapThisWithSRet)
1470 assert(ArgNo == ArgInfo.size());
1473 InallocaArgNo = IRArgNo++;
1475 TotalIRArgs = IRArgNo;
1486 return ReturnTypeUsesSRet(FI) &&
1487 getTargetCodeGenInfo().doesReturnSlotInterfereWithArgs();
1492 switch (BT->getKind()) {
1495 case BuiltinType::Float:
1497 case BuiltinType::Double:
1499 case BuiltinType::LongDouble:
1510 if (BT->getKind() == BuiltinType::LongDouble)
1523 llvm::FunctionType *
1526 bool Inserted = FunctionsBeingProcessed.insert(&FI).second;
1528 assert(Inserted &&
"Recursively being processed?");
1534 llvm_unreachable(
"Invalid ABI kind for return argument");
1547 resultType = llvm::PointerType::get(ty, addressSpace);
1563 ClangToLLVMArgMapping IRFunctionArgs(
getContext(), FI,
true);
1567 if (IRFunctionArgs.hasSRetArg()) {
1571 ArgTypes[IRFunctionArgs.getSRetArgNo()] =
1572 llvm::PointerType::get(Ty, AddressSpace);
1576 if (IRFunctionArgs.hasInallocaArg()) {
1579 ArgTypes[IRFunctionArgs.getInallocaArgNo()] = ArgStruct->getPointerTo();
1586 for (; it != ie; ++it, ++ArgNo) {
1590 if (IRFunctionArgs.hasPaddingArg(ArgNo))
1591 ArgTypes[IRFunctionArgs.getPaddingArgNo(ArgNo)] =
1594 unsigned FirstIRArg, NumIRArgs;
1595 std::tie(FirstIRArg, NumIRArgs) = IRFunctionArgs.getIRArgs(ArgNo);
1600 assert(NumIRArgs == 0);
1604 assert(NumIRArgs == 1);
1607 ArgTypes[FirstIRArg] = LTy->getPointerTo(
1608 CGM.getDataLayout().getAllocaAddrSpace());
1617 llvm::StructType *st = dyn_cast<llvm::StructType>(argType);
1619 assert(NumIRArgs == st->getNumElements());
1620 for (
unsigned i = 0, e = st->getNumElements(); i != e; ++i)
1621 ArgTypes[FirstIRArg + i] = st->getElementType(i);
1623 assert(NumIRArgs == 1);
1624 ArgTypes[FirstIRArg] = argType;
1630 auto ArgTypesIter = ArgTypes.begin() + FirstIRArg;
1632 *ArgTypesIter++ = EltTy;
1634 assert(ArgTypesIter == ArgTypes.begin() + FirstIRArg + NumIRArgs);
1639 auto ArgTypesIter = ArgTypes.begin() + FirstIRArg;
1641 assert(ArgTypesIter == ArgTypes.begin() + FirstIRArg + NumIRArgs);
1646 bool Erased = FunctionsBeingProcessed.erase(&FI); (void)Erased;
1647 assert(Erased &&
"Not in set?");
1649 return llvm::FunctionType::get(resultType, ArgTypes, FI.
isVariadic());
1660 if (isa<CXXDestructorDecl>(MD))
1669 llvm::AttrBuilder &FuncAttrs,
1676 FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
1679 void CodeGenModule::ConstructDefaultFnAttrList(StringRef Name,
bool HasOptnone,
1680 bool AttrOnCallSite,
1681 llvm::AttrBuilder &FuncAttrs) {
1684 if (CodeGenOpts.OptimizeSize)
1685 FuncAttrs.addAttribute(llvm::Attribute::OptimizeForSize);
1686 if (CodeGenOpts.OptimizeSize == 2)
1687 FuncAttrs.addAttribute(llvm::Attribute::MinSize);
1690 if (CodeGenOpts.DisableRedZone)
1691 FuncAttrs.addAttribute(llvm::Attribute::NoRedZone);
1692 if (CodeGenOpts.NoImplicitFloat)
1693 FuncAttrs.addAttribute(llvm::Attribute::NoImplicitFloat);
1695 if (AttrOnCallSite) {
1697 if (!CodeGenOpts.SimplifyLibCalls ||
1698 CodeGenOpts.isNoBuiltinFunc(Name.data()))
1699 FuncAttrs.addAttribute(llvm::Attribute::NoBuiltin);
1700 if (!CodeGenOpts.TrapFuncName.empty())
1701 FuncAttrs.addAttribute(
"trap-func-name", CodeGenOpts.TrapFuncName);
1704 if (!CodeGenOpts.DisableFPElim) {
1705 FuncAttrs.addAttribute(
"no-frame-pointer-elim",
"false");
1706 }
else if (CodeGenOpts.OmitLeafFramePointer) {
1707 FuncAttrs.addAttribute(
"no-frame-pointer-elim",
"false");
1708 FuncAttrs.addAttribute(
"no-frame-pointer-elim-non-leaf");
1710 FuncAttrs.addAttribute(
"no-frame-pointer-elim",
"true");
1711 FuncAttrs.addAttribute(
"no-frame-pointer-elim-non-leaf");
1714 FuncAttrs.addAttribute(
"less-precise-fpmad",
1715 llvm::toStringRef(CodeGenOpts.LessPreciseFPMAD));
1717 if (!CodeGenOpts.FPDenormalMode.empty())
1718 FuncAttrs.addAttribute(
"denormal-fp-math", CodeGenOpts.FPDenormalMode);
1720 FuncAttrs.addAttribute(
"no-trapping-math",
1721 llvm::toStringRef(CodeGenOpts.NoTrappingMath));
1725 FuncAttrs.addAttribute(
"no-infs-fp-math",
1726 llvm::toStringRef(CodeGenOpts.NoInfsFPMath));
1727 FuncAttrs.addAttribute(
"no-nans-fp-math",
1728 llvm::toStringRef(CodeGenOpts.NoNaNsFPMath));
1729 FuncAttrs.addAttribute(
"unsafe-fp-math",
1730 llvm::toStringRef(CodeGenOpts.UnsafeFPMath));
1731 FuncAttrs.addAttribute(
"use-soft-float",
1732 llvm::toStringRef(CodeGenOpts.SoftFloat));
1733 FuncAttrs.addAttribute(
"stack-protector-buffer-size",
1734 llvm::utostr(CodeGenOpts.SSPBufferSize));
1735 FuncAttrs.addAttribute(
"no-signed-zeros-fp-math",
1736 llvm::toStringRef(CodeGenOpts.NoSignedZeros));
1737 FuncAttrs.addAttribute(
1738 "correctly-rounded-divide-sqrt-fp-math",
1739 llvm::toStringRef(CodeGenOpts.CorrectlyRoundedDivSqrt));
1742 const std::vector<std::string> &Recips = CodeGenOpts.Reciprocals;
1743 if (!Recips.empty())
1744 FuncAttrs.addAttribute(
"reciprocal-estimates",
1745 llvm::join(Recips,
","));
1747 if (!CodeGenOpts.PreferVectorWidth.empty() &&
1748 CodeGenOpts.PreferVectorWidth !=
"none")
1749 FuncAttrs.addAttribute(
"prefer-vector-width",
1750 CodeGenOpts.PreferVectorWidth);
1752 if (CodeGenOpts.StackRealignment)
1753 FuncAttrs.addAttribute(
"stackrealign");
1754 if (CodeGenOpts.Backchain)
1755 FuncAttrs.addAttribute(
"backchain");
1758 if (getLangOpts().assumeFunctionsAreConvergent()) {
1764 FuncAttrs.addAttribute(llvm::Attribute::Convergent);
1767 if (getLangOpts().CUDA && getLangOpts().CUDAIsDevice) {
1769 FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
1772 if (getLangOpts().CUDADeviceFlushDenormalsToZero)
1773 FuncAttrs.addAttribute(
"nvptx-f32ftz",
"true");
1778 llvm::AttrBuilder FuncAttrs;
1779 ConstructDefaultFnAttrList(F.getName(),
1780 F.hasFnAttribute(llvm::Attribute::OptimizeNone),
1782 F.addAttributes(llvm::AttributeList::FunctionIndex, FuncAttrs);
1787 llvm::AttributeList &AttrList,
unsigned &
CallingConv,
bool AttrOnCallSite) {
1788 llvm::AttrBuilder FuncAttrs;
1789 llvm::AttrBuilder RetAttrs;
1793 FuncAttrs.addAttribute(llvm::Attribute::NoReturn);
1802 bool HasOptnone =
false;
1805 if (TargetDecl->hasAttr<ReturnsTwiceAttr>())
1806 FuncAttrs.addAttribute(llvm::Attribute::ReturnsTwice);
1807 if (TargetDecl->hasAttr<NoThrowAttr>())
1808 FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
1809 if (TargetDecl->hasAttr<NoReturnAttr>())
1810 FuncAttrs.addAttribute(llvm::Attribute::NoReturn);
1811 if (TargetDecl->hasAttr<ColdAttr>())
1812 FuncAttrs.addAttribute(llvm::Attribute::Cold);
1813 if (TargetDecl->hasAttr<NoDuplicateAttr>())
1814 FuncAttrs.addAttribute(llvm::Attribute::NoDuplicate);
1815 if (TargetDecl->hasAttr<ConvergentAttr>())
1816 FuncAttrs.addAttribute(llvm::Attribute::Convergent);
1818 if (
const FunctionDecl *Fn = dyn_cast<FunctionDecl>(TargetDecl)) {
1824 if (Fn->isNoReturn() && !(AttrOnCallSite && MD && MD->
isVirtual()))
1825 FuncAttrs.addAttribute(llvm::Attribute::NoReturn);
1829 if (TargetDecl->hasAttr<ConstAttr>()) {
1830 FuncAttrs.addAttribute(llvm::Attribute::ReadNone);
1831 FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
1832 }
else if (TargetDecl->hasAttr<PureAttr>()) {
1833 FuncAttrs.addAttribute(llvm::Attribute::ReadOnly);
1834 FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
1835 }
else if (TargetDecl->hasAttr<NoAliasAttr>()) {
1836 FuncAttrs.addAttribute(llvm::Attribute::ArgMemOnly);
1837 FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
1839 if (TargetDecl->hasAttr<RestrictAttr>())
1840 RetAttrs.addAttribute(llvm::Attribute::NoAlias);
1841 if (TargetDecl->hasAttr<ReturnsNonNullAttr>())
1842 RetAttrs.addAttribute(llvm::Attribute::NonNull);
1843 if (TargetDecl->hasAttr<AnyX86NoCallerSavedRegistersAttr>())
1844 FuncAttrs.addAttribute(
"no_caller_saved_registers");
1846 HasOptnone = TargetDecl->
hasAttr<OptimizeNoneAttr>();
1847 if (
auto *AllocSize = TargetDecl->getAttr<AllocSizeAttr>()) {
1850 if (
unsigned N = AllocSize->getNumElemsParam())
1851 NumElemsParam = N - 1;
1852 FuncAttrs.addAllocSizeAttr(AllocSize->getElemSizeParam() - 1,
1857 ConstructDefaultFnAttrList(Name, HasOptnone, AttrOnCallSite, FuncAttrs);
1859 if (CodeGenOpts.EnableSegmentedStacks &&
1860 !(TargetDecl && TargetDecl->hasAttr<NoSplitStackAttr>()))
1861 FuncAttrs.addAttribute(
"split-stack");
1865 if (TargetDecl && CodeGenOpts.NoPLT) {
1866 if (
auto *Fn = dyn_cast<FunctionDecl>(TargetDecl)) {
1867 if (!Fn->isDefined() && !AttrOnCallSite) {
1868 FuncAttrs.addAttribute(llvm::Attribute::NonLazyBind);
1873 if (!AttrOnCallSite) {
1874 bool DisableTailCalls =
1875 CodeGenOpts.DisableTailCalls ||
1876 (TargetDecl && (TargetDecl->hasAttr<DisableTailCallsAttr>() ||
1877 TargetDecl->hasAttr<AnyX86InterruptAttr>()));
1878 FuncAttrs.addAttribute(
"disable-tail-calls",
1879 llvm::toStringRef(DisableTailCalls));
1885 std::vector<std::string> Features;
1886 const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(TargetDecl);
1887 if (FD && FD->
hasAttr<TargetAttr>()) {
1888 llvm::StringMap<bool> FeatureMap;
1889 getFunctionFeatureMap(FeatureMap, FD);
1892 for (llvm::StringMap<bool>::const_iterator it = FeatureMap.begin(),
1893 ie = FeatureMap.end();
1895 Features.push_back((it->second ?
"+" :
"-") + it->first().str());
1901 const auto *TD = FD->
getAttr<TargetAttr>();
1902 TargetAttr::ParsedTargetAttr ParsedAttr = TD->parse();
1903 if (ParsedAttr.Architecture !=
"" &&
1904 getTarget().isValidCPUName(ParsedAttr.Architecture))
1905 TargetCPU = ParsedAttr.Architecture;
1912 if (TargetCPU !=
"")
1913 FuncAttrs.addAttribute(
"target-cpu", TargetCPU);
1914 if (!Features.empty()) {
1915 std::sort(Features.begin(), Features.end());
1916 FuncAttrs.addAttribute(
1918 llvm::join(Features,
","));
1922 ClangToLLVMArgMapping IRFunctionArgs(
getContext(), FI);
1929 RetAttrs.addAttribute(llvm::Attribute::SExt);
1931 RetAttrs.addAttribute(llvm::Attribute::ZExt);
1935 RetAttrs.addAttribute(llvm::Attribute::InReg);
1943 FuncAttrs.removeAttribute(llvm::Attribute::ReadOnly)
1944 .removeAttribute(llvm::Attribute::ReadNone);
1952 llvm_unreachable(
"Invalid ABI kind for return argument");
1958 RetAttrs.addDereferenceableAttr(
getContext().getTypeSizeInChars(PTy)
1960 else if (
getContext().getTargetAddressSpace(PTy) == 0)
1961 RetAttrs.addAttribute(llvm::Attribute::NonNull);
1964 bool hasUsedSRet =
false;
1968 if (IRFunctionArgs.hasSRetArg()) {
1969 llvm::AttrBuilder SRETAttrs;
1970 SRETAttrs.addAttribute(llvm::Attribute::StructRet);
1973 SRETAttrs.addAttribute(llvm::Attribute::InReg);
1974 ArgAttrs[IRFunctionArgs.getSRetArgNo()] =
1979 if (IRFunctionArgs.hasInallocaArg()) {
1980 llvm::AttrBuilder Attrs;
1981 Attrs.addAttribute(llvm::Attribute::InAlloca);
1982 ArgAttrs[IRFunctionArgs.getInallocaArgNo()] =
1989 I != E; ++I, ++ArgNo) {
1992 llvm::AttrBuilder Attrs;
1995 if (IRFunctionArgs.hasPaddingArg(ArgNo)) {
1997 ArgAttrs[IRFunctionArgs.getPaddingArgNo(ArgNo)] =
1998 llvm::AttributeSet::get(
2000 llvm::AttrBuilder().addAttribute(llvm::Attribute::InReg));
2010 Attrs.addAttribute(llvm::Attribute::SExt);
2012 if (getTypes().getABIInfo().shouldSignExtUnsignedType(ParamType))
2013 Attrs.addAttribute(llvm::Attribute::SExt);
2015 Attrs.addAttribute(llvm::Attribute::ZExt);
2020 Attrs.addAttribute(llvm::Attribute::Nest);
2022 Attrs.addAttribute(llvm::Attribute::InReg);
2027 Attrs.addAttribute(llvm::Attribute::InReg);
2030 Attrs.addAttribute(llvm::Attribute::ByVal);
2052 FuncAttrs.removeAttribute(llvm::Attribute::ReadOnly)
2053 .removeAttribute(llvm::Attribute::ReadNone);
2063 FuncAttrs.removeAttribute(llvm::Attribute::ReadOnly)
2064 .removeAttribute(llvm::Attribute::ReadNone);
2071 Attrs.addDereferenceableAttr(
getContext().getTypeSizeInChars(PTy)
2073 else if (
getContext().getTargetAddressSpace(PTy) == 0)
2074 Attrs.addAttribute(llvm::Attribute::NonNull);
2085 Attrs.addAttribute(llvm::Attribute::StructRet);
2090 Attrs.addAttribute(llvm::Attribute::NoAlias);
2094 if (!PTy->isIncompleteType() && PTy->isConstantSizeType()) {
2096 Attrs.addDereferenceableAttr(info.first.getQuantity());
2097 Attrs.addAttribute(llvm::Attribute::getWithAlignment(
getLLVMContext(),
2098 info.second.getQuantity()));
2104 Attrs.addAttribute(llvm::Attribute::SwiftError);
2108 Attrs.addAttribute(llvm::Attribute::SwiftSelf);
2113 Attrs.addAttribute(llvm::Attribute::NoCapture);
2115 if (Attrs.hasAttributes()) {
2116 unsigned FirstIRArg, NumIRArgs;
2117 std::tie(FirstIRArg, NumIRArgs) = IRFunctionArgs.getIRArgs(ArgNo);
2118 for (
unsigned i = 0; i < NumIRArgs; i++)
2119 ArgAttrs[FirstIRArg + i] =
2125 AttrList = llvm::AttributeList::get(
2139 if (value->getType() == varType)
return value;
2141 assert((varType->isIntegerTy() || varType->isFloatingPointTy())
2142 &&
"unexpected promotion type");
2144 if (isa<llvm::IntegerType>(varType))
2145 return CGF.
Builder.CreateTrunc(value, varType,
"arg.unpromote");
2147 return CGF.
Builder.CreateFPCast(value, varType,
"arg.unpromote");
2153 QualType ArgType,
unsigned ArgNo) {
2165 if (
auto ParmNNAttr = PVD->
getAttr<NonNullAttr>())
2172 if (NNAttr->isNonNull(ArgNo))
2182 CopyBackSwiftError(
Address temp,
Address arg) : Temp(temp), Arg(arg) {}
2193 if (CurCodeDecl && CurCodeDecl->hasAttr<NakedAttr>())
2201 if (
const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(CurCodeDecl)) {
2202 if (FD->hasImplicitReturnZero()) {
2203 QualType RetTy = FD->getReturnType().getUnqualifiedType();
2204 llvm::Type* LLVMTy = CGM.getTypes().ConvertType(RetTy);
2205 llvm::Constant* Zero = llvm::Constant::getNullValue(LLVMTy);
2206 Builder.CreateStore(Zero, ReturnValue);
2213 ClangToLLVMArgMapping IRFunctionArgs(CGM.getContext(), FI);
2216 FnArgs.reserve(IRFunctionArgs.totalIRArgs());
2217 for (
auto &Arg : Fn->args()) {
2218 FnArgs.push_back(&Arg);
2220 assert(FnArgs.size() == IRFunctionArgs.totalIRArgs());
2225 const llvm::StructLayout *ArgStructLayout =
nullptr;
2226 if (IRFunctionArgs.hasInallocaArg()) {
2227 ArgStructLayout = CGM.getDataLayout().getStructLayout(FI.
getArgStruct());
2228 ArgStruct =
Address(FnArgs[IRFunctionArgs.getInallocaArgNo()],
2231 assert(ArgStruct.getType() == FI.
getArgStruct()->getPointerTo());
2235 if (IRFunctionArgs.hasSRetArg()) {
2236 auto AI = cast<llvm::Argument>(FnArgs[IRFunctionArgs.getSRetArgNo()]);
2237 AI->setName(
"agg.result");
2238 AI->addAttr(llvm::Attribute::NoAlias);
2245 ArgVals.reserve(Args.size());
2251 assert(FI.
arg_size() == Args.size() &&
2252 "Mismatch between function signature & arguments.");
2255 for (FunctionArgList::const_iterator i = Args.begin(), e = Args.end();
2256 i != e; ++i, ++info_it, ++ArgNo) {
2262 isa<ParmVarDecl>(Arg) && cast<ParmVarDecl>(Arg)->isKNRPromoted();
2264 unsigned FirstIRArg, NumIRArgs;
2265 std::tie(FirstIRArg, NumIRArgs) = IRFunctionArgs.getIRArgs(ArgNo);
2269 assert(NumIRArgs == 0);
2273 Address V = Builder.CreateStructGEP(ArgStruct, FieldIndex, FieldOffset,
2275 ArgVals.push_back(ParamValue::forIndirect(V));
2280 assert(NumIRArgs == 1);
2283 if (!hasScalarEvaluationKind(Ty)) {
2288 Address AlignedTemp = CreateMemTemp(Ty,
"coerce");
2296 auto SizeVal = llvm::ConstantInt::get(IntPtrTy, Size.
getQuantity());
2297 Address Dst = Builder.CreateBitCast(AlignedTemp, Int8PtrTy);
2298 Address Src = Builder.CreateBitCast(ParamAddr, Int8PtrTy);
2299 Builder.CreateMemCpy(Dst, Src, SizeVal,
false);
2302 ArgVals.push_back(ParamValue::forIndirect(V));
2306 EmitLoadOfScalar(ParamAddr,
false, Ty, Arg->
getLocStart());
2310 ArgVals.push_back(ParamValue::forDirect(V));
2322 assert(NumIRArgs == 1);
2324 auto AI = cast<llvm::Argument>(V);
2326 if (
const ParmVarDecl *PVD = dyn_cast<ParmVarDecl>(Arg)) {
2328 PVD->getFunctionScopeIndex()))
2329 AI->addAttr(llvm::Attribute::NonNull);
2331 QualType OTy = PVD->getOriginalType();
2332 if (
const auto *ArrTy =
2339 QualType ETy = ArrTy->getElementType();
2340 uint64_t ArrSize = ArrTy->getSize().getZExtValue();
2343 llvm::AttrBuilder Attrs;
2344 Attrs.addDereferenceableAttr(
2345 getContext().getTypeSizeInChars(ETy).getQuantity()*ArrSize);
2346 AI->addAttrs(Attrs);
2347 }
else if (
getContext().getTargetAddressSpace(ETy) == 0) {
2348 AI->addAttr(llvm::Attribute::NonNull);
2351 }
else if (
const auto *ArrTy =
2358 AI->addAttr(llvm::Attribute::NonNull);
2361 const auto *AVAttr = PVD->getAttr<AlignValueAttr>();
2363 if (
const auto *TOTy = dyn_cast<TypedefType>(OTy))
2364 AVAttr = TOTy->getDecl()->getAttr<AlignValueAttr>();
2367 EmitScalarExpr(AVAttr->getAlignment());
2368 llvm::ConstantInt *AlignmentCI =
2369 cast<llvm::ConstantInt>(AlignmentValue);
2370 unsigned Alignment =
std::min((
unsigned)AlignmentCI->getZExtValue(),
2371 +llvm::Value::MaximumAlignment);
2372 AI->addAttrs(llvm::AttrBuilder().addAlignmentAttr(Alignment));
2377 AI->addAttr(llvm::Attribute::NoAlias);
2386 CreateMemTemp(pointeeTy, getPointerAlign(),
"swifterror.temp");
2388 llvm::Value *incomingErrorValue = Builder.CreateLoad(arg);
2389 Builder.CreateStore(incomingErrorValue, temp);
2390 V = temp.getPointer();
2395 EHStack.pushCleanup<CopyBackSwiftError>(
NormalCleanup, temp, arg);
2410 if (V->getType() != LTy)
2411 V = Builder.CreateBitCast(V, LTy);
2413 ArgVals.push_back(ParamValue::forDirect(V));
2425 llvm::StructType *STy = dyn_cast<llvm::StructType>(ArgI.
getCoerceToType());
2427 STy->getNumElements() > 1) {
2428 auto SrcLayout = CGM.getDataLayout().getStructLayout(STy);
2429 uint64_t SrcSize = CGM.getDataLayout().getTypeAllocSize(STy);
2431 uint64_t DstSize = CGM.getDataLayout().getTypeAllocSize(DstTy);
2434 if (SrcSize <= DstSize) {
2435 AddrToStoreInto = Builder.CreateElementBitCast(Ptr, STy);
2438 CreateTempAlloca(STy, Alloca.
getAlignment(),
"coerce");
2441 assert(STy->getNumElements() == NumIRArgs);
2442 for (
unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
2443 auto AI = FnArgs[FirstIRArg + i];
2444 AI->setName(Arg->
getName() +
".coerce" + Twine(i));
2447 Builder.CreateStructGEP(AddrToStoreInto, i,
Offset);
2448 Builder.CreateStore(AI, EltPtr);
2451 if (SrcSize > DstSize) {
2452 Builder.CreateMemCpy(Ptr, AddrToStoreInto, DstSize);
2457 assert(NumIRArgs == 1);
2458 auto AI = FnArgs[FirstIRArg];
2459 AI->setName(Arg->
getName() +
".coerce");
2466 EmitLoadOfScalar(Alloca,
false, Ty, Arg->
getLocStart());
2469 ArgVals.push_back(ParamValue::forDirect(V));
2471 ArgVals.push_back(ParamValue::forIndirect(Alloca));
2479 ArgVals.push_back(ParamValue::forIndirect(alloca));
2482 alloca = Builder.CreateElementBitCast(alloca, coercionType);
2483 auto layout = CGM.getDataLayout().getStructLayout(coercionType);
2485 unsigned argIndex = FirstIRArg;
2486 for (
unsigned i = 0, e = coercionType->getNumElements(); i != e; ++i) {
2487 llvm::Type *eltType = coercionType->getElementType(i);
2491 auto eltAddr = Builder.CreateStructGEP(alloca, i, layout);
2492 auto elt = FnArgs[argIndex++];
2493 Builder.CreateStore(elt, eltAddr);
2495 assert(argIndex == FirstIRArg + NumIRArgs);
2504 LValue LV = MakeAddrLValue(Alloca, Ty);
2505 ArgVals.push_back(ParamValue::forIndirect(Alloca));
2507 auto FnArgIter = FnArgs.begin() + FirstIRArg;
2508 ExpandTypeFromArgs(Ty, LV, FnArgIter);
2509 assert(FnArgIter == FnArgs.begin() + FirstIRArg + NumIRArgs);
2510 for (
unsigned i = 0, e = NumIRArgs; i != e; ++i) {
2511 auto AI = FnArgs[FirstIRArg + i];
2512 AI->setName(Arg->
getName() +
"." + Twine(i));
2518 assert(NumIRArgs == 0);
2520 if (!hasScalarEvaluationKind(Ty)) {
2521 ArgVals.push_back(ParamValue::forIndirect(CreateMemTemp(Ty)));
2524 ArgVals.push_back(ParamValue::forDirect(U));
2531 for (
int I = Args.size() - 1; I >= 0; --I)
2532 EmitParmDecl(*Args[I], ArgVals[I], I + 1);
2534 for (
unsigned I = 0, E = Args.size(); I != E; ++I)
2535 EmitParmDecl(*Args[I], ArgVals[I], I + 1);
2540 while (insn->use_empty()) {
2541 llvm::BitCastInst *bitcast = dyn_cast<llvm::BitCastInst>(insn);
2542 if (!bitcast)
return;
2545 insn = cast<llvm::Instruction>(bitcast->getOperand(0));
2546 bitcast->eraseFromParent();
2554 llvm::BasicBlock *BB = CGF.
Builder.GetInsertBlock();
2555 if (BB->empty())
return nullptr;
2556 if (&BB->back() != result)
return nullptr;
2561 llvm::Instruction *generator = cast<llvm::Instruction>(result);
2567 while (llvm::BitCastInst *bitcast = dyn_cast<llvm::BitCastInst>(generator)) {
2570 generator = cast<llvm::Instruction>(bitcast->getOperand(0));
2573 if (generator->getNextNode() != bitcast)
2576 InstsToKill.push_back(bitcast);
2583 llvm::CallInst *call = dyn_cast<llvm::CallInst>(generator);
2584 if (!call)
return nullptr;
2586 bool doRetainAutorelease;
2589 doRetainAutorelease =
true;
2592 doRetainAutorelease =
false;
2600 llvm::Instruction *prev = call->getPrevNode();
2602 if (isa<llvm::BitCastInst>(prev)) {
2603 prev = prev->getPrevNode();
2606 assert(isa<llvm::CallInst>(prev));
2607 assert(cast<llvm::CallInst>(prev)->getCalledValue() ==
2609 InstsToKill.push_back(prev);
2615 result = call->getArgOperand(0);
2616 InstsToKill.push_back(call);
2620 while (llvm::BitCastInst *bitcast = dyn_cast<llvm::BitCastInst>(result)) {
2621 if (!bitcast->hasOneUse())
break;
2622 InstsToKill.push_back(bitcast);
2623 result = bitcast->getOperand(0);
2627 for (
auto *I : InstsToKill)
2628 I->eraseFromParent();
2631 if (doRetainAutorelease)
2643 dyn_cast_or_null<ObjCMethodDecl>(CGF.
CurCodeDecl);
2644 if (!method)
return nullptr;
2646 if (!self->getType().isConstQualified())
return nullptr;
2649 llvm::CallInst *retainCall =
2650 dyn_cast<llvm::CallInst>(result->stripPointerCasts());
2656 llvm::Value *retainedValue = retainCall->getArgOperand(0);
2657 llvm::LoadInst *load =
2658 dyn_cast<llvm::LoadInst>(retainedValue->stripPointerCasts());
2659 if (!load || load->isAtomic() || load->isVolatile() ||
2668 assert(retainCall->use_empty());
2669 retainCall->eraseFromParent();
2700 auto GetStoreIfValid = [&CGF](llvm::User *U) -> llvm::StoreInst * {
2701 auto *SI = dyn_cast<llvm::StoreInst>(U);
2706 assert(!SI->isAtomic() && !SI->isVolatile());
2714 llvm::BasicBlock *IP = CGF.
Builder.GetInsertBlock();
2715 if (IP->empty())
return nullptr;
2716 llvm::Instruction *I = &IP->back();
2719 for (llvm::BasicBlock::reverse_iterator II = IP->rbegin(),
2722 if (llvm::IntrinsicInst *Intrinsic =
2723 dyn_cast<llvm::IntrinsicInst>(&*II)) {
2724 if (Intrinsic->getIntrinsicID() == llvm::Intrinsic::lifetime_end) {
2725 const llvm::Value *CastAddr = Intrinsic->getArgOperand(1);
2729 if (isa<llvm::BitCastInst>(&*II) && (CastAddr == &*II))
2737 return GetStoreIfValid(I);
2740 llvm::StoreInst *store =
2742 if (!store)
return nullptr;
2746 llvm::BasicBlock *StoreBB = store->getParent();
2747 llvm::BasicBlock *IP = CGF.
Builder.GetInsertBlock();
2748 while (IP != StoreBB) {
2749 if (!(IP = IP->getSinglePredecessor()))
2763 EmitUnreachable(EndLoc);
2767 if (CurCodeDecl && CurCodeDecl->hasAttr<NakedAttr>()) {
2769 Builder.CreateUnreachable();
2774 if (!ReturnValue.isValid()) {
2775 Builder.CreateRetVoid();
2779 llvm::DebugLoc RetDbgLoc;
2788 assert(hasAggregateEvaluationKind(RetTy));
2790 llvm::Function::arg_iterator EI = CurFn->arg_end();
2795 RV = Builder.CreateAlignedLoad(SRet, getPointerAlign(),
"sret");
2800 auto AI = CurFn->arg_begin();
2803 switch (getEvaluationKind(RetTy)) {
2806 EmitLoadOfComplex(MakeAddrLValue(ReturnValue, RetTy), EndLoc);
2807 EmitStoreOfComplex(RT, MakeNaturalAlignAddrLValue(&*AI, RetTy),
2815 EmitStoreOfScalar(Builder.CreateLoad(ReturnValue),
2816 MakeNaturalAlignAddrLValue(&*AI, RetTy),
2832 if (llvm::StoreInst *SI =
2837 if (EmitRetDbgLoc && !AutoreleaseResult)
2838 RetDbgLoc = SI->getDebugLoc();
2840 RV = SI->getValueOperand();
2841 SI->eraseFromParent();
2844 auto returnValueInst = ReturnValue.getPointer();
2845 if (returnValueInst->use_empty()) {
2846 if (
auto alloca = dyn_cast<llvm::AllocaInst>(returnValueInst)) {
2847 alloca->eraseFromParent();
2854 RV = Builder.CreateLoad(ReturnValue);
2865 if (AutoreleaseResult) {
2873 if (
auto *FD = dyn_cast<FunctionDecl>(CurCodeDecl))
2874 RT = FD->getReturnType();
2875 else if (
auto *MD = dyn_cast<ObjCMethodDecl>(CurCodeDecl))
2876 RT = MD->getReturnType();
2877 else if (isa<BlockDecl>(CurCodeDecl))
2878 RT = BlockInfo->BlockExpression->getFunctionType()->getReturnType();
2880 llvm_unreachable(
"Unexpected function/method type");
2882 assert(getLangOpts().ObjCAutoRefCount &&
2896 auto layout = CGM.getDataLayout().getStructLayout(coercionType);
2900 Address addr = Builder.CreateElementBitCast(ReturnValue, coercionType);
2901 for (
unsigned i = 0, e = coercionType->getNumElements(); i != e; ++i) {
2902 auto coercedEltType = coercionType->getElementType(i);
2906 auto eltAddr = Builder.CreateStructGEP(addr, i, layout);
2907 auto elt = Builder.CreateLoad(eltAddr);
2908 results.push_back(elt);
2912 if (results.size() == 1) {
2920 RV = llvm::UndefValue::get(returnType);
2921 for (
unsigned i = 0, e = results.size(); i != e; ++i) {
2922 RV = Builder.CreateInsertValue(RV, results[i], i);
2929 llvm_unreachable(
"Invalid ABI kind for return argument");
2932 llvm::Instruction *Ret;
2934 EmitReturnValueCheck(RV);
2935 Ret = Builder.CreateRet(RV);
2937 Ret = Builder.CreateRetVoid();
2941 Ret->setDebugLoc(std::move(RetDbgLoc));
2949 ReturnsNonNullAttr *RetNNAttr =
nullptr;
2950 if (SanOpts.has(SanitizerKind::ReturnsNonnullAttribute))
2951 RetNNAttr = CurCodeDecl->getAttr<ReturnsNonNullAttr>();
2953 if (!RetNNAttr && !requiresReturnValueNullabilityCheck())
2961 assert(!requiresReturnValueNullabilityCheck() &&
2962 "Cannot check nullability and the nonnull attribute");
2963 AttrLoc = RetNNAttr->getLocation();
2964 CheckKind = SanitizerKind::ReturnsNonnullAttribute;
2965 Handler = SanitizerHandler::NonnullReturn;
2967 if (
auto *DD = dyn_cast<DeclaratorDecl>(CurCodeDecl))
2968 if (
auto *TSI = DD->getTypeSourceInfo())
2970 AttrLoc = FTL.getReturnLoc().findNullabilityLoc();
2971 CheckKind = SanitizerKind::NullabilityReturn;
2972 Handler = SanitizerHandler::NullabilityReturn;
2979 llvm::BasicBlock *Check = createBasicBlock(
"nullcheck");
2980 llvm::BasicBlock *NoCheck = createBasicBlock(
"no.nullcheck");
2981 llvm::Value *SLocPtr = Builder.CreateLoad(ReturnLocation,
"return.sloc.load");
2982 llvm::Value *CanNullCheck = Builder.CreateIsNotNull(SLocPtr);
2983 if (requiresReturnValueNullabilityCheck())
2985 Builder.CreateAnd(CanNullCheck, RetValNullabilityPrecondition);
2986 Builder.CreateCondBr(CanNullCheck, Check, NoCheck);
2991 llvm::Constant *StaticData[] = {EmitCheckSourceLocation(AttrLoc)};
2993 EmitCheck(std::make_pair(Cond, CheckKind), Handler, StaticData, DynamicData);
3014 llvm::Value *Placeholder = llvm::UndefValue::get(IRPtrTy->getPointerTo());
3034 Address local = GetAddrOfLocalVar(param);
3039 "cannot emit delegate call arguments for inalloca arguments!");
3051 }
else if (getLangOpts().ObjCAutoRefCount &&
3052 param->
hasAttr<NSConsumedAttr>() &&
3056 llvm::ConstantPointerNull::get(cast<llvm::PointerType>(ptr->getType()));
3057 Builder.CreateStore(null, local);
3063 args.
add(convertTempToRValue(local, type, loc), type);
3068 return isa<llvm::ConstantPointerNull>(addr);
3077 "shouldn't have writeback for provably null argument");
3079 llvm::BasicBlock *contBB =
nullptr;
3083 bool provablyNonNull = llvm::isKnownNonZero(srcAddr.
getPointer(),
3085 if (!provablyNonNull) {
3091 CGF.
Builder.CreateCondBr(isNull, contBB, writebackBB);
3100 "icr.writeback-cast");
3109 if (writeback.
ToUse) {
3134 if (!provablyNonNull)
3150 for (
const auto &I : llvm::reverse(Cleanups)) {
3152 I.IsActiveIP->eraseFromParent();
3158 if (uop->getOpcode() == UO_AddrOf)
3159 return uop->getSubExpr();
3189 llvm::PointerType *destType =
3213 llvm::ConstantPointerNull::get(
3214 cast<llvm::PointerType>(destType->getElementType()));
3218 llvm::BasicBlock *contBB =
nullptr;
3219 llvm::BasicBlock *originBB =
nullptr;
3224 bool provablyNonNull = llvm::isKnownNonZero(srcAddr.
getPointer(),
3226 if (provablyNonNull) {
3232 finalArgument = CGF.
Builder.CreateSelect(isNull,
3233 llvm::ConstantPointerNull::get(destType),
3239 originBB = CGF.
Builder.GetInsertBlock();
3242 CGF.
Builder.CreateCondBr(isNull, contBB, copyBB);
3244 condEval.
begin(CGF);
3274 if (shouldCopy && !provablyNonNull) {
3275 llvm::BasicBlock *copyBB = CGF.
Builder.GetInsertBlock();
3280 llvm::PHINode *phiToUse = CGF.
Builder.CreatePHI(valueToUse->getType(), 2,
3282 phiToUse->addIncoming(valueToUse, copyBB);
3283 phiToUse->addIncoming(llvm::UndefValue::get(valueToUse->getType()),
3285 valueToUse = phiToUse;
3300 StackBase = CGF.
Builder.CreateCall(F, {},
"inalloca.save");
3307 CGF.
Builder.CreateCall(F, StackBase);
3315 if (!AC.
getDecl() || !(SanOpts.has(SanitizerKind::NonnullAttribute) ||
3316 SanOpts.has(SanitizerKind::NullabilityArg)))
3324 const NonNullAttr *NNAttr =
nullptr;
3325 if (SanOpts.has(SanitizerKind::NonnullAttribute))
3328 bool CanCheckNullability =
false;
3329 if (SanOpts.has(SanitizerKind::NullabilityArg) && !NNAttr && PVD) {
3333 PVD->getTypeSourceInfo();
3336 if (!NNAttr && !CanCheckNullability)
3343 AttrLoc = NNAttr->getLocation();
3344 CheckKind = SanitizerKind::NonnullAttribute;
3345 Handler = SanitizerHandler::NonnullArg;
3347 AttrLoc = PVD->getTypeSourceInfo()->getTypeLoc().findNullabilityLoc();
3348 CheckKind = SanitizerKind::NullabilityArg;
3349 Handler = SanitizerHandler::NullabilityArg;
3356 Builder.CreateICmpNE(V, llvm::Constant::getNullValue(V->getType()));
3357 llvm::Constant *StaticData[] = {
3358 EmitCheckSourceLocation(ArgLoc), EmitCheckSourceLocation(AttrLoc),
3359 llvm::ConstantInt::get(Int32Ty, ArgNo + 1),
3361 EmitCheck(std::make_pair(Cond, CheckKind), Handler, StaticData, None);
3366 llvm::iterator_range<CallExpr::const_arg_iterator> ArgRange,
3368 assert((
int)ArgTypes.size() == (ArgRange.end() - ArgRange.begin()));
3376 CGM.getTarget().getCXXABI().areArgsDestroyedLeftToRightInCallee()
3377 ? Order == EvaluationOrder::ForceLeftToRight
3378 : Order != EvaluationOrder::ForceRightToLeft;
3380 auto MaybeEmitImplicitObjectSize = [&](
unsigned I,
const Expr *Arg,
3390 auto T = Builder.getIntNTy(Context.
getTypeSize(SizeTy));
3391 assert(EmittedArg.getScalarVal() &&
"We emitted nothing for the arg?");
3392 llvm::Value *V = evaluateOrEmitBuiltinObjectSize(Arg, PS->getType(),
T,
3393 EmittedArg.getScalarVal());
3398 std::swap(Args.back(), *(&Args.back() - 1));
3402 bool HasInAllocaArgs =
false;
3403 if (CGM.getTarget().getCXXABI().isMicrosoft()) {
3405 I != E && !HasInAllocaArgs; ++I)
3407 if (HasInAllocaArgs) {
3408 assert(
getTarget().getTriple().getArch() == llvm::Triple::x86);
3414 size_t CallArgsStart = Args.size();
3415 for (
unsigned I = 0, E = ArgTypes.size(); I != E; ++I) {
3416 unsigned Idx = LeftToRight ? I : E - I - 1;
3418 unsigned InitialArgSize = Args.size();
3421 assert((!isa<ObjCIndirectCopyRestoreExpr>(*Arg) ||
3422 getContext().hasSameUnqualifiedType((*Arg)->getType(),
3424 (isa<ObjCMethodDecl>(AC.
getDecl()) &&
3425 isObjCMethodWithTypeParams(cast<ObjCMethodDecl>(AC.
getDecl())))) &&
3426 "Argument and parameter types don't match");
3427 EmitCallArg(Args, *Arg, ArgTypes[Idx]);
3430 assert(InitialArgSize + 1 == Args.size() &&
3431 "The code below depends on only adding one arg per EmitCallArg");
3432 (void)InitialArgSize;
3433 RValue RVArg = Args.back().RV;
3434 EmitNonNullArgCheck(RVArg, ArgTypes[Idx], (*Arg)->getExprLoc(), AC,
3435 ParamsToSkip + Idx);
3439 MaybeEmitImplicitObjectSize(Idx, *Arg, RVArg);
3445 std::reverse(Args.begin() + CallArgsStart, Args.end());
3453 : Addr(Addr), Ty(Ty) {}
3466 struct DisableDebugLocationUpdates {
3468 bool disabledDebugInfo;
3470 if ((disabledDebugInfo = isa<CXXDefaultArgExpr>(E) && CGF.
getDebugInfo()))
3473 ~DisableDebugLocationUpdates() {
3474 if (disabledDebugInfo)
3483 DisableDebugLocationUpdates Dis(*
this, E);
3485 = dyn_cast<ObjCIndirectCopyRestoreExpr>(E)) {
3486 assert(getLangOpts().ObjCAutoRefCount);
3491 "reference binding to unmaterialized r-value!");
3495 return args.
add(EmitReferenceBindingToExpr(E), type);
3498 bool HasAggregateEvalKind = hasAggregateEvaluationKind(type);
3503 if (HasAggregateEvalKind &&
3504 CGM.getTarget().getCXXABI().areArgsDestroyedLeftToRightInCallee()) {
3511 Slot = CreateAggTemp(type,
"agg.tmp");
3514 bool DestroyedInCallee =
3517 if (DestroyedInCallee)
3520 EmitAggExpr(E, Slot);
3524 if (DestroyedInCallee) {
3531 llvm::Instruction *IsActive = Builder.CreateUnreachable();
3537 if (HasAggregateEvalKind && isa<ImplicitCastExpr>(E) &&
3538 cast<CastExpr>(E)->getCastKind() == CK_LValueToRValue) {
3539 LValue L = EmitLValue(cast<CastExpr>(E)->getSubExpr());
3546 Address tmp = CreateMemTemp(type);
3553 args.
add(EmitAnyExprToTemp(E), type);
3556 QualType CodeGenFunction::getVarArgType(
const Expr *Arg) {
3560 if (!
getTarget().getTriple().isOSWindows())
3577 CodeGenFunction::AddObjCARCExceptionMetadata(llvm::Instruction *Inst) {
3578 if (CGM.getCodeGenOpts().OptimizationLevel != 0 &&
3579 !CGM.getCodeGenOpts().ObjCAutoRefCountExceptions)
3580 Inst->setMetadata(
"clang.arc.no_objc_arc_exceptions",
3581 CGM.getNoObjCARCExceptionsMetadata());
3587 const llvm::Twine &name) {
3588 return EmitNounwindRuntimeCall(callee, None, name);
3595 const llvm::Twine &name) {
3596 llvm::CallInst *call = EmitRuntimeCall(callee, args, name);
3597 call->setDoesNotThrow();
3605 const llvm::Twine &name) {
3606 return EmitRuntimeCall(callee, None, name);
3616 if (!CurrentFuncletPad)
3620 auto *CalleeFn = dyn_cast<llvm::Function>(Callee->stripPointerCasts());
3621 if (CalleeFn && CalleeFn->isIntrinsic() && CalleeFn->doesNotThrow())
3624 BundleList.emplace_back(
"funclet", CurrentFuncletPad);
3631 const llvm::Twine &name) {
3635 llvm::CallInst *call = Builder.CreateCall(callee, args, BundleList, name);
3636 call->setCallingConv(getRuntimeCC());
3646 if (getInvokeDest()) {
3647 llvm::InvokeInst *invoke =
3648 Builder.CreateInvoke(callee,
3649 getUnreachableBlock(),
3653 invoke->setDoesNotReturn();
3654 invoke->setCallingConv(getRuntimeCC());
3656 llvm::CallInst *call = Builder.CreateCall(callee, args, BundleList);
3657 call->setDoesNotReturn();
3658 call->setCallingConv(getRuntimeCC());
3659 Builder.CreateUnreachable();
3666 const Twine &name) {
3667 return EmitRuntimeCallOrInvoke(callee, None, name);
3674 const Twine &name) {
3675 llvm::CallSite callSite = EmitCallOrInvoke(callee, args, name);
3676 callSite.setCallingConv(getRuntimeCC());
3685 const Twine &Name) {
3686 llvm::BasicBlock *InvokeDest = getInvokeDest();
3690 llvm::Instruction *Inst;
3692 Inst = Builder.CreateCall(Callee, Args, BundleList, Name);
3694 llvm::BasicBlock *ContBB = createBasicBlock(
"invoke.cont");
3695 Inst = Builder.CreateInvoke(Callee, ContBB, InvokeDest, Args, BundleList,
3702 if (CGM.getLangOpts().ObjCAutoRefCount)
3703 AddObjCARCExceptionMetadata(Inst);
3705 return llvm::CallSite(Inst);
3718 void CodeGenFunction::deferPlaceholderReplacement(llvm::Instruction *Old,
3720 DeferredReplacements.push_back(std::make_pair(Old, New));
3727 llvm::Instruction **callOrInvoke,
3745 const llvm::StructLayout *ArgMemoryLayout =
nullptr;
3746 if (llvm::StructType *ArgStruct = CallInfo.
getArgStruct()) {
3747 const llvm::DataLayout &DL = CGM.getDataLayout();
3748 ArgMemoryLayout = DL.getStructLayout(ArgStruct);
3750 llvm::AllocaInst *AI;
3752 IP = IP->getNextNode();
3753 AI =
new llvm::AllocaInst(ArgStruct, DL.getAllocaAddrSpace(),
3756 AI = CreateTempAlloca(ArgStruct,
"argmem");
3759 AI->setAlignment(Align.getQuantity());
3760 AI->setUsedWithInAlloca(
true);
3761 assert(AI->isUsedWithInAlloca() && !AI->isStaticAlloca());
3762 ArgMemory =
Address(AI, Align);
3766 auto createInAllocaStructGEP = [&](
unsigned FieldIndex) ->
Address {
3769 return Builder.CreateStructGEP(ArgMemory, FieldIndex, FieldOffset);
3772 ClangToLLVMArgMapping IRFunctionArgs(CGM.getContext(), CallInfo);
3778 size_t UnusedReturnSize = 0;
3780 if (!ReturnValue.
isNull()) {
3783 SRetPtr = CreateMemTemp(RetTy);
3784 if (HaveInsertPoint() && ReturnValue.
isUnused()) {
3787 if (EmitLifetimeStart(size, SRetPtr.getPointer()))
3788 UnusedReturnSize = size;
3791 if (IRFunctionArgs.hasSRetArg()) {
3792 IRCallArgs[IRFunctionArgs.getSRetArgNo()] = SRetPtr.getPointer();
3795 Builder.CreateStore(SRetPtr.getPointer(), Addr);
3803 assert(CallInfo.
arg_size() == CallArgs.size() &&
3804 "Mismatch between function signature & arguments.");
3807 for (CallArgList::const_iterator I = CallArgs.begin(), E = CallArgs.end();
3808 I != E; ++I, ++info_it, ++ArgNo) {
3813 if (IRFunctionArgs.hasPaddingArg(ArgNo))
3814 IRCallArgs[IRFunctionArgs.getPaddingArgNo(ArgNo)] =
3817 unsigned FirstIRArg, NumIRArgs;
3818 std::tie(FirstIRArg, NumIRArgs) = IRFunctionArgs.getIRArgs(ArgNo);
3822 assert(NumIRArgs == 0);
3823 assert(
getTarget().getTriple().getArch() == llvm::Triple::x86);
3826 llvm::Instruction *Placeholder =
3828 CGBuilderTy::InsertPoint IP = Builder.saveIP();
3829 Builder.SetInsertPoint(Placeholder);
3831 Builder.restoreIP(IP);
3832 deferPlaceholderReplacement(Placeholder, Addr.
getPointer());
3836 unsigned AS = Addr.
getType()->getPointerAddressSpace();
3841 if (Addr.
getType() != MemType)
3842 Addr = Builder.CreateBitCast(Addr, MemType);
3843 LValue argLV = MakeAddrLValue(Addr, I->Ty);
3850 assert(NumIRArgs == 1);
3854 "indirect-arg-temp",
false);
3857 LValue argLV = MakeAddrLValue(Addr, I->Ty);
3870 const llvm::DataLayout *TD = &CGM.getDataLayout();
3871 const unsigned RVAddrSpace = Addr.
getType()->getAddressSpace();
3872 const unsigned ArgAddrSpace =
3873 (FirstIRArg < IRFuncTy->getNumParams()
3874 ? IRFuncTy->getParamType(FirstIRArg)->getPointerAddressSpace()
3878 llvm::getOrEnforceKnownAlignment(Addr.
getPointer(),
3884 "byval-temp",
false);
3896 assert(NumIRArgs == 0);
3904 assert(NumIRArgs == 1);
3915 assert(!swiftErrorTemp.
isValid() &&
"multiple swifterror args");
3917 QualType pointeeTy = I->Ty->getPointeeType();
3922 CreateMemTemp(pointeeTy, getPointerAlign(),
"swifterror.temp");
3924 cast<llvm::AllocaInst>(V)->setSwiftError(
true);
3926 llvm::Value *errorValue = Builder.CreateLoad(swiftErrorArg);
3927 Builder.CreateStore(errorValue, swiftErrorTemp);
3932 V->getType()->isIntegerTy())
3937 if (FirstIRArg < IRFuncTy->getNumParams() &&
3938 V->getType() != IRFuncTy->getParamType(FirstIRArg))
3939 V = Builder.CreateBitCast(V, IRFuncTy->getParamType(FirstIRArg));
3941 IRCallArgs[FirstIRArg] = V;
3948 Src = CreateMemTemp(I->Ty,
"coerce");
3949 LValue SrcLV = MakeAddrLValue(Src, I->Ty);
3960 llvm::StructType *STy =
3964 uint64_t SrcSize = CGM.getDataLayout().getTypeAllocSize(SrcTy);
3965 uint64_t DstSize = CGM.getDataLayout().getTypeAllocSize(STy);
3971 if (SrcSize < DstSize) {
3975 Builder.CreateMemCpy(TempAlloca, Src, SrcSize);
3978 Src = Builder.CreateBitCast(Src,
3982 auto SrcLayout = CGM.getDataLayout().getStructLayout(STy);
3983 assert(NumIRArgs == STy->getNumElements());
3984 for (
unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
3988 IRCallArgs[FirstIRArg + i] = LI;
3992 assert(NumIRArgs == 1);
3993 IRCallArgs[FirstIRArg] =
4002 auto layout = CGM.getDataLayout().getStructLayout(coercionType);
4012 auto scalarSize = CGM.getDataLayout().getTypeAllocSize(scalarType);
4013 auto scalarAlign = CGM.getDataLayout().getPrefTypeAlignment(scalarType);
4015 tempSize = llvm::ConstantInt::get(CGM.Int64Ty, scalarSize);
4021 EmitLifetimeStart(scalarSize, addr.
getPointer());
4026 addr = Builder.CreateElementBitCast(addr, coercionType);
4028 unsigned IRArgPos = FirstIRArg;
4029 for (
unsigned i = 0, e = coercionType->getNumElements(); i != e; ++i) {
4030 llvm::Type *eltType = coercionType->getElementType(i);
4032 Address eltAddr = Builder.CreateStructGEP(addr, i, layout);
4034 IRCallArgs[IRArgPos++] = elt;
4036 assert(IRArgPos == FirstIRArg + NumIRArgs);
4039 EmitLifetimeEnd(tempSize, addr.
getPointer());
4046 unsigned IRArgPos = FirstIRArg;
4047 ExpandTypeToArgs(I->Ty, RV, IRFuncTy, IRCallArgs, IRArgPos);
4048 assert(IRArgPos == FirstIRArg + NumIRArgs);
4063 unsigned CalleeAS = CalleePtr->getType()->getPointerAddressSpace();
4064 auto FnTy = getTypes().GetFunctionType(CallInfo)->getPointerTo(CalleeAS);
4065 CalleePtr = Builder.CreateBitCast(CalleePtr, FnTy);
4068 IRFuncTy->getParamType(IRFuncTy->getNumParams() - 1);
4069 if (Arg->getType() != LastParamTy) {
4073 llvm::StructType *DeclaredTy = cast<llvm::StructType>(
4074 cast<llvm::PointerType>(LastParamTy)->getElementType());
4075 assert(DeclaredTy->getNumElements() == FullTy->getNumElements());
4076 for (llvm::StructType::element_iterator DI = DeclaredTy->element_begin(),
4077 DE = DeclaredTy->element_end(),
4078 FI = FullTy->element_begin();
4079 DI != DE; ++DI, ++FI)
4082 Arg = Builder.CreateBitCast(Arg, LastParamTy);
4085 assert(IRFunctionArgs.hasInallocaArg());
4086 IRCallArgs[IRFunctionArgs.getInallocaArgNo()] = Arg;
4098 llvm::FunctionType *CalleeFT =
4099 cast<llvm::FunctionType>(Ptr->getType()->getPointerElementType());
4100 if (!CalleeFT->isVarArg())
4103 llvm::ConstantExpr *CE = dyn_cast<llvm::ConstantExpr>(Ptr);
4104 if (!CE || CE->getOpcode() != llvm::Instruction::BitCast)
4107 llvm::Function *OrigFn = dyn_cast<llvm::Function>(CE->getOperand(0));
4111 llvm::FunctionType *OrigFT = OrigFn->getFunctionType();
4115 if (OrigFT->isVarArg() ||
4116 OrigFT->getNumParams() != CalleeFT->getNumParams() ||
4117 OrigFT->getReturnType() != CalleeFT->getReturnType())
4120 for (
unsigned i = 0, e = OrigFT->getNumParams(); i != e; ++i)
4121 if (OrigFT->getParamType(i) != CalleeFT->getParamType(i))
4126 CalleePtr = simplifyVariadicCallee(CalleePtr);
4140 assert(IRCallArgs.size() == IRFuncTy->getNumParams() || IRFuncTy->isVarArg());
4141 for (
unsigned i = 0; i < IRCallArgs.size(); ++i) {
4143 if (IRFunctionArgs.hasInallocaArg() &&
4144 i == IRFunctionArgs.getInallocaArgNo())
4146 if (i < IRFuncTy->getNumParams())
4147 assert(IRCallArgs[i]->getType() == IRFuncTy->getParamType(i));
4153 llvm::AttributeList Attrs;
4154 CGM.ConstructAttributeList(CalleePtr->getName(), CallInfo,
4163 if (CurCodeDecl && CurCodeDecl->hasAttr<FlattenAttr>() &&
4167 Attrs.addAttribute(
getLLVMContext(), llvm::AttributeList::FunctionIndex,
4168 llvm::Attribute::AlwaysInline);
4172 if (isSEHTryScope()) {
4174 Attrs.addAttribute(
getLLVMContext(), llvm::AttributeList::FunctionIndex,
4175 llvm::Attribute::NoInline);
4180 if (currentFunctionUsesSEHTry()) {
4182 CannotThrow =
false;
4183 }
else if (isCleanupPadScope() &&
4191 CannotThrow = Attrs.hasAttribute(llvm::AttributeList::FunctionIndex,
4192 llvm::Attribute::NoUnwind);
4194 llvm::BasicBlock *InvokeDest = CannotThrow ? nullptr : getInvokeDest();
4202 CS = Builder.CreateCall(CalleePtr, IRCallArgs, BundleList);
4204 llvm::BasicBlock *Cont = createBasicBlock(
"invoke.cont");
4205 CS = Builder.CreateInvoke(CalleePtr, Cont, InvokeDest, IRCallArgs,
4209 llvm::Instruction *CI = CS.getInstruction();
4214 CS.setAttributes(Attrs);
4215 CS.setCallingConv(static_cast<llvm::CallingConv::ID>(CallingConv));
4219 if (!CI->getType()->isVoidTy())
4220 CI->setName(
"call");
4225 if (!CS.getCalledFunction())
4226 PGO.valueProfile(Builder, llvm::IPVK_IndirectCallTarget,
4231 if (CGM.getLangOpts().ObjCAutoRefCount)
4232 AddObjCARCExceptionMetadata(CI);
4235 if (llvm::CallInst *Call = dyn_cast<llvm::CallInst>(CI)) {
4237 if (TargetDecl && TargetDecl->
hasAttr<NotTailCalledAttr>())
4238 Call->setTailCallKind(llvm::CallInst::TCK_NoTail);
4246 if (CS.doesNotReturn()) {
4247 if (UnusedReturnSize)
4248 EmitLifetimeEnd(llvm::ConstantInt::get(Int64Ty, UnusedReturnSize),
4249 SRetPtr.getPointer());
4252 if (SanOpts.has(SanitizerKind::Unreachable)) {
4253 if (
auto *F = CS.getCalledFunction())
4254 F->removeFnAttr(llvm::Attribute::NoReturn);
4255 CS.removeAttribute(llvm::AttributeList::FunctionIndex,
4256 llvm::Attribute::NoReturn);
4259 EmitUnreachable(Loc);
4260 Builder.ClearInsertionPoint();
4265 EnsureInsertPoint();
4268 return GetUndefRValue(RetTy);
4272 if (swiftErrorTemp.
isValid()) {
4273 llvm::Value *errorResult = Builder.CreateLoad(swiftErrorTemp);
4274 Builder.CreateStore(errorResult, swiftErrorArg);
4291 auto layout = CGM.getDataLayout().getStructLayout(coercionType);
4294 addr = Builder.CreateElementBitCast(addr, coercionType);
4297 bool requiresExtract = isa<llvm::StructType>(CI->getType());
4299 unsigned unpaddedIndex = 0;
4300 for (
unsigned i = 0, e = coercionType->getNumElements(); i != e; ++i) {
4301 llvm::Type *eltType = coercionType->getElementType(i);
4303 Address eltAddr = Builder.CreateStructGEP(addr, i, layout);
4305 if (requiresExtract)
4306 elt = Builder.CreateExtractValue(elt, unpaddedIndex++);
4308 assert(unpaddedIndex == 0);
4309 Builder.CreateStore(elt, eltAddr);
4318 if (UnusedReturnSize)
4319 EmitLifetimeEnd(llvm::ConstantInt::get(Int64Ty, UnusedReturnSize),
4320 SRetPtr.getPointer());
4327 return GetUndefRValue(RetTy);
4333 switch (getEvaluationKind(RetTy)) {
4335 llvm::Value *Real = Builder.CreateExtractValue(CI, 0);
4336 llvm::Value *Imag = Builder.CreateExtractValue(CI, 1);
4341 bool DestIsVolatile = ReturnValue.
isVolatile();
4344 DestPtr = CreateMemTemp(RetTy,
"agg.tmp");
4345 DestIsVolatile =
false;
4354 if (V->getType() != RetIRTy)
4355 V = Builder.CreateBitCast(V, RetIRTy);
4359 llvm_unreachable(
"bad evaluation kind");
4363 bool DestIsVolatile = ReturnValue.
isVolatile();
4366 DestPtr = CreateMemTemp(RetTy,
"coerce");
4367 DestIsVolatile =
false;
4378 llvm_unreachable(
"Invalid ABI kind for return argument");
4381 llvm_unreachable(
"Unhandled ABIArgInfo::Kind");
4386 if (Ret.
isScalar() && TargetDecl) {
4387 if (
const auto *AA = TargetDecl->
getAttr<AssumeAlignedAttr>()) {
4389 if (
const auto *
Offset = AA->getOffset())
4390 OffsetValue = EmitScalarExpr(
Offset);
4392 llvm::Value *Alignment = EmitScalarExpr(AA->getAlignment());
4393 llvm::ConstantInt *AlignmentCI = cast<llvm::ConstantInt>(Alignment);
4394 EmitAlignmentAssumption(Ret.
getScalarVal(), AlignmentCI->getZExtValue(),
4396 }
else if (
const auto *AA = TargetDecl->
getAttr<AllocAlignAttr>()) {
4398 CallArgs[AA->getParamIndex() - 1].RV.getScalarVal();
4414 return CGM.getTypes().getABIInfo().EmitMSVAArg(*
this, VAListAddr, Ty);
4415 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...
ParameterABI getABI() const
Return the ABI treatment of this parameter.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
TargetOptions & getTargetOpts() const
Retrieve the target options.
An instance of this class is created to represent 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.
llvm::Type * ConvertTypeForMem(QualType T)
const CodeGenOptions & getCodeGenOpts() const
bool isReturnsRetained() const
In ARC, whether this function retains its return value.
bool isUnsignedIntegerOrEnumerationType() const
Determines whether this is an integer type that is unsigned or an enumeration types whose underlying ...
static CanQual< FunctionProtoType > GetFormalType(const CXXMethodDecl *MD)
Returns the canonical formal type of the given C++ method.
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.
const Decl * getCalleeDecl() const
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...
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
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.
ExtParameterInfo withIsNoEscape(bool NoEscape) const
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...
VarDecl - An instance of this class is created to represent 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.
static void EmitInitStoreOfNonAggregate(CodeGenFunction &CGF, RValue Src, LValue Dst)
Store a non-aggregate value to an address to initialize it.
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.
ParmVarDecl - Represents a parameter to a function.
bool hasFunctionDecl() const
unsigned getAddressSpace() const
Return the address space that this address resides in.
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.
RecordDecl - 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.
const TargetInfo & getTarget() const
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.
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
llvm::Value * EmitARCRetainAutoreleaseReturnValue(llvm::Value *value)
Do a fused retain/autorelease of the given object.
FieldDecl - An instance of this class is created by Sema::ActOnField to represent a member of a struc...
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
Interesting information about a specific parameter that can't simply be reflected in parameter's type...
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 CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
static const EHPersonality & get(CodeGenModule &CGM, const FunctionDecl *FD)
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 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.
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.
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.
bool isNothrow(const ASTContext &Ctx, bool ResultIfDependent=false) const
Determine whether this function type has a non-throwing exception specification.
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
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)
bool hasUnsignedIntegerRepresentation() const
Determine whether this type has an unsigned integer representation of some sort, e.g., it is an unsigned integer type or a vector.
const CGFunctionInfo & arrangeGlobalDeclaration(GlobalDecl GD)
static CanQualType GetThisType(ASTContext &Context, const CXXRecordDecl *RD)
Derives the 'this' type for codegen purposes, i.e.
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.
static AggValueSlot createPlaceholderSlot(CodeGenFunction &CGF, QualType Ty)
Expr - This represents one expression.
bool isVariadic() const
Whether this function is variadic.
llvm::Type * getUnpaddedCoerceAndExpandType() const
const FunctionProtoType * T
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)
void add(RValue rvalue, QualType type, bool needscopy=false)
static SmallVector< CanQualType, 16 > getArgTypesForCall(ASTContext &ctx, const CallArgList &args)
static void eraseUnusedBitCasts(llvm::Instruction *insn)
char __ovld __cnfn min(char x, char y)
Returns y if y < x, otherwise it returns x.
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)
bool hasNonTrivialDestructor() const
Determine whether this class has a non-trivial destructor (C++ [class.dtor]p3)
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
llvm::PointerType * AllocaInt8PtrTy
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 AggValueSlot forAddr(Address addr, Qualifiers quals, IsDestructed_t isDestructed, NeedsGCBarriers_t needsGC, IsAliased_t isAliased, IsZeroed_t isZeroed=IsNotZeroed)
forAddr - Make a slot for an aggregate value.
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
std::string CPU
If given, the name of the target CPU to generate code for.
The l-value was considered opaque, so the alignment was determined from a type.
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
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.
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)
std::vector< std::string > Features
The list of target specific features to enable or disable – this should be a list of strings startin...
bool isSignedIntegerOrEnumerationType() const
Determines whether this is an integer type that is signed or an enumeration types whose underlying ty...
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
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.
const CGCalleeInfo & getAbstractInfo() const
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...
void EmitARCIntrinsicUse(ArrayRef< llvm::Value *> values)
Given a number of pointers, inform the optimizer that they're being intrinsically used up until this ...
llvm::LoadInst * CreateLoad(Address Addr, const llvm::Twine &Name="")
llvm::IntegerType * IntPtrTy
bool areArgsDestroyedLeftToRightInCallee() const
Are arguments to a call destroyed left to right in the callee? This is a fundamental language change...
const CXXRecordDecl * getParent() const
Returns the parent of this method declaration, which is the class in which this method is defined...
SourceLocation getLocStart() const LLVM_READONLY
llvm::Function * getIntrinsic(unsigned IID, ArrayRef< llvm::Type *> Tys=None)
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
static void getBundlesForFunclet(llvm::Value *Callee, llvm::Instruction *CurrentFuncletPad, SmallVectorImpl< llvm::OperandBundleDef > &BundleList)
ArrayRef< llvm::Type * > getCoerceAndExpandTypeSequence() const
bool isVolatileQualified() 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
Pass it using the normal C aggregate rules for the ABI, potentially introducing extra copies and pass...
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::Value * getAggregatePointer() const
llvm::StringRef getName() const
Return the IR name of the pointer value.
Expand - Only valid for aggregate argument types.
const CGFunctionInfo & arrangeMSMemberPointerThunk(const CXXMethodDecl *MD)
Arrange a thunk that takes 'this' as the first parameter followed by varargs.
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)
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false)
EmitBlock - Emit the given block.
ABIArgInfo & getReturnInfo()
Represents a base class of a C++ class.
char __ovld __cnfn max(char x, char y)
Returns y if x < y, otherwise it returns x.
RValue asAggregateRValue() const
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...
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
bool hasSignedIntegerRepresentation() const
Determine whether this type has an signed integer representation of some sort, e.g., it is an signed integer type or a vector.
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.
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.
StringRef getName() const
getName - Get the name of identifier for this declaration as a StringRef.
static CallingConv getCallingConventionForDecl(const Decl *D, bool IsWindows)
const CGFunctionInfo & arrangeMSCtorClosure(const CXXConstructorDecl *CD, CXXCtorType CT)
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)
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
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.
Information for lazily generating a cleanup.
llvm::Type * getCoerceToType() 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.
This parameter (which must have pointer type) is a Swift indirect result parameter.
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.