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