LLVM 23.0.0git
Intrinsics.cpp
Go to the documentation of this file.
1//===-- Intrinsics.cpp - Intrinsic Function Handling ------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements functions required for supporting intrinsic functions.
10//
11//===----------------------------------------------------------------------===//
12
13#include "llvm/IR/Intrinsics.h"
17#include "llvm/IR/Function.h"
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"
34#include "llvm/IR/Module.h"
36#include "llvm/IR/Type.h"
37
38using namespace llvm;
39
40// Forward declaration of static functions.
41static bool isSignatureValid(FunctionType *FTy,
43 unsigned NumArgs, bool IsVarArg,
44 SmallVectorImpl<Type *> &OverloadTys,
45 raw_ostream &OS);
46
47/// Table of string intrinsic names indexed by enum value.
48#define GET_INTRINSIC_NAME_TABLE
49#include "llvm/IR/IntrinsicImpl.inc"
50
52 assert(id < num_intrinsics && "Invalid intrinsic ID!");
53 return IntrinsicNameTable[IntrinsicNameOffsetTable[id]];
54}
55
57 assert(id < num_intrinsics && "Invalid intrinsic ID!");
59 "This version of getName does not support overloading");
60 return getBaseName(id);
61}
62
63/// Returns a stable mangling for the type specified for use in the name
64/// mangling scheme used by 'any' types in intrinsic signatures. The mangling
65/// of named types is simply their name. Manglings for unnamed types consist
66/// of a prefix ('p' for pointers, 'a' for arrays, 'f_' for functions)
67/// combined with the mangling of their component types. A vararg function
68/// type will have a suffix of 'vararg'. Since function types can contain
69/// other function types, we close a function type mangling with suffix 'f'
70/// which can't be confused with it's prefix. This ensures we don't have
71/// collisions between two unrelated function types. Otherwise, you might
72/// parse ffXX as f(fXX) or f(fX)X. (X is a placeholder for any other type.)
73/// The HasUnnamedType boolean is set if an unnamed type was encountered,
74/// indicating that extra care must be taken to ensure a unique name.
75static std::string getMangledTypeStr(Type *Ty, bool &HasUnnamedType) {
76 std::string Result;
77 if (PointerType *PTyp = dyn_cast<PointerType>(Ty)) {
78 Result += "p" + utostr(PTyp->getAddressSpace());
79 } else if (ArrayType *ATyp = dyn_cast<ArrayType>(Ty)) {
80 Result += "a" + utostr(ATyp->getNumElements()) +
81 getMangledTypeStr(ATyp->getElementType(), HasUnnamedType);
82 } else if (StructType *STyp = dyn_cast<StructType>(Ty)) {
83 if (!STyp->isLiteral()) {
84 Result += "s_";
85 if (STyp->hasName())
86 Result += STyp->getName();
87 else
88 HasUnnamedType = true;
89 } else {
90 Result += "sl_";
91 for (auto *Elem : STyp->elements())
92 Result += getMangledTypeStr(Elem, HasUnnamedType);
93 }
94 // Ensure nested structs are distinguishable.
95 Result += "s";
96 } else if (FunctionType *FT = dyn_cast<FunctionType>(Ty)) {
97 Result += "f_" + getMangledTypeStr(FT->getReturnType(), HasUnnamedType);
98 for (size_t i = 0; i < FT->getNumParams(); i++)
99 Result += getMangledTypeStr(FT->getParamType(i), HasUnnamedType);
100 if (FT->isVarArg())
101 Result += "vararg";
102 // Ensure nested function types are distinguishable.
103 Result += "f";
104 } else if (VectorType *VTy = dyn_cast<VectorType>(Ty)) {
105 ElementCount EC = VTy->getElementCount();
106 if (EC.isScalable())
107 Result += "nx";
108 Result += "v" + utostr(EC.getKnownMinValue()) +
109 getMangledTypeStr(VTy->getElementType(), HasUnnamedType);
110 } else if (TargetExtType *TETy = dyn_cast<TargetExtType>(Ty)) {
111 Result += "t";
112 Result += TETy->getName();
113 for (Type *ParamTy : TETy->type_params())
114 Result += "_" + getMangledTypeStr(ParamTy, HasUnnamedType);
115 for (unsigned IntParam : TETy->int_params())
116 Result += "_" + utostr(IntParam);
117 // Ensure nested target extension types are distinguishable.
118 Result += "t";
119 } else if (Ty) {
120 switch (Ty->getTypeID()) {
121 default:
122 llvm_unreachable("Unhandled type");
123 case Type::VoidTyID:
124 Result += "isVoid";
125 break;
127 Result += "Metadata";
128 break;
129 case Type::HalfTyID:
130 Result += "f16";
131 break;
132 case Type::BFloatTyID:
133 Result += "bf16";
134 break;
135 case Type::FloatTyID:
136 Result += "f32";
137 break;
138 case Type::DoubleTyID:
139 Result += "f64";
140 break;
142 Result += "f80";
143 break;
144 case Type::FP128TyID:
145 Result += "f128";
146 break;
148 Result += "ppcf128";
149 break;
151 Result += "x86amx";
152 break;
154 Result += "i" + utostr(cast<IntegerType>(Ty)->getBitWidth());
155 break;
156 case Type::ByteTyID:
157 Result += "b" + utostr(cast<ByteType>(Ty)->getBitWidth());
158 break;
159 }
160 }
161 return Result;
162}
163
165 ArrayRef<Type *> OverloadTys, Module *M,
166 FunctionType *FT,
167 bool EarlyModuleCheck) {
168
169 assert(Id < Intrinsic::num_intrinsics && "Invalid intrinsic ID!");
170 assert((OverloadTys.empty() || Intrinsic::isOverloaded(Id)) &&
171 "This version of getName is for overloaded intrinsics only");
172 (void)EarlyModuleCheck;
173 assert((!EarlyModuleCheck || M ||
174 !any_of(OverloadTys, llvm::IsaPred<PointerType>)) &&
175 "Intrinsic overloading on pointer types need to provide a Module");
176 bool HasUnnamedType = false;
177 std::string Result(Intrinsic::getBaseName(Id));
178 for (Type *Ty : OverloadTys)
179 Result += "." + getMangledTypeStr(Ty, HasUnnamedType);
180 if (HasUnnamedType) {
181 assert(M && "unnamed types need a module");
182 if (!FT)
183 FT = Intrinsic::getType(M->getContext(), Id, OverloadTys);
184 else
185 assert(FT == Intrinsic::getType(M->getContext(), Id, OverloadTys) &&
186 "Provided FunctionType must match arguments");
187 return M->getUniqueIntrinsicName(Result, Id, FT);
188 }
189 return Result;
190}
191
192std::string Intrinsic::getName(ID Id, ArrayRef<Type *> OverloadTys, Module *M,
193 FunctionType *FT) {
194 assert(M && "We need to have a Module");
195 return getIntrinsicNameImpl(Id, OverloadTys, M, FT, true);
196}
197
199 ArrayRef<Type *> OverloadTys) {
200 return getIntrinsicNameImpl(Id, OverloadTys, nullptr, nullptr, false);
201}
202
203/// IIT_Info - These are enumerators that describe the entries returned by the
204/// getIntrinsicInfoTableEntries function.
205///
206/// Defined in Intrinsics.td.
208#define GET_INTRINSIC_IITINFO
209#include "llvm/IR/IntrinsicImpl.inc"
210};
211
212static_assert(IIT_Done == 0, "IIT_Done expected to be 0");
213
214static void
215DecodeIITType(unsigned &NextElt, ArrayRef<unsigned char> Infos,
217 using namespace Intrinsic;
218
219 auto IsScalableVector = [&]() {
220 IIT_Info NextInfo = IIT_Info(Infos[NextElt]);
221 if (NextInfo != IIT_SCALABLE_VEC)
222 return false;
223 // Eat the IIT_SCALABLE_VEC token.
224 ++NextElt;
225 return true;
226 };
227
228 IIT_Info Info = IIT_Info(Infos[NextElt++]);
229
230 switch (Info) {
231 case IIT_Done:
232 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Void, 0));
233 return;
234 case IIT_VARARG:
235 OutputTable.push_back(IITDescriptor::get(IITDescriptor::VarArg, 0));
236 return;
237 case IIT_MMX:
238 OutputTable.push_back(IITDescriptor::get(IITDescriptor::MMX, 0));
239 return;
240 case IIT_AMX:
241 OutputTable.push_back(IITDescriptor::get(IITDescriptor::AMX, 0));
242 return;
243 case IIT_TOKEN:
244 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Token, 0));
245 return;
246 case IIT_METADATA:
247 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Metadata, 0));
248 return;
249 case IIT_F16:
250 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Half, 0));
251 return;
252 case IIT_BF16:
253 OutputTable.push_back(IITDescriptor::get(IITDescriptor::BFloat, 0));
254 return;
255 case IIT_F32:
256 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Float, 0));
257 return;
258 case IIT_F64:
259 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Double, 0));
260 return;
261 case IIT_F128:
262 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Quad, 0));
263 return;
264 case IIT_PPCF128:
265 OutputTable.push_back(IITDescriptor::get(IITDescriptor::PPCQuad, 0));
266 return;
267 case IIT_I1:
268 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 1));
269 return;
270 case IIT_I2:
271 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 2));
272 return;
273 case IIT_I4:
274 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 4));
275 return;
276 case IIT_AARCH64_SVCOUNT:
277 OutputTable.push_back(IITDescriptor::get(IITDescriptor::AArch64Svcount, 0));
278 return;
279 case IIT_I8:
280 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 8));
281 return;
282 case IIT_I16:
283 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 16));
284 return;
285 case IIT_I32:
286 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 32));
287 return;
288 case IIT_I64:
289 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 64));
290 return;
291 case IIT_I128:
292 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 128));
293 return;
294 case IIT_V1:
295 OutputTable.push_back(IITDescriptor::getVector(1, IsScalableVector()));
296 DecodeIITType(NextElt, Infos, OutputTable);
297 return;
298 case IIT_V2:
299 OutputTable.push_back(IITDescriptor::getVector(2, IsScalableVector()));
300 DecodeIITType(NextElt, Infos, OutputTable);
301 return;
302 case IIT_V3:
303 OutputTable.push_back(IITDescriptor::getVector(3, IsScalableVector()));
304 DecodeIITType(NextElt, Infos, OutputTable);
305 return;
306 case IIT_V4:
307 OutputTable.push_back(IITDescriptor::getVector(4, IsScalableVector()));
308 DecodeIITType(NextElt, Infos, OutputTable);
309 return;
310 case IIT_V6:
311 OutputTable.push_back(IITDescriptor::getVector(6, IsScalableVector()));
312 DecodeIITType(NextElt, Infos, OutputTable);
313 return;
314 case IIT_V8:
315 OutputTable.push_back(IITDescriptor::getVector(8, IsScalableVector()));
316 DecodeIITType(NextElt, Infos, OutputTable);
317 return;
318 case IIT_V10:
319 OutputTable.push_back(IITDescriptor::getVector(10, IsScalableVector()));
320 DecodeIITType(NextElt, Infos, OutputTable);
321 return;
322 case IIT_V16:
323 OutputTable.push_back(IITDescriptor::getVector(16, IsScalableVector()));
324 DecodeIITType(NextElt, Infos, OutputTable);
325 return;
326 case IIT_V32:
327 OutputTable.push_back(IITDescriptor::getVector(32, IsScalableVector()));
328 DecodeIITType(NextElt, Infos, OutputTable);
329 return;
330 case IIT_V64:
331 OutputTable.push_back(IITDescriptor::getVector(64, IsScalableVector()));
332 DecodeIITType(NextElt, Infos, OutputTable);
333 return;
334 case IIT_V128:
335 OutputTable.push_back(IITDescriptor::getVector(128, IsScalableVector()));
336 DecodeIITType(NextElt, Infos, OutputTable);
337 return;
338 case IIT_V256:
339 OutputTable.push_back(IITDescriptor::getVector(256, IsScalableVector()));
340 DecodeIITType(NextElt, Infos, OutputTable);
341 return;
342 case IIT_V512:
343 OutputTable.push_back(IITDescriptor::getVector(512, IsScalableVector()));
344 DecodeIITType(NextElt, Infos, OutputTable);
345 return;
346 case IIT_V1024:
347 OutputTable.push_back(IITDescriptor::getVector(1024, IsScalableVector()));
348 DecodeIITType(NextElt, Infos, OutputTable);
349 return;
350 case IIT_V2048:
351 OutputTable.push_back(IITDescriptor::getVector(2048, IsScalableVector()));
352 DecodeIITType(NextElt, Infos, OutputTable);
353 return;
354 case IIT_V4096:
355 OutputTable.push_back(IITDescriptor::getVector(4096, IsScalableVector()));
356 DecodeIITType(NextElt, Infos, OutputTable);
357 return;
358 case IIT_EXTERNREF:
359 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Pointer, 10));
360 return;
361 case IIT_FUNCREF:
362 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Pointer, 20));
363 return;
364 case IIT_PTR:
365 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Pointer, 0));
366 return;
367 case IIT_PTR_AS: // pointer with address space.
368 OutputTable.push_back(
369 IITDescriptor::get(IITDescriptor::Pointer, Infos[NextElt++]));
370 return;
371 case IIT_ANY: {
372 unsigned OverloadInfo = Infos[NextElt++];
373 OutputTable.push_back(
374 IITDescriptor::get(IITDescriptor::Overloaded, OverloadInfo));
375 return;
376 }
377 case IIT_EXTEND_ARG: {
378 unsigned OverloadIndex = Infos[NextElt++];
379 OutputTable.push_back(
380 IITDescriptor::get(IITDescriptor::Extend, OverloadIndex));
381 return;
382 }
383 case IIT_TRUNC_ARG: {
384 unsigned OverloadIndex = Infos[NextElt++];
385 OutputTable.push_back(
386 IITDescriptor::get(IITDescriptor::Trunc, OverloadIndex));
387 return;
388 }
389 case IIT_ONE_NTH_ELTS_VEC_ARG: {
390 unsigned short OverloadIndex = Infos[NextElt++];
391 unsigned short N = Infos[NextElt++];
392 OutputTable.push_back(IITDescriptor::get(IITDescriptor::OneNthEltsVec,
393 /*Hi=*/N, /*Lo=*/OverloadIndex));
394 return;
395 }
396 case IIT_SAME_VEC_WIDTH_ARG: {
397 unsigned OverloadIndex = Infos[NextElt++];
398 OutputTable.push_back(
399 IITDescriptor::get(IITDescriptor::SameVecWidth, OverloadIndex));
400 // IIT_SAME_VEC_WIDTH_ARG entry is followed by the element type.
401 DecodeIITType(NextElt, Infos, OutputTable);
402 return;
403 }
404 case IIT_VEC_OF_ANYPTRS_TO_ELT: {
405 unsigned short OverloadIndex = Infos[NextElt++];
406 unsigned short RefOverloadIndex = Infos[NextElt++];
407 OutputTable.push_back(IITDescriptor::get(IITDescriptor::VecOfAnyPtrsToElt,
408 /*Hi=*/RefOverloadIndex,
409 /*Lo=*/OverloadIndex));
410 return;
411 }
412 case IIT_STRUCT: {
413 unsigned StructElts = Infos[NextElt++] + 2;
414
415 OutputTable.push_back(
416 IITDescriptor::get(IITDescriptor::Struct, StructElts));
417
418 for (unsigned i = 0; i != StructElts; ++i)
419 DecodeIITType(NextElt, Infos, OutputTable);
420 return;
421 }
422 case IIT_SUBDIVIDE2_ARG: {
423 unsigned OverloadIndex = Infos[NextElt++];
424 OutputTable.push_back(
425 IITDescriptor::get(IITDescriptor::Subdivide2, OverloadIndex));
426 return;
427 }
428 case IIT_SUBDIVIDE4_ARG: {
429 unsigned OverloadIndex = Infos[NextElt++];
430 OutputTable.push_back(
431 IITDescriptor::get(IITDescriptor::Subdivide4, OverloadIndex));
432 return;
433 }
434 case IIT_VEC_ELEMENT: {
435 unsigned OverloadIndex = Infos[NextElt++];
436 OutputTable.push_back(
437 IITDescriptor::get(IITDescriptor::VecElement, OverloadIndex));
438 return;
439 }
440 case IIT_VEC_OF_BITCASTS_TO_INT: {
441 unsigned OverloadIndex = Infos[NextElt++];
442 OutputTable.push_back(
443 IITDescriptor::get(IITDescriptor::VecOfBitcastsToInt, OverloadIndex));
444 return;
445 }
446 case IIT_SCALABLE_VEC:
447 break;
448 }
449 llvm_unreachable("unhandled");
450}
451
452#define GET_INTRINSIC_GENERATOR_GLOBAL
453#include "llvm/IR/IntrinsicImpl.inc"
454
455std::tuple<ArrayRef<Intrinsic::IITDescriptor>, unsigned, bool>
458 // Note that `FixedEncodingTy` is defined in IntrinsicImpl.inc and can be
459 // uint16_t or uint32_t based on the the value of `Use16BitFixedEncoding` in
460 // IntrinsicEmitter.cpp.
461 constexpr unsigned FixedEncodingBits = sizeof(FixedEncodingTy) * CHAR_BIT;
462 constexpr unsigned MSBPosition = FixedEncodingBits - 1;
463 // Mask with all bits 1 except the most significant bit.
464 constexpr unsigned Mask = (1U << MSBPosition) - 1;
465
466 FixedEncodingTy TableVal = IIT_Table[id - 1];
467
468 // Array to hold the inlined fixed encoding values expanded from nibbles to
469 // bytes. Its size can be be atmost FixedEncodingBits / 4 i.e., number
470 // of nibbles that can fit in `FixedEncodingTy` + 1 (the IIT_Done terminator
471 // that is not explicitly encoded). Note that if there are trailing 0 bytes
472 // in the encoding (for example, payload following one of the IIT tokens),
473 // the inlined encoding does not encode the actual size of the encoding, so
474 // we always assume its size of this maximum length possible, followed by the
475 // IIT_Done terminator token (whose value is 0).
476 unsigned char IITValues[FixedEncodingBits / 4 + 1] = {0};
477
478 ArrayRef<unsigned char> IITEntries;
479 unsigned NextElt = 0;
480 // Check to see if the intrinsic's type was inlined in the fixed encoding
481 // table.
482 if (TableVal >> MSBPosition) {
483 // This is an offset into the IIT_LongEncodingTable.
484 IITEntries = IIT_LongEncodingTable;
485
486 // Strip sentinel bit.
487 NextElt = TableVal & Mask;
488 } else {
489 // If the entry was encoded into a single word in the table itself, decode
490 // it from an array of nibbles to an array of bytes.
491 do {
492 IITValues[NextElt++] = TableVal & 0xF;
493 TableVal >>= 4;
494 } while (TableVal);
495
496 IITEntries = IITValues;
497 NextElt = 0;
498 }
499
500 // Okay, decode the table into the output vector of IITDescriptors.
501 DecodeIITType(NextElt, IITEntries, T);
502 unsigned NumArgs = 0;
503 while (IITEntries[NextElt] != IIT_Done) {
504 DecodeIITType(NextElt, IITEntries, T);
505 ++NumArgs;
506 }
507
509
510 bool IsVarArg = false;
511 if (TableRef.back().Kind == Intrinsic::IITDescriptor::VarArg) {
512 IsVarArg = true;
513 TableRef.consume_back();
514 --NumArgs;
515 }
516 return {TableRef, NumArgs, IsVarArg};
517}
518
520 ArrayRef<Type *> OverloadTys,
521 LLVMContext &Context) {
522 using namespace Intrinsic;
523
524 IITDescriptor D = Infos.consume_front();
525
526 switch (D.Kind) {
527 case IITDescriptor::Void:
528 return Type::getVoidTy(Context);
529 case IITDescriptor::MMX:
531 case IITDescriptor::AMX:
532 return Type::getX86_AMXTy(Context);
533 case IITDescriptor::Token:
534 return Type::getTokenTy(Context);
535 case IITDescriptor::Metadata:
536 return Type::getMetadataTy(Context);
537 case IITDescriptor::Half:
538 return Type::getHalfTy(Context);
539 case IITDescriptor::BFloat:
540 return Type::getBFloatTy(Context);
541 case IITDescriptor::Float:
542 return Type::getFloatTy(Context);
543 case IITDescriptor::Double:
544 return Type::getDoubleTy(Context);
545 case IITDescriptor::Quad:
546 return Type::getFP128Ty(Context);
547 case IITDescriptor::PPCQuad:
548 return Type::getPPC_FP128Ty(Context);
549 case IITDescriptor::AArch64Svcount:
550 return TargetExtType::get(Context, "aarch64.svcount");
551
552 case IITDescriptor::Integer:
553 return IntegerType::get(Context, D.IntegerWidth);
554 case IITDescriptor::Vector:
555 return VectorType::get(DecodeFixedType(Infos, OverloadTys, Context),
556 D.VectorWidth);
557 case IITDescriptor::Pointer:
558 return PointerType::get(Context, D.PointerAddressSpace);
559 case IITDescriptor::Struct: {
561 for (unsigned i = 0, e = D.StructNumElements; i != e; ++i)
562 Elts.push_back(DecodeFixedType(Infos, OverloadTys, Context));
563 return StructType::get(Context, Elts);
564 }
565 // For any overload kind or partially dependent type, substitute it with the
566 // corresponding concrete type from OverloadTys.
567 case IITDescriptor::Overloaded:
568 case IITDescriptor::VecOfAnyPtrsToElt:
569 return OverloadTys[D.getOverloadIndex()];
570 case IITDescriptor::Extend:
571 return OverloadTys[D.getOverloadIndex()]->getExtendedType();
572 case IITDescriptor::Trunc:
573 return OverloadTys[D.getOverloadIndex()]->getTruncatedType();
574 case IITDescriptor::Subdivide2:
575 case IITDescriptor::Subdivide4: {
576 Type *Ty = OverloadTys[D.getOverloadIndex()];
578 assert(VTy && "Expected overload type to be a Vector Type");
579 int SubDivs = D.Kind == IITDescriptor::Subdivide2 ? 1 : 2;
580 return VectorType::getSubdividedVectorType(VTy, SubDivs);
581 }
582 case IITDescriptor::OneNthEltsVec:
584 cast<VectorType>(OverloadTys[D.getOverloadIndex()]),
585 D.getVectorDivisor());
586 case IITDescriptor::SameVecWidth: {
587 Type *EltTy = DecodeFixedType(Infos, OverloadTys, Context);
588 Type *Ty = OverloadTys[D.getOverloadIndex()];
589 if (auto *VTy = dyn_cast<VectorType>(Ty))
590 return VectorType::get(EltTy, VTy->getElementCount());
591 return EltTy;
592 }
593 case IITDescriptor::VecElement: {
594 Type *Ty = OverloadTys[D.getOverloadIndex()];
595 if (VectorType *VTy = dyn_cast<VectorType>(Ty))
596 return VTy->getElementType();
597 llvm_unreachable("Expected overload type to be a Vector Type");
598 }
599 case IITDescriptor::VecOfBitcastsToInt: {
600 Type *Ty = OverloadTys[D.getOverloadIndex()];
602 assert(VTy && "Expected overload type to be a Vector Type");
603 return VectorType::getInteger(VTy);
604 }
605 case IITDescriptor::VarArg:
606 // VarArg token should be consumed by `getIntrinsicInfoTableEntries`, so we
607 // should never see it here.
608 llvm_unreachable("IITDescriptor::VarArg not expected");
609 }
610 llvm_unreachable("unhandled");
611}
612
614 ArrayRef<Type *> OverloadTys) {
616 auto [TableRef, _, IsVarArg] = getIntrinsicInfoTableEntries(id, Table);
617
618 Type *ResultTy = DecodeFixedType(TableRef, OverloadTys, Context);
619
621 while (!TableRef.empty())
622 ArgTys.push_back(DecodeFixedType(TableRef, OverloadTys, Context));
623 return FunctionType::get(ResultTy, ArgTys, IsVarArg);
624}
625
627#define GET_INTRINSIC_OVERLOAD_TABLE
628#include "llvm/IR/IntrinsicImpl.inc"
629}
630
632#define GET_INTRINSIC_SCALARIZABLE_TABLE
633#include "llvm/IR/IntrinsicImpl.inc"
634}
635
637#define GET_INTRINSIC_PRETTY_PRINT_TABLE
638#include "llvm/IR/IntrinsicImpl.inc"
639}
640
641/// Table of per-target intrinsic name tables.
642#define GET_INTRINSIC_TARGET_DATA
643#include "llvm/IR/IntrinsicImpl.inc"
644
646 return IID > TargetInfos[0].Count;
647}
648
649/// Looks up Name in NameTable via binary search. NameTable must be sorted
650/// and all entries must start with "llvm.". If NameTable contains an exact
651/// match for Name or a prefix of Name followed by a dot, its index in
652/// NameTable is returned. Otherwise, -1 is returned.
654 StringRef Name, StringRef Target = "") {
655 assert(Name.starts_with("llvm.") && "Unexpected intrinsic prefix");
656 assert(Name.drop_front(5).starts_with(Target) && "Unexpected target");
657
658 // Do successive binary searches of the dotted name components. For
659 // "llvm.gc.experimental.statepoint.p1i8.p1i32", we will find the range of
660 // intrinsics starting with "llvm.gc", then "llvm.gc.experimental", then
661 // "llvm.gc.experimental.statepoint", and then we will stop as the range is
662 // size 1. During the search, we can skip the prefix that we already know is
663 // identical. By using strncmp we consider names with differing suffixes to
664 // be part of the equal range.
665 size_t CmpEnd = 4; // Skip the "llvm" component.
666 if (!Target.empty())
667 CmpEnd += 1 + Target.size(); // skip the .target component.
668
669 const unsigned *Low = NameOffsetTable.begin();
670 const unsigned *High = NameOffsetTable.end();
671 const unsigned *LastLow = Low;
672 while (CmpEnd < Name.size() && High - Low > 0) {
673 size_t CmpStart = CmpEnd;
674 CmpEnd = Name.find('.', CmpStart + 1);
675 CmpEnd = CmpEnd == StringRef::npos ? Name.size() : CmpEnd;
676 auto Cmp = [CmpStart, CmpEnd](auto LHS, auto RHS) {
677 // `equal_range` requires the comparison to work with either side being an
678 // offset or the value. Detect which kind each side is to set up the
679 // compared strings.
680 const char *LHSStr;
681 if constexpr (std::is_integral_v<decltype(LHS)>)
682 LHSStr = IntrinsicNameTable.getCString(LHS);
683 else
684 LHSStr = LHS;
685
686 const char *RHSStr;
687 if constexpr (std::is_integral_v<decltype(RHS)>)
688 RHSStr = IntrinsicNameTable.getCString(RHS);
689 else
690 RHSStr = RHS;
691
692 return strncmp(LHSStr + CmpStart, RHSStr + CmpStart, CmpEnd - CmpStart) <
693 0;
694 };
695 LastLow = Low;
696 std::tie(Low, High) = std::equal_range(Low, High, Name.data(), Cmp);
697 }
698 if (High - Low > 0)
699 LastLow = Low;
700
701 if (LastLow == NameOffsetTable.end())
702 return -1;
703 StringRef NameFound = IntrinsicNameTable[*LastLow];
704 if (Name == NameFound ||
705 (Name.starts_with(NameFound) && Name[NameFound.size()] == '.'))
706 return LastLow - NameOffsetTable.begin();
707 return -1;
708}
709
710/// Find the segment of \c IntrinsicNameOffsetTable for intrinsics with the same
711/// target as \c Name, or the generic table if \c Name is not target specific.
712///
713/// Returns the relevant slice of \c IntrinsicNameOffsetTable and the target
714/// name.
715static std::pair<ArrayRef<unsigned>, StringRef>
717 assert(Name.starts_with("llvm."));
718
719 ArrayRef<IntrinsicTargetInfo> Targets(TargetInfos);
720 // Drop "llvm." and take the first dotted component. That will be the target
721 // if this is target specific.
722 StringRef Target = Name.drop_front(5).split('.').first;
723 auto It = partition_point(
724 Targets, [=](const IntrinsicTargetInfo &TI) { return TI.Name < Target; });
725 // We've either found the target or just fall back to the generic set, which
726 // is always first.
727 const auto &TI = It != Targets.end() && It->Name == Target ? *It : Targets[0];
728 return {ArrayRef(&IntrinsicNameOffsetTable[1] + TI.Offset, TI.Count),
729 TI.Name};
730}
731
732/// This does the actual lookup of an intrinsic ID which matches the given
733/// function name.
735 auto [NameOffsetTable, Target] = findTargetSubtable(Name);
736 int Idx = lookupLLVMIntrinsicByName(NameOffsetTable, Name, Target);
737 if (Idx == -1)
739
740 // Intrinsic IDs correspond to the location in IntrinsicNameTable, but we have
741 // an index into a sub-table.
742 int Adjust = NameOffsetTable.data() - IntrinsicNameOffsetTable;
743 Intrinsic::ID ID = static_cast<Intrinsic::ID>(Idx + Adjust);
744
745 // If the intrinsic is not overloaded, require an exact match. If it is
746 // overloaded, require either exact or prefix match.
747 const auto MatchSize = IntrinsicNameTable[NameOffsetTable[Idx]].size();
748 assert(Name.size() >= MatchSize && "Expected either exact or prefix match");
749 bool IsExactMatch = Name.size() == MatchSize;
750 return IsExactMatch || Intrinsic::isOverloaded(ID) ? ID
752}
753
754/// This defines the "Intrinsic::getAttributes(ID id)" method.
755#define GET_INTRINSIC_ATTRIBUTES
756#include "llvm/IR/IntrinsicImpl.inc"
757
758static Function *
760 ArrayRef<Type *> OverloadTys,
761 FunctionType *FT) {
762 std::string Name = OverloadTys.empty()
763 ? Intrinsic::getName(id).str()
764 : Intrinsic::getName(id, OverloadTys, M, FT);
765 Function *F = cast<Function>(M->getOrInsertFunction(Name, FT).getCallee());
766 if (F->getFunctionType() == FT)
767 return F;
768
769 // It's possible that a declaration for this intrinsic already exists with an
770 // incorrect signature, if the signature has changed, but this particular
771 // declaration has not been auto-upgraded yet. In that case, rename the
772 // invalid declaration and insert a new one with the correct signature. The
773 // invalid declaration will get upgraded later.
774 F->setName(F->getName() + ".invalid");
775 return cast<Function>(M->getOrInsertFunction(Name, FT).getCallee());
776}
777
779 ArrayRef<Type *> OverloadTys) {
780 // There can never be multiple globals with the same name of different types,
781 // because intrinsics must be a specific type.
782 FunctionType *FT = getType(M->getContext(), id, OverloadTys);
783 return getOrInsertIntrinsicDeclarationImpl(M, id, OverloadTys, FT);
784}
785
787 ArrayRef<Type *> ArgTys) {
788 // If the intrinsic is not overloaded, use the non-overloaded version.
790 return getOrInsertDeclaration(M, id);
791
792 // Get the intrinsic signature metadata.
794 auto [TableRef, NumArgs, IsVarArg] = getIntrinsicInfoTableEntries(id, Table);
795 FunctionType *FTy = FunctionType::get(RetTy, ArgTys, IsVarArg);
796
797 // Automatically determine the overloaded types.
798 SmallVector<Type *, 4> OverloadTys;
799 [[maybe_unused]] bool IsValid = ::isSignatureValid(
800 FTy, TableRef, NumArgs, IsVarArg, OverloadTys, nulls());
801 assert(IsValid && "intrinsic signature mismatch");
802 return getOrInsertIntrinsicDeclarationImpl(M, id, OverloadTys, FTy);
803}
804
806 return M->getFunction(getName(id));
807}
808
810 ArrayRef<Type *> OverloadTys,
811 FunctionType *FT) {
812 return M->getFunction(getName(id, OverloadTys, M, FT));
813}
814
815// This defines the "Intrinsic::getIntrinsicForClangBuiltin()" method.
816#define GET_LLVM_INTRINSIC_FOR_CLANG_BUILTIN
817#include "llvm/IR/IntrinsicImpl.inc"
818
819// This defines the "Intrinsic::getIntrinsicForMSBuiltin()" method.
820#define GET_LLVM_INTRINSIC_FOR_MS_BUILTIN
821#include "llvm/IR/IntrinsicImpl.inc"
822
824 switch (QID) {
825#define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC) \
826 case Intrinsic::INTRINSIC:
827#include "llvm/IR/ConstrainedOps.def"
828#undef INSTRUCTION
829 return true;
830 default:
831 return false;
832 }
833}
834
836 switch (QID) {
837#define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC) \
838 case Intrinsic::INTRINSIC: \
839 return ROUND_MODE == 1;
840#include "llvm/IR/ConstrainedOps.def"
841#undef INSTRUCTION
842 default:
843 return false;
844 }
845}
846
848 std::pair<Type *, ArrayRef<Intrinsic::IITDescriptor>>;
849
850static bool
852 SmallVectorImpl<Type *> &OverloadTys,
854 bool IsDeferredCheck) {
855 using namespace Intrinsic;
856
857 // If we ran out of descriptors, there are too many arguments.
858 if (Infos.empty())
859 return true;
860
861 // Do this before slicing off the 'front' part
862 auto InfosRef = Infos;
863 auto DeferCheck = [&DeferredChecks, &InfosRef](Type *T) {
864 DeferredChecks.emplace_back(T, InfosRef);
865 return false;
866 };
867
868 IITDescriptor D = Infos.consume_front();
869
870 switch (D.Kind) {
871 case IITDescriptor::Void:
872 return !Ty->isVoidTy();
873 case IITDescriptor::MMX: {
875 return !VT || VT->getNumElements() != 1 ||
876 !VT->getElementType()->isIntegerTy(64);
877 }
878 case IITDescriptor::AMX:
879 return !Ty->isX86_AMXTy();
880 case IITDescriptor::Token:
881 return !Ty->isTokenTy();
882 case IITDescriptor::Metadata:
883 return !Ty->isMetadataTy();
884 case IITDescriptor::Half:
885 return !Ty->isHalfTy();
886 case IITDescriptor::BFloat:
887 return !Ty->isBFloatTy();
888 case IITDescriptor::Float:
889 return !Ty->isFloatTy();
890 case IITDescriptor::Double:
891 return !Ty->isDoubleTy();
892 case IITDescriptor::Quad:
893 return !Ty->isFP128Ty();
894 case IITDescriptor::PPCQuad:
895 return !Ty->isPPC_FP128Ty();
896 case IITDescriptor::Integer:
897 return !Ty->isIntegerTy(D.IntegerWidth);
898 case IITDescriptor::AArch64Svcount:
899 return !isa<TargetExtType>(Ty) ||
900 cast<TargetExtType>(Ty)->getName() != "aarch64.svcount";
901 case IITDescriptor::Vector: {
903 return !VT || VT->getElementCount() != D.VectorWidth ||
904 matchIntrinsicType(VT->getElementType(), Infos, OverloadTys,
905 DeferredChecks, IsDeferredCheck);
906 }
907 case IITDescriptor::Pointer: {
909 return !PT || PT->getAddressSpace() != D.PointerAddressSpace;
910 }
911
912 case IITDescriptor::Struct: {
914 if (!ST || !ST->isLiteral() || ST->isPacked() ||
915 ST->getNumElements() != D.StructNumElements)
916 return true;
917
918 for (unsigned i = 0, e = D.StructNumElements; i != e; ++i)
919 if (matchIntrinsicType(ST->getElementType(i), Infos, OverloadTys,
920 DeferredChecks, IsDeferredCheck))
921 return true;
922 return false;
923 }
924
925 case IITDescriptor::Overloaded:
926 // If this is the second occurrence of an argument,
927 // verify that the later instance matches the previous instance.
928 if (D.getOverloadIndex() < OverloadTys.size())
929 return Ty != OverloadTys[D.getOverloadIndex()];
930
931 if (D.getOverloadIndex() > OverloadTys.size() ||
932 D.getOverloadKind() == IITDescriptor::AK_MatchType)
933 return IsDeferredCheck || DeferCheck(Ty);
934
935 assert(D.getOverloadIndex() == OverloadTys.size() && !IsDeferredCheck &&
936 "Table consistency error");
937 OverloadTys.push_back(Ty);
938
939 switch (D.getOverloadKind()) {
940 case IITDescriptor::AK_Any:
941 return false; // Success
942 case IITDescriptor::AK_AnyInteger:
943 return !Ty->isIntOrIntVectorTy();
944 case IITDescriptor::AK_AnyFloat:
945 return !Ty->isFPOrFPVectorTy();
946 case IITDescriptor::AK_AnyVector:
947 return !isa<VectorType>(Ty);
948 case IITDescriptor::AK_AnyPointer:
949 return !isa<PointerType>(Ty);
950 default:
951 break;
952 }
953 llvm_unreachable("all argument kinds not covered");
954
955 case IITDescriptor::Extend: {
956 // If this is a forward reference, defer the check for later.
957 if (D.getOverloadIndex() >= OverloadTys.size())
958 return IsDeferredCheck || DeferCheck(Ty);
959
960 Type *NewTy = OverloadTys[D.getOverloadIndex()]->getExtendedType();
961 return Ty != NewTy;
962 }
963 case IITDescriptor::Trunc: {
964 // If this is a forward reference, defer the check for later.
965 if (D.getOverloadIndex() >= OverloadTys.size())
966 return IsDeferredCheck || DeferCheck(Ty);
967
968 Type *NewTy = OverloadTys[D.getOverloadIndex()]->getTruncatedType();
969 return Ty != NewTy;
970 }
971 case IITDescriptor::OneNthEltsVec: {
972 // If this is a forward reference, defer the check for later.
973 if (D.getOverloadIndex() >= OverloadTys.size())
974 return IsDeferredCheck || DeferCheck(Ty);
975 auto *VTy = dyn_cast<VectorType>(OverloadTys[D.getOverloadIndex()]);
976 if (!VTy)
977 return true;
978 if (!VTy->getElementCount().isKnownMultipleOf(D.getVectorDivisor()))
979 return true;
980 return VectorType::getOneNthElementsVectorType(VTy, D.getVectorDivisor()) !=
981 Ty;
982 }
983 case IITDescriptor::SameVecWidth: {
984 if (D.getOverloadIndex() >= OverloadTys.size()) {
985 // Defer check and subsequent check for the vector element type.
986 Infos.consume_front();
987 return IsDeferredCheck || DeferCheck(Ty);
988 }
989 auto *ReferenceType =
990 dyn_cast<VectorType>(OverloadTys[D.getOverloadIndex()]);
991 auto *ThisArgType = dyn_cast<VectorType>(Ty);
992 // Both must be vectors of the same number of elements or neither.
993 if ((ReferenceType != nullptr) != (ThisArgType != nullptr))
994 return true;
995 Type *EltTy = Ty;
996 if (ThisArgType) {
997 if (ReferenceType->getElementCount() != ThisArgType->getElementCount())
998 return true;
999 EltTy = ThisArgType->getElementType();
1000 }
1001 return matchIntrinsicType(EltTy, Infos, OverloadTys, DeferredChecks,
1002 IsDeferredCheck);
1003 }
1004 case IITDescriptor::VecOfAnyPtrsToElt: {
1005 unsigned RefOverloadIndex = D.getRefOverloadIndex();
1006 if (RefOverloadIndex >= OverloadTys.size()) {
1007 if (IsDeferredCheck)
1008 return true;
1009 // If forward referencing, already add the pointer-vector type and
1010 // defer the checks for later.
1011 OverloadTys.push_back(Ty);
1012 return DeferCheck(Ty);
1013 }
1014
1015 if (!IsDeferredCheck) {
1016 assert(D.getOverloadIndex() == OverloadTys.size() &&
1017 "Table consistency error");
1018 OverloadTys.push_back(Ty);
1019 }
1020
1021 // Verify the overloaded type "matches" the Ref type.
1022 // i.e. Ty is a vector with the same width as Ref.
1023 // Composed of pointers to the same element type as Ref.
1024 auto *ReferenceType = dyn_cast<VectorType>(OverloadTys[RefOverloadIndex]);
1025 auto *ThisArgVecTy = dyn_cast<VectorType>(Ty);
1026 if (!ThisArgVecTy || !ReferenceType ||
1027 (ReferenceType->getElementCount() != ThisArgVecTy->getElementCount()))
1028 return true;
1029 return !ThisArgVecTy->getElementType()->isPointerTy();
1030 }
1031 case IITDescriptor::VecElement: {
1032 if (D.getOverloadIndex() >= OverloadTys.size())
1033 return IsDeferredCheck ? true : DeferCheck(Ty);
1034 auto *ReferenceType =
1035 dyn_cast<VectorType>(OverloadTys[D.getOverloadIndex()]);
1036 return !ReferenceType || Ty != ReferenceType->getElementType();
1037 }
1038 case IITDescriptor::Subdivide2:
1039 case IITDescriptor::Subdivide4: {
1040 // If this is a forward reference, defer the check for later.
1041 if (D.getOverloadIndex() >= OverloadTys.size())
1042 return IsDeferredCheck || DeferCheck(Ty);
1043
1044 Type *NewTy = OverloadTys[D.getOverloadIndex()];
1045 if (auto *VTy = dyn_cast<VectorType>(NewTy)) {
1046 int SubDivs = D.Kind == IITDescriptor::Subdivide2 ? 1 : 2;
1047 NewTy = VectorType::getSubdividedVectorType(VTy, SubDivs);
1048 return Ty != NewTy;
1049 }
1050 return true;
1051 }
1052 case IITDescriptor::VecOfBitcastsToInt: {
1053 if (D.getOverloadIndex() >= OverloadTys.size())
1054 return IsDeferredCheck || DeferCheck(Ty);
1055 auto *ReferenceType =
1056 dyn_cast<VectorType>(OverloadTys[D.getOverloadIndex()]);
1057 auto *ThisArgVecTy = dyn_cast<VectorType>(Ty);
1058 if (!ThisArgVecTy || !ReferenceType)
1059 return true;
1060 return ThisArgVecTy != VectorType::getInteger(ReferenceType);
1061 }
1062 case IITDescriptor::VarArg:
1063 // VarArg token should be consumed by `getIntrinsicInfoTableEntries`, so we
1064 // should never see it here.
1065 llvm_unreachable("IITDescriptor::VarArg not expected");
1066 }
1067 llvm_unreachable("unhandled");
1068}
1069
1070/// Return true if the function type \p FTy is a valid type signature for the
1071/// type constraints specified in the .td file, represented by \p Infos and
1072/// \p IsVarArg. The overloaded types for the intrinsic are pushed to the
1073/// \p OverloadTys vector.
1074///
1075/// If the type is not valid, returns false and prints an error message to
1076/// \p OS.
1079 unsigned NumArgs, bool IsVarArg,
1080 SmallVectorImpl<Type *> &OverloadTys,
1081 raw_ostream &OS) {
1083 if (matchIntrinsicType(FTy->getReturnType(), Infos, OverloadTys,
1084 DeferredChecks, false)) {
1085 OS << "intrinsic has incorrect return type!";
1086 return false;
1087 }
1088 unsigned NumDeferredReturnChecks = DeferredChecks.size();
1089
1090 if (FTy->getNumParams() != NumArgs) {
1091 OS << "intrinsic has incorrect number of args. Expected " << NumArgs
1092 << ", but got " << FTy->getNumParams();
1093 return false;
1094 }
1095
1096 for (Type *Ty : FTy->params()) {
1097 if (matchIntrinsicType(Ty, Infos, OverloadTys, DeferredChecks, false)) {
1098 OS << "intrinsic has incorrect argument type!";
1099 return false;
1100 }
1101 }
1102
1103 for (unsigned I = 0, E = DeferredChecks.size(); I != E; ++I) {
1104 DeferredIntrinsicMatchPair &Check = DeferredChecks[I];
1105 if (!matchIntrinsicType(Check.first, Check.second, OverloadTys,
1106 DeferredChecks, true))
1107 continue;
1108 if (I < NumDeferredReturnChecks)
1109 OS << "intrinsic has incorrect return type!";
1110 else
1111 OS << "intrinsic has incorrect argument type!";
1112 return false;
1113 }
1114
1115 if (!Infos.empty()) {
1116 OS << "intrinsic has too few arguments!";
1117 return false;
1118 }
1119
1120 if (FTy->isVarArg() != IsVarArg) {
1121 if (IsVarArg)
1122 OS << "intrinsic was not defined with variable arguments!";
1123 else
1124 OS << "intrinsic was defined with variable arguments!";
1125 return false;
1126 }
1127
1128 return true;
1129}
1130
1132 using namespace Intrinsic;
1135 return !Table.empty() && Table[0].Kind == IITDescriptor::Struct;
1136}
1137
1139 SmallVectorImpl<Type *> &OverloadTys,
1140 raw_ostream &OS) {
1141 if (!ID)
1142 return false;
1143
1145 auto [TableRef, NumArgs, IsVarArg] = getIntrinsicInfoTableEntries(ID, Table);
1146
1147 return ::isSignatureValid(FT, TableRef, NumArgs, IsVarArg, OverloadTys, OS);
1148}
1149
1151 SmallVectorImpl<Type *> &OverloadTys,
1152 raw_ostream &OS) {
1153 return isSignatureValid(F->getIntrinsicID(), F->getFunctionType(),
1154 OverloadTys, OS);
1155}
1156
1158 SmallVector<Type *, 4> OverloadTys;
1159 if (!isSignatureValid(F, OverloadTys))
1160 return std::nullopt;
1161
1162 Intrinsic::ID ID = F->getIntrinsicID();
1163 StringRef Name = F->getName();
1164 std::string WantedName =
1165 Intrinsic::getName(ID, OverloadTys, F->getParent(), F->getFunctionType());
1166 if (Name == WantedName)
1167 return std::nullopt;
1168
1169 Function *NewDecl = [&] {
1170 if (auto *ExistingGV = F->getParent()->getNamedValue(WantedName)) {
1171 if (auto *ExistingF = dyn_cast<Function>(ExistingGV))
1172 if (ExistingF->getFunctionType() == F->getFunctionType())
1173 return ExistingF;
1174
1175 // The name already exists, but is not a function or has the wrong
1176 // prototype. Make place for the new one by renaming the old version.
1177 // Either this old version will be removed later on or the module is
1178 // invalid and we'll get an error.
1179 ExistingGV->setName(WantedName + ".renamed");
1180 }
1181 return Intrinsic::getOrInsertDeclaration(F->getParent(), ID, OverloadTys);
1182 }();
1183
1184 NewDecl->setCallingConv(F->getCallingConv());
1185 assert(NewDecl->getFunctionType() == F->getFunctionType() &&
1186 "Shouldn't change the signature");
1187 return NewDecl;
1188}
1189
1193
1195 {Intrinsic::vector_interleave2, Intrinsic::vector_deinterleave2},
1196 {Intrinsic::vector_interleave3, Intrinsic::vector_deinterleave3},
1197 {Intrinsic::vector_interleave4, Intrinsic::vector_deinterleave4},
1198 {Intrinsic::vector_interleave5, Intrinsic::vector_deinterleave5},
1199 {Intrinsic::vector_interleave6, Intrinsic::vector_deinterleave6},
1200 {Intrinsic::vector_interleave7, Intrinsic::vector_deinterleave7},
1201 {Intrinsic::vector_interleave8, Intrinsic::vector_deinterleave8},
1202};
1203
1205 assert(Factor >= 2 && Factor <= 8 && "Unexpected factor");
1206 return InterleaveIntrinsics[Factor - 2].Interleave;
1207}
1208
1210 assert(Factor >= 2 && Factor <= 8 && "Unexpected factor");
1211 return InterleaveIntrinsics[Factor - 2].Deinterleave;
1212}
1213
1214#define GET_INTRINSIC_PRETTY_PRINT_ARGUMENTS
1215#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")
#define Check(C,...)
#define _
Module.h This file contains the declarations for the Module class.
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[]
static bool matchIntrinsicType(Type *Ty, ArrayRef< Intrinsic::IITDescriptor > &Infos, SmallVectorImpl< Type * > &OverloadTys, SmallVectorImpl< DeferredIntrinsicMatchPair > &DeferredChecks, bool IsDeferredCheck)
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)
std::pair< Type *, ArrayRef< Intrinsic::IITDescriptor > > DeferredIntrinsicMatchPair
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...
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
#define T
uint64_t High
This file contains the definitions of the enumerations and flags associated with NVVM Intrinsics,...
static StringRef getName(Value *V)
This file contains some functions that are useful when dealing with strings.
static SymbolRef::Type getType(const Symbol *Sym)
Definition TapiFile.cpp:39
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
Value * RHS
Value * LHS
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
iterator end() const
Definition ArrayRef.h:130
iterator begin() const
Definition ArrayRef.h:129
bool empty() const
Check if the array is empty.
Definition ArrayRef.h:136
const T & consume_front()
consume_front() - Returns the first element and drops it from ArrayRef.
Definition ArrayRef.h:156
Class to represent fixed width SIMD vectors.
unsigned getNumElements() const
static LLVM_ABI FixedVectorType * get(Type *ElementType, unsigned NumElts)
Definition Type.cpp:873
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.
Definition Function.h:211
const Function & getFunction() const
Definition Function.h:166
void setCallingConv(CallingConv::ID CC)
Definition Function.h:276
static LLVM_ABI IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Definition Type.cpp:354
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
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.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
static constexpr size_t npos
Definition StringRef.h:58
std::string str() const
Get the contents as an std::string.
Definition StringRef.h:222
constexpr size_t size() const
Get the string size.
Definition StringRef.h:144
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.
Definition Type.cpp:483
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.
Definition Type.cpp:978
Target - Wrapper for Target specific information.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
static LLVM_ABI Type * getX86_AMXTy(LLVMContext &C)
Definition Type.cpp:297
static LLVM_ABI Type * getMetadataTy(LLVMContext &C)
Definition Type.cpp:292
static LLVM_ABI Type * getTokenTy(LLVMContext &C)
Definition Type.cpp:293
static LLVM_ABI Type * getPPC_FP128Ty(LLVMContext &C)
Definition Type.cpp:296
static LLVM_ABI Type * getFP128Ty(LLVMContext &C)
Definition Type.cpp:295
@ X86_AMXTyID
AMX vectors (8192 bits, X86 specific)
Definition Type.h:67
@ HalfTyID
16-bit floating point type
Definition Type.h:57
@ VoidTyID
type with no size
Definition Type.h:64
@ FloatTyID
32-bit floating point type
Definition Type.h:59
@ IntegerTyID
Arbitrary bit width integers.
Definition Type.h:71
@ BFloatTyID
16-bit floating point type (7-bit significand)
Definition Type.h:58
@ DoubleTyID
64-bit floating point type
Definition Type.h:60
@ X86_FP80TyID
80-bit floating point type (X87)
Definition Type.h:61
@ PPC_FP128TyID
128-bit floating point type (two 64-bits, PowerPC)
Definition Type.h:63
@ MetadataTyID
Metadata.
Definition Type.h:66
@ ByteTyID
Arbitrary bit width bytes.
Definition Type.h:72
@ FP128TyID
128-bit floating point type (112-bit significand)
Definition Type.h:62
static LLVM_ABI Type * getVoidTy(LLVMContext &C)
Definition Type.cpp:286
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition Type.h:257
static LLVM_ABI Type * getDoubleTy(LLVMContext &C)
Definition Type.cpp:291
static LLVM_ABI Type * getFloatTy(LLVMContext &C)
Definition Type.cpp:290
static LLVM_ABI Type * getBFloatTy(LLVMContext &C)
Definition Type.cpp:289
static LLVM_ABI Type * getHalfTy(LLVMContext &C)
Definition Type.cpp:288
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.
Definition raw_ostream.h:53
#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.
Definition CallingConv.h:24
This namespace contains an enum with a value for every intrinsic/builtin function known by LLVM.
LLVM_ABI Intrinsic::ID getDeinterleaveIntrinsicID(unsigned Factor)
Returns the corresponding llvm.vector.deinterleaveN intrinsic for factor N.
LLVM_ABI Function * getDeclarationIfExists(const Module *M, ID id)
Look up the Function declaration of the intrinsic id in the Module M and return it if it exists.
LLVM_ABI std::optional< Function * > remangleIntrinsicFunction(Function *F)
LLVM_ABI bool hasConstrainedFPRoundingModeOperand(ID QID)
Returns true if the intrinsic ID is for one of the "ConstrainedFloating-Point Intrinsics" that take r...
LLVM_ABI StringRef getName(ID id)
Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
LLVM_ABI Function * getOrInsertDeclaration(Module *M, ID id, ArrayRef< Type * > OverloadTys={})
Look up the Function declaration of the intrinsic id in the Module M.
LLVM_ABI bool isConstrainedFPIntrinsic(ID QID)
Returns true if the intrinsic ID is for one of the "ConstrainedFloating-Point Intrinsics".
LLVM_ABI ID lookupIntrinsicID(StringRef Name)
This does the actual lookup of an intrinsic ID which matches the given function name.
LLVM_ABI bool hasPrettyPrintedArgs(ID id)
Returns true if the intrinsic has pretty printed immediate arguments.
LLVM_ABI std::tuple< ArrayRef< IITDescriptor >, unsigned, bool > getIntrinsicInfoTableEntries(ID id, SmallVectorImpl< IITDescriptor > &T)
Fill the IIT table descriptor for the intrinsic id into an array of IITDescriptors.
LLVM_ABI StringRef getBaseName(ID id)
Return the LLVM name for an intrinsic, without encoded types for overloading, such as "llvm....
LLVM_ABI Intrinsic::ID getInterleaveIntrinsicID(unsigned Factor)
Returns the corresponding llvm.vector.interleaveN intrinsic for factor N.
LLVM_ABI bool isOverloaded(ID id)
Returns true if the intrinsic can be overloaded.
LLVM_ABI FunctionType * getType(LLVMContext &Context, ID id, ArrayRef< Type * > OverloadTys={})
Return the function type for an intrinsic.
LLVM_ABI bool isSignatureValid(Intrinsic::ID ID, FunctionType *FT, SmallVectorImpl< Type * > &OverloadTys, raw_ostream &OS=nulls())
Returns true if FT is a valid function type for intrinsic ID.
LLVM_ABI bool hasStructReturnType(ID id)
Returns true if id has a struct return type.
LLVM_ABI bool isTriviallyScalarizable(ID id)
Returns true if the intrinsic is trivially scalarizable.
LLVM_ABI bool isTargetIntrinsic(ID IID)
isTargetIntrinsic - Returns true if IID is an intrinsic specific to a certain target.
LLVM_ABI std::string getNameNoUnnamedTypes(ID Id, ArrayRef< Type * > OverloadTys)
Return the LLVM name for an intrinsic.
This is an optimization pass for GlobalISel generic memory operations.
@ Low
Lower the current thread's priority such that it does not affect foreground tasks significantly.
Definition Threading.h:280
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
auto partition_point(R &&Range, Predicate P)
Binary search for the first iterator in a range where a predicate is false.
Definition STLExtras.h:2128
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.
Definition STLExtras.h:1745
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...
Definition Casting.h:547
ArrayRef(const T &OneElt) -> ArrayRef< T >
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
constexpr detail::IsaCheckPredicate< Types... > IsaPred
Function object wrapper for the llvm::isa type check.
Definition Casting.h:866
#define N
Intrinsic::ID Interleave
Intrinsic::ID Deinterleave