LLVM 23.0.0git
Intrinsics.cpp
Go to the documentation of this file.
1//===-- Intrinsics.cpp - Intrinsic Function Handling ------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements functions required for supporting intrinsic functions.
10//
11//===----------------------------------------------------------------------===//
12
13#include "llvm/IR/Intrinsics.h"
17#include "llvm/IR/Function.h"
18#include "llvm/IR/IntrinsicsAArch64.h"
19#include "llvm/IR/IntrinsicsAMDGPU.h"
20#include "llvm/IR/IntrinsicsARM.h"
21#include "llvm/IR/IntrinsicsBPF.h"
22#include "llvm/IR/IntrinsicsHexagon.h"
23#include "llvm/IR/IntrinsicsLoongArch.h"
24#include "llvm/IR/IntrinsicsMips.h"
25#include "llvm/IR/IntrinsicsNVPTX.h"
26#include "llvm/IR/IntrinsicsPowerPC.h"
27#include "llvm/IR/IntrinsicsR600.h"
28#include "llvm/IR/IntrinsicsRISCV.h"
29#include "llvm/IR/IntrinsicsS390.h"
30#include "llvm/IR/IntrinsicsSPIRV.h"
31#include "llvm/IR/IntrinsicsVE.h"
32#include "llvm/IR/IntrinsicsX86.h"
33#include "llvm/IR/IntrinsicsXCore.h"
34#include "llvm/IR/Module.h"
36#include "llvm/IR/Type.h"
37
38using namespace llvm;
39
40/// Table of string intrinsic names indexed by enum value.
41#define GET_INTRINSIC_NAME_TABLE
42#include "llvm/IR/IntrinsicImpl.inc"
43
45 assert(id < num_intrinsics && "Invalid intrinsic ID!");
46 return IntrinsicNameTable[IntrinsicNameOffsetTable[id]];
47}
48
50 assert(id < num_intrinsics && "Invalid intrinsic ID!");
52 "This version of getName does not support overloading");
53 return getBaseName(id);
54}
55
56/// Returns a stable mangling for the type specified for use in the name
57/// mangling scheme used by 'any' types in intrinsic signatures. The mangling
58/// of named types is simply their name. Manglings for unnamed types consist
59/// of a prefix ('p' for pointers, 'a' for arrays, 'f_' for functions)
60/// combined with the mangling of their component types. A vararg function
61/// type will have a suffix of 'vararg'. Since function types can contain
62/// other function types, we close a function type mangling with suffix 'f'
63/// which can't be confused with it's prefix. This ensures we don't have
64/// collisions between two unrelated function types. Otherwise, you might
65/// parse ffXX as f(fXX) or f(fX)X. (X is a placeholder for any other type.)
66/// The HasUnnamedType boolean is set if an unnamed type was encountered,
67/// indicating that extra care must be taken to ensure a unique name.
68static std::string getMangledTypeStr(Type *Ty, bool &HasUnnamedType) {
69 std::string Result;
70 if (PointerType *PTyp = dyn_cast<PointerType>(Ty)) {
71 Result += "p" + utostr(PTyp->getAddressSpace());
72 } else if (ArrayType *ATyp = dyn_cast<ArrayType>(Ty)) {
73 Result += "a" + utostr(ATyp->getNumElements()) +
74 getMangledTypeStr(ATyp->getElementType(), HasUnnamedType);
75 } else if (StructType *STyp = dyn_cast<StructType>(Ty)) {
76 if (!STyp->isLiteral()) {
77 Result += "s_";
78 if (STyp->hasName())
79 Result += STyp->getName();
80 else
81 HasUnnamedType = true;
82 } else {
83 Result += "sl_";
84 for (auto *Elem : STyp->elements())
85 Result += getMangledTypeStr(Elem, HasUnnamedType);
86 }
87 // Ensure nested structs are distinguishable.
88 Result += "s";
89 } else if (FunctionType *FT = dyn_cast<FunctionType>(Ty)) {
90 Result += "f_" + getMangledTypeStr(FT->getReturnType(), HasUnnamedType);
91 for (size_t i = 0; i < FT->getNumParams(); i++)
92 Result += getMangledTypeStr(FT->getParamType(i), HasUnnamedType);
93 if (FT->isVarArg())
94 Result += "vararg";
95 // Ensure nested function types are distinguishable.
96 Result += "f";
97 } else if (VectorType *VTy = dyn_cast<VectorType>(Ty)) {
98 ElementCount EC = VTy->getElementCount();
99 if (EC.isScalable())
100 Result += "nx";
101 Result += "v" + utostr(EC.getKnownMinValue()) +
102 getMangledTypeStr(VTy->getElementType(), HasUnnamedType);
103 } else if (TargetExtType *TETy = dyn_cast<TargetExtType>(Ty)) {
104 Result += "t";
105 Result += TETy->getName();
106 for (Type *ParamTy : TETy->type_params())
107 Result += "_" + getMangledTypeStr(ParamTy, HasUnnamedType);
108 for (unsigned IntParam : TETy->int_params())
109 Result += "_" + utostr(IntParam);
110 // Ensure nested target extension types are distinguishable.
111 Result += "t";
112 } else if (Ty) {
113 switch (Ty->getTypeID()) {
114 default:
115 llvm_unreachable("Unhandled type");
116 case Type::VoidTyID:
117 Result += "isVoid";
118 break;
120 Result += "Metadata";
121 break;
122 case Type::HalfTyID:
123 Result += "f16";
124 break;
125 case Type::BFloatTyID:
126 Result += "bf16";
127 break;
128 case Type::FloatTyID:
129 Result += "f32";
130 break;
131 case Type::DoubleTyID:
132 Result += "f64";
133 break;
135 Result += "f80";
136 break;
137 case Type::FP128TyID:
138 Result += "f128";
139 break;
141 Result += "ppcf128";
142 break;
144 Result += "x86amx";
145 break;
147 Result += "i" + utostr(cast<IntegerType>(Ty)->getBitWidth());
148 break;
149 case Type::ByteTyID:
150 Result += "b" + utostr(cast<ByteType>(Ty)->getBitWidth());
151 break;
152 }
153 }
154 return Result;
155}
156
158 ArrayRef<Type *> OverloadTys, Module *M,
159 FunctionType *FT,
160 bool EarlyModuleCheck) {
161
162 assert(Id < Intrinsic::num_intrinsics && "Invalid intrinsic ID!");
163 assert((OverloadTys.empty() || Intrinsic::isOverloaded(Id)) &&
164 "This version of getName is for overloaded intrinsics only");
165 (void)EarlyModuleCheck;
166 assert((!EarlyModuleCheck || M ||
167 !any_of(OverloadTys, llvm::IsaPred<PointerType>)) &&
168 "Intrinsic overloading on pointer types need to provide a Module");
169 bool HasUnnamedType = false;
170 std::string Result(Intrinsic::getBaseName(Id));
171 for (Type *Ty : OverloadTys)
172 Result += "." + getMangledTypeStr(Ty, HasUnnamedType);
173 if (HasUnnamedType) {
174 assert(M && "unnamed types need a module");
175 if (!FT)
176 FT = Intrinsic::getType(M->getContext(), Id, OverloadTys);
177 else
178 assert(FT == Intrinsic::getType(M->getContext(), Id, OverloadTys) &&
179 "Provided FunctionType must match arguments");
180 return M->getUniqueIntrinsicName(Result, Id, FT);
181 }
182 return Result;
183}
184
185std::string Intrinsic::getName(ID Id, ArrayRef<Type *> OverloadTys, Module *M,
186 FunctionType *FT) {
187 assert(M && "We need to have a Module");
188 return getIntrinsicNameImpl(Id, OverloadTys, M, FT, true);
189}
190
192 ArrayRef<Type *> OverloadTys) {
193 return getIntrinsicNameImpl(Id, OverloadTys, nullptr, nullptr, false);
194}
195
196/// IIT_Info - These are enumerators that describe the entries returned by the
197/// getIntrinsicInfoTableEntries function.
198///
199/// Defined in Intrinsics.td.
201#define GET_INTRINSIC_IITINFO
202#include "llvm/IR/IntrinsicImpl.inc"
203};
204
205static_assert(IIT_Done == 0, "IIT_Done expected to be 0");
206
207static void
208DecodeIITType(unsigned &NextElt, ArrayRef<unsigned char> Infos,
210 using namespace Intrinsic;
211
212 auto IsScalableVector = [&]() {
213 IIT_Info NextInfo = IIT_Info(Infos[NextElt]);
214 if (NextInfo != IIT_SCALABLE_VEC)
215 return false;
216 // Eat the IIT_SCALABLE_VEC token.
217 ++NextElt;
218 return true;
219 };
220
221 IIT_Info Info = IIT_Info(Infos[NextElt++]);
222
223 switch (Info) {
224 case IIT_Done:
225 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Void, 0));
226 return;
227 case IIT_VARARG:
228 OutputTable.push_back(IITDescriptor::get(IITDescriptor::VarArg, 0));
229 return;
230 case IIT_MMX:
231 OutputTable.push_back(IITDescriptor::get(IITDescriptor::MMX, 0));
232 return;
233 case IIT_AMX:
234 OutputTable.push_back(IITDescriptor::get(IITDescriptor::AMX, 0));
235 return;
236 case IIT_TOKEN:
237 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Token, 0));
238 return;
239 case IIT_METADATA:
240 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Metadata, 0));
241 return;
242 case IIT_F16:
243 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Half, 0));
244 return;
245 case IIT_BF16:
246 OutputTable.push_back(IITDescriptor::get(IITDescriptor::BFloat, 0));
247 return;
248 case IIT_F32:
249 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Float, 0));
250 return;
251 case IIT_F64:
252 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Double, 0));
253 return;
254 case IIT_F128:
255 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Quad, 0));
256 return;
257 case IIT_PPCF128:
258 OutputTable.push_back(IITDescriptor::get(IITDescriptor::PPCQuad, 0));
259 return;
260 case IIT_I1:
261 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 1));
262 return;
263 case IIT_I2:
264 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 2));
265 return;
266 case IIT_I4:
267 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 4));
268 return;
269 case IIT_AARCH64_SVCOUNT:
270 OutputTable.push_back(IITDescriptor::get(IITDescriptor::AArch64Svcount, 0));
271 return;
272 case IIT_I8:
273 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 8));
274 return;
275 case IIT_I16:
276 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 16));
277 return;
278 case IIT_I32:
279 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 32));
280 return;
281 case IIT_I64:
282 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 64));
283 return;
284 case IIT_I128:
285 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 128));
286 return;
287 case IIT_V1:
288 OutputTable.push_back(IITDescriptor::getVector(1, IsScalableVector()));
289 DecodeIITType(NextElt, Infos, OutputTable);
290 return;
291 case IIT_V2:
292 OutputTable.push_back(IITDescriptor::getVector(2, IsScalableVector()));
293 DecodeIITType(NextElt, Infos, OutputTable);
294 return;
295 case IIT_V3:
296 OutputTable.push_back(IITDescriptor::getVector(3, IsScalableVector()));
297 DecodeIITType(NextElt, Infos, OutputTable);
298 return;
299 case IIT_V4:
300 OutputTable.push_back(IITDescriptor::getVector(4, IsScalableVector()));
301 DecodeIITType(NextElt, Infos, OutputTable);
302 return;
303 case IIT_V6:
304 OutputTable.push_back(IITDescriptor::getVector(6, IsScalableVector()));
305 DecodeIITType(NextElt, Infos, OutputTable);
306 return;
307 case IIT_V8:
308 OutputTable.push_back(IITDescriptor::getVector(8, IsScalableVector()));
309 DecodeIITType(NextElt, Infos, OutputTable);
310 return;
311 case IIT_V10:
312 OutputTable.push_back(IITDescriptor::getVector(10, IsScalableVector()));
313 DecodeIITType(NextElt, Infos, OutputTable);
314 return;
315 case IIT_V16:
316 OutputTable.push_back(IITDescriptor::getVector(16, IsScalableVector()));
317 DecodeIITType(NextElt, Infos, OutputTable);
318 return;
319 case IIT_V32:
320 OutputTable.push_back(IITDescriptor::getVector(32, IsScalableVector()));
321 DecodeIITType(NextElt, Infos, OutputTable);
322 return;
323 case IIT_V64:
324 OutputTable.push_back(IITDescriptor::getVector(64, IsScalableVector()));
325 DecodeIITType(NextElt, Infos, OutputTable);
326 return;
327 case IIT_V128:
328 OutputTable.push_back(IITDescriptor::getVector(128, IsScalableVector()));
329 DecodeIITType(NextElt, Infos, OutputTable);
330 return;
331 case IIT_V256:
332 OutputTable.push_back(IITDescriptor::getVector(256, IsScalableVector()));
333 DecodeIITType(NextElt, Infos, OutputTable);
334 return;
335 case IIT_V512:
336 OutputTable.push_back(IITDescriptor::getVector(512, IsScalableVector()));
337 DecodeIITType(NextElt, Infos, OutputTable);
338 return;
339 case IIT_V1024:
340 OutputTable.push_back(IITDescriptor::getVector(1024, IsScalableVector()));
341 DecodeIITType(NextElt, Infos, OutputTable);
342 return;
343 case IIT_V2048:
344 OutputTable.push_back(IITDescriptor::getVector(2048, IsScalableVector()));
345 DecodeIITType(NextElt, Infos, OutputTable);
346 return;
347 case IIT_V4096:
348 OutputTable.push_back(IITDescriptor::getVector(4096, IsScalableVector()));
349 DecodeIITType(NextElt, Infos, OutputTable);
350 return;
351 case IIT_EXTERNREF:
352 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Pointer, 10));
353 return;
354 case IIT_FUNCREF:
355 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Pointer, 20));
356 return;
357 case IIT_PTR:
358 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Pointer, 0));
359 return;
360 case IIT_PTR_AS: // pointer with address space.
361 OutputTable.push_back(
362 IITDescriptor::get(IITDescriptor::Pointer, Infos[NextElt++]));
363 return;
364 case IIT_ANY: {
365 unsigned OverloadInfo = Infos[NextElt++];
366 OutputTable.push_back(
367 IITDescriptor::get(IITDescriptor::Overloaded, OverloadInfo));
368 return;
369 }
370 case IIT_EXTEND_ARG: {
371 unsigned OverloadIndex = Infos[NextElt++];
372 OutputTable.push_back(
373 IITDescriptor::get(IITDescriptor::Extend, OverloadIndex));
374 return;
375 }
376 case IIT_TRUNC_ARG: {
377 unsigned OverloadIndex = Infos[NextElt++];
378 OutputTable.push_back(
379 IITDescriptor::get(IITDescriptor::Trunc, OverloadIndex));
380 return;
381 }
382 case IIT_ONE_NTH_ELTS_VEC_ARG: {
383 unsigned short OverloadIndex = Infos[NextElt++];
384 unsigned short N = Infos[NextElt++];
385 OutputTable.push_back(IITDescriptor::get(IITDescriptor::OneNthEltsVec,
386 /*Hi=*/N, /*Lo=*/OverloadIndex));
387 return;
388 }
389 case IIT_SAME_VEC_WIDTH_ARG: {
390 unsigned OverloadIndex = Infos[NextElt++];
391 OutputTable.push_back(
392 IITDescriptor::get(IITDescriptor::SameVecWidth, OverloadIndex));
393 return;
394 }
395 case IIT_VEC_OF_ANYPTRS_TO_ELT: {
396 unsigned short OverloadIndex = Infos[NextElt++];
397 unsigned short RefOverloadIndex = Infos[NextElt++];
398 OutputTable.push_back(IITDescriptor::get(IITDescriptor::VecOfAnyPtrsToElt,
399 /*Hi=*/RefOverloadIndex,
400 /*Lo=*/OverloadIndex));
401 return;
402 }
403 case IIT_STRUCT: {
404 unsigned StructElts = Infos[NextElt++] + 2;
405
406 OutputTable.push_back(
407 IITDescriptor::get(IITDescriptor::Struct, StructElts));
408
409 for (unsigned i = 0; i != StructElts; ++i)
410 DecodeIITType(NextElt, Infos, OutputTable);
411 return;
412 }
413 case IIT_SUBDIVIDE2_ARG: {
414 unsigned OverloadIndex = Infos[NextElt++];
415 OutputTable.push_back(
416 IITDescriptor::get(IITDescriptor::Subdivide2, OverloadIndex));
417 return;
418 }
419 case IIT_SUBDIVIDE4_ARG: {
420 unsigned OverloadIndex = Infos[NextElt++];
421 OutputTable.push_back(
422 IITDescriptor::get(IITDescriptor::Subdivide4, OverloadIndex));
423 return;
424 }
425 case IIT_VEC_ELEMENT: {
426 unsigned OverloadIndex = Infos[NextElt++];
427 OutputTable.push_back(
428 IITDescriptor::get(IITDescriptor::VecElement, OverloadIndex));
429 return;
430 }
431 case IIT_VEC_OF_BITCASTS_TO_INT: {
432 unsigned OverloadIndex = Infos[NextElt++];
433 OutputTable.push_back(
434 IITDescriptor::get(IITDescriptor::VecOfBitcastsToInt, OverloadIndex));
435 return;
436 }
437 case IIT_SCALABLE_VEC:
438 break;
439 }
440 llvm_unreachable("unhandled");
441}
442
443#define GET_INTRINSIC_GENERATOR_GLOBAL
444#include "llvm/IR/IntrinsicImpl.inc"
445
448 // Note that `FixedEncodingTy` is defined in IntrinsicImpl.inc and can be
449 // uint16_t or uint32_t based on the the value of `Use16BitFixedEncoding` in
450 // IntrinsicEmitter.cpp.
451 constexpr unsigned FixedEncodingBits = sizeof(FixedEncodingTy) * CHAR_BIT;
452 constexpr unsigned MSBPosition = FixedEncodingBits - 1;
453 // Mask with all bits 1 except the most significant bit.
454 constexpr unsigned Mask = (1U << MSBPosition) - 1;
455
456 FixedEncodingTy TableVal = IIT_Table[id - 1];
457
458 // Array to hold the inlined fixed encoding values expanded from nibbles to
459 // bytes. Its size can be be atmost FixedEncodingBits / 4 i.e., number
460 // of nibbles that can fit in `FixedEncodingTy` + 1 (the IIT_Done terminator
461 // that is not explicitly encoded). Note that if there are trailing 0 bytes
462 // in the encoding (for example, payload following one of the IIT tokens),
463 // the inlined encoding does not encode the actual size of the encoding, so
464 // we always assume its size of this maximum length possible, followed by the
465 // IIT_Done terminator token (whose value is 0).
466 unsigned char IITValues[FixedEncodingBits / 4 + 1] = {0};
467
468 ArrayRef<unsigned char> IITEntries;
469 unsigned NextElt = 0;
470 // Check to see if the intrinsic's type was inlined in the fixed encoding
471 // table.
472 if (TableVal >> MSBPosition) {
473 // This is an offset into the IIT_LongEncodingTable.
474 IITEntries = IIT_LongEncodingTable;
475
476 // Strip sentinel bit.
477 NextElt = TableVal & Mask;
478 } else {
479 // If the entry was encoded into a single word in the table itself, decode
480 // it from an array of nibbles to an array of bytes.
481 do {
482 IITValues[NextElt++] = TableVal & 0xF;
483 TableVal >>= 4;
484 } while (TableVal);
485
486 IITEntries = IITValues;
487 NextElt = 0;
488 }
489
490 // Okay, decode the table into the output vector of IITDescriptors.
491 DecodeIITType(NextElt, IITEntries, T);
492 while (IITEntries[NextElt] != IIT_Done)
493 DecodeIITType(NextElt, IITEntries, T);
494}
495
497 ArrayRef<Type *> OverloadTys,
498 LLVMContext &Context) {
499 using namespace Intrinsic;
500
501 IITDescriptor D = Infos.consume_front();
502
503 switch (D.Kind) {
504 case IITDescriptor::Void:
505 return Type::getVoidTy(Context);
506 case IITDescriptor::VarArg:
507 return Type::getVoidTy(Context);
508 case IITDescriptor::MMX:
510 case IITDescriptor::AMX:
511 return Type::getX86_AMXTy(Context);
512 case IITDescriptor::Token:
513 return Type::getTokenTy(Context);
514 case IITDescriptor::Metadata:
515 return Type::getMetadataTy(Context);
516 case IITDescriptor::Half:
517 return Type::getHalfTy(Context);
518 case IITDescriptor::BFloat:
519 return Type::getBFloatTy(Context);
520 case IITDescriptor::Float:
521 return Type::getFloatTy(Context);
522 case IITDescriptor::Double:
523 return Type::getDoubleTy(Context);
524 case IITDescriptor::Quad:
525 return Type::getFP128Ty(Context);
526 case IITDescriptor::PPCQuad:
527 return Type::getPPC_FP128Ty(Context);
528 case IITDescriptor::AArch64Svcount:
529 return TargetExtType::get(Context, "aarch64.svcount");
530
531 case IITDescriptor::Integer:
532 return IntegerType::get(Context, D.IntegerWidth);
533 case IITDescriptor::Vector:
534 return VectorType::get(DecodeFixedType(Infos, OverloadTys, Context),
535 D.VectorWidth);
536 case IITDescriptor::Pointer:
537 return PointerType::get(Context, D.PointerAddressSpace);
538 case IITDescriptor::Struct: {
540 for (unsigned i = 0, e = D.StructNumElements; i != e; ++i)
541 Elts.push_back(DecodeFixedType(Infos, OverloadTys, Context));
542 return StructType::get(Context, Elts);
543 }
544 // For any overload kind or partially dependent type, substitute it with the
545 // corresponding concrete type from OverloadTys.
546 case IITDescriptor::Overloaded:
547 case IITDescriptor::VecOfAnyPtrsToElt:
548 return OverloadTys[D.getOverloadIndex()];
549 case IITDescriptor::Extend: {
550 Type *Ty = OverloadTys[D.getOverloadIndex()];
551 if (VectorType *VTy = dyn_cast<VectorType>(Ty))
553
554 return IntegerType::get(Context, 2 * cast<IntegerType>(Ty)->getBitWidth());
555 }
556 case IITDescriptor::Trunc: {
557 Type *Ty = OverloadTys[D.getOverloadIndex()];
558 if (VectorType *VTy = dyn_cast<VectorType>(Ty))
560
562 assert(ITy->getBitWidth() % 2 == 0);
563 return IntegerType::get(Context, ITy->getBitWidth() / 2);
564 }
565 case IITDescriptor::Subdivide2:
566 case IITDescriptor::Subdivide4: {
567 Type *Ty = OverloadTys[D.getOverloadIndex()];
569 assert(VTy && "Expected overload type to be a Vector Type");
570 int SubDivs = D.Kind == IITDescriptor::Subdivide2 ? 1 : 2;
571 return VectorType::getSubdividedVectorType(VTy, SubDivs);
572 }
573 case IITDescriptor::OneNthEltsVec:
575 cast<VectorType>(OverloadTys[D.getOverloadIndex()]),
576 D.getVectorDivisor());
577 case IITDescriptor::SameVecWidth: {
578 Type *EltTy = DecodeFixedType(Infos, OverloadTys, Context);
579 Type *Ty = OverloadTys[D.getOverloadIndex()];
580 if (auto *VTy = dyn_cast<VectorType>(Ty))
581 return VectorType::get(EltTy, VTy->getElementCount());
582 return EltTy;
583 }
584 case IITDescriptor::VecElement: {
585 Type *Ty = OverloadTys[D.getOverloadIndex()];
586 if (VectorType *VTy = dyn_cast<VectorType>(Ty))
587 return VTy->getElementType();
588 llvm_unreachable("Expected overload type to be a Vector Type");
589 }
590 case IITDescriptor::VecOfBitcastsToInt: {
591 Type *Ty = OverloadTys[D.getOverloadIndex()];
593 assert(VTy && "Expected overload type to be a Vector Type");
594 return VectorType::getInteger(VTy);
595 }
596 }
597 llvm_unreachable("unhandled");
598}
599
601 ArrayRef<Type *> OverloadTys) {
604
606 Type *ResultTy = DecodeFixedType(TableRef, OverloadTys, Context);
607
609 while (!TableRef.empty())
610 ArgTys.push_back(DecodeFixedType(TableRef, OverloadTys, Context));
611
612 // VarArg intrinsics encode a void type as the last argument type. Detect that
613 // and then drop the void argument.
614 bool IsVarArg = false;
615 if (!ArgTys.empty() && ArgTys.back()->isVoidTy()) {
616 ArgTys.pop_back();
617 IsVarArg = true;
618 }
619 return FunctionType::get(ResultTy, ArgTys, IsVarArg);
620}
621
623#define GET_INTRINSIC_OVERLOAD_TABLE
624#include "llvm/IR/IntrinsicImpl.inc"
625}
626
628#define GET_INTRINSIC_SCALARIZABLE_TABLE
629#include "llvm/IR/IntrinsicImpl.inc"
630}
631
633#define GET_INTRINSIC_PRETTY_PRINT_TABLE
634#include "llvm/IR/IntrinsicImpl.inc"
635}
636
637/// Table of per-target intrinsic name tables.
638#define GET_INTRINSIC_TARGET_DATA
639#include "llvm/IR/IntrinsicImpl.inc"
640
642 return IID > TargetInfos[0].Count;
643}
644
645/// Looks up Name in NameTable via binary search. NameTable must be sorted
646/// and all entries must start with "llvm.". If NameTable contains an exact
647/// match for Name or a prefix of Name followed by a dot, its index in
648/// NameTable is returned. Otherwise, -1 is returned.
650 StringRef Name, StringRef Target = "") {
651 assert(Name.starts_with("llvm.") && "Unexpected intrinsic prefix");
652 assert(Name.drop_front(5).starts_with(Target) && "Unexpected target");
653
654 // Do successive binary searches of the dotted name components. For
655 // "llvm.gc.experimental.statepoint.p1i8.p1i32", we will find the range of
656 // intrinsics starting with "llvm.gc", then "llvm.gc.experimental", then
657 // "llvm.gc.experimental.statepoint", and then we will stop as the range is
658 // size 1. During the search, we can skip the prefix that we already know is
659 // identical. By using strncmp we consider names with differing suffixes to
660 // be part of the equal range.
661 size_t CmpEnd = 4; // Skip the "llvm" component.
662 if (!Target.empty())
663 CmpEnd += 1 + Target.size(); // skip the .target component.
664
665 const unsigned *Low = NameOffsetTable.begin();
666 const unsigned *High = NameOffsetTable.end();
667 const unsigned *LastLow = Low;
668 while (CmpEnd < Name.size() && High - Low > 0) {
669 size_t CmpStart = CmpEnd;
670 CmpEnd = Name.find('.', CmpStart + 1);
671 CmpEnd = CmpEnd == StringRef::npos ? Name.size() : CmpEnd;
672 auto Cmp = [CmpStart, CmpEnd](auto LHS, auto RHS) {
673 // `equal_range` requires the comparison to work with either side being an
674 // offset or the value. Detect which kind each side is to set up the
675 // compared strings.
676 const char *LHSStr;
677 if constexpr (std::is_integral_v<decltype(LHS)>)
678 LHSStr = IntrinsicNameTable.getCString(LHS);
679 else
680 LHSStr = LHS;
681
682 const char *RHSStr;
683 if constexpr (std::is_integral_v<decltype(RHS)>)
684 RHSStr = IntrinsicNameTable.getCString(RHS);
685 else
686 RHSStr = RHS;
687
688 return strncmp(LHSStr + CmpStart, RHSStr + CmpStart, CmpEnd - CmpStart) <
689 0;
690 };
691 LastLow = Low;
692 std::tie(Low, High) = std::equal_range(Low, High, Name.data(), Cmp);
693 }
694 if (High - Low > 0)
695 LastLow = Low;
696
697 if (LastLow == NameOffsetTable.end())
698 return -1;
699 StringRef NameFound = IntrinsicNameTable[*LastLow];
700 if (Name == NameFound ||
701 (Name.starts_with(NameFound) && Name[NameFound.size()] == '.'))
702 return LastLow - NameOffsetTable.begin();
703 return -1;
704}
705
706/// Find the segment of \c IntrinsicNameOffsetTable for intrinsics with the same
707/// target as \c Name, or the generic table if \c Name is not target specific.
708///
709/// Returns the relevant slice of \c IntrinsicNameOffsetTable and the target
710/// name.
711static std::pair<ArrayRef<unsigned>, StringRef>
713 assert(Name.starts_with("llvm."));
714
715 ArrayRef<IntrinsicTargetInfo> Targets(TargetInfos);
716 // Drop "llvm." and take the first dotted component. That will be the target
717 // if this is target specific.
718 StringRef Target = Name.drop_front(5).split('.').first;
719 auto It = partition_point(
720 Targets, [=](const IntrinsicTargetInfo &TI) { return TI.Name < Target; });
721 // We've either found the target or just fall back to the generic set, which
722 // is always first.
723 const auto &TI = It != Targets.end() && It->Name == Target ? *It : Targets[0];
724 return {ArrayRef(&IntrinsicNameOffsetTable[1] + TI.Offset, TI.Count),
725 TI.Name};
726}
727
728/// This does the actual lookup of an intrinsic ID which matches the given
729/// function name.
731 auto [NameOffsetTable, Target] = findTargetSubtable(Name);
732 int Idx = lookupLLVMIntrinsicByName(NameOffsetTable, Name, Target);
733 if (Idx == -1)
735
736 // Intrinsic IDs correspond to the location in IntrinsicNameTable, but we have
737 // an index into a sub-table.
738 int Adjust = NameOffsetTable.data() - IntrinsicNameOffsetTable;
739 Intrinsic::ID ID = static_cast<Intrinsic::ID>(Idx + Adjust);
740
741 // If the intrinsic is not overloaded, require an exact match. If it is
742 // overloaded, require either exact or prefix match.
743 const auto MatchSize = IntrinsicNameTable[NameOffsetTable[Idx]].size();
744 assert(Name.size() >= MatchSize && "Expected either exact or prefix match");
745 bool IsExactMatch = Name.size() == MatchSize;
746 return IsExactMatch || Intrinsic::isOverloaded(ID) ? ID
748}
749
750/// This defines the "Intrinsic::getAttributes(ID id)" method.
751#define GET_INTRINSIC_ATTRIBUTES
752#include "llvm/IR/IntrinsicImpl.inc"
753
754static Function *
756 ArrayRef<Type *> OverloadTys,
757 FunctionType *FT) {
758 std::string Name = OverloadTys.empty()
759 ? Intrinsic::getName(id).str()
760 : Intrinsic::getName(id, OverloadTys, M, FT);
761 Function *F = cast<Function>(M->getOrInsertFunction(Name, FT).getCallee());
762 if (F->getFunctionType() == FT)
763 return F;
764
765 // It's possible that a declaration for this intrinsic already exists with an
766 // incorrect signature, if the signature has changed, but this particular
767 // declaration has not been auto-upgraded yet. In that case, rename the
768 // invalid declaration and insert a new one with the correct signature. The
769 // invalid declaration will get upgraded later.
770 F->setName(F->getName() + ".invalid");
771 return cast<Function>(M->getOrInsertFunction(Name, FT).getCallee());
772}
773
775 ArrayRef<Type *> OverloadTys) {
776 // There can never be multiple globals with the same name of different types,
777 // because intrinsics must be a specific type.
778 FunctionType *FT = getType(M->getContext(), id, OverloadTys);
779 return getOrInsertIntrinsicDeclarationImpl(M, id, OverloadTys, FT);
780}
781
783 bool Consume);
784static bool isSignatureValid(FunctionType *FTy,
786 SmallVectorImpl<Type *> &OverloadTys,
787 raw_ostream &OS);
788
790 ArrayRef<Type *> ArgTys) {
791 // If the intrinsic is not overloaded, use the non-overloaded version.
793 return getOrInsertDeclaration(M, id);
794
795 // Get the intrinsic signature metadata.
799 bool IsVarArg = isIntrinsicVarArg(TableRef, /*Consume=*/false);
800
801 FunctionType *FTy = FunctionType::get(RetTy, ArgTys, IsVarArg);
802
803 // Automatically determine the overloaded types.
804 SmallVector<Type *, 4> OverloadTys;
805 [[maybe_unused]] bool IsValid =
806 ::isSignatureValid(FTy, TableRef, OverloadTys, nulls());
807 assert(IsValid && "intrinsic signature mismatch");
808 return getOrInsertIntrinsicDeclarationImpl(M, id, OverloadTys, FTy);
809}
810
812 return M->getFunction(getName(id));
813}
814
816 ArrayRef<Type *> OverloadTys,
817 FunctionType *FT) {
818 return M->getFunction(getName(id, OverloadTys, M, FT));
819}
820
821// This defines the "Intrinsic::getIntrinsicForClangBuiltin()" method.
822#define GET_LLVM_INTRINSIC_FOR_CLANG_BUILTIN
823#include "llvm/IR/IntrinsicImpl.inc"
824
825// This defines the "Intrinsic::getIntrinsicForMSBuiltin()" method.
826#define GET_LLVM_INTRINSIC_FOR_MS_BUILTIN
827#include "llvm/IR/IntrinsicImpl.inc"
828
830 switch (QID) {
831#define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC) \
832 case Intrinsic::INTRINSIC:
833#include "llvm/IR/ConstrainedOps.def"
834#undef INSTRUCTION
835 return true;
836 default:
837 return false;
838 }
839}
840
842 switch (QID) {
843#define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC) \
844 case Intrinsic::INTRINSIC: \
845 return ROUND_MODE == 1;
846#include "llvm/IR/ConstrainedOps.def"
847#undef INSTRUCTION
848 default:
849 return false;
850 }
851}
852
854 std::pair<Type *, ArrayRef<Intrinsic::IITDescriptor>>;
855
856static bool
858 SmallVectorImpl<Type *> &OverloadTys,
860 bool IsDeferredCheck) {
861 using namespace Intrinsic;
862
863 // If we ran out of descriptors, there are too many arguments.
864 if (Infos.empty())
865 return true;
866
867 // Do this before slicing off the 'front' part
868 auto InfosRef = Infos;
869 auto DeferCheck = [&DeferredChecks, &InfosRef](Type *T) {
870 DeferredChecks.emplace_back(T, InfosRef);
871 return false;
872 };
873
874 IITDescriptor D = Infos.consume_front();
875
876 switch (D.Kind) {
877 case IITDescriptor::Void:
878 return !Ty->isVoidTy();
879 case IITDescriptor::VarArg:
880 return true;
881 case IITDescriptor::MMX: {
883 return !VT || VT->getNumElements() != 1 ||
884 !VT->getElementType()->isIntegerTy(64);
885 }
886 case IITDescriptor::AMX:
887 return !Ty->isX86_AMXTy();
888 case IITDescriptor::Token:
889 return !Ty->isTokenTy();
890 case IITDescriptor::Metadata:
891 return !Ty->isMetadataTy();
892 case IITDescriptor::Half:
893 return !Ty->isHalfTy();
894 case IITDescriptor::BFloat:
895 return !Ty->isBFloatTy();
896 case IITDescriptor::Float:
897 return !Ty->isFloatTy();
898 case IITDescriptor::Double:
899 return !Ty->isDoubleTy();
900 case IITDescriptor::Quad:
901 return !Ty->isFP128Ty();
902 case IITDescriptor::PPCQuad:
903 return !Ty->isPPC_FP128Ty();
904 case IITDescriptor::Integer:
905 return !Ty->isIntegerTy(D.IntegerWidth);
906 case IITDescriptor::AArch64Svcount:
907 return !isa<TargetExtType>(Ty) ||
908 cast<TargetExtType>(Ty)->getName() != "aarch64.svcount";
909 case IITDescriptor::Vector: {
911 return !VT || VT->getElementCount() != D.VectorWidth ||
912 matchIntrinsicType(VT->getElementType(), Infos, OverloadTys,
913 DeferredChecks, IsDeferredCheck);
914 }
915 case IITDescriptor::Pointer: {
917 return !PT || PT->getAddressSpace() != D.PointerAddressSpace;
918 }
919
920 case IITDescriptor::Struct: {
922 if (!ST || !ST->isLiteral() || ST->isPacked() ||
923 ST->getNumElements() != D.StructNumElements)
924 return true;
925
926 for (unsigned i = 0, e = D.StructNumElements; i != e; ++i)
927 if (matchIntrinsicType(ST->getElementType(i), Infos, OverloadTys,
928 DeferredChecks, IsDeferredCheck))
929 return true;
930 return false;
931 }
932
933 case IITDescriptor::Overloaded:
934 // If this is the second occurrence of an argument,
935 // verify that the later instance matches the previous instance.
936 if (D.getOverloadIndex() < OverloadTys.size())
937 return Ty != OverloadTys[D.getOverloadIndex()];
938
939 if (D.getOverloadIndex() > OverloadTys.size() ||
940 D.getOverloadKind() == IITDescriptor::AK_MatchType)
941 return IsDeferredCheck || DeferCheck(Ty);
942
943 assert(D.getOverloadIndex() == OverloadTys.size() && !IsDeferredCheck &&
944 "Table consistency error");
945 OverloadTys.push_back(Ty);
946
947 switch (D.getOverloadKind()) {
948 case IITDescriptor::AK_Any:
949 return false; // Success
950 case IITDescriptor::AK_AnyInteger:
951 return !Ty->isIntOrIntVectorTy();
952 case IITDescriptor::AK_AnyFloat:
953 return !Ty->isFPOrFPVectorTy();
954 case IITDescriptor::AK_AnyVector:
955 return !isa<VectorType>(Ty);
956 case IITDescriptor::AK_AnyPointer:
957 return !isa<PointerType>(Ty);
958 default:
959 break;
960 }
961 llvm_unreachable("all argument kinds not covered");
962
963 case IITDescriptor::Extend: {
964 // If this is a forward reference, defer the check for later.
965 if (D.getOverloadIndex() >= OverloadTys.size())
966 return IsDeferredCheck || DeferCheck(Ty);
967
968 Type *NewTy = OverloadTys[D.getOverloadIndex()];
969 if (VectorType *VTy = dyn_cast<VectorType>(NewTy))
971 else if (IntegerType *ITy = dyn_cast<IntegerType>(NewTy))
972 NewTy = IntegerType::get(ITy->getContext(), 2 * ITy->getBitWidth());
973 else
974 return true;
975
976 return Ty != NewTy;
977 }
978 case IITDescriptor::Trunc: {
979 // If this is a forward reference, defer the check for later.
980 if (D.getOverloadIndex() >= OverloadTys.size())
981 return IsDeferredCheck || DeferCheck(Ty);
982
983 Type *NewTy = OverloadTys[D.getOverloadIndex()];
984 if (VectorType *VTy = dyn_cast<VectorType>(NewTy))
986 else if (IntegerType *ITy = dyn_cast<IntegerType>(NewTy))
987 NewTy = IntegerType::get(ITy->getContext(), ITy->getBitWidth() / 2);
988 else
989 return true;
990
991 return Ty != NewTy;
992 }
993 case IITDescriptor::OneNthEltsVec: {
994 // If this is a forward reference, defer the check for later.
995 if (D.getOverloadIndex() >= OverloadTys.size())
996 return IsDeferredCheck || DeferCheck(Ty);
997 auto *VTy = dyn_cast<VectorType>(OverloadTys[D.getOverloadIndex()]);
998 if (!VTy)
999 return true;
1000 if (!VTy->getElementCount().isKnownMultipleOf(D.getVectorDivisor()))
1001 return true;
1002 return VectorType::getOneNthElementsVectorType(VTy, D.getVectorDivisor()) !=
1003 Ty;
1004 }
1005 case IITDescriptor::SameVecWidth: {
1006 if (D.getOverloadIndex() >= OverloadTys.size()) {
1007 // Defer check and subsequent check for the vector element type.
1008 Infos.consume_front();
1009 return IsDeferredCheck || DeferCheck(Ty);
1010 }
1011 auto *ReferenceType =
1012 dyn_cast<VectorType>(OverloadTys[D.getOverloadIndex()]);
1013 auto *ThisArgType = dyn_cast<VectorType>(Ty);
1014 // Both must be vectors of the same number of elements or neither.
1015 if ((ReferenceType != nullptr) != (ThisArgType != nullptr))
1016 return true;
1017 Type *EltTy = Ty;
1018 if (ThisArgType) {
1019 if (ReferenceType->getElementCount() != ThisArgType->getElementCount())
1020 return true;
1021 EltTy = ThisArgType->getElementType();
1022 }
1023 return matchIntrinsicType(EltTy, Infos, OverloadTys, DeferredChecks,
1024 IsDeferredCheck);
1025 }
1026 case IITDescriptor::VecOfAnyPtrsToElt: {
1027 unsigned RefOverloadIndex = D.getRefOverloadIndex();
1028 if (RefOverloadIndex >= OverloadTys.size()) {
1029 if (IsDeferredCheck)
1030 return true;
1031 // If forward referencing, already add the pointer-vector type and
1032 // defer the checks for later.
1033 OverloadTys.push_back(Ty);
1034 return DeferCheck(Ty);
1035 }
1036
1037 if (!IsDeferredCheck) {
1038 assert(D.getOverloadIndex() == OverloadTys.size() &&
1039 "Table consistency error");
1040 OverloadTys.push_back(Ty);
1041 }
1042
1043 // Verify the overloaded type "matches" the Ref type.
1044 // i.e. Ty is a vector with the same width as Ref.
1045 // Composed of pointers to the same element type as Ref.
1046 auto *ReferenceType = dyn_cast<VectorType>(OverloadTys[RefOverloadIndex]);
1047 auto *ThisArgVecTy = dyn_cast<VectorType>(Ty);
1048 if (!ThisArgVecTy || !ReferenceType ||
1049 (ReferenceType->getElementCount() != ThisArgVecTy->getElementCount()))
1050 return true;
1051 return !ThisArgVecTy->getElementType()->isPointerTy();
1052 }
1053 case IITDescriptor::VecElement: {
1054 if (D.getOverloadIndex() >= OverloadTys.size())
1055 return IsDeferredCheck ? true : DeferCheck(Ty);
1056 auto *ReferenceType =
1057 dyn_cast<VectorType>(OverloadTys[D.getOverloadIndex()]);
1058 return !ReferenceType || Ty != ReferenceType->getElementType();
1059 }
1060 case IITDescriptor::Subdivide2:
1061 case IITDescriptor::Subdivide4: {
1062 // If this is a forward reference, defer the check for later.
1063 if (D.getOverloadIndex() >= OverloadTys.size())
1064 return IsDeferredCheck || DeferCheck(Ty);
1065
1066 Type *NewTy = OverloadTys[D.getOverloadIndex()];
1067 if (auto *VTy = dyn_cast<VectorType>(NewTy)) {
1068 int SubDivs = D.Kind == IITDescriptor::Subdivide2 ? 1 : 2;
1069 NewTy = VectorType::getSubdividedVectorType(VTy, SubDivs);
1070 return Ty != NewTy;
1071 }
1072 return true;
1073 }
1074 case IITDescriptor::VecOfBitcastsToInt: {
1075 if (D.getOverloadIndex() >= OverloadTys.size())
1076 return IsDeferredCheck || DeferCheck(Ty);
1077 auto *ReferenceType =
1078 dyn_cast<VectorType>(OverloadTys[D.getOverloadIndex()]);
1079 auto *ThisArgVecTy = dyn_cast<VectorType>(Ty);
1080 if (!ThisArgVecTy || !ReferenceType)
1081 return true;
1082 return ThisArgVecTy != VectorType::getInteger(ReferenceType);
1083 }
1084 }
1085 llvm_unreachable("unhandled");
1086}
1087
1088/// Returns true if the intrinsic is a VarArg intrinsics. If \p Consume is true
1089/// the IITDescriptor for the VarArg is consumed and removed from \p Infos, else
1090/// it stays unchanged.
1092 bool Consume) {
1093 if (!Infos.empty() && Infos.back().Kind == Intrinsic::IITDescriptor::VarArg) {
1094 if (Consume)
1095 Infos.consume_back();
1096 return true;
1097 }
1098 return false;
1099}
1100
1101/// Return true if the function type \p FTy is a valid type signature for the
1102/// type constraints specified in the .td file, represented by \p Infos.
1103/// The overloaded type for the intrinsic are pushed to the OverloadTys vector.
1104///
1105/// If the type is not valid, returns false and prints an error message to
1106/// \p OS.
1109 SmallVectorImpl<Type *> &OverloadTys,
1110 raw_ostream &OS) {
1111 bool IsVarArg = isIntrinsicVarArg(Infos, /*Consume=*/true);
1112
1114 if (matchIntrinsicType(FTy->getReturnType(), Infos, OverloadTys,
1115 DeferredChecks, false)) {
1116 OS << "intrinsic has incorrect return type!";
1117 return false;
1118 }
1119
1120 unsigned NumDeferredReturnChecks = DeferredChecks.size();
1121
1122 for (Type *Ty : FTy->params()) {
1123 if (matchIntrinsicType(Ty, Infos, OverloadTys, DeferredChecks, false)) {
1124 OS << "intrinsic has incorrect argument type!";
1125 return false;
1126 }
1127 }
1128
1129 for (unsigned I = 0, E = DeferredChecks.size(); I != E; ++I) {
1130 DeferredIntrinsicMatchPair &Check = DeferredChecks[I];
1131 if (!matchIntrinsicType(Check.first, Check.second, OverloadTys,
1132 DeferredChecks, true))
1133 continue;
1134 if (I < NumDeferredReturnChecks)
1135 OS << "intrinsic has incorrect return type!";
1136 else
1137 OS << "intrinsic has incorrect argument type!";
1138 return false;
1139 }
1140
1141 if (!Infos.empty()) {
1142 OS << "intrinsic has too few arguments!";
1143 return false;
1144 }
1145
1146 if (FTy->isVarArg() != IsVarArg) {
1147 if (IsVarArg)
1148 OS << "intrinsic was not defined with variable arguments!";
1149 else
1150 OS << "intrinsic was defined with variable arguments!";
1151 return false;
1152 }
1153
1154 return true;
1155}
1156
1158 using namespace Intrinsic;
1161 return !Table.empty() && Table[0].Kind == IITDescriptor::Struct;
1162}
1163
1165 SmallVectorImpl<Type *> &OverloadTys,
1166 raw_ostream &OS) {
1167 if (!ID)
1168 return false;
1169
1173
1174 return ::isSignatureValid(FT, TableRef, OverloadTys, OS);
1175}
1176
1178 SmallVectorImpl<Type *> &OverloadTys,
1179 raw_ostream &OS) {
1180 return isSignatureValid(F->getIntrinsicID(), F->getFunctionType(),
1181 OverloadTys, OS);
1182}
1183
1185 SmallVector<Type *, 4> OverloadTys;
1186 if (!isSignatureValid(F, OverloadTys))
1187 return std::nullopt;
1188
1189 Intrinsic::ID ID = F->getIntrinsicID();
1190 StringRef Name = F->getName();
1191 std::string WantedName =
1192 Intrinsic::getName(ID, OverloadTys, F->getParent(), F->getFunctionType());
1193 if (Name == WantedName)
1194 return std::nullopt;
1195
1196 Function *NewDecl = [&] {
1197 if (auto *ExistingGV = F->getParent()->getNamedValue(WantedName)) {
1198 if (auto *ExistingF = dyn_cast<Function>(ExistingGV))
1199 if (ExistingF->getFunctionType() == F->getFunctionType())
1200 return ExistingF;
1201
1202 // The name already exists, but is not a function or has the wrong
1203 // prototype. Make place for the new one by renaming the old version.
1204 // Either this old version will be removed later on or the module is
1205 // invalid and we'll get an error.
1206 ExistingGV->setName(WantedName + ".renamed");
1207 }
1208 return Intrinsic::getOrInsertDeclaration(F->getParent(), ID, OverloadTys);
1209 }();
1210
1211 NewDecl->setCallingConv(F->getCallingConv());
1212 assert(NewDecl->getFunctionType() == F->getFunctionType() &&
1213 "Shouldn't change the signature");
1214 return NewDecl;
1215}
1216
1220
1222 {Intrinsic::vector_interleave2, Intrinsic::vector_deinterleave2},
1223 {Intrinsic::vector_interleave3, Intrinsic::vector_deinterleave3},
1224 {Intrinsic::vector_interleave4, Intrinsic::vector_deinterleave4},
1225 {Intrinsic::vector_interleave5, Intrinsic::vector_deinterleave5},
1226 {Intrinsic::vector_interleave6, Intrinsic::vector_deinterleave6},
1227 {Intrinsic::vector_interleave7, Intrinsic::vector_deinterleave7},
1228 {Intrinsic::vector_interleave8, Intrinsic::vector_deinterleave8},
1229};
1230
1232 assert(Factor >= 2 && Factor <= 8 && "Unexpected factor");
1233 return InterleaveIntrinsics[Factor - 2].Interleave;
1234}
1235
1237 assert(Factor >= 2 && Factor <= 8 && "Unexpected factor");
1238 return InterleaveIntrinsics[Factor - 2].Deinterleave;
1239}
1240
1241#define GET_INTRINSIC_PRETTY_PRINT_ARGUMENTS
1242#include "llvm/IR/IntrinsicImpl.inc"
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
ArrayRef< TableEntry > TableRef
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define Check(C,...)
Module.h This file contains the declarations for the Module class.
static InterleaveIntrinsic InterleaveIntrinsics[]
static bool isSignatureValid(FunctionType *FTy, ArrayRef< Intrinsic::IITDescriptor > &Infos, SmallVectorImpl< Type * > &OverloadTys, raw_ostream &OS)
Return true if the function type FTy is a valid type signature for the type constraints specified in ...
static bool matchIntrinsicType(Type *Ty, ArrayRef< Intrinsic::IITDescriptor > &Infos, SmallVectorImpl< Type * > &OverloadTys, SmallVectorImpl< DeferredIntrinsicMatchPair > &DeferredChecks, bool IsDeferredCheck)
static std::pair< ArrayRef< unsigned >, StringRef > findTargetSubtable(StringRef Name)
Find the segment of IntrinsicNameOffsetTable for intrinsics with the same target as Name,...
static Function * getOrInsertIntrinsicDeclarationImpl(Module *M, Intrinsic::ID id, ArrayRef< Type * > OverloadTys, FunctionType *FT)
std::pair< Type *, ArrayRef< Intrinsic::IITDescriptor > > DeferredIntrinsicMatchPair
static void DecodeIITType(unsigned &NextElt, ArrayRef< unsigned char > Infos, SmallVectorImpl< Intrinsic::IITDescriptor > &OutputTable)
static std::string getIntrinsicNameImpl(Intrinsic::ID Id, ArrayRef< Type * > OverloadTys, Module *M, FunctionType *FT, bool EarlyModuleCheck)
IIT_Info
IIT_Info - These are enumerators that describe the entries returned by the getIntrinsicInfoTableEntri...
static Type * DecodeFixedType(ArrayRef< Intrinsic::IITDescriptor > &Infos, ArrayRef< Type * > OverloadTys, 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...
static bool isIntrinsicVarArg(ArrayRef< Intrinsic::IITDescriptor > &Infos, bool Consume)
Returns true if the intrinsic is a VarArg intrinsics.
#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 & back() const
back - Get the last element.
Definition ArrayRef.h:151
iterator end() const
Definition ArrayRef.h:131
const T & consume_back()
consume_back() - Returns the last element and drops it from ArrayRef.
Definition ArrayRef.h:164
iterator begin() const
Definition ArrayRef.h:130
bool empty() const
empty - Check if the array is empty.
Definition ArrayRef.h:137
const T & consume_front()
consume_front() - Returns the first element and drops it from ArrayRef.
Definition ArrayRef.h:157
Class to represent fixed width SIMD vectors.
unsigned getNumElements() const
static LLVM_ABI FixedVectorType * get(Type *ElementType, unsigned NumElts)
Definition Type.cpp:873
Class to represent function types.
static LLVM_ABI FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
FunctionType * getFunctionType() const
Returns the FunctionType for me.
Definition Function.h:211
const Function & getFunction() const
Definition Function.h:166
void setCallingConv(CallingConv::ID CC)
Definition Function.h:276
Class to represent integer types.
static LLVM_ABI IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Definition Type.cpp:354
unsigned getBitWidth() const
Get the number of bits in this IntegerType.
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
static LLVM_ABI PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
reference emplace_back(ArgTypes &&... Args)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Definition StringRef.h:55
static constexpr size_t npos
Definition StringRef.h:57
std::string str() const
Get the contents as an std::string.
Definition StringRef.h:221
constexpr size_t size() const
Get the string size.
Definition StringRef.h:143
Class to represent struct types.
static LLVM_ABI StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
Definition Type.cpp:483
Class to represent target extensions types, which are generally unintrospectable from target-independ...
static LLVM_ABI TargetExtType * get(LLVMContext &Context, StringRef Name, ArrayRef< Type * > Types={}, ArrayRef< unsigned > Ints={})
Return a target extension type having the specified name and optional type and integer parameters.
Definition Type.cpp:978
Target - Wrapper for Target specific information.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
static LLVM_ABI Type * getX86_AMXTy(LLVMContext &C)
Definition Type.cpp:297
static LLVM_ABI Type * getMetadataTy(LLVMContext &C)
Definition Type.cpp:292
static LLVM_ABI Type * getTokenTy(LLVMContext &C)
Definition Type.cpp:293
static LLVM_ABI Type * getPPC_FP128Ty(LLVMContext &C)
Definition Type.cpp:296
static LLVM_ABI Type * getFP128Ty(LLVMContext &C)
Definition Type.cpp:295
@ X86_AMXTyID
AMX vectors (8192 bits, X86 specific)
Definition Type.h:67
@ HalfTyID
16-bit floating point type
Definition Type.h:57
@ VoidTyID
type with no size
Definition Type.h:64
@ FloatTyID
32-bit floating point type
Definition Type.h:59
@ IntegerTyID
Arbitrary bit width integers.
Definition Type.h:71
@ BFloatTyID
16-bit floating point type (7-bit significand)
Definition Type.h:58
@ DoubleTyID
64-bit floating point type
Definition Type.h:60
@ X86_FP80TyID
80-bit floating point type (X87)
Definition Type.h:61
@ PPC_FP128TyID
128-bit floating point type (two 64-bits, PowerPC)
Definition Type.h:63
@ MetadataTyID
Metadata.
Definition Type.h:66
@ ByteTyID
Arbitrary bit width bytes.
Definition Type.h:72
@ FP128TyID
128-bit floating point type (112-bit significand)
Definition Type.h:62
static LLVM_ABI Type * getVoidTy(LLVMContext &C)
Definition Type.cpp:286
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition Type.h:257
static LLVM_ABI Type * getDoubleTy(LLVMContext &C)
Definition Type.cpp:291
static LLVM_ABI Type * getFloatTy(LLVMContext &C)
Definition Type.cpp:290
static LLVM_ABI Type * getBFloatTy(LLVMContext &C)
Definition Type.cpp:289
static LLVM_ABI Type * getHalfTy(LLVMContext &C)
Definition Type.cpp:288
static VectorType * getExtendedElementVectorType(VectorType *VTy)
This static method is like getInteger except that the element types are twice as wide as the elements...
static VectorType * getOneNthElementsVectorType(VectorType *VTy, unsigned Denominator)
static VectorType * getSubdividedVectorType(VectorType *VTy, int NumSubdivs)
static VectorType * getInteger(VectorType *VTy)
This static method gets a VectorType with the same number of elements as the input type,...
static VectorType * getTruncatedElementVectorType(VectorType *VTy)
static LLVM_ABI VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
Type * getElementType() const
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
#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
This namespace contains an enum with a value for every intrinsic/builtin function known by LLVM.
LLVM_ABI Intrinsic::ID getDeinterleaveIntrinsicID(unsigned Factor)
Returns the corresponding llvm.vector.deinterleaveN intrinsic for factor N.
LLVM_ABI void getIntrinsicInfoTableEntries(ID id, SmallVectorImpl< IITDescriptor > &T)
Return the IIT table descriptor for the specified intrinsic into an array of IITDescriptors.
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::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 Function * getOrInsertDeclaration(Module *M, ID id, ArrayRef< Type * > OverloadTys={})
Look up the Function declaration of the intrinsic id in the Module M.
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 * > OverloadTys={})
Return the function type for an intrinsic.
LLVM_ABI bool isSignatureValid(Intrinsic::ID ID, FunctionType *FT, SmallVectorImpl< Type * > &OverloadTys, raw_ostream &OS=nulls())
Returns true if FT is a valid function type for intrinsic ID.
LLVM_ABI bool hasStructReturnType(ID id)
Returns true if id has a struct return type.
LLVM_ABI bool isTriviallyScalarizable(ID id)
Returns true if the intrinsic is trivially scalarizable.
LLVM_ABI bool isTargetIntrinsic(ID IID)
isTargetIntrinsic - Returns true if IID is an intrinsic specific to a certain target.
LLVM_ABI std::string getNameNoUnnamedTypes(ID Id, ArrayRef< Type * > OverloadTys)
Return the LLVM name for an intrinsic.
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:2128
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:1745
LLVM_ABI raw_ostream & nulls()
This returns a reference to a raw_ostream which simply discards output.
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
constexpr detail::IsaCheckPredicate< Types... > IsaPred
Function object wrapper for the llvm::isa type check.
Definition Casting.h:866
#define N
Intrinsic::ID Interleave
Intrinsic::ID Deinterleave