30 #include "llvm/ADT/StringExtras.h" 31 #include "llvm/Transforms/Utils/Local.h" 32 #include "llvm/Analysis/ValueTracking.h" 33 #include "llvm/IR/Attributes.h" 34 #include "llvm/IR/CallingConv.h" 35 #include "llvm/IR/DataLayout.h" 36 #include "llvm/IR/InlineAsm.h" 37 #include "llvm/IR/IntrinsicInst.h" 38 #include "llvm/IR/Intrinsics.h" 39 using namespace clang;
40 using namespace CodeGen;
51 case CC_Win64:
return llvm::CallingConv::Win64;
53 case CC_AAPCS:
return llvm::CallingConv::ARM_AAPCS;
54 case CC_AAPCS_VFP:
return llvm::CallingConv::ARM_AAPCS_VFP;
65 case CC_Swift:
return llvm::CallingConv::Swift;
116 unsigned totalArgs) {
118 assert(paramInfos.size() <= prefixArgs);
119 assert(proto->
getNumParams() + prefixArgs <= totalArgs);
121 paramInfos.reserve(totalArgs);
124 paramInfos.resize(prefixArgs);
128 paramInfos.push_back(ParamInfo);
130 if (ParamInfo.hasPassObjectSize())
131 paramInfos.emplace_back();
134 assert(paramInfos.size() <= totalArgs &&
135 "Did we forget to insert pass_object_size args?");
137 paramInfos.resize(totalArgs);
147 if (!FPT->hasExtParameterInfos()) {
148 assert(paramInfos.empty() &&
149 "We have paramInfos, but the prototype doesn't?");
150 prefix.append(FPT->param_type_begin(), FPT->param_type_end());
154 unsigned PrefixSize = prefix.size();
158 prefix.reserve(prefix.size() + FPT->getNumParams());
160 auto ExtInfos = FPT->getExtParameterInfos();
161 assert(ExtInfos.size() == FPT->getNumParams());
162 for (
unsigned I = 0, E = FPT->getNumParams(); I != E; ++I) {
163 prefix.push_back(FPT->getParamType(I));
164 if (ExtInfos[I].hasPassObjectSize())
186 FTP->getExtInfo(), paramInfos,
204 if (D->
hasAttr<FastCallAttr>())
210 if (D->
hasAttr<ThisCallAttr>())
213 if (D->
hasAttr<VectorCallAttr>())
219 if (PcsAttr *PCS = D->
getAttr<PcsAttr>())
222 if (D->
hasAttr<AArch64VectorPcsAttr>())
225 if (D->
hasAttr<IntelOclBiccAttr>())
234 if (D->
hasAttr<PreserveMostAttr>())
237 if (D->
hasAttr<PreserveAllAttr>())
259 *
this,
true, argTypes,
266 if (FD->
hasAttr<CUDAGlobalAttr>()) {
279 assert(!isa<CXXConstructorDecl>(MD) &&
"wrong method for constructors!");
280 assert(!isa<CXXDestructorDecl>(MD) &&
"wrong method for destructors!");
306 auto *MD = cast<CXXMethodDecl>(GD.
getDecl());
312 bool PassParams =
true;
314 if (
auto *CD = dyn_cast<CXXConstructorDecl>(MD)) {
317 if (
auto Inherited = CD->getInheritedConstructor())
329 if (!paramInfos.empty()) {
332 paramInfos.insert(paramInfos.begin() + 1, AddedArgs.
Prefix,
335 paramInfos.append(AddedArgs.
Suffix,
340 (PassParams && MD->isVariadic() ?
RequiredArgs(argTypes.size())
350 false, argTypes, extInfo,
351 paramInfos, required);
357 for (
auto &arg : args)
365 for (
auto &arg : args)
372 unsigned prefixArgs,
unsigned totalArgs) {
392 unsigned ExtraPrefixArgs,
393 unsigned ExtraSuffixArgs,
394 bool PassProtoArgs) {
397 for (
const auto &Arg : args)
401 unsigned TotalPrefixArgs = 1 + ExtraPrefixArgs;
406 FPT, TotalPrefixArgs + ExtraSuffixArgs)
420 if (PassProtoArgs && FPT->hasExtParameterInfos()) {
426 false, ArgTypes, Info,
427 ParamInfos, Required);
435 if (MD->isInstance())
440 assert(isa<FunctionType>(FTy));
447 noProto->getReturnType(),
false,
480 I->hasAttr<NoEscapeAttr>());
481 extParamInfos.push_back(extParamInfo);
488 if (
getContext().getLangOpts().ObjCAutoRefCount &&
489 MD->
hasAttr<NSReturnsRetainedAttr>())
497 false, argTys, einfo, extParamInfos, required);
516 if (isa<CXXConstructorDecl>(GD.
getDecl()) ||
517 isa<CXXDestructorDecl>(GD.
getDecl()))
530 assert(MD->
isVirtual() &&
"only methods have thunks");
548 ArgTys.push_back(*FTP->param_type_begin());
550 ArgTys.push_back(Context.
IntTy);
566 unsigned numExtraRequiredArgs,
568 assert(args.size() >= numExtraRequiredArgs);
578 if (proto->isVariadic())
581 if (proto->hasExtParameterInfos())
591 cast<FunctionNoProtoType>(fnType))) {
597 for (
const auto &arg : args)
614 chainCall ? 1 : 0, chainCall);
643 for (
const auto &Arg : args)
665 resultType,
false,
false,
677 unsigned numPrefixArgs) {
678 assert(numPrefixArgs + 1 <= args.size() &&
679 "Emitting a call with less args than the required prefix?");
691 false, argTypes, info, paramInfos, required);
703 assert(signature.
arg_size() <= args.size());
704 if (signature.
arg_size() == args.size())
709 if (!sigParamInfos.empty()) {
710 paramInfos.append(sigParamInfos.begin(), sigParamInfos.end());
711 paramInfos.resize(args.size());
743 assert(llvm::all_of(argTypes,
747 llvm::FoldingSetNodeID
ID;
749 required, resultType, argTypes);
751 void *insertPos =
nullptr;
752 CGFunctionInfo *FI = FunctionInfos.FindNodeOrInsertPos(ID, insertPos);
760 paramInfos, resultType, argTypes, required);
761 FunctionInfos.InsertNode(FI, insertPos);
763 bool inserted = FunctionsBeingProcessed.insert(FI).second;
765 assert(inserted &&
"Recursively being processed?");
768 if (CC == llvm::CallingConv::SPIR_KERNEL) {
785 for (
auto &I : FI->arguments())
786 if (I.info.canHaveCoerceToType() && I.info.getCoerceToType() ==
nullptr)
789 bool erased = FunctionsBeingProcessed.erase(FI); (void)erased;
790 assert(erased &&
"Not in set?");
803 assert(paramInfos.empty() || paramInfos.size() == argTypes.size());
808 operator new(totalSizeToAlloc<ArgInfo, ExtParameterInfo>(
809 argTypes.size() + 1, paramInfos.size()));
812 FI->CallingConvention = llvmCC;
813 FI->EffectiveCallingConvention = llvmCC;
814 FI->ASTCallingConvention = info.
getCC();
815 FI->InstanceMethod = instanceMethod;
816 FI->ChainCall = chainCall;
821 FI->Required = required;
824 FI->ArgStruct =
nullptr;
825 FI->ArgStructAlign = 0;
826 FI->NumArgs = argTypes.size();
827 FI->HasExtParameterInfos = !paramInfos.empty();
828 FI->getArgsBuffer()[0].
type = resultType;
829 for (
unsigned i = 0, e = argTypes.size();
i != e; ++
i)
830 FI->getArgsBuffer()[
i + 1].
type = argTypes[
i];
831 for (
unsigned i = 0, e = paramInfos.size();
i != e; ++
i)
832 FI->getExtParameterInfosBuffer()[
i] = paramInfos[
i];
842 struct TypeExpansion {
843 enum TypeExpansionKind {
855 const TypeExpansionKind
Kind;
857 TypeExpansion(TypeExpansionKind K) :
Kind(K) {}
858 virtual ~TypeExpansion() {}
861 struct ConstantArrayExpansion : TypeExpansion {
865 ConstantArrayExpansion(
QualType EltTy, uint64_t NumElts)
866 : TypeExpansion(TEK_ConstantArray), EltTy(EltTy), NumElts(NumElts) {}
867 static bool classof(
const TypeExpansion *TE) {
868 return TE->Kind == TEK_ConstantArray;
872 struct RecordExpansion : TypeExpansion {
879 : TypeExpansion(TEK_Record), Bases(std::move(Bases)),
880 Fields(std::move(Fields)) {}
881 static bool classof(
const TypeExpansion *TE) {
882 return TE->Kind == TEK_Record;
886 struct ComplexExpansion : TypeExpansion {
890 static bool classof(
const TypeExpansion *TE) {
895 struct NoExpansion : TypeExpansion {
896 NoExpansion() : TypeExpansion(TEK_None) {}
897 static bool classof(
const TypeExpansion *TE) {
898 return TE->Kind == TEK_None;
903 static std::unique_ptr<TypeExpansion>
906 return llvm::make_unique<ConstantArrayExpansion>(
907 AT->getElementType(), AT->getSize().getZExtValue());
914 "Cannot expand structure with flexible array.");
921 for (
const auto *FD : RD->
fields()) {
922 if (FD->isZeroLengthBitField(Context))
924 assert(!FD->isBitField() &&
925 "Cannot expand structure with bit-field members.");
927 if (UnionSize < FieldSize) {
928 UnionSize = FieldSize;
933 Fields.push_back(LargestFD);
935 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
936 assert(!CXXRD->isDynamicClass() &&
937 "cannot expand vtable pointers in dynamic classes");
939 Bases.push_back(&BS);
942 for (
const auto *FD : RD->
fields()) {
943 if (FD->isZeroLengthBitField(Context))
945 assert(!FD->isBitField() &&
946 "Cannot expand structure with bit-field members.");
947 Fields.push_back(FD);
950 return llvm::make_unique<RecordExpansion>(std::move(Bases),
954 return llvm::make_unique<ComplexExpansion>(CT->getElementType());
956 return llvm::make_unique<NoExpansion>();
961 if (
auto CAExp = dyn_cast<ConstantArrayExpansion>(Exp.get())) {
964 if (
auto RExp = dyn_cast<RecordExpansion>(Exp.get())) {
966 for (
auto BS : RExp->Bases)
968 for (
auto FD : RExp->Fields)
972 if (isa<ComplexExpansion>(Exp.get()))
974 assert(isa<NoExpansion>(Exp.get()));
982 if (
auto CAExp = dyn_cast<ConstantArrayExpansion>(Exp.get())) {
983 for (
int i = 0, n = CAExp->NumElts;
i < n;
i++) {
986 }
else if (
auto RExp = dyn_cast<RecordExpansion>(Exp.get())) {
987 for (
auto BS : RExp->Bases)
989 for (
auto FD : RExp->Fields)
991 }
else if (
auto CExp = dyn_cast<ComplexExpansion>(Exp.get())) {
996 assert(isa<NoExpansion>(Exp.get()));
1002 ConstantArrayExpansion *CAE,
1004 llvm::function_ref<
void(
Address)> Fn) {
1009 for (
int i = 0, n = CAE->NumElts;
i < n;
i++) {
1012 Fn(
Address(EltAddr, EltAlign));
1016 void CodeGenFunction::ExpandTypeFromArgs(
1019 "Unexpected non-simple lvalue during struct expansion.");
1022 if (
auto CAExp = dyn_cast<ConstantArrayExpansion>(Exp.get())) {
1025 LValue LV = MakeAddrLValue(EltAddr, CAExp->EltTy);
1026 ExpandTypeFromArgs(CAExp->EltTy, LV, AI);
1028 }
else if (
auto RExp = dyn_cast<RecordExpansion>(Exp.get())) {
1038 ExpandTypeFromArgs(BS->getType(), SubLV, AI);
1040 for (
auto FD : RExp->Fields) {
1042 LValue SubLV = EmitLValueForFieldInitialization(LV, FD);
1043 ExpandTypeFromArgs(FD->getType(), SubLV, AI);
1045 }
else if (isa<ComplexExpansion>(Exp.get())) {
1046 auto realValue = *AI++;
1047 auto imagValue = *AI++;
1048 EmitStoreOfComplex(
ComplexPairTy(realValue, imagValue), LV,
true);
1050 assert(isa<NoExpansion>(Exp.get()));
1055 void CodeGenFunction::ExpandTypeToArgs(
1059 if (
auto CAExp = dyn_cast<ConstantArrayExpansion>(Exp.get())) {
1063 *
this, CAExp, Addr, [&](
Address EltAddr) {
1067 ExpandTypeToArgs(CAExp->EltTy, EltArg, IRFuncTy, IRCallArgs,
1070 }
else if (
auto RExp = dyn_cast<RecordExpansion>(Exp.get())) {
1081 ExpandTypeToArgs(BS->getType(), BaseArg, IRFuncTy, IRCallArgs,
1085 LValue LV = MakeAddrLValue(This, Ty);
1086 for (
auto FD : RExp->Fields) {
1089 ExpandTypeToArgs(FD->getType(), FldArg, IRFuncTy, IRCallArgs,
1092 }
else if (isa<ComplexExpansion>(Exp.get())) {
1094 IRCallArgs[IRCallArgPos++] = CV.first;
1095 IRCallArgs[IRCallArgPos++] = CV.second;
1097 assert(isa<NoExpansion>(Exp.get()));
1099 assert(RV.isScalar() &&
1100 "Unexpected non-scalar rvalue during struct expansion.");
1104 if (IRCallArgPos < IRFuncTy->getNumParams() &&
1105 V->getType() != IRFuncTy->getParamType(IRCallArgPos))
1106 V = Builder.CreateBitCast(V, IRFuncTy->getParamType(IRCallArgPos));
1108 IRCallArgs[IRCallArgPos++] =
V;
1128 llvm::StructType *SrcSTy,
1131 if (SrcSTy->getNumElements() == 0)
return SrcPtr;
1133 llvm::Type *FirstElt = SrcSTy->getElementType(0);
1139 uint64_t FirstEltSize =
1141 if (FirstEltSize < DstSize &&
1150 if (llvm::StructType *SrcSTy = dyn_cast<llvm::StructType>(SrcTy))
1166 if (Val->getType() == Ty)
1169 if (isa<llvm::PointerType>(Val->getType())) {
1171 if (isa<llvm::PointerType>(Ty))
1179 if (isa<llvm::PointerType>(DestIntTy))
1182 if (Val->getType() != DestIntTy) {
1184 if (DL.isBigEndian()) {
1187 uint64_t SrcSize = DL.getTypeSizeInBits(Val->getType());
1188 uint64_t DstSize = DL.getTypeSizeInBits(DestIntTy);
1190 if (SrcSize > DstSize) {
1191 Val = CGF.
Builder.CreateLShr(Val, SrcSize - DstSize,
"coerce.highbits");
1192 Val = CGF.
Builder.CreateTrunc(Val, DestIntTy,
"coerce.val.ii");
1194 Val = CGF.
Builder.CreateZExt(Val, DestIntTy,
"coerce.val.ii");
1195 Val = CGF.
Builder.CreateShl(Val, DstSize - SrcSize,
"coerce.highbits");
1199 Val = CGF.
Builder.CreateIntCast(Val, DestIntTy,
false,
"coerce.val.ii");
1203 if (isa<llvm::PointerType>(Ty))
1204 Val = CGF.
Builder.CreateIntToPtr(Val, Ty,
"coerce.val.ip");
1227 if (llvm::StructType *SrcSTy = dyn_cast<llvm::StructType>(SrcTy)) {
1229 SrcTy = Src.
getType()->getElementType();
1236 if ((isa<llvm::IntegerType>(Ty) || isa<llvm::PointerType>(Ty)) &&
1237 (isa<llvm::IntegerType>(SrcTy) || isa<llvm::PointerType>(SrcTy))) {
1243 if (SrcSize >= DstSize) {
1260 llvm::ConstantInt::get(CGF.
IntPtrTy, SrcSize),
1270 Address Dest,
bool DestIsVolatile) {
1272 if (llvm::StructType *STy =
1273 dyn_cast<llvm::StructType>(Val->getType())) {
1274 for (
unsigned i = 0, e = STy->getNumElements();
i != e; ++
i) {
1296 if (SrcTy == DstTy) {
1303 if (llvm::StructType *DstSTy = dyn_cast<llvm::StructType>(DstTy)) {
1305 DstTy = Dst.
getType()->getElementType();
1310 if ((isa<llvm::IntegerType>(SrcTy) || isa<llvm::PointerType>(SrcTy)) &&
1311 (isa<llvm::IntegerType>(DstTy) || isa<llvm::PointerType>(DstTy))) {
1320 if (SrcSize <= DstSize) {
1338 llvm::ConstantInt::get(CGF.
IntPtrTy, DstSize),
1358 class ClangToLLVMArgMapping {
1359 static const unsigned InvalidIndex = ~0U;
1360 unsigned InallocaArgNo;
1362 unsigned TotalIRArgs;
1366 unsigned PaddingArgIndex;
1369 unsigned FirstArgIndex;
1370 unsigned NumberOfArgs;
1373 : PaddingArgIndex(InvalidIndex), FirstArgIndex(InvalidIndex),
1381 bool OnlyRequiredArgs =
false)
1382 : InallocaArgNo(InvalidIndex), SRetArgNo(InvalidIndex), TotalIRArgs(0),
1384 construct(Context, FI, OnlyRequiredArgs);
1387 bool hasInallocaArg()
const {
return InallocaArgNo != InvalidIndex; }
1388 unsigned getInallocaArgNo()
const {
1389 assert(hasInallocaArg());
1390 return InallocaArgNo;
1393 bool hasSRetArg()
const {
return SRetArgNo != InvalidIndex; }
1394 unsigned getSRetArgNo()
const {
1395 assert(hasSRetArg());
1399 unsigned totalIRArgs()
const {
return TotalIRArgs; }
1401 bool hasPaddingArg(
unsigned ArgNo)
const {
1402 assert(ArgNo < ArgInfo.size());
1403 return ArgInfo[ArgNo].PaddingArgIndex != InvalidIndex;
1405 unsigned getPaddingArgNo(
unsigned ArgNo)
const {
1406 assert(hasPaddingArg(ArgNo));
1407 return ArgInfo[ArgNo].PaddingArgIndex;
1412 std::pair<unsigned, unsigned> getIRArgs(
unsigned ArgNo)
const {
1413 assert(ArgNo < ArgInfo.size());
1414 return std::make_pair(ArgInfo[ArgNo].FirstArgIndex,
1415 ArgInfo[ArgNo].NumberOfArgs);
1420 bool OnlyRequiredArgs);
1423 void ClangToLLVMArgMapping::construct(
const ASTContext &Context,
1425 bool OnlyRequiredArgs) {
1426 unsigned IRArgNo = 0;
1427 bool SwapThisWithSRet =
false;
1432 SRetArgNo = SwapThisWithSRet ? 1 : IRArgNo++;
1443 auto &IRArgs = ArgInfo[ArgNo];
1446 IRArgs.PaddingArgIndex = IRArgNo++;
1452 llvm::StructType *STy = dyn_cast<llvm::StructType>(AI.
getCoerceToType());
1454 IRArgs.NumberOfArgs = STy->getNumElements();
1456 IRArgs.NumberOfArgs = 1;
1461 IRArgs.NumberOfArgs = 1;
1466 IRArgs.NumberOfArgs = 0;
1476 if (IRArgs.NumberOfArgs > 0) {
1477 IRArgs.FirstArgIndex = IRArgNo;
1478 IRArgNo += IRArgs.NumberOfArgs;
1483 if (IRArgNo == 1 && SwapThisWithSRet)
1486 assert(ArgNo == ArgInfo.size());
1489 InallocaArgNo = IRArgNo++;
1491 TotalIRArgs = IRArgNo;
1499 return RI.
isIndirect() || (RI.isInAlloca() && RI.getInAllocaSRet());
1503 return ReturnTypeUsesSRet(FI) &&
1504 getTargetCodeGenInfo().doesReturnSlotInterfereWithArgs();
1509 switch (BT->getKind()) {
1512 case BuiltinType::Float:
1514 case BuiltinType::Double:
1516 case BuiltinType::LongDouble:
1527 if (BT->getKind() == BuiltinType::LongDouble)
1540 llvm::FunctionType *
1543 bool Inserted = FunctionsBeingProcessed.insert(&FI).second;
1545 assert(Inserted &&
"Recursively being processed?");
1551 llvm_unreachable(
"Invalid ABI kind for return argument");
1564 resultType = llvm::PointerType::get(ty, addressSpace);
1580 ClangToLLVMArgMapping IRFunctionArgs(
getContext(), FI,
true);
1584 if (IRFunctionArgs.hasSRetArg()) {
1588 ArgTypes[IRFunctionArgs.getSRetArgNo()] =
1589 llvm::PointerType::get(Ty, AddressSpace);
1593 if (IRFunctionArgs.hasInallocaArg()) {
1596 ArgTypes[IRFunctionArgs.getInallocaArgNo()] = ArgStruct->getPointerTo();
1603 for (; it != ie; ++it, ++ArgNo) {
1607 if (IRFunctionArgs.hasPaddingArg(ArgNo))
1608 ArgTypes[IRFunctionArgs.getPaddingArgNo(ArgNo)] =
1611 unsigned FirstIRArg, NumIRArgs;
1612 std::tie(FirstIRArg, NumIRArgs) = IRFunctionArgs.getIRArgs(ArgNo);
1617 assert(NumIRArgs == 0);
1621 assert(NumIRArgs == 1);
1624 ArgTypes[FirstIRArg] = LTy->getPointerTo(
1625 CGM.getDataLayout().getAllocaAddrSpace());
1634 llvm::StructType *st = dyn_cast<llvm::StructType>(argType);
1636 assert(NumIRArgs == st->getNumElements());
1637 for (
unsigned i = 0, e = st->getNumElements();
i != e; ++
i)
1638 ArgTypes[FirstIRArg +
i] = st->getElementType(
i);
1640 assert(NumIRArgs == 1);
1641 ArgTypes[FirstIRArg] = argType;
1647 auto ArgTypesIter = ArgTypes.begin() + FirstIRArg;
1649 *ArgTypesIter++ = EltTy;
1651 assert(ArgTypesIter == ArgTypes.begin() + FirstIRArg + NumIRArgs);
1656 auto ArgTypesIter = ArgTypes.begin() + FirstIRArg;
1658 assert(ArgTypesIter == ArgTypes.begin() + FirstIRArg + NumIRArgs);
1663 bool Erased = FunctionsBeingProcessed.erase(&FI); (void)Erased;
1664 assert(Erased &&
"Not in set?");
1666 return llvm::FunctionType::get(resultType, ArgTypes, FI.
isVariadic());
1680 llvm::AttrBuilder &FuncAttrs,
1687 FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
1690 void CodeGenModule::ConstructDefaultFnAttrList(StringRef Name,
bool HasOptnone,
1691 bool AttrOnCallSite,
1692 llvm::AttrBuilder &FuncAttrs) {
1695 if (CodeGenOpts.OptimizeSize)
1696 FuncAttrs.addAttribute(llvm::Attribute::OptimizeForSize);
1697 if (CodeGenOpts.OptimizeSize == 2)
1698 FuncAttrs.addAttribute(llvm::Attribute::MinSize);
1701 if (CodeGenOpts.DisableRedZone)
1702 FuncAttrs.addAttribute(llvm::Attribute::NoRedZone);
1703 if (CodeGenOpts.IndirectTlsSegRefs)
1704 FuncAttrs.addAttribute(
"indirect-tls-seg-refs");
1705 if (CodeGenOpts.NoImplicitFloat)
1706 FuncAttrs.addAttribute(llvm::Attribute::NoImplicitFloat);
1708 if (AttrOnCallSite) {
1710 if (!CodeGenOpts.SimplifyLibCalls ||
1711 CodeGenOpts.isNoBuiltinFunc(Name.data()))
1712 FuncAttrs.addAttribute(llvm::Attribute::NoBuiltin);
1713 if (!CodeGenOpts.TrapFuncName.empty())
1714 FuncAttrs.addAttribute(
"trap-func-name", CodeGenOpts.TrapFuncName);
1717 if (!CodeGenOpts.DisableFPElim) {
1718 FuncAttrs.addAttribute(
"no-frame-pointer-elim",
"false");
1719 }
else if (CodeGenOpts.OmitLeafFramePointer) {
1720 FuncAttrs.addAttribute(
"no-frame-pointer-elim",
"false");
1721 FuncAttrs.addAttribute(
"no-frame-pointer-elim-non-leaf");
1723 FuncAttrs.addAttribute(
"no-frame-pointer-elim",
"true");
1724 FuncAttrs.addAttribute(
"no-frame-pointer-elim-non-leaf");
1727 FuncAttrs.addAttribute(
"less-precise-fpmad",
1728 llvm::toStringRef(CodeGenOpts.LessPreciseFPMAD));
1730 if (CodeGenOpts.NullPointerIsValid)
1731 FuncAttrs.addAttribute(
"null-pointer-is-valid",
"true");
1732 if (!CodeGenOpts.FPDenormalMode.empty())
1733 FuncAttrs.addAttribute(
"denormal-fp-math", CodeGenOpts.FPDenormalMode);
1735 FuncAttrs.addAttribute(
"no-trapping-math",
1736 llvm::toStringRef(CodeGenOpts.NoTrappingMath));
1740 if (!CodeGenOpts.StrictFloatCastOverflow)
1741 FuncAttrs.addAttribute(
"strict-float-cast-overflow",
"false");
1745 FuncAttrs.addAttribute(
"no-infs-fp-math",
1746 llvm::toStringRef(CodeGenOpts.NoInfsFPMath));
1747 FuncAttrs.addAttribute(
"no-nans-fp-math",
1748 llvm::toStringRef(CodeGenOpts.NoNaNsFPMath));
1749 FuncAttrs.addAttribute(
"unsafe-fp-math",
1750 llvm::toStringRef(CodeGenOpts.UnsafeFPMath));
1751 FuncAttrs.addAttribute(
"use-soft-float",
1752 llvm::toStringRef(CodeGenOpts.SoftFloat));
1753 FuncAttrs.addAttribute(
"stack-protector-buffer-size",
1754 llvm::utostr(CodeGenOpts.SSPBufferSize));
1755 FuncAttrs.addAttribute(
"no-signed-zeros-fp-math",
1756 llvm::toStringRef(CodeGenOpts.NoSignedZeros));
1757 FuncAttrs.addAttribute(
1758 "correctly-rounded-divide-sqrt-fp-math",
1759 llvm::toStringRef(CodeGenOpts.CorrectlyRoundedDivSqrt));
1761 if (getLangOpts().OpenCL)
1762 FuncAttrs.addAttribute(
"denorms-are-zero",
1763 llvm::toStringRef(CodeGenOpts.FlushDenorm));
1766 const std::vector<std::string> &Recips = CodeGenOpts.Reciprocals;
1767 if (!Recips.empty())
1768 FuncAttrs.addAttribute(
"reciprocal-estimates",
1769 llvm::join(Recips,
","));
1771 if (!CodeGenOpts.PreferVectorWidth.empty() &&
1772 CodeGenOpts.PreferVectorWidth !=
"none")
1773 FuncAttrs.addAttribute(
"prefer-vector-width",
1774 CodeGenOpts.PreferVectorWidth);
1776 if (CodeGenOpts.StackRealignment)
1777 FuncAttrs.addAttribute(
"stackrealign");
1778 if (CodeGenOpts.Backchain)
1779 FuncAttrs.addAttribute(
"backchain");
1781 if (CodeGenOpts.SpeculativeLoadHardening)
1782 FuncAttrs.addAttribute(llvm::Attribute::SpeculativeLoadHardening);
1785 if (getLangOpts().assumeFunctionsAreConvergent()) {
1791 FuncAttrs.addAttribute(llvm::Attribute::Convergent);
1794 if (getLangOpts().CUDA && getLangOpts().CUDAIsDevice) {
1796 FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
1799 if (CodeGenOpts.FlushDenorm)
1800 FuncAttrs.addAttribute(
"nvptx-f32ftz",
"true");
1803 for (StringRef
Attr : CodeGenOpts.DefaultFunctionAttrs) {
1804 StringRef Var,
Value;
1805 std::tie(Var, Value) = Attr.split(
'=');
1806 FuncAttrs.addAttribute(Var, Value);
1811 llvm::AttrBuilder FuncAttrs;
1812 ConstructDefaultFnAttrList(F.getName(), F.hasOptNone(),
1814 F.addAttributes(llvm::AttributeList::FunctionIndex, FuncAttrs);
1819 llvm::AttributeList &AttrList,
unsigned &
CallingConv,
bool AttrOnCallSite) {
1820 llvm::AttrBuilder FuncAttrs;
1821 llvm::AttrBuilder RetAttrs;
1825 FuncAttrs.addAttribute(llvm::Attribute::NoReturn);
1834 bool HasOptnone =
false;
1837 if (TargetDecl->hasAttr<ReturnsTwiceAttr>())
1838 FuncAttrs.addAttribute(llvm::Attribute::ReturnsTwice);
1839 if (TargetDecl->hasAttr<NoThrowAttr>())
1840 FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
1841 if (TargetDecl->hasAttr<NoReturnAttr>())
1842 FuncAttrs.addAttribute(llvm::Attribute::NoReturn);
1843 if (TargetDecl->hasAttr<ColdAttr>())
1844 FuncAttrs.addAttribute(llvm::Attribute::Cold);
1845 if (TargetDecl->hasAttr<NoDuplicateAttr>())
1846 FuncAttrs.addAttribute(llvm::Attribute::NoDuplicate);
1847 if (TargetDecl->hasAttr<ConvergentAttr>())
1848 FuncAttrs.addAttribute(llvm::Attribute::Convergent);
1850 if (
const FunctionDecl *Fn = dyn_cast<FunctionDecl>(TargetDecl)) {
1856 if (Fn->isNoReturn() && !(AttrOnCallSite && MD && MD->
isVirtual()))
1857 FuncAttrs.addAttribute(llvm::Attribute::NoReturn);
1861 if (TargetDecl->hasAttr<ConstAttr>()) {
1862 FuncAttrs.addAttribute(llvm::Attribute::ReadNone);
1863 FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
1864 }
else if (TargetDecl->hasAttr<PureAttr>()) {
1865 FuncAttrs.addAttribute(llvm::Attribute::ReadOnly);
1866 FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
1867 }
else if (TargetDecl->hasAttr<NoAliasAttr>()) {
1868 FuncAttrs.addAttribute(llvm::Attribute::ArgMemOnly);
1869 FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
1871 if (TargetDecl->hasAttr<RestrictAttr>())
1872 RetAttrs.addAttribute(llvm::Attribute::NoAlias);
1873 if (TargetDecl->hasAttr<ReturnsNonNullAttr>() &&
1874 !CodeGenOpts.NullPointerIsValid)
1875 RetAttrs.addAttribute(llvm::Attribute::NonNull);
1876 if (TargetDecl->hasAttr<AnyX86NoCallerSavedRegistersAttr>())
1877 FuncAttrs.addAttribute(
"no_caller_saved_registers");
1878 if (TargetDecl->hasAttr<AnyX86NoCfCheckAttr>())
1879 FuncAttrs.addAttribute(llvm::Attribute::NoCfCheck);
1881 HasOptnone = TargetDecl->
hasAttr<OptimizeNoneAttr>();
1882 if (
auto *AllocSize = TargetDecl->getAttr<AllocSizeAttr>()) {
1884 if (AllocSize->getNumElemsParam().isValid())
1885 NumElemsParam = AllocSize->getNumElemsParam().getLLVMIndex();
1886 FuncAttrs.addAllocSizeAttr(AllocSize->getElemSizeParam().getLLVMIndex(),
1891 ConstructDefaultFnAttrList(Name, HasOptnone, AttrOnCallSite, FuncAttrs);
1897 if (TargetDecl->hasAttr<NoSpeculativeLoadHardeningAttr>())
1898 FuncAttrs.removeAttribute(llvm::Attribute::SpeculativeLoadHardening);
1899 if (TargetDecl->hasAttr<SpeculativeLoadHardeningAttr>())
1900 FuncAttrs.addAttribute(llvm::Attribute::SpeculativeLoadHardening);
1903 if (CodeGenOpts.EnableSegmentedStacks &&
1904 !(TargetDecl && TargetDecl->hasAttr<NoSplitStackAttr>()))
1905 FuncAttrs.addAttribute(
"split-stack");
1909 if (TargetDecl && CodeGenOpts.NoPLT) {
1910 if (
auto *Fn = dyn_cast<FunctionDecl>(TargetDecl)) {
1911 if (!Fn->isDefined() && !AttrOnCallSite) {
1912 FuncAttrs.addAttribute(llvm::Attribute::NonLazyBind);
1917 if (TargetDecl && TargetDecl->hasAttr<OpenCLKernelAttr>()) {
1918 if (getLangOpts().OpenCLVersion <= 120) {
1920 FuncAttrs.addAttribute(
"uniform-work-group-size",
"true");
1927 FuncAttrs.addAttribute(
"uniform-work-group-size",
1928 llvm::toStringRef(CodeGenOpts.UniformWGSize));
1932 if (!AttrOnCallSite) {
1933 bool DisableTailCalls =
false;
1935 if (CodeGenOpts.DisableTailCalls)
1936 DisableTailCalls =
true;
1937 else if (TargetDecl) {
1938 if (TargetDecl->hasAttr<DisableTailCallsAttr>() ||
1939 TargetDecl->hasAttr<AnyX86InterruptAttr>())
1940 DisableTailCalls =
true;
1941 else if (CodeGenOpts.NoEscapingBlockTailCalls) {
1942 if (
const auto *BD = dyn_cast<BlockDecl>(TargetDecl))
1943 if (!BD->doesNotEscape())
1944 DisableTailCalls =
true;
1948 FuncAttrs.addAttribute(
"disable-tail-calls",
1949 llvm::toStringRef(DisableTailCalls));
1950 GetCPUAndFeaturesAttributes(CalleeInfo.
getCalleeDecl(), FuncAttrs);
1953 ClangToLLVMArgMapping IRFunctionArgs(
getContext(), FI);
1960 RetAttrs.addAttribute(llvm::Attribute::SExt);
1962 RetAttrs.addAttribute(llvm::Attribute::ZExt);
1966 RetAttrs.addAttribute(llvm::Attribute::InReg);
1974 FuncAttrs.removeAttribute(llvm::Attribute::ReadOnly)
1975 .removeAttribute(llvm::Attribute::ReadNone);
1983 llvm_unreachable(
"Invalid ABI kind for return argument");
1989 RetAttrs.addDereferenceableAttr(
getContext().getTypeSizeInChars(PTy)
1991 else if (
getContext().getTargetAddressSpace(PTy) == 0 &&
1992 !CodeGenOpts.NullPointerIsValid)
1993 RetAttrs.addAttribute(llvm::Attribute::NonNull);
1996 bool hasUsedSRet =
false;
2000 if (IRFunctionArgs.hasSRetArg()) {
2001 llvm::AttrBuilder SRETAttrs;
2002 SRETAttrs.addAttribute(llvm::Attribute::StructRet);
2005 SRETAttrs.addAttribute(llvm::Attribute::InReg);
2006 ArgAttrs[IRFunctionArgs.getSRetArgNo()] =
2011 if (IRFunctionArgs.hasInallocaArg()) {
2012 llvm::AttrBuilder Attrs;
2013 Attrs.addAttribute(llvm::Attribute::InAlloca);
2014 ArgAttrs[IRFunctionArgs.getInallocaArgNo()] =
2021 I != E; ++I, ++ArgNo) {
2024 llvm::AttrBuilder Attrs;
2027 if (IRFunctionArgs.hasPaddingArg(ArgNo)) {
2029 ArgAttrs[IRFunctionArgs.getPaddingArgNo(ArgNo)] =
2030 llvm::AttributeSet::get(
2032 llvm::AttrBuilder().addAttribute(llvm::Attribute::InReg));
2042 Attrs.addAttribute(llvm::Attribute::SExt);
2044 Attrs.addAttribute(llvm::Attribute::ZExt);
2048 Attrs.addAttribute(llvm::Attribute::Nest);
2050 Attrs.addAttribute(llvm::Attribute::InReg);
2055 Attrs.addAttribute(llvm::Attribute::InReg);
2080 FuncAttrs.removeAttribute(llvm::Attribute::ReadOnly)
2081 .removeAttribute(llvm::Attribute::ReadNone);
2091 FuncAttrs.removeAttribute(llvm::Attribute::ReadOnly)
2092 .removeAttribute(llvm::Attribute::ReadNone);
2099 Attrs.addDereferenceableAttr(
getContext().getTypeSizeInChars(PTy)
2101 else if (
getContext().getTargetAddressSpace(PTy) == 0 &&
2102 !CodeGenOpts.NullPointerIsValid)
2103 Attrs.addAttribute(llvm::Attribute::NonNull);
2114 Attrs.addAttribute(llvm::Attribute::StructRet);
2119 Attrs.addAttribute(llvm::Attribute::NoAlias);
2123 if (!PTy->isIncompleteType() && PTy->isConstantSizeType()) {
2125 Attrs.addDereferenceableAttr(info.first.getQuantity());
2126 Attrs.addAttribute(llvm::Attribute::getWithAlignment(
getLLVMContext(),
2127 info.second.getQuantity()));
2133 Attrs.addAttribute(llvm::Attribute::SwiftError);
2137 Attrs.addAttribute(llvm::Attribute::SwiftSelf);
2142 Attrs.addAttribute(llvm::Attribute::NoCapture);
2144 if (Attrs.hasAttributes()) {
2145 unsigned FirstIRArg, NumIRArgs;
2146 std::tie(FirstIRArg, NumIRArgs) = IRFunctionArgs.getIRArgs(ArgNo);
2147 for (
unsigned i = 0;
i < NumIRArgs;
i++)
2148 ArgAttrs[FirstIRArg +
i] =
2154 AttrList = llvm::AttributeList::get(
2168 if (value->getType() == varType)
return value;
2170 assert((varType->isIntegerTy() || varType->isFloatingPointTy())
2171 &&
"unexpected promotion type");
2173 if (isa<llvm::IntegerType>(varType))
2174 return CGF.
Builder.CreateTrunc(value, varType,
"arg.unpromote");
2176 return CGF.
Builder.CreateFPCast(value, varType,
"arg.unpromote");
2182 QualType ArgType,
unsigned ArgNo) {
2194 if (
auto ParmNNAttr = PVD->
getAttr<NonNullAttr>())
2201 if (NNAttr->isNonNull(ArgNo))
2211 CopyBackSwiftError(
Address temp,
Address arg) : Temp(temp), Arg(arg) {}
2222 if (CurCodeDecl && CurCodeDecl->hasAttr<NakedAttr>())
2230 if (
const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(CurCodeDecl)) {
2231 if (FD->hasImplicitReturnZero()) {
2232 QualType RetTy = FD->getReturnType().getUnqualifiedType();
2233 llvm::Type* LLVMTy = CGM.getTypes().ConvertType(RetTy);
2234 llvm::Constant* Zero = llvm::Constant::getNullValue(LLVMTy);
2235 Builder.CreateStore(Zero, ReturnValue);
2242 ClangToLLVMArgMapping IRFunctionArgs(CGM.getContext(), FI);
2245 FnArgs.reserve(IRFunctionArgs.totalIRArgs());
2246 for (
auto &Arg : Fn->args()) {
2247 FnArgs.push_back(&Arg);
2249 assert(FnArgs.size() == IRFunctionArgs.totalIRArgs());
2254 if (IRFunctionArgs.hasInallocaArg()) {
2255 ArgStruct =
Address(FnArgs[IRFunctionArgs.getInallocaArgNo()],
2258 assert(ArgStruct.getType() == FI.
getArgStruct()->getPointerTo());
2262 if (IRFunctionArgs.hasSRetArg()) {
2263 auto AI = cast<llvm::Argument>(FnArgs[IRFunctionArgs.getSRetArgNo()]);
2264 AI->setName(
"agg.result");
2265 AI->addAttr(llvm::Attribute::NoAlias);
2272 ArgVals.reserve(Args.size());
2278 assert(FI.
arg_size() == Args.size() &&
2279 "Mismatch between function signature & arguments.");
2282 for (FunctionArgList::const_iterator
i = Args.begin(), e = Args.end();
2283 i != e; ++
i, ++info_it, ++ArgNo) {
2288 isa<ParmVarDecl>(Arg) && cast<ParmVarDecl>(Arg)->isKNRPromoted();
2293 assert(hasScalarEvaluationKind(Ty) ==
2294 hasScalarEvaluationKind(Arg->
getType()));
2296 unsigned FirstIRArg, NumIRArgs;
2297 std::tie(FirstIRArg, NumIRArgs) = IRFunctionArgs.getIRArgs(ArgNo);
2301 assert(NumIRArgs == 0);
2304 Builder.CreateStructGEP(ArgStruct, FieldIndex, Arg->
getName());
2305 ArgVals.push_back(ParamValue::forIndirect(V));
2310 assert(NumIRArgs == 1);
2313 if (!hasScalarEvaluationKind(Ty)) {
2318 Address AlignedTemp = CreateMemTemp(Ty,
"coerce");
2326 auto SizeVal = llvm::ConstantInt::get(IntPtrTy, Size.
getQuantity());
2327 Address Dst = Builder.CreateBitCast(AlignedTemp, Int8PtrTy);
2328 Address Src = Builder.CreateBitCast(ParamAddr, Int8PtrTy);
2329 Builder.CreateMemCpy(Dst, Src, SizeVal,
false);
2332 ArgVals.push_back(ParamValue::forIndirect(V));
2336 EmitLoadOfScalar(ParamAddr,
false, Ty, Arg->
getBeginLoc());
2340 ArgVals.push_back(ParamValue::forDirect(V));
2352 assert(NumIRArgs == 1);
2354 auto AI = cast<llvm::Argument>(
V);
2356 if (
const ParmVarDecl *PVD = dyn_cast<ParmVarDecl>(Arg)) {
2358 PVD->getFunctionScopeIndex()) &&
2359 !CGM.getCodeGenOpts().NullPointerIsValid)
2360 AI->addAttr(llvm::Attribute::NonNull);
2362 QualType OTy = PVD->getOriginalType();
2363 if (
const auto *ArrTy =
2370 QualType ETy = ArrTy->getElementType();
2371 uint64_t ArrSize = ArrTy->getSize().getZExtValue();
2374 llvm::AttrBuilder Attrs;
2375 Attrs.addDereferenceableAttr(
2376 getContext().getTypeSizeInChars(ETy).getQuantity()*ArrSize);
2377 AI->addAttrs(Attrs);
2378 }
else if (
getContext().getTargetAddressSpace(ETy) == 0 &&
2379 !CGM.getCodeGenOpts().NullPointerIsValid) {
2380 AI->addAttr(llvm::Attribute::NonNull);
2383 }
else if (
const auto *ArrTy =
2390 !CGM.getCodeGenOpts().NullPointerIsValid)
2391 AI->addAttr(llvm::Attribute::NonNull);
2394 const auto *AVAttr = PVD->getAttr<AlignValueAttr>();
2396 if (
const auto *TOTy = dyn_cast<TypedefType>(OTy))
2397 AVAttr = TOTy->getDecl()->getAttr<AlignValueAttr>();
2398 if (AVAttr && !SanOpts.has(SanitizerKind::Alignment)) {
2403 EmitScalarExpr(AVAttr->getAlignment());
2404 llvm::ConstantInt *AlignmentCI =
2405 cast<llvm::ConstantInt>(AlignmentValue);
2406 unsigned Alignment =
std::min((
unsigned)AlignmentCI->getZExtValue(),
2407 +llvm::Value::MaximumAlignment);
2408 AI->addAttrs(llvm::AttrBuilder().addAlignmentAttr(Alignment));
2413 AI->addAttr(llvm::Attribute::NoAlias);
2422 CreateMemTemp(pointeeTy, getPointerAlign(),
"swifterror.temp");
2424 llvm::Value *incomingErrorValue = Builder.CreateLoad(arg);
2425 Builder.CreateStore(incomingErrorValue, temp);
2426 V = temp.getPointer();
2431 EHStack.pushCleanup<CopyBackSwiftError>(
NormalCleanup, temp, arg);
2446 if (V->getType() != LTy)
2447 V = Builder.CreateBitCast(V, LTy);
2449 ArgVals.push_back(ParamValue::forDirect(V));
2461 llvm::StructType *STy = dyn_cast<llvm::StructType>(ArgI.
getCoerceToType());
2463 STy->getNumElements() > 1) {
2464 uint64_t SrcSize = CGM.getDataLayout().getTypeAllocSize(STy);
2466 uint64_t DstSize = CGM.getDataLayout().getTypeAllocSize(DstTy);
2469 if (SrcSize <= DstSize) {
2470 AddrToStoreInto = Builder.CreateElementBitCast(Ptr, STy);
2473 CreateTempAlloca(STy, Alloca.
getAlignment(),
"coerce");
2476 assert(STy->getNumElements() == NumIRArgs);
2477 for (
unsigned i = 0, e = STy->getNumElements();
i != e; ++
i) {
2478 auto AI = FnArgs[FirstIRArg +
i];
2479 AI->setName(Arg->
getName() +
".coerce" + Twine(
i));
2480 Address EltPtr = Builder.CreateStructGEP(AddrToStoreInto,
i);
2481 Builder.CreateStore(AI, EltPtr);
2484 if (SrcSize > DstSize) {
2485 Builder.CreateMemCpy(Ptr, AddrToStoreInto, DstSize);
2490 assert(NumIRArgs == 1);
2491 auto AI = FnArgs[FirstIRArg];
2492 AI->setName(Arg->
getName() +
".coerce");
2499 EmitLoadOfScalar(Alloca,
false, Ty, Arg->
getBeginLoc());
2502 ArgVals.push_back(ParamValue::forDirect(V));
2504 ArgVals.push_back(ParamValue::forIndirect(Alloca));
2512 ArgVals.push_back(ParamValue::forIndirect(alloca));
2515 alloca = Builder.CreateElementBitCast(alloca, coercionType);
2517 unsigned argIndex = FirstIRArg;
2518 for (
unsigned i = 0, e = coercionType->getNumElements();
i != e; ++
i) {
2519 llvm::Type *eltType = coercionType->getElementType(
i);
2523 auto eltAddr = Builder.CreateStructGEP(alloca,
i);
2524 auto elt = FnArgs[argIndex++];
2525 Builder.CreateStore(elt, eltAddr);
2527 assert(argIndex == FirstIRArg + NumIRArgs);
2536 LValue LV = MakeAddrLValue(Alloca, Ty);
2537 ArgVals.push_back(ParamValue::forIndirect(Alloca));
2539 auto FnArgIter = FnArgs.begin() + FirstIRArg;
2540 ExpandTypeFromArgs(Ty, LV, FnArgIter);
2541 assert(FnArgIter == FnArgs.begin() + FirstIRArg + NumIRArgs);
2542 for (
unsigned i = 0, e = NumIRArgs;
i != e; ++
i) {
2543 auto AI = FnArgs[FirstIRArg +
i];
2544 AI->setName(Arg->
getName() +
"." + Twine(
i));
2550 assert(NumIRArgs == 0);
2552 if (!hasScalarEvaluationKind(Ty)) {
2553 ArgVals.push_back(ParamValue::forIndirect(CreateMemTemp(Ty)));
2556 ArgVals.push_back(ParamValue::forDirect(U));
2563 for (
int I = Args.size() - 1; I >= 0; --I)
2564 EmitParmDecl(*Args[I], ArgVals[I], I + 1);
2566 for (
unsigned I = 0, E = Args.size(); I != E; ++I)
2567 EmitParmDecl(*Args[I], ArgVals[I], I + 1);
2572 while (insn->use_empty()) {
2573 llvm::BitCastInst *bitcast = dyn_cast<llvm::BitCastInst>(insn);
2574 if (!bitcast)
return;
2577 insn = cast<llvm::Instruction>(bitcast->getOperand(0));
2578 bitcast->eraseFromParent();
2586 llvm::BasicBlock *BB = CGF.
Builder.GetInsertBlock();
2587 if (BB->empty())
return nullptr;
2588 if (&BB->back() !=
result)
return nullptr;
2593 llvm::Instruction *generator = cast<llvm::Instruction>(
result);
2599 while (llvm::BitCastInst *bitcast = dyn_cast<llvm::BitCastInst>(generator)) {
2602 generator = cast<llvm::Instruction>(bitcast->getOperand(0));
2605 if (generator->getNextNode() != bitcast)
2608 InstsToKill.push_back(bitcast);
2615 llvm::CallInst *call = dyn_cast<llvm::CallInst>(generator);
2616 if (!call)
return nullptr;
2618 bool doRetainAutorelease;
2621 doRetainAutorelease =
true;
2624 doRetainAutorelease =
false;
2632 llvm::Instruction *prev = call->getPrevNode();
2634 if (isa<llvm::BitCastInst>(prev)) {
2635 prev = prev->getPrevNode();
2638 assert(isa<llvm::CallInst>(prev));
2639 assert(cast<llvm::CallInst>(prev)->getCalledValue() ==
2641 InstsToKill.push_back(prev);
2647 result = call->getArgOperand(0);
2648 InstsToKill.push_back(call);
2652 while (llvm::BitCastInst *bitcast = dyn_cast<llvm::BitCastInst>(result)) {
2653 if (!bitcast->hasOneUse())
break;
2654 InstsToKill.push_back(bitcast);
2655 result = bitcast->getOperand(0);
2659 for (
auto *I : InstsToKill)
2660 I->eraseFromParent();
2663 if (doRetainAutorelease)
2675 dyn_cast_or_null<ObjCMethodDecl>(CGF.
CurCodeDecl);
2676 if (!method)
return nullptr;
2678 if (!self->getType().isConstQualified())
return nullptr;
2681 llvm::CallInst *retainCall =
2682 dyn_cast<llvm::CallInst>(result->stripPointerCasts());
2688 llvm::Value *retainedValue = retainCall->getArgOperand(0);
2689 llvm::LoadInst *load =
2690 dyn_cast<llvm::LoadInst>(retainedValue->stripPointerCasts());
2691 if (!load || load->isAtomic() || load->isVolatile() ||
2700 assert(retainCall->use_empty());
2701 retainCall->eraseFromParent();
2732 auto GetStoreIfValid = [&CGF](llvm::User *U) -> llvm::StoreInst * {
2733 auto *SI = dyn_cast<llvm::StoreInst>(U);
2738 assert(!SI->isAtomic() && !SI->isVolatile());
2746 llvm::BasicBlock *IP = CGF.
Builder.GetInsertBlock();
2747 if (IP->empty())
return nullptr;
2748 llvm::Instruction *I = &IP->back();
2751 for (llvm::BasicBlock::reverse_iterator II = IP->rbegin(),
2754 if (llvm::IntrinsicInst *Intrinsic =
2755 dyn_cast<llvm::IntrinsicInst>(&*II)) {
2756 if (Intrinsic->getIntrinsicID() == llvm::Intrinsic::lifetime_end) {
2757 const llvm::Value *CastAddr = Intrinsic->getArgOperand(1);
2761 if (isa<llvm::BitCastInst>(&*II) && (CastAddr == &*II))
2769 return GetStoreIfValid(I);
2772 llvm::StoreInst *store =
2774 if (!store)
return nullptr;
2778 llvm::BasicBlock *StoreBB = store->getParent();
2779 llvm::BasicBlock *IP = CGF.
Builder.GetInsertBlock();
2780 while (IP != StoreBB) {
2781 if (!(IP = IP->getSinglePredecessor()))
2795 EmitUnreachable(EndLoc);
2799 if (CurCodeDecl && CurCodeDecl->hasAttr<NakedAttr>()) {
2801 Builder.CreateUnreachable();
2806 if (!ReturnValue.isValid()) {
2807 Builder.CreateRetVoid();
2811 llvm::DebugLoc RetDbgLoc;
2820 assert(hasAggregateEvaluationKind(RetTy));
2822 llvm::Function::arg_iterator EI = CurFn->arg_end();
2827 RV = Builder.CreateAlignedLoad(SRet, getPointerAlign(),
"sret");
2832 auto AI = CurFn->arg_begin();
2835 switch (getEvaluationKind(RetTy)) {
2838 EmitLoadOfComplex(MakeAddrLValue(ReturnValue, RetTy), EndLoc);
2839 EmitStoreOfComplex(RT, MakeNaturalAlignAddrLValue(&*AI, RetTy),
2847 EmitStoreOfScalar(Builder.CreateLoad(ReturnValue),
2848 MakeNaturalAlignAddrLValue(&*AI, RetTy),
2864 if (llvm::StoreInst *SI =
2869 if (EmitRetDbgLoc && !AutoreleaseResult)
2870 RetDbgLoc = SI->getDebugLoc();
2872 RV = SI->getValueOperand();
2873 SI->eraseFromParent();
2877 RV = Builder.CreateLoad(ReturnValue);
2888 if (AutoreleaseResult) {
2896 if (
auto *FD = dyn_cast<FunctionDecl>(CurCodeDecl))
2897 RT = FD->getReturnType();
2898 else if (
auto *MD = dyn_cast<ObjCMethodDecl>(CurCodeDecl))
2899 RT = MD->getReturnType();
2900 else if (isa<BlockDecl>(CurCodeDecl))
2901 RT = BlockInfo->BlockExpression->getFunctionType()->getReturnType();
2903 llvm_unreachable(
"Unexpected function/method type");
2905 assert(getLangOpts().ObjCAutoRefCount &&
2922 Address addr = Builder.CreateElementBitCast(ReturnValue, coercionType);
2923 for (
unsigned i = 0, e = coercionType->getNumElements();
i != e; ++
i) {
2924 auto coercedEltType = coercionType->getElementType(
i);
2928 auto eltAddr = Builder.CreateStructGEP(addr,
i);
2929 auto elt = Builder.CreateLoad(eltAddr);
2930 results.push_back(elt);
2934 if (results.size() == 1) {
2942 RV = llvm::UndefValue::get(returnType);
2943 for (
unsigned i = 0, e = results.size();
i != e; ++
i) {
2944 RV = Builder.CreateInsertValue(RV, results[
i], i);
2951 llvm_unreachable(
"Invalid ABI kind for return argument");
2954 llvm::Instruction *Ret;
2956 EmitReturnValueCheck(RV);
2957 Ret = Builder.CreateRet(RV);
2959 Ret = Builder.CreateRetVoid();
2963 Ret->setDebugLoc(std::move(RetDbgLoc));
2971 ReturnsNonNullAttr *RetNNAttr =
nullptr;
2972 if (SanOpts.has(SanitizerKind::ReturnsNonnullAttribute))
2973 RetNNAttr = CurCodeDecl->getAttr<ReturnsNonNullAttr>();
2975 if (!RetNNAttr && !requiresReturnValueNullabilityCheck())
2983 assert(!requiresReturnValueNullabilityCheck() &&
2984 "Cannot check nullability and the nonnull attribute");
2985 AttrLoc = RetNNAttr->getLocation();
2986 CheckKind = SanitizerKind::ReturnsNonnullAttribute;
2987 Handler = SanitizerHandler::NonnullReturn;
2989 if (
auto *DD = dyn_cast<DeclaratorDecl>(CurCodeDecl))
2990 if (
auto *TSI = DD->getTypeSourceInfo())
2992 AttrLoc = FTL.getReturnLoc().findNullabilityLoc();
2993 CheckKind = SanitizerKind::NullabilityReturn;
2994 Handler = SanitizerHandler::NullabilityReturn;
3001 llvm::BasicBlock *Check = createBasicBlock(
"nullcheck");
3002 llvm::BasicBlock *NoCheck = createBasicBlock(
"no.nullcheck");
3003 llvm::Value *SLocPtr = Builder.CreateLoad(ReturnLocation,
"return.sloc.load");
3004 llvm::Value *CanNullCheck = Builder.CreateIsNotNull(SLocPtr);
3005 if (requiresReturnValueNullabilityCheck())
3007 Builder.CreateAnd(CanNullCheck, RetValNullabilityPrecondition);
3008 Builder.CreateCondBr(CanNullCheck, Check, NoCheck);
3013 llvm::Constant *StaticData[] = {EmitCheckSourceLocation(AttrLoc)};
3015 EmitCheck(std::make_pair(Cond, CheckKind), Handler, StaticData, DynamicData);
3036 llvm::Value *Placeholder = llvm::UndefValue::get(IRPtrTy->getPointerTo());
3057 Address local = GetAddrOfLocalVar(param);
3062 CGM.ErrorUnsupported(param,
"forwarded non-trivially copyable parameter");
3075 }
else if (getLangOpts().ObjCAutoRefCount &&
3076 param->
hasAttr<NSConsumedAttr>() &&
3080 llvm::ConstantPointerNull::get(cast<llvm::PointerType>(ptr->getType()));
3081 Builder.CreateStore(null, local);
3087 args.
add(convertTempToRValue(local, type, loc), type);
3091 if (hasAggregateEvaluationKind(type) && !CurFuncIsThunk &&
3095 CalleeDestructedParamCleanups.lookup(cast<ParmVarDecl>(param));
3097 "cleanup for callee-destructed param not recorded");
3099 llvm::Instruction *isActive = Builder.CreateUnreachable();
3105 return isa<llvm::ConstantPointerNull>(addr);
3114 "shouldn't have writeback for provably null argument");
3116 llvm::BasicBlock *contBB =
nullptr;
3120 bool provablyNonNull = llvm::isKnownNonZero(srcAddr.
getPointer(),
3122 if (!provablyNonNull) {
3128 CGF.
Builder.CreateCondBr(isNull, contBB, writebackBB);
3137 "icr.writeback-cast");
3146 if (writeback.
ToUse) {
3171 if (!provablyNonNull)
3186 for (
const auto &I : llvm::reverse(Cleanups)) {
3188 I.IsActiveIP->eraseFromParent();
3194 if (uop->getOpcode() == UO_AddrOf)
3195 return uop->getSubExpr();
3225 llvm::PointerType *destType =
3249 llvm::ConstantPointerNull::get(
3250 cast<llvm::PointerType>(destType->getElementType()));
3254 llvm::BasicBlock *contBB =
nullptr;
3255 llvm::BasicBlock *originBB =
nullptr;
3260 bool provablyNonNull = llvm::isKnownNonZero(srcAddr.
getPointer(),
3262 if (provablyNonNull) {
3268 finalArgument = CGF.
Builder.CreateSelect(isNull,
3269 llvm::ConstantPointerNull::get(destType),
3275 originBB = CGF.
Builder.GetInsertBlock();
3278 CGF.
Builder.CreateCondBr(isNull, contBB, copyBB);
3280 condEval.
begin(CGF);
3310 if (shouldCopy && !provablyNonNull) {
3311 llvm::BasicBlock *copyBB = CGF.
Builder.GetInsertBlock();
3316 llvm::PHINode *phiToUse = CGF.
Builder.CreatePHI(valueToUse->getType(), 2,
3318 phiToUse->addIncoming(valueToUse, copyBB);
3319 phiToUse->addIncoming(llvm::UndefValue::get(valueToUse->getType()),
3321 valueToUse = phiToUse;
3336 StackBase = CGF.
Builder.CreateCall(F, {},
"inalloca.save");
3342 llvm::Function *F = CGF.
CGM.
getIntrinsic(llvm::Intrinsic::stackrestore);
3343 CGF.
Builder.CreateCall(F, StackBase);
3351 if (!AC.
getDecl() || !(SanOpts.has(SanitizerKind::NonnullAttribute) ||
3352 SanOpts.has(SanitizerKind::NullabilityArg)))
3360 const NonNullAttr *NNAttr =
nullptr;
3361 if (SanOpts.has(SanitizerKind::NonnullAttribute))
3364 bool CanCheckNullability =
false;
3365 if (SanOpts.has(SanitizerKind::NullabilityArg) && !NNAttr && PVD) {
3369 PVD->getTypeSourceInfo();
3372 if (!NNAttr && !CanCheckNullability)
3379 AttrLoc = NNAttr->getLocation();
3380 CheckKind = SanitizerKind::NonnullAttribute;
3381 Handler = SanitizerHandler::NonnullArg;
3383 AttrLoc = PVD->getTypeSourceInfo()->getTypeLoc().findNullabilityLoc();
3384 CheckKind = SanitizerKind::NullabilityArg;
3385 Handler = SanitizerHandler::NullabilityArg;
3392 Builder.CreateICmpNE(V, llvm::Constant::getNullValue(V->getType()));
3393 llvm::Constant *StaticData[] = {
3394 EmitCheckSourceLocation(ArgLoc), EmitCheckSourceLocation(AttrLoc),
3395 llvm::ConstantInt::get(Int32Ty, ArgNo + 1),
3397 EmitCheck(std::make_pair(Cond, CheckKind), Handler, StaticData, None);
3402 llvm::iterator_range<CallExpr::const_arg_iterator> ArgRange,
3404 assert((
int)ArgTypes.size() == (ArgRange.end() - ArgRange.begin()));
3412 CGM.getTarget().getCXXABI().areArgsDestroyedLeftToRightInCallee()
3413 ? Order == EvaluationOrder::ForceLeftToRight
3414 : Order != EvaluationOrder::ForceRightToLeft;
3416 auto MaybeEmitImplicitObjectSize = [&](
unsigned I,
const Expr *Arg,
3426 auto T = Builder.getIntNTy(Context.
getTypeSize(SizeTy));
3427 assert(EmittedArg.getScalarVal() &&
"We emitted nothing for the arg?");
3428 llvm::Value *
V = evaluateOrEmitBuiltinObjectSize(Arg, PS->getType(), T,
3429 EmittedArg.getScalarVal(),
3435 std::swap(Args.back(), *(&Args.back() - 1));
3439 bool HasInAllocaArgs =
false;
3440 if (CGM.getTarget().getCXXABI().isMicrosoft()) {
3442 I != E && !HasInAllocaArgs; ++I)
3444 if (HasInAllocaArgs) {
3445 assert(
getTarget().getTriple().getArch() == llvm::Triple::x86);
3451 size_t CallArgsStart = Args.size();
3452 for (
unsigned I = 0, E = ArgTypes.size(); I != E; ++I) {
3453 unsigned Idx = LeftToRight ? I : E - I - 1;
3455 unsigned InitialArgSize = Args.size();
3458 assert((!isa<ObjCIndirectCopyRestoreExpr>(*Arg) ||
3459 getContext().hasSameUnqualifiedType((*Arg)->getType(),
3461 (isa<ObjCMethodDecl>(AC.
getDecl()) &&
3462 isObjCMethodWithTypeParams(cast<ObjCMethodDecl>(AC.
getDecl())))) &&
3463 "Argument and parameter types don't match");
3464 EmitCallArg(Args, *Arg, ArgTypes[Idx]);
3467 assert(InitialArgSize + 1 == Args.size() &&
3468 "The code below depends on only adding one arg per EmitCallArg");
3469 (void)InitialArgSize;
3472 if (!Args.back().hasLValue()) {
3473 RValue RVArg = Args.back().getKnownRValue();
3474 EmitNonNullArgCheck(RVArg, ArgTypes[Idx], (*Arg)->getExprLoc(), AC,
3475 ParamsToSkip + Idx);
3479 MaybeEmitImplicitObjectSize(Idx, *Arg, RVArg);
3486 std::reverse(Args.begin() + CallArgsStart, Args.end());
3494 : Addr(Addr), Ty(Ty) {}
3512 struct DisableDebugLocationUpdates {
3514 bool disabledDebugInfo;
3516 if ((disabledDebugInfo = isa<CXXDefaultArgExpr>(E) && CGF.
getDebugInfo()))
3519 ~DisableDebugLocationUpdates() {
3520 if (disabledDebugInfo)
3539 if (!HasLV && RV.isScalar())
3541 else if (!HasLV && RV.isComplex())
3544 auto Addr = HasLV ? LV.
getAddress() : RV.getAggregateAddress();
3549 : RV.isVolatileQualified());
3556 DisableDebugLocationUpdates Dis(*
this, E);
3558 = dyn_cast<ObjCIndirectCopyRestoreExpr>(E)) {
3559 assert(getLangOpts().ObjCAutoRefCount);
3564 "reference binding to unmaterialized r-value!");
3568 return args.
add(EmitReferenceBindingToExpr(E), type);
3571 bool HasAggregateEvalKind = hasAggregateEvaluationKind(type);
3576 if (HasAggregateEvalKind &&
3584 Slot = CreateAggTemp(type,
"agg.tmp");
3586 bool DestroyedInCallee =
true, NeedsEHCleanup =
true;
3588 DestroyedInCallee = RD->hasNonTrivialDestructor();
3592 if (DestroyedInCallee)
3595 EmitAggExpr(E, Slot);
3599 if (DestroyedInCallee && NeedsEHCleanup) {
3606 llvm::Instruction *IsActive = Builder.CreateUnreachable();
3612 if (HasAggregateEvalKind && isa<ImplicitCastExpr>(E) &&
3613 cast<CastExpr>(E)->getCastKind() == CK_LValueToRValue) {
3614 LValue L = EmitLValue(cast<CastExpr>(E)->getSubExpr());
3620 args.
add(EmitAnyExprToTemp(E), type);
3623 QualType CodeGenFunction::getVarArgType(
const Expr *Arg) {
3627 if (!
getTarget().getTriple().isOSWindows())
3644 CodeGenFunction::AddObjCARCExceptionMetadata(llvm::Instruction *Inst) {
3645 if (CGM.getCodeGenOpts().OptimizationLevel != 0 &&
3646 !CGM.getCodeGenOpts().ObjCAutoRefCountExceptions)
3647 Inst->setMetadata(
"clang.arc.no_objc_arc_exceptions",
3648 CGM.getNoObjCARCExceptionsMetadata());
3654 const llvm::Twine &
name) {
3655 return EmitNounwindRuntimeCall(callee, None, name);
3662 const llvm::Twine &name) {
3663 llvm::CallInst *call = EmitRuntimeCall(callee, args, name);
3664 call->setDoesNotThrow();
3671 const llvm::Twine &name) {
3672 return EmitRuntimeCall(callee, None, name);
3682 if (!CurrentFuncletPad)
3686 auto *CalleeFn = dyn_cast<llvm::Function>(Callee->stripPointerCasts());
3687 if (CalleeFn && CalleeFn->isIntrinsic() && CalleeFn->doesNotThrow())
3690 BundleList.emplace_back(
"funclet", CurrentFuncletPad);
3697 const llvm::Twine &name) {
3698 llvm::CallInst *call = Builder.CreateCall(
3699 callee, args, getBundlesForFunclet(callee.getCallee()), name);
3700 call->setCallingConv(getRuntimeCC());
3708 getBundlesForFunclet(callee.getCallee());
3710 if (getInvokeDest()) {
3711 llvm::InvokeInst *invoke =
3712 Builder.CreateInvoke(callee,
3713 getUnreachableBlock(),
3717 invoke->setDoesNotReturn();
3718 invoke->setCallingConv(getRuntimeCC());
3720 llvm::CallInst *call = Builder.CreateCall(callee, args, BundleList);
3721 call->setDoesNotReturn();
3722 call->setCallingConv(getRuntimeCC());
3723 Builder.CreateUnreachable();
3730 const Twine &name) {
3731 return EmitRuntimeCallOrInvoke(callee, None, name);
3738 const Twine &name) {
3739 llvm::CallBase *call = EmitCallOrInvoke(callee, args, name);
3740 call->setCallingConv(getRuntimeCC());
3748 const Twine &Name) {
3749 llvm::BasicBlock *InvokeDest = getInvokeDest();
3751 getBundlesForFunclet(Callee.getCallee());
3753 llvm::CallBase *Inst;
3755 Inst = Builder.CreateCall(Callee, Args, BundleList, Name);
3757 llvm::BasicBlock *ContBB = createBasicBlock(
"invoke.cont");
3758 Inst = Builder.CreateInvoke(Callee, ContBB, InvokeDest, Args, BundleList,
3765 if (CGM.getLangOpts().ObjCAutoRefCount)
3766 AddObjCARCExceptionMetadata(Inst);
3771 void CodeGenFunction::deferPlaceholderReplacement(llvm::Instruction *Old,
3773 DeferredReplacements.push_back(std::make_pair(Old, New));
3780 llvm::CallBase **callOrInvoke,
3791 llvm::FunctionType *IRFuncTy = getTypes().GetFunctionType(CallInfo);
3794 if (
const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(TargetDecl))
3801 if (TargetDecl->
hasAttr<AlwaysInlineAttr>() &&
3802 TargetDecl->
hasAttr<TargetAttr>())
3803 checkTargetFeatures(Loc, FD);
3820 assert(IRFuncTy == TypeFromVal);
3829 if (llvm::StructType *ArgStruct = CallInfo.
getArgStruct()) {
3830 const llvm::DataLayout &DL = CGM.getDataLayout();
3832 llvm::AllocaInst *AI;
3834 IP = IP->getNextNode();
3835 AI =
new llvm::AllocaInst(ArgStruct, DL.getAllocaAddrSpace(),
3838 AI = CreateTempAlloca(ArgStruct,
"argmem");
3841 AI->setAlignment(Align.getQuantity());
3842 AI->setUsedWithInAlloca(
true);
3843 assert(AI->isUsedWithInAlloca() && !AI->isStaticAlloca());
3844 ArgMemory =
Address(AI, Align);
3847 ClangToLLVMArgMapping IRFunctionArgs(CGM.getContext(), CallInfo);
3856 if (!ReturnValue.
isNull()) {
3859 SRetPtr = CreateMemTemp(RetTy,
"tmp", &SRetAlloca);
3860 if (HaveInsertPoint() && ReturnValue.
isUnused()) {
3863 UnusedReturnSizePtr = EmitLifetimeStart(size, SRetAlloca.
getPointer());
3866 if (IRFunctionArgs.hasSRetArg()) {
3867 IRCallArgs[IRFunctionArgs.getSRetArgNo()] = SRetPtr.getPointer();
3871 Builder.CreateStore(SRetPtr.getPointer(), Addr);
3879 assert(CallInfo.
arg_size() == CallArgs.size() &&
3880 "Mismatch between function signature & arguments.");
3883 for (CallArgList::const_iterator I = CallArgs.begin(), E = CallArgs.end();
3884 I != E; ++I, ++info_it, ++ArgNo) {
3888 if (IRFunctionArgs.hasPaddingArg(ArgNo))
3889 IRCallArgs[IRFunctionArgs.getPaddingArgNo(ArgNo)] =
3892 unsigned FirstIRArg, NumIRArgs;
3893 std::tie(FirstIRArg, NumIRArgs) = IRFunctionArgs.getIRArgs(ArgNo);
3897 assert(NumIRArgs == 0);
3898 assert(
getTarget().getTriple().getArch() == llvm::Triple::x86);
3899 if (I->isAggregate()) {
3902 ? I->getKnownLValue().getAddress()
3903 : I->getKnownRValue().getAggregateAddress();
3904 llvm::Instruction *Placeholder =
3906 CGBuilderTy::InsertPoint IP = Builder.saveIP();
3907 Builder.SetInsertPoint(Placeholder);
3910 Builder.restoreIP(IP);
3911 deferPlaceholderReplacement(Placeholder, Addr.
getPointer());
3916 unsigned AS = Addr.
getType()->getPointerAddressSpace();
3921 if (Addr.
getType() != MemType)
3922 Addr = Builder.CreateBitCast(Addr, MemType);
3923 I->copyInto(*
this, Addr);
3929 assert(NumIRArgs == 1);
3930 if (!I->isAggregate()) {
3932 Address Addr = CreateMemTempWithoutCast(
3936 I->copyInto(*
this, Addr);
3947 ? I->getKnownLValue().getAddress()
3948 : I->getKnownRValue().getAggregateAddress();
3951 const llvm::DataLayout *TD = &CGM.getDataLayout();
3953 assert((FirstIRArg >= IRFuncTy->getNumParams() ||
3954 IRFuncTy->getParamType(FirstIRArg)->getPointerAddressSpace() ==
3955 TD->getAllocaAddrSpace()) &&
3956 "indirect argument must be in alloca address space");
3958 bool NeedCopy =
false;
3961 llvm::getOrEnforceKnownAlignment(V, Align.
getQuantity(), *TD) <
3964 }
else if (I->hasLValue()) {
3965 auto LV = I->getKnownLValue();
3973 if (!getLangOpts().OpenCL) {
3976 AS != CGM.getASTAllocaAddressSpace()))) {
3983 Addr.
getType()->getAddressSpace() != IRFuncTy->
3991 Address AI = CreateMemTempWithoutCast(
3994 I->copyInto(*
this, AI);
3997 auto *T = V->getType()->getPointerElementType()->getPointerTo(
3998 CGM.getDataLayout().getAllocaAddrSpace());
3999 IRCallArgs[FirstIRArg] = getTargetHooks().performAddrSpaceCast(
4008 assert(NumIRArgs == 0);
4016 assert(NumIRArgs == 1);
4018 if (!I->isAggregate())
4019 V = I->getKnownRValue().getScalarVal();
4021 V = Builder.CreateLoad(
4022 I->hasLValue() ? I->getKnownLValue().getAddress()
4023 : I->getKnownRValue().getAggregateAddress());
4029 assert(!swiftErrorTemp.
isValid() &&
"multiple swifterror args");
4036 CreateMemTemp(pointeeTy, getPointerAlign(),
"swifterror.temp");
4038 cast<llvm::AllocaInst>(
V)->setSwiftError(
true);
4040 llvm::Value *errorValue = Builder.CreateLoad(swiftErrorArg);
4041 Builder.CreateStore(errorValue, swiftErrorTemp);
4046 V->getType()->isIntegerTy())
4051 if (FirstIRArg < IRFuncTy->getNumParams() &&
4052 V->getType() != IRFuncTy->getParamType(FirstIRArg))
4053 V = Builder.CreateBitCast(V, IRFuncTy->getParamType(FirstIRArg));
4055 IRCallArgs[FirstIRArg] =
V;
4061 if (!I->isAggregate()) {
4062 Src = CreateMemTemp(I->Ty,
"coerce");
4063 I->copyInto(*
this, Src);
4065 Src = I->hasLValue() ? I->getKnownLValue().getAddress()
4066 : I->getKnownRValue().getAggregateAddress();
4074 llvm::StructType *STy =
4078 uint64_t SrcSize = CGM.getDataLayout().getTypeAllocSize(SrcTy);
4079 uint64_t DstSize = CGM.getDataLayout().getTypeAllocSize(STy);
4085 if (SrcSize < DstSize) {
4089 Builder.CreateMemCpy(TempAlloca, Src, SrcSize);
4092 Src = Builder.CreateBitCast(Src,
4096 assert(NumIRArgs == STy->getNumElements());
4097 for (
unsigned i = 0, e = STy->getNumElements();
i != e; ++
i) {
4098 Address EltPtr = Builder.CreateStructGEP(Src,
i);
4100 IRCallArgs[FirstIRArg +
i] = LI;
4104 assert(NumIRArgs == 1);
4105 IRCallArgs[FirstIRArg] =
4114 auto layout = CGM.getDataLayout().getStructLayout(coercionType);
4119 if (I->isAggregate()) {
4120 addr = I->hasLValue() ? I->getKnownLValue().getAddress()
4121 : I->getKnownRValue().getAggregateAddress();
4124 RValue RV = I->getKnownRValue();
4128 auto scalarSize = CGM.getDataLayout().getTypeAllocSize(scalarType);
4129 auto scalarAlign = CGM.getDataLayout().getPrefTypeAlignment(scalarType);
4134 layout->getAlignment(), scalarAlign)),
4136 nullptr, &AllocaAddr);
4137 tempSize = EmitLifetimeStart(scalarSize, AllocaAddr.
getPointer());
4142 addr = Builder.CreateElementBitCast(addr, coercionType);
4144 unsigned IRArgPos = FirstIRArg;
4145 for (
unsigned i = 0, e = coercionType->getNumElements();
i != e; ++
i) {
4146 llvm::Type *eltType = coercionType->getElementType(
i);
4148 Address eltAddr = Builder.CreateStructGEP(addr,
i);
4150 IRCallArgs[IRArgPos++] = elt;
4152 assert(IRArgPos == FirstIRArg + NumIRArgs);
4155 EmitLifetimeEnd(tempSize, AllocaAddr.
getPointer());
4162 unsigned IRArgPos = FirstIRArg;
4163 ExpandTypeToArgs(I->Ty, *I, IRFuncTy, IRCallArgs, IRArgPos);
4164 assert(IRArgPos == FirstIRArg + NumIRArgs);
4180 unsigned CalleeAS = CalleePtr->getType()->getPointerAddressSpace();
4182 Builder.CreateBitCast(CalleePtr, IRFuncTy->getPointerTo(CalleeAS));
4185 IRFuncTy->getParamType(IRFuncTy->getNumParams() - 1);
4186 if (Arg->getType() != LastParamTy) {
4190 llvm::StructType *DeclaredTy = cast<llvm::StructType>(
4191 cast<llvm::PointerType>(LastParamTy)->getElementType());
4192 assert(DeclaredTy->getNumElements() == FullTy->getNumElements());
4193 for (llvm::StructType::element_iterator DI = DeclaredTy->element_begin(),
4194 DE = DeclaredTy->element_end(),
4195 FI = FullTy->element_begin();
4196 DI != DE; ++DI, ++FI)
4199 Arg = Builder.CreateBitCast(Arg, LastParamTy);
4202 assert(IRFunctionArgs.hasInallocaArg());
4203 IRCallArgs[IRFunctionArgs.getInallocaArgNo()] = Arg;
4214 auto simplifyVariadicCallee = [](llvm::FunctionType *CalleeFT,
4216 if (!CalleeFT->isVarArg())
4220 if (llvm::ConstantExpr *CE = dyn_cast<llvm::ConstantExpr>(Ptr)) {
4221 if (CE->getOpcode() == llvm::Instruction::BitCast)
4222 Ptr = CE->getOperand(0);
4225 llvm::Function *OrigFn = dyn_cast<llvm::Function>(Ptr);
4229 llvm::FunctionType *OrigFT = OrigFn->getFunctionType();
4233 if (OrigFT->isVarArg() ||
4234 OrigFT->getNumParams() != CalleeFT->getNumParams() ||
4235 OrigFT->getReturnType() != CalleeFT->getReturnType())
4238 for (
unsigned i = 0, e = OrigFT->getNumParams();
i != e; ++
i)
4239 if (OrigFT->getParamType(
i) != CalleeFT->getParamType(
i))
4245 if (llvm::Function *OrigFn = simplifyVariadicCallee(IRFuncTy, CalleePtr)) {
4247 IRFuncTy = OrigFn->getFunctionType();
4262 assert(IRCallArgs.size() == IRFuncTy->getNumParams() || IRFuncTy->isVarArg());
4263 for (
unsigned i = 0;
i < IRCallArgs.size(); ++
i) {
4265 if (IRFunctionArgs.hasInallocaArg() &&
4266 i == IRFunctionArgs.getInallocaArgNo())
4268 if (i < IRFuncTy->getNumParams())
4269 assert(IRCallArgs[
i]->getType() == IRFuncTy->getParamType(
i));
4274 for (
unsigned i = 0;
i < IRCallArgs.size(); ++
i) {
4275 if (
auto *VT = dyn_cast<llvm::VectorType>(IRCallArgs[
i]->getType()))
4276 LargestVectorWidth =
std::max(LargestVectorWidth,
4277 VT->getPrimitiveSizeInBits());
4282 llvm::AttributeList Attrs;
4283 CGM.ConstructAttributeList(CalleePtr->getName(), CallInfo,
4292 if (CurCodeDecl && CurCodeDecl->hasAttr<FlattenAttr>() &&
4293 !(TargetDecl && TargetDecl->
hasAttr<NoInlineAttr>())) {
4295 Attrs.addAttribute(
getLLVMContext(), llvm::AttributeList::FunctionIndex,
4296 llvm::Attribute::AlwaysInline);
4300 if (isSEHTryScope()) {
4302 Attrs.addAttribute(
getLLVMContext(), llvm::AttributeList::FunctionIndex,
4303 llvm::Attribute::NoInline);
4308 if (currentFunctionUsesSEHTry()) {
4310 CannotThrow =
false;
4311 }
else if (isCleanupPadScope() &&
4319 CannotThrow = Attrs.hasAttribute(llvm::AttributeList::FunctionIndex,
4320 llvm::Attribute::NoUnwind);
4327 if (UnusedReturnSizePtr)
4329 UnusedReturnSizePtr);
4331 llvm::BasicBlock *InvokeDest = CannotThrow ? nullptr : getInvokeDest();
4334 getBundlesForFunclet(CalleePtr);
4339 CI = Builder.CreateCall(IRFuncTy, CalleePtr, IRCallArgs, BundleList);
4341 llvm::BasicBlock *Cont = createBasicBlock(
"invoke.cont");
4342 CI = Builder.CreateInvoke(IRFuncTy, CalleePtr, Cont, InvokeDest, IRCallArgs,
4350 CI->setAttributes(Attrs);
4351 CI->setCallingConv(static_cast<llvm::CallingConv::ID>(CallingConv));
4355 if (!CI->getType()->isVoidTy())
4356 CI->setName(
"call");
4359 if (
auto *VT = dyn_cast<llvm::VectorType>(CI->getType()))
4360 LargestVectorWidth =
std::max(LargestVectorWidth,
4361 VT->getPrimitiveSizeInBits());
4366 if (!CI->getCalledFunction())
4367 PGO.valueProfile(Builder, llvm::IPVK_IndirectCallTarget,
4372 if (CGM.getLangOpts().ObjCAutoRefCount)
4373 AddObjCARCExceptionMetadata(CI);
4376 if (llvm::CallInst *Call = dyn_cast<llvm::CallInst>(CI)) {
4377 if (TargetDecl && TargetDecl->
hasAttr<NotTailCalledAttr>())
4378 Call->setTailCallKind(llvm::CallInst::TCK_NoTail);
4382 if (getDebugInfo() && TargetDecl &&
4383 TargetDecl->
hasAttr<MSAllocatorAttr>())
4384 getDebugInfo()->addHeapAllocSiteMetadata(CI, RetTy, Loc);
4391 if (CI->doesNotReturn()) {
4392 if (UnusedReturnSizePtr)
4396 if (SanOpts.has(SanitizerKind::Unreachable)) {
4399 if (
auto *F = CI->getCalledFunction())
4400 F->removeFnAttr(llvm::Attribute::NoReturn);
4401 CI->removeAttribute(llvm::AttributeList::FunctionIndex,
4402 llvm::Attribute::NoReturn);
4406 if (SanOpts.hasOneOf(SanitizerKind::Address |
4407 SanitizerKind::KernelAddress)) {
4409 llvm::IRBuilder<>::InsertPointGuard IPGuard(Builder);
4410 Builder.SetInsertPoint(CI);
4411 auto *FnType = llvm::FunctionType::get(CGM.VoidTy,
false);
4412 llvm::FunctionCallee Fn =
4413 CGM.CreateRuntimeFunction(FnType,
"__asan_handle_no_return");
4414 EmitNounwindRuntimeCall(Fn);
4418 EmitUnreachable(Loc);
4419 Builder.ClearInsertionPoint();
4424 EnsureInsertPoint();
4427 return GetUndefRValue(RetTy);
4431 if (swiftErrorTemp.
isValid()) {
4432 llvm::Value *errorResult = Builder.CreateLoad(swiftErrorTemp);
4433 Builder.CreateStore(errorResult, swiftErrorArg);
4452 addr = Builder.CreateElementBitCast(addr, coercionType);
4455 bool requiresExtract = isa<llvm::StructType>(CI->getType());
4457 unsigned unpaddedIndex = 0;
4458 for (
unsigned i = 0, e = coercionType->getNumElements();
i != e; ++
i) {
4459 llvm::Type *eltType = coercionType->getElementType(
i);
4461 Address eltAddr = Builder.CreateStructGEP(addr,
i);
4463 if (requiresExtract)
4464 elt = Builder.CreateExtractValue(elt, unpaddedIndex++);
4466 assert(unpaddedIndex == 0);
4467 Builder.CreateStore(elt, eltAddr);
4476 if (UnusedReturnSizePtr)
4484 return GetUndefRValue(RetTy);
4490 switch (getEvaluationKind(RetTy)) {
4492 llvm::Value *Real = Builder.CreateExtractValue(CI, 0);
4493 llvm::Value *Imag = Builder.CreateExtractValue(CI, 1);
4498 bool DestIsVolatile = ReturnValue.
isVolatile();
4501 DestPtr = CreateMemTemp(RetTy,
"agg.tmp");
4502 DestIsVolatile =
false;
4511 if (V->getType() != RetIRTy)
4512 V = Builder.CreateBitCast(V, RetIRTy);
4516 llvm_unreachable(
"bad evaluation kind");
4520 bool DestIsVolatile = ReturnValue.
isVolatile();
4523 DestPtr = CreateMemTemp(RetTy,
"coerce");
4524 DestIsVolatile =
false;
4535 llvm_unreachable(
"Invalid ABI kind for return argument");
4538 llvm_unreachable(
"Unhandled ABIArgInfo::Kind");
4542 if (Ret.
isScalar() && TargetDecl) {
4543 if (
const auto *AA = TargetDecl->
getAttr<AssumeAlignedAttr>()) {
4545 if (
const auto *
Offset = AA->getOffset())
4546 OffsetValue = EmitScalarExpr(
Offset);
4548 llvm::Value *Alignment = EmitScalarExpr(AA->getAlignment());
4549 llvm::ConstantInt *AlignmentCI = cast<llvm::ConstantInt>(Alignment);
4550 EmitAlignmentAssumption(Ret.
getScalarVal(), RetTy, Loc, AA->getLocation(),
4551 AlignmentCI->getZExtValue(), OffsetValue);
4552 }
else if (
const auto *AA = TargetDecl->
getAttr<AllocAlignAttr>()) {
4553 llvm::Value *AlignmentVal = CallArgs[AA->getParamIndex().getLLVMIndex()]
4556 EmitAlignmentAssumption(Ret.
getScalarVal(), RetTy, Loc, AA->getLocation(),
4566 const CallExpr *CE = getVirtualCallExpr();
4568 CGF, getVirtualMethodDecl(), getThisAddress(), getVirtualFunctionType(),
4583 return CGM.getTypes().getABIInfo().EmitMSVAArg(*
this, VAListAddr, Ty);
4584 return CGM.getTypes().getABIInfo().EmitVAArg(*
this, VAListAddr, Ty);
const CGFunctionInfo & arrangeBuiltinFunctionDeclaration(QualType resultType, const FunctionArgList &args)
A builtin function is a freestanding function using the default C conventions.
const llvm::DataLayout & getDataLayout() const
static CanQual< Type > CreateUnsafe(QualType Other)
Builds a canonical type from a QualType.
ObjCIndirectCopyRestoreExpr - Represents the passing of a function argument by indirect copy-restore ...
CGCXXABI & getCXXABI() const
Ignore - Ignore the argument (treat as void).
ReturnValueSlot - Contains the address where the return value of a function can be stored...
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
Address CreateStructGEP(Address Addr, unsigned Index, const llvm::Twine &Name="")
QualType getAddrSpaceQualType(QualType T, LangAS AddressSpace) const
Return the uniqued reference to the type for an address space qualified type with the specified type ...
CanQualType DeriveThisType(const CXXRecordDecl *RD, const CXXMethodDecl *MD)
Derives the 'this' type for codegen purposes, i.e.
Represents a function declaration or definition.
Address getAddress() const
void end(CodeGenFunction &CGF)
const CGFunctionInfo & arrangeBlockFunctionDeclaration(const FunctionProtoType *type, const FunctionArgList &args)
Block invocation functions are C functions with an implicit parameter.
void EmitReturnValueCheck(llvm::Value *RV)
Emit a test that checks if the return value RV is nonnull.
PointerType - C99 6.7.5.1 - Pointer Declarators.
A (possibly-)qualified type.
bool isBlockPointerType() const
bool ReturnTypeUsesSRet(const CGFunctionInfo &FI)
Return true iff the given type uses 'sret' when used as a return type.
bool getNoCfCheck() const
llvm::Type * ConvertTypeForMem(QualType T)
const CodeGenOptions & getCodeGenOpts() const
bool isReturnsRetained() const
In ARC, whether this function retains its return value.
static void setCUDAKernelCallingConvention(CanQualType &FTy, CodeGenModule &CGM, const FunctionDecl *FD)
Set calling convention for CUDA/HIP kernel.
static CanQual< FunctionProtoType > GetFormalType(const CXXMethodDecl *MD)
Returns the canonical formal type of the given C++ method.
Address CreateMemTemp(QualType T, const Twine &Name="tmp", Address *Alloca=nullptr)
CreateMemTemp - Create a temporary memory object of the given type, with appropriate alignmen and cas...
static void emitWriteback(CodeGenFunction &CGF, const CallArgList::Writeback &writeback)
Emit the actual writing-back of a writeback.
static Address CreateTempAllocaForCoercion(CodeGenFunction &CGF, llvm::Type *Ty, CharUnits MinAlign)
Create a temporary allocation for the purposes of coercion.
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.
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
bool hasExtParameterInfos() const
Is there any interesting extra information for any of the parameters of this function type...
unsigned getNumVBases() const
Retrieves the number of virtual base classes of this class.
Extend - Valid only for integer argument types.
Address EmitPointerWithAlignment(const Expr *Addr, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr)
EmitPointerWithAlignment - Given an expression with a pointer type, emit the value and compute our be...
Address EmitVAArg(VAArgExpr *VE, Address &VAListAddr)
Generate code to get an argument from the passed in pointer and update it accordingly.
static bool isProvablyNull(llvm::Value *addr)
Decl - This represents one declaration (or definition), e.g.
const CGFunctionInfo & arrangeCXXMethodType(const CXXRecordDecl *RD, const FunctionProtoType *FTP, const CXXMethodDecl *MD)
Arrange the argument and result information for a call to an unknown C++ non-static member function o...
CGCallee prepareConcreteCallee(CodeGenFunction &CGF) const
If this is a delayed callee computation of some sort, prepare a concrete callee.
const Decl * CurCodeDecl
CurCodeDecl - This is the inner-most code context, which includes blocks.
Direct - Pass the argument directly using the normal converted LLVM type, or by coercing to another s...
const Expr * getSubExpr() const
void addUncopiedAggregate(LValue LV, QualType type)
The base class of the type hierarchy.
void EmitStoreThroughLValue(RValue Src, LValue Dst, bool isInit=false)
EmitStoreThroughLValue - Store the specified rvalue into the specified lvalue, where both are guarant...
CanQual< T > getUnqualifiedType() const
Retrieve the unqualified form of this type.
static const NonNullAttr * getNonNullAttr(const Decl *FD, const ParmVarDecl *PVD, QualType ArgType, unsigned ArgNo)
Returns the attribute (either parameter attribute, or function attribute), which declares argument Ar...
bool isRestrictQualified() const
Determine whether this type is restrict-qualified.
bool isZero() const
isZero - Test whether the quantity equals zero.
static int getExpansionSize(QualType Ty, const ASTContext &Context)
const TargetInfo & getTargetInfo() const
const ParmVarDecl * getParamDecl(unsigned I) const
bool isFuncTypeConvertible(const FunctionType *FT)
isFuncTypeConvertible - Utility to check whether a function type can be converted to an LLVM type (i...
llvm::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.
static llvm::Value * emitArgumentDemotion(CodeGenFunction &CGF, const VarDecl *var, llvm::Value *value)
An argument came in as a promoted argument; demote it back to its declared type.
bool hasWritebacks() const
bool isCoerceAndExpand() const
Default closure variant of a ctor.
Address GetAddrOfLocalVar(const VarDecl *VD)
GetAddrOfLocalVar - Return the address of a local variable.
CanQualType getCanonicalParamType(QualType T) const
Return the canonical parameter type corresponding to the specific potentially non-canonical one...
Represents a variable declaration or definition.
static void addExtParameterInfosForCall(llvm::SmallVectorImpl< FunctionProtoType::ExtParameterInfo > ¶mInfos, const FunctionProtoType *proto, unsigned prefixArgs, unsigned totalArgs)
llvm::Instruction * getStackBase() const
unsigned getNumParams() const
RAII object to set/unset CodeGenFunction::IsSanitizerScope.
llvm::Value * getFunctionPointer() const
static llvm::Value * CreateCoercedLoad(Address Src, llvm::Type *Ty, CodeGenFunction &CGF)
CreateCoercedLoad - Create a load from.
const T * getAs() const
Member-template getAs<specific type>'.
void setCoerceToType(llvm::Type *T)
void EmitCXXDestructorCall(const CXXDestructorDecl *D, CXXDtorType Type, bool ForVirtualBase, bool Delegating, Address This, QualType ThisTy)
ExtInfo withProducesResult(bool producesResult) const
ObjCMethodDecl - Represents an instance or class method declaration.
static const CGFunctionInfo & arrangeLLVMFunctionInfo(CodeGenTypes &CGT, bool instanceMethod, SmallVectorImpl< CanQualType > &prefix, CanQual< FunctionProtoType > FTP)
Arrange the LLVM function layout for a value of the given function type, on top of any implicit param...
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()
llvm::Type * ConvertTypeForMem(QualType T)
ConvertTypeForMem - Convert type T into a llvm::Type.
const CGFunctionInfo & arrangeFreeFunctionType(CanQual< FunctionProtoType > Ty)
Arrange the argument and result information for a value of the given freestanding function type...
Represents a parameter to a function.
bool hasFunctionDecl() const
unsigned getAddressSpace() const
Return the address space that this address resides in.
void add(RValue rvalue, QualType type)
unsigned ClangCallConvToLLVMCallConv(CallingConv CC)
Convert clang calling convention to LLVM callilng convention.
unsigned arg_size() const
virtual unsigned getOpenCLKernelCallingConv() const
Get LLVM calling convention for OpenCL kernel.
Represents a struct/union/class.
void freeArgumentMemory(CodeGenFunction &CGF) const
uint64_t getPointerWidth(unsigned AddrSpace) const
Return the width of pointers on this target, for the specified address space.
An object to manage conditionally-evaluated expressions.
Description of a constructor that was inherited from a base class.
bool usesInAlloca() const
Return true if this function uses inalloca arguments.
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
static void emitWritebacks(CodeGenFunction &CGF, const CallArgList &args)
void EmitFunctionEpilog(const CGFunctionInfo &FI, bool EmitRetDbgLoc, SourceLocation EndLoc)
EmitFunctionEpilog - Emit the target specific LLVM code to return the given temporary.
bool isNothrow(bool ResultIfDependent=false) const
Determine whether this function type has a non-throwing exception specification.
Address getAddress() const
unsigned getRegParm() const
Indirect - Pass the argument indirectly via a hidden pointer with the specified alignment (0 indicate...
CGDebugInfo * getDebugInfo()
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
llvm::Type * ConvertType(QualType T)
ConvertType - Convert type T into a llvm::Type.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
ArrayRef< ExtParameterInfo > getExtParameterInfos() const
field_range fields() const
bool isVolatileQualified() const
llvm::Value * EmitARCRetainAutoreleaseReturnValue(llvm::Value *value)
Do a fused retain/autorelease of the given object.
Represents a member of a struct/union/class.
CharUnits getAlignment() const
RequiredArgs getRequiredArgs() const
bool isUsingInAlloca() const
Returns if we're using an inalloca struct to pass arguments in memory.
unsigned getFunctionScopeIndex() const
Returns the index of this parameter in its prototype or method scope.
Qualifiers::ObjCLifetime getObjCLifetime() const
CharUnits getArgStructAlignment() const
bool isReferenceType() const
Denotes a cleanup that should run when a scope is exited using exceptional control flow (a throw stat...
llvm::Value * EmitARCAutoreleaseReturnValue(llvm::Value *value)
Autorelease the given object.
static void emitWritebackArg(CodeGenFunction &CGF, CallArgList &args, const ObjCIndirectCopyRestoreExpr *CRE)
Emit an argument that's being passed call-by-writeback.
static AggValueSlot forAddr(Address addr, Qualifiers quals, IsDestructed_t isDestructed, NeedsGCBarriers_t needsGC, IsAliased_t isAliased, Overlap_t mayOverlap, IsZeroed_t isZeroed=IsNotZeroed, IsSanitizerChecked_t isChecked=IsNotSanitizerChecked)
forAddr - Make a slot for an aggregate value.
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
static const EHPersonality & get(CodeGenModule &CGM, const FunctionDecl *FD)
__DEVICE__ int max(int __a, int __b)
SourceLocation getBeginLoc() const LLVM_READONLY
unsigned getNumParams() const
void EmitStoreOfScalar(llvm::Value *Value, Address Addr, bool Volatile, QualType Ty, AlignmentSource Source=AlignmentSource::Type, bool isInit=false, bool isNontemporal=false)
EmitStoreOfScalar - Store a scalar value to an address, taking care to appropriately convert from the...
void addArgCleanupDeactivation(EHScopeStack::stable_iterator Cleanup, llvm::Instruction *IsActiveIP)
bool getProducesResult() const
ARCPreciseLifetime_t isARCPreciseLifetime() const
This parameter (which must have pointer type) uses the special Swift context-pointer ABI treatment...
static bool hasScalarEvaluationKind(QualType T)
static llvm::Value * tryEmitFusedAutoreleaseOfResult(CodeGenFunction &CGF, llvm::Value *result)
Try to emit a fused autorelease of a return result.
void copyInto(CodeGenFunction &CGF, Address A) const
Address CreateElementBitCast(Address Addr, llvm::Type *Ty, const llvm::Twine &Name="")
Cast the element type of the given address to a different type, preserving information like the align...
CharUnits - This is an opaque type for sizes expressed in character units.
llvm::StructType * getCoerceAndExpandType() const
llvm::CallInst * EmitRuntimeCall(llvm::FunctionCallee callee, const Twine &name="")
bool hasConstructorVariants() const
Does this ABI have different entrypoints for complete-object and base-subobject constructors?
Wrapper for source info for functions.
CharUnits getAlignment() const
Return the alignment of this pointer.
virtual bool hasMostDerivedReturn(GlobalDecl GD) const
unsigned getInAllocaFieldIndex() const
const_arg_iterator arg_begin() const
CXXCtorType getCtorType() const
const CGFunctionInfo & arrangeCXXConstructorCall(const CallArgList &Args, const CXXConstructorDecl *D, CXXCtorType CtorKind, unsigned ExtraPrefixArgs, unsigned ExtraSuffixArgs, bool PassProtoArgs=true)
Arrange a call to a C++ method, passing the given arguments.
LangAS getAddressSpace() const
void ConstructAttributeList(StringRef Name, const CGFunctionInfo &Info, CGCalleeInfo CalleeInfo, llvm::AttributeList &Attrs, unsigned &CallingConv, bool AttrOnCallSite)
Get the LLVM attributes and calling convention to use for a particular function type.
llvm::CallInst * CreateMemCpy(Address Dest, Address Src, llvm::Value *Size, bool IsVolatile=false)
ABIArgInfo - Helper class to encapsulate information about how a specific C type should be passed to ...
static void appendParameterTypes(const CodeGenTypes &CGT, SmallVectorImpl< CanQualType > &prefix, SmallVectorImpl< FunctionProtoType::ExtParameterInfo > ¶mInfos, CanQual< FunctionProtoType > FPT)
Adds the formal parameters in FPT to the given prefix.
const CGFunctionInfo & arrangeObjCMessageSendSignature(const ObjCMethodDecl *MD, QualType receiverType)
Arrange the argument and result information for the function type through which to perform a send to ...
const CGFunctionInfo & arrangeCall(const CGFunctionInfo &declFI, const CallArgList &args)
Given a function info for a declaration, return the function info for a call with the given arguments...
Values of this type can never be null.
llvm::BasicBlock * createBasicBlock(const Twine &name="", llvm::Function *parent=nullptr, llvm::BasicBlock *before=nullptr)
createBasicBlock - Create an LLVM basic block.
Denotes a cleanup that should run when a scope is exited using normal control flow (falling off the e...
const CGFunctionInfo & arrangeCXXMethodDeclaration(const CXXMethodDecl *MD)
C++ methods have some special rules and also have implicit parameters.
CharUnits getPointerAlign() const
An ordinary object is located at an address in memory.
CXXDestructorDecl * getDestructor() const
Returns the destructor decl for this class.
llvm::AllocaInst * CreateTempAlloca(llvm::Type *Ty, const Twine &Name="tmp", llvm::Value *ArraySize=nullptr)
CreateTempAlloca - This creates an alloca and inserts it into the entry block if ArraySize is nullptr...
FunctionType::ExtInfo getExtInfo() const
QualType getReturnType() const
const CGFunctionInfo & arrangeLLVMFunctionInfo(CanQualType returnType, bool instanceMethod, bool chainCall, ArrayRef< CanQualType > argTypes, FunctionType::ExtInfo info, ArrayRef< FunctionProtoType::ExtParameterInfo > paramInfos, RequiredArgs args)
"Arrange" the LLVM information for a call or type with the given signature.
const T * getTypePtr() const
Retrieve the underlying type pointer, which refers to a canonical type.
Address getAggregateAddress() const
getAggregateAddr() - Return the Value* of the address of the aggregate.
const Decl * getDecl() const
bool getNoCallerSavedRegs() const
virtual AddedStructorArgs buildStructorSignature(GlobalDecl GD, SmallVectorImpl< CanQualType > &ArgTys)=0
Build the signature of the given constructor or destructor variant by adding any required parameters...
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)
CallingConv getDefaultCallingConvention(bool IsVariadic, bool IsCXXMethod, bool IsBuiltin=false) const
Retrieves the default calling convention for the current target.
const CGFunctionInfo & arrangeGlobalDeclaration(GlobalDecl GD)
virtual void setCUDAKernelCallingConvention(const FunctionType *&FT) const
ExtInfo withCallingConv(CallingConv cc) const
llvm::Value * EmitLoadOfScalar(Address Addr, bool Volatile, QualType Ty, SourceLocation Loc, AlignmentSource Source=AlignmentSource::Type, bool isNontemporal=false)
EmitLoadOfScalar - Load a scalar value from an address, taking care to appropriately convert from the...
const CGFunctionInfo & arrangeUnprototypedObjCMessageSend(QualType returnType, const CallArgList &args)
Represents a K&R-style 'int foo()' function, which has no information available about its arguments...
CanQualType getReturnType() const
unsigned getNumRequiredArgs() const
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.
bool isMicrosoftABI() const
Returns whether this is really a Win64 ABI va_arg expression.
bool allowsOptionalArgs() const
const TargetCodeGenInfo & getTargetCodeGenInfo()
llvm::Function * objc_retainAutoreleasedReturnValue
id objc_retainAutoreleasedReturnValue(id);
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.
const CGFunctionInfo & arrangeCXXStructorDeclaration(GlobalDecl GD)
ExtParameterInfo withIsNoEscape(bool NoEscape) const
static AggValueSlot createPlaceholderSlot(CodeGenFunction &CGF, QualType Ty)
This represents one expression.
llvm::Type * getUnpaddedCoerceAndExpandType() const
static bool isInAllocaArgument(CGCXXABI &ABI, QualType type)
bool useObjCFPRetForRealType(RealType T) const
Check whether the given real type should use the "fpret" flavor of Objective-C message passing on thi...
static CanQualType GetReturnType(QualType RetTy)
Returns the "extra-canonicalized" return type, which discards qualifiers on the return type...
std::pair< llvm::Value *, llvm::Value * > getComplexVal() const
getComplexVal - Return the real/imag components of this complex value.
void EmitCallArgs(CallArgList &Args, const T *CallArgTypeInfo, llvm::iterator_range< CallExpr::const_arg_iterator > ArgRange, AbstractCallee AC=AbstractCallee(), unsigned ParamsToSkip=0, EvaluationOrder Order=EvaluationOrder::Default)
EmitCallArgs - Emit call arguments for a function.
const CGFunctionInfo & arrangeNullaryFunction()
A nullary function is a freestanding function of type 'void ()'.
bool getHasRegParm() const
const T * castAs() const
Member-template castAs<specific type>.
bool isObjCRetainableType() const
Represents a C++ destructor within a class.
QualType getTagDeclType(const TagDecl *Decl) const
Return the unique reference to the type for the specified TagDecl (struct/union/class/enum) decl...
llvm::PointerType * getType() const
Return the type of the pointer value.
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
static bool isPaddingForCoerceAndExpand(llvm::Type *eltType)
static SmallVector< CanQualType, 16 > getArgTypesForCall(ASTContext &ctx, const CallArgList &args)
static void eraseUnusedBitCasts(llvm::Instruction *insn)
SmallVector< llvm::OperandBundleDef, 1 > getBundlesForFunclet(llvm::Value *Callee)
A class for recording the number of arguments that a function signature requires. ...
bool ReturnSlotInterferesWithArgs(const CGFunctionInfo &FI)
Return true iff the given type uses an argument slot when 'sret' is used as a return type...
const CGFunctionInfo & arrangeBuiltinFunctionCall(QualType resultType, const CallArgList &args)
static Address emitAddressAtOffset(CodeGenFunction &CGF, Address addr, const ABIArgInfo &info)
const CGFunctionInfo & arrangeUnprototypedMustTailThunk(const CXXMethodDecl *MD)
Arrange a thunk that takes 'this' as the first parameter followed by varargs.
static llvm::StoreInst * findDominatingStoreToReturnValue(CodeGenFunction &CGF)
Heuristically search for a dominating store to the return-value slot.
bool canHaveCoerceToType() const
CharUnits alignmentOfArrayElement(CharUnits elementSize) const
Given that this is the alignment of the first element of an array, return the minimum alignment of an...
bool getIndirectByVal() const
void Profile(llvm::FoldingSetNodeID &ID)
UnaryOperator - This represents the unary-expression's (except sizeof and alignof), the postinc/postdec operators from postfix-expression, and various extensions.
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
ASTContext & getContext() const
ImplicitParamDecl * getSelfDecl() const
static llvm::Value * CoerceIntOrPtrToIntOrPtr(llvm::Value *Val, llvm::Type *Ty, CodeGenFunction &CGF)
CoerceIntOrPtrToIntOrPtr - Convert a value Val to the specific Ty where both are either integers or p...
CallingConv
CallingConv - Specifies the calling convention that a function uses.
GlobalDecl - represents a global declaration.
static void BuildAggStore(CodeGenFunction &CGF, llvm::Value *Val, Address Dest, bool DestIsVolatile)
ExprObjectKind getObjectKind() const
getObjectKind - The object kind that this expression produces.
CanQualType getCanonicalTypeUnqualified() const
LValue getKnownLValue() const
The l-value was considered opaque, so the alignment was determined from a type.
RecordDecl * getDecl() const
unsigned getEffectiveCallingConvention() const
getEffectiveCallingConvention - Return the actual calling convention to use, which may depend on the ...
static void CreateCoercedStore(llvm::Value *Src, Address Dst, bool DstIsVolatile, CodeGenFunction &CGF)
CreateCoercedStore - Create a store to.
Enumerates target-specific builtins in their own namespaces within namespace clang.
Address CreateBitCast(Address Addr, llvm::Type *Ty, const llvm::Twine &Name="")
Assigning into this object requires the old value to be released and the new value to be retained...
bool ReturnTypeUsesFPRet(QualType ResultType)
Return true iff the given type uses 'fpret' when used as a return type.
CanProxy< U > castAs() const
static const Expr * maybeGetUnaryAddrOfOperand(const Expr *E)
NullPointerConstantKind isNullPointerConstant(ASTContext &Ctx, NullPointerConstantValueDependence NPC) const
isNullPointerConstant - C99 6.3.2.3p3 - Test if this reduces down to a Null pointer constant...
Encodes a location in the source.
QualType getReturnType() const
void EmitARCRelease(llvm::Value *value, ARCPreciseLifetime_t precise)
Release the given object.
bool isSRetAfterThis() const
A saved depth on the scope stack.
llvm::FunctionType * getVirtualFunctionType() const
RValue EmitCall(const CGFunctionInfo &CallInfo, const CGCallee &Callee, ReturnValueSlot ReturnValue, const CallArgList &Args, llvm::CallBase **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.
bool inheritingCtorHasParams(const InheritedConstructor &Inherited, CXXCtorType Type)
Determine if a C++ inheriting constructor should have parameters matching those of its inherited cons...
ParameterABI getABI() const
Return the ABI treatment of this parameter.
void DeactivateCleanupBlock(EHScopeStack::stable_iterator Cleanup, llvm::Instruction *DominatingIP)
DeactivateCleanupBlock - Deactivates the given cleanup block.
CallingConv getCC() const
const Decl * getDecl() const
QualType getObjCSelType() const
Retrieve the type that corresponds to the predefined Objective-C 'SEL' type.
virtual void computeInfo(CodeGen::CGFunctionInfo &FI) const =0
const CGFunctionInfo & arrangeObjCMethodDeclaration(const ObjCMethodDecl *MD)
Objective-C methods are C functions with some implicit parameters.
Represents a static or instance method of a struct/union/class.
void computeABIInfo(CodeGenModule &CGM, CGFunctionInfo &FI)
Compute the ABI information of a swiftcall function.
const ConstantArrayType * getAsConstantArrayType(QualType T) const
const_arg_iterator arg_end() const
llvm::StructType * getArgStruct() const
Get the struct type used to represent all the arguments in memory.
ObjCEntrypoints & getObjCEntrypoints() const
bool isInstanceMethod() const
CoerceAndExpand - Only valid for aggregate argument types.
void allocateArgumentMemory(CodeGenFunction &CGF)
Specifies that a value-dependent expression should be considered to never be a null pointer constant...
llvm::InlineAsm * retainAutoreleasedReturnValueMarker
A void(void) inline asm to use to mark that the return value of a call will be immediately retain...
bool isAnyPointerType() const
DestructionKind isDestructedType() const
Returns a nonzero value if objects of this type require non-trivial work to clean up after...
bool useObjCFP2RetForComplexLongDouble() const
Check whether _Complex long double should use the "fp2ret" flavor of Objective-C message passing on t...
llvm::LLVMContext & getLLVMContext()
All available information about a concrete callee.
static SmallVector< CanQualType, 16 > getArgTypesForDeclaration(ASTContext &ctx, const FunctionArgList &args)
InAlloca - Pass the argument directly using the LLVM inalloca attribute.
bool ReturnTypeUsesFP2Ret(QualType ResultType)
Return true iff the given type uses 'fp2ret' when used as a return type.
static void AddAttributesFromFunctionProtoType(ASTContext &Ctx, llvm::AttrBuilder &FuncAttrs, const FunctionProtoType *FPT)
bool hasFlexibleArrayMember() const
ExceptionSpecificationType getExceptionSpecType() const
Get the kind of exception specification on this function.
CXXCtorType
C++ constructor types.
CanProxy< U > getAs() const
Retrieve a canonical type pointer with a different static type, upcasting or downcasting as needed...
const CGFunctionInfo & arrangeBlockFunctionCall(const CallArgList &args, const FunctionType *type)
A block function is essentially a free function with an extra implicit argument.
std::pair< CharUnits, CharUnits > getTypeInfoInChars(const Type *T) const
llvm::Type * getPaddingType() const
void setExternallyDestructed(bool destructed=true)
static Address EnterStructPointerForCoercedAccess(Address SrcPtr, llvm::StructType *SrcSTy, uint64_t DstSize, CodeGenFunction &CGF)
EnterStructPointerForCoercedAccess - Given a struct pointer that we are accessing some number of byte...
FunctionArgList - Type for representing both the decl and type of parameters to a function...
bool getInAllocaSRet() const
Return true if this field of an inalloca struct should be returned to implement a struct return calli...
llvm::Value * getScalarVal() const
getScalarVal() - Return the Value* of this scalar value.
const TargetInfo & getTarget() const
llvm::CallBase * EmitCallOrInvoke(llvm::FunctionCallee 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...
CGFunctionInfo - Class to encapsulate the information about a function definition.
This class organizes the cross-function state that is used while generating LLVM code.
Dataflow Directional Tag Classes.
ExtInfo getExtInfo() const
static RValue getComplex(llvm::Value *V1, llvm::Value *V2)
CodeGenFunction::ComplexPairTy ComplexPairTy
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...
Qualifiers getMethodQualifiers() const
llvm::LoadInst * CreateAlignedLoad(llvm::Value *Addr, CharUnits Align, const llvm::Twine &Name="")
static void forConstantArrayExpansion(CodeGenFunction &CGF, ConstantArrayExpansion *CAE, Address BaseAddr, llvm::function_ref< void(Address)> Fn)
ArrayRef< ExtParameterInfo > getExtParameterInfos() const
Interesting information about a specific parameter that can't simply be reflected in parameter's type...
void EmitARCIntrinsicUse(ArrayRef< llvm::Value *> values)
Given a number of pointers, inform the optimizer that they're being intrinsically used up until this ...
void callCStructDestructor(LValue Dst)
llvm::LoadInst * CreateLoad(Address Addr, const llvm::Twine &Name="")
llvm::IntegerType * IntPtrTy
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined...
llvm::Function * getIntrinsic(unsigned IID, ArrayRef< llvm::Type *> Tys=None)
RValue getRValue(CodeGenFunction &CGF) const
static CGFunctionInfo * create(unsigned llvmCC, bool instanceMethod, bool chainCall, const FunctionType::ExtInfo &extInfo, ArrayRef< ExtParameterInfo > paramInfos, CanQualType resultType, ArrayRef< CanQualType > argTypes, RequiredArgs required)
llvm::StoreInst * CreateStore(llvm::Value *Val, Address Addr, bool IsVolatile=false)
virtual bool isNoProtoCallVariadic(const CodeGen::CallArgList &args, const FunctionNoProtoType *fnType) const
Determine whether a call to an unprototyped functions under the given calling convention should use t...
LValue MakeAddrLValue(Address Addr, QualType T, AlignmentSource Source=AlignmentSource::Type)
bool getCanBeFlattened() const
void EmitNoreturnRuntimeCallOrInvoke(llvm::FunctionCallee callee, ArrayRef< llvm::Value *> args)
Emits a call or invoke to the given noreturn runtime function.
ArrayRef< llvm::Type * > getCoerceAndExpandTypeSequence() const
static RequiredArgs forPrototypePlus(const FunctionProtoType *prototype, unsigned additional)
Compute the arguments required by the given formal prototype, given that there may be some additional...
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.
Iterator for iterating over Stmt * arrays that contain only T *.
static bool classof(const OMPClause *T)
bool isConstantSizeType() const
Return true if this is not a variable sized type, according to the rules of C99 6.7.5p3.
QualType getCanonicalTypeInternal() const
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
void EmitStoreOfComplex(ComplexPairTy V, LValue dest, bool isInit)
EmitStoreOfComplex - Store a complex number into the specified l-value.
static llvm::Value * tryRemoveRetainOfSelf(CodeGenFunction &CGF, llvm::Value *result)
If this is a +1 of the value of an immutable 'self', remove it.
CharUnits getIndirectAlign() const
Implements C++ ABI-specific code generation functions.
llvm::Type * getElementType() const
Return the type of the values stored in this address.
bool isMSVCXXPersonality() const
This class organizes the cross-module state that is used while lowering AST types to LLVM types...
llvm::StringRef getName() const
Return the IR name of the pointer value.
Expand - Only valid for aggregate argument types.
Base for LValueReferenceType and RValueReferenceType.
void getExpandedTypes(QualType Ty, SmallVectorImpl< llvm::Type *>::iterator &TI)
getExpandedTypes - Expand the type
static std::unique_ptr< TypeExpansion > getTypeExpansion(QualType Ty, const ASTContext &Context)
bool isParamDestroyedInCallee() const
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false)
EmitBlock - Emit the given block.
ABIArgInfo & getReturnInfo()
Represents a base class of a C++ class.
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types...
ASTContext & getContext() const
Pass it on the stack using its defined layout.
llvm::iterator_range< specific_attr_iterator< T > > specific_attrs() const
llvm::Type * GetFunctionTypeForVTable(GlobalDecl GD)
GetFunctionTypeForVTable - Get the LLVM function type for use in a vtable, given a CXXMethodDecl...
LangAS getAddressSpace() const
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
RValue getKnownRValue() const
Represents a C++ struct/union/class.
virtual const CXXRecordDecl * getThisArgumentTypeForMethod(const CXXMethodDecl *MD)
Get the type of the implicit "this" parameter used by a method.
llvm::Type * ConvertType(QualType T)
void EmitFunctionProlog(const CGFunctionInfo &FI, llvm::Function *Fn, const FunctionArgList &Args)
EmitFunctionProlog - Emit the target specific LLVM code to load the arguments for the given function...
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
virtual RecordArgABI getRecordArgABI(const CXXRecordDecl *RD) const =0
Returns how an argument of the given record type should be passed.
const GlobalDecl getCalleeDecl() const
LValue EmitLValue(const Expr *E)
EmitLValue - Emit code to compute a designator that specifies the location of the expression...
Address ReturnValue
ReturnValue - The temporary alloca to hold the return value.
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
This class is used for builtin types like 'int'.
bool shouldCopy() const
shouldCopy - True if we should do the 'copy' part of the copy-restore.
__DEVICE__ int min(int __a, int __b)
RValue EmitLoadOfLValue(LValue V, SourceLocation Loc)
EmitLoadOfLValue - Given an expression that represents a value lvalue, this method emits the address ...
Copying closure variant of a ctor.
Defines the clang::TargetInfo interface.
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
static CallingConv getCallingConventionForDecl(const Decl *D, bool IsWindows)
bool isCanonicalAsParam() const
Determines if this canonical type is furthermore canonical as a parameter.
CGCXXABI & getCXXABI() const
const CGFunctionInfo & arrangeMSCtorClosure(const CXXConstructorDecl *CD, CXXCtorType CT)
bool constructsVirtualBase() const
Returns true if the constructed base class is a virtual base class subobject of this declaration's cl...
llvm::Function * objc_retain
id objc_retain(id);
static void deactivateArgCleanupsBeforeCall(CodeGenFunction &CGF, const CallArgList &CallArgs)
void EmitAggregateCopy(LValue Dest, LValue Src, QualType EltTy, AggValueSlot::Overlap_t MayOverlap, bool isVolatile=false)
EmitAggregateCopy - Emit an aggregate copy.
const FunctionProtoType * getCalleeFunctionProtoType() const
QualType getIntPtrType() const
Return a type compatible with "intptr_t" (C99 7.18.1.4), as defined by the target.
static RValue get(llvm::Value *V)
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.
void computeSPIRKernelABIInfo(CodeGenModule &CGM, CGFunctionInfo &FI)
static RValue getAggregate(Address addr, bool isVolatile=false)
bool isUnresolvedExceptionSpec(ExceptionSpecificationType ESpecType)
ExtParameterInfo getExtParameterInfo(unsigned argIndex) const
LValue - This represents an lvalue references.
An abstract representation of regular/ObjC call/message targets.
SourceLocation getBeginLoc() const LLVM_READONLY
Information for lazily generating a cleanup.
virtual CGCallee getVirtualFunctionPointer(CodeGenFunction &CGF, GlobalDecl GD, Address This, llvm::Type *Ty, SourceLocation Loc)=0
Build a virtual function pointer in the ABI-specific way.
llvm::Type * getCoerceToType() const
CGCalleeInfo getAbstractInfo() const
Notes how many arguments were added to the beginning (Prefix) and ending (Suffix) of an arg list...
unsigned getTargetAddressSpace(QualType T) const
void AddDefaultFnAttrs(llvm::Function &F)
Adds attributes to F according to our CodeGenOptions and LangOptions, as though we had emitted it our...
llvm::CallInst * EmitNounwindRuntimeCall(llvm::FunctionCallee callee, const Twine &name="")
llvm::CallBase * EmitRuntimeCallOrInvoke(llvm::FunctionCallee callee, ArrayRef< llvm::Value *> args, const Twine &name="")
Emits a call or invoke instruction to the given runtime function.
CallArgList - Type for representing both the value and type of arguments in a call.
const CGFunctionInfo & arrangeCXXMethodCall(const CallArgList &args, const FunctionProtoType *type, RequiredArgs required, unsigned numPrefixArgs)
Arrange a call to a C++ method, passing the given arguments.
Represents the canonical version of C arrays with a specified constant size.
bool getIndirectRealign() const
Abstract information about a function or function prototype.
A class which abstracts out some details necessary for making a call.
Attr - This represents one attribute.
This parameter (which must have pointer type) is a Swift indirect result parameter.
static QualType getParamType(Sema &SemaRef, ArrayRef< ResultCandidate > Candidates, unsigned N)
Get the type of the Nth parameter from a given set of overload candidates.
ConstructorUsingShadowDecl * getShadowDecl() const
ArrayRef< ParmVarDecl * > parameters() const
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point...
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.