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/IntrinsicsPowerPC.h"
26#include "llvm/IR/IntrinsicsR600.h"
27#include "llvm/IR/IntrinsicsRISCV.h"
28#include "llvm/IR/IntrinsicsS390.h"
29#include "llvm/IR/IntrinsicsSPIRV.h"
30#include "llvm/IR/IntrinsicsVE.h"
31#include "llvm/IR/IntrinsicsX86.h"
32#include "llvm/IR/IntrinsicsXCore.h"
44 unsigned NumArgs,
bool IsVarArg,
47 unsigned NumMissingTrailingParams = 0);
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 {
892 uint16_t IsStruct : 1;
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");
1104 if (Ty->isTokenTy())
1105 return PrintMsg(
false,
"any manglable type", OIdx);
1107 IITDescriptor::AnyKindVectorConstraint VC;
1108 IITDescriptor::AnyKindElementConstraint EC;
1109 std::tie(VC, EC) =
D.getOverloadConstraints();
1111 bool IsValid = [&]() {
1113 case IITDescriptor::VC_None:
1115 case IITDescriptor::VC_Vector:
1117 case IITDescriptor::VC_Scalar:
1126 case IITDescriptor::EC_None:
1128 case IITDescriptor::EC_Integer:
1130 case IITDescriptor::EC_Float:
1132 case IITDescriptor::EC_Pointer:
1153 if (EC == IITDescriptor::EC_None) {
1157 return PrintMsg(
false,
formatv(
"any {} type", VK), OIdx);
1162 case IITDescriptor::VC_None:
1164 return PrintMsg(
false,
formatv(
"any {0} or {0} vector", EK), OIdx);
1165 case IITDescriptor::VC_Vector:
1166 return PrintMsg(
false,
formatv(
"any {} vector", EK), OIdx);
1167 case IITDescriptor::VC_Scalar:
1168 return PrintMsg(
false,
formatv(
"any {} type", EK), OIdx);
1173 case IITDescriptor::Match: {
1174 unsigned OIdx =
D.getOverloadIndex();
1175 if (OIdx >= OverloadTys.
size())
1176 return IsDeferredCheck || DeferCheck(Ty);
1177 return PrintMsgInvalidDepType(Ty == OverloadTys[OIdx],
"matching",
1178 formatv(
"{}", *OverloadTys[OIdx]), OIdx);
1181 case IITDescriptor::Extend:
1182 case IITDescriptor::Trunc: {
1183 unsigned OIdx =
D.getOverloadIndex();
1185 if (OIdx >= OverloadTys.
size())
1186 return IsDeferredCheck || DeferCheck(Ty);
1188 Type *OTy = OverloadTys[OIdx];
1189 bool IsExtend =
D.Kind == IITDescriptor::Extend;
1190 StringRef Qualifier = IsExtend ?
"extended" :
"truncated";
1192 return PrintMsgInvalidOverloadTy(Qualifier,
"int or vector of int", OIdx);
1195 return PrintMsgInvalidDepType(Ty == NewTy, Qualifier,
formatv(
"{}", *NewTy),
1198 case IITDescriptor::OneNthEltsVec: {
1199 unsigned OIdx =
D.getOverloadIndex();
1200 unsigned Divisor =
D.getVectorDivisor();
1202 if (OIdx >= OverloadTys.
size())
1203 return IsDeferredCheck || DeferCheck(Ty);
1204 Type *OTy = OverloadTys[OIdx];
1206 auto Qualifier =
formatv(
"1/nth (n={}) elements vector of", Divisor);
1208 return PrintMsgInvalidOverloadTy(Qualifier,
"vector", OIdx);
1209 if (!OVecTy->getElementCount().isKnownMultipleOf(Divisor))
1210 return PrintMsgInvalidOverloadTy(
1211 Qualifier,
formatv(
"vector with multiple of {} elements", Divisor),
1214 return PrintMsgInvalidDepType(
Expected == Ty, Qualifier,
1217 case IITDescriptor::SameVecWidth: {
1218 unsigned OIdx =
D.getOverloadIndex();
1219 if (OIdx >= OverloadTys.
size()) {
1222 return IsDeferredCheck || DeferCheck(Ty);
1227 StringRef Qualifier =
"same vector width of";
1228 if (OVecTy && !ThisArgVecType)
1229 return PrintMsgInvalidDepType(
false, Qualifier,
"vector", OIdx);
1230 if (!OVecTy && ThisArgVecType)
1231 return PrintMsgInvalidDepType(
false, Qualifier,
"scalar", OIdx);
1233 if (ThisArgVecType) {
1235 if (
Expected != ThisArgVecType->getElementCount())
1236 return PrintMsgInvalidDepType(
1239 EltTy = ThisArgVecType->getElementType();
1240 Position.push_vector_element();
1243 DeferredChecks, IsDeferredCheck, OS);
1245 case IITDescriptor::VecOfAnyPtrsToElt: {
1246 unsigned RefOverloadIndex =
D.getRefOverloadIndex();
1247 if (RefOverloadIndex >= OverloadTys.
size()) {
1248 if (IsDeferredCheck)
1252 assert(
D.getOverloadIndex() == OverloadTys.
size() &&
1253 "Table consistency error");
1255 return DeferCheck(Ty);
1258 if (!IsDeferredCheck) {
1259 assert(
D.getOverloadIndex() == OverloadTys.
size() &&
1260 "Table consistency error");
1267 StringRef Qualifier =
"vector of pointers to elements of";
1270 return PrintMsgInvalidOverloadTy(Qualifier,
"vector", RefOverloadIndex);
1274 return PrintMsgInvalidDepType(
false, Qualifier,
"vector",
1279 formatv(
"vector of pointers with {} elements", ExpectedCount);
1280 bool IsValid = ThisArgVecTy->getElementCount() == ExpectedCount &&
1281 ThisArgVecTy->getElementType()->isPointerTy();
1282 return PrintMsgInvalidDepType(IsValid, Qualifier,
Expected,
1285 case IITDescriptor::VecElement: {
1286 unsigned OIdx =
D.getOverloadIndex();
1287 if (OIdx >= OverloadTys.
size())
1288 return IsDeferredCheck || DeferCheck(Ty);
1289 StringRef Qualifier =
"vector element of";
1292 return PrintMsgInvalidOverloadTy(Qualifier,
"vector", OIdx);
1294 return PrintMsgInvalidDepType(
Expected == Ty, Qualifier,
1297 case IITDescriptor::Subdivide2:
1298 case IITDescriptor::Subdivide4: {
1299 unsigned OIdx =
D.getOverloadIndex();
1301 if (OIdx >= OverloadTys.
size())
1302 return IsDeferredCheck || DeferCheck(Ty);
1304 int SubDivs =
D.Kind == IITDescriptor::Subdivide2 ? 1 : 2;
1307 formatv(
"subdivided by {} vector of", SubDivs == 1 ? 2 : 4);
1309 return PrintMsgInvalidOverloadTy(Qualifier,
"vector", OIdx);
1314 return PrintMsgInvalidDepType(
Expected == Ty, Qualifier,
1317 case IITDescriptor::VecOfBitcastsToInt: {
1318 unsigned OIdx =
D.getOverloadIndex();
1319 if (OIdx >= OverloadTys.
size())
1320 return IsDeferredCheck || DeferCheck(Ty);
1322 StringRef Qualifier =
"vector of bitcasts to int of";
1324 return PrintMsgInvalidOverloadTy(Qualifier,
"vector", OIdx);
1326 return PrintMsgInvalidDepType(
Expected == Ty, Qualifier,
1329 case IITDescriptor::VarArg:
1350 unsigned NumArgs,
bool IsVarArg,
1353 unsigned NumMissingTrailingParams) {
1356 assert(!Infos.
empty() &&
"Table consistency error");
1363 DeferredChecks,
false, OS))
1366 unsigned ProvidedArgs = FTy->getNumParams();
1367 if (ProvidedArgs + NumMissingTrailingParams != NumArgs) {
1368 OS <<
"intrinsic has incorrect number of args. Expected " << NumArgs
1369 <<
", but got " << ProvidedArgs;
1381 for (
unsigned I = 0,
E = DeferredChecks.
size();
I !=
E; ++
I) {
1382 auto &[DefTy, DefInfos, DefPosition] = DeferredChecks[
I];
1384 DeferredChecks,
true, OS))
1390 if (NumMissingTrailingParams != 0 &&
1391 (Infos.
size() != NumMissingTrailingParams ||
1393 return D.Kind != Intrinsic::IITDescriptor::Integer;
1395 OS <<
"cannot omit trailing parameters that are overloaded or non-integer";
1398 Infos = Infos.
drop_front(NumMissingTrailingParams);
1400 if (!Infos.
empty()) {
1401 OS <<
"intrinsic has too few arguments!";
1405 if (FTy->isVarArg() != IsVarArg) {
1407 OS <<
"intrinsic was not defined with variable arguments!";
1409 OS <<
"intrinsic was defined with variable arguments!";
1432 unsigned NumMissingTrailingParams,
1440 return ::isSignatureValid(FT,
TableRef, NumArgs, IsVarArg, OverloadTys, OS,
1441 NumMissingTrailingParams);
1454 return std::nullopt;
1458 std::string WantedName =
1460 if (Name == WantedName)
1461 return std::nullopt;
1464 if (
auto *ExistingGV =
F->getParent()->getNamedValue(WantedName)) {
1466 if (ExistingF->getFunctionType() ==
F->getFunctionType())
1473 ExistingGV->setName(WantedName +
".renamed");
1480 "Shouldn't change the signature");
1489 {Intrinsic::vector_interleave2, Intrinsic::vector_deinterleave2},
1490 {Intrinsic::vector_interleave3, Intrinsic::vector_deinterleave3},
1491 {Intrinsic::vector_interleave4, Intrinsic::vector_deinterleave4},
1492 {Intrinsic::vector_interleave5, Intrinsic::vector_deinterleave5},
1493 {Intrinsic::vector_interleave6, Intrinsic::vector_deinterleave6},
1494 {Intrinsic::vector_interleave7, Intrinsic::vector_deinterleave7},
1495 {Intrinsic::vector_interleave8, Intrinsic::vector_deinterleave8},
1499 assert(Factor >= 2 && Factor <= 8 &&
"Unexpected factor");
1504 assert(Factor >= 2 && Factor <= 8 &&
"Unexpected factor");
1511 OS << static_cast<FPClassTest>(Val);
1514#define GET_INTRINSIC_IMMARG_RANGE_SET_CHECKS
1515#include "llvm/IR/IntrinsicImpl.inc"
1517#define GET_INTRINSIC_PRETTY_PRINT_ARGUMENTS
1518#include "llvm/IR/IntrinsicImpl.inc"
1522#define GET_INTRINSIC_DEFAULT_ARG_VALUES
1523#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 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...
static bool isSignatureValid(FunctionType *FTy, ArrayRef< Intrinsic::IITDescriptor > &Infos, unsigned NumArgs, bool IsVarArg, SmallVectorImpl< Type * > &OverloadTys, raw_ostream &OS, unsigned NumMissingTrailingParams=0)
Return true if the function type FTy is a valid type signature for the type constraints specified in ...
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),...
ArrayRef< T > drop_front(size_t N=1) const
Drop the first N elements of the array.
size_t size() const
Get the array size.
bool empty() const
Check if the array is empty.
const T & consume_front()
consume_front() - Returns the first element and drops it from ArrayRef.
This is an important base class in LLVM.
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(LLVMContext &C, unsigned AddressSpace)
This constructs an opaque pointer to an object 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.
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 void printFPClassMask(raw_ostream &OS, const Constant *ImmArgVal)
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
This is a type descriptor which explains the type requirements of an intrinsic.