38#include "llvm/ADT/APFloat.h"
39#include "llvm/ADT/APInt.h"
40#include "llvm/ADT/FloatingPointMode.h"
41#include "llvm/ADT/SmallPtrSet.h"
42#include "llvm/ADT/StringExtras.h"
43#include "llvm/Analysis/ValueTracking.h"
44#include "llvm/IR/DataLayout.h"
45#include "llvm/IR/InlineAsm.h"
46#include "llvm/IR/Intrinsics.h"
47#include "llvm/IR/IntrinsicsAArch64.h"
48#include "llvm/IR/IntrinsicsAMDGPU.h"
49#include "llvm/IR/IntrinsicsARM.h"
50#include "llvm/IR/IntrinsicsBPF.h"
51#include "llvm/IR/IntrinsicsDirectX.h"
52#include "llvm/IR/IntrinsicsHexagon.h"
53#include "llvm/IR/IntrinsicsNVPTX.h"
54#include "llvm/IR/IntrinsicsPowerPC.h"
55#include "llvm/IR/IntrinsicsR600.h"
56#include "llvm/IR/IntrinsicsRISCV.h"
57#include "llvm/IR/IntrinsicsS390.h"
58#include "llvm/IR/IntrinsicsWebAssembly.h"
59#include "llvm/IR/IntrinsicsX86.h"
60#include "llvm/IR/MDBuilder.h"
61#include "llvm/IR/MatrixBuilder.h"
62#include "llvm/IR/MemoryModelRelaxationAnnotations.h"
63#include "llvm/Support/AMDGPUAddrSpace.h"
64#include "llvm/Support/ConvertUTF.h"
65#include "llvm/Support/MathExtras.h"
66#include "llvm/Support/ScopedPrinter.h"
67#include "llvm/TargetParser/AArch64TargetParser.h"
68#include "llvm/TargetParser/RISCVISAInfo.h"
69#include "llvm/TargetParser/RISCVTargetParser.h"
70#include "llvm/TargetParser/X86TargetParser.h"
75using namespace CodeGen;
79 Align AlignmentInBytes) {
81 switch (CGF.
getLangOpts().getTrivialAutoVarInit()) {
82 case LangOptions::TrivialAutoVarInitKind::Uninitialized:
85 case LangOptions::TrivialAutoVarInitKind::Zero:
86 Byte = CGF.
Builder.getInt8(0x00);
88 case LangOptions::TrivialAutoVarInitKind::Pattern: {
90 Byte = llvm::dyn_cast<llvm::ConstantInt>(
98 I->addAnnotationMetadata(
"auto-init");
104 Constant *FZeroConst = ConstantFP::getZero(CGF->
FloatTy);
109 FZeroConst = ConstantVector::getSplat(
110 ElementCount::getFixed(VecTy->getNumElements()), FZeroConst);
111 auto *FCompInst = CGF->
Builder.CreateFCmpOLT(Op0, FZeroConst);
112 CMP = CGF->
Builder.CreateIntrinsic(
114 {FCompInst},
nullptr);
116 CMP = CGF->
Builder.CreateFCmpOLT(Op0, FZeroConst);
119 LastInstr = CGF->
Builder.CreateIntrinsic(
120 CGF->
VoidTy, llvm::Intrinsic::dx_discard, {CMP},
nullptr);
125 CGF->
Builder.CreateCondBr(CMP, LT0, End);
127 CGF->
Builder.SetInsertPoint(LT0);
129 CGF->
Builder.CreateIntrinsic(CGF->
VoidTy, llvm::Intrinsic::spv_discard, {},
132 LastInstr = CGF->
Builder.CreateBr(End);
134 CGF->
Builder.SetInsertPoint(End);
136 llvm_unreachable(
"Backend Codegen not supported.");
144 const auto *OutArg1 = dyn_cast<HLSLOutArgExpr>(
E->getArg(1));
145 const auto *OutArg2 = dyn_cast<HLSLOutArgExpr>(
E->getArg(2));
156 Value *LowBits =
nullptr;
157 Value *HighBits =
nullptr;
161 llvm::Type *RetElementTy = CGF->
Int32Ty;
163 RetElementTy = llvm::VectorType::get(
164 CGF->
Int32Ty, ElementCount::getFixed(Op0VecTy->getNumElements()));
165 auto *RetTy = llvm::StructType::get(RetElementTy, RetElementTy);
167 CallInst *CI = CGF->
Builder.CreateIntrinsic(
168 RetTy, Intrinsic::dx_splitdouble, {Op0},
nullptr,
"hlsl.splitdouble");
170 LowBits = CGF->
Builder.CreateExtractValue(CI, 0);
171 HighBits = CGF->
Builder.CreateExtractValue(CI, 1);
176 if (!Op0->
getType()->isVectorTy()) {
177 FixedVectorType *DestTy = FixedVectorType::get(CGF->
Int32Ty, 2);
178 Value *Bitcast = CGF->
Builder.CreateBitCast(Op0, DestTy);
180 LowBits = CGF->
Builder.CreateExtractElement(Bitcast, (uint64_t)0);
181 HighBits = CGF->
Builder.CreateExtractElement(Bitcast, 1);
184 if (
const auto *VecTy =
186 NumElements = VecTy->getNumElements();
188 FixedVectorType *Uint32VecTy =
189 FixedVectorType::get(CGF->
Int32Ty, NumElements * 2);
190 Value *Uint32Vec = CGF->
Builder.CreateBitCast(Op0, Uint32VecTy);
191 if (NumElements == 1) {
192 LowBits = CGF->
Builder.CreateExtractElement(Uint32Vec, (uint64_t)0);
193 HighBits = CGF->
Builder.CreateExtractElement(Uint32Vec, 1);
196 for (
int I = 0,
E = NumElements; I !=
E; ++I) {
197 EvenMask.push_back(I * 2);
198 OddMask.push_back(I * 2 + 1);
200 LowBits = CGF->
Builder.CreateShuffleVector(Uint32Vec, EvenMask);
201 HighBits = CGF->
Builder.CreateShuffleVector(Uint32Vec, OddMask);
215 "asdouble operands types mismatch");
219 llvm::Type *ResultType = CGF.
DoubleTy;
222 N = VTy->getNumElements();
223 ResultType = llvm::FixedVectorType::get(CGF.
DoubleTy, N);
227 return CGF.
Builder.CreateIntrinsic(
228 ResultType, Intrinsic::dx_asdouble,
232 OpLowBits = CGF.
Builder.CreateVectorSplat(1, OpLowBits);
233 OpHighBits = CGF.
Builder.CreateVectorSplat(1, OpHighBits);
237 for (
int i = 0; i < N; i++) {
239 Mask.push_back(i + N);
242 Value *BitVec = CGF.
Builder.CreateShuffleVector(OpLowBits, OpHighBits, Mask);
244 return CGF.
Builder.CreateBitCast(BitVec, ResultType);
251 llvm::Metadata *Ops[] = {llvm::MDString::get(Context,
"x18")};
252 llvm::MDNode *RegName = llvm::MDNode::get(Context, Ops);
253 llvm::Value *Metadata = llvm::MetadataAsValue::get(Context, RegName);
256 llvm::Value *X18 = CGF.
Builder.CreateCall(F, Metadata);
263 unsigned BuiltinID) {
272 static SmallDenseMap<unsigned, StringRef, 64> F128Builtins{
273 {Builtin::BI__builtin___fprintf_chk,
"__fprintf_chkieee128"},
274 {Builtin::BI__builtin___printf_chk,
"__printf_chkieee128"},
275 {Builtin::BI__builtin___snprintf_chk,
"__snprintf_chkieee128"},
276 {Builtin::BI__builtin___sprintf_chk,
"__sprintf_chkieee128"},
277 {Builtin::BI__builtin___vfprintf_chk,
"__vfprintf_chkieee128"},
278 {Builtin::BI__builtin___vprintf_chk,
"__vprintf_chkieee128"},
279 {Builtin::BI__builtin___vsnprintf_chk,
"__vsnprintf_chkieee128"},
280 {Builtin::BI__builtin___vsprintf_chk,
"__vsprintf_chkieee128"},
281 {Builtin::BI__builtin_fprintf,
"__fprintfieee128"},
282 {Builtin::BI__builtin_printf,
"__printfieee128"},
283 {Builtin::BI__builtin_snprintf,
"__snprintfieee128"},
284 {Builtin::BI__builtin_sprintf,
"__sprintfieee128"},
285 {Builtin::BI__builtin_vfprintf,
"__vfprintfieee128"},
286 {Builtin::BI__builtin_vprintf,
"__vprintfieee128"},
287 {Builtin::BI__builtin_vsnprintf,
"__vsnprintfieee128"},
288 {Builtin::BI__builtin_vsprintf,
"__vsprintfieee128"},
289 {Builtin::BI__builtin_fscanf,
"__fscanfieee128"},
290 {Builtin::BI__builtin_scanf,
"__scanfieee128"},
291 {Builtin::BI__builtin_sscanf,
"__sscanfieee128"},
292 {Builtin::BI__builtin_vfscanf,
"__vfscanfieee128"},
293 {Builtin::BI__builtin_vscanf,
"__vscanfieee128"},
294 {Builtin::BI__builtin_vsscanf,
"__vsscanfieee128"},
295 {Builtin::BI__builtin_nexttowardf128,
"__nexttowardieee128"},
301 static SmallDenseMap<unsigned, StringRef, 4> AIXLongDouble64Builtins{
302 {Builtin::BI__builtin_frexpl,
"frexp"},
303 {Builtin::BI__builtin_ldexpl,
"ldexp"},
304 {Builtin::BI__builtin_modfl,
"modf"},
310 if (FD->
hasAttr<AsmLabelAttr>())
316 &
getTarget().getLongDoubleFormat() == &llvm::APFloat::IEEEquad() &&
317 F128Builtins.contains(BuiltinID))
318 Name = F128Builtins[BuiltinID];
321 &llvm::APFloat::IEEEdouble() &&
322 AIXLongDouble64Builtins.contains(BuiltinID))
323 Name = AIXLongDouble64Builtins[BuiltinID];
328 llvm::FunctionType *Ty =
331 return GetOrCreateLLVMFunction(Name, Ty,
D,
false);
337 QualType T, llvm::IntegerType *IntType) {
340 if (
V->getType()->isPointerTy())
341 return CGF.
Builder.CreatePtrToInt(
V, IntType);
343 assert(
V->getType() == IntType);
351 if (ResultType->isPointerTy())
352 return CGF.
Builder.CreateIntToPtr(
V, ResultType);
354 assert(
V->getType() == ResultType);
365 if (Align % Bytes != 0) {
378 AtomicOrdering Ordering = AtomicOrdering::SequentiallyConsistent) {
388 llvm::IntegerType *IntType = llvm::IntegerType::get(
392 llvm::Type *ValueType = Val->getType();
420 llvm::AtomicRMWInst::BinOp Kind,
429 llvm::AtomicRMWInst::BinOp Kind,
431 Instruction::BinaryOps Op,
432 bool Invert =
false) {
441 llvm::IntegerType *IntType = llvm::IntegerType::get(
445 llvm::Type *ValueType = Val->getType();
449 Kind, DestAddr, Val, llvm::AtomicOrdering::SequentiallyConsistent);
454 llvm::ConstantInt::getAllOnesValue(IntType));
478 llvm::IntegerType *IntType = llvm::IntegerType::get(
482 llvm::Type *ValueType = Cmp->getType();
487 DestAddr, Cmp, New, llvm::AtomicOrdering::SequentiallyConsistent,
488 llvm::AtomicOrdering::SequentiallyConsistent);
491 return CGF.
Builder.CreateZExt(CGF.
Builder.CreateExtractValue(Pair, 1),
514 AtomicOrdering SuccessOrdering = AtomicOrdering::SequentiallyConsistent) {
526 auto *RTy = Exchange->getType();
530 if (RTy->isPointerTy()) {
536 auto FailureOrdering = SuccessOrdering == AtomicOrdering::Release ?
537 AtomicOrdering::Monotonic :
545 DestAddr, Comparand, Exchange, SuccessOrdering, FailureOrdering);
546 CmpXchg->setVolatile(
true);
549 if (RTy->isPointerTy()) {
570 AtomicOrdering SuccessOrdering) {
571 assert(
E->getNumArgs() == 4);
577 assert(DestPtr->getType()->isPointerTy());
578 assert(!ExchangeHigh->getType()->isPointerTy());
579 assert(!ExchangeLow->getType()->isPointerTy());
582 auto FailureOrdering = SuccessOrdering == AtomicOrdering::Release
583 ? AtomicOrdering::Monotonic
588 llvm::Type *Int128Ty = llvm::IntegerType::get(CGF.
getLLVMContext(), 128);
589 Address DestAddr(DestPtr, Int128Ty,
594 ExchangeHigh = CGF.
Builder.CreateZExt(ExchangeHigh, Int128Ty);
595 ExchangeLow = CGF.
Builder.CreateZExt(ExchangeLow, Int128Ty);
597 CGF.
Builder.CreateShl(ExchangeHigh, llvm::ConstantInt::get(Int128Ty, 64));
598 llvm::Value *Exchange = CGF.
Builder.CreateOr(ExchangeHigh, ExchangeLow);
604 SuccessOrdering, FailureOrdering);
610 CXI->setVolatile(
true);
622 AtomicOrdering Ordering = AtomicOrdering::SequentiallyConsistent) {
628 AtomicRMWInst::Add, DestAddr, ConstantInt::get(IntTy, 1), Ordering);
629 return CGF.
Builder.CreateAdd(
Result, ConstantInt::get(IntTy, 1));
634 AtomicOrdering Ordering = AtomicOrdering::SequentiallyConsistent) {
640 AtomicRMWInst::Sub, DestAddr, ConstantInt::get(IntTy, 1), Ordering);
641 return CGF.
Builder.CreateSub(
Result, ConstantInt::get(IntTy, 1));
652 Load->setVolatile(
true);
662 llvm::StoreInst *Store =
664 Store->setVolatile(
true);
673 unsigned ConstrainedIntrinsicID) {
676 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF,
E);
677 if (CGF.
Builder.getIsFPConstrained()) {
679 return CGF.
Builder.CreateConstrainedFPCall(F, { Src0 });
682 return CGF.
Builder.CreateCall(F, Src0);
690 unsigned ConstrainedIntrinsicID) {
694 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF,
E);
695 if (CGF.
Builder.getIsFPConstrained()) {
697 return CGF.
Builder.CreateConstrainedFPCall(F, { Src0, Src1 });
700 return CGF.
Builder.CreateCall(F, { Src0, Src1 });
707 llvm::Intrinsic::ID ConstrainedIntrinsicID) {
711 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF,
E);
712 if (CGF.
Builder.getIsFPConstrained()) {
714 {Src0->getType(), Src1->getType()});
715 return CGF.
Builder.CreateConstrainedFPCall(F, {Src0, Src1});
720 return CGF.
Builder.CreateCall(F, {Src0, Src1});
727 unsigned ConstrainedIntrinsicID) {
732 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF,
E);
733 if (CGF.
Builder.getIsFPConstrained()) {
735 return CGF.
Builder.CreateConstrainedFPCall(F, { Src0, Src1, Src2 });
738 return CGF.
Builder.CreateCall(F, { Src0, Src1, Src2 });
745 unsigned IntrinsicID,
746 unsigned ConstrainedIntrinsicID,
750 if (CGF.
Builder.getIsFPConstrained())
755 if (CGF.
Builder.getIsFPConstrained())
756 return CGF.
Builder.CreateConstrainedFPCall(F, Args);
758 return CGF.
Builder.CreateCall(F, Args);
767 unsigned IntrinsicID,
768 llvm::StringRef Name =
"") {
769 static_assert(N,
"expect non-empty argument");
771 for (
unsigned I = 0; I < N; ++I)
774 return CGF.
Builder.CreateCall(F, Args, Name);
779 unsigned IntrinsicID) {
786 return CGF.
Builder.CreateCall(F, {Src0, Src1, Src2, Src3});
792 unsigned IntrinsicID) {
797 return CGF.
Builder.CreateCall(F, {Src0, Src1});
803 unsigned IntrinsicID,
804 unsigned ConstrainedIntrinsicID) {
808 if (CGF.
Builder.getIsFPConstrained()) {
809 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF,
E);
811 {ResultType, Src0->getType()});
812 return CGF.
Builder.CreateConstrainedFPCall(F, {Src0});
816 return CGF.
Builder.CreateCall(F, Src0);
821 llvm::Intrinsic::ID IntrinsicID) {
829 llvm::Value *
Call = CGF.
Builder.CreateCall(F, Src0);
831 llvm::Value *Exp = CGF.
Builder.CreateExtractValue(
Call, 1);
842 Call->setDoesNotAccessMemory();
851 llvm::Type *Ty =
V->getType();
852 int Width = Ty->getPrimitiveSizeInBits();
853 llvm::Type *IntTy = llvm::IntegerType::get(
C, Width);
855 if (Ty->isPPC_FP128Ty()) {
865 Value *ShiftCst = llvm::ConstantInt::get(IntTy, Width);
870 IntTy = llvm::IntegerType::get(
C, Width);
873 Value *Zero = llvm::Constant::getNullValue(IntTy);
874 return CGF.
Builder.CreateICmpSLT(
V, Zero);
883 auto IsIndirect = [&](
ABIArgInfo const &info) {
884 return info.isIndirect() || info.isIndirectAliased() || info.isInAlloca();
889 return IsIndirect(ArgInfo.info);
894 const CallExpr *
E, llvm::Constant *calleeValue) {
895 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF,
E);
897 llvm::CallBase *callOrInvoke =
nullptr;
901 nullptr, &callOrInvoke, &FnInfo);
906 bool ConstWithoutErrnoAndExceptions =
910 if (ConstWithoutErrnoAndExceptions && CGF.
CGM.
getLangOpts().MathErrno &&
911 !CGF.
Builder.getIsFPConstrained() &&
Call.isScalar() &&
932 const llvm::Intrinsic::ID IntrinsicID,
933 llvm::Value *
X, llvm::Value *Y,
934 llvm::Value *&Carry) {
936 assert(
X->getType() == Y->getType() &&
937 "Arguments must be the same type. (Did you forget to make sure both "
938 "arguments have the same integer width?)");
941 llvm::Value *Tmp = CGF.
Builder.CreateCall(Callee, {
X, Y});
942 Carry = CGF.
Builder.CreateExtractValue(Tmp, 1);
943 return CGF.
Builder.CreateExtractValue(Tmp, 0);
950 llvm::ConstantRange CR(APInt(32, low), APInt(32, high));
951 Call->addRangeRetAttr(CR);
952 Call->addRetAttr(llvm::Attribute::AttrKind::NoUndef);
957 struct WidthAndSignedness {
963static WidthAndSignedness
975static struct WidthAndSignedness
977 assert(Types.size() > 0 &&
"Empty list of types.");
981 for (
const auto &
Type : Types) {
990 for (
const auto &
Type : Types) {
992 if (Width < MinWidth) {
1001 Intrinsic::ID inst = IsStart ? Intrinsic::vastart : Intrinsic::vaend;
1012 return From == To || (From == 0 && To == 1) || (From == 3 && To == 2);
1017 return ConstantInt::get(ResType, (
Type & 2) ? 0 : -1,
true);
1021CodeGenFunction::evaluateOrEmitBuiltinObjectSize(
const Expr *
E,
unsigned Type,
1022 llvm::IntegerType *ResType,
1023 llvm::Value *EmittedE,
1027 return emitBuiltinObjectSize(
E,
Type, ResType, EmittedE, IsDynamic);
1028 return ConstantInt::get(ResType, ObjectSize,
true);
1042 if ((!FAMDecl || FD == FAMDecl) &&
1044 Ctx, FD, FD->getType(), StrictFlexArraysLevel,
1072 if (FD->getType()->isCountAttributedType())
1084CodeGenFunction::emitFlexibleArrayMemberSize(
const Expr *
E,
unsigned Type,
1085 llvm::IntegerType *ResType) {
1114 const Expr *Idx =
nullptr;
1116 if (
const auto *UO = dyn_cast<UnaryOperator>(
Base);
1117 UO && UO->getOpcode() == UO_AddrOf) {
1119 if (
const auto *ASE = dyn_cast<ArraySubscriptExpr>(SubExpr)) {
1120 Base = ASE->getBase()->IgnoreParenImpCasts();
1123 if (
const auto *IL = dyn_cast<IntegerLiteral>(Idx)) {
1124 int64_t Val = IL->getValue().getSExtValue();
1141 if (
const auto *ME = dyn_cast<MemberExpr>(
Base)) {
1143 const ValueDecl *VD = ME->getMemberDecl();
1145 FAMDecl = dyn_cast<FieldDecl>(VD);
1148 }
else if (
const auto *DRE = dyn_cast<DeclRefExpr>(
Base)) {
1150 QualType Ty = DRE->getDecl()->getType();
1203 if (isa<DeclRefExpr>(
Base))
1227 CountedByInst =
Builder.CreateIntCast(CountedByInst, ResType, IsSigned);
1230 Value *IdxInst =
nullptr;
1238 IdxInst =
Builder.CreateIntCast(IdxInst, ResType, IdxSigned);
1243 Builder.CreateSub(CountedByInst, IdxInst,
"", !IsSigned, IsSigned);
1249 llvm::Constant *ElemSize =
1250 llvm::ConstantInt::get(ResType,
Size.getQuantity(), IsSigned);
1252 Builder.CreateMul(CountedByInst, ElemSize,
"", !IsSigned, IsSigned);
1253 Res =
Builder.CreateIntCast(Res, ResType, IsSigned);
1262 return Builder.CreateSelect(Cmp, Res, ConstantInt::get(ResType, 0, IsSigned));
1275CodeGenFunction::emitBuiltinObjectSize(
const Expr *
E,
unsigned Type,
1276 llvm::IntegerType *ResType,
1277 llvm::Value *EmittedE,
bool IsDynamic) {
1281 auto *Param = dyn_cast<ParmVarDecl>(
D->getDecl());
1282 auto *PS =
D->getDecl()->
getAttr<PassObjectSizeAttr>();
1283 if (Param !=
nullptr && PS !=
nullptr &&
1285 auto Iter = SizeArguments.find(Param);
1286 assert(
Iter != SizeArguments.end());
1289 auto DIter = LocalDeclMap.find(
D);
1290 assert(DIter != LocalDeclMap.end());
1300 if (
Value *
V = emitFlexibleArrayMemberSize(
E,
Type, ResType))
1311 assert(Ptr->
getType()->isPointerTy() &&
1312 "Non-pointer passed to __builtin_object_size?");
1328 enum ActionKind : uint8_t { TestOnly, Complement, Reset,
Set };
1329 enum InterlockingKind : uint8_t {
1338 InterlockingKind Interlocking;
1341 static BitTest decodeBitTestBuiltin(
unsigned BuiltinID);
1346BitTest BitTest::decodeBitTestBuiltin(
unsigned BuiltinID) {
1347 switch (BuiltinID) {
1349 case Builtin::BI_bittest:
1350 return {TestOnly, Unlocked,
false};
1351 case Builtin::BI_bittestandcomplement:
1352 return {Complement, Unlocked,
false};
1353 case Builtin::BI_bittestandreset:
1354 return {Reset, Unlocked,
false};
1355 case Builtin::BI_bittestandset:
1356 return {
Set, Unlocked,
false};
1357 case Builtin::BI_interlockedbittestandreset:
1358 return {Reset, Sequential,
false};
1359 case Builtin::BI_interlockedbittestandset:
1360 return {
Set, Sequential,
false};
1363 case Builtin::BI_bittest64:
1364 return {TestOnly, Unlocked,
true};
1365 case Builtin::BI_bittestandcomplement64:
1366 return {Complement, Unlocked,
true};
1367 case Builtin::BI_bittestandreset64:
1368 return {Reset, Unlocked,
true};
1369 case Builtin::BI_bittestandset64:
1370 return {
Set, Unlocked,
true};
1371 case Builtin::BI_interlockedbittestandreset64:
1372 return {Reset, Sequential,
true};
1373 case Builtin::BI_interlockedbittestandset64:
1374 return {
Set, Sequential,
true};
1377 case Builtin::BI_interlockedbittestandset_acq:
1378 return {
Set, Acquire,
false};
1379 case Builtin::BI_interlockedbittestandset_rel:
1380 return {
Set, Release,
false};
1381 case Builtin::BI_interlockedbittestandset_nf:
1382 return {
Set, NoFence,
false};
1383 case Builtin::BI_interlockedbittestandreset_acq:
1384 return {Reset, Acquire,
false};
1385 case Builtin::BI_interlockedbittestandreset_rel:
1386 return {Reset, Release,
false};
1387 case Builtin::BI_interlockedbittestandreset_nf:
1388 return {Reset, NoFence,
false};
1390 llvm_unreachable(
"expected only bittest intrinsics");
1395 case BitTest::TestOnly:
return '\0';
1396 case BitTest::Complement:
return 'c';
1397 case BitTest::Reset:
return 'r';
1398 case BitTest::Set:
return 's';
1400 llvm_unreachable(
"invalid action");
1408 char SizeSuffix = BT.Is64Bit ?
'q' :
'l';
1412 raw_svector_ostream AsmOS(
Asm);
1413 if (BT.Interlocking != BitTest::Unlocked)
1418 AsmOS << SizeSuffix <<
" $2, ($1)";
1421 std::string Constraints =
"={@ccc},r,r,~{cc},~{memory}";
1423 if (!MachineClobbers.empty()) {
1425 Constraints += MachineClobbers;
1427 llvm::IntegerType *IntType = llvm::IntegerType::get(
1430 llvm::FunctionType *FTy =
1431 llvm::FunctionType::get(CGF.
Int8Ty, {CGF.UnqualPtrTy, IntType},
false);
1433 llvm::InlineAsm *IA =
1434 llvm::InlineAsm::get(FTy,
Asm, Constraints,
true);
1435 return CGF.
Builder.CreateCall(IA, {BitBase, BitPos});
1438static llvm::AtomicOrdering
1441 case BitTest::Unlocked:
return llvm::AtomicOrdering::NotAtomic;
1442 case BitTest::Sequential:
return llvm::AtomicOrdering::SequentiallyConsistent;
1443 case BitTest::Acquire:
return llvm::AtomicOrdering::Acquire;
1444 case BitTest::Release:
return llvm::AtomicOrdering::Release;
1445 case BitTest::NoFence:
return llvm::AtomicOrdering::Monotonic;
1447 llvm_unreachable(
"invalid interlocking");
1460 BitTest BT = BitTest::decodeBitTestBuiltin(BuiltinID);
1472 BitPos, llvm::ConstantInt::get(BitPos->
getType(), 3),
"bittest.byteidx");
1474 "bittest.byteaddr"),
1478 llvm::ConstantInt::get(CGF.
Int8Ty, 0x7));
1481 Value *Mask =
nullptr;
1482 if (BT.Action != BitTest::TestOnly) {
1483 Mask = CGF.
Builder.CreateShl(llvm::ConstantInt::get(CGF.
Int8Ty, 1), PosLow,
1490 Value *OldByte =
nullptr;
1491 if (Ordering != llvm::AtomicOrdering::NotAtomic) {
1494 llvm::AtomicRMWInst::BinOp RMWOp = llvm::AtomicRMWInst::Or;
1495 if (BT.Action == BitTest::Reset) {
1496 Mask = CGF.
Builder.CreateNot(Mask);
1497 RMWOp = llvm::AtomicRMWInst::And;
1503 Value *NewByte =
nullptr;
1504 switch (BT.Action) {
1505 case BitTest::TestOnly:
1508 case BitTest::Complement:
1509 NewByte = CGF.
Builder.CreateXor(OldByte, Mask);
1511 case BitTest::Reset:
1512 NewByte = CGF.
Builder.CreateAnd(OldByte, CGF.
Builder.CreateNot(Mask));
1515 NewByte = CGF.
Builder.CreateOr(OldByte, Mask);
1524 Value *ShiftedByte = CGF.
Builder.CreateLShr(OldByte, PosLow,
"bittest.shr");
1526 ShiftedByte, llvm::ConstantInt::get(CGF.
Int8Ty, 1),
"bittest.res");
1535 raw_svector_ostream AsmOS(
Asm);
1536 llvm::IntegerType *RetType = CGF.
Int32Ty;
1538 switch (BuiltinID) {
1539 case clang::PPC::BI__builtin_ppc_ldarx:
1543 case clang::PPC::BI__builtin_ppc_lwarx:
1547 case clang::PPC::BI__builtin_ppc_lharx:
1551 case clang::PPC::BI__builtin_ppc_lbarx:
1556 llvm_unreachable(
"Expected only PowerPC load reserve intrinsics");
1559 AsmOS <<
"$0, ${1:y}";
1561 std::string Constraints =
"=r,*Z,~{memory}";
1563 if (!MachineClobbers.empty()) {
1565 Constraints += MachineClobbers;
1569 llvm::FunctionType *FTy = llvm::FunctionType::get(RetType, {PtrType},
false);
1571 llvm::InlineAsm *IA =
1572 llvm::InlineAsm::get(FTy,
Asm, Constraints,
true);
1573 llvm::CallInst *CI = CGF.
Builder.CreateCall(IA, {Addr});
1575 0, Attribute::get(CGF.
getLLVMContext(), Attribute::ElementType, RetType));
1580enum class MSVCSetJmpKind {
1592 llvm::Value *Arg1 =
nullptr;
1593 llvm::Type *Arg1Ty =
nullptr;
1595 bool IsVarArg =
false;
1596 if (SJKind == MSVCSetJmpKind::_setjmp3) {
1599 Arg1 = llvm::ConstantInt::get(CGF.
IntTy, 0);
1602 Name = SJKind == MSVCSetJmpKind::_setjmp ?
"_setjmp" :
"_setjmpex";
1605 Arg1 = CGF.
Builder.CreateCall(
1608 Arg1 = CGF.
Builder.CreateCall(
1610 llvm::ConstantInt::get(CGF.
Int32Ty, 0));
1614 llvm::Type *ArgTypes[2] = {CGF.
Int8PtrTy, Arg1Ty};
1615 llvm::AttributeList ReturnsTwiceAttr = llvm::AttributeList::get(
1617 llvm::Attribute::ReturnsTwice);
1619 llvm::FunctionType::get(CGF.
IntTy, ArgTypes, IsVarArg), Name,
1620 ReturnsTwiceAttr,
true);
1622 llvm::Value *Buf = CGF.
Builder.CreateBitOrPointerCast(
1624 llvm::Value *Args[] = {Buf, Arg1};
1626 CB->setAttributes(ReturnsTwiceAttr);
1675static std::optional<CodeGenFunction::MSVCIntrin>
1678 switch (BuiltinID) {
1680 return std::nullopt;
1681 case clang::ARM::BI_BitScanForward:
1682 case clang::ARM::BI_BitScanForward64:
1683 return MSVCIntrin::_BitScanForward;
1684 case clang::ARM::BI_BitScanReverse:
1685 case clang::ARM::BI_BitScanReverse64:
1686 return MSVCIntrin::_BitScanReverse;
1687 case clang::ARM::BI_InterlockedAnd64:
1688 return MSVCIntrin::_InterlockedAnd;
1689 case clang::ARM::BI_InterlockedExchange64:
1690 return MSVCIntrin::_InterlockedExchange;
1691 case clang::ARM::BI_InterlockedExchangeAdd64:
1692 return MSVCIntrin::_InterlockedExchangeAdd;
1693 case clang::ARM::BI_InterlockedExchangeSub64:
1694 return MSVCIntrin::_InterlockedExchangeSub;
1695 case clang::ARM::BI_InterlockedOr64:
1696 return MSVCIntrin::_InterlockedOr;
1697 case clang::ARM::BI_InterlockedXor64:
1698 return MSVCIntrin::_InterlockedXor;
1699 case clang::ARM::BI_InterlockedDecrement64:
1700 return MSVCIntrin::_InterlockedDecrement;
1701 case clang::ARM::BI_InterlockedIncrement64:
1702 return MSVCIntrin::_InterlockedIncrement;
1703 case clang::ARM::BI_InterlockedExchangeAdd8_acq:
1704 case clang::ARM::BI_InterlockedExchangeAdd16_acq:
1705 case clang::ARM::BI_InterlockedExchangeAdd_acq:
1706 case clang::ARM::BI_InterlockedExchangeAdd64_acq:
1707 return MSVCIntrin::_InterlockedExchangeAdd_acq;
1708 case clang::ARM::BI_InterlockedExchangeAdd8_rel:
1709 case clang::ARM::BI_InterlockedExchangeAdd16_rel:
1710 case clang::ARM::BI_InterlockedExchangeAdd_rel:
1711 case clang::ARM::BI_InterlockedExchangeAdd64_rel:
1712 return MSVCIntrin::_InterlockedExchangeAdd_rel;
1713 case clang::ARM::BI_InterlockedExchangeAdd8_nf:
1714 case clang::ARM::BI_InterlockedExchangeAdd16_nf:
1715 case clang::ARM::BI_InterlockedExchangeAdd_nf:
1716 case clang::ARM::BI_InterlockedExchangeAdd64_nf:
1717 return MSVCIntrin::_InterlockedExchangeAdd_nf;
1718 case clang::ARM::BI_InterlockedExchange8_acq:
1719 case clang::ARM::BI_InterlockedExchange16_acq:
1720 case clang::ARM::BI_InterlockedExchange_acq:
1721 case clang::ARM::BI_InterlockedExchange64_acq:
1722 case clang::ARM::BI_InterlockedExchangePointer_acq:
1723 return MSVCIntrin::_InterlockedExchange_acq;
1724 case clang::ARM::BI_InterlockedExchange8_rel:
1725 case clang::ARM::BI_InterlockedExchange16_rel:
1726 case clang::ARM::BI_InterlockedExchange_rel:
1727 case clang::ARM::BI_InterlockedExchange64_rel:
1728 case clang::ARM::BI_InterlockedExchangePointer_rel:
1729 return MSVCIntrin::_InterlockedExchange_rel;
1730 case clang::ARM::BI_InterlockedExchange8_nf:
1731 case clang::ARM::BI_InterlockedExchange16_nf:
1732 case clang::ARM::BI_InterlockedExchange_nf:
1733 case clang::ARM::BI_InterlockedExchange64_nf:
1734 case clang::ARM::BI_InterlockedExchangePointer_nf:
1735 return MSVCIntrin::_InterlockedExchange_nf;
1736 case clang::ARM::BI_InterlockedCompareExchange8_acq:
1737 case clang::ARM::BI_InterlockedCompareExchange16_acq:
1738 case clang::ARM::BI_InterlockedCompareExchange_acq:
1739 case clang::ARM::BI_InterlockedCompareExchange64_acq:
1740 case clang::ARM::BI_InterlockedCompareExchangePointer_acq:
1741 return MSVCIntrin::_InterlockedCompareExchange_acq;
1742 case clang::ARM::BI_InterlockedCompareExchange8_rel:
1743 case clang::ARM::BI_InterlockedCompareExchange16_rel:
1744 case clang::ARM::BI_InterlockedCompareExchange_rel:
1745 case clang::ARM::BI_InterlockedCompareExchange64_rel:
1746 case clang::ARM::BI_InterlockedCompareExchangePointer_rel:
1747 return MSVCIntrin::_InterlockedCompareExchange_rel;
1748 case clang::ARM::BI_InterlockedCompareExchange8_nf:
1749 case clang::ARM::BI_InterlockedCompareExchange16_nf:
1750 case clang::ARM::BI_InterlockedCompareExchange_nf:
1751 case clang::ARM::BI_InterlockedCompareExchange64_nf:
1752 return MSVCIntrin::_InterlockedCompareExchange_nf;
1753 case clang::ARM::BI_InterlockedOr8_acq:
1754 case clang::ARM::BI_InterlockedOr16_acq:
1755 case clang::ARM::BI_InterlockedOr_acq:
1756 case clang::ARM::BI_InterlockedOr64_acq:
1757 return MSVCIntrin::_InterlockedOr_acq;
1758 case clang::ARM::BI_InterlockedOr8_rel:
1759 case clang::ARM::BI_InterlockedOr16_rel:
1760 case clang::ARM::BI_InterlockedOr_rel:
1761 case clang::ARM::BI_InterlockedOr64_rel:
1762 return MSVCIntrin::_InterlockedOr_rel;
1763 case clang::ARM::BI_InterlockedOr8_nf:
1764 case clang::ARM::BI_InterlockedOr16_nf:
1765 case clang::ARM::BI_InterlockedOr_nf:
1766 case clang::ARM::BI_InterlockedOr64_nf:
1767 return MSVCIntrin::_InterlockedOr_nf;
1768 case clang::ARM::BI_InterlockedXor8_acq:
1769 case clang::ARM::BI_InterlockedXor16_acq:
1770 case clang::ARM::BI_InterlockedXor_acq:
1771 case clang::ARM::BI_InterlockedXor64_acq:
1772 return MSVCIntrin::_InterlockedXor_acq;
1773 case clang::ARM::BI_InterlockedXor8_rel:
1774 case clang::ARM::BI_InterlockedXor16_rel:
1775 case clang::ARM::BI_InterlockedXor_rel:
1776 case clang::ARM::BI_InterlockedXor64_rel:
1777 return MSVCIntrin::_InterlockedXor_rel;
1778 case clang::ARM::BI_InterlockedXor8_nf:
1779 case clang::ARM::BI_InterlockedXor16_nf:
1780 case clang::ARM::BI_InterlockedXor_nf:
1781 case clang::ARM::BI_InterlockedXor64_nf:
1782 return MSVCIntrin::_InterlockedXor_nf;
1783 case clang::ARM::BI_InterlockedAnd8_acq:
1784 case clang::ARM::BI_InterlockedAnd16_acq:
1785 case clang::ARM::BI_InterlockedAnd_acq:
1786 case clang::ARM::BI_InterlockedAnd64_acq:
1787 return MSVCIntrin::_InterlockedAnd_acq;
1788 case clang::ARM::BI_InterlockedAnd8_rel:
1789 case clang::ARM::BI_InterlockedAnd16_rel:
1790 case clang::ARM::BI_InterlockedAnd_rel:
1791 case clang::ARM::BI_InterlockedAnd64_rel:
1792 return MSVCIntrin::_InterlockedAnd_rel;
1793 case clang::ARM::BI_InterlockedAnd8_nf:
1794 case clang::ARM::BI_InterlockedAnd16_nf:
1795 case clang::ARM::BI_InterlockedAnd_nf:
1796 case clang::ARM::BI_InterlockedAnd64_nf:
1797 return MSVCIntrin::_InterlockedAnd_nf;
1798 case clang::ARM::BI_InterlockedIncrement16_acq:
1799 case clang::ARM::BI_InterlockedIncrement_acq:
1800 case clang::ARM::BI_InterlockedIncrement64_acq:
1801 return MSVCIntrin::_InterlockedIncrement_acq;
1802 case clang::ARM::BI_InterlockedIncrement16_rel:
1803 case clang::ARM::BI_InterlockedIncrement_rel:
1804 case clang::ARM::BI_InterlockedIncrement64_rel:
1805 return MSVCIntrin::_InterlockedIncrement_rel;
1806 case clang::ARM::BI_InterlockedIncrement16_nf:
1807 case clang::ARM::BI_InterlockedIncrement_nf:
1808 case clang::ARM::BI_InterlockedIncrement64_nf:
1809 return MSVCIntrin::_InterlockedIncrement_nf;
1810 case clang::ARM::BI_InterlockedDecrement16_acq:
1811 case clang::ARM::BI_InterlockedDecrement_acq:
1812 case clang::ARM::BI_InterlockedDecrement64_acq:
1813 return MSVCIntrin::_InterlockedDecrement_acq;
1814 case clang::ARM::BI_InterlockedDecrement16_rel:
1815 case clang::ARM::BI_InterlockedDecrement_rel:
1816 case clang::ARM::BI_InterlockedDecrement64_rel:
1817 return MSVCIntrin::_InterlockedDecrement_rel;
1818 case clang::ARM::BI_InterlockedDecrement16_nf:
1819 case clang::ARM::BI_InterlockedDecrement_nf:
1820 case clang::ARM::BI_InterlockedDecrement64_nf:
1821 return MSVCIntrin::_InterlockedDecrement_nf;
1823 llvm_unreachable(
"must return from switch");
1826static std::optional<CodeGenFunction::MSVCIntrin>
1829 switch (BuiltinID) {
1831 return std::nullopt;
1832 case clang::AArch64::BI_BitScanForward:
1833 case clang::AArch64::BI_BitScanForward64:
1834 return MSVCIntrin::_BitScanForward;
1835 case clang::AArch64::BI_BitScanReverse:
1836 case clang::AArch64::BI_BitScanReverse64:
1837 return MSVCIntrin::_BitScanReverse;
1838 case clang::AArch64::BI_InterlockedAnd64:
1839 return MSVCIntrin::_InterlockedAnd;
1840 case clang::AArch64::BI_InterlockedExchange64:
1841 return MSVCIntrin::_InterlockedExchange;
1842 case clang::AArch64::BI_InterlockedExchangeAdd64:
1843 return MSVCIntrin::_InterlockedExchangeAdd;
1844 case clang::AArch64::BI_InterlockedExchangeSub64:
1845 return MSVCIntrin::_InterlockedExchangeSub;
1846 case clang::AArch64::BI_InterlockedOr64:
1847 return MSVCIntrin::_InterlockedOr;
1848 case clang::AArch64::BI_InterlockedXor64:
1849 return MSVCIntrin::_InterlockedXor;
1850 case clang::AArch64::BI_InterlockedDecrement64:
1851 return MSVCIntrin::_InterlockedDecrement;
1852 case clang::AArch64::BI_InterlockedIncrement64:
1853 return MSVCIntrin::_InterlockedIncrement;
1854 case clang::AArch64::BI_InterlockedExchangeAdd8_acq:
1855 case clang::AArch64::BI_InterlockedExchangeAdd16_acq:
1856 case clang::AArch64::BI_InterlockedExchangeAdd_acq:
1857 case clang::AArch64::BI_InterlockedExchangeAdd64_acq:
1858 return MSVCIntrin::_InterlockedExchangeAdd_acq;
1859 case clang::AArch64::BI_InterlockedExchangeAdd8_rel:
1860 case clang::AArch64::BI_InterlockedExchangeAdd16_rel:
1861 case clang::AArch64::BI_InterlockedExchangeAdd_rel:
1862 case clang::AArch64::BI_InterlockedExchangeAdd64_rel:
1863 return MSVCIntrin::_InterlockedExchangeAdd_rel;
1864 case clang::AArch64::BI_InterlockedExchangeAdd8_nf:
1865 case clang::AArch64::BI_InterlockedExchangeAdd16_nf:
1866 case clang::AArch64::BI_InterlockedExchangeAdd_nf:
1867 case clang::AArch64::BI_InterlockedExchangeAdd64_nf:
1868 return MSVCIntrin::_InterlockedExchangeAdd_nf;
1869 case clang::AArch64::BI_InterlockedExchange8_acq:
1870 case clang::AArch64::BI_InterlockedExchange16_acq:
1871 case clang::AArch64::BI_InterlockedExchange_acq:
1872 case clang::AArch64::BI_InterlockedExchange64_acq:
1873 case clang::AArch64::BI_InterlockedExchangePointer_acq:
1874 return MSVCIntrin::_InterlockedExchange_acq;
1875 case clang::AArch64::BI_InterlockedExchange8_rel:
1876 case clang::AArch64::BI_InterlockedExchange16_rel:
1877 case clang::AArch64::BI_InterlockedExchange_rel:
1878 case clang::AArch64::BI_InterlockedExchange64_rel:
1879 case clang::AArch64::BI_InterlockedExchangePointer_rel:
1880 return MSVCIntrin::_InterlockedExchange_rel;
1881 case clang::AArch64::BI_InterlockedExchange8_nf:
1882 case clang::AArch64::BI_InterlockedExchange16_nf:
1883 case clang::AArch64::BI_InterlockedExchange_nf:
1884 case clang::AArch64::BI_InterlockedExchange64_nf:
1885 case clang::AArch64::BI_InterlockedExchangePointer_nf:
1886 return MSVCIntrin::_InterlockedExchange_nf;
1887 case clang::AArch64::BI_InterlockedCompareExchange8_acq:
1888 case clang::AArch64::BI_InterlockedCompareExchange16_acq:
1889 case clang::AArch64::BI_InterlockedCompareExchange_acq:
1890 case clang::AArch64::BI_InterlockedCompareExchange64_acq:
1891 case clang::AArch64::BI_InterlockedCompareExchangePointer_acq:
1892 return MSVCIntrin::_InterlockedCompareExchange_acq;
1893 case clang::AArch64::BI_InterlockedCompareExchange8_rel:
1894 case clang::AArch64::BI_InterlockedCompareExchange16_rel:
1895 case clang::AArch64::BI_InterlockedCompareExchange_rel:
1896 case clang::AArch64::BI_InterlockedCompareExchange64_rel:
1897 case clang::AArch64::BI_InterlockedCompareExchangePointer_rel:
1898 return MSVCIntrin::_InterlockedCompareExchange_rel;
1899 case clang::AArch64::BI_InterlockedCompareExchange8_nf:
1900 case clang::AArch64::BI_InterlockedCompareExchange16_nf:
1901 case clang::AArch64::BI_InterlockedCompareExchange_nf:
1902 case clang::AArch64::BI_InterlockedCompareExchange64_nf:
1903 return MSVCIntrin::_InterlockedCompareExchange_nf;
1904 case clang::AArch64::BI_InterlockedCompareExchange128:
1905 return MSVCIntrin::_InterlockedCompareExchange128;
1906 case clang::AArch64::BI_InterlockedCompareExchange128_acq:
1907 return MSVCIntrin::_InterlockedCompareExchange128_acq;
1908 case clang::AArch64::BI_InterlockedCompareExchange128_nf:
1909 return MSVCIntrin::_InterlockedCompareExchange128_nf;
1910 case clang::AArch64::BI_InterlockedCompareExchange128_rel:
1911 return MSVCIntrin::_InterlockedCompareExchange128_rel;
1912 case clang::AArch64::BI_InterlockedOr8_acq:
1913 case clang::AArch64::BI_InterlockedOr16_acq:
1914 case clang::AArch64::BI_InterlockedOr_acq:
1915 case clang::AArch64::BI_InterlockedOr64_acq:
1916 return MSVCIntrin::_InterlockedOr_acq;
1917 case clang::AArch64::BI_InterlockedOr8_rel:
1918 case clang::AArch64::BI_InterlockedOr16_rel:
1919 case clang::AArch64::BI_InterlockedOr_rel:
1920 case clang::AArch64::BI_InterlockedOr64_rel:
1921 return MSVCIntrin::_InterlockedOr_rel;
1922 case clang::AArch64::BI_InterlockedOr8_nf:
1923 case clang::AArch64::BI_InterlockedOr16_nf:
1924 case clang::AArch64::BI_InterlockedOr_nf:
1925 case clang::AArch64::BI_InterlockedOr64_nf:
1926 return MSVCIntrin::_InterlockedOr_nf;
1927 case clang::AArch64::BI_InterlockedXor8_acq:
1928 case clang::AArch64::BI_InterlockedXor16_acq:
1929 case clang::AArch64::BI_InterlockedXor_acq:
1930 case clang::AArch64::BI_InterlockedXor64_acq:
1931 return MSVCIntrin::_InterlockedXor_acq;
1932 case clang::AArch64::BI_InterlockedXor8_rel:
1933 case clang::AArch64::BI_InterlockedXor16_rel:
1934 case clang::AArch64::BI_InterlockedXor_rel:
1935 case clang::AArch64::BI_InterlockedXor64_rel:
1936 return MSVCIntrin::_InterlockedXor_rel;
1937 case clang::AArch64::BI_InterlockedXor8_nf:
1938 case clang::AArch64::BI_InterlockedXor16_nf:
1939 case clang::AArch64::BI_InterlockedXor_nf:
1940 case clang::AArch64::BI_InterlockedXor64_nf:
1941 return MSVCIntrin::_InterlockedXor_nf;
1942 case clang::AArch64::BI_InterlockedAnd8_acq:
1943 case clang::AArch64::BI_InterlockedAnd16_acq:
1944 case clang::AArch64::BI_InterlockedAnd_acq:
1945 case clang::AArch64::BI_InterlockedAnd64_acq:
1946 return MSVCIntrin::_InterlockedAnd_acq;
1947 case clang::AArch64::BI_InterlockedAnd8_rel:
1948 case clang::AArch64::BI_InterlockedAnd16_rel:
1949 case clang::AArch64::BI_InterlockedAnd_rel:
1950 case clang::AArch64::BI_InterlockedAnd64_rel:
1951 return MSVCIntrin::_InterlockedAnd_rel;
1952 case clang::AArch64::BI_InterlockedAnd8_nf:
1953 case clang::AArch64::BI_InterlockedAnd16_nf:
1954 case clang::AArch64::BI_InterlockedAnd_nf:
1955 case clang::AArch64::BI_InterlockedAnd64_nf:
1956 return MSVCIntrin::_InterlockedAnd_nf;
1957 case clang::AArch64::BI_InterlockedIncrement16_acq:
1958 case clang::AArch64::BI_InterlockedIncrement_acq:
1959 case clang::AArch64::BI_InterlockedIncrement64_acq:
1960 return MSVCIntrin::_InterlockedIncrement_acq;
1961 case clang::AArch64::BI_InterlockedIncrement16_rel:
1962 case clang::AArch64::BI_InterlockedIncrement_rel:
1963 case clang::AArch64::BI_InterlockedIncrement64_rel:
1964 return MSVCIntrin::_InterlockedIncrement_rel;
1965 case clang::AArch64::BI_InterlockedIncrement16_nf:
1966 case clang::AArch64::BI_InterlockedIncrement_nf:
1967 case clang::AArch64::BI_InterlockedIncrement64_nf:
1968 return MSVCIntrin::_InterlockedIncrement_nf;
1969 case clang::AArch64::BI_InterlockedDecrement16_acq:
1970 case clang::AArch64::BI_InterlockedDecrement_acq:
1971 case clang::AArch64::BI_InterlockedDecrement64_acq:
1972 return MSVCIntrin::_InterlockedDecrement_acq;
1973 case clang::AArch64::BI_InterlockedDecrement16_rel:
1974 case clang::AArch64::BI_InterlockedDecrement_rel:
1975 case clang::AArch64::BI_InterlockedDecrement64_rel:
1976 return MSVCIntrin::_InterlockedDecrement_rel;
1977 case clang::AArch64::BI_InterlockedDecrement16_nf:
1978 case clang::AArch64::BI_InterlockedDecrement_nf:
1979 case clang::AArch64::BI_InterlockedDecrement64_nf:
1980 return MSVCIntrin::_InterlockedDecrement_nf;
1982 llvm_unreachable(
"must return from switch");
1985static std::optional<CodeGenFunction::MSVCIntrin>
1988 switch (BuiltinID) {
1990 return std::nullopt;
1991 case clang::X86::BI_BitScanForward:
1992 case clang::X86::BI_BitScanForward64:
1993 return MSVCIntrin::_BitScanForward;
1994 case clang::X86::BI_BitScanReverse:
1995 case clang::X86::BI_BitScanReverse64:
1996 return MSVCIntrin::_BitScanReverse;
1997 case clang::X86::BI_InterlockedAnd64:
1998 return MSVCIntrin::_InterlockedAnd;
1999 case clang::X86::BI_InterlockedCompareExchange128:
2000 return MSVCIntrin::_InterlockedCompareExchange128;
2001 case clang::X86::BI_InterlockedExchange64:
2002 return MSVCIntrin::_InterlockedExchange;
2003 case clang::X86::BI_InterlockedExchangeAdd64:
2004 return MSVCIntrin::_InterlockedExchangeAdd;
2005 case clang::X86::BI_InterlockedExchangeSub64:
2006 return MSVCIntrin::_InterlockedExchangeSub;
2007 case clang::X86::BI_InterlockedOr64:
2008 return MSVCIntrin::_InterlockedOr;
2009 case clang::X86::BI_InterlockedXor64:
2010 return MSVCIntrin::_InterlockedXor;
2011 case clang::X86::BI_InterlockedDecrement64:
2012 return MSVCIntrin::_InterlockedDecrement;
2013 case clang::X86::BI_InterlockedIncrement64:
2014 return MSVCIntrin::_InterlockedIncrement;
2016 llvm_unreachable(
"must return from switch");
2022 switch (BuiltinID) {
2023 case MSVCIntrin::_BitScanForward:
2024 case MSVCIntrin::_BitScanReverse: {
2028 llvm::Type *ArgType = ArgValue->
getType();
2029 llvm::Type *IndexType = IndexAddress.getElementType();
2032 Value *ArgZero = llvm::Constant::getNullValue(ArgType);
2033 Value *ResZero = llvm::Constant::getNullValue(ResultType);
2034 Value *ResOne = llvm::ConstantInt::get(ResultType, 1);
2039 PHINode *
Result =
Builder.CreatePHI(ResultType, 2,
"bitscan_result");
2042 Value *IsZero =
Builder.CreateICmpEQ(ArgValue, ArgZero);
2044 Builder.CreateCondBr(IsZero, End, NotZero);
2047 Builder.SetInsertPoint(NotZero);
2049 if (BuiltinID == MSVCIntrin::_BitScanForward) {
2052 ZeroCount =
Builder.CreateIntCast(ZeroCount, IndexType,
false);
2055 unsigned ArgWidth = cast<llvm::IntegerType>(ArgType)->getBitWidth();
2056 Value *ArgTypeLastIndex = llvm::ConstantInt::get(IndexType, ArgWidth - 1);
2060 ZeroCount =
Builder.CreateIntCast(ZeroCount, IndexType,
false);
2061 Value *Index =
Builder.CreateNSWSub(ArgTypeLastIndex, ZeroCount);
2065 Result->addIncoming(ResOne, NotZero);
2070 case MSVCIntrin::_InterlockedAnd:
2072 case MSVCIntrin::_InterlockedExchange:
2074 case MSVCIntrin::_InterlockedExchangeAdd:
2076 case MSVCIntrin::_InterlockedExchangeSub:
2078 case MSVCIntrin::_InterlockedOr:
2080 case MSVCIntrin::_InterlockedXor:
2082 case MSVCIntrin::_InterlockedExchangeAdd_acq:
2084 AtomicOrdering::Acquire);
2085 case MSVCIntrin::_InterlockedExchangeAdd_rel:
2087 AtomicOrdering::Release);
2088 case MSVCIntrin::_InterlockedExchangeAdd_nf:
2090 AtomicOrdering::Monotonic);
2091 case MSVCIntrin::_InterlockedExchange_acq:
2093 AtomicOrdering::Acquire);
2094 case MSVCIntrin::_InterlockedExchange_rel:
2096 AtomicOrdering::Release);
2097 case MSVCIntrin::_InterlockedExchange_nf:
2099 AtomicOrdering::Monotonic);
2100 case MSVCIntrin::_InterlockedCompareExchange:
2102 case MSVCIntrin::_InterlockedCompareExchange_acq:
2104 case MSVCIntrin::_InterlockedCompareExchange_rel:
2106 case MSVCIntrin::_InterlockedCompareExchange_nf:
2108 case MSVCIntrin::_InterlockedCompareExchange128:
2110 *
this,
E, AtomicOrdering::SequentiallyConsistent);
2111 case MSVCIntrin::_InterlockedCompareExchange128_acq:
2113 case MSVCIntrin::_InterlockedCompareExchange128_rel:
2115 case MSVCIntrin::_InterlockedCompareExchange128_nf:
2117 case MSVCIntrin::_InterlockedOr_acq:
2119 AtomicOrdering::Acquire);
2120 case MSVCIntrin::_InterlockedOr_rel:
2122 AtomicOrdering::Release);
2123 case MSVCIntrin::_InterlockedOr_nf:
2125 AtomicOrdering::Monotonic);
2126 case MSVCIntrin::_InterlockedXor_acq:
2128 AtomicOrdering::Acquire);
2129 case MSVCIntrin::_InterlockedXor_rel:
2131 AtomicOrdering::Release);
2132 case MSVCIntrin::_InterlockedXor_nf:
2134 AtomicOrdering::Monotonic);
2135 case MSVCIntrin::_InterlockedAnd_acq:
2137 AtomicOrdering::Acquire);
2138 case MSVCIntrin::_InterlockedAnd_rel:
2140 AtomicOrdering::Release);
2141 case MSVCIntrin::_InterlockedAnd_nf:
2143 AtomicOrdering::Monotonic);
2144 case MSVCIntrin::_InterlockedIncrement_acq:
2146 case MSVCIntrin::_InterlockedIncrement_rel:
2148 case MSVCIntrin::_InterlockedIncrement_nf:
2150 case MSVCIntrin::_InterlockedDecrement_acq:
2152 case MSVCIntrin::_InterlockedDecrement_rel:
2154 case MSVCIntrin::_InterlockedDecrement_nf:
2157 case MSVCIntrin::_InterlockedDecrement:
2159 case MSVCIntrin::_InterlockedIncrement:
2162 case MSVCIntrin::__fastfail: {
2167 StringRef
Asm, Constraints;
2172 case llvm::Triple::x86:
2173 case llvm::Triple::x86_64:
2175 Constraints =
"{cx}";
2177 case llvm::Triple::thumb:
2179 Constraints =
"{r0}";
2181 case llvm::Triple::aarch64:
2182 Asm =
"brk #0xF003";
2183 Constraints =
"{w0}";
2185 llvm::FunctionType *FTy = llvm::FunctionType::get(
VoidTy, {
Int32Ty},
false);
2186 llvm::InlineAsm *IA =
2187 llvm::InlineAsm::get(FTy,
Asm, Constraints,
true);
2188 llvm::AttributeList NoReturnAttr = llvm::AttributeList::get(
2190 llvm::Attribute::NoReturn);
2192 CI->setAttributes(NoReturnAttr);
2196 llvm_unreachable(
"Incorrect MSVC intrinsic!");
2202 CallObjCArcUse(llvm::Value *
object) : object(object) {}
2203 llvm::Value *object;
2212 BuiltinCheckKind Kind) {
2214 "Unsupported builtin check kind");
2220 SanitizerScope SanScope(
this);
2222 ArgValue, llvm::Constant::getNullValue(ArgValue->
getType()));
2223 EmitCheck(std::make_pair(Cond, SanitizerKind::Builtin),
2224 SanitizerHandler::InvalidBuiltin,
2226 llvm::ConstantInt::get(
Builder.getInt8Ty(), Kind)},
2236 SanitizerScope SanScope(
this);
2238 std::make_pair(ArgValue, SanitizerKind::Builtin),
2239 SanitizerHandler::InvalidBuiltin,
2247 return CGF.
Builder.CreateBinaryIntrinsic(
2248 Intrinsic::abs, ArgValue,
2249 ConstantInt::get(CGF.
Builder.getInt1Ty(), HasNSW));
2253 bool SanitizeOverflow) {
2257 if (
const auto *VCI = dyn_cast<llvm::ConstantInt>(ArgValue)) {
2258 if (!VCI->isMinSignedValue())
2259 return EmitAbs(CGF, ArgValue,
true);
2262 CodeGenFunction::SanitizerScope SanScope(&CGF);
2264 Constant *Zero = Constant::getNullValue(ArgValue->
getType());
2265 Value *ResultAndOverflow = CGF.
Builder.CreateBinaryIntrinsic(
2266 Intrinsic::ssub_with_overflow, Zero, ArgValue);
2269 CGF.
Builder.CreateExtractValue(ResultAndOverflow, 1));
2272 if (SanitizeOverflow) {
2273 CGF.
EmitCheck({{NotOverflow, SanitizerKind::SignedIntegerOverflow}},
2274 SanitizerHandler::NegateOverflow,
2279 CGF.
EmitTrapCheck(NotOverflow, SanitizerHandler::SubOverflow);
2281 Value *CmpResult = CGF.
Builder.CreateICmpSLT(ArgValue, Zero,
"abscond");
2282 return CGF.
Builder.CreateSelect(CmpResult,
Result, ArgValue,
"abs");
2287 QualType UnsignedTy =
C.getIntTypeForBitwidth(Size * 8,
false);
2288 return C.getCanonicalType(UnsignedTy);
2298 raw_svector_ostream OS(Name);
2299 OS <<
"__os_log_helper";
2303 for (
const auto &Item : Layout.
Items)
2304 OS <<
"_" <<
int(Item.getSizeByte()) <<
"_"
2305 <<
int(Item.getDescriptorByte());
2308 if (llvm::Function *F =
CGM.
getModule().getFunction(Name))
2318 for (
unsigned int I = 0,
E = Layout.
Items.size(); I <
E; ++I) {
2319 char Size = Layout.
Items[I].getSizeByte();
2326 &Ctx.
Idents.
get(std::string(
"arg") + llvm::to_string(I)), ArgTy,
2328 ArgTys.emplace_back(ArgTy);
2339 llvm::Function *
Fn = llvm::Function::Create(
2340 FuncTy, llvm::GlobalValue::LinkOnceODRLinkage, Name, &
CGM.
getModule());
2341 Fn->setVisibility(llvm::GlobalValue::HiddenVisibility);
2344 Fn->setDoesNotThrow();
2348 Fn->addFnAttr(llvm::Attribute::NoInline);
2366 for (
const auto &Item : Layout.
Items) {
2368 Builder.getInt8(Item.getDescriptorByte()),
2371 Builder.getInt8(Item.getSizeByte()),
2375 if (!
Size.getQuantity())
2392 assert(
E.getNumArgs() >= 2 &&
2393 "__builtin_os_log_format takes at least 2 arguments");
2404 for (
const auto &Item : Layout.
Items) {
2405 int Size = Item.getSizeByte();
2409 llvm::Value *ArgVal;
2413 for (
unsigned I = 0,
E = Item.getMaskType().size(); I <
E; ++I)
2414 Val |= ((
uint64_t)Item.getMaskType()[I]) << I * 8;
2415 ArgVal = llvm::Constant::getIntegerValue(
Int64Ty, llvm::APInt(64, Val));
2416 }
else if (
const Expr *TheExpr = Item.getExpr()) {
2422 auto LifetimeExtendObject = [&](
const Expr *
E) {
2430 if (isa<CallExpr>(
E) || isa<ObjCMessageExpr>(
E))
2435 if (TheExpr->getType()->isObjCRetainableType() &&
2436 getLangOpts().ObjCAutoRefCount && LifetimeExtendObject(TheExpr)) {
2438 "Only scalar can be a ObjC retainable type");
2439 if (!isa<Constant>(ArgVal)) {
2453 pushCleanupAfterFullExpr<CallObjCArcUse>(Cleanup, ArgVal);
2457 ArgVal =
Builder.getInt32(Item.getConstValue().getQuantity());
2460 unsigned ArgValSize =
2464 ArgVal =
Builder.CreateBitOrPointerCast(ArgVal,
IntTy);
2480 unsigned BuiltinID, WidthAndSignedness Op1Info, WidthAndSignedness Op2Info,
2481 WidthAndSignedness ResultInfo) {
2482 return BuiltinID == Builtin::BI__builtin_mul_overflow &&
2483 Op1Info.Width == Op2Info.Width && Op2Info.Width == ResultInfo.Width &&
2484 !Op1Info.Signed && !Op2Info.Signed && ResultInfo.Signed;
2489 const clang::Expr *Op2, WidthAndSignedness Op2Info,
2491 WidthAndSignedness ResultInfo) {
2493 Builtin::BI__builtin_mul_overflow, Op1Info, Op2Info, ResultInfo) &&
2494 "Cannot specialize this multiply");
2499 llvm::Value *HasOverflow;
2501 CGF, llvm::Intrinsic::umul_with_overflow, V1, V2, HasOverflow);
2506 auto IntMax = llvm::APInt::getSignedMaxValue(ResultInfo.Width);
2507 llvm::Value *IntMaxValue = llvm::ConstantInt::get(
Result->getType(), IntMax);
2509 llvm::Value *IntMaxOverflow = CGF.
Builder.CreateICmpUGT(
Result, IntMaxValue);
2510 HasOverflow = CGF.
Builder.CreateOr(HasOverflow, IntMaxOverflow);
2522 WidthAndSignedness Op1Info,
2523 WidthAndSignedness Op2Info,
2524 WidthAndSignedness ResultInfo) {
2525 return BuiltinID == Builtin::BI__builtin_mul_overflow &&
2526 std::max(Op1Info.Width, Op2Info.Width) >= ResultInfo.Width &&
2527 Op1Info.Signed != Op2Info.Signed;
2534 WidthAndSignedness Op1Info,
const clang::Expr *Op2,
2535 WidthAndSignedness Op2Info,
2537 WidthAndSignedness ResultInfo) {
2539 Op2Info, ResultInfo) &&
2540 "Not a mixed-sign multipliction we can specialize");
2543 const clang::Expr *SignedOp = Op1Info.Signed ? Op1 : Op2;
2544 const clang::Expr *UnsignedOp = Op1Info.Signed ? Op2 : Op1;
2547 unsigned SignedOpWidth = Op1Info.Signed ? Op1Info.Width : Op2Info.Width;
2548 unsigned UnsignedOpWidth = Op1Info.Signed ? Op2Info.Width : Op1Info.Width;
2551 if (SignedOpWidth < UnsignedOpWidth)
2553 if (UnsignedOpWidth < SignedOpWidth)
2556 llvm::Type *OpTy =
Signed->getType();
2557 llvm::Value *Zero = llvm::Constant::getNullValue(OpTy);
2560 unsigned OpWidth = std::max(Op1Info.Width, Op2Info.Width);
2563 llvm::Value *IsNegative = CGF.
Builder.CreateICmpSLT(
Signed, Zero);
2564 llvm::Value *AbsOfNegative = CGF.
Builder.CreateSub(Zero,
Signed);
2565 llvm::Value *AbsSigned =
2566 CGF.
Builder.CreateSelect(IsNegative, AbsOfNegative,
Signed);
2569 llvm::Value *UnsignedOverflow;
2570 llvm::Value *UnsignedResult =
2574 llvm::Value *Overflow, *
Result;
2575 if (ResultInfo.Signed) {
2579 llvm::APInt::getSignedMaxValue(ResultInfo.Width).zext(OpWidth);
2580 llvm::Value *MaxResult =
2581 CGF.
Builder.CreateAdd(llvm::ConstantInt::get(OpTy, IntMax),
2582 CGF.
Builder.CreateZExt(IsNegative, OpTy));
2583 llvm::Value *SignedOverflow =
2584 CGF.
Builder.CreateICmpUGT(UnsignedResult, MaxResult);
2585 Overflow = CGF.
Builder.CreateOr(UnsignedOverflow, SignedOverflow);
2588 llvm::Value *NegativeResult = CGF.
Builder.CreateNeg(UnsignedResult);
2589 llvm::Value *SignedResult =
2590 CGF.
Builder.CreateSelect(IsNegative, NegativeResult, UnsignedResult);
2594 llvm::Value *Underflow = CGF.
Builder.CreateAnd(
2595 IsNegative, CGF.
Builder.CreateIsNotNull(UnsignedResult));
2596 Overflow = CGF.
Builder.CreateOr(UnsignedOverflow, Underflow);
2597 if (ResultInfo.Width < OpWidth) {
2599 llvm::APInt::getMaxValue(ResultInfo.Width).zext(OpWidth);
2600 llvm::Value *TruncOverflow = CGF.
Builder.CreateICmpUGT(
2601 UnsignedResult, llvm::ConstantInt::get(OpTy, IntMax));
2602 Overflow = CGF.
Builder.CreateOr(Overflow, TruncOverflow);
2607 IsNegative, CGF.
Builder.CreateNeg(UnsignedResult), UnsignedResult);
2611 assert(Overflow &&
Result &&
"Missing overflow or result");
2622 llvm::SmallPtrSetImpl<const Decl *> &Seen) {
2631 if (!Seen.insert(
Record).second)
2634 assert(
Record->hasDefinition() &&
2635 "Incomplete types should already be diagnosed");
2637 if (
Record->isDynamicClass())
2662 llvm::Type *Ty = Src->getType();
2663 ShiftAmt =
Builder.CreateIntCast(ShiftAmt, Ty,
false);
2666 unsigned IID = IsRotateRight ? Intrinsic::fshr : Intrinsic::fshl;
2673 switch (BuiltinID) {
2674#define MUTATE_LDBL(func) \
2675 case Builtin::BI__builtin_##func##l: \
2676 return Builtin::BI__builtin_##func##f128;
2745 if (CGF.
Builder.getIsFPConstrained() &&
2746 CGF.
Builder.getDefaultConstrainedExcept() != fp::ebIgnore) {
2758 auto UBF = CGF->
CGM.
getModule().getOrInsertFunction(Name, FnTy);
2761 for (
auto &&FormalTy : FnTy->params())
2762 Args.push_back(llvm::PoisonValue::get(FormalTy));
2771 "Should not codegen for consteval builtins");
2778 !
Result.hasSideEffects()) {
2782 if (
Result.Val.isFloat())
2791 if (
getTarget().getTriple().isPPC64() &&
2792 &
getTarget().getLongDoubleFormat() == &llvm::APFloat::IEEEquad())
2799 const unsigned BuiltinIDIfNoAsmLabel =
2800 FD->
hasAttr<AsmLabelAttr>() ? 0 : BuiltinID;
2802 std::optional<bool> ErrnoOverriden;
2806 if (
E->hasStoredFPFeatures()) {
2808 if (OP.hasMathErrnoOverride())
2809 ErrnoOverriden = OP.getMathErrnoOverride();
2818 bool ErrnoOverridenToFalseWithOpt =
2819 ErrnoOverriden.has_value() && !ErrnoOverriden.value() && !OptNone &&
2837 switch (BuiltinID) {
2838 case Builtin::BI__builtin_fma:
2839 case Builtin::BI__builtin_fmaf:
2840 case Builtin::BI__builtin_fmal:
2841 case Builtin::BI__builtin_fmaf16:
2842 case Builtin::BIfma:
2843 case Builtin::BIfmaf:
2844 case Builtin::BIfmal: {
2846 if (Trip.isGNUEnvironment() || Trip.isOSMSVCRT())
2854 bool ConstWithoutErrnoAndExceptions =
2856 bool ConstWithoutExceptions =
2874 bool ConstWithoutErrnoOrExceptions =
2875 ConstWithoutErrnoAndExceptions || ConstWithoutExceptions;
2876 bool GenerateIntrinsics =
2877 (ConstAlways && !OptNone) ||
2879 !(ErrnoOverriden.has_value() && ErrnoOverriden.value()) && !OptNone);
2880 if (!GenerateIntrinsics) {
2881 GenerateIntrinsics =
2882 ConstWithoutErrnoOrExceptions && !ConstWithoutErrnoAndExceptions;
2883 if (!GenerateIntrinsics)
2884 GenerateIntrinsics =
2885 ConstWithoutErrnoOrExceptions &&
2887 !(ErrnoOverriden.has_value() && ErrnoOverriden.value()) && !OptNone);
2888 if (!GenerateIntrinsics)
2889 GenerateIntrinsics =
2890 ConstWithoutErrnoOrExceptions && ErrnoOverridenToFalseWithOpt;
2892 if (GenerateIntrinsics) {
2893 switch (BuiltinIDIfNoAsmLabel) {
2894 case Builtin::BIacos:
2895 case Builtin::BIacosf:
2896 case Builtin::BIacosl:
2897 case Builtin::BI__builtin_acos:
2898 case Builtin::BI__builtin_acosf:
2899 case Builtin::BI__builtin_acosf16:
2900 case Builtin::BI__builtin_acosl:
2901 case Builtin::BI__builtin_acosf128:
2903 *
this,
E, Intrinsic::acos, Intrinsic::experimental_constrained_acos));
2905 case Builtin::BIasin:
2906 case Builtin::BIasinf:
2907 case Builtin::BIasinl:
2908 case Builtin::BI__builtin_asin:
2909 case Builtin::BI__builtin_asinf:
2910 case Builtin::BI__builtin_asinf16:
2911 case Builtin::BI__builtin_asinl:
2912 case Builtin::BI__builtin_asinf128:
2914 *
this,
E, Intrinsic::asin, Intrinsic::experimental_constrained_asin));
2916 case Builtin::BIatan:
2917 case Builtin::BIatanf:
2918 case Builtin::BIatanl:
2919 case Builtin::BI__builtin_atan:
2920 case Builtin::BI__builtin_atanf:
2921 case Builtin::BI__builtin_atanf16:
2922 case Builtin::BI__builtin_atanl:
2923 case Builtin::BI__builtin_atanf128:
2925 *
this,
E, Intrinsic::atan, Intrinsic::experimental_constrained_atan));
2927 case Builtin::BIatan2:
2928 case Builtin::BIatan2f:
2929 case Builtin::BIatan2l:
2930 case Builtin::BI__builtin_atan2:
2931 case Builtin::BI__builtin_atan2f:
2932 case Builtin::BI__builtin_atan2f16:
2933 case Builtin::BI__builtin_atan2l:
2934 case Builtin::BI__builtin_atan2f128:
2936 *
this,
E, Intrinsic::atan2,
2937 Intrinsic::experimental_constrained_atan2));
2939 case Builtin::BIceil:
2940 case Builtin::BIceilf:
2941 case Builtin::BIceill:
2942 case Builtin::BI__builtin_ceil:
2943 case Builtin::BI__builtin_ceilf:
2944 case Builtin::BI__builtin_ceilf16:
2945 case Builtin::BI__builtin_ceill:
2946 case Builtin::BI__builtin_ceilf128:
2949 Intrinsic::experimental_constrained_ceil));
2951 case Builtin::BIcopysign:
2952 case Builtin::BIcopysignf:
2953 case Builtin::BIcopysignl:
2954 case Builtin::BI__builtin_copysign:
2955 case Builtin::BI__builtin_copysignf:
2956 case Builtin::BI__builtin_copysignf16:
2957 case Builtin::BI__builtin_copysignl:
2958 case Builtin::BI__builtin_copysignf128:
2960 emitBuiltinWithOneOverloadedType<2>(*
this,
E, Intrinsic::copysign));
2962 case Builtin::BIcos:
2963 case Builtin::BIcosf:
2964 case Builtin::BIcosl:
2965 case Builtin::BI__builtin_cos:
2966 case Builtin::BI__builtin_cosf:
2967 case Builtin::BI__builtin_cosf16:
2968 case Builtin::BI__builtin_cosl:
2969 case Builtin::BI__builtin_cosf128:
2972 Intrinsic::experimental_constrained_cos));
2974 case Builtin::BIcosh:
2975 case Builtin::BIcoshf:
2976 case Builtin::BIcoshl:
2977 case Builtin::BI__builtin_cosh:
2978 case Builtin::BI__builtin_coshf:
2979 case Builtin::BI__builtin_coshf16:
2980 case Builtin::BI__builtin_coshl:
2981 case Builtin::BI__builtin_coshf128:
2983 *
this,
E, Intrinsic::cosh, Intrinsic::experimental_constrained_cosh));
2985 case Builtin::BIexp:
2986 case Builtin::BIexpf:
2987 case Builtin::BIexpl:
2988 case Builtin::BI__builtin_exp:
2989 case Builtin::BI__builtin_expf:
2990 case Builtin::BI__builtin_expf16:
2991 case Builtin::BI__builtin_expl:
2992 case Builtin::BI__builtin_expf128:
2995 Intrinsic::experimental_constrained_exp));
2997 case Builtin::BIexp2:
2998 case Builtin::BIexp2f:
2999 case Builtin::BIexp2l:
3000 case Builtin::BI__builtin_exp2:
3001 case Builtin::BI__builtin_exp2f:
3002 case Builtin::BI__builtin_exp2f16:
3003 case Builtin::BI__builtin_exp2l:
3004 case Builtin::BI__builtin_exp2f128:
3007 Intrinsic::experimental_constrained_exp2));
3008 case Builtin::BI__builtin_exp10:
3009 case Builtin::BI__builtin_exp10f:
3010 case Builtin::BI__builtin_exp10f16:
3011 case Builtin::BI__builtin_exp10l:
3012 case Builtin::BI__builtin_exp10f128: {
3014 if (
Builder.getIsFPConstrained())
3017 emitBuiltinWithOneOverloadedType<1>(*
this,
E, Intrinsic::exp10));
3019 case Builtin::BIfabs:
3020 case Builtin::BIfabsf:
3021 case Builtin::BIfabsl:
3022 case Builtin::BI__builtin_fabs:
3023 case Builtin::BI__builtin_fabsf:
3024 case Builtin::BI__builtin_fabsf16:
3025 case Builtin::BI__builtin_fabsl:
3026 case Builtin::BI__builtin_fabsf128:
3028 emitBuiltinWithOneOverloadedType<1>(*
this,
E, Intrinsic::fabs));
3030 case Builtin::BIfloor:
3031 case Builtin::BIfloorf:
3032 case Builtin::BIfloorl:
3033 case Builtin::BI__builtin_floor:
3034 case Builtin::BI__builtin_floorf:
3035 case Builtin::BI__builtin_floorf16:
3036 case Builtin::BI__builtin_floorl:
3037 case Builtin::BI__builtin_floorf128:
3040 Intrinsic::experimental_constrained_floor));
3042 case Builtin::BIfma:
3043 case Builtin::BIfmaf:
3044 case Builtin::BIfmal:
3045 case Builtin::BI__builtin_fma:
3046 case Builtin::BI__builtin_fmaf:
3047 case Builtin::BI__builtin_fmaf16:
3048 case Builtin::BI__builtin_fmal:
3049 case Builtin::BI__builtin_fmaf128:
3052 Intrinsic::experimental_constrained_fma));
3054 case Builtin::BIfmax:
3055 case Builtin::BIfmaxf:
3056 case Builtin::BIfmaxl:
3057 case Builtin::BI__builtin_fmax:
3058 case Builtin::BI__builtin_fmaxf:
3059 case Builtin::BI__builtin_fmaxf16:
3060 case Builtin::BI__builtin_fmaxl:
3061 case Builtin::BI__builtin_fmaxf128:
3064 Intrinsic::experimental_constrained_maxnum));
3066 case Builtin::BIfmin:
3067 case Builtin::BIfminf:
3068 case Builtin::BIfminl:
3069 case Builtin::BI__builtin_fmin:
3070 case Builtin::BI__builtin_fminf:
3071 case Builtin::BI__builtin_fminf16:
3072 case Builtin::BI__builtin_fminl:
3073 case Builtin::BI__builtin_fminf128:
3076 Intrinsic::experimental_constrained_minnum));
3078 case Builtin::BIfmaximum_num:
3079 case Builtin::BIfmaximum_numf:
3080 case Builtin::BIfmaximum_numl:
3081 case Builtin::BI__builtin_fmaximum_num:
3082 case Builtin::BI__builtin_fmaximum_numf:
3083 case Builtin::BI__builtin_fmaximum_numf16:
3084 case Builtin::BI__builtin_fmaximum_numl:
3085 case Builtin::BI__builtin_fmaximum_numf128:
3087 emitBuiltinWithOneOverloadedType<2>(*
this,
E, Intrinsic::maximumnum));
3089 case Builtin::BIfminimum_num:
3090 case Builtin::BIfminimum_numf:
3091 case Builtin::BIfminimum_numl:
3092 case Builtin::BI__builtin_fminimum_num:
3093 case Builtin::BI__builtin_fminimum_numf:
3094 case Builtin::BI__builtin_fminimum_numf16:
3095 case Builtin::BI__builtin_fminimum_numl:
3096 case Builtin::BI__builtin_fminimum_numf128:
3098 emitBuiltinWithOneOverloadedType<2>(*
this,
E, Intrinsic::minimumnum));
3102 case Builtin::BIfmod:
3103 case Builtin::BIfmodf:
3104 case Builtin::BIfmodl:
3105 case Builtin::BI__builtin_fmod:
3106 case Builtin::BI__builtin_fmodf:
3107 case Builtin::BI__builtin_fmodf16:
3108 case Builtin::BI__builtin_fmodl:
3109 case Builtin::BI__builtin_fmodf128:
3110 case Builtin::BI__builtin_elementwise_fmod: {
3111 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*
this,
E);
3117 case Builtin::BIlog:
3118 case Builtin::BIlogf:
3119 case Builtin::BIlogl:
3120 case Builtin::BI__builtin_log:
3121 case Builtin::BI__builtin_logf:
3122 case Builtin::BI__builtin_logf16:
3123 case Builtin::BI__builtin_logl:
3124 case Builtin::BI__builtin_logf128:
3127 Intrinsic::experimental_constrained_log));
3129 case Builtin::BIlog10:
3130 case Builtin::BIlog10f:
3131 case Builtin::BIlog10l:
3132 case Builtin::BI__builtin_log10:
3133 case Builtin::BI__builtin_log10f:
3134 case Builtin::BI__builtin_log10f16:
3135 case Builtin::BI__builtin_log10l:
3136 case Builtin::BI__builtin_log10f128:
3139 Intrinsic::experimental_constrained_log10));
3141 case Builtin::BIlog2:
3142 case Builtin::BIlog2f:
3143 case Builtin::BIlog2l:
3144 case Builtin::BI__builtin_log2:
3145 case Builtin::BI__builtin_log2f:
3146 case Builtin::BI__builtin_log2f16:
3147 case Builtin::BI__builtin_log2l:
3148 case Builtin::BI__builtin_log2f128:
3151 Intrinsic::experimental_constrained_log2));
3153 case Builtin::BInearbyint:
3154 case Builtin::BInearbyintf:
3155 case Builtin::BInearbyintl:
3156 case Builtin::BI__builtin_nearbyint:
3157 case Builtin::BI__builtin_nearbyintf:
3158 case Builtin::BI__builtin_nearbyintl:
3159 case Builtin::BI__builtin_nearbyintf128:
3161 Intrinsic::nearbyint,
3162 Intrinsic::experimental_constrained_nearbyint));
3164 case Builtin::BIpow:
3165 case Builtin::BIpowf:
3166 case Builtin::BIpowl:
3167 case Builtin::BI__builtin_pow:
3168 case Builtin::BI__builtin_powf:
3169 case Builtin::BI__builtin_powf16:
3170 case Builtin::BI__builtin_powl:
3171 case Builtin::BI__builtin_powf128:
3174 Intrinsic::experimental_constrained_pow));
3176 case Builtin::BIrint:
3177 case Builtin::BIrintf:
3178 case Builtin::BIrintl:
3179 case Builtin::BI__builtin_rint:
3180 case Builtin::BI__builtin_rintf:
3181 case Builtin::BI__builtin_rintf16:
3182 case Builtin::BI__builtin_rintl:
3183 case Builtin::BI__builtin_rintf128:
3186 Intrinsic::experimental_constrained_rint));
3188 case Builtin::BIround:
3189 case Builtin::BIroundf:
3190 case Builtin::BIroundl:
3191 case Builtin::BI__builtin_round:
3192 case Builtin::BI__builtin_roundf:
3193 case Builtin::BI__builtin_roundf16:
3194 case Builtin::BI__builtin_roundl:
3195 case Builtin::BI__builtin_roundf128:
3198 Intrinsic::experimental_constrained_round));
3200 case Builtin::BIroundeven:
3201 case Builtin::BIroundevenf:
3202 case Builtin::BIroundevenl:
3203 case Builtin::BI__builtin_roundeven:
3204 case Builtin::BI__builtin_roundevenf:
3205 case Builtin::BI__builtin_roundevenf16:
3206 case Builtin::BI__builtin_roundevenl:
3207 case Builtin::BI__builtin_roundevenf128:
3209 Intrinsic::roundeven,
3210 Intrinsic::experimental_constrained_roundeven));
3212 case Builtin::BIsin:
3213 case Builtin::BIsinf:
3214 case Builtin::BIsinl:
3215 case Builtin::BI__builtin_sin:
3216 case Builtin::BI__builtin_sinf:
3217 case Builtin::BI__builtin_sinf16:
3218 case Builtin::BI__builtin_sinl:
3219 case Builtin::BI__builtin_sinf128:
3222 Intrinsic::experimental_constrained_sin));
3224 case Builtin::BIsinh:
3225 case Builtin::BIsinhf:
3226 case Builtin::BIsinhl:
3227 case Builtin::BI__builtin_sinh:
3228 case Builtin::BI__builtin_sinhf:
3229 case Builtin::BI__builtin_sinhf16:
3230 case Builtin::BI__builtin_sinhl:
3231 case Builtin::BI__builtin_sinhf128:
3233 *
this,
E, Intrinsic::sinh, Intrinsic::experimental_constrained_sinh));
3235 case Builtin::BIsqrt:
3236 case Builtin::BIsqrtf:
3237 case Builtin::BIsqrtl:
3238 case Builtin::BI__builtin_sqrt:
3239 case Builtin::BI__builtin_sqrtf:
3240 case Builtin::BI__builtin_sqrtf16:
3241 case Builtin::BI__builtin_sqrtl:
3242 case Builtin::BI__builtin_sqrtf128:
3243 case Builtin::BI__builtin_elementwise_sqrt: {
3245 *
this,
E, Intrinsic::sqrt, Intrinsic::experimental_constrained_sqrt);
3250 case Builtin::BItan:
3251 case Builtin::BItanf:
3252 case Builtin::BItanl:
3253 case Builtin::BI__builtin_tan:
3254 case Builtin::BI__builtin_tanf:
3255 case Builtin::BI__builtin_tanf16:
3256 case Builtin::BI__builtin_tanl:
3257 case Builtin::BI__builtin_tanf128:
3259 *
this,
E, Intrinsic::tan, Intrinsic::experimental_constrained_tan));
3261 case Builtin::BItanh:
3262 case Builtin::BItanhf:
3263 case Builtin::BItanhl:
3264 case Builtin::BI__builtin_tanh:
3265 case Builtin::BI__builtin_tanhf:
3266 case Builtin::BI__builtin_tanhf16:
3267 case Builtin::BI__builtin_tanhl:
3268 case Builtin::BI__builtin_tanhf128:
3270 *
this,
E, Intrinsic::tanh, Intrinsic::experimental_constrained_tanh));
3272 case Builtin::BItrunc:
3273 case Builtin::BItruncf:
3274 case Builtin::BItruncl:
3275 case Builtin::BI__builtin_trunc:
3276 case Builtin::BI__builtin_truncf:
3277 case Builtin::BI__builtin_truncf16:
3278 case Builtin::BI__builtin_truncl:
3279 case Builtin::BI__builtin_truncf128:
3282 Intrinsic::experimental_constrained_trunc));
3284 case Builtin::BIlround:
3285 case Builtin::BIlroundf:
3286 case Builtin::BIlroundl:
3287 case Builtin::BI__builtin_lround:
3288 case Builtin::BI__builtin_lroundf:
3289 case Builtin::BI__builtin_lroundl:
3290 case Builtin::BI__builtin_lroundf128:
3292 *
this,
E, Intrinsic::lround,
3293 Intrinsic::experimental_constrained_lround));
3295 case Builtin::BIllround:
3296 case Builtin::BIllroundf:
3297 case Builtin::BIllroundl:
3298 case Builtin::BI__builtin_llround:
3299 case Builtin::BI__builtin_llroundf:
3300 case Builtin::BI__builtin_llroundl:
3301 case Builtin::BI__builtin_llroundf128:
3303 *
this,
E, Intrinsic::llround,
3304 Intrinsic::experimental_constrained_llround));
3306 case Builtin::BIlrint:
3307 case Builtin::BIlrintf:
3308 case Builtin::BIlrintl:
3309 case Builtin::BI__builtin_lrint:
3310 case Builtin::BI__builtin_lrintf:
3311 case Builtin::BI__builtin_lrintl:
3312 case Builtin::BI__builtin_lrintf128:
3314 *
this,
E, Intrinsic::lrint,
3315 Intrinsic::experimental_constrained_lrint));
3317 case Builtin::BIllrint:
3318 case Builtin::BIllrintf:
3319 case Builtin::BIllrintl:
3320 case Builtin::BI__builtin_llrint:
3321 case Builtin::BI__builtin_llrintf:
3322 case Builtin::BI__builtin_llrintl:
3323 case Builtin::BI__builtin_llrintf128:
3325 *
this,
E, Intrinsic::llrint,
3326 Intrinsic::experimental_constrained_llrint));
3327 case Builtin::BI__builtin_ldexp:
3328 case Builtin::BI__builtin_ldexpf:
3329 case Builtin::BI__builtin_ldexpl:
3330 case Builtin::BI__builtin_ldexpf16:
3331 case Builtin::BI__builtin_ldexpf128: {
3333 *
this,
E, Intrinsic::ldexp,
3334 Intrinsic::experimental_constrained_ldexp));
3344 Value *Val = A.emitRawPointer(*
this);
3350 SkippedChecks.
set(SanitizerKind::All);
3351 SkippedChecks.
clear(SanitizerKind::Alignment);
3354 if (
auto *CE = dyn_cast<ImplicitCastExpr>(Arg))
3355 if (CE->getCastKind() == CK_BitCast)
3356 Arg = CE->getSubExpr();
3362 switch (BuiltinIDIfNoAsmLabel) {
3364 case Builtin::BI__builtin___CFStringMakeConstantString:
3365 case Builtin::BI__builtin___NSStringMakeConstantString:
3367 case Builtin::BI__builtin_stdarg_start:
3368 case Builtin::BI__builtin_va_start:
3369 case Builtin::BI__va_start:
3370 case Builtin::BI__builtin_va_end:
3374 BuiltinID != Builtin::BI__builtin_va_end);
3376 case Builtin::BI__builtin_va_copy: {
3383 case Builtin::BIabs:
3384 case Builtin::BIlabs:
3385 case Builtin::BIllabs:
3386 case Builtin::BI__builtin_abs:
3387 case Builtin::BI__builtin_labs:
3388 case Builtin::BI__builtin_llabs: {
3389 bool SanitizeOverflow =
SanOpts.
has(SanitizerKind::SignedIntegerOverflow);
3392 switch (
getLangOpts().getSignedOverflowBehavior()) {
3397 if (!SanitizeOverflow) {
3409 case Builtin::BI__builtin_complex: {
3414 case Builtin::BI__builtin_conj:
3415 case Builtin::BI__builtin_conjf:
3416 case Builtin::BI__builtin_conjl:
3417 case Builtin::BIconj:
3418 case Builtin::BIconjf:
3419 case Builtin::BIconjl: {
3421 Value *Real = ComplexVal.first;
3422 Value *Imag = ComplexVal.second;
3423 Imag =
Builder.CreateFNeg(Imag,
"neg");
3426 case Builtin::BI__builtin_creal:
3427 case Builtin::BI__builtin_crealf:
3428 case Builtin::BI__builtin_creall:
3429 case Builtin::BIcreal:
3430 case Builtin::BIcrealf:
3431 case Builtin::BIcreall: {
3436 case Builtin::BI__builtin_preserve_access_index: {
3457 case Builtin::BI__builtin_cimag:
3458 case Builtin::BI__builtin_cimagf:
3459 case Builtin::BI__builtin_cimagl:
3460 case Builtin::BIcimag:
3461 case Builtin::BIcimagf:
3462 case Builtin::BIcimagl: {
3467 case Builtin::BI__builtin_clrsb:
3468 case Builtin::BI__builtin_clrsbl:
3469 case Builtin::BI__builtin_clrsbll: {
3473 llvm::Type *ArgType = ArgValue->
getType();
3477 Value *
Zero = llvm::Constant::getNullValue(ArgType);
3478 Value *IsNeg =
Builder.CreateICmpSLT(ArgValue, Zero,
"isneg");
3480 Value *Tmp =
Builder.CreateSelect(IsNeg, Inverse, ArgValue);
3487 case Builtin::BI__builtin_ctzs:
3488 case Builtin::BI__builtin_ctz:
3489 case Builtin::BI__builtin_ctzl:
3490 case Builtin::BI__builtin_ctzll:
3491 case Builtin::BI__builtin_ctzg: {
3492 bool HasFallback = BuiltinIDIfNoAsmLabel == Builtin::BI__builtin_ctzg &&
3493 E->getNumArgs() > 1;
3499 llvm::Type *ArgType = ArgValue->
getType();
3506 if (
Result->getType() != ResultType)
3512 Value *
Zero = Constant::getNullValue(ArgType);
3513 Value *IsZero =
Builder.CreateICmpEQ(ArgValue, Zero,
"iszero");
3515 Value *ResultOrFallback =
3516 Builder.CreateSelect(IsZero, FallbackValue,
Result,
"ctzg");
3519 case Builtin::BI__builtin_clzs:
3520 case Builtin::BI__builtin_clz:
3521 case Builtin::BI__builtin_clzl:
3522 case Builtin::BI__builtin_clzll:
3523 case Builtin::BI__builtin_clzg: {
3524 bool HasFallback = BuiltinIDIfNoAsmLabel == Builtin::BI__builtin_clzg &&
3525 E->getNumArgs() > 1;
3531 llvm::Type *ArgType = ArgValue->
getType();
3538 if (
Result->getType() != ResultType)
3544 Value *
Zero = Constant::getNullValue(ArgType);
3545 Value *IsZero =
Builder.CreateICmpEQ(ArgValue, Zero,
"iszero");
3547 Value *ResultOrFallback =
3548 Builder.CreateSelect(IsZero, FallbackValue,
Result,
"clzg");
3551 case Builtin::BI__builtin_ffs:
3552 case Builtin::BI__builtin_ffsl:
3553 case Builtin::BI__builtin_ffsll: {
3557 llvm::Type *ArgType = ArgValue->
getType();
3562 Builder.CreateAdd(
Builder.CreateCall(F, {ArgValue, Builder.getTrue()}),
3563 llvm::ConstantInt::get(ArgType, 1));
3564 Value *
Zero = llvm::Constant::getNullValue(ArgType);
3565 Value *IsZero =
Builder.CreateICmpEQ(ArgValue, Zero,
"iszero");
3567 if (
Result->getType() != ResultType)
3572 case Builtin::BI__builtin_parity:
3573 case Builtin::BI__builtin_parityl:
3574 case Builtin::BI__builtin_parityll: {
3578 llvm::Type *ArgType = ArgValue->
getType();
3584 if (
Result->getType() != ResultType)
3589 case Builtin::BI__lzcnt16:
3590 case Builtin::BI__lzcnt:
3591 case Builtin::BI__lzcnt64: {
3594 llvm::Type *ArgType = ArgValue->
getType();
3599 if (
Result->getType() != ResultType)
3604 case Builtin::BI__popcnt16:
3605 case Builtin::BI__popcnt:
3606 case Builtin::BI__popcnt64:
3607 case Builtin::BI__builtin_popcount:
3608 case Builtin::BI__builtin_popcountl:
3609 case Builtin::BI__builtin_popcountll:
3610 case Builtin::BI__builtin_popcountg: {
3613 llvm::Type *ArgType = ArgValue->
getType();
3618 if (
Result->getType() != ResultType)
3623 case Builtin::BI__builtin_unpredictable: {
3629 case Builtin::BI__builtin_expect: {
3631 llvm::Type *ArgType = ArgValue->
getType();
3642 Builder.CreateCall(FnExpect, {ArgValue, ExpectedValue},
"expval");
3645 case Builtin::BI__builtin_expect_with_probability: {
3647 llvm::Type *ArgType = ArgValue->
getType();
3650 llvm::APFloat Probability(0.0);
3651 const Expr *ProbArg =
E->getArg(2);
3653 assert(EvalSucceed &&
"probability should be able to evaluate as float");
3655 bool LoseInfo =
false;
3656 Probability.convert(llvm::APFloat::IEEEdouble(),
3657 llvm::RoundingMode::Dynamic, &LoseInfo);
3659 Constant *Confidence = ConstantFP::get(Ty, Probability);
3669 FnExpect, {ArgValue, ExpectedValue, Confidence},
"expval");
3672 case Builtin::BI__builtin_assume_aligned: {
3673 const Expr *Ptr =
E->getArg(0);
3675 Value *OffsetValue =
3679 ConstantInt *AlignmentCI = cast<ConstantInt>(AlignmentValue);
3680 if (AlignmentCI->getValue().ugt(llvm::Value::MaximumAlignment))
3681 AlignmentCI = ConstantInt::get(AlignmentCI->getIntegerType(),
3682 llvm::Value::MaximumAlignment);
3686 AlignmentCI, OffsetValue);
3689 case Builtin::BI__assume:
3690 case Builtin::BI__builtin_assume: {
3696 Builder.CreateCall(FnAssume, ArgValue);
3699 case Builtin::BI__builtin_assume_separate_storage: {
3700 const Expr *Arg0 =
E->getArg(0);
3701 const Expr *Arg1 =
E->getArg(1);
3706 Value *Values[] = {Value0, Value1};
3707 OperandBundleDefT<Value *> OBD(
"separate_storage", Values);
3711 case Builtin::BI__builtin_allow_runtime_check: {
3715 llvm::Value *Allow =
Builder.CreateCall(
3717 llvm::MetadataAsValue::get(Ctx, llvm::MDString::get(Ctx, Kind)));
3720 case Builtin::BI__arithmetic_fence: {
3723 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*
this,
E);
3724 llvm::FastMathFlags FMF =
Builder.getFastMathFlags();
3725 bool isArithmeticFenceEnabled =
3726 FMF.allowReassoc() &&
3730 if (isArithmeticFenceEnabled) {
3733 Value *Real =
Builder.CreateArithmeticFence(ComplexVal.first,
3735 Value *Imag =
Builder.CreateArithmeticFence(ComplexVal.second,
3740 Value *Real = ComplexVal.first;
3741 Value *Imag = ComplexVal.second;
3745 if (isArithmeticFenceEnabled)
3750 case Builtin::BI__builtin_bswap16:
3751 case Builtin::BI__builtin_bswap32:
3752 case Builtin::BI__builtin_bswap64:
3753 case Builtin::BI_byteswap_ushort:
3754 case Builtin::BI_byteswap_ulong:
3755 case Builtin::BI_byteswap_uint64: {
3757 emitBuiltinWithOneOverloadedType<1>(*
this,
E, Intrinsic::bswap));
3759 case Builtin::BI__builtin_bitreverse8:
3760 case Builtin::BI__builtin_bitreverse16:
3761 case Builtin::BI__builtin_bitreverse32:
3762 case Builtin::BI__builtin_bitreverse64: {
3764 emitBuiltinWithOneOverloadedType<1>(*
this,
E, Intrinsic::bitreverse));
3766 case Builtin::BI__builtin_rotateleft8:
3767 case Builtin::BI__builtin_rotateleft16:
3768 case Builtin::BI__builtin_rotateleft32:
3769 case Builtin::BI__builtin_rotateleft64:
3770 case Builtin::BI_rotl8:
3771 case Builtin::BI_rotl16:
3772 case Builtin::BI_rotl:
3773 case Builtin::BI_lrotl:
3774 case Builtin::BI_rotl64:
3777 case Builtin::BI__builtin_rotateright8:
3778 case Builtin::BI__builtin_rotateright16:
3779 case Builtin::BI__builtin_rotateright32:
3780 case Builtin::BI__builtin_rotateright64:
3781 case Builtin::BI_rotr8:
3782 case Builtin::BI_rotr16:
3783 case Builtin::BI_rotr:
3784 case Builtin::BI_lrotr:
3785 case Builtin::BI_rotr64:
3788 case Builtin::BI__builtin_constant_p: {
3791 const Expr *Arg =
E->getArg(0);
3799 return RValue::get(ConstantInt::get(ResultType, 0));
3804 return RValue::get(ConstantInt::get(ResultType, 0));
3816 if (
Result->getType() != ResultType)
3820 case Builtin::BI__builtin_dynamic_object_size:
3821 case Builtin::BI__builtin_object_size: {
3828 bool IsDynamic = BuiltinID == Builtin::BI__builtin_dynamic_object_size;
3830 nullptr, IsDynamic));
3832 case Builtin::BI__builtin_counted_by_ref: {
3834 llvm::Value *
Result = llvm::ConstantPointerNull::get(
3839 if (
auto *UO = dyn_cast<UnaryOperator>(Arg);
3840 UO && UO->getOpcode() == UO_AddrOf) {
3843 if (
auto *ASE = dyn_cast<ArraySubscriptExpr>(Arg))
3847 if (
const MemberExpr *ME = dyn_cast_if_present<MemberExpr>(Arg)) {
3851 const auto *FAMDecl = cast<FieldDecl>(ME->getMemberDecl());
3855 llvm::report_fatal_error(
"Cannot find the counted_by 'count' field");
3861 case Builtin::BI__builtin_prefetch: {
3865 llvm::ConstantInt::get(
Int32Ty, 0);
3867 llvm::ConstantInt::get(
Int32Ty, 3);
3873 case Builtin::BI__builtin_readcyclecounter: {
3877 case Builtin::BI__builtin_readsteadycounter: {
3881 case Builtin::BI__builtin___clear_cache: {
3887 case Builtin::BI__builtin_trap:
3890 case Builtin::BI__builtin_verbose_trap: {
3891 llvm::DILocation *TrapLocation =
Builder.getCurrentDebugLocation();
3902 case Builtin::BI__debugbreak:
3905 case Builtin::BI__builtin_unreachable: {
3914 case Builtin::BI__builtin_powi:
3915 case Builtin::BI__builtin_powif:
3916 case Builtin::BI__builtin_powil: {
3920 if (
Builder.getIsFPConstrained()) {
3923 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*
this,
E);
3930 { Src0->getType(), Src1->getType() });
3933 case Builtin::BI__builtin_frexpl: {
3937 if (&
getTarget().getLongDoubleFormat() == &llvm::APFloat::PPCDoubleDouble())
3941 case Builtin::BI__builtin_frexp:
3942 case Builtin::BI__builtin_frexpf:
3943 case Builtin::BI__builtin_frexpf128:
3944 case Builtin::BI__builtin_frexpf16:
3946 case Builtin::BI__builtin_isgreater:
3947 case Builtin::BI__builtin_isgreaterequal:
3948 case Builtin::BI__builtin_isless:
3949 case Builtin::BI__builtin_islessequal:
3950 case Builtin::BI__builtin_islessgreater:
3951 case Builtin::BI__builtin_isunordered: {
3954 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*
this,
E);
3958 switch (BuiltinID) {
3959 default: llvm_unreachable(
"Unknown ordered comparison");
3960 case Builtin::BI__builtin_isgreater:
3961 LHS =
Builder.CreateFCmpOGT(LHS, RHS,
"cmp");
3963 case Builtin::BI__builtin_isgreaterequal:
3964 LHS =
Builder.CreateFCmpOGE(LHS, RHS,
"cmp");
3966 case Builtin::BI__builtin_isless:
3967 LHS =
Builder.CreateFCmpOLT(LHS, RHS,
"cmp");
3969 case Builtin::BI__builtin_islessequal:
3970 LHS =
Builder.CreateFCmpOLE(LHS, RHS,
"cmp");
3972 case Builtin::BI__builtin_islessgreater:
3973 LHS =
Builder.CreateFCmpONE(LHS, RHS,
"cmp");
3975 case Builtin::BI__builtin_isunordered:
3976 LHS =
Builder.CreateFCmpUNO(LHS, RHS,
"cmp");
3983 case Builtin::BI__builtin_isnan: {
3984 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*
this,
E);
3993 case Builtin::BI__builtin_issignaling: {
3994 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*
this,
E);
4001 case Builtin::BI__builtin_isinf: {
4002 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*
this,
E);
4011 case Builtin::BIfinite:
4012 case Builtin::BI__finite:
4013 case Builtin::BIfinitef:
4014 case Builtin::BI__finitef:
4015 case Builtin::BIfinitel:
4016 case Builtin::BI__finitel:
4017 case Builtin::BI__builtin_isfinite: {
4018 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*
this,
E);
4027 case Builtin::BI__builtin_isnormal: {
4028 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*
this,
E);
4035 case Builtin::BI__builtin_issubnormal: {
4036 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*
this,
E);
4039 Builder.CreateZExt(
Builder.createIsFPClass(
V, FPClassTest::fcSubnormal),
4043 case Builtin::BI__builtin_iszero: {
4044 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*
this,
E);
4051 case Builtin::BI__builtin_isfpclass: {
4056 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*
this,
E);
4062 case Builtin::BI__builtin_nondeterministic_value: {
4071 case Builtin::BI__builtin_elementwise_abs: {
4076 QT = VecTy->getElementType();
4080 Builder.getFalse(),
nullptr,
"elt.abs");
4082 Result = emitBuiltinWithOneOverloadedType<1>(
4083 *
this,
E, llvm::Intrinsic::fabs,
"elt.abs");
4087 case Builtin::BI__builtin_elementwise_acos:
4088 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
4089 *
this,
E, llvm::Intrinsic::acos,
"elt.acos"));
4090 case Builtin::BI__builtin_elementwise_asin:
4091 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
4092 *
this,
E, llvm::Intrinsic::asin,
"elt.asin"));
4093 case Builtin::BI__builtin_elementwise_atan:
4094 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
4095 *
this,
E, llvm::Intrinsic::atan,
"elt.atan"));
4096 case Builtin::BI__builtin_elementwise_atan2:
4097 return RValue::get(emitBuiltinWithOneOverloadedType<2>(
4098 *
this,
E, llvm::Intrinsic::atan2,
"elt.atan2"));
4099 case Builtin::BI__builtin_elementwise_ceil:
4100 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
4101 *
this,
E, llvm::Intrinsic::ceil,
"elt.ceil"));
4102 case Builtin::BI__builtin_elementwise_exp:
4103 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
4104 *
this,
E, llvm::Intrinsic::exp,
"elt.exp"));
4105 case Builtin::BI__builtin_elementwise_exp2:
4106 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
4107 *
this,
E, llvm::Intrinsic::exp2,
"elt.exp2"));
4108 case Builtin::BI__builtin_elementwise_log:
4109 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
4110 *
this,
E, llvm::Intrinsic::log,
"elt.log"));
4111 case Builtin::BI__builtin_elementwise_log2:
4112 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
4113 *
this,
E, llvm::Intrinsic::log2,
"elt.log2"));
4114 case Builtin::BI__builtin_elementwise_log10:
4115 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
4116 *
this,
E, llvm::Intrinsic::log10,
"elt.log10"));
4117 case Builtin::BI__builtin_elementwise_pow: {
4119 emitBuiltinWithOneOverloadedType<2>(*
this,
E, llvm::Intrinsic::pow));
4121 case Builtin::BI__builtin_elementwise_bitreverse:
4122 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
4123 *
this,
E, llvm::Intrinsic::bitreverse,
"elt.bitreverse"));
4124 case Builtin::BI__builtin_elementwise_cos:
4125 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
4126 *
this,
E, llvm::Intrinsic::cos,
"elt.cos"));
4127 case Builtin::BI__builtin_elementwise_cosh:
4128 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
4129 *
this,
E, llvm::Intrinsic::cosh,
"elt.cosh"));
4130 case Builtin::BI__builtin_elementwise_floor:
4131 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
4132 *
this,
E, llvm::Intrinsic::floor,
"elt.floor"));
4133 case Builtin::BI__builtin_elementwise_popcount:
4134 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
4135 *
this,
E, llvm::Intrinsic::ctpop,
"elt.ctpop"));
4136 case Builtin::BI__builtin_elementwise_roundeven:
4137 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
4138 *
this,
E, llvm::Intrinsic::roundeven,
"elt.roundeven"));
4139 case Builtin::BI__builtin_elementwise_round:
4140 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
4141 *
this,
E, llvm::Intrinsic::round,
"elt.round"));
4142 case Builtin::BI__builtin_elementwise_rint:
4143 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
4144 *
this,
E, llvm::Intrinsic::rint,
"elt.rint"));
4145 case Builtin::BI__builtin_elementwise_nearbyint:
4146 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
4147 *
this,
E, llvm::Intrinsic::nearbyint,
"elt.nearbyint"));
4148 case Builtin::BI__builtin_elementwise_sin:
4149 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
4150 *
this,
E, llvm::Intrinsic::sin,
"elt.sin"));
4151 case Builtin::BI__builtin_elementwise_sinh:
4152 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
4153 *
this,
E, llvm::Intrinsic::sinh,
"elt.sinh"));
4154 case Builtin::BI__builtin_elementwise_tan:
4155 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
4156 *
this,
E, llvm::Intrinsic::tan,
"elt.tan"));
4157 case Builtin::BI__builtin_elementwise_tanh:
4158 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
4159 *
this,
E, llvm::Intrinsic::tanh,
"elt.tanh"));
4160 case Builtin::BI__builtin_elementwise_trunc:
4161 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
4162 *
this,
E, llvm::Intrinsic::trunc,
"elt.trunc"));
4163 case Builtin::BI__builtin_elementwise_canonicalize:
4164 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
4165 *
this,
E, llvm::Intrinsic::canonicalize,
"elt.canonicalize"));
4166 case Builtin::BI__builtin_elementwise_copysign:
4167 return RValue::get(emitBuiltinWithOneOverloadedType<2>(
4168 *
this,
E, llvm::Intrinsic::copysign));
4169 case Builtin::BI__builtin_elementwise_fma:
4171 emitBuiltinWithOneOverloadedType<3>(*
this,
E, llvm::Intrinsic::fma));
4172 case Builtin::BI__builtin_elementwise_add_sat:
4173 case Builtin::BI__builtin_elementwise_sub_sat: {
4177 assert(Op0->
getType()->isIntOrIntVectorTy() &&
"integer type expected");
4180 Ty = VecTy->getElementType();
4183 if (BuiltinIDIfNoAsmLabel == Builtin::BI__builtin_elementwise_add_sat)
4184 Opc = IsSigned ? llvm::Intrinsic::sadd_sat : llvm::Intrinsic::uadd_sat;
4186 Opc = IsSigned ? llvm::Intrinsic::ssub_sat : llvm::Intrinsic::usub_sat;
4187 Result =
Builder.CreateBinaryIntrinsic(Opc, Op0, Op1,
nullptr,
"elt.sat");
4191 case Builtin::BI__builtin_elementwise_max: {
4195 if (Op0->
getType()->isIntOrIntVectorTy()) {
4198 Ty = VecTy->getElementType();
4200 ? llvm::Intrinsic::smax
4201 : llvm::Intrinsic::umax,
4202 Op0, Op1,
nullptr,
"elt.max");
4207 case Builtin::BI__builtin_elementwise_min: {
4211 if (Op0->
getType()->isIntOrIntVectorTy()) {
4214 Ty = VecTy->getElementType();
4216 ? llvm::Intrinsic::smin
4217 : llvm::Intrinsic::umin,
4218 Op0, Op1,
nullptr,
"elt.min");
4224 case Builtin::BI__builtin_elementwise_maximum: {
4228 Op1,
nullptr,
"elt.maximum");
4232 case Builtin::BI__builtin_elementwise_minimum: {
4236 Op1,
nullptr,
"elt.minimum");
4240 case Builtin::BI__builtin_reduce_max: {
4241 auto GetIntrinsicID = [
this](
QualType QT) {
4243 QT = VecTy->getElementType();
4248 return llvm::Intrinsic::vector_reduce_smax;
4250 return llvm::Intrinsic::vector_reduce_umax;
4252 return llvm::Intrinsic::vector_reduce_fmax;
4254 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
4255 *
this,
E, GetIntrinsicID(
E->getArg(0)->
getType()),
"rdx.min"));
4258 case Builtin::BI__builtin_reduce_min: {
4259 auto GetIntrinsicID = [
this](
QualType QT) {
4261 QT = VecTy->getElementType();
4266 return llvm::Intrinsic::vector_reduce_smin;
4268 return llvm::Intrinsic::vector_reduce_umin;
4270 return llvm::Intrinsic::vector_reduce_fmin;
4273 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
4274 *
this,
E, GetIntrinsicID(
E->getArg(0)->
getType()),
"rdx.min"));
4277 case Builtin::BI__builtin_reduce_add:
4278 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
4279 *
this,
E, llvm::Intrinsic::vector_reduce_add,
"rdx.add"));
4280 case Builtin::BI__builtin_reduce_mul:
4281 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
4282 *
this,
E, llvm::Intrinsic::vector_reduce_mul,
"rdx.mul"));
4283 case Builtin::BI__builtin_reduce_xor:
4284 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
4285 *
this,
E, llvm::Intrinsic::vector_reduce_xor,
"rdx.xor"));
4286 case Builtin::BI__builtin_reduce_or:
4287 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
4288 *
this,
E, llvm::Intrinsic::vector_reduce_or,
"rdx.or"));
4289 case Builtin::BI__builtin_reduce_and:
4290 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
4291 *
this,
E, llvm::Intrinsic::vector_reduce_and,
"rdx.and"));
4292 case Builtin::BI__builtin_reduce_maximum:
4293 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
4294 *
this,
E, llvm::Intrinsic::vector_reduce_fmaximum,
"rdx.maximum"));
4295 case Builtin::BI__builtin_reduce_minimum:
4296 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
4297 *
this,
E, llvm::Intrinsic::vector_reduce_fminimum,
"rdx.minimum"));
4299 case Builtin::BI__builtin_matrix_transpose: {
4303 Value *
Result = MB.CreateMatrixTranspose(MatValue, MatrixTy->getNumRows(),
4304 MatrixTy->getNumColumns());
4308 case Builtin::BI__builtin_matrix_column_major_load: {
4314 assert(PtrTy &&
"arg0 must be of pointer type");
4324 ResultTy->getNumRows(), ResultTy->getNumColumns(),
"matrix");
4328 case Builtin::BI__builtin_matrix_column_major_store: {
4336 assert(PtrTy &&
"arg1 must be of pointer type");
4345 MatrixTy->getNumRows(), MatrixTy->getNumColumns());
4349 case Builtin::BI__builtin_isinf_sign: {
4351 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*
this,
E);
4356 AbsArg, ConstantFP::getInfinity(Arg->
getType()),
"isinf");
4362 Value *NegativeOne = ConstantInt::get(
IntTy, -1);
4363 Value *SignResult =
Builder.CreateSelect(IsNeg, NegativeOne, One);
4368 case Builtin::BI__builtin_flt_rounds: {
4373 if (
Result->getType() != ResultType)
4379 case Builtin::BI__builtin_set_flt_rounds: {
4387 case Builtin::BI__builtin_fpclassify: {
4388 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*
this,
E);
4399 "fpclassify_result");
4403 Value *IsZero =
Builder.CreateFCmpOEQ(
V, Constant::getNullValue(Ty),
4407 Builder.CreateCondBr(IsZero, End, NotZero);
4411 Builder.SetInsertPoint(NotZero);
4415 Builder.CreateCondBr(IsNan, End, NotNan);
4416 Result->addIncoming(NanLiteral, NotZero);
4419 Builder.SetInsertPoint(NotNan);
4422 Builder.CreateFCmpOEQ(VAbs, ConstantFP::getInfinity(
V->getType()),
4426 Builder.CreateCondBr(IsInf, End, NotInf);
4427 Result->addIncoming(InfLiteral, NotNan);
4430 Builder.SetInsertPoint(NotInf);
4431 APFloat Smallest = APFloat::getSmallestNormalized(
4434 Builder.CreateFCmpUGE(VAbs, ConstantFP::get(
V->getContext(), Smallest),
4436 Value *NormalResult =
4440 Result->addIncoming(NormalResult, NotInf);
4453 case Builtin::BIalloca:
4454 case Builtin::BI_alloca:
4455 case Builtin::BI__builtin_alloca_uninitialized:
4456 case Builtin::BI__builtin_alloca: {
4460 const Align SuitableAlignmentInBytes =
4464 AllocaInst *AI =
Builder.CreateAlloca(
Builder.getInt8Ty(), Size);
4465 AI->setAlignment(SuitableAlignmentInBytes);
4466 if (BuiltinID != Builtin::BI__builtin_alloca_uninitialized)
4478 case Builtin::BI__builtin_alloca_with_align_uninitialized:
4479 case Builtin::BI__builtin_alloca_with_align: {
4482 auto *AlignmentInBitsCI = cast<ConstantInt>(AlignmentInBitsValue);
4483 unsigned AlignmentInBits = AlignmentInBitsCI->getZExtValue();
4484 const Align AlignmentInBytes =
4486 AllocaInst *AI =
Builder.CreateAlloca(
Builder.getInt8Ty(), Size);
4487 AI->setAlignment(AlignmentInBytes);
4488 if (BuiltinID != Builtin::BI__builtin_alloca_with_align_uninitialized)
4500 case Builtin::BIbzero:
4501 case Builtin::BI__builtin_bzero: {
4510 case Builtin::BIbcopy:
4511 case Builtin::BI__builtin_bcopy: {
4525 case Builtin::BImemcpy:
4526 case Builtin::BI__builtin_memcpy:
4527 case Builtin::BImempcpy:
4528 case Builtin::BI__builtin_mempcpy: {
4532 EmitArgCheck(
TCK_Store, Dest,
E->getArg(0), 0);
4533 EmitArgCheck(
TCK_Load, Src,
E->getArg(1), 1);
4535 if (BuiltinID == Builtin::BImempcpy ||
4536 BuiltinID == Builtin::BI__builtin_mempcpy)
4543 case Builtin::BI__builtin_memcpy_inline: {
4548 EmitArgCheck(
TCK_Store, Dest,
E->getArg(0), 0);
4549 EmitArgCheck(
TCK_Load, Src,
E->getArg(1), 1);
4554 case Builtin::BI__builtin_char_memchr:
4555 BuiltinID = Builtin::BI__builtin_memchr;
4558 case Builtin::BI__builtin___memcpy_chk: {
4565 llvm::APSInt DstSize = DstSizeResult.
Val.
getInt();
4566 if (
Size.ugt(DstSize))
4570 Value *SizeVal = llvm::ConstantInt::get(
Builder.getContext(), Size);
4575 case Builtin::BI__builtin_objc_memmove_collectable: {
4580 DestAddr, SrcAddr, SizeVal);
4584 case Builtin::BI__builtin___memmove_chk: {
4591 llvm::APSInt DstSize = DstSizeResult.
Val.
getInt();
4592 if (
Size.ugt(DstSize))
4596 Value *SizeVal = llvm::ConstantInt::get(
Builder.getContext(), Size);
4601 case Builtin::BImemmove:
4602 case Builtin::BI__builtin_memmove: {
4606 EmitArgCheck(
TCK_Store, Dest,
E->getArg(0), 0);
4607 EmitArgCheck(
TCK_Load, Src,
E->getArg(1), 1);
4611 case Builtin::BImemset:
4612 case Builtin::BI__builtin_memset: {
4622 case Builtin::BI__builtin_memset_inline: {
4634 case Builtin::BI__builtin___memset_chk: {
4641 llvm::APSInt DstSize = DstSizeResult.
Val.
getInt();
4642 if (
Size.ugt(DstSize))
4647 Value *SizeVal = llvm::ConstantInt::get(
Builder.getContext(), Size);
4651 case Builtin::BI__builtin_wmemchr: {
4654 if (!
getTarget().getTriple().isOSMSVCRT())
4662 BasicBlock *Entry =
Builder.GetInsertBlock();
4667 Builder.CreateCondBr(SizeEq0, Exit, CmpEq);
4671 StrPhi->addIncoming(Str, Entry);
4673 SizePhi->addIncoming(Size, Entry);
4677 Value *FoundChr =
Builder.CreateConstInBoundsGEP1_32(WCharTy, StrPhi, 0);
4679 Builder.CreateCondBr(StrEqChr, Exit, Next);
4682 Value *NextStr =
Builder.CreateConstInBoundsGEP1_32(WCharTy, StrPhi, 1);
4684 Value *NextSizeEq0 =
4685 Builder.CreateICmpEQ(NextSize, ConstantInt::get(
SizeTy, 0));
4686 Builder.CreateCondBr(NextSizeEq0, Exit, CmpEq);
4687 StrPhi->addIncoming(NextStr, Next);
4688 SizePhi->addIncoming(NextSize, Next);
4692 Ret->addIncoming(llvm::Constant::getNullValue(Str->
getType()), Entry);
4693 Ret->addIncoming(llvm::Constant::getNullValue(Str->
getType()), Next);
4694 Ret->addIncoming(FoundChr, CmpEq);
4697 case Builtin::BI__builtin_wmemcmp: {
4700 if (!
getTarget().getTriple().isOSMSVCRT())
4709 BasicBlock *Entry =
Builder.GetInsertBlock();
4715 Builder.CreateCondBr(SizeEq0, Exit, CmpGT);
4719 DstPhi->addIncoming(Dst, Entry);
4721 SrcPhi->addIncoming(Src, Entry);
4723 SizePhi->addIncoming(Size, Entry);
4729 Builder.CreateCondBr(DstGtSrc, Exit, CmpLT);
4733 Builder.CreateCondBr(DstLtSrc, Exit, Next);
4736 Value *NextDst =
Builder.CreateConstInBoundsGEP1_32(WCharTy, DstPhi, 1);
4737 Value *NextSrc =
Builder.CreateConstInBoundsGEP1_32(WCharTy, SrcPhi, 1);
4739 Value *NextSizeEq0 =
4740 Builder.CreateICmpEQ(NextSize, ConstantInt::get(
SizeTy, 0));
4741 Builder.CreateCondBr(NextSizeEq0, Exit, CmpGT);
4742 DstPhi->addIncoming(NextDst, Next);
4743 SrcPhi->addIncoming(NextSrc, Next);
4744 SizePhi->addIncoming(NextSize, Next);
4748 Ret->addIncoming(ConstantInt::get(
IntTy, 0), Entry);
4749 Ret->addIncoming(ConstantInt::get(
IntTy, 1), CmpGT);
4750 Ret->addIncoming(ConstantInt::get(
IntTy, -1), CmpLT);
4751 Ret->addIncoming(ConstantInt::get(
IntTy, 0), Next);
4754 case Builtin::BI__builtin_dwarf_cfa: {
4767 llvm::ConstantInt::get(
Int32Ty, Offset)));
4769 case Builtin::BI__builtin_return_address: {
4775 case Builtin::BI_ReturnAddress: {
4779 case Builtin::BI__builtin_frame_address: {
4785 case Builtin::BI__builtin_extract_return_addr: {
4790 case Builtin::BI__builtin_frob_return_addr: {
4795 case Builtin::BI__builtin_dwarf_sp_column: {
4796 llvm::IntegerType *Ty
4805 case Builtin::BI__builtin_init_dwarf_reg_size_table: {
4811 case Builtin::BI__builtin_eh_return: {
4815 llvm::IntegerType *
IntTy = cast<llvm::IntegerType>(
Int->getType());
4816 assert((
IntTy->getBitWidth() == 32 ||
IntTy->getBitWidth() == 64) &&
4817 "LLVM's __builtin_eh_return only supports 32- and 64-bit variants");
4820 : Intrinsic::eh_return_i64);
4829 case Builtin::BI__builtin_unwind_init: {
4834 case Builtin::BI__builtin_extend_pointer: {
4859 case Builtin::BI__builtin_setjmp: {
4863 if (
getTarget().getTriple().getArch() == llvm::Triple::systemz) {
4874 ConstantInt::get(
Int32Ty, 0));
4888 case Builtin::BI__builtin_longjmp: {
4902 case Builtin::BI__builtin_launder: {
4903 const Expr *Arg =
E->getArg(0);
4911 case Builtin::BI__sync_fetch_and_add:
4912 case Builtin::BI__sync_fetch_and_sub:
4913 case Builtin::BI__sync_fetch_and_or:
4914 case Builtin::BI__sync_fetch_and_and:
4915 case Builtin::BI__sync_fetch_and_xor:
4916 case Builtin::BI__sync_fetch_and_nand:
4917 case Builtin::BI__sync_add_and_fetch:
4918 case Builtin::BI__sync_sub_and_fetch:
4919 case Builtin::BI__sync_and_and_fetch:
4920 case Builtin::BI__sync_or_and_fetch:
4921 case Builtin::BI__sync_xor_and_fetch:
4922 case Builtin::BI__sync_nand_and_fetch:
4923 case Builtin::BI__sync_val_compare_and_swap:
4924 case Builtin::BI__sync_bool_compare_and_swap:
4925 case Builtin::BI__sync_lock_test_and_set:
4926 case Builtin::BI__sync_lock_release:
4927 case Builtin::BI__sync_swap:
4928 llvm_unreachable(
"Shouldn't make it through sema");
4929 case Builtin::BI__sync_fetch_and_add_1:
4930 case Builtin::BI__sync_fetch_and_add_2:
4931 case Builtin::BI__sync_fetch_and_add_4:
4932 case Builtin::BI__sync_fetch_and_add_8:
4933 case Builtin::BI__sync_fetch_and_add_16:
4935 case Builtin::BI__sync_fetch_and_sub_1:
4936 case Builtin::BI__sync_fetch_and_sub_2:
4937 case Builtin::BI__sync_fetch_and_sub_4:
4938 case Builtin::BI__sync_fetch_and_sub_8:
4939 case Builtin::BI__sync_fetch_and_sub_16:
4941 case Builtin::BI__sync_fetch_and_or_1:
4942 case Builtin::BI__sync_fetch_and_or_2:
4943 case Builtin::BI__sync_fetch_and_or_4:
4944 case Builtin::BI__sync_fetch_and_or_8:
4945 case Builtin::BI__sync_fetch_and_or_16:
4947 case Builtin::BI__sync_fetch_and_and_1:
4948 case Builtin::BI__sync_fetch_and_and_2:
4949 case Builtin::BI__sync_fetch_and_and_4:
4950 case Builtin::BI__sync_fetch_and_and_8:
4951 case Builtin::BI__sync_fetch_and_and_16:
4953 case Builtin::BI__sync_fetch_and_xor_1:
4954 case Builtin::BI__sync_fetch_and_xor_2:
4955 case Builtin::BI__sync_fetch_and_xor_4:
4956 case Builtin::BI__sync_fetch_and_xor_8:
4957 case Builtin::BI__sync_fetch_and_xor_16:
4959 case Builtin::BI__sync_fetch_and_nand_1:
4960 case Builtin::BI__sync_fetch_and_nand_2:
4961 case Builtin::BI__sync_fetch_and_nand_4:
4962 case Builtin::BI__sync_fetch_and_nand_8:
4963 case Builtin::BI__sync_fetch_and_nand_16:
4967 case Builtin::BI__sync_fetch_and_min:
4969 case Builtin::BI__sync_fetch_and_max:
4971 case Builtin::BI__sync_fetch_and_umin:
4973 case Builtin::BI__sync_fetch_and_umax:
4976 case Builtin::BI__sync_add_and_fetch_1:
4977 case Builtin::BI__sync_add_and_fetch_2:
4978 case Builtin::BI__sync_add_and_fetch_4:
4979 case Builtin::BI__sync_add_and_fetch_8:
4980 case Builtin::BI__sync_add_and_fetch_16:
4982 llvm::Instruction::Add);
4983 case Builtin::BI__sync_sub_and_fetch_1:
4984 case Builtin::BI__sync_sub_and_fetch_2:
4985 case Builtin::BI__sync_sub_and_fetch_4:
4986 case Builtin::BI__sync_sub_and_fetch_8:
4987 case Builtin::BI__sync_sub_and_fetch_16:
4989 llvm::Instruction::Sub);
4990 case Builtin::BI__sync_and_and_fetch_1:
4991 case Builtin::BI__sync_and_and_fetch_2:
4992 case Builtin::BI__sync_and_and_fetch_4:
4993 case Builtin::BI__sync_and_and_fetch_8:
4994 case Builtin::BI__sync_and_and_fetch_16:
4996 llvm::Instruction::And);
4997 case Builtin::BI__sync_or_and_fetch_1:
4998 case Builtin::BI__sync_or_and_fetch_2:
4999 case Builtin::BI__sync_or_and_fetch_4:
5000 case Builtin::BI__sync_or_and_fetch_8:
5001 case Builtin::BI__sync_or_and_fetch_16:
5003 llvm::Instruction::Or);
5004 case Builtin::BI__sync_xor_and_fetch_1:
5005 case Builtin::BI__sync_xor_and_fetch_2:
5006 case Builtin::BI__sync_xor_and_fetch_4:
5007 case Builtin::BI__sync_xor_and_fetch_8:
5008 case Builtin::BI__sync_xor_and_fetch_16:
5010 llvm::Instruction::Xor);
5011 case Builtin::BI__sync_nand_and_fetch_1:
5012 case Builtin::BI__sync_nand_and_fetch_2:
5013 case Builtin::BI__sync_nand_and_fetch_4:
5014 case Builtin::BI__sync_nand_and_fetch_8:
5015 case Builtin::BI__sync_nand_and_fetch_16:
5017 llvm::Instruction::And,
true);
5019 case Builtin::BI__sync_val_compare_and_swap_1:
5020 case Builtin::BI__sync_val_compare_and_swap_2:
5021 case Builtin::BI__sync_val_compare_and_swap_4:
5022 case Builtin::BI__sync_val_compare_and_swap_8:
5023 case Builtin::BI__sync_val_compare_and_swap_16:
5026 case Builtin::BI__sync_bool_compare_and_swap_1:
5027 case Builtin::BI__sync_bool_compare_and_swap_2:
5028 case Builtin::BI__sync_bool_compare_and_swap_4:
5029 case Builtin::BI__sync_bool_compare_and_swap_8:
5030 case Builtin::BI__sync_bool_compare_and_swap_16:
5033 case Builtin::BI__sync_swap_1:
5034 case Builtin::BI__sync_swap_2:
5035 case Builtin::BI__sync_swap_4:
5036 case Builtin::BI__sync_swap_8:
5037 case Builtin::BI__sync_swap_16:
5040 case Builtin::BI__sync_lock_test_and_set_1:
5041 case Builtin::BI__sync_lock_test_and_set_2:
5042 case Builtin::BI__sync_lock_test_and_set_4:
5043 case Builtin::BI__sync_lock_test_and_set_8:
5044 case Builtin::BI__sync_lock_test_and_set_16:
5047 case Builtin::BI__sync_lock_release_1:
5048 case Builtin::BI__sync_lock_release_2:
5049 case Builtin::BI__sync_lock_release_4:
5050 case Builtin::BI__sync_lock_release_8:
5051 case Builtin::BI__sync_lock_release_16: {
5057 llvm::StoreInst *
Store =
5059 Store->setAtomic(llvm::AtomicOrdering::Release);
5063 case Builtin::BI__sync_synchronize: {
5071 Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent);
5075 case Builtin::BI__builtin_nontemporal_load:
5077 case Builtin::BI__builtin_nontemporal_store:
5079 case Builtin::BI__c11_atomic_is_lock_free:
5080 case Builtin::BI__atomic_is_lock_free: {
5084 const char *LibCallName =
"__atomic_is_lock_free";
5088 if (BuiltinID == Builtin::BI__atomic_is_lock_free)
5102 case Builtin::BI__atomic_test_and_set: {
5114 if (isa<llvm::ConstantInt>(Order)) {
5115 int ord = cast<llvm::ConstantInt>(Order)->getZExtValue();
5116 AtomicRMWInst *
Result =
nullptr;
5121 llvm::AtomicOrdering::Monotonic);
5126 llvm::AtomicOrdering::Acquire);
5130 llvm::AtomicOrdering::Release);
5135 llvm::AtomicOrdering::AcquireRelease);
5139 llvm::AtomicRMWInst::Xchg, Ptr, NewVal,
5140 llvm::AtomicOrdering::SequentiallyConsistent);
5143 Result->setVolatile(Volatile);
5149 llvm::BasicBlock *BBs[5] = {
5156 llvm::AtomicOrdering Orders[5] = {
5157 llvm::AtomicOrdering::Monotonic, llvm::AtomicOrdering::Acquire,
5158 llvm::AtomicOrdering::Release, llvm::AtomicOrdering::AcquireRelease,
5159 llvm::AtomicOrdering::SequentiallyConsistent};
5161 Order =
Builder.CreateIntCast(Order,
Builder.getInt32Ty(),
false);
5162 llvm::SwitchInst *SI =
Builder.CreateSwitch(Order, BBs[0]);
5164 Builder.SetInsertPoint(ContBB);
5167 for (
unsigned i = 0; i < 5; ++i) {
5168 Builder.SetInsertPoint(BBs[i]);
5170 Ptr, NewVal, Orders[i]);
5171 RMW->setVolatile(Volatile);
5172 Result->addIncoming(RMW, BBs[i]);
5176 SI->addCase(
Builder.getInt32(0), BBs[0]);
5177 SI->addCase(
Builder.getInt32(1), BBs[1]);
5178 SI->addCase(
Builder.getInt32(2), BBs[1]);
5179 SI->addCase(
Builder.getInt32(3), BBs[2]);
5180 SI->addCase(
Builder.getInt32(4), BBs[3]);
5181 SI->addCase(
Builder.getInt32(5), BBs[4]);
5183 Builder.SetInsertPoint(ContBB);
5187 case Builtin::BI__atomic_clear: {
5196 if (isa<llvm::ConstantInt>(Order)) {
5197 int ord = cast<llvm::ConstantInt>(Order)->getZExtValue();
5202 Store->setOrdering(llvm::AtomicOrdering::Monotonic);
5205 Store->setOrdering(llvm::AtomicOrdering::Release);
5208 Store->setOrdering(llvm::AtomicOrdering::SequentiallyConsistent);
5216 llvm::BasicBlock *BBs[3] = {
5221 llvm::AtomicOrdering Orders[3] = {
5222 llvm::AtomicOrdering::Monotonic, llvm::AtomicOrdering::Release,
5223 llvm::AtomicOrdering::SequentiallyConsistent};
5225 Order =
Builder.CreateIntCast(Order,
Builder.getInt32Ty(),
false);
5226 llvm::SwitchInst *SI =
Builder.CreateSwitch(Order, BBs[0]);
5228 for (
unsigned i = 0; i < 3; ++i) {
5229 Builder.SetInsertPoint(BBs[i]);
5231 Store->setOrdering(Orders[i]);
5235 SI->addCase(
Builder.getInt32(0), BBs[0]);
5236 SI->addCase(
Builder.getInt32(3), BBs[1]);
5237 SI->addCase(
Builder.getInt32(5), BBs[2]);
5239 Builder.SetInsertPoint(ContBB);
5243 case Builtin::BI__atomic_thread_fence:
5244 case Builtin::BI__atomic_signal_fence:
5245 case Builtin::BI__c11_atomic_thread_fence:
5246 case Builtin::BI__c11_atomic_signal_fence: {
5247 llvm::SyncScope::ID SSID;
5248 if (BuiltinID == Builtin::BI__atomic_signal_fence ||
5249 BuiltinID == Builtin::BI__c11_atomic_signal_fence)
5250 SSID = llvm::SyncScope::SingleThread;
5252 SSID = llvm::SyncScope::System;
5254 if (isa<llvm::ConstantInt>(Order)) {
5255 int ord = cast<llvm::ConstantInt>(Order)->getZExtValue();
5262 Builder.CreateFence(llvm::AtomicOrdering::Acquire, SSID);
5265 Builder.CreateFence(llvm::AtomicOrdering::Release, SSID);
5268 Builder.CreateFence(llvm::AtomicOrdering::AcquireRelease, SSID);
5271 Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent, SSID);
5277 llvm::BasicBlock *AcquireBB, *ReleaseBB, *AcqRelBB, *SeqCstBB;
5284 Order =
Builder.CreateIntCast(Order,
Builder.getInt32Ty(),
false);
5285 llvm::SwitchInst *SI =
Builder.CreateSwitch(Order, ContBB);
5287 Builder.SetInsertPoint(AcquireBB);
5288 Builder.CreateFence(llvm::AtomicOrdering::Acquire, SSID);
5290 SI->addCase(
Builder.getInt32(1), AcquireBB);
5291 SI->addCase(
Builder.getInt32(2), AcquireBB);
5293 Builder.SetInsertPoint(ReleaseBB);
5294 Builder.CreateFence(llvm::AtomicOrdering::Release, SSID);
5296 SI->addCase(
Builder.getInt32(3), ReleaseBB);
5298 Builder.SetInsertPoint(AcqRelBB);
5299 Builder.CreateFence(llvm::AtomicOrdering::AcquireRelease, SSID);
5301 SI->addCase(
Builder.getInt32(4), AcqRelBB);
5303 Builder.SetInsertPoint(SeqCstBB);
5304 Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent, SSID);
5306 SI->addCase(
Builder.getInt32(5), SeqCstBB);
5308 Builder.SetInsertPoint(ContBB);
5311 case Builtin::BI__scoped_atomic_thread_fence: {
5316 auto Ord = dyn_cast<llvm::ConstantInt>(Order);
5317 auto Scp = dyn_cast<llvm::ConstantInt>(
Scope);
5319 SyncScope SS = ScopeModel->isValid(Scp->getZExtValue())
5320 ? ScopeModel->map(Scp->getZExtValue())
5321 : ScopeModel->map(ScopeModel->getFallBackValue());
5322 switch (Ord->getZExtValue()) {
5329 llvm::AtomicOrdering::Acquire,
5331 llvm::AtomicOrdering::Acquire,
5336 llvm::AtomicOrdering::Release,
5338 llvm::AtomicOrdering::Release,
5342 Builder.CreateFence(llvm::AtomicOrdering::AcquireRelease,
5345 llvm::AtomicOrdering::AcquireRelease,
5349 Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent,
5352 llvm::AtomicOrdering::SequentiallyConsistent,
5364 switch (Ord->getZExtValue()) {
5367 ContBB->eraseFromParent();
5371 OrderBBs.emplace_back(
Builder.GetInsertBlock(),
5372 llvm::AtomicOrdering::Acquire);
5375 OrderBBs.emplace_back(
Builder.GetInsertBlock(),
5376 llvm::AtomicOrdering::Release);
5379 OrderBBs.emplace_back(
Builder.GetInsertBlock(),
5380 llvm::AtomicOrdering::AcquireRelease);
5383 OrderBBs.emplace_back(
Builder.GetInsertBlock(),
5384 llvm::AtomicOrdering::SequentiallyConsistent);
5393 Order =
Builder.CreateIntCast(Order,
Builder.getInt32Ty(),
false);
5394 llvm::SwitchInst *SI =
Builder.CreateSwitch(Order, ContBB);
5395 SI->addCase(
Builder.getInt32(1), AcquireBB);
5396 SI->addCase(
Builder.getInt32(2), AcquireBB);
5397 SI->addCase(
Builder.getInt32(3), ReleaseBB);
5398 SI->addCase(
Builder.getInt32(4), AcqRelBB);
5399 SI->addCase(
Builder.getInt32(5), SeqCstBB);
5401 OrderBBs.emplace_back(AcquireBB, llvm::AtomicOrdering::Acquire);
5402 OrderBBs.emplace_back(ReleaseBB, llvm::AtomicOrdering::Release);
5403 OrderBBs.emplace_back(AcqRelBB, llvm::AtomicOrdering::AcquireRelease);
5404 OrderBBs.emplace_back(SeqCstBB,
5405 llvm::AtomicOrdering::SequentiallyConsistent);
5408 for (
auto &[OrderBB, Ordering] : OrderBBs) {
5409 Builder.SetInsertPoint(OrderBB);
5411 SyncScope SS = ScopeModel->isValid(Scp->getZExtValue())
5412 ? ScopeModel->map(Scp->getZExtValue())
5413 : ScopeModel->map(ScopeModel->getFallBackValue());
5419 llvm::DenseMap<unsigned, llvm::BasicBlock *> BBs;
5420 for (
unsigned Scp : ScopeModel->getRuntimeValues())
5424 llvm::SwitchInst *SI =
Builder.CreateSwitch(SC, ContBB);
5425 for (
unsigned Scp : ScopeModel->getRuntimeValues()) {
5427 SI->addCase(
Builder.getInt32(Scp), B);
5438 Builder.SetInsertPoint(ContBB);
5442 case Builtin::BI__builtin_signbit:
5443 case Builtin::BI__builtin_signbitf:
5444 case Builtin::BI__builtin_signbitl: {
5449 case Builtin::BI__warn_memset_zero_len:
5451 case Builtin::BI__annotation: {
5454 for (
const Expr *Arg :
E->arguments()) {
5456 assert(Str->getCharByteWidth() == 2);
5457 StringRef WideBytes = Str->getBytes();
5458 std::string StrUtf8;
5459 if (!convertUTF16ToUTF8String(
5460 ArrayRef(WideBytes.data(), WideBytes.size()), StrUtf8)) {
5464 Strings.push_back(llvm::MDString::get(
getLLVMContext(), StrUtf8));
5474 case Builtin::BI__builtin_annotation: {
5483 StringRef Str = cast<StringLiteral>(AnnotationStrExpr)->getString();
5487 case Builtin::BI__builtin_addcb:
5488 case Builtin::BI__builtin_addcs:
5489 case Builtin::BI__builtin_addc:
5490 case Builtin::BI__builtin_addcl:
5491 case Builtin::BI__builtin_addcll:
5492 case Builtin::BI__builtin_subcb:
5493 case Builtin::BI__builtin_subcs:
5494 case Builtin::BI__builtin_subc:
5495 case Builtin::BI__builtin_subcl:
5496 case Builtin::BI__builtin_subcll: {
5522 llvm::Intrinsic::ID IntrinsicId;
5523 switch (BuiltinID) {
5524 default: llvm_unreachable(
"Unknown multiprecision builtin id.");
5525 case Builtin::BI__builtin_addcb:
5526 case Builtin::BI__builtin_addcs:
5527 case Builtin::BI__builtin_addc:
5528 case Builtin::BI__builtin_addcl:
5529 case Builtin::BI__builtin_addcll:
5530 IntrinsicId = llvm::Intrinsic::uadd_with_overflow;
5532 case Builtin::BI__builtin_subcb:
5533 case Builtin::BI__builtin_subcs:
5534 case Builtin::BI__builtin_subc:
5535 case Builtin::BI__builtin_subcl:
5536 case Builtin::BI__builtin_subcll:
5537 IntrinsicId = llvm::Intrinsic::usub_with_overflow;
5542 llvm::Value *Carry1;
5545 llvm::Value *Carry2;
5547 Sum1, Carryin, Carry2);
5548 llvm::Value *CarryOut =
Builder.CreateZExt(
Builder.CreateOr(Carry1, Carry2),
5554 case Builtin::BI__builtin_add_overflow:
5555 case Builtin::BI__builtin_sub_overflow:
5556 case Builtin::BI__builtin_mul_overflow: {
5564 WidthAndSignedness LeftInfo =
5566 WidthAndSignedness RightInfo =
5568 WidthAndSignedness ResultInfo =
5575 RightInfo, ResultArg, ResultQTy,
5581 *
this, LeftArg, LeftInfo, RightArg, RightInfo, ResultArg, ResultQTy,
5584 WidthAndSignedness EncompassingInfo =
5587 llvm::Type *EncompassingLLVMTy =
5592 llvm::Intrinsic::ID IntrinsicId;
5593 switch (BuiltinID) {
5595 llvm_unreachable(
"Unknown overflow builtin id.");
5596 case Builtin::BI__builtin_add_overflow:
5597 IntrinsicId = EncompassingInfo.Signed
5598 ? llvm::Intrinsic::sadd_with_overflow
5599 : llvm::Intrinsic::uadd_with_overflow;
5601 case Builtin::BI__builtin_sub_overflow:
5602 IntrinsicId = EncompassingInfo.Signed
5603 ? llvm::Intrinsic::ssub_with_overflow
5604 : llvm::Intrinsic::usub_with_overflow;
5606 case Builtin::BI__builtin_mul_overflow:
5607 IntrinsicId = EncompassingInfo.Signed
5608 ? llvm::Intrinsic::smul_with_overflow
5609 : llvm::Intrinsic::umul_with_overflow;
5618 Left =
Builder.CreateIntCast(Left, EncompassingLLVMTy, LeftInfo.Signed);
5619 Right =
Builder.CreateIntCast(Right, EncompassingLLVMTy, RightInfo.Signed);
5622 llvm::Value *Overflow, *
Result;
5625 if (EncompassingInfo.Width > ResultInfo.Width) {
5628 llvm::Value *ResultTrunc =
Builder.CreateTrunc(
Result, ResultLLVMTy);
5632 llvm::Value *ResultTruncExt =
Builder.CreateIntCast(
5633 ResultTrunc, EncompassingLLVMTy, ResultInfo.Signed);
5634 llvm::Value *TruncationOverflow =
5637 Overflow =
Builder.CreateOr(Overflow, TruncationOverflow);
5649 case Builtin::BI__builtin_uadd_overflow:
5650 case Builtin::BI__builtin_uaddl_overflow:
5651 case Builtin::BI__builtin_uaddll_overflow:
5652 case Builtin::BI__builtin_usub_overflow:
5653 case Builtin::BI__builtin_usubl_overflow:
5654 case Builtin::BI__builtin_usubll_overflow:
5655 case Builtin::BI__builtin_umul_overflow:
5656 case Builtin::BI__builtin_umull_overflow:
5657 case Builtin::BI__builtin_umulll_overflow:
5658 case Builtin::BI__builtin_sadd_overflow:
5659 case Builtin::BI__builtin_saddl_overflow:
5660 case Builtin::BI__builtin_saddll_overflow:
5661 case Builtin::BI__builtin_ssub_overflow:
5662 case Builtin::BI__builtin_ssubl_overflow:
5663 case Builtin::BI__builtin_ssubll_overflow:
5664 case Builtin::BI__builtin_smul_overflow:
5665 case Builtin::BI__builtin_smull_overflow:
5666 case Builtin::BI__builtin_smulll_overflow: {
5676 llvm::Intrinsic::ID IntrinsicId;
5677 switch (BuiltinID) {
5678 default: llvm_unreachable(
"Unknown overflow builtin id.");
5679 case Builtin::BI__builtin_uadd_overflow:
5680 case Builtin::BI__builtin_uaddl_overflow:
5681 case Builtin::BI__builtin_uaddll_overflow:
5682 IntrinsicId = llvm::Intrinsic::uadd_with_overflow;
5684 case Builtin::BI__builtin_usub_overflow:
5685 case Builtin::BI__builtin_usubl_overflow:
5686 case Builtin::BI__builtin_usubll_overflow:
5687 IntrinsicId = llvm::Intrinsic::usub_with_overflow;
5689 case Builtin::BI__builtin_umul_overflow:
5690 case Builtin::BI__builtin_umull_overflow:
5691 case Builtin::BI__builtin_umulll_overflow:
5692 IntrinsicId = llvm::Intrinsic::umul_with_overflow;
5694 case Builtin::BI__builtin_sadd_overflow:
5695 case Builtin::BI__builtin_saddl_overflow:
5696 case Builtin::BI__builtin_saddll_overflow:
5697 IntrinsicId = llvm::Intrinsic::sadd_with_overflow;
5699 case Builtin::BI__builtin_ssub_overflow:
5700 case Builtin::BI__builtin_ssubl_overflow:
5701 case Builtin::BI__builtin_ssubll_overflow:
5702 IntrinsicId = llvm::Intrinsic::ssub_with_overflow;
5704 case Builtin::BI__builtin_smul_overflow:
5705 case Builtin::BI__builtin_smull_overflow:
5706 case Builtin::BI__builtin_smulll_overflow:
5707 IntrinsicId = llvm::Intrinsic::smul_with_overflow;
5718 case Builtin::BIaddressof:
5719 case Builtin::BI__addressof:
5720 case Builtin::BI__builtin_addressof:
5722 case Builtin::BI__builtin_function_start:
5725 case Builtin::BI__builtin_operator_new:
5728 case Builtin::BI__builtin_operator_delete:
5733 case Builtin::BI__builtin_is_aligned:
5735 case Builtin::BI__builtin_align_up:
5737 case Builtin::BI__builtin_align_down:
5740 case Builtin::BI__noop:
5743 case Builtin::BI__builtin_call_with_static_chain: {
5745 const Expr *Chain =
E->getArg(1);
5750 case Builtin::BI_InterlockedExchange8:
5751 case Builtin::BI_InterlockedExchange16:
5752 case Builtin::BI_InterlockedExchange:
5753 case Builtin::BI_InterlockedExchangePointer:
5756 case Builtin::BI_InterlockedCompareExchangePointer:
5759 case Builtin::BI_InterlockedCompareExchangePointer_nf:
5762 case Builtin::BI_InterlockedCompareExchange8:
5763 case Builtin::BI_InterlockedCompareExchange16:
5764 case Builtin::BI_InterlockedCompareExchange:
5765 case Builtin::BI_InterlockedCompareExchange64:
5767 case Builtin::BI_InterlockedIncrement16:
5768 case Builtin::BI_InterlockedIncrement:
5771 case Builtin::BI_InterlockedDecrement16:
5772 case Builtin::BI_InterlockedDecrement:
5775 case Builtin::BI_InterlockedAnd8:
5776 case Builtin::BI_InterlockedAnd16:
5777 case Builtin::BI_InterlockedAnd:
5779 case Builtin::BI_InterlockedExchangeAdd8:
5780 case Builtin::BI_InterlockedExchangeAdd16:
5781 case Builtin::BI_InterlockedExchangeAdd:
5784 case Builtin::BI_InterlockedExchangeSub8:
5785 case Builtin::BI_InterlockedExchangeSub16:
5786 case Builtin::BI_InterlockedExchangeSub:
5789 case Builtin::BI_InterlockedOr8:
5790 case Builtin::BI_InterlockedOr16:
5791 case Builtin::BI_InterlockedOr:
5793 case Builtin::BI_InterlockedXor8:
5794 case Builtin::BI_InterlockedXor16:
5795 case Builtin::BI_InterlockedXor:
5798 case Builtin::BI_bittest64:
5799 case Builtin::BI_bittest:
5800 case Builtin::BI_bittestandcomplement64:
5801 case Builtin::BI_bittestandcomplement:
5802 case Builtin::BI_bittestandreset64:
5803 case Builtin::BI_bittestandreset:
5804 case Builtin::BI_bittestandset64:
5805 case Builtin::BI_bittestandset:
5806 case Builtin::BI_interlockedbittestandreset:
5807 case Builtin::BI_interlockedbittestandreset64:
5808 case Builtin::BI_interlockedbittestandset64:
5809 case Builtin::BI_interlockedbittestandset:
5810 case Builtin::BI_interlockedbittestandset_acq:
5811 case Builtin::BI_interlockedbittestandset_rel:
5812 case Builtin::BI_interlockedbittestandset_nf:
5813 case Builtin::BI_interlockedbittestandreset_acq:
5814 case Builtin::BI_interlockedbittestandreset_rel:
5815 case Builtin::BI_interlockedbittestandreset_nf:
5820 case Builtin::BI__iso_volatile_load8:
5821 case Builtin::BI__iso_volatile_load16:
5822 case Builtin::BI__iso_volatile_load32:
5823 case Builtin::BI__iso_volatile_load64:
5825 case Builtin::BI__iso_volatile_store8:
5826 case Builtin::BI__iso_volatile_store16:
5827 case Builtin::BI__iso_volatile_store32:
5828 case Builtin::BI__iso_volatile_store64:
5831 case Builtin::BI__builtin_ptrauth_sign_constant:
5834 case Builtin::BI__builtin_ptrauth_auth:
5835 case Builtin::BI__builtin_ptrauth_auth_and_resign:
5836 case Builtin::BI__builtin_ptrauth_blend_discriminator:
5837 case Builtin::BI__builtin_ptrauth_sign_generic_data:
5838 case Builtin::BI__builtin_ptrauth_sign_unauthenticated:
5839 case Builtin::BI__builtin_ptrauth_strip: {
5842 for (
auto argExpr :
E->arguments())
5846 llvm::Type *OrigValueType = Args[0]->getType();
5847 if (OrigValueType->isPointerTy())
5850 switch (BuiltinID) {
5851 case Builtin::BI__builtin_ptrauth_auth_and_resign:
5852 if (Args[4]->getType()->isPointerTy())
5856 case Builtin::BI__builtin_ptrauth_auth:
5857 case Builtin::BI__builtin_ptrauth_sign_unauthenticated:
5858 if (Args[2]->getType()->isPointerTy())
5862 case Builtin::BI__builtin_ptrauth_sign_generic_data:
5863 if (Args[1]->getType()->isPointerTy())
5867 case Builtin::BI__builtin_ptrauth_blend_discriminator:
5868 case Builtin::BI__builtin_ptrauth_strip:
5873 auto IntrinsicID = [&]() ->
unsigned {
5874 switch (BuiltinID) {
5875 case Builtin::BI__builtin_ptrauth_auth:
5876 return llvm::Intrinsic::ptrauth_auth;
5877 case Builtin::BI__builtin_ptrauth_auth_and_resign:
5878 return llvm::Intrinsic::ptrauth_resign;
5879 case Builtin::BI__builtin_ptrauth_blend_discriminator:
5880 return llvm::Intrinsic::ptrauth_blend;
5881 case Builtin::BI__builtin_ptrauth_sign_generic_data:
5882 return llvm::Intrinsic::ptrauth_sign_generic;
5883 case Builtin::BI__builtin_ptrauth_sign_unauthenticated:
5884 return llvm::Intrinsic::ptrauth_sign;
5885 case Builtin::BI__builtin_ptrauth_strip:
5886 return llvm::Intrinsic::ptrauth_strip;
5888 llvm_unreachable(
"bad ptrauth intrinsic");
5893 if (BuiltinID != Builtin::BI__builtin_ptrauth_sign_generic_data &&
5894 BuiltinID != Builtin::BI__builtin_ptrauth_blend_discriminator &&
5895 OrigValueType->isPointerTy()) {
5901 case Builtin::BI__exception_code:
5902 case Builtin::BI_exception_code:
5904 case Builtin::BI__exception_info:
5905 case Builtin::BI_exception_info:
5907 case Builtin::BI__abnormal_termination:
5908 case Builtin::BI_abnormal_termination:
5910 case Builtin::BI_setjmpex:
5911 if (
getTarget().getTriple().isOSMSVCRT() &&
E->getNumArgs() == 1 &&
5915 case Builtin::BI_setjmp:
5916 if (
getTarget().getTriple().isOSMSVCRT() &&
E->getNumArgs() == 1 &&
5918 if (
getTarget().getTriple().getArch() == llvm::Triple::x86)
5920 else if (
getTarget().getTriple().getArch() == llvm::Triple::aarch64)
5927 case Builtin::BImove:
5928 case Builtin::BImove_if_noexcept:
5929 case Builtin::BIforward:
5930 case Builtin::BIforward_like:
5931 case Builtin::BIas_const:
5933 case Builtin::BI__GetExceptionInfo: {
5934 if (llvm::GlobalVariable *GV =
5940 case Builtin::BI__fastfail:
5943 case Builtin::BI__builtin_coro_id:
5945 case Builtin::BI__builtin_coro_promise:
5947 case Builtin::BI__builtin_coro_resume:
5950 case Builtin::BI__builtin_coro_frame:
5952 case Builtin::BI__builtin_coro_noop:
5954 case Builtin::BI__builtin_coro_free:
5956 case Builtin::BI__builtin_coro_destroy:
5959 case Builtin::BI__builtin_coro_done:
5961 case Builtin::BI__builtin_coro_alloc:
5963 case Builtin::BI__builtin_coro_begin:
5965 case Builtin::BI__builtin_coro_end:
5967 case Builtin::BI__builtin_coro_suspend:
5969 case Builtin::BI__builtin_coro_size:
5971 case Builtin::BI__builtin_coro_align:
5975 case Builtin::BIread_pipe:
5976 case Builtin::BIwrite_pipe: {
5980 Value *PacketSize = OpenCLRT.getPipeElemSize(
E->getArg(0));
5981 Value *PacketAlign = OpenCLRT.getPipeElemAlign(
E->getArg(0));
5984 unsigned GenericAS =
5986 llvm::Type *I8PTy = llvm::PointerType::get(
getLLVMContext(), GenericAS);
5989 if (2U ==
E->getNumArgs()) {
5990 const char *Name = (BuiltinID == Builtin::BIread_pipe) ?
"__read_pipe_2"
5995 llvm::FunctionType *FTy = llvm::FunctionType::get(
6000 {Arg0, ACast, PacketSize, PacketAlign}));
6002 assert(4 ==
E->getNumArgs() &&
6003 "Illegal number of parameters to pipe function");
6004 const char *Name = (BuiltinID == Builtin::BIread_pipe) ?
"__read_pipe_4"
6011 llvm::FunctionType *FTy = llvm::FunctionType::get(
6020 {Arg0, Arg1, Arg2, ACast, PacketSize, PacketAlign}));
6025 case Builtin::BIreserve_read_pipe:
6026 case Builtin::BIreserve_write_pipe:
6027 case Builtin::BIwork_group_reserve_read_pipe:
6028 case Builtin::BIwork_group_reserve_write_pipe:
6029 case Builtin::BIsub_group_reserve_read_pipe:
6030 case Builtin::BIsub_group_reserve_write_pipe: {
6033 if (BuiltinID == Builtin::BIreserve_read_pipe)
6034 Name =
"__reserve_read_pipe";
6035 else if (BuiltinID == Builtin::BIreserve_write_pipe)
6036 Name =
"__reserve_write_pipe";
6037 else if (BuiltinID == Builtin::BIwork_group_reserve_read_pipe)
6038 Name =
"__work_group_reserve_read_pipe";
6039 else if (BuiltinID == Builtin::BIwork_group_reserve_write_pipe)
6040 Name =
"__work_group_reserve_write_pipe";
6041 else if (BuiltinID == Builtin::BIsub_group_reserve_read_pipe)
6042 Name =
"__sub_group_reserve_read_pipe";
6044 Name =
"__sub_group_reserve_write_pipe";
6050 Value *PacketSize = OpenCLRT.getPipeElemSize(
E->getArg(0));
6051 Value *PacketAlign = OpenCLRT.getPipeElemAlign(
E->getArg(0));
6055 llvm::FunctionType *FTy = llvm::FunctionType::get(
6062 {Arg0, Arg1, PacketSize, PacketAlign}));
6066 case Builtin::BIcommit_read_pipe:
6067 case Builtin::BIcommit_write_pipe:
6068 case Builtin::BIwork_group_commit_read_pipe:
6069 case Builtin::BIwork_group_commit_write_pipe:
6070 case Builtin::BIsub_group_commit_read_pipe:
6071 case Builtin::BIsub_group_commit_write_pipe: {
6073 if (BuiltinID == Builtin::BIcommit_read_pipe)
6074 Name =
"__commit_read_pipe";
6075 else if (BuiltinID == Builtin::BIcommit_write_pipe)
6076 Name =
"__commit_write_pipe";
6077 else if (BuiltinID == Builtin::BIwork_group_commit_read_pipe)
6078 Name =
"__work_group_commit_read_pipe";
6079 else if (BuiltinID == Builtin::BIwork_group_commit_write_pipe)
6080 Name =
"__work_group_commit_write_pipe";
6081 else if (BuiltinID == Builtin::BIsub_group_commit_read_pipe)
6082 Name =
"__sub_group_commit_read_pipe";
6084 Name =
"__sub_group_commit_write_pipe";
6089 Value *PacketSize = OpenCLRT.getPipeElemSize(
E->getArg(0));
6090 Value *PacketAlign = OpenCLRT.getPipeElemAlign(
E->getArg(0));
6094 llvm::FunctionType *FTy =
6099 {Arg0, Arg1, PacketSize, PacketAlign}));
6102 case Builtin::BIget_pipe_num_packets:
6103 case Builtin::BIget_pipe_max_packets: {
6104 const char *BaseName;
6106 if (BuiltinID == Builtin::BIget_pipe_num_packets)
6107 BaseName =
"__get_pipe_num_packets";
6109 BaseName =
"__get_pipe_max_packets";
6110 std::string Name = std::string(BaseName) +
6111 std::string(PipeTy->isReadOnly() ?
"_ro" :
"_wo");
6116 Value *PacketSize = OpenCLRT.getPipeElemSize(
E->getArg(0));
6117 Value *PacketAlign = OpenCLRT.getPipeElemAlign(
E->getArg(0));
6119 llvm::FunctionType *FTy = llvm::FunctionType::get(
6123 {Arg0, PacketSize, PacketAlign}));
6127 case Builtin::BIto_global:
6128 case Builtin::BIto_local:
6129 case Builtin::BIto_private: {
6131 auto NewArgT = llvm::PointerType::get(
6134 auto NewRetT = llvm::PointerType::get(
6138 auto FTy = llvm::FunctionType::get(NewRetT, {NewArgT},
false);
6139 llvm::Value *NewArg;
6140 if (Arg0->
getType()->getPointerAddressSpace() !=
6141 NewArgT->getPointerAddressSpace())
6144 NewArg =
Builder.CreateBitOrPointerCast(Arg0, NewArgT);
6145 auto NewName = std::string(
"__") +
E->getDirectCallee()->getName().str();
6160 case Builtin::BIenqueue_kernel: {
6162 unsigned NumArgs =
E->getNumArgs();
6165 llvm::Type *GenericVoidPtrTy =
Builder.getPtrTy(
6177 Name =
"__enqueue_kernel_basic";
6178 llvm::Type *ArgTys[] = {QueueTy,
Int32Ty, RangeTy, GenericVoidPtrTy,
6180 llvm::FunctionType *FTy = llvm::FunctionType::get(
6186 Builder.CreatePointerCast(Info.KernelHandle, GenericVoidPtrTy);
6187 llvm::Value *
Block =
6188 Builder.CreatePointerCast(Info.BlockArg, GenericVoidPtrTy);
6191 {Queue, Flags, Range, Kernel, Block});
6194 assert(NumArgs >= 5 &&
"Invalid enqueue_kernel signature");
6198 auto CreateArrayForSizeVar = [=](
unsigned First)
6199 -> std::tuple<llvm::Value *, llvm::Value *, llvm::Value *> {
6200 llvm::APInt ArraySize(32, NumArgs -
First);
6202 getContext().getSizeType(), ArraySize,
nullptr,
6206 llvm::Value *TmpPtr = Tmp.getPointer();
6211 llvm::Value *Alloca = TmpPtr->stripPointerCasts();
6214 llvm::Value *ElemPtr;
6217 auto *
Zero = llvm::ConstantInt::get(
IntTy, 0);
6218 for (
unsigned I =
First; I < NumArgs; ++I) {
6219 auto *Index = llvm::ConstantInt::get(
IntTy, I -
First);
6231 return std::tie(ElemPtr, TmpSize, Alloca);
6237 Name =
"__enqueue_kernel_varargs";
6241 Builder.CreatePointerCast(Info.KernelHandle, GenericVoidPtrTy);
6242 auto *
Block =
Builder.CreatePointerCast(Info.BlockArg, GenericVoidPtrTy);
6243 llvm::Value *ElemPtr, *TmpSize, *TmpPtr;
6244 std::tie(ElemPtr, TmpSize, TmpPtr) = CreateArrayForSizeVar(4);
6248 llvm::Value *
const Args[] = {Queue, Flags,
6252 llvm::Type *
const ArgTys[] = {
6253 QueueTy,
IntTy, RangeTy, GenericVoidPtrTy,
6254 GenericVoidPtrTy,
IntTy, ElemPtr->getType()};
6256 llvm::FunctionType *FTy = llvm::FunctionType::get(
Int32Ty, ArgTys,
false);
6265 llvm::PointerType *PtrTy = llvm::PointerType::get(
6269 llvm::Value *NumEvents =
6275 llvm::Value *EventWaitList =
nullptr;
6278 EventWaitList = llvm::ConstantPointerNull::get(PtrTy);
6285 EventWaitList =
Builder.CreatePointerCast(EventWaitList, PtrTy);
6287 llvm::Value *EventRet =
nullptr;
6290 EventRet = llvm::ConstantPointerNull::get(PtrTy);
6299 Builder.CreatePointerCast(Info.KernelHandle, GenericVoidPtrTy);
6300 llvm::Value *
Block =
6301 Builder.CreatePointerCast(Info.BlockArg, GenericVoidPtrTy);
6303 std::vector<llvm::Type *> ArgTys = {
6305 PtrTy, PtrTy, GenericVoidPtrTy, GenericVoidPtrTy};
6307 std::vector<llvm::Value *> Args = {Queue, Flags,
Range,
6308 NumEvents, EventWaitList, EventRet,
6313 Name =
"__enqueue_kernel_basic_events";
6314 llvm::FunctionType *FTy = llvm::FunctionType::get(
6322 Args.push_back(ConstantInt::get(
Int32Ty, NumArgs - 7));
6324 Name =
"__enqueue_kernel_events_varargs";
6326 llvm::Value *ElemPtr, *TmpSize, *TmpPtr;
6327 std::tie(ElemPtr, TmpSize, TmpPtr) = CreateArrayForSizeVar(7);
6328 Args.push_back(ElemPtr);
6329 ArgTys.push_back(ElemPtr->getType());
6331 llvm::FunctionType *FTy = llvm::FunctionType::get(
6340 llvm_unreachable(
"Unexpected enqueue_kernel signature");
6344 case Builtin::BIget_kernel_work_group_size: {
6345 llvm::Type *GenericVoidPtrTy =
Builder.getPtrTy(
6350 Builder.CreatePointerCast(Info.KernelHandle, GenericVoidPtrTy);
6351 Value *Arg =
Builder.CreatePointerCast(Info.BlockArg, GenericVoidPtrTy);
6354 llvm::FunctionType::get(
IntTy, {GenericVoidPtrTy, GenericVoidPtrTy},
6356 "__get_kernel_work_group_size_impl"),
6359 case Builtin::BIget_kernel_preferred_work_group_size_multiple: {
6360 llvm::Type *GenericVoidPtrTy =
Builder.getPtrTy(
6365 Builder.CreatePointerCast(Info.KernelHandle, GenericVoidPtrTy);
6366 Value *Arg =
Builder.CreatePointerCast(Info.BlockArg, GenericVoidPtrTy);
6369 llvm::FunctionType::get(
IntTy, {GenericVoidPtrTy, GenericVoidPtrTy},
6371 "__get_kernel_preferred_work_group_size_multiple_impl"),
6374 case Builtin::BIget_kernel_max_sub_group_size_for_ndrange:
6375 case Builtin::BIget_kernel_sub_group_count_for_ndrange: {
6376 llvm::Type *GenericVoidPtrTy =
Builder.getPtrTy(
6383 Builder.CreatePointerCast(Info.KernelHandle, GenericVoidPtrTy);
6386 BuiltinID == Builtin::BIget_kernel_max_sub_group_size_for_ndrange
6387 ?
"__get_kernel_max_sub_group_size_for_ndrange_impl"
6388 :
"__get_kernel_sub_group_count_for_ndrange_impl";
6391 llvm::FunctionType::get(
6392 IntTy, {NDRange->getType(), GenericVoidPtrTy, GenericVoidPtrTy},
6395 {NDRange, Kernel, Block}));
6397 case Builtin::BI__builtin_store_half:
6398 case Builtin::BI__builtin_store_halff: {
6405 case Builtin::BI__builtin_load_half: {
6410 case Builtin::BI__builtin_load_halff: {
6415 case Builtin::BI__builtin_printf:
6416 case Builtin::BIprintf:
6417 if (
getTarget().getTriple().isNVPTX() ||
6420 getTarget().getTriple().getVendor() == Triple::VendorType::AMD)) {
6423 if ((
getTarget().getTriple().isAMDGCN() ||
6430 case Builtin::BI__builtin_canonicalize:
6431 case Builtin::BI__builtin_canonicalizef:
6432 case Builtin::BI__builtin_canonicalizef16:
6433 case Builtin::BI__builtin_canonicalizel:
6435 emitBuiltinWithOneOverloadedType<1>(*
this,
E, Intrinsic::canonicalize));
6437 case Builtin::BI__builtin_thread_pointer: {
6438 if (!
getContext().getTargetInfo().isTLSSupported())
6443 case Builtin::BI__builtin_os_log_format:
6446 case Builtin::BI__xray_customevent: {
6459 auto FTy = F->getFunctionType();
6460 auto Arg0 =
E->getArg(0);
6462 auto Arg0Ty = Arg0->
getType();
6463 auto PTy0 = FTy->getParamType(0);
6464 if (PTy0 != Arg0Val->getType()) {
6465 if (Arg0Ty->isArrayType())
6468 Arg0Val =
Builder.CreatePointerCast(Arg0Val, PTy0);
6471 auto PTy1 = FTy->getParamType(1);
6473 Arg1 =
Builder.CreateTruncOrBitCast(Arg1, PTy1);
6477 case Builtin::BI__xray_typedevent: {
6493 auto FTy = F->getFunctionType();
6495 auto PTy0 = FTy->getParamType(0);
6497 Arg0 =
Builder.CreateTruncOrBitCast(Arg0, PTy0);
6498 auto Arg1 =
E->getArg(1);
6500 auto Arg1Ty = Arg1->
getType();
6501 auto PTy1 = FTy->getParamType(1);
6502 if (PTy1 != Arg1Val->getType()) {
6503 if (Arg1Ty->isArrayType())
6506 Arg1Val =
Builder.CreatePointerCast(Arg1Val, PTy1);
6509 auto PTy2 = FTy->getParamType(2);
6511 Arg2 =
Builder.CreateTruncOrBitCast(Arg2, PTy2);
6515 case Builtin::BI__builtin_ms_va_start:
6516 case Builtin::BI__builtin_ms_va_end:
6519 BuiltinID == Builtin::BI__builtin_ms_va_start));
6521 case Builtin::BI__builtin_ms_va_copy: {
6538 case Builtin::BI__builtin_get_device_side_mangled_name: {
6566 LargestVectorWidth = std::max(LargestVectorWidth, VectorWidth);
6570 Intrinsic::ID IntrinsicID = Intrinsic::not_intrinsic;
6572 llvm::Triple::getArchTypePrefix(
getTarget().getTriple().getArch());
6573 if (!Prefix.empty()) {
6574 IntrinsicID = Intrinsic::getIntrinsicForClangBuiltin(Prefix.data(), Name);
6575 if (IntrinsicID == Intrinsic::not_intrinsic && Prefix ==
"spv" &&
6576 getTarget().getTriple().getOS() == llvm::Triple::OSType::AMDHSA)
6577 IntrinsicID = Intrinsic::getIntrinsicForClangBuiltin(
"amdgcn", Name);
6581 if (IntrinsicID == Intrinsic::not_intrinsic)
6582 IntrinsicID = Intrinsic::getIntrinsicForMSBuiltin(Prefix.data(), Name);
6585 if (IntrinsicID != Intrinsic::not_intrinsic) {
6590 unsigned ICEArguments = 0;
6596 llvm::FunctionType *FTy = F->getFunctionType();
6598 for (
unsigned i = 0, e =
E->getNumArgs(); i != e; ++i) {
6602 llvm::Type *PTy = FTy->getParamType(i);
6603 if (PTy != ArgValue->
getType()) {
6605 if (
auto *PtrTy = dyn_cast<llvm::PointerType>(PTy)) {
6606 if (PtrTy->getAddressSpace() !=
6607 ArgValue->
getType()->getPointerAddressSpace()) {
6610 PtrTy->getAddressSpace()));
6616 if (PTy->isX86_AMXTy())
6617 ArgValue =
Builder.CreateIntrinsic(Intrinsic::x86_cast_vector_to_tile,
6618 {ArgValue->
getType()}, {ArgValue});
6620 ArgValue =
Builder.CreateBitCast(ArgValue, PTy);
6623 Args.push_back(ArgValue);
6629 llvm::Type *RetTy =
VoidTy;
6633 if (RetTy !=
V->getType()) {
6635 if (
auto *PtrTy = dyn_cast<llvm::PointerType>(RetTy)) {
6636 if (PtrTy->getAddressSpace() !=
V->getType()->getPointerAddressSpace()) {
6639 PtrTy->getAddressSpace()));
6645 if (
V->getType()->isX86_AMXTy())
6646 V =
Builder.CreateIntrinsic(Intrinsic::x86_cast_tile_to_vector, {RetTy},
6652 if (RetTy->isVoidTy())
6672 if (
V->getType()->isVoidTy())
6679 llvm_unreachable(
"No current target builtin returns complex");
6681 llvm_unreachable(
"Bad evaluation kind in EmitBuiltinExpr");
6688 if (
V->getType()->isVoidTy())
6695 llvm_unreachable(
"No current hlsl builtin returns complex");
6697 llvm_unreachable(
"Bad evaluation kind in EmitBuiltinExpr");
6712 llvm::Triple::ArchType Arch) {
6724 case llvm::Triple::arm:
6725 case llvm::Triple::armeb:
6726 case llvm::Triple::thumb:
6727 case llvm::Triple::thumbeb:
6729 case llvm::Triple::aarch64:
6730 case llvm::Triple::aarch64_32:
6731 case llvm::Triple::aarch64_be:
6733 case llvm::Triple::bpfeb:
6734 case llvm::Triple::bpfel:
6736 case llvm::Triple::x86:
6737 case llvm::Triple::x86_64:
6739 case llvm::Triple::ppc:
6740 case llvm::Triple::ppcle:
6741 case llvm::Triple::ppc64:
6742 case llvm::Triple::ppc64le:
6744 case llvm::Triple::r600:
6745 case llvm::Triple::amdgcn:
6747 case llvm::Triple::systemz:
6749 case llvm::Triple::nvptx:
6750 case llvm::Triple::nvptx64:
6752 case llvm::Triple::wasm32:
6753 case llvm::Triple::wasm64:
6755 case llvm::Triple::hexagon:
6757 case llvm::Triple::riscv32:
6758 case llvm::Triple::riscv64:
6760 case llvm::Triple::spirv64:
6773 assert(
getContext().getAuxTargetInfo() &&
"Missing aux target info");
6785 bool HasLegalHalfType =
true,
6787 bool AllowBFloatArgsAndRet =
true) {
6788 int IsQuad = TypeFlags.
isQuad();
6792 return llvm::FixedVectorType::get(CGF->
Int8Ty, V1Ty ? 1 : (8 << IsQuad));
6795 return llvm::FixedVectorType::get(CGF->
Int16Ty, V1Ty ? 1 : (4 << IsQuad));
6797 if (AllowBFloatArgsAndRet)
6798 return llvm::FixedVectorType::get(CGF->
BFloatTy, V1Ty ? 1 : (4 << IsQuad));
6800 return llvm::FixedVectorType::get(CGF->
Int16Ty, V1Ty ? 1 : (4 << IsQuad));
6802 if (HasLegalHalfType)
6803 return llvm::FixedVectorType::get(CGF->
HalfTy, V1Ty ? 1 : (4 << IsQuad));
6805 return llvm::FixedVectorType::get(CGF->
Int16Ty, V1Ty ? 1 : (4 << IsQuad));
6807 return llvm::FixedVectorType::get(CGF->
Int32Ty, V1Ty ? 1 : (2 << IsQuad));
6810 return llvm::FixedVectorType::get(CGF->
Int64Ty, V1Ty ? 1 : (1 << IsQuad));
6815 return llvm::FixedVectorType::get(CGF->
Int8Ty, 16);
6817 return llvm::FixedVectorType::get(CGF->
FloatTy, V1Ty ? 1 : (2 << IsQuad));
6819 return llvm::FixedVectorType::get(CGF->
DoubleTy, V1Ty ? 1 : (1 << IsQuad));
6821 llvm_unreachable(
"Unknown vector element type!");
6826 int IsQuad = IntTypeFlags.
isQuad();
6829 return llvm::FixedVectorType::get(CGF->
HalfTy, (4 << IsQuad));
6831 return llvm::FixedVectorType::get(CGF->
FloatTy, (2 << IsQuad));
6833 return llvm::FixedVectorType::get(CGF->
DoubleTy, (1 << IsQuad));
6835 llvm_unreachable(
"Type can't be converted to floating-point!");
6840 const ElementCount &Count) {
6841 Value *SV = llvm::ConstantVector::getSplat(Count,
C);
6842 return Builder.CreateShuffleVector(
V,
V, SV,
"lane");
6846 ElementCount EC = cast<llvm::VectorType>(
V->getType())->getElementCount();
6852 unsigned shift,
bool rightshift) {
6854 for (Function::const_arg_iterator ai = F->arg_begin(), ae = F->arg_end();
6855 ai != ae; ++ai, ++j) {
6856 if (F->isConstrainedFPIntrinsic())
6857 if (ai->getType()->isMetadataTy())
6859 if (shift > 0 && shift == j)
6862 Ops[j] =
Builder.CreateBitCast(Ops[j], ai->getType(), name);
6865 if (F->isConstrainedFPIntrinsic())
6866 return Builder.CreateConstrainedFPCall(F, Ops, name);
6868 return Builder.CreateCall(F, Ops, name);
6873 int SV = cast<ConstantInt>(
V)->getSExtValue();
6874 return ConstantInt::get(Ty, neg ? -SV : SV);
6879 llvm::Type *Ty,
bool usgn,
6881 llvm::VectorType *VTy = cast<llvm::VectorType>(Ty);
6883 int ShiftAmt = cast<ConstantInt>(Shift)->getSExtValue();
6884 int EltSize = VTy->getScalarSizeInBits();
6886 Vec =
Builder.CreateBitCast(Vec, Ty);
6890 if (ShiftAmt == EltSize) {
6893 return llvm::ConstantAggregateZero::get(VTy);
6898 Shift = ConstantInt::get(VTy->getElementType(), ShiftAmt);
6904 return Builder.CreateLShr(Vec, Shift, name);
6906 return Builder.CreateAShr(Vec, Shift, name);
6932struct ARMVectorIntrinsicInfo {
6933 const char *NameHint;
6935 unsigned LLVMIntrinsic;
6936 unsigned AltLLVMIntrinsic;
6939 bool operator<(
unsigned RHSBuiltinID)
const {
6940 return BuiltinID < RHSBuiltinID;
6942 bool operator<(
const ARMVectorIntrinsicInfo &TE)
const {
6943 return BuiltinID < TE.BuiltinID;
6948#define NEONMAP0(NameBase) \
6949 { #NameBase, NEON::BI__builtin_neon_ ## NameBase, 0, 0, 0 }
6951#define NEONMAP1(NameBase, LLVMIntrinsic, TypeModifier) \
6952 { #NameBase, NEON:: BI__builtin_neon_ ## NameBase, \
6953 Intrinsic::LLVMIntrinsic, 0, TypeModifier }
6955#define NEONMAP2(NameBase, LLVMIntrinsic, AltLLVMIntrinsic, TypeModifier) \
6956 { #NameBase, NEON:: BI__builtin_neon_ ## NameBase, \
6957 Intrinsic::LLVMIntrinsic, Intrinsic::AltLLVMIntrinsic, \
6961 NEONMAP1(__a32_vcvt_bf16_f32, arm_neon_vcvtfp2bf, 0),
6968 NEONMAP1(vabs_v, arm_neon_vabs, 0),
6969 NEONMAP1(vabsq_v, arm_neon_vabs, 0),
6973 NEONMAP1(vaesdq_u8, arm_neon_aesd, 0),
6974 NEONMAP1(vaeseq_u8, arm_neon_aese, 0),
6975 NEONMAP1(vaesimcq_u8, arm_neon_aesimc, 0),
6976 NEONMAP1(vaesmcq_u8, arm_neon_aesmc, 0),
6977 NEONMAP1(vbfdot_f32, arm_neon_bfdot, 0),
6978 NEONMAP1(vbfdotq_f32, arm_neon_bfdot, 0),
6979 NEONMAP1(vbfmlalbq_f32, arm_neon_bfmlalb, 0),
6980 NEONMAP1(vbfmlaltq_f32, arm_neon_bfmlalt, 0),
6981 NEONMAP1(vbfmmlaq_f32, arm_neon_bfmmla, 0),
6994 NEONMAP1(vcage_v, arm_neon_vacge, 0),
6995 NEONMAP1(vcageq_v, arm_neon_vacge, 0),
6996 NEONMAP1(vcagt_v, arm_neon_vacgt, 0),
6997 NEONMAP1(vcagtq_v, arm_neon_vacgt, 0),
6998 NEONMAP1(vcale_v, arm_neon_vacge, 0),
6999 NEONMAP1(vcaleq_v, arm_neon_vacge, 0),
7000 NEONMAP1(vcalt_v, arm_neon_vacgt, 0),
7001 NEONMAP1(vcaltq_v, arm_neon_vacgt, 0),
7018 NEONMAP1(vcvt_f16_f32, arm_neon_vcvtfp2hf, 0),
7021 NEONMAP1(vcvt_f32_f16, arm_neon_vcvthf2fp, 0),
7023 NEONMAP1(vcvt_n_f16_s16, arm_neon_vcvtfxs2fp, 0),
7024 NEONMAP1(vcvt_n_f16_u16, arm_neon_vcvtfxu2fp, 0),
7025 NEONMAP2(vcvt_n_f32_v, arm_neon_vcvtfxu2fp, arm_neon_vcvtfxs2fp, 0),
7026 NEONMAP1(vcvt_n_s16_f16, arm_neon_vcvtfp2fxs, 0),
7027 NEONMAP1(vcvt_n_s32_v, arm_neon_vcvtfp2fxs, 0),
7028 NEONMAP1(vcvt_n_s64_v, arm_neon_vcvtfp2fxs, 0),
7029 NEONMAP1(vcvt_n_u16_f16, arm_neon_vcvtfp2fxu, 0),
7030 NEONMAP1(vcvt_n_u32_v, arm_neon_vcvtfp2fxu, 0),
7031 NEONMAP1(vcvt_n_u64_v, arm_neon_vcvtfp2fxu, 0),
7038 NEONMAP1(vcvta_s16_f16, arm_neon_vcvtas, 0),
7039 NEONMAP1(vcvta_s32_v, arm_neon_vcvtas, 0),
7040 NEONMAP1(vcvta_s64_v, arm_neon_vcvtas, 0),
7041 NEONMAP1(vcvta_u16_f16, arm_neon_vcvtau, 0),
7042 NEONMAP1(vcvta_u32_v, arm_neon_vcvtau, 0),
7043 NEONMAP1(vcvta_u64_v, arm_neon_vcvtau, 0),
7044 NEONMAP1(vcvtaq_s16_f16, arm_neon_vcvtas, 0),
7045 NEONMAP1(vcvtaq_s32_v, arm_neon_vcvtas, 0),
7046 NEONMAP1(vcvtaq_s64_v, arm_neon_vcvtas, 0),
7047 NEONMAP1(vcvtaq_u16_f16, arm_neon_vcvtau, 0),
7048 NEONMAP1(vcvtaq_u32_v, arm_neon_vcvtau, 0),
7049 NEONMAP1(vcvtaq_u64_v, arm_neon_vcvtau, 0),
7050 NEONMAP1(vcvth_bf16_f32, arm_neon_vcvtbfp2bf, 0),
7051 NEONMAP1(vcvtm_s16_f16, arm_neon_vcvtms, 0),
7052 NEONMAP1(vcvtm_s32_v, arm_neon_vcvtms, 0),
7053 NEONMAP1(vcvtm_s64_v, arm_neon_vcvtms, 0),
7054 NEONMAP1(vcvtm_u16_f16, arm_neon_vcvtmu, 0),
7055 NEONMAP1(vcvtm_u32_v, arm_neon_vcvtmu, 0),
7056 NEONMAP1(vcvtm_u64_v, arm_neon_vcvtmu, 0),
7057 NEONMAP1(vcvtmq_s16_f16, arm_neon_vcvtms, 0),
7058 NEONMAP1(vcvtmq_s32_v, arm_neon_vcvtms, 0),
7059 NEONMAP1(vcvtmq_s64_v, arm_neon_vcvtms, 0),
7060 NEONMAP1(vcvtmq_u16_f16, arm_neon_vcvtmu, 0),
7061 NEONMAP1(vcvtmq_u32_v, arm_neon_vcvtmu, 0),
7062 NEONMAP1(vcvtmq_u64_v, arm_neon_vcvtmu, 0),
7063 NEONMAP1(vcvtn_s16_f16, arm_neon_vcvtns, 0),
7064 NEONMAP1(vcvtn_s32_v, arm_neon_vcvtns, 0),
7065 NEONMAP1(vcvtn_s64_v, arm_neon_vcvtns, 0),
7066 NEONMAP1(vcvtn_u16_f16, arm_neon_vcvtnu, 0),
7067 NEONMAP1(vcvtn_u32_v, arm_neon_vcvtnu, 0),
7068 NEONMAP1(vcvtn_u64_v, arm_neon_vcvtnu, 0),
7069 NEONMAP1(vcvtnq_s16_f16, arm_neon_vcvtns, 0),
7070 NEONMAP1(vcvtnq_s32_v, arm_neon_vcvtns, 0),
7071 NEONMAP1(vcvtnq_s64_v, arm_neon_vcvtns, 0),
7072 NEONMAP1(vcvtnq_u16_f16, arm_neon_vcvtnu, 0),
7073 NEONMAP1(vcvtnq_u32_v, arm_neon_vcvtnu, 0),
7074 NEONMAP1(vcvtnq_u64_v, arm_neon_vcvtnu, 0),
7075 NEONMAP1(vcvtp_s16_f16, arm_neon_vcvtps, 0),
7076 NEONMAP1(vcvtp_s32_v, arm_neon_vcvtps, 0),
7077 NEONMAP1(vcvtp_s64_v, arm_neon_vcvtps, 0),
7078 NEONMAP1(vcvtp_u16_f16, arm_neon_vcvtpu, 0),
7079 NEONMAP1(vcvtp_u32_v, arm_neon_vcvtpu, 0),
7080 NEONMAP1(vcvtp_u64_v, arm_neon_vcvtpu, 0),
7081 NEONMAP1(vcvtpq_s16_f16, arm_neon_vcvtps, 0),
7082 NEONMAP1(vcvtpq_s32_v, arm_neon_vcvtps, 0),
7083 NEONMAP1(vcvtpq_s64_v, arm_neon_vcvtps, 0),
7084 NEONMAP1(vcvtpq_u16_f16, arm_neon_vcvtpu, 0),
7085 NEONMAP1(vcvtpq_u32_v, arm_neon_vcvtpu, 0),
7086 NEONMAP1(vcvtpq_u64_v, arm_neon_vcvtpu, 0),
7090 NEONMAP1(vcvtq_n_f16_s16, arm_neon_vcvtfxs2fp, 0),
7091 NEONMAP1(vcvtq_n_f16_u16, arm_neon_vcvtfxu2fp, 0),
7092 NEONMAP2(vcvtq_n_f32_v, arm_neon_vcvtfxu2fp, arm_neon_vcvtfxs2fp, 0),
7093 NEONMAP1(vcvtq_n_s16_f16, arm_neon_vcvtfp2fxs, 0),
7094 NEONMAP1(vcvtq_n_s32_v, arm_neon_vcvtfp2fxs, 0),
7095 NEONMAP1(vcvtq_n_s64_v, arm_neon_vcvtfp2fxs, 0),
7096 NEONMAP1(vcvtq_n_u16_f16, arm_neon_vcvtfp2fxu, 0),
7097 NEONMAP1(vcvtq_n_u32_v, arm_neon_vcvtfp2fxu, 0),
7098 NEONMAP1(vcvtq_n_u64_v, arm_neon_vcvtfp2fxu, 0),
7105 NEONMAP1(vdot_s32, arm_neon_sdot, 0),
7106 NEONMAP1(vdot_u32, arm_neon_udot, 0),
7107 NEONMAP1(vdotq_s32, arm_neon_sdot, 0),
7108 NEONMAP1(vdotq_u32, arm_neon_udot, 0),
7118 NEONMAP1(vld1_v, arm_neon_vld1, 0),
7119 NEONMAP1(vld1_x2_v, arm_neon_vld1x2, 0),
7120 NEONMAP1(vld1_x3_v, arm_neon_vld1x3, 0),
7121 NEONMAP1(vld1_x4_v, arm_neon_vld1x4, 0),
7123 NEONMAP1(vld1q_v, arm_neon_vld1, 0),
7124 NEONMAP1(vld1q_x2_v, arm_neon_vld1x2, 0),
7125 NEONMAP1(vld1q_x3_v, arm_neon_vld1x3, 0),
7126 NEONMAP1(vld1q_x4_v, arm_neon_vld1x4, 0),
7127 NEONMAP1(vld2_dup_v, arm_neon_vld2dup, 0),
7128 NEONMAP1(vld2_lane_v, arm_neon_vld2lane, 0),
7129 NEONMAP1(vld2_v, arm_neon_vld2, 0),
7130 NEONMAP1(vld2q_dup_v, arm_neon_vld2dup, 0),
7131 NEONMAP1(vld2q_lane_v, arm_neon_vld2lane, 0),
7132 NEONMAP1(vld2q_v, arm_neon_vld2, 0),
7133 NEONMAP1(vld3_dup_v, arm_neon_vld3dup, 0),
7134 NEONMAP1(vld3_lane_v, arm_neon_vld3lane, 0),
7135 NEONMAP1(vld3_v, arm_neon_vld3, 0),
7136 NEONMAP1(vld3q_dup_v, arm_neon_vld3dup, 0),
7137 NEONMAP1(vld3q_lane_v, arm_neon_vld3lane, 0),
7138 NEONMAP1(vld3q_v, arm_neon_vld3, 0),
7139 NEONMAP1(vld4_dup_v, arm_neon_vld4dup, 0),
7140 NEONMAP1(vld4_lane_v, arm_neon_vld4lane, 0),
7141 NEONMAP1(vld4_v, arm_neon_vld4, 0),
7142 NEONMAP1(vld4q_dup_v, arm_neon_vld4dup, 0),
7143 NEONMAP1(vld4q_lane_v, arm_neon_vld4lane, 0),
7144 NEONMAP1(vld4q_v, arm_neon_vld4, 0),
7153 NEONMAP1(vmmlaq_s32, arm_neon_smmla, 0),
7154 NEONMAP1(vmmlaq_u32, arm_neon_ummla, 0),
7172 NEONMAP2(vqdmlal_v, arm_neon_vqdmull, sadd_sat, 0),
7173 NEONMAP2(vqdmlsl_v, arm_neon_vqdmull, ssub_sat, 0),
7197 NEONMAP1(vqshlu_n_v, arm_neon_vqshiftsu, 0),
7198 NEONMAP1(vqshluq_n_v, arm_neon_vqshiftsu, 0),
7202 NEONMAP2(vrecpe_v, arm_neon_vrecpe, arm_neon_vrecpe, 0),
7203 NEONMAP2(vrecpeq_v, arm_neon_vrecpe, arm_neon_vrecpe, 0),
7226 NEONMAP2(vrsqrte_v, arm_neon_vrsqrte, arm_neon_vrsqrte, 0),
7227 NEONMAP2(vrsqrteq_v, arm_neon_vrsqrte, arm_neon_vrsqrte, 0),
7231 NEONMAP1(vsha1su0q_u32, arm_neon_sha1su0, 0),
7232 NEONMAP1(vsha1su1q_u32, arm_neon_sha1su1, 0),
7233 NEONMAP1(vsha256h2q_u32, arm_neon_sha256h2, 0),
7234 NEONMAP1(vsha256hq_u32, arm_neon_sha256h, 0),
7235 NEONMAP1(vsha256su0q_u32, arm_neon_sha256su0, 0),
7236 NEONMAP1(vsha256su1q_u32, arm_neon_sha256su1, 0),
7245 NEONMAP1(vst1_v, arm_neon_vst1, 0),
7246 NEONMAP1(vst1_x2_v, arm_neon_vst1x2, 0),
7247 NEONMAP1(vst1_x3_v, arm_neon_vst1x3, 0),
7248 NEONMAP1(vst1_x4_v, arm_neon_vst1x4, 0),
7249 NEONMAP1(vst1q_v, arm_neon_vst1, 0),
7250 NEONMAP1(vst1q_x2_v, arm_neon_vst1x2, 0),
7251 NEONMAP1(vst1q_x3_v, arm_neon_vst1x3, 0),
7252 NEONMAP1(vst1q_x4_v, arm_neon_vst1x4, 0),
7253 NEONMAP1(vst2_lane_v, arm_neon_vst2lane, 0),
7254 NEONMAP1(vst2_v, arm_neon_vst2, 0),
7255 NEONMAP1(vst2q_lane_v, arm_neon_vst2lane, 0),
7256 NEONMAP1(vst2q_v, arm_neon_vst2, 0),
7257 NEONMAP1(vst3_lane_v, arm_neon_vst3lane, 0),
7258 NEONMAP1(vst3_v, arm_neon_vst3, 0),
7259 NEONMAP1(vst3q_lane_v, arm_neon_vst3lane, 0),
7260 NEONMAP1(vst3q_v, arm_neon_vst3, 0),
7261 NEONMAP1(vst4_lane_v, arm_neon_vst4lane, 0),
7262 NEONMAP1(vst4_v, arm_neon_vst4, 0),
7263 NEONMAP1(vst4q_lane_v, arm_neon_vst4lane, 0),
7264 NEONMAP1(vst4q_v, arm_neon_vst4, 0),
7270 NEONMAP1(vusdot_s32, arm_neon_usdot, 0),
7271 NEONMAP1(vusdotq_s32, arm_neon_usdot, 0),
7272 NEONMAP1(vusmmlaq_s32, arm_neon_usmmla, 0),
7280 NEONMAP1(__a64_vcvtq_low_bf16_f32, aarch64_neon_bfcvtn, 0),
7285 NEONMAP1(vabs_v, aarch64_neon_abs, 0),
7286 NEONMAP1(vabsq_v, aarch64_neon_abs, 0),
7291 NEONMAP1(vaesdq_u8, aarch64_crypto_aesd, 0),
7292 NEONMAP1(vaeseq_u8, aarch64_crypto_aese, 0),
7293 NEONMAP1(vaesimcq_u8, aarch64_crypto_aesimc, 0),
7294 NEONMAP1(vaesmcq_u8, aarch64_crypto_aesmc, 0),
7303 NEONMAP1(vbfdot_f32, aarch64_neon_bfdot, 0),
7304 NEONMAP1(vbfdotq_f32, aarch64_neon_bfdot, 0),
7305 NEONMAP1(vbfmlalbq_f32, aarch64_neon_bfmlalb, 0),
7306 NEONMAP1(vbfmlaltq_f32, aarch64_neon_bfmlalt, 0),
7307 NEONMAP1(vbfmmlaq_f32, aarch64_neon_bfmmla, 0),
7318 NEONMAP1(vcage_v, aarch64_neon_facge, 0),
7319 NEONMAP1(vcageq_v, aarch64_neon_facge, 0),
7320 NEONMAP1(vcagt_v, aarch64_neon_facgt, 0),
7321 NEONMAP1(vcagtq_v, aarch64_neon_facgt, 0),
7322 NEONMAP1(vcale_v, aarch64_neon_facge, 0),
7323 NEONMAP1(vcaleq_v, aarch64_neon_facge, 0),
7324 NEONMAP1(vcalt_v, aarch64_neon_facgt, 0),
7325 NEONMAP1(vcaltq_v, aarch64_neon_facgt, 0),
7362 NEONMAP1(vcvt_f16_f32, aarch64_neon_vcvtfp2hf, 0),
7365 NEONMAP1(vcvt_f32_f16, aarch64_neon_vcvthf2fp, 0),
7367 NEONMAP1(vcvt_n_f16_s16, aarch64_neon_vcvtfxs2fp, 0),
7368 NEONMAP1(vcvt_n_f16_u16, aarch64_neon_vcvtfxu2fp, 0),
7369 NEONMAP2(vcvt_n_f32_v, aarch64_neon_vcvtfxu2fp, aarch64_neon_vcvtfxs2fp, 0),
7370 NEONMAP2(vcvt_n_f64_v, aarch64_neon_vcvtfxu2fp, aarch64_neon_vcvtfxs2fp, 0),
7371 NEONMAP1(vcvt_n_s16_f16, aarch64_neon_vcvtfp2fxs, 0),
7372 NEONMAP1(vcvt_n_s32_v, aarch64_neon_vcvtfp2fxs, 0),
7373 NEONMAP1(vcvt_n_s64_v, aarch64_neon_vcvtfp2fxs, 0),
7374 NEONMAP1(vcvt_n_u16_f16, aarch64_neon_vcvtfp2fxu, 0),
7375 NEONMAP1(vcvt_n_u32_v, aarch64_neon_vcvtfp2fxu, 0),
7376 NEONMAP1(vcvt_n_u64_v, aarch64_neon_vcvtfp2fxu, 0),
7380 NEONMAP1(vcvtq_high_bf16_f32, aarch64_neon_bfcvtn2, 0),
7381 NEONMAP1(vcvtq_n_f16_s16, aarch64_neon_vcvtfxs2fp, 0),
7382 NEONMAP1(vcvtq_n_f16_u16, aarch64_neon_vcvtfxu2fp, 0),
7383 NEONMAP2(vcvtq_n_f32_v, aarch64_neon_vcvtfxu2fp, aarch64_neon_vcvtfxs2fp, 0),
7384 NEONMAP2(vcvtq_n_f64_v, aarch64_neon_vcvtfxu2fp, aarch64_neon_vcvtfxs2fp, 0),
7385 NEONMAP1(vcvtq_n_s16_f16, aarch64_neon_vcvtfp2fxs, 0),
7386 NEONMAP1(vcvtq_n_s32_v, aarch64_neon_vcvtfp2fxs, 0),
7387 NEONMAP1(vcvtq_n_s64_v, aarch64_neon_vcvtfp2fxs, 0),
7388 NEONMAP1(vcvtq_n_u16_f16, aarch64_neon_vcvtfp2fxu, 0),
7389 NEONMAP1(vcvtq_n_u32_v, aarch64_neon_vcvtfp2fxu, 0),
7390 NEONMAP1(vcvtq_n_u64_v, aarch64_neon_vcvtfp2fxu, 0),
7392 NEONMAP1(vdot_s32, aarch64_neon_sdot, 0),
7393 NEONMAP1(vdot_u32, aarch64_neon_udot, 0),
7394 NEONMAP1(vdotq_s32, aarch64_neon_sdot, 0),
7395 NEONMAP1(vdotq_u32, aarch64_neon_udot, 0),
7408 NEONMAP1(vfmlal_high_f16, aarch64_neon_fmlal2, 0),
7409 NEONMAP1(vfmlal_low_f16, aarch64_neon_fmlal, 0),
7410 NEONMAP1(vfmlalq_high_f16, aarch64_neon_fmlal2, 0),
7411 NEONMAP1(vfmlalq_low_f16, aarch64_neon_fmlal, 0),
7412 NEONMAP1(vfmlsl_high_f16, aarch64_neon_fmlsl2, 0),
7413 NEONMAP1(vfmlsl_low_f16, aarch64_neon_fmlsl, 0),
7414 NEONMAP1(vfmlslq_high_f16, aarch64_neon_fmlsl2, 0),
7415 NEONMAP1(vfmlslq_low_f16, aarch64_neon_fmlsl, 0),
7420 NEONMAP1(vld1_x2_v, aarch64_neon_ld1x2, 0),
7421 NEONMAP1(vld1_x3_v, aarch64_neon_ld1x3, 0),
7422 NEONMAP1(vld1_x4_v, aarch64_neon_ld1x4, 0),
7423 NEONMAP1(vld1q_x2_v, aarch64_neon_ld1x2, 0),
7424 NEONMAP1(vld1q_x3_v, aarch64_neon_ld1x3, 0),
7425 NEONMAP1(vld1q_x4_v, aarch64_neon_ld1x4, 0),
7426 NEONMAP1(vmmlaq_s32, aarch64_neon_smmla, 0),
7427 NEONMAP1(vmmlaq_u32, aarch64_neon_ummla, 0),
7440 NEONMAP2(vqdmlal_v, aarch64_neon_sqdmull, aarch64_neon_sqadd, 0),
7441 NEONMAP2(vqdmlsl_v, aarch64_neon_sqdmull, aarch64_neon_sqsub, 0),
7442 NEONMAP1(vqdmulh_lane_v, aarch64_neon_sqdmulh_lane, 0),
7443 NEONMAP1(vqdmulh_laneq_v, aarch64_neon_sqdmulh_laneq, 0),
7445 NEONMAP1(vqdmulhq_lane_v, aarch64_neon_sqdmulh_lane, 0),
7446 NEONMAP1(vqdmulhq_laneq_v, aarch64_neon_sqdmulh_laneq, 0),
7461 NEONMAP1(vqrdmulh_lane_v, aarch64_neon_sqrdmulh_lane, 0),
7462 NEONMAP1(vqrdmulh_laneq_v, aarch64_neon_sqrdmulh_laneq, 0),
7464 NEONMAP1(vqrdmulhq_lane_v, aarch64_neon_sqrdmulh_lane, 0),
7465 NEONMAP1(vqrdmulhq_laneq_v, aarch64_neon_sqrdmulh_laneq, 0),
7473 NEONMAP1(vqshlu_n_v, aarch64_neon_sqshlu, 0),
7474 NEONMAP1(vqshluq_n_v, aarch64_neon_sqshlu, 0),
7478 NEONMAP1(vrax1q_u64, aarch64_crypto_rax1, 0),
7479 NEONMAP2(vrecpe_v, aarch64_neon_frecpe, aarch64_neon_urecpe, 0),
7480 NEONMAP2(vrecpeq_v, aarch64_neon_frecpe, aarch64_neon_urecpe, 0),
7507 NEONMAP2(vrsqrte_v, aarch64_neon_frsqrte, aarch64_neon_ursqrte, 0),
7508 NEONMAP2(vrsqrteq_v, aarch64_neon_frsqrte, aarch64_neon_ursqrte, 0),
7512 NEONMAP1(vsha1su0q_u32, aarch64_crypto_sha1su0, 0),
7513 NEONMAP1(vsha1su1q_u32, aarch64_crypto_sha1su1, 0),
7514 NEONMAP1(vsha256h2q_u32, aarch64_crypto_sha256h2, 0),
7515 NEONMAP1(vsha256hq_u32, aarch64_crypto_sha256h, 0),
7516 NEONMAP1(vsha256su0q_u32, aarch64_crypto_sha256su0, 0),
7517 NEONMAP1(vsha256su1q_u32, aarch64_crypto_sha256su1, 0),
7518 NEONMAP1(vsha512h2q_u64, aarch64_crypto_sha512h2, 0),
7519 NEONMAP1(vsha512hq_u64, aarch64_crypto_sha512h, 0),
7520 NEONMAP1(vsha512su0q_u64, aarch64_crypto_sha512su0, 0),
7521 NEONMAP1(vsha512su1q_u64, aarch64_crypto_sha512su1, 0),
7530 NEONMAP1(vsm3partw1q_u32, aarch64_crypto_sm3partw1, 0),
7531 NEONMAP1(vsm3partw2q_u32, aarch64_crypto_sm3partw2, 0),
7532 NEONMAP1(vsm3ss1q_u32, aarch64_crypto_sm3ss1, 0),
7533 NEONMAP1(vsm3tt1aq_u32, aarch64_crypto_sm3tt1a, 0),
7534 NEONMAP1(vsm3tt1bq_u32, aarch64_crypto_sm3tt1b, 0),
7535 NEONMAP1(vsm3tt2aq_u32, aarch64_crypto_sm3tt2a, 0),
7536 NEONMAP1(vsm3tt2bq_u32, aarch64_crypto_sm3tt2b, 0),
7537 NEONMAP1(vsm4ekeyq_u32, aarch64_crypto_sm4ekey, 0),
7538 NEONMAP1(vsm4eq_u32, aarch64_crypto_sm4e, 0),
7539 NEONMAP1(vst1_x2_v, aarch64_neon_st1x2, 0),
7540 NEONMAP1(vst1_x3_v, aarch64_neon_st1x3, 0),
7541 NEONMAP1(vst1_x4_v, aarch64_neon_st1x4, 0),
7542 NEONMAP1(vst1q_x2_v, aarch64_neon_st1x2, 0),
7543 NEONMAP1(vst1q_x3_v, aarch64_neon_st1x3, 0),
7544 NEONMAP1(vst1q_x4_v, aarch64_neon_st1x4, 0),
7548 NEONMAP1(vusdot_s32, aarch64_neon_usdot, 0),
7549 NEONMAP1(vusdotq_s32, aarch64_neon_usdot, 0),
7550 NEONMAP1(vusmmlaq_s32, aarch64_neon_usmmla, 0),
7551 NEONMAP1(vxarq_u64, aarch64_crypto_xar, 0),
7589 NEONMAP1(vcvth_bf16_f32, aarch64_neon_bfcvt, 0),
7608 NEONMAP1(vcvtxd_f32_f64, aarch64_sisd_fcvtxn, 0),
7629 NEONMAP1(vmull_p64, aarch64_neon_pmull64, 0),
7657 NEONMAP1(vqdmulls_s32, aarch64_neon_sqdmulls_scalar, 0),
7738 NEONMAP1(vsha1cq_u32, aarch64_crypto_sha1c, 0),
7739 NEONMAP1(vsha1h_u32, aarch64_crypto_sha1h, 0),
7740 NEONMAP1(vsha1mq_u32, aarch64_crypto_sha1m, 0),
7741 NEONMAP1(vsha1pq_u32, aarch64_crypto_sha1p, 0),
7795 { NEON::BI__builtin_neon_splat_lane_bf16, NEON::BI__builtin_neon_splat_lane_v, },
7796 { NEON::BI__builtin_neon_splat_laneq_bf16, NEON::BI__builtin_neon_splat_laneq_v, },
7797 { NEON::BI__builtin_neon_splatq_lane_bf16, NEON::BI__builtin_neon_splatq_lane_v, },
7798 { NEON::BI__builtin_neon_splatq_laneq_bf16, NEON::BI__builtin_neon_splatq_laneq_v, },
7799 { NEON::BI__builtin_neon_vabd_f16, NEON::BI__builtin_neon_vabd_v, },
7800 { NEON::BI__builtin_neon_vabdq_f16, NEON::BI__builtin_neon_vabdq_v, },
7801 { NEON::BI__builtin_neon_vabs_f16, NEON::BI__builtin_neon_vabs_v, },
7802 { NEON::BI__builtin_neon_vabsq_f16, NEON::BI__builtin_neon_vabsq_v, },
7803 { NEON::BI__builtin_neon_vcage_f16, NEON::BI__builtin_neon_vcage_v, },
7804 { NEON::BI__builtin_neon_vcageq_f16, NEON::BI__builtin_neon_vcageq_v, },
7805 { NEON::BI__builtin_neon_vcagt_f16, NEON::BI__builtin_neon_vcagt_v, },
7806 { NEON::BI__builtin_neon_vcagtq_f16, NEON::BI__builtin_neon_vcagtq_v, },
7807 { NEON::BI__builtin_neon_vcale_f16, NEON::BI__builtin_neon_vcale_v, },
7808 { NEON::BI__builtin_neon_vcaleq_f16, NEON::BI__builtin_neon_vcaleq_v, },
7809 { NEON::BI__builtin_neon_vcalt_f16, NEON::BI__builtin_neon_vcalt_v, },
7810 { NEON::BI__builtin_neon_vcaltq_f16, NEON::BI__builtin_neon_vcaltq_v, },
7811 { NEON::BI__builtin_neon_vceqz_f16, NEON::BI__builtin_neon_vceqz_v, },
7812 { NEON::BI__builtin_neon_vceqzq_f16, NEON::BI__builtin_neon_vceqzq_v, },
7813 { NEON::BI__builtin_neon_vcgez_f16, NEON::BI__builtin_neon_vcgez_v, },
7814 { NEON::BI__builtin_neon_vcgezq_f16, NEON::BI__builtin_neon_vcgezq_v, },
7815 { NEON::BI__builtin_neon_vcgtz_f16, NEON::BI__builtin_neon_vcgtz_v, },
7816 { NEON::BI__builtin_neon_vcgtzq_f16, NEON::BI__builtin_neon_vcgtzq_v, },
7817 { NEON::BI__builtin_neon_vclez_f16, NEON::BI__builtin_neon_vclez_v, },
7818 { NEON::BI__builtin_neon_vclezq_f16, NEON::BI__builtin_neon_vclezq_v, },
7819 { NEON::BI__builtin_neon_vcltz_f16, NEON::BI__builtin_neon_vcltz_v, },
7820 { NEON::BI__builtin_neon_vcltzq_f16, NEON::BI__builtin_neon_vcltzq_v, },
7821 { NEON::BI__builtin_neon_vfma_f16, NEON::BI__builtin_neon_vfma_v, },
7822 { NEON::BI__builtin_neon_vfma_lane_f16, NEON::BI__builtin_neon_vfma_lane_v, },
7823 { NEON::BI__builtin_neon_vfma_laneq_f16, NEON::BI__builtin_neon_vfma_laneq_v, },
7824 { NEON::BI__builtin_neon_vfmaq_f16, NEON::BI__builtin_neon_vfmaq_v, },
7825 { NEON::BI__builtin_neon_vfmaq_lane_f16, NEON::BI__builtin_neon_vfmaq_lane_v, },
7826 { NEON::BI__builtin_neon_vfmaq_laneq_f16, NEON::BI__builtin_neon_vfmaq_laneq_v, },
7827 { NEON::BI__builtin_neon_vld1_bf16_x2, NEON::BI__builtin_neon_vld1_x2_v },
7828 { NEON::BI__builtin_neon_vld1_bf16_x3, NEON::BI__builtin_neon_vld1_x3_v },
7829 { NEON::BI__builtin_neon_vld1_bf16_x4, NEON::BI__builtin_neon_vld1_x4_v },
7830 { NEON::BI__builtin_neon_vld1_bf16, NEON::BI__builtin_neon_vld1_v },
7831 { NEON::BI__builtin_neon_vld1_dup_bf16, NEON::BI__builtin_neon_vld1_dup_v },
7832 { NEON::BI__builtin_neon_vld1_lane_bf16, NEON::BI__builtin_neon_vld1_lane_v },
7833 { NEON::BI__builtin_neon_vld1q_bf16_x2, NEON::BI__builtin_neon_vld1q_x2_v },
7834 { NEON::BI__builtin_neon_vld1q_bf16_x3, NEON::BI__builtin_neon_vld1q_x3_v },
7835 { NEON::BI__builtin_neon_vld1q_bf16_x4, NEON::BI__builtin_neon_vld1q_x4_v },
7836 { NEON::BI__builtin_neon_vld1q_bf16, NEON::BI__builtin_neon_vld1q_v },
7837 { NEON::BI__builtin_neon_vld1q_dup_bf16, NEON::BI__builtin_neon_vld1q_dup_v },
7838 { NEON::BI__builtin_neon_vld1q_lane_bf16, NEON::BI__builtin_neon_vld1q_lane_v },
7839 { NEON::BI__builtin_neon_vld2_bf16, NEON::BI__builtin_neon_vld2_v },
7840 { NEON::BI__builtin_neon_vld2_dup_bf16, NEON::BI__builtin_neon_vld2_dup_v },
7841 { NEON::BI__builtin_neon_vld2_lane_bf16, NEON::BI__builtin_neon_vld2_lane_v },
7842 { NEON::BI__builtin_neon_vld2q_bf16, NEON::BI__builtin_neon_vld2q_v },
7843 { NEON::BI__builtin_neon_vld2q_dup_bf16, NEON::BI__builtin_neon_vld2q_dup_v },
7844 { NEON::BI__builtin_neon_vld2q_lane_bf16, NEON::BI__builtin_neon_vld2q_lane_v },
7845 { NEON::BI__builtin_neon_vld3_bf16, NEON::BI__builtin_neon_vld3_v },
7846 { NEON::BI__builtin_neon_vld3_dup_bf16, NEON::BI__builtin_neon_vld3_dup_v },
7847 { NEON::BI__builtin_neon_vld3_lane_bf16, NEON::BI__builtin_neon_vld3_lane_v },
7848 { NEON::BI__builtin_neon_vld3q_bf16, NEON::BI__builtin_neon_vld3q_v },
7849 { NEON::BI__builtin_neon_vld3q_dup_bf16, NEON::BI__builtin_neon_vld3q_dup_v },
7850 { NEON::BI__builtin_neon_vld3q_lane_bf16, NEON::BI__builtin_neon_vld3q_lane_v },
7851 { NEON::BI__builtin_neon_vld4_bf16, NEON::BI__builtin_neon_vld4_v },
7852 { NEON::BI__builtin_neon_vld4_dup_bf16, NEON::BI__builtin_neon_vld4_dup_v },
7853 { NEON::BI__builtin_neon_vld4_lane_bf16, NEON::BI__builtin_neon_vld4_lane_v },
7854 { NEON::BI__builtin_neon_vld4q_bf16, NEON::BI__builtin_neon_vld4q_v },
7855 { NEON::BI__builtin_neon_vld4q_dup_bf16, NEON::BI__builtin_neon_vld4q_dup_v },
7856 { NEON::BI__builtin_neon_vld4q_lane_bf16, NEON::BI__builtin_neon_vld4q_lane_v },
7857 { NEON::BI__builtin_neon_vmax_f16, NEON::BI__builtin_neon_vmax_v, },
7858 { NEON::BI__builtin_neon_vmaxnm_f16, NEON::BI__builtin_neon_vmaxnm_v, },
7859 { NEON::BI__builtin_neon_vmaxnmq_f16, NEON::BI__builtin_neon_vmaxnmq_v, },
7860 { NEON::BI__builtin_neon_vmaxq_f16, NEON::BI__builtin_neon_vmaxq_v, },
7861 { NEON::BI__builtin_neon_vmin_f16, NEON::BI__builtin_neon_vmin_v, },
7862 { NEON::BI__builtin_neon_vminnm_f16, NEON::BI__builtin_neon_vminnm_v, },
7863 { NEON::BI__builtin_neon_vminnmq_f16, NEON::BI__builtin_neon_vminnmq_v, },
7864 { NEON::BI__builtin_neon_vminq_f16, NEON::BI__builtin_neon_vminq_v, },
7865 { NEON::BI__builtin_neon_vmulx_f16, NEON::BI__builtin_neon_vmulx_v, },
7866 { NEON::BI__builtin_neon_vmulxq_f16, NEON::BI__builtin_neon_vmulxq_v, },
7867 { NEON::BI__builtin_neon_vpadd_f16, NEON::BI__builtin_neon_vpadd_v, },
7868 { NEON::BI__builtin_neon_vpaddq_f16, NEON::BI__builtin_neon_vpaddq_v, },
7869 { NEON::BI__builtin_neon_vpmax_f16, NEON::BI__builtin_neon_vpmax_v, },
7870 { NEON::BI__builtin_neon_vpmaxnm_f16, NEON::BI__builtin_neon_vpmaxnm_v, },
7871 { NEON::BI__builtin_neon_vpmaxnmq_f16, NEON::BI__builtin_neon_vpmaxnmq_v, },
7872 { NEON::BI__builtin_neon_vpmaxq_f16, NEON::BI__builtin_neon_vpmaxq_v, },
7873 { NEON::BI__builtin_neon_vpmin_f16, NEON::BI__builtin_neon_vpmin_v, },
7874 { NEON::BI__builtin_neon_vpminnm_f16, NEON::BI__builtin_neon_vpminnm_v, },
7875 { NEON::BI__builtin_neon_vpminnmq_f16, NEON::BI__builtin_neon_vpminnmq_v, },
7876 { NEON::BI__builtin_neon_vpminq_f16, NEON::BI__builtin_neon_vpminq_v, },
7877 { NEON::BI__builtin_neon_vrecpe_f16, NEON::BI__builtin_neon_vrecpe_v, },
7878 { NEON::BI__builtin_neon_vrecpeq_f16, NEON::BI__builtin_neon_vrecpeq_v, },
7879 { NEON::BI__builtin_neon_vrecps_f16, NEON::BI__builtin_neon_vrecps_v, },
7880 { NEON::BI__builtin_neon_vrecpsq_f16, NEON::BI__builtin_neon_vrecpsq_v, },
7881 { NEON::BI__builtin_neon_vrnd_f16, NEON::BI__builtin_neon_vrnd_v, },
7882 { NEON::BI__builtin_neon_vrnda_f16, NEON::BI__builtin_neon_vrnda_v, },
7883 { NEON::BI__builtin_neon_vrndaq_f16, NEON::BI__builtin_neon_vrndaq_v, },
7884 { NEON::BI__builtin_neon_vrndi_f16, NEON::BI__builtin_neon_vrndi_v, },
7885 { NEON::BI__builtin_neon_vrndiq_f16, NEON::BI__builtin_neon_vrndiq_v, },
7886 { NEON::BI__builtin_neon_vrndm_f16, NEON::BI__builtin_neon_vrndm_v, },
7887 { NEON::BI__builtin_neon_vrndmq_f16, NEON::BI__builtin_neon_vrndmq_v, },
7888 { NEON::BI__builtin_neon_vrndn_f16, NEON::BI__builtin_neon_vrndn_v, },
7889 { NEON::BI__builtin_neon_vrndnq_f16, NEON::BI__builtin_neon_vrndnq_v, },
7890 { NEON::BI__builtin_neon_vrndp_f16, NEON::BI__builtin_neon_vrndp_v, },
7891 { NEON::BI__builtin_neon_vrndpq_f16, NEON::BI__builtin_neon_vrndpq_v, },
7892 { NEON::BI__builtin_neon_vrndq_f16, NEON::BI__builtin_neon_vrndq_v, },
7893 { NEON::BI__builtin_neon_vrndx_f16, NEON::BI__builtin_neon_vrndx_v, },
7894 { NEON::BI__builtin_neon_vrndxq_f16, NEON::BI__builtin_neon_vrndxq_v, },
7895 { NEON::BI__builtin_neon_vrsqrte_f16, NEON::BI__builtin_neon_vrsqrte_v, },
7896 { NEON::BI__builtin_neon_vrsqrteq_f16, NEON::BI__builtin_neon_vrsqrteq_v, },
7897 { NEON::BI__builtin_neon_vrsqrts_f16, NEON::BI__builtin_neon_vrsqrts_v, },
7898 { NEON::BI__builtin_neon_vrsqrtsq_f16, NEON::BI__builtin_neon_vrsqrtsq_v, },
7899 { NEON::BI__builtin_neon_vsqrt_f16, NEON::BI__builtin_neon_vsqrt_v, },
7900 { NEON::BI__builtin_neon_vsqrtq_f16, NEON::BI__builtin_neon_vsqrtq_v, },
7901 { NEON::BI__builtin_neon_vst1_bf16_x2, NEON::BI__builtin_neon_vst1_x2_v },
7902 { NEON::BI__builtin_neon_vst1_bf16_x3, NEON::BI__builtin_neon_vst1_x3_v },
7903 { NEON::BI__builtin_neon_vst1_bf16_x4, NEON::BI__builtin_neon_vst1_x4_v },
7904 { NEON::BI__builtin_neon_vst1_bf16, NEON::BI__builtin_neon_vst1_v },
7905 { NEON::BI__builtin_neon_vst1_lane_bf16, NEON::BI__builtin_neon_vst1_lane_v },
7906 { NEON::BI__builtin_neon_vst1q_bf16_x2, NEON::BI__builtin_neon_vst1q_x2_v },
7907 { NEON::BI__builtin_neon_vst1q_bf16_x3, NEON::BI__builtin_neon_vst1q_x3_v },
7908 { NEON::BI__builtin_neon_vst1q_bf16_x4, NEON::BI__builtin_neon_vst1q_x4_v },
7909 { NEON::BI__builtin_neon_vst1q_bf16, NEON::BI__builtin_neon_vst1q_v },
7910 { NEON::BI__builtin_neon_vst1q_lane_bf16, NEON::BI__builtin_neon_vst1q_lane_v },
7911 { NEON::BI__builtin_neon_vst2_bf16, NEON::BI__builtin_neon_vst2_v },
7912 { NEON::BI__builtin_neon_vst2_lane_bf16, NEON::BI__builtin_neon_vst2_lane_v },
7913 { NEON::BI__builtin_neon_vst2q_bf16, NEON::BI__builtin_neon_vst2q_v },
7914 { NEON::BI__builtin_neon_vst2q_lane_bf16, NEON::BI__builtin_neon_vst2q_lane_v },
7915 { NEON::BI__builtin_neon_vst3_bf16, NEON::BI__builtin_neon_vst3_v },
7916 { NEON::BI__builtin_neon_vst3_lane_bf16, NEON::BI__builtin_neon_vst3_lane_v },
7917 { NEON::BI__builtin_neon_vst3q_bf16, NEON::BI__builtin_neon_vst3q_v },
7918 { NEON::BI__builtin_neon_vst3q_lane_bf16, NEON::BI__builtin_neon_vst3q_lane_v },
7919 { NEON::BI__builtin_neon_vst4_bf16, NEON::BI__builtin_neon_vst4_v },
7920 { NEON::BI__builtin_neon_vst4_lane_bf16, NEON::BI__builtin_neon_vst4_lane_v },
7921 { NEON::BI__builtin_neon_vst4q_bf16, NEON::BI__builtin_neon_vst4q_v },
7922 { NEON::BI__builtin_neon_vst4q_lane_bf16, NEON::BI__builtin_neon_vst4q_lane_v },
7926 { NEON::BI__builtin_neon_vldap1_lane_u64, NEON::BI__builtin_neon_vldap1_lane_s64 },
7927 { NEON::BI__builtin_neon_vldap1_lane_f64, NEON::BI__builtin_neon_vldap1_lane_s64 },
7928 { NEON::BI__builtin_neon_vldap1_lane_p64, NEON::BI__builtin_neon_vldap1_lane_s64 },
7929 { NEON::BI__builtin_neon_vldap1q_lane_u64, NEON::BI__builtin_neon_vldap1q_lane_s64 },
7930 { NEON::BI__builtin_neon_vldap1q_lane_f64, NEON::BI__builtin_neon_vldap1q_lane_s64 },
7931 { NEON::BI__builtin_neon_vldap1q_lane_p64, NEON::BI__builtin_neon_vldap1q_lane_s64 },
7932 { NEON::BI__builtin_neon_vstl1_lane_u64, NEON::BI__builtin_neon_vstl1_lane_s64 },
7933 { NEON::BI__builtin_neon_vstl1_lane_f64, NEON::BI__builtin_neon_vstl1_lane_s64 },
7934 { NEON::BI__builtin_neon_vstl1_lane_p64, NEON::BI__builtin_neon_vstl1_lane_s64 },
7935 { NEON::BI__builtin_neon_vstl1q_lane_u64, NEON::BI__builtin_neon_vstl1q_lane_s64 },
7936 { NEON::BI__builtin_neon_vstl1q_lane_f64, NEON::BI__builtin_neon_vstl1q_lane_s64 },
7937 { NEON::BI__builtin_neon_vstl1q_lane_p64, NEON::BI__builtin_neon_vstl1q_lane_s64 },
7944#define SVEMAP1(NameBase, LLVMIntrinsic, TypeModifier) \
7946 #NameBase, SVE::BI__builtin_sve_##NameBase, Intrinsic::LLVMIntrinsic, 0, \
7950#define SVEMAP2(NameBase, TypeModifier) \
7951 { #NameBase, SVE::BI__builtin_sve_##NameBase, 0, 0, TypeModifier }
7953#define GET_SVE_LLVM_INTRINSIC_MAP
7954#include "clang/Basic/arm_sve_builtin_cg.inc"
7955#include "clang/Basic/BuiltinsAArch64NeonSVEBridge_cg.def"
7956#undef GET_SVE_LLVM_INTRINSIC_MAP
7962#define SMEMAP1(NameBase, LLVMIntrinsic, TypeModifier) \
7964 #NameBase, SME::BI__builtin_sme_##NameBase, Intrinsic::LLVMIntrinsic, 0, \
7968#define SMEMAP2(NameBase, TypeModifier) \
7969 { #NameBase, SME::BI__builtin_sme_##NameBase, 0, 0, TypeModifier }
7971#define GET_SME_LLVM_INTRINSIC_MAP
7972#include "clang/Basic/arm_sme_builtin_cg.inc"
7973#undef GET_SME_LLVM_INTRINSIC_MAP
7986static const ARMVectorIntrinsicInfo *
7988 unsigned BuiltinID,
bool &MapProvenSorted) {
7991 if (!MapProvenSorted) {
7992 assert(llvm::is_sorted(IntrinsicMap));
7993 MapProvenSorted =
true;
7997 const ARMVectorIntrinsicInfo *Builtin =
7998 llvm::lower_bound(IntrinsicMap, BuiltinID);
8000 if (Builtin != IntrinsicMap.end() && Builtin->BuiltinID == BuiltinID)
8008 llvm::Type *ArgType,
8021 Ty = llvm::FixedVectorType::get(
8022 Ty, VectorSize ? VectorSize / Ty->getPrimitiveSizeInBits() : 1);
8029 int Elts = VectorSize ? VectorSize / ArgType->getPrimitiveSizeInBits() : 1;
8030 ArgType = llvm::FixedVectorType::get(ArgType, Elts);
8034 Tys.push_back(ArgType);
8037 Tys.push_back(ArgType);
8048 unsigned BuiltinID = SISDInfo.BuiltinID;
8049 unsigned int Int = SISDInfo.LLVMIntrinsic;
8050 unsigned Modifier = SISDInfo.TypeModifier;
8051 const char *
s = SISDInfo.NameHint;
8053 switch (BuiltinID) {
8054 case NEON::BI__builtin_neon_vcled_s64:
8055 case NEON::BI__builtin_neon_vcled_u64:
8056 case NEON::BI__builtin_neon_vcles_f32:
8057 case NEON::BI__builtin_neon_vcled_f64:
8058 case NEON::BI__builtin_neon_vcltd_s64:
8059 case NEON::BI__builtin_neon_vcltd_u64:
8060 case NEON::BI__builtin_neon_vclts_f32:
8061 case NEON::BI__builtin_neon_vcltd_f64:
8062 case NEON::BI__builtin_neon_vcales_f32:
8063 case NEON::BI__builtin_neon_vcaled_f64:
8064 case NEON::BI__builtin_neon_vcalts_f32:
8065 case NEON::BI__builtin_neon_vcaltd_f64:
8069 std::swap(Ops[0], Ops[1]);
8073 assert(Int &&
"Generic code assumes a valid intrinsic");
8076 const Expr *Arg =
E->getArg(0);
8081 ConstantInt *C0 = ConstantInt::get(CGF.
SizeTy, 0);
8082 for (Function::const_arg_iterator ai = F->arg_begin(), ae = F->arg_end();
8083 ai != ae; ++ai, ++j) {
8084 llvm::Type *ArgTy = ai->getType();
8085 if (Ops[j]->getType()->getPrimitiveSizeInBits() ==
8086 ArgTy->getPrimitiveSizeInBits())
8089 assert(ArgTy->isVectorTy() && !Ops[j]->getType()->isVectorTy());
8092 Ops[j] = CGF.
Builder.CreateTruncOrBitCast(
8093 Ops[j], cast<llvm::VectorType>(ArgTy)->getElementType());
8095 CGF.
Builder.CreateInsertElement(PoisonValue::get(ArgTy), Ops[j], C0);
8100 if (ResultType->getPrimitiveSizeInBits().getFixedValue() <
8101 Result->getType()->getPrimitiveSizeInBits().getFixedValue())
8108 unsigned BuiltinID,
unsigned LLVMIntrinsic,
unsigned AltLLVMIntrinsic,
8109 const char *NameHint,
unsigned Modifier,
const CallExpr *
E,
8111 llvm::Triple::ArchType Arch) {
8113 const Expr *Arg =
E->getArg(
E->getNumArgs() - 1);
8114 std::optional<llvm::APSInt> NeonTypeConst =
8121 bool Usgn =
Type.isUnsigned();
8122 bool Quad =
Type.isQuad();
8124 const bool AllowBFloatArgsAndRet =
8127 llvm::FixedVectorType *VTy =
8128 GetNeonType(
this,
Type, HasLegalHalfType,
false, AllowBFloatArgsAndRet);
8129 llvm::Type *Ty = VTy;
8133 auto getAlignmentValue32 = [&](
Address addr) ->
Value* {
8134 return Builder.getInt32(addr.getAlignment().getQuantity());
8137 unsigned Int = LLVMIntrinsic;
8139 Int = AltLLVMIntrinsic;
8141 switch (BuiltinID) {
8143 case NEON::BI__builtin_neon_splat_lane_v:
8144 case NEON::BI__builtin_neon_splat_laneq_v:
8145 case NEON::BI__builtin_neon_splatq_lane_v:
8146 case NEON::BI__builtin_neon_splatq_laneq_v: {
8147 auto NumElements = VTy->getElementCount();
8148 if (BuiltinID == NEON::BI__builtin_neon_splatq_lane_v)
8149 NumElements = NumElements * 2;
8150 if (BuiltinID == NEON::BI__builtin_neon_splat_laneq_v)
8151 NumElements = NumElements.divideCoefficientBy(2);
8153 Ops[0] =
Builder.CreateBitCast(Ops[0], VTy);
8154 return EmitNeonSplat(Ops[0], cast<ConstantInt>(Ops[1]), NumElements);
8156 case NEON::BI__builtin_neon_vpadd_v:
8157 case NEON::BI__builtin_neon_vpaddq_v:
8159 if (VTy->getElementType()->isFloatingPointTy() &&
8160 Int == Intrinsic::aarch64_neon_addp)
8161 Int = Intrinsic::aarch64_neon_faddp;
8163 case NEON::BI__builtin_neon_vabs_v:
8164 case NEON::BI__builtin_neon_vabsq_v:
8165 if (VTy->getElementType()->isFloatingPointTy())
8168 case NEON::BI__builtin_neon_vadd_v:
8169 case NEON::BI__builtin_neon_vaddq_v: {
8170 llvm::Type *VTy = llvm::FixedVectorType::get(
Int8Ty, Quad ? 16 : 8);
8171 Ops[0] =
Builder.CreateBitCast(Ops[0], VTy);
8172 Ops[1] =
Builder.CreateBitCast(Ops[1], VTy);
8173 Ops[0] =
Builder.CreateXor(Ops[0], Ops[1]);
8174 return Builder.CreateBitCast(Ops[0], Ty);
8176 case NEON::BI__builtin_neon_vaddhn_v: {
8177 llvm::FixedVectorType *SrcTy =
8178 llvm::FixedVectorType::getExtendedElementVectorType(VTy);
8181 Ops[0] =
Builder.CreateBitCast(Ops[0], SrcTy);
8182 Ops[1] =
Builder.CreateBitCast(Ops[1], SrcTy);
8183 Ops[0] =
Builder.CreateAdd(Ops[0], Ops[1],
"vaddhn");
8186 Constant *ShiftAmt =
8187 ConstantInt::get(SrcTy, SrcTy->getScalarSizeInBits() / 2);
8188 Ops[0] =
Builder.CreateLShr(Ops[0], ShiftAmt,
"vaddhn");
8191 return Builder.CreateTrunc(Ops[0], VTy,
"vaddhn");
8193 case NEON::BI__builtin_neon_vcale_v:
8194 case NEON::BI__builtin_neon_vcaleq_v:
8195 case NEON::BI__builtin_neon_vcalt_v:
8196 case NEON::BI__builtin_neon_vcaltq_v:
8197 std::swap(Ops[0], Ops[1]);
8199 case NEON::BI__builtin_neon_vcage_v:
8200 case NEON::BI__builtin_neon_vcageq_v:
8201 case NEON::BI__builtin_neon_vcagt_v:
8202 case NEON::BI__builtin_neon_vcagtq_v: {
8204 switch (VTy->getScalarSizeInBits()) {
8205 default: llvm_unreachable(
"unexpected type");
8216 auto *VecFlt = llvm::FixedVectorType::get(Ty, VTy->getNumElements());
8217 llvm::Type *Tys[] = { VTy, VecFlt };
8221 case NEON::BI__builtin_neon_vceqz_v:
8222 case NEON::BI__builtin_neon_vceqzq_v:
8224 ICmpInst::ICMP_EQ,
"vceqz");
8225 case NEON::BI__builtin_neon_vcgez_v:
8226 case NEON::BI__builtin_neon_vcgezq_v:
8228 ICmpInst::ICMP_SGE,
"vcgez");
8229 case NEON::BI__builtin_neon_vclez_v:
8230 case NEON::BI__builtin_neon_vclezq_v:
8232 ICmpInst::ICMP_SLE,
"vclez");
8233 case NEON::BI__builtin_neon_vcgtz_v:
8234 case NEON::BI__builtin_neon_vcgtzq_v:
8236 ICmpInst::ICMP_SGT,
"vcgtz");
8237 case NEON::BI__builtin_neon_vcltz_v:
8238 case NEON::BI__builtin_neon_vcltzq_v:
8240 ICmpInst::ICMP_SLT,
"vcltz");
8241 case NEON::BI__builtin_neon_vclz_v:
8242 case NEON::BI__builtin_neon_vclzq_v:
8247 case NEON::BI__builtin_neon_vcvt_f32_v:
8248 case NEON::BI__builtin_neon_vcvtq_f32_v:
8249 Ops[0] =
Builder.CreateBitCast(Ops[0], Ty);
8252 return Usgn ?
Builder.CreateUIToFP(Ops[0], Ty,
"vcvt")
8253 :
Builder.CreateSIToFP(Ops[0], Ty,
"vcvt");
8254 case NEON::BI__builtin_neon_vcvt_f16_s16:
8255 case NEON::BI__builtin_neon_vcvt_f16_u16:
8256 case NEON::BI__builtin_neon_vcvtq_f16_s16:
8257 case NEON::BI__builtin_neon_vcvtq_f16_u16:
8258 Ops[0] =
Builder.CreateBitCast(Ops[0], Ty);
8261 return Usgn ?
Builder.CreateUIToFP(Ops[0], Ty,
"vcvt")
8262 :
Builder.CreateSIToFP(Ops[0], Ty,
"vcvt");
8263 case NEON::BI__builtin_neon_vcvt_n_f16_s16:
8264 case NEON::BI__builtin_neon_vcvt_n_f16_u16:
8265 case NEON::BI__builtin_neon_vcvtq_n_f16_s16:
8266 case NEON::BI__builtin_neon_vcvtq_n_f16_u16: {
8271 case NEON::BI__builtin_neon_vcvt_n_f32_v:
8272 case NEON::BI__builtin_neon_vcvt_n_f64_v:
8273 case NEON::BI__builtin_neon_vcvtq_n_f32_v:
8274 case NEON::BI__builtin_neon_vcvtq_n_f64_v: {
8276 Int = Usgn ? LLVMIntrinsic : AltLLVMIntrinsic;
8280 case NEON::BI__builtin_neon_vcvt_n_s16_f16:
8281 case NEON::BI__builtin_neon_vcvt_n_s32_v:
8282 case NEON::BI__builtin_neon_vcvt_n_u16_f16:
8283 case NEON::BI__builtin_neon_vcvt_n_u32_v:
8284 case NEON::BI__builtin_neon_vcvt_n_s64_v:
8285 case NEON::BI__builtin_neon_vcvt_n_u64_v:
8286 case NEON::BI__builtin_neon_vcvtq_n_s16_f16:
8287 case NEON::BI__builtin_neon_vcvtq_n_s32_v:
8288 case NEON::BI__builtin_neon_vcvtq_n_u16_f16:
8289 case NEON::BI__builtin_neon_vcvtq_n_u32_v:
8290 case NEON::BI__builtin_neon_vcvtq_n_s64_v:
8291 case NEON::BI__builtin_neon_vcvtq_n_u64_v: {
8296 case NEON::BI__builtin_neon_vcvt_s32_v:
8297 case NEON::BI__builtin_neon_vcvt_u32_v:
8298 case NEON::BI__builtin_neon_vcvt_s64_v:
8299 case NEON::BI__builtin_neon_vcvt_u64_v:
8300 case NEON::BI__builtin_neon_vcvt_s16_f16:
8301 case NEON::BI__builtin_neon_vcvt_u16_f16:
8302 case NEON::BI__builtin_neon_vcvtq_s32_v:
8303 case NEON::BI__builtin_neon_vcvtq_u32_v:
8304 case NEON::BI__builtin_neon_vcvtq_s64_v:
8305 case NEON::BI__builtin_neon_vcvtq_u64_v:
8306 case NEON::BI__builtin_neon_vcvtq_s16_f16:
8307 case NEON::BI__builtin_neon_vcvtq_u16_f16: {
8309 return Usgn ?
Builder.CreateFPToUI(Ops[0], Ty,
"vcvt")
8310 :
Builder.CreateFPToSI(Ops[0], Ty,
"vcvt");
8312 case NEON::BI__builtin_neon_vcvta_s16_f16:
8313 case NEON::BI__builtin_neon_vcvta_s32_v:
8314 case NEON::BI__builtin_neon_vcvta_s64_v:
8315 case NEON::BI__builtin_neon_vcvta_u16_f16:
8316 case NEON::BI__builtin_neon_vcvta_u32_v:
8317 case NEON::BI__builtin_neon_vcvta_u64_v:
8318 case NEON::BI__builtin_neon_vcvtaq_s16_f16:
8319 case NEON::BI__builtin_neon_vcvtaq_s32_v:
8320 case NEON::BI__builtin_neon_vcvtaq_s64_v:
8321 case NEON::BI__builtin_neon_vcvtaq_u16_f16:
8322 case NEON::BI__builtin_neon_vcvtaq_u32_v:
8323 case NEON::BI__builtin_neon_vcvtaq_u64_v:
8324 case NEON::BI__builtin_neon_vcvtn_s16_f16:
8325 case NEON::BI__builtin_neon_vcvtn_s32_v:
8326 case NEON::BI__builtin_neon_vcvtn_s64_v:
8327 case NEON::BI__builtin_neon_vcvtn_u16_f16:
8328 case NEON::BI__builtin_neon_vcvtn_u32_v:
8329 case NEON::BI__builtin_neon_vcvtn_u64_v:
8330 case NEON::BI__builtin_neon_vcvtnq_s16_f16:
8331 case NEON::BI__builtin_neon_vcvtnq_s32_v:
8332 case NEON::BI__builtin_neon_vcvtnq_s64_v:
8333 case NEON::BI__builtin_neon_vcvtnq_u16_f16:
8334 case NEON::BI__builtin_neon_vcvtnq_u32_v:
8335 case NEON::BI__builtin_neon_vcvtnq_u64_v:
8336 case NEON::BI__builtin_neon_vcvtp_s16_f16:
8337 case NEON::BI__builtin_neon_vcvtp_s32_v:
8338 case NEON::BI__builtin_neon_vcvtp_s64_v:
8339 case NEON::BI__builtin_neon_vcvtp_u16_f16:
8340 case NEON::BI__builtin_neon_vcvtp_u32_v:
8341 case NEON::BI__builtin_neon_vcvtp_u64_v:
8342 case NEON::BI__builtin_neon_vcvtpq_s16_f16:
8343 case NEON::BI__builtin_neon_vcvtpq_s32_v:
8344 case NEON::BI__builtin_neon_vcvtpq_s64_v:
8345 case NEON::BI__builtin_neon_vcvtpq_u16_f16:
8346 case NEON::BI__builtin_neon_vcvtpq_u32_v:
8347 case NEON::BI__builtin_neon_vcvtpq_u64_v:
8348 case NEON::BI__builtin_neon_vcvtm_s16_f16:
8349 case NEON::BI__builtin_neon_vcvtm_s32_v:
8350 case NEON::BI__builtin_neon_vcvtm_s64_v:
8351 case NEON::BI__builtin_neon_vcvtm_u16_f16:
8352 case NEON::BI__builtin_neon_vcvtm_u32_v:
8353 case NEON::BI__builtin_neon_vcvtm_u64_v:
8354 case NEON::BI__builtin_neon_vcvtmq_s16_f16:
8355 case NEON::BI__builtin_neon_vcvtmq_s32_v:
8356 case NEON::BI__builtin_neon_vcvtmq_s64_v:
8357 case NEON::BI__builtin_neon_vcvtmq_u16_f16:
8358 case NEON::BI__builtin_neon_vcvtmq_u32_v:
8359 case NEON::BI__builtin_neon_vcvtmq_u64_v: {
8363 case NEON::BI__builtin_neon_vcvtx_f32_v: {
8364 llvm::Type *Tys[2] = { VTy->getTruncatedElementVectorType(VTy), Ty};
8368 case NEON::BI__builtin_neon_vext_v:
8369 case NEON::BI__builtin_neon_vextq_v: {
8370 int CV = cast<ConstantInt>(Ops[2])->getSExtValue();
8372 for (
unsigned i = 0, e = VTy->getNumElements(); i != e; ++i)
8373 Indices.push_back(i+CV);
8375 Ops[0] =
Builder.CreateBitCast(Ops[0], Ty);
8376 Ops[1] =
Builder.CreateBitCast(Ops[1], Ty);
8377 return Builder.CreateShuffleVector(Ops[0], Ops[1], Indices,
"vext");
8379 case NEON::BI__builtin_neon_vfma_v:
8380 case NEON::BI__builtin_neon_vfmaq_v: {
8381 Ops[0] =
Builder.CreateBitCast(Ops[0], Ty);
8382 Ops[1] =
Builder.CreateBitCast(Ops[1], Ty);
8383 Ops[2] =
Builder.CreateBitCast(Ops[2], Ty);
8387 *
this, Intrinsic::fma, Intrinsic::experimental_constrained_fma, Ty,
8388 {Ops[1], Ops[2], Ops[0]});
8390 case NEON::BI__builtin_neon_vld1_v:
8391 case NEON::BI__builtin_neon_vld1q_v: {
8393 Ops.push_back(getAlignmentValue32(PtrOp0));
8396 case NEON::BI__builtin_neon_vld1_x2_v:
8397 case NEON::BI__builtin_neon_vld1q_x2_v:
8398 case NEON::BI__builtin_neon_vld1_x3_v:
8399 case NEON::BI__builtin_neon_vld1q_x3_v:
8400 case NEON::BI__builtin_neon_vld1_x4_v:
8401 case NEON::BI__builtin_neon_vld1q_x4_v: {
8404 Ops[1] =
Builder.CreateCall(F, Ops[1],
"vld1xN");
8407 case NEON::BI__builtin_neon_vld2_v:
8408 case NEON::BI__builtin_neon_vld2q_v:
8409 case NEON::BI__builtin_neon_vld3_v:
8410 case NEON::BI__builtin_neon_vld3q_v:
8411 case NEON::BI__builtin_neon_vld4_v:
8412 case NEON::BI__builtin_neon_vld4q_v:
8413 case NEON::BI__builtin_neon_vld2_dup_v:
8414 case NEON::BI__builtin_neon_vld2q_dup_v:
8415 case NEON::BI__builtin_neon_vld3_dup_v:
8416 case NEON::BI__builtin_neon_vld3q_dup_v:
8417 case NEON::BI__builtin_neon_vld4_dup_v:
8418 case NEON::BI__builtin_neon_vld4q_dup_v: {
8421 Value *Align = getAlignmentValue32(PtrOp1);
8422 Ops[1] =
Builder.CreateCall(F, {Ops[1], Align}, NameHint);
8425 case NEON::BI__builtin_neon_vld1_dup_v:
8426 case NEON::BI__builtin_neon_vld1q_dup_v: {
8427 Value *
V = PoisonValue::get(Ty);
8430 llvm::Constant *CI = ConstantInt::get(
SizeTy, 0);
8431 Ops[0] =
Builder.CreateInsertElement(
V, Ld, CI);
8434 case NEON::BI__builtin_neon_vld2_lane_v:
8435 case NEON::BI__builtin_neon_vld2q_lane_v:
8436 case NEON::BI__builtin_neon_vld3_lane_v:
8437 case NEON::BI__builtin_neon_vld3q_lane_v:
8438 case NEON::BI__builtin_neon_vld4_lane_v:
8439 case NEON::BI__builtin_neon_vld4q_lane_v: {
8442 for (
unsigned I = 2; I < Ops.size() - 1; ++I)
8443 Ops[I] =
Builder.CreateBitCast(Ops[I], Ty);
8444 Ops.push_back(getAlignmentValue32(PtrOp1));
8448 case NEON::BI__builtin_neon_vmovl_v: {
8449 llvm::FixedVectorType *DTy =
8450 llvm::FixedVectorType::getTruncatedElementVectorType(VTy);
8451 Ops[0] =
Builder.CreateBitCast(Ops[0], DTy);
8453 return Builder.CreateZExt(Ops[0], Ty,
"vmovl");
8454 return Builder.CreateSExt(Ops[0], Ty,
"vmovl");
8456 case NEON::BI__builtin_neon_vmovn_v: {
8457 llvm::FixedVectorType *QTy =
8458 llvm::FixedVectorType::getExtendedElementVectorType(VTy);
8459 Ops[0] =
Builder.CreateBitCast(Ops[0], QTy);
8460 return Builder.CreateTrunc(Ops[0], Ty,
"vmovn");
8462 case NEON::BI__builtin_neon_vmull_v:
8468 Int = Usgn ? Intrinsic::arm_neon_vmullu : Intrinsic::arm_neon_vmulls;
8471 case NEON::BI__builtin_neon_vpadal_v:
8472 case NEON::BI__builtin_neon_vpadalq_v: {
8474 unsigned EltBits = VTy->getElementType()->getPrimitiveSizeInBits();
8478 llvm::FixedVectorType::get(EltTy, VTy->getNumElements() * 2);
8479 llvm::Type *Tys[2] = { Ty, NarrowTy };
8482 case NEON::BI__builtin_neon_vpaddl_v:
8483 case NEON::BI__builtin_neon_vpaddlq_v: {
8485 unsigned EltBits = VTy->getElementType()->getPrimitiveSizeInBits();
8486 llvm::Type *EltTy = llvm::IntegerType::get(
getLLVMContext(), EltBits / 2);
8488 llvm::FixedVectorType::get(EltTy, VTy->getNumElements() * 2);
8489 llvm::Type *Tys[2] = { Ty, NarrowTy };
8492 case NEON::BI__builtin_neon_vqdmlal_v:
8493 case NEON::BI__builtin_neon_vqdmlsl_v: {
8500 case NEON::BI__builtin_neon_vqdmulhq_lane_v:
8501 case NEON::BI__builtin_neon_vqdmulh_lane_v:
8502 case NEON::BI__builtin_neon_vqrdmulhq_lane_v:
8503 case NEON::BI__builtin_neon_vqrdmulh_lane_v: {
8504 auto *RTy = cast<llvm::FixedVectorType>(Ty);
8505 if (BuiltinID == NEON::BI__builtin_neon_vqdmulhq_lane_v ||
8506 BuiltinID == NEON::BI__builtin_neon_vqrdmulhq_lane_v)
8507 RTy = llvm::FixedVectorType::get(RTy->getElementType(),
8508 RTy->getNumElements() * 2);
8509 llvm::Type *Tys[2] = {
8514 case NEON::BI__builtin_neon_vqdmulhq_laneq_v:
8515 case NEON::BI__builtin_neon_vqdmulh_laneq_v:
8516 case NEON::BI__builtin_neon_vqrdmulhq_laneq_v:
8517 case NEON::BI__builtin_neon_vqrdmulh_laneq_v: {
8518 llvm::Type *Tys[2] = {
8523 case NEON::BI__builtin_neon_vqshl_n_v:
8524 case NEON::BI__builtin_neon_vqshlq_n_v:
8527 case NEON::BI__builtin_neon_vqshlu_n_v:
8528 case NEON::BI__builtin_neon_vqshluq_n_v:
8531 case NEON::BI__builtin_neon_vrecpe_v:
8532 case NEON::BI__builtin_neon_vrecpeq_v:
8533 case NEON::BI__builtin_neon_vrsqrte_v:
8534 case NEON::BI__builtin_neon_vrsqrteq_v:
8535 Int = Ty->isFPOrFPVectorTy() ? LLVMIntrinsic : AltLLVMIntrinsic;
8537 case NEON::BI__builtin_neon_vrndi_v:
8538 case NEON::BI__builtin_neon_vrndiq_v:
8540 ? Intrinsic::experimental_constrained_nearbyint
8541 : Intrinsic::nearbyint;
8543 case NEON::BI__builtin_neon_vrshr_n_v:
8544 case NEON::BI__builtin_neon_vrshrq_n_v:
8547 case NEON::BI__builtin_neon_vsha512hq_u64:
8548 case NEON::BI__builtin_neon_vsha512h2q_u64:
8549 case NEON::BI__builtin_neon_vsha512su0q_u64:
8550 case NEON::BI__builtin_neon_vsha512su1q_u64: {
8554 case NEON::BI__builtin_neon_vshl_n_v:
8555 case NEON::BI__builtin_neon_vshlq_n_v:
8557 return Builder.CreateShl(
Builder.CreateBitCast(Ops[0],Ty), Ops[1],
8559 case NEON::BI__builtin_neon_vshll_n_v: {
8560 llvm::FixedVectorType *SrcTy =
8561 llvm::FixedVectorType::getTruncatedElementVectorType(VTy);
8562 Ops[0] =
Builder.CreateBitCast(Ops[0], SrcTy);
8564 Ops[0] =
Builder.CreateZExt(Ops[0], VTy);
8566 Ops[0] =
Builder.CreateSExt(Ops[0], VTy);
8568 return Builder.CreateShl(Ops[0], Ops[1],
"vshll_n");
8570 case NEON::BI__builtin_neon_vshrn_n_v: {
8571 llvm::FixedVectorType *SrcTy =
8572 llvm::FixedVectorType::getExtendedElementVectorType(VTy);
8573 Ops[0] =
Builder.CreateBitCast(Ops[0], SrcTy);
8576 Ops[0] =
Builder.CreateLShr(Ops[0], Ops[1]);
8578 Ops[0] =
Builder.CreateAShr(Ops[0], Ops[1]);
8579 return Builder.CreateTrunc(Ops[0], Ty,
"vshrn_n");
8581 case NEON::BI__builtin_neon_vshr_n_v:
8582 case NEON::BI__builtin_neon_vshrq_n_v:
8584 case NEON::BI__builtin_neon_vst1_v:
8585 case NEON::BI__builtin_neon_vst1q_v:
8586 case NEON::BI__builtin_neon_vst2_v:
8587 case NEON::BI__builtin_neon_vst2q_v:
8588 case NEON::BI__builtin_neon_vst3_v:
8589 case NEON::BI__builtin_neon_vst3q_v:
8590 case NEON::BI__builtin_neon_vst4_v:
8591 case NEON::BI__builtin_neon_vst4q_v:
8592 case NEON::BI__builtin_neon_vst2_lane_v:
8593 case NEON::BI__builtin_neon_vst2q_lane_v:
8594 case NEON::BI__builtin_neon_vst3_lane_v:
8595 case NEON::BI__builtin_neon_vst3q_lane_v:
8596 case NEON::BI__builtin_neon_vst4_lane_v:
8597 case NEON::BI__builtin_neon_vst4q_lane_v: {
8599 Ops.push_back(getAlignmentValue32(PtrOp0));
8602 case NEON::BI__builtin_neon_vsm3partw1q_u32:
8603 case NEON::BI__builtin_neon_vsm3partw2q_u32:
8604 case NEON::BI__builtin_neon_vsm3ss1q_u32:
8605 case NEON::BI__builtin_neon_vsm4ekeyq_u32:
8606 case NEON::BI__builtin_neon_vsm4eq_u32: {
8610 case NEON::BI__builtin_neon_vsm3tt1aq_u32:
8611 case NEON::BI__builtin_neon_vsm3tt1bq_u32:
8612 case NEON::BI__builtin_neon_vsm3tt2aq_u32:
8613 case NEON::BI__builtin_neon_vsm3tt2bq_u32: {
8618 case NEON::BI__builtin_neon_vst1_x2_v:
8619 case NEON::BI__builtin_neon_vst1q_x2_v:
8620 case NEON::BI__builtin_neon_vst1_x3_v:
8621 case NEON::BI__builtin_neon_vst1q_x3_v:
8622 case NEON::BI__builtin_neon_vst1_x4_v:
8623 case NEON::BI__builtin_neon_vst1q_x4_v: {
8626 if (Arch == llvm::Triple::aarch64 || Arch == llvm::Triple::aarch64_be ||
8627 Arch == llvm::Triple::aarch64_32) {
8629 std::rotate(Ops.begin(), Ops.begin() + 1, Ops.end());
8635 case NEON::BI__builtin_neon_vsubhn_v: {
8636 llvm::FixedVectorType *SrcTy =
8637 llvm::FixedVectorType::getExtendedElementVectorType(VTy);
8640 Ops[0] =
Builder.CreateBitCast(Ops[0], SrcTy);
8641 Ops[1] =
Builder.CreateBitCast(Ops[1], SrcTy);
8642 Ops[0] =
Builder.CreateSub(Ops[0], Ops[1],
"vsubhn");
8645 Constant *ShiftAmt =
8646 ConstantInt::get(SrcTy, SrcTy->getScalarSizeInBits() / 2);
8647 Ops[0] =
Builder.CreateLShr(Ops[0], ShiftAmt,
"vsubhn");
8650 return Builder.CreateTrunc(Ops[0], VTy,
"vsubhn");
8652 case NEON::BI__builtin_neon_vtrn_v:
8653 case NEON::BI__builtin_neon_vtrnq_v: {
8654 Ops[1] =
Builder.CreateBitCast(Ops[1], Ty);
8655 Ops[2] =
Builder.CreateBitCast(Ops[2], Ty);
8656 Value *SV =
nullptr;
8658 for (
unsigned vi = 0; vi != 2; ++vi) {
8660 for (
unsigned i = 0, e = VTy->getNumElements(); i != e; i += 2) {
8661 Indices.push_back(i+vi);
8662 Indices.push_back(i+e+vi);
8664 Value *Addr =
Builder.CreateConstInBoundsGEP1_32(Ty, Ops[0], vi);
8665 SV =
Builder.CreateShuffleVector(Ops[1], Ops[2], Indices,
"vtrn");
8670 case NEON::BI__builtin_neon_vtst_v:
8671 case NEON::BI__builtin_neon_vtstq_v: {
8672 Ops[0] =
Builder.CreateBitCast(Ops[0], Ty);
8673 Ops[1] =
Builder.CreateBitCast(Ops[1], Ty);
8674 Ops[0] =
Builder.CreateAnd(Ops[0], Ops[1]);
8675 Ops[0] =
Builder.CreateICmp(ICmpInst::ICMP_NE, Ops[0],
8676 ConstantAggregateZero::get(Ty));
8677 return Builder.CreateSExt(Ops[0], Ty,
"vtst");
8679 case NEON::BI__builtin_neon_vuzp_v:
8680 case NEON::BI__builtin_neon_vuzpq_v: {
8681 Ops[1] =
Builder.CreateBitCast(Ops[1], Ty);
8682 Ops[2] =
Builder.CreateBitCast(Ops[2], Ty);
8683 Value *SV =
nullptr;
8685 for (
unsigned vi = 0; vi != 2; ++vi) {
8687 for (
unsigned i = 0, e = VTy->getNumElements(); i != e; ++i)
8688 Indices.push_back(2*i+vi);
8690 Value *Addr =
Builder.CreateConstInBoundsGEP1_32(Ty, Ops[0], vi);
8691 SV =
Builder.CreateShuffleVector(Ops[1], Ops[2], Indices,
"vuzp");
8696 case NEON::BI__builtin_neon_vxarq_u64: {
8701 case NEON::BI__builtin_neon_vzip_v:
8702 case NEON::BI__builtin_neon_vzipq_v: {
8703 Ops[1] =
Builder.CreateBitCast(Ops[1], Ty);
8704 Ops[2] =
Builder.CreateBitCast(Ops[2], Ty);
8705 Value *SV =
nullptr;
8707 for (
unsigned vi = 0; vi != 2; ++vi) {
8709 for (
unsigned i = 0, e = VTy->getNumElements(); i != e; i += 2) {
8710 Indices.push_back((i + vi*e) >> 1);
8711 Indices.push_back(((i + vi*e) >> 1)+e);
8713 Value *Addr =
Builder.CreateConstInBoundsGEP1_32(Ty, Ops[0], vi);
8714 SV =
Builder.CreateShuffleVector(Ops[1], Ops[2], Indices,
"vzip");
8719 case NEON::BI__builtin_neon_vdot_s32:
8720 case NEON::BI__builtin_neon_vdot_u32:
8721 case NEON::BI__builtin_neon_vdotq_s32:
8722 case NEON::BI__builtin_neon_vdotq_u32: {
8724 llvm::FixedVectorType::get(
Int8Ty, Ty->getPrimitiveSizeInBits() / 8);
8725 llvm::Type *Tys[2] = { Ty, InputTy };
8728 case NEON::BI__builtin_neon_vfmlal_low_f16:
8729 case NEON::BI__builtin_neon_vfmlalq_low_f16: {
8731 llvm::FixedVectorType::get(
HalfTy, Ty->getPrimitiveSizeInBits() / 16);
8732 llvm::Type *Tys[2] = { Ty, InputTy };
8735 case NEON::BI__builtin_neon_vfmlsl_low_f16:
8736 case NEON::BI__builtin_neon_vfmlslq_low_f16: {
8738 llvm::FixedVectorType::get(
HalfTy, Ty->getPrimitiveSizeInBits() / 16);
8739 llvm::Type *Tys[2] = { Ty, InputTy };
8742 case NEON::BI__builtin_neon_vfmlal_high_f16:
8743 case NEON::BI__builtin_neon_vfmlalq_high_f16: {
8745 llvm::FixedVectorType::get(
HalfTy, Ty->getPrimitiveSizeInBits() / 16);
8746 llvm::Type *Tys[2] = { Ty, InputTy };
8749 case NEON::BI__builtin_neon_vfmlsl_high_f16:
8750 case NEON::BI__builtin_neon_vfmlslq_high_f16: {
8752 llvm::FixedVectorType::get(
HalfTy, Ty->getPrimitiveSizeInBits() / 16);
8753 llvm::Type *Tys[2] = { Ty, InputTy };
8756 case NEON::BI__builtin_neon_vmmlaq_s32:
8757 case NEON::BI__builtin_neon_vmmlaq_u32: {
8759 llvm::FixedVectorType::get(
Int8Ty, Ty->getPrimitiveSizeInBits() / 8);
8760 llvm::Type *Tys[2] = { Ty, InputTy };
8763 case NEON::BI__builtin_neon_vusmmlaq_s32: {
8765 llvm::FixedVectorType::get(
Int8Ty, Ty->getPrimitiveSizeInBits() / 8);
8766 llvm::Type *Tys[2] = { Ty, InputTy };
8769 case NEON::BI__builtin_neon_vusdot_s32:
8770 case NEON::BI__builtin_neon_vusdotq_s32: {
8772 llvm::FixedVectorType::get(
Int8Ty, Ty->getPrimitiveSizeInBits() / 8);
8773 llvm::Type *Tys[2] = { Ty, InputTy };
8776 case NEON::BI__builtin_neon_vbfdot_f32:
8777 case NEON::BI__builtin_neon_vbfdotq_f32: {
8778 llvm::Type *InputTy =
8779 llvm::FixedVectorType::get(
BFloatTy, Ty->getPrimitiveSizeInBits() / 16);
8780 llvm::Type *Tys[2] = { Ty, InputTy };
8783 case NEON::BI__builtin_neon___a32_vcvt_bf16_f32: {
8784 llvm::Type *Tys[1] = { Ty };
8791 assert(Int &&
"Expected valid intrinsic number");
8804 Value *Op, llvm::Type *Ty,
const CmpInst::Predicate Fp,
8805 const CmpInst::Predicate Ip,
const Twine &Name) {
8806 llvm::Type *OTy = Op->
getType();
8812 if (BitCastInst *BI = dyn_cast<BitCastInst>(Op))
8813 OTy = BI->getOperand(0)->getType();
8815 Op =
Builder.CreateBitCast(Op, OTy);
8816 if (OTy->getScalarType()->isFloatingPointTy()) {
8817 if (Fp == CmpInst::FCMP_OEQ)
8818 Op =
Builder.CreateFCmp(Fp, Op, Constant::getNullValue(OTy));
8820 Op =
Builder.CreateFCmpS(Fp, Op, Constant::getNullValue(OTy));
8822 Op =
Builder.CreateICmp(Ip, Op, Constant::getNullValue(OTy));
8824 return Builder.CreateSExt(Op, Ty, Name);
8829 llvm::Type *ResTy,
unsigned IntID,
8833 TblOps.push_back(ExtOp);
8837 auto *TblTy = cast<llvm::FixedVectorType>(Ops[0]->getType());
8838 for (
unsigned i = 0, e = TblTy->getNumElements(); i != e; ++i) {
8839 Indices.push_back(2*i);
8840 Indices.push_back(2*i+1);
8843 int PairPos = 0, End = Ops.size() - 1;
8844 while (PairPos < End) {
8845 TblOps.push_back(CGF.
Builder.CreateShuffleVector(Ops[PairPos],
8846 Ops[PairPos+1], Indices,
8853 if (PairPos == End) {
8854 Value *ZeroTbl = ConstantAggregateZero::get(TblTy);
8855 TblOps.push_back(CGF.
Builder.CreateShuffleVector(Ops[PairPos],
8856 ZeroTbl, Indices, Name));
8860 TblOps.push_back(IndexOp);
8866Value *CodeGenFunction::GetValueForARMHint(
unsigned BuiltinID) {
8868 switch (BuiltinID) {
8871 case clang::ARM::BI__builtin_arm_nop:
8874 case clang::ARM::BI__builtin_arm_yield:
8875 case clang::ARM::BI__yield:
8878 case clang::ARM::BI__builtin_arm_wfe:
8879 case clang::ARM::BI__wfe:
8882 case clang::ARM::BI__builtin_arm_wfi:
8883 case clang::ARM::BI__wfi:
8886 case clang::ARM::BI__builtin_arm_sev:
8887 case clang::ARM::BI__sev:
8890 case clang::ARM::BI__builtin_arm_sevl:
8891 case clang::ARM::BI__sevl:
8910 llvm::Type *ValueType,
bool isExecHi) {
8915 llvm::Value *
Call = Builder.CreateCall(F, {Builder.getInt1(
true)});
8918 Value *Rt2 = Builder.CreateLShr(
Call, 32);
8919 Rt2 = Builder.CreateTrunc(Rt2, CGF.
Int32Ty);
8932 llvm::Type *ValueType,
8934 StringRef SysReg =
"") {
8938 "Unsupported size for register.");
8944 if (SysReg.empty()) {
8946 SysReg = cast<clang::StringLiteral>(SysRegStrExpr)->getString();
8949 llvm::Metadata *Ops[] = { llvm::MDString::get(Context, SysReg) };
8950 llvm::MDNode *RegName = llvm::MDNode::get(Context, Ops);
8951 llvm::Value *Metadata = llvm::MetadataAsValue::get(Context, RegName);
8955 bool MixedTypes =
RegisterType->isIntegerTy(64) && ValueType->isIntegerTy(32);
8956 assert(!(
RegisterType->isIntegerTy(32) && ValueType->isIntegerTy(64))
8957 &&
"Can't fit 64-bit value in 32-bit register");
8959 if (AccessKind !=
Write) {
8962 AccessKind ==
VolatileRead ? llvm::Intrinsic::read_volatile_register
8963 : llvm::Intrinsic::read_register,
8965 llvm::Value *
Call = Builder.CreateCall(F, Metadata);
8969 return Builder.CreateTrunc(
Call, ValueType);
8971 if (ValueType->isPointerTy())
8973 return Builder.CreateIntToPtr(
Call, ValueType);
8978 llvm::Function *F = CGM.
getIntrinsic(llvm::Intrinsic::write_register, Types);
8983 return Builder.CreateCall(F, { Metadata, ArgValue });
8986 if (ValueType->isPointerTy()) {
8988 ArgValue = Builder.CreatePtrToInt(ArgValue,
RegisterType);
8989 return Builder.CreateCall(F, { Metadata, ArgValue });
8992 return Builder.CreateCall(F, { Metadata, ArgValue });
8998 switch (BuiltinID) {
9000 case NEON::BI__builtin_neon_vget_lane_i8:
9001 case NEON::BI__builtin_neon_vget_lane_i16:
9002 case NEON::BI__builtin_neon_vget_lane_bf16:
9003 case NEON::BI__builtin_neon_vget_lane_i32:
9004 case NEON::BI__builtin_neon_vget_lane_i64:
9005 case NEON::BI__builtin_neon_vget_lane_f32:
9006 case NEON::BI__builtin_neon_vgetq_lane_i8:
9007 case NEON::BI__builtin_neon_vgetq_lane_i16:
9008 case NEON::BI__builtin_neon_vgetq_lane_bf16:
9009 case NEON::BI__builtin_neon_vgetq_lane_i32:
9010 case NEON::BI__builtin_neon_vgetq_lane_i64:
9011 case NEON::BI__builtin_neon_vgetq_lane_f32:
9012 case NEON::BI__builtin_neon_vduph_lane_bf16:
9013 case NEON::BI__builtin_neon_vduph_laneq_bf16:
9014 case NEON::BI__builtin_neon_vset_lane_i8:
9015 case NEON::BI__builtin_neon_vset_lane_i16:
9016 case NEON::BI__builtin_neon_vset_lane_bf16:
9017 case NEON::BI__builtin_neon_vset_lane_i32:
9018 case NEON::BI__builtin_neon_vset_lane_i64:
9019 case NEON::BI__builtin_neon_vset_lane_f32:
9020 case NEON::BI__builtin_neon_vsetq_lane_i8:
9021 case NEON::BI__builtin_neon_vsetq_lane_i16:
9022 case NEON::BI__builtin_neon_vsetq_lane_bf16:
9023 case NEON::BI__builtin_neon_vsetq_lane_i32:
9024 case NEON::BI__builtin_neon_vsetq_lane_i64:
9025 case NEON::BI__builtin_neon_vsetq_lane_f32:
9026 case NEON::BI__builtin_neon_vsha1h_u32:
9027 case NEON::BI__builtin_neon_vsha1cq_u32:
9028 case NEON::BI__builtin_neon_vsha1pq_u32:
9029 case NEON::BI__builtin_neon_vsha1mq_u32:
9030 case NEON::BI__builtin_neon_vcvth_bf16_f32:
9031 case clang::ARM::BI_MoveToCoprocessor:
9032 case clang::ARM::BI_MoveToCoprocessor2:
9041 llvm::Triple::ArchType Arch) {
9042 if (
auto Hint = GetValueForARMHint(BuiltinID))
9045 if (BuiltinID == clang::ARM::BI__emit) {
9047 llvm::FunctionType *FTy =
9048 llvm::FunctionType::get(
VoidTy,
false);
9052 llvm_unreachable(
"Sema will ensure that the parameter is constant");
9055 uint64_t ZExtValue =
Value.zextOrTrunc(IsThumb ? 16 : 32).getZExtValue();
9057 llvm::InlineAsm *Emit =
9058 IsThumb ? InlineAsm::get(FTy,
".inst.n 0x" + utohexstr(ZExtValue),
"",
9060 : InlineAsm::get(FTy,
".inst 0x" + utohexstr(ZExtValue),
"",
9063 return Builder.CreateCall(Emit);
9066 if (BuiltinID == clang::ARM::BI__builtin_arm_dbg) {
9071 if (BuiltinID == clang::ARM::BI__builtin_arm_prefetch) {
9083 if (BuiltinID == clang::ARM::BI__builtin_arm_rbit) {
9086 CGM.
getIntrinsic(Intrinsic::bitreverse, Arg->getType()), Arg,
"rbit");
9089 if (BuiltinID == clang::ARM::BI__builtin_arm_clz ||
9090 BuiltinID == clang::ARM::BI__builtin_arm_clz64) {
9094 if (BuiltinID == clang::ARM::BI__builtin_arm_clz64)
9100 if (BuiltinID == clang::ARM::BI__builtin_arm_cls) {
9104 if (BuiltinID == clang::ARM::BI__builtin_arm_cls64) {
9110 if (BuiltinID == clang::ARM::BI__clear_cache) {
9111 assert(
E->getNumArgs() == 2 &&
"__clear_cache takes 2 arguments");
9114 for (
unsigned i = 0; i < 2; i++)
9117 llvm::FunctionType *FTy = cast<llvm::FunctionType>(Ty);
9118 StringRef Name = FD->
getName();
9122 if (BuiltinID == clang::ARM::BI__builtin_arm_mcrr ||
9123 BuiltinID == clang::ARM::BI__builtin_arm_mcrr2) {
9126 switch (BuiltinID) {
9127 default: llvm_unreachable(
"unexpected builtin");
9128 case clang::ARM::BI__builtin_arm_mcrr:
9131 case clang::ARM::BI__builtin_arm_mcrr2:
9153 return Builder.CreateCall(F, {Coproc, Opc1, Rt, Rt2, CRm});
9156 if (BuiltinID == clang::ARM::BI__builtin_arm_mrrc ||
9157 BuiltinID == clang::ARM::BI__builtin_arm_mrrc2) {
9160 switch (BuiltinID) {
9161 default: llvm_unreachable(
"unexpected builtin");
9162 case clang::ARM::BI__builtin_arm_mrrc:
9165 case clang::ARM::BI__builtin_arm_mrrc2:
9173 Value *RtAndRt2 =
Builder.CreateCall(F, {Coproc, Opc1, CRm});
9183 Value *ShiftCast = llvm::ConstantInt::get(
Int64Ty, 32);
9184 RtAndRt2 =
Builder.CreateShl(Rt, ShiftCast,
"shl",
true);
9185 RtAndRt2 =
Builder.CreateOr(RtAndRt2, Rt1);
9190 if (BuiltinID == clang::ARM::BI__builtin_arm_ldrexd ||
9191 ((BuiltinID == clang::ARM::BI__builtin_arm_ldrex ||
9192 BuiltinID == clang::ARM::BI__builtin_arm_ldaex) &&
9194 BuiltinID == clang::ARM::BI__ldrexd) {
9197 switch (BuiltinID) {
9198 default: llvm_unreachable(
"unexpected builtin");
9199 case clang::ARM::BI__builtin_arm_ldaex:
9202 case clang::ARM::BI__builtin_arm_ldrexd:
9203 case clang::ARM::BI__builtin_arm_ldrex:
9204 case clang::ARM::BI__ldrexd:
9218 Val =
Builder.CreateShl(Val0, ShiftCst,
"shl",
true );
9219 Val =
Builder.CreateOr(Val, Val1);
9223 if (BuiltinID == clang::ARM::BI__builtin_arm_ldrex ||
9224 BuiltinID == clang::ARM::BI__builtin_arm_ldaex) {
9233 BuiltinID == clang::ARM::BI__builtin_arm_ldaex ? Intrinsic::arm_ldaex
9234 : Intrinsic::arm_ldrex,
9236 CallInst *Val =
Builder.CreateCall(F, LoadAddr,
"ldrex");
9240 if (RealResTy->isPointerTy())
9241 return Builder.CreateIntToPtr(Val, RealResTy);
9243 llvm::Type *IntResTy = llvm::IntegerType::get(
9245 return Builder.CreateBitCast(
Builder.CreateTruncOrBitCast(Val, IntResTy),
9250 if (BuiltinID == clang::ARM::BI__builtin_arm_strexd ||
9251 ((BuiltinID == clang::ARM::BI__builtin_arm_stlex ||
9252 BuiltinID == clang::ARM::BI__builtin_arm_strex) &&
9255 BuiltinID == clang::ARM::BI__builtin_arm_stlex ? Intrinsic::arm_stlexd
9256 : Intrinsic::arm_strexd);
9269 return Builder.CreateCall(F, {Arg0, Arg1, StPtr},
"strexd");
9272 if (BuiltinID == clang::ARM::BI__builtin_arm_strex ||
9273 BuiltinID == clang::ARM::BI__builtin_arm_stlex) {
9278 llvm::Type *StoreTy =
9281 if (StoreVal->
getType()->isPointerTy())
9284 llvm::Type *
IntTy = llvm::IntegerType::get(
9292 BuiltinID == clang::ARM::BI__builtin_arm_stlex ? Intrinsic::arm_stlex
9293 : Intrinsic::arm_strex,
9296 CallInst *CI =
Builder.CreateCall(F, {StoreVal, StoreAddr},
"strex");
9298 1, Attribute::get(
getLLVMContext(), Attribute::ElementType, StoreTy));
9302 if (BuiltinID == clang::ARM::BI__builtin_arm_clrex) {
9308 Intrinsic::ID CRCIntrinsicID = Intrinsic::not_intrinsic;
9309 switch (BuiltinID) {
9310 case clang::ARM::BI__builtin_arm_crc32b:
9311 CRCIntrinsicID = Intrinsic::arm_crc32b;
break;
9312 case clang::ARM::BI__builtin_arm_crc32cb:
9313 CRCIntrinsicID = Intrinsic::arm_crc32cb;
break;
9314 case clang::ARM::BI__builtin_arm_crc32h:
9315 CRCIntrinsicID = Intrinsic::arm_crc32h;
break;
9316 case clang::ARM::BI__builtin_arm_crc32ch:
9317 CRCIntrinsicID = Intrinsic::arm_crc32ch;
break;
9318 case clang::ARM::BI__builtin_arm_crc32w:
9319 case clang::ARM::BI__builtin_arm_crc32d:
9320 CRCIntrinsicID = Intrinsic::arm_crc32w;
break;
9321 case clang::ARM::BI__builtin_arm_crc32cw:
9322 case clang::ARM::BI__builtin_arm_crc32cd:
9323 CRCIntrinsicID = Intrinsic::arm_crc32cw;
break;
9326 if (CRCIntrinsicID != Intrinsic::not_intrinsic) {
9332 if (BuiltinID == clang::ARM::BI__builtin_arm_crc32d ||
9333 BuiltinID == clang::ARM::BI__builtin_arm_crc32cd) {
9341 return Builder.CreateCall(F, {Res, Arg1b});
9346 return Builder.CreateCall(F, {Arg0, Arg1});
9350 if (BuiltinID == clang::ARM::BI__builtin_arm_rsr ||
9351 BuiltinID == clang::ARM::BI__builtin_arm_rsr64 ||
9352 BuiltinID == clang::ARM::BI__builtin_arm_rsrp ||
9353 BuiltinID == clang::ARM::BI__builtin_arm_wsr ||
9354 BuiltinID == clang::ARM::BI__builtin_arm_wsr64 ||
9355 BuiltinID == clang::ARM::BI__builtin_arm_wsrp) {
9358 if (BuiltinID == clang::ARM::BI__builtin_arm_rsr ||
9359 BuiltinID == clang::ARM::BI__builtin_arm_rsr64 ||
9360 BuiltinID == clang::ARM::BI__builtin_arm_rsrp)
9363 bool IsPointerBuiltin = BuiltinID == clang::ARM::BI__builtin_arm_rsrp ||
9364 BuiltinID == clang::ARM::BI__builtin_arm_wsrp;
9366 bool Is64Bit = BuiltinID == clang::ARM::BI__builtin_arm_rsr64 ||
9367 BuiltinID == clang::ARM::BI__builtin_arm_wsr64;
9369 llvm::Type *ValueType;
9371 if (IsPointerBuiltin) {
9374 }
else if (Is64Bit) {
9384 if (BuiltinID == ARM::BI__builtin_sponentry) {
9403 return P.first == BuiltinID;
9406 BuiltinID = It->second;
9410 unsigned ICEArguments = 0;
9415 auto getAlignmentValue32 = [&](
Address addr) ->
Value* {
9416 return Builder.getInt32(addr.getAlignment().getQuantity());
9423 unsigned NumArgs =
E->getNumArgs() - (HasExtraArg ? 1 : 0);
9424 for (
unsigned i = 0, e = NumArgs; i != e; i++) {
9426 switch (BuiltinID) {
9427 case NEON::BI__builtin_neon_vld1_v:
9428 case NEON::BI__builtin_neon_vld1q_v:
9429 case NEON::BI__builtin_neon_vld1q_lane_v:
9430 case NEON::BI__builtin_neon_vld1_lane_v:
9431 case NEON::BI__builtin_neon_vld1_dup_v:
9432 case NEON::BI__builtin_neon_vld1q_dup_v:
9433 case NEON::BI__builtin_neon_vst1_v:
9434 case NEON::BI__builtin_neon_vst1q_v:
9435 case NEON::BI__builtin_neon_vst1q_lane_v:
9436 case NEON::BI__builtin_neon_vst1_lane_v:
9437 case NEON::BI__builtin_neon_vst2_v:
9438 case NEON::BI__builtin_neon_vst2q_v:
9439 case NEON::BI__builtin_neon_vst2_lane_v:
9440 case NEON::BI__builtin_neon_vst2q_lane_v:
9441 case NEON::BI__builtin_neon_vst3_v:
9442 case NEON::BI__builtin_neon_vst3q_v:
9443 case NEON::BI__builtin_neon_vst3_lane_v:
9444 case NEON::BI__builtin_neon_vst3q_lane_v:
9445 case NEON::BI__builtin_neon_vst4_v:
9446 case NEON::BI__builtin_neon_vst4q_v:
9447 case NEON::BI__builtin_neon_vst4_lane_v:
9448 case NEON::BI__builtin_neon_vst4q_lane_v:
9457 switch (BuiltinID) {
9458 case NEON::BI__builtin_neon_vld2_v:
9459 case NEON::BI__builtin_neon_vld2q_v:
9460 case NEON::BI__builtin_neon_vld3_v:
9461 case NEON::BI__builtin_neon_vld3q_v:
9462 case NEON::BI__builtin_neon_vld4_v:
9463 case NEON::BI__builtin_neon_vld4q_v:
9464 case NEON::BI__builtin_neon_vld2_lane_v:
9465 case NEON::BI__builtin_neon_vld2q_lane_v:
9466 case NEON::BI__builtin_neon_vld3_lane_v:
9467 case NEON::BI__builtin_neon_vld3q_lane_v:
9468 case NEON::BI__builtin_neon_vld4_lane_v:
9469 case NEON::BI__builtin_neon_vld4q_lane_v:
9470 case NEON::BI__builtin_neon_vld2_dup_v:
9471 case NEON::BI__builtin_neon_vld2q_dup_v:
9472 case NEON::BI__builtin_neon_vld3_dup_v:
9473 case NEON::BI__builtin_neon_vld3q_dup_v:
9474 case NEON::BI__builtin_neon_vld4_dup_v:
9475 case NEON::BI__builtin_neon_vld4q_dup_v:
9487 switch (BuiltinID) {
9490 case NEON::BI__builtin_neon_vget_lane_i8:
9491 case NEON::BI__builtin_neon_vget_lane_i16:
9492 case NEON::BI__builtin_neon_vget_lane_i32:
9493 case NEON::BI__builtin_neon_vget_lane_i64:
9494 case NEON::BI__builtin_neon_vget_lane_bf16:
9495 case NEON::BI__builtin_neon_vget_lane_f32:
9496 case NEON::BI__builtin_neon_vgetq_lane_i8:
9497 case NEON::BI__builtin_neon_vgetq_lane_i16:
9498 case NEON::BI__builtin_neon_vgetq_lane_i32:
9499 case NEON::BI__builtin_neon_vgetq_lane_i64:
9500 case NEON::BI__builtin_neon_vgetq_lane_bf16:
9501 case NEON::BI__builtin_neon_vgetq_lane_f32:
9502 case NEON::BI__builtin_neon_vduph_lane_bf16:
9503 case NEON::BI__builtin_neon_vduph_laneq_bf16:
9504 return Builder.CreateExtractElement(Ops[0], Ops[1],
"vget_lane");
9506 case NEON::BI__builtin_neon_vrndns_f32: {
9508 llvm::Type *Tys[] = {Arg->
getType()};
9510 return Builder.CreateCall(F, {Arg},
"vrndn"); }
9512 case NEON::BI__builtin_neon_vset_lane_i8:
9513 case NEON::BI__builtin_neon_vset_lane_i16:
9514 case NEON::BI__builtin_neon_vset_lane_i32:
9515 case NEON::BI__builtin_neon_vset_lane_i64:
9516 case NEON::BI__builtin_neon_vset_lane_bf16:
9517 case NEON::BI__builtin_neon_vset_lane_f32:
9518 case NEON::BI__builtin_neon_vsetq_lane_i8:
9519 case NEON::BI__builtin_neon_vsetq_lane_i16:
9520 case NEON::BI__builtin_neon_vsetq_lane_i32:
9521 case NEON::BI__builtin_neon_vsetq_lane_i64:
9522 case NEON::BI__builtin_neon_vsetq_lane_bf16:
9523 case NEON::BI__builtin_neon_vsetq_lane_f32:
9524 return Builder.CreateInsertElement(Ops[1], Ops[0], Ops[2],
"vset_lane");
9526 case NEON::BI__builtin_neon_vsha1h_u32:
9529 case NEON::BI__builtin_neon_vsha1cq_u32:
9532 case NEON::BI__builtin_neon_vsha1pq_u32:
9535 case NEON::BI__builtin_neon_vsha1mq_u32:
9539 case NEON::BI__builtin_neon_vcvth_bf16_f32: {
9546 case clang::ARM::BI_MoveToCoprocessor:
9547 case clang::ARM::BI_MoveToCoprocessor2: {
9549 ? Intrinsic::arm_mcr
9550 : Intrinsic::arm_mcr2);
9551 return Builder.CreateCall(F, {Ops[1], Ops[2], Ops[0],
9552 Ops[3], Ops[4], Ops[5]});
9557 assert(HasExtraArg);
9558 const Expr *Arg =
E->getArg(
E->getNumArgs()-1);
9559 std::optional<llvm::APSInt>
Result =
9564 if (BuiltinID == clang::ARM::BI__builtin_arm_vcvtr_f ||
9565 BuiltinID == clang::ARM::BI__builtin_arm_vcvtr_d) {
9568 if (BuiltinID == clang::ARM::BI__builtin_arm_vcvtr_f)
9574 bool usgn =
Result->getZExtValue() == 1;
9575 unsigned Int = usgn ? Intrinsic::arm_vcvtru : Intrinsic::arm_vcvtr;
9579 return Builder.CreateCall(F, Ops,
"vcvtr");
9584 bool usgn =
Type.isUnsigned();
9585 bool rightShift =
false;
9587 llvm::FixedVectorType *VTy =
9590 llvm::Type *Ty = VTy;
9601 Builtin->BuiltinID, Builtin->LLVMIntrinsic, Builtin->AltLLVMIntrinsic,
9602 Builtin->NameHint, Builtin->TypeModifier,
E, Ops, PtrOp0, PtrOp1, Arch);
9605 switch (BuiltinID) {
9606 default:
return nullptr;
9607 case NEON::BI__builtin_neon_vld1q_lane_v:
9610 if (VTy->getElementType()->isIntegerTy(64)) {
9612 Ops[1] =
Builder.CreateBitCast(Ops[1], Ty);
9613 int Lane = cast<ConstantInt>(Ops[2])->getZExtValue();
9614 Value *SV = llvm::ConstantVector::get(ConstantInt::get(
Int32Ty, 1-Lane));
9615 Ops[1] =
Builder.CreateShuffleVector(Ops[1], Ops[1], SV);
9617 Ty = llvm::FixedVectorType::get(VTy->getElementType(), 1);
9620 Value *Align = getAlignmentValue32(PtrOp0);
9623 int Indices[] = {1 - Lane, Lane};
9624 return Builder.CreateShuffleVector(Ops[1], Ld, Indices,
"vld1q_lane");
9627 case NEON::BI__builtin_neon_vld1_lane_v: {
9628 Ops[1] =
Builder.CreateBitCast(Ops[1], Ty);
9631 return Builder.CreateInsertElement(Ops[1], Ld, Ops[2],
"vld1_lane");
9633 case NEON::BI__builtin_neon_vqrshrn_n_v:
9635 usgn ? Intrinsic::arm_neon_vqrshiftnu : Intrinsic::arm_neon_vqrshiftns;
9638 case NEON::BI__builtin_neon_vqrshrun_n_v:
9640 Ops,
"vqrshrun_n", 1,
true);
9641 case NEON::BI__builtin_neon_vqshrn_n_v:
9642 Int = usgn ? Intrinsic::arm_neon_vqshiftnu : Intrinsic::arm_neon_vqshiftns;
9645 case NEON::BI__builtin_neon_vqshrun_n_v:
9647 Ops,
"vqshrun_n", 1,
true);
9648 case NEON::BI__builtin_neon_vrecpe_v:
9649 case NEON::BI__builtin_neon_vrecpeq_v:
9652 case NEON::BI__builtin_neon_vrshrn_n_v:
9654 Ops,
"vrshrn_n", 1,
true);
9655 case NEON::BI__builtin_neon_vrsra_n_v:
9656 case NEON::BI__builtin_neon_vrsraq_n_v:
9657 Ops[0] =
Builder.CreateBitCast(Ops[0], Ty);
9658 Ops[1] =
Builder.CreateBitCast(Ops[1], Ty);
9660 Int = usgn ? Intrinsic::arm_neon_vrshiftu : Intrinsic::arm_neon_vrshifts;
9662 return Builder.CreateAdd(Ops[0], Ops[1],
"vrsra_n");
9663 case NEON::BI__builtin_neon_vsri_n_v:
9664 case NEON::BI__builtin_neon_vsriq_n_v:
9667 case NEON::BI__builtin_neon_vsli_n_v:
9668 case NEON::BI__builtin_neon_vsliq_n_v:
9672 case NEON::BI__builtin_neon_vsra_n_v:
9673 case NEON::BI__builtin_neon_vsraq_n_v:
9674 Ops[0] =
Builder.CreateBitCast(Ops[0], Ty);
9676 return Builder.CreateAdd(Ops[0], Ops[1]);
9677 case NEON::BI__builtin_neon_vst1q_lane_v:
9680 if (VTy->getElementType()->isIntegerTy(64)) {
9681 Ops[1] =
Builder.CreateBitCast(Ops[1], Ty);
9682 Value *SV = llvm::ConstantVector::get(cast<llvm::Constant>(Ops[2]));
9683 Ops[1] =
Builder.CreateShuffleVector(Ops[1], Ops[1], SV);
9684 Ops[2] = getAlignmentValue32(PtrOp0);
9685 llvm::Type *Tys[] = {
Int8PtrTy, Ops[1]->getType()};
9690 case NEON::BI__builtin_neon_vst1_lane_v: {
9691 Ops[1] =
Builder.CreateBitCast(Ops[1], Ty);
9692 Ops[1] =
Builder.CreateExtractElement(Ops[1], Ops[2]);
9696 case NEON::BI__builtin_neon_vtbl1_v:
9699 case NEON::BI__builtin_neon_vtbl2_v:
9702 case NEON::BI__builtin_neon_vtbl3_v:
9705 case NEON::BI__builtin_neon_vtbl4_v:
9708 case NEON::BI__builtin_neon_vtbx1_v:
9711 case NEON::BI__builtin_neon_vtbx2_v:
9714 case NEON::BI__builtin_neon_vtbx3_v:
9717 case NEON::BI__builtin_neon_vtbx4_v:
9723template<
typename Integer>
9732 return Unsigned ? Builder.CreateZExt(
V,
T) : Builder.CreateSExt(
V,
T);
9742 unsigned LaneBits = cast<llvm::VectorType>(
V->getType())
9744 ->getPrimitiveSizeInBits();
9745 if (Shift == LaneBits) {
9750 return llvm::Constant::getNullValue(
V->getType());
9754 return Unsigned ? Builder.CreateLShr(
V, Shift) : Builder.CreateAShr(
V, Shift);
9761 unsigned Elements = 128 /
V->getType()->getPrimitiveSizeInBits();
9762 return Builder.CreateVectorSplat(Elements,
V);
9768 llvm::Type *DestType) {
9781 V->getType()->getScalarSizeInBits() != DestType->getScalarSizeInBits()) {
9782 return Builder.CreateCall(
9784 {DestType, V->getType()}),
9787 return Builder.CreateBitCast(
V, DestType);
9795 unsigned InputElements =
9796 cast<llvm::FixedVectorType>(
V->getType())->getNumElements();
9797 for (
unsigned i = 0; i < InputElements; i += 2)
9798 Indices.push_back(i + Odd);
9799 return Builder.CreateShuffleVector(
V, Indices);
9805 assert(V0->getType() == V1->getType() &&
"Can't zip different vector types");
9807 unsigned InputElements =
9808 cast<llvm::FixedVectorType>(V0->getType())->getNumElements();
9809 for (
unsigned i = 0; i < InputElements; i++) {
9810 Indices.push_back(i);
9811 Indices.push_back(i + InputElements);
9813 return Builder.CreateShuffleVector(V0, V1, Indices);
9816template<
unsigned HighBit,
unsigned OtherBits>
9820 llvm::Type *
T = cast<llvm::VectorType>(VT)->getElementType();
9821 unsigned LaneBits =
T->getPrimitiveSizeInBits();
9822 uint32_t
Value = HighBit << (LaneBits - 1);
9824 Value |= (1UL << (LaneBits - 1)) - 1;
9825 llvm::Value *Lane = llvm::ConstantInt::get(
T,
Value);
9831 unsigned ReverseWidth) {
9835 unsigned LaneSize =
V->getType()->getScalarSizeInBits();
9836 unsigned Elements = 128 / LaneSize;
9837 unsigned Mask = ReverseWidth / LaneSize - 1;
9838 for (
unsigned i = 0; i < Elements; i++)
9839 Indices.push_back(i ^ Mask);
9840 return Builder.CreateShuffleVector(
V, Indices);
9846 llvm::Triple::ArchType Arch) {
9847 enum class CustomCodeGen { VLD24, VST24 } CustomCodeGenType;
9848 Intrinsic::ID IRIntr;
9849 unsigned NumVectors;
9852 switch (BuiltinID) {
9853 #include "clang/Basic/arm_mve_builtin_cg.inc"
9864 switch (CustomCodeGenType) {
9866 case CustomCodeGen::VLD24: {
9872 assert(MvecLType->isStructTy() &&
9873 "Return type for vld[24]q should be a struct");
9874 assert(MvecLType->getStructNumElements() == 1 &&
9875 "Return-type struct for vld[24]q should have one element");
9876 auto MvecLTypeInner = MvecLType->getStructElementType(0);
9877 assert(MvecLTypeInner->isArrayTy() &&
9878 "Return-type struct for vld[24]q should contain an array");
9879 assert(MvecLTypeInner->getArrayNumElements() == NumVectors &&
9880 "Array member of return-type struct vld[24]q has wrong length");
9881 auto VecLType = MvecLTypeInner->getArrayElementType();
9883 Tys.push_back(VecLType);
9885 auto Addr =
E->getArg(0);
9891 Value *MvecOut = PoisonValue::get(MvecLType);
9892 for (
unsigned i = 0; i < NumVectors; ++i) {
9893 Value *Vec =
Builder.CreateExtractValue(LoadResult, i);
9894 MvecOut =
Builder.CreateInsertValue(MvecOut, Vec, {0, i});
9903 case CustomCodeGen::VST24: {
9907 auto Addr =
E->getArg(0);
9911 auto MvecCType =
E->getArg(1)->
getType();
9913 assert(MvecLType->isStructTy() &&
"Data type for vst2q should be a struct");
9914 assert(MvecLType->getStructNumElements() == 1 &&
9915 "Data-type struct for vst2q should have one element");
9916 auto MvecLTypeInner = MvecLType->getStructElementType(0);
9917 assert(MvecLTypeInner->isArrayTy() &&
9918 "Data-type struct for vst2q should contain an array");
9919 assert(MvecLTypeInner->getArrayNumElements() == NumVectors &&
9920 "Array member of return-type struct vld[24]q has wrong length");
9921 auto VecLType = MvecLTypeInner->getArrayElementType();
9923 Tys.push_back(VecLType);
9928 for (
unsigned i = 0; i < NumVectors; i++)
9929 Ops.push_back(
Builder.CreateExtractValue(Mvec, {0, i}));
9932 Value *ToReturn =
nullptr;
9933 for (
unsigned i = 0; i < NumVectors; i++) {
9934 Ops.push_back(llvm::ConstantInt::get(
Int32Ty, i));
9935 ToReturn =
Builder.CreateCall(F, Ops);
9941 llvm_unreachable(
"unknown custom codegen type.");
9947 llvm::Triple::ArchType Arch) {
9948 switch (BuiltinID) {
9951#include "clang/Basic/arm_cde_builtin_cg.inc"
9958 llvm::Triple::ArchType Arch) {
9959 unsigned int Int = 0;
9960 const char *
s =
nullptr;
9962 switch (BuiltinID) {
9965 case NEON::BI__builtin_neon_vtbl1_v:
9966 case NEON::BI__builtin_neon_vqtbl1_v:
9967 case NEON::BI__builtin_neon_vqtbl1q_v:
9968 case NEON::BI__builtin_neon_vtbl2_v:
9969 case NEON::BI__builtin_neon_vqtbl2_v:
9970 case NEON::BI__builtin_neon_vqtbl2q_v:
9971 case NEON::BI__builtin_neon_vtbl3_v:
9972 case NEON::BI__builtin_neon_vqtbl3_v:
9973 case NEON::BI__builtin_neon_vqtbl3q_v:
9974 case NEON::BI__builtin_neon_vtbl4_v:
9975 case NEON::BI__builtin_neon_vqtbl4_v:
9976 case NEON::BI__builtin_neon_vqtbl4q_v:
9978 case NEON::BI__builtin_neon_vtbx1_v:
9979 case NEON::BI__builtin_neon_vqtbx1_v:
9980 case NEON::BI__builtin_neon_vqtbx1q_v:
9981 case NEON::BI__builtin_neon_vtbx2_v:
9982 case NEON::BI__builtin_neon_vqtbx2_v:
9983 case NEON::BI__builtin_neon_vqtbx2q_v:
9984 case NEON::BI__builtin_neon_vtbx3_v:
9985 case NEON::BI__builtin_neon_vqtbx3_v:
9986 case NEON::BI__builtin_neon_vqtbx3q_v:
9987 case NEON::BI__builtin_neon_vtbx4_v:
9988 case NEON::BI__builtin_neon_vqtbx4_v:
9989 case NEON::BI__builtin_neon_vqtbx4q_v:
9993 assert(
E->getNumArgs() >= 3);
9996 const Expr *Arg =
E->getArg(
E->getNumArgs() - 1);
9997 std::optional<llvm::APSInt>
Result =
10012 switch (BuiltinID) {
10013 case NEON::BI__builtin_neon_vtbl1_v: {
10015 Ty, Intrinsic::aarch64_neon_tbl1,
"vtbl1");
10017 case NEON::BI__builtin_neon_vtbl2_v: {
10019 Ty, Intrinsic::aarch64_neon_tbl1,
"vtbl1");
10021 case NEON::BI__builtin_neon_vtbl3_v: {
10023 Ty, Intrinsic::aarch64_neon_tbl2,
"vtbl2");
10025 case NEON::BI__builtin_neon_vtbl4_v: {
10027 Ty, Intrinsic::aarch64_neon_tbl2,
"vtbl2");
10029 case NEON::BI__builtin_neon_vtbx1_v: {
10032 Intrinsic::aarch64_neon_tbl1,
"vtbl1");
10034 llvm::Constant *EightV = ConstantInt::get(Ty, 8);
10035 Value *CmpRes = Builder.CreateICmp(ICmpInst::ICMP_UGE, Ops[2], EightV);
10036 CmpRes = Builder.CreateSExt(CmpRes, Ty);
10038 Value *EltsFromInput = Builder.CreateAnd(CmpRes, Ops[0]);
10039 Value *EltsFromTbl = Builder.CreateAnd(Builder.CreateNot(CmpRes), TblRes);
10040 return Builder.CreateOr(EltsFromInput, EltsFromTbl,
"vtbx");
10042 case NEON::BI__builtin_neon_vtbx2_v: {
10044 Ty, Intrinsic::aarch64_neon_tbx1,
"vtbx1");
10046 case NEON::BI__builtin_neon_vtbx3_v: {
10049 Intrinsic::aarch64_neon_tbl2,
"vtbl2");
10051 llvm::Constant *TwentyFourV = ConstantInt::get(Ty, 24);
10052 Value *CmpRes = Builder.CreateICmp(ICmpInst::ICMP_UGE, Ops[4],
10054 CmpRes = Builder.CreateSExt(CmpRes, Ty);
10056 Value *EltsFromInput = Builder.CreateAnd(CmpRes, Ops[0]);
10057 Value *EltsFromTbl = Builder.CreateAnd(Builder.CreateNot(CmpRes), TblRes);
10058 return Builder.CreateOr(EltsFromInput, EltsFromTbl,
"vtbx");
10060 case NEON::BI__builtin_neon_vtbx4_v: {
10062 Ty, Intrinsic::aarch64_neon_tbx2,
"vtbx2");
10064 case NEON::BI__builtin_neon_vqtbl1_v:
10065 case NEON::BI__builtin_neon_vqtbl1q_v:
10066 Int = Intrinsic::aarch64_neon_tbl1;
s =
"vtbl1";
break;
10067 case NEON::BI__builtin_neon_vqtbl2_v:
10068 case NEON::BI__builtin_neon_vqtbl2q_v: {
10069 Int = Intrinsic::aarch64_neon_tbl2;
s =
"vtbl2";
break;
10070 case NEON::BI__builtin_neon_vqtbl3_v:
10071 case NEON::BI__builtin_neon_vqtbl3q_v:
10072 Int = Intrinsic::aarch64_neon_tbl3;
s =
"vtbl3";
break;
10073 case NEON::BI__builtin_neon_vqtbl4_v:
10074 case NEON::BI__builtin_neon_vqtbl4q_v:
10075 Int = Intrinsic::aarch64_neon_tbl4;
s =
"vtbl4";
break;
10076 case NEON::BI__builtin_neon_vqtbx1_v:
10077 case NEON::BI__builtin_neon_vqtbx1q_v:
10078 Int = Intrinsic::aarch64_neon_tbx1;
s =
"vtbx1";
break;
10079 case NEON::BI__builtin_neon_vqtbx2_v:
10080 case NEON::BI__builtin_neon_vqtbx2q_v:
10081 Int = Intrinsic::aarch64_neon_tbx2;
s =
"vtbx2";
break;
10082 case NEON::BI__builtin_neon_vqtbx3_v:
10083 case NEON::BI__builtin_neon_vqtbx3q_v:
10084 Int = Intrinsic::aarch64_neon_tbx3;
s =
"vtbx3";
break;
10085 case NEON::BI__builtin_neon_vqtbx4_v:
10086 case NEON::BI__builtin_neon_vqtbx4q_v:
10087 Int = Intrinsic::aarch64_neon_tbx4;
s =
"vtbx4";
break;
10099 auto *VTy = llvm::FixedVectorType::get(
Int16Ty, 4);
10101 Value *
V = PoisonValue::get(VTy);
10102 llvm::Constant *CI = ConstantInt::get(
SizeTy, 0);
10103 Op =
Builder.CreateInsertElement(
V, Op, CI);
10112 case SVETypeFlags::MemEltTyDefault:
10114 case SVETypeFlags::MemEltTyInt8:
10116 case SVETypeFlags::MemEltTyInt16:
10118 case SVETypeFlags::MemEltTyInt32:
10120 case SVETypeFlags::MemEltTyInt64:
10123 llvm_unreachable(
"Unknown MemEltType");
10129 llvm_unreachable(
"Invalid SVETypeFlag!");
10131 case SVETypeFlags::EltTyInt8:
10133 case SVETypeFlags::EltTyInt16:
10135 case SVETypeFlags::EltTyInt32:
10137 case SVETypeFlags::EltTyInt64:
10139 case SVETypeFlags::EltTyInt128:
10140 return Builder.getInt128Ty();
10142 case SVETypeFlags::EltTyFloat16:
10144 case SVETypeFlags::EltTyFloat32:
10146 case SVETypeFlags::EltTyFloat64:
10147 return Builder.getDoubleTy();
10149 case SVETypeFlags::EltTyBFloat16:
10150 return Builder.getBFloatTy();
10152 case SVETypeFlags::EltTyBool8:
10153 case SVETypeFlags::EltTyBool16:
10154 case SVETypeFlags::EltTyBool32:
10155 case SVETypeFlags::EltTyBool64:
10162llvm::ScalableVectorType *
10165 default: llvm_unreachable(
"Unhandled SVETypeFlag!");
10167 case SVETypeFlags::EltTyInt8:
10168 return llvm::ScalableVectorType::get(
Builder.getInt1Ty(), 16);
10169 case SVETypeFlags::EltTyInt16:
10170 return llvm::ScalableVectorType::get(
Builder.getInt1Ty(), 8);
10171 case SVETypeFlags::EltTyInt32:
10172 return llvm::ScalableVectorType::get(
Builder.getInt1Ty(), 4);
10173 case SVETypeFlags::EltTyInt64:
10174 return llvm::ScalableVectorType::get(
Builder.getInt1Ty(), 2);
10176 case SVETypeFlags::EltTyBFloat16:
10177 return llvm::ScalableVectorType::get(
Builder.getInt1Ty(), 8);
10178 case SVETypeFlags::EltTyFloat16:
10179 return llvm::ScalableVectorType::get(
Builder.getInt1Ty(), 8);
10180 case SVETypeFlags::EltTyFloat32:
10181 return llvm::ScalableVectorType::get(
Builder.getInt1Ty(), 4);
10182 case SVETypeFlags::EltTyFloat64:
10183 return llvm::ScalableVectorType::get(
Builder.getInt1Ty(), 2);
10185 case SVETypeFlags::EltTyBool8:
10186 return llvm::ScalableVectorType::get(
Builder.getInt1Ty(), 16);
10187 case SVETypeFlags::EltTyBool16:
10188 return llvm::ScalableVectorType::get(
Builder.getInt1Ty(), 8);
10189 case SVETypeFlags::EltTyBool32:
10190 return llvm::ScalableVectorType::get(
Builder.getInt1Ty(), 4);
10191 case SVETypeFlags::EltTyBool64:
10192 return llvm::ScalableVectorType::get(
Builder.getInt1Ty(), 2);
10197llvm::ScalableVectorType *
10201 llvm_unreachable(
"Invalid SVETypeFlag!");
10203 case SVETypeFlags::EltTyInt8:
10204 return llvm::ScalableVectorType::get(
Builder.getInt8Ty(), 16);
10205 case SVETypeFlags::EltTyInt16:
10206 return llvm::ScalableVectorType::get(
Builder.getInt16Ty(), 8);
10207 case SVETypeFlags::EltTyInt32:
10208 return llvm::ScalableVectorType::get(
Builder.getInt32Ty(), 4);
10209 case SVETypeFlags::EltTyInt64:
10210 return llvm::ScalableVectorType::get(
Builder.getInt64Ty(), 2);
10212 case SVETypeFlags::EltTyMFloat8:
10213 return llvm::ScalableVectorType::get(
Builder.getInt8Ty(), 16);
10214 case SVETypeFlags::EltTyFloat16:
10215 return llvm::ScalableVectorType::get(
Builder.getHalfTy(), 8);
10216 case SVETypeFlags::EltTyBFloat16:
10217 return llvm::ScalableVectorType::get(
Builder.getBFloatTy(), 8);
10218 case SVETypeFlags::EltTyFloat32:
10219 return llvm::ScalableVectorType::get(
Builder.getFloatTy(), 4);
10220 case SVETypeFlags::EltTyFloat64:
10221 return llvm::ScalableVectorType::get(
Builder.getDoubleTy(), 2);
10223 case SVETypeFlags::EltTyBool8:
10224 return llvm::ScalableVectorType::get(
Builder.getInt1Ty(), 16);
10225 case SVETypeFlags::EltTyBool16:
10226 return llvm::ScalableVectorType::get(
Builder.getInt1Ty(), 8);
10227 case SVETypeFlags::EltTyBool32:
10228 return llvm::ScalableVectorType::get(
Builder.getInt1Ty(), 4);
10229 case SVETypeFlags::EltTyBool64:
10230 return llvm::ScalableVectorType::get(
Builder.getInt1Ty(), 2);
10245 return llvm::ScalableVectorType::get(EltTy, NumElts);
10251 llvm::ScalableVectorType *VTy) {
10253 if (isa<TargetExtType>(Pred->
getType()) &&
10254 cast<TargetExtType>(Pred->
getType())->getName() ==
"aarch64.svcount")
10257 auto *RTy = llvm::VectorType::get(IntegerType::get(
getLLVMContext(), 1), VTy);
10262 llvm::Type *IntrinsicTy;
10263 switch (VTy->getMinNumElements()) {
10265 llvm_unreachable(
"unsupported element count!");
10270 IntID = Intrinsic::aarch64_sve_convert_from_svbool;
10274 IntID = Intrinsic::aarch64_sve_convert_to_svbool;
10275 IntrinsicTy = Pred->
getType();
10281 assert(
C->getType() == RTy &&
"Unexpected return type!");
10286 llvm::StructType *Ty) {
10287 if (PredTuple->
getType() == Ty)
10290 Value *
Ret = llvm::PoisonValue::get(Ty);
10291 for (
unsigned I = 0; I < Ty->getNumElements(); ++I) {
10292 Value *Pred =
Builder.CreateExtractValue(PredTuple, I);
10294 Pred, cast<llvm::ScalableVectorType>(Ty->getTypeAtIndex(I)));
10295 Ret =
Builder.CreateInsertValue(Ret, Pred, I);
10305 auto *OverloadedTy =
10309 if (Ops[1]->getType()->isVectorTy())
10329 Ops[0], cast<llvm::ScalableVectorType>(F->getArg(0)->getType()));
10334 if (Ops.size() == 2) {
10335 assert(Ops[1]->getType()->isVectorTy() &&
"Scalar base requires an offset");
10336 Ops.push_back(ConstantInt::get(
Int64Ty, 0));
10341 if (!TypeFlags.
isByteIndexed() && Ops[1]->getType()->isVectorTy()) {
10342 unsigned BytesPerElt =
10343 OverloadedTy->getElementType()->getScalarSizeInBits() / 8;
10344 Ops[2] =
Builder.CreateShl(Ops[2], Log2_32(BytesPerElt));
10359 auto *OverloadedTy =
10364 Ops.insert(Ops.begin(), Ops.pop_back_val());
10367 if (Ops[2]->getType()->isVectorTy())
10382 if (Ops.size() == 3) {
10383 assert(Ops[1]->getType()->isVectorTy() &&
"Scalar base requires an offset");
10384 Ops.push_back(ConstantInt::get(
Int64Ty, 0));
10389 Ops[0] =
Builder.CreateTrunc(Ops[0], OverloadedTy);
10399 Ops[1], cast<llvm::ScalableVectorType>(F->getArg(1)->getType()));
10403 if (!TypeFlags.
isByteIndexed() && Ops[2]->getType()->isVectorTy()) {
10404 unsigned BytesPerElt =
10405 OverloadedTy->getElementType()->getScalarSizeInBits() / 8;
10406 Ops[3] =
Builder.CreateShl(Ops[3], Log2_32(BytesPerElt));
10409 return Builder.CreateCall(F, Ops);
10417 auto *OverloadedTy = dyn_cast<llvm::ScalableVectorType>(Ops[1]->getType());
10419 OverloadedTy = cast<llvm::ScalableVectorType>(Ops[2]->getType());
10425 if (Ops[1]->getType()->isVectorTy()) {
10426 if (Ops.size() == 3) {
10428 Ops.push_back(ConstantInt::get(
Int64Ty, 0));
10431 std::swap(Ops[2], Ops[3]);
10435 unsigned BytesPerElt = MemEltTy->getPrimitiveSizeInBits() / 8;
10436 if (BytesPerElt > 1)
10437 Ops[2] =
Builder.CreateShl(Ops[2], Log2_32(BytesPerElt));
10442 return Builder.CreateCall(F, Ops);
10448 llvm::ScalableVectorType *VTy =
getSVEType(TypeFlags);
10450 Value *BasePtr = Ops[1];
10453 if (Ops.size() > 2)
10457 return Builder.CreateCall(F, {Predicate, BasePtr});
10463 llvm::ScalableVectorType *VTy =
getSVEType(TypeFlags);
10467 case Intrinsic::aarch64_sve_st2:
10468 case Intrinsic::aarch64_sve_st1_pn_x2:
10469 case Intrinsic::aarch64_sve_stnt1_pn_x2:
10470 case Intrinsic::aarch64_sve_st2q:
10473 case Intrinsic::aarch64_sve_st3:
10474 case Intrinsic::aarch64_sve_st3q:
10477 case Intrinsic::aarch64_sve_st4:
10478 case Intrinsic::aarch64_sve_st1_pn_x4:
10479 case Intrinsic::aarch64_sve_stnt1_pn_x4:
10480 case Intrinsic::aarch64_sve_st4q:
10484 llvm_unreachable(
"unknown intrinsic!");
10488 Value *BasePtr = Ops[1];
10491 if (Ops.size() > (2 + N))
10497 for (
unsigned I = Ops.size() - N; I < Ops.size(); ++I)
10498 Operands.push_back(Ops[I]);
10499 Operands.append({Predicate, BasePtr});
10502 return Builder.CreateCall(F, Operands);
10510 unsigned BuiltinID) {
10522 llvm::ScalableVectorType *Ty =
getSVEType(TypeFlags);
10528 llvm::Type *OverloadedTy =
getSVEType(TypeFlags);
10535 unsigned BuiltinID) {
10538 auto *MemoryTy = llvm::ScalableVectorType::get(MemEltTy, VectorTy);
10541 Value *BasePtr = Ops[1];
10544 if (Ops.size() > 3)
10547 Value *PrfOp = Ops.back();
10550 return Builder.CreateCall(F, {Predicate, BasePtr, PrfOp});
10554 llvm::Type *ReturnTy,
10556 unsigned IntrinsicID,
10557 bool IsZExtReturn) {
10564 auto VectorTy = cast<llvm::ScalableVectorType>(ReturnTy);
10565 llvm::ScalableVectorType *MemoryTy =
nullptr;
10566 llvm::ScalableVectorType *PredTy =
nullptr;
10567 bool IsQuadLoad =
false;
10568 switch (IntrinsicID) {
10569 case Intrinsic::aarch64_sve_ld1uwq:
10570 case Intrinsic::aarch64_sve_ld1udq:
10571 MemoryTy = llvm::ScalableVectorType::get(MemEltTy, 1);
10572 PredTy = llvm::ScalableVectorType::get(
10577 MemoryTy = llvm::ScalableVectorType::get(MemEltTy, VectorTy);
10583 Value *BasePtr = Ops[1];
10586 if (Ops.size() > 2)
10591 cast<llvm::Instruction>(
Builder.CreateCall(F, {Predicate, BasePtr}));
10598 return IsZExtReturn ?
Builder.CreateZExt(Load, VectorTy)
10599 :
Builder.CreateSExt(Load, VectorTy);
10604 unsigned IntrinsicID) {
10611 auto VectorTy = cast<llvm::ScalableVectorType>(Ops.back()->getType());
10612 auto MemoryTy = llvm::ScalableVectorType::get(MemEltTy, VectorTy);
10614 auto PredTy = MemoryTy;
10615 auto AddrMemoryTy = MemoryTy;
10616 bool IsQuadStore =
false;
10618 switch (IntrinsicID) {
10619 case Intrinsic::aarch64_sve_st1wq:
10620 case Intrinsic::aarch64_sve_st1dq:
10621 AddrMemoryTy = llvm::ScalableVectorType::get(MemEltTy, 1);
10623 llvm::ScalableVectorType::get(IntegerType::get(
getLLVMContext(), 1), 1);
10624 IsQuadStore =
true;
10630 Value *BasePtr = Ops[1];
10633 if (Ops.size() == 4)
10638 IsQuadStore ? Ops.back() :
Builder.CreateTrunc(Ops.back(), MemoryTy);
10643 cast<llvm::Instruction>(
Builder.CreateCall(F, {Val, Predicate, BasePtr}));
10656 NewOps.push_back(Ops[2]);
10658 llvm::Value *BasePtr = Ops[3];
10659 llvm::Value *RealSlice = Ops[1];
10662 if (Ops.size() == 5) {
10665 llvm::Value *StreamingVectorLengthCall =
10666 Builder.CreateCall(StreamingVectorLength);
10667 llvm::Value *Mulvl =
10668 Builder.CreateMul(StreamingVectorLengthCall, Ops[4],
"mulvl");
10672 RealSlice =
Builder.CreateAdd(RealSlice, Ops[4]);
10675 NewOps.push_back(BasePtr);
10676 NewOps.push_back(Ops[0]);
10677 NewOps.push_back(RealSlice);
10679 return Builder.CreateCall(F, NewOps);
10691 return Builder.CreateCall(F, Ops);
10698 if (Ops.size() == 0)
10699 Ops.push_back(llvm::ConstantInt::get(
Int32Ty, 255));
10701 return Builder.CreateCall(F, Ops);
10707 if (Ops.size() == 2)
10708 Ops.push_back(
Builder.getInt32(0));
10712 return Builder.CreateCall(F, Ops);
10718 return Builder.CreateVectorSplat(
10719 cast<llvm::VectorType>(Ty)->getElementCount(), Scalar);
10723 if (
auto *Ty =
Scalar->getType(); Ty->isVectorTy()) {
10725 auto *VecTy = cast<llvm::VectorType>(Ty);
10726 ElementCount EC = VecTy->getElementCount();
10727 assert(EC.isScalar() && VecTy->getElementType() ==
Int8Ty &&
10728 "Only <1 x i8> expected");
10743 if (
auto *StructTy = dyn_cast<StructType>(Ty)) {
10744 Value *Tuple = llvm::PoisonValue::get(Ty);
10746 for (
unsigned I = 0; I < StructTy->getNumElements(); ++I) {
10748 Value *Out =
Builder.CreateBitCast(In, StructTy->getTypeAtIndex(I));
10749 Tuple =
Builder.CreateInsertValue(Tuple, Out, I);
10755 return Builder.CreateBitCast(Val, Ty);
10760 auto *SplatZero = Constant::getNullValue(Ty);
10761 Ops.insert(Ops.begin(), SplatZero);
10766 auto *SplatUndef = UndefValue::get(Ty);
10767 Ops.insert(Ops.begin(), SplatUndef);
10772 llvm::Type *ResultType,
10777 llvm::Type *DefaultType =
getSVEType(TypeFlags);
10780 return {DefaultType, Ops[1]->getType()};
10786 return {Ops[0]->getType(), Ops.back()->getType()};
10788 if (TypeFlags.
isReductionQV() && !ResultType->isScalableTy() &&
10789 ResultType->isVectorTy())
10790 return {ResultType, Ops[1]->getType()};
10793 return {DefaultType};
10799 "Expects TypleFlags.isTupleSet() or TypeFlags.isTupleGet()");
10800 unsigned Idx = cast<ConstantInt>(Ops[1])->getZExtValue();
10803 return Builder.CreateInsertValue(Ops[0], Ops[2], Idx);
10804 return Builder.CreateExtractValue(Ops[0], Idx);
10810 assert(TypeFlags.
isTupleCreate() &&
"Expects TypleFlag isTupleCreate");
10812 Value *Tuple = llvm::PoisonValue::get(Ty);
10813 for (
unsigned Idx = 0; Idx < Ops.size(); Idx++)
10814 Tuple =
Builder.CreateInsertValue(Tuple, Ops[Idx], Idx);
10823 unsigned ICEArguments = 0;
10832 for (
unsigned i = 0, e =
E->getNumArgs(); i != e; i++) {
10833 bool IsICE = ICEArguments & (1 << i);
10839 std::optional<llvm::APSInt>
Result =
10841 assert(
Result &&
"Expected argument to be a constant");
10851 if (isa<StructType>(Arg->getType()) && !IsTupleGetOrSet) {
10852 for (
unsigned I = 0; I < Arg->getType()->getStructNumElements(); ++I)
10853 Ops.push_back(
Builder.CreateExtractValue(Arg, I));
10858 Ops.push_back(Arg);
10865 if (BuiltinID >= SVE::BI__builtin_sve_reinterpret_s8_s8 &&
10866 BuiltinID <= SVE::BI__builtin_sve_reinterpret_f64_f64_x4) {
10881 else if (TypeFlags.
isStore())
10899 else if (TypeFlags.
isUndef())
10900 return UndefValue::get(Ty);
10901 else if (Builtin->LLVMIntrinsic != 0) {
10905 Ops.pop_back_val());
10906 if (TypeFlags.
getMergeType() == SVETypeFlags::MergeZeroExp)
10909 if (TypeFlags.
getMergeType() == SVETypeFlags::MergeAnyExp)
10915 Ops.push_back(
Builder.getInt32( 31));
10917 Ops.insert(&Ops[1],
Builder.getInt32( 31));
10920 for (
unsigned i = 0, e = Ops.size(); i != e; ++i)
10921 if (
auto PredTy = dyn_cast<llvm::VectorType>(Ops[i]->getType()))
10922 if (PredTy->getElementType()->isIntegerTy(1))
10932 std::swap(Ops[1], Ops[2]);
10934 std::swap(Ops[1], Ops[2]);
10937 std::swap(Ops[1], Ops[2]);
10940 std::swap(Ops[1], Ops[3]);
10943 if (TypeFlags.
getMergeType() == SVETypeFlags::MergeZero) {
10944 llvm::Type *OpndTy = Ops[1]->getType();
10945 auto *SplatZero = Constant::getNullValue(OpndTy);
10946 Ops[1] =
Builder.CreateSelect(Ops[0], Ops[1], SplatZero);
10953 if (
Call->getType() == Ty)
10957 if (
auto PredTy = dyn_cast<llvm::ScalableVectorType>(Ty))
10959 if (
auto PredTupleTy = dyn_cast<llvm::StructType>(Ty))
10962 llvm_unreachable(
"unsupported element count!");
10965 switch (BuiltinID) {
10969 case SVE::BI__builtin_sve_svreinterpret_b: {
10973 CGM.
getIntrinsic(Intrinsic::aarch64_sve_convert_to_svbool, SVCountTy);
10974 return Builder.CreateCall(CastFromSVCountF, Ops[0]);
10976 case SVE::BI__builtin_sve_svreinterpret_c: {
10980 CGM.
getIntrinsic(Intrinsic::aarch64_sve_convert_from_svbool, SVCountTy);
10981 return Builder.CreateCall(CastToSVCountF, Ops[0]);
10984 case SVE::BI__builtin_sve_svpsel_lane_b8:
10985 case SVE::BI__builtin_sve_svpsel_lane_b16:
10986 case SVE::BI__builtin_sve_svpsel_lane_b32:
10987 case SVE::BI__builtin_sve_svpsel_lane_b64:
10988 case SVE::BI__builtin_sve_svpsel_lane_c8:
10989 case SVE::BI__builtin_sve_svpsel_lane_c16:
10990 case SVE::BI__builtin_sve_svpsel_lane_c32:
10991 case SVE::BI__builtin_sve_svpsel_lane_c64: {
10992 bool IsSVCount = isa<TargetExtType>(Ops[0]->getType());
10993 assert(((!IsSVCount || cast<TargetExtType>(Ops[0]->getType())->
getName() ==
10994 "aarch64.svcount")) &&
10995 "Unexpected TargetExtType");
10999 CGM.
getIntrinsic(Intrinsic::aarch64_sve_convert_to_svbool, SVCountTy);
11001 CGM.
getIntrinsic(Intrinsic::aarch64_sve_convert_from_svbool, SVCountTy);
11005 llvm::Value *Ops0 =
11006 IsSVCount ?
Builder.CreateCall(CastFromSVCountF, Ops[0]) : Ops[0];
11008 llvm::Value *PSel =
Builder.CreateCall(F, {Ops0, Ops1, Ops[2]});
11009 return IsSVCount ?
Builder.CreateCall(CastToSVCountF, PSel) : PSel;
11011 case SVE::BI__builtin_sve_svmov_b_z: {
11014 llvm::Type* OverloadedTy =
getSVEType(TypeFlags);
11016 return Builder.CreateCall(F, {Ops[0], Ops[1], Ops[1]});
11019 case SVE::BI__builtin_sve_svnot_b_z: {
11022 llvm::Type* OverloadedTy =
getSVEType(TypeFlags);
11024 return Builder.CreateCall(F, {Ops[0], Ops[1], Ops[0]});
11027 case SVE::BI__builtin_sve_svmovlb_u16:
11028 case SVE::BI__builtin_sve_svmovlb_u32:
11029 case SVE::BI__builtin_sve_svmovlb_u64:
11030 return EmitSVEMovl(TypeFlags, Ops, Intrinsic::aarch64_sve_ushllb);
11032 case SVE::BI__builtin_sve_svmovlb_s16:
11033 case SVE::BI__builtin_sve_svmovlb_s32:
11034 case SVE::BI__builtin_sve_svmovlb_s64:
11035 return EmitSVEMovl(TypeFlags, Ops, Intrinsic::aarch64_sve_sshllb);
11037 case SVE::BI__builtin_sve_svmovlt_u16:
11038 case SVE::BI__builtin_sve_svmovlt_u32:
11039 case SVE::BI__builtin_sve_svmovlt_u64:
11040 return EmitSVEMovl(TypeFlags, Ops, Intrinsic::aarch64_sve_ushllt);
11042 case SVE::BI__builtin_sve_svmovlt_s16:
11043 case SVE::BI__builtin_sve_svmovlt_s32:
11044 case SVE::BI__builtin_sve_svmovlt_s64:
11045 return EmitSVEMovl(TypeFlags, Ops, Intrinsic::aarch64_sve_sshllt);
11047 case SVE::BI__builtin_sve_svpmullt_u16:
11048 case SVE::BI__builtin_sve_svpmullt_u64:
11049 case SVE::BI__builtin_sve_svpmullt_n_u16:
11050 case SVE::BI__builtin_sve_svpmullt_n_u64:
11051 return EmitSVEPMull(TypeFlags, Ops, Intrinsic::aarch64_sve_pmullt_pair);
11053 case SVE::BI__builtin_sve_svpmullb_u16:
11054 case SVE::BI__builtin_sve_svpmullb_u64:
11055 case SVE::BI__builtin_sve_svpmullb_n_u16:
11056 case SVE::BI__builtin_sve_svpmullb_n_u64:
11057 return EmitSVEPMull(TypeFlags, Ops, Intrinsic::aarch64_sve_pmullb_pair);
11059 case SVE::BI__builtin_sve_svdup_n_b8:
11060 case SVE::BI__builtin_sve_svdup_n_b16:
11061 case SVE::BI__builtin_sve_svdup_n_b32:
11062 case SVE::BI__builtin_sve_svdup_n_b64: {
11064 Builder.CreateICmpNE(Ops[0], Constant::getNullValue(Ops[0]->getType()));
11065 llvm::ScalableVectorType *OverloadedTy =
getSVEType(TypeFlags);
11070 case SVE::BI__builtin_sve_svdupq_n_b8:
11071 case SVE::BI__builtin_sve_svdupq_n_b16:
11072 case SVE::BI__builtin_sve_svdupq_n_b32:
11073 case SVE::BI__builtin_sve_svdupq_n_b64:
11074 case SVE::BI__builtin_sve_svdupq_n_u8:
11075 case SVE::BI__builtin_sve_svdupq_n_s8:
11076 case SVE::BI__builtin_sve_svdupq_n_u64:
11077 case SVE::BI__builtin_sve_svdupq_n_f64:
11078 case SVE::BI__builtin_sve_svdupq_n_s64:
11079 case SVE::BI__builtin_sve_svdupq_n_u16:
11080 case SVE::BI__builtin_sve_svdupq_n_f16:
11081 case SVE::BI__builtin_sve_svdupq_n_bf16:
11082 case SVE::BI__builtin_sve_svdupq_n_s16:
11083 case SVE::BI__builtin_sve_svdupq_n_u32:
11084 case SVE::BI__builtin_sve_svdupq_n_f32:
11085 case SVE::BI__builtin_sve_svdupq_n_s32: {
11088 unsigned NumOpnds = Ops.size();
11091 cast<llvm::VectorType>(Ty)->getElementType()->isIntegerTy(1);
11096 llvm::Type *EltTy = Ops[0]->getType();
11101 for (
unsigned I = 0; I < NumOpnds; ++I)
11102 VecOps.push_back(
Builder.CreateZExt(Ops[I], EltTy));
11107 OverloadedTy, PoisonValue::get(OverloadedTy), Vec,
Builder.getInt64(0));
11122 : Intrinsic::aarch64_sve_cmpne_wide,
11129 case SVE::BI__builtin_sve_svpfalse_b:
11130 return ConstantInt::getFalse(Ty);
11132 case SVE::BI__builtin_sve_svpfalse_c: {
11133 auto SVBoolTy = ScalableVectorType::get(
Builder.getInt1Ty(), 16);
11136 return Builder.CreateCall(CastToSVCountF, ConstantInt::getFalse(SVBoolTy));
11139 case SVE::BI__builtin_sve_svlen_bf16:
11140 case SVE::BI__builtin_sve_svlen_f16:
11141 case SVE::BI__builtin_sve_svlen_f32:
11142 case SVE::BI__builtin_sve_svlen_f64:
11143 case SVE::BI__builtin_sve_svlen_s8:
11144 case SVE::BI__builtin_sve_svlen_s16:
11145 case SVE::BI__builtin_sve_svlen_s32:
11146 case SVE::BI__builtin_sve_svlen_s64:
11147 case SVE::BI__builtin_sve_svlen_u8:
11148 case SVE::BI__builtin_sve_svlen_u16:
11149 case SVE::BI__builtin_sve_svlen_u32:
11150 case SVE::BI__builtin_sve_svlen_u64: {
11152 auto VTy = cast<llvm::VectorType>(
getSVEType(TF));
11154 llvm::ConstantInt::get(Ty, VTy->getElementCount().getKnownMinValue());
11160 case SVE::BI__builtin_sve_svtbl2_u8:
11161 case SVE::BI__builtin_sve_svtbl2_s8:
11162 case SVE::BI__builtin_sve_svtbl2_u16:
11163 case SVE::BI__builtin_sve_svtbl2_s16:
11164 case SVE::BI__builtin_sve_svtbl2_u32:
11165 case SVE::BI__builtin_sve_svtbl2_s32:
11166 case SVE::BI__builtin_sve_svtbl2_u64:
11167 case SVE::BI__builtin_sve_svtbl2_s64:
11168 case SVE::BI__builtin_sve_svtbl2_f16:
11169 case SVE::BI__builtin_sve_svtbl2_bf16:
11170 case SVE::BI__builtin_sve_svtbl2_f32:
11171 case SVE::BI__builtin_sve_svtbl2_f64: {
11173 auto VTy = cast<llvm::ScalableVectorType>(
getSVEType(TF));
11175 return Builder.CreateCall(F, Ops);
11178 case SVE::BI__builtin_sve_svset_neonq_s8:
11179 case SVE::BI__builtin_sve_svset_neonq_s16:
11180 case SVE::BI__builtin_sve_svset_neonq_s32:
11181 case SVE::BI__builtin_sve_svset_neonq_s64:
11182 case SVE::BI__builtin_sve_svset_neonq_u8:
11183 case SVE::BI__builtin_sve_svset_neonq_u16:
11184 case SVE::BI__builtin_sve_svset_neonq_u32:
11185 case SVE::BI__builtin_sve_svset_neonq_u64:
11186 case SVE::BI__builtin_sve_svset_neonq_f16:
11187 case SVE::BI__builtin_sve_svset_neonq_f32:
11188 case SVE::BI__builtin_sve_svset_neonq_f64:
11189 case SVE::BI__builtin_sve_svset_neonq_bf16: {
11190 return Builder.CreateInsertVector(Ty, Ops[0], Ops[1],
Builder.getInt64(0));
11193 case SVE::BI__builtin_sve_svget_neonq_s8:
11194 case SVE::BI__builtin_sve_svget_neonq_s16:
11195 case SVE::BI__builtin_sve_svget_neonq_s32:
11196 case SVE::BI__builtin_sve_svget_neonq_s64:
11197 case SVE::BI__builtin_sve_svget_neonq_u8:
11198 case SVE::BI__builtin_sve_svget_neonq_u16:
11199 case SVE::BI__builtin_sve_svget_neonq_u32:
11200 case SVE::BI__builtin_sve_svget_neonq_u64:
11201 case SVE::BI__builtin_sve_svget_neonq_f16:
11202 case SVE::BI__builtin_sve_svget_neonq_f32:
11203 case SVE::BI__builtin_sve_svget_neonq_f64:
11204 case SVE::BI__builtin_sve_svget_neonq_bf16: {
11205 return Builder.CreateExtractVector(Ty, Ops[0],
Builder.getInt64(0));
11208 case SVE::BI__builtin_sve_svdup_neonq_s8:
11209 case SVE::BI__builtin_sve_svdup_neonq_s16:
11210 case SVE::BI__builtin_sve_svdup_neonq_s32:
11211 case SVE::BI__builtin_sve_svdup_neonq_s64:
11212 case SVE::BI__builtin_sve_svdup_neonq_u8:
11213 case SVE::BI__builtin_sve_svdup_neonq_u16:
11214 case SVE::BI__builtin_sve_svdup_neonq_u32:
11215 case SVE::BI__builtin_sve_svdup_neonq_u64:
11216 case SVE::BI__builtin_sve_svdup_neonq_f16:
11217 case SVE::BI__builtin_sve_svdup_neonq_f32:
11218 case SVE::BI__builtin_sve_svdup_neonq_f64:
11219 case SVE::BI__builtin_sve_svdup_neonq_bf16: {
11222 return Builder.CreateIntrinsic(Intrinsic::aarch64_sve_dupq_lane, {Ty},
11234 switch (BuiltinID) {
11237 case SME::BI__builtin_sme_svsumla_za32_s8_vg4x1:
11240 case SME::BI__builtin_sme_svsumla_za32_s8_vg4x2:
11241 case SME::BI__builtin_sme_svsudot_za32_s8_vg1x2:
11244 case SME::BI__builtin_sme_svsudot_za32_s8_vg1x4:
11245 case SME::BI__builtin_sme_svsumla_za32_s8_vg4x4:
11251 for (
unsigned I = 0; I < MultiVec; ++I)
11252 std::swap(Ops[I + 1], Ops[I + 1 + MultiVec]);
11265 return EmitSMELd1St1(TypeFlags, Ops, Builtin->LLVMIntrinsic);
11268 else if (BuiltinID == SME::BI__builtin_sme_svzero_mask_za ||
11269 BuiltinID == SME::BI__builtin_sme_svzero_za)
11270 return EmitSMEZero(TypeFlags, Ops, Builtin->LLVMIntrinsic);
11271 else if (BuiltinID == SME::BI__builtin_sme_svldr_vnum_za ||
11272 BuiltinID == SME::BI__builtin_sme_svstr_vnum_za ||
11273 BuiltinID == SME::BI__builtin_sme_svldr_za ||
11274 BuiltinID == SME::BI__builtin_sme_svstr_za)
11275 return EmitSMELdrStr(TypeFlags, Ops, Builtin->LLVMIntrinsic);
11280 Ops.pop_back_val());
11285 if (Builtin->LLVMIntrinsic == 0)
11289 for (
unsigned i = 0, e = Ops.size(); i != e; ++i)
11290 if (
auto PredTy = dyn_cast<llvm::VectorType>(Ops[i]->getType()))
11291 if (PredTy->getElementType()->isIntegerTy(1))
11299 return Builder.CreateCall(F, Ops);
11304 llvm::Triple::ArchType Arch) {
11313 if (BuiltinID == Builtin::BI__builtin_cpu_supports)
11314 return EmitAArch64CpuSupports(
E);
11316 unsigned HintID =
static_cast<unsigned>(-1);
11317 switch (BuiltinID) {
11319 case clang::AArch64::BI__builtin_arm_nop:
11322 case clang::AArch64::BI__builtin_arm_yield:
11323 case clang::AArch64::BI__yield:
11326 case clang::AArch64::BI__builtin_arm_wfe:
11327 case clang::AArch64::BI__wfe:
11330 case clang::AArch64::BI__builtin_arm_wfi:
11331 case clang::AArch64::BI__wfi:
11334 case clang::AArch64::BI__builtin_arm_sev:
11335 case clang::AArch64::BI__sev:
11338 case clang::AArch64::BI__builtin_arm_sevl:
11339 case clang::AArch64::BI__sevl:
11344 if (HintID !=
static_cast<unsigned>(-1)) {
11346 return Builder.CreateCall(F, llvm::ConstantInt::get(
Int32Ty, HintID));
11349 if (BuiltinID == clang::AArch64::BI__builtin_arm_trap) {
11355 if (BuiltinID == clang::AArch64::BI__builtin_arm_get_sme_state) {
11360 "__arm_sme_state"));
11362 "aarch64_pstate_sm_compatible");
11363 CI->setAttributes(Attrs);
11364 CI->setCallingConv(
11365 llvm::CallingConv::
11366 AArch64_SME_ABI_Support_Routines_PreserveMost_From_X2);
11373 if (BuiltinID == clang::AArch64::BI__builtin_arm_rbit) {
11375 "rbit of unusual size!");
11378 CGM.
getIntrinsic(Intrinsic::bitreverse, Arg->getType()), Arg,
"rbit");
11380 if (BuiltinID == clang::AArch64::BI__builtin_arm_rbit64) {
11382 "rbit of unusual size!");
11385 CGM.
getIntrinsic(Intrinsic::bitreverse, Arg->getType()), Arg,
"rbit");
11388 if (BuiltinID == clang::AArch64::BI__builtin_arm_clz ||
11389 BuiltinID == clang::AArch64::BI__builtin_arm_clz64) {
11393 if (BuiltinID == clang::AArch64::BI__builtin_arm_clz64)
11398 if (BuiltinID == clang::AArch64::BI__builtin_arm_cls) {
11403 if (BuiltinID == clang::AArch64::BI__builtin_arm_cls64) {
11409 if (BuiltinID == clang::AArch64::BI__builtin_arm_rint32zf ||
11410 BuiltinID == clang::AArch64::BI__builtin_arm_rint32z) {
11412 llvm::Type *Ty = Arg->getType();
11417 if (BuiltinID == clang::AArch64::BI__builtin_arm_rint64zf ||
11418 BuiltinID == clang::AArch64::BI__builtin_arm_rint64z) {
11420 llvm::Type *Ty = Arg->getType();
11425 if (BuiltinID == clang::AArch64::BI__builtin_arm_rint32xf ||
11426 BuiltinID == clang::AArch64::BI__builtin_arm_rint32x) {
11428 llvm::Type *Ty = Arg->getType();
11433 if (BuiltinID == clang::AArch64::BI__builtin_arm_rint64xf ||
11434 BuiltinID == clang::AArch64::BI__builtin_arm_rint64x) {
11436 llvm::Type *Ty = Arg->getType();
11441 if (BuiltinID == clang::AArch64::BI__builtin_arm_jcvt) {
11443 "__jcvt of unusual size!");
11449 if (BuiltinID == clang::AArch64::BI__builtin_arm_ld64b ||
11450 BuiltinID == clang::AArch64::BI__builtin_arm_st64b ||
11451 BuiltinID == clang::AArch64::BI__builtin_arm_st64bv ||
11452 BuiltinID == clang::AArch64::BI__builtin_arm_st64bv0) {
11456 if (BuiltinID == clang::AArch64::BI__builtin_arm_ld64b) {
11460 llvm::Value *Val =
Builder.CreateCall(F, MemAddr);
11461 llvm::Value *ToRet;
11462 for (
size_t i = 0; i < 8; i++) {
11463 llvm::Value *ValOffsetPtr =
11474 Args.push_back(MemAddr);
11475 for (
size_t i = 0; i < 8; i++) {
11476 llvm::Value *ValOffsetPtr =
11483 auto Intr = (BuiltinID == clang::AArch64::BI__builtin_arm_st64b
11484 ? Intrinsic::aarch64_st64b
11485 : BuiltinID == clang::AArch64::BI__builtin_arm_st64bv
11486 ? Intrinsic::aarch64_st64bv
11487 : Intrinsic::aarch64_st64bv0);
11489 return Builder.CreateCall(F, Args);
11493 if (BuiltinID == clang::AArch64::BI__builtin_arm_rndr ||
11494 BuiltinID == clang::AArch64::BI__builtin_arm_rndrrs) {
11496 auto Intr = (BuiltinID == clang::AArch64::BI__builtin_arm_rndr
11497 ? Intrinsic::aarch64_rndr
11498 : Intrinsic::aarch64_rndrrs);
11500 llvm::Value *Val =
Builder.CreateCall(F);
11501 Value *RandomValue =
Builder.CreateExtractValue(Val, 0);
11510 if (BuiltinID == clang::AArch64::BI__clear_cache) {
11511 assert(
E->getNumArgs() == 2 &&
"__clear_cache takes 2 arguments");
11514 for (
unsigned i = 0; i < 2; i++)
11517 llvm::FunctionType *FTy = cast<llvm::FunctionType>(Ty);
11518 StringRef Name = FD->
getName();
11522 if ((BuiltinID == clang::AArch64::BI__builtin_arm_ldrex ||
11523 BuiltinID == clang::AArch64::BI__builtin_arm_ldaex) &&
11527 ? Intrinsic::aarch64_ldaxp
11528 : Intrinsic::aarch64_ldxp);
11535 llvm::Type *Int128Ty = llvm::IntegerType::get(
getLLVMContext(), 128);
11536 Val0 =
Builder.CreateZExt(Val0, Int128Ty);
11537 Val1 =
Builder.CreateZExt(Val1, Int128Ty);
11539 Value *ShiftCst = llvm::ConstantInt::get(Int128Ty, 64);
11540 Val =
Builder.CreateShl(Val0, ShiftCst,
"shl",
true );
11541 Val =
Builder.CreateOr(Val, Val1);
11543 }
else if (BuiltinID == clang::AArch64::BI__builtin_arm_ldrex ||
11544 BuiltinID == clang::AArch64::BI__builtin_arm_ldaex) {
11549 llvm::Type *
IntTy =
11554 ? Intrinsic::aarch64_ldaxr
11555 : Intrinsic::aarch64_ldxr,
11557 CallInst *Val =
Builder.CreateCall(F, LoadAddr,
"ldxr");
11561 if (RealResTy->isPointerTy())
11562 return Builder.CreateIntToPtr(Val, RealResTy);
11564 llvm::Type *IntResTy = llvm::IntegerType::get(
11566 return Builder.CreateBitCast(
Builder.CreateTruncOrBitCast(Val, IntResTy),
11570 if ((BuiltinID == clang::AArch64::BI__builtin_arm_strex ||
11571 BuiltinID == clang::AArch64::BI__builtin_arm_stlex) &&
11575 ? Intrinsic::aarch64_stlxp
11576 : Intrinsic::aarch64_stxp);
11588 return Builder.CreateCall(F, {Arg0, Arg1, StPtr},
"stxp");
11591 if (BuiltinID == clang::AArch64::BI__builtin_arm_strex ||
11592 BuiltinID == clang::AArch64::BI__builtin_arm_stlex) {
11597 llvm::Type *StoreTy =
11600 if (StoreVal->
getType()->isPointerTy())
11603 llvm::Type *
IntTy = llvm::IntegerType::get(
11612 ? Intrinsic::aarch64_stlxr
11613 : Intrinsic::aarch64_stxr,
11615 CallInst *CI =
Builder.CreateCall(F, {StoreVal, StoreAddr},
"stxr");
11617 1, Attribute::get(
getLLVMContext(), Attribute::ElementType, StoreTy));
11621 if (BuiltinID == clang::AArch64::BI__getReg) {
11624 llvm_unreachable(
"Sema will ensure that the parameter is constant");
11630 llvm::Metadata *Ops[] = {llvm::MDString::get(Context, Reg)};
11631 llvm::MDNode *RegName = llvm::MDNode::get(Context, Ops);
11632 llvm::Value *Metadata = llvm::MetadataAsValue::get(Context, RegName);
11634 llvm::Function *F =
11636 return Builder.CreateCall(F, Metadata);
11639 if (BuiltinID == clang::AArch64::BI__break) {
11642 llvm_unreachable(
"Sema will ensure that the parameter is constant");
11644 llvm::Function *F =
CGM.
getIntrinsic(llvm::Intrinsic::aarch64_break);
11648 if (BuiltinID == clang::AArch64::BI__builtin_arm_clrex) {
11650 return Builder.CreateCall(F);
11653 if (BuiltinID == clang::AArch64::BI_ReadWriteBarrier)
11654 return Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent,
11655 llvm::SyncScope::SingleThread);
11658 Intrinsic::ID CRCIntrinsicID = Intrinsic::not_intrinsic;
11659 switch (BuiltinID) {
11660 case clang::AArch64::BI__builtin_arm_crc32b:
11661 CRCIntrinsicID = Intrinsic::aarch64_crc32b;
break;
11662 case clang::AArch64::BI__builtin_arm_crc32cb:
11663 CRCIntrinsicID = Intrinsic::aarch64_crc32cb;
break;
11664 case clang::AArch64::BI__builtin_arm_crc32h:
11665 CRCIntrinsicID = Intrinsic::aarch64_crc32h;
break;
11666 case clang::AArch64::BI__builtin_arm_crc32ch:
11667 CRCIntrinsicID = Intrinsic::aarch64_crc32ch;
break;
11668 case clang::AArch64::BI__builtin_arm_crc32w:
11669 CRCIntrinsicID = Intrinsic::aarch64_crc32w;
break;
11670 case clang::AArch64::BI__builtin_arm_crc32cw:
11671 CRCIntrinsicID = Intrinsic::aarch64_crc32cw;
break;
11672 case clang::AArch64::BI__builtin_arm_crc32d:
11673 CRCIntrinsicID = Intrinsic::aarch64_crc32x;
break;
11674 case clang::AArch64::BI__builtin_arm_crc32cd:
11675 CRCIntrinsicID = Intrinsic::aarch64_crc32cx;
break;
11678 if (CRCIntrinsicID != Intrinsic::not_intrinsic) {
11683 llvm::Type *DataTy = F->getFunctionType()->getParamType(1);
11684 Arg1 =
Builder.CreateZExtOrBitCast(Arg1, DataTy);
11686 return Builder.CreateCall(F, {Arg0, Arg1});
11690 if (BuiltinID == AArch64::BI__builtin_arm_mops_memset_tag) {
11697 CGM.
getIntrinsic(Intrinsic::aarch64_mops_memset_tag), {Dst, Val, Size});
11701 Intrinsic::ID MTEIntrinsicID = Intrinsic::not_intrinsic;
11702 switch (BuiltinID) {
11703 case clang::AArch64::BI__builtin_arm_irg:
11704 MTEIntrinsicID = Intrinsic::aarch64_irg;
break;
11705 case clang::AArch64::BI__builtin_arm_addg:
11706 MTEIntrinsicID = Intrinsic::aarch64_addg;
break;
11707 case clang::AArch64::BI__builtin_arm_gmi:
11708 MTEIntrinsicID = Intrinsic::aarch64_gmi;
break;
11709 case clang::AArch64::BI__builtin_arm_ldg:
11710 MTEIntrinsicID = Intrinsic::aarch64_ldg;
break;
11711 case clang::AArch64::BI__builtin_arm_stg:
11712 MTEIntrinsicID = Intrinsic::aarch64_stg;
break;
11713 case clang::AArch64::BI__builtin_arm_subp:
11714 MTEIntrinsicID = Intrinsic::aarch64_subp;
break;
11717 if (MTEIntrinsicID != Intrinsic::not_intrinsic) {
11718 if (MTEIntrinsicID == Intrinsic::aarch64_irg) {
11726 if (MTEIntrinsicID == Intrinsic::aarch64_addg) {
11732 {Pointer, TagOffset});
11734 if (MTEIntrinsicID == Intrinsic::aarch64_gmi) {
11745 if (MTEIntrinsicID == Intrinsic::aarch64_ldg) {
11748 {TagAddress, TagAddress});
11753 if (MTEIntrinsicID == Intrinsic::aarch64_stg) {
11756 {TagAddress, TagAddress});
11758 if (MTEIntrinsicID == Intrinsic::aarch64_subp) {
11766 if (BuiltinID == clang::AArch64::BI__builtin_arm_rsr ||
11767 BuiltinID == clang::AArch64::BI__builtin_arm_rsr64 ||
11768 BuiltinID == clang::AArch64::BI__builtin_arm_rsr128 ||
11769 BuiltinID == clang::AArch64::BI__builtin_arm_rsrp ||
11770 BuiltinID == clang::AArch64::BI__builtin_arm_wsr ||
11771 BuiltinID == clang::AArch64::BI__builtin_arm_wsr64 ||
11772 BuiltinID == clang::AArch64::BI__builtin_arm_wsr128 ||
11773 BuiltinID == clang::AArch64::BI__builtin_arm_wsrp) {
11776 if (BuiltinID == clang::AArch64::BI__builtin_arm_rsr ||
11777 BuiltinID == clang::AArch64::BI__builtin_arm_rsr64 ||
11778 BuiltinID == clang::AArch64::BI__builtin_arm_rsr128 ||
11779 BuiltinID == clang::AArch64::BI__builtin_arm_rsrp)
11782 bool IsPointerBuiltin = BuiltinID == clang::AArch64::BI__builtin_arm_rsrp ||
11783 BuiltinID == clang::AArch64::BI__builtin_arm_wsrp;
11785 bool Is32Bit = BuiltinID == clang::AArch64::BI__builtin_arm_rsr ||
11786 BuiltinID == clang::AArch64::BI__builtin_arm_wsr;
11788 bool Is128Bit = BuiltinID == clang::AArch64::BI__builtin_arm_rsr128 ||
11789 BuiltinID == clang::AArch64::BI__builtin_arm_wsr128;
11791 llvm::Type *ValueType;
11795 }
else if (Is128Bit) {
11796 llvm::Type *Int128Ty =
11798 ValueType = Int128Ty;
11800 }
else if (IsPointerBuiltin) {
11810 if (BuiltinID == clang::AArch64::BI_ReadStatusReg ||
11811 BuiltinID == clang::AArch64::BI_WriteStatusReg) {
11817 std::string SysRegStr;
11818 llvm::raw_string_ostream(SysRegStr) <<
11819 ((1 << 1) | ((SysReg >> 14) & 1)) <<
":" <<
11820 ((SysReg >> 11) & 7) <<
":" <<
11821 ((SysReg >> 7) & 15) <<
":" <<
11822 ((SysReg >> 3) & 15) <<
":" <<
11825 llvm::Metadata *Ops[] = { llvm::MDString::get(Context, SysRegStr) };
11826 llvm::MDNode *RegName = llvm::MDNode::get(Context, Ops);
11827 llvm::Value *Metadata = llvm::MetadataAsValue::get(Context, RegName);
11832 if (BuiltinID == clang::AArch64::BI_ReadStatusReg) {
11833 llvm::Function *F =
CGM.
getIntrinsic(llvm::Intrinsic::read_register, Types);
11835 return Builder.CreateCall(F, Metadata);
11838 llvm::Function *F =
CGM.
getIntrinsic(llvm::Intrinsic::write_register, Types);
11841 return Builder.CreateCall(F, { Metadata, ArgValue });
11844 if (BuiltinID == clang::AArch64::BI_AddressOfReturnAddress) {
11845 llvm::Function *F =
11847 return Builder.CreateCall(F);
11850 if (BuiltinID == clang::AArch64::BI__builtin_sponentry) {
11852 return Builder.CreateCall(F);
11855 if (BuiltinID == clang::AArch64::BI__mulh ||
11856 BuiltinID == clang::AArch64::BI__umulh) {
11858 llvm::Type *Int128Ty = llvm::IntegerType::get(
getLLVMContext(), 128);
11860 bool IsSigned = BuiltinID == clang::AArch64::BI__mulh;
11866 Value *MulResult, *HigherBits;
11868 MulResult =
Builder.CreateNSWMul(LHS, RHS);
11869 HigherBits =
Builder.CreateAShr(MulResult, 64);
11871 MulResult =
Builder.CreateNUWMul(LHS, RHS);
11872 HigherBits =
Builder.CreateLShr(MulResult, 64);
11874 HigherBits =
Builder.CreateIntCast(HigherBits, ResType, IsSigned);
11879 if (BuiltinID == AArch64::BI__writex18byte ||
11880 BuiltinID == AArch64::BI__writex18word ||
11881 BuiltinID == AArch64::BI__writex18dword ||
11882 BuiltinID == AArch64::BI__writex18qword) {
11898 if (BuiltinID == AArch64::BI__readx18byte ||
11899 BuiltinID == AArch64::BI__readx18word ||
11900 BuiltinID == AArch64::BI__readx18dword ||
11901 BuiltinID == AArch64::BI__readx18qword) {
11916 if (BuiltinID == AArch64::BI__addx18byte ||
11917 BuiltinID == AArch64::BI__addx18word ||
11918 BuiltinID == AArch64::BI__addx18dword ||
11919 BuiltinID == AArch64::BI__addx18qword ||
11920 BuiltinID == AArch64::BI__incx18byte ||
11921 BuiltinID == AArch64::BI__incx18word ||
11922 BuiltinID == AArch64::BI__incx18dword ||
11923 BuiltinID == AArch64::BI__incx18qword) {
11926 switch (BuiltinID) {
11927 case AArch64::BI__incx18byte:
11929 isIncrement =
true;
11931 case AArch64::BI__incx18word:
11933 isIncrement =
true;
11935 case AArch64::BI__incx18dword:
11937 isIncrement =
true;
11939 case AArch64::BI__incx18qword:
11941 isIncrement =
true;
11945 isIncrement =
false;
11970 if (BuiltinID == AArch64::BI_CopyDoubleFromInt64 ||
11971 BuiltinID == AArch64::BI_CopyFloatFromInt32 ||
11972 BuiltinID == AArch64::BI_CopyInt32FromFloat ||
11973 BuiltinID == AArch64::BI_CopyInt64FromDouble) {
11976 return Builder.CreateBitCast(Arg, RetTy);
11979 if (BuiltinID == AArch64::BI_CountLeadingOnes ||
11980 BuiltinID == AArch64::BI_CountLeadingOnes64 ||
11981 BuiltinID == AArch64::BI_CountLeadingZeros ||
11982 BuiltinID == AArch64::BI_CountLeadingZeros64) {
11984 llvm::Type *ArgType = Arg->
getType();
11986 if (BuiltinID == AArch64::BI_CountLeadingOnes ||
11987 BuiltinID == AArch64::BI_CountLeadingOnes64)
11988 Arg =
Builder.CreateXor(Arg, Constant::getAllOnesValue(ArgType));
11993 if (BuiltinID == AArch64::BI_CountLeadingOnes64 ||
11994 BuiltinID == AArch64::BI_CountLeadingZeros64)
11999 if (BuiltinID == AArch64::BI_CountLeadingSigns ||
12000 BuiltinID == AArch64::BI_CountLeadingSigns64) {
12003 Function *F = (BuiltinID == AArch64::BI_CountLeadingSigns)
12008 if (BuiltinID == AArch64::BI_CountLeadingSigns64)
12013 if (BuiltinID == AArch64::BI_CountOneBits ||
12014 BuiltinID == AArch64::BI_CountOneBits64) {
12016 llvm::Type *ArgType = ArgValue->
getType();
12020 if (BuiltinID == AArch64::BI_CountOneBits64)
12025 if (BuiltinID == AArch64::BI__prefetch) {
12034 if (BuiltinID == AArch64::BI__hlt) {
12040 return ConstantInt::get(
Builder.getInt32Ty(), 0);
12045 if (std::optional<MSVCIntrin> MsvcIntId =
12051 return P.first == BuiltinID;
12054 BuiltinID = It->second;
12058 unsigned ICEArguments = 0;
12065 for (
unsigned i = 0, e =
E->getNumArgs() - 1; i != e; i++) {
12067 switch (BuiltinID) {
12068 case NEON::BI__builtin_neon_vld1_v:
12069 case NEON::BI__builtin_neon_vld1q_v:
12070 case NEON::BI__builtin_neon_vld1_dup_v:
12071 case NEON::BI__builtin_neon_vld1q_dup_v:
12072 case NEON::BI__builtin_neon_vld1_lane_v:
12073 case NEON::BI__builtin_neon_vld1q_lane_v:
12074 case NEON::BI__builtin_neon_vst1_v:
12075 case NEON::BI__builtin_neon_vst1q_v:
12076 case NEON::BI__builtin_neon_vst1_lane_v:
12077 case NEON::BI__builtin_neon_vst1q_lane_v:
12078 case NEON::BI__builtin_neon_vldap1_lane_s64:
12079 case NEON::BI__builtin_neon_vldap1q_lane_s64:
12080 case NEON::BI__builtin_neon_vstl1_lane_s64:
12081 case NEON::BI__builtin_neon_vstl1q_lane_s64:
12099 assert(
Result &&
"SISD intrinsic should have been handled");
12103 const Expr *Arg =
E->getArg(
E->getNumArgs()-1);
12105 if (std::optional<llvm::APSInt>
Result =
12110 bool usgn =
Type.isUnsigned();
12111 bool quad =
Type.isQuad();
12114 switch (BuiltinID) {
12116 case NEON::BI__builtin_neon_vabsh_f16:
12119 case NEON::BI__builtin_neon_vaddq_p128: {
12122 Ops[0] =
Builder.CreateBitCast(Ops[0], Ty);
12123 Ops[1] =
Builder.CreateBitCast(Ops[1], Ty);
12124 Ops[0] =
Builder.CreateXor(Ops[0], Ops[1]);
12125 llvm::Type *Int128Ty = llvm::Type::getIntNTy(
getLLVMContext(), 128);
12126 return Builder.CreateBitCast(Ops[0], Int128Ty);
12128 case NEON::BI__builtin_neon_vldrq_p128: {
12129 llvm::Type *Int128Ty = llvm::Type::getIntNTy(
getLLVMContext(), 128);
12134 case NEON::BI__builtin_neon_vstrq_p128: {
12135 Value *Ptr = Ops[0];
12138 case NEON::BI__builtin_neon_vcvts_f32_u32:
12139 case NEON::BI__builtin_neon_vcvtd_f64_u64:
12142 case NEON::BI__builtin_neon_vcvts_f32_s32:
12143 case NEON::BI__builtin_neon_vcvtd_f64_s64: {
12145 bool Is64 = Ops[0]->getType()->getPrimitiveSizeInBits() == 64;
12148 Ops[0] =
Builder.CreateBitCast(Ops[0], InTy);
12150 return Builder.CreateUIToFP(Ops[0], FTy);
12151 return Builder.CreateSIToFP(Ops[0], FTy);
12153 case NEON::BI__builtin_neon_vcvth_f16_u16:
12154 case NEON::BI__builtin_neon_vcvth_f16_u32:
12155 case NEON::BI__builtin_neon_vcvth_f16_u64:
12158 case NEON::BI__builtin_neon_vcvth_f16_s16:
12159 case NEON::BI__builtin_neon_vcvth_f16_s32:
12160 case NEON::BI__builtin_neon_vcvth_f16_s64: {
12162 llvm::Type *FTy =
HalfTy;
12164 if (Ops[0]->getType()->getPrimitiveSizeInBits() == 64)
12166 else if (Ops[0]->getType()->getPrimitiveSizeInBits() == 32)
12170 Ops[0] =
Builder.CreateBitCast(Ops[0], InTy);
12172 return Builder.CreateUIToFP(Ops[0], FTy);
12173 return Builder.CreateSIToFP(Ops[0], FTy);
12175 case NEON::BI__builtin_neon_vcvtah_u16_f16:
12176 case NEON::BI__builtin_neon_vcvtmh_u16_f16:
12177 case NEON::BI__builtin_neon_vcvtnh_u16_f16:
12178 case NEON::BI__builtin_neon_vcvtph_u16_f16:
12179 case NEON::BI__builtin_neon_vcvth_u16_f16:
12180 case NEON::BI__builtin_neon_vcvtah_s16_f16:
12181 case NEON::BI__builtin_neon_vcvtmh_s16_f16:
12182 case NEON::BI__builtin_neon_vcvtnh_s16_f16:
12183 case NEON::BI__builtin_neon_vcvtph_s16_f16:
12184 case NEON::BI__builtin_neon_vcvth_s16_f16: {
12187 llvm::Type* FTy =
HalfTy;
12188 llvm::Type *Tys[2] = {InTy, FTy};
12190 switch (BuiltinID) {
12191 default: llvm_unreachable(
"missing builtin ID in switch!");
12192 case NEON::BI__builtin_neon_vcvtah_u16_f16:
12193 Int = Intrinsic::aarch64_neon_fcvtau;
break;
12194 case NEON::BI__builtin_neon_vcvtmh_u16_f16:
12195 Int = Intrinsic::aarch64_neon_fcvtmu;
break;
12196 case NEON::BI__builtin_neon_vcvtnh_u16_f16:
12197 Int = Intrinsic::aarch64_neon_fcvtnu;
break;
12198 case NEON::BI__builtin_neon_vcvtph_u16_f16:
12199 Int = Intrinsic::aarch64_neon_fcvtpu;
break;
12200 case NEON::BI__builtin_neon_vcvth_u16_f16:
12201 Int = Intrinsic::aarch64_neon_fcvtzu;
break;
12202 case NEON::BI__builtin_neon_vcvtah_s16_f16:
12203 Int = Intrinsic::aarch64_neon_fcvtas;
break;
12204 case NEON::BI__builtin_neon_vcvtmh_s16_f16:
12205 Int = Intrinsic::aarch64_neon_fcvtms;
break;
12206 case NEON::BI__builtin_neon_vcvtnh_s16_f16:
12207 Int = Intrinsic::aarch64_neon_fcvtns;
break;
12208 case NEON::BI__builtin_neon_vcvtph_s16_f16:
12209 Int = Intrinsic::aarch64_neon_fcvtps;
break;
12210 case NEON::BI__builtin_neon_vcvth_s16_f16:
12211 Int = Intrinsic::aarch64_neon_fcvtzs;
break;
12216 case NEON::BI__builtin_neon_vcaleh_f16:
12217 case NEON::BI__builtin_neon_vcalth_f16:
12218 case NEON::BI__builtin_neon_vcageh_f16:
12219 case NEON::BI__builtin_neon_vcagth_f16: {
12222 llvm::Type* FTy =
HalfTy;
12223 llvm::Type *Tys[2] = {InTy, FTy};
12225 switch (BuiltinID) {
12226 default: llvm_unreachable(
"missing builtin ID in switch!");
12227 case NEON::BI__builtin_neon_vcageh_f16:
12228 Int = Intrinsic::aarch64_neon_facge;
break;
12229 case NEON::BI__builtin_neon_vcagth_f16:
12230 Int = Intrinsic::aarch64_neon_facgt;
break;
12231 case NEON::BI__builtin_neon_vcaleh_f16:
12232 Int = Intrinsic::aarch64_neon_facge; std::swap(Ops[0], Ops[1]);
break;
12233 case NEON::BI__builtin_neon_vcalth_f16:
12234 Int = Intrinsic::aarch64_neon_facgt; std::swap(Ops[0], Ops[1]);
break;
12239 case NEON::BI__builtin_neon_vcvth_n_s16_f16:
12240 case NEON::BI__builtin_neon_vcvth_n_u16_f16: {
12243 llvm::Type* FTy =
HalfTy;
12244 llvm::Type *Tys[2] = {InTy, FTy};
12246 switch (BuiltinID) {
12247 default: llvm_unreachable(
"missing builtin ID in switch!");
12248 case NEON::BI__builtin_neon_vcvth_n_s16_f16:
12249 Int = Intrinsic::aarch64_neon_vcvtfp2fxs;
break;
12250 case NEON::BI__builtin_neon_vcvth_n_u16_f16:
12251 Int = Intrinsic::aarch64_neon_vcvtfp2fxu;
break;
12256 case NEON::BI__builtin_neon_vcvth_n_f16_s16:
12257 case NEON::BI__builtin_neon_vcvth_n_f16_u16: {
12259 llvm::Type* FTy =
HalfTy;
12261 llvm::Type *Tys[2] = {FTy, InTy};
12263 switch (BuiltinID) {
12264 default: llvm_unreachable(
"missing builtin ID in switch!");
12265 case NEON::BI__builtin_neon_vcvth_n_f16_s16:
12266 Int = Intrinsic::aarch64_neon_vcvtfxs2fp;
12267 Ops[0] =
Builder.CreateSExt(Ops[0], InTy,
"sext");
12269 case NEON::BI__builtin_neon_vcvth_n_f16_u16:
12270 Int = Intrinsic::aarch64_neon_vcvtfxu2fp;
12271 Ops[0] =
Builder.CreateZExt(Ops[0], InTy);
12276 case NEON::BI__builtin_neon_vpaddd_s64: {
12277 auto *Ty = llvm::FixedVectorType::get(
Int64Ty, 2);
12280 Vec =
Builder.CreateBitCast(Vec, Ty,
"v2i64");
12281 llvm::Value *Idx0 = llvm::ConstantInt::get(
SizeTy, 0);
12282 llvm::Value *Idx1 = llvm::ConstantInt::get(
SizeTy, 1);
12283 Value *Op0 =
Builder.CreateExtractElement(Vec, Idx0,
"lane0");
12284 Value *Op1 =
Builder.CreateExtractElement(Vec, Idx1,
"lane1");
12286 return Builder.CreateAdd(Op0, Op1,
"vpaddd");
12288 case NEON::BI__builtin_neon_vpaddd_f64: {
12289 auto *Ty = llvm::FixedVectorType::get(
DoubleTy, 2);
12292 Vec =
Builder.CreateBitCast(Vec, Ty,
"v2f64");
12293 llvm::Value *Idx0 = llvm::ConstantInt::get(
SizeTy, 0);
12294 llvm::Value *Idx1 = llvm::ConstantInt::get(
SizeTy, 1);
12295 Value *Op0 =
Builder.CreateExtractElement(Vec, Idx0,
"lane0");
12296 Value *Op1 =
Builder.CreateExtractElement(Vec, Idx1,
"lane1");
12298 return Builder.CreateFAdd(Op0, Op1,
"vpaddd");
12300 case NEON::BI__builtin_neon_vpadds_f32: {
12301 auto *Ty = llvm::FixedVectorType::get(
FloatTy, 2);
12304 Vec =
Builder.CreateBitCast(Vec, Ty,
"v2f32");
12305 llvm::Value *Idx0 = llvm::ConstantInt::get(
SizeTy, 0);
12306 llvm::Value *Idx1 = llvm::ConstantInt::get(
SizeTy, 1);
12307 Value *Op0 =
Builder.CreateExtractElement(Vec, Idx0,
"lane0");
12308 Value *Op1 =
Builder.CreateExtractElement(Vec, Idx1,
"lane1");
12310 return Builder.CreateFAdd(Op0, Op1,
"vpaddd");
12312 case NEON::BI__builtin_neon_vceqzd_s64:
12313 case NEON::BI__builtin_neon_vceqzd_f64:
12314 case NEON::BI__builtin_neon_vceqzs_f32:
12315 case NEON::BI__builtin_neon_vceqzh_f16:
12319 ICmpInst::FCMP_OEQ, ICmpInst::ICMP_EQ,
"vceqz");
12320 case NEON::BI__builtin_neon_vcgezd_s64:
12321 case NEON::BI__builtin_neon_vcgezd_f64:
12322 case NEON::BI__builtin_neon_vcgezs_f32:
12323 case NEON::BI__builtin_neon_vcgezh_f16:
12327 ICmpInst::FCMP_OGE, ICmpInst::ICMP_SGE,
"vcgez");
12328 case NEON::BI__builtin_neon_vclezd_s64:
12329 case NEON::BI__builtin_neon_vclezd_f64:
12330 case NEON::BI__builtin_neon_vclezs_f32:
12331 case NEON::BI__builtin_neon_vclezh_f16:
12335 ICmpInst::FCMP_OLE, ICmpInst::ICMP_SLE,
"vclez");
12336 case NEON::BI__builtin_neon_vcgtzd_s64:
12337 case NEON::BI__builtin_neon_vcgtzd_f64:
12338 case NEON::BI__builtin_neon_vcgtzs_f32:
12339 case NEON::BI__builtin_neon_vcgtzh_f16:
12343 ICmpInst::FCMP_OGT, ICmpInst::ICMP_SGT,
"vcgtz");
12344 case NEON::BI__builtin_neon_vcltzd_s64:
12345 case NEON::BI__builtin_neon_vcltzd_f64:
12346 case NEON::BI__builtin_neon_vcltzs_f32:
12347 case NEON::BI__builtin_neon_vcltzh_f16:
12351 ICmpInst::FCMP_OLT, ICmpInst::ICMP_SLT,
"vcltz");
12353 case NEON::BI__builtin_neon_vceqzd_u64: {
12357 Builder.CreateICmpEQ(Ops[0], llvm::Constant::getNullValue(
Int64Ty));
12360 case NEON::BI__builtin_neon_vceqd_f64:
12361 case NEON::BI__builtin_neon_vcled_f64:
12362 case NEON::BI__builtin_neon_vcltd_f64:
12363 case NEON::BI__builtin_neon_vcged_f64:
12364 case NEON::BI__builtin_neon_vcgtd_f64: {
12365 llvm::CmpInst::Predicate
P;
12366 switch (BuiltinID) {
12367 default: llvm_unreachable(
"missing builtin ID in switch!");
12368 case NEON::BI__builtin_neon_vceqd_f64:
P = llvm::FCmpInst::FCMP_OEQ;
break;
12369 case NEON::BI__builtin_neon_vcled_f64:
P = llvm::FCmpInst::FCMP_OLE;
break;
12370 case NEON::BI__builtin_neon_vcltd_f64:
P = llvm::FCmpInst::FCMP_OLT;
break;
12371 case NEON::BI__builtin_neon_vcged_f64:
P = llvm::FCmpInst::FCMP_OGE;
break;
12372 case NEON::BI__builtin_neon_vcgtd_f64:
P = llvm::FCmpInst::FCMP_OGT;
break;
12377 if (
P == llvm::FCmpInst::FCMP_OEQ)
12378 Ops[0] =
Builder.CreateFCmp(
P, Ops[0], Ops[1]);
12380 Ops[0] =
Builder.CreateFCmpS(
P, Ops[0], Ops[1]);
12383 case NEON::BI__builtin_neon_vceqs_f32:
12384 case NEON::BI__builtin_neon_vcles_f32:
12385 case NEON::BI__builtin_neon_vclts_f32:
12386 case NEON::BI__builtin_neon_vcges_f32:
12387 case NEON::BI__builtin_neon_vcgts_f32: {
12388 llvm::CmpInst::Predicate
P;
12389 switch (BuiltinID) {
12390 default: llvm_unreachable(
"missing builtin ID in switch!");
12391 case NEON::BI__builtin_neon_vceqs_f32:
P = llvm::FCmpInst::FCMP_OEQ;
break;
12392 case NEON::BI__builtin_neon_vcles_f32:
P = llvm::FCmpInst::FCMP_OLE;
break;
12393 case NEON::BI__builtin_neon_vclts_f32:
P = llvm::FCmpInst::FCMP_OLT;
break;
12394 case NEON::BI__builtin_neon_vcges_f32:
P = llvm::FCmpInst::FCMP_OGE;
break;
12395 case NEON::BI__builtin_neon_vcgts_f32:
P = llvm::FCmpInst::FCMP_OGT;
break;
12400 if (
P == llvm::FCmpInst::FCMP_OEQ)
12401 Ops[0] =
Builder.CreateFCmp(
P, Ops[0], Ops[1]);
12403 Ops[0] =
Builder.CreateFCmpS(
P, Ops[0], Ops[1]);
12406 case NEON::BI__builtin_neon_vceqh_f16:
12407 case NEON::BI__builtin_neon_vcleh_f16:
12408 case NEON::BI__builtin_neon_vclth_f16:
12409 case NEON::BI__builtin_neon_vcgeh_f16:
12410 case NEON::BI__builtin_neon_vcgth_f16: {
12411 llvm::CmpInst::Predicate
P;
12412 switch (BuiltinID) {
12413 default: llvm_unreachable(
"missing builtin ID in switch!");
12414 case NEON::BI__builtin_neon_vceqh_f16:
P = llvm::FCmpInst::FCMP_OEQ;
break;
12415 case NEON::BI__builtin_neon_vcleh_f16:
P = llvm::FCmpInst::FCMP_OLE;
break;
12416 case NEON::BI__builtin_neon_vclth_f16:
P = llvm::FCmpInst::FCMP_OLT;
break;
12417 case NEON::BI__builtin_neon_vcgeh_f16:
P = llvm::FCmpInst::FCMP_OGE;
break;
12418 case NEON::BI__builtin_neon_vcgth_f16:
P = llvm::FCmpInst::FCMP_OGT;
break;
12423 if (
P == llvm::FCmpInst::FCMP_OEQ)
12424 Ops[0] =
Builder.CreateFCmp(
P, Ops[0], Ops[1]);
12426 Ops[0] =
Builder.CreateFCmpS(
P, Ops[0], Ops[1]);
12429 case NEON::BI__builtin_neon_vceqd_s64:
12430 case NEON::BI__builtin_neon_vceqd_u64:
12431 case NEON::BI__builtin_neon_vcgtd_s64:
12432 case NEON::BI__builtin_neon_vcgtd_u64:
12433 case NEON::BI__builtin_neon_vcltd_s64:
12434 case NEON::BI__builtin_neon_vcltd_u64:
12435 case NEON::BI__builtin_neon_vcged_u64:
12436 case NEON::BI__builtin_neon_vcged_s64:
12437 case NEON::BI__builtin_neon_vcled_u64:
12438 case NEON::BI__builtin_neon_vcled_s64: {
12439 llvm::CmpInst::Predicate
P;
12440 switch (BuiltinID) {
12441 default: llvm_unreachable(
"missing builtin ID in switch!");
12442 case NEON::BI__builtin_neon_vceqd_s64:
12443 case NEON::BI__builtin_neon_vceqd_u64:
P = llvm::ICmpInst::ICMP_EQ;
break;
12444 case NEON::BI__builtin_neon_vcgtd_s64:
P = llvm::ICmpInst::ICMP_SGT;
break;
12445 case NEON::BI__builtin_neon_vcgtd_u64:
P = llvm::ICmpInst::ICMP_UGT;
break;
12446 case NEON::BI__builtin_neon_vcltd_s64:
P = llvm::ICmpInst::ICMP_SLT;
break;
12447 case NEON::BI__builtin_neon_vcltd_u64:
P = llvm::ICmpInst::ICMP_ULT;
break;
12448 case NEON::BI__builtin_neon_vcged_u64:
P = llvm::ICmpInst::ICMP_UGE;
break;
12449 case NEON::BI__builtin_neon_vcged_s64:
P = llvm::ICmpInst::ICMP_SGE;
break;
12450 case NEON::BI__builtin_neon_vcled_u64:
P = llvm::ICmpInst::ICMP_ULE;
break;
12451 case NEON::BI__builtin_neon_vcled_s64:
P = llvm::ICmpInst::ICMP_SLE;
break;
12456 Ops[0] =
Builder.CreateICmp(
P, Ops[0], Ops[1]);
12459 case NEON::BI__builtin_neon_vtstd_s64:
12460 case NEON::BI__builtin_neon_vtstd_u64: {
12464 Ops[0] =
Builder.CreateAnd(Ops[0], Ops[1]);
12465 Ops[0] =
Builder.CreateICmp(ICmpInst::ICMP_NE, Ops[0],
12466 llvm::Constant::getNullValue(
Int64Ty));
12469 case NEON::BI__builtin_neon_vset_lane_i8:
12470 case NEON::BI__builtin_neon_vset_lane_i16:
12471 case NEON::BI__builtin_neon_vset_lane_i32:
12472 case NEON::BI__builtin_neon_vset_lane_i64:
12473 case NEON::BI__builtin_neon_vset_lane_bf16:
12474 case NEON::BI__builtin_neon_vset_lane_f32:
12475 case NEON::BI__builtin_neon_vsetq_lane_i8:
12476 case NEON::BI__builtin_neon_vsetq_lane_i16:
12477 case NEON::BI__builtin_neon_vsetq_lane_i32:
12478 case NEON::BI__builtin_neon_vsetq_lane_i64:
12479 case NEON::BI__builtin_neon_vsetq_lane_bf16:
12480 case NEON::BI__builtin_neon_vsetq_lane_f32:
12482 return Builder.CreateInsertElement(Ops[1], Ops[0], Ops[2],
"vset_lane");
12483 case NEON::BI__builtin_neon_vset_lane_f64:
12486 Builder.CreateBitCast(Ops[1], llvm::FixedVectorType::get(
DoubleTy, 1));
12488 return Builder.CreateInsertElement(Ops[1], Ops[0], Ops[2],
"vset_lane");
12489 case NEON::BI__builtin_neon_vsetq_lane_f64:
12492 Builder.CreateBitCast(Ops[1], llvm::FixedVectorType::get(
DoubleTy, 2));
12494 return Builder.CreateInsertElement(Ops[1], Ops[0], Ops[2],
"vset_lane");
12496 case NEON::BI__builtin_neon_vget_lane_i8:
12497 case NEON::BI__builtin_neon_vdupb_lane_i8:
12499 Builder.CreateBitCast(Ops[0], llvm::FixedVectorType::get(
Int8Ty, 8));
12502 case NEON::BI__builtin_neon_vgetq_lane_i8:
12503 case NEON::BI__builtin_neon_vdupb_laneq_i8:
12505 Builder.CreateBitCast(Ops[0], llvm::FixedVectorType::get(
Int8Ty, 16));
12508 case NEON::BI__builtin_neon_vget_lane_i16:
12509 case NEON::BI__builtin_neon_vduph_lane_i16:
12511 Builder.CreateBitCast(Ops[0], llvm::FixedVectorType::get(
Int16Ty, 4));
12514 case NEON::BI__builtin_neon_vgetq_lane_i16:
12515 case NEON::BI__builtin_neon_vduph_laneq_i16:
12517 Builder.CreateBitCast(Ops[0], llvm::FixedVectorType::get(
Int16Ty, 8));
12520 case NEON::BI__builtin_neon_vget_lane_i32:
12521 case NEON::BI__builtin_neon_vdups_lane_i32:
12523 Builder.CreateBitCast(Ops[0], llvm::FixedVectorType::get(
Int32Ty, 2));
12526 case NEON::BI__builtin_neon_vdups_lane_f32:
12528 Builder.CreateBitCast(Ops[0], llvm::FixedVectorType::get(
FloatTy, 2));
12531 case NEON::BI__builtin_neon_vgetq_lane_i32:
12532 case NEON::BI__builtin_neon_vdups_laneq_i32:
12534 Builder.CreateBitCast(Ops[0], llvm::FixedVectorType::get(
Int32Ty, 4));
12537 case NEON::BI__builtin_neon_vget_lane_i64:
12538 case NEON::BI__builtin_neon_vdupd_lane_i64:
12540 Builder.CreateBitCast(Ops[0], llvm::FixedVectorType::get(
Int64Ty, 1));
12543 case NEON::BI__builtin_neon_vdupd_lane_f64:
12545 Builder.CreateBitCast(Ops[0], llvm::FixedVectorType::get(
DoubleTy, 1));
12548 case NEON::BI__builtin_neon_vgetq_lane_i64:
12549 case NEON::BI__builtin_neon_vdupd_laneq_i64:
12551 Builder.CreateBitCast(Ops[0], llvm::FixedVectorType::get(
Int64Ty, 2));
12554 case NEON::BI__builtin_neon_vget_lane_f32:
12556 Builder.CreateBitCast(Ops[0], llvm::FixedVectorType::get(
FloatTy, 2));
12559 case NEON::BI__builtin_neon_vget_lane_f64:
12561 Builder.CreateBitCast(Ops[0], llvm::FixedVectorType::get(
DoubleTy, 1));
12564 case NEON::BI__builtin_neon_vgetq_lane_f32:
12565 case NEON::BI__builtin_neon_vdups_laneq_f32:
12567 Builder.CreateBitCast(Ops[0], llvm::FixedVectorType::get(
FloatTy, 4));
12570 case NEON::BI__builtin_neon_vgetq_lane_f64:
12571 case NEON::BI__builtin_neon_vdupd_laneq_f64:
12573 Builder.CreateBitCast(Ops[0], llvm::FixedVectorType::get(
DoubleTy, 2));
12576 case NEON::BI__builtin_neon_vaddh_f16:
12578 return Builder.CreateFAdd(Ops[0], Ops[1],
"vaddh");
12579 case NEON::BI__builtin_neon_vsubh_f16:
12581 return Builder.CreateFSub(Ops[0], Ops[1],
"vsubh");
12582 case NEON::BI__builtin_neon_vmulh_f16:
12584 return Builder.CreateFMul(Ops[0], Ops[1],
"vmulh");
12585 case NEON::BI__builtin_neon_vdivh_f16:
12587 return Builder.CreateFDiv(Ops[0], Ops[1],
"vdivh");
12588 case NEON::BI__builtin_neon_vfmah_f16:
12591 *
this, Intrinsic::fma, Intrinsic::experimental_constrained_fma,
HalfTy,
12593 case NEON::BI__builtin_neon_vfmsh_f16: {
12598 *
this, Intrinsic::fma, Intrinsic::experimental_constrained_fma,
HalfTy,
12601 case NEON::BI__builtin_neon_vaddd_s64:
12602 case NEON::BI__builtin_neon_vaddd_u64:
12604 case NEON::BI__builtin_neon_vsubd_s64:
12605 case NEON::BI__builtin_neon_vsubd_u64:
12607 case NEON::BI__builtin_neon_vqdmlalh_s16:
12608 case NEON::BI__builtin_neon_vqdmlslh_s16: {
12612 auto *VTy = llvm::FixedVectorType::get(
Int32Ty, 4);
12614 ProductOps,
"vqdmlXl");
12615 Constant *CI = ConstantInt::get(
SizeTy, 0);
12616 Ops[1] =
Builder.CreateExtractElement(Ops[1], CI,
"lane0");
12618 unsigned AccumInt = BuiltinID == NEON::BI__builtin_neon_vqdmlalh_s16
12619 ? Intrinsic::aarch64_neon_sqadd
12620 : Intrinsic::aarch64_neon_sqsub;
12623 case NEON::BI__builtin_neon_vqshlud_n_s64: {
12629 case NEON::BI__builtin_neon_vqshld_n_u64:
12630 case NEON::BI__builtin_neon_vqshld_n_s64: {
12631 unsigned Int = BuiltinID == NEON::BI__builtin_neon_vqshld_n_u64
12632 ? Intrinsic::aarch64_neon_uqshl
12633 : Intrinsic::aarch64_neon_sqshl;
12638 case NEON::BI__builtin_neon_vrshrd_n_u64:
12639 case NEON::BI__builtin_neon_vrshrd_n_s64: {
12640 unsigned Int = BuiltinID == NEON::BI__builtin_neon_vrshrd_n_u64
12641 ? Intrinsic::aarch64_neon_urshl
12642 : Intrinsic::aarch64_neon_srshl;
12644 int SV = cast<ConstantInt>(Ops[1])->getSExtValue();
12645 Ops[1] = ConstantInt::get(
Int64Ty, -SV);
12648 case NEON::BI__builtin_neon_vrsrad_n_u64:
12649 case NEON::BI__builtin_neon_vrsrad_n_s64: {
12650 unsigned Int = BuiltinID == NEON::BI__builtin_neon_vrsrad_n_u64
12651 ? Intrinsic::aarch64_neon_urshl
12652 : Intrinsic::aarch64_neon_srshl;
12656 {Ops[1], Builder.CreateSExt(Ops[2], Int64Ty)});
12659 case NEON::BI__builtin_neon_vshld_n_s64:
12660 case NEON::BI__builtin_neon_vshld_n_u64: {
12661 llvm::ConstantInt *Amt = cast<ConstantInt>(
EmitScalarExpr(
E->getArg(1)));
12663 Ops[0], ConstantInt::get(
Int64Ty, Amt->getZExtValue()),
"shld_n");
12665 case NEON::BI__builtin_neon_vshrd_n_s64: {
12666 llvm::ConstantInt *Amt = cast<ConstantInt>(
EmitScalarExpr(
E->getArg(1)));
12668 Ops[0], ConstantInt::get(
Int64Ty, std::min(
static_cast<uint64_t>(63),
12669 Amt->getZExtValue())),
12672 case NEON::BI__builtin_neon_vshrd_n_u64: {
12673 llvm::ConstantInt *Amt = cast<ConstantInt>(
EmitScalarExpr(
E->getArg(1)));
12674 uint64_t ShiftAmt = Amt->getZExtValue();
12676 if (ShiftAmt == 64)
12677 return ConstantInt::get(
Int64Ty, 0);
12678 return Builder.CreateLShr(Ops[0], ConstantInt::get(
Int64Ty, ShiftAmt),
12681 case NEON::BI__builtin_neon_vsrad_n_s64: {
12682 llvm::ConstantInt *Amt = cast<ConstantInt>(
EmitScalarExpr(
E->getArg(2)));
12684 Ops[1], ConstantInt::get(
Int64Ty, std::min(
static_cast<uint64_t>(63),
12685 Amt->getZExtValue())),
12687 return Builder.CreateAdd(Ops[0], Ops[1]);
12689 case NEON::BI__builtin_neon_vsrad_n_u64: {
12690 llvm::ConstantInt *Amt = cast<ConstantInt>(
EmitScalarExpr(
E->getArg(2)));
12691 uint64_t ShiftAmt = Amt->getZExtValue();
12694 if (ShiftAmt == 64)
12696 Ops[1] =
Builder.CreateLShr(Ops[1], ConstantInt::get(
Int64Ty, ShiftAmt),
12698 return Builder.CreateAdd(Ops[0], Ops[1]);
12700 case NEON::BI__builtin_neon_vqdmlalh_lane_s16:
12701 case NEON::BI__builtin_neon_vqdmlalh_laneq_s16:
12702 case NEON::BI__builtin_neon_vqdmlslh_lane_s16:
12703 case NEON::BI__builtin_neon_vqdmlslh_laneq_s16: {
12709 auto *VTy = llvm::FixedVectorType::get(
Int32Ty, 4);
12711 ProductOps,
"vqdmlXl");
12712 Constant *CI = ConstantInt::get(
SizeTy, 0);
12713 Ops[1] =
Builder.CreateExtractElement(Ops[1], CI,
"lane0");
12716 unsigned AccInt = (BuiltinID == NEON::BI__builtin_neon_vqdmlalh_lane_s16 ||
12717 BuiltinID == NEON::BI__builtin_neon_vqdmlalh_laneq_s16)
12718 ? Intrinsic::aarch64_neon_sqadd
12719 : Intrinsic::aarch64_neon_sqsub;
12722 case NEON::BI__builtin_neon_vqdmlals_s32:
12723 case NEON::BI__builtin_neon_vqdmlsls_s32: {
12725 ProductOps.push_back(Ops[1]);
12729 ProductOps,
"vqdmlXl");
12731 unsigned AccumInt = BuiltinID == NEON::BI__builtin_neon_vqdmlals_s32
12732 ? Intrinsic::aarch64_neon_sqadd
12733 : Intrinsic::aarch64_neon_sqsub;
12736 case NEON::BI__builtin_neon_vqdmlals_lane_s32:
12737 case NEON::BI__builtin_neon_vqdmlals_laneq_s32:
12738 case NEON::BI__builtin_neon_vqdmlsls_lane_s32:
12739 case NEON::BI__builtin_neon_vqdmlsls_laneq_s32: {
12743 ProductOps.push_back(Ops[1]);
12744 ProductOps.push_back(Ops[2]);
12747 ProductOps,
"vqdmlXl");
12750 unsigned AccInt = (BuiltinID == NEON::BI__builtin_neon_vqdmlals_lane_s32 ||
12751 BuiltinID == NEON::BI__builtin_neon_vqdmlals_laneq_s32)
12752 ? Intrinsic::aarch64_neon_sqadd
12753 : Intrinsic::aarch64_neon_sqsub;
12756 case NEON::BI__builtin_neon_vget_lane_bf16:
12757 case NEON::BI__builtin_neon_vduph_lane_bf16:
12758 case NEON::BI__builtin_neon_vduph_lane_f16: {
12762 case NEON::BI__builtin_neon_vgetq_lane_bf16:
12763 case NEON::BI__builtin_neon_vduph_laneq_bf16:
12764 case NEON::BI__builtin_neon_vduph_laneq_f16: {
12769 case clang::AArch64::BI_InterlockedAdd:
12770 case clang::AArch64::BI_InterlockedAdd64: {
12773 AtomicRMWInst *RMWI =
12775 llvm::AtomicOrdering::SequentiallyConsistent);
12776 return Builder.CreateAdd(RMWI, Val);
12781 llvm::Type *Ty = VTy;
12792 Builtin->BuiltinID, Builtin->LLVMIntrinsic, Builtin->AltLLVMIntrinsic,
12793 Builtin->NameHint, Builtin->TypeModifier,
E, Ops,
12800 switch (BuiltinID) {
12801 default:
return nullptr;
12802 case NEON::BI__builtin_neon_vbsl_v:
12803 case NEON::BI__builtin_neon_vbslq_v: {
12804 llvm::Type *BitTy = llvm::VectorType::getInteger(VTy);
12805 Ops[0] =
Builder.CreateBitCast(Ops[0], BitTy,
"vbsl");
12806 Ops[1] =
Builder.CreateBitCast(Ops[1], BitTy,
"vbsl");
12807 Ops[2] =
Builder.CreateBitCast(Ops[2], BitTy,
"vbsl");
12809 Ops[1] =
Builder.CreateAnd(Ops[0], Ops[1],
"vbsl");
12810 Ops[2] =
Builder.CreateAnd(
Builder.CreateNot(Ops[0]), Ops[2],
"vbsl");
12811 Ops[0] =
Builder.CreateOr(Ops[1], Ops[2],
"vbsl");
12812 return Builder.CreateBitCast(Ops[0], Ty);
12814 case NEON::BI__builtin_neon_vfma_lane_v:
12815 case NEON::BI__builtin_neon_vfmaq_lane_v: {
12818 Value *Addend = Ops[0];
12819 Value *Multiplicand = Ops[1];
12820 Value *LaneSource = Ops[2];
12821 Ops[0] = Multiplicand;
12822 Ops[1] = LaneSource;
12826 auto *SourceTy = BuiltinID == NEON::BI__builtin_neon_vfmaq_lane_v
12827 ? llvm::FixedVectorType::get(VTy->getElementType(),
12828 VTy->getNumElements() / 2)
12830 llvm::Constant *cst = cast<Constant>(Ops[3]);
12831 Value *SV = llvm::ConstantVector::getSplat(VTy->getElementCount(), cst);
12832 Ops[1] =
Builder.CreateBitCast(Ops[1], SourceTy);
12833 Ops[1] =
Builder.CreateShuffleVector(Ops[1], Ops[1], SV,
"lane");
12836 Int =
Builder.getIsFPConstrained() ? Intrinsic::experimental_constrained_fma
12840 case NEON::BI__builtin_neon_vfma_laneq_v: {
12841 auto *VTy = cast<llvm::FixedVectorType>(Ty);
12843 if (VTy && VTy->getElementType() ==
DoubleTy) {
12846 llvm::FixedVectorType *VTy =
12848 Ops[2] =
Builder.CreateBitCast(Ops[2], VTy);
12849 Ops[2] =
Builder.CreateExtractElement(Ops[2], Ops[3],
"extract");
12852 *
this, Intrinsic::fma, Intrinsic::experimental_constrained_fma,
12853 DoubleTy, {Ops[1], Ops[2], Ops[0]});
12856 Ops[0] =
Builder.CreateBitCast(Ops[0], Ty);
12857 Ops[1] =
Builder.CreateBitCast(Ops[1], Ty);
12859 auto *STy = llvm::FixedVectorType::get(VTy->getElementType(),
12860 VTy->getNumElements() * 2);
12861 Ops[2] =
Builder.CreateBitCast(Ops[2], STy);
12862 Value *SV = llvm::ConstantVector::getSplat(VTy->getElementCount(),
12863 cast<ConstantInt>(Ops[3]));
12864 Ops[2] =
Builder.CreateShuffleVector(Ops[2], Ops[2], SV,
"lane");
12867 *
this, Intrinsic::fma, Intrinsic::experimental_constrained_fma, Ty,
12868 {Ops[2], Ops[1], Ops[0]});
12870 case NEON::BI__builtin_neon_vfmaq_laneq_v: {
12871 Ops[0] =
Builder.CreateBitCast(Ops[0], Ty);
12872 Ops[1] =
Builder.CreateBitCast(Ops[1], Ty);
12874 Ops[2] =
Builder.CreateBitCast(Ops[2], Ty);
12877 *
this, Intrinsic::fma, Intrinsic::experimental_constrained_fma, Ty,
12878 {Ops[2], Ops[1], Ops[0]});
12880 case NEON::BI__builtin_neon_vfmah_lane_f16:
12881 case NEON::BI__builtin_neon_vfmas_lane_f32:
12882 case NEON::BI__builtin_neon_vfmah_laneq_f16:
12883 case NEON::BI__builtin_neon_vfmas_laneq_f32:
12884 case NEON::BI__builtin_neon_vfmad_lane_f64:
12885 case NEON::BI__builtin_neon_vfmad_laneq_f64: {
12888 Ops[2] =
Builder.CreateExtractElement(Ops[2], Ops[3],
"extract");
12890 *
this, Intrinsic::fma, Intrinsic::experimental_constrained_fma, Ty,
12891 {Ops[1], Ops[2], Ops[0]});
12893 case NEON::BI__builtin_neon_vmull_v:
12895 Int = usgn ? Intrinsic::aarch64_neon_umull : Intrinsic::aarch64_neon_smull;
12896 if (
Type.isPoly())
Int = Intrinsic::aarch64_neon_pmull;
12898 case NEON::BI__builtin_neon_vmax_v:
12899 case NEON::BI__builtin_neon_vmaxq_v:
12901 Int = usgn ? Intrinsic::aarch64_neon_umax : Intrinsic::aarch64_neon_smax;
12902 if (Ty->isFPOrFPVectorTy())
Int = Intrinsic::aarch64_neon_fmax;
12904 case NEON::BI__builtin_neon_vmaxh_f16: {
12906 Int = Intrinsic::aarch64_neon_fmax;
12909 case NEON::BI__builtin_neon_vmin_v:
12910 case NEON::BI__builtin_neon_vminq_v:
12912 Int = usgn ? Intrinsic::aarch64_neon_umin : Intrinsic::aarch64_neon_smin;
12913 if (Ty->isFPOrFPVectorTy())
Int = Intrinsic::aarch64_neon_fmin;
12915 case NEON::BI__builtin_neon_vminh_f16: {
12917 Int = Intrinsic::aarch64_neon_fmin;
12920 case NEON::BI__builtin_neon_vabd_v:
12921 case NEON::BI__builtin_neon_vabdq_v:
12923 Int = usgn ? Intrinsic::aarch64_neon_uabd : Intrinsic::aarch64_neon_sabd;
12924 if (Ty->isFPOrFPVectorTy())
Int = Intrinsic::aarch64_neon_fabd;
12926 case NEON::BI__builtin_neon_vpadal_v:
12927 case NEON::BI__builtin_neon_vpadalq_v: {
12928 unsigned ArgElts = VTy->getNumElements();
12929 llvm::IntegerType *EltTy = cast<IntegerType>(VTy->getElementType());
12930 unsigned BitWidth = EltTy->getBitWidth();
12931 auto *ArgTy = llvm::FixedVectorType::get(
12932 llvm::IntegerType::get(
getLLVMContext(), BitWidth / 2), 2 * ArgElts);
12933 llvm::Type* Tys[2] = { VTy, ArgTy };
12934 Int = usgn ? Intrinsic::aarch64_neon_uaddlp : Intrinsic::aarch64_neon_saddlp;
12936 TmpOps.push_back(Ops[1]);
12939 llvm::Value *addend =
Builder.CreateBitCast(Ops[0], tmp->getType());
12940 return Builder.CreateAdd(tmp, addend);
12942 case NEON::BI__builtin_neon_vpmin_v:
12943 case NEON::BI__builtin_neon_vpminq_v:
12945 Int = usgn ? Intrinsic::aarch64_neon_uminp : Intrinsic::aarch64_neon_sminp;
12946 if (Ty->isFPOrFPVectorTy())
Int = Intrinsic::aarch64_neon_fminp;
12948 case NEON::BI__builtin_neon_vpmax_v:
12949 case NEON::BI__builtin_neon_vpmaxq_v:
12951 Int = usgn ? Intrinsic::aarch64_neon_umaxp : Intrinsic::aarch64_neon_smaxp;
12952 if (Ty->isFPOrFPVectorTy())
Int = Intrinsic::aarch64_neon_fmaxp;
12954 case NEON::BI__builtin_neon_vminnm_v:
12955 case NEON::BI__builtin_neon_vminnmq_v:
12956 Int = Intrinsic::aarch64_neon_fminnm;
12958 case NEON::BI__builtin_neon_vminnmh_f16:
12960 Int = Intrinsic::aarch64_neon_fminnm;
12962 case NEON::BI__builtin_neon_vmaxnm_v:
12963 case NEON::BI__builtin_neon_vmaxnmq_v:
12964 Int = Intrinsic::aarch64_neon_fmaxnm;
12966 case NEON::BI__builtin_neon_vmaxnmh_f16:
12968 Int = Intrinsic::aarch64_neon_fmaxnm;
12970 case NEON::BI__builtin_neon_vrecpss_f32: {
12975 case NEON::BI__builtin_neon_vrecpsd_f64:
12979 case NEON::BI__builtin_neon_vrecpsh_f16:
12983 case NEON::BI__builtin_neon_vqshrun_n_v:
12984 Int = Intrinsic::aarch64_neon_sqshrun;
12986 case NEON::BI__builtin_neon_vqrshrun_n_v:
12987 Int = Intrinsic::aarch64_neon_sqrshrun;
12989 case NEON::BI__builtin_neon_vqshrn_n_v:
12990 Int = usgn ? Intrinsic::aarch64_neon_uqshrn : Intrinsic::aarch64_neon_sqshrn;
12992 case NEON::BI__builtin_neon_vrshrn_n_v:
12993 Int = Intrinsic::aarch64_neon_rshrn;
12995 case NEON::BI__builtin_neon_vqrshrn_n_v:
12996 Int = usgn ? Intrinsic::aarch64_neon_uqrshrn : Intrinsic::aarch64_neon_sqrshrn;
12998 case NEON::BI__builtin_neon_vrndah_f16: {
13001 ? Intrinsic::experimental_constrained_round
13002 : Intrinsic::round;
13005 case NEON::BI__builtin_neon_vrnda_v:
13006 case NEON::BI__builtin_neon_vrndaq_v: {
13008 ? Intrinsic::experimental_constrained_round
13009 : Intrinsic::round;
13012 case NEON::BI__builtin_neon_vrndih_f16: {
13015 ? Intrinsic::experimental_constrained_nearbyint
13016 : Intrinsic::nearbyint;
13019 case NEON::BI__builtin_neon_vrndmh_f16: {
13022 ? Intrinsic::experimental_constrained_floor
13023 : Intrinsic::floor;
13026 case NEON::BI__builtin_neon_vrndm_v:
13027 case NEON::BI__builtin_neon_vrndmq_v: {
13029 ? Intrinsic::experimental_constrained_floor
13030 : Intrinsic::floor;
13033 case NEON::BI__builtin_neon_vrndnh_f16: {
13036 ? Intrinsic::experimental_constrained_roundeven
13037 : Intrinsic::roundeven;
13040 case NEON::BI__builtin_neon_vrndn_v:
13041 case NEON::BI__builtin_neon_vrndnq_v: {
13043 ? Intrinsic::experimental_constrained_roundeven
13044 : Intrinsic::roundeven;
13047 case NEON::BI__builtin_neon_vrndns_f32: {
13050 ? Intrinsic::experimental_constrained_roundeven
13051 : Intrinsic::roundeven;
13054 case NEON::BI__builtin_neon_vrndph_f16: {
13057 ? Intrinsic::experimental_constrained_ceil
13061 case NEON::BI__builtin_neon_vrndp_v:
13062 case NEON::BI__builtin_neon_vrndpq_v: {
13064 ? Intrinsic::experimental_constrained_ceil
13068 case NEON::BI__builtin_neon_vrndxh_f16: {
13071 ? Intrinsic::experimental_constrained_rint
13075 case NEON::BI__builtin_neon_vrndx_v:
13076 case NEON::BI__builtin_neon_vrndxq_v: {
13078 ? Intrinsic::experimental_constrained_rint
13082 case NEON::BI__builtin_neon_vrndh_f16: {
13085 ? Intrinsic::experimental_constrained_trunc
13086 : Intrinsic::trunc;
13089 case NEON::BI__builtin_neon_vrnd32x_f32:
13090 case NEON::BI__builtin_neon_vrnd32xq_f32:
13091 case NEON::BI__builtin_neon_vrnd32x_f64:
13092 case NEON::BI__builtin_neon_vrnd32xq_f64: {
13094 Int = Intrinsic::aarch64_neon_frint32x;
13097 case NEON::BI__builtin_neon_vrnd32z_f32:
13098 case NEON::BI__builtin_neon_vrnd32zq_f32:
13099 case NEON::BI__builtin_neon_vrnd32z_f64:
13100 case NEON::BI__builtin_neon_vrnd32zq_f64: {
13102 Int = Intrinsic::aarch64_neon_frint32z;
13105 case NEON::BI__builtin_neon_vrnd64x_f32:
13106 case NEON::BI__builtin_neon_vrnd64xq_f32:
13107 case NEON::BI__builtin_neon_vrnd64x_f64:
13108 case NEON::BI__builtin_neon_vrnd64xq_f64: {
13110 Int = Intrinsic::aarch64_neon_frint64x;
13113 case NEON::BI__builtin_neon_vrnd64z_f32:
13114 case NEON::BI__builtin_neon_vrnd64zq_f32:
13115 case NEON::BI__builtin_neon_vrnd64z_f64:
13116 case NEON::BI__builtin_neon_vrnd64zq_f64: {
13118 Int = Intrinsic::aarch64_neon_frint64z;
13121 case NEON::BI__builtin_neon_vrnd_v:
13122 case NEON::BI__builtin_neon_vrndq_v: {
13124 ? Intrinsic::experimental_constrained_trunc
13125 : Intrinsic::trunc;
13128 case NEON::BI__builtin_neon_vcvt_f64_v:
13129 case NEON::BI__builtin_neon_vcvtq_f64_v:
13130 Ops[0] =
Builder.CreateBitCast(Ops[0], Ty);
13132 return usgn ?
Builder.CreateUIToFP(Ops[0], Ty,
"vcvt")
13133 :
Builder.CreateSIToFP(Ops[0], Ty,
"vcvt");
13134 case NEON::BI__builtin_neon_vcvt_f64_f32: {
13136 "unexpected vcvt_f64_f32 builtin");
13140 return Builder.CreateFPExt(Ops[0], Ty,
"vcvt");
13142 case NEON::BI__builtin_neon_vcvt_f32_f64: {
13144 "unexpected vcvt_f32_f64 builtin");
13148 return Builder.CreateFPTrunc(Ops[0], Ty,
"vcvt");
13150 case NEON::BI__builtin_neon_vcvt_s32_v:
13151 case NEON::BI__builtin_neon_vcvt_u32_v:
13152 case NEON::BI__builtin_neon_vcvt_s64_v:
13153 case NEON::BI__builtin_neon_vcvt_u64_v:
13154 case NEON::BI__builtin_neon_vcvt_s16_f16:
13155 case NEON::BI__builtin_neon_vcvt_u16_f16:
13156 case NEON::BI__builtin_neon_vcvtq_s32_v:
13157 case NEON::BI__builtin_neon_vcvtq_u32_v:
13158 case NEON::BI__builtin_neon_vcvtq_s64_v:
13159 case NEON::BI__builtin_neon_vcvtq_u64_v:
13160 case NEON::BI__builtin_neon_vcvtq_s16_f16:
13161 case NEON::BI__builtin_neon_vcvtq_u16_f16: {
13163 usgn ? Intrinsic::aarch64_neon_fcvtzu : Intrinsic::aarch64_neon_fcvtzs;
13167 case NEON::BI__builtin_neon_vcvta_s16_f16:
13168 case NEON::BI__builtin_neon_vcvta_u16_f16:
13169 case NEON::BI__builtin_neon_vcvta_s32_v:
13170 case NEON::BI__builtin_neon_vcvtaq_s16_f16:
13171 case NEON::BI__builtin_neon_vcvtaq_s32_v:
13172 case NEON::BI__builtin_neon_vcvta_u32_v:
13173 case NEON::BI__builtin_neon_vcvtaq_u16_f16:
13174 case NEON::BI__builtin_neon_vcvtaq_u32_v:
13175 case NEON::BI__builtin_neon_vcvta_s64_v:
13176 case NEON::BI__builtin_neon_vcvtaq_s64_v:
13177 case NEON::BI__builtin_neon_vcvta_u64_v:
13178 case NEON::BI__builtin_neon_vcvtaq_u64_v: {
13179 Int = usgn ? Intrinsic::aarch64_neon_fcvtau : Intrinsic::aarch64_neon_fcvtas;
13183 case NEON::BI__builtin_neon_vcvtm_s16_f16:
13184 case NEON::BI__builtin_neon_vcvtm_s32_v:
13185 case NEON::BI__builtin_neon_vcvtmq_s16_f16:
13186 case NEON::BI__builtin_neon_vcvtmq_s32_v:
13187 case NEON::BI__builtin_neon_vcvtm_u16_f16:
13188 case NEON::BI__builtin_neon_vcvtm_u32_v:
13189 case NEON::BI__builtin_neon_vcvtmq_u16_f16:
13190 case NEON::BI__builtin_neon_vcvtmq_u32_v:
13191 case NEON::BI__builtin_neon_vcvtm_s64_v:
13192 case NEON::BI__builtin_neon_vcvtmq_s64_v:
13193 case NEON::BI__builtin_neon_vcvtm_u64_v:
13194 case NEON::BI__builtin_neon_vcvtmq_u64_v: {
13195 Int = usgn ? Intrinsic::aarch64_neon_fcvtmu : Intrinsic::aarch64_neon_fcvtms;
13199 case NEON::BI__builtin_neon_vcvtn_s16_f16:
13200 case NEON::BI__builtin_neon_vcvtn_s32_v:
13201 case NEON::BI__builtin_neon_vcvtnq_s16_f16:
13202 case NEON::BI__builtin_neon_vcvtnq_s32_v:
13203 case NEON::BI__builtin_neon_vcvtn_u16_f16:
13204 case NEON::BI__builtin_neon_vcvtn_u32_v:
13205 case NEON::BI__builtin_neon_vcvtnq_u16_f16:
13206 case NEON::BI__builtin_neon_vcvtnq_u32_v:
13207 case NEON::BI__builtin_neon_vcvtn_s64_v:
13208 case NEON::BI__builtin_neon_vcvtnq_s64_v:
13209 case NEON::BI__builtin_neon_vcvtn_u64_v:
13210 case NEON::BI__builtin_neon_vcvtnq_u64_v: {
13211 Int = usgn ? Intrinsic::aarch64_neon_fcvtnu : Intrinsic::aarch64_neon_fcvtns;
13215 case NEON::BI__builtin_neon_vcvtp_s16_f16:
13216 case NEON::BI__builtin_neon_vcvtp_s32_v:
13217 case NEON::BI__builtin_neon_vcvtpq_s16_f16:
13218 case NEON::BI__builtin_neon_vcvtpq_s32_v:
13219 case NEON::BI__builtin_neon_vcvtp_u16_f16:
13220 case NEON::BI__builtin_neon_vcvtp_u32_v:
13221 case NEON::BI__builtin_neon_vcvtpq_u16_f16:
13222 case NEON::BI__builtin_neon_vcvtpq_u32_v:
13223 case NEON::BI__builtin_neon_vcvtp_s64_v:
13224 case NEON::BI__builtin_neon_vcvtpq_s64_v:
13225 case NEON::BI__builtin_neon_vcvtp_u64_v:
13226 case NEON::BI__builtin_neon_vcvtpq_u64_v: {
13227 Int = usgn ? Intrinsic::aarch64_neon_fcvtpu : Intrinsic::aarch64_neon_fcvtps;
13231 case NEON::BI__builtin_neon_vmulx_v:
13232 case NEON::BI__builtin_neon_vmulxq_v: {
13233 Int = Intrinsic::aarch64_neon_fmulx;
13236 case NEON::BI__builtin_neon_vmulxh_lane_f16:
13237 case NEON::BI__builtin_neon_vmulxh_laneq_f16: {
13241 Ops[1] =
Builder.CreateExtractElement(Ops[1], Ops[2],
"extract");
13243 Int = Intrinsic::aarch64_neon_fmulx;
13246 case NEON::BI__builtin_neon_vmul_lane_v:
13247 case NEON::BI__builtin_neon_vmul_laneq_v: {
13250 if (BuiltinID == NEON::BI__builtin_neon_vmul_laneq_v)
13253 llvm::FixedVectorType *VTy =
13255 Ops[1] =
Builder.CreateBitCast(Ops[1], VTy);
13256 Ops[1] =
Builder.CreateExtractElement(Ops[1], Ops[2],
"extract");
13260 case NEON::BI__builtin_neon_vnegd_s64:
13262 case NEON::BI__builtin_neon_vnegh_f16:
13264 case NEON::BI__builtin_neon_vpmaxnm_v:
13265 case NEON::BI__builtin_neon_vpmaxnmq_v: {
13266 Int = Intrinsic::aarch64_neon_fmaxnmp;
13269 case NEON::BI__builtin_neon_vpminnm_v:
13270 case NEON::BI__builtin_neon_vpminnmq_v: {
13271 Int = Intrinsic::aarch64_neon_fminnmp;
13274 case NEON::BI__builtin_neon_vsqrth_f16: {
13277 ? Intrinsic::experimental_constrained_sqrt
13281 case NEON::BI__builtin_neon_vsqrt_v:
13282 case NEON::BI__builtin_neon_vsqrtq_v: {
13284 ? Intrinsic::experimental_constrained_sqrt
13286 Ops[0] =
Builder.CreateBitCast(Ops[0], Ty);
13289 case NEON::BI__builtin_neon_vrbit_v:
13290 case NEON::BI__builtin_neon_vrbitq_v: {
13291 Int = Intrinsic::bitreverse;
13294 case NEON::BI__builtin_neon_vaddv_u8:
13298 case NEON::BI__builtin_neon_vaddv_s8: {
13299 Int = usgn ? Intrinsic::aarch64_neon_uaddv : Intrinsic::aarch64_neon_saddv;
13301 VTy = llvm::FixedVectorType::get(
Int8Ty, 8);
13302 llvm::Type *Tys[2] = { Ty, VTy };
13307 case NEON::BI__builtin_neon_vaddv_u16:
13310 case NEON::BI__builtin_neon_vaddv_s16: {
13311 Int = usgn ? Intrinsic::aarch64_neon_uaddv : Intrinsic::aarch64_neon_saddv;
13313 VTy = llvm::FixedVectorType::get(
Int16Ty, 4);
13314 llvm::Type *Tys[2] = { Ty, VTy };
13319 case NEON::BI__builtin_neon_vaddvq_u8:
13322 case NEON::BI__builtin_neon_vaddvq_s8: {
13323 Int = usgn ? Intrinsic::aarch64_neon_uaddv : Intrinsic::aarch64_neon_saddv;
13325 VTy = llvm::FixedVectorType::get(
Int8Ty, 16);
13326 llvm::Type *Tys[2] = { Ty, VTy };
13331 case NEON::BI__builtin_neon_vaddvq_u16:
13334 case NEON::BI__builtin_neon_vaddvq_s16: {
13335 Int = usgn ? Intrinsic::aarch64_neon_uaddv : Intrinsic::aarch64_neon_saddv;
13337 VTy = llvm::FixedVectorType::get(
Int16Ty, 8);
13338 llvm::Type *Tys[2] = { Ty, VTy };
13343 case NEON::BI__builtin_neon_vmaxv_u8: {
13344 Int = Intrinsic::aarch64_neon_umaxv;
13346 VTy = llvm::FixedVectorType::get(
Int8Ty, 8);
13347 llvm::Type *Tys[2] = { Ty, VTy };
13352 case NEON::BI__builtin_neon_vmaxv_u16: {
13353 Int = Intrinsic::aarch64_neon_umaxv;
13355 VTy = llvm::FixedVectorType::get(
Int16Ty, 4);
13356 llvm::Type *Tys[2] = { Ty, VTy };
13361 case NEON::BI__builtin_neon_vmaxvq_u8: {
13362 Int = Intrinsic::aarch64_neon_umaxv;
13364 VTy = llvm::FixedVectorType::get(
Int8Ty, 16);
13365 llvm::Type *Tys[2] = { Ty, VTy };
13370 case NEON::BI__builtin_neon_vmaxvq_u16: {
13371 Int = Intrinsic::aarch64_neon_umaxv;
13373 VTy = llvm::FixedVectorType::get(
Int16Ty, 8);
13374 llvm::Type *Tys[2] = { Ty, VTy };
13379 case NEON::BI__builtin_neon_vmaxv_s8: {
13380 Int = Intrinsic::aarch64_neon_smaxv;
13382 VTy = llvm::FixedVectorType::get(
Int8Ty, 8);
13383 llvm::Type *Tys[2] = { Ty, VTy };
13388 case NEON::BI__builtin_neon_vmaxv_s16: {
13389 Int = Intrinsic::aarch64_neon_smaxv;
13391 VTy = llvm::FixedVectorType::get(
Int16Ty, 4);
13392 llvm::Type *Tys[2] = { Ty, VTy };
13397 case NEON::BI__builtin_neon_vmaxvq_s8: {
13398 Int = Intrinsic::aarch64_neon_smaxv;
13400 VTy = llvm::FixedVectorType::get(
Int8Ty, 16);
13401 llvm::Type *Tys[2] = { Ty, VTy };
13406 case NEON::BI__builtin_neon_vmaxvq_s16: {
13407 Int = Intrinsic::aarch64_neon_smaxv;
13409 VTy = llvm::FixedVectorType::get(
Int16Ty, 8);
13410 llvm::Type *Tys[2] = { Ty, VTy };
13415 case NEON::BI__builtin_neon_vmaxv_f16: {
13416 Int = Intrinsic::aarch64_neon_fmaxv;
13418 VTy = llvm::FixedVectorType::get(
HalfTy, 4);
13419 llvm::Type *Tys[2] = { Ty, VTy };
13424 case NEON::BI__builtin_neon_vmaxvq_f16: {
13425 Int = Intrinsic::aarch64_neon_fmaxv;
13427 VTy = llvm::FixedVectorType::get(
HalfTy, 8);
13428 llvm::Type *Tys[2] = { Ty, VTy };
13433 case NEON::BI__builtin_neon_vminv_u8: {
13434 Int = Intrinsic::aarch64_neon_uminv;
13436 VTy = llvm::FixedVectorType::get(
Int8Ty, 8);
13437 llvm::Type *Tys[2] = { Ty, VTy };
13442 case NEON::BI__builtin_neon_vminv_u16: {
13443 Int = Intrinsic::aarch64_neon_uminv;
13445 VTy = llvm::FixedVectorType::get(
Int16Ty, 4);
13446 llvm::Type *Tys[2] = { Ty, VTy };
13451 case NEON::BI__builtin_neon_vminvq_u8: {
13452 Int = Intrinsic::aarch64_neon_uminv;
13454 VTy = llvm::FixedVectorType::get(
Int8Ty, 16);
13455 llvm::Type *Tys[2] = { Ty, VTy };
13460 case NEON::BI__builtin_neon_vminvq_u16: {
13461 Int = Intrinsic::aarch64_neon_uminv;
13463 VTy = llvm::FixedVectorType::get(
Int16Ty, 8);
13464 llvm::Type *Tys[2] = { Ty, VTy };
13469 case NEON::BI__builtin_neon_vminv_s8: {
13470 Int = Intrinsic::aarch64_neon_sminv;
13472 VTy = llvm::FixedVectorType::get(
Int8Ty, 8);
13473 llvm::Type *Tys[2] = { Ty, VTy };
13478 case NEON::BI__builtin_neon_vminv_s16: {
13479 Int = Intrinsic::aarch64_neon_sminv;
13481 VTy = llvm::FixedVectorType::get(
Int16Ty, 4);
13482 llvm::Type *Tys[2] = { Ty, VTy };
13487 case NEON::BI__builtin_neon_vminvq_s8: {
13488 Int = Intrinsic::aarch64_neon_sminv;
13490 VTy = llvm::FixedVectorType::get(
Int8Ty, 16);
13491 llvm::Type *Tys[2] = { Ty, VTy };
13496 case NEON::BI__builtin_neon_vminvq_s16: {
13497 Int = Intrinsic::aarch64_neon_sminv;
13499 VTy = llvm::FixedVectorType::get(
Int16Ty, 8);
13500 llvm::Type *Tys[2] = { Ty, VTy };
13505 case NEON::BI__builtin_neon_vminv_f16: {
13506 Int = Intrinsic::aarch64_neon_fminv;
13508 VTy = llvm::FixedVectorType::get(
HalfTy, 4);
13509 llvm::Type *Tys[2] = { Ty, VTy };
13514 case NEON::BI__builtin_neon_vminvq_f16: {
13515 Int = Intrinsic::aarch64_neon_fminv;
13517 VTy = llvm::FixedVectorType::get(
HalfTy, 8);
13518 llvm::Type *Tys[2] = { Ty, VTy };
13523 case NEON::BI__builtin_neon_vmaxnmv_f16: {
13524 Int = Intrinsic::aarch64_neon_fmaxnmv;
13526 VTy = llvm::FixedVectorType::get(
HalfTy, 4);
13527 llvm::Type *Tys[2] = { Ty, VTy };
13532 case NEON::BI__builtin_neon_vmaxnmvq_f16: {
13533 Int = Intrinsic::aarch64_neon_fmaxnmv;
13535 VTy = llvm::FixedVectorType::get(
HalfTy, 8);
13536 llvm::Type *Tys[2] = { Ty, VTy };
13541 case NEON::BI__builtin_neon_vminnmv_f16: {
13542 Int = Intrinsic::aarch64_neon_fminnmv;
13544 VTy = llvm::FixedVectorType::get(
HalfTy, 4);
13545 llvm::Type *Tys[2] = { Ty, VTy };
13550 case NEON::BI__builtin_neon_vminnmvq_f16: {
13551 Int = Intrinsic::aarch64_neon_fminnmv;
13553 VTy = llvm::FixedVectorType::get(
HalfTy, 8);
13554 llvm::Type *Tys[2] = { Ty, VTy };
13559 case NEON::BI__builtin_neon_vmul_n_f64: {
13562 return Builder.CreateFMul(Ops[0], RHS);
13564 case NEON::BI__builtin_neon_vaddlv_u8: {
13565 Int = Intrinsic::aarch64_neon_uaddlv;
13567 VTy = llvm::FixedVectorType::get(
Int8Ty, 8);
13568 llvm::Type *Tys[2] = { Ty, VTy };
13573 case NEON::BI__builtin_neon_vaddlv_u16: {
13574 Int = Intrinsic::aarch64_neon_uaddlv;
13576 VTy = llvm::FixedVectorType::get(
Int16Ty, 4);
13577 llvm::Type *Tys[2] = { Ty, VTy };
13581 case NEON::BI__builtin_neon_vaddlvq_u8: {
13582 Int = Intrinsic::aarch64_neon_uaddlv;
13584 VTy = llvm::FixedVectorType::get(
Int8Ty, 16);
13585 llvm::Type *Tys[2] = { Ty, VTy };
13590 case NEON::BI__builtin_neon_vaddlvq_u16: {
13591 Int = Intrinsic::aarch64_neon_uaddlv;
13593 VTy = llvm::FixedVectorType::get(
Int16Ty, 8);
13594 llvm::Type *Tys[2] = { Ty, VTy };
13598 case NEON::BI__builtin_neon_vaddlv_s8: {
13599 Int = Intrinsic::aarch64_neon_saddlv;
13601 VTy = llvm::FixedVectorType::get(
Int8Ty, 8);
13602 llvm::Type *Tys[2] = { Ty, VTy };
13607 case NEON::BI__builtin_neon_vaddlv_s16: {
13608 Int = Intrinsic::aarch64_neon_saddlv;
13610 VTy = llvm::FixedVectorType::get(
Int16Ty, 4);
13611 llvm::Type *Tys[2] = { Ty, VTy };
13615 case NEON::BI__builtin_neon_vaddlvq_s8: {
13616 Int = Intrinsic::aarch64_neon_saddlv;
13618 VTy = llvm::FixedVectorType::get(
Int8Ty, 16);
13619 llvm::Type *Tys[2] = { Ty, VTy };
13624 case NEON::BI__builtin_neon_vaddlvq_s16: {
13625 Int = Intrinsic::aarch64_neon_saddlv;
13627 VTy = llvm::FixedVectorType::get(
Int16Ty, 8);
13628 llvm::Type *Tys[2] = { Ty, VTy };
13632 case NEON::BI__builtin_neon_vsri_n_v:
13633 case NEON::BI__builtin_neon_vsriq_n_v: {
13634 Int = Intrinsic::aarch64_neon_vsri;
13638 case NEON::BI__builtin_neon_vsli_n_v:
13639 case NEON::BI__builtin_neon_vsliq_n_v: {
13640 Int = Intrinsic::aarch64_neon_vsli;
13644 case NEON::BI__builtin_neon_vsra_n_v:
13645 case NEON::BI__builtin_neon_vsraq_n_v:
13646 Ops[0] =
Builder.CreateBitCast(Ops[0], Ty);
13648 return Builder.CreateAdd(Ops[0], Ops[1]);
13649 case NEON::BI__builtin_neon_vrsra_n_v:
13650 case NEON::BI__builtin_neon_vrsraq_n_v: {
13651 Int = usgn ? Intrinsic::aarch64_neon_urshl : Intrinsic::aarch64_neon_srshl;
13653 TmpOps.push_back(Ops[1]);
13654 TmpOps.push_back(Ops[2]);
13656 llvm::Value *tmp =
EmitNeonCall(F, TmpOps,
"vrshr_n", 1,
true);
13657 Ops[0] =
Builder.CreateBitCast(Ops[0], VTy);
13658 return Builder.CreateAdd(Ops[0], tmp);
13660 case NEON::BI__builtin_neon_vld1_v:
13661 case NEON::BI__builtin_neon_vld1q_v: {
13664 case NEON::BI__builtin_neon_vst1_v:
13665 case NEON::BI__builtin_neon_vst1q_v:
13666 Ops[1] =
Builder.CreateBitCast(Ops[1], VTy);
13668 case NEON::BI__builtin_neon_vld1_lane_v:
13669 case NEON::BI__builtin_neon_vld1q_lane_v: {
13670 Ops[1] =
Builder.CreateBitCast(Ops[1], Ty);
13673 return Builder.CreateInsertElement(Ops[1], Ops[0], Ops[2],
"vld1_lane");
13675 case NEON::BI__builtin_neon_vldap1_lane_s64:
13676 case NEON::BI__builtin_neon_vldap1q_lane_s64: {
13677 Ops[1] =
Builder.CreateBitCast(Ops[1], Ty);
13679 VTy->getElementType(), Ops[0], PtrOp0.
getAlignment());
13680 LI->setAtomic(llvm::AtomicOrdering::Acquire);
13682 return Builder.CreateInsertElement(Ops[1], Ops[0], Ops[2],
"vldap1_lane");
13684 case NEON::BI__builtin_neon_vld1_dup_v:
13685 case NEON::BI__builtin_neon_vld1q_dup_v: {
13686 Value *
V = PoisonValue::get(Ty);
13689 llvm::Constant *CI = ConstantInt::get(
Int32Ty, 0);
13690 Ops[0] =
Builder.CreateInsertElement(
V, Ops[0], CI);
13693 case NEON::BI__builtin_neon_vst1_lane_v:
13694 case NEON::BI__builtin_neon_vst1q_lane_v:
13695 Ops[1] =
Builder.CreateBitCast(Ops[1], Ty);
13696 Ops[1] =
Builder.CreateExtractElement(Ops[1], Ops[2]);
13698 case NEON::BI__builtin_neon_vstl1_lane_s64:
13699 case NEON::BI__builtin_neon_vstl1q_lane_s64: {
13700 Ops[1] =
Builder.CreateBitCast(Ops[1], Ty);
13701 Ops[1] =
Builder.CreateExtractElement(Ops[1], Ops[2]);
13702 llvm::StoreInst *SI =
13704 SI->setAtomic(llvm::AtomicOrdering::Release);
13707 case NEON::BI__builtin_neon_vld2_v:
13708 case NEON::BI__builtin_neon_vld2q_v: {
13711 Ops[1] =
Builder.CreateCall(F, Ops[1],
"vld2");
13714 case NEON::BI__builtin_neon_vld3_v:
13715 case NEON::BI__builtin_neon_vld3q_v: {
13718 Ops[1] =
Builder.CreateCall(F, Ops[1],
"vld3");
13721 case NEON::BI__builtin_neon_vld4_v:
13722 case NEON::BI__builtin_neon_vld4q_v: {
13725 Ops[1] =
Builder.CreateCall(F, Ops[1],
"vld4");
13728 case NEON::BI__builtin_neon_vld2_dup_v:
13729 case NEON::BI__builtin_neon_vld2q_dup_v: {
13732 Ops[1] =
Builder.CreateCall(F, Ops[1],
"vld2");
13735 case NEON::BI__builtin_neon_vld3_dup_v:
13736 case NEON::BI__builtin_neon_vld3q_dup_v: {
13739 Ops[1] =
Builder.CreateCall(F, Ops[1],
"vld3");
13742 case NEON::BI__builtin_neon_vld4_dup_v:
13743 case NEON::BI__builtin_neon_vld4q_dup_v: {
13746 Ops[1] =
Builder.CreateCall(F, Ops[1],
"vld4");
13749 case NEON::BI__builtin_neon_vld2_lane_v:
13750 case NEON::BI__builtin_neon_vld2q_lane_v: {
13751 llvm::Type *Tys[2] = { VTy, Ops[1]->getType() };
13753 std::rotate(Ops.begin() + 1, Ops.begin() + 2, Ops.end());
13754 Ops[1] =
Builder.CreateBitCast(Ops[1], Ty);
13755 Ops[2] =
Builder.CreateBitCast(Ops[2], Ty);
13760 case NEON::BI__builtin_neon_vld3_lane_v:
13761 case NEON::BI__builtin_neon_vld3q_lane_v: {
13762 llvm::Type *Tys[2] = { VTy, Ops[1]->getType() };
13764 std::rotate(Ops.begin() + 1, Ops.begin() + 2, Ops.end());
13765 Ops[1] =
Builder.CreateBitCast(Ops[1], Ty);
13766 Ops[2] =
Builder.CreateBitCast(Ops[2], Ty);
13767 Ops[3] =
Builder.CreateBitCast(Ops[3], Ty);
13772 case NEON::BI__builtin_neon_vld4_lane_v:
13773 case NEON::BI__builtin_neon_vld4q_lane_v: {
13774 llvm::Type *Tys[2] = { VTy, Ops[1]->getType() };
13776 std::rotate(Ops.begin() + 1, Ops.begin() + 2, Ops.end());
13777 Ops[1] =
Builder.CreateBitCast(Ops[1], Ty);
13778 Ops[2] =
Builder.CreateBitCast(Ops[2], Ty);
13779 Ops[3] =
Builder.CreateBitCast(Ops[3], Ty);
13780 Ops[4] =
Builder.CreateBitCast(Ops[4], Ty);
13785 case NEON::BI__builtin_neon_vst2_v:
13786 case NEON::BI__builtin_neon_vst2q_v: {
13787 std::rotate(Ops.begin(), Ops.begin() + 1, Ops.end());
13788 llvm::Type *Tys[2] = { VTy, Ops[2]->getType() };
13792 case NEON::BI__builtin_neon_vst2_lane_v:
13793 case NEON::BI__builtin_neon_vst2q_lane_v: {
13794 std::rotate(Ops.begin(), Ops.begin() + 1, Ops.end());
13796 llvm::Type *Tys[2] = { VTy, Ops[3]->getType() };
13800 case NEON::BI__builtin_neon_vst3_v:
13801 case NEON::BI__builtin_neon_vst3q_v: {
13802 std::rotate(Ops.begin(), Ops.begin() + 1, Ops.end());
13803 llvm::Type *Tys[2] = { VTy, Ops[3]->getType() };
13807 case NEON::BI__builtin_neon_vst3_lane_v:
13808 case NEON::BI__builtin_neon_vst3q_lane_v: {
13809 std::rotate(Ops.begin(), Ops.begin() + 1, Ops.end());
13811 llvm::Type *Tys[2] = { VTy, Ops[4]->getType() };
13815 case NEON::BI__builtin_neon_vst4_v:
13816 case NEON::BI__builtin_neon_vst4q_v: {
13817 std::rotate(Ops.begin(), Ops.begin() + 1, Ops.end());
13818 llvm::Type *Tys[2] = { VTy, Ops[4]->getType() };
13822 case NEON::BI__builtin_neon_vst4_lane_v:
13823 case NEON::BI__builtin_neon_vst4q_lane_v: {
13824 std::rotate(Ops.begin(), Ops.begin() + 1, Ops.end());
13826 llvm::Type *Tys[2] = { VTy, Ops[5]->getType() };
13830 case NEON::BI__builtin_neon_vtrn_v:
13831 case NEON::BI__builtin_neon_vtrnq_v: {
13832 Ops[1] =
Builder.CreateBitCast(Ops[1], Ty);
13833 Ops[2] =
Builder.CreateBitCast(Ops[2], Ty);
13834 Value *SV =
nullptr;
13836 for (
unsigned vi = 0; vi != 2; ++vi) {
13838 for (
unsigned i = 0, e = VTy->getNumElements(); i != e; i += 2) {
13839 Indices.push_back(i+vi);
13840 Indices.push_back(i+e+vi);
13842 Value *Addr =
Builder.CreateConstInBoundsGEP1_32(Ty, Ops[0], vi);
13843 SV =
Builder.CreateShuffleVector(Ops[1], Ops[2], Indices,
"vtrn");
13848 case NEON::BI__builtin_neon_vuzp_v:
13849 case NEON::BI__builtin_neon_vuzpq_v: {
13850 Ops[1] =
Builder.CreateBitCast(Ops[1], Ty);
13851 Ops[2] =
Builder.CreateBitCast(Ops[2], Ty);
13852 Value *SV =
nullptr;
13854 for (
unsigned vi = 0; vi != 2; ++vi) {
13856 for (
unsigned i = 0, e = VTy->getNumElements(); i != e; ++i)
13857 Indices.push_back(2*i+vi);
13859 Value *Addr =
Builder.CreateConstInBoundsGEP1_32(Ty, Ops[0], vi);
13860 SV =
Builder.CreateShuffleVector(Ops[1], Ops[2], Indices,
"vuzp");
13865 case NEON::BI__builtin_neon_vzip_v:
13866 case NEON::BI__builtin_neon_vzipq_v: {
13867 Ops[1] =
Builder.CreateBitCast(Ops[1], Ty);
13868 Ops[2] =
Builder.CreateBitCast(Ops[2], Ty);
13869 Value *SV =
nullptr;
13871 for (
unsigned vi = 0; vi != 2; ++vi) {
13873 for (
unsigned i = 0, e = VTy->getNumElements(); i != e; i += 2) {
13874 Indices.push_back((i + vi*e) >> 1);
13875 Indices.push_back(((i + vi*e) >> 1)+e);
13877 Value *Addr =
Builder.CreateConstInBoundsGEP1_32(Ty, Ops[0], vi);
13878 SV =
Builder.CreateShuffleVector(Ops[1], Ops[2], Indices,
"vzip");
13883 case NEON::BI__builtin_neon_vqtbl1q_v: {
13887 case NEON::BI__builtin_neon_vqtbl2q_v: {
13891 case NEON::BI__builtin_neon_vqtbl3q_v: {
13895 case NEON::BI__builtin_neon_vqtbl4q_v: {
13899 case NEON::BI__builtin_neon_vqtbx1q_v: {
13903 case NEON::BI__builtin_neon_vqtbx2q_v: {
13907 case NEON::BI__builtin_neon_vqtbx3q_v: {
13911 case NEON::BI__builtin_neon_vqtbx4q_v: {
13915 case NEON::BI__builtin_neon_vsqadd_v:
13916 case NEON::BI__builtin_neon_vsqaddq_v: {
13917 Int = Intrinsic::aarch64_neon_usqadd;
13920 case NEON::BI__builtin_neon_vuqadd_v:
13921 case NEON::BI__builtin_neon_vuqaddq_v: {
13922 Int = Intrinsic::aarch64_neon_suqadd;
13926 case NEON::BI__builtin_neon_vluti2_laneq_bf16:
13927 case NEON::BI__builtin_neon_vluti2_laneq_f16:
13928 case NEON::BI__builtin_neon_vluti2_laneq_p16:
13929 case NEON::BI__builtin_neon_vluti2_laneq_p8:
13930 case NEON::BI__builtin_neon_vluti2_laneq_s16:
13931 case NEON::BI__builtin_neon_vluti2_laneq_s8:
13932 case NEON::BI__builtin_neon_vluti2_laneq_u16:
13933 case NEON::BI__builtin_neon_vluti2_laneq_u8: {
13934 Int = Intrinsic::aarch64_neon_vluti2_laneq;
13935 llvm::Type *Tys[2];
13941 case NEON::BI__builtin_neon_vluti2q_laneq_bf16:
13942 case NEON::BI__builtin_neon_vluti2q_laneq_f16:
13943 case NEON::BI__builtin_neon_vluti2q_laneq_p16:
13944 case NEON::BI__builtin_neon_vluti2q_laneq_p8:
13945 case NEON::BI__builtin_neon_vluti2q_laneq_s16:
13946 case NEON::BI__builtin_neon_vluti2q_laneq_s8:
13947 case NEON::BI__builtin_neon_vluti2q_laneq_u16:
13948 case NEON::BI__builtin_neon_vluti2q_laneq_u8: {
13949 Int = Intrinsic::aarch64_neon_vluti2_laneq;
13950 llvm::Type *Tys[2];
13956 case NEON::BI__builtin_neon_vluti2_lane_bf16:
13957 case NEON::BI__builtin_neon_vluti2_lane_f16:
13958 case NEON::BI__builtin_neon_vluti2_lane_p16:
13959 case NEON::BI__builtin_neon_vluti2_lane_p8:
13960 case NEON::BI__builtin_neon_vluti2_lane_s16:
13961 case NEON::BI__builtin_neon_vluti2_lane_s8:
13962 case NEON::BI__builtin_neon_vluti2_lane_u16:
13963 case NEON::BI__builtin_neon_vluti2_lane_u8: {
13964 Int = Intrinsic::aarch64_neon_vluti2_lane;
13965 llvm::Type *Tys[2];
13971 case NEON::BI__builtin_neon_vluti2q_lane_bf16:
13972 case NEON::BI__builtin_neon_vluti2q_lane_f16:
13973 case NEON::BI__builtin_neon_vluti2q_lane_p16:
13974 case NEON::BI__builtin_neon_vluti2q_lane_p8:
13975 case NEON::BI__builtin_neon_vluti2q_lane_s16:
13976 case NEON::BI__builtin_neon_vluti2q_lane_s8:
13977 case NEON::BI__builtin_neon_vluti2q_lane_u16:
13978 case NEON::BI__builtin_neon_vluti2q_lane_u8: {
13979 Int = Intrinsic::aarch64_neon_vluti2_lane;
13980 llvm::Type *Tys[2];
13986 case NEON::BI__builtin_neon_vluti4q_lane_p8:
13987 case NEON::BI__builtin_neon_vluti4q_lane_s8:
13988 case NEON::BI__builtin_neon_vluti4q_lane_u8: {
13989 Int = Intrinsic::aarch64_neon_vluti4q_lane;
13992 case NEON::BI__builtin_neon_vluti4q_laneq_p8:
13993 case NEON::BI__builtin_neon_vluti4q_laneq_s8:
13994 case NEON::BI__builtin_neon_vluti4q_laneq_u8: {
13995 Int = Intrinsic::aarch64_neon_vluti4q_laneq;
13998 case NEON::BI__builtin_neon_vluti4q_lane_bf16_x2:
13999 case NEON::BI__builtin_neon_vluti4q_lane_f16_x2:
14000 case NEON::BI__builtin_neon_vluti4q_lane_p16_x2:
14001 case NEON::BI__builtin_neon_vluti4q_lane_s16_x2:
14002 case NEON::BI__builtin_neon_vluti4q_lane_u16_x2: {
14003 Int = Intrinsic::aarch64_neon_vluti4q_lane_x2;
14006 case NEON::BI__builtin_neon_vluti4q_laneq_bf16_x2:
14007 case NEON::BI__builtin_neon_vluti4q_laneq_f16_x2:
14008 case NEON::BI__builtin_neon_vluti4q_laneq_p16_x2:
14009 case NEON::BI__builtin_neon_vluti4q_laneq_s16_x2:
14010 case NEON::BI__builtin_neon_vluti4q_laneq_u16_x2: {
14011 Int = Intrinsic::aarch64_neon_vluti4q_laneq_x2;
14015 case NEON::BI__builtin_neon_vamin_f16:
14016 case NEON::BI__builtin_neon_vaminq_f16:
14017 case NEON::BI__builtin_neon_vamin_f32:
14018 case NEON::BI__builtin_neon_vaminq_f32:
14019 case NEON::BI__builtin_neon_vaminq_f64: {
14020 Int = Intrinsic::aarch64_neon_famin;
14023 case NEON::BI__builtin_neon_vamax_f16:
14024 case NEON::BI__builtin_neon_vamaxq_f16:
14025 case NEON::BI__builtin_neon_vamax_f32:
14026 case NEON::BI__builtin_neon_vamaxq_f32:
14027 case NEON::BI__builtin_neon_vamaxq_f64: {
14028 Int = Intrinsic::aarch64_neon_famax;
14031 case NEON::BI__builtin_neon_vscale_f16:
14032 case NEON::BI__builtin_neon_vscaleq_f16:
14033 case NEON::BI__builtin_neon_vscale_f32:
14034 case NEON::BI__builtin_neon_vscaleq_f32:
14035 case NEON::BI__builtin_neon_vscaleq_f64: {
14036 Int = Intrinsic::aarch64_neon_fp8_fscale;
14044 assert((BuiltinID == BPF::BI__builtin_preserve_field_info ||
14045 BuiltinID == BPF::BI__builtin_btf_type_id ||
14046 BuiltinID == BPF::BI__builtin_preserve_type_info ||
14047 BuiltinID == BPF::BI__builtin_preserve_enum_value) &&
14048 "unexpected BPF builtin");
14055 switch (BuiltinID) {
14057 llvm_unreachable(
"Unexpected BPF builtin");
14058 case BPF::BI__builtin_preserve_field_info: {
14059 const Expr *Arg =
E->getArg(0);
14064 "using __builtin_preserve_field_info() without -g");
14077 Value *InfoKind = ConstantInt::get(
Int64Ty,
C->getSExtValue());
14080 llvm::Function *FnGetFieldInfo = llvm::Intrinsic::getOrInsertDeclaration(
14081 &
CGM.
getModule(), llvm::Intrinsic::bpf_preserve_field_info,
14082 {FieldAddr->getType()});
14083 return Builder.CreateCall(FnGetFieldInfo, {FieldAddr, InfoKind});
14085 case BPF::BI__builtin_btf_type_id:
14086 case BPF::BI__builtin_preserve_type_info: {
14092 const Expr *Arg0 =
E->getArg(0);
14097 Value *FlagValue = ConstantInt::get(
Int64Ty, Flag->getSExtValue());
14098 Value *SeqNumVal = ConstantInt::get(
Int32Ty, BuiltinSeqNum++);
14100 llvm::Function *FnDecl;
14101 if (BuiltinID == BPF::BI__builtin_btf_type_id)
14102 FnDecl = llvm::Intrinsic::getOrInsertDeclaration(
14103 &
CGM.
getModule(), llvm::Intrinsic::bpf_btf_type_id, {});
14105 FnDecl = llvm::Intrinsic::getOrInsertDeclaration(
14106 &
CGM.
getModule(), llvm::Intrinsic::bpf_preserve_type_info, {});
14107 CallInst *
Fn =
Builder.CreateCall(FnDecl, {SeqNumVal, FlagValue});
14108 Fn->setMetadata(LLVMContext::MD_preserve_access_index, DbgInfo);
14111 case BPF::BI__builtin_preserve_enum_value: {
14117 const Expr *Arg0 =
E->getArg(0);
14122 const auto *UO = cast<UnaryOperator>(Arg0->
IgnoreParens());
14123 const auto *CE = cast<CStyleCastExpr>(UO->getSubExpr());
14124 const auto *DR = cast<DeclRefExpr>(CE->getSubExpr());
14125 const auto *Enumerator = cast<EnumConstantDecl>(DR->getDecl());
14127 auto InitVal = Enumerator->getInitVal();
14128 std::string InitValStr;
14129 if (InitVal.isNegative() || InitVal >
uint64_t(INT64_MAX))
14130 InitValStr = std::to_string(InitVal.getSExtValue());
14132 InitValStr = std::to_string(InitVal.getZExtValue());
14133 std::string EnumStr = Enumerator->getNameAsString() +
":" + InitValStr;
14134 Value *EnumStrVal =
Builder.CreateGlobalString(EnumStr);
14137 Value *FlagValue = ConstantInt::get(
Int64Ty, Flag->getSExtValue());
14138 Value *SeqNumVal = ConstantInt::get(
Int32Ty, BuiltinSeqNum++);
14140 llvm::Function *IntrinsicFn = llvm::Intrinsic::getOrInsertDeclaration(
14141 &
CGM.
getModule(), llvm::Intrinsic::bpf_preserve_enum_value, {});
14143 Builder.CreateCall(IntrinsicFn, {SeqNumVal, EnumStrVal, FlagValue});
14144 Fn->setMetadata(LLVMContext::MD_preserve_access_index, DbgInfo);
14152 assert((Ops.size() & (Ops.size() - 1)) == 0 &&
14153 "Not a power-of-two sized vector!");
14154 bool AllConstants =
true;
14155 for (
unsigned i = 0, e = Ops.size(); i != e && AllConstants; ++i)
14156 AllConstants &= isa<Constant>(Ops[i]);
14159 if (AllConstants) {
14161 for (
unsigned i = 0, e = Ops.size(); i != e; ++i)
14162 CstOps.push_back(cast<Constant>(Ops[i]));
14163 return llvm::ConstantVector::get(CstOps);
14168 llvm::FixedVectorType::get(Ops[0]->getType(), Ops.size()));
14170 for (
unsigned i = 0, e = Ops.size(); i != e; ++i)
14178 unsigned NumElts) {
14180 auto *MaskTy = llvm::FixedVectorType::get(
14182 cast<IntegerType>(Mask->
getType())->getBitWidth());
14183 Value *MaskVec = CGF.
Builder.CreateBitCast(Mask, MaskTy);
14189 for (
unsigned i = 0; i != NumElts; ++i)
14191 MaskVec = CGF.
Builder.CreateShuffleVector(
14192 MaskVec, MaskVec,
ArrayRef(Indices, NumElts),
"extract");
14199 Value *Ptr = Ops[0];
14203 cast<llvm::FixedVectorType>(Ops[1]->getType())->getNumElements());
14205 return CGF.
Builder.CreateMaskedStore(Ops[1], Ptr, Alignment, MaskVec);
14210 llvm::Type *Ty = Ops[1]->getType();
14211 Value *Ptr = Ops[0];
14214 CGF, Ops[2], cast<llvm::FixedVectorType>(Ty)->getNumElements());
14216 return CGF.
Builder.CreateMaskedLoad(Ty, Ptr, Alignment, MaskVec, Ops[1]);
14221 auto *ResultTy = cast<llvm::VectorType>(Ops[1]->getType());
14222 Value *Ptr = Ops[0];
14225 CGF, Ops[2], cast<FixedVectorType>(ResultTy)->getNumElements());
14227 llvm::Function *F = CGF.
CGM.
getIntrinsic(Intrinsic::masked_expandload,
14229 return CGF.
Builder.CreateCall(F, { Ptr, MaskVec, Ops[1] });
14235 auto *ResultTy = cast<llvm::FixedVectorType>(Ops[1]->getType());
14239 Intrinsic::ID IID = IsCompress ? Intrinsic::x86_avx512_mask_compress
14240 : Intrinsic::x86_avx512_mask_expand;
14242 return CGF.
Builder.CreateCall(F, { Ops[0], Ops[1], MaskVec });
14247 auto *ResultTy = cast<llvm::FixedVectorType>(Ops[1]->getType());
14248 Value *Ptr = Ops[0];
14252 llvm::Function *F = CGF.
CGM.
getIntrinsic(Intrinsic::masked_compressstore,
14254 return CGF.
Builder.CreateCall(F, { Ops[1], Ptr, MaskVec });
14259 bool InvertLHS =
false) {
14260 unsigned NumElts = Ops[0]->getType()->getIntegerBitWidth();
14265 LHS = CGF.
Builder.CreateNot(LHS);
14267 return CGF.
Builder.CreateBitCast(CGF.
Builder.CreateBinOp(Opc, LHS, RHS),
14268 Ops[0]->getType());
14272 Value *Amt,
bool IsRight) {
14273 llvm::Type *Ty = Op0->
getType();
14279 unsigned NumElts = cast<llvm::FixedVectorType>(Ty)->getNumElements();
14280 Amt = CGF.
Builder.CreateIntCast(Amt, Ty->getScalarType(),
false);
14281 Amt = CGF.
Builder.CreateVectorSplat(NumElts, Amt);
14284 unsigned IID = IsRight ? Intrinsic::fshr : Intrinsic::fshl;
14286 return CGF.
Builder.CreateCall(F, {Op0, Op1, Amt});
14291 Value *Op0 = Ops[0];
14292 Value *Op1 = Ops[1];
14293 llvm::Type *Ty = Op0->
getType();
14294 uint64_t Imm = cast<llvm::ConstantInt>(Ops[2])->getZExtValue() & 0x7;
14296 CmpInst::Predicate Pred;
14299 Pred = IsSigned ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT;
14302 Pred = IsSigned ? ICmpInst::ICMP_SLE : ICmpInst::ICMP_ULE;
14305 Pred = IsSigned ? ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT;
14308 Pred = IsSigned ? ICmpInst::ICMP_SGE : ICmpInst::ICMP_UGE;
14311 Pred = ICmpInst::ICMP_EQ;
14314 Pred = ICmpInst::ICMP_NE;
14317 return llvm::Constant::getNullValue(Ty);
14319 return llvm::Constant::getAllOnesValue(Ty);
14321 llvm_unreachable(
"Unexpected XOP vpcom/vpcomu predicate");
14333 if (
const auto *
C = dyn_cast<Constant>(Mask))
14334 if (
C->isAllOnesValue())
14338 CGF, Mask, cast<llvm::FixedVectorType>(Op0->
getType())->getNumElements());
14340 return CGF.
Builder.CreateSelect(Mask, Op0, Op1);
14346 if (
const auto *
C = dyn_cast<Constant>(Mask))
14347 if (
C->isAllOnesValue())
14350 auto *MaskTy = llvm::FixedVectorType::get(
14351 CGF.
Builder.getInt1Ty(), Mask->
getType()->getIntegerBitWidth());
14352 Mask = CGF.
Builder.CreateBitCast(Mask, MaskTy);
14353 Mask = CGF.
Builder.CreateExtractElement(Mask, (uint64_t)0);
14354 return CGF.
Builder.CreateSelect(Mask, Op0, Op1);
14358 unsigned NumElts,
Value *MaskIn) {
14360 const auto *
C = dyn_cast<Constant>(MaskIn);
14361 if (!
C || !
C->isAllOnesValue())
14367 for (
unsigned i = 0; i != NumElts; ++i)
14369 for (
unsigned i = NumElts; i != 8; ++i)
14370 Indices[i] = i % NumElts + NumElts;
14371 Cmp = CGF.
Builder.CreateShuffleVector(
14372 Cmp, llvm::Constant::getNullValue(Cmp->getType()), Indices);
14375 return CGF.
Builder.CreateBitCast(Cmp,
14377 std::max(NumElts, 8U)));
14382 assert((Ops.size() == 2 || Ops.size() == 4) &&
14383 "Unexpected number of arguments");
14385 cast<llvm::FixedVectorType>(Ops[0]->getType())->getNumElements();
14389 Cmp = Constant::getNullValue(
14390 llvm::FixedVectorType::get(CGF.
Builder.getInt1Ty(), NumElts));
14391 }
else if (CC == 7) {
14392 Cmp = Constant::getAllOnesValue(
14393 llvm::FixedVectorType::get(CGF.
Builder.getInt1Ty(), NumElts));
14395 ICmpInst::Predicate Pred;
14397 default: llvm_unreachable(
"Unknown condition code");
14398 case 0: Pred = ICmpInst::ICMP_EQ;
break;
14399 case 1: Pred =
Signed ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT;
break;
14400 case 2: Pred =
Signed ? ICmpInst::ICMP_SLE : ICmpInst::ICMP_ULE;
break;
14401 case 4: Pred = ICmpInst::ICMP_NE;
break;
14402 case 5: Pred =
Signed ? ICmpInst::ICMP_SGE : ICmpInst::ICMP_UGE;
break;
14403 case 6: Pred =
Signed ? ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT;
break;
14405 Cmp = CGF.
Builder.CreateICmp(Pred, Ops[0], Ops[1]);
14408 Value *MaskIn =
nullptr;
14409 if (Ops.size() == 4)
14416 Value *Zero = Constant::getNullValue(In->getType());
14422 unsigned Rnd = cast<llvm::ConstantInt>(Ops[3])->getZExtValue();
14423 llvm::Type *Ty = Ops[1]->getType();
14427 Intrinsic::ID IID = IsSigned ? Intrinsic::x86_avx512_sitofp_round
14428 : Intrinsic::x86_avx512_uitofp_round;
14430 Res = CGF.
Builder.CreateCall(F, { Ops[0], Ops[3] });
14432 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF,
E);
14433 Res = IsSigned ? CGF.
Builder.CreateSIToFP(Ops[0], Ty)
14434 : CGF.
Builder.CreateUIToFP(Ops[0], Ty);
14445 bool Subtract =
false;
14446 Intrinsic::ID IID = Intrinsic::not_intrinsic;
14447 switch (BuiltinID) {
14449 case clang::X86::BI__builtin_ia32_vfmsubph512_mask3:
14452 case clang::X86::BI__builtin_ia32_vfmaddph512_mask:
14453 case clang::X86::BI__builtin_ia32_vfmaddph512_maskz:
14454 case clang::X86::BI__builtin_ia32_vfmaddph512_mask3:
14455 IID = llvm::Intrinsic::x86_avx512fp16_vfmadd_ph_512;
14457 case clang::X86::BI__builtin_ia32_vfmsubaddph512_mask3:
14460 case clang::X86::BI__builtin_ia32_vfmaddsubph512_mask:
14461 case clang::X86::BI__builtin_ia32_vfmaddsubph512_maskz:
14462 case clang::X86::BI__builtin_ia32_vfmaddsubph512_mask3:
14463 IID = llvm::Intrinsic::x86_avx512fp16_vfmaddsub_ph_512;
14465 case clang::X86::BI__builtin_ia32_vfmsubps512_mask3:
14468 case clang::X86::BI__builtin_ia32_vfmaddps512_mask:
14469 case clang::X86::BI__builtin_ia32_vfmaddps512_maskz:
14470 case clang::X86::BI__builtin_ia32_vfmaddps512_mask3:
14471 IID = llvm::Intrinsic::x86_avx512_vfmadd_ps_512;
break;
14472 case clang::X86::BI__builtin_ia32_vfmsubpd512_mask3:
14475 case clang::X86::BI__builtin_ia32_vfmaddpd512_mask:
14476 case clang::X86::BI__builtin_ia32_vfmaddpd512_maskz:
14477 case clang::X86::BI__builtin_ia32_vfmaddpd512_mask3:
14478 IID = llvm::Intrinsic::x86_avx512_vfmadd_pd_512;
break;
14479 case clang::X86::BI__builtin_ia32_vfmsubaddps512_mask3:
14482 case clang::X86::BI__builtin_ia32_vfmaddsubps512_mask:
14483 case clang::X86::BI__builtin_ia32_vfmaddsubps512_maskz:
14484 case clang::X86::BI__builtin_ia32_vfmaddsubps512_mask3:
14485 IID = llvm::Intrinsic::x86_avx512_vfmaddsub_ps_512;
14487 case clang::X86::BI__builtin_ia32_vfmsubaddpd512_mask3:
14490 case clang::X86::BI__builtin_ia32_vfmaddsubpd512_mask:
14491 case clang::X86::BI__builtin_ia32_vfmaddsubpd512_maskz:
14492 case clang::X86::BI__builtin_ia32_vfmaddsubpd512_mask3:
14493 IID = llvm::Intrinsic::x86_avx512_vfmaddsub_pd_512;
14495 case clang::X86::BI__builtin_ia32_vfmsubph256_round_mask3:
14498 case clang::X86::BI__builtin_ia32_vfmaddph256_round_mask:
14499 case clang::X86::BI__builtin_ia32_vfmaddph256_round_maskz:
14500 case clang::X86::BI__builtin_ia32_vfmaddph256_round_mask3:
14501 IID = llvm::Intrinsic::x86_avx10_vfmaddph256;
14503 case clang::X86::BI__builtin_ia32_vfmsubaddph256_round_mask3:
14506 case clang::X86::BI__builtin_ia32_vfmaddsubph256_round_mask:
14507 case clang::X86::BI__builtin_ia32_vfmaddsubph256_round_maskz:
14508 case clang::X86::BI__builtin_ia32_vfmaddsubph256_round_mask3:
14509 IID = llvm::Intrinsic::x86_avx10_vfmaddsubph256;
14511 case clang::X86::BI__builtin_ia32_vfmsubps256_round_mask3:
14514 case clang::X86::BI__builtin_ia32_vfmaddps256_round_mask:
14515 case clang::X86::BI__builtin_ia32_vfmaddps256_round_maskz:
14516 case clang::X86::BI__builtin_ia32_vfmaddps256_round_mask3:
14517 IID = llvm::Intrinsic::x86_avx10_vfmaddps256;
14519 case clang::X86::BI__builtin_ia32_vfmsubpd256_round_mask3:
14522 case clang::X86::BI__builtin_ia32_vfmaddpd256_round_mask:
14523 case clang::X86::BI__builtin_ia32_vfmaddpd256_round_maskz:
14524 case clang::X86::BI__builtin_ia32_vfmaddpd256_round_mask3:
14525 IID = llvm::Intrinsic::x86_avx10_vfmaddpd256;
14527 case clang::X86::BI__builtin_ia32_vfmsubaddps256_round_mask3:
14530 case clang::X86::BI__builtin_ia32_vfmaddsubps256_round_mask:
14531 case clang::X86::BI__builtin_ia32_vfmaddsubps256_round_maskz:
14532 case clang::X86::BI__builtin_ia32_vfmaddsubps256_round_mask3:
14533 IID = llvm::Intrinsic::x86_avx10_vfmaddsubps256;
14535 case clang::X86::BI__builtin_ia32_vfmsubaddpd256_round_mask3:
14538 case clang::X86::BI__builtin_ia32_vfmaddsubpd256_round_mask:
14539 case clang::X86::BI__builtin_ia32_vfmaddsubpd256_round_maskz:
14540 case clang::X86::BI__builtin_ia32_vfmaddsubpd256_round_mask3:
14541 IID = llvm::Intrinsic::x86_avx10_vfmaddsubpd256;
14555 if (IID != Intrinsic::not_intrinsic &&
14556 (cast<llvm::ConstantInt>(Ops.back())->getZExtValue() != (uint64_t)4 ||
14559 Res = CGF.
Builder.CreateCall(Intr, {A, B,
C, Ops.back() });
14561 llvm::Type *Ty = A->
getType();
14563 if (CGF.
Builder.getIsFPConstrained()) {
14564 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF,
E);
14565 FMA = CGF.
CGM.
getIntrinsic(Intrinsic::experimental_constrained_fma, Ty);
14566 Res = CGF.
Builder.CreateConstrainedFPCall(FMA, {A, B,
C});
14569 Res = CGF.
Builder.CreateCall(FMA, {A, B,
C});
14574 Value *MaskFalseVal =
nullptr;
14575 switch (BuiltinID) {
14576 case clang::X86::BI__builtin_ia32_vfmaddph512_mask:
14577 case clang::X86::BI__builtin_ia32_vfmaddps512_mask:
14578 case clang::X86::BI__builtin_ia32_vfmaddpd512_mask:
14579 case clang::X86::BI__builtin_ia32_vfmaddsubph512_mask:
14580 case clang::X86::BI__builtin_ia32_vfmaddsubps512_mask:
14581 case clang::X86::BI__builtin_ia32_vfmaddsubpd512_mask:
14582 case clang::X86::BI__builtin_ia32_vfmaddph256_round_mask:
14583 case clang::X86::BI__builtin_ia32_vfmaddps256_round_mask:
14584 case clang::X86::BI__builtin_ia32_vfmaddpd256_round_mask:
14585 case clang::X86::BI__builtin_ia32_vfmaddsubph256_round_mask:
14586 case clang::X86::BI__builtin_ia32_vfmaddsubps256_round_mask:
14587 case clang::X86::BI__builtin_ia32_vfmaddsubpd256_round_mask:
14588 MaskFalseVal = Ops[0];
14590 case clang::X86::BI__builtin_ia32_vfmaddph512_maskz:
14591 case clang::X86::BI__builtin_ia32_vfmaddps512_maskz:
14592 case clang::X86::BI__builtin_ia32_vfmaddpd512_maskz:
14593 case clang::X86::BI__builtin_ia32_vfmaddsubph512_maskz:
14594 case clang::X86::BI__builtin_ia32_vfmaddsubps512_maskz:
14595 case clang::X86::BI__builtin_ia32_vfmaddsubpd512_maskz:
14596 case clang::X86::BI__builtin_ia32_vfmaddph256_round_maskz:
14597 case clang::X86::BI__builtin_ia32_vfmaddps256_round_maskz:
14598 case clang::X86::BI__builtin_ia32_vfmaddpd256_round_maskz:
14599 case clang::X86::BI__builtin_ia32_vfmaddsubph256_round_maskz:
14600 case clang::X86::BI__builtin_ia32_vfmaddsubps256_round_maskz:
14601 case clang::X86::BI__builtin_ia32_vfmaddsubpd256_round_maskz:
14602 MaskFalseVal = Constant::getNullValue(Ops[0]->getType());
14604 case clang::X86::BI__builtin_ia32_vfmsubph512_mask3:
14605 case clang::X86::BI__builtin_ia32_vfmaddph512_mask3:
14606 case clang::X86::BI__builtin_ia32_vfmsubps512_mask3:
14607 case clang::X86::BI__builtin_ia32_vfmaddps512_mask3:
14608 case clang::X86::BI__builtin_ia32_vfmsubpd512_mask3:
14609 case clang::X86::BI__builtin_ia32_vfmaddpd512_mask3:
14610 case clang::X86::BI__builtin_ia32_vfmsubaddph512_mask3:
14611 case clang::X86::BI__builtin_ia32_vfmaddsubph512_mask3:
14612 case clang::X86::BI__builtin_ia32_vfmsubaddps512_mask3:
14613 case clang::X86::BI__builtin_ia32_vfmaddsubps512_mask3:
14614 case clang::X86::BI__builtin_ia32_vfmsubaddpd512_mask3:
14615 case clang::X86::BI__builtin_ia32_vfmaddsubpd512_mask3:
14616 case clang::X86::BI__builtin_ia32_vfmsubph256_round_mask3:
14617 case clang::X86::BI__builtin_ia32_vfmaddph256_round_mask3:
14618 case clang::X86::BI__builtin_ia32_vfmsubps256_round_mask3:
14619 case clang::X86::BI__builtin_ia32_vfmaddps256_round_mask3:
14620 case clang::X86::BI__builtin_ia32_vfmsubpd256_round_mask3:
14621 case clang::X86::BI__builtin_ia32_vfmaddpd256_round_mask3:
14622 case clang::X86::BI__builtin_ia32_vfmsubaddph256_round_mask3:
14623 case clang::X86::BI__builtin_ia32_vfmaddsubph256_round_mask3:
14624 case clang::X86::BI__builtin_ia32_vfmsubaddps256_round_mask3:
14625 case clang::X86::BI__builtin_ia32_vfmaddsubps256_round_mask3:
14626 case clang::X86::BI__builtin_ia32_vfmsubaddpd256_round_mask3:
14627 case clang::X86::BI__builtin_ia32_vfmaddsubpd256_round_mask3:
14628 MaskFalseVal = Ops[2];
14640 bool ZeroMask =
false,
unsigned PTIdx = 0,
14641 bool NegAcc =
false) {
14643 if (Ops.size() > 4)
14644 Rnd = cast<llvm::ConstantInt>(Ops[4])->getZExtValue();
14647 Ops[2] = CGF.
Builder.CreateFNeg(Ops[2]);
14649 Ops[0] = CGF.
Builder.CreateExtractElement(Ops[0], (uint64_t)0);
14650 Ops[1] = CGF.
Builder.CreateExtractElement(Ops[1], (uint64_t)0);
14651 Ops[2] = CGF.
Builder.CreateExtractElement(Ops[2], (uint64_t)0);
14656 switch (Ops[0]->getType()->getPrimitiveSizeInBits()) {
14658 IID = Intrinsic::x86_avx512fp16_vfmadd_f16;
14661 IID = Intrinsic::x86_avx512_vfmadd_f32;
14664 IID = Intrinsic::x86_avx512_vfmadd_f64;
14667 llvm_unreachable(
"Unexpected size");
14670 {Ops[0], Ops[1], Ops[2], Ops[4]});
14671 }
else if (CGF.
Builder.getIsFPConstrained()) {
14672 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF,
E);
14674 Intrinsic::experimental_constrained_fma, Ops[0]->getType());
14675 Res = CGF.
Builder.CreateConstrainedFPCall(FMA, Ops.slice(0, 3));
14678 Res = CGF.
Builder.CreateCall(FMA, Ops.slice(0, 3));
14681 if (Ops.size() > 3) {
14682 Value *PassThru = ZeroMask ? Constant::getNullValue(Res->
getType())
14688 if (NegAcc && PTIdx == 2)
14689 PassThru = CGF.
Builder.CreateExtractElement(Upper, (uint64_t)0);
14693 return CGF.
Builder.CreateInsertElement(Upper, Res, (uint64_t)0);
14698 llvm::Type *Ty = Ops[0]->getType();
14700 Ty = llvm::FixedVectorType::get(CGF.
Int64Ty,
14701 Ty->getPrimitiveSizeInBits() / 64);
14707 Constant *ShiftAmt = ConstantInt::get(Ty, 32);
14708 LHS = CGF.
Builder.CreateShl(LHS, ShiftAmt);
14709 LHS = CGF.
Builder.CreateAShr(LHS, ShiftAmt);
14710 RHS = CGF.
Builder.CreateShl(RHS, ShiftAmt);
14711 RHS = CGF.
Builder.CreateAShr(RHS, ShiftAmt);
14714 Constant *Mask = ConstantInt::get(Ty, 0xffffffff);
14715 LHS = CGF.
Builder.CreateAnd(LHS, Mask);
14716 RHS = CGF.
Builder.CreateAnd(RHS, Mask);
14719 return CGF.
Builder.CreateMul(LHS, RHS);
14727 llvm::Type *Ty = Ops[0]->getType();
14729 unsigned VecWidth = Ty->getPrimitiveSizeInBits();
14730 unsigned EltWidth = Ty->getScalarSizeInBits();
14732 if (VecWidth == 128 && EltWidth == 32)
14733 IID = Intrinsic::x86_avx512_pternlog_d_128;
14734 else if (VecWidth == 256 && EltWidth == 32)
14735 IID = Intrinsic::x86_avx512_pternlog_d_256;
14736 else if (VecWidth == 512 && EltWidth == 32)
14737 IID = Intrinsic::x86_avx512_pternlog_d_512;
14738 else if (VecWidth == 128 && EltWidth == 64)
14739 IID = Intrinsic::x86_avx512_pternlog_q_128;
14740 else if (VecWidth == 256 && EltWidth == 64)
14741 IID = Intrinsic::x86_avx512_pternlog_q_256;
14742 else if (VecWidth == 512 && EltWidth == 64)
14743 IID = Intrinsic::x86_avx512_pternlog_q_512;
14745 llvm_unreachable(
"Unexpected intrinsic");
14749 Value *PassThru = ZeroMask ? ConstantAggregateZero::get(Ty) : Ops[0];
14754 llvm::Type *DstTy) {
14755 unsigned NumberOfElements =
14756 cast<llvm::FixedVectorType>(DstTy)->getNumElements();
14758 return CGF.
Builder.CreateSExt(Mask, DstTy,
"vpmovm2");
14763 StringRef CPUStr = cast<clang::StringLiteral>(CPUExpr)->getString();
14764 return EmitX86CpuIs(CPUStr);
14770 llvm::Type *DstTy) {
14771 assert((Ops.size() == 1 || Ops.size() == 3 || Ops.size() == 4) &&
14772 "Unknown cvtph2ps intrinsic");
14775 if (Ops.size() == 4 && cast<llvm::ConstantInt>(Ops[3])->getZExtValue() != 4) {
14778 return CGF.
Builder.CreateCall(F, {Ops[0], Ops[1], Ops[2], Ops[3]});
14781 unsigned NumDstElts = cast<llvm::FixedVectorType>(DstTy)->getNumElements();
14782 Value *Src = Ops[0];
14786 cast<llvm::FixedVectorType>(Src->
getType())->getNumElements()) {
14787 assert(NumDstElts == 4 &&
"Unexpected vector size");
14792 auto *HalfTy = llvm::FixedVectorType::get(
14794 Src = CGF.
Builder.CreateBitCast(Src, HalfTy);
14797 Value *Res = CGF.
Builder.CreateFPExt(Src, DstTy,
"cvtph2ps");
14799 if (Ops.size() >= 3)
14804Value *CodeGenFunction::EmitX86CpuIs(StringRef CPUStr) {
14815 llvm::ArrayType::get(
Int32Ty, 1));
14819 cast<llvm::GlobalValue>(CpuModel)->setDSOLocal(
true);
14825 std::tie(Index,
Value) = StringSwitch<std::pair<unsigned, unsigned>>(CPUStr)
14827 .Case(STRING, {0u,
static_cast<unsigned>(llvm::X86::ENUM)})
14829 .Case(
ALIAS, {1u,
static_cast<unsigned>(llvm::X86::ENUM)})
14831 .Case(STR, {1u,
static_cast<unsigned>(llvm::X86::ENUM)})
14833 .Case(
ALIAS, {2u,
static_cast<unsigned>(llvm::X86::ENUM)})
14835 .Case(STR, {2u,
static_cast<unsigned>(llvm::X86::ENUM)})
14836#include
"llvm/TargetParser/X86TargetParser.def"
14838 assert(
Value != 0 &&
"Invalid CPUStr passed to CpuIs");
14841 llvm::Value *Idxs[] = {ConstantInt::get(
Int32Ty, 0),
14842 ConstantInt::get(
Int32Ty, Index)};
14848 return Builder.CreateICmpEQ(CpuValue,
14854 StringRef FeatureStr = cast<StringLiteral>(FeatureExpr)->getString();
14855 if (!
getContext().getTargetInfo().validateCpuSupports(FeatureStr))
14857 return EmitX86CpuSupports(FeatureStr);
14861 return EmitX86CpuSupports(llvm::X86::getCpuSupportsMask(FeatureStrs));
14865CodeGenFunction::EmitX86CpuSupports(std::array<uint32_t, 4> FeatureMask) {
14867 if (FeatureMask[0] != 0) {
14875 llvm::ArrayType::get(
Int32Ty, 1));
14879 cast<llvm::GlobalValue>(CpuModel)->setDSOLocal(
true);
14896 llvm::Type *ATy = llvm::ArrayType::get(
Int32Ty, 3);
14897 llvm::Constant *CpuFeatures2 =
14899 cast<llvm::GlobalValue>(CpuFeatures2)->setDSOLocal(
true);
14900 for (
int i = 1; i != 4; ++i) {
14901 const uint32_t M = FeatureMask[i];
14918Value *CodeGenFunction::EmitAArch64CpuInit() {
14919 llvm::FunctionType *FTy = llvm::FunctionType::get(
VoidTy,
false);
14920 llvm::FunctionCallee
Func =
14922 cast<llvm::GlobalValue>(
Func.getCallee())->setDSOLocal(
true);
14923 cast<llvm::GlobalValue>(
Func.getCallee())
14924 ->setDLLStorageClass(llvm::GlobalValue::DefaultStorageClass);
14929 llvm::FunctionType *FTy = llvm::FunctionType::get(
VoidTy, {
VoidPtrTy},
false);
14930 llvm::FunctionCallee
Func =
14932 auto *CalleeGV = cast<llvm::GlobalValue>(
Func.getCallee());
14933 CalleeGV->setDSOLocal(
true);
14934 CalleeGV->setDLLStorageClass(llvm::GlobalValue::DefaultStorageClass);
14938Value *CodeGenFunction::EmitX86CpuInit() {
14939 llvm::FunctionType *FTy = llvm::FunctionType::get(
VoidTy,
14941 llvm::FunctionCallee
Func =
14943 cast<llvm::GlobalValue>(
Func.getCallee())->setDSOLocal(
true);
14944 cast<llvm::GlobalValue>(
Func.getCallee())
14945 ->setDLLStorageClass(llvm::GlobalValue::DefaultStorageClass);
14949Value *CodeGenFunction::EmitAArch64CpuSupports(
const CallExpr *
E) {
14951 StringRef ArgStr = cast<StringLiteral>(ArgExpr)->getString();
14953 ArgStr.split(Features,
"+");
14954 for (
auto &Feature : Features) {
14955 Feature = Feature.trim();
14956 if (!llvm::AArch64::parseFMVExtension(Feature))
14958 if (Feature !=
"default")
14959 Features.push_back(Feature);
14961 return EmitAArch64CpuSupports(Features);
14966 uint64_t FeaturesMask = llvm::AArch64::getCpuSupportsMask(FeaturesStrs);
14968 if (FeaturesMask != 0) {
14973 llvm::Type *STy = llvm::StructType::get(
Int64Ty);
14974 llvm::Constant *AArch64CPUFeatures =
14976 cast<llvm::GlobalValue>(AArch64CPUFeatures)->setDSOLocal(
true);
14978 STy, AArch64CPUFeatures,
14993 StringRef FeatureStr = cast<StringLiteral>(FeatureExpr)->getString();
14994 if (!
getContext().getTargetInfo().validateCpuSupports(FeatureStr))
15002 llvm::Type *Int32Ty = Builder.getInt32Ty();
15003 llvm::Type *Int64Ty = Builder.getInt64Ty();
15004 llvm::ArrayType *ArrayOfInt64Ty =
15005 llvm::ArrayType::get(Int64Ty, llvm::RISCVISAInfo::FeatureBitSize);
15006 llvm::Type *StructTy = llvm::StructType::get(Int32Ty, ArrayOfInt64Ty);
15007 llvm::Constant *RISCVFeaturesBits =
15009 cast<llvm::GlobalValue>(RISCVFeaturesBits)->setDSOLocal(
true);
15010 Value *IndexVal = llvm::ConstantInt::get(Int32Ty, Index);
15011 llvm::Value *GEPIndices[] = {Builder.getInt32(0), Builder.getInt32(1),
15014 Builder.CreateInBoundsGEP(StructTy, RISCVFeaturesBits, GEPIndices);
15015 Value *FeaturesBit =
15017 return FeaturesBit;
15021 const unsigned RISCVFeatureLength = llvm::RISCVISAInfo::FeatureBitSize;
15022 uint64_t RequireBitMasks[RISCVFeatureLength] = {0};
15024 for (
auto Feat : FeaturesStrs) {
15025 auto [GroupID, BitPos] = RISCVISAInfo::getRISCVFeaturesBitsInfo(Feat);
15032 RequireBitMasks[GroupID] |= (1ULL << BitPos);
15036 for (
unsigned Idx = 0; Idx < RISCVFeatureLength; Idx++) {
15037 if (RequireBitMasks[Idx] == 0)
15047 assert(
Result &&
"Should have value here.");
15054 if (BuiltinID == Builtin::BI__builtin_cpu_is)
15055 return EmitX86CpuIs(
E);
15056 if (BuiltinID == Builtin::BI__builtin_cpu_supports)
15057 return EmitX86CpuSupports(
E);
15058 if (BuiltinID == Builtin::BI__builtin_cpu_init)
15059 return EmitX86CpuInit();
15067 bool IsMaskFCmp =
false;
15068 bool IsConjFMA =
false;
15071 unsigned ICEArguments = 0;
15076 for (
unsigned i = 0, e =
E->getNumArgs(); i != e; i++) {
15086 auto getCmpIntrinsicCall = [
this, &Ops](Intrinsic::ID
ID,
unsigned Imm) {
15087 Ops.push_back(llvm::ConstantInt::get(
Int8Ty, Imm));
15089 return Builder.CreateCall(F, Ops);
15097 auto getVectorFCmpIR = [
this, &Ops,
E](CmpInst::Predicate Pred,
15098 bool IsSignaling) {
15099 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*
this,
E);
15102 Cmp =
Builder.CreateFCmpS(Pred, Ops[0], Ops[1]);
15104 Cmp =
Builder.CreateFCmp(Pred, Ops[0], Ops[1]);
15105 llvm::VectorType *FPVecTy = cast<llvm::VectorType>(Ops[0]->getType());
15106 llvm::VectorType *IntVecTy = llvm::VectorType::getInteger(FPVecTy);
15108 return Builder.CreateBitCast(Sext, FPVecTy);
15111 switch (BuiltinID) {
15112 default:
return nullptr;
15113 case X86::BI_mm_prefetch: {
15115 ConstantInt *
C = cast<ConstantInt>(Ops[1]);
15116 Value *RW = ConstantInt::get(
Int32Ty, (
C->getZExtValue() >> 2) & 0x1);
15117 Value *Locality = ConstantInt::get(
Int32Ty,
C->getZExtValue() & 0x3);
15122 case X86::BI_mm_clflush: {
15126 case X86::BI_mm_lfence: {
15129 case X86::BI_mm_mfence: {
15132 case X86::BI_mm_sfence: {
15135 case X86::BI_mm_pause: {
15138 case X86::BI__rdtsc: {
15141 case X86::BI__builtin_ia32_rdtscp: {
15147 case X86::BI__builtin_ia32_lzcnt_u16:
15148 case X86::BI__builtin_ia32_lzcnt_u32:
15149 case X86::BI__builtin_ia32_lzcnt_u64: {
15153 case X86::BI__builtin_ia32_tzcnt_u16:
15154 case X86::BI__builtin_ia32_tzcnt_u32:
15155 case X86::BI__builtin_ia32_tzcnt_u64: {
15159 case X86::BI__builtin_ia32_undef128:
15160 case X86::BI__builtin_ia32_undef256:
15161 case X86::BI__builtin_ia32_undef512:
15168 case X86::BI__builtin_ia32_vec_ext_v4hi:
15169 case X86::BI__builtin_ia32_vec_ext_v16qi:
15170 case X86::BI__builtin_ia32_vec_ext_v8hi:
15171 case X86::BI__builtin_ia32_vec_ext_v4si:
15172 case X86::BI__builtin_ia32_vec_ext_v4sf:
15173 case X86::BI__builtin_ia32_vec_ext_v2di:
15174 case X86::BI__builtin_ia32_vec_ext_v32qi:
15175 case X86::BI__builtin_ia32_vec_ext_v16hi:
15176 case X86::BI__builtin_ia32_vec_ext_v8si:
15177 case X86::BI__builtin_ia32_vec_ext_v4di: {
15179 cast<llvm::FixedVectorType>(Ops[0]->getType())->getNumElements();
15180 uint64_t Index = cast<ConstantInt>(Ops[1])->getZExtValue();
15181 Index &= NumElts - 1;
15184 return Builder.CreateExtractElement(Ops[0], Index);
15186 case X86::BI__builtin_ia32_vec_set_v4hi:
15187 case X86::BI__builtin_ia32_vec_set_v16qi:
15188 case X86::BI__builtin_ia32_vec_set_v8hi:
15189 case X86::BI__builtin_ia32_vec_set_v4si:
15190 case X86::BI__builtin_ia32_vec_set_v2di:
15191 case X86::BI__builtin_ia32_vec_set_v32qi:
15192 case X86::BI__builtin_ia32_vec_set_v16hi:
15193 case X86::BI__builtin_ia32_vec_set_v8si:
15194 case X86::BI__builtin_ia32_vec_set_v4di: {
15196 cast<llvm::FixedVectorType>(Ops[0]->getType())->getNumElements();
15197 unsigned Index = cast<ConstantInt>(Ops[2])->getZExtValue();
15198 Index &= NumElts - 1;
15201 return Builder.CreateInsertElement(Ops[0], Ops[1], Index);
15203 case X86::BI_mm_setcsr:
15204 case X86::BI__builtin_ia32_ldmxcsr: {
15210 case X86::BI_mm_getcsr:
15211 case X86::BI__builtin_ia32_stmxcsr: {
15217 case X86::BI__builtin_ia32_xsave:
15218 case X86::BI__builtin_ia32_xsave64:
15219 case X86::BI__builtin_ia32_xrstor:
15220 case X86::BI__builtin_ia32_xrstor64:
15221 case X86::BI__builtin_ia32_xsaveopt:
15222 case X86::BI__builtin_ia32_xsaveopt64:
15223 case X86::BI__builtin_ia32_xrstors:
15224 case X86::BI__builtin_ia32_xrstors64:
15225 case X86::BI__builtin_ia32_xsavec:
15226 case X86::BI__builtin_ia32_xsavec64:
15227 case X86::BI__builtin_ia32_xsaves:
15228 case X86::BI__builtin_ia32_xsaves64:
15229 case X86::BI__builtin_ia32_xsetbv:
15230 case X86::BI_xsetbv: {
15232#define INTRINSIC_X86_XSAVE_ID(NAME) \
15233 case X86::BI__builtin_ia32_##NAME: \
15234 ID = Intrinsic::x86_##NAME; \
15236 switch (BuiltinID) {
15237 default: llvm_unreachable(
"Unsupported intrinsic!");
15251 case X86::BI_xsetbv:
15252 ID = Intrinsic::x86_xsetbv;
15255#undef INTRINSIC_X86_XSAVE_ID
15260 Ops.push_back(Mlo);
15263 case X86::BI__builtin_ia32_xgetbv:
15264 case X86::BI_xgetbv:
15266 case X86::BI__builtin_ia32_storedqudi128_mask:
15267 case X86::BI__builtin_ia32_storedqusi128_mask:
15268 case X86::BI__builtin_ia32_storedquhi128_mask:
15269 case X86::BI__builtin_ia32_storedquqi128_mask:
15270 case X86::BI__builtin_ia32_storeupd128_mask:
15271 case X86::BI__builtin_ia32_storeups128_mask:
15272 case X86::BI__builtin_ia32_storedqudi256_mask:
15273 case X86::BI__builtin_ia32_storedqusi256_mask:
15274 case X86::BI__builtin_ia32_storedquhi256_mask:
15275 case X86::BI__builtin_ia32_storedquqi256_mask:
15276 case X86::BI__builtin_ia32_storeupd256_mask:
15277 case X86::BI__builtin_ia32_storeups256_mask:
15278 case X86::BI__builtin_ia32_storedqudi512_mask:
15279 case X86::BI__builtin_ia32_storedqusi512_mask:
15280 case X86::BI__builtin_ia32_storedquhi512_mask:
15281 case X86::BI__builtin_ia32_storedquqi512_mask:
15282 case X86::BI__builtin_ia32_storeupd512_mask:
15283 case X86::BI__builtin_ia32_storeups512_mask:
15286 case X86::BI__builtin_ia32_storesbf16128_mask:
15287 case X86::BI__builtin_ia32_storesh128_mask:
15288 case X86::BI__builtin_ia32_storess128_mask:
15289 case X86::BI__builtin_ia32_storesd128_mask:
15292 case X86::BI__builtin_ia32_cvtmask2b128:
15293 case X86::BI__builtin_ia32_cvtmask2b256:
15294 case X86::BI__builtin_ia32_cvtmask2b512:
15295 case X86::BI__builtin_ia32_cvtmask2w128:
15296 case X86::BI__builtin_ia32_cvtmask2w256:
15297 case X86::BI__builtin_ia32_cvtmask2w512:
15298 case X86::BI__builtin_ia32_cvtmask2d128:
15299 case X86::BI__builtin_ia32_cvtmask2d256:
15300 case X86::BI__builtin_ia32_cvtmask2d512:
15301 case X86::BI__builtin_ia32_cvtmask2q128:
15302 case X86::BI__builtin_ia32_cvtmask2q256:
15303 case X86::BI__builtin_ia32_cvtmask2q512:
15306 case X86::BI__builtin_ia32_cvtb2mask128:
15307 case X86::BI__builtin_ia32_cvtb2mask256:
15308 case X86::BI__builtin_ia32_cvtb2mask512:
15309 case X86::BI__builtin_ia32_cvtw2mask128:
15310 case X86::BI__builtin_ia32_cvtw2mask256:
15311 case X86::BI__builtin_ia32_cvtw2mask512:
15312 case X86::BI__builtin_ia32_cvtd2mask128:
15313 case X86::BI__builtin_ia32_cvtd2mask256:
15314 case X86::BI__builtin_ia32_cvtd2mask512:
15315 case X86::BI__builtin_ia32_cvtq2mask128:
15316 case X86::BI__builtin_ia32_cvtq2mask256:
15317 case X86::BI__builtin_ia32_cvtq2mask512:
15320 case X86::BI__builtin_ia32_cvtdq2ps512_mask:
15321 case X86::BI__builtin_ia32_cvtqq2ps512_mask:
15322 case X86::BI__builtin_ia32_cvtqq2pd512_mask:
15323 case X86::BI__builtin_ia32_vcvtw2ph512_mask:
15324 case X86::BI__builtin_ia32_vcvtdq2ph512_mask:
15325 case X86::BI__builtin_ia32_vcvtqq2ph512_mask:
15326 case X86::BI__builtin_ia32_vcvtdq2ph256_round_mask:
15327 case X86::BI__builtin_ia32_vcvtdq2ps256_round_mask:
15328 case X86::BI__builtin_ia32_vcvtqq2pd256_round_mask:
15329 case X86::BI__builtin_ia32_vcvtqq2ph256_round_mask:
15330 case X86::BI__builtin_ia32_vcvtqq2ps256_round_mask:
15331 case X86::BI__builtin_ia32_vcvtw2ph256_round_mask:
15333 case X86::BI__builtin_ia32_cvtudq2ps512_mask:
15334 case X86::BI__builtin_ia32_cvtuqq2ps512_mask:
15335 case X86::BI__builtin_ia32_cvtuqq2pd512_mask:
15336 case X86::BI__builtin_ia32_vcvtuw2ph512_mask:
15337 case X86::BI__builtin_ia32_vcvtudq2ph512_mask:
15338 case X86::BI__builtin_ia32_vcvtuqq2ph512_mask:
15339 case X86::BI__builtin_ia32_vcvtudq2ph256_round_mask:
15340 case X86::BI__builtin_ia32_vcvtudq2ps256_round_mask:
15341 case X86::BI__builtin_ia32_vcvtuqq2pd256_round_mask:
15342 case X86::BI__builtin_ia32_vcvtuqq2ph256_round_mask:
15343 case X86::BI__builtin_ia32_vcvtuqq2ps256_round_mask:
15344 case X86::BI__builtin_ia32_vcvtuw2ph256_round_mask:
15347 case X86::BI__builtin_ia32_vfmaddss3:
15348 case X86::BI__builtin_ia32_vfmaddsd3:
15349 case X86::BI__builtin_ia32_vfmaddsh3_mask:
15350 case X86::BI__builtin_ia32_vfmaddss3_mask:
15351 case X86::BI__builtin_ia32_vfmaddsd3_mask:
15353 case X86::BI__builtin_ia32_vfmaddss:
15354 case X86::BI__builtin_ia32_vfmaddsd:
15356 Constant::getNullValue(Ops[0]->getType()));
15357 case X86::BI__builtin_ia32_vfmaddsh3_maskz:
15358 case X86::BI__builtin_ia32_vfmaddss3_maskz:
15359 case X86::BI__builtin_ia32_vfmaddsd3_maskz:
15361 case X86::BI__builtin_ia32_vfmaddsh3_mask3:
15362 case X86::BI__builtin_ia32_vfmaddss3_mask3:
15363 case X86::BI__builtin_ia32_vfmaddsd3_mask3:
15365 case X86::BI__builtin_ia32_vfmsubsh3_mask3:
15366 case X86::BI__builtin_ia32_vfmsubss3_mask3:
15367 case X86::BI__builtin_ia32_vfmsubsd3_mask3:
15370 case X86::BI__builtin_ia32_vfmaddph:
15371 case X86::BI__builtin_ia32_vfmaddps:
15372 case X86::BI__builtin_ia32_vfmaddpd:
15373 case X86::BI__builtin_ia32_vfmaddph256:
15374 case X86::BI__builtin_ia32_vfmaddps256:
15375 case X86::BI__builtin_ia32_vfmaddpd256:
15376 case X86::BI__builtin_ia32_vfmaddph512_mask:
15377 case X86::BI__builtin_ia32_vfmaddph512_maskz:
15378 case X86::BI__builtin_ia32_vfmaddph512_mask3:
15379 case X86::BI__builtin_ia32_vfmaddnepbh128:
15380 case X86::BI__builtin_ia32_vfmaddnepbh256:
15381 case X86::BI__builtin_ia32_vfmaddnepbh512:
15382 case X86::BI__builtin_ia32_vfmaddps512_mask:
15383 case X86::BI__builtin_ia32_vfmaddps512_maskz:
15384 case X86::BI__builtin_ia32_vfmaddps512_mask3:
15385 case X86::BI__builtin_ia32_vfmsubps512_mask3:
15386 case X86::BI__builtin_ia32_vfmaddpd512_mask:
15387 case X86::BI__builtin_ia32_vfmaddpd512_maskz:
15388 case X86::BI__builtin_ia32_vfmaddpd512_mask3:
15389 case X86::BI__builtin_ia32_vfmsubpd512_mask3:
15390 case X86::BI__builtin_ia32_vfmsubph512_mask3:
15391 case X86::BI__builtin_ia32_vfmaddph256_round_mask:
15392 case X86::BI__builtin_ia32_vfmaddph256_round_maskz:
15393 case X86::BI__builtin_ia32_vfmaddph256_round_mask3:
15394 case X86::BI__builtin_ia32_vfmaddps256_round_mask:
15395 case X86::BI__builtin_ia32_vfmaddps256_round_maskz:
15396 case X86::BI__builtin_ia32_vfmaddps256_round_mask3:
15397 case X86::BI__builtin_ia32_vfmsubps256_round_mask3:
15398 case X86::BI__builtin_ia32_vfmaddpd256_round_mask:
15399 case X86::BI__builtin_ia32_vfmaddpd256_round_maskz:
15400 case X86::BI__builtin_ia32_vfmaddpd256_round_mask3:
15401 case X86::BI__builtin_ia32_vfmsubpd256_round_mask3:
15402 case X86::BI__builtin_ia32_vfmsubph256_round_mask3:
15404 case X86::BI__builtin_ia32_vfmaddsubph512_mask:
15405 case X86::BI__builtin_ia32_vfmaddsubph512_maskz:
15406 case X86::BI__builtin_ia32_vfmaddsubph512_mask3:
15407 case X86::BI__builtin_ia32_vfmsubaddph512_mask3:
15408 case X86::BI__builtin_ia32_vfmaddsubps512_mask:
15409 case X86::BI__builtin_ia32_vfmaddsubps512_maskz:
15410 case X86::BI__builtin_ia32_vfmaddsubps512_mask3:
15411 case X86::BI__builtin_ia32_vfmsubaddps512_mask3:
15412 case X86::BI__builtin_ia32_vfmaddsubpd512_mask:
15413 case X86::BI__builtin_ia32_vfmaddsubpd512_maskz:
15414 case X86::BI__builtin_ia32_vfmaddsubpd512_mask3:
15415 case X86::BI__builtin_ia32_vfmsubaddpd512_mask3:
15416 case X86::BI__builtin_ia32_vfmaddsubph256_round_mask:
15417 case X86::BI__builtin_ia32_vfmaddsubph256_round_maskz:
15418 case X86::BI__builtin_ia32_vfmaddsubph256_round_mask3:
15419 case X86::BI__builtin_ia32_vfmsubaddph256_round_mask3:
15420 case X86::BI__builtin_ia32_vfmaddsubps256_round_mask:
15421 case X86::BI__builtin_ia32_vfmaddsubps256_round_maskz:
15422 case X86::BI__builtin_ia32_vfmaddsubps256_round_mask3:
15423 case X86::BI__builtin_ia32_vfmsubaddps256_round_mask3:
15424 case X86::BI__builtin_ia32_vfmaddsubpd256_round_mask:
15425 case X86::BI__builtin_ia32_vfmaddsubpd256_round_maskz:
15426 case X86::BI__builtin_ia32_vfmaddsubpd256_round_mask3:
15427 case X86::BI__builtin_ia32_vfmsubaddpd256_round_mask3:
15430 case X86::BI__builtin_ia32_movdqa32store128_mask:
15431 case X86::BI__builtin_ia32_movdqa64store128_mask:
15432 case X86::BI__builtin_ia32_storeaps128_mask:
15433 case X86::BI__builtin_ia32_storeapd128_mask:
15434 case X86::BI__builtin_ia32_movdqa32store256_mask:
15435 case X86::BI__builtin_ia32_movdqa64store256_mask:
15436 case X86::BI__builtin_ia32_storeaps256_mask:
15437 case X86::BI__builtin_ia32_storeapd256_mask:
15438 case X86::BI__builtin_ia32_movdqa32store512_mask:
15439 case X86::BI__builtin_ia32_movdqa64store512_mask:
15440 case X86::BI__builtin_ia32_storeaps512_mask:
15441 case X86::BI__builtin_ia32_storeapd512_mask:
15446 case X86::BI__builtin_ia32_loadups128_mask:
15447 case X86::BI__builtin_ia32_loadups256_mask:
15448 case X86::BI__builtin_ia32_loadups512_mask:
15449 case X86::BI__builtin_ia32_loadupd128_mask:
15450 case X86::BI__builtin_ia32_loadupd256_mask:
15451 case X86::BI__builtin_ia32_loadupd512_mask:
15452 case X86::BI__builtin_ia32_loaddquqi128_mask:
15453 case X86::BI__builtin_ia32_loaddquqi256_mask:
15454 case X86::BI__builtin_ia32_loaddquqi512_mask:
15455 case X86::BI__builtin_ia32_loaddquhi128_mask:
15456 case X86::BI__builtin_ia32_loaddquhi256_mask:
15457 case X86::BI__builtin_ia32_loaddquhi512_mask:
15458 case X86::BI__builtin_ia32_loaddqusi128_mask:
15459 case X86::BI__builtin_ia32_loaddqusi256_mask:
15460 case X86::BI__builtin_ia32_loaddqusi512_mask:
15461 case X86::BI__builtin_ia32_loaddqudi128_mask:
15462 case X86::BI__builtin_ia32_loaddqudi256_mask:
15463 case X86::BI__builtin_ia32_loaddqudi512_mask:
15466 case X86::BI__builtin_ia32_loadsbf16128_mask:
15467 case X86::BI__builtin_ia32_loadsh128_mask:
15468 case X86::BI__builtin_ia32_loadss128_mask:
15469 case X86::BI__builtin_ia32_loadsd128_mask:
15472 case X86::BI__builtin_ia32_loadaps128_mask:
15473 case X86::BI__builtin_ia32_loadaps256_mask:
15474 case X86::BI__builtin_ia32_loadaps512_mask:
15475 case X86::BI__builtin_ia32_loadapd128_mask:
15476 case X86::BI__builtin_ia32_loadapd256_mask:
15477 case X86::BI__builtin_ia32_loadapd512_mask:
15478 case X86::BI__builtin_ia32_movdqa32load128_mask:
15479 case X86::BI__builtin_ia32_movdqa32load256_mask:
15480 case X86::BI__builtin_ia32_movdqa32load512_mask:
15481 case X86::BI__builtin_ia32_movdqa64load128_mask:
15482 case X86::BI__builtin_ia32_movdqa64load256_mask:
15483 case X86::BI__builtin_ia32_movdqa64load512_mask:
15488 case X86::BI__builtin_ia32_expandloaddf128_mask:
15489 case X86::BI__builtin_ia32_expandloaddf256_mask:
15490 case X86::BI__builtin_ia32_expandloaddf512_mask:
15491 case X86::BI__builtin_ia32_expandloadsf128_mask:
15492 case X86::BI__builtin_ia32_expandloadsf256_mask:
15493 case X86::BI__builtin_ia32_expandloadsf512_mask:
15494 case X86::BI__builtin_ia32_expandloaddi128_mask:
15495 case X86::BI__builtin_ia32_expandloaddi256_mask:
15496 case X86::BI__builtin_ia32_expandloaddi512_mask:
15497 case X86::BI__builtin_ia32_expandloadsi128_mask:
15498 case X86::BI__builtin_ia32_expandloadsi256_mask:
15499 case X86::BI__builtin_ia32_expandloadsi512_mask:
15500 case X86::BI__builtin_ia32_expandloadhi128_mask:
15501 case X86::BI__builtin_ia32_expandloadhi256_mask:
15502 case X86::BI__builtin_ia32_expandloadhi512_mask:
15503 case X86::BI__builtin_ia32_expandloadqi128_mask:
15504 case X86::BI__builtin_ia32_expandloadqi256_mask:
15505 case X86::BI__builtin_ia32_expandloadqi512_mask:
15508 case X86::BI__builtin_ia32_compressstoredf128_mask:
15509 case X86::BI__builtin_ia32_compressstoredf256_mask:
15510 case X86::BI__builtin_ia32_compressstoredf512_mask:
15511 case X86::BI__builtin_ia32_compressstoresf128_mask:
15512 case X86::BI__builtin_ia32_compressstoresf256_mask:
15513 case X86::BI__builtin_ia32_compressstoresf512_mask:
15514 case X86::BI__builtin_ia32_compressstoredi128_mask:
15515 case X86::BI__builtin_ia32_compressstoredi256_mask:
15516 case X86::BI__builtin_ia32_compressstoredi512_mask:
15517 case X86::BI__builtin_ia32_compressstoresi128_mask:
15518 case X86::BI__builtin_ia32_compressstoresi256_mask:
15519 case X86::BI__builtin_ia32_compressstoresi512_mask:
15520 case X86::BI__builtin_ia32_compressstorehi128_mask:
15521 case X86::BI__builtin_ia32_compressstorehi256_mask:
15522 case X86::BI__builtin_ia32_compressstorehi512_mask:
15523 case X86::BI__builtin_ia32_compressstoreqi128_mask:
15524 case X86::BI__builtin_ia32_compressstoreqi256_mask:
15525 case X86::BI__builtin_ia32_compressstoreqi512_mask:
15528 case X86::BI__builtin_ia32_expanddf128_mask:
15529 case X86::BI__builtin_ia32_expanddf256_mask:
15530 case X86::BI__builtin_ia32_expanddf512_mask:
15531 case X86::BI__builtin_ia32_expandsf128_mask:
15532 case X86::BI__builtin_ia32_expandsf256_mask:
15533 case X86::BI__builtin_ia32_expandsf512_mask:
15534 case X86::BI__builtin_ia32_expanddi128_mask:
15535 case X86::BI__builtin_ia32_expanddi256_mask:
15536 case X86::BI__builtin_ia32_expanddi512_mask:
15537 case X86::BI__builtin_ia32_expandsi128_mask:
15538 case X86::BI__builtin_ia32_expandsi256_mask:
15539 case X86::BI__builtin_ia32_expandsi512_mask:
15540 case X86::BI__builtin_ia32_expandhi128_mask:
15541 case X86::BI__builtin_ia32_expandhi256_mask:
15542 case X86::BI__builtin_ia32_expandhi512_mask:
15543 case X86::BI__builtin_ia32_expandqi128_mask:
15544 case X86::BI__builtin_ia32_expandqi256_mask:
15545 case X86::BI__builtin_ia32_expandqi512_mask:
15548 case X86::BI__builtin_ia32_compressdf128_mask:
15549 case X86::BI__builtin_ia32_compressdf256_mask:
15550 case X86::BI__builtin_ia32_compressdf512_mask:
15551 case X86::BI__builtin_ia32_compresssf128_mask:
15552 case X86::BI__builtin_ia32_compresssf256_mask:
15553 case X86::BI__builtin_ia32_compresssf512_mask:
15554 case X86::BI__builtin_ia32_compressdi128_mask:
15555 case X86::BI__builtin_ia32_compressdi256_mask:
15556 case X86::BI__builtin_ia32_compressdi512_mask:
15557 case X86::BI__builtin_ia32_compresssi128_mask:
15558 case X86::BI__builtin_ia32_compresssi256_mask:
15559 case X86::BI__builtin_ia32_compresssi512_mask:
15560 case X86::BI__builtin_ia32_compresshi128_mask:
15561 case X86::BI__builtin_ia32_compresshi256_mask:
15562 case X86::BI__builtin_ia32_compresshi512_mask:
15563 case X86::BI__builtin_ia32_compressqi128_mask:
15564 case X86::BI__builtin_ia32_compressqi256_mask:
15565 case X86::BI__builtin_ia32_compressqi512_mask:
15568 case X86::BI__builtin_ia32_gather3div2df:
15569 case X86::BI__builtin_ia32_gather3div2di:
15570 case X86::BI__builtin_ia32_gather3div4df:
15571 case X86::BI__builtin_ia32_gather3div4di:
15572 case X86::BI__builtin_ia32_gather3div4sf:
15573 case X86::BI__builtin_ia32_gather3div4si:
15574 case X86::BI__builtin_ia32_gather3div8sf:
15575 case X86::BI__builtin_ia32_gather3div8si:
15576 case X86::BI__builtin_ia32_gather3siv2df:
15577 case X86::BI__builtin_ia32_gather3siv2di:
15578 case X86::BI__builtin_ia32_gather3siv4df:
15579 case X86::BI__builtin_ia32_gather3siv4di:
15580 case X86::BI__builtin_ia32_gather3siv4sf:
15581 case X86::BI__builtin_ia32_gather3siv4si:
15582 case X86::BI__builtin_ia32_gather3siv8sf:
15583 case X86::BI__builtin_ia32_gather3siv8si:
15584 case X86::BI__builtin_ia32_gathersiv8df:
15585 case X86::BI__builtin_ia32_gathersiv16sf:
15586 case X86::BI__builtin_ia32_gatherdiv8df:
15587 case X86::BI__builtin_ia32_gatherdiv16sf:
15588 case X86::BI__builtin_ia32_gathersiv8di:
15589 case X86::BI__builtin_ia32_gathersiv16si:
15590 case X86::BI__builtin_ia32_gatherdiv8di:
15591 case X86::BI__builtin_ia32_gatherdiv16si: {
15593 switch (BuiltinID) {
15594 default: llvm_unreachable(
"Unexpected builtin");
15595 case X86::BI__builtin_ia32_gather3div2df:
15596 IID = Intrinsic::x86_avx512_mask_gather3div2_df;
15598 case X86::BI__builtin_ia32_gather3div2di:
15599 IID = Intrinsic::x86_avx512_mask_gather3div2_di;
15601 case X86::BI__builtin_ia32_gather3div4df:
15602 IID = Intrinsic::x86_avx512_mask_gather3div4_df;
15604 case X86::BI__builtin_ia32_gather3div4di:
15605 IID = Intrinsic::x86_avx512_mask_gather3div4_di;
15607 case X86::BI__builtin_ia32_gather3div4sf:
15608 IID = Intrinsic::x86_avx512_mask_gather3div4_sf;
15610 case X86::BI__builtin_ia32_gather3div4si:
15611 IID = Intrinsic::x86_avx512_mask_gather3div4_si;
15613 case X86::BI__builtin_ia32_gather3div8sf:
15614 IID = Intrinsic::x86_avx512_mask_gather3div8_sf;
15616 case X86::BI__builtin_ia32_gather3div8si:
15617 IID = Intrinsic::x86_avx512_mask_gather3div8_si;
15619 case X86::BI__builtin_ia32_gather3siv2df:
15620 IID = Intrinsic::x86_avx512_mask_gather3siv2_df;
15622 case X86::BI__builtin_ia32_gather3siv2di:
15623 IID = Intrinsic::x86_avx512_mask_gather3siv2_di;
15625 case X86::BI__builtin_ia32_gather3siv4df:
15626 IID = Intrinsic::x86_avx512_mask_gather3siv4_df;
15628 case X86::BI__builtin_ia32_gather3siv4di:
15629 IID = Intrinsic::x86_avx512_mask_gather3siv4_di;
15631 case X86::BI__builtin_ia32_gather3siv4sf:
15632 IID = Intrinsic::x86_avx512_mask_gather3siv4_sf;
15634 case X86::BI__builtin_ia32_gather3siv4si:
15635 IID = Intrinsic::x86_avx512_mask_gather3siv4_si;
15637 case X86::BI__builtin_ia32_gather3siv8sf:
15638 IID = Intrinsic::x86_avx512_mask_gather3siv8_sf;
15640 case X86::BI__builtin_ia32_gather3siv8si:
15641 IID = Intrinsic::x86_avx512_mask_gather3siv8_si;
15643 case X86::BI__builtin_ia32_gathersiv8df:
15644 IID = Intrinsic::x86_avx512_mask_gather_dpd_512;
15646 case X86::BI__builtin_ia32_gathersiv16sf:
15647 IID = Intrinsic::x86_avx512_mask_gather_dps_512;
15649 case X86::BI__builtin_ia32_gatherdiv8df:
15650 IID = Intrinsic::x86_avx512_mask_gather_qpd_512;
15652 case X86::BI__builtin_ia32_gatherdiv16sf:
15653 IID = Intrinsic::x86_avx512_mask_gather_qps_512;
15655 case X86::BI__builtin_ia32_gathersiv8di:
15656 IID = Intrinsic::x86_avx512_mask_gather_dpq_512;
15658 case X86::BI__builtin_ia32_gathersiv16si:
15659 IID = Intrinsic::x86_avx512_mask_gather_dpi_512;
15661 case X86::BI__builtin_ia32_gatherdiv8di:
15662 IID = Intrinsic::x86_avx512_mask_gather_qpq_512;
15664 case X86::BI__builtin_ia32_gatherdiv16si:
15665 IID = Intrinsic::x86_avx512_mask_gather_qpi_512;
15669 unsigned MinElts = std::min(
15670 cast<llvm::FixedVectorType>(Ops[0]->getType())->getNumElements(),
15671 cast<llvm::FixedVectorType>(Ops[2]->getType())->getNumElements());
15674 return Builder.CreateCall(Intr, Ops);
15677 case X86::BI__builtin_ia32_scattersiv8df:
15678 case X86::BI__builtin_ia32_scattersiv16sf:
15679 case X86::BI__builtin_ia32_scatterdiv8df:
15680 case X86::BI__builtin_ia32_scatterdiv16sf:
15681 case X86::BI__builtin_ia32_scattersiv8di:
15682 case X86::BI__builtin_ia32_scattersiv16si:
15683 case X86::BI__builtin_ia32_scatterdiv8di:
15684 case X86::BI__builtin_ia32_scatterdiv16si:
15685 case X86::BI__builtin_ia32_scatterdiv2df:
15686 case X86::BI__builtin_ia32_scatterdiv2di:
15687 case X86::BI__builtin_ia32_scatterdiv4df:
15688 case X86::BI__builtin_ia32_scatterdiv4di:
15689 case X86::BI__builtin_ia32_scatterdiv4sf:
15690 case X86::BI__builtin_ia32_scatterdiv4si:
15691 case X86::BI__builtin_ia32_scatterdiv8sf:
15692 case X86::BI__builtin_ia32_scatterdiv8si:
15693 case X86::BI__builtin_ia32_scattersiv2df:
15694 case X86::BI__builtin_ia32_scattersiv2di:
15695 case X86::BI__builtin_ia32_scattersiv4df:
15696 case X86::BI__builtin_ia32_scattersiv4di:
15697 case X86::BI__builtin_ia32_scattersiv4sf:
15698 case X86::BI__builtin_ia32_scattersiv4si:
15699 case X86::BI__builtin_ia32_scattersiv8sf:
15700 case X86::BI__builtin_ia32_scattersiv8si: {
15702 switch (BuiltinID) {
15703 default: llvm_unreachable(
"Unexpected builtin");
15704 case X86::BI__builtin_ia32_scattersiv8df:
15705 IID = Intrinsic::x86_avx512_mask_scatter_dpd_512;
15707 case X86::BI__builtin_ia32_scattersiv16sf:
15708 IID = Intrinsic::x86_avx512_mask_scatter_dps_512;
15710 case X86::BI__builtin_ia32_scatterdiv8df:
15711 IID = Intrinsic::x86_avx512_mask_scatter_qpd_512;
15713 case X86::BI__builtin_ia32_scatterdiv16sf:
15714 IID = Intrinsic::x86_avx512_mask_scatter_qps_512;
15716 case X86::BI__builtin_ia32_scattersiv8di:
15717 IID = Intrinsic::x86_avx512_mask_scatter_dpq_512;
15719 case X86::BI__builtin_ia32_scattersiv16si:
15720 IID = Intrinsic::x86_avx512_mask_scatter_dpi_512;
15722 case X86::BI__builtin_ia32_scatterdiv8di:
15723 IID = Intrinsic::x86_avx512_mask_scatter_qpq_512;
15725 case X86::BI__builtin_ia32_scatterdiv16si:
15726 IID = Intrinsic::x86_avx512_mask_scatter_qpi_512;
15728 case X86::BI__builtin_ia32_scatterdiv2df:
15729 IID = Intrinsic::x86_avx512_mask_scatterdiv2_df;
15731 case X86::BI__builtin_ia32_scatterdiv2di:
15732 IID = Intrinsic::x86_avx512_mask_scatterdiv2_di;
15734 case X86::BI__builtin_ia32_scatterdiv4df:
15735 IID = Intrinsic::x86_avx512_mask_scatterdiv4_df;
15737 case X86::BI__builtin_ia32_scatterdiv4di:
15738 IID = Intrinsic::x86_avx512_mask_scatterdiv4_di;
15740 case X86::BI__builtin_ia32_scatterdiv4sf:
15741 IID = Intrinsic::x86_avx512_mask_scatterdiv4_sf;
15743 case X86::BI__builtin_ia32_scatterdiv4si:
15744 IID = Intrinsic::x86_avx512_mask_scatterdiv4_si;
15746 case X86::BI__builtin_ia32_scatterdiv8sf:
15747 IID = Intrinsic::x86_avx512_mask_scatterdiv8_sf;
15749 case X86::BI__builtin_ia32_scatterdiv8si:
15750 IID = Intrinsic::x86_avx512_mask_scatterdiv8_si;
15752 case X86::BI__builtin_ia32_scattersiv2df:
15753 IID = Intrinsic::x86_avx512_mask_scattersiv2_df;
15755 case X86::BI__builtin_ia32_scattersiv2di:
15756 IID = Intrinsic::x86_avx512_mask_scattersiv2_di;
15758 case X86::BI__builtin_ia32_scattersiv4df:
15759 IID = Intrinsic::x86_avx512_mask_scattersiv4_df;
15761 case X86::BI__builtin_ia32_scattersiv4di:
15762 IID = Intrinsic::x86_avx512_mask_scattersiv4_di;
15764 case X86::BI__builtin_ia32_scattersiv4sf:
15765 IID = Intrinsic::x86_avx512_mask_scattersiv4_sf;
15767 case X86::BI__builtin_ia32_scattersiv4si:
15768 IID = Intrinsic::x86_avx512_mask_scattersiv4_si;
15770 case X86::BI__builtin_ia32_scattersiv8sf:
15771 IID = Intrinsic::x86_avx512_mask_scattersiv8_sf;
15773 case X86::BI__builtin_ia32_scattersiv8si:
15774 IID = Intrinsic::x86_avx512_mask_scattersiv8_si;
15778 unsigned MinElts = std::min(
15779 cast<llvm::FixedVectorType>(Ops[2]->getType())->getNumElements(),
15780 cast<llvm::FixedVectorType>(Ops[3]->getType())->getNumElements());
15783 return Builder.CreateCall(Intr, Ops);
15786 case X86::BI__builtin_ia32_vextractf128_pd256:
15787 case X86::BI__builtin_ia32_vextractf128_ps256:
15788 case X86::BI__builtin_ia32_vextractf128_si256:
15789 case X86::BI__builtin_ia32_extract128i256:
15790 case X86::BI__builtin_ia32_extractf64x4_mask:
15791 case X86::BI__builtin_ia32_extractf32x4_mask:
15792 case X86::BI__builtin_ia32_extracti64x4_mask:
15793 case X86::BI__builtin_ia32_extracti32x4_mask:
15794 case X86::BI__builtin_ia32_extractf32x8_mask:
15795 case X86::BI__builtin_ia32_extracti32x8_mask:
15796 case X86::BI__builtin_ia32_extractf32x4_256_mask:
15797 case X86::BI__builtin_ia32_extracti32x4_256_mask:
15798 case X86::BI__builtin_ia32_extractf64x2_256_mask:
15799 case X86::BI__builtin_ia32_extracti64x2_256_mask:
15800 case X86::BI__builtin_ia32_extractf64x2_512_mask:
15801 case X86::BI__builtin_ia32_extracti64x2_512_mask: {
15803 unsigned NumElts = DstTy->getNumElements();
15804 unsigned SrcNumElts =
15805 cast<llvm::FixedVectorType>(Ops[0]->getType())->getNumElements();
15806 unsigned SubVectors = SrcNumElts / NumElts;
15807 unsigned Index = cast<ConstantInt>(Ops[1])->getZExtValue();
15808 assert(llvm::isPowerOf2_32(SubVectors) &&
"Expected power of 2 subvectors");
15809 Index &= SubVectors - 1;
15813 for (
unsigned i = 0; i != NumElts; ++i)
15814 Indices[i] = i + Index;
15819 if (Ops.size() == 4)
15824 case X86::BI__builtin_ia32_vinsertf128_pd256:
15825 case X86::BI__builtin_ia32_vinsertf128_ps256:
15826 case X86::BI__builtin_ia32_vinsertf128_si256:
15827 case X86::BI__builtin_ia32_insert128i256:
15828 case X86::BI__builtin_ia32_insertf64x4:
15829 case X86::BI__builtin_ia32_insertf32x4:
15830 case X86::BI__builtin_ia32_inserti64x4:
15831 case X86::BI__builtin_ia32_inserti32x4:
15832 case X86::BI__builtin_ia32_insertf32x8:
15833 case X86::BI__builtin_ia32_inserti32x8:
15834 case X86::BI__builtin_ia32_insertf32x4_256:
15835 case X86::BI__builtin_ia32_inserti32x4_256:
15836 case X86::BI__builtin_ia32_insertf64x2_256:
15837 case X86::BI__builtin_ia32_inserti64x2_256:
15838 case X86::BI__builtin_ia32_insertf64x2_512:
15839 case X86::BI__builtin_ia32_inserti64x2_512: {
15840 unsigned DstNumElts =
15841 cast<llvm::FixedVectorType>(Ops[0]->getType())->getNumElements();
15842 unsigned SrcNumElts =
15843 cast<llvm::FixedVectorType>(Ops[1]->getType())->getNumElements();
15844 unsigned SubVectors = DstNumElts / SrcNumElts;
15845 unsigned Index = cast<ConstantInt>(Ops[2])->getZExtValue();
15846 assert(llvm::isPowerOf2_32(SubVectors) &&
"Expected power of 2 subvectors");
15847 Index &= SubVectors - 1;
15848 Index *= SrcNumElts;
15851 for (
unsigned i = 0; i != DstNumElts; ++i)
15852 Indices[i] = (i >= SrcNumElts) ? SrcNumElts + (i % SrcNumElts) : i;
15855 Ops[1],
ArrayRef(Indices, DstNumElts),
"widen");
15857 for (
unsigned i = 0; i != DstNumElts; ++i) {
15858 if (i >= Index && i < (Index + SrcNumElts))
15859 Indices[i] = (i - Index) + DstNumElts;
15864 return Builder.CreateShuffleVector(Ops[0], Op1,
15865 ArrayRef(Indices, DstNumElts),
"insert");
15867 case X86::BI__builtin_ia32_pmovqd512_mask:
15868 case X86::BI__builtin_ia32_pmovwb512_mask: {
15869 Value *Res =
Builder.CreateTrunc(Ops[0], Ops[1]->getType());
15872 case X86::BI__builtin_ia32_pmovdb512_mask:
15873 case X86::BI__builtin_ia32_pmovdw512_mask:
15874 case X86::BI__builtin_ia32_pmovqw512_mask: {
15875 if (
const auto *
C = dyn_cast<Constant>(Ops[2]))
15876 if (
C->isAllOnesValue())
15877 return Builder.CreateTrunc(Ops[0], Ops[1]->getType());
15880 switch (BuiltinID) {
15881 default: llvm_unreachable(
"Unsupported intrinsic!");
15882 case X86::BI__builtin_ia32_pmovdb512_mask:
15883 IID = Intrinsic::x86_avx512_mask_pmov_db_512;
15885 case X86::BI__builtin_ia32_pmovdw512_mask:
15886 IID = Intrinsic::x86_avx512_mask_pmov_dw_512;
15888 case X86::BI__builtin_ia32_pmovqw512_mask:
15889 IID = Intrinsic::x86_avx512_mask_pmov_qw_512;
15894 return Builder.CreateCall(Intr, Ops);
15896 case X86::BI__builtin_ia32_pblendw128:
15897 case X86::BI__builtin_ia32_blendpd:
15898 case X86::BI__builtin_ia32_blendps:
15899 case X86::BI__builtin_ia32_blendpd256:
15900 case X86::BI__builtin_ia32_blendps256:
15901 case X86::BI__builtin_ia32_pblendw256:
15902 case X86::BI__builtin_ia32_pblendd128:
15903 case X86::BI__builtin_ia32_pblendd256: {
15905 cast<llvm::FixedVectorType>(Ops[0]->getType())->getNumElements();
15906 unsigned Imm = cast<llvm::ConstantInt>(Ops[2])->getZExtValue();
15911 for (
unsigned i = 0; i != NumElts; ++i)
15912 Indices[i] = ((Imm >> (i % 8)) & 0x1) ? NumElts + i : i;
15914 return Builder.CreateShuffleVector(Ops[0], Ops[1],
15915 ArrayRef(Indices, NumElts),
"blend");
15917 case X86::BI__builtin_ia32_pshuflw:
15918 case X86::BI__builtin_ia32_pshuflw256:
15919 case X86::BI__builtin_ia32_pshuflw512: {
15920 uint32_t Imm = cast<llvm::ConstantInt>(Ops[1])->getZExtValue();
15921 auto *Ty = cast<llvm::FixedVectorType>(Ops[0]->getType());
15922 unsigned NumElts = Ty->getNumElements();
15925 Imm = (Imm & 0xff) * 0x01010101;
15928 for (
unsigned l = 0; l != NumElts; l += 8) {
15929 for (
unsigned i = 0; i != 4; ++i) {
15930 Indices[l + i] = l + (Imm & 3);
15933 for (
unsigned i = 4; i != 8; ++i)
15934 Indices[l + i] = l + i;
15937 return Builder.CreateShuffleVector(Ops[0],
ArrayRef(Indices, NumElts),
15940 case X86::BI__builtin_ia32_pshufhw:
15941 case X86::BI__builtin_ia32_pshufhw256:
15942 case X86::BI__builtin_ia32_pshufhw512: {
15943 uint32_t Imm = cast<llvm::ConstantInt>(Ops[1])->getZExtValue();
15944 auto *Ty = cast<llvm::FixedVectorType>(Ops[0]->getType());
15945 unsigned NumElts = Ty->getNumElements();
15948 Imm = (Imm & 0xff) * 0x01010101;
15951 for (
unsigned l = 0; l != NumElts; l += 8) {
15952 for (
unsigned i = 0; i != 4; ++i)
15953 Indices[l + i] = l + i;
15954 for (
unsigned i = 4; i != 8; ++i) {
15955 Indices[l + i] = l + 4 + (Imm & 3);
15960 return Builder.CreateShuffleVector(Ops[0],
ArrayRef(Indices, NumElts),
15963 case X86::BI__builtin_ia32_pshufd:
15964 case X86::BI__builtin_ia32_pshufd256:
15965 case X86::BI__builtin_ia32_pshufd512:
15966 case X86::BI__builtin_ia32_vpermilpd:
15967 case X86::BI__builtin_ia32_vpermilps:
15968 case X86::BI__builtin_ia32_vpermilpd256:
15969 case X86::BI__builtin_ia32_vpermilps256:
15970 case X86::BI__builtin_ia32_vpermilpd512:
15971 case X86::BI__builtin_ia32_vpermilps512: {
15972 uint32_t Imm = cast<llvm::ConstantInt>(Ops[1])->getZExtValue();
15973 auto *Ty = cast<llvm::FixedVectorType>(Ops[0]->getType());
15974 unsigned NumElts = Ty->getNumElements();
15975 unsigned NumLanes = Ty->getPrimitiveSizeInBits() / 128;
15976 unsigned NumLaneElts = NumElts / NumLanes;
15979 Imm = (Imm & 0xff) * 0x01010101;
15982 for (
unsigned l = 0; l != NumElts; l += NumLaneElts) {
15983 for (
unsigned i = 0; i != NumLaneElts; ++i) {
15984 Indices[i + l] = (Imm % NumLaneElts) + l;
15985 Imm /= NumLaneElts;
15989 return Builder.CreateShuffleVector(Ops[0],
ArrayRef(Indices, NumElts),
15992 case X86::BI__builtin_ia32_shufpd:
15993 case X86::BI__builtin_ia32_shufpd256:
15994 case X86::BI__builtin_ia32_shufpd512:
15995 case X86::BI__builtin_ia32_shufps:
15996 case X86::BI__builtin_ia32_shufps256:
15997 case X86::BI__builtin_ia32_shufps512: {
15998 uint32_t Imm = cast<llvm::ConstantInt>(Ops[2])->getZExtValue();
15999 auto *Ty = cast<llvm::FixedVectorType>(Ops[0]->getType());
16000 unsigned NumElts = Ty->getNumElements();
16001 unsigned NumLanes = Ty->getPrimitiveSizeInBits() / 128;
16002 unsigned NumLaneElts = NumElts / NumLanes;
16005 Imm = (Imm & 0xff) * 0x01010101;
16008 for (
unsigned l = 0; l != NumElts; l += NumLaneElts) {
16009 for (
unsigned i = 0; i != NumLaneElts; ++i) {
16010 unsigned Index = Imm % NumLaneElts;
16011 Imm /= NumLaneElts;
16012 if (i >= (NumLaneElts / 2))
16014 Indices[l + i] = l + Index;
16018 return Builder.CreateShuffleVector(Ops[0], Ops[1],
16019 ArrayRef(Indices, NumElts),
"shufp");
16021 case X86::BI__builtin_ia32_permdi256:
16022 case X86::BI__builtin_ia32_permdf256:
16023 case X86::BI__builtin_ia32_permdi512:
16024 case X86::BI__builtin_ia32_permdf512: {
16025 unsigned Imm = cast<llvm::ConstantInt>(Ops[1])->getZExtValue();
16026 auto *Ty = cast<llvm::FixedVectorType>(Ops[0]->getType());
16027 unsigned NumElts = Ty->getNumElements();
16031 for (
unsigned l = 0; l != NumElts; l += 4)
16032 for (
unsigned i = 0; i != 4; ++i)
16033 Indices[l + i] = l + ((Imm >> (2 * i)) & 0x3);
16035 return Builder.CreateShuffleVector(Ops[0],
ArrayRef(Indices, NumElts),
16038 case X86::BI__builtin_ia32_palignr128:
16039 case X86::BI__builtin_ia32_palignr256:
16040 case X86::BI__builtin_ia32_palignr512: {
16041 unsigned ShiftVal = cast<llvm::ConstantInt>(Ops[2])->getZExtValue() & 0xff;
16044 cast<llvm::FixedVectorType>(Ops[0]->getType())->getNumElements();
16045 assert(NumElts % 16 == 0);
16049 if (ShiftVal >= 32)
16054 if (ShiftVal > 16) {
16057 Ops[0] = llvm::Constant::getNullValue(Ops[0]->getType());
16062 for (
unsigned l = 0; l != NumElts; l += 16) {
16063 for (
unsigned i = 0; i != 16; ++i) {
16064 unsigned Idx = ShiftVal + i;
16066 Idx += NumElts - 16;
16067 Indices[l + i] = Idx + l;
16071 return Builder.CreateShuffleVector(Ops[1], Ops[0],
16072 ArrayRef(Indices, NumElts),
"palignr");
16074 case X86::BI__builtin_ia32_alignd128:
16075 case X86::BI__builtin_ia32_alignd256:
16076 case X86::BI__builtin_ia32_alignd512:
16077 case X86::BI__builtin_ia32_alignq128:
16078 case X86::BI__builtin_ia32_alignq256:
16079 case X86::BI__builtin_ia32_alignq512: {
16081 cast<llvm::FixedVectorType>(Ops[0]->getType())->getNumElements();
16082 unsigned ShiftVal = cast<llvm::ConstantInt>(Ops[2])->getZExtValue() & 0xff;
16085 ShiftVal &= NumElts - 1;
16088 for (
unsigned i = 0; i != NumElts; ++i)
16089 Indices[i] = i + ShiftVal;
16091 return Builder.CreateShuffleVector(Ops[1], Ops[0],
16092 ArrayRef(Indices, NumElts),
"valign");
16094 case X86::BI__builtin_ia32_shuf_f32x4_256:
16095 case X86::BI__builtin_ia32_shuf_f64x2_256:
16096 case X86::BI__builtin_ia32_shuf_i32x4_256:
16097 case X86::BI__builtin_ia32_shuf_i64x2_256:
16098 case X86::BI__builtin_ia32_shuf_f32x4:
16099 case X86::BI__builtin_ia32_shuf_f64x2:
16100 case X86::BI__builtin_ia32_shuf_i32x4:
16101 case X86::BI__builtin_ia32_shuf_i64x2: {
16102 unsigned Imm = cast<llvm::ConstantInt>(Ops[2])->getZExtValue();
16103 auto *Ty = cast<llvm::FixedVectorType>(Ops[0]->getType());
16104 unsigned NumElts = Ty->getNumElements();
16105 unsigned NumLanes = Ty->getPrimitiveSizeInBits() == 512 ? 4 : 2;
16106 unsigned NumLaneElts = NumElts / NumLanes;
16109 for (
unsigned l = 0; l != NumElts; l += NumLaneElts) {
16110 unsigned Index = (Imm % NumLanes) * NumLaneElts;
16112 if (l >= (NumElts / 2))
16114 for (
unsigned i = 0; i != NumLaneElts; ++i) {
16115 Indices[l + i] = Index + i;
16119 return Builder.CreateShuffleVector(Ops[0], Ops[1],
16120 ArrayRef(Indices, NumElts),
"shuf");
16123 case X86::BI__builtin_ia32_vperm2f128_pd256:
16124 case X86::BI__builtin_ia32_vperm2f128_ps256:
16125 case X86::BI__builtin_ia32_vperm2f128_si256:
16126 case X86::BI__builtin_ia32_permti256: {
16127 unsigned Imm = cast<llvm::ConstantInt>(Ops[2])->getZExtValue();
16129 cast<llvm::FixedVectorType>(Ops[0]->getType())->getNumElements();
16138 for (
unsigned l = 0; l != 2; ++l) {
16140 if (Imm & (1 << ((l * 4) + 3)))
16141 OutOps[l] = llvm::ConstantAggregateZero::get(Ops[0]->getType());
16142 else if (Imm & (1 << ((l * 4) + 1)))
16143 OutOps[l] = Ops[1];
16145 OutOps[l] = Ops[0];
16147 for (
unsigned i = 0; i != NumElts/2; ++i) {
16149 unsigned Idx = (l * NumElts) + i;
16152 if (Imm & (1 << (l * 4)))
16154 Indices[(l * (NumElts/2)) + i] = Idx;
16158 return Builder.CreateShuffleVector(OutOps[0], OutOps[1],
16159 ArrayRef(Indices, NumElts),
"vperm");
16162 case X86::BI__builtin_ia32_pslldqi128_byteshift:
16163 case X86::BI__builtin_ia32_pslldqi256_byteshift:
16164 case X86::BI__builtin_ia32_pslldqi512_byteshift: {
16165 unsigned ShiftVal = cast<llvm::ConstantInt>(Ops[1])->getZExtValue() & 0xff;
16166 auto *ResultType = cast<llvm::FixedVectorType>(Ops[0]->getType());
16168 unsigned NumElts = ResultType->getNumElements() * 8;
16171 if (ShiftVal >= 16)
16172 return llvm::Constant::getNullValue(ResultType);
16176 for (
unsigned l = 0; l != NumElts; l += 16) {
16177 for (
unsigned i = 0; i != 16; ++i) {
16178 unsigned Idx = NumElts + i - ShiftVal;
16179 if (Idx < NumElts) Idx -= NumElts - 16;
16180 Indices[l + i] = Idx + l;
16184 auto *VecTy = llvm::FixedVectorType::get(
Int8Ty, NumElts);
16186 Value *
Zero = llvm::Constant::getNullValue(VecTy);
16188 Zero, Cast,
ArrayRef(Indices, NumElts),
"pslldq");
16189 return Builder.CreateBitCast(SV, Ops[0]->getType(),
"cast");
16191 case X86::BI__builtin_ia32_psrldqi128_byteshift:
16192 case X86::BI__builtin_ia32_psrldqi256_byteshift:
16193 case X86::BI__builtin_ia32_psrldqi512_byteshift: {
16194 unsigned ShiftVal = cast<llvm::ConstantInt>(Ops[1])->getZExtValue() & 0xff;
16195 auto *ResultType = cast<llvm::FixedVectorType>(Ops[0]->getType());
16197 unsigned NumElts = ResultType->getNumElements() * 8;
16200 if (ShiftVal >= 16)
16201 return llvm::Constant::getNullValue(ResultType);
16205 for (
unsigned l = 0; l != NumElts; l += 16) {
16206 for (
unsigned i = 0; i != 16; ++i) {
16207 unsigned Idx = i + ShiftVal;
16208 if (Idx >= 16) Idx += NumElts - 16;
16209 Indices[l + i] = Idx + l;
16213 auto *VecTy = llvm::FixedVectorType::get(
Int8Ty, NumElts);
16215 Value *
Zero = llvm::Constant::getNullValue(VecTy);
16217 Cast, Zero,
ArrayRef(Indices, NumElts),
"psrldq");
16218 return Builder.CreateBitCast(SV, ResultType,
"cast");
16220 case X86::BI__builtin_ia32_kshiftliqi:
16221 case X86::BI__builtin_ia32_kshiftlihi:
16222 case X86::BI__builtin_ia32_kshiftlisi:
16223 case X86::BI__builtin_ia32_kshiftlidi: {
16224 unsigned ShiftVal = cast<llvm::ConstantInt>(Ops[1])->getZExtValue() & 0xff;
16225 unsigned NumElts = Ops[0]->getType()->getIntegerBitWidth();
16227 if (ShiftVal >= NumElts)
16228 return llvm::Constant::getNullValue(Ops[0]->getType());
16233 for (
unsigned i = 0; i != NumElts; ++i)
16234 Indices[i] = NumElts + i - ShiftVal;
16236 Value *
Zero = llvm::Constant::getNullValue(
In->getType());
16238 Zero, In,
ArrayRef(Indices, NumElts),
"kshiftl");
16239 return Builder.CreateBitCast(SV, Ops[0]->getType());
16241 case X86::BI__builtin_ia32_kshiftriqi:
16242 case X86::BI__builtin_ia32_kshiftrihi:
16243 case X86::BI__builtin_ia32_kshiftrisi:
16244 case X86::BI__builtin_ia32_kshiftridi: {
16245 unsigned ShiftVal = cast<llvm::ConstantInt>(Ops[1])->getZExtValue() & 0xff;
16246 unsigned NumElts = Ops[0]->getType()->getIntegerBitWidth();
16248 if (ShiftVal >= NumElts)
16249 return llvm::Constant::getNullValue(Ops[0]->getType());
16254 for (
unsigned i = 0; i != NumElts; ++i)
16255 Indices[i] = i + ShiftVal;
16257 Value *
Zero = llvm::Constant::getNullValue(
In->getType());
16259 In, Zero,
ArrayRef(Indices, NumElts),
"kshiftr");
16260 return Builder.CreateBitCast(SV, Ops[0]->getType());
16262 case X86::BI__builtin_ia32_movnti:
16263 case X86::BI__builtin_ia32_movnti64:
16264 case X86::BI__builtin_ia32_movntsd:
16265 case X86::BI__builtin_ia32_movntss: {
16266 llvm::MDNode *
Node = llvm::MDNode::get(
16269 Value *Ptr = Ops[0];
16270 Value *Src = Ops[1];
16273 if (BuiltinID == X86::BI__builtin_ia32_movntsd ||
16274 BuiltinID == X86::BI__builtin_ia32_movntss)
16275 Src =
Builder.CreateExtractElement(Src, (uint64_t)0,
"extract");
16279 SI->setMetadata(llvm::LLVMContext::MD_nontemporal,
Node);
16280 SI->setAlignment(llvm::Align(1));
16284 case X86::BI__builtin_ia32_vprotb:
16285 case X86::BI__builtin_ia32_vprotw:
16286 case X86::BI__builtin_ia32_vprotd:
16287 case X86::BI__builtin_ia32_vprotq:
16288 case X86::BI__builtin_ia32_vprotbi:
16289 case X86::BI__builtin_ia32_vprotwi:
16290 case X86::BI__builtin_ia32_vprotdi:
16291 case X86::BI__builtin_ia32_vprotqi:
16292 case X86::BI__builtin_ia32_prold128:
16293 case X86::BI__builtin_ia32_prold256:
16294 case X86::BI__builtin_ia32_prold512:
16295 case X86::BI__builtin_ia32_prolq128:
16296 case X86::BI__builtin_ia32_prolq256:
16297 case X86::BI__builtin_ia32_prolq512:
16298 case X86::BI__builtin_ia32_prolvd128:
16299 case X86::BI__builtin_ia32_prolvd256:
16300 case X86::BI__builtin_ia32_prolvd512:
16301 case X86::BI__builtin_ia32_prolvq128:
16302 case X86::BI__builtin_ia32_prolvq256:
16303 case X86::BI__builtin_ia32_prolvq512:
16305 case X86::BI__builtin_ia32_prord128:
16306 case X86::BI__builtin_ia32_prord256:
16307 case X86::BI__builtin_ia32_prord512:
16308 case X86::BI__builtin_ia32_prorq128:
16309 case X86::BI__builtin_ia32_prorq256:
16310 case X86::BI__builtin_ia32_prorq512:
16311 case X86::BI__builtin_ia32_prorvd128:
16312 case X86::BI__builtin_ia32_prorvd256:
16313 case X86::BI__builtin_ia32_prorvd512:
16314 case X86::BI__builtin_ia32_prorvq128:
16315 case X86::BI__builtin_ia32_prorvq256:
16316 case X86::BI__builtin_ia32_prorvq512:
16318 case X86::BI__builtin_ia32_selectb_128:
16319 case X86::BI__builtin_ia32_selectb_256:
16320 case X86::BI__builtin_ia32_selectb_512:
16321 case X86::BI__builtin_ia32_selectw_128:
16322 case X86::BI__builtin_ia32_selectw_256:
16323 case X86::BI__builtin_ia32_selectw_512:
16324 case X86::BI__builtin_ia32_selectd_128:
16325 case X86::BI__builtin_ia32_selectd_256:
16326 case X86::BI__builtin_ia32_selectd_512:
16327 case X86::BI__builtin_ia32_selectq_128:
16328 case X86::BI__builtin_ia32_selectq_256:
16329 case X86::BI__builtin_ia32_selectq_512:
16330 case X86::BI__builtin_ia32_selectph_128:
16331 case X86::BI__builtin_ia32_selectph_256:
16332 case X86::BI__builtin_ia32_selectph_512:
16333 case X86::BI__builtin_ia32_selectpbf_128:
16334 case X86::BI__builtin_ia32_selectpbf_256:
16335 case X86::BI__builtin_ia32_selectpbf_512:
16336 case X86::BI__builtin_ia32_selectps_128:
16337 case X86::BI__builtin_ia32_selectps_256:
16338 case X86::BI__builtin_ia32_selectps_512:
16339 case X86::BI__builtin_ia32_selectpd_128:
16340 case X86::BI__builtin_ia32_selectpd_256:
16341 case X86::BI__builtin_ia32_selectpd_512:
16343 case X86::BI__builtin_ia32_selectsh_128:
16344 case X86::BI__builtin_ia32_selectsbf_128:
16345 case X86::BI__builtin_ia32_selectss_128:
16346 case X86::BI__builtin_ia32_selectsd_128: {
16347 Value *A =
Builder.CreateExtractElement(Ops[1], (uint64_t)0);
16348 Value *B =
Builder.CreateExtractElement(Ops[2], (uint64_t)0);
16350 return Builder.CreateInsertElement(Ops[1], A, (uint64_t)0);
16352 case X86::BI__builtin_ia32_cmpb128_mask:
16353 case X86::BI__builtin_ia32_cmpb256_mask:
16354 case X86::BI__builtin_ia32_cmpb512_mask:
16355 case X86::BI__builtin_ia32_cmpw128_mask:
16356 case X86::BI__builtin_ia32_cmpw256_mask:
16357 case X86::BI__builtin_ia32_cmpw512_mask:
16358 case X86::BI__builtin_ia32_cmpd128_mask:
16359 case X86::BI__builtin_ia32_cmpd256_mask:
16360 case X86::BI__builtin_ia32_cmpd512_mask:
16361 case X86::BI__builtin_ia32_cmpq128_mask:
16362 case X86::BI__builtin_ia32_cmpq256_mask:
16363 case X86::BI__builtin_ia32_cmpq512_mask: {
16364 unsigned CC = cast<llvm::ConstantInt>(Ops[2])->getZExtValue() & 0x7;
16367 case X86::BI__builtin_ia32_ucmpb128_mask:
16368 case X86::BI__builtin_ia32_ucmpb256_mask:
16369 case X86::BI__builtin_ia32_ucmpb512_mask:
16370 case X86::BI__builtin_ia32_ucmpw128_mask:
16371 case X86::BI__builtin_ia32_ucmpw256_mask:
16372 case X86::BI__builtin_ia32_ucmpw512_mask:
16373 case X86::BI__builtin_ia32_ucmpd128_mask:
16374 case X86::BI__builtin_ia32_ucmpd256_mask:
16375 case X86::BI__builtin_ia32_ucmpd512_mask:
16376 case X86::BI__builtin_ia32_ucmpq128_mask:
16377 case X86::BI__builtin_ia32_ucmpq256_mask:
16378 case X86::BI__builtin_ia32_ucmpq512_mask: {
16379 unsigned CC = cast<llvm::ConstantInt>(Ops[2])->getZExtValue() & 0x7;
16382 case X86::BI__builtin_ia32_vpcomb:
16383 case X86::BI__builtin_ia32_vpcomw:
16384 case X86::BI__builtin_ia32_vpcomd:
16385 case X86::BI__builtin_ia32_vpcomq:
16387 case X86::BI__builtin_ia32_vpcomub:
16388 case X86::BI__builtin_ia32_vpcomuw:
16389 case X86::BI__builtin_ia32_vpcomud:
16390 case X86::BI__builtin_ia32_vpcomuq:
16393 case X86::BI__builtin_ia32_kortestcqi:
16394 case X86::BI__builtin_ia32_kortestchi:
16395 case X86::BI__builtin_ia32_kortestcsi:
16396 case X86::BI__builtin_ia32_kortestcdi: {
16398 Value *
C = llvm::Constant::getAllOnesValue(Ops[0]->getType());
16402 case X86::BI__builtin_ia32_kortestzqi:
16403 case X86::BI__builtin_ia32_kortestzhi:
16404 case X86::BI__builtin_ia32_kortestzsi:
16405 case X86::BI__builtin_ia32_kortestzdi: {
16407 Value *
C = llvm::Constant::getNullValue(Ops[0]->getType());
16412 case X86::BI__builtin_ia32_ktestcqi:
16413 case X86::BI__builtin_ia32_ktestzqi:
16414 case X86::BI__builtin_ia32_ktestchi:
16415 case X86::BI__builtin_ia32_ktestzhi:
16416 case X86::BI__builtin_ia32_ktestcsi:
16417 case X86::BI__builtin_ia32_ktestzsi:
16418 case X86::BI__builtin_ia32_ktestcdi:
16419 case X86::BI__builtin_ia32_ktestzdi: {
16421 switch (BuiltinID) {
16422 default: llvm_unreachable(
"Unsupported intrinsic!");
16423 case X86::BI__builtin_ia32_ktestcqi:
16424 IID = Intrinsic::x86_avx512_ktestc_b;
16426 case X86::BI__builtin_ia32_ktestzqi:
16427 IID = Intrinsic::x86_avx512_ktestz_b;
16429 case X86::BI__builtin_ia32_ktestchi:
16430 IID = Intrinsic::x86_avx512_ktestc_w;
16432 case X86::BI__builtin_ia32_ktestzhi:
16433 IID = Intrinsic::x86_avx512_ktestz_w;
16435 case X86::BI__builtin_ia32_ktestcsi:
16436 IID = Intrinsic::x86_avx512_ktestc_d;
16438 case X86::BI__builtin_ia32_ktestzsi:
16439 IID = Intrinsic::x86_avx512_ktestz_d;
16441 case X86::BI__builtin_ia32_ktestcdi:
16442 IID = Intrinsic::x86_avx512_ktestc_q;
16444 case X86::BI__builtin_ia32_ktestzdi:
16445 IID = Intrinsic::x86_avx512_ktestz_q;
16449 unsigned NumElts = Ops[0]->getType()->getIntegerBitWidth();
16453 return Builder.CreateCall(Intr, {LHS, RHS});
16456 case X86::BI__builtin_ia32_kaddqi:
16457 case X86::BI__builtin_ia32_kaddhi:
16458 case X86::BI__builtin_ia32_kaddsi:
16459 case X86::BI__builtin_ia32_kadddi: {
16461 switch (BuiltinID) {
16462 default: llvm_unreachable(
"Unsupported intrinsic!");
16463 case X86::BI__builtin_ia32_kaddqi:
16464 IID = Intrinsic::x86_avx512_kadd_b;
16466 case X86::BI__builtin_ia32_kaddhi:
16467 IID = Intrinsic::x86_avx512_kadd_w;
16469 case X86::BI__builtin_ia32_kaddsi:
16470 IID = Intrinsic::x86_avx512_kadd_d;
16472 case X86::BI__builtin_ia32_kadddi:
16473 IID = Intrinsic::x86_avx512_kadd_q;
16477 unsigned NumElts = Ops[0]->getType()->getIntegerBitWidth();
16482 return Builder.CreateBitCast(Res, Ops[0]->getType());
16484 case X86::BI__builtin_ia32_kandqi:
16485 case X86::BI__builtin_ia32_kandhi:
16486 case X86::BI__builtin_ia32_kandsi:
16487 case X86::BI__builtin_ia32_kanddi:
16489 case X86::BI__builtin_ia32_kandnqi:
16490 case X86::BI__builtin_ia32_kandnhi:
16491 case X86::BI__builtin_ia32_kandnsi:
16492 case X86::BI__builtin_ia32_kandndi:
16494 case X86::BI__builtin_ia32_korqi:
16495 case X86::BI__builtin_ia32_korhi:
16496 case X86::BI__builtin_ia32_korsi:
16497 case X86::BI__builtin_ia32_kordi:
16499 case X86::BI__builtin_ia32_kxnorqi:
16500 case X86::BI__builtin_ia32_kxnorhi:
16501 case X86::BI__builtin_ia32_kxnorsi:
16502 case X86::BI__builtin_ia32_kxnordi:
16504 case X86::BI__builtin_ia32_kxorqi:
16505 case X86::BI__builtin_ia32_kxorhi:
16506 case X86::BI__builtin_ia32_kxorsi:
16507 case X86::BI__builtin_ia32_kxordi:
16509 case X86::BI__builtin_ia32_knotqi:
16510 case X86::BI__builtin_ia32_knothi:
16511 case X86::BI__builtin_ia32_knotsi:
16512 case X86::BI__builtin_ia32_knotdi: {
16513 unsigned NumElts = Ops[0]->getType()->getIntegerBitWidth();
16516 Ops[0]->getType());
16518 case X86::BI__builtin_ia32_kmovb:
16519 case X86::BI__builtin_ia32_kmovw:
16520 case X86::BI__builtin_ia32_kmovd:
16521 case X86::BI__builtin_ia32_kmovq: {
16525 unsigned NumElts = Ops[0]->getType()->getIntegerBitWidth();
16527 return Builder.CreateBitCast(Res, Ops[0]->getType());
16530 case X86::BI__builtin_ia32_kunpckdi:
16531 case X86::BI__builtin_ia32_kunpcksi:
16532 case X86::BI__builtin_ia32_kunpckhi: {
16533 unsigned NumElts = Ops[0]->getType()->getIntegerBitWidth();
16537 for (
unsigned i = 0; i != NumElts; ++i)
16542 LHS =
Builder.CreateShuffleVector(LHS, LHS,
ArrayRef(Indices, NumElts / 2));
16543 RHS =
Builder.CreateShuffleVector(RHS, RHS,
ArrayRef(Indices, NumElts / 2));
16548 return Builder.CreateBitCast(Res, Ops[0]->getType());
16551 case X86::BI__builtin_ia32_vplzcntd_128:
16552 case X86::BI__builtin_ia32_vplzcntd_256:
16553 case X86::BI__builtin_ia32_vplzcntd_512:
16554 case X86::BI__builtin_ia32_vplzcntq_128:
16555 case X86::BI__builtin_ia32_vplzcntq_256:
16556 case X86::BI__builtin_ia32_vplzcntq_512: {
16560 case X86::BI__builtin_ia32_sqrtss:
16561 case X86::BI__builtin_ia32_sqrtsd: {
16562 Value *A =
Builder.CreateExtractElement(Ops[0], (uint64_t)0);
16564 if (
Builder.getIsFPConstrained()) {
16565 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*
this,
E);
16568 A =
Builder.CreateConstrainedFPCall(F, {A});
16571 A =
Builder.CreateCall(F, {A});
16573 return Builder.CreateInsertElement(Ops[0], A, (uint64_t)0);
16575 case X86::BI__builtin_ia32_sqrtsh_round_mask:
16576 case X86::BI__builtin_ia32_sqrtsd_round_mask:
16577 case X86::BI__builtin_ia32_sqrtss_round_mask: {
16578 unsigned CC = cast<llvm::ConstantInt>(Ops[4])->getZExtValue();
16584 switch (BuiltinID) {
16586 llvm_unreachable(
"Unsupported intrinsic!");
16587 case X86::BI__builtin_ia32_sqrtsh_round_mask:
16588 IID = Intrinsic::x86_avx512fp16_mask_sqrt_sh;
16590 case X86::BI__builtin_ia32_sqrtsd_round_mask:
16591 IID = Intrinsic::x86_avx512_mask_sqrt_sd;
16593 case X86::BI__builtin_ia32_sqrtss_round_mask:
16594 IID = Intrinsic::x86_avx512_mask_sqrt_ss;
16599 Value *A =
Builder.CreateExtractElement(Ops[1], (uint64_t)0);
16601 if (
Builder.getIsFPConstrained()) {
16602 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*
this,
E);
16605 A =
Builder.CreateConstrainedFPCall(F, A);
16608 A =
Builder.CreateCall(F, A);
16610 Value *Src =
Builder.CreateExtractElement(Ops[2], (uint64_t)0);
16612 return Builder.CreateInsertElement(Ops[0], A, (uint64_t)0);
16614 case X86::BI__builtin_ia32_sqrtpd256:
16615 case X86::BI__builtin_ia32_sqrtpd:
16616 case X86::BI__builtin_ia32_sqrtps256:
16617 case X86::BI__builtin_ia32_sqrtps:
16618 case X86::BI__builtin_ia32_sqrtph256:
16619 case X86::BI__builtin_ia32_sqrtph:
16620 case X86::BI__builtin_ia32_sqrtph512:
16621 case X86::BI__builtin_ia32_vsqrtnepbf16256:
16622 case X86::BI__builtin_ia32_vsqrtnepbf16:
16623 case X86::BI__builtin_ia32_vsqrtnepbf16512:
16624 case X86::BI__builtin_ia32_sqrtps512:
16625 case X86::BI__builtin_ia32_sqrtpd512: {
16626 if (Ops.size() == 2) {
16627 unsigned CC = cast<llvm::ConstantInt>(Ops[1])->getZExtValue();
16633 switch (BuiltinID) {
16635 llvm_unreachable(
"Unsupported intrinsic!");
16636 case X86::BI__builtin_ia32_sqrtph512:
16637 IID = Intrinsic::x86_avx512fp16_sqrt_ph_512;
16639 case X86::BI__builtin_ia32_sqrtps512:
16640 IID = Intrinsic::x86_avx512_sqrt_ps_512;
16642 case X86::BI__builtin_ia32_sqrtpd512:
16643 IID = Intrinsic::x86_avx512_sqrt_pd_512;
16649 if (
Builder.getIsFPConstrained()) {
16650 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*
this,
E);
16652 Ops[0]->getType());
16653 return Builder.CreateConstrainedFPCall(F, Ops[0]);
16656 return Builder.CreateCall(F, Ops[0]);
16660 case X86::BI__builtin_ia32_pmuludq128:
16661 case X86::BI__builtin_ia32_pmuludq256:
16662 case X86::BI__builtin_ia32_pmuludq512:
16665 case X86::BI__builtin_ia32_pmuldq128:
16666 case X86::BI__builtin_ia32_pmuldq256:
16667 case X86::BI__builtin_ia32_pmuldq512:
16670 case X86::BI__builtin_ia32_pternlogd512_mask:
16671 case X86::BI__builtin_ia32_pternlogq512_mask:
16672 case X86::BI__builtin_ia32_pternlogd128_mask:
16673 case X86::BI__builtin_ia32_pternlogd256_mask:
16674 case X86::BI__builtin_ia32_pternlogq128_mask:
16675 case X86::BI__builtin_ia32_pternlogq256_mask:
16678 case X86::BI__builtin_ia32_pternlogd512_maskz:
16679 case X86::BI__builtin_ia32_pternlogq512_maskz:
16680 case X86::BI__builtin_ia32_pternlogd128_maskz:
16681 case X86::BI__builtin_ia32_pternlogd256_maskz:
16682 case X86::BI__builtin_ia32_pternlogq128_maskz:
16683 case X86::BI__builtin_ia32_pternlogq256_maskz:
16686 case X86::BI__builtin_ia32_vpshldd128:
16687 case X86::BI__builtin_ia32_vpshldd256:
16688 case X86::BI__builtin_ia32_vpshldd512:
16689 case X86::BI__builtin_ia32_vpshldq128:
16690 case X86::BI__builtin_ia32_vpshldq256:
16691 case X86::BI__builtin_ia32_vpshldq512:
16692 case X86::BI__builtin_ia32_vpshldw128:
16693 case X86::BI__builtin_ia32_vpshldw256:
16694 case X86::BI__builtin_ia32_vpshldw512:
16697 case X86::BI__builtin_ia32_vpshrdd128:
16698 case X86::BI__builtin_ia32_vpshrdd256:
16699 case X86::BI__builtin_ia32_vpshrdd512:
16700 case X86::BI__builtin_ia32_vpshrdq128:
16701 case X86::BI__builtin_ia32_vpshrdq256:
16702 case X86::BI__builtin_ia32_vpshrdq512:
16703 case X86::BI__builtin_ia32_vpshrdw128:
16704 case X86::BI__builtin_ia32_vpshrdw256:
16705 case X86::BI__builtin_ia32_vpshrdw512:
16709 case X86::BI__builtin_ia32_vpshldvd128:
16710 case X86::BI__builtin_ia32_vpshldvd256:
16711 case X86::BI__builtin_ia32_vpshldvd512:
16712 case X86::BI__builtin_ia32_vpshldvq128:
16713 case X86::BI__builtin_ia32_vpshldvq256:
16714 case X86::BI__builtin_ia32_vpshldvq512:
16715 case X86::BI__builtin_ia32_vpshldvw128:
16716 case X86::BI__builtin_ia32_vpshldvw256:
16717 case X86::BI__builtin_ia32_vpshldvw512:
16720 case X86::BI__builtin_ia32_vpshrdvd128:
16721 case X86::BI__builtin_ia32_vpshrdvd256:
16722 case X86::BI__builtin_ia32_vpshrdvd512:
16723 case X86::BI__builtin_ia32_vpshrdvq128:
16724 case X86::BI__builtin_ia32_vpshrdvq256:
16725 case X86::BI__builtin_ia32_vpshrdvq512:
16726 case X86::BI__builtin_ia32_vpshrdvw128:
16727 case X86::BI__builtin_ia32_vpshrdvw256:
16728 case X86::BI__builtin_ia32_vpshrdvw512:
16733 case X86::BI__builtin_ia32_reduce_fadd_pd512:
16734 case X86::BI__builtin_ia32_reduce_fadd_ps512:
16735 case X86::BI__builtin_ia32_reduce_fadd_ph512:
16736 case X86::BI__builtin_ia32_reduce_fadd_ph256:
16737 case X86::BI__builtin_ia32_reduce_fadd_ph128: {
16740 IRBuilder<>::FastMathFlagGuard FMFGuard(
Builder);
16741 Builder.getFastMathFlags().setAllowReassoc();
16742 return Builder.CreateCall(F, {Ops[0], Ops[1]});
16744 case X86::BI__builtin_ia32_reduce_fmul_pd512:
16745 case X86::BI__builtin_ia32_reduce_fmul_ps512:
16746 case X86::BI__builtin_ia32_reduce_fmul_ph512:
16747 case X86::BI__builtin_ia32_reduce_fmul_ph256:
16748 case X86::BI__builtin_ia32_reduce_fmul_ph128: {
16751 IRBuilder<>::FastMathFlagGuard FMFGuard(
Builder);
16752 Builder.getFastMathFlags().setAllowReassoc();
16753 return Builder.CreateCall(F, {Ops[0], Ops[1]});
16755 case X86::BI__builtin_ia32_reduce_fmax_pd512:
16756 case X86::BI__builtin_ia32_reduce_fmax_ps512:
16757 case X86::BI__builtin_ia32_reduce_fmax_ph512:
16758 case X86::BI__builtin_ia32_reduce_fmax_ph256:
16759 case X86::BI__builtin_ia32_reduce_fmax_ph128: {
16762 IRBuilder<>::FastMathFlagGuard FMFGuard(
Builder);
16763 Builder.getFastMathFlags().setNoNaNs();
16764 return Builder.CreateCall(F, {Ops[0]});
16766 case X86::BI__builtin_ia32_reduce_fmin_pd512:
16767 case X86::BI__builtin_ia32_reduce_fmin_ps512:
16768 case X86::BI__builtin_ia32_reduce_fmin_ph512:
16769 case X86::BI__builtin_ia32_reduce_fmin_ph256:
16770 case X86::BI__builtin_ia32_reduce_fmin_ph128: {
16773 IRBuilder<>::FastMathFlagGuard FMFGuard(
Builder);
16774 Builder.getFastMathFlags().setNoNaNs();
16775 return Builder.CreateCall(F, {Ops[0]});
16778 case X86::BI__builtin_ia32_rdrand16_step:
16779 case X86::BI__builtin_ia32_rdrand32_step:
16780 case X86::BI__builtin_ia32_rdrand64_step:
16781 case X86::BI__builtin_ia32_rdseed16_step:
16782 case X86::BI__builtin_ia32_rdseed32_step:
16783 case X86::BI__builtin_ia32_rdseed64_step: {
16785 switch (BuiltinID) {
16786 default: llvm_unreachable(
"Unsupported intrinsic!");
16787 case X86::BI__builtin_ia32_rdrand16_step:
16788 ID = Intrinsic::x86_rdrand_16;
16790 case X86::BI__builtin_ia32_rdrand32_step:
16791 ID = Intrinsic::x86_rdrand_32;
16793 case X86::BI__builtin_ia32_rdrand64_step:
16794 ID = Intrinsic::x86_rdrand_64;
16796 case X86::BI__builtin_ia32_rdseed16_step:
16797 ID = Intrinsic::x86_rdseed_16;
16799 case X86::BI__builtin_ia32_rdseed32_step:
16800 ID = Intrinsic::x86_rdseed_32;
16802 case X86::BI__builtin_ia32_rdseed64_step:
16803 ID = Intrinsic::x86_rdseed_64;
16812 case X86::BI__builtin_ia32_addcarryx_u32:
16813 case X86::BI__builtin_ia32_addcarryx_u64:
16814 case X86::BI__builtin_ia32_subborrow_u32:
16815 case X86::BI__builtin_ia32_subborrow_u64: {
16817 switch (BuiltinID) {
16818 default: llvm_unreachable(
"Unsupported intrinsic!");
16819 case X86::BI__builtin_ia32_addcarryx_u32:
16820 IID = Intrinsic::x86_addcarry_32;
16822 case X86::BI__builtin_ia32_addcarryx_u64:
16823 IID = Intrinsic::x86_addcarry_64;
16825 case X86::BI__builtin_ia32_subborrow_u32:
16826 IID = Intrinsic::x86_subborrow_32;
16828 case X86::BI__builtin_ia32_subborrow_u64:
16829 IID = Intrinsic::x86_subborrow_64;
16834 { Ops[0], Ops[1], Ops[2] });
16840 case X86::BI__builtin_ia32_fpclassps128_mask:
16841 case X86::BI__builtin_ia32_fpclassps256_mask:
16842 case X86::BI__builtin_ia32_fpclassps512_mask:
16843 case X86::BI__builtin_ia32_vfpclasspbf16128_mask:
16844 case X86::BI__builtin_ia32_vfpclasspbf16256_mask:
16845 case X86::BI__builtin_ia32_vfpclasspbf16512_mask:
16846 case X86::BI__builtin_ia32_fpclassph128_mask:
16847 case X86::BI__builtin_ia32_fpclassph256_mask:
16848 case X86::BI__builtin_ia32_fpclassph512_mask:
16849 case X86::BI__builtin_ia32_fpclasspd128_mask:
16850 case X86::BI__builtin_ia32_fpclasspd256_mask:
16851 case X86::BI__builtin_ia32_fpclasspd512_mask: {
16853 cast<llvm::FixedVectorType>(Ops[0]->getType())->getNumElements();
16854 Value *MaskIn = Ops[2];
16855 Ops.erase(&Ops[2]);
16858 switch (BuiltinID) {
16859 default: llvm_unreachable(
"Unsupported intrinsic!");
16860 case X86::BI__builtin_ia32_vfpclasspbf16128_mask:
16861 ID = Intrinsic::x86_avx10_fpclass_nepbf16_128;
16863 case X86::BI__builtin_ia32_vfpclasspbf16256_mask:
16864 ID = Intrinsic::x86_avx10_fpclass_nepbf16_256;
16866 case X86::BI__builtin_ia32_vfpclasspbf16512_mask:
16867 ID = Intrinsic::x86_avx10_fpclass_nepbf16_512;
16869 case X86::BI__builtin_ia32_fpclassph128_mask:
16870 ID = Intrinsic::x86_avx512fp16_fpclass_ph_128;
16872 case X86::BI__builtin_ia32_fpclassph256_mask:
16873 ID = Intrinsic::x86_avx512fp16_fpclass_ph_256;
16875 case X86::BI__builtin_ia32_fpclassph512_mask:
16876 ID = Intrinsic::x86_avx512fp16_fpclass_ph_512;
16878 case X86::BI__builtin_ia32_fpclassps128_mask:
16879 ID = Intrinsic::x86_avx512_fpclass_ps_128;
16881 case X86::BI__builtin_ia32_fpclassps256_mask:
16882 ID = Intrinsic::x86_avx512_fpclass_ps_256;
16884 case X86::BI__builtin_ia32_fpclassps512_mask:
16885 ID = Intrinsic::x86_avx512_fpclass_ps_512;
16887 case X86::BI__builtin_ia32_fpclasspd128_mask:
16888 ID = Intrinsic::x86_avx512_fpclass_pd_128;
16890 case X86::BI__builtin_ia32_fpclasspd256_mask:
16891 ID = Intrinsic::x86_avx512_fpclass_pd_256;
16893 case X86::BI__builtin_ia32_fpclasspd512_mask:
16894 ID = Intrinsic::x86_avx512_fpclass_pd_512;
16902 case X86::BI__builtin_ia32_vp2intersect_q_512:
16903 case X86::BI__builtin_ia32_vp2intersect_q_256:
16904 case X86::BI__builtin_ia32_vp2intersect_q_128:
16905 case X86::BI__builtin_ia32_vp2intersect_d_512:
16906 case X86::BI__builtin_ia32_vp2intersect_d_256:
16907 case X86::BI__builtin_ia32_vp2intersect_d_128: {
16909 cast<llvm::FixedVectorType>(Ops[0]->getType())->getNumElements();
16912 switch (BuiltinID) {
16913 default: llvm_unreachable(
"Unsupported intrinsic!");
16914 case X86::BI__builtin_ia32_vp2intersect_q_512:
16915 ID = Intrinsic::x86_avx512_vp2intersect_q_512;
16917 case X86::BI__builtin_ia32_vp2intersect_q_256:
16918 ID = Intrinsic::x86_avx512_vp2intersect_q_256;
16920 case X86::BI__builtin_ia32_vp2intersect_q_128:
16921 ID = Intrinsic::x86_avx512_vp2intersect_q_128;
16923 case X86::BI__builtin_ia32_vp2intersect_d_512:
16924 ID = Intrinsic::x86_avx512_vp2intersect_d_512;
16926 case X86::BI__builtin_ia32_vp2intersect_d_256:
16927 ID = Intrinsic::x86_avx512_vp2intersect_d_256;
16929 case X86::BI__builtin_ia32_vp2intersect_d_128:
16930 ID = Intrinsic::x86_avx512_vp2intersect_d_128;
16944 case X86::BI__builtin_ia32_vpmultishiftqb128:
16945 case X86::BI__builtin_ia32_vpmultishiftqb256:
16946 case X86::BI__builtin_ia32_vpmultishiftqb512: {
16948 switch (BuiltinID) {
16949 default: llvm_unreachable(
"Unsupported intrinsic!");
16950 case X86::BI__builtin_ia32_vpmultishiftqb128:
16951 ID = Intrinsic::x86_avx512_pmultishift_qb_128;
16953 case X86::BI__builtin_ia32_vpmultishiftqb256:
16954 ID = Intrinsic::x86_avx512_pmultishift_qb_256;
16956 case X86::BI__builtin_ia32_vpmultishiftqb512:
16957 ID = Intrinsic::x86_avx512_pmultishift_qb_512;
16964 case X86::BI__builtin_ia32_vpshufbitqmb128_mask:
16965 case X86::BI__builtin_ia32_vpshufbitqmb256_mask:
16966 case X86::BI__builtin_ia32_vpshufbitqmb512_mask: {
16968 cast<llvm::FixedVectorType>(Ops[0]->getType())->getNumElements();
16969 Value *MaskIn = Ops[2];
16970 Ops.erase(&Ops[2]);
16973 switch (BuiltinID) {
16974 default: llvm_unreachable(
"Unsupported intrinsic!");
16975 case X86::BI__builtin_ia32_vpshufbitqmb128_mask:
16976 ID = Intrinsic::x86_avx512_vpshufbitqmb_128;
16978 case X86::BI__builtin_ia32_vpshufbitqmb256_mask:
16979 ID = Intrinsic::x86_avx512_vpshufbitqmb_256;
16981 case X86::BI__builtin_ia32_vpshufbitqmb512_mask:
16982 ID = Intrinsic::x86_avx512_vpshufbitqmb_512;
16991 case X86::BI__builtin_ia32_cmpeqps:
16992 case X86::BI__builtin_ia32_cmpeqpd:
16993 return getVectorFCmpIR(CmpInst::FCMP_OEQ,
false);
16994 case X86::BI__builtin_ia32_cmpltps:
16995 case X86::BI__builtin_ia32_cmpltpd:
16996 return getVectorFCmpIR(CmpInst::FCMP_OLT,
true);
16997 case X86::BI__builtin_ia32_cmpleps:
16998 case X86::BI__builtin_ia32_cmplepd:
16999 return getVectorFCmpIR(CmpInst::FCMP_OLE,
true);
17000 case X86::BI__builtin_ia32_cmpunordps:
17001 case X86::BI__builtin_ia32_cmpunordpd:
17002 return getVectorFCmpIR(CmpInst::FCMP_UNO,
false);
17003 case X86::BI__builtin_ia32_cmpneqps:
17004 case X86::BI__builtin_ia32_cmpneqpd:
17005 return getVectorFCmpIR(CmpInst::FCMP_UNE,
false);
17006 case X86::BI__builtin_ia32_cmpnltps:
17007 case X86::BI__builtin_ia32_cmpnltpd:
17008 return getVectorFCmpIR(CmpInst::FCMP_UGE,
true);
17009 case X86::BI__builtin_ia32_cmpnleps:
17010 case X86::BI__builtin_ia32_cmpnlepd:
17011 return getVectorFCmpIR(CmpInst::FCMP_UGT,
true);
17012 case X86::BI__builtin_ia32_cmpordps:
17013 case X86::BI__builtin_ia32_cmpordpd:
17014 return getVectorFCmpIR(CmpInst::FCMP_ORD,
false);
17015 case X86::BI__builtin_ia32_cmpph128_mask:
17016 case X86::BI__builtin_ia32_cmpph256_mask:
17017 case X86::BI__builtin_ia32_cmpph512_mask:
17018 case X86::BI__builtin_ia32_cmpps128_mask:
17019 case X86::BI__builtin_ia32_cmpps256_mask:
17020 case X86::BI__builtin_ia32_cmpps512_mask:
17021 case X86::BI__builtin_ia32_cmppd128_mask:
17022 case X86::BI__builtin_ia32_cmppd256_mask:
17023 case X86::BI__builtin_ia32_cmppd512_mask:
17024 case X86::BI__builtin_ia32_vcmppd256_round_mask:
17025 case X86::BI__builtin_ia32_vcmpps256_round_mask:
17026 case X86::BI__builtin_ia32_vcmpph256_round_mask:
17027 case X86::BI__builtin_ia32_vcmppbf16512_mask:
17028 case X86::BI__builtin_ia32_vcmppbf16256_mask:
17029 case X86::BI__builtin_ia32_vcmppbf16128_mask:
17032 case X86::BI__builtin_ia32_cmpps:
17033 case X86::BI__builtin_ia32_cmpps256:
17034 case X86::BI__builtin_ia32_cmppd:
17035 case X86::BI__builtin_ia32_cmppd256: {
17043 unsigned CC = cast<llvm::ConstantInt>(Ops[2])->getZExtValue() & 0x1f;
17048 FCmpInst::Predicate Pred;
17052 switch (CC & 0xf) {
17053 case 0x00: Pred = FCmpInst::FCMP_OEQ; IsSignaling =
false;
break;
17054 case 0x01: Pred = FCmpInst::FCMP_OLT; IsSignaling =
true;
break;
17055 case 0x02: Pred = FCmpInst::FCMP_OLE; IsSignaling =
true;
break;
17056 case 0x03: Pred = FCmpInst::FCMP_UNO; IsSignaling =
false;
break;
17057 case 0x04: Pred = FCmpInst::FCMP_UNE; IsSignaling =
false;
break;
17058 case 0x05: Pred = FCmpInst::FCMP_UGE; IsSignaling =
true;
break;
17059 case 0x06: Pred = FCmpInst::FCMP_UGT; IsSignaling =
true;
break;
17060 case 0x07: Pred = FCmpInst::FCMP_ORD; IsSignaling =
false;
break;
17061 case 0x08: Pred = FCmpInst::FCMP_UEQ; IsSignaling =
false;
break;
17062 case 0x09: Pred = FCmpInst::FCMP_ULT; IsSignaling =
true;
break;
17063 case 0x0a: Pred = FCmpInst::FCMP_ULE; IsSignaling =
true;
break;
17064 case 0x0b: Pred = FCmpInst::FCMP_FALSE; IsSignaling =
false;
break;
17065 case 0x0c: Pred = FCmpInst::FCMP_ONE; IsSignaling =
false;
break;
17066 case 0x0d: Pred = FCmpInst::FCMP_OGE; IsSignaling =
true;
break;
17067 case 0x0e: Pred = FCmpInst::FCMP_OGT; IsSignaling =
true;
break;
17068 case 0x0f: Pred = FCmpInst::FCMP_TRUE; IsSignaling =
false;
break;
17069 default: llvm_unreachable(
"Unhandled CC");
17074 IsSignaling = !IsSignaling;
17081 if (
Builder.getIsFPConstrained() &&
17082 (Pred == FCmpInst::FCMP_TRUE || Pred == FCmpInst::FCMP_FALSE ||
17086 switch (BuiltinID) {
17087 default: llvm_unreachable(
"Unexpected builtin");
17088 case X86::BI__builtin_ia32_cmpps:
17089 IID = Intrinsic::x86_sse_cmp_ps;
17091 case X86::BI__builtin_ia32_cmpps256:
17092 IID = Intrinsic::x86_avx_cmp_ps_256;
17094 case X86::BI__builtin_ia32_cmppd:
17095 IID = Intrinsic::x86_sse2_cmp_pd;
17097 case X86::BI__builtin_ia32_cmppd256:
17098 IID = Intrinsic::x86_avx_cmp_pd_256;
17100 case X86::BI__builtin_ia32_cmpph128_mask:
17101 IID = Intrinsic::x86_avx512fp16_mask_cmp_ph_128;
17103 case X86::BI__builtin_ia32_cmpph256_mask:
17104 IID = Intrinsic::x86_avx512fp16_mask_cmp_ph_256;
17106 case X86::BI__builtin_ia32_cmpph512_mask:
17107 IID = Intrinsic::x86_avx512fp16_mask_cmp_ph_512;
17109 case X86::BI__builtin_ia32_cmpps512_mask:
17110 IID = Intrinsic::x86_avx512_mask_cmp_ps_512;
17112 case X86::BI__builtin_ia32_cmppd512_mask:
17113 IID = Intrinsic::x86_avx512_mask_cmp_pd_512;
17115 case X86::BI__builtin_ia32_cmpps128_mask:
17116 IID = Intrinsic::x86_avx512_mask_cmp_ps_128;
17118 case X86::BI__builtin_ia32_cmpps256_mask:
17119 IID = Intrinsic::x86_avx512_mask_cmp_ps_256;
17121 case X86::BI__builtin_ia32_cmppd128_mask:
17122 IID = Intrinsic::x86_avx512_mask_cmp_pd_128;
17124 case X86::BI__builtin_ia32_cmppd256_mask:
17125 IID = Intrinsic::x86_avx512_mask_cmp_pd_256;
17132 cast<llvm::FixedVectorType>(Ops[0]->getType())->getNumElements();
17138 return Builder.CreateCall(Intr, Ops);
17149 cast<llvm::FixedVectorType>(Ops[0]->getType())->getNumElements();
17152 Cmp =
Builder.CreateFCmpS(Pred, Ops[0], Ops[1]);
17154 Cmp =
Builder.CreateFCmp(Pred, Ops[0], Ops[1]);
17158 return getVectorFCmpIR(Pred, IsSignaling);
17162 case X86::BI__builtin_ia32_cmpeqss:
17163 return getCmpIntrinsicCall(Intrinsic::x86_sse_cmp_ss, 0);
17164 case X86::BI__builtin_ia32_cmpltss:
17165 return getCmpIntrinsicCall(Intrinsic::x86_sse_cmp_ss, 1);
17166 case X86::BI__builtin_ia32_cmpless:
17167 return getCmpIntrinsicCall(Intrinsic::x86_sse_cmp_ss, 2);
17168 case X86::BI__builtin_ia32_cmpunordss:
17169 return getCmpIntrinsicCall(Intrinsic::x86_sse_cmp_ss, 3);
17170 case X86::BI__builtin_ia32_cmpneqss:
17171 return getCmpIntrinsicCall(Intrinsic::x86_sse_cmp_ss, 4);
17172 case X86::BI__builtin_ia32_cmpnltss:
17173 return getCmpIntrinsicCall(Intrinsic::x86_sse_cmp_ss, 5);
17174 case X86::BI__builtin_ia32_cmpnless:
17175 return getCmpIntrinsicCall(Intrinsic::x86_sse_cmp_ss, 6);
17176 case X86::BI__builtin_ia32_cmpordss:
17177 return getCmpIntrinsicCall(Intrinsic::x86_sse_cmp_ss, 7);
17178 case X86::BI__builtin_ia32_cmpeqsd:
17179 return getCmpIntrinsicCall(Intrinsic::x86_sse2_cmp_sd, 0);
17180 case X86::BI__builtin_ia32_cmpltsd:
17181 return getCmpIntrinsicCall(Intrinsic::x86_sse2_cmp_sd, 1);
17182 case X86::BI__builtin_ia32_cmplesd:
17183 return getCmpIntrinsicCall(Intrinsic::x86_sse2_cmp_sd, 2);
17184 case X86::BI__builtin_ia32_cmpunordsd:
17185 return getCmpIntrinsicCall(Intrinsic::x86_sse2_cmp_sd, 3);
17186 case X86::BI__builtin_ia32_cmpneqsd:
17187 return getCmpIntrinsicCall(Intrinsic::x86_sse2_cmp_sd, 4);
17188 case X86::BI__builtin_ia32_cmpnltsd:
17189 return getCmpIntrinsicCall(Intrinsic::x86_sse2_cmp_sd, 5);
17190 case X86::BI__builtin_ia32_cmpnlesd:
17191 return getCmpIntrinsicCall(Intrinsic::x86_sse2_cmp_sd, 6);
17192 case X86::BI__builtin_ia32_cmpordsd:
17193 return getCmpIntrinsicCall(Intrinsic::x86_sse2_cmp_sd, 7);
17196 case X86::BI__builtin_ia32_vcvtph2ps:
17197 case X86::BI__builtin_ia32_vcvtph2ps256:
17198 case X86::BI__builtin_ia32_vcvtph2ps_mask:
17199 case X86::BI__builtin_ia32_vcvtph2ps256_mask:
17200 case X86::BI__builtin_ia32_vcvtph2ps512_mask: {
17201 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*
this,
E);
17206 case X86::BI__builtin_ia32_cvtneps2bf16_128_mask: {
17209 cast<llvm::FixedVectorType>(Ops[0]->getType())->getNumElements());
17210 Intrinsic::ID IID = Intrinsic::x86_avx512bf16_mask_cvtneps2bf16_128;
17213 case X86::BI__builtin_ia32_cvtsbf162ss_32:
17216 case X86::BI__builtin_ia32_cvtneps2bf16_256_mask:
17217 case X86::BI__builtin_ia32_cvtneps2bf16_512_mask: {
17219 switch (BuiltinID) {
17220 default: llvm_unreachable(
"Unsupported intrinsic!");
17221 case X86::BI__builtin_ia32_cvtneps2bf16_256_mask:
17222 IID = Intrinsic::x86_avx512bf16_cvtneps2bf16_256;
17224 case X86::BI__builtin_ia32_cvtneps2bf16_512_mask:
17225 IID = Intrinsic::x86_avx512bf16_cvtneps2bf16_512;
17232 case X86::BI__cpuid:
17233 case X86::BI__cpuidex: {
17235 Value *SubFuncId = BuiltinID == X86::BI__cpuidex
17239 llvm::StructType *CpuidRetTy =
17241 llvm::FunctionType *FTy =
17244 StringRef
Asm, Constraints;
17245 if (
getTarget().getTriple().getArch() == llvm::Triple::x86) {
17247 Constraints =
"={ax},={bx},={cx},={dx},{ax},{cx}";
17250 Asm =
"xchgq %rbx, ${1:q}\n"
17252 "xchgq %rbx, ${1:q}";
17253 Constraints =
"={ax},=r,={cx},={dx},0,2";
17256 llvm::InlineAsm *IA = llvm::InlineAsm::get(FTy,
Asm, Constraints,
17258 Value *IACall =
Builder.CreateCall(IA, {FuncId, SubFuncId});
17261 for (
unsigned i = 0; i < 4; i++) {
17262 Value *Extracted =
Builder.CreateExtractValue(IACall, i);
17272 case X86::BI__emul:
17273 case X86::BI__emulu: {
17275 bool isSigned = (BuiltinID == X86::BI__emul);
17278 return Builder.CreateMul(LHS, RHS,
"", !isSigned, isSigned);
17280 case X86::BI__mulh:
17281 case X86::BI__umulh:
17282 case X86::BI_mul128:
17283 case X86::BI_umul128: {
17285 llvm::Type *Int128Ty = llvm::IntegerType::get(
getLLVMContext(), 128);
17287 bool IsSigned = (BuiltinID == X86::BI__mulh || BuiltinID == X86::BI_mul128);
17288 Value *LHS =
Builder.CreateIntCast(Ops[0], Int128Ty, IsSigned);
17289 Value *RHS =
Builder.CreateIntCast(Ops[1], Int128Ty, IsSigned);
17291 Value *MulResult, *HigherBits;
17293 MulResult =
Builder.CreateNSWMul(LHS, RHS);
17294 HigherBits =
Builder.CreateAShr(MulResult, 64);
17296 MulResult =
Builder.CreateNUWMul(LHS, RHS);
17297 HigherBits =
Builder.CreateLShr(MulResult, 64);
17299 HigherBits =
Builder.CreateIntCast(HigherBits, ResType, IsSigned);
17301 if (BuiltinID == X86::BI__mulh || BuiltinID == X86::BI__umulh)
17306 return Builder.CreateIntCast(MulResult, ResType, IsSigned);
17309 case X86::BI__faststorefence: {
17310 return Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent,
17311 llvm::SyncScope::System);
17313 case X86::BI__shiftleft128:
17314 case X86::BI__shiftright128: {
17316 BuiltinID == X86::BI__shiftleft128 ? Intrinsic::fshl : Intrinsic::fshr,
17321 std::swap(Ops[0], Ops[1]);
17323 return Builder.CreateCall(F, Ops);
17325 case X86::BI_ReadWriteBarrier:
17326 case X86::BI_ReadBarrier:
17327 case X86::BI_WriteBarrier: {
17328 return Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent,
17329 llvm::SyncScope::SingleThread);
17332 case X86::BI_AddressOfReturnAddress: {
17335 return Builder.CreateCall(F);
17337 case X86::BI__stosb: {
17343 case X86::BI__builtin_ia32_t2rpntlvwz0_internal:
17344 case X86::BI__builtin_ia32_t2rpntlvwz0rs_internal:
17345 case X86::BI__builtin_ia32_t2rpntlvwz0t1_internal:
17346 case X86::BI__builtin_ia32_t2rpntlvwz0rst1_internal:
17347 case X86::BI__builtin_ia32_t2rpntlvwz1_internal:
17348 case X86::BI__builtin_ia32_t2rpntlvwz1rs_internal:
17349 case X86::BI__builtin_ia32_t2rpntlvwz1t1_internal:
17350 case X86::BI__builtin_ia32_t2rpntlvwz1rst1_internal: {
17352 switch (BuiltinID) {
17354 llvm_unreachable(
"Unsupported intrinsic!");
17355 case X86::BI__builtin_ia32_t2rpntlvwz0_internal:
17356 IID = Intrinsic::x86_t2rpntlvwz0_internal;
17358 case X86::BI__builtin_ia32_t2rpntlvwz0rs_internal:
17359 IID = Intrinsic::x86_t2rpntlvwz0rs_internal;
17361 case X86::BI__builtin_ia32_t2rpntlvwz0t1_internal:
17362 IID = Intrinsic::x86_t2rpntlvwz0t1_internal;
17364 case X86::BI__builtin_ia32_t2rpntlvwz0rst1_internal:
17365 IID = Intrinsic::x86_t2rpntlvwz0rst1_internal;
17367 case X86::BI__builtin_ia32_t2rpntlvwz1_internal:
17368 IID = Intrinsic::x86_t2rpntlvwz1_internal;
17370 case X86::BI__builtin_ia32_t2rpntlvwz1rs_internal:
17371 IID = Intrinsic::x86_t2rpntlvwz1rs_internal;
17373 case X86::BI__builtin_ia32_t2rpntlvwz1t1_internal:
17374 IID = Intrinsic::x86_t2rpntlvwz1t1_internal;
17376 case X86::BI__builtin_ia32_t2rpntlvwz1rst1_internal:
17377 IID = Intrinsic::x86_t2rpntlvwz1rst1_internal;
17383 {Ops[0], Ops[1], Ops[2], Ops[5], Ops[6]});
17386 assert(PtrTy &&
"arg3 must be of pointer type");
17393 Value *VecT0 =
Builder.CreateIntrinsic(Intrinsic::x86_cast_tile_to_vector,
17399 Value *VecT1 =
Builder.CreateIntrinsic(Intrinsic::x86_cast_tile_to_vector,
17413 case X86::BI__int2c: {
17415 llvm::FunctionType *FTy = llvm::FunctionType::get(
VoidTy,
false);
17416 llvm::InlineAsm *IA =
17417 llvm::InlineAsm::get(FTy,
"int $$0x2c",
"",
true);
17418 llvm::AttributeList NoReturnAttr = llvm::AttributeList::get(
17420 llvm::Attribute::NoReturn);
17421 llvm::CallInst *CI =
Builder.CreateCall(IA);
17422 CI->setAttributes(NoReturnAttr);
17425 case X86::BI__readfsbyte:
17426 case X86::BI__readfsword:
17427 case X86::BI__readfsdword:
17428 case X86::BI__readfsqword: {
17434 Load->setVolatile(
true);
17437 case X86::BI__readgsbyte:
17438 case X86::BI__readgsword:
17439 case X86::BI__readgsdword:
17440 case X86::BI__readgsqword: {
17446 Load->setVolatile(
true);
17449 case X86::BI__builtin_ia32_encodekey128_u32: {
17450 Intrinsic::ID IID = Intrinsic::x86_encodekey128;
17454 for (
int i = 0; i < 3; ++i) {
17462 case X86::BI__builtin_ia32_encodekey256_u32: {
17463 Intrinsic::ID IID = Intrinsic::x86_encodekey256;
17468 for (
int i = 0; i < 4; ++i) {
17476 case X86::BI__builtin_ia32_aesenc128kl_u8:
17477 case X86::BI__builtin_ia32_aesdec128kl_u8:
17478 case X86::BI__builtin_ia32_aesenc256kl_u8:
17479 case X86::BI__builtin_ia32_aesdec256kl_u8: {
17481 StringRef BlockName;
17482 switch (BuiltinID) {
17484 llvm_unreachable(
"Unexpected builtin");
17485 case X86::BI__builtin_ia32_aesenc128kl_u8:
17486 IID = Intrinsic::x86_aesenc128kl;
17487 BlockName =
"aesenc128kl";
17489 case X86::BI__builtin_ia32_aesdec128kl_u8:
17490 IID = Intrinsic::x86_aesdec128kl;
17491 BlockName =
"aesdec128kl";
17493 case X86::BI__builtin_ia32_aesenc256kl_u8:
17494 IID = Intrinsic::x86_aesenc256kl;
17495 BlockName =
"aesenc256kl";
17497 case X86::BI__builtin_ia32_aesdec256kl_u8:
17498 IID = Intrinsic::x86_aesdec256kl;
17499 BlockName =
"aesdec256kl";
17505 BasicBlock *NoError =
17513 Builder.CreateCondBr(Succ, NoError, Error);
17515 Builder.SetInsertPoint(NoError);
17519 Builder.SetInsertPoint(Error);
17520 Constant *
Zero = llvm::Constant::getNullValue(Out->getType());
17527 case X86::BI__builtin_ia32_aesencwide128kl_u8:
17528 case X86::BI__builtin_ia32_aesdecwide128kl_u8:
17529 case X86::BI__builtin_ia32_aesencwide256kl_u8:
17530 case X86::BI__builtin_ia32_aesdecwide256kl_u8: {
17532 StringRef BlockName;
17533 switch (BuiltinID) {
17534 case X86::BI__builtin_ia32_aesencwide128kl_u8:
17535 IID = Intrinsic::x86_aesencwide128kl;
17536 BlockName =
"aesencwide128kl";
17538 case X86::BI__builtin_ia32_aesdecwide128kl_u8:
17539 IID = Intrinsic::x86_aesdecwide128kl;
17540 BlockName =
"aesdecwide128kl";
17542 case X86::BI__builtin_ia32_aesencwide256kl_u8:
17543 IID = Intrinsic::x86_aesencwide256kl;
17544 BlockName =
"aesencwide256kl";
17546 case X86::BI__builtin_ia32_aesdecwide256kl_u8:
17547 IID = Intrinsic::x86_aesdecwide256kl;
17548 BlockName =
"aesdecwide256kl";
17552 llvm::Type *Ty = FixedVectorType::get(
Builder.getInt64Ty(), 2);
17555 for (
int i = 0; i != 8; ++i) {
17556 Value *Ptr =
Builder.CreateConstGEP1_32(Ty, Ops[1], i);
17562 BasicBlock *NoError =
17569 Builder.CreateCondBr(Succ, NoError, Error);
17571 Builder.SetInsertPoint(NoError);
17572 for (
int i = 0; i != 8; ++i) {
17579 Builder.SetInsertPoint(Error);
17580 for (
int i = 0; i != 8; ++i) {
17582 Constant *
Zero = llvm::Constant::getNullValue(Out->getType());
17583 Value *Ptr =
Builder.CreateConstGEP1_32(Out->getType(), Ops[0], i);
17591 case X86::BI__builtin_ia32_vfcmaddcph512_mask:
17594 case X86::BI__builtin_ia32_vfmaddcph512_mask: {
17595 Intrinsic::ID IID = IsConjFMA
17596 ? Intrinsic::x86_avx512fp16_mask_vfcmadd_cph_512
17597 : Intrinsic::x86_avx512fp16_mask_vfmadd_cph_512;
17601 case X86::BI__builtin_ia32_vfcmaddcph256_round_mask:
17604 case X86::BI__builtin_ia32_vfmaddcph256_round_mask: {
17605 Intrinsic::ID IID = IsConjFMA ? Intrinsic::x86_avx10_mask_vfcmaddcph256
17606 : Intrinsic::x86_avx10_mask_vfmaddcph256;
17610 case X86::BI__builtin_ia32_vfcmaddcsh_round_mask:
17613 case X86::BI__builtin_ia32_vfmaddcsh_round_mask: {
17614 Intrinsic::ID IID = IsConjFMA ? Intrinsic::x86_avx512fp16_mask_vfcmadd_csh
17615 : Intrinsic::x86_avx512fp16_mask_vfmadd_csh;
17620 case X86::BI__builtin_ia32_vfcmaddcsh_round_mask3:
17623 case X86::BI__builtin_ia32_vfmaddcsh_round_mask3: {
17624 Intrinsic::ID IID = IsConjFMA ? Intrinsic::x86_avx512fp16_mask_vfcmadd_csh
17625 : Intrinsic::x86_avx512fp16_mask_vfmadd_csh;
17627 static constexpr int Mask[] = {0, 5, 6, 7};
17628 return Builder.CreateShuffleVector(
Call, Ops[2], Mask);
17630 case X86::BI__builtin_ia32_prefetchi:
17633 {Ops[0], llvm::ConstantInt::get(Int32Ty, 0), Ops[1],
17634 llvm::ConstantInt::get(Int32Ty, 0)});
17652 Intrinsic::ID
ID = Intrinsic::not_intrinsic;
17654#include "llvm/TargetParser/PPCTargetParser.def"
17655 auto GenAIXPPCBuiltinCpuExpr = [&](
unsigned SupportMethod,
unsigned FieldIdx,
17656 unsigned Mask, CmpInst::Predicate CompOp,
17657 unsigned OpValue) ->
Value * {
17658 if (SupportMethod == BUILTIN_PPC_FALSE)
17661 if (SupportMethod == BUILTIN_PPC_TRUE)
17664 assert(SupportMethod <= SYS_CALL &&
"Invalid value for SupportMethod.");
17666 llvm::Value *FieldValue =
nullptr;
17667 if (SupportMethod == USE_SYS_CONF) {
17668 llvm::Type *STy = llvm::StructType::get(PPC_SYSTEMCONFIG_TYPE);
17669 llvm::Constant *SysConf =
17673 llvm::Value *Idxs[] = {ConstantInt::get(
Int32Ty, 0),
17674 ConstantInt::get(
Int32Ty, FieldIdx)};
17679 }
else if (SupportMethod == SYS_CALL) {
17680 llvm::FunctionType *FTy =
17682 llvm::FunctionCallee
Func =
17688 assert(FieldValue &&
17689 "SupportMethod value is not defined in PPCTargetParser.def.");
17692 FieldValue =
Builder.CreateAnd(FieldValue, Mask);
17694 llvm::Type *ValueType = FieldValue->getType();
17695 bool IsValueType64Bit = ValueType->isIntegerTy(64);
17697 (IsValueType64Bit || ValueType->isIntegerTy(32)) &&
17698 "Only 32/64-bit integers are supported in GenAIXPPCBuiltinCpuExpr().");
17701 CompOp, FieldValue,
17702 ConstantInt::get(IsValueType64Bit ?
Int64Ty :
Int32Ty, OpValue));
17705 switch (BuiltinID) {
17706 default:
return nullptr;
17708 case Builtin::BI__builtin_cpu_is: {
17710 StringRef CPUStr = cast<clang::StringLiteral>(CPUExpr)->getString();
17713 unsigned LinuxSupportMethod, LinuxIDValue, AIXSupportMethod, AIXIDValue;
17714 typedef std::tuple<unsigned, unsigned, unsigned, unsigned>
CPUInfo;
17716 std::tie(LinuxSupportMethod, LinuxIDValue, AIXSupportMethod, AIXIDValue) =
17717 static_cast<CPUInfo>(StringSwitch<CPUInfo>(CPUStr)
17718#define PPC_CPU(NAME, Linux_SUPPORT_METHOD, LinuxID, AIX_SUPPORT_METHOD, \
17720 .Case(NAME, {Linux_SUPPORT_METHOD, LinuxID, AIX_SUPPORT_METHOD, AIXID})
17721#include "llvm/TargetParser/PPCTargetParser.def"
17722 .Default({BUILTIN_PPC_UNSUPPORTED, 0,
17723 BUILTIN_PPC_UNSUPPORTED, 0}));
17725 if (Triple.isOSAIX()) {
17726 assert((AIXSupportMethod != BUILTIN_PPC_UNSUPPORTED) &&
17727 "Invalid CPU name. Missed by SemaChecking?");
17728 return GenAIXPPCBuiltinCpuExpr(AIXSupportMethod, AIX_SYSCON_IMPL_IDX, 0,
17729 ICmpInst::ICMP_EQ, AIXIDValue);
17732 assert(Triple.isOSLinux() &&
17733 "__builtin_cpu_is() is only supported for AIX and Linux.");
17735 assert((LinuxSupportMethod != BUILTIN_PPC_UNSUPPORTED) &&
17736 "Invalid CPU name. Missed by SemaChecking?");
17738 if (LinuxSupportMethod == BUILTIN_PPC_FALSE)
17741 Value *Op0 = llvm::ConstantInt::get(
Int32Ty, PPC_FAWORD_CPUID);
17743 Value *TheCall =
Builder.CreateCall(F, {Op0},
"cpu_is");
17744 return Builder.CreateICmpEQ(TheCall,
17745 llvm::ConstantInt::get(
Int32Ty, LinuxIDValue));
17747 case Builtin::BI__builtin_cpu_supports: {
17750 StringRef CPUStr = cast<clang::StringLiteral>(CPUExpr)->getString();
17751 if (Triple.isOSAIX()) {
17752 unsigned SupportMethod, FieldIdx, Mask,
Value;
17753 CmpInst::Predicate CompOp;
17757 std::tie(SupportMethod, FieldIdx, Mask, CompOp,
Value) =
17758 static_cast<CPUSupportType
>(StringSwitch<CPUSupportType>(CPUStr)
17759#define PPC_AIX_FEATURE(NAME, DESC, SUPPORT_METHOD, INDEX, MASK, COMP_OP, \
17761 .Case(NAME, {SUPPORT_METHOD, INDEX, MASK, COMP_OP, VALUE})
17762#include "llvm/TargetParser/PPCTargetParser.def"
17763 .Default({BUILTIN_PPC_FALSE, 0, 0,
17764 CmpInst::Predicate(), 0}));
17765 return GenAIXPPCBuiltinCpuExpr(SupportMethod, FieldIdx, Mask, CompOp,
17769 assert(Triple.isOSLinux() &&
17770 "__builtin_cpu_supports() is only supported for AIX and Linux.");
17771 unsigned FeatureWord;
17773 std::tie(FeatureWord, BitMask) =
17774 StringSwitch<std::pair<unsigned, unsigned>>(CPUStr)
17775#define
PPC_LNX_FEATURE(Name, Description, EnumName, Bitmask, FA_WORD) \
17776 .Case(Name, {FA_WORD, Bitmask})
17777#include
"llvm/TargetParser/PPCTargetParser.def"
17781 Value *Op0 = llvm::ConstantInt::get(
Int32Ty, FeatureWord);
17783 Value *TheCall =
Builder.CreateCall(F, {Op0},
"cpu_supports");
17785 Builder.CreateAnd(TheCall, llvm::ConstantInt::get(
Int32Ty, BitMask));
17786 return Builder.CreateICmpNE(Mask, llvm::Constant::getNullValue(
Int32Ty));
17787#undef PPC_FAWORD_HWCAP
17788#undef PPC_FAWORD_HWCAP2
17789#undef PPC_FAWORD_CPUID
17794 case PPC::BI__builtin_ppc_get_timebase:
17798 case PPC::BI__builtin_altivec_lvx:
17799 case PPC::BI__builtin_altivec_lvxl:
17800 case PPC::BI__builtin_altivec_lvebx:
17801 case PPC::BI__builtin_altivec_lvehx:
17802 case PPC::BI__builtin_altivec_lvewx:
17803 case PPC::BI__builtin_altivec_lvsl:
17804 case PPC::BI__builtin_altivec_lvsr:
17805 case PPC::BI__builtin_vsx_lxvd2x:
17806 case PPC::BI__builtin_vsx_lxvw4x:
17807 case PPC::BI__builtin_vsx_lxvd2x_be:
17808 case PPC::BI__builtin_vsx_lxvw4x_be:
17809 case PPC::BI__builtin_vsx_lxvl:
17810 case PPC::BI__builtin_vsx_lxvll:
17815 if (!(BuiltinID == PPC::BI__builtin_vsx_lxvl ||
17816 BuiltinID == PPC::BI__builtin_vsx_lxvll)) {
17821 switch (BuiltinID) {
17822 default: llvm_unreachable(
"Unsupported ld/lvsl/lvsr intrinsic!");
17823 case PPC::BI__builtin_altivec_lvx:
17824 ID = Intrinsic::ppc_altivec_lvx;
17826 case PPC::BI__builtin_altivec_lvxl:
17827 ID = Intrinsic::ppc_altivec_lvxl;
17829 case PPC::BI__builtin_altivec_lvebx:
17830 ID = Intrinsic::ppc_altivec_lvebx;
17832 case PPC::BI__builtin_altivec_lvehx:
17833 ID = Intrinsic::ppc_altivec_lvehx;
17835 case PPC::BI__builtin_altivec_lvewx:
17836 ID = Intrinsic::ppc_altivec_lvewx;
17838 case PPC::BI__builtin_altivec_lvsl:
17839 ID = Intrinsic::ppc_altivec_lvsl;
17841 case PPC::BI__builtin_altivec_lvsr:
17842 ID = Intrinsic::ppc_altivec_lvsr;
17844 case PPC::BI__builtin_vsx_lxvd2x:
17845 ID = Intrinsic::ppc_vsx_lxvd2x;
17847 case PPC::BI__builtin_vsx_lxvw4x:
17848 ID = Intrinsic::ppc_vsx_lxvw4x;
17850 case PPC::BI__builtin_vsx_lxvd2x_be:
17851 ID = Intrinsic::ppc_vsx_lxvd2x_be;
17853 case PPC::BI__builtin_vsx_lxvw4x_be:
17854 ID = Intrinsic::ppc_vsx_lxvw4x_be;
17856 case PPC::BI__builtin_vsx_lxvl:
17857 ID = Intrinsic::ppc_vsx_lxvl;
17859 case PPC::BI__builtin_vsx_lxvll:
17860 ID = Intrinsic::ppc_vsx_lxvll;
17864 return Builder.CreateCall(F, Ops,
"");
17868 case PPC::BI__builtin_altivec_stvx:
17869 case PPC::BI__builtin_altivec_stvxl:
17870 case PPC::BI__builtin_altivec_stvebx:
17871 case PPC::BI__builtin_altivec_stvehx:
17872 case PPC::BI__builtin_altivec_stvewx:
17873 case PPC::BI__builtin_vsx_stxvd2x:
17874 case PPC::BI__builtin_vsx_stxvw4x:
17875 case PPC::BI__builtin_vsx_stxvd2x_be:
17876 case PPC::BI__builtin_vsx_stxvw4x_be:
17877 case PPC::BI__builtin_vsx_stxvl:
17878 case PPC::BI__builtin_vsx_stxvll:
17884 if (!(BuiltinID == PPC::BI__builtin_vsx_stxvl ||
17885 BuiltinID == PPC::BI__builtin_vsx_stxvll)) {
17890 switch (BuiltinID) {
17891 default: llvm_unreachable(
"Unsupported st intrinsic!");
17892 case PPC::BI__builtin_altivec_stvx:
17893 ID = Intrinsic::ppc_altivec_stvx;
17895 case PPC::BI__builtin_altivec_stvxl:
17896 ID = Intrinsic::ppc_altivec_stvxl;
17898 case PPC::BI__builtin_altivec_stvebx:
17899 ID = Intrinsic::ppc_altivec_stvebx;
17901 case PPC::BI__builtin_altivec_stvehx:
17902 ID = Intrinsic::ppc_altivec_stvehx;
17904 case PPC::BI__builtin_altivec_stvewx:
17905 ID = Intrinsic::ppc_altivec_stvewx;
17907 case PPC::BI__builtin_vsx_stxvd2x:
17908 ID = Intrinsic::ppc_vsx_stxvd2x;
17910 case PPC::BI__builtin_vsx_stxvw4x:
17911 ID = Intrinsic::ppc_vsx_stxvw4x;
17913 case PPC::BI__builtin_vsx_stxvd2x_be:
17914 ID = Intrinsic::ppc_vsx_stxvd2x_be;
17916 case PPC::BI__builtin_vsx_stxvw4x_be:
17917 ID = Intrinsic::ppc_vsx_stxvw4x_be;
17919 case PPC::BI__builtin_vsx_stxvl:
17920 ID = Intrinsic::ppc_vsx_stxvl;
17922 case PPC::BI__builtin_vsx_stxvll:
17923 ID = Intrinsic::ppc_vsx_stxvll;
17927 return Builder.CreateCall(F, Ops,
"");
17929 case PPC::BI__builtin_vsx_ldrmb: {
17935 int64_t NumBytes = cast<ConstantInt>(Op1)->getZExtValue();
17940 if (NumBytes == 16) {
17948 for (
int Idx = 0; Idx < 16; Idx++)
17949 RevMask.push_back(15 - Idx);
17950 return Builder.CreateShuffleVector(LD, LD, RevMask);
17954 llvm::Function *Lvs =
CGM.
getIntrinsic(IsLE ? Intrinsic::ppc_altivec_lvsr
17955 : Intrinsic::ppc_altivec_lvsl);
17956 llvm::Function *Vperm =
CGM.
getIntrinsic(Intrinsic::ppc_altivec_vperm);
17958 Int8Ty, Op0, ConstantInt::get(Op1->
getType(), NumBytes - 1));
17960 Value *HiLd =
Builder.CreateCall(Lvx, HiMem,
"ld.hi");
17963 Op0 = IsLE ? HiLd : LoLd;
17964 Op1 = IsLE ? LoLd : HiLd;
17965 Value *AllElts =
Builder.CreateCall(Vperm, {Op0, Op1, Mask1},
"shuffle1");
17966 Constant *
Zero = llvm::Constant::getNullValue(IsLE ? ResTy : AllElts->
getType());
17970 for (
int Idx = 0; Idx < 16; Idx++) {
17971 int Val = (NumBytes - Idx - 1 >= 0) ? (NumBytes - Idx - 1)
17972 : 16 - (NumBytes - Idx);
17973 Consts.push_back(Val);
17975 return Builder.CreateShuffleVector(
Builder.CreateBitCast(AllElts, ResTy),
17979 for (
int Idx = 0; Idx < 16; Idx++)
17980 Consts.push_back(
Builder.getInt8(NumBytes + Idx));
17981 Value *Mask2 = ConstantVector::get(Consts);
17982 return Builder.CreateBitCast(
17983 Builder.CreateCall(Vperm, {Zero, AllElts, Mask2},
"shuffle2"), ResTy);
17985 case PPC::BI__builtin_vsx_strmb: {
17989 int64_t NumBytes = cast<ConstantInt>(Op1)->getZExtValue();
17991 auto StoreSubVec = [&](
unsigned Width,
unsigned Offset,
unsigned EltNo) {
17995 Value *StVec = Op2;
17998 for (
int Idx = 0; Idx < 16; Idx++)
17999 RevMask.push_back(15 - Idx);
18000 StVec =
Builder.CreateShuffleVector(Op2, Op2, RevMask);
18006 unsigned NumElts = 0;
18009 llvm_unreachable(
"width for stores must be a power of 2");
18028 Op2, llvm::FixedVectorType::get(ConvTy, NumElts));
18031 Value *Elt =
Builder.CreateExtractElement(Vec, EltNo);
18032 if (IsLE && Width > 1) {
18034 Elt =
Builder.CreateCall(F, Elt);
18039 unsigned Stored = 0;
18040 unsigned RemainingBytes = NumBytes;
18042 if (NumBytes == 16)
18043 return StoreSubVec(16, 0, 0);
18044 if (NumBytes >= 8) {
18045 Result = StoreSubVec(8, NumBytes - 8, IsLE ? 0 : 1);
18046 RemainingBytes -= 8;
18049 if (RemainingBytes >= 4) {
18050 Result = StoreSubVec(4, NumBytes - Stored - 4,
18051 IsLE ? (Stored >> 2) : 3 - (Stored >> 2));
18052 RemainingBytes -= 4;
18055 if (RemainingBytes >= 2) {
18056 Result = StoreSubVec(2, NumBytes - Stored - 2,
18057 IsLE ? (Stored >> 1) : 7 - (Stored >> 1));
18058 RemainingBytes -= 2;
18061 if (RemainingBytes)
18063 StoreSubVec(1, NumBytes - Stored - 1, IsLE ? Stored : 15 - Stored);
18067 case PPC::BI__builtin_vsx_xvsqrtsp:
18068 case PPC::BI__builtin_vsx_xvsqrtdp: {
18071 if (
Builder.getIsFPConstrained()) {
18073 Intrinsic::experimental_constrained_sqrt, ResultType);
18074 return Builder.CreateConstrainedFPCall(F,
X);
18081 case PPC::BI__builtin_altivec_vclzb:
18082 case PPC::BI__builtin_altivec_vclzh:
18083 case PPC::BI__builtin_altivec_vclzw:
18084 case PPC::BI__builtin_altivec_vclzd: {
18087 Value *Undef = ConstantInt::get(
Builder.getInt1Ty(),
false);
18089 return Builder.CreateCall(F, {
X, Undef});
18091 case PPC::BI__builtin_altivec_vctzb:
18092 case PPC::BI__builtin_altivec_vctzh:
18093 case PPC::BI__builtin_altivec_vctzw:
18094 case PPC::BI__builtin_altivec_vctzd: {
18097 Value *Undef = ConstantInt::get(
Builder.getInt1Ty(),
false);
18099 return Builder.CreateCall(F, {
X, Undef});
18101 case PPC::BI__builtin_altivec_vinsd:
18102 case PPC::BI__builtin_altivec_vinsw:
18103 case PPC::BI__builtin_altivec_vinsd_elt:
18104 case PPC::BI__builtin_altivec_vinsw_elt: {
18110 bool IsUnaligned = (BuiltinID == PPC::BI__builtin_altivec_vinsw ||
18111 BuiltinID == PPC::BI__builtin_altivec_vinsd);
18113 bool Is32bit = (BuiltinID == PPC::BI__builtin_altivec_vinsw ||
18114 BuiltinID == PPC::BI__builtin_altivec_vinsw_elt);
18117 ConstantInt *ArgCI = dyn_cast<ConstantInt>(Op2);
18119 "Third Arg to vinsw/vinsd intrinsic must be a constant integer!");
18123 int ValidMaxValue = 0;
18125 ValidMaxValue = (Is32bit) ? 12 : 8;
18127 ValidMaxValue = (Is32bit) ? 3 : 1;
18130 int64_t ConstArg = ArgCI->getSExtValue();
18133 std::string RangeErrMsg = IsUnaligned ?
"byte" :
"element";
18134 RangeErrMsg +=
" number " + llvm::to_string(ConstArg);
18135 RangeErrMsg +=
" is outside of the valid range [0, ";
18136 RangeErrMsg += llvm::to_string(ValidMaxValue) +
"]";
18139 if (ConstArg < 0 || ConstArg > ValidMaxValue)
18143 if (!IsUnaligned) {
18144 ConstArg *= Is32bit ? 4 : 8;
18147 ConstArg = (Is32bit ? 12 : 8) - ConstArg;
18150 ID = Is32bit ? Intrinsic::ppc_altivec_vinsw : Intrinsic::ppc_altivec_vinsd;
18151 Op2 = ConstantInt::getSigned(
Int32Ty, ConstArg);
18155 ?
Builder.CreateBitCast(Op0, llvm::FixedVectorType::get(
Int32Ty, 4))
18157 llvm::FixedVectorType::get(
Int64Ty, 2));
18158 return Builder.CreateBitCast(
18161 case PPC::BI__builtin_altivec_vadduqm:
18162 case PPC::BI__builtin_altivec_vsubuqm: {
18165 llvm::Type *Int128Ty = llvm::IntegerType::get(
getLLVMContext(), 128);
18166 Op0 =
Builder.CreateBitCast(Op0, llvm::FixedVectorType::get(Int128Ty, 1));
18167 Op1 =
Builder.CreateBitCast(Op1, llvm::FixedVectorType::get(Int128Ty, 1));
18168 if (BuiltinID == PPC::BI__builtin_altivec_vadduqm)
18169 return Builder.CreateAdd(Op0, Op1,
"vadduqm");
18171 return Builder.CreateSub(Op0, Op1,
"vsubuqm");
18173 case PPC::BI__builtin_altivec_vaddcuq_c:
18174 case PPC::BI__builtin_altivec_vsubcuq_c: {
18178 llvm::Type *V1I128Ty = llvm::FixedVectorType::get(
18180 Ops.push_back(
Builder.CreateBitCast(Op0, V1I128Ty));
18181 Ops.push_back(
Builder.CreateBitCast(Op1, V1I128Ty));
18182 ID = (BuiltinID == PPC::BI__builtin_altivec_vaddcuq_c)
18183 ? Intrinsic::ppc_altivec_vaddcuq
18184 : Intrinsic::ppc_altivec_vsubcuq;
18187 case PPC::BI__builtin_altivec_vaddeuqm_c:
18188 case PPC::BI__builtin_altivec_vaddecuq_c:
18189 case PPC::BI__builtin_altivec_vsubeuqm_c:
18190 case PPC::BI__builtin_altivec_vsubecuq_c: {
18195 llvm::Type *V1I128Ty = llvm::FixedVectorType::get(
18197 Ops.push_back(
Builder.CreateBitCast(Op0, V1I128Ty));
18198 Ops.push_back(
Builder.CreateBitCast(Op1, V1I128Ty));
18199 Ops.push_back(
Builder.CreateBitCast(Op2, V1I128Ty));
18200 switch (BuiltinID) {
18202 llvm_unreachable(
"Unsupported intrinsic!");
18203 case PPC::BI__builtin_altivec_vaddeuqm_c:
18204 ID = Intrinsic::ppc_altivec_vaddeuqm;
18206 case PPC::BI__builtin_altivec_vaddecuq_c:
18207 ID = Intrinsic::ppc_altivec_vaddecuq;
18209 case PPC::BI__builtin_altivec_vsubeuqm_c:
18210 ID = Intrinsic::ppc_altivec_vsubeuqm;
18212 case PPC::BI__builtin_altivec_vsubecuq_c:
18213 ID = Intrinsic::ppc_altivec_vsubecuq;
18218 case PPC::BI__builtin_ppc_rldimi:
18219 case PPC::BI__builtin_ppc_rlwimi: {
18226 if (BuiltinID == PPC::BI__builtin_ppc_rldimi &&
18236 ? Intrinsic::ppc_rldimi
18237 : Intrinsic::ppc_rlwimi),
18238 {Op0, Op1, Op2, Op3});
18240 case PPC::BI__builtin_ppc_rlwnm: {
18247 case PPC::BI__builtin_ppc_poppar4:
18248 case PPC::BI__builtin_ppc_poppar8: {
18250 llvm::Type *ArgType = Op0->
getType();
18256 if (
Result->getType() != ResultType)
18261 case PPC::BI__builtin_ppc_cmpb: {
18264 if (
getTarget().getTriple().isPPC64()) {
18267 return Builder.CreateCall(F, {Op0, Op1},
"cmpb");
18287 Constant *ShiftAmt = ConstantInt::get(
Int64Ty, 32);
18296 Value *ResHi =
Builder.CreateShl(ResHiShift, ShiftAmt);
18297 return Builder.CreateOr(ResLo, ResHi);
18300 case PPC::BI__builtin_vsx_xvcpsgnsp:
18301 case PPC::BI__builtin_vsx_xvcpsgndp: {
18305 ID = Intrinsic::copysign;
18307 return Builder.CreateCall(F, {
X, Y});
18310 case PPC::BI__builtin_vsx_xvrspip:
18311 case PPC::BI__builtin_vsx_xvrdpip:
18312 case PPC::BI__builtin_vsx_xvrdpim:
18313 case PPC::BI__builtin_vsx_xvrspim:
18314 case PPC::BI__builtin_vsx_xvrdpi:
18315 case PPC::BI__builtin_vsx_xvrspi:
18316 case PPC::BI__builtin_vsx_xvrdpic:
18317 case PPC::BI__builtin_vsx_xvrspic:
18318 case PPC::BI__builtin_vsx_xvrdpiz:
18319 case PPC::BI__builtin_vsx_xvrspiz: {
18322 if (BuiltinID == PPC::BI__builtin_vsx_xvrdpim ||
18323 BuiltinID == PPC::BI__builtin_vsx_xvrspim)
18325 ? Intrinsic::experimental_constrained_floor
18326 : Intrinsic::floor;
18327 else if (BuiltinID == PPC::BI__builtin_vsx_xvrdpi ||
18328 BuiltinID == PPC::BI__builtin_vsx_xvrspi)
18330 ? Intrinsic::experimental_constrained_round
18331 : Intrinsic::round;
18332 else if (BuiltinID == PPC::BI__builtin_vsx_xvrdpic ||
18333 BuiltinID == PPC::BI__builtin_vsx_xvrspic)
18335 ? Intrinsic::experimental_constrained_rint
18337 else if (BuiltinID == PPC::BI__builtin_vsx_xvrdpip ||
18338 BuiltinID == PPC::BI__builtin_vsx_xvrspip)
18340 ? Intrinsic::experimental_constrained_ceil
18342 else if (BuiltinID == PPC::BI__builtin_vsx_xvrdpiz ||
18343 BuiltinID == PPC::BI__builtin_vsx_xvrspiz)
18345 ? Intrinsic::experimental_constrained_trunc
18346 : Intrinsic::trunc;
18348 return Builder.getIsFPConstrained() ?
Builder.CreateConstrainedFPCall(F,
X)
18353 case PPC::BI__builtin_vsx_xvabsdp:
18354 case PPC::BI__builtin_vsx_xvabssp: {
18362 case PPC::BI__builtin_ppc_recipdivf:
18363 case PPC::BI__builtin_ppc_recipdivd:
18364 case PPC::BI__builtin_ppc_rsqrtf:
18365 case PPC::BI__builtin_ppc_rsqrtd: {
18366 FastMathFlags FMF =
Builder.getFastMathFlags();
18367 Builder.getFastMathFlags().setFast();
18371 if (BuiltinID == PPC::BI__builtin_ppc_recipdivf ||
18372 BuiltinID == PPC::BI__builtin_ppc_recipdivd) {
18375 Builder.getFastMathFlags() &= (FMF);
18378 auto *One = ConstantFP::get(ResultType, 1.0);
18381 Builder.getFastMathFlags() &= (FMF);
18384 case PPC::BI__builtin_ppc_alignx: {
18387 ConstantInt *AlignmentCI = cast<ConstantInt>(Op0);
18388 if (AlignmentCI->getValue().ugt(llvm::Value::MaximumAlignment))
18389 AlignmentCI = ConstantInt::get(AlignmentCI->getIntegerType(),
18390 llvm::Value::MaximumAlignment);
18394 AlignmentCI,
nullptr);
18397 case PPC::BI__builtin_ppc_rdlam: {
18401 llvm::Type *Ty = Op0->
getType();
18402 Value *ShiftAmt =
Builder.CreateIntCast(Op1, Ty,
false);
18404 Value *Rotate =
Builder.CreateCall(F, {Op0, Op0, ShiftAmt});
18405 return Builder.CreateAnd(Rotate, Op2);
18407 case PPC::BI__builtin_ppc_load2r: {
18414 case PPC::BI__builtin_ppc_fnmsub:
18415 case PPC::BI__builtin_ppc_fnmsubs:
18416 case PPC::BI__builtin_vsx_xvmaddadp:
18417 case PPC::BI__builtin_vsx_xvmaddasp:
18418 case PPC::BI__builtin_vsx_xvnmaddadp:
18419 case PPC::BI__builtin_vsx_xvnmaddasp:
18420 case PPC::BI__builtin_vsx_xvmsubadp:
18421 case PPC::BI__builtin_vsx_xvmsubasp:
18422 case PPC::BI__builtin_vsx_xvnmsubadp:
18423 case PPC::BI__builtin_vsx_xvnmsubasp: {
18429 if (
Builder.getIsFPConstrained())
18430 F =
CGM.
getIntrinsic(Intrinsic::experimental_constrained_fma, ResultType);
18433 switch (BuiltinID) {
18434 case PPC::BI__builtin_vsx_xvmaddadp:
18435 case PPC::BI__builtin_vsx_xvmaddasp:
18436 if (
Builder.getIsFPConstrained())
18437 return Builder.CreateConstrainedFPCall(F, {
X, Y, Z});
18439 return Builder.CreateCall(F, {
X, Y, Z});
18440 case PPC::BI__builtin_vsx_xvnmaddadp:
18441 case PPC::BI__builtin_vsx_xvnmaddasp:
18442 if (
Builder.getIsFPConstrained())
18444 Builder.CreateConstrainedFPCall(F, {X, Y, Z}),
"neg");
18446 return Builder.CreateFNeg(
Builder.CreateCall(F, {X, Y, Z}),
"neg");
18447 case PPC::BI__builtin_vsx_xvmsubadp:
18448 case PPC::BI__builtin_vsx_xvmsubasp:
18449 if (
Builder.getIsFPConstrained())
18450 return Builder.CreateConstrainedFPCall(
18451 F, {
X, Y,
Builder.CreateFNeg(Z,
"neg")});
18454 case PPC::BI__builtin_ppc_fnmsub:
18455 case PPC::BI__builtin_ppc_fnmsubs:
18456 case PPC::BI__builtin_vsx_xvnmsubadp:
18457 case PPC::BI__builtin_vsx_xvnmsubasp:
18458 if (
Builder.getIsFPConstrained())
18460 Builder.CreateConstrainedFPCall(
18461 F, {X, Y, Builder.CreateFNeg(Z,
"neg")}),
18467 llvm_unreachable(
"Unknown FMA operation");
18471 case PPC::BI__builtin_vsx_insertword: {
18479 ConstantInt *ArgCI = dyn_cast<ConstantInt>(Op2);
18481 "Third arg to xxinsertw intrinsic must be constant integer");
18483 int64_t Index = std::clamp(ArgCI->getSExtValue(), (int64_t)0, MaxIndex);
18490 std::swap(Op0, Op1);
18494 Op1 =
Builder.CreateBitCast(Op1, llvm::FixedVectorType::get(
Int64Ty, 2));
18498 Op0 =
Builder.CreateBitCast(Op0, llvm::FixedVectorType::get(
Int64Ty, 2));
18502 Index = MaxIndex - Index;
18506 Op0 =
Builder.CreateBitCast(Op0, llvm::FixedVectorType::get(
Int32Ty, 4));
18507 Op2 = ConstantInt::getSigned(
Int32Ty, Index);
18508 return Builder.CreateCall(F, {Op0, Op1, Op2});
18511 case PPC::BI__builtin_vsx_extractuword: {
18514 llvm::Function *F =
CGM.
getIntrinsic(Intrinsic::ppc_vsx_xxextractuw);
18517 Op0 =
Builder.CreateBitCast(Op0, llvm::FixedVectorType::get(
Int64Ty, 2));
18521 ConstantInt *ArgCI = dyn_cast<ConstantInt>(Op1);
18523 "Second Arg to xxextractuw intrinsic must be a constant integer!");
18525 int64_t Index = std::clamp(ArgCI->getSExtValue(), (int64_t)0, MaxIndex);
18529 Index = MaxIndex - Index;
18530 Op1 = ConstantInt::getSigned(
Int32Ty, Index);
18535 Value *ShuffleCall =
18537 return ShuffleCall;
18539 Op1 = ConstantInt::getSigned(
Int32Ty, Index);
18540 return Builder.CreateCall(F, {Op0, Op1});
18544 case PPC::BI__builtin_vsx_xxpermdi: {
18548 ConstantInt *ArgCI = dyn_cast<ConstantInt>(Op2);
18549 assert(ArgCI &&
"Third arg must be constant integer!");
18551 unsigned Index = ArgCI->getZExtValue();
18552 Op0 =
Builder.CreateBitCast(Op0, llvm::FixedVectorType::get(
Int64Ty, 2));
18553 Op1 =
Builder.CreateBitCast(Op1, llvm::FixedVectorType::get(
Int64Ty, 2));
18558 int ElemIdx0 = (Index & 2) >> 1;
18559 int ElemIdx1 = 2 + (Index & 1);
18561 int ShuffleElts[2] = {ElemIdx0, ElemIdx1};
18562 Value *ShuffleCall =
Builder.CreateShuffleVector(Op0, Op1, ShuffleElts);
18565 return Builder.CreateBitCast(ShuffleCall, RetTy);
18568 case PPC::BI__builtin_vsx_xxsldwi: {
18572 ConstantInt *ArgCI = dyn_cast<ConstantInt>(Op2);
18573 assert(ArgCI &&
"Third argument must be a compile time constant");
18574 unsigned Index = ArgCI->getZExtValue() & 0x3;
18575 Op0 =
Builder.CreateBitCast(Op0, llvm::FixedVectorType::get(
Int32Ty, 4));
18576 Op1 =
Builder.CreateBitCast(Op1, llvm::FixedVectorType::get(
Int32Ty, 4));
18587 ElemIdx0 = (8 - Index) % 8;
18588 ElemIdx1 = (9 - Index) % 8;
18589 ElemIdx2 = (10 - Index) % 8;
18590 ElemIdx3 = (11 - Index) % 8;
18594 ElemIdx1 = Index + 1;
18595 ElemIdx2 = Index + 2;
18596 ElemIdx3 = Index + 3;
18599 int ShuffleElts[4] = {ElemIdx0, ElemIdx1, ElemIdx2, ElemIdx3};
18600 Value *ShuffleCall =
Builder.CreateShuffleVector(Op0, Op1, ShuffleElts);
18603 return Builder.CreateBitCast(ShuffleCall, RetTy);
18606 case PPC::BI__builtin_pack_vector_int128: {
18610 Value *PoisonValue =
18611 llvm::PoisonValue::get(llvm::FixedVectorType::get(Op0->
getType(), 2));
18613 PoisonValue, Op0, (uint64_t)(isLittleEndian ? 1 : 0));
18614 Res =
Builder.CreateInsertElement(Res, Op1,
18615 (uint64_t)(isLittleEndian ? 0 : 1));
18619 case PPC::BI__builtin_unpack_vector_int128: {
18622 ConstantInt *Index = cast<ConstantInt>(Op1);
18628 ConstantInt::get(Index->getIntegerType(), 1 - Index->getZExtValue());
18630 return Builder.CreateExtractElement(Unpacked, Index);
18633 case PPC::BI__builtin_ppc_sthcx: {
18637 return Builder.CreateCall(F, {Op0, Op1});
18646#define CUSTOM_BUILTIN(Name, Intr, Types, Accumulate, Feature) \
18647 case PPC::BI__builtin_##Name:
18648#include "clang/Basic/BuiltinsPPC.def"
18651 for (
unsigned i = 0, e =
E->getNumArgs(); i != e; i++)
18661 if (BuiltinID == PPC::BI__builtin_mma_disassemble_acc ||
18662 BuiltinID == PPC::BI__builtin_vsx_disassemble_pair ||
18663 BuiltinID == PPC::BI__builtin_mma_disassemble_pair) {
18664 unsigned NumVecs = 2;
18665 auto Intrinsic = Intrinsic::ppc_vsx_disassemble_pair;
18666 if (BuiltinID == PPC::BI__builtin_mma_disassemble_acc) {
18668 Intrinsic = Intrinsic::ppc_mma_disassemble_acc;
18674 llvm::Type *VTy = llvm::FixedVectorType::get(
Int8Ty, 16);
18675 Value *Ptr = Ops[0];
18676 for (
unsigned i=0; i<NumVecs; i++) {
18678 llvm::ConstantInt* Index = llvm::ConstantInt::get(
IntTy, i);
18684 if (BuiltinID == PPC::BI__builtin_vsx_build_pair ||
18685 BuiltinID == PPC::BI__builtin_mma_build_acc) {
18693 std::reverse(Ops.begin() + 1, Ops.end());
18696 switch (BuiltinID) {
18697 #define CUSTOM_BUILTIN(Name, Intr, Types, Acc, Feature) \
18698 case PPC::BI__builtin_##Name: \
18699 ID = Intrinsic::ppc_##Intr; \
18700 Accumulate = Acc; \
18702 #include "clang/Basic/BuiltinsPPC.def"
18704 if (BuiltinID == PPC::BI__builtin_vsx_lxvp ||
18705 BuiltinID == PPC::BI__builtin_vsx_stxvp ||
18706 BuiltinID == PPC::BI__builtin_mma_lxvp ||
18707 BuiltinID == PPC::BI__builtin_mma_stxvp) {
18708 if (BuiltinID == PPC::BI__builtin_vsx_lxvp ||
18709 BuiltinID == PPC::BI__builtin_mma_lxvp) {
18716 return Builder.CreateCall(F, Ops,
"");
18722 CallOps.push_back(Acc);
18724 for (
unsigned i=1; i<Ops.size(); i++)
18725 CallOps.push_back(Ops[i]);
18731 case PPC::BI__builtin_ppc_compare_and_swap:
18732 case PPC::BI__builtin_ppc_compare_and_swaplp: {
18741 llvm::AtomicOrdering::Monotonic, llvm::AtomicOrdering::Monotonic,
true);
18749 Value *LoadedVal = Pair.first.getScalarVal();
18753 case PPC::BI__builtin_ppc_fetch_and_add:
18754 case PPC::BI__builtin_ppc_fetch_and_addlp: {
18756 llvm::AtomicOrdering::Monotonic);
18758 case PPC::BI__builtin_ppc_fetch_and_and:
18759 case PPC::BI__builtin_ppc_fetch_and_andlp: {
18761 llvm::AtomicOrdering::Monotonic);
18764 case PPC::BI__builtin_ppc_fetch_and_or:
18765 case PPC::BI__builtin_ppc_fetch_and_orlp: {
18767 llvm::AtomicOrdering::Monotonic);
18769 case PPC::BI__builtin_ppc_fetch_and_swap:
18770 case PPC::BI__builtin_ppc_fetch_and_swaplp: {
18772 llvm::AtomicOrdering::Monotonic);
18774 case PPC::BI__builtin_ppc_ldarx:
18775 case PPC::BI__builtin_ppc_lwarx:
18776 case PPC::BI__builtin_ppc_lharx:
18777 case PPC::BI__builtin_ppc_lbarx:
18779 case PPC::BI__builtin_ppc_mfspr: {
18785 return Builder.CreateCall(F, {Op0});
18787 case PPC::BI__builtin_ppc_mtspr: {
18794 return Builder.CreateCall(F, {Op0, Op1});
18796 case PPC::BI__builtin_ppc_popcntb: {
18798 llvm::Type *ArgType = ArgValue->
getType();
18800 return Builder.CreateCall(F, {ArgValue},
"popcntb");
18802 case PPC::BI__builtin_ppc_mtfsf: {
18812 case PPC::BI__builtin_ppc_swdiv_nochk:
18813 case PPC::BI__builtin_ppc_swdivs_nochk: {
18816 FastMathFlags FMF =
Builder.getFastMathFlags();
18817 Builder.getFastMathFlags().setFast();
18818 Value *FDiv =
Builder.CreateFDiv(Op0, Op1,
"swdiv_nochk");
18819 Builder.getFastMathFlags() &= (FMF);
18822 case PPC::BI__builtin_ppc_fric:
18824 *
this,
E, Intrinsic::rint,
18825 Intrinsic::experimental_constrained_rint))
18827 case PPC::BI__builtin_ppc_frim:
18828 case PPC::BI__builtin_ppc_frims:
18830 *
this,
E, Intrinsic::floor,
18831 Intrinsic::experimental_constrained_floor))
18833 case PPC::BI__builtin_ppc_frin:
18834 case PPC::BI__builtin_ppc_frins:
18836 *
this,
E, Intrinsic::round,
18837 Intrinsic::experimental_constrained_round))
18839 case PPC::BI__builtin_ppc_frip:
18840 case PPC::BI__builtin_ppc_frips:
18842 *
this,
E, Intrinsic::ceil,
18843 Intrinsic::experimental_constrained_ceil))
18845 case PPC::BI__builtin_ppc_friz:
18846 case PPC::BI__builtin_ppc_frizs:
18848 *
this,
E, Intrinsic::trunc,
18849 Intrinsic::experimental_constrained_trunc))
18851 case PPC::BI__builtin_ppc_fsqrt:
18852 case PPC::BI__builtin_ppc_fsqrts:
18854 *
this,
E, Intrinsic::sqrt,
18855 Intrinsic::experimental_constrained_sqrt))
18857 case PPC::BI__builtin_ppc_test_data_class: {
18862 {Op0, Op1},
"test_data_class");
18864 case PPC::BI__builtin_ppc_maxfe: {
18870 {Op0, Op1, Op2, Op3});
18872 case PPC::BI__builtin_ppc_maxfl: {
18878 {Op0, Op1, Op2, Op3});
18880 case PPC::BI__builtin_ppc_maxfs: {
18886 {Op0, Op1, Op2, Op3});
18888 case PPC::BI__builtin_ppc_minfe: {
18894 {Op0, Op1, Op2, Op3});
18896 case PPC::BI__builtin_ppc_minfl: {
18902 {Op0, Op1, Op2, Op3});
18904 case PPC::BI__builtin_ppc_minfs: {
18910 {Op0, Op1, Op2, Op3});
18912 case PPC::BI__builtin_ppc_swdiv:
18913 case PPC::BI__builtin_ppc_swdivs: {
18916 return Builder.CreateFDiv(Op0, Op1,
"swdiv");
18918 case PPC::BI__builtin_ppc_set_fpscr_rn:
18920 {EmitScalarExpr(E->getArg(0))});
18921 case PPC::BI__builtin_ppc_mffs:
18934 Attribute::getWithDereferenceableBytes(
Call->getContext(), 64));
18935 Call->addRetAttr(Attribute::getWithAlignment(
Call->getContext(), Align(4)));
18939 auto *RetTy = cast<llvm::PointerType>(CGF.
ConvertType(BuiltinRetType));
18940 if (RetTy ==
Call->getType())
18949 Attribute::getWithDereferenceableBytes(
Call->getContext(), 256));
18950 Call->addRetAttr(Attribute::getWithAlignment(
Call->getContext(), Align(8)));
18965 llvm::LoadInst *LD;
18969 if (Cov == CodeObjectVersionKind::COV_None) {
18970 StringRef Name =
"__oclc_ABI_version";
18971 auto *ABIVersionC = CGF.
CGM.
getModule().getNamedGlobal(Name);
18973 ABIVersionC =
new llvm::GlobalVariable(
18975 llvm::GlobalValue::ExternalLinkage,
nullptr, Name,
nullptr,
18976 llvm::GlobalVariable::NotThreadLocal,
18987 llvm::ConstantInt::get(CGF.
Int32Ty, CodeObjectVersionKind::COV_5));
18991 CGF.
Int8Ty, EmitAMDGPUImplicitArgPtr(CGF), 12 + Index * 2);
18995 CGF.
Int8Ty, EmitAMDGPUDispatchPtr(CGF), 4 + Index * 2);
18997 auto Result = CGF.
Builder.CreateSelect(IsCOV5, ImplicitGEP, DispatchGEP);
19001 Value *GEP =
nullptr;
19002 if (Cov >= CodeObjectVersionKind::COV_5) {
19004 GEP = CGF.
Builder.CreateConstGEP1_32(
19005 CGF.
Int8Ty, EmitAMDGPUImplicitArgPtr(CGF), 12 + Index * 2);
19008 GEP = CGF.
Builder.CreateConstGEP1_32(
19009 CGF.
Int8Ty, EmitAMDGPUDispatchPtr(CGF), 4 + Index * 2);
19016 llvm::MDNode *RNode = MDHelper.createRange(
APInt(16, 1),
19018 LD->setMetadata(llvm::LLVMContext::MD_range, RNode);
19019 LD->setMetadata(llvm::LLVMContext::MD_noundef,
19021 LD->setMetadata(llvm::LLVMContext::MD_invariant_load,
19028 const unsigned XOffset = 12;
19029 auto *DP = EmitAMDGPUDispatchPtr(CGF);
19031 auto *Offset = llvm::ConstantInt::get(CGF.
Int32Ty, XOffset + Index * 4);
19039 LD->setMetadata(llvm::LLVMContext::MD_range,
19040 MDB.createRange(
APInt(32, 1), APInt::getZero(32)));
19041 LD->setMetadata(llvm::LLVMContext::MD_invariant_load,
19054 llvm::AtomicOrdering &AO,
19055 llvm::SyncScope::ID &SSID) {
19056 int ord = cast<llvm::ConstantInt>(Order)->getZExtValue();
19059 assert(llvm::isValidAtomicOrderingCABI(ord));
19060 switch (
static_cast<llvm::AtomicOrderingCABI
>(ord)) {
19061 case llvm::AtomicOrderingCABI::acquire:
19062 case llvm::AtomicOrderingCABI::consume:
19063 AO = llvm::AtomicOrdering::Acquire;
19065 case llvm::AtomicOrderingCABI::release:
19066 AO = llvm::AtomicOrdering::Release;
19068 case llvm::AtomicOrderingCABI::acq_rel:
19069 AO = llvm::AtomicOrdering::AcquireRelease;
19071 case llvm::AtomicOrderingCABI::seq_cst:
19072 AO = llvm::AtomicOrdering::SequentiallyConsistent;
19074 case llvm::AtomicOrderingCABI::relaxed:
19075 AO = llvm::AtomicOrdering::Monotonic;
19081 if (llvm::getConstantStringInfo(
Scope, scp)) {
19087 int scope = cast<llvm::ConstantInt>(
Scope)->getZExtValue();
19090 SSID = llvm::SyncScope::System;
19102 SSID = llvm::SyncScope::SingleThread;
19105 SSID = llvm::SyncScope::System;
19113 llvm::Value *Arg =
nullptr;
19114 if ((ICEArguments & (1 << Idx)) == 0) {
19119 std::optional<llvm::APSInt>
Result =
19121 assert(
Result &&
"Expected argument to be a constant");
19130 return RT.getFDotIntrinsic();
19132 return RT.getSDotIntrinsic();
19134 return RT.getUDotIntrinsic();
19139 return RT.getFirstBitSHighIntrinsic();
19143 return RT.getFirstBitUHighIntrinsic();
19152 switch (BuiltinID) {
19153 case Builtin::BI__builtin_hlsl_resource_getpointer: {
19158 llvm::Type *RetTy = llvm::PointerType::getUnqual(
getLLVMContext());
19160 return Builder.CreateIntrinsic(RetTy, Intrinsic::dx_resource_getpointer,
19163 case Builtin::BI__builtin_hlsl_all: {
19165 return Builder.CreateIntrinsic(
19170 case Builtin::BI__builtin_hlsl_any: {
19172 return Builder.CreateIntrinsic(
19177 case Builtin::BI__builtin_hlsl_asdouble:
19179 case Builtin::BI__builtin_hlsl_elementwise_clamp: {
19186 Ty = VecTy->getElementType();
19188 Intrinsic::ID Intr;
19197 return Builder.CreateIntrinsic(
19201 case Builtin::BI__builtin_hlsl_cross: {
19206 "cross operands must have a float representation");
19211 "input vectors must have 3 elements each");
19212 return Builder.CreateIntrinsic(
19216 case Builtin::BI__builtin_hlsl_dot: {
19219 llvm::Type *T0 = Op0->
getType();
19220 llvm::Type *T1 = Op1->
getType();
19223 if (!T0->isVectorTy() && !T1->isVectorTy()) {
19224 if (T0->isFloatingPointTy())
19225 return Builder.CreateFMul(Op0, Op1,
"hlsl.dot");
19227 if (T0->isIntegerTy())
19228 return Builder.CreateMul(Op0, Op1,
"hlsl.dot");
19231 "Scalar dot product is only supported on ints and floats.");
19236 assert(T0->isVectorTy() && T1->isVectorTy() &&
19237 "Dot product of vector and scalar is not supported.");
19240 [[maybe_unused]]
auto *VecTy1 =
19244 "Dot product of vectors need the same element types.");
19247 "Dot product requires vectors to be of the same size.");
19249 return Builder.CreateIntrinsic(
19250 T0->getScalarType(),
19254 case Builtin::BI__builtin_hlsl_dot4add_i8packed: {
19260 return Builder.CreateIntrinsic(
19262 "hlsl.dot4add.i8packed");
19264 case Builtin::BI__builtin_hlsl_dot4add_u8packed: {
19270 return Builder.CreateIntrinsic(
19272 "hlsl.dot4add.u8packed");
19274 case Builtin::BI__builtin_hlsl_elementwise_firstbithigh: {
19278 return Builder.CreateIntrinsic(
19283 case Builtin::BI__builtin_hlsl_lerp: {
19288 llvm_unreachable(
"lerp operand must have a float representation");
19289 return Builder.CreateIntrinsic(
19293 case Builtin::BI__builtin_hlsl_length: {
19297 "length operand must have a float representation");
19302 return Builder.CreateIntrinsic(
19303 X->getType()->getScalarType(),
19305 nullptr,
"hlsl.length");
19307 case Builtin::BI__builtin_hlsl_normalize: {
19311 "normalize operand must have a float representation");
19313 return Builder.CreateIntrinsic(
19316 nullptr,
"hlsl.normalize");
19318 case Builtin::BI__builtin_hlsl_elementwise_degrees: {
19322 "degree operand must have a float representation");
19324 return Builder.CreateIntrinsic(
19328 case Builtin::BI__builtin_hlsl_elementwise_frac: {
19331 llvm_unreachable(
"frac operand must have a float representation");
19332 return Builder.CreateIntrinsic(
19336case Builtin::BI__builtin_hlsl_elementwise_isinf: {
19338 llvm::Type *Xty = Op0->
getType();
19339 llvm::Type *retType = llvm::Type::getInt1Ty(this->
getLLVMContext());
19340 if (Xty->isVectorTy()) {
19342 retType = llvm::VectorType::get(
19343 retType, ElementCount::getFixed(XVecTy->getNumElements()));
19346 llvm_unreachable(
"isinf operand must have a float representation");
19347 return Builder.CreateIntrinsic(retType, Intrinsic::dx_isinf,
19350 case Builtin::BI__builtin_hlsl_mad: {
19355 return Builder.CreateIntrinsic(
19356 M->
getType(), Intrinsic::fmuladd,
19361 return Builder.CreateIntrinsic(
19362 M->
getType(), Intrinsic::dx_imad,
19366 return Builder.CreateNSWAdd(Mul, B);
19370 return Builder.CreateIntrinsic(
19371 M->
getType(), Intrinsic::dx_umad,
19375 return Builder.CreateNUWAdd(Mul, B);
19377 case Builtin::BI__builtin_hlsl_elementwise_rcp: {
19380 llvm_unreachable(
"rcp operand must have a float representation");
19381 llvm::Type *Ty = Op0->
getType();
19382 llvm::Type *EltTy = Ty->getScalarType();
19383 Constant *One = Ty->isVectorTy()
19384 ? ConstantVector::getSplat(
19385 ElementCount::getFixed(
19386 cast<FixedVectorType>(Ty)->getNumElements()),
19387 ConstantFP::get(EltTy, 1.0))
19388 : ConstantFP::get(EltTy, 1.0);
19389 return Builder.CreateFDiv(One, Op0,
"hlsl.rcp");
19391 case Builtin::BI__builtin_hlsl_elementwise_rsqrt: {
19394 llvm_unreachable(
"rsqrt operand must have a float representation");
19395 return Builder.CreateIntrinsic(
19399 case Builtin::BI__builtin_hlsl_elementwise_saturate: {
19402 "saturate operand must have a float representation");
19403 return Builder.CreateIntrinsic(
19406 nullptr,
"hlsl.saturate");
19408 case Builtin::BI__builtin_hlsl_select: {
19422 Builder.CreateSelect(OpCond, OpTrue, OpFalse,
"hlsl.select");
19429 case Builtin::BI__builtin_hlsl_step: {
19434 "step operands must have a float representation");
19435 return Builder.CreateIntrinsic(
19439 case Builtin::BI__builtin_hlsl_wave_active_all_true: {
19441 assert(Op->
getType()->isIntegerTy(1) &&
19442 "Intrinsic WaveActiveAllTrue operand must be a bool");
19446 Intrinsic::getOrInsertDeclaration(&
CGM.
getModule(), ID), {Op});
19448 case Builtin::BI__builtin_hlsl_wave_active_any_true: {
19450 assert(Op->
getType()->isIntegerTy(1) &&
19451 "Intrinsic WaveActiveAnyTrue operand must be a bool");
19455 Intrinsic::getOrInsertDeclaration(&
CGM.
getModule(), ID), {Op});
19457 case Builtin::BI__builtin_hlsl_wave_active_count_bits: {
19461 Intrinsic::getOrInsertDeclaration(&
CGM.
getModule(), ID),
19464 case Builtin::BI__builtin_hlsl_wave_get_lane_index: {
19469 case llvm::Triple::dxil:
19472 case llvm::Triple::spirv:
19474 llvm::FunctionType::get(
IntTy, {},
false),
19475 "__hlsl_wave_get_lane_index", {},
false,
true));
19478 "Intrinsic WaveGetLaneIndex not supported by target architecture");
19481 case Builtin::BI__builtin_hlsl_wave_is_first_lane: {
19484 Intrinsic::getOrInsertDeclaration(&
CGM.
getModule(), ID));
19486 case Builtin::BI__builtin_hlsl_wave_read_lane_at: {
19491 llvm::FunctionType *FT = llvm::FunctionType::get(
19502 ArrayRef{OpExpr, OpIndex},
"hlsl.wave.readlane");
19504 case Builtin::BI__builtin_hlsl_elementwise_sign: {
19505 auto *Arg0 =
E->getArg(0);
19507 llvm::Type *Xty = Op0->
getType();
19508 llvm::Type *retType = llvm::Type::getInt32Ty(this->
getLLVMContext());
19509 if (Xty->isVectorTy()) {
19511 retType = llvm::VectorType::get(
19512 retType, ElementCount::getFixed(XVecTy->getNumElements()));
19516 "sign operand must have a float or int representation");
19519 Value *Cmp =
Builder.CreateICmpEQ(Op0, ConstantInt::get(Xty, 0));
19520 return Builder.CreateSelect(Cmp, ConstantInt::get(retType, 0),
19521 ConstantInt::get(retType, 1),
"hlsl.sign");
19524 return Builder.CreateIntrinsic(
19528 case Builtin::BI__builtin_hlsl_elementwise_radians: {
19531 "radians operand must have a float representation");
19532 return Builder.CreateIntrinsic(
19535 nullptr,
"hlsl.radians");
19537 case Builtin::BI__builtin_hlsl_buffer_update_counter: {
19541 return Builder.CreateIntrinsic(
19546 case Builtin::BI__builtin_hlsl_elementwise_splitdouble: {
19551 "asuint operands types mismatch");
19554 case Builtin::BI__builtin_hlsl_elementwise_clip:
19556 "clip operands types mismatch");
19558 case Builtin::BI__builtin_hlsl_group_memory_barrier_with_group_sync: {
19562 Intrinsic::getOrInsertDeclaration(&
CGM.
getModule(), ID));
19570 constexpr const char *
Tag =
"amdgpu-as";
19572 LLVMContext &Ctx = Inst->getContext();
19574 for (
unsigned K = 2; K <
E->getNumArgs(); ++K) {
19577 if (llvm::getConstantStringInfo(
V, AS)) {
19578 MMRAs.push_back({
Tag, AS});
19583 "expected an address space name as a string literal");
19587 MMRAs.erase(llvm::unique(MMRAs), MMRAs.end());
19588 Inst->setMetadata(LLVMContext::MD_mmra, MMRAMetadata::getMD(Ctx, MMRAs));
19593 llvm::AtomicOrdering AO = llvm::AtomicOrdering::SequentiallyConsistent;
19594 llvm::SyncScope::ID SSID;
19595 switch (BuiltinID) {
19596 case AMDGPU::BI__builtin_amdgcn_div_scale:
19597 case AMDGPU::BI__builtin_amdgcn_div_scalef: {
19610 llvm::Value *Tmp =
Builder.CreateCall(Callee, {
X, Y, Z});
19613 llvm::Value *Flag =
Builder.CreateExtractValue(Tmp, 1);
19617 llvm::Value *FlagExt =
Builder.CreateZExt(Flag, RealFlagType);
19621 case AMDGPU::BI__builtin_amdgcn_div_fmas:
19622 case AMDGPU::BI__builtin_amdgcn_div_fmasf: {
19630 llvm::Value *Src3ToBool =
Builder.CreateIsNotNull(Src3);
19631 return Builder.CreateCall(F, {Src0, Src1, Src2, Src3ToBool});
19634 case AMDGPU::BI__builtin_amdgcn_ds_swizzle:
19635 return emitBuiltinWithOneOverloadedType<2>(*
this,
E,
19636 Intrinsic::amdgcn_ds_swizzle);
19637 case AMDGPU::BI__builtin_amdgcn_mov_dpp8:
19638 case AMDGPU::BI__builtin_amdgcn_mov_dpp:
19639 case AMDGPU::BI__builtin_amdgcn_update_dpp: {
19643 unsigned ICEArguments = 0;
19648 unsigned Size = DataTy->getPrimitiveSizeInBits();
19649 llvm::Type *
IntTy =
19650 llvm::IntegerType::get(
Builder.getContext(), std::max(Size, 32u));
19653 ? Intrinsic::amdgcn_mov_dpp8
19654 : Intrinsic::amdgcn_update_dpp,
19656 assert(
E->getNumArgs() == 5 ||
E->getNumArgs() == 6 ||
19657 E->getNumArgs() == 2);
19658 bool InsertOld = BuiltinID == AMDGPU::BI__builtin_amdgcn_mov_dpp;
19660 Args.push_back(llvm::PoisonValue::get(
IntTy));
19661 for (
unsigned I = 0; I !=
E->getNumArgs(); ++I) {
19663 if (I < (BuiltinID == AMDGPU::BI__builtin_amdgcn_update_dpp ? 2u : 1u) &&
19665 if (!DataTy->isIntegerTy())
19667 V, llvm::IntegerType::get(
Builder.getContext(), Size));
19670 llvm::Type *ExpTy =
19671 F->getFunctionType()->getFunctionParamType(I + InsertOld);
19672 Args.push_back(
Builder.CreateTruncOrBitCast(
V, ExpTy));
19675 if (Size < 32 && !DataTy->isIntegerTy())
19677 V, llvm::IntegerType::get(
Builder.getContext(), Size));
19678 return Builder.CreateTruncOrBitCast(
V, DataTy);
19680 case AMDGPU::BI__builtin_amdgcn_permlane16:
19681 case AMDGPU::BI__builtin_amdgcn_permlanex16:
19682 return emitBuiltinWithOneOverloadedType<6>(
19684 BuiltinID == AMDGPU::BI__builtin_amdgcn_permlane16
19685 ? Intrinsic::amdgcn_permlane16
19686 : Intrinsic::amdgcn_permlanex16);
19687 case AMDGPU::BI__builtin_amdgcn_permlane64:
19688 return emitBuiltinWithOneOverloadedType<1>(*
this,
E,
19689 Intrinsic::amdgcn_permlane64);
19690 case AMDGPU::BI__builtin_amdgcn_readlane:
19691 return emitBuiltinWithOneOverloadedType<2>(*
this,
E,
19692 Intrinsic::amdgcn_readlane);
19693 case AMDGPU::BI__builtin_amdgcn_readfirstlane:
19694 return emitBuiltinWithOneOverloadedType<1>(*
this,
E,
19695 Intrinsic::amdgcn_readfirstlane);
19696 case AMDGPU::BI__builtin_amdgcn_div_fixup:
19697 case AMDGPU::BI__builtin_amdgcn_div_fixupf:
19698 case AMDGPU::BI__builtin_amdgcn_div_fixuph:
19699 return emitBuiltinWithOneOverloadedType<3>(*
this,
E,
19700 Intrinsic::amdgcn_div_fixup);
19701 case AMDGPU::BI__builtin_amdgcn_trig_preop:
19702 case AMDGPU::BI__builtin_amdgcn_trig_preopf:
19704 case AMDGPU::BI__builtin_amdgcn_rcp:
19705 case AMDGPU::BI__builtin_amdgcn_rcpf:
19706 case AMDGPU::BI__builtin_amdgcn_rcph:
19707 return emitBuiltinWithOneOverloadedType<1>(*
this,
E, Intrinsic::amdgcn_rcp);
19708 case AMDGPU::BI__builtin_amdgcn_sqrt:
19709 case AMDGPU::BI__builtin_amdgcn_sqrtf:
19710 case AMDGPU::BI__builtin_amdgcn_sqrth:
19711 return emitBuiltinWithOneOverloadedType<1>(*
this,
E,
19712 Intrinsic::amdgcn_sqrt);
19713 case AMDGPU::BI__builtin_amdgcn_rsq:
19714 case AMDGPU::BI__builtin_amdgcn_rsqf:
19715 case AMDGPU::BI__builtin_amdgcn_rsqh:
19716 return emitBuiltinWithOneOverloadedType<1>(*
this,
E, Intrinsic::amdgcn_rsq);
19717 case AMDGPU::BI__builtin_amdgcn_rsq_clamp:
19718 case AMDGPU::BI__builtin_amdgcn_rsq_clampf:
19719 return emitBuiltinWithOneOverloadedType<1>(*
this,
E,
19720 Intrinsic::amdgcn_rsq_clamp);
19721 case AMDGPU::BI__builtin_amdgcn_sinf:
19722 case AMDGPU::BI__builtin_amdgcn_sinh:
19723 return emitBuiltinWithOneOverloadedType<1>(*
this,
E, Intrinsic::amdgcn_sin);
19724 case AMDGPU::BI__builtin_amdgcn_cosf:
19725 case AMDGPU::BI__builtin_amdgcn_cosh:
19726 return emitBuiltinWithOneOverloadedType<1>(*
this,
E, Intrinsic::amdgcn_cos);
19727 case AMDGPU::BI__builtin_amdgcn_dispatch_ptr:
19728 return EmitAMDGPUDispatchPtr(*
this,
E);
19729 case AMDGPU::BI__builtin_amdgcn_logf:
19730 return emitBuiltinWithOneOverloadedType<1>(*
this,
E, Intrinsic::amdgcn_log);
19731 case AMDGPU::BI__builtin_amdgcn_exp2f:
19732 return emitBuiltinWithOneOverloadedType<1>(*
this,
E,
19733 Intrinsic::amdgcn_exp2);
19734 case AMDGPU::BI__builtin_amdgcn_log_clampf:
19735 return emitBuiltinWithOneOverloadedType<1>(*
this,
E,
19736 Intrinsic::amdgcn_log_clamp);
19737 case AMDGPU::BI__builtin_amdgcn_ldexp:
19738 case AMDGPU::BI__builtin_amdgcn_ldexpf: {
19741 llvm::Function *F =
19742 CGM.
getIntrinsic(Intrinsic::ldexp, {Src0->getType(), Src1->getType()});
19743 return Builder.CreateCall(F, {Src0, Src1});
19745 case AMDGPU::BI__builtin_amdgcn_ldexph: {
19750 llvm::Function *F =
19754 case AMDGPU::BI__builtin_amdgcn_frexp_mant:
19755 case AMDGPU::BI__builtin_amdgcn_frexp_mantf:
19756 case AMDGPU::BI__builtin_amdgcn_frexp_manth:
19757 return emitBuiltinWithOneOverloadedType<1>(*
this,
E,
19758 Intrinsic::amdgcn_frexp_mant);
19759 case AMDGPU::BI__builtin_amdgcn_frexp_exp:
19760 case AMDGPU::BI__builtin_amdgcn_frexp_expf: {
19764 return Builder.CreateCall(F, Src0);
19766 case AMDGPU::BI__builtin_amdgcn_frexp_exph: {
19770 return Builder.CreateCall(F, Src0);
19772 case AMDGPU::BI__builtin_amdgcn_fract:
19773 case AMDGPU::BI__builtin_amdgcn_fractf:
19774 case AMDGPU::BI__builtin_amdgcn_fracth:
19775 return emitBuiltinWithOneOverloadedType<1>(*
this,
E,
19776 Intrinsic::amdgcn_fract);
19777 case AMDGPU::BI__builtin_amdgcn_lerp:
19778 return emitBuiltinWithOneOverloadedType<3>(*
this,
E,
19779 Intrinsic::amdgcn_lerp);
19780 case AMDGPU::BI__builtin_amdgcn_ubfe:
19781 return emitBuiltinWithOneOverloadedType<3>(*
this,
E,
19782 Intrinsic::amdgcn_ubfe);
19783 case AMDGPU::BI__builtin_amdgcn_sbfe:
19784 return emitBuiltinWithOneOverloadedType<3>(*
this,
E,
19785 Intrinsic::amdgcn_sbfe);
19786 case AMDGPU::BI__builtin_amdgcn_ballot_w32:
19787 case AMDGPU::BI__builtin_amdgcn_ballot_w64: {
19791 return Builder.CreateCall(F, { Src });
19793 case AMDGPU::BI__builtin_amdgcn_uicmp:
19794 case AMDGPU::BI__builtin_amdgcn_uicmpl:
19795 case AMDGPU::BI__builtin_amdgcn_sicmp:
19796 case AMDGPU::BI__builtin_amdgcn_sicmpl: {
19803 {
Builder.getInt64Ty(), Src0->getType() });
19804 return Builder.CreateCall(F, { Src0, Src1, Src2 });
19806 case AMDGPU::BI__builtin_amdgcn_fcmp:
19807 case AMDGPU::BI__builtin_amdgcn_fcmpf: {
19814 {
Builder.getInt64Ty(), Src0->getType() });
19815 return Builder.CreateCall(F, { Src0, Src1, Src2 });
19817 case AMDGPU::BI__builtin_amdgcn_class:
19818 case AMDGPU::BI__builtin_amdgcn_classf:
19819 case AMDGPU::BI__builtin_amdgcn_classh:
19821 case AMDGPU::BI__builtin_amdgcn_fmed3f:
19822 case AMDGPU::BI__builtin_amdgcn_fmed3h:
19823 return emitBuiltinWithOneOverloadedType<3>(*
this,
E,
19824 Intrinsic::amdgcn_fmed3);
19825 case AMDGPU::BI__builtin_amdgcn_ds_append:
19826 case AMDGPU::BI__builtin_amdgcn_ds_consume: {
19827 Intrinsic::ID Intrin = BuiltinID == AMDGPU::BI__builtin_amdgcn_ds_append ?
19828 Intrinsic::amdgcn_ds_append : Intrinsic::amdgcn_ds_consume;
19833 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b64_i32:
19834 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b64_v2i32:
19835 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v4i16:
19836 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v4f16:
19837 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v4bf16:
19838 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v8i16:
19839 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v8f16:
19840 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v8bf16:
19841 case AMDGPU::BI__builtin_amdgcn_ds_read_tr4_b64_v2i32:
19842 case AMDGPU::BI__builtin_amdgcn_ds_read_tr8_b64_v2i32:
19843 case AMDGPU::BI__builtin_amdgcn_ds_read_tr6_b96_v3i32:
19844 case AMDGPU::BI__builtin_amdgcn_ds_read_tr16_b64_v4f16:
19845 case AMDGPU::BI__builtin_amdgcn_ds_read_tr16_b64_v4bf16:
19846 case AMDGPU::BI__builtin_amdgcn_ds_read_tr16_b64_v4i16: {
19848 switch (BuiltinID) {
19849 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b64_i32:
19850 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b64_v2i32:
19851 IID = Intrinsic::amdgcn_global_load_tr_b64;
19853 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v4i16:
19854 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v4f16:
19855 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v4bf16:
19856 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v8i16:
19857 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v8f16:
19858 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v8bf16:
19859 IID = Intrinsic::amdgcn_global_load_tr_b128;
19861 case AMDGPU::BI__builtin_amdgcn_ds_read_tr4_b64_v2i32:
19862 IID = Intrinsic::amdgcn_ds_read_tr4_b64;
19864 case AMDGPU::BI__builtin_amdgcn_ds_read_tr8_b64_v2i32:
19865 IID = Intrinsic::amdgcn_ds_read_tr8_b64;
19867 case AMDGPU::BI__builtin_amdgcn_ds_read_tr6_b96_v3i32:
19868 IID = Intrinsic::amdgcn_ds_read_tr6_b96;
19870 case AMDGPU::BI__builtin_amdgcn_ds_read_tr16_b64_v4i16:
19871 case AMDGPU::BI__builtin_amdgcn_ds_read_tr16_b64_v4f16:
19872 case AMDGPU::BI__builtin_amdgcn_ds_read_tr16_b64_v4bf16:
19873 IID = Intrinsic::amdgcn_ds_read_tr16_b64;
19879 return Builder.CreateCall(F, {Addr});
19881 case AMDGPU::BI__builtin_amdgcn_get_fpenv: {
19884 return Builder.CreateCall(F);
19886 case AMDGPU::BI__builtin_amdgcn_set_fpenv: {
19892 case AMDGPU::BI__builtin_amdgcn_read_exec:
19894 case AMDGPU::BI__builtin_amdgcn_read_exec_lo:
19896 case AMDGPU::BI__builtin_amdgcn_read_exec_hi:
19898 case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray:
19899 case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray_h:
19900 case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray_l:
19901 case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray_lh: {
19911 RayOrigin =
Builder.CreateShuffleVector(RayOrigin, RayOrigin,
19915 RayInverseDir =
Builder.CreateShuffleVector(RayInverseDir, RayInverseDir,
19919 {NodePtr->getType(), RayDir->getType()});
19920 return Builder.CreateCall(F, {NodePtr, RayExtent, RayOrigin, RayDir,
19921 RayInverseDir, TextureDescr});
19924 case AMDGPU::BI__builtin_amdgcn_ds_bvh_stack_rtn: {
19926 for (
int i = 0, e =
E->getNumArgs(); i != e; ++i)
19934 Value *I0 =
Builder.CreateInsertElement(PoisonValue::get(RetTy), Rtn,
19936 return Builder.CreateInsertElement(I0, A, 1);
19938 case AMDGPU::BI__builtin_amdgcn_mfma_scale_f32_16x16x128_f8f6f4:
19939 case AMDGPU::BI__builtin_amdgcn_mfma_scale_f32_32x32x64_f8f6f4: {
19940 llvm::FixedVectorType *VT = FixedVectorType::get(
Builder.getInt32Ty(), 8);
19942 BuiltinID == AMDGPU::BI__builtin_amdgcn_mfma_scale_f32_32x32x64_f8f6f4
19943 ? Intrinsic::amdgcn_mfma_scale_f32_32x32x64_f8f6f4
19944 : Intrinsic::amdgcn_mfma_scale_f32_16x16x128_f8f6f4,
19948 for (
unsigned I = 0, N =
E->getNumArgs(); I != N; ++I)
19950 return Builder.CreateCall(F, Args);
19952 case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x16_bf16_w32:
19953 case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x16_bf16_tied_w32:
19954 case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x16_bf16_w64:
19955 case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x16_bf16_tied_w64:
19956 case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x16_f16_w32:
19957 case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x16_f16_tied_w32:
19958 case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x16_f16_w64:
19959 case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x16_f16_tied_w64:
19960 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf16_w32:
19961 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf16_w64:
19962 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_f16_w32:
19963 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_f16_w64:
19964 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu4_w32:
19965 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu4_w64:
19966 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu8_w32:
19967 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu8_w64:
19968 case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x16_bf16_w32_gfx12:
19969 case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x16_bf16_w64_gfx12:
19970 case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x16_f16_w32_gfx12:
19971 case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x16_f16_w64_gfx12:
19972 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf16_w32_gfx12:
19973 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf16_w64_gfx12:
19974 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_f16_w32_gfx12:
19975 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_f16_w64_gfx12:
19976 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu4_w32_gfx12:
19977 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu4_w64_gfx12:
19978 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu8_w32_gfx12:
19979 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu8_w64_gfx12:
19980 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_fp8_fp8_w32_gfx12:
19981 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_fp8_fp8_w64_gfx12:
19982 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_fp8_bf8_w32_gfx12:
19983 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_fp8_bf8_w64_gfx12:
19984 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf8_fp8_w32_gfx12:
19985 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf8_fp8_w64_gfx12:
19986 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf8_bf8_w32_gfx12:
19987 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf8_bf8_w64_gfx12:
19988 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x32_iu4_w32_gfx12:
19989 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x32_iu4_w64_gfx12:
19990 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_f16_w32:
19991 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_f16_w64:
19992 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf16_w32:
19993 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf16_w64:
19994 case AMDGPU::BI__builtin_amdgcn_swmmac_f16_16x16x32_f16_w32:
19995 case AMDGPU::BI__builtin_amdgcn_swmmac_f16_16x16x32_f16_w64:
19996 case AMDGPU::BI__builtin_amdgcn_swmmac_bf16_16x16x32_bf16_w32:
19997 case AMDGPU::BI__builtin_amdgcn_swmmac_bf16_16x16x32_bf16_w64:
19998 case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x32_iu8_w32:
19999 case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x32_iu8_w64:
20000 case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x32_iu4_w32:
20001 case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x32_iu4_w64:
20002 case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x64_iu4_w32:
20003 case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x64_iu4_w64:
20004 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_fp8_fp8_w32:
20005 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_fp8_fp8_w64:
20006 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_fp8_bf8_w32:
20007 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_fp8_bf8_w64:
20008 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf8_fp8_w32:
20009 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf8_fp8_w64:
20010 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf8_bf8_w32:
20011 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf8_bf8_w64: {
20024 bool AppendFalseForOpselArg =
false;
20025 unsigned BuiltinWMMAOp;
20027 switch (BuiltinID) {
20028 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_f16_w32:
20029 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_f16_w64:
20030 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_f16_w32_gfx12:
20031 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_f16_w64_gfx12:
20032 ArgsForMatchingMatrixTypes = {2, 0};
20033 BuiltinWMMAOp = Intrinsic::amdgcn_wmma_f32_16x16x16_f16;
20035 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf16_w32:
20036 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf16_w64:
20037 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf16_w32_gfx12:
20038 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf16_w64_gfx12:
20039 ArgsForMatchingMatrixTypes = {2, 0};
20040 BuiltinWMMAOp = Intrinsic::amdgcn_wmma_f32_16x16x16_bf16;
20042 case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x16_f16_w32_gfx12:
20043 case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x16_f16_w64_gfx12:
20044 AppendFalseForOpselArg =
true;
20046 case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x16_f16_w32:
20047 case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x16_f16_w64:
20048 ArgsForMatchingMatrixTypes = {2, 0};
20049 BuiltinWMMAOp = Intrinsic::amdgcn_wmma_f16_16x16x16_f16;
20051 case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x16_bf16_w32_gfx12:
20052 case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x16_bf16_w64_gfx12:
20053 AppendFalseForOpselArg =
true;
20055 case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x16_bf16_w32:
20056 case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x16_bf16_w64:
20057 ArgsForMatchingMatrixTypes = {2, 0};
20058 BuiltinWMMAOp = Intrinsic::amdgcn_wmma_bf16_16x16x16_bf16;
20060 case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x16_f16_tied_w32:
20061 case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x16_f16_tied_w64:
20062 ArgsForMatchingMatrixTypes = {2, 0};
20063 BuiltinWMMAOp = Intrinsic::amdgcn_wmma_f16_16x16x16_f16_tied;
20065 case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x16_bf16_tied_w32:
20066 case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x16_bf16_tied_w64:
20067 ArgsForMatchingMatrixTypes = {2, 0};
20068 BuiltinWMMAOp = Intrinsic::amdgcn_wmma_bf16_16x16x16_bf16_tied;
20070 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu8_w32:
20071 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu8_w64:
20072 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu8_w32_gfx12:
20073 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu8_w64_gfx12:
20074 ArgsForMatchingMatrixTypes = {4, 1};
20075 BuiltinWMMAOp = Intrinsic::amdgcn_wmma_i32_16x16x16_iu8;
20077 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu4_w32:
20078 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu4_w64:
20079 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu4_w32_gfx12:
20080 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu4_w64_gfx12:
20081 ArgsForMatchingMatrixTypes = {4, 1};
20082 BuiltinWMMAOp = Intrinsic::amdgcn_wmma_i32_16x16x16_iu4;
20084 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_fp8_fp8_w32_gfx12:
20085 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_fp8_fp8_w64_gfx12:
20086 ArgsForMatchingMatrixTypes = {2, 0};
20087 BuiltinWMMAOp = Intrinsic::amdgcn_wmma_f32_16x16x16_fp8_fp8;
20089 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_fp8_bf8_w32_gfx12:
20090 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_fp8_bf8_w64_gfx12:
20091 ArgsForMatchingMatrixTypes = {2, 0};
20092 BuiltinWMMAOp = Intrinsic::amdgcn_wmma_f32_16x16x16_fp8_bf8;
20094 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf8_fp8_w32_gfx12:
20095 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf8_fp8_w64_gfx12:
20096 ArgsForMatchingMatrixTypes = {2, 0};
20097 BuiltinWMMAOp = Intrinsic::amdgcn_wmma_f32_16x16x16_bf8_fp8;
20099 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf8_bf8_w32_gfx12:
20100 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf8_bf8_w64_gfx12:
20101 ArgsForMatchingMatrixTypes = {2, 0};
20102 BuiltinWMMAOp = Intrinsic::amdgcn_wmma_f32_16x16x16_bf8_bf8;
20104 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x32_iu4_w32_gfx12:
20105 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x32_iu4_w64_gfx12:
20106 ArgsForMatchingMatrixTypes = {4, 1};
20107 BuiltinWMMAOp = Intrinsic::amdgcn_wmma_i32_16x16x32_iu4;
20109 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_f16_w32:
20110 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_f16_w64:
20111 ArgsForMatchingMatrixTypes = {2, 0, 1, 3};
20112 BuiltinWMMAOp = Intrinsic::amdgcn_swmmac_f32_16x16x32_f16;
20114 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf16_w32:
20115 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf16_w64:
20116 ArgsForMatchingMatrixTypes = {2, 0, 1, 3};
20117 BuiltinWMMAOp = Intrinsic::amdgcn_swmmac_f32_16x16x32_bf16;
20119 case AMDGPU::BI__builtin_amdgcn_swmmac_f16_16x16x32_f16_w32:
20120 case AMDGPU::BI__builtin_amdgcn_swmmac_f16_16x16x32_f16_w64:
20121 ArgsForMatchingMatrixTypes = {2, 0, 1, 3};
20122 BuiltinWMMAOp = Intrinsic::amdgcn_swmmac_f16_16x16x32_f16;
20124 case AMDGPU::BI__builtin_amdgcn_swmmac_bf16_16x16x32_bf16_w32:
20125 case AMDGPU::BI__builtin_amdgcn_swmmac_bf16_16x16x32_bf16_w64:
20126 ArgsForMatchingMatrixTypes = {2, 0, 1, 3};
20127 BuiltinWMMAOp = Intrinsic::amdgcn_swmmac_bf16_16x16x32_bf16;
20129 case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x32_iu8_w32:
20130 case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x32_iu8_w64:
20131 ArgsForMatchingMatrixTypes = {4, 1, 3, 5};
20132 BuiltinWMMAOp = Intrinsic::amdgcn_swmmac_i32_16x16x32_iu8;
20134 case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x32_iu4_w32:
20135 case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x32_iu4_w64:
20136 ArgsForMatchingMatrixTypes = {4, 1, 3, 5};
20137 BuiltinWMMAOp = Intrinsic::amdgcn_swmmac_i32_16x16x32_iu4;
20139 case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x64_iu4_w32:
20140 case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x64_iu4_w64:
20141 ArgsForMatchingMatrixTypes = {4, 1, 3, 5};
20142 BuiltinWMMAOp = Intrinsic::amdgcn_swmmac_i32_16x16x64_iu4;
20144 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_fp8_fp8_w32:
20145 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_fp8_fp8_w64:
20146 ArgsForMatchingMatrixTypes = {2, 0, 1, 3};
20147 BuiltinWMMAOp = Intrinsic::amdgcn_swmmac_f32_16x16x32_fp8_fp8;
20149 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_fp8_bf8_w32:
20150 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_fp8_bf8_w64:
20151 ArgsForMatchingMatrixTypes = {2, 0, 1, 3};
20152 BuiltinWMMAOp = Intrinsic::amdgcn_swmmac_f32_16x16x32_fp8_bf8;
20154 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf8_fp8_w32:
20155 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf8_fp8_w64:
20156 ArgsForMatchingMatrixTypes = {2, 0, 1, 3};
20157 BuiltinWMMAOp = Intrinsic::amdgcn_swmmac_f32_16x16x32_bf8_fp8;
20159 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf8_bf8_w32:
20160 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf8_bf8_w64:
20161 ArgsForMatchingMatrixTypes = {2, 0, 1, 3};
20162 BuiltinWMMAOp = Intrinsic::amdgcn_swmmac_f32_16x16x32_bf8_bf8;
20167 for (
int i = 0, e =
E->getNumArgs(); i != e; ++i)
20169 if (AppendFalseForOpselArg)
20170 Args.push_back(
Builder.getFalse());
20173 for (
auto ArgIdx : ArgsForMatchingMatrixTypes)
20174 ArgTypes.push_back(Args[ArgIdx]->getType());
20177 return Builder.CreateCall(F, Args);
20181 case AMDGPU::BI__builtin_amdgcn_workitem_id_x:
20183 case AMDGPU::BI__builtin_amdgcn_workitem_id_y:
20185 case AMDGPU::BI__builtin_amdgcn_workitem_id_z:
20189 case AMDGPU::BI__builtin_amdgcn_workgroup_size_x:
20190 return EmitAMDGPUWorkGroupSize(*
this, 0);
20191 case AMDGPU::BI__builtin_amdgcn_workgroup_size_y:
20192 return EmitAMDGPUWorkGroupSize(*
this, 1);
20193 case AMDGPU::BI__builtin_amdgcn_workgroup_size_z:
20194 return EmitAMDGPUWorkGroupSize(*
this, 2);
20197 case AMDGPU::BI__builtin_amdgcn_grid_size_x:
20198 return EmitAMDGPUGridSize(*
this, 0);
20199 case AMDGPU::BI__builtin_amdgcn_grid_size_y:
20200 return EmitAMDGPUGridSize(*
this, 1);
20201 case AMDGPU::BI__builtin_amdgcn_grid_size_z:
20202 return EmitAMDGPUGridSize(*
this, 2);
20205 case AMDGPU::BI__builtin_r600_recipsqrt_ieee:
20206 case AMDGPU::BI__builtin_r600_recipsqrt_ieeef:
20207 return emitBuiltinWithOneOverloadedType<1>(*
this,
E,
20208 Intrinsic::r600_recipsqrt_ieee);
20209 case AMDGPU::BI__builtin_r600_read_tidig_x:
20211 case AMDGPU::BI__builtin_r600_read_tidig_y:
20213 case AMDGPU::BI__builtin_r600_read_tidig_z:
20215 case AMDGPU::BI__builtin_amdgcn_alignbit: {
20220 return Builder.CreateCall(F, { Src0, Src1, Src2 });
20222 case AMDGPU::BI__builtin_amdgcn_fence: {
20225 FenceInst *Fence =
Builder.CreateFence(AO, SSID);
20226 if (
E->getNumArgs() > 2)
20230 case AMDGPU::BI__builtin_amdgcn_atomic_inc32:
20231 case AMDGPU::BI__builtin_amdgcn_atomic_inc64:
20232 case AMDGPU::BI__builtin_amdgcn_atomic_dec32:
20233 case AMDGPU::BI__builtin_amdgcn_atomic_dec64:
20234 case AMDGPU::BI__builtin_amdgcn_ds_atomic_fadd_f64:
20235 case AMDGPU::BI__builtin_amdgcn_ds_atomic_fadd_f32:
20236 case AMDGPU::BI__builtin_amdgcn_ds_atomic_fadd_v2f16:
20237 case AMDGPU::BI__builtin_amdgcn_ds_atomic_fadd_v2bf16:
20238 case AMDGPU::BI__builtin_amdgcn_ds_faddf:
20239 case AMDGPU::BI__builtin_amdgcn_ds_fminf:
20240 case AMDGPU::BI__builtin_amdgcn_ds_fmaxf:
20241 case AMDGPU::BI__builtin_amdgcn_global_atomic_fadd_f32:
20242 case AMDGPU::BI__builtin_amdgcn_global_atomic_fadd_f64:
20243 case AMDGPU::BI__builtin_amdgcn_global_atomic_fadd_v2f16:
20244 case AMDGPU::BI__builtin_amdgcn_flat_atomic_fadd_v2f16:
20245 case AMDGPU::BI__builtin_amdgcn_flat_atomic_fadd_f32:
20246 case AMDGPU::BI__builtin_amdgcn_flat_atomic_fadd_f64:
20247 case AMDGPU::BI__builtin_amdgcn_global_atomic_fadd_v2bf16:
20248 case AMDGPU::BI__builtin_amdgcn_flat_atomic_fadd_v2bf16:
20249 case AMDGPU::BI__builtin_amdgcn_global_atomic_fmin_f64:
20250 case AMDGPU::BI__builtin_amdgcn_global_atomic_fmax_f64:
20251 case AMDGPU::BI__builtin_amdgcn_flat_atomic_fmin_f64:
20252 case AMDGPU::BI__builtin_amdgcn_flat_atomic_fmax_f64: {
20253 llvm::AtomicRMWInst::BinOp BinOp;
20254 switch (BuiltinID) {
20255 case AMDGPU::BI__builtin_amdgcn_atomic_inc32:
20256 case AMDGPU::BI__builtin_amdgcn_atomic_inc64:
20257 BinOp = llvm::AtomicRMWInst::UIncWrap;
20259 case AMDGPU::BI__builtin_amdgcn_atomic_dec32:
20260 case AMDGPU::BI__builtin_amdgcn_atomic_dec64:
20261 BinOp = llvm::AtomicRMWInst::UDecWrap;
20263 case AMDGPU::BI__builtin_amdgcn_ds_faddf:
20264 case AMDGPU::BI__builtin_amdgcn_ds_atomic_fadd_f64:
20265 case AMDGPU::BI__builtin_amdgcn_ds_atomic_fadd_f32:
20266 case AMDGPU::BI__builtin_amdgcn_ds_atomic_fadd_v2f16:
20267 case AMDGPU::BI__builtin_amdgcn_ds_atomic_fadd_v2bf16:
20268 case AMDGPU::BI__builtin_amdgcn_global_atomic_fadd_f32:
20269 case AMDGPU::BI__builtin_amdgcn_global_atomic_fadd_f64:
20270 case AMDGPU::BI__builtin_amdgcn_global_atomic_fadd_v2f16:
20271 case AMDGPU::BI__builtin_amdgcn_flat_atomic_fadd_v2f16:
20272 case AMDGPU::BI__builtin_amdgcn_flat_atomic_fadd_f32:
20273 case AMDGPU::BI__builtin_amdgcn_flat_atomic_fadd_f64:
20274 case AMDGPU::BI__builtin_amdgcn_global_atomic_fadd_v2bf16:
20275 case AMDGPU::BI__builtin_amdgcn_flat_atomic_fadd_v2bf16:
20276 BinOp = llvm::AtomicRMWInst::FAdd;
20278 case AMDGPU::BI__builtin_amdgcn_ds_fminf:
20279 case AMDGPU::BI__builtin_amdgcn_global_atomic_fmin_f64:
20280 case AMDGPU::BI__builtin_amdgcn_flat_atomic_fmin_f64:
20281 BinOp = llvm::AtomicRMWInst::FMin;
20283 case AMDGPU::BI__builtin_amdgcn_global_atomic_fmax_f64:
20284 case AMDGPU::BI__builtin_amdgcn_flat_atomic_fmax_f64:
20285 case AMDGPU::BI__builtin_amdgcn_ds_fmaxf:
20286 BinOp = llvm::AtomicRMWInst::FMax;
20292 llvm::Type *OrigTy = Val->
getType();
20297 if (BuiltinID == AMDGPU::BI__builtin_amdgcn_ds_faddf ||
20298 BuiltinID == AMDGPU::BI__builtin_amdgcn_ds_fminf ||
20299 BuiltinID == AMDGPU::BI__builtin_amdgcn_ds_fmaxf) {
20309 if (
E->getNumArgs() >= 4) {
20321 AO = AtomicOrdering::Monotonic;
20324 if (BuiltinID == AMDGPU::BI__builtin_amdgcn_ds_atomic_fadd_v2bf16 ||
20325 BuiltinID == AMDGPU::BI__builtin_amdgcn_global_atomic_fadd_v2bf16 ||
20326 BuiltinID == AMDGPU::BI__builtin_amdgcn_flat_atomic_fadd_v2bf16) {
20327 llvm::Type *V2BF16Ty = FixedVectorType::get(
20328 llvm::Type::getBFloatTy(
Builder.getContext()), 2);
20329 Val =
Builder.CreateBitCast(Val, V2BF16Ty);
20333 llvm::AtomicRMWInst *RMW =
20336 RMW->setVolatile(
true);
20338 unsigned AddrSpace = Ptr.
getType()->getAddressSpace();
20339 if (AddrSpace != llvm::AMDGPUAS::LOCAL_ADDRESS) {
20343 RMW->setMetadata(
"amdgpu.no.fine.grained.memory", EmptyMD);
20347 if (BinOp == llvm::AtomicRMWInst::FAdd && Val->
getType()->isFloatTy())
20348 RMW->setMetadata(
"amdgpu.ignore.denormal.mode", EmptyMD);
20351 return Builder.CreateBitCast(RMW, OrigTy);
20353 case AMDGPU::BI__builtin_amdgcn_s_sendmsg_rtn:
20354 case AMDGPU::BI__builtin_amdgcn_s_sendmsg_rtnl: {
20360 return Builder.CreateCall(F, {Arg});
20362 case AMDGPU::BI__builtin_amdgcn_permlane16_swap:
20363 case AMDGPU::BI__builtin_amdgcn_permlane32_swap: {
20371 CGM.
getIntrinsic(BuiltinID == AMDGPU::BI__builtin_amdgcn_permlane16_swap
20372 ? Intrinsic::amdgcn_permlane16_swap
20373 : Intrinsic::amdgcn_permlane32_swap);
20374 llvm::CallInst *
Call =
20375 Builder.CreateCall(F, {VDstOld, VSrcOld, FI, BoundCtrl});
20377 llvm::Value *Elt0 =
Builder.CreateExtractValue(
Call, 0);
20378 llvm::Value *Elt1 =
Builder.CreateExtractValue(
Call, 1);
20382 llvm::Value *Insert0 =
Builder.CreateInsertElement(
20383 llvm::PoisonValue::get(ResultType), Elt0, UINT64_C(0));
20384 llvm::Value *AsVector =
20385 Builder.CreateInsertElement(Insert0, Elt1, UINT64_C(1));
20388 case AMDGPU::BI__builtin_amdgcn_bitop3_b32:
20389 case AMDGPU::BI__builtin_amdgcn_bitop3_b16:
20391 case AMDGPU::BI__builtin_amdgcn_make_buffer_rsrc:
20392 return emitBuiltinWithOneOverloadedType<4>(
20393 *
this,
E, Intrinsic::amdgcn_make_buffer_rsrc);
20394 case AMDGPU::BI__builtin_amdgcn_raw_buffer_store_b8:
20395 case AMDGPU::BI__builtin_amdgcn_raw_buffer_store_b16:
20396 case AMDGPU::BI__builtin_amdgcn_raw_buffer_store_b32:
20397 case AMDGPU::BI__builtin_amdgcn_raw_buffer_store_b64:
20398 case AMDGPU::BI__builtin_amdgcn_raw_buffer_store_b96:
20399 case AMDGPU::BI__builtin_amdgcn_raw_buffer_store_b128:
20400 return emitBuiltinWithOneOverloadedType<5>(
20401 *
this,
E, Intrinsic::amdgcn_raw_ptr_buffer_store);
20402 case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b8:
20403 case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b16:
20404 case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b32:
20405 case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b64:
20406 case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b96:
20407 case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b128: {
20408 llvm::Type *RetTy =
nullptr;
20409 switch (BuiltinID) {
20410 case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b8:
20413 case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b16:
20416 case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b32:
20419 case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b64:
20420 RetTy = llvm::FixedVectorType::get(
Int32Ty, 2);
20422 case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b96:
20423 RetTy = llvm::FixedVectorType::get(
Int32Ty, 3);
20425 case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b128:
20426 RetTy = llvm::FixedVectorType::get(
Int32Ty, 4);
20435 case AMDGPU::BI__builtin_amdgcn_s_prefetch_data:
20436 return emitBuiltinWithOneOverloadedType<2>(
20437 *
this,
E, Intrinsic::amdgcn_s_prefetch_data);
20447 unsigned IntrinsicID,
20449 unsigned NumArgs =
E->getNumArgs() - 1;
20451 for (
unsigned I = 0; I < NumArgs; ++I)
20463 switch (BuiltinID) {
20464 case SystemZ::BI__builtin_tbegin: {
20466 Value *Control = llvm::ConstantInt::get(
Int32Ty, 0xff0c);
20468 return Builder.CreateCall(F, {TDB, Control});
20470 case SystemZ::BI__builtin_tbegin_nofloat: {
20472 Value *Control = llvm::ConstantInt::get(
Int32Ty, 0xff0c);
20474 return Builder.CreateCall(F, {TDB, Control});
20476 case SystemZ::BI__builtin_tbeginc: {
20478 Value *Control = llvm::ConstantInt::get(
Int32Ty, 0xff08);
20480 return Builder.CreateCall(F, {TDB, Control});
20482 case SystemZ::BI__builtin_tabort: {
20487 case SystemZ::BI__builtin_non_tx_store: {
20499 case SystemZ::BI__builtin_s390_vclzb:
20500 case SystemZ::BI__builtin_s390_vclzh:
20501 case SystemZ::BI__builtin_s390_vclzf:
20502 case SystemZ::BI__builtin_s390_vclzg: {
20505 Value *Undef = ConstantInt::get(
Builder.getInt1Ty(),
false);
20507 return Builder.CreateCall(F, {
X, Undef});
20510 case SystemZ::BI__builtin_s390_vctzb:
20511 case SystemZ::BI__builtin_s390_vctzh:
20512 case SystemZ::BI__builtin_s390_vctzf:
20513 case SystemZ::BI__builtin_s390_vctzg: {
20516 Value *Undef = ConstantInt::get(
Builder.getInt1Ty(),
false);
20518 return Builder.CreateCall(F, {
X, Undef});
20521 case SystemZ::BI__builtin_s390_verllb:
20522 case SystemZ::BI__builtin_s390_verllh:
20523 case SystemZ::BI__builtin_s390_verllf:
20524 case SystemZ::BI__builtin_s390_verllg: {
20529 unsigned NumElts = cast<llvm::FixedVectorType>(ResultType)->getNumElements();
20530 Amt =
Builder.CreateIntCast(Amt, ResultType->getScalarType(),
false);
20531 Amt =
Builder.CreateVectorSplat(NumElts, Amt);
20533 return Builder.CreateCall(F, { Src, Src, Amt });
20536 case SystemZ::BI__builtin_s390_verllvb:
20537 case SystemZ::BI__builtin_s390_verllvh:
20538 case SystemZ::BI__builtin_s390_verllvf:
20539 case SystemZ::BI__builtin_s390_verllvg: {
20544 return Builder.CreateCall(F, { Src, Src, Amt });
20547 case SystemZ::BI__builtin_s390_vfsqsb:
20548 case SystemZ::BI__builtin_s390_vfsqdb: {
20551 if (
Builder.getIsFPConstrained()) {
20553 return Builder.CreateConstrainedFPCall(F, {
X });
20559 case SystemZ::BI__builtin_s390_vfmasb:
20560 case SystemZ::BI__builtin_s390_vfmadb: {
20565 if (
Builder.getIsFPConstrained()) {
20567 return Builder.CreateConstrainedFPCall(F, {
X, Y, Z});
20570 return Builder.CreateCall(F, {
X, Y, Z});
20573 case SystemZ::BI__builtin_s390_vfmssb:
20574 case SystemZ::BI__builtin_s390_vfmsdb: {
20579 if (
Builder.getIsFPConstrained()) {
20581 return Builder.CreateConstrainedFPCall(F, {
X, Y,
Builder.CreateFNeg(Z,
"neg")});
20587 case SystemZ::BI__builtin_s390_vfnmasb:
20588 case SystemZ::BI__builtin_s390_vfnmadb: {
20593 if (
Builder.getIsFPConstrained()) {
20595 return Builder.CreateFNeg(
Builder.CreateConstrainedFPCall(F, {X, Y, Z}),
"neg");
20598 return Builder.CreateFNeg(
Builder.CreateCall(F, {X, Y, Z}),
"neg");
20601 case SystemZ::BI__builtin_s390_vfnmssb:
20602 case SystemZ::BI__builtin_s390_vfnmsdb: {
20607 if (
Builder.getIsFPConstrained()) {
20610 return Builder.CreateFNeg(
Builder.CreateConstrainedFPCall(F, {X, Y, NegZ}));
20617 case SystemZ::BI__builtin_s390_vflpsb:
20618 case SystemZ::BI__builtin_s390_vflpdb: {
20624 case SystemZ::BI__builtin_s390_vflnsb:
20625 case SystemZ::BI__builtin_s390_vflndb: {
20631 case SystemZ::BI__builtin_s390_vfisb:
20632 case SystemZ::BI__builtin_s390_vfidb: {
20640 Intrinsic::ID
ID = Intrinsic::not_intrinsic;
20642 switch (M4.getZExtValue()) {
20645 switch (M5.getZExtValue()) {
20647 case 0:
ID = Intrinsic::rint;
20648 CI = Intrinsic::experimental_constrained_rint;
break;
20652 switch (M5.getZExtValue()) {
20654 case 0:
ID = Intrinsic::nearbyint;
20655 CI = Intrinsic::experimental_constrained_nearbyint;
break;
20656 case 1:
ID = Intrinsic::round;
20657 CI = Intrinsic::experimental_constrained_round;
break;
20658 case 5:
ID = Intrinsic::trunc;
20659 CI = Intrinsic::experimental_constrained_trunc;
break;
20660 case 6:
ID = Intrinsic::ceil;
20661 CI = Intrinsic::experimental_constrained_ceil;
break;
20662 case 7:
ID = Intrinsic::floor;
20663 CI = Intrinsic::experimental_constrained_floor;
break;
20667 if (ID != Intrinsic::not_intrinsic) {
20668 if (
Builder.getIsFPConstrained()) {
20670 return Builder.CreateConstrainedFPCall(F,
X);
20676 switch (BuiltinID) {
20677 case SystemZ::BI__builtin_s390_vfisb:
ID = Intrinsic::s390_vfisb;
break;
20678 case SystemZ::BI__builtin_s390_vfidb:
ID = Intrinsic::s390_vfidb;
break;
20679 default: llvm_unreachable(
"Unknown BuiltinID");
20684 return Builder.CreateCall(F, {
X, M4Value, M5Value});
20686 case SystemZ::BI__builtin_s390_vfmaxsb:
20687 case SystemZ::BI__builtin_s390_vfmaxdb: {
20695 Intrinsic::ID
ID = Intrinsic::not_intrinsic;
20697 switch (M4.getZExtValue()) {
20699 case 4:
ID = Intrinsic::maxnum;
20700 CI = Intrinsic::experimental_constrained_maxnum;
break;
20702 if (ID != Intrinsic::not_intrinsic) {
20703 if (
Builder.getIsFPConstrained()) {
20705 return Builder.CreateConstrainedFPCall(F, {
X, Y});
20708 return Builder.CreateCall(F, {
X, Y});
20711 switch (BuiltinID) {
20712 case SystemZ::BI__builtin_s390_vfmaxsb:
ID = Intrinsic::s390_vfmaxsb;
break;
20713 case SystemZ::BI__builtin_s390_vfmaxdb:
ID = Intrinsic::s390_vfmaxdb;
break;
20714 default: llvm_unreachable(
"Unknown BuiltinID");
20718 return Builder.CreateCall(F, {
X, Y, M4Value});
20720 case SystemZ::BI__builtin_s390_vfminsb:
20721 case SystemZ::BI__builtin_s390_vfmindb: {
20729 Intrinsic::ID
ID = Intrinsic::not_intrinsic;
20731 switch (M4.getZExtValue()) {
20733 case 4:
ID = Intrinsic::minnum;
20734 CI = Intrinsic::experimental_constrained_minnum;
break;
20736 if (ID != Intrinsic::not_intrinsic) {
20737 if (
Builder.getIsFPConstrained()) {
20739 return Builder.CreateConstrainedFPCall(F, {
X, Y});
20742 return Builder.CreateCall(F, {
X, Y});
20745 switch (BuiltinID) {
20746 case SystemZ::BI__builtin_s390_vfminsb:
ID = Intrinsic::s390_vfminsb;
break;
20747 case SystemZ::BI__builtin_s390_vfmindb:
ID = Intrinsic::s390_vfmindb;
break;
20748 default: llvm_unreachable(
"Unknown BuiltinID");
20752 return Builder.CreateCall(F, {
X, Y, M4Value});
20755 case SystemZ::BI__builtin_s390_vlbrh:
20756 case SystemZ::BI__builtin_s390_vlbrf:
20757 case SystemZ::BI__builtin_s390_vlbrg: {
20766#define INTRINSIC_WITH_CC(NAME) \
20767 case SystemZ::BI__builtin_##NAME: \
20768 return EmitSystemZIntrinsicWithCC(*this, Intrinsic::NAME, E)
20847#undef INTRINSIC_WITH_CC
20856struct NVPTXMmaLdstInfo {
20857 unsigned NumResults;
20863#define MMA_INTR(geom_op_type, layout) \
20864 Intrinsic::nvvm_wmma_##geom_op_type##_##layout##_stride
20865#define MMA_LDST(n, geom_op_type) \
20866 { n, MMA_INTR(geom_op_type, col), MMA_INTR(geom_op_type, row) }
20868static NVPTXMmaLdstInfo getNVPTXMmaLdstInfo(
unsigned BuiltinID) {
20869 switch (BuiltinID) {
20871 case NVPTX::BI__hmma_m16n16k16_ld_a:
20872 return MMA_LDST(8, m16n16k16_load_a_f16);
20873 case NVPTX::BI__hmma_m16n16k16_ld_b:
20874 return MMA_LDST(8, m16n16k16_load_b_f16);
20875 case NVPTX::BI__hmma_m16n16k16_ld_c_f16:
20876 return MMA_LDST(4, m16n16k16_load_c_f16);
20877 case NVPTX::BI__hmma_m16n16k16_ld_c_f32:
20878 return MMA_LDST(8, m16n16k16_load_c_f32);
20879 case NVPTX::BI__hmma_m32n8k16_ld_a:
20880 return MMA_LDST(8, m32n8k16_load_a_f16);
20881 case NVPTX::BI__hmma_m32n8k16_ld_b:
20882 return MMA_LDST(8, m32n8k16_load_b_f16);
20883 case NVPTX::BI__hmma_m32n8k16_ld_c_f16:
20884 return MMA_LDST(4, m32n8k16_load_c_f16);
20885 case NVPTX::BI__hmma_m32n8k16_ld_c_f32:
20886 return MMA_LDST(8, m32n8k16_load_c_f32);
20887 case NVPTX::BI__hmma_m8n32k16_ld_a:
20888 return MMA_LDST(8, m8n32k16_load_a_f16);
20889 case NVPTX::BI__hmma_m8n32k16_ld_b:
20890 return MMA_LDST(8, m8n32k16_load_b_f16);
20891 case NVPTX::BI__hmma_m8n32k16_ld_c_f16:
20892 return MMA_LDST(4, m8n32k16_load_c_f16);
20893 case NVPTX::BI__hmma_m8n32k16_ld_c_f32:
20894 return MMA_LDST(8, m8n32k16_load_c_f32);
20897 case NVPTX::BI__imma_m16n16k16_ld_a_s8:
20898 return MMA_LDST(2, m16n16k16_load_a_s8);
20899 case NVPTX::BI__imma_m16n16k16_ld_a_u8:
20900 return MMA_LDST(2, m16n16k16_load_a_u8);
20901 case NVPTX::BI__imma_m16n16k16_ld_b_s8:
20902 return MMA_LDST(2, m16n16k16_load_b_s8);
20903 case NVPTX::BI__imma_m16n16k16_ld_b_u8:
20904 return MMA_LDST(2, m16n16k16_load_b_u8);
20905 case NVPTX::BI__imma_m16n16k16_ld_c:
20906 return MMA_LDST(8, m16n16k16_load_c_s32);
20907 case NVPTX::BI__imma_m32n8k16_ld_a_s8:
20908 return MMA_LDST(4, m32n8k16_load_a_s8);
20909 case NVPTX::BI__imma_m32n8k16_ld_a_u8:
20910 return MMA_LDST(4, m32n8k16_load_a_u8);
20911 case NVPTX::BI__imma_m32n8k16_ld_b_s8:
20912 return MMA_LDST(1, m32n8k16_load_b_s8);
20913 case NVPTX::BI__imma_m32n8k16_ld_b_u8:
20914 return MMA_LDST(1, m32n8k16_load_b_u8);
20915 case NVPTX::BI__imma_m32n8k16_ld_c:
20916 return MMA_LDST(8, m32n8k16_load_c_s32);
20917 case NVPTX::BI__imma_m8n32k16_ld_a_s8:
20918 return MMA_LDST(1, m8n32k16_load_a_s8);
20919 case NVPTX::BI__imma_m8n32k16_ld_a_u8:
20920 return MMA_LDST(1, m8n32k16_load_a_u8);
20921 case NVPTX::BI__imma_m8n32k16_ld_b_s8:
20922 return MMA_LDST(4, m8n32k16_load_b_s8);
20923 case NVPTX::BI__imma_m8n32k16_ld_b_u8:
20924 return MMA_LDST(4, m8n32k16_load_b_u8);
20925 case NVPTX::BI__imma_m8n32k16_ld_c:
20926 return MMA_LDST(8, m8n32k16_load_c_s32);
20930 case NVPTX::BI__imma_m8n8k32_ld_a_s4:
20931 return {1, 0,
MMA_INTR(m8n8k32_load_a_s4, row)};
20932 case NVPTX::BI__imma_m8n8k32_ld_a_u4:
20933 return {1, 0,
MMA_INTR(m8n8k32_load_a_u4, row)};
20934 case NVPTX::BI__imma_m8n8k32_ld_b_s4:
20935 return {1,
MMA_INTR(m8n8k32_load_b_s4, col), 0};
20936 case NVPTX::BI__imma_m8n8k32_ld_b_u4:
20937 return {1,
MMA_INTR(m8n8k32_load_b_u4, col), 0};
20938 case NVPTX::BI__imma_m8n8k32_ld_c:
20939 return MMA_LDST(2, m8n8k32_load_c_s32);
20940 case NVPTX::BI__bmma_m8n8k128_ld_a_b1:
20941 return {1, 0,
MMA_INTR(m8n8k128_load_a_b1, row)};
20942 case NVPTX::BI__bmma_m8n8k128_ld_b_b1:
20943 return {1,
MMA_INTR(m8n8k128_load_b_b1, col), 0};
20944 case NVPTX::BI__bmma_m8n8k128_ld_c:
20945 return MMA_LDST(2, m8n8k128_load_c_s32);
20948 case NVPTX::BI__dmma_m8n8k4_ld_a:
20949 return MMA_LDST(1, m8n8k4_load_a_f64);
20950 case NVPTX::BI__dmma_m8n8k4_ld_b:
20951 return MMA_LDST(1, m8n8k4_load_b_f64);
20952 case NVPTX::BI__dmma_m8n8k4_ld_c:
20953 return MMA_LDST(2, m8n8k4_load_c_f64);
20956 case NVPTX::BI__mma_bf16_m16n16k16_ld_a:
20957 return MMA_LDST(4, m16n16k16_load_a_bf16);
20958 case NVPTX::BI__mma_bf16_m16n16k16_ld_b:
20959 return MMA_LDST(4, m16n16k16_load_b_bf16);
20960 case NVPTX::BI__mma_bf16_m8n32k16_ld_a:
20961 return MMA_LDST(2, m8n32k16_load_a_bf16);
20962 case NVPTX::BI__mma_bf16_m8n32k16_ld_b:
20963 return MMA_LDST(8, m8n32k16_load_b_bf16);
20964 case NVPTX::BI__mma_bf16_m32n8k16_ld_a:
20965 return MMA_LDST(8, m32n8k16_load_a_bf16);
20966 case NVPTX::BI__mma_bf16_m32n8k16_ld_b:
20967 return MMA_LDST(2, m32n8k16_load_b_bf16);
20968 case NVPTX::BI__mma_tf32_m16n16k8_ld_a:
20969 return MMA_LDST(4, m16n16k8_load_a_tf32);
20970 case NVPTX::BI__mma_tf32_m16n16k8_ld_b:
20971 return MMA_LDST(4, m16n16k8_load_b_tf32);
20972 case NVPTX::BI__mma_tf32_m16n16k8_ld_c:
20973 return MMA_LDST(8, m16n16k8_load_c_f32);
20979 case NVPTX::BI__hmma_m16n16k16_st_c_f16:
20980 return MMA_LDST(4, m16n16k16_store_d_f16);
20981 case NVPTX::BI__hmma_m16n16k16_st_c_f32:
20982 return MMA_LDST(8, m16n16k16_store_d_f32);
20983 case NVPTX::BI__hmma_m32n8k16_st_c_f16:
20984 return MMA_LDST(4, m32n8k16_store_d_f16);
20985 case NVPTX::BI__hmma_m32n8k16_st_c_f32:
20986 return MMA_LDST(8, m32n8k16_store_d_f32);
20987 case NVPTX::BI__hmma_m8n32k16_st_c_f16:
20988 return MMA_LDST(4, m8n32k16_store_d_f16);
20989 case NVPTX::BI__hmma_m8n32k16_st_c_f32:
20990 return MMA_LDST(8, m8n32k16_store_d_f32);
20995 case NVPTX::BI__imma_m16n16k16_st_c_i32:
20996 return MMA_LDST(8, m16n16k16_store_d_s32);
20997 case NVPTX::BI__imma_m32n8k16_st_c_i32:
20998 return MMA_LDST(8, m32n8k16_store_d_s32);
20999 case NVPTX::BI__imma_m8n32k16_st_c_i32:
21000 return MMA_LDST(8, m8n32k16_store_d_s32);
21001 case NVPTX::BI__imma_m8n8k32_st_c_i32:
21002 return MMA_LDST(2, m8n8k32_store_d_s32);
21003 case NVPTX::BI__bmma_m8n8k128_st_c_i32:
21004 return MMA_LDST(2, m8n8k128_store_d_s32);
21007 case NVPTX::BI__dmma_m8n8k4_st_c_f64:
21008 return MMA_LDST(2, m8n8k4_store_d_f64);
21011 case NVPTX::BI__mma_m16n16k8_st_c_f32:
21012 return MMA_LDST(8, m16n16k8_store_d_f32);
21015 llvm_unreachable(
"Unknown MMA builtin");
21022struct NVPTXMmaInfo {
21031 std::array<unsigned, 8> Variants;
21033 unsigned getMMAIntrinsic(
int Layout,
bool Satf) {
21034 unsigned Index = Layout + 4 * Satf;
21035 if (Index >= Variants.size())
21037 return Variants[Index];
21043static NVPTXMmaInfo getNVPTXMmaInfo(
unsigned BuiltinID) {
21045#define MMA_VARIANTS(geom, type) \
21046 Intrinsic::nvvm_wmma_##geom##_mma_row_row_##type, \
21047 Intrinsic::nvvm_wmma_##geom##_mma_row_col_##type, \
21048 Intrinsic::nvvm_wmma_##geom##_mma_col_row_##type, \
21049 Intrinsic::nvvm_wmma_##geom##_mma_col_col_##type
21050#define MMA_SATF_VARIANTS(geom, type) \
21051 MMA_VARIANTS(geom, type), \
21052 Intrinsic::nvvm_wmma_##geom##_mma_row_row_##type##_satfinite, \
21053 Intrinsic::nvvm_wmma_##geom##_mma_row_col_##type##_satfinite, \
21054 Intrinsic::nvvm_wmma_##geom##_mma_col_row_##type##_satfinite, \
21055 Intrinsic::nvvm_wmma_##geom##_mma_col_col_##type##_satfinite
21057#define MMA_VARIANTS_I4(geom, type) \
21059 Intrinsic::nvvm_wmma_##geom##_mma_row_col_##type, \
21063 Intrinsic::nvvm_wmma_##geom##_mma_row_col_##type##_satfinite, \
21067#define MMA_VARIANTS_B1_XOR(geom, type) \
21069 Intrinsic::nvvm_wmma_##geom##_mma_xor_popc_row_col_##type, \
21076#define MMA_VARIANTS_B1_AND(geom, type) \
21078 Intrinsic::nvvm_wmma_##geom##_mma_and_popc_row_col_##type, \
21086 switch (BuiltinID) {
21090 case NVPTX::BI__hmma_m16n16k16_mma_f16f16:
21092 case NVPTX::BI__hmma_m16n16k16_mma_f32f16:
21094 case NVPTX::BI__hmma_m16n16k16_mma_f16f32:
21096 case NVPTX::BI__hmma_m16n16k16_mma_f32f32:
21098 case NVPTX::BI__hmma_m32n8k16_mma_f16f16:
21100 case NVPTX::BI__hmma_m32n8k16_mma_f32f16:
21102 case NVPTX::BI__hmma_m32n8k16_mma_f16f32:
21104 case NVPTX::BI__hmma_m32n8k16_mma_f32f32:
21106 case NVPTX::BI__hmma_m8n32k16_mma_f16f16:
21108 case NVPTX::BI__hmma_m8n32k16_mma_f32f16:
21110 case NVPTX::BI__hmma_m8n32k16_mma_f16f32:
21112 case NVPTX::BI__hmma_m8n32k16_mma_f32f32:
21116 case NVPTX::BI__imma_m16n16k16_mma_s8:
21118 case NVPTX::BI__imma_m16n16k16_mma_u8:
21120 case NVPTX::BI__imma_m32n8k16_mma_s8:
21122 case NVPTX::BI__imma_m32n8k16_mma_u8:
21124 case NVPTX::BI__imma_m8n32k16_mma_s8:
21126 case NVPTX::BI__imma_m8n32k16_mma_u8:
21130 case NVPTX::BI__imma_m8n8k32_mma_s4:
21132 case NVPTX::BI__imma_m8n8k32_mma_u4:
21134 case NVPTX::BI__bmma_m8n8k128_mma_xor_popc_b1:
21136 case NVPTX::BI__bmma_m8n8k128_mma_and_popc_b1:
21140 case NVPTX::BI__dmma_m8n8k4_mma_f64:
21144 case NVPTX::BI__mma_bf16_m16n16k16_mma_f32:
21145 return {4, 4, 8, 8, {{
MMA_VARIANTS(m16n16k16, bf16)}}};
21146 case NVPTX::BI__mma_bf16_m8n32k16_mma_f32:
21147 return {2, 8, 8, 8, {{
MMA_VARIANTS(m8n32k16, bf16)}}};
21148 case NVPTX::BI__mma_bf16_m32n8k16_mma_f32:
21149 return {8, 2, 8, 8, {{
MMA_VARIANTS(m32n8k16, bf16)}}};
21150 case NVPTX::BI__mma_tf32_m16n16k8_mma_f32:
21151 return {4, 4, 8, 8, {{
MMA_VARIANTS(m16n16k8, tf32)}}};
21153 llvm_unreachable(
"Unexpected builtin ID.");
21156#undef MMA_SATF_VARIANTS
21157#undef MMA_VARIANTS_I4
21158#undef MMA_VARIANTS_B1_AND
21159#undef MMA_VARIANTS_B1_XOR
21168 return CGF.
Builder.CreateCall(
21170 {Ptr, ConstantInt::get(CGF.Builder.getInt32Ty(), Align.getQuantity())});
21182 MDNode *MD = MDNode::get(CGF.
Builder.getContext(), {});
21183 LD->setMetadata(LLVMContext::MD_invariant_load, MD);
21191 llvm::Type *ElemTy =
21193 return CGF.
Builder.CreateCall(
21195 {Ptr, CGF.EmitScalarExpr(E->getArg(1))});
21198static Value *MakeCpAsync(
unsigned IntrinsicID,
unsigned IntrinsicIDS,
21201 return E->getNumArgs() == 3
21203 {CGF.EmitScalarExpr(E->getArg(0)),
21204 CGF.EmitScalarExpr(E->getArg(1)),
21205 CGF.EmitScalarExpr(E->getArg(2))})
21207 {CGF.EmitScalarExpr(E->getArg(0)),
21208 CGF.EmitScalarExpr(E->getArg(1))});
21211static Value *MakeHalfType(
unsigned IntrinsicID,
unsigned BuiltinID,
21214 if (!(
C.getLangOpts().NativeHalfType ||
21215 !
C.getTargetInfo().useFP16ConversionIntrinsics())) {
21217 " requires native half type support.");
21221 if (BuiltinID == NVPTX::BI__nvvm_ldg_h || BuiltinID == NVPTX::BI__nvvm_ldg_h2)
21222 return MakeLdg(CGF,
E);
21224 if (IntrinsicID == Intrinsic::nvvm_ldu_global_f)
21225 return MakeLdu(IntrinsicID, CGF,
E);
21229 auto *FTy = F->getFunctionType();
21230 unsigned ICEArguments = 0;
21232 C.GetBuiltinType(BuiltinID, Error, &ICEArguments);
21234 for (
unsigned i = 0, e =
E->getNumArgs(); i != e; ++i) {
21235 assert((ICEArguments & (1 << i)) == 0);
21237 auto *PTy = FTy->getParamType(i);
21238 if (PTy != ArgValue->
getType())
21239 ArgValue = CGF.
Builder.CreateBitCast(ArgValue, PTy);
21240 Args.push_back(ArgValue);
21243 return CGF.
Builder.CreateCall(F, Args);
21249 switch (BuiltinID) {
21250 case NVPTX::BI__nvvm_atom_add_gen_i:
21251 case NVPTX::BI__nvvm_atom_add_gen_l:
21252 case NVPTX::BI__nvvm_atom_add_gen_ll:
21255 case NVPTX::BI__nvvm_atom_sub_gen_i:
21256 case NVPTX::BI__nvvm_atom_sub_gen_l:
21257 case NVPTX::BI__nvvm_atom_sub_gen_ll:
21260 case NVPTX::BI__nvvm_atom_and_gen_i:
21261 case NVPTX::BI__nvvm_atom_and_gen_l:
21262 case NVPTX::BI__nvvm_atom_and_gen_ll:
21265 case NVPTX::BI__nvvm_atom_or_gen_i:
21266 case NVPTX::BI__nvvm_atom_or_gen_l:
21267 case NVPTX::BI__nvvm_atom_or_gen_ll:
21270 case NVPTX::BI__nvvm_atom_xor_gen_i:
21271 case NVPTX::BI__nvvm_atom_xor_gen_l:
21272 case NVPTX::BI__nvvm_atom_xor_gen_ll:
21275 case NVPTX::BI__nvvm_atom_xchg_gen_i:
21276 case NVPTX::BI__nvvm_atom_xchg_gen_l:
21277 case NVPTX::BI__nvvm_atom_xchg_gen_ll:
21280 case NVPTX::BI__nvvm_atom_max_gen_i:
21281 case NVPTX::BI__nvvm_atom_max_gen_l:
21282 case NVPTX::BI__nvvm_atom_max_gen_ll:
21285 case NVPTX::BI__nvvm_atom_max_gen_ui:
21286 case NVPTX::BI__nvvm_atom_max_gen_ul:
21287 case NVPTX::BI__nvvm_atom_max_gen_ull:
21290 case NVPTX::BI__nvvm_atom_min_gen_i:
21291 case NVPTX::BI__nvvm_atom_min_gen_l:
21292 case NVPTX::BI__nvvm_atom_min_gen_ll:
21295 case NVPTX::BI__nvvm_atom_min_gen_ui:
21296 case NVPTX::BI__nvvm_atom_min_gen_ul:
21297 case NVPTX::BI__nvvm_atom_min_gen_ull:
21300 case NVPTX::BI__nvvm_atom_cas_gen_us:
21301 case NVPTX::BI__nvvm_atom_cas_gen_i:
21302 case NVPTX::BI__nvvm_atom_cas_gen_l:
21303 case NVPTX::BI__nvvm_atom_cas_gen_ll:
21308 case NVPTX::BI__nvvm_atom_add_gen_f:
21309 case NVPTX::BI__nvvm_atom_add_gen_d: {
21314 AtomicOrdering::SequentiallyConsistent);
21317 case NVPTX::BI__nvvm_atom_inc_gen_ui: {
21322 return Builder.CreateCall(FnALI32, {Ptr, Val});
21325 case NVPTX::BI__nvvm_atom_dec_gen_ui: {
21330 return Builder.CreateCall(FnALD32, {Ptr, Val});
21333 case NVPTX::BI__nvvm_ldg_c:
21334 case NVPTX::BI__nvvm_ldg_sc:
21335 case NVPTX::BI__nvvm_ldg_c2:
21336 case NVPTX::BI__nvvm_ldg_sc2:
21337 case NVPTX::BI__nvvm_ldg_c4:
21338 case NVPTX::BI__nvvm_ldg_sc4:
21339 case NVPTX::BI__nvvm_ldg_s:
21340 case NVPTX::BI__nvvm_ldg_s2:
21341 case NVPTX::BI__nvvm_ldg_s4:
21342 case NVPTX::BI__nvvm_ldg_i:
21343 case NVPTX::BI__nvvm_ldg_i2:
21344 case NVPTX::BI__nvvm_ldg_i4:
21345 case NVPTX::BI__nvvm_ldg_l:
21346 case NVPTX::BI__nvvm_ldg_l2:
21347 case NVPTX::BI__nvvm_ldg_ll:
21348 case NVPTX::BI__nvvm_ldg_ll2:
21349 case NVPTX::BI__nvvm_ldg_uc:
21350 case NVPTX::BI__nvvm_ldg_uc2:
21351 case NVPTX::BI__nvvm_ldg_uc4:
21352 case NVPTX::BI__nvvm_ldg_us:
21353 case NVPTX::BI__nvvm_ldg_us2:
21354 case NVPTX::BI__nvvm_ldg_us4:
21355 case NVPTX::BI__nvvm_ldg_ui:
21356 case NVPTX::BI__nvvm_ldg_ui2:
21357 case NVPTX::BI__nvvm_ldg_ui4:
21358 case NVPTX::BI__nvvm_ldg_ul:
21359 case NVPTX::BI__nvvm_ldg_ul2:
21360 case NVPTX::BI__nvvm_ldg_ull:
21361 case NVPTX::BI__nvvm_ldg_ull2:
21362 case NVPTX::BI__nvvm_ldg_f:
21363 case NVPTX::BI__nvvm_ldg_f2:
21364 case NVPTX::BI__nvvm_ldg_f4:
21365 case NVPTX::BI__nvvm_ldg_d:
21366 case NVPTX::BI__nvvm_ldg_d2:
21370 return MakeLdg(*
this,
E);
21372 case NVPTX::BI__nvvm_ldu_c:
21373 case NVPTX::BI__nvvm_ldu_sc:
21374 case NVPTX::BI__nvvm_ldu_c2:
21375 case NVPTX::BI__nvvm_ldu_sc2:
21376 case NVPTX::BI__nvvm_ldu_c4:
21377 case NVPTX::BI__nvvm_ldu_sc4:
21378 case NVPTX::BI__nvvm_ldu_s:
21379 case NVPTX::BI__nvvm_ldu_s2:
21380 case NVPTX::BI__nvvm_ldu_s4:
21381 case NVPTX::BI__nvvm_ldu_i:
21382 case NVPTX::BI__nvvm_ldu_i2:
21383 case NVPTX::BI__nvvm_ldu_i4:
21384 case NVPTX::BI__nvvm_ldu_l:
21385 case NVPTX::BI__nvvm_ldu_l2:
21386 case NVPTX::BI__nvvm_ldu_ll:
21387 case NVPTX::BI__nvvm_ldu_ll2:
21388 case NVPTX::BI__nvvm_ldu_uc:
21389 case NVPTX::BI__nvvm_ldu_uc2:
21390 case NVPTX::BI__nvvm_ldu_uc4:
21391 case NVPTX::BI__nvvm_ldu_us:
21392 case NVPTX::BI__nvvm_ldu_us2:
21393 case NVPTX::BI__nvvm_ldu_us4:
21394 case NVPTX::BI__nvvm_ldu_ui:
21395 case NVPTX::BI__nvvm_ldu_ui2:
21396 case NVPTX::BI__nvvm_ldu_ui4:
21397 case NVPTX::BI__nvvm_ldu_ul:
21398 case NVPTX::BI__nvvm_ldu_ul2:
21399 case NVPTX::BI__nvvm_ldu_ull:
21400 case NVPTX::BI__nvvm_ldu_ull2:
21401 return MakeLdu(Intrinsic::nvvm_ldu_global_i, *
this,
E);
21402 case NVPTX::BI__nvvm_ldu_f:
21403 case NVPTX::BI__nvvm_ldu_f2:
21404 case NVPTX::BI__nvvm_ldu_f4:
21405 case NVPTX::BI__nvvm_ldu_d:
21406 case NVPTX::BI__nvvm_ldu_d2:
21407 return MakeLdu(Intrinsic::nvvm_ldu_global_f, *
this,
E);
21409 case NVPTX::BI__nvvm_atom_cta_add_gen_i:
21410 case NVPTX::BI__nvvm_atom_cta_add_gen_l:
21411 case NVPTX::BI__nvvm_atom_cta_add_gen_ll:
21412 return MakeScopedAtomic(Intrinsic::nvvm_atomic_add_gen_i_cta, *
this,
E);
21413 case NVPTX::BI__nvvm_atom_sys_add_gen_i:
21414 case NVPTX::BI__nvvm_atom_sys_add_gen_l:
21415 case NVPTX::BI__nvvm_atom_sys_add_gen_ll:
21416 return MakeScopedAtomic(Intrinsic::nvvm_atomic_add_gen_i_sys, *
this,
E);
21417 case NVPTX::BI__nvvm_atom_cta_add_gen_f:
21418 case NVPTX::BI__nvvm_atom_cta_add_gen_d:
21419 return MakeScopedAtomic(Intrinsic::nvvm_atomic_add_gen_f_cta, *
this,
E);
21420 case NVPTX::BI__nvvm_atom_sys_add_gen_f:
21421 case NVPTX::BI__nvvm_atom_sys_add_gen_d:
21422 return MakeScopedAtomic(Intrinsic::nvvm_atomic_add_gen_f_sys, *
this,
E);
21423 case NVPTX::BI__nvvm_atom_cta_xchg_gen_i:
21424 case NVPTX::BI__nvvm_atom_cta_xchg_gen_l:
21425 case NVPTX::BI__nvvm_atom_cta_xchg_gen_ll:
21426 return MakeScopedAtomic(Intrinsic::nvvm_atomic_exch_gen_i_cta, *
this,
E);
21427 case NVPTX::BI__nvvm_atom_sys_xchg_gen_i:
21428 case NVPTX::BI__nvvm_atom_sys_xchg_gen_l:
21429 case NVPTX::BI__nvvm_atom_sys_xchg_gen_ll:
21430 return MakeScopedAtomic(Intrinsic::nvvm_atomic_exch_gen_i_sys, *
this,
E);
21431 case NVPTX::BI__nvvm_atom_cta_max_gen_i:
21432 case NVPTX::BI__nvvm_atom_cta_max_gen_ui:
21433 case NVPTX::BI__nvvm_atom_cta_max_gen_l:
21434 case NVPTX::BI__nvvm_atom_cta_max_gen_ul:
21435 case NVPTX::BI__nvvm_atom_cta_max_gen_ll:
21436 case NVPTX::BI__nvvm_atom_cta_max_gen_ull:
21437 return MakeScopedAtomic(Intrinsic::nvvm_atomic_max_gen_i_cta, *
this,
E);
21438 case NVPTX::BI__nvvm_atom_sys_max_gen_i:
21439 case NVPTX::BI__nvvm_atom_sys_max_gen_ui:
21440 case NVPTX::BI__nvvm_atom_sys_max_gen_l:
21441 case NVPTX::BI__nvvm_atom_sys_max_gen_ul:
21442 case NVPTX::BI__nvvm_atom_sys_max_gen_ll:
21443 case NVPTX::BI__nvvm_atom_sys_max_gen_ull:
21444 return MakeScopedAtomic(Intrinsic::nvvm_atomic_max_gen_i_sys, *
this,
E);
21445 case NVPTX::BI__nvvm_atom_cta_min_gen_i:
21446 case NVPTX::BI__nvvm_atom_cta_min_gen_ui:
21447 case NVPTX::BI__nvvm_atom_cta_min_gen_l:
21448 case NVPTX::BI__nvvm_atom_cta_min_gen_ul:
21449 case NVPTX::BI__nvvm_atom_cta_min_gen_ll:
21450 case NVPTX::BI__nvvm_atom_cta_min_gen_ull:
21451 return MakeScopedAtomic(Intrinsic::nvvm_atomic_min_gen_i_cta, *
this,
E);
21452 case NVPTX::BI__nvvm_atom_sys_min_gen_i:
21453 case NVPTX::BI__nvvm_atom_sys_min_gen_ui:
21454 case NVPTX::BI__nvvm_atom_sys_min_gen_l:
21455 case NVPTX::BI__nvvm_atom_sys_min_gen_ul:
21456 case NVPTX::BI__nvvm_atom_sys_min_gen_ll:
21457 case NVPTX::BI__nvvm_atom_sys_min_gen_ull:
21458 return MakeScopedAtomic(Intrinsic::nvvm_atomic_min_gen_i_sys, *
this,
E);
21459 case NVPTX::BI__nvvm_atom_cta_inc_gen_ui:
21460 return MakeScopedAtomic(Intrinsic::nvvm_atomic_inc_gen_i_cta, *
this,
E);
21461 case NVPTX::BI__nvvm_atom_cta_dec_gen_ui:
21462 return MakeScopedAtomic(Intrinsic::nvvm_atomic_dec_gen_i_cta, *
this,
E);
21463 case NVPTX::BI__nvvm_atom_sys_inc_gen_ui:
21464 return MakeScopedAtomic(Intrinsic::nvvm_atomic_inc_gen_i_sys, *
this,
E);
21465 case NVPTX::BI__nvvm_atom_sys_dec_gen_ui:
21466 return MakeScopedAtomic(Intrinsic::nvvm_atomic_dec_gen_i_sys, *
this,
E);
21467 case NVPTX::BI__nvvm_atom_cta_and_gen_i:
21468 case NVPTX::BI__nvvm_atom_cta_and_gen_l:
21469 case NVPTX::BI__nvvm_atom_cta_and_gen_ll:
21470 return MakeScopedAtomic(Intrinsic::nvvm_atomic_and_gen_i_cta, *
this,
E);
21471 case NVPTX::BI__nvvm_atom_sys_and_gen_i:
21472 case NVPTX::BI__nvvm_atom_sys_and_gen_l:
21473 case NVPTX::BI__nvvm_atom_sys_and_gen_ll:
21474 return MakeScopedAtomic(Intrinsic::nvvm_atomic_and_gen_i_sys, *
this,
E);
21475 case NVPTX::BI__nvvm_atom_cta_or_gen_i:
21476 case NVPTX::BI__nvvm_atom_cta_or_gen_l:
21477 case NVPTX::BI__nvvm_atom_cta_or_gen_ll:
21478 return MakeScopedAtomic(Intrinsic::nvvm_atomic_or_gen_i_cta, *
this,
E);
21479 case NVPTX::BI__nvvm_atom_sys_or_gen_i:
21480 case NVPTX::BI__nvvm_atom_sys_or_gen_l:
21481 case NVPTX::BI__nvvm_atom_sys_or_gen_ll:
21482 return MakeScopedAtomic(Intrinsic::nvvm_atomic_or_gen_i_sys, *
this,
E);
21483 case NVPTX::BI__nvvm_atom_cta_xor_gen_i:
21484 case NVPTX::BI__nvvm_atom_cta_xor_gen_l:
21485 case NVPTX::BI__nvvm_atom_cta_xor_gen_ll:
21486 return MakeScopedAtomic(Intrinsic::nvvm_atomic_xor_gen_i_cta, *
this,
E);
21487 case NVPTX::BI__nvvm_atom_sys_xor_gen_i:
21488 case NVPTX::BI__nvvm_atom_sys_xor_gen_l:
21489 case NVPTX::BI__nvvm_atom_sys_xor_gen_ll:
21490 return MakeScopedAtomic(Intrinsic::nvvm_atomic_xor_gen_i_sys, *
this,
E);
21491 case NVPTX::BI__nvvm_atom_cta_cas_gen_us:
21492 case NVPTX::BI__nvvm_atom_cta_cas_gen_i:
21493 case NVPTX::BI__nvvm_atom_cta_cas_gen_l:
21494 case NVPTX::BI__nvvm_atom_cta_cas_gen_ll: {
21496 llvm::Type *ElemTy =
21500 Intrinsic::nvvm_atomic_cas_gen_i_cta, {ElemTy, Ptr->getType()}),
21501 {Ptr, EmitScalarExpr(E->getArg(1)), EmitScalarExpr(E->getArg(2))});
21503 case NVPTX::BI__nvvm_atom_sys_cas_gen_us:
21504 case NVPTX::BI__nvvm_atom_sys_cas_gen_i:
21505 case NVPTX::BI__nvvm_atom_sys_cas_gen_l:
21506 case NVPTX::BI__nvvm_atom_sys_cas_gen_ll: {
21508 llvm::Type *ElemTy =
21512 Intrinsic::nvvm_atomic_cas_gen_i_sys, {ElemTy, Ptr->getType()}),
21513 {Ptr, EmitScalarExpr(E->getArg(1)), EmitScalarExpr(E->getArg(2))});
21515 case NVPTX::BI__nvvm_match_all_sync_i32p:
21516 case NVPTX::BI__nvvm_match_all_sync_i64p: {
21522 ? Intrinsic::nvvm_match_all_sync_i32p
21523 : Intrinsic::nvvm_match_all_sync_i64p),
21528 return Builder.CreateExtractValue(ResultPair, 0);
21532 case NVPTX::BI__hmma_m16n16k16_ld_a:
21533 case NVPTX::BI__hmma_m16n16k16_ld_b:
21534 case NVPTX::BI__hmma_m16n16k16_ld_c_f16:
21535 case NVPTX::BI__hmma_m16n16k16_ld_c_f32:
21536 case NVPTX::BI__hmma_m32n8k16_ld_a:
21537 case NVPTX::BI__hmma_m32n8k16_ld_b:
21538 case NVPTX::BI__hmma_m32n8k16_ld_c_f16:
21539 case NVPTX::BI__hmma_m32n8k16_ld_c_f32:
21540 case NVPTX::BI__hmma_m8n32k16_ld_a:
21541 case NVPTX::BI__hmma_m8n32k16_ld_b:
21542 case NVPTX::BI__hmma_m8n32k16_ld_c_f16:
21543 case NVPTX::BI__hmma_m8n32k16_ld_c_f32:
21545 case NVPTX::BI__imma_m16n16k16_ld_a_s8:
21546 case NVPTX::BI__imma_m16n16k16_ld_a_u8:
21547 case NVPTX::BI__imma_m16n16k16_ld_b_s8:
21548 case NVPTX::BI__imma_m16n16k16_ld_b_u8:
21549 case NVPTX::BI__imma_m16n16k16_ld_c:
21550 case NVPTX::BI__imma_m32n8k16_ld_a_s8:
21551 case NVPTX::BI__imma_m32n8k16_ld_a_u8:
21552 case NVPTX::BI__imma_m32n8k16_ld_b_s8:
21553 case NVPTX::BI__imma_m32n8k16_ld_b_u8:
21554 case NVPTX::BI__imma_m32n8k16_ld_c:
21555 case NVPTX::BI__imma_m8n32k16_ld_a_s8:
21556 case NVPTX::BI__imma_m8n32k16_ld_a_u8:
21557 case NVPTX::BI__imma_m8n32k16_ld_b_s8:
21558 case NVPTX::BI__imma_m8n32k16_ld_b_u8:
21559 case NVPTX::BI__imma_m8n32k16_ld_c:
21561 case NVPTX::BI__imma_m8n8k32_ld_a_s4:
21562 case NVPTX::BI__imma_m8n8k32_ld_a_u4:
21563 case NVPTX::BI__imma_m8n8k32_ld_b_s4:
21564 case NVPTX::BI__imma_m8n8k32_ld_b_u4:
21565 case NVPTX::BI__imma_m8n8k32_ld_c:
21566 case NVPTX::BI__bmma_m8n8k128_ld_a_b1:
21567 case NVPTX::BI__bmma_m8n8k128_ld_b_b1:
21568 case NVPTX::BI__bmma_m8n8k128_ld_c:
21570 case NVPTX::BI__dmma_m8n8k4_ld_a:
21571 case NVPTX::BI__dmma_m8n8k4_ld_b:
21572 case NVPTX::BI__dmma_m8n8k4_ld_c:
21574 case NVPTX::BI__mma_bf16_m16n16k16_ld_a:
21575 case NVPTX::BI__mma_bf16_m16n16k16_ld_b:
21576 case NVPTX::BI__mma_bf16_m8n32k16_ld_a:
21577 case NVPTX::BI__mma_bf16_m8n32k16_ld_b:
21578 case NVPTX::BI__mma_bf16_m32n8k16_ld_a:
21579 case NVPTX::BI__mma_bf16_m32n8k16_ld_b:
21580 case NVPTX::BI__mma_tf32_m16n16k8_ld_a:
21581 case NVPTX::BI__mma_tf32_m16n16k8_ld_b:
21582 case NVPTX::BI__mma_tf32_m16n16k8_ld_c: {
21586 std::optional<llvm::APSInt> isColMajorArg =
21588 if (!isColMajorArg)
21590 bool isColMajor = isColMajorArg->getSExtValue();
21591 NVPTXMmaLdstInfo II = getNVPTXMmaLdstInfo(BuiltinID);
21592 unsigned IID = isColMajor ? II.IID_col : II.IID_row;
21600 assert(II.NumResults);
21601 if (II.NumResults == 1) {
21605 for (
unsigned i = 0; i < II.NumResults; ++i) {
21610 llvm::ConstantInt::get(
IntTy, i)),
21617 case NVPTX::BI__hmma_m16n16k16_st_c_f16:
21618 case NVPTX::BI__hmma_m16n16k16_st_c_f32:
21619 case NVPTX::BI__hmma_m32n8k16_st_c_f16:
21620 case NVPTX::BI__hmma_m32n8k16_st_c_f32:
21621 case NVPTX::BI__hmma_m8n32k16_st_c_f16:
21622 case NVPTX::BI__hmma_m8n32k16_st_c_f32:
21623 case NVPTX::BI__imma_m16n16k16_st_c_i32:
21624 case NVPTX::BI__imma_m32n8k16_st_c_i32:
21625 case NVPTX::BI__imma_m8n32k16_st_c_i32:
21626 case NVPTX::BI__imma_m8n8k32_st_c_i32:
21627 case NVPTX::BI__bmma_m8n8k128_st_c_i32:
21628 case NVPTX::BI__dmma_m8n8k4_st_c_f64:
21629 case NVPTX::BI__mma_m16n16k8_st_c_f32: {
21633 std::optional<llvm::APSInt> isColMajorArg =
21635 if (!isColMajorArg)
21637 bool isColMajor = isColMajorArg->getSExtValue();
21638 NVPTXMmaLdstInfo II = getNVPTXMmaLdstInfo(BuiltinID);
21639 unsigned IID = isColMajor ? II.IID_col : II.IID_row;
21644 llvm::Type *ParamType = Intrinsic->getFunctionType()->getParamType(1);
21646 for (
unsigned i = 0; i < II.NumResults; ++i) {
21650 llvm::ConstantInt::get(
IntTy, i)),
21652 Values.push_back(
Builder.CreateBitCast(
V, ParamType));
21654 Values.push_back(Ldm);
21661 case NVPTX::BI__hmma_m16n16k16_mma_f16f16:
21662 case NVPTX::BI__hmma_m16n16k16_mma_f32f16:
21663 case NVPTX::BI__hmma_m16n16k16_mma_f32f32:
21664 case NVPTX::BI__hmma_m16n16k16_mma_f16f32:
21665 case NVPTX::BI__hmma_m32n8k16_mma_f16f16:
21666 case NVPTX::BI__hmma_m32n8k16_mma_f32f16:
21667 case NVPTX::BI__hmma_m32n8k16_mma_f32f32:
21668 case NVPTX::BI__hmma_m32n8k16_mma_f16f32:
21669 case NVPTX::BI__hmma_m8n32k16_mma_f16f16:
21670 case NVPTX::BI__hmma_m8n32k16_mma_f32f16:
21671 case NVPTX::BI__hmma_m8n32k16_mma_f32f32:
21672 case NVPTX::BI__hmma_m8n32k16_mma_f16f32:
21673 case NVPTX::BI__imma_m16n16k16_mma_s8:
21674 case NVPTX::BI__imma_m16n16k16_mma_u8:
21675 case NVPTX::BI__imma_m32n8k16_mma_s8:
21676 case NVPTX::BI__imma_m32n8k16_mma_u8:
21677 case NVPTX::BI__imma_m8n32k16_mma_s8:
21678 case NVPTX::BI__imma_m8n32k16_mma_u8:
21679 case NVPTX::BI__imma_m8n8k32_mma_s4:
21680 case NVPTX::BI__imma_m8n8k32_mma_u4:
21681 case NVPTX::BI__bmma_m8n8k128_mma_xor_popc_b1:
21682 case NVPTX::BI__bmma_m8n8k128_mma_and_popc_b1:
21683 case NVPTX::BI__dmma_m8n8k4_mma_f64:
21684 case NVPTX::BI__mma_bf16_m16n16k16_mma_f32:
21685 case NVPTX::BI__mma_bf16_m8n32k16_mma_f32:
21686 case NVPTX::BI__mma_bf16_m32n8k16_mma_f32:
21687 case NVPTX::BI__mma_tf32_m16n16k8_mma_f32: {
21692 std::optional<llvm::APSInt> LayoutArg =
21696 int Layout = LayoutArg->getSExtValue();
21697 if (Layout < 0 || Layout > 3)
21699 llvm::APSInt SatfArg;
21700 if (BuiltinID == NVPTX::BI__bmma_m8n8k128_mma_xor_popc_b1 ||
21701 BuiltinID == NVPTX::BI__bmma_m8n8k128_mma_and_popc_b1)
21703 else if (std::optional<llvm::APSInt> OptSatfArg =
21705 SatfArg = *OptSatfArg;
21708 bool Satf = SatfArg.getSExtValue();
21709 NVPTXMmaInfo MI = getNVPTXMmaInfo(BuiltinID);
21710 unsigned IID = MI.getMMAIntrinsic(Layout, Satf);
21716 llvm::Type *AType = Intrinsic->getFunctionType()->getParamType(0);
21718 for (
unsigned i = 0; i < MI.NumEltsA; ++i) {
21722 llvm::ConstantInt::get(
IntTy, i)),
21724 Values.push_back(
Builder.CreateBitCast(
V, AType));
21727 llvm::Type *BType = Intrinsic->getFunctionType()->getParamType(MI.NumEltsA);
21728 for (
unsigned i = 0; i < MI.NumEltsB; ++i) {
21732 llvm::ConstantInt::get(
IntTy, i)),
21734 Values.push_back(
Builder.CreateBitCast(
V, BType));
21737 llvm::Type *CType =
21738 Intrinsic->getFunctionType()->getParamType(MI.NumEltsA + MI.NumEltsB);
21739 for (
unsigned i = 0; i < MI.NumEltsC; ++i) {
21743 llvm::ConstantInt::get(
IntTy, i)),
21745 Values.push_back(
Builder.CreateBitCast(
V, CType));
21749 for (
unsigned i = 0; i < MI.NumEltsD; ++i)
21753 llvm::ConstantInt::get(
IntTy, i)),
21758 case NVPTX::BI__nvvm_ex2_approx_f16:
21759 return MakeHalfType(Intrinsic::nvvm_ex2_approx_f16, BuiltinID,
E, *
this);
21760 case NVPTX::BI__nvvm_ex2_approx_f16x2:
21761 return MakeHalfType(Intrinsic::nvvm_ex2_approx_f16x2, BuiltinID,
E, *
this);
21762 case NVPTX::BI__nvvm_ff2f16x2_rn:
21763 return MakeHalfType(Intrinsic::nvvm_ff2f16x2_rn, BuiltinID,
E, *
this);
21764 case NVPTX::BI__nvvm_ff2f16x2_rn_relu:
21765 return MakeHalfType(Intrinsic::nvvm_ff2f16x2_rn_relu, BuiltinID,
E, *
this);
21766 case NVPTX::BI__nvvm_ff2f16x2_rz:
21767 return MakeHalfType(Intrinsic::nvvm_ff2f16x2_rz, BuiltinID,
E, *
this);
21768 case NVPTX::BI__nvvm_ff2f16x2_rz_relu:
21769 return MakeHalfType(Intrinsic::nvvm_ff2f16x2_rz_relu, BuiltinID,
E, *
this);
21770 case NVPTX::BI__nvvm_fma_rn_f16:
21771 return MakeHalfType(Intrinsic::nvvm_fma_rn_f16, BuiltinID,
E, *
this);
21772 case NVPTX::BI__nvvm_fma_rn_f16x2:
21773 return MakeHalfType(Intrinsic::nvvm_fma_rn_f16x2, BuiltinID,
E, *
this);
21774 case NVPTX::BI__nvvm_fma_rn_ftz_f16:
21775 return MakeHalfType(Intrinsic::nvvm_fma_rn_ftz_f16, BuiltinID,
E, *
this);
21776 case NVPTX::BI__nvvm_fma_rn_ftz_f16x2:
21777 return MakeHalfType(Intrinsic::nvvm_fma_rn_ftz_f16x2, BuiltinID,
E, *
this);
21778 case NVPTX::BI__nvvm_fma_rn_ftz_relu_f16:
21779 return MakeHalfType(Intrinsic::nvvm_fma_rn_ftz_relu_f16, BuiltinID,
E,
21781 case NVPTX::BI__nvvm_fma_rn_ftz_relu_f16x2:
21782 return MakeHalfType(Intrinsic::nvvm_fma_rn_ftz_relu_f16x2, BuiltinID,
E,
21784 case NVPTX::BI__nvvm_fma_rn_ftz_sat_f16:
21785 return MakeHalfType(Intrinsic::nvvm_fma_rn_ftz_sat_f16, BuiltinID,
E,
21787 case NVPTX::BI__nvvm_fma_rn_ftz_sat_f16x2:
21788 return MakeHalfType(Intrinsic::nvvm_fma_rn_ftz_sat_f16x2, BuiltinID,
E,
21790 case NVPTX::BI__nvvm_fma_rn_relu_f16:
21791 return MakeHalfType(Intrinsic::nvvm_fma_rn_relu_f16, BuiltinID,
E, *
this);
21792 case NVPTX::BI__nvvm_fma_rn_relu_f16x2:
21793 return MakeHalfType(Intrinsic::nvvm_fma_rn_relu_f16x2, BuiltinID,
E, *
this);
21794 case NVPTX::BI__nvvm_fma_rn_sat_f16:
21795 return MakeHalfType(Intrinsic::nvvm_fma_rn_sat_f16, BuiltinID,
E, *
this);
21796 case NVPTX::BI__nvvm_fma_rn_sat_f16x2:
21797 return MakeHalfType(Intrinsic::nvvm_fma_rn_sat_f16x2, BuiltinID,
E, *
this);
21798 case NVPTX::BI__nvvm_fmax_f16:
21799 return MakeHalfType(Intrinsic::nvvm_fmax_f16, BuiltinID,
E, *
this);
21800 case NVPTX::BI__nvvm_fmax_f16x2:
21801 return MakeHalfType(Intrinsic::nvvm_fmax_f16x2, BuiltinID,
E, *
this);
21802 case NVPTX::BI__nvvm_fmax_ftz_f16:
21803 return MakeHalfType(Intrinsic::nvvm_fmax_ftz_f16, BuiltinID,
E, *
this);
21804 case NVPTX::BI__nvvm_fmax_ftz_f16x2:
21805 return MakeHalfType(Intrinsic::nvvm_fmax_ftz_f16x2, BuiltinID,
E, *
this);
21806 case NVPTX::BI__nvvm_fmax_ftz_nan_f16:
21807 return MakeHalfType(Intrinsic::nvvm_fmax_ftz_nan_f16, BuiltinID,
E, *
this);
21808 case NVPTX::BI__nvvm_fmax_ftz_nan_f16x2:
21809 return MakeHalfType(Intrinsic::nvvm_fmax_ftz_nan_f16x2, BuiltinID,
E,
21811 case NVPTX::BI__nvvm_fmax_ftz_nan_xorsign_abs_f16:
21812 return MakeHalfType(Intrinsic::nvvm_fmax_ftz_nan_xorsign_abs_f16, BuiltinID,
21814 case NVPTX::BI__nvvm_fmax_ftz_nan_xorsign_abs_f16x2:
21815 return MakeHalfType(Intrinsic::nvvm_fmax_ftz_nan_xorsign_abs_f16x2,
21816 BuiltinID,
E, *
this);
21817 case NVPTX::BI__nvvm_fmax_ftz_xorsign_abs_f16:
21818 return MakeHalfType(Intrinsic::nvvm_fmax_ftz_xorsign_abs_f16, BuiltinID,
E,
21820 case NVPTX::BI__nvvm_fmax_ftz_xorsign_abs_f16x2:
21821 return MakeHalfType(Intrinsic::nvvm_fmax_ftz_xorsign_abs_f16x2, BuiltinID,
21823 case NVPTX::BI__nvvm_fmax_nan_f16:
21824 return MakeHalfType(Intrinsic::nvvm_fmax_nan_f16, BuiltinID,
E, *
this);
21825 case NVPTX::BI__nvvm_fmax_nan_f16x2:
21826 return MakeHalfType(Intrinsic::nvvm_fmax_nan_f16x2, BuiltinID,
E, *
this);
21827 case NVPTX::BI__nvvm_fmax_nan_xorsign_abs_f16:
21828 return MakeHalfType(Intrinsic::nvvm_fmax_nan_xorsign_abs_f16, BuiltinID,
E,
21830 case NVPTX::BI__nvvm_fmax_nan_xorsign_abs_f16x2:
21831 return MakeHalfType(Intrinsic::nvvm_fmax_nan_xorsign_abs_f16x2, BuiltinID,
21833 case NVPTX::BI__nvvm_fmax_xorsign_abs_f16:
21834 return MakeHalfType(Intrinsic::nvvm_fmax_xorsign_abs_f16, BuiltinID,
E,
21836 case NVPTX::BI__nvvm_fmax_xorsign_abs_f16x2:
21837 return MakeHalfType(Intrinsic::nvvm_fmax_xorsign_abs_f16x2, BuiltinID,
E,
21839 case NVPTX::BI__nvvm_fmin_f16:
21840 return MakeHalfType(Intrinsic::nvvm_fmin_f16, BuiltinID,
E, *
this);
21841 case NVPTX::BI__nvvm_fmin_f16x2:
21842 return MakeHalfType(Intrinsic::nvvm_fmin_f16x2, BuiltinID,
E, *
this);
21843 case NVPTX::BI__nvvm_fmin_ftz_f16:
21844 return MakeHalfType(Intrinsic::nvvm_fmin_ftz_f16, BuiltinID,
E, *
this);
21845 case NVPTX::BI__nvvm_fmin_ftz_f16x2:
21846 return MakeHalfType(Intrinsic::nvvm_fmin_ftz_f16x2, BuiltinID,
E, *
this);
21847 case NVPTX::BI__nvvm_fmin_ftz_nan_f16:
21848 return MakeHalfType(Intrinsic::nvvm_fmin_ftz_nan_f16, BuiltinID,
E, *
this);
21849 case NVPTX::BI__nvvm_fmin_ftz_nan_f16x2:
21850 return MakeHalfType(Intrinsic::nvvm_fmin_ftz_nan_f16x2, BuiltinID,
E,
21852 case NVPTX::BI__nvvm_fmin_ftz_nan_xorsign_abs_f16:
21853 return MakeHalfType(Intrinsic::nvvm_fmin_ftz_nan_xorsign_abs_f16, BuiltinID,
21855 case NVPTX::BI__nvvm_fmin_ftz_nan_xorsign_abs_f16x2:
21856 return MakeHalfType(Intrinsic::nvvm_fmin_ftz_nan_xorsign_abs_f16x2,
21857 BuiltinID,
E, *
this);
21858 case NVPTX::BI__nvvm_fmin_ftz_xorsign_abs_f16:
21859 return MakeHalfType(Intrinsic::nvvm_fmin_ftz_xorsign_abs_f16, BuiltinID,
E,
21861 case NVPTX::BI__nvvm_fmin_ftz_xorsign_abs_f16x2:
21862 return MakeHalfType(Intrinsic::nvvm_fmin_ftz_xorsign_abs_f16x2, BuiltinID,
21864 case NVPTX::BI__nvvm_fmin_nan_f16:
21865 return MakeHalfType(Intrinsic::nvvm_fmin_nan_f16, BuiltinID,
E, *
this);
21866 case NVPTX::BI__nvvm_fmin_nan_f16x2:
21867 return MakeHalfType(Intrinsic::nvvm_fmin_nan_f16x2, BuiltinID,
E, *
this);
21868 case NVPTX::BI__nvvm_fmin_nan_xorsign_abs_f16:
21869 return MakeHalfType(Intrinsic::nvvm_fmin_nan_xorsign_abs_f16, BuiltinID,
E,
21871 case NVPTX::BI__nvvm_fmin_nan_xorsign_abs_f16x2:
21872 return MakeHalfType(Intrinsic::nvvm_fmin_nan_xorsign_abs_f16x2, BuiltinID,
21874 case NVPTX::BI__nvvm_fmin_xorsign_abs_f16:
21875 return MakeHalfType(Intrinsic::nvvm_fmin_xorsign_abs_f16, BuiltinID,
E,
21877 case NVPTX::BI__nvvm_fmin_xorsign_abs_f16x2:
21878 return MakeHalfType(Intrinsic::nvvm_fmin_xorsign_abs_f16x2, BuiltinID,
E,
21880 case NVPTX::BI__nvvm_ldg_h:
21881 case NVPTX::BI__nvvm_ldg_h2:
21882 return MakeHalfType(Intrinsic::not_intrinsic, BuiltinID,
E, *
this);
21883 case NVPTX::BI__nvvm_ldu_h:
21884 case NVPTX::BI__nvvm_ldu_h2:
21885 return MakeHalfType(Intrinsic::nvvm_ldu_global_f, BuiltinID,
E, *
this);
21886 case NVPTX::BI__nvvm_cp_async_ca_shared_global_4:
21887 return MakeCpAsync(Intrinsic::nvvm_cp_async_ca_shared_global_4,
21888 Intrinsic::nvvm_cp_async_ca_shared_global_4_s, *
this,
E,
21890 case NVPTX::BI__nvvm_cp_async_ca_shared_global_8:
21891 return MakeCpAsync(Intrinsic::nvvm_cp_async_ca_shared_global_8,
21892 Intrinsic::nvvm_cp_async_ca_shared_global_8_s, *
this,
E,
21894 case NVPTX::BI__nvvm_cp_async_ca_shared_global_16:
21895 return MakeCpAsync(Intrinsic::nvvm_cp_async_ca_shared_global_16,
21896 Intrinsic::nvvm_cp_async_ca_shared_global_16_s, *
this,
E,
21898 case NVPTX::BI__nvvm_cp_async_cg_shared_global_16:
21899 return MakeCpAsync(Intrinsic::nvvm_cp_async_cg_shared_global_16,
21900 Intrinsic::nvvm_cp_async_cg_shared_global_16_s, *
this,
E,
21902 case NVPTX::BI__nvvm_read_ptx_sreg_clusterid_x:
21905 case NVPTX::BI__nvvm_read_ptx_sreg_clusterid_y:
21908 case NVPTX::BI__nvvm_read_ptx_sreg_clusterid_z:
21911 case NVPTX::BI__nvvm_read_ptx_sreg_clusterid_w:
21914 case NVPTX::BI__nvvm_read_ptx_sreg_nclusterid_x:
21917 case NVPTX::BI__nvvm_read_ptx_sreg_nclusterid_y:
21920 case NVPTX::BI__nvvm_read_ptx_sreg_nclusterid_z:
21923 case NVPTX::BI__nvvm_read_ptx_sreg_nclusterid_w:
21926 case NVPTX::BI__nvvm_read_ptx_sreg_cluster_ctaid_x:
21929 case NVPTX::BI__nvvm_read_ptx_sreg_cluster_ctaid_y:
21932 case NVPTX::BI__nvvm_read_ptx_sreg_cluster_ctaid_z:
21935 case NVPTX::BI__nvvm_read_ptx_sreg_cluster_ctaid_w:
21938 case NVPTX::BI__nvvm_read_ptx_sreg_cluster_nctaid_x:
21941 case NVPTX::BI__nvvm_read_ptx_sreg_cluster_nctaid_y:
21944 case NVPTX::BI__nvvm_read_ptx_sreg_cluster_nctaid_z:
21947 case NVPTX::BI__nvvm_read_ptx_sreg_cluster_nctaid_w:
21950 case NVPTX::BI__nvvm_read_ptx_sreg_cluster_ctarank:
21953 case NVPTX::BI__nvvm_read_ptx_sreg_cluster_nctarank:
21956 case NVPTX::BI__nvvm_is_explicit_cluster:
21959 case NVPTX::BI__nvvm_isspacep_shared_cluster:
21963 case NVPTX::BI__nvvm_mapa:
21966 {EmitScalarExpr(E->getArg(0)), EmitScalarExpr(E->getArg(1))});
21967 case NVPTX::BI__nvvm_mapa_shared_cluster:
21970 {EmitScalarExpr(E->getArg(0)), EmitScalarExpr(E->getArg(1))});
21971 case NVPTX::BI__nvvm_getctarank:
21975 case NVPTX::BI__nvvm_getctarank_shared_cluster:
21979 case NVPTX::BI__nvvm_barrier_cluster_arrive:
21982 case NVPTX::BI__nvvm_barrier_cluster_arrive_relaxed:
21985 case NVPTX::BI__nvvm_barrier_cluster_wait:
21988 case NVPTX::BI__nvvm_fence_sc_cluster:
21997struct BuiltinAlignArgs {
21998 llvm::Value *Src =
nullptr;
21999 llvm::Type *SrcType =
nullptr;
22000 llvm::Value *Alignment =
nullptr;
22001 llvm::Value *Mask =
nullptr;
22002 llvm::IntegerType *IntType =
nullptr;
22010 SrcType = Src->getType();
22011 if (SrcType->isPointerTy()) {
22012 IntType = IntegerType::get(
22016 assert(SrcType->isIntegerTy());
22017 IntType = cast<llvm::IntegerType>(SrcType);
22020 Alignment = CGF.
Builder.CreateZExtOrTrunc(Alignment, IntType,
"alignment");
22021 auto *One = llvm::ConstantInt::get(IntType, 1);
22022 Mask = CGF.
Builder.CreateSub(Alignment, One,
"mask");
22029 BuiltinAlignArgs Args(
E, *
this);
22030 llvm::Value *SrcAddress = Args.Src;
22031 if (Args.SrcType->isPointerTy())
22033 Builder.CreateBitOrPointerCast(Args.Src, Args.IntType,
"src_addr");
22035 Builder.CreateAnd(SrcAddress, Args.Mask,
"set_bits"),
22036 llvm::Constant::getNullValue(Args.IntType),
"is_aligned"));
22043 BuiltinAlignArgs Args(
E, *
this);
22044 llvm::Value *SrcForMask = Args.Src;
22050 if (Args.Src->getType()->isPointerTy()) {
22060 SrcForMask =
Builder.CreateAdd(SrcForMask, Args.Mask,
"over_boundary");
22064 llvm::Value *InvertedMask =
Builder.CreateNot(Args.Mask,
"inverted_mask");
22065 llvm::Value *
Result =
nullptr;
22066 if (Args.Src->getType()->isPointerTy()) {
22068 Intrinsic::ptrmask, {Args.SrcType, Args.IntType},
22069 {SrcForMask, InvertedMask},
nullptr,
"aligned_result");
22071 Result =
Builder.CreateAnd(SrcForMask, InvertedMask,
"aligned_result");
22073 assert(
Result->getType() == Args.SrcType);
22079 switch (BuiltinID) {
22080 case WebAssembly::BI__builtin_wasm_memory_size: {
22085 return Builder.CreateCall(Callee, I);
22087 case WebAssembly::BI__builtin_wasm_memory_grow: {
22093 return Builder.CreateCall(Callee, Args);
22095 case WebAssembly::BI__builtin_wasm_tls_size: {
22098 return Builder.CreateCall(Callee);
22100 case WebAssembly::BI__builtin_wasm_tls_align: {
22103 return Builder.CreateCall(Callee);
22105 case WebAssembly::BI__builtin_wasm_tls_base: {
22107 return Builder.CreateCall(Callee);
22109 case WebAssembly::BI__builtin_wasm_throw: {
22113 return Builder.CreateCall(Callee, {
Tag, Obj});
22115 case WebAssembly::BI__builtin_wasm_rethrow: {
22117 return Builder.CreateCall(Callee);
22119 case WebAssembly::BI__builtin_wasm_memory_atomic_wait32: {
22126 case WebAssembly::BI__builtin_wasm_memory_atomic_wait64: {
22133 case WebAssembly::BI__builtin_wasm_memory_atomic_notify: {
22137 return Builder.CreateCall(Callee, {Addr, Count});
22139 case WebAssembly::BI__builtin_wasm_trunc_s_i32_f32:
22140 case WebAssembly::BI__builtin_wasm_trunc_s_i32_f64:
22141 case WebAssembly::BI__builtin_wasm_trunc_s_i64_f32:
22142 case WebAssembly::BI__builtin_wasm_trunc_s_i64_f64: {
22147 return Builder.CreateCall(Callee, {Src});
22149 case WebAssembly::BI__builtin_wasm_trunc_u_i32_f32:
22150 case WebAssembly::BI__builtin_wasm_trunc_u_i32_f64:
22151 case WebAssembly::BI__builtin_wasm_trunc_u_i64_f32:
22152 case WebAssembly::BI__builtin_wasm_trunc_u_i64_f64: {
22157 return Builder.CreateCall(Callee, {Src});
22159 case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i32_f32:
22160 case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i32_f64:
22161 case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i64_f32:
22162 case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i64_f64:
22163 case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i16x8_f16x8:
22164 case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i32x4_f32x4: {
22169 return Builder.CreateCall(Callee, {Src});
22171 case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i32_f32:
22172 case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i32_f64:
22173 case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i64_f32:
22174 case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i64_f64:
22175 case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i16x8_f16x8:
22176 case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i32x4_f32x4: {
22181 return Builder.CreateCall(Callee, {Src});
22183 case WebAssembly::BI__builtin_wasm_min_f32:
22184 case WebAssembly::BI__builtin_wasm_min_f64:
22185 case WebAssembly::BI__builtin_wasm_min_f16x8:
22186 case WebAssembly::BI__builtin_wasm_min_f32x4:
22187 case WebAssembly::BI__builtin_wasm_min_f64x2: {
22192 return Builder.CreateCall(Callee, {LHS, RHS});
22194 case WebAssembly::BI__builtin_wasm_max_f32:
22195 case WebAssembly::BI__builtin_wasm_max_f64:
22196 case WebAssembly::BI__builtin_wasm_max_f16x8:
22197 case WebAssembly::BI__builtin_wasm_max_f32x4:
22198 case WebAssembly::BI__builtin_wasm_max_f64x2: {
22203 return Builder.CreateCall(Callee, {LHS, RHS});
22205 case WebAssembly::BI__builtin_wasm_pmin_f16x8:
22206 case WebAssembly::BI__builtin_wasm_pmin_f32x4:
22207 case WebAssembly::BI__builtin_wasm_pmin_f64x2: {
22212 return Builder.CreateCall(Callee, {LHS, RHS});
22214 case WebAssembly::BI__builtin_wasm_pmax_f16x8:
22215 case WebAssembly::BI__builtin_wasm_pmax_f32x4:
22216 case WebAssembly::BI__builtin_wasm_pmax_f64x2: {
22221 return Builder.CreateCall(Callee, {LHS, RHS});
22223 case WebAssembly::BI__builtin_wasm_ceil_f16x8:
22224 case WebAssembly::BI__builtin_wasm_floor_f16x8:
22225 case WebAssembly::BI__builtin_wasm_trunc_f16x8:
22226 case WebAssembly::BI__builtin_wasm_nearest_f16x8:
22227 case WebAssembly::BI__builtin_wasm_ceil_f32x4:
22228 case WebAssembly::BI__builtin_wasm_floor_f32x4:
22229 case WebAssembly::BI__builtin_wasm_trunc_f32x4:
22230 case WebAssembly::BI__builtin_wasm_nearest_f32x4:
22231 case WebAssembly::BI__builtin_wasm_ceil_f64x2:
22232 case WebAssembly::BI__builtin_wasm_floor_f64x2:
22233 case WebAssembly::BI__builtin_wasm_trunc_f64x2:
22234 case WebAssembly::BI__builtin_wasm_nearest_f64x2: {
22236 switch (BuiltinID) {
22237 case WebAssembly::BI__builtin_wasm_ceil_f16x8:
22238 case WebAssembly::BI__builtin_wasm_ceil_f32x4:
22239 case WebAssembly::BI__builtin_wasm_ceil_f64x2:
22240 IntNo = Intrinsic::ceil;
22242 case WebAssembly::BI__builtin_wasm_floor_f16x8:
22243 case WebAssembly::BI__builtin_wasm_floor_f32x4:
22244 case WebAssembly::BI__builtin_wasm_floor_f64x2:
22245 IntNo = Intrinsic::floor;
22247 case WebAssembly::BI__builtin_wasm_trunc_f16x8:
22248 case WebAssembly::BI__builtin_wasm_trunc_f32x4:
22249 case WebAssembly::BI__builtin_wasm_trunc_f64x2:
22250 IntNo = Intrinsic::trunc;
22252 case WebAssembly::BI__builtin_wasm_nearest_f16x8:
22253 case WebAssembly::BI__builtin_wasm_nearest_f32x4:
22254 case WebAssembly::BI__builtin_wasm_nearest_f64x2:
22255 IntNo = Intrinsic::nearbyint;
22258 llvm_unreachable(
"unexpected builtin ID");
22264 case WebAssembly::BI__builtin_wasm_ref_null_extern: {
22266 return Builder.CreateCall(Callee);
22268 case WebAssembly::BI__builtin_wasm_ref_null_func: {
22270 return Builder.CreateCall(Callee);
22272 case WebAssembly::BI__builtin_wasm_swizzle_i8x16: {
22276 return Builder.CreateCall(Callee, {Src, Indices});
22278 case WebAssembly::BI__builtin_wasm_abs_i8x16:
22279 case WebAssembly::BI__builtin_wasm_abs_i16x8:
22280 case WebAssembly::BI__builtin_wasm_abs_i32x4:
22281 case WebAssembly::BI__builtin_wasm_abs_i64x2: {
22284 Constant *
Zero = llvm::Constant::getNullValue(Vec->
getType());
22285 Value *ICmp =
Builder.CreateICmpSLT(Vec, Zero,
"abscond");
22286 return Builder.CreateSelect(ICmp, Neg, Vec,
"abs");
22288 case WebAssembly::BI__builtin_wasm_avgr_u_i8x16:
22289 case WebAssembly::BI__builtin_wasm_avgr_u_i16x8: {
22294 return Builder.CreateCall(Callee, {LHS, RHS});
22296 case WebAssembly::BI__builtin_wasm_q15mulr_sat_s_i16x8: {
22300 return Builder.CreateCall(Callee, {LHS, RHS});
22302 case WebAssembly::BI__builtin_wasm_extadd_pairwise_i8x16_s_i16x8:
22303 case WebAssembly::BI__builtin_wasm_extadd_pairwise_i8x16_u_i16x8:
22304 case WebAssembly::BI__builtin_wasm_extadd_pairwise_i16x8_s_i32x4:
22305 case WebAssembly::BI__builtin_wasm_extadd_pairwise_i16x8_u_i32x4: {
22308 switch (BuiltinID) {
22309 case WebAssembly::BI__builtin_wasm_extadd_pairwise_i8x16_s_i16x8:
22310 case WebAssembly::BI__builtin_wasm_extadd_pairwise_i16x8_s_i32x4:
22311 IntNo = Intrinsic::wasm_extadd_pairwise_signed;
22313 case WebAssembly::BI__builtin_wasm_extadd_pairwise_i8x16_u_i16x8:
22314 case WebAssembly::BI__builtin_wasm_extadd_pairwise_i16x8_u_i32x4:
22315 IntNo = Intrinsic::wasm_extadd_pairwise_unsigned;
22318 llvm_unreachable(
"unexpected builtin ID");
22322 return Builder.CreateCall(Callee, Vec);
22324 case WebAssembly::BI__builtin_wasm_bitselect: {
22330 return Builder.CreateCall(Callee, {V1, V2,
C});
22332 case WebAssembly::BI__builtin_wasm_dot_s_i32x4_i16x8: {
22336 return Builder.CreateCall(Callee, {LHS, RHS});
22338 case WebAssembly::BI__builtin_wasm_any_true_v128:
22339 case WebAssembly::BI__builtin_wasm_all_true_i8x16:
22340 case WebAssembly::BI__builtin_wasm_all_true_i16x8:
22341 case WebAssembly::BI__builtin_wasm_all_true_i32x4:
22342 case WebAssembly::BI__builtin_wasm_all_true_i64x2: {
22344 switch (BuiltinID) {
22345 case WebAssembly::BI__builtin_wasm_any_true_v128:
22346 IntNo = Intrinsic::wasm_anytrue;
22348 case WebAssembly::BI__builtin_wasm_all_true_i8x16:
22349 case WebAssembly::BI__builtin_wasm_all_true_i16x8:
22350 case WebAssembly::BI__builtin_wasm_all_true_i32x4:
22351 case WebAssembly::BI__builtin_wasm_all_true_i64x2:
22352 IntNo = Intrinsic::wasm_alltrue;
22355 llvm_unreachable(
"unexpected builtin ID");
22359 return Builder.CreateCall(Callee, {Vec});
22361 case WebAssembly::BI__builtin_wasm_bitmask_i8x16:
22362 case WebAssembly::BI__builtin_wasm_bitmask_i16x8:
22363 case WebAssembly::BI__builtin_wasm_bitmask_i32x4:
22364 case WebAssembly::BI__builtin_wasm_bitmask_i64x2: {
22368 return Builder.CreateCall(Callee, {Vec});
22370 case WebAssembly::BI__builtin_wasm_abs_f16x8:
22371 case WebAssembly::BI__builtin_wasm_abs_f32x4:
22372 case WebAssembly::BI__builtin_wasm_abs_f64x2: {
22375 return Builder.CreateCall(Callee, {Vec});
22377 case WebAssembly::BI__builtin_wasm_sqrt_f16x8:
22378 case WebAssembly::BI__builtin_wasm_sqrt_f32x4:
22379 case WebAssembly::BI__builtin_wasm_sqrt_f64x2: {
22382 return Builder.CreateCall(Callee, {Vec});
22384 case WebAssembly::BI__builtin_wasm_narrow_s_i8x16_i16x8:
22385 case WebAssembly::BI__builtin_wasm_narrow_u_i8x16_i16x8:
22386 case WebAssembly::BI__builtin_wasm_narrow_s_i16x8_i32x4:
22387 case WebAssembly::BI__builtin_wasm_narrow_u_i16x8_i32x4: {
22391 switch (BuiltinID) {
22392 case WebAssembly::BI__builtin_wasm_narrow_s_i8x16_i16x8:
22393 case WebAssembly::BI__builtin_wasm_narrow_s_i16x8_i32x4:
22394 IntNo = Intrinsic::wasm_narrow_signed;
22396 case WebAssembly::BI__builtin_wasm_narrow_u_i8x16_i16x8:
22397 case WebAssembly::BI__builtin_wasm_narrow_u_i16x8_i32x4:
22398 IntNo = Intrinsic::wasm_narrow_unsigned;
22401 llvm_unreachable(
"unexpected builtin ID");
22405 return Builder.CreateCall(Callee, {Low, High});
22407 case WebAssembly::BI__builtin_wasm_trunc_sat_s_zero_f64x2_i32x4:
22408 case WebAssembly::BI__builtin_wasm_trunc_sat_u_zero_f64x2_i32x4: {
22411 switch (BuiltinID) {
22412 case WebAssembly::BI__builtin_wasm_trunc_sat_s_zero_f64x2_i32x4:
22413 IntNo = Intrinsic::fptosi_sat;
22415 case WebAssembly::BI__builtin_wasm_trunc_sat_u_zero_f64x2_i32x4:
22416 IntNo = Intrinsic::fptoui_sat;
22419 llvm_unreachable(
"unexpected builtin ID");
22421 llvm::Type *SrcT = Vec->
getType();
22422 llvm::Type *TruncT = SrcT->getWithNewType(
Builder.getInt32Ty());
22425 Value *Splat = Constant::getNullValue(TruncT);
22428 case WebAssembly::BI__builtin_wasm_shuffle_i8x16: {
22433 while (OpIdx < 18) {
22434 std::optional<llvm::APSInt> LaneConst =
22436 assert(LaneConst &&
"Constant arg isn't actually constant?");
22437 Ops[OpIdx++] = llvm::ConstantInt::get(
getLLVMContext(), *LaneConst);
22440 return Builder.CreateCall(Callee, Ops);
22442 case WebAssembly::BI__builtin_wasm_relaxed_madd_f16x8:
22443 case WebAssembly::BI__builtin_wasm_relaxed_nmadd_f16x8:
22444 case WebAssembly::BI__builtin_wasm_relaxed_madd_f32x4:
22445 case WebAssembly::BI__builtin_wasm_relaxed_nmadd_f32x4:
22446 case WebAssembly::BI__builtin_wasm_relaxed_madd_f64x2:
22447 case WebAssembly::BI__builtin_wasm_relaxed_nmadd_f64x2: {
22452 switch (BuiltinID) {
22453 case WebAssembly::BI__builtin_wasm_relaxed_madd_f16x8:
22454 case WebAssembly::BI__builtin_wasm_relaxed_madd_f32x4:
22455 case WebAssembly::BI__builtin_wasm_relaxed_madd_f64x2:
22456 IntNo = Intrinsic::wasm_relaxed_madd;
22458 case WebAssembly::BI__builtin_wasm_relaxed_nmadd_f16x8:
22459 case WebAssembly::BI__builtin_wasm_relaxed_nmadd_f32x4:
22460 case WebAssembly::BI__builtin_wasm_relaxed_nmadd_f64x2:
22461 IntNo = Intrinsic::wasm_relaxed_nmadd;
22464 llvm_unreachable(
"unexpected builtin ID");
22467 return Builder.CreateCall(Callee, {A, B,
C});
22469 case WebAssembly::BI__builtin_wasm_relaxed_laneselect_i8x16:
22470 case WebAssembly::BI__builtin_wasm_relaxed_laneselect_i16x8:
22471 case WebAssembly::BI__builtin_wasm_relaxed_laneselect_i32x4:
22472 case WebAssembly::BI__builtin_wasm_relaxed_laneselect_i64x2: {
22478 return Builder.CreateCall(Callee, {A, B,
C});
22480 case WebAssembly::BI__builtin_wasm_relaxed_swizzle_i8x16: {
22484 return Builder.CreateCall(Callee, {Src, Indices});
22486 case WebAssembly::BI__builtin_wasm_relaxed_min_f32x4:
22487 case WebAssembly::BI__builtin_wasm_relaxed_max_f32x4:
22488 case WebAssembly::BI__builtin_wasm_relaxed_min_f64x2:
22489 case WebAssembly::BI__builtin_wasm_relaxed_max_f64x2: {
22493 switch (BuiltinID) {
22494 case WebAssembly::BI__builtin_wasm_relaxed_min_f32x4:
22495 case WebAssembly::BI__builtin_wasm_relaxed_min_f64x2:
22496 IntNo = Intrinsic::wasm_relaxed_min;
22498 case WebAssembly::BI__builtin_wasm_relaxed_max_f32x4:
22499 case WebAssembly::BI__builtin_wasm_relaxed_max_f64x2:
22500 IntNo = Intrinsic::wasm_relaxed_max;
22503 llvm_unreachable(
"unexpected builtin ID");
22506 return Builder.CreateCall(Callee, {LHS, RHS});
22508 case WebAssembly::BI__builtin_wasm_relaxed_trunc_s_i32x4_f32x4:
22509 case WebAssembly::BI__builtin_wasm_relaxed_trunc_u_i32x4_f32x4:
22510 case WebAssembly::BI__builtin_wasm_relaxed_trunc_s_zero_i32x4_f64x2:
22511 case WebAssembly::BI__builtin_wasm_relaxed_trunc_u_zero_i32x4_f64x2: {
22514 switch (BuiltinID) {
22515 case WebAssembly::BI__builtin_wasm_relaxed_trunc_s_i32x4_f32x4:
22516 IntNo = Intrinsic::wasm_relaxed_trunc_signed;
22518 case WebAssembly::BI__builtin_wasm_relaxed_trunc_u_i32x4_f32x4:
22519 IntNo = Intrinsic::wasm_relaxed_trunc_unsigned;
22521 case WebAssembly::BI__builtin_wasm_relaxed_trunc_s_zero_i32x4_f64x2:
22522 IntNo = Intrinsic::wasm_relaxed_trunc_signed_zero;
22524 case WebAssembly::BI__builtin_wasm_relaxed_trunc_u_zero_i32x4_f64x2:
22525 IntNo = Intrinsic::wasm_relaxed_trunc_unsigned_zero;
22528 llvm_unreachable(
"unexpected builtin ID");
22531 return Builder.CreateCall(Callee, {Vec});
22533 case WebAssembly::BI__builtin_wasm_relaxed_q15mulr_s_i16x8: {
22537 return Builder.CreateCall(Callee, {LHS, RHS});
22539 case WebAssembly::BI__builtin_wasm_relaxed_dot_i8x16_i7x16_s_i16x8: {
22544 return Builder.CreateCall(Callee, {LHS, RHS});
22546 case WebAssembly::BI__builtin_wasm_relaxed_dot_i8x16_i7x16_add_s_i32x4: {
22551 CGM.
getIntrinsic(Intrinsic::wasm_relaxed_dot_i8x16_i7x16_add_signed);
22552 return Builder.CreateCall(Callee, {LHS, RHS, Acc});
22554 case WebAssembly::BI__builtin_wasm_relaxed_dot_bf16x8_add_f32_f32x4: {
22560 return Builder.CreateCall(Callee, {LHS, RHS, Acc});
22562 case WebAssembly::BI__builtin_wasm_loadf16_f32: {
22565 return Builder.CreateCall(Callee, {Addr});
22567 case WebAssembly::BI__builtin_wasm_storef16_f32: {
22571 return Builder.CreateCall(Callee, {Val, Addr});
22573 case WebAssembly::BI__builtin_wasm_splat_f16x8: {
22576 return Builder.CreateCall(Callee, {Val});
22578 case WebAssembly::BI__builtin_wasm_extract_lane_f16x8: {
22584 case WebAssembly::BI__builtin_wasm_replace_lane_f16x8: {
22591 case WebAssembly::BI__builtin_wasm_table_get: {
22602 "Unexpected reference type for __builtin_wasm_table_get");
22603 return Builder.CreateCall(Callee, {Table, Index});
22605 case WebAssembly::BI__builtin_wasm_table_set: {
22617 "Unexpected reference type for __builtin_wasm_table_set");
22618 return Builder.CreateCall(Callee, {Table, Index, Val});
22620 case WebAssembly::BI__builtin_wasm_table_size: {
22626 case WebAssembly::BI__builtin_wasm_table_grow: {
22639 "Unexpected reference type for __builtin_wasm_table_grow");
22641 return Builder.CreateCall(Callee, {Table, Val, NElems});
22643 case WebAssembly::BI__builtin_wasm_table_fill: {
22657 "Unexpected reference type for __builtin_wasm_table_fill");
22659 return Builder.CreateCall(Callee, {Table, Index, Val, NElems});
22661 case WebAssembly::BI__builtin_wasm_table_copy: {
22671 return Builder.CreateCall(Callee, {TableX, TableY, SrcIdx, DstIdx, NElems});
22678static std::pair<Intrinsic::ID, unsigned>
22681 unsigned BuiltinID;
22682 Intrinsic::ID IntrinsicID;
22685 static Info Infos[] = {
22686#define CUSTOM_BUILTIN_MAPPING(x,s) \
22687 { Hexagon::BI__builtin_HEXAGON_##x, Intrinsic::hexagon_##x, s },
22719#include "clang/Basic/BuiltinsHexagonMapCustomDep.def"
22720#undef CUSTOM_BUILTIN_MAPPING
22723 auto CmpInfo = [] (Info A, Info B) {
return A.BuiltinID < B.BuiltinID; };
22724 static const bool SortOnce = (llvm::sort(Infos, CmpInfo),
true);
22727 const Info *F = llvm::lower_bound(Infos, Info{BuiltinID, 0, 0}, CmpInfo);
22728 if (F == std::end(Infos) || F->BuiltinID != BuiltinID)
22729 return {Intrinsic::not_intrinsic, 0};
22731 return {F->IntrinsicID, F->VecLen};
22740 auto MakeCircOp = [
this,
E](
unsigned IntID,
bool IsLoad) {
22754 for (
unsigned i = 1, e =
E->getNumArgs(); i != e; ++i)
22760 llvm::Value *NewBase = IsLoad ?
Builder.CreateExtractValue(
Result, 1)
22764 llvm::Value *RetVal =
22774 auto MakeBrevLd = [
this,
E](
unsigned IntID, llvm::Type *DestTy) {
22791 CGM.
getIntrinsic(IntID), {BaseAddress, EmitScalarExpr(E->getArg(2))});
22794 llvm::Value *DestVal =
Builder.CreateExtractValue(
Result, 0);
22799 DestVal =
Builder.CreateTrunc(DestVal, DestTy);
22806 auto V2Q = [
this, VecLen] (llvm::Value *Vec) {
22807 Intrinsic::ID
ID = VecLen == 128 ? Intrinsic::hexagon_V6_vandvrt_128B
22808 : Intrinsic::hexagon_V6_vandvrt;
22810 {Vec,
Builder.getInt32(-1)});
22812 auto Q2V = [
this, VecLen] (llvm::Value *Pred) {
22813 Intrinsic::ID
ID = VecLen == 128 ? Intrinsic::hexagon_V6_vandqrt_128B
22814 : Intrinsic::hexagon_V6_vandqrt;
22816 {Pred,
Builder.getInt32(-1)});
22819 switch (BuiltinID) {
22823 case Hexagon::BI__builtin_HEXAGON_V6_vaddcarry:
22824 case Hexagon::BI__builtin_HEXAGON_V6_vaddcarry_128B:
22825 case Hexagon::BI__builtin_HEXAGON_V6_vsubcarry:
22826 case Hexagon::BI__builtin_HEXAGON_V6_vsubcarry_128B: {
22833 {EmitScalarExpr(E->getArg(0)), EmitScalarExpr(E->getArg(1)), PredIn});
22835 llvm::Value *PredOut =
Builder.CreateExtractValue(
Result, 1);
22843 case Hexagon::BI__builtin_HEXAGON_V6_vaddcarryo:
22844 case Hexagon::BI__builtin_HEXAGON_V6_vaddcarryo_128B:
22845 case Hexagon::BI__builtin_HEXAGON_V6_vsubcarryo:
22846 case Hexagon::BI__builtin_HEXAGON_V6_vsubcarryo_128B: {
22852 {EmitScalarExpr(E->getArg(0)), EmitScalarExpr(E->getArg(1))});
22854 llvm::Value *PredOut =
Builder.CreateExtractValue(
Result, 1);
22860 case Hexagon::BI__builtin_HEXAGON_V6_vmaskedstoreq:
22861 case Hexagon::BI__builtin_HEXAGON_V6_vmaskedstorenq:
22862 case Hexagon::BI__builtin_HEXAGON_V6_vmaskedstorentq:
22863 case Hexagon::BI__builtin_HEXAGON_V6_vmaskedstorentnq:
22864 case Hexagon::BI__builtin_HEXAGON_V6_vmaskedstoreq_128B:
22865 case Hexagon::BI__builtin_HEXAGON_V6_vmaskedstorenq_128B:
22866 case Hexagon::BI__builtin_HEXAGON_V6_vmaskedstorentq_128B:
22867 case Hexagon::BI__builtin_HEXAGON_V6_vmaskedstorentnq_128B: {
22869 const Expr *PredOp =
E->getArg(0);
22871 if (
auto *Cast = dyn_cast<ImplicitCastExpr>(PredOp)) {
22872 if (
Cast->getCastKind() == CK_BitCast)
22873 PredOp =
Cast->getSubExpr();
22876 for (
int i = 1, e =
E->getNumArgs(); i != e; ++i)
22881 case Hexagon::BI__builtin_HEXAGON_L2_loadrub_pci:
22882 case Hexagon::BI__builtin_HEXAGON_L2_loadrb_pci:
22883 case Hexagon::BI__builtin_HEXAGON_L2_loadruh_pci:
22884 case Hexagon::BI__builtin_HEXAGON_L2_loadrh_pci:
22885 case Hexagon::BI__builtin_HEXAGON_L2_loadri_pci:
22886 case Hexagon::BI__builtin_HEXAGON_L2_loadrd_pci:
22887 case Hexagon::BI__builtin_HEXAGON_L2_loadrub_pcr:
22888 case Hexagon::BI__builtin_HEXAGON_L2_loadrb_pcr:
22889 case Hexagon::BI__builtin_HEXAGON_L2_loadruh_pcr:
22890 case Hexagon::BI__builtin_HEXAGON_L2_loadrh_pcr:
22891 case Hexagon::BI__builtin_HEXAGON_L2_loadri_pcr:
22892 case Hexagon::BI__builtin_HEXAGON_L2_loadrd_pcr:
22893 return MakeCircOp(ID,
true);
22894 case Hexagon::BI__builtin_HEXAGON_S2_storerb_pci:
22895 case Hexagon::BI__builtin_HEXAGON_S2_storerh_pci:
22896 case Hexagon::BI__builtin_HEXAGON_S2_storerf_pci:
22897 case Hexagon::BI__builtin_HEXAGON_S2_storeri_pci:
22898 case Hexagon::BI__builtin_HEXAGON_S2_storerd_pci:
22899 case Hexagon::BI__builtin_HEXAGON_S2_storerb_pcr:
22900 case Hexagon::BI__builtin_HEXAGON_S2_storerh_pcr:
22901 case Hexagon::BI__builtin_HEXAGON_S2_storerf_pcr:
22902 case Hexagon::BI__builtin_HEXAGON_S2_storeri_pcr:
22903 case Hexagon::BI__builtin_HEXAGON_S2_storerd_pcr:
22904 return MakeCircOp(ID,
false);
22905 case Hexagon::BI__builtin_brev_ldub:
22906 return MakeBrevLd(Intrinsic::hexagon_L2_loadrub_pbr,
Int8Ty);
22907 case Hexagon::BI__builtin_brev_ldb:
22908 return MakeBrevLd(Intrinsic::hexagon_L2_loadrb_pbr,
Int8Ty);
22909 case Hexagon::BI__builtin_brev_lduh:
22910 return MakeBrevLd(Intrinsic::hexagon_L2_loadruh_pbr,
Int16Ty);
22911 case Hexagon::BI__builtin_brev_ldh:
22912 return MakeBrevLd(Intrinsic::hexagon_L2_loadrh_pbr,
Int16Ty);
22913 case Hexagon::BI__builtin_brev_ldw:
22914 return MakeBrevLd(Intrinsic::hexagon_L2_loadri_pbr,
Int32Ty);
22915 case Hexagon::BI__builtin_brev_ldd:
22916 return MakeBrevLd(Intrinsic::hexagon_L2_loadrd_pbr,
Int64Ty);
22924 StringRef CPUStr = cast<clang::StringLiteral>(CPUExpr)->getString();
22932 llvm::Constant *RISCVCPUModel =
22934 cast<llvm::GlobalValue>(RISCVCPUModel)->setDSOLocal(
true);
22936 auto loadRISCVCPUID = [&](
unsigned Index) {
22939 Ptr, llvm::MaybeAlign());
22943 const llvm::RISCV::CPUModel Model = llvm::RISCV::getCPUModel(CPUStr);
22946 Value *VendorID = loadRISCVCPUID(0);
22948 Builder.CreateICmpEQ(VendorID,
Builder.getInt32(Model.MVendorID));
22951 Value *ArchID = loadRISCVCPUID(1);
22956 Value *ImpID = loadRISCVCPUID(2);
22967 if (BuiltinID == Builtin::BI__builtin_cpu_supports)
22969 if (BuiltinID == Builtin::BI__builtin_cpu_init)
22971 if (BuiltinID == Builtin::BI__builtin_cpu_is)
22978 unsigned ICEArguments = 0;
22986 if (BuiltinID == RISCVVector::BI__builtin_rvv_vget_v ||
22987 BuiltinID == RISCVVector::BI__builtin_rvv_vset_v)
22988 ICEArguments = 1 << 1;
22993 if (BuiltinID == RISCV::BI__builtin_riscv_ntl_load)
22994 ICEArguments |= (1 << 1);
22995 if (BuiltinID == RISCV::BI__builtin_riscv_ntl_store)
22996 ICEArguments |= (1 << 2);
22998 for (
unsigned i = 0, e =
E->getNumArgs(); i != e; i++) {
23003 Ops.push_back(AggValue);
23009 Intrinsic::ID
ID = Intrinsic::not_intrinsic;
23012 constexpr unsigned RVV_VTA = 0x1;
23013 constexpr unsigned RVV_VMA = 0x2;
23014 int PolicyAttrs = 0;
23015 bool IsMasked =
false;
23017 unsigned SegInstSEW = 8;
23021 switch (BuiltinID) {
23022 default: llvm_unreachable(
"unexpected builtin ID");
23023 case RISCV::BI__builtin_riscv_orc_b_32:
23024 case RISCV::BI__builtin_riscv_orc_b_64:
23025 case RISCV::BI__builtin_riscv_clmul_32:
23026 case RISCV::BI__builtin_riscv_clmul_64:
23027 case RISCV::BI__builtin_riscv_clmulh_32:
23028 case RISCV::BI__builtin_riscv_clmulh_64:
23029 case RISCV::BI__builtin_riscv_clmulr_32:
23030 case RISCV::BI__builtin_riscv_clmulr_64:
23031 case RISCV::BI__builtin_riscv_xperm4_32:
23032 case RISCV::BI__builtin_riscv_xperm4_64:
23033 case RISCV::BI__builtin_riscv_xperm8_32:
23034 case RISCV::BI__builtin_riscv_xperm8_64:
23035 case RISCV::BI__builtin_riscv_brev8_32:
23036 case RISCV::BI__builtin_riscv_brev8_64:
23037 case RISCV::BI__builtin_riscv_zip_32:
23038 case RISCV::BI__builtin_riscv_unzip_32: {
23039 switch (BuiltinID) {
23040 default: llvm_unreachable(
"unexpected builtin ID");
23042 case RISCV::BI__builtin_riscv_orc_b_32:
23043 case RISCV::BI__builtin_riscv_orc_b_64:
23044 ID = Intrinsic::riscv_orc_b;
23048 case RISCV::BI__builtin_riscv_clmul_32:
23049 case RISCV::BI__builtin_riscv_clmul_64:
23050 ID = Intrinsic::riscv_clmul;
23052 case RISCV::BI__builtin_riscv_clmulh_32:
23053 case RISCV::BI__builtin_riscv_clmulh_64:
23054 ID = Intrinsic::riscv_clmulh;
23056 case RISCV::BI__builtin_riscv_clmulr_32:
23057 case RISCV::BI__builtin_riscv_clmulr_64:
23058 ID = Intrinsic::riscv_clmulr;
23062 case RISCV::BI__builtin_riscv_xperm8_32:
23063 case RISCV::BI__builtin_riscv_xperm8_64:
23064 ID = Intrinsic::riscv_xperm8;
23066 case RISCV::BI__builtin_riscv_xperm4_32:
23067 case RISCV::BI__builtin_riscv_xperm4_64:
23068 ID = Intrinsic::riscv_xperm4;
23072 case RISCV::BI__builtin_riscv_brev8_32:
23073 case RISCV::BI__builtin_riscv_brev8_64:
23074 ID = Intrinsic::riscv_brev8;
23076 case RISCV::BI__builtin_riscv_zip_32:
23077 ID = Intrinsic::riscv_zip;
23079 case RISCV::BI__builtin_riscv_unzip_32:
23080 ID = Intrinsic::riscv_unzip;
23084 IntrinsicTypes = {ResultType};
23091 case RISCV::BI__builtin_riscv_sha256sig0:
23092 ID = Intrinsic::riscv_sha256sig0;
23094 case RISCV::BI__builtin_riscv_sha256sig1:
23095 ID = Intrinsic::riscv_sha256sig1;
23097 case RISCV::BI__builtin_riscv_sha256sum0:
23098 ID = Intrinsic::riscv_sha256sum0;
23100 case RISCV::BI__builtin_riscv_sha256sum1:
23101 ID = Intrinsic::riscv_sha256sum1;
23105 case RISCV::BI__builtin_riscv_sm4ks:
23106 ID = Intrinsic::riscv_sm4ks;
23108 case RISCV::BI__builtin_riscv_sm4ed:
23109 ID = Intrinsic::riscv_sm4ed;
23113 case RISCV::BI__builtin_riscv_sm3p0:
23114 ID = Intrinsic::riscv_sm3p0;
23116 case RISCV::BI__builtin_riscv_sm3p1:
23117 ID = Intrinsic::riscv_sm3p1;
23120 case RISCV::BI__builtin_riscv_clz_32:
23121 case RISCV::BI__builtin_riscv_clz_64: {
23124 if (
Result->getType() != ResultType)
23129 case RISCV::BI__builtin_riscv_ctz_32:
23130 case RISCV::BI__builtin_riscv_ctz_64: {
23133 if (
Result->getType() != ResultType)
23140 case RISCV::BI__builtin_riscv_ntl_load: {
23142 unsigned DomainVal = 5;
23143 if (Ops.size() == 2)
23144 DomainVal = cast<ConstantInt>(Ops[1])->getZExtValue();
23146 llvm::MDNode *RISCVDomainNode = llvm::MDNode::get(
23148 llvm::ConstantAsMetadata::get(
Builder.getInt32(DomainVal)));
23149 llvm::MDNode *NontemporalNode = llvm::MDNode::get(
23153 if(ResTy->isScalableTy()) {
23154 const ScalableVectorType *SVTy = cast<ScalableVectorType>(ResTy);
23155 llvm::Type *ScalarTy = ResTy->getScalarType();
23156 Width = ScalarTy->getPrimitiveSizeInBits() *
23157 SVTy->getElementCount().getKnownMinValue();
23159 Width = ResTy->getPrimitiveSizeInBits();
23163 Load->setMetadata(llvm::LLVMContext::MD_nontemporal, NontemporalNode);
23164 Load->setMetadata(
CGM.
getModule().getMDKindID(
"riscv-nontemporal-domain"),
23169 case RISCV::BI__builtin_riscv_ntl_store: {
23170 unsigned DomainVal = 5;
23171 if (Ops.size() == 3)
23172 DomainVal = cast<ConstantInt>(Ops[2])->getZExtValue();
23174 llvm::MDNode *RISCVDomainNode = llvm::MDNode::get(
23176 llvm::ConstantAsMetadata::get(
Builder.getInt32(DomainVal)));
23177 llvm::MDNode *NontemporalNode = llvm::MDNode::get(
23181 Store->setMetadata(llvm::LLVMContext::MD_nontemporal, NontemporalNode);
23188 case RISCV::BI__builtin_riscv_cv_alu_addN:
23189 ID = Intrinsic::riscv_cv_alu_addN;
23191 case RISCV::BI__builtin_riscv_cv_alu_addRN:
23192 ID = Intrinsic::riscv_cv_alu_addRN;
23194 case RISCV::BI__builtin_riscv_cv_alu_adduN:
23195 ID = Intrinsic::riscv_cv_alu_adduN;
23197 case RISCV::BI__builtin_riscv_cv_alu_adduRN:
23198 ID = Intrinsic::riscv_cv_alu_adduRN;
23200 case RISCV::BI__builtin_riscv_cv_alu_clip:
23201 ID = Intrinsic::riscv_cv_alu_clip;
23203 case RISCV::BI__builtin_riscv_cv_alu_clipu:
23204 ID = Intrinsic::riscv_cv_alu_clipu;
23206 case RISCV::BI__builtin_riscv_cv_alu_extbs:
23209 case RISCV::BI__builtin_riscv_cv_alu_extbz:
23212 case RISCV::BI__builtin_riscv_cv_alu_exths:
23215 case RISCV::BI__builtin_riscv_cv_alu_exthz:
23218 case RISCV::BI__builtin_riscv_cv_alu_slet:
23221 case RISCV::BI__builtin_riscv_cv_alu_sletu:
23224 case RISCV::BI__builtin_riscv_cv_alu_subN:
23225 ID = Intrinsic::riscv_cv_alu_subN;
23227 case RISCV::BI__builtin_riscv_cv_alu_subRN:
23228 ID = Intrinsic::riscv_cv_alu_subRN;
23230 case RISCV::BI__builtin_riscv_cv_alu_subuN:
23231 ID = Intrinsic::riscv_cv_alu_subuN;
23233 case RISCV::BI__builtin_riscv_cv_alu_subuRN:
23234 ID = Intrinsic::riscv_cv_alu_subuRN;
23238#include "clang/Basic/riscv_vector_builtin_cg.inc"
23241#include "clang/Basic/riscv_sifive_vector_builtin_cg.inc"
23244 assert(ID != Intrinsic::not_intrinsic);
23247 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)
static Intrinsic::ID getDotProductIntrinsic(CGHLSLRuntime &RT, QualType QT)
#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 * emitQuaternaryBuiltin(CodeGenFunction &CGF, const CallExpr *E, unsigned IntrinsicID)
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 * handleHlslSplitdouble(const CallExpr *E, CodeGenFunction *CGF)
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 bool HasNoIndirectArgumentsOrResults(CGFunctionInfo const &FnInfo)
Checks no arguments or results are passed indirectly in the ABI (i.e.
static Value * EmitX86Muldq(CodeGenFunction &CGF, bool IsSigned, ArrayRef< Value * > Ops)
Value * readX18AsPtr(CodeGenFunction &CGF)
Helper for the read/write/add/inc X18 builtins: read the X18 register and return it as an i8 pointer.
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)
static llvm::Value * EmitBitTestIntrinsic(CodeGenFunction &CGF, unsigned BuiltinID, const CallExpr *E)
Emit a _bittest* intrinsic.
static Value * emitBuiltinWithOneOverloadedType(CodeGenFunction &CGF, const CallExpr *E, unsigned IntrinsicID, llvm::StringRef Name="")
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 Intrinsic::ID getFirstBitHighIntrinsic(CGHLSLRuntime &RT, QualType QT)
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
@ _InterlockedCompareExchange
@ _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 * handleAsDoubleBuiltin(CodeGenFunction &CGF, const CallExpr *E)
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)
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 Value * handleHlslClip(const CallExpr *E, CodeGenFunction *CGF)
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.
HLSLResourceBindingAttr::RegisterType RegisterType
static QualType getPointeeType(const MemRegion *R)
Enumerates target-specific builtins in their own namespaces within namespace clang.
Defines the clang::TargetOptions class.
C Language Family Type Representation.
__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/...
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
static std::unique_ptr< AtomicScopeModel > create(AtomicScopeModelKind K)
Create an atomic scope model by AtomicScopeModelKind.
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.
ABIArgInfo - Helper class to encapsulate information about how a specific C type should be passed to ...
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)
Address CreateStructGEP(Address Addr, unsigned Index, const llvm::Twine &Name="")
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.
ABIArgInfo & getReturnInfo()
MutableArrayRef< ArgInfo > arguments()
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 * EmitHLSLBuiltinExpr(unsigned BuiltinID, const CallExpr *E, ReturnValueSlot ReturnValue)
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)
void EmitTrapCheck(llvm::Value *Checked, SanitizerHandler CheckHandlerID, bool NoMerge=false)
Create a basic block that will call the trap intrinsic, and emit a conditional branch to it,...
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)
LValue EmitHLSLOutArgExpr(const HLSLOutArgExpr *E, CallArgList &Args, QualType Ty)
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 * 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 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)
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.
llvm::Value * EmitCheckedArgForAssume(const Expr *E)
Emits an argument for a call to a __builtin_assume.
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 * 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()
RValue EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, const CallExpr *E, ReturnValueSlot ReturnValue)
RValue EmitAnyExpr(const Expr *E, AggValueSlot aggSlot=AggValueSlot::ignored(), bool ignoreResult=false)
EmitAnyExpr - Emit code to compute the specified expression which can have any type.
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)
llvm::Value * EmitRISCVCpuIs(const CallExpr *E)
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.
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,...
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::Value * GetCountedByFieldExprGEP(const Expr *Base, const FieldDecl *FAMDecl, const FieldDecl *CountDecl)
llvm::CallInst * EmitRuntimeCall(llvm::FunctionCallee callee, const Twine &name="")
llvm::Value * EmitSVEPredicateTupleCast(llvm::Value *PredTuple, llvm::StructType *Ty)
llvm::Type * ConvertType(QualType T)
void EmitWritebacks(const CallArgList &Args)
EmitWriteback - Emit callbacks for function.
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 * EvaluateExprAsBool(const Expr *E)
EvaluateExprAsBool - Perform the usual unary conversions on the specified expression and compare the ...
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)
llvm::Value * EmitSVETupleSetOrGet(const SVETypeFlags &TypeFlags, ArrayRef< llvm::Value * > Ops)
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()
llvm::Function * getIntrinsic(unsigned IID, ArrayRef< llvm::Type * > Tys={})
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.
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.
llvm::Value * getAggregatePointer(QualType PointeeType, CodeGenFunction &CGF) const
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.
Represents a sugar type with __counted_by or __sized_by annotations, including their _or_null variant...
DynamicCountPointerKind getKind() const
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
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
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
bool areArgsDestroyedLeftToRightInCallee() const
Are arguments to a call destroyed left to right in the callee? This is a fundamental language change,...
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
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
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 hasIntegerRepresentation() const
Determine whether this type has an integer representation of some sort, e.g., it is an integer type o...
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
QualType getElementType() 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 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)
bool Ret(InterpState &S, CodePtr &PC)
The JSON file list parser is used to communicate input to InstallAPI.
@ OK_BitField
A bitfield object is a bitfield on a C or C++ record.
@ Vector
'vector' clause, allowed on 'loop', Combined, and 'routine' directives.
@ DType
'dtype' clause, an alias for 'device_type', stored separately for diagnostic purposes.
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
SyncScope
Defines synch scope values used internally by clang.
llvm::StringRef getAsString(SyncScope S)
@ 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)