LLVM 20.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"
16#include "llvm/IR/Function.h"
17#include "llvm/IR/IntrinsicsAArch64.h"
18#include "llvm/IR/IntrinsicsAMDGPU.h"
19#include "llvm/IR/IntrinsicsARM.h"
20#include "llvm/IR/IntrinsicsBPF.h"
21#include "llvm/IR/IntrinsicsHexagon.h"
22#include "llvm/IR/IntrinsicsLoongArch.h"
23#include "llvm/IR/IntrinsicsMips.h"
24#include "llvm/IR/IntrinsicsNVPTX.h"
25#include "llvm/IR/IntrinsicsPowerPC.h"
26#include "llvm/IR/IntrinsicsR600.h"
27#include "llvm/IR/IntrinsicsRISCV.h"
28#include "llvm/IR/IntrinsicsS390.h"
29#include "llvm/IR/IntrinsicsVE.h"
30#include "llvm/IR/IntrinsicsX86.h"
31#include "llvm/IR/IntrinsicsXCore.h"
32#include "llvm/IR/Module.h"
33#include "llvm/IR/Type.h"
34
35using namespace llvm;
36
37/// Table of string intrinsic names indexed by enum value.
38#define GET_INTRINSIC_NAME_TABLE
39#include "llvm/IR/IntrinsicImpl.inc"
40#undef GET_INTRINSIC_NAME_TABLE
41
43 assert(id < num_intrinsics && "Invalid intrinsic ID!");
44 return IntrinsicNameTable[IntrinsicNameOffsetTable[id]];
45}
46
48 assert(id < num_intrinsics && "Invalid intrinsic ID!");
50 "This version of getName does not support overloading");
51 return getBaseName(id);
52}
53
54/// Returns a stable mangling for the type specified for use in the name
55/// mangling scheme used by 'any' types in intrinsic signatures. The mangling
56/// of named types is simply their name. Manglings for unnamed types consist
57/// of a prefix ('p' for pointers, 'a' for arrays, 'f_' for functions)
58/// combined with the mangling of their component types. A vararg function
59/// type will have a suffix of 'vararg'. Since function types can contain
60/// other function types, we close a function type mangling with suffix 'f'
61/// which can't be confused with it's prefix. This ensures we don't have
62/// collisions between two unrelated function types. Otherwise, you might
63/// parse ffXX as f(fXX) or f(fX)X. (X is a placeholder for any other type.)
64/// The HasUnnamedType boolean is set if an unnamed type was encountered,
65/// indicating that extra care must be taken to ensure a unique name.
66static std::string getMangledTypeStr(Type *Ty, bool &HasUnnamedType) {
67 std::string Result;
68 if (PointerType *PTyp = dyn_cast<PointerType>(Ty)) {
69 Result += "p" + utostr(PTyp->getAddressSpace());
70 } else if (ArrayType *ATyp = dyn_cast<ArrayType>(Ty)) {
71 Result += "a" + utostr(ATyp->getNumElements()) +
72 getMangledTypeStr(ATyp->getElementType(), HasUnnamedType);
73 } else if (StructType *STyp = dyn_cast<StructType>(Ty)) {
74 if (!STyp->isLiteral()) {
75 Result += "s_";
76 if (STyp->hasName())
77 Result += STyp->getName();
78 else
79 HasUnnamedType = true;
80 } else {
81 Result += "sl_";
82 for (auto *Elem : STyp->elements())
83 Result += getMangledTypeStr(Elem, HasUnnamedType);
84 }
85 // Ensure nested structs are distinguishable.
86 Result += "s";
87 } else if (FunctionType *FT = dyn_cast<FunctionType>(Ty)) {
88 Result += "f_" + getMangledTypeStr(FT->getReturnType(), HasUnnamedType);
89 for (size_t i = 0; i < FT->getNumParams(); i++)
90 Result += getMangledTypeStr(FT->getParamType(i), HasUnnamedType);
91 if (FT->isVarArg())
92 Result += "vararg";
93 // Ensure nested function types are distinguishable.
94 Result += "f";
95 } else if (VectorType *VTy = dyn_cast<VectorType>(Ty)) {
96 ElementCount EC = VTy->getElementCount();
97 if (EC.isScalable())
98 Result += "nx";
99 Result += "v" + utostr(EC.getKnownMinValue()) +
100 getMangledTypeStr(VTy->getElementType(), HasUnnamedType);
101 } else if (TargetExtType *TETy = dyn_cast<TargetExtType>(Ty)) {
102 Result += "t";
103 Result += TETy->getName();
104 for (Type *ParamTy : TETy->type_params())
105 Result += "_" + getMangledTypeStr(ParamTy, HasUnnamedType);
106 for (unsigned IntParam : TETy->int_params())
107 Result += "_" + utostr(IntParam);
108 // Ensure nested target extension types are distinguishable.
109 Result += "t";
110 } else if (Ty) {
111 switch (Ty->getTypeID()) {
112 default:
113 llvm_unreachable("Unhandled type");
114 case Type::VoidTyID:
115 Result += "isVoid";
116 break;
118 Result += "Metadata";
119 break;
120 case Type::HalfTyID:
121 Result += "f16";
122 break;
123 case Type::BFloatTyID:
124 Result += "bf16";
125 break;
126 case Type::FloatTyID:
127 Result += "f32";
128 break;
129 case Type::DoubleTyID:
130 Result += "f64";
131 break;
133 Result += "f80";
134 break;
135 case Type::FP128TyID:
136 Result += "f128";
137 break;
139 Result += "ppcf128";
140 break;
142 Result += "x86amx";
143 break;
145 Result += "i" + utostr(cast<IntegerType>(Ty)->getBitWidth());
146 break;
147 }
148 }
149 return Result;
150}
151
153 Module *M, FunctionType *FT,
154 bool EarlyModuleCheck) {
155
156 assert(Id < Intrinsic::num_intrinsics && "Invalid intrinsic ID!");
157 assert((Tys.empty() || Intrinsic::isOverloaded(Id)) &&
158 "This version of getName is for overloaded intrinsics only");
159 (void)EarlyModuleCheck;
160 assert((!EarlyModuleCheck || M ||
161 !any_of(Tys, [](Type *T) { return isa<PointerType>(T); })) &&
162 "Intrinsic overloading on pointer types need to provide a Module");
163 bool HasUnnamedType = false;
164 std::string Result(Intrinsic::getBaseName(Id));
165 for (Type *Ty : Tys)
166 Result += "." + getMangledTypeStr(Ty, HasUnnamedType);
167 if (HasUnnamedType) {
168 assert(M && "unnamed types need a module");
169 if (!FT)
170 FT = Intrinsic::getType(M->getContext(), Id, Tys);
171 else
172 assert((FT == Intrinsic::getType(M->getContext(), Id, Tys)) &&
173 "Provided FunctionType must match arguments");
174 return M->getUniqueIntrinsicName(Result, Id, FT);
175 }
176 return Result;
177}
178
180 FunctionType *FT) {
181 assert(M && "We need to have a Module");
182 return getIntrinsicNameImpl(Id, Tys, M, FT, true);
183}
184
186 return getIntrinsicNameImpl(Id, Tys, nullptr, nullptr, false);
187}
188
189/// IIT_Info - These are enumerators that describe the entries returned by the
190/// getIntrinsicInfoTableEntries function.
191///
192/// Defined in Intrinsics.td.
194#define GET_INTRINSIC_IITINFO
195#include "llvm/IR/IntrinsicImpl.inc"
196#undef GET_INTRINSIC_IITINFO
197};
198
199static void
200DecodeIITType(unsigned &NextElt, ArrayRef<unsigned char> Infos,
201 IIT_Info LastInfo,
203 using namespace Intrinsic;
204
205 bool IsScalableVector = (LastInfo == IIT_SCALABLE_VEC);
206
207 IIT_Info Info = IIT_Info(Infos[NextElt++]);
208 unsigned StructElts = 2;
209
210 switch (Info) {
211 case IIT_Done:
212 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Void, 0));
213 return;
214 case IIT_VARARG:
215 OutputTable.push_back(IITDescriptor::get(IITDescriptor::VarArg, 0));
216 return;
217 case IIT_MMX:
218 OutputTable.push_back(IITDescriptor::get(IITDescriptor::MMX, 0));
219 return;
220 case IIT_AMX:
221 OutputTable.push_back(IITDescriptor::get(IITDescriptor::AMX, 0));
222 return;
223 case IIT_TOKEN:
224 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Token, 0));
225 return;
226 case IIT_METADATA:
227 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Metadata, 0));
228 return;
229 case IIT_F16:
230 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Half, 0));
231 return;
232 case IIT_BF16:
233 OutputTable.push_back(IITDescriptor::get(IITDescriptor::BFloat, 0));
234 return;
235 case IIT_F32:
236 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Float, 0));
237 return;
238 case IIT_F64:
239 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Double, 0));
240 return;
241 case IIT_F128:
242 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Quad, 0));
243 return;
244 case IIT_PPCF128:
245 OutputTable.push_back(IITDescriptor::get(IITDescriptor::PPCQuad, 0));
246 return;
247 case IIT_I1:
248 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 1));
249 return;
250 case IIT_I2:
251 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 2));
252 return;
253 case IIT_I4:
254 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 4));
255 return;
256 case IIT_AARCH64_SVCOUNT:
257 OutputTable.push_back(IITDescriptor::get(IITDescriptor::AArch64Svcount, 0));
258 return;
259 case IIT_I8:
260 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 8));
261 return;
262 case IIT_I16:
263 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 16));
264 return;
265 case IIT_I32:
266 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 32));
267 return;
268 case IIT_I64:
269 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 64));
270 return;
271 case IIT_I128:
272 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 128));
273 return;
274 case IIT_V1:
275 OutputTable.push_back(IITDescriptor::getVector(1, IsScalableVector));
276 DecodeIITType(NextElt, Infos, Info, OutputTable);
277 return;
278 case IIT_V2:
279 OutputTable.push_back(IITDescriptor::getVector(2, IsScalableVector));
280 DecodeIITType(NextElt, Infos, Info, OutputTable);
281 return;
282 case IIT_V3:
283 OutputTable.push_back(IITDescriptor::getVector(3, IsScalableVector));
284 DecodeIITType(NextElt, Infos, Info, OutputTable);
285 return;
286 case IIT_V4:
287 OutputTable.push_back(IITDescriptor::getVector(4, IsScalableVector));
288 DecodeIITType(NextElt, Infos, Info, OutputTable);
289 return;
290 case IIT_V6:
291 OutputTable.push_back(IITDescriptor::getVector(6, IsScalableVector));
292 DecodeIITType(NextElt, Infos, Info, OutputTable);
293 return;
294 case IIT_V8:
295 OutputTable.push_back(IITDescriptor::getVector(8, IsScalableVector));
296 DecodeIITType(NextElt, Infos, Info, OutputTable);
297 return;
298 case IIT_V10:
299 OutputTable.push_back(IITDescriptor::getVector(10, IsScalableVector));
300 DecodeIITType(NextElt, Infos, Info, OutputTable);
301 return;
302 case IIT_V16:
303 OutputTable.push_back(IITDescriptor::getVector(16, IsScalableVector));
304 DecodeIITType(NextElt, Infos, Info, OutputTable);
305 return;
306 case IIT_V32:
307 OutputTable.push_back(IITDescriptor::getVector(32, IsScalableVector));
308 DecodeIITType(NextElt, Infos, Info, OutputTable);
309 return;
310 case IIT_V64:
311 OutputTable.push_back(IITDescriptor::getVector(64, IsScalableVector));
312 DecodeIITType(NextElt, Infos, Info, OutputTable);
313 return;
314 case IIT_V128:
315 OutputTable.push_back(IITDescriptor::getVector(128, IsScalableVector));
316 DecodeIITType(NextElt, Infos, Info, OutputTable);
317 return;
318 case IIT_V256:
319 OutputTable.push_back(IITDescriptor::getVector(256, IsScalableVector));
320 DecodeIITType(NextElt, Infos, Info, OutputTable);
321 return;
322 case IIT_V512:
323 OutputTable.push_back(IITDescriptor::getVector(512, IsScalableVector));
324 DecodeIITType(NextElt, Infos, Info, OutputTable);
325 return;
326 case IIT_V1024:
327 OutputTable.push_back(IITDescriptor::getVector(1024, IsScalableVector));
328 DecodeIITType(NextElt, Infos, Info, OutputTable);
329 return;
330 case IIT_EXTERNREF:
331 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Pointer, 10));
332 return;
333 case IIT_FUNCREF:
334 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Pointer, 20));
335 return;
336 case IIT_PTR:
337 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Pointer, 0));
338 return;
339 case IIT_ANYPTR: // [ANYPTR addrspace]
340 OutputTable.push_back(
341 IITDescriptor::get(IITDescriptor::Pointer, Infos[NextElt++]));
342 return;
343 case IIT_ARG: {
344 unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
345 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Argument, ArgInfo));
346 return;
347 }
348 case IIT_EXTEND_ARG: {
349 unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
350 OutputTable.push_back(
351 IITDescriptor::get(IITDescriptor::ExtendArgument, ArgInfo));
352 return;
353 }
354 case IIT_TRUNC_ARG: {
355 unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
356 OutputTable.push_back(
357 IITDescriptor::get(IITDescriptor::TruncArgument, ArgInfo));
358 return;
359 }
360 case IIT_HALF_VEC_ARG: {
361 unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
362 OutputTable.push_back(
363 IITDescriptor::get(IITDescriptor::HalfVecArgument, ArgInfo));
364 return;
365 }
366 case IIT_SAME_VEC_WIDTH_ARG: {
367 unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
368 OutputTable.push_back(
369 IITDescriptor::get(IITDescriptor::SameVecWidthArgument, ArgInfo));
370 return;
371 }
372 case IIT_VEC_OF_ANYPTRS_TO_ELT: {
373 unsigned short ArgNo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
374 unsigned short RefNo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
375 OutputTable.push_back(
376 IITDescriptor::get(IITDescriptor::VecOfAnyPtrsToElt, ArgNo, RefNo));
377 return;
378 }
379 case IIT_EMPTYSTRUCT:
380 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Struct, 0));
381 return;
382 case IIT_STRUCT9:
383 ++StructElts;
384 [[fallthrough]];
385 case IIT_STRUCT8:
386 ++StructElts;
387 [[fallthrough]];
388 case IIT_STRUCT7:
389 ++StructElts;
390 [[fallthrough]];
391 case IIT_STRUCT6:
392 ++StructElts;
393 [[fallthrough]];
394 case IIT_STRUCT5:
395 ++StructElts;
396 [[fallthrough]];
397 case IIT_STRUCT4:
398 ++StructElts;
399 [[fallthrough]];
400 case IIT_STRUCT3:
401 ++StructElts;
402 [[fallthrough]];
403 case IIT_STRUCT2: {
404 OutputTable.push_back(
405 IITDescriptor::get(IITDescriptor::Struct, StructElts));
406
407 for (unsigned i = 0; i != StructElts; ++i)
408 DecodeIITType(NextElt, Infos, Info, OutputTable);
409 return;
410 }
411 case IIT_SUBDIVIDE2_ARG: {
412 unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
413 OutputTable.push_back(
414 IITDescriptor::get(IITDescriptor::Subdivide2Argument, ArgInfo));
415 return;
416 }
417 case IIT_SUBDIVIDE4_ARG: {
418 unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
419 OutputTable.push_back(
420 IITDescriptor::get(IITDescriptor::Subdivide4Argument, ArgInfo));
421 return;
422 }
423 case IIT_VEC_ELEMENT: {
424 unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
425 OutputTable.push_back(
426 IITDescriptor::get(IITDescriptor::VecElementArgument, ArgInfo));
427 return;
428 }
429 case IIT_SCALABLE_VEC: {
430 DecodeIITType(NextElt, Infos, Info, OutputTable);
431 return;
432 }
433 case IIT_VEC_OF_BITCASTS_TO_INT: {
434 unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]);
435 OutputTable.push_back(
436 IITDescriptor::get(IITDescriptor::VecOfBitcastsToInt, ArgInfo));
437 return;
438 }
439 }
440 llvm_unreachable("unhandled");
441}
442
443#define GET_INTRINSIC_GENERATOR_GLOBAL
444#include "llvm/IR/IntrinsicImpl.inc"
445#undef GET_INTRINSIC_GENERATOR_GLOBAL
446
449 static_assert(sizeof(IIT_Table[0]) == 2,
450 "Expect 16-bit entries in IIT_Table");
451 // Check to see if the intrinsic's type was expressible by the table.
452 uint16_t TableVal = IIT_Table[id - 1];
453
454 // Decode the TableVal into an array of IITValues.
456 ArrayRef<unsigned char> IITEntries;
457 unsigned NextElt = 0;
458 if (TableVal >> 15) {
459 // This is an offset into the IIT_LongEncodingTable.
460 IITEntries = IIT_LongEncodingTable;
461
462 // Strip sentinel bit.
463 NextElt = TableVal & 0x7fff;
464 } else {
465 // If the entry was encoded into a single word in the table itself, decode
466 // it from an array of nibbles to an array of bytes.
467 do {
468 IITValues.push_back(TableVal & 0xF);
469 TableVal >>= 4;
470 } while (TableVal);
471
472 IITEntries = IITValues;
473 NextElt = 0;
474 }
475
476 // Okay, decode the table into the output vector of IITDescriptors.
477 DecodeIITType(NextElt, IITEntries, IIT_Done, T);
478 while (NextElt != IITEntries.size() && IITEntries[NextElt] != 0)
479 DecodeIITType(NextElt, IITEntries, IIT_Done, T);
480}
481
483 ArrayRef<Type *> Tys, LLVMContext &Context) {
484 using namespace Intrinsic;
485
486 IITDescriptor D = Infos.front();
487 Infos = Infos.slice(1);
488
489 switch (D.Kind) {
490 case IITDescriptor::Void:
491 return Type::getVoidTy(Context);
492 case IITDescriptor::VarArg:
493 return Type::getVoidTy(Context);
494 case IITDescriptor::MMX:
496 case IITDescriptor::AMX:
497 return Type::getX86_AMXTy(Context);
498 case IITDescriptor::Token:
499 return Type::getTokenTy(Context);
500 case IITDescriptor::Metadata:
501 return Type::getMetadataTy(Context);
502 case IITDescriptor::Half:
503 return Type::getHalfTy(Context);
504 case IITDescriptor::BFloat:
505 return Type::getBFloatTy(Context);
506 case IITDescriptor::Float:
507 return Type::getFloatTy(Context);
508 case IITDescriptor::Double:
509 return Type::getDoubleTy(Context);
510 case IITDescriptor::Quad:
511 return Type::getFP128Ty(Context);
512 case IITDescriptor::PPCQuad:
513 return Type::getPPC_FP128Ty(Context);
514 case IITDescriptor::AArch64Svcount:
515 return TargetExtType::get(Context, "aarch64.svcount");
516
517 case IITDescriptor::Integer:
518 return IntegerType::get(Context, D.Integer_Width);
519 case IITDescriptor::Vector:
520 return VectorType::get(DecodeFixedType(Infos, Tys, Context),
521 D.Vector_Width);
522 case IITDescriptor::Pointer:
523 return PointerType::get(Context, D.Pointer_AddressSpace);
524 case IITDescriptor::Struct: {
526 for (unsigned i = 0, e = D.Struct_NumElements; i != e; ++i)
527 Elts.push_back(DecodeFixedType(Infos, Tys, Context));
528 return StructType::get(Context, Elts);
529 }
530 case IITDescriptor::Argument:
531 return Tys[D.getArgumentNumber()];
532 case IITDescriptor::ExtendArgument: {
533 Type *Ty = Tys[D.getArgumentNumber()];
534 if (VectorType *VTy = dyn_cast<VectorType>(Ty))
535 return VectorType::getExtendedElementVectorType(VTy);
536
537 return IntegerType::get(Context, 2 * cast<IntegerType>(Ty)->getBitWidth());
538 }
539 case IITDescriptor::TruncArgument: {
540 Type *Ty = Tys[D.getArgumentNumber()];
541 if (VectorType *VTy = dyn_cast<VectorType>(Ty))
542 return VectorType::getTruncatedElementVectorType(VTy);
543
544 IntegerType *ITy = cast<IntegerType>(Ty);
545 assert(ITy->getBitWidth() % 2 == 0);
546 return IntegerType::get(Context, ITy->getBitWidth() / 2);
547 }
548 case IITDescriptor::Subdivide2Argument:
549 case IITDescriptor::Subdivide4Argument: {
550 Type *Ty = Tys[D.getArgumentNumber()];
551 VectorType *VTy = dyn_cast<VectorType>(Ty);
552 assert(VTy && "Expected an argument of Vector Type");
553 int SubDivs = D.Kind == IITDescriptor::Subdivide2Argument ? 1 : 2;
554 return VectorType::getSubdividedVectorType(VTy, SubDivs);
555 }
556 case IITDescriptor::HalfVecArgument:
557 return VectorType::getHalfElementsVectorType(
558 cast<VectorType>(Tys[D.getArgumentNumber()]));
559 case IITDescriptor::SameVecWidthArgument: {
560 Type *EltTy = DecodeFixedType(Infos, Tys, Context);
561 Type *Ty = Tys[D.getArgumentNumber()];
562 if (auto *VTy = dyn_cast<VectorType>(Ty))
563 return VectorType::get(EltTy, VTy->getElementCount());
564 return EltTy;
565 }
566 case IITDescriptor::VecElementArgument: {
567 Type *Ty = Tys[D.getArgumentNumber()];
568 if (VectorType *VTy = dyn_cast<VectorType>(Ty))
569 return VTy->getElementType();
570 llvm_unreachable("Expected an argument of Vector Type");
571 }
572 case IITDescriptor::VecOfBitcastsToInt: {
573 Type *Ty = Tys[D.getArgumentNumber()];
574 VectorType *VTy = dyn_cast<VectorType>(Ty);
575 assert(VTy && "Expected an argument of Vector Type");
576 return VectorType::getInteger(VTy);
577 }
578 case IITDescriptor::VecOfAnyPtrsToElt:
579 // Return the overloaded type (which determines the pointers address space)
580 return Tys[D.getOverloadArgNumber()];
581 }
582 llvm_unreachable("unhandled");
583}
584
586 ArrayRef<Type *> Tys) {
589
591 Type *ResultTy = DecodeFixedType(TableRef, Tys, Context);
592
594 while (!TableRef.empty())
595 ArgTys.push_back(DecodeFixedType(TableRef, Tys, Context));
596
597 // DecodeFixedType returns Void for IITDescriptor::Void and
598 // IITDescriptor::VarArg If we see void type as the type of the last argument,
599 // it is vararg intrinsic
600 if (!ArgTys.empty() && ArgTys.back()->isVoidTy()) {
601 ArgTys.pop_back();
602 return FunctionType::get(ResultTy, ArgTys, true);
603 }
604 return FunctionType::get(ResultTy, ArgTys, false);
605}
606
608#define GET_INTRINSIC_OVERLOAD_TABLE
609#include "llvm/IR/IntrinsicImpl.inc"
610#undef GET_INTRINSIC_OVERLOAD_TABLE
611}
612
613/// Table of per-target intrinsic name tables.
614#define GET_INTRINSIC_TARGET_DATA
615#include "llvm/IR/IntrinsicImpl.inc"
616#undef GET_INTRINSIC_TARGET_DATA
617
619 return IID > TargetInfos[0].Count;
620}
621
622/// Looks up Name in NameTable via binary search. NameTable must be sorted
623/// and all entries must start with "llvm.". If NameTable contains an exact
624/// match for Name or a prefix of Name followed by a dot, its index in
625/// NameTable is returned. Otherwise, -1 is returned.
628 assert(Name.starts_with("llvm.") && "Unexpected intrinsic prefix");
629 assert(Name.drop_front(5).starts_with(Target) && "Unexpected target");
630
631 // Do successive binary searches of the dotted name components. For
632 // "llvm.gc.experimental.statepoint.p1i8.p1i32", we will find the range of
633 // intrinsics starting with "llvm.gc", then "llvm.gc.experimental", then
634 // "llvm.gc.experimental.statepoint", and then we will stop as the range is
635 // size 1. During the search, we can skip the prefix that we already know is
636 // identical. By using strncmp we consider names with differing suffixes to
637 // be part of the equal range.
638 size_t CmpEnd = 4; // Skip the "llvm" component.
639 if (!Target.empty())
640 CmpEnd += 1 + Target.size(); // skip the .target component.
641
642 const unsigned *Low = NameOffsetTable.begin();
643 const unsigned *High = NameOffsetTable.end();
644 const unsigned *LastLow = Low;
645 while (CmpEnd < Name.size() && High - Low > 0) {
646 size_t CmpStart = CmpEnd;
647 CmpEnd = Name.find('.', CmpStart + 1);
648 CmpEnd = CmpEnd == StringRef::npos ? Name.size() : CmpEnd;
649 auto Cmp = [CmpStart, CmpEnd](auto LHS, auto RHS) {
650 // `equal_range` requires the comparison to work with either side being an
651 // offset or the value. Detect which kind each side is to set up the
652 // compared strings.
653 StringRef LHSStr;
654 if constexpr (std::is_integral_v<decltype(LHS)>) {
655 LHSStr = IntrinsicNameTable[LHS];
656 } else {
657 LHSStr = LHS;
658 }
659 StringRef RHSStr;
660 if constexpr (std::is_integral_v<decltype(RHS)>) {
661 RHSStr = IntrinsicNameTable[RHS];
662 } else {
663 RHSStr = RHS;
664 }
665 return strncmp(LHSStr.data() + CmpStart, RHSStr.data() + CmpStart,
666 CmpEnd - CmpStart) < 0;
667 };
668 LastLow = Low;
669 std::tie(Low, High) = std::equal_range(Low, High, Name.data(), Cmp);
670 }
671 if (High - Low > 0)
672 LastLow = Low;
673
674 if (LastLow == NameOffsetTable.end())
675 return -1;
676 StringRef NameFound = IntrinsicNameTable[*LastLow];
677 if (Name == NameFound ||
678 (Name.starts_with(NameFound) && Name[NameFound.size()] == '.'))
679 return LastLow - NameOffsetTable.begin();
680 return -1;
681}
682
683/// Find the segment of \c IntrinsicNameOffsetTable for intrinsics with the same
684/// target as \c Name, or the generic table if \c Name is not target specific.
685///
686/// Returns the relevant slice of \c IntrinsicNameOffsetTable and the target
687/// name.
688static std::pair<ArrayRef<unsigned>, StringRef>
690 assert(Name.starts_with("llvm."));
691
692 ArrayRef<IntrinsicTargetInfo> Targets(TargetInfos);
693 // Drop "llvm." and take the first dotted component. That will be the target
694 // if this is target specific.
695 StringRef Target = Name.drop_front(5).split('.').first;
696 auto It = partition_point(
697 Targets, [=](const IntrinsicTargetInfo &TI) { return TI.Name < Target; });
698 // We've either found the target or just fall back to the generic set, which
699 // is always first.
700 const auto &TI = It != Targets.end() && It->Name == Target ? *It : Targets[0];
701 return {ArrayRef(&IntrinsicNameOffsetTable[1] + TI.Offset, TI.Count),
702 TI.Name};
703}
704
705/// This does the actual lookup of an intrinsic ID which matches the given
706/// function name.
708 auto [NameOffsetTable, Target] = findTargetSubtable(Name);
709 int Idx = lookupLLVMIntrinsicByName(NameOffsetTable, Name, Target);
710 if (Idx == -1)
712
713 // Intrinsic IDs correspond to the location in IntrinsicNameTable, but we have
714 // an index into a sub-table.
715 int Adjust = NameOffsetTable.data() - IntrinsicNameOffsetTable;
716 Intrinsic::ID ID = static_cast<Intrinsic::ID>(Idx + Adjust);
717
718 // If the intrinsic is not overloaded, require an exact match. If it is
719 // overloaded, require either exact or prefix match.
720 const auto MatchSize = IntrinsicNameTable[NameOffsetTable[Idx]].size();
721 assert(Name.size() >= MatchSize && "Expected either exact or prefix match");
722 bool IsExactMatch = Name.size() == MatchSize;
723 return IsExactMatch || Intrinsic::isOverloaded(ID) ? ID
725}
726
727/// This defines the "Intrinsic::getAttributes(ID id)" method.
728#define GET_INTRINSIC_ATTRIBUTES
729#include "llvm/IR/IntrinsicImpl.inc"
730#undef GET_INTRINSIC_ATTRIBUTES
731
733 ArrayRef<Type *> Tys) {
734 // There can never be multiple globals with the same name of different types,
735 // because intrinsics must be a specific type.
736 auto *FT = getType(M->getContext(), id, Tys);
737 return cast<Function>(
738 M->getOrInsertFunction(
739 Tys.empty() ? getName(id) : getName(id, Tys, M, FT), FT)
740 .getCallee());
741}
742
744 return M->getFunction(getName(id));
745}
746
749 FunctionType *FT) {
750 return M->getFunction(getName(id, Tys, M, FT));
751}
752
753// This defines the "Intrinsic::getIntrinsicForClangBuiltin()" method.
754#define GET_LLVM_INTRINSIC_FOR_CLANG_BUILTIN
755#include "llvm/IR/IntrinsicImpl.inc"
756#undef GET_LLVM_INTRINSIC_FOR_CLANG_BUILTIN
757
758// This defines the "Intrinsic::getIntrinsicForMSBuiltin()" method.
759#define GET_LLVM_INTRINSIC_FOR_MS_BUILTIN
760#include "llvm/IR/IntrinsicImpl.inc"
761#undef GET_LLVM_INTRINSIC_FOR_MS_BUILTIN
762
764 switch (QID) {
765#define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC) \
766 case Intrinsic::INTRINSIC:
767#include "llvm/IR/ConstrainedOps.def"
768#undef INSTRUCTION
769 return true;
770 default:
771 return false;
772 }
773}
774
776 switch (QID) {
777#define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC) \
778 case Intrinsic::INTRINSIC: \
779 return ROUND_MODE == 1;
780#include "llvm/IR/ConstrainedOps.def"
781#undef INSTRUCTION
782 default:
783 return false;
784 }
785}
786
788 std::pair<Type *, ArrayRef<Intrinsic::IITDescriptor>>;
789
790static bool
794 bool IsDeferredCheck) {
795 using namespace Intrinsic;
796
797 // If we ran out of descriptors, there are too many arguments.
798 if (Infos.empty())
799 return true;
800
801 // Do this before slicing off the 'front' part
802 auto InfosRef = Infos;
803 auto DeferCheck = [&DeferredChecks, &InfosRef](Type *T) {
804 DeferredChecks.emplace_back(T, InfosRef);
805 return false;
806 };
807
808 IITDescriptor D = Infos.front();
809 Infos = Infos.slice(1);
810
811 switch (D.Kind) {
812 case IITDescriptor::Void:
813 return !Ty->isVoidTy();
814 case IITDescriptor::VarArg:
815 return true;
816 case IITDescriptor::MMX: {
817 FixedVectorType *VT = dyn_cast<FixedVectorType>(Ty);
818 return !VT || VT->getNumElements() != 1 ||
819 !VT->getElementType()->isIntegerTy(64);
820 }
821 case IITDescriptor::AMX:
822 return !Ty->isX86_AMXTy();
823 case IITDescriptor::Token:
824 return !Ty->isTokenTy();
825 case IITDescriptor::Metadata:
826 return !Ty->isMetadataTy();
827 case IITDescriptor::Half:
828 return !Ty->isHalfTy();
829 case IITDescriptor::BFloat:
830 return !Ty->isBFloatTy();
831 case IITDescriptor::Float:
832 return !Ty->isFloatTy();
833 case IITDescriptor::Double:
834 return !Ty->isDoubleTy();
835 case IITDescriptor::Quad:
836 return !Ty->isFP128Ty();
837 case IITDescriptor::PPCQuad:
838 return !Ty->isPPC_FP128Ty();
839 case IITDescriptor::Integer:
840 return !Ty->isIntegerTy(D.Integer_Width);
841 case IITDescriptor::AArch64Svcount:
842 return !isa<TargetExtType>(Ty) ||
843 cast<TargetExtType>(Ty)->getName() != "aarch64.svcount";
844 case IITDescriptor::Vector: {
845 VectorType *VT = dyn_cast<VectorType>(Ty);
846 return !VT || VT->getElementCount() != D.Vector_Width ||
847 matchIntrinsicType(VT->getElementType(), Infos, ArgTys,
848 DeferredChecks, IsDeferredCheck);
849 }
850 case IITDescriptor::Pointer: {
851 PointerType *PT = dyn_cast<PointerType>(Ty);
852 return !PT || PT->getAddressSpace() != D.Pointer_AddressSpace;
853 }
854
855 case IITDescriptor::Struct: {
856 StructType *ST = dyn_cast<StructType>(Ty);
857 if (!ST || !ST->isLiteral() || ST->isPacked() ||
858 ST->getNumElements() != D.Struct_NumElements)
859 return true;
860
861 for (unsigned i = 0, e = D.Struct_NumElements; i != e; ++i)
862 if (matchIntrinsicType(ST->getElementType(i), Infos, ArgTys,
863 DeferredChecks, IsDeferredCheck))
864 return true;
865 return false;
866 }
867
868 case IITDescriptor::Argument:
869 // If this is the second occurrence of an argument,
870 // verify that the later instance matches the previous instance.
871 if (D.getArgumentNumber() < ArgTys.size())
872 return Ty != ArgTys[D.getArgumentNumber()];
873
874 if (D.getArgumentNumber() > ArgTys.size() ||
875 D.getArgumentKind() == IITDescriptor::AK_MatchType)
876 return IsDeferredCheck || DeferCheck(Ty);
877
878 assert(D.getArgumentNumber() == ArgTys.size() && !IsDeferredCheck &&
879 "Table consistency error");
880 ArgTys.push_back(Ty);
881
882 switch (D.getArgumentKind()) {
883 case IITDescriptor::AK_Any:
884 return false; // Success
885 case IITDescriptor::AK_AnyInteger:
886 return !Ty->isIntOrIntVectorTy();
887 case IITDescriptor::AK_AnyFloat:
888 return !Ty->isFPOrFPVectorTy();
889 case IITDescriptor::AK_AnyVector:
890 return !isa<VectorType>(Ty);
891 case IITDescriptor::AK_AnyPointer:
892 return !isa<PointerType>(Ty);
893 default:
894 break;
895 }
896 llvm_unreachable("all argument kinds not covered");
897
898 case IITDescriptor::ExtendArgument: {
899 // If this is a forward reference, defer the check for later.
900 if (D.getArgumentNumber() >= ArgTys.size())
901 return IsDeferredCheck || DeferCheck(Ty);
902
903 Type *NewTy = ArgTys[D.getArgumentNumber()];
904 if (VectorType *VTy = dyn_cast<VectorType>(NewTy))
905 NewTy = VectorType::getExtendedElementVectorType(VTy);
906 else if (IntegerType *ITy = dyn_cast<IntegerType>(NewTy))
907 NewTy = IntegerType::get(ITy->getContext(), 2 * ITy->getBitWidth());
908 else
909 return true;
910
911 return Ty != NewTy;
912 }
913 case IITDescriptor::TruncArgument: {
914 // If this is a forward reference, defer the check for later.
915 if (D.getArgumentNumber() >= ArgTys.size())
916 return IsDeferredCheck || DeferCheck(Ty);
917
918 Type *NewTy = ArgTys[D.getArgumentNumber()];
919 if (VectorType *VTy = dyn_cast<VectorType>(NewTy))
920 NewTy = VectorType::getTruncatedElementVectorType(VTy);
921 else if (IntegerType *ITy = dyn_cast<IntegerType>(NewTy))
922 NewTy = IntegerType::get(ITy->getContext(), ITy->getBitWidth() / 2);
923 else
924 return true;
925
926 return Ty != NewTy;
927 }
928 case IITDescriptor::HalfVecArgument:
929 // If this is a forward reference, defer the check for later.
930 if (D.getArgumentNumber() >= ArgTys.size())
931 return IsDeferredCheck || DeferCheck(Ty);
932 return !isa<VectorType>(ArgTys[D.getArgumentNumber()]) ||
933 VectorType::getHalfElementsVectorType(
934 cast<VectorType>(ArgTys[D.getArgumentNumber()])) != Ty;
935 case IITDescriptor::SameVecWidthArgument: {
936 if (D.getArgumentNumber() >= ArgTys.size()) {
937 // Defer check and subsequent check for the vector element type.
938 Infos = Infos.slice(1);
939 return IsDeferredCheck || DeferCheck(Ty);
940 }
941 auto *ReferenceType = dyn_cast<VectorType>(ArgTys[D.getArgumentNumber()]);
942 auto *ThisArgType = dyn_cast<VectorType>(Ty);
943 // Both must be vectors of the same number of elements or neither.
944 if ((ReferenceType != nullptr) != (ThisArgType != nullptr))
945 return true;
946 Type *EltTy = Ty;
947 if (ThisArgType) {
948 if (ReferenceType->getElementCount() != ThisArgType->getElementCount())
949 return true;
950 EltTy = ThisArgType->getElementType();
951 }
952 return matchIntrinsicType(EltTy, Infos, ArgTys, DeferredChecks,
953 IsDeferredCheck);
954 }
955 case IITDescriptor::VecOfAnyPtrsToElt: {
956 unsigned RefArgNumber = D.getRefArgNumber();
957 if (RefArgNumber >= ArgTys.size()) {
958 if (IsDeferredCheck)
959 return true;
960 // If forward referencing, already add the pointer-vector type and
961 // defer the checks for later.
962 ArgTys.push_back(Ty);
963 return DeferCheck(Ty);
964 }
965
966 if (!IsDeferredCheck) {
967 assert(D.getOverloadArgNumber() == ArgTys.size() &&
968 "Table consistency error");
969 ArgTys.push_back(Ty);
970 }
971
972 // Verify the overloaded type "matches" the Ref type.
973 // i.e. Ty is a vector with the same width as Ref.
974 // Composed of pointers to the same element type as Ref.
975 auto *ReferenceType = dyn_cast<VectorType>(ArgTys[RefArgNumber]);
976 auto *ThisArgVecTy = dyn_cast<VectorType>(Ty);
977 if (!ThisArgVecTy || !ReferenceType ||
978 (ReferenceType->getElementCount() != ThisArgVecTy->getElementCount()))
979 return true;
980 return !ThisArgVecTy->getElementType()->isPointerTy();
981 }
982 case IITDescriptor::VecElementArgument: {
983 if (D.getArgumentNumber() >= ArgTys.size())
984 return IsDeferredCheck ? true : DeferCheck(Ty);
985 auto *ReferenceType = dyn_cast<VectorType>(ArgTys[D.getArgumentNumber()]);
986 return !ReferenceType || Ty != ReferenceType->getElementType();
987 }
988 case IITDescriptor::Subdivide2Argument:
989 case IITDescriptor::Subdivide4Argument: {
990 // If this is a forward reference, defer the check for later.
991 if (D.getArgumentNumber() >= ArgTys.size())
992 return IsDeferredCheck || DeferCheck(Ty);
993
994 Type *NewTy = ArgTys[D.getArgumentNumber()];
995 if (auto *VTy = dyn_cast<VectorType>(NewTy)) {
996 int SubDivs = D.Kind == IITDescriptor::Subdivide2Argument ? 1 : 2;
997 NewTy = VectorType::getSubdividedVectorType(VTy, SubDivs);
998 return Ty != NewTy;
999 }
1000 return true;
1001 }
1002 case IITDescriptor::VecOfBitcastsToInt: {
1003 if (D.getArgumentNumber() >= ArgTys.size())
1004 return IsDeferredCheck || DeferCheck(Ty);
1005 auto *ReferenceType = dyn_cast<VectorType>(ArgTys[D.getArgumentNumber()]);
1006 auto *ThisArgVecTy = dyn_cast<VectorType>(Ty);
1007 if (!ThisArgVecTy || !ReferenceType)
1008 return true;
1009 return ThisArgVecTy != VectorType::getInteger(ReferenceType);
1010 }
1011 }
1012 llvm_unreachable("unhandled");
1013}
1014
1018 SmallVectorImpl<Type *> &ArgTys) {
1020 if (matchIntrinsicType(FTy->getReturnType(), Infos, ArgTys, DeferredChecks,
1021 false))
1023
1024 unsigned NumDeferredReturnChecks = DeferredChecks.size();
1025
1026 for (auto *Ty : FTy->params())
1027 if (matchIntrinsicType(Ty, Infos, ArgTys, DeferredChecks, false))
1029
1030 for (unsigned I = 0, E = DeferredChecks.size(); I != E; ++I) {
1031 DeferredIntrinsicMatchPair &Check = DeferredChecks[I];
1032 if (matchIntrinsicType(Check.first, Check.second, ArgTys, DeferredChecks,
1033 true))
1034 return I < NumDeferredReturnChecks ? MatchIntrinsicTypes_NoMatchRet
1036 }
1037
1039}
1040
1042 bool isVarArg, ArrayRef<Intrinsic::IITDescriptor> &Infos) {
1043 // If there are no descriptors left, then it can't be a vararg.
1044 if (Infos.empty())
1045 return isVarArg;
1046
1047 // There should be only one descriptor remaining at this point.
1048 if (Infos.size() != 1)
1049 return true;
1050
1051 // Check and verify the descriptor.
1052 IITDescriptor D = Infos.front();
1053 Infos = Infos.slice(1);
1054 if (D.Kind == IITDescriptor::VarArg)
1055 return !isVarArg;
1056
1057 return true;
1058}
1059
1061 SmallVectorImpl<Type *> &ArgTys) {
1062 if (!ID)
1063 return false;
1064
1068
1070 Intrinsic::MatchIntrinsicTypesResult::MatchIntrinsicTypes_Match) {
1071 return false;
1072 }
1074 return false;
1075 return true;
1076}
1077
1079 SmallVectorImpl<Type *> &ArgTys) {
1080 return getIntrinsicSignature(F->getIntrinsicID(), F->getFunctionType(),
1081 ArgTys);
1082}
1083
1086 if (!getIntrinsicSignature(F, ArgTys))
1087 return std::nullopt;
1088
1089 Intrinsic::ID ID = F->getIntrinsicID();
1090 StringRef Name = F->getName();
1091 std::string WantedName =
1092 Intrinsic::getName(ID, ArgTys, F->getParent(), F->getFunctionType());
1093 if (Name == WantedName)
1094 return std::nullopt;
1095
1096 Function *NewDecl = [&] {
1097 if (auto *ExistingGV = F->getParent()->getNamedValue(WantedName)) {
1098 if (auto *ExistingF = dyn_cast<Function>(ExistingGV))
1099 if (ExistingF->getFunctionType() == F->getFunctionType())
1100 return ExistingF;
1101
1102 // The name already exists, but is not a function or has the wrong
1103 // prototype. Make place for the new one by renaming the old version.
1104 // Either this old version will be removed later on or the module is
1105 // invalid and we'll get an error.
1106 ExistingGV->setName(WantedName + ".renamed");
1107 }
1108 return Intrinsic::getOrInsertDeclaration(F->getParent(), ID, ArgTys);
1109 }();
1110
1111 NewDecl->setCallingConv(F->getCallingConv());
1112 assert(NewDecl->getFunctionType() == F->getFunctionType() &&
1113 "Shouldn't change the signature");
1114 return NewDecl;
1115}
basic Basic Alias true
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:791
static std::string getIntrinsicNameImpl(Intrinsic::ID Id, ArrayRef< Type * > Tys, Module *M, FunctionType *FT, bool EarlyModuleCheck)
Definition: Intrinsics.cpp:152
std::pair< Type *, ArrayRef< Intrinsic::IITDescriptor > > DeferredIntrinsicMatchPair
Definition: Intrinsics.cpp:788
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:689
static void DecodeIITType(unsigned &NextElt, ArrayRef< unsigned char > Infos, IIT_Info LastInfo, SmallVectorImpl< Intrinsic::IITDescriptor > &OutputTable)
Definition: Intrinsics.cpp:200
IIT_Info
IIT_Info - These are enumerators that describe the entries returned by the getIntrinsicInfoTableEntri...
Definition: Intrinsics.cpp:193
static Type * DecodeFixedType(ArrayRef< Intrinsic::IITDescriptor > &Infos, ArrayRef< Type * > Tys, LLVMContext &Context)
Definition: Intrinsics.cpp:482
static int lookupLLVMIntrinsicByName(ArrayRef< unsigned > NameOffsetTable, StringRef Name, StringRef Target="")
Looks up Name in NameTable via binary search.
Definition: Intrinsics.cpp:626
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:66
#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)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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:171
iterator end() const
Definition: ArrayRef.h:157
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:168
iterator begin() const
Definition: ArrayRef.h:156
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:163
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:198
Class to represent fixed width SIMD vectors.
Definition: DerivedTypes.h:563
unsigned getNumElements() const
Definition: DerivedTypes.h:606
static FixedVectorType * get(Type *ElementType, unsigned NumElts)
Definition: Type.cpp:791
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:216
void setCallingConv(CallingConv::ID CC)
Definition: Function.h:281
Class to represent integer types.
Definition: DerivedTypes.h:42
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Definition: Type.cpp:311
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:67
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
bool empty() const
Definition: SmallVector.h:81
size_t size() const
Definition: SmallVector.h:78
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:573
reference emplace_back(ArgTypes &&... Args)
Definition: SmallVector.h:937
void push_back(const T &Elt)
Definition: SmallVector.h:413
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1196
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
constexpr size_t size() const
size - Get the string size.
Definition: StringRef.h:150
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition: StringRef.h:144
static constexpr size_t npos
Definition: StringRef.h:53
Class to represent struct types.
Definition: DerivedTypes.h:218
static 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:406
Class to represent target extensions types, which are generally unintrospectable from target-independ...
Definition: DerivedTypes.h:744
static 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:895
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 Type * getHalfTy(LLVMContext &C)
static Type * getDoubleTy(LLVMContext &C)
static Type * getBFloatTy(LLVMContext &C)
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
Definition: Type.h:243
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
Definition: Type.h:153
static Type * getX86_AMXTy(LLVMContext &C)
bool isBFloatTy() const
Return true if this is 'bfloat', a 16-bit bfloat type.
Definition: Type.h:145
static Type * getMetadataTy(LLVMContext &C)
@ 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
bool isFP128Ty() const
Return true if this is 'fp128'.
Definition: Type.h:162
static Type * getVoidTy(LLVMContext &C)
static Type * getFP128Ty(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
static Type * getTokenTy(LLVMContext &C)
bool isX86_AMXTy() const
Return true if this is X86 AMX.
Definition: Type.h:200
static Type * getFloatTy(LLVMContext &C)
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition: Type.h:237
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
bool isFPOrFPVectorTy() const
Return true if this is a FP type or a vector of FP.
Definition: Type.h:225
static Type * getPPC_FP128Ty(LLVMContext &C)
bool isVoidTy() const
Return true if this is 'void'.
Definition: Type.h:139
bool isMetadataTy() const
Return true if this is 'metadata'.
Definition: Type.h:231
void setName(const Twine &Name)
Change the name of the value.
Definition: Value.cpp:377
Type * getElementType() const
Definition: DerivedTypes.h:460
#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
ID ArrayRef< Type * > Tys
Definition: Intrinsics.h:102
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:732
MatchIntrinsicTypesResult matchIntrinsicSignature(FunctionType *FTy, ArrayRef< IITDescriptor > &Infos, SmallVectorImpl< Type * > &ArgTys)
Match the specified function type with the type constraints specified by the .td file.
void getIntrinsicInfoTableEntries(ID id, SmallVectorImpl< IITDescriptor > &T)
Return the IIT table descriptor for the specified intrinsic into an array of IITDescriptors.
Definition: Intrinsics.cpp:447
@ MatchIntrinsicTypes_Match
Definition: Intrinsics.h:230
@ MatchIntrinsicTypes_NoMatchRet
Definition: Intrinsics.h:231
@ MatchIntrinsicTypes_NoMatchArg
Definition: Intrinsics.h:232
std::string getNameNoUnnamedTypes(ID Id, ArrayRef< Type * > Tys)
Return the LLVM name for an intrinsic.
Definition: Intrinsics.cpp:185
std::optional< Function * > remangleIntrinsicFunction(Function *F)
bool hasConstrainedFPRoundingModeOperand(ID QID)
Returns true if the intrinsic ID is for one of the "Constrained Floating-Point Intrinsics" that take ...
Definition: Intrinsics.cpp:775
StringRef getName(ID id)
Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
Definition: Intrinsics.cpp:47
bool isConstrainedFPIntrinsic(ID QID)
Returns true if the intrinsic ID is for one of the "Constrained Floating-Point Intrinsics".
Definition: Intrinsics.cpp:763
ID lookupIntrinsicID(StringRef Name)
This does the actual lookup of an intrinsic ID which matches the given function name.
Definition: Intrinsics.cpp:707
Function * getDeclarationIfExists(Module *M, ID id, ArrayRef< Type * > Tys, FunctionType *FT=nullptr)
This version supports overloaded intrinsics.
Definition: Intrinsics.cpp:747
StringRef getBaseName(ID id)
Return the LLVM name for an intrinsic, without encoded types for overloading, such as "llvm....
Definition: Intrinsics.cpp:42
bool isOverloaded(ID id)
Returns true if the intrinsic can be overloaded.
Definition: Intrinsics.cpp:607
FunctionType * getType(LLVMContext &Context, ID id, ArrayRef< Type * > Tys={})
Return the function type for an intrinsic.
Definition: Intrinsics.cpp:585
bool getIntrinsicSignature(Intrinsic::ID, FunctionType *FT, SmallVectorImpl< Type * > &ArgTys)
Gets the type arguments of an intrinsic call by matching type contraints specified by the ....
bool isTargetIntrinsic(ID IID)
isTargetIntrinsic - Returns true if IID is an intrinsic specific to a certain target.
Definition: Intrinsics.cpp:618
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:2050
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1746
Helper struct shared between Function Specialization and SCCP Solver.
Definition: SCCPSolver.h:41
This is a type descriptor which explains the type requirements of an intrinsic.
Definition: Intrinsics.h:131