35#include "llvm/ADT/APFloat.h"
36#include "llvm/ADT/APInt.h"
37#include "llvm/ADT/FloatingPointMode.h"
38#include "llvm/ADT/SmallPtrSet.h"
39#include "llvm/ADT/StringExtras.h"
40#include "llvm/Analysis/ValueTracking.h"
41#include "llvm/IR/DataLayout.h"
42#include "llvm/IR/InlineAsm.h"
43#include "llvm/IR/Intrinsics.h"
44#include "llvm/IR/IntrinsicsAArch64.h"
45#include "llvm/IR/IntrinsicsAMDGPU.h"
46#include "llvm/IR/IntrinsicsARM.h"
47#include "llvm/IR/IntrinsicsBPF.h"
48#include "llvm/IR/IntrinsicsDirectX.h"
49#include "llvm/IR/IntrinsicsHexagon.h"
50#include "llvm/IR/IntrinsicsNVPTX.h"
51#include "llvm/IR/IntrinsicsPowerPC.h"
52#include "llvm/IR/IntrinsicsR600.h"
53#include "llvm/IR/IntrinsicsRISCV.h"
54#include "llvm/IR/IntrinsicsS390.h"
55#include "llvm/IR/IntrinsicsVE.h"
56#include "llvm/IR/IntrinsicsWebAssembly.h"
57#include "llvm/IR/IntrinsicsX86.h"
58#include "llvm/IR/MDBuilder.h"
59#include "llvm/IR/MatrixBuilder.h"
60#include "llvm/IR/MemoryModelRelaxationAnnotations.h"
61#include "llvm/Support/AMDGPUAddrSpace.h"
62#include "llvm/Support/ConvertUTF.h"
63#include "llvm/Support/MathExtras.h"
64#include "llvm/Support/ScopedPrinter.h"
65#include "llvm/TargetParser/AArch64TargetParser.h"
66#include "llvm/TargetParser/RISCVISAInfo.h"
67#include "llvm/TargetParser/X86TargetParser.h"
72using namespace CodeGen;
76 Align AlignmentInBytes) {
78 switch (CGF.
getLangOpts().getTrivialAutoVarInit()) {
79 case LangOptions::TrivialAutoVarInitKind::Uninitialized:
82 case LangOptions::TrivialAutoVarInitKind::Zero:
83 Byte = CGF.
Builder.getInt8(0x00);
85 case LangOptions::TrivialAutoVarInitKind::Pattern: {
87 Byte = llvm::dyn_cast<llvm::ConstantInt>(
95 I->addAnnotationMetadata(
"auto-init");
101 unsigned BuiltinID) {
110 static SmallDenseMap<unsigned, StringRef, 64> F128Builtins{
111 {Builtin::BI__builtin___fprintf_chk,
"__fprintf_chkieee128"},
112 {Builtin::BI__builtin___printf_chk,
"__printf_chkieee128"},
113 {Builtin::BI__builtin___snprintf_chk,
"__snprintf_chkieee128"},
114 {Builtin::BI__builtin___sprintf_chk,
"__sprintf_chkieee128"},
115 {Builtin::BI__builtin___vfprintf_chk,
"__vfprintf_chkieee128"},
116 {Builtin::BI__builtin___vprintf_chk,
"__vprintf_chkieee128"},
117 {Builtin::BI__builtin___vsnprintf_chk,
"__vsnprintf_chkieee128"},
118 {Builtin::BI__builtin___vsprintf_chk,
"__vsprintf_chkieee128"},
119 {Builtin::BI__builtin_fprintf,
"__fprintfieee128"},
120 {Builtin::BI__builtin_printf,
"__printfieee128"},
121 {Builtin::BI__builtin_snprintf,
"__snprintfieee128"},
122 {Builtin::BI__builtin_sprintf,
"__sprintfieee128"},
123 {Builtin::BI__builtin_vfprintf,
"__vfprintfieee128"},
124 {Builtin::BI__builtin_vprintf,
"__vprintfieee128"},
125 {Builtin::BI__builtin_vsnprintf,
"__vsnprintfieee128"},
126 {Builtin::BI__builtin_vsprintf,
"__vsprintfieee128"},
127 {Builtin::BI__builtin_fscanf,
"__fscanfieee128"},
128 {Builtin::BI__builtin_scanf,
"__scanfieee128"},
129 {Builtin::BI__builtin_sscanf,
"__sscanfieee128"},
130 {Builtin::BI__builtin_vfscanf,
"__vfscanfieee128"},
131 {Builtin::BI__builtin_vscanf,
"__vscanfieee128"},
132 {Builtin::BI__builtin_vsscanf,
"__vsscanfieee128"},
133 {Builtin::BI__builtin_nexttowardf128,
"__nexttowardieee128"},
139 static SmallDenseMap<unsigned, StringRef, 4> AIXLongDouble64Builtins{
140 {Builtin::BI__builtin_frexpl,
"frexp"},
141 {Builtin::BI__builtin_ldexpl,
"ldexp"},
142 {Builtin::BI__builtin_modfl,
"modf"},
148 if (FD->
hasAttr<AsmLabelAttr>())
154 &
getTarget().getLongDoubleFormat() == &llvm::APFloat::IEEEquad() &&
155 F128Builtins.contains(BuiltinID))
156 Name = F128Builtins[BuiltinID];
159 &llvm::APFloat::IEEEdouble() &&
160 AIXLongDouble64Builtins.contains(BuiltinID))
161 Name = AIXLongDouble64Builtins[BuiltinID];
166 llvm::FunctionType *Ty =
169 return GetOrCreateLLVMFunction(Name, Ty,
D,
false);
175 QualType T, llvm::IntegerType *IntType) {
178 if (
V->getType()->isPointerTy())
179 return CGF.
Builder.CreatePtrToInt(
V, IntType);
181 assert(
V->getType() == IntType);
189 if (ResultType->isPointerTy())
190 return CGF.
Builder.CreateIntToPtr(
V, ResultType);
192 assert(
V->getType() == ResultType);
203 if (Align % Bytes != 0) {
216 AtomicOrdering Ordering = AtomicOrdering::SequentiallyConsistent) {
226 llvm::IntegerType *IntType = llvm::IntegerType::get(
230 llvm::Type *ValueType = Val->getType();
258 llvm::AtomicRMWInst::BinOp Kind,
267 llvm::AtomicRMWInst::BinOp Kind,
269 Instruction::BinaryOps Op,
270 bool Invert =
false) {
279 llvm::IntegerType *IntType = llvm::IntegerType::get(
283 llvm::Type *ValueType = Val->getType();
287 Kind, DestAddr, Val, llvm::AtomicOrdering::SequentiallyConsistent);
292 llvm::ConstantInt::getAllOnesValue(IntType));
316 llvm::IntegerType *IntType = llvm::IntegerType::get(
320 llvm::Type *ValueType = Cmp->getType();
325 DestAddr, Cmp, New, llvm::AtomicOrdering::SequentiallyConsistent,
326 llvm::AtomicOrdering::SequentiallyConsistent);
329 return CGF.
Builder.CreateZExt(CGF.
Builder.CreateExtractValue(Pair, 1),
352 AtomicOrdering SuccessOrdering = AtomicOrdering::SequentiallyConsistent) {
367 auto FailureOrdering = SuccessOrdering == AtomicOrdering::Release ?
368 AtomicOrdering::Monotonic :
376 DestAddr, Comparand, Exchange, SuccessOrdering, FailureOrdering);
377 Result->setVolatile(
true);
395 AtomicOrdering SuccessOrdering) {
396 assert(
E->getNumArgs() == 4);
402 assert(DestPtr->getType()->isPointerTy());
403 assert(!ExchangeHigh->getType()->isPointerTy());
404 assert(!ExchangeLow->getType()->isPointerTy());
407 auto FailureOrdering = SuccessOrdering == AtomicOrdering::Release
408 ? AtomicOrdering::Monotonic
413 llvm::Type *Int128Ty = llvm::IntegerType::get(CGF.
getLLVMContext(), 128);
414 Address DestAddr(DestPtr, Int128Ty,
419 ExchangeHigh = CGF.
Builder.CreateZExt(ExchangeHigh, Int128Ty);
420 ExchangeLow = CGF.
Builder.CreateZExt(ExchangeLow, Int128Ty);
422 CGF.
Builder.CreateShl(ExchangeHigh, llvm::ConstantInt::get(Int128Ty, 64));
423 llvm::Value *Exchange = CGF.
Builder.CreateOr(ExchangeHigh, ExchangeLow);
429 SuccessOrdering, FailureOrdering);
435 CXI->setVolatile(
true);
447 AtomicOrdering Ordering = AtomicOrdering::SequentiallyConsistent) {
453 AtomicRMWInst::Add, DestAddr, ConstantInt::get(IntTy, 1), Ordering);
454 return CGF.
Builder.CreateAdd(
Result, ConstantInt::get(IntTy, 1));
459 AtomicOrdering Ordering = AtomicOrdering::SequentiallyConsistent) {
465 AtomicRMWInst::Sub, DestAddr, ConstantInt::get(IntTy, 1), Ordering);
466 return CGF.
Builder.CreateSub(
Result, ConstantInt::get(IntTy, 1));
477 Load->setVolatile(
true);
487 llvm::StoreInst *Store =
489 Store->setVolatile(
true);
498 unsigned ConstrainedIntrinsicID) {
501 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF,
E);
502 if (CGF.
Builder.getIsFPConstrained()) {
504 return CGF.
Builder.CreateConstrainedFPCall(F, { Src0 });
507 return CGF.
Builder.CreateCall(F, Src0);
515 unsigned ConstrainedIntrinsicID) {
519 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF,
E);
520 if (CGF.
Builder.getIsFPConstrained()) {
522 return CGF.
Builder.CreateConstrainedFPCall(F, { Src0, Src1 });
525 return CGF.
Builder.CreateCall(F, { Src0, Src1 });
532 llvm::Intrinsic::ID ConstrainedIntrinsicID) {
536 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF,
E);
537 if (CGF.
Builder.getIsFPConstrained()) {
539 {Src0->getType(), Src1->getType()});
540 return CGF.
Builder.CreateConstrainedFPCall(F, {Src0, Src1});
545 return CGF.
Builder.CreateCall(F, {Src0, Src1});
552 unsigned ConstrainedIntrinsicID) {
557 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF,
E);
558 if (CGF.
Builder.getIsFPConstrained()) {
560 return CGF.
Builder.CreateConstrainedFPCall(F, { Src0, Src1, Src2 });
563 return CGF.
Builder.CreateCall(F, { Src0, Src1, Src2 });
570 unsigned IntrinsicID,
571 unsigned ConstrainedIntrinsicID,
575 if (CGF.
Builder.getIsFPConstrained())
580 if (CGF.
Builder.getIsFPConstrained())
581 return CGF.
Builder.CreateConstrainedFPCall(F, Args);
583 return CGF.
Builder.CreateCall(F, Args);
591 unsigned IntrinsicID,
592 llvm::StringRef Name =
"") {
593 static_assert(N,
"expect non-empty argument");
595 for (
unsigned I = 0; I < N; ++I)
598 return CGF.
Builder.CreateCall(F, Args, Name);
604 unsigned IntrinsicID) {
609 return CGF.
Builder.CreateCall(F, {Src0, Src1});
615 unsigned IntrinsicID,
616 unsigned ConstrainedIntrinsicID) {
620 if (CGF.
Builder.getIsFPConstrained()) {
621 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF,
E);
623 {ResultType, Src0->getType()});
624 return CGF.
Builder.CreateConstrainedFPCall(F, {Src0});
628 return CGF.
Builder.CreateCall(F, Src0);
633 llvm::Intrinsic::ID IntrinsicID) {
641 llvm::Value *
Call = CGF.
Builder.CreateCall(F, Src0);
643 llvm::Value *Exp = CGF.
Builder.CreateExtractValue(
Call, 1);
654 Call->setDoesNotAccessMemory();
663 llvm::Type *Ty =
V->getType();
664 int Width = Ty->getPrimitiveSizeInBits();
665 llvm::Type *IntTy = llvm::IntegerType::get(
C, Width);
667 if (Ty->isPPC_FP128Ty()) {
677 Value *ShiftCst = llvm::ConstantInt::get(IntTy, Width);
682 IntTy = llvm::IntegerType::get(
C, Width);
685 Value *Zero = llvm::Constant::getNullValue(IntTy);
686 return CGF.
Builder.CreateICmpSLT(
V, Zero);
690 const CallExpr *
E, llvm::Constant *calleeValue) {
691 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF,
E);
699 bool ConstWithoutErrnoAndExceptions =
703 if (ConstWithoutErrnoAndExceptions && CGF.
CGM.
getLangOpts().MathErrno &&
704 !CGF.
Builder.getIsFPConstrained() &&
Call.isScalar()) {
708 Instruction *Inst = cast<llvm::Instruction>(
Call.getScalarVal());
725 const llvm::Intrinsic::ID IntrinsicID,
726 llvm::Value *
X, llvm::Value *Y,
727 llvm::Value *&Carry) {
729 assert(
X->getType() == Y->getType() &&
730 "Arguments must be the same type. (Did you forget to make sure both "
731 "arguments have the same integer width?)");
734 llvm::Value *Tmp = CGF.
Builder.CreateCall(Callee, {
X, Y});
735 Carry = CGF.
Builder.CreateExtractValue(Tmp, 1);
736 return CGF.
Builder.CreateExtractValue(Tmp, 0);
743 llvm::ConstantRange CR(APInt(32, low), APInt(32, high));
744 Call->addRangeRetAttr(CR);
745 Call->addRetAttr(llvm::Attribute::AttrKind::NoUndef);
750 struct WidthAndSignedness {
756static WidthAndSignedness
768static struct WidthAndSignedness
770 assert(Types.size() > 0 &&
"Empty list of types.");
774 for (
const auto &
Type : Types) {
783 for (
const auto &
Type : Types) {
785 if (Width < MinWidth) {
794 Intrinsic::ID inst = IsStart ? Intrinsic::vastart : Intrinsic::vaend;
805 return From == To || (From == 0 && To == 1) || (From == 3 && To == 2);
810 return ConstantInt::get(ResType, (
Type & 2) ? 0 : -1,
true);
814CodeGenFunction::evaluateOrEmitBuiltinObjectSize(
const Expr *
E,
unsigned Type,
815 llvm::IntegerType *ResType,
816 llvm::Value *EmittedE,
820 return emitBuiltinObjectSize(
E,
Type, ResType, EmittedE, IsDynamic);
821 return ConstantInt::get(ResType, ObjectSize,
true);
835 if ((!FAMDecl || FD == FAMDecl) &&
837 Ctx, FD, FD->getType(), StrictFlexArraysLevel,
865 if (FD->getType()->isCountAttributedType())
877CodeGenFunction::emitFlexibleArrayMemberSize(
const Expr *
E,
unsigned Type,
878 llvm::IntegerType *ResType) {
907 const Expr *Idx =
nullptr;
909 if (
const auto *UO = dyn_cast<UnaryOperator>(
Base);
910 UO && UO->getOpcode() == UO_AddrOf) {
912 if (
const auto *ASE = dyn_cast<ArraySubscriptExpr>(SubExpr)) {
913 Base = ASE->getBase()->IgnoreParenImpCasts();
916 if (
const auto *IL = dyn_cast<IntegerLiteral>(Idx)) {
917 int64_t Val = IL->getValue().getSExtValue();
934 if (
const auto *ME = dyn_cast<MemberExpr>(
Base)) {
936 const ValueDecl *VD = ME->getMemberDecl();
938 FAMDecl = dyn_cast<FieldDecl>(VD);
941 }
else if (
const auto *DRE = dyn_cast<DeclRefExpr>(
Base)) {
943 QualType Ty = DRE->getDecl()->getType();
1002 CountedByInst =
Builder.CreateIntCast(CountedByInst, ResType, IsSigned);
1005 Value *IdxInst =
nullptr;
1013 IdxInst =
Builder.CreateIntCast(IdxInst, ResType, IdxSigned);
1018 Builder.CreateSub(CountedByInst, IdxInst,
"", !IsSigned, IsSigned);
1024 llvm::Constant *ElemSize =
1025 llvm::ConstantInt::get(ResType,
Size.getQuantity(), IsSigned);
1027 Builder.CreateMul(CountedByInst, ElemSize,
"", !IsSigned, IsSigned);
1028 FAMSize =
Builder.CreateIntCast(FAMSize, ResType, IsSigned);
1029 Value *Res = FAMSize;
1031 if (isa<DeclRefExpr>(
Base)) {
1036 llvm::Constant *FAMOffset = ConstantInt::get(ResType, Offset, IsSigned);
1037 Value *OffsetAndFAMSize =
1038 Builder.CreateAdd(FAMOffset, Res,
"", !IsSigned, IsSigned);
1041 llvm::Constant *SizeofStruct =
1047 ?
Builder.CreateBinaryIntrinsic(llvm::Intrinsic::smax,
1048 OffsetAndFAMSize, SizeofStruct)
1049 :
Builder.CreateBinaryIntrinsic(llvm::Intrinsic::umax,
1050 OffsetAndFAMSize, SizeofStruct);
1060 return Builder.CreateSelect(Cmp, Res, ConstantInt::get(ResType, 0, IsSigned));
1073CodeGenFunction::emitBuiltinObjectSize(
const Expr *
E,
unsigned Type,
1074 llvm::IntegerType *ResType,
1075 llvm::Value *EmittedE,
bool IsDynamic) {
1079 auto *Param = dyn_cast<ParmVarDecl>(
D->getDecl());
1080 auto *PS =
D->getDecl()->
getAttr<PassObjectSizeAttr>();
1081 if (Param !=
nullptr && PS !=
nullptr &&
1083 auto Iter = SizeArguments.find(Param);
1084 assert(
Iter != SizeArguments.end());
1087 auto DIter = LocalDeclMap.find(
D);
1088 assert(DIter != LocalDeclMap.end());
1098 if (
Value *
V = emitFlexibleArrayMemberSize(
E,
Type, ResType))
1109 assert(Ptr->
getType()->isPointerTy() &&
1110 "Non-pointer passed to __builtin_object_size?");
1126 enum ActionKind : uint8_t { TestOnly, Complement, Reset,
Set };
1127 enum InterlockingKind : uint8_t {
1136 InterlockingKind Interlocking;
1139 static BitTest decodeBitTestBuiltin(
unsigned BuiltinID);
1144BitTest BitTest::decodeBitTestBuiltin(
unsigned BuiltinID) {
1145 switch (BuiltinID) {
1147 case Builtin::BI_bittest:
1148 return {TestOnly, Unlocked,
false};
1149 case Builtin::BI_bittestandcomplement:
1150 return {Complement, Unlocked,
false};
1151 case Builtin::BI_bittestandreset:
1152 return {Reset, Unlocked,
false};
1153 case Builtin::BI_bittestandset:
1154 return {
Set, Unlocked,
false};
1155 case Builtin::BI_interlockedbittestandreset:
1156 return {Reset, Sequential,
false};
1157 case Builtin::BI_interlockedbittestandset:
1158 return {
Set, Sequential,
false};
1161 case Builtin::BI_bittest64:
1162 return {TestOnly, Unlocked,
true};
1163 case Builtin::BI_bittestandcomplement64:
1164 return {Complement, Unlocked,
true};
1165 case Builtin::BI_bittestandreset64:
1166 return {Reset, Unlocked,
true};
1167 case Builtin::BI_bittestandset64:
1168 return {
Set, Unlocked,
true};
1169 case Builtin::BI_interlockedbittestandreset64:
1170 return {Reset, Sequential,
true};
1171 case Builtin::BI_interlockedbittestandset64:
1172 return {
Set, Sequential,
true};
1175 case Builtin::BI_interlockedbittestandset_acq:
1176 return {
Set, Acquire,
false};
1177 case Builtin::BI_interlockedbittestandset_rel:
1178 return {
Set, Release,
false};
1179 case Builtin::BI_interlockedbittestandset_nf:
1180 return {
Set, NoFence,
false};
1181 case Builtin::BI_interlockedbittestandreset_acq:
1182 return {Reset, Acquire,
false};
1183 case Builtin::BI_interlockedbittestandreset_rel:
1184 return {Reset, Release,
false};
1185 case Builtin::BI_interlockedbittestandreset_nf:
1186 return {Reset, NoFence,
false};
1188 llvm_unreachable(
"expected only bittest intrinsics");
1193 case BitTest::TestOnly:
return '\0';
1194 case BitTest::Complement:
return 'c';
1195 case BitTest::Reset:
return 'r';
1196 case BitTest::Set:
return 's';
1198 llvm_unreachable(
"invalid action");
1206 char SizeSuffix = BT.Is64Bit ?
'q' :
'l';
1210 raw_svector_ostream AsmOS(
Asm);
1211 if (BT.Interlocking != BitTest::Unlocked)
1216 AsmOS << SizeSuffix <<
" $2, ($1)";
1219 std::string Constraints =
"={@ccc},r,r,~{cc},~{memory}";
1221 if (!MachineClobbers.empty()) {
1223 Constraints += MachineClobbers;
1225 llvm::IntegerType *IntType = llvm::IntegerType::get(
1228 llvm::FunctionType *FTy =
1229 llvm::FunctionType::get(CGF.
Int8Ty, {CGF.UnqualPtrTy, IntType},
false);
1231 llvm::InlineAsm *IA =
1232 llvm::InlineAsm::get(FTy,
Asm, Constraints,
true);
1233 return CGF.
Builder.CreateCall(IA, {BitBase, BitPos});
1236static llvm::AtomicOrdering
1239 case BitTest::Unlocked:
return llvm::AtomicOrdering::NotAtomic;
1240 case BitTest::Sequential:
return llvm::AtomicOrdering::SequentiallyConsistent;
1241 case BitTest::Acquire:
return llvm::AtomicOrdering::Acquire;
1242 case BitTest::Release:
return llvm::AtomicOrdering::Release;
1243 case BitTest::NoFence:
return llvm::AtomicOrdering::Monotonic;
1245 llvm_unreachable(
"invalid interlocking");
1258 BitTest BT = BitTest::decodeBitTestBuiltin(BuiltinID);
1270 BitPos, llvm::ConstantInt::get(BitPos->
getType(), 3),
"bittest.byteidx");
1273 ByteIndex,
"bittest.byteaddr"),
1277 llvm::ConstantInt::get(CGF.
Int8Ty, 0x7));
1280 Value *Mask =
nullptr;
1281 if (BT.Action != BitTest::TestOnly) {
1282 Mask = CGF.
Builder.CreateShl(llvm::ConstantInt::get(CGF.
Int8Ty, 1), PosLow,
1289 Value *OldByte =
nullptr;
1290 if (Ordering != llvm::AtomicOrdering::NotAtomic) {
1293 llvm::AtomicRMWInst::BinOp RMWOp = llvm::AtomicRMWInst::Or;
1294 if (BT.Action == BitTest::Reset) {
1295 Mask = CGF.
Builder.CreateNot(Mask);
1296 RMWOp = llvm::AtomicRMWInst::And;
1302 Value *NewByte =
nullptr;
1303 switch (BT.Action) {
1304 case BitTest::TestOnly:
1307 case BitTest::Complement:
1308 NewByte = CGF.
Builder.CreateXor(OldByte, Mask);
1310 case BitTest::Reset:
1311 NewByte = CGF.
Builder.CreateAnd(OldByte, CGF.
Builder.CreateNot(Mask));
1314 NewByte = CGF.
Builder.CreateOr(OldByte, Mask);
1323 Value *ShiftedByte = CGF.
Builder.CreateLShr(OldByte, PosLow,
"bittest.shr");
1325 ShiftedByte, llvm::ConstantInt::get(CGF.
Int8Ty, 1),
"bittest.res");
1334 raw_svector_ostream AsmOS(
Asm);
1335 llvm::IntegerType *RetType = CGF.
Int32Ty;
1337 switch (BuiltinID) {
1338 case clang::PPC::BI__builtin_ppc_ldarx:
1342 case clang::PPC::BI__builtin_ppc_lwarx:
1346 case clang::PPC::BI__builtin_ppc_lharx:
1350 case clang::PPC::BI__builtin_ppc_lbarx:
1355 llvm_unreachable(
"Expected only PowerPC load reserve intrinsics");
1358 AsmOS <<
"$0, ${1:y}";
1360 std::string Constraints =
"=r,*Z,~{memory}";
1362 if (!MachineClobbers.empty()) {
1364 Constraints += MachineClobbers;
1368 llvm::FunctionType *FTy = llvm::FunctionType::get(RetType, {PtrType},
false);
1370 llvm::InlineAsm *IA =
1371 llvm::InlineAsm::get(FTy,
Asm, Constraints,
true);
1372 llvm::CallInst *CI = CGF.
Builder.CreateCall(IA, {Addr});
1374 0, Attribute::get(CGF.
getLLVMContext(), Attribute::ElementType, RetType));
1379enum class MSVCSetJmpKind {
1391 llvm::Value *Arg1 =
nullptr;
1392 llvm::Type *Arg1Ty =
nullptr;
1394 bool IsVarArg =
false;
1395 if (SJKind == MSVCSetJmpKind::_setjmp3) {
1398 Arg1 = llvm::ConstantInt::get(CGF.
IntTy, 0);
1401 Name = SJKind == MSVCSetJmpKind::_setjmp ?
"_setjmp" :
"_setjmpex";
1404 Arg1 = CGF.
Builder.CreateCall(
1407 Arg1 = CGF.
Builder.CreateCall(
1409 llvm::ConstantInt::get(CGF.
Int32Ty, 0));
1413 llvm::Type *ArgTypes[2] = {CGF.
Int8PtrTy, Arg1Ty};
1414 llvm::AttributeList ReturnsTwiceAttr = llvm::AttributeList::get(
1416 llvm::Attribute::ReturnsTwice);
1418 llvm::FunctionType::get(CGF.
IntTy, ArgTypes, IsVarArg), Name,
1419 ReturnsTwiceAttr,
true);
1421 llvm::Value *Buf = CGF.
Builder.CreateBitOrPointerCast(
1423 llvm::Value *Args[] = {Buf, Arg1};
1425 CB->setAttributes(ReturnsTwiceAttr);
1473static std::optional<CodeGenFunction::MSVCIntrin>
1476 switch (BuiltinID) {
1478 return std::nullopt;
1479 case clang::ARM::BI_BitScanForward:
1480 case clang::ARM::BI_BitScanForward64:
1481 return MSVCIntrin::_BitScanForward;
1482 case clang::ARM::BI_BitScanReverse:
1483 case clang::ARM::BI_BitScanReverse64:
1484 return MSVCIntrin::_BitScanReverse;
1485 case clang::ARM::BI_InterlockedAnd64:
1486 return MSVCIntrin::_InterlockedAnd;
1487 case clang::ARM::BI_InterlockedExchange64:
1488 return MSVCIntrin::_InterlockedExchange;
1489 case clang::ARM::BI_InterlockedExchangeAdd64:
1490 return MSVCIntrin::_InterlockedExchangeAdd;
1491 case clang::ARM::BI_InterlockedExchangeSub64:
1492 return MSVCIntrin::_InterlockedExchangeSub;
1493 case clang::ARM::BI_InterlockedOr64:
1494 return MSVCIntrin::_InterlockedOr;
1495 case clang::ARM::BI_InterlockedXor64:
1496 return MSVCIntrin::_InterlockedXor;
1497 case clang::ARM::BI_InterlockedDecrement64:
1498 return MSVCIntrin::_InterlockedDecrement;
1499 case clang::ARM::BI_InterlockedIncrement64:
1500 return MSVCIntrin::_InterlockedIncrement;
1501 case clang::ARM::BI_InterlockedExchangeAdd8_acq:
1502 case clang::ARM::BI_InterlockedExchangeAdd16_acq:
1503 case clang::ARM::BI_InterlockedExchangeAdd_acq:
1504 case clang::ARM::BI_InterlockedExchangeAdd64_acq:
1505 return MSVCIntrin::_InterlockedExchangeAdd_acq;
1506 case clang::ARM::BI_InterlockedExchangeAdd8_rel:
1507 case clang::ARM::BI_InterlockedExchangeAdd16_rel:
1508 case clang::ARM::BI_InterlockedExchangeAdd_rel:
1509 case clang::ARM::BI_InterlockedExchangeAdd64_rel:
1510 return MSVCIntrin::_InterlockedExchangeAdd_rel;
1511 case clang::ARM::BI_InterlockedExchangeAdd8_nf:
1512 case clang::ARM::BI_InterlockedExchangeAdd16_nf:
1513 case clang::ARM::BI_InterlockedExchangeAdd_nf:
1514 case clang::ARM::BI_InterlockedExchangeAdd64_nf:
1515 return MSVCIntrin::_InterlockedExchangeAdd_nf;
1516 case clang::ARM::BI_InterlockedExchange8_acq:
1517 case clang::ARM::BI_InterlockedExchange16_acq:
1518 case clang::ARM::BI_InterlockedExchange_acq:
1519 case clang::ARM::BI_InterlockedExchange64_acq:
1520 return MSVCIntrin::_InterlockedExchange_acq;
1521 case clang::ARM::BI_InterlockedExchange8_rel:
1522 case clang::ARM::BI_InterlockedExchange16_rel:
1523 case clang::ARM::BI_InterlockedExchange_rel:
1524 case clang::ARM::BI_InterlockedExchange64_rel:
1525 return MSVCIntrin::_InterlockedExchange_rel;
1526 case clang::ARM::BI_InterlockedExchange8_nf:
1527 case clang::ARM::BI_InterlockedExchange16_nf:
1528 case clang::ARM::BI_InterlockedExchange_nf:
1529 case clang::ARM::BI_InterlockedExchange64_nf:
1530 return MSVCIntrin::_InterlockedExchange_nf;
1531 case clang::ARM::BI_InterlockedCompareExchange8_acq:
1532 case clang::ARM::BI_InterlockedCompareExchange16_acq:
1533 case clang::ARM::BI_InterlockedCompareExchange_acq:
1534 case clang::ARM::BI_InterlockedCompareExchange64_acq:
1535 return MSVCIntrin::_InterlockedCompareExchange_acq;
1536 case clang::ARM::BI_InterlockedCompareExchange8_rel:
1537 case clang::ARM::BI_InterlockedCompareExchange16_rel:
1538 case clang::ARM::BI_InterlockedCompareExchange_rel:
1539 case clang::ARM::BI_InterlockedCompareExchange64_rel:
1540 return MSVCIntrin::_InterlockedCompareExchange_rel;
1541 case clang::ARM::BI_InterlockedCompareExchange8_nf:
1542 case clang::ARM::BI_InterlockedCompareExchange16_nf:
1543 case clang::ARM::BI_InterlockedCompareExchange_nf:
1544 case clang::ARM::BI_InterlockedCompareExchange64_nf:
1545 return MSVCIntrin::_InterlockedCompareExchange_nf;
1546 case clang::ARM::BI_InterlockedOr8_acq:
1547 case clang::ARM::BI_InterlockedOr16_acq:
1548 case clang::ARM::BI_InterlockedOr_acq:
1549 case clang::ARM::BI_InterlockedOr64_acq:
1550 return MSVCIntrin::_InterlockedOr_acq;
1551 case clang::ARM::BI_InterlockedOr8_rel:
1552 case clang::ARM::BI_InterlockedOr16_rel:
1553 case clang::ARM::BI_InterlockedOr_rel:
1554 case clang::ARM::BI_InterlockedOr64_rel:
1555 return MSVCIntrin::_InterlockedOr_rel;
1556 case clang::ARM::BI_InterlockedOr8_nf:
1557 case clang::ARM::BI_InterlockedOr16_nf:
1558 case clang::ARM::BI_InterlockedOr_nf:
1559 case clang::ARM::BI_InterlockedOr64_nf:
1560 return MSVCIntrin::_InterlockedOr_nf;
1561 case clang::ARM::BI_InterlockedXor8_acq:
1562 case clang::ARM::BI_InterlockedXor16_acq:
1563 case clang::ARM::BI_InterlockedXor_acq:
1564 case clang::ARM::BI_InterlockedXor64_acq:
1565 return MSVCIntrin::_InterlockedXor_acq;
1566 case clang::ARM::BI_InterlockedXor8_rel:
1567 case clang::ARM::BI_InterlockedXor16_rel:
1568 case clang::ARM::BI_InterlockedXor_rel:
1569 case clang::ARM::BI_InterlockedXor64_rel:
1570 return MSVCIntrin::_InterlockedXor_rel;
1571 case clang::ARM::BI_InterlockedXor8_nf:
1572 case clang::ARM::BI_InterlockedXor16_nf:
1573 case clang::ARM::BI_InterlockedXor_nf:
1574 case clang::ARM::BI_InterlockedXor64_nf:
1575 return MSVCIntrin::_InterlockedXor_nf;
1576 case clang::ARM::BI_InterlockedAnd8_acq:
1577 case clang::ARM::BI_InterlockedAnd16_acq:
1578 case clang::ARM::BI_InterlockedAnd_acq:
1579 case clang::ARM::BI_InterlockedAnd64_acq:
1580 return MSVCIntrin::_InterlockedAnd_acq;
1581 case clang::ARM::BI_InterlockedAnd8_rel:
1582 case clang::ARM::BI_InterlockedAnd16_rel:
1583 case clang::ARM::BI_InterlockedAnd_rel:
1584 case clang::ARM::BI_InterlockedAnd64_rel:
1585 return MSVCIntrin::_InterlockedAnd_rel;
1586 case clang::ARM::BI_InterlockedAnd8_nf:
1587 case clang::ARM::BI_InterlockedAnd16_nf:
1588 case clang::ARM::BI_InterlockedAnd_nf:
1589 case clang::ARM::BI_InterlockedAnd64_nf:
1590 return MSVCIntrin::_InterlockedAnd_nf;
1591 case clang::ARM::BI_InterlockedIncrement16_acq:
1592 case clang::ARM::BI_InterlockedIncrement_acq:
1593 case clang::ARM::BI_InterlockedIncrement64_acq:
1594 return MSVCIntrin::_InterlockedIncrement_acq;
1595 case clang::ARM::BI_InterlockedIncrement16_rel:
1596 case clang::ARM::BI_InterlockedIncrement_rel:
1597 case clang::ARM::BI_InterlockedIncrement64_rel:
1598 return MSVCIntrin::_InterlockedIncrement_rel;
1599 case clang::ARM::BI_InterlockedIncrement16_nf:
1600 case clang::ARM::BI_InterlockedIncrement_nf:
1601 case clang::ARM::BI_InterlockedIncrement64_nf:
1602 return MSVCIntrin::_InterlockedIncrement_nf;
1603 case clang::ARM::BI_InterlockedDecrement16_acq:
1604 case clang::ARM::BI_InterlockedDecrement_acq:
1605 case clang::ARM::BI_InterlockedDecrement64_acq:
1606 return MSVCIntrin::_InterlockedDecrement_acq;
1607 case clang::ARM::BI_InterlockedDecrement16_rel:
1608 case clang::ARM::BI_InterlockedDecrement_rel:
1609 case clang::ARM::BI_InterlockedDecrement64_rel:
1610 return MSVCIntrin::_InterlockedDecrement_rel;
1611 case clang::ARM::BI_InterlockedDecrement16_nf:
1612 case clang::ARM::BI_InterlockedDecrement_nf:
1613 case clang::ARM::BI_InterlockedDecrement64_nf:
1614 return MSVCIntrin::_InterlockedDecrement_nf;
1616 llvm_unreachable(
"must return from switch");
1619static std::optional<CodeGenFunction::MSVCIntrin>
1622 switch (BuiltinID) {
1624 return std::nullopt;
1625 case clang::AArch64::BI_BitScanForward:
1626 case clang::AArch64::BI_BitScanForward64:
1627 return MSVCIntrin::_BitScanForward;
1628 case clang::AArch64::BI_BitScanReverse:
1629 case clang::AArch64::BI_BitScanReverse64:
1630 return MSVCIntrin::_BitScanReverse;
1631 case clang::AArch64::BI_InterlockedAnd64:
1632 return MSVCIntrin::_InterlockedAnd;
1633 case clang::AArch64::BI_InterlockedExchange64:
1634 return MSVCIntrin::_InterlockedExchange;
1635 case clang::AArch64::BI_InterlockedExchangeAdd64:
1636 return MSVCIntrin::_InterlockedExchangeAdd;
1637 case clang::AArch64::BI_InterlockedExchangeSub64:
1638 return MSVCIntrin::_InterlockedExchangeSub;
1639 case clang::AArch64::BI_InterlockedOr64:
1640 return MSVCIntrin::_InterlockedOr;
1641 case clang::AArch64::BI_InterlockedXor64:
1642 return MSVCIntrin::_InterlockedXor;
1643 case clang::AArch64::BI_InterlockedDecrement64:
1644 return MSVCIntrin::_InterlockedDecrement;
1645 case clang::AArch64::BI_InterlockedIncrement64:
1646 return MSVCIntrin::_InterlockedIncrement;
1647 case clang::AArch64::BI_InterlockedExchangeAdd8_acq:
1648 case clang::AArch64::BI_InterlockedExchangeAdd16_acq:
1649 case clang::AArch64::BI_InterlockedExchangeAdd_acq:
1650 case clang::AArch64::BI_InterlockedExchangeAdd64_acq:
1651 return MSVCIntrin::_InterlockedExchangeAdd_acq;
1652 case clang::AArch64::BI_InterlockedExchangeAdd8_rel:
1653 case clang::AArch64::BI_InterlockedExchangeAdd16_rel:
1654 case clang::AArch64::BI_InterlockedExchangeAdd_rel:
1655 case clang::AArch64::BI_InterlockedExchangeAdd64_rel:
1656 return MSVCIntrin::_InterlockedExchangeAdd_rel;
1657 case clang::AArch64::BI_InterlockedExchangeAdd8_nf:
1658 case clang::AArch64::BI_InterlockedExchangeAdd16_nf:
1659 case clang::AArch64::BI_InterlockedExchangeAdd_nf:
1660 case clang::AArch64::BI_InterlockedExchangeAdd64_nf:
1661 return MSVCIntrin::_InterlockedExchangeAdd_nf;
1662 case clang::AArch64::BI_InterlockedExchange8_acq:
1663 case clang::AArch64::BI_InterlockedExchange16_acq:
1664 case clang::AArch64::BI_InterlockedExchange_acq:
1665 case clang::AArch64::BI_InterlockedExchange64_acq:
1666 return MSVCIntrin::_InterlockedExchange_acq;
1667 case clang::AArch64::BI_InterlockedExchange8_rel:
1668 case clang::AArch64::BI_InterlockedExchange16_rel:
1669 case clang::AArch64::BI_InterlockedExchange_rel:
1670 case clang::AArch64::BI_InterlockedExchange64_rel:
1671 return MSVCIntrin::_InterlockedExchange_rel;
1672 case clang::AArch64::BI_InterlockedExchange8_nf:
1673 case clang::AArch64::BI_InterlockedExchange16_nf:
1674 case clang::AArch64::BI_InterlockedExchange_nf:
1675 case clang::AArch64::BI_InterlockedExchange64_nf:
1676 return MSVCIntrin::_InterlockedExchange_nf;
1677 case clang::AArch64::BI_InterlockedCompareExchange8_acq:
1678 case clang::AArch64::BI_InterlockedCompareExchange16_acq:
1679 case clang::AArch64::BI_InterlockedCompareExchange_acq:
1680 case clang::AArch64::BI_InterlockedCompareExchange64_acq:
1681 return MSVCIntrin::_InterlockedCompareExchange_acq;
1682 case clang::AArch64::BI_InterlockedCompareExchange8_rel:
1683 case clang::AArch64::BI_InterlockedCompareExchange16_rel:
1684 case clang::AArch64::BI_InterlockedCompareExchange_rel:
1685 case clang::AArch64::BI_InterlockedCompareExchange64_rel:
1686 return MSVCIntrin::_InterlockedCompareExchange_rel;
1687 case clang::AArch64::BI_InterlockedCompareExchange8_nf:
1688 case clang::AArch64::BI_InterlockedCompareExchange16_nf:
1689 case clang::AArch64::BI_InterlockedCompareExchange_nf:
1690 case clang::AArch64::BI_InterlockedCompareExchange64_nf:
1691 return MSVCIntrin::_InterlockedCompareExchange_nf;
1692 case clang::AArch64::BI_InterlockedCompareExchange128:
1693 return MSVCIntrin::_InterlockedCompareExchange128;
1694 case clang::AArch64::BI_InterlockedCompareExchange128_acq:
1695 return MSVCIntrin::_InterlockedCompareExchange128_acq;
1696 case clang::AArch64::BI_InterlockedCompareExchange128_nf:
1697 return MSVCIntrin::_InterlockedCompareExchange128_nf;
1698 case clang::AArch64::BI_InterlockedCompareExchange128_rel:
1699 return MSVCIntrin::_InterlockedCompareExchange128_rel;
1700 case clang::AArch64::BI_InterlockedOr8_acq:
1701 case clang::AArch64::BI_InterlockedOr16_acq:
1702 case clang::AArch64::BI_InterlockedOr_acq:
1703 case clang::AArch64::BI_InterlockedOr64_acq:
1704 return MSVCIntrin::_InterlockedOr_acq;
1705 case clang::AArch64::BI_InterlockedOr8_rel:
1706 case clang::AArch64::BI_InterlockedOr16_rel:
1707 case clang::AArch64::BI_InterlockedOr_rel:
1708 case clang::AArch64::BI_InterlockedOr64_rel:
1709 return MSVCIntrin::_InterlockedOr_rel;
1710 case clang::AArch64::BI_InterlockedOr8_nf:
1711 case clang::AArch64::BI_InterlockedOr16_nf:
1712 case clang::AArch64::BI_InterlockedOr_nf:
1713 case clang::AArch64::BI_InterlockedOr64_nf:
1714 return MSVCIntrin::_InterlockedOr_nf;
1715 case clang::AArch64::BI_InterlockedXor8_acq:
1716 case clang::AArch64::BI_InterlockedXor16_acq:
1717 case clang::AArch64::BI_InterlockedXor_acq:
1718 case clang::AArch64::BI_InterlockedXor64_acq:
1719 return MSVCIntrin::_InterlockedXor_acq;
1720 case clang::AArch64::BI_InterlockedXor8_rel:
1721 case clang::AArch64::BI_InterlockedXor16_rel:
1722 case clang::AArch64::BI_InterlockedXor_rel:
1723 case clang::AArch64::BI_InterlockedXor64_rel:
1724 return MSVCIntrin::_InterlockedXor_rel;
1725 case clang::AArch64::BI_InterlockedXor8_nf:
1726 case clang::AArch64::BI_InterlockedXor16_nf:
1727 case clang::AArch64::BI_InterlockedXor_nf:
1728 case clang::AArch64::BI_InterlockedXor64_nf:
1729 return MSVCIntrin::_InterlockedXor_nf;
1730 case clang::AArch64::BI_InterlockedAnd8_acq:
1731 case clang::AArch64::BI_InterlockedAnd16_acq:
1732 case clang::AArch64::BI_InterlockedAnd_acq:
1733 case clang::AArch64::BI_InterlockedAnd64_acq:
1734 return MSVCIntrin::_InterlockedAnd_acq;
1735 case clang::AArch64::BI_InterlockedAnd8_rel:
1736 case clang::AArch64::BI_InterlockedAnd16_rel:
1737 case clang::AArch64::BI_InterlockedAnd_rel:
1738 case clang::AArch64::BI_InterlockedAnd64_rel:
1739 return MSVCIntrin::_InterlockedAnd_rel;
1740 case clang::AArch64::BI_InterlockedAnd8_nf:
1741 case clang::AArch64::BI_InterlockedAnd16_nf:
1742 case clang::AArch64::BI_InterlockedAnd_nf:
1743 case clang::AArch64::BI_InterlockedAnd64_nf:
1744 return MSVCIntrin::_InterlockedAnd_nf;
1745 case clang::AArch64::BI_InterlockedIncrement16_acq:
1746 case clang::AArch64::BI_InterlockedIncrement_acq:
1747 case clang::AArch64::BI_InterlockedIncrement64_acq:
1748 return MSVCIntrin::_InterlockedIncrement_acq;
1749 case clang::AArch64::BI_InterlockedIncrement16_rel:
1750 case clang::AArch64::BI_InterlockedIncrement_rel:
1751 case clang::AArch64::BI_InterlockedIncrement64_rel:
1752 return MSVCIntrin::_InterlockedIncrement_rel;
1753 case clang::AArch64::BI_InterlockedIncrement16_nf:
1754 case clang::AArch64::BI_InterlockedIncrement_nf:
1755 case clang::AArch64::BI_InterlockedIncrement64_nf:
1756 return MSVCIntrin::_InterlockedIncrement_nf;
1757 case clang::AArch64::BI_InterlockedDecrement16_acq:
1758 case clang::AArch64::BI_InterlockedDecrement_acq:
1759 case clang::AArch64::BI_InterlockedDecrement64_acq:
1760 return MSVCIntrin::_InterlockedDecrement_acq;
1761 case clang::AArch64::BI_InterlockedDecrement16_rel:
1762 case clang::AArch64::BI_InterlockedDecrement_rel:
1763 case clang::AArch64::BI_InterlockedDecrement64_rel:
1764 return MSVCIntrin::_InterlockedDecrement_rel;
1765 case clang::AArch64::BI_InterlockedDecrement16_nf:
1766 case clang::AArch64::BI_InterlockedDecrement_nf:
1767 case clang::AArch64::BI_InterlockedDecrement64_nf:
1768 return MSVCIntrin::_InterlockedDecrement_nf;
1770 llvm_unreachable(
"must return from switch");
1773static std::optional<CodeGenFunction::MSVCIntrin>
1776 switch (BuiltinID) {
1778 return std::nullopt;
1779 case clang::X86::BI_BitScanForward:
1780 case clang::X86::BI_BitScanForward64:
1781 return MSVCIntrin::_BitScanForward;
1782 case clang::X86::BI_BitScanReverse:
1783 case clang::X86::BI_BitScanReverse64:
1784 return MSVCIntrin::_BitScanReverse;
1785 case clang::X86::BI_InterlockedAnd64:
1786 return MSVCIntrin::_InterlockedAnd;
1787 case clang::X86::BI_InterlockedCompareExchange128:
1788 return MSVCIntrin::_InterlockedCompareExchange128;
1789 case clang::X86::BI_InterlockedExchange64:
1790 return MSVCIntrin::_InterlockedExchange;
1791 case clang::X86::BI_InterlockedExchangeAdd64:
1792 return MSVCIntrin::_InterlockedExchangeAdd;
1793 case clang::X86::BI_InterlockedExchangeSub64:
1794 return MSVCIntrin::_InterlockedExchangeSub;
1795 case clang::X86::BI_InterlockedOr64:
1796 return MSVCIntrin::_InterlockedOr;
1797 case clang::X86::BI_InterlockedXor64:
1798 return MSVCIntrin::_InterlockedXor;
1799 case clang::X86::BI_InterlockedDecrement64:
1800 return MSVCIntrin::_InterlockedDecrement;
1801 case clang::X86::BI_InterlockedIncrement64:
1802 return MSVCIntrin::_InterlockedIncrement;
1804 llvm_unreachable(
"must return from switch");
1810 switch (BuiltinID) {
1811 case MSVCIntrin::_BitScanForward:
1812 case MSVCIntrin::_BitScanReverse: {
1816 llvm::Type *ArgType = ArgValue->
getType();
1817 llvm::Type *IndexType = IndexAddress.getElementType();
1820 Value *ArgZero = llvm::Constant::getNullValue(ArgType);
1821 Value *ResZero = llvm::Constant::getNullValue(ResultType);
1822 Value *ResOne = llvm::ConstantInt::get(ResultType, 1);
1827 PHINode *
Result =
Builder.CreatePHI(ResultType, 2,
"bitscan_result");
1830 Value *IsZero =
Builder.CreateICmpEQ(ArgValue, ArgZero);
1832 Builder.CreateCondBr(IsZero, End, NotZero);
1835 Builder.SetInsertPoint(NotZero);
1837 if (BuiltinID == MSVCIntrin::_BitScanForward) {
1840 ZeroCount =
Builder.CreateIntCast(ZeroCount, IndexType,
false);
1843 unsigned ArgWidth = cast<llvm::IntegerType>(ArgType)->getBitWidth();
1844 Value *ArgTypeLastIndex = llvm::ConstantInt::get(IndexType, ArgWidth - 1);
1848 ZeroCount =
Builder.CreateIntCast(ZeroCount, IndexType,
false);
1849 Value *Index =
Builder.CreateNSWSub(ArgTypeLastIndex, ZeroCount);
1853 Result->addIncoming(ResOne, NotZero);
1858 case MSVCIntrin::_InterlockedAnd:
1860 case MSVCIntrin::_InterlockedExchange:
1862 case MSVCIntrin::_InterlockedExchangeAdd:
1864 case MSVCIntrin::_InterlockedExchangeSub:
1866 case MSVCIntrin::_InterlockedOr:
1868 case MSVCIntrin::_InterlockedXor:
1870 case MSVCIntrin::_InterlockedExchangeAdd_acq:
1872 AtomicOrdering::Acquire);
1873 case MSVCIntrin::_InterlockedExchangeAdd_rel:
1875 AtomicOrdering::Release);
1876 case MSVCIntrin::_InterlockedExchangeAdd_nf:
1878 AtomicOrdering::Monotonic);
1879 case MSVCIntrin::_InterlockedExchange_acq:
1881 AtomicOrdering::Acquire);
1882 case MSVCIntrin::_InterlockedExchange_rel:
1884 AtomicOrdering::Release);
1885 case MSVCIntrin::_InterlockedExchange_nf:
1887 AtomicOrdering::Monotonic);
1888 case MSVCIntrin::_InterlockedCompareExchange_acq:
1890 case MSVCIntrin::_InterlockedCompareExchange_rel:
1892 case MSVCIntrin::_InterlockedCompareExchange_nf:
1894 case MSVCIntrin::_InterlockedCompareExchange128:
1896 *
this,
E, AtomicOrdering::SequentiallyConsistent);
1897 case MSVCIntrin::_InterlockedCompareExchange128_acq:
1899 case MSVCIntrin::_InterlockedCompareExchange128_rel:
1901 case MSVCIntrin::_InterlockedCompareExchange128_nf:
1903 case MSVCIntrin::_InterlockedOr_acq:
1905 AtomicOrdering::Acquire);
1906 case MSVCIntrin::_InterlockedOr_rel:
1908 AtomicOrdering::Release);
1909 case MSVCIntrin::_InterlockedOr_nf:
1911 AtomicOrdering::Monotonic);
1912 case MSVCIntrin::_InterlockedXor_acq:
1914 AtomicOrdering::Acquire);
1915 case MSVCIntrin::_InterlockedXor_rel:
1917 AtomicOrdering::Release);
1918 case MSVCIntrin::_InterlockedXor_nf:
1920 AtomicOrdering::Monotonic);
1921 case MSVCIntrin::_InterlockedAnd_acq:
1923 AtomicOrdering::Acquire);
1924 case MSVCIntrin::_InterlockedAnd_rel:
1926 AtomicOrdering::Release);
1927 case MSVCIntrin::_InterlockedAnd_nf:
1929 AtomicOrdering::Monotonic);
1930 case MSVCIntrin::_InterlockedIncrement_acq:
1932 case MSVCIntrin::_InterlockedIncrement_rel:
1934 case MSVCIntrin::_InterlockedIncrement_nf:
1936 case MSVCIntrin::_InterlockedDecrement_acq:
1938 case MSVCIntrin::_InterlockedDecrement_rel:
1940 case MSVCIntrin::_InterlockedDecrement_nf:
1943 case MSVCIntrin::_InterlockedDecrement:
1945 case MSVCIntrin::_InterlockedIncrement:
1948 case MSVCIntrin::__fastfail: {
1953 StringRef
Asm, Constraints;
1958 case llvm::Triple::x86:
1959 case llvm::Triple::x86_64:
1961 Constraints =
"{cx}";
1963 case llvm::Triple::thumb:
1965 Constraints =
"{r0}";
1967 case llvm::Triple::aarch64:
1968 Asm =
"brk #0xF003";
1969 Constraints =
"{w0}";
1971 llvm::FunctionType *FTy = llvm::FunctionType::get(
VoidTy, {
Int32Ty},
false);
1972 llvm::InlineAsm *IA =
1973 llvm::InlineAsm::get(FTy,
Asm, Constraints,
true);
1974 llvm::AttributeList NoReturnAttr = llvm::AttributeList::get(
1976 llvm::Attribute::NoReturn);
1978 CI->setAttributes(NoReturnAttr);
1982 llvm_unreachable(
"Incorrect MSVC intrinsic!");
1988 CallObjCArcUse(llvm::Value *
object) : object(object) {}
1989 llvm::Value *object;
1998 BuiltinCheckKind Kind) {
2000 &&
"Unsupported builtin check kind");
2006 SanitizerScope SanScope(
this);
2008 ArgValue, llvm::Constant::getNullValue(ArgValue->
getType()));
2009 EmitCheck(std::make_pair(Cond, SanitizerKind::Builtin),
2010 SanitizerHandler::InvalidBuiltin,
2012 llvm::ConstantInt::get(
Builder.getInt8Ty(), Kind)},
2018 return CGF.
Builder.CreateBinaryIntrinsic(
2019 Intrinsic::abs, ArgValue,
2020 ConstantInt::get(CGF.
Builder.getInt1Ty(), HasNSW));
2024 bool SanitizeOverflow) {
2028 if (
const auto *VCI = dyn_cast<llvm::ConstantInt>(ArgValue)) {
2029 if (!VCI->isMinSignedValue())
2030 return EmitAbs(CGF, ArgValue,
true);
2033 CodeGenFunction::SanitizerScope SanScope(&CGF);
2035 Constant *Zero = Constant::getNullValue(ArgValue->
getType());
2036 Value *ResultAndOverflow = CGF.
Builder.CreateBinaryIntrinsic(
2037 Intrinsic::ssub_with_overflow, Zero, ArgValue);
2040 CGF.
Builder.CreateExtractValue(ResultAndOverflow, 1));
2043 if (SanitizeOverflow) {
2044 CGF.
EmitCheck({{NotOverflow, SanitizerKind::SignedIntegerOverflow}},
2045 SanitizerHandler::NegateOverflow,
2050 CGF.
EmitTrapCheck(NotOverflow, SanitizerHandler::SubOverflow);
2052 Value *CmpResult = CGF.
Builder.CreateICmpSLT(ArgValue, Zero,
"abscond");
2053 return CGF.
Builder.CreateSelect(CmpResult,
Result, ArgValue,
"abs");
2058 QualType UnsignedTy =
C.getIntTypeForBitwidth(Size * 8,
false);
2059 return C.getCanonicalType(UnsignedTy);
2069 raw_svector_ostream OS(Name);
2070 OS <<
"__os_log_helper";
2074 for (
const auto &Item : Layout.
Items)
2075 OS <<
"_" <<
int(Item.getSizeByte()) <<
"_"
2076 <<
int(Item.getDescriptorByte());
2079 if (llvm::Function *F =
CGM.
getModule().getFunction(Name))
2089 for (
unsigned int I = 0,
E = Layout.
Items.size(); I <
E; ++I) {
2090 char Size = Layout.
Items[I].getSizeByte();
2097 &Ctx.
Idents.
get(std::string(
"arg") + llvm::to_string(I)), ArgTy,
2099 ArgTys.emplace_back(ArgTy);
2110 llvm::Function *
Fn = llvm::Function::Create(
2111 FuncTy, llvm::GlobalValue::LinkOnceODRLinkage, Name, &
CGM.
getModule());
2112 Fn->setVisibility(llvm::GlobalValue::HiddenVisibility);
2115 Fn->setDoesNotThrow();
2119 Fn->addFnAttr(llvm::Attribute::NoInline);
2137 for (
const auto &Item : Layout.
Items) {
2139 Builder.getInt8(Item.getDescriptorByte()),
2142 Builder.getInt8(Item.getSizeByte()),
2146 if (!
Size.getQuantity())
2163 assert(
E.getNumArgs() >= 2 &&
2164 "__builtin_os_log_format takes at least 2 arguments");
2175 for (
const auto &Item : Layout.
Items) {
2176 int Size = Item.getSizeByte();
2180 llvm::Value *ArgVal;
2184 for (
unsigned I = 0,
E = Item.getMaskType().size(); I <
E; ++I)
2185 Val |= ((
uint64_t)Item.getMaskType()[I]) << I * 8;
2186 ArgVal = llvm::Constant::getIntegerValue(
Int64Ty, llvm::APInt(64, Val));
2187 }
else if (
const Expr *TheExpr = Item.getExpr()) {
2193 auto LifetimeExtendObject = [&](
const Expr *
E) {
2201 if (isa<CallExpr>(
E) || isa<ObjCMessageExpr>(
E))
2206 if (TheExpr->getType()->isObjCRetainableType() &&
2207 getLangOpts().ObjCAutoRefCount && LifetimeExtendObject(TheExpr)) {
2209 "Only scalar can be a ObjC retainable type");
2210 if (!isa<Constant>(ArgVal)) {
2224 pushCleanupAfterFullExpr<CallObjCArcUse>(Cleanup, ArgVal);
2228 ArgVal =
Builder.getInt32(Item.getConstValue().getQuantity());
2231 unsigned ArgValSize =
2235 ArgVal =
Builder.CreateBitOrPointerCast(ArgVal,
IntTy);
2251 unsigned BuiltinID, WidthAndSignedness Op1Info, WidthAndSignedness Op2Info,
2252 WidthAndSignedness ResultInfo) {
2253 return BuiltinID == Builtin::BI__builtin_mul_overflow &&
2254 Op1Info.Width == Op2Info.Width && Op2Info.Width == ResultInfo.Width &&
2255 !Op1Info.Signed && !Op2Info.Signed && ResultInfo.Signed;
2260 const clang::Expr *Op2, WidthAndSignedness Op2Info,
2262 WidthAndSignedness ResultInfo) {
2264 Builtin::BI__builtin_mul_overflow, Op1Info, Op2Info, ResultInfo) &&
2265 "Cannot specialize this multiply");
2270 llvm::Value *HasOverflow;
2272 CGF, llvm::Intrinsic::umul_with_overflow, V1, V2, HasOverflow);
2277 auto IntMax = llvm::APInt::getSignedMaxValue(ResultInfo.Width);
2278 llvm::Value *IntMaxValue = llvm::ConstantInt::get(
Result->getType(), IntMax);
2280 llvm::Value *IntMaxOverflow = CGF.
Builder.CreateICmpUGT(
Result, IntMaxValue);
2281 HasOverflow = CGF.
Builder.CreateOr(HasOverflow, IntMaxOverflow);
2293 WidthAndSignedness Op1Info,
2294 WidthAndSignedness Op2Info,
2295 WidthAndSignedness ResultInfo) {
2296 return BuiltinID == Builtin::BI__builtin_mul_overflow &&
2297 std::max(Op1Info.Width, Op2Info.Width) >= ResultInfo.Width &&
2298 Op1Info.Signed != Op2Info.Signed;
2305 WidthAndSignedness Op1Info,
const clang::Expr *Op2,
2306 WidthAndSignedness Op2Info,
2308 WidthAndSignedness ResultInfo) {
2310 Op2Info, ResultInfo) &&
2311 "Not a mixed-sign multipliction we can specialize");
2314 const clang::Expr *SignedOp = Op1Info.Signed ? Op1 : Op2;
2315 const clang::Expr *UnsignedOp = Op1Info.Signed ? Op2 : Op1;
2318 unsigned SignedOpWidth = Op1Info.Signed ? Op1Info.Width : Op2Info.Width;
2319 unsigned UnsignedOpWidth = Op1Info.Signed ? Op2Info.Width : Op1Info.Width;
2322 if (SignedOpWidth < UnsignedOpWidth)
2324 if (UnsignedOpWidth < SignedOpWidth)
2327 llvm::Type *OpTy =
Signed->getType();
2328 llvm::Value *Zero = llvm::Constant::getNullValue(OpTy);
2331 unsigned OpWidth = std::max(Op1Info.Width, Op2Info.Width);
2334 llvm::Value *IsNegative = CGF.
Builder.CreateICmpSLT(
Signed, Zero);
2335 llvm::Value *AbsOfNegative = CGF.
Builder.CreateSub(Zero,
Signed);
2336 llvm::Value *AbsSigned =
2337 CGF.
Builder.CreateSelect(IsNegative, AbsOfNegative,
Signed);
2340 llvm::Value *UnsignedOverflow;
2341 llvm::Value *UnsignedResult =
2345 llvm::Value *Overflow, *
Result;
2346 if (ResultInfo.Signed) {
2350 llvm::APInt::getSignedMaxValue(ResultInfo.Width).zext(OpWidth);
2351 llvm::Value *MaxResult =
2352 CGF.
Builder.CreateAdd(llvm::ConstantInt::get(OpTy, IntMax),
2353 CGF.
Builder.CreateZExt(IsNegative, OpTy));
2354 llvm::Value *SignedOverflow =
2355 CGF.
Builder.CreateICmpUGT(UnsignedResult, MaxResult);
2356 Overflow = CGF.
Builder.CreateOr(UnsignedOverflow, SignedOverflow);
2359 llvm::Value *NegativeResult = CGF.
Builder.CreateNeg(UnsignedResult);
2360 llvm::Value *SignedResult =
2361 CGF.
Builder.CreateSelect(IsNegative, NegativeResult, UnsignedResult);
2365 llvm::Value *Underflow = CGF.
Builder.CreateAnd(
2366 IsNegative, CGF.
Builder.CreateIsNotNull(UnsignedResult));
2367 Overflow = CGF.
Builder.CreateOr(UnsignedOverflow, Underflow);
2368 if (ResultInfo.Width < OpWidth) {
2370 llvm::APInt::getMaxValue(ResultInfo.Width).zext(OpWidth);
2371 llvm::Value *TruncOverflow = CGF.
Builder.CreateICmpUGT(
2372 UnsignedResult, llvm::ConstantInt::get(OpTy, IntMax));
2373 Overflow = CGF.
Builder.CreateOr(Overflow, TruncOverflow);
2378 IsNegative, CGF.
Builder.CreateNeg(UnsignedResult), UnsignedResult);
2382 assert(Overflow &&
Result &&
"Missing overflow or result");
2393 llvm::SmallPtrSetImpl<const Decl *> &Seen) {
2402 if (!Seen.insert(
Record).second)
2405 assert(
Record->hasDefinition() &&
2406 "Incomplete types should already be diagnosed");
2408 if (
Record->isDynamicClass())
2433 llvm::Type *Ty = Src->getType();
2434 ShiftAmt =
Builder.CreateIntCast(ShiftAmt, Ty,
false);
2437 unsigned IID = IsRotateRight ? Intrinsic::fshr : Intrinsic::fshl;
2444 switch (BuiltinID) {
2445#define MUTATE_LDBL(func) \
2446 case Builtin::BI__builtin_##func##l: \
2447 return Builtin::BI__builtin_##func##f128;
2516 if (CGF.
Builder.getIsFPConstrained() &&
2517 CGF.
Builder.getDefaultConstrainedExcept() != fp::ebIgnore) {
2529 auto UBF = CGF->
CGM.
getModule().getOrInsertFunction(Name, FnTy);
2532 for (
auto &&FormalTy : FnTy->params())
2533 Args.push_back(llvm::PoisonValue::get(FormalTy));
2546 !
Result.hasSideEffects()) {
2550 if (
Result.Val.isFloat())
2559 if (
getTarget().getTriple().isPPC64() &&
2560 &
getTarget().getLongDoubleFormat() == &llvm::APFloat::IEEEquad())
2567 const unsigned BuiltinIDIfNoAsmLabel =
2568 FD->
hasAttr<AsmLabelAttr>() ? 0 : BuiltinID;
2570 std::optional<bool> ErrnoOverriden;
2574 if (
E->hasStoredFPFeatures()) {
2576 if (OP.hasMathErrnoOverride())
2577 ErrnoOverriden = OP.getMathErrnoOverride();
2586 bool ErrnoOverridenToFalseWithOpt =
2587 ErrnoOverriden.has_value() && !ErrnoOverriden.value() && !OptNone &&
2605 switch (BuiltinID) {
2606 case Builtin::BI__builtin_fma:
2607 case Builtin::BI__builtin_fmaf:
2608 case Builtin::BI__builtin_fmal:
2609 case Builtin::BI__builtin_fmaf16:
2610 case Builtin::BIfma:
2611 case Builtin::BIfmaf:
2612 case Builtin::BIfmal: {
2614 if (Trip.isGNUEnvironment() || Trip.isOSMSVCRT())
2622 bool ConstWithoutErrnoAndExceptions =
2624 bool ConstWithoutExceptions =
2642 bool ConstWithoutErrnoOrExceptions =
2643 ConstWithoutErrnoAndExceptions || ConstWithoutExceptions;
2644 bool GenerateIntrinsics =
2645 (ConstAlways && !OptNone) ||
2647 !(ErrnoOverriden.has_value() && ErrnoOverriden.value()) && !OptNone);
2648 if (!GenerateIntrinsics) {
2649 GenerateIntrinsics =
2650 ConstWithoutErrnoOrExceptions && !ConstWithoutErrnoAndExceptions;
2651 if (!GenerateIntrinsics)
2652 GenerateIntrinsics =
2653 ConstWithoutErrnoOrExceptions &&
2655 !(ErrnoOverriden.has_value() && ErrnoOverriden.value()) && !OptNone);
2656 if (!GenerateIntrinsics)
2657 GenerateIntrinsics =
2658 ConstWithoutErrnoOrExceptions && ErrnoOverridenToFalseWithOpt;
2660 if (GenerateIntrinsics) {
2661 switch (BuiltinIDIfNoAsmLabel) {
2662 case Builtin::BIacos:
2663 case Builtin::BIacosf:
2664 case Builtin::BIacosl:
2665 case Builtin::BI__builtin_acos:
2666 case Builtin::BI__builtin_acosf:
2667 case Builtin::BI__builtin_acosf16:
2668 case Builtin::BI__builtin_acosl:
2669 case Builtin::BI__builtin_acosf128:
2671 *
this,
E, Intrinsic::acos, Intrinsic::experimental_constrained_acos));
2673 case Builtin::BIasin:
2674 case Builtin::BIasinf:
2675 case Builtin::BIasinl:
2676 case Builtin::BI__builtin_asin:
2677 case Builtin::BI__builtin_asinf:
2678 case Builtin::BI__builtin_asinf16:
2679 case Builtin::BI__builtin_asinl:
2680 case Builtin::BI__builtin_asinf128:
2682 *
this,
E, Intrinsic::asin, Intrinsic::experimental_constrained_asin));
2684 case Builtin::BIatan:
2685 case Builtin::BIatanf:
2686 case Builtin::BIatanl:
2687 case Builtin::BI__builtin_atan:
2688 case Builtin::BI__builtin_atanf:
2689 case Builtin::BI__builtin_atanf16:
2690 case Builtin::BI__builtin_atanl:
2691 case Builtin::BI__builtin_atanf128:
2693 *
this,
E, Intrinsic::atan, Intrinsic::experimental_constrained_atan));
2695 case Builtin::BIceil:
2696 case Builtin::BIceilf:
2697 case Builtin::BIceill:
2698 case Builtin::BI__builtin_ceil:
2699 case Builtin::BI__builtin_ceilf:
2700 case Builtin::BI__builtin_ceilf16:
2701 case Builtin::BI__builtin_ceill:
2702 case Builtin::BI__builtin_ceilf128:
2705 Intrinsic::experimental_constrained_ceil));
2707 case Builtin::BIcopysign:
2708 case Builtin::BIcopysignf:
2709 case Builtin::BIcopysignl:
2710 case Builtin::BI__builtin_copysign:
2711 case Builtin::BI__builtin_copysignf:
2712 case Builtin::BI__builtin_copysignf16:
2713 case Builtin::BI__builtin_copysignl:
2714 case Builtin::BI__builtin_copysignf128:
2716 emitBuiltinWithOneOverloadedType<2>(*
this,
E, Intrinsic::copysign));
2718 case Builtin::BIcos:
2719 case Builtin::BIcosf:
2720 case Builtin::BIcosl:
2721 case Builtin::BI__builtin_cos:
2722 case Builtin::BI__builtin_cosf:
2723 case Builtin::BI__builtin_cosf16:
2724 case Builtin::BI__builtin_cosl:
2725 case Builtin::BI__builtin_cosf128:
2728 Intrinsic::experimental_constrained_cos));
2730 case Builtin::BIcosh:
2731 case Builtin::BIcoshf:
2732 case Builtin::BIcoshl:
2733 case Builtin::BI__builtin_cosh:
2734 case Builtin::BI__builtin_coshf:
2735 case Builtin::BI__builtin_coshf16:
2736 case Builtin::BI__builtin_coshl:
2737 case Builtin::BI__builtin_coshf128:
2739 *
this,
E, Intrinsic::cosh, Intrinsic::experimental_constrained_cosh));
2741 case Builtin::BIexp:
2742 case Builtin::BIexpf:
2743 case Builtin::BIexpl:
2744 case Builtin::BI__builtin_exp:
2745 case Builtin::BI__builtin_expf:
2746 case Builtin::BI__builtin_expf16:
2747 case Builtin::BI__builtin_expl:
2748 case Builtin::BI__builtin_expf128:
2751 Intrinsic::experimental_constrained_exp));
2753 case Builtin::BIexp2:
2754 case Builtin::BIexp2f:
2755 case Builtin::BIexp2l:
2756 case Builtin::BI__builtin_exp2:
2757 case Builtin::BI__builtin_exp2f:
2758 case Builtin::BI__builtin_exp2f16:
2759 case Builtin::BI__builtin_exp2l:
2760 case Builtin::BI__builtin_exp2f128:
2763 Intrinsic::experimental_constrained_exp2));
2764 case Builtin::BI__builtin_exp10:
2765 case Builtin::BI__builtin_exp10f:
2766 case Builtin::BI__builtin_exp10f16:
2767 case Builtin::BI__builtin_exp10l:
2768 case Builtin::BI__builtin_exp10f128: {
2770 if (
Builder.getIsFPConstrained())
2773 emitBuiltinWithOneOverloadedType<1>(*
this,
E, Intrinsic::exp10));
2775 case Builtin::BIfabs:
2776 case Builtin::BIfabsf:
2777 case Builtin::BIfabsl:
2778 case Builtin::BI__builtin_fabs:
2779 case Builtin::BI__builtin_fabsf:
2780 case Builtin::BI__builtin_fabsf16:
2781 case Builtin::BI__builtin_fabsl:
2782 case Builtin::BI__builtin_fabsf128:
2784 emitBuiltinWithOneOverloadedType<1>(*
this,
E, Intrinsic::fabs));
2786 case Builtin::BIfloor:
2787 case Builtin::BIfloorf:
2788 case Builtin::BIfloorl:
2789 case Builtin::BI__builtin_floor:
2790 case Builtin::BI__builtin_floorf:
2791 case Builtin::BI__builtin_floorf16:
2792 case Builtin::BI__builtin_floorl:
2793 case Builtin::BI__builtin_floorf128:
2796 Intrinsic::experimental_constrained_floor));
2798 case Builtin::BIfma:
2799 case Builtin::BIfmaf:
2800 case Builtin::BIfmal:
2801 case Builtin::BI__builtin_fma:
2802 case Builtin::BI__builtin_fmaf:
2803 case Builtin::BI__builtin_fmaf16:
2804 case Builtin::BI__builtin_fmal:
2805 case Builtin::BI__builtin_fmaf128:
2808 Intrinsic::experimental_constrained_fma));
2810 case Builtin::BIfmax:
2811 case Builtin::BIfmaxf:
2812 case Builtin::BIfmaxl:
2813 case Builtin::BI__builtin_fmax:
2814 case Builtin::BI__builtin_fmaxf:
2815 case Builtin::BI__builtin_fmaxf16:
2816 case Builtin::BI__builtin_fmaxl:
2817 case Builtin::BI__builtin_fmaxf128:
2820 Intrinsic::experimental_constrained_maxnum));
2822 case Builtin::BIfmin:
2823 case Builtin::BIfminf:
2824 case Builtin::BIfminl:
2825 case Builtin::BI__builtin_fmin:
2826 case Builtin::BI__builtin_fminf:
2827 case Builtin::BI__builtin_fminf16:
2828 case Builtin::BI__builtin_fminl:
2829 case Builtin::BI__builtin_fminf128:
2832 Intrinsic::experimental_constrained_minnum));
2836 case Builtin::BIfmod:
2837 case Builtin::BIfmodf:
2838 case Builtin::BIfmodl:
2839 case Builtin::BI__builtin_fmod:
2840 case Builtin::BI__builtin_fmodf:
2841 case Builtin::BI__builtin_fmodf16:
2842 case Builtin::BI__builtin_fmodl:
2843 case Builtin::BI__builtin_fmodf128: {
2844 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*
this,
E);
2850 case Builtin::BIlog:
2851 case Builtin::BIlogf:
2852 case Builtin::BIlogl:
2853 case Builtin::BI__builtin_log:
2854 case Builtin::BI__builtin_logf:
2855 case Builtin::BI__builtin_logf16:
2856 case Builtin::BI__builtin_logl:
2857 case Builtin::BI__builtin_logf128:
2860 Intrinsic::experimental_constrained_log));
2862 case Builtin::BIlog10:
2863 case Builtin::BIlog10f:
2864 case Builtin::BIlog10l:
2865 case Builtin::BI__builtin_log10:
2866 case Builtin::BI__builtin_log10f:
2867 case Builtin::BI__builtin_log10f16:
2868 case Builtin::BI__builtin_log10l:
2869 case Builtin::BI__builtin_log10f128:
2872 Intrinsic::experimental_constrained_log10));
2874 case Builtin::BIlog2:
2875 case Builtin::BIlog2f:
2876 case Builtin::BIlog2l:
2877 case Builtin::BI__builtin_log2:
2878 case Builtin::BI__builtin_log2f:
2879 case Builtin::BI__builtin_log2f16:
2880 case Builtin::BI__builtin_log2l:
2881 case Builtin::BI__builtin_log2f128:
2884 Intrinsic::experimental_constrained_log2));
2886 case Builtin::BInearbyint:
2887 case Builtin::BInearbyintf:
2888 case Builtin::BInearbyintl:
2889 case Builtin::BI__builtin_nearbyint:
2890 case Builtin::BI__builtin_nearbyintf:
2891 case Builtin::BI__builtin_nearbyintl:
2892 case Builtin::BI__builtin_nearbyintf128:
2894 Intrinsic::nearbyint,
2895 Intrinsic::experimental_constrained_nearbyint));
2897 case Builtin::BIpow:
2898 case Builtin::BIpowf:
2899 case Builtin::BIpowl:
2900 case Builtin::BI__builtin_pow:
2901 case Builtin::BI__builtin_powf:
2902 case Builtin::BI__builtin_powf16:
2903 case Builtin::BI__builtin_powl:
2904 case Builtin::BI__builtin_powf128:
2907 Intrinsic::experimental_constrained_pow));
2909 case Builtin::BIrint:
2910 case Builtin::BIrintf:
2911 case Builtin::BIrintl:
2912 case Builtin::BI__builtin_rint:
2913 case Builtin::BI__builtin_rintf:
2914 case Builtin::BI__builtin_rintf16:
2915 case Builtin::BI__builtin_rintl:
2916 case Builtin::BI__builtin_rintf128:
2919 Intrinsic::experimental_constrained_rint));
2921 case Builtin::BIround:
2922 case Builtin::BIroundf:
2923 case Builtin::BIroundl:
2924 case Builtin::BI__builtin_round:
2925 case Builtin::BI__builtin_roundf:
2926 case Builtin::BI__builtin_roundf16:
2927 case Builtin::BI__builtin_roundl:
2928 case Builtin::BI__builtin_roundf128:
2931 Intrinsic::experimental_constrained_round));
2933 case Builtin::BIroundeven:
2934 case Builtin::BIroundevenf:
2935 case Builtin::BIroundevenl:
2936 case Builtin::BI__builtin_roundeven:
2937 case Builtin::BI__builtin_roundevenf:
2938 case Builtin::BI__builtin_roundevenf16:
2939 case Builtin::BI__builtin_roundevenl:
2940 case Builtin::BI__builtin_roundevenf128:
2942 Intrinsic::roundeven,
2943 Intrinsic::experimental_constrained_roundeven));
2945 case Builtin::BIsin:
2946 case Builtin::BIsinf:
2947 case Builtin::BIsinl:
2948 case Builtin::BI__builtin_sin:
2949 case Builtin::BI__builtin_sinf:
2950 case Builtin::BI__builtin_sinf16:
2951 case Builtin::BI__builtin_sinl:
2952 case Builtin::BI__builtin_sinf128:
2955 Intrinsic::experimental_constrained_sin));
2957 case Builtin::BIsinh:
2958 case Builtin::BIsinhf:
2959 case Builtin::BIsinhl:
2960 case Builtin::BI__builtin_sinh:
2961 case Builtin::BI__builtin_sinhf:
2962 case Builtin::BI__builtin_sinhf16:
2963 case Builtin::BI__builtin_sinhl:
2964 case Builtin::BI__builtin_sinhf128:
2966 *
this,
E, Intrinsic::sinh, Intrinsic::experimental_constrained_sinh));
2968 case Builtin::BIsqrt:
2969 case Builtin::BIsqrtf:
2970 case Builtin::BIsqrtl:
2971 case Builtin::BI__builtin_sqrt:
2972 case Builtin::BI__builtin_sqrtf:
2973 case Builtin::BI__builtin_sqrtf16:
2974 case Builtin::BI__builtin_sqrtl:
2975 case Builtin::BI__builtin_sqrtf128:
2976 case Builtin::BI__builtin_elementwise_sqrt: {
2978 *
this,
E, Intrinsic::sqrt, Intrinsic::experimental_constrained_sqrt);
2983 case Builtin::BItan:
2984 case Builtin::BItanf:
2985 case Builtin::BItanl:
2986 case Builtin::BI__builtin_tan:
2987 case Builtin::BI__builtin_tanf:
2988 case Builtin::BI__builtin_tanf16:
2989 case Builtin::BI__builtin_tanl:
2990 case Builtin::BI__builtin_tanf128:
2992 *
this,
E, Intrinsic::tan, Intrinsic::experimental_constrained_tan));
2994 case Builtin::BItanh:
2995 case Builtin::BItanhf:
2996 case Builtin::BItanhl:
2997 case Builtin::BI__builtin_tanh:
2998 case Builtin::BI__builtin_tanhf:
2999 case Builtin::BI__builtin_tanhf16:
3000 case Builtin::BI__builtin_tanhl:
3001 case Builtin::BI__builtin_tanhf128:
3003 *
this,
E, Intrinsic::tanh, Intrinsic::experimental_constrained_tanh));
3005 case Builtin::BItrunc:
3006 case Builtin::BItruncf:
3007 case Builtin::BItruncl:
3008 case Builtin::BI__builtin_trunc:
3009 case Builtin::BI__builtin_truncf:
3010 case Builtin::BI__builtin_truncf16:
3011 case Builtin::BI__builtin_truncl:
3012 case Builtin::BI__builtin_truncf128:
3015 Intrinsic::experimental_constrained_trunc));
3017 case Builtin::BIlround:
3018 case Builtin::BIlroundf:
3019 case Builtin::BIlroundl:
3020 case Builtin::BI__builtin_lround:
3021 case Builtin::BI__builtin_lroundf:
3022 case Builtin::BI__builtin_lroundl:
3023 case Builtin::BI__builtin_lroundf128:
3025 *
this,
E, Intrinsic::lround,
3026 Intrinsic::experimental_constrained_lround));
3028 case Builtin::BIllround:
3029 case Builtin::BIllroundf:
3030 case Builtin::BIllroundl:
3031 case Builtin::BI__builtin_llround:
3032 case Builtin::BI__builtin_llroundf:
3033 case Builtin::BI__builtin_llroundl:
3034 case Builtin::BI__builtin_llroundf128:
3036 *
this,
E, Intrinsic::llround,
3037 Intrinsic::experimental_constrained_llround));
3039 case Builtin::BIlrint:
3040 case Builtin::BIlrintf:
3041 case Builtin::BIlrintl:
3042 case Builtin::BI__builtin_lrint:
3043 case Builtin::BI__builtin_lrintf:
3044 case Builtin::BI__builtin_lrintl:
3045 case Builtin::BI__builtin_lrintf128:
3047 *
this,
E, Intrinsic::lrint,
3048 Intrinsic::experimental_constrained_lrint));
3050 case Builtin::BIllrint:
3051 case Builtin::BIllrintf:
3052 case Builtin::BIllrintl:
3053 case Builtin::BI__builtin_llrint:
3054 case Builtin::BI__builtin_llrintf:
3055 case Builtin::BI__builtin_llrintl:
3056 case Builtin::BI__builtin_llrintf128:
3058 *
this,
E, Intrinsic::llrint,
3059 Intrinsic::experimental_constrained_llrint));
3060 case Builtin::BI__builtin_ldexp:
3061 case Builtin::BI__builtin_ldexpf:
3062 case Builtin::BI__builtin_ldexpl:
3063 case Builtin::BI__builtin_ldexpf16:
3064 case Builtin::BI__builtin_ldexpf128: {
3066 *
this,
E, Intrinsic::ldexp,
3067 Intrinsic::experimental_constrained_ldexp));
3077 Value *Val = A.emitRawPointer(*
this);
3083 SkippedChecks.
set(SanitizerKind::All);
3084 SkippedChecks.
clear(SanitizerKind::Alignment);
3087 if (
auto *CE = dyn_cast<ImplicitCastExpr>(Arg))
3088 if (CE->getCastKind() == CK_BitCast)
3089 Arg = CE->getSubExpr();
3095 switch (BuiltinIDIfNoAsmLabel) {
3097 case Builtin::BI__builtin___CFStringMakeConstantString:
3098 case Builtin::BI__builtin___NSStringMakeConstantString:
3100 case Builtin::BI__builtin_stdarg_start:
3101 case Builtin::BI__builtin_va_start:
3102 case Builtin::BI__va_start:
3103 case Builtin::BI__builtin_va_end:
3107 BuiltinID != Builtin::BI__builtin_va_end);
3109 case Builtin::BI__builtin_va_copy: {
3116 case Builtin::BIabs:
3117 case Builtin::BIlabs:
3118 case Builtin::BIllabs:
3119 case Builtin::BI__builtin_abs:
3120 case Builtin::BI__builtin_labs:
3121 case Builtin::BI__builtin_llabs: {
3122 bool SanitizeOverflow =
SanOpts.
has(SanitizerKind::SignedIntegerOverflow);
3125 switch (
getLangOpts().getSignedOverflowBehavior()) {
3130 if (!SanitizeOverflow) {
3142 case Builtin::BI__builtin_complex: {
3147 case Builtin::BI__builtin_conj:
3148 case Builtin::BI__builtin_conjf:
3149 case Builtin::BI__builtin_conjl:
3150 case Builtin::BIconj:
3151 case Builtin::BIconjf:
3152 case Builtin::BIconjl: {
3154 Value *Real = ComplexVal.first;
3155 Value *Imag = ComplexVal.second;
3156 Imag =
Builder.CreateFNeg(Imag,
"neg");
3159 case Builtin::BI__builtin_creal:
3160 case Builtin::BI__builtin_crealf:
3161 case Builtin::BI__builtin_creall:
3162 case Builtin::BIcreal:
3163 case Builtin::BIcrealf:
3164 case Builtin::BIcreall: {
3169 case Builtin::BI__builtin_preserve_access_index: {
3190 case Builtin::BI__builtin_cimag:
3191 case Builtin::BI__builtin_cimagf:
3192 case Builtin::BI__builtin_cimagl:
3193 case Builtin::BIcimag:
3194 case Builtin::BIcimagf:
3195 case Builtin::BIcimagl: {
3200 case Builtin::BI__builtin_clrsb:
3201 case Builtin::BI__builtin_clrsbl:
3202 case Builtin::BI__builtin_clrsbll: {
3206 llvm::Type *ArgType = ArgValue->
getType();
3210 Value *
Zero = llvm::Constant::getNullValue(ArgType);
3211 Value *IsNeg =
Builder.CreateICmpSLT(ArgValue, Zero,
"isneg");
3213 Value *Tmp =
Builder.CreateSelect(IsNeg, Inverse, ArgValue);
3220 case Builtin::BI__builtin_ctzs:
3221 case Builtin::BI__builtin_ctz:
3222 case Builtin::BI__builtin_ctzl:
3223 case Builtin::BI__builtin_ctzll:
3224 case Builtin::BI__builtin_ctzg: {
3225 bool HasFallback = BuiltinIDIfNoAsmLabel == Builtin::BI__builtin_ctzg &&
3226 E->getNumArgs() > 1;
3232 llvm::Type *ArgType = ArgValue->
getType();
3239 if (
Result->getType() != ResultType)
3245 Value *
Zero = Constant::getNullValue(ArgType);
3246 Value *IsZero =
Builder.CreateICmpEQ(ArgValue, Zero,
"iszero");
3248 Value *ResultOrFallback =
3249 Builder.CreateSelect(IsZero, FallbackValue,
Result,
"ctzg");
3252 case Builtin::BI__builtin_clzs:
3253 case Builtin::BI__builtin_clz:
3254 case Builtin::BI__builtin_clzl:
3255 case Builtin::BI__builtin_clzll:
3256 case Builtin::BI__builtin_clzg: {
3257 bool HasFallback = BuiltinIDIfNoAsmLabel == Builtin::BI__builtin_clzg &&
3258 E->getNumArgs() > 1;
3264 llvm::Type *ArgType = ArgValue->
getType();
3271 if (
Result->getType() != ResultType)
3277 Value *
Zero = Constant::getNullValue(ArgType);
3278 Value *IsZero =
Builder.CreateICmpEQ(ArgValue, Zero,
"iszero");
3280 Value *ResultOrFallback =
3281 Builder.CreateSelect(IsZero, FallbackValue,
Result,
"clzg");
3284 case Builtin::BI__builtin_ffs:
3285 case Builtin::BI__builtin_ffsl:
3286 case Builtin::BI__builtin_ffsll: {
3290 llvm::Type *ArgType = ArgValue->
getType();
3295 Builder.CreateAdd(
Builder.CreateCall(F, {ArgValue, Builder.getTrue()}),
3296 llvm::ConstantInt::get(ArgType, 1));
3297 Value *
Zero = llvm::Constant::getNullValue(ArgType);
3298 Value *IsZero =
Builder.CreateICmpEQ(ArgValue, Zero,
"iszero");
3300 if (
Result->getType() != ResultType)
3305 case Builtin::BI__builtin_parity:
3306 case Builtin::BI__builtin_parityl:
3307 case Builtin::BI__builtin_parityll: {
3311 llvm::Type *ArgType = ArgValue->
getType();
3317 if (
Result->getType() != ResultType)
3322 case Builtin::BI__lzcnt16:
3323 case Builtin::BI__lzcnt:
3324 case Builtin::BI__lzcnt64: {
3327 llvm::Type *ArgType = ArgValue->
getType();
3332 if (
Result->getType() != ResultType)
3337 case Builtin::BI__popcnt16:
3338 case Builtin::BI__popcnt:
3339 case Builtin::BI__popcnt64:
3340 case Builtin::BI__builtin_popcount:
3341 case Builtin::BI__builtin_popcountl:
3342 case Builtin::BI__builtin_popcountll:
3343 case Builtin::BI__builtin_popcountg: {
3346 llvm::Type *ArgType = ArgValue->
getType();
3351 if (
Result->getType() != ResultType)
3356 case Builtin::BI__builtin_unpredictable: {
3362 case Builtin::BI__builtin_expect: {
3364 llvm::Type *ArgType = ArgValue->
getType();
3375 Builder.CreateCall(FnExpect, {ArgValue, ExpectedValue},
"expval");
3378 case Builtin::BI__builtin_expect_with_probability: {
3380 llvm::Type *ArgType = ArgValue->
getType();
3383 llvm::APFloat Probability(0.0);
3384 const Expr *ProbArg =
E->getArg(2);
3386 assert(EvalSucceed &&
"probability should be able to evaluate as float");
3388 bool LoseInfo =
false;
3389 Probability.convert(llvm::APFloat::IEEEdouble(),
3390 llvm::RoundingMode::Dynamic, &LoseInfo);
3392 Constant *Confidence = ConstantFP::get(Ty, Probability);
3402 FnExpect, {ArgValue, ExpectedValue, Confidence},
"expval");
3405 case Builtin::BI__builtin_assume_aligned: {
3406 const Expr *Ptr =
E->getArg(0);
3408 Value *OffsetValue =
3412 ConstantInt *AlignmentCI = cast<ConstantInt>(AlignmentValue);
3413 if (AlignmentCI->getValue().ugt(llvm::Value::MaximumAlignment))
3414 AlignmentCI = ConstantInt::get(AlignmentCI->getIntegerType(),
3415 llvm::Value::MaximumAlignment);
3419 AlignmentCI, OffsetValue);
3422 case Builtin::BI__assume:
3423 case Builtin::BI__builtin_assume: {
3429 Builder.CreateCall(FnAssume, ArgValue);
3432 case Builtin::BI__builtin_assume_separate_storage: {
3433 const Expr *Arg0 =
E->getArg(0);
3434 const Expr *Arg1 =
E->getArg(1);
3439 Value *Values[] = {Value0, Value1};
3440 OperandBundleDefT<Value *> OBD(
"separate_storage", Values);
3444 case Builtin::BI__builtin_allow_runtime_check: {
3448 llvm::Value *Allow =
Builder.CreateCall(
3450 llvm::MetadataAsValue::get(Ctx, llvm::MDString::get(Ctx, Kind)));
3453 case Builtin::BI__arithmetic_fence: {
3456 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*
this,
E);
3457 llvm::FastMathFlags FMF =
Builder.getFastMathFlags();
3458 bool isArithmeticFenceEnabled =
3459 FMF.allowReassoc() &&
3463 if (isArithmeticFenceEnabled) {
3466 Value *Real =
Builder.CreateArithmeticFence(ComplexVal.first,
3468 Value *Imag =
Builder.CreateArithmeticFence(ComplexVal.second,
3473 Value *Real = ComplexVal.first;
3474 Value *Imag = ComplexVal.second;
3478 if (isArithmeticFenceEnabled)
3483 case Builtin::BI__builtin_bswap16:
3484 case Builtin::BI__builtin_bswap32:
3485 case Builtin::BI__builtin_bswap64:
3486 case Builtin::BI_byteswap_ushort:
3487 case Builtin::BI_byteswap_ulong:
3488 case Builtin::BI_byteswap_uint64: {
3490 emitBuiltinWithOneOverloadedType<1>(*
this,
E, Intrinsic::bswap));
3492 case Builtin::BI__builtin_bitreverse8:
3493 case Builtin::BI__builtin_bitreverse16:
3494 case Builtin::BI__builtin_bitreverse32:
3495 case Builtin::BI__builtin_bitreverse64: {
3497 emitBuiltinWithOneOverloadedType<1>(*
this,
E, Intrinsic::bitreverse));
3499 case Builtin::BI__builtin_rotateleft8:
3500 case Builtin::BI__builtin_rotateleft16:
3501 case Builtin::BI__builtin_rotateleft32:
3502 case Builtin::BI__builtin_rotateleft64:
3503 case Builtin::BI_rotl8:
3504 case Builtin::BI_rotl16:
3505 case Builtin::BI_rotl:
3506 case Builtin::BI_lrotl:
3507 case Builtin::BI_rotl64:
3510 case Builtin::BI__builtin_rotateright8:
3511 case Builtin::BI__builtin_rotateright16:
3512 case Builtin::BI__builtin_rotateright32:
3513 case Builtin::BI__builtin_rotateright64:
3514 case Builtin::BI_rotr8:
3515 case Builtin::BI_rotr16:
3516 case Builtin::BI_rotr:
3517 case Builtin::BI_lrotr:
3518 case Builtin::BI_rotr64:
3521 case Builtin::BI__builtin_constant_p: {
3524 const Expr *Arg =
E->getArg(0);
3532 return RValue::get(ConstantInt::get(ResultType, 0));
3537 return RValue::get(ConstantInt::get(ResultType, 0));
3549 if (
Result->getType() != ResultType)
3553 case Builtin::BI__builtin_dynamic_object_size:
3554 case Builtin::BI__builtin_object_size: {
3561 bool IsDynamic = BuiltinID == Builtin::BI__builtin_dynamic_object_size;
3563 nullptr, IsDynamic));
3565 case Builtin::BI__builtin_prefetch: {
3569 llvm::ConstantInt::get(
Int32Ty, 0);
3571 llvm::ConstantInt::get(
Int32Ty, 3);
3577 case Builtin::BI__builtin_readcyclecounter: {
3581 case Builtin::BI__builtin_readsteadycounter: {
3585 case Builtin::BI__builtin___clear_cache: {
3591 case Builtin::BI__builtin_trap:
3594 case Builtin::BI__builtin_verbose_trap: {
3595 llvm::DILocation *TrapLocation =
Builder.getCurrentDebugLocation();
3606 case Builtin::BI__debugbreak:
3609 case Builtin::BI__builtin_unreachable: {
3618 case Builtin::BI__builtin_powi:
3619 case Builtin::BI__builtin_powif:
3620 case Builtin::BI__builtin_powil: {
3624 if (
Builder.getIsFPConstrained()) {
3627 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*
this,
E);
3634 { Src0->getType(), Src1->getType() });
3637 case Builtin::BI__builtin_frexpl: {
3641 if (&
getTarget().getLongDoubleFormat() == &llvm::APFloat::PPCDoubleDouble())
3645 case Builtin::BI__builtin_frexp:
3646 case Builtin::BI__builtin_frexpf:
3647 case Builtin::BI__builtin_frexpf128:
3648 case Builtin::BI__builtin_frexpf16:
3650 case Builtin::BI__builtin_isgreater:
3651 case Builtin::BI__builtin_isgreaterequal:
3652 case Builtin::BI__builtin_isless:
3653 case Builtin::BI__builtin_islessequal:
3654 case Builtin::BI__builtin_islessgreater:
3655 case Builtin::BI__builtin_isunordered: {
3658 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*
this,
E);
3662 switch (BuiltinID) {
3663 default: llvm_unreachable(
"Unknown ordered comparison");
3664 case Builtin::BI__builtin_isgreater:
3665 LHS =
Builder.CreateFCmpOGT(LHS, RHS,
"cmp");
3667 case Builtin::BI__builtin_isgreaterequal:
3668 LHS =
Builder.CreateFCmpOGE(LHS, RHS,
"cmp");
3670 case Builtin::BI__builtin_isless:
3671 LHS =
Builder.CreateFCmpOLT(LHS, RHS,
"cmp");
3673 case Builtin::BI__builtin_islessequal:
3674 LHS =
Builder.CreateFCmpOLE(LHS, RHS,
"cmp");
3676 case Builtin::BI__builtin_islessgreater:
3677 LHS =
Builder.CreateFCmpONE(LHS, RHS,
"cmp");
3679 case Builtin::BI__builtin_isunordered:
3680 LHS =
Builder.CreateFCmpUNO(LHS, RHS,
"cmp");
3687 case Builtin::BI__builtin_isnan: {
3688 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*
this,
E);
3697 case Builtin::BI__builtin_issignaling: {
3698 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*
this,
E);
3705 case Builtin::BI__builtin_isinf: {
3706 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*
this,
E);
3715 case Builtin::BIfinite:
3716 case Builtin::BI__finite:
3717 case Builtin::BIfinitef:
3718 case Builtin::BI__finitef:
3719 case Builtin::BIfinitel:
3720 case Builtin::BI__finitel:
3721 case Builtin::BI__builtin_isfinite: {
3722 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*
this,
E);
3731 case Builtin::BI__builtin_isnormal: {
3732 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*
this,
E);
3739 case Builtin::BI__builtin_issubnormal: {
3740 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*
this,
E);
3743 Builder.CreateZExt(
Builder.createIsFPClass(
V, FPClassTest::fcSubnormal),
3747 case Builtin::BI__builtin_iszero: {
3748 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*
this,
E);
3755 case Builtin::BI__builtin_isfpclass: {
3760 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*
this,
E);
3766 case Builtin::BI__builtin_nondeterministic_value: {
3775 case Builtin::BI__builtin_elementwise_abs: {
3780 QT = VecTy->getElementType();
3784 Builder.getFalse(),
nullptr,
"elt.abs");
3786 Result = emitBuiltinWithOneOverloadedType<1>(
3787 *
this,
E, llvm::Intrinsic::fabs,
"elt.abs");
3791 case Builtin::BI__builtin_elementwise_acos:
3792 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
3793 *
this,
E, llvm::Intrinsic::acos,
"elt.acos"));
3794 case Builtin::BI__builtin_elementwise_asin:
3795 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
3796 *
this,
E, llvm::Intrinsic::asin,
"elt.asin"));
3797 case Builtin::BI__builtin_elementwise_atan:
3798 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
3799 *
this,
E, llvm::Intrinsic::atan,
"elt.atan"));
3800 case Builtin::BI__builtin_elementwise_ceil:
3801 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
3802 *
this,
E, llvm::Intrinsic::ceil,
"elt.ceil"));
3803 case Builtin::BI__builtin_elementwise_exp:
3804 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
3805 *
this,
E, llvm::Intrinsic::exp,
"elt.exp"));
3806 case Builtin::BI__builtin_elementwise_exp2:
3807 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
3808 *
this,
E, llvm::Intrinsic::exp2,
"elt.exp2"));
3809 case Builtin::BI__builtin_elementwise_log:
3810 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
3811 *
this,
E, llvm::Intrinsic::log,
"elt.log"));
3812 case Builtin::BI__builtin_elementwise_log2:
3813 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
3814 *
this,
E, llvm::Intrinsic::log2,
"elt.log2"));
3815 case Builtin::BI__builtin_elementwise_log10:
3816 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
3817 *
this,
E, llvm::Intrinsic::log10,
"elt.log10"));
3818 case Builtin::BI__builtin_elementwise_pow: {
3820 emitBuiltinWithOneOverloadedType<2>(*
this,
E, llvm::Intrinsic::pow));
3822 case Builtin::BI__builtin_elementwise_bitreverse:
3823 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
3824 *
this,
E, llvm::Intrinsic::bitreverse,
"elt.bitreverse"));
3825 case Builtin::BI__builtin_elementwise_cos:
3826 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
3827 *
this,
E, llvm::Intrinsic::cos,
"elt.cos"));
3828 case Builtin::BI__builtin_elementwise_cosh:
3829 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
3830 *
this,
E, llvm::Intrinsic::cosh,
"elt.cosh"));
3831 case Builtin::BI__builtin_elementwise_floor:
3832 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
3833 *
this,
E, llvm::Intrinsic::floor,
"elt.floor"));
3834 case Builtin::BI__builtin_elementwise_roundeven:
3835 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
3836 *
this,
E, llvm::Intrinsic::roundeven,
"elt.roundeven"));
3837 case Builtin::BI__builtin_elementwise_round:
3838 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
3839 *
this,
E, llvm::Intrinsic::round,
"elt.round"));
3840 case Builtin::BI__builtin_elementwise_rint:
3841 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
3842 *
this,
E, llvm::Intrinsic::rint,
"elt.rint"));
3843 case Builtin::BI__builtin_elementwise_nearbyint:
3844 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
3845 *
this,
E, llvm::Intrinsic::nearbyint,
"elt.nearbyint"));
3846 case Builtin::BI__builtin_elementwise_sin:
3847 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
3848 *
this,
E, llvm::Intrinsic::sin,
"elt.sin"));
3849 case Builtin::BI__builtin_elementwise_sinh:
3850 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
3851 *
this,
E, llvm::Intrinsic::sinh,
"elt.sinh"));
3852 case Builtin::BI__builtin_elementwise_tan:
3853 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
3854 *
this,
E, llvm::Intrinsic::tan,
"elt.tan"));
3855 case Builtin::BI__builtin_elementwise_tanh:
3856 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
3857 *
this,
E, llvm::Intrinsic::tanh,
"elt.tanh"));
3858 case Builtin::BI__builtin_elementwise_trunc:
3859 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
3860 *
this,
E, llvm::Intrinsic::trunc,
"elt.trunc"));
3861 case Builtin::BI__builtin_elementwise_canonicalize:
3862 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
3863 *
this,
E, llvm::Intrinsic::canonicalize,
"elt.canonicalize"));
3864 case Builtin::BI__builtin_elementwise_copysign:
3865 return RValue::get(emitBuiltinWithOneOverloadedType<2>(
3866 *
this,
E, llvm::Intrinsic::copysign));
3867 case Builtin::BI__builtin_elementwise_fma:
3869 emitBuiltinWithOneOverloadedType<3>(*
this,
E, llvm::Intrinsic::fma));
3870 case Builtin::BI__builtin_elementwise_add_sat:
3871 case Builtin::BI__builtin_elementwise_sub_sat: {
3875 assert(Op0->
getType()->isIntOrIntVectorTy() &&
"integer type expected");
3878 Ty = VecTy->getElementType();
3881 if (BuiltinIDIfNoAsmLabel == Builtin::BI__builtin_elementwise_add_sat)
3882 Opc = IsSigned ? llvm::Intrinsic::sadd_sat : llvm::Intrinsic::uadd_sat;
3884 Opc = IsSigned ? llvm::Intrinsic::ssub_sat : llvm::Intrinsic::usub_sat;
3885 Result =
Builder.CreateBinaryIntrinsic(Opc, Op0, Op1,
nullptr,
"elt.sat");
3889 case Builtin::BI__builtin_elementwise_max: {
3893 if (Op0->
getType()->isIntOrIntVectorTy()) {
3896 Ty = VecTy->getElementType();
3898 ? llvm::Intrinsic::smax
3899 : llvm::Intrinsic::umax,
3900 Op0, Op1,
nullptr,
"elt.max");
3905 case Builtin::BI__builtin_elementwise_min: {
3909 if (Op0->
getType()->isIntOrIntVectorTy()) {
3912 Ty = VecTy->getElementType();
3914 ? llvm::Intrinsic::smin
3915 : llvm::Intrinsic::umin,
3916 Op0, Op1,
nullptr,
"elt.min");
3922 case Builtin::BI__builtin_reduce_max: {
3923 auto GetIntrinsicID = [
this](
QualType QT) {
3925 QT = VecTy->getElementType();
3930 return llvm::Intrinsic::vector_reduce_smax;
3932 return llvm::Intrinsic::vector_reduce_umax;
3934 return llvm::Intrinsic::vector_reduce_fmax;
3936 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
3937 *
this,
E, GetIntrinsicID(
E->getArg(0)->
getType()),
"rdx.min"));
3940 case Builtin::BI__builtin_reduce_min: {
3941 auto GetIntrinsicID = [
this](
QualType QT) {
3943 QT = VecTy->getElementType();
3948 return llvm::Intrinsic::vector_reduce_smin;
3950 return llvm::Intrinsic::vector_reduce_umin;
3952 return llvm::Intrinsic::vector_reduce_fmin;
3955 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
3956 *
this,
E, GetIntrinsicID(
E->getArg(0)->
getType()),
"rdx.min"));
3959 case Builtin::BI__builtin_reduce_add:
3960 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
3961 *
this,
E, llvm::Intrinsic::vector_reduce_add,
"rdx.add"));
3962 case Builtin::BI__builtin_reduce_mul:
3963 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
3964 *
this,
E, llvm::Intrinsic::vector_reduce_mul,
"rdx.mul"));
3965 case Builtin::BI__builtin_reduce_xor:
3966 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
3967 *
this,
E, llvm::Intrinsic::vector_reduce_xor,
"rdx.xor"));
3968 case Builtin::BI__builtin_reduce_or:
3969 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
3970 *
this,
E, llvm::Intrinsic::vector_reduce_or,
"rdx.or"));
3971 case Builtin::BI__builtin_reduce_and:
3972 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
3973 *
this,
E, llvm::Intrinsic::vector_reduce_and,
"rdx.and"));
3975 case Builtin::BI__builtin_matrix_transpose: {
3979 Value *
Result = MB.CreateMatrixTranspose(MatValue, MatrixTy->getNumRows(),
3980 MatrixTy->getNumColumns());
3984 case Builtin::BI__builtin_matrix_column_major_load: {
3990 assert(PtrTy &&
"arg0 must be of pointer type");
4000 ResultTy->getNumRows(), ResultTy->getNumColumns(),
"matrix");
4004 case Builtin::BI__builtin_matrix_column_major_store: {
4012 assert(PtrTy &&
"arg1 must be of pointer type");
4021 MatrixTy->getNumRows(), MatrixTy->getNumColumns());
4025 case Builtin::BI__builtin_isinf_sign: {
4027 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*
this,
E);
4032 AbsArg, ConstantFP::getInfinity(Arg->
getType()),
"isinf");
4038 Value *NegativeOne = ConstantInt::get(
IntTy, -1);
4039 Value *SignResult =
Builder.CreateSelect(IsNeg, NegativeOne, One);
4044 case Builtin::BI__builtin_flt_rounds: {
4049 if (
Result->getType() != ResultType)
4055 case Builtin::BI__builtin_set_flt_rounds: {
4063 case Builtin::BI__builtin_fpclassify: {
4064 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*
this,
E);
4075 "fpclassify_result");
4079 Value *IsZero =
Builder.CreateFCmpOEQ(
V, Constant::getNullValue(Ty),
4083 Builder.CreateCondBr(IsZero, End, NotZero);
4087 Builder.SetInsertPoint(NotZero);
4091 Builder.CreateCondBr(IsNan, End, NotNan);
4092 Result->addIncoming(NanLiteral, NotZero);
4095 Builder.SetInsertPoint(NotNan);
4098 Builder.CreateFCmpOEQ(VAbs, ConstantFP::getInfinity(
V->getType()),
4102 Builder.CreateCondBr(IsInf, End, NotInf);
4103 Result->addIncoming(InfLiteral, NotNan);
4106 Builder.SetInsertPoint(NotInf);
4107 APFloat Smallest = APFloat::getSmallestNormalized(
4110 Builder.CreateFCmpUGE(VAbs, ConstantFP::get(
V->getContext(), Smallest),
4112 Value *NormalResult =
4116 Result->addIncoming(NormalResult, NotInf);
4129 case Builtin::BIalloca:
4130 case Builtin::BI_alloca:
4131 case Builtin::BI__builtin_alloca_uninitialized:
4132 case Builtin::BI__builtin_alloca: {
4136 const Align SuitableAlignmentInBytes =
4140 AllocaInst *AI =
Builder.CreateAlloca(
Builder.getInt8Ty(), Size);
4141 AI->setAlignment(SuitableAlignmentInBytes);
4142 if (BuiltinID != Builtin::BI__builtin_alloca_uninitialized)
4154 case Builtin::BI__builtin_alloca_with_align_uninitialized:
4155 case Builtin::BI__builtin_alloca_with_align: {
4158 auto *AlignmentInBitsCI = cast<ConstantInt>(AlignmentInBitsValue);
4159 unsigned AlignmentInBits = AlignmentInBitsCI->getZExtValue();
4160 const Align AlignmentInBytes =
4162 AllocaInst *AI =
Builder.CreateAlloca(
Builder.getInt8Ty(), Size);
4163 AI->setAlignment(AlignmentInBytes);
4164 if (BuiltinID != Builtin::BI__builtin_alloca_with_align_uninitialized)
4176 case Builtin::BIbzero:
4177 case Builtin::BI__builtin_bzero: {
4186 case Builtin::BIbcopy:
4187 case Builtin::BI__builtin_bcopy: {
4201 case Builtin::BImemcpy:
4202 case Builtin::BI__builtin_memcpy:
4203 case Builtin::BImempcpy:
4204 case Builtin::BI__builtin_mempcpy: {
4208 EmitArgCheck(
TCK_Store, Dest,
E->getArg(0), 0);
4209 EmitArgCheck(
TCK_Load, Src,
E->getArg(1), 1);
4211 if (BuiltinID == Builtin::BImempcpy ||
4212 BuiltinID == Builtin::BI__builtin_mempcpy)
4219 case Builtin::BI__builtin_memcpy_inline: {
4224 EmitArgCheck(
TCK_Store, Dest,
E->getArg(0), 0);
4225 EmitArgCheck(
TCK_Load, Src,
E->getArg(1), 1);
4230 case Builtin::BI__builtin_char_memchr:
4231 BuiltinID = Builtin::BI__builtin_memchr;
4234 case Builtin::BI__builtin___memcpy_chk: {
4241 llvm::APSInt DstSize = DstSizeResult.
Val.
getInt();
4242 if (
Size.ugt(DstSize))
4246 Value *SizeVal = llvm::ConstantInt::get(
Builder.getContext(), Size);
4251 case Builtin::BI__builtin_objc_memmove_collectable: {
4256 DestAddr, SrcAddr, SizeVal);
4260 case Builtin::BI__builtin___memmove_chk: {
4267 llvm::APSInt DstSize = DstSizeResult.
Val.
getInt();
4268 if (
Size.ugt(DstSize))
4272 Value *SizeVal = llvm::ConstantInt::get(
Builder.getContext(), Size);
4277 case Builtin::BImemmove:
4278 case Builtin::BI__builtin_memmove: {
4282 EmitArgCheck(
TCK_Store, Dest,
E->getArg(0), 0);
4283 EmitArgCheck(
TCK_Load, Src,
E->getArg(1), 1);
4287 case Builtin::BImemset:
4288 case Builtin::BI__builtin_memset: {
4298 case Builtin::BI__builtin_memset_inline: {
4310 case Builtin::BI__builtin___memset_chk: {
4317 llvm::APSInt DstSize = DstSizeResult.
Val.
getInt();
4318 if (
Size.ugt(DstSize))
4323 Value *SizeVal = llvm::ConstantInt::get(
Builder.getContext(), Size);
4327 case Builtin::BI__builtin_wmemchr: {
4330 if (!
getTarget().getTriple().isOSMSVCRT())
4338 BasicBlock *Entry =
Builder.GetInsertBlock();
4343 Builder.CreateCondBr(SizeEq0, Exit, CmpEq);
4347 StrPhi->addIncoming(Str, Entry);
4349 SizePhi->addIncoming(Size, Entry);
4353 Value *FoundChr =
Builder.CreateConstInBoundsGEP1_32(WCharTy, StrPhi, 0);
4355 Builder.CreateCondBr(StrEqChr, Exit, Next);
4358 Value *NextStr =
Builder.CreateConstInBoundsGEP1_32(WCharTy, StrPhi, 1);
4360 Value *NextSizeEq0 =
4361 Builder.CreateICmpEQ(NextSize, ConstantInt::get(
SizeTy, 0));
4362 Builder.CreateCondBr(NextSizeEq0, Exit, CmpEq);
4363 StrPhi->addIncoming(NextStr, Next);
4364 SizePhi->addIncoming(NextSize, Next);
4368 Ret->addIncoming(llvm::Constant::getNullValue(Str->
getType()), Entry);
4369 Ret->addIncoming(llvm::Constant::getNullValue(Str->
getType()), Next);
4370 Ret->addIncoming(FoundChr, CmpEq);
4373 case Builtin::BI__builtin_wmemcmp: {
4376 if (!
getTarget().getTriple().isOSMSVCRT())
4385 BasicBlock *Entry =
Builder.GetInsertBlock();
4391 Builder.CreateCondBr(SizeEq0, Exit, CmpGT);
4395 DstPhi->addIncoming(Dst, Entry);
4397 SrcPhi->addIncoming(Src, Entry);
4399 SizePhi->addIncoming(Size, Entry);
4405 Builder.CreateCondBr(DstGtSrc, Exit, CmpLT);
4409 Builder.CreateCondBr(DstLtSrc, Exit, Next);
4412 Value *NextDst =
Builder.CreateConstInBoundsGEP1_32(WCharTy, DstPhi, 1);
4413 Value *NextSrc =
Builder.CreateConstInBoundsGEP1_32(WCharTy, SrcPhi, 1);
4415 Value *NextSizeEq0 =
4416 Builder.CreateICmpEQ(NextSize, ConstantInt::get(
SizeTy, 0));
4417 Builder.CreateCondBr(NextSizeEq0, Exit, CmpGT);
4418 DstPhi->addIncoming(NextDst, Next);
4419 SrcPhi->addIncoming(NextSrc, Next);
4420 SizePhi->addIncoming(NextSize, Next);
4424 Ret->addIncoming(ConstantInt::get(
IntTy, 0), Entry);
4425 Ret->addIncoming(ConstantInt::get(
IntTy, 1), CmpGT);
4426 Ret->addIncoming(ConstantInt::get(
IntTy, -1), CmpLT);
4427 Ret->addIncoming(ConstantInt::get(
IntTy, 0), Next);
4430 case Builtin::BI__builtin_dwarf_cfa: {
4443 llvm::ConstantInt::get(
Int32Ty, Offset)));
4445 case Builtin::BI__builtin_return_address: {
4451 case Builtin::BI_ReturnAddress: {
4455 case Builtin::BI__builtin_frame_address: {
4461 case Builtin::BI__builtin_extract_return_addr: {
4466 case Builtin::BI__builtin_frob_return_addr: {
4471 case Builtin::BI__builtin_dwarf_sp_column: {
4472 llvm::IntegerType *Ty
4481 case Builtin::BI__builtin_init_dwarf_reg_size_table: {
4487 case Builtin::BI__builtin_eh_return: {
4491 llvm::IntegerType *
IntTy = cast<llvm::IntegerType>(
Int->getType());
4492 assert((
IntTy->getBitWidth() == 32 ||
IntTy->getBitWidth() == 64) &&
4493 "LLVM's __builtin_eh_return only supports 32- and 64-bit variants");
4496 : Intrinsic::eh_return_i64);
4505 case Builtin::BI__builtin_unwind_init: {
4510 case Builtin::BI__builtin_extend_pointer: {
4535 case Builtin::BI__builtin_setjmp: {
4542 ConstantInt::get(
Int32Ty, 0));
4556 case Builtin::BI__builtin_longjmp: {
4570 case Builtin::BI__builtin_launder: {
4571 const Expr *Arg =
E->getArg(0);
4579 case Builtin::BI__sync_fetch_and_add:
4580 case Builtin::BI__sync_fetch_and_sub:
4581 case Builtin::BI__sync_fetch_and_or:
4582 case Builtin::BI__sync_fetch_and_and:
4583 case Builtin::BI__sync_fetch_and_xor:
4584 case Builtin::BI__sync_fetch_and_nand:
4585 case Builtin::BI__sync_add_and_fetch:
4586 case Builtin::BI__sync_sub_and_fetch:
4587 case Builtin::BI__sync_and_and_fetch:
4588 case Builtin::BI__sync_or_and_fetch:
4589 case Builtin::BI__sync_xor_and_fetch:
4590 case Builtin::BI__sync_nand_and_fetch:
4591 case Builtin::BI__sync_val_compare_and_swap:
4592 case Builtin::BI__sync_bool_compare_and_swap:
4593 case Builtin::BI__sync_lock_test_and_set:
4594 case Builtin::BI__sync_lock_release:
4595 case Builtin::BI__sync_swap:
4596 llvm_unreachable(
"Shouldn't make it through sema");
4597 case Builtin::BI__sync_fetch_and_add_1:
4598 case Builtin::BI__sync_fetch_and_add_2:
4599 case Builtin::BI__sync_fetch_and_add_4:
4600 case Builtin::BI__sync_fetch_and_add_8:
4601 case Builtin::BI__sync_fetch_and_add_16:
4603 case Builtin::BI__sync_fetch_and_sub_1:
4604 case Builtin::BI__sync_fetch_and_sub_2:
4605 case Builtin::BI__sync_fetch_and_sub_4:
4606 case Builtin::BI__sync_fetch_and_sub_8:
4607 case Builtin::BI__sync_fetch_and_sub_16:
4609 case Builtin::BI__sync_fetch_and_or_1:
4610 case Builtin::BI__sync_fetch_and_or_2:
4611 case Builtin::BI__sync_fetch_and_or_4:
4612 case Builtin::BI__sync_fetch_and_or_8:
4613 case Builtin::BI__sync_fetch_and_or_16:
4615 case Builtin::BI__sync_fetch_and_and_1:
4616 case Builtin::BI__sync_fetch_and_and_2:
4617 case Builtin::BI__sync_fetch_and_and_4:
4618 case Builtin::BI__sync_fetch_and_and_8:
4619 case Builtin::BI__sync_fetch_and_and_16:
4621 case Builtin::BI__sync_fetch_and_xor_1:
4622 case Builtin::BI__sync_fetch_and_xor_2:
4623 case Builtin::BI__sync_fetch_and_xor_4:
4624 case Builtin::BI__sync_fetch_and_xor_8:
4625 case Builtin::BI__sync_fetch_and_xor_16:
4627 case Builtin::BI__sync_fetch_and_nand_1:
4628 case Builtin::BI__sync_fetch_and_nand_2:
4629 case Builtin::BI__sync_fetch_and_nand_4:
4630 case Builtin::BI__sync_fetch_and_nand_8:
4631 case Builtin::BI__sync_fetch_and_nand_16:
4635 case Builtin::BI__sync_fetch_and_min:
4637 case Builtin::BI__sync_fetch_and_max:
4639 case Builtin::BI__sync_fetch_and_umin:
4641 case Builtin::BI__sync_fetch_and_umax:
4644 case Builtin::BI__sync_add_and_fetch_1:
4645 case Builtin::BI__sync_add_and_fetch_2:
4646 case Builtin::BI__sync_add_and_fetch_4:
4647 case Builtin::BI__sync_add_and_fetch_8:
4648 case Builtin::BI__sync_add_and_fetch_16:
4650 llvm::Instruction::Add);
4651 case Builtin::BI__sync_sub_and_fetch_1:
4652 case Builtin::BI__sync_sub_and_fetch_2:
4653 case Builtin::BI__sync_sub_and_fetch_4:
4654 case Builtin::BI__sync_sub_and_fetch_8:
4655 case Builtin::BI__sync_sub_and_fetch_16:
4657 llvm::Instruction::Sub);
4658 case Builtin::BI__sync_and_and_fetch_1:
4659 case Builtin::BI__sync_and_and_fetch_2:
4660 case Builtin::BI__sync_and_and_fetch_4:
4661 case Builtin::BI__sync_and_and_fetch_8:
4662 case Builtin::BI__sync_and_and_fetch_16:
4664 llvm::Instruction::And);
4665 case Builtin::BI__sync_or_and_fetch_1:
4666 case Builtin::BI__sync_or_and_fetch_2:
4667 case Builtin::BI__sync_or_and_fetch_4:
4668 case Builtin::BI__sync_or_and_fetch_8:
4669 case Builtin::BI__sync_or_and_fetch_16:
4671 llvm::Instruction::Or);
4672 case Builtin::BI__sync_xor_and_fetch_1:
4673 case Builtin::BI__sync_xor_and_fetch_2:
4674 case Builtin::BI__sync_xor_and_fetch_4:
4675 case Builtin::BI__sync_xor_and_fetch_8:
4676 case Builtin::BI__sync_xor_and_fetch_16:
4678 llvm::Instruction::Xor);
4679 case Builtin::BI__sync_nand_and_fetch_1:
4680 case Builtin::BI__sync_nand_and_fetch_2:
4681 case Builtin::BI__sync_nand_and_fetch_4:
4682 case Builtin::BI__sync_nand_and_fetch_8:
4683 case Builtin::BI__sync_nand_and_fetch_16:
4685 llvm::Instruction::And,
true);
4687 case Builtin::BI__sync_val_compare_and_swap_1:
4688 case Builtin::BI__sync_val_compare_and_swap_2:
4689 case Builtin::BI__sync_val_compare_and_swap_4:
4690 case Builtin::BI__sync_val_compare_and_swap_8:
4691 case Builtin::BI__sync_val_compare_and_swap_16:
4694 case Builtin::BI__sync_bool_compare_and_swap_1:
4695 case Builtin::BI__sync_bool_compare_and_swap_2:
4696 case Builtin::BI__sync_bool_compare_and_swap_4:
4697 case Builtin::BI__sync_bool_compare_and_swap_8:
4698 case Builtin::BI__sync_bool_compare_and_swap_16:
4701 case Builtin::BI__sync_swap_1:
4702 case Builtin::BI__sync_swap_2:
4703 case Builtin::BI__sync_swap_4:
4704 case Builtin::BI__sync_swap_8:
4705 case Builtin::BI__sync_swap_16:
4708 case Builtin::BI__sync_lock_test_and_set_1:
4709 case Builtin::BI__sync_lock_test_and_set_2:
4710 case Builtin::BI__sync_lock_test_and_set_4:
4711 case Builtin::BI__sync_lock_test_and_set_8:
4712 case Builtin::BI__sync_lock_test_and_set_16:
4715 case Builtin::BI__sync_lock_release_1:
4716 case Builtin::BI__sync_lock_release_2:
4717 case Builtin::BI__sync_lock_release_4:
4718 case Builtin::BI__sync_lock_release_8:
4719 case Builtin::BI__sync_lock_release_16: {
4725 llvm::StoreInst *
Store =
4727 Store->setAtomic(llvm::AtomicOrdering::Release);
4731 case Builtin::BI__sync_synchronize: {
4739 Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent);
4743 case Builtin::BI__builtin_nontemporal_load:
4745 case Builtin::BI__builtin_nontemporal_store:
4747 case Builtin::BI__c11_atomic_is_lock_free:
4748 case Builtin::BI__atomic_is_lock_free: {
4752 const char *LibCallName =
"__atomic_is_lock_free";
4756 if (BuiltinID == Builtin::BI__atomic_is_lock_free)
4770 case Builtin::BI__atomic_test_and_set: {
4782 if (isa<llvm::ConstantInt>(Order)) {
4783 int ord = cast<llvm::ConstantInt>(Order)->getZExtValue();
4784 AtomicRMWInst *
Result =
nullptr;
4789 llvm::AtomicOrdering::Monotonic);
4794 llvm::AtomicOrdering::Acquire);
4798 llvm::AtomicOrdering::Release);
4803 llvm::AtomicOrdering::AcquireRelease);
4807 llvm::AtomicRMWInst::Xchg, Ptr, NewVal,
4808 llvm::AtomicOrdering::SequentiallyConsistent);
4811 Result->setVolatile(Volatile);
4817 llvm::BasicBlock *BBs[5] = {
4824 llvm::AtomicOrdering Orders[5] = {
4825 llvm::AtomicOrdering::Monotonic, llvm::AtomicOrdering::Acquire,
4826 llvm::AtomicOrdering::Release, llvm::AtomicOrdering::AcquireRelease,
4827 llvm::AtomicOrdering::SequentiallyConsistent};
4829 Order =
Builder.CreateIntCast(Order,
Builder.getInt32Ty(),
false);
4830 llvm::SwitchInst *SI =
Builder.CreateSwitch(Order, BBs[0]);
4832 Builder.SetInsertPoint(ContBB);
4835 for (
unsigned i = 0; i < 5; ++i) {
4836 Builder.SetInsertPoint(BBs[i]);
4838 Ptr, NewVal, Orders[i]);
4839 RMW->setVolatile(Volatile);
4840 Result->addIncoming(RMW, BBs[i]);
4844 SI->addCase(
Builder.getInt32(0), BBs[0]);
4845 SI->addCase(
Builder.getInt32(1), BBs[1]);
4846 SI->addCase(
Builder.getInt32(2), BBs[1]);
4847 SI->addCase(
Builder.getInt32(3), BBs[2]);
4848 SI->addCase(
Builder.getInt32(4), BBs[3]);
4849 SI->addCase(
Builder.getInt32(5), BBs[4]);
4851 Builder.SetInsertPoint(ContBB);
4855 case Builtin::BI__atomic_clear: {
4864 if (isa<llvm::ConstantInt>(Order)) {
4865 int ord = cast<llvm::ConstantInt>(Order)->getZExtValue();
4870 Store->setOrdering(llvm::AtomicOrdering::Monotonic);
4873 Store->setOrdering(llvm::AtomicOrdering::Release);
4876 Store->setOrdering(llvm::AtomicOrdering::SequentiallyConsistent);
4884 llvm::BasicBlock *BBs[3] = {
4889 llvm::AtomicOrdering Orders[3] = {
4890 llvm::AtomicOrdering::Monotonic, llvm::AtomicOrdering::Release,
4891 llvm::AtomicOrdering::SequentiallyConsistent};
4893 Order =
Builder.CreateIntCast(Order,
Builder.getInt32Ty(),
false);
4894 llvm::SwitchInst *SI =
Builder.CreateSwitch(Order, BBs[0]);
4896 for (
unsigned i = 0; i < 3; ++i) {
4897 Builder.SetInsertPoint(BBs[i]);
4899 Store->setOrdering(Orders[i]);
4903 SI->addCase(
Builder.getInt32(0), BBs[0]);
4904 SI->addCase(
Builder.getInt32(3), BBs[1]);
4905 SI->addCase(
Builder.getInt32(5), BBs[2]);
4907 Builder.SetInsertPoint(ContBB);
4911 case Builtin::BI__atomic_thread_fence:
4912 case Builtin::BI__atomic_signal_fence:
4913 case Builtin::BI__c11_atomic_thread_fence:
4914 case Builtin::BI__c11_atomic_signal_fence: {
4915 llvm::SyncScope::ID SSID;
4916 if (BuiltinID == Builtin::BI__atomic_signal_fence ||
4917 BuiltinID == Builtin::BI__c11_atomic_signal_fence)
4918 SSID = llvm::SyncScope::SingleThread;
4920 SSID = llvm::SyncScope::System;
4922 if (isa<llvm::ConstantInt>(Order)) {
4923 int ord = cast<llvm::ConstantInt>(Order)->getZExtValue();
4930 Builder.CreateFence(llvm::AtomicOrdering::Acquire, SSID);
4933 Builder.CreateFence(llvm::AtomicOrdering::Release, SSID);
4936 Builder.CreateFence(llvm::AtomicOrdering::AcquireRelease, SSID);
4939 Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent, SSID);
4945 llvm::BasicBlock *AcquireBB, *ReleaseBB, *AcqRelBB, *SeqCstBB;
4952 Order =
Builder.CreateIntCast(Order,
Builder.getInt32Ty(),
false);
4953 llvm::SwitchInst *SI =
Builder.CreateSwitch(Order, ContBB);
4955 Builder.SetInsertPoint(AcquireBB);
4956 Builder.CreateFence(llvm::AtomicOrdering::Acquire, SSID);
4958 SI->addCase(
Builder.getInt32(1), AcquireBB);
4959 SI->addCase(
Builder.getInt32(2), AcquireBB);
4961 Builder.SetInsertPoint(ReleaseBB);
4962 Builder.CreateFence(llvm::AtomicOrdering::Release, SSID);
4964 SI->addCase(
Builder.getInt32(3), ReleaseBB);
4966 Builder.SetInsertPoint(AcqRelBB);
4967 Builder.CreateFence(llvm::AtomicOrdering::AcquireRelease, SSID);
4969 SI->addCase(
Builder.getInt32(4), AcqRelBB);
4971 Builder.SetInsertPoint(SeqCstBB);
4972 Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent, SSID);
4974 SI->addCase(
Builder.getInt32(5), SeqCstBB);
4976 Builder.SetInsertPoint(ContBB);
4980 case Builtin::BI__builtin_signbit:
4981 case Builtin::BI__builtin_signbitf:
4982 case Builtin::BI__builtin_signbitl: {
4987 case Builtin::BI__warn_memset_zero_len:
4989 case Builtin::BI__annotation: {
4992 for (
const Expr *Arg :
E->arguments()) {
4994 assert(Str->getCharByteWidth() == 2);
4995 StringRef WideBytes = Str->getBytes();
4996 std::string StrUtf8;
4997 if (!convertUTF16ToUTF8String(
4998 ArrayRef(WideBytes.data(), WideBytes.size()), StrUtf8)) {
5002 Strings.push_back(llvm::MDString::get(
getLLVMContext(), StrUtf8));
5012 case Builtin::BI__builtin_annotation: {
5021 StringRef Str = cast<StringLiteral>(AnnotationStrExpr)->getString();
5025 case Builtin::BI__builtin_addcb:
5026 case Builtin::BI__builtin_addcs:
5027 case Builtin::BI__builtin_addc:
5028 case Builtin::BI__builtin_addcl:
5029 case Builtin::BI__builtin_addcll:
5030 case Builtin::BI__builtin_subcb:
5031 case Builtin::BI__builtin_subcs:
5032 case Builtin::BI__builtin_subc:
5033 case Builtin::BI__builtin_subcl:
5034 case Builtin::BI__builtin_subcll: {
5060 llvm::Intrinsic::ID IntrinsicId;
5061 switch (BuiltinID) {
5062 default: llvm_unreachable(
"Unknown multiprecision builtin id.");
5063 case Builtin::BI__builtin_addcb:
5064 case Builtin::BI__builtin_addcs:
5065 case Builtin::BI__builtin_addc:
5066 case Builtin::BI__builtin_addcl:
5067 case Builtin::BI__builtin_addcll:
5068 IntrinsicId = llvm::Intrinsic::uadd_with_overflow;
5070 case Builtin::BI__builtin_subcb:
5071 case Builtin::BI__builtin_subcs:
5072 case Builtin::BI__builtin_subc:
5073 case Builtin::BI__builtin_subcl:
5074 case Builtin::BI__builtin_subcll:
5075 IntrinsicId = llvm::Intrinsic::usub_with_overflow;
5080 llvm::Value *Carry1;
5083 llvm::Value *Carry2;
5085 Sum1, Carryin, Carry2);
5086 llvm::Value *CarryOut =
Builder.CreateZExt(
Builder.CreateOr(Carry1, Carry2),
5092 case Builtin::BI__builtin_add_overflow:
5093 case Builtin::BI__builtin_sub_overflow:
5094 case Builtin::BI__builtin_mul_overflow: {
5102 WidthAndSignedness LeftInfo =
5104 WidthAndSignedness RightInfo =
5106 WidthAndSignedness ResultInfo =
5113 RightInfo, ResultArg, ResultQTy,
5119 *
this, LeftArg, LeftInfo, RightArg, RightInfo, ResultArg, ResultQTy,
5122 WidthAndSignedness EncompassingInfo =
5125 llvm::Type *EncompassingLLVMTy =
5130 llvm::Intrinsic::ID IntrinsicId;
5131 switch (BuiltinID) {
5133 llvm_unreachable(
"Unknown overflow builtin id.");
5134 case Builtin::BI__builtin_add_overflow:
5135 IntrinsicId = EncompassingInfo.Signed
5136 ? llvm::Intrinsic::sadd_with_overflow
5137 : llvm::Intrinsic::uadd_with_overflow;
5139 case Builtin::BI__builtin_sub_overflow:
5140 IntrinsicId = EncompassingInfo.Signed
5141 ? llvm::Intrinsic::ssub_with_overflow
5142 : llvm::Intrinsic::usub_with_overflow;
5144 case Builtin::BI__builtin_mul_overflow:
5145 IntrinsicId = EncompassingInfo.Signed
5146 ? llvm::Intrinsic::smul_with_overflow
5147 : llvm::Intrinsic::umul_with_overflow;
5156 Left =
Builder.CreateIntCast(Left, EncompassingLLVMTy, LeftInfo.Signed);
5157 Right =
Builder.CreateIntCast(Right, EncompassingLLVMTy, RightInfo.Signed);
5160 llvm::Value *Overflow, *
Result;
5163 if (EncompassingInfo.Width > ResultInfo.Width) {
5166 llvm::Value *ResultTrunc =
Builder.CreateTrunc(
Result, ResultLLVMTy);
5170 llvm::Value *ResultTruncExt =
Builder.CreateIntCast(
5171 ResultTrunc, EncompassingLLVMTy, ResultInfo.Signed);
5172 llvm::Value *TruncationOverflow =
5175 Overflow =
Builder.CreateOr(Overflow, TruncationOverflow);
5187 case Builtin::BI__builtin_uadd_overflow:
5188 case Builtin::BI__builtin_uaddl_overflow:
5189 case Builtin::BI__builtin_uaddll_overflow:
5190 case Builtin::BI__builtin_usub_overflow:
5191 case Builtin::BI__builtin_usubl_overflow:
5192 case Builtin::BI__builtin_usubll_overflow:
5193 case Builtin::BI__builtin_umul_overflow:
5194 case Builtin::BI__builtin_umull_overflow:
5195 case Builtin::BI__builtin_umulll_overflow:
5196 case Builtin::BI__builtin_sadd_overflow:
5197 case Builtin::BI__builtin_saddl_overflow:
5198 case Builtin::BI__builtin_saddll_overflow:
5199 case Builtin::BI__builtin_ssub_overflow:
5200 case Builtin::BI__builtin_ssubl_overflow:
5201 case Builtin::BI__builtin_ssubll_overflow:
5202 case Builtin::BI__builtin_smul_overflow:
5203 case Builtin::BI__builtin_smull_overflow:
5204 case Builtin::BI__builtin_smulll_overflow: {
5214 llvm::Intrinsic::ID IntrinsicId;
5215 switch (BuiltinID) {
5216 default: llvm_unreachable(
"Unknown overflow builtin id.");
5217 case Builtin::BI__builtin_uadd_overflow:
5218 case Builtin::BI__builtin_uaddl_overflow:
5219 case Builtin::BI__builtin_uaddll_overflow:
5220 IntrinsicId = llvm::Intrinsic::uadd_with_overflow;
5222 case Builtin::BI__builtin_usub_overflow:
5223 case Builtin::BI__builtin_usubl_overflow:
5224 case Builtin::BI__builtin_usubll_overflow:
5225 IntrinsicId = llvm::Intrinsic::usub_with_overflow;
5227 case Builtin::BI__builtin_umul_overflow:
5228 case Builtin::BI__builtin_umull_overflow:
5229 case Builtin::BI__builtin_umulll_overflow:
5230 IntrinsicId = llvm::Intrinsic::umul_with_overflow;
5232 case Builtin::BI__builtin_sadd_overflow:
5233 case Builtin::BI__builtin_saddl_overflow:
5234 case Builtin::BI__builtin_saddll_overflow:
5235 IntrinsicId = llvm::Intrinsic::sadd_with_overflow;
5237 case Builtin::BI__builtin_ssub_overflow:
5238 case Builtin::BI__builtin_ssubl_overflow:
5239 case Builtin::BI__builtin_ssubll_overflow:
5240 IntrinsicId = llvm::Intrinsic::ssub_with_overflow;
5242 case Builtin::BI__builtin_smul_overflow:
5243 case Builtin::BI__builtin_smull_overflow:
5244 case Builtin::BI__builtin_smulll_overflow:
5245 IntrinsicId = llvm::Intrinsic::smul_with_overflow;
5256 case Builtin::BIaddressof:
5257 case Builtin::BI__addressof:
5258 case Builtin::BI__builtin_addressof:
5260 case Builtin::BI__builtin_function_start:
5263 case Builtin::BI__builtin_operator_new:
5266 case Builtin::BI__builtin_operator_delete:
5271 case Builtin::BI__builtin_is_aligned:
5273 case Builtin::BI__builtin_align_up:
5275 case Builtin::BI__builtin_align_down:
5278 case Builtin::BI__noop:
5281 case Builtin::BI__builtin_call_with_static_chain: {
5283 const Expr *Chain =
E->getArg(1);
5288 case Builtin::BI_InterlockedExchange8:
5289 case Builtin::BI_InterlockedExchange16:
5290 case Builtin::BI_InterlockedExchange:
5291 case Builtin::BI_InterlockedExchangePointer:
5294 case Builtin::BI_InterlockedCompareExchangePointer:
5295 case Builtin::BI_InterlockedCompareExchangePointer_nf: {
5297 llvm::IntegerType *IntType = IntegerType::get(
5303 RTy = Exchange->getType();
5304 Exchange =
Builder.CreatePtrToInt(Exchange, IntType);
5306 llvm::Value *Comparand =
5310 BuiltinID == Builtin::BI_InterlockedCompareExchangePointer_nf ?
5311 AtomicOrdering::Monotonic : AtomicOrdering::SequentiallyConsistent;
5314 Ordering, Ordering);
5315 Result->setVolatile(
true);
5321 case Builtin::BI_InterlockedCompareExchange8:
5322 case Builtin::BI_InterlockedCompareExchange16:
5323 case Builtin::BI_InterlockedCompareExchange:
5324 case Builtin::BI_InterlockedCompareExchange64:
5326 case Builtin::BI_InterlockedIncrement16:
5327 case Builtin::BI_InterlockedIncrement:
5330 case Builtin::BI_InterlockedDecrement16:
5331 case Builtin::BI_InterlockedDecrement:
5334 case Builtin::BI_InterlockedAnd8:
5335 case Builtin::BI_InterlockedAnd16:
5336 case Builtin::BI_InterlockedAnd:
5338 case Builtin::BI_InterlockedExchangeAdd8:
5339 case Builtin::BI_InterlockedExchangeAdd16:
5340 case Builtin::BI_InterlockedExchangeAdd:
5343 case Builtin::BI_InterlockedExchangeSub8:
5344 case Builtin::BI_InterlockedExchangeSub16:
5345 case Builtin::BI_InterlockedExchangeSub:
5348 case Builtin::BI_InterlockedOr8:
5349 case Builtin::BI_InterlockedOr16:
5350 case Builtin::BI_InterlockedOr:
5352 case Builtin::BI_InterlockedXor8:
5353 case Builtin::BI_InterlockedXor16:
5354 case Builtin::BI_InterlockedXor:
5357 case Builtin::BI_bittest64:
5358 case Builtin::BI_bittest:
5359 case Builtin::BI_bittestandcomplement64:
5360 case Builtin::BI_bittestandcomplement:
5361 case Builtin::BI_bittestandreset64:
5362 case Builtin::BI_bittestandreset:
5363 case Builtin::BI_bittestandset64:
5364 case Builtin::BI_bittestandset:
5365 case Builtin::BI_interlockedbittestandreset:
5366 case Builtin::BI_interlockedbittestandreset64:
5367 case Builtin::BI_interlockedbittestandset64:
5368 case Builtin::BI_interlockedbittestandset:
5369 case Builtin::BI_interlockedbittestandset_acq:
5370 case Builtin::BI_interlockedbittestandset_rel:
5371 case Builtin::BI_interlockedbittestandset_nf:
5372 case Builtin::BI_interlockedbittestandreset_acq:
5373 case Builtin::BI_interlockedbittestandreset_rel:
5374 case Builtin::BI_interlockedbittestandreset_nf:
5379 case Builtin::BI__iso_volatile_load8:
5380 case Builtin::BI__iso_volatile_load16:
5381 case Builtin::BI__iso_volatile_load32:
5382 case Builtin::BI__iso_volatile_load64:
5384 case Builtin::BI__iso_volatile_store8:
5385 case Builtin::BI__iso_volatile_store16:
5386 case Builtin::BI__iso_volatile_store32:
5387 case Builtin::BI__iso_volatile_store64:
5390 case Builtin::BI__builtin_ptrauth_sign_constant:
5393 case Builtin::BI__builtin_ptrauth_auth:
5394 case Builtin::BI__builtin_ptrauth_auth_and_resign:
5395 case Builtin::BI__builtin_ptrauth_blend_discriminator:
5396 case Builtin::BI__builtin_ptrauth_sign_generic_data:
5397 case Builtin::BI__builtin_ptrauth_sign_unauthenticated:
5398 case Builtin::BI__builtin_ptrauth_strip: {
5401 for (
auto argExpr :
E->arguments())
5405 llvm::Type *OrigValueType = Args[0]->getType();
5406 if (OrigValueType->isPointerTy())
5409 switch (BuiltinID) {
5410 case Builtin::BI__builtin_ptrauth_auth_and_resign:
5411 if (Args[4]->getType()->isPointerTy())
5415 case Builtin::BI__builtin_ptrauth_auth:
5416 case Builtin::BI__builtin_ptrauth_sign_unauthenticated:
5417 if (Args[2]->getType()->isPointerTy())
5421 case Builtin::BI__builtin_ptrauth_sign_generic_data:
5422 if (Args[1]->getType()->isPointerTy())
5426 case Builtin::BI__builtin_ptrauth_blend_discriminator:
5427 case Builtin::BI__builtin_ptrauth_strip:
5432 auto IntrinsicID = [&]() ->
unsigned {
5433 switch (BuiltinID) {
5434 case Builtin::BI__builtin_ptrauth_auth:
5435 return llvm::Intrinsic::ptrauth_auth;
5436 case Builtin::BI__builtin_ptrauth_auth_and_resign:
5437 return llvm::Intrinsic::ptrauth_resign;
5438 case Builtin::BI__builtin_ptrauth_blend_discriminator:
5439 return llvm::Intrinsic::ptrauth_blend;
5440 case Builtin::BI__builtin_ptrauth_sign_generic_data:
5441 return llvm::Intrinsic::ptrauth_sign_generic;
5442 case Builtin::BI__builtin_ptrauth_sign_unauthenticated:
5443 return llvm::Intrinsic::ptrauth_sign;
5444 case Builtin::BI__builtin_ptrauth_strip:
5445 return llvm::Intrinsic::ptrauth_strip;
5447 llvm_unreachable(
"bad ptrauth intrinsic");
5452 if (BuiltinID != Builtin::BI__builtin_ptrauth_sign_generic_data &&
5453 BuiltinID != Builtin::BI__builtin_ptrauth_blend_discriminator &&
5454 OrigValueType->isPointerTy()) {
5460 case Builtin::BI__exception_code:
5461 case Builtin::BI_exception_code:
5463 case Builtin::BI__exception_info:
5464 case Builtin::BI_exception_info:
5466 case Builtin::BI__abnormal_termination:
5467 case Builtin::BI_abnormal_termination:
5469 case Builtin::BI_setjmpex:
5470 if (
getTarget().getTriple().isOSMSVCRT() &&
E->getNumArgs() == 1 &&
5474 case Builtin::BI_setjmp:
5475 if (
getTarget().getTriple().isOSMSVCRT() &&
E->getNumArgs() == 1 &&
5477 if (
getTarget().getTriple().getArch() == llvm::Triple::x86)
5479 else if (
getTarget().getTriple().getArch() == llvm::Triple::aarch64)
5486 case Builtin::BImove:
5487 case Builtin::BImove_if_noexcept:
5488 case Builtin::BIforward:
5489 case Builtin::BIforward_like:
5490 case Builtin::BIas_const:
5492 case Builtin::BI__GetExceptionInfo: {
5493 if (llvm::GlobalVariable *GV =
5499 case Builtin::BI__fastfail:
5502 case Builtin::BI__builtin_coro_id:
5504 case Builtin::BI__builtin_coro_promise:
5506 case Builtin::BI__builtin_coro_resume:
5509 case Builtin::BI__builtin_coro_frame:
5511 case Builtin::BI__builtin_coro_noop:
5513 case Builtin::BI__builtin_coro_free:
5515 case Builtin::BI__builtin_coro_destroy:
5518 case Builtin::BI__builtin_coro_done:
5520 case Builtin::BI__builtin_coro_alloc:
5522 case Builtin::BI__builtin_coro_begin:
5524 case Builtin::BI__builtin_coro_end:
5526 case Builtin::BI__builtin_coro_suspend:
5528 case Builtin::BI__builtin_coro_size:
5530 case Builtin::BI__builtin_coro_align:
5534 case Builtin::BIread_pipe:
5535 case Builtin::BIwrite_pipe: {
5539 Value *PacketSize = OpenCLRT.getPipeElemSize(
E->getArg(0));
5540 Value *PacketAlign = OpenCLRT.getPipeElemAlign(
E->getArg(0));
5543 unsigned GenericAS =
5545 llvm::Type *I8PTy = llvm::PointerType::get(
getLLVMContext(), GenericAS);
5548 if (2U ==
E->getNumArgs()) {
5549 const char *Name = (BuiltinID == Builtin::BIread_pipe) ?
"__read_pipe_2"
5554 llvm::FunctionType *FTy = llvm::FunctionType::get(
5559 {Arg0, BCast, PacketSize, PacketAlign}));
5561 assert(4 ==
E->getNumArgs() &&
5562 "Illegal number of parameters to pipe function");
5563 const char *Name = (BuiltinID == Builtin::BIread_pipe) ?
"__read_pipe_4"
5570 llvm::FunctionType *FTy = llvm::FunctionType::get(
5579 {Arg0, Arg1, Arg2, BCast, PacketSize, PacketAlign}));
5584 case Builtin::BIreserve_read_pipe:
5585 case Builtin::BIreserve_write_pipe:
5586 case Builtin::BIwork_group_reserve_read_pipe:
5587 case Builtin::BIwork_group_reserve_write_pipe:
5588 case Builtin::BIsub_group_reserve_read_pipe:
5589 case Builtin::BIsub_group_reserve_write_pipe: {
5592 if (BuiltinID == Builtin::BIreserve_read_pipe)
5593 Name =
"__reserve_read_pipe";
5594 else if (BuiltinID == Builtin::BIreserve_write_pipe)
5595 Name =
"__reserve_write_pipe";
5596 else if (BuiltinID == Builtin::BIwork_group_reserve_read_pipe)
5597 Name =
"__work_group_reserve_read_pipe";
5598 else if (BuiltinID == Builtin::BIwork_group_reserve_write_pipe)
5599 Name =
"__work_group_reserve_write_pipe";
5600 else if (BuiltinID == Builtin::BIsub_group_reserve_read_pipe)
5601 Name =
"__sub_group_reserve_read_pipe";
5603 Name =
"__sub_group_reserve_write_pipe";
5609 Value *PacketSize = OpenCLRT.getPipeElemSize(
E->getArg(0));
5610 Value *PacketAlign = OpenCLRT.getPipeElemAlign(
E->getArg(0));
5614 llvm::FunctionType *FTy = llvm::FunctionType::get(
5621 {Arg0, Arg1, PacketSize, PacketAlign}));
5625 case Builtin::BIcommit_read_pipe:
5626 case Builtin::BIcommit_write_pipe:
5627 case Builtin::BIwork_group_commit_read_pipe:
5628 case Builtin::BIwork_group_commit_write_pipe:
5629 case Builtin::BIsub_group_commit_read_pipe:
5630 case Builtin::BIsub_group_commit_write_pipe: {
5632 if (BuiltinID == Builtin::BIcommit_read_pipe)
5633 Name =
"__commit_read_pipe";
5634 else if (BuiltinID == Builtin::BIcommit_write_pipe)
5635 Name =
"__commit_write_pipe";
5636 else if (BuiltinID == Builtin::BIwork_group_commit_read_pipe)
5637 Name =
"__work_group_commit_read_pipe";
5638 else if (BuiltinID == Builtin::BIwork_group_commit_write_pipe)
5639 Name =
"__work_group_commit_write_pipe";
5640 else if (BuiltinID == Builtin::BIsub_group_commit_read_pipe)
5641 Name =
"__sub_group_commit_read_pipe";
5643 Name =
"__sub_group_commit_write_pipe";
5648 Value *PacketSize = OpenCLRT.getPipeElemSize(
E->getArg(0));
5649 Value *PacketAlign = OpenCLRT.getPipeElemAlign(
E->getArg(0));
5653 llvm::FunctionType *FTy =
5658 {Arg0, Arg1, PacketSize, PacketAlign}));
5661 case Builtin::BIget_pipe_num_packets:
5662 case Builtin::BIget_pipe_max_packets: {
5663 const char *BaseName;
5665 if (BuiltinID == Builtin::BIget_pipe_num_packets)
5666 BaseName =
"__get_pipe_num_packets";
5668 BaseName =
"__get_pipe_max_packets";
5669 std::string Name = std::string(BaseName) +
5670 std::string(PipeTy->isReadOnly() ?
"_ro" :
"_wo");
5675 Value *PacketSize = OpenCLRT.getPipeElemSize(
E->getArg(0));
5676 Value *PacketAlign = OpenCLRT.getPipeElemAlign(
E->getArg(0));
5678 llvm::FunctionType *FTy = llvm::FunctionType::get(
5682 {Arg0, PacketSize, PacketAlign}));
5686 case Builtin::BIto_global:
5687 case Builtin::BIto_local:
5688 case Builtin::BIto_private: {
5690 auto NewArgT = llvm::PointerType::get(
5693 auto NewRetT = llvm::PointerType::get(
5697 auto FTy = llvm::FunctionType::get(NewRetT, {NewArgT},
false);
5698 llvm::Value *NewArg;
5699 if (Arg0->
getType()->getPointerAddressSpace() !=
5700 NewArgT->getPointerAddressSpace())
5703 NewArg =
Builder.CreateBitOrPointerCast(Arg0, NewArgT);
5704 auto NewName = std::string(
"__") +
E->getDirectCallee()->getName().str();
5719 case Builtin::BIenqueue_kernel: {
5721 unsigned NumArgs =
E->getNumArgs();
5724 llvm::Type *GenericVoidPtrTy =
Builder.getPtrTy(
5736 Name =
"__enqueue_kernel_basic";
5737 llvm::Type *ArgTys[] = {QueueTy,
Int32Ty, RangeTy, GenericVoidPtrTy,
5739 llvm::FunctionType *FTy = llvm::FunctionType::get(
5745 Builder.CreatePointerCast(Info.KernelHandle, GenericVoidPtrTy);
5746 llvm::Value *
Block =
5747 Builder.CreatePointerCast(Info.BlockArg, GenericVoidPtrTy);
5749 AttrBuilder B(
Builder.getContext());
5751 llvm::AttributeList ByValAttrSet =
5752 llvm::AttributeList::get(
CGM.
getModule().getContext(), 3U, B);
5756 {Queue, Flags, Range, Kernel, Block});
5757 RTCall->setAttributes(ByValAttrSet);
5760 assert(NumArgs >= 5 &&
"Invalid enqueue_kernel signature");
5764 auto CreateArrayForSizeVar = [=](
unsigned First)
5765 -> std::tuple<llvm::Value *, llvm::Value *, llvm::Value *> {
5766 llvm::APInt ArraySize(32, NumArgs -
First);
5768 getContext().getSizeType(), ArraySize,
nullptr,
5772 llvm::Value *TmpPtr = Tmp.getPointer();
5775 llvm::Value *ElemPtr;
5778 auto *
Zero = llvm::ConstantInt::get(
IntTy, 0);
5779 for (
unsigned I =
First; I < NumArgs; ++I) {
5780 auto *Index = llvm::ConstantInt::get(
IntTy, I -
First);
5790 return std::tie(ElemPtr, TmpSize, TmpPtr);
5796 Name =
"__enqueue_kernel_varargs";
5800 Builder.CreatePointerCast(Info.KernelHandle, GenericVoidPtrTy);
5801 auto *
Block =
Builder.CreatePointerCast(Info.BlockArg, GenericVoidPtrTy);
5802 llvm::Value *ElemPtr, *TmpSize, *TmpPtr;
5803 std::tie(ElemPtr, TmpSize, TmpPtr) = CreateArrayForSizeVar(4);
5807 llvm::Value *
const Args[] = {Queue, Flags,
5811 llvm::Type *
const ArgTys[] = {
5812 QueueTy,
IntTy, RangeTy, GenericVoidPtrTy,
5813 GenericVoidPtrTy,
IntTy, ElemPtr->getType()};
5815 llvm::FunctionType *FTy = llvm::FunctionType::get(
Int32Ty, ArgTys,
false);
5824 llvm::PointerType *PtrTy = llvm::PointerType::get(
5828 llvm::Value *NumEvents =
5834 llvm::Value *EventWaitList =
nullptr;
5837 EventWaitList = llvm::ConstantPointerNull::get(PtrTy);
5844 EventWaitList =
Builder.CreatePointerCast(EventWaitList, PtrTy);
5846 llvm::Value *EventRet =
nullptr;
5849 EventRet = llvm::ConstantPointerNull::get(PtrTy);
5858 Builder.CreatePointerCast(Info.KernelHandle, GenericVoidPtrTy);
5859 llvm::Value *
Block =
5860 Builder.CreatePointerCast(Info.BlockArg, GenericVoidPtrTy);
5862 std::vector<llvm::Type *> ArgTys = {
5864 PtrTy, PtrTy, GenericVoidPtrTy, GenericVoidPtrTy};
5866 std::vector<llvm::Value *> Args = {Queue, Flags,
Range,
5867 NumEvents, EventWaitList, EventRet,
5872 Name =
"__enqueue_kernel_basic_events";
5873 llvm::FunctionType *FTy = llvm::FunctionType::get(
5881 Args.push_back(ConstantInt::get(
Int32Ty, NumArgs - 7));
5883 Name =
"__enqueue_kernel_events_varargs";
5885 llvm::Value *ElemPtr, *TmpSize, *TmpPtr;
5886 std::tie(ElemPtr, TmpSize, TmpPtr) = CreateArrayForSizeVar(7);
5887 Args.push_back(ElemPtr);
5888 ArgTys.push_back(ElemPtr->getType());
5890 llvm::FunctionType *FTy = llvm::FunctionType::get(
5899 llvm_unreachable(
"Unexpected enqueue_kernel signature");
5903 case Builtin::BIget_kernel_work_group_size: {
5904 llvm::Type *GenericVoidPtrTy =
Builder.getPtrTy(
5909 Builder.CreatePointerCast(Info.KernelHandle, GenericVoidPtrTy);
5910 Value *Arg =
Builder.CreatePointerCast(Info.BlockArg, GenericVoidPtrTy);
5913 llvm::FunctionType::get(
IntTy, {GenericVoidPtrTy, GenericVoidPtrTy},
5915 "__get_kernel_work_group_size_impl"),
5918 case Builtin::BIget_kernel_preferred_work_group_size_multiple: {
5919 llvm::Type *GenericVoidPtrTy =
Builder.getPtrTy(
5924 Builder.CreatePointerCast(Info.KernelHandle, GenericVoidPtrTy);
5925 Value *Arg =
Builder.CreatePointerCast(Info.BlockArg, GenericVoidPtrTy);
5928 llvm::FunctionType::get(
IntTy, {GenericVoidPtrTy, GenericVoidPtrTy},
5930 "__get_kernel_preferred_work_group_size_multiple_impl"),
5933 case Builtin::BIget_kernel_max_sub_group_size_for_ndrange:
5934 case Builtin::BIget_kernel_sub_group_count_for_ndrange: {
5935 llvm::Type *GenericVoidPtrTy =
Builder.getPtrTy(
5942 Builder.CreatePointerCast(Info.KernelHandle, GenericVoidPtrTy);
5945 BuiltinID == Builtin::BIget_kernel_max_sub_group_size_for_ndrange
5946 ?
"__get_kernel_max_sub_group_size_for_ndrange_impl"
5947 :
"__get_kernel_sub_group_count_for_ndrange_impl";
5950 llvm::FunctionType::get(
5951 IntTy, {NDRange->getType(), GenericVoidPtrTy, GenericVoidPtrTy},
5954 {NDRange, Kernel, Block}));
5956 case Builtin::BI__builtin_store_half:
5957 case Builtin::BI__builtin_store_halff: {
5964 case Builtin::BI__builtin_load_half: {
5969 case Builtin::BI__builtin_load_halff: {
5974 case Builtin::BI__builtin_printf:
5975 case Builtin::BIprintf:
5976 if (
getTarget().getTriple().isNVPTX() ||
5979 getTarget().getTriple().getVendor() == Triple::VendorType::AMD)) {
5982 if ((
getTarget().getTriple().isAMDGCN() ||
5989 case Builtin::BI__builtin_canonicalize:
5990 case Builtin::BI__builtin_canonicalizef:
5991 case Builtin::BI__builtin_canonicalizef16:
5992 case Builtin::BI__builtin_canonicalizel:
5994 emitBuiltinWithOneOverloadedType<1>(*
this,
E, Intrinsic::canonicalize));
5996 case Builtin::BI__builtin_thread_pointer: {
5997 if (!
getContext().getTargetInfo().isTLSSupported())
6002 case Builtin::BI__builtin_os_log_format:
6005 case Builtin::BI__xray_customevent: {
6018 auto FTy = F->getFunctionType();
6019 auto Arg0 =
E->getArg(0);
6021 auto Arg0Ty = Arg0->
getType();
6022 auto PTy0 = FTy->getParamType(0);
6023 if (PTy0 != Arg0Val->getType()) {
6024 if (Arg0Ty->isArrayType())
6027 Arg0Val =
Builder.CreatePointerCast(Arg0Val, PTy0);
6030 auto PTy1 = FTy->getParamType(1);
6032 Arg1 =
Builder.CreateTruncOrBitCast(Arg1, PTy1);
6036 case Builtin::BI__xray_typedevent: {
6052 auto FTy = F->getFunctionType();
6054 auto PTy0 = FTy->getParamType(0);
6056 Arg0 =
Builder.CreateTruncOrBitCast(Arg0, PTy0);
6057 auto Arg1 =
E->getArg(1);
6059 auto Arg1Ty = Arg1->
getType();
6060 auto PTy1 = FTy->getParamType(1);
6061 if (PTy1 != Arg1Val->getType()) {
6062 if (Arg1Ty->isArrayType())
6065 Arg1Val =
Builder.CreatePointerCast(Arg1Val, PTy1);
6068 auto PTy2 = FTy->getParamType(2);
6070 Arg2 =
Builder.CreateTruncOrBitCast(Arg2, PTy2);
6074 case Builtin::BI__builtin_ms_va_start:
6075 case Builtin::BI__builtin_ms_va_end:
6078 BuiltinID == Builtin::BI__builtin_ms_va_start));
6080 case Builtin::BI__builtin_ms_va_copy: {
6097 case Builtin::BI__builtin_get_device_side_mangled_name: {
6125 LargestVectorWidth = std::max(LargestVectorWidth, VectorWidth);
6129 Intrinsic::ID IntrinsicID = Intrinsic::not_intrinsic;
6131 llvm::Triple::getArchTypePrefix(
getTarget().getTriple().getArch());
6132 if (!Prefix.empty()) {
6133 IntrinsicID = Intrinsic::getIntrinsicForClangBuiltin(Prefix.data(), Name);
6134 if (IntrinsicID == Intrinsic::not_intrinsic && Prefix ==
"spv" &&
6135 getTarget().getTriple().getOS() == llvm::Triple::OSType::AMDHSA)
6136 IntrinsicID = Intrinsic::getIntrinsicForClangBuiltin(
"amdgcn", Name);
6140 if (IntrinsicID == Intrinsic::not_intrinsic)
6141 IntrinsicID = Intrinsic::getIntrinsicForMSBuiltin(Prefix.data(), Name);
6144 if (IntrinsicID != Intrinsic::not_intrinsic) {
6149 unsigned ICEArguments = 0;
6155 llvm::FunctionType *FTy = F->getFunctionType();
6157 for (
unsigned i = 0, e =
E->getNumArgs(); i != e; ++i) {
6161 llvm::Type *PTy = FTy->getParamType(i);
6162 if (PTy != ArgValue->
getType()) {
6164 if (
auto *PtrTy = dyn_cast<llvm::PointerType>(PTy)) {
6165 if (PtrTy->getAddressSpace() !=
6166 ArgValue->
getType()->getPointerAddressSpace()) {
6169 PtrTy->getAddressSpace()));
6175 if (PTy->isX86_AMXTy())
6176 ArgValue =
Builder.CreateIntrinsic(Intrinsic::x86_cast_vector_to_tile,
6177 {ArgValue->
getType()}, {ArgValue});
6179 ArgValue =
Builder.CreateBitCast(ArgValue, PTy);
6182 Args.push_back(ArgValue);
6188 llvm::Type *RetTy =
VoidTy;
6192 if (RetTy !=
V->getType()) {
6194 if (
auto *PtrTy = dyn_cast<llvm::PointerType>(RetTy)) {
6195 if (PtrTy->getAddressSpace() !=
V->getType()->getPointerAddressSpace()) {
6198 PtrTy->getAddressSpace()));
6204 if (
V->getType()->isX86_AMXTy())
6205 V =
Builder.CreateIntrinsic(Intrinsic::x86_cast_tile_to_vector, {RetTy},
6211 if (RetTy->isVoidTy())
6231 if (
V->getType()->isVoidTy())
6238 llvm_unreachable(
"No current target builtin returns complex");
6240 llvm_unreachable(
"Bad evaluation kind in EmitBuiltinExpr");
6259 llvm::Triple::ArchType Arch) {
6271 case llvm::Triple::arm:
6272 case llvm::Triple::armeb:
6273 case llvm::Triple::thumb:
6274 case llvm::Triple::thumbeb:
6276 case llvm::Triple::aarch64:
6277 case llvm::Triple::aarch64_32:
6278 case llvm::Triple::aarch64_be:
6280 case llvm::Triple::bpfeb:
6281 case llvm::Triple::bpfel:
6283 case llvm::Triple::x86:
6284 case llvm::Triple::x86_64:
6286 case llvm::Triple::ppc:
6287 case llvm::Triple::ppcle:
6288 case llvm::Triple::ppc64:
6289 case llvm::Triple::ppc64le:
6291 case llvm::Triple::r600:
6292 case llvm::Triple::amdgcn:
6294 case llvm::Triple::systemz:
6296 case llvm::Triple::nvptx:
6297 case llvm::Triple::nvptx64:
6299 case llvm::Triple::wasm32:
6300 case llvm::Triple::wasm64:
6302 case llvm::Triple::hexagon:
6304 case llvm::Triple::riscv32:
6305 case llvm::Triple::riscv64:
6307 case llvm::Triple::spirv64:
6320 assert(
getContext().getAuxTargetInfo() &&
"Missing aux target info");
6332 bool HasLegalHalfType =
true,
6334 bool AllowBFloatArgsAndRet =
true) {
6335 int IsQuad = TypeFlags.
isQuad();
6339 return llvm::FixedVectorType::get(CGF->
Int8Ty, V1Ty ? 1 : (8 << IsQuad));
6342 return llvm::FixedVectorType::get(CGF->
Int16Ty, V1Ty ? 1 : (4 << IsQuad));
6344 if (AllowBFloatArgsAndRet)
6345 return llvm::FixedVectorType::get(CGF->
BFloatTy, V1Ty ? 1 : (4 << IsQuad));
6347 return llvm::FixedVectorType::get(CGF->
Int16Ty, V1Ty ? 1 : (4 << IsQuad));
6349 if (HasLegalHalfType)
6350 return llvm::FixedVectorType::get(CGF->
HalfTy, V1Ty ? 1 : (4 << IsQuad));
6352 return llvm::FixedVectorType::get(CGF->
Int16Ty, V1Ty ? 1 : (4 << IsQuad));
6354 return llvm::FixedVectorType::get(CGF->
Int32Ty, V1Ty ? 1 : (2 << IsQuad));
6357 return llvm::FixedVectorType::get(CGF->
Int64Ty, V1Ty ? 1 : (1 << IsQuad));
6362 return llvm::FixedVectorType::get(CGF->
Int8Ty, 16);
6364 return llvm::FixedVectorType::get(CGF->
FloatTy, V1Ty ? 1 : (2 << IsQuad));
6366 return llvm::FixedVectorType::get(CGF->
DoubleTy, V1Ty ? 1 : (1 << IsQuad));
6368 llvm_unreachable(
"Unknown vector element type!");
6373 int IsQuad = IntTypeFlags.
isQuad();
6376 return llvm::FixedVectorType::get(CGF->
HalfTy, (4 << IsQuad));
6378 return llvm::FixedVectorType::get(CGF->
FloatTy, (2 << IsQuad));
6380 return llvm::FixedVectorType::get(CGF->
DoubleTy, (1 << IsQuad));
6382 llvm_unreachable(
"Type can't be converted to floating-point!");
6387 const ElementCount &Count) {
6388 Value *SV = llvm::ConstantVector::getSplat(Count,
C);
6389 return Builder.CreateShuffleVector(
V,
V, SV,
"lane");
6393 ElementCount EC = cast<llvm::VectorType>(
V->getType())->getElementCount();
6399 unsigned shift,
bool rightshift) {
6401 for (Function::const_arg_iterator ai = F->arg_begin(), ae = F->arg_end();
6402 ai != ae; ++ai, ++j) {
6403 if (F->isConstrainedFPIntrinsic())
6404 if (ai->getType()->isMetadataTy())
6406 if (shift > 0 && shift == j)
6409 Ops[j] =
Builder.CreateBitCast(Ops[j], ai->getType(), name);
6412 if (F->isConstrainedFPIntrinsic())
6413 return Builder.CreateConstrainedFPCall(F, Ops, name);
6415 return Builder.CreateCall(F, Ops, name);
6420 int SV = cast<ConstantInt>(
V)->getSExtValue();
6421 return ConstantInt::get(Ty, neg ? -SV : SV);
6426 llvm::Type *Ty,
bool usgn,
6428 llvm::VectorType *VTy = cast<llvm::VectorType>(Ty);
6430 int ShiftAmt = cast<ConstantInt>(Shift)->getSExtValue();
6431 int EltSize = VTy->getScalarSizeInBits();
6433 Vec =
Builder.CreateBitCast(Vec, Ty);
6437 if (ShiftAmt == EltSize) {
6440 return llvm::ConstantAggregateZero::get(VTy);
6445 Shift = ConstantInt::get(VTy->getElementType(), ShiftAmt);
6451 return Builder.CreateLShr(Vec, Shift, name);
6453 return Builder.CreateAShr(Vec, Shift, name);
6479struct ARMVectorIntrinsicInfo {
6480 const char *NameHint;
6482 unsigned LLVMIntrinsic;
6483 unsigned AltLLVMIntrinsic;
6486 bool operator<(
unsigned RHSBuiltinID)
const {
6487 return BuiltinID < RHSBuiltinID;
6489 bool operator<(
const ARMVectorIntrinsicInfo &TE)
const {
6490 return BuiltinID < TE.BuiltinID;
6495#define NEONMAP0(NameBase) \
6496 { #NameBase, NEON::BI__builtin_neon_ ## NameBase, 0, 0, 0 }
6498#define NEONMAP1(NameBase, LLVMIntrinsic, TypeModifier) \
6499 { #NameBase, NEON:: BI__builtin_neon_ ## NameBase, \
6500 Intrinsic::LLVMIntrinsic, 0, TypeModifier }
6502#define NEONMAP2(NameBase, LLVMIntrinsic, AltLLVMIntrinsic, TypeModifier) \
6503 { #NameBase, NEON:: BI__builtin_neon_ ## NameBase, \
6504 Intrinsic::LLVMIntrinsic, Intrinsic::AltLLVMIntrinsic, \
6508 NEONMAP1(__a32_vcvt_bf16_f32, arm_neon_vcvtfp2bf, 0),
6515 NEONMAP1(vabs_v, arm_neon_vabs, 0),
6516 NEONMAP1(vabsq_v, arm_neon_vabs, 0),
6520 NEONMAP1(vaesdq_u8, arm_neon_aesd, 0),
6521 NEONMAP1(vaeseq_u8, arm_neon_aese, 0),
6522 NEONMAP1(vaesimcq_u8, arm_neon_aesimc, 0),
6523 NEONMAP1(vaesmcq_u8, arm_neon_aesmc, 0),
6524 NEONMAP1(vbfdot_f32, arm_neon_bfdot, 0),
6525 NEONMAP1(vbfdotq_f32, arm_neon_bfdot, 0),
6526 NEONMAP1(vbfmlalbq_f32, arm_neon_bfmlalb, 0),
6527 NEONMAP1(vbfmlaltq_f32, arm_neon_bfmlalt, 0),
6528 NEONMAP1(vbfmmlaq_f32, arm_neon_bfmmla, 0),
6541 NEONMAP1(vcage_v, arm_neon_vacge, 0),
6542 NEONMAP1(vcageq_v, arm_neon_vacge, 0),
6543 NEONMAP1(vcagt_v, arm_neon_vacgt, 0),
6544 NEONMAP1(vcagtq_v, arm_neon_vacgt, 0),
6545 NEONMAP1(vcale_v, arm_neon_vacge, 0),
6546 NEONMAP1(vcaleq_v, arm_neon_vacge, 0),
6547 NEONMAP1(vcalt_v, arm_neon_vacgt, 0),
6548 NEONMAP1(vcaltq_v, arm_neon_vacgt, 0),
6565 NEONMAP1(vcvt_f16_f32, arm_neon_vcvtfp2hf, 0),
6568 NEONMAP1(vcvt_f32_f16, arm_neon_vcvthf2fp, 0),
6570 NEONMAP1(vcvt_n_f16_s16, arm_neon_vcvtfxs2fp, 0),
6571 NEONMAP1(vcvt_n_f16_u16, arm_neon_vcvtfxu2fp, 0),
6572 NEONMAP2(vcvt_n_f32_v, arm_neon_vcvtfxu2fp, arm_neon_vcvtfxs2fp, 0),
6573 NEONMAP1(vcvt_n_s16_f16, arm_neon_vcvtfp2fxs, 0),
6574 NEONMAP1(vcvt_n_s32_v, arm_neon_vcvtfp2fxs, 0),
6575 NEONMAP1(vcvt_n_s64_v, arm_neon_vcvtfp2fxs, 0),
6576 NEONMAP1(vcvt_n_u16_f16, arm_neon_vcvtfp2fxu, 0),
6577 NEONMAP1(vcvt_n_u32_v, arm_neon_vcvtfp2fxu, 0),
6578 NEONMAP1(vcvt_n_u64_v, arm_neon_vcvtfp2fxu, 0),
6585 NEONMAP1(vcvta_s16_f16, arm_neon_vcvtas, 0),
6586 NEONMAP1(vcvta_s32_v, arm_neon_vcvtas, 0),
6587 NEONMAP1(vcvta_s64_v, arm_neon_vcvtas, 0),
6588 NEONMAP1(vcvta_u16_f16, arm_neon_vcvtau, 0),
6589 NEONMAP1(vcvta_u32_v, arm_neon_vcvtau, 0),
6590 NEONMAP1(vcvta_u64_v, arm_neon_vcvtau, 0),
6591 NEONMAP1(vcvtaq_s16_f16, arm_neon_vcvtas, 0),
6592 NEONMAP1(vcvtaq_s32_v, arm_neon_vcvtas, 0),
6593 NEONMAP1(vcvtaq_s64_v, arm_neon_vcvtas, 0),
6594 NEONMAP1(vcvtaq_u16_f16, arm_neon_vcvtau, 0),
6595 NEONMAP1(vcvtaq_u32_v, arm_neon_vcvtau, 0),
6596 NEONMAP1(vcvtaq_u64_v, arm_neon_vcvtau, 0),
6597 NEONMAP1(vcvth_bf16_f32, arm_neon_vcvtbfp2bf, 0),
6598 NEONMAP1(vcvtm_s16_f16, arm_neon_vcvtms, 0),
6599 NEONMAP1(vcvtm_s32_v, arm_neon_vcvtms, 0),
6600 NEONMAP1(vcvtm_s64_v, arm_neon_vcvtms, 0),
6601 NEONMAP1(vcvtm_u16_f16, arm_neon_vcvtmu, 0),
6602 NEONMAP1(vcvtm_u32_v, arm_neon_vcvtmu, 0),
6603 NEONMAP1(vcvtm_u64_v, arm_neon_vcvtmu, 0),
6604 NEONMAP1(vcvtmq_s16_f16, arm_neon_vcvtms, 0),
6605 NEONMAP1(vcvtmq_s32_v, arm_neon_vcvtms, 0),
6606 NEONMAP1(vcvtmq_s64_v, arm_neon_vcvtms, 0),
6607 NEONMAP1(vcvtmq_u16_f16, arm_neon_vcvtmu, 0),
6608 NEONMAP1(vcvtmq_u32_v, arm_neon_vcvtmu, 0),
6609 NEONMAP1(vcvtmq_u64_v, arm_neon_vcvtmu, 0),
6610 NEONMAP1(vcvtn_s16_f16, arm_neon_vcvtns, 0),
6611 NEONMAP1(vcvtn_s32_v, arm_neon_vcvtns, 0),
6612 NEONMAP1(vcvtn_s64_v, arm_neon_vcvtns, 0),
6613 NEONMAP1(vcvtn_u16_f16, arm_neon_vcvtnu, 0),
6614 NEONMAP1(vcvtn_u32_v, arm_neon_vcvtnu, 0),
6615 NEONMAP1(vcvtn_u64_v, arm_neon_vcvtnu, 0),
6616 NEONMAP1(vcvtnq_s16_f16, arm_neon_vcvtns, 0),
6617 NEONMAP1(vcvtnq_s32_v, arm_neon_vcvtns, 0),
6618 NEONMAP1(vcvtnq_s64_v, arm_neon_vcvtns, 0),
6619 NEONMAP1(vcvtnq_u16_f16, arm_neon_vcvtnu, 0),
6620 NEONMAP1(vcvtnq_u32_v, arm_neon_vcvtnu, 0),
6621 NEONMAP1(vcvtnq_u64_v, arm_neon_vcvtnu, 0),
6622 NEONMAP1(vcvtp_s16_f16, arm_neon_vcvtps, 0),
6623 NEONMAP1(vcvtp_s32_v, arm_neon_vcvtps, 0),
6624 NEONMAP1(vcvtp_s64_v, arm_neon_vcvtps, 0),
6625 NEONMAP1(vcvtp_u16_f16, arm_neon_vcvtpu, 0),
6626 NEONMAP1(vcvtp_u32_v, arm_neon_vcvtpu, 0),
6627 NEONMAP1(vcvtp_u64_v, arm_neon_vcvtpu, 0),
6628 NEONMAP1(vcvtpq_s16_f16, arm_neon_vcvtps, 0),
6629 NEONMAP1(vcvtpq_s32_v, arm_neon_vcvtps, 0),
6630 NEONMAP1(vcvtpq_s64_v, arm_neon_vcvtps, 0),
6631 NEONMAP1(vcvtpq_u16_f16, arm_neon_vcvtpu, 0),
6632 NEONMAP1(vcvtpq_u32_v, arm_neon_vcvtpu, 0),
6633 NEONMAP1(vcvtpq_u64_v, arm_neon_vcvtpu, 0),
6637 NEONMAP1(vcvtq_n_f16_s16, arm_neon_vcvtfxs2fp, 0),
6638 NEONMAP1(vcvtq_n_f16_u16, arm_neon_vcvtfxu2fp, 0),
6639 NEONMAP2(vcvtq_n_f32_v, arm_neon_vcvtfxu2fp, arm_neon_vcvtfxs2fp, 0),
6640 NEONMAP1(vcvtq_n_s16_f16, arm_neon_vcvtfp2fxs, 0),
6641 NEONMAP1(vcvtq_n_s32_v, arm_neon_vcvtfp2fxs, 0),
6642 NEONMAP1(vcvtq_n_s64_v, arm_neon_vcvtfp2fxs, 0),
6643 NEONMAP1(vcvtq_n_u16_f16, arm_neon_vcvtfp2fxu, 0),
6644 NEONMAP1(vcvtq_n_u32_v, arm_neon_vcvtfp2fxu, 0),
6645 NEONMAP1(vcvtq_n_u64_v, arm_neon_vcvtfp2fxu, 0),
6652 NEONMAP1(vdot_s32, arm_neon_sdot, 0),
6653 NEONMAP1(vdot_u32, arm_neon_udot, 0),
6654 NEONMAP1(vdotq_s32, arm_neon_sdot, 0),
6655 NEONMAP1(vdotq_u32, arm_neon_udot, 0),
6665 NEONMAP1(vld1_v, arm_neon_vld1, 0),
6666 NEONMAP1(vld1_x2_v, arm_neon_vld1x2, 0),
6667 NEONMAP1(vld1_x3_v, arm_neon_vld1x3, 0),
6668 NEONMAP1(vld1_x4_v, arm_neon_vld1x4, 0),
6670 NEONMAP1(vld1q_v, arm_neon_vld1, 0),
6671 NEONMAP1(vld1q_x2_v, arm_neon_vld1x2, 0),
6672 NEONMAP1(vld1q_x3_v, arm_neon_vld1x3, 0),
6673 NEONMAP1(vld1q_x4_v, arm_neon_vld1x4, 0),
6674 NEONMAP1(vld2_dup_v, arm_neon_vld2dup, 0),
6675 NEONMAP1(vld2_lane_v, arm_neon_vld2lane, 0),
6676 NEONMAP1(vld2_v, arm_neon_vld2, 0),
6677 NEONMAP1(vld2q_dup_v, arm_neon_vld2dup, 0),
6678 NEONMAP1(vld2q_lane_v, arm_neon_vld2lane, 0),
6679 NEONMAP1(vld2q_v, arm_neon_vld2, 0),
6680 NEONMAP1(vld3_dup_v, arm_neon_vld3dup, 0),
6681 NEONMAP1(vld3_lane_v, arm_neon_vld3lane, 0),
6682 NEONMAP1(vld3_v, arm_neon_vld3, 0),
6683 NEONMAP1(vld3q_dup_v, arm_neon_vld3dup, 0),
6684 NEONMAP1(vld3q_lane_v, arm_neon_vld3lane, 0),
6685 NEONMAP1(vld3q_v, arm_neon_vld3, 0),
6686 NEONMAP1(vld4_dup_v, arm_neon_vld4dup, 0),
6687 NEONMAP1(vld4_lane_v, arm_neon_vld4lane, 0),
6688 NEONMAP1(vld4_v, arm_neon_vld4, 0),
6689 NEONMAP1(vld4q_dup_v, arm_neon_vld4dup, 0),
6690 NEONMAP1(vld4q_lane_v, arm_neon_vld4lane, 0),
6691 NEONMAP1(vld4q_v, arm_neon_vld4, 0),
6700 NEONMAP1(vmmlaq_s32, arm_neon_smmla, 0),
6701 NEONMAP1(vmmlaq_u32, arm_neon_ummla, 0),
6719 NEONMAP2(vqdmlal_v, arm_neon_vqdmull, sadd_sat, 0),
6720 NEONMAP2(vqdmlsl_v, arm_neon_vqdmull, ssub_sat, 0),
6744 NEONMAP1(vqshlu_n_v, arm_neon_vqshiftsu, 0),
6745 NEONMAP1(vqshluq_n_v, arm_neon_vqshiftsu, 0),
6749 NEONMAP2(vrecpe_v, arm_neon_vrecpe, arm_neon_vrecpe, 0),
6750 NEONMAP2(vrecpeq_v, arm_neon_vrecpe, arm_neon_vrecpe, 0),
6773 NEONMAP2(vrsqrte_v, arm_neon_vrsqrte, arm_neon_vrsqrte, 0),
6774 NEONMAP2(vrsqrteq_v, arm_neon_vrsqrte, arm_neon_vrsqrte, 0),
6778 NEONMAP1(vsha1su0q_u32, arm_neon_sha1su0, 0),
6779 NEONMAP1(vsha1su1q_u32, arm_neon_sha1su1, 0),
6780 NEONMAP1(vsha256h2q_u32, arm_neon_sha256h2, 0),
6781 NEONMAP1(vsha256hq_u32, arm_neon_sha256h, 0),
6782 NEONMAP1(vsha256su0q_u32, arm_neon_sha256su0, 0),
6783 NEONMAP1(vsha256su1q_u32, arm_neon_sha256su1, 0),
6792 NEONMAP1(vst1_v, arm_neon_vst1, 0),
6793 NEONMAP1(vst1_x2_v, arm_neon_vst1x2, 0),
6794 NEONMAP1(vst1_x3_v, arm_neon_vst1x3, 0),
6795 NEONMAP1(vst1_x4_v, arm_neon_vst1x4, 0),
6796 NEONMAP1(vst1q_v, arm_neon_vst1, 0),
6797 NEONMAP1(vst1q_x2_v, arm_neon_vst1x2, 0),
6798 NEONMAP1(vst1q_x3_v, arm_neon_vst1x3, 0),
6799 NEONMAP1(vst1q_x4_v, arm_neon_vst1x4, 0),
6800 NEONMAP1(vst2_lane_v, arm_neon_vst2lane, 0),
6801 NEONMAP1(vst2_v, arm_neon_vst2, 0),
6802 NEONMAP1(vst2q_lane_v, arm_neon_vst2lane, 0),
6803 NEONMAP1(vst2q_v, arm_neon_vst2, 0),
6804 NEONMAP1(vst3_lane_v, arm_neon_vst3lane, 0),
6805 NEONMAP1(vst3_v, arm_neon_vst3, 0),
6806 NEONMAP1(vst3q_lane_v, arm_neon_vst3lane, 0),
6807 NEONMAP1(vst3q_v, arm_neon_vst3, 0),
6808 NEONMAP1(vst4_lane_v, arm_neon_vst4lane, 0),
6809 NEONMAP1(vst4_v, arm_neon_vst4, 0),
6810 NEONMAP1(vst4q_lane_v, arm_neon_vst4lane, 0),
6811 NEONMAP1(vst4q_v, arm_neon_vst4, 0),
6817 NEONMAP1(vusdot_s32, arm_neon_usdot, 0),
6818 NEONMAP1(vusdotq_s32, arm_neon_usdot, 0),
6819 NEONMAP1(vusmmlaq_s32, arm_neon_usmmla, 0),
6827 NEONMAP1(__a64_vcvtq_low_bf16_f32, aarch64_neon_bfcvtn, 0),
6832 NEONMAP1(vabs_v, aarch64_neon_abs, 0),
6833 NEONMAP1(vabsq_v, aarch64_neon_abs, 0),
6838 NEONMAP1(vaesdq_u8, aarch64_crypto_aesd, 0),
6839 NEONMAP1(vaeseq_u8, aarch64_crypto_aese, 0),
6840 NEONMAP1(vaesimcq_u8, aarch64_crypto_aesimc, 0),
6841 NEONMAP1(vaesmcq_u8, aarch64_crypto_aesmc, 0),
6850 NEONMAP1(vbfdot_f32, aarch64_neon_bfdot, 0),
6851 NEONMAP1(vbfdotq_f32, aarch64_neon_bfdot, 0),
6852 NEONMAP1(vbfmlalbq_f32, aarch64_neon_bfmlalb, 0),
6853 NEONMAP1(vbfmlaltq_f32, aarch64_neon_bfmlalt, 0),
6854 NEONMAP1(vbfmmlaq_f32, aarch64_neon_bfmmla, 0),
6865 NEONMAP1(vcage_v, aarch64_neon_facge, 0),
6866 NEONMAP1(vcageq_v, aarch64_neon_facge, 0),
6867 NEONMAP1(vcagt_v, aarch64_neon_facgt, 0),
6868 NEONMAP1(vcagtq_v, aarch64_neon_facgt, 0),
6869 NEONMAP1(vcale_v, aarch64_neon_facge, 0),
6870 NEONMAP1(vcaleq_v, aarch64_neon_facge, 0),
6871 NEONMAP1(vcalt_v, aarch64_neon_facgt, 0),
6872 NEONMAP1(vcaltq_v, aarch64_neon_facgt, 0),
6909 NEONMAP1(vcvt_f16_f32, aarch64_neon_vcvtfp2hf, 0),
6912 NEONMAP1(vcvt_f32_f16, aarch64_neon_vcvthf2fp, 0),
6914 NEONMAP1(vcvt_n_f16_s16, aarch64_neon_vcvtfxs2fp, 0),
6915 NEONMAP1(vcvt_n_f16_u16, aarch64_neon_vcvtfxu2fp, 0),
6916 NEONMAP2(vcvt_n_f32_v, aarch64_neon_vcvtfxu2fp, aarch64_neon_vcvtfxs2fp, 0),
6917 NEONMAP2(vcvt_n_f64_v, aarch64_neon_vcvtfxu2fp, aarch64_neon_vcvtfxs2fp, 0),
6918 NEONMAP1(vcvt_n_s16_f16, aarch64_neon_vcvtfp2fxs, 0),
6919 NEONMAP1(vcvt_n_s32_v, aarch64_neon_vcvtfp2fxs, 0),
6920 NEONMAP1(vcvt_n_s64_v, aarch64_neon_vcvtfp2fxs, 0),
6921 NEONMAP1(vcvt_n_u16_f16, aarch64_neon_vcvtfp2fxu, 0),
6922 NEONMAP1(vcvt_n_u32_v, aarch64_neon_vcvtfp2fxu, 0),
6923 NEONMAP1(vcvt_n_u64_v, aarch64_neon_vcvtfp2fxu, 0),
6927 NEONMAP1(vcvtq_high_bf16_f32, aarch64_neon_bfcvtn2, 0),
6928 NEONMAP1(vcvtq_n_f16_s16, aarch64_neon_vcvtfxs2fp, 0),
6929 NEONMAP1(vcvtq_n_f16_u16, aarch64_neon_vcvtfxu2fp, 0),
6930 NEONMAP2(vcvtq_n_f32_v, aarch64_neon_vcvtfxu2fp, aarch64_neon_vcvtfxs2fp, 0),
6931 NEONMAP2(vcvtq_n_f64_v, aarch64_neon_vcvtfxu2fp, aarch64_neon_vcvtfxs2fp, 0),
6932 NEONMAP1(vcvtq_n_s16_f16, aarch64_neon_vcvtfp2fxs, 0),
6933 NEONMAP1(vcvtq_n_s32_v, aarch64_neon_vcvtfp2fxs, 0),
6934 NEONMAP1(vcvtq_n_s64_v, aarch64_neon_vcvtfp2fxs, 0),
6935 NEONMAP1(vcvtq_n_u16_f16, aarch64_neon_vcvtfp2fxu, 0),
6936 NEONMAP1(vcvtq_n_u32_v, aarch64_neon_vcvtfp2fxu, 0),
6937 NEONMAP1(vcvtq_n_u64_v, aarch64_neon_vcvtfp2fxu, 0),
6939 NEONMAP1(vdot_s32, aarch64_neon_sdot, 0),
6940 NEONMAP1(vdot_u32, aarch64_neon_udot, 0),
6941 NEONMAP1(vdotq_s32, aarch64_neon_sdot, 0),
6942 NEONMAP1(vdotq_u32, aarch64_neon_udot, 0),
6955 NEONMAP1(vfmlal_high_f16, aarch64_neon_fmlal2, 0),
6956 NEONMAP1(vfmlal_low_f16, aarch64_neon_fmlal, 0),
6957 NEONMAP1(vfmlalq_high_f16, aarch64_neon_fmlal2, 0),
6958 NEONMAP1(vfmlalq_low_f16, aarch64_neon_fmlal, 0),
6959 NEONMAP1(vfmlsl_high_f16, aarch64_neon_fmlsl2, 0),
6960 NEONMAP1(vfmlsl_low_f16, aarch64_neon_fmlsl, 0),
6961 NEONMAP1(vfmlslq_high_f16, aarch64_neon_fmlsl2, 0),
6962 NEONMAP1(vfmlslq_low_f16, aarch64_neon_fmlsl, 0),
6967 NEONMAP1(vld1_x2_v, aarch64_neon_ld1x2, 0),
6968 NEONMAP1(vld1_x3_v, aarch64_neon_ld1x3, 0),
6969 NEONMAP1(vld1_x4_v, aarch64_neon_ld1x4, 0),
6970 NEONMAP1(vld1q_x2_v, aarch64_neon_ld1x2, 0),
6971 NEONMAP1(vld1q_x3_v, aarch64_neon_ld1x3, 0),
6972 NEONMAP1(vld1q_x4_v, aarch64_neon_ld1x4, 0),
6973 NEONMAP1(vmmlaq_s32, aarch64_neon_smmla, 0),
6974 NEONMAP1(vmmlaq_u32, aarch64_neon_ummla, 0),
6987 NEONMAP2(vqdmlal_v, aarch64_neon_sqdmull, aarch64_neon_sqadd, 0),
6988 NEONMAP2(vqdmlsl_v, aarch64_neon_sqdmull, aarch64_neon_sqsub, 0),
6989 NEONMAP1(vqdmulh_lane_v, aarch64_neon_sqdmulh_lane, 0),
6990 NEONMAP1(vqdmulh_laneq_v, aarch64_neon_sqdmulh_laneq, 0),
6992 NEONMAP1(vqdmulhq_lane_v, aarch64_neon_sqdmulh_lane, 0),
6993 NEONMAP1(vqdmulhq_laneq_v, aarch64_neon_sqdmulh_laneq, 0),
7008 NEONMAP1(vqrdmulh_lane_v, aarch64_neon_sqrdmulh_lane, 0),
7009 NEONMAP1(vqrdmulh_laneq_v, aarch64_neon_sqrdmulh_laneq, 0),
7011 NEONMAP1(vqrdmulhq_lane_v, aarch64_neon_sqrdmulh_lane, 0),
7012 NEONMAP1(vqrdmulhq_laneq_v, aarch64_neon_sqrdmulh_laneq, 0),
7020 NEONMAP1(vqshlu_n_v, aarch64_neon_sqshlu, 0),
7021 NEONMAP1(vqshluq_n_v, aarch64_neon_sqshlu, 0),
7025 NEONMAP1(vrax1q_u64, aarch64_crypto_rax1, 0),
7026 NEONMAP2(vrecpe_v, aarch64_neon_frecpe, aarch64_neon_urecpe, 0),
7027 NEONMAP2(vrecpeq_v, aarch64_neon_frecpe, aarch64_neon_urecpe, 0),
7054 NEONMAP2(vrsqrte_v, aarch64_neon_frsqrte, aarch64_neon_ursqrte, 0),
7055 NEONMAP2(vrsqrteq_v, aarch64_neon_frsqrte, aarch64_neon_ursqrte, 0),
7059 NEONMAP1(vsha1su0q_u32, aarch64_crypto_sha1su0, 0),
7060 NEONMAP1(vsha1su1q_u32, aarch64_crypto_sha1su1, 0),
7061 NEONMAP1(vsha256h2q_u32, aarch64_crypto_sha256h2, 0),
7062 NEONMAP1(vsha256hq_u32, aarch64_crypto_sha256h, 0),
7063 NEONMAP1(vsha256su0q_u32, aarch64_crypto_sha256su0, 0),
7064 NEONMAP1(vsha256su1q_u32, aarch64_crypto_sha256su1, 0),
7065 NEONMAP1(vsha512h2q_u64, aarch64_crypto_sha512h2, 0),
7066 NEONMAP1(vsha512hq_u64, aarch64_crypto_sha512h, 0),
7067 NEONMAP1(vsha512su0q_u64, aarch64_crypto_sha512su0, 0),
7068 NEONMAP1(vsha512su1q_u64, aarch64_crypto_sha512su1, 0),
7077 NEONMAP1(vsm3partw1q_u32, aarch64_crypto_sm3partw1, 0),
7078 NEONMAP1(vsm3partw2q_u32, aarch64_crypto_sm3partw2, 0),
7079 NEONMAP1(vsm3ss1q_u32, aarch64_crypto_sm3ss1, 0),
7080 NEONMAP1(vsm3tt1aq_u32, aarch64_crypto_sm3tt1a, 0),
7081 NEONMAP1(vsm3tt1bq_u32, aarch64_crypto_sm3tt1b, 0),
7082 NEONMAP1(vsm3tt2aq_u32, aarch64_crypto_sm3tt2a, 0),
7083 NEONMAP1(vsm3tt2bq_u32, aarch64_crypto_sm3tt2b, 0),
7084 NEONMAP1(vsm4ekeyq_u32, aarch64_crypto_sm4ekey, 0),
7085 NEONMAP1(vsm4eq_u32, aarch64_crypto_sm4e, 0),
7086 NEONMAP1(vst1_x2_v, aarch64_neon_st1x2, 0),
7087 NEONMAP1(vst1_x3_v, aarch64_neon_st1x3, 0),
7088 NEONMAP1(vst1_x4_v, aarch64_neon_st1x4, 0),
7089 NEONMAP1(vst1q_x2_v, aarch64_neon_st1x2, 0),
7090 NEONMAP1(vst1q_x3_v, aarch64_neon_st1x3, 0),
7091 NEONMAP1(vst1q_x4_v, aarch64_neon_st1x4, 0),
7095 NEONMAP1(vusdot_s32, aarch64_neon_usdot, 0),
7096 NEONMAP1(vusdotq_s32, aarch64_neon_usdot, 0),
7097 NEONMAP1(vusmmlaq_s32, aarch64_neon_usmmla, 0),
7098 NEONMAP1(vxarq_u64, aarch64_crypto_xar, 0),
7136 NEONMAP1(vcvth_bf16_f32, aarch64_neon_bfcvt, 0),
7155 NEONMAP1(vcvtxd_f32_f64, aarch64_sisd_fcvtxn, 0),
7176 NEONMAP1(vmull_p64, aarch64_neon_pmull64, 0),
7204 NEONMAP1(vqdmulls_s32, aarch64_neon_sqdmulls_scalar, 0),
7285 NEONMAP1(vsha1cq_u32, aarch64_crypto_sha1c, 0),
7286 NEONMAP1(vsha1h_u32, aarch64_crypto_sha1h, 0),
7287 NEONMAP1(vsha1mq_u32, aarch64_crypto_sha1m, 0),
7288 NEONMAP1(vsha1pq_u32, aarch64_crypto_sha1p, 0),
7342 { NEON::BI__builtin_neon_splat_lane_bf16, NEON::BI__builtin_neon_splat_lane_v, },
7343 { NEON::BI__builtin_neon_splat_laneq_bf16, NEON::BI__builtin_neon_splat_laneq_v, },
7344 { NEON::BI__builtin_neon_splatq_lane_bf16, NEON::BI__builtin_neon_splatq_lane_v, },
7345 { NEON::BI__builtin_neon_splatq_laneq_bf16, NEON::BI__builtin_neon_splatq_laneq_v, },
7346 { NEON::BI__builtin_neon_vabd_f16, NEON::BI__builtin_neon_vabd_v, },
7347 { NEON::BI__builtin_neon_vabdq_f16, NEON::BI__builtin_neon_vabdq_v, },
7348 { NEON::BI__builtin_neon_vabs_f16, NEON::BI__builtin_neon_vabs_v, },
7349 { NEON::BI__builtin_neon_vabsq_f16, NEON::BI__builtin_neon_vabsq_v, },
7350 { NEON::BI__builtin_neon_vcage_f16, NEON::BI__builtin_neon_vcage_v, },
7351 { NEON::BI__builtin_neon_vcageq_f16, NEON::BI__builtin_neon_vcageq_v, },
7352 { NEON::BI__builtin_neon_vcagt_f16, NEON::BI__builtin_neon_vcagt_v, },
7353 { NEON::BI__builtin_neon_vcagtq_f16, NEON::BI__builtin_neon_vcagtq_v, },
7354 { NEON::BI__builtin_neon_vcale_f16, NEON::BI__builtin_neon_vcale_v, },
7355 { NEON::BI__builtin_neon_vcaleq_f16, NEON::BI__builtin_neon_vcaleq_v, },
7356 { NEON::BI__builtin_neon_vcalt_f16, NEON::BI__builtin_neon_vcalt_v, },
7357 { NEON::BI__builtin_neon_vcaltq_f16, NEON::BI__builtin_neon_vcaltq_v, },
7358 { NEON::BI__builtin_neon_vceqz_f16, NEON::BI__builtin_neon_vceqz_v, },
7359 { NEON::BI__builtin_neon_vceqzq_f16, NEON::BI__builtin_neon_vceqzq_v, },
7360 { NEON::BI__builtin_neon_vcgez_f16, NEON::BI__builtin_neon_vcgez_v, },
7361 { NEON::BI__builtin_neon_vcgezq_f16, NEON::BI__builtin_neon_vcgezq_v, },
7362 { NEON::BI__builtin_neon_vcgtz_f16, NEON::BI__builtin_neon_vcgtz_v, },
7363 { NEON::BI__builtin_neon_vcgtzq_f16, NEON::BI__builtin_neon_vcgtzq_v, },
7364 { NEON::BI__builtin_neon_vclez_f16, NEON::BI__builtin_neon_vclez_v, },
7365 { NEON::BI__builtin_neon_vclezq_f16, NEON::BI__builtin_neon_vclezq_v, },
7366 { NEON::BI__builtin_neon_vcltz_f16, NEON::BI__builtin_neon_vcltz_v, },
7367 { NEON::BI__builtin_neon_vcltzq_f16, NEON::BI__builtin_neon_vcltzq_v, },
7368 { NEON::BI__builtin_neon_vfma_f16, NEON::BI__builtin_neon_vfma_v, },
7369 { NEON::BI__builtin_neon_vfma_lane_f16, NEON::BI__builtin_neon_vfma_lane_v, },
7370 { NEON::BI__builtin_neon_vfma_laneq_f16, NEON::BI__builtin_neon_vfma_laneq_v, },
7371 { NEON::BI__builtin_neon_vfmaq_f16, NEON::BI__builtin_neon_vfmaq_v, },
7372 { NEON::BI__builtin_neon_vfmaq_lane_f16, NEON::BI__builtin_neon_vfmaq_lane_v, },
7373 { NEON::BI__builtin_neon_vfmaq_laneq_f16, NEON::BI__builtin_neon_vfmaq_laneq_v, },
7374 { NEON::BI__builtin_neon_vld1_bf16_x2, NEON::BI__builtin_neon_vld1_x2_v },
7375 { NEON::BI__builtin_neon_vld1_bf16_x3, NEON::BI__builtin_neon_vld1_x3_v },
7376 { NEON::BI__builtin_neon_vld1_bf16_x4, NEON::BI__builtin_neon_vld1_x4_v },
7377 { NEON::BI__builtin_neon_vld1_bf16, NEON::BI__builtin_neon_vld1_v },
7378 { NEON::BI__builtin_neon_vld1_dup_bf16, NEON::BI__builtin_neon_vld1_dup_v },
7379 { NEON::BI__builtin_neon_vld1_lane_bf16, NEON::BI__builtin_neon_vld1_lane_v },
7380 { NEON::BI__builtin_neon_vld1q_bf16_x2, NEON::BI__builtin_neon_vld1q_x2_v },
7381 { NEON::BI__builtin_neon_vld1q_bf16_x3, NEON::BI__builtin_neon_vld1q_x3_v },
7382 { NEON::BI__builtin_neon_vld1q_bf16_x4, NEON::BI__builtin_neon_vld1q_x4_v },
7383 { NEON::BI__builtin_neon_vld1q_bf16, NEON::BI__builtin_neon_vld1q_v },
7384 { NEON::BI__builtin_neon_vld1q_dup_bf16, NEON::BI__builtin_neon_vld1q_dup_v },
7385 { NEON::BI__builtin_neon_vld1q_lane_bf16, NEON::BI__builtin_neon_vld1q_lane_v },
7386 { NEON::BI__builtin_neon_vld2_bf16, NEON::BI__builtin_neon_vld2_v },
7387 { NEON::BI__builtin_neon_vld2_dup_bf16, NEON::BI__builtin_neon_vld2_dup_v },
7388 { NEON::BI__builtin_neon_vld2_lane_bf16, NEON::BI__builtin_neon_vld2_lane_v },
7389 { NEON::BI__builtin_neon_vld2q_bf16, NEON::BI__builtin_neon_vld2q_v },
7390 { NEON::BI__builtin_neon_vld2q_dup_bf16, NEON::BI__builtin_neon_vld2q_dup_v },
7391 { NEON::BI__builtin_neon_vld2q_lane_bf16, NEON::BI__builtin_neon_vld2q_lane_v },
7392 { NEON::BI__builtin_neon_vld3_bf16, NEON::BI__builtin_neon_vld3_v },
7393 { NEON::BI__builtin_neon_vld3_dup_bf16, NEON::BI__builtin_neon_vld3_dup_v },
7394 { NEON::BI__builtin_neon_vld3_lane_bf16, NEON::BI__builtin_neon_vld3_lane_v },
7395 { NEON::BI__builtin_neon_vld3q_bf16, NEON::BI__builtin_neon_vld3q_v },
7396 { NEON::BI__builtin_neon_vld3q_dup_bf16, NEON::BI__builtin_neon_vld3q_dup_v },
7397 { NEON::BI__builtin_neon_vld3q_lane_bf16, NEON::BI__builtin_neon_vld3q_lane_v },
7398 { NEON::BI__builtin_neon_vld4_bf16, NEON::BI__builtin_neon_vld4_v },
7399 { NEON::BI__builtin_neon_vld4_dup_bf16, NEON::BI__builtin_neon_vld4_dup_v },
7400 { NEON::BI__builtin_neon_vld4_lane_bf16, NEON::BI__builtin_neon_vld4_lane_v },
7401 { NEON::BI__builtin_neon_vld4q_bf16, NEON::BI__builtin_neon_vld4q_v },
7402 { NEON::BI__builtin_neon_vld4q_dup_bf16, NEON::BI__builtin_neon_vld4q_dup_v },
7403 { NEON::BI__builtin_neon_vld4q_lane_bf16, NEON::BI__builtin_neon_vld4q_lane_v },
7404 { NEON::BI__builtin_neon_vmax_f16, NEON::BI__builtin_neon_vmax_v, },
7405 { NEON::BI__builtin_neon_vmaxnm_f16, NEON::BI__builtin_neon_vmaxnm_v, },
7406 { NEON::BI__builtin_neon_vmaxnmq_f16, NEON::BI__builtin_neon_vmaxnmq_v, },
7407 { NEON::BI__builtin_neon_vmaxq_f16, NEON::BI__builtin_neon_vmaxq_v, },
7408 { NEON::BI__builtin_neon_vmin_f16, NEON::BI__builtin_neon_vmin_v, },
7409 { NEON::BI__builtin_neon_vminnm_f16, NEON::BI__builtin_neon_vminnm_v, },
7410 { NEON::BI__builtin_neon_vminnmq_f16, NEON::BI__builtin_neon_vminnmq_v, },
7411 { NEON::BI__builtin_neon_vminq_f16, NEON::BI__builtin_neon_vminq_v, },
7412 { NEON::BI__builtin_neon_vmulx_f16, NEON::BI__builtin_neon_vmulx_v, },
7413 { NEON::BI__builtin_neon_vmulxq_f16, NEON::BI__builtin_neon_vmulxq_v, },
7414 { NEON::BI__builtin_neon_vpadd_f16, NEON::BI__builtin_neon_vpadd_v, },
7415 { NEON::BI__builtin_neon_vpaddq_f16, NEON::BI__builtin_neon_vpaddq_v, },
7416 { NEON::BI__builtin_neon_vpmax_f16, NEON::BI__builtin_neon_vpmax_v, },
7417 { NEON::BI__builtin_neon_vpmaxnm_f16, NEON::BI__builtin_neon_vpmaxnm_v, },
7418 { NEON::BI__builtin_neon_vpmaxnmq_f16, NEON::BI__builtin_neon_vpmaxnmq_v, },
7419 { NEON::BI__builtin_neon_vpmaxq_f16, NEON::BI__builtin_neon_vpmaxq_v, },
7420 { NEON::BI__builtin_neon_vpmin_f16, NEON::BI__builtin_neon_vpmin_v, },
7421 { NEON::BI__builtin_neon_vpminnm_f16, NEON::BI__builtin_neon_vpminnm_v, },
7422 { NEON::BI__builtin_neon_vpminnmq_f16, NEON::BI__builtin_neon_vpminnmq_v, },
7423 { NEON::BI__builtin_neon_vpminq_f16, NEON::BI__builtin_neon_vpminq_v, },
7424 { NEON::BI__builtin_neon_vrecpe_f16, NEON::BI__builtin_neon_vrecpe_v, },
7425 { NEON::BI__builtin_neon_vrecpeq_f16, NEON::BI__builtin_neon_vrecpeq_v, },
7426 { NEON::BI__builtin_neon_vrecps_f16, NEON::BI__builtin_neon_vrecps_v, },
7427 { NEON::BI__builtin_neon_vrecpsq_f16, NEON::BI__builtin_neon_vrecpsq_v, },
7428 { NEON::BI__builtin_neon_vrnd_f16, NEON::BI__builtin_neon_vrnd_v, },
7429 { NEON::BI__builtin_neon_vrnda_f16, NEON::BI__builtin_neon_vrnda_v, },
7430 { NEON::BI__builtin_neon_vrndaq_f16, NEON::BI__builtin_neon_vrndaq_v, },
7431 { NEON::BI__builtin_neon_vrndi_f16, NEON::BI__builtin_neon_vrndi_v, },
7432 { NEON::BI__builtin_neon_vrndiq_f16, NEON::BI__builtin_neon_vrndiq_v, },
7433 { NEON::BI__builtin_neon_vrndm_f16, NEON::BI__builtin_neon_vrndm_v, },
7434 { NEON::BI__builtin_neon_vrndmq_f16, NEON::BI__builtin_neon_vrndmq_v, },
7435 { NEON::BI__builtin_neon_vrndn_f16, NEON::BI__builtin_neon_vrndn_v, },
7436 { NEON::BI__builtin_neon_vrndnq_f16, NEON::BI__builtin_neon_vrndnq_v, },
7437 { NEON::BI__builtin_neon_vrndp_f16, NEON::BI__builtin_neon_vrndp_v, },
7438 { NEON::BI__builtin_neon_vrndpq_f16, NEON::BI__builtin_neon_vrndpq_v, },
7439 { NEON::BI__builtin_neon_vrndq_f16, NEON::BI__builtin_neon_vrndq_v, },
7440 { NEON::BI__builtin_neon_vrndx_f16, NEON::BI__builtin_neon_vrndx_v, },
7441 { NEON::BI__builtin_neon_vrndxq_f16, NEON::BI__builtin_neon_vrndxq_v, },
7442 { NEON::BI__builtin_neon_vrsqrte_f16, NEON::BI__builtin_neon_vrsqrte_v, },
7443 { NEON::BI__builtin_neon_vrsqrteq_f16, NEON::BI__builtin_neon_vrsqrteq_v, },
7444 { NEON::BI__builtin_neon_vrsqrts_f16, NEON::BI__builtin_neon_vrsqrts_v, },
7445 { NEON::BI__builtin_neon_vrsqrtsq_f16, NEON::BI__builtin_neon_vrsqrtsq_v, },
7446 { NEON::BI__builtin_neon_vsqrt_f16, NEON::BI__builtin_neon_vsqrt_v, },
7447 { NEON::BI__builtin_neon_vsqrtq_f16, NEON::BI__builtin_neon_vsqrtq_v, },
7448 { NEON::BI__builtin_neon_vst1_bf16_x2, NEON::BI__builtin_neon_vst1_x2_v },
7449 { NEON::BI__builtin_neon_vst1_bf16_x3, NEON::BI__builtin_neon_vst1_x3_v },
7450 { NEON::BI__builtin_neon_vst1_bf16_x4, NEON::BI__builtin_neon_vst1_x4_v },
7451 { NEON::BI__builtin_neon_vst1_bf16, NEON::BI__builtin_neon_vst1_v },
7452 { NEON::BI__builtin_neon_vst1_lane_bf16, NEON::BI__builtin_neon_vst1_lane_v },
7453 { NEON::BI__builtin_neon_vst1q_bf16_x2, NEON::BI__builtin_neon_vst1q_x2_v },
7454 { NEON::BI__builtin_neon_vst1q_bf16_x3, NEON::BI__builtin_neon_vst1q_x3_v },
7455 { NEON::BI__builtin_neon_vst1q_bf16_x4, NEON::BI__builtin_neon_vst1q_x4_v },
7456 { NEON::BI__builtin_neon_vst1q_bf16, NEON::BI__builtin_neon_vst1q_v },
7457 { NEON::BI__builtin_neon_vst1q_lane_bf16, NEON::BI__builtin_neon_vst1q_lane_v },
7458 { NEON::BI__builtin_neon_vst2_bf16, NEON::BI__builtin_neon_vst2_v },
7459 { NEON::BI__builtin_neon_vst2_lane_bf16, NEON::BI__builtin_neon_vst2_lane_v },
7460 { NEON::BI__builtin_neon_vst2q_bf16, NEON::BI__builtin_neon_vst2q_v },
7461 { NEON::BI__builtin_neon_vst2q_lane_bf16, NEON::BI__builtin_neon_vst2q_lane_v },
7462 { NEON::BI__builtin_neon_vst3_bf16, NEON::BI__builtin_neon_vst3_v },
7463 { NEON::BI__builtin_neon_vst3_lane_bf16, NEON::BI__builtin_neon_vst3_lane_v },
7464 { NEON::BI__builtin_neon_vst3q_bf16, NEON::BI__builtin_neon_vst3q_v },
7465 { NEON::BI__builtin_neon_vst3q_lane_bf16, NEON::BI__builtin_neon_vst3q_lane_v },
7466 { NEON::BI__builtin_neon_vst4_bf16, NEON::BI__builtin_neon_vst4_v },
7467 { NEON::BI__builtin_neon_vst4_lane_bf16, NEON::BI__builtin_neon_vst4_lane_v },
7468 { NEON::BI__builtin_neon_vst4q_bf16, NEON::BI__builtin_neon_vst4q_v },
7469 { NEON::BI__builtin_neon_vst4q_lane_bf16, NEON::BI__builtin_neon_vst4q_lane_v },
7473 { NEON::BI__builtin_neon_vldap1_lane_u64, NEON::BI__builtin_neon_vldap1_lane_s64 },
7474 { NEON::BI__builtin_neon_vldap1_lane_f64, NEON::BI__builtin_neon_vldap1_lane_s64 },
7475 { NEON::BI__builtin_neon_vldap1_lane_p64, NEON::BI__builtin_neon_vldap1_lane_s64 },
7476 { NEON::BI__builtin_neon_vldap1q_lane_u64, NEON::BI__builtin_neon_vldap1q_lane_s64 },
7477 { NEON::BI__builtin_neon_vldap1q_lane_f64, NEON::BI__builtin_neon_vldap1q_lane_s64 },
7478 { NEON::BI__builtin_neon_vldap1q_lane_p64, NEON::BI__builtin_neon_vldap1q_lane_s64 },
7479 { NEON::BI__builtin_neon_vstl1_lane_u64, NEON::BI__builtin_neon_vstl1_lane_s64 },
7480 { NEON::BI__builtin_neon_vstl1_lane_f64, NEON::BI__builtin_neon_vstl1_lane_s64 },
7481 { NEON::BI__builtin_neon_vstl1_lane_p64, NEON::BI__builtin_neon_vstl1_lane_s64 },
7482 { NEON::BI__builtin_neon_vstl1q_lane_u64, NEON::BI__builtin_neon_vstl1q_lane_s64 },
7483 { NEON::BI__builtin_neon_vstl1q_lane_f64, NEON::BI__builtin_neon_vstl1q_lane_s64 },
7484 { NEON::BI__builtin_neon_vstl1q_lane_p64, NEON::BI__builtin_neon_vstl1q_lane_s64 },
7491#define SVEMAP1(NameBase, LLVMIntrinsic, TypeModifier) \
7493 #NameBase, SVE::BI__builtin_sve_##NameBase, Intrinsic::LLVMIntrinsic, 0, \
7497#define SVEMAP2(NameBase, TypeModifier) \
7498 { #NameBase, SVE::BI__builtin_sve_##NameBase, 0, 0, TypeModifier }
7500#define GET_SVE_LLVM_INTRINSIC_MAP
7501#include "clang/Basic/arm_sve_builtin_cg.inc"
7502#include "clang/Basic/BuiltinsAArch64NeonSVEBridge_cg.def"
7503#undef GET_SVE_LLVM_INTRINSIC_MAP
7509#define SMEMAP1(NameBase, LLVMIntrinsic, TypeModifier) \
7511 #NameBase, SME::BI__builtin_sme_##NameBase, Intrinsic::LLVMIntrinsic, 0, \
7515#define SMEMAP2(NameBase, TypeModifier) \
7516 { #NameBase, SME::BI__builtin_sme_##NameBase, 0, 0, TypeModifier }
7518#define GET_SME_LLVM_INTRINSIC_MAP
7519#include "clang/Basic/arm_sme_builtin_cg.inc"
7520#undef GET_SME_LLVM_INTRINSIC_MAP
7533static const ARMVectorIntrinsicInfo *
7535 unsigned BuiltinID,
bool &MapProvenSorted) {
7538 if (!MapProvenSorted) {
7539 assert(llvm::is_sorted(IntrinsicMap));
7540 MapProvenSorted =
true;
7544 const ARMVectorIntrinsicInfo *Builtin =
7545 llvm::lower_bound(IntrinsicMap, BuiltinID);
7547 if (Builtin != IntrinsicMap.end() && Builtin->BuiltinID == BuiltinID)
7555 llvm::Type *ArgType,
7568 Ty = llvm::FixedVectorType::get(
7569 Ty, VectorSize ? VectorSize / Ty->getPrimitiveSizeInBits() : 1);
7576 int Elts = VectorSize ? VectorSize / ArgType->getPrimitiveSizeInBits() : 1;
7577 ArgType = llvm::FixedVectorType::get(ArgType, Elts);
7581 Tys.push_back(ArgType);
7584 Tys.push_back(ArgType);
7595 unsigned BuiltinID = SISDInfo.BuiltinID;
7596 unsigned int Int = SISDInfo.LLVMIntrinsic;
7597 unsigned Modifier = SISDInfo.TypeModifier;
7598 const char *
s = SISDInfo.NameHint;
7600 switch (BuiltinID) {
7601 case NEON::BI__builtin_neon_vcled_s64:
7602 case NEON::BI__builtin_neon_vcled_u64:
7603 case NEON::BI__builtin_neon_vcles_f32:
7604 case NEON::BI__builtin_neon_vcled_f64:
7605 case NEON::BI__builtin_neon_vcltd_s64:
7606 case NEON::BI__builtin_neon_vcltd_u64:
7607 case NEON::BI__builtin_neon_vclts_f32:
7608 case NEON::BI__builtin_neon_vcltd_f64:
7609 case NEON::BI__builtin_neon_vcales_f32:
7610 case NEON::BI__builtin_neon_vcaled_f64:
7611 case NEON::BI__builtin_neon_vcalts_f32:
7612 case NEON::BI__builtin_neon_vcaltd_f64:
7616 std::swap(Ops[0], Ops[1]);
7620 assert(Int &&
"Generic code assumes a valid intrinsic");
7623 const Expr *Arg =
E->getArg(0);
7628 ConstantInt *C0 = ConstantInt::get(CGF.
SizeTy, 0);
7629 for (Function::const_arg_iterator ai = F->arg_begin(), ae = F->arg_end();
7630 ai != ae; ++ai, ++j) {
7631 llvm::Type *ArgTy = ai->getType();
7632 if (Ops[j]->getType()->getPrimitiveSizeInBits() ==
7633 ArgTy->getPrimitiveSizeInBits())
7636 assert(ArgTy->isVectorTy() && !Ops[j]->getType()->isVectorTy());
7639 Ops[j] = CGF.
Builder.CreateTruncOrBitCast(
7640 Ops[j], cast<llvm::VectorType>(ArgTy)->getElementType());
7642 CGF.
Builder.CreateInsertElement(PoisonValue::get(ArgTy), Ops[j], C0);
7647 if (ResultType->getPrimitiveSizeInBits().getFixedValue() <
7648 Result->getType()->getPrimitiveSizeInBits().getFixedValue())
7655 unsigned BuiltinID,
unsigned LLVMIntrinsic,
unsigned AltLLVMIntrinsic,
7656 const char *NameHint,
unsigned Modifier,
const CallExpr *
E,
7658 llvm::Triple::ArchType Arch) {
7660 const Expr *Arg =
E->getArg(
E->getNumArgs() - 1);
7661 std::optional<llvm::APSInt> NeonTypeConst =
7668 bool Usgn =
Type.isUnsigned();
7669 bool Quad =
Type.isQuad();
7671 const bool AllowBFloatArgsAndRet =
7674 llvm::FixedVectorType *VTy =
7675 GetNeonType(
this,
Type, HasLegalHalfType,
false, AllowBFloatArgsAndRet);
7676 llvm::Type *Ty = VTy;
7680 auto getAlignmentValue32 = [&](
Address addr) ->
Value* {
7681 return Builder.getInt32(addr.getAlignment().getQuantity());
7684 unsigned Int = LLVMIntrinsic;
7686 Int = AltLLVMIntrinsic;
7688 switch (BuiltinID) {
7690 case NEON::BI__builtin_neon_splat_lane_v:
7691 case NEON::BI__builtin_neon_splat_laneq_v:
7692 case NEON::BI__builtin_neon_splatq_lane_v:
7693 case NEON::BI__builtin_neon_splatq_laneq_v: {
7694 auto NumElements = VTy->getElementCount();
7695 if (BuiltinID == NEON::BI__builtin_neon_splatq_lane_v)
7696 NumElements = NumElements * 2;
7697 if (BuiltinID == NEON::BI__builtin_neon_splat_laneq_v)
7698 NumElements = NumElements.divideCoefficientBy(2);
7700 Ops[0] =
Builder.CreateBitCast(Ops[0], VTy);
7701 return EmitNeonSplat(Ops[0], cast<ConstantInt>(Ops[1]), NumElements);
7703 case NEON::BI__builtin_neon_vpadd_v:
7704 case NEON::BI__builtin_neon_vpaddq_v:
7706 if (VTy->getElementType()->isFloatingPointTy() &&
7707 Int == Intrinsic::aarch64_neon_addp)
7708 Int = Intrinsic::aarch64_neon_faddp;
7710 case NEON::BI__builtin_neon_vabs_v:
7711 case NEON::BI__builtin_neon_vabsq_v:
7712 if (VTy->getElementType()->isFloatingPointTy())
7715 case NEON::BI__builtin_neon_vadd_v:
7716 case NEON::BI__builtin_neon_vaddq_v: {
7717 llvm::Type *VTy = llvm::FixedVectorType::get(
Int8Ty, Quad ? 16 : 8);
7718 Ops[0] =
Builder.CreateBitCast(Ops[0], VTy);
7719 Ops[1] =
Builder.CreateBitCast(Ops[1], VTy);
7720 Ops[0] =
Builder.CreateXor(Ops[0], Ops[1]);
7721 return Builder.CreateBitCast(Ops[0], Ty);
7723 case NEON::BI__builtin_neon_vaddhn_v: {
7724 llvm::FixedVectorType *SrcTy =
7725 llvm::FixedVectorType::getExtendedElementVectorType(VTy);
7728 Ops[0] =
Builder.CreateBitCast(Ops[0], SrcTy);
7729 Ops[1] =
Builder.CreateBitCast(Ops[1], SrcTy);
7730 Ops[0] =
Builder.CreateAdd(Ops[0], Ops[1],
"vaddhn");
7733 Constant *ShiftAmt =
7734 ConstantInt::get(SrcTy, SrcTy->getScalarSizeInBits() / 2);
7735 Ops[0] =
Builder.CreateLShr(Ops[0], ShiftAmt,
"vaddhn");
7738 return Builder.CreateTrunc(Ops[0], VTy,
"vaddhn");
7740 case NEON::BI__builtin_neon_vcale_v:
7741 case NEON::BI__builtin_neon_vcaleq_v:
7742 case NEON::BI__builtin_neon_vcalt_v:
7743 case NEON::BI__builtin_neon_vcaltq_v:
7744 std::swap(Ops[0], Ops[1]);
7746 case NEON::BI__builtin_neon_vcage_v:
7747 case NEON::BI__builtin_neon_vcageq_v:
7748 case NEON::BI__builtin_neon_vcagt_v:
7749 case NEON::BI__builtin_neon_vcagtq_v: {
7751 switch (VTy->getScalarSizeInBits()) {
7752 default: llvm_unreachable(
"unexpected type");
7763 auto *VecFlt = llvm::FixedVectorType::get(Ty, VTy->getNumElements());
7764 llvm::Type *Tys[] = { VTy, VecFlt };
7768 case NEON::BI__builtin_neon_vceqz_v:
7769 case NEON::BI__builtin_neon_vceqzq_v:
7771 ICmpInst::ICMP_EQ,
"vceqz");
7772 case NEON::BI__builtin_neon_vcgez_v:
7773 case NEON::BI__builtin_neon_vcgezq_v:
7775 ICmpInst::ICMP_SGE,
"vcgez");
7776 case NEON::BI__builtin_neon_vclez_v:
7777 case NEON::BI__builtin_neon_vclezq_v:
7779 ICmpInst::ICMP_SLE,
"vclez");
7780 case NEON::BI__builtin_neon_vcgtz_v:
7781 case NEON::BI__builtin_neon_vcgtzq_v:
7783 ICmpInst::ICMP_SGT,
"vcgtz");
7784 case NEON::BI__builtin_neon_vcltz_v:
7785 case NEON::BI__builtin_neon_vcltzq_v:
7787 ICmpInst::ICMP_SLT,
"vcltz");
7788 case NEON::BI__builtin_neon_vclz_v:
7789 case NEON::BI__builtin_neon_vclzq_v:
7794 case NEON::BI__builtin_neon_vcvt_f32_v:
7795 case NEON::BI__builtin_neon_vcvtq_f32_v:
7796 Ops[0] =
Builder.CreateBitCast(Ops[0], Ty);
7799 return Usgn ?
Builder.CreateUIToFP(Ops[0], Ty,
"vcvt")
7800 :
Builder.CreateSIToFP(Ops[0], Ty,
"vcvt");
7801 case NEON::BI__builtin_neon_vcvt_f16_s16:
7802 case NEON::BI__builtin_neon_vcvt_f16_u16:
7803 case NEON::BI__builtin_neon_vcvtq_f16_s16:
7804 case NEON::BI__builtin_neon_vcvtq_f16_u16:
7805 Ops[0] =
Builder.CreateBitCast(Ops[0], Ty);
7808 return Usgn ?
Builder.CreateUIToFP(Ops[0], Ty,
"vcvt")
7809 :
Builder.CreateSIToFP(Ops[0], Ty,
"vcvt");
7810 case NEON::BI__builtin_neon_vcvt_n_f16_s16:
7811 case NEON::BI__builtin_neon_vcvt_n_f16_u16:
7812 case NEON::BI__builtin_neon_vcvtq_n_f16_s16:
7813 case NEON::BI__builtin_neon_vcvtq_n_f16_u16: {
7818 case NEON::BI__builtin_neon_vcvt_n_f32_v:
7819 case NEON::BI__builtin_neon_vcvt_n_f64_v:
7820 case NEON::BI__builtin_neon_vcvtq_n_f32_v:
7821 case NEON::BI__builtin_neon_vcvtq_n_f64_v: {
7823 Int = Usgn ? LLVMIntrinsic : AltLLVMIntrinsic;
7827 case NEON::BI__builtin_neon_vcvt_n_s16_f16:
7828 case NEON::BI__builtin_neon_vcvt_n_s32_v:
7829 case NEON::BI__builtin_neon_vcvt_n_u16_f16:
7830 case NEON::BI__builtin_neon_vcvt_n_u32_v:
7831 case NEON::BI__builtin_neon_vcvt_n_s64_v:
7832 case NEON::BI__builtin_neon_vcvt_n_u64_v:
7833 case NEON::BI__builtin_neon_vcvtq_n_s16_f16:
7834 case NEON::BI__builtin_neon_vcvtq_n_s32_v:
7835 case NEON::BI__builtin_neon_vcvtq_n_u16_f16:
7836 case NEON::BI__builtin_neon_vcvtq_n_u32_v:
7837 case NEON::BI__builtin_neon_vcvtq_n_s64_v:
7838 case NEON::BI__builtin_neon_vcvtq_n_u64_v: {
7843 case NEON::BI__builtin_neon_vcvt_s32_v:
7844 case NEON::BI__builtin_neon_vcvt_u32_v:
7845 case NEON::BI__builtin_neon_vcvt_s64_v:
7846 case NEON::BI__builtin_neon_vcvt_u64_v:
7847 case NEON::BI__builtin_neon_vcvt_s16_f16:
7848 case NEON::BI__builtin_neon_vcvt_u16_f16:
7849 case NEON::BI__builtin_neon_vcvtq_s32_v:
7850 case NEON::BI__builtin_neon_vcvtq_u32_v:
7851 case NEON::BI__builtin_neon_vcvtq_s64_v:
7852 case NEON::BI__builtin_neon_vcvtq_u64_v:
7853 case NEON::BI__builtin_neon_vcvtq_s16_f16:
7854 case NEON::BI__builtin_neon_vcvtq_u16_f16: {
7856 return Usgn ?
Builder.CreateFPToUI(Ops[0], Ty,
"vcvt")
7857 :
Builder.CreateFPToSI(Ops[0], Ty,
"vcvt");
7859 case NEON::BI__builtin_neon_vcvta_s16_f16:
7860 case NEON::BI__builtin_neon_vcvta_s32_v:
7861 case NEON::BI__builtin_neon_vcvta_s64_v:
7862 case NEON::BI__builtin_neon_vcvta_u16_f16:
7863 case NEON::BI__builtin_neon_vcvta_u32_v:
7864 case NEON::BI__builtin_neon_vcvta_u64_v:
7865 case NEON::BI__builtin_neon_vcvtaq_s16_f16:
7866 case NEON::BI__builtin_neon_vcvtaq_s32_v:
7867 case NEON::BI__builtin_neon_vcvtaq_s64_v:
7868 case NEON::BI__builtin_neon_vcvtaq_u16_f16:
7869 case NEON::BI__builtin_neon_vcvtaq_u32_v:
7870 case NEON::BI__builtin_neon_vcvtaq_u64_v:
7871 case NEON::BI__builtin_neon_vcvtn_s16_f16:
7872 case NEON::BI__builtin_neon_vcvtn_s32_v:
7873 case NEON::BI__builtin_neon_vcvtn_s64_v:
7874 case NEON::BI__builtin_neon_vcvtn_u16_f16:
7875 case NEON::BI__builtin_neon_vcvtn_u32_v:
7876 case NEON::BI__builtin_neon_vcvtn_u64_v:
7877 case NEON::BI__builtin_neon_vcvtnq_s16_f16:
7878 case NEON::BI__builtin_neon_vcvtnq_s32_v:
7879 case NEON::BI__builtin_neon_vcvtnq_s64_v:
7880 case NEON::BI__builtin_neon_vcvtnq_u16_f16:
7881 case NEON::BI__builtin_neon_vcvtnq_u32_v:
7882 case NEON::BI__builtin_neon_vcvtnq_u64_v:
7883 case NEON::BI__builtin_neon_vcvtp_s16_f16:
7884 case NEON::BI__builtin_neon_vcvtp_s32_v:
7885 case NEON::BI__builtin_neon_vcvtp_s64_v:
7886 case NEON::BI__builtin_neon_vcvtp_u16_f16:
7887 case NEON::BI__builtin_neon_vcvtp_u32_v:
7888 case NEON::BI__builtin_neon_vcvtp_u64_v:
7889 case NEON::BI__builtin_neon_vcvtpq_s16_f16:
7890 case NEON::BI__builtin_neon_vcvtpq_s32_v:
7891 case NEON::BI__builtin_neon_vcvtpq_s64_v:
7892 case NEON::BI__builtin_neon_vcvtpq_u16_f16:
7893 case NEON::BI__builtin_neon_vcvtpq_u32_v:
7894 case NEON::BI__builtin_neon_vcvtpq_u64_v:
7895 case NEON::BI__builtin_neon_vcvtm_s16_f16:
7896 case NEON::BI__builtin_neon_vcvtm_s32_v:
7897 case NEON::BI__builtin_neon_vcvtm_s64_v:
7898 case NEON::BI__builtin_neon_vcvtm_u16_f16:
7899 case NEON::BI__builtin_neon_vcvtm_u32_v:
7900 case NEON::BI__builtin_neon_vcvtm_u64_v:
7901 case NEON::BI__builtin_neon_vcvtmq_s16_f16:
7902 case NEON::BI__builtin_neon_vcvtmq_s32_v:
7903 case NEON::BI__builtin_neon_vcvtmq_s64_v:
7904 case NEON::BI__builtin_neon_vcvtmq_u16_f16:
7905 case NEON::BI__builtin_neon_vcvtmq_u32_v:
7906 case NEON::BI__builtin_neon_vcvtmq_u64_v: {
7910 case NEON::BI__builtin_neon_vcvtx_f32_v: {
7911 llvm::Type *Tys[2] = { VTy->getTruncatedElementVectorType(VTy), Ty};
7915 case NEON::BI__builtin_neon_vext_v:
7916 case NEON::BI__builtin_neon_vextq_v: {
7917 int CV = cast<ConstantInt>(Ops[2])->getSExtValue();
7919 for (
unsigned i = 0, e = VTy->getNumElements(); i != e; ++i)
7920 Indices.push_back(i+CV);
7922 Ops[0] =
Builder.CreateBitCast(Ops[0], Ty);
7923 Ops[1] =
Builder.CreateBitCast(Ops[1], Ty);
7924 return Builder.CreateShuffleVector(Ops[0], Ops[1], Indices,
"vext");
7926 case NEON::BI__builtin_neon_vfma_v:
7927 case NEON::BI__builtin_neon_vfmaq_v: {
7928 Ops[0] =
Builder.CreateBitCast(Ops[0], Ty);
7929 Ops[1] =
Builder.CreateBitCast(Ops[1], Ty);
7930 Ops[2] =
Builder.CreateBitCast(Ops[2], Ty);
7934 *
this, Intrinsic::fma, Intrinsic::experimental_constrained_fma, Ty,
7935 {Ops[1], Ops[2], Ops[0]});
7937 case NEON::BI__builtin_neon_vld1_v:
7938 case NEON::BI__builtin_neon_vld1q_v: {
7940 Ops.push_back(getAlignmentValue32(PtrOp0));
7943 case NEON::BI__builtin_neon_vld1_x2_v:
7944 case NEON::BI__builtin_neon_vld1q_x2_v:
7945 case NEON::BI__builtin_neon_vld1_x3_v:
7946 case NEON::BI__builtin_neon_vld1q_x3_v:
7947 case NEON::BI__builtin_neon_vld1_x4_v:
7948 case NEON::BI__builtin_neon_vld1q_x4_v: {
7951 Ops[1] =
Builder.CreateCall(F, Ops[1],
"vld1xN");
7954 case NEON::BI__builtin_neon_vld2_v:
7955 case NEON::BI__builtin_neon_vld2q_v:
7956 case NEON::BI__builtin_neon_vld3_v:
7957 case NEON::BI__builtin_neon_vld3q_v:
7958 case NEON::BI__builtin_neon_vld4_v:
7959 case NEON::BI__builtin_neon_vld4q_v:
7960 case NEON::BI__builtin_neon_vld2_dup_v:
7961 case NEON::BI__builtin_neon_vld2q_dup_v:
7962 case NEON::BI__builtin_neon_vld3_dup_v:
7963 case NEON::BI__builtin_neon_vld3q_dup_v:
7964 case NEON::BI__builtin_neon_vld4_dup_v:
7965 case NEON::BI__builtin_neon_vld4q_dup_v: {
7968 Value *Align = getAlignmentValue32(PtrOp1);
7969 Ops[1] =
Builder.CreateCall(F, {Ops[1], Align}, NameHint);
7972 case NEON::BI__builtin_neon_vld1_dup_v:
7973 case NEON::BI__builtin_neon_vld1q_dup_v: {
7974 Value *
V = PoisonValue::get(Ty);
7977 llvm::Constant *CI = ConstantInt::get(
SizeTy, 0);
7978 Ops[0] =
Builder.CreateInsertElement(
V, Ld, CI);
7981 case NEON::BI__builtin_neon_vld2_lane_v:
7982 case NEON::BI__builtin_neon_vld2q_lane_v:
7983 case NEON::BI__builtin_neon_vld3_lane_v:
7984 case NEON::BI__builtin_neon_vld3q_lane_v:
7985 case NEON::BI__builtin_neon_vld4_lane_v:
7986 case NEON::BI__builtin_neon_vld4q_lane_v: {
7989 for (
unsigned I = 2; I < Ops.size() - 1; ++I)
7990 Ops[I] =
Builder.CreateBitCast(Ops[I], Ty);
7991 Ops.push_back(getAlignmentValue32(PtrOp1));
7995 case NEON::BI__builtin_neon_vmovl_v: {
7996 llvm::FixedVectorType *DTy =
7997 llvm::FixedVectorType::getTruncatedElementVectorType(VTy);
7998 Ops[0] =
Builder.CreateBitCast(Ops[0], DTy);
8000 return Builder.CreateZExt(Ops[0], Ty,
"vmovl");
8001 return Builder.CreateSExt(Ops[0], Ty,
"vmovl");
8003 case NEON::BI__builtin_neon_vmovn_v: {
8004 llvm::FixedVectorType *QTy =
8005 llvm::FixedVectorType::getExtendedElementVectorType(VTy);
8006 Ops[0] =
Builder.CreateBitCast(Ops[0], QTy);
8007 return Builder.CreateTrunc(Ops[0], Ty,
"vmovn");
8009 case NEON::BI__builtin_neon_vmull_v:
8015 Int = Usgn ? Intrinsic::arm_neon_vmullu : Intrinsic::arm_neon_vmulls;
8018 case NEON::BI__builtin_neon_vpadal_v:
8019 case NEON::BI__builtin_neon_vpadalq_v: {
8021 unsigned EltBits = VTy->getElementType()->getPrimitiveSizeInBits();
8025 llvm::FixedVectorType::get(EltTy, VTy->getNumElements() * 2);
8026 llvm::Type *Tys[2] = { Ty, NarrowTy };
8029 case NEON::BI__builtin_neon_vpaddl_v:
8030 case NEON::BI__builtin_neon_vpaddlq_v: {
8032 unsigned EltBits = VTy->getElementType()->getPrimitiveSizeInBits();
8033 llvm::Type *EltTy = llvm::IntegerType::get(
getLLVMContext(), EltBits / 2);
8035 llvm::FixedVectorType::get(EltTy, VTy->getNumElements() * 2);
8036 llvm::Type *Tys[2] = { Ty, NarrowTy };
8039 case NEON::BI__builtin_neon_vqdmlal_v:
8040 case NEON::BI__builtin_neon_vqdmlsl_v: {
8047 case NEON::BI__builtin_neon_vqdmulhq_lane_v:
8048 case NEON::BI__builtin_neon_vqdmulh_lane_v:
8049 case NEON::BI__builtin_neon_vqrdmulhq_lane_v:
8050 case NEON::BI__builtin_neon_vqrdmulh_lane_v: {
8051 auto *RTy = cast<llvm::FixedVectorType>(Ty);
8052 if (BuiltinID == NEON::BI__builtin_neon_vqdmulhq_lane_v ||
8053 BuiltinID == NEON::BI__builtin_neon_vqrdmulhq_lane_v)
8054 RTy = llvm::FixedVectorType::get(RTy->getElementType(),
8055 RTy->getNumElements() * 2);
8056 llvm::Type *Tys[2] = {
8061 case NEON::BI__builtin_neon_vqdmulhq_laneq_v:
8062 case NEON::BI__builtin_neon_vqdmulh_laneq_v:
8063 case NEON::BI__builtin_neon_vqrdmulhq_laneq_v:
8064 case NEON::BI__builtin_neon_vqrdmulh_laneq_v: {
8065 llvm::Type *Tys[2] = {
8070 case NEON::BI__builtin_neon_vqshl_n_v:
8071 case NEON::BI__builtin_neon_vqshlq_n_v:
8074 case NEON::BI__builtin_neon_vqshlu_n_v:
8075 case NEON::BI__builtin_neon_vqshluq_n_v:
8078 case NEON::BI__builtin_neon_vrecpe_v:
8079 case NEON::BI__builtin_neon_vrecpeq_v:
8080 case NEON::BI__builtin_neon_vrsqrte_v:
8081 case NEON::BI__builtin_neon_vrsqrteq_v:
8082 Int = Ty->isFPOrFPVectorTy() ? LLVMIntrinsic : AltLLVMIntrinsic;
8084 case NEON::BI__builtin_neon_vrndi_v:
8085 case NEON::BI__builtin_neon_vrndiq_v:
8087 ? Intrinsic::experimental_constrained_nearbyint
8088 : Intrinsic::nearbyint;
8090 case NEON::BI__builtin_neon_vrshr_n_v:
8091 case NEON::BI__builtin_neon_vrshrq_n_v:
8094 case NEON::BI__builtin_neon_vsha512hq_u64:
8095 case NEON::BI__builtin_neon_vsha512h2q_u64:
8096 case NEON::BI__builtin_neon_vsha512su0q_u64:
8097 case NEON::BI__builtin_neon_vsha512su1q_u64: {
8101 case NEON::BI__builtin_neon_vshl_n_v:
8102 case NEON::BI__builtin_neon_vshlq_n_v:
8104 return Builder.CreateShl(
Builder.CreateBitCast(Ops[0],Ty), Ops[1],
8106 case NEON::BI__builtin_neon_vshll_n_v: {
8107 llvm::FixedVectorType *SrcTy =
8108 llvm::FixedVectorType::getTruncatedElementVectorType(VTy);
8109 Ops[0] =
Builder.CreateBitCast(Ops[0], SrcTy);
8111 Ops[0] =
Builder.CreateZExt(Ops[0], VTy);
8113 Ops[0] =
Builder.CreateSExt(Ops[0], VTy);
8115 return Builder.CreateShl(Ops[0], Ops[1],
"vshll_n");
8117 case NEON::BI__builtin_neon_vshrn_n_v: {
8118 llvm::FixedVectorType *SrcTy =
8119 llvm::FixedVectorType::getExtendedElementVectorType(VTy);
8120 Ops[0] =
Builder.CreateBitCast(Ops[0], SrcTy);
8123 Ops[0] =
Builder.CreateLShr(Ops[0], Ops[1]);
8125 Ops[0] =
Builder.CreateAShr(Ops[0], Ops[1]);
8126 return Builder.CreateTrunc(Ops[0], Ty,
"vshrn_n");
8128 case NEON::BI__builtin_neon_vshr_n_v:
8129 case NEON::BI__builtin_neon_vshrq_n_v:
8131 case NEON::BI__builtin_neon_vst1_v:
8132 case NEON::BI__builtin_neon_vst1q_v:
8133 case NEON::BI__builtin_neon_vst2_v:
8134 case NEON::BI__builtin_neon_vst2q_v:
8135 case NEON::BI__builtin_neon_vst3_v:
8136 case NEON::BI__builtin_neon_vst3q_v:
8137 case NEON::BI__builtin_neon_vst4_v:
8138 case NEON::BI__builtin_neon_vst4q_v:
8139 case NEON::BI__builtin_neon_vst2_lane_v:
8140 case NEON::BI__builtin_neon_vst2q_lane_v:
8141 case NEON::BI__builtin_neon_vst3_lane_v:
8142 case NEON::BI__builtin_neon_vst3q_lane_v:
8143 case NEON::BI__builtin_neon_vst4_lane_v:
8144 case NEON::BI__builtin_neon_vst4q_lane_v: {
8146 Ops.push_back(getAlignmentValue32(PtrOp0));
8149 case NEON::BI__builtin_neon_vsm3partw1q_u32:
8150 case NEON::BI__builtin_neon_vsm3partw2q_u32:
8151 case NEON::BI__builtin_neon_vsm3ss1q_u32:
8152 case NEON::BI__builtin_neon_vsm4ekeyq_u32:
8153 case NEON::BI__builtin_neon_vsm4eq_u32: {
8157 case NEON::BI__builtin_neon_vsm3tt1aq_u32:
8158 case NEON::BI__builtin_neon_vsm3tt1bq_u32:
8159 case NEON::BI__builtin_neon_vsm3tt2aq_u32:
8160 case NEON::BI__builtin_neon_vsm3tt2bq_u32: {
8165 case NEON::BI__builtin_neon_vst1_x2_v:
8166 case NEON::BI__builtin_neon_vst1q_x2_v:
8167 case NEON::BI__builtin_neon_vst1_x3_v:
8168 case NEON::BI__builtin_neon_vst1q_x3_v:
8169 case NEON::BI__builtin_neon_vst1_x4_v:
8170 case NEON::BI__builtin_neon_vst1q_x4_v: {
8173 if (Arch == llvm::Triple::aarch64 || Arch == llvm::Triple::aarch64_be ||
8174 Arch == llvm::Triple::aarch64_32) {
8176 std::rotate(Ops.begin(), Ops.begin() + 1, Ops.end());
8182 case NEON::BI__builtin_neon_vsubhn_v: {
8183 llvm::FixedVectorType *SrcTy =
8184 llvm::FixedVectorType::getExtendedElementVectorType(VTy);
8187 Ops[0] =
Builder.CreateBitCast(Ops[0], SrcTy);
8188 Ops[1] =
Builder.CreateBitCast(Ops[1], SrcTy);
8189 Ops[0] =
Builder.CreateSub(Ops[0], Ops[1],
"vsubhn");
8192 Constant *ShiftAmt =
8193 ConstantInt::get(SrcTy, SrcTy->getScalarSizeInBits() / 2);
8194 Ops[0] =
Builder.CreateLShr(Ops[0], ShiftAmt,
"vsubhn");
8197 return Builder.CreateTrunc(Ops[0], VTy,
"vsubhn");
8199 case NEON::BI__builtin_neon_vtrn_v:
8200 case NEON::BI__builtin_neon_vtrnq_v: {
8201 Ops[1] =
Builder.CreateBitCast(Ops[1], Ty);
8202 Ops[2] =
Builder.CreateBitCast(Ops[2], Ty);
8203 Value *SV =
nullptr;
8205 for (
unsigned vi = 0; vi != 2; ++vi) {
8207 for (
unsigned i = 0, e = VTy->getNumElements(); i != e; i += 2) {
8208 Indices.push_back(i+vi);
8209 Indices.push_back(i+e+vi);
8211 Value *Addr =
Builder.CreateConstInBoundsGEP1_32(Ty, Ops[0], vi);
8212 SV =
Builder.CreateShuffleVector(Ops[1], Ops[2], Indices,
"vtrn");
8217 case NEON::BI__builtin_neon_vtst_v:
8218 case NEON::BI__builtin_neon_vtstq_v: {
8219 Ops[0] =
Builder.CreateBitCast(Ops[0], Ty);
8220 Ops[1] =
Builder.CreateBitCast(Ops[1], Ty);
8221 Ops[0] =
Builder.CreateAnd(Ops[0], Ops[1]);
8222 Ops[0] =
Builder.CreateICmp(ICmpInst::ICMP_NE, Ops[0],
8223 ConstantAggregateZero::get(Ty));
8224 return Builder.CreateSExt(Ops[0], Ty,
"vtst");
8226 case NEON::BI__builtin_neon_vuzp_v:
8227 case NEON::BI__builtin_neon_vuzpq_v: {
8228 Ops[1] =
Builder.CreateBitCast(Ops[1], Ty);
8229 Ops[2] =
Builder.CreateBitCast(Ops[2], Ty);
8230 Value *SV =
nullptr;
8232 for (
unsigned vi = 0; vi != 2; ++vi) {
8234 for (
unsigned i = 0, e = VTy->getNumElements(); i != e; ++i)
8235 Indices.push_back(2*i+vi);
8237 Value *Addr =
Builder.CreateConstInBoundsGEP1_32(Ty, Ops[0], vi);
8238 SV =
Builder.CreateShuffleVector(Ops[1], Ops[2], Indices,
"vuzp");
8243 case NEON::BI__builtin_neon_vxarq_u64: {
8248 case NEON::BI__builtin_neon_vzip_v:
8249 case NEON::BI__builtin_neon_vzipq_v: {
8250 Ops[1] =
Builder.CreateBitCast(Ops[1], Ty);
8251 Ops[2] =
Builder.CreateBitCast(Ops[2], Ty);
8252 Value *SV =
nullptr;
8254 for (
unsigned vi = 0; vi != 2; ++vi) {
8256 for (
unsigned i = 0, e = VTy->getNumElements(); i != e; i += 2) {
8257 Indices.push_back((i + vi*e) >> 1);
8258 Indices.push_back(((i + vi*e) >> 1)+e);
8260 Value *Addr =
Builder.CreateConstInBoundsGEP1_32(Ty, Ops[0], vi);
8261 SV =
Builder.CreateShuffleVector(Ops[1], Ops[2], Indices,
"vzip");
8266 case NEON::BI__builtin_neon_vdot_s32:
8267 case NEON::BI__builtin_neon_vdot_u32:
8268 case NEON::BI__builtin_neon_vdotq_s32:
8269 case NEON::BI__builtin_neon_vdotq_u32: {
8271 llvm::FixedVectorType::get(
Int8Ty, Ty->getPrimitiveSizeInBits() / 8);
8272 llvm::Type *Tys[2] = { Ty, InputTy };
8275 case NEON::BI__builtin_neon_vfmlal_low_f16:
8276 case NEON::BI__builtin_neon_vfmlalq_low_f16: {
8278 llvm::FixedVectorType::get(
HalfTy, Ty->getPrimitiveSizeInBits() / 16);
8279 llvm::Type *Tys[2] = { Ty, InputTy };
8282 case NEON::BI__builtin_neon_vfmlsl_low_f16:
8283 case NEON::BI__builtin_neon_vfmlslq_low_f16: {
8285 llvm::FixedVectorType::get(
HalfTy, Ty->getPrimitiveSizeInBits() / 16);
8286 llvm::Type *Tys[2] = { Ty, InputTy };
8289 case NEON::BI__builtin_neon_vfmlal_high_f16:
8290 case NEON::BI__builtin_neon_vfmlalq_high_f16: {
8292 llvm::FixedVectorType::get(
HalfTy, Ty->getPrimitiveSizeInBits() / 16);
8293 llvm::Type *Tys[2] = { Ty, InputTy };
8296 case NEON::BI__builtin_neon_vfmlsl_high_f16:
8297 case NEON::BI__builtin_neon_vfmlslq_high_f16: {
8299 llvm::FixedVectorType::get(
HalfTy, Ty->getPrimitiveSizeInBits() / 16);
8300 llvm::Type *Tys[2] = { Ty, InputTy };
8303 case NEON::BI__builtin_neon_vmmlaq_s32:
8304 case NEON::BI__builtin_neon_vmmlaq_u32: {
8306 llvm::FixedVectorType::get(
Int8Ty, Ty->getPrimitiveSizeInBits() / 8);
8307 llvm::Type *Tys[2] = { Ty, InputTy };
8310 case NEON::BI__builtin_neon_vusmmlaq_s32: {
8312 llvm::FixedVectorType::get(
Int8Ty, Ty->getPrimitiveSizeInBits() / 8);
8313 llvm::Type *Tys[2] = { Ty, InputTy };
8316 case NEON::BI__builtin_neon_vusdot_s32:
8317 case NEON::BI__builtin_neon_vusdotq_s32: {
8319 llvm::FixedVectorType::get(
Int8Ty, Ty->getPrimitiveSizeInBits() / 8);
8320 llvm::Type *Tys[2] = { Ty, InputTy };
8323 case NEON::BI__builtin_neon_vbfdot_f32:
8324 case NEON::BI__builtin_neon_vbfdotq_f32: {
8325 llvm::Type *InputTy =
8326 llvm::FixedVectorType::get(
BFloatTy, Ty->getPrimitiveSizeInBits() / 16);
8327 llvm::Type *Tys[2] = { Ty, InputTy };
8330 case NEON::BI__builtin_neon___a32_vcvt_bf16_f32: {
8331 llvm::Type *Tys[1] = { Ty };
8338 assert(Int &&
"Expected valid intrinsic number");
8351 Value *Op, llvm::Type *Ty,
const CmpInst::Predicate Fp,
8352 const CmpInst::Predicate Ip,
const Twine &Name) {
8353 llvm::Type *OTy = Op->
getType();
8359 if (BitCastInst *BI = dyn_cast<BitCastInst>(Op))
8360 OTy = BI->getOperand(0)->getType();
8362 Op =
Builder.CreateBitCast(Op, OTy);
8363 if (OTy->getScalarType()->isFloatingPointTy()) {
8364 if (Fp == CmpInst::FCMP_OEQ)
8365 Op =
Builder.CreateFCmp(Fp, Op, Constant::getNullValue(OTy));
8367 Op =
Builder.CreateFCmpS(Fp, Op, Constant::getNullValue(OTy));
8369 Op =
Builder.CreateICmp(Ip, Op, Constant::getNullValue(OTy));
8371 return Builder.CreateSExt(Op, Ty, Name);
8376 llvm::Type *ResTy,
unsigned IntID,
8380 TblOps.push_back(ExtOp);
8384 auto *TblTy = cast<llvm::FixedVectorType>(Ops[0]->getType());
8385 for (
unsigned i = 0, e = TblTy->getNumElements(); i != e; ++i) {
8386 Indices.push_back(2*i);
8387 Indices.push_back(2*i+1);
8390 int PairPos = 0, End = Ops.size() - 1;
8391 while (PairPos < End) {
8392 TblOps.push_back(CGF.
Builder.CreateShuffleVector(Ops[PairPos],
8393 Ops[PairPos+1], Indices,
8400 if (PairPos == End) {
8401 Value *ZeroTbl = ConstantAggregateZero::get(TblTy);
8402 TblOps.push_back(CGF.
Builder.CreateShuffleVector(Ops[PairPos],
8403 ZeroTbl, Indices, Name));
8407 TblOps.push_back(IndexOp);
8413Value *CodeGenFunction::GetValueForARMHint(
unsigned BuiltinID) {
8415 switch (BuiltinID) {
8418 case clang::ARM::BI__builtin_arm_nop:
8421 case clang::ARM::BI__builtin_arm_yield:
8422 case clang::ARM::BI__yield:
8425 case clang::ARM::BI__builtin_arm_wfe:
8426 case clang::ARM::BI__wfe:
8429 case clang::ARM::BI__builtin_arm_wfi:
8430 case clang::ARM::BI__wfi:
8433 case clang::ARM::BI__builtin_arm_sev:
8434 case clang::ARM::BI__sev:
8437 case clang::ARM::BI__builtin_arm_sevl:
8438 case clang::ARM::BI__sevl:
8456 llvm::Type *RegisterType,
8457 llvm::Type *ValueType,
bool isExecHi) {
8462 llvm::Value *
Call = Builder.CreateCall(F, {Builder.getInt1(
true)});
8465 Value *Rt2 = Builder.CreateLShr(
Call, 32);
8466 Rt2 = Builder.CreateTrunc(Rt2, CGF.
Int32Ty);
8478 llvm::Type *RegisterType,
8479 llvm::Type *ValueType,
8481 StringRef SysReg =
"") {
8483 assert((RegisterType->isIntegerTy(32) || RegisterType->isIntegerTy(64) ||
8484 RegisterType->isIntegerTy(128)) &&
8485 "Unsupported size for register.");
8491 if (SysReg.empty()) {
8493 SysReg = cast<clang::StringLiteral>(SysRegStrExpr)->getString();
8496 llvm::Metadata *Ops[] = { llvm::MDString::get(Context, SysReg) };
8497 llvm::MDNode *RegName = llvm::MDNode::get(Context, Ops);
8498 llvm::Value *Metadata = llvm::MetadataAsValue::get(Context, RegName);
8500 llvm::Type *Types[] = { RegisterType };
8502 bool MixedTypes = RegisterType->isIntegerTy(64) && ValueType->isIntegerTy(32);
8503 assert(!(RegisterType->isIntegerTy(32) && ValueType->isIntegerTy(64))
8504 &&
"Can't fit 64-bit value in 32-bit register");
8506 if (AccessKind !=
Write) {
8509 AccessKind ==
VolatileRead ? llvm::Intrinsic::read_volatile_register
8510 : llvm::Intrinsic::read_register,
8512 llvm::Value *
Call = Builder.CreateCall(F, Metadata);
8516 return Builder.CreateTrunc(
Call, ValueType);
8518 if (ValueType->isPointerTy())
8520 return Builder.CreateIntToPtr(
Call, ValueType);
8525 llvm::Function *F = CGM.
getIntrinsic(llvm::Intrinsic::write_register, Types);
8529 ArgValue = Builder.CreateZExt(ArgValue, RegisterType);
8530 return Builder.CreateCall(F, { Metadata, ArgValue });
8533 if (ValueType->isPointerTy()) {
8535 ArgValue = Builder.CreatePtrToInt(ArgValue, RegisterType);
8536 return Builder.CreateCall(F, { Metadata, ArgValue });
8539 return Builder.CreateCall(F, { Metadata, ArgValue });
8545 switch (BuiltinID) {
8547 case NEON::BI__builtin_neon_vget_lane_i8:
8548 case NEON::BI__builtin_neon_vget_lane_i16:
8549 case NEON::BI__builtin_neon_vget_lane_bf16:
8550 case NEON::BI__builtin_neon_vget_lane_i32:
8551 case NEON::BI__builtin_neon_vget_lane_i64:
8552 case NEON::BI__builtin_neon_vget_lane_f32:
8553 case NEON::BI__builtin_neon_vgetq_lane_i8:
8554 case NEON::BI__builtin_neon_vgetq_lane_i16:
8555 case NEON::BI__builtin_neon_vgetq_lane_bf16:
8556 case NEON::BI__builtin_neon_vgetq_lane_i32:
8557 case NEON::BI__builtin_neon_vgetq_lane_i64:
8558 case NEON::BI__builtin_neon_vgetq_lane_f32:
8559 case NEON::BI__builtin_neon_vduph_lane_bf16:
8560 case NEON::BI__builtin_neon_vduph_laneq_bf16:
8561 case NEON::BI__builtin_neon_vset_lane_i8:
8562 case NEON::BI__builtin_neon_vset_lane_i16:
8563 case NEON::BI__builtin_neon_vset_lane_bf16:
8564 case NEON::BI__builtin_neon_vset_lane_i32:
8565 case NEON::BI__builtin_neon_vset_lane_i64:
8566 case NEON::BI__builtin_neon_vset_lane_f32:
8567 case NEON::BI__builtin_neon_vsetq_lane_i8:
8568 case NEON::BI__builtin_neon_vsetq_lane_i16:
8569 case NEON::BI__builtin_neon_vsetq_lane_bf16:
8570 case NEON::BI__builtin_neon_vsetq_lane_i32:
8571 case NEON::BI__builtin_neon_vsetq_lane_i64:
8572 case NEON::BI__builtin_neon_vsetq_lane_f32:
8573 case NEON::BI__builtin_neon_vsha1h_u32:
8574 case NEON::BI__builtin_neon_vsha1cq_u32:
8575 case NEON::BI__builtin_neon_vsha1pq_u32:
8576 case NEON::BI__builtin_neon_vsha1mq_u32:
8577 case NEON::BI__builtin_neon_vcvth_bf16_f32:
8578 case clang::ARM::BI_MoveToCoprocessor:
8579 case clang::ARM::BI_MoveToCoprocessor2:
8588 llvm::Triple::ArchType Arch) {
8589 if (
auto Hint = GetValueForARMHint(BuiltinID))
8592 if (BuiltinID == clang::ARM::BI__emit) {
8594 llvm::FunctionType *FTy =
8595 llvm::FunctionType::get(
VoidTy,
false);
8599 llvm_unreachable(
"Sema will ensure that the parameter is constant");
8602 uint64_t ZExtValue =
Value.zextOrTrunc(IsThumb ? 16 : 32).getZExtValue();
8604 llvm::InlineAsm *Emit =
8605 IsThumb ? InlineAsm::get(FTy,
".inst.n 0x" + utohexstr(ZExtValue),
"",
8607 : InlineAsm::get(FTy,
".inst 0x" + utohexstr(ZExtValue),
"",
8610 return Builder.CreateCall(Emit);
8613 if (BuiltinID == clang::ARM::BI__builtin_arm_dbg) {
8618 if (BuiltinID == clang::ARM::BI__builtin_arm_prefetch) {
8630 if (BuiltinID == clang::ARM::BI__builtin_arm_rbit) {
8633 CGM.
getIntrinsic(Intrinsic::bitreverse, Arg->getType()), Arg,
"rbit");
8636 if (BuiltinID == clang::ARM::BI__builtin_arm_clz ||
8637 BuiltinID == clang::ARM::BI__builtin_arm_clz64) {
8641 if (BuiltinID == clang::ARM::BI__builtin_arm_clz64)
8647 if (BuiltinID == clang::ARM::BI__builtin_arm_cls) {
8651 if (BuiltinID == clang::ARM::BI__builtin_arm_cls64) {
8657 if (BuiltinID == clang::ARM::BI__clear_cache) {
8658 assert(
E->getNumArgs() == 2 &&
"__clear_cache takes 2 arguments");
8661 for (
unsigned i = 0; i < 2; i++)
8664 llvm::FunctionType *FTy = cast<llvm::FunctionType>(Ty);
8665 StringRef Name = FD->
getName();
8669 if (BuiltinID == clang::ARM::BI__builtin_arm_mcrr ||
8670 BuiltinID == clang::ARM::BI__builtin_arm_mcrr2) {
8673 switch (BuiltinID) {
8674 default: llvm_unreachable(
"unexpected builtin");
8675 case clang::ARM::BI__builtin_arm_mcrr:
8678 case clang::ARM::BI__builtin_arm_mcrr2:
8700 return Builder.CreateCall(F, {Coproc, Opc1, Rt, Rt2, CRm});
8703 if (BuiltinID == clang::ARM::BI__builtin_arm_mrrc ||
8704 BuiltinID == clang::ARM::BI__builtin_arm_mrrc2) {
8707 switch (BuiltinID) {
8708 default: llvm_unreachable(
"unexpected builtin");
8709 case clang::ARM::BI__builtin_arm_mrrc:
8712 case clang::ARM::BI__builtin_arm_mrrc2:
8720 Value *RtAndRt2 =
Builder.CreateCall(F, {Coproc, Opc1, CRm});
8730 Value *ShiftCast = llvm::ConstantInt::get(
Int64Ty, 32);
8731 RtAndRt2 =
Builder.CreateShl(Rt, ShiftCast,
"shl",
true);
8732 RtAndRt2 =
Builder.CreateOr(RtAndRt2, Rt1);
8737 if (BuiltinID == clang::ARM::BI__builtin_arm_ldrexd ||
8738 ((BuiltinID == clang::ARM::BI__builtin_arm_ldrex ||
8739 BuiltinID == clang::ARM::BI__builtin_arm_ldaex) &&
8741 BuiltinID == clang::ARM::BI__ldrexd) {
8744 switch (BuiltinID) {
8745 default: llvm_unreachable(
"unexpected builtin");
8746 case clang::ARM::BI__builtin_arm_ldaex:
8749 case clang::ARM::BI__builtin_arm_ldrexd:
8750 case clang::ARM::BI__builtin_arm_ldrex:
8751 case clang::ARM::BI__ldrexd:
8765 Val =
Builder.CreateShl(Val0, ShiftCst,
"shl",
true );
8766 Val =
Builder.CreateOr(Val, Val1);
8770 if (BuiltinID == clang::ARM::BI__builtin_arm_ldrex ||
8771 BuiltinID == clang::ARM::BI__builtin_arm_ldaex) {
8780 BuiltinID == clang::ARM::BI__builtin_arm_ldaex ? Intrinsic::arm_ldaex
8781 : Intrinsic::arm_ldrex,
8783 CallInst *Val =
Builder.CreateCall(F, LoadAddr,
"ldrex");
8787 if (RealResTy->isPointerTy())
8788 return Builder.CreateIntToPtr(Val, RealResTy);
8790 llvm::Type *IntResTy = llvm::IntegerType::get(
8792 return Builder.CreateBitCast(
Builder.CreateTruncOrBitCast(Val, IntResTy),
8797 if (BuiltinID == clang::ARM::BI__builtin_arm_strexd ||
8798 ((BuiltinID == clang::ARM::BI__builtin_arm_stlex ||
8799 BuiltinID == clang::ARM::BI__builtin_arm_strex) &&
8802 BuiltinID == clang::ARM::BI__builtin_arm_stlex ? Intrinsic::arm_stlexd
8803 : Intrinsic::arm_strexd);
8816 return Builder.CreateCall(F, {Arg0, Arg1, StPtr},
"strexd");
8819 if (BuiltinID == clang::ARM::BI__builtin_arm_strex ||
8820 BuiltinID == clang::ARM::BI__builtin_arm_stlex) {
8825 llvm::Type *StoreTy =
8828 if (StoreVal->
getType()->isPointerTy())
8831 llvm::Type *
IntTy = llvm::IntegerType::get(
8839 BuiltinID == clang::ARM::BI__builtin_arm_stlex ? Intrinsic::arm_stlex
8840 : Intrinsic::arm_strex,
8843 CallInst *CI =
Builder.CreateCall(F, {StoreVal, StoreAddr},
"strex");
8845 1, Attribute::get(
getLLVMContext(), Attribute::ElementType, StoreTy));
8849 if (BuiltinID == clang::ARM::BI__builtin_arm_clrex) {
8855 Intrinsic::ID CRCIntrinsicID = Intrinsic::not_intrinsic;
8856 switch (BuiltinID) {
8857 case clang::ARM::BI__builtin_arm_crc32b:
8858 CRCIntrinsicID = Intrinsic::arm_crc32b;
break;
8859 case clang::ARM::BI__builtin_arm_crc32cb:
8860 CRCIntrinsicID = Intrinsic::arm_crc32cb;
break;
8861 case clang::ARM::BI__builtin_arm_crc32h:
8862 CRCIntrinsicID = Intrinsic::arm_crc32h;
break;
8863 case clang::ARM::BI__builtin_arm_crc32ch:
8864 CRCIntrinsicID = Intrinsic::arm_crc32ch;
break;
8865 case clang::ARM::BI__builtin_arm_crc32w:
8866 case clang::ARM::BI__builtin_arm_crc32d:
8867 CRCIntrinsicID = Intrinsic::arm_crc32w;
break;
8868 case clang::ARM::BI__builtin_arm_crc32cw:
8869 case clang::ARM::BI__builtin_arm_crc32cd:
8870 CRCIntrinsicID = Intrinsic::arm_crc32cw;
break;
8873 if (CRCIntrinsicID != Intrinsic::not_intrinsic) {
8879 if (BuiltinID == clang::ARM::BI__builtin_arm_crc32d ||
8880 BuiltinID == clang::ARM::BI__builtin_arm_crc32cd) {
8888 return Builder.CreateCall(F, {Res, Arg1b});
8893 return Builder.CreateCall(F, {Arg0, Arg1});
8897 if (BuiltinID == clang::ARM::BI__builtin_arm_rsr ||
8898 BuiltinID == clang::ARM::BI__builtin_arm_rsr64 ||
8899 BuiltinID == clang::ARM::BI__builtin_arm_rsrp ||
8900 BuiltinID == clang::ARM::BI__builtin_arm_wsr ||
8901 BuiltinID == clang::ARM::BI__builtin_arm_wsr64 ||
8902 BuiltinID == clang::ARM::BI__builtin_arm_wsrp) {
8905 if (BuiltinID == clang::ARM::BI__builtin_arm_rsr ||
8906 BuiltinID == clang::ARM::BI__builtin_arm_rsr64 ||
8907 BuiltinID == clang::ARM::BI__builtin_arm_rsrp)
8910 bool IsPointerBuiltin = BuiltinID == clang::ARM::BI__builtin_arm_rsrp ||
8911 BuiltinID == clang::ARM::BI__builtin_arm_wsrp;
8913 bool Is64Bit = BuiltinID == clang::ARM::BI__builtin_arm_rsr64 ||
8914 BuiltinID == clang::ARM::BI__builtin_arm_wsr64;
8916 llvm::Type *ValueType;
8917 llvm::Type *RegisterType;
8918 if (IsPointerBuiltin) {
8921 }
else if (Is64Bit) {
8922 ValueType = RegisterType =
Int64Ty;
8924 ValueType = RegisterType =
Int32Ty;
8931 if (BuiltinID == ARM::BI__builtin_sponentry) {
8950 return P.first == BuiltinID;
8953 BuiltinID = It->second;
8957 unsigned ICEArguments = 0;
8962 auto getAlignmentValue32 = [&](
Address addr) ->
Value* {
8963 return Builder.getInt32(addr.getAlignment().getQuantity());
8970 unsigned NumArgs =
E->getNumArgs() - (HasExtraArg ? 1 : 0);
8971 for (
unsigned i = 0, e = NumArgs; i != e; i++) {
8973 switch (BuiltinID) {
8974 case NEON::BI__builtin_neon_vld1_v:
8975 case NEON::BI__builtin_neon_vld1q_v:
8976 case NEON::BI__builtin_neon_vld1q_lane_v:
8977 case NEON::BI__builtin_neon_vld1_lane_v:
8978 case NEON::BI__builtin_neon_vld1_dup_v:
8979 case NEON::BI__builtin_neon_vld1q_dup_v:
8980 case NEON::BI__builtin_neon_vst1_v:
8981 case NEON::BI__builtin_neon_vst1q_v:
8982 case NEON::BI__builtin_neon_vst1q_lane_v:
8983 case NEON::BI__builtin_neon_vst1_lane_v:
8984 case NEON::BI__builtin_neon_vst2_v:
8985 case NEON::BI__builtin_neon_vst2q_v:
8986 case NEON::BI__builtin_neon_vst2_lane_v:
8987 case NEON::BI__builtin_neon_vst2q_lane_v:
8988 case NEON::BI__builtin_neon_vst3_v:
8989 case NEON::BI__builtin_neon_vst3q_v:
8990 case NEON::BI__builtin_neon_vst3_lane_v:
8991 case NEON::BI__builtin_neon_vst3q_lane_v:
8992 case NEON::BI__builtin_neon_vst4_v:
8993 case NEON::BI__builtin_neon_vst4q_v:
8994 case NEON::BI__builtin_neon_vst4_lane_v:
8995 case NEON::BI__builtin_neon_vst4q_lane_v:
9004 switch (BuiltinID) {
9005 case NEON::BI__builtin_neon_vld2_v:
9006 case NEON::BI__builtin_neon_vld2q_v:
9007 case NEON::BI__builtin_neon_vld3_v:
9008 case NEON::BI__builtin_neon_vld3q_v:
9009 case NEON::BI__builtin_neon_vld4_v:
9010 case NEON::BI__builtin_neon_vld4q_v:
9011 case NEON::BI__builtin_neon_vld2_lane_v:
9012 case NEON::BI__builtin_neon_vld2q_lane_v:
9013 case NEON::BI__builtin_neon_vld3_lane_v:
9014 case NEON::BI__builtin_neon_vld3q_lane_v:
9015 case NEON::BI__builtin_neon_vld4_lane_v:
9016 case NEON::BI__builtin_neon_vld4q_lane_v:
9017 case NEON::BI__builtin_neon_vld2_dup_v:
9018 case NEON::BI__builtin_neon_vld2q_dup_v:
9019 case NEON::BI__builtin_neon_vld3_dup_v:
9020 case NEON::BI__builtin_neon_vld3q_dup_v:
9021 case NEON::BI__builtin_neon_vld4_dup_v:
9022 case NEON::BI__builtin_neon_vld4q_dup_v:
9034 switch (BuiltinID) {
9037 case NEON::BI__builtin_neon_vget_lane_i8:
9038 case NEON::BI__builtin_neon_vget_lane_i16:
9039 case NEON::BI__builtin_neon_vget_lane_i32:
9040 case NEON::BI__builtin_neon_vget_lane_i64:
9041 case NEON::BI__builtin_neon_vget_lane_bf16:
9042 case NEON::BI__builtin_neon_vget_lane_f32:
9043 case NEON::BI__builtin_neon_vgetq_lane_i8:
9044 case NEON::BI__builtin_neon_vgetq_lane_i16:
9045 case NEON::BI__builtin_neon_vgetq_lane_i32:
9046 case NEON::BI__builtin_neon_vgetq_lane_i64:
9047 case NEON::BI__builtin_neon_vgetq_lane_bf16:
9048 case NEON::BI__builtin_neon_vgetq_lane_f32:
9049 case NEON::BI__builtin_neon_vduph_lane_bf16:
9050 case NEON::BI__builtin_neon_vduph_laneq_bf16:
9051 return Builder.CreateExtractElement(Ops[0], Ops[1],
"vget_lane");
9053 case NEON::BI__builtin_neon_vrndns_f32: {
9055 llvm::Type *Tys[] = {Arg->
getType()};
9057 return Builder.CreateCall(F, {Arg},
"vrndn"); }
9059 case NEON::BI__builtin_neon_vset_lane_i8:
9060 case NEON::BI__builtin_neon_vset_lane_i16:
9061 case NEON::BI__builtin_neon_vset_lane_i32:
9062 case NEON::BI__builtin_neon_vset_lane_i64:
9063 case NEON::BI__builtin_neon_vset_lane_bf16:
9064 case NEON::BI__builtin_neon_vset_lane_f32:
9065 case NEON::BI__builtin_neon_vsetq_lane_i8:
9066 case NEON::BI__builtin_neon_vsetq_lane_i16:
9067 case NEON::BI__builtin_neon_vsetq_lane_i32:
9068 case NEON::BI__builtin_neon_vsetq_lane_i64:
9069 case NEON::BI__builtin_neon_vsetq_lane_bf16:
9070 case NEON::BI__builtin_neon_vsetq_lane_f32:
9071 return Builder.CreateInsertElement(Ops[1], Ops[0], Ops[2],
"vset_lane");
9073 case NEON::BI__builtin_neon_vsha1h_u32:
9076 case NEON::BI__builtin_neon_vsha1cq_u32:
9079 case NEON::BI__builtin_neon_vsha1pq_u32:
9082 case NEON::BI__builtin_neon_vsha1mq_u32:
9086 case NEON::BI__builtin_neon_vcvth_bf16_f32: {
9093 case clang::ARM::BI_MoveToCoprocessor:
9094 case clang::ARM::BI_MoveToCoprocessor2: {
9096 ? Intrinsic::arm_mcr
9097 : Intrinsic::arm_mcr2);
9098 return Builder.CreateCall(F, {Ops[1], Ops[2], Ops[0],
9099 Ops[3], Ops[4], Ops[5]});
9104 assert(HasExtraArg);
9105 const Expr *Arg =
E->getArg(
E->getNumArgs()-1);
9106 std::optional<llvm::APSInt>
Result =
9111 if (BuiltinID == clang::ARM::BI__builtin_arm_vcvtr_f ||
9112 BuiltinID == clang::ARM::BI__builtin_arm_vcvtr_d) {
9115 if (BuiltinID == clang::ARM::BI__builtin_arm_vcvtr_f)
9121 bool usgn =
Result->getZExtValue() == 1;
9122 unsigned Int = usgn ? Intrinsic::arm_vcvtru : Intrinsic::arm_vcvtr;
9126 return Builder.CreateCall(F, Ops,
"vcvtr");
9131 bool usgn =
Type.isUnsigned();
9132 bool rightShift =
false;
9134 llvm::FixedVectorType *VTy =
9137 llvm::Type *Ty = VTy;
9148 Builtin->BuiltinID, Builtin->LLVMIntrinsic, Builtin->AltLLVMIntrinsic,
9149 Builtin->NameHint, Builtin->TypeModifier,
E, Ops, PtrOp0, PtrOp1, Arch);
9152 switch (BuiltinID) {
9153 default:
return nullptr;
9154 case NEON::BI__builtin_neon_vld1q_lane_v:
9157 if (VTy->getElementType()->isIntegerTy(64)) {
9159 Ops[1] =
Builder.CreateBitCast(Ops[1], Ty);
9160 int Lane = cast<ConstantInt>(Ops[2])->getZExtValue();
9161 Value *SV = llvm::ConstantVector::get(ConstantInt::get(
Int32Ty, 1-Lane));
9162 Ops[1] =
Builder.CreateShuffleVector(Ops[1], Ops[1], SV);
9164 Ty = llvm::FixedVectorType::get(VTy->getElementType(), 1);
9167 Value *Align = getAlignmentValue32(PtrOp0);
9170 int Indices[] = {1 - Lane, Lane};
9171 return Builder.CreateShuffleVector(Ops[1], Ld, Indices,
"vld1q_lane");
9174 case NEON::BI__builtin_neon_vld1_lane_v: {
9175 Ops[1] =
Builder.CreateBitCast(Ops[1], Ty);
9178 return Builder.CreateInsertElement(Ops[1], Ld, Ops[2],
"vld1_lane");
9180 case NEON::BI__builtin_neon_vqrshrn_n_v:
9182 usgn ? Intrinsic::arm_neon_vqrshiftnu : Intrinsic::arm_neon_vqrshiftns;
9185 case NEON::BI__builtin_neon_vqrshrun_n_v:
9187 Ops,
"vqrshrun_n", 1,
true);
9188 case NEON::BI__builtin_neon_vqshrn_n_v:
9189 Int = usgn ? Intrinsic::arm_neon_vqshiftnu : Intrinsic::arm_neon_vqshiftns;
9192 case NEON::BI__builtin_neon_vqshrun_n_v:
9194 Ops,
"vqshrun_n", 1,
true);
9195 case NEON::BI__builtin_neon_vrecpe_v:
9196 case NEON::BI__builtin_neon_vrecpeq_v:
9199 case NEON::BI__builtin_neon_vrshrn_n_v:
9201 Ops,
"vrshrn_n", 1,
true);
9202 case NEON::BI__builtin_neon_vrsra_n_v:
9203 case NEON::BI__builtin_neon_vrsraq_n_v:
9204 Ops[0] =
Builder.CreateBitCast(Ops[0], Ty);
9205 Ops[1] =
Builder.CreateBitCast(Ops[1], Ty);
9207 Int = usgn ? Intrinsic::arm_neon_vrshiftu : Intrinsic::arm_neon_vrshifts;
9209 return Builder.CreateAdd(Ops[0], Ops[1],
"vrsra_n");
9210 case NEON::BI__builtin_neon_vsri_n_v:
9211 case NEON::BI__builtin_neon_vsriq_n_v:
9214 case NEON::BI__builtin_neon_vsli_n_v:
9215 case NEON::BI__builtin_neon_vsliq_n_v:
9219 case NEON::BI__builtin_neon_vsra_n_v:
9220 case NEON::BI__builtin_neon_vsraq_n_v:
9221 Ops[0] =
Builder.CreateBitCast(Ops[0], Ty);
9223 return Builder.CreateAdd(Ops[0], Ops[1]);
9224 case NEON::BI__builtin_neon_vst1q_lane_v:
9227 if (VTy->getElementType()->isIntegerTy(64)) {
9228 Ops[1] =
Builder.CreateBitCast(Ops[1], Ty);
9229 Value *SV = llvm::ConstantVector::get(cast<llvm::Constant>(Ops[2]));
9230 Ops[1] =
Builder.CreateShuffleVector(Ops[1], Ops[1], SV);
9231 Ops[2] = getAlignmentValue32(PtrOp0);
9232 llvm::Type *Tys[] = {
Int8PtrTy, Ops[1]->getType()};
9237 case NEON::BI__builtin_neon_vst1_lane_v: {
9238 Ops[1] =
Builder.CreateBitCast(Ops[1], Ty);
9239 Ops[1] =
Builder.CreateExtractElement(Ops[1], Ops[2]);
9243 case NEON::BI__builtin_neon_vtbl1_v:
9246 case NEON::BI__builtin_neon_vtbl2_v:
9249 case NEON::BI__builtin_neon_vtbl3_v:
9252 case NEON::BI__builtin_neon_vtbl4_v:
9255 case NEON::BI__builtin_neon_vtbx1_v:
9258 case NEON::BI__builtin_neon_vtbx2_v:
9261 case NEON::BI__builtin_neon_vtbx3_v:
9264 case NEON::BI__builtin_neon_vtbx4_v:
9270template<
typename Integer>
9279 return Unsigned ? Builder.CreateZExt(
V,
T) : Builder.CreateSExt(
V,
T);
9289 unsigned LaneBits = cast<llvm::VectorType>(
V->getType())
9291 ->getPrimitiveSizeInBits();
9292 if (Shift == LaneBits) {
9297 return llvm::Constant::getNullValue(
V->getType());
9301 return Unsigned ? Builder.CreateLShr(
V, Shift) : Builder.CreateAShr(
V, Shift);
9308 unsigned Elements = 128 /
V->getType()->getPrimitiveSizeInBits();
9309 return Builder.CreateVectorSplat(Elements,
V);
9315 llvm::Type *DestType) {
9328 V->getType()->getScalarSizeInBits() != DestType->getScalarSizeInBits()) {
9329 return Builder.CreateCall(
9331 {DestType, V->getType()}),
9334 return Builder.CreateBitCast(
V, DestType);
9342 unsigned InputElements =
9343 cast<llvm::FixedVectorType>(
V->getType())->getNumElements();
9344 for (
unsigned i = 0; i < InputElements; i += 2)
9345 Indices.push_back(i + Odd);
9346 return Builder.CreateShuffleVector(
V, Indices);
9352 assert(V0->getType() == V1->getType() &&
"Can't zip different vector types");
9354 unsigned InputElements =
9355 cast<llvm::FixedVectorType>(V0->getType())->getNumElements();
9356 for (
unsigned i = 0; i < InputElements; i++) {
9357 Indices.push_back(i);
9358 Indices.push_back(i + InputElements);
9360 return Builder.CreateShuffleVector(V0, V1, Indices);
9363template<
unsigned HighBit,
unsigned OtherBits>
9367 llvm::Type *
T = cast<llvm::VectorType>(VT)->getElementType();
9368 unsigned LaneBits =
T->getPrimitiveSizeInBits();
9369 uint32_t
Value = HighBit << (LaneBits - 1);
9371 Value |= (1UL << (LaneBits - 1)) - 1;
9372 llvm::Value *Lane = llvm::ConstantInt::get(
T,
Value);
9378 unsigned ReverseWidth) {
9382 unsigned LaneSize =
V->getType()->getScalarSizeInBits();
9383 unsigned Elements = 128 / LaneSize;
9384 unsigned Mask = ReverseWidth / LaneSize - 1;
9385 for (
unsigned i = 0; i < Elements; i++)
9386 Indices.push_back(i ^ Mask);
9387 return Builder.CreateShuffleVector(
V, Indices);
9393 llvm::Triple::ArchType Arch) {
9394 enum class CustomCodeGen { VLD24, VST24 } CustomCodeGenType;
9395 Intrinsic::ID IRIntr;
9396 unsigned NumVectors;
9399 switch (BuiltinID) {
9400 #include "clang/Basic/arm_mve_builtin_cg.inc"
9411 switch (CustomCodeGenType) {
9413 case CustomCodeGen::VLD24: {
9419 assert(MvecLType->isStructTy() &&
9420 "Return type for vld[24]q should be a struct");
9421 assert(MvecLType->getStructNumElements() == 1 &&
9422 "Return-type struct for vld[24]q should have one element");
9423 auto MvecLTypeInner = MvecLType->getStructElementType(0);
9424 assert(MvecLTypeInner->isArrayTy() &&
9425 "Return-type struct for vld[24]q should contain an array");
9426 assert(MvecLTypeInner->getArrayNumElements() == NumVectors &&
9427 "Array member of return-type struct vld[24]q has wrong length");
9428 auto VecLType = MvecLTypeInner->getArrayElementType();
9430 Tys.push_back(VecLType);
9432 auto Addr =
E->getArg(0);
9438 Value *MvecOut = PoisonValue::get(MvecLType);
9439 for (
unsigned i = 0; i < NumVectors; ++i) {
9440 Value *Vec =
Builder.CreateExtractValue(LoadResult, i);
9441 MvecOut =
Builder.CreateInsertValue(MvecOut, Vec, {0, i});
9450 case CustomCodeGen::VST24: {
9454 auto Addr =
E->getArg(0);
9458 auto MvecCType =
E->getArg(1)->
getType();
9460 assert(MvecLType->isStructTy() &&
"Data type for vst2q should be a struct");
9461 assert(MvecLType->getStructNumElements() == 1 &&
9462 "Data-type struct for vst2q should have one element");
9463 auto MvecLTypeInner = MvecLType->getStructElementType(0);
9464 assert(MvecLTypeInner->isArrayTy() &&
9465 "Data-type struct for vst2q should contain an array");
9466 assert(MvecLTypeInner->getArrayNumElements() == NumVectors &&
9467 "Array member of return-type struct vld[24]q has wrong length");
9468 auto VecLType = MvecLTypeInner->getArrayElementType();
9470 Tys.push_back(VecLType);
9475 for (
unsigned i = 0; i < NumVectors; i++)
9476 Ops.push_back(
Builder.CreateExtractValue(Mvec, {0, i}));
9479 Value *ToReturn =
nullptr;
9480 for (
unsigned i = 0; i < NumVectors; i++) {
9481 Ops.push_back(llvm::ConstantInt::get(
Int32Ty, i));
9482 ToReturn =
Builder.CreateCall(F, Ops);
9488 llvm_unreachable(
"unknown custom codegen type.");
9494 llvm::Triple::ArchType Arch) {
9495 switch (BuiltinID) {
9498#include "clang/Basic/arm_cde_builtin_cg.inc"
9505 llvm::Triple::ArchType Arch) {
9506 unsigned int Int = 0;
9507 const char *
s =
nullptr;
9509 switch (BuiltinID) {
9512 case NEON::BI__builtin_neon_vtbl1_v:
9513 case NEON::BI__builtin_neon_vqtbl1_v:
9514 case NEON::BI__builtin_neon_vqtbl1q_v:
9515 case NEON::BI__builtin_neon_vtbl2_v:
9516 case NEON::BI__builtin_neon_vqtbl2_v:
9517 case NEON::BI__builtin_neon_vqtbl2q_v:
9518 case NEON::BI__builtin_neon_vtbl3_v:
9519 case NEON::BI__builtin_neon_vqtbl3_v:
9520 case NEON::BI__builtin_neon_vqtbl3q_v:
9521 case NEON::BI__builtin_neon_vtbl4_v:
9522 case NEON::BI__builtin_neon_vqtbl4_v:
9523 case NEON::BI__builtin_neon_vqtbl4q_v:
9525 case NEON::BI__builtin_neon_vtbx1_v:
9526 case NEON::BI__builtin_neon_vqtbx1_v:
9527 case NEON::BI__builtin_neon_vqtbx1q_v:
9528 case NEON::BI__builtin_neon_vtbx2_v:
9529 case NEON::BI__builtin_neon_vqtbx2_v:
9530 case NEON::BI__builtin_neon_vqtbx2q_v:
9531 case NEON::BI__builtin_neon_vtbx3_v:
9532 case NEON::BI__builtin_neon_vqtbx3_v:
9533 case NEON::BI__builtin_neon_vqtbx3q_v:
9534 case NEON::BI__builtin_neon_vtbx4_v:
9535 case NEON::BI__builtin_neon_vqtbx4_v:
9536 case NEON::BI__builtin_neon_vqtbx4q_v:
9540 assert(
E->getNumArgs() >= 3);
9543 const Expr *Arg =
E->getArg(
E->getNumArgs() - 1);
9544 std::optional<llvm::APSInt>
Result =
9559 switch (BuiltinID) {
9560 case NEON::BI__builtin_neon_vtbl1_v: {
9562 Ty, Intrinsic::aarch64_neon_tbl1,
"vtbl1");
9564 case NEON::BI__builtin_neon_vtbl2_v: {
9566 Ty, Intrinsic::aarch64_neon_tbl1,
"vtbl1");
9568 case NEON::BI__builtin_neon_vtbl3_v: {
9570 Ty, Intrinsic::aarch64_neon_tbl2,
"vtbl2");
9572 case NEON::BI__builtin_neon_vtbl4_v: {
9574 Ty, Intrinsic::aarch64_neon_tbl2,
"vtbl2");
9576 case NEON::BI__builtin_neon_vtbx1_v: {
9579 Intrinsic::aarch64_neon_tbl1,
"vtbl1");
9581 llvm::Constant *EightV = ConstantInt::get(Ty, 8);
9582 Value *CmpRes = Builder.CreateICmp(ICmpInst::ICMP_UGE, Ops[2], EightV);
9583 CmpRes = Builder.CreateSExt(CmpRes, Ty);
9585 Value *EltsFromInput = Builder.CreateAnd(CmpRes, Ops[0]);
9586 Value *EltsFromTbl = Builder.CreateAnd(Builder.CreateNot(CmpRes), TblRes);
9587 return Builder.CreateOr(EltsFromInput, EltsFromTbl,
"vtbx");
9589 case NEON::BI__builtin_neon_vtbx2_v: {
9591 Ty, Intrinsic::aarch64_neon_tbx1,
"vtbx1");
9593 case NEON::BI__builtin_neon_vtbx3_v: {
9596 Intrinsic::aarch64_neon_tbl2,
"vtbl2");
9598 llvm::Constant *TwentyFourV = ConstantInt::get(Ty, 24);
9599 Value *CmpRes = Builder.CreateICmp(ICmpInst::ICMP_UGE, Ops[4],
9601 CmpRes = Builder.CreateSExt(CmpRes, Ty);
9603 Value *EltsFromInput = Builder.CreateAnd(CmpRes, Ops[0]);
9604 Value *EltsFromTbl = Builder.CreateAnd(Builder.CreateNot(CmpRes), TblRes);
9605 return Builder.CreateOr(EltsFromInput, EltsFromTbl,
"vtbx");
9607 case NEON::BI__builtin_neon_vtbx4_v: {
9609 Ty, Intrinsic::aarch64_neon_tbx2,
"vtbx2");
9611 case NEON::BI__builtin_neon_vqtbl1_v:
9612 case NEON::BI__builtin_neon_vqtbl1q_v:
9613 Int = Intrinsic::aarch64_neon_tbl1;
s =
"vtbl1";
break;
9614 case NEON::BI__builtin_neon_vqtbl2_v:
9615 case NEON::BI__builtin_neon_vqtbl2q_v: {
9616 Int = Intrinsic::aarch64_neon_tbl2;
s =
"vtbl2";
break;
9617 case NEON::BI__builtin_neon_vqtbl3_v:
9618 case NEON::BI__builtin_neon_vqtbl3q_v:
9619 Int = Intrinsic::aarch64_neon_tbl3;
s =
"vtbl3";
break;
9620 case NEON::BI__builtin_neon_vqtbl4_v:
9621 case NEON::BI__builtin_neon_vqtbl4q_v:
9622 Int = Intrinsic::aarch64_neon_tbl4;
s =
"vtbl4";
break;
9623 case NEON::BI__builtin_neon_vqtbx1_v:
9624 case NEON::BI__builtin_neon_vqtbx1q_v:
9625 Int = Intrinsic::aarch64_neon_tbx1;
s =
"vtbx1";
break;
9626 case NEON::BI__builtin_neon_vqtbx2_v:
9627 case NEON::BI__builtin_neon_vqtbx2q_v:
9628 Int = Intrinsic::aarch64_neon_tbx2;
s =
"vtbx2";
break;
9629 case NEON::BI__builtin_neon_vqtbx3_v:
9630 case NEON::BI__builtin_neon_vqtbx3q_v:
9631 Int = Intrinsic::aarch64_neon_tbx3;
s =
"vtbx3";
break;
9632 case NEON::BI__builtin_neon_vqtbx4_v:
9633 case NEON::BI__builtin_neon_vqtbx4q_v:
9634 Int = Intrinsic::aarch64_neon_tbx4;
s =
"vtbx4";
break;
9646 auto *VTy = llvm::FixedVectorType::get(
Int16Ty, 4);
9648 Value *
V = PoisonValue::get(VTy);
9649 llvm::Constant *CI = ConstantInt::get(
SizeTy, 0);
9650 Op =
Builder.CreateInsertElement(
V, Op, CI);
9659 case SVETypeFlags::MemEltTyDefault:
9661 case SVETypeFlags::MemEltTyInt8:
9663 case SVETypeFlags::MemEltTyInt16:
9665 case SVETypeFlags::MemEltTyInt32:
9667 case SVETypeFlags::MemEltTyInt64:
9670 llvm_unreachable(
"Unknown MemEltType");
9676 llvm_unreachable(
"Invalid SVETypeFlag!");
9678 case SVETypeFlags::EltTyInt8:
9680 case SVETypeFlags::EltTyInt16:
9682 case SVETypeFlags::EltTyInt32:
9684 case SVETypeFlags::EltTyInt64:
9686 case SVETypeFlags::EltTyInt128:
9689 case SVETypeFlags::EltTyFloat16:
9691 case SVETypeFlags::EltTyFloat32:
9693 case SVETypeFlags::EltTyFloat64:
9696 case SVETypeFlags::EltTyBFloat16:
9699 case SVETypeFlags::EltTyBool8:
9700 case SVETypeFlags::EltTyBool16:
9701 case SVETypeFlags::EltTyBool32:
9702 case SVETypeFlags::EltTyBool64:
9709llvm::ScalableVectorType *
9712 default: llvm_unreachable(
"Unhandled SVETypeFlag!");
9714 case SVETypeFlags::EltTyInt8:
9715 return llvm::ScalableVectorType::get(
Builder.getInt1Ty(), 16);
9716 case SVETypeFlags::EltTyInt16:
9717 return llvm::ScalableVectorType::get(
Builder.getInt1Ty(), 8);
9718 case SVETypeFlags::EltTyInt32:
9719 return llvm::ScalableVectorType::get(
Builder.getInt1Ty(), 4);
9720 case SVETypeFlags::EltTyInt64:
9721 return llvm::ScalableVectorType::get(
Builder.getInt1Ty(), 2);
9723 case SVETypeFlags::EltTyBFloat16:
9724 return llvm::ScalableVectorType::get(
Builder.getInt1Ty(), 8);
9725 case SVETypeFlags::EltTyFloat16:
9726 return llvm::ScalableVectorType::get(
Builder.getInt1Ty(), 8);
9727 case SVETypeFlags::EltTyFloat32:
9728 return llvm::ScalableVectorType::get(
Builder.getInt1Ty(), 4);
9729 case SVETypeFlags::EltTyFloat64:
9730 return llvm::ScalableVectorType::get(
Builder.getInt1Ty(), 2);
9732 case SVETypeFlags::EltTyBool8:
9733 return llvm::ScalableVectorType::get(
Builder.getInt1Ty(), 16);
9734 case SVETypeFlags::EltTyBool16:
9735 return llvm::ScalableVectorType::get(
Builder.getInt1Ty(), 8);
9736 case SVETypeFlags::EltTyBool32:
9737 return llvm::ScalableVectorType::get(
Builder.getInt1Ty(), 4);
9738 case SVETypeFlags::EltTyBool64:
9739 return llvm::ScalableVectorType::get(
Builder.getInt1Ty(), 2);
9744llvm::ScalableVectorType *
9748 llvm_unreachable(
"Invalid SVETypeFlag!");
9750 case SVETypeFlags::EltTyInt8:
9751 return llvm::ScalableVectorType::get(
Builder.getInt8Ty(), 16);
9752 case SVETypeFlags::EltTyInt16:
9753 return llvm::ScalableVectorType::get(
Builder.getInt16Ty(), 8);
9754 case SVETypeFlags::EltTyInt32:
9755 return llvm::ScalableVectorType::get(
Builder.getInt32Ty(), 4);
9756 case SVETypeFlags::EltTyInt64:
9757 return llvm::ScalableVectorType::get(
Builder.getInt64Ty(), 2);
9759 case SVETypeFlags::EltTyFloat16:
9760 return llvm::ScalableVectorType::get(
Builder.getHalfTy(), 8);
9761 case SVETypeFlags::EltTyBFloat16:
9762 return llvm::ScalableVectorType::get(
Builder.getBFloatTy(), 8);
9763 case SVETypeFlags::EltTyFloat32:
9764 return llvm::ScalableVectorType::get(
Builder.getFloatTy(), 4);
9765 case SVETypeFlags::EltTyFloat64:
9766 return llvm::ScalableVectorType::get(
Builder.getDoubleTy(), 2);
9768 case SVETypeFlags::EltTyBool8:
9769 return llvm::ScalableVectorType::get(
Builder.getInt1Ty(), 16);
9770 case SVETypeFlags::EltTyBool16:
9771 return llvm::ScalableVectorType::get(
Builder.getInt1Ty(), 8);
9772 case SVETypeFlags::EltTyBool32:
9773 return llvm::ScalableVectorType::get(
Builder.getInt1Ty(), 4);
9774 case SVETypeFlags::EltTyBool64:
9775 return llvm::ScalableVectorType::get(
Builder.getInt1Ty(), 2);
9790 return llvm::ScalableVectorType::get(EltTy, NumElts);
9796 llvm::ScalableVectorType *VTy) {
9798 if (isa<TargetExtType>(Pred->
getType()) &&
9799 cast<TargetExtType>(Pred->
getType())->getName() ==
"aarch64.svcount")
9802 auto *RTy = llvm::VectorType::get(IntegerType::get(
getLLVMContext(), 1), VTy);
9807 llvm::Type *IntrinsicTy;
9808 switch (VTy->getMinNumElements()) {
9810 llvm_unreachable(
"unsupported element count!");
9815 IntID = Intrinsic::aarch64_sve_convert_from_svbool;
9819 IntID = Intrinsic::aarch64_sve_convert_to_svbool;
9820 IntrinsicTy = Pred->
getType();
9826 assert(
C->getType() == RTy &&
"Unexpected return type!");
9834 auto *OverloadedTy =
9838 if (Ops[1]->getType()->isVectorTy())
9858 Ops[0], cast<llvm::ScalableVectorType>(F->getArg(0)->getType()));
9863 if (Ops.size() == 2) {
9864 assert(Ops[1]->getType()->isVectorTy() &&
"Scalar base requires an offset");
9865 Ops.push_back(ConstantInt::get(
Int64Ty, 0));
9870 if (!TypeFlags.
isByteIndexed() && Ops[1]->getType()->isVectorTy()) {
9871 unsigned BytesPerElt =
9872 OverloadedTy->getElementType()->getScalarSizeInBits() / 8;
9873 Ops[2] =
Builder.CreateShl(Ops[2], Log2_32(BytesPerElt));
9888 auto *OverloadedTy =
9893 Ops.insert(Ops.begin(), Ops.pop_back_val());
9896 if (Ops[2]->getType()->isVectorTy())
9911 if (Ops.size() == 3) {
9912 assert(Ops[1]->getType()->isVectorTy() &&
"Scalar base requires an offset");
9913 Ops.push_back(ConstantInt::get(
Int64Ty, 0));
9918 Ops[0] =
Builder.CreateTrunc(Ops[0], OverloadedTy);
9928 Ops[1], cast<llvm::ScalableVectorType>(F->getArg(1)->getType()));
9932 if (!TypeFlags.
isByteIndexed() && Ops[2]->getType()->isVectorTy()) {
9933 unsigned BytesPerElt =
9934 OverloadedTy->getElementType()->getScalarSizeInBits() / 8;
9935 Ops[3] =
Builder.CreateShl(Ops[3], Log2_32(BytesPerElt));
9938 return Builder.CreateCall(F, Ops);
9946 auto *OverloadedTy = dyn_cast<llvm::ScalableVectorType>(Ops[1]->getType());
9948 OverloadedTy = cast<llvm::ScalableVectorType>(Ops[2]->getType());
9954 if (Ops[1]->getType()->isVectorTy()) {
9955 if (Ops.size() == 3) {
9957 Ops.push_back(ConstantInt::get(
Int64Ty, 0));
9960 std::swap(Ops[2], Ops[3]);
9964 unsigned BytesPerElt = MemEltTy->getPrimitiveSizeInBits() / 8;
9965 if (BytesPerElt > 1)
9966 Ops[2] =
Builder.CreateShl(Ops[2], Log2_32(BytesPerElt));
9971 return Builder.CreateCall(F, Ops);
9977 llvm::ScalableVectorType *VTy =
getSVEType(TypeFlags);
9981 case Intrinsic::aarch64_sve_ld2_sret:
9982 case Intrinsic::aarch64_sve_ld1_pn_x2:
9983 case Intrinsic::aarch64_sve_ldnt1_pn_x2:
9984 case Intrinsic::aarch64_sve_ld2q_sret:
9987 case Intrinsic::aarch64_sve_ld3_sret:
9988 case Intrinsic::aarch64_sve_ld3q_sret:
9991 case Intrinsic::aarch64_sve_ld4_sret:
9992 case Intrinsic::aarch64_sve_ld1_pn_x4:
9993 case Intrinsic::aarch64_sve_ldnt1_pn_x4:
9994 case Intrinsic::aarch64_sve_ld4q_sret:
9998 llvm_unreachable(
"unknown intrinsic!");
10000 auto RetTy = llvm::VectorType::get(VTy->getElementType(),
10001 VTy->getElementCount() * N);
10004 Value *BasePtr = Ops[1];
10007 if (Ops.size() > 2)
10012 unsigned MinElts = VTy->getMinNumElements();
10013 Value *
Ret = llvm::PoisonValue::get(RetTy);
10014 for (
unsigned I = 0; I < N; I++) {
10017 Ret =
Builder.CreateInsertVector(RetTy, Ret, SRet, Idx);
10025 llvm::ScalableVectorType *VTy =
getSVEType(TypeFlags);
10029 case Intrinsic::aarch64_sve_st2:
10030 case Intrinsic::aarch64_sve_st1_pn_x2:
10031 case Intrinsic::aarch64_sve_stnt1_pn_x2:
10032 case Intrinsic::aarch64_sve_st2q:
10035 case Intrinsic::aarch64_sve_st3:
10036 case Intrinsic::aarch64_sve_st3q:
10039 case Intrinsic::aarch64_sve_st4:
10040 case Intrinsic::aarch64_sve_st1_pn_x4:
10041 case Intrinsic::aarch64_sve_stnt1_pn_x4:
10042 case Intrinsic::aarch64_sve_st4q:
10046 llvm_unreachable(
"unknown intrinsic!");
10050 Value *BasePtr = Ops[1];
10053 if (Ops.size() > (2 + N))
10059 for (
unsigned I = Ops.size() - N; I < Ops.size(); ++I)
10060 Operands.push_back(Ops[I]);
10061 Operands.append({Predicate, BasePtr});
10064 return Builder.CreateCall(F, Operands);
10072 unsigned BuiltinID) {
10084 llvm::ScalableVectorType *Ty =
getSVEType(TypeFlags);
10090 llvm::Type *OverloadedTy =
getSVEType(TypeFlags);
10097 unsigned BuiltinID) {
10100 auto *MemoryTy = llvm::ScalableVectorType::get(MemEltTy, VectorTy);
10103 Value *BasePtr = Ops[1];
10106 if (Ops.size() > 3)
10109 Value *PrfOp = Ops.back();
10112 return Builder.CreateCall(F, {Predicate, BasePtr, PrfOp});
10116 llvm::Type *ReturnTy,
10118 unsigned IntrinsicID,
10119 bool IsZExtReturn) {
10126 auto VectorTy = cast<llvm::ScalableVectorType>(ReturnTy);
10127 llvm::ScalableVectorType *MemoryTy =
nullptr;
10128 llvm::ScalableVectorType *PredTy =
nullptr;
10129 bool IsQuadLoad =
false;
10130 switch (IntrinsicID) {
10131 case Intrinsic::aarch64_sve_ld1uwq:
10132 case Intrinsic::aarch64_sve_ld1udq:
10133 MemoryTy = llvm::ScalableVectorType::get(MemEltTy, 1);
10134 PredTy = llvm::ScalableVectorType::get(
10139 MemoryTy = llvm::ScalableVectorType::get(MemEltTy, VectorTy);
10145 Value *BasePtr = Ops[1];
10148 if (Ops.size() > 2)
10153 cast<llvm::Instruction>(
Builder.CreateCall(F, {Predicate, BasePtr}));
10160 return IsZExtReturn ?
Builder.CreateZExt(Load, VectorTy)
10161 :
Builder.CreateSExt(Load, VectorTy);
10166 unsigned IntrinsicID) {
10173 auto VectorTy = cast<llvm::ScalableVectorType>(Ops.back()->getType());
10174 auto MemoryTy = llvm::ScalableVectorType::get(MemEltTy, VectorTy);
10176 auto PredTy = MemoryTy;
10177 auto AddrMemoryTy = MemoryTy;
10178 bool IsQuadStore =
false;
10180 switch (IntrinsicID) {
10181 case Intrinsic::aarch64_sve_st1wq:
10182 case Intrinsic::aarch64_sve_st1dq:
10183 AddrMemoryTy = llvm::ScalableVectorType::get(MemEltTy, 1);
10185 llvm::ScalableVectorType::get(IntegerType::get(
getLLVMContext(), 1), 1);
10186 IsQuadStore =
true;
10192 Value *BasePtr = Ops[1];
10195 if (Ops.size() == 4)
10200 IsQuadStore ? Ops.back() :
Builder.CreateTrunc(Ops.back(), MemoryTy);
10205 cast<llvm::Instruction>(
Builder.CreateCall(F, {Val, Predicate, BasePtr}));
10218 NewOps.push_back(Ops[2]);
10220 llvm::Value *BasePtr = Ops[3];
10224 if (Ops.size() == 5) {
10227 llvm::Value *StreamingVectorLengthCall =
10228 Builder.CreateCall(StreamingVectorLength);
10229 llvm::Value *Mulvl =
10230 Builder.CreateMul(StreamingVectorLengthCall, Ops[4],
"mulvl");
10234 NewOps.push_back(BasePtr);
10235 NewOps.push_back(Ops[0]);
10236 NewOps.push_back(Ops[1]);
10238 return Builder.CreateCall(F, NewOps);
10250 return Builder.CreateCall(F, Ops);
10257 if (Ops.size() == 0)
10258 Ops.push_back(llvm::ConstantInt::get(
Int32Ty, 255));
10260 return Builder.CreateCall(F, Ops);
10266 if (Ops.size() == 2)
10267 Ops.push_back(
Builder.getInt32(0));
10271 return Builder.CreateCall(F, Ops);
10277 return Builder.CreateVectorSplat(
10278 cast<llvm::VectorType>(Ty)->getElementCount(), Scalar);
10292 return Builder.CreateBitCast(Val, Ty);
10297 auto *SplatZero = Constant::getNullValue(Ty);
10298 Ops.insert(Ops.begin(), SplatZero);
10303 auto *SplatUndef = UndefValue::get(Ty);
10304 Ops.insert(Ops.begin(), SplatUndef);
10309 llvm::Type *ResultType,
10314 llvm::Type *DefaultType =
getSVEType(TypeFlags);
10317 return {DefaultType, Ops[1]->getType()};
10323 return {Ops[0]->getType(), Ops.back()->getType()};
10325 if (TypeFlags.
isReductionQV() && !ResultType->isScalableTy() &&
10326 ResultType->isVectorTy())
10327 return {ResultType, Ops[1]->getType()};
10330 return {DefaultType};
10337 "Expects TypleFlags.isTupleSet() or TypeFlags.isTupleGet()");
10339 unsigned I = cast<ConstantInt>(Ops[1])->getSExtValue();
10340 auto *SingleVecTy = dyn_cast<llvm::ScalableVectorType>(
10341 TypeFlags.
isTupleSet() ? Ops[2]->getType() : Ty);
10347 I * SingleVecTy->getMinNumElements());
10350 return Builder.CreateInsertVector(Ty, Ops[0], Ops[2], Idx);
10351 return Builder.CreateExtractVector(Ty, Ops[0], Idx);
10357 assert(TypeFlags.
isTupleCreate() &&
"Expects TypleFlag isTupleCreate");
10359 auto *SrcTy = dyn_cast<llvm::ScalableVectorType>(Ops[0]->getType());
10364 unsigned MinElts = SrcTy->getMinNumElements();
10365 Value *
Call = llvm::PoisonValue::get(Ty);
10366 for (
unsigned I = 0; I < Ops.size(); I++) {
10377 auto *StructTy = dyn_cast<StructType>(
Call->getType());
10381 auto *VTy = dyn_cast<ScalableVectorType>(StructTy->getTypeAtIndex(0
U));
10384 unsigned N = StructTy->getNumElements();
10387 bool IsPredTy = VTy->getElementType()->isIntegerTy(1);
10388 unsigned MinElts = IsPredTy ? 16 : VTy->getMinNumElements();
10390 ScalableVectorType *WideVTy =
10391 ScalableVectorType::get(VTy->getElementType(), MinElts * N);
10392 Value *
Ret = llvm::PoisonValue::get(WideVTy);
10393 for (
unsigned I = 0; I < N; ++I) {
10395 assert(SRet->
getType() == VTy &&
"Unexpected type for result value");
10400 SRet, ScalableVectorType::get(
Builder.getInt1Ty(), 16));
10402 Ret =
Builder.CreateInsertVector(WideVTy, Ret, SRet, Idx);
10413 unsigned ICEArguments = 0;
10422 for (
unsigned i = 0, e =
E->getNumArgs(); i != e; i++) {
10423 bool IsICE = ICEArguments & (1 << i);
10429 std::optional<llvm::APSInt>
Result =
10431 assert(
Result &&
"Expected argument to be a constant");
10441 if (IsTupleGetOrSet || !isa<ScalableVectorType>(Arg->getType())) {
10442 Ops.push_back(Arg);
10446 auto *VTy = cast<ScalableVectorType>(Arg->getType());
10447 unsigned MinElts = VTy->getMinNumElements();
10448 bool IsPred = VTy->getElementType()->isIntegerTy(1);
10449 unsigned N = (MinElts * VTy->getScalarSizeInBits()) / (IsPred ? 16 : 128);
10452 Ops.push_back(Arg);
10456 for (
unsigned I = 0; I < N; ++I) {
10459 ScalableVectorType::get(VTy->getElementType(), MinElts / N);
10460 Ops.push_back(
Builder.CreateExtractVector(NewVTy, Arg, Idx));
10468 if (BuiltinID >= SVE::BI__builtin_sve_reinterpret_s8_s8 &&
10469 BuiltinID <= SVE::BI__builtin_sve_reinterpret_f64_f64_x4) {
10484 else if (TypeFlags.
isStore())
10502 else if (TypeFlags.
isUndef())
10503 return UndefValue::get(Ty);
10504 else if (Builtin->LLVMIntrinsic != 0) {
10505 if (TypeFlags.
getMergeType() == SVETypeFlags::MergeZeroExp)
10508 if (TypeFlags.
getMergeType() == SVETypeFlags::MergeAnyExp)
10514 Ops.push_back(
Builder.getInt32( 31));
10516 Ops.insert(&Ops[1],
Builder.getInt32( 31));
10519 for (
unsigned i = 0, e = Ops.size(); i != e; ++i)
10520 if (
auto PredTy = dyn_cast<llvm::VectorType>(Ops[i]->getType()))
10521 if (PredTy->getElementType()->isIntegerTy(1))
10531 std::swap(Ops[1], Ops[2]);
10533 std::swap(Ops[1], Ops[2]);
10536 std::swap(Ops[1], Ops[2]);
10539 std::swap(Ops[1], Ops[3]);
10542 if (TypeFlags.
getMergeType() == SVETypeFlags::MergeZero) {
10543 llvm::Type *OpndTy = Ops[1]->getType();
10544 auto *SplatZero = Constant::getNullValue(OpndTy);
10545 Ops[1] =
Builder.CreateSelect(Ops[0], Ops[1], SplatZero);
10553 if (
auto PredTy = dyn_cast<llvm::VectorType>(
Call->getType()))
10554 if (PredTy->getScalarType()->isIntegerTy(1))
10560 switch (BuiltinID) {
10564 case SVE::BI__builtin_sve_svreinterpret_b: {
10568 CGM.
getIntrinsic(Intrinsic::aarch64_sve_convert_to_svbool, SVCountTy);
10569 return Builder.CreateCall(CastFromSVCountF, Ops[0]);
10571 case SVE::BI__builtin_sve_svreinterpret_c: {
10575 CGM.
getIntrinsic(Intrinsic::aarch64_sve_convert_from_svbool, SVCountTy);
10576 return Builder.CreateCall(CastToSVCountF, Ops[0]);
10579 case SVE::BI__builtin_sve_svpsel_lane_b8:
10580 case SVE::BI__builtin_sve_svpsel_lane_b16:
10581 case SVE::BI__builtin_sve_svpsel_lane_b32:
10582 case SVE::BI__builtin_sve_svpsel_lane_b64:
10583 case SVE::BI__builtin_sve_svpsel_lane_c8:
10584 case SVE::BI__builtin_sve_svpsel_lane_c16:
10585 case SVE::BI__builtin_sve_svpsel_lane_c32:
10586 case SVE::BI__builtin_sve_svpsel_lane_c64: {
10587 bool IsSVCount = isa<TargetExtType>(Ops[0]->getType());
10588 assert(((!IsSVCount || cast<TargetExtType>(Ops[0]->getType())->
getName() ==
10589 "aarch64.svcount")) &&
10590 "Unexpected TargetExtType");
10594 CGM.
getIntrinsic(Intrinsic::aarch64_sve_convert_to_svbool, SVCountTy);
10596 CGM.
getIntrinsic(Intrinsic::aarch64_sve_convert_from_svbool, SVCountTy);
10600 llvm::Value *Ops0 =
10601 IsSVCount ?
Builder.CreateCall(CastFromSVCountF, Ops[0]) : Ops[0];
10603 llvm::Value *PSel =
Builder.CreateCall(F, {Ops0, Ops1, Ops[2]});
10604 return IsSVCount ?
Builder.CreateCall(CastToSVCountF, PSel) : PSel;
10606 case SVE::BI__builtin_sve_svmov_b_z: {
10609 llvm::Type* OverloadedTy =
getSVEType(TypeFlags);
10611 return Builder.CreateCall(F, {Ops[0], Ops[1], Ops[1]});
10614 case SVE::BI__builtin_sve_svnot_b_z: {
10617 llvm::Type* OverloadedTy =
getSVEType(TypeFlags);
10619 return Builder.CreateCall(F, {Ops[0], Ops[1], Ops[0]});
10622 case SVE::BI__builtin_sve_svmovlb_u16:
10623 case SVE::BI__builtin_sve_svmovlb_u32:
10624 case SVE::BI__builtin_sve_svmovlb_u64:
10625 return EmitSVEMovl(TypeFlags, Ops, Intrinsic::aarch64_sve_ushllb);
10627 case SVE::BI__builtin_sve_svmovlb_s16:
10628 case SVE::BI__builtin_sve_svmovlb_s32:
10629 case SVE::BI__builtin_sve_svmovlb_s64:
10630 return EmitSVEMovl(TypeFlags, Ops, Intrinsic::aarch64_sve_sshllb);
10632 case SVE::BI__builtin_sve_svmovlt_u16:
10633 case SVE::BI__builtin_sve_svmovlt_u32:
10634 case SVE::BI__builtin_sve_svmovlt_u64:
10635 return EmitSVEMovl(TypeFlags, Ops, Intrinsic::aarch64_sve_ushllt);
10637 case SVE::BI__builtin_sve_svmovlt_s16:
10638 case SVE::BI__builtin_sve_svmovlt_s32:
10639 case SVE::BI__builtin_sve_svmovlt_s64:
10640 return EmitSVEMovl(TypeFlags, Ops, Intrinsic::aarch64_sve_sshllt);
10642 case SVE::BI__builtin_sve_svpmullt_u16:
10643 case SVE::BI__builtin_sve_svpmullt_u64:
10644 case SVE::BI__builtin_sve_svpmullt_n_u16:
10645 case SVE::BI__builtin_sve_svpmullt_n_u64:
10646 return EmitSVEPMull(TypeFlags, Ops, Intrinsic::aarch64_sve_pmullt_pair);
10648 case SVE::BI__builtin_sve_svpmullb_u16:
10649 case SVE::BI__builtin_sve_svpmullb_u64:
10650 case SVE::BI__builtin_sve_svpmullb_n_u16:
10651 case SVE::BI__builtin_sve_svpmullb_n_u64:
10652 return EmitSVEPMull(TypeFlags, Ops, Intrinsic::aarch64_sve_pmullb_pair);
10654 case SVE::BI__builtin_sve_svdup_n_b8:
10655 case SVE::BI__builtin_sve_svdup_n_b16:
10656 case SVE::BI__builtin_sve_svdup_n_b32:
10657 case SVE::BI__builtin_sve_svdup_n_b64: {
10659 Builder.CreateICmpNE(Ops[0], Constant::getNullValue(Ops[0]->getType()));
10660 llvm::ScalableVectorType *OverloadedTy =
getSVEType(TypeFlags);
10665 case SVE::BI__builtin_sve_svdupq_n_b8:
10666 case SVE::BI__builtin_sve_svdupq_n_b16:
10667 case SVE::BI__builtin_sve_svdupq_n_b32:
10668 case SVE::BI__builtin_sve_svdupq_n_b64:
10669 case SVE::BI__builtin_sve_svdupq_n_u8:
10670 case SVE::BI__builtin_sve_svdupq_n_s8:
10671 case SVE::BI__builtin_sve_svdupq_n_u64:
10672 case SVE::BI__builtin_sve_svdupq_n_f64:
10673 case SVE::BI__builtin_sve_svdupq_n_s64:
10674 case SVE::BI__builtin_sve_svdupq_n_u16:
10675 case SVE::BI__builtin_sve_svdupq_n_f16:
10676 case SVE::BI__builtin_sve_svdupq_n_bf16:
10677 case SVE::BI__builtin_sve_svdupq_n_s16:
10678 case SVE::BI__builtin_sve_svdupq_n_u32:
10679 case SVE::BI__builtin_sve_svdupq_n_f32:
10680 case SVE::BI__builtin_sve_svdupq_n_s32: {
10683 unsigned NumOpnds = Ops.size();
10686 cast<llvm::VectorType>(Ty)->getElementType()->isIntegerTy(1);
10691 llvm::Type *EltTy = Ops[0]->getType();
10696 for (
unsigned I = 0; I < NumOpnds; ++I)
10697 VecOps.push_back(
Builder.CreateZExt(Ops[I], EltTy));
10702 OverloadedTy, PoisonValue::get(OverloadedTy), Vec,
Builder.getInt64(0));
10717 : Intrinsic::aarch64_sve_cmpne_wide,
10724 case SVE::BI__builtin_sve_svpfalse_b:
10725 return ConstantInt::getFalse(Ty);
10727 case SVE::BI__builtin_sve_svpfalse_c: {
10728 auto SVBoolTy = ScalableVectorType::get(
Builder.getInt1Ty(), 16);
10731 return Builder.CreateCall(CastToSVCountF, ConstantInt::getFalse(SVBoolTy));
10734 case SVE::BI__builtin_sve_svlen_bf16:
10735 case SVE::BI__builtin_sve_svlen_f16:
10736 case SVE::BI__builtin_sve_svlen_f32:
10737 case SVE::BI__builtin_sve_svlen_f64:
10738 case SVE::BI__builtin_sve_svlen_s8:
10739 case SVE::BI__builtin_sve_svlen_s16:
10740 case SVE::BI__builtin_sve_svlen_s32:
10741 case SVE::BI__builtin_sve_svlen_s64:
10742 case SVE::BI__builtin_sve_svlen_u8:
10743 case SVE::BI__builtin_sve_svlen_u16:
10744 case SVE::BI__builtin_sve_svlen_u32:
10745 case SVE::BI__builtin_sve_svlen_u64: {
10747 auto VTy = cast<llvm::VectorType>(
getSVEType(TF));
10749 llvm::ConstantInt::get(Ty, VTy->getElementCount().getKnownMinValue());
10755 case SVE::BI__builtin_sve_svtbl2_u8:
10756 case SVE::BI__builtin_sve_svtbl2_s8:
10757 case SVE::BI__builtin_sve_svtbl2_u16:
10758 case SVE::BI__builtin_sve_svtbl2_s16:
10759 case SVE::BI__builtin_sve_svtbl2_u32:
10760 case SVE::BI__builtin_sve_svtbl2_s32:
10761 case SVE::BI__builtin_sve_svtbl2_u64:
10762 case SVE::BI__builtin_sve_svtbl2_s64:
10763 case SVE::BI__builtin_sve_svtbl2_f16:
10764 case SVE::BI__builtin_sve_svtbl2_bf16:
10765 case SVE::BI__builtin_sve_svtbl2_f32:
10766 case SVE::BI__builtin_sve_svtbl2_f64: {
10768 auto VTy = cast<llvm::ScalableVectorType>(
getSVEType(TF));
10770 return Builder.CreateCall(F, Ops);
10773 case SVE::BI__builtin_sve_svset_neonq_s8:
10774 case SVE::BI__builtin_sve_svset_neonq_s16:
10775 case SVE::BI__builtin_sve_svset_neonq_s32:
10776 case SVE::BI__builtin_sve_svset_neonq_s64:
10777 case SVE::BI__builtin_sve_svset_neonq_u8:
10778 case SVE::BI__builtin_sve_svset_neonq_u16:
10779 case SVE::BI__builtin_sve_svset_neonq_u32:
10780 case SVE::BI__builtin_sve_svset_neonq_u64:
10781 case SVE::BI__builtin_sve_svset_neonq_f16:
10782 case SVE::BI__builtin_sve_svset_neonq_f32:
10783 case SVE::BI__builtin_sve_svset_neonq_f64:
10784 case SVE::BI__builtin_sve_svset_neonq_bf16: {
10785 return Builder.CreateInsertVector(Ty, Ops[0], Ops[1],
Builder.getInt64(0));
10788 case SVE::BI__builtin_sve_svget_neonq_s8:
10789 case SVE::BI__builtin_sve_svget_neonq_s16:
10790 case SVE::BI__builtin_sve_svget_neonq_s32:
10791 case SVE::BI__builtin_sve_svget_neonq_s64:
10792 case SVE::BI__builtin_sve_svget_neonq_u8:
10793 case SVE::BI__builtin_sve_svget_neonq_u16:
10794 case SVE::BI__builtin_sve_svget_neonq_u32:
10795 case SVE::BI__builtin_sve_svget_neonq_u64:
10796 case SVE::BI__builtin_sve_svget_neonq_f16:
10797 case SVE::BI__builtin_sve_svget_neonq_f32:
10798 case SVE::BI__builtin_sve_svget_neonq_f64:
10799 case SVE::BI__builtin_sve_svget_neonq_bf16: {
10800 return Builder.CreateExtractVector(Ty, Ops[0],
Builder.getInt64(0));
10803 case SVE::BI__builtin_sve_svdup_neonq_s8:
10804 case SVE::BI__builtin_sve_svdup_neonq_s16:
10805 case SVE::BI__builtin_sve_svdup_neonq_s32:
10806 case SVE::BI__builtin_sve_svdup_neonq_s64:
10807 case SVE::BI__builtin_sve_svdup_neonq_u8:
10808 case SVE::BI__builtin_sve_svdup_neonq_u16:
10809 case SVE::BI__builtin_sve_svdup_neonq_u32:
10810 case SVE::BI__builtin_sve_svdup_neonq_u64:
10811 case SVE::BI__builtin_sve_svdup_neonq_f16:
10812 case SVE::BI__builtin_sve_svdup_neonq_f32:
10813 case SVE::BI__builtin_sve_svdup_neonq_f64:
10814 case SVE::BI__builtin_sve_svdup_neonq_bf16: {
10817 return Builder.CreateIntrinsic(Intrinsic::aarch64_sve_dupq_lane, {Ty},
10829 switch (BuiltinID) {
10832 case SME::BI__builtin_sme_svsumla_za32_s8_vg4x1:
10835 case SME::BI__builtin_sme_svsumla_za32_s8_vg4x2:
10836 case SME::BI__builtin_sme_svsudot_za32_s8_vg1x2:
10839 case SME::BI__builtin_sme_svsudot_za32_s8_vg1x4:
10840 case SME::BI__builtin_sme_svsumla_za32_s8_vg4x4:
10846 for (
unsigned I = 0; I < MultiVec; ++I)
10847 std::swap(Ops[I + 1], Ops[I + 1 + MultiVec]);
10860 return EmitSMELd1St1(TypeFlags, Ops, Builtin->LLVMIntrinsic);
10863 else if (BuiltinID == SME::BI__builtin_sme_svzero_mask_za ||
10864 BuiltinID == SME::BI__builtin_sme_svzero_za)
10865 return EmitSMEZero(TypeFlags, Ops, Builtin->LLVMIntrinsic);
10866 else if (BuiltinID == SME::BI__builtin_sme_svldr_vnum_za ||
10867 BuiltinID == SME::BI__builtin_sme_svstr_vnum_za ||
10868 BuiltinID == SME::BI__builtin_sme_svldr_za ||
10869 BuiltinID == SME::BI__builtin_sme_svstr_za)
10870 return EmitSMELdrStr(TypeFlags, Ops, Builtin->LLVMIntrinsic);
10876 if (Builtin->LLVMIntrinsic == 0)
10880 for (
unsigned i = 0, e = Ops.size(); i != e; ++i)
10881 if (
auto PredTy = dyn_cast<llvm::VectorType>(Ops[i]->getType()))
10882 if (PredTy->getElementType()->isIntegerTy(1))
10896 llvm::Triple::ArchType Arch) {
10905 if (BuiltinID == Builtin::BI__builtin_cpu_supports)
10906 return EmitAArch64CpuSupports(
E);
10908 unsigned HintID =
static_cast<unsigned>(-1);
10909 switch (BuiltinID) {
10911 case clang::AArch64::BI__builtin_arm_nop:
10914 case clang::AArch64::BI__builtin_arm_yield:
10915 case clang::AArch64::BI__yield:
10918 case clang::AArch64::BI__builtin_arm_wfe:
10919 case clang::AArch64::BI__wfe:
10922 case clang::AArch64::BI__builtin_arm_wfi:
10923 case clang::AArch64::BI__wfi:
10926 case clang::AArch64::BI__builtin_arm_sev:
10927 case clang::AArch64::BI__sev:
10930 case clang::AArch64::BI__builtin_arm_sevl:
10931 case clang::AArch64::BI__sevl:
10936 if (HintID !=
static_cast<unsigned>(-1)) {
10938 return Builder.CreateCall(F, llvm::ConstantInt::get(
Int32Ty, HintID));
10941 if (BuiltinID == clang::AArch64::BI__builtin_arm_trap) {
10947 if (BuiltinID == clang::AArch64::BI__builtin_arm_get_sme_state) {
10952 "__arm_sme_state"));
10954 "aarch64_pstate_sm_compatible");
10955 CI->setAttributes(Attrs);
10956 CI->setCallingConv(
10957 llvm::CallingConv::
10958 AArch64_SME_ABI_Support_Routines_PreserveMost_From_X2);
10965 if (BuiltinID == clang::AArch64::BI__builtin_arm_rbit) {
10967 "rbit of unusual size!");
10970 CGM.
getIntrinsic(Intrinsic::bitreverse, Arg->getType()), Arg,
"rbit");
10972 if (BuiltinID == clang::AArch64::BI__builtin_arm_rbit64) {
10974 "rbit of unusual size!");
10977 CGM.
getIntrinsic(Intrinsic::bitreverse, Arg->getType()), Arg,
"rbit");
10980 if (BuiltinID == clang::AArch64::BI__builtin_arm_clz ||
10981 BuiltinID == clang::AArch64::BI__builtin_arm_clz64) {
10985 if (BuiltinID == clang::AArch64::BI__builtin_arm_clz64)
10990 if (BuiltinID == clang::AArch64::BI__builtin_arm_cls) {
10995 if (BuiltinID == clang::AArch64::BI__builtin_arm_cls64) {
11001 if (BuiltinID == clang::AArch64::BI__builtin_arm_rint32zf ||
11002 BuiltinID == clang::AArch64::BI__builtin_arm_rint32z) {
11004 llvm::Type *Ty = Arg->getType();
11009 if (BuiltinID == clang::AArch64::BI__builtin_arm_rint64zf ||
11010 BuiltinID == clang::AArch64::BI__builtin_arm_rint64z) {
11012 llvm::Type *Ty = Arg->getType();
11017 if (BuiltinID == clang::AArch64::BI__builtin_arm_rint32xf ||
11018 BuiltinID == clang::AArch64::BI__builtin_arm_rint32x) {
11020 llvm::Type *Ty = Arg->getType();
11025 if (BuiltinID == clang::AArch64::BI__builtin_arm_rint64xf ||
11026 BuiltinID == clang::AArch64::BI__builtin_arm_rint64x) {
11028 llvm::Type *Ty = Arg->getType();
11033 if (BuiltinID == clang::AArch64::BI__builtin_arm_jcvt) {
11035 "__jcvt of unusual size!");
11041 if (BuiltinID == clang::AArch64::BI__builtin_arm_ld64b ||
11042 BuiltinID == clang::AArch64::BI__builtin_arm_st64b ||
11043 BuiltinID == clang::AArch64::BI__builtin_arm_st64bv ||
11044 BuiltinID == clang::AArch64::BI__builtin_arm_st64bv0) {
11048 if (BuiltinID == clang::AArch64::BI__builtin_arm_ld64b) {
11052 llvm::Value *Val =
Builder.CreateCall(F, MemAddr);
11053 llvm::Value *ToRet;
11054 for (
size_t i = 0; i < 8; i++) {
11055 llvm::Value *ValOffsetPtr =
11066 Args.push_back(MemAddr);
11067 for (
size_t i = 0; i < 8; i++) {
11068 llvm::Value *ValOffsetPtr =
11075 auto Intr = (BuiltinID == clang::AArch64::BI__builtin_arm_st64b
11076 ? Intrinsic::aarch64_st64b
11077 : BuiltinID == clang::AArch64::BI__builtin_arm_st64bv
11078 ? Intrinsic::aarch64_st64bv
11079 : Intrinsic::aarch64_st64bv0);
11081 return Builder.CreateCall(F, Args);
11085 if (BuiltinID == clang::AArch64::BI__builtin_arm_rndr ||
11086 BuiltinID == clang::AArch64::BI__builtin_arm_rndrrs) {
11088 auto Intr = (BuiltinID == clang::AArch64::BI__builtin_arm_rndr
11089 ? Intrinsic::aarch64_rndr
11090 : Intrinsic::aarch64_rndrrs);
11092 llvm::Value *Val =
Builder.CreateCall(F);
11093 Value *RandomValue =
Builder.CreateExtractValue(Val, 0);
11102 if (BuiltinID == clang::AArch64::BI__clear_cache) {
11103 assert(
E->getNumArgs() == 2 &&
"__clear_cache takes 2 arguments");
11106 for (
unsigned i = 0; i < 2; i++)
11109 llvm::FunctionType *FTy = cast<llvm::FunctionType>(Ty);
11110 StringRef Name = FD->
getName();
11114 if ((BuiltinID == clang::AArch64::BI__builtin_arm_ldrex ||
11115 BuiltinID == clang::AArch64::BI__builtin_arm_ldaex) &&
11119 ? Intrinsic::aarch64_ldaxp
11120 : Intrinsic::aarch64_ldxp);
11127 llvm::Type *Int128Ty = llvm::IntegerType::get(
getLLVMContext(), 128);
11128 Val0 =
Builder.CreateZExt(Val0, Int128Ty);
11129 Val1 =
Builder.CreateZExt(Val1, Int128Ty);
11131 Value *ShiftCst = llvm::ConstantInt::get(Int128Ty, 64);
11132 Val =
Builder.CreateShl(Val0, ShiftCst,
"shl",
true );
11133 Val =
Builder.CreateOr(Val, Val1);
11135 }
else if (BuiltinID == clang::AArch64::BI__builtin_arm_ldrex ||
11136 BuiltinID == clang::AArch64::BI__builtin_arm_ldaex) {
11141 llvm::Type *
IntTy =
11146 ? Intrinsic::aarch64_ldaxr
11147 : Intrinsic::aarch64_ldxr,
11149 CallInst *Val =
Builder.CreateCall(F, LoadAddr,
"ldxr");
11153 if (RealResTy->isPointerTy())
11154 return Builder.CreateIntToPtr(Val, RealResTy);
11156 llvm::Type *IntResTy = llvm::IntegerType::get(
11158 return Builder.CreateBitCast(
Builder.CreateTruncOrBitCast(Val, IntResTy),
11162 if ((BuiltinID == clang::AArch64::BI__builtin_arm_strex ||
11163 BuiltinID == clang::AArch64::BI__builtin_arm_stlex) &&
11167 ? Intrinsic::aarch64_stlxp
11168 : Intrinsic::aarch64_stxp);
11180 return Builder.CreateCall(F, {Arg0, Arg1, StPtr},
"stxp");
11183 if (BuiltinID == clang::AArch64::BI__builtin_arm_strex ||
11184 BuiltinID == clang::AArch64::BI__builtin_arm_stlex) {
11189 llvm::Type *StoreTy =
11192 if (StoreVal->
getType()->isPointerTy())
11195 llvm::Type *
IntTy = llvm::IntegerType::get(
11204 ? Intrinsic::aarch64_stlxr
11205 : Intrinsic::aarch64_stxr,
11207 CallInst *CI =
Builder.CreateCall(F, {StoreVal, StoreAddr},
"stxr");
11209 1, Attribute::get(
getLLVMContext(), Attribute::ElementType, StoreTy));
11213 if (BuiltinID == clang::AArch64::BI__getReg) {
11216 llvm_unreachable(
"Sema will ensure that the parameter is constant");
11222 llvm::Metadata *Ops[] = {llvm::MDString::get(Context, Reg)};
11223 llvm::MDNode *RegName = llvm::MDNode::get(Context, Ops);
11224 llvm::Value *Metadata = llvm::MetadataAsValue::get(Context, RegName);
11226 llvm::Function *F =
11228 return Builder.CreateCall(F, Metadata);
11231 if (BuiltinID == clang::AArch64::BI__break) {
11234 llvm_unreachable(
"Sema will ensure that the parameter is constant");
11236 llvm::Function *F =
CGM.
getIntrinsic(llvm::Intrinsic::aarch64_break);
11240 if (BuiltinID == clang::AArch64::BI__builtin_arm_clrex) {
11242 return Builder.CreateCall(F);
11245 if (BuiltinID == clang::AArch64::BI_ReadWriteBarrier)
11246 return Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent,
11247 llvm::SyncScope::SingleThread);
11250 Intrinsic::ID CRCIntrinsicID = Intrinsic::not_intrinsic;
11251 switch (BuiltinID) {
11252 case clang::AArch64::BI__builtin_arm_crc32b:
11253 CRCIntrinsicID = Intrinsic::aarch64_crc32b;
break;
11254 case clang::AArch64::BI__builtin_arm_crc32cb:
11255 CRCIntrinsicID = Intrinsic::aarch64_crc32cb;
break;
11256 case clang::AArch64::BI__builtin_arm_crc32h:
11257 CRCIntrinsicID = Intrinsic::aarch64_crc32h;
break;
11258 case clang::AArch64::BI__builtin_arm_crc32ch:
11259 CRCIntrinsicID = Intrinsic::aarch64_crc32ch;
break;
11260 case clang::AArch64::BI__builtin_arm_crc32w:
11261 CRCIntrinsicID = Intrinsic::aarch64_crc32w;
break;
11262 case clang::AArch64::BI__builtin_arm_crc32cw:
11263 CRCIntrinsicID = Intrinsic::aarch64_crc32cw;
break;
11264 case clang::AArch64::BI__builtin_arm_crc32d:
11265 CRCIntrinsicID = Intrinsic::aarch64_crc32x;
break;
11266 case clang::AArch64::BI__builtin_arm_crc32cd:
11267 CRCIntrinsicID = Intrinsic::aarch64_crc32cx;
break;
11270 if (CRCIntrinsicID != Intrinsic::not_intrinsic) {
11275 llvm::Type *DataTy = F->getFunctionType()->getParamType(1);
11276 Arg1 =
Builder.CreateZExtOrBitCast(Arg1, DataTy);
11278 return Builder.CreateCall(F, {Arg0, Arg1});
11282 if (BuiltinID == AArch64::BI__builtin_arm_mops_memset_tag) {
11290 CGM.
getIntrinsic(Intrinsic::aarch64_mops_memset_tag), {Dst, Val, Size});
11294 Intrinsic::ID MTEIntrinsicID = Intrinsic::not_intrinsic;
11295 switch (BuiltinID) {
11296 case clang::AArch64::BI__builtin_arm_irg:
11297 MTEIntrinsicID = Intrinsic::aarch64_irg;
break;
11298 case clang::AArch64::BI__builtin_arm_addg:
11299 MTEIntrinsicID = Intrinsic::aarch64_addg;
break;
11300 case clang::AArch64::BI__builtin_arm_gmi:
11301 MTEIntrinsicID = Intrinsic::aarch64_gmi;
break;
11302 case clang::AArch64::BI__builtin_arm_ldg:
11303 MTEIntrinsicID = Intrinsic::aarch64_ldg;
break;
11304 case clang::AArch64::BI__builtin_arm_stg:
11305 MTEIntrinsicID = Intrinsic::aarch64_stg;
break;
11306 case clang::AArch64::BI__builtin_arm_subp:
11307 MTEIntrinsicID = Intrinsic::aarch64_subp;
break;
11310 if (MTEIntrinsicID != Intrinsic::not_intrinsic) {
11313 if (MTEIntrinsicID == Intrinsic::aarch64_irg) {
11321 return Builder.CreatePointerCast(RV,
T);
11323 if (MTEIntrinsicID == Intrinsic::aarch64_addg) {
11331 return Builder.CreatePointerCast(RV,
T);
11333 if (MTEIntrinsicID == Intrinsic::aarch64_gmi) {
11345 if (MTEIntrinsicID == Intrinsic::aarch64_ldg) {
11350 return Builder.CreatePointerCast(RV,
T);
11355 if (MTEIntrinsicID == Intrinsic::aarch64_stg) {
11361 if (MTEIntrinsicID == Intrinsic::aarch64_subp) {
11371 if (BuiltinID == clang::AArch64::BI__builtin_arm_rsr ||
11372 BuiltinID == clang::AArch64::BI__builtin_arm_rsr64 ||
11373 BuiltinID == clang::AArch64::BI__builtin_arm_rsr128 ||
11374 BuiltinID == clang::AArch64::BI__builtin_arm_rsrp ||
11375 BuiltinID == clang::AArch64::BI__builtin_arm_wsr ||
11376 BuiltinID == clang::AArch64::BI__builtin_arm_wsr64 ||
11377 BuiltinID == clang::AArch64::BI__builtin_arm_wsr128 ||
11378 BuiltinID == clang::AArch64::BI__builtin_arm_wsrp) {
11381 if (BuiltinID == clang::AArch64::BI__builtin_arm_rsr ||
11382 BuiltinID == clang::AArch64::BI__builtin_arm_rsr64 ||
11383 BuiltinID == clang::AArch64::BI__builtin_arm_rsr128 ||
11384 BuiltinID == clang::AArch64::BI__builtin_arm_rsrp)
11387 bool IsPointerBuiltin = BuiltinID == clang::AArch64::BI__builtin_arm_rsrp ||
11388 BuiltinID == clang::AArch64::BI__builtin_arm_wsrp;
11390 bool Is32Bit = BuiltinID == clang::AArch64::BI__builtin_arm_rsr ||
11391 BuiltinID == clang::AArch64::BI__builtin_arm_wsr;
11393 bool Is128Bit = BuiltinID == clang::AArch64::BI__builtin_arm_rsr128 ||
11394 BuiltinID == clang::AArch64::BI__builtin_arm_wsr128;
11396 llvm::Type *ValueType;
11397 llvm::Type *RegisterType =
Int64Ty;
11400 }
else if (Is128Bit) {
11401 llvm::Type *Int128Ty =
11403 ValueType = Int128Ty;
11404 RegisterType = Int128Ty;
11405 }
else if (IsPointerBuiltin) {
11415 if (BuiltinID == clang::AArch64::BI_ReadStatusReg ||
11416 BuiltinID == clang::AArch64::BI_WriteStatusReg) {
11422 std::string SysRegStr;
11423 llvm::raw_string_ostream(SysRegStr) <<
11424 ((1 << 1) | ((SysReg >> 14) & 1)) <<
":" <<
11425 ((SysReg >> 11) & 7) <<
":" <<
11426 ((SysReg >> 7) & 15) <<
":" <<
11427 ((SysReg >> 3) & 15) <<
":" <<
11430 llvm::Metadata *Ops[] = { llvm::MDString::get(Context, SysRegStr) };
11431 llvm::MDNode *RegName = llvm::MDNode::get(Context, Ops);
11432 llvm::Value *Metadata = llvm::MetadataAsValue::get(Context, RegName);
11434 llvm::Type *RegisterType =
Int64Ty;
11435 llvm::Type *Types[] = { RegisterType };
11437 if (BuiltinID == clang::AArch64::BI_ReadStatusReg) {
11438 llvm::Function *F =
CGM.
getIntrinsic(llvm::Intrinsic::read_register, Types);
11440 return Builder.CreateCall(F, Metadata);
11443 llvm::Function *F =
CGM.
getIntrinsic(llvm::Intrinsic::write_register, Types);
11446 return Builder.CreateCall(F, { Metadata, ArgValue });
11449 if (BuiltinID == clang::AArch64::BI_AddressOfReturnAddress) {
11450 llvm::Function *F =
11452 return Builder.CreateCall(F);
11455 if (BuiltinID == clang::AArch64::BI__builtin_sponentry) {
11457 return Builder.CreateCall(F);
11460 if (BuiltinID == clang::AArch64::BI__mulh ||
11461 BuiltinID == clang::AArch64::BI__umulh) {
11463 llvm::Type *Int128Ty = llvm::IntegerType::get(
getLLVMContext(), 128);
11465 bool IsSigned = BuiltinID == clang::AArch64::BI__mulh;
11471 Value *MulResult, *HigherBits;
11473 MulResult =
Builder.CreateNSWMul(LHS, RHS);
11474 HigherBits =
Builder.CreateAShr(MulResult, 64);
11476 MulResult =
Builder.CreateNUWMul(LHS, RHS);
11477 HigherBits =
Builder.CreateLShr(MulResult, 64);
11479 HigherBits =
Builder.CreateIntCast(HigherBits, ResType, IsSigned);
11484 if (BuiltinID == AArch64::BI__writex18byte ||
11485 BuiltinID == AArch64::BI__writex18word ||
11486 BuiltinID == AArch64::BI__writex18dword ||
11487 BuiltinID == AArch64::BI__writex18qword) {
11490 llvm::Metadata *Ops[] = {llvm::MDString::get(Context,
"x18")};
11491 llvm::MDNode *RegName = llvm::MDNode::get(Context, Ops);
11492 llvm::Value *Metadata = llvm::MetadataAsValue::get(Context, RegName);
11493 llvm::Function *F =
11495 llvm::Value *X18 =
Builder.CreateCall(F, Metadata);
11506 if (BuiltinID == AArch64::BI__readx18byte ||
11507 BuiltinID == AArch64::BI__readx18word ||
11508 BuiltinID == AArch64::BI__readx18dword ||
11509 BuiltinID == AArch64::BI__readx18qword) {
11514 llvm::Metadata *Ops[] = {llvm::MDString::get(Context,
"x18")};
11515 llvm::MDNode *RegName = llvm::MDNode::get(Context, Ops);
11516 llvm::Value *Metadata = llvm::MetadataAsValue::get(Context, RegName);
11517 llvm::Function *F =
11519 llvm::Value *X18 =
Builder.CreateCall(F, Metadata);
11529 if (BuiltinID == AArch64::BI_CopyDoubleFromInt64 ||
11530 BuiltinID == AArch64::BI_CopyFloatFromInt32 ||
11531 BuiltinID == AArch64::BI_CopyInt32FromFloat ||
11532 BuiltinID == AArch64::BI_CopyInt64FromDouble) {
11535 return Builder.CreateBitCast(Arg, RetTy);
11538 if (BuiltinID == AArch64::BI_CountLeadingOnes ||
11539 BuiltinID == AArch64::BI_CountLeadingOnes64 ||
11540 BuiltinID == AArch64::BI_CountLeadingZeros ||
11541 BuiltinID == AArch64::BI_CountLeadingZeros64) {
11543 llvm::Type *ArgType = Arg->
getType();
11545 if (BuiltinID == AArch64::BI_CountLeadingOnes ||
11546 BuiltinID == AArch64::BI_CountLeadingOnes64)
11547 Arg =
Builder.CreateXor(Arg, Constant::getAllOnesValue(ArgType));
11552 if (BuiltinID == AArch64::BI_CountLeadingOnes64 ||
11553 BuiltinID == AArch64::BI_CountLeadingZeros64)
11558 if (BuiltinID == AArch64::BI_CountLeadingSigns ||
11559 BuiltinID == AArch64::BI_CountLeadingSigns64) {
11562 Function *F = (BuiltinID == AArch64::BI_CountLeadingSigns)
11567 if (BuiltinID == AArch64::BI_CountLeadingSigns64)
11572 if (BuiltinID == AArch64::BI_CountOneBits ||
11573 BuiltinID == AArch64::BI_CountOneBits64) {
11575 llvm::Type *ArgType = ArgValue->
getType();
11579 if (BuiltinID == AArch64::BI_CountOneBits64)
11584 if (BuiltinID == AArch64::BI__prefetch) {
11593 if (BuiltinID == AArch64::BI__hlt) {
11599 return ConstantInt::get(
Builder.getInt32Ty(), 0);
11604 if (std::optional<MSVCIntrin> MsvcIntId =
11610 return P.first == BuiltinID;
11613 BuiltinID = It->second;
11617 unsigned ICEArguments = 0;
11624 for (
unsigned i = 0, e =
E->getNumArgs() - 1; i != e; i++) {
11626 switch (BuiltinID) {
11627 case NEON::BI__builtin_neon_vld1_v:
11628 case NEON::BI__builtin_neon_vld1q_v:
11629 case NEON::BI__builtin_neon_vld1_dup_v:
11630 case NEON::BI__builtin_neon_vld1q_dup_v:
11631 case NEON::BI__builtin_neon_vld1_lane_v:
11632 case NEON::BI__builtin_neon_vld1q_lane_v:
11633 case NEON::BI__builtin_neon_vst1_v:
11634 case NEON::BI__builtin_neon_vst1q_v:
11635 case NEON::BI__builtin_neon_vst1_lane_v:
11636 case NEON::BI__builtin_neon_vst1q_lane_v:
11637 case NEON::BI__builtin_neon_vldap1_lane_s64:
11638 case NEON::BI__builtin_neon_vldap1q_lane_s64:
11639 case NEON::BI__builtin_neon_vstl1_lane_s64:
11640 case NEON::BI__builtin_neon_vstl1q_lane_s64:
11658 assert(
Result &&
"SISD intrinsic should have been handled");
11662 const Expr *Arg =
E->getArg(
E->getNumArgs()-1);
11664 if (std::optional<llvm::APSInt>
Result =
11669 bool usgn =
Type.isUnsigned();
11670 bool quad =
Type.isQuad();
11673 switch (BuiltinID) {
11675 case NEON::BI__builtin_neon_vabsh_f16:
11678 case NEON::BI__builtin_neon_vaddq_p128: {
11681 Ops[0] =
Builder.CreateBitCast(Ops[0], Ty);
11682 Ops[1] =
Builder.CreateBitCast(Ops[1], Ty);
11683 Ops[0] =
Builder.CreateXor(Ops[0], Ops[1]);
11684 llvm::Type *Int128Ty = llvm::Type::getIntNTy(
getLLVMContext(), 128);
11685 return Builder.CreateBitCast(Ops[0], Int128Ty);
11687 case NEON::BI__builtin_neon_vldrq_p128: {
11688 llvm::Type *Int128Ty = llvm::Type::getIntNTy(
getLLVMContext(), 128);
11693 case NEON::BI__builtin_neon_vstrq_p128: {
11694 Value *Ptr = Ops[0];
11697 case NEON::BI__builtin_neon_vcvts_f32_u32:
11698 case NEON::BI__builtin_neon_vcvtd_f64_u64:
11701 case NEON::BI__builtin_neon_vcvts_f32_s32:
11702 case NEON::BI__builtin_neon_vcvtd_f64_s64: {
11704 bool Is64 = Ops[0]->getType()->getPrimitiveSizeInBits() == 64;
11707 Ops[0] =
Builder.CreateBitCast(Ops[0], InTy);
11709 return Builder.CreateUIToFP(Ops[0], FTy);
11710 return Builder.CreateSIToFP(Ops[0], FTy);
11712 case NEON::BI__builtin_neon_vcvth_f16_u16:
11713 case NEON::BI__builtin_neon_vcvth_f16_u32:
11714 case NEON::BI__builtin_neon_vcvth_f16_u64:
11717 case NEON::BI__builtin_neon_vcvth_f16_s16:
11718 case NEON::BI__builtin_neon_vcvth_f16_s32:
11719 case NEON::BI__builtin_neon_vcvth_f16_s64: {
11721 llvm::Type *FTy =
HalfTy;
11723 if (Ops[0]->getType()->getPrimitiveSizeInBits() == 64)
11725 else if (Ops[0]->getType()->getPrimitiveSizeInBits() == 32)
11729 Ops[0] =
Builder.CreateBitCast(Ops[0], InTy);
11731 return Builder.CreateUIToFP(Ops[0], FTy);
11732 return Builder.CreateSIToFP(Ops[0], FTy);
11734 case NEON::BI__builtin_neon_vcvtah_u16_f16:
11735 case NEON::BI__builtin_neon_vcvtmh_u16_f16:
11736 case NEON::BI__builtin_neon_vcvtnh_u16_f16:
11737 case NEON::BI__builtin_neon_vcvtph_u16_f16:
11738 case NEON::BI__builtin_neon_vcvth_u16_f16:
11739 case NEON::BI__builtin_neon_vcvtah_s16_f16:
11740 case NEON::BI__builtin_neon_vcvtmh_s16_f16:
11741 case NEON::BI__builtin_neon_vcvtnh_s16_f16:
11742 case NEON::BI__builtin_neon_vcvtph_s16_f16:
11743 case NEON::BI__builtin_neon_vcvth_s16_f16: {
11746 llvm::Type* FTy =
HalfTy;
11747 llvm::Type *Tys[2] = {InTy, FTy};
11749 switch (BuiltinID) {
11750 default: llvm_unreachable(
"missing builtin ID in switch!");
11751 case NEON::BI__builtin_neon_vcvtah_u16_f16:
11752 Int = Intrinsic::aarch64_neon_fcvtau;
break;
11753 case NEON::BI__builtin_neon_vcvtmh_u16_f16:
11754 Int = Intrinsic::aarch64_neon_fcvtmu;
break;
11755 case NEON::BI__builtin_neon_vcvtnh_u16_f16:
11756 Int = Intrinsic::aarch64_neon_fcvtnu;
break;
11757 case NEON::BI__builtin_neon_vcvtph_u16_f16:
11758 Int = Intrinsic::aarch64_neon_fcvtpu;
break;
11759 case NEON::BI__builtin_neon_vcvth_u16_f16:
11760 Int = Intrinsic::aarch64_neon_fcvtzu;
break;
11761 case NEON::BI__builtin_neon_vcvtah_s16_f16:
11762 Int = Intrinsic::aarch64_neon_fcvtas;
break;
11763 case NEON::BI__builtin_neon_vcvtmh_s16_f16:
11764 Int = Intrinsic::aarch64_neon_fcvtms;
break;
11765 case NEON::BI__builtin_neon_vcvtnh_s16_f16:
11766 Int = Intrinsic::aarch64_neon_fcvtns;
break;
11767 case NEON::BI__builtin_neon_vcvtph_s16_f16:
11768 Int = Intrinsic::aarch64_neon_fcvtps;
break;
11769 case NEON::BI__builtin_neon_vcvth_s16_f16:
11770 Int = Intrinsic::aarch64_neon_fcvtzs;
break;
11775 case NEON::BI__builtin_neon_vcaleh_f16:
11776 case NEON::BI__builtin_neon_vcalth_f16:
11777 case NEON::BI__builtin_neon_vcageh_f16:
11778 case NEON::BI__builtin_neon_vcagth_f16: {
11781 llvm::Type* FTy =
HalfTy;
11782 llvm::Type *Tys[2] = {InTy, FTy};
11784 switch (BuiltinID) {
11785 default: llvm_unreachable(
"missing builtin ID in switch!");
11786 case NEON::BI__builtin_neon_vcageh_f16:
11787 Int = Intrinsic::aarch64_neon_facge;
break;
11788 case NEON::BI__builtin_neon_vcagth_f16:
11789 Int = Intrinsic::aarch64_neon_facgt;
break;
11790 case NEON::BI__builtin_neon_vcaleh_f16:
11791 Int = Intrinsic::aarch64_neon_facge; std::swap(Ops[0], Ops[1]);
break;
11792 case NEON::BI__builtin_neon_vcalth_f16:
11793 Int = Intrinsic::aarch64_neon_facgt; std::swap(Ops[0], Ops[1]);
break;
11798 case NEON::BI__builtin_neon_vcvth_n_s16_f16:
11799 case NEON::BI__builtin_neon_vcvth_n_u16_f16: {
11802 llvm::Type* FTy =
HalfTy;
11803 llvm::Type *Tys[2] = {InTy, FTy};
11805 switch (BuiltinID) {
11806 default: llvm_unreachable(
"missing builtin ID in switch!");
11807 case NEON::BI__builtin_neon_vcvth_n_s16_f16:
11808 Int = Intrinsic::aarch64_neon_vcvtfp2fxs;
break;
11809 case NEON::BI__builtin_neon_vcvth_n_u16_f16:
11810 Int = Intrinsic::aarch64_neon_vcvtfp2fxu;
break;
11815 case NEON::BI__builtin_neon_vcvth_n_f16_s16:
11816 case NEON::BI__builtin_neon_vcvth_n_f16_u16: {
11818 llvm::Type* FTy =
HalfTy;
11820 llvm::Type *Tys[2] = {FTy, InTy};
11822 switch (BuiltinID) {
11823 default: llvm_unreachable(
"missing builtin ID in switch!");
11824 case NEON::BI__builtin_neon_vcvth_n_f16_s16:
11825 Int = Intrinsic::aarch64_neon_vcvtfxs2fp;
11826 Ops[0] =
Builder.CreateSExt(Ops[0], InTy,
"sext");
11828 case NEON::BI__builtin_neon_vcvth_n_f16_u16:
11829 Int = Intrinsic::aarch64_neon_vcvtfxu2fp;
11830 Ops[0] =
Builder.CreateZExt(Ops[0], InTy);
11835 case NEON::BI__builtin_neon_vpaddd_s64: {
11836 auto *Ty = llvm::FixedVectorType::get(
Int64Ty, 2);
11839 Vec =
Builder.CreateBitCast(Vec, Ty,
"v2i64");
11840 llvm::Value *Idx0 = llvm::ConstantInt::get(
SizeTy, 0);
11841 llvm::Value *Idx1 = llvm::ConstantInt::get(
SizeTy, 1);
11842 Value *Op0 =
Builder.CreateExtractElement(Vec, Idx0,
"lane0");
11843 Value *Op1 =
Builder.CreateExtractElement(Vec, Idx1,
"lane1");
11845 return Builder.CreateAdd(Op0, Op1,
"vpaddd");
11847 case NEON::BI__builtin_neon_vpaddd_f64: {
11848 auto *Ty = llvm::FixedVectorType::get(
DoubleTy, 2);
11851 Vec =
Builder.CreateBitCast(Vec, Ty,
"v2f64");
11852 llvm::Value *Idx0 = llvm::ConstantInt::get(
SizeTy, 0);
11853 llvm::Value *Idx1 = llvm::ConstantInt::get(
SizeTy, 1);
11854 Value *Op0 =
Builder.CreateExtractElement(Vec, Idx0,
"lane0");
11855 Value *Op1 =
Builder.CreateExtractElement(Vec, Idx1,
"lane1");
11857 return Builder.CreateFAdd(Op0, Op1,
"vpaddd");
11859 case NEON::BI__builtin_neon_vpadds_f32: {
11860 auto *Ty = llvm::FixedVectorType::get(
FloatTy, 2);
11863 Vec =
Builder.CreateBitCast(Vec, Ty,
"v2f32");
11864 llvm::Value *Idx0 = llvm::ConstantInt::get(
SizeTy, 0);
11865 llvm::Value *Idx1 = llvm::ConstantInt::get(
SizeTy, 1);
11866 Value *Op0 =
Builder.CreateExtractElement(Vec, Idx0,
"lane0");
11867 Value *Op1 =
Builder.CreateExtractElement(Vec, Idx1,
"lane1");
11869 return Builder.CreateFAdd(Op0, Op1,
"vpaddd");
11871 case NEON::BI__builtin_neon_vceqzd_s64:
11872 case NEON::BI__builtin_neon_vceqzd_f64:
11873 case NEON::BI__builtin_neon_vceqzs_f32:
11874 case NEON::BI__builtin_neon_vceqzh_f16:
11878 ICmpInst::FCMP_OEQ, ICmpInst::ICMP_EQ,
"vceqz");
11879 case NEON::BI__builtin_neon_vcgezd_s64:
11880 case NEON::BI__builtin_neon_vcgezd_f64:
11881 case NEON::BI__builtin_neon_vcgezs_f32:
11882 case NEON::BI__builtin_neon_vcgezh_f16:
11886 ICmpInst::FCMP_OGE, ICmpInst::ICMP_SGE,
"vcgez");
11887 case NEON::BI__builtin_neon_vclezd_s64:
11888 case NEON::BI__builtin_neon_vclezd_f64:
11889 case NEON::BI__builtin_neon_vclezs_f32:
11890 case NEON::BI__builtin_neon_vclezh_f16:
11894 ICmpInst::FCMP_OLE, ICmpInst::ICMP_SLE,
"vclez");
11895 case NEON::BI__builtin_neon_vcgtzd_s64:
11896 case NEON::BI__builtin_neon_vcgtzd_f64:
11897 case NEON::BI__builtin_neon_vcgtzs_f32:
11898 case NEON::BI__builtin_neon_vcgtzh_f16:
11902 ICmpInst::FCMP_OGT, ICmpInst::ICMP_SGT,
"vcgtz");
11903 case NEON::BI__builtin_neon_vcltzd_s64:
11904 case NEON::BI__builtin_neon_vcltzd_f64:
11905 case NEON::BI__builtin_neon_vcltzs_f32:
11906 case NEON::BI__builtin_neon_vcltzh_f16:
11910 ICmpInst::FCMP_OLT, ICmpInst::ICMP_SLT,
"vcltz");
11912 case NEON::BI__builtin_neon_vceqzd_u64: {
11916 Builder.CreateICmpEQ(Ops[0], llvm::Constant::getNullValue(
Int64Ty));
11919 case NEON::BI__builtin_neon_vceqd_f64:
11920 case NEON::BI__builtin_neon_vcled_f64:
11921 case NEON::BI__builtin_neon_vcltd_f64:
11922 case NEON::BI__builtin_neon_vcged_f64:
11923 case NEON::BI__builtin_neon_vcgtd_f64: {
11924 llvm::CmpInst::Predicate
P;
11925 switch (BuiltinID) {
11926 default: llvm_unreachable(
"missing builtin ID in switch!");
11927 case NEON::BI__builtin_neon_vceqd_f64:
P = llvm::FCmpInst::FCMP_OEQ;
break;
11928 case NEON::BI__builtin_neon_vcled_f64:
P = llvm::FCmpInst::FCMP_OLE;
break;
11929 case NEON::BI__builtin_neon_vcltd_f64:
P = llvm::FCmpInst::FCMP_OLT;
break;
11930 case NEON::BI__builtin_neon_vcged_f64:
P = llvm::FCmpInst::FCMP_OGE;
break;
11931 case NEON::BI__builtin_neon_vcgtd_f64:
P = llvm::FCmpInst::FCMP_OGT;
break;
11936 if (
P == llvm::FCmpInst::FCMP_OEQ)
11937 Ops[0] =
Builder.CreateFCmp(
P, Ops[0], Ops[1]);
11939 Ops[0] =
Builder.CreateFCmpS(
P, Ops[0], Ops[1]);
11942 case NEON::BI__builtin_neon_vceqs_f32:
11943 case NEON::BI__builtin_neon_vcles_f32:
11944 case NEON::BI__builtin_neon_vclts_f32:
11945 case NEON::BI__builtin_neon_vcges_f32:
11946 case NEON::BI__builtin_neon_vcgts_f32: {
11947 llvm::CmpInst::Predicate
P;
11948 switch (BuiltinID) {
11949 default: llvm_unreachable(
"missing builtin ID in switch!");
11950 case NEON::BI__builtin_neon_vceqs_f32:
P = llvm::FCmpInst::FCMP_OEQ;
break;
11951 case NEON::BI__builtin_neon_vcles_f32:
P = llvm::FCmpInst::FCMP_OLE;
break;
11952 case NEON::BI__builtin_neon_vclts_f32:
P = llvm::FCmpInst::FCMP_OLT;
break;
11953 case NEON::BI__builtin_neon_vcges_f32:
P = llvm::FCmpInst::FCMP_OGE;
break;
11954 case NEON::BI__builtin_neon_vcgts_f32:
P = llvm::FCmpInst::FCMP_OGT;
break;
11959 if (
P == llvm::FCmpInst::FCMP_OEQ)
11960 Ops[0] =
Builder.CreateFCmp(
P, Ops[0], Ops[1]);
11962 Ops[0] =
Builder.CreateFCmpS(
P, Ops[0], Ops[1]);
11965 case NEON::BI__builtin_neon_vceqh_f16:
11966 case NEON::BI__builtin_neon_vcleh_f16:
11967 case NEON::BI__builtin_neon_vclth_f16:
11968 case NEON::BI__builtin_neon_vcgeh_f16:
11969 case NEON::BI__builtin_neon_vcgth_f16: {
11970 llvm::CmpInst::Predicate
P;
11971 switch (BuiltinID) {
11972 default: llvm_unreachable(
"missing builtin ID in switch!");
11973 case NEON::BI__builtin_neon_vceqh_f16:
P = llvm::FCmpInst::FCMP_OEQ;
break;
11974 case NEON::BI__builtin_neon_vcleh_f16:
P = llvm::FCmpInst::FCMP_OLE;
break;
11975 case NEON::BI__builtin_neon_vclth_f16:
P = llvm::FCmpInst::FCMP_OLT;
break;
11976 case NEON::BI__builtin_neon_vcgeh_f16:
P = llvm::FCmpInst::FCMP_OGE;
break;
11977 case NEON::BI__builtin_neon_vcgth_f16:
P = llvm::FCmpInst::FCMP_OGT;
break;
11982 if (
P == llvm::FCmpInst::FCMP_OEQ)
11983 Ops[0] =
Builder.CreateFCmp(
P, Ops[0], Ops[1]);
11985 Ops[0] =
Builder.CreateFCmpS(
P, Ops[0], Ops[1]);
11988 case NEON::BI__builtin_neon_vceqd_s64:
11989 case NEON::BI__builtin_neon_vceqd_u64:
11990 case NEON::BI__builtin_neon_vcgtd_s64:
11991 case NEON::BI__builtin_neon_vcgtd_u64:
11992 case NEON::BI__builtin_neon_vcltd_s64:
11993 case NEON::BI__builtin_neon_vcltd_u64:
11994 case NEON::BI__builtin_neon_vcged_u64:
11995 case NEON::BI__builtin_neon_vcged_s64:
11996 case NEON::BI__builtin_neon_vcled_u64:
11997 case NEON::BI__builtin_neon_vcled_s64: {
11998 llvm::CmpInst::Predicate
P;
11999 switch (BuiltinID) {
12000 default: llvm_unreachable(
"missing builtin ID in switch!");
12001 case NEON::BI__builtin_neon_vceqd_s64:
12002 case NEON::BI__builtin_neon_vceqd_u64:
P = llvm::ICmpInst::ICMP_EQ;
break;
12003 case NEON::BI__builtin_neon_vcgtd_s64:
P = llvm::ICmpInst::ICMP_SGT;
break;
12004 case NEON::BI__builtin_neon_vcgtd_u64:
P = llvm::ICmpInst::ICMP_UGT;
break;
12005 case NEON::BI__builtin_neon_vcltd_s64:
P = llvm::ICmpInst::ICMP_SLT;
break;
12006 case NEON::BI__builtin_neon_vcltd_u64:
P = llvm::ICmpInst::ICMP_ULT;
break;
12007 case NEON::BI__builtin_neon_vcged_u64:
P = llvm::ICmpInst::ICMP_UGE;
break;
12008 case NEON::BI__builtin_neon_vcged_s64:
P = llvm::ICmpInst::ICMP_SGE;
break;
12009 case NEON::BI__builtin_neon_vcled_u64:
P = llvm::ICmpInst::ICMP_ULE;
break;
12010 case NEON::BI__builtin_neon_vcled_s64:
P = llvm::ICmpInst::ICMP_SLE;
break;
12015 Ops[0] =
Builder.CreateICmp(
P, Ops[0], Ops[1]);
12018 case NEON::BI__builtin_neon_vtstd_s64:
12019 case NEON::BI__builtin_neon_vtstd_u64: {
12023 Ops[0] =
Builder.CreateAnd(Ops[0], Ops[1]);
12024 Ops[0] =
Builder.CreateICmp(ICmpInst::ICMP_NE, Ops[0],
12025 llvm::Constant::getNullValue(
Int64Ty));
12028 case NEON::BI__builtin_neon_vset_lane_i8:
12029 case NEON::BI__builtin_neon_vset_lane_i16:
12030 case NEON::BI__builtin_neon_vset_lane_i32:
12031 case NEON::BI__builtin_neon_vset_lane_i64:
12032 case NEON::BI__builtin_neon_vset_lane_bf16:
12033 case NEON::BI__builtin_neon_vset_lane_f32:
12034 case NEON::BI__builtin_neon_vsetq_lane_i8:
12035 case NEON::BI__builtin_neon_vsetq_lane_i16:
12036 case NEON::BI__builtin_neon_vsetq_lane_i32:
12037 case NEON::BI__builtin_neon_vsetq_lane_i64:
12038 case NEON::BI__builtin_neon_vsetq_lane_bf16:
12039 case NEON::BI__builtin_neon_vsetq_lane_f32:
12041 return Builder.CreateInsertElement(Ops[1], Ops[0], Ops[2],
"vset_lane");
12042 case NEON::BI__builtin_neon_vset_lane_f64:
12045 Builder.CreateBitCast(Ops[1], llvm::FixedVectorType::get(
DoubleTy, 1));
12047 return Builder.CreateInsertElement(Ops[1], Ops[0], Ops[2],
"vset_lane");
12048 case NEON::BI__builtin_neon_vsetq_lane_f64:
12051 Builder.CreateBitCast(Ops[1], llvm::FixedVectorType::get(
DoubleTy, 2));
12053 return Builder.CreateInsertElement(Ops[1], Ops[0], Ops[2],
"vset_lane");
12055 case NEON::BI__builtin_neon_vget_lane_i8:
12056 case NEON::BI__builtin_neon_vdupb_lane_i8:
12058 Builder.CreateBitCast(Ops[0], llvm::FixedVectorType::get(
Int8Ty, 8));
12061 case NEON::BI__builtin_neon_vgetq_lane_i8:
12062 case NEON::BI__builtin_neon_vdupb_laneq_i8:
12064 Builder.CreateBitCast(Ops[0], llvm::FixedVectorType::get(
Int8Ty, 16));
12067 case NEON::BI__builtin_neon_vget_lane_i16:
12068 case NEON::BI__builtin_neon_vduph_lane_i16:
12070 Builder.CreateBitCast(Ops[0], llvm::FixedVectorType::get(
Int16Ty, 4));
12073 case NEON::BI__builtin_neon_vgetq_lane_i16:
12074 case NEON::BI__builtin_neon_vduph_laneq_i16:
12076 Builder.CreateBitCast(Ops[0], llvm::FixedVectorType::get(
Int16Ty, 8));
12079 case NEON::BI__builtin_neon_vget_lane_i32:
12080 case NEON::BI__builtin_neon_vdups_lane_i32:
12082 Builder.CreateBitCast(Ops[0], llvm::FixedVectorType::get(
Int32Ty, 2));
12085 case NEON::BI__builtin_neon_vdups_lane_f32:
12087 Builder.CreateBitCast(Ops[0], llvm::FixedVectorType::get(
FloatTy, 2));
12090 case NEON::BI__builtin_neon_vgetq_lane_i32:
12091 case NEON::BI__builtin_neon_vdups_laneq_i32:
12093 Builder.CreateBitCast(Ops[0], llvm::FixedVectorType::get(
Int32Ty, 4));
12096 case NEON::BI__builtin_neon_vget_lane_i64:
12097 case NEON::BI__builtin_neon_vdupd_lane_i64:
12099 Builder.CreateBitCast(Ops[0], llvm::FixedVectorType::get(
Int64Ty, 1));
12102 case NEON::BI__builtin_neon_vdupd_lane_f64:
12104 Builder.CreateBitCast(Ops[0], llvm::FixedVectorType::get(
DoubleTy, 1));
12107 case NEON::BI__builtin_neon_vgetq_lane_i64:
12108 case NEON::BI__builtin_neon_vdupd_laneq_i64:
12110 Builder.CreateBitCast(Ops[0], llvm::FixedVectorType::get(
Int64Ty, 2));
12113 case NEON::BI__builtin_neon_vget_lane_f32:
12115 Builder.CreateBitCast(Ops[0], llvm::FixedVectorType::get(
FloatTy, 2));
12118 case NEON::BI__builtin_neon_vget_lane_f64:
12120 Builder.CreateBitCast(Ops[0], llvm::FixedVectorType::get(
DoubleTy, 1));
12123 case NEON::BI__builtin_neon_vgetq_lane_f32:
12124 case NEON::BI__builtin_neon_vdups_laneq_f32:
12126 Builder.CreateBitCast(Ops[0], llvm::FixedVectorType::get(
FloatTy, 4));
12129 case NEON::BI__builtin_neon_vgetq_lane_f64:
12130 case NEON::BI__builtin_neon_vdupd_laneq_f64:
12132 Builder.CreateBitCast(Ops[0], llvm::FixedVectorType::get(
DoubleTy, 2));
12135 case NEON::BI__builtin_neon_vaddh_f16:
12137 return Builder.CreateFAdd(Ops[0], Ops[1],
"vaddh");
12138 case NEON::BI__builtin_neon_vsubh_f16:
12140 return Builder.CreateFSub(Ops[0], Ops[1],
"vsubh");
12141 case NEON::BI__builtin_neon_vmulh_f16:
12143 return Builder.CreateFMul(Ops[0], Ops[1],
"vmulh");
12144 case NEON::BI__builtin_neon_vdivh_f16:
12146 return Builder.CreateFDiv(Ops[0], Ops[1],
"vdivh");
12147 case NEON::BI__builtin_neon_vfmah_f16:
12150 *
this, Intrinsic::fma, Intrinsic::experimental_constrained_fma,
HalfTy,
12152 case NEON::BI__builtin_neon_vfmsh_f16: {
12157 *
this, Intrinsic::fma, Intrinsic::experimental_constrained_fma,
HalfTy,
12160 case NEON::BI__builtin_neon_vaddd_s64:
12161 case NEON::BI__builtin_neon_vaddd_u64:
12163 case NEON::BI__builtin_neon_vsubd_s64:
12164 case NEON::BI__builtin_neon_vsubd_u64:
12166 case NEON::BI__builtin_neon_vqdmlalh_s16:
12167 case NEON::BI__builtin_neon_vqdmlslh_s16: {
12171 auto *VTy = llvm::FixedVectorType::get(
Int32Ty, 4);
12173 ProductOps,
"vqdmlXl");
12174 Constant *CI = ConstantInt::get(
SizeTy, 0);
12175 Ops[1] =
Builder.CreateExtractElement(Ops[1], CI,
"lane0");
12177 unsigned AccumInt = BuiltinID == NEON::BI__builtin_neon_vqdmlalh_s16
12178 ? Intrinsic::aarch64_neon_sqadd
12179 : Intrinsic::aarch64_neon_sqsub;
12182 case NEON::BI__builtin_neon_vqshlud_n_s64: {
12188 case NEON::BI__builtin_neon_vqshld_n_u64:
12189 case NEON::BI__builtin_neon_vqshld_n_s64: {
12190 unsigned Int = BuiltinID == NEON::BI__builtin_neon_vqshld_n_u64
12191 ? Intrinsic::aarch64_neon_uqshl
12192 : Intrinsic::aarch64_neon_sqshl;
12197 case NEON::BI__builtin_neon_vrshrd_n_u64:
12198 case NEON::BI__builtin_neon_vrshrd_n_s64: {
12199 unsigned Int = BuiltinID == NEON::BI__builtin_neon_vrshrd_n_u64
12200 ? Intrinsic::aarch64_neon_urshl
12201 : Intrinsic::aarch64_neon_srshl;
12203 int SV = cast<ConstantInt>(Ops[1])->getSExtValue();
12204 Ops[1] = ConstantInt::get(
Int64Ty, -SV);
12207 case NEON::BI__builtin_neon_vrsrad_n_u64:
12208 case NEON::BI__builtin_neon_vrsrad_n_s64: {
12209 unsigned Int = BuiltinID == NEON::BI__builtin_neon_vrsrad_n_u64
12210 ? Intrinsic::aarch64_neon_urshl
12211 : Intrinsic::aarch64_neon_srshl;
12215 {Ops[1], Builder.CreateSExt(Ops[2], Int64Ty)});
12218 case NEON::BI__builtin_neon_vshld_n_s64:
12219 case NEON::BI__builtin_neon_vshld_n_u64: {
12220 llvm::ConstantInt *Amt = cast<ConstantInt>(
EmitScalarExpr(
E->getArg(1)));
12222 Ops[0], ConstantInt::get(
Int64Ty, Amt->getZExtValue()),
"shld_n");
12224 case NEON::BI__builtin_neon_vshrd_n_s64: {
12225 llvm::ConstantInt *Amt = cast<ConstantInt>(
EmitScalarExpr(
E->getArg(1)));
12227 Ops[0], ConstantInt::get(
Int64Ty, std::min(
static_cast<uint64_t>(63),
12228 Amt->getZExtValue())),
12231 case NEON::BI__builtin_neon_vshrd_n_u64: {
12232 llvm::ConstantInt *Amt = cast<ConstantInt>(
EmitScalarExpr(
E->getArg(1)));
12233 uint64_t ShiftAmt = Amt->getZExtValue();
12235 if (ShiftAmt == 64)
12236 return ConstantInt::get(
Int64Ty, 0);
12237 return Builder.CreateLShr(Ops[0], ConstantInt::get(
Int64Ty, ShiftAmt),
12240 case NEON::BI__builtin_neon_vsrad_n_s64: {
12241 llvm::ConstantInt *Amt = cast<ConstantInt>(
EmitScalarExpr(
E->getArg(2)));
12243 Ops[1], ConstantInt::get(
Int64Ty, std::min(
static_cast<uint64_t>(63),
12244 Amt->getZExtValue())),
12246 return Builder.CreateAdd(Ops[0], Ops[1]);
12248 case NEON::BI__builtin_neon_vsrad_n_u64: {
12249 llvm::ConstantInt *Amt = cast<ConstantInt>(
EmitScalarExpr(
E->getArg(2)));
12250 uint64_t ShiftAmt = Amt->getZExtValue();
12253 if (ShiftAmt == 64)
12255 Ops[1] =
Builder.CreateLShr(Ops[1], ConstantInt::get(
Int64Ty, ShiftAmt),
12257 return Builder.CreateAdd(Ops[0], Ops[1]);
12259 case NEON::BI__builtin_neon_vqdmlalh_lane_s16:
12260 case NEON::BI__builtin_neon_vqdmlalh_laneq_s16:
12261 case NEON::BI__builtin_neon_vqdmlslh_lane_s16:
12262 case NEON::BI__builtin_neon_vqdmlslh_laneq_s16: {
12268 auto *VTy = llvm::FixedVectorType::get(
Int32Ty, 4);
12270 ProductOps,
"vqdmlXl");
12271 Constant *CI = ConstantInt::get(
SizeTy, 0);
12272 Ops[1] =
Builder.CreateExtractElement(Ops[1], CI,
"lane0");
12275 unsigned AccInt = (BuiltinID == NEON::BI__builtin_neon_vqdmlalh_lane_s16 ||
12276 BuiltinID == NEON::BI__builtin_neon_vqdmlalh_laneq_s16)
12277 ? Intrinsic::aarch64_neon_sqadd
12278 : Intrinsic::aarch64_neon_sqsub;
12281 case NEON::BI__builtin_neon_vqdmlals_s32:
12282 case NEON::BI__builtin_neon_vqdmlsls_s32: {
12284 ProductOps.push_back(Ops[1]);
12288 ProductOps,
"vqdmlXl");
12290 unsigned AccumInt = BuiltinID == NEON::BI__builtin_neon_vqdmlals_s32
12291 ? Intrinsic::aarch64_neon_sqadd
12292 : Intrinsic::aarch64_neon_sqsub;
12295 case NEON::BI__builtin_neon_vqdmlals_lane_s32:
12296 case NEON::BI__builtin_neon_vqdmlals_laneq_s32:
12297 case NEON::BI__builtin_neon_vqdmlsls_lane_s32:
12298 case NEON::BI__builtin_neon_vqdmlsls_laneq_s32: {
12302 ProductOps.push_back(Ops[1]);
12303 ProductOps.push_back(Ops[2]);
12306 ProductOps,
"vqdmlXl");
12309 unsigned AccInt = (BuiltinID == NEON::BI__builtin_neon_vqdmlals_lane_s32 ||
12310 BuiltinID == NEON::BI__builtin_neon_vqdmlals_laneq_s32)
12311 ? Intrinsic::aarch64_neon_sqadd
12312 : Intrinsic::aarch64_neon_sqsub;
12315 case NEON::BI__builtin_neon_vget_lane_bf16:
12316 case NEON::BI__builtin_neon_vduph_lane_bf16:
12317 case NEON::BI__builtin_neon_vduph_lane_f16: {
12321 case NEON::BI__builtin_neon_vgetq_lane_bf16:
12322 case NEON::BI__builtin_neon_vduph_laneq_bf16:
12323 case NEON::BI__builtin_neon_vduph_laneq_f16: {
12328 case clang::AArch64::BI_InterlockedAdd:
12329 case clang::AArch64::BI_InterlockedAdd64: {
12332 AtomicRMWInst *RMWI =
12334 llvm::AtomicOrdering::SequentiallyConsistent);
12335 return Builder.CreateAdd(RMWI, Val);
12340 llvm::Type *Ty = VTy;
12351 Builtin->BuiltinID, Builtin->LLVMIntrinsic, Builtin->AltLLVMIntrinsic,
12352 Builtin->NameHint, Builtin->TypeModifier,
E, Ops,
12359 switch (BuiltinID) {
12360 default:
return nullptr;
12361 case NEON::BI__builtin_neon_vbsl_v:
12362 case NEON::BI__builtin_neon_vbslq_v: {
12363 llvm::Type *BitTy = llvm::VectorType::getInteger(VTy);
12364 Ops[0] =
Builder.CreateBitCast(Ops[0], BitTy,
"vbsl");
12365 Ops[1] =
Builder.CreateBitCast(Ops[1], BitTy,
"vbsl");
12366 Ops[2] =
Builder.CreateBitCast(Ops[2], BitTy,
"vbsl");
12368 Ops[1] =
Builder.CreateAnd(Ops[0], Ops[1],
"vbsl");
12369 Ops[2] =
Builder.CreateAnd(
Builder.CreateNot(Ops[0]), Ops[2],
"vbsl");
12370 Ops[0] =
Builder.CreateOr(Ops[1], Ops[2],
"vbsl");
12371 return Builder.CreateBitCast(Ops[0], Ty);
12373 case NEON::BI__builtin_neon_vfma_lane_v:
12374 case NEON::BI__builtin_neon_vfmaq_lane_v: {
12377 Value *Addend = Ops[0];
12378 Value *Multiplicand = Ops[1];
12379 Value *LaneSource = Ops[2];
12380 Ops[0] = Multiplicand;
12381 Ops[1] = LaneSource;
12385 auto *SourceTy = BuiltinID == NEON::BI__builtin_neon_vfmaq_lane_v
12386 ? llvm::FixedVectorType::get(VTy->getElementType(),
12387 VTy->getNumElements() / 2)
12389 llvm::Constant *cst = cast<Constant>(Ops[3]);
12390 Value *SV = llvm::ConstantVector::getSplat(VTy->getElementCount(), cst);
12391 Ops[1] =
Builder.CreateBitCast(Ops[1], SourceTy);
12392 Ops[1] =
Builder.CreateShuffleVector(Ops[1], Ops[1], SV,
"lane");
12395 Int =
Builder.getIsFPConstrained() ? Intrinsic::experimental_constrained_fma
12399 case NEON::BI__builtin_neon_vfma_laneq_v: {
12400 auto *VTy = cast<llvm::FixedVectorType>(Ty);
12402 if (VTy && VTy->getElementType() ==
DoubleTy) {
12405 llvm::FixedVectorType *VTy =
12407 Ops[2] =
Builder.CreateBitCast(Ops[2], VTy);
12408 Ops[2] =
Builder.CreateExtractElement(Ops[2], Ops[3],
"extract");
12411 *
this, Intrinsic::fma, Intrinsic::experimental_constrained_fma,
12412 DoubleTy, {Ops[1], Ops[2], Ops[0]});
12415 Ops[0] =
Builder.CreateBitCast(Ops[0], Ty);
12416 Ops[1] =
Builder.CreateBitCast(Ops[1], Ty);
12418 auto *STy = llvm::FixedVectorType::get(VTy->getElementType(),
12419 VTy->getNumElements() * 2);
12420 Ops[2] =
Builder.CreateBitCast(Ops[2], STy);
12421 Value *SV = llvm::ConstantVector::getSplat(VTy->getElementCount(),
12422 cast<ConstantInt>(Ops[3]));
12423 Ops[2] =
Builder.CreateShuffleVector(Ops[2], Ops[2], SV,
"lane");
12426 *
this, Intrinsic::fma, Intrinsic::experimental_constrained_fma, Ty,
12427 {Ops[2], Ops[1], Ops[0]});
12429 case NEON::BI__builtin_neon_vfmaq_laneq_v: {
12430 Ops[0] =
Builder.CreateBitCast(Ops[0], Ty);
12431 Ops[1] =
Builder.CreateBitCast(Ops[1], Ty);
12433 Ops[2] =
Builder.CreateBitCast(Ops[2], Ty);
12436 *
this, Intrinsic::fma, Intrinsic::experimental_constrained_fma, Ty,
12437 {Ops[2], Ops[1], Ops[0]});
12439 case NEON::BI__builtin_neon_vfmah_lane_f16:
12440 case NEON::BI__builtin_neon_vfmas_lane_f32:
12441 case NEON::BI__builtin_neon_vfmah_laneq_f16:
12442 case NEON::BI__builtin_neon_vfmas_laneq_f32:
12443 case NEON::BI__builtin_neon_vfmad_lane_f64:
12444 case NEON::BI__builtin_neon_vfmad_laneq_f64: {
12447 Ops[2] =
Builder.CreateExtractElement(Ops[2], Ops[3],
"extract");
12449 *
this, Intrinsic::fma, Intrinsic::experimental_constrained_fma, Ty,
12450 {Ops[1], Ops[2], Ops[0]});
12452 case NEON::BI__builtin_neon_vmull_v:
12454 Int = usgn ? Intrinsic::aarch64_neon_umull : Intrinsic::aarch64_neon_smull;
12455 if (
Type.isPoly())
Int = Intrinsic::aarch64_neon_pmull;
12457 case NEON::BI__builtin_neon_vmax_v:
12458 case NEON::BI__builtin_neon_vmaxq_v:
12460 Int = usgn ? Intrinsic::aarch64_neon_umax : Intrinsic::aarch64_neon_smax;
12461 if (Ty->isFPOrFPVectorTy())
Int = Intrinsic::aarch64_neon_fmax;
12463 case NEON::BI__builtin_neon_vmaxh_f16: {
12465 Int = Intrinsic::aarch64_neon_fmax;
12468 case NEON::BI__builtin_neon_vmin_v:
12469 case NEON::BI__builtin_neon_vminq_v:
12471 Int = usgn ? Intrinsic::aarch64_neon_umin : Intrinsic::aarch64_neon_smin;
12472 if (Ty->isFPOrFPVectorTy())
Int = Intrinsic::aarch64_neon_fmin;
12474 case NEON::BI__builtin_neon_vminh_f16: {
12476 Int = Intrinsic::aarch64_neon_fmin;
12479 case NEON::BI__builtin_neon_vabd_v:
12480 case NEON::BI__builtin_neon_vabdq_v:
12482 Int = usgn ? Intrinsic::aarch64_neon_uabd : Intrinsic::aarch64_neon_sabd;
12483 if (Ty->isFPOrFPVectorTy())
Int = Intrinsic::aarch64_neon_fabd;
12485 case NEON::BI__builtin_neon_vpadal_v:
12486 case NEON::BI__builtin_neon_vpadalq_v: {
12487 unsigned ArgElts = VTy->getNumElements();
12488 llvm::IntegerType *EltTy = cast<IntegerType>(VTy->getElementType());
12489 unsigned BitWidth = EltTy->getBitWidth();
12490 auto *ArgTy = llvm::FixedVectorType::get(
12491 llvm::IntegerType::get(
getLLVMContext(), BitWidth / 2), 2 * ArgElts);
12492 llvm::Type* Tys[2] = { VTy, ArgTy };
12493 Int = usgn ? Intrinsic::aarch64_neon_uaddlp : Intrinsic::aarch64_neon_saddlp;
12495 TmpOps.push_back(Ops[1]);
12498 llvm::Value *addend =
Builder.CreateBitCast(Ops[0], tmp->getType());
12499 return Builder.CreateAdd(tmp, addend);
12501 case NEON::BI__builtin_neon_vpmin_v:
12502 case NEON::BI__builtin_neon_vpminq_v:
12504 Int = usgn ? Intrinsic::aarch64_neon_uminp : Intrinsic::aarch64_neon_sminp;
12505 if (Ty->isFPOrFPVectorTy())
Int = Intrinsic::aarch64_neon_fminp;
12507 case NEON::BI__builtin_neon_vpmax_v:
12508 case NEON::BI__builtin_neon_vpmaxq_v:
12510 Int = usgn ? Intrinsic::aarch64_neon_umaxp : Intrinsic::aarch64_neon_smaxp;
12511 if (Ty->isFPOrFPVectorTy())
Int = Intrinsic::aarch64_neon_fmaxp;
12513 case NEON::BI__builtin_neon_vminnm_v:
12514 case NEON::BI__builtin_neon_vminnmq_v:
12515 Int = Intrinsic::aarch64_neon_fminnm;
12517 case NEON::BI__builtin_neon_vminnmh_f16:
12519 Int = Intrinsic::aarch64_neon_fminnm;
12521 case NEON::BI__builtin_neon_vmaxnm_v:
12522 case NEON::BI__builtin_neon_vmaxnmq_v:
12523 Int = Intrinsic::aarch64_neon_fmaxnm;
12525 case NEON::BI__builtin_neon_vmaxnmh_f16:
12527 Int = Intrinsic::aarch64_neon_fmaxnm;
12529 case NEON::BI__builtin_neon_vrecpss_f32: {
12534 case NEON::BI__builtin_neon_vrecpsd_f64:
12538 case NEON::BI__builtin_neon_vrecpsh_f16:
12542 case NEON::BI__builtin_neon_vqshrun_n_v:
12543 Int = Intrinsic::aarch64_neon_sqshrun;
12545 case NEON::BI__builtin_neon_vqrshrun_n_v:
12546 Int = Intrinsic::aarch64_neon_sqrshrun;
12548 case NEON::BI__builtin_neon_vqshrn_n_v:
12549 Int = usgn ? Intrinsic::aarch64_neon_uqshrn : Intrinsic::aarch64_neon_sqshrn;
12551 case NEON::BI__builtin_neon_vrshrn_n_v:
12552 Int = Intrinsic::aarch64_neon_rshrn;
12554 case NEON::BI__builtin_neon_vqrshrn_n_v:
12555 Int = usgn ? Intrinsic::aarch64_neon_uqrshrn : Intrinsic::aarch64_neon_sqrshrn;
12557 case NEON::BI__builtin_neon_vrndah_f16: {
12560 ? Intrinsic::experimental_constrained_round
12561 : Intrinsic::round;
12564 case NEON::BI__builtin_neon_vrnda_v:
12565 case NEON::BI__builtin_neon_vrndaq_v: {
12567 ? Intrinsic::experimental_constrained_round
12568 : Intrinsic::round;
12571 case NEON::BI__builtin_neon_vrndih_f16: {
12574 ? Intrinsic::experimental_constrained_nearbyint
12575 : Intrinsic::nearbyint;
12578 case NEON::BI__builtin_neon_vrndmh_f16: {
12581 ? Intrinsic::experimental_constrained_floor
12582 : Intrinsic::floor;
12585 case NEON::BI__builtin_neon_vrndm_v:
12586 case NEON::BI__builtin_neon_vrndmq_v: {
12588 ? Intrinsic::experimental_constrained_floor
12589 : Intrinsic::floor;
12592 case NEON::BI__builtin_neon_vrndnh_f16: {
12595 ? Intrinsic::experimental_constrained_roundeven
12596 : Intrinsic::roundeven;
12599 case NEON::BI__builtin_neon_vrndn_v:
12600 case NEON::BI__builtin_neon_vrndnq_v: {
12602 ? Intrinsic::experimental_constrained_roundeven
12603 : Intrinsic::roundeven;
12606 case NEON::BI__builtin_neon_vrndns_f32: {
12609 ? Intrinsic::experimental_constrained_roundeven
12610 : Intrinsic::roundeven;
12613 case NEON::BI__builtin_neon_vrndph_f16: {
12616 ? Intrinsic::experimental_constrained_ceil
12620 case NEON::BI__builtin_neon_vrndp_v:
12621 case NEON::BI__builtin_neon_vrndpq_v: {
12623 ? Intrinsic::experimental_constrained_ceil
12627 case NEON::BI__builtin_neon_vrndxh_f16: {
12630 ? Intrinsic::experimental_constrained_rint
12634 case NEON::BI__builtin_neon_vrndx_v:
12635 case NEON::BI__builtin_neon_vrndxq_v: {
12637 ? Intrinsic::experimental_constrained_rint
12641 case NEON::BI__builtin_neon_vrndh_f16: {
12644 ? Intrinsic::experimental_constrained_trunc
12645 : Intrinsic::trunc;
12648 case NEON::BI__builtin_neon_vrnd32x_f32:
12649 case NEON::BI__builtin_neon_vrnd32xq_f32:
12650 case NEON::BI__builtin_neon_vrnd32x_f64:
12651 case NEON::BI__builtin_neon_vrnd32xq_f64: {
12653 Int = Intrinsic::aarch64_neon_frint32x;
12656 case NEON::BI__builtin_neon_vrnd32z_f32:
12657 case NEON::BI__builtin_neon_vrnd32zq_f32:
12658 case NEON::BI__builtin_neon_vrnd32z_f64:
12659 case NEON::BI__builtin_neon_vrnd32zq_f64: {
12661 Int = Intrinsic::aarch64_neon_frint32z;
12664 case NEON::BI__builtin_neon_vrnd64x_f32:
12665 case NEON::BI__builtin_neon_vrnd64xq_f32:
12666 case NEON::BI__builtin_neon_vrnd64x_f64:
12667 case NEON::BI__builtin_neon_vrnd64xq_f64: {
12669 Int = Intrinsic::aarch64_neon_frint64x;
12672 case NEON::BI__builtin_neon_vrnd64z_f32:
12673 case NEON::BI__builtin_neon_vrnd64zq_f32:
12674 case NEON::BI__builtin_neon_vrnd64z_f64:
12675 case NEON::BI__builtin_neon_vrnd64zq_f64: {
12677 Int = Intrinsic::aarch64_neon_frint64z;
12680 case NEON::BI__builtin_neon_vrnd_v:
12681 case NEON::BI__builtin_neon_vrndq_v: {
12683 ? Intrinsic::experimental_constrained_trunc
12684 : Intrinsic::trunc;
12687 case NEON::BI__builtin_neon_vcvt_f64_v:
12688 case NEON::BI__builtin_neon_vcvtq_f64_v:
12689 Ops[0] =
Builder.CreateBitCast(Ops[0], Ty);
12691 return usgn ?
Builder.CreateUIToFP(Ops[0], Ty,
"vcvt")
12692 :
Builder.CreateSIToFP(Ops[0], Ty,
"vcvt");
12693 case NEON::BI__builtin_neon_vcvt_f64_f32: {
12695 "unexpected vcvt_f64_f32 builtin");
12699 return Builder.CreateFPExt(Ops[0], Ty,
"vcvt");
12701 case NEON::BI__builtin_neon_vcvt_f32_f64: {
12703 "unexpected vcvt_f32_f64 builtin");
12707 return Builder.CreateFPTrunc(Ops[0], Ty,
"vcvt");
12709 case NEON::BI__builtin_neon_vcvt_s32_v:
12710 case NEON::BI__builtin_neon_vcvt_u32_v:
12711 case NEON::BI__builtin_neon_vcvt_s64_v:
12712 case NEON::BI__builtin_neon_vcvt_u64_v:
12713 case NEON::BI__builtin_neon_vcvt_s16_f16:
12714 case NEON::BI__builtin_neon_vcvt_u16_f16:
12715 case NEON::BI__builtin_neon_vcvtq_s32_v:
12716 case NEON::BI__builtin_neon_vcvtq_u32_v:
12717 case NEON::BI__builtin_neon_vcvtq_s64_v:
12718 case NEON::BI__builtin_neon_vcvtq_u64_v:
12719 case NEON::BI__builtin_neon_vcvtq_s16_f16:
12720 case NEON::BI__builtin_neon_vcvtq_u16_f16: {
12722 usgn ? Intrinsic::aarch64_neon_fcvtzu : Intrinsic::aarch64_neon_fcvtzs;
12726 case NEON::BI__builtin_neon_vcvta_s16_f16:
12727 case NEON::BI__builtin_neon_vcvta_u16_f16:
12728 case NEON::BI__builtin_neon_vcvta_s32_v:
12729 case NEON::BI__builtin_neon_vcvtaq_s16_f16:
12730 case NEON::BI__builtin_neon_vcvtaq_s32_v:
12731 case NEON::BI__builtin_neon_vcvta_u32_v:
12732 case NEON::BI__builtin_neon_vcvtaq_u16_f16:
12733 case NEON::BI__builtin_neon_vcvtaq_u32_v:
12734 case NEON::BI__builtin_neon_vcvta_s64_v:
12735 case NEON::BI__builtin_neon_vcvtaq_s64_v:
12736 case NEON::BI__builtin_neon_vcvta_u64_v:
12737 case NEON::BI__builtin_neon_vcvtaq_u64_v: {
12738 Int = usgn ? Intrinsic::aarch64_neon_fcvtau : Intrinsic::aarch64_neon_fcvtas;
12742 case NEON::BI__builtin_neon_vcvtm_s16_f16:
12743 case NEON::BI__builtin_neon_vcvtm_s32_v:
12744 case NEON::BI__builtin_neon_vcvtmq_s16_f16:
12745 case NEON::BI__builtin_neon_vcvtmq_s32_v:
12746 case NEON::BI__builtin_neon_vcvtm_u16_f16:
12747 case NEON::BI__builtin_neon_vcvtm_u32_v:
12748 case NEON::BI__builtin_neon_vcvtmq_u16_f16:
12749 case NEON::BI__builtin_neon_vcvtmq_u32_v:
12750 case NEON::BI__builtin_neon_vcvtm_s64_v:
12751 case NEON::BI__builtin_neon_vcvtmq_s64_v:
12752 case NEON::BI__builtin_neon_vcvtm_u64_v:
12753 case NEON::BI__builtin_neon_vcvtmq_u64_v: {
12754 Int = usgn ? Intrinsic::aarch64_neon_fcvtmu : Intrinsic::aarch64_neon_fcvtms;
12758 case NEON::BI__builtin_neon_vcvtn_s16_f16:
12759 case NEON::BI__builtin_neon_vcvtn_s32_v:
12760 case NEON::BI__builtin_neon_vcvtnq_s16_f16:
12761 case NEON::BI__builtin_neon_vcvtnq_s32_v:
12762 case NEON::BI__builtin_neon_vcvtn_u16_f16:
12763 case NEON::BI__builtin_neon_vcvtn_u32_v:
12764 case NEON::BI__builtin_neon_vcvtnq_u16_f16:
12765 case NEON::BI__builtin_neon_vcvtnq_u32_v:
12766 case NEON::BI__builtin_neon_vcvtn_s64_v:
12767 case NEON::BI__builtin_neon_vcvtnq_s64_v:
12768 case NEON::BI__builtin_neon_vcvtn_u64_v:
12769 case NEON::BI__builtin_neon_vcvtnq_u64_v: {
12770 Int = usgn ? Intrinsic::aarch64_neon_fcvtnu : Intrinsic::aarch64_neon_fcvtns;
12774 case NEON::BI__builtin_neon_vcvtp_s16_f16:
12775 case NEON::BI__builtin_neon_vcvtp_s32_v:
12776 case NEON::BI__builtin_neon_vcvtpq_s16_f16:
12777 case NEON::BI__builtin_neon_vcvtpq_s32_v:
12778 case NEON::BI__builtin_neon_vcvtp_u16_f16:
12779 case NEON::BI__builtin_neon_vcvtp_u32_v:
12780 case NEON::BI__builtin_neon_vcvtpq_u16_f16:
12781 case NEON::BI__builtin_neon_vcvtpq_u32_v:
12782 case NEON::BI__builtin_neon_vcvtp_s64_v:
12783 case NEON::BI__builtin_neon_vcvtpq_s64_v:
12784 case NEON::BI__builtin_neon_vcvtp_u64_v:
12785 case NEON::BI__builtin_neon_vcvtpq_u64_v: {
12786 Int = usgn ? Intrinsic::aarch64_neon_fcvtpu : Intrinsic::aarch64_neon_fcvtps;
12790 case NEON::BI__builtin_neon_vmulx_v:
12791 case NEON::BI__builtin_neon_vmulxq_v: {
12792 Int = Intrinsic::aarch64_neon_fmulx;
12795 case NEON::BI__builtin_neon_vmulxh_lane_f16:
12796 case NEON::BI__builtin_neon_vmulxh_laneq_f16: {
12800 Ops[1] =
Builder.CreateExtractElement(Ops[1], Ops[2],
"extract");
12802 Int = Intrinsic::aarch64_neon_fmulx;
12805 case NEON::BI__builtin_neon_vmul_lane_v:
12806 case NEON::BI__builtin_neon_vmul_laneq_v: {
12809 if (BuiltinID == NEON::BI__builtin_neon_vmul_laneq_v)
12812 llvm::FixedVectorType *VTy =
12814 Ops[1] =
Builder.CreateBitCast(Ops[1], VTy);
12815 Ops[1] =
Builder.CreateExtractElement(Ops[1], Ops[2],
"extract");
12819 case NEON::BI__builtin_neon_vnegd_s64:
12821 case NEON::BI__builtin_neon_vnegh_f16:
12823 case NEON::BI__builtin_neon_vpmaxnm_v:
12824 case NEON::BI__builtin_neon_vpmaxnmq_v: {
12825 Int = Intrinsic::aarch64_neon_fmaxnmp;
12828 case NEON::BI__builtin_neon_vpminnm_v:
12829 case NEON::BI__builtin_neon_vpminnmq_v: {
12830 Int = Intrinsic::aarch64_neon_fminnmp;
12833 case NEON::BI__builtin_neon_vsqrth_f16: {
12836 ? Intrinsic::experimental_constrained_sqrt
12840 case NEON::BI__builtin_neon_vsqrt_v:
12841 case NEON::BI__builtin_neon_vsqrtq_v: {
12843 ? Intrinsic::experimental_constrained_sqrt
12845 Ops[0] =
Builder.CreateBitCast(Ops[0], Ty);
12848 case NEON::BI__builtin_neon_vrbit_v:
12849 case NEON::BI__builtin_neon_vrbitq_v: {
12850 Int = Intrinsic::bitreverse;
12853 case NEON::BI__builtin_neon_vaddv_u8:
12857 case NEON::BI__builtin_neon_vaddv_s8: {
12858 Int = usgn ? Intrinsic::aarch64_neon_uaddv : Intrinsic::aarch64_neon_saddv;
12860 VTy = llvm::FixedVectorType::get(
Int8Ty, 8);
12861 llvm::Type *Tys[2] = { Ty, VTy };
12866 case NEON::BI__builtin_neon_vaddv_u16:
12869 case NEON::BI__builtin_neon_vaddv_s16: {
12870 Int = usgn ? Intrinsic::aarch64_neon_uaddv : Intrinsic::aarch64_neon_saddv;
12872 VTy = llvm::FixedVectorType::get(
Int16Ty, 4);
12873 llvm::Type *Tys[2] = { Ty, VTy };
12878 case NEON::BI__builtin_neon_vaddvq_u8:
12881 case NEON::BI__builtin_neon_vaddvq_s8: {
12882 Int = usgn ? Intrinsic::aarch64_neon_uaddv : Intrinsic::aarch64_neon_saddv;
12884 VTy = llvm::FixedVectorType::get(
Int8Ty, 16);
12885 llvm::Type *Tys[2] = { Ty, VTy };
12890 case NEON::BI__builtin_neon_vaddvq_u16:
12893 case NEON::BI__builtin_neon_vaddvq_s16: {
12894 Int = usgn ? Intrinsic::aarch64_neon_uaddv : Intrinsic::aarch64_neon_saddv;
12896 VTy = llvm::FixedVectorType::get(
Int16Ty, 8);
12897 llvm::Type *Tys[2] = { Ty, VTy };
12902 case NEON::BI__builtin_neon_vmaxv_u8: {
12903 Int = Intrinsic::aarch64_neon_umaxv;
12905 VTy = llvm::FixedVectorType::get(
Int8Ty, 8);
12906 llvm::Type *Tys[2] = { Ty, VTy };
12911 case NEON::BI__builtin_neon_vmaxv_u16: {
12912 Int = Intrinsic::aarch64_neon_umaxv;
12914 VTy = llvm::FixedVectorType::get(
Int16Ty, 4);
12915 llvm::Type *Tys[2] = { Ty, VTy };
12920 case NEON::BI__builtin_neon_vmaxvq_u8: {
12921 Int = Intrinsic::aarch64_neon_umaxv;
12923 VTy = llvm::FixedVectorType::get(
Int8Ty, 16);
12924 llvm::Type *Tys[2] = { Ty, VTy };
12929 case NEON::BI__builtin_neon_vmaxvq_u16: {
12930 Int = Intrinsic::aarch64_neon_umaxv;
12932 VTy = llvm::FixedVectorType::get(
Int16Ty, 8);
12933 llvm::Type *Tys[2] = { Ty, VTy };
12938 case NEON::BI__builtin_neon_vmaxv_s8: {
12939 Int = Intrinsic::aarch64_neon_smaxv;
12941 VTy = llvm::FixedVectorType::get(
Int8Ty, 8);
12942 llvm::Type *Tys[2] = { Ty, VTy };
12947 case NEON::BI__builtin_neon_vmaxv_s16: {
12948 Int = Intrinsic::aarch64_neon_smaxv;
12950 VTy = llvm::FixedVectorType::get(
Int16Ty, 4);
12951 llvm::Type *Tys[2] = { Ty, VTy };
12956 case NEON::BI__builtin_neon_vmaxvq_s8: {
12957 Int = Intrinsic::aarch64_neon_smaxv;
12959 VTy = llvm::FixedVectorType::get(
Int8Ty, 16);
12960 llvm::Type *Tys[2] = { Ty, VTy };
12965 case NEON::BI__builtin_neon_vmaxvq_s16: {
12966 Int = Intrinsic::aarch64_neon_smaxv;
12968 VTy = llvm::FixedVectorType::get(
Int16Ty, 8);
12969 llvm::Type *Tys[2] = { Ty, VTy };
12974 case NEON::BI__builtin_neon_vmaxv_f16: {
12975 Int = Intrinsic::aarch64_neon_fmaxv;
12977 VTy = llvm::FixedVectorType::get(
HalfTy, 4);
12978 llvm::Type *Tys[2] = { Ty, VTy };
12983 case NEON::BI__builtin_neon_vmaxvq_f16: {
12984 Int = Intrinsic::aarch64_neon_fmaxv;
12986 VTy = llvm::FixedVectorType::get(
HalfTy, 8);
12987 llvm::Type *Tys[2] = { Ty, VTy };
12992 case NEON::BI__builtin_neon_vminv_u8: {
12993 Int = Intrinsic::aarch64_neon_uminv;
12995 VTy = llvm::FixedVectorType::get(
Int8Ty, 8);
12996 llvm::Type *Tys[2] = { Ty, VTy };
13001 case NEON::BI__builtin_neon_vminv_u16: {
13002 Int = Intrinsic::aarch64_neon_uminv;
13004 VTy = llvm::FixedVectorType::get(
Int16Ty, 4);
13005 llvm::Type *Tys[2] = { Ty, VTy };
13010 case NEON::BI__builtin_neon_vminvq_u8: {
13011 Int = Intrinsic::aarch64_neon_uminv;
13013 VTy = llvm::FixedVectorType::get(
Int8Ty, 16);
13014 llvm::Type *Tys[2] = { Ty, VTy };
13019 case NEON::BI__builtin_neon_vminvq_u16: {
13020 Int = Intrinsic::aarch64_neon_uminv;
13022 VTy = llvm::FixedVectorType::get(
Int16Ty, 8);
13023 llvm::Type *Tys[2] = { Ty, VTy };
13028 case NEON::BI__builtin_neon_vminv_s8: {
13029 Int = Intrinsic::aarch64_neon_sminv;
13031 VTy = llvm::FixedVectorType::get(
Int8Ty, 8);
13032 llvm::Type *Tys[2] = { Ty, VTy };
13037 case NEON::BI__builtin_neon_vminv_s16: {
13038 Int = Intrinsic::aarch64_neon_sminv;
13040 VTy = llvm::FixedVectorType::get(
Int16Ty, 4);
13041 llvm::Type *Tys[2] = { Ty, VTy };
13046 case NEON::BI__builtin_neon_vminvq_s8: {
13047 Int = Intrinsic::aarch64_neon_sminv;
13049 VTy = llvm::FixedVectorType::get(
Int8Ty, 16);
13050 llvm::Type *Tys[2] = { Ty, VTy };
13055 case NEON::BI__builtin_neon_vminvq_s16: {
13056 Int = Intrinsic::aarch64_neon_sminv;
13058 VTy = llvm::FixedVectorType::get(
Int16Ty, 8);
13059 llvm::Type *Tys[2] = { Ty, VTy };
13064 case NEON::BI__builtin_neon_vminv_f16: {
13065 Int = Intrinsic::aarch64_neon_fminv;
13067 VTy = llvm::FixedVectorType::get(
HalfTy, 4);
13068 llvm::Type *Tys[2] = { Ty, VTy };
13073 case NEON::BI__builtin_neon_vminvq_f16: {
13074 Int = Intrinsic::aarch64_neon_fminv;
13076 VTy = llvm::FixedVectorType::get(
HalfTy, 8);
13077 llvm::Type *Tys[2] = { Ty, VTy };
13082 case NEON::BI__builtin_neon_vmaxnmv_f16: {
13083 Int = Intrinsic::aarch64_neon_fmaxnmv;
13085 VTy = llvm::FixedVectorType::get(
HalfTy, 4);
13086 llvm::Type *Tys[2] = { Ty, VTy };
13091 case NEON::BI__builtin_neon_vmaxnmvq_f16: {
13092 Int = Intrinsic::aarch64_neon_fmaxnmv;
13094 VTy = llvm::FixedVectorType::get(
HalfTy, 8);
13095 llvm::Type *Tys[2] = { Ty, VTy };
13100 case NEON::BI__builtin_neon_vminnmv_f16: {
13101 Int = Intrinsic::aarch64_neon_fminnmv;
13103 VTy = llvm::FixedVectorType::get(
HalfTy, 4);
13104 llvm::Type *Tys[2] = { Ty, VTy };
13109 case NEON::BI__builtin_neon_vminnmvq_f16: {
13110 Int = Intrinsic::aarch64_neon_fminnmv;
13112 VTy = llvm::FixedVectorType::get(
HalfTy, 8);
13113 llvm::Type *Tys[2] = { Ty, VTy };
13118 case NEON::BI__builtin_neon_vmul_n_f64: {
13121 return Builder.CreateFMul(Ops[0], RHS);
13123 case NEON::BI__builtin_neon_vaddlv_u8: {
13124 Int = Intrinsic::aarch64_neon_uaddlv;
13126 VTy = llvm::FixedVectorType::get(
Int8Ty, 8);
13127 llvm::Type *Tys[2] = { Ty, VTy };
13132 case NEON::BI__builtin_neon_vaddlv_u16: {
13133 Int = Intrinsic::aarch64_neon_uaddlv;
13135 VTy = llvm::FixedVectorType::get(
Int16Ty, 4);
13136 llvm::Type *Tys[2] = { Ty, VTy };
13140 case NEON::BI__builtin_neon_vaddlvq_u8: {
13141 Int = Intrinsic::aarch64_neon_uaddlv;
13143 VTy = llvm::FixedVectorType::get(
Int8Ty, 16);
13144 llvm::Type *Tys[2] = { Ty, VTy };
13149 case NEON::BI__builtin_neon_vaddlvq_u16: {
13150 Int = Intrinsic::aarch64_neon_uaddlv;
13152 VTy = llvm::FixedVectorType::get(
Int16Ty, 8);
13153 llvm::Type *Tys[2] = { Ty, VTy };
13157 case NEON::BI__builtin_neon_vaddlv_s8: {
13158 Int = Intrinsic::aarch64_neon_saddlv;
13160 VTy = llvm::FixedVectorType::get(
Int8Ty, 8);
13161 llvm::Type *Tys[2] = { Ty, VTy };
13166 case NEON::BI__builtin_neon_vaddlv_s16: {
13167 Int = Intrinsic::aarch64_neon_saddlv;
13169 VTy = llvm::FixedVectorType::get(
Int16Ty, 4);
13170 llvm::Type *Tys[2] = { Ty, VTy };
13174 case NEON::BI__builtin_neon_vaddlvq_s8: {
13175 Int = Intrinsic::aarch64_neon_saddlv;
13177 VTy = llvm::FixedVectorType::get(
Int8Ty, 16);
13178 llvm::Type *Tys[2] = { Ty, VTy };
13183 case NEON::BI__builtin_neon_vaddlvq_s16: {
13184 Int = Intrinsic::aarch64_neon_saddlv;
13186 VTy = llvm::FixedVectorType::get(
Int16Ty, 8);
13187 llvm::Type *Tys[2] = { Ty, VTy };
13191 case NEON::BI__builtin_neon_vsri_n_v:
13192 case NEON::BI__builtin_neon_vsriq_n_v: {
13193 Int = Intrinsic::aarch64_neon_vsri;
13197 case NEON::BI__builtin_neon_vsli_n_v:
13198 case NEON::BI__builtin_neon_vsliq_n_v: {
13199 Int = Intrinsic::aarch64_neon_vsli;
13203 case NEON::BI__builtin_neon_vsra_n_v:
13204 case NEON::BI__builtin_neon_vsraq_n_v:
13205 Ops[0] =
Builder.CreateBitCast(Ops[0], Ty);
13207 return Builder.CreateAdd(Ops[0], Ops[1]);
13208 case NEON::BI__builtin_neon_vrsra_n_v:
13209 case NEON::BI__builtin_neon_vrsraq_n_v: {
13210 Int = usgn ? Intrinsic::aarch64_neon_urshl : Intrinsic::aarch64_neon_srshl;
13212 TmpOps.push_back(Ops[1]);
13213 TmpOps.push_back(Ops[2]);
13215 llvm::Value *tmp =
EmitNeonCall(F, TmpOps,
"vrshr_n", 1,
true);
13216 Ops[0] =
Builder.CreateBitCast(Ops[0], VTy);
13217 return Builder.CreateAdd(Ops[0], tmp);
13219 case NEON::BI__builtin_neon_vld1_v:
13220 case NEON::BI__builtin_neon_vld1q_v: {
13223 case NEON::BI__builtin_neon_vst1_v:
13224 case NEON::BI__builtin_neon_vst1q_v:
13225 Ops[1] =
Builder.CreateBitCast(Ops[1], VTy);
13227 case NEON::BI__builtin_neon_vld1_lane_v:
13228 case NEON::BI__builtin_neon_vld1q_lane_v: {
13229 Ops[1] =
Builder.CreateBitCast(Ops[1], Ty);
13232 return Builder.CreateInsertElement(Ops[1], Ops[0], Ops[2],
"vld1_lane");
13234 case NEON::BI__builtin_neon_vldap1_lane_s64:
13235 case NEON::BI__builtin_neon_vldap1q_lane_s64: {
13236 Ops[1] =
Builder.CreateBitCast(Ops[1], Ty);
13238 VTy->getElementType(), Ops[0], PtrOp0.
getAlignment());
13239 LI->setAtomic(llvm::AtomicOrdering::Acquire);
13241 return Builder.CreateInsertElement(Ops[1], Ops[0], Ops[2],
"vldap1_lane");
13243 case NEON::BI__builtin_neon_vld1_dup_v:
13244 case NEON::BI__builtin_neon_vld1q_dup_v: {
13245 Value *
V = PoisonValue::get(Ty);
13248 llvm::Constant *CI = ConstantInt::get(
Int32Ty, 0);
13249 Ops[0] =
Builder.CreateInsertElement(
V, Ops[0], CI);
13252 case NEON::BI__builtin_neon_vst1_lane_v:
13253 case NEON::BI__builtin_neon_vst1q_lane_v:
13254 Ops[1] =
Builder.CreateBitCast(Ops[1], Ty);
13255 Ops[1] =
Builder.CreateExtractElement(Ops[1], Ops[2]);
13257 case NEON::BI__builtin_neon_vstl1_lane_s64:
13258 case NEON::BI__builtin_neon_vstl1q_lane_s64: {
13259 Ops[1] =
Builder.CreateBitCast(Ops[1], Ty);
13260 Ops[1] =
Builder.CreateExtractElement(Ops[1], Ops[2]);
13261 llvm::StoreInst *SI =
13263 SI->setAtomic(llvm::AtomicOrdering::Release);
13266 case NEON::BI__builtin_neon_vld2_v:
13267 case NEON::BI__builtin_neon_vld2q_v: {
13270 Ops[1] =
Builder.CreateCall(F, Ops[1],
"vld2");
13273 case NEON::BI__builtin_neon_vld3_v:
13274 case NEON::BI__builtin_neon_vld3q_v: {
13277 Ops[1] =
Builder.CreateCall(F, Ops[1],
"vld3");
13280 case NEON::BI__builtin_neon_vld4_v:
13281 case NEON::BI__builtin_neon_vld4q_v: {
13284 Ops[1] =
Builder.CreateCall(F, Ops[1],
"vld4");
13287 case NEON::BI__builtin_neon_vld2_dup_v:
13288 case NEON::BI__builtin_neon_vld2q_dup_v: {
13291 Ops[1] =
Builder.CreateCall(F, Ops[1],
"vld2");
13294 case NEON::BI__builtin_neon_vld3_dup_v:
13295 case NEON::BI__builtin_neon_vld3q_dup_v: {
13298 Ops[1] =
Builder.CreateCall(F, Ops[1],
"vld3");
13301 case NEON::BI__builtin_neon_vld4_dup_v:
13302 case NEON::BI__builtin_neon_vld4q_dup_v: {
13305 Ops[1] =
Builder.CreateCall(F, Ops[1],
"vld4");
13308 case NEON::BI__builtin_neon_vld2_lane_v:
13309 case NEON::BI__builtin_neon_vld2q_lane_v: {
13310 llvm::Type *Tys[2] = { VTy, Ops[1]->getType() };
13312 std::rotate(Ops.begin() + 1, Ops.begin() + 2, Ops.end());
13313 Ops[1] =
Builder.CreateBitCast(Ops[1], Ty);
13314 Ops[2] =
Builder.CreateBitCast(Ops[2], Ty);
13319 case NEON::BI__builtin_neon_vld3_lane_v:
13320 case NEON::BI__builtin_neon_vld3q_lane_v: {
13321 llvm::Type *Tys[2] = { VTy, Ops[1]->getType() };
13323 std::rotate(Ops.begin() + 1, Ops.begin() + 2, Ops.end());
13324 Ops[1] =
Builder.CreateBitCast(Ops[1], Ty);
13325 Ops[2] =
Builder.CreateBitCast(Ops[2], Ty);
13326 Ops[3] =
Builder.CreateBitCast(Ops[3], Ty);
13331 case NEON::BI__builtin_neon_vld4_lane_v:
13332 case NEON::BI__builtin_neon_vld4q_lane_v: {
13333 llvm::Type *Tys[2] = { VTy, Ops[1]->getType() };
13335 std::rotate(Ops.begin() + 1, Ops.begin() + 2, Ops.end());
13336 Ops[1] =
Builder.CreateBitCast(Ops[1], Ty);
13337 Ops[2] =
Builder.CreateBitCast(Ops[2], Ty);
13338 Ops[3] =
Builder.CreateBitCast(Ops[3], Ty);
13339 Ops[4] =
Builder.CreateBitCast(Ops[4], Ty);
13344 case NEON::BI__builtin_neon_vst2_v:
13345 case NEON::BI__builtin_neon_vst2q_v: {
13346 std::rotate(Ops.begin(), Ops.begin() + 1, Ops.end());
13347 llvm::Type *Tys[2] = { VTy, Ops[2]->getType() };
13351 case NEON::BI__builtin_neon_vst2_lane_v:
13352 case NEON::BI__builtin_neon_vst2q_lane_v: {
13353 std::rotate(Ops.begin(), Ops.begin() + 1, Ops.end());
13355 llvm::Type *Tys[2] = { VTy, Ops[3]->getType() };
13359 case NEON::BI__builtin_neon_vst3_v:
13360 case NEON::BI__builtin_neon_vst3q_v: {
13361 std::rotate(Ops.begin(), Ops.begin() + 1, Ops.end());
13362 llvm::Type *Tys[2] = { VTy, Ops[3]->getType() };
13366 case NEON::BI__builtin_neon_vst3_lane_v:
13367 case NEON::BI__builtin_neon_vst3q_lane_v: {
13368 std::rotate(Ops.begin(), Ops.begin() + 1, Ops.end());
13370 llvm::Type *Tys[2] = { VTy, Ops[4]->getType() };
13374 case NEON::BI__builtin_neon_vst4_v:
13375 case NEON::BI__builtin_neon_vst4q_v: {
13376 std::rotate(Ops.begin(), Ops.begin() + 1, Ops.end());
13377 llvm::Type *Tys[2] = { VTy, Ops[4]->getType() };
13381 case NEON::BI__builtin_neon_vst4_lane_v:
13382 case NEON::BI__builtin_neon_vst4q_lane_v: {
13383 std::rotate(Ops.begin(), Ops.begin() + 1, Ops.end());
13385 llvm::Type *Tys[2] = { VTy, Ops[5]->getType() };
13389 case NEON::BI__builtin_neon_vtrn_v:
13390 case NEON::BI__builtin_neon_vtrnq_v: {
13391 Ops[1] =
Builder.CreateBitCast(Ops[1], Ty);
13392 Ops[2] =
Builder.CreateBitCast(Ops[2], Ty);
13393 Value *SV =
nullptr;
13395 for (
unsigned vi = 0; vi != 2; ++vi) {
13397 for (
unsigned i = 0, e = VTy->getNumElements(); i != e; i += 2) {
13398 Indices.push_back(i+vi);
13399 Indices.push_back(i+e+vi);
13401 Value *Addr =
Builder.CreateConstInBoundsGEP1_32(Ty, Ops[0], vi);
13402 SV =
Builder.CreateShuffleVector(Ops[1], Ops[2], Indices,
"vtrn");
13407 case NEON::BI__builtin_neon_vuzp_v:
13408 case NEON::BI__builtin_neon_vuzpq_v: {
13409 Ops[1] =
Builder.CreateBitCast(Ops[1], Ty);
13410 Ops[2] =
Builder.CreateBitCast(Ops[2], Ty);
13411 Value *SV =
nullptr;
13413 for (
unsigned vi = 0; vi != 2; ++vi) {
13415 for (
unsigned i = 0, e = VTy->getNumElements(); i != e; ++i)
13416 Indices.push_back(2*i+vi);
13418 Value *Addr =
Builder.CreateConstInBoundsGEP1_32(Ty, Ops[0], vi);
13419 SV =
Builder.CreateShuffleVector(Ops[1], Ops[2], Indices,
"vuzp");
13424 case NEON::BI__builtin_neon_vzip_v:
13425 case NEON::BI__builtin_neon_vzipq_v: {
13426 Ops[1] =
Builder.CreateBitCast(Ops[1], Ty);
13427 Ops[2] =
Builder.CreateBitCast(Ops[2], Ty);
13428 Value *SV =
nullptr;
13430 for (
unsigned vi = 0; vi != 2; ++vi) {
13432 for (
unsigned i = 0, e = VTy->getNumElements(); i != e; i += 2) {
13433 Indices.push_back((i + vi*e) >> 1);
13434 Indices.push_back(((i + vi*e) >> 1)+e);
13436 Value *Addr =
Builder.CreateConstInBoundsGEP1_32(Ty, Ops[0], vi);
13437 SV =
Builder.CreateShuffleVector(Ops[1], Ops[2], Indices,
"vzip");
13442 case NEON::BI__builtin_neon_vqtbl1q_v: {
13446 case NEON::BI__builtin_neon_vqtbl2q_v: {
13450 case NEON::BI__builtin_neon_vqtbl3q_v: {
13454 case NEON::BI__builtin_neon_vqtbl4q_v: {
13458 case NEON::BI__builtin_neon_vqtbx1q_v: {
13462 case NEON::BI__builtin_neon_vqtbx2q_v: {
13466 case NEON::BI__builtin_neon_vqtbx3q_v: {
13470 case NEON::BI__builtin_neon_vqtbx4q_v: {
13474 case NEON::BI__builtin_neon_vsqadd_v:
13475 case NEON::BI__builtin_neon_vsqaddq_v: {
13476 Int = Intrinsic::aarch64_neon_usqadd;
13479 case NEON::BI__builtin_neon_vuqadd_v:
13480 case NEON::BI__builtin_neon_vuqaddq_v: {
13481 Int = Intrinsic::aarch64_neon_suqadd;
13489 assert((BuiltinID == BPF::BI__builtin_preserve_field_info ||
13490 BuiltinID == BPF::BI__builtin_btf_type_id ||
13491 BuiltinID == BPF::BI__builtin_preserve_type_info ||
13492 BuiltinID == BPF::BI__builtin_preserve_enum_value) &&
13493 "unexpected BPF builtin");
13500 switch (BuiltinID) {
13502 llvm_unreachable(
"Unexpected BPF builtin");
13503 case BPF::BI__builtin_preserve_field_info: {
13504 const Expr *Arg =
E->getArg(0);
13509 "using __builtin_preserve_field_info() without -g");
13522 Value *InfoKind = ConstantInt::get(
Int64Ty,
C->getSExtValue());
13525 llvm::Function *FnGetFieldInfo = llvm::Intrinsic::getDeclaration(
13526 &
CGM.
getModule(), llvm::Intrinsic::bpf_preserve_field_info,
13527 {FieldAddr->getType()});
13528 return Builder.CreateCall(FnGetFieldInfo, {FieldAddr, InfoKind});
13530 case BPF::BI__builtin_btf_type_id:
13531 case BPF::BI__builtin_preserve_type_info: {
13537 const Expr *Arg0 =
E->getArg(0);
13542 Value *FlagValue = ConstantInt::get(
Int64Ty, Flag->getSExtValue());
13543 Value *SeqNumVal = ConstantInt::get(
Int32Ty, BuiltinSeqNum++);
13545 llvm::Function *FnDecl;
13546 if (BuiltinID == BPF::BI__builtin_btf_type_id)
13547 FnDecl = llvm::Intrinsic::getDeclaration(
13548 &
CGM.
getModule(), llvm::Intrinsic::bpf_btf_type_id, {});
13550 FnDecl = llvm::Intrinsic::getDeclaration(
13551 &
CGM.
getModule(), llvm::Intrinsic::bpf_preserve_type_info, {});
13552 CallInst *
Fn =
Builder.CreateCall(FnDecl, {SeqNumVal, FlagValue});
13553 Fn->setMetadata(LLVMContext::MD_preserve_access_index, DbgInfo);
13556 case BPF::BI__builtin_preserve_enum_value: {
13562 const Expr *Arg0 =
E->getArg(0);
13567 const auto *UO = cast<UnaryOperator>(Arg0->
IgnoreParens());
13568 const auto *CE = cast<CStyleCastExpr>(UO->getSubExpr());
13569 const auto *DR = cast<DeclRefExpr>(CE->getSubExpr());
13570 const auto *Enumerator = cast<EnumConstantDecl>(DR->getDecl());
13572 auto InitVal = Enumerator->getInitVal();
13573 std::string InitValStr;
13574 if (InitVal.isNegative() || InitVal >
uint64_t(INT64_MAX))
13575 InitValStr = std::to_string(InitVal.getSExtValue());
13577 InitValStr = std::to_string(InitVal.getZExtValue());
13578 std::string EnumStr = Enumerator->getNameAsString() +
":" + InitValStr;
13579 Value *EnumStrVal =
Builder.CreateGlobalStringPtr(EnumStr);
13582 Value *FlagValue = ConstantInt::get(
Int64Ty, Flag->getSExtValue());
13583 Value *SeqNumVal = ConstantInt::get(
Int32Ty, BuiltinSeqNum++);
13585 llvm::Function *IntrinsicFn = llvm::Intrinsic::getDeclaration(
13586 &
CGM.
getModule(), llvm::Intrinsic::bpf_preserve_enum_value, {});
13588 Builder.CreateCall(IntrinsicFn, {SeqNumVal, EnumStrVal, FlagValue});
13589 Fn->setMetadata(LLVMContext::MD_preserve_access_index, DbgInfo);
13597 assert((Ops.size() & (Ops.size() - 1)) == 0 &&
13598 "Not a power-of-two sized vector!");
13599 bool AllConstants =
true;
13600 for (
unsigned i = 0, e = Ops.size(); i != e && AllConstants; ++i)
13601 AllConstants &= isa<Constant>(Ops[i]);
13604 if (AllConstants) {
13606 for (
unsigned i = 0, e = Ops.size(); i != e; ++i)
13607 CstOps.push_back(cast<Constant>(Ops[i]));
13608 return llvm::ConstantVector::get(CstOps);
13613 llvm::FixedVectorType::get(Ops[0]->getType(), Ops.size()));
13615 for (
unsigned i = 0, e = Ops.size(); i != e; ++i)
13623 unsigned NumElts) {
13625 auto *MaskTy = llvm::FixedVectorType::get(
13627 cast<IntegerType>(Mask->
getType())->getBitWidth());
13628 Value *MaskVec = CGF.
Builder.CreateBitCast(Mask, MaskTy);
13634 for (
unsigned i = 0; i != NumElts; ++i)
13636 MaskVec = CGF.
Builder.CreateShuffleVector(
13637 MaskVec, MaskVec,
ArrayRef(Indices, NumElts),
"extract");
13644 Value *Ptr = Ops[0];
13648 cast<llvm::FixedVectorType>(Ops[1]->getType())->getNumElements());
13650 return CGF.
Builder.CreateMaskedStore(Ops[1], Ptr, Alignment, MaskVec);
13655 llvm::Type *Ty = Ops[1]->getType();
13656 Value *Ptr = Ops[0];
13659 CGF, Ops[2], cast<llvm::FixedVectorType>(Ty)->getNumElements());
13661 return CGF.
Builder.CreateMaskedLoad(Ty, Ptr, Alignment, MaskVec, Ops[1]);
13666 auto *ResultTy = cast<llvm::VectorType>(Ops[1]->getType());
13667 Value *Ptr = Ops[0];
13670 CGF, Ops[2], cast<FixedVectorType>(ResultTy)->getNumElements());
13672 llvm::Function *F = CGF.
CGM.
getIntrinsic(Intrinsic::masked_expandload,
13674 return CGF.
Builder.CreateCall(F, { Ptr, MaskVec, Ops[1] });
13680 auto *ResultTy = cast<llvm::FixedVectorType>(Ops[1]->getType());
13684 Intrinsic::ID IID = IsCompress ? Intrinsic::x86_avx512_mask_compress
13685 : Intrinsic::x86_avx512_mask_expand;
13687 return CGF.
Builder.CreateCall(F, { Ops[0], Ops[1], MaskVec });
13692 auto *ResultTy = cast<llvm::FixedVectorType>(Ops[1]->getType());
13693 Value *Ptr = Ops[0];
13697 llvm::Function *F = CGF.
CGM.
getIntrinsic(Intrinsic::masked_compressstore,
13699 return CGF.
Builder.CreateCall(F, { Ops[1], Ptr, MaskVec });
13704 bool InvertLHS =
false) {
13705 unsigned NumElts = Ops[0]->getType()->getIntegerBitWidth();
13710 LHS = CGF.
Builder.CreateNot(LHS);
13712 return CGF.
Builder.CreateBitCast(CGF.
Builder.CreateBinOp(Opc, LHS, RHS),
13713 Ops[0]->getType());
13717 Value *Amt,
bool IsRight) {
13718 llvm::Type *Ty = Op0->
getType();
13724 unsigned NumElts = cast<llvm::FixedVectorType>(Ty)->getNumElements();
13725 Amt = CGF.
Builder.CreateIntCast(Amt, Ty->getScalarType(),
false);
13726 Amt = CGF.
Builder.CreateVectorSplat(NumElts, Amt);
13729 unsigned IID = IsRight ? Intrinsic::fshr : Intrinsic::fshl;
13731 return CGF.
Builder.CreateCall(F, {Op0, Op1, Amt});
13736 Value *Op0 = Ops[0];
13737 Value *Op1 = Ops[1];
13738 llvm::Type *Ty = Op0->
getType();
13739 uint64_t Imm = cast<llvm::ConstantInt>(Ops[2])->getZExtValue() & 0x7;
13741 CmpInst::Predicate Pred;
13744 Pred = IsSigned ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT;
13747 Pred = IsSigned ? ICmpInst::ICMP_SLE : ICmpInst::ICMP_ULE;
13750 Pred = IsSigned ? ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT;
13753 Pred = IsSigned ? ICmpInst::ICMP_SGE : ICmpInst::ICMP_UGE;
13756 Pred = ICmpInst::ICMP_EQ;
13759 Pred = ICmpInst::ICMP_NE;
13762 return llvm::Constant::getNullValue(Ty);
13764 return llvm::Constant::getAllOnesValue(Ty);
13766 llvm_unreachable(
"Unexpected XOP vpcom/vpcomu predicate");
13778 if (
const auto *
C = dyn_cast<Constant>(Mask))
13779 if (
C->isAllOnesValue())
13783 CGF, Mask, cast<llvm::FixedVectorType>(Op0->
getType())->getNumElements());
13785 return CGF.
Builder.CreateSelect(Mask, Op0, Op1);
13791 if (
const auto *
C = dyn_cast<Constant>(Mask))
13792 if (
C->isAllOnesValue())
13795 auto *MaskTy = llvm::FixedVectorType::get(
13796 CGF.
Builder.getInt1Ty(), Mask->
getType()->getIntegerBitWidth());
13797 Mask = CGF.
Builder.CreateBitCast(Mask, MaskTy);
13798 Mask = CGF.
Builder.CreateExtractElement(Mask, (uint64_t)0);
13799 return CGF.
Builder.CreateSelect(Mask, Op0, Op1);
13803 unsigned NumElts,
Value *MaskIn) {
13805 const auto *
C = dyn_cast<Constant>(MaskIn);
13806 if (!
C || !
C->isAllOnesValue())
13812 for (
unsigned i = 0; i != NumElts; ++i)
13814 for (
unsigned i = NumElts; i != 8; ++i)
13815 Indices[i] = i % NumElts + NumElts;
13816 Cmp = CGF.
Builder.CreateShuffleVector(
13817 Cmp, llvm::Constant::getNullValue(Cmp->getType()), Indices);
13820 return CGF.
Builder.CreateBitCast(Cmp,
13822 std::max(NumElts, 8U)));
13827 assert((Ops.size() == 2 || Ops.size() == 4) &&
13828 "Unexpected number of arguments");
13830 cast<llvm::FixedVectorType>(Ops[0]->getType())->getNumElements();
13834 Cmp = Constant::getNullValue(
13835 llvm::FixedVectorType::get(CGF.
Builder.getInt1Ty(), NumElts));
13836 }
else if (CC == 7) {
13837 Cmp = Constant::getAllOnesValue(
13838 llvm::FixedVectorType::get(CGF.
Builder.getInt1Ty(), NumElts));
13840 ICmpInst::Predicate Pred;
13842 default: llvm_unreachable(
"Unknown condition code");
13843 case 0: Pred = ICmpInst::ICMP_EQ;
break;
13844 case 1: Pred =
Signed ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT;
break;
13845 case 2: Pred =
Signed ? ICmpInst::ICMP_SLE : ICmpInst::ICMP_ULE;
break;
13846 case 4: Pred = ICmpInst::ICMP_NE;
break;
13847 case 5: Pred =
Signed ? ICmpInst::ICMP_SGE : ICmpInst::ICMP_UGE;
break;
13848 case 6: Pred =
Signed ? ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT;
break;
13850 Cmp = CGF.
Builder.CreateICmp(Pred, Ops[0], Ops[1]);
13853 Value *MaskIn =
nullptr;
13854 if (Ops.size() == 4)
13861 Value *Zero = Constant::getNullValue(In->getType());
13867 unsigned Rnd = cast<llvm::ConstantInt>(Ops[3])->getZExtValue();
13868 llvm::Type *Ty = Ops[1]->getType();
13872 Intrinsic::ID IID = IsSigned ? Intrinsic::x86_avx512_sitofp_round
13873 : Intrinsic::x86_avx512_uitofp_round;
13875 Res = CGF.
Builder.CreateCall(F, { Ops[0], Ops[3] });
13877 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF,
E);
13878 Res = IsSigned ? CGF.
Builder.CreateSIToFP(Ops[0], Ty)
13879 : CGF.
Builder.CreateUIToFP(Ops[0], Ty);
13890 bool Subtract =
false;
13891 Intrinsic::ID IID = Intrinsic::not_intrinsic;
13892 switch (BuiltinID) {
13894 case clang::X86::BI__builtin_ia32_vfmsubph512_mask3:
13897 case clang::X86::BI__builtin_ia32_vfmaddph512_mask:
13898 case clang::X86::BI__builtin_ia32_vfmaddph512_maskz:
13899 case clang::X86::BI__builtin_ia32_vfmaddph512_mask3:
13900 IID = llvm::Intrinsic::x86_avx512fp16_vfmadd_ph_512;
13902 case clang::X86::BI__builtin_ia32_vfmsubaddph512_mask3:
13905 case clang::X86::BI__builtin_ia32_vfmaddsubph512_mask:
13906 case clang::X86::BI__builtin_ia32_vfmaddsubph512_maskz:
13907 case clang::X86::BI__builtin_ia32_vfmaddsubph512_mask3:
13908 IID = llvm::Intrinsic::x86_avx512fp16_vfmaddsub_ph_512;
13910 case clang::X86::BI__builtin_ia32_vfmsubps512_mask3:
13913 case clang::X86::BI__builtin_ia32_vfmaddps512_mask:
13914 case clang::X86::BI__builtin_ia32_vfmaddps512_maskz:
13915 case clang::X86::BI__builtin_ia32_vfmaddps512_mask3:
13916 IID = llvm::Intrinsic::x86_avx512_vfmadd_ps_512;
break;
13917 case clang::X86::BI__builtin_ia32_vfmsubpd512_mask3:
13920 case clang::X86::BI__builtin_ia32_vfmaddpd512_mask:
13921 case clang::X86::BI__builtin_ia32_vfmaddpd512_maskz:
13922 case clang::X86::BI__builtin_ia32_vfmaddpd512_mask3:
13923 IID = llvm::Intrinsic::x86_avx512_vfmadd_pd_512;
break;
13924 case clang::X86::BI__builtin_ia32_vfmsubaddps512_mask3:
13927 case clang::X86::BI__builtin_ia32_vfmaddsubps512_mask:
13928 case clang::X86::BI__builtin_ia32_vfmaddsubps512_maskz:
13929 case clang::X86::BI__builtin_ia32_vfmaddsubps512_mask3:
13930 IID = llvm::Intrinsic::x86_avx512_vfmaddsub_ps_512;
13932 case clang::X86::BI__builtin_ia32_vfmsubaddpd512_mask3:
13935 case clang::X86::BI__builtin_ia32_vfmaddsubpd512_mask:
13936 case clang::X86::BI__builtin_ia32_vfmaddsubpd512_maskz:
13937 case clang::X86::BI__builtin_ia32_vfmaddsubpd512_mask3:
13938 IID = llvm::Intrinsic::x86_avx512_vfmaddsub_pd_512;
13940 case clang::X86::BI__builtin_ia32_vfmsubph256_round_mask3:
13943 case clang::X86::BI__builtin_ia32_vfmaddph256_round_mask:
13944 case clang::X86::BI__builtin_ia32_vfmaddph256_round_maskz:
13945 case clang::X86::BI__builtin_ia32_vfmaddph256_round_mask3:
13946 IID = llvm::Intrinsic::x86_avx10_vfmaddph256;
13948 case clang::X86::BI__builtin_ia32_vfmsubaddph256_round_mask3:
13951 case clang::X86::BI__builtin_ia32_vfmaddsubph256_round_mask:
13952 case clang::X86::BI__builtin_ia32_vfmaddsubph256_round_maskz:
13953 case clang::X86::BI__builtin_ia32_vfmaddsubph256_round_mask3:
13954 IID = llvm::Intrinsic::x86_avx10_vfmaddsubph256;
13956 case clang::X86::BI__builtin_ia32_vfmsubps256_round_mask3:
13959 case clang::X86::BI__builtin_ia32_vfmaddps256_round_mask:
13960 case clang::X86::BI__builtin_ia32_vfmaddps256_round_maskz:
13961 case clang::X86::BI__builtin_ia32_vfmaddps256_round_mask3:
13962 IID = llvm::Intrinsic::x86_avx10_vfmaddps256;
13964 case clang::X86::BI__builtin_ia32_vfmsubpd256_round_mask3:
13967 case clang::X86::BI__builtin_ia32_vfmaddpd256_round_mask:
13968 case clang::X86::BI__builtin_ia32_vfmaddpd256_round_maskz:
13969 case clang::X86::BI__builtin_ia32_vfmaddpd256_round_mask3:
13970 IID = llvm::Intrinsic::x86_avx10_vfmaddpd256;
13972 case clang::X86::BI__builtin_ia32_vfmsubaddps256_round_mask3:
13975 case clang::X86::BI__builtin_ia32_vfmaddsubps256_round_mask:
13976 case clang::X86::BI__builtin_ia32_vfmaddsubps256_round_maskz:
13977 case clang::X86::BI__builtin_ia32_vfmaddsubps256_round_mask3:
13978 IID = llvm::Intrinsic::x86_avx10_vfmaddsubps256;
13980 case clang::X86::BI__builtin_ia32_vfmsubaddpd256_round_mask3:
13983 case clang::X86::BI__builtin_ia32_vfmaddsubpd256_round_mask:
13984 case clang::X86::BI__builtin_ia32_vfmaddsubpd256_round_maskz:
13985 case clang::X86::BI__builtin_ia32_vfmaddsubpd256_round_mask3:
13986 IID = llvm::Intrinsic::x86_avx10_vfmaddsubpd256;
14000 if (IID != Intrinsic::not_intrinsic &&
14001 (cast<llvm::ConstantInt>(Ops.back())->getZExtValue() != (uint64_t)4 ||
14004 Res = CGF.
Builder.CreateCall(Intr, {A, B,
C, Ops.back() });
14006 llvm::Type *Ty = A->
getType();
14008 if (CGF.
Builder.getIsFPConstrained()) {
14009 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF,
E);
14010 FMA = CGF.
CGM.
getIntrinsic(Intrinsic::experimental_constrained_fma, Ty);
14011 Res = CGF.
Builder.CreateConstrainedFPCall(FMA, {A, B,
C});
14014 Res = CGF.
Builder.CreateCall(FMA, {A, B,
C});
14019 Value *MaskFalseVal =
nullptr;
14020 switch (BuiltinID) {
14021 case clang::X86::BI__builtin_ia32_vfmaddph512_mask:
14022 case clang::X86::BI__builtin_ia32_vfmaddps512_mask:
14023 case clang::X86::BI__builtin_ia32_vfmaddpd512_mask:
14024 case clang::X86::BI__builtin_ia32_vfmaddsubph512_mask:
14025 case clang::X86::BI__builtin_ia32_vfmaddsubps512_mask:
14026 case clang::X86::BI__builtin_ia32_vfmaddsubpd512_mask:
14027 case clang::X86::BI__builtin_ia32_vfmaddph256_round_mask:
14028 case clang::X86::BI__builtin_ia32_vfmaddps256_round_mask:
14029 case clang::X86::BI__builtin_ia32_vfmaddpd256_round_mask:
14030 case clang::X86::BI__builtin_ia32_vfmaddsubph256_round_mask:
14031 case clang::X86::BI__builtin_ia32_vfmaddsubps256_round_mask:
14032 case clang::X86::BI__builtin_ia32_vfmaddsubpd256_round_mask:
14033 MaskFalseVal = Ops[0];
14035 case clang::X86::BI__builtin_ia32_vfmaddph512_maskz:
14036 case clang::X86::BI__builtin_ia32_vfmaddps512_maskz:
14037 case clang::X86::BI__builtin_ia32_vfmaddpd512_maskz:
14038 case clang::X86::BI__builtin_ia32_vfmaddsubph512_maskz:
14039 case clang::X86::BI__builtin_ia32_vfmaddsubps512_maskz:
14040 case clang::X86::BI__builtin_ia32_vfmaddsubpd512_maskz:
14041 case clang::X86::BI__builtin_ia32_vfmaddph256_round_maskz:
14042 case clang::X86::BI__builtin_ia32_vfmaddps256_round_maskz:
14043 case clang::X86::BI__builtin_ia32_vfmaddpd256_round_maskz:
14044 case clang::X86::BI__builtin_ia32_vfmaddsubph256_round_maskz:
14045 case clang::X86::BI__builtin_ia32_vfmaddsubps256_round_maskz:
14046 case clang::X86::BI__builtin_ia32_vfmaddsubpd256_round_maskz:
14047 MaskFalseVal = Constant::getNullValue(Ops[0]->getType());
14049 case clang::X86::BI__builtin_ia32_vfmsubph512_mask3:
14050 case clang::X86::BI__builtin_ia32_vfmaddph512_mask3:
14051 case clang::X86::BI__builtin_ia32_vfmsubps512_mask3:
14052 case clang::X86::BI__builtin_ia32_vfmaddps512_mask3:
14053 case clang::X86::BI__builtin_ia32_vfmsubpd512_mask3:
14054 case clang::X86::BI__builtin_ia32_vfmaddpd512_mask3:
14055 case clang::X86::BI__builtin_ia32_vfmsubaddph512_mask3:
14056 case clang::X86::BI__builtin_ia32_vfmaddsubph512_mask3:
14057 case clang::X86::BI__builtin_ia32_vfmsubaddps512_mask3:
14058 case clang::X86::BI__builtin_ia32_vfmaddsubps512_mask3:
14059 case clang::X86::BI__builtin_ia32_vfmsubaddpd512_mask3:
14060 case clang::X86::BI__builtin_ia32_vfmaddsubpd512_mask3:
14061 case clang::X86::BI__builtin_ia32_vfmsubph256_round_mask3:
14062 case clang::X86::BI__builtin_ia32_vfmaddph256_round_mask3:
14063 case clang::X86::BI__builtin_ia32_vfmsubps256_round_mask3:
14064 case clang::X86::BI__builtin_ia32_vfmaddps256_round_mask3:
14065 case clang::X86::BI__builtin_ia32_vfmsubpd256_round_mask3:
14066 case clang::X86::BI__builtin_ia32_vfmaddpd256_round_mask3:
14067 case clang::X86::BI__builtin_ia32_vfmsubaddph256_round_mask3:
14068 case clang::X86::BI__builtin_ia32_vfmaddsubph256_round_mask3:
14069 case clang::X86::BI__builtin_ia32_vfmsubaddps256_round_mask3:
14070 case clang::X86::BI__builtin_ia32_vfmaddsubps256_round_mask3:
14071 case clang::X86::BI__builtin_ia32_vfmsubaddpd256_round_mask3:
14072 case clang::X86::BI__builtin_ia32_vfmaddsubpd256_round_mask3:
14073 MaskFalseVal = Ops[2];
14085 bool ZeroMask =
false,
unsigned PTIdx = 0,
14086 bool NegAcc =
false) {
14088 if (Ops.size() > 4)
14089 Rnd = cast<llvm::ConstantInt>(Ops[4])->getZExtValue();
14092 Ops[2] = CGF.
Builder.CreateFNeg(Ops[2]);
14094 Ops[0] = CGF.
Builder.CreateExtractElement(Ops[0], (uint64_t)0);
14095 Ops[1] = CGF.
Builder.CreateExtractElement(Ops[1], (uint64_t)0);
14096 Ops[2] = CGF.
Builder.CreateExtractElement(Ops[2], (uint64_t)0);
14101 switch (Ops[0]->getType()->getPrimitiveSizeInBits()) {
14103 IID = Intrinsic::x86_avx512fp16_vfmadd_f16;
14106 IID = Intrinsic::x86_avx512_vfmadd_f32;
14109 IID = Intrinsic::x86_avx512_vfmadd_f64;
14112 llvm_unreachable(
"Unexpected size");
14115 {Ops[0], Ops[1], Ops[2], Ops[4]});
14116 }
else if (CGF.
Builder.getIsFPConstrained()) {
14117 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF,
E);
14119 Intrinsic::experimental_constrained_fma, Ops[0]->getType());
14120 Res = CGF.
Builder.CreateConstrainedFPCall(FMA, Ops.slice(0, 3));
14123 Res = CGF.
Builder.CreateCall(FMA, Ops.slice(0, 3));
14126 if (Ops.size() > 3) {
14127 Value *PassThru = ZeroMask ? Constant::getNullValue(Res->
getType())
14133 if (NegAcc && PTIdx == 2)
14134 PassThru = CGF.
Builder.CreateExtractElement(Upper, (uint64_t)0);
14138 return CGF.
Builder.CreateInsertElement(Upper, Res, (uint64_t)0);
14143 llvm::Type *Ty = Ops[0]->getType();
14145 Ty = llvm::FixedVectorType::get(CGF.
Int64Ty,
14146 Ty->getPrimitiveSizeInBits() / 64);
14152 Constant *ShiftAmt = ConstantInt::get(Ty, 32);
14153 LHS = CGF.
Builder.CreateShl(LHS, ShiftAmt);
14154 LHS = CGF.
Builder.CreateAShr(LHS, ShiftAmt);
14155 RHS = CGF.
Builder.CreateShl(RHS, ShiftAmt);
14156 RHS = CGF.
Builder.CreateAShr(RHS, ShiftAmt);
14159 Constant *Mask = ConstantInt::get(Ty, 0xffffffff);
14160 LHS = CGF.
Builder.CreateAnd(LHS, Mask);
14161 RHS = CGF.
Builder.CreateAnd(RHS, Mask);
14164 return CGF.
Builder.CreateMul(LHS, RHS);
14172 llvm::Type *Ty = Ops[0]->getType();
14174 unsigned VecWidth = Ty->getPrimitiveSizeInBits();
14175 unsigned EltWidth = Ty->getScalarSizeInBits();
14177 if (VecWidth == 128 && EltWidth == 32)
14178 IID = Intrinsic::x86_avx512_pternlog_d_128;
14179 else if (VecWidth == 256 && EltWidth == 32)
14180 IID = Intrinsic::x86_avx512_pternlog_d_256;
14181 else if (VecWidth == 512 && EltWidth == 32)
14182 IID = Intrinsic::x86_avx512_pternlog_d_512;
14183 else if (VecWidth == 128 && EltWidth == 64)
14184 IID = Intrinsic::x86_avx512_pternlog_q_128;
14185 else if (VecWidth == 256 && EltWidth == 64)
14186 IID = Intrinsic::x86_avx512_pternlog_q_256;
14187 else if (VecWidth == 512 && EltWidth == 64)
14188 IID = Intrinsic::x86_avx512_pternlog_q_512;
14190 llvm_unreachable(
"Unexpected intrinsic");
14194 Value *PassThru = ZeroMask ? ConstantAggregateZero::get(Ty) : Ops[0];
14199 llvm::Type *DstTy) {
14200 unsigned NumberOfElements =
14201 cast<llvm::FixedVectorType>(DstTy)->getNumElements();
14203 return CGF.
Builder.CreateSExt(Mask, DstTy,
"vpmovm2");
14208 StringRef CPUStr = cast<clang::StringLiteral>(CPUExpr)->getString();
14209 return EmitX86CpuIs(CPUStr);
14215 llvm::Type *DstTy) {
14216 assert((Ops.size() == 1 || Ops.size() == 3 || Ops.size() == 4) &&
14217 "Unknown cvtph2ps intrinsic");
14220 if (Ops.size() == 4 && cast<llvm::ConstantInt>(Ops[3])->getZExtValue() != 4) {
14223 return CGF.
Builder.CreateCall(F, {Ops[0], Ops[1], Ops[2], Ops[3]});
14226 unsigned NumDstElts = cast<llvm::FixedVectorType>(DstTy)->getNumElements();
14227 Value *Src = Ops[0];
14231 cast<llvm::FixedVectorType>(Src->
getType())->getNumElements()) {
14232 assert(NumDstElts == 4 &&
"Unexpected vector size");
14237 auto *HalfTy = llvm::FixedVectorType::get(
14239 Src = CGF.
Builder.CreateBitCast(Src, HalfTy);
14242 Value *Res = CGF.
Builder.CreateFPExt(Src, DstTy,
"cvtph2ps");
14244 if (Ops.size() >= 3)
14249Value *CodeGenFunction::EmitX86CpuIs(StringRef CPUStr) {
14260 llvm::ArrayType::get(
Int32Ty, 1));
14264 cast<llvm::GlobalValue>(CpuModel)->setDSOLocal(
true);
14270 std::tie(Index,
Value) = StringSwitch<std::pair<unsigned, unsigned>>(CPUStr)
14272 .Case(STRING, {0u,
static_cast<unsigned>(llvm::X86::ENUM)})
14274 .Case(
ALIAS, {1u,
static_cast<unsigned>(llvm::X86::ENUM)})
14276 .Case(STR, {1u,
static_cast<unsigned>(llvm::X86::ENUM)})
14278 .Case(
ALIAS, {2u,
static_cast<unsigned>(llvm::X86::ENUM)})
14280 .Case(STR, {2u,
static_cast<unsigned>(llvm::X86::ENUM)})
14281#include
"llvm/TargetParser/X86TargetParser.def"
14283 assert(
Value != 0 &&
"Invalid CPUStr passed to CpuIs");
14286 llvm::Value *Idxs[] = {ConstantInt::get(
Int32Ty, 0),
14287 ConstantInt::get(
Int32Ty, Index)};
14293 return Builder.CreateICmpEQ(CpuValue,
14299 StringRef FeatureStr = cast<StringLiteral>(FeatureExpr)->getString();
14300 if (!
getContext().getTargetInfo().validateCpuSupports(FeatureStr))
14302 return EmitX86CpuSupports(FeatureStr);
14306 return EmitX86CpuSupports(llvm::X86::getCpuSupportsMask(FeatureStrs));
14310CodeGenFunction::EmitX86CpuSupports(std::array<uint32_t, 4> FeatureMask) {
14312 if (FeatureMask[0] != 0) {
14320 llvm::ArrayType::get(
Int32Ty, 1));
14324 cast<llvm::GlobalValue>(CpuModel)->setDSOLocal(
true);
14341 llvm::Type *ATy = llvm::ArrayType::get(
Int32Ty, 3);
14342 llvm::Constant *CpuFeatures2 =
14344 cast<llvm::GlobalValue>(CpuFeatures2)->setDSOLocal(
true);
14345 for (
int i = 1; i != 4; ++i) {
14346 const uint32_t M = FeatureMask[i];
14363Value *CodeGenFunction::EmitAArch64CpuInit() {
14364 llvm::FunctionType *FTy = llvm::FunctionType::get(
VoidTy,
false);
14365 llvm::FunctionCallee
Func =
14367 cast<llvm::GlobalValue>(
Func.getCallee())->setDSOLocal(
true);
14368 cast<llvm::GlobalValue>(
Func.getCallee())
14369 ->setDLLStorageClass(llvm::GlobalValue::DefaultStorageClass);
14374 llvm::FunctionType *FTy = llvm::FunctionType::get(
VoidTy, {
VoidPtrTy},
false);
14375 llvm::FunctionCallee
Func =
14377 auto *CalleeGV = cast<llvm::GlobalValue>(
Func.getCallee());
14378 CalleeGV->setDSOLocal(
true);
14379 CalleeGV->setDLLStorageClass(llvm::GlobalValue::DefaultStorageClass);
14383Value *CodeGenFunction::EmitX86CpuInit() {
14384 llvm::FunctionType *FTy = llvm::FunctionType::get(
VoidTy,
14386 llvm::FunctionCallee
Func =
14388 cast<llvm::GlobalValue>(
Func.getCallee())->setDSOLocal(
true);
14389 cast<llvm::GlobalValue>(
Func.getCallee())
14390 ->setDLLStorageClass(llvm::GlobalValue::DefaultStorageClass);
14394Value *CodeGenFunction::EmitAArch64CpuSupports(
const CallExpr *
E) {
14396 StringRef ArgStr = cast<StringLiteral>(ArgExpr)->getString();
14398 ArgStr.split(Features,
"+");
14399 for (
auto &Feature : Features) {
14400 Feature = Feature.trim();
14401 if (!llvm::AArch64::parseFMVExtension(Feature))
14403 if (Feature !=
"default")
14404 Features.push_back(Feature);
14406 return EmitAArch64CpuSupports(Features);
14411 uint64_t FeaturesMask = llvm::AArch64::getCpuSupportsMask(FeaturesStrs);
14413 if (FeaturesMask != 0) {
14418 llvm::Type *STy = llvm::StructType::get(
Int64Ty);
14419 llvm::Constant *AArch64CPUFeatures =
14421 cast<llvm::GlobalValue>(AArch64CPUFeatures)->setDSOLocal(
true);
14423 STy, AArch64CPUFeatures,
14438 StringRef FeatureStr = cast<StringLiteral>(FeatureExpr)->getString();
14439 if (!
getContext().getTargetInfo().validateCpuSupports(FeatureStr))
14445 llvm::ArrayType *ArrayOfInt64Ty = llvm::ArrayType::get(
Int64Ty, 1);
14446 llvm::Type *StructTy = llvm::StructType::get(
Int32Ty, ArrayOfInt64Ty);
14447 llvm::Constant *RISCVFeaturesBits =
14449 auto *GV = cast<llvm::GlobalValue>(RISCVFeaturesBits);
14450 GV->setDSOLocal(
true);
14452 auto LoadFeatureBit = [&](
unsigned Index) {
14454 Value *IndexVal = llvm::ConstantInt::get(
Int32Ty, Index);
14455 llvm::Value *GEPIndices[] = {
Builder.getInt32(0),
Builder.getInt32(1),
14459 Value *FeaturesBit =
14461 return FeaturesBit;
14464 auto [GroupID, BitPos] = RISCVISAInfo::getRISCVFeaturesBitsInfo(FeatureStr);
14465 assert(BitPos != -1 &&
"validation should have rejected this feature");
14467 Value *Bitset =
Builder.CreateAnd(LoadFeatureBit(GroupID), MaskV);
14468 return Builder.CreateICmpEQ(Bitset, MaskV);
14473 if (BuiltinID == Builtin::BI__builtin_cpu_is)
14474 return EmitX86CpuIs(
E);
14475 if (BuiltinID == Builtin::BI__builtin_cpu_supports)
14476 return EmitX86CpuSupports(
E);
14477 if (BuiltinID == Builtin::BI__builtin_cpu_init)
14478 return EmitX86CpuInit();
14486 bool IsMaskFCmp =
false;
14487 bool IsConjFMA =
false;
14490 unsigned ICEArguments = 0;
14495 for (
unsigned i = 0, e =
E->getNumArgs(); i != e; i++) {
14505 auto getCmpIntrinsicCall = [
this, &Ops](Intrinsic::ID
ID,
unsigned Imm) {
14506 Ops.push_back(llvm::ConstantInt::get(
Int8Ty, Imm));
14508 return Builder.CreateCall(F, Ops);
14516 auto getVectorFCmpIR = [
this, &Ops,
E](CmpInst::Predicate Pred,
14517 bool IsSignaling) {
14518 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*
this,
E);
14521 Cmp =
Builder.CreateFCmpS(Pred, Ops[0], Ops[1]);
14523 Cmp =
Builder.CreateFCmp(Pred, Ops[0], Ops[1]);
14524 llvm::VectorType *FPVecTy = cast<llvm::VectorType>(Ops[0]->getType());
14525 llvm::VectorType *IntVecTy = llvm::VectorType::getInteger(FPVecTy);
14527 return Builder.CreateBitCast(Sext, FPVecTy);
14530 switch (BuiltinID) {
14531 default:
return nullptr;
14532 case X86::BI_mm_prefetch: {
14534 ConstantInt *
C = cast<ConstantInt>(Ops[1]);
14535 Value *RW = ConstantInt::get(
Int32Ty, (
C->getZExtValue() >> 2) & 0x1);
14536 Value *Locality = ConstantInt::get(
Int32Ty,
C->getZExtValue() & 0x3);
14541 case X86::BI_mm_clflush: {
14545 case X86::BI_mm_lfence: {
14548 case X86::BI_mm_mfence: {
14551 case X86::BI_mm_sfence: {
14554 case X86::BI_mm_pause: {
14557 case X86::BI__rdtsc: {
14560 case X86::BI__builtin_ia32_rdtscp: {
14566 case X86::BI__builtin_ia32_lzcnt_u16:
14567 case X86::BI__builtin_ia32_lzcnt_u32:
14568 case X86::BI__builtin_ia32_lzcnt_u64: {
14572 case X86::BI__builtin_ia32_tzcnt_u16:
14573 case X86::BI__builtin_ia32_tzcnt_u32:
14574 case X86::BI__builtin_ia32_tzcnt_u64: {
14578 case X86::BI__builtin_ia32_undef128:
14579 case X86::BI__builtin_ia32_undef256:
14580 case X86::BI__builtin_ia32_undef512:
14587 case X86::BI__builtin_ia32_vec_ext_v4hi:
14588 case X86::BI__builtin_ia32_vec_ext_v16qi:
14589 case X86::BI__builtin_ia32_vec_ext_v8hi:
14590 case X86::BI__builtin_ia32_vec_ext_v4si:
14591 case X86::BI__builtin_ia32_vec_ext_v4sf:
14592 case X86::BI__builtin_ia32_vec_ext_v2di:
14593 case X86::BI__builtin_ia32_vec_ext_v32qi:
14594 case X86::BI__builtin_ia32_vec_ext_v16hi:
14595 case X86::BI__builtin_ia32_vec_ext_v8si:
14596 case X86::BI__builtin_ia32_vec_ext_v4di: {
14598 cast<llvm::FixedVectorType>(Ops[0]->getType())->getNumElements();
14599 uint64_t Index = cast<ConstantInt>(Ops[1])->getZExtValue();
14600 Index &= NumElts - 1;
14603 return Builder.CreateExtractElement(Ops[0], Index);
14605 case X86::BI__builtin_ia32_vec_set_v4hi:
14606 case X86::BI__builtin_ia32_vec_set_v16qi:
14607 case X86::BI__builtin_ia32_vec_set_v8hi:
14608 case X86::BI__builtin_ia32_vec_set_v4si:
14609 case X86::BI__builtin_ia32_vec_set_v2di:
14610 case X86::BI__builtin_ia32_vec_set_v32qi:
14611 case X86::BI__builtin_ia32_vec_set_v16hi:
14612 case X86::BI__builtin_ia32_vec_set_v8si:
14613 case X86::BI__builtin_ia32_vec_set_v4di: {
14615 cast<llvm::FixedVectorType>(Ops[0]->getType())->getNumElements();
14616 unsigned Index = cast<ConstantInt>(Ops[2])->getZExtValue();
14617 Index &= NumElts - 1;
14620 return Builder.CreateInsertElement(Ops[0], Ops[1], Index);
14622 case X86::BI_mm_setcsr:
14623 case X86::BI__builtin_ia32_ldmxcsr: {
14629 case X86::BI_mm_getcsr:
14630 case X86::BI__builtin_ia32_stmxcsr: {
14636 case X86::BI__builtin_ia32_xsave:
14637 case X86::BI__builtin_ia32_xsave64:
14638 case X86::BI__builtin_ia32_xrstor:
14639 case X86::BI__builtin_ia32_xrstor64:
14640 case X86::BI__builtin_ia32_xsaveopt:
14641 case X86::BI__builtin_ia32_xsaveopt64:
14642 case X86::BI__builtin_ia32_xrstors:
14643 case X86::BI__builtin_ia32_xrstors64:
14644 case X86::BI__builtin_ia32_xsavec:
14645 case X86::BI__builtin_ia32_xsavec64:
14646 case X86::BI__builtin_ia32_xsaves:
14647 case X86::BI__builtin_ia32_xsaves64:
14648 case X86::BI__builtin_ia32_xsetbv:
14649 case X86::BI_xsetbv: {
14651#define INTRINSIC_X86_XSAVE_ID(NAME) \
14652 case X86::BI__builtin_ia32_##NAME: \
14653 ID = Intrinsic::x86_##NAME; \
14655 switch (BuiltinID) {
14656 default: llvm_unreachable(
"Unsupported intrinsic!");
14670 case X86::BI_xsetbv:
14671 ID = Intrinsic::x86_xsetbv;
14674#undef INTRINSIC_X86_XSAVE_ID
14679 Ops.push_back(Mlo);
14682 case X86::BI__builtin_ia32_xgetbv:
14683 case X86::BI_xgetbv:
14685 case X86::BI__builtin_ia32_storedqudi128_mask:
14686 case X86::BI__builtin_ia32_storedqusi128_mask:
14687 case X86::BI__builtin_ia32_storedquhi128_mask:
14688 case X86::BI__builtin_ia32_storedquqi128_mask:
14689 case X86::BI__builtin_ia32_storeupd128_mask:
14690 case X86::BI__builtin_ia32_storeups128_mask:
14691 case X86::BI__builtin_ia32_storedqudi256_mask:
14692 case X86::BI__builtin_ia32_storedqusi256_mask:
14693 case X86::BI__builtin_ia32_storedquhi256_mask:
14694 case X86::BI__builtin_ia32_storedquqi256_mask:
14695 case X86::BI__builtin_ia32_storeupd256_mask:
14696 case X86::BI__builtin_ia32_storeups256_mask:
14697 case X86::BI__builtin_ia32_storedqudi512_mask:
14698 case X86::BI__builtin_ia32_storedqusi512_mask:
14699 case X86::BI__builtin_ia32_storedquhi512_mask:
14700 case X86::BI__builtin_ia32_storedquqi512_mask:
14701 case X86::BI__builtin_ia32_storeupd512_mask:
14702 case X86::BI__builtin_ia32_storeups512_mask:
14705 case X86::BI__builtin_ia32_storesh128_mask:
14706 case X86::BI__builtin_ia32_storess128_mask:
14707 case X86::BI__builtin_ia32_storesd128_mask:
14710 case X86::BI__builtin_ia32_vpopcntb_128:
14711 case X86::BI__builtin_ia32_vpopcntd_128:
14712 case X86::BI__builtin_ia32_vpopcntq_128:
14713 case X86::BI__builtin_ia32_vpopcntw_128:
14714 case X86::BI__builtin_ia32_vpopcntb_256:
14715 case X86::BI__builtin_ia32_vpopcntd_256:
14716 case X86::BI__builtin_ia32_vpopcntq_256:
14717 case X86::BI__builtin_ia32_vpopcntw_256:
14718 case X86::BI__builtin_ia32_vpopcntb_512:
14719 case X86::BI__builtin_ia32_vpopcntd_512:
14720 case X86::BI__builtin_ia32_vpopcntq_512:
14721 case X86::BI__builtin_ia32_vpopcntw_512: {
14724 return Builder.CreateCall(F, Ops);
14726 case X86::BI__builtin_ia32_cvtmask2b128:
14727 case X86::BI__builtin_ia32_cvtmask2b256:
14728 case X86::BI__builtin_ia32_cvtmask2b512:
14729 case X86::BI__builtin_ia32_cvtmask2w128:
14730 case X86::BI__builtin_ia32_cvtmask2w256:
14731 case X86::BI__builtin_ia32_cvtmask2w512:
14732 case X86::BI__builtin_ia32_cvtmask2d128:
14733 case X86::BI__builtin_ia32_cvtmask2d256:
14734 case X86::BI__builtin_ia32_cvtmask2d512:
14735 case X86::BI__builtin_ia32_cvtmask2q128:
14736 case X86::BI__builtin_ia32_cvtmask2q256:
14737 case X86::BI__builtin_ia32_cvtmask2q512:
14740 case X86::BI__builtin_ia32_cvtb2mask128:
14741 case X86::BI__builtin_ia32_cvtb2mask256:
14742 case X86::BI__builtin_ia32_cvtb2mask512:
14743 case X86::BI__builtin_ia32_cvtw2mask128:
14744 case X86::BI__builtin_ia32_cvtw2mask256:
14745 case X86::BI__builtin_ia32_cvtw2mask512:
14746 case X86::BI__builtin_ia32_cvtd2mask128:
14747 case X86::BI__builtin_ia32_cvtd2mask256:
14748 case X86::BI__builtin_ia32_cvtd2mask512:
14749 case X86::BI__builtin_ia32_cvtq2mask128:
14750 case X86::BI__builtin_ia32_cvtq2mask256:
14751 case X86::BI__builtin_ia32_cvtq2mask512:
14754 case X86::BI__builtin_ia32_cvtdq2ps512_mask:
14755 case X86::BI__builtin_ia32_cvtqq2ps512_mask:
14756 case X86::BI__builtin_ia32_cvtqq2pd512_mask:
14757 case X86::BI__builtin_ia32_vcvtw2ph512_mask:
14758 case X86::BI__builtin_ia32_vcvtdq2ph512_mask:
14759 case X86::BI__builtin_ia32_vcvtqq2ph512_mask:
14760 case X86::BI__builtin_ia32_vcvtdq2ph256_round_mask:
14761 case X86::BI__builtin_ia32_vcvtdq2ps256_round_mask:
14762 case X86::BI__builtin_ia32_vcvtqq2pd256_round_mask:
14763 case X86::BI__builtin_ia32_vcvtqq2ph256_round_mask:
14764 case X86::BI__builtin_ia32_vcvtqq2ps256_round_mask:
14765 case X86::BI__builtin_ia32_vcvtw2ph256_round_mask:
14767 case X86::BI__builtin_ia32_cvtudq2ps512_mask:
14768 case X86::BI__builtin_ia32_cvtuqq2ps512_mask:
14769 case X86::BI__builtin_ia32_cvtuqq2pd512_mask:
14770 case X86::BI__builtin_ia32_vcvtuw2ph512_mask:
14771 case X86::BI__builtin_ia32_vcvtudq2ph512_mask:
14772 case X86::BI__builtin_ia32_vcvtuqq2ph512_mask:
14773 case X86::BI__builtin_ia32_vcvtudq2ph256_round_mask:
14774 case X86::BI__builtin_ia32_vcvtudq2ps256_round_mask:
14775 case X86::BI__builtin_ia32_vcvtuqq2pd256_round_mask:
14776 case X86::BI__builtin_ia32_vcvtuqq2ph256_round_mask:
14777 case X86::BI__builtin_ia32_vcvtuqq2ps256_round_mask:
14778 case X86::BI__builtin_ia32_vcvtuw2ph256_round_mask:
14781 case X86::BI__builtin_ia32_vfmaddss3:
14782 case X86::BI__builtin_ia32_vfmaddsd3:
14783 case X86::BI__builtin_ia32_vfmaddsh3_mask:
14784 case X86::BI__builtin_ia32_vfmaddss3_mask:
14785 case X86::BI__builtin_ia32_vfmaddsd3_mask:
14787 case X86::BI__builtin_ia32_vfmaddss:
14788 case X86::BI__builtin_ia32_vfmaddsd:
14790 Constant::getNullValue(Ops[0]->getType()));
14791 case X86::BI__builtin_ia32_vfmaddsh3_maskz:
14792 case X86::BI__builtin_ia32_vfmaddss3_maskz:
14793 case X86::BI__builtin_ia32_vfmaddsd3_maskz:
14795 case X86::BI__builtin_ia32_vfmaddsh3_mask3:
14796 case X86::BI__builtin_ia32_vfmaddss3_mask3:
14797 case X86::BI__builtin_ia32_vfmaddsd3_mask3:
14799 case X86::BI__builtin_ia32_vfmsubsh3_mask3:
14800 case X86::BI__builtin_ia32_vfmsubss3_mask3:
14801 case X86::BI__builtin_ia32_vfmsubsd3_mask3:
14804 case X86::BI__builtin_ia32_vfmaddph:
14805 case X86::BI__builtin_ia32_vfmaddps:
14806 case X86::BI__builtin_ia32_vfmaddpd:
14807 case X86::BI__builtin_ia32_vfmaddph256:
14808 case X86::BI__builtin_ia32_vfmaddps256:
14809 case X86::BI__builtin_ia32_vfmaddpd256:
14810 case X86::BI__builtin_ia32_vfmaddph512_mask:
14811 case X86::BI__builtin_ia32_vfmaddph512_maskz:
14812 case X86::BI__builtin_ia32_vfmaddph512_mask3:
14813 case X86::BI__builtin_ia32_vfmaddps512_mask:
14814 case X86::BI__builtin_ia32_vfmaddps512_maskz:
14815 case X86::BI__builtin_ia32_vfmaddps512_mask3:
14816 case X86::BI__builtin_ia32_vfmsubps512_mask3:
14817 case X86::BI__builtin_ia32_vfmaddpd512_mask:
14818 case X86::BI__builtin_ia32_vfmaddpd512_maskz:
14819 case X86::BI__builtin_ia32_vfmaddpd512_mask3:
14820 case X86::BI__builtin_ia32_vfmsubpd512_mask3:
14821 case X86::BI__builtin_ia32_vfmsubph512_mask3:
14822 case X86::BI__builtin_ia32_vfmaddph256_round_mask:
14823 case X86::BI__builtin_ia32_vfmaddph256_round_maskz:
14824 case X86::BI__builtin_ia32_vfmaddph256_round_mask3:
14825 case X86::BI__builtin_ia32_vfmaddps256_round_mask:
14826 case X86::BI__builtin_ia32_vfmaddps256_round_maskz:
14827 case X86::BI__builtin_ia32_vfmaddps256_round_mask3:
14828 case X86::BI__builtin_ia32_vfmsubps256_round_mask3:
14829 case X86::BI__builtin_ia32_vfmaddpd256_round_mask:
14830 case X86::BI__builtin_ia32_vfmaddpd256_round_maskz:
14831 case X86::BI__builtin_ia32_vfmaddpd256_round_mask3:
14832 case X86::BI__builtin_ia32_vfmsubpd256_round_mask3:
14833 case X86::BI__builtin_ia32_vfmsubph256_round_mask3:
14835 case X86::BI__builtin_ia32_vfmaddsubph512_mask:
14836 case X86::BI__builtin_ia32_vfmaddsubph512_maskz:
14837 case X86::BI__builtin_ia32_vfmaddsubph512_mask3:
14838 case X86::BI__builtin_ia32_vfmsubaddph512_mask3:
14839 case X86::BI__builtin_ia32_vfmaddsubps512_mask:
14840 case X86::BI__builtin_ia32_vfmaddsubps512_maskz:
14841 case X86::BI__builtin_ia32_vfmaddsubps512_mask3:
14842 case X86::BI__builtin_ia32_vfmsubaddps512_mask3:
14843 case X86::BI__builtin_ia32_vfmaddsubpd512_mask:
14844 case X86::BI__builtin_ia32_vfmaddsubpd512_maskz:
14845 case X86::BI__builtin_ia32_vfmaddsubpd512_mask3:
14846 case X86::BI__builtin_ia32_vfmsubaddpd512_mask3:
14847 case X86::BI__builtin_ia32_vfmaddsubph256_round_mask:
14848 case X86::BI__builtin_ia32_vfmaddsubph256_round_maskz:
14849 case X86::BI__builtin_ia32_vfmaddsubph256_round_mask3:
14850 case X86::BI__builtin_ia32_vfmsubaddph256_round_mask3:
14851 case X86::BI__builtin_ia32_vfmaddsubps256_round_mask:
14852 case X86::BI__builtin_ia32_vfmaddsubps256_round_maskz:
14853 case X86::BI__builtin_ia32_vfmaddsubps256_round_mask3:
14854 case X86::BI__builtin_ia32_vfmsubaddps256_round_mask3:
14855 case X86::BI__builtin_ia32_vfmaddsubpd256_round_mask:
14856 case X86::BI__builtin_ia32_vfmaddsubpd256_round_maskz:
14857 case X86::BI__builtin_ia32_vfmaddsubpd256_round_mask3:
14858 case X86::BI__builtin_ia32_vfmsubaddpd256_round_mask3:
14861 case X86::BI__builtin_ia32_movdqa32store128_mask:
14862 case X86::BI__builtin_ia32_movdqa64store128_mask:
14863 case X86::BI__builtin_ia32_storeaps128_mask:
14864 case X86::BI__builtin_ia32_storeapd128_mask:
14865 case X86::BI__builtin_ia32_movdqa32store256_mask:
14866 case X86::BI__builtin_ia32_movdqa64store256_mask:
14867 case X86::BI__builtin_ia32_storeaps256_mask:
14868 case X86::BI__builtin_ia32_storeapd256_mask:
14869 case X86::BI__builtin_ia32_movdqa32store512_mask:
14870 case X86::BI__builtin_ia32_movdqa64store512_mask:
14871 case X86::BI__builtin_ia32_storeaps512_mask:
14872 case X86::BI__builtin_ia32_storeapd512_mask:
14877 case X86::BI__builtin_ia32_loadups128_mask:
14878 case X86::BI__builtin_ia32_loadups256_mask:
14879 case X86::BI__builtin_ia32_loadups512_mask:
14880 case X86::BI__builtin_ia32_loadupd128_mask:
14881 case X86::BI__builtin_ia32_loadupd256_mask:
14882 case X86::BI__builtin_ia32_loadupd512_mask:
14883 case X86::BI__builtin_ia32_loaddquqi128_mask:
14884 case X86::BI__builtin_ia32_loaddquqi256_mask:
14885 case X86::BI__builtin_ia32_loaddquqi512_mask:
14886 case X86::BI__builtin_ia32_loaddquhi128_mask:
14887 case X86::BI__builtin_ia32_loaddquhi256_mask:
14888 case X86::BI__builtin_ia32_loaddquhi512_mask:
14889 case X86::BI__builtin_ia32_loaddqusi128_mask:
14890 case X86::BI__builtin_ia32_loaddqusi256_mask:
14891 case X86::BI__builtin_ia32_loaddqusi512_mask:
14892 case X86::BI__builtin_ia32_loaddqudi128_mask:
14893 case X86::BI__builtin_ia32_loaddqudi256_mask:
14894 case X86::BI__builtin_ia32_loaddqudi512_mask:
14897 case X86::BI__builtin_ia32_loadsh128_mask:
14898 case X86::BI__builtin_ia32_loadss128_mask:
14899 case X86::BI__builtin_ia32_loadsd128_mask:
14902 case X86::BI__builtin_ia32_loadaps128_mask:
14903 case X86::BI__builtin_ia32_loadaps256_mask:
14904 case X86::BI__builtin_ia32_loadaps512_mask:
14905 case X86::BI__builtin_ia32_loadapd128_mask:
14906 case X86::BI__builtin_ia32_loadapd256_mask:
14907 case X86::BI__builtin_ia32_loadapd512_mask:
14908 case X86::BI__builtin_ia32_movdqa32load128_mask:
14909 case X86::BI__builtin_ia32_movdqa32load256_mask:
14910 case X86::BI__builtin_ia32_movdqa32load512_mask:
14911 case X86::BI__builtin_ia32_movdqa64load128_mask:
14912 case X86::BI__builtin_ia32_movdqa64load256_mask:
14913 case X86::BI__builtin_ia32_movdqa64load512_mask:
14918 case X86::BI__builtin_ia32_expandloaddf128_mask:
14919 case X86::BI__builtin_ia32_expandloaddf256_mask:
14920 case X86::BI__builtin_ia32_expandloaddf512_mask:
14921 case X86::BI__builtin_ia32_expandloadsf128_mask:
14922 case X86::BI__builtin_ia32_expandloadsf256_mask:
14923 case X86::BI__builtin_ia32_expandloadsf512_mask:
14924 case X86::BI__builtin_ia32_expandloaddi128_mask:
14925 case X86::BI__builtin_ia32_expandloaddi256_mask:
14926 case X86::BI__builtin_ia32_expandloaddi512_mask:
14927 case X86::BI__builtin_ia32_expandloadsi128_mask:
14928 case X86::BI__builtin_ia32_expandloadsi256_mask:
14929 case X86::BI__builtin_ia32_expandloadsi512_mask:
14930 case X86::BI__builtin_ia32_expandloadhi128_mask:
14931 case X86::BI__builtin_ia32_expandloadhi256_mask:
14932 case X86::BI__builtin_ia32_expandloadhi512_mask:
14933 case X86::BI__builtin_ia32_expandloadqi128_mask:
14934 case X86::BI__builtin_ia32_expandloadqi256_mask:
14935 case X86::BI__builtin_ia32_expandloadqi512_mask:
14938 case X86::BI__builtin_ia32_compressstoredf128_mask:
14939 case X86::BI__builtin_ia32_compressstoredf256_mask:
14940 case X86::BI__builtin_ia32_compressstoredf512_mask:
14941 case X86::BI__builtin_ia32_compressstoresf128_mask:
14942 case X86::BI__builtin_ia32_compressstoresf256_mask:
14943 case X86::BI__builtin_ia32_compressstoresf512_mask:
14944 case X86::BI__builtin_ia32_compressstoredi128_mask:
14945 case X86::BI__builtin_ia32_compressstoredi256_mask:
14946 case X86::BI__builtin_ia32_compressstoredi512_mask:
14947 case X86::BI__builtin_ia32_compressstoresi128_mask:
14948 case X86::BI__builtin_ia32_compressstoresi256_mask:
14949 case X86::BI__builtin_ia32_compressstoresi512_mask:
14950 case X86::BI__builtin_ia32_compressstorehi128_mask:
14951 case X86::BI__builtin_ia32_compressstorehi256_mask:
14952 case X86::BI__builtin_ia32_compressstorehi512_mask:
14953 case X86::BI__builtin_ia32_compressstoreqi128_mask:
14954 case X86::BI__builtin_ia32_compressstoreqi256_mask:
14955 case X86::BI__builtin_ia32_compressstoreqi512_mask:
14958 case X86::BI__builtin_ia32_expanddf128_mask:
14959 case X86::BI__builtin_ia32_expanddf256_mask:
14960 case X86::BI__builtin_ia32_expanddf512_mask:
14961 case X86::BI__builtin_ia32_expandsf128_mask:
14962 case X86::BI__builtin_ia32_expandsf256_mask:
14963 case X86::BI__builtin_ia32_expandsf512_mask:
14964 case X86::BI__builtin_ia32_expanddi128_mask:
14965 case X86::BI__builtin_ia32_expanddi256_mask:
14966 case X86::BI__builtin_ia32_expanddi512_mask:
14967 case X86::BI__builtin_ia32_expandsi128_mask:
14968 case X86::BI__builtin_ia32_expandsi256_mask:
14969 case X86::BI__builtin_ia32_expandsi512_mask:
14970 case X86::BI__builtin_ia32_expandhi128_mask:
14971 case X86::BI__builtin_ia32_expandhi256_mask:
14972 case X86::BI__builtin_ia32_expandhi512_mask:
14973 case X86::BI__builtin_ia32_expandqi128_mask:
14974 case X86::BI__builtin_ia32_expandqi256_mask:
14975 case X86::BI__builtin_ia32_expandqi512_mask:
14978 case X86::BI__builtin_ia32_compressdf128_mask:
14979 case X86::BI__builtin_ia32_compressdf256_mask:
14980 case X86::BI__builtin_ia32_compressdf512_mask:
14981 case X86::BI__builtin_ia32_compresssf128_mask:
14982 case X86::BI__builtin_ia32_compresssf256_mask:
14983 case X86::BI__builtin_ia32_compresssf512_mask:
14984 case X86::BI__builtin_ia32_compressdi128_mask:
14985 case X86::BI__builtin_ia32_compressdi256_mask:
14986 case X86::BI__builtin_ia32_compressdi512_mask:
14987 case X86::BI__builtin_ia32_compresssi128_mask:
14988 case X86::BI__builtin_ia32_compresssi256_mask:
14989 case X86::BI__builtin_ia32_compresssi512_mask:
14990 case X86::BI__builtin_ia32_compresshi128_mask:
14991 case X86::BI__builtin_ia32_compresshi256_mask:
14992 case X86::BI__builtin_ia32_compresshi512_mask:
14993 case X86::BI__builtin_ia32_compressqi128_mask:
14994 case X86::BI__builtin_ia32_compressqi256_mask:
14995 case X86::BI__builtin_ia32_compressqi512_mask:
14998 case X86::BI__builtin_ia32_gather3div2df:
14999 case X86::BI__builtin_ia32_gather3div2di:
15000 case X86::BI__builtin_ia32_gather3div4df:
15001 case X86::BI__builtin_ia32_gather3div4di:
15002 case X86::BI__builtin_ia32_gather3div4sf:
15003 case X86::BI__builtin_ia32_gather3div4si:
15004 case X86::BI__builtin_ia32_gather3div8sf:
15005 case X86::BI__builtin_ia32_gather3div8si:
15006 case X86::BI__builtin_ia32_gather3siv2df:
15007 case X86::BI__builtin_ia32_gather3siv2di:
15008 case X86::BI__builtin_ia32_gather3siv4df:
15009 case X86::BI__builtin_ia32_gather3siv4di:
15010 case X86::BI__builtin_ia32_gather3siv4sf:
15011 case X86::BI__builtin_ia32_gather3siv4si:
15012 case X86::BI__builtin_ia32_gather3siv8sf:
15013 case X86::BI__builtin_ia32_gather3siv8si:
15014 case X86::BI__builtin_ia32_gathersiv8df:
15015 case X86::BI__builtin_ia32_gathersiv16sf:
15016 case X86::BI__builtin_ia32_gatherdiv8df:
15017 case X86::BI__builtin_ia32_gatherdiv16sf:
15018 case X86::BI__builtin_ia32_gathersiv8di:
15019 case X86::BI__builtin_ia32_gathersiv16si:
15020 case X86::BI__builtin_ia32_gatherdiv8di:
15021 case X86::BI__builtin_ia32_gatherdiv16si: {
15023 switch (BuiltinID) {
15024 default: llvm_unreachable(
"Unexpected builtin");
15025 case X86::BI__builtin_ia32_gather3div2df:
15026 IID = Intrinsic::x86_avx512_mask_gather3div2_df;
15028 case X86::BI__builtin_ia32_gather3div2di:
15029 IID = Intrinsic::x86_avx512_mask_gather3div2_di;
15031 case X86::BI__builtin_ia32_gather3div4df:
15032 IID = Intrinsic::x86_avx512_mask_gather3div4_df;
15034 case X86::BI__builtin_ia32_gather3div4di:
15035 IID = Intrinsic::x86_avx512_mask_gather3div4_di;
15037 case X86::BI__builtin_ia32_gather3div4sf:
15038 IID = Intrinsic::x86_avx512_mask_gather3div4_sf;
15040 case X86::BI__builtin_ia32_gather3div4si:
15041 IID = Intrinsic::x86_avx512_mask_gather3div4_si;
15043 case X86::BI__builtin_ia32_gather3div8sf:
15044 IID = Intrinsic::x86_avx512_mask_gather3div8_sf;
15046 case X86::BI__builtin_ia32_gather3div8si:
15047 IID = Intrinsic::x86_avx512_mask_gather3div8_si;
15049 case X86::BI__builtin_ia32_gather3siv2df:
15050 IID = Intrinsic::x86_avx512_mask_gather3siv2_df;
15052 case X86::BI__builtin_ia32_gather3siv2di:
15053 IID = Intrinsic::x86_avx512_mask_gather3siv2_di;
15055 case X86::BI__builtin_ia32_gather3siv4df:
15056 IID = Intrinsic::x86_avx512_mask_gather3siv4_df;
15058 case X86::BI__builtin_ia32_gather3siv4di:
15059 IID = Intrinsic::x86_avx512_mask_gather3siv4_di;
15061 case X86::BI__builtin_ia32_gather3siv4sf:
15062 IID = Intrinsic::x86_avx512_mask_gather3siv4_sf;
15064 case X86::BI__builtin_ia32_gather3siv4si:
15065 IID = Intrinsic::x86_avx512_mask_gather3siv4_si;
15067 case X86::BI__builtin_ia32_gather3siv8sf:
15068 IID = Intrinsic::x86_avx512_mask_gather3siv8_sf;
15070 case X86::BI__builtin_ia32_gather3siv8si:
15071 IID = Intrinsic::x86_avx512_mask_gather3siv8_si;
15073 case X86::BI__builtin_ia32_gathersiv8df:
15074 IID = Intrinsic::x86_avx512_mask_gather_dpd_512;
15076 case X86::BI__builtin_ia32_gathersiv16sf:
15077 IID = Intrinsic::x86_avx512_mask_gather_dps_512;
15079 case X86::BI__builtin_ia32_gatherdiv8df:
15080 IID = Intrinsic::x86_avx512_mask_gather_qpd_512;
15082 case X86::BI__builtin_ia32_gatherdiv16sf:
15083 IID = Intrinsic::x86_avx512_mask_gather_qps_512;
15085 case X86::BI__builtin_ia32_gathersiv8di:
15086 IID = Intrinsic::x86_avx512_mask_gather_dpq_512;
15088 case X86::BI__builtin_ia32_gathersiv16si:
15089 IID = Intrinsic::x86_avx512_mask_gather_dpi_512;
15091 case X86::BI__builtin_ia32_gatherdiv8di:
15092 IID = Intrinsic::x86_avx512_mask_gather_qpq_512;
15094 case X86::BI__builtin_ia32_gatherdiv16si:
15095 IID = Intrinsic::x86_avx512_mask_gather_qpi_512;
15099 unsigned MinElts = std::min(
15100 cast<llvm::FixedVectorType>(Ops[0]->getType())->getNumElements(),
15101 cast<llvm::FixedVectorType>(Ops[2]->getType())->getNumElements());
15104 return Builder.CreateCall(Intr, Ops);
15107 case X86::BI__builtin_ia32_scattersiv8df:
15108 case X86::BI__builtin_ia32_scattersiv16sf:
15109 case X86::BI__builtin_ia32_scatterdiv8df:
15110 case X86::BI__builtin_ia32_scatterdiv16sf:
15111 case X86::BI__builtin_ia32_scattersiv8di:
15112 case X86::BI__builtin_ia32_scattersiv16si:
15113 case X86::BI__builtin_ia32_scatterdiv8di:
15114 case X86::BI__builtin_ia32_scatterdiv16si:
15115 case X86::BI__builtin_ia32_scatterdiv2df:
15116 case X86::BI__builtin_ia32_scatterdiv2di:
15117 case X86::BI__builtin_ia32_scatterdiv4df:
15118 case X86::BI__builtin_ia32_scatterdiv4di:
15119 case X86::BI__builtin_ia32_scatterdiv4sf:
15120 case X86::BI__builtin_ia32_scatterdiv4si:
15121 case X86::BI__builtin_ia32_scatterdiv8sf:
15122 case X86::BI__builtin_ia32_scatterdiv8si:
15123 case X86::BI__builtin_ia32_scattersiv2df:
15124 case X86::BI__builtin_ia32_scattersiv2di:
15125 case X86::BI__builtin_ia32_scattersiv4df:
15126 case X86::BI__builtin_ia32_scattersiv4di:
15127 case X86::BI__builtin_ia32_scattersiv4sf:
15128 case X86::BI__builtin_ia32_scattersiv4si:
15129 case X86::BI__builtin_ia32_scattersiv8sf:
15130 case X86::BI__builtin_ia32_scattersiv8si: {
15132 switch (BuiltinID) {
15133 default: llvm_unreachable(
"Unexpected builtin");
15134 case X86::BI__builtin_ia32_scattersiv8df:
15135 IID = Intrinsic::x86_avx512_mask_scatter_dpd_512;
15137 case X86::BI__builtin_ia32_scattersiv16sf:
15138 IID = Intrinsic::x86_avx512_mask_scatter_dps_512;
15140 case X86::BI__builtin_ia32_scatterdiv8df:
15141 IID = Intrinsic::x86_avx512_mask_scatter_qpd_512;
15143 case X86::BI__builtin_ia32_scatterdiv16sf:
15144 IID = Intrinsic::x86_avx512_mask_scatter_qps_512;
15146 case X86::BI__builtin_ia32_scattersiv8di:
15147 IID = Intrinsic::x86_avx512_mask_scatter_dpq_512;
15149 case X86::BI__builtin_ia32_scattersiv16si:
15150 IID = Intrinsic::x86_avx512_mask_scatter_dpi_512;
15152 case X86::BI__builtin_ia32_scatterdiv8di:
15153 IID = Intrinsic::x86_avx512_mask_scatter_qpq_512;
15155 case X86::BI__builtin_ia32_scatterdiv16si:
15156 IID = Intrinsic::x86_avx512_mask_scatter_qpi_512;
15158 case X86::BI__builtin_ia32_scatterdiv2df:
15159 IID = Intrinsic::x86_avx512_mask_scatterdiv2_df;
15161 case X86::BI__builtin_ia32_scatterdiv2di:
15162 IID = Intrinsic::x86_avx512_mask_scatterdiv2_di;
15164 case X86::BI__builtin_ia32_scatterdiv4df:
15165 IID = Intrinsic::x86_avx512_mask_scatterdiv4_df;
15167 case X86::BI__builtin_ia32_scatterdiv4di:
15168 IID = Intrinsic::x86_avx512_mask_scatterdiv4_di;
15170 case X86::BI__builtin_ia32_scatterdiv4sf:
15171 IID = Intrinsic::x86_avx512_mask_scatterdiv4_sf;
15173 case X86::BI__builtin_ia32_scatterdiv4si:
15174 IID = Intrinsic::x86_avx512_mask_scatterdiv4_si;
15176 case X86::BI__builtin_ia32_scatterdiv8sf:
15177 IID = Intrinsic::x86_avx512_mask_scatterdiv8_sf;
15179 case X86::BI__builtin_ia32_scatterdiv8si:
15180 IID = Intrinsic::x86_avx512_mask_scatterdiv8_si;
15182 case X86::BI__builtin_ia32_scattersiv2df:
15183 IID = Intrinsic::x86_avx512_mask_scattersiv2_df;
15185 case X86::BI__builtin_ia32_scattersiv2di:
15186 IID = Intrinsic::x86_avx512_mask_scattersiv2_di;
15188 case X86::BI__builtin_ia32_scattersiv4df:
15189 IID = Intrinsic::x86_avx512_mask_scattersiv4_df;
15191 case X86::BI__builtin_ia32_scattersiv4di:
15192 IID = Intrinsic::x86_avx512_mask_scattersiv4_di;
15194 case X86::BI__builtin_ia32_scattersiv4sf:
15195 IID = Intrinsic::x86_avx512_mask_scattersiv4_sf;
15197 case X86::BI__builtin_ia32_scattersiv4si:
15198 IID = Intrinsic::x86_avx512_mask_scattersiv4_si;
15200 case X86::BI__builtin_ia32_scattersiv8sf:
15201 IID = Intrinsic::x86_avx512_mask_scattersiv8_sf;
15203 case X86::BI__builtin_ia32_scattersiv8si:
15204 IID = Intrinsic::x86_avx512_mask_scattersiv8_si;
15208 unsigned MinElts = std::min(
15209 cast<llvm::FixedVectorType>(Ops[2]->getType())->getNumElements(),
15210 cast<llvm::FixedVectorType>(Ops[3]->getType())->getNumElements());
15213 return Builder.CreateCall(Intr, Ops);
15216 case X86::BI__builtin_ia32_vextractf128_pd256:
15217 case X86::BI__builtin_ia32_vextractf128_ps256:
15218 case X86::BI__builtin_ia32_vextractf128_si256:
15219 case X86::BI__builtin_ia32_extract128i256:
15220 case X86::BI__builtin_ia32_extractf64x4_mask:
15221 case X86::BI__builtin_ia32_extractf32x4_mask:
15222 case X86::BI__builtin_ia32_extracti64x4_mask:
15223 case X86::BI__builtin_ia32_extracti32x4_mask:
15224 case X86::BI__builtin_ia32_extractf32x8_mask:
15225 case X86::BI__builtin_ia32_extracti32x8_mask:
15226 case X86::BI__builtin_ia32_extractf32x4_256_mask:
15227 case X86::BI__builtin_ia32_extracti32x4_256_mask:
15228 case X86::BI__builtin_ia32_extractf64x2_256_mask:
15229 case X86::BI__builtin_ia32_extracti64x2_256_mask:
15230 case X86::BI__builtin_ia32_extractf64x2_512_mask:
15231 case X86::BI__builtin_ia32_extracti64x2_512_mask: {
15233 unsigned NumElts = DstTy->getNumElements();
15234 unsigned SrcNumElts =
15235 cast<llvm::FixedVectorType>(Ops[0]->getType())->getNumElements();
15236 unsigned SubVectors = SrcNumElts / NumElts;
15237 unsigned Index = cast<ConstantInt>(Ops[1])->getZExtValue();
15238 assert(llvm::isPowerOf2_32(SubVectors) &&
"Expected power of 2 subvectors");
15239 Index &= SubVectors - 1;
15243 for (
unsigned i = 0; i != NumElts; ++i)
15244 Indices[i] = i + Index;
15249 if (Ops.size() == 4)
15254 case X86::BI__builtin_ia32_vinsertf128_pd256:
15255 case X86::BI__builtin_ia32_vinsertf128_ps256:
15256 case X86::BI__builtin_ia32_vinsertf128_si256:
15257 case X86::BI__builtin_ia32_insert128i256:
15258 case X86::BI__builtin_ia32_insertf64x4:
15259 case X86::BI__builtin_ia32_insertf32x4:
15260 case X86::BI__builtin_ia32_inserti64x4:
15261 case X86::BI__builtin_ia32_inserti32x4:
15262 case X86::BI__builtin_ia32_insertf32x8:
15263 case X86::BI__builtin_ia32_inserti32x8:
15264 case X86::BI__builtin_ia32_insertf32x4_256:
15265 case X86::BI__builtin_ia32_inserti32x4_256:
15266 case X86::BI__builtin_ia32_insertf64x2_256:
15267 case X86::BI__builtin_ia32_inserti64x2_256:
15268 case X86::BI__builtin_ia32_insertf64x2_512:
15269 case X86::BI__builtin_ia32_inserti64x2_512: {
15270 unsigned DstNumElts =
15271 cast<llvm::FixedVectorType>(Ops[0]->getType())->getNumElements();
15272 unsigned SrcNumElts =
15273 cast<llvm::FixedVectorType>(Ops[1]->getType())->getNumElements();
15274 unsigned SubVectors = DstNumElts / SrcNumElts;
15275 unsigned Index = cast<ConstantInt>(Ops[2])->getZExtValue();
15276 assert(llvm::isPowerOf2_32(SubVectors) &&
"Expected power of 2 subvectors");
15277 Index &= SubVectors - 1;
15278 Index *= SrcNumElts;
15281 for (
unsigned i = 0; i != DstNumElts; ++i)
15282 Indices[i] = (i >= SrcNumElts) ? SrcNumElts + (i % SrcNumElts) : i;
15285 Ops[1],
ArrayRef(Indices, DstNumElts),
"widen");
15287 for (
unsigned i = 0; i != DstNumElts; ++i) {
15288 if (i >= Index && i < (Index + SrcNumElts))
15289 Indices[i] = (i - Index) + DstNumElts;
15294 return Builder.CreateShuffleVector(Ops[0], Op1,
15295 ArrayRef(Indices, DstNumElts),
"insert");
15297 case X86::BI__builtin_ia32_pmovqd512_mask:
15298 case X86::BI__builtin_ia32_pmovwb512_mask: {
15299 Value *Res =
Builder.CreateTrunc(Ops[0], Ops[1]->getType());
15302 case X86::BI__builtin_ia32_pmovdb512_mask:
15303 case X86::BI__builtin_ia32_pmovdw512_mask:
15304 case X86::BI__builtin_ia32_pmovqw512_mask: {
15305 if (
const auto *
C = dyn_cast<Constant>(Ops[2]))
15306 if (
C->isAllOnesValue())
15307 return Builder.CreateTrunc(Ops[0], Ops[1]->getType());
15310 switch (BuiltinID) {
15311 default: llvm_unreachable(
"Unsupported intrinsic!");
15312 case X86::BI__builtin_ia32_pmovdb512_mask:
15313 IID = Intrinsic::x86_avx512_mask_pmov_db_512;
15315 case X86::BI__builtin_ia32_pmovdw512_mask:
15316 IID = Intrinsic::x86_avx512_mask_pmov_dw_512;
15318 case X86::BI__builtin_ia32_pmovqw512_mask:
15319 IID = Intrinsic::x86_avx512_mask_pmov_qw_512;
15324 return Builder.CreateCall(Intr, Ops);
15326 case X86::BI__builtin_ia32_pblendw128:
15327 case X86::BI__builtin_ia32_blendpd:
15328 case X86::BI__builtin_ia32_blendps:
15329 case X86::BI__builtin_ia32_blendpd256:
15330 case X86::BI__builtin_ia32_blendps256:
15331 case X86::BI__builtin_ia32_pblendw256:
15332 case X86::BI__builtin_ia32_pblendd128:
15333 case X86::BI__builtin_ia32_pblendd256: {
15335 cast<llvm::FixedVectorType>(Ops[0]->getType())->getNumElements();
15336 unsigned Imm = cast<llvm::ConstantInt>(Ops[2])->getZExtValue();
15341 for (
unsigned i = 0; i != NumElts; ++i)
15342 Indices[i] = ((Imm >> (i % 8)) & 0x1) ? NumElts + i : i;
15344 return Builder.CreateShuffleVector(Ops[0], Ops[1],
15345 ArrayRef(Indices, NumElts),
"blend");
15347 case X86::BI__builtin_ia32_pshuflw:
15348 case X86::BI__builtin_ia32_pshuflw256:
15349 case X86::BI__builtin_ia32_pshuflw512: {
15350 uint32_t Imm = cast<llvm::ConstantInt>(Ops[1])->getZExtValue();
15351 auto *Ty = cast<llvm::FixedVectorType>(Ops[0]->getType());
15352 unsigned NumElts = Ty->getNumElements();
15355 Imm = (Imm & 0xff) * 0x01010101;
15358 for (
unsigned l = 0; l != NumElts; l += 8) {
15359 for (
unsigned i = 0; i != 4; ++i) {
15360 Indices[l + i] = l + (Imm & 3);
15363 for (
unsigned i = 4; i != 8; ++i)
15364 Indices[l + i] = l + i;
15367 return Builder.CreateShuffleVector(Ops[0],
ArrayRef(Indices, NumElts),
15370 case X86::BI__builtin_ia32_pshufhw:
15371 case X86::BI__builtin_ia32_pshufhw256:
15372 case X86::BI__builtin_ia32_pshufhw512: {
15373 uint32_t Imm = cast<llvm::ConstantInt>(Ops[1])->getZExtValue();
15374 auto *Ty = cast<llvm::FixedVectorType>(Ops[0]->getType());
15375 unsigned NumElts = Ty->getNumElements();
15378 Imm = (Imm & 0xff) * 0x01010101;
15381 for (
unsigned l = 0; l != NumElts; l += 8) {
15382 for (
unsigned i = 0; i != 4; ++i)
15383 Indices[l + i] = l + i;
15384 for (
unsigned i = 4; i != 8; ++i) {
15385 Indices[l + i] = l + 4 + (Imm & 3);
15390 return Builder.CreateShuffleVector(Ops[0],
ArrayRef(Indices, NumElts),
15393 case X86::BI__builtin_ia32_pshufd:
15394 case X86::BI__builtin_ia32_pshufd256:
15395 case X86::BI__builtin_ia32_pshufd512:
15396 case X86::BI__builtin_ia32_vpermilpd:
15397 case X86::BI__builtin_ia32_vpermilps:
15398 case X86::BI__builtin_ia32_vpermilpd256:
15399 case X86::BI__builtin_ia32_vpermilps256:
15400 case X86::BI__builtin_ia32_vpermilpd512:
15401 case X86::BI__builtin_ia32_vpermilps512: {
15402 uint32_t Imm = cast<llvm::ConstantInt>(Ops[1])->getZExtValue();
15403 auto *Ty = cast<llvm::FixedVectorType>(Ops[0]->getType());
15404 unsigned NumElts = Ty->getNumElements();
15405 unsigned NumLanes = Ty->getPrimitiveSizeInBits() / 128;
15406 unsigned NumLaneElts = NumElts / NumLanes;
15409 Imm = (Imm & 0xff) * 0x01010101;
15412 for (
unsigned l = 0; l != NumElts; l += NumLaneElts) {
15413 for (
unsigned i = 0; i != NumLaneElts; ++i) {
15414 Indices[i + l] = (Imm % NumLaneElts) + l;
15415 Imm /= NumLaneElts;
15419 return Builder.CreateShuffleVector(Ops[0],
ArrayRef(Indices, NumElts),
15422 case X86::BI__builtin_ia32_shufpd:
15423 case X86::BI__builtin_ia32_shufpd256:
15424 case X86::BI__builtin_ia32_shufpd512:
15425 case X86::BI__builtin_ia32_shufps:
15426 case X86::BI__builtin_ia32_shufps256:
15427 case X86::BI__builtin_ia32_shufps512: {
15428 uint32_t Imm = cast<llvm::ConstantInt>(Ops[2])->getZExtValue();
15429 auto *Ty = cast<llvm::FixedVectorType>(Ops[0]->getType());
15430 unsigned NumElts = Ty->getNumElements();
15431 unsigned NumLanes = Ty->getPrimitiveSizeInBits() / 128;
15432 unsigned NumLaneElts = NumElts / NumLanes;
15435 Imm = (Imm & 0xff) * 0x01010101;
15438 for (
unsigned l = 0; l != NumElts; l += NumLaneElts) {
15439 for (
unsigned i = 0; i != NumLaneElts; ++i) {
15440 unsigned Index = Imm % NumLaneElts;
15441 Imm /= NumLaneElts;
15442 if (i >= (NumLaneElts / 2))
15444 Indices[l + i] = l + Index;
15448 return Builder.CreateShuffleVector(Ops[0], Ops[1],
15449 ArrayRef(Indices, NumElts),
"shufp");
15451 case X86::BI__builtin_ia32_permdi256:
15452 case X86::BI__builtin_ia32_permdf256:
15453 case X86::BI__builtin_ia32_permdi512:
15454 case X86::BI__builtin_ia32_permdf512: {
15455 unsigned Imm = cast<llvm::ConstantInt>(Ops[1])->getZExtValue();
15456 auto *Ty = cast<llvm::FixedVectorType>(Ops[0]->getType());
15457 unsigned NumElts = Ty->getNumElements();
15461 for (
unsigned l = 0; l != NumElts; l += 4)
15462 for (
unsigned i = 0; i != 4; ++i)
15463 Indices[l + i] = l + ((Imm >> (2 * i)) & 0x3);
15465 return Builder.CreateShuffleVector(Ops[0],
ArrayRef(Indices, NumElts),
15468 case X86::BI__builtin_ia32_palignr128:
15469 case X86::BI__builtin_ia32_palignr256:
15470 case X86::BI__builtin_ia32_palignr512: {
15471 unsigned ShiftVal = cast<llvm::ConstantInt>(Ops[2])->getZExtValue() & 0xff;
15474 cast<llvm::FixedVectorType>(Ops[0]->getType())->getNumElements();
15475 assert(NumElts % 16 == 0);
15479 if (ShiftVal >= 32)
15484 if (ShiftVal > 16) {
15487 Ops[0] = llvm::Constant::getNullValue(Ops[0]->getType());
15492 for (
unsigned l = 0; l != NumElts; l += 16) {
15493 for (
unsigned i = 0; i != 16; ++i) {
15494 unsigned Idx = ShiftVal + i;
15496 Idx += NumElts - 16;
15497 Indices[l + i] = Idx + l;
15501 return Builder.CreateShuffleVector(Ops[1], Ops[0],
15502 ArrayRef(Indices, NumElts),
"palignr");
15504 case X86::BI__builtin_ia32_alignd128:
15505 case X86::BI__builtin_ia32_alignd256:
15506 case X86::BI__builtin_ia32_alignd512:
15507 case X86::BI__builtin_ia32_alignq128:
15508 case X86::BI__builtin_ia32_alignq256:
15509 case X86::BI__builtin_ia32_alignq512: {
15511 cast<llvm::FixedVectorType>(Ops[0]->getType())->getNumElements();
15512 unsigned ShiftVal = cast<llvm::ConstantInt>(Ops[2])->getZExtValue() & 0xff;
15515 ShiftVal &= NumElts - 1;
15518 for (
unsigned i = 0; i != NumElts; ++i)
15519 Indices[i] = i + ShiftVal;
15521 return Builder.CreateShuffleVector(Ops[1], Ops[0],
15522 ArrayRef(Indices, NumElts),
"valign");
15524 case X86::BI__builtin_ia32_shuf_f32x4_256:
15525 case X86::BI__builtin_ia32_shuf_f64x2_256:
15526 case X86::BI__builtin_ia32_shuf_i32x4_256:
15527 case X86::BI__builtin_ia32_shuf_i64x2_256:
15528 case X86::BI__builtin_ia32_shuf_f32x4:
15529 case X86::BI__builtin_ia32_shuf_f64x2:
15530 case X86::BI__builtin_ia32_shuf_i32x4:
15531 case X86::BI__builtin_ia32_shuf_i64x2: {
15532 unsigned Imm = cast<llvm::ConstantInt>(Ops[2])->getZExtValue();
15533 auto *Ty = cast<llvm::FixedVectorType>(Ops[0]->getType());
15534 unsigned NumElts = Ty->getNumElements();
15535 unsigned NumLanes = Ty->getPrimitiveSizeInBits() == 512 ? 4 : 2;
15536 unsigned NumLaneElts = NumElts / NumLanes;
15539 for (
unsigned l = 0; l != NumElts; l += NumLaneElts) {
15540 unsigned Index = (Imm % NumLanes) * NumLaneElts;
15542 if (l >= (NumElts / 2))
15544 for (
unsigned i = 0; i != NumLaneElts; ++i) {
15545 Indices[l + i] = Index + i;
15549 return Builder.CreateShuffleVector(Ops[0], Ops[1],
15550 ArrayRef(Indices, NumElts),
"shuf");
15553 case X86::BI__builtin_ia32_vperm2f128_pd256:
15554 case X86::BI__builtin_ia32_vperm2f128_ps256:
15555 case X86::BI__builtin_ia32_vperm2f128_si256:
15556 case X86::BI__builtin_ia32_permti256: {
15557 unsigned Imm = cast<llvm::ConstantInt>(Ops[2])->getZExtValue();
15559 cast<llvm::FixedVectorType>(Ops[0]->getType())->getNumElements();
15568 for (
unsigned l = 0; l != 2; ++l) {
15570 if (Imm & (1 << ((l * 4) + 3)))
15571 OutOps[l] = llvm::ConstantAggregateZero::get(Ops[0]->getType());
15572 else if (Imm & (1 << ((l * 4) + 1)))
15573 OutOps[l] = Ops[1];
15575 OutOps[l] = Ops[0];
15577 for (
unsigned i = 0; i != NumElts/2; ++i) {
15579 unsigned Idx = (l * NumElts) + i;
15582 if (Imm & (1 << (l * 4)))
15584 Indices[(l * (NumElts/2)) + i] = Idx;
15588 return Builder.CreateShuffleVector(OutOps[0], OutOps[1],
15589 ArrayRef(Indices, NumElts),
"vperm");
15592 case X86::BI__builtin_ia32_pslldqi128_byteshift:
15593 case X86::BI__builtin_ia32_pslldqi256_byteshift:
15594 case X86::BI__builtin_ia32_pslldqi512_byteshift: {
15595 unsigned ShiftVal = cast<llvm::ConstantInt>(Ops[1])->getZExtValue() & 0xff;
15596 auto *ResultType = cast<llvm::FixedVectorType>(Ops[0]->getType());
15598 unsigned NumElts = ResultType->getNumElements() * 8;
15601 if (ShiftVal >= 16)
15602 return llvm::Constant::getNullValue(ResultType);
15606 for (
unsigned l = 0; l != NumElts; l += 16) {
15607 for (
unsigned i = 0; i != 16; ++i) {
15608 unsigned Idx = NumElts + i - ShiftVal;
15609 if (Idx < NumElts) Idx -= NumElts - 16;
15610 Indices[l + i] = Idx + l;
15614 auto *VecTy = llvm::FixedVectorType::get(
Int8Ty, NumElts);
15616 Value *
Zero = llvm::Constant::getNullValue(VecTy);
15618 Zero, Cast,
ArrayRef(Indices, NumElts),
"pslldq");
15619 return Builder.CreateBitCast(SV, Ops[0]->getType(),
"cast");
15621 case X86::BI__builtin_ia32_psrldqi128_byteshift:
15622 case X86::BI__builtin_ia32_psrldqi256_byteshift:
15623 case X86::BI__builtin_ia32_psrldqi512_byteshift: {
15624 unsigned ShiftVal = cast<llvm::ConstantInt>(Ops[1])->getZExtValue() & 0xff;
15625 auto *ResultType = cast<llvm::FixedVectorType>(Ops[0]->getType());
15627 unsigned NumElts = ResultType->getNumElements() * 8;
15630 if (ShiftVal >= 16)
15631 return llvm::Constant::getNullValue(ResultType);
15635 for (
unsigned l = 0; l != NumElts; l += 16) {
15636 for (
unsigned i = 0; i != 16; ++i) {
15637 unsigned Idx = i + ShiftVal;
15638 if (Idx >= 16) Idx += NumElts - 16;
15639 Indices[l + i] = Idx + l;
15643 auto *VecTy = llvm::FixedVectorType::get(
Int8Ty, NumElts);
15645 Value *
Zero = llvm::Constant::getNullValue(VecTy);
15647 Cast, Zero,
ArrayRef(Indices, NumElts),
"psrldq");
15648 return Builder.CreateBitCast(SV, ResultType,
"cast");
15650 case X86::BI__builtin_ia32_kshiftliqi:
15651 case X86::BI__builtin_ia32_kshiftlihi:
15652 case X86::BI__builtin_ia32_kshiftlisi:
15653 case X86::BI__builtin_ia32_kshiftlidi: {
15654 unsigned ShiftVal = cast<llvm::ConstantInt>(Ops[1])->getZExtValue() & 0xff;
15655 unsigned NumElts = Ops[0]->getType()->getIntegerBitWidth();
15657 if (ShiftVal >= NumElts)
15658 return llvm::Constant::getNullValue(Ops[0]->getType());
15663 for (
unsigned i = 0; i != NumElts; ++i)
15664 Indices[i] = NumElts + i - ShiftVal;
15666 Value *
Zero = llvm::Constant::getNullValue(
In->getType());
15668 Zero, In,
ArrayRef(Indices, NumElts),
"kshiftl");
15669 return Builder.CreateBitCast(SV, Ops[0]->getType());
15671 case X86::BI__builtin_ia32_kshiftriqi:
15672 case X86::BI__builtin_ia32_kshiftrihi:
15673 case X86::BI__builtin_ia32_kshiftrisi:
15674 case X86::BI__builtin_ia32_kshiftridi: {
15675 unsigned ShiftVal = cast<llvm::ConstantInt>(Ops[1])->getZExtValue() & 0xff;
15676 unsigned NumElts = Ops[0]->getType()->getIntegerBitWidth();
15678 if (ShiftVal >= NumElts)
15679 return llvm::Constant::getNullValue(Ops[0]->getType());
15684 for (
unsigned i = 0; i != NumElts; ++i)
15685 Indices[i] = i + ShiftVal;
15687 Value *
Zero = llvm::Constant::getNullValue(
In->getType());
15689 In, Zero,
ArrayRef(Indices, NumElts),
"kshiftr");
15690 return Builder.CreateBitCast(SV, Ops[0]->getType());
15692 case X86::BI__builtin_ia32_movnti:
15693 case X86::BI__builtin_ia32_movnti64:
15694 case X86::BI__builtin_ia32_movntsd:
15695 case X86::BI__builtin_ia32_movntss: {
15696 llvm::MDNode *
Node = llvm::MDNode::get(
15699 Value *Ptr = Ops[0];
15700 Value *Src = Ops[1];
15703 if (BuiltinID == X86::BI__builtin_ia32_movntsd ||
15704 BuiltinID == X86::BI__builtin_ia32_movntss)
15705 Src =
Builder.CreateExtractElement(Src, (uint64_t)0,
"extract");
15709 SI->setMetadata(llvm::LLVMContext::MD_nontemporal,
Node);
15710 SI->setAlignment(llvm::Align(1));
15714 case X86::BI__builtin_ia32_vprotb:
15715 case X86::BI__builtin_ia32_vprotw:
15716 case X86::BI__builtin_ia32_vprotd:
15717 case X86::BI__builtin_ia32_vprotq:
15718 case X86::BI__builtin_ia32_vprotbi:
15719 case X86::BI__builtin_ia32_vprotwi:
15720 case X86::BI__builtin_ia32_vprotdi:
15721 case X86::BI__builtin_ia32_vprotqi:
15722 case X86::BI__builtin_ia32_prold128:
15723 case X86::BI__builtin_ia32_prold256:
15724 case X86::BI__builtin_ia32_prold512:
15725 case X86::BI__builtin_ia32_prolq128:
15726 case X86::BI__builtin_ia32_prolq256:
15727 case X86::BI__builtin_ia32_prolq512:
15728 case X86::BI__builtin_ia32_prolvd128:
15729 case X86::BI__builtin_ia32_prolvd256:
15730 case X86::BI__builtin_ia32_prolvd512:
15731 case X86::BI__builtin_ia32_prolvq128:
15732 case X86::BI__builtin_ia32_prolvq256:
15733 case X86::BI__builtin_ia32_prolvq512:
15735 case X86::BI__builtin_ia32_prord128:
15736 case X86::BI__builtin_ia32_prord256:
15737 case X86::BI__builtin_ia32_prord512:
15738 case X86::BI__builtin_ia32_prorq128:
15739 case X86::BI__builtin_ia32_prorq256:
15740 case X86::BI__builtin_ia32_prorq512:
15741 case X86::BI__builtin_ia32_prorvd128:
15742 case X86::BI__builtin_ia32_prorvd256:
15743 case X86::BI__builtin_ia32_prorvd512:
15744 case X86::BI__builtin_ia32_prorvq128:
15745 case X86::BI__builtin_ia32_prorvq256:
15746 case X86::BI__builtin_ia32_prorvq512:
15748 case X86::BI__builtin_ia32_selectb_128:
15749 case X86::BI__builtin_ia32_selectb_256:
15750 case X86::BI__builtin_ia32_selectb_512:
15751 case X86::BI__builtin_ia32_selectw_128:
15752 case X86::BI__builtin_ia32_selectw_256:
15753 case X86::BI__builtin_ia32_selectw_512:
15754 case X86::BI__builtin_ia32_selectd_128:
15755 case X86::BI__builtin_ia32_selectd_256:
15756 case X86::BI__builtin_ia32_selectd_512:
15757 case X86::BI__builtin_ia32_selectq_128:
15758 case X86::BI__builtin_ia32_selectq_256:
15759 case X86::BI__builtin_ia32_selectq_512:
15760 case X86::BI__builtin_ia32_selectph_128:
15761 case X86::BI__builtin_ia32_selectph_256:
15762 case X86::BI__builtin_ia32_selectph_512:
15763 case X86::BI__builtin_ia32_selectpbf_128:
15764 case X86::BI__builtin_ia32_selectpbf_256:
15765 case X86::BI__builtin_ia32_selectpbf_512:
15766 case X86::BI__builtin_ia32_selectps_128:
15767 case X86::BI__builtin_ia32_selectps_256:
15768 case X86::BI__builtin_ia32_selectps_512:
15769 case X86::BI__builtin_ia32_selectpd_128:
15770 case X86::BI__builtin_ia32_selectpd_256:
15771 case X86::BI__builtin_ia32_selectpd_512:
15773 case X86::BI__builtin_ia32_selectsh_128:
15774 case X86::BI__builtin_ia32_selectsbf_128:
15775 case X86::BI__builtin_ia32_selectss_128:
15776 case X86::BI__builtin_ia32_selectsd_128: {
15777 Value *A =
Builder.CreateExtractElement(Ops[1], (uint64_t)0);
15778 Value *B =
Builder.CreateExtractElement(Ops[2], (uint64_t)0);
15780 return Builder.CreateInsertElement(Ops[1], A, (uint64_t)0);
15782 case X86::BI__builtin_ia32_cmpb128_mask:
15783 case X86::BI__builtin_ia32_cmpb256_mask:
15784 case X86::BI__builtin_ia32_cmpb512_mask:
15785 case X86::BI__builtin_ia32_cmpw128_mask:
15786 case X86::BI__builtin_ia32_cmpw256_mask:
15787 case X86::BI__builtin_ia32_cmpw512_mask:
15788 case X86::BI__builtin_ia32_cmpd128_mask:
15789 case X86::BI__builtin_ia32_cmpd256_mask:
15790 case X86::BI__builtin_ia32_cmpd512_mask:
15791 case X86::BI__builtin_ia32_cmpq128_mask:
15792 case X86::BI__builtin_ia32_cmpq256_mask:
15793 case X86::BI__builtin_ia32_cmpq512_mask: {
15794 unsigned CC = cast<llvm::ConstantInt>(Ops[2])->getZExtValue() & 0x7;
15797 case X86::BI__builtin_ia32_ucmpb128_mask:
15798 case X86::BI__builtin_ia32_ucmpb256_mask:
15799 case X86::BI__builtin_ia32_ucmpb512_mask:
15800 case X86::BI__builtin_ia32_ucmpw128_mask:
15801 case X86::BI__builtin_ia32_ucmpw256_mask:
15802 case X86::BI__builtin_ia32_ucmpw512_mask:
15803 case X86::BI__builtin_ia32_ucmpd128_mask:
15804 case X86::BI__builtin_ia32_ucmpd256_mask:
15805 case X86::BI__builtin_ia32_ucmpd512_mask:
15806 case X86::BI__builtin_ia32_ucmpq128_mask:
15807 case X86::BI__builtin_ia32_ucmpq256_mask:
15808 case X86::BI__builtin_ia32_ucmpq512_mask: {
15809 unsigned CC = cast<llvm::ConstantInt>(Ops[2])->getZExtValue() & 0x7;
15812 case X86::BI__builtin_ia32_vpcomb:
15813 case X86::BI__builtin_ia32_vpcomw:
15814 case X86::BI__builtin_ia32_vpcomd:
15815 case X86::BI__builtin_ia32_vpcomq:
15817 case X86::BI__builtin_ia32_vpcomub:
15818 case X86::BI__builtin_ia32_vpcomuw:
15819 case X86::BI__builtin_ia32_vpcomud:
15820 case X86::BI__builtin_ia32_vpcomuq:
15823 case X86::BI__builtin_ia32_kortestcqi:
15824 case X86::BI__builtin_ia32_kortestchi:
15825 case X86::BI__builtin_ia32_kortestcsi:
15826 case X86::BI__builtin_ia32_kortestcdi: {
15828 Value *
C = llvm::Constant::getAllOnesValue(Ops[0]->getType());
15832 case X86::BI__builtin_ia32_kortestzqi:
15833 case X86::BI__builtin_ia32_kortestzhi:
15834 case X86::BI__builtin_ia32_kortestzsi:
15835 case X86::BI__builtin_ia32_kortestzdi: {
15837 Value *
C = llvm::Constant::getNullValue(Ops[0]->getType());
15842 case X86::BI__builtin_ia32_ktestcqi:
15843 case X86::BI__builtin_ia32_ktestzqi:
15844 case X86::BI__builtin_ia32_ktestchi:
15845 case X86::BI__builtin_ia32_ktestzhi:
15846 case X86::BI__builtin_ia32_ktestcsi:
15847 case X86::BI__builtin_ia32_ktestzsi:
15848 case X86::BI__builtin_ia32_ktestcdi:
15849 case X86::BI__builtin_ia32_ktestzdi: {
15851 switch (BuiltinID) {
15852 default: llvm_unreachable(
"Unsupported intrinsic!");
15853 case X86::BI__builtin_ia32_ktestcqi:
15854 IID = Intrinsic::x86_avx512_ktestc_b;
15856 case X86::BI__builtin_ia32_ktestzqi:
15857 IID = Intrinsic::x86_avx512_ktestz_b;
15859 case X86::BI__builtin_ia32_ktestchi:
15860 IID = Intrinsic::x86_avx512_ktestc_w;
15862 case X86::BI__builtin_ia32_ktestzhi:
15863 IID = Intrinsic::x86_avx512_ktestz_w;
15865 case X86::BI__builtin_ia32_ktestcsi:
15866 IID = Intrinsic::x86_avx512_ktestc_d;
15868 case X86::BI__builtin_ia32_ktestzsi:
15869 IID = Intrinsic::x86_avx512_ktestz_d;
15871 case X86::BI__builtin_ia32_ktestcdi:
15872 IID = Intrinsic::x86_avx512_ktestc_q;
15874 case X86::BI__builtin_ia32_ktestzdi:
15875 IID = Intrinsic::x86_avx512_ktestz_q;
15879 unsigned NumElts = Ops[0]->getType()->getIntegerBitWidth();
15883 return Builder.CreateCall(Intr, {LHS, RHS});
15886 case X86::BI__builtin_ia32_kaddqi:
15887 case X86::BI__builtin_ia32_kaddhi:
15888 case X86::BI__builtin_ia32_kaddsi:
15889 case X86::BI__builtin_ia32_kadddi: {
15891 switch (BuiltinID) {
15892 default: llvm_unreachable(
"Unsupported intrinsic!");
15893 case X86::BI__builtin_ia32_kaddqi:
15894 IID = Intrinsic::x86_avx512_kadd_b;
15896 case X86::BI__builtin_ia32_kaddhi:
15897 IID = Intrinsic::x86_avx512_kadd_w;
15899 case X86::BI__builtin_ia32_kaddsi:
15900 IID = Intrinsic::x86_avx512_kadd_d;
15902 case X86::BI__builtin_ia32_kadddi:
15903 IID = Intrinsic::x86_avx512_kadd_q;
15907 unsigned NumElts = Ops[0]->getType()->getIntegerBitWidth();
15912 return Builder.CreateBitCast(Res, Ops[0]->getType());
15914 case X86::BI__builtin_ia32_kandqi:
15915 case X86::BI__builtin_ia32_kandhi:
15916 case X86::BI__builtin_ia32_kandsi:
15917 case X86::BI__builtin_ia32_kanddi:
15919 case X86::BI__builtin_ia32_kandnqi:
15920 case X86::BI__builtin_ia32_kandnhi:
15921 case X86::BI__builtin_ia32_kandnsi:
15922 case X86::BI__builtin_ia32_kandndi:
15924 case X86::BI__builtin_ia32_korqi:
15925 case X86::BI__builtin_ia32_korhi:
15926 case X86::BI__builtin_ia32_korsi:
15927 case X86::BI__builtin_ia32_kordi:
15929 case X86::BI__builtin_ia32_kxnorqi:
15930 case X86::BI__builtin_ia32_kxnorhi:
15931 case X86::BI__builtin_ia32_kxnorsi:
15932 case X86::BI__builtin_ia32_kxnordi:
15934 case X86::BI__builtin_ia32_kxorqi:
15935 case X86::BI__builtin_ia32_kxorhi:
15936 case X86::BI__builtin_ia32_kxorsi:
15937 case X86::BI__builtin_ia32_kxordi:
15939 case X86::BI__builtin_ia32_knotqi:
15940 case X86::BI__builtin_ia32_knothi:
15941 case X86::BI__builtin_ia32_knotsi:
15942 case X86::BI__builtin_ia32_knotdi: {
15943 unsigned NumElts = Ops[0]->getType()->getIntegerBitWidth();
15946 Ops[0]->getType());
15948 case X86::BI__builtin_ia32_kmovb:
15949 case X86::BI__builtin_ia32_kmovw:
15950 case X86::BI__builtin_ia32_kmovd:
15951 case X86::BI__builtin_ia32_kmovq: {
15955 unsigned NumElts = Ops[0]->getType()->getIntegerBitWidth();
15957 return Builder.CreateBitCast(Res, Ops[0]->getType());
15960 case X86::BI__builtin_ia32_kunpckdi:
15961 case X86::BI__builtin_ia32_kunpcksi:
15962 case X86::BI__builtin_ia32_kunpckhi: {
15963 unsigned NumElts = Ops[0]->getType()->getIntegerBitWidth();
15967 for (
unsigned i = 0; i != NumElts; ++i)
15972 LHS =
Builder.CreateShuffleVector(LHS, LHS,
ArrayRef(Indices, NumElts / 2));
15973 RHS =
Builder.CreateShuffleVector(RHS, RHS,
ArrayRef(Indices, NumElts / 2));
15978 return Builder.CreateBitCast(Res, Ops[0]->getType());
15981 case X86::BI__builtin_ia32_vplzcntd_128:
15982 case X86::BI__builtin_ia32_vplzcntd_256:
15983 case X86::BI__builtin_ia32_vplzcntd_512:
15984 case X86::BI__builtin_ia32_vplzcntq_128:
15985 case X86::BI__builtin_ia32_vplzcntq_256:
15986 case X86::BI__builtin_ia32_vplzcntq_512: {
15990 case X86::BI__builtin_ia32_sqrtss:
15991 case X86::BI__builtin_ia32_sqrtsd: {
15992 Value *A =
Builder.CreateExtractElement(Ops[0], (uint64_t)0);
15994 if (
Builder.getIsFPConstrained()) {
15995 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*
this,
E);
15998 A =
Builder.CreateConstrainedFPCall(F, {A});
16001 A =
Builder.CreateCall(F, {A});
16003 return Builder.CreateInsertElement(Ops[0], A, (uint64_t)0);
16005 case X86::BI__builtin_ia32_sqrtsh_round_mask:
16006 case X86::BI__builtin_ia32_sqrtsd_round_mask:
16007 case X86::BI__builtin_ia32_sqrtss_round_mask: {
16008 unsigned CC = cast<llvm::ConstantInt>(Ops[4])->getZExtValue();
16014 switch (BuiltinID) {
16016 llvm_unreachable(
"Unsupported intrinsic!");
16017 case X86::BI__builtin_ia32_sqrtsh_round_mask:
16018 IID = Intrinsic::x86_avx512fp16_mask_sqrt_sh;
16020 case X86::BI__builtin_ia32_sqrtsd_round_mask:
16021 IID = Intrinsic::x86_avx512_mask_sqrt_sd;
16023 case X86::BI__builtin_ia32_sqrtss_round_mask:
16024 IID = Intrinsic::x86_avx512_mask_sqrt_ss;
16029 Value *A =
Builder.CreateExtractElement(Ops[1], (uint64_t)0);
16031 if (
Builder.getIsFPConstrained()) {
16032 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*
this,
E);
16035 A =
Builder.CreateConstrainedFPCall(F, A);
16038 A =
Builder.CreateCall(F, A);
16040 Value *Src =
Builder.CreateExtractElement(Ops[2], (uint64_t)0);
16042 return Builder.CreateInsertElement(Ops[0], A, (uint64_t)0);
16044 case X86::BI__builtin_ia32_sqrtpd256:
16045 case X86::BI__builtin_ia32_sqrtpd:
16046 case X86::BI__builtin_ia32_sqrtps256:
16047 case X86::BI__builtin_ia32_sqrtps:
16048 case X86::BI__builtin_ia32_sqrtph256:
16049 case X86::BI__builtin_ia32_sqrtph:
16050 case X86::BI__builtin_ia32_sqrtph512:
16051 case X86::BI__builtin_ia32_sqrtps512:
16052 case X86::BI__builtin_ia32_sqrtpd512: {
16053 if (Ops.size() == 2) {
16054 unsigned CC = cast<llvm::ConstantInt>(Ops[1])->getZExtValue();
16060 switch (BuiltinID) {
16062 llvm_unreachable(
"Unsupported intrinsic!");
16063 case X86::BI__builtin_ia32_sqrtph512:
16064 IID = Intrinsic::x86_avx512fp16_sqrt_ph_512;
16066 case X86::BI__builtin_ia32_sqrtps512:
16067 IID = Intrinsic::x86_avx512_sqrt_ps_512;
16069 case X86::BI__builtin_ia32_sqrtpd512:
16070 IID = Intrinsic::x86_avx512_sqrt_pd_512;
16076 if (
Builder.getIsFPConstrained()) {
16077 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*
this,
E);
16079 Ops[0]->getType());
16080 return Builder.CreateConstrainedFPCall(F, Ops[0]);
16083 return Builder.CreateCall(F, Ops[0]);
16087 case X86::BI__builtin_ia32_pmuludq128:
16088 case X86::BI__builtin_ia32_pmuludq256:
16089 case X86::BI__builtin_ia32_pmuludq512:
16092 case X86::BI__builtin_ia32_pmuldq128:
16093 case X86::BI__builtin_ia32_pmuldq256:
16094 case X86::BI__builtin_ia32_pmuldq512:
16097 case X86::BI__builtin_ia32_pternlogd512_mask:
16098 case X86::BI__builtin_ia32_pternlogq512_mask:
16099 case X86::BI__builtin_ia32_pternlogd128_mask:
16100 case X86::BI__builtin_ia32_pternlogd256_mask:
16101 case X86::BI__builtin_ia32_pternlogq128_mask:
16102 case X86::BI__builtin_ia32_pternlogq256_mask:
16105 case X86::BI__builtin_ia32_pternlogd512_maskz:
16106 case X86::BI__builtin_ia32_pternlogq512_maskz:
16107 case X86::BI__builtin_ia32_pternlogd128_maskz:
16108 case X86::BI__builtin_ia32_pternlogd256_maskz:
16109 case X86::BI__builtin_ia32_pternlogq128_maskz:
16110 case X86::BI__builtin_ia32_pternlogq256_maskz:
16113 case X86::BI__builtin_ia32_vpshldd128:
16114 case X86::BI__builtin_ia32_vpshldd256:
16115 case X86::BI__builtin_ia32_vpshldd512:
16116 case X86::BI__builtin_ia32_vpshldq128:
16117 case X86::BI__builtin_ia32_vpshldq256:
16118 case X86::BI__builtin_ia32_vpshldq512:
16119 case X86::BI__builtin_ia32_vpshldw128:
16120 case X86::BI__builtin_ia32_vpshldw256:
16121 case X86::BI__builtin_ia32_vpshldw512:
16124 case X86::BI__builtin_ia32_vpshrdd128:
16125 case X86::BI__builtin_ia32_vpshrdd256:
16126 case X86::BI__builtin_ia32_vpshrdd512:
16127 case X86::BI__builtin_ia32_vpshrdq128:
16128 case X86::BI__builtin_ia32_vpshrdq256:
16129 case X86::BI__builtin_ia32_vpshrdq512:
16130 case X86::BI__builtin_ia32_vpshrdw128:
16131 case X86::BI__builtin_ia32_vpshrdw256:
16132 case X86::BI__builtin_ia32_vpshrdw512:
16136 case X86::BI__builtin_ia32_vpshldvd128:
16137 case X86::BI__builtin_ia32_vpshldvd256:
16138 case X86::BI__builtin_ia32_vpshldvd512:
16139 case X86::BI__builtin_ia32_vpshldvq128:
16140 case X86::BI__builtin_ia32_vpshldvq256:
16141 case X86::BI__builtin_ia32_vpshldvq512:
16142 case X86::BI__builtin_ia32_vpshldvw128:
16143 case X86::BI__builtin_ia32_vpshldvw256:
16144 case X86::BI__builtin_ia32_vpshldvw512:
16147 case X86::BI__builtin_ia32_vpshrdvd128:
16148 case X86::BI__builtin_ia32_vpshrdvd256:
16149 case X86::BI__builtin_ia32_vpshrdvd512:
16150 case X86::BI__builtin_ia32_vpshrdvq128:
16151 case X86::BI__builtin_ia32_vpshrdvq256:
16152 case X86::BI__builtin_ia32_vpshrdvq512:
16153 case X86::BI__builtin_ia32_vpshrdvw128:
16154 case X86::BI__builtin_ia32_vpshrdvw256:
16155 case X86::BI__builtin_ia32_vpshrdvw512:
16160 case X86::BI__builtin_ia32_reduce_fadd_pd512:
16161 case X86::BI__builtin_ia32_reduce_fadd_ps512:
16162 case X86::BI__builtin_ia32_reduce_fadd_ph512:
16163 case X86::BI__builtin_ia32_reduce_fadd_ph256:
16164 case X86::BI__builtin_ia32_reduce_fadd_ph128: {
16167 IRBuilder<>::FastMathFlagGuard FMFGuard(
Builder);
16168 Builder.getFastMathFlags().setAllowReassoc();
16169 return Builder.CreateCall(F, {Ops[0], Ops[1]});
16171 case X86::BI__builtin_ia32_reduce_fmul_pd512:
16172 case X86::BI__builtin_ia32_reduce_fmul_ps512:
16173 case X86::BI__builtin_ia32_reduce_fmul_ph512:
16174 case X86::BI__builtin_ia32_reduce_fmul_ph256:
16175 case X86::BI__builtin_ia32_reduce_fmul_ph128: {
16178 IRBuilder<>::FastMathFlagGuard FMFGuard(
Builder);
16179 Builder.getFastMathFlags().setAllowReassoc();
16180 return Builder.CreateCall(F, {Ops[0], Ops[1]});
16182 case X86::BI__builtin_ia32_reduce_fmax_pd512:
16183 case X86::BI__builtin_ia32_reduce_fmax_ps512:
16184 case X86::BI__builtin_ia32_reduce_fmax_ph512:
16185 case X86::BI__builtin_ia32_reduce_fmax_ph256:
16186 case X86::BI__builtin_ia32_reduce_fmax_ph128: {
16189 IRBuilder<>::FastMathFlagGuard FMFGuard(
Builder);
16190 Builder.getFastMathFlags().setNoNaNs();
16191 return Builder.CreateCall(F, {Ops[0]});
16193 case X86::BI__builtin_ia32_reduce_fmin_pd512:
16194 case X86::BI__builtin_ia32_reduce_fmin_ps512:
16195 case X86::BI__builtin_ia32_reduce_fmin_ph512:
16196 case X86::BI__builtin_ia32_reduce_fmin_ph256:
16197 case X86::BI__builtin_ia32_reduce_fmin_ph128: {
16200 IRBuilder<>::FastMathFlagGuard FMFGuard(
Builder);
16201 Builder.getFastMathFlags().setNoNaNs();
16202 return Builder.CreateCall(F, {Ops[0]});
16205 case X86::BI__builtin_ia32_rdrand16_step:
16206 case X86::BI__builtin_ia32_rdrand32_step:
16207 case X86::BI__builtin_ia32_rdrand64_step:
16208 case X86::BI__builtin_ia32_rdseed16_step:
16209 case X86::BI__builtin_ia32_rdseed32_step:
16210 case X86::BI__builtin_ia32_rdseed64_step: {
16212 switch (BuiltinID) {
16213 default: llvm_unreachable(
"Unsupported intrinsic!");
16214 case X86::BI__builtin_ia32_rdrand16_step:
16215 ID = Intrinsic::x86_rdrand_16;
16217 case X86::BI__builtin_ia32_rdrand32_step:
16218 ID = Intrinsic::x86_rdrand_32;
16220 case X86::BI__builtin_ia32_rdrand64_step:
16221 ID = Intrinsic::x86_rdrand_64;
16223 case X86::BI__builtin_ia32_rdseed16_step:
16224 ID = Intrinsic::x86_rdseed_16;
16226 case X86::BI__builtin_ia32_rdseed32_step:
16227 ID = Intrinsic::x86_rdseed_32;
16229 case X86::BI__builtin_ia32_rdseed64_step:
16230 ID = Intrinsic::x86_rdseed_64;
16239 case X86::BI__builtin_ia32_addcarryx_u32:
16240 case X86::BI__builtin_ia32_addcarryx_u64:
16241 case X86::BI__builtin_ia32_subborrow_u32:
16242 case X86::BI__builtin_ia32_subborrow_u64: {
16244 switch (BuiltinID) {
16245 default: llvm_unreachable(
"Unsupported intrinsic!");
16246 case X86::BI__builtin_ia32_addcarryx_u32:
16247 IID = Intrinsic::x86_addcarry_32;
16249 case X86::BI__builtin_ia32_addcarryx_u64:
16250 IID = Intrinsic::x86_addcarry_64;
16252 case X86::BI__builtin_ia32_subborrow_u32:
16253 IID = Intrinsic::x86_subborrow_32;
16255 case X86::BI__builtin_ia32_subborrow_u64:
16256 IID = Intrinsic::x86_subborrow_64;
16261 { Ops[0], Ops[1], Ops[2] });
16267 case X86::BI__builtin_ia32_fpclassps128_mask:
16268 case X86::BI__builtin_ia32_fpclassps256_mask:
16269 case X86::BI__builtin_ia32_fpclassps512_mask:
16270 case X86::BI__builtin_ia32_fpclassph128_mask:
16271 case X86::BI__builtin_ia32_fpclassph256_mask:
16272 case X86::BI__builtin_ia32_fpclassph512_mask:
16273 case X86::BI__builtin_ia32_fpclasspd128_mask:
16274 case X86::BI__builtin_ia32_fpclasspd256_mask:
16275 case X86::BI__builtin_ia32_fpclasspd512_mask: {
16277 cast<llvm::FixedVectorType>(Ops[0]->getType())->getNumElements();
16278 Value *MaskIn = Ops[2];
16279 Ops.erase(&Ops[2]);
16282 switch (BuiltinID) {
16283 default: llvm_unreachable(
"Unsupported intrinsic!");
16284 case X86::BI__builtin_ia32_fpclassph128_mask:
16285 ID = Intrinsic::x86_avx512fp16_fpclass_ph_128;
16287 case X86::BI__builtin_ia32_fpclassph256_mask:
16288 ID = Intrinsic::x86_avx512fp16_fpclass_ph_256;
16290 case X86::BI__builtin_ia32_fpclassph512_mask:
16291 ID = Intrinsic::x86_avx512fp16_fpclass_ph_512;
16293 case X86::BI__builtin_ia32_fpclassps128_mask:
16294 ID = Intrinsic::x86_avx512_fpclass_ps_128;
16296 case X86::BI__builtin_ia32_fpclassps256_mask:
16297 ID = Intrinsic::x86_avx512_fpclass_ps_256;
16299 case X86::BI__builtin_ia32_fpclassps512_mask:
16300 ID = Intrinsic::x86_avx512_fpclass_ps_512;
16302 case X86::BI__builtin_ia32_fpclasspd128_mask:
16303 ID = Intrinsic::x86_avx512_fpclass_pd_128;
16305 case X86::BI__builtin_ia32_fpclasspd256_mask:
16306 ID = Intrinsic::x86_avx512_fpclass_pd_256;
16308 case X86::BI__builtin_ia32_fpclasspd512_mask:
16309 ID = Intrinsic::x86_avx512_fpclass_pd_512;
16317 case X86::BI__builtin_ia32_vp2intersect_q_512:
16318 case X86::BI__builtin_ia32_vp2intersect_q_256:
16319 case X86::BI__builtin_ia32_vp2intersect_q_128:
16320 case X86::BI__builtin_ia32_vp2intersect_d_512:
16321 case X86::BI__builtin_ia32_vp2intersect_d_256:
16322 case X86::BI__builtin_ia32_vp2intersect_d_128: {
16324 cast<llvm::FixedVectorType>(Ops[0]->getType())->getNumElements();
16327 switch (BuiltinID) {
16328 default: llvm_unreachable(
"Unsupported intrinsic!");
16329 case X86::BI__builtin_ia32_vp2intersect_q_512:
16330 ID = Intrinsic::x86_avx512_vp2intersect_q_512;
16332 case X86::BI__builtin_ia32_vp2intersect_q_256:
16333 ID = Intrinsic::x86_avx512_vp2intersect_q_256;
16335 case X86::BI__builtin_ia32_vp2intersect_q_128:
16336 ID = Intrinsic::x86_avx512_vp2intersect_q_128;
16338 case X86::BI__builtin_ia32_vp2intersect_d_512:
16339 ID = Intrinsic::x86_avx512_vp2intersect_d_512;
16341 case X86::BI__builtin_ia32_vp2intersect_d_256:
16342 ID = Intrinsic::x86_avx512_vp2intersect_d_256;
16344 case X86::BI__builtin_ia32_vp2intersect_d_128:
16345 ID = Intrinsic::x86_avx512_vp2intersect_d_128;
16359 case X86::BI__builtin_ia32_vpmultishiftqb128:
16360 case X86::BI__builtin_ia32_vpmultishiftqb256:
16361 case X86::BI__builtin_ia32_vpmultishiftqb512: {
16363 switch (BuiltinID) {
16364 default: llvm_unreachable(
"Unsupported intrinsic!");
16365 case X86::BI__builtin_ia32_vpmultishiftqb128:
16366 ID = Intrinsic::x86_avx512_pmultishift_qb_128;
16368 case X86::BI__builtin_ia32_vpmultishiftqb256:
16369 ID = Intrinsic::x86_avx512_pmultishift_qb_256;
16371 case X86::BI__builtin_ia32_vpmultishiftqb512:
16372 ID = Intrinsic::x86_avx512_pmultishift_qb_512;
16379 case X86::BI__builtin_ia32_vpshufbitqmb128_mask:
16380 case X86::BI__builtin_ia32_vpshufbitqmb256_mask:
16381 case X86::BI__builtin_ia32_vpshufbitqmb512_mask: {
16383 cast<llvm::FixedVectorType>(Ops[0]->getType())->getNumElements();
16384 Value *MaskIn = Ops[2];
16385 Ops.erase(&Ops[2]);
16388 switch (BuiltinID) {
16389 default: llvm_unreachable(
"Unsupported intrinsic!");
16390 case X86::BI__builtin_ia32_vpshufbitqmb128_mask:
16391 ID = Intrinsic::x86_avx512_vpshufbitqmb_128;
16393 case X86::BI__builtin_ia32_vpshufbitqmb256_mask:
16394 ID = Intrinsic::x86_avx512_vpshufbitqmb_256;
16396 case X86::BI__builtin_ia32_vpshufbitqmb512_mask:
16397 ID = Intrinsic::x86_avx512_vpshufbitqmb_512;
16406 case X86::BI__builtin_ia32_cmpeqps:
16407 case X86::BI__builtin_ia32_cmpeqpd:
16408 return getVectorFCmpIR(CmpInst::FCMP_OEQ,
false);
16409 case X86::BI__builtin_ia32_cmpltps:
16410 case X86::BI__builtin_ia32_cmpltpd:
16411 return getVectorFCmpIR(CmpInst::FCMP_OLT,
true);
16412 case X86::BI__builtin_ia32_cmpleps:
16413 case X86::BI__builtin_ia32_cmplepd:
16414 return getVectorFCmpIR(CmpInst::FCMP_OLE,
true);
16415 case X86::BI__builtin_ia32_cmpunordps:
16416 case X86::BI__builtin_ia32_cmpunordpd:
16417 return getVectorFCmpIR(CmpInst::FCMP_UNO,
false);
16418 case X86::BI__builtin_ia32_cmpneqps:
16419 case X86::BI__builtin_ia32_cmpneqpd:
16420 return getVectorFCmpIR(CmpInst::FCMP_UNE,
false);
16421 case X86::BI__builtin_ia32_cmpnltps:
16422 case X86::BI__builtin_ia32_cmpnltpd:
16423 return getVectorFCmpIR(CmpInst::FCMP_UGE,
true);
16424 case X86::BI__builtin_ia32_cmpnleps:
16425 case X86::BI__builtin_ia32_cmpnlepd:
16426 return getVectorFCmpIR(CmpInst::FCMP_UGT,
true);
16427 case X86::BI__builtin_ia32_cmpordps:
16428 case X86::BI__builtin_ia32_cmpordpd:
16429 return getVectorFCmpIR(CmpInst::FCMP_ORD,
false);
16430 case X86::BI__builtin_ia32_cmpph128_mask:
16431 case X86::BI__builtin_ia32_cmpph256_mask:
16432 case X86::BI__builtin_ia32_cmpph512_mask:
16433 case X86::BI__builtin_ia32_cmpps128_mask:
16434 case X86::BI__builtin_ia32_cmpps256_mask:
16435 case X86::BI__builtin_ia32_cmpps512_mask:
16436 case X86::BI__builtin_ia32_cmppd128_mask:
16437 case X86::BI__builtin_ia32_cmppd256_mask:
16438 case X86::BI__builtin_ia32_cmppd512_mask:
16439 case X86::BI__builtin_ia32_vcmppd256_round_mask:
16440 case X86::BI__builtin_ia32_vcmpps256_round_mask:
16441 case X86::BI__builtin_ia32_vcmpph256_round_mask:
16444 case X86::BI__builtin_ia32_cmpps:
16445 case X86::BI__builtin_ia32_cmpps256:
16446 case X86::BI__builtin_ia32_cmppd:
16447 case X86::BI__builtin_ia32_cmppd256: {
16455 unsigned CC = cast<llvm::ConstantInt>(Ops[2])->getZExtValue() & 0x1f;
16460 FCmpInst::Predicate Pred;
16464 switch (CC & 0xf) {
16465 case 0x00: Pred = FCmpInst::FCMP_OEQ; IsSignaling =
false;
break;
16466 case 0x01: Pred = FCmpInst::FCMP_OLT; IsSignaling =
true;
break;
16467 case 0x02: Pred = FCmpInst::FCMP_OLE; IsSignaling =
true;
break;
16468 case 0x03: Pred = FCmpInst::FCMP_UNO; IsSignaling =
false;
break;
16469 case 0x04: Pred = FCmpInst::FCMP_UNE; IsSignaling =
false;
break;
16470 case 0x05: Pred = FCmpInst::FCMP_UGE; IsSignaling =
true;
break;
16471 case 0x06: Pred = FCmpInst::FCMP_UGT; IsSignaling =
true;
break;
16472 case 0x07: Pred = FCmpInst::FCMP_ORD; IsSignaling =
false;
break;
16473 case 0x08: Pred = FCmpInst::FCMP_UEQ; IsSignaling =
false;
break;
16474 case 0x09: Pred = FCmpInst::FCMP_ULT; IsSignaling =
true;
break;
16475 case 0x0a: Pred = FCmpInst::FCMP_ULE; IsSignaling =
true;
break;
16476 case 0x0b: Pred = FCmpInst::FCMP_FALSE; IsSignaling =
false;
break;
16477 case 0x0c: Pred = FCmpInst::FCMP_ONE; IsSignaling =
false;
break;
16478 case 0x0d: Pred = FCmpInst::FCMP_OGE; IsSignaling =
true;
break;
16479 case 0x0e: Pred = FCmpInst::FCMP_OGT; IsSignaling =
true;
break;
16480 case 0x0f: Pred = FCmpInst::FCMP_TRUE; IsSignaling =
false;
break;
16481 default: llvm_unreachable(
"Unhandled CC");
16486 IsSignaling = !IsSignaling;
16493 if (
Builder.getIsFPConstrained() &&
16494 (Pred == FCmpInst::FCMP_TRUE || Pred == FCmpInst::FCMP_FALSE ||
16498 switch (BuiltinID) {
16499 default: llvm_unreachable(
"Unexpected builtin");
16500 case X86::BI__builtin_ia32_cmpps:
16501 IID = Intrinsic::x86_sse_cmp_ps;
16503 case X86::BI__builtin_ia32_cmpps256:
16504 IID = Intrinsic::x86_avx_cmp_ps_256;
16506 case X86::BI__builtin_ia32_cmppd:
16507 IID = Intrinsic::x86_sse2_cmp_pd;
16509 case X86::BI__builtin_ia32_cmppd256:
16510 IID = Intrinsic::x86_avx_cmp_pd_256;
16512 case X86::BI__builtin_ia32_cmpph128_mask:
16513 IID = Intrinsic::x86_avx512fp16_mask_cmp_ph_128;
16515 case X86::BI__builtin_ia32_cmpph256_mask:
16516 IID = Intrinsic::x86_avx512fp16_mask_cmp_ph_256;
16518 case X86::BI__builtin_ia32_cmpph512_mask:
16519 IID = Intrinsic::x86_avx512fp16_mask_cmp_ph_512;
16521 case X86::BI__builtin_ia32_cmpps512_mask:
16522 IID = Intrinsic::x86_avx512_mask_cmp_ps_512;
16524 case X86::BI__builtin_ia32_cmppd512_mask:
16525 IID = Intrinsic::x86_avx512_mask_cmp_pd_512;
16527 case X86::BI__builtin_ia32_cmpps128_mask:
16528 IID = Intrinsic::x86_avx512_mask_cmp_ps_128;
16530 case X86::BI__builtin_ia32_cmpps256_mask:
16531 IID = Intrinsic::x86_avx512_mask_cmp_ps_256;
16533 case X86::BI__builtin_ia32_cmppd128_mask:
16534 IID = Intrinsic::x86_avx512_mask_cmp_pd_128;
16536 case X86::BI__builtin_ia32_cmppd256_mask:
16537 IID = Intrinsic::x86_avx512_mask_cmp_pd_256;
16544 cast<llvm::FixedVectorType>(Ops[0]->getType())->getNumElements();
16550 return Builder.CreateCall(Intr, Ops);
16561 cast<llvm::FixedVectorType>(Ops[0]->getType())->getNumElements();
16564 Cmp =
Builder.CreateFCmpS(Pred, Ops[0], Ops[1]);
16566 Cmp =
Builder.CreateFCmp(Pred, Ops[0], Ops[1]);
16570 return getVectorFCmpIR(Pred, IsSignaling);
16574 case X86::BI__builtin_ia32_cmpeqss:
16575 return getCmpIntrinsicCall(Intrinsic::x86_sse_cmp_ss, 0);
16576 case X86::BI__builtin_ia32_cmpltss:
16577 return getCmpIntrinsicCall(Intrinsic::x86_sse_cmp_ss, 1);
16578 case X86::BI__builtin_ia32_cmpless:
16579 return getCmpIntrinsicCall(Intrinsic::x86_sse_cmp_ss, 2);
16580 case X86::BI__builtin_ia32_cmpunordss:
16581 return getCmpIntrinsicCall(Intrinsic::x86_sse_cmp_ss, 3);
16582 case X86::BI__builtin_ia32_cmpneqss:
16583 return getCmpIntrinsicCall(Intrinsic::x86_sse_cmp_ss, 4);
16584 case X86::BI__builtin_ia32_cmpnltss:
16585 return getCmpIntrinsicCall(Intrinsic::x86_sse_cmp_ss, 5);
16586 case X86::BI__builtin_ia32_cmpnless:
16587 return getCmpIntrinsicCall(Intrinsic::x86_sse_cmp_ss, 6);
16588 case X86::BI__builtin_ia32_cmpordss:
16589 return getCmpIntrinsicCall(Intrinsic::x86_sse_cmp_ss, 7);
16590 case X86::BI__builtin_ia32_cmpeqsd:
16591 return getCmpIntrinsicCall(Intrinsic::x86_sse2_cmp_sd, 0);
16592 case X86::BI__builtin_ia32_cmpltsd:
16593 return getCmpIntrinsicCall(Intrinsic::x86_sse2_cmp_sd, 1);
16594 case X86::BI__builtin_ia32_cmplesd:
16595 return getCmpIntrinsicCall(Intrinsic::x86_sse2_cmp_sd, 2);
16596 case X86::BI__builtin_ia32_cmpunordsd:
16597 return getCmpIntrinsicCall(Intrinsic::x86_sse2_cmp_sd, 3);
16598 case X86::BI__builtin_ia32_cmpneqsd:
16599 return getCmpIntrinsicCall(Intrinsic::x86_sse2_cmp_sd, 4);
16600 case X86::BI__builtin_ia32_cmpnltsd:
16601 return getCmpIntrinsicCall(Intrinsic::x86_sse2_cmp_sd, 5);
16602 case X86::BI__builtin_ia32_cmpnlesd:
16603 return getCmpIntrinsicCall(Intrinsic::x86_sse2_cmp_sd, 6);
16604 case X86::BI__builtin_ia32_cmpordsd:
16605 return getCmpIntrinsicCall(Intrinsic::x86_sse2_cmp_sd, 7);
16608 case X86::BI__builtin_ia32_vcvtph2ps:
16609 case X86::BI__builtin_ia32_vcvtph2ps256:
16610 case X86::BI__builtin_ia32_vcvtph2ps_mask:
16611 case X86::BI__builtin_ia32_vcvtph2ps256_mask:
16612 case X86::BI__builtin_ia32_vcvtph2ps512_mask: {
16613 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*
this,
E);
16618 case X86::BI__builtin_ia32_cvtneps2bf16_128_mask: {
16621 cast<llvm::FixedVectorType>(Ops[0]->getType())->getNumElements());
16622 Intrinsic::ID IID = Intrinsic::x86_avx512bf16_mask_cvtneps2bf16_128;
16625 case X86::BI__builtin_ia32_cvtsbf162ss_32:
16628 case X86::BI__builtin_ia32_cvtneps2bf16_256_mask:
16629 case X86::BI__builtin_ia32_cvtneps2bf16_512_mask: {
16631 switch (BuiltinID) {
16632 default: llvm_unreachable(
"Unsupported intrinsic!");
16633 case X86::BI__builtin_ia32_cvtneps2bf16_256_mask:
16634 IID = Intrinsic::x86_avx512bf16_cvtneps2bf16_256;
16636 case X86::BI__builtin_ia32_cvtneps2bf16_512_mask:
16637 IID = Intrinsic::x86_avx512bf16_cvtneps2bf16_512;
16644 case X86::BI__cpuid:
16645 case X86::BI__cpuidex: {
16647 Value *SubFuncId = BuiltinID == X86::BI__cpuidex
16651 llvm::StructType *CpuidRetTy =
16653 llvm::FunctionType *FTy =
16656 StringRef
Asm, Constraints;
16657 if (
getTarget().getTriple().getArch() == llvm::Triple::x86) {
16659 Constraints =
"={ax},={bx},={cx},={dx},{ax},{cx}";
16662 Asm =
"xchgq %rbx, ${1:q}\n"
16664 "xchgq %rbx, ${1:q}";
16665 Constraints =
"={ax},=r,={cx},={dx},0,2";
16668 llvm::InlineAsm *IA = llvm::InlineAsm::get(FTy,
Asm, Constraints,
16670 Value *IACall =
Builder.CreateCall(IA, {FuncId, SubFuncId});
16673 for (
unsigned i = 0; i < 4; i++) {
16674 Value *Extracted =
Builder.CreateExtractValue(IACall, i);
16684 case X86::BI__emul:
16685 case X86::BI__emulu: {
16687 bool isSigned = (BuiltinID == X86::BI__emul);
16690 return Builder.CreateMul(LHS, RHS,
"", !isSigned, isSigned);
16692 case X86::BI__mulh:
16693 case X86::BI__umulh:
16694 case X86::BI_mul128:
16695 case X86::BI_umul128: {
16697 llvm::Type *Int128Ty = llvm::IntegerType::get(
getLLVMContext(), 128);
16699 bool IsSigned = (BuiltinID == X86::BI__mulh || BuiltinID == X86::BI_mul128);
16700 Value *LHS =
Builder.CreateIntCast(Ops[0], Int128Ty, IsSigned);
16701 Value *RHS =
Builder.CreateIntCast(Ops[1], Int128Ty, IsSigned);
16703 Value *MulResult, *HigherBits;
16705 MulResult =
Builder.CreateNSWMul(LHS, RHS);
16706 HigherBits =
Builder.CreateAShr(MulResult, 64);
16708 MulResult =
Builder.CreateNUWMul(LHS, RHS);
16709 HigherBits =
Builder.CreateLShr(MulResult, 64);
16711 HigherBits =
Builder.CreateIntCast(HigherBits, ResType, IsSigned);
16713 if (BuiltinID == X86::BI__mulh || BuiltinID == X86::BI__umulh)
16718 return Builder.CreateIntCast(MulResult, ResType, IsSigned);
16721 case X86::BI__faststorefence: {
16722 return Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent,
16723 llvm::SyncScope::System);
16725 case X86::BI__shiftleft128:
16726 case X86::BI__shiftright128: {
16728 BuiltinID == X86::BI__shiftleft128 ? Intrinsic::fshl : Intrinsic::fshr,
16733 std::swap(Ops[0], Ops[1]);
16735 return Builder.CreateCall(F, Ops);
16737 case X86::BI_ReadWriteBarrier:
16738 case X86::BI_ReadBarrier:
16739 case X86::BI_WriteBarrier: {
16740 return Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent,
16741 llvm::SyncScope::SingleThread);
16744 case X86::BI_AddressOfReturnAddress: {
16747 return Builder.CreateCall(F);
16749 case X86::BI__stosb: {
16757 case X86::BI__int2c: {
16759 llvm::FunctionType *FTy = llvm::FunctionType::get(
VoidTy,
false);
16760 llvm::InlineAsm *IA =
16761 llvm::InlineAsm::get(FTy,
"int $$0x2c",
"",
true);
16762 llvm::AttributeList NoReturnAttr = llvm::AttributeList::get(
16764 llvm::Attribute::NoReturn);
16765 llvm::CallInst *CI =
Builder.CreateCall(IA);
16766 CI->setAttributes(NoReturnAttr);
16769 case X86::BI__readfsbyte:
16770 case X86::BI__readfsword:
16771 case X86::BI__readfsdword:
16772 case X86::BI__readfsqword: {
16778 Load->setVolatile(
true);
16781 case X86::BI__readgsbyte:
16782 case X86::BI__readgsword:
16783 case X86::BI__readgsdword:
16784 case X86::BI__readgsqword: {
16790 Load->setVolatile(
true);
16793 case X86::BI__builtin_ia32_encodekey128_u32: {
16794 Intrinsic::ID IID = Intrinsic::x86_encodekey128;
16798 for (
int i = 0; i < 3; ++i) {
16806 case X86::BI__builtin_ia32_encodekey256_u32: {
16807 Intrinsic::ID IID = Intrinsic::x86_encodekey256;
16812 for (
int i = 0; i < 4; ++i) {
16820 case X86::BI__builtin_ia32_aesenc128kl_u8:
16821 case X86::BI__builtin_ia32_aesdec128kl_u8:
16822 case X86::BI__builtin_ia32_aesenc256kl_u8:
16823 case X86::BI__builtin_ia32_aesdec256kl_u8: {
16825 StringRef BlockName;
16826 switch (BuiltinID) {
16828 llvm_unreachable(
"Unexpected builtin");
16829 case X86::BI__builtin_ia32_aesenc128kl_u8:
16830 IID = Intrinsic::x86_aesenc128kl;
16831 BlockName =
"aesenc128kl";
16833 case X86::BI__builtin_ia32_aesdec128kl_u8:
16834 IID = Intrinsic::x86_aesdec128kl;
16835 BlockName =
"aesdec128kl";
16837 case X86::BI__builtin_ia32_aesenc256kl_u8:
16838 IID = Intrinsic::x86_aesenc256kl;
16839 BlockName =
"aesenc256kl";
16841 case X86::BI__builtin_ia32_aesdec256kl_u8:
16842 IID = Intrinsic::x86_aesdec256kl;
16843 BlockName =
"aesdec256kl";
16849 BasicBlock *NoError =
16857 Builder.CreateCondBr(Succ, NoError, Error);
16859 Builder.SetInsertPoint(NoError);
16863 Builder.SetInsertPoint(Error);
16864 Constant *
Zero = llvm::Constant::getNullValue(Out->getType());
16871 case X86::BI__builtin_ia32_aesencwide128kl_u8:
16872 case X86::BI__builtin_ia32_aesdecwide128kl_u8:
16873 case X86::BI__builtin_ia32_aesencwide256kl_u8:
16874 case X86::BI__builtin_ia32_aesdecwide256kl_u8: {
16876 StringRef BlockName;
16877 switch (BuiltinID) {
16878 case X86::BI__builtin_ia32_aesencwide128kl_u8:
16879 IID = Intrinsic::x86_aesencwide128kl;
16880 BlockName =
"aesencwide128kl";
16882 case X86::BI__builtin_ia32_aesdecwide128kl_u8:
16883 IID = Intrinsic::x86_aesdecwide128kl;
16884 BlockName =
"aesdecwide128kl";
16886 case X86::BI__builtin_ia32_aesencwide256kl_u8:
16887 IID = Intrinsic::x86_aesencwide256kl;
16888 BlockName =
"aesencwide256kl";
16890 case X86::BI__builtin_ia32_aesdecwide256kl_u8:
16891 IID = Intrinsic::x86_aesdecwide256kl;
16892 BlockName =
"aesdecwide256kl";
16896 llvm::Type *Ty = FixedVectorType::get(
Builder.getInt64Ty(), 2);
16899 for (
int i = 0; i != 8; ++i) {
16900 Value *Ptr =
Builder.CreateConstGEP1_32(Ty, Ops[1], i);
16906 BasicBlock *NoError =
16913 Builder.CreateCondBr(Succ, NoError, Error);
16915 Builder.SetInsertPoint(NoError);
16916 for (
int i = 0; i != 8; ++i) {
16923 Builder.SetInsertPoint(Error);
16924 for (
int i = 0; i != 8; ++i) {
16926 Constant *
Zero = llvm::Constant::getNullValue(Out->getType());
16927 Value *Ptr =
Builder.CreateConstGEP1_32(Out->getType(), Ops[0], i);
16935 case X86::BI__builtin_ia32_vfcmaddcph512_mask:
16938 case X86::BI__builtin_ia32_vfmaddcph512_mask: {
16939 Intrinsic::ID IID = IsConjFMA
16940 ? Intrinsic::x86_avx512fp16_mask_vfcmadd_cph_512
16941 : Intrinsic::x86_avx512fp16_mask_vfmadd_cph_512;
16945 case X86::BI__builtin_ia32_vfcmaddcph256_round_mask:
16948 case X86::BI__builtin_ia32_vfmaddcph256_round_mask: {
16949 Intrinsic::ID IID = IsConjFMA ? Intrinsic::x86_avx10_mask_vfcmaddcph256
16950 : Intrinsic::x86_avx10_mask_vfmaddcph256;
16954 case X86::BI__builtin_ia32_vfcmaddcsh_round_mask:
16957 case X86::BI__builtin_ia32_vfmaddcsh_round_mask: {
16958 Intrinsic::ID IID = IsConjFMA ? Intrinsic::x86_avx512fp16_mask_vfcmadd_csh
16959 : Intrinsic::x86_avx512fp16_mask_vfmadd_csh;
16964 case X86::BI__builtin_ia32_vfcmaddcsh_round_mask3:
16967 case X86::BI__builtin_ia32_vfmaddcsh_round_mask3: {
16968 Intrinsic::ID IID = IsConjFMA ? Intrinsic::x86_avx512fp16_mask_vfcmadd_csh
16969 : Intrinsic::x86_avx512fp16_mask_vfmadd_csh;
16971 static constexpr int Mask[] = {0, 5, 6, 7};
16972 return Builder.CreateShuffleVector(
Call, Ops[2], Mask);
16974 case X86::BI__builtin_ia32_prefetchi:
16977 {Ops[0], llvm::ConstantInt::get(Int32Ty, 0), Ops[1],
16978 llvm::ConstantInt::get(Int32Ty, 0)});
16996 Intrinsic::ID
ID = Intrinsic::not_intrinsic;
16998#include "llvm/TargetParser/PPCTargetParser.def"
16999 auto GenAIXPPCBuiltinCpuExpr = [&](
unsigned SupportMethod,
unsigned FieldIdx,
17000 unsigned Mask, CmpInst::Predicate CompOp,
17001 unsigned OpValue) ->
Value * {
17002 if (SupportMethod == BUILTIN_PPC_FALSE)
17005 if (SupportMethod == BUILTIN_PPC_TRUE)
17008 assert(SupportMethod <= SYS_CALL &&
"Invalid value for SupportMethod.");
17010 llvm::Value *FieldValue =
nullptr;
17011 if (SupportMethod == USE_SYS_CONF) {
17012 llvm::Type *STy = llvm::StructType::get(PPC_SYSTEMCONFIG_TYPE);
17013 llvm::Constant *SysConf =
17017 llvm::Value *Idxs[] = {ConstantInt::get(
Int32Ty, 0),
17018 ConstantInt::get(
Int32Ty, FieldIdx)};
17023 }
else if (SupportMethod == SYS_CALL) {
17024 llvm::FunctionType *FTy =
17026 llvm::FunctionCallee
Func =
17032 assert(FieldValue &&
17033 "SupportMethod value is not defined in PPCTargetParser.def.");
17036 FieldValue =
Builder.CreateAnd(FieldValue, Mask);
17038 llvm::Type *ValueType = FieldValue->getType();
17039 bool IsValueType64Bit = ValueType->isIntegerTy(64);
17041 (IsValueType64Bit || ValueType->isIntegerTy(32)) &&
17042 "Only 32/64-bit integers are supported in GenAIXPPCBuiltinCpuExpr().");
17045 CompOp, FieldValue,
17046 ConstantInt::get(IsValueType64Bit ?
Int64Ty :
Int32Ty, OpValue));
17049 switch (BuiltinID) {
17050 default:
return nullptr;
17052 case Builtin::BI__builtin_cpu_is: {
17054 StringRef CPUStr = cast<clang::StringLiteral>(CPUExpr)->getString();
17057 unsigned LinuxSupportMethod, LinuxIDValue, AIXSupportMethod, AIXIDValue;
17058 typedef std::tuple<unsigned, unsigned, unsigned, unsigned>
CPUInfo;
17060 std::tie(LinuxSupportMethod, LinuxIDValue, AIXSupportMethod, AIXIDValue) =
17061 static_cast<CPUInfo>(StringSwitch<CPUInfo>(CPUStr)
17062#define PPC_CPU(NAME, Linux_SUPPORT_METHOD, LinuxID, AIX_SUPPORT_METHOD, \
17064 .Case(NAME, {Linux_SUPPORT_METHOD, LinuxID, AIX_SUPPORT_METHOD, AIXID})
17065#include "llvm/TargetParser/PPCTargetParser.def"
17066 .Default({BUILTIN_PPC_UNSUPPORTED, 0,
17067 BUILTIN_PPC_UNSUPPORTED, 0}));
17069 if (Triple.isOSAIX()) {
17070 assert((AIXSupportMethod != BUILTIN_PPC_UNSUPPORTED) &&
17071 "Invalid CPU name. Missed by SemaChecking?");
17072 return GenAIXPPCBuiltinCpuExpr(AIXSupportMethod, AIX_SYSCON_IMPL_IDX, 0,
17073 ICmpInst::ICMP_EQ, AIXIDValue);
17076 assert(Triple.isOSLinux() &&
17077 "__builtin_cpu_is() is only supported for AIX and Linux.");
17079 assert((LinuxSupportMethod != BUILTIN_PPC_UNSUPPORTED) &&
17080 "Invalid CPU name. Missed by SemaChecking?");
17082 if (LinuxSupportMethod == BUILTIN_PPC_FALSE)
17085 Value *Op0 = llvm::ConstantInt::get(
Int32Ty, PPC_FAWORD_CPUID);
17087 Value *TheCall =
Builder.CreateCall(F, {Op0},
"cpu_is");
17088 return Builder.CreateICmpEQ(TheCall,
17089 llvm::ConstantInt::get(
Int32Ty, LinuxIDValue));
17091 case Builtin::BI__builtin_cpu_supports: {
17094 StringRef CPUStr = cast<clang::StringLiteral>(CPUExpr)->getString();
17095 if (Triple.isOSAIX()) {
17096 unsigned SupportMethod, FieldIdx, Mask,
Value;
17097 CmpInst::Predicate CompOp;
17101 std::tie(SupportMethod, FieldIdx, Mask, CompOp,
Value) =
17102 static_cast<CPUSupportType
>(StringSwitch<CPUSupportType>(CPUStr)
17103#define PPC_AIX_FEATURE(NAME, DESC, SUPPORT_METHOD, INDEX, MASK, COMP_OP, \
17105 .Case(NAME, {SUPPORT_METHOD, INDEX, MASK, COMP_OP, VALUE})
17106#include "llvm/TargetParser/PPCTargetParser.def"
17107 .Default({BUILTIN_PPC_FALSE, 0, 0,
17108 CmpInst::Predicate(), 0}));
17109 return GenAIXPPCBuiltinCpuExpr(SupportMethod, FieldIdx, Mask, CompOp,
17113 assert(Triple.isOSLinux() &&
17114 "__builtin_cpu_supports() is only supported for AIX and Linux.");
17115 unsigned FeatureWord;
17117 std::tie(FeatureWord, BitMask) =
17118 StringSwitch<std::pair<unsigned, unsigned>>(CPUStr)
17119#define
PPC_LNX_FEATURE(Name, Description, EnumName, Bitmask, FA_WORD) \
17120 .Case(Name, {FA_WORD, Bitmask})
17121#include
"llvm/TargetParser/PPCTargetParser.def"
17125 Value *Op0 = llvm::ConstantInt::get(
Int32Ty, FeatureWord);
17127 Value *TheCall =
Builder.CreateCall(F, {Op0},
"cpu_supports");
17129 Builder.CreateAnd(TheCall, llvm::ConstantInt::get(
Int32Ty, BitMask));
17130 return Builder.CreateICmpNE(Mask, llvm::Constant::getNullValue(
Int32Ty));
17131#undef PPC_FAWORD_HWCAP
17132#undef PPC_FAWORD_HWCAP2
17133#undef PPC_FAWORD_CPUID
17138 case PPC::BI__builtin_ppc_get_timebase:
17142 case PPC::BI__builtin_altivec_lvx:
17143 case PPC::BI__builtin_altivec_lvxl:
17144 case PPC::BI__builtin_altivec_lvebx:
17145 case PPC::BI__builtin_altivec_lvehx:
17146 case PPC::BI__builtin_altivec_lvewx:
17147 case PPC::BI__builtin_altivec_lvsl:
17148 case PPC::BI__builtin_altivec_lvsr:
17149 case PPC::BI__builtin_vsx_lxvd2x:
17150 case PPC::BI__builtin_vsx_lxvw4x:
17151 case PPC::BI__builtin_vsx_lxvd2x_be:
17152 case PPC::BI__builtin_vsx_lxvw4x_be:
17153 case PPC::BI__builtin_vsx_lxvl:
17154 case PPC::BI__builtin_vsx_lxvll:
17159 if (!(BuiltinID == PPC::BI__builtin_vsx_lxvl ||
17160 BuiltinID == PPC::BI__builtin_vsx_lxvll)) {
17165 switch (BuiltinID) {
17166 default: llvm_unreachable(
"Unsupported ld/lvsl/lvsr intrinsic!");
17167 case PPC::BI__builtin_altivec_lvx:
17168 ID = Intrinsic::ppc_altivec_lvx;
17170 case PPC::BI__builtin_altivec_lvxl:
17171 ID = Intrinsic::ppc_altivec_lvxl;
17173 case PPC::BI__builtin_altivec_lvebx:
17174 ID = Intrinsic::ppc_altivec_lvebx;
17176 case PPC::BI__builtin_altivec_lvehx:
17177 ID = Intrinsic::ppc_altivec_lvehx;
17179 case PPC::BI__builtin_altivec_lvewx:
17180 ID = Intrinsic::ppc_altivec_lvewx;
17182 case PPC::BI__builtin_altivec_lvsl:
17183 ID = Intrinsic::ppc_altivec_lvsl;
17185 case PPC::BI__builtin_altivec_lvsr:
17186 ID = Intrinsic::ppc_altivec_lvsr;
17188 case PPC::BI__builtin_vsx_lxvd2x:
17189 ID = Intrinsic::ppc_vsx_lxvd2x;
17191 case PPC::BI__builtin_vsx_lxvw4x:
17192 ID = Intrinsic::ppc_vsx_lxvw4x;
17194 case PPC::BI__builtin_vsx_lxvd2x_be:
17195 ID = Intrinsic::ppc_vsx_lxvd2x_be;
17197 case PPC::BI__builtin_vsx_lxvw4x_be:
17198 ID = Intrinsic::ppc_vsx_lxvw4x_be;
17200 case PPC::BI__builtin_vsx_lxvl:
17201 ID = Intrinsic::ppc_vsx_lxvl;
17203 case PPC::BI__builtin_vsx_lxvll:
17204 ID = Intrinsic::ppc_vsx_lxvll;
17208 return Builder.CreateCall(F, Ops,
"");
17212 case PPC::BI__builtin_altivec_stvx:
17213 case PPC::BI__builtin_altivec_stvxl:
17214 case PPC::BI__builtin_altivec_stvebx:
17215 case PPC::BI__builtin_altivec_stvehx:
17216 case PPC::BI__builtin_altivec_stvewx:
17217 case PPC::BI__builtin_vsx_stxvd2x:
17218 case PPC::BI__builtin_vsx_stxvw4x:
17219 case PPC::BI__builtin_vsx_stxvd2x_be:
17220 case PPC::BI__builtin_vsx_stxvw4x_be:
17221 case PPC::BI__builtin_vsx_stxvl:
17222 case PPC::BI__builtin_vsx_stxvll:
17228 if (!(BuiltinID == PPC::BI__builtin_vsx_stxvl ||
17229 BuiltinID == PPC::BI__builtin_vsx_stxvll)) {
17234 switch (BuiltinID) {
17235 default: llvm_unreachable(
"Unsupported st intrinsic!");
17236 case PPC::BI__builtin_altivec_stvx:
17237 ID = Intrinsic::ppc_altivec_stvx;
17239 case PPC::BI__builtin_altivec_stvxl:
17240 ID = Intrinsic::ppc_altivec_stvxl;
17242 case PPC::BI__builtin_altivec_stvebx:
17243 ID = Intrinsic::ppc_altivec_stvebx;
17245 case PPC::BI__builtin_altivec_stvehx:
17246 ID = Intrinsic::ppc_altivec_stvehx;
17248 case PPC::BI__builtin_altivec_stvewx:
17249 ID = Intrinsic::ppc_altivec_stvewx;
17251 case PPC::BI__builtin_vsx_stxvd2x:
17252 ID = Intrinsic::ppc_vsx_stxvd2x;
17254 case PPC::BI__builtin_vsx_stxvw4x:
17255 ID = Intrinsic::ppc_vsx_stxvw4x;
17257 case PPC::BI__builtin_vsx_stxvd2x_be:
17258 ID = Intrinsic::ppc_vsx_stxvd2x_be;
17260 case PPC::BI__builtin_vsx_stxvw4x_be:
17261 ID = Intrinsic::ppc_vsx_stxvw4x_be;
17263 case PPC::BI__builtin_vsx_stxvl:
17264 ID = Intrinsic::ppc_vsx_stxvl;
17266 case PPC::BI__builtin_vsx_stxvll:
17267 ID = Intrinsic::ppc_vsx_stxvll;
17271 return Builder.CreateCall(F, Ops,
"");
17273 case PPC::BI__builtin_vsx_ldrmb: {
17279 int64_t NumBytes = cast<ConstantInt>(Op1)->getZExtValue();
17284 if (NumBytes == 16) {
17292 for (
int Idx = 0; Idx < 16; Idx++)
17293 RevMask.push_back(15 - Idx);
17294 return Builder.CreateShuffleVector(LD, LD, RevMask);
17298 llvm::Function *Lvs =
CGM.
getIntrinsic(IsLE ? Intrinsic::ppc_altivec_lvsr
17299 : Intrinsic::ppc_altivec_lvsl);
17300 llvm::Function *Vperm =
CGM.
getIntrinsic(Intrinsic::ppc_altivec_vperm);
17302 Int8Ty, Op0, ConstantInt::get(Op1->
getType(), NumBytes - 1));
17304 Value *HiLd =
Builder.CreateCall(Lvx, HiMem,
"ld.hi");
17307 Op0 = IsLE ? HiLd : LoLd;
17308 Op1 = IsLE ? LoLd : HiLd;
17309 Value *AllElts =
Builder.CreateCall(Vperm, {Op0, Op1, Mask1},
"shuffle1");
17310 Constant *
Zero = llvm::Constant::getNullValue(IsLE ? ResTy : AllElts->
getType());
17314 for (
int Idx = 0; Idx < 16; Idx++) {
17315 int Val = (NumBytes - Idx - 1 >= 0) ? (NumBytes - Idx - 1)
17316 : 16 - (NumBytes - Idx);
17317 Consts.push_back(Val);
17319 return Builder.CreateShuffleVector(
Builder.CreateBitCast(AllElts, ResTy),
17323 for (
int Idx = 0; Idx < 16; Idx++)
17324 Consts.push_back(
Builder.getInt8(NumBytes + Idx));
17325 Value *Mask2 = ConstantVector::get(Consts);
17326 return Builder.CreateBitCast(
17327 Builder.CreateCall(Vperm, {Zero, AllElts, Mask2},
"shuffle2"), ResTy);
17329 case PPC::BI__builtin_vsx_strmb: {
17333 int64_t NumBytes = cast<ConstantInt>(Op1)->getZExtValue();
17335 auto StoreSubVec = [&](
unsigned Width,
unsigned Offset,
unsigned EltNo) {
17339 Value *StVec = Op2;
17342 for (
int Idx = 0; Idx < 16; Idx++)
17343 RevMask.push_back(15 - Idx);
17344 StVec =
Builder.CreateShuffleVector(Op2, Op2, RevMask);
17350 unsigned NumElts = 0;
17353 llvm_unreachable(
"width for stores must be a power of 2");
17372 Op2, llvm::FixedVectorType::get(ConvTy, NumElts));
17375 Value *Elt =
Builder.CreateExtractElement(Vec, EltNo);
17376 if (IsLE && Width > 1) {
17378 Elt =
Builder.CreateCall(F, Elt);
17383 unsigned Stored = 0;
17384 unsigned RemainingBytes = NumBytes;
17386 if (NumBytes == 16)
17387 return StoreSubVec(16, 0, 0);
17388 if (NumBytes >= 8) {
17389 Result = StoreSubVec(8, NumBytes - 8, IsLE ? 0 : 1);
17390 RemainingBytes -= 8;
17393 if (RemainingBytes >= 4) {
17394 Result = StoreSubVec(4, NumBytes - Stored - 4,
17395 IsLE ? (Stored >> 2) : 3 - (Stored >> 2));
17396 RemainingBytes -= 4;
17399 if (RemainingBytes >= 2) {
17400 Result = StoreSubVec(2, NumBytes - Stored - 2,
17401 IsLE ? (Stored >> 1) : 7 - (Stored >> 1));
17402 RemainingBytes -= 2;
17405 if (RemainingBytes)
17407 StoreSubVec(1, NumBytes - Stored - 1, IsLE ? Stored : 15 - Stored);
17411 case PPC::BI__builtin_vsx_xvsqrtsp:
17412 case PPC::BI__builtin_vsx_xvsqrtdp: {
17415 if (
Builder.getIsFPConstrained()) {
17417 Intrinsic::experimental_constrained_sqrt, ResultType);
17418 return Builder.CreateConstrainedFPCall(F,
X);
17425 case PPC::BI__builtin_altivec_vclzb:
17426 case PPC::BI__builtin_altivec_vclzh:
17427 case PPC::BI__builtin_altivec_vclzw:
17428 case PPC::BI__builtin_altivec_vclzd: {
17431 Value *Undef = ConstantInt::get(
Builder.getInt1Ty(),
false);
17433 return Builder.CreateCall(F, {
X, Undef});
17435 case PPC::BI__builtin_altivec_vctzb:
17436 case PPC::BI__builtin_altivec_vctzh:
17437 case PPC::BI__builtin_altivec_vctzw:
17438 case PPC::BI__builtin_altivec_vctzd: {
17441 Value *Undef = ConstantInt::get(
Builder.getInt1Ty(),
false);
17443 return Builder.CreateCall(F, {
X, Undef});
17445 case PPC::BI__builtin_altivec_vinsd:
17446 case PPC::BI__builtin_altivec_vinsw:
17447 case PPC::BI__builtin_altivec_vinsd_elt:
17448 case PPC::BI__builtin_altivec_vinsw_elt: {
17454 bool IsUnaligned = (BuiltinID == PPC::BI__builtin_altivec_vinsw ||
17455 BuiltinID == PPC::BI__builtin_altivec_vinsd);
17457 bool Is32bit = (BuiltinID == PPC::BI__builtin_altivec_vinsw ||
17458 BuiltinID == PPC::BI__builtin_altivec_vinsw_elt);
17461 ConstantInt *ArgCI = dyn_cast<ConstantInt>(Op2);
17463 "Third Arg to vinsw/vinsd intrinsic must be a constant integer!");
17467 int ValidMaxValue = 0;
17469 ValidMaxValue = (Is32bit) ? 12 : 8;
17471 ValidMaxValue = (Is32bit) ? 3 : 1;
17474 int64_t ConstArg = ArgCI->getSExtValue();
17477 std::string RangeErrMsg = IsUnaligned ?
"byte" :
"element";
17478 RangeErrMsg +=
" number " + llvm::to_string(ConstArg);
17479 RangeErrMsg +=
" is outside of the valid range [0, ";
17480 RangeErrMsg += llvm::to_string(ValidMaxValue) +
"]";
17483 if (ConstArg < 0 || ConstArg > ValidMaxValue)
17487 if (!IsUnaligned) {
17488 ConstArg *= Is32bit ? 4 : 8;
17491 ConstArg = (Is32bit ? 12 : 8) - ConstArg;
17494 ID = Is32bit ? Intrinsic::ppc_altivec_vinsw : Intrinsic::ppc_altivec_vinsd;
17495 Op2 = ConstantInt::getSigned(
Int32Ty, ConstArg);
17499 ?
Builder.CreateBitCast(Op0, llvm::FixedVectorType::get(
Int32Ty, 4))
17501 llvm::FixedVectorType::get(
Int64Ty, 2));
17502 return Builder.CreateBitCast(
17505 case PPC::BI__builtin_altivec_vpopcntb:
17506 case PPC::BI__builtin_altivec_vpopcnth:
17507 case PPC::BI__builtin_altivec_vpopcntw:
17508 case PPC::BI__builtin_altivec_vpopcntd: {
17514 case PPC::BI__builtin_altivec_vadduqm:
17515 case PPC::BI__builtin_altivec_vsubuqm: {
17518 llvm::Type *Int128Ty = llvm::IntegerType::get(
getLLVMContext(), 128);
17519 Op0 =
Builder.CreateBitCast(Op0, llvm::FixedVectorType::get(Int128Ty, 1));
17520 Op1 =
Builder.CreateBitCast(Op1, llvm::FixedVectorType::get(Int128Ty, 1));
17521 if (BuiltinID == PPC::BI__builtin_altivec_vadduqm)
17522 return Builder.CreateAdd(Op0, Op1,
"vadduqm");
17524 return Builder.CreateSub(Op0, Op1,
"vsubuqm");
17526 case PPC::BI__builtin_altivec_vaddcuq_c:
17527 case PPC::BI__builtin_altivec_vsubcuq_c: {
17531 llvm::Type *V1I128Ty = llvm::FixedVectorType::get(
17533 Ops.push_back(
Builder.CreateBitCast(Op0, V1I128Ty));
17534 Ops.push_back(
Builder.CreateBitCast(Op1, V1I128Ty));
17535 ID = (BuiltinID == PPC::BI__builtin_altivec_vaddcuq_c)
17536 ? Intrinsic::ppc_altivec_vaddcuq
17537 : Intrinsic::ppc_altivec_vsubcuq;
17540 case PPC::BI__builtin_altivec_vaddeuqm_c:
17541 case PPC::BI__builtin_altivec_vaddecuq_c:
17542 case PPC::BI__builtin_altivec_vsubeuqm_c:
17543 case PPC::BI__builtin_altivec_vsubecuq_c: {
17548 llvm::Type *V1I128Ty = llvm::FixedVectorType::get(
17550 Ops.push_back(
Builder.CreateBitCast(Op0, V1I128Ty));
17551 Ops.push_back(
Builder.CreateBitCast(Op1, V1I128Ty));
17552 Ops.push_back(
Builder.CreateBitCast(Op2, V1I128Ty));
17553 switch (BuiltinID) {
17555 llvm_unreachable(
"Unsupported intrinsic!");
17556 case PPC::BI__builtin_altivec_vaddeuqm_c:
17557 ID = Intrinsic::ppc_altivec_vaddeuqm;
17559 case PPC::BI__builtin_altivec_vaddecuq_c:
17560 ID = Intrinsic::ppc_altivec_vaddecuq;
17562 case PPC::BI__builtin_altivec_vsubeuqm_c:
17563 ID = Intrinsic::ppc_altivec_vsubeuqm;
17565 case PPC::BI__builtin_altivec_vsubecuq_c:
17566 ID = Intrinsic::ppc_altivec_vsubecuq;
17571 case PPC::BI__builtin_ppc_rldimi:
17572 case PPC::BI__builtin_ppc_rlwimi: {
17579 if (BuiltinID == PPC::BI__builtin_ppc_rldimi &&
17589 ? Intrinsic::ppc_rldimi
17590 : Intrinsic::ppc_rlwimi),
17591 {Op0, Op1, Op2, Op3});
17593 case PPC::BI__builtin_ppc_rlwnm: {
17600 case PPC::BI__builtin_ppc_poppar4:
17601 case PPC::BI__builtin_ppc_poppar8: {
17603 llvm::Type *ArgType = Op0->
getType();
17609 if (
Result->getType() != ResultType)
17614 case PPC::BI__builtin_ppc_cmpb: {
17617 if (
getTarget().getTriple().isPPC64()) {
17620 return Builder.CreateCall(F, {Op0, Op1},
"cmpb");
17640 Constant *ShiftAmt = ConstantInt::get(
Int64Ty, 32);
17649 Value *ResHi =
Builder.CreateShl(ResHiShift, ShiftAmt);
17650 return Builder.CreateOr(ResLo, ResHi);
17653 case PPC::BI__builtin_vsx_xvcpsgnsp:
17654 case PPC::BI__builtin_vsx_xvcpsgndp: {
17658 ID = Intrinsic::copysign;
17660 return Builder.CreateCall(F, {
X, Y});
17663 case PPC::BI__builtin_vsx_xvrspip:
17664 case PPC::BI__builtin_vsx_xvrdpip:
17665 case PPC::BI__builtin_vsx_xvrdpim:
17666 case PPC::BI__builtin_vsx_xvrspim:
17667 case PPC::BI__builtin_vsx_xvrdpi:
17668 case PPC::BI__builtin_vsx_xvrspi:
17669 case PPC::BI__builtin_vsx_xvrdpic:
17670 case PPC::BI__builtin_vsx_xvrspic:
17671 case PPC::BI__builtin_vsx_xvrdpiz:
17672 case PPC::BI__builtin_vsx_xvrspiz: {
17675 if (BuiltinID == PPC::BI__builtin_vsx_xvrdpim ||
17676 BuiltinID == PPC::BI__builtin_vsx_xvrspim)
17678 ? Intrinsic::experimental_constrained_floor
17679 : Intrinsic::floor;
17680 else if (BuiltinID == PPC::BI__builtin_vsx_xvrdpi ||
17681 BuiltinID == PPC::BI__builtin_vsx_xvrspi)
17683 ? Intrinsic::experimental_constrained_round
17684 : Intrinsic::round;
17685 else if (BuiltinID == PPC::BI__builtin_vsx_xvrdpic ||
17686 BuiltinID == PPC::BI__builtin_vsx_xvrspic)
17688 ? Intrinsic::experimental_constrained_rint
17690 else if (BuiltinID == PPC::BI__builtin_vsx_xvrdpip ||
17691 BuiltinID == PPC::BI__builtin_vsx_xvrspip)
17693 ? Intrinsic::experimental_constrained_ceil
17695 else if (BuiltinID == PPC::BI__builtin_vsx_xvrdpiz ||
17696 BuiltinID == PPC::BI__builtin_vsx_xvrspiz)
17698 ? Intrinsic::experimental_constrained_trunc
17699 : Intrinsic::trunc;
17701 return Builder.getIsFPConstrained() ?
Builder.CreateConstrainedFPCall(F,
X)
17706 case PPC::BI__builtin_vsx_xvabsdp:
17707 case PPC::BI__builtin_vsx_xvabssp: {
17715 case PPC::BI__builtin_ppc_recipdivf:
17716 case PPC::BI__builtin_ppc_recipdivd:
17717 case PPC::BI__builtin_ppc_rsqrtf:
17718 case PPC::BI__builtin_ppc_rsqrtd: {
17719 FastMathFlags FMF =
Builder.getFastMathFlags();
17720 Builder.getFastMathFlags().setFast();
17724 if (BuiltinID == PPC::BI__builtin_ppc_recipdivf ||
17725 BuiltinID == PPC::BI__builtin_ppc_recipdivd) {
17728 Builder.getFastMathFlags() &= (FMF);
17731 auto *One = ConstantFP::get(ResultType, 1.0);
17734 Builder.getFastMathFlags() &= (FMF);
17737 case PPC::BI__builtin_ppc_alignx: {
17740 ConstantInt *AlignmentCI = cast<ConstantInt>(Op0);
17741 if (AlignmentCI->getValue().ugt(llvm::Value::MaximumAlignment))
17742 AlignmentCI = ConstantInt::get(AlignmentCI->getIntegerType(),
17743 llvm::Value::MaximumAlignment);
17747 AlignmentCI,
nullptr);
17750 case PPC::BI__builtin_ppc_rdlam: {
17754 llvm::Type *Ty = Op0->
getType();
17755 Value *ShiftAmt =
Builder.CreateIntCast(Op1, Ty,
false);
17757 Value *Rotate =
Builder.CreateCall(F, {Op0, Op0, ShiftAmt});
17758 return Builder.CreateAnd(Rotate, Op2);
17760 case PPC::BI__builtin_ppc_load2r: {
17767 case PPC::BI__builtin_ppc_fnmsub:
17768 case PPC::BI__builtin_ppc_fnmsubs:
17769 case PPC::BI__builtin_vsx_xvmaddadp:
17770 case PPC::BI__builtin_vsx_xvmaddasp:
17771 case PPC::BI__builtin_vsx_xvnmaddadp:
17772 case PPC::BI__builtin_vsx_xvnmaddasp:
17773 case PPC::BI__builtin_vsx_xvmsubadp:
17774 case PPC::BI__builtin_vsx_xvmsubasp:
17775 case PPC::BI__builtin_vsx_xvnmsubadp:
17776 case PPC::BI__builtin_vsx_xvnmsubasp: {
17782 if (
Builder.getIsFPConstrained())
17783 F =
CGM.
getIntrinsic(Intrinsic::experimental_constrained_fma, ResultType);
17786 switch (BuiltinID) {
17787 case PPC::BI__builtin_vsx_xvmaddadp:
17788 case PPC::BI__builtin_vsx_xvmaddasp:
17789 if (
Builder.getIsFPConstrained())
17790 return Builder.CreateConstrainedFPCall(F, {
X, Y, Z});
17792 return Builder.CreateCall(F, {
X, Y, Z});
17793 case PPC::BI__builtin_vsx_xvnmaddadp:
17794 case PPC::BI__builtin_vsx_xvnmaddasp:
17795 if (
Builder.getIsFPConstrained())
17797 Builder.CreateConstrainedFPCall(F, {X, Y, Z}),
"neg");
17799 return Builder.CreateFNeg(
Builder.CreateCall(F, {X, Y, Z}),
"neg");
17800 case PPC::BI__builtin_vsx_xvmsubadp:
17801 case PPC::BI__builtin_vsx_xvmsubasp:
17802 if (
Builder.getIsFPConstrained())
17803 return Builder.CreateConstrainedFPCall(
17804 F, {
X, Y,
Builder.CreateFNeg(Z,
"neg")});
17807 case PPC::BI__builtin_ppc_fnmsub:
17808 case PPC::BI__builtin_ppc_fnmsubs:
17809 case PPC::BI__builtin_vsx_xvnmsubadp:
17810 case PPC::BI__builtin_vsx_xvnmsubasp:
17811 if (
Builder.getIsFPConstrained())
17813 Builder.CreateConstrainedFPCall(
17814 F, {X, Y, Builder.CreateFNeg(Z,
"neg")}),
17820 llvm_unreachable(
"Unknown FMA operation");
17824 case PPC::BI__builtin_vsx_insertword: {
17832 ConstantInt *ArgCI = dyn_cast<ConstantInt>(Op2);
17834 "Third arg to xxinsertw intrinsic must be constant integer");
17836 int64_t Index = std::clamp(ArgCI->getSExtValue(), (int64_t)0, MaxIndex);
17843 std::swap(Op0, Op1);
17847 Op1 =
Builder.CreateBitCast(Op1, llvm::FixedVectorType::get(
Int64Ty, 2));
17851 Op0 =
Builder.CreateBitCast(Op0, llvm::FixedVectorType::get(
Int64Ty, 2));
17855 Index = MaxIndex - Index;
17859 Op0 =
Builder.CreateBitCast(Op0, llvm::FixedVectorType::get(
Int32Ty, 4));
17860 Op2 = ConstantInt::getSigned(
Int32Ty, Index);
17861 return Builder.CreateCall(F, {Op0, Op1, Op2});
17864 case PPC::BI__builtin_vsx_extractuword: {
17867 llvm::Function *F =
CGM.
getIntrinsic(Intrinsic::ppc_vsx_xxextractuw);
17870 Op0 =
Builder.CreateBitCast(Op0, llvm::FixedVectorType::get(
Int64Ty, 2));
17874 ConstantInt *ArgCI = dyn_cast<ConstantInt>(Op1);
17876 "Second Arg to xxextractuw intrinsic must be a constant integer!");
17878 int64_t Index = std::clamp(ArgCI->getSExtValue(), (int64_t)0, MaxIndex);
17882 Index = MaxIndex - Index;
17883 Op1 = ConstantInt::getSigned(
Int32Ty, Index);
17888 Value *ShuffleCall =
17890 return ShuffleCall;
17892 Op1 = ConstantInt::getSigned(
Int32Ty, Index);
17893 return Builder.CreateCall(F, {Op0, Op1});
17897 case PPC::BI__builtin_vsx_xxpermdi: {
17901 ConstantInt *ArgCI = dyn_cast<ConstantInt>(Op2);
17902 assert(ArgCI &&
"Third arg must be constant integer!");
17904 unsigned Index = ArgCI->getZExtValue();
17905 Op0 =
Builder.CreateBitCast(Op0, llvm::FixedVectorType::get(
Int64Ty, 2));
17906 Op1 =
Builder.CreateBitCast(Op1, llvm::FixedVectorType::get(
Int64Ty, 2));
17911 int ElemIdx0 = (Index & 2) >> 1;
17912 int ElemIdx1 = 2 + (Index & 1);
17914 int ShuffleElts[2] = {ElemIdx0, ElemIdx1};
17915 Value *ShuffleCall =
Builder.CreateShuffleVector(Op0, Op1, ShuffleElts);
17918 return Builder.CreateBitCast(ShuffleCall, RetTy);
17921 case PPC::BI__builtin_vsx_xxsldwi: {
17925 ConstantInt *ArgCI = dyn_cast<ConstantInt>(Op2);
17926 assert(ArgCI &&
"Third argument must be a compile time constant");
17927 unsigned Index = ArgCI->getZExtValue() & 0x3;
17928 Op0 =
Builder.CreateBitCast(Op0, llvm::FixedVectorType::get(
Int32Ty, 4));
17929 Op1 =
Builder.CreateBitCast(Op1, llvm::FixedVectorType::get(
Int32Ty, 4));
17940 ElemIdx0 = (8 - Index) % 8;
17941 ElemIdx1 = (9 - Index) % 8;
17942 ElemIdx2 = (10 - Index) % 8;
17943 ElemIdx3 = (11 - Index) % 8;
17947 ElemIdx1 = Index + 1;
17948 ElemIdx2 = Index + 2;
17949 ElemIdx3 = Index + 3;
17952 int ShuffleElts[4] = {ElemIdx0, ElemIdx1, ElemIdx2, ElemIdx3};
17953 Value *ShuffleCall =
Builder.CreateShuffleVector(Op0, Op1, ShuffleElts);
17956 return Builder.CreateBitCast(ShuffleCall, RetTy);
17959 case PPC::BI__builtin_pack_vector_int128: {
17963 Value *PoisonValue =
17964 llvm::PoisonValue::get(llvm::FixedVectorType::get(Op0->
getType(), 2));
17966 PoisonValue, Op0, (uint64_t)(isLittleEndian ? 1 : 0));
17967 Res =
Builder.CreateInsertElement(Res, Op1,
17968 (uint64_t)(isLittleEndian ? 0 : 1));
17972 case PPC::BI__builtin_unpack_vector_int128: {
17975 ConstantInt *Index = cast<ConstantInt>(Op1);
17981 ConstantInt::get(Index->getIntegerType(), 1 - Index->getZExtValue());
17983 return Builder.CreateExtractElement(Unpacked, Index);
17986 case PPC::BI__builtin_ppc_sthcx: {
17990 return Builder.CreateCall(F, {Op0, Op1});
17999#define CUSTOM_BUILTIN(Name, Intr, Types, Accumulate, Feature) \
18000 case PPC::BI__builtin_##Name:
18001#include "clang/Basic/BuiltinsPPC.def"
18004 for (
unsigned i = 0, e =
E->getNumArgs(); i != e; i++)
18014 if (BuiltinID == PPC::BI__builtin_mma_disassemble_acc ||
18015 BuiltinID == PPC::BI__builtin_vsx_disassemble_pair ||
18016 BuiltinID == PPC::BI__builtin_mma_disassemble_pair) {
18017 unsigned NumVecs = 2;
18018 auto Intrinsic = Intrinsic::ppc_vsx_disassemble_pair;
18019 if (BuiltinID == PPC::BI__builtin_mma_disassemble_acc) {
18021 Intrinsic = Intrinsic::ppc_mma_disassemble_acc;
18027 llvm::Type *VTy = llvm::FixedVectorType::get(
Int8Ty, 16);
18028 Value *Ptr = Ops[0];
18029 for (
unsigned i=0; i<NumVecs; i++) {
18031 llvm::ConstantInt* Index = llvm::ConstantInt::get(
IntTy, i);
18037 if (BuiltinID == PPC::BI__builtin_vsx_build_pair ||
18038 BuiltinID == PPC::BI__builtin_mma_build_acc) {
18046 std::reverse(Ops.begin() + 1, Ops.end());
18049 switch (BuiltinID) {
18050 #define CUSTOM_BUILTIN(Name, Intr, Types, Acc, Feature) \
18051 case PPC::BI__builtin_##Name: \
18052 ID = Intrinsic::ppc_##Intr; \
18053 Accumulate = Acc; \
18055 #include "clang/Basic/BuiltinsPPC.def"
18057 if (BuiltinID == PPC::BI__builtin_vsx_lxvp ||
18058 BuiltinID == PPC::BI__builtin_vsx_stxvp ||
18059 BuiltinID == PPC::BI__builtin_mma_lxvp ||
18060 BuiltinID == PPC::BI__builtin_mma_stxvp) {
18061 if (BuiltinID == PPC::BI__builtin_vsx_lxvp ||
18062 BuiltinID == PPC::BI__builtin_mma_lxvp) {
18069 return Builder.CreateCall(F, Ops,
"");
18075 CallOps.push_back(Acc);
18077 for (
unsigned i=1; i<Ops.size(); i++)
18078 CallOps.push_back(Ops[i]);
18084 case PPC::BI__builtin_ppc_compare_and_swap:
18085 case PPC::BI__builtin_ppc_compare_and_swaplp: {
18094 llvm::AtomicOrdering::Monotonic, llvm::AtomicOrdering::Monotonic,
true);
18102 Value *LoadedVal = Pair.first.getScalarVal();
18106 case PPC::BI__builtin_ppc_fetch_and_add:
18107 case PPC::BI__builtin_ppc_fetch_and_addlp: {
18109 llvm::AtomicOrdering::Monotonic);
18111 case PPC::BI__builtin_ppc_fetch_and_and:
18112 case PPC::BI__builtin_ppc_fetch_and_andlp: {
18114 llvm::AtomicOrdering::Monotonic);
18117 case PPC::BI__builtin_ppc_fetch_and_or:
18118 case PPC::BI__builtin_ppc_fetch_and_orlp: {
18120 llvm::AtomicOrdering::Monotonic);
18122 case PPC::BI__builtin_ppc_fetch_and_swap:
18123 case PPC::BI__builtin_ppc_fetch_and_swaplp: {
18125 llvm::AtomicOrdering::Monotonic);
18127 case PPC::BI__builtin_ppc_ldarx:
18128 case PPC::BI__builtin_ppc_lwarx:
18129 case PPC::BI__builtin_ppc_lharx:
18130 case PPC::BI__builtin_ppc_lbarx:
18132 case PPC::BI__builtin_ppc_mfspr: {
18138 return Builder.CreateCall(F, {Op0});
18140 case PPC::BI__builtin_ppc_mtspr: {
18147 return Builder.CreateCall(F, {Op0, Op1});
18149 case PPC::BI__builtin_ppc_popcntb: {
18151 llvm::Type *ArgType = ArgValue->
getType();
18153 return Builder.CreateCall(F, {ArgValue},
"popcntb");
18155 case PPC::BI__builtin_ppc_mtfsf: {
18165 case PPC::BI__builtin_ppc_swdiv_nochk:
18166 case PPC::BI__builtin_ppc_swdivs_nochk: {
18169 FastMathFlags FMF =
Builder.getFastMathFlags();
18170 Builder.getFastMathFlags().setFast();
18171 Value *FDiv =
Builder.CreateFDiv(Op0, Op1,
"swdiv_nochk");
18172 Builder.getFastMathFlags() &= (FMF);
18175 case PPC::BI__builtin_ppc_fric:
18177 *
this,
E, Intrinsic::rint,
18178 Intrinsic::experimental_constrained_rint))
18180 case PPC::BI__builtin_ppc_frim:
18181 case PPC::BI__builtin_ppc_frims:
18183 *
this,
E, Intrinsic::floor,
18184 Intrinsic::experimental_constrained_floor))
18186 case PPC::BI__builtin_ppc_frin:
18187 case PPC::BI__builtin_ppc_frins:
18189 *
this,
E, Intrinsic::round,
18190 Intrinsic::experimental_constrained_round))
18192 case PPC::BI__builtin_ppc_frip:
18193 case PPC::BI__builtin_ppc_frips:
18195 *
this,
E, Intrinsic::ceil,
18196 Intrinsic::experimental_constrained_ceil))
18198 case PPC::BI__builtin_ppc_friz:
18199 case PPC::BI__builtin_ppc_frizs:
18201 *
this,
E, Intrinsic::trunc,
18202 Intrinsic::experimental_constrained_trunc))
18204 case PPC::BI__builtin_ppc_fsqrt:
18205 case PPC::BI__builtin_ppc_fsqrts:
18207 *
this,
E, Intrinsic::sqrt,
18208 Intrinsic::experimental_constrained_sqrt))
18210 case PPC::BI__builtin_ppc_test_data_class: {
18215 {Op0, Op1},
"test_data_class");
18217 case PPC::BI__builtin_ppc_maxfe: {
18223 {Op0, Op1, Op2, Op3});
18225 case PPC::BI__builtin_ppc_maxfl: {
18231 {Op0, Op1, Op2, Op3});
18233 case PPC::BI__builtin_ppc_maxfs: {
18239 {Op0, Op1, Op2, Op3});
18241 case PPC::BI__builtin_ppc_minfe: {
18247 {Op0, Op1, Op2, Op3});
18249 case PPC::BI__builtin_ppc_minfl: {
18255 {Op0, Op1, Op2, Op3});
18257 case PPC::BI__builtin_ppc_minfs: {
18263 {Op0, Op1, Op2, Op3});
18265 case PPC::BI__builtin_ppc_swdiv:
18266 case PPC::BI__builtin_ppc_swdivs: {
18269 return Builder.CreateFDiv(Op0, Op1,
"swdiv");
18271 case PPC::BI__builtin_ppc_set_fpscr_rn:
18273 {EmitScalarExpr(E->getArg(0))});
18274 case PPC::BI__builtin_ppc_mffs:
18287 Attribute::getWithDereferenceableBytes(
Call->getContext(), 64));
18288 Call->addRetAttr(Attribute::getWithAlignment(
Call->getContext(), Align(4)));
18292 auto *RetTy = cast<llvm::PointerType>(CGF.
ConvertType(BuiltinRetType));
18293 if (RetTy ==
Call->getType())
18302 Attribute::getWithDereferenceableBytes(
Call->getContext(), 256));
18303 Call->addRetAttr(Attribute::getWithAlignment(
Call->getContext(), Align(8)));
18318 llvm::LoadInst *LD;
18322 if (Cov == CodeObjectVersionKind::COV_None) {
18323 StringRef Name =
"__oclc_ABI_version";
18324 auto *ABIVersionC = CGF.
CGM.
getModule().getNamedGlobal(Name);
18326 ABIVersionC =
new llvm::GlobalVariable(
18328 llvm::GlobalValue::ExternalLinkage,
nullptr, Name,
nullptr,
18329 llvm::GlobalVariable::NotThreadLocal,
18340 llvm::ConstantInt::get(CGF.
Int32Ty, CodeObjectVersionKind::COV_5));
18344 CGF.
Int8Ty, EmitAMDGPUImplicitArgPtr(CGF), 12 + Index * 2);
18348 CGF.
Int8Ty, EmitAMDGPUDispatchPtr(CGF), 4 + Index * 2);
18350 auto Result = CGF.
Builder.CreateSelect(IsCOV5, ImplicitGEP, DispatchGEP);
18354 Value *GEP =
nullptr;
18355 if (Cov >= CodeObjectVersionKind::COV_5) {
18357 GEP = CGF.
Builder.CreateConstGEP1_32(
18358 CGF.
Int8Ty, EmitAMDGPUImplicitArgPtr(CGF), 12 + Index * 2);
18361 GEP = CGF.
Builder.CreateConstGEP1_32(
18362 CGF.
Int8Ty, EmitAMDGPUDispatchPtr(CGF), 4 + Index * 2);
18369 llvm::MDNode *RNode = MDHelper.createRange(
APInt(16, 1),
18371 LD->setMetadata(llvm::LLVMContext::MD_range, RNode);
18372 LD->setMetadata(llvm::LLVMContext::MD_noundef,
18374 LD->setMetadata(llvm::LLVMContext::MD_invariant_load,
18381 const unsigned XOffset = 12;
18382 auto *DP = EmitAMDGPUDispatchPtr(CGF);
18384 auto *Offset = llvm::ConstantInt::get(CGF.
Int32Ty, XOffset + Index * 4);
18388 LD->setMetadata(llvm::LLVMContext::MD_invariant_load,
18401 llvm::AtomicOrdering &AO,
18402 llvm::SyncScope::ID &SSID) {
18403 int ord = cast<llvm::ConstantInt>(Order)->getZExtValue();
18406 assert(llvm::isValidAtomicOrderingCABI(ord));
18407 switch (
static_cast<llvm::AtomicOrderingCABI
>(ord)) {
18408 case llvm::AtomicOrderingCABI::acquire:
18409 case llvm::AtomicOrderingCABI::consume:
18410 AO = llvm::AtomicOrdering::Acquire;
18412 case llvm::AtomicOrderingCABI::release:
18413 AO = llvm::AtomicOrdering::Release;
18415 case llvm::AtomicOrderingCABI::acq_rel:
18416 AO = llvm::AtomicOrdering::AcquireRelease;
18418 case llvm::AtomicOrderingCABI::seq_cst:
18419 AO = llvm::AtomicOrdering::SequentiallyConsistent;
18421 case llvm::AtomicOrderingCABI::relaxed:
18422 AO = llvm::AtomicOrdering::Monotonic;
18428 if (llvm::getConstantStringInfo(
Scope, scp)) {
18434 int scope = cast<llvm::ConstantInt>(
Scope)->getZExtValue();
18437 SSID = llvm::SyncScope::System;
18449 SSID = llvm::SyncScope::SingleThread;
18452 SSID = llvm::SyncScope::System;
18460 llvm::Value *Arg =
nullptr;
18461 if ((ICEArguments & (1 << Idx)) == 0) {
18466 std::optional<llvm::APSInt>
Result =
18468 assert(
Result &&
"Expected argument to be a constant");
18476 switch (elementCount) {
18478 return Intrinsic::dx_dot2;
18480 return Intrinsic::dx_dot3;
18482 return Intrinsic::dx_dot4;
18486 return Intrinsic::dx_sdot;
18489 return Intrinsic::dx_udot;
18497 switch (BuiltinID) {
18498 case Builtin::BI__builtin_hlsl_all: {
18500 return Builder.CreateIntrinsic(
18505 case Builtin::BI__builtin_hlsl_any: {
18507 return Builder.CreateIntrinsic(
18512 case Builtin::BI__builtin_hlsl_elementwise_clamp: {
18518 bool IsUnsigned =
false;
18520 Ty = VecTy->getElementType();
18522 return Builder.CreateIntrinsic(
18524 IsUnsigned ? Intrinsic::dx_uclamp : Intrinsic::dx_clamp,
18527 case Builtin::BI__builtin_hlsl_dot: {
18530 llvm::Type *T0 = Op0->
getType();
18531 llvm::Type *T1 = Op1->
getType();
18532 if (!T0->isVectorTy() && !T1->isVectorTy()) {
18533 if (T0->isFloatingPointTy())
18534 return Builder.CreateFMul(Op0, Op1,
"dx.dot");
18536 if (T0->isIntegerTy())
18537 return Builder.CreateMul(Op0, Op1,
"dx.dot");
18541 "Scalar dot product is only supported on ints and floats.");
18544 assert(T0->isVectorTy() && T1->isVectorTy() &&
18545 "Dot product of vector and scalar is not supported.");
18548 assert(T0->getScalarType() == T1->getScalarType() &&
18549 "Dot product of vectors need the same element types.");
18552 [[maybe_unused]]
auto *VecTy1 =
18556 "Dot product requires vectors to be of the same size.");
18558 return Builder.CreateIntrinsic(
18559 T0->getScalarType(),
18561 VecTy0->getNumElements()),
18564 case Builtin::BI__builtin_hlsl_lerp: {
18569 llvm_unreachable(
"lerp operand must have a float representation");
18570 return Builder.CreateIntrinsic(
18574 case Builtin::BI__builtin_hlsl_length: {
18578 "length operand must have a float representation");
18583 return Builder.CreateIntrinsic(
18584 X->getType()->getScalarType(),
18586 nullptr,
"hlsl.length");
18588 case Builtin::BI__builtin_hlsl_normalize: {
18592 "normalize operand must have a float representation");
18594 return Builder.CreateIntrinsic(
18597 nullptr,
"hlsl.normalize");
18599 case Builtin::BI__builtin_hlsl_elementwise_frac: {
18602 llvm_unreachable(
"frac operand must have a float representation");
18603 return Builder.CreateIntrinsic(
18607case Builtin::BI__builtin_hlsl_elementwise_isinf: {
18609 llvm::Type *Xty = Op0->
getType();
18610 llvm::Type *retType = llvm::Type::getInt1Ty(this->
getLLVMContext());
18611 if (Xty->isVectorTy()) {
18613 retType = llvm::VectorType::get(
18614 retType, ElementCount::getFixed(XVecTy->getNumElements()));
18617 llvm_unreachable(
"isinf operand must have a float representation");
18618 return Builder.CreateIntrinsic(retType, Intrinsic::dx_isinf,
18621 case Builtin::BI__builtin_hlsl_mad: {
18626 return Builder.CreateIntrinsic(
18627 M->
getType(), Intrinsic::fmuladd,
18632 return Builder.CreateIntrinsic(
18633 M->
getType(), Intrinsic::dx_imad,
18637 return Builder.CreateNSWAdd(Mul, B);
18641 return Builder.CreateIntrinsic(
18642 M->
getType(), Intrinsic::dx_umad,
18646 return Builder.CreateNUWAdd(Mul, B);
18648 case Builtin::BI__builtin_hlsl_elementwise_rcp: {
18651 llvm_unreachable(
"rcp operand must have a float representation");
18652 llvm::Type *Ty = Op0->
getType();
18653 llvm::Type *EltTy = Ty->getScalarType();
18654 Constant *One = Ty->isVectorTy()
18655 ? ConstantVector::getSplat(
18656 ElementCount::getFixed(
18657 cast<FixedVectorType>(Ty)->getNumElements()),
18658 ConstantFP::get(EltTy, 1.0))
18659 : ConstantFP::get(EltTy, 1.0);
18660 return Builder.CreateFDiv(One, Op0,
"hlsl.rcp");
18662 case Builtin::BI__builtin_hlsl_elementwise_rsqrt: {
18665 llvm_unreachable(
"rsqrt operand must have a float representation");
18666 return Builder.CreateIntrinsic(
18670 case Builtin::BI__builtin_hlsl_elementwise_saturate: {
18673 "saturate operand must have a float representation");
18674 return Builder.CreateIntrinsic(
18677 nullptr,
"hlsl.saturate");
18679 case Builtin::BI__builtin_hlsl_wave_get_lane_index: {
18681 llvm::FunctionType::get(
IntTy, {},
false),
"__hlsl_wave_get_lane_index",
18690 constexpr const char *
Tag =
"amdgpu-as";
18692 LLVMContext &Ctx = Inst->getContext();
18694 for (
unsigned K = 2; K <
E->getNumArgs(); ++K) {
18697 if (llvm::getConstantStringInfo(
V, AS)) {
18698 MMRAs.push_back({
Tag, AS});
18703 "expected an address space name as a string literal");
18707 MMRAs.erase(llvm::unique(MMRAs), MMRAs.end());
18708 Inst->setMetadata(LLVMContext::MD_mmra, MMRAMetadata::getMD(Ctx, MMRAs));
18713 llvm::AtomicOrdering AO = llvm::AtomicOrdering::SequentiallyConsistent;
18714 llvm::SyncScope::ID SSID;
18715 switch (BuiltinID) {
18716 case AMDGPU::BI__builtin_amdgcn_div_scale:
18717 case AMDGPU::BI__builtin_amdgcn_div_scalef: {
18730 llvm::Value *Tmp =
Builder.CreateCall(Callee, {
X, Y, Z});
18733 llvm::Value *Flag =
Builder.CreateExtractValue(Tmp, 1);
18737 llvm::Value *FlagExt =
Builder.CreateZExt(Flag, RealFlagType);
18741 case AMDGPU::BI__builtin_amdgcn_div_fmas:
18742 case AMDGPU::BI__builtin_amdgcn_div_fmasf: {
18750 llvm::Value *Src3ToBool =
Builder.CreateIsNotNull(Src3);
18751 return Builder.CreateCall(F, {Src0, Src1, Src2, Src3ToBool});
18754 case AMDGPU::BI__builtin_amdgcn_ds_swizzle:
18755 return emitBuiltinWithOneOverloadedType<2>(*
this,
E,
18756 Intrinsic::amdgcn_ds_swizzle);
18757 case AMDGPU::BI__builtin_amdgcn_mov_dpp8:
18758 return emitBuiltinWithOneOverloadedType<2>(*
this,
E,
18759 Intrinsic::amdgcn_mov_dpp8);
18760 case AMDGPU::BI__builtin_amdgcn_mov_dpp:
18761 case AMDGPU::BI__builtin_amdgcn_update_dpp: {
18765 unsigned ICEArguments = 0;
18769 for (
unsigned I = 0; I !=
E->getNumArgs(); ++I) {
18772 assert(Args.size() == 5 || Args.size() == 6);
18773 if (Args.size() == 5)
18774 Args.insert(Args.begin(), llvm::PoisonValue::get(Args[0]->getType()));
18777 return Builder.CreateCall(F, Args);
18779 case AMDGPU::BI__builtin_amdgcn_permlane16:
18780 case AMDGPU::BI__builtin_amdgcn_permlanex16:
18781 return emitBuiltinWithOneOverloadedType<6>(
18783 BuiltinID == AMDGPU::BI__builtin_amdgcn_permlane16
18784 ? Intrinsic::amdgcn_permlane16
18785 : Intrinsic::amdgcn_permlanex16);
18786 case AMDGPU::BI__builtin_amdgcn_permlane64:
18787 return emitBuiltinWithOneOverloadedType<1>(*
this,
E,
18788 Intrinsic::amdgcn_permlane64);
18789 case AMDGPU::BI__builtin_amdgcn_readlane:
18790 return emitBuiltinWithOneOverloadedType<2>(*
this,
E,
18791 Intrinsic::amdgcn_readlane);
18792 case AMDGPU::BI__builtin_amdgcn_readfirstlane:
18793 return emitBuiltinWithOneOverloadedType<1>(*
this,
E,
18794 Intrinsic::amdgcn_readfirstlane);
18795 case AMDGPU::BI__builtin_amdgcn_div_fixup:
18796 case AMDGPU::BI__builtin_amdgcn_div_fixupf:
18797 case AMDGPU::BI__builtin_amdgcn_div_fixuph:
18798 return emitBuiltinWithOneOverloadedType<3>(*
this,
E,
18799 Intrinsic::amdgcn_div_fixup);
18800 case AMDGPU::BI__builtin_amdgcn_trig_preop:
18801 case AMDGPU::BI__builtin_amdgcn_trig_preopf:
18803 case AMDGPU::BI__builtin_amdgcn_rcp:
18804 case AMDGPU::BI__builtin_amdgcn_rcpf:
18805 case AMDGPU::BI__builtin_amdgcn_rcph:
18806 return emitBuiltinWithOneOverloadedType<1>(*
this,
E, Intrinsic::amdgcn_rcp);
18807 case AMDGPU::BI__builtin_amdgcn_sqrt:
18808 case AMDGPU::BI__builtin_amdgcn_sqrtf:
18809 case AMDGPU::BI__builtin_amdgcn_sqrth:
18810 return emitBuiltinWithOneOverloadedType<1>(*
this,
E,
18811 Intrinsic::amdgcn_sqrt);
18812 case AMDGPU::BI__builtin_amdgcn_rsq:
18813 case AMDGPU::BI__builtin_amdgcn_rsqf:
18814 case AMDGPU::BI__builtin_amdgcn_rsqh:
18815 return emitBuiltinWithOneOverloadedType<1>(*
this,
E, Intrinsic::amdgcn_rsq);
18816 case AMDGPU::BI__builtin_amdgcn_rsq_clamp:
18817 case AMDGPU::BI__builtin_amdgcn_rsq_clampf:
18818 return emitBuiltinWithOneOverloadedType<1>(*
this,
E,
18819 Intrinsic::amdgcn_rsq_clamp);
18820 case AMDGPU::BI__builtin_amdgcn_sinf:
18821 case AMDGPU::BI__builtin_amdgcn_sinh:
18822 return emitBuiltinWithOneOverloadedType<1>(*
this,
E, Intrinsic::amdgcn_sin);
18823 case AMDGPU::BI__builtin_amdgcn_cosf:
18824 case AMDGPU::BI__builtin_amdgcn_cosh:
18825 return emitBuiltinWithOneOverloadedType<1>(*
this,
E, Intrinsic::amdgcn_cos);
18826 case AMDGPU::BI__builtin_amdgcn_dispatch_ptr:
18827 return EmitAMDGPUDispatchPtr(*
this,
E);
18828 case AMDGPU::BI__builtin_amdgcn_logf:
18829 return emitBuiltinWithOneOverloadedType<1>(*
this,
E, Intrinsic::amdgcn_log);
18830 case AMDGPU::BI__builtin_amdgcn_exp2f:
18831 return emitBuiltinWithOneOverloadedType<1>(*
this,
E,
18832 Intrinsic::amdgcn_exp2);
18833 case AMDGPU::BI__builtin_amdgcn_log_clampf:
18834 return emitBuiltinWithOneOverloadedType<1>(*
this,
E,
18835 Intrinsic::amdgcn_log_clamp);
18836 case AMDGPU::BI__builtin_amdgcn_ldexp:
18837 case AMDGPU::BI__builtin_amdgcn_ldexpf: {
18840 llvm::Function *F =
18841 CGM.
getIntrinsic(Intrinsic::ldexp, {Src0->getType(), Src1->getType()});
18842 return Builder.CreateCall(F, {Src0, Src1});
18844 case AMDGPU::BI__builtin_amdgcn_ldexph: {
18849 llvm::Function *F =
18853 case AMDGPU::BI__builtin_amdgcn_frexp_mant:
18854 case AMDGPU::BI__builtin_amdgcn_frexp_mantf:
18855 case AMDGPU::BI__builtin_amdgcn_frexp_manth:
18856 return emitBuiltinWithOneOverloadedType<1>(*
this,
E,
18857 Intrinsic::amdgcn_frexp_mant);
18858 case AMDGPU::BI__builtin_amdgcn_frexp_exp:
18859 case AMDGPU::BI__builtin_amdgcn_frexp_expf: {
18863 return Builder.CreateCall(F, Src0);
18865 case AMDGPU::BI__builtin_amdgcn_frexp_exph: {
18869 return Builder.CreateCall(F, Src0);
18871 case AMDGPU::BI__builtin_amdgcn_fract:
18872 case AMDGPU::BI__builtin_amdgcn_fractf:
18873 case AMDGPU::BI__builtin_amdgcn_fracth:
18874 return emitBuiltinWithOneOverloadedType<1>(*
this,
E,
18875 Intrinsic::amdgcn_fract);
18876 case AMDGPU::BI__builtin_amdgcn_lerp:
18877 return emitBuiltinWithOneOverloadedType<3>(*
this,
E,
18878 Intrinsic::amdgcn_lerp);
18879 case AMDGPU::BI__builtin_amdgcn_ubfe:
18880 return emitBuiltinWithOneOverloadedType<3>(*
this,
E,
18881 Intrinsic::amdgcn_ubfe);
18882 case AMDGPU::BI__builtin_amdgcn_sbfe:
18883 return emitBuiltinWithOneOverloadedType<3>(*
this,
E,
18884 Intrinsic::amdgcn_sbfe);
18885 case AMDGPU::BI__builtin_amdgcn_ballot_w32:
18886 case AMDGPU::BI__builtin_amdgcn_ballot_w64: {
18890 return Builder.CreateCall(F, { Src });
18892 case AMDGPU::BI__builtin_amdgcn_uicmp:
18893 case AMDGPU::BI__builtin_amdgcn_uicmpl:
18894 case AMDGPU::BI__builtin_amdgcn_sicmp:
18895 case AMDGPU::BI__builtin_amdgcn_sicmpl: {
18902 {
Builder.getInt64Ty(), Src0->getType() });
18903 return Builder.CreateCall(F, { Src0, Src1, Src2 });
18905 case AMDGPU::BI__builtin_amdgcn_fcmp:
18906 case AMDGPU::BI__builtin_amdgcn_fcmpf: {
18913 {
Builder.getInt64Ty(), Src0->getType() });
18914 return Builder.CreateCall(F, { Src0, Src1, Src2 });
18916 case AMDGPU::BI__builtin_amdgcn_class:
18917 case AMDGPU::BI__builtin_amdgcn_classf:
18918 case AMDGPU::BI__builtin_amdgcn_classh:
18920 case AMDGPU::BI__builtin_amdgcn_fmed3f:
18921 case AMDGPU::BI__builtin_amdgcn_fmed3h:
18922 return emitBuiltinWithOneOverloadedType<3>(*
this,
E,
18923 Intrinsic::amdgcn_fmed3);
18924 case AMDGPU::BI__builtin_amdgcn_ds_append:
18925 case AMDGPU::BI__builtin_amdgcn_ds_consume: {
18926 Intrinsic::ID Intrin = BuiltinID == AMDGPU::BI__builtin_amdgcn_ds_append ?
18927 Intrinsic::amdgcn_ds_append : Intrinsic::amdgcn_ds_consume;
18932 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b64_i32:
18933 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b64_v2i32:
18934 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v4i16:
18935 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v4f16:
18936 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v4bf16:
18937 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v8i16:
18938 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v8f16:
18939 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v8bf16: {
18942 switch (BuiltinID) {
18943 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b64_i32:
18944 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b64_v2i32:
18945 IID = Intrinsic::amdgcn_global_load_tr_b64;
18947 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v4i16:
18948 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v4f16:
18949 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v4bf16:
18950 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v8i16:
18951 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v8f16:
18952 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v8bf16:
18953 IID = Intrinsic::amdgcn_global_load_tr_b128;
18959 return Builder.CreateCall(F, {Addr});
18961 case AMDGPU::BI__builtin_amdgcn_get_fpenv: {
18964 return Builder.CreateCall(F);
18966 case AMDGPU::BI__builtin_amdgcn_set_fpenv: {
18972 case AMDGPU::BI__builtin_amdgcn_read_exec:
18974 case AMDGPU::BI__builtin_amdgcn_read_exec_lo:
18976 case AMDGPU::BI__builtin_amdgcn_read_exec_hi:
18978 case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray:
18979 case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray_h:
18980 case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray_l:
18981 case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray_lh: {
18991 RayOrigin =
Builder.CreateShuffleVector(RayOrigin, RayOrigin,
18995 RayInverseDir =
Builder.CreateShuffleVector(RayInverseDir, RayInverseDir,
18999 {NodePtr->getType(), RayDir->getType()});
19000 return Builder.CreateCall(F, {NodePtr, RayExtent, RayOrigin, RayDir,
19001 RayInverseDir, TextureDescr});
19004 case AMDGPU::BI__builtin_amdgcn_ds_bvh_stack_rtn: {
19006 for (
int i = 0, e =
E->getNumArgs(); i != e; ++i)
19014 Value *I0 =
Builder.CreateInsertElement(PoisonValue::get(RetTy), Rtn,
19016 return Builder.CreateInsertElement(I0, A, 1);
19019 case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x16_bf16_w32:
19020 case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x16_bf16_tied_w32:
19021 case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x16_bf16_w64:
19022 case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x16_bf16_tied_w64:
19023 case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x16_f16_w32:
19024 case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x16_f16_tied_w32:
19025 case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x16_f16_w64:
19026 case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x16_f16_tied_w64:
19027 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf16_w32:
19028 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf16_w64:
19029 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_f16_w32:
19030 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_f16_w64:
19031 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu4_w32:
19032 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu4_w64:
19033 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu8_w32:
19034 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu8_w64:
19035 case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x16_bf16_w32_gfx12:
19036 case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x16_bf16_w64_gfx12:
19037 case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x16_f16_w32_gfx12:
19038 case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x16_f16_w64_gfx12:
19039 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf16_w32_gfx12:
19040 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf16_w64_gfx12:
19041 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_f16_w32_gfx12:
19042 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_f16_w64_gfx12:
19043 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu4_w32_gfx12:
19044 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu4_w64_gfx12:
19045 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu8_w32_gfx12:
19046 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu8_w64_gfx12:
19047 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_fp8_fp8_w32_gfx12:
19048 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_fp8_fp8_w64_gfx12:
19049 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_fp8_bf8_w32_gfx12:
19050 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_fp8_bf8_w64_gfx12:
19051 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf8_fp8_w32_gfx12:
19052 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf8_fp8_w64_gfx12:
19053 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf8_bf8_w32_gfx12:
19054 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf8_bf8_w64_gfx12:
19055 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x32_iu4_w32_gfx12:
19056 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x32_iu4_w64_gfx12:
19057 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_f16_w32:
19058 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_f16_w64:
19059 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf16_w32:
19060 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf16_w64:
19061 case AMDGPU::BI__builtin_amdgcn_swmmac_f16_16x16x32_f16_w32:
19062 case AMDGPU::BI__builtin_amdgcn_swmmac_f16_16x16x32_f16_w64:
19063 case AMDGPU::BI__builtin_amdgcn_swmmac_bf16_16x16x32_bf16_w32:
19064 case AMDGPU::BI__builtin_amdgcn_swmmac_bf16_16x16x32_bf16_w64:
19065 case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x32_iu8_w32:
19066 case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x32_iu8_w64:
19067 case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x32_iu4_w32:
19068 case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x32_iu4_w64:
19069 case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x64_iu4_w32:
19070 case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x64_iu4_w64:
19071 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_fp8_fp8_w32:
19072 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_fp8_fp8_w64:
19073 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_fp8_bf8_w32:
19074 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_fp8_bf8_w64:
19075 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf8_fp8_w32:
19076 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf8_fp8_w64:
19077 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf8_bf8_w32:
19078 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf8_bf8_w64: {
19091 bool AppendFalseForOpselArg =
false;
19092 unsigned BuiltinWMMAOp;
19094 switch (BuiltinID) {
19095 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_f16_w32:
19096 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_f16_w64:
19097 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_f16_w32_gfx12:
19098 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_f16_w64_gfx12:
19099 ArgsForMatchingMatrixTypes = {2, 0};
19100 BuiltinWMMAOp = Intrinsic::amdgcn_wmma_f32_16x16x16_f16;
19102 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf16_w32:
19103 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf16_w64:
19104 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf16_w32_gfx12:
19105 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf16_w64_gfx12:
19106 ArgsForMatchingMatrixTypes = {2, 0};
19107 BuiltinWMMAOp = Intrinsic::amdgcn_wmma_f32_16x16x16_bf16;
19109 case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x16_f16_w32_gfx12:
19110 case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x16_f16_w64_gfx12:
19111 AppendFalseForOpselArg =
true;
19113 case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x16_f16_w32:
19114 case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x16_f16_w64:
19115 ArgsForMatchingMatrixTypes = {2, 0};
19116 BuiltinWMMAOp = Intrinsic::amdgcn_wmma_f16_16x16x16_f16;
19118 case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x16_bf16_w32_gfx12:
19119 case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x16_bf16_w64_gfx12:
19120 AppendFalseForOpselArg =
true;
19122 case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x16_bf16_w32:
19123 case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x16_bf16_w64:
19124 ArgsForMatchingMatrixTypes = {2, 0};
19125 BuiltinWMMAOp = Intrinsic::amdgcn_wmma_bf16_16x16x16_bf16;
19127 case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x16_f16_tied_w32:
19128 case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x16_f16_tied_w64:
19129 ArgsForMatchingMatrixTypes = {2, 0};
19130 BuiltinWMMAOp = Intrinsic::amdgcn_wmma_f16_16x16x16_f16_tied;
19132 case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x16_bf16_tied_w32:
19133 case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x16_bf16_tied_w64:
19134 ArgsForMatchingMatrixTypes = {2, 0};
19135 BuiltinWMMAOp = Intrinsic::amdgcn_wmma_bf16_16x16x16_bf16_tied;
19137 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu8_w32:
19138 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu8_w64:
19139 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu8_w32_gfx12:
19140 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu8_w64_gfx12:
19141 ArgsForMatchingMatrixTypes = {4, 1};
19142 BuiltinWMMAOp = Intrinsic::amdgcn_wmma_i32_16x16x16_iu8;
19144 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu4_w32:
19145 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu4_w64:
19146 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu4_w32_gfx12:
19147 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu4_w64_gfx12:
19148 ArgsForMatchingMatrixTypes = {4, 1};
19149 BuiltinWMMAOp = Intrinsic::amdgcn_wmma_i32_16x16x16_iu4;
19151 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_fp8_fp8_w32_gfx12:
19152 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_fp8_fp8_w64_gfx12:
19153 ArgsForMatchingMatrixTypes = {2, 0};
19154 BuiltinWMMAOp = Intrinsic::amdgcn_wmma_f32_16x16x16_fp8_fp8;
19156 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_fp8_bf8_w32_gfx12:
19157 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_fp8_bf8_w64_gfx12:
19158 ArgsForMatchingMatrixTypes = {2, 0};
19159 BuiltinWMMAOp = Intrinsic::amdgcn_wmma_f32_16x16x16_fp8_bf8;
19161 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf8_fp8_w32_gfx12:
19162 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf8_fp8_w64_gfx12:
19163 ArgsForMatchingMatrixTypes = {2, 0};
19164 BuiltinWMMAOp = Intrinsic::amdgcn_wmma_f32_16x16x16_bf8_fp8;
19166 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf8_bf8_w32_gfx12:
19167 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf8_bf8_w64_gfx12:
19168 ArgsForMatchingMatrixTypes = {2, 0};
19169 BuiltinWMMAOp = Intrinsic::amdgcn_wmma_f32_16x16x16_bf8_bf8;
19171 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x32_iu4_w32_gfx12:
19172 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x32_iu4_w64_gfx12:
19173 ArgsForMatchingMatrixTypes = {4, 1};
19174 BuiltinWMMAOp = Intrinsic::amdgcn_wmma_i32_16x16x32_iu4;
19176 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_f16_w32:
19177 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_f16_w64:
19178 ArgsForMatchingMatrixTypes = {2, 0, 1, 3};
19179 BuiltinWMMAOp = Intrinsic::amdgcn_swmmac_f32_16x16x32_f16;
19181 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf16_w32:
19182 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf16_w64:
19183 ArgsForMatchingMatrixTypes = {2, 0, 1, 3};
19184 BuiltinWMMAOp = Intrinsic::amdgcn_swmmac_f32_16x16x32_bf16;
19186 case AMDGPU::BI__builtin_amdgcn_swmmac_f16_16x16x32_f16_w32:
19187 case AMDGPU::BI__builtin_amdgcn_swmmac_f16_16x16x32_f16_w64:
19188 ArgsForMatchingMatrixTypes = {2, 0, 1, 3};
19189 BuiltinWMMAOp = Intrinsic::amdgcn_swmmac_f16_16x16x32_f16;
19191 case AMDGPU::BI__builtin_amdgcn_swmmac_bf16_16x16x32_bf16_w32:
19192 case AMDGPU::BI__builtin_amdgcn_swmmac_bf16_16x16x32_bf16_w64:
19193 ArgsForMatchingMatrixTypes = {2, 0, 1, 3};
19194 BuiltinWMMAOp = Intrinsic::amdgcn_swmmac_bf16_16x16x32_bf16;
19196 case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x32_iu8_w32:
19197 case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x32_iu8_w64:
19198 ArgsForMatchingMatrixTypes = {4, 1, 3, 5};
19199 BuiltinWMMAOp = Intrinsic::amdgcn_swmmac_i32_16x16x32_iu8;
19201 case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x32_iu4_w32:
19202 case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x32_iu4_w64:
19203 ArgsForMatchingMatrixTypes = {4, 1, 3, 5};
19204 BuiltinWMMAOp = Intrinsic::amdgcn_swmmac_i32_16x16x32_iu4;
19206 case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x64_iu4_w32:
19207 case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x64_iu4_w64:
19208 ArgsForMatchingMatrixTypes = {4, 1, 3, 5};
19209 BuiltinWMMAOp = Intrinsic::amdgcn_swmmac_i32_16x16x64_iu4;
19211 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_fp8_fp8_w32:
19212 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_fp8_fp8_w64:
19213 ArgsForMatchingMatrixTypes = {2, 0, 1, 3};
19214 BuiltinWMMAOp = Intrinsic::amdgcn_swmmac_f32_16x16x32_fp8_fp8;
19216 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_fp8_bf8_w32:
19217 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_fp8_bf8_w64:
19218 ArgsForMatchingMatrixTypes = {2, 0, 1, 3};
19219 BuiltinWMMAOp = Intrinsic::amdgcn_swmmac_f32_16x16x32_fp8_bf8;
19221 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf8_fp8_w32:
19222 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf8_fp8_w64:
19223 ArgsForMatchingMatrixTypes = {2, 0, 1, 3};
19224 BuiltinWMMAOp = Intrinsic::amdgcn_swmmac_f32_16x16x32_bf8_fp8;
19226 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf8_bf8_w32:
19227 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf8_bf8_w64:
19228 ArgsForMatchingMatrixTypes = {2, 0, 1, 3};
19229 BuiltinWMMAOp = Intrinsic::amdgcn_swmmac_f32_16x16x32_bf8_bf8;
19234 for (
int i = 0, e =
E->getNumArgs(); i != e; ++i)
19236 if (AppendFalseForOpselArg)
19237 Args.push_back(
Builder.getFalse());
19240 for (
auto ArgIdx : ArgsForMatchingMatrixTypes)
19241 ArgTypes.push_back(Args[ArgIdx]->getType());
19244 return Builder.CreateCall(F, Args);
19248 case AMDGPU::BI__builtin_amdgcn_workitem_id_x:
19250 case AMDGPU::BI__builtin_amdgcn_workitem_id_y:
19252 case AMDGPU::BI__builtin_amdgcn_workitem_id_z:
19256 case AMDGPU::BI__builtin_amdgcn_workgroup_size_x:
19257 return EmitAMDGPUWorkGroupSize(*
this, 0);
19258 case AMDGPU::BI__builtin_amdgcn_workgroup_size_y:
19259 return EmitAMDGPUWorkGroupSize(*
this, 1);
19260 case AMDGPU::BI__builtin_amdgcn_workgroup_size_z:
19261 return EmitAMDGPUWorkGroupSize(*
this, 2);
19264 case AMDGPU::BI__builtin_amdgcn_grid_size_x:
19265 return EmitAMDGPUGridSize(*
this, 0);
19266 case AMDGPU::BI__builtin_amdgcn_grid_size_y:
19267 return EmitAMDGPUGridSize(*
this, 1);
19268 case AMDGPU::BI__builtin_amdgcn_grid_size_z:
19269 return EmitAMDGPUGridSize(*
this, 2);
19272 case AMDGPU::BI__builtin_r600_recipsqrt_ieee:
19273 case AMDGPU::BI__builtin_r600_recipsqrt_ieeef:
19274 return emitBuiltinWithOneOverloadedType<1>(*
this,
E,
19275 Intrinsic::r600_recipsqrt_ieee);
19276 case AMDGPU::BI__builtin_r600_read_tidig_x:
19278 case AMDGPU::BI__builtin_r600_read_tidig_y:
19280 case AMDGPU::BI__builtin_r600_read_tidig_z:
19282 case AMDGPU::BI__builtin_amdgcn_alignbit: {
19287 return Builder.CreateCall(F, { Src0, Src1, Src2 });
19289 case AMDGPU::BI__builtin_amdgcn_fence: {
19292 FenceInst *Fence =
Builder.CreateFence(AO, SSID);
19293 if (
E->getNumArgs() > 2)
19297 case AMDGPU::BI__builtin_amdgcn_atomic_inc32:
19298 case AMDGPU::BI__builtin_amdgcn_atomic_inc64:
19299 case AMDGPU::BI__builtin_amdgcn_atomic_dec32:
19300 case AMDGPU::BI__builtin_amdgcn_atomic_dec64:
19301 case AMDGPU::BI__builtin_amdgcn_ds_atomic_fadd_f64:
19302 case AMDGPU::BI__builtin_amdgcn_ds_atomic_fadd_f32:
19303 case AMDGPU::BI__builtin_amdgcn_ds_atomic_fadd_v2f16:
19304 case AMDGPU::BI__builtin_amdgcn_ds_atomic_fadd_v2bf16:
19305 case AMDGPU::BI__builtin_amdgcn_ds_faddf:
19306 case AMDGPU::BI__builtin_amdgcn_ds_fminf:
19307 case AMDGPU::BI__builtin_amdgcn_ds_fmaxf:
19308 case AMDGPU::BI__builtin_amdgcn_global_atomic_fadd_f32:
19309 case AMDGPU::BI__builtin_amdgcn_global_atomic_fadd_f64:
19310 case AMDGPU::BI__builtin_amdgcn_global_atomic_fadd_v2f16:
19311 case AMDGPU::BI__builtin_amdgcn_flat_atomic_fadd_v2f16:
19312 case AMDGPU::BI__builtin_amdgcn_flat_atomic_fadd_f32:
19313 case AMDGPU::BI__builtin_amdgcn_flat_atomic_fadd_f64:
19314 case AMDGPU::BI__builtin_amdgcn_global_atomic_fadd_v2bf16:
19315 case AMDGPU::BI__builtin_amdgcn_flat_atomic_fadd_v2bf16:
19316 case AMDGPU::BI__builtin_amdgcn_global_atomic_fmin_f64:
19317 case AMDGPU::BI__builtin_amdgcn_global_atomic_fmax_f64:
19318 case AMDGPU::BI__builtin_amdgcn_flat_atomic_fmin_f64:
19319 case AMDGPU::BI__builtin_amdgcn_flat_atomic_fmax_f64: {
19320 llvm::AtomicRMWInst::BinOp BinOp;
19321 switch (BuiltinID) {
19322 case AMDGPU::BI__builtin_amdgcn_atomic_inc32:
19323 case AMDGPU::BI__builtin_amdgcn_atomic_inc64:
19324 BinOp = llvm::AtomicRMWInst::UIncWrap;
19326 case AMDGPU::BI__builtin_amdgcn_atomic_dec32:
19327 case AMDGPU::BI__builtin_amdgcn_atomic_dec64:
19328 BinOp = llvm::AtomicRMWInst::UDecWrap;
19330 case AMDGPU::BI__builtin_amdgcn_ds_faddf:
19331 case AMDGPU::BI__builtin_amdgcn_ds_atomic_fadd_f64:
19332 case AMDGPU::BI__builtin_amdgcn_ds_atomic_fadd_f32:
19333 case AMDGPU::BI__builtin_amdgcn_ds_atomic_fadd_v2f16:
19334 case AMDGPU::BI__builtin_amdgcn_ds_atomic_fadd_v2bf16:
19335 case AMDGPU::BI__builtin_amdgcn_global_atomic_fadd_f32:
19336 case AMDGPU::BI__builtin_amdgcn_global_atomic_fadd_f64:
19337 case AMDGPU::BI__builtin_amdgcn_global_atomic_fadd_v2f16:
19338 case AMDGPU::BI__builtin_amdgcn_flat_atomic_fadd_v2f16:
19339 case AMDGPU::BI__builtin_amdgcn_flat_atomic_fadd_f32:
19340 case AMDGPU::BI__builtin_amdgcn_flat_atomic_fadd_f64:
19341 case AMDGPU::BI__builtin_amdgcn_global_atomic_fadd_v2bf16:
19342 case AMDGPU::BI__builtin_amdgcn_flat_atomic_fadd_v2bf16:
19343 BinOp = llvm::AtomicRMWInst::FAdd;
19345 case AMDGPU::BI__builtin_amdgcn_ds_fminf:
19346 case AMDGPU::BI__builtin_amdgcn_global_atomic_fmin_f64:
19347 case AMDGPU::BI__builtin_amdgcn_flat_atomic_fmin_f64:
19348 BinOp = llvm::AtomicRMWInst::FMin;
19350 case AMDGPU::BI__builtin_amdgcn_global_atomic_fmax_f64:
19351 case AMDGPU::BI__builtin_amdgcn_flat_atomic_fmax_f64:
19352 case AMDGPU::BI__builtin_amdgcn_ds_fmaxf:
19353 BinOp = llvm::AtomicRMWInst::FMax;
19359 llvm::Type *OrigTy = Val->
getType();
19364 if (BuiltinID == AMDGPU::BI__builtin_amdgcn_ds_faddf ||
19365 BuiltinID == AMDGPU::BI__builtin_amdgcn_ds_fminf ||
19366 BuiltinID == AMDGPU::BI__builtin_amdgcn_ds_fmaxf) {
19376 if (
E->getNumArgs() >= 4) {
19388 AO = AtomicOrdering::Monotonic;
19391 if (BuiltinID == AMDGPU::BI__builtin_amdgcn_ds_atomic_fadd_v2bf16 ||
19392 BuiltinID == AMDGPU::BI__builtin_amdgcn_global_atomic_fadd_v2bf16 ||
19393 BuiltinID == AMDGPU::BI__builtin_amdgcn_flat_atomic_fadd_v2bf16) {
19394 llvm::Type *V2BF16Ty = FixedVectorType::get(
19395 llvm::Type::getBFloatTy(
Builder.getContext()), 2);
19396 Val =
Builder.CreateBitCast(Val, V2BF16Ty);
19400 llvm::AtomicRMWInst *RMW =
19403 RMW->setVolatile(
true);
19405 unsigned AddrSpace = Ptr.
getType()->getAddressSpace();
19406 if (AddrSpace != llvm::AMDGPUAS::LOCAL_ADDRESS) {
19410 RMW->setMetadata(
"amdgpu.no.fine.grained.memory", EmptyMD);
19414 if (BinOp == llvm::AtomicRMWInst::FAdd && Val->
getType()->isFloatTy())
19415 RMW->setMetadata(
"amdgpu.ignore.denormal.mode", EmptyMD);
19418 return Builder.CreateBitCast(RMW, OrigTy);
19420 case AMDGPU::BI__builtin_amdgcn_s_sendmsg_rtn:
19421 case AMDGPU::BI__builtin_amdgcn_s_sendmsg_rtnl: {
19427 return Builder.CreateCall(F, {Arg});
19429 case AMDGPU::BI__builtin_amdgcn_make_buffer_rsrc:
19430 return emitBuiltinWithOneOverloadedType<4>(
19431 *
this,
E, Intrinsic::amdgcn_make_buffer_rsrc);
19432 case AMDGPU::BI__builtin_amdgcn_raw_buffer_store_b8:
19433 case AMDGPU::BI__builtin_amdgcn_raw_buffer_store_b16:
19434 case AMDGPU::BI__builtin_amdgcn_raw_buffer_store_b32:
19435 case AMDGPU::BI__builtin_amdgcn_raw_buffer_store_b64:
19436 case AMDGPU::BI__builtin_amdgcn_raw_buffer_store_b96:
19437 case AMDGPU::BI__builtin_amdgcn_raw_buffer_store_b128:
19438 return emitBuiltinWithOneOverloadedType<5>(
19439 *
this,
E, Intrinsic::amdgcn_raw_ptr_buffer_store);
19440 case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b8:
19441 case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b16:
19442 case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b32:
19443 case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b64:
19444 case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b96:
19445 case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b128: {
19446 llvm::Type *RetTy =
nullptr;
19447 switch (BuiltinID) {
19448 case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b8:
19451 case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b16:
19454 case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b32:
19457 case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b64:
19458 RetTy = llvm::FixedVectorType::get(
Int32Ty, 2);
19460 case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b96:
19461 RetTy = llvm::FixedVectorType::get(
Int32Ty, 3);
19463 case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b128:
19464 RetTy = llvm::FixedVectorType::get(
Int32Ty, 4);
19482 unsigned IntrinsicID,
19484 unsigned NumArgs =
E->getNumArgs() - 1;
19486 for (
unsigned I = 0; I < NumArgs; ++I)
19498 switch (BuiltinID) {
19499 case SystemZ::BI__builtin_tbegin: {
19501 Value *Control = llvm::ConstantInt::get(
Int32Ty, 0xff0c);
19503 return Builder.CreateCall(F, {TDB, Control});
19505 case SystemZ::BI__builtin_tbegin_nofloat: {
19507 Value *Control = llvm::ConstantInt::get(
Int32Ty, 0xff0c);
19509 return Builder.CreateCall(F, {TDB, Control});
19511 case SystemZ::BI__builtin_tbeginc: {
19513 Value *Control = llvm::ConstantInt::get(
Int32Ty, 0xff08);
19515 return Builder.CreateCall(F, {TDB, Control});
19517 case SystemZ::BI__builtin_tabort: {
19522 case SystemZ::BI__builtin_non_tx_store: {
19534 case SystemZ::BI__builtin_s390_vpopctb:
19535 case SystemZ::BI__builtin_s390_vpopcth:
19536 case SystemZ::BI__builtin_s390_vpopctf:
19537 case SystemZ::BI__builtin_s390_vpopctg: {
19544 case SystemZ::BI__builtin_s390_vclzb:
19545 case SystemZ::BI__builtin_s390_vclzh:
19546 case SystemZ::BI__builtin_s390_vclzf:
19547 case SystemZ::BI__builtin_s390_vclzg: {
19550 Value *Undef = ConstantInt::get(
Builder.getInt1Ty(),
false);
19552 return Builder.CreateCall(F, {
X, Undef});
19555 case SystemZ::BI__builtin_s390_vctzb:
19556 case SystemZ::BI__builtin_s390_vctzh:
19557 case SystemZ::BI__builtin_s390_vctzf:
19558 case SystemZ::BI__builtin_s390_vctzg: {
19561 Value *Undef = ConstantInt::get(
Builder.getInt1Ty(),
false);
19563 return Builder.CreateCall(F, {
X, Undef});
19566 case SystemZ::BI__builtin_s390_verllb:
19567 case SystemZ::BI__builtin_s390_verllh:
19568 case SystemZ::BI__builtin_s390_verllf:
19569 case SystemZ::BI__builtin_s390_verllg: {
19574 unsigned NumElts = cast<llvm::FixedVectorType>(ResultType)->getNumElements();
19575 Amt =
Builder.CreateIntCast(Amt, ResultType->getScalarType(),
false);
19576 Amt =
Builder.CreateVectorSplat(NumElts, Amt);
19578 return Builder.CreateCall(F, { Src, Src, Amt });
19581 case SystemZ::BI__builtin_s390_verllvb:
19582 case SystemZ::BI__builtin_s390_verllvh:
19583 case SystemZ::BI__builtin_s390_verllvf:
19584 case SystemZ::BI__builtin_s390_verllvg: {
19589 return Builder.CreateCall(F, { Src, Src, Amt });
19592 case SystemZ::BI__builtin_s390_vfsqsb:
19593 case SystemZ::BI__builtin_s390_vfsqdb: {
19596 if (
Builder.getIsFPConstrained()) {
19598 return Builder.CreateConstrainedFPCall(F, {
X });
19604 case SystemZ::BI__builtin_s390_vfmasb:
19605 case SystemZ::BI__builtin_s390_vfmadb: {
19610 if (
Builder.getIsFPConstrained()) {
19612 return Builder.CreateConstrainedFPCall(F, {
X, Y, Z});
19615 return Builder.CreateCall(F, {
X, Y, Z});
19618 case SystemZ::BI__builtin_s390_vfmssb:
19619 case SystemZ::BI__builtin_s390_vfmsdb: {
19624 if (
Builder.getIsFPConstrained()) {
19626 return Builder.CreateConstrainedFPCall(F, {
X, Y,
Builder.CreateFNeg(Z,
"neg")});
19632 case SystemZ::BI__builtin_s390_vfnmasb:
19633 case SystemZ::BI__builtin_s390_vfnmadb: {
19638 if (
Builder.getIsFPConstrained()) {
19640 return Builder.CreateFNeg(
Builder.CreateConstrainedFPCall(F, {X, Y, Z}),
"neg");
19643 return Builder.CreateFNeg(
Builder.CreateCall(F, {X, Y, Z}),
"neg");
19646 case SystemZ::BI__builtin_s390_vfnmssb:
19647 case SystemZ::BI__builtin_s390_vfnmsdb: {
19652 if (
Builder.getIsFPConstrained()) {
19655 return Builder.CreateFNeg(
Builder.CreateConstrainedFPCall(F, {X, Y, NegZ}));
19662 case SystemZ::BI__builtin_s390_vflpsb:
19663 case SystemZ::BI__builtin_s390_vflpdb: {
19669 case SystemZ::BI__builtin_s390_vflnsb:
19670 case SystemZ::BI__builtin_s390_vflndb: {
19676 case SystemZ::BI__builtin_s390_vfisb:
19677 case SystemZ::BI__builtin_s390_vfidb: {
19685 Intrinsic::ID
ID = Intrinsic::not_intrinsic;
19687 switch (M4.getZExtValue()) {
19690 switch (M5.getZExtValue()) {
19692 case 0:
ID = Intrinsic::rint;
19693 CI = Intrinsic::experimental_constrained_rint;
break;
19697 switch (M5.getZExtValue()) {
19699 case 0:
ID = Intrinsic::nearbyint;
19700 CI = Intrinsic::experimental_constrained_nearbyint;
break;
19701 case 1:
ID = Intrinsic::round;
19702 CI = Intrinsic::experimental_constrained_round;
break;
19703 case 5:
ID = Intrinsic::trunc;
19704 CI = Intrinsic::experimental_constrained_trunc;
break;
19705 case 6:
ID = Intrinsic::ceil;
19706 CI = Intrinsic::experimental_constrained_ceil;
break;
19707 case 7:
ID = Intrinsic::floor;
19708 CI = Intrinsic::experimental_constrained_floor;
break;
19712 if (ID != Intrinsic::not_intrinsic) {
19713 if (
Builder.getIsFPConstrained()) {
19715 return Builder.CreateConstrainedFPCall(F,
X);
19721 switch (BuiltinID) {
19722 case SystemZ::BI__builtin_s390_vfisb:
ID = Intrinsic::s390_vfisb;
break;
19723 case SystemZ::BI__builtin_s390_vfidb:
ID = Intrinsic::s390_vfidb;
break;
19724 default: llvm_unreachable(
"Unknown BuiltinID");
19729 return Builder.CreateCall(F, {
X, M4Value, M5Value});
19731 case SystemZ::BI__builtin_s390_vfmaxsb:
19732 case SystemZ::BI__builtin_s390_vfmaxdb: {
19740 Intrinsic::ID
ID = Intrinsic::not_intrinsic;
19742 switch (M4.getZExtValue()) {
19744 case 4:
ID = Intrinsic::maxnum;
19745 CI = Intrinsic::experimental_constrained_maxnum;
break;
19747 if (ID != Intrinsic::not_intrinsic) {
19748 if (
Builder.getIsFPConstrained()) {
19750 return Builder.CreateConstrainedFPCall(F, {
X, Y});
19753 return Builder.CreateCall(F, {
X, Y});
19756 switch (BuiltinID) {
19757 case SystemZ::BI__builtin_s390_vfmaxsb:
ID = Intrinsic::s390_vfmaxsb;
break;
19758 case SystemZ::BI__builtin_s390_vfmaxdb:
ID = Intrinsic::s390_vfmaxdb;
break;
19759 default: llvm_unreachable(
"Unknown BuiltinID");
19763 return Builder.CreateCall(F, {
X, Y, M4Value});
19765 case SystemZ::BI__builtin_s390_vfminsb:
19766 case SystemZ::BI__builtin_s390_vfmindb: {
19774 Intrinsic::ID
ID = Intrinsic::not_intrinsic;
19776 switch (M4.getZExtValue()) {
19778 case 4:
ID = Intrinsic::minnum;
19779 CI = Intrinsic::experimental_constrained_minnum;
break;
19781 if (ID != Intrinsic::not_intrinsic) {
19782 if (
Builder.getIsFPConstrained()) {
19784 return Builder.CreateConstrainedFPCall(F, {
X, Y});
19787 return Builder.CreateCall(F, {
X, Y});
19790 switch (BuiltinID) {
19791 case SystemZ::BI__builtin_s390_vfminsb:
ID = Intrinsic::s390_vfminsb;
break;
19792 case SystemZ::BI__builtin_s390_vfmindb:
ID = Intrinsic::s390_vfmindb;
break;
19793 default: llvm_unreachable(
"Unknown BuiltinID");
19797 return Builder.CreateCall(F, {
X, Y, M4Value});
19800 case SystemZ::BI__builtin_s390_vlbrh:
19801 case SystemZ::BI__builtin_s390_vlbrf:
19802 case SystemZ::BI__builtin_s390_vlbrg: {
19811#define INTRINSIC_WITH_CC(NAME) \
19812 case SystemZ::BI__builtin_##NAME: \
19813 return EmitSystemZIntrinsicWithCC(*this, Intrinsic::NAME, E)
19892#undef INTRINSIC_WITH_CC
19901struct NVPTXMmaLdstInfo {
19902 unsigned NumResults;
19908#define MMA_INTR(geom_op_type, layout) \
19909 Intrinsic::nvvm_wmma_##geom_op_type##_##layout##_stride
19910#define MMA_LDST(n, geom_op_type) \
19911 { n, MMA_INTR(geom_op_type, col), MMA_INTR(geom_op_type, row) }
19913static NVPTXMmaLdstInfo getNVPTXMmaLdstInfo(
unsigned BuiltinID) {
19914 switch (BuiltinID) {
19916 case NVPTX::BI__hmma_m16n16k16_ld_a:
19917 return MMA_LDST(8, m16n16k16_load_a_f16);
19918 case NVPTX::BI__hmma_m16n16k16_ld_b:
19919 return MMA_LDST(8, m16n16k16_load_b_f16);
19920 case NVPTX::BI__hmma_m16n16k16_ld_c_f16:
19921 return MMA_LDST(4, m16n16k16_load_c_f16);
19922 case NVPTX::BI__hmma_m16n16k16_ld_c_f32:
19923 return MMA_LDST(8, m16n16k16_load_c_f32);
19924 case NVPTX::BI__hmma_m32n8k16_ld_a:
19925 return MMA_LDST(8, m32n8k16_load_a_f16);
19926 case NVPTX::BI__hmma_m32n8k16_ld_b:
19927 return MMA_LDST(8, m32n8k16_load_b_f16);
19928 case NVPTX::BI__hmma_m32n8k16_ld_c_f16:
19929 return MMA_LDST(4, m32n8k16_load_c_f16);
19930 case NVPTX::BI__hmma_m32n8k16_ld_c_f32:
19931 return MMA_LDST(8, m32n8k16_load_c_f32);
19932 case NVPTX::BI__hmma_m8n32k16_ld_a:
19933 return MMA_LDST(8, m8n32k16_load_a_f16);
19934 case NVPTX::BI__hmma_m8n32k16_ld_b:
19935 return MMA_LDST(8, m8n32k16_load_b_f16);
19936 case NVPTX::BI__hmma_m8n32k16_ld_c_f16:
19937 return MMA_LDST(4, m8n32k16_load_c_f16);
19938 case NVPTX::BI__hmma_m8n32k16_ld_c_f32:
19939 return MMA_LDST(8, m8n32k16_load_c_f32);
19942 case NVPTX::BI__imma_m16n16k16_ld_a_s8:
19943 return MMA_LDST(2, m16n16k16_load_a_s8);
19944 case NVPTX::BI__imma_m16n16k16_ld_a_u8:
19945 return MMA_LDST(2, m16n16k16_load_a_u8);
19946 case NVPTX::BI__imma_m16n16k16_ld_b_s8:
19947 return MMA_LDST(2, m16n16k16_load_b_s8);
19948 case NVPTX::BI__imma_m16n16k16_ld_b_u8:
19949 return MMA_LDST(2, m16n16k16_load_b_u8);
19950 case NVPTX::BI__imma_m16n16k16_ld_c:
19951 return MMA_LDST(8, m16n16k16_load_c_s32);
19952 case NVPTX::BI__imma_m32n8k16_ld_a_s8:
19953 return MMA_LDST(4, m32n8k16_load_a_s8);
19954 case NVPTX::BI__imma_m32n8k16_ld_a_u8:
19955 return MMA_LDST(4, m32n8k16_load_a_u8);
19956 case NVPTX::BI__imma_m32n8k16_ld_b_s8:
19957 return MMA_LDST(1, m32n8k16_load_b_s8);
19958 case NVPTX::BI__imma_m32n8k16_ld_b_u8:
19959 return MMA_LDST(1, m32n8k16_load_b_u8);
19960 case NVPTX::BI__imma_m32n8k16_ld_c:
19961 return MMA_LDST(8, m32n8k16_load_c_s32);
19962 case NVPTX::BI__imma_m8n32k16_ld_a_s8:
19963 return MMA_LDST(1, m8n32k16_load_a_s8);
19964 case NVPTX::BI__imma_m8n32k16_ld_a_u8:
19965 return MMA_LDST(1, m8n32k16_load_a_u8);
19966 case NVPTX::BI__imma_m8n32k16_ld_b_s8:
19967 return MMA_LDST(4, m8n32k16_load_b_s8);
19968 case NVPTX::BI__imma_m8n32k16_ld_b_u8:
19969 return MMA_LDST(4, m8n32k16_load_b_u8);
19970 case NVPTX::BI__imma_m8n32k16_ld_c:
19971 return MMA_LDST(8, m8n32k16_load_c_s32);
19975 case NVPTX::BI__imma_m8n8k32_ld_a_s4:
19976 return {1, 0,
MMA_INTR(m8n8k32_load_a_s4, row)};
19977 case NVPTX::BI__imma_m8n8k32_ld_a_u4:
19978 return {1, 0,
MMA_INTR(m8n8k32_load_a_u4, row)};
19979 case NVPTX::BI__imma_m8n8k32_ld_b_s4:
19980 return {1,
MMA_INTR(m8n8k32_load_b_s4, col), 0};
19981 case NVPTX::BI__imma_m8n8k32_ld_b_u4:
19982 return {1,
MMA_INTR(m8n8k32_load_b_u4, col), 0};
19983 case NVPTX::BI__imma_m8n8k32_ld_c:
19984 return MMA_LDST(2, m8n8k32_load_c_s32);
19985 case NVPTX::BI__bmma_m8n8k128_ld_a_b1:
19986 return {1, 0,
MMA_INTR(m8n8k128_load_a_b1, row)};
19987 case NVPTX::BI__bmma_m8n8k128_ld_b_b1:
19988 return {1,
MMA_INTR(m8n8k128_load_b_b1, col), 0};
19989 case NVPTX::BI__bmma_m8n8k128_ld_c:
19990 return MMA_LDST(2, m8n8k128_load_c_s32);
19993 case NVPTX::BI__dmma_m8n8k4_ld_a:
19994 return MMA_LDST(1, m8n8k4_load_a_f64);
19995 case NVPTX::BI__dmma_m8n8k4_ld_b:
19996 return MMA_LDST(1, m8n8k4_load_b_f64);
19997 case NVPTX::BI__dmma_m8n8k4_ld_c:
19998 return MMA_LDST(2, m8n8k4_load_c_f64);
20001 case NVPTX::BI__mma_bf16_m16n16k16_ld_a:
20002 return MMA_LDST(4, m16n16k16_load_a_bf16);
20003 case NVPTX::BI__mma_bf16_m16n16k16_ld_b:
20004 return MMA_LDST(4, m16n16k16_load_b_bf16);
20005 case NVPTX::BI__mma_bf16_m8n32k16_ld_a:
20006 return MMA_LDST(2, m8n32k16_load_a_bf16);
20007 case NVPTX::BI__mma_bf16_m8n32k16_ld_b:
20008 return MMA_LDST(8, m8n32k16_load_b_bf16);
20009 case NVPTX::BI__mma_bf16_m32n8k16_ld_a:
20010 return MMA_LDST(8, m32n8k16_load_a_bf16);
20011 case NVPTX::BI__mma_bf16_m32n8k16_ld_b:
20012 return MMA_LDST(2, m32n8k16_load_b_bf16);
20013 case NVPTX::BI__mma_tf32_m16n16k8_ld_a:
20014 return MMA_LDST(4, m16n16k8_load_a_tf32);
20015 case NVPTX::BI__mma_tf32_m16n16k8_ld_b:
20016 return MMA_LDST(4, m16n16k8_load_b_tf32);
20017 case NVPTX::BI__mma_tf32_m16n16k8_ld_c:
20018 return MMA_LDST(8, m16n16k8_load_c_f32);
20024 case NVPTX::BI__hmma_m16n16k16_st_c_f16:
20025 return MMA_LDST(4, m16n16k16_store_d_f16);
20026 case NVPTX::BI__hmma_m16n16k16_st_c_f32:
20027 return MMA_LDST(8, m16n16k16_store_d_f32);
20028 case NVPTX::BI__hmma_m32n8k16_st_c_f16:
20029 return MMA_LDST(4, m32n8k16_store_d_f16);
20030 case NVPTX::BI__hmma_m32n8k16_st_c_f32:
20031 return MMA_LDST(8, m32n8k16_store_d_f32);
20032 case NVPTX::BI__hmma_m8n32k16_st_c_f16:
20033 return MMA_LDST(4, m8n32k16_store_d_f16);
20034 case NVPTX::BI__hmma_m8n32k16_st_c_f32:
20035 return MMA_LDST(8, m8n32k16_store_d_f32);
20040 case NVPTX::BI__imma_m16n16k16_st_c_i32:
20041 return MMA_LDST(8, m16n16k16_store_d_s32);
20042 case NVPTX::BI__imma_m32n8k16_st_c_i32:
20043 return MMA_LDST(8, m32n8k16_store_d_s32);
20044 case NVPTX::BI__imma_m8n32k16_st_c_i32:
20045 return MMA_LDST(8, m8n32k16_store_d_s32);
20046 case NVPTX::BI__imma_m8n8k32_st_c_i32:
20047 return MMA_LDST(2, m8n8k32_store_d_s32);
20048 case NVPTX::BI__bmma_m8n8k128_st_c_i32:
20049 return MMA_LDST(2, m8n8k128_store_d_s32);
20052 case NVPTX::BI__dmma_m8n8k4_st_c_f64:
20053 return MMA_LDST(2, m8n8k4_store_d_f64);
20056 case NVPTX::BI__mma_m16n16k8_st_c_f32:
20057 return MMA_LDST(8, m16n16k8_store_d_f32);
20060 llvm_unreachable(
"Unknown MMA builtin");
20067struct NVPTXMmaInfo {
20076 std::array<unsigned, 8> Variants;
20078 unsigned getMMAIntrinsic(
int Layout,
bool Satf) {
20079 unsigned Index = Layout + 4 * Satf;
20080 if (Index >= Variants.size())
20082 return Variants[Index];
20088static NVPTXMmaInfo getNVPTXMmaInfo(
unsigned BuiltinID) {
20090#define MMA_VARIANTS(geom, type) \
20091 Intrinsic::nvvm_wmma_##geom##_mma_row_row_##type, \
20092 Intrinsic::nvvm_wmma_##geom##_mma_row_col_##type, \
20093 Intrinsic::nvvm_wmma_##geom##_mma_col_row_##type, \
20094 Intrinsic::nvvm_wmma_##geom##_mma_col_col_##type
20095#define MMA_SATF_VARIANTS(geom, type) \
20096 MMA_VARIANTS(geom, type), \
20097 Intrinsic::nvvm_wmma_##geom##_mma_row_row_##type##_satfinite, \
20098 Intrinsic::nvvm_wmma_##geom##_mma_row_col_##type##_satfinite, \
20099 Intrinsic::nvvm_wmma_##geom##_mma_col_row_##type##_satfinite, \
20100 Intrinsic::nvvm_wmma_##geom##_mma_col_col_##type##_satfinite
20102#define MMA_VARIANTS_I4(geom, type) \
20104 Intrinsic::nvvm_wmma_##geom##_mma_row_col_##type, \
20108 Intrinsic::nvvm_wmma_##geom##_mma_row_col_##type##_satfinite, \
20112#define MMA_VARIANTS_B1_XOR(geom, type) \
20114 Intrinsic::nvvm_wmma_##geom##_mma_xor_popc_row_col_##type, \
20121#define MMA_VARIANTS_B1_AND(geom, type) \
20123 Intrinsic::nvvm_wmma_##geom##_mma_and_popc_row_col_##type, \
20131 switch (BuiltinID) {
20135 case NVPTX::BI__hmma_m16n16k16_mma_f16f16:
20137 case NVPTX::BI__hmma_m16n16k16_mma_f32f16:
20139 case NVPTX::BI__hmma_m16n16k16_mma_f16f32:
20141 case NVPTX::BI__hmma_m16n16k16_mma_f32f32:
20143 case NVPTX::BI__hmma_m32n8k16_mma_f16f16:
20145 case NVPTX::BI__hmma_m32n8k16_mma_f32f16:
20147 case NVPTX::BI__hmma_m32n8k16_mma_f16f32:
20149 case NVPTX::BI__hmma_m32n8k16_mma_f32f32:
20151 case NVPTX::BI__hmma_m8n32k16_mma_f16f16:
20153 case NVPTX::BI__hmma_m8n32k16_mma_f32f16:
20155 case NVPTX::BI__hmma_m8n32k16_mma_f16f32:
20157 case NVPTX::BI__hmma_m8n32k16_mma_f32f32:
20161 case NVPTX::BI__imma_m16n16k16_mma_s8:
20163 case NVPTX::BI__imma_m16n16k16_mma_u8:
20165 case NVPTX::BI__imma_m32n8k16_mma_s8:
20167 case NVPTX::BI__imma_m32n8k16_mma_u8:
20169 case NVPTX::BI__imma_m8n32k16_mma_s8:
20171 case NVPTX::BI__imma_m8n32k16_mma_u8:
20175 case NVPTX::BI__imma_m8n8k32_mma_s4:
20177 case NVPTX::BI__imma_m8n8k32_mma_u4:
20179 case NVPTX::BI__bmma_m8n8k128_mma_xor_popc_b1:
20181 case NVPTX::BI__bmma_m8n8k128_mma_and_popc_b1:
20185 case NVPTX::BI__dmma_m8n8k4_mma_f64:
20189 case NVPTX::BI__mma_bf16_m16n16k16_mma_f32:
20190 return {4, 4, 8, 8, {{
MMA_VARIANTS(m16n16k16, bf16)}}};
20191 case NVPTX::BI__mma_bf16_m8n32k16_mma_f32:
20192 return {2, 8, 8, 8, {{
MMA_VARIANTS(m8n32k16, bf16)}}};
20193 case NVPTX::BI__mma_bf16_m32n8k16_mma_f32:
20194 return {8, 2, 8, 8, {{
MMA_VARIANTS(m32n8k16, bf16)}}};
20195 case NVPTX::BI__mma_tf32_m16n16k8_mma_f32:
20196 return {4, 4, 8, 8, {{
MMA_VARIANTS(m16n16k8, tf32)}}};
20198 llvm_unreachable(
"Unexpected builtin ID.");
20201#undef MMA_SATF_VARIANTS
20202#undef MMA_VARIANTS_I4
20203#undef MMA_VARIANTS_B1_AND
20204#undef MMA_VARIANTS_B1_XOR
20213 return CGF.
Builder.CreateCall(
20215 {Ptr, ConstantInt::get(CGF.Builder.getInt32Ty(), Align.getQuantity())});
20221 llvm::Type *ElemTy =
20223 return CGF.
Builder.CreateCall(
20225 {Ptr, CGF.EmitScalarExpr(E->getArg(1))});
20228static Value *MakeCpAsync(
unsigned IntrinsicID,
unsigned IntrinsicIDS,
20231 return E->getNumArgs() == 3
20233 {CGF.EmitScalarExpr(E->getArg(0)),
20234 CGF.EmitScalarExpr(E->getArg(1)),
20235 CGF.EmitScalarExpr(E->getArg(2))})
20237 {CGF.EmitScalarExpr(E->getArg(0)),
20238 CGF.EmitScalarExpr(E->getArg(1))});
20241static Value *MakeHalfType(
unsigned IntrinsicID,
unsigned BuiltinID,
20244 if (!(
C.getLangOpts().NativeHalfType ||
20245 !
C.getTargetInfo().useFP16ConversionIntrinsics())) {
20247 " requires native half type support.");
20251 if (IntrinsicID == Intrinsic::nvvm_ldg_global_f ||
20252 IntrinsicID == Intrinsic::nvvm_ldu_global_f)
20253 return MakeLdgLdu(IntrinsicID, CGF,
E);
20257 auto *FTy = F->getFunctionType();
20258 unsigned ICEArguments = 0;
20260 C.GetBuiltinType(BuiltinID, Error, &ICEArguments);
20262 for (
unsigned i = 0, e =
E->getNumArgs(); i != e; ++i) {
20263 assert((ICEArguments & (1 << i)) == 0);
20265 auto *PTy = FTy->getParamType(i);
20266 if (PTy != ArgValue->
getType())
20267 ArgValue = CGF.
Builder.CreateBitCast(ArgValue, PTy);
20268 Args.push_back(ArgValue);
20271 return CGF.
Builder.CreateCall(F, Args);
20277 switch (BuiltinID) {
20278 case NVPTX::BI__nvvm_atom_add_gen_i:
20279 case NVPTX::BI__nvvm_atom_add_gen_l:
20280 case NVPTX::BI__nvvm_atom_add_gen_ll:
20283 case NVPTX::BI__nvvm_atom_sub_gen_i:
20284 case NVPTX::BI__nvvm_atom_sub_gen_l:
20285 case NVPTX::BI__nvvm_atom_sub_gen_ll:
20288 case NVPTX::BI__nvvm_atom_and_gen_i:
20289 case NVPTX::BI__nvvm_atom_and_gen_l:
20290 case NVPTX::BI__nvvm_atom_and_gen_ll:
20293 case NVPTX::BI__nvvm_atom_or_gen_i:
20294 case NVPTX::BI__nvvm_atom_or_gen_l:
20295 case NVPTX::BI__nvvm_atom_or_gen_ll:
20298 case NVPTX::BI__nvvm_atom_xor_gen_i:
20299 case NVPTX::BI__nvvm_atom_xor_gen_l:
20300 case NVPTX::BI__nvvm_atom_xor_gen_ll:
20303 case NVPTX::BI__nvvm_atom_xchg_gen_i:
20304 case NVPTX::BI__nvvm_atom_xchg_gen_l:
20305 case NVPTX::BI__nvvm_atom_xchg_gen_ll:
20308 case NVPTX::BI__nvvm_atom_max_gen_i:
20309 case NVPTX::BI__nvvm_atom_max_gen_l:
20310 case NVPTX::BI__nvvm_atom_max_gen_ll:
20313 case NVPTX::BI__nvvm_atom_max_gen_ui:
20314 case NVPTX::BI__nvvm_atom_max_gen_ul:
20315 case NVPTX::BI__nvvm_atom_max_gen_ull:
20318 case NVPTX::BI__nvvm_atom_min_gen_i:
20319 case NVPTX::BI__nvvm_atom_min_gen_l:
20320 case NVPTX::BI__nvvm_atom_min_gen_ll:
20323 case NVPTX::BI__nvvm_atom_min_gen_ui:
20324 case NVPTX::BI__nvvm_atom_min_gen_ul:
20325 case NVPTX::BI__nvvm_atom_min_gen_ull:
20328 case NVPTX::BI__nvvm_atom_cas_gen_i:
20329 case NVPTX::BI__nvvm_atom_cas_gen_l:
20330 case NVPTX::BI__nvvm_atom_cas_gen_ll:
20335 case NVPTX::BI__nvvm_atom_add_gen_f:
20336 case NVPTX::BI__nvvm_atom_add_gen_d: {
20341 AtomicOrdering::SequentiallyConsistent);
20344 case NVPTX::BI__nvvm_atom_inc_gen_ui: {
20349 return Builder.CreateCall(FnALI32, {Ptr, Val});
20352 case NVPTX::BI__nvvm_atom_dec_gen_ui: {
20357 return Builder.CreateCall(FnALD32, {Ptr, Val});
20360 case NVPTX::BI__nvvm_ldg_c:
20361 case NVPTX::BI__nvvm_ldg_sc:
20362 case NVPTX::BI__nvvm_ldg_c2:
20363 case NVPTX::BI__nvvm_ldg_sc2:
20364 case NVPTX::BI__nvvm_ldg_c4:
20365 case NVPTX::BI__nvvm_ldg_sc4:
20366 case NVPTX::BI__nvvm_ldg_s:
20367 case NVPTX::BI__nvvm_ldg_s2:
20368 case NVPTX::BI__nvvm_ldg_s4:
20369 case NVPTX::BI__nvvm_ldg_i:
20370 case NVPTX::BI__nvvm_ldg_i2:
20371 case NVPTX::BI__nvvm_ldg_i4:
20372 case NVPTX::BI__nvvm_ldg_l:
20373 case NVPTX::BI__nvvm_ldg_l2:
20374 case NVPTX::BI__nvvm_ldg_ll:
20375 case NVPTX::BI__nvvm_ldg_ll2:
20376 case NVPTX::BI__nvvm_ldg_uc:
20377 case NVPTX::BI__nvvm_ldg_uc2:
20378 case NVPTX::BI__nvvm_ldg_uc4:
20379 case NVPTX::BI__nvvm_ldg_us:
20380 case NVPTX::BI__nvvm_ldg_us2:
20381 case NVPTX::BI__nvvm_ldg_us4:
20382 case NVPTX::BI__nvvm_ldg_ui:
20383 case NVPTX::BI__nvvm_ldg_ui2:
20384 case NVPTX::BI__nvvm_ldg_ui4:
20385 case NVPTX::BI__nvvm_ldg_ul:
20386 case NVPTX::BI__nvvm_ldg_ul2:
20387 case NVPTX::BI__nvvm_ldg_ull:
20388 case NVPTX::BI__nvvm_ldg_ull2:
20392 return MakeLdgLdu(Intrinsic::nvvm_ldg_global_i, *
this,
E);
20393 case NVPTX::BI__nvvm_ldg_f:
20394 case NVPTX::BI__nvvm_ldg_f2:
20395 case NVPTX::BI__nvvm_ldg_f4:
20396 case NVPTX::BI__nvvm_ldg_d:
20397 case NVPTX::BI__nvvm_ldg_d2:
20398 return MakeLdgLdu(Intrinsic::nvvm_ldg_global_f, *
this,
E);
20400 case NVPTX::BI__nvvm_ldu_c:
20401 case NVPTX::BI__nvvm_ldu_sc:
20402 case NVPTX::BI__nvvm_ldu_c2:
20403 case NVPTX::BI__nvvm_ldu_sc2:
20404 case NVPTX::BI__nvvm_ldu_c4:
20405 case NVPTX::BI__nvvm_ldu_sc4:
20406 case NVPTX::BI__nvvm_ldu_s:
20407 case NVPTX::BI__nvvm_ldu_s2:
20408 case NVPTX::BI__nvvm_ldu_s4:
20409 case NVPTX::BI__nvvm_ldu_i:
20410 case NVPTX::BI__nvvm_ldu_i2:
20411 case NVPTX::BI__nvvm_ldu_i4:
20412 case NVPTX::BI__nvvm_ldu_l:
20413 case NVPTX::BI__nvvm_ldu_l2:
20414 case NVPTX::BI__nvvm_ldu_ll:
20415 case NVPTX::BI__nvvm_ldu_ll2:
20416 case NVPTX::BI__nvvm_ldu_uc:
20417 case NVPTX::BI__nvvm_ldu_uc2:
20418 case NVPTX::BI__nvvm_ldu_uc4:
20419 case NVPTX::BI__nvvm_ldu_us:
20420 case NVPTX::BI__nvvm_ldu_us2:
20421 case NVPTX::BI__nvvm_ldu_us4:
20422 case NVPTX::BI__nvvm_ldu_ui:
20423 case NVPTX::BI__nvvm_ldu_ui2:
20424 case NVPTX::BI__nvvm_ldu_ui4:
20425 case NVPTX::BI__nvvm_ldu_ul:
20426 case NVPTX::BI__nvvm_ldu_ul2:
20427 case NVPTX::BI__nvvm_ldu_ull:
20428 case NVPTX::BI__nvvm_ldu_ull2:
20429 return MakeLdgLdu(Intrinsic::nvvm_ldu_global_i, *
this,
E);
20430 case NVPTX::BI__nvvm_ldu_f:
20431 case NVPTX::BI__nvvm_ldu_f2:
20432 case NVPTX::BI__nvvm_ldu_f4:
20433 case NVPTX::BI__nvvm_ldu_d:
20434 case NVPTX::BI__nvvm_ldu_d2:
20435 return MakeLdgLdu(Intrinsic::nvvm_ldu_global_f, *
this,
E);
20437 case NVPTX::BI__nvvm_atom_cta_add_gen_i:
20438 case NVPTX::BI__nvvm_atom_cta_add_gen_l:
20439 case NVPTX::BI__nvvm_atom_cta_add_gen_ll:
20440 return MakeScopedAtomic(Intrinsic::nvvm_atomic_add_gen_i_cta, *
this,
E);
20441 case NVPTX::BI__nvvm_atom_sys_add_gen_i:
20442 case NVPTX::BI__nvvm_atom_sys_add_gen_l:
20443 case NVPTX::BI__nvvm_atom_sys_add_gen_ll:
20444 return MakeScopedAtomic(Intrinsic::nvvm_atomic_add_gen_i_sys, *
this,
E);
20445 case NVPTX::BI__nvvm_atom_cta_add_gen_f:
20446 case NVPTX::BI__nvvm_atom_cta_add_gen_d:
20447 return MakeScopedAtomic(Intrinsic::nvvm_atomic_add_gen_f_cta, *
this,
E);
20448 case NVPTX::BI__nvvm_atom_sys_add_gen_f:
20449 case NVPTX::BI__nvvm_atom_sys_add_gen_d:
20450 return MakeScopedAtomic(Intrinsic::nvvm_atomic_add_gen_f_sys, *
this,
E);
20451 case NVPTX::BI__nvvm_atom_cta_xchg_gen_i:
20452 case NVPTX::BI__nvvm_atom_cta_xchg_gen_l:
20453 case NVPTX::BI__nvvm_atom_cta_xchg_gen_ll:
20454 return MakeScopedAtomic(Intrinsic::nvvm_atomic_exch_gen_i_cta, *
this,
E);
20455 case NVPTX::BI__nvvm_atom_sys_xchg_gen_i:
20456 case NVPTX::BI__nvvm_atom_sys_xchg_gen_l:
20457 case NVPTX::BI__nvvm_atom_sys_xchg_gen_ll:
20458 return MakeScopedAtomic(Intrinsic::nvvm_atomic_exch_gen_i_sys, *
this,
E);
20459 case NVPTX::BI__nvvm_atom_cta_max_gen_i:
20460 case NVPTX::BI__nvvm_atom_cta_max_gen_ui:
20461 case NVPTX::BI__nvvm_atom_cta_max_gen_l:
20462 case NVPTX::BI__nvvm_atom_cta_max_gen_ul:
20463 case NVPTX::BI__nvvm_atom_cta_max_gen_ll:
20464 case NVPTX::BI__nvvm_atom_cta_max_gen_ull:
20465 return MakeScopedAtomic(Intrinsic::nvvm_atomic_max_gen_i_cta, *
this,
E);
20466 case NVPTX::BI__nvvm_atom_sys_max_gen_i:
20467 case NVPTX::BI__nvvm_atom_sys_max_gen_ui:
20468 case NVPTX::BI__nvvm_atom_sys_max_gen_l:
20469 case NVPTX::BI__nvvm_atom_sys_max_gen_ul:
20470 case NVPTX::BI__nvvm_atom_sys_max_gen_ll:
20471 case NVPTX::BI__nvvm_atom_sys_max_gen_ull:
20472 return MakeScopedAtomic(Intrinsic::nvvm_atomic_max_gen_i_sys, *
this,
E);
20473 case NVPTX::BI__nvvm_atom_cta_min_gen_i:
20474 case NVPTX::BI__nvvm_atom_cta_min_gen_ui:
20475 case NVPTX::BI__nvvm_atom_cta_min_gen_l:
20476 case NVPTX::BI__nvvm_atom_cta_min_gen_ul:
20477 case NVPTX::BI__nvvm_atom_cta_min_gen_ll:
20478 case NVPTX::BI__nvvm_atom_cta_min_gen_ull:
20479 return MakeScopedAtomic(Intrinsic::nvvm_atomic_min_gen_i_cta, *
this,
E);
20480 case NVPTX::BI__nvvm_atom_sys_min_gen_i:
20481 case NVPTX::BI__nvvm_atom_sys_min_gen_ui:
20482 case NVPTX::BI__nvvm_atom_sys_min_gen_l:
20483 case NVPTX::BI__nvvm_atom_sys_min_gen_ul:
20484 case NVPTX::BI__nvvm_atom_sys_min_gen_ll:
20485 case NVPTX::BI__nvvm_atom_sys_min_gen_ull:
20486 return MakeScopedAtomic(Intrinsic::nvvm_atomic_min_gen_i_sys, *
this,
E);
20487 case NVPTX::BI__nvvm_atom_cta_inc_gen_ui:
20488 return MakeScopedAtomic(Intrinsic::nvvm_atomic_inc_gen_i_cta, *
this,
E);
20489 case NVPTX::BI__nvvm_atom_cta_dec_gen_ui:
20490 return MakeScopedAtomic(Intrinsic::nvvm_atomic_dec_gen_i_cta, *
this,
E);
20491 case NVPTX::BI__nvvm_atom_sys_inc_gen_ui:
20492 return MakeScopedAtomic(Intrinsic::nvvm_atomic_inc_gen_i_sys, *
this,
E);
20493 case NVPTX::BI__nvvm_atom_sys_dec_gen_ui:
20494 return MakeScopedAtomic(Intrinsic::nvvm_atomic_dec_gen_i_sys, *
this,
E);
20495 case NVPTX::BI__nvvm_atom_cta_and_gen_i:
20496 case NVPTX::BI__nvvm_atom_cta_and_gen_l:
20497 case NVPTX::BI__nvvm_atom_cta_and_gen_ll:
20498 return MakeScopedAtomic(Intrinsic::nvvm_atomic_and_gen_i_cta, *
this,
E);
20499 case NVPTX::BI__nvvm_atom_sys_and_gen_i:
20500 case NVPTX::BI__nvvm_atom_sys_and_gen_l:
20501 case NVPTX::BI__nvvm_atom_sys_and_gen_ll:
20502 return MakeScopedAtomic(Intrinsic::nvvm_atomic_and_gen_i_sys, *
this,
E);
20503 case NVPTX::BI__nvvm_atom_cta_or_gen_i:
20504 case NVPTX::BI__nvvm_atom_cta_or_gen_l:
20505 case NVPTX::BI__nvvm_atom_cta_or_gen_ll:
20506 return MakeScopedAtomic(Intrinsic::nvvm_atomic_or_gen_i_cta, *
this,
E);
20507 case NVPTX::BI__nvvm_atom_sys_or_gen_i:
20508 case NVPTX::BI__nvvm_atom_sys_or_gen_l:
20509 case NVPTX::BI__nvvm_atom_sys_or_gen_ll:
20510 return MakeScopedAtomic(Intrinsic::nvvm_atomic_or_gen_i_sys, *
this,
E);
20511 case NVPTX::BI__nvvm_atom_cta_xor_gen_i:
20512 case NVPTX::BI__nvvm_atom_cta_xor_gen_l:
20513 case NVPTX::BI__nvvm_atom_cta_xor_gen_ll:
20514 return MakeScopedAtomic(Intrinsic::nvvm_atomic_xor_gen_i_cta, *
this,
E);
20515 case NVPTX::BI__nvvm_atom_sys_xor_gen_i:
20516 case NVPTX::BI__nvvm_atom_sys_xor_gen_l:
20517 case NVPTX::BI__nvvm_atom_sys_xor_gen_ll:
20518 return MakeScopedAtomic(Intrinsic::nvvm_atomic_xor_gen_i_sys, *
this,
E);
20519 case NVPTX::BI__nvvm_atom_cta_cas_gen_i:
20520 case NVPTX::BI__nvvm_atom_cta_cas_gen_l:
20521 case NVPTX::BI__nvvm_atom_cta_cas_gen_ll: {
20523 llvm::Type *ElemTy =
20527 Intrinsic::nvvm_atomic_cas_gen_i_cta, {ElemTy, Ptr->getType()}),
20528 {Ptr, EmitScalarExpr(E->getArg(1)), EmitScalarExpr(E->getArg(2))});
20530 case NVPTX::BI__nvvm_atom_sys_cas_gen_i:
20531 case NVPTX::BI__nvvm_atom_sys_cas_gen_l:
20532 case NVPTX::BI__nvvm_atom_sys_cas_gen_ll: {
20534 llvm::Type *ElemTy =
20538 Intrinsic::nvvm_atomic_cas_gen_i_sys, {ElemTy, Ptr->getType()}),
20539 {Ptr, EmitScalarExpr(E->getArg(1)), EmitScalarExpr(E->getArg(2))});
20541 case NVPTX::BI__nvvm_match_all_sync_i32p:
20542 case NVPTX::BI__nvvm_match_all_sync_i64p: {
20548 ? Intrinsic::nvvm_match_all_sync_i32p
20549 : Intrinsic::nvvm_match_all_sync_i64p),
20554 return Builder.CreateExtractValue(ResultPair, 0);
20558 case NVPTX::BI__hmma_m16n16k16_ld_a:
20559 case NVPTX::BI__hmma_m16n16k16_ld_b:
20560 case NVPTX::BI__hmma_m16n16k16_ld_c_f16:
20561 case NVPTX::BI__hmma_m16n16k16_ld_c_f32:
20562 case NVPTX::BI__hmma_m32n8k16_ld_a:
20563 case NVPTX::BI__hmma_m32n8k16_ld_b:
20564 case NVPTX::BI__hmma_m32n8k16_ld_c_f16:
20565 case NVPTX::BI__hmma_m32n8k16_ld_c_f32:
20566 case NVPTX::BI__hmma_m8n32k16_ld_a:
20567 case NVPTX::BI__hmma_m8n32k16_ld_b:
20568 case NVPTX::BI__hmma_m8n32k16_ld_c_f16:
20569 case NVPTX::BI__hmma_m8n32k16_ld_c_f32:
20571 case NVPTX::BI__imma_m16n16k16_ld_a_s8:
20572 case NVPTX::BI__imma_m16n16k16_ld_a_u8:
20573 case NVPTX::BI__imma_m16n16k16_ld_b_s8:
20574 case NVPTX::BI__imma_m16n16k16_ld_b_u8:
20575 case NVPTX::BI__imma_m16n16k16_ld_c:
20576 case NVPTX::BI__imma_m32n8k16_ld_a_s8:
20577 case NVPTX::BI__imma_m32n8k16_ld_a_u8:
20578 case NVPTX::BI__imma_m32n8k16_ld_b_s8:
20579 case NVPTX::BI__imma_m32n8k16_ld_b_u8:
20580 case NVPTX::BI__imma_m32n8k16_ld_c:
20581 case NVPTX::BI__imma_m8n32k16_ld_a_s8:
20582 case NVPTX::BI__imma_m8n32k16_ld_a_u8:
20583 case NVPTX::BI__imma_m8n32k16_ld_b_s8:
20584 case NVPTX::BI__imma_m8n32k16_ld_b_u8:
20585 case NVPTX::BI__imma_m8n32k16_ld_c:
20587 case NVPTX::BI__imma_m8n8k32_ld_a_s4:
20588 case NVPTX::BI__imma_m8n8k32_ld_a_u4:
20589 case NVPTX::BI__imma_m8n8k32_ld_b_s4:
20590 case NVPTX::BI__imma_m8n8k32_ld_b_u4:
20591 case NVPTX::BI__imma_m8n8k32_ld_c:
20592 case NVPTX::BI__bmma_m8n8k128_ld_a_b1:
20593 case NVPTX::BI__bmma_m8n8k128_ld_b_b1:
20594 case NVPTX::BI__bmma_m8n8k128_ld_c:
20596 case NVPTX::BI__dmma_m8n8k4_ld_a:
20597 case NVPTX::BI__dmma_m8n8k4_ld_b:
20598 case NVPTX::BI__dmma_m8n8k4_ld_c:
20600 case NVPTX::BI__mma_bf16_m16n16k16_ld_a:
20601 case NVPTX::BI__mma_bf16_m16n16k16_ld_b:
20602 case NVPTX::BI__mma_bf16_m8n32k16_ld_a:
20603 case NVPTX::BI__mma_bf16_m8n32k16_ld_b:
20604 case NVPTX::BI__mma_bf16_m32n8k16_ld_a:
20605 case NVPTX::BI__mma_bf16_m32n8k16_ld_b:
20606 case NVPTX::BI__mma_tf32_m16n16k8_ld_a:
20607 case NVPTX::BI__mma_tf32_m16n16k8_ld_b:
20608 case NVPTX::BI__mma_tf32_m16n16k8_ld_c: {
20612 std::optional<llvm::APSInt> isColMajorArg =
20614 if (!isColMajorArg)
20616 bool isColMajor = isColMajorArg->getSExtValue();
20617 NVPTXMmaLdstInfo II = getNVPTXMmaLdstInfo(BuiltinID);
20618 unsigned IID = isColMajor ? II.IID_col : II.IID_row;
20626 assert(II.NumResults);
20627 if (II.NumResults == 1) {
20631 for (
unsigned i = 0; i < II.NumResults; ++i) {
20636 llvm::ConstantInt::get(
IntTy, i)),
20643 case NVPTX::BI__hmma_m16n16k16_st_c_f16:
20644 case NVPTX::BI__hmma_m16n16k16_st_c_f32:
20645 case NVPTX::BI__hmma_m32n8k16_st_c_f16:
20646 case NVPTX::BI__hmma_m32n8k16_st_c_f32:
20647 case NVPTX::BI__hmma_m8n32k16_st_c_f16:
20648 case NVPTX::BI__hmma_m8n32k16_st_c_f32:
20649 case NVPTX::BI__imma_m16n16k16_st_c_i32:
20650 case NVPTX::BI__imma_m32n8k16_st_c_i32:
20651 case NVPTX::BI__imma_m8n32k16_st_c_i32:
20652 case NVPTX::BI__imma_m8n8k32_st_c_i32:
20653 case NVPTX::BI__bmma_m8n8k128_st_c_i32:
20654 case NVPTX::BI__dmma_m8n8k4_st_c_f64:
20655 case NVPTX::BI__mma_m16n16k8_st_c_f32: {
20659 std::optional<llvm::APSInt> isColMajorArg =
20661 if (!isColMajorArg)
20663 bool isColMajor = isColMajorArg->getSExtValue();
20664 NVPTXMmaLdstInfo II = getNVPTXMmaLdstInfo(BuiltinID);
20665 unsigned IID = isColMajor ? II.IID_col : II.IID_row;
20670 llvm::Type *ParamType = Intrinsic->getFunctionType()->getParamType(1);
20672 for (
unsigned i = 0; i < II.NumResults; ++i) {
20676 llvm::ConstantInt::get(
IntTy, i)),
20678 Values.push_back(
Builder.CreateBitCast(
V, ParamType));
20680 Values.push_back(Ldm);
20687 case NVPTX::BI__hmma_m16n16k16_mma_f16f16:
20688 case NVPTX::BI__hmma_m16n16k16_mma_f32f16:
20689 case NVPTX::BI__hmma_m16n16k16_mma_f32f32:
20690 case NVPTX::BI__hmma_m16n16k16_mma_f16f32:
20691 case NVPTX::BI__hmma_m32n8k16_mma_f16f16:
20692 case NVPTX::BI__hmma_m32n8k16_mma_f32f16:
20693 case NVPTX::BI__hmma_m32n8k16_mma_f32f32:
20694 case NVPTX::BI__hmma_m32n8k16_mma_f16f32:
20695 case NVPTX::BI__hmma_m8n32k16_mma_f16f16:
20696 case NVPTX::BI__hmma_m8n32k16_mma_f32f16:
20697 case NVPTX::BI__hmma_m8n32k16_mma_f32f32:
20698 case NVPTX::BI__hmma_m8n32k16_mma_f16f32:
20699 case NVPTX::BI__imma_m16n16k16_mma_s8:
20700 case NVPTX::BI__imma_m16n16k16_mma_u8:
20701 case NVPTX::BI__imma_m32n8k16_mma_s8:
20702 case NVPTX::BI__imma_m32n8k16_mma_u8:
20703 case NVPTX::BI__imma_m8n32k16_mma_s8:
20704 case NVPTX::BI__imma_m8n32k16_mma_u8:
20705 case NVPTX::BI__imma_m8n8k32_mma_s4:
20706 case NVPTX::BI__imma_m8n8k32_mma_u4:
20707 case NVPTX::BI__bmma_m8n8k128_mma_xor_popc_b1:
20708 case NVPTX::BI__bmma_m8n8k128_mma_and_popc_b1:
20709 case NVPTX::BI__dmma_m8n8k4_mma_f64:
20710 case NVPTX::BI__mma_bf16_m16n16k16_mma_f32:
20711 case NVPTX::BI__mma_bf16_m8n32k16_mma_f32:
20712 case NVPTX::BI__mma_bf16_m32n8k16_mma_f32:
20713 case NVPTX::BI__mma_tf32_m16n16k8_mma_f32: {
20718 std::optional<llvm::APSInt> LayoutArg =
20722 int Layout = LayoutArg->getSExtValue();
20723 if (Layout < 0 || Layout > 3)
20725 llvm::APSInt SatfArg;
20726 if (BuiltinID == NVPTX::BI__bmma_m8n8k128_mma_xor_popc_b1 ||
20727 BuiltinID == NVPTX::BI__bmma_m8n8k128_mma_and_popc_b1)
20729 else if (std::optional<llvm::APSInt> OptSatfArg =
20731 SatfArg = *OptSatfArg;
20734 bool Satf = SatfArg.getSExtValue();
20735 NVPTXMmaInfo MI = getNVPTXMmaInfo(BuiltinID);
20736 unsigned IID = MI.getMMAIntrinsic(Layout, Satf);
20742 llvm::Type *AType = Intrinsic->getFunctionType()->getParamType(0);
20744 for (
unsigned i = 0; i < MI.NumEltsA; ++i) {
20748 llvm::ConstantInt::get(
IntTy, i)),
20750 Values.push_back(
Builder.CreateBitCast(
V, AType));
20753 llvm::Type *BType = Intrinsic->getFunctionType()->getParamType(MI.NumEltsA);
20754 for (
unsigned i = 0; i < MI.NumEltsB; ++i) {
20758 llvm::ConstantInt::get(
IntTy, i)),
20760 Values.push_back(
Builder.CreateBitCast(
V, BType));
20763 llvm::Type *CType =
20764 Intrinsic->getFunctionType()->getParamType(MI.NumEltsA + MI.NumEltsB);
20765 for (
unsigned i = 0; i < MI.NumEltsC; ++i) {
20769 llvm::ConstantInt::get(
IntTy, i)),
20771 Values.push_back(
Builder.CreateBitCast(
V, CType));
20775 for (
unsigned i = 0; i < MI.NumEltsD; ++i)
20779 llvm::ConstantInt::get(
IntTy, i)),
20784 case NVPTX::BI__nvvm_ex2_approx_f16:
20785 return MakeHalfType(Intrinsic::nvvm_ex2_approx_f16, BuiltinID,
E, *
this);
20786 case NVPTX::BI__nvvm_ex2_approx_f16x2:
20787 return MakeHalfType(Intrinsic::nvvm_ex2_approx_f16x2, BuiltinID,
E, *
this);
20788 case NVPTX::BI__nvvm_ff2f16x2_rn:
20789 return MakeHalfType(Intrinsic::nvvm_ff2f16x2_rn, BuiltinID,
E, *
this);
20790 case NVPTX::BI__nvvm_ff2f16x2_rn_relu:
20791 return MakeHalfType(Intrinsic::nvvm_ff2f16x2_rn_relu, BuiltinID,
E, *
this);
20792 case NVPTX::BI__nvvm_ff2f16x2_rz:
20793 return MakeHalfType(Intrinsic::nvvm_ff2f16x2_rz, BuiltinID,
E, *
this);
20794 case NVPTX::BI__nvvm_ff2f16x2_rz_relu:
20795 return MakeHalfType(Intrinsic::nvvm_ff2f16x2_rz_relu, BuiltinID,
E, *
this);
20796 case NVPTX::BI__nvvm_fma_rn_f16:
20797 return MakeHalfType(Intrinsic::nvvm_fma_rn_f16, BuiltinID,
E, *
this);
20798 case NVPTX::BI__nvvm_fma_rn_f16x2:
20799 return MakeHalfType(Intrinsic::nvvm_fma_rn_f16x2, BuiltinID,
E, *
this);
20800 case NVPTX::BI__nvvm_fma_rn_ftz_f16:
20801 return MakeHalfType(Intrinsic::nvvm_fma_rn_ftz_f16, BuiltinID,
E, *
this);
20802 case NVPTX::BI__nvvm_fma_rn_ftz_f16x2:
20803 return MakeHalfType(Intrinsic::nvvm_fma_rn_ftz_f16x2, BuiltinID,
E, *
this);
20804 case NVPTX::BI__nvvm_fma_rn_ftz_relu_f16:
20805 return MakeHalfType(Intrinsic::nvvm_fma_rn_ftz_relu_f16, BuiltinID,
E,
20807 case NVPTX::BI__nvvm_fma_rn_ftz_relu_f16x2:
20808 return MakeHalfType(Intrinsic::nvvm_fma_rn_ftz_relu_f16x2, BuiltinID,
E,
20810 case NVPTX::BI__nvvm_fma_rn_ftz_sat_f16:
20811 return MakeHalfType(Intrinsic::nvvm_fma_rn_ftz_sat_f16, BuiltinID,
E,
20813 case NVPTX::BI__nvvm_fma_rn_ftz_sat_f16x2:
20814 return MakeHalfType(Intrinsic::nvvm_fma_rn_ftz_sat_f16x2, BuiltinID,
E,
20816 case NVPTX::BI__nvvm_fma_rn_relu_f16:
20817 return MakeHalfType(Intrinsic::nvvm_fma_rn_relu_f16, BuiltinID,
E, *
this);
20818 case NVPTX::BI__nvvm_fma_rn_relu_f16x2:
20819 return MakeHalfType(Intrinsic::nvvm_fma_rn_relu_f16x2, BuiltinID,
E, *
this);
20820 case NVPTX::BI__nvvm_fma_rn_sat_f16:
20821 return MakeHalfType(Intrinsic::nvvm_fma_rn_sat_f16, BuiltinID,
E, *
this);
20822 case NVPTX::BI__nvvm_fma_rn_sat_f16x2:
20823 return MakeHalfType(Intrinsic::nvvm_fma_rn_sat_f16x2, BuiltinID,
E, *
this);
20824 case NVPTX::BI__nvvm_fmax_f16:
20825 return MakeHalfType(Intrinsic::nvvm_fmax_f16, BuiltinID,
E, *
this);
20826 case NVPTX::BI__nvvm_fmax_f16x2:
20827 return MakeHalfType(Intrinsic::nvvm_fmax_f16x2, BuiltinID,
E, *
this);
20828 case NVPTX::BI__nvvm_fmax_ftz_f16:
20829 return MakeHalfType(Intrinsic::nvvm_fmax_ftz_f16, BuiltinID,
E, *
this);
20830 case NVPTX::BI__nvvm_fmax_ftz_f16x2:
20831 return MakeHalfType(Intrinsic::nvvm_fmax_ftz_f16x2, BuiltinID,
E, *
this);
20832 case NVPTX::BI__nvvm_fmax_ftz_nan_f16:
20833 return MakeHalfType(Intrinsic::nvvm_fmax_ftz_nan_f16, BuiltinID,
E, *
this);
20834 case NVPTX::BI__nvvm_fmax_ftz_nan_f16x2:
20835 return MakeHalfType(Intrinsic::nvvm_fmax_ftz_nan_f16x2, BuiltinID,
E,
20837 case NVPTX::BI__nvvm_fmax_ftz_nan_xorsign_abs_f16:
20838 return MakeHalfType(Intrinsic::nvvm_fmax_ftz_nan_xorsign_abs_f16, BuiltinID,
20840 case NVPTX::BI__nvvm_fmax_ftz_nan_xorsign_abs_f16x2:
20841 return MakeHalfType(Intrinsic::nvvm_fmax_ftz_nan_xorsign_abs_f16x2,
20842 BuiltinID,
E, *
this);
20843 case NVPTX::BI__nvvm_fmax_ftz_xorsign_abs_f16:
20844 return MakeHalfType(Intrinsic::nvvm_fmax_ftz_xorsign_abs_f16, BuiltinID,
E,
20846 case NVPTX::BI__nvvm_fmax_ftz_xorsign_abs_f16x2:
20847 return MakeHalfType(Intrinsic::nvvm_fmax_ftz_xorsign_abs_f16x2, BuiltinID,
20849 case NVPTX::BI__nvvm_fmax_nan_f16:
20850 return MakeHalfType(Intrinsic::nvvm_fmax_nan_f16, BuiltinID,
E, *
this);
20851 case NVPTX::BI__nvvm_fmax_nan_f16x2:
20852 return MakeHalfType(Intrinsic::nvvm_fmax_nan_f16x2, BuiltinID,
E, *
this);
20853 case NVPTX::BI__nvvm_fmax_nan_xorsign_abs_f16:
20854 return MakeHalfType(Intrinsic::nvvm_fmax_nan_xorsign_abs_f16, BuiltinID,
E,
20856 case NVPTX::BI__nvvm_fmax_nan_xorsign_abs_f16x2:
20857 return MakeHalfType(Intrinsic::nvvm_fmax_nan_xorsign_abs_f16x2, BuiltinID,
20859 case NVPTX::BI__nvvm_fmax_xorsign_abs_f16:
20860 return MakeHalfType(Intrinsic::nvvm_fmax_xorsign_abs_f16, BuiltinID,
E,
20862 case NVPTX::BI__nvvm_fmax_xorsign_abs_f16x2:
20863 return MakeHalfType(Intrinsic::nvvm_fmax_xorsign_abs_f16x2, BuiltinID,
E,
20865 case NVPTX::BI__nvvm_fmin_f16:
20866 return MakeHalfType(Intrinsic::nvvm_fmin_f16, BuiltinID,
E, *
this);
20867 case NVPTX::BI__nvvm_fmin_f16x2:
20868 return MakeHalfType(Intrinsic::nvvm_fmin_f16x2, BuiltinID,
E, *
this);
20869 case NVPTX::BI__nvvm_fmin_ftz_f16:
20870 return MakeHalfType(Intrinsic::nvvm_fmin_ftz_f16, BuiltinID,
E, *
this);
20871 case NVPTX::BI__nvvm_fmin_ftz_f16x2:
20872 return MakeHalfType(Intrinsic::nvvm_fmin_ftz_f16x2, BuiltinID,
E, *
this);
20873 case NVPTX::BI__nvvm_fmin_ftz_nan_f16:
20874 return MakeHalfType(Intrinsic::nvvm_fmin_ftz_nan_f16, BuiltinID,
E, *
this);
20875 case NVPTX::BI__nvvm_fmin_ftz_nan_f16x2:
20876 return MakeHalfType(Intrinsic::nvvm_fmin_ftz_nan_f16x2, BuiltinID,
E,
20878 case NVPTX::BI__nvvm_fmin_ftz_nan_xorsign_abs_f16:
20879 return MakeHalfType(Intrinsic::nvvm_fmin_ftz_nan_xorsign_abs_f16, BuiltinID,
20881 case NVPTX::BI__nvvm_fmin_ftz_nan_xorsign_abs_f16x2:
20882 return MakeHalfType(Intrinsic::nvvm_fmin_ftz_nan_xorsign_abs_f16x2,
20883 BuiltinID,
E, *
this);
20884 case NVPTX::BI__nvvm_fmin_ftz_xorsign_abs_f16:
20885 return MakeHalfType(Intrinsic::nvvm_fmin_ftz_xorsign_abs_f16, BuiltinID,
E,
20887 case NVPTX::BI__nvvm_fmin_ftz_xorsign_abs_f16x2:
20888 return MakeHalfType(Intrinsic::nvvm_fmin_ftz_xorsign_abs_f16x2, BuiltinID,
20890 case NVPTX::BI__nvvm_fmin_nan_f16:
20891 return MakeHalfType(Intrinsic::nvvm_fmin_nan_f16, BuiltinID,
E, *
this);
20892 case NVPTX::BI__nvvm_fmin_nan_f16x2:
20893 return MakeHalfType(Intrinsic::nvvm_fmin_nan_f16x2, BuiltinID,
E, *
this);
20894 case NVPTX::BI__nvvm_fmin_nan_xorsign_abs_f16:
20895 return MakeHalfType(Intrinsic::nvvm_fmin_nan_xorsign_abs_f16, BuiltinID,
E,
20897 case NVPTX::BI__nvvm_fmin_nan_xorsign_abs_f16x2:
20898 return MakeHalfType(Intrinsic::nvvm_fmin_nan_xorsign_abs_f16x2, BuiltinID,
20900 case NVPTX::BI__nvvm_fmin_xorsign_abs_f16:
20901 return MakeHalfType(Intrinsic::nvvm_fmin_xorsign_abs_f16, BuiltinID,
E,
20903 case NVPTX::BI__nvvm_fmin_xorsign_abs_f16x2:
20904 return MakeHalfType(Intrinsic::nvvm_fmin_xorsign_abs_f16x2, BuiltinID,
E,
20906 case NVPTX::BI__nvvm_ldg_h:
20907 return MakeHalfType(Intrinsic::nvvm_ldg_global_f, BuiltinID,
E, *
this);
20908 case NVPTX::BI__nvvm_ldg_h2:
20909 return MakeHalfType(Intrinsic::nvvm_ldg_global_f, BuiltinID,
E, *
this);
20910 case NVPTX::BI__nvvm_ldu_h:
20911 return MakeHalfType(Intrinsic::nvvm_ldu_global_f, BuiltinID,
E, *
this);
20912 case NVPTX::BI__nvvm_ldu_h2: {
20913 return MakeHalfType(Intrinsic::nvvm_ldu_global_f, BuiltinID,
E, *
this);
20915 case NVPTX::BI__nvvm_cp_async_ca_shared_global_4:
20916 return MakeCpAsync(Intrinsic::nvvm_cp_async_ca_shared_global_4,
20917 Intrinsic::nvvm_cp_async_ca_shared_global_4_s, *
this,
E,
20919 case NVPTX::BI__nvvm_cp_async_ca_shared_global_8:
20920 return MakeCpAsync(Intrinsic::nvvm_cp_async_ca_shared_global_8,
20921 Intrinsic::nvvm_cp_async_ca_shared_global_8_s, *
this,
E,
20923 case NVPTX::BI__nvvm_cp_async_ca_shared_global_16:
20924 return MakeCpAsync(Intrinsic::nvvm_cp_async_ca_shared_global_16,
20925 Intrinsic::nvvm_cp_async_ca_shared_global_16_s, *
this,
E,
20927 case NVPTX::BI__nvvm_cp_async_cg_shared_global_16:
20928 return MakeCpAsync(Intrinsic::nvvm_cp_async_cg_shared_global_16,
20929 Intrinsic::nvvm_cp_async_cg_shared_global_16_s, *
this,
E,
20931 case NVPTX::BI__nvvm_read_ptx_sreg_clusterid_x:
20934 case NVPTX::BI__nvvm_read_ptx_sreg_clusterid_y:
20937 case NVPTX::BI__nvvm_read_ptx_sreg_clusterid_z:
20940 case NVPTX::BI__nvvm_read_ptx_sreg_clusterid_w:
20943 case NVPTX::BI__nvvm_read_ptx_sreg_nclusterid_x:
20946 case NVPTX::BI__nvvm_read_ptx_sreg_nclusterid_y:
20949 case NVPTX::BI__nvvm_read_ptx_sreg_nclusterid_z:
20952 case NVPTX::BI__nvvm_read_ptx_sreg_nclusterid_w:
20955 case NVPTX::BI__nvvm_read_ptx_sreg_cluster_ctaid_x:
20958 case NVPTX::BI__nvvm_read_ptx_sreg_cluster_ctaid_y:
20961 case NVPTX::BI__nvvm_read_ptx_sreg_cluster_ctaid_z:
20964 case NVPTX::BI__nvvm_read_ptx_sreg_cluster_ctaid_w:
20967 case NVPTX::BI__nvvm_read_ptx_sreg_cluster_nctaid_x:
20970 case NVPTX::BI__nvvm_read_ptx_sreg_cluster_nctaid_y:
20973 case NVPTX::BI__nvvm_read_ptx_sreg_cluster_nctaid_z:
20976 case NVPTX::BI__nvvm_read_ptx_sreg_cluster_nctaid_w:
20979 case NVPTX::BI__nvvm_read_ptx_sreg_cluster_ctarank:
20982 case NVPTX::BI__nvvm_read_ptx_sreg_cluster_nctarank:
20985 case NVPTX::BI__nvvm_is_explicit_cluster:
20988 case NVPTX::BI__nvvm_isspacep_shared_cluster:
20992 case NVPTX::BI__nvvm_mapa:
20995 {EmitScalarExpr(E->getArg(0)), EmitScalarExpr(E->getArg(1))});
20996 case NVPTX::BI__nvvm_mapa_shared_cluster:
20999 {EmitScalarExpr(E->getArg(0)), EmitScalarExpr(E->getArg(1))});
21000 case NVPTX::BI__nvvm_getctarank:
21004 case NVPTX::BI__nvvm_getctarank_shared_cluster:
21008 case NVPTX::BI__nvvm_barrier_cluster_arrive:
21011 case NVPTX::BI__nvvm_barrier_cluster_arrive_relaxed:
21014 case NVPTX::BI__nvvm_barrier_cluster_wait:
21017 case NVPTX::BI__nvvm_fence_sc_cluster:
21026struct BuiltinAlignArgs {
21027 llvm::Value *Src =
nullptr;
21028 llvm::Type *SrcType =
nullptr;
21029 llvm::Value *Alignment =
nullptr;
21030 llvm::Value *Mask =
nullptr;
21031 llvm::IntegerType *IntType =
nullptr;
21039 SrcType = Src->getType();
21040 if (SrcType->isPointerTy()) {
21041 IntType = IntegerType::get(
21045 assert(SrcType->isIntegerTy());
21046 IntType = cast<llvm::IntegerType>(SrcType);
21049 Alignment = CGF.
Builder.CreateZExtOrTrunc(Alignment, IntType,
"alignment");
21050 auto *One = llvm::ConstantInt::get(IntType, 1);
21051 Mask = CGF.
Builder.CreateSub(Alignment, One,
"mask");
21058 BuiltinAlignArgs Args(
E, *
this);
21059 llvm::Value *SrcAddress = Args.Src;
21060 if (Args.SrcType->isPointerTy())
21062 Builder.CreateBitOrPointerCast(Args.Src, Args.IntType,
"src_addr");
21064 Builder.CreateAnd(SrcAddress, Args.Mask,
"set_bits"),
21065 llvm::Constant::getNullValue(Args.IntType),
"is_aligned"));
21072 BuiltinAlignArgs Args(
E, *
this);
21073 llvm::Value *SrcForMask = Args.Src;
21079 if (Args.Src->getType()->isPointerTy()) {
21089 SrcForMask =
Builder.CreateAdd(SrcForMask, Args.Mask,
"over_boundary");
21093 llvm::Value *InvertedMask =
Builder.CreateNot(Args.Mask,
"inverted_mask");
21094 llvm::Value *
Result =
nullptr;
21095 if (Args.Src->getType()->isPointerTy()) {
21097 Intrinsic::ptrmask, {Args.SrcType, Args.IntType},
21098 {SrcForMask, InvertedMask},
nullptr,
"aligned_result");
21100 Result =
Builder.CreateAnd(SrcForMask, InvertedMask,
"aligned_result");
21102 assert(
Result->getType() == Args.SrcType);
21108 switch (BuiltinID) {
21109 case WebAssembly::BI__builtin_wasm_memory_size: {
21114 return Builder.CreateCall(Callee, I);
21116 case WebAssembly::BI__builtin_wasm_memory_grow: {
21122 return Builder.CreateCall(Callee, Args);
21124 case WebAssembly::BI__builtin_wasm_tls_size: {
21127 return Builder.CreateCall(Callee);
21129 case WebAssembly::BI__builtin_wasm_tls_align: {
21132 return Builder.CreateCall(Callee);
21134 case WebAssembly::BI__builtin_wasm_tls_base: {
21136 return Builder.CreateCall(Callee);
21138 case WebAssembly::BI__builtin_wasm_throw: {
21142 return Builder.CreateCall(Callee, {
Tag, Obj});
21144 case WebAssembly::BI__builtin_wasm_rethrow: {
21146 return Builder.CreateCall(Callee);
21148 case WebAssembly::BI__builtin_wasm_memory_atomic_wait32: {
21155 case WebAssembly::BI__builtin_wasm_memory_atomic_wait64: {
21162 case WebAssembly::BI__builtin_wasm_memory_atomic_notify: {
21166 return Builder.CreateCall(Callee, {Addr, Count});
21168 case WebAssembly::BI__builtin_wasm_trunc_s_i32_f32:
21169 case WebAssembly::BI__builtin_wasm_trunc_s_i32_f64:
21170 case WebAssembly::BI__builtin_wasm_trunc_s_i64_f32:
21171 case WebAssembly::BI__builtin_wasm_trunc_s_i64_f64: {
21176 return Builder.CreateCall(Callee, {Src});
21178 case WebAssembly::BI__builtin_wasm_trunc_u_i32_f32:
21179 case WebAssembly::BI__builtin_wasm_trunc_u_i32_f64:
21180 case WebAssembly::BI__builtin_wasm_trunc_u_i64_f32:
21181 case WebAssembly::BI__builtin_wasm_trunc_u_i64_f64: {
21186 return Builder.CreateCall(Callee, {Src});
21188 case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i32_f32:
21189 case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i32_f64:
21190 case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i64_f32:
21191 case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i64_f64:
21192 case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i32x4_f32x4: {
21197 return Builder.CreateCall(Callee, {Src});
21199 case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i32_f32:
21200 case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i32_f64:
21201 case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i64_f32:
21202 case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i64_f64:
21203 case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i32x4_f32x4: {
21208 return Builder.CreateCall(Callee, {Src});
21210 case WebAssembly::BI__builtin_wasm_min_f32:
21211 case WebAssembly::BI__builtin_wasm_min_f64:
21212 case WebAssembly::BI__builtin_wasm_min_f16x8:
21213 case WebAssembly::BI__builtin_wasm_min_f32x4:
21214 case WebAssembly::BI__builtin_wasm_min_f64x2: {
21219 return Builder.CreateCall(Callee, {LHS, RHS});
21221 case WebAssembly::BI__builtin_wasm_max_f32:
21222 case WebAssembly::BI__builtin_wasm_max_f64:
21223 case WebAssembly::BI__builtin_wasm_max_f16x8:
21224 case WebAssembly::BI__builtin_wasm_max_f32x4:
21225 case WebAssembly::BI__builtin_wasm_max_f64x2: {
21230 return Builder.CreateCall(Callee, {LHS, RHS});
21232 case WebAssembly::BI__builtin_wasm_pmin_f16x8:
21233 case WebAssembly::BI__builtin_wasm_pmin_f32x4:
21234 case WebAssembly::BI__builtin_wasm_pmin_f64x2: {
21239 return Builder.CreateCall(Callee, {LHS, RHS});
21241 case WebAssembly::BI__builtin_wasm_pmax_f16x8:
21242 case WebAssembly::BI__builtin_wasm_pmax_f32x4:
21243 case WebAssembly::BI__builtin_wasm_pmax_f64x2: {
21248 return Builder.CreateCall(Callee, {LHS, RHS});
21250 case WebAssembly::BI__builtin_wasm_ceil_f32x4:
21251 case WebAssembly::BI__builtin_wasm_floor_f32x4:
21252 case WebAssembly::BI__builtin_wasm_trunc_f32x4:
21253 case WebAssembly::BI__builtin_wasm_nearest_f32x4:
21254 case WebAssembly::BI__builtin_wasm_ceil_f64x2:
21255 case WebAssembly::BI__builtin_wasm_floor_f64x2:
21256 case WebAssembly::BI__builtin_wasm_trunc_f64x2:
21257 case WebAssembly::BI__builtin_wasm_nearest_f64x2: {
21259 switch (BuiltinID) {
21260 case WebAssembly::BI__builtin_wasm_ceil_f32x4:
21261 case WebAssembly::BI__builtin_wasm_ceil_f64x2:
21262 IntNo = Intrinsic::ceil;
21264 case WebAssembly::BI__builtin_wasm_floor_f32x4:
21265 case WebAssembly::BI__builtin_wasm_floor_f64x2:
21266 IntNo = Intrinsic::floor;
21268 case WebAssembly::BI__builtin_wasm_trunc_f32x4:
21269 case WebAssembly::BI__builtin_wasm_trunc_f64x2:
21270 IntNo = Intrinsic::trunc;
21272 case WebAssembly::BI__builtin_wasm_nearest_f32x4:
21273 case WebAssembly::BI__builtin_wasm_nearest_f64x2:
21274 IntNo = Intrinsic::nearbyint;
21277 llvm_unreachable(
"unexpected builtin ID");
21283 case WebAssembly::BI__builtin_wasm_ref_null_extern: {
21285 return Builder.CreateCall(Callee);
21287 case WebAssembly::BI__builtin_wasm_ref_null_func: {
21289 return Builder.CreateCall(Callee);
21291 case WebAssembly::BI__builtin_wasm_swizzle_i8x16: {
21295 return Builder.CreateCall(Callee, {Src, Indices});
21297 case WebAssembly::BI__builtin_wasm_add_sat_s_i8x16:
21298 case WebAssembly::BI__builtin_wasm_add_sat_u_i8x16:
21299 case WebAssembly::BI__builtin_wasm_add_sat_s_i16x8:
21300 case WebAssembly::BI__builtin_wasm_add_sat_u_i16x8:
21301 case WebAssembly::BI__builtin_wasm_sub_sat_s_i8x16:
21302 case WebAssembly::BI__builtin_wasm_sub_sat_u_i8x16:
21303 case WebAssembly::BI__builtin_wasm_sub_sat_s_i16x8:
21304 case WebAssembly::BI__builtin_wasm_sub_sat_u_i16x8: {
21306 switch (BuiltinID) {
21307 case WebAssembly::BI__builtin_wasm_add_sat_s_i8x16:
21308 case WebAssembly::BI__builtin_wasm_add_sat_s_i16x8:
21309 IntNo = Intrinsic::sadd_sat;
21311 case WebAssembly::BI__builtin_wasm_add_sat_u_i8x16:
21312 case WebAssembly::BI__builtin_wasm_add_sat_u_i16x8:
21313 IntNo = Intrinsic::uadd_sat;
21315 case WebAssembly::BI__builtin_wasm_sub_sat_s_i8x16:
21316 case WebAssembly::BI__builtin_wasm_sub_sat_s_i16x8:
21317 IntNo = Intrinsic::wasm_sub_sat_signed;
21319 case WebAssembly::BI__builtin_wasm_sub_sat_u_i8x16:
21320 case WebAssembly::BI__builtin_wasm_sub_sat_u_i16x8:
21321 IntNo = Intrinsic::wasm_sub_sat_unsigned;
21324 llvm_unreachable(
"unexpected builtin ID");
21329 return Builder.CreateCall(Callee, {LHS, RHS});
21331 case WebAssembly::BI__builtin_wasm_abs_i8x16:
21332 case WebAssembly::BI__builtin_wasm_abs_i16x8:
21333 case WebAssembly::BI__builtin_wasm_abs_i32x4:
21334 case WebAssembly::BI__builtin_wasm_abs_i64x2: {
21337 Constant *
Zero = llvm::Constant::getNullValue(Vec->
getType());
21338 Value *ICmp =
Builder.CreateICmpSLT(Vec, Zero,
"abscond");
21339 return Builder.CreateSelect(ICmp, Neg, Vec,
"abs");
21341 case WebAssembly::BI__builtin_wasm_min_s_i8x16:
21342 case WebAssembly::BI__builtin_wasm_min_u_i8x16:
21343 case WebAssembly::BI__builtin_wasm_max_s_i8x16:
21344 case WebAssembly::BI__builtin_wasm_max_u_i8x16:
21345 case WebAssembly::BI__builtin_wasm_min_s_i16x8:
21346 case WebAssembly::BI__builtin_wasm_min_u_i16x8:
21347 case WebAssembly::BI__builtin_wasm_max_s_i16x8:
21348 case WebAssembly::BI__builtin_wasm_max_u_i16x8:
21349 case WebAssembly::BI__builtin_wasm_min_s_i32x4:
21350 case WebAssembly::BI__builtin_wasm_min_u_i32x4:
21351 case WebAssembly::BI__builtin_wasm_max_s_i32x4:
21352 case WebAssembly::BI__builtin_wasm_max_u_i32x4: {
21356 switch (BuiltinID) {
21357 case WebAssembly::BI__builtin_wasm_min_s_i8x16:
21358 case WebAssembly::BI__builtin_wasm_min_s_i16x8:
21359 case WebAssembly::BI__builtin_wasm_min_s_i32x4:
21360 ICmp =
Builder.CreateICmpSLT(LHS, RHS);
21362 case WebAssembly::BI__builtin_wasm_min_u_i8x16:
21363 case WebAssembly::BI__builtin_wasm_min_u_i16x8:
21364 case WebAssembly::BI__builtin_wasm_min_u_i32x4:
21365 ICmp =
Builder.CreateICmpULT(LHS, RHS);
21367 case WebAssembly::BI__builtin_wasm_max_s_i8x16:
21368 case WebAssembly::BI__builtin_wasm_max_s_i16x8:
21369 case WebAssembly::BI__builtin_wasm_max_s_i32x4:
21370 ICmp =
Builder.CreateICmpSGT(LHS, RHS);
21372 case WebAssembly::BI__builtin_wasm_max_u_i8x16:
21373 case WebAssembly::BI__builtin_wasm_max_u_i16x8:
21374 case WebAssembly::BI__builtin_wasm_max_u_i32x4:
21375 ICmp =
Builder.CreateICmpUGT(LHS, RHS);
21378 llvm_unreachable(
"unexpected builtin ID");
21380 return Builder.CreateSelect(ICmp, LHS, RHS);
21382 case WebAssembly::BI__builtin_wasm_avgr_u_i8x16:
21383 case WebAssembly::BI__builtin_wasm_avgr_u_i16x8: {
21388 return Builder.CreateCall(Callee, {LHS, RHS});
21390 case WebAssembly::BI__builtin_wasm_q15mulr_sat_s_i16x8: {
21394 return Builder.CreateCall(Callee, {LHS, RHS});
21396 case WebAssembly::BI__builtin_wasm_extadd_pairwise_i8x16_s_i16x8:
21397 case WebAssembly::BI__builtin_wasm_extadd_pairwise_i8x16_u_i16x8:
21398 case WebAssembly::BI__builtin_wasm_extadd_pairwise_i16x8_s_i32x4:
21399 case WebAssembly::BI__builtin_wasm_extadd_pairwise_i16x8_u_i32x4: {
21402 switch (BuiltinID) {
21403 case WebAssembly::BI__builtin_wasm_extadd_pairwise_i8x16_s_i16x8:
21404 case WebAssembly::BI__builtin_wasm_extadd_pairwise_i16x8_s_i32x4:
21405 IntNo = Intrinsic::wasm_extadd_pairwise_signed;
21407 case WebAssembly::BI__builtin_wasm_extadd_pairwise_i8x16_u_i16x8:
21408 case WebAssembly::BI__builtin_wasm_extadd_pairwise_i16x8_u_i32x4:
21409 IntNo = Intrinsic::wasm_extadd_pairwise_unsigned;
21412 llvm_unreachable(
"unexpected builtin ID");
21416 return Builder.CreateCall(Callee, Vec);
21418 case WebAssembly::BI__builtin_wasm_bitselect: {
21424 return Builder.CreateCall(Callee, {V1, V2,
C});
21426 case WebAssembly::BI__builtin_wasm_dot_s_i32x4_i16x8: {
21430 return Builder.CreateCall(Callee, {LHS, RHS});
21432 case WebAssembly::BI__builtin_wasm_popcnt_i8x16: {
21436 return Builder.CreateCall(Callee, {Vec});
21438 case WebAssembly::BI__builtin_wasm_any_true_v128:
21439 case WebAssembly::BI__builtin_wasm_all_true_i8x16:
21440 case WebAssembly::BI__builtin_wasm_all_true_i16x8:
21441 case WebAssembly::BI__builtin_wasm_all_true_i32x4:
21442 case WebAssembly::BI__builtin_wasm_all_true_i64x2: {
21444 switch (BuiltinID) {
21445 case WebAssembly::BI__builtin_wasm_any_true_v128:
21446 IntNo = Intrinsic::wasm_anytrue;
21448 case WebAssembly::BI__builtin_wasm_all_true_i8x16:
21449 case WebAssembly::BI__builtin_wasm_all_true_i16x8:
21450 case WebAssembly::BI__builtin_wasm_all_true_i32x4:
21451 case WebAssembly::BI__builtin_wasm_all_true_i64x2:
21452 IntNo = Intrinsic::wasm_alltrue;
21455 llvm_unreachable(
"unexpected builtin ID");
21459 return Builder.CreateCall(Callee, {Vec});
21461 case WebAssembly::BI__builtin_wasm_bitmask_i8x16:
21462 case WebAssembly::BI__builtin_wasm_bitmask_i16x8:
21463 case WebAssembly::BI__builtin_wasm_bitmask_i32x4:
21464 case WebAssembly::BI__builtin_wasm_bitmask_i64x2: {
21468 return Builder.CreateCall(Callee, {Vec});
21470 case WebAssembly::BI__builtin_wasm_abs_f32x4:
21471 case WebAssembly::BI__builtin_wasm_abs_f64x2: {
21474 return Builder.CreateCall(Callee, {Vec});
21476 case WebAssembly::BI__builtin_wasm_sqrt_f32x4:
21477 case WebAssembly::BI__builtin_wasm_sqrt_f64x2: {
21480 return Builder.CreateCall(Callee, {Vec});
21482 case WebAssembly::BI__builtin_wasm_narrow_s_i8x16_i16x8:
21483 case WebAssembly::BI__builtin_wasm_narrow_u_i8x16_i16x8:
21484 case WebAssembly::BI__builtin_wasm_narrow_s_i16x8_i32x4:
21485 case WebAssembly::BI__builtin_wasm_narrow_u_i16x8_i32x4: {
21489 switch (BuiltinID) {
21490 case WebAssembly::BI__builtin_wasm_narrow_s_i8x16_i16x8:
21491 case WebAssembly::BI__builtin_wasm_narrow_s_i16x8_i32x4:
21492 IntNo = Intrinsic::wasm_narrow_signed;
21494 case WebAssembly::BI__builtin_wasm_narrow_u_i8x16_i16x8:
21495 case WebAssembly::BI__builtin_wasm_narrow_u_i16x8_i32x4:
21496 IntNo = Intrinsic::wasm_narrow_unsigned;
21499 llvm_unreachable(
"unexpected builtin ID");
21503 return Builder.CreateCall(Callee, {Low, High});
21505 case WebAssembly::BI__builtin_wasm_trunc_sat_s_zero_f64x2_i32x4:
21506 case WebAssembly::BI__builtin_wasm_trunc_sat_u_zero_f64x2_i32x4: {
21509 switch (BuiltinID) {
21510 case WebAssembly::BI__builtin_wasm_trunc_sat_s_zero_f64x2_i32x4:
21511 IntNo = Intrinsic::fptosi_sat;
21513 case WebAssembly::BI__builtin_wasm_trunc_sat_u_zero_f64x2_i32x4:
21514 IntNo = Intrinsic::fptoui_sat;
21517 llvm_unreachable(
"unexpected builtin ID");
21519 llvm::Type *SrcT = Vec->
getType();
21520 llvm::Type *TruncT = SrcT->getWithNewType(
Builder.getInt32Ty());
21523 Value *Splat = Constant::getNullValue(TruncT);
21526 case WebAssembly::BI__builtin_wasm_shuffle_i8x16: {
21531 while (OpIdx < 18) {
21532 std::optional<llvm::APSInt> LaneConst =
21534 assert(LaneConst &&
"Constant arg isn't actually constant?");
21535 Ops[OpIdx++] = llvm::ConstantInt::get(
getLLVMContext(), *LaneConst);
21538 return Builder.CreateCall(Callee, Ops);
21540 case WebAssembly::BI__builtin_wasm_relaxed_madd_f16x8:
21541 case WebAssembly::BI__builtin_wasm_relaxed_nmadd_f16x8:
21542 case WebAssembly::BI__builtin_wasm_relaxed_madd_f32x4:
21543 case WebAssembly::BI__builtin_wasm_relaxed_nmadd_f32x4:
21544 case WebAssembly::BI__builtin_wasm_relaxed_madd_f64x2:
21545 case WebAssembly::BI__builtin_wasm_relaxed_nmadd_f64x2: {
21550 switch (BuiltinID) {
21551 case WebAssembly::BI__builtin_wasm_relaxed_madd_f16x8:
21552 case WebAssembly::BI__builtin_wasm_relaxed_madd_f32x4:
21553 case WebAssembly::BI__builtin_wasm_relaxed_madd_f64x2:
21554 IntNo = Intrinsic::wasm_relaxed_madd;
21556 case WebAssembly::BI__builtin_wasm_relaxed_nmadd_f16x8:
21557 case WebAssembly::BI__builtin_wasm_relaxed_nmadd_f32x4:
21558 case WebAssembly::BI__builtin_wasm_relaxed_nmadd_f64x2:
21559 IntNo = Intrinsic::wasm_relaxed_nmadd;
21562 llvm_unreachable(
"unexpected builtin ID");
21565 return Builder.CreateCall(Callee, {A, B,
C});
21567 case WebAssembly::BI__builtin_wasm_relaxed_laneselect_i8x16:
21568 case WebAssembly::BI__builtin_wasm_relaxed_laneselect_i16x8:
21569 case WebAssembly::BI__builtin_wasm_relaxed_laneselect_i32x4:
21570 case WebAssembly::BI__builtin_wasm_relaxed_laneselect_i64x2: {
21576 return Builder.CreateCall(Callee, {A, B,
C});
21578 case WebAssembly::BI__builtin_wasm_relaxed_swizzle_i8x16: {
21582 return Builder.CreateCall(Callee, {Src, Indices});
21584 case WebAssembly::BI__builtin_wasm_relaxed_min_f32x4:
21585 case WebAssembly::BI__builtin_wasm_relaxed_max_f32x4:
21586 case WebAssembly::BI__builtin_wasm_relaxed_min_f64x2:
21587 case WebAssembly::BI__builtin_wasm_relaxed_max_f64x2: {
21591 switch (BuiltinID) {
21592 case WebAssembly::BI__builtin_wasm_relaxed_min_f32x4:
21593 case WebAssembly::BI__builtin_wasm_relaxed_min_f64x2:
21594 IntNo = Intrinsic::wasm_relaxed_min;
21596 case WebAssembly::BI__builtin_wasm_relaxed_max_f32x4:
21597 case WebAssembly::BI__builtin_wasm_relaxed_max_f64x2:
21598 IntNo = Intrinsic::wasm_relaxed_max;
21601 llvm_unreachable(
"unexpected builtin ID");
21604 return Builder.CreateCall(Callee, {LHS, RHS});
21606 case WebAssembly::BI__builtin_wasm_relaxed_trunc_s_i32x4_f32x4:
21607 case WebAssembly::BI__builtin_wasm_relaxed_trunc_u_i32x4_f32x4:
21608 case WebAssembly::BI__builtin_wasm_relaxed_trunc_s_zero_i32x4_f64x2:
21609 case WebAssembly::BI__builtin_wasm_relaxed_trunc_u_zero_i32x4_f64x2: {
21612 switch (BuiltinID) {
21613 case WebAssembly::BI__builtin_wasm_relaxed_trunc_s_i32x4_f32x4:
21614 IntNo = Intrinsic::wasm_relaxed_trunc_signed;
21616 case WebAssembly::BI__builtin_wasm_relaxed_trunc_u_i32x4_f32x4:
21617 IntNo = Intrinsic::wasm_relaxed_trunc_unsigned;
21619 case WebAssembly::BI__builtin_wasm_relaxed_trunc_s_zero_i32x4_f64x2:
21620 IntNo = Intrinsic::wasm_relaxed_trunc_signed_zero;
21622 case WebAssembly::BI__builtin_wasm_relaxed_trunc_u_zero_i32x4_f64x2:
21623 IntNo = Intrinsic::wasm_relaxed_trunc_unsigned_zero;
21626 llvm_unreachable(
"unexpected builtin ID");
21629 return Builder.CreateCall(Callee, {Vec});
21631 case WebAssembly::BI__builtin_wasm_relaxed_q15mulr_s_i16x8: {
21635 return Builder.CreateCall(Callee, {LHS, RHS});
21637 case WebAssembly::BI__builtin_wasm_relaxed_dot_i8x16_i7x16_s_i16x8: {
21642 return Builder.CreateCall(Callee, {LHS, RHS});
21644 case WebAssembly::BI__builtin_wasm_relaxed_dot_i8x16_i7x16_add_s_i32x4: {
21649 CGM.
getIntrinsic(Intrinsic::wasm_relaxed_dot_i8x16_i7x16_add_signed);
21650 return Builder.CreateCall(Callee, {LHS, RHS, Acc});
21652 case WebAssembly::BI__builtin_wasm_relaxed_dot_bf16x8_add_f32_f32x4: {
21658 return Builder.CreateCall(Callee, {LHS, RHS, Acc});
21660 case WebAssembly::BI__builtin_wasm_loadf16_f32: {
21663 return Builder.CreateCall(Callee, {Addr});
21665 case WebAssembly::BI__builtin_wasm_storef16_f32: {
21669 return Builder.CreateCall(Callee, {Val, Addr});
21671 case WebAssembly::BI__builtin_wasm_splat_f16x8: {
21674 return Builder.CreateCall(Callee, {Val});
21676 case WebAssembly::BI__builtin_wasm_extract_lane_f16x8: {
21682 case WebAssembly::BI__builtin_wasm_replace_lane_f16x8: {
21689 case WebAssembly::BI__builtin_wasm_table_get: {
21700 "Unexpected reference type for __builtin_wasm_table_get");
21701 return Builder.CreateCall(Callee, {Table, Index});
21703 case WebAssembly::BI__builtin_wasm_table_set: {
21715 "Unexpected reference type for __builtin_wasm_table_set");
21716 return Builder.CreateCall(Callee, {Table, Index, Val});
21718 case WebAssembly::BI__builtin_wasm_table_size: {
21724 case WebAssembly::BI__builtin_wasm_table_grow: {
21737 "Unexpected reference type for __builtin_wasm_table_grow");
21739 return Builder.CreateCall(Callee, {Table, Val, NElems});
21741 case WebAssembly::BI__builtin_wasm_table_fill: {
21755 "Unexpected reference type for __builtin_wasm_table_fill");
21757 return Builder.CreateCall(Callee, {Table, Index, Val, NElems});
21759 case WebAssembly::BI__builtin_wasm_table_copy: {
21769 return Builder.CreateCall(Callee, {TableX, TableY, SrcIdx, DstIdx, NElems});
21776static std::pair<Intrinsic::ID, unsigned>
21779 unsigned BuiltinID;
21780 Intrinsic::ID IntrinsicID;
21783 static Info Infos[] = {
21784#define CUSTOM_BUILTIN_MAPPING(x,s) \
21785 { Hexagon::BI__builtin_HEXAGON_##x, Intrinsic::hexagon_##x, s },
21817#include "clang/Basic/BuiltinsHexagonMapCustomDep.def"
21818#undef CUSTOM_BUILTIN_MAPPING
21821 auto CmpInfo = [] (Info A, Info B) {
return A.BuiltinID < B.BuiltinID; };
21822 static const bool SortOnce = (llvm::sort(Infos, CmpInfo),
true);
21825 const Info *F = llvm::lower_bound(Infos, Info{BuiltinID, 0, 0}, CmpInfo);
21826 if (F == std::end(Infos) || F->BuiltinID != BuiltinID)
21827 return {Intrinsic::not_intrinsic, 0};
21829 return {F->IntrinsicID, F->VecLen};
21838 auto MakeCircOp = [
this,
E](
unsigned IntID,
bool IsLoad) {
21852 for (
unsigned i = 1, e =
E->getNumArgs(); i != e; ++i)
21858 llvm::Value *NewBase = IsLoad ?
Builder.CreateExtractValue(
Result, 1)
21862 llvm::Value *RetVal =
21872 auto MakeBrevLd = [
this,
E](
unsigned IntID, llvm::Type *DestTy) {
21889 CGM.
getIntrinsic(IntID), {BaseAddress, EmitScalarExpr(E->getArg(2))});
21892 llvm::Value *DestVal =
Builder.CreateExtractValue(
Result, 0);
21897 DestVal =
Builder.CreateTrunc(DestVal, DestTy);
21904 auto V2Q = [
this, VecLen] (llvm::Value *Vec) {
21905 Intrinsic::ID
ID = VecLen == 128 ? Intrinsic::hexagon_V6_vandvrt_128B
21906 : Intrinsic::hexagon_V6_vandvrt;
21908 {Vec,
Builder.getInt32(-1)});
21910 auto Q2V = [
this, VecLen] (llvm::Value *Pred) {
21911 Intrinsic::ID
ID = VecLen == 128 ? Intrinsic::hexagon_V6_vandqrt_128B
21912 : Intrinsic::hexagon_V6_vandqrt;
21914 {Pred,
Builder.getInt32(-1)});
21917 switch (BuiltinID) {
21921 case Hexagon::BI__builtin_HEXAGON_V6_vaddcarry:
21922 case Hexagon::BI__builtin_HEXAGON_V6_vaddcarry_128B:
21923 case Hexagon::BI__builtin_HEXAGON_V6_vsubcarry:
21924 case Hexagon::BI__builtin_HEXAGON_V6_vsubcarry_128B: {
21931 {EmitScalarExpr(E->getArg(0)), EmitScalarExpr(E->getArg(1)), PredIn});
21933 llvm::Value *PredOut =
Builder.CreateExtractValue(
Result, 1);
21941 case Hexagon::BI__builtin_HEXAGON_V6_vaddcarryo:
21942 case Hexagon::BI__builtin_HEXAGON_V6_vaddcarryo_128B:
21943 case Hexagon::BI__builtin_HEXAGON_V6_vsubcarryo:
21944 case Hexagon::BI__builtin_HEXAGON_V6_vsubcarryo_128B: {
21950 {EmitScalarExpr(E->getArg(0)), EmitScalarExpr(E->getArg(1))});
21952 llvm::Value *PredOut =
Builder.CreateExtractValue(
Result, 1);
21958 case Hexagon::BI__builtin_HEXAGON_V6_vmaskedstoreq:
21959 case Hexagon::BI__builtin_HEXAGON_V6_vmaskedstorenq:
21960 case Hexagon::BI__builtin_HEXAGON_V6_vmaskedstorentq:
21961 case Hexagon::BI__builtin_HEXAGON_V6_vmaskedstorentnq:
21962 case Hexagon::BI__builtin_HEXAGON_V6_vmaskedstoreq_128B:
21963 case Hexagon::BI__builtin_HEXAGON_V6_vmaskedstorenq_128B:
21964 case Hexagon::BI__builtin_HEXAGON_V6_vmaskedstorentq_128B:
21965 case Hexagon::BI__builtin_HEXAGON_V6_vmaskedstorentnq_128B: {
21967 const Expr *PredOp =
E->getArg(0);
21969 if (
auto *Cast = dyn_cast<ImplicitCastExpr>(PredOp)) {
21970 if (
Cast->getCastKind() == CK_BitCast)
21971 PredOp =
Cast->getSubExpr();
21974 for (
int i = 1, e =
E->getNumArgs(); i != e; ++i)
21979 case Hexagon::BI__builtin_HEXAGON_L2_loadrub_pci:
21980 case Hexagon::BI__builtin_HEXAGON_L2_loadrb_pci:
21981 case Hexagon::BI__builtin_HEXAGON_L2_loadruh_pci:
21982 case Hexagon::BI__builtin_HEXAGON_L2_loadrh_pci:
21983 case Hexagon::BI__builtin_HEXAGON_L2_loadri_pci:
21984 case Hexagon::BI__builtin_HEXAGON_L2_loadrd_pci:
21985 case Hexagon::BI__builtin_HEXAGON_L2_loadrub_pcr:
21986 case Hexagon::BI__builtin_HEXAGON_L2_loadrb_pcr:
21987 case Hexagon::BI__builtin_HEXAGON_L2_loadruh_pcr:
21988 case Hexagon::BI__builtin_HEXAGON_L2_loadrh_pcr:
21989 case Hexagon::BI__builtin_HEXAGON_L2_loadri_pcr:
21990 case Hexagon::BI__builtin_HEXAGON_L2_loadrd_pcr:
21991 return MakeCircOp(ID,
true);
21992 case Hexagon::BI__builtin_HEXAGON_S2_storerb_pci:
21993 case Hexagon::BI__builtin_HEXAGON_S2_storerh_pci:
21994 case Hexagon::BI__builtin_HEXAGON_S2_storerf_pci:
21995 case Hexagon::BI__builtin_HEXAGON_S2_storeri_pci:
21996 case Hexagon::BI__builtin_HEXAGON_S2_storerd_pci:
21997 case Hexagon::BI__builtin_HEXAGON_S2_storerb_pcr:
21998 case Hexagon::BI__builtin_HEXAGON_S2_storerh_pcr:
21999 case Hexagon::BI__builtin_HEXAGON_S2_storerf_pcr:
22000 case Hexagon::BI__builtin_HEXAGON_S2_storeri_pcr:
22001 case Hexagon::BI__builtin_HEXAGON_S2_storerd_pcr:
22002 return MakeCircOp(ID,
false);
22003 case Hexagon::BI__builtin_brev_ldub:
22004 return MakeBrevLd(Intrinsic::hexagon_L2_loadrub_pbr,
Int8Ty);
22005 case Hexagon::BI__builtin_brev_ldb:
22006 return MakeBrevLd(Intrinsic::hexagon_L2_loadrb_pbr,
Int8Ty);
22007 case Hexagon::BI__builtin_brev_lduh:
22008 return MakeBrevLd(Intrinsic::hexagon_L2_loadruh_pbr,
Int16Ty);
22009 case Hexagon::BI__builtin_brev_ldh:
22010 return MakeBrevLd(Intrinsic::hexagon_L2_loadrh_pbr,
Int16Ty);
22011 case Hexagon::BI__builtin_brev_ldw:
22012 return MakeBrevLd(Intrinsic::hexagon_L2_loadri_pbr,
Int32Ty);
22013 case Hexagon::BI__builtin_brev_ldd:
22014 return MakeBrevLd(Intrinsic::hexagon_L2_loadrd_pbr,
Int64Ty);
22024 if (BuiltinID == Builtin::BI__builtin_cpu_supports)
22026 if (BuiltinID == Builtin::BI__builtin_cpu_init)
22033 unsigned ICEArguments = 0;
22041 if (BuiltinID == RISCVVector::BI__builtin_rvv_vget_v ||
22042 BuiltinID == RISCVVector::BI__builtin_rvv_vset_v)
22043 ICEArguments = 1 << 1;
22048 if (BuiltinID == RISCV::BI__builtin_riscv_ntl_load)
22049 ICEArguments |= (1 << 1);
22050 if (BuiltinID == RISCV::BI__builtin_riscv_ntl_store)
22051 ICEArguments |= (1 << 2);
22053 for (
unsigned i = 0, e =
E->getNumArgs(); i != e; i++) {
22058 Ops.push_back(AggValue);
22064 Intrinsic::ID
ID = Intrinsic::not_intrinsic;
22068 constexpr unsigned RVV_VTA = 0x1;
22069 constexpr unsigned RVV_VMA = 0x2;
22070 int PolicyAttrs = 0;
22071 bool IsMasked =
false;
22075 switch (BuiltinID) {
22076 default: llvm_unreachable(
"unexpected builtin ID");
22077 case RISCV::BI__builtin_riscv_orc_b_32:
22078 case RISCV::BI__builtin_riscv_orc_b_64:
22079 case RISCV::BI__builtin_riscv_clz_32:
22080 case RISCV::BI__builtin_riscv_clz_64:
22081 case RISCV::BI__builtin_riscv_ctz_32:
22082 case RISCV::BI__builtin_riscv_ctz_64:
22083 case RISCV::BI__builtin_riscv_clmul_32:
22084 case RISCV::BI__builtin_riscv_clmul_64:
22085 case RISCV::BI__builtin_riscv_clmulh_32:
22086 case RISCV::BI__builtin_riscv_clmulh_64:
22087 case RISCV::BI__builtin_riscv_clmulr_32:
22088 case RISCV::BI__builtin_riscv_clmulr_64:
22089 case RISCV::BI__builtin_riscv_xperm4_32:
22090 case RISCV::BI__builtin_riscv_xperm4_64:
22091 case RISCV::BI__builtin_riscv_xperm8_32:
22092 case RISCV::BI__builtin_riscv_xperm8_64:
22093 case RISCV::BI__builtin_riscv_brev8_32:
22094 case RISCV::BI__builtin_riscv_brev8_64:
22095 case RISCV::BI__builtin_riscv_zip_32:
22096 case RISCV::BI__builtin_riscv_unzip_32: {
22097 switch (BuiltinID) {
22098 default: llvm_unreachable(
"unexpected builtin ID");
22100 case RISCV::BI__builtin_riscv_orc_b_32:
22101 case RISCV::BI__builtin_riscv_orc_b_64:
22102 ID = Intrinsic::riscv_orc_b;
22104 case RISCV::BI__builtin_riscv_clz_32:
22105 case RISCV::BI__builtin_riscv_clz_64: {
22108 if (
Result->getType() != ResultType)
22113 case RISCV::BI__builtin_riscv_ctz_32:
22114 case RISCV::BI__builtin_riscv_ctz_64: {
22117 if (
Result->getType() != ResultType)
22124 case RISCV::BI__builtin_riscv_clmul_32:
22125 case RISCV::BI__builtin_riscv_clmul_64:
22126 ID = Intrinsic::riscv_clmul;
22128 case RISCV::BI__builtin_riscv_clmulh_32:
22129 case RISCV::BI__builtin_riscv_clmulh_64:
22130 ID = Intrinsic::riscv_clmulh;
22132 case RISCV::BI__builtin_riscv_clmulr_32:
22133 case RISCV::BI__builtin_riscv_clmulr_64:
22134 ID = Intrinsic::riscv_clmulr;
22138 case RISCV::BI__builtin_riscv_xperm8_32:
22139 case RISCV::BI__builtin_riscv_xperm8_64:
22140 ID = Intrinsic::riscv_xperm8;
22142 case RISCV::BI__builtin_riscv_xperm4_32:
22143 case RISCV::BI__builtin_riscv_xperm4_64:
22144 ID = Intrinsic::riscv_xperm4;
22148 case RISCV::BI__builtin_riscv_brev8_32:
22149 case RISCV::BI__builtin_riscv_brev8_64:
22150 ID = Intrinsic::riscv_brev8;
22152 case RISCV::BI__builtin_riscv_zip_32:
22153 ID = Intrinsic::riscv_zip;
22155 case RISCV::BI__builtin_riscv_unzip_32:
22156 ID = Intrinsic::riscv_unzip;
22160 IntrinsicTypes = {ResultType};
22167 case RISCV::BI__builtin_riscv_sha256sig0:
22168 ID = Intrinsic::riscv_sha256sig0;
22170 case RISCV::BI__builtin_riscv_sha256sig1:
22171 ID = Intrinsic::riscv_sha256sig1;
22173 case RISCV::BI__builtin_riscv_sha256sum0:
22174 ID = Intrinsic::riscv_sha256sum0;
22176 case RISCV::BI__builtin_riscv_sha256sum1:
22177 ID = Intrinsic::riscv_sha256sum1;
22181 case RISCV::BI__builtin_riscv_sm4ks:
22182 ID = Intrinsic::riscv_sm4ks;
22184 case RISCV::BI__builtin_riscv_sm4ed:
22185 ID = Intrinsic::riscv_sm4ed;
22189 case RISCV::BI__builtin_riscv_sm3p0:
22190 ID = Intrinsic::riscv_sm3p0;
22192 case RISCV::BI__builtin_riscv_sm3p1:
22193 ID = Intrinsic::riscv_sm3p1;
22197 case RISCV::BI__builtin_riscv_ntl_load: {
22199 unsigned DomainVal = 5;
22200 if (Ops.size() == 2)
22201 DomainVal = cast<ConstantInt>(Ops[1])->getZExtValue();
22203 llvm::MDNode *RISCVDomainNode = llvm::MDNode::get(
22205 llvm::ConstantAsMetadata::get(
Builder.getInt32(DomainVal)));
22206 llvm::MDNode *NontemporalNode = llvm::MDNode::get(
22210 if(ResTy->isScalableTy()) {
22211 const ScalableVectorType *SVTy = cast<ScalableVectorType>(ResTy);
22212 llvm::Type *ScalarTy = ResTy->getScalarType();
22213 Width = ScalarTy->getPrimitiveSizeInBits() *
22214 SVTy->getElementCount().getKnownMinValue();
22216 Width = ResTy->getPrimitiveSizeInBits();
22220 Load->setMetadata(llvm::LLVMContext::MD_nontemporal, NontemporalNode);
22221 Load->setMetadata(
CGM.
getModule().getMDKindID(
"riscv-nontemporal-domain"),
22226 case RISCV::BI__builtin_riscv_ntl_store: {
22227 unsigned DomainVal = 5;
22228 if (Ops.size() == 3)
22229 DomainVal = cast<ConstantInt>(Ops[2])->getZExtValue();
22231 llvm::MDNode *RISCVDomainNode = llvm::MDNode::get(
22233 llvm::ConstantAsMetadata::get(
Builder.getInt32(DomainVal)));
22234 llvm::MDNode *NontemporalNode = llvm::MDNode::get(
22238 Store->setMetadata(llvm::LLVMContext::MD_nontemporal, NontemporalNode);
22246#include "clang/Basic/riscv_vector_builtin_cg.inc"
22248#include "clang/Basic/riscv_sifive_vector_builtin_cg.inc"
22251 assert(ID != Intrinsic::not_intrinsic);
22254 return Builder.CreateCall(F, Ops,
"");
Defines the clang::ASTContext interface.
#define PPC_LNX_FEATURE(NAME, DESC, ENUMNAME, ENUMVAL, HWCAPN)
static constexpr SparcCPUInfo CPUInfo[]
#define X86_CPU_SUBTYPE(ENUM, STR)
#define X86_CPU_SUBTYPE_ALIAS(ENUM, ALIAS)
#define X86_VENDOR(ENUM, STRING)
#define X86_CPU_TYPE_ALIAS(ENUM, ALIAS)
#define X86_CPU_TYPE(ENUM, STR)
static constexpr Builtin::Info BuiltinInfo[]
static void Accumulate(SMap &SM, CFGBlock *B)
static Value * EmitSpecialRegisterBuiltin(CodeGenFunction &CGF, const CallExpr *E, llvm::Type *RegisterType, llvm::Type *ValueType, SpecialRegisterAccessKind AccessKind, StringRef SysReg="")
static llvm::Value * ARMMVEVectorReinterpret(CGBuilderTy &Builder, CodeGenFunction *CGF, llvm::Value *V, llvm::Type *DestType)
static Value * MakeBinaryAtomicValue(CodeGenFunction &CGF, llvm::AtomicRMWInst::BinOp Kind, const CallExpr *E, AtomicOrdering Ordering=AtomicOrdering::SequentiallyConsistent)
Utility to insert an atomic instruction based on Intrinsic::ID and the expression node.
static char bitActionToX86BTCode(BitTest::ActionKind A)
#define NEONMAP2(NameBase, LLVMIntrinsic, AltLLVMIntrinsic, TypeModifier)
static Value * EmitAtomicCmpXchg128ForMSIntrin(CodeGenFunction &CGF, const CallExpr *E, AtomicOrdering SuccessOrdering)
#define INTRINSIC_X86_XSAVE_ID(NAME)
static CanQualType getOSLogArgType(ASTContext &C, int Size)
Get the argument type for arguments to os_log_helper.
static Value * EmitOverflowCheckedAbs(CodeGenFunction &CGF, const CallExpr *E, bool SanitizeOverflow)
static llvm::VectorType * GetFloatNeonType(CodeGenFunction *CGF, NeonTypeFlags IntTypeFlags)
static Value * tryUseTestFPKind(CodeGenFunction &CGF, unsigned BuiltinID, Value *V)
static llvm::Value * MVEImmediateShr(CGBuilderTy &Builder, llvm::Value *V, uint32_t Shift, bool Unsigned)
static bool areBOSTypesCompatible(int From, int To)
Checks if using the result of __builtin_object_size(p, From) in place of __builtin_object_size(p,...
static llvm::Value * SignOrZeroExtend(CGBuilderTy &Builder, llvm::Value *V, llvm::Type *T, bool Unsigned)
static void InsertExplicitZeroOperand(CGBuilderTy &Builder, llvm::Type *Ty, SmallVectorImpl< Value * > &Ops)
static const ARMVectorIntrinsicInfo AArch64SMEIntrinsicMap[]
static Value * EmitAArch64TblBuiltinExpr(CodeGenFunction &CGF, unsigned BuiltinID, const CallExpr *E, SmallVectorImpl< Value * > &Ops, llvm::Triple::ArchType Arch)
#define MMA_VARIANTS_B1_AND(geom, type)
static void swapCommutativeSMEOperands(unsigned BuiltinID, SmallVectorImpl< Value * > &Ops)
static bool AArch64SISDIntrinsicsProvenSorted
static Value * EmitX86CompressExpand(CodeGenFunction &CGF, ArrayRef< Value * > Ops, bool IsCompress)
static const ARMVectorIntrinsicInfo AArch64SVEIntrinsicMap[]
static bool HasExtraNeonArgument(unsigned BuiltinID)
Return true if BuiltinID is an overloaded Neon intrinsic with an extra argument that specifies the ve...
static bool TypeRequiresBuiltinLaunderImp(const ASTContext &Ctx, QualType Ty, llvm::SmallPtrSetImpl< const Decl * > &Seen)
static Value * EmitAtomicIncrementValue(CodeGenFunction &CGF, const CallExpr *E, AtomicOrdering Ordering=AtomicOrdering::SequentiallyConsistent)
static std::pair< Intrinsic::ID, unsigned > getIntrinsicForHexagonNonClangBuiltin(unsigned BuiltinID)
static Value * emitRangedBuiltin(CodeGenFunction &CGF, unsigned IntrinsicID, int low, int high)
#define MMA_INTR(geom_op_type, layout)
static Value * EmitX86MaskedCompare(CodeGenFunction &CGF, unsigned CC, bool Signed, ArrayRef< Value * > Ops)
static Value * emitUnaryMaybeConstrainedFPBuiltin(CodeGenFunction &CGF, const CallExpr *E, unsigned IntrinsicID, unsigned ConstrainedIntrinsicID)
#define NEONMAP1(NameBase, LLVMIntrinsic, TypeModifier)
static bool AArch64SVEIntrinsicsProvenSorted
static RValue EmitMSVCRTSetJmp(CodeGenFunction &CGF, MSVCSetJmpKind SJKind, const CallExpr *E)
MSVC handles setjmp a bit differently on different platforms.
static const ARMVectorIntrinsicInfo * findARMVectorIntrinsicInMap(ArrayRef< ARMVectorIntrinsicInfo > IntrinsicMap, unsigned BuiltinID, bool &MapProvenSorted)
static Value * EmitScalarFMAExpr(CodeGenFunction &CGF, const CallExpr *E, MutableArrayRef< Value * > Ops, Value *Upper, bool ZeroMask=false, unsigned PTIdx=0, bool NegAcc=false)
#define MUTATE_LDBL(func)
static Value * EmitX86ExpandLoad(CodeGenFunction &CGF, ArrayRef< Value * > Ops)
static unsigned CountCountedByAttrs(const RecordDecl *RD)
static Value * emitMaybeConstrainedFPToIntRoundBuiltin(CodeGenFunction &CGF, const CallExpr *E, unsigned IntrinsicID, unsigned ConstrainedIntrinsicID)
static Value * EmitX86MaskedLoad(CodeGenFunction &CGF, ArrayRef< Value * > Ops, Align Alignment)
static bool TypeRequiresBuiltinLaunder(CodeGenModule &CGM, QualType Ty)
Determine if the specified type requires laundering by checking if it is a dynamic class type or cont...
static void InsertExplicitUndefOperand(CGBuilderTy &Builder, llvm::Type *Ty, SmallVectorImpl< Value * > &Ops)
static Value * EmitISOVolatileLoad(CodeGenFunction &CGF, const CallExpr *E)
static struct WidthAndSignedness EncompassingIntegerType(ArrayRef< struct WidthAndSignedness > Types)
static Integer GetIntegerConstantValue(const Expr *E, ASTContext &Context)
#define MMA_VARIANTS(geom, type)
static bool AArch64SMEIntrinsicsProvenSorted
static llvm::Value * VectorZip(CGBuilderTy &Builder, llvm::Value *V0, llvm::Value *V1)
static Value * EmitTargetArchBuiltinExpr(CodeGenFunction *CGF, unsigned BuiltinID, const CallExpr *E, ReturnValueSlot ReturnValue, llvm::Triple::ArchType Arch)
constexpr unsigned SVEBitsPerBlock
static std::optional< CodeGenFunction::MSVCIntrin > translateX86ToMsvcIntrin(unsigned BuiltinID)
static const std::pair< unsigned, unsigned > NEONEquivalentIntrinsicMap[]
#define NEONMAP0(NameBase)
static Value * EmitX86MaskedStore(CodeGenFunction &CGF, ArrayRef< Value * > Ops, Align Alignment)
static Value * emitBinaryMaybeConstrainedFPBuiltin(CodeGenFunction &CGF, const CallExpr *E, unsigned IntrinsicID, unsigned ConstrainedIntrinsicID)
static RValue EmitBinaryAtomicPost(CodeGenFunction &CGF, llvm::AtomicRMWInst::BinOp Kind, const CallExpr *E, Instruction::BinaryOps Op, bool Invert=false)
Utility to insert an atomic instruction based Intrinsic::ID and the expression node,...
static Value * EmitX86Muldq(CodeGenFunction &CGF, bool IsSigned, ArrayRef< Value * > Ops)
static llvm::Value * ARMMVEVectorElementReverse(CGBuilderTy &Builder, llvm::Value *V, unsigned ReverseWidth)
#define MMA_SATF_VARIANTS(geom, type)
static std::optional< CodeGenFunction::MSVCIntrin > translateAarch64ToMsvcIntrin(unsigned BuiltinID)
static std::optional< CodeGenFunction::MSVCIntrin > translateArmToMsvcIntrin(unsigned BuiltinID)
Value * emitBuiltinWithOneOverloadedType(CodeGenFunction &CGF, const CallExpr *E, unsigned IntrinsicID, llvm::StringRef Name="")
static llvm::Value * EmitBitTestIntrinsic(CodeGenFunction &CGF, unsigned BuiltinID, const CallExpr *E)
Emit a _bittest* intrinsic.
static const ARMVectorIntrinsicInfo ARMSIMDIntrinsicMap[]
static Value * EmitSignBit(CodeGenFunction &CGF, Value *V)
Emit the computation of the sign bit for a floating point value.
static Value * EmitFAbs(CodeGenFunction &CGF, Value *V)
EmitFAbs - Emit a call to @llvm.fabs().
#define CUSTOM_BUILTIN_MAPPING(x, s)
static Value * EmitX86CvtF16ToFloatExpr(CodeGenFunction &CGF, ArrayRef< Value * > Ops, llvm::Type *DstTy)
static bool isSpecialUnsignedMultiplySignedResult(unsigned BuiltinID, WidthAndSignedness Op1Info, WidthAndSignedness Op2Info, WidthAndSignedness ResultInfo)
static llvm::Value * getDefaultBuiltinObjectSizeResult(unsigned Type, llvm::IntegerType *ResType)
static llvm::Value * emitPPCLoadReserveIntrinsic(CodeGenFunction &CGF, unsigned BuiltinID, const CallExpr *E)
static llvm::Value * VectorUnzip(CGBuilderTy &Builder, llvm::Value *V, bool Odd)
static Value * EmitX86SExtMask(CodeGenFunction &CGF, Value *Op, llvm::Type *DstTy)
static Value * emitTernaryMaybeConstrainedFPBuiltin(CodeGenFunction &CGF, const CallExpr *E, unsigned IntrinsicID, unsigned ConstrainedIntrinsicID)
static WidthAndSignedness getIntegerWidthAndSignedness(const clang::ASTContext &context, const clang::QualType Type)
static Value * EmitX86FunnelShift(CodeGenFunction &CGF, Value *Op0, Value *Op1, Value *Amt, bool IsRight)
static RValue EmitCheckedMixedSignMultiply(CodeGenFunction &CGF, const clang::Expr *Op1, WidthAndSignedness Op1Info, const clang::Expr *Op2, WidthAndSignedness Op2Info, const clang::Expr *ResultArg, QualType ResultQTy, WidthAndSignedness ResultInfo)
Emit a checked mixed-sign multiply.
static llvm::ScalableVectorType * getSVEVectorForElementType(llvm::Type *EltTy)
static unsigned mutateLongDoubleBuiltin(unsigned BuiltinID)
#define INTRINSIC_WITH_CC(NAME)
static llvm::FixedVectorType * GetNeonType(CodeGenFunction *CGF, NeonTypeFlags TypeFlags, bool HasLegalHalfType=true, bool V1Ty=false, bool AllowBFloatArgsAndRet=true)
static RValue EmitBinaryAtomic(CodeGenFunction &CGF, llvm::AtomicRMWInst::BinOp Kind, const CallExpr *E)
static llvm::Value * ARMMVEConstantSplat(CGBuilderTy &Builder, llvm::Type *VT)
static Value * EmitX86MaskLogic(CodeGenFunction &CGF, Instruction::BinaryOps Opc, ArrayRef< Value * > Ops, bool InvertLHS=false)
static Value * EmitFromInt(CodeGenFunction &CGF, llvm::Value *V, QualType T, llvm::Type *ResultType)
static Value * EmitAMDGCNBallotForExec(CodeGenFunction &CGF, const CallExpr *E, llvm::Type *RegisterType, llvm::Type *ValueType, bool isExecHi)
static void initializeAlloca(CodeGenFunction &CGF, AllocaInst *AI, Value *Size, Align AlignmentInBytes)
static Value * EmitX86Select(CodeGenFunction &CGF, Value *Mask, Value *Op0, Value *Op1)
SpecialRegisterAccessKind
static Value * EmitAtomicCmpXchgForMSIntrin(CodeGenFunction &CGF, const CallExpr *E, AtomicOrdering SuccessOrdering=AtomicOrdering::SequentiallyConsistent)
This function should be invoked to emit atomic cmpxchg for Microsoft's _InterlockedCompareExchange* i...
static Address CheckAtomicAlignment(CodeGenFunction &CGF, const CallExpr *E)
static Value * EmitX86FMAExpr(CodeGenFunction &CGF, const CallExpr *E, ArrayRef< Value * > Ops, unsigned BuiltinID, bool IsAddSub)
static Value * getMaskVecValue(CodeGenFunction &CGF, Value *Mask, unsigned NumElts)
static bool isSpecialMixedSignMultiply(unsigned BuiltinID, WidthAndSignedness Op1Info, WidthAndSignedness Op2Info, WidthAndSignedness ResultInfo)
Determine if a binop is a checked mixed-sign multiply we can specialize.
static Value * MakeAtomicCmpXchgValue(CodeGenFunction &CGF, const CallExpr *E, bool ReturnBool)
Utility to insert an atomic cmpxchg instruction.
static Value * emitBinaryExpMaybeConstrainedFPBuiltin(CodeGenFunction &CGF, const CallExpr *E, llvm::Intrinsic::ID IntrinsicID, llvm::Intrinsic::ID ConstrainedIntrinsicID)
static Value * EmitToInt(CodeGenFunction &CGF, llvm::Value *V, QualType T, llvm::IntegerType *IntType)
Emit the conversions required to turn the given value into an integer of the given size.
static llvm::Value * ARMMVEVectorSplat(CGBuilderTy &Builder, llvm::Value *V)
static Value * EmitX86MaskedCompareResult(CodeGenFunction &CGF, Value *Cmp, unsigned NumElts, Value *MaskIn)
static Value * EmitX86CompressStore(CodeGenFunction &CGF, ArrayRef< Value * > Ops)
static bool NEONSIMDIntrinsicsProvenSorted
static const ARMVectorIntrinsicInfo AArch64SIMDIntrinsicMap[]
static Value * EmitNontemporalStore(CodeGenFunction &CGF, const CallExpr *E)
static llvm::Value * EmitOverflowIntrinsic(CodeGenFunction &CGF, const llvm::Intrinsic::ID IntrinsicID, llvm::Value *X, llvm::Value *Y, llvm::Value *&Carry)
Emit a call to llvm.
static Value * EmitCommonNeonSISDBuiltinExpr(CodeGenFunction &CGF, const ARMVectorIntrinsicInfo &SISDInfo, SmallVectorImpl< Value * > &Ops, const CallExpr *E)
static Value * emitFPIntBuiltin(CodeGenFunction &CGF, const CallExpr *E, unsigned IntrinsicID)
#define MMA_LDST(n, geom_op_type)
static Value * EmitX86vpcom(CodeGenFunction &CGF, ArrayRef< Value * > Ops, bool IsSigned)
static Value * emitFrexpBuiltin(CodeGenFunction &CGF, const CallExpr *E, llvm::Intrinsic::ID IntrinsicID)
@ _InterlockedExchangeAdd_rel
@ _InterlockedIncrement_acq
@ _InterlockedExchange_nf
@ _InterlockedIncrement_nf
@ _InterlockedExchange_acq
@ _InterlockedCompareExchange128_rel
@ _InterlockedCompareExchange128_acq
@ _InterlockedCompareExchange_acq
@ _InterlockedExchangeAdd_nf
@ _InterlockedCompareExchange_nf
@ _InterlockedDecrement_rel
@ _InterlockedExchangeSub
@ _InterlockedExchangeAdd_acq
@ _InterlockedIncrement_rel
@ _InterlockedCompareExchange128_nf
@ _InterlockedCompareExchange128
@ _InterlockedExchange_rel
@ _InterlockedDecrement_nf
@ _InterlockedExchangeAdd
@ _InterlockedDecrement_acq
@ _InterlockedCompareExchange_rel
static Value * EmitX86ConvertToMask(CodeGenFunction &CGF, Value *In)
static Value * EmitISOVolatileStore(CodeGenFunction &CGF, const CallExpr *E)
static Value * EmitSystemZIntrinsicWithCC(CodeGenFunction &CGF, unsigned IntrinsicID, const CallExpr *E)
Handle a SystemZ function in which the final argument is a pointer to an int that receives the post-i...
static RValue EmitHipStdParUnsupportedBuiltin(CodeGenFunction *CGF, const FunctionDecl *FD)
static llvm::Value * EmitX86BitTestIntrinsic(CodeGenFunction &CGF, BitTest BT, const CallExpr *E, Value *BitBase, Value *BitPos)
static RValue EmitCheckedUnsignedMultiplySignedResult(CodeGenFunction &CGF, const clang::Expr *Op1, WidthAndSignedness Op1Info, const clang::Expr *Op2, WidthAndSignedness Op2Info, const clang::Expr *ResultArg, QualType ResultQTy, WidthAndSignedness ResultInfo)
static Value * emitCallMaybeConstrainedFPBuiltin(CodeGenFunction &CGF, unsigned IntrinsicID, unsigned ConstrainedIntrinsicID, llvm::Type *Ty, ArrayRef< Value * > Args)
static RValue emitLibraryCall(CodeGenFunction &CGF, const FunctionDecl *FD, const CallExpr *E, llvm::Constant *calleeValue)
static Value * EmitNontemporalLoad(CodeGenFunction &CGF, const CallExpr *E)
static Value * EmitX86Ternlog(CodeGenFunction &CGF, bool ZeroMask, ArrayRef< Value * > Ops)
static llvm::AtomicOrdering getBitTestAtomicOrdering(BitTest::InterlockingKind I)
#define MMA_VARIANTS_B1_XOR(geom, type)
#define MMA_VARIANTS_I4(geom, type)
Intrinsic::ID getDotProductIntrinsic(QualType QT, int elementCount)
static Value * EmitX86ConvertIntToFp(CodeGenFunction &CGF, const CallExpr *E, ArrayRef< Value * > Ops, bool IsSigned)
static Value * packTBLDVectorList(CodeGenFunction &CGF, ArrayRef< Value * > Ops, Value *ExtOp, Value *IndexOp, llvm::Type *ResTy, unsigned IntID, const char *Name)
static Value * EmitAbs(CodeGenFunction &CGF, Value *ArgValue, bool HasNSW)
static Value * EmitX86ScalarSelect(CodeGenFunction &CGF, Value *Mask, Value *Op0, Value *Op1)
static Value * EmitAtomicDecrementValue(CodeGenFunction &CGF, const CallExpr *E, AtomicOrdering Ordering=AtomicOrdering::SequentiallyConsistent)
static bool AArch64SIMDIntrinsicsProvenSorted
static const ARMVectorIntrinsicInfo AArch64SISDIntrinsicMap[]
CodeGenFunction::ComplexPairTy ComplexPairTy
#define ALIAS(NAME, TOK, FLAGS)
llvm::MachO::Record Record
static std::string getName(const CallEvent &Call)
static std::string toString(const clang::SanitizerSet &Sanitizers)
Produce a string containing comma-separated names of sanitizers in Sanitizers set.
static QualType getPointeeType(const MemRegion *R)
Enumerates target-specific builtins in their own namespaces within namespace clang.
Defines the clang::TargetOptions class.
__DEVICE__ float modf(float __x, float *__iptr)
__DEVICE__ double nan(const char *)
__device__ __2f16 float __ockl_bool s
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
unsigned getIntWidth(QualType T) const
const ASTRecordLayout & getASTRecordLayout(const RecordDecl *D) const
Get or compute information about the layout of the specified record (struct/union/class) D,...
Builtin::Context & BuiltinInfo
QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize, const Expr *SizeExpr, ArraySizeModifier ASM, unsigned IndexTypeQuals) const
Return the unique reference to the type for a constant array of the specified element type.
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
QualType getObjCIdType() const
Represents the Objective-CC id type.
bool hasSameUnqualifiedType(QualType T1, QualType T2) const
Determine whether the given types are equivalent after cvr-qualifiers have been removed.
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
QualType GetBuiltinType(unsigned ID, GetBuiltinTypeError &Error, unsigned *IntegerConstantArgs=nullptr) const
Return the type for the specified builtin.
const TargetInfo & getTargetInfo() const
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
unsigned getTargetAddressSpace(LangAS AS) const
@ GE_Missing_type
Missing a type.
ASTRecordLayout - This class contains layout information for one RecordDecl, which is a struct/union/...
CharUnits getSize() const
getSize - Get the record size in characters.
uint64_t getFieldOffset(unsigned FieldNo) const
getFieldOffset - Get the offset of the given field index, in bits.
Represents an array type, per C99 6.7.5.2 - Array Declarators.
QualType getElementType() const
bool isLibFunction(unsigned ID) const
Return true if this is a builtin for a libc/libm function, with a "__builtin_" prefix (e....
llvm::StringRef getName(unsigned ID) const
Return the identifier name for the specified builtin, e.g.
bool isConstWithoutErrnoAndExceptions(unsigned ID) const
Return true if this function has no side effects and doesn't read memory, except for possibly errno o...
bool isConstWithoutExceptions(unsigned ID) const
bool isConst(unsigned ID) const
Return true if this function has no side effects and doesn't read memory.
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
CharUnits - This is an opaque type for sizes expressed in character units.
llvm::Align getAsAlign() const
getAsAlign - Returns Quantity as a valid llvm::Align, Beware llvm::Align assumes power of two 8-bit b...
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
static CharUnits One()
One - Construct a CharUnits quantity of one.
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
XRayInstrSet XRayInstrumentationBundle
Set of XRay instrumentation kinds to emit.
Like RawAddress, an abstract representation of an aligned address, but the pointer contained in this ...
llvm::Value * emitRawPointer(CodeGenFunction &CGF) const
Return the pointer contained in this class after authenticating it and adding offset to it if necessa...
CharUnits getAlignment() const
llvm::Type * getElementType() const
Return the type of the values stored in this address.
Address withElementType(llvm::Type *ElemTy) const
Return address with different element type, but same pointer and alignment.
Address withAlignment(CharUnits NewAlignment) const
Return address with different alignment, but same pointer and element type.
llvm::PointerType * getType() const
Return the type of the pointer value.
Address getAddress() const
A scoped helper to set the current debug location to the specified location or preferred location of ...
static ApplyDebugLocation CreateArtificial(CodeGenFunction &CGF)
Apply TemporaryLocation if it is valid.
static ApplyDebugLocation CreateEmpty(CodeGenFunction &CGF)
Set the IRBuilder to not attach debug locations.
llvm::StoreInst * CreateStore(llvm::Value *Val, Address Addr, bool IsVolatile=false)
llvm::StoreInst * CreateAlignedStore(llvm::Value *Val, llvm::Value *Addr, CharUnits Align, bool IsVolatile=false)
Address CreateGEP(CodeGenFunction &CGF, Address Addr, llvm::Value *Index, const llvm::Twine &Name="")
llvm::CallInst * CreateMemMove(Address Dest, Address Src, llvm::Value *Size, bool IsVolatile=false)
llvm::CallInst * CreateMemCpyInline(Address Dest, Address Src, uint64_t Size)
llvm::AtomicRMWInst * CreateAtomicRMW(llvm::AtomicRMWInst::BinOp Op, Address Addr, llvm::Value *Val, llvm::AtomicOrdering Ordering, llvm::SyncScope::ID SSID=llvm::SyncScope::System)
llvm::CallInst * CreateMemSetInline(Address Dest, llvm::Value *Value, uint64_t Size)
llvm::StoreInst * CreateDefaultAlignedStore(llvm::Value *Val, llvm::Value *Addr, bool IsVolatile=false)
llvm::CallInst * CreateMemSet(Address Dest, llvm::Value *Value, llvm::Value *Size, bool IsVolatile=false)
llvm::AtomicCmpXchgInst * CreateAtomicCmpXchg(Address Addr, llvm::Value *Cmp, llvm::Value *New, llvm::AtomicOrdering SuccessOrdering, llvm::AtomicOrdering FailureOrdering, llvm::SyncScope::ID SSID=llvm::SyncScope::System)
llvm::LoadInst * CreateLoad(Address Addr, const llvm::Twine &Name="")
Address CreateConstByteGEP(Address Addr, CharUnits Offset, const llvm::Twine &Name="")
Address CreateLaunderInvariantGroup(Address Addr)
llvm::CallInst * CreateMemCpy(Address Dest, Address Src, llvm::Value *Size, bool IsVolatile=false)
llvm::LoadInst * CreateAlignedLoad(llvm::Type *Ty, llvm::Value *Addr, CharUnits Align, const llvm::Twine &Name="")
Address CreateAddrSpaceCast(Address Addr, llvm::Type *Ty, llvm::Type *ElementTy, const llvm::Twine &Name="")
Address CreateConstInBoundsGEP(Address Addr, uint64_t Index, const llvm::Twine &Name="")
Given addr = T* ... produce name = getelementptr inbounds addr, i64 index where i64 is actually the t...
Address CreateInBoundsGEP(Address Addr, ArrayRef< llvm::Value * > IdxList, llvm::Type *ElementType, CharUnits Align, const Twine &Name="")
virtual std::string getDeviceSideName(const NamedDecl *ND)=0
Returns function or variable name on device side even if the current compilation is for host.
virtual llvm::GlobalVariable * getThrowInfo(QualType T)
All available information about a concrete callee.
static CGCallee forDirect(llvm::Constant *functionPtr, const CGCalleeInfo &abstractInfo=CGCalleeInfo())
llvm::DIType * getOrCreateStandaloneType(QualType Ty, SourceLocation Loc)
Emit standalone debug info for a type.
llvm::DILocation * CreateTrapFailureMessageFor(llvm::DebugLoc TrapLocation, StringRef Category, StringRef FailureMsg)
Create a debug location from TrapLocation that adds an artificial inline frame where the frame name i...
CGFunctionInfo - Class to encapsulate the information about a function definition.
virtual void EmitGCMemmoveCollectable(CodeGen::CodeGenFunction &CGF, Address DestPtr, Address SrcPtr, llvm::Value *Size)=0
EnqueuedBlockInfo emitOpenCLEnqueuedBlock(CodeGenFunction &CGF, const Expr *E)
CallArgList - Type for representing both the value and type of arguments in a call.
void add(RValue rvalue, QualType type)
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
llvm::Value * EmitAArch64BuiltinExpr(unsigned BuiltinID, const CallExpr *E, llvm::Triple::ArchType Arch)
llvm::Value * EmitFromMemory(llvm::Value *Value, QualType Ty)
EmitFromMemory - Change a scalar value from its memory representation to its value representation.
llvm::Value * EmitMSVCBuiltinExpr(MSVCIntrin BuiltinID, const CallExpr *E)
void FinishFunction(SourceLocation EndLoc=SourceLocation())
FinishFunction - Complete IR generation of the current function.
llvm::Value * EmitLifetimeStart(llvm::TypeSize Size, llvm::Value *Addr)
std::pair< RValue, llvm::Value * > EmitAtomicCompareExchange(LValue Obj, RValue Expected, RValue Desired, SourceLocation Loc, llvm::AtomicOrdering Success=llvm::AtomicOrdering::SequentiallyConsistent, llvm::AtomicOrdering Failure=llvm::AtomicOrdering::SequentiallyConsistent, bool IsWeak=false, AggValueSlot Slot=AggValueSlot::ignored())
static TypeEvaluationKind getEvaluationKind(QualType T)
getEvaluationKind - Return the TypeEvaluationKind of QualType T.
llvm::Value * EmitSVEPredicateCast(llvm::Value *Pred, llvm::ScalableVectorType *VTy)
llvm::CallInst * EmitTrapCall(llvm::Intrinsic::ID IntrID)
Emit a call to trap or debugtrap and attach function attribute "trap-func-name" if specified.
SanitizerSet SanOpts
Sanitizers enabled for this function.
RValue EmitBuiltinIsAligned(const CallExpr *E)
Emit IR for __builtin_is_aligned.
LValue EmitAggExprToLValue(const Expr *E)
EmitAggExprToLValue - Emit the computation of the specified expression of aggregate type into a tempo...
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.
llvm::Value * EmitHexagonBuiltinExpr(unsigned BuiltinID, const CallExpr *E)
void GetAArch64SVEProcessedOperands(unsigned BuiltinID, const CallExpr *E, SmallVectorImpl< llvm::Value * > &Ops, SVETypeFlags TypeFlags)
llvm::Value * EmitAMDGPUBuiltinExpr(unsigned BuiltinID, const CallExpr *E)
void EmitLifetimeEnd(llvm::Value *Size, llvm::Value *Addr)
void pushLifetimeExtendedDestroy(CleanupKind kind, Address addr, QualType type, Destroyer *destroyer, bool useEHCleanupForArray)
llvm::Value * EmitCheckedArgForBuiltin(const Expr *E, BuiltinCheckKind Kind)
Emits an argument for a call to a builtin.
llvm::Value * EmitSVEGatherLoad(const SVETypeFlags &TypeFlags, llvm::SmallVectorImpl< llvm::Value * > &Ops, unsigned IntID)
CleanupKind getARCCleanupKind()
Retrieves the default cleanup kind for an ARC cleanup.
llvm::Value * EmitRISCVCpuSupports(const CallExpr *E)
llvm::Value * EmitNVPTXBuiltinExpr(unsigned BuiltinID, const CallExpr *E)
llvm::Value * EmitHLSLBuiltinExpr(unsigned BuiltinID, const CallExpr *E)
llvm::Value * EmitAArch64SVEBuiltinExpr(unsigned BuiltinID, const CallExpr *E)
RValue emitBuiltinOSLogFormat(const CallExpr &E)
Emit IR for __builtin_os_log_format.
LValue EmitLValue(const Expr *E, KnownNonNull_t IsKnownNonNull=NotKnownNonNull)
EmitLValue - Emit code to compute a designator that specifies the location of the expression.
llvm::Value * EmitVAStartEnd(llvm::Value *ArgValue, bool IsStart)
Emits a call to an LLVM variable-argument intrinsic, either llvm.va_start or llvm....
llvm::Value * EmitSVEMaskedStore(const CallExpr *, SmallVectorImpl< llvm::Value * > &Ops, unsigned BuiltinID)
llvm::Value * EmitSVEReinterpret(llvm::Value *Val, llvm::Type *Ty)
llvm::BasicBlock * createBasicBlock(const Twine &name="", llvm::Function *parent=nullptr, llvm::BasicBlock *before=nullptr)
createBasicBlock - Create an LLVM basic block.
llvm::Value * EmitSEHExceptionInfo()
RValue EmitBuiltinAlignTo(const CallExpr *E, bool AlignUp)
Emit IR for __builtin_align_up/__builtin_align_down.
const LangOptions & getLangOpts() const
llvm::Value * EmitLoadOfCountedByField(const Expr *Base, const FieldDecl *FAMDecl, const FieldDecl *CountDecl)
Build an expression accessing the "counted_by" field.
void ProcessOrderScopeAMDGCN(llvm::Value *Order, llvm::Value *Scope, llvm::AtomicOrdering &AO, llvm::SyncScope::ID &SSID)
llvm::Constant * EmitCheckTypeDescriptor(QualType T)
Emit a description of a type in a format suitable for passing to a runtime sanitizer handler.
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false)
EmitBlock - Emit the given block.
void EmitTrapCheck(llvm::Value *Checked, SanitizerHandler CheckHandlerID)
Create a basic block that will call the trap intrinsic, and emit a conditional branch to it,...
void EmitUnreachable(SourceLocation Loc)
Emit a reached-unreachable diagnostic if Loc is valid and runtime checking is enabled.
llvm::Value * EmitSVETupleCreate(const SVETypeFlags &TypeFlags, llvm::Type *ReturnType, ArrayRef< llvm::Value * > Ops)
RValue EmitCall(const CGFunctionInfo &CallInfo, const CGCallee &Callee, ReturnValueSlot ReturnValue, const CallArgList &Args, llvm::CallBase **callOrInvoke, bool IsMustTail, SourceLocation Loc, bool IsVirtualFunctionPointerThunk=false)
EmitCall - Generate a call of the given function, expecting the given result type,...
Address makeNaturalAddressForPointer(llvm::Value *Ptr, QualType T, CharUnits Alignment=CharUnits::Zero(), bool ForPointeeType=false, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr, KnownNonNull_t IsKnownNonNull=NotKnownNonNull)
Construct an address with the natural alignment of T.
ComplexPairTy EmitComplexExpr(const Expr *E, bool IgnoreReal=false, bool IgnoreImag=false)
EmitComplexExpr - Emit the computation of the specified expression of complex type,...
void EmitAnyExprToMem(const Expr *E, Address Location, Qualifiers Quals, bool IsInitializer)
EmitAnyExprToMem - Emits the code necessary to evaluate an arbitrary expression into the given memory...
TypeCheckKind
Situations in which we might emit a check for the suitability of a pointer or glvalue.
@ TCK_Store
Checking the destination of a store. Must be suitably sized and aligned.
@ TCK_Load
Checking the operand of a load. Must be suitably sized and aligned.
llvm::Value * EmitSMELdrStr(const SVETypeFlags &TypeFlags, llvm::SmallVectorImpl< llvm::Value * > &Ops, unsigned IntID)
llvm::Value * FormSVEBuiltinResult(llvm::Value *Call)
FormSVEBuiltinResult - Returns the struct of scalable vectors as a wider vector.
llvm::Value * EmitNeonSplat(llvm::Value *V, llvm::Constant *Idx, const llvm::ElementCount &Count)
llvm::Type * ConvertTypeForMem(QualType T)
llvm::Value * EmitSVEMaskedLoad(const CallExpr *, llvm::Type *ReturnTy, SmallVectorImpl< llvm::Value * > &Ops, unsigned BuiltinID, bool IsZExtReturn)
bool AlwaysEmitXRayCustomEvents() const
AlwaysEmitXRayCustomEvents - Return true if we must unconditionally emit XRay custom event handling c...
llvm::Value * EmitSVEDupX(llvm::Value *Scalar)
RawAddress CreateMemTemp(QualType T, const Twine &Name="tmp", RawAddress *Alloca=nullptr)
CreateMemTemp - Create a temporary memory object of the given type, with appropriate alignmen and cas...
@ Default
! No language constraints on evaluation order.
const TargetInfo & getTarget() const
llvm::Value * vectorWrapScalar16(llvm::Value *Op)
llvm::Function * LookupNeonLLVMIntrinsic(unsigned IntrinsicID, unsigned Modifier, llvm::Type *ArgTy, const CallExpr *E)
llvm::Value * getTypeSize(QualType Ty)
Returns calculated size of the specified type.
llvm::Value * EmitSEHExceptionCode()
Address EmitPointerWithAlignment(const Expr *Addr, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr, KnownNonNull_t IsKnownNonNull=NotKnownNonNull)
EmitPointerWithAlignment - Given an expression with a pointer type, emit the value and compute our be...
llvm::Value * EmitTargetBuiltinExpr(unsigned BuiltinID, const CallExpr *E, ReturnValueSlot ReturnValue)
EmitTargetBuiltinExpr - Emit the given builtin call.
RValue EmitAnyExprToTemp(const Expr *E)
EmitAnyExprToTemp - Similarly to EmitAnyExpr(), however, the result will always be accessible even if...
RValue EmitCoroutineIntrinsic(const CallExpr *E, unsigned int IID)
llvm::Value * EmitAArch64SMEBuiltinExpr(unsigned BuiltinID, const CallExpr *E)
RValue EmitAMDGPUDevicePrintfCallExpr(const CallExpr *E)
Address EmitArrayToPointerDecay(const Expr *Array, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr)
void EmitCheck(ArrayRef< std::pair< llvm::Value *, SanitizerMask > > Checked, SanitizerHandler Check, ArrayRef< llvm::Constant * > StaticArgs, ArrayRef< llvm::Value * > DynamicArgs)
Create a basic block that will either trap or call a handler function in the UBSan runtime with the p...
RValue EmitBuiltinNewDeleteCall(const FunctionProtoType *Type, const CallExpr *TheCallExpr, bool IsDelete)
llvm::Value * EmitRISCVCpuInit()
llvm::Value * EmitSVETupleSetOrGet(const SVETypeFlags &TypeFlags, llvm::Type *ReturnType, ArrayRef< llvm::Value * > Ops)
RValue EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, const CallExpr *E, ReturnValueSlot ReturnValue)
llvm::Value * EmitSVEPrefetchLoad(const SVETypeFlags &TypeFlags, SmallVectorImpl< llvm::Value * > &Ops, unsigned BuiltinID)
llvm::Value * EmitAArch64CompareBuiltinExpr(llvm::Value *Op, llvm::Type *Ty, const llvm::CmpInst::Predicate Fp, const llvm::CmpInst::Predicate Ip, const llvm::Twine &Name="")
void StartFunction(GlobalDecl GD, QualType RetTy, llvm::Function *Fn, const CGFunctionInfo &FnInfo, const FunctionArgList &Args, SourceLocation Loc=SourceLocation(), SourceLocation StartLoc=SourceLocation())
Emit code for the start of a function.
AggValueSlot CreateAggTemp(QualType T, const Twine &Name="tmp", RawAddress *Alloca=nullptr)
CreateAggTemp - Create a temporary memory object for the given aggregate type.
llvm::ScalableVectorType * getSVEType(const SVETypeFlags &TypeFlags)
RValue emitRotate(const CallExpr *E, bool IsRotateRight)
llvm::Constant * EmitCheckSourceLocation(SourceLocation Loc)
Emit a description of a source location in a format suitable for passing to a runtime sanitizer handl...
void ErrorUnsupported(const Stmt *S, const char *Type)
ErrorUnsupported - Print out an error that codegen doesn't support the specified stmt yet.
CGDebugInfo * getDebugInfo()
const FieldDecl * FindFlexibleArrayMemberFieldAndOffset(ASTContext &Ctx, const RecordDecl *RD, const FieldDecl *FAMDecl, uint64_t &Offset)
Address EmitVAListRef(const Expr *E)
llvm::Value * EmitNeonShiftVector(llvm::Value *V, llvm::Type *Ty, bool negateForRightShift)
llvm::Value * EmitSVEMovl(const SVETypeFlags &TypeFlags, llvm::ArrayRef< llvm::Value * > Ops, unsigned BuiltinID)
void emitAlignmentAssumption(llvm::Value *PtrValue, QualType Ty, SourceLocation Loc, SourceLocation AssumptionLoc, llvm::Value *Alignment, llvm::Value *OffsetValue=nullptr)
const TargetCodeGenInfo & getTargetHooks() const
llvm::Value * EmitARMBuiltinExpr(unsigned BuiltinID, const CallExpr *E, ReturnValueSlot ReturnValue, llvm::Triple::ArchType Arch)
llvm::Type * getEltType(const SVETypeFlags &TypeFlags)
void EmitAggExpr(const Expr *E, AggValueSlot AS)
EmitAggExpr - Emit the computation of the specified expression of aggregate type.
bool ShouldXRayInstrumentFunction() const
ShouldXRayInstrument - Return true if the current function should be instrumented with XRay nop sleds...
llvm::Value * EmitSVEPMull(const SVETypeFlags &TypeFlags, llvm::SmallVectorImpl< llvm::Value * > &Ops, unsigned BuiltinID)
llvm::Value * EmitToMemory(llvm::Value *Value, QualType Ty)
EmitToMemory - Change a scalar value from its value representation to its in-memory representation.
bool IsInPreservedAIRegion
True if CodeGen currently emits code inside presereved access index region.
llvm::Value * EmitARCRetain(QualType type, llvm::Value *value)
bool AlwaysEmitXRayTypedEvents() const
AlwaysEmitXRayTypedEvents - Return true if clang must unconditionally emit XRay typed event handling ...
void SetSqrtFPAccuracy(llvm::Value *Val)
Set the minimum required accuracy of the given sqrt operation based on CodeGenOpts.
llvm::Value * EmitSVEScatterStore(const SVETypeFlags &TypeFlags, llvm::SmallVectorImpl< llvm::Value * > &Ops, unsigned IntID)
llvm::CallInst * EmitNounwindRuntimeCall(llvm::FunctionCallee callee, const Twine &name="")
ASTContext & getContext() const
llvm::Function * generateBuiltinOSLogHelperFunction(const analyze_os_log::OSLogBufferLayout &Layout, CharUnits BufferAlignment)
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...
CGCallee EmitCallee(const Expr *E)
const Decl * CurFuncDecl
CurFuncDecl - Holds the Decl for the current outermost non-closure context.
llvm::Value * EmitScalarOrConstFoldImmArg(unsigned ICEArguments, unsigned Idx, const CallExpr *E)
void checkTargetFeatures(const CallExpr *E, const FunctionDecl *TargetDecl)
llvm::Value * BuildVector(ArrayRef< llvm::Value * > Ops)
llvm::Value * EmitWebAssemblyBuiltinExpr(unsigned BuiltinID, const CallExpr *E)
llvm::Value * EmitARMCDEBuiltinExpr(unsigned BuiltinID, const CallExpr *E, ReturnValueSlot ReturnValue, llvm::Triple::ArchType Arch)
llvm::CallInst * EmitRuntimeCall(llvm::FunctionCallee callee, const Twine &name="")
llvm::Type * ConvertType(QualType T)
llvm::CallBase * EmitRuntimeCallOrInvoke(llvm::FunctionCallee callee, ArrayRef< llvm::Value * > args, const Twine &name="")
llvm::Value * EmitSystemZBuiltinExpr(unsigned BuiltinID, const CallExpr *E)
llvm::Value * EmitSMEReadWrite(const SVETypeFlags &TypeFlags, llvm::SmallVectorImpl< llvm::Value * > &Ops, unsigned IntID)
void EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc, LValue LV, QualType Type, SanitizerSet SkippedChecks=SanitizerSet(), llvm::Value *ArraySize=nullptr)
llvm::Value * EmitSMELd1St1(const SVETypeFlags &TypeFlags, llvm::SmallVectorImpl< llvm::Value * > &Ops, unsigned IntID)
llvm::Value * EmitPPCBuiltinExpr(unsigned BuiltinID, const CallExpr *E)
static Destroyer destroyARCStrongPrecise
void EmitARCIntrinsicUse(ArrayRef< llvm::Value * > values)
RValue EmitNVPTXDevicePrintfCallExpr(const CallExpr *E)
llvm::Value * EmitSVEStructLoad(const SVETypeFlags &TypeFlags, SmallVectorImpl< llvm::Value * > &Ops, unsigned IntID)
Address EmitMSVAListRef(const Expr *E)
Emit a "reference" to a __builtin_ms_va_list; this is always the value of the expression,...
llvm::Value * EmitCheckedInBoundsGEP(llvm::Type *ElemTy, llvm::Value *Ptr, ArrayRef< llvm::Value * > IdxList, bool SignedIndices, bool IsSubtraction, SourceLocation Loc, const Twine &Name="")
Same as IRBuilder::CreateInBoundsGEP, but additionally emits a check to detect undefined behavior whe...
llvm::Value * EmitNeonRShiftImm(llvm::Value *Vec, llvm::Value *Amt, llvm::Type *Ty, bool usgn, const char *name)
SmallVector< llvm::Type *, 2 > getSVEOverloadTypes(const SVETypeFlags &TypeFlags, llvm::Type *ReturnType, ArrayRef< llvm::Value * > Ops)
static bool hasAggregateEvaluationKind(QualType T)
LValue MakeAddrLValue(Address Addr, QualType T, AlignmentSource Source=AlignmentSource::Type)
llvm::Value * EmitARMMVEBuiltinExpr(unsigned BuiltinID, const CallExpr *E, ReturnValueSlot ReturnValue, llvm::Triple::ArchType Arch)
LValue MakeNaturalAlignAddrLValue(llvm::Value *V, QualType T, KnownNonNull_t IsKnownNonNull=NotKnownNonNull)
llvm::Value * EmitSVEStructStore(const SVETypeFlags &TypeFlags, SmallVectorImpl< llvm::Value * > &Ops, unsigned IntID)
Address GetAddrOfLocalVar(const VarDecl *VD)
GetAddrOfLocalVar - Return the address of a local variable.
llvm::Value * EmitSEHAbnormalTermination()
llvm::Value * EmitX86BuiltinExpr(unsigned BuiltinID, const CallExpr *E)
Address ReturnValue
ReturnValue - The temporary alloca to hold the return value.
llvm::Value * EmitSVEAllTruePred(const SVETypeFlags &TypeFlags)
RValue GetUndefRValue(QualType Ty)
GetUndefRValue - Get an appropriate 'undef' rvalue for the given type.
llvm::Type * SVEBuiltinMemEltTy(const SVETypeFlags &TypeFlags)
SVEBuiltinMemEltTy - Returns the memory element type for this memory access builtin.
llvm::LLVMContext & getLLVMContext()
llvm::Value * EmitScalarExpr(const Expr *E, bool IgnoreResultAssign=false)
EmitScalarExpr - Emit the computation of the specified expression of LLVM scalar type,...
void AddAMDGPUFenceAddressSpaceMMRA(llvm::Instruction *Inst, const CallExpr *E)
llvm::Value * EmitSMEZero(const SVETypeFlags &TypeFlags, llvm::SmallVectorImpl< llvm::Value * > &Ops, unsigned IntID)
llvm::Value * EmitRISCVBuiltinExpr(unsigned BuiltinID, const CallExpr *E, ReturnValueSlot ReturnValue)
llvm::Value * EmitCommonNeonBuiltinExpr(unsigned BuiltinID, unsigned LLVMIntrinsic, unsigned AltLLVMIntrinsic, const char *NameHint, unsigned Modifier, const CallExpr *E, SmallVectorImpl< llvm::Value * > &Ops, Address PtrOp0, Address PtrOp1, llvm::Triple::ArchType Arch)
llvm::Value * EmitNeonCall(llvm::Function *F, SmallVectorImpl< llvm::Value * > &O, const char *name, unsigned shift=0, bool rightshift=false)
llvm::Value * EmitAnnotationCall(llvm::Function *AnnotationFn, llvm::Value *AnnotatedVal, StringRef AnnotationStr, SourceLocation Location, const AnnotateAttr *Attr)
Emit an annotation call (intrinsic).
llvm::ScalableVectorType * getSVEPredType(const SVETypeFlags &TypeFlags)
llvm::Value * EmitSVEGatherPrefetch(const SVETypeFlags &TypeFlags, SmallVectorImpl< llvm::Value * > &Ops, unsigned IntID)
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...
llvm::Value * EmitBPFBuiltinExpr(unsigned BuiltinID, const CallExpr *E)
This class organizes the cross-function state that is used while generating LLVM code.
CGHLSLRuntime & getHLSLRuntime()
Return a reference to the configured HLSL runtime.
llvm::Module & getModule() const
llvm::FunctionCallee CreateRuntimeFunction(llvm::FunctionType *Ty, StringRef Name, llvm::AttributeList ExtraAttrs=llvm::AttributeList(), bool Local=false, bool AssumeConvergent=false)
Create or return a runtime function declaration with the specified type and name.
llvm::Constant * getRawFunctionPointer(GlobalDecl GD, llvm::Type *Ty=nullptr)
Return a function pointer for a reference to the given function.
llvm::Constant * getBuiltinLibFunction(const FunctionDecl *FD, unsigned BuiltinID)
Given a builtin id for a function like "__builtin_fabsf", return a Function* for "fabsf".
DiagnosticsEngine & getDiags() const
void ErrorUnsupported(const Stmt *S, const char *Type)
Print out an error that codegen doesn't support the specified stmt yet.
const LangOptions & getLangOpts() const
CGCUDARuntime & getCUDARuntime()
Return a reference to the configured CUDA runtime.
CodeGenTypes & getTypes()
CGOpenCLRuntime & getOpenCLRuntime()
Return a reference to the configured OpenCL runtime.
const TargetInfo & getTarget() const
const llvm::DataLayout & getDataLayout() const
void Error(SourceLocation loc, StringRef error)
Emit a general error that something can't be done.
CGCXXABI & getCXXABI() const
llvm::Constant * GetFunctionStart(const ValueDecl *Decl)
const llvm::Triple & getTriple() const
void DecorateInstructionWithTBAA(llvm::Instruction *Inst, TBAAAccessInfo TBAAInfo)
DecorateInstructionWithTBAA - Decorate the instruction with a TBAA tag.
llvm::Constant * CreateRuntimeVariable(llvm::Type *Ty, StringRef Name)
Create a new runtime global variable with the specified type and name.
TBAAAccessInfo getTBAAAccessInfo(QualType AccessType)
getTBAAAccessInfo - Get TBAA information that describes an access to an object of the given type.
ASTContext & getContext() const
const CodeGenOptions & getCodeGenOpts() const
StringRef getMangledName(GlobalDecl GD)
CharUnits getNaturalPointeeTypeAlignment(QualType T, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr)
llvm::LLVMContext & getLLVMContext()
CGObjCRuntime & getObjCRuntime()
Return a reference to the configured Objective-C runtime.
void SetLLVMFunctionAttributes(GlobalDecl GD, const CGFunctionInfo &Info, llvm::Function *F, bool IsThunk)
Set the LLVM function attributes (sext, zext, etc).
void SetLLVMFunctionAttributesForDefinition(const Decl *D, llvm::Function *F)
Set the LLVM function attributes which only apply to a function definition.
llvm::Function * getIntrinsic(unsigned IID, ArrayRef< llvm::Type * > Tys=std::nullopt)
ConstantAddress GetAddrOfConstantCString(const std::string &Str, const char *GlobalName=nullptr)
Returns a pointer to a character array containing the literal and a terminating '\0' character.
llvm::Type * ConvertType(QualType T)
ConvertType - Convert type T into a llvm::Type.
llvm::FunctionType * GetFunctionType(const CGFunctionInfo &Info)
GetFunctionType - Get the LLVM function type for.
const CGFunctionInfo & arrangeBuiltinFunctionDeclaration(QualType resultType, const FunctionArgList &args)
A builtin function is a freestanding function using the default C conventions.
const CGFunctionInfo & arrangeBuiltinFunctionCall(QualType resultType, const CallArgList &args)
llvm::Constant * emitAbstract(const Expr *E, QualType T)
Emit the result of the given expression as an abstract constant, asserting that it succeeded.
Information for lazily generating a cleanup.
FunctionArgList - Type for representing both the decl and type of parameters to a function.
LValue - This represents an lvalue references.
llvm::Value * getRawBitFieldPointer(CodeGenFunction &CGF) const
llvm::Value * getPointer(CodeGenFunction &CGF) const
Address getAddress() const
void setNontemporal(bool Value)
llvm::Value * emitRawPointer(CodeGenFunction &CGF) const
RValue - This trivial value class is used to represent the result of an expression that is evaluated.
static RValue getIgnored()
static RValue get(llvm::Value *V)
static RValue getAggregate(Address addr, bool isVolatile=false)
Convert an Address to an RValue.
static RValue getComplex(llvm::Value *V1, llvm::Value *V2)
llvm::Value * getScalarVal() const
getScalarVal() - Return the Value* of this scalar value.
An abstract representation of an aligned address.
llvm::Value * getPointer() const
static RawAddress invalid()
ReturnValueSlot - Contains the address where the return value of a function can be stored,...
virtual llvm::Value * encodeReturnAddress(CodeGen::CodeGenFunction &CGF, llvm::Value *Address) const
Performs the code-generation required to convert the address of an instruction into a return address ...
virtual llvm::Value * decodeReturnAddress(CodeGen::CodeGenFunction &CGF, llvm::Value *Address) const
Performs the code-generation required to convert a return address as stored by the system into the ac...
const T & getABIInfo() const
virtual int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const
Determines the DWARF register number for the stack pointer, for exception-handling purposes.
virtual llvm::Value * testFPKind(llvm::Value *V, unsigned BuiltinID, CGBuilderTy &Builder, CodeGenModule &CGM) const
Performs a target specific test of a floating point value for things like IsNaN, Infinity,...
Complex values, per C99 6.2.5p11.
Represents a concrete matrix type with constant number of rows and columns.
RecordDecl * getOuterLexicalRecordContext()
Retrieve the outermost lexically enclosing record context.
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
FunctionDecl * getAsFunction() LLVM_READONLY
Returns the function itself, or the templated function if this is a function template.
DeclContext * getDeclContext()
static bool isFlexibleArrayMemberLike(ASTContext &Context, const Decl *D, QualType Ty, LangOptions::StrictFlexArraysLevelKind StrictFlexArraysLevel, bool IgnoreTemplateOrMacroSubstitution)
Whether it resembles a flexible array member.
Concrete class used by the front-end to report problems and issues.
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
This represents one expression.
bool EvaluateAsInt(EvalResult &Result, const ASTContext &Ctx, SideEffectsKind AllowSideEffects=SE_NoSideEffects, bool InConstantContext=false) const
EvaluateAsInt - Return true if this is a constant which we can fold and convert to an integer,...
Expr * IgnoreParenCasts() LLVM_READONLY
Skip past any parentheses and casts which might surround this expression until reaching a fixed point...
llvm::APSInt EvaluateKnownConstInt(const ASTContext &Ctx, SmallVectorImpl< PartialDiagnosticAt > *Diag=nullptr) const
EvaluateKnownConstInt - Call EvaluateAsRValue and return the folded integer.
Expr * IgnoreParenImpCasts() LLVM_READONLY
Skip past any parentheses and implicit casts which might surround this expression until reaching a fi...
bool EvaluateAsFloat(llvm::APFloat &Result, const ASTContext &Ctx, SideEffectsKind AllowSideEffects=SE_NoSideEffects, bool InConstantContext=false) const
EvaluateAsFloat - Return true if this is a constant which we can fold and convert to a floating point...
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
@ NPC_ValueDependentIsNotNull
Specifies that a value-dependent expression should be considered to never be a null pointer constant.
ExprObjectKind getObjectKind() const
getObjectKind - The object kind that this expression produces.
bool EvaluateAsRValue(EvalResult &Result, const ASTContext &Ctx, bool InConstantContext=false) const
EvaluateAsRValue - Return true if this is a constant which we can fold to an rvalue using any crazy t...
bool HasSideEffects(const ASTContext &Ctx, bool IncludePossibleEffects=true) const
HasSideEffects - This routine returns true for all those expressions which have any effect other than...
std::optional< std::string > tryEvaluateString(ASTContext &Ctx) const
If the current Expr can be evaluated to a pointer to a null-terminated constant string,...
Expr * IgnoreImpCasts() LLVM_READONLY
Skip past any implicit casts which might surround this expression until reaching a fixed point.
NullPointerConstantKind isNullPointerConstant(ASTContext &Ctx, NullPointerConstantValueDependence NPC) const
isNullPointerConstant - C99 6.3.2.3p3 - Test if this reduces down to a Null pointer constant.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
std::optional< llvm::APSInt > getIntegerConstantExpr(const ASTContext &Ctx, SourceLocation *Loc=nullptr) const
isIntegerConstantExpr - Return the value if this expression is a valid integer constant expression.
bool tryEvaluateObjectSize(uint64_t &Result, ASTContext &Ctx, unsigned Type) const
If the current Expr is a pointer, this will try to statically determine the number of bytes available...
const ValueDecl * getAsBuiltinConstantDeclRef(const ASTContext &Context) const
If this expression is an unambiguous reference to a single declaration, in the style of __builtin_fun...
Represents difference between two FPOptions values.
Represents a member of a struct/union/class.
const FieldDecl * findCountedByField() const
Find the FieldDecl specified in a FAM's "counted_by" attribute.
Represents a function declaration or definition.
const ParmVarDecl * getParamDecl(unsigned i) const
unsigned getBuiltinID(bool ConsiderWrapperFunctions=false) const
Returns a value indicating whether this function corresponds to a builtin function.
Represents a prototype with parameter type info, e.g.
GlobalDecl - represents a global declaration.
const Decl * getDecl() const
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
static ImplicitParamDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, ImplicitParamKind ParamKind)
Create implicit parameter.
StrictFlexArraysLevelKind
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
std::string getNameAsString() const
Get a human-readable name for the declaration, even if it is one of the special kinds of names (C++ c...
Flags to identify the types for overloaded Neon builtins.
EltType getEltType() const
PointerType - C99 6.7.5.1 - Pointer Declarators.
QualType getPointeeType() const
A (possibly-)qualified type.
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
bool isWebAssemblyFuncrefType() const
Returns true if it is a WebAssembly Funcref Type.
LangAS getAddressSpace() const
Return the address space of this type.
bool isWebAssemblyExternrefType() const
Returns true if it is a WebAssembly Externref Type.
The collection of all-type qualifiers we support.
Represents a struct/union/class.
field_range fields() const
Flags to identify the types for overloaded SVE builtins.
bool isZExtReturn() const
bool isReverseUSDOT() const
bool isOverloadNone() const
MemEltType getMemEltType() const
bool isGatherLoad() const
bool isOverloadCvt() const
EltType getEltType() const
bool isOverloadDefault() const
bool isOverloadWhileRW() const
bool isReverseMergeAnyAccOp() const
bool isReductionQV() const
bool isInsertOp1SVALL() const
bool isAppendSVALL() const
bool isReverseMergeAnyBinOp() const
bool isStructStore() const
bool isTupleCreate() const
bool isGatherPrefetch() const
bool hasSplatOperand() const
MergeType getMergeType() const
bool isByteIndexed() const
bool isStructLoad() const
bool isOverloadWhileOrMultiVecCvt() const
unsigned getSplatOperand() const
bool isScatterStore() const
bool isReverseCompare() const
Scope - A scope is a transient data structure that is used while parsing the program.
Encodes a location in the source.
SourceLocation getBeginLoc() const LLVM_READONLY
Exposes information about the current target.
TargetOptions & getTargetOpts() const
Retrieve the target options.
virtual bool hasLegalHalfType() const
Determine whether _Float16 is supported on this target.
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
bool isLittleEndian() const
unsigned getMaxOpenCLWorkGroupSize() const
virtual bool checkArithmeticFenceSupported() const
Controls if __arithmetic_fence is supported in the targeted backend.
unsigned getSuitableAlign() const
Return the alignment that is the largest alignment ever used for any scalar/SIMD data type on the tar...
virtual std::string_view getClobbers() const =0
Returns a string of target-specific clobbers, in LLVM format.
llvm::CodeObjectVersionKind CodeObjectVersion
Code object version for AMDGPU.
The base class of the type hierarchy.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
bool isBlockPointerType() const
bool isSignedIntegerType() const
Return true if this is an integer type that is signed, according to C99 6.2.5p4 [char,...
bool isComplexType() const
isComplexType() does not include complex integers (a GCC extension).
bool isCountAttributedType() const
bool isPointerType() const
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
const T * castAs() const
Member-template castAs<specific type>.
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
bool hasUnsignedIntegerRepresentation() const
Determine whether this type has an unsigned integer representation of some sort, e....
bool hasSignedIntegerRepresentation() const
Determine whether this type has an signed integer representation of some sort, e.g....
bool isObjCObjectPointerType() const
bool hasFloatingRepresentation() const
Determine whether this type has a floating-point representation of some sort, e.g....
bool isVectorType() const
bool isFloatingType() const
bool isUnsignedIntegerType() const
Return true if this is an integer type that is unsigned, according to C99 6.2.5p6 [which returns true...
const T * getAs() const
Member-template getAs<specific type>'.
bool isRecordType() const
bool isSizelessVectorType() const
Returns true for all scalable vector types.
QualType getSizelessVectorEltType(const ASTContext &Ctx) const
Returns the representative type for the element of a sizeless vector builtin type.
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Represents a GCC generic vector type.
unsigned getNumElements() const
SmallVector< OSLogBufferItem, 4 > Items
unsigned char getNumArgsByte() const
unsigned char getSummaryByte() const
Defines the clang::TargetInfo interface.
@ Type
The l-value was considered opaque, so the alignment was determined from a type.
llvm::Constant * initializationPatternFor(CodeGenModule &, llvm::Type *)
TypeEvaluationKind
The kind of evaluation to perform on values of a particular type.
@ EHCleanup
Denotes a cleanup that should run when a scope is exited using exceptional control flow (a throw stat...
constexpr XRayInstrMask Typed
constexpr XRayInstrMask Custom
bool computeOSLogBufferLayout(clang::ASTContext &Ctx, const clang::CallExpr *E, OSLogBufferLayout &layout)
const void * Store
Store - This opaque type encapsulates an immutable mapping from locations to values.
bool Dup(InterpState &S, CodePtr OpPC)
bool Ret(InterpState &S, CodePtr &PC, APValue &Result)
bool Zero(InterpState &S, CodePtr OpPC)
bool Mul(InterpState &S, CodePtr OpPC)
bool Neg(InterpState &S, CodePtr OpPC)
bool Load(InterpState &S, CodePtr OpPC)
bool Cast(InterpState &S, CodePtr OpPC)
The JSON file list parser is used to communicate input to InstallAPI.
@ Vector
'vector' clause, allowed on 'loop', Combined, and 'routine' directives.
@ DType
'dtype' clause, an alias for 'device_type', stored separately for diagnostic purposes.
@ OK_BitField
A bitfield object is a bitfield on a C or C++ record.
bool operator<(DeclarationName LHS, DeclarationName RHS)
Ordering on two declaration names.
@ Asm
Assembly: we accept this only so that we can preprocess it.
@ Result
The result type of a method or function.
LangAS
Defines the address space values used by the address space qualifier of QualType.
const FunctionProtoType * T
@ Success
Template argument deduction was successful.
@ Other
Other implicit parameter.
Diagnostic wrappers for TextAPI types for error reporting.
llvm::PointerType * VoidPtrTy
llvm::IntegerType * Int64Ty
llvm::PointerType * ConstGlobalsPtrTy
void* in the address space for constant globals
CharUnits getIntAlign() const
llvm::IntegerType * Int8Ty
i8, i16, i32, and i64
llvm::Type * HalfTy
half, bfloat, float, double
llvm::IntegerType * SizeTy
llvm::IntegerType * Int32Ty
llvm::IntegerType * IntPtrTy
llvm::IntegerType * IntTy
int
llvm::IntegerType * Int16Ty
llvm::PointerType * Int8PtrTy
llvm::PointerType * UnqualPtrTy
llvm::PointerType * AllocaInt8PtrTy
LangAS getASTAllocaAddressSpace() const
EvalResult is a struct with detailed info about an evaluated expression.
APValue Val
Val - This is the value the expression can be folded to.
void clear(SanitizerMask K=SanitizerKind::All)
Disable the sanitizers specified in K.
void set(SanitizerMask K, bool Value)
Enable or disable a certain (single) sanitizer.
bool has(SanitizerMask K) const
Check if a certain (single) sanitizer is enabled.
bool has(XRayInstrMask K) const
#define scalbln(__x, __y)
#define copysign(__x, __y)
#define remquo(__x, __y, __z)
#define nextafter(__x, __y)
#define nexttoward(__x, __y)
#define remainder(__x, __y)
#define fma(__x, __y, __z)