31 #include "llvm/ADT/StringExtras.h" 32 #include "llvm/Analysis/ValueTracking.h" 33 #include "llvm/IR/Attributes.h" 34 #include "llvm/IR/CallingConv.h" 35 #include "llvm/IR/DataLayout.h" 36 #include "llvm/IR/InlineAsm.h" 37 #include "llvm/IR/IntrinsicInst.h" 38 #include "llvm/IR/Intrinsics.h" 39 #include "llvm/Transforms/Utils/Local.h" 40 using namespace clang;
41 using namespace CodeGen;
52 case CC_Win64:
return llvm::CallingConv::Win64;
54 case CC_AAPCS:
return llvm::CallingConv::ARM_AAPCS;
55 case CC_AAPCS_VFP:
return llvm::CallingConv::ARM_AAPCS_VFP;
66 case CC_Swift:
return llvm::CallingConv::Swift;
117 unsigned totalArgs) {
119 assert(paramInfos.size() <= prefixArgs);
120 assert(proto->
getNumParams() + prefixArgs <= totalArgs);
122 paramInfos.reserve(totalArgs);
125 paramInfos.resize(prefixArgs);
129 paramInfos.push_back(ParamInfo);
131 if (ParamInfo.hasPassObjectSize())
132 paramInfos.emplace_back();
135 assert(paramInfos.size() <= totalArgs &&
136 "Did we forget to insert pass_object_size args?");
138 paramInfos.resize(totalArgs);
148 if (!FPT->hasExtParameterInfos()) {
149 assert(paramInfos.empty() &&
150 "We have paramInfos, but the prototype doesn't?");
151 prefix.append(FPT->param_type_begin(), FPT->param_type_end());
155 unsigned PrefixSize = prefix.size();
159 prefix.reserve(prefix.size() + FPT->getNumParams());
161 auto ExtInfos = FPT->getExtParameterInfos();
162 assert(ExtInfos.size() == FPT->getNumParams());
163 for (
unsigned I = 0, E = FPT->getNumParams(); I != E; ++I) {
164 prefix.push_back(FPT->getParamType(I));
165 if (ExtInfos[I].hasPassObjectSize())
187 FTP->getExtInfo(), paramInfos,
205 if (D->
hasAttr<FastCallAttr>())
211 if (D->
hasAttr<ThisCallAttr>())
214 if (D->
hasAttr<VectorCallAttr>())
220 if (PcsAttr *PCS = D->
getAttr<PcsAttr>())
223 if (D->
hasAttr<AArch64VectorPcsAttr>())
226 if (D->
hasAttr<IntelOclBiccAttr>())
235 if (D->
hasAttr<PreserveMostAttr>())
238 if (D->
hasAttr<PreserveAllAttr>())
260 *
this,
true, argTypes,
267 if (FD->
hasAttr<CUDAGlobalAttr>()) {
280 assert(!isa<CXXConstructorDecl>(MD) &&
"wrong method for constructors!");
281 assert(!isa<CXXDestructorDecl>(MD) &&
"wrong method for destructors!");
307 auto *MD = cast<CXXMethodDecl>(GD.
getDecl());
313 bool PassParams =
true;
315 if (
auto *CD = dyn_cast<CXXConstructorDecl>(MD)) {
318 if (
auto Inherited = CD->getInheritedConstructor())
330 if (!paramInfos.empty()) {
333 paramInfos.insert(paramInfos.begin() + 1, AddedArgs.
Prefix,
336 paramInfos.append(AddedArgs.
Suffix,
341 (PassParams && MD->isVariadic() ?
RequiredArgs(argTypes.size())
351 false, argTypes, extInfo,
352 paramInfos, required);
358 for (
auto &arg : args)
366 for (
auto &arg : args)
373 unsigned prefixArgs,
unsigned totalArgs) {
393 unsigned ExtraPrefixArgs,
394 unsigned ExtraSuffixArgs,
395 bool PassProtoArgs) {
398 for (
const auto &Arg : args)
402 unsigned TotalPrefixArgs = 1 + ExtraPrefixArgs;
407 FPT, TotalPrefixArgs + ExtraSuffixArgs)
421 if (PassProtoArgs && FPT->hasExtParameterInfos()) {
427 false, ArgTypes, Info,
428 ParamInfos, Required);
436 if (MD->isInstance())
441 assert(isa<FunctionType>(FTy));
448 noProto->getReturnType(),
false,
481 I->hasAttr<NoEscapeAttr>());
482 extParamInfos.push_back(extParamInfo);
489 if (
getContext().getLangOpts().ObjCAutoRefCount &&
490 MD->
hasAttr<NSReturnsRetainedAttr>())
498 false, argTys, einfo, extParamInfos, required);
517 if (isa<CXXConstructorDecl>(GD.
getDecl()) ||
518 isa<CXXDestructorDecl>(GD.
getDecl()))
531 assert(MD->
isVirtual() &&
"only methods have thunks");
549 ArgTys.push_back(*FTP->param_type_begin());
551 ArgTys.push_back(Context.
IntTy);
567 unsigned numExtraRequiredArgs,
569 assert(args.size() >= numExtraRequiredArgs);
579 if (proto->isVariadic())
582 if (proto->hasExtParameterInfos())
592 cast<FunctionNoProtoType>(fnType))) {
598 for (
const auto &arg : args)
615 chainCall ? 1 : 0, chainCall);
644 for (
const auto &Arg : args)
666 resultType,
false,
false,
678 unsigned numPrefixArgs) {
679 assert(numPrefixArgs + 1 <= args.size() &&
680 "Emitting a call with less args than the required prefix?");
692 false, argTypes, info, paramInfos, required);
704 assert(signature.
arg_size() <= args.size());
705 if (signature.
arg_size() == args.size())
710 if (!sigParamInfos.empty()) {
711 paramInfos.append(sigParamInfos.begin(), sigParamInfos.end());
712 paramInfos.resize(args.size());
744 assert(llvm::all_of(argTypes,
748 llvm::FoldingSetNodeID
ID;
750 required, resultType, argTypes);
752 void *insertPos =
nullptr;
753 CGFunctionInfo *FI = FunctionInfos.FindNodeOrInsertPos(ID, insertPos);
761 paramInfos, resultType, argTypes, required);
762 FunctionInfos.InsertNode(FI, insertPos);
764 bool inserted = FunctionsBeingProcessed.insert(FI).second;
766 assert(inserted &&
"Recursively being processed?");
769 if (CC == llvm::CallingConv::SPIR_KERNEL) {
786 for (
auto &I : FI->arguments())
787 if (I.info.canHaveCoerceToType() && I.info.getCoerceToType() ==
nullptr)
790 bool erased = FunctionsBeingProcessed.erase(FI); (void)erased;
791 assert(erased &&
"Not in set?");
804 assert(paramInfos.empty() || paramInfos.size() == argTypes.size());
809 operator new(totalSizeToAlloc<ArgInfo, ExtParameterInfo>(
810 argTypes.size() + 1, paramInfos.size()));
813 FI->CallingConvention = llvmCC;
814 FI->EffectiveCallingConvention = llvmCC;
815 FI->ASTCallingConvention = info.
getCC();
816 FI->InstanceMethod = instanceMethod;
817 FI->ChainCall = chainCall;
822 FI->Required = required;
825 FI->ArgStruct =
nullptr;
826 FI->ArgStructAlign = 0;
827 FI->NumArgs = argTypes.size();
828 FI->HasExtParameterInfos = !paramInfos.empty();
829 FI->getArgsBuffer()[0].
type = resultType;
830 for (
unsigned i = 0, e = argTypes.size(); i != e; ++i)
831 FI->getArgsBuffer()[i + 1].
type = argTypes[i];
832 for (
unsigned i = 0, e = paramInfos.size(); i != e; ++i)
833 FI->getExtParameterInfosBuffer()[i] = paramInfos[i];
843 struct TypeExpansion {
844 enum TypeExpansionKind {
856 const TypeExpansionKind
Kind;
858 TypeExpansion(TypeExpansionKind K) :
Kind(K) {}
859 virtual ~TypeExpansion() {}
862 struct ConstantArrayExpansion : TypeExpansion {
866 ConstantArrayExpansion(
QualType EltTy, uint64_t NumElts)
867 : TypeExpansion(TEK_ConstantArray), EltTy(EltTy), NumElts(NumElts) {}
868 static bool classof(
const TypeExpansion *TE) {
869 return TE->Kind == TEK_ConstantArray;
873 struct RecordExpansion : TypeExpansion {
880 : TypeExpansion(TEK_Record), Bases(std::move(Bases)),
881 Fields(std::move(Fields)) {}
882 static bool classof(
const TypeExpansion *TE) {
883 return TE->Kind == TEK_Record;
887 struct ComplexExpansion : TypeExpansion {
891 static bool classof(
const TypeExpansion *TE) {
896 struct NoExpansion : TypeExpansion {
897 NoExpansion() : TypeExpansion(TEK_None) {}
898 static bool classof(
const TypeExpansion *TE) {
899 return TE->Kind == TEK_None;
904 static std::unique_ptr<TypeExpansion>
907 return std::make_unique<ConstantArrayExpansion>(
908 AT->getElementType(), AT->getSize().getZExtValue());
915 "Cannot expand structure with flexible array.");
922 for (
const auto *FD : RD->
fields()) {
923 if (FD->isZeroLengthBitField(Context))
925 assert(!FD->isBitField() &&
926 "Cannot expand structure with bit-field members.");
928 if (UnionSize < FieldSize) {
929 UnionSize = FieldSize;
934 Fields.push_back(LargestFD);
936 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
937 assert(!CXXRD->isDynamicClass() &&
938 "cannot expand vtable pointers in dynamic classes");
940 Bases.push_back(&BS);
943 for (
const auto *FD : RD->
fields()) {
944 if (FD->isZeroLengthBitField(Context))
946 assert(!FD->isBitField() &&
947 "Cannot expand structure with bit-field members.");
948 Fields.push_back(FD);
951 return std::make_unique<RecordExpansion>(std::move(Bases),
955 return std::make_unique<ComplexExpansion>(CT->getElementType());
957 return std::make_unique<NoExpansion>();
962 if (
auto CAExp = dyn_cast<ConstantArrayExpansion>(Exp.get())) {
965 if (
auto RExp = dyn_cast<RecordExpansion>(Exp.get())) {
967 for (
auto BS : RExp->Bases)
969 for (
auto FD : RExp->Fields)
973 if (isa<ComplexExpansion>(Exp.get()))
975 assert(isa<NoExpansion>(Exp.get()));
983 if (
auto CAExp = dyn_cast<ConstantArrayExpansion>(Exp.get())) {
984 for (
int i = 0, n = CAExp->NumElts; i < n; i++) {
987 }
else if (
auto RExp = dyn_cast<RecordExpansion>(Exp.get())) {
988 for (
auto BS : RExp->Bases)
990 for (
auto FD : RExp->Fields)
992 }
else if (
auto CExp = dyn_cast<ComplexExpansion>(Exp.get())) {
997 assert(isa<NoExpansion>(Exp.get()));
1003 ConstantArrayExpansion *CAE,
1005 llvm::function_ref<
void(
Address)> Fn) {
1010 for (
int i = 0, n = CAE->NumElts; i < n; i++) {
1013 Fn(
Address(EltAddr, EltAlign));
1017 void CodeGenFunction::ExpandTypeFromArgs(
1020 "Unexpected non-simple lvalue during struct expansion.");
1023 if (
auto CAExp = dyn_cast<ConstantArrayExpansion>(Exp.get())) {
1026 LValue LV = MakeAddrLValue(EltAddr, CAExp->EltTy);
1027 ExpandTypeFromArgs(CAExp->EltTy, LV, AI);
1029 }
else if (
auto RExp = dyn_cast<RecordExpansion>(Exp.get())) {
1039 ExpandTypeFromArgs(BS->getType(), SubLV, AI);
1041 for (
auto FD : RExp->Fields) {
1043 LValue SubLV = EmitLValueForFieldInitialization(LV, FD);
1044 ExpandTypeFromArgs(FD->getType(), SubLV, AI);
1046 }
else if (isa<ComplexExpansion>(Exp.get())) {
1047 auto realValue = *AI++;
1048 auto imagValue = *AI++;
1049 EmitStoreOfComplex(
ComplexPairTy(realValue, imagValue), LV,
true);
1053 assert(isa<NoExpansion>(Exp.get()));
1057 EmitStoreOfScalar(*AI++, LV);
1061 void CodeGenFunction::ExpandTypeToArgs(
1065 if (
auto CAExp = dyn_cast<ConstantArrayExpansion>(Exp.get())) {
1069 *
this, CAExp, Addr, [&](
Address EltAddr) {
1073 ExpandTypeToArgs(CAExp->EltTy, EltArg, IRFuncTy, IRCallArgs,
1076 }
else if (
auto RExp = dyn_cast<RecordExpansion>(Exp.get())) {
1087 ExpandTypeToArgs(BS->getType(), BaseArg, IRFuncTy, IRCallArgs,
1091 LValue LV = MakeAddrLValue(This, Ty);
1092 for (
auto FD : RExp->Fields) {
1095 ExpandTypeToArgs(FD->getType(), FldArg, IRFuncTy, IRCallArgs,
1098 }
else if (isa<ComplexExpansion>(Exp.get())) {
1100 IRCallArgs[IRCallArgPos++] = CV.first;
1101 IRCallArgs[IRCallArgPos++] = CV.second;
1103 assert(isa<NoExpansion>(Exp.get()));
1105 assert(RV.isScalar() &&
1106 "Unexpected non-scalar rvalue during struct expansion.");
1110 if (IRCallArgPos < IRFuncTy->getNumParams() &&
1111 V->getType() != IRFuncTy->getParamType(IRCallArgPos))
1112 V = Builder.CreateBitCast(V, IRFuncTy->getParamType(IRCallArgPos));
1114 IRCallArgs[IRCallArgPos++] =
V;
1134 llvm::StructType *SrcSTy,
1137 if (SrcSTy->getNumElements() == 0)
return SrcPtr;
1139 llvm::Type *FirstElt = SrcSTy->getElementType(0);
1145 uint64_t FirstEltSize =
1147 if (FirstEltSize < DstSize &&
1156 if (llvm::StructType *SrcSTy = dyn_cast<llvm::StructType>(SrcTy))
1172 if (Val->getType() == Ty)
1175 if (isa<llvm::PointerType>(Val->getType())) {
1177 if (isa<llvm::PointerType>(Ty))
1185 if (isa<llvm::PointerType>(DestIntTy))
1188 if (Val->getType() != DestIntTy) {
1190 if (DL.isBigEndian()) {
1193 uint64_t SrcSize = DL.getTypeSizeInBits(Val->getType());
1194 uint64_t DstSize = DL.getTypeSizeInBits(DestIntTy);
1196 if (SrcSize > DstSize) {
1197 Val = CGF.
Builder.CreateLShr(Val, SrcSize - DstSize,
"coerce.highbits");
1198 Val = CGF.
Builder.CreateTrunc(Val, DestIntTy,
"coerce.val.ii");
1200 Val = CGF.
Builder.CreateZExt(Val, DestIntTy,
"coerce.val.ii");
1201 Val = CGF.
Builder.CreateShl(Val, DstSize - SrcSize,
"coerce.highbits");
1205 Val = CGF.
Builder.CreateIntCast(Val, DestIntTy,
false,
"coerce.val.ii");
1209 if (isa<llvm::PointerType>(Ty))
1210 Val = CGF.
Builder.CreateIntToPtr(Val, Ty,
"coerce.val.ip");
1233 if (llvm::StructType *SrcSTy = dyn_cast<llvm::StructType>(SrcTy)) {
1235 SrcTy = Src.
getType()->getElementType();
1242 if ((isa<llvm::IntegerType>(Ty) || isa<llvm::PointerType>(Ty)) &&
1243 (isa<llvm::IntegerType>(SrcTy) || isa<llvm::PointerType>(SrcTy))) {
1249 if (SrcSize >= DstSize) {
1266 llvm::ConstantInt::get(CGF.
IntPtrTy, SrcSize),
1276 Address Dest,
bool DestIsVolatile) {
1278 if (llvm::StructType *STy =
1279 dyn_cast<llvm::StructType>(Val->getType())) {
1280 for (
unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
1302 if (SrcTy == DstTy) {
1309 if (llvm::StructType *DstSTy = dyn_cast<llvm::StructType>(DstTy)) {
1311 DstTy = Dst.
getType()->getElementType();
1314 llvm::PointerType *SrcPtrTy = llvm::dyn_cast<llvm::PointerType>(SrcTy);
1315 llvm::PointerType *DstPtrTy = llvm::dyn_cast<llvm::PointerType>(DstTy);
1316 if (SrcPtrTy && DstPtrTy &&
1317 SrcPtrTy->getAddressSpace() != DstPtrTy->getAddressSpace()) {
1325 if ((isa<llvm::IntegerType>(SrcTy) || isa<llvm::PointerType>(SrcTy)) &&
1326 (isa<llvm::IntegerType>(DstTy) || isa<llvm::PointerType>(DstTy))) {
1335 if (SrcSize <= DstSize) {
1353 llvm::ConstantInt::get(CGF.
IntPtrTy, DstSize),
1373 class ClangToLLVMArgMapping {
1374 static const unsigned InvalidIndex = ~0U;
1375 unsigned InallocaArgNo;
1377 unsigned TotalIRArgs;
1381 unsigned PaddingArgIndex;
1384 unsigned FirstArgIndex;
1385 unsigned NumberOfArgs;
1388 : PaddingArgIndex(InvalidIndex), FirstArgIndex(InvalidIndex),
1396 bool OnlyRequiredArgs =
false)
1397 : InallocaArgNo(InvalidIndex), SRetArgNo(InvalidIndex), TotalIRArgs(0),
1399 construct(Context, FI, OnlyRequiredArgs);
1402 bool hasInallocaArg()
const {
return InallocaArgNo != InvalidIndex; }
1403 unsigned getInallocaArgNo()
const {
1404 assert(hasInallocaArg());
1405 return InallocaArgNo;
1408 bool hasSRetArg()
const {
return SRetArgNo != InvalidIndex; }
1409 unsigned getSRetArgNo()
const {
1410 assert(hasSRetArg());
1414 unsigned totalIRArgs()
const {
return TotalIRArgs; }
1416 bool hasPaddingArg(
unsigned ArgNo)
const {
1417 assert(ArgNo < ArgInfo.size());
1418 return ArgInfo[ArgNo].PaddingArgIndex != InvalidIndex;
1420 unsigned getPaddingArgNo(
unsigned ArgNo)
const {
1421 assert(hasPaddingArg(ArgNo));
1422 return ArgInfo[ArgNo].PaddingArgIndex;
1427 std::pair<unsigned, unsigned> getIRArgs(
unsigned ArgNo)
const {
1428 assert(ArgNo < ArgInfo.size());
1429 return std::make_pair(ArgInfo[ArgNo].FirstArgIndex,
1430 ArgInfo[ArgNo].NumberOfArgs);
1435 bool OnlyRequiredArgs);
1438 void ClangToLLVMArgMapping::construct(
const ASTContext &Context,
1440 bool OnlyRequiredArgs) {
1441 unsigned IRArgNo = 0;
1442 bool SwapThisWithSRet =
false;
1447 SRetArgNo = SwapThisWithSRet ? 1 : IRArgNo++;
1458 auto &IRArgs = ArgInfo[ArgNo];
1461 IRArgs.PaddingArgIndex = IRArgNo++;
1467 llvm::StructType *STy = dyn_cast<llvm::StructType>(AI.
getCoerceToType());
1469 IRArgs.NumberOfArgs = STy->getNumElements();
1471 IRArgs.NumberOfArgs = 1;
1476 IRArgs.NumberOfArgs = 1;
1481 IRArgs.NumberOfArgs = 0;
1491 if (IRArgs.NumberOfArgs > 0) {
1492 IRArgs.FirstArgIndex = IRArgNo;
1493 IRArgNo += IRArgs.NumberOfArgs;
1498 if (IRArgNo == 1 && SwapThisWithSRet)
1501 assert(ArgNo == ArgInfo.size());
1504 InallocaArgNo = IRArgNo++;
1506 TotalIRArgs = IRArgNo;
1514 return RI.
isIndirect() || (RI.isInAlloca() && RI.getInAllocaSRet());
1518 return ReturnTypeUsesSRet(FI) &&
1519 getTargetCodeGenInfo().doesReturnSlotInterfereWithArgs();
1524 switch (BT->getKind()) {
1527 case BuiltinType::Float:
1529 case BuiltinType::Double:
1531 case BuiltinType::LongDouble:
1542 if (BT->getKind() == BuiltinType::LongDouble)
1555 llvm::FunctionType *
1558 bool Inserted = FunctionsBeingProcessed.insert(&FI).second;
1560 assert(Inserted &&
"Recursively being processed?");
1566 llvm_unreachable(
"Invalid ABI kind for return argument");
1579 resultType = llvm::PointerType::get(ty, addressSpace);
1595 ClangToLLVMArgMapping IRFunctionArgs(
getContext(), FI,
true);
1599 if (IRFunctionArgs.hasSRetArg()) {
1603 ArgTypes[IRFunctionArgs.getSRetArgNo()] =
1604 llvm::PointerType::get(Ty, AddressSpace);
1608 if (IRFunctionArgs.hasInallocaArg()) {
1611 ArgTypes[IRFunctionArgs.getInallocaArgNo()] = ArgStruct->getPointerTo();
1618 for (; it != ie; ++it, ++ArgNo) {
1622 if (IRFunctionArgs.hasPaddingArg(ArgNo))
1623 ArgTypes[IRFunctionArgs.getPaddingArgNo(ArgNo)] =
1626 unsigned FirstIRArg, NumIRArgs;
1627 std::tie(FirstIRArg, NumIRArgs) = IRFunctionArgs.getIRArgs(ArgNo);
1632 assert(NumIRArgs == 0);
1636 assert(NumIRArgs == 1);
1639 ArgTypes[FirstIRArg] = LTy->getPointerTo(
1640 CGM.getDataLayout().getAllocaAddrSpace());
1649 llvm::StructType *st = dyn_cast<llvm::StructType>(argType);
1651 assert(NumIRArgs == st->getNumElements());
1652 for (
unsigned i = 0, e = st->getNumElements(); i != e; ++i)
1653 ArgTypes[FirstIRArg + i] = st->getElementType(i);
1655 assert(NumIRArgs == 1);
1656 ArgTypes[FirstIRArg] = argType;
1662 auto ArgTypesIter = ArgTypes.begin() + FirstIRArg;
1664 *ArgTypesIter++ = EltTy;
1666 assert(ArgTypesIter == ArgTypes.begin() + FirstIRArg + NumIRArgs);
1671 auto ArgTypesIter = ArgTypes.begin() + FirstIRArg;
1673 assert(ArgTypesIter == ArgTypes.begin() + FirstIRArg + NumIRArgs);
1678 bool Erased = FunctionsBeingProcessed.erase(&FI); (void)Erased;
1679 assert(Erased &&
"Not in set?");
1681 return llvm::FunctionType::get(resultType, ArgTypes, FI.
isVariadic());
1695 llvm::AttrBuilder &FuncAttrs,
1702 FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
1705 void CodeGenModule::ConstructDefaultFnAttrList(StringRef Name,
bool HasOptnone,
1706 bool AttrOnCallSite,
1707 llvm::AttrBuilder &FuncAttrs) {
1710 if (CodeGenOpts.OptimizeSize)
1711 FuncAttrs.addAttribute(llvm::Attribute::OptimizeForSize);
1712 if (CodeGenOpts.OptimizeSize == 2)
1713 FuncAttrs.addAttribute(llvm::Attribute::MinSize);
1716 if (CodeGenOpts.DisableRedZone)
1717 FuncAttrs.addAttribute(llvm::Attribute::NoRedZone);
1718 if (CodeGenOpts.IndirectTlsSegRefs)
1719 FuncAttrs.addAttribute(
"indirect-tls-seg-refs");
1720 if (CodeGenOpts.NoImplicitFloat)
1721 FuncAttrs.addAttribute(llvm::Attribute::NoImplicitFloat);
1723 if (AttrOnCallSite) {
1725 if (!CodeGenOpts.SimplifyLibCalls ||
1726 CodeGenOpts.isNoBuiltinFunc(Name.data()))
1727 FuncAttrs.addAttribute(llvm::Attribute::NoBuiltin);
1728 if (!CodeGenOpts.TrapFuncName.empty())
1729 FuncAttrs.addAttribute(
"trap-func-name", CodeGenOpts.TrapFuncName);
1732 switch (CodeGenOpts.getFramePointer()) {
1737 FpKind =
"non-leaf";
1743 FuncAttrs.addAttribute(
"frame-pointer", FpKind);
1745 FuncAttrs.addAttribute(
"less-precise-fpmad",
1746 llvm::toStringRef(CodeGenOpts.LessPreciseFPMAD));
1748 if (CodeGenOpts.NullPointerIsValid)
1749 FuncAttrs.addAttribute(
"null-pointer-is-valid",
"true");
1750 if (CodeGenOpts.FPDenormalMode != llvm::DenormalMode::Invalid)
1751 FuncAttrs.addAttribute(
"denormal-fp-math",
1752 llvm::denormalModeName(CodeGenOpts.FPDenormalMode));
1754 FuncAttrs.addAttribute(
"no-trapping-math",
1755 llvm::toStringRef(CodeGenOpts.NoTrappingMath));
1759 if (!CodeGenOpts.StrictFloatCastOverflow)
1760 FuncAttrs.addAttribute(
"strict-float-cast-overflow",
"false");
1764 FuncAttrs.addAttribute(
"no-infs-fp-math",
1765 llvm::toStringRef(CodeGenOpts.NoInfsFPMath));
1766 FuncAttrs.addAttribute(
"no-nans-fp-math",
1767 llvm::toStringRef(CodeGenOpts.NoNaNsFPMath));
1768 FuncAttrs.addAttribute(
"unsafe-fp-math",
1769 llvm::toStringRef(CodeGenOpts.UnsafeFPMath));
1770 FuncAttrs.addAttribute(
"use-soft-float",
1771 llvm::toStringRef(CodeGenOpts.SoftFloat));
1772 FuncAttrs.addAttribute(
"stack-protector-buffer-size",
1773 llvm::utostr(CodeGenOpts.SSPBufferSize));
1774 FuncAttrs.addAttribute(
"no-signed-zeros-fp-math",
1775 llvm::toStringRef(CodeGenOpts.NoSignedZeros));
1776 FuncAttrs.addAttribute(
1777 "correctly-rounded-divide-sqrt-fp-math",
1778 llvm::toStringRef(CodeGenOpts.CorrectlyRoundedDivSqrt));
1780 if (getLangOpts().
OpenCL)
1781 FuncAttrs.addAttribute(
"denorms-are-zero",
1782 llvm::toStringRef(CodeGenOpts.FlushDenorm));
1785 const std::vector<std::string> &Recips = CodeGenOpts.Reciprocals;
1786 if (!Recips.empty())
1787 FuncAttrs.addAttribute(
"reciprocal-estimates",
1788 llvm::join(Recips,
","));
1790 if (!CodeGenOpts.PreferVectorWidth.empty() &&
1791 CodeGenOpts.PreferVectorWidth !=
"none")
1792 FuncAttrs.addAttribute(
"prefer-vector-width",
1793 CodeGenOpts.PreferVectorWidth);
1795 if (CodeGenOpts.StackRealignment)
1796 FuncAttrs.addAttribute(
"stackrealign");
1797 if (CodeGenOpts.Backchain)
1798 FuncAttrs.addAttribute(
"backchain");
1800 if (CodeGenOpts.SpeculativeLoadHardening)
1801 FuncAttrs.addAttribute(llvm::Attribute::SpeculativeLoadHardening);
1804 if (getLangOpts().assumeFunctionsAreConvergent()) {
1810 FuncAttrs.addAttribute(llvm::Attribute::Convergent);
1813 if (getLangOpts().
CUDA && getLangOpts().CUDAIsDevice) {
1815 FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
1818 if (CodeGenOpts.FlushDenorm)
1819 FuncAttrs.addAttribute(
"nvptx-f32ftz",
"true");
1822 for (StringRef
Attr : CodeGenOpts.DefaultFunctionAttrs) {
1823 StringRef Var,
Value;
1824 std::tie(Var, Value) = Attr.split(
'=');
1825 FuncAttrs.addAttribute(Var, Value);
1830 llvm::AttrBuilder FuncAttrs;
1831 ConstructDefaultFnAttrList(F.getName(), F.hasOptNone(),
1833 F.addAttributes(llvm::AttributeList::FunctionIndex, FuncAttrs);
1838 llvm::AttributeList &AttrList,
unsigned &
CallingConv,
bool AttrOnCallSite) {
1839 llvm::AttrBuilder FuncAttrs;
1840 llvm::AttrBuilder RetAttrs;
1844 FuncAttrs.addAttribute(llvm::Attribute::NoReturn);
1853 bool HasOptnone =
false;
1856 if (TargetDecl->hasAttr<ReturnsTwiceAttr>())
1857 FuncAttrs.addAttribute(llvm::Attribute::ReturnsTwice);
1858 if (TargetDecl->hasAttr<NoThrowAttr>())
1859 FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
1860 if (TargetDecl->hasAttr<NoReturnAttr>())
1861 FuncAttrs.addAttribute(llvm::Attribute::NoReturn);
1862 if (TargetDecl->hasAttr<ColdAttr>())
1863 FuncAttrs.addAttribute(llvm::Attribute::Cold);
1864 if (TargetDecl->hasAttr<NoDuplicateAttr>())
1865 FuncAttrs.addAttribute(llvm::Attribute::NoDuplicate);
1866 if (TargetDecl->hasAttr<ConvergentAttr>())
1867 FuncAttrs.addAttribute(llvm::Attribute::Convergent);
1869 if (
const FunctionDecl *Fn = dyn_cast<FunctionDecl>(TargetDecl)) {
1873 const bool IsVirtualCall = MD && MD->
isVirtual();
1876 if (!(AttrOnCallSite && IsVirtualCall)) {
1877 if (Fn->isNoReturn())
1878 FuncAttrs.addAttribute(llvm::Attribute::NoReturn);
1880 const auto *NBA = Fn->getAttr<NoBuiltinAttr>();
1881 bool HasWildcard = NBA && llvm::is_contained(NBA->builtinNames(),
"*");
1882 if (getLangOpts().NoBuiltin || HasWildcard)
1883 FuncAttrs.addAttribute(
"no-builtins");
1885 auto AddNoBuiltinAttr = [&FuncAttrs](StringRef BuiltinName) {
1887 AttributeName +=
"no-builtin-";
1888 AttributeName += BuiltinName;
1889 FuncAttrs.addAttribute(AttributeName);
1891 llvm::for_each(getLangOpts().NoBuiltinFuncs, AddNoBuiltinAttr);
1893 llvm::for_each(NBA->builtinNames(), AddNoBuiltinAttr);
1899 if (TargetDecl->hasAttr<ConstAttr>()) {
1900 FuncAttrs.addAttribute(llvm::Attribute::ReadNone);
1901 FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
1902 }
else if (TargetDecl->hasAttr<PureAttr>()) {
1903 FuncAttrs.addAttribute(llvm::Attribute::ReadOnly);
1904 FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
1905 }
else if (TargetDecl->hasAttr<NoAliasAttr>()) {
1906 FuncAttrs.addAttribute(llvm::Attribute::ArgMemOnly);
1907 FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
1909 if (TargetDecl->hasAttr<RestrictAttr>())
1910 RetAttrs.addAttribute(llvm::Attribute::NoAlias);
1911 if (TargetDecl->hasAttr<ReturnsNonNullAttr>() &&
1912 !CodeGenOpts.NullPointerIsValid)
1913 RetAttrs.addAttribute(llvm::Attribute::NonNull);
1914 if (TargetDecl->hasAttr<AnyX86NoCallerSavedRegistersAttr>())
1915 FuncAttrs.addAttribute(
"no_caller_saved_registers");
1916 if (TargetDecl->hasAttr<AnyX86NoCfCheckAttr>())
1917 FuncAttrs.addAttribute(llvm::Attribute::NoCfCheck);
1919 HasOptnone = TargetDecl->hasAttr<OptimizeNoneAttr>();
1920 if (
auto *AllocSize = TargetDecl->getAttr<AllocSizeAttr>()) {
1922 if (AllocSize->getNumElemsParam().isValid())
1923 NumElemsParam = AllocSize->getNumElemsParam().getLLVMIndex();
1924 FuncAttrs.addAllocSizeAttr(AllocSize->getElemSizeParam().getLLVMIndex(),
1929 ConstructDefaultFnAttrList(Name, HasOptnone, AttrOnCallSite, FuncAttrs);
1935 if (TargetDecl->hasAttr<NoSpeculativeLoadHardeningAttr>())
1936 FuncAttrs.removeAttribute(llvm::Attribute::SpeculativeLoadHardening);
1937 if (TargetDecl->hasAttr<SpeculativeLoadHardeningAttr>())
1938 FuncAttrs.addAttribute(llvm::Attribute::SpeculativeLoadHardening);
1941 if (CodeGenOpts.EnableSegmentedStacks &&
1942 !(TargetDecl && TargetDecl->hasAttr<NoSplitStackAttr>()))
1943 FuncAttrs.addAttribute(
"split-stack");
1947 if (TargetDecl && CodeGenOpts.NoPLT) {
1948 if (
auto *Fn = dyn_cast<FunctionDecl>(TargetDecl)) {
1949 if (!Fn->isDefined() && !AttrOnCallSite) {
1950 FuncAttrs.addAttribute(llvm::Attribute::NonLazyBind);
1955 if (TargetDecl && TargetDecl->hasAttr<OpenCLKernelAttr>()) {
1956 if (getLangOpts().OpenCLVersion <= 120) {
1958 FuncAttrs.addAttribute(
"uniform-work-group-size",
"true");
1965 FuncAttrs.addAttribute(
"uniform-work-group-size",
1966 llvm::toStringRef(CodeGenOpts.UniformWGSize));
1970 if (!AttrOnCallSite) {
1971 bool DisableTailCalls =
false;
1973 if (CodeGenOpts.DisableTailCalls)
1974 DisableTailCalls =
true;
1975 else if (TargetDecl) {
1976 if (TargetDecl->hasAttr<DisableTailCallsAttr>() ||
1977 TargetDecl->hasAttr<AnyX86InterruptAttr>())
1978 DisableTailCalls =
true;
1979 else if (CodeGenOpts.NoEscapingBlockTailCalls) {
1980 if (
const auto *BD = dyn_cast<BlockDecl>(TargetDecl))
1981 if (!BD->doesNotEscape())
1982 DisableTailCalls =
true;
1986 FuncAttrs.addAttribute(
"disable-tail-calls",
1987 llvm::toStringRef(DisableTailCalls));
1988 GetCPUAndFeaturesAttributes(CalleeInfo.
getCalleeDecl(), FuncAttrs);
1991 ClangToLLVMArgMapping IRFunctionArgs(
getContext(), FI);
1998 RetAttrs.addAttribute(llvm::Attribute::SExt);
2000 RetAttrs.addAttribute(llvm::Attribute::ZExt);
2004 RetAttrs.addAttribute(llvm::Attribute::InReg);
2012 FuncAttrs.removeAttribute(llvm::Attribute::ReadOnly)
2013 .removeAttribute(llvm::Attribute::ReadNone);
2021 llvm_unreachable(
"Invalid ABI kind for return argument");
2027 RetAttrs.addDereferenceableAttr(
getContext().getTypeSizeInChars(PTy)
2029 else if (
getContext().getTargetAddressSpace(PTy) == 0 &&
2030 !CodeGenOpts.NullPointerIsValid)
2031 RetAttrs.addAttribute(llvm::Attribute::NonNull);
2034 bool hasUsedSRet =
false;
2038 if (IRFunctionArgs.hasSRetArg()) {
2039 llvm::AttrBuilder SRETAttrs;
2040 SRETAttrs.addAttribute(llvm::Attribute::StructRet);
2043 SRETAttrs.addAttribute(llvm::Attribute::InReg);
2044 ArgAttrs[IRFunctionArgs.getSRetArgNo()] =
2049 if (IRFunctionArgs.hasInallocaArg()) {
2050 llvm::AttrBuilder Attrs;
2051 Attrs.addAttribute(llvm::Attribute::InAlloca);
2052 ArgAttrs[IRFunctionArgs.getInallocaArgNo()] =
2059 I != E; ++I, ++ArgNo) {
2062 llvm::AttrBuilder Attrs;
2065 if (IRFunctionArgs.hasPaddingArg(ArgNo)) {
2067 ArgAttrs[IRFunctionArgs.getPaddingArgNo(ArgNo)] =
2068 llvm::AttributeSet::get(
2070 llvm::AttrBuilder().addAttribute(llvm::Attribute::InReg));
2080 Attrs.addAttribute(llvm::Attribute::SExt);
2082 Attrs.addAttribute(llvm::Attribute::ZExt);
2086 Attrs.addAttribute(llvm::Attribute::Nest);
2088 Attrs.addAttribute(llvm::Attribute::InReg);
2093 Attrs.addAttribute(llvm::Attribute::InReg);
2118 FuncAttrs.removeAttribute(llvm::Attribute::ReadOnly)
2119 .removeAttribute(llvm::Attribute::ReadNone);
2129 FuncAttrs.removeAttribute(llvm::Attribute::ReadOnly)
2130 .removeAttribute(llvm::Attribute::ReadNone);
2137 Attrs.addDereferenceableAttr(
getContext().getTypeSizeInChars(PTy)
2139 else if (
getContext().getTargetAddressSpace(PTy) == 0 &&
2140 !CodeGenOpts.NullPointerIsValid)
2141 Attrs.addAttribute(llvm::Attribute::NonNull);
2152 Attrs.addAttribute(llvm::Attribute::StructRet);
2157 Attrs.addAttribute(llvm::Attribute::NoAlias);
2161 if (!PTy->isIncompleteType() && PTy->isConstantSizeType()) {
2163 Attrs.addDereferenceableAttr(info.first.getQuantity());
2164 Attrs.addAttribute(llvm::Attribute::getWithAlignment(
2171 Attrs.addAttribute(llvm::Attribute::SwiftError);
2175 Attrs.addAttribute(llvm::Attribute::SwiftSelf);
2180 Attrs.addAttribute(llvm::Attribute::NoCapture);
2182 if (Attrs.hasAttributes()) {
2183 unsigned FirstIRArg, NumIRArgs;
2184 std::tie(FirstIRArg, NumIRArgs) = IRFunctionArgs.getIRArgs(ArgNo);
2185 for (
unsigned i = 0; i < NumIRArgs; i++)
2186 ArgAttrs[FirstIRArg + i] =
2192 AttrList = llvm::AttributeList::get(
2206 if (value->getType() == varType)
return value;
2208 assert((varType->isIntegerTy() || varType->isFloatingPointTy())
2209 &&
"unexpected promotion type");
2211 if (isa<llvm::IntegerType>(varType))
2212 return CGF.
Builder.CreateTrunc(value, varType,
"arg.unpromote");
2214 return CGF.
Builder.CreateFPCast(value, varType,
"arg.unpromote");
2220 QualType ArgType,
unsigned ArgNo) {
2232 if (
auto ParmNNAttr = PVD->
getAttr<NonNullAttr>())
2239 if (NNAttr->isNonNull(ArgNo))
2249 CopyBackSwiftError(
Address temp,
Address arg) : Temp(temp), Arg(arg) {}
2260 if (CurCodeDecl && CurCodeDecl->hasAttr<NakedAttr>())
2268 if (
const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(CurCodeDecl)) {
2269 if (FD->hasImplicitReturnZero()) {
2270 QualType RetTy = FD->getReturnType().getUnqualifiedType();
2271 llvm::Type* LLVMTy = CGM.getTypes().ConvertType(RetTy);
2272 llvm::Constant*
Zero = llvm::Constant::getNullValue(LLVMTy);
2280 ClangToLLVMArgMapping IRFunctionArgs(CGM.getContext(), FI);
2283 FnArgs.reserve(IRFunctionArgs.totalIRArgs());
2284 for (
auto &Arg : Fn->args()) {
2285 FnArgs.push_back(&Arg);
2287 assert(FnArgs.size() == IRFunctionArgs.totalIRArgs());
2292 if (IRFunctionArgs.hasInallocaArg()) {
2293 ArgStruct =
Address(FnArgs[IRFunctionArgs.getInallocaArgNo()],
2296 assert(ArgStruct.getType() == FI.
getArgStruct()->getPointerTo());
2300 if (IRFunctionArgs.hasSRetArg()) {
2301 auto AI = cast<llvm::Argument>(FnArgs[IRFunctionArgs.getSRetArgNo()]);
2302 AI->setName(
"agg.result");
2303 AI->addAttr(llvm::Attribute::NoAlias);
2310 ArgVals.reserve(Args.size());
2316 assert(FI.
arg_size() == Args.size() &&
2317 "Mismatch between function signature & arguments.");
2320 for (FunctionArgList::const_iterator i = Args.begin(), e = Args.end();
2321 i != e; ++i, ++info_it, ++ArgNo) {
2326 isa<ParmVarDecl>(Arg) && cast<ParmVarDecl>(Arg)->isKNRPromoted();
2331 assert(hasScalarEvaluationKind(Ty) ==
2332 hasScalarEvaluationKind(Arg->
getType()));
2334 unsigned FirstIRArg, NumIRArgs;
2335 std::tie(FirstIRArg, NumIRArgs) = IRFunctionArgs.getIRArgs(ArgNo);
2339 assert(NumIRArgs == 0);
2342 Builder.CreateStructGEP(ArgStruct, FieldIndex, Arg->
getName());
2343 ArgVals.push_back(ParamValue::forIndirect(V));
2348 assert(NumIRArgs == 1);
2351 if (!hasScalarEvaluationKind(Ty)) {
2356 Address AlignedTemp = CreateMemTemp(Ty,
"coerce");
2364 auto SizeVal = llvm::ConstantInt::get(IntPtrTy, Size.
getQuantity());
2365 Address Dst = Builder.CreateBitCast(AlignedTemp, Int8PtrTy);
2366 Address Src = Builder.CreateBitCast(ParamAddr, Int8PtrTy);
2367 Builder.CreateMemCpy(Dst, Src, SizeVal,
false);
2370 ArgVals.push_back(ParamValue::forIndirect(V));
2374 EmitLoadOfScalar(ParamAddr,
false, Ty, Arg->
getBeginLoc());
2378 ArgVals.push_back(ParamValue::forDirect(V));
2390 assert(NumIRArgs == 1);
2392 auto AI = cast<llvm::Argument>(
V);
2394 if (
const ParmVarDecl *PVD = dyn_cast<ParmVarDecl>(Arg)) {
2396 PVD->getFunctionScopeIndex()) &&
2397 !CGM.getCodeGenOpts().NullPointerIsValid)
2398 AI->addAttr(llvm::Attribute::NonNull);
2400 QualType OTy = PVD->getOriginalType();
2401 if (
const auto *ArrTy =
2408 QualType ETy = ArrTy->getElementType();
2409 uint64_t ArrSize = ArrTy->getSize().getZExtValue();
2412 llvm::AttrBuilder Attrs;
2413 Attrs.addDereferenceableAttr(
2414 getContext().getTypeSizeInChars(ETy).getQuantity()*ArrSize);
2415 AI->addAttrs(Attrs);
2416 }
else if (
getContext().getTargetAddressSpace(ETy) == 0 &&
2417 !CGM.getCodeGenOpts().NullPointerIsValid) {
2418 AI->addAttr(llvm::Attribute::NonNull);
2421 }
else if (
const auto *ArrTy =
2428 !CGM.getCodeGenOpts().NullPointerIsValid)
2429 AI->addAttr(llvm::Attribute::NonNull);
2432 const auto *AVAttr = PVD->getAttr<AlignValueAttr>();
2434 if (
const auto *TOTy = dyn_cast<TypedefType>(OTy))
2435 AVAttr = TOTy->getDecl()->getAttr<AlignValueAttr>();
2436 if (AVAttr && !SanOpts.has(SanitizerKind::Alignment)) {
2441 EmitScalarExpr(AVAttr->getAlignment());
2442 llvm::ConstantInt *AlignmentCI =
2443 cast<llvm::ConstantInt>(AlignmentValue);
2444 unsigned Alignment =
std::min((
unsigned)AlignmentCI->getZExtValue(),
2445 +llvm::Value::MaximumAlignment);
2446 AI->addAttrs(llvm::AttrBuilder().addAlignmentAttr(Alignment));
2451 AI->addAttr(llvm::Attribute::NoAlias);
2460 CreateMemTemp(pointeeTy, getPointerAlign(),
"swifterror.temp");
2462 llvm::Value *incomingErrorValue = Builder.CreateLoad(arg);
2463 Builder.CreateStore(incomingErrorValue, temp);
2464 V = temp.getPointer();
2469 EHStack.pushCleanup<CopyBackSwiftError>(
NormalCleanup, temp, arg);
2484 if (V->getType() != LTy)
2485 V = Builder.CreateBitCast(V, LTy);
2487 ArgVals.push_back(ParamValue::forDirect(V));
2499 llvm::StructType *STy = dyn_cast<llvm::StructType>(ArgI.
getCoerceToType());
2501 STy->getNumElements() > 1) {
2502 uint64_t SrcSize = CGM.getDataLayout().getTypeAllocSize(STy);
2504 uint64_t DstSize = CGM.getDataLayout().getTypeAllocSize(DstTy);
2507 if (SrcSize <= DstSize) {
2508 AddrToStoreInto = Builder.CreateElementBitCast(Ptr, STy);
2511 CreateTempAlloca(STy, Alloca.
getAlignment(),
"coerce");
2514 assert(STy->getNumElements() == NumIRArgs);
2515 for (
unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
2516 auto AI = FnArgs[FirstIRArg + i];
2517 AI->setName(Arg->
getName() +
".coerce" + Twine(i));
2518 Address EltPtr = Builder.CreateStructGEP(AddrToStoreInto, i);
2519 Builder.CreateStore(AI, EltPtr);
2522 if (SrcSize > DstSize) {
2523 Builder.CreateMemCpy(Ptr, AddrToStoreInto, DstSize);
2528 assert(NumIRArgs == 1);
2529 auto AI = FnArgs[FirstIRArg];
2530 AI->setName(Arg->
getName() +
".coerce");
2537 EmitLoadOfScalar(Alloca,
false, Ty, Arg->
getBeginLoc());
2540 ArgVals.push_back(ParamValue::forDirect(V));
2542 ArgVals.push_back(ParamValue::forIndirect(Alloca));
2550 ArgVals.push_back(ParamValue::forIndirect(alloca));
2553 alloca = Builder.CreateElementBitCast(alloca, coercionType);
2555 unsigned argIndex = FirstIRArg;
2556 for (
unsigned i = 0, e = coercionType->getNumElements(); i != e; ++i) {
2557 llvm::Type *eltType = coercionType->getElementType(i);
2561 auto eltAddr = Builder.CreateStructGEP(alloca, i);
2562 auto elt = FnArgs[argIndex++];
2563 Builder.CreateStore(elt, eltAddr);
2565 assert(argIndex == FirstIRArg + NumIRArgs);
2574 LValue LV = MakeAddrLValue(Alloca, Ty);
2575 ArgVals.push_back(ParamValue::forIndirect(Alloca));
2577 auto FnArgIter = FnArgs.begin() + FirstIRArg;
2578 ExpandTypeFromArgs(Ty, LV, FnArgIter);
2579 assert(FnArgIter == FnArgs.begin() + FirstIRArg + NumIRArgs);
2580 for (
unsigned i = 0, e = NumIRArgs; i != e; ++i) {
2581 auto AI = FnArgs[FirstIRArg + i];
2582 AI->setName(Arg->
getName() +
"." + Twine(i));
2588 assert(NumIRArgs == 0);
2590 if (!hasScalarEvaluationKind(Ty)) {
2591 ArgVals.push_back(ParamValue::forIndirect(CreateMemTemp(Ty)));
2594 ArgVals.push_back(ParamValue::forDirect(U));
2601 for (
int I = Args.size() - 1; I >= 0; --I)
2602 EmitParmDecl(*Args[I], ArgVals[I], I + 1);
2604 for (
unsigned I = 0, E = Args.size(); I != E; ++I)
2605 EmitParmDecl(*Args[I], ArgVals[I], I + 1);
2610 while (insn->use_empty()) {
2611 llvm::BitCastInst *bitcast = dyn_cast<llvm::BitCastInst>(insn);
2612 if (!bitcast)
return;
2615 insn = cast<llvm::Instruction>(bitcast->getOperand(0));
2616 bitcast->eraseFromParent();
2624 llvm::BasicBlock *BB = CGF.
Builder.GetInsertBlock();
2625 if (BB->empty())
return nullptr;
2626 if (&BB->back() != result)
return nullptr;
2631 llvm::Instruction *generator = cast<llvm::Instruction>(result);
2637 while (llvm::BitCastInst *bitcast = dyn_cast<llvm::BitCastInst>(generator)) {
2640 generator = cast<llvm::Instruction>(bitcast->getOperand(0));
2643 if (generator->getNextNode() != bitcast)
2646 InstsToKill.push_back(bitcast);
2653 llvm::CallInst *call = dyn_cast<llvm::CallInst>(generator);
2654 if (!call)
return nullptr;
2656 bool doRetainAutorelease;
2659 doRetainAutorelease =
true;
2662 doRetainAutorelease =
false;
2670 llvm::Instruction *prev = call->getPrevNode();
2672 if (isa<llvm::BitCastInst>(prev)) {
2673 prev = prev->getPrevNode();
2676 assert(isa<llvm::CallInst>(prev));
2677 assert(cast<llvm::CallInst>(prev)->getCalledValue() ==
2679 InstsToKill.push_back(prev);
2685 result = call->getArgOperand(0);
2686 InstsToKill.push_back(call);
2690 while (llvm::BitCastInst *bitcast = dyn_cast<llvm::BitCastInst>(result)) {
2691 if (!bitcast->hasOneUse())
break;
2692 InstsToKill.push_back(bitcast);
2693 result = bitcast->getOperand(0);
2697 for (
auto *I : InstsToKill)
2698 I->eraseFromParent();
2701 if (doRetainAutorelease)
2713 dyn_cast_or_null<ObjCMethodDecl>(CGF.
CurCodeDecl);
2714 if (!method)
return nullptr;
2716 if (!self->getType().isConstQualified())
return nullptr;
2719 llvm::CallInst *retainCall =
2720 dyn_cast<llvm::CallInst>(result->stripPointerCasts());
2726 llvm::Value *retainedValue = retainCall->getArgOperand(0);
2727 llvm::LoadInst *load =
2728 dyn_cast<llvm::LoadInst>(retainedValue->stripPointerCasts());
2729 if (!load || load->isAtomic() || load->isVolatile() ||
2738 assert(retainCall->use_empty());
2739 retainCall->eraseFromParent();
2770 auto GetStoreIfValid = [&CGF](llvm::User *U) -> llvm::StoreInst * {
2771 auto *SI = dyn_cast<llvm::StoreInst>(U);
2776 assert(!SI->isAtomic() && !SI->isVolatile());
2784 llvm::BasicBlock *IP = CGF.
Builder.GetInsertBlock();
2785 if (IP->empty())
return nullptr;
2786 llvm::Instruction *I = &IP->back();
2789 for (llvm::BasicBlock::reverse_iterator II = IP->rbegin(),
2792 if (llvm::IntrinsicInst *Intrinsic =
2793 dyn_cast<llvm::IntrinsicInst>(&*II)) {
2794 if (Intrinsic->getIntrinsicID() == llvm::Intrinsic::lifetime_end) {
2795 const llvm::Value *CastAddr = Intrinsic->getArgOperand(1);
2799 if (isa<llvm::BitCastInst>(&*II) && (CastAddr == &*II))
2807 return GetStoreIfValid(I);
2810 llvm::StoreInst *store =
2812 if (!store)
return nullptr;
2816 llvm::BasicBlock *StoreBB = store->getParent();
2817 llvm::BasicBlock *IP = CGF.
Builder.GetInsertBlock();
2818 while (IP != StoreBB) {
2819 if (!(IP = IP->getSinglePredecessor()))
2833 EmitUnreachable(EndLoc);
2837 if (CurCodeDecl && CurCodeDecl->hasAttr<NakedAttr>()) {
2839 Builder.CreateUnreachable();
2845 Builder.CreateRetVoid();
2849 llvm::DebugLoc RetDbgLoc;
2858 assert(hasAggregateEvaluationKind(RetTy));
2860 llvm::Function::arg_iterator EI = CurFn->arg_end();
2865 RV = Builder.CreateAlignedLoad(SRet, getPointerAlign(),
"sret");
2870 auto AI = CurFn->arg_begin();
2873 switch (getEvaluationKind(RetTy)) {
2876 EmitLoadOfComplex(MakeAddrLValue(
ReturnValue, RetTy), EndLoc);
2877 EmitStoreOfComplex(RT, MakeNaturalAlignAddrLValue(&*AI, RetTy),
2885 EmitStoreOfScalar(Builder.CreateLoad(
ReturnValue),
2886 MakeNaturalAlignAddrLValue(&*AI, RetTy),
2902 if (llvm::StoreInst *SI =
2907 if (EmitRetDbgLoc && !AutoreleaseResult)
2908 RetDbgLoc = SI->getDebugLoc();
2910 RV = SI->getValueOperand();
2911 SI->eraseFromParent();
2926 if (AutoreleaseResult) {
2934 if (
auto *FD = dyn_cast<FunctionDecl>(CurCodeDecl))
2935 RT = FD->getReturnType();
2936 else if (
auto *MD = dyn_cast<ObjCMethodDecl>(CurCodeDecl))
2937 RT = MD->getReturnType();
2938 else if (isa<BlockDecl>(CurCodeDecl))
2939 RT = BlockInfo->BlockExpression->getFunctionType()->getReturnType();
2941 llvm_unreachable(
"Unexpected function/method type");
2943 assert(getLangOpts().ObjCAutoRefCount &&
2961 for (
unsigned i = 0, e = coercionType->getNumElements(); i != e; ++i) {
2962 auto coercedEltType = coercionType->getElementType(i);
2966 auto eltAddr = Builder.CreateStructGEP(addr, i);
2967 auto elt = Builder.CreateLoad(eltAddr);
2968 results.push_back(elt);
2972 if (results.size() == 1) {
2980 RV = llvm::UndefValue::get(returnType);
2981 for (
unsigned i = 0, e = results.size(); i != e; ++i) {
2982 RV = Builder.CreateInsertValue(RV, results[i], i);
2989 llvm_unreachable(
"Invalid ABI kind for return argument");
2992 llvm::Instruction *
Ret;
2994 EmitReturnValueCheck(RV);
2995 Ret = Builder.CreateRet(RV);
2997 Ret = Builder.CreateRetVoid();
3001 Ret->setDebugLoc(std::move(RetDbgLoc));
3009 ReturnsNonNullAttr *RetNNAttr =
nullptr;
3010 if (SanOpts.has(SanitizerKind::ReturnsNonnullAttribute))
3011 RetNNAttr = CurCodeDecl->getAttr<ReturnsNonNullAttr>();
3013 if (!RetNNAttr && !requiresReturnValueNullabilityCheck())
3021 assert(!requiresReturnValueNullabilityCheck() &&
3022 "Cannot check nullability and the nonnull attribute");
3023 AttrLoc = RetNNAttr->getLocation();
3024 CheckKind = SanitizerKind::ReturnsNonnullAttribute;
3025 Handler = SanitizerHandler::NonnullReturn;
3027 if (
auto *DD = dyn_cast<DeclaratorDecl>(CurCodeDecl))
3028 if (
auto *TSI = DD->getTypeSourceInfo())
3030 AttrLoc = FTL.getReturnLoc().findNullabilityLoc();
3031 CheckKind = SanitizerKind::NullabilityReturn;
3032 Handler = SanitizerHandler::NullabilityReturn;
3039 llvm::BasicBlock *Check = createBasicBlock(
"nullcheck");
3040 llvm::BasicBlock *NoCheck = createBasicBlock(
"no.nullcheck");
3041 llvm::Value *SLocPtr = Builder.CreateLoad(ReturnLocation,
"return.sloc.load");
3042 llvm::Value *CanNullCheck = Builder.CreateIsNotNull(SLocPtr);
3043 if (requiresReturnValueNullabilityCheck())
3045 Builder.CreateAnd(CanNullCheck, RetValNullabilityPrecondition);
3046 Builder.CreateCondBr(CanNullCheck, Check, NoCheck);
3051 llvm::Constant *StaticData[] = {EmitCheckSourceLocation(AttrLoc)};
3053 EmitCheck(std::make_pair(Cond, CheckKind), Handler, StaticData, DynamicData);
3074 llvm::Value *Placeholder = llvm::UndefValue::get(IRPtrTy->getPointerTo());
3095 Address local = GetAddrOfLocalVar(param);
3100 CGM.ErrorUnsupported(param,
"forwarded non-trivially copyable parameter");
3113 }
else if (getLangOpts().ObjCAutoRefCount &&
3114 param->
hasAttr<NSConsumedAttr>() &&
3118 llvm::ConstantPointerNull::get(cast<llvm::PointerType>(ptr->getType()));
3119 Builder.CreateStore(null, local);
3125 args.
add(convertTempToRValue(local, type, loc), type);
3129 if (hasAggregateEvaluationKind(type) && !CurFuncIsThunk &&
3133 CalleeDestructedParamCleanups.lookup(cast<ParmVarDecl>(param));
3135 "cleanup for callee-destructed param not recorded");
3137 llvm::Instruction *isActive = Builder.CreateUnreachable();
3143 return isa<llvm::ConstantPointerNull>(addr);
3152 "shouldn't have writeback for provably null argument");
3154 llvm::BasicBlock *contBB =
nullptr;
3158 bool provablyNonNull = llvm::isKnownNonZero(srcAddr.
getPointer(),
3160 if (!provablyNonNull) {
3166 CGF.
Builder.CreateCondBr(isNull, contBB, writebackBB);
3175 "icr.writeback-cast");
3184 if (writeback.
ToUse) {
3209 if (!provablyNonNull)
3224 for (
const auto &I : llvm::reverse(Cleanups)) {
3226 I.IsActiveIP->eraseFromParent();
3232 if (uop->getOpcode() == UO_AddrOf)
3233 return uop->getSubExpr();
3263 llvm::PointerType *destType =
3287 llvm::ConstantPointerNull::get(
3288 cast<llvm::PointerType>(destType->getElementType()));
3292 llvm::BasicBlock *contBB =
nullptr;
3293 llvm::BasicBlock *originBB =
nullptr;
3298 bool provablyNonNull = llvm::isKnownNonZero(srcAddr.
getPointer(),
3300 if (provablyNonNull) {
3306 finalArgument = CGF.
Builder.CreateSelect(isNull,
3307 llvm::ConstantPointerNull::get(destType),
3313 originBB = CGF.
Builder.GetInsertBlock();
3316 CGF.
Builder.CreateCondBr(isNull, contBB, copyBB);
3318 condEval.
begin(CGF);
3348 if (shouldCopy && !provablyNonNull) {
3349 llvm::BasicBlock *copyBB = CGF.
Builder.GetInsertBlock();
3354 llvm::PHINode *phiToUse = CGF.
Builder.CreatePHI(valueToUse->getType(), 2,
3356 phiToUse->addIncoming(valueToUse, copyBB);
3357 phiToUse->addIncoming(llvm::UndefValue::get(valueToUse->getType()),
3359 valueToUse = phiToUse;
3374 StackBase = CGF.
Builder.CreateCall(F, {},
"inalloca.save");
3380 llvm::Function *F = CGF.
CGM.
getIntrinsic(llvm::Intrinsic::stackrestore);
3381 CGF.
Builder.CreateCall(F, StackBase);
3389 if (!AC.
getDecl() || !(SanOpts.has(SanitizerKind::NonnullAttribute) ||
3390 SanOpts.has(SanitizerKind::NullabilityArg)))
3398 const NonNullAttr *NNAttr =
nullptr;
3399 if (SanOpts.has(SanitizerKind::NonnullAttribute))
3402 bool CanCheckNullability =
false;
3403 if (SanOpts.has(SanitizerKind::NullabilityArg) && !NNAttr && PVD) {
3407 PVD->getTypeSourceInfo();
3410 if (!NNAttr && !CanCheckNullability)
3417 AttrLoc = NNAttr->getLocation();
3418 CheckKind = SanitizerKind::NonnullAttribute;
3419 Handler = SanitizerHandler::NonnullArg;
3421 AttrLoc = PVD->getTypeSourceInfo()->getTypeLoc().findNullabilityLoc();
3422 CheckKind = SanitizerKind::NullabilityArg;
3423 Handler = SanitizerHandler::NullabilityArg;
3430 Builder.CreateICmpNE(V, llvm::Constant::getNullValue(V->getType()));
3431 llvm::Constant *StaticData[] = {
3432 EmitCheckSourceLocation(ArgLoc), EmitCheckSourceLocation(AttrLoc),
3433 llvm::ConstantInt::get(Int32Ty, ArgNo + 1),
3435 EmitCheck(std::make_pair(Cond, CheckKind), Handler, StaticData, None);
3440 llvm::iterator_range<CallExpr::const_arg_iterator> ArgRange,
3442 assert((
int)ArgTypes.size() == (ArgRange.end() - ArgRange.begin()));
3450 CGM.getTarget().getCXXABI().areArgsDestroyedLeftToRightInCallee()
3451 ? Order == EvaluationOrder::ForceLeftToRight
3452 : Order != EvaluationOrder::ForceRightToLeft;
3454 auto MaybeEmitImplicitObjectSize = [&](
unsigned I,
const Expr *Arg,
3464 auto T = Builder.getIntNTy(Context.
getTypeSize(SizeTy));
3465 assert(EmittedArg.getScalarVal() &&
"We emitted nothing for the arg?");
3466 llvm::Value *
V = evaluateOrEmitBuiltinObjectSize(Arg, PS->getType(), T,
3467 EmittedArg.getScalarVal(),
3473 std::swap(Args.back(), *(&Args.back() - 1));
3477 bool HasInAllocaArgs =
false;
3478 if (CGM.getTarget().getCXXABI().isMicrosoft()) {
3480 I != E && !HasInAllocaArgs; ++I)
3482 if (HasInAllocaArgs) {
3483 assert(
getTarget().getTriple().getArch() == llvm::Triple::x86);
3489 size_t CallArgsStart = Args.size();
3490 for (
unsigned I = 0, E = ArgTypes.size(); I != E; ++I) {
3491 unsigned Idx = LeftToRight ? I : E - I - 1;
3493 unsigned InitialArgSize = Args.size();
3496 assert((!isa<ObjCIndirectCopyRestoreExpr>(*Arg) ||
3497 getContext().hasSameUnqualifiedType((*Arg)->getType(),
3499 (isa<ObjCMethodDecl>(AC.
getDecl()) &&
3500 isObjCMethodWithTypeParams(cast<ObjCMethodDecl>(AC.
getDecl())))) &&
3501 "Argument and parameter types don't match");
3502 EmitCallArg(Args, *Arg, ArgTypes[Idx]);
3505 assert(InitialArgSize + 1 == Args.size() &&
3506 "The code below depends on only adding one arg per EmitCallArg");
3507 (void)InitialArgSize;
3510 if (!Args.back().hasLValue()) {
3511 RValue RVArg = Args.back().getKnownRValue();
3512 EmitNonNullArgCheck(RVArg, ArgTypes[Idx], (*Arg)->getExprLoc(), AC,
3513 ParamsToSkip + Idx);
3517 MaybeEmitImplicitObjectSize(Idx, *Arg, RVArg);
3524 std::reverse(Args.begin() + CallArgsStart, Args.end());
3532 : Addr(Addr), Ty(Ty) {}
3550 struct DisableDebugLocationUpdates {
3552 bool disabledDebugInfo;
3554 if ((disabledDebugInfo = isa<CXXDefaultArgExpr>(E) && CGF.
getDebugInfo()))
3557 ~DisableDebugLocationUpdates() {
3558 if (disabledDebugInfo)
3577 if (!HasLV && RV.isScalar())
3579 else if (!HasLV && RV.isComplex())
3582 auto Addr = HasLV ? LV.
getAddress(CGF) : RV.getAggregateAddress();
3587 : RV.isVolatileQualified());
3594 DisableDebugLocationUpdates Dis(*
this, E);
3596 = dyn_cast<ObjCIndirectCopyRestoreExpr>(E)) {
3597 assert(getLangOpts().ObjCAutoRefCount);
3602 "reference binding to unmaterialized r-value!");
3606 return args.
add(EmitReferenceBindingToExpr(E), type);
3609 bool HasAggregateEvalKind = hasAggregateEvaluationKind(type);
3614 if (HasAggregateEvalKind &&
3622 Slot = CreateAggTemp(type,
"agg.tmp");
3624 bool DestroyedInCallee =
true, NeedsEHCleanup =
true;
3626 DestroyedInCallee = RD->hasNonTrivialDestructor();
3630 if (DestroyedInCallee)
3633 EmitAggExpr(E, Slot);
3637 if (DestroyedInCallee && NeedsEHCleanup) {
3644 llvm::Instruction *IsActive = Builder.CreateUnreachable();
3650 if (HasAggregateEvalKind && isa<ImplicitCastExpr>(E) &&
3651 cast<CastExpr>(E)->getCastKind() == CK_LValueToRValue) {
3652 LValue L = EmitLValue(cast<CastExpr>(E)->getSubExpr());
3658 args.
add(EmitAnyExprToTemp(E), type);
3661 QualType CodeGenFunction::getVarArgType(
const Expr *Arg) {
3665 if (!
getTarget().getTriple().isOSWindows())
3682 CodeGenFunction::AddObjCARCExceptionMetadata(llvm::Instruction *Inst) {
3683 if (CGM.getCodeGenOpts().OptimizationLevel != 0 &&
3684 !CGM.getCodeGenOpts().ObjCAutoRefCountExceptions)
3685 Inst->setMetadata(
"clang.arc.no_objc_arc_exceptions",
3686 CGM.getNoObjCARCExceptionsMetadata());
3692 const llvm::Twine &
name) {
3693 return EmitNounwindRuntimeCall(callee, None, name);
3700 const llvm::Twine &name) {
3701 llvm::CallInst *call = EmitRuntimeCall(callee, args, name);
3702 call->setDoesNotThrow();
3709 const llvm::Twine &name) {
3710 return EmitRuntimeCall(callee, None, name);
3720 if (!CurrentFuncletPad)
3724 auto *CalleeFn = dyn_cast<llvm::Function>(Callee->stripPointerCasts());
3725 if (CalleeFn && CalleeFn->isIntrinsic() && CalleeFn->doesNotThrow())
3728 BundleList.emplace_back(
"funclet", CurrentFuncletPad);
3735 const llvm::Twine &name) {
3736 llvm::CallInst *call = Builder.CreateCall(
3737 callee, args, getBundlesForFunclet(callee.getCallee()), name);
3738 call->setCallingConv(getRuntimeCC());
3746 getBundlesForFunclet(callee.getCallee());
3748 if (getInvokeDest()) {
3749 llvm::InvokeInst *invoke =
3750 Builder.CreateInvoke(callee,
3751 getUnreachableBlock(),
3755 invoke->setDoesNotReturn();
3756 invoke->setCallingConv(getRuntimeCC());
3758 llvm::CallInst *call = Builder.CreateCall(callee, args, BundleList);
3759 call->setDoesNotReturn();
3760 call->setCallingConv(getRuntimeCC());
3761 Builder.CreateUnreachable();
3768 const Twine &name) {
3769 return EmitRuntimeCallOrInvoke(callee, None, name);
3776 const Twine &name) {
3777 llvm::CallBase *call = EmitCallOrInvoke(callee, args, name);
3778 call->setCallingConv(getRuntimeCC());
3786 const Twine &Name) {
3787 llvm::BasicBlock *InvokeDest = getInvokeDest();
3789 getBundlesForFunclet(Callee.getCallee());
3791 llvm::CallBase *Inst;
3793 Inst = Builder.CreateCall(Callee, Args, BundleList, Name);
3795 llvm::BasicBlock *ContBB = createBasicBlock(
"invoke.cont");
3796 Inst = Builder.CreateInvoke(Callee, ContBB, InvokeDest, Args, BundleList,
3803 if (CGM.getLangOpts().ObjCAutoRefCount)
3804 AddObjCARCExceptionMetadata(Inst);
3809 void CodeGenFunction::deferPlaceholderReplacement(llvm::Instruction *Old,
3811 DeferredReplacements.push_back(std::make_pair(Old, New));
3818 llvm::CallBase **callOrInvoke,
3829 llvm::FunctionType *IRFuncTy = getTypes().GetFunctionType(CallInfo);
3832 if (
const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(TargetDecl))
3839 if (TargetDecl->
hasAttr<AlwaysInlineAttr>() &&
3840 TargetDecl->
hasAttr<TargetAttr>())
3841 checkTargetFeatures(Loc, FD);
3858 assert(IRFuncTy == TypeFromVal);
3867 if (llvm::StructType *ArgStruct = CallInfo.
getArgStruct()) {
3868 const llvm::DataLayout &DL = CGM.getDataLayout();
3870 llvm::AllocaInst *AI;
3872 IP = IP->getNextNode();
3873 AI =
new llvm::AllocaInst(ArgStruct, DL.getAllocaAddrSpace(),
3876 AI = CreateTempAlloca(ArgStruct,
"argmem");
3879 AI->setAlignment(Align.getAsAlign());
3880 AI->setUsedWithInAlloca(
true);
3881 assert(AI->isUsedWithInAlloca() && !AI->isStaticAlloca());
3882 ArgMemory =
Address(AI, Align);
3885 ClangToLLVMArgMapping IRFunctionArgs(CGM.getContext(), CallInfo);
3894 if (!ReturnValue.
isNull()) {
3897 SRetPtr = CreateMemTemp(RetTy,
"tmp", &SRetAlloca);
3898 if (HaveInsertPoint() && ReturnValue.
isUnused()) {
3901 UnusedReturnSizePtr = EmitLifetimeStart(size, SRetAlloca.
getPointer());
3904 if (IRFunctionArgs.hasSRetArg()) {
3905 IRCallArgs[IRFunctionArgs.getSRetArgNo()] = SRetPtr.getPointer();
3909 Builder.CreateStore(SRetPtr.getPointer(), Addr);
3922 assert(CallInfo.
arg_size() == CallArgs.size() &&
3923 "Mismatch between function signature & arguments.");
3926 for (CallArgList::const_iterator I = CallArgs.begin(), E = CallArgs.end();
3927 I != E; ++I, ++info_it, ++ArgNo) {
3931 if (IRFunctionArgs.hasPaddingArg(ArgNo))
3932 IRCallArgs[IRFunctionArgs.getPaddingArgNo(ArgNo)] =
3935 unsigned FirstIRArg, NumIRArgs;
3936 std::tie(FirstIRArg, NumIRArgs) = IRFunctionArgs.getIRArgs(ArgNo);
3940 assert(NumIRArgs == 0);
3941 assert(
getTarget().getTriple().getArch() == llvm::Triple::x86);
3942 if (I->isAggregate()) {
3945 ? I->getKnownLValue().getAddress(*
this)
3946 : I->getKnownRValue().getAggregateAddress();
3947 llvm::Instruction *Placeholder =
3949 CGBuilderTy::InsertPoint IP = Builder.saveIP();
3950 Builder.SetInsertPoint(Placeholder);
3953 Builder.restoreIP(IP);
3954 deferPlaceholderReplacement(Placeholder, Addr.
getPointer());
3959 unsigned AS = Addr.
getType()->getPointerAddressSpace();
3964 if (Addr.
getType() != MemType)
3965 Addr = Builder.CreateBitCast(Addr, MemType);
3966 I->copyInto(*
this, Addr);
3972 assert(NumIRArgs == 1);
3973 if (!I->isAggregate()) {
3975 Address Addr = CreateMemTempWithoutCast(
3979 I->copyInto(*
this, Addr);
3990 ? I->getKnownLValue().getAddress(*
this)
3991 : I->getKnownRValue().getAggregateAddress();
3994 const llvm::DataLayout *TD = &CGM.getDataLayout();
3996 assert((FirstIRArg >= IRFuncTy->getNumParams() ||
3997 IRFuncTy->getParamType(FirstIRArg)->getPointerAddressSpace() ==
3998 TD->getAllocaAddrSpace()) &&
3999 "indirect argument must be in alloca address space");
4001 bool NeedCopy =
false;
4004 llvm::getOrEnforceKnownAlignment(V, Align.
getQuantity(), *TD) <
4007 }
else if (I->hasLValue()) {
4008 auto LV = I->getKnownLValue();
4015 if (!getLangOpts().OpenCL) {
4018 AS != CGM.getASTAllocaAddressSpace()))) {
4025 Addr.
getType()->getAddressSpace() != IRFuncTy->
4033 Address AI = CreateMemTempWithoutCast(
4038 uint64_t ByvalTempElementSize =
4041 EmitLifetimeStart(ByvalTempElementSize, AI.
getPointer());
4045 CallLifetimeEndAfterCall.emplace_back(AI, LifetimeSize);
4048 I->copyInto(*
this, AI);
4051 auto *T = V->getType()->getPointerElementType()->getPointerTo(
4052 CGM.getDataLayout().getAllocaAddrSpace());
4053 IRCallArgs[FirstIRArg] = getTargetHooks().performAddrSpaceCast(
4062 assert(NumIRArgs == 0);
4070 assert(NumIRArgs == 1);
4072 if (!I->isAggregate())
4073 V = I->getKnownRValue().getScalarVal();
4075 V = Builder.CreateLoad(
4076 I->hasLValue() ? I->getKnownLValue().getAddress(*
this)
4077 : I->getKnownRValue().getAggregateAddress());
4083 assert(!swiftErrorTemp.
isValid() &&
"multiple swifterror args");
4090 CreateMemTemp(pointeeTy, getPointerAlign(),
"swifterror.temp");
4092 cast<llvm::AllocaInst>(
V)->setSwiftError(
true);
4094 llvm::Value *errorValue = Builder.CreateLoad(swiftErrorArg);
4095 Builder.CreateStore(errorValue, swiftErrorTemp);
4100 V->getType()->isIntegerTy())
4105 if (FirstIRArg < IRFuncTy->getNumParams() &&
4106 V->getType() != IRFuncTy->getParamType(FirstIRArg))
4107 V = Builder.CreateBitCast(V, IRFuncTy->getParamType(FirstIRArg));
4109 IRCallArgs[FirstIRArg] =
V;
4115 if (!I->isAggregate()) {
4116 Src = CreateMemTemp(I->Ty,
"coerce");
4117 I->copyInto(*
this, Src);
4119 Src = I->hasLValue() ? I->getKnownLValue().getAddress(*
this)
4120 : I->getKnownRValue().getAggregateAddress();
4128 llvm::StructType *STy =
4132 uint64_t SrcSize = CGM.getDataLayout().getTypeAllocSize(SrcTy);
4133 uint64_t DstSize = CGM.getDataLayout().getTypeAllocSize(STy);
4139 if (SrcSize < DstSize) {
4143 Builder.CreateMemCpy(TempAlloca, Src, SrcSize);
4146 Src = Builder.CreateBitCast(Src,
4150 assert(NumIRArgs == STy->getNumElements());
4151 for (
unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
4152 Address EltPtr = Builder.CreateStructGEP(Src, i);
4154 IRCallArgs[FirstIRArg + i] = LI;
4158 assert(NumIRArgs == 1);
4159 IRCallArgs[FirstIRArg] =
4168 auto layout = CGM.getDataLayout().getStructLayout(coercionType);
4173 if (I->isAggregate()) {
4174 addr = I->hasLValue() ? I->getKnownLValue().getAddress(*
this)
4175 : I->getKnownRValue().getAggregateAddress();
4178 RValue RV = I->getKnownRValue();
4182 auto scalarSize = CGM.getDataLayout().getTypeAllocSize(scalarType);
4183 auto scalarAlign = CGM.getDataLayout().getPrefTypeAlignment(scalarType);
4186 addr = CreateTempAlloca(
4189 (
unsigned)layout->getAlignment().value(), scalarAlign)),
4191 nullptr, &AllocaAddr);
4192 tempSize = EmitLifetimeStart(scalarSize, AllocaAddr.
getPointer());
4197 addr = Builder.CreateElementBitCast(addr, coercionType);
4199 unsigned IRArgPos = FirstIRArg;
4200 for (
unsigned i = 0, e = coercionType->getNumElements(); i != e; ++i) {
4201 llvm::Type *eltType = coercionType->getElementType(i);
4203 Address eltAddr = Builder.CreateStructGEP(addr, i);
4205 IRCallArgs[IRArgPos++] = elt;
4207 assert(IRArgPos == FirstIRArg + NumIRArgs);
4210 EmitLifetimeEnd(tempSize, AllocaAddr.
getPointer());
4217 unsigned IRArgPos = FirstIRArg;
4218 ExpandTypeToArgs(I->Ty, *I, IRFuncTy, IRCallArgs, IRArgPos);
4219 assert(IRArgPos == FirstIRArg + NumIRArgs);
4235 unsigned CalleeAS = CalleePtr->getType()->getPointerAddressSpace();
4237 Builder.CreateBitCast(CalleePtr, IRFuncTy->getPointerTo(CalleeAS));
4240 IRFuncTy->getParamType(IRFuncTy->getNumParams() - 1);
4241 if (Arg->getType() != LastParamTy) {
4245 llvm::StructType *DeclaredTy = cast<llvm::StructType>(
4246 cast<llvm::PointerType>(LastParamTy)->getElementType());
4247 assert(DeclaredTy->getNumElements() == FullTy->getNumElements());
4248 for (llvm::StructType::element_iterator DI = DeclaredTy->element_begin(),
4249 DE = DeclaredTy->element_end(),
4250 FI = FullTy->element_begin();
4251 DI != DE; ++DI, ++FI)
4254 Arg = Builder.CreateBitCast(Arg, LastParamTy);
4257 assert(IRFunctionArgs.hasInallocaArg());
4258 IRCallArgs[IRFunctionArgs.getInallocaArgNo()] = Arg;
4269 auto simplifyVariadicCallee = [](llvm::FunctionType *CalleeFT,
4271 if (!CalleeFT->isVarArg())
4275 if (llvm::ConstantExpr *CE = dyn_cast<llvm::ConstantExpr>(Ptr)) {
4276 if (CE->getOpcode() == llvm::Instruction::BitCast)
4277 Ptr = CE->getOperand(0);
4280 llvm::Function *OrigFn = dyn_cast<llvm::Function>(Ptr);
4284 llvm::FunctionType *OrigFT = OrigFn->getFunctionType();
4288 if (OrigFT->isVarArg() ||
4289 OrigFT->getNumParams() != CalleeFT->getNumParams() ||
4290 OrigFT->getReturnType() != CalleeFT->getReturnType())
4293 for (
unsigned i = 0, e = OrigFT->getNumParams(); i != e; ++i)
4294 if (OrigFT->getParamType(i) != CalleeFT->getParamType(i))
4300 if (llvm::Function *OrigFn = simplifyVariadicCallee(IRFuncTy, CalleePtr)) {
4302 IRFuncTy = OrigFn->getFunctionType();
4317 assert(IRCallArgs.size() == IRFuncTy->getNumParams() || IRFuncTy->isVarArg());
4318 for (
unsigned i = 0; i < IRCallArgs.size(); ++i) {
4320 if (IRFunctionArgs.hasInallocaArg() &&
4321 i == IRFunctionArgs.getInallocaArgNo())
4323 if (i < IRFuncTy->getNumParams())
4324 assert(IRCallArgs[i]->getType() == IRFuncTy->getParamType(i));
4329 for (
unsigned i = 0; i < IRCallArgs.size(); ++i) {
4330 if (
auto *VT = dyn_cast<llvm::VectorType>(IRCallArgs[i]->getType()))
4331 LargestVectorWidth =
std::max((uint64_t)LargestVectorWidth,
4332 VT->getPrimitiveSizeInBits().getFixedSize());
4337 llvm::AttributeList Attrs;
4338 CGM.ConstructAttributeList(CalleePtr->getName(), CallInfo,
4342 if (
const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(CurFuncDecl))
4343 if (FD->usesFPIntrin())
4346 Attrs.addAttribute(
getLLVMContext(), llvm::AttributeList::FunctionIndex,
4347 llvm::Attribute::StrictFP);
4354 if (CurCodeDecl && CurCodeDecl->hasAttr<FlattenAttr>() &&
4355 !(TargetDecl && TargetDecl->
hasAttr<NoInlineAttr>())) {
4357 Attrs.addAttribute(
getLLVMContext(), llvm::AttributeList::FunctionIndex,
4358 llvm::Attribute::AlwaysInline);
4362 if (isSEHTryScope()) {
4364 Attrs.addAttribute(
getLLVMContext(), llvm::AttributeList::FunctionIndex,
4365 llvm::Attribute::NoInline);
4370 if (currentFunctionUsesSEHTry()) {
4372 CannotThrow =
false;
4373 }
else if (isCleanupPadScope() &&
4381 CannotThrow = Attrs.hasAttribute(llvm::AttributeList::FunctionIndex,
4382 llvm::Attribute::NoUnwind);
4389 if (UnusedReturnSizePtr)
4391 UnusedReturnSizePtr);
4393 llvm::BasicBlock *InvokeDest = CannotThrow ? nullptr : getInvokeDest();
4396 getBundlesForFunclet(CalleePtr);
4398 if (
const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(CurFuncDecl))
4399 if (FD->usesFPIntrin())
4402 Attrs.addAttribute(
getLLVMContext(), llvm::AttributeList::FunctionIndex,
4403 llvm::Attribute::StrictFP);
4408 CI = Builder.CreateCall(IRFuncTy, CalleePtr, IRCallArgs, BundleList);
4410 llvm::BasicBlock *Cont = createBasicBlock(
"invoke.cont");
4411 CI = Builder.CreateInvoke(IRFuncTy, CalleePtr, Cont, InvokeDest, IRCallArgs,
4421 if (
const auto *FD = dyn_cast_or_null<FunctionDecl>(CurFuncDecl)) {
4422 if (
const auto *A = FD->getAttr<CFGuardAttr>()) {
4423 if (A->getGuard() == CFGuardAttr::GuardArg::nocf && !CI->getCalledFunction())
4424 Attrs = Attrs.addAttribute(
4425 getLLVMContext(), llvm::AttributeList::FunctionIndex,
"guard_nocf");
4430 CI->setAttributes(Attrs);
4431 CI->setCallingConv(static_cast<llvm::CallingConv::ID>(CallingConv));
4435 if (!CI->getType()->isVoidTy())
4436 CI->setName(
"call");
4439 if (
auto *VT = dyn_cast<llvm::VectorType>(CI->getType()))
4440 LargestVectorWidth =
std::max((uint64_t)LargestVectorWidth,
4441 VT->getPrimitiveSizeInBits().getFixedSize());
4446 if (!CI->getCalledFunction())
4447 PGO.valueProfile(Builder, llvm::IPVK_IndirectCallTarget,
4452 if (CGM.getLangOpts().ObjCAutoRefCount)
4453 AddObjCARCExceptionMetadata(CI);
4456 if (llvm::CallInst *Call = dyn_cast<llvm::CallInst>(CI)) {
4457 if (TargetDecl && TargetDecl->
hasAttr<NotTailCalledAttr>())
4458 Call->setTailCallKind(llvm::CallInst::TCK_NoTail);
4462 if (getDebugInfo() && TargetDecl &&
4463 TargetDecl->
hasAttr<MSAllocatorAttr>())
4464 getDebugInfo()->addHeapAllocSiteMetadata(CI, RetTy, Loc);
4471 if (CI->doesNotReturn()) {
4472 if (UnusedReturnSizePtr)
4476 if (SanOpts.has(SanitizerKind::Unreachable)) {
4479 if (
auto *F = CI->getCalledFunction())
4480 F->removeFnAttr(llvm::Attribute::NoReturn);
4481 CI->removeAttribute(llvm::AttributeList::FunctionIndex,
4482 llvm::Attribute::NoReturn);
4486 if (SanOpts.hasOneOf(SanitizerKind::Address |
4487 SanitizerKind::KernelAddress)) {
4489 llvm::IRBuilder<>::InsertPointGuard IPGuard(Builder);
4490 Builder.SetInsertPoint(CI);
4491 auto *FnType = llvm::FunctionType::get(CGM.VoidTy,
false);
4492 llvm::FunctionCallee Fn =
4493 CGM.CreateRuntimeFunction(FnType,
"__asan_handle_no_return");
4494 EmitNounwindRuntimeCall(Fn);
4498 EmitUnreachable(Loc);
4499 Builder.ClearInsertionPoint();
4504 EnsureInsertPoint();
4507 return GetUndefRValue(RetTy);
4511 if (swiftErrorTemp.
isValid()) {
4512 llvm::Value *errorResult = Builder.CreateLoad(swiftErrorTemp);
4513 Builder.CreateStore(errorResult, swiftErrorArg);
4532 addr = Builder.CreateElementBitCast(addr, coercionType);
4535 bool requiresExtract = isa<llvm::StructType>(CI->getType());
4537 unsigned unpaddedIndex = 0;
4538 for (
unsigned i = 0, e = coercionType->getNumElements(); i != e; ++i) {
4539 llvm::Type *eltType = coercionType->getElementType(i);
4541 Address eltAddr = Builder.CreateStructGEP(addr, i);
4543 if (requiresExtract)
4544 elt = Builder.CreateExtractValue(elt, unpaddedIndex++);
4546 assert(unpaddedIndex == 0);
4547 Builder.CreateStore(elt, eltAddr);
4556 if (UnusedReturnSizePtr)
4564 return GetUndefRValue(RetTy);
4570 switch (getEvaluationKind(RetTy)) {
4572 llvm::Value *Real = Builder.CreateExtractValue(CI, 0);
4573 llvm::Value *Imag = Builder.CreateExtractValue(CI, 1);
4578 bool DestIsVolatile = ReturnValue.
isVolatile();
4581 DestPtr = CreateMemTemp(RetTy,
"agg.tmp");
4582 DestIsVolatile =
false;
4591 if (V->getType() != RetIRTy)
4592 V = Builder.CreateBitCast(V, RetIRTy);
4596 llvm_unreachable(
"bad evaluation kind");
4600 bool DestIsVolatile = ReturnValue.
isVolatile();
4603 DestPtr = CreateMemTemp(RetTy,
"coerce");
4604 DestIsVolatile =
false;
4615 llvm_unreachable(
"Invalid ABI kind for return argument");
4618 llvm_unreachable(
"Unhandled ABIArgInfo::Kind");
4622 if (Ret.
isScalar() && TargetDecl) {
4623 if (
const auto *AA = TargetDecl->
getAttr<AssumeAlignedAttr>()) {
4625 if (
const auto *
Offset = AA->getOffset())
4626 OffsetValue = EmitScalarExpr(
Offset);
4628 llvm::Value *Alignment = EmitScalarExpr(AA->getAlignment());
4629 llvm::ConstantInt *AlignmentCI = cast<llvm::ConstantInt>(Alignment);
4630 EmitAlignmentAssumption(Ret.
getScalarVal(), RetTy, Loc, AA->getLocation(),
4631 AlignmentCI, OffsetValue);
4632 }
else if (
const auto *AA = TargetDecl->
getAttr<AllocAlignAttr>()) {
4633 llvm::Value *AlignmentVal = CallArgs[AA->getParamIndex().getLLVMIndex()]
4636 EmitAlignmentAssumption(Ret.
getScalarVal(), RetTy, Loc, AA->getLocation(),
4644 LifetimeEnd.Emit(*
this, {});
4651 const CallExpr *CE = getVirtualCallExpr();
4653 CGF, getVirtualMethodDecl(), getThisAddress(), getVirtualFunctionType(),
4668 return CGM.getTypes().getABIInfo().EmitMSVAArg(*
this, VAListAddr, Ty);
4669 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...
bool ReturnValue(const T &V, APValue &R)
Convers a value to an APValue.
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>'.
bool This(InterpState &S, CodePtr OpPC)
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.
unsigned getRegParm() const
QualType::DestructionKind needsDestruction(const ASTContext &Ctx) const
Would the destruction of this variable have any effect, and if so, what kind?
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.
bool Zero(InterpState &S, CodePtr OpPC)
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.
Address getAddress(CodeGenFunction &CGF) const
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.
static bool Ret(InterpState &S, CodePtr &PC, APValue &Result)
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)
bool Load(InterpState &S, CodePtr OpPC)
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="")
Address CreatePointerBitCastOrAddrSpaceCast(Address Addr, llvm::Type *Ty, const llvm::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.