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/IntrinsicsPISA.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"
46 unsigned NumArgs,
bool IsVarArg,
49 unsigned NumMissingTrailingParams = 0);
52#define GET_INTRINSIC_NAME_TABLE
53#include "llvm/IR/IntrinsicImpl.inc"
56#define GET_INTRINSIC_TARGET_FEATURES_TABLE
57#include "llvm/IR/IntrinsicImpl.inc"
60 assert(
id < num_intrinsics &&
"Invalid intrinsic ID!");
61 return IntrinsicNameTable[IntrinsicNameOffsetTable[id]];
65 assert(
id < num_intrinsics &&
"invalid intrinsic ID!");
66 return IntrinsicTargetFeaturesTable[IntrinsicTargetFeaturesOffsetTable[id]];
70 assert(
id < num_intrinsics &&
"Invalid intrinsic ID!");
72 "This version of getName does not support overloading");
91 Result +=
"p" +
utostr(PTyp->getAddressSpace());
93 Result +=
"a" +
utostr(ATyp->getNumElements()) +
96 if (!STyp->isLiteral()) {
99 Result += STyp->getName();
101 HasUnnamedType =
true;
104 for (
auto *Elem : STyp->elements())
111 for (
size_t i = 0; i < FT->getNumParams(); i++)
121 Result +=
"v" +
utostr(EC.getKnownMinValue()) +
125 Result += TETy->getName();
126 for (
Type *ParamTy : TETy->type_params())
128 for (
unsigned IntParam : TETy->int_params())
129 Result +=
"_" +
utostr(IntParam);
133 switch (Ty->getTypeID()) {
140 Result +=
"Metadata";
180 bool EarlyModuleCheck) {
182 assert(Id < Intrinsic::num_intrinsics &&
"Invalid intrinsic ID!");
184 "This version of getName is for overloaded intrinsics only");
185 (void)EarlyModuleCheck;
186 assert((!EarlyModuleCheck || M ||
188 "Intrinsic overloading on pointer types need to provide a Module");
189 bool HasUnnamedType =
false;
191 for (
Type *Ty : OverloadTys)
193 if (HasUnnamedType) {
194 assert(M &&
"unnamed types need a module");
199 "Provided FunctionType must match arguments");
200 return M->getUniqueIntrinsicName(Result, Id, FT);
207 assert(M &&
"We need to have a Module");
221#define GET_INTRINSIC_IITINFO
222#include "llvm/IR/IntrinsicImpl.inc"
225static_assert(IIT_Done == 0,
"IIT_Done expected to be 0");
232 auto IsScalableVector = [&]() {
234 if (NextInfo != IIT_SCALABLE_VEC)
245 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::Void, 0));
248 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::VarArg, 0));
251 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::MMX, 0));
254 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::AMX, 0));
257 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::Token, 0));
260 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::Metadata, 0));
263 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::Half, 0));
266 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::BFloat, 0));
269 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::Float, 0));
272 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::Double, 0));
275 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::Quad, 0));
278 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::PPCQuad, 0));
281 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::Integer, 1));
284 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::Integer, 2));
287 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::Integer, 4));
289 case IIT_AARCH64_SVCOUNT:
290 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::AArch64Svcount, 0));
293 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::Integer, 8));
296 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::Integer, 16));
299 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::Integer, 32));
302 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::Integer, 64));
305 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::Integer, 128));
308 OutputTable.
push_back(IITDescriptor::getVector(1, IsScalableVector()));
312 OutputTable.
push_back(IITDescriptor::getVector(2, IsScalableVector()));
316 OutputTable.
push_back(IITDescriptor::getVector(3, IsScalableVector()));
320 OutputTable.
push_back(IITDescriptor::getVector(4, IsScalableVector()));
324 OutputTable.
push_back(IITDescriptor::getVector(6, IsScalableVector()));
328 OutputTable.
push_back(IITDescriptor::getVector(8, IsScalableVector()));
332 OutputTable.
push_back(IITDescriptor::getVector(10, IsScalableVector()));
336 OutputTable.
push_back(IITDescriptor::getVector(16, IsScalableVector()));
340 OutputTable.
push_back(IITDescriptor::getVector(32, IsScalableVector()));
344 OutputTable.
push_back(IITDescriptor::getVector(64, IsScalableVector()));
348 OutputTable.
push_back(IITDescriptor::getVector(128, IsScalableVector()));
352 OutputTable.
push_back(IITDescriptor::getVector(256, IsScalableVector()));
356 OutputTable.
push_back(IITDescriptor::getVector(512, IsScalableVector()));
360 OutputTable.
push_back(IITDescriptor::getVector(1024, IsScalableVector()));
364 OutputTable.
push_back(IITDescriptor::getVector(2048, IsScalableVector()));
368 OutputTable.
push_back(IITDescriptor::getVector(4096, IsScalableVector()));
372 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::WasmExternref, 0));
375 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::WasmFuncref, 0));
378 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::Pointer, 0));
382 IITDescriptor::get(IITDescriptor::Pointer, Infos[NextElt++]));
385 unsigned OverloadIndex = Infos[NextElt++];
386 unsigned ArgKindEnums = Infos[NextElt++];
387 unsigned Packed = (ArgKindEnums << 8) | OverloadIndex;
389 IITDescriptor::get(IITDescriptor::Overloaded, Packed));
393 unsigned OverloadIndex = Infos[NextElt++];
395 IITDescriptor::get(IITDescriptor::Match, OverloadIndex));
398 case IIT_EXTEND_ARG: {
399 unsigned OverloadIndex = Infos[NextElt++];
401 IITDescriptor::get(IITDescriptor::Extend, OverloadIndex));
404 case IIT_TRUNC_ARG: {
405 unsigned OverloadIndex = Infos[NextElt++];
407 IITDescriptor::get(IITDescriptor::Trunc, OverloadIndex));
410 case IIT_ONE_NTH_ELTS_VEC_ARG: {
411 unsigned short OverloadIndex = Infos[NextElt++];
412 unsigned short N = Infos[NextElt++];
413 OutputTable.
push_back(IITDescriptor::get(IITDescriptor::OneNthEltsVec,
417 case IIT_SAME_VEC_WIDTH_ARG: {
418 unsigned OverloadIndex = Infos[NextElt++];
420 IITDescriptor::get(IITDescriptor::SameVecWidth, OverloadIndex));
425 case IIT_ANY_SAME_VEC_WIDTH_ARG: {
426 unsigned short OverloadIndex = Infos[NextElt++];
427 unsigned short RefOverloadIndex = Infos[NextElt++];
428 unsigned short ElementConstraint = Infos[NextElt++];
431 OutputTable.
push_back(IITDescriptor::get(
432 IITDescriptor::AnySameVecWidth, RefOverloadIndex,
433 ElementConstraint << 4 | OverloadIndex));
437 unsigned StructElts = Infos[NextElt++] + 2;
440 IITDescriptor::get(IITDescriptor::Struct, StructElts));
442 for (
unsigned i = 0; i != StructElts; ++i)
446 case IIT_SUBDIVIDE2_ARG: {
447 unsigned OverloadIndex = Infos[NextElt++];
449 IITDescriptor::get(IITDescriptor::Subdivide2, OverloadIndex));
452 case IIT_SUBDIVIDE4_ARG: {
453 unsigned OverloadIndex = Infos[NextElt++];
455 IITDescriptor::get(IITDescriptor::Subdivide4, OverloadIndex));
458 case IIT_VEC_ELEMENT: {
459 unsigned OverloadIndex = Infos[NextElt++];
461 IITDescriptor::get(IITDescriptor::VecElement, OverloadIndex));
464 case IIT_VEC_OF_BITCASTS_TO_INT: {
465 unsigned OverloadIndex = Infos[NextElt++];
467 IITDescriptor::get(IITDescriptor::VecOfBitcastsToInt, OverloadIndex));
470 case IIT_SCALABLE_VEC:
476#define GET_INTRINSIC_GENERATOR_GLOBAL
477#include "llvm/IR/IntrinsicImpl.inc"
479std::tuple<ArrayRef<Intrinsic::IITDescriptor>,
unsigned,
bool>
485 constexpr unsigned FixedEncodingBits =
sizeof(FixedEncodingTy) * CHAR_BIT;
486 constexpr unsigned MSBPosition = FixedEncodingBits - 1;
488 constexpr unsigned Mask = (1U << MSBPosition) - 1;
490 FixedEncodingTy TableVal = IIT_Table[
id - 1];
500 unsigned char IITValues[FixedEncodingBits / 4 + 1] = {0};
503 unsigned NextElt = 0;
506 if (TableVal >> MSBPosition) {
508 IITEntries = IIT_LongEncodingTable;
511 NextElt = TableVal & Mask;
516 IITValues[NextElt++] = TableVal & 0xF;
520 IITEntries = IITValues;
526 unsigned NumArgs = 0;
527 while (IITEntries[NextElt] != IIT_Done) {
534 bool IsVarArg =
false;
540 return {
TableRef, NumArgs, IsVarArg};
551 case IITDescriptor::Void:
553 case IITDescriptor::MMX:
555 case IITDescriptor::AMX:
557 case IITDescriptor::Token:
559 case IITDescriptor::Metadata:
561 case IITDescriptor::Half:
563 case IITDescriptor::BFloat:
565 case IITDescriptor::Float:
567 case IITDescriptor::Double:
569 case IITDescriptor::Quad:
571 case IITDescriptor::PPCQuad:
573 case IITDescriptor::AArch64Svcount:
575 case IITDescriptor::WasmExternref:
577 case IITDescriptor::WasmFuncref:
579 case IITDescriptor::Integer:
581 case IITDescriptor::Vector:
584 case IITDescriptor::Pointer:
586 case IITDescriptor::Struct: {
588 for (
unsigned i = 0, e =
D.StructNumElements; i != e; ++i)
595 case IITDescriptor::Overloaded:
596 case IITDescriptor::AnySameVecWidth:
597 case IITDescriptor::Match:
598 return OverloadTys[
D.getOverloadIndex()];
599 case IITDescriptor::Extend:
600 return OverloadTys[
D.getOverloadIndex()]->getExtendedType();
601 case IITDescriptor::Trunc:
602 return OverloadTys[
D.getOverloadIndex()]->getTruncatedType();
603 case IITDescriptor::Subdivide2:
604 case IITDescriptor::Subdivide4: {
605 Type *Ty = OverloadTys[
D.getOverloadIndex()];
607 assert(VTy &&
"Expected overload type to be a Vector Type");
608 int SubDivs =
D.Kind == IITDescriptor::Subdivide2 ? 1 : 2;
611 case IITDescriptor::OneNthEltsVec:
614 D.getVectorDivisor());
615 case IITDescriptor::SameVecWidth: {
617 Type *Ty = OverloadTys[
D.getOverloadIndex()];
622 case IITDescriptor::VecElement: {
623 Type *Ty = OverloadTys[
D.getOverloadIndex()];
625 return VTy->getElementType();
628 case IITDescriptor::VecOfBitcastsToInt: {
629 Type *Ty = OverloadTys[
D.getOverloadIndex()];
631 assert(VTy &&
"Expected overload type to be a Vector Type");
634 case IITDescriptor::VarArg:
656#define GET_INTRINSIC_OVERLOAD_TABLE
657#include "llvm/IR/IntrinsicImpl.inc"
661#define GET_INTRINSIC_SCALARIZABLE_TABLE
662#include "llvm/IR/IntrinsicImpl.inc"
666#define GET_INTRINSIC_PRETTY_PRINT_TABLE
667#include "llvm/IR/IntrinsicImpl.inc"
671#define GET_INTRINSIC_TARGET_DATA
672#include "llvm/IR/IntrinsicImpl.inc"
675 return IID > TargetInfos[0].Count;
684 assert(Name.starts_with(
"llvm.") &&
"Unexpected intrinsic prefix");
685 assert(Name.drop_front(5).starts_with(
Target) &&
"Unexpected target");
696 CmpEnd += 1 +
Target.size();
698 const unsigned *
Low = NameOffsetTable.
begin();
699 const unsigned *
High = NameOffsetTable.
end();
700 const unsigned *LastLow =
Low;
701 while (CmpEnd < Name.size() &&
High -
Low > 0) {
702 size_t CmpStart = CmpEnd;
703 CmpEnd = Name.find(
'.', CmpStart + 1);
705 auto Cmp = [CmpStart, CmpEnd](
auto LHS,
auto RHS) {
710 if constexpr (std::is_integral_v<
decltype(
LHS)>)
711 LHSStr = IntrinsicNameTable.getCString(
LHS);
716 if constexpr (std::is_integral_v<
decltype(
RHS)>)
717 RHSStr = IntrinsicNameTable.getCString(
RHS);
721 return strncmp(LHSStr + CmpStart, RHSStr + CmpStart, CmpEnd - CmpStart) <
725 std::tie(
Low,
High) = std::equal_range(
Low,
High, Name.data(), Cmp);
730 if (LastLow == NameOffsetTable.
end())
732 StringRef NameFound = IntrinsicNameTable[*LastLow];
733 if (Name == NameFound ||
734 (Name.starts_with(NameFound) && Name[NameFound.
size()] ==
'.'))
735 return LastLow - NameOffsetTable.
begin();
744static std::pair<ArrayRef<unsigned>,
StringRef>
746 assert(Name.starts_with(
"llvm."));
753 Targets, [=](
const IntrinsicTargetInfo &TI) {
return TI.Name <
Target; });
756 const auto &TI = It != Targets.
end() && It->Name ==
Target ? *It : Targets[0];
757 return {
ArrayRef(&IntrinsicNameOffsetTable[1] + TI.Offset, TI.Count),
771 int Adjust = NameOffsetTable.data() - IntrinsicNameOffsetTable;
776 const auto MatchSize = IntrinsicNameTable[NameOffsetTable[Idx]].size();
777 assert(Name.size() >= MatchSize &&
"Expected either exact or prefix match");
778 bool IsExactMatch = Name.size() == MatchSize;
784#define GET_INTRINSIC_ATTRIBUTES
785#include "llvm/IR/IntrinsicImpl.inc"
791 std::string Name = OverloadTys.
empty()
795 if (
F->getFunctionType() == FT)
803 F->setName(
F->getName() +
".invalid");
804 return cast<Function>(M->getOrInsertFunction(Name, FT).getCallee());
830 assert(IsValid &&
"intrinsic signature mismatch");
845#define GET_LLVM_INTRINSIC_FOR_CLANG_BUILTIN
846#include "llvm/IR/IntrinsicImpl.inc"
849#define GET_LLVM_INTRINSIC_FOR_MS_BUILTIN
850#include "llvm/IR/IntrinsicImpl.inc"
854#define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC) \
855 case Intrinsic::INTRINSIC:
856#include "llvm/IR/ConstrainedOps.def"
866#define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC) \
867 case Intrinsic::INTRINSIC: \
868 return ROUND_MODE == 1;
869#include "llvm/IR/ConstrainedOps.def"
893struct MatchPosition {
897 uint16_t IsStruct : 1;
903 static constexpr unsigned INDEX_TABLE_SIZE = 2;
904 Index Indices[INDEX_TABLE_SIZE];
908 assert(NumIndices > 0 &&
"cannot pop from empty indices");
912 void push_struct_element(
unsigned ElementNum) {
913 assert(NumIndices < INDEX_TABLE_SIZE &&
"index table overflow");
915 Indices[NumIndices].IsStruct =
true;
916 Indices[NumIndices++].Num = ElementNum;
919 void push_vector_element() {
920 assert(NumIndices < INDEX_TABLE_SIZE &&
"index table overflow");
921 Indices[NumIndices].IsStruct =
false;
922 Indices[NumIndices++].Num = 0;
933 OS <<
"argument " << Pos.Num;
935 for (
const MatchPosition::Index &Idx :
936 ArrayRef(Pos.Indices).take_front(Pos.NumIndices)) {
938 OS <<
" struct element " << Idx.Num;
940 OS <<
" vector element";
946 std::tuple<Type *, ArrayRef<Intrinsic::IITDescriptor>, MatchPosition>;
950static std::pair<bool, StringRef>
952 Intrinsic::IITDescriptor::AnyKindElementConstraint EC) {
957 case IITDescriptor::EC_None:
958 return {
true,
"value"};
959 case IITDescriptor::EC_Integer:
961 case IITDescriptor::EC_Float:
963 case IITDescriptor::EC_Pointer:
978 OS << Position <<
" too many "
979 << (Position.IsRet ?
"returns" :
"arguments");
984 auto InfosRef = Infos;
985 auto DeferCheck = [&DeferredChecks, &InfosRef, &Position](
Type *
T) {
994 auto PrintMsg = [&OS, &Position,
996 std::optional<unsigned> OIdx = std::nullopt) ->
bool {
999 OS << Position <<
" type";
1001 OS <<
" (overload type " << *OIdx <<
")";
1002 OS <<
" expected " <<
Expected <<
", but got " << *Ty;
1009 auto PrintMsgInvalidOverloadTy =
1010 [&OS, &Position, &OverloadTys](
const Twine &DependentQualifier,
1012 unsigned OIdx) ->
bool {
1013 OS << Position <<
" is " << DependentQualifier <<
" overload type " << OIdx
1014 <<
", so overload type " << OIdx <<
" expected " <<
Expected
1015 <<
", but got " << *OverloadTys[OIdx];
1020 auto PrintMsgInvalidDepType =
1021 [&OS, &Position, &OverloadTys,
1023 unsigned OIdx) ->
bool {
1026 bool IsMatching = DependentQualifier.isSingleStringRef() &&
1027 DependentQualifier.getSingleStringRef() ==
"matching";
1028 OS << Position <<
" type (" << DependentQualifier <<
" overload type "
1029 << OIdx <<
") expected " <<
Expected;
1031 OS <<
" (overload type " << OIdx <<
" is " << *OverloadTys[OIdx] <<
")";
1032 OS <<
", but got " << *Ty;
1037 case IITDescriptor::Void:
1038 assert(Position.IsRet && Position.NumIndices == 0 &&
1039 "void descriptor expected only for return type");
1040 return PrintMsg(Ty->isVoidTy(),
"void");
1041 case IITDescriptor::MMX: {
1045 "x86_mmx (<1 x i64>)");
1047 case IITDescriptor::AMX:
1048 return PrintMsg(Ty->isX86_AMXTy(),
"x86_amx");
1049 case IITDescriptor::Token:
1050 return PrintMsg(Ty->isTokenTy(),
"token");
1051 case IITDescriptor::Metadata:
1052 return PrintMsg(Ty->isMetadataTy(),
"metadata");
1053 case IITDescriptor::Half:
1054 return PrintMsg(Ty->isHalfTy(),
"half");
1055 case IITDescriptor::BFloat:
1056 return PrintMsg(Ty->isBFloatTy(),
"bfloat");
1057 case IITDescriptor::Float:
1058 return PrintMsg(Ty->isFloatTy(),
"float");
1059 case IITDescriptor::Double:
1060 return PrintMsg(Ty->isDoubleTy(),
"double");
1061 case IITDescriptor::Quad:
1062 return PrintMsg(Ty->isFP128Ty(),
"fp128");
1063 case IITDescriptor::PPCQuad:
1064 return PrintMsg(Ty->isPPC_FP128Ty(),
"ppc_fp128");
1065 case IITDescriptor::Integer:
1066 return PrintMsg(Ty->isIntegerTy(
D.IntegerWidth),
1067 "i" +
Twine(
D.IntegerWidth));
1068 case IITDescriptor::AArch64Svcount:
1072 case IITDescriptor::WasmExternref:
1076 case IITDescriptor::WasmFuncref:
1080 case IITDescriptor::Vector: {
1082 StringRef Scalable =
D.VectorWidth.isScalable() ?
"vscale " :
"";
1084 PrintMsg(VT && VT->getElementCount() ==
D.VectorWidth,
1085 Twine(Scalable) +
"vector with " +
1086 Twine(
D.VectorWidth.getKnownMinValue()) +
" elements");
1089 Position.push_vector_element();
1091 OverloadTys, DeferredChecks, IsDeferredCheck, OS);
1093 case IITDescriptor::Pointer: {
1095 unsigned AS =
D.PointerAddressSpace;
1096 bool IsValid = PT && PT->getAddressSpace() == AS;
1098 return PrintMsg(IsValid,
"ptr");
1099 return PrintMsg(IsValid,
"ptr addrspace(" +
Twine(AS) +
")");
1102 case IITDescriptor::Struct: {
1104 unsigned EC =
D.StructNumElements;
1105 bool HasError = PrintMsg(
1106 ST && ST->isLiteral() && !ST->isPacked() && ST->getNumElements() == EC,
1107 "literal non-packed struct with " +
Twine(EC) +
" elements");
1112 Position.push_struct_element(Idx);
1114 IsDeferredCheck, OS))
1116 Position.pop_index();
1121 case IITDescriptor::Overloaded: {
1122 unsigned OIdx =
D.getOverloadIndex();
1123 assert(OIdx == OverloadTys.
size() && !IsDeferredCheck &&
1124 "Table consistency error");
1130 if (Ty->isTokenTy())
1131 return PrintMsg(
false,
"any manglable type", OIdx);
1133 IITDescriptor::AnyKindVectorConstraint VC;
1134 IITDescriptor::AnyKindElementConstraint EC;
1135 std::tie(VC, EC) =
D.getOverloadConstraints();
1137 bool IsValid = [&]() {
1139 case IITDescriptor::VC_None:
1141 case IITDescriptor::VC_Vector:
1143 case IITDescriptor::VC_Scalar:
1150 IsValid &= ElemValid;
1161 if (EC == IITDescriptor::EC_None) {
1165 return PrintMsg(
false,
formatv(
"any {} type", VK), OIdx);
1169 case IITDescriptor::VC_None:
1171 return PrintMsg(
false,
formatv(
"any {0} or {0} vector", EK), OIdx);
1172 case IITDescriptor::VC_Vector:
1173 return PrintMsg(
false,
formatv(
"any {} vector", EK), OIdx);
1174 case IITDescriptor::VC_Scalar:
1175 return PrintMsg(
false,
formatv(
"any {} type", EK), OIdx);
1180 case IITDescriptor::Match: {
1181 unsigned OIdx =
D.getOverloadIndex();
1182 if (OIdx >= OverloadTys.
size())
1183 return IsDeferredCheck || DeferCheck(Ty);
1184 return PrintMsgInvalidDepType(Ty == OverloadTys[OIdx],
"matching",
1185 formatv(
"{}", *OverloadTys[OIdx]), OIdx);
1188 case IITDescriptor::Extend:
1189 case IITDescriptor::Trunc: {
1190 unsigned OIdx =
D.getOverloadIndex();
1192 if (OIdx >= OverloadTys.
size())
1193 return IsDeferredCheck || DeferCheck(Ty);
1195 Type *OTy = OverloadTys[OIdx];
1196 bool IsExtend =
D.Kind == IITDescriptor::Extend;
1197 StringRef Qualifier = IsExtend ?
"extended" :
"truncated";
1199 return PrintMsgInvalidOverloadTy(Qualifier,
"int or vector of int", OIdx);
1202 return PrintMsgInvalidDepType(Ty == NewTy, Qualifier,
formatv(
"{}", *NewTy),
1205 case IITDescriptor::OneNthEltsVec: {
1206 unsigned OIdx =
D.getOverloadIndex();
1207 unsigned Divisor =
D.getVectorDivisor();
1209 if (OIdx >= OverloadTys.
size())
1210 return IsDeferredCheck || DeferCheck(Ty);
1211 Type *OTy = OverloadTys[OIdx];
1213 auto Qualifier =
formatv(
"1/nth (n={}) elements vector of", Divisor);
1215 return PrintMsgInvalidOverloadTy(Qualifier,
"vector", OIdx);
1216 if (!OVecTy->getElementCount().isKnownMultipleOf(Divisor))
1217 return PrintMsgInvalidOverloadTy(
1218 Qualifier,
formatv(
"vector with multiple of {} elements", Divisor),
1221 return PrintMsgInvalidDepType(
Expected == Ty, Qualifier,
1224 case IITDescriptor::SameVecWidth: {
1225 unsigned OIdx =
D.getOverloadIndex();
1226 if (OIdx >= OverloadTys.
size()) {
1229 return IsDeferredCheck || DeferCheck(Ty);
1234 StringRef Qualifier =
"same vector width of";
1235 if (OVecTy && !ThisArgVecType)
1236 return PrintMsgInvalidDepType(
false, Qualifier,
"vector", OIdx);
1237 if (!OVecTy && ThisArgVecType)
1238 return PrintMsgInvalidDepType(
false, Qualifier,
"scalar", OIdx);
1240 if (ThisArgVecType) {
1242 if (
Expected != ThisArgVecType->getElementCount())
1243 return PrintMsgInvalidDepType(
1246 EltTy = ThisArgVecType->getElementType();
1247 Position.push_vector_element();
1250 DeferredChecks, IsDeferredCheck, OS);
1252 case IITDescriptor::AnySameVecWidth: {
1253 unsigned RefOverloadIndex =
D.getRefOverloadIndex();
1254 if (RefOverloadIndex >= OverloadTys.
size()) {
1255 if (IsDeferredCheck)
1259 assert(
D.getOverloadIndex() == OverloadTys.
size() &&
1260 "Table consistency error");
1262 return DeferCheck(Ty);
1265 if (!IsDeferredCheck) {
1266 assert(
D.getOverloadIndex() == OverloadTys.
size() &&
1267 "Table consistency error");
1271 auto [ElemValid, Kind] =
1276 StringRef Qualifier =
"same vector width of";
1280 formatv(
"{0} vector with {1} elements", Kind, ExpectedCount);
1282 return PrintMsgInvalidDepType(
false, Qualifier,
Expected,
1285 ThisArgVecTy->getElementCount() == ExpectedCount && ElemValid;
1286 return PrintMsgInvalidDepType(IsValid, Qualifier,
Expected,
1292 return PrintMsgInvalidDepType(
false, Qualifier,
Expected,
1294 return PrintMsgInvalidDepType(ElemValid, Qualifier,
Expected,
1297 case IITDescriptor::VecElement: {
1298 unsigned OIdx =
D.getOverloadIndex();
1299 if (OIdx >= OverloadTys.
size())
1300 return IsDeferredCheck || DeferCheck(Ty);
1301 StringRef Qualifier =
"vector element of";
1304 return PrintMsgInvalidOverloadTy(Qualifier,
"vector", OIdx);
1306 return PrintMsgInvalidDepType(
Expected == Ty, Qualifier,
1309 case IITDescriptor::Subdivide2:
1310 case IITDescriptor::Subdivide4: {
1311 unsigned OIdx =
D.getOverloadIndex();
1313 if (OIdx >= OverloadTys.
size())
1314 return IsDeferredCheck || DeferCheck(Ty);
1316 int SubDivs =
D.Kind == IITDescriptor::Subdivide2 ? 1 : 2;
1319 formatv(
"subdivided by {} vector of", SubDivs == 1 ? 2 : 4);
1321 return PrintMsgInvalidOverloadTy(Qualifier,
"vector", OIdx);
1326 return PrintMsgInvalidDepType(
Expected == Ty, Qualifier,
1329 case IITDescriptor::VecOfBitcastsToInt: {
1330 unsigned OIdx =
D.getOverloadIndex();
1331 if (OIdx >= OverloadTys.
size())
1332 return IsDeferredCheck || DeferCheck(Ty);
1334 StringRef Qualifier =
"vector of bitcasts to int of";
1336 return PrintMsgInvalidOverloadTy(Qualifier,
"vector", OIdx);
1338 return PrintMsgInvalidDepType(
Expected == Ty, Qualifier,
1341 case IITDescriptor::VarArg:
1362 unsigned NumArgs,
bool IsVarArg,
1365 unsigned NumMissingTrailingParams) {
1368 assert(!Infos.
empty() &&
"Table consistency error");
1375 DeferredChecks,
false, OS))
1378 unsigned ProvidedArgs = FTy->getNumParams();
1379 if (ProvidedArgs + NumMissingTrailingParams != NumArgs) {
1380 OS <<
"intrinsic has incorrect number of args. Expected " << NumArgs
1381 <<
", but got " << ProvidedArgs;
1393 for (
unsigned I = 0,
E = DeferredChecks.
size();
I !=
E; ++
I) {
1394 auto &[DefTy, DefInfos, DefPosition] = DeferredChecks[
I];
1396 DeferredChecks,
true, OS))
1402 if (NumMissingTrailingParams != 0 &&
1403 (Infos.
size() != NumMissingTrailingParams ||
1405 return D.Kind != Intrinsic::IITDescriptor::Integer;
1407 OS <<
"cannot omit trailing parameters that are overloaded or non-integer";
1410 Infos = Infos.
drop_front(NumMissingTrailingParams);
1412 if (!Infos.
empty()) {
1413 OS <<
"intrinsic has too few arguments!";
1417 if (FTy->isVarArg() != IsVarArg) {
1419 OS <<
"intrinsic was not defined with variable arguments!";
1421 OS <<
"intrinsic was defined with variable arguments!";
1444 unsigned NumMissingTrailingParams,
1452 return ::isSignatureValid(FT,
TableRef, NumArgs, IsVarArg, OverloadTys, OS,
1453 NumMissingTrailingParams);
1466 return std::nullopt;
1470 std::string WantedName =
1472 if (Name == WantedName)
1473 return std::nullopt;
1476 if (
auto *ExistingGV =
F->getParent()->getNamedValue(WantedName)) {
1478 if (ExistingF->getFunctionType() ==
F->getFunctionType())
1485 ExistingGV->setName(WantedName +
".renamed");
1492 "Shouldn't change the signature");
1501 {Intrinsic::vector_interleave2, Intrinsic::vector_deinterleave2},
1502 {Intrinsic::vector_interleave3, Intrinsic::vector_deinterleave3},
1503 {Intrinsic::vector_interleave4, Intrinsic::vector_deinterleave4},
1504 {Intrinsic::vector_interleave5, Intrinsic::vector_deinterleave5},
1505 {Intrinsic::vector_interleave6, Intrinsic::vector_deinterleave6},
1506 {Intrinsic::vector_interleave7, Intrinsic::vector_deinterleave7},
1507 {Intrinsic::vector_interleave8, Intrinsic::vector_deinterleave8},
1511 assert(Factor >= 2 && Factor <= 8 &&
"Unexpected factor");
1516 assert(Factor >= 2 && Factor <= 8 &&
"Unexpected factor");
1523 OS << static_cast<FPClassTest>(Val);
1526#define GET_INTRINSIC_IMMARG_RANGE_SET_CHECKS
1527#include "llvm/IR/IntrinsicImpl.inc"
1529#define GET_INTRINSIC_PRETTY_PRINT_ARGUMENTS
1530#include "llvm/IR/IntrinsicImpl.inc"
1534#define GET_INTRINSIC_DEFAULT_ARG_VALUES
1535#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[]
static std::pair< bool, StringRef > checkElementConstraint(Type *Ty, Intrinsic::IITDescriptor::AnyKindElementConstraint EC)
Check whether Ty satisfies the given element constraint EC and return a description of the expected e...
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,...
This file declares utility interfaces for PISA 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.