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