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 void
206DecodeIITType(unsigned &NextElt, ArrayRef<unsigned char> Infos,
207 IIT_Info LastInfo,
209 using namespace Intrinsic;
210
211 bool IsScalableVector = LastInfo == IIT_SCALABLE_VEC;
212
213 IIT_Info Info = IIT_Info(Infos[NextElt++]);
214
215 switch (Info) {
216 case IIT_Done:
217 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Void, 0));
218 return;
219 case IIT_VARARG:
220 OutputTable.push_back(IITDescriptor::get(IITDescriptor::VarArg, 0));
221 return;
222 case IIT_MMX:
223 OutputTable.push_back(IITDescriptor::get(IITDescriptor::MMX, 0));
224 return;
225 case IIT_AMX:
226 OutputTable.push_back(IITDescriptor::get(IITDescriptor::AMX, 0));
227 return;
228 case IIT_TOKEN:
229 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Token, 0));
230 return;
231 case IIT_METADATA:
232 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Metadata, 0));
233 return;
234 case IIT_F16:
235 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Half, 0));
236 return;
237 case IIT_BF16:
238 OutputTable.push_back(IITDescriptor::get(IITDescriptor::BFloat, 0));
239 return;
240 case IIT_F32:
241 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Float, 0));
242 return;
243 case IIT_F64:
244 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Double, 0));
245 return;
246 case IIT_F128:
247 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Quad, 0));
248 return;
249 case IIT_PPCF128:
250 OutputTable.push_back(IITDescriptor::get(IITDescriptor::PPCQuad, 0));
251 return;
252 case IIT_I1:
253 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 1));
254 return;
255 case IIT_I2:
256 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 2));
257 return;
258 case IIT_I4:
259 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 4));
260 return;
261 case IIT_AARCH64_SVCOUNT:
262 OutputTable.push_back(IITDescriptor::get(IITDescriptor::AArch64Svcount, 0));
263 return;
264 case IIT_I8:
265 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 8));
266 return;
267 case IIT_I16:
268 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 16));
269 return;
270 case IIT_I32:
271 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 32));
272 return;
273 case IIT_I64:
274 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 64));
275 return;
276 case IIT_I128:
277 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 128));
278 return;
279 case IIT_V1:
280 OutputTable.push_back(IITDescriptor::getVector(1, IsScalableVector));
281 DecodeIITType(NextElt, Infos, Info, OutputTable);
282 return;
283 case IIT_V2:
284 OutputTable.push_back(IITDescriptor::getVector(2, IsScalableVector));
285 DecodeIITType(NextElt, Infos, Info, OutputTable);
286 return;
287 case IIT_V3:
288 OutputTable.push_back(IITDescriptor::getVector(3, IsScalableVector));
289 DecodeIITType(NextElt, Infos, Info, OutputTable);
290 return;
291 case IIT_V4:
292 OutputTable.push_back(IITDescriptor::getVector(4, IsScalableVector));
293 DecodeIITType(NextElt, Infos, Info, OutputTable);
294 return;
295 case IIT_V6:
296 OutputTable.push_back(IITDescriptor::getVector(6, IsScalableVector));
297 DecodeIITType(NextElt, Infos, Info, OutputTable);
298 return;
299 case IIT_V8:
300 OutputTable.push_back(IITDescriptor::getVector(8, IsScalableVector));
301 DecodeIITType(NextElt, Infos, Info, OutputTable);
302 return;
303 case IIT_V10:
304 OutputTable.push_back(IITDescriptor::getVector(10, IsScalableVector));
305 DecodeIITType(NextElt, Infos, Info, OutputTable);
306 return;
307 case IIT_V16:
308 OutputTable.push_back(IITDescriptor::getVector(16, IsScalableVector));
309 DecodeIITType(NextElt, Infos, Info, OutputTable);
310 return;
311 case IIT_V32:
312 OutputTable.push_back(IITDescriptor::getVector(32, IsScalableVector));
313 DecodeIITType(NextElt, Infos, Info, OutputTable);
314 return;
315 case IIT_V64:
316 OutputTable.push_back(IITDescriptor::getVector(64, IsScalableVector));
317 DecodeIITType(NextElt, Infos, Info, OutputTable);
318 return;
319 case IIT_V128:
320 OutputTable.push_back(IITDescriptor::getVector(128, IsScalableVector));
321 DecodeIITType(NextElt, Infos, Info, OutputTable);
322 return;
323 case IIT_V256:
324 OutputTable.push_back(IITDescriptor::getVector(256, IsScalableVector));
325 DecodeIITType(NextElt, Infos, Info, OutputTable);
326 return;
327 case IIT_V512:
328 OutputTable.push_back(IITDescriptor::getVector(512, IsScalableVector));
329 DecodeIITType(NextElt, Infos, Info, OutputTable);
330 return;
331 case IIT_V1024:
332 OutputTable.push_back(IITDescriptor::getVector(1024, IsScalableVector));
333 DecodeIITType(NextElt, Infos, Info, OutputTable);
334 return;
335 case IIT_V2048:
336 OutputTable.push_back(IITDescriptor::getVector(2048, IsScalableVector));
337 DecodeIITType(NextElt, Infos, Info, OutputTable);
338 return;
339 case IIT_V4096:
340 OutputTable.push_back(IITDescriptor::getVector(4096, IsScalableVector));
341 DecodeIITType(NextElt, Infos, Info, OutputTable);
342 return;
343 case IIT_EXTERNREF:
344 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Pointer, 10));
345 return;
346 case IIT_FUNCREF:
347 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Pointer, 20));
348 return;
349 case IIT_PTR:
350 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Pointer, 0));
351 return;
352 case IIT_PTR_AS: // pointer with address space.
353 OutputTable.push_back(
354 IITDescriptor::get(IITDescriptor::Pointer, Infos[NextElt++]));
355 return;
356 case IIT_ANY: {
357 unsigned OverloadInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
358 OutputTable.push_back(
359 IITDescriptor::get(IITDescriptor::Overloaded, OverloadInfo));
360 return;
361 }
362 case IIT_EXTEND_ARG: {
363 unsigned OverloadIndex = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
364 OutputTable.push_back(
365 IITDescriptor::get(IITDescriptor::Extend, OverloadIndex));
366 return;
367 }
368 case IIT_TRUNC_ARG: {
369 unsigned OverloadIndex = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
370 OutputTable.push_back(
371 IITDescriptor::get(IITDescriptor::Trunc, OverloadIndex));
372 return;
373 }
374 case IIT_ONE_NTH_ELTS_VEC_ARG: {
375 unsigned short OverloadIndex =
376 (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
377 unsigned short N = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
378 OutputTable.push_back(IITDescriptor::get(IITDescriptor::OneNthEltsVec,
379 /*Hi=*/N, /*Lo=*/OverloadIndex));
380 return;
381 }
382 case IIT_SAME_VEC_WIDTH_ARG: {
383 unsigned OverloadIndex = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
384 OutputTable.push_back(
385 IITDescriptor::get(IITDescriptor::SameVecWidth, OverloadIndex));
386 return;
387 }
388 case IIT_VEC_OF_ANYPTRS_TO_ELT: {
389 unsigned short OverloadIndex =
390 (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
391 unsigned short RefOverloadIndex =
392 (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
393 OutputTable.push_back(IITDescriptor::get(IITDescriptor::VecOfAnyPtrsToElt,
394 /*Hi=*/RefOverloadIndex,
395 /*Lo=*/OverloadIndex));
396 return;
397 }
398 case IIT_EMPTYSTRUCT:
399 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Struct, 0));
400 return;
401 case IIT_STRUCT: {
402 unsigned StructElts = Infos[NextElt++] + 2;
403
404 OutputTable.push_back(
405 IITDescriptor::get(IITDescriptor::Struct, StructElts));
406
407 for (unsigned i = 0; i != StructElts; ++i)
408 DecodeIITType(NextElt, Infos, Info, OutputTable);
409 return;
410 }
411 case IIT_SUBDIVIDE2_ARG: {
412 unsigned OverloadIndex = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
413 OutputTable.push_back(
414 IITDescriptor::get(IITDescriptor::Subdivide2, OverloadIndex));
415 return;
416 }
417 case IIT_SUBDIVIDE4_ARG: {
418 unsigned OverloadIndex = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
419 OutputTable.push_back(
420 IITDescriptor::get(IITDescriptor::Subdivide4, OverloadIndex));
421 return;
422 }
423 case IIT_VEC_ELEMENT: {
424 unsigned OverloadIndex = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
425 OutputTable.push_back(
426 IITDescriptor::get(IITDescriptor::VecElement, OverloadIndex));
427 return;
428 }
429 case IIT_SCALABLE_VEC: {
430 DecodeIITType(NextElt, Infos, Info, OutputTable);
431 return;
432 }
433 case IIT_VEC_OF_BITCASTS_TO_INT: {
434 unsigned OverloadIndex = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
435 OutputTable.push_back(
436 IITDescriptor::get(IITDescriptor::VecOfBitcastsToInt, OverloadIndex));
437 return;
438 }
439 }
440 llvm_unreachable("unhandled");
441}
442
443#define GET_INTRINSIC_GENERATOR_GLOBAL
444#include "llvm/IR/IntrinsicImpl.inc"
445
448 // Note that `FixedEncodingTy` is defined in IntrinsicImpl.inc and can be
449 // uint16_t or uint32_t based on the the value of `Use16BitFixedEncoding` in
450 // IntrinsicEmitter.cpp.
451 constexpr unsigned FixedEncodingBits = sizeof(FixedEncodingTy) * CHAR_BIT;
452 constexpr unsigned MSBPosition = FixedEncodingBits - 1;
453 // Mask with all bits 1 except the most significant bit.
454 constexpr unsigned Mask = (1U << MSBPosition) - 1;
455
456 FixedEncodingTy TableVal = IIT_Table[id - 1];
457
458 // Array to hold the inlined fixed encoding values expanded from nibbles to
459 // bytes. Its size can be be atmost FixedEncodingBits / 4 i.e., number
460 // of nibbles that can fit in `FixedEncodingTy`.
461 unsigned char IITValues[FixedEncodingBits / 4];
462
463 ArrayRef<unsigned char> IITEntries;
464 unsigned NextElt = 0;
465 // Check to see if the intrinsic's type was inlined in the fixed encoding
466 // table.
467 if (TableVal >> MSBPosition) {
468 // This is an offset into the IIT_LongEncodingTable.
469 IITEntries = IIT_LongEncodingTable;
470
471 // Strip sentinel bit.
472 NextElt = TableVal & Mask;
473 } else {
474 // If the entry was encoded into a single word in the table itself, decode
475 // it from an array of nibbles to an array of bytes.
476 do {
477 IITValues[NextElt++] = TableVal & 0xF;
478 TableVal >>= 4;
479 } while (TableVal);
480
481 IITEntries = ArrayRef(IITValues).take_front(NextElt);
482 NextElt = 0;
483 }
484
485 // Okay, decode the table into the output vector of IITDescriptors.
486 DecodeIITType(NextElt, IITEntries, IIT_Done, T);
487 while (NextElt != IITEntries.size() && IITEntries[NextElt] != 0)
488 DecodeIITType(NextElt, IITEntries, IIT_Done, T);
489}
490
492 ArrayRef<Type *> OverloadTys,
493 LLVMContext &Context) {
494 using namespace Intrinsic;
495
496 IITDescriptor D = Infos.front();
497 Infos = Infos.slice(1);
498
499 switch (D.Kind) {
500 case IITDescriptor::Void:
501 return Type::getVoidTy(Context);
502 case IITDescriptor::VarArg:
503 return Type::getVoidTy(Context);
504 case IITDescriptor::MMX:
506 case IITDescriptor::AMX:
507 return Type::getX86_AMXTy(Context);
508 case IITDescriptor::Token:
509 return Type::getTokenTy(Context);
510 case IITDescriptor::Metadata:
511 return Type::getMetadataTy(Context);
512 case IITDescriptor::Half:
513 return Type::getHalfTy(Context);
514 case IITDescriptor::BFloat:
515 return Type::getBFloatTy(Context);
516 case IITDescriptor::Float:
517 return Type::getFloatTy(Context);
518 case IITDescriptor::Double:
519 return Type::getDoubleTy(Context);
520 case IITDescriptor::Quad:
521 return Type::getFP128Ty(Context);
522 case IITDescriptor::PPCQuad:
523 return Type::getPPC_FP128Ty(Context);
524 case IITDescriptor::AArch64Svcount:
525 return TargetExtType::get(Context, "aarch64.svcount");
526
527 case IITDescriptor::Integer:
528 return IntegerType::get(Context, D.IntegerWidth);
529 case IITDescriptor::Vector:
530 return VectorType::get(DecodeFixedType(Infos, OverloadTys, Context),
531 D.VectorWidth);
532 case IITDescriptor::Pointer:
533 return PointerType::get(Context, D.PointerAddressSpace);
534 case IITDescriptor::Struct: {
536 for (unsigned i = 0, e = D.StructNumElements; i != e; ++i)
537 Elts.push_back(DecodeFixedType(Infos, OverloadTys, Context));
538 return StructType::get(Context, Elts);
539 }
540 // For any overload kind or partially dependent type, substitute it with the
541 // corresponding concrete type from OverloadTys.
542 case IITDescriptor::Overloaded:
543 case IITDescriptor::VecOfAnyPtrsToElt:
544 return OverloadTys[D.getOverloadIndex()];
545 case IITDescriptor::Extend: {
546 Type *Ty = OverloadTys[D.getOverloadIndex()];
547 if (VectorType *VTy = dyn_cast<VectorType>(Ty))
549
550 return IntegerType::get(Context, 2 * cast<IntegerType>(Ty)->getBitWidth());
551 }
552 case IITDescriptor::Trunc: {
553 Type *Ty = OverloadTys[D.getOverloadIndex()];
554 if (VectorType *VTy = dyn_cast<VectorType>(Ty))
556
558 assert(ITy->getBitWidth() % 2 == 0);
559 return IntegerType::get(Context, ITy->getBitWidth() / 2);
560 }
561 case IITDescriptor::Subdivide2:
562 case IITDescriptor::Subdivide4: {
563 Type *Ty = OverloadTys[D.getOverloadIndex()];
565 assert(VTy && "Expected overload type to be a Vector Type");
566 int SubDivs = D.Kind == IITDescriptor::Subdivide2 ? 1 : 2;
567 return VectorType::getSubdividedVectorType(VTy, SubDivs);
568 }
569 case IITDescriptor::OneNthEltsVec:
571 cast<VectorType>(OverloadTys[D.getOverloadIndex()]),
572 D.getVectorDivisor());
573 case IITDescriptor::SameVecWidth: {
574 Type *EltTy = DecodeFixedType(Infos, OverloadTys, Context);
575 Type *Ty = OverloadTys[D.getOverloadIndex()];
576 if (auto *VTy = dyn_cast<VectorType>(Ty))
577 return VectorType::get(EltTy, VTy->getElementCount());
578 return EltTy;
579 }
580 case IITDescriptor::VecElement: {
581 Type *Ty = OverloadTys[D.getOverloadIndex()];
582 if (VectorType *VTy = dyn_cast<VectorType>(Ty))
583 return VTy->getElementType();
584 llvm_unreachable("Expected overload type to be a Vector Type");
585 }
586 case IITDescriptor::VecOfBitcastsToInt: {
587 Type *Ty = OverloadTys[D.getOverloadIndex()];
589 assert(VTy && "Expected overload type to be a Vector Type");
590 return VectorType::getInteger(VTy);
591 }
592 }
593 llvm_unreachable("unhandled");
594}
595
597 ArrayRef<Type *> OverloadTys) {
600
602 Type *ResultTy = DecodeFixedType(TableRef, OverloadTys, Context);
603
605 while (!TableRef.empty())
606 ArgTys.push_back(DecodeFixedType(TableRef, OverloadTys, Context));
607
608 // VarArg intrinsics encode a void type as the last argument type. Detect that
609 // and then drop the void argument.
610 bool IsVarArg = false;
611 if (!ArgTys.empty() && ArgTys.back()->isVoidTy()) {
612 ArgTys.pop_back();
613 IsVarArg = true;
614 }
615 return FunctionType::get(ResultTy, ArgTys, IsVarArg);
616}
617
619#define GET_INTRINSIC_OVERLOAD_TABLE
620#include "llvm/IR/IntrinsicImpl.inc"
621}
622
624#define GET_INTRINSIC_PRETTY_PRINT_TABLE
625#include "llvm/IR/IntrinsicImpl.inc"
626}
627
628/// Table of per-target intrinsic name tables.
629#define GET_INTRINSIC_TARGET_DATA
630#include "llvm/IR/IntrinsicImpl.inc"
631
633 return IID > TargetInfos[0].Count;
634}
635
636/// Looks up Name in NameTable via binary search. NameTable must be sorted
637/// and all entries must start with "llvm.". If NameTable contains an exact
638/// match for Name or a prefix of Name followed by a dot, its index in
639/// NameTable is returned. Otherwise, -1 is returned.
641 StringRef Name, StringRef Target = "") {
642 assert(Name.starts_with("llvm.") && "Unexpected intrinsic prefix");
643 assert(Name.drop_front(5).starts_with(Target) && "Unexpected target");
644
645 // Do successive binary searches of the dotted name components. For
646 // "llvm.gc.experimental.statepoint.p1i8.p1i32", we will find the range of
647 // intrinsics starting with "llvm.gc", then "llvm.gc.experimental", then
648 // "llvm.gc.experimental.statepoint", and then we will stop as the range is
649 // size 1. During the search, we can skip the prefix that we already know is
650 // identical. By using strncmp we consider names with differing suffixes to
651 // be part of the equal range.
652 size_t CmpEnd = 4; // Skip the "llvm" component.
653 if (!Target.empty())
654 CmpEnd += 1 + Target.size(); // skip the .target component.
655
656 const unsigned *Low = NameOffsetTable.begin();
657 const unsigned *High = NameOffsetTable.end();
658 const unsigned *LastLow = Low;
659 while (CmpEnd < Name.size() && High - Low > 0) {
660 size_t CmpStart = CmpEnd;
661 CmpEnd = Name.find('.', CmpStart + 1);
662 CmpEnd = CmpEnd == StringRef::npos ? Name.size() : CmpEnd;
663 auto Cmp = [CmpStart, CmpEnd](auto LHS, auto RHS) {
664 // `equal_range` requires the comparison to work with either side being an
665 // offset or the value. Detect which kind each side is to set up the
666 // compared strings.
667 const char *LHSStr;
668 if constexpr (std::is_integral_v<decltype(LHS)>)
669 LHSStr = IntrinsicNameTable.getCString(LHS);
670 else
671 LHSStr = LHS;
672
673 const char *RHSStr;
674 if constexpr (std::is_integral_v<decltype(RHS)>)
675 RHSStr = IntrinsicNameTable.getCString(RHS);
676 else
677 RHSStr = RHS;
678
679 return strncmp(LHSStr + CmpStart, RHSStr + CmpStart, CmpEnd - CmpStart) <
680 0;
681 };
682 LastLow = Low;
683 std::tie(Low, High) = std::equal_range(Low, High, Name.data(), Cmp);
684 }
685 if (High - Low > 0)
686 LastLow = Low;
687
688 if (LastLow == NameOffsetTable.end())
689 return -1;
690 StringRef NameFound = IntrinsicNameTable[*LastLow];
691 if (Name == NameFound ||
692 (Name.starts_with(NameFound) && Name[NameFound.size()] == '.'))
693 return LastLow - NameOffsetTable.begin();
694 return -1;
695}
696
697/// Find the segment of \c IntrinsicNameOffsetTable for intrinsics with the same
698/// target as \c Name, or the generic table if \c Name is not target specific.
699///
700/// Returns the relevant slice of \c IntrinsicNameOffsetTable and the target
701/// name.
702static std::pair<ArrayRef<unsigned>, StringRef>
704 assert(Name.starts_with("llvm."));
705
706 ArrayRef<IntrinsicTargetInfo> Targets(TargetInfos);
707 // Drop "llvm." and take the first dotted component. That will be the target
708 // if this is target specific.
709 StringRef Target = Name.drop_front(5).split('.').first;
710 auto It = partition_point(
711 Targets, [=](const IntrinsicTargetInfo &TI) { return TI.Name < Target; });
712 // We've either found the target or just fall back to the generic set, which
713 // is always first.
714 const auto &TI = It != Targets.end() && It->Name == Target ? *It : Targets[0];
715 return {ArrayRef(&IntrinsicNameOffsetTable[1] + TI.Offset, TI.Count),
716 TI.Name};
717}
718
719/// This does the actual lookup of an intrinsic ID which matches the given
720/// function name.
722 auto [NameOffsetTable, Target] = findTargetSubtable(Name);
723 int Idx = lookupLLVMIntrinsicByName(NameOffsetTable, Name, Target);
724 if (Idx == -1)
726
727 // Intrinsic IDs correspond to the location in IntrinsicNameTable, but we have
728 // an index into a sub-table.
729 int Adjust = NameOffsetTable.data() - IntrinsicNameOffsetTable;
730 Intrinsic::ID ID = static_cast<Intrinsic::ID>(Idx + Adjust);
731
732 // If the intrinsic is not overloaded, require an exact match. If it is
733 // overloaded, require either exact or prefix match.
734 const auto MatchSize = IntrinsicNameTable[NameOffsetTable[Idx]].size();
735 assert(Name.size() >= MatchSize && "Expected either exact or prefix match");
736 bool IsExactMatch = Name.size() == MatchSize;
737 return IsExactMatch || Intrinsic::isOverloaded(ID) ? ID
739}
740
741/// This defines the "Intrinsic::getAttributes(ID id)" method.
742#define GET_INTRINSIC_ATTRIBUTES
743#include "llvm/IR/IntrinsicImpl.inc"
744
745static Function *
747 ArrayRef<Type *> OverloadTys,
748 FunctionType *FT) {
749 std::string Name = OverloadTys.empty()
750 ? Intrinsic::getName(id).str()
751 : Intrinsic::getName(id, OverloadTys, M, FT);
752 Function *F = cast<Function>(M->getOrInsertFunction(Name, FT).getCallee());
753 if (F->getFunctionType() == FT)
754 return F;
755
756 // It's possible that a declaration for this intrinsic already exists with an
757 // incorrect signature, if the signature has changed, but this particular
758 // declaration has not been auto-upgraded yet. In that case, rename the
759 // invalid declaration and insert a new one with the correct signature. The
760 // invalid declaration will get upgraded later.
761 F->setName(F->getName() + ".invalid");
762 return cast<Function>(M->getOrInsertFunction(Name, FT).getCallee());
763}
764
766 ArrayRef<Type *> OverloadTys) {
767 // There can never be multiple globals with the same name of different types,
768 // because intrinsics must be a specific type.
769 FunctionType *FT = getType(M->getContext(), id, OverloadTys);
770 return getOrInsertIntrinsicDeclarationImpl(M, id, OverloadTys, FT);
771}
772
774 ArrayRef<Type *> ArgTys) {
775 // If the intrinsic is not overloaded, use the non-overloaded version.
777 return getOrInsertDeclaration(M, id);
778
779 // Get the intrinsic signature metadata.
783
784 FunctionType *FTy = FunctionType::get(RetTy, ArgTys, /*isVarArg=*/false);
785
786 // Automatically determine the overloaded types.
787 SmallVector<Type *, 4> OverloadTys;
788 [[maybe_unused]] Intrinsic::MatchIntrinsicTypesResult Res =
789 matchIntrinsicSignature(FTy, TableRef, OverloadTys);
791 "intrinsic signature mismatch");
792
793 // If intrinsic requires vararg, recreate the FunctionType accordingly.
794 if (!matchIntrinsicVarArg(/*isVarArg=*/true, TableRef))
795 FTy = FunctionType::get(RetTy, ArgTys, /*isVarArg=*/true);
796
797 assert(TableRef.empty() && "Unprocessed descriptors remain");
798
799 return getOrInsertIntrinsicDeclarationImpl(M, id, OverloadTys, FTy);
800}
801
803 return M->getFunction(getName(id));
804}
805
807 ArrayRef<Type *> OverloadTys,
808 FunctionType *FT) {
809 return M->getFunction(getName(id, OverloadTys, M, FT));
810}
811
812// This defines the "Intrinsic::getIntrinsicForClangBuiltin()" method.
813#define GET_LLVM_INTRINSIC_FOR_CLANG_BUILTIN
814#include "llvm/IR/IntrinsicImpl.inc"
815
816// This defines the "Intrinsic::getIntrinsicForMSBuiltin()" method.
817#define GET_LLVM_INTRINSIC_FOR_MS_BUILTIN
818#include "llvm/IR/IntrinsicImpl.inc"
819
821 switch (QID) {
822#define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC) \
823 case Intrinsic::INTRINSIC:
824#include "llvm/IR/ConstrainedOps.def"
825#undef INSTRUCTION
826 return true;
827 default:
828 return false;
829 }
830}
831
833 switch (QID) {
834#define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC) \
835 case Intrinsic::INTRINSIC: \
836 return ROUND_MODE == 1;
837#include "llvm/IR/ConstrainedOps.def"
838#undef INSTRUCTION
839 default:
840 return false;
841 }
842}
843
845 std::pair<Type *, ArrayRef<Intrinsic::IITDescriptor>>;
846
847static bool
849 SmallVectorImpl<Type *> &OverloadTys,
851 bool IsDeferredCheck) {
852 using namespace Intrinsic;
853
854 // If we ran out of descriptors, there are too many arguments.
855 if (Infos.empty())
856 return true;
857
858 // Do this before slicing off the 'front' part
859 auto InfosRef = Infos;
860 auto DeferCheck = [&DeferredChecks, &InfosRef](Type *T) {
861 DeferredChecks.emplace_back(T, InfosRef);
862 return false;
863 };
864
865 IITDescriptor D = Infos.front();
866 Infos = Infos.slice(1);
867
868 switch (D.Kind) {
869 case IITDescriptor::Void:
870 return !Ty->isVoidTy();
871 case IITDescriptor::VarArg:
872 return true;
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()];
961 if (VectorType *VTy = dyn_cast<VectorType>(NewTy))
963 else if (IntegerType *ITy = dyn_cast<IntegerType>(NewTy))
964 NewTy = IntegerType::get(ITy->getContext(), 2 * ITy->getBitWidth());
965 else
966 return true;
967
968 return Ty != NewTy;
969 }
970 case IITDescriptor::Trunc: {
971 // If this is a forward reference, defer the check for later.
972 if (D.getOverloadIndex() >= OverloadTys.size())
973 return IsDeferredCheck || DeferCheck(Ty);
974
975 Type *NewTy = OverloadTys[D.getOverloadIndex()];
976 if (VectorType *VTy = dyn_cast<VectorType>(NewTy))
978 else if (IntegerType *ITy = dyn_cast<IntegerType>(NewTy))
979 NewTy = IntegerType::get(ITy->getContext(), ITy->getBitWidth() / 2);
980 else
981 return true;
982
983 return Ty != NewTy;
984 }
985 case IITDescriptor::OneNthEltsVec: {
986 // If this is a forward reference, defer the check for later.
987 if (D.getOverloadIndex() >= OverloadTys.size())
988 return IsDeferredCheck || DeferCheck(Ty);
989 auto *VTy = dyn_cast<VectorType>(OverloadTys[D.getOverloadIndex()]);
990 if (!VTy)
991 return true;
992 if (!VTy->getElementCount().isKnownMultipleOf(D.getVectorDivisor()))
993 return true;
994 return VectorType::getOneNthElementsVectorType(VTy, D.getVectorDivisor()) !=
995 Ty;
996 }
997 case IITDescriptor::SameVecWidth: {
998 if (D.getOverloadIndex() >= OverloadTys.size()) {
999 // Defer check and subsequent check for the vector element type.
1000 Infos = Infos.slice(1);
1001 return IsDeferredCheck || DeferCheck(Ty);
1002 }
1003 auto *ReferenceType =
1004 dyn_cast<VectorType>(OverloadTys[D.getOverloadIndex()]);
1005 auto *ThisArgType = dyn_cast<VectorType>(Ty);
1006 // Both must be vectors of the same number of elements or neither.
1007 if ((ReferenceType != nullptr) != (ThisArgType != nullptr))
1008 return true;
1009 Type *EltTy = Ty;
1010 if (ThisArgType) {
1011 if (ReferenceType->getElementCount() != ThisArgType->getElementCount())
1012 return true;
1013 EltTy = ThisArgType->getElementType();
1014 }
1015 return matchIntrinsicType(EltTy, Infos, OverloadTys, DeferredChecks,
1016 IsDeferredCheck);
1017 }
1018 case IITDescriptor::VecOfAnyPtrsToElt: {
1019 unsigned RefOverloadIndex = D.getRefOverloadIndex();
1020 if (RefOverloadIndex >= OverloadTys.size()) {
1021 if (IsDeferredCheck)
1022 return true;
1023 // If forward referencing, already add the pointer-vector type and
1024 // defer the checks for later.
1025 OverloadTys.push_back(Ty);
1026 return DeferCheck(Ty);
1027 }
1028
1029 if (!IsDeferredCheck) {
1030 assert(D.getOverloadIndex() == OverloadTys.size() &&
1031 "Table consistency error");
1032 OverloadTys.push_back(Ty);
1033 }
1034
1035 // Verify the overloaded type "matches" the Ref type.
1036 // i.e. Ty is a vector with the same width as Ref.
1037 // Composed of pointers to the same element type as Ref.
1038 auto *ReferenceType = dyn_cast<VectorType>(OverloadTys[RefOverloadIndex]);
1039 auto *ThisArgVecTy = dyn_cast<VectorType>(Ty);
1040 if (!ThisArgVecTy || !ReferenceType ||
1041 (ReferenceType->getElementCount() != ThisArgVecTy->getElementCount()))
1042 return true;
1043 return !ThisArgVecTy->getElementType()->isPointerTy();
1044 }
1045 case IITDescriptor::VecElement: {
1046 if (D.getOverloadIndex() >= OverloadTys.size())
1047 return IsDeferredCheck ? true : DeferCheck(Ty);
1048 auto *ReferenceType =
1049 dyn_cast<VectorType>(OverloadTys[D.getOverloadIndex()]);
1050 return !ReferenceType || Ty != ReferenceType->getElementType();
1051 }
1052 case IITDescriptor::Subdivide2:
1053 case IITDescriptor::Subdivide4: {
1054 // If this is a forward reference, defer the check for later.
1055 if (D.getOverloadIndex() >= OverloadTys.size())
1056 return IsDeferredCheck || DeferCheck(Ty);
1057
1058 Type *NewTy = OverloadTys[D.getOverloadIndex()];
1059 if (auto *VTy = dyn_cast<VectorType>(NewTy)) {
1060 int SubDivs = D.Kind == IITDescriptor::Subdivide2 ? 1 : 2;
1061 NewTy = VectorType::getSubdividedVectorType(VTy, SubDivs);
1062 return Ty != NewTy;
1063 }
1064 return true;
1065 }
1066 case IITDescriptor::VecOfBitcastsToInt: {
1067 if (D.getOverloadIndex() >= OverloadTys.size())
1068 return IsDeferredCheck || DeferCheck(Ty);
1069 auto *ReferenceType =
1070 dyn_cast<VectorType>(OverloadTys[D.getOverloadIndex()]);
1071 auto *ThisArgVecTy = dyn_cast<VectorType>(Ty);
1072 if (!ThisArgVecTy || !ReferenceType)
1073 return true;
1074 return ThisArgVecTy != VectorType::getInteger(ReferenceType);
1075 }
1076 }
1077 llvm_unreachable("unhandled");
1078}
1079
1083 SmallVectorImpl<Type *> &OverloadTys) {
1085 if (matchIntrinsicType(FTy->getReturnType(), Infos, OverloadTys,
1086 DeferredChecks, false))
1088
1089 unsigned NumDeferredReturnChecks = DeferredChecks.size();
1090
1091 for (auto *Ty : FTy->params())
1092 if (matchIntrinsicType(Ty, Infos, OverloadTys, DeferredChecks, false))
1094
1095 for (unsigned I = 0, E = DeferredChecks.size(); I != E; ++I) {
1096 DeferredIntrinsicMatchPair &Check = DeferredChecks[I];
1097 if (matchIntrinsicType(Check.first, Check.second, OverloadTys,
1098 DeferredChecks, true))
1099 return I < NumDeferredReturnChecks ? MatchIntrinsicTypes_NoMatchRet
1101 }
1102
1104}
1105
1107 bool isVarArg, ArrayRef<Intrinsic::IITDescriptor> &Infos) {
1108 // If there are no descriptors left, then it can't be a vararg.
1109 if (Infos.empty())
1110 return isVarArg;
1111
1112 // There should be only one descriptor remaining at this point.
1113 if (Infos.size() != 1)
1114 return true;
1115
1116 // Check and verify the descriptor.
1117 IITDescriptor D = Infos.front();
1118 Infos = Infos.slice(1);
1119 if (D.Kind == IITDescriptor::VarArg)
1120 return !isVarArg;
1121
1122 return true;
1123}
1124
1126 SmallVectorImpl<Type *> &OverloadTys) {
1127 if (!ID)
1128 return false;
1129
1133
1134 if (Intrinsic::matchIntrinsicSignature(FT, TableRef, OverloadTys) !=
1136 return false;
1137 }
1139 return false;
1140 return true;
1141}
1142
1144 SmallVectorImpl<Type *> &OverloadTys) {
1145 return getIntrinsicSignature(F->getIntrinsicID(), F->getFunctionType(),
1146 OverloadTys);
1147}
1148
1150 SmallVector<Type *, 4> OverloadTys;
1151 if (!getIntrinsicSignature(F, OverloadTys))
1152 return std::nullopt;
1153
1154 Intrinsic::ID ID = F->getIntrinsicID();
1155 StringRef Name = F->getName();
1156 std::string WantedName =
1157 Intrinsic::getName(ID, OverloadTys, F->getParent(), F->getFunctionType());
1158 if (Name == WantedName)
1159 return std::nullopt;
1160
1161 Function *NewDecl = [&] {
1162 if (auto *ExistingGV = F->getParent()->getNamedValue(WantedName)) {
1163 if (auto *ExistingF = dyn_cast<Function>(ExistingGV))
1164 if (ExistingF->getFunctionType() == F->getFunctionType())
1165 return ExistingF;
1166
1167 // The name already exists, but is not a function or has the wrong
1168 // prototype. Make place for the new one by renaming the old version.
1169 // Either this old version will be removed later on or the module is
1170 // invalid and we'll get an error.
1171 ExistingGV->setName(WantedName + ".renamed");
1172 }
1173 return Intrinsic::getOrInsertDeclaration(F->getParent(), ID, OverloadTys);
1174 }();
1175
1176 NewDecl->setCallingConv(F->getCallingConv());
1177 assert(NewDecl->getFunctionType() == F->getFunctionType() &&
1178 "Shouldn't change the signature");
1179 return NewDecl;
1180}
1181
1185
1187 {Intrinsic::vector_interleave2, Intrinsic::vector_deinterleave2},
1188 {Intrinsic::vector_interleave3, Intrinsic::vector_deinterleave3},
1189 {Intrinsic::vector_interleave4, Intrinsic::vector_deinterleave4},
1190 {Intrinsic::vector_interleave5, Intrinsic::vector_deinterleave5},
1191 {Intrinsic::vector_interleave6, Intrinsic::vector_deinterleave6},
1192 {Intrinsic::vector_interleave7, Intrinsic::vector_deinterleave7},
1193 {Intrinsic::vector_interleave8, Intrinsic::vector_deinterleave8},
1194};
1195
1197 assert(Factor >= 2 && Factor <= 8 && "Unexpected factor");
1198 return InterleaveIntrinsics[Factor - 2].Interleave;
1199}
1200
1202 assert(Factor >= 2 && Factor <= 8 && "Unexpected factor");
1203 return InterleaveIntrinsics[Factor - 2].Deinterleave;
1204}
1205
1206#define GET_INTRINSIC_PRETTY_PRINT_ARGUMENTS
1207#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, IIT_Info LastInfo, 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
ArrayRef< T > take_front(size_t N=1) const
Return a copy of *this with only the first N elements.
Definition ArrayRef.h:219
const T & front() const
front - Get the first element.
Definition ArrayRef.h:145
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
ArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array.
Definition ArrayRef.h:186
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.
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:262
@ MatchIntrinsicTypes_NoMatchArg
Definition Intrinsics.h:263
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 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:155