18#include "llvm/IR/IntrinsicsAArch64.h"
19#include "llvm/IR/IntrinsicsAMDGPU.h"
20#include "llvm/IR/IntrinsicsARM.h"
21#include "llvm/IR/IntrinsicsBPF.h"
22#include "llvm/IR/IntrinsicsHexagon.h"
23#include "llvm/IR/IntrinsicsLoongArch.h"
24#include "llvm/IR/IntrinsicsMips.h"
25#include "llvm/IR/IntrinsicsNVPTX.h"
26#include "llvm/IR/IntrinsicsPowerPC.h"
27#include "llvm/IR/IntrinsicsR600.h"
28#include "llvm/IR/IntrinsicsRISCV.h"
29#include "llvm/IR/IntrinsicsS390.h"
30#include "llvm/IR/IntrinsicsSPIRV.h"
31#include "llvm/IR/IntrinsicsVE.h"
32#include "llvm/IR/IntrinsicsX86.h"
33#include "llvm/IR/IntrinsicsXCore.h"
45 unsigned NumArgs,
bool IsVarArg,
50#define GET_INTRINSIC_NAME_TABLE
51#include "llvm/IR/IntrinsicImpl.inc"
54 assert(
id < num_intrinsics &&
"Invalid intrinsic ID!");
55 return IntrinsicNameTable[IntrinsicNameOffsetTable[id]];
59 assert(
id < num_intrinsics &&
"Invalid intrinsic ID!");
61 "This version of getName does not support overloading");
80 Result +=
"p" +
utostr(PTyp->getAddressSpace());
82 Result +=
"a" +
utostr(ATyp->getNumElements()) +
85 if (!STyp->isLiteral()) {
88 Result += STyp->getName();
90 HasUnnamedType =
true;
93 for (
auto *Elem : STyp->elements())
100 for (
size_t i = 0; i < FT->getNumParams(); i++)
110 Result +=
"v" +
utostr(EC.getKnownMinValue()) +
114 Result += TETy->getName();
115 for (
Type *ParamTy : TETy->type_params())
117 for (
unsigned IntParam : TETy->int_params())
118 Result +=
"_" +
utostr(IntParam);
122 switch (Ty->getTypeID()) {
129 Result +=
"Metadata";
169 bool EarlyModuleCheck) {
171 assert(Id < Intrinsic::num_intrinsics &&
"Invalid intrinsic ID!");
173 "This version of getName is for overloaded intrinsics only");
174 (void)EarlyModuleCheck;
175 assert((!EarlyModuleCheck || M ||
177 "Intrinsic overloading on pointer types need to provide a Module");
178 bool HasUnnamedType =
false;
180 for (
Type *Ty : OverloadTys)
182 if (HasUnnamedType) {
183 assert(M &&
"unnamed types need a module");
188 "Provided FunctionType must match arguments");
189 return M->getUniqueIntrinsicName(Result, Id, FT);
196 assert(M &&
"We need to have a Module");
210#define GET_INTRINSIC_IITINFO
211#include "llvm/IR/IntrinsicImpl.inc"
214static_assert(IIT_Done == 0,
"IIT_Done expected to be 0");
221 auto IsScalableVector = [&]() {
223 if (NextInfo != IIT_SCALABLE_VEC)
234 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::Void, 0));
237 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::VarArg, 0));
240 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::MMX, 0));
243 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::AMX, 0));
246 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::Token, 0));
249 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::Metadata, 0));
252 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::Half, 0));
255 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::BFloat, 0));
258 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::Float, 0));
261 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::Double, 0));
264 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::Quad, 0));
267 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::PPCQuad, 0));
270 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::Integer, 1));
273 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::Integer, 2));
276 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::Integer, 4));
278 case IIT_AARCH64_SVCOUNT:
279 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::AArch64Svcount, 0));
282 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::Integer, 8));
285 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::Integer, 16));
288 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::Integer, 32));
291 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::Integer, 64));
294 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::Integer, 128));
297 OutputTable.
push_back(IITDescriptor::getVector(1, IsScalableVector()));
301 OutputTable.
push_back(IITDescriptor::getVector(2, IsScalableVector()));
305 OutputTable.
push_back(IITDescriptor::getVector(3, IsScalableVector()));
309 OutputTable.
push_back(IITDescriptor::getVector(4, IsScalableVector()));
313 OutputTable.
push_back(IITDescriptor::getVector(6, IsScalableVector()));
317 OutputTable.
push_back(IITDescriptor::getVector(8, IsScalableVector()));
321 OutputTable.
push_back(IITDescriptor::getVector(10, IsScalableVector()));
325 OutputTable.
push_back(IITDescriptor::getVector(16, IsScalableVector()));
329 OutputTable.
push_back(IITDescriptor::getVector(32, IsScalableVector()));
333 OutputTable.
push_back(IITDescriptor::getVector(64, IsScalableVector()));
337 OutputTable.
push_back(IITDescriptor::getVector(128, IsScalableVector()));
341 OutputTable.
push_back(IITDescriptor::getVector(256, IsScalableVector()));
345 OutputTable.
push_back(IITDescriptor::getVector(512, IsScalableVector()));
349 OutputTable.
push_back(IITDescriptor::getVector(1024, IsScalableVector()));
353 OutputTable.
push_back(IITDescriptor::getVector(2048, IsScalableVector()));
357 OutputTable.
push_back(IITDescriptor::getVector(4096, IsScalableVector()));
361 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::Pointer, 10));
364 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::Pointer, 20));
367 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::Pointer, 0));
371 IITDescriptor::get(IITDescriptor::Pointer, Infos[NextElt++]));
374 unsigned OverloadIndex = Infos[NextElt++];
375 unsigned ArgKindEnums = Infos[NextElt++];
376 unsigned Packed = (ArgKindEnums << 8) | OverloadIndex;
378 IITDescriptor::get(IITDescriptor::Overloaded, Packed));
382 unsigned OverloadIndex = Infos[NextElt++];
384 IITDescriptor::get(IITDescriptor::Match, OverloadIndex));
387 case IIT_EXTEND_ARG: {
388 unsigned OverloadIndex = Infos[NextElt++];
390 IITDescriptor::get(IITDescriptor::Extend, OverloadIndex));
393 case IIT_TRUNC_ARG: {
394 unsigned OverloadIndex = Infos[NextElt++];
396 IITDescriptor::get(IITDescriptor::Trunc, OverloadIndex));
399 case IIT_ONE_NTH_ELTS_VEC_ARG: {
400 unsigned short OverloadIndex = Infos[NextElt++];
401 unsigned short N = Infos[NextElt++];
402 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::OneNthEltsVec,
406 case IIT_SAME_VEC_WIDTH_ARG: {
407 unsigned OverloadIndex = Infos[NextElt++];
409 IITDescriptor::get(IITDescriptor::SameVecWidth, OverloadIndex));
414 case IIT_VEC_OF_ANYPTRS_TO_ELT: {
415 unsigned short OverloadIndex = Infos[NextElt++];
416 unsigned short RefOverloadIndex = Infos[NextElt++];
417 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::VecOfAnyPtrsToElt,
423 unsigned StructElts = Infos[NextElt++] + 2;
426 IITDescriptor::get(IITDescriptor::Struct, StructElts));
428 for (
unsigned i = 0; i != StructElts; ++i)
432 case IIT_SUBDIVIDE2_ARG: {
433 unsigned OverloadIndex = Infos[NextElt++];
435 IITDescriptor::get(IITDescriptor::Subdivide2, OverloadIndex));
438 case IIT_SUBDIVIDE4_ARG: {
439 unsigned OverloadIndex = Infos[NextElt++];
441 IITDescriptor::get(IITDescriptor::Subdivide4, OverloadIndex));
444 case IIT_VEC_ELEMENT: {
445 unsigned OverloadIndex = Infos[NextElt++];
447 IITDescriptor::get(IITDescriptor::VecElement, OverloadIndex));
450 case IIT_VEC_OF_BITCASTS_TO_INT: {
451 unsigned OverloadIndex = Infos[NextElt++];
453 IITDescriptor::get(IITDescriptor::VecOfBitcastsToInt, OverloadIndex));
456 case IIT_SCALABLE_VEC:
462#define GET_INTRINSIC_GENERATOR_GLOBAL
463#include "llvm/IR/IntrinsicImpl.inc"
465std::tuple<ArrayRef<Intrinsic::IITDescriptor>,
unsigned,
bool>
471 constexpr unsigned FixedEncodingBits =
sizeof(FixedEncodingTy) * CHAR_BIT;
472 constexpr unsigned MSBPosition = FixedEncodingBits - 1;
474 constexpr unsigned Mask = (1U << MSBPosition) - 1;
476 FixedEncodingTy TableVal = IIT_Table[
id - 1];
486 unsigned char IITValues[FixedEncodingBits / 4 + 1] = {0};
489 unsigned NextElt = 0;
492 if (TableVal >> MSBPosition) {
494 IITEntries = IIT_LongEncodingTable;
497 NextElt = TableVal & Mask;
502 IITValues[NextElt++] = TableVal & 0xF;
506 IITEntries = IITValues;
512 unsigned NumArgs = 0;
513 while (IITEntries[NextElt] != IIT_Done) {
520 bool IsVarArg =
false;
526 return {
TableRef, NumArgs, IsVarArg};
537 case IITDescriptor::Void:
539 case IITDescriptor::MMX:
541 case IITDescriptor::AMX:
543 case IITDescriptor::Token:
545 case IITDescriptor::Metadata:
547 case IITDescriptor::Half:
549 case IITDescriptor::BFloat:
551 case IITDescriptor::Float:
553 case IITDescriptor::Double:
555 case IITDescriptor::Quad:
557 case IITDescriptor::PPCQuad:
559 case IITDescriptor::AArch64Svcount:
562 case IITDescriptor::Integer:
564 case IITDescriptor::Vector:
567 case IITDescriptor::Pointer:
569 case IITDescriptor::Struct: {
571 for (
unsigned i = 0, e =
D.StructNumElements; i != e; ++i)
578 case IITDescriptor::Overloaded:
579 case IITDescriptor::VecOfAnyPtrsToElt:
580 case IITDescriptor::Match:
581 return OverloadTys[
D.getOverloadIndex()];
582 case IITDescriptor::Extend:
583 return OverloadTys[
D.getOverloadIndex()]->getExtendedType();
584 case IITDescriptor::Trunc:
585 return OverloadTys[
D.getOverloadIndex()]->getTruncatedType();
586 case IITDescriptor::Subdivide2:
587 case IITDescriptor::Subdivide4: {
588 Type *Ty = OverloadTys[
D.getOverloadIndex()];
590 assert(VTy &&
"Expected overload type to be a Vector Type");
591 int SubDivs =
D.Kind == IITDescriptor::Subdivide2 ? 1 : 2;
594 case IITDescriptor::OneNthEltsVec:
597 D.getVectorDivisor());
598 case IITDescriptor::SameVecWidth: {
600 Type *Ty = OverloadTys[
D.getOverloadIndex()];
605 case IITDescriptor::VecElement: {
606 Type *Ty = OverloadTys[
D.getOverloadIndex()];
608 return VTy->getElementType();
611 case IITDescriptor::VecOfBitcastsToInt: {
612 Type *Ty = OverloadTys[
D.getOverloadIndex()];
614 assert(VTy &&
"Expected overload type to be a Vector Type");
617 case IITDescriptor::VarArg:
639#define GET_INTRINSIC_OVERLOAD_TABLE
640#include "llvm/IR/IntrinsicImpl.inc"
644#define GET_INTRINSIC_SCALARIZABLE_TABLE
645#include "llvm/IR/IntrinsicImpl.inc"
649#define GET_INTRINSIC_PRETTY_PRINT_TABLE
650#include "llvm/IR/IntrinsicImpl.inc"
654#define GET_INTRINSIC_TARGET_DATA
655#include "llvm/IR/IntrinsicImpl.inc"
658 return IID > TargetInfos[0].Count;
667 assert(Name.starts_with(
"llvm.") &&
"Unexpected intrinsic prefix");
668 assert(Name.drop_front(5).starts_with(
Target) &&
"Unexpected target");
679 CmpEnd += 1 +
Target.size();
681 const unsigned *
Low = NameOffsetTable.
begin();
682 const unsigned *
High = NameOffsetTable.
end();
683 const unsigned *LastLow =
Low;
684 while (CmpEnd < Name.size() &&
High -
Low > 0) {
685 size_t CmpStart = CmpEnd;
686 CmpEnd = Name.find(
'.', CmpStart + 1);
688 auto Cmp = [CmpStart, CmpEnd](
auto LHS,
auto RHS) {
693 if constexpr (std::is_integral_v<
decltype(
LHS)>)
694 LHSStr = IntrinsicNameTable.getCString(
LHS);
699 if constexpr (std::is_integral_v<
decltype(
RHS)>)
700 RHSStr = IntrinsicNameTable.getCString(
RHS);
704 return strncmp(LHSStr + CmpStart, RHSStr + CmpStart, CmpEnd - CmpStart) <
708 std::tie(
Low,
High) = std::equal_range(
Low,
High, Name.data(), Cmp);
713 if (LastLow == NameOffsetTable.
end())
715 StringRef NameFound = IntrinsicNameTable[*LastLow];
716 if (Name == NameFound ||
717 (Name.starts_with(NameFound) && Name[NameFound.
size()] ==
'.'))
718 return LastLow - NameOffsetTable.
begin();
727static std::pair<ArrayRef<unsigned>,
StringRef>
729 assert(Name.starts_with(
"llvm."));
736 Targets, [=](
const IntrinsicTargetInfo &TI) {
return TI.Name <
Target; });
739 const auto &TI = It != Targets.
end() && It->Name ==
Target ? *It : Targets[0];
740 return {
ArrayRef(&IntrinsicNameOffsetTable[1] + TI.Offset, TI.Count),
754 int Adjust = NameOffsetTable.data() - IntrinsicNameOffsetTable;
759 const auto MatchSize = IntrinsicNameTable[NameOffsetTable[Idx]].size();
760 assert(Name.size() >= MatchSize &&
"Expected either exact or prefix match");
761 bool IsExactMatch = Name.size() == MatchSize;
767#define GET_INTRINSIC_ATTRIBUTES
768#include "llvm/IR/IntrinsicImpl.inc"
774 std::string Name = OverloadTys.
empty()
778 if (
F->getFunctionType() == FT)
786 F->setName(
F->getName() +
".invalid");
787 return cast<Function>(M->getOrInsertFunction(Name, FT).getCallee());
813 assert(IsValid &&
"intrinsic signature mismatch");
828#define GET_LLVM_INTRINSIC_FOR_CLANG_BUILTIN
829#include "llvm/IR/IntrinsicImpl.inc"
832#define GET_LLVM_INTRINSIC_FOR_MS_BUILTIN
833#include "llvm/IR/IntrinsicImpl.inc"
837#define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC) \
838 case Intrinsic::INTRINSIC:
839#include "llvm/IR/ConstrainedOps.def"
849#define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC) \
850 case Intrinsic::INTRINSIC: \
851 return ROUND_MODE == 1;
852#include "llvm/IR/ConstrainedOps.def"
876struct MatchPosition {
886 static constexpr unsigned INDEX_TABLE_SIZE = 2;
887 Index Indices[INDEX_TABLE_SIZE];
891 assert(NumIndices > 0 &&
"cannot pop from empty indices");
895 void push_struct_element(
unsigned ElementNum) {
896 assert(NumIndices < INDEX_TABLE_SIZE &&
"index table overflow");
898 Indices[NumIndices].IsStruct =
true;
899 Indices[NumIndices++].Num = ElementNum;
902 void push_vector_element() {
903 assert(NumIndices < INDEX_TABLE_SIZE &&
"index table overflow");
904 Indices[NumIndices].IsStruct =
false;
905 Indices[NumIndices++].Num = 0;
916 OS <<
"argument " << Pos.Num;
918 for (
const MatchPosition::Index &Idx :
919 ArrayRef(Pos.Indices).take_front(Pos.NumIndices)) {
921 OS <<
" struct element " << Idx.Num;
923 OS <<
" vector element";
929 std::tuple<Type *, ArrayRef<Intrinsic::IITDescriptor>, MatchPosition>;
940 OS << Position <<
" too many "
941 << (Position.IsRet ?
"returns" :
"arguments");
946 auto InfosRef = Infos;
947 auto DeferCheck = [&DeferredChecks, &InfosRef, &Position](
Type *
T) {
956 auto PrintMsg = [&OS, &Position,
958 std::optional<unsigned> OIdx = std::nullopt) ->
bool {
961 OS << Position <<
" type";
963 OS <<
" (overload type " << *OIdx <<
")";
964 OS <<
" expected " <<
Expected <<
", but got " << *Ty;
971 auto PrintMsgInvalidOverloadTy =
972 [&OS, &Position, &OverloadTys](
const Twine &DependentQualifier,
974 unsigned OIdx) ->
bool {
975 OS << Position <<
" is " << DependentQualifier <<
" overload type " << OIdx
976 <<
", so overload type " << OIdx <<
" expected " <<
Expected
977 <<
", but got " << *OverloadTys[OIdx];
982 auto PrintMsgInvalidDepType =
983 [&OS, &Position, &OverloadTys,
985 unsigned OIdx) ->
bool {
988 bool IsMatching = DependentQualifier.isSingleStringRef() &&
989 DependentQualifier.getSingleStringRef() ==
"matching";
990 OS << Position <<
" type (" << DependentQualifier <<
" overload type "
991 << OIdx <<
") expected " <<
Expected;
993 OS <<
" (overload type " << OIdx <<
" is " << *OverloadTys[OIdx] <<
")";
994 OS <<
", but got " << *Ty;
999 case IITDescriptor::Void:
1000 assert(Position.IsRet && Position.NumIndices == 0 &&
1001 "void descriptor expected only for return type");
1002 return PrintMsg(Ty->isVoidTy(),
"void");
1003 case IITDescriptor::MMX: {
1007 "x86_mmx (<1 x i64>)");
1009 case IITDescriptor::AMX:
1010 return PrintMsg(Ty->isX86_AMXTy(),
"x86_amx");
1011 case IITDescriptor::Token:
1012 return PrintMsg(Ty->isTokenTy(),
"token");
1013 case IITDescriptor::Metadata:
1014 return PrintMsg(Ty->isMetadataTy(),
"metadata");
1015 case IITDescriptor::Half:
1016 return PrintMsg(Ty->isHalfTy(),
"half");
1017 case IITDescriptor::BFloat:
1018 return PrintMsg(Ty->isBFloatTy(),
"bfloat");
1019 case IITDescriptor::Float:
1020 return PrintMsg(Ty->isFloatTy(),
"float");
1021 case IITDescriptor::Double:
1022 return PrintMsg(Ty->isDoubleTy(),
"double");
1023 case IITDescriptor::Quad:
1024 return PrintMsg(Ty->isFP128Ty(),
"fp128");
1025 case IITDescriptor::PPCQuad:
1026 return PrintMsg(Ty->isPPC_FP128Ty(),
"ppc_fp128");
1027 case IITDescriptor::Integer:
1028 return PrintMsg(Ty->isIntegerTy(
D.IntegerWidth),
1029 "i" +
Twine(
D.IntegerWidth));
1030 case IITDescriptor::AArch64Svcount:
1034 case IITDescriptor::Vector: {
1036 StringRef Scalable =
D.VectorWidth.isScalable() ?
"vscale " :
"";
1038 PrintMsg(VT && VT->getElementCount() ==
D.VectorWidth,
1039 Twine(Scalable) +
"vector with " +
1040 Twine(
D.VectorWidth.getKnownMinValue()) +
" elements");
1043 Position.push_vector_element();
1045 OverloadTys, DeferredChecks, IsDeferredCheck, OS);
1047 case IITDescriptor::Pointer: {
1049 unsigned AS =
D.PointerAddressSpace;
1050 bool IsValid = PT && PT->getAddressSpace() == AS;
1052 return PrintMsg(IsValid,
"ptr");
1053 return PrintMsg(IsValid,
"ptr addrspace(" +
Twine(AS) +
")");
1056 case IITDescriptor::Struct: {
1058 unsigned EC =
D.StructNumElements;
1059 bool HasError = PrintMsg(
1060 ST && ST->isLiteral() && !ST->isPacked() && ST->getNumElements() == EC,
1061 "literal non-packed struct with " +
Twine(EC) +
" elements");
1066 Position.push_struct_element(Idx);
1068 IsDeferredCheck, OS))
1070 Position.pop_index();
1075 case IITDescriptor::Overloaded: {
1076 unsigned OIdx =
D.getOverloadIndex();
1077 assert(OIdx == OverloadTys.
size() && !IsDeferredCheck &&
1078 "Table consistency error");
1081 IITDescriptor::AnyKindVectorConstraint VC;
1082 IITDescriptor::AnyKindElementConstraint EC;
1083 std::tie(VC, EC) =
D.getOverloadConstraints();
1085 bool IsValid = [&]() {
1087 case IITDescriptor::VC_None:
1089 case IITDescriptor::VC_Vector:
1091 case IITDescriptor::VC_Scalar:
1100 case IITDescriptor::EC_None:
1102 case IITDescriptor::EC_Integer:
1104 case IITDescriptor::EC_Float:
1106 case IITDescriptor::EC_Pointer:
1127 if (EC == IITDescriptor::EC_None) {
1131 return PrintMsg(
false,
formatv(
"any {} type", VK), OIdx);
1136 case IITDescriptor::VC_None:
1138 return PrintMsg(
false,
formatv(
"any {0} or {0} vector", EK), OIdx);
1139 case IITDescriptor::VC_Vector:
1140 return PrintMsg(
false,
formatv(
"any {} vector", EK), OIdx);
1141 case IITDescriptor::VC_Scalar:
1142 return PrintMsg(
false,
formatv(
"any {} type", EK), OIdx);
1146 case IITDescriptor::Match: {
1147 unsigned OIdx =
D.getOverloadIndex();
1148 if (OIdx >= OverloadTys.
size())
1149 return IsDeferredCheck || DeferCheck(Ty);
1150 return PrintMsgInvalidDepType(Ty == OverloadTys[OIdx],
"matching",
1151 formatv(
"{}", *OverloadTys[OIdx]), OIdx);
1154 case IITDescriptor::Extend:
1155 case IITDescriptor::Trunc: {
1156 unsigned OIdx =
D.getOverloadIndex();
1158 if (OIdx >= OverloadTys.
size())
1159 return IsDeferredCheck || DeferCheck(Ty);
1161 Type *OTy = OverloadTys[OIdx];
1162 bool IsExtend =
D.Kind == IITDescriptor::Extend;
1163 StringRef Qualifier = IsExtend ?
"extended" :
"truncated";
1165 return PrintMsgInvalidOverloadTy(Qualifier,
"int or vector of int", OIdx);
1168 return PrintMsgInvalidDepType(Ty == NewTy, Qualifier,
formatv(
"{}", *NewTy),
1171 case IITDescriptor::OneNthEltsVec: {
1172 unsigned OIdx =
D.getOverloadIndex();
1173 unsigned Divisor =
D.getVectorDivisor();
1175 if (OIdx >= OverloadTys.
size())
1176 return IsDeferredCheck || DeferCheck(Ty);
1177 Type *OTy = OverloadTys[OIdx];
1179 auto Qualifier =
formatv(
"1/nth (n={}) elements vector of", Divisor);
1181 return PrintMsgInvalidOverloadTy(Qualifier,
"vector", OIdx);
1182 if (!OVecTy->getElementCount().isKnownMultipleOf(Divisor))
1183 return PrintMsgInvalidOverloadTy(
1184 Qualifier,
formatv(
"vector with multiple of {} elements", Divisor),
1187 return PrintMsgInvalidDepType(
Expected == Ty, Qualifier,
1190 case IITDescriptor::SameVecWidth: {
1191 unsigned OIdx =
D.getOverloadIndex();
1192 if (OIdx >= OverloadTys.
size()) {
1195 return IsDeferredCheck || DeferCheck(Ty);
1200 StringRef Qualifier =
"same vector width of";
1201 if (OVecTy && !ThisArgVecType)
1202 return PrintMsgInvalidDepType(
false, Qualifier,
"vector", OIdx);
1203 if (!OVecTy && ThisArgVecType)
1204 return PrintMsgInvalidDepType(
false, Qualifier,
"scalar", OIdx);
1206 if (ThisArgVecType) {
1208 if (
Expected != ThisArgVecType->getElementCount())
1209 return PrintMsgInvalidDepType(
1212 EltTy = ThisArgVecType->getElementType();
1213 Position.push_vector_element();
1216 DeferredChecks, IsDeferredCheck, OS);
1218 case IITDescriptor::VecOfAnyPtrsToElt: {
1219 unsigned RefOverloadIndex =
D.getRefOverloadIndex();
1220 if (RefOverloadIndex >= OverloadTys.
size()) {
1221 if (IsDeferredCheck)
1225 assert(
D.getOverloadIndex() == OverloadTys.
size() &&
1226 "Table consistency error");
1228 return DeferCheck(Ty);
1231 if (!IsDeferredCheck) {
1232 assert(
D.getOverloadIndex() == OverloadTys.
size() &&
1233 "Table consistency error");
1240 StringRef Qualifier =
"vector of pointers to elements of";
1243 return PrintMsgInvalidOverloadTy(Qualifier,
"vector", RefOverloadIndex);
1247 return PrintMsgInvalidDepType(
false, Qualifier,
"vector",
1252 formatv(
"vector of pointers with {} elements", ExpectedCount);
1253 bool IsValid = ThisArgVecTy->getElementCount() == ExpectedCount &&
1254 ThisArgVecTy->getElementType()->isPointerTy();
1255 return PrintMsgInvalidDepType(IsValid, Qualifier,
Expected,
1258 case IITDescriptor::VecElement: {
1259 unsigned OIdx =
D.getOverloadIndex();
1260 if (OIdx >= OverloadTys.
size())
1261 return IsDeferredCheck || DeferCheck(Ty);
1262 StringRef Qualifier =
"vector element of";
1265 return PrintMsgInvalidOverloadTy(Qualifier,
"vector", OIdx);
1267 return PrintMsgInvalidDepType(
Expected == Ty, Qualifier,
1270 case IITDescriptor::Subdivide2:
1271 case IITDescriptor::Subdivide4: {
1272 unsigned OIdx =
D.getOverloadIndex();
1274 if (OIdx >= OverloadTys.
size())
1275 return IsDeferredCheck || DeferCheck(Ty);
1277 int SubDivs =
D.Kind == IITDescriptor::Subdivide2 ? 1 : 2;
1280 formatv(
"subdivided by {} vector of", SubDivs == 1 ? 2 : 4);
1282 return PrintMsgInvalidOverloadTy(Qualifier,
"vector", OIdx);
1287 return PrintMsgInvalidDepType(
Expected == Ty, Qualifier,
1290 case IITDescriptor::VecOfBitcastsToInt: {
1291 unsigned OIdx =
D.getOverloadIndex();
1292 if (OIdx >= OverloadTys.
size())
1293 return IsDeferredCheck || DeferCheck(Ty);
1295 StringRef Qualifier =
"vector of bitcasts to int of";
1297 return PrintMsgInvalidOverloadTy(Qualifier,
"vector", OIdx);
1299 return PrintMsgInvalidDepType(
Expected == Ty, Qualifier,
1302 case IITDescriptor::VarArg:
1319 unsigned NumArgs,
bool IsVarArg,
1324 assert(!Infos.
empty() &&
"Table consistency error");
1331 DeferredChecks,
false, OS))
1334 if (FTy->getNumParams() != NumArgs) {
1335 OS <<
"intrinsic has incorrect number of args. Expected " << NumArgs
1336 <<
", but got " << FTy->getNumParams();
1348 for (
unsigned I = 0,
E = DeferredChecks.
size();
I !=
E; ++
I) {
1349 auto &[DefTy, DefInfos, DefPosition] = DeferredChecks[
I];
1351 DeferredChecks,
true, OS))
1355 if (!Infos.
empty()) {
1356 OS <<
"intrinsic has too few arguments!";
1360 if (FTy->isVarArg() != IsVarArg) {
1362 OS <<
"intrinsic was not defined with variable arguments!";
1364 OS <<
"intrinsic was defined with variable arguments!";
1387 return ::isSignatureValid(FT,
TableRef, NumArgs, IsVarArg, OverloadTys, OS);
1400 return std::nullopt;
1404 std::string WantedName =
1406 if (Name == WantedName)
1407 return std::nullopt;
1410 if (
auto *ExistingGV =
F->getParent()->getNamedValue(WantedName)) {
1412 if (ExistingF->getFunctionType() ==
F->getFunctionType())
1419 ExistingGV->setName(WantedName +
".renamed");
1426 "Shouldn't change the signature");
1435 {Intrinsic::vector_interleave2, Intrinsic::vector_deinterleave2},
1436 {Intrinsic::vector_interleave3, Intrinsic::vector_deinterleave3},
1437 {Intrinsic::vector_interleave4, Intrinsic::vector_deinterleave4},
1438 {Intrinsic::vector_interleave5, Intrinsic::vector_deinterleave5},
1439 {Intrinsic::vector_interleave6, Intrinsic::vector_deinterleave6},
1440 {Intrinsic::vector_interleave7, Intrinsic::vector_deinterleave7},
1441 {Intrinsic::vector_interleave8, Intrinsic::vector_deinterleave8},
1445 assert(Factor >= 2 && Factor <= 8 &&
"Unexpected factor");
1450 assert(Factor >= 2 && Factor <= 8 &&
"Unexpected factor");
1454#define GET_INTRINSIC_PRETTY_PRINT_ARGUMENTS
1455#include "llvm/IR/IntrinsicImpl.inc"
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
ArrayRef< TableEntry > TableRef
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Module.h This file contains the declarations for the Module class.
static bool matchIntrinsicType(Type *Ty, ArrayRef< Intrinsic::IITDescriptor > &Infos, MatchPosition Position, SmallVectorImpl< Type * > &OverloadTys, SmallVectorImpl< DeferredIntrinsicMatchInfo > &DeferredChecks, bool IsDeferredCheck, raw_ostream &OS)
static bool isSignatureValid(FunctionType *FTy, ArrayRef< Intrinsic::IITDescriptor > &Infos, unsigned NumArgs, bool IsVarArg, SmallVectorImpl< Type * > &OverloadTys, raw_ostream &OS)
Return true if the function type FTy is a valid type signature for the type constraints specified in ...
static InterleaveIntrinsic InterleaveIntrinsics[]
std::tuple< Type *, ArrayRef< Intrinsic::IITDescriptor >, MatchPosition > DeferredIntrinsicMatchInfo
static std::pair< ArrayRef< unsigned >, StringRef > findTargetSubtable(StringRef Name)
Find the segment of IntrinsicNameOffsetTable for intrinsics with the same target as Name,...
static Function * getOrInsertIntrinsicDeclarationImpl(Module *M, Intrinsic::ID id, ArrayRef< Type * > OverloadTys, FunctionType *FT)
static void DecodeIITType(unsigned &NextElt, ArrayRef< unsigned char > Infos, SmallVectorImpl< Intrinsic::IITDescriptor > &OutputTable)
static std::string getIntrinsicNameImpl(Intrinsic::ID Id, ArrayRef< Type * > OverloadTys, Module *M, FunctionType *FT, bool EarlyModuleCheck)
IIT_Info
IIT_Info - These are enumerators that describe the entries returned by the getIntrinsicInfoTableEntri...
static Type * DecodeFixedType(ArrayRef< Intrinsic::IITDescriptor > &Infos, ArrayRef< Type * > OverloadTys, LLVMContext &Context)
static int lookupLLVMIntrinsicByName(ArrayRef< unsigned > NameOffsetTable, StringRef Name, StringRef Target="")
Looks up Name in NameTable via binary search.
static std::string getMangledTypeStr(Type *Ty, bool &HasUnnamedType)
Returns a stable mangling for the type specified for use in the name mangling scheme used by 'any' ty...
This file contains the definitions of the enumerations and flags associated with NVVM Intrinsics,...
static StringRef getName(Value *V)
static SymbolRef::Type getType(const Symbol *Sym)
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
bool empty() const
Check if the array is empty.
const T & consume_front()
consume_front() - Returns the first element and drops it from ArrayRef.
Tagged union holding either a T or a Error.
Class to represent fixed width SIMD vectors.
unsigned getNumElements() const
static LLVM_ABI FixedVectorType * get(Type *ElementType, unsigned NumElts)
Class to represent function types.
static LLVM_ABI FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
FunctionType * getFunctionType() const
Returns the FunctionType for me.
const Function & getFunction() const
void setCallingConv(CallingConv::ID CC)
static LLVM_ABI IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
This is an important class for using LLVM in a threaded context.
A Module instance is used to store all the information related to an LLVM module.
static LLVM_ABI PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
reference emplace_back(ArgTypes &&... Args)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
Represent a constant reference to a string, i.e.
static constexpr size_t npos
std::string str() const
Get the contents as an std::string.
constexpr size_t size() const
Get the string size.
Class to represent struct types.
static LLVM_ABI StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
Class to represent target extensions types, which are generally unintrospectable from target-independ...
static LLVM_ABI TargetExtType * get(LLVMContext &Context, StringRef Name, ArrayRef< Type * > Types={}, ArrayRef< unsigned > Ints={})
Return a target extension type having the specified name and optional type and integer parameters.
Target - Wrapper for Target specific information.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
static LLVM_ABI Type * getX86_AMXTy(LLVMContext &C)
LLVM_ABI Type * getTruncatedType() const
Given scalar/vector integer type, returns a type with elements half as wide as in the original type.
static LLVM_ABI Type * getMetadataTy(LLVMContext &C)
static LLVM_ABI Type * getTokenTy(LLVMContext &C)
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
bool isPointerTy() const
True if this is an instance of PointerType.
static LLVM_ABI Type * getPPC_FP128Ty(LLVMContext &C)
static LLVM_ABI Type * getFP128Ty(LLVMContext &C)
@ X86_AMXTyID
AMX vectors (8192 bits, X86 specific)
@ HalfTyID
16-bit floating point type
@ VoidTyID
type with no size
@ FloatTyID
32-bit floating point type
@ IntegerTyID
Arbitrary bit width integers.
@ BFloatTyID
16-bit floating point type (7-bit significand)
@ DoubleTyID
64-bit floating point type
@ X86_FP80TyID
80-bit floating point type (X87)
@ PPC_FP128TyID
128-bit floating point type (two 64-bits, PowerPC)
@ ByteTyID
Arbitrary bit width bytes.
@ FP128TyID
128-bit floating point type (112-bit significand)
static LLVM_ABI Type * getVoidTy(LLVMContext &C)
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
bool isFloatingPointTy() const
Return true if this is one of the floating-point types.
LLVM_ABI Type * getExtendedType() const
Given scalar/vector integer type, returns a type with elements twice as wide as in the original type.
bool isIntegerTy() const
True if this is an instance of IntegerType.
static LLVM_ABI Type * getDoubleTy(LLVMContext &C)
static LLVM_ABI Type * getFloatTy(LLVMContext &C)
static LLVM_ABI Type * getBFloatTy(LLVMContext &C)
static LLVM_ABI Type * getHalfTy(LLVMContext &C)
static VectorType * getOneNthElementsVectorType(VectorType *VTy, unsigned Denominator)
static VectorType * getSubdividedVectorType(VectorType *VTy, int NumSubdivs)
static VectorType * getInteger(VectorType *VTy)
This static method gets a VectorType with the same number of elements as the input type,...
static LLVM_ABI VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
Type * getElementType() const
This class implements an extremely fast bulk output stream that can only output to a stream.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
This namespace contains an enum with a value for every intrinsic/builtin function known by LLVM.
LLVM_ABI Intrinsic::ID getDeinterleaveIntrinsicID(unsigned Factor)
Returns the corresponding llvm.vector.deinterleaveN intrinsic for factor N.
LLVM_ABI Function * getDeclarationIfExists(const Module *M, ID id)
Look up the Function declaration of the intrinsic id in the Module M and return it if it exists.
LLVM_ABI std::optional< Function * > remangleIntrinsicFunction(Function *F)
LLVM_ABI bool hasConstrainedFPRoundingModeOperand(ID QID)
Returns true if the intrinsic ID is for one of the "ConstrainedFloating-Point Intrinsics" that take r...
LLVM_ABI StringRef getName(ID id)
Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
LLVM_ABI Function * getOrInsertDeclaration(Module *M, ID id, ArrayRef< Type * > OverloadTys={})
Look up the Function declaration of the intrinsic id in the Module M.
LLVM_ABI bool isConstrainedFPIntrinsic(ID QID)
Returns true if the intrinsic ID is for one of the "ConstrainedFloating-Point Intrinsics".
LLVM_ABI ID lookupIntrinsicID(StringRef Name)
This does the actual lookup of an intrinsic ID which matches the given function name.
LLVM_ABI bool hasPrettyPrintedArgs(ID id)
Returns true if the intrinsic has pretty printed immediate arguments.
LLVM_ABI std::tuple< ArrayRef< IITDescriptor >, unsigned, bool > getIntrinsicInfoTableEntries(ID id, SmallVectorImpl< IITDescriptor > &T)
Fill the IIT table descriptor for the intrinsic id into an array of IITDescriptors.
LLVM_ABI StringRef getBaseName(ID id)
Return the LLVM name for an intrinsic, without encoded types for overloading, such as "llvm....
LLVM_ABI Intrinsic::ID getInterleaveIntrinsicID(unsigned Factor)
Returns the corresponding llvm.vector.interleaveN intrinsic for factor N.
LLVM_ABI bool isOverloaded(ID id)
Returns true if the intrinsic can be overloaded.
LLVM_ABI FunctionType * getType(LLVMContext &Context, ID id, ArrayRef< Type * > OverloadTys={})
Return the function type for an intrinsic.
LLVM_ABI bool isSignatureValid(Intrinsic::ID ID, FunctionType *FT, SmallVectorImpl< Type * > &OverloadTys, raw_ostream &OS=nulls())
Returns true if FT is a valid function type for intrinsic ID.
LLVM_ABI bool hasStructReturnType(ID id)
Returns true if id has a struct return type.
LLVM_ABI bool isTriviallyScalarizable(ID id)
Returns true if the intrinsic is trivially scalarizable.
LLVM_ABI bool isTargetIntrinsic(ID IID)
isTargetIntrinsic - Returns true if IID is an intrinsic specific to a certain target.
LLVM_ABI std::string getNameNoUnnamedTypes(ID Id, ArrayRef< Type * > OverloadTys)
Return the LLVM name for an intrinsic.
This is an optimization pass for GlobalISel generic memory operations.
@ Low
Lower the current thread's priority such that it does not affect foreground tasks significantly.
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
auto partition_point(R &&Range, Predicate P)
Binary search for the first iterator in a range where a predicate is false.
std::string utostr(uint64_t X, bool isNeg=false)
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
LLVM_ABI raw_ostream & nulls()
This returns a reference to a raw_ostream which simply discards output.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
ArrayRef(const T &OneElt) -> ArrayRef< T >
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
constexpr detail::IsaCheckPredicate< Types... > IsaPred
Function object wrapper for the llvm::isa type check.
Intrinsic::ID Deinterleave