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