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))
14447 llvm::Type *Int32Ty = Builder.getInt32Ty();
14448 llvm::Type *Int64Ty = Builder.getInt64Ty();
14449 llvm::ArrayType *ArrayOfInt64Ty =
14450 llvm::ArrayType::get(Int64Ty, llvm::RISCVISAInfo::FeatureBitSize);
14451 llvm::Type *StructTy = llvm::StructType::get(Int32Ty, ArrayOfInt64Ty);
14452 llvm::Constant *RISCVFeaturesBits =
14454 cast<llvm::GlobalValue>(RISCVFeaturesBits)->setDSOLocal(
true);
14455 Value *IndexVal = llvm::ConstantInt::get(Int32Ty, Index);
14456 llvm::Value *GEPIndices[] = {Builder.getInt32(0), Builder.getInt32(1),
14459 Builder.CreateInBoundsGEP(StructTy, RISCVFeaturesBits, GEPIndices);
14460 Value *FeaturesBit =
14462 return FeaturesBit;
14466 const unsigned RISCVFeatureLength = llvm::RISCVISAInfo::FeatureBitSize;
14467 uint64_t RequireBitMasks[RISCVFeatureLength] = {0};
14469 for (
auto Feat : FeaturesStrs) {
14470 auto [GroupID, BitPos] = RISCVISAInfo::getRISCVFeaturesBitsInfo(Feat);
14477 RequireBitMasks[GroupID] |= (1ULL << BitPos);
14481 for (
unsigned Idx = 0; Idx < RISCVFeatureLength; Idx++) {
14482 if (RequireBitMasks[Idx] == 0)
14492 assert(
Result &&
"Should have value here.");
14499 if (BuiltinID == Builtin::BI__builtin_cpu_is)
14500 return EmitX86CpuIs(
E);
14501 if (BuiltinID == Builtin::BI__builtin_cpu_supports)
14502 return EmitX86CpuSupports(
E);
14503 if (BuiltinID == Builtin::BI__builtin_cpu_init)
14504 return EmitX86CpuInit();
14512 bool IsMaskFCmp =
false;
14513 bool IsConjFMA =
false;
14516 unsigned ICEArguments = 0;
14521 for (
unsigned i = 0, e =
E->getNumArgs(); i != e; i++) {
14531 auto getCmpIntrinsicCall = [
this, &Ops](Intrinsic::ID
ID,
unsigned Imm) {
14532 Ops.push_back(llvm::ConstantInt::get(
Int8Ty, Imm));
14534 return Builder.CreateCall(F, Ops);
14542 auto getVectorFCmpIR = [
this, &Ops,
E](CmpInst::Predicate Pred,
14543 bool IsSignaling) {
14544 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*
this,
E);
14547 Cmp =
Builder.CreateFCmpS(Pred, Ops[0], Ops[1]);
14549 Cmp =
Builder.CreateFCmp(Pred, Ops[0], Ops[1]);
14550 llvm::VectorType *FPVecTy = cast<llvm::VectorType>(Ops[0]->getType());
14551 llvm::VectorType *IntVecTy = llvm::VectorType::getInteger(FPVecTy);
14553 return Builder.CreateBitCast(Sext, FPVecTy);
14556 switch (BuiltinID) {
14557 default:
return nullptr;
14558 case X86::BI_mm_prefetch: {
14560 ConstantInt *
C = cast<ConstantInt>(Ops[1]);
14561 Value *RW = ConstantInt::get(
Int32Ty, (
C->getZExtValue() >> 2) & 0x1);
14562 Value *Locality = ConstantInt::get(
Int32Ty,
C->getZExtValue() & 0x3);
14567 case X86::BI_mm_clflush: {
14571 case X86::BI_mm_lfence: {
14574 case X86::BI_mm_mfence: {
14577 case X86::BI_mm_sfence: {
14580 case X86::BI_mm_pause: {
14583 case X86::BI__rdtsc: {
14586 case X86::BI__builtin_ia32_rdtscp: {
14592 case X86::BI__builtin_ia32_lzcnt_u16:
14593 case X86::BI__builtin_ia32_lzcnt_u32:
14594 case X86::BI__builtin_ia32_lzcnt_u64: {
14598 case X86::BI__builtin_ia32_tzcnt_u16:
14599 case X86::BI__builtin_ia32_tzcnt_u32:
14600 case X86::BI__builtin_ia32_tzcnt_u64: {
14604 case X86::BI__builtin_ia32_undef128:
14605 case X86::BI__builtin_ia32_undef256:
14606 case X86::BI__builtin_ia32_undef512:
14613 case X86::BI__builtin_ia32_vec_ext_v4hi:
14614 case X86::BI__builtin_ia32_vec_ext_v16qi:
14615 case X86::BI__builtin_ia32_vec_ext_v8hi:
14616 case X86::BI__builtin_ia32_vec_ext_v4si:
14617 case X86::BI__builtin_ia32_vec_ext_v4sf:
14618 case X86::BI__builtin_ia32_vec_ext_v2di:
14619 case X86::BI__builtin_ia32_vec_ext_v32qi:
14620 case X86::BI__builtin_ia32_vec_ext_v16hi:
14621 case X86::BI__builtin_ia32_vec_ext_v8si:
14622 case X86::BI__builtin_ia32_vec_ext_v4di: {
14624 cast<llvm::FixedVectorType>(Ops[0]->getType())->getNumElements();
14625 uint64_t Index = cast<ConstantInt>(Ops[1])->getZExtValue();
14626 Index &= NumElts - 1;
14629 return Builder.CreateExtractElement(Ops[0], Index);
14631 case X86::BI__builtin_ia32_vec_set_v4hi:
14632 case X86::BI__builtin_ia32_vec_set_v16qi:
14633 case X86::BI__builtin_ia32_vec_set_v8hi:
14634 case X86::BI__builtin_ia32_vec_set_v4si:
14635 case X86::BI__builtin_ia32_vec_set_v2di:
14636 case X86::BI__builtin_ia32_vec_set_v32qi:
14637 case X86::BI__builtin_ia32_vec_set_v16hi:
14638 case X86::BI__builtin_ia32_vec_set_v8si:
14639 case X86::BI__builtin_ia32_vec_set_v4di: {
14641 cast<llvm::FixedVectorType>(Ops[0]->getType())->getNumElements();
14642 unsigned Index = cast<ConstantInt>(Ops[2])->getZExtValue();
14643 Index &= NumElts - 1;
14646 return Builder.CreateInsertElement(Ops[0], Ops[1], Index);
14648 case X86::BI_mm_setcsr:
14649 case X86::BI__builtin_ia32_ldmxcsr: {
14655 case X86::BI_mm_getcsr:
14656 case X86::BI__builtin_ia32_stmxcsr: {
14662 case X86::BI__builtin_ia32_xsave:
14663 case X86::BI__builtin_ia32_xsave64:
14664 case X86::BI__builtin_ia32_xrstor:
14665 case X86::BI__builtin_ia32_xrstor64:
14666 case X86::BI__builtin_ia32_xsaveopt:
14667 case X86::BI__builtin_ia32_xsaveopt64:
14668 case X86::BI__builtin_ia32_xrstors:
14669 case X86::BI__builtin_ia32_xrstors64:
14670 case X86::BI__builtin_ia32_xsavec:
14671 case X86::BI__builtin_ia32_xsavec64:
14672 case X86::BI__builtin_ia32_xsaves:
14673 case X86::BI__builtin_ia32_xsaves64:
14674 case X86::BI__builtin_ia32_xsetbv:
14675 case X86::BI_xsetbv: {
14677#define INTRINSIC_X86_XSAVE_ID(NAME) \
14678 case X86::BI__builtin_ia32_##NAME: \
14679 ID = Intrinsic::x86_##NAME; \
14681 switch (BuiltinID) {
14682 default: llvm_unreachable(
"Unsupported intrinsic!");
14696 case X86::BI_xsetbv:
14697 ID = Intrinsic::x86_xsetbv;
14700#undef INTRINSIC_X86_XSAVE_ID
14705 Ops.push_back(Mlo);
14708 case X86::BI__builtin_ia32_xgetbv:
14709 case X86::BI_xgetbv:
14711 case X86::BI__builtin_ia32_storedqudi128_mask:
14712 case X86::BI__builtin_ia32_storedqusi128_mask:
14713 case X86::BI__builtin_ia32_storedquhi128_mask:
14714 case X86::BI__builtin_ia32_storedquqi128_mask:
14715 case X86::BI__builtin_ia32_storeupd128_mask:
14716 case X86::BI__builtin_ia32_storeups128_mask:
14717 case X86::BI__builtin_ia32_storedqudi256_mask:
14718 case X86::BI__builtin_ia32_storedqusi256_mask:
14719 case X86::BI__builtin_ia32_storedquhi256_mask:
14720 case X86::BI__builtin_ia32_storedquqi256_mask:
14721 case X86::BI__builtin_ia32_storeupd256_mask:
14722 case X86::BI__builtin_ia32_storeups256_mask:
14723 case X86::BI__builtin_ia32_storedqudi512_mask:
14724 case X86::BI__builtin_ia32_storedqusi512_mask:
14725 case X86::BI__builtin_ia32_storedquhi512_mask:
14726 case X86::BI__builtin_ia32_storedquqi512_mask:
14727 case X86::BI__builtin_ia32_storeupd512_mask:
14728 case X86::BI__builtin_ia32_storeups512_mask:
14731 case X86::BI__builtin_ia32_storesh128_mask:
14732 case X86::BI__builtin_ia32_storess128_mask:
14733 case X86::BI__builtin_ia32_storesd128_mask:
14736 case X86::BI__builtin_ia32_vpopcntb_128:
14737 case X86::BI__builtin_ia32_vpopcntd_128:
14738 case X86::BI__builtin_ia32_vpopcntq_128:
14739 case X86::BI__builtin_ia32_vpopcntw_128:
14740 case X86::BI__builtin_ia32_vpopcntb_256:
14741 case X86::BI__builtin_ia32_vpopcntd_256:
14742 case X86::BI__builtin_ia32_vpopcntq_256:
14743 case X86::BI__builtin_ia32_vpopcntw_256:
14744 case X86::BI__builtin_ia32_vpopcntb_512:
14745 case X86::BI__builtin_ia32_vpopcntd_512:
14746 case X86::BI__builtin_ia32_vpopcntq_512:
14747 case X86::BI__builtin_ia32_vpopcntw_512: {
14750 return Builder.CreateCall(F, Ops);
14752 case X86::BI__builtin_ia32_cvtmask2b128:
14753 case X86::BI__builtin_ia32_cvtmask2b256:
14754 case X86::BI__builtin_ia32_cvtmask2b512:
14755 case X86::BI__builtin_ia32_cvtmask2w128:
14756 case X86::BI__builtin_ia32_cvtmask2w256:
14757 case X86::BI__builtin_ia32_cvtmask2w512:
14758 case X86::BI__builtin_ia32_cvtmask2d128:
14759 case X86::BI__builtin_ia32_cvtmask2d256:
14760 case X86::BI__builtin_ia32_cvtmask2d512:
14761 case X86::BI__builtin_ia32_cvtmask2q128:
14762 case X86::BI__builtin_ia32_cvtmask2q256:
14763 case X86::BI__builtin_ia32_cvtmask2q512:
14766 case X86::BI__builtin_ia32_cvtb2mask128:
14767 case X86::BI__builtin_ia32_cvtb2mask256:
14768 case X86::BI__builtin_ia32_cvtb2mask512:
14769 case X86::BI__builtin_ia32_cvtw2mask128:
14770 case X86::BI__builtin_ia32_cvtw2mask256:
14771 case X86::BI__builtin_ia32_cvtw2mask512:
14772 case X86::BI__builtin_ia32_cvtd2mask128:
14773 case X86::BI__builtin_ia32_cvtd2mask256:
14774 case X86::BI__builtin_ia32_cvtd2mask512:
14775 case X86::BI__builtin_ia32_cvtq2mask128:
14776 case X86::BI__builtin_ia32_cvtq2mask256:
14777 case X86::BI__builtin_ia32_cvtq2mask512:
14780 case X86::BI__builtin_ia32_cvtdq2ps512_mask:
14781 case X86::BI__builtin_ia32_cvtqq2ps512_mask:
14782 case X86::BI__builtin_ia32_cvtqq2pd512_mask:
14783 case X86::BI__builtin_ia32_vcvtw2ph512_mask:
14784 case X86::BI__builtin_ia32_vcvtdq2ph512_mask:
14785 case X86::BI__builtin_ia32_vcvtqq2ph512_mask:
14786 case X86::BI__builtin_ia32_vcvtdq2ph256_round_mask:
14787 case X86::BI__builtin_ia32_vcvtdq2ps256_round_mask:
14788 case X86::BI__builtin_ia32_vcvtqq2pd256_round_mask:
14789 case X86::BI__builtin_ia32_vcvtqq2ph256_round_mask:
14790 case X86::BI__builtin_ia32_vcvtqq2ps256_round_mask:
14791 case X86::BI__builtin_ia32_vcvtw2ph256_round_mask:
14793 case X86::BI__builtin_ia32_cvtudq2ps512_mask:
14794 case X86::BI__builtin_ia32_cvtuqq2ps512_mask:
14795 case X86::BI__builtin_ia32_cvtuqq2pd512_mask:
14796 case X86::BI__builtin_ia32_vcvtuw2ph512_mask:
14797 case X86::BI__builtin_ia32_vcvtudq2ph512_mask:
14798 case X86::BI__builtin_ia32_vcvtuqq2ph512_mask:
14799 case X86::BI__builtin_ia32_vcvtudq2ph256_round_mask:
14800 case X86::BI__builtin_ia32_vcvtudq2ps256_round_mask:
14801 case X86::BI__builtin_ia32_vcvtuqq2pd256_round_mask:
14802 case X86::BI__builtin_ia32_vcvtuqq2ph256_round_mask:
14803 case X86::BI__builtin_ia32_vcvtuqq2ps256_round_mask:
14804 case X86::BI__builtin_ia32_vcvtuw2ph256_round_mask:
14807 case X86::BI__builtin_ia32_vfmaddss3:
14808 case X86::BI__builtin_ia32_vfmaddsd3:
14809 case X86::BI__builtin_ia32_vfmaddsh3_mask:
14810 case X86::BI__builtin_ia32_vfmaddss3_mask:
14811 case X86::BI__builtin_ia32_vfmaddsd3_mask:
14813 case X86::BI__builtin_ia32_vfmaddss:
14814 case X86::BI__builtin_ia32_vfmaddsd:
14816 Constant::getNullValue(Ops[0]->getType()));
14817 case X86::BI__builtin_ia32_vfmaddsh3_maskz:
14818 case X86::BI__builtin_ia32_vfmaddss3_maskz:
14819 case X86::BI__builtin_ia32_vfmaddsd3_maskz:
14821 case X86::BI__builtin_ia32_vfmaddsh3_mask3:
14822 case X86::BI__builtin_ia32_vfmaddss3_mask3:
14823 case X86::BI__builtin_ia32_vfmaddsd3_mask3:
14825 case X86::BI__builtin_ia32_vfmsubsh3_mask3:
14826 case X86::BI__builtin_ia32_vfmsubss3_mask3:
14827 case X86::BI__builtin_ia32_vfmsubsd3_mask3:
14830 case X86::BI__builtin_ia32_vfmaddph:
14831 case X86::BI__builtin_ia32_vfmaddps:
14832 case X86::BI__builtin_ia32_vfmaddpd:
14833 case X86::BI__builtin_ia32_vfmaddph256:
14834 case X86::BI__builtin_ia32_vfmaddps256:
14835 case X86::BI__builtin_ia32_vfmaddpd256:
14836 case X86::BI__builtin_ia32_vfmaddph512_mask:
14837 case X86::BI__builtin_ia32_vfmaddph512_maskz:
14838 case X86::BI__builtin_ia32_vfmaddph512_mask3:
14839 case X86::BI__builtin_ia32_vfmaddps512_mask:
14840 case X86::BI__builtin_ia32_vfmaddps512_maskz:
14841 case X86::BI__builtin_ia32_vfmaddps512_mask3:
14842 case X86::BI__builtin_ia32_vfmsubps512_mask3:
14843 case X86::BI__builtin_ia32_vfmaddpd512_mask:
14844 case X86::BI__builtin_ia32_vfmaddpd512_maskz:
14845 case X86::BI__builtin_ia32_vfmaddpd512_mask3:
14846 case X86::BI__builtin_ia32_vfmsubpd512_mask3:
14847 case X86::BI__builtin_ia32_vfmsubph512_mask3:
14848 case X86::BI__builtin_ia32_vfmaddph256_round_mask:
14849 case X86::BI__builtin_ia32_vfmaddph256_round_maskz:
14850 case X86::BI__builtin_ia32_vfmaddph256_round_mask3:
14851 case X86::BI__builtin_ia32_vfmaddps256_round_mask:
14852 case X86::BI__builtin_ia32_vfmaddps256_round_maskz:
14853 case X86::BI__builtin_ia32_vfmaddps256_round_mask3:
14854 case X86::BI__builtin_ia32_vfmsubps256_round_mask3:
14855 case X86::BI__builtin_ia32_vfmaddpd256_round_mask:
14856 case X86::BI__builtin_ia32_vfmaddpd256_round_maskz:
14857 case X86::BI__builtin_ia32_vfmaddpd256_round_mask3:
14858 case X86::BI__builtin_ia32_vfmsubpd256_round_mask3:
14859 case X86::BI__builtin_ia32_vfmsubph256_round_mask3:
14861 case X86::BI__builtin_ia32_vfmaddsubph512_mask:
14862 case X86::BI__builtin_ia32_vfmaddsubph512_maskz:
14863 case X86::BI__builtin_ia32_vfmaddsubph512_mask3:
14864 case X86::BI__builtin_ia32_vfmsubaddph512_mask3:
14865 case X86::BI__builtin_ia32_vfmaddsubps512_mask:
14866 case X86::BI__builtin_ia32_vfmaddsubps512_maskz:
14867 case X86::BI__builtin_ia32_vfmaddsubps512_mask3:
14868 case X86::BI__builtin_ia32_vfmsubaddps512_mask3:
14869 case X86::BI__builtin_ia32_vfmaddsubpd512_mask:
14870 case X86::BI__builtin_ia32_vfmaddsubpd512_maskz:
14871 case X86::BI__builtin_ia32_vfmaddsubpd512_mask3:
14872 case X86::BI__builtin_ia32_vfmsubaddpd512_mask3:
14873 case X86::BI__builtin_ia32_vfmaddsubph256_round_mask:
14874 case X86::BI__builtin_ia32_vfmaddsubph256_round_maskz:
14875 case X86::BI__builtin_ia32_vfmaddsubph256_round_mask3:
14876 case X86::BI__builtin_ia32_vfmsubaddph256_round_mask3:
14877 case X86::BI__builtin_ia32_vfmaddsubps256_round_mask:
14878 case X86::BI__builtin_ia32_vfmaddsubps256_round_maskz:
14879 case X86::BI__builtin_ia32_vfmaddsubps256_round_mask3:
14880 case X86::BI__builtin_ia32_vfmsubaddps256_round_mask3:
14881 case X86::BI__builtin_ia32_vfmaddsubpd256_round_mask:
14882 case X86::BI__builtin_ia32_vfmaddsubpd256_round_maskz:
14883 case X86::BI__builtin_ia32_vfmaddsubpd256_round_mask3:
14884 case X86::BI__builtin_ia32_vfmsubaddpd256_round_mask3:
14887 case X86::BI__builtin_ia32_movdqa32store128_mask:
14888 case X86::BI__builtin_ia32_movdqa64store128_mask:
14889 case X86::BI__builtin_ia32_storeaps128_mask:
14890 case X86::BI__builtin_ia32_storeapd128_mask:
14891 case X86::BI__builtin_ia32_movdqa32store256_mask:
14892 case X86::BI__builtin_ia32_movdqa64store256_mask:
14893 case X86::BI__builtin_ia32_storeaps256_mask:
14894 case X86::BI__builtin_ia32_storeapd256_mask:
14895 case X86::BI__builtin_ia32_movdqa32store512_mask:
14896 case X86::BI__builtin_ia32_movdqa64store512_mask:
14897 case X86::BI__builtin_ia32_storeaps512_mask:
14898 case X86::BI__builtin_ia32_storeapd512_mask:
14903 case X86::BI__builtin_ia32_loadups128_mask:
14904 case X86::BI__builtin_ia32_loadups256_mask:
14905 case X86::BI__builtin_ia32_loadups512_mask:
14906 case X86::BI__builtin_ia32_loadupd128_mask:
14907 case X86::BI__builtin_ia32_loadupd256_mask:
14908 case X86::BI__builtin_ia32_loadupd512_mask:
14909 case X86::BI__builtin_ia32_loaddquqi128_mask:
14910 case X86::BI__builtin_ia32_loaddquqi256_mask:
14911 case X86::BI__builtin_ia32_loaddquqi512_mask:
14912 case X86::BI__builtin_ia32_loaddquhi128_mask:
14913 case X86::BI__builtin_ia32_loaddquhi256_mask:
14914 case X86::BI__builtin_ia32_loaddquhi512_mask:
14915 case X86::BI__builtin_ia32_loaddqusi128_mask:
14916 case X86::BI__builtin_ia32_loaddqusi256_mask:
14917 case X86::BI__builtin_ia32_loaddqusi512_mask:
14918 case X86::BI__builtin_ia32_loaddqudi128_mask:
14919 case X86::BI__builtin_ia32_loaddqudi256_mask:
14920 case X86::BI__builtin_ia32_loaddqudi512_mask:
14923 case X86::BI__builtin_ia32_loadsh128_mask:
14924 case X86::BI__builtin_ia32_loadss128_mask:
14925 case X86::BI__builtin_ia32_loadsd128_mask:
14928 case X86::BI__builtin_ia32_loadaps128_mask:
14929 case X86::BI__builtin_ia32_loadaps256_mask:
14930 case X86::BI__builtin_ia32_loadaps512_mask:
14931 case X86::BI__builtin_ia32_loadapd128_mask:
14932 case X86::BI__builtin_ia32_loadapd256_mask:
14933 case X86::BI__builtin_ia32_loadapd512_mask:
14934 case X86::BI__builtin_ia32_movdqa32load128_mask:
14935 case X86::BI__builtin_ia32_movdqa32load256_mask:
14936 case X86::BI__builtin_ia32_movdqa32load512_mask:
14937 case X86::BI__builtin_ia32_movdqa64load128_mask:
14938 case X86::BI__builtin_ia32_movdqa64load256_mask:
14939 case X86::BI__builtin_ia32_movdqa64load512_mask:
14944 case X86::BI__builtin_ia32_expandloaddf128_mask:
14945 case X86::BI__builtin_ia32_expandloaddf256_mask:
14946 case X86::BI__builtin_ia32_expandloaddf512_mask:
14947 case X86::BI__builtin_ia32_expandloadsf128_mask:
14948 case X86::BI__builtin_ia32_expandloadsf256_mask:
14949 case X86::BI__builtin_ia32_expandloadsf512_mask:
14950 case X86::BI__builtin_ia32_expandloaddi128_mask:
14951 case X86::BI__builtin_ia32_expandloaddi256_mask:
14952 case X86::BI__builtin_ia32_expandloaddi512_mask:
14953 case X86::BI__builtin_ia32_expandloadsi128_mask:
14954 case X86::BI__builtin_ia32_expandloadsi256_mask:
14955 case X86::BI__builtin_ia32_expandloadsi512_mask:
14956 case X86::BI__builtin_ia32_expandloadhi128_mask:
14957 case X86::BI__builtin_ia32_expandloadhi256_mask:
14958 case X86::BI__builtin_ia32_expandloadhi512_mask:
14959 case X86::BI__builtin_ia32_expandloadqi128_mask:
14960 case X86::BI__builtin_ia32_expandloadqi256_mask:
14961 case X86::BI__builtin_ia32_expandloadqi512_mask:
14964 case X86::BI__builtin_ia32_compressstoredf128_mask:
14965 case X86::BI__builtin_ia32_compressstoredf256_mask:
14966 case X86::BI__builtin_ia32_compressstoredf512_mask:
14967 case X86::BI__builtin_ia32_compressstoresf128_mask:
14968 case X86::BI__builtin_ia32_compressstoresf256_mask:
14969 case X86::BI__builtin_ia32_compressstoresf512_mask:
14970 case X86::BI__builtin_ia32_compressstoredi128_mask:
14971 case X86::BI__builtin_ia32_compressstoredi256_mask:
14972 case X86::BI__builtin_ia32_compressstoredi512_mask:
14973 case X86::BI__builtin_ia32_compressstoresi128_mask:
14974 case X86::BI__builtin_ia32_compressstoresi256_mask:
14975 case X86::BI__builtin_ia32_compressstoresi512_mask:
14976 case X86::BI__builtin_ia32_compressstorehi128_mask:
14977 case X86::BI__builtin_ia32_compressstorehi256_mask:
14978 case X86::BI__builtin_ia32_compressstorehi512_mask:
14979 case X86::BI__builtin_ia32_compressstoreqi128_mask:
14980 case X86::BI__builtin_ia32_compressstoreqi256_mask:
14981 case X86::BI__builtin_ia32_compressstoreqi512_mask:
14984 case X86::BI__builtin_ia32_expanddf128_mask:
14985 case X86::BI__builtin_ia32_expanddf256_mask:
14986 case X86::BI__builtin_ia32_expanddf512_mask:
14987 case X86::BI__builtin_ia32_expandsf128_mask:
14988 case X86::BI__builtin_ia32_expandsf256_mask:
14989 case X86::BI__builtin_ia32_expandsf512_mask:
14990 case X86::BI__builtin_ia32_expanddi128_mask:
14991 case X86::BI__builtin_ia32_expanddi256_mask:
14992 case X86::BI__builtin_ia32_expanddi512_mask:
14993 case X86::BI__builtin_ia32_expandsi128_mask:
14994 case X86::BI__builtin_ia32_expandsi256_mask:
14995 case X86::BI__builtin_ia32_expandsi512_mask:
14996 case X86::BI__builtin_ia32_expandhi128_mask:
14997 case X86::BI__builtin_ia32_expandhi256_mask:
14998 case X86::BI__builtin_ia32_expandhi512_mask:
14999 case X86::BI__builtin_ia32_expandqi128_mask:
15000 case X86::BI__builtin_ia32_expandqi256_mask:
15001 case X86::BI__builtin_ia32_expandqi512_mask:
15004 case X86::BI__builtin_ia32_compressdf128_mask:
15005 case X86::BI__builtin_ia32_compressdf256_mask:
15006 case X86::BI__builtin_ia32_compressdf512_mask:
15007 case X86::BI__builtin_ia32_compresssf128_mask:
15008 case X86::BI__builtin_ia32_compresssf256_mask:
15009 case X86::BI__builtin_ia32_compresssf512_mask:
15010 case X86::BI__builtin_ia32_compressdi128_mask:
15011 case X86::BI__builtin_ia32_compressdi256_mask:
15012 case X86::BI__builtin_ia32_compressdi512_mask:
15013 case X86::BI__builtin_ia32_compresssi128_mask:
15014 case X86::BI__builtin_ia32_compresssi256_mask:
15015 case X86::BI__builtin_ia32_compresssi512_mask:
15016 case X86::BI__builtin_ia32_compresshi128_mask:
15017 case X86::BI__builtin_ia32_compresshi256_mask:
15018 case X86::BI__builtin_ia32_compresshi512_mask:
15019 case X86::BI__builtin_ia32_compressqi128_mask:
15020 case X86::BI__builtin_ia32_compressqi256_mask:
15021 case X86::BI__builtin_ia32_compressqi512_mask:
15024 case X86::BI__builtin_ia32_gather3div2df:
15025 case X86::BI__builtin_ia32_gather3div2di:
15026 case X86::BI__builtin_ia32_gather3div4df:
15027 case X86::BI__builtin_ia32_gather3div4di:
15028 case X86::BI__builtin_ia32_gather3div4sf:
15029 case X86::BI__builtin_ia32_gather3div4si:
15030 case X86::BI__builtin_ia32_gather3div8sf:
15031 case X86::BI__builtin_ia32_gather3div8si:
15032 case X86::BI__builtin_ia32_gather3siv2df:
15033 case X86::BI__builtin_ia32_gather3siv2di:
15034 case X86::BI__builtin_ia32_gather3siv4df:
15035 case X86::BI__builtin_ia32_gather3siv4di:
15036 case X86::BI__builtin_ia32_gather3siv4sf:
15037 case X86::BI__builtin_ia32_gather3siv4si:
15038 case X86::BI__builtin_ia32_gather3siv8sf:
15039 case X86::BI__builtin_ia32_gather3siv8si:
15040 case X86::BI__builtin_ia32_gathersiv8df:
15041 case X86::BI__builtin_ia32_gathersiv16sf:
15042 case X86::BI__builtin_ia32_gatherdiv8df:
15043 case X86::BI__builtin_ia32_gatherdiv16sf:
15044 case X86::BI__builtin_ia32_gathersiv8di:
15045 case X86::BI__builtin_ia32_gathersiv16si:
15046 case X86::BI__builtin_ia32_gatherdiv8di:
15047 case X86::BI__builtin_ia32_gatherdiv16si: {
15049 switch (BuiltinID) {
15050 default: llvm_unreachable(
"Unexpected builtin");
15051 case X86::BI__builtin_ia32_gather3div2df:
15052 IID = Intrinsic::x86_avx512_mask_gather3div2_df;
15054 case X86::BI__builtin_ia32_gather3div2di:
15055 IID = Intrinsic::x86_avx512_mask_gather3div2_di;
15057 case X86::BI__builtin_ia32_gather3div4df:
15058 IID = Intrinsic::x86_avx512_mask_gather3div4_df;
15060 case X86::BI__builtin_ia32_gather3div4di:
15061 IID = Intrinsic::x86_avx512_mask_gather3div4_di;
15063 case X86::BI__builtin_ia32_gather3div4sf:
15064 IID = Intrinsic::x86_avx512_mask_gather3div4_sf;
15066 case X86::BI__builtin_ia32_gather3div4si:
15067 IID = Intrinsic::x86_avx512_mask_gather3div4_si;
15069 case X86::BI__builtin_ia32_gather3div8sf:
15070 IID = Intrinsic::x86_avx512_mask_gather3div8_sf;
15072 case X86::BI__builtin_ia32_gather3div8si:
15073 IID = Intrinsic::x86_avx512_mask_gather3div8_si;
15075 case X86::BI__builtin_ia32_gather3siv2df:
15076 IID = Intrinsic::x86_avx512_mask_gather3siv2_df;
15078 case X86::BI__builtin_ia32_gather3siv2di:
15079 IID = Intrinsic::x86_avx512_mask_gather3siv2_di;
15081 case X86::BI__builtin_ia32_gather3siv4df:
15082 IID = Intrinsic::x86_avx512_mask_gather3siv4_df;
15084 case X86::BI__builtin_ia32_gather3siv4di:
15085 IID = Intrinsic::x86_avx512_mask_gather3siv4_di;
15087 case X86::BI__builtin_ia32_gather3siv4sf:
15088 IID = Intrinsic::x86_avx512_mask_gather3siv4_sf;
15090 case X86::BI__builtin_ia32_gather3siv4si:
15091 IID = Intrinsic::x86_avx512_mask_gather3siv4_si;
15093 case X86::BI__builtin_ia32_gather3siv8sf:
15094 IID = Intrinsic::x86_avx512_mask_gather3siv8_sf;
15096 case X86::BI__builtin_ia32_gather3siv8si:
15097 IID = Intrinsic::x86_avx512_mask_gather3siv8_si;
15099 case X86::BI__builtin_ia32_gathersiv8df:
15100 IID = Intrinsic::x86_avx512_mask_gather_dpd_512;
15102 case X86::BI__builtin_ia32_gathersiv16sf:
15103 IID = Intrinsic::x86_avx512_mask_gather_dps_512;
15105 case X86::BI__builtin_ia32_gatherdiv8df:
15106 IID = Intrinsic::x86_avx512_mask_gather_qpd_512;
15108 case X86::BI__builtin_ia32_gatherdiv16sf:
15109 IID = Intrinsic::x86_avx512_mask_gather_qps_512;
15111 case X86::BI__builtin_ia32_gathersiv8di:
15112 IID = Intrinsic::x86_avx512_mask_gather_dpq_512;
15114 case X86::BI__builtin_ia32_gathersiv16si:
15115 IID = Intrinsic::x86_avx512_mask_gather_dpi_512;
15117 case X86::BI__builtin_ia32_gatherdiv8di:
15118 IID = Intrinsic::x86_avx512_mask_gather_qpq_512;
15120 case X86::BI__builtin_ia32_gatherdiv16si:
15121 IID = Intrinsic::x86_avx512_mask_gather_qpi_512;
15125 unsigned MinElts = std::min(
15126 cast<llvm::FixedVectorType>(Ops[0]->getType())->getNumElements(),
15127 cast<llvm::FixedVectorType>(Ops[2]->getType())->getNumElements());
15130 return Builder.CreateCall(Intr, Ops);
15133 case X86::BI__builtin_ia32_scattersiv8df:
15134 case X86::BI__builtin_ia32_scattersiv16sf:
15135 case X86::BI__builtin_ia32_scatterdiv8df:
15136 case X86::BI__builtin_ia32_scatterdiv16sf:
15137 case X86::BI__builtin_ia32_scattersiv8di:
15138 case X86::BI__builtin_ia32_scattersiv16si:
15139 case X86::BI__builtin_ia32_scatterdiv8di:
15140 case X86::BI__builtin_ia32_scatterdiv16si:
15141 case X86::BI__builtin_ia32_scatterdiv2df:
15142 case X86::BI__builtin_ia32_scatterdiv2di:
15143 case X86::BI__builtin_ia32_scatterdiv4df:
15144 case X86::BI__builtin_ia32_scatterdiv4di:
15145 case X86::BI__builtin_ia32_scatterdiv4sf:
15146 case X86::BI__builtin_ia32_scatterdiv4si:
15147 case X86::BI__builtin_ia32_scatterdiv8sf:
15148 case X86::BI__builtin_ia32_scatterdiv8si:
15149 case X86::BI__builtin_ia32_scattersiv2df:
15150 case X86::BI__builtin_ia32_scattersiv2di:
15151 case X86::BI__builtin_ia32_scattersiv4df:
15152 case X86::BI__builtin_ia32_scattersiv4di:
15153 case X86::BI__builtin_ia32_scattersiv4sf:
15154 case X86::BI__builtin_ia32_scattersiv4si:
15155 case X86::BI__builtin_ia32_scattersiv8sf:
15156 case X86::BI__builtin_ia32_scattersiv8si: {
15158 switch (BuiltinID) {
15159 default: llvm_unreachable(
"Unexpected builtin");
15160 case X86::BI__builtin_ia32_scattersiv8df:
15161 IID = Intrinsic::x86_avx512_mask_scatter_dpd_512;
15163 case X86::BI__builtin_ia32_scattersiv16sf:
15164 IID = Intrinsic::x86_avx512_mask_scatter_dps_512;
15166 case X86::BI__builtin_ia32_scatterdiv8df:
15167 IID = Intrinsic::x86_avx512_mask_scatter_qpd_512;
15169 case X86::BI__builtin_ia32_scatterdiv16sf:
15170 IID = Intrinsic::x86_avx512_mask_scatter_qps_512;
15172 case X86::BI__builtin_ia32_scattersiv8di:
15173 IID = Intrinsic::x86_avx512_mask_scatter_dpq_512;
15175 case X86::BI__builtin_ia32_scattersiv16si:
15176 IID = Intrinsic::x86_avx512_mask_scatter_dpi_512;
15178 case X86::BI__builtin_ia32_scatterdiv8di:
15179 IID = Intrinsic::x86_avx512_mask_scatter_qpq_512;
15181 case X86::BI__builtin_ia32_scatterdiv16si:
15182 IID = Intrinsic::x86_avx512_mask_scatter_qpi_512;
15184 case X86::BI__builtin_ia32_scatterdiv2df:
15185 IID = Intrinsic::x86_avx512_mask_scatterdiv2_df;
15187 case X86::BI__builtin_ia32_scatterdiv2di:
15188 IID = Intrinsic::x86_avx512_mask_scatterdiv2_di;
15190 case X86::BI__builtin_ia32_scatterdiv4df:
15191 IID = Intrinsic::x86_avx512_mask_scatterdiv4_df;
15193 case X86::BI__builtin_ia32_scatterdiv4di:
15194 IID = Intrinsic::x86_avx512_mask_scatterdiv4_di;
15196 case X86::BI__builtin_ia32_scatterdiv4sf:
15197 IID = Intrinsic::x86_avx512_mask_scatterdiv4_sf;
15199 case X86::BI__builtin_ia32_scatterdiv4si:
15200 IID = Intrinsic::x86_avx512_mask_scatterdiv4_si;
15202 case X86::BI__builtin_ia32_scatterdiv8sf:
15203 IID = Intrinsic::x86_avx512_mask_scatterdiv8_sf;
15205 case X86::BI__builtin_ia32_scatterdiv8si:
15206 IID = Intrinsic::x86_avx512_mask_scatterdiv8_si;
15208 case X86::BI__builtin_ia32_scattersiv2df:
15209 IID = Intrinsic::x86_avx512_mask_scattersiv2_df;
15211 case X86::BI__builtin_ia32_scattersiv2di:
15212 IID = Intrinsic::x86_avx512_mask_scattersiv2_di;
15214 case X86::BI__builtin_ia32_scattersiv4df:
15215 IID = Intrinsic::x86_avx512_mask_scattersiv4_df;
15217 case X86::BI__builtin_ia32_scattersiv4di:
15218 IID = Intrinsic::x86_avx512_mask_scattersiv4_di;
15220 case X86::BI__builtin_ia32_scattersiv4sf:
15221 IID = Intrinsic::x86_avx512_mask_scattersiv4_sf;
15223 case X86::BI__builtin_ia32_scattersiv4si:
15224 IID = Intrinsic::x86_avx512_mask_scattersiv4_si;
15226 case X86::BI__builtin_ia32_scattersiv8sf:
15227 IID = Intrinsic::x86_avx512_mask_scattersiv8_sf;
15229 case X86::BI__builtin_ia32_scattersiv8si:
15230 IID = Intrinsic::x86_avx512_mask_scattersiv8_si;
15234 unsigned MinElts = std::min(
15235 cast<llvm::FixedVectorType>(Ops[2]->getType())->getNumElements(),
15236 cast<llvm::FixedVectorType>(Ops[3]->getType())->getNumElements());
15239 return Builder.CreateCall(Intr, Ops);
15242 case X86::BI__builtin_ia32_vextractf128_pd256:
15243 case X86::BI__builtin_ia32_vextractf128_ps256:
15244 case X86::BI__builtin_ia32_vextractf128_si256:
15245 case X86::BI__builtin_ia32_extract128i256:
15246 case X86::BI__builtin_ia32_extractf64x4_mask:
15247 case X86::BI__builtin_ia32_extractf32x4_mask:
15248 case X86::BI__builtin_ia32_extracti64x4_mask:
15249 case X86::BI__builtin_ia32_extracti32x4_mask:
15250 case X86::BI__builtin_ia32_extractf32x8_mask:
15251 case X86::BI__builtin_ia32_extracti32x8_mask:
15252 case X86::BI__builtin_ia32_extractf32x4_256_mask:
15253 case X86::BI__builtin_ia32_extracti32x4_256_mask:
15254 case X86::BI__builtin_ia32_extractf64x2_256_mask:
15255 case X86::BI__builtin_ia32_extracti64x2_256_mask:
15256 case X86::BI__builtin_ia32_extractf64x2_512_mask:
15257 case X86::BI__builtin_ia32_extracti64x2_512_mask: {
15259 unsigned NumElts = DstTy->getNumElements();
15260 unsigned SrcNumElts =
15261 cast<llvm::FixedVectorType>(Ops[0]->getType())->getNumElements();
15262 unsigned SubVectors = SrcNumElts / NumElts;
15263 unsigned Index = cast<ConstantInt>(Ops[1])->getZExtValue();
15264 assert(llvm::isPowerOf2_32(SubVectors) &&
"Expected power of 2 subvectors");
15265 Index &= SubVectors - 1;
15269 for (
unsigned i = 0; i != NumElts; ++i)
15270 Indices[i] = i + Index;
15275 if (Ops.size() == 4)
15280 case X86::BI__builtin_ia32_vinsertf128_pd256:
15281 case X86::BI__builtin_ia32_vinsertf128_ps256:
15282 case X86::BI__builtin_ia32_vinsertf128_si256:
15283 case X86::BI__builtin_ia32_insert128i256:
15284 case X86::BI__builtin_ia32_insertf64x4:
15285 case X86::BI__builtin_ia32_insertf32x4:
15286 case X86::BI__builtin_ia32_inserti64x4:
15287 case X86::BI__builtin_ia32_inserti32x4:
15288 case X86::BI__builtin_ia32_insertf32x8:
15289 case X86::BI__builtin_ia32_inserti32x8:
15290 case X86::BI__builtin_ia32_insertf32x4_256:
15291 case X86::BI__builtin_ia32_inserti32x4_256:
15292 case X86::BI__builtin_ia32_insertf64x2_256:
15293 case X86::BI__builtin_ia32_inserti64x2_256:
15294 case X86::BI__builtin_ia32_insertf64x2_512:
15295 case X86::BI__builtin_ia32_inserti64x2_512: {
15296 unsigned DstNumElts =
15297 cast<llvm::FixedVectorType>(Ops[0]->getType())->getNumElements();
15298 unsigned SrcNumElts =
15299 cast<llvm::FixedVectorType>(Ops[1]->getType())->getNumElements();
15300 unsigned SubVectors = DstNumElts / SrcNumElts;
15301 unsigned Index = cast<ConstantInt>(Ops[2])->getZExtValue();
15302 assert(llvm::isPowerOf2_32(SubVectors) &&
"Expected power of 2 subvectors");
15303 Index &= SubVectors - 1;
15304 Index *= SrcNumElts;
15307 for (
unsigned i = 0; i != DstNumElts; ++i)
15308 Indices[i] = (i >= SrcNumElts) ? SrcNumElts + (i % SrcNumElts) : i;
15311 Ops[1],
ArrayRef(Indices, DstNumElts),
"widen");
15313 for (
unsigned i = 0; i != DstNumElts; ++i) {
15314 if (i >= Index && i < (Index + SrcNumElts))
15315 Indices[i] = (i - Index) + DstNumElts;
15320 return Builder.CreateShuffleVector(Ops[0], Op1,
15321 ArrayRef(Indices, DstNumElts),
"insert");
15323 case X86::BI__builtin_ia32_pmovqd512_mask:
15324 case X86::BI__builtin_ia32_pmovwb512_mask: {
15325 Value *Res =
Builder.CreateTrunc(Ops[0], Ops[1]->getType());
15328 case X86::BI__builtin_ia32_pmovdb512_mask:
15329 case X86::BI__builtin_ia32_pmovdw512_mask:
15330 case X86::BI__builtin_ia32_pmovqw512_mask: {
15331 if (
const auto *
C = dyn_cast<Constant>(Ops[2]))
15332 if (
C->isAllOnesValue())
15333 return Builder.CreateTrunc(Ops[0], Ops[1]->getType());
15336 switch (BuiltinID) {
15337 default: llvm_unreachable(
"Unsupported intrinsic!");
15338 case X86::BI__builtin_ia32_pmovdb512_mask:
15339 IID = Intrinsic::x86_avx512_mask_pmov_db_512;
15341 case X86::BI__builtin_ia32_pmovdw512_mask:
15342 IID = Intrinsic::x86_avx512_mask_pmov_dw_512;
15344 case X86::BI__builtin_ia32_pmovqw512_mask:
15345 IID = Intrinsic::x86_avx512_mask_pmov_qw_512;
15350 return Builder.CreateCall(Intr, Ops);
15352 case X86::BI__builtin_ia32_pblendw128:
15353 case X86::BI__builtin_ia32_blendpd:
15354 case X86::BI__builtin_ia32_blendps:
15355 case X86::BI__builtin_ia32_blendpd256:
15356 case X86::BI__builtin_ia32_blendps256:
15357 case X86::BI__builtin_ia32_pblendw256:
15358 case X86::BI__builtin_ia32_pblendd128:
15359 case X86::BI__builtin_ia32_pblendd256: {
15361 cast<llvm::FixedVectorType>(Ops[0]->getType())->getNumElements();
15362 unsigned Imm = cast<llvm::ConstantInt>(Ops[2])->getZExtValue();
15367 for (
unsigned i = 0; i != NumElts; ++i)
15368 Indices[i] = ((Imm >> (i % 8)) & 0x1) ? NumElts + i : i;
15370 return Builder.CreateShuffleVector(Ops[0], Ops[1],
15371 ArrayRef(Indices, NumElts),
"blend");
15373 case X86::BI__builtin_ia32_pshuflw:
15374 case X86::BI__builtin_ia32_pshuflw256:
15375 case X86::BI__builtin_ia32_pshuflw512: {
15376 uint32_t Imm = cast<llvm::ConstantInt>(Ops[1])->getZExtValue();
15377 auto *Ty = cast<llvm::FixedVectorType>(Ops[0]->getType());
15378 unsigned NumElts = Ty->getNumElements();
15381 Imm = (Imm & 0xff) * 0x01010101;
15384 for (
unsigned l = 0; l != NumElts; l += 8) {
15385 for (
unsigned i = 0; i != 4; ++i) {
15386 Indices[l + i] = l + (Imm & 3);
15389 for (
unsigned i = 4; i != 8; ++i)
15390 Indices[l + i] = l + i;
15393 return Builder.CreateShuffleVector(Ops[0],
ArrayRef(Indices, NumElts),
15396 case X86::BI__builtin_ia32_pshufhw:
15397 case X86::BI__builtin_ia32_pshufhw256:
15398 case X86::BI__builtin_ia32_pshufhw512: {
15399 uint32_t Imm = cast<llvm::ConstantInt>(Ops[1])->getZExtValue();
15400 auto *Ty = cast<llvm::FixedVectorType>(Ops[0]->getType());
15401 unsigned NumElts = Ty->getNumElements();
15404 Imm = (Imm & 0xff) * 0x01010101;
15407 for (
unsigned l = 0; l != NumElts; l += 8) {
15408 for (
unsigned i = 0; i != 4; ++i)
15409 Indices[l + i] = l + i;
15410 for (
unsigned i = 4; i != 8; ++i) {
15411 Indices[l + i] = l + 4 + (Imm & 3);
15416 return Builder.CreateShuffleVector(Ops[0],
ArrayRef(Indices, NumElts),
15419 case X86::BI__builtin_ia32_pshufd:
15420 case X86::BI__builtin_ia32_pshufd256:
15421 case X86::BI__builtin_ia32_pshufd512:
15422 case X86::BI__builtin_ia32_vpermilpd:
15423 case X86::BI__builtin_ia32_vpermilps:
15424 case X86::BI__builtin_ia32_vpermilpd256:
15425 case X86::BI__builtin_ia32_vpermilps256:
15426 case X86::BI__builtin_ia32_vpermilpd512:
15427 case X86::BI__builtin_ia32_vpermilps512: {
15428 uint32_t Imm = cast<llvm::ConstantInt>(Ops[1])->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 Indices[i + l] = (Imm % NumLaneElts) + l;
15441 Imm /= NumLaneElts;
15445 return Builder.CreateShuffleVector(Ops[0],
ArrayRef(Indices, NumElts),
15448 case X86::BI__builtin_ia32_shufpd:
15449 case X86::BI__builtin_ia32_shufpd256:
15450 case X86::BI__builtin_ia32_shufpd512:
15451 case X86::BI__builtin_ia32_shufps:
15452 case X86::BI__builtin_ia32_shufps256:
15453 case X86::BI__builtin_ia32_shufps512: {
15454 uint32_t Imm = cast<llvm::ConstantInt>(Ops[2])->getZExtValue();
15455 auto *Ty = cast<llvm::FixedVectorType>(Ops[0]->getType());
15456 unsigned NumElts = Ty->getNumElements();
15457 unsigned NumLanes = Ty->getPrimitiveSizeInBits() / 128;
15458 unsigned NumLaneElts = NumElts / NumLanes;
15461 Imm = (Imm & 0xff) * 0x01010101;
15464 for (
unsigned l = 0; l != NumElts; l += NumLaneElts) {
15465 for (
unsigned i = 0; i != NumLaneElts; ++i) {
15466 unsigned Index = Imm % NumLaneElts;
15467 Imm /= NumLaneElts;
15468 if (i >= (NumLaneElts / 2))
15470 Indices[l + i] = l + Index;
15474 return Builder.CreateShuffleVector(Ops[0], Ops[1],
15475 ArrayRef(Indices, NumElts),
"shufp");
15477 case X86::BI__builtin_ia32_permdi256:
15478 case X86::BI__builtin_ia32_permdf256:
15479 case X86::BI__builtin_ia32_permdi512:
15480 case X86::BI__builtin_ia32_permdf512: {
15481 unsigned Imm = cast<llvm::ConstantInt>(Ops[1])->getZExtValue();
15482 auto *Ty = cast<llvm::FixedVectorType>(Ops[0]->getType());
15483 unsigned NumElts = Ty->getNumElements();
15487 for (
unsigned l = 0; l != NumElts; l += 4)
15488 for (
unsigned i = 0; i != 4; ++i)
15489 Indices[l + i] = l + ((Imm >> (2 * i)) & 0x3);
15491 return Builder.CreateShuffleVector(Ops[0],
ArrayRef(Indices, NumElts),
15494 case X86::BI__builtin_ia32_palignr128:
15495 case X86::BI__builtin_ia32_palignr256:
15496 case X86::BI__builtin_ia32_palignr512: {
15497 unsigned ShiftVal = cast<llvm::ConstantInt>(Ops[2])->getZExtValue() & 0xff;
15500 cast<llvm::FixedVectorType>(Ops[0]->getType())->getNumElements();
15501 assert(NumElts % 16 == 0);
15505 if (ShiftVal >= 32)
15510 if (ShiftVal > 16) {
15513 Ops[0] = llvm::Constant::getNullValue(Ops[0]->getType());
15518 for (
unsigned l = 0; l != NumElts; l += 16) {
15519 for (
unsigned i = 0; i != 16; ++i) {
15520 unsigned Idx = ShiftVal + i;
15522 Idx += NumElts - 16;
15523 Indices[l + i] = Idx + l;
15527 return Builder.CreateShuffleVector(Ops[1], Ops[0],
15528 ArrayRef(Indices, NumElts),
"palignr");
15530 case X86::BI__builtin_ia32_alignd128:
15531 case X86::BI__builtin_ia32_alignd256:
15532 case X86::BI__builtin_ia32_alignd512:
15533 case X86::BI__builtin_ia32_alignq128:
15534 case X86::BI__builtin_ia32_alignq256:
15535 case X86::BI__builtin_ia32_alignq512: {
15537 cast<llvm::FixedVectorType>(Ops[0]->getType())->getNumElements();
15538 unsigned ShiftVal = cast<llvm::ConstantInt>(Ops[2])->getZExtValue() & 0xff;
15541 ShiftVal &= NumElts - 1;
15544 for (
unsigned i = 0; i != NumElts; ++i)
15545 Indices[i] = i + ShiftVal;
15547 return Builder.CreateShuffleVector(Ops[1], Ops[0],
15548 ArrayRef(Indices, NumElts),
"valign");
15550 case X86::BI__builtin_ia32_shuf_f32x4_256:
15551 case X86::BI__builtin_ia32_shuf_f64x2_256:
15552 case X86::BI__builtin_ia32_shuf_i32x4_256:
15553 case X86::BI__builtin_ia32_shuf_i64x2_256:
15554 case X86::BI__builtin_ia32_shuf_f32x4:
15555 case X86::BI__builtin_ia32_shuf_f64x2:
15556 case X86::BI__builtin_ia32_shuf_i32x4:
15557 case X86::BI__builtin_ia32_shuf_i64x2: {
15558 unsigned Imm = cast<llvm::ConstantInt>(Ops[2])->getZExtValue();
15559 auto *Ty = cast<llvm::FixedVectorType>(Ops[0]->getType());
15560 unsigned NumElts = Ty->getNumElements();
15561 unsigned NumLanes = Ty->getPrimitiveSizeInBits() == 512 ? 4 : 2;
15562 unsigned NumLaneElts = NumElts / NumLanes;
15565 for (
unsigned l = 0; l != NumElts; l += NumLaneElts) {
15566 unsigned Index = (Imm % NumLanes) * NumLaneElts;
15568 if (l >= (NumElts / 2))
15570 for (
unsigned i = 0; i != NumLaneElts; ++i) {
15571 Indices[l + i] = Index + i;
15575 return Builder.CreateShuffleVector(Ops[0], Ops[1],
15576 ArrayRef(Indices, NumElts),
"shuf");
15579 case X86::BI__builtin_ia32_vperm2f128_pd256:
15580 case X86::BI__builtin_ia32_vperm2f128_ps256:
15581 case X86::BI__builtin_ia32_vperm2f128_si256:
15582 case X86::BI__builtin_ia32_permti256: {
15583 unsigned Imm = cast<llvm::ConstantInt>(Ops[2])->getZExtValue();
15585 cast<llvm::FixedVectorType>(Ops[0]->getType())->getNumElements();
15594 for (
unsigned l = 0; l != 2; ++l) {
15596 if (Imm & (1 << ((l * 4) + 3)))
15597 OutOps[l] = llvm::ConstantAggregateZero::get(Ops[0]->getType());
15598 else if (Imm & (1 << ((l * 4) + 1)))
15599 OutOps[l] = Ops[1];
15601 OutOps[l] = Ops[0];
15603 for (
unsigned i = 0; i != NumElts/2; ++i) {
15605 unsigned Idx = (l * NumElts) + i;
15608 if (Imm & (1 << (l * 4)))
15610 Indices[(l * (NumElts/2)) + i] = Idx;
15614 return Builder.CreateShuffleVector(OutOps[0], OutOps[1],
15615 ArrayRef(Indices, NumElts),
"vperm");
15618 case X86::BI__builtin_ia32_pslldqi128_byteshift:
15619 case X86::BI__builtin_ia32_pslldqi256_byteshift:
15620 case X86::BI__builtin_ia32_pslldqi512_byteshift: {
15621 unsigned ShiftVal = cast<llvm::ConstantInt>(Ops[1])->getZExtValue() & 0xff;
15622 auto *ResultType = cast<llvm::FixedVectorType>(Ops[0]->getType());
15624 unsigned NumElts = ResultType->getNumElements() * 8;
15627 if (ShiftVal >= 16)
15628 return llvm::Constant::getNullValue(ResultType);
15632 for (
unsigned l = 0; l != NumElts; l += 16) {
15633 for (
unsigned i = 0; i != 16; ++i) {
15634 unsigned Idx = NumElts + i - ShiftVal;
15635 if (Idx < NumElts) Idx -= NumElts - 16;
15636 Indices[l + i] = Idx + l;
15640 auto *VecTy = llvm::FixedVectorType::get(
Int8Ty, NumElts);
15642 Value *
Zero = llvm::Constant::getNullValue(VecTy);
15644 Zero, Cast,
ArrayRef(Indices, NumElts),
"pslldq");
15645 return Builder.CreateBitCast(SV, Ops[0]->getType(),
"cast");
15647 case X86::BI__builtin_ia32_psrldqi128_byteshift:
15648 case X86::BI__builtin_ia32_psrldqi256_byteshift:
15649 case X86::BI__builtin_ia32_psrldqi512_byteshift: {
15650 unsigned ShiftVal = cast<llvm::ConstantInt>(Ops[1])->getZExtValue() & 0xff;
15651 auto *ResultType = cast<llvm::FixedVectorType>(Ops[0]->getType());
15653 unsigned NumElts = ResultType->getNumElements() * 8;
15656 if (ShiftVal >= 16)
15657 return llvm::Constant::getNullValue(ResultType);
15661 for (
unsigned l = 0; l != NumElts; l += 16) {
15662 for (
unsigned i = 0; i != 16; ++i) {
15663 unsigned Idx = i + ShiftVal;
15664 if (Idx >= 16) Idx += NumElts - 16;
15665 Indices[l + i] = Idx + l;
15669 auto *VecTy = llvm::FixedVectorType::get(
Int8Ty, NumElts);
15671 Value *
Zero = llvm::Constant::getNullValue(VecTy);
15673 Cast, Zero,
ArrayRef(Indices, NumElts),
"psrldq");
15674 return Builder.CreateBitCast(SV, ResultType,
"cast");
15676 case X86::BI__builtin_ia32_kshiftliqi:
15677 case X86::BI__builtin_ia32_kshiftlihi:
15678 case X86::BI__builtin_ia32_kshiftlisi:
15679 case X86::BI__builtin_ia32_kshiftlidi: {
15680 unsigned ShiftVal = cast<llvm::ConstantInt>(Ops[1])->getZExtValue() & 0xff;
15681 unsigned NumElts = Ops[0]->getType()->getIntegerBitWidth();
15683 if (ShiftVal >= NumElts)
15684 return llvm::Constant::getNullValue(Ops[0]->getType());
15689 for (
unsigned i = 0; i != NumElts; ++i)
15690 Indices[i] = NumElts + i - ShiftVal;
15692 Value *
Zero = llvm::Constant::getNullValue(
In->getType());
15694 Zero, In,
ArrayRef(Indices, NumElts),
"kshiftl");
15695 return Builder.CreateBitCast(SV, Ops[0]->getType());
15697 case X86::BI__builtin_ia32_kshiftriqi:
15698 case X86::BI__builtin_ia32_kshiftrihi:
15699 case X86::BI__builtin_ia32_kshiftrisi:
15700 case X86::BI__builtin_ia32_kshiftridi: {
15701 unsigned ShiftVal = cast<llvm::ConstantInt>(Ops[1])->getZExtValue() & 0xff;
15702 unsigned NumElts = Ops[0]->getType()->getIntegerBitWidth();
15704 if (ShiftVal >= NumElts)
15705 return llvm::Constant::getNullValue(Ops[0]->getType());
15710 for (
unsigned i = 0; i != NumElts; ++i)
15711 Indices[i] = i + ShiftVal;
15713 Value *
Zero = llvm::Constant::getNullValue(
In->getType());
15715 In, Zero,
ArrayRef(Indices, NumElts),
"kshiftr");
15716 return Builder.CreateBitCast(SV, Ops[0]->getType());
15718 case X86::BI__builtin_ia32_movnti:
15719 case X86::BI__builtin_ia32_movnti64:
15720 case X86::BI__builtin_ia32_movntsd:
15721 case X86::BI__builtin_ia32_movntss: {
15722 llvm::MDNode *
Node = llvm::MDNode::get(
15725 Value *Ptr = Ops[0];
15726 Value *Src = Ops[1];
15729 if (BuiltinID == X86::BI__builtin_ia32_movntsd ||
15730 BuiltinID == X86::BI__builtin_ia32_movntss)
15731 Src =
Builder.CreateExtractElement(Src, (uint64_t)0,
"extract");
15735 SI->setMetadata(llvm::LLVMContext::MD_nontemporal,
Node);
15736 SI->setAlignment(llvm::Align(1));
15740 case X86::BI__builtin_ia32_vprotb:
15741 case X86::BI__builtin_ia32_vprotw:
15742 case X86::BI__builtin_ia32_vprotd:
15743 case X86::BI__builtin_ia32_vprotq:
15744 case X86::BI__builtin_ia32_vprotbi:
15745 case X86::BI__builtin_ia32_vprotwi:
15746 case X86::BI__builtin_ia32_vprotdi:
15747 case X86::BI__builtin_ia32_vprotqi:
15748 case X86::BI__builtin_ia32_prold128:
15749 case X86::BI__builtin_ia32_prold256:
15750 case X86::BI__builtin_ia32_prold512:
15751 case X86::BI__builtin_ia32_prolq128:
15752 case X86::BI__builtin_ia32_prolq256:
15753 case X86::BI__builtin_ia32_prolq512:
15754 case X86::BI__builtin_ia32_prolvd128:
15755 case X86::BI__builtin_ia32_prolvd256:
15756 case X86::BI__builtin_ia32_prolvd512:
15757 case X86::BI__builtin_ia32_prolvq128:
15758 case X86::BI__builtin_ia32_prolvq256:
15759 case X86::BI__builtin_ia32_prolvq512:
15761 case X86::BI__builtin_ia32_prord128:
15762 case X86::BI__builtin_ia32_prord256:
15763 case X86::BI__builtin_ia32_prord512:
15764 case X86::BI__builtin_ia32_prorq128:
15765 case X86::BI__builtin_ia32_prorq256:
15766 case X86::BI__builtin_ia32_prorq512:
15767 case X86::BI__builtin_ia32_prorvd128:
15768 case X86::BI__builtin_ia32_prorvd256:
15769 case X86::BI__builtin_ia32_prorvd512:
15770 case X86::BI__builtin_ia32_prorvq128:
15771 case X86::BI__builtin_ia32_prorvq256:
15772 case X86::BI__builtin_ia32_prorvq512:
15774 case X86::BI__builtin_ia32_selectb_128:
15775 case X86::BI__builtin_ia32_selectb_256:
15776 case X86::BI__builtin_ia32_selectb_512:
15777 case X86::BI__builtin_ia32_selectw_128:
15778 case X86::BI__builtin_ia32_selectw_256:
15779 case X86::BI__builtin_ia32_selectw_512:
15780 case X86::BI__builtin_ia32_selectd_128:
15781 case X86::BI__builtin_ia32_selectd_256:
15782 case X86::BI__builtin_ia32_selectd_512:
15783 case X86::BI__builtin_ia32_selectq_128:
15784 case X86::BI__builtin_ia32_selectq_256:
15785 case X86::BI__builtin_ia32_selectq_512:
15786 case X86::BI__builtin_ia32_selectph_128:
15787 case X86::BI__builtin_ia32_selectph_256:
15788 case X86::BI__builtin_ia32_selectph_512:
15789 case X86::BI__builtin_ia32_selectpbf_128:
15790 case X86::BI__builtin_ia32_selectpbf_256:
15791 case X86::BI__builtin_ia32_selectpbf_512:
15792 case X86::BI__builtin_ia32_selectps_128:
15793 case X86::BI__builtin_ia32_selectps_256:
15794 case X86::BI__builtin_ia32_selectps_512:
15795 case X86::BI__builtin_ia32_selectpd_128:
15796 case X86::BI__builtin_ia32_selectpd_256:
15797 case X86::BI__builtin_ia32_selectpd_512:
15799 case X86::BI__builtin_ia32_selectsh_128:
15800 case X86::BI__builtin_ia32_selectsbf_128:
15801 case X86::BI__builtin_ia32_selectss_128:
15802 case X86::BI__builtin_ia32_selectsd_128: {
15803 Value *A =
Builder.CreateExtractElement(Ops[1], (uint64_t)0);
15804 Value *B =
Builder.CreateExtractElement(Ops[2], (uint64_t)0);
15806 return Builder.CreateInsertElement(Ops[1], A, (uint64_t)0);
15808 case X86::BI__builtin_ia32_cmpb128_mask:
15809 case X86::BI__builtin_ia32_cmpb256_mask:
15810 case X86::BI__builtin_ia32_cmpb512_mask:
15811 case X86::BI__builtin_ia32_cmpw128_mask:
15812 case X86::BI__builtin_ia32_cmpw256_mask:
15813 case X86::BI__builtin_ia32_cmpw512_mask:
15814 case X86::BI__builtin_ia32_cmpd128_mask:
15815 case X86::BI__builtin_ia32_cmpd256_mask:
15816 case X86::BI__builtin_ia32_cmpd512_mask:
15817 case X86::BI__builtin_ia32_cmpq128_mask:
15818 case X86::BI__builtin_ia32_cmpq256_mask:
15819 case X86::BI__builtin_ia32_cmpq512_mask: {
15820 unsigned CC = cast<llvm::ConstantInt>(Ops[2])->getZExtValue() & 0x7;
15823 case X86::BI__builtin_ia32_ucmpb128_mask:
15824 case X86::BI__builtin_ia32_ucmpb256_mask:
15825 case X86::BI__builtin_ia32_ucmpb512_mask:
15826 case X86::BI__builtin_ia32_ucmpw128_mask:
15827 case X86::BI__builtin_ia32_ucmpw256_mask:
15828 case X86::BI__builtin_ia32_ucmpw512_mask:
15829 case X86::BI__builtin_ia32_ucmpd128_mask:
15830 case X86::BI__builtin_ia32_ucmpd256_mask:
15831 case X86::BI__builtin_ia32_ucmpd512_mask:
15832 case X86::BI__builtin_ia32_ucmpq128_mask:
15833 case X86::BI__builtin_ia32_ucmpq256_mask:
15834 case X86::BI__builtin_ia32_ucmpq512_mask: {
15835 unsigned CC = cast<llvm::ConstantInt>(Ops[2])->getZExtValue() & 0x7;
15838 case X86::BI__builtin_ia32_vpcomb:
15839 case X86::BI__builtin_ia32_vpcomw:
15840 case X86::BI__builtin_ia32_vpcomd:
15841 case X86::BI__builtin_ia32_vpcomq:
15843 case X86::BI__builtin_ia32_vpcomub:
15844 case X86::BI__builtin_ia32_vpcomuw:
15845 case X86::BI__builtin_ia32_vpcomud:
15846 case X86::BI__builtin_ia32_vpcomuq:
15849 case X86::BI__builtin_ia32_kortestcqi:
15850 case X86::BI__builtin_ia32_kortestchi:
15851 case X86::BI__builtin_ia32_kortestcsi:
15852 case X86::BI__builtin_ia32_kortestcdi: {
15854 Value *
C = llvm::Constant::getAllOnesValue(Ops[0]->getType());
15858 case X86::BI__builtin_ia32_kortestzqi:
15859 case X86::BI__builtin_ia32_kortestzhi:
15860 case X86::BI__builtin_ia32_kortestzsi:
15861 case X86::BI__builtin_ia32_kortestzdi: {
15863 Value *
C = llvm::Constant::getNullValue(Ops[0]->getType());
15868 case X86::BI__builtin_ia32_ktestcqi:
15869 case X86::BI__builtin_ia32_ktestzqi:
15870 case X86::BI__builtin_ia32_ktestchi:
15871 case X86::BI__builtin_ia32_ktestzhi:
15872 case X86::BI__builtin_ia32_ktestcsi:
15873 case X86::BI__builtin_ia32_ktestzsi:
15874 case X86::BI__builtin_ia32_ktestcdi:
15875 case X86::BI__builtin_ia32_ktestzdi: {
15877 switch (BuiltinID) {
15878 default: llvm_unreachable(
"Unsupported intrinsic!");
15879 case X86::BI__builtin_ia32_ktestcqi:
15880 IID = Intrinsic::x86_avx512_ktestc_b;
15882 case X86::BI__builtin_ia32_ktestzqi:
15883 IID = Intrinsic::x86_avx512_ktestz_b;
15885 case X86::BI__builtin_ia32_ktestchi:
15886 IID = Intrinsic::x86_avx512_ktestc_w;
15888 case X86::BI__builtin_ia32_ktestzhi:
15889 IID = Intrinsic::x86_avx512_ktestz_w;
15891 case X86::BI__builtin_ia32_ktestcsi:
15892 IID = Intrinsic::x86_avx512_ktestc_d;
15894 case X86::BI__builtin_ia32_ktestzsi:
15895 IID = Intrinsic::x86_avx512_ktestz_d;
15897 case X86::BI__builtin_ia32_ktestcdi:
15898 IID = Intrinsic::x86_avx512_ktestc_q;
15900 case X86::BI__builtin_ia32_ktestzdi:
15901 IID = Intrinsic::x86_avx512_ktestz_q;
15905 unsigned NumElts = Ops[0]->getType()->getIntegerBitWidth();
15909 return Builder.CreateCall(Intr, {LHS, RHS});
15912 case X86::BI__builtin_ia32_kaddqi:
15913 case X86::BI__builtin_ia32_kaddhi:
15914 case X86::BI__builtin_ia32_kaddsi:
15915 case X86::BI__builtin_ia32_kadddi: {
15917 switch (BuiltinID) {
15918 default: llvm_unreachable(
"Unsupported intrinsic!");
15919 case X86::BI__builtin_ia32_kaddqi:
15920 IID = Intrinsic::x86_avx512_kadd_b;
15922 case X86::BI__builtin_ia32_kaddhi:
15923 IID = Intrinsic::x86_avx512_kadd_w;
15925 case X86::BI__builtin_ia32_kaddsi:
15926 IID = Intrinsic::x86_avx512_kadd_d;
15928 case X86::BI__builtin_ia32_kadddi:
15929 IID = Intrinsic::x86_avx512_kadd_q;
15933 unsigned NumElts = Ops[0]->getType()->getIntegerBitWidth();
15938 return Builder.CreateBitCast(Res, Ops[0]->getType());
15940 case X86::BI__builtin_ia32_kandqi:
15941 case X86::BI__builtin_ia32_kandhi:
15942 case X86::BI__builtin_ia32_kandsi:
15943 case X86::BI__builtin_ia32_kanddi:
15945 case X86::BI__builtin_ia32_kandnqi:
15946 case X86::BI__builtin_ia32_kandnhi:
15947 case X86::BI__builtin_ia32_kandnsi:
15948 case X86::BI__builtin_ia32_kandndi:
15950 case X86::BI__builtin_ia32_korqi:
15951 case X86::BI__builtin_ia32_korhi:
15952 case X86::BI__builtin_ia32_korsi:
15953 case X86::BI__builtin_ia32_kordi:
15955 case X86::BI__builtin_ia32_kxnorqi:
15956 case X86::BI__builtin_ia32_kxnorhi:
15957 case X86::BI__builtin_ia32_kxnorsi:
15958 case X86::BI__builtin_ia32_kxnordi:
15960 case X86::BI__builtin_ia32_kxorqi:
15961 case X86::BI__builtin_ia32_kxorhi:
15962 case X86::BI__builtin_ia32_kxorsi:
15963 case X86::BI__builtin_ia32_kxordi:
15965 case X86::BI__builtin_ia32_knotqi:
15966 case X86::BI__builtin_ia32_knothi:
15967 case X86::BI__builtin_ia32_knotsi:
15968 case X86::BI__builtin_ia32_knotdi: {
15969 unsigned NumElts = Ops[0]->getType()->getIntegerBitWidth();
15972 Ops[0]->getType());
15974 case X86::BI__builtin_ia32_kmovb:
15975 case X86::BI__builtin_ia32_kmovw:
15976 case X86::BI__builtin_ia32_kmovd:
15977 case X86::BI__builtin_ia32_kmovq: {
15981 unsigned NumElts = Ops[0]->getType()->getIntegerBitWidth();
15983 return Builder.CreateBitCast(Res, Ops[0]->getType());
15986 case X86::BI__builtin_ia32_kunpckdi:
15987 case X86::BI__builtin_ia32_kunpcksi:
15988 case X86::BI__builtin_ia32_kunpckhi: {
15989 unsigned NumElts = Ops[0]->getType()->getIntegerBitWidth();
15993 for (
unsigned i = 0; i != NumElts; ++i)
15998 LHS =
Builder.CreateShuffleVector(LHS, LHS,
ArrayRef(Indices, NumElts / 2));
15999 RHS =
Builder.CreateShuffleVector(RHS, RHS,
ArrayRef(Indices, NumElts / 2));
16004 return Builder.CreateBitCast(Res, Ops[0]->getType());
16007 case X86::BI__builtin_ia32_vplzcntd_128:
16008 case X86::BI__builtin_ia32_vplzcntd_256:
16009 case X86::BI__builtin_ia32_vplzcntd_512:
16010 case X86::BI__builtin_ia32_vplzcntq_128:
16011 case X86::BI__builtin_ia32_vplzcntq_256:
16012 case X86::BI__builtin_ia32_vplzcntq_512: {
16016 case X86::BI__builtin_ia32_sqrtss:
16017 case X86::BI__builtin_ia32_sqrtsd: {
16018 Value *A =
Builder.CreateExtractElement(Ops[0], (uint64_t)0);
16020 if (
Builder.getIsFPConstrained()) {
16021 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*
this,
E);
16024 A =
Builder.CreateConstrainedFPCall(F, {A});
16027 A =
Builder.CreateCall(F, {A});
16029 return Builder.CreateInsertElement(Ops[0], A, (uint64_t)0);
16031 case X86::BI__builtin_ia32_sqrtsh_round_mask:
16032 case X86::BI__builtin_ia32_sqrtsd_round_mask:
16033 case X86::BI__builtin_ia32_sqrtss_round_mask: {
16034 unsigned CC = cast<llvm::ConstantInt>(Ops[4])->getZExtValue();
16040 switch (BuiltinID) {
16042 llvm_unreachable(
"Unsupported intrinsic!");
16043 case X86::BI__builtin_ia32_sqrtsh_round_mask:
16044 IID = Intrinsic::x86_avx512fp16_mask_sqrt_sh;
16046 case X86::BI__builtin_ia32_sqrtsd_round_mask:
16047 IID = Intrinsic::x86_avx512_mask_sqrt_sd;
16049 case X86::BI__builtin_ia32_sqrtss_round_mask:
16050 IID = Intrinsic::x86_avx512_mask_sqrt_ss;
16055 Value *A =
Builder.CreateExtractElement(Ops[1], (uint64_t)0);
16057 if (
Builder.getIsFPConstrained()) {
16058 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*
this,
E);
16061 A =
Builder.CreateConstrainedFPCall(F, A);
16064 A =
Builder.CreateCall(F, A);
16066 Value *Src =
Builder.CreateExtractElement(Ops[2], (uint64_t)0);
16068 return Builder.CreateInsertElement(Ops[0], A, (uint64_t)0);
16070 case X86::BI__builtin_ia32_sqrtpd256:
16071 case X86::BI__builtin_ia32_sqrtpd:
16072 case X86::BI__builtin_ia32_sqrtps256:
16073 case X86::BI__builtin_ia32_sqrtps:
16074 case X86::BI__builtin_ia32_sqrtph256:
16075 case X86::BI__builtin_ia32_sqrtph:
16076 case X86::BI__builtin_ia32_sqrtph512:
16077 case X86::BI__builtin_ia32_sqrtps512:
16078 case X86::BI__builtin_ia32_sqrtpd512: {
16079 if (Ops.size() == 2) {
16080 unsigned CC = cast<llvm::ConstantInt>(Ops[1])->getZExtValue();
16086 switch (BuiltinID) {
16088 llvm_unreachable(
"Unsupported intrinsic!");
16089 case X86::BI__builtin_ia32_sqrtph512:
16090 IID = Intrinsic::x86_avx512fp16_sqrt_ph_512;
16092 case X86::BI__builtin_ia32_sqrtps512:
16093 IID = Intrinsic::x86_avx512_sqrt_ps_512;
16095 case X86::BI__builtin_ia32_sqrtpd512:
16096 IID = Intrinsic::x86_avx512_sqrt_pd_512;
16102 if (
Builder.getIsFPConstrained()) {
16103 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*
this,
E);
16105 Ops[0]->getType());
16106 return Builder.CreateConstrainedFPCall(F, Ops[0]);
16109 return Builder.CreateCall(F, Ops[0]);
16113 case X86::BI__builtin_ia32_pmuludq128:
16114 case X86::BI__builtin_ia32_pmuludq256:
16115 case X86::BI__builtin_ia32_pmuludq512:
16118 case X86::BI__builtin_ia32_pmuldq128:
16119 case X86::BI__builtin_ia32_pmuldq256:
16120 case X86::BI__builtin_ia32_pmuldq512:
16123 case X86::BI__builtin_ia32_pternlogd512_mask:
16124 case X86::BI__builtin_ia32_pternlogq512_mask:
16125 case X86::BI__builtin_ia32_pternlogd128_mask:
16126 case X86::BI__builtin_ia32_pternlogd256_mask:
16127 case X86::BI__builtin_ia32_pternlogq128_mask:
16128 case X86::BI__builtin_ia32_pternlogq256_mask:
16131 case X86::BI__builtin_ia32_pternlogd512_maskz:
16132 case X86::BI__builtin_ia32_pternlogq512_maskz:
16133 case X86::BI__builtin_ia32_pternlogd128_maskz:
16134 case X86::BI__builtin_ia32_pternlogd256_maskz:
16135 case X86::BI__builtin_ia32_pternlogq128_maskz:
16136 case X86::BI__builtin_ia32_pternlogq256_maskz:
16139 case X86::BI__builtin_ia32_vpshldd128:
16140 case X86::BI__builtin_ia32_vpshldd256:
16141 case X86::BI__builtin_ia32_vpshldd512:
16142 case X86::BI__builtin_ia32_vpshldq128:
16143 case X86::BI__builtin_ia32_vpshldq256:
16144 case X86::BI__builtin_ia32_vpshldq512:
16145 case X86::BI__builtin_ia32_vpshldw128:
16146 case X86::BI__builtin_ia32_vpshldw256:
16147 case X86::BI__builtin_ia32_vpshldw512:
16150 case X86::BI__builtin_ia32_vpshrdd128:
16151 case X86::BI__builtin_ia32_vpshrdd256:
16152 case X86::BI__builtin_ia32_vpshrdd512:
16153 case X86::BI__builtin_ia32_vpshrdq128:
16154 case X86::BI__builtin_ia32_vpshrdq256:
16155 case X86::BI__builtin_ia32_vpshrdq512:
16156 case X86::BI__builtin_ia32_vpshrdw128:
16157 case X86::BI__builtin_ia32_vpshrdw256:
16158 case X86::BI__builtin_ia32_vpshrdw512:
16162 case X86::BI__builtin_ia32_vpshldvd128:
16163 case X86::BI__builtin_ia32_vpshldvd256:
16164 case X86::BI__builtin_ia32_vpshldvd512:
16165 case X86::BI__builtin_ia32_vpshldvq128:
16166 case X86::BI__builtin_ia32_vpshldvq256:
16167 case X86::BI__builtin_ia32_vpshldvq512:
16168 case X86::BI__builtin_ia32_vpshldvw128:
16169 case X86::BI__builtin_ia32_vpshldvw256:
16170 case X86::BI__builtin_ia32_vpshldvw512:
16173 case X86::BI__builtin_ia32_vpshrdvd128:
16174 case X86::BI__builtin_ia32_vpshrdvd256:
16175 case X86::BI__builtin_ia32_vpshrdvd512:
16176 case X86::BI__builtin_ia32_vpshrdvq128:
16177 case X86::BI__builtin_ia32_vpshrdvq256:
16178 case X86::BI__builtin_ia32_vpshrdvq512:
16179 case X86::BI__builtin_ia32_vpshrdvw128:
16180 case X86::BI__builtin_ia32_vpshrdvw256:
16181 case X86::BI__builtin_ia32_vpshrdvw512:
16186 case X86::BI__builtin_ia32_reduce_fadd_pd512:
16187 case X86::BI__builtin_ia32_reduce_fadd_ps512:
16188 case X86::BI__builtin_ia32_reduce_fadd_ph512:
16189 case X86::BI__builtin_ia32_reduce_fadd_ph256:
16190 case X86::BI__builtin_ia32_reduce_fadd_ph128: {
16193 IRBuilder<>::FastMathFlagGuard FMFGuard(
Builder);
16194 Builder.getFastMathFlags().setAllowReassoc();
16195 return Builder.CreateCall(F, {Ops[0], Ops[1]});
16197 case X86::BI__builtin_ia32_reduce_fmul_pd512:
16198 case X86::BI__builtin_ia32_reduce_fmul_ps512:
16199 case X86::BI__builtin_ia32_reduce_fmul_ph512:
16200 case X86::BI__builtin_ia32_reduce_fmul_ph256:
16201 case X86::BI__builtin_ia32_reduce_fmul_ph128: {
16204 IRBuilder<>::FastMathFlagGuard FMFGuard(
Builder);
16205 Builder.getFastMathFlags().setAllowReassoc();
16206 return Builder.CreateCall(F, {Ops[0], Ops[1]});
16208 case X86::BI__builtin_ia32_reduce_fmax_pd512:
16209 case X86::BI__builtin_ia32_reduce_fmax_ps512:
16210 case X86::BI__builtin_ia32_reduce_fmax_ph512:
16211 case X86::BI__builtin_ia32_reduce_fmax_ph256:
16212 case X86::BI__builtin_ia32_reduce_fmax_ph128: {
16215 IRBuilder<>::FastMathFlagGuard FMFGuard(
Builder);
16216 Builder.getFastMathFlags().setNoNaNs();
16217 return Builder.CreateCall(F, {Ops[0]});
16219 case X86::BI__builtin_ia32_reduce_fmin_pd512:
16220 case X86::BI__builtin_ia32_reduce_fmin_ps512:
16221 case X86::BI__builtin_ia32_reduce_fmin_ph512:
16222 case X86::BI__builtin_ia32_reduce_fmin_ph256:
16223 case X86::BI__builtin_ia32_reduce_fmin_ph128: {
16226 IRBuilder<>::FastMathFlagGuard FMFGuard(
Builder);
16227 Builder.getFastMathFlags().setNoNaNs();
16228 return Builder.CreateCall(F, {Ops[0]});
16231 case X86::BI__builtin_ia32_rdrand16_step:
16232 case X86::BI__builtin_ia32_rdrand32_step:
16233 case X86::BI__builtin_ia32_rdrand64_step:
16234 case X86::BI__builtin_ia32_rdseed16_step:
16235 case X86::BI__builtin_ia32_rdseed32_step:
16236 case X86::BI__builtin_ia32_rdseed64_step: {
16238 switch (BuiltinID) {
16239 default: llvm_unreachable(
"Unsupported intrinsic!");
16240 case X86::BI__builtin_ia32_rdrand16_step:
16241 ID = Intrinsic::x86_rdrand_16;
16243 case X86::BI__builtin_ia32_rdrand32_step:
16244 ID = Intrinsic::x86_rdrand_32;
16246 case X86::BI__builtin_ia32_rdrand64_step:
16247 ID = Intrinsic::x86_rdrand_64;
16249 case X86::BI__builtin_ia32_rdseed16_step:
16250 ID = Intrinsic::x86_rdseed_16;
16252 case X86::BI__builtin_ia32_rdseed32_step:
16253 ID = Intrinsic::x86_rdseed_32;
16255 case X86::BI__builtin_ia32_rdseed64_step:
16256 ID = Intrinsic::x86_rdseed_64;
16265 case X86::BI__builtin_ia32_addcarryx_u32:
16266 case X86::BI__builtin_ia32_addcarryx_u64:
16267 case X86::BI__builtin_ia32_subborrow_u32:
16268 case X86::BI__builtin_ia32_subborrow_u64: {
16270 switch (BuiltinID) {
16271 default: llvm_unreachable(
"Unsupported intrinsic!");
16272 case X86::BI__builtin_ia32_addcarryx_u32:
16273 IID = Intrinsic::x86_addcarry_32;
16275 case X86::BI__builtin_ia32_addcarryx_u64:
16276 IID = Intrinsic::x86_addcarry_64;
16278 case X86::BI__builtin_ia32_subborrow_u32:
16279 IID = Intrinsic::x86_subborrow_32;
16281 case X86::BI__builtin_ia32_subborrow_u64:
16282 IID = Intrinsic::x86_subborrow_64;
16287 { Ops[0], Ops[1], Ops[2] });
16293 case X86::BI__builtin_ia32_fpclassps128_mask:
16294 case X86::BI__builtin_ia32_fpclassps256_mask:
16295 case X86::BI__builtin_ia32_fpclassps512_mask:
16296 case X86::BI__builtin_ia32_fpclassph128_mask:
16297 case X86::BI__builtin_ia32_fpclassph256_mask:
16298 case X86::BI__builtin_ia32_fpclassph512_mask:
16299 case X86::BI__builtin_ia32_fpclasspd128_mask:
16300 case X86::BI__builtin_ia32_fpclasspd256_mask:
16301 case X86::BI__builtin_ia32_fpclasspd512_mask: {
16303 cast<llvm::FixedVectorType>(Ops[0]->getType())->getNumElements();
16304 Value *MaskIn = Ops[2];
16305 Ops.erase(&Ops[2]);
16308 switch (BuiltinID) {
16309 default: llvm_unreachable(
"Unsupported intrinsic!");
16310 case X86::BI__builtin_ia32_fpclassph128_mask:
16311 ID = Intrinsic::x86_avx512fp16_fpclass_ph_128;
16313 case X86::BI__builtin_ia32_fpclassph256_mask:
16314 ID = Intrinsic::x86_avx512fp16_fpclass_ph_256;
16316 case X86::BI__builtin_ia32_fpclassph512_mask:
16317 ID = Intrinsic::x86_avx512fp16_fpclass_ph_512;
16319 case X86::BI__builtin_ia32_fpclassps128_mask:
16320 ID = Intrinsic::x86_avx512_fpclass_ps_128;
16322 case X86::BI__builtin_ia32_fpclassps256_mask:
16323 ID = Intrinsic::x86_avx512_fpclass_ps_256;
16325 case X86::BI__builtin_ia32_fpclassps512_mask:
16326 ID = Intrinsic::x86_avx512_fpclass_ps_512;
16328 case X86::BI__builtin_ia32_fpclasspd128_mask:
16329 ID = Intrinsic::x86_avx512_fpclass_pd_128;
16331 case X86::BI__builtin_ia32_fpclasspd256_mask:
16332 ID = Intrinsic::x86_avx512_fpclass_pd_256;
16334 case X86::BI__builtin_ia32_fpclasspd512_mask:
16335 ID = Intrinsic::x86_avx512_fpclass_pd_512;
16343 case X86::BI__builtin_ia32_vp2intersect_q_512:
16344 case X86::BI__builtin_ia32_vp2intersect_q_256:
16345 case X86::BI__builtin_ia32_vp2intersect_q_128:
16346 case X86::BI__builtin_ia32_vp2intersect_d_512:
16347 case X86::BI__builtin_ia32_vp2intersect_d_256:
16348 case X86::BI__builtin_ia32_vp2intersect_d_128: {
16350 cast<llvm::FixedVectorType>(Ops[0]->getType())->getNumElements();
16353 switch (BuiltinID) {
16354 default: llvm_unreachable(
"Unsupported intrinsic!");
16355 case X86::BI__builtin_ia32_vp2intersect_q_512:
16356 ID = Intrinsic::x86_avx512_vp2intersect_q_512;
16358 case X86::BI__builtin_ia32_vp2intersect_q_256:
16359 ID = Intrinsic::x86_avx512_vp2intersect_q_256;
16361 case X86::BI__builtin_ia32_vp2intersect_q_128:
16362 ID = Intrinsic::x86_avx512_vp2intersect_q_128;
16364 case X86::BI__builtin_ia32_vp2intersect_d_512:
16365 ID = Intrinsic::x86_avx512_vp2intersect_d_512;
16367 case X86::BI__builtin_ia32_vp2intersect_d_256:
16368 ID = Intrinsic::x86_avx512_vp2intersect_d_256;
16370 case X86::BI__builtin_ia32_vp2intersect_d_128:
16371 ID = Intrinsic::x86_avx512_vp2intersect_d_128;
16385 case X86::BI__builtin_ia32_vpmultishiftqb128:
16386 case X86::BI__builtin_ia32_vpmultishiftqb256:
16387 case X86::BI__builtin_ia32_vpmultishiftqb512: {
16389 switch (BuiltinID) {
16390 default: llvm_unreachable(
"Unsupported intrinsic!");
16391 case X86::BI__builtin_ia32_vpmultishiftqb128:
16392 ID = Intrinsic::x86_avx512_pmultishift_qb_128;
16394 case X86::BI__builtin_ia32_vpmultishiftqb256:
16395 ID = Intrinsic::x86_avx512_pmultishift_qb_256;
16397 case X86::BI__builtin_ia32_vpmultishiftqb512:
16398 ID = Intrinsic::x86_avx512_pmultishift_qb_512;
16405 case X86::BI__builtin_ia32_vpshufbitqmb128_mask:
16406 case X86::BI__builtin_ia32_vpshufbitqmb256_mask:
16407 case X86::BI__builtin_ia32_vpshufbitqmb512_mask: {
16409 cast<llvm::FixedVectorType>(Ops[0]->getType())->getNumElements();
16410 Value *MaskIn = Ops[2];
16411 Ops.erase(&Ops[2]);
16414 switch (BuiltinID) {
16415 default: llvm_unreachable(
"Unsupported intrinsic!");
16416 case X86::BI__builtin_ia32_vpshufbitqmb128_mask:
16417 ID = Intrinsic::x86_avx512_vpshufbitqmb_128;
16419 case X86::BI__builtin_ia32_vpshufbitqmb256_mask:
16420 ID = Intrinsic::x86_avx512_vpshufbitqmb_256;
16422 case X86::BI__builtin_ia32_vpshufbitqmb512_mask:
16423 ID = Intrinsic::x86_avx512_vpshufbitqmb_512;
16432 case X86::BI__builtin_ia32_cmpeqps:
16433 case X86::BI__builtin_ia32_cmpeqpd:
16434 return getVectorFCmpIR(CmpInst::FCMP_OEQ,
false);
16435 case X86::BI__builtin_ia32_cmpltps:
16436 case X86::BI__builtin_ia32_cmpltpd:
16437 return getVectorFCmpIR(CmpInst::FCMP_OLT,
true);
16438 case X86::BI__builtin_ia32_cmpleps:
16439 case X86::BI__builtin_ia32_cmplepd:
16440 return getVectorFCmpIR(CmpInst::FCMP_OLE,
true);
16441 case X86::BI__builtin_ia32_cmpunordps:
16442 case X86::BI__builtin_ia32_cmpunordpd:
16443 return getVectorFCmpIR(CmpInst::FCMP_UNO,
false);
16444 case X86::BI__builtin_ia32_cmpneqps:
16445 case X86::BI__builtin_ia32_cmpneqpd:
16446 return getVectorFCmpIR(CmpInst::FCMP_UNE,
false);
16447 case X86::BI__builtin_ia32_cmpnltps:
16448 case X86::BI__builtin_ia32_cmpnltpd:
16449 return getVectorFCmpIR(CmpInst::FCMP_UGE,
true);
16450 case X86::BI__builtin_ia32_cmpnleps:
16451 case X86::BI__builtin_ia32_cmpnlepd:
16452 return getVectorFCmpIR(CmpInst::FCMP_UGT,
true);
16453 case X86::BI__builtin_ia32_cmpordps:
16454 case X86::BI__builtin_ia32_cmpordpd:
16455 return getVectorFCmpIR(CmpInst::FCMP_ORD,
false);
16456 case X86::BI__builtin_ia32_cmpph128_mask:
16457 case X86::BI__builtin_ia32_cmpph256_mask:
16458 case X86::BI__builtin_ia32_cmpph512_mask:
16459 case X86::BI__builtin_ia32_cmpps128_mask:
16460 case X86::BI__builtin_ia32_cmpps256_mask:
16461 case X86::BI__builtin_ia32_cmpps512_mask:
16462 case X86::BI__builtin_ia32_cmppd128_mask:
16463 case X86::BI__builtin_ia32_cmppd256_mask:
16464 case X86::BI__builtin_ia32_cmppd512_mask:
16465 case X86::BI__builtin_ia32_vcmppd256_round_mask:
16466 case X86::BI__builtin_ia32_vcmpps256_round_mask:
16467 case X86::BI__builtin_ia32_vcmpph256_round_mask:
16470 case X86::BI__builtin_ia32_cmpps:
16471 case X86::BI__builtin_ia32_cmpps256:
16472 case X86::BI__builtin_ia32_cmppd:
16473 case X86::BI__builtin_ia32_cmppd256: {
16481 unsigned CC = cast<llvm::ConstantInt>(Ops[2])->getZExtValue() & 0x1f;
16486 FCmpInst::Predicate Pred;
16490 switch (CC & 0xf) {
16491 case 0x00: Pred = FCmpInst::FCMP_OEQ; IsSignaling =
false;
break;
16492 case 0x01: Pred = FCmpInst::FCMP_OLT; IsSignaling =
true;
break;
16493 case 0x02: Pred = FCmpInst::FCMP_OLE; IsSignaling =
true;
break;
16494 case 0x03: Pred = FCmpInst::FCMP_UNO; IsSignaling =
false;
break;
16495 case 0x04: Pred = FCmpInst::FCMP_UNE; IsSignaling =
false;
break;
16496 case 0x05: Pred = FCmpInst::FCMP_UGE; IsSignaling =
true;
break;
16497 case 0x06: Pred = FCmpInst::FCMP_UGT; IsSignaling =
true;
break;
16498 case 0x07: Pred = FCmpInst::FCMP_ORD; IsSignaling =
false;
break;
16499 case 0x08: Pred = FCmpInst::FCMP_UEQ; IsSignaling =
false;
break;
16500 case 0x09: Pred = FCmpInst::FCMP_ULT; IsSignaling =
true;
break;
16501 case 0x0a: Pred = FCmpInst::FCMP_ULE; IsSignaling =
true;
break;
16502 case 0x0b: Pred = FCmpInst::FCMP_FALSE; IsSignaling =
false;
break;
16503 case 0x0c: Pred = FCmpInst::FCMP_ONE; IsSignaling =
false;
break;
16504 case 0x0d: Pred = FCmpInst::FCMP_OGE; IsSignaling =
true;
break;
16505 case 0x0e: Pred = FCmpInst::FCMP_OGT; IsSignaling =
true;
break;
16506 case 0x0f: Pred = FCmpInst::FCMP_TRUE; IsSignaling =
false;
break;
16507 default: llvm_unreachable(
"Unhandled CC");
16512 IsSignaling = !IsSignaling;
16519 if (
Builder.getIsFPConstrained() &&
16520 (Pred == FCmpInst::FCMP_TRUE || Pred == FCmpInst::FCMP_FALSE ||
16524 switch (BuiltinID) {
16525 default: llvm_unreachable(
"Unexpected builtin");
16526 case X86::BI__builtin_ia32_cmpps:
16527 IID = Intrinsic::x86_sse_cmp_ps;
16529 case X86::BI__builtin_ia32_cmpps256:
16530 IID = Intrinsic::x86_avx_cmp_ps_256;
16532 case X86::BI__builtin_ia32_cmppd:
16533 IID = Intrinsic::x86_sse2_cmp_pd;
16535 case X86::BI__builtin_ia32_cmppd256:
16536 IID = Intrinsic::x86_avx_cmp_pd_256;
16538 case X86::BI__builtin_ia32_cmpph128_mask:
16539 IID = Intrinsic::x86_avx512fp16_mask_cmp_ph_128;
16541 case X86::BI__builtin_ia32_cmpph256_mask:
16542 IID = Intrinsic::x86_avx512fp16_mask_cmp_ph_256;
16544 case X86::BI__builtin_ia32_cmpph512_mask:
16545 IID = Intrinsic::x86_avx512fp16_mask_cmp_ph_512;
16547 case X86::BI__builtin_ia32_cmpps512_mask:
16548 IID = Intrinsic::x86_avx512_mask_cmp_ps_512;
16550 case X86::BI__builtin_ia32_cmppd512_mask:
16551 IID = Intrinsic::x86_avx512_mask_cmp_pd_512;
16553 case X86::BI__builtin_ia32_cmpps128_mask:
16554 IID = Intrinsic::x86_avx512_mask_cmp_ps_128;
16556 case X86::BI__builtin_ia32_cmpps256_mask:
16557 IID = Intrinsic::x86_avx512_mask_cmp_ps_256;
16559 case X86::BI__builtin_ia32_cmppd128_mask:
16560 IID = Intrinsic::x86_avx512_mask_cmp_pd_128;
16562 case X86::BI__builtin_ia32_cmppd256_mask:
16563 IID = Intrinsic::x86_avx512_mask_cmp_pd_256;
16570 cast<llvm::FixedVectorType>(Ops[0]->getType())->getNumElements();
16576 return Builder.CreateCall(Intr, Ops);
16587 cast<llvm::FixedVectorType>(Ops[0]->getType())->getNumElements();
16590 Cmp =
Builder.CreateFCmpS(Pred, Ops[0], Ops[1]);
16592 Cmp =
Builder.CreateFCmp(Pred, Ops[0], Ops[1]);
16596 return getVectorFCmpIR(Pred, IsSignaling);
16600 case X86::BI__builtin_ia32_cmpeqss:
16601 return getCmpIntrinsicCall(Intrinsic::x86_sse_cmp_ss, 0);
16602 case X86::BI__builtin_ia32_cmpltss:
16603 return getCmpIntrinsicCall(Intrinsic::x86_sse_cmp_ss, 1);
16604 case X86::BI__builtin_ia32_cmpless:
16605 return getCmpIntrinsicCall(Intrinsic::x86_sse_cmp_ss, 2);
16606 case X86::BI__builtin_ia32_cmpunordss:
16607 return getCmpIntrinsicCall(Intrinsic::x86_sse_cmp_ss, 3);
16608 case X86::BI__builtin_ia32_cmpneqss:
16609 return getCmpIntrinsicCall(Intrinsic::x86_sse_cmp_ss, 4);
16610 case X86::BI__builtin_ia32_cmpnltss:
16611 return getCmpIntrinsicCall(Intrinsic::x86_sse_cmp_ss, 5);
16612 case X86::BI__builtin_ia32_cmpnless:
16613 return getCmpIntrinsicCall(Intrinsic::x86_sse_cmp_ss, 6);
16614 case X86::BI__builtin_ia32_cmpordss:
16615 return getCmpIntrinsicCall(Intrinsic::x86_sse_cmp_ss, 7);
16616 case X86::BI__builtin_ia32_cmpeqsd:
16617 return getCmpIntrinsicCall(Intrinsic::x86_sse2_cmp_sd, 0);
16618 case X86::BI__builtin_ia32_cmpltsd:
16619 return getCmpIntrinsicCall(Intrinsic::x86_sse2_cmp_sd, 1);
16620 case X86::BI__builtin_ia32_cmplesd:
16621 return getCmpIntrinsicCall(Intrinsic::x86_sse2_cmp_sd, 2);
16622 case X86::BI__builtin_ia32_cmpunordsd:
16623 return getCmpIntrinsicCall(Intrinsic::x86_sse2_cmp_sd, 3);
16624 case X86::BI__builtin_ia32_cmpneqsd:
16625 return getCmpIntrinsicCall(Intrinsic::x86_sse2_cmp_sd, 4);
16626 case X86::BI__builtin_ia32_cmpnltsd:
16627 return getCmpIntrinsicCall(Intrinsic::x86_sse2_cmp_sd, 5);
16628 case X86::BI__builtin_ia32_cmpnlesd:
16629 return getCmpIntrinsicCall(Intrinsic::x86_sse2_cmp_sd, 6);
16630 case X86::BI__builtin_ia32_cmpordsd:
16631 return getCmpIntrinsicCall(Intrinsic::x86_sse2_cmp_sd, 7);
16634 case X86::BI__builtin_ia32_vcvtph2ps:
16635 case X86::BI__builtin_ia32_vcvtph2ps256:
16636 case X86::BI__builtin_ia32_vcvtph2ps_mask:
16637 case X86::BI__builtin_ia32_vcvtph2ps256_mask:
16638 case X86::BI__builtin_ia32_vcvtph2ps512_mask: {
16639 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*
this,
E);
16644 case X86::BI__builtin_ia32_cvtneps2bf16_128_mask: {
16647 cast<llvm::FixedVectorType>(Ops[0]->getType())->getNumElements());
16648 Intrinsic::ID IID = Intrinsic::x86_avx512bf16_mask_cvtneps2bf16_128;
16651 case X86::BI__builtin_ia32_cvtsbf162ss_32:
16654 case X86::BI__builtin_ia32_cvtneps2bf16_256_mask:
16655 case X86::BI__builtin_ia32_cvtneps2bf16_512_mask: {
16657 switch (BuiltinID) {
16658 default: llvm_unreachable(
"Unsupported intrinsic!");
16659 case X86::BI__builtin_ia32_cvtneps2bf16_256_mask:
16660 IID = Intrinsic::x86_avx512bf16_cvtneps2bf16_256;
16662 case X86::BI__builtin_ia32_cvtneps2bf16_512_mask:
16663 IID = Intrinsic::x86_avx512bf16_cvtneps2bf16_512;
16670 case X86::BI__cpuid:
16671 case X86::BI__cpuidex: {
16673 Value *SubFuncId = BuiltinID == X86::BI__cpuidex
16677 llvm::StructType *CpuidRetTy =
16679 llvm::FunctionType *FTy =
16682 StringRef
Asm, Constraints;
16683 if (
getTarget().getTriple().getArch() == llvm::Triple::x86) {
16685 Constraints =
"={ax},={bx},={cx},={dx},{ax},{cx}";
16688 Asm =
"xchgq %rbx, ${1:q}\n"
16690 "xchgq %rbx, ${1:q}";
16691 Constraints =
"={ax},=r,={cx},={dx},0,2";
16694 llvm::InlineAsm *IA = llvm::InlineAsm::get(FTy,
Asm, Constraints,
16696 Value *IACall =
Builder.CreateCall(IA, {FuncId, SubFuncId});
16699 for (
unsigned i = 0; i < 4; i++) {
16700 Value *Extracted =
Builder.CreateExtractValue(IACall, i);
16710 case X86::BI__emul:
16711 case X86::BI__emulu: {
16713 bool isSigned = (BuiltinID == X86::BI__emul);
16716 return Builder.CreateMul(LHS, RHS,
"", !isSigned, isSigned);
16718 case X86::BI__mulh:
16719 case X86::BI__umulh:
16720 case X86::BI_mul128:
16721 case X86::BI_umul128: {
16723 llvm::Type *Int128Ty = llvm::IntegerType::get(
getLLVMContext(), 128);
16725 bool IsSigned = (BuiltinID == X86::BI__mulh || BuiltinID == X86::BI_mul128);
16726 Value *LHS =
Builder.CreateIntCast(Ops[0], Int128Ty, IsSigned);
16727 Value *RHS =
Builder.CreateIntCast(Ops[1], Int128Ty, IsSigned);
16729 Value *MulResult, *HigherBits;
16731 MulResult =
Builder.CreateNSWMul(LHS, RHS);
16732 HigherBits =
Builder.CreateAShr(MulResult, 64);
16734 MulResult =
Builder.CreateNUWMul(LHS, RHS);
16735 HigherBits =
Builder.CreateLShr(MulResult, 64);
16737 HigherBits =
Builder.CreateIntCast(HigherBits, ResType, IsSigned);
16739 if (BuiltinID == X86::BI__mulh || BuiltinID == X86::BI__umulh)
16744 return Builder.CreateIntCast(MulResult, ResType, IsSigned);
16747 case X86::BI__faststorefence: {
16748 return Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent,
16749 llvm::SyncScope::System);
16751 case X86::BI__shiftleft128:
16752 case X86::BI__shiftright128: {
16754 BuiltinID == X86::BI__shiftleft128 ? Intrinsic::fshl : Intrinsic::fshr,
16759 std::swap(Ops[0], Ops[1]);
16761 return Builder.CreateCall(F, Ops);
16763 case X86::BI_ReadWriteBarrier:
16764 case X86::BI_ReadBarrier:
16765 case X86::BI_WriteBarrier: {
16766 return Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent,
16767 llvm::SyncScope::SingleThread);
16770 case X86::BI_AddressOfReturnAddress: {
16773 return Builder.CreateCall(F);
16775 case X86::BI__stosb: {
16783 case X86::BI__int2c: {
16785 llvm::FunctionType *FTy = llvm::FunctionType::get(
VoidTy,
false);
16786 llvm::InlineAsm *IA =
16787 llvm::InlineAsm::get(FTy,
"int $$0x2c",
"",
true);
16788 llvm::AttributeList NoReturnAttr = llvm::AttributeList::get(
16790 llvm::Attribute::NoReturn);
16791 llvm::CallInst *CI =
Builder.CreateCall(IA);
16792 CI->setAttributes(NoReturnAttr);
16795 case X86::BI__readfsbyte:
16796 case X86::BI__readfsword:
16797 case X86::BI__readfsdword:
16798 case X86::BI__readfsqword: {
16804 Load->setVolatile(
true);
16807 case X86::BI__readgsbyte:
16808 case X86::BI__readgsword:
16809 case X86::BI__readgsdword:
16810 case X86::BI__readgsqword: {
16816 Load->setVolatile(
true);
16819 case X86::BI__builtin_ia32_encodekey128_u32: {
16820 Intrinsic::ID IID = Intrinsic::x86_encodekey128;
16824 for (
int i = 0; i < 3; ++i) {
16832 case X86::BI__builtin_ia32_encodekey256_u32: {
16833 Intrinsic::ID IID = Intrinsic::x86_encodekey256;
16838 for (
int i = 0; i < 4; ++i) {
16846 case X86::BI__builtin_ia32_aesenc128kl_u8:
16847 case X86::BI__builtin_ia32_aesdec128kl_u8:
16848 case X86::BI__builtin_ia32_aesenc256kl_u8:
16849 case X86::BI__builtin_ia32_aesdec256kl_u8: {
16851 StringRef BlockName;
16852 switch (BuiltinID) {
16854 llvm_unreachable(
"Unexpected builtin");
16855 case X86::BI__builtin_ia32_aesenc128kl_u8:
16856 IID = Intrinsic::x86_aesenc128kl;
16857 BlockName =
"aesenc128kl";
16859 case X86::BI__builtin_ia32_aesdec128kl_u8:
16860 IID = Intrinsic::x86_aesdec128kl;
16861 BlockName =
"aesdec128kl";
16863 case X86::BI__builtin_ia32_aesenc256kl_u8:
16864 IID = Intrinsic::x86_aesenc256kl;
16865 BlockName =
"aesenc256kl";
16867 case X86::BI__builtin_ia32_aesdec256kl_u8:
16868 IID = Intrinsic::x86_aesdec256kl;
16869 BlockName =
"aesdec256kl";
16875 BasicBlock *NoError =
16883 Builder.CreateCondBr(Succ, NoError, Error);
16885 Builder.SetInsertPoint(NoError);
16889 Builder.SetInsertPoint(Error);
16890 Constant *
Zero = llvm::Constant::getNullValue(Out->getType());
16897 case X86::BI__builtin_ia32_aesencwide128kl_u8:
16898 case X86::BI__builtin_ia32_aesdecwide128kl_u8:
16899 case X86::BI__builtin_ia32_aesencwide256kl_u8:
16900 case X86::BI__builtin_ia32_aesdecwide256kl_u8: {
16902 StringRef BlockName;
16903 switch (BuiltinID) {
16904 case X86::BI__builtin_ia32_aesencwide128kl_u8:
16905 IID = Intrinsic::x86_aesencwide128kl;
16906 BlockName =
"aesencwide128kl";
16908 case X86::BI__builtin_ia32_aesdecwide128kl_u8:
16909 IID = Intrinsic::x86_aesdecwide128kl;
16910 BlockName =
"aesdecwide128kl";
16912 case X86::BI__builtin_ia32_aesencwide256kl_u8:
16913 IID = Intrinsic::x86_aesencwide256kl;
16914 BlockName =
"aesencwide256kl";
16916 case X86::BI__builtin_ia32_aesdecwide256kl_u8:
16917 IID = Intrinsic::x86_aesdecwide256kl;
16918 BlockName =
"aesdecwide256kl";
16922 llvm::Type *Ty = FixedVectorType::get(
Builder.getInt64Ty(), 2);
16925 for (
int i = 0; i != 8; ++i) {
16926 Value *Ptr =
Builder.CreateConstGEP1_32(Ty, Ops[1], i);
16932 BasicBlock *NoError =
16939 Builder.CreateCondBr(Succ, NoError, Error);
16941 Builder.SetInsertPoint(NoError);
16942 for (
int i = 0; i != 8; ++i) {
16949 Builder.SetInsertPoint(Error);
16950 for (
int i = 0; i != 8; ++i) {
16952 Constant *
Zero = llvm::Constant::getNullValue(Out->getType());
16953 Value *Ptr =
Builder.CreateConstGEP1_32(Out->getType(), Ops[0], i);
16961 case X86::BI__builtin_ia32_vfcmaddcph512_mask:
16964 case X86::BI__builtin_ia32_vfmaddcph512_mask: {
16965 Intrinsic::ID IID = IsConjFMA
16966 ? Intrinsic::x86_avx512fp16_mask_vfcmadd_cph_512
16967 : Intrinsic::x86_avx512fp16_mask_vfmadd_cph_512;
16971 case X86::BI__builtin_ia32_vfcmaddcph256_round_mask:
16974 case X86::BI__builtin_ia32_vfmaddcph256_round_mask: {
16975 Intrinsic::ID IID = IsConjFMA ? Intrinsic::x86_avx10_mask_vfcmaddcph256
16976 : Intrinsic::x86_avx10_mask_vfmaddcph256;
16980 case X86::BI__builtin_ia32_vfcmaddcsh_round_mask:
16983 case X86::BI__builtin_ia32_vfmaddcsh_round_mask: {
16984 Intrinsic::ID IID = IsConjFMA ? Intrinsic::x86_avx512fp16_mask_vfcmadd_csh
16985 : Intrinsic::x86_avx512fp16_mask_vfmadd_csh;
16990 case X86::BI__builtin_ia32_vfcmaddcsh_round_mask3:
16993 case X86::BI__builtin_ia32_vfmaddcsh_round_mask3: {
16994 Intrinsic::ID IID = IsConjFMA ? Intrinsic::x86_avx512fp16_mask_vfcmadd_csh
16995 : Intrinsic::x86_avx512fp16_mask_vfmadd_csh;
16997 static constexpr int Mask[] = {0, 5, 6, 7};
16998 return Builder.CreateShuffleVector(
Call, Ops[2], Mask);
17000 case X86::BI__builtin_ia32_prefetchi:
17003 {Ops[0], llvm::ConstantInt::get(Int32Ty, 0), Ops[1],
17004 llvm::ConstantInt::get(Int32Ty, 0)});
17022 Intrinsic::ID
ID = Intrinsic::not_intrinsic;
17024#include "llvm/TargetParser/PPCTargetParser.def"
17025 auto GenAIXPPCBuiltinCpuExpr = [&](
unsigned SupportMethod,
unsigned FieldIdx,
17026 unsigned Mask, CmpInst::Predicate CompOp,
17027 unsigned OpValue) ->
Value * {
17028 if (SupportMethod == BUILTIN_PPC_FALSE)
17031 if (SupportMethod == BUILTIN_PPC_TRUE)
17034 assert(SupportMethod <= SYS_CALL &&
"Invalid value for SupportMethod.");
17036 llvm::Value *FieldValue =
nullptr;
17037 if (SupportMethod == USE_SYS_CONF) {
17038 llvm::Type *STy = llvm::StructType::get(PPC_SYSTEMCONFIG_TYPE);
17039 llvm::Constant *SysConf =
17043 llvm::Value *Idxs[] = {ConstantInt::get(
Int32Ty, 0),
17044 ConstantInt::get(
Int32Ty, FieldIdx)};
17049 }
else if (SupportMethod == SYS_CALL) {
17050 llvm::FunctionType *FTy =
17052 llvm::FunctionCallee
Func =
17058 assert(FieldValue &&
17059 "SupportMethod value is not defined in PPCTargetParser.def.");
17062 FieldValue =
Builder.CreateAnd(FieldValue, Mask);
17064 llvm::Type *ValueType = FieldValue->getType();
17065 bool IsValueType64Bit = ValueType->isIntegerTy(64);
17067 (IsValueType64Bit || ValueType->isIntegerTy(32)) &&
17068 "Only 32/64-bit integers are supported in GenAIXPPCBuiltinCpuExpr().");
17071 CompOp, FieldValue,
17072 ConstantInt::get(IsValueType64Bit ?
Int64Ty :
Int32Ty, OpValue));
17075 switch (BuiltinID) {
17076 default:
return nullptr;
17078 case Builtin::BI__builtin_cpu_is: {
17080 StringRef CPUStr = cast<clang::StringLiteral>(CPUExpr)->getString();
17083 unsigned LinuxSupportMethod, LinuxIDValue, AIXSupportMethod, AIXIDValue;
17084 typedef std::tuple<unsigned, unsigned, unsigned, unsigned>
CPUInfo;
17086 std::tie(LinuxSupportMethod, LinuxIDValue, AIXSupportMethod, AIXIDValue) =
17087 static_cast<CPUInfo>(StringSwitch<CPUInfo>(CPUStr)
17088#define PPC_CPU(NAME, Linux_SUPPORT_METHOD, LinuxID, AIX_SUPPORT_METHOD, \
17090 .Case(NAME, {Linux_SUPPORT_METHOD, LinuxID, AIX_SUPPORT_METHOD, AIXID})
17091#include "llvm/TargetParser/PPCTargetParser.def"
17092 .Default({BUILTIN_PPC_UNSUPPORTED, 0,
17093 BUILTIN_PPC_UNSUPPORTED, 0}));
17095 if (Triple.isOSAIX()) {
17096 assert((AIXSupportMethod != BUILTIN_PPC_UNSUPPORTED) &&
17097 "Invalid CPU name. Missed by SemaChecking?");
17098 return GenAIXPPCBuiltinCpuExpr(AIXSupportMethod, AIX_SYSCON_IMPL_IDX, 0,
17099 ICmpInst::ICMP_EQ, AIXIDValue);
17102 assert(Triple.isOSLinux() &&
17103 "__builtin_cpu_is() is only supported for AIX and Linux.");
17105 assert((LinuxSupportMethod != BUILTIN_PPC_UNSUPPORTED) &&
17106 "Invalid CPU name. Missed by SemaChecking?");
17108 if (LinuxSupportMethod == BUILTIN_PPC_FALSE)
17111 Value *Op0 = llvm::ConstantInt::get(
Int32Ty, PPC_FAWORD_CPUID);
17113 Value *TheCall =
Builder.CreateCall(F, {Op0},
"cpu_is");
17114 return Builder.CreateICmpEQ(TheCall,
17115 llvm::ConstantInt::get(
Int32Ty, LinuxIDValue));
17117 case Builtin::BI__builtin_cpu_supports: {
17120 StringRef CPUStr = cast<clang::StringLiteral>(CPUExpr)->getString();
17121 if (Triple.isOSAIX()) {
17122 unsigned SupportMethod, FieldIdx, Mask,
Value;
17123 CmpInst::Predicate CompOp;
17127 std::tie(SupportMethod, FieldIdx, Mask, CompOp,
Value) =
17128 static_cast<CPUSupportType
>(StringSwitch<CPUSupportType>(CPUStr)
17129#define PPC_AIX_FEATURE(NAME, DESC, SUPPORT_METHOD, INDEX, MASK, COMP_OP, \
17131 .Case(NAME, {SUPPORT_METHOD, INDEX, MASK, COMP_OP, VALUE})
17132#include "llvm/TargetParser/PPCTargetParser.def"
17133 .Default({BUILTIN_PPC_FALSE, 0, 0,
17134 CmpInst::Predicate(), 0}));
17135 return GenAIXPPCBuiltinCpuExpr(SupportMethod, FieldIdx, Mask, CompOp,
17139 assert(Triple.isOSLinux() &&
17140 "__builtin_cpu_supports() is only supported for AIX and Linux.");
17141 unsigned FeatureWord;
17143 std::tie(FeatureWord, BitMask) =
17144 StringSwitch<std::pair<unsigned, unsigned>>(CPUStr)
17145#define
PPC_LNX_FEATURE(Name, Description, EnumName, Bitmask, FA_WORD) \
17146 .Case(Name, {FA_WORD, Bitmask})
17147#include
"llvm/TargetParser/PPCTargetParser.def"
17151 Value *Op0 = llvm::ConstantInt::get(
Int32Ty, FeatureWord);
17153 Value *TheCall =
Builder.CreateCall(F, {Op0},
"cpu_supports");
17155 Builder.CreateAnd(TheCall, llvm::ConstantInt::get(
Int32Ty, BitMask));
17156 return Builder.CreateICmpNE(Mask, llvm::Constant::getNullValue(
Int32Ty));
17157#undef PPC_FAWORD_HWCAP
17158#undef PPC_FAWORD_HWCAP2
17159#undef PPC_FAWORD_CPUID
17164 case PPC::BI__builtin_ppc_get_timebase:
17168 case PPC::BI__builtin_altivec_lvx:
17169 case PPC::BI__builtin_altivec_lvxl:
17170 case PPC::BI__builtin_altivec_lvebx:
17171 case PPC::BI__builtin_altivec_lvehx:
17172 case PPC::BI__builtin_altivec_lvewx:
17173 case PPC::BI__builtin_altivec_lvsl:
17174 case PPC::BI__builtin_altivec_lvsr:
17175 case PPC::BI__builtin_vsx_lxvd2x:
17176 case PPC::BI__builtin_vsx_lxvw4x:
17177 case PPC::BI__builtin_vsx_lxvd2x_be:
17178 case PPC::BI__builtin_vsx_lxvw4x_be:
17179 case PPC::BI__builtin_vsx_lxvl:
17180 case PPC::BI__builtin_vsx_lxvll:
17185 if (!(BuiltinID == PPC::BI__builtin_vsx_lxvl ||
17186 BuiltinID == PPC::BI__builtin_vsx_lxvll)) {
17191 switch (BuiltinID) {
17192 default: llvm_unreachable(
"Unsupported ld/lvsl/lvsr intrinsic!");
17193 case PPC::BI__builtin_altivec_lvx:
17194 ID = Intrinsic::ppc_altivec_lvx;
17196 case PPC::BI__builtin_altivec_lvxl:
17197 ID = Intrinsic::ppc_altivec_lvxl;
17199 case PPC::BI__builtin_altivec_lvebx:
17200 ID = Intrinsic::ppc_altivec_lvebx;
17202 case PPC::BI__builtin_altivec_lvehx:
17203 ID = Intrinsic::ppc_altivec_lvehx;
17205 case PPC::BI__builtin_altivec_lvewx:
17206 ID = Intrinsic::ppc_altivec_lvewx;
17208 case PPC::BI__builtin_altivec_lvsl:
17209 ID = Intrinsic::ppc_altivec_lvsl;
17211 case PPC::BI__builtin_altivec_lvsr:
17212 ID = Intrinsic::ppc_altivec_lvsr;
17214 case PPC::BI__builtin_vsx_lxvd2x:
17215 ID = Intrinsic::ppc_vsx_lxvd2x;
17217 case PPC::BI__builtin_vsx_lxvw4x:
17218 ID = Intrinsic::ppc_vsx_lxvw4x;
17220 case PPC::BI__builtin_vsx_lxvd2x_be:
17221 ID = Intrinsic::ppc_vsx_lxvd2x_be;
17223 case PPC::BI__builtin_vsx_lxvw4x_be:
17224 ID = Intrinsic::ppc_vsx_lxvw4x_be;
17226 case PPC::BI__builtin_vsx_lxvl:
17227 ID = Intrinsic::ppc_vsx_lxvl;
17229 case PPC::BI__builtin_vsx_lxvll:
17230 ID = Intrinsic::ppc_vsx_lxvll;
17234 return Builder.CreateCall(F, Ops,
"");
17238 case PPC::BI__builtin_altivec_stvx:
17239 case PPC::BI__builtin_altivec_stvxl:
17240 case PPC::BI__builtin_altivec_stvebx:
17241 case PPC::BI__builtin_altivec_stvehx:
17242 case PPC::BI__builtin_altivec_stvewx:
17243 case PPC::BI__builtin_vsx_stxvd2x:
17244 case PPC::BI__builtin_vsx_stxvw4x:
17245 case PPC::BI__builtin_vsx_stxvd2x_be:
17246 case PPC::BI__builtin_vsx_stxvw4x_be:
17247 case PPC::BI__builtin_vsx_stxvl:
17248 case PPC::BI__builtin_vsx_stxvll:
17254 if (!(BuiltinID == PPC::BI__builtin_vsx_stxvl ||
17255 BuiltinID == PPC::BI__builtin_vsx_stxvll)) {
17260 switch (BuiltinID) {
17261 default: llvm_unreachable(
"Unsupported st intrinsic!");
17262 case PPC::BI__builtin_altivec_stvx:
17263 ID = Intrinsic::ppc_altivec_stvx;
17265 case PPC::BI__builtin_altivec_stvxl:
17266 ID = Intrinsic::ppc_altivec_stvxl;
17268 case PPC::BI__builtin_altivec_stvebx:
17269 ID = Intrinsic::ppc_altivec_stvebx;
17271 case PPC::BI__builtin_altivec_stvehx:
17272 ID = Intrinsic::ppc_altivec_stvehx;
17274 case PPC::BI__builtin_altivec_stvewx:
17275 ID = Intrinsic::ppc_altivec_stvewx;
17277 case PPC::BI__builtin_vsx_stxvd2x:
17278 ID = Intrinsic::ppc_vsx_stxvd2x;
17280 case PPC::BI__builtin_vsx_stxvw4x:
17281 ID = Intrinsic::ppc_vsx_stxvw4x;
17283 case PPC::BI__builtin_vsx_stxvd2x_be:
17284 ID = Intrinsic::ppc_vsx_stxvd2x_be;
17286 case PPC::BI__builtin_vsx_stxvw4x_be:
17287 ID = Intrinsic::ppc_vsx_stxvw4x_be;
17289 case PPC::BI__builtin_vsx_stxvl:
17290 ID = Intrinsic::ppc_vsx_stxvl;
17292 case PPC::BI__builtin_vsx_stxvll:
17293 ID = Intrinsic::ppc_vsx_stxvll;
17297 return Builder.CreateCall(F, Ops,
"");
17299 case PPC::BI__builtin_vsx_ldrmb: {
17305 int64_t NumBytes = cast<ConstantInt>(Op1)->getZExtValue();
17310 if (NumBytes == 16) {
17318 for (
int Idx = 0; Idx < 16; Idx++)
17319 RevMask.push_back(15 - Idx);
17320 return Builder.CreateShuffleVector(LD, LD, RevMask);
17324 llvm::Function *Lvs =
CGM.
getIntrinsic(IsLE ? Intrinsic::ppc_altivec_lvsr
17325 : Intrinsic::ppc_altivec_lvsl);
17326 llvm::Function *Vperm =
CGM.
getIntrinsic(Intrinsic::ppc_altivec_vperm);
17328 Int8Ty, Op0, ConstantInt::get(Op1->
getType(), NumBytes - 1));
17330 Value *HiLd =
Builder.CreateCall(Lvx, HiMem,
"ld.hi");
17333 Op0 = IsLE ? HiLd : LoLd;
17334 Op1 = IsLE ? LoLd : HiLd;
17335 Value *AllElts =
Builder.CreateCall(Vperm, {Op0, Op1, Mask1},
"shuffle1");
17336 Constant *
Zero = llvm::Constant::getNullValue(IsLE ? ResTy : AllElts->
getType());
17340 for (
int Idx = 0; Idx < 16; Idx++) {
17341 int Val = (NumBytes - Idx - 1 >= 0) ? (NumBytes - Idx - 1)
17342 : 16 - (NumBytes - Idx);
17343 Consts.push_back(Val);
17345 return Builder.CreateShuffleVector(
Builder.CreateBitCast(AllElts, ResTy),
17349 for (
int Idx = 0; Idx < 16; Idx++)
17350 Consts.push_back(
Builder.getInt8(NumBytes + Idx));
17351 Value *Mask2 = ConstantVector::get(Consts);
17352 return Builder.CreateBitCast(
17353 Builder.CreateCall(Vperm, {Zero, AllElts, Mask2},
"shuffle2"), ResTy);
17355 case PPC::BI__builtin_vsx_strmb: {
17359 int64_t NumBytes = cast<ConstantInt>(Op1)->getZExtValue();
17361 auto StoreSubVec = [&](
unsigned Width,
unsigned Offset,
unsigned EltNo) {
17365 Value *StVec = Op2;
17368 for (
int Idx = 0; Idx < 16; Idx++)
17369 RevMask.push_back(15 - Idx);
17370 StVec =
Builder.CreateShuffleVector(Op2, Op2, RevMask);
17376 unsigned NumElts = 0;
17379 llvm_unreachable(
"width for stores must be a power of 2");
17398 Op2, llvm::FixedVectorType::get(ConvTy, NumElts));
17401 Value *Elt =
Builder.CreateExtractElement(Vec, EltNo);
17402 if (IsLE && Width > 1) {
17404 Elt =
Builder.CreateCall(F, Elt);
17409 unsigned Stored = 0;
17410 unsigned RemainingBytes = NumBytes;
17412 if (NumBytes == 16)
17413 return StoreSubVec(16, 0, 0);
17414 if (NumBytes >= 8) {
17415 Result = StoreSubVec(8, NumBytes - 8, IsLE ? 0 : 1);
17416 RemainingBytes -= 8;
17419 if (RemainingBytes >= 4) {
17420 Result = StoreSubVec(4, NumBytes - Stored - 4,
17421 IsLE ? (Stored >> 2) : 3 - (Stored >> 2));
17422 RemainingBytes -= 4;
17425 if (RemainingBytes >= 2) {
17426 Result = StoreSubVec(2, NumBytes - Stored - 2,
17427 IsLE ? (Stored >> 1) : 7 - (Stored >> 1));
17428 RemainingBytes -= 2;
17431 if (RemainingBytes)
17433 StoreSubVec(1, NumBytes - Stored - 1, IsLE ? Stored : 15 - Stored);
17437 case PPC::BI__builtin_vsx_xvsqrtsp:
17438 case PPC::BI__builtin_vsx_xvsqrtdp: {
17441 if (
Builder.getIsFPConstrained()) {
17443 Intrinsic::experimental_constrained_sqrt, ResultType);
17444 return Builder.CreateConstrainedFPCall(F,
X);
17451 case PPC::BI__builtin_altivec_vclzb:
17452 case PPC::BI__builtin_altivec_vclzh:
17453 case PPC::BI__builtin_altivec_vclzw:
17454 case PPC::BI__builtin_altivec_vclzd: {
17457 Value *Undef = ConstantInt::get(
Builder.getInt1Ty(),
false);
17459 return Builder.CreateCall(F, {
X, Undef});
17461 case PPC::BI__builtin_altivec_vctzb:
17462 case PPC::BI__builtin_altivec_vctzh:
17463 case PPC::BI__builtin_altivec_vctzw:
17464 case PPC::BI__builtin_altivec_vctzd: {
17467 Value *Undef = ConstantInt::get(
Builder.getInt1Ty(),
false);
17469 return Builder.CreateCall(F, {
X, Undef});
17471 case PPC::BI__builtin_altivec_vinsd:
17472 case PPC::BI__builtin_altivec_vinsw:
17473 case PPC::BI__builtin_altivec_vinsd_elt:
17474 case PPC::BI__builtin_altivec_vinsw_elt: {
17480 bool IsUnaligned = (BuiltinID == PPC::BI__builtin_altivec_vinsw ||
17481 BuiltinID == PPC::BI__builtin_altivec_vinsd);
17483 bool Is32bit = (BuiltinID == PPC::BI__builtin_altivec_vinsw ||
17484 BuiltinID == PPC::BI__builtin_altivec_vinsw_elt);
17487 ConstantInt *ArgCI = dyn_cast<ConstantInt>(Op2);
17489 "Third Arg to vinsw/vinsd intrinsic must be a constant integer!");
17493 int ValidMaxValue = 0;
17495 ValidMaxValue = (Is32bit) ? 12 : 8;
17497 ValidMaxValue = (Is32bit) ? 3 : 1;
17500 int64_t ConstArg = ArgCI->getSExtValue();
17503 std::string RangeErrMsg = IsUnaligned ?
"byte" :
"element";
17504 RangeErrMsg +=
" number " + llvm::to_string(ConstArg);
17505 RangeErrMsg +=
" is outside of the valid range [0, ";
17506 RangeErrMsg += llvm::to_string(ValidMaxValue) +
"]";
17509 if (ConstArg < 0 || ConstArg > ValidMaxValue)
17513 if (!IsUnaligned) {
17514 ConstArg *= Is32bit ? 4 : 8;
17517 ConstArg = (Is32bit ? 12 : 8) - ConstArg;
17520 ID = Is32bit ? Intrinsic::ppc_altivec_vinsw : Intrinsic::ppc_altivec_vinsd;
17521 Op2 = ConstantInt::getSigned(
Int32Ty, ConstArg);
17525 ?
Builder.CreateBitCast(Op0, llvm::FixedVectorType::get(
Int32Ty, 4))
17527 llvm::FixedVectorType::get(
Int64Ty, 2));
17528 return Builder.CreateBitCast(
17531 case PPC::BI__builtin_altivec_vpopcntb:
17532 case PPC::BI__builtin_altivec_vpopcnth:
17533 case PPC::BI__builtin_altivec_vpopcntw:
17534 case PPC::BI__builtin_altivec_vpopcntd: {
17540 case PPC::BI__builtin_altivec_vadduqm:
17541 case PPC::BI__builtin_altivec_vsubuqm: {
17544 llvm::Type *Int128Ty = llvm::IntegerType::get(
getLLVMContext(), 128);
17545 Op0 =
Builder.CreateBitCast(Op0, llvm::FixedVectorType::get(Int128Ty, 1));
17546 Op1 =
Builder.CreateBitCast(Op1, llvm::FixedVectorType::get(Int128Ty, 1));
17547 if (BuiltinID == PPC::BI__builtin_altivec_vadduqm)
17548 return Builder.CreateAdd(Op0, Op1,
"vadduqm");
17550 return Builder.CreateSub(Op0, Op1,
"vsubuqm");
17552 case PPC::BI__builtin_altivec_vaddcuq_c:
17553 case PPC::BI__builtin_altivec_vsubcuq_c: {
17557 llvm::Type *V1I128Ty = llvm::FixedVectorType::get(
17559 Ops.push_back(
Builder.CreateBitCast(Op0, V1I128Ty));
17560 Ops.push_back(
Builder.CreateBitCast(Op1, V1I128Ty));
17561 ID = (BuiltinID == PPC::BI__builtin_altivec_vaddcuq_c)
17562 ? Intrinsic::ppc_altivec_vaddcuq
17563 : Intrinsic::ppc_altivec_vsubcuq;
17566 case PPC::BI__builtin_altivec_vaddeuqm_c:
17567 case PPC::BI__builtin_altivec_vaddecuq_c:
17568 case PPC::BI__builtin_altivec_vsubeuqm_c:
17569 case PPC::BI__builtin_altivec_vsubecuq_c: {
17574 llvm::Type *V1I128Ty = llvm::FixedVectorType::get(
17576 Ops.push_back(
Builder.CreateBitCast(Op0, V1I128Ty));
17577 Ops.push_back(
Builder.CreateBitCast(Op1, V1I128Ty));
17578 Ops.push_back(
Builder.CreateBitCast(Op2, V1I128Ty));
17579 switch (BuiltinID) {
17581 llvm_unreachable(
"Unsupported intrinsic!");
17582 case PPC::BI__builtin_altivec_vaddeuqm_c:
17583 ID = Intrinsic::ppc_altivec_vaddeuqm;
17585 case PPC::BI__builtin_altivec_vaddecuq_c:
17586 ID = Intrinsic::ppc_altivec_vaddecuq;
17588 case PPC::BI__builtin_altivec_vsubeuqm_c:
17589 ID = Intrinsic::ppc_altivec_vsubeuqm;
17591 case PPC::BI__builtin_altivec_vsubecuq_c:
17592 ID = Intrinsic::ppc_altivec_vsubecuq;
17597 case PPC::BI__builtin_ppc_rldimi:
17598 case PPC::BI__builtin_ppc_rlwimi: {
17605 if (BuiltinID == PPC::BI__builtin_ppc_rldimi &&
17615 ? Intrinsic::ppc_rldimi
17616 : Intrinsic::ppc_rlwimi),
17617 {Op0, Op1, Op2, Op3});
17619 case PPC::BI__builtin_ppc_rlwnm: {
17626 case PPC::BI__builtin_ppc_poppar4:
17627 case PPC::BI__builtin_ppc_poppar8: {
17629 llvm::Type *ArgType = Op0->
getType();
17635 if (
Result->getType() != ResultType)
17640 case PPC::BI__builtin_ppc_cmpb: {
17643 if (
getTarget().getTriple().isPPC64()) {
17646 return Builder.CreateCall(F, {Op0, Op1},
"cmpb");
17666 Constant *ShiftAmt = ConstantInt::get(
Int64Ty, 32);
17675 Value *ResHi =
Builder.CreateShl(ResHiShift, ShiftAmt);
17676 return Builder.CreateOr(ResLo, ResHi);
17679 case PPC::BI__builtin_vsx_xvcpsgnsp:
17680 case PPC::BI__builtin_vsx_xvcpsgndp: {
17684 ID = Intrinsic::copysign;
17686 return Builder.CreateCall(F, {
X, Y});
17689 case PPC::BI__builtin_vsx_xvrspip:
17690 case PPC::BI__builtin_vsx_xvrdpip:
17691 case PPC::BI__builtin_vsx_xvrdpim:
17692 case PPC::BI__builtin_vsx_xvrspim:
17693 case PPC::BI__builtin_vsx_xvrdpi:
17694 case PPC::BI__builtin_vsx_xvrspi:
17695 case PPC::BI__builtin_vsx_xvrdpic:
17696 case PPC::BI__builtin_vsx_xvrspic:
17697 case PPC::BI__builtin_vsx_xvrdpiz:
17698 case PPC::BI__builtin_vsx_xvrspiz: {
17701 if (BuiltinID == PPC::BI__builtin_vsx_xvrdpim ||
17702 BuiltinID == PPC::BI__builtin_vsx_xvrspim)
17704 ? Intrinsic::experimental_constrained_floor
17705 : Intrinsic::floor;
17706 else if (BuiltinID == PPC::BI__builtin_vsx_xvrdpi ||
17707 BuiltinID == PPC::BI__builtin_vsx_xvrspi)
17709 ? Intrinsic::experimental_constrained_round
17710 : Intrinsic::round;
17711 else if (BuiltinID == PPC::BI__builtin_vsx_xvrdpic ||
17712 BuiltinID == PPC::BI__builtin_vsx_xvrspic)
17714 ? Intrinsic::experimental_constrained_rint
17716 else if (BuiltinID == PPC::BI__builtin_vsx_xvrdpip ||
17717 BuiltinID == PPC::BI__builtin_vsx_xvrspip)
17719 ? Intrinsic::experimental_constrained_ceil
17721 else if (BuiltinID == PPC::BI__builtin_vsx_xvrdpiz ||
17722 BuiltinID == PPC::BI__builtin_vsx_xvrspiz)
17724 ? Intrinsic::experimental_constrained_trunc
17725 : Intrinsic::trunc;
17727 return Builder.getIsFPConstrained() ?
Builder.CreateConstrainedFPCall(F,
X)
17732 case PPC::BI__builtin_vsx_xvabsdp:
17733 case PPC::BI__builtin_vsx_xvabssp: {
17741 case PPC::BI__builtin_ppc_recipdivf:
17742 case PPC::BI__builtin_ppc_recipdivd:
17743 case PPC::BI__builtin_ppc_rsqrtf:
17744 case PPC::BI__builtin_ppc_rsqrtd: {
17745 FastMathFlags FMF =
Builder.getFastMathFlags();
17746 Builder.getFastMathFlags().setFast();
17750 if (BuiltinID == PPC::BI__builtin_ppc_recipdivf ||
17751 BuiltinID == PPC::BI__builtin_ppc_recipdivd) {
17754 Builder.getFastMathFlags() &= (FMF);
17757 auto *One = ConstantFP::get(ResultType, 1.0);
17760 Builder.getFastMathFlags() &= (FMF);
17763 case PPC::BI__builtin_ppc_alignx: {
17766 ConstantInt *AlignmentCI = cast<ConstantInt>(Op0);
17767 if (AlignmentCI->getValue().ugt(llvm::Value::MaximumAlignment))
17768 AlignmentCI = ConstantInt::get(AlignmentCI->getIntegerType(),
17769 llvm::Value::MaximumAlignment);
17773 AlignmentCI,
nullptr);
17776 case PPC::BI__builtin_ppc_rdlam: {
17780 llvm::Type *Ty = Op0->
getType();
17781 Value *ShiftAmt =
Builder.CreateIntCast(Op1, Ty,
false);
17783 Value *Rotate =
Builder.CreateCall(F, {Op0, Op0, ShiftAmt});
17784 return Builder.CreateAnd(Rotate, Op2);
17786 case PPC::BI__builtin_ppc_load2r: {
17793 case PPC::BI__builtin_ppc_fnmsub:
17794 case PPC::BI__builtin_ppc_fnmsubs:
17795 case PPC::BI__builtin_vsx_xvmaddadp:
17796 case PPC::BI__builtin_vsx_xvmaddasp:
17797 case PPC::BI__builtin_vsx_xvnmaddadp:
17798 case PPC::BI__builtin_vsx_xvnmaddasp:
17799 case PPC::BI__builtin_vsx_xvmsubadp:
17800 case PPC::BI__builtin_vsx_xvmsubasp:
17801 case PPC::BI__builtin_vsx_xvnmsubadp:
17802 case PPC::BI__builtin_vsx_xvnmsubasp: {
17808 if (
Builder.getIsFPConstrained())
17809 F =
CGM.
getIntrinsic(Intrinsic::experimental_constrained_fma, ResultType);
17812 switch (BuiltinID) {
17813 case PPC::BI__builtin_vsx_xvmaddadp:
17814 case PPC::BI__builtin_vsx_xvmaddasp:
17815 if (
Builder.getIsFPConstrained())
17816 return Builder.CreateConstrainedFPCall(F, {
X, Y, Z});
17818 return Builder.CreateCall(F, {
X, Y, Z});
17819 case PPC::BI__builtin_vsx_xvnmaddadp:
17820 case PPC::BI__builtin_vsx_xvnmaddasp:
17821 if (
Builder.getIsFPConstrained())
17823 Builder.CreateConstrainedFPCall(F, {X, Y, Z}),
"neg");
17825 return Builder.CreateFNeg(
Builder.CreateCall(F, {X, Y, Z}),
"neg");
17826 case PPC::BI__builtin_vsx_xvmsubadp:
17827 case PPC::BI__builtin_vsx_xvmsubasp:
17828 if (
Builder.getIsFPConstrained())
17829 return Builder.CreateConstrainedFPCall(
17830 F, {
X, Y,
Builder.CreateFNeg(Z,
"neg")});
17833 case PPC::BI__builtin_ppc_fnmsub:
17834 case PPC::BI__builtin_ppc_fnmsubs:
17835 case PPC::BI__builtin_vsx_xvnmsubadp:
17836 case PPC::BI__builtin_vsx_xvnmsubasp:
17837 if (
Builder.getIsFPConstrained())
17839 Builder.CreateConstrainedFPCall(
17840 F, {X, Y, Builder.CreateFNeg(Z,
"neg")}),
17846 llvm_unreachable(
"Unknown FMA operation");
17850 case PPC::BI__builtin_vsx_insertword: {
17858 ConstantInt *ArgCI = dyn_cast<ConstantInt>(Op2);
17860 "Third arg to xxinsertw intrinsic must be constant integer");
17862 int64_t Index = std::clamp(ArgCI->getSExtValue(), (int64_t)0, MaxIndex);
17869 std::swap(Op0, Op1);
17873 Op1 =
Builder.CreateBitCast(Op1, llvm::FixedVectorType::get(
Int64Ty, 2));
17877 Op0 =
Builder.CreateBitCast(Op0, llvm::FixedVectorType::get(
Int64Ty, 2));
17881 Index = MaxIndex - Index;
17885 Op0 =
Builder.CreateBitCast(Op0, llvm::FixedVectorType::get(
Int32Ty, 4));
17886 Op2 = ConstantInt::getSigned(
Int32Ty, Index);
17887 return Builder.CreateCall(F, {Op0, Op1, Op2});
17890 case PPC::BI__builtin_vsx_extractuword: {
17893 llvm::Function *F =
CGM.
getIntrinsic(Intrinsic::ppc_vsx_xxextractuw);
17896 Op0 =
Builder.CreateBitCast(Op0, llvm::FixedVectorType::get(
Int64Ty, 2));
17900 ConstantInt *ArgCI = dyn_cast<ConstantInt>(Op1);
17902 "Second Arg to xxextractuw intrinsic must be a constant integer!");
17904 int64_t Index = std::clamp(ArgCI->getSExtValue(), (int64_t)0, MaxIndex);
17908 Index = MaxIndex - Index;
17909 Op1 = ConstantInt::getSigned(
Int32Ty, Index);
17914 Value *ShuffleCall =
17916 return ShuffleCall;
17918 Op1 = ConstantInt::getSigned(
Int32Ty, Index);
17919 return Builder.CreateCall(F, {Op0, Op1});
17923 case PPC::BI__builtin_vsx_xxpermdi: {
17927 ConstantInt *ArgCI = dyn_cast<ConstantInt>(Op2);
17928 assert(ArgCI &&
"Third arg must be constant integer!");
17930 unsigned Index = ArgCI->getZExtValue();
17931 Op0 =
Builder.CreateBitCast(Op0, llvm::FixedVectorType::get(
Int64Ty, 2));
17932 Op1 =
Builder.CreateBitCast(Op1, llvm::FixedVectorType::get(
Int64Ty, 2));
17937 int ElemIdx0 = (Index & 2) >> 1;
17938 int ElemIdx1 = 2 + (Index & 1);
17940 int ShuffleElts[2] = {ElemIdx0, ElemIdx1};
17941 Value *ShuffleCall =
Builder.CreateShuffleVector(Op0, Op1, ShuffleElts);
17944 return Builder.CreateBitCast(ShuffleCall, RetTy);
17947 case PPC::BI__builtin_vsx_xxsldwi: {
17951 ConstantInt *ArgCI = dyn_cast<ConstantInt>(Op2);
17952 assert(ArgCI &&
"Third argument must be a compile time constant");
17953 unsigned Index = ArgCI->getZExtValue() & 0x3;
17954 Op0 =
Builder.CreateBitCast(Op0, llvm::FixedVectorType::get(
Int32Ty, 4));
17955 Op1 =
Builder.CreateBitCast(Op1, llvm::FixedVectorType::get(
Int32Ty, 4));
17966 ElemIdx0 = (8 - Index) % 8;
17967 ElemIdx1 = (9 - Index) % 8;
17968 ElemIdx2 = (10 - Index) % 8;
17969 ElemIdx3 = (11 - Index) % 8;
17973 ElemIdx1 = Index + 1;
17974 ElemIdx2 = Index + 2;
17975 ElemIdx3 = Index + 3;
17978 int ShuffleElts[4] = {ElemIdx0, ElemIdx1, ElemIdx2, ElemIdx3};
17979 Value *ShuffleCall =
Builder.CreateShuffleVector(Op0, Op1, ShuffleElts);
17982 return Builder.CreateBitCast(ShuffleCall, RetTy);
17985 case PPC::BI__builtin_pack_vector_int128: {
17989 Value *PoisonValue =
17990 llvm::PoisonValue::get(llvm::FixedVectorType::get(Op0->
getType(), 2));
17992 PoisonValue, Op0, (uint64_t)(isLittleEndian ? 1 : 0));
17993 Res =
Builder.CreateInsertElement(Res, Op1,
17994 (uint64_t)(isLittleEndian ? 0 : 1));
17998 case PPC::BI__builtin_unpack_vector_int128: {
18001 ConstantInt *Index = cast<ConstantInt>(Op1);
18007 ConstantInt::get(Index->getIntegerType(), 1 - Index->getZExtValue());
18009 return Builder.CreateExtractElement(Unpacked, Index);
18012 case PPC::BI__builtin_ppc_sthcx: {
18016 return Builder.CreateCall(F, {Op0, Op1});
18025#define CUSTOM_BUILTIN(Name, Intr, Types, Accumulate, Feature) \
18026 case PPC::BI__builtin_##Name:
18027#include "clang/Basic/BuiltinsPPC.def"
18030 for (
unsigned i = 0, e =
E->getNumArgs(); i != e; i++)
18040 if (BuiltinID == PPC::BI__builtin_mma_disassemble_acc ||
18041 BuiltinID == PPC::BI__builtin_vsx_disassemble_pair ||
18042 BuiltinID == PPC::BI__builtin_mma_disassemble_pair) {
18043 unsigned NumVecs = 2;
18044 auto Intrinsic = Intrinsic::ppc_vsx_disassemble_pair;
18045 if (BuiltinID == PPC::BI__builtin_mma_disassemble_acc) {
18047 Intrinsic = Intrinsic::ppc_mma_disassemble_acc;
18053 llvm::Type *VTy = llvm::FixedVectorType::get(
Int8Ty, 16);
18054 Value *Ptr = Ops[0];
18055 for (
unsigned i=0; i<NumVecs; i++) {
18057 llvm::ConstantInt* Index = llvm::ConstantInt::get(
IntTy, i);
18063 if (BuiltinID == PPC::BI__builtin_vsx_build_pair ||
18064 BuiltinID == PPC::BI__builtin_mma_build_acc) {
18072 std::reverse(Ops.begin() + 1, Ops.end());
18075 switch (BuiltinID) {
18076 #define CUSTOM_BUILTIN(Name, Intr, Types, Acc, Feature) \
18077 case PPC::BI__builtin_##Name: \
18078 ID = Intrinsic::ppc_##Intr; \
18079 Accumulate = Acc; \
18081 #include "clang/Basic/BuiltinsPPC.def"
18083 if (BuiltinID == PPC::BI__builtin_vsx_lxvp ||
18084 BuiltinID == PPC::BI__builtin_vsx_stxvp ||
18085 BuiltinID == PPC::BI__builtin_mma_lxvp ||
18086 BuiltinID == PPC::BI__builtin_mma_stxvp) {
18087 if (BuiltinID == PPC::BI__builtin_vsx_lxvp ||
18088 BuiltinID == PPC::BI__builtin_mma_lxvp) {
18095 return Builder.CreateCall(F, Ops,
"");
18101 CallOps.push_back(Acc);
18103 for (
unsigned i=1; i<Ops.size(); i++)
18104 CallOps.push_back(Ops[i]);
18110 case PPC::BI__builtin_ppc_compare_and_swap:
18111 case PPC::BI__builtin_ppc_compare_and_swaplp: {
18120 llvm::AtomicOrdering::Monotonic, llvm::AtomicOrdering::Monotonic,
true);
18128 Value *LoadedVal = Pair.first.getScalarVal();
18132 case PPC::BI__builtin_ppc_fetch_and_add:
18133 case PPC::BI__builtin_ppc_fetch_and_addlp: {
18135 llvm::AtomicOrdering::Monotonic);
18137 case PPC::BI__builtin_ppc_fetch_and_and:
18138 case PPC::BI__builtin_ppc_fetch_and_andlp: {
18140 llvm::AtomicOrdering::Monotonic);
18143 case PPC::BI__builtin_ppc_fetch_and_or:
18144 case PPC::BI__builtin_ppc_fetch_and_orlp: {
18146 llvm::AtomicOrdering::Monotonic);
18148 case PPC::BI__builtin_ppc_fetch_and_swap:
18149 case PPC::BI__builtin_ppc_fetch_and_swaplp: {
18151 llvm::AtomicOrdering::Monotonic);
18153 case PPC::BI__builtin_ppc_ldarx:
18154 case PPC::BI__builtin_ppc_lwarx:
18155 case PPC::BI__builtin_ppc_lharx:
18156 case PPC::BI__builtin_ppc_lbarx:
18158 case PPC::BI__builtin_ppc_mfspr: {
18164 return Builder.CreateCall(F, {Op0});
18166 case PPC::BI__builtin_ppc_mtspr: {
18173 return Builder.CreateCall(F, {Op0, Op1});
18175 case PPC::BI__builtin_ppc_popcntb: {
18177 llvm::Type *ArgType = ArgValue->
getType();
18179 return Builder.CreateCall(F, {ArgValue},
"popcntb");
18181 case PPC::BI__builtin_ppc_mtfsf: {
18191 case PPC::BI__builtin_ppc_swdiv_nochk:
18192 case PPC::BI__builtin_ppc_swdivs_nochk: {
18195 FastMathFlags FMF =
Builder.getFastMathFlags();
18196 Builder.getFastMathFlags().setFast();
18197 Value *FDiv =
Builder.CreateFDiv(Op0, Op1,
"swdiv_nochk");
18198 Builder.getFastMathFlags() &= (FMF);
18201 case PPC::BI__builtin_ppc_fric:
18203 *
this,
E, Intrinsic::rint,
18204 Intrinsic::experimental_constrained_rint))
18206 case PPC::BI__builtin_ppc_frim:
18207 case PPC::BI__builtin_ppc_frims:
18209 *
this,
E, Intrinsic::floor,
18210 Intrinsic::experimental_constrained_floor))
18212 case PPC::BI__builtin_ppc_frin:
18213 case PPC::BI__builtin_ppc_frins:
18215 *
this,
E, Intrinsic::round,
18216 Intrinsic::experimental_constrained_round))
18218 case PPC::BI__builtin_ppc_frip:
18219 case PPC::BI__builtin_ppc_frips:
18221 *
this,
E, Intrinsic::ceil,
18222 Intrinsic::experimental_constrained_ceil))
18224 case PPC::BI__builtin_ppc_friz:
18225 case PPC::BI__builtin_ppc_frizs:
18227 *
this,
E, Intrinsic::trunc,
18228 Intrinsic::experimental_constrained_trunc))
18230 case PPC::BI__builtin_ppc_fsqrt:
18231 case PPC::BI__builtin_ppc_fsqrts:
18233 *
this,
E, Intrinsic::sqrt,
18234 Intrinsic::experimental_constrained_sqrt))
18236 case PPC::BI__builtin_ppc_test_data_class: {
18241 {Op0, Op1},
"test_data_class");
18243 case PPC::BI__builtin_ppc_maxfe: {
18249 {Op0, Op1, Op2, Op3});
18251 case PPC::BI__builtin_ppc_maxfl: {
18257 {Op0, Op1, Op2, Op3});
18259 case PPC::BI__builtin_ppc_maxfs: {
18265 {Op0, Op1, Op2, Op3});
18267 case PPC::BI__builtin_ppc_minfe: {
18273 {Op0, Op1, Op2, Op3});
18275 case PPC::BI__builtin_ppc_minfl: {
18281 {Op0, Op1, Op2, Op3});
18283 case PPC::BI__builtin_ppc_minfs: {
18289 {Op0, Op1, Op2, Op3});
18291 case PPC::BI__builtin_ppc_swdiv:
18292 case PPC::BI__builtin_ppc_swdivs: {
18295 return Builder.CreateFDiv(Op0, Op1,
"swdiv");
18297 case PPC::BI__builtin_ppc_set_fpscr_rn:
18299 {EmitScalarExpr(E->getArg(0))});
18300 case PPC::BI__builtin_ppc_mffs:
18313 Attribute::getWithDereferenceableBytes(
Call->getContext(), 64));
18314 Call->addRetAttr(Attribute::getWithAlignment(
Call->getContext(), Align(4)));
18318 auto *RetTy = cast<llvm::PointerType>(CGF.
ConvertType(BuiltinRetType));
18319 if (RetTy ==
Call->getType())
18328 Attribute::getWithDereferenceableBytes(
Call->getContext(), 256));
18329 Call->addRetAttr(Attribute::getWithAlignment(
Call->getContext(), Align(8)));
18344 llvm::LoadInst *LD;
18348 if (Cov == CodeObjectVersionKind::COV_None) {
18349 StringRef Name =
"__oclc_ABI_version";
18350 auto *ABIVersionC = CGF.
CGM.
getModule().getNamedGlobal(Name);
18352 ABIVersionC =
new llvm::GlobalVariable(
18354 llvm::GlobalValue::ExternalLinkage,
nullptr, Name,
nullptr,
18355 llvm::GlobalVariable::NotThreadLocal,
18366 llvm::ConstantInt::get(CGF.
Int32Ty, CodeObjectVersionKind::COV_5));
18370 CGF.
Int8Ty, EmitAMDGPUImplicitArgPtr(CGF), 12 + Index * 2);
18374 CGF.
Int8Ty, EmitAMDGPUDispatchPtr(CGF), 4 + Index * 2);
18376 auto Result = CGF.
Builder.CreateSelect(IsCOV5, ImplicitGEP, DispatchGEP);
18380 Value *GEP =
nullptr;
18381 if (Cov >= CodeObjectVersionKind::COV_5) {
18383 GEP = CGF.
Builder.CreateConstGEP1_32(
18384 CGF.
Int8Ty, EmitAMDGPUImplicitArgPtr(CGF), 12 + Index * 2);
18387 GEP = CGF.
Builder.CreateConstGEP1_32(
18388 CGF.
Int8Ty, EmitAMDGPUDispatchPtr(CGF), 4 + Index * 2);
18395 llvm::MDNode *RNode = MDHelper.createRange(
APInt(16, 1),
18397 LD->setMetadata(llvm::LLVMContext::MD_range, RNode);
18398 LD->setMetadata(llvm::LLVMContext::MD_noundef,
18400 LD->setMetadata(llvm::LLVMContext::MD_invariant_load,
18407 const unsigned XOffset = 12;
18408 auto *DP = EmitAMDGPUDispatchPtr(CGF);
18410 auto *Offset = llvm::ConstantInt::get(CGF.
Int32Ty, XOffset + Index * 4);
18414 LD->setMetadata(llvm::LLVMContext::MD_invariant_load,
18427 llvm::AtomicOrdering &AO,
18428 llvm::SyncScope::ID &SSID) {
18429 int ord = cast<llvm::ConstantInt>(Order)->getZExtValue();
18432 assert(llvm::isValidAtomicOrderingCABI(ord));
18433 switch (
static_cast<llvm::AtomicOrderingCABI
>(ord)) {
18434 case llvm::AtomicOrderingCABI::acquire:
18435 case llvm::AtomicOrderingCABI::consume:
18436 AO = llvm::AtomicOrdering::Acquire;
18438 case llvm::AtomicOrderingCABI::release:
18439 AO = llvm::AtomicOrdering::Release;
18441 case llvm::AtomicOrderingCABI::acq_rel:
18442 AO = llvm::AtomicOrdering::AcquireRelease;
18444 case llvm::AtomicOrderingCABI::seq_cst:
18445 AO = llvm::AtomicOrdering::SequentiallyConsistent;
18447 case llvm::AtomicOrderingCABI::relaxed:
18448 AO = llvm::AtomicOrdering::Monotonic;
18454 if (llvm::getConstantStringInfo(
Scope, scp)) {
18460 int scope = cast<llvm::ConstantInt>(
Scope)->getZExtValue();
18463 SSID = llvm::SyncScope::System;
18475 SSID = llvm::SyncScope::SingleThread;
18478 SSID = llvm::SyncScope::System;
18486 llvm::Value *Arg =
nullptr;
18487 if ((ICEArguments & (1 << Idx)) == 0) {
18492 std::optional<llvm::APSInt>
Result =
18494 assert(
Result &&
"Expected argument to be a constant");
18502 switch (elementCount) {
18504 return Intrinsic::dx_dot2;
18506 return Intrinsic::dx_dot3;
18508 return Intrinsic::dx_dot4;
18512 return Intrinsic::dx_sdot;
18515 return Intrinsic::dx_udot;
18523 switch (BuiltinID) {
18524 case Builtin::BI__builtin_hlsl_all: {
18526 return Builder.CreateIntrinsic(
18531 case Builtin::BI__builtin_hlsl_any: {
18533 return Builder.CreateIntrinsic(
18538 case Builtin::BI__builtin_hlsl_elementwise_clamp: {
18544 bool IsUnsigned =
false;
18546 Ty = VecTy->getElementType();
18548 return Builder.CreateIntrinsic(
18550 IsUnsigned ? Intrinsic::dx_uclamp : Intrinsic::dx_clamp,
18553 case Builtin::BI__builtin_hlsl_dot: {
18556 llvm::Type *T0 = Op0->
getType();
18557 llvm::Type *T1 = Op1->
getType();
18558 if (!T0->isVectorTy() && !T1->isVectorTy()) {
18559 if (T0->isFloatingPointTy())
18560 return Builder.CreateFMul(Op0, Op1,
"dx.dot");
18562 if (T0->isIntegerTy())
18563 return Builder.CreateMul(Op0, Op1,
"dx.dot");
18567 "Scalar dot product is only supported on ints and floats.");
18570 assert(T0->isVectorTy() && T1->isVectorTy() &&
18571 "Dot product of vector and scalar is not supported.");
18574 assert(T0->getScalarType() == T1->getScalarType() &&
18575 "Dot product of vectors need the same element types.");
18578 [[maybe_unused]]
auto *VecTy1 =
18582 "Dot product requires vectors to be of the same size.");
18584 return Builder.CreateIntrinsic(
18585 T0->getScalarType(),
18587 VecTy0->getNumElements()),
18590 case Builtin::BI__builtin_hlsl_lerp: {
18595 llvm_unreachable(
"lerp operand must have a float representation");
18596 return Builder.CreateIntrinsic(
18600 case Builtin::BI__builtin_hlsl_length: {
18604 "length operand must have a float representation");
18609 return Builder.CreateIntrinsic(
18610 X->getType()->getScalarType(),
18612 nullptr,
"hlsl.length");
18614 case Builtin::BI__builtin_hlsl_normalize: {
18618 "normalize operand must have a float representation");
18620 return Builder.CreateIntrinsic(
18623 nullptr,
"hlsl.normalize");
18625 case Builtin::BI__builtin_hlsl_elementwise_frac: {
18628 llvm_unreachable(
"frac operand must have a float representation");
18629 return Builder.CreateIntrinsic(
18633case Builtin::BI__builtin_hlsl_elementwise_isinf: {
18635 llvm::Type *Xty = Op0->
getType();
18636 llvm::Type *retType = llvm::Type::getInt1Ty(this->
getLLVMContext());
18637 if (Xty->isVectorTy()) {
18639 retType = llvm::VectorType::get(
18640 retType, ElementCount::getFixed(XVecTy->getNumElements()));
18643 llvm_unreachable(
"isinf operand must have a float representation");
18644 return Builder.CreateIntrinsic(retType, Intrinsic::dx_isinf,
18647 case Builtin::BI__builtin_hlsl_mad: {
18652 return Builder.CreateIntrinsic(
18653 M->
getType(), Intrinsic::fmuladd,
18658 return Builder.CreateIntrinsic(
18659 M->
getType(), Intrinsic::dx_imad,
18663 return Builder.CreateNSWAdd(Mul, B);
18667 return Builder.CreateIntrinsic(
18668 M->
getType(), Intrinsic::dx_umad,
18672 return Builder.CreateNUWAdd(Mul, B);
18674 case Builtin::BI__builtin_hlsl_elementwise_rcp: {
18677 llvm_unreachable(
"rcp operand must have a float representation");
18678 llvm::Type *Ty = Op0->
getType();
18679 llvm::Type *EltTy = Ty->getScalarType();
18680 Constant *One = Ty->isVectorTy()
18681 ? ConstantVector::getSplat(
18682 ElementCount::getFixed(
18683 cast<FixedVectorType>(Ty)->getNumElements()),
18684 ConstantFP::get(EltTy, 1.0))
18685 : ConstantFP::get(EltTy, 1.0);
18686 return Builder.CreateFDiv(One, Op0,
"hlsl.rcp");
18688 case Builtin::BI__builtin_hlsl_elementwise_rsqrt: {
18691 llvm_unreachable(
"rsqrt operand must have a float representation");
18692 return Builder.CreateIntrinsic(
18696 case Builtin::BI__builtin_hlsl_elementwise_saturate: {
18699 "saturate operand must have a float representation");
18700 return Builder.CreateIntrinsic(
18703 nullptr,
"hlsl.saturate");
18705 case Builtin::BI__builtin_hlsl_wave_get_lane_index: {
18707 llvm::FunctionType::get(
IntTy, {},
false),
"__hlsl_wave_get_lane_index",
18716 constexpr const char *
Tag =
"amdgpu-as";
18718 LLVMContext &Ctx = Inst->getContext();
18720 for (
unsigned K = 2; K <
E->getNumArgs(); ++K) {
18723 if (llvm::getConstantStringInfo(
V, AS)) {
18724 MMRAs.push_back({
Tag, AS});
18729 "expected an address space name as a string literal");
18733 MMRAs.erase(llvm::unique(MMRAs), MMRAs.end());
18734 Inst->setMetadata(LLVMContext::MD_mmra, MMRAMetadata::getMD(Ctx, MMRAs));
18739 llvm::AtomicOrdering AO = llvm::AtomicOrdering::SequentiallyConsistent;
18740 llvm::SyncScope::ID SSID;
18741 switch (BuiltinID) {
18742 case AMDGPU::BI__builtin_amdgcn_div_scale:
18743 case AMDGPU::BI__builtin_amdgcn_div_scalef: {
18756 llvm::Value *Tmp =
Builder.CreateCall(Callee, {
X, Y, Z});
18759 llvm::Value *Flag =
Builder.CreateExtractValue(Tmp, 1);
18763 llvm::Value *FlagExt =
Builder.CreateZExt(Flag, RealFlagType);
18767 case AMDGPU::BI__builtin_amdgcn_div_fmas:
18768 case AMDGPU::BI__builtin_amdgcn_div_fmasf: {
18776 llvm::Value *Src3ToBool =
Builder.CreateIsNotNull(Src3);
18777 return Builder.CreateCall(F, {Src0, Src1, Src2, Src3ToBool});
18780 case AMDGPU::BI__builtin_amdgcn_ds_swizzle:
18781 return emitBuiltinWithOneOverloadedType<2>(*
this,
E,
18782 Intrinsic::amdgcn_ds_swizzle);
18783 case AMDGPU::BI__builtin_amdgcn_mov_dpp8:
18784 return emitBuiltinWithOneOverloadedType<2>(*
this,
E,
18785 Intrinsic::amdgcn_mov_dpp8);
18786 case AMDGPU::BI__builtin_amdgcn_mov_dpp:
18787 case AMDGPU::BI__builtin_amdgcn_update_dpp: {
18791 unsigned ICEArguments = 0;
18795 for (
unsigned I = 0; I !=
E->getNumArgs(); ++I) {
18798 assert(Args.size() == 5 || Args.size() == 6);
18799 if (Args.size() == 5)
18800 Args.insert(Args.begin(), llvm::PoisonValue::get(Args[0]->getType()));
18803 return Builder.CreateCall(F, Args);
18805 case AMDGPU::BI__builtin_amdgcn_permlane16:
18806 case AMDGPU::BI__builtin_amdgcn_permlanex16:
18807 return emitBuiltinWithOneOverloadedType<6>(
18809 BuiltinID == AMDGPU::BI__builtin_amdgcn_permlane16
18810 ? Intrinsic::amdgcn_permlane16
18811 : Intrinsic::amdgcn_permlanex16);
18812 case AMDGPU::BI__builtin_amdgcn_permlane64:
18813 return emitBuiltinWithOneOverloadedType<1>(*
this,
E,
18814 Intrinsic::amdgcn_permlane64);
18815 case AMDGPU::BI__builtin_amdgcn_readlane:
18816 return emitBuiltinWithOneOverloadedType<2>(*
this,
E,
18817 Intrinsic::amdgcn_readlane);
18818 case AMDGPU::BI__builtin_amdgcn_readfirstlane:
18819 return emitBuiltinWithOneOverloadedType<1>(*
this,
E,
18820 Intrinsic::amdgcn_readfirstlane);
18821 case AMDGPU::BI__builtin_amdgcn_div_fixup:
18822 case AMDGPU::BI__builtin_amdgcn_div_fixupf:
18823 case AMDGPU::BI__builtin_amdgcn_div_fixuph:
18824 return emitBuiltinWithOneOverloadedType<3>(*
this,
E,
18825 Intrinsic::amdgcn_div_fixup);
18826 case AMDGPU::BI__builtin_amdgcn_trig_preop:
18827 case AMDGPU::BI__builtin_amdgcn_trig_preopf:
18829 case AMDGPU::BI__builtin_amdgcn_rcp:
18830 case AMDGPU::BI__builtin_amdgcn_rcpf:
18831 case AMDGPU::BI__builtin_amdgcn_rcph:
18832 return emitBuiltinWithOneOverloadedType<1>(*
this,
E, Intrinsic::amdgcn_rcp);
18833 case AMDGPU::BI__builtin_amdgcn_sqrt:
18834 case AMDGPU::BI__builtin_amdgcn_sqrtf:
18835 case AMDGPU::BI__builtin_amdgcn_sqrth:
18836 return emitBuiltinWithOneOverloadedType<1>(*
this,
E,
18837 Intrinsic::amdgcn_sqrt);
18838 case AMDGPU::BI__builtin_amdgcn_rsq:
18839 case AMDGPU::BI__builtin_amdgcn_rsqf:
18840 case AMDGPU::BI__builtin_amdgcn_rsqh:
18841 return emitBuiltinWithOneOverloadedType<1>(*
this,
E, Intrinsic::amdgcn_rsq);
18842 case AMDGPU::BI__builtin_amdgcn_rsq_clamp:
18843 case AMDGPU::BI__builtin_amdgcn_rsq_clampf:
18844 return emitBuiltinWithOneOverloadedType<1>(*
this,
E,
18845 Intrinsic::amdgcn_rsq_clamp);
18846 case AMDGPU::BI__builtin_amdgcn_sinf:
18847 case AMDGPU::BI__builtin_amdgcn_sinh:
18848 return emitBuiltinWithOneOverloadedType<1>(*
this,
E, Intrinsic::amdgcn_sin);
18849 case AMDGPU::BI__builtin_amdgcn_cosf:
18850 case AMDGPU::BI__builtin_amdgcn_cosh:
18851 return emitBuiltinWithOneOverloadedType<1>(*
this,
E, Intrinsic::amdgcn_cos);
18852 case AMDGPU::BI__builtin_amdgcn_dispatch_ptr:
18853 return EmitAMDGPUDispatchPtr(*
this,
E);
18854 case AMDGPU::BI__builtin_amdgcn_logf:
18855 return emitBuiltinWithOneOverloadedType<1>(*
this,
E, Intrinsic::amdgcn_log);
18856 case AMDGPU::BI__builtin_amdgcn_exp2f:
18857 return emitBuiltinWithOneOverloadedType<1>(*
this,
E,
18858 Intrinsic::amdgcn_exp2);
18859 case AMDGPU::BI__builtin_amdgcn_log_clampf:
18860 return emitBuiltinWithOneOverloadedType<1>(*
this,
E,
18861 Intrinsic::amdgcn_log_clamp);
18862 case AMDGPU::BI__builtin_amdgcn_ldexp:
18863 case AMDGPU::BI__builtin_amdgcn_ldexpf: {
18866 llvm::Function *F =
18867 CGM.
getIntrinsic(Intrinsic::ldexp, {Src0->getType(), Src1->getType()});
18868 return Builder.CreateCall(F, {Src0, Src1});
18870 case AMDGPU::BI__builtin_amdgcn_ldexph: {
18875 llvm::Function *F =
18879 case AMDGPU::BI__builtin_amdgcn_frexp_mant:
18880 case AMDGPU::BI__builtin_amdgcn_frexp_mantf:
18881 case AMDGPU::BI__builtin_amdgcn_frexp_manth:
18882 return emitBuiltinWithOneOverloadedType<1>(*
this,
E,
18883 Intrinsic::amdgcn_frexp_mant);
18884 case AMDGPU::BI__builtin_amdgcn_frexp_exp:
18885 case AMDGPU::BI__builtin_amdgcn_frexp_expf: {
18889 return Builder.CreateCall(F, Src0);
18891 case AMDGPU::BI__builtin_amdgcn_frexp_exph: {
18895 return Builder.CreateCall(F, Src0);
18897 case AMDGPU::BI__builtin_amdgcn_fract:
18898 case AMDGPU::BI__builtin_amdgcn_fractf:
18899 case AMDGPU::BI__builtin_amdgcn_fracth:
18900 return emitBuiltinWithOneOverloadedType<1>(*
this,
E,
18901 Intrinsic::amdgcn_fract);
18902 case AMDGPU::BI__builtin_amdgcn_lerp:
18903 return emitBuiltinWithOneOverloadedType<3>(*
this,
E,
18904 Intrinsic::amdgcn_lerp);
18905 case AMDGPU::BI__builtin_amdgcn_ubfe:
18906 return emitBuiltinWithOneOverloadedType<3>(*
this,
E,
18907 Intrinsic::amdgcn_ubfe);
18908 case AMDGPU::BI__builtin_amdgcn_sbfe:
18909 return emitBuiltinWithOneOverloadedType<3>(*
this,
E,
18910 Intrinsic::amdgcn_sbfe);
18911 case AMDGPU::BI__builtin_amdgcn_ballot_w32:
18912 case AMDGPU::BI__builtin_amdgcn_ballot_w64: {
18916 return Builder.CreateCall(F, { Src });
18918 case AMDGPU::BI__builtin_amdgcn_uicmp:
18919 case AMDGPU::BI__builtin_amdgcn_uicmpl:
18920 case AMDGPU::BI__builtin_amdgcn_sicmp:
18921 case AMDGPU::BI__builtin_amdgcn_sicmpl: {
18928 {
Builder.getInt64Ty(), Src0->getType() });
18929 return Builder.CreateCall(F, { Src0, Src1, Src2 });
18931 case AMDGPU::BI__builtin_amdgcn_fcmp:
18932 case AMDGPU::BI__builtin_amdgcn_fcmpf: {
18939 {
Builder.getInt64Ty(), Src0->getType() });
18940 return Builder.CreateCall(F, { Src0, Src1, Src2 });
18942 case AMDGPU::BI__builtin_amdgcn_class:
18943 case AMDGPU::BI__builtin_amdgcn_classf:
18944 case AMDGPU::BI__builtin_amdgcn_classh:
18946 case AMDGPU::BI__builtin_amdgcn_fmed3f:
18947 case AMDGPU::BI__builtin_amdgcn_fmed3h:
18948 return emitBuiltinWithOneOverloadedType<3>(*
this,
E,
18949 Intrinsic::amdgcn_fmed3);
18950 case AMDGPU::BI__builtin_amdgcn_ds_append:
18951 case AMDGPU::BI__builtin_amdgcn_ds_consume: {
18952 Intrinsic::ID Intrin = BuiltinID == AMDGPU::BI__builtin_amdgcn_ds_append ?
18953 Intrinsic::amdgcn_ds_append : Intrinsic::amdgcn_ds_consume;
18958 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b64_i32:
18959 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b64_v2i32:
18960 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v4i16:
18961 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v4f16:
18962 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v4bf16:
18963 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v8i16:
18964 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v8f16:
18965 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v8bf16: {
18968 switch (BuiltinID) {
18969 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b64_i32:
18970 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b64_v2i32:
18971 IID = Intrinsic::amdgcn_global_load_tr_b64;
18973 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v4i16:
18974 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v4f16:
18975 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v4bf16:
18976 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v8i16:
18977 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v8f16:
18978 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v8bf16:
18979 IID = Intrinsic::amdgcn_global_load_tr_b128;
18985 return Builder.CreateCall(F, {Addr});
18987 case AMDGPU::BI__builtin_amdgcn_get_fpenv: {
18990 return Builder.CreateCall(F);
18992 case AMDGPU::BI__builtin_amdgcn_set_fpenv: {
18998 case AMDGPU::BI__builtin_amdgcn_read_exec:
19000 case AMDGPU::BI__builtin_amdgcn_read_exec_lo:
19002 case AMDGPU::BI__builtin_amdgcn_read_exec_hi:
19004 case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray:
19005 case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray_h:
19006 case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray_l:
19007 case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray_lh: {
19017 RayOrigin =
Builder.CreateShuffleVector(RayOrigin, RayOrigin,
19021 RayInverseDir =
Builder.CreateShuffleVector(RayInverseDir, RayInverseDir,
19025 {NodePtr->getType(), RayDir->getType()});
19026 return Builder.CreateCall(F, {NodePtr, RayExtent, RayOrigin, RayDir,
19027 RayInverseDir, TextureDescr});
19030 case AMDGPU::BI__builtin_amdgcn_ds_bvh_stack_rtn: {
19032 for (
int i = 0, e =
E->getNumArgs(); i != e; ++i)
19040 Value *I0 =
Builder.CreateInsertElement(PoisonValue::get(RetTy), Rtn,
19042 return Builder.CreateInsertElement(I0, A, 1);
19045 case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x16_bf16_w32:
19046 case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x16_bf16_tied_w32:
19047 case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x16_bf16_w64:
19048 case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x16_bf16_tied_w64:
19049 case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x16_f16_w32:
19050 case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x16_f16_tied_w32:
19051 case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x16_f16_w64:
19052 case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x16_f16_tied_w64:
19053 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf16_w32:
19054 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf16_w64:
19055 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_f16_w32:
19056 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_f16_w64:
19057 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu4_w32:
19058 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu4_w64:
19059 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu8_w32:
19060 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu8_w64:
19061 case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x16_bf16_w32_gfx12:
19062 case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x16_bf16_w64_gfx12:
19063 case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x16_f16_w32_gfx12:
19064 case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x16_f16_w64_gfx12:
19065 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf16_w32_gfx12:
19066 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf16_w64_gfx12:
19067 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_f16_w32_gfx12:
19068 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_f16_w64_gfx12:
19069 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu4_w32_gfx12:
19070 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu4_w64_gfx12:
19071 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu8_w32_gfx12:
19072 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu8_w64_gfx12:
19073 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_fp8_fp8_w32_gfx12:
19074 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_fp8_fp8_w64_gfx12:
19075 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_fp8_bf8_w32_gfx12:
19076 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_fp8_bf8_w64_gfx12:
19077 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf8_fp8_w32_gfx12:
19078 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf8_fp8_w64_gfx12:
19079 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf8_bf8_w32_gfx12:
19080 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf8_bf8_w64_gfx12:
19081 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x32_iu4_w32_gfx12:
19082 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x32_iu4_w64_gfx12:
19083 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_f16_w32:
19084 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_f16_w64:
19085 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf16_w32:
19086 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf16_w64:
19087 case AMDGPU::BI__builtin_amdgcn_swmmac_f16_16x16x32_f16_w32:
19088 case AMDGPU::BI__builtin_amdgcn_swmmac_f16_16x16x32_f16_w64:
19089 case AMDGPU::BI__builtin_amdgcn_swmmac_bf16_16x16x32_bf16_w32:
19090 case AMDGPU::BI__builtin_amdgcn_swmmac_bf16_16x16x32_bf16_w64:
19091 case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x32_iu8_w32:
19092 case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x32_iu8_w64:
19093 case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x32_iu4_w32:
19094 case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x32_iu4_w64:
19095 case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x64_iu4_w32:
19096 case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x64_iu4_w64:
19097 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_fp8_fp8_w32:
19098 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_fp8_fp8_w64:
19099 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_fp8_bf8_w32:
19100 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_fp8_bf8_w64:
19101 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf8_fp8_w32:
19102 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf8_fp8_w64:
19103 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf8_bf8_w32:
19104 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf8_bf8_w64: {
19117 bool AppendFalseForOpselArg =
false;
19118 unsigned BuiltinWMMAOp;
19120 switch (BuiltinID) {
19121 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_f16_w32:
19122 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_f16_w64:
19123 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_f16_w32_gfx12:
19124 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_f16_w64_gfx12:
19125 ArgsForMatchingMatrixTypes = {2, 0};
19126 BuiltinWMMAOp = Intrinsic::amdgcn_wmma_f32_16x16x16_f16;
19128 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf16_w32:
19129 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf16_w64:
19130 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf16_w32_gfx12:
19131 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf16_w64_gfx12:
19132 ArgsForMatchingMatrixTypes = {2, 0};
19133 BuiltinWMMAOp = Intrinsic::amdgcn_wmma_f32_16x16x16_bf16;
19135 case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x16_f16_w32_gfx12:
19136 case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x16_f16_w64_gfx12:
19137 AppendFalseForOpselArg =
true;
19139 case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x16_f16_w32:
19140 case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x16_f16_w64:
19141 ArgsForMatchingMatrixTypes = {2, 0};
19142 BuiltinWMMAOp = Intrinsic::amdgcn_wmma_f16_16x16x16_f16;
19144 case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x16_bf16_w32_gfx12:
19145 case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x16_bf16_w64_gfx12:
19146 AppendFalseForOpselArg =
true;
19148 case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x16_bf16_w32:
19149 case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x16_bf16_w64:
19150 ArgsForMatchingMatrixTypes = {2, 0};
19151 BuiltinWMMAOp = Intrinsic::amdgcn_wmma_bf16_16x16x16_bf16;
19153 case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x16_f16_tied_w32:
19154 case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x16_f16_tied_w64:
19155 ArgsForMatchingMatrixTypes = {2, 0};
19156 BuiltinWMMAOp = Intrinsic::amdgcn_wmma_f16_16x16x16_f16_tied;
19158 case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x16_bf16_tied_w32:
19159 case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x16_bf16_tied_w64:
19160 ArgsForMatchingMatrixTypes = {2, 0};
19161 BuiltinWMMAOp = Intrinsic::amdgcn_wmma_bf16_16x16x16_bf16_tied;
19163 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu8_w32:
19164 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu8_w64:
19165 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu8_w32_gfx12:
19166 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu8_w64_gfx12:
19167 ArgsForMatchingMatrixTypes = {4, 1};
19168 BuiltinWMMAOp = Intrinsic::amdgcn_wmma_i32_16x16x16_iu8;
19170 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu4_w32:
19171 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu4_w64:
19172 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu4_w32_gfx12:
19173 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu4_w64_gfx12:
19174 ArgsForMatchingMatrixTypes = {4, 1};
19175 BuiltinWMMAOp = Intrinsic::amdgcn_wmma_i32_16x16x16_iu4;
19177 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_fp8_fp8_w32_gfx12:
19178 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_fp8_fp8_w64_gfx12:
19179 ArgsForMatchingMatrixTypes = {2, 0};
19180 BuiltinWMMAOp = Intrinsic::amdgcn_wmma_f32_16x16x16_fp8_fp8;
19182 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_fp8_bf8_w32_gfx12:
19183 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_fp8_bf8_w64_gfx12:
19184 ArgsForMatchingMatrixTypes = {2, 0};
19185 BuiltinWMMAOp = Intrinsic::amdgcn_wmma_f32_16x16x16_fp8_bf8;
19187 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf8_fp8_w32_gfx12:
19188 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf8_fp8_w64_gfx12:
19189 ArgsForMatchingMatrixTypes = {2, 0};
19190 BuiltinWMMAOp = Intrinsic::amdgcn_wmma_f32_16x16x16_bf8_fp8;
19192 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf8_bf8_w32_gfx12:
19193 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf8_bf8_w64_gfx12:
19194 ArgsForMatchingMatrixTypes = {2, 0};
19195 BuiltinWMMAOp = Intrinsic::amdgcn_wmma_f32_16x16x16_bf8_bf8;
19197 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x32_iu4_w32_gfx12:
19198 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x32_iu4_w64_gfx12:
19199 ArgsForMatchingMatrixTypes = {4, 1};
19200 BuiltinWMMAOp = Intrinsic::amdgcn_wmma_i32_16x16x32_iu4;
19202 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_f16_w32:
19203 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_f16_w64:
19204 ArgsForMatchingMatrixTypes = {2, 0, 1, 3};
19205 BuiltinWMMAOp = Intrinsic::amdgcn_swmmac_f32_16x16x32_f16;
19207 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf16_w32:
19208 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf16_w64:
19209 ArgsForMatchingMatrixTypes = {2, 0, 1, 3};
19210 BuiltinWMMAOp = Intrinsic::amdgcn_swmmac_f32_16x16x32_bf16;
19212 case AMDGPU::BI__builtin_amdgcn_swmmac_f16_16x16x32_f16_w32:
19213 case AMDGPU::BI__builtin_amdgcn_swmmac_f16_16x16x32_f16_w64:
19214 ArgsForMatchingMatrixTypes = {2, 0, 1, 3};
19215 BuiltinWMMAOp = Intrinsic::amdgcn_swmmac_f16_16x16x32_f16;
19217 case AMDGPU::BI__builtin_amdgcn_swmmac_bf16_16x16x32_bf16_w32:
19218 case AMDGPU::BI__builtin_amdgcn_swmmac_bf16_16x16x32_bf16_w64:
19219 ArgsForMatchingMatrixTypes = {2, 0, 1, 3};
19220 BuiltinWMMAOp = Intrinsic::amdgcn_swmmac_bf16_16x16x32_bf16;
19222 case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x32_iu8_w32:
19223 case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x32_iu8_w64:
19224 ArgsForMatchingMatrixTypes = {4, 1, 3, 5};
19225 BuiltinWMMAOp = Intrinsic::amdgcn_swmmac_i32_16x16x32_iu8;
19227 case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x32_iu4_w32:
19228 case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x32_iu4_w64:
19229 ArgsForMatchingMatrixTypes = {4, 1, 3, 5};
19230 BuiltinWMMAOp = Intrinsic::amdgcn_swmmac_i32_16x16x32_iu4;
19232 case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x64_iu4_w32:
19233 case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x64_iu4_w64:
19234 ArgsForMatchingMatrixTypes = {4, 1, 3, 5};
19235 BuiltinWMMAOp = Intrinsic::amdgcn_swmmac_i32_16x16x64_iu4;
19237 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_fp8_fp8_w32:
19238 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_fp8_fp8_w64:
19239 ArgsForMatchingMatrixTypes = {2, 0, 1, 3};
19240 BuiltinWMMAOp = Intrinsic::amdgcn_swmmac_f32_16x16x32_fp8_fp8;
19242 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_fp8_bf8_w32:
19243 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_fp8_bf8_w64:
19244 ArgsForMatchingMatrixTypes = {2, 0, 1, 3};
19245 BuiltinWMMAOp = Intrinsic::amdgcn_swmmac_f32_16x16x32_fp8_bf8;
19247 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf8_fp8_w32:
19248 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf8_fp8_w64:
19249 ArgsForMatchingMatrixTypes = {2, 0, 1, 3};
19250 BuiltinWMMAOp = Intrinsic::amdgcn_swmmac_f32_16x16x32_bf8_fp8;
19252 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf8_bf8_w32:
19253 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf8_bf8_w64:
19254 ArgsForMatchingMatrixTypes = {2, 0, 1, 3};
19255 BuiltinWMMAOp = Intrinsic::amdgcn_swmmac_f32_16x16x32_bf8_bf8;
19260 for (
int i = 0, e =
E->getNumArgs(); i != e; ++i)
19262 if (AppendFalseForOpselArg)
19263 Args.push_back(
Builder.getFalse());
19266 for (
auto ArgIdx : ArgsForMatchingMatrixTypes)
19267 ArgTypes.push_back(Args[ArgIdx]->getType());
19270 return Builder.CreateCall(F, Args);
19274 case AMDGPU::BI__builtin_amdgcn_workitem_id_x:
19276 case AMDGPU::BI__builtin_amdgcn_workitem_id_y:
19278 case AMDGPU::BI__builtin_amdgcn_workitem_id_z:
19282 case AMDGPU::BI__builtin_amdgcn_workgroup_size_x:
19283 return EmitAMDGPUWorkGroupSize(*
this, 0);
19284 case AMDGPU::BI__builtin_amdgcn_workgroup_size_y:
19285 return EmitAMDGPUWorkGroupSize(*
this, 1);
19286 case AMDGPU::BI__builtin_amdgcn_workgroup_size_z:
19287 return EmitAMDGPUWorkGroupSize(*
this, 2);
19290 case AMDGPU::BI__builtin_amdgcn_grid_size_x:
19291 return EmitAMDGPUGridSize(*
this, 0);
19292 case AMDGPU::BI__builtin_amdgcn_grid_size_y:
19293 return EmitAMDGPUGridSize(*
this, 1);
19294 case AMDGPU::BI__builtin_amdgcn_grid_size_z:
19295 return EmitAMDGPUGridSize(*
this, 2);
19298 case AMDGPU::BI__builtin_r600_recipsqrt_ieee:
19299 case AMDGPU::BI__builtin_r600_recipsqrt_ieeef:
19300 return emitBuiltinWithOneOverloadedType<1>(*
this,
E,
19301 Intrinsic::r600_recipsqrt_ieee);
19302 case AMDGPU::BI__builtin_r600_read_tidig_x:
19304 case AMDGPU::BI__builtin_r600_read_tidig_y:
19306 case AMDGPU::BI__builtin_r600_read_tidig_z:
19308 case AMDGPU::BI__builtin_amdgcn_alignbit: {
19313 return Builder.CreateCall(F, { Src0, Src1, Src2 });
19315 case AMDGPU::BI__builtin_amdgcn_fence: {
19318 FenceInst *Fence =
Builder.CreateFence(AO, SSID);
19319 if (
E->getNumArgs() > 2)
19323 case AMDGPU::BI__builtin_amdgcn_atomic_inc32:
19324 case AMDGPU::BI__builtin_amdgcn_atomic_inc64:
19325 case AMDGPU::BI__builtin_amdgcn_atomic_dec32:
19326 case AMDGPU::BI__builtin_amdgcn_atomic_dec64:
19327 case AMDGPU::BI__builtin_amdgcn_ds_atomic_fadd_f64:
19328 case AMDGPU::BI__builtin_amdgcn_ds_atomic_fadd_f32:
19329 case AMDGPU::BI__builtin_amdgcn_ds_atomic_fadd_v2f16:
19330 case AMDGPU::BI__builtin_amdgcn_ds_atomic_fadd_v2bf16:
19331 case AMDGPU::BI__builtin_amdgcn_ds_faddf:
19332 case AMDGPU::BI__builtin_amdgcn_ds_fminf:
19333 case AMDGPU::BI__builtin_amdgcn_ds_fmaxf:
19334 case AMDGPU::BI__builtin_amdgcn_global_atomic_fadd_f32:
19335 case AMDGPU::BI__builtin_amdgcn_global_atomic_fadd_f64:
19336 case AMDGPU::BI__builtin_amdgcn_global_atomic_fadd_v2f16:
19337 case AMDGPU::BI__builtin_amdgcn_flat_atomic_fadd_v2f16:
19338 case AMDGPU::BI__builtin_amdgcn_flat_atomic_fadd_f32:
19339 case AMDGPU::BI__builtin_amdgcn_flat_atomic_fadd_f64:
19340 case AMDGPU::BI__builtin_amdgcn_global_atomic_fadd_v2bf16:
19341 case AMDGPU::BI__builtin_amdgcn_flat_atomic_fadd_v2bf16:
19342 case AMDGPU::BI__builtin_amdgcn_global_atomic_fmin_f64:
19343 case AMDGPU::BI__builtin_amdgcn_global_atomic_fmax_f64:
19344 case AMDGPU::BI__builtin_amdgcn_flat_atomic_fmin_f64:
19345 case AMDGPU::BI__builtin_amdgcn_flat_atomic_fmax_f64: {
19346 llvm::AtomicRMWInst::BinOp BinOp;
19347 switch (BuiltinID) {
19348 case AMDGPU::BI__builtin_amdgcn_atomic_inc32:
19349 case AMDGPU::BI__builtin_amdgcn_atomic_inc64:
19350 BinOp = llvm::AtomicRMWInst::UIncWrap;
19352 case AMDGPU::BI__builtin_amdgcn_atomic_dec32:
19353 case AMDGPU::BI__builtin_amdgcn_atomic_dec64:
19354 BinOp = llvm::AtomicRMWInst::UDecWrap;
19356 case AMDGPU::BI__builtin_amdgcn_ds_faddf:
19357 case AMDGPU::BI__builtin_amdgcn_ds_atomic_fadd_f64:
19358 case AMDGPU::BI__builtin_amdgcn_ds_atomic_fadd_f32:
19359 case AMDGPU::BI__builtin_amdgcn_ds_atomic_fadd_v2f16:
19360 case AMDGPU::BI__builtin_amdgcn_ds_atomic_fadd_v2bf16:
19361 case AMDGPU::BI__builtin_amdgcn_global_atomic_fadd_f32:
19362 case AMDGPU::BI__builtin_amdgcn_global_atomic_fadd_f64:
19363 case AMDGPU::BI__builtin_amdgcn_global_atomic_fadd_v2f16:
19364 case AMDGPU::BI__builtin_amdgcn_flat_atomic_fadd_v2f16:
19365 case AMDGPU::BI__builtin_amdgcn_flat_atomic_fadd_f32:
19366 case AMDGPU::BI__builtin_amdgcn_flat_atomic_fadd_f64:
19367 case AMDGPU::BI__builtin_amdgcn_global_atomic_fadd_v2bf16:
19368 case AMDGPU::BI__builtin_amdgcn_flat_atomic_fadd_v2bf16:
19369 BinOp = llvm::AtomicRMWInst::FAdd;
19371 case AMDGPU::BI__builtin_amdgcn_ds_fminf:
19372 case AMDGPU::BI__builtin_amdgcn_global_atomic_fmin_f64:
19373 case AMDGPU::BI__builtin_amdgcn_flat_atomic_fmin_f64:
19374 BinOp = llvm::AtomicRMWInst::FMin;
19376 case AMDGPU::BI__builtin_amdgcn_global_atomic_fmax_f64:
19377 case AMDGPU::BI__builtin_amdgcn_flat_atomic_fmax_f64:
19378 case AMDGPU::BI__builtin_amdgcn_ds_fmaxf:
19379 BinOp = llvm::AtomicRMWInst::FMax;
19385 llvm::Type *OrigTy = Val->
getType();
19390 if (BuiltinID == AMDGPU::BI__builtin_amdgcn_ds_faddf ||
19391 BuiltinID == AMDGPU::BI__builtin_amdgcn_ds_fminf ||
19392 BuiltinID == AMDGPU::BI__builtin_amdgcn_ds_fmaxf) {
19402 if (
E->getNumArgs() >= 4) {
19414 AO = AtomicOrdering::Monotonic;
19417 if (BuiltinID == AMDGPU::BI__builtin_amdgcn_ds_atomic_fadd_v2bf16 ||
19418 BuiltinID == AMDGPU::BI__builtin_amdgcn_global_atomic_fadd_v2bf16 ||
19419 BuiltinID == AMDGPU::BI__builtin_amdgcn_flat_atomic_fadd_v2bf16) {
19420 llvm::Type *V2BF16Ty = FixedVectorType::get(
19421 llvm::Type::getBFloatTy(
Builder.getContext()), 2);
19422 Val =
Builder.CreateBitCast(Val, V2BF16Ty);
19426 llvm::AtomicRMWInst *RMW =
19429 RMW->setVolatile(
true);
19431 unsigned AddrSpace = Ptr.
getType()->getAddressSpace();
19432 if (AddrSpace != llvm::AMDGPUAS::LOCAL_ADDRESS) {
19436 RMW->setMetadata(
"amdgpu.no.fine.grained.memory", EmptyMD);
19440 if (BinOp == llvm::AtomicRMWInst::FAdd && Val->
getType()->isFloatTy())
19441 RMW->setMetadata(
"amdgpu.ignore.denormal.mode", EmptyMD);
19444 return Builder.CreateBitCast(RMW, OrigTy);
19446 case AMDGPU::BI__builtin_amdgcn_s_sendmsg_rtn:
19447 case AMDGPU::BI__builtin_amdgcn_s_sendmsg_rtnl: {
19453 return Builder.CreateCall(F, {Arg});
19455 case AMDGPU::BI__builtin_amdgcn_make_buffer_rsrc:
19456 return emitBuiltinWithOneOverloadedType<4>(
19457 *
this,
E, Intrinsic::amdgcn_make_buffer_rsrc);
19458 case AMDGPU::BI__builtin_amdgcn_raw_buffer_store_b8:
19459 case AMDGPU::BI__builtin_amdgcn_raw_buffer_store_b16:
19460 case AMDGPU::BI__builtin_amdgcn_raw_buffer_store_b32:
19461 case AMDGPU::BI__builtin_amdgcn_raw_buffer_store_b64:
19462 case AMDGPU::BI__builtin_amdgcn_raw_buffer_store_b96:
19463 case AMDGPU::BI__builtin_amdgcn_raw_buffer_store_b128:
19464 return emitBuiltinWithOneOverloadedType<5>(
19465 *
this,
E, Intrinsic::amdgcn_raw_ptr_buffer_store);
19466 case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b8:
19467 case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b16:
19468 case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b32:
19469 case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b64:
19470 case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b96:
19471 case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b128: {
19472 llvm::Type *RetTy =
nullptr;
19473 switch (BuiltinID) {
19474 case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b8:
19477 case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b16:
19480 case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b32:
19483 case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b64:
19484 RetTy = llvm::FixedVectorType::get(
Int32Ty, 2);
19486 case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b96:
19487 RetTy = llvm::FixedVectorType::get(
Int32Ty, 3);
19489 case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b128:
19490 RetTy = llvm::FixedVectorType::get(
Int32Ty, 4);
19508 unsigned IntrinsicID,
19510 unsigned NumArgs =
E->getNumArgs() - 1;
19512 for (
unsigned I = 0; I < NumArgs; ++I)
19524 switch (BuiltinID) {
19525 case SystemZ::BI__builtin_tbegin: {
19527 Value *Control = llvm::ConstantInt::get(
Int32Ty, 0xff0c);
19529 return Builder.CreateCall(F, {TDB, Control});
19531 case SystemZ::BI__builtin_tbegin_nofloat: {
19533 Value *Control = llvm::ConstantInt::get(
Int32Ty, 0xff0c);
19535 return Builder.CreateCall(F, {TDB, Control});
19537 case SystemZ::BI__builtin_tbeginc: {
19539 Value *Control = llvm::ConstantInt::get(
Int32Ty, 0xff08);
19541 return Builder.CreateCall(F, {TDB, Control});
19543 case SystemZ::BI__builtin_tabort: {
19548 case SystemZ::BI__builtin_non_tx_store: {
19560 case SystemZ::BI__builtin_s390_vpopctb:
19561 case SystemZ::BI__builtin_s390_vpopcth:
19562 case SystemZ::BI__builtin_s390_vpopctf:
19563 case SystemZ::BI__builtin_s390_vpopctg: {
19570 case SystemZ::BI__builtin_s390_vclzb:
19571 case SystemZ::BI__builtin_s390_vclzh:
19572 case SystemZ::BI__builtin_s390_vclzf:
19573 case SystemZ::BI__builtin_s390_vclzg: {
19576 Value *Undef = ConstantInt::get(
Builder.getInt1Ty(),
false);
19578 return Builder.CreateCall(F, {
X, Undef});
19581 case SystemZ::BI__builtin_s390_vctzb:
19582 case SystemZ::BI__builtin_s390_vctzh:
19583 case SystemZ::BI__builtin_s390_vctzf:
19584 case SystemZ::BI__builtin_s390_vctzg: {
19587 Value *Undef = ConstantInt::get(
Builder.getInt1Ty(),
false);
19589 return Builder.CreateCall(F, {
X, Undef});
19592 case SystemZ::BI__builtin_s390_verllb:
19593 case SystemZ::BI__builtin_s390_verllh:
19594 case SystemZ::BI__builtin_s390_verllf:
19595 case SystemZ::BI__builtin_s390_verllg: {
19600 unsigned NumElts = cast<llvm::FixedVectorType>(ResultType)->getNumElements();
19601 Amt =
Builder.CreateIntCast(Amt, ResultType->getScalarType(),
false);
19602 Amt =
Builder.CreateVectorSplat(NumElts, Amt);
19604 return Builder.CreateCall(F, { Src, Src, Amt });
19607 case SystemZ::BI__builtin_s390_verllvb:
19608 case SystemZ::BI__builtin_s390_verllvh:
19609 case SystemZ::BI__builtin_s390_verllvf:
19610 case SystemZ::BI__builtin_s390_verllvg: {
19615 return Builder.CreateCall(F, { Src, Src, Amt });
19618 case SystemZ::BI__builtin_s390_vfsqsb:
19619 case SystemZ::BI__builtin_s390_vfsqdb: {
19622 if (
Builder.getIsFPConstrained()) {
19624 return Builder.CreateConstrainedFPCall(F, {
X });
19630 case SystemZ::BI__builtin_s390_vfmasb:
19631 case SystemZ::BI__builtin_s390_vfmadb: {
19636 if (
Builder.getIsFPConstrained()) {
19638 return Builder.CreateConstrainedFPCall(F, {
X, Y, Z});
19641 return Builder.CreateCall(F, {
X, Y, Z});
19644 case SystemZ::BI__builtin_s390_vfmssb:
19645 case SystemZ::BI__builtin_s390_vfmsdb: {
19650 if (
Builder.getIsFPConstrained()) {
19652 return Builder.CreateConstrainedFPCall(F, {
X, Y,
Builder.CreateFNeg(Z,
"neg")});
19658 case SystemZ::BI__builtin_s390_vfnmasb:
19659 case SystemZ::BI__builtin_s390_vfnmadb: {
19664 if (
Builder.getIsFPConstrained()) {
19666 return Builder.CreateFNeg(
Builder.CreateConstrainedFPCall(F, {X, Y, Z}),
"neg");
19669 return Builder.CreateFNeg(
Builder.CreateCall(F, {X, Y, Z}),
"neg");
19672 case SystemZ::BI__builtin_s390_vfnmssb:
19673 case SystemZ::BI__builtin_s390_vfnmsdb: {
19678 if (
Builder.getIsFPConstrained()) {
19681 return Builder.CreateFNeg(
Builder.CreateConstrainedFPCall(F, {X, Y, NegZ}));
19688 case SystemZ::BI__builtin_s390_vflpsb:
19689 case SystemZ::BI__builtin_s390_vflpdb: {
19695 case SystemZ::BI__builtin_s390_vflnsb:
19696 case SystemZ::BI__builtin_s390_vflndb: {
19702 case SystemZ::BI__builtin_s390_vfisb:
19703 case SystemZ::BI__builtin_s390_vfidb: {
19711 Intrinsic::ID
ID = Intrinsic::not_intrinsic;
19713 switch (M4.getZExtValue()) {
19716 switch (M5.getZExtValue()) {
19718 case 0:
ID = Intrinsic::rint;
19719 CI = Intrinsic::experimental_constrained_rint;
break;
19723 switch (M5.getZExtValue()) {
19725 case 0:
ID = Intrinsic::nearbyint;
19726 CI = Intrinsic::experimental_constrained_nearbyint;
break;
19727 case 1:
ID = Intrinsic::round;
19728 CI = Intrinsic::experimental_constrained_round;
break;
19729 case 5:
ID = Intrinsic::trunc;
19730 CI = Intrinsic::experimental_constrained_trunc;
break;
19731 case 6:
ID = Intrinsic::ceil;
19732 CI = Intrinsic::experimental_constrained_ceil;
break;
19733 case 7:
ID = Intrinsic::floor;
19734 CI = Intrinsic::experimental_constrained_floor;
break;
19738 if (ID != Intrinsic::not_intrinsic) {
19739 if (
Builder.getIsFPConstrained()) {
19741 return Builder.CreateConstrainedFPCall(F,
X);
19747 switch (BuiltinID) {
19748 case SystemZ::BI__builtin_s390_vfisb:
ID = Intrinsic::s390_vfisb;
break;
19749 case SystemZ::BI__builtin_s390_vfidb:
ID = Intrinsic::s390_vfidb;
break;
19750 default: llvm_unreachable(
"Unknown BuiltinID");
19755 return Builder.CreateCall(F, {
X, M4Value, M5Value});
19757 case SystemZ::BI__builtin_s390_vfmaxsb:
19758 case SystemZ::BI__builtin_s390_vfmaxdb: {
19766 Intrinsic::ID
ID = Intrinsic::not_intrinsic;
19768 switch (M4.getZExtValue()) {
19770 case 4:
ID = Intrinsic::maxnum;
19771 CI = Intrinsic::experimental_constrained_maxnum;
break;
19773 if (ID != Intrinsic::not_intrinsic) {
19774 if (
Builder.getIsFPConstrained()) {
19776 return Builder.CreateConstrainedFPCall(F, {
X, Y});
19779 return Builder.CreateCall(F, {
X, Y});
19782 switch (BuiltinID) {
19783 case SystemZ::BI__builtin_s390_vfmaxsb:
ID = Intrinsic::s390_vfmaxsb;
break;
19784 case SystemZ::BI__builtin_s390_vfmaxdb:
ID = Intrinsic::s390_vfmaxdb;
break;
19785 default: llvm_unreachable(
"Unknown BuiltinID");
19789 return Builder.CreateCall(F, {
X, Y, M4Value});
19791 case SystemZ::BI__builtin_s390_vfminsb:
19792 case SystemZ::BI__builtin_s390_vfmindb: {
19800 Intrinsic::ID
ID = Intrinsic::not_intrinsic;
19802 switch (M4.getZExtValue()) {
19804 case 4:
ID = Intrinsic::minnum;
19805 CI = Intrinsic::experimental_constrained_minnum;
break;
19807 if (ID != Intrinsic::not_intrinsic) {
19808 if (
Builder.getIsFPConstrained()) {
19810 return Builder.CreateConstrainedFPCall(F, {
X, Y});
19813 return Builder.CreateCall(F, {
X, Y});
19816 switch (BuiltinID) {
19817 case SystemZ::BI__builtin_s390_vfminsb:
ID = Intrinsic::s390_vfminsb;
break;
19818 case SystemZ::BI__builtin_s390_vfmindb:
ID = Intrinsic::s390_vfmindb;
break;
19819 default: llvm_unreachable(
"Unknown BuiltinID");
19823 return Builder.CreateCall(F, {
X, Y, M4Value});
19826 case SystemZ::BI__builtin_s390_vlbrh:
19827 case SystemZ::BI__builtin_s390_vlbrf:
19828 case SystemZ::BI__builtin_s390_vlbrg: {
19837#define INTRINSIC_WITH_CC(NAME) \
19838 case SystemZ::BI__builtin_##NAME: \
19839 return EmitSystemZIntrinsicWithCC(*this, Intrinsic::NAME, E)
19918#undef INTRINSIC_WITH_CC
19927struct NVPTXMmaLdstInfo {
19928 unsigned NumResults;
19934#define MMA_INTR(geom_op_type, layout) \
19935 Intrinsic::nvvm_wmma_##geom_op_type##_##layout##_stride
19936#define MMA_LDST(n, geom_op_type) \
19937 { n, MMA_INTR(geom_op_type, col), MMA_INTR(geom_op_type, row) }
19939static NVPTXMmaLdstInfo getNVPTXMmaLdstInfo(
unsigned BuiltinID) {
19940 switch (BuiltinID) {
19942 case NVPTX::BI__hmma_m16n16k16_ld_a:
19943 return MMA_LDST(8, m16n16k16_load_a_f16);
19944 case NVPTX::BI__hmma_m16n16k16_ld_b:
19945 return MMA_LDST(8, m16n16k16_load_b_f16);
19946 case NVPTX::BI__hmma_m16n16k16_ld_c_f16:
19947 return MMA_LDST(4, m16n16k16_load_c_f16);
19948 case NVPTX::BI__hmma_m16n16k16_ld_c_f32:
19949 return MMA_LDST(8, m16n16k16_load_c_f32);
19950 case NVPTX::BI__hmma_m32n8k16_ld_a:
19951 return MMA_LDST(8, m32n8k16_load_a_f16);
19952 case NVPTX::BI__hmma_m32n8k16_ld_b:
19953 return MMA_LDST(8, m32n8k16_load_b_f16);
19954 case NVPTX::BI__hmma_m32n8k16_ld_c_f16:
19955 return MMA_LDST(4, m32n8k16_load_c_f16);
19956 case NVPTX::BI__hmma_m32n8k16_ld_c_f32:
19957 return MMA_LDST(8, m32n8k16_load_c_f32);
19958 case NVPTX::BI__hmma_m8n32k16_ld_a:
19959 return MMA_LDST(8, m8n32k16_load_a_f16);
19960 case NVPTX::BI__hmma_m8n32k16_ld_b:
19961 return MMA_LDST(8, m8n32k16_load_b_f16);
19962 case NVPTX::BI__hmma_m8n32k16_ld_c_f16:
19963 return MMA_LDST(4, m8n32k16_load_c_f16);
19964 case NVPTX::BI__hmma_m8n32k16_ld_c_f32:
19965 return MMA_LDST(8, m8n32k16_load_c_f32);
19968 case NVPTX::BI__imma_m16n16k16_ld_a_s8:
19969 return MMA_LDST(2, m16n16k16_load_a_s8);
19970 case NVPTX::BI__imma_m16n16k16_ld_a_u8:
19971 return MMA_LDST(2, m16n16k16_load_a_u8);
19972 case NVPTX::BI__imma_m16n16k16_ld_b_s8:
19973 return MMA_LDST(2, m16n16k16_load_b_s8);
19974 case NVPTX::BI__imma_m16n16k16_ld_b_u8:
19975 return MMA_LDST(2, m16n16k16_load_b_u8);
19976 case NVPTX::BI__imma_m16n16k16_ld_c:
19977 return MMA_LDST(8, m16n16k16_load_c_s32);
19978 case NVPTX::BI__imma_m32n8k16_ld_a_s8:
19979 return MMA_LDST(4, m32n8k16_load_a_s8);
19980 case NVPTX::BI__imma_m32n8k16_ld_a_u8:
19981 return MMA_LDST(4, m32n8k16_load_a_u8);
19982 case NVPTX::BI__imma_m32n8k16_ld_b_s8:
19983 return MMA_LDST(1, m32n8k16_load_b_s8);
19984 case NVPTX::BI__imma_m32n8k16_ld_b_u8:
19985 return MMA_LDST(1, m32n8k16_load_b_u8);
19986 case NVPTX::BI__imma_m32n8k16_ld_c:
19987 return MMA_LDST(8, m32n8k16_load_c_s32);
19988 case NVPTX::BI__imma_m8n32k16_ld_a_s8:
19989 return MMA_LDST(1, m8n32k16_load_a_s8);
19990 case NVPTX::BI__imma_m8n32k16_ld_a_u8:
19991 return MMA_LDST(1, m8n32k16_load_a_u8);
19992 case NVPTX::BI__imma_m8n32k16_ld_b_s8:
19993 return MMA_LDST(4, m8n32k16_load_b_s8);
19994 case NVPTX::BI__imma_m8n32k16_ld_b_u8:
19995 return MMA_LDST(4, m8n32k16_load_b_u8);
19996 case NVPTX::BI__imma_m8n32k16_ld_c:
19997 return MMA_LDST(8, m8n32k16_load_c_s32);
20001 case NVPTX::BI__imma_m8n8k32_ld_a_s4:
20002 return {1, 0,
MMA_INTR(m8n8k32_load_a_s4, row)};
20003 case NVPTX::BI__imma_m8n8k32_ld_a_u4:
20004 return {1, 0,
MMA_INTR(m8n8k32_load_a_u4, row)};
20005 case NVPTX::BI__imma_m8n8k32_ld_b_s4:
20006 return {1,
MMA_INTR(m8n8k32_load_b_s4, col), 0};
20007 case NVPTX::BI__imma_m8n8k32_ld_b_u4:
20008 return {1,
MMA_INTR(m8n8k32_load_b_u4, col), 0};
20009 case NVPTX::BI__imma_m8n8k32_ld_c:
20010 return MMA_LDST(2, m8n8k32_load_c_s32);
20011 case NVPTX::BI__bmma_m8n8k128_ld_a_b1:
20012 return {1, 0,
MMA_INTR(m8n8k128_load_a_b1, row)};
20013 case NVPTX::BI__bmma_m8n8k128_ld_b_b1:
20014 return {1,
MMA_INTR(m8n8k128_load_b_b1, col), 0};
20015 case NVPTX::BI__bmma_m8n8k128_ld_c:
20016 return MMA_LDST(2, m8n8k128_load_c_s32);
20019 case NVPTX::BI__dmma_m8n8k4_ld_a:
20020 return MMA_LDST(1, m8n8k4_load_a_f64);
20021 case NVPTX::BI__dmma_m8n8k4_ld_b:
20022 return MMA_LDST(1, m8n8k4_load_b_f64);
20023 case NVPTX::BI__dmma_m8n8k4_ld_c:
20024 return MMA_LDST(2, m8n8k4_load_c_f64);
20027 case NVPTX::BI__mma_bf16_m16n16k16_ld_a:
20028 return MMA_LDST(4, m16n16k16_load_a_bf16);
20029 case NVPTX::BI__mma_bf16_m16n16k16_ld_b:
20030 return MMA_LDST(4, m16n16k16_load_b_bf16);
20031 case NVPTX::BI__mma_bf16_m8n32k16_ld_a:
20032 return MMA_LDST(2, m8n32k16_load_a_bf16);
20033 case NVPTX::BI__mma_bf16_m8n32k16_ld_b:
20034 return MMA_LDST(8, m8n32k16_load_b_bf16);
20035 case NVPTX::BI__mma_bf16_m32n8k16_ld_a:
20036 return MMA_LDST(8, m32n8k16_load_a_bf16);
20037 case NVPTX::BI__mma_bf16_m32n8k16_ld_b:
20038 return MMA_LDST(2, m32n8k16_load_b_bf16);
20039 case NVPTX::BI__mma_tf32_m16n16k8_ld_a:
20040 return MMA_LDST(4, m16n16k8_load_a_tf32);
20041 case NVPTX::BI__mma_tf32_m16n16k8_ld_b:
20042 return MMA_LDST(4, m16n16k8_load_b_tf32);
20043 case NVPTX::BI__mma_tf32_m16n16k8_ld_c:
20044 return MMA_LDST(8, m16n16k8_load_c_f32);
20050 case NVPTX::BI__hmma_m16n16k16_st_c_f16:
20051 return MMA_LDST(4, m16n16k16_store_d_f16);
20052 case NVPTX::BI__hmma_m16n16k16_st_c_f32:
20053 return MMA_LDST(8, m16n16k16_store_d_f32);
20054 case NVPTX::BI__hmma_m32n8k16_st_c_f16:
20055 return MMA_LDST(4, m32n8k16_store_d_f16);
20056 case NVPTX::BI__hmma_m32n8k16_st_c_f32:
20057 return MMA_LDST(8, m32n8k16_store_d_f32);
20058 case NVPTX::BI__hmma_m8n32k16_st_c_f16:
20059 return MMA_LDST(4, m8n32k16_store_d_f16);
20060 case NVPTX::BI__hmma_m8n32k16_st_c_f32:
20061 return MMA_LDST(8, m8n32k16_store_d_f32);
20066 case NVPTX::BI__imma_m16n16k16_st_c_i32:
20067 return MMA_LDST(8, m16n16k16_store_d_s32);
20068 case NVPTX::BI__imma_m32n8k16_st_c_i32:
20069 return MMA_LDST(8, m32n8k16_store_d_s32);
20070 case NVPTX::BI__imma_m8n32k16_st_c_i32:
20071 return MMA_LDST(8, m8n32k16_store_d_s32);
20072 case NVPTX::BI__imma_m8n8k32_st_c_i32:
20073 return MMA_LDST(2, m8n8k32_store_d_s32);
20074 case NVPTX::BI__bmma_m8n8k128_st_c_i32:
20075 return MMA_LDST(2, m8n8k128_store_d_s32);
20078 case NVPTX::BI__dmma_m8n8k4_st_c_f64:
20079 return MMA_LDST(2, m8n8k4_store_d_f64);
20082 case NVPTX::BI__mma_m16n16k8_st_c_f32:
20083 return MMA_LDST(8, m16n16k8_store_d_f32);
20086 llvm_unreachable(
"Unknown MMA builtin");
20093struct NVPTXMmaInfo {
20102 std::array<unsigned, 8> Variants;
20104 unsigned getMMAIntrinsic(
int Layout,
bool Satf) {
20105 unsigned Index = Layout + 4 * Satf;
20106 if (Index >= Variants.size())
20108 return Variants[Index];
20114static NVPTXMmaInfo getNVPTXMmaInfo(
unsigned BuiltinID) {
20116#define MMA_VARIANTS(geom, type) \
20117 Intrinsic::nvvm_wmma_##geom##_mma_row_row_##type, \
20118 Intrinsic::nvvm_wmma_##geom##_mma_row_col_##type, \
20119 Intrinsic::nvvm_wmma_##geom##_mma_col_row_##type, \
20120 Intrinsic::nvvm_wmma_##geom##_mma_col_col_##type
20121#define MMA_SATF_VARIANTS(geom, type) \
20122 MMA_VARIANTS(geom, type), \
20123 Intrinsic::nvvm_wmma_##geom##_mma_row_row_##type##_satfinite, \
20124 Intrinsic::nvvm_wmma_##geom##_mma_row_col_##type##_satfinite, \
20125 Intrinsic::nvvm_wmma_##geom##_mma_col_row_##type##_satfinite, \
20126 Intrinsic::nvvm_wmma_##geom##_mma_col_col_##type##_satfinite
20128#define MMA_VARIANTS_I4(geom, type) \
20130 Intrinsic::nvvm_wmma_##geom##_mma_row_col_##type, \
20134 Intrinsic::nvvm_wmma_##geom##_mma_row_col_##type##_satfinite, \
20138#define MMA_VARIANTS_B1_XOR(geom, type) \
20140 Intrinsic::nvvm_wmma_##geom##_mma_xor_popc_row_col_##type, \
20147#define MMA_VARIANTS_B1_AND(geom, type) \
20149 Intrinsic::nvvm_wmma_##geom##_mma_and_popc_row_col_##type, \
20157 switch (BuiltinID) {
20161 case NVPTX::BI__hmma_m16n16k16_mma_f16f16:
20163 case NVPTX::BI__hmma_m16n16k16_mma_f32f16:
20165 case NVPTX::BI__hmma_m16n16k16_mma_f16f32:
20167 case NVPTX::BI__hmma_m16n16k16_mma_f32f32:
20169 case NVPTX::BI__hmma_m32n8k16_mma_f16f16:
20171 case NVPTX::BI__hmma_m32n8k16_mma_f32f16:
20173 case NVPTX::BI__hmma_m32n8k16_mma_f16f32:
20175 case NVPTX::BI__hmma_m32n8k16_mma_f32f32:
20177 case NVPTX::BI__hmma_m8n32k16_mma_f16f16:
20179 case NVPTX::BI__hmma_m8n32k16_mma_f32f16:
20181 case NVPTX::BI__hmma_m8n32k16_mma_f16f32:
20183 case NVPTX::BI__hmma_m8n32k16_mma_f32f32:
20187 case NVPTX::BI__imma_m16n16k16_mma_s8:
20189 case NVPTX::BI__imma_m16n16k16_mma_u8:
20191 case NVPTX::BI__imma_m32n8k16_mma_s8:
20193 case NVPTX::BI__imma_m32n8k16_mma_u8:
20195 case NVPTX::BI__imma_m8n32k16_mma_s8:
20197 case NVPTX::BI__imma_m8n32k16_mma_u8:
20201 case NVPTX::BI__imma_m8n8k32_mma_s4:
20203 case NVPTX::BI__imma_m8n8k32_mma_u4:
20205 case NVPTX::BI__bmma_m8n8k128_mma_xor_popc_b1:
20207 case NVPTX::BI__bmma_m8n8k128_mma_and_popc_b1:
20211 case NVPTX::BI__dmma_m8n8k4_mma_f64:
20215 case NVPTX::BI__mma_bf16_m16n16k16_mma_f32:
20216 return {4, 4, 8, 8, {{
MMA_VARIANTS(m16n16k16, bf16)}}};
20217 case NVPTX::BI__mma_bf16_m8n32k16_mma_f32:
20218 return {2, 8, 8, 8, {{
MMA_VARIANTS(m8n32k16, bf16)}}};
20219 case NVPTX::BI__mma_bf16_m32n8k16_mma_f32:
20220 return {8, 2, 8, 8, {{
MMA_VARIANTS(m32n8k16, bf16)}}};
20221 case NVPTX::BI__mma_tf32_m16n16k8_mma_f32:
20222 return {4, 4, 8, 8, {{
MMA_VARIANTS(m16n16k8, tf32)}}};
20224 llvm_unreachable(
"Unexpected builtin ID.");
20227#undef MMA_SATF_VARIANTS
20228#undef MMA_VARIANTS_I4
20229#undef MMA_VARIANTS_B1_AND
20230#undef MMA_VARIANTS_B1_XOR
20239 return CGF.
Builder.CreateCall(
20241 {Ptr, ConstantInt::get(CGF.Builder.getInt32Ty(), Align.getQuantity())});
20247 llvm::Type *ElemTy =
20249 return CGF.
Builder.CreateCall(
20251 {Ptr, CGF.EmitScalarExpr(E->getArg(1))});
20254static Value *MakeCpAsync(
unsigned IntrinsicID,
unsigned IntrinsicIDS,
20257 return E->getNumArgs() == 3
20259 {CGF.EmitScalarExpr(E->getArg(0)),
20260 CGF.EmitScalarExpr(E->getArg(1)),
20261 CGF.EmitScalarExpr(E->getArg(2))})
20263 {CGF.EmitScalarExpr(E->getArg(0)),
20264 CGF.EmitScalarExpr(E->getArg(1))});
20267static Value *MakeHalfType(
unsigned IntrinsicID,
unsigned BuiltinID,
20270 if (!(
C.getLangOpts().NativeHalfType ||
20271 !
C.getTargetInfo().useFP16ConversionIntrinsics())) {
20273 " requires native half type support.");
20277 if (IntrinsicID == Intrinsic::nvvm_ldg_global_f ||
20278 IntrinsicID == Intrinsic::nvvm_ldu_global_f)
20279 return MakeLdgLdu(IntrinsicID, CGF,
E);
20283 auto *FTy = F->getFunctionType();
20284 unsigned ICEArguments = 0;
20286 C.GetBuiltinType(BuiltinID, Error, &ICEArguments);
20288 for (
unsigned i = 0, e =
E->getNumArgs(); i != e; ++i) {
20289 assert((ICEArguments & (1 << i)) == 0);
20291 auto *PTy = FTy->getParamType(i);
20292 if (PTy != ArgValue->
getType())
20293 ArgValue = CGF.
Builder.CreateBitCast(ArgValue, PTy);
20294 Args.push_back(ArgValue);
20297 return CGF.
Builder.CreateCall(F, Args);
20303 switch (BuiltinID) {
20304 case NVPTX::BI__nvvm_atom_add_gen_i:
20305 case NVPTX::BI__nvvm_atom_add_gen_l:
20306 case NVPTX::BI__nvvm_atom_add_gen_ll:
20309 case NVPTX::BI__nvvm_atom_sub_gen_i:
20310 case NVPTX::BI__nvvm_atom_sub_gen_l:
20311 case NVPTX::BI__nvvm_atom_sub_gen_ll:
20314 case NVPTX::BI__nvvm_atom_and_gen_i:
20315 case NVPTX::BI__nvvm_atom_and_gen_l:
20316 case NVPTX::BI__nvvm_atom_and_gen_ll:
20319 case NVPTX::BI__nvvm_atom_or_gen_i:
20320 case NVPTX::BI__nvvm_atom_or_gen_l:
20321 case NVPTX::BI__nvvm_atom_or_gen_ll:
20324 case NVPTX::BI__nvvm_atom_xor_gen_i:
20325 case NVPTX::BI__nvvm_atom_xor_gen_l:
20326 case NVPTX::BI__nvvm_atom_xor_gen_ll:
20329 case NVPTX::BI__nvvm_atom_xchg_gen_i:
20330 case NVPTX::BI__nvvm_atom_xchg_gen_l:
20331 case NVPTX::BI__nvvm_atom_xchg_gen_ll:
20334 case NVPTX::BI__nvvm_atom_max_gen_i:
20335 case NVPTX::BI__nvvm_atom_max_gen_l:
20336 case NVPTX::BI__nvvm_atom_max_gen_ll:
20339 case NVPTX::BI__nvvm_atom_max_gen_ui:
20340 case NVPTX::BI__nvvm_atom_max_gen_ul:
20341 case NVPTX::BI__nvvm_atom_max_gen_ull:
20344 case NVPTX::BI__nvvm_atom_min_gen_i:
20345 case NVPTX::BI__nvvm_atom_min_gen_l:
20346 case NVPTX::BI__nvvm_atom_min_gen_ll:
20349 case NVPTX::BI__nvvm_atom_min_gen_ui:
20350 case NVPTX::BI__nvvm_atom_min_gen_ul:
20351 case NVPTX::BI__nvvm_atom_min_gen_ull:
20354 case NVPTX::BI__nvvm_atom_cas_gen_i:
20355 case NVPTX::BI__nvvm_atom_cas_gen_l:
20356 case NVPTX::BI__nvvm_atom_cas_gen_ll:
20361 case NVPTX::BI__nvvm_atom_add_gen_f:
20362 case NVPTX::BI__nvvm_atom_add_gen_d: {
20367 AtomicOrdering::SequentiallyConsistent);
20370 case NVPTX::BI__nvvm_atom_inc_gen_ui: {
20375 return Builder.CreateCall(FnALI32, {Ptr, Val});
20378 case NVPTX::BI__nvvm_atom_dec_gen_ui: {
20383 return Builder.CreateCall(FnALD32, {Ptr, Val});
20386 case NVPTX::BI__nvvm_ldg_c:
20387 case NVPTX::BI__nvvm_ldg_sc:
20388 case NVPTX::BI__nvvm_ldg_c2:
20389 case NVPTX::BI__nvvm_ldg_sc2:
20390 case NVPTX::BI__nvvm_ldg_c4:
20391 case NVPTX::BI__nvvm_ldg_sc4:
20392 case NVPTX::BI__nvvm_ldg_s:
20393 case NVPTX::BI__nvvm_ldg_s2:
20394 case NVPTX::BI__nvvm_ldg_s4:
20395 case NVPTX::BI__nvvm_ldg_i:
20396 case NVPTX::BI__nvvm_ldg_i2:
20397 case NVPTX::BI__nvvm_ldg_i4:
20398 case NVPTX::BI__nvvm_ldg_l:
20399 case NVPTX::BI__nvvm_ldg_l2:
20400 case NVPTX::BI__nvvm_ldg_ll:
20401 case NVPTX::BI__nvvm_ldg_ll2:
20402 case NVPTX::BI__nvvm_ldg_uc:
20403 case NVPTX::BI__nvvm_ldg_uc2:
20404 case NVPTX::BI__nvvm_ldg_uc4:
20405 case NVPTX::BI__nvvm_ldg_us:
20406 case NVPTX::BI__nvvm_ldg_us2:
20407 case NVPTX::BI__nvvm_ldg_us4:
20408 case NVPTX::BI__nvvm_ldg_ui:
20409 case NVPTX::BI__nvvm_ldg_ui2:
20410 case NVPTX::BI__nvvm_ldg_ui4:
20411 case NVPTX::BI__nvvm_ldg_ul:
20412 case NVPTX::BI__nvvm_ldg_ul2:
20413 case NVPTX::BI__nvvm_ldg_ull:
20414 case NVPTX::BI__nvvm_ldg_ull2:
20418 return MakeLdgLdu(Intrinsic::nvvm_ldg_global_i, *
this,
E);
20419 case NVPTX::BI__nvvm_ldg_f:
20420 case NVPTX::BI__nvvm_ldg_f2:
20421 case NVPTX::BI__nvvm_ldg_f4:
20422 case NVPTX::BI__nvvm_ldg_d:
20423 case NVPTX::BI__nvvm_ldg_d2:
20424 return MakeLdgLdu(Intrinsic::nvvm_ldg_global_f, *
this,
E);
20426 case NVPTX::BI__nvvm_ldu_c:
20427 case NVPTX::BI__nvvm_ldu_sc:
20428 case NVPTX::BI__nvvm_ldu_c2:
20429 case NVPTX::BI__nvvm_ldu_sc2:
20430 case NVPTX::BI__nvvm_ldu_c4:
20431 case NVPTX::BI__nvvm_ldu_sc4:
20432 case NVPTX::BI__nvvm_ldu_s:
20433 case NVPTX::BI__nvvm_ldu_s2:
20434 case NVPTX::BI__nvvm_ldu_s4:
20435 case NVPTX::BI__nvvm_ldu_i:
20436 case NVPTX::BI__nvvm_ldu_i2:
20437 case NVPTX::BI__nvvm_ldu_i4:
20438 case NVPTX::BI__nvvm_ldu_l:
20439 case NVPTX::BI__nvvm_ldu_l2:
20440 case NVPTX::BI__nvvm_ldu_ll:
20441 case NVPTX::BI__nvvm_ldu_ll2:
20442 case NVPTX::BI__nvvm_ldu_uc:
20443 case NVPTX::BI__nvvm_ldu_uc2:
20444 case NVPTX::BI__nvvm_ldu_uc4:
20445 case NVPTX::BI__nvvm_ldu_us:
20446 case NVPTX::BI__nvvm_ldu_us2:
20447 case NVPTX::BI__nvvm_ldu_us4:
20448 case NVPTX::BI__nvvm_ldu_ui:
20449 case NVPTX::BI__nvvm_ldu_ui2:
20450 case NVPTX::BI__nvvm_ldu_ui4:
20451 case NVPTX::BI__nvvm_ldu_ul:
20452 case NVPTX::BI__nvvm_ldu_ul2:
20453 case NVPTX::BI__nvvm_ldu_ull:
20454 case NVPTX::BI__nvvm_ldu_ull2:
20455 return MakeLdgLdu(Intrinsic::nvvm_ldu_global_i, *
this,
E);
20456 case NVPTX::BI__nvvm_ldu_f:
20457 case NVPTX::BI__nvvm_ldu_f2:
20458 case NVPTX::BI__nvvm_ldu_f4:
20459 case NVPTX::BI__nvvm_ldu_d:
20460 case NVPTX::BI__nvvm_ldu_d2:
20461 return MakeLdgLdu(Intrinsic::nvvm_ldu_global_f, *
this,
E);
20463 case NVPTX::BI__nvvm_atom_cta_add_gen_i:
20464 case NVPTX::BI__nvvm_atom_cta_add_gen_l:
20465 case NVPTX::BI__nvvm_atom_cta_add_gen_ll:
20466 return MakeScopedAtomic(Intrinsic::nvvm_atomic_add_gen_i_cta, *
this,
E);
20467 case NVPTX::BI__nvvm_atom_sys_add_gen_i:
20468 case NVPTX::BI__nvvm_atom_sys_add_gen_l:
20469 case NVPTX::BI__nvvm_atom_sys_add_gen_ll:
20470 return MakeScopedAtomic(Intrinsic::nvvm_atomic_add_gen_i_sys, *
this,
E);
20471 case NVPTX::BI__nvvm_atom_cta_add_gen_f:
20472 case NVPTX::BI__nvvm_atom_cta_add_gen_d:
20473 return MakeScopedAtomic(Intrinsic::nvvm_atomic_add_gen_f_cta, *
this,
E);
20474 case NVPTX::BI__nvvm_atom_sys_add_gen_f:
20475 case NVPTX::BI__nvvm_atom_sys_add_gen_d:
20476 return MakeScopedAtomic(Intrinsic::nvvm_atomic_add_gen_f_sys, *
this,
E);
20477 case NVPTX::BI__nvvm_atom_cta_xchg_gen_i:
20478 case NVPTX::BI__nvvm_atom_cta_xchg_gen_l:
20479 case NVPTX::BI__nvvm_atom_cta_xchg_gen_ll:
20480 return MakeScopedAtomic(Intrinsic::nvvm_atomic_exch_gen_i_cta, *
this,
E);
20481 case NVPTX::BI__nvvm_atom_sys_xchg_gen_i:
20482 case NVPTX::BI__nvvm_atom_sys_xchg_gen_l:
20483 case NVPTX::BI__nvvm_atom_sys_xchg_gen_ll:
20484 return MakeScopedAtomic(Intrinsic::nvvm_atomic_exch_gen_i_sys, *
this,
E);
20485 case NVPTX::BI__nvvm_atom_cta_max_gen_i:
20486 case NVPTX::BI__nvvm_atom_cta_max_gen_ui:
20487 case NVPTX::BI__nvvm_atom_cta_max_gen_l:
20488 case NVPTX::BI__nvvm_atom_cta_max_gen_ul:
20489 case NVPTX::BI__nvvm_atom_cta_max_gen_ll:
20490 case NVPTX::BI__nvvm_atom_cta_max_gen_ull:
20491 return MakeScopedAtomic(Intrinsic::nvvm_atomic_max_gen_i_cta, *
this,
E);
20492 case NVPTX::BI__nvvm_atom_sys_max_gen_i:
20493 case NVPTX::BI__nvvm_atom_sys_max_gen_ui:
20494 case NVPTX::BI__nvvm_atom_sys_max_gen_l:
20495 case NVPTX::BI__nvvm_atom_sys_max_gen_ul:
20496 case NVPTX::BI__nvvm_atom_sys_max_gen_ll:
20497 case NVPTX::BI__nvvm_atom_sys_max_gen_ull:
20498 return MakeScopedAtomic(Intrinsic::nvvm_atomic_max_gen_i_sys, *
this,
E);
20499 case NVPTX::BI__nvvm_atom_cta_min_gen_i:
20500 case NVPTX::BI__nvvm_atom_cta_min_gen_ui:
20501 case NVPTX::BI__nvvm_atom_cta_min_gen_l:
20502 case NVPTX::BI__nvvm_atom_cta_min_gen_ul:
20503 case NVPTX::BI__nvvm_atom_cta_min_gen_ll:
20504 case NVPTX::BI__nvvm_atom_cta_min_gen_ull:
20505 return MakeScopedAtomic(Intrinsic::nvvm_atomic_min_gen_i_cta, *
this,
E);
20506 case NVPTX::BI__nvvm_atom_sys_min_gen_i:
20507 case NVPTX::BI__nvvm_atom_sys_min_gen_ui:
20508 case NVPTX::BI__nvvm_atom_sys_min_gen_l:
20509 case NVPTX::BI__nvvm_atom_sys_min_gen_ul:
20510 case NVPTX::BI__nvvm_atom_sys_min_gen_ll:
20511 case NVPTX::BI__nvvm_atom_sys_min_gen_ull:
20512 return MakeScopedAtomic(Intrinsic::nvvm_atomic_min_gen_i_sys, *
this,
E);
20513 case NVPTX::BI__nvvm_atom_cta_inc_gen_ui:
20514 return MakeScopedAtomic(Intrinsic::nvvm_atomic_inc_gen_i_cta, *
this,
E);
20515 case NVPTX::BI__nvvm_atom_cta_dec_gen_ui:
20516 return MakeScopedAtomic(Intrinsic::nvvm_atomic_dec_gen_i_cta, *
this,
E);
20517 case NVPTX::BI__nvvm_atom_sys_inc_gen_ui:
20518 return MakeScopedAtomic(Intrinsic::nvvm_atomic_inc_gen_i_sys, *
this,
E);
20519 case NVPTX::BI__nvvm_atom_sys_dec_gen_ui:
20520 return MakeScopedAtomic(Intrinsic::nvvm_atomic_dec_gen_i_sys, *
this,
E);
20521 case NVPTX::BI__nvvm_atom_cta_and_gen_i:
20522 case NVPTX::BI__nvvm_atom_cta_and_gen_l:
20523 case NVPTX::BI__nvvm_atom_cta_and_gen_ll:
20524 return MakeScopedAtomic(Intrinsic::nvvm_atomic_and_gen_i_cta, *
this,
E);
20525 case NVPTX::BI__nvvm_atom_sys_and_gen_i:
20526 case NVPTX::BI__nvvm_atom_sys_and_gen_l:
20527 case NVPTX::BI__nvvm_atom_sys_and_gen_ll:
20528 return MakeScopedAtomic(Intrinsic::nvvm_atomic_and_gen_i_sys, *
this,
E);
20529 case NVPTX::BI__nvvm_atom_cta_or_gen_i:
20530 case NVPTX::BI__nvvm_atom_cta_or_gen_l:
20531 case NVPTX::BI__nvvm_atom_cta_or_gen_ll:
20532 return MakeScopedAtomic(Intrinsic::nvvm_atomic_or_gen_i_cta, *
this,
E);
20533 case NVPTX::BI__nvvm_atom_sys_or_gen_i:
20534 case NVPTX::BI__nvvm_atom_sys_or_gen_l:
20535 case NVPTX::BI__nvvm_atom_sys_or_gen_ll:
20536 return MakeScopedAtomic(Intrinsic::nvvm_atomic_or_gen_i_sys, *
this,
E);
20537 case NVPTX::BI__nvvm_atom_cta_xor_gen_i:
20538 case NVPTX::BI__nvvm_atom_cta_xor_gen_l:
20539 case NVPTX::BI__nvvm_atom_cta_xor_gen_ll:
20540 return MakeScopedAtomic(Intrinsic::nvvm_atomic_xor_gen_i_cta, *
this,
E);
20541 case NVPTX::BI__nvvm_atom_sys_xor_gen_i:
20542 case NVPTX::BI__nvvm_atom_sys_xor_gen_l:
20543 case NVPTX::BI__nvvm_atom_sys_xor_gen_ll:
20544 return MakeScopedAtomic(Intrinsic::nvvm_atomic_xor_gen_i_sys, *
this,
E);
20545 case NVPTX::BI__nvvm_atom_cta_cas_gen_i:
20546 case NVPTX::BI__nvvm_atom_cta_cas_gen_l:
20547 case NVPTX::BI__nvvm_atom_cta_cas_gen_ll: {
20549 llvm::Type *ElemTy =
20553 Intrinsic::nvvm_atomic_cas_gen_i_cta, {ElemTy, Ptr->getType()}),
20554 {Ptr, EmitScalarExpr(E->getArg(1)), EmitScalarExpr(E->getArg(2))});
20556 case NVPTX::BI__nvvm_atom_sys_cas_gen_i:
20557 case NVPTX::BI__nvvm_atom_sys_cas_gen_l:
20558 case NVPTX::BI__nvvm_atom_sys_cas_gen_ll: {
20560 llvm::Type *ElemTy =
20564 Intrinsic::nvvm_atomic_cas_gen_i_sys, {ElemTy, Ptr->getType()}),
20565 {Ptr, EmitScalarExpr(E->getArg(1)), EmitScalarExpr(E->getArg(2))});
20567 case NVPTX::BI__nvvm_match_all_sync_i32p:
20568 case NVPTX::BI__nvvm_match_all_sync_i64p: {
20574 ? Intrinsic::nvvm_match_all_sync_i32p
20575 : Intrinsic::nvvm_match_all_sync_i64p),
20580 return Builder.CreateExtractValue(ResultPair, 0);
20584 case NVPTX::BI__hmma_m16n16k16_ld_a:
20585 case NVPTX::BI__hmma_m16n16k16_ld_b:
20586 case NVPTX::BI__hmma_m16n16k16_ld_c_f16:
20587 case NVPTX::BI__hmma_m16n16k16_ld_c_f32:
20588 case NVPTX::BI__hmma_m32n8k16_ld_a:
20589 case NVPTX::BI__hmma_m32n8k16_ld_b:
20590 case NVPTX::BI__hmma_m32n8k16_ld_c_f16:
20591 case NVPTX::BI__hmma_m32n8k16_ld_c_f32:
20592 case NVPTX::BI__hmma_m8n32k16_ld_a:
20593 case NVPTX::BI__hmma_m8n32k16_ld_b:
20594 case NVPTX::BI__hmma_m8n32k16_ld_c_f16:
20595 case NVPTX::BI__hmma_m8n32k16_ld_c_f32:
20597 case NVPTX::BI__imma_m16n16k16_ld_a_s8:
20598 case NVPTX::BI__imma_m16n16k16_ld_a_u8:
20599 case NVPTX::BI__imma_m16n16k16_ld_b_s8:
20600 case NVPTX::BI__imma_m16n16k16_ld_b_u8:
20601 case NVPTX::BI__imma_m16n16k16_ld_c:
20602 case NVPTX::BI__imma_m32n8k16_ld_a_s8:
20603 case NVPTX::BI__imma_m32n8k16_ld_a_u8:
20604 case NVPTX::BI__imma_m32n8k16_ld_b_s8:
20605 case NVPTX::BI__imma_m32n8k16_ld_b_u8:
20606 case NVPTX::BI__imma_m32n8k16_ld_c:
20607 case NVPTX::BI__imma_m8n32k16_ld_a_s8:
20608 case NVPTX::BI__imma_m8n32k16_ld_a_u8:
20609 case NVPTX::BI__imma_m8n32k16_ld_b_s8:
20610 case NVPTX::BI__imma_m8n32k16_ld_b_u8:
20611 case NVPTX::BI__imma_m8n32k16_ld_c:
20613 case NVPTX::BI__imma_m8n8k32_ld_a_s4:
20614 case NVPTX::BI__imma_m8n8k32_ld_a_u4:
20615 case NVPTX::BI__imma_m8n8k32_ld_b_s4:
20616 case NVPTX::BI__imma_m8n8k32_ld_b_u4:
20617 case NVPTX::BI__imma_m8n8k32_ld_c:
20618 case NVPTX::BI__bmma_m8n8k128_ld_a_b1:
20619 case NVPTX::BI__bmma_m8n8k128_ld_b_b1:
20620 case NVPTX::BI__bmma_m8n8k128_ld_c:
20622 case NVPTX::BI__dmma_m8n8k4_ld_a:
20623 case NVPTX::BI__dmma_m8n8k4_ld_b:
20624 case NVPTX::BI__dmma_m8n8k4_ld_c:
20626 case NVPTX::BI__mma_bf16_m16n16k16_ld_a:
20627 case NVPTX::BI__mma_bf16_m16n16k16_ld_b:
20628 case NVPTX::BI__mma_bf16_m8n32k16_ld_a:
20629 case NVPTX::BI__mma_bf16_m8n32k16_ld_b:
20630 case NVPTX::BI__mma_bf16_m32n8k16_ld_a:
20631 case NVPTX::BI__mma_bf16_m32n8k16_ld_b:
20632 case NVPTX::BI__mma_tf32_m16n16k8_ld_a:
20633 case NVPTX::BI__mma_tf32_m16n16k8_ld_b:
20634 case NVPTX::BI__mma_tf32_m16n16k8_ld_c: {
20638 std::optional<llvm::APSInt> isColMajorArg =
20640 if (!isColMajorArg)
20642 bool isColMajor = isColMajorArg->getSExtValue();
20643 NVPTXMmaLdstInfo II = getNVPTXMmaLdstInfo(BuiltinID);
20644 unsigned IID = isColMajor ? II.IID_col : II.IID_row;
20652 assert(II.NumResults);
20653 if (II.NumResults == 1) {
20657 for (
unsigned i = 0; i < II.NumResults; ++i) {
20662 llvm::ConstantInt::get(
IntTy, i)),
20669 case NVPTX::BI__hmma_m16n16k16_st_c_f16:
20670 case NVPTX::BI__hmma_m16n16k16_st_c_f32:
20671 case NVPTX::BI__hmma_m32n8k16_st_c_f16:
20672 case NVPTX::BI__hmma_m32n8k16_st_c_f32:
20673 case NVPTX::BI__hmma_m8n32k16_st_c_f16:
20674 case NVPTX::BI__hmma_m8n32k16_st_c_f32:
20675 case NVPTX::BI__imma_m16n16k16_st_c_i32:
20676 case NVPTX::BI__imma_m32n8k16_st_c_i32:
20677 case NVPTX::BI__imma_m8n32k16_st_c_i32:
20678 case NVPTX::BI__imma_m8n8k32_st_c_i32:
20679 case NVPTX::BI__bmma_m8n8k128_st_c_i32:
20680 case NVPTX::BI__dmma_m8n8k4_st_c_f64:
20681 case NVPTX::BI__mma_m16n16k8_st_c_f32: {
20685 std::optional<llvm::APSInt> isColMajorArg =
20687 if (!isColMajorArg)
20689 bool isColMajor = isColMajorArg->getSExtValue();
20690 NVPTXMmaLdstInfo II = getNVPTXMmaLdstInfo(BuiltinID);
20691 unsigned IID = isColMajor ? II.IID_col : II.IID_row;
20696 llvm::Type *ParamType = Intrinsic->getFunctionType()->getParamType(1);
20698 for (
unsigned i = 0; i < II.NumResults; ++i) {
20702 llvm::ConstantInt::get(
IntTy, i)),
20704 Values.push_back(
Builder.CreateBitCast(
V, ParamType));
20706 Values.push_back(Ldm);
20713 case NVPTX::BI__hmma_m16n16k16_mma_f16f16:
20714 case NVPTX::BI__hmma_m16n16k16_mma_f32f16:
20715 case NVPTX::BI__hmma_m16n16k16_mma_f32f32:
20716 case NVPTX::BI__hmma_m16n16k16_mma_f16f32:
20717 case NVPTX::BI__hmma_m32n8k16_mma_f16f16:
20718 case NVPTX::BI__hmma_m32n8k16_mma_f32f16:
20719 case NVPTX::BI__hmma_m32n8k16_mma_f32f32:
20720 case NVPTX::BI__hmma_m32n8k16_mma_f16f32:
20721 case NVPTX::BI__hmma_m8n32k16_mma_f16f16:
20722 case NVPTX::BI__hmma_m8n32k16_mma_f32f16:
20723 case NVPTX::BI__hmma_m8n32k16_mma_f32f32:
20724 case NVPTX::BI__hmma_m8n32k16_mma_f16f32:
20725 case NVPTX::BI__imma_m16n16k16_mma_s8:
20726 case NVPTX::BI__imma_m16n16k16_mma_u8:
20727 case NVPTX::BI__imma_m32n8k16_mma_s8:
20728 case NVPTX::BI__imma_m32n8k16_mma_u8:
20729 case NVPTX::BI__imma_m8n32k16_mma_s8:
20730 case NVPTX::BI__imma_m8n32k16_mma_u8:
20731 case NVPTX::BI__imma_m8n8k32_mma_s4:
20732 case NVPTX::BI__imma_m8n8k32_mma_u4:
20733 case NVPTX::BI__bmma_m8n8k128_mma_xor_popc_b1:
20734 case NVPTX::BI__bmma_m8n8k128_mma_and_popc_b1:
20735 case NVPTX::BI__dmma_m8n8k4_mma_f64:
20736 case NVPTX::BI__mma_bf16_m16n16k16_mma_f32:
20737 case NVPTX::BI__mma_bf16_m8n32k16_mma_f32:
20738 case NVPTX::BI__mma_bf16_m32n8k16_mma_f32:
20739 case NVPTX::BI__mma_tf32_m16n16k8_mma_f32: {
20744 std::optional<llvm::APSInt> LayoutArg =
20748 int Layout = LayoutArg->getSExtValue();
20749 if (Layout < 0 || Layout > 3)
20751 llvm::APSInt SatfArg;
20752 if (BuiltinID == NVPTX::BI__bmma_m8n8k128_mma_xor_popc_b1 ||
20753 BuiltinID == NVPTX::BI__bmma_m8n8k128_mma_and_popc_b1)
20755 else if (std::optional<llvm::APSInt> OptSatfArg =
20757 SatfArg = *OptSatfArg;
20760 bool Satf = SatfArg.getSExtValue();
20761 NVPTXMmaInfo MI = getNVPTXMmaInfo(BuiltinID);
20762 unsigned IID = MI.getMMAIntrinsic(Layout, Satf);
20768 llvm::Type *AType = Intrinsic->getFunctionType()->getParamType(0);
20770 for (
unsigned i = 0; i < MI.NumEltsA; ++i) {
20774 llvm::ConstantInt::get(
IntTy, i)),
20776 Values.push_back(
Builder.CreateBitCast(
V, AType));
20779 llvm::Type *BType = Intrinsic->getFunctionType()->getParamType(MI.NumEltsA);
20780 for (
unsigned i = 0; i < MI.NumEltsB; ++i) {
20784 llvm::ConstantInt::get(
IntTy, i)),
20786 Values.push_back(
Builder.CreateBitCast(
V, BType));
20789 llvm::Type *CType =
20790 Intrinsic->getFunctionType()->getParamType(MI.NumEltsA + MI.NumEltsB);
20791 for (
unsigned i = 0; i < MI.NumEltsC; ++i) {
20795 llvm::ConstantInt::get(
IntTy, i)),
20797 Values.push_back(
Builder.CreateBitCast(
V, CType));
20801 for (
unsigned i = 0; i < MI.NumEltsD; ++i)
20805 llvm::ConstantInt::get(
IntTy, i)),
20810 case NVPTX::BI__nvvm_ex2_approx_f16:
20811 return MakeHalfType(Intrinsic::nvvm_ex2_approx_f16, BuiltinID,
E, *
this);
20812 case NVPTX::BI__nvvm_ex2_approx_f16x2:
20813 return MakeHalfType(Intrinsic::nvvm_ex2_approx_f16x2, BuiltinID,
E, *
this);
20814 case NVPTX::BI__nvvm_ff2f16x2_rn:
20815 return MakeHalfType(Intrinsic::nvvm_ff2f16x2_rn, BuiltinID,
E, *
this);
20816 case NVPTX::BI__nvvm_ff2f16x2_rn_relu:
20817 return MakeHalfType(Intrinsic::nvvm_ff2f16x2_rn_relu, BuiltinID,
E, *
this);
20818 case NVPTX::BI__nvvm_ff2f16x2_rz:
20819 return MakeHalfType(Intrinsic::nvvm_ff2f16x2_rz, BuiltinID,
E, *
this);
20820 case NVPTX::BI__nvvm_ff2f16x2_rz_relu:
20821 return MakeHalfType(Intrinsic::nvvm_ff2f16x2_rz_relu, BuiltinID,
E, *
this);
20822 case NVPTX::BI__nvvm_fma_rn_f16:
20823 return MakeHalfType(Intrinsic::nvvm_fma_rn_f16, BuiltinID,
E, *
this);
20824 case NVPTX::BI__nvvm_fma_rn_f16x2:
20825 return MakeHalfType(Intrinsic::nvvm_fma_rn_f16x2, BuiltinID,
E, *
this);
20826 case NVPTX::BI__nvvm_fma_rn_ftz_f16:
20827 return MakeHalfType(Intrinsic::nvvm_fma_rn_ftz_f16, BuiltinID,
E, *
this);
20828 case NVPTX::BI__nvvm_fma_rn_ftz_f16x2:
20829 return MakeHalfType(Intrinsic::nvvm_fma_rn_ftz_f16x2, BuiltinID,
E, *
this);
20830 case NVPTX::BI__nvvm_fma_rn_ftz_relu_f16:
20831 return MakeHalfType(Intrinsic::nvvm_fma_rn_ftz_relu_f16, BuiltinID,
E,
20833 case NVPTX::BI__nvvm_fma_rn_ftz_relu_f16x2:
20834 return MakeHalfType(Intrinsic::nvvm_fma_rn_ftz_relu_f16x2, BuiltinID,
E,
20836 case NVPTX::BI__nvvm_fma_rn_ftz_sat_f16:
20837 return MakeHalfType(Intrinsic::nvvm_fma_rn_ftz_sat_f16, BuiltinID,
E,
20839 case NVPTX::BI__nvvm_fma_rn_ftz_sat_f16x2:
20840 return MakeHalfType(Intrinsic::nvvm_fma_rn_ftz_sat_f16x2, BuiltinID,
E,
20842 case NVPTX::BI__nvvm_fma_rn_relu_f16:
20843 return MakeHalfType(Intrinsic::nvvm_fma_rn_relu_f16, BuiltinID,
E, *
this);
20844 case NVPTX::BI__nvvm_fma_rn_relu_f16x2:
20845 return MakeHalfType(Intrinsic::nvvm_fma_rn_relu_f16x2, BuiltinID,
E, *
this);
20846 case NVPTX::BI__nvvm_fma_rn_sat_f16:
20847 return MakeHalfType(Intrinsic::nvvm_fma_rn_sat_f16, BuiltinID,
E, *
this);
20848 case NVPTX::BI__nvvm_fma_rn_sat_f16x2:
20849 return MakeHalfType(Intrinsic::nvvm_fma_rn_sat_f16x2, BuiltinID,
E, *
this);
20850 case NVPTX::BI__nvvm_fmax_f16:
20851 return MakeHalfType(Intrinsic::nvvm_fmax_f16, BuiltinID,
E, *
this);
20852 case NVPTX::BI__nvvm_fmax_f16x2:
20853 return MakeHalfType(Intrinsic::nvvm_fmax_f16x2, BuiltinID,
E, *
this);
20854 case NVPTX::BI__nvvm_fmax_ftz_f16:
20855 return MakeHalfType(Intrinsic::nvvm_fmax_ftz_f16, BuiltinID,
E, *
this);
20856 case NVPTX::BI__nvvm_fmax_ftz_f16x2:
20857 return MakeHalfType(Intrinsic::nvvm_fmax_ftz_f16x2, BuiltinID,
E, *
this);
20858 case NVPTX::BI__nvvm_fmax_ftz_nan_f16:
20859 return MakeHalfType(Intrinsic::nvvm_fmax_ftz_nan_f16, BuiltinID,
E, *
this);
20860 case NVPTX::BI__nvvm_fmax_ftz_nan_f16x2:
20861 return MakeHalfType(Intrinsic::nvvm_fmax_ftz_nan_f16x2, BuiltinID,
E,
20863 case NVPTX::BI__nvvm_fmax_ftz_nan_xorsign_abs_f16:
20864 return MakeHalfType(Intrinsic::nvvm_fmax_ftz_nan_xorsign_abs_f16, BuiltinID,
20866 case NVPTX::BI__nvvm_fmax_ftz_nan_xorsign_abs_f16x2:
20867 return MakeHalfType(Intrinsic::nvvm_fmax_ftz_nan_xorsign_abs_f16x2,
20868 BuiltinID,
E, *
this);
20869 case NVPTX::BI__nvvm_fmax_ftz_xorsign_abs_f16:
20870 return MakeHalfType(Intrinsic::nvvm_fmax_ftz_xorsign_abs_f16, BuiltinID,
E,
20872 case NVPTX::BI__nvvm_fmax_ftz_xorsign_abs_f16x2:
20873 return MakeHalfType(Intrinsic::nvvm_fmax_ftz_xorsign_abs_f16x2, BuiltinID,
20875 case NVPTX::BI__nvvm_fmax_nan_f16:
20876 return MakeHalfType(Intrinsic::nvvm_fmax_nan_f16, BuiltinID,
E, *
this);
20877 case NVPTX::BI__nvvm_fmax_nan_f16x2:
20878 return MakeHalfType(Intrinsic::nvvm_fmax_nan_f16x2, BuiltinID,
E, *
this);
20879 case NVPTX::BI__nvvm_fmax_nan_xorsign_abs_f16:
20880 return MakeHalfType(Intrinsic::nvvm_fmax_nan_xorsign_abs_f16, BuiltinID,
E,
20882 case NVPTX::BI__nvvm_fmax_nan_xorsign_abs_f16x2:
20883 return MakeHalfType(Intrinsic::nvvm_fmax_nan_xorsign_abs_f16x2, BuiltinID,
20885 case NVPTX::BI__nvvm_fmax_xorsign_abs_f16:
20886 return MakeHalfType(Intrinsic::nvvm_fmax_xorsign_abs_f16, BuiltinID,
E,
20888 case NVPTX::BI__nvvm_fmax_xorsign_abs_f16x2:
20889 return MakeHalfType(Intrinsic::nvvm_fmax_xorsign_abs_f16x2, BuiltinID,
E,
20891 case NVPTX::BI__nvvm_fmin_f16:
20892 return MakeHalfType(Intrinsic::nvvm_fmin_f16, BuiltinID,
E, *
this);
20893 case NVPTX::BI__nvvm_fmin_f16x2:
20894 return MakeHalfType(Intrinsic::nvvm_fmin_f16x2, BuiltinID,
E, *
this);
20895 case NVPTX::BI__nvvm_fmin_ftz_f16:
20896 return MakeHalfType(Intrinsic::nvvm_fmin_ftz_f16, BuiltinID,
E, *
this);
20897 case NVPTX::BI__nvvm_fmin_ftz_f16x2:
20898 return MakeHalfType(Intrinsic::nvvm_fmin_ftz_f16x2, BuiltinID,
E, *
this);
20899 case NVPTX::BI__nvvm_fmin_ftz_nan_f16:
20900 return MakeHalfType(Intrinsic::nvvm_fmin_ftz_nan_f16, BuiltinID,
E, *
this);
20901 case NVPTX::BI__nvvm_fmin_ftz_nan_f16x2:
20902 return MakeHalfType(Intrinsic::nvvm_fmin_ftz_nan_f16x2, BuiltinID,
E,
20904 case NVPTX::BI__nvvm_fmin_ftz_nan_xorsign_abs_f16:
20905 return MakeHalfType(Intrinsic::nvvm_fmin_ftz_nan_xorsign_abs_f16, BuiltinID,
20907 case NVPTX::BI__nvvm_fmin_ftz_nan_xorsign_abs_f16x2:
20908 return MakeHalfType(Intrinsic::nvvm_fmin_ftz_nan_xorsign_abs_f16x2,
20909 BuiltinID,
E, *
this);
20910 case NVPTX::BI__nvvm_fmin_ftz_xorsign_abs_f16:
20911 return MakeHalfType(Intrinsic::nvvm_fmin_ftz_xorsign_abs_f16, BuiltinID,
E,
20913 case NVPTX::BI__nvvm_fmin_ftz_xorsign_abs_f16x2:
20914 return MakeHalfType(Intrinsic::nvvm_fmin_ftz_xorsign_abs_f16x2, BuiltinID,
20916 case NVPTX::BI__nvvm_fmin_nan_f16:
20917 return MakeHalfType(Intrinsic::nvvm_fmin_nan_f16, BuiltinID,
E, *
this);
20918 case NVPTX::BI__nvvm_fmin_nan_f16x2:
20919 return MakeHalfType(Intrinsic::nvvm_fmin_nan_f16x2, BuiltinID,
E, *
this);
20920 case NVPTX::BI__nvvm_fmin_nan_xorsign_abs_f16:
20921 return MakeHalfType(Intrinsic::nvvm_fmin_nan_xorsign_abs_f16, BuiltinID,
E,
20923 case NVPTX::BI__nvvm_fmin_nan_xorsign_abs_f16x2:
20924 return MakeHalfType(Intrinsic::nvvm_fmin_nan_xorsign_abs_f16x2, BuiltinID,
20926 case NVPTX::BI__nvvm_fmin_xorsign_abs_f16:
20927 return MakeHalfType(Intrinsic::nvvm_fmin_xorsign_abs_f16, BuiltinID,
E,
20929 case NVPTX::BI__nvvm_fmin_xorsign_abs_f16x2:
20930 return MakeHalfType(Intrinsic::nvvm_fmin_xorsign_abs_f16x2, BuiltinID,
E,
20932 case NVPTX::BI__nvvm_ldg_h:
20933 return MakeHalfType(Intrinsic::nvvm_ldg_global_f, BuiltinID,
E, *
this);
20934 case NVPTX::BI__nvvm_ldg_h2:
20935 return MakeHalfType(Intrinsic::nvvm_ldg_global_f, BuiltinID,
E, *
this);
20936 case NVPTX::BI__nvvm_ldu_h:
20937 return MakeHalfType(Intrinsic::nvvm_ldu_global_f, BuiltinID,
E, *
this);
20938 case NVPTX::BI__nvvm_ldu_h2: {
20939 return MakeHalfType(Intrinsic::nvvm_ldu_global_f, BuiltinID,
E, *
this);
20941 case NVPTX::BI__nvvm_cp_async_ca_shared_global_4:
20942 return MakeCpAsync(Intrinsic::nvvm_cp_async_ca_shared_global_4,
20943 Intrinsic::nvvm_cp_async_ca_shared_global_4_s, *
this,
E,
20945 case NVPTX::BI__nvvm_cp_async_ca_shared_global_8:
20946 return MakeCpAsync(Intrinsic::nvvm_cp_async_ca_shared_global_8,
20947 Intrinsic::nvvm_cp_async_ca_shared_global_8_s, *
this,
E,
20949 case NVPTX::BI__nvvm_cp_async_ca_shared_global_16:
20950 return MakeCpAsync(Intrinsic::nvvm_cp_async_ca_shared_global_16,
20951 Intrinsic::nvvm_cp_async_ca_shared_global_16_s, *
this,
E,
20953 case NVPTX::BI__nvvm_cp_async_cg_shared_global_16:
20954 return MakeCpAsync(Intrinsic::nvvm_cp_async_cg_shared_global_16,
20955 Intrinsic::nvvm_cp_async_cg_shared_global_16_s, *
this,
E,
20957 case NVPTX::BI__nvvm_read_ptx_sreg_clusterid_x:
20960 case NVPTX::BI__nvvm_read_ptx_sreg_clusterid_y:
20963 case NVPTX::BI__nvvm_read_ptx_sreg_clusterid_z:
20966 case NVPTX::BI__nvvm_read_ptx_sreg_clusterid_w:
20969 case NVPTX::BI__nvvm_read_ptx_sreg_nclusterid_x:
20972 case NVPTX::BI__nvvm_read_ptx_sreg_nclusterid_y:
20975 case NVPTX::BI__nvvm_read_ptx_sreg_nclusterid_z:
20978 case NVPTX::BI__nvvm_read_ptx_sreg_nclusterid_w:
20981 case NVPTX::BI__nvvm_read_ptx_sreg_cluster_ctaid_x:
20984 case NVPTX::BI__nvvm_read_ptx_sreg_cluster_ctaid_y:
20987 case NVPTX::BI__nvvm_read_ptx_sreg_cluster_ctaid_z:
20990 case NVPTX::BI__nvvm_read_ptx_sreg_cluster_ctaid_w:
20993 case NVPTX::BI__nvvm_read_ptx_sreg_cluster_nctaid_x:
20996 case NVPTX::BI__nvvm_read_ptx_sreg_cluster_nctaid_y:
20999 case NVPTX::BI__nvvm_read_ptx_sreg_cluster_nctaid_z:
21002 case NVPTX::BI__nvvm_read_ptx_sreg_cluster_nctaid_w:
21005 case NVPTX::BI__nvvm_read_ptx_sreg_cluster_ctarank:
21008 case NVPTX::BI__nvvm_read_ptx_sreg_cluster_nctarank:
21011 case NVPTX::BI__nvvm_is_explicit_cluster:
21014 case NVPTX::BI__nvvm_isspacep_shared_cluster:
21018 case NVPTX::BI__nvvm_mapa:
21021 {EmitScalarExpr(E->getArg(0)), EmitScalarExpr(E->getArg(1))});
21022 case NVPTX::BI__nvvm_mapa_shared_cluster:
21025 {EmitScalarExpr(E->getArg(0)), EmitScalarExpr(E->getArg(1))});
21026 case NVPTX::BI__nvvm_getctarank:
21030 case NVPTX::BI__nvvm_getctarank_shared_cluster:
21034 case NVPTX::BI__nvvm_barrier_cluster_arrive:
21037 case NVPTX::BI__nvvm_barrier_cluster_arrive_relaxed:
21040 case NVPTX::BI__nvvm_barrier_cluster_wait:
21043 case NVPTX::BI__nvvm_fence_sc_cluster:
21052struct BuiltinAlignArgs {
21053 llvm::Value *Src =
nullptr;
21054 llvm::Type *SrcType =
nullptr;
21055 llvm::Value *Alignment =
nullptr;
21056 llvm::Value *Mask =
nullptr;
21057 llvm::IntegerType *IntType =
nullptr;
21065 SrcType = Src->getType();
21066 if (SrcType->isPointerTy()) {
21067 IntType = IntegerType::get(
21071 assert(SrcType->isIntegerTy());
21072 IntType = cast<llvm::IntegerType>(SrcType);
21075 Alignment = CGF.
Builder.CreateZExtOrTrunc(Alignment, IntType,
"alignment");
21076 auto *One = llvm::ConstantInt::get(IntType, 1);
21077 Mask = CGF.
Builder.CreateSub(Alignment, One,
"mask");
21084 BuiltinAlignArgs Args(
E, *
this);
21085 llvm::Value *SrcAddress = Args.Src;
21086 if (Args.SrcType->isPointerTy())
21088 Builder.CreateBitOrPointerCast(Args.Src, Args.IntType,
"src_addr");
21090 Builder.CreateAnd(SrcAddress, Args.Mask,
"set_bits"),
21091 llvm::Constant::getNullValue(Args.IntType),
"is_aligned"));
21098 BuiltinAlignArgs Args(
E, *
this);
21099 llvm::Value *SrcForMask = Args.Src;
21105 if (Args.Src->getType()->isPointerTy()) {
21115 SrcForMask =
Builder.CreateAdd(SrcForMask, Args.Mask,
"over_boundary");
21119 llvm::Value *InvertedMask =
Builder.CreateNot(Args.Mask,
"inverted_mask");
21120 llvm::Value *
Result =
nullptr;
21121 if (Args.Src->getType()->isPointerTy()) {
21123 Intrinsic::ptrmask, {Args.SrcType, Args.IntType},
21124 {SrcForMask, InvertedMask},
nullptr,
"aligned_result");
21126 Result =
Builder.CreateAnd(SrcForMask, InvertedMask,
"aligned_result");
21128 assert(
Result->getType() == Args.SrcType);
21134 switch (BuiltinID) {
21135 case WebAssembly::BI__builtin_wasm_memory_size: {
21140 return Builder.CreateCall(Callee, I);
21142 case WebAssembly::BI__builtin_wasm_memory_grow: {
21148 return Builder.CreateCall(Callee, Args);
21150 case WebAssembly::BI__builtin_wasm_tls_size: {
21153 return Builder.CreateCall(Callee);
21155 case WebAssembly::BI__builtin_wasm_tls_align: {
21158 return Builder.CreateCall(Callee);
21160 case WebAssembly::BI__builtin_wasm_tls_base: {
21162 return Builder.CreateCall(Callee);
21164 case WebAssembly::BI__builtin_wasm_throw: {
21168 return Builder.CreateCall(Callee, {
Tag, Obj});
21170 case WebAssembly::BI__builtin_wasm_rethrow: {
21172 return Builder.CreateCall(Callee);
21174 case WebAssembly::BI__builtin_wasm_memory_atomic_wait32: {
21181 case WebAssembly::BI__builtin_wasm_memory_atomic_wait64: {
21188 case WebAssembly::BI__builtin_wasm_memory_atomic_notify: {
21192 return Builder.CreateCall(Callee, {Addr, Count});
21194 case WebAssembly::BI__builtin_wasm_trunc_s_i32_f32:
21195 case WebAssembly::BI__builtin_wasm_trunc_s_i32_f64:
21196 case WebAssembly::BI__builtin_wasm_trunc_s_i64_f32:
21197 case WebAssembly::BI__builtin_wasm_trunc_s_i64_f64: {
21202 return Builder.CreateCall(Callee, {Src});
21204 case WebAssembly::BI__builtin_wasm_trunc_u_i32_f32:
21205 case WebAssembly::BI__builtin_wasm_trunc_u_i32_f64:
21206 case WebAssembly::BI__builtin_wasm_trunc_u_i64_f32:
21207 case WebAssembly::BI__builtin_wasm_trunc_u_i64_f64: {
21212 return Builder.CreateCall(Callee, {Src});
21214 case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i32_f32:
21215 case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i32_f64:
21216 case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i64_f32:
21217 case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i64_f64:
21218 case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i32x4_f32x4: {
21223 return Builder.CreateCall(Callee, {Src});
21225 case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i32_f32:
21226 case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i32_f64:
21227 case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i64_f32:
21228 case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i64_f64:
21229 case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i32x4_f32x4: {
21234 return Builder.CreateCall(Callee, {Src});
21236 case WebAssembly::BI__builtin_wasm_min_f32:
21237 case WebAssembly::BI__builtin_wasm_min_f64:
21238 case WebAssembly::BI__builtin_wasm_min_f16x8:
21239 case WebAssembly::BI__builtin_wasm_min_f32x4:
21240 case WebAssembly::BI__builtin_wasm_min_f64x2: {
21245 return Builder.CreateCall(Callee, {LHS, RHS});
21247 case WebAssembly::BI__builtin_wasm_max_f32:
21248 case WebAssembly::BI__builtin_wasm_max_f64:
21249 case WebAssembly::BI__builtin_wasm_max_f16x8:
21250 case WebAssembly::BI__builtin_wasm_max_f32x4:
21251 case WebAssembly::BI__builtin_wasm_max_f64x2: {
21256 return Builder.CreateCall(Callee, {LHS, RHS});
21258 case WebAssembly::BI__builtin_wasm_pmin_f16x8:
21259 case WebAssembly::BI__builtin_wasm_pmin_f32x4:
21260 case WebAssembly::BI__builtin_wasm_pmin_f64x2: {
21265 return Builder.CreateCall(Callee, {LHS, RHS});
21267 case WebAssembly::BI__builtin_wasm_pmax_f16x8:
21268 case WebAssembly::BI__builtin_wasm_pmax_f32x4:
21269 case WebAssembly::BI__builtin_wasm_pmax_f64x2: {
21274 return Builder.CreateCall(Callee, {LHS, RHS});
21276 case WebAssembly::BI__builtin_wasm_ceil_f32x4:
21277 case WebAssembly::BI__builtin_wasm_floor_f32x4:
21278 case WebAssembly::BI__builtin_wasm_trunc_f32x4:
21279 case WebAssembly::BI__builtin_wasm_nearest_f32x4:
21280 case WebAssembly::BI__builtin_wasm_ceil_f64x2:
21281 case WebAssembly::BI__builtin_wasm_floor_f64x2:
21282 case WebAssembly::BI__builtin_wasm_trunc_f64x2:
21283 case WebAssembly::BI__builtin_wasm_nearest_f64x2: {
21285 switch (BuiltinID) {
21286 case WebAssembly::BI__builtin_wasm_ceil_f32x4:
21287 case WebAssembly::BI__builtin_wasm_ceil_f64x2:
21288 IntNo = Intrinsic::ceil;
21290 case WebAssembly::BI__builtin_wasm_floor_f32x4:
21291 case WebAssembly::BI__builtin_wasm_floor_f64x2:
21292 IntNo = Intrinsic::floor;
21294 case WebAssembly::BI__builtin_wasm_trunc_f32x4:
21295 case WebAssembly::BI__builtin_wasm_trunc_f64x2:
21296 IntNo = Intrinsic::trunc;
21298 case WebAssembly::BI__builtin_wasm_nearest_f32x4:
21299 case WebAssembly::BI__builtin_wasm_nearest_f64x2:
21300 IntNo = Intrinsic::nearbyint;
21303 llvm_unreachable(
"unexpected builtin ID");
21309 case WebAssembly::BI__builtin_wasm_ref_null_extern: {
21311 return Builder.CreateCall(Callee);
21313 case WebAssembly::BI__builtin_wasm_ref_null_func: {
21315 return Builder.CreateCall(Callee);
21317 case WebAssembly::BI__builtin_wasm_swizzle_i8x16: {
21321 return Builder.CreateCall(Callee, {Src, Indices});
21323 case WebAssembly::BI__builtin_wasm_add_sat_s_i8x16:
21324 case WebAssembly::BI__builtin_wasm_add_sat_u_i8x16:
21325 case WebAssembly::BI__builtin_wasm_add_sat_s_i16x8:
21326 case WebAssembly::BI__builtin_wasm_add_sat_u_i16x8:
21327 case WebAssembly::BI__builtin_wasm_sub_sat_s_i8x16:
21328 case WebAssembly::BI__builtin_wasm_sub_sat_u_i8x16:
21329 case WebAssembly::BI__builtin_wasm_sub_sat_s_i16x8:
21330 case WebAssembly::BI__builtin_wasm_sub_sat_u_i16x8: {
21332 switch (BuiltinID) {
21333 case WebAssembly::BI__builtin_wasm_add_sat_s_i8x16:
21334 case WebAssembly::BI__builtin_wasm_add_sat_s_i16x8:
21335 IntNo = Intrinsic::sadd_sat;
21337 case WebAssembly::BI__builtin_wasm_add_sat_u_i8x16:
21338 case WebAssembly::BI__builtin_wasm_add_sat_u_i16x8:
21339 IntNo = Intrinsic::uadd_sat;
21341 case WebAssembly::BI__builtin_wasm_sub_sat_s_i8x16:
21342 case WebAssembly::BI__builtin_wasm_sub_sat_s_i16x8:
21343 IntNo = Intrinsic::wasm_sub_sat_signed;
21345 case WebAssembly::BI__builtin_wasm_sub_sat_u_i8x16:
21346 case WebAssembly::BI__builtin_wasm_sub_sat_u_i16x8:
21347 IntNo = Intrinsic::wasm_sub_sat_unsigned;
21350 llvm_unreachable(
"unexpected builtin ID");
21355 return Builder.CreateCall(Callee, {LHS, RHS});
21357 case WebAssembly::BI__builtin_wasm_abs_i8x16:
21358 case WebAssembly::BI__builtin_wasm_abs_i16x8:
21359 case WebAssembly::BI__builtin_wasm_abs_i32x4:
21360 case WebAssembly::BI__builtin_wasm_abs_i64x2: {
21363 Constant *
Zero = llvm::Constant::getNullValue(Vec->
getType());
21364 Value *ICmp =
Builder.CreateICmpSLT(Vec, Zero,
"abscond");
21365 return Builder.CreateSelect(ICmp, Neg, Vec,
"abs");
21367 case WebAssembly::BI__builtin_wasm_min_s_i8x16:
21368 case WebAssembly::BI__builtin_wasm_min_u_i8x16:
21369 case WebAssembly::BI__builtin_wasm_max_s_i8x16:
21370 case WebAssembly::BI__builtin_wasm_max_u_i8x16:
21371 case WebAssembly::BI__builtin_wasm_min_s_i16x8:
21372 case WebAssembly::BI__builtin_wasm_min_u_i16x8:
21373 case WebAssembly::BI__builtin_wasm_max_s_i16x8:
21374 case WebAssembly::BI__builtin_wasm_max_u_i16x8:
21375 case WebAssembly::BI__builtin_wasm_min_s_i32x4:
21376 case WebAssembly::BI__builtin_wasm_min_u_i32x4:
21377 case WebAssembly::BI__builtin_wasm_max_s_i32x4:
21378 case WebAssembly::BI__builtin_wasm_max_u_i32x4: {
21382 switch (BuiltinID) {
21383 case WebAssembly::BI__builtin_wasm_min_s_i8x16:
21384 case WebAssembly::BI__builtin_wasm_min_s_i16x8:
21385 case WebAssembly::BI__builtin_wasm_min_s_i32x4:
21386 ICmp =
Builder.CreateICmpSLT(LHS, RHS);
21388 case WebAssembly::BI__builtin_wasm_min_u_i8x16:
21389 case WebAssembly::BI__builtin_wasm_min_u_i16x8:
21390 case WebAssembly::BI__builtin_wasm_min_u_i32x4:
21391 ICmp =
Builder.CreateICmpULT(LHS, RHS);
21393 case WebAssembly::BI__builtin_wasm_max_s_i8x16:
21394 case WebAssembly::BI__builtin_wasm_max_s_i16x8:
21395 case WebAssembly::BI__builtin_wasm_max_s_i32x4:
21396 ICmp =
Builder.CreateICmpSGT(LHS, RHS);
21398 case WebAssembly::BI__builtin_wasm_max_u_i8x16:
21399 case WebAssembly::BI__builtin_wasm_max_u_i16x8:
21400 case WebAssembly::BI__builtin_wasm_max_u_i32x4:
21401 ICmp =
Builder.CreateICmpUGT(LHS, RHS);
21404 llvm_unreachable(
"unexpected builtin ID");
21406 return Builder.CreateSelect(ICmp, LHS, RHS);
21408 case WebAssembly::BI__builtin_wasm_avgr_u_i8x16:
21409 case WebAssembly::BI__builtin_wasm_avgr_u_i16x8: {
21414 return Builder.CreateCall(Callee, {LHS, RHS});
21416 case WebAssembly::BI__builtin_wasm_q15mulr_sat_s_i16x8: {
21420 return Builder.CreateCall(Callee, {LHS, RHS});
21422 case WebAssembly::BI__builtin_wasm_extadd_pairwise_i8x16_s_i16x8:
21423 case WebAssembly::BI__builtin_wasm_extadd_pairwise_i8x16_u_i16x8:
21424 case WebAssembly::BI__builtin_wasm_extadd_pairwise_i16x8_s_i32x4:
21425 case WebAssembly::BI__builtin_wasm_extadd_pairwise_i16x8_u_i32x4: {
21428 switch (BuiltinID) {
21429 case WebAssembly::BI__builtin_wasm_extadd_pairwise_i8x16_s_i16x8:
21430 case WebAssembly::BI__builtin_wasm_extadd_pairwise_i16x8_s_i32x4:
21431 IntNo = Intrinsic::wasm_extadd_pairwise_signed;
21433 case WebAssembly::BI__builtin_wasm_extadd_pairwise_i8x16_u_i16x8:
21434 case WebAssembly::BI__builtin_wasm_extadd_pairwise_i16x8_u_i32x4:
21435 IntNo = Intrinsic::wasm_extadd_pairwise_unsigned;
21438 llvm_unreachable(
"unexpected builtin ID");
21442 return Builder.CreateCall(Callee, Vec);
21444 case WebAssembly::BI__builtin_wasm_bitselect: {
21450 return Builder.CreateCall(Callee, {V1, V2,
C});
21452 case WebAssembly::BI__builtin_wasm_dot_s_i32x4_i16x8: {
21456 return Builder.CreateCall(Callee, {LHS, RHS});
21458 case WebAssembly::BI__builtin_wasm_popcnt_i8x16: {
21462 return Builder.CreateCall(Callee, {Vec});
21464 case WebAssembly::BI__builtin_wasm_any_true_v128:
21465 case WebAssembly::BI__builtin_wasm_all_true_i8x16:
21466 case WebAssembly::BI__builtin_wasm_all_true_i16x8:
21467 case WebAssembly::BI__builtin_wasm_all_true_i32x4:
21468 case WebAssembly::BI__builtin_wasm_all_true_i64x2: {
21470 switch (BuiltinID) {
21471 case WebAssembly::BI__builtin_wasm_any_true_v128:
21472 IntNo = Intrinsic::wasm_anytrue;
21474 case WebAssembly::BI__builtin_wasm_all_true_i8x16:
21475 case WebAssembly::BI__builtin_wasm_all_true_i16x8:
21476 case WebAssembly::BI__builtin_wasm_all_true_i32x4:
21477 case WebAssembly::BI__builtin_wasm_all_true_i64x2:
21478 IntNo = Intrinsic::wasm_alltrue;
21481 llvm_unreachable(
"unexpected builtin ID");
21485 return Builder.CreateCall(Callee, {Vec});
21487 case WebAssembly::BI__builtin_wasm_bitmask_i8x16:
21488 case WebAssembly::BI__builtin_wasm_bitmask_i16x8:
21489 case WebAssembly::BI__builtin_wasm_bitmask_i32x4:
21490 case WebAssembly::BI__builtin_wasm_bitmask_i64x2: {
21494 return Builder.CreateCall(Callee, {Vec});
21496 case WebAssembly::BI__builtin_wasm_abs_f32x4:
21497 case WebAssembly::BI__builtin_wasm_abs_f64x2: {
21500 return Builder.CreateCall(Callee, {Vec});
21502 case WebAssembly::BI__builtin_wasm_sqrt_f32x4:
21503 case WebAssembly::BI__builtin_wasm_sqrt_f64x2: {
21506 return Builder.CreateCall(Callee, {Vec});
21508 case WebAssembly::BI__builtin_wasm_narrow_s_i8x16_i16x8:
21509 case WebAssembly::BI__builtin_wasm_narrow_u_i8x16_i16x8:
21510 case WebAssembly::BI__builtin_wasm_narrow_s_i16x8_i32x4:
21511 case WebAssembly::BI__builtin_wasm_narrow_u_i16x8_i32x4: {
21515 switch (BuiltinID) {
21516 case WebAssembly::BI__builtin_wasm_narrow_s_i8x16_i16x8:
21517 case WebAssembly::BI__builtin_wasm_narrow_s_i16x8_i32x4:
21518 IntNo = Intrinsic::wasm_narrow_signed;
21520 case WebAssembly::BI__builtin_wasm_narrow_u_i8x16_i16x8:
21521 case WebAssembly::BI__builtin_wasm_narrow_u_i16x8_i32x4:
21522 IntNo = Intrinsic::wasm_narrow_unsigned;
21525 llvm_unreachable(
"unexpected builtin ID");
21529 return Builder.CreateCall(Callee, {Low, High});
21531 case WebAssembly::BI__builtin_wasm_trunc_sat_s_zero_f64x2_i32x4:
21532 case WebAssembly::BI__builtin_wasm_trunc_sat_u_zero_f64x2_i32x4: {
21535 switch (BuiltinID) {
21536 case WebAssembly::BI__builtin_wasm_trunc_sat_s_zero_f64x2_i32x4:
21537 IntNo = Intrinsic::fptosi_sat;
21539 case WebAssembly::BI__builtin_wasm_trunc_sat_u_zero_f64x2_i32x4:
21540 IntNo = Intrinsic::fptoui_sat;
21543 llvm_unreachable(
"unexpected builtin ID");
21545 llvm::Type *SrcT = Vec->
getType();
21546 llvm::Type *TruncT = SrcT->getWithNewType(
Builder.getInt32Ty());
21549 Value *Splat = Constant::getNullValue(TruncT);
21552 case WebAssembly::BI__builtin_wasm_shuffle_i8x16: {
21557 while (OpIdx < 18) {
21558 std::optional<llvm::APSInt> LaneConst =
21560 assert(LaneConst &&
"Constant arg isn't actually constant?");
21561 Ops[OpIdx++] = llvm::ConstantInt::get(
getLLVMContext(), *LaneConst);
21564 return Builder.CreateCall(Callee, Ops);
21566 case WebAssembly::BI__builtin_wasm_relaxed_madd_f16x8:
21567 case WebAssembly::BI__builtin_wasm_relaxed_nmadd_f16x8:
21568 case WebAssembly::BI__builtin_wasm_relaxed_madd_f32x4:
21569 case WebAssembly::BI__builtin_wasm_relaxed_nmadd_f32x4:
21570 case WebAssembly::BI__builtin_wasm_relaxed_madd_f64x2:
21571 case WebAssembly::BI__builtin_wasm_relaxed_nmadd_f64x2: {
21576 switch (BuiltinID) {
21577 case WebAssembly::BI__builtin_wasm_relaxed_madd_f16x8:
21578 case WebAssembly::BI__builtin_wasm_relaxed_madd_f32x4:
21579 case WebAssembly::BI__builtin_wasm_relaxed_madd_f64x2:
21580 IntNo = Intrinsic::wasm_relaxed_madd;
21582 case WebAssembly::BI__builtin_wasm_relaxed_nmadd_f16x8:
21583 case WebAssembly::BI__builtin_wasm_relaxed_nmadd_f32x4:
21584 case WebAssembly::BI__builtin_wasm_relaxed_nmadd_f64x2:
21585 IntNo = Intrinsic::wasm_relaxed_nmadd;
21588 llvm_unreachable(
"unexpected builtin ID");
21591 return Builder.CreateCall(Callee, {A, B,
C});
21593 case WebAssembly::BI__builtin_wasm_relaxed_laneselect_i8x16:
21594 case WebAssembly::BI__builtin_wasm_relaxed_laneselect_i16x8:
21595 case WebAssembly::BI__builtin_wasm_relaxed_laneselect_i32x4:
21596 case WebAssembly::BI__builtin_wasm_relaxed_laneselect_i64x2: {
21602 return Builder.CreateCall(Callee, {A, B,
C});
21604 case WebAssembly::BI__builtin_wasm_relaxed_swizzle_i8x16: {
21608 return Builder.CreateCall(Callee, {Src, Indices});
21610 case WebAssembly::BI__builtin_wasm_relaxed_min_f32x4:
21611 case WebAssembly::BI__builtin_wasm_relaxed_max_f32x4:
21612 case WebAssembly::BI__builtin_wasm_relaxed_min_f64x2:
21613 case WebAssembly::BI__builtin_wasm_relaxed_max_f64x2: {
21617 switch (BuiltinID) {
21618 case WebAssembly::BI__builtin_wasm_relaxed_min_f32x4:
21619 case WebAssembly::BI__builtin_wasm_relaxed_min_f64x2:
21620 IntNo = Intrinsic::wasm_relaxed_min;
21622 case WebAssembly::BI__builtin_wasm_relaxed_max_f32x4:
21623 case WebAssembly::BI__builtin_wasm_relaxed_max_f64x2:
21624 IntNo = Intrinsic::wasm_relaxed_max;
21627 llvm_unreachable(
"unexpected builtin ID");
21630 return Builder.CreateCall(Callee, {LHS, RHS});
21632 case WebAssembly::BI__builtin_wasm_relaxed_trunc_s_i32x4_f32x4:
21633 case WebAssembly::BI__builtin_wasm_relaxed_trunc_u_i32x4_f32x4:
21634 case WebAssembly::BI__builtin_wasm_relaxed_trunc_s_zero_i32x4_f64x2:
21635 case WebAssembly::BI__builtin_wasm_relaxed_trunc_u_zero_i32x4_f64x2: {
21638 switch (BuiltinID) {
21639 case WebAssembly::BI__builtin_wasm_relaxed_trunc_s_i32x4_f32x4:
21640 IntNo = Intrinsic::wasm_relaxed_trunc_signed;
21642 case WebAssembly::BI__builtin_wasm_relaxed_trunc_u_i32x4_f32x4:
21643 IntNo = Intrinsic::wasm_relaxed_trunc_unsigned;
21645 case WebAssembly::BI__builtin_wasm_relaxed_trunc_s_zero_i32x4_f64x2:
21646 IntNo = Intrinsic::wasm_relaxed_trunc_signed_zero;
21648 case WebAssembly::BI__builtin_wasm_relaxed_trunc_u_zero_i32x4_f64x2:
21649 IntNo = Intrinsic::wasm_relaxed_trunc_unsigned_zero;
21652 llvm_unreachable(
"unexpected builtin ID");
21655 return Builder.CreateCall(Callee, {Vec});
21657 case WebAssembly::BI__builtin_wasm_relaxed_q15mulr_s_i16x8: {
21661 return Builder.CreateCall(Callee, {LHS, RHS});
21663 case WebAssembly::BI__builtin_wasm_relaxed_dot_i8x16_i7x16_s_i16x8: {
21668 return Builder.CreateCall(Callee, {LHS, RHS});
21670 case WebAssembly::BI__builtin_wasm_relaxed_dot_i8x16_i7x16_add_s_i32x4: {
21675 CGM.
getIntrinsic(Intrinsic::wasm_relaxed_dot_i8x16_i7x16_add_signed);
21676 return Builder.CreateCall(Callee, {LHS, RHS, Acc});
21678 case WebAssembly::BI__builtin_wasm_relaxed_dot_bf16x8_add_f32_f32x4: {
21684 return Builder.CreateCall(Callee, {LHS, RHS, Acc});
21686 case WebAssembly::BI__builtin_wasm_loadf16_f32: {
21689 return Builder.CreateCall(Callee, {Addr});
21691 case WebAssembly::BI__builtin_wasm_storef16_f32: {
21695 return Builder.CreateCall(Callee, {Val, Addr});
21697 case WebAssembly::BI__builtin_wasm_splat_f16x8: {
21700 return Builder.CreateCall(Callee, {Val});
21702 case WebAssembly::BI__builtin_wasm_extract_lane_f16x8: {
21708 case WebAssembly::BI__builtin_wasm_replace_lane_f16x8: {
21715 case WebAssembly::BI__builtin_wasm_table_get: {
21726 "Unexpected reference type for __builtin_wasm_table_get");
21727 return Builder.CreateCall(Callee, {Table, Index});
21729 case WebAssembly::BI__builtin_wasm_table_set: {
21741 "Unexpected reference type for __builtin_wasm_table_set");
21742 return Builder.CreateCall(Callee, {Table, Index, Val});
21744 case WebAssembly::BI__builtin_wasm_table_size: {
21750 case WebAssembly::BI__builtin_wasm_table_grow: {
21763 "Unexpected reference type for __builtin_wasm_table_grow");
21765 return Builder.CreateCall(Callee, {Table, Val, NElems});
21767 case WebAssembly::BI__builtin_wasm_table_fill: {
21781 "Unexpected reference type for __builtin_wasm_table_fill");
21783 return Builder.CreateCall(Callee, {Table, Index, Val, NElems});
21785 case WebAssembly::BI__builtin_wasm_table_copy: {
21795 return Builder.CreateCall(Callee, {TableX, TableY, SrcIdx, DstIdx, NElems});
21802static std::pair<Intrinsic::ID, unsigned>
21805 unsigned BuiltinID;
21806 Intrinsic::ID IntrinsicID;
21809 static Info Infos[] = {
21810#define CUSTOM_BUILTIN_MAPPING(x,s) \
21811 { Hexagon::BI__builtin_HEXAGON_##x, Intrinsic::hexagon_##x, s },
21843#include "clang/Basic/BuiltinsHexagonMapCustomDep.def"
21844#undef CUSTOM_BUILTIN_MAPPING
21847 auto CmpInfo = [] (Info A, Info B) {
return A.BuiltinID < B.BuiltinID; };
21848 static const bool SortOnce = (llvm::sort(Infos, CmpInfo),
true);
21851 const Info *F = llvm::lower_bound(Infos, Info{BuiltinID, 0, 0}, CmpInfo);
21852 if (F == std::end(Infos) || F->BuiltinID != BuiltinID)
21853 return {Intrinsic::not_intrinsic, 0};
21855 return {F->IntrinsicID, F->VecLen};
21864 auto MakeCircOp = [
this,
E](
unsigned IntID,
bool IsLoad) {
21878 for (
unsigned i = 1, e =
E->getNumArgs(); i != e; ++i)
21884 llvm::Value *NewBase = IsLoad ?
Builder.CreateExtractValue(
Result, 1)
21888 llvm::Value *RetVal =
21898 auto MakeBrevLd = [
this,
E](
unsigned IntID, llvm::Type *DestTy) {
21915 CGM.
getIntrinsic(IntID), {BaseAddress, EmitScalarExpr(E->getArg(2))});
21918 llvm::Value *DestVal =
Builder.CreateExtractValue(
Result, 0);
21923 DestVal =
Builder.CreateTrunc(DestVal, DestTy);
21930 auto V2Q = [
this, VecLen] (llvm::Value *Vec) {
21931 Intrinsic::ID
ID = VecLen == 128 ? Intrinsic::hexagon_V6_vandvrt_128B
21932 : Intrinsic::hexagon_V6_vandvrt;
21934 {Vec,
Builder.getInt32(-1)});
21936 auto Q2V = [
this, VecLen] (llvm::Value *Pred) {
21937 Intrinsic::ID
ID = VecLen == 128 ? Intrinsic::hexagon_V6_vandqrt_128B
21938 : Intrinsic::hexagon_V6_vandqrt;
21940 {Pred,
Builder.getInt32(-1)});
21943 switch (BuiltinID) {
21947 case Hexagon::BI__builtin_HEXAGON_V6_vaddcarry:
21948 case Hexagon::BI__builtin_HEXAGON_V6_vaddcarry_128B:
21949 case Hexagon::BI__builtin_HEXAGON_V6_vsubcarry:
21950 case Hexagon::BI__builtin_HEXAGON_V6_vsubcarry_128B: {
21957 {EmitScalarExpr(E->getArg(0)), EmitScalarExpr(E->getArg(1)), PredIn});
21959 llvm::Value *PredOut =
Builder.CreateExtractValue(
Result, 1);
21967 case Hexagon::BI__builtin_HEXAGON_V6_vaddcarryo:
21968 case Hexagon::BI__builtin_HEXAGON_V6_vaddcarryo_128B:
21969 case Hexagon::BI__builtin_HEXAGON_V6_vsubcarryo:
21970 case Hexagon::BI__builtin_HEXAGON_V6_vsubcarryo_128B: {
21976 {EmitScalarExpr(E->getArg(0)), EmitScalarExpr(E->getArg(1))});
21978 llvm::Value *PredOut =
Builder.CreateExtractValue(
Result, 1);
21984 case Hexagon::BI__builtin_HEXAGON_V6_vmaskedstoreq:
21985 case Hexagon::BI__builtin_HEXAGON_V6_vmaskedstorenq:
21986 case Hexagon::BI__builtin_HEXAGON_V6_vmaskedstorentq:
21987 case Hexagon::BI__builtin_HEXAGON_V6_vmaskedstorentnq:
21988 case Hexagon::BI__builtin_HEXAGON_V6_vmaskedstoreq_128B:
21989 case Hexagon::BI__builtin_HEXAGON_V6_vmaskedstorenq_128B:
21990 case Hexagon::BI__builtin_HEXAGON_V6_vmaskedstorentq_128B:
21991 case Hexagon::BI__builtin_HEXAGON_V6_vmaskedstorentnq_128B: {
21993 const Expr *PredOp =
E->getArg(0);
21995 if (
auto *Cast = dyn_cast<ImplicitCastExpr>(PredOp)) {
21996 if (
Cast->getCastKind() == CK_BitCast)
21997 PredOp =
Cast->getSubExpr();
22000 for (
int i = 1, e =
E->getNumArgs(); i != e; ++i)
22005 case Hexagon::BI__builtin_HEXAGON_L2_loadrub_pci:
22006 case Hexagon::BI__builtin_HEXAGON_L2_loadrb_pci:
22007 case Hexagon::BI__builtin_HEXAGON_L2_loadruh_pci:
22008 case Hexagon::BI__builtin_HEXAGON_L2_loadrh_pci:
22009 case Hexagon::BI__builtin_HEXAGON_L2_loadri_pci:
22010 case Hexagon::BI__builtin_HEXAGON_L2_loadrd_pci:
22011 case Hexagon::BI__builtin_HEXAGON_L2_loadrub_pcr:
22012 case Hexagon::BI__builtin_HEXAGON_L2_loadrb_pcr:
22013 case Hexagon::BI__builtin_HEXAGON_L2_loadruh_pcr:
22014 case Hexagon::BI__builtin_HEXAGON_L2_loadrh_pcr:
22015 case Hexagon::BI__builtin_HEXAGON_L2_loadri_pcr:
22016 case Hexagon::BI__builtin_HEXAGON_L2_loadrd_pcr:
22017 return MakeCircOp(ID,
true);
22018 case Hexagon::BI__builtin_HEXAGON_S2_storerb_pci:
22019 case Hexagon::BI__builtin_HEXAGON_S2_storerh_pci:
22020 case Hexagon::BI__builtin_HEXAGON_S2_storerf_pci:
22021 case Hexagon::BI__builtin_HEXAGON_S2_storeri_pci:
22022 case Hexagon::BI__builtin_HEXAGON_S2_storerd_pci:
22023 case Hexagon::BI__builtin_HEXAGON_S2_storerb_pcr:
22024 case Hexagon::BI__builtin_HEXAGON_S2_storerh_pcr:
22025 case Hexagon::BI__builtin_HEXAGON_S2_storerf_pcr:
22026 case Hexagon::BI__builtin_HEXAGON_S2_storeri_pcr:
22027 case Hexagon::BI__builtin_HEXAGON_S2_storerd_pcr:
22028 return MakeCircOp(ID,
false);
22029 case Hexagon::BI__builtin_brev_ldub:
22030 return MakeBrevLd(Intrinsic::hexagon_L2_loadrub_pbr,
Int8Ty);
22031 case Hexagon::BI__builtin_brev_ldb:
22032 return MakeBrevLd(Intrinsic::hexagon_L2_loadrb_pbr,
Int8Ty);
22033 case Hexagon::BI__builtin_brev_lduh:
22034 return MakeBrevLd(Intrinsic::hexagon_L2_loadruh_pbr,
Int16Ty);
22035 case Hexagon::BI__builtin_brev_ldh:
22036 return MakeBrevLd(Intrinsic::hexagon_L2_loadrh_pbr,
Int16Ty);
22037 case Hexagon::BI__builtin_brev_ldw:
22038 return MakeBrevLd(Intrinsic::hexagon_L2_loadri_pbr,
Int32Ty);
22039 case Hexagon::BI__builtin_brev_ldd:
22040 return MakeBrevLd(Intrinsic::hexagon_L2_loadrd_pbr,
Int64Ty);
22050 if (BuiltinID == Builtin::BI__builtin_cpu_supports)
22052 if (BuiltinID == Builtin::BI__builtin_cpu_init)
22059 unsigned ICEArguments = 0;
22067 if (BuiltinID == RISCVVector::BI__builtin_rvv_vget_v ||
22068 BuiltinID == RISCVVector::BI__builtin_rvv_vset_v)
22069 ICEArguments = 1 << 1;
22074 if (BuiltinID == RISCV::BI__builtin_riscv_ntl_load)
22075 ICEArguments |= (1 << 1);
22076 if (BuiltinID == RISCV::BI__builtin_riscv_ntl_store)
22077 ICEArguments |= (1 << 2);
22079 for (
unsigned i = 0, e =
E->getNumArgs(); i != e; i++) {
22084 Ops.push_back(AggValue);
22090 Intrinsic::ID
ID = Intrinsic::not_intrinsic;
22094 constexpr unsigned RVV_VTA = 0x1;
22095 constexpr unsigned RVV_VMA = 0x2;
22096 int PolicyAttrs = 0;
22097 bool IsMasked =
false;
22101 switch (BuiltinID) {
22102 default: llvm_unreachable(
"unexpected builtin ID");
22103 case RISCV::BI__builtin_riscv_orc_b_32:
22104 case RISCV::BI__builtin_riscv_orc_b_64:
22105 case RISCV::BI__builtin_riscv_clz_32:
22106 case RISCV::BI__builtin_riscv_clz_64:
22107 case RISCV::BI__builtin_riscv_ctz_32:
22108 case RISCV::BI__builtin_riscv_ctz_64:
22109 case RISCV::BI__builtin_riscv_clmul_32:
22110 case RISCV::BI__builtin_riscv_clmul_64:
22111 case RISCV::BI__builtin_riscv_clmulh_32:
22112 case RISCV::BI__builtin_riscv_clmulh_64:
22113 case RISCV::BI__builtin_riscv_clmulr_32:
22114 case RISCV::BI__builtin_riscv_clmulr_64:
22115 case RISCV::BI__builtin_riscv_xperm4_32:
22116 case RISCV::BI__builtin_riscv_xperm4_64:
22117 case RISCV::BI__builtin_riscv_xperm8_32:
22118 case RISCV::BI__builtin_riscv_xperm8_64:
22119 case RISCV::BI__builtin_riscv_brev8_32:
22120 case RISCV::BI__builtin_riscv_brev8_64:
22121 case RISCV::BI__builtin_riscv_zip_32:
22122 case RISCV::BI__builtin_riscv_unzip_32: {
22123 switch (BuiltinID) {
22124 default: llvm_unreachable(
"unexpected builtin ID");
22126 case RISCV::BI__builtin_riscv_orc_b_32:
22127 case RISCV::BI__builtin_riscv_orc_b_64:
22128 ID = Intrinsic::riscv_orc_b;
22130 case RISCV::BI__builtin_riscv_clz_32:
22131 case RISCV::BI__builtin_riscv_clz_64: {
22134 if (
Result->getType() != ResultType)
22139 case RISCV::BI__builtin_riscv_ctz_32:
22140 case RISCV::BI__builtin_riscv_ctz_64: {
22143 if (
Result->getType() != ResultType)
22150 case RISCV::BI__builtin_riscv_clmul_32:
22151 case RISCV::BI__builtin_riscv_clmul_64:
22152 ID = Intrinsic::riscv_clmul;
22154 case RISCV::BI__builtin_riscv_clmulh_32:
22155 case RISCV::BI__builtin_riscv_clmulh_64:
22156 ID = Intrinsic::riscv_clmulh;
22158 case RISCV::BI__builtin_riscv_clmulr_32:
22159 case RISCV::BI__builtin_riscv_clmulr_64:
22160 ID = Intrinsic::riscv_clmulr;
22164 case RISCV::BI__builtin_riscv_xperm8_32:
22165 case RISCV::BI__builtin_riscv_xperm8_64:
22166 ID = Intrinsic::riscv_xperm8;
22168 case RISCV::BI__builtin_riscv_xperm4_32:
22169 case RISCV::BI__builtin_riscv_xperm4_64:
22170 ID = Intrinsic::riscv_xperm4;
22174 case RISCV::BI__builtin_riscv_brev8_32:
22175 case RISCV::BI__builtin_riscv_brev8_64:
22176 ID = Intrinsic::riscv_brev8;
22178 case RISCV::BI__builtin_riscv_zip_32:
22179 ID = Intrinsic::riscv_zip;
22181 case RISCV::BI__builtin_riscv_unzip_32:
22182 ID = Intrinsic::riscv_unzip;
22186 IntrinsicTypes = {ResultType};
22193 case RISCV::BI__builtin_riscv_sha256sig0:
22194 ID = Intrinsic::riscv_sha256sig0;
22196 case RISCV::BI__builtin_riscv_sha256sig1:
22197 ID = Intrinsic::riscv_sha256sig1;
22199 case RISCV::BI__builtin_riscv_sha256sum0:
22200 ID = Intrinsic::riscv_sha256sum0;
22202 case RISCV::BI__builtin_riscv_sha256sum1:
22203 ID = Intrinsic::riscv_sha256sum1;
22207 case RISCV::BI__builtin_riscv_sm4ks:
22208 ID = Intrinsic::riscv_sm4ks;
22210 case RISCV::BI__builtin_riscv_sm4ed:
22211 ID = Intrinsic::riscv_sm4ed;
22215 case RISCV::BI__builtin_riscv_sm3p0:
22216 ID = Intrinsic::riscv_sm3p0;
22218 case RISCV::BI__builtin_riscv_sm3p1:
22219 ID = Intrinsic::riscv_sm3p1;
22223 case RISCV::BI__builtin_riscv_ntl_load: {
22225 unsigned DomainVal = 5;
22226 if (Ops.size() == 2)
22227 DomainVal = cast<ConstantInt>(Ops[1])->getZExtValue();
22229 llvm::MDNode *RISCVDomainNode = llvm::MDNode::get(
22231 llvm::ConstantAsMetadata::get(
Builder.getInt32(DomainVal)));
22232 llvm::MDNode *NontemporalNode = llvm::MDNode::get(
22236 if(ResTy->isScalableTy()) {
22237 const ScalableVectorType *SVTy = cast<ScalableVectorType>(ResTy);
22238 llvm::Type *ScalarTy = ResTy->getScalarType();
22239 Width = ScalarTy->getPrimitiveSizeInBits() *
22240 SVTy->getElementCount().getKnownMinValue();
22242 Width = ResTy->getPrimitiveSizeInBits();
22246 Load->setMetadata(llvm::LLVMContext::MD_nontemporal, NontemporalNode);
22247 Load->setMetadata(
CGM.
getModule().getMDKindID(
"riscv-nontemporal-domain"),
22252 case RISCV::BI__builtin_riscv_ntl_store: {
22253 unsigned DomainVal = 5;
22254 if (Ops.size() == 3)
22255 DomainVal = cast<ConstantInt>(Ops[2])->getZExtValue();
22257 llvm::MDNode *RISCVDomainNode = llvm::MDNode::get(
22259 llvm::ConstantAsMetadata::get(
Builder.getInt32(DomainVal)));
22260 llvm::MDNode *NontemporalNode = llvm::MDNode::get(
22264 Store->setMetadata(llvm::LLVMContext::MD_nontemporal, NontemporalNode);
22272#include "clang/Basic/riscv_vector_builtin_cg.inc"
22274#include "clang/Basic/riscv_sifive_vector_builtin_cg.inc"
22277 assert(ID != Intrinsic::not_intrinsic);
22280 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)
static Value * loadRISCVFeatureBits(unsigned Index, CGBuilderTy &Builder, CodeGenModule &CGM)
#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)