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#define GET_INTRINSIC_TARGET_FEATURES_TABLE
55#include "llvm/IR/IntrinsicImpl.inc"
58 assert(
id < num_intrinsics &&
"Invalid intrinsic ID!");
59 return IntrinsicNameTable[IntrinsicNameOffsetTable[id]];
63 assert(
id < num_intrinsics &&
"invalid intrinsic ID!");
64 return IntrinsicTargetFeaturesTable[IntrinsicTargetFeaturesOffsetTable[id]];
68 assert(
id < num_intrinsics &&
"Invalid intrinsic ID!");
70 "This version of getName does not support overloading");
89 Result +=
"p" +
utostr(PTyp->getAddressSpace());
91 Result +=
"a" +
utostr(ATyp->getNumElements()) +
94 if (!STyp->isLiteral()) {
97 Result += STyp->getName();
99 HasUnnamedType =
true;
102 for (
auto *Elem : STyp->elements())
109 for (
size_t i = 0; i < FT->getNumParams(); i++)
119 Result +=
"v" +
utostr(EC.getKnownMinValue()) +
123 Result += TETy->getName();
124 for (
Type *ParamTy : TETy->type_params())
126 for (
unsigned IntParam : TETy->int_params())
127 Result +=
"_" +
utostr(IntParam);
131 switch (Ty->getTypeID()) {
138 Result +=
"Metadata";
178 bool EarlyModuleCheck) {
180 assert(Id < Intrinsic::num_intrinsics &&
"Invalid intrinsic ID!");
182 "This version of getName is for overloaded intrinsics only");
183 (void)EarlyModuleCheck;
184 assert((!EarlyModuleCheck || M ||
186 "Intrinsic overloading on pointer types need to provide a Module");
187 bool HasUnnamedType =
false;
189 for (
Type *Ty : OverloadTys)
191 if (HasUnnamedType) {
192 assert(M &&
"unnamed types need a module");
197 "Provided FunctionType must match arguments");
198 return M->getUniqueIntrinsicName(Result, Id, FT);
205 assert(M &&
"We need to have a Module");
219#define GET_INTRINSIC_IITINFO
220#include "llvm/IR/IntrinsicImpl.inc"
223static_assert(IIT_Done == 0,
"IIT_Done expected to be 0");
230 auto IsScalableVector = [&]() {
232 if (NextInfo != IIT_SCALABLE_VEC)
243 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::Void, 0));
246 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::VarArg, 0));
249 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::MMX, 0));
252 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::AMX, 0));
255 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::Token, 0));
258 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::Metadata, 0));
261 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::Half, 0));
264 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::BFloat, 0));
267 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::Float, 0));
270 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::Double, 0));
273 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::Quad, 0));
276 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::PPCQuad, 0));
279 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::Integer, 1));
282 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::Integer, 2));
285 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::Integer, 4));
287 case IIT_AARCH64_SVCOUNT:
288 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::AArch64Svcount, 0));
291 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::Integer, 8));
294 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::Integer, 16));
297 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::Integer, 32));
300 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::Integer, 64));
303 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::Integer, 128));
306 OutputTable.
push_back(IITDescriptor::getVector(1, IsScalableVector()));
310 OutputTable.
push_back(IITDescriptor::getVector(2, IsScalableVector()));
314 OutputTable.
push_back(IITDescriptor::getVector(3, IsScalableVector()));
318 OutputTable.
push_back(IITDescriptor::getVector(4, IsScalableVector()));
322 OutputTable.
push_back(IITDescriptor::getVector(6, IsScalableVector()));
326 OutputTable.
push_back(IITDescriptor::getVector(8, IsScalableVector()));
330 OutputTable.
push_back(IITDescriptor::getVector(10, IsScalableVector()));
334 OutputTable.
push_back(IITDescriptor::getVector(16, IsScalableVector()));
338 OutputTable.
push_back(IITDescriptor::getVector(32, IsScalableVector()));
342 OutputTable.
push_back(IITDescriptor::getVector(64, IsScalableVector()));
346 OutputTable.
push_back(IITDescriptor::getVector(128, IsScalableVector()));
350 OutputTable.
push_back(IITDescriptor::getVector(256, IsScalableVector()));
354 OutputTable.
push_back(IITDescriptor::getVector(512, IsScalableVector()));
358 OutputTable.
push_back(IITDescriptor::getVector(1024, IsScalableVector()));
362 OutputTable.
push_back(IITDescriptor::getVector(2048, IsScalableVector()));
366 OutputTable.
push_back(IITDescriptor::getVector(4096, IsScalableVector()));
370 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::WasmExternref, 0));
373 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::WasmFuncref, 0));
376 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::Pointer, 0));
380 IITDescriptor::get(IITDescriptor::Pointer, Infos[NextElt++]));
383 unsigned OverloadIndex = Infos[NextElt++];
384 unsigned ArgKindEnums = Infos[NextElt++];
385 unsigned Packed = (ArgKindEnums << 8) | OverloadIndex;
387 IITDescriptor::get(IITDescriptor::Overloaded, Packed));
391 unsigned OverloadIndex = Infos[NextElt++];
393 IITDescriptor::get(IITDescriptor::Match, OverloadIndex));
396 case IIT_EXTEND_ARG: {
397 unsigned OverloadIndex = Infos[NextElt++];
399 IITDescriptor::get(IITDescriptor::Extend, OverloadIndex));
402 case IIT_TRUNC_ARG: {
403 unsigned OverloadIndex = Infos[NextElt++];
405 IITDescriptor::get(IITDescriptor::Trunc, OverloadIndex));
408 case IIT_ONE_NTH_ELTS_VEC_ARG: {
409 unsigned short OverloadIndex = Infos[NextElt++];
410 unsigned short N = Infos[NextElt++];
411 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::OneNthEltsVec,
415 case IIT_SAME_VEC_WIDTH_ARG: {
416 unsigned OverloadIndex = Infos[NextElt++];
418 IITDescriptor::get(IITDescriptor::SameVecWidth, OverloadIndex));
423 case IIT_VEC_OF_ANYPTRS_TO_ELT: {
424 unsigned short OverloadIndex = Infos[NextElt++];
425 unsigned short RefOverloadIndex = Infos[NextElt++];
426 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::VecOfAnyPtrsToElt,
432 unsigned StructElts = Infos[NextElt++] + 2;
435 IITDescriptor::get(IITDescriptor::Struct, StructElts));
437 for (
unsigned i = 0; i != StructElts; ++i)
441 case IIT_SUBDIVIDE2_ARG: {
442 unsigned OverloadIndex = Infos[NextElt++];
444 IITDescriptor::get(IITDescriptor::Subdivide2, OverloadIndex));
447 case IIT_SUBDIVIDE4_ARG: {
448 unsigned OverloadIndex = Infos[NextElt++];
450 IITDescriptor::get(IITDescriptor::Subdivide4, OverloadIndex));
453 case IIT_VEC_ELEMENT: {
454 unsigned OverloadIndex = Infos[NextElt++];
456 IITDescriptor::get(IITDescriptor::VecElement, OverloadIndex));
459 case IIT_VEC_OF_BITCASTS_TO_INT: {
460 unsigned OverloadIndex = Infos[NextElt++];
462 IITDescriptor::get(IITDescriptor::VecOfBitcastsToInt, OverloadIndex));
465 case IIT_SCALABLE_VEC:
471#define GET_INTRINSIC_GENERATOR_GLOBAL
472#include "llvm/IR/IntrinsicImpl.inc"
474std::tuple<ArrayRef<Intrinsic::IITDescriptor>,
unsigned,
bool>
480 constexpr unsigned FixedEncodingBits =
sizeof(FixedEncodingTy) * CHAR_BIT;
481 constexpr unsigned MSBPosition = FixedEncodingBits - 1;
483 constexpr unsigned Mask = (1U << MSBPosition) - 1;
485 FixedEncodingTy TableVal = IIT_Table[
id - 1];
495 unsigned char IITValues[FixedEncodingBits / 4 + 1] = {0};
498 unsigned NextElt = 0;
501 if (TableVal >> MSBPosition) {
503 IITEntries = IIT_LongEncodingTable;
506 NextElt = TableVal & Mask;
511 IITValues[NextElt++] = TableVal & 0xF;
515 IITEntries = IITValues;
521 unsigned NumArgs = 0;
522 while (IITEntries[NextElt] != IIT_Done) {
529 bool IsVarArg =
false;
535 return {
TableRef, NumArgs, IsVarArg};
546 case IITDescriptor::Void:
548 case IITDescriptor::MMX:
550 case IITDescriptor::AMX:
552 case IITDescriptor::Token:
554 case IITDescriptor::Metadata:
556 case IITDescriptor::Half:
558 case IITDescriptor::BFloat:
560 case IITDescriptor::Float:
562 case IITDescriptor::Double:
564 case IITDescriptor::Quad:
566 case IITDescriptor::PPCQuad:
568 case IITDescriptor::AArch64Svcount:
570 case IITDescriptor::WasmExternref:
572 case IITDescriptor::WasmFuncref:
574 case IITDescriptor::Integer:
576 case IITDescriptor::Vector:
579 case IITDescriptor::Pointer:
581 case IITDescriptor::Struct: {
583 for (
unsigned i = 0, e =
D.StructNumElements; i != e; ++i)
590 case IITDescriptor::Overloaded:
591 case IITDescriptor::VecOfAnyPtrsToElt:
592 case IITDescriptor::Match:
593 return OverloadTys[
D.getOverloadIndex()];
594 case IITDescriptor::Extend:
595 return OverloadTys[
D.getOverloadIndex()]->getExtendedType();
596 case IITDescriptor::Trunc:
597 return OverloadTys[
D.getOverloadIndex()]->getTruncatedType();
598 case IITDescriptor::Subdivide2:
599 case IITDescriptor::Subdivide4: {
600 Type *Ty = OverloadTys[
D.getOverloadIndex()];
602 assert(VTy &&
"Expected overload type to be a Vector Type");
603 int SubDivs =
D.Kind == IITDescriptor::Subdivide2 ? 1 : 2;
606 case IITDescriptor::OneNthEltsVec:
609 D.getVectorDivisor());
610 case IITDescriptor::SameVecWidth: {
612 Type *Ty = OverloadTys[
D.getOverloadIndex()];
617 case IITDescriptor::VecElement: {
618 Type *Ty = OverloadTys[
D.getOverloadIndex()];
620 return VTy->getElementType();
623 case IITDescriptor::VecOfBitcastsToInt: {
624 Type *Ty = OverloadTys[
D.getOverloadIndex()];
626 assert(VTy &&
"Expected overload type to be a Vector Type");
629 case IITDescriptor::VarArg:
651#define GET_INTRINSIC_OVERLOAD_TABLE
652#include "llvm/IR/IntrinsicImpl.inc"
656#define GET_INTRINSIC_SCALARIZABLE_TABLE
657#include "llvm/IR/IntrinsicImpl.inc"
661#define GET_INTRINSIC_PRETTY_PRINT_TABLE
662#include "llvm/IR/IntrinsicImpl.inc"
666#define GET_INTRINSIC_TARGET_DATA
667#include "llvm/IR/IntrinsicImpl.inc"
670 return IID > TargetInfos[0].Count;
679 assert(Name.starts_with(
"llvm.") &&
"Unexpected intrinsic prefix");
680 assert(Name.drop_front(5).starts_with(
Target) &&
"Unexpected target");
691 CmpEnd += 1 +
Target.size();
693 const unsigned *
Low = NameOffsetTable.
begin();
694 const unsigned *
High = NameOffsetTable.
end();
695 const unsigned *LastLow =
Low;
696 while (CmpEnd < Name.size() &&
High -
Low > 0) {
697 size_t CmpStart = CmpEnd;
698 CmpEnd = Name.find(
'.', CmpStart + 1);
700 auto Cmp = [CmpStart, CmpEnd](
auto LHS,
auto RHS) {
705 if constexpr (std::is_integral_v<
decltype(
LHS)>)
706 LHSStr = IntrinsicNameTable.getCString(
LHS);
711 if constexpr (std::is_integral_v<
decltype(
RHS)>)
712 RHSStr = IntrinsicNameTable.getCString(
RHS);
716 return strncmp(LHSStr + CmpStart, RHSStr + CmpStart, CmpEnd - CmpStart) <
720 std::tie(
Low,
High) = std::equal_range(
Low,
High, Name.data(), Cmp);
725 if (LastLow == NameOffsetTable.
end())
727 StringRef NameFound = IntrinsicNameTable[*LastLow];
728 if (Name == NameFound ||
729 (Name.starts_with(NameFound) && Name[NameFound.
size()] ==
'.'))
730 return LastLow - NameOffsetTable.
begin();
739static std::pair<ArrayRef<unsigned>,
StringRef>
741 assert(Name.starts_with(
"llvm."));
748 Targets, [=](
const IntrinsicTargetInfo &TI) {
return TI.Name <
Target; });
751 const auto &TI = It != Targets.
end() && It->Name ==
Target ? *It : Targets[0];
752 return {
ArrayRef(&IntrinsicNameOffsetTable[1] + TI.Offset, TI.Count),
766 int Adjust = NameOffsetTable.data() - IntrinsicNameOffsetTable;
771 const auto MatchSize = IntrinsicNameTable[NameOffsetTable[Idx]].size();
772 assert(Name.size() >= MatchSize &&
"Expected either exact or prefix match");
773 bool IsExactMatch = Name.size() == MatchSize;
779#define GET_INTRINSIC_ATTRIBUTES
780#include "llvm/IR/IntrinsicImpl.inc"
786 std::string Name = OverloadTys.
empty()
790 if (
F->getFunctionType() == FT)
798 F->setName(
F->getName() +
".invalid");
799 return cast<Function>(M->getOrInsertFunction(Name, FT).getCallee());
825 assert(IsValid &&
"intrinsic signature mismatch");
840#define GET_LLVM_INTRINSIC_FOR_CLANG_BUILTIN
841#include "llvm/IR/IntrinsicImpl.inc"
844#define GET_LLVM_INTRINSIC_FOR_MS_BUILTIN
845#include "llvm/IR/IntrinsicImpl.inc"
849#define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC) \
850 case Intrinsic::INTRINSIC:
851#include "llvm/IR/ConstrainedOps.def"
861#define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC) \
862 case Intrinsic::INTRINSIC: \
863 return ROUND_MODE == 1;
864#include "llvm/IR/ConstrainedOps.def"
888struct MatchPosition {
898 static constexpr unsigned INDEX_TABLE_SIZE = 2;
899 Index Indices[INDEX_TABLE_SIZE];
903 assert(NumIndices > 0 &&
"cannot pop from empty indices");
907 void push_struct_element(
unsigned ElementNum) {
908 assert(NumIndices < INDEX_TABLE_SIZE &&
"index table overflow");
910 Indices[NumIndices].IsStruct =
true;
911 Indices[NumIndices++].Num = ElementNum;
914 void push_vector_element() {
915 assert(NumIndices < INDEX_TABLE_SIZE &&
"index table overflow");
916 Indices[NumIndices].IsStruct =
false;
917 Indices[NumIndices++].Num = 0;
928 OS <<
"argument " << Pos.Num;
930 for (
const MatchPosition::Index &Idx :
931 ArrayRef(Pos.Indices).take_front(Pos.NumIndices)) {
933 OS <<
" struct element " << Idx.Num;
935 OS <<
" vector element";
941 std::tuple<Type *, ArrayRef<Intrinsic::IITDescriptor>, MatchPosition>;
952 OS << Position <<
" too many "
953 << (Position.IsRet ?
"returns" :
"arguments");
958 auto InfosRef = Infos;
959 auto DeferCheck = [&DeferredChecks, &InfosRef, &Position](
Type *
T) {
968 auto PrintMsg = [&OS, &Position,
970 std::optional<unsigned> OIdx = std::nullopt) ->
bool {
973 OS << Position <<
" type";
975 OS <<
" (overload type " << *OIdx <<
")";
976 OS <<
" expected " <<
Expected <<
", but got " << *Ty;
983 auto PrintMsgInvalidOverloadTy =
984 [&OS, &Position, &OverloadTys](
const Twine &DependentQualifier,
986 unsigned OIdx) ->
bool {
987 OS << Position <<
" is " << DependentQualifier <<
" overload type " << OIdx
988 <<
", so overload type " << OIdx <<
" expected " <<
Expected
989 <<
", but got " << *OverloadTys[OIdx];
994 auto PrintMsgInvalidDepType =
995 [&OS, &Position, &OverloadTys,
997 unsigned OIdx) ->
bool {
1000 bool IsMatching = DependentQualifier.isSingleStringRef() &&
1001 DependentQualifier.getSingleStringRef() ==
"matching";
1002 OS << Position <<
" type (" << DependentQualifier <<
" overload type "
1003 << OIdx <<
") expected " <<
Expected;
1005 OS <<
" (overload type " << OIdx <<
" is " << *OverloadTys[OIdx] <<
")";
1006 OS <<
", but got " << *Ty;
1011 case IITDescriptor::Void:
1012 assert(Position.IsRet && Position.NumIndices == 0 &&
1013 "void descriptor expected only for return type");
1014 return PrintMsg(Ty->isVoidTy(),
"void");
1015 case IITDescriptor::MMX: {
1019 "x86_mmx (<1 x i64>)");
1021 case IITDescriptor::AMX:
1022 return PrintMsg(Ty->isX86_AMXTy(),
"x86_amx");
1023 case IITDescriptor::Token:
1024 return PrintMsg(Ty->isTokenTy(),
"token");
1025 case IITDescriptor::Metadata:
1026 return PrintMsg(Ty->isMetadataTy(),
"metadata");
1027 case IITDescriptor::Half:
1028 return PrintMsg(Ty->isHalfTy(),
"half");
1029 case IITDescriptor::BFloat:
1030 return PrintMsg(Ty->isBFloatTy(),
"bfloat");
1031 case IITDescriptor::Float:
1032 return PrintMsg(Ty->isFloatTy(),
"float");
1033 case IITDescriptor::Double:
1034 return PrintMsg(Ty->isDoubleTy(),
"double");
1035 case IITDescriptor::Quad:
1036 return PrintMsg(Ty->isFP128Ty(),
"fp128");
1037 case IITDescriptor::PPCQuad:
1038 return PrintMsg(Ty->isPPC_FP128Ty(),
"ppc_fp128");
1039 case IITDescriptor::Integer:
1040 return PrintMsg(Ty->isIntegerTy(
D.IntegerWidth),
1041 "i" +
Twine(
D.IntegerWidth));
1042 case IITDescriptor::AArch64Svcount:
1046 case IITDescriptor::WasmExternref:
1050 case IITDescriptor::WasmFuncref:
1054 case IITDescriptor::Vector: {
1056 StringRef Scalable =
D.VectorWidth.isScalable() ?
"vscale " :
"";
1058 PrintMsg(VT && VT->getElementCount() ==
D.VectorWidth,
1059 Twine(Scalable) +
"vector with " +
1060 Twine(
D.VectorWidth.getKnownMinValue()) +
" elements");
1063 Position.push_vector_element();
1065 OverloadTys, DeferredChecks, IsDeferredCheck, OS);
1067 case IITDescriptor::Pointer: {
1069 unsigned AS =
D.PointerAddressSpace;
1070 bool IsValid = PT && PT->getAddressSpace() == AS;
1072 return PrintMsg(IsValid,
"ptr");
1073 return PrintMsg(IsValid,
"ptr addrspace(" +
Twine(AS) +
")");
1076 case IITDescriptor::Struct: {
1078 unsigned EC =
D.StructNumElements;
1079 bool HasError = PrintMsg(
1080 ST && ST->isLiteral() && !ST->isPacked() && ST->getNumElements() == EC,
1081 "literal non-packed struct with " +
Twine(EC) +
" elements");
1086 Position.push_struct_element(Idx);
1088 IsDeferredCheck, OS))
1090 Position.pop_index();
1095 case IITDescriptor::Overloaded: {
1096 unsigned OIdx =
D.getOverloadIndex();
1097 assert(OIdx == OverloadTys.
size() && !IsDeferredCheck &&
1098 "Table consistency error");
1101 IITDescriptor::AnyKindVectorConstraint VC;
1102 IITDescriptor::AnyKindElementConstraint EC;
1103 std::tie(VC, EC) =
D.getOverloadConstraints();
1105 bool IsValid = [&]() {
1107 case IITDescriptor::VC_None:
1109 case IITDescriptor::VC_Vector:
1111 case IITDescriptor::VC_Scalar:
1120 case IITDescriptor::EC_None:
1122 case IITDescriptor::EC_Integer:
1124 case IITDescriptor::EC_Float:
1126 case IITDescriptor::EC_Pointer:
1147 if (EC == IITDescriptor::EC_None) {
1151 return PrintMsg(
false,
formatv(
"any {} type", VK), OIdx);
1156 case IITDescriptor::VC_None:
1158 return PrintMsg(
false,
formatv(
"any {0} or {0} vector", EK), OIdx);
1159 case IITDescriptor::VC_Vector:
1160 return PrintMsg(
false,
formatv(
"any {} vector", EK), OIdx);
1161 case IITDescriptor::VC_Scalar:
1162 return PrintMsg(
false,
formatv(
"any {} type", EK), OIdx);
1167 case IITDescriptor::Match: {
1168 unsigned OIdx =
D.getOverloadIndex();
1169 if (OIdx >= OverloadTys.
size())
1170 return IsDeferredCheck || DeferCheck(Ty);
1171 return PrintMsgInvalidDepType(Ty == OverloadTys[OIdx],
"matching",
1172 formatv(
"{}", *OverloadTys[OIdx]), OIdx);
1175 case IITDescriptor::Extend:
1176 case IITDescriptor::Trunc: {
1177 unsigned OIdx =
D.getOverloadIndex();
1179 if (OIdx >= OverloadTys.
size())
1180 return IsDeferredCheck || DeferCheck(Ty);
1182 Type *OTy = OverloadTys[OIdx];
1183 bool IsExtend =
D.Kind == IITDescriptor::Extend;
1184 StringRef Qualifier = IsExtend ?
"extended" :
"truncated";
1186 return PrintMsgInvalidOverloadTy(Qualifier,
"int or vector of int", OIdx);
1189 return PrintMsgInvalidDepType(Ty == NewTy, Qualifier,
formatv(
"{}", *NewTy),
1192 case IITDescriptor::OneNthEltsVec: {
1193 unsigned OIdx =
D.getOverloadIndex();
1194 unsigned Divisor =
D.getVectorDivisor();
1196 if (OIdx >= OverloadTys.
size())
1197 return IsDeferredCheck || DeferCheck(Ty);
1198 Type *OTy = OverloadTys[OIdx];
1200 auto Qualifier =
formatv(
"1/nth (n={}) elements vector of", Divisor);
1202 return PrintMsgInvalidOverloadTy(Qualifier,
"vector", OIdx);
1203 if (!OVecTy->getElementCount().isKnownMultipleOf(Divisor))
1204 return PrintMsgInvalidOverloadTy(
1205 Qualifier,
formatv(
"vector with multiple of {} elements", Divisor),
1208 return PrintMsgInvalidDepType(
Expected == Ty, Qualifier,
1211 case IITDescriptor::SameVecWidth: {
1212 unsigned OIdx =
D.getOverloadIndex();
1213 if (OIdx >= OverloadTys.
size()) {
1216 return IsDeferredCheck || DeferCheck(Ty);
1221 StringRef Qualifier =
"same vector width of";
1222 if (OVecTy && !ThisArgVecType)
1223 return PrintMsgInvalidDepType(
false, Qualifier,
"vector", OIdx);
1224 if (!OVecTy && ThisArgVecType)
1225 return PrintMsgInvalidDepType(
false, Qualifier,
"scalar", OIdx);
1227 if (ThisArgVecType) {
1229 if (
Expected != ThisArgVecType->getElementCount())
1230 return PrintMsgInvalidDepType(
1233 EltTy = ThisArgVecType->getElementType();
1234 Position.push_vector_element();
1237 DeferredChecks, IsDeferredCheck, OS);
1239 case IITDescriptor::VecOfAnyPtrsToElt: {
1240 unsigned RefOverloadIndex =
D.getRefOverloadIndex();
1241 if (RefOverloadIndex >= OverloadTys.
size()) {
1242 if (IsDeferredCheck)
1246 assert(
D.getOverloadIndex() == OverloadTys.
size() &&
1247 "Table consistency error");
1249 return DeferCheck(Ty);
1252 if (!IsDeferredCheck) {
1253 assert(
D.getOverloadIndex() == OverloadTys.
size() &&
1254 "Table consistency error");
1261 StringRef Qualifier =
"vector of pointers to elements of";
1264 return PrintMsgInvalidOverloadTy(Qualifier,
"vector", RefOverloadIndex);
1268 return PrintMsgInvalidDepType(
false, Qualifier,
"vector",
1273 formatv(
"vector of pointers with {} elements", ExpectedCount);
1274 bool IsValid = ThisArgVecTy->getElementCount() == ExpectedCount &&
1275 ThisArgVecTy->getElementType()->isPointerTy();
1276 return PrintMsgInvalidDepType(IsValid, Qualifier,
Expected,
1279 case IITDescriptor::VecElement: {
1280 unsigned OIdx =
D.getOverloadIndex();
1281 if (OIdx >= OverloadTys.
size())
1282 return IsDeferredCheck || DeferCheck(Ty);
1283 StringRef Qualifier =
"vector element of";
1286 return PrintMsgInvalidOverloadTy(Qualifier,
"vector", OIdx);
1288 return PrintMsgInvalidDepType(
Expected == Ty, Qualifier,
1291 case IITDescriptor::Subdivide2:
1292 case IITDescriptor::Subdivide4: {
1293 unsigned OIdx =
D.getOverloadIndex();
1295 if (OIdx >= OverloadTys.
size())
1296 return IsDeferredCheck || DeferCheck(Ty);
1298 int SubDivs =
D.Kind == IITDescriptor::Subdivide2 ? 1 : 2;
1301 formatv(
"subdivided by {} vector of", SubDivs == 1 ? 2 : 4);
1303 return PrintMsgInvalidOverloadTy(Qualifier,
"vector", OIdx);
1308 return PrintMsgInvalidDepType(
Expected == Ty, Qualifier,
1311 case IITDescriptor::VecOfBitcastsToInt: {
1312 unsigned OIdx =
D.getOverloadIndex();
1313 if (OIdx >= OverloadTys.
size())
1314 return IsDeferredCheck || DeferCheck(Ty);
1316 StringRef Qualifier =
"vector of bitcasts to int of";
1318 return PrintMsgInvalidOverloadTy(Qualifier,
"vector", OIdx);
1320 return PrintMsgInvalidDepType(
Expected == Ty, Qualifier,
1323 case IITDescriptor::VarArg:
1340 unsigned NumArgs,
bool IsVarArg,
1345 assert(!Infos.
empty() &&
"Table consistency error");
1352 DeferredChecks,
false, OS))
1355 if (FTy->getNumParams() != NumArgs) {
1356 OS <<
"intrinsic has incorrect number of args. Expected " << NumArgs
1357 <<
", but got " << FTy->getNumParams();
1369 for (
unsigned I = 0,
E = DeferredChecks.
size();
I !=
E; ++
I) {
1370 auto &[DefTy, DefInfos, DefPosition] = DeferredChecks[
I];
1372 DeferredChecks,
true, OS))
1376 if (!Infos.
empty()) {
1377 OS <<
"intrinsic has too few arguments!";
1381 if (FTy->isVarArg() != IsVarArg) {
1383 OS <<
"intrinsic was not defined with variable arguments!";
1385 OS <<
"intrinsic was defined with variable arguments!";
1408 return ::isSignatureValid(FT,
TableRef, NumArgs, IsVarArg, OverloadTys, OS);
1421 return std::nullopt;
1425 std::string WantedName =
1427 if (Name == WantedName)
1428 return std::nullopt;
1431 if (
auto *ExistingGV =
F->getParent()->getNamedValue(WantedName)) {
1433 if (ExistingF->getFunctionType() ==
F->getFunctionType())
1440 ExistingGV->setName(WantedName +
".renamed");
1447 "Shouldn't change the signature");
1456 {Intrinsic::vector_interleave2, Intrinsic::vector_deinterleave2},
1457 {Intrinsic::vector_interleave3, Intrinsic::vector_deinterleave3},
1458 {Intrinsic::vector_interleave4, Intrinsic::vector_deinterleave4},
1459 {Intrinsic::vector_interleave5, Intrinsic::vector_deinterleave5},
1460 {Intrinsic::vector_interleave6, Intrinsic::vector_deinterleave6},
1461 {Intrinsic::vector_interleave7, Intrinsic::vector_deinterleave7},
1462 {Intrinsic::vector_interleave8, Intrinsic::vector_deinterleave8},
1466 assert(Factor >= 2 && Factor <= 8 &&
"Unexpected factor");
1471 assert(Factor >= 2 && Factor <= 8 &&
"Unexpected factor");
1475#define GET_INTRINSIC_PRETTY_PRINT_ARGUMENTS
1476#include "llvm/IR/IntrinsicImpl.inc"
1480#define GET_INTRINSIC_DEFAULT_ARG_VALUES
1481#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 StringRef getRequiredTargetFeatures(ID id)
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