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