LLVM 22.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"
35#include "llvm/IR/Type.h"
36
37using namespace llvm;
38
39/// Table of string intrinsic names indexed by enum value.
40#define GET_INTRINSIC_NAME_TABLE
41#include "llvm/IR/IntrinsicImpl.inc"
42#undef GET_INTRINSIC_NAME_TABLE
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#undef GET_INTRINSIC_IITINFO
199};
200
201static void
202DecodeIITType(unsigned &NextElt, ArrayRef<unsigned char> Infos,
203 IIT_Info LastInfo,
205 using namespace Intrinsic;
206
207 bool IsScalableVector = (LastInfo == IIT_SCALABLE_VEC);
208
209 IIT_Info Info = IIT_Info(Infos[NextElt++]);
210 unsigned StructElts = 2;
211
212 switch (Info) {
213 case IIT_Done:
214 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Void, 0));
215 return;
216 case IIT_VARARG:
217 OutputTable.push_back(IITDescriptor::get(IITDescriptor::VarArg, 0));
218 return;
219 case IIT_MMX:
220 OutputTable.push_back(IITDescriptor::get(IITDescriptor::MMX, 0));
221 return;
222 case IIT_AMX:
223 OutputTable.push_back(IITDescriptor::get(IITDescriptor::AMX, 0));
224 return;
225 case IIT_TOKEN:
226 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Token, 0));
227 return;
228 case IIT_METADATA:
229 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Metadata, 0));
230 return;
231 case IIT_F16:
232 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Half, 0));
233 return;
234 case IIT_BF16:
235 OutputTable.push_back(IITDescriptor::get(IITDescriptor::BFloat, 0));
236 return;
237 case IIT_F32:
238 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Float, 0));
239 return;
240 case IIT_F64:
241 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Double, 0));
242 return;
243 case IIT_F128:
244 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Quad, 0));
245 return;
246 case IIT_PPCF128:
247 OutputTable.push_back(IITDescriptor::get(IITDescriptor::PPCQuad, 0));
248 return;
249 case IIT_I1:
250 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 1));
251 return;
252 case IIT_I2:
253 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 2));
254 return;
255 case IIT_I4:
256 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 4));
257 return;
258 case IIT_AARCH64_SVCOUNT:
259 OutputTable.push_back(IITDescriptor::get(IITDescriptor::AArch64Svcount, 0));
260 return;
261 case IIT_I8:
262 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 8));
263 return;
264 case IIT_I16:
265 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 16));
266 return;
267 case IIT_I32:
268 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 32));
269 return;
270 case IIT_I64:
271 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 64));
272 return;
273 case IIT_I128:
274 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 128));
275 return;
276 case IIT_V1:
277 OutputTable.push_back(IITDescriptor::getVector(1, IsScalableVector));
278 DecodeIITType(NextElt, Infos, Info, OutputTable);
279 return;
280 case IIT_V2:
281 OutputTable.push_back(IITDescriptor::getVector(2, IsScalableVector));
282 DecodeIITType(NextElt, Infos, Info, OutputTable);
283 return;
284 case IIT_V3:
285 OutputTable.push_back(IITDescriptor::getVector(3, IsScalableVector));
286 DecodeIITType(NextElt, Infos, Info, OutputTable);
287 return;
288 case IIT_V4:
289 OutputTable.push_back(IITDescriptor::getVector(4, IsScalableVector));
290 DecodeIITType(NextElt, Infos, Info, OutputTable);
291 return;
292 case IIT_V6:
293 OutputTable.push_back(IITDescriptor::getVector(6, IsScalableVector));
294 DecodeIITType(NextElt, Infos, Info, OutputTable);
295 return;
296 case IIT_V8:
297 OutputTable.push_back(IITDescriptor::getVector(8, IsScalableVector));
298 DecodeIITType(NextElt, Infos, Info, OutputTable);
299 return;
300 case IIT_V10:
301 OutputTable.push_back(IITDescriptor::getVector(10, IsScalableVector));
302 DecodeIITType(NextElt, Infos, Info, OutputTable);
303 return;
304 case IIT_V16:
305 OutputTable.push_back(IITDescriptor::getVector(16, IsScalableVector));
306 DecodeIITType(NextElt, Infos, Info, OutputTable);
307 return;
308 case IIT_V32:
309 OutputTable.push_back(IITDescriptor::getVector(32, IsScalableVector));
310 DecodeIITType(NextElt, Infos, Info, OutputTable);
311 return;
312 case IIT_V64:
313 OutputTable.push_back(IITDescriptor::getVector(64, IsScalableVector));
314 DecodeIITType(NextElt, Infos, Info, OutputTable);
315 return;
316 case IIT_V128:
317 OutputTable.push_back(IITDescriptor::getVector(128, IsScalableVector));
318 DecodeIITType(NextElt, Infos, Info, OutputTable);
319 return;
320 case IIT_V256:
321 OutputTable.push_back(IITDescriptor::getVector(256, IsScalableVector));
322 DecodeIITType(NextElt, Infos, Info, OutputTable);
323 return;
324 case IIT_V512:
325 OutputTable.push_back(IITDescriptor::getVector(512, IsScalableVector));
326 DecodeIITType(NextElt, Infos, Info, OutputTable);
327 return;
328 case IIT_V1024:
329 OutputTable.push_back(IITDescriptor::getVector(1024, IsScalableVector));
330 DecodeIITType(NextElt, Infos, Info, OutputTable);
331 return;
332 case IIT_V2048:
333 OutputTable.push_back(IITDescriptor::getVector(2048, IsScalableVector));
334 DecodeIITType(NextElt, Infos, Info, OutputTable);
335 return;
336 case IIT_V4096:
337 OutputTable.push_back(IITDescriptor::getVector(4096, IsScalableVector));
338 DecodeIITType(NextElt, Infos, Info, OutputTable);
339 return;
340 case IIT_EXTERNREF:
341 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Pointer, 10));
342 return;
343 case IIT_FUNCREF:
344 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Pointer, 20));
345 return;
346 case IIT_PTR:
347 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Pointer, 0));
348 return;
349 case IIT_ANYPTR: // [ANYPTR addrspace]
350 OutputTable.push_back(
351 IITDescriptor::get(IITDescriptor::Pointer, Infos[NextElt++]));
352 return;
353 case IIT_ARG: {
354 unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
355 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Argument, ArgInfo));
356 return;
357 }
358 case IIT_EXTEND_ARG: {
359 unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
360 OutputTable.push_back(
361 IITDescriptor::get(IITDescriptor::ExtendArgument, ArgInfo));
362 return;
363 }
364 case IIT_TRUNC_ARG: {
365 unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
366 OutputTable.push_back(
367 IITDescriptor::get(IITDescriptor::TruncArgument, ArgInfo));
368 return;
369 }
370 case IIT_ONE_NTH_ELTS_VEC_ARG: {
371 unsigned short ArgNo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
372 unsigned short N = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
373 OutputTable.push_back(
374 IITDescriptor::get(IITDescriptor::OneNthEltsVecArgument, N, ArgNo));
375 return;
376 }
377 case IIT_SAME_VEC_WIDTH_ARG: {
378 unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
379 OutputTable.push_back(
380 IITDescriptor::get(IITDescriptor::SameVecWidthArgument, ArgInfo));
381 return;
382 }
383 case IIT_VEC_OF_ANYPTRS_TO_ELT: {
384 unsigned short ArgNo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
385 unsigned short RefNo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
386 OutputTable.push_back(
387 IITDescriptor::get(IITDescriptor::VecOfAnyPtrsToElt, ArgNo, RefNo));
388 return;
389 }
390 case IIT_EMPTYSTRUCT:
391 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Struct, 0));
392 return;
393 case IIT_STRUCT9:
394 ++StructElts;
395 [[fallthrough]];
396 case IIT_STRUCT8:
397 ++StructElts;
398 [[fallthrough]];
399 case IIT_STRUCT7:
400 ++StructElts;
401 [[fallthrough]];
402 case IIT_STRUCT6:
403 ++StructElts;
404 [[fallthrough]];
405 case IIT_STRUCT5:
406 ++StructElts;
407 [[fallthrough]];
408 case IIT_STRUCT4:
409 ++StructElts;
410 [[fallthrough]];
411 case IIT_STRUCT3:
412 ++StructElts;
413 [[fallthrough]];
414 case IIT_STRUCT2: {
415 OutputTable.push_back(
416 IITDescriptor::get(IITDescriptor::Struct, StructElts));
417
418 for (unsigned i = 0; i != StructElts; ++i)
419 DecodeIITType(NextElt, Infos, Info, OutputTable);
420 return;
421 }
422 case IIT_SUBDIVIDE2_ARG: {
423 unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
424 OutputTable.push_back(
425 IITDescriptor::get(IITDescriptor::Subdivide2Argument, ArgInfo));
426 return;
427 }
428 case IIT_SUBDIVIDE4_ARG: {
429 unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
430 OutputTable.push_back(
431 IITDescriptor::get(IITDescriptor::Subdivide4Argument, ArgInfo));
432 return;
433 }
434 case IIT_VEC_ELEMENT: {
435 unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
436 OutputTable.push_back(
437 IITDescriptor::get(IITDescriptor::VecElementArgument, ArgInfo));
438 return;
439 }
440 case IIT_SCALABLE_VEC: {
441 DecodeIITType(NextElt, Infos, Info, OutputTable);
442 return;
443 }
444 case IIT_VEC_OF_BITCASTS_TO_INT: {
445 unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
446 OutputTable.push_back(
447 IITDescriptor::get(IITDescriptor::VecOfBitcastsToInt, ArgInfo));
448 return;
449 }
450 }
451 llvm_unreachable("unhandled");
452}
453
454#define GET_INTRINSIC_GENERATOR_GLOBAL
455#include "llvm/IR/IntrinsicImpl.inc"
456#undef GET_INTRINSIC_GENERATOR_GLOBAL
457
460 static_assert(sizeof(IIT_Table[0]) == 2,
461 "Expect 16-bit entries in IIT_Table");
462 // Check to see if the intrinsic's type was expressible by the table.
463 uint16_t TableVal = IIT_Table[id - 1];
464
465 // Decode the TableVal into an array of IITValues.
467 ArrayRef<unsigned char> IITEntries;
468 unsigned NextElt = 0;
469 if (TableVal >> 15) {
470 // This is an offset into the IIT_LongEncodingTable.
471 IITEntries = IIT_LongEncodingTable;
472
473 // Strip sentinel bit.
474 NextElt = TableVal & 0x7fff;
475 } else {
476 // If the entry was encoded into a single word in the table itself, decode
477 // it from an array of nibbles to an array of bytes.
478 do {
479 IITValues.push_back(TableVal & 0xF);
480 TableVal >>= 4;
481 } while (TableVal);
482
483 IITEntries = IITValues;
484 NextElt = 0;
485 }
486
487 // Okay, decode the table into the output vector of IITDescriptors.
488 DecodeIITType(NextElt, IITEntries, IIT_Done, T);
489 while (NextElt != IITEntries.size() && IITEntries[NextElt] != 0)
490 DecodeIITType(NextElt, IITEntries, IIT_Done, T);
491}
492
494 ArrayRef<Type *> Tys, LLVMContext &Context) {
495 using namespace Intrinsic;
496
497 IITDescriptor D = Infos.front();
498 Infos = Infos.slice(1);
499
500 switch (D.Kind) {
501 case IITDescriptor::Void:
502 return Type::getVoidTy(Context);
503 case IITDescriptor::VarArg:
504 return Type::getVoidTy(Context);
505 case IITDescriptor::MMX:
507 case IITDescriptor::AMX:
509 case IITDescriptor::Token:
511 case IITDescriptor::Metadata:
513 case IITDescriptor::Half:
514 return Type::getHalfTy(Context);
515 case IITDescriptor::BFloat:
517 case IITDescriptor::Float:
519 case IITDescriptor::Double:
521 case IITDescriptor::Quad:
523 case IITDescriptor::PPCQuad:
525 case IITDescriptor::AArch64Svcount:
526 return TargetExtType::get(Context, "aarch64.svcount");
527
528 case IITDescriptor::Integer:
529 return IntegerType::get(Context, D.Integer_Width);
530 case IITDescriptor::Vector:
531 return VectorType::get(DecodeFixedType(Infos, Tys, Context),
532 D.Vector_Width);
533 case IITDescriptor::Pointer:
534 return PointerType::get(Context, D.Pointer_AddressSpace);
535 case IITDescriptor::Struct: {
537 for (unsigned i = 0, e = D.Struct_NumElements; i != e; ++i)
538 Elts.push_back(DecodeFixedType(Infos, Tys, Context));
539 return StructType::get(Context, Elts);
540 }
541 case IITDescriptor::Argument:
542 return Tys[D.getArgumentNumber()];
543 case IITDescriptor::ExtendArgument: {
544 Type *Ty = Tys[D.getArgumentNumber()];
545 if (VectorType *VTy = dyn_cast<VectorType>(Ty))
546 return VectorType::getExtendedElementVectorType(VTy);
547
548 return IntegerType::get(Context, 2 * cast<IntegerType>(Ty)->getBitWidth());
549 }
550 case IITDescriptor::TruncArgument: {
551 Type *Ty = Tys[D.getArgumentNumber()];
552 if (VectorType *VTy = dyn_cast<VectorType>(Ty))
553 return VectorType::getTruncatedElementVectorType(VTy);
554
555 IntegerType *ITy = cast<IntegerType>(Ty);
556 assert(ITy->getBitWidth() % 2 == 0);
557 return IntegerType::get(Context, ITy->getBitWidth() / 2);
558 }
559 case IITDescriptor::Subdivide2Argument:
560 case IITDescriptor::Subdivide4Argument: {
561 Type *Ty = Tys[D.getArgumentNumber()];
562 VectorType *VTy = dyn_cast<VectorType>(Ty);
563 assert(VTy && "Expected an argument of Vector Type");
564 int SubDivs = D.Kind == IITDescriptor::Subdivide2Argument ? 1 : 2;
565 return VectorType::getSubdividedVectorType(VTy, SubDivs);
566 }
567 case IITDescriptor::OneNthEltsVecArgument:
568 return VectorType::getOneNthElementsVectorType(
569 cast<VectorType>(Tys[D.getRefArgNumber()]), D.getVectorDivisor());
570 case IITDescriptor::SameVecWidthArgument: {
571 Type *EltTy = DecodeFixedType(Infos, Tys, Context);
572 Type *Ty = Tys[D.getArgumentNumber()];
573 if (auto *VTy = dyn_cast<VectorType>(Ty))
574 return VectorType::get(EltTy, VTy->getElementCount());
575 return EltTy;
576 }
577 case IITDescriptor::VecElementArgument: {
578 Type *Ty = Tys[D.getArgumentNumber()];
579 if (VectorType *VTy = dyn_cast<VectorType>(Ty))
580 return VTy->getElementType();
581 llvm_unreachable("Expected an argument of Vector Type");
582 }
583 case IITDescriptor::VecOfBitcastsToInt: {
584 Type *Ty = Tys[D.getArgumentNumber()];
585 VectorType *VTy = dyn_cast<VectorType>(Ty);
586 assert(VTy && "Expected an argument of Vector Type");
587 return VectorType::getInteger(VTy);
588 }
589 case IITDescriptor::VecOfAnyPtrsToElt:
590 // Return the overloaded type (which determines the pointers address space)
591 return Tys[D.getOverloadArgNumber()];
592 }
593 llvm_unreachable("unhandled");
594}
595
597 ArrayRef<Type *> Tys) {
600
602 Type *ResultTy = DecodeFixedType(TableRef, Tys, Context);
603
605 while (!TableRef.empty())
607
608 // DecodeFixedType returns Void for IITDescriptor::Void and
609 // IITDescriptor::VarArg If we see void type as the type of the last argument,
610 // it is vararg intrinsic
611 if (!ArgTys.empty() && ArgTys.back()->isVoidTy()) {
612 ArgTys.pop_back();
613 return FunctionType::get(ResultTy, ArgTys, true);
614 }
615 return FunctionType::get(ResultTy, ArgTys, false);
616}
617
619#define GET_INTRINSIC_OVERLOAD_TABLE
620#include "llvm/IR/IntrinsicImpl.inc"
621#undef GET_INTRINSIC_OVERLOAD_TABLE
622}
623
624/// Table of per-target intrinsic name tables.
625#define GET_INTRINSIC_TARGET_DATA
626#include "llvm/IR/IntrinsicImpl.inc"
627#undef GET_INTRINSIC_TARGET_DATA
628
630 return IID > TargetInfos[0].Count;
631}
632
633/// Looks up Name in NameTable via binary search. NameTable must be sorted
634/// and all entries must start with "llvm.". If NameTable contains an exact
635/// match for Name or a prefix of Name followed by a dot, its index in
636/// NameTable is returned. Otherwise, -1 is returned.
639 assert(Name.starts_with("llvm.") && "Unexpected intrinsic prefix");
640 assert(Name.drop_front(5).starts_with(Target) && "Unexpected target");
641
642 // Do successive binary searches of the dotted name components. For
643 // "llvm.gc.experimental.statepoint.p1i8.p1i32", we will find the range of
644 // intrinsics starting with "llvm.gc", then "llvm.gc.experimental", then
645 // "llvm.gc.experimental.statepoint", and then we will stop as the range is
646 // size 1. During the search, we can skip the prefix that we already know is
647 // identical. By using strncmp we consider names with differing suffixes to
648 // be part of the equal range.
649 size_t CmpEnd = 4; // Skip the "llvm" component.
650 if (!Target.empty())
651 CmpEnd += 1 + Target.size(); // skip the .target component.
652
653 const unsigned *Low = NameOffsetTable.begin();
654 const unsigned *High = NameOffsetTable.end();
655 const unsigned *LastLow = Low;
656 while (CmpEnd < Name.size() && High - Low > 0) {
657 size_t CmpStart = CmpEnd;
658 CmpEnd = Name.find('.', CmpStart + 1);
659 CmpEnd = CmpEnd == StringRef::npos ? Name.size() : CmpEnd;
660 auto Cmp = [CmpStart, CmpEnd](auto LHS, auto RHS) {
661 // `equal_range` requires the comparison to work with either side being an
662 // offset or the value. Detect which kind each side is to set up the
663 // compared strings.
664 const char *LHSStr;
665 if constexpr (std::is_integral_v<decltype(LHS)>)
666 LHSStr = IntrinsicNameTable.getCString(LHS);
667 else
668 LHSStr = LHS;
669
670 const char *RHSStr;
671 if constexpr (std::is_integral_v<decltype(RHS)>)
672 RHSStr = IntrinsicNameTable.getCString(RHS);
673 else
674 RHSStr = RHS;
675
676 return strncmp(LHSStr + CmpStart, RHSStr + CmpStart, CmpEnd - CmpStart) <
677 0;
678 };
679 LastLow = Low;
680 std::tie(Low, High) = std::equal_range(Low, High, Name.data(), Cmp);
681 }
682 if (High - Low > 0)
683 LastLow = Low;
684
685 if (LastLow == NameOffsetTable.end())
686 return -1;
687 StringRef NameFound = IntrinsicNameTable[*LastLow];
688 if (Name == NameFound ||
689 (Name.starts_with(NameFound) && Name[NameFound.size()] == '.'))
690 return LastLow - NameOffsetTable.begin();
691 return -1;
692}
693
694/// Find the segment of \c IntrinsicNameOffsetTable for intrinsics with the same
695/// target as \c Name, or the generic table if \c Name is not target specific.
696///
697/// Returns the relevant slice of \c IntrinsicNameOffsetTable and the target
698/// name.
699static std::pair<ArrayRef<unsigned>, StringRef>
701 assert(Name.starts_with("llvm."));
702
703 ArrayRef<IntrinsicTargetInfo> Targets(TargetInfos);
704 // Drop "llvm." and take the first dotted component. That will be the target
705 // if this is target specific.
706 StringRef Target = Name.drop_front(5).split('.').first;
707 auto It = partition_point(
708 Targets, [=](const IntrinsicTargetInfo &TI) { return TI.Name < Target; });
709 // We've either found the target or just fall back to the generic set, which
710 // is always first.
711 const auto &TI = It != Targets.end() && It->Name == Target ? *It : Targets[0];
712 return {ArrayRef(&IntrinsicNameOffsetTable[1] + TI.Offset, TI.Count),
713 TI.Name};
714}
715
716/// This does the actual lookup of an intrinsic ID which matches the given
717/// function name.
719 auto [NameOffsetTable, Target] = findTargetSubtable(Name);
720 int Idx = lookupLLVMIntrinsicByName(NameOffsetTable, Name, Target);
721 if (Idx == -1)
723
724 // Intrinsic IDs correspond to the location in IntrinsicNameTable, but we have
725 // an index into a sub-table.
726 int Adjust = NameOffsetTable.data() - IntrinsicNameOffsetTable;
727 Intrinsic::ID ID = static_cast<Intrinsic::ID>(Idx + Adjust);
728
729 // If the intrinsic is not overloaded, require an exact match. If it is
730 // overloaded, require either exact or prefix match.
731 const auto MatchSize = IntrinsicNameTable[NameOffsetTable[Idx]].size();
732 assert(Name.size() >= MatchSize && "Expected either exact or prefix match");
733 bool IsExactMatch = Name.size() == MatchSize;
734 return IsExactMatch || Intrinsic::isOverloaded(ID) ? ID
736}
737
738/// This defines the "Intrinsic::getAttributes(ID id)" method.
739#define GET_INTRINSIC_ATTRIBUTES
740#include "llvm/IR/IntrinsicImpl.inc"
741#undef GET_INTRINSIC_ATTRIBUTES
742
744 if (id == 0)
745 return AttributeSet();
746 uint16_t PackedID = IntrinsicsToAttributesMap[id - 1];
747 uint8_t FnAttrID = PackedID >> 8;
748 return getIntrinsicFnAttributeSet(C, FnAttrID);
749}
750
752 ArrayRef<Type *> Tys) {
753 // There can never be multiple globals with the same name of different types,
754 // because intrinsics must be a specific type.
755 auto *FT = getType(M->getContext(), id, Tys);
756 return cast<Function>(
757 M->getOrInsertFunction(
758 Tys.empty() ? getName(id) : getName(id, Tys, M, FT), FT)
759 .getCallee());
760}
761
763 return M->getFunction(getName(id));
764}
765
768 FunctionType *FT) {
769 return M->getFunction(getName(id, Tys, M, FT));
770}
771
772// This defines the "Intrinsic::getIntrinsicForClangBuiltin()" method.
773#define GET_LLVM_INTRINSIC_FOR_CLANG_BUILTIN
774#include "llvm/IR/IntrinsicImpl.inc"
775#undef GET_LLVM_INTRINSIC_FOR_CLANG_BUILTIN
776
777// This defines the "Intrinsic::getIntrinsicForMSBuiltin()" method.
778#define GET_LLVM_INTRINSIC_FOR_MS_BUILTIN
779#include "llvm/IR/IntrinsicImpl.inc"
780#undef GET_LLVM_INTRINSIC_FOR_MS_BUILTIN
781
783 switch (QID) {
784#define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC) \
785 case Intrinsic::INTRINSIC:
786#include "llvm/IR/ConstrainedOps.def"
787#undef INSTRUCTION
788 return true;
789 default:
790 return false;
791 }
792}
793
795 switch (QID) {
796#define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC) \
797 case Intrinsic::INTRINSIC: \
798 return ROUND_MODE == 1;
799#include "llvm/IR/ConstrainedOps.def"
800#undef INSTRUCTION
801 default:
802 return false;
803 }
804}
805
807 std::pair<Type *, ArrayRef<Intrinsic::IITDescriptor>>;
808
809static bool
813 bool IsDeferredCheck) {
814 using namespace Intrinsic;
815
816 // If we ran out of descriptors, there are too many arguments.
817 if (Infos.empty())
818 return true;
819
820 // Do this before slicing off the 'front' part
821 auto InfosRef = Infos;
822 auto DeferCheck = [&DeferredChecks, &InfosRef](Type *T) {
823 DeferredChecks.emplace_back(T, InfosRef);
824 return false;
825 };
826
827 IITDescriptor D = Infos.front();
828 Infos = Infos.slice(1);
829
830 switch (D.Kind) {
831 case IITDescriptor::Void:
832 return !Ty->isVoidTy();
833 case IITDescriptor::VarArg:
834 return true;
835 case IITDescriptor::MMX: {
836 FixedVectorType *VT = dyn_cast<FixedVectorType>(Ty);
837 return !VT || VT->getNumElements() != 1 ||
838 !VT->getElementType()->isIntegerTy(64);
839 }
840 case IITDescriptor::AMX:
841 return !Ty->isX86_AMXTy();
842 case IITDescriptor::Token:
843 return !Ty->isTokenTy();
844 case IITDescriptor::Metadata:
845 return !Ty->isMetadataTy();
846 case IITDescriptor::Half:
847 return !Ty->isHalfTy();
848 case IITDescriptor::BFloat:
849 return !Ty->isBFloatTy();
850 case IITDescriptor::Float:
851 return !Ty->isFloatTy();
852 case IITDescriptor::Double:
853 return !Ty->isDoubleTy();
854 case IITDescriptor::Quad:
855 return !Ty->isFP128Ty();
856 case IITDescriptor::PPCQuad:
857 return !Ty->isPPC_FP128Ty();
858 case IITDescriptor::Integer:
859 return !Ty->isIntegerTy(D.Integer_Width);
860 case IITDescriptor::AArch64Svcount:
861 return !isa<TargetExtType>(Ty) ||
862 cast<TargetExtType>(Ty)->getName() != "aarch64.svcount";
863 case IITDescriptor::Vector: {
864 VectorType *VT = dyn_cast<VectorType>(Ty);
865 return !VT || VT->getElementCount() != D.Vector_Width ||
866 matchIntrinsicType(VT->getElementType(), Infos, ArgTys,
867 DeferredChecks, IsDeferredCheck);
868 }
869 case IITDescriptor::Pointer: {
870 PointerType *PT = dyn_cast<PointerType>(Ty);
871 return !PT || PT->getAddressSpace() != D.Pointer_AddressSpace;
872 }
873
874 case IITDescriptor::Struct: {
875 StructType *ST = dyn_cast<StructType>(Ty);
876 if (!ST || !ST->isLiteral() || ST->isPacked() ||
877 ST->getNumElements() != D.Struct_NumElements)
878 return true;
879
880 for (unsigned i = 0, e = D.Struct_NumElements; i != e; ++i)
881 if (matchIntrinsicType(ST->getElementType(i), Infos, ArgTys,
882 DeferredChecks, IsDeferredCheck))
883 return true;
884 return false;
885 }
886
887 case IITDescriptor::Argument:
888 // If this is the second occurrence of an argument,
889 // verify that the later instance matches the previous instance.
890 if (D.getArgumentNumber() < ArgTys.size())
891 return Ty != ArgTys[D.getArgumentNumber()];
892
893 if (D.getArgumentNumber() > ArgTys.size() ||
894 D.getArgumentKind() == IITDescriptor::AK_MatchType)
895 return IsDeferredCheck || DeferCheck(Ty);
896
897 assert(D.getArgumentNumber() == ArgTys.size() && !IsDeferredCheck &&
898 "Table consistency error");
899 ArgTys.push_back(Ty);
900
901 switch (D.getArgumentKind()) {
902 case IITDescriptor::AK_Any:
903 return false; // Success
904 case IITDescriptor::AK_AnyInteger:
905 return !Ty->isIntOrIntVectorTy();
906 case IITDescriptor::AK_AnyFloat:
907 return !Ty->isFPOrFPVectorTy();
908 case IITDescriptor::AK_AnyVector:
909 return !isa<VectorType>(Ty);
910 case IITDescriptor::AK_AnyPointer:
911 return !isa<PointerType>(Ty);
912 default:
913 break;
914 }
915 llvm_unreachable("all argument kinds not covered");
916
917 case IITDescriptor::ExtendArgument: {
918 // If this is a forward reference, defer the check for later.
919 if (D.getArgumentNumber() >= ArgTys.size())
920 return IsDeferredCheck || DeferCheck(Ty);
921
922 Type *NewTy = ArgTys[D.getArgumentNumber()];
923 if (VectorType *VTy = dyn_cast<VectorType>(NewTy))
924 NewTy = VectorType::getExtendedElementVectorType(VTy);
925 else if (IntegerType *ITy = dyn_cast<IntegerType>(NewTy))
926 NewTy = IntegerType::get(ITy->getContext(), 2 * ITy->getBitWidth());
927 else
928 return true;
929
930 return Ty != NewTy;
931 }
932 case IITDescriptor::TruncArgument: {
933 // If this is a forward reference, defer the check for later.
934 if (D.getArgumentNumber() >= ArgTys.size())
935 return IsDeferredCheck || DeferCheck(Ty);
936
937 Type *NewTy = ArgTys[D.getArgumentNumber()];
938 if (VectorType *VTy = dyn_cast<VectorType>(NewTy))
939 NewTy = VectorType::getTruncatedElementVectorType(VTy);
940 else if (IntegerType *ITy = dyn_cast<IntegerType>(NewTy))
941 NewTy = IntegerType::get(ITy->getContext(), ITy->getBitWidth() / 2);
942 else
943 return true;
944
945 return Ty != NewTy;
946 }
947 case IITDescriptor::OneNthEltsVecArgument:
948 // If this is a forward reference, defer the check for later.
949 if (D.getRefArgNumber() >= ArgTys.size())
950 return IsDeferredCheck || DeferCheck(Ty);
951 return !isa<VectorType>(ArgTys[D.getRefArgNumber()]) ||
952 VectorType::getOneNthElementsVectorType(
953 cast<VectorType>(ArgTys[D.getRefArgNumber()]),
954 D.getVectorDivisor()) != Ty;
955 case IITDescriptor::SameVecWidthArgument: {
956 if (D.getArgumentNumber() >= ArgTys.size()) {
957 // Defer check and subsequent check for the vector element type.
958 Infos = Infos.slice(1);
959 return IsDeferredCheck || DeferCheck(Ty);
960 }
961 auto *ReferenceType = dyn_cast<VectorType>(ArgTys[D.getArgumentNumber()]);
962 auto *ThisArgType = dyn_cast<VectorType>(Ty);
963 // Both must be vectors of the same number of elements or neither.
964 if ((ReferenceType != nullptr) != (ThisArgType != nullptr))
965 return true;
966 Type *EltTy = Ty;
967 if (ThisArgType) {
968 if (ReferenceType->getElementCount() != ThisArgType->getElementCount())
969 return true;
970 EltTy = ThisArgType->getElementType();
971 }
972 return matchIntrinsicType(EltTy, Infos, ArgTys, DeferredChecks,
973 IsDeferredCheck);
974 }
975 case IITDescriptor::VecOfAnyPtrsToElt: {
976 unsigned RefArgNumber = D.getRefArgNumber();
977 if (RefArgNumber >= ArgTys.size()) {
978 if (IsDeferredCheck)
979 return true;
980 // If forward referencing, already add the pointer-vector type and
981 // defer the checks for later.
982 ArgTys.push_back(Ty);
983 return DeferCheck(Ty);
984 }
985
986 if (!IsDeferredCheck) {
987 assert(D.getOverloadArgNumber() == ArgTys.size() &&
988 "Table consistency error");
989 ArgTys.push_back(Ty);
990 }
991
992 // Verify the overloaded type "matches" the Ref type.
993 // i.e. Ty is a vector with the same width as Ref.
994 // Composed of pointers to the same element type as Ref.
995 auto *ReferenceType = dyn_cast<VectorType>(ArgTys[RefArgNumber]);
996 auto *ThisArgVecTy = dyn_cast<VectorType>(Ty);
997 if (!ThisArgVecTy || !ReferenceType ||
998 (ReferenceType->getElementCount() != ThisArgVecTy->getElementCount()))
999 return true;
1000 return !ThisArgVecTy->getElementType()->isPointerTy();
1001 }
1002 case IITDescriptor::VecElementArgument: {
1003 if (D.getArgumentNumber() >= ArgTys.size())
1004 return IsDeferredCheck ? true : DeferCheck(Ty);
1005 auto *ReferenceType = dyn_cast<VectorType>(ArgTys[D.getArgumentNumber()]);
1006 return !ReferenceType || Ty != ReferenceType->getElementType();
1007 }
1008 case IITDescriptor::Subdivide2Argument:
1009 case IITDescriptor::Subdivide4Argument: {
1010 // If this is a forward reference, defer the check for later.
1011 if (D.getArgumentNumber() >= ArgTys.size())
1012 return IsDeferredCheck || DeferCheck(Ty);
1013
1014 Type *NewTy = ArgTys[D.getArgumentNumber()];
1015 if (auto *VTy = dyn_cast<VectorType>(NewTy)) {
1016 int SubDivs = D.Kind == IITDescriptor::Subdivide2Argument ? 1 : 2;
1017 NewTy = VectorType::getSubdividedVectorType(VTy, SubDivs);
1018 return Ty != NewTy;
1019 }
1020 return true;
1021 }
1022 case IITDescriptor::VecOfBitcastsToInt: {
1023 if (D.getArgumentNumber() >= ArgTys.size())
1024 return IsDeferredCheck || DeferCheck(Ty);
1025 auto *ReferenceType = dyn_cast<VectorType>(ArgTys[D.getArgumentNumber()]);
1026 auto *ThisArgVecTy = dyn_cast<VectorType>(Ty);
1027 if (!ThisArgVecTy || !ReferenceType)
1028 return true;
1029 return ThisArgVecTy != VectorType::getInteger(ReferenceType);
1030 }
1031 }
1032 llvm_unreachable("unhandled");
1033}
1034
1038 SmallVectorImpl<Type *> &ArgTys) {
1040 if (matchIntrinsicType(FTy->getReturnType(), Infos, ArgTys, DeferredChecks,
1041 false))
1043
1044 unsigned NumDeferredReturnChecks = DeferredChecks.size();
1045
1046 for (auto *Ty : FTy->params())
1047 if (matchIntrinsicType(Ty, Infos, ArgTys, DeferredChecks, false))
1049
1050 for (unsigned I = 0, E = DeferredChecks.size(); I != E; ++I) {
1051 DeferredIntrinsicMatchPair &Check = DeferredChecks[I];
1052 if (matchIntrinsicType(Check.first, Check.second, ArgTys, DeferredChecks,
1053 true))
1054 return I < NumDeferredReturnChecks ? MatchIntrinsicTypes_NoMatchRet
1056 }
1057
1059}
1060
1062 bool isVarArg, ArrayRef<Intrinsic::IITDescriptor> &Infos) {
1063 // If there are no descriptors left, then it can't be a vararg.
1064 if (Infos.empty())
1065 return isVarArg;
1066
1067 // There should be only one descriptor remaining at this point.
1068 if (Infos.size() != 1)
1069 return true;
1070
1071 // Check and verify the descriptor.
1072 IITDescriptor D = Infos.front();
1073 Infos = Infos.slice(1);
1074 if (D.Kind == IITDescriptor::VarArg)
1075 return !isVarArg;
1076
1077 return true;
1078}
1079
1081 SmallVectorImpl<Type *> &ArgTys) {
1082 if (!ID)
1083 return false;
1084
1088
1090 Intrinsic::MatchIntrinsicTypesResult::MatchIntrinsicTypes_Match) {
1091 return false;
1092 }
1094 return false;
1095 return true;
1096}
1097
1099 SmallVectorImpl<Type *> &ArgTys) {
1100 return getIntrinsicSignature(F->getIntrinsicID(), F->getFunctionType(),
1101 ArgTys);
1102}
1103
1106 if (!getIntrinsicSignature(F, ArgTys))
1107 return std::nullopt;
1108
1109 Intrinsic::ID ID = F->getIntrinsicID();
1110 StringRef Name = F->getName();
1111 std::string WantedName =
1112 Intrinsic::getName(ID, ArgTys, F->getParent(), F->getFunctionType());
1113 if (Name == WantedName)
1114 return std::nullopt;
1115
1116 Function *NewDecl = [&] {
1117 if (auto *ExistingGV = F->getParent()->getNamedValue(WantedName)) {
1118 if (auto *ExistingF = dyn_cast<Function>(ExistingGV))
1119 if (ExistingF->getFunctionType() == F->getFunctionType())
1120 return ExistingF;
1121
1122 // The name already exists, but is not a function or has the wrong
1123 // prototype. Make place for the new one by renaming the old version.
1124 // Either this old version will be removed later on or the module is
1125 // invalid and we'll get an error.
1126 ExistingGV->setName(WantedName + ".renamed");
1127 }
1128 return Intrinsic::getOrInsertDeclaration(F->getParent(), ID, ArgTys);
1129 }();
1130
1131 NewDecl->setCallingConv(F->getCallingConv());
1132 assert(NewDecl->getFunctionType() == F->getFunctionType() &&
1133 "Shouldn't change the signature");
1134 return NewDecl;
1135}
1136
1139};
1140
1142 {Intrinsic::vector_interleave2, Intrinsic::vector_deinterleave2},
1143 {Intrinsic::vector_interleave3, Intrinsic::vector_deinterleave3},
1144 {Intrinsic::vector_interleave4, Intrinsic::vector_deinterleave4},
1145 {Intrinsic::vector_interleave5, Intrinsic::vector_deinterleave5},
1146 {Intrinsic::vector_interleave6, Intrinsic::vector_deinterleave6},
1147 {Intrinsic::vector_interleave7, Intrinsic::vector_deinterleave7},
1148 {Intrinsic::vector_interleave8, Intrinsic::vector_deinterleave8},
1149};
1150
1152 assert(Factor >= 2 && Factor <= 8 && "Unexpected factor");
1153 return InterleaveIntrinsics[Factor - 2].Interleave;
1154}
1155
1157 assert(Factor >= 2 && Factor <= 8 && "Unexpected factor");
1158 return InterleaveIntrinsics[Factor - 2].Deinterleave;
1159}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
std::string Name
#define Check(C,...)
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)
Definition: Intrinsics.cpp:810
static std::string getIntrinsicNameImpl(Intrinsic::ID Id, ArrayRef< Type * > Tys, Module *M, FunctionType *FT, bool EarlyModuleCheck)
Definition: Intrinsics.cpp:154
static InterleaveIntrinsic InterleaveIntrinsics[]
std::pair< Type *, ArrayRef< Intrinsic::IITDescriptor > > DeferredIntrinsicMatchPair
Definition: Intrinsics.cpp:807
static std::pair< ArrayRef< unsigned >, StringRef > findTargetSubtable(StringRef Name)
Find the segment of IntrinsicNameOffsetTable for intrinsics with the same target as Name,...
Definition: Intrinsics.cpp:700
static void DecodeIITType(unsigned &NextElt, ArrayRef< unsigned char > Infos, IIT_Info LastInfo, SmallVectorImpl< Intrinsic::IITDescriptor > &OutputTable)
Definition: Intrinsics.cpp:202
IIT_Info
IIT_Info - These are enumerators that describe the entries returned by the getIntrinsicInfoTableEntri...
Definition: Intrinsics.cpp:195
static Type * DecodeFixedType(ArrayRef< Intrinsic::IITDescriptor > &Infos, ArrayRef< Type * > Tys, LLVMContext &Context)
Definition: Intrinsics.cpp:493
static int lookupLLVMIntrinsicByName(ArrayRef< unsigned > NameOffsetTable, StringRef Name, StringRef Target="")
Looks up Name in NameTable via binary search.
Definition: Intrinsics.cpp:637
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...
Definition: Intrinsics.cpp:68
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
uint64_t High
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:41
const T & front() const
front - Get the first element.
Definition: ArrayRef.h:150
iterator end() const
Definition: ArrayRef.h:136
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:147
iterator begin() const
Definition: ArrayRef.h:135
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:142
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:191
Class to represent fixed width SIMD vectors.
Definition: DerivedTypes.h:592
unsigned getNumElements() const
Definition: DerivedTypes.h:635
static LLVM_ABI FixedVectorType * get(Type *ElementType, unsigned NumElts)
Definition: Type.cpp:803
Class to represent function types.
Definition: DerivedTypes.h:105
ArrayRef< Type * > params() const
Definition: DerivedTypes.h:132
bool isVarArg() const
Definition: DerivedTypes.h:125
Type * getReturnType() const
Definition: DerivedTypes.h:126
FunctionType * getFunctionType() const
Returns the FunctionType for me.
Definition: Function.h:209
void setCallingConv(CallingConv::ID CC)
Definition: Function.h:274
Class to represent integer types.
Definition: DerivedTypes.h:42
static LLVM_ABI IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Definition: Type.cpp:319
unsigned getBitWidth() const
Get the number of bits in this IntegerType.
Definition: DerivedTypes.h:74
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
bool empty() const
Definition: SmallVector.h:82
size_t size() const
Definition: SmallVector.h:79
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:574
reference emplace_back(ArgTypes &&... Args)
Definition: SmallVector.h:938
void push_back(const T &Elt)
Definition: SmallVector.h:414
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1197
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
constexpr size_t size() const
size - Get the string size.
Definition: StringRef.h:154
static constexpr size_t npos
Definition: StringRef.h:57
Class to represent struct types.
Definition: DerivedTypes.h:218
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:414
Class to represent target extensions types, which are generally unintrospectable from target-independ...
Definition: DerivedTypes.h:781
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:908
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 * getFloatTy(LLVMContext &C)
static LLVM_ABI Type * getFP128Ty(LLVMContext &C)
static LLVM_ABI Type * getPPC_FP128Ty(LLVMContext &C)
static LLVM_ABI Type * getDoubleTy(LLVMContext &C)
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
Definition: Type.h:246
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
Definition: Type.h:153
static LLVM_ABI Type * getHalfTy(LLVMContext &C)
bool isBFloatTy() const
Return true if this is 'bfloat', a 16-bit bfloat type.
Definition: Type.h:145
@ 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
bool isPPC_FP128Ty() const
Return true if this is powerpc long double.
Definition: Type.h:165
static LLVM_ABI Type * getX86_AMXTy(LLVMContext &C)
bool isFP128Ty() const
Return true if this is 'fp128'.
Definition: Type.h:162
static LLVM_ABI Type * getBFloatTy(LLVMContext &C)
static LLVM_ABI Type * getVoidTy(LLVMContext &C)
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
Definition: Type.h:142
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
Definition: Type.h:156
bool isX86_AMXTy() const
Return true if this is X86 AMX.
Definition: Type.h:200
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition: Type.h:240
TypeID getTypeID() const
Return the type id for the type.
Definition: Type.h:136
bool isTokenTy() const
Return true if this is 'token'.
Definition: Type.h:234
static LLVM_ABI Type * getMetadataTy(LLVMContext &C)
bool isFPOrFPVectorTy() const
Return true if this is a FP type or a vector of FP.
Definition: Type.h:225
bool isVoidTy() const
Return true if this is 'void'.
Definition: Type.h:139
static LLVM_ABI Type * getTokenTy(LLVMContext &C)
bool isMetadataTy() const
Return true if this is 'metadata'.
Definition: Type.h:231
LLVM_ABI void setName(const Twine &Name)
Change the name of the value.
Definition: Value.cpp:390
Type * getElementType() const
Definition: DerivedTypes.h:463
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
LLVM_ABI Function * getOrInsertDeclaration(Module *M, ID id, ArrayRef< Type * > Tys={})
Look up the Function declaration of the intrinsic id in the Module M.
Definition: Intrinsics.cpp:751
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 AttributeSet getFnAttributes(LLVMContext &C, ID id)
Return the function attributes for an intrinsic.
Definition: Intrinsics.cpp:743
LLVM_ABI void getIntrinsicInfoTableEntries(ID id, SmallVectorImpl< IITDescriptor > &T)
Return the IIT table descriptor for the specified intrinsic into an array of IITDescriptors.
Definition: Intrinsics.cpp:458
@ MatchIntrinsicTypes_Match
Definition: Intrinsics.h:239
@ MatchIntrinsicTypes_NoMatchRet
Definition: Intrinsics.h:240
@ MatchIntrinsicTypes_NoMatchArg
Definition: Intrinsics.h:241
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.
Definition: Intrinsics.cpp:762
LLVM_ABI std::string getNameNoUnnamedTypes(ID Id, ArrayRef< Type * > Tys)
Return the LLVM name for an intrinsic.
Definition: Intrinsics.cpp:187
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 "Constrained Floating-Point Intrinsics" that take ...
Definition: Intrinsics.cpp:794
LLVM_ABI StringRef getName(ID id)
Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
Definition: Intrinsics.cpp:49
LLVM_ABI bool isConstrainedFPIntrinsic(ID QID)
Returns true if the intrinsic ID is for one of the "Constrained Floating-Point Intrinsics".
Definition: Intrinsics.cpp:782
LLVM_ABI ID lookupIntrinsicID(StringRef Name)
This does the actual lookup of an intrinsic ID which matches the given function name.
Definition: Intrinsics.cpp:718
LLVM_ABI StringRef getBaseName(ID id)
Return the LLVM name for an intrinsic, without encoded types for overloading, such as "llvm....
Definition: Intrinsics.cpp:44
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.
Definition: Intrinsics.cpp:618
LLVM_ABI FunctionType * getType(LLVMContext &Context, ID id, ArrayRef< Type * > Tys={})
Return the function type for an intrinsic.
Definition: Intrinsics.cpp:596
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.
Definition: Intrinsics.cpp:629
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: AddressRanges.h:18
@ Low
Lower the current thread's priority such that it does not affect foreground tasks significantly.
auto partition_point(R &&Range, Predicate P)
Binary search for the first iterator in a range where a predicate is false.
Definition: STLExtras.h:2090
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:1751
#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:135