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