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