LLVM 24.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/IntrinsicsPISA.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"
37#include "llvm/IR/Type.h"
40
41using namespace llvm;
42
43// Forward declaration of static functions.
44static bool isSignatureValid(FunctionType *FTy,
46 unsigned NumArgs, bool IsVarArg,
47 SmallVectorImpl<Type *> &OverloadTys,
48 raw_ostream &OS,
49 unsigned NumMissingTrailingParams = 0);
50
51/// Table of string intrinsic names indexed by enum value.
52#define GET_INTRINSIC_NAME_TABLE
53#include "llvm/IR/IntrinsicImpl.inc"
54
55/// Table of required target features indexed by enum value.
56#define GET_INTRINSIC_TARGET_FEATURES_TABLE
57#include "llvm/IR/IntrinsicImpl.inc"
58
60 assert(id < num_intrinsics && "Invalid intrinsic ID!");
61 return IntrinsicNameTable[IntrinsicNameOffsetTable[id]];
62}
63
65 assert(id < num_intrinsics && "invalid intrinsic ID!");
66 return IntrinsicTargetFeaturesTable[IntrinsicTargetFeaturesOffsetTable[id]];
67}
68
70 assert(id < num_intrinsics && "Invalid intrinsic ID!");
72 "This version of getName does not support overloading");
73 return getBaseName(id);
74}
75
76/// Returns a stable mangling for the type specified for use in the name
77/// mangling scheme used by 'any' types in intrinsic signatures. The mangling
78/// of named types is simply their name. Manglings for unnamed types consist
79/// of a prefix ('p' for pointers, 'a' for arrays, 'f_' for functions)
80/// combined with the mangling of their component types. A vararg function
81/// type will have a suffix of 'vararg'. Since function types can contain
82/// other function types, we close a function type mangling with suffix 'f'
83/// which can't be confused with it's prefix. This ensures we don't have
84/// collisions between two unrelated function types. Otherwise, you might
85/// parse ffXX as f(fXX) or f(fX)X. (X is a placeholder for any other type.)
86/// The HasUnnamedType boolean is set if an unnamed type was encountered,
87/// indicating that extra care must be taken to ensure a unique name.
88static std::string getMangledTypeStr(Type *Ty, bool &HasUnnamedType) {
89 std::string Result;
90 if (PointerType *PTyp = dyn_cast<PointerType>(Ty)) {
91 Result += "p" + utostr(PTyp->getAddressSpace());
92 } else if (ArrayType *ATyp = dyn_cast<ArrayType>(Ty)) {
93 Result += "a" + utostr(ATyp->getNumElements()) +
94 getMangledTypeStr(ATyp->getElementType(), HasUnnamedType);
95 } else if (StructType *STyp = dyn_cast<StructType>(Ty)) {
96 if (!STyp->isLiteral()) {
97 Result += "s_";
98 if (STyp->hasName())
99 Result += STyp->getName();
100 else
101 HasUnnamedType = true;
102 } else {
103 Result += "sl_";
104 for (auto *Elem : STyp->elements())
105 Result += getMangledTypeStr(Elem, HasUnnamedType);
106 }
107 // Ensure nested structs are distinguishable.
108 Result += "s";
109 } else if (FunctionType *FT = dyn_cast<FunctionType>(Ty)) {
110 Result += "f_" + getMangledTypeStr(FT->getReturnType(), HasUnnamedType);
111 for (size_t i = 0; i < FT->getNumParams(); i++)
112 Result += getMangledTypeStr(FT->getParamType(i), HasUnnamedType);
113 if (FT->isVarArg())
114 Result += "vararg";
115 // Ensure nested function types are distinguishable.
116 Result += "f";
117 } else if (VectorType *VTy = dyn_cast<VectorType>(Ty)) {
118 ElementCount EC = VTy->getElementCount();
119 if (EC.isScalable())
120 Result += "nx";
121 Result += "v" + utostr(EC.getKnownMinValue()) +
122 getMangledTypeStr(VTy->getElementType(), HasUnnamedType);
123 } else if (TargetExtType *TETy = dyn_cast<TargetExtType>(Ty)) {
124 Result += "t";
125 Result += TETy->getName();
126 for (Type *ParamTy : TETy->type_params())
127 Result += "_" + getMangledTypeStr(ParamTy, HasUnnamedType);
128 for (unsigned IntParam : TETy->int_params())
129 Result += "_" + utostr(IntParam);
130 // Ensure nested target extension types are distinguishable.
131 Result += "t";
132 } else if (Ty) {
133 switch (Ty->getTypeID()) {
134 default:
135 llvm_unreachable("Unhandled type");
136 case Type::VoidTyID:
137 Result += "isVoid";
138 break;
140 Result += "Metadata";
141 break;
142 case Type::HalfTyID:
143 Result += "f16";
144 break;
145 case Type::BFloatTyID:
146 Result += "bf16";
147 break;
148 case Type::FloatTyID:
149 Result += "f32";
150 break;
151 case Type::DoubleTyID:
152 Result += "f64";
153 break;
155 Result += "f80";
156 break;
157 case Type::FP128TyID:
158 Result += "f128";
159 break;
161 Result += "ppcf128";
162 break;
164 Result += "x86amx";
165 break;
167 Result += "i" + utostr(cast<IntegerType>(Ty)->getBitWidth());
168 break;
169 case Type::ByteTyID:
170 Result += "b" + utostr(cast<ByteType>(Ty)->getBitWidth());
171 break;
172 }
173 }
174 return Result;
175}
176
178 ArrayRef<Type *> OverloadTys, Module *M,
179 FunctionType *FT,
180 bool EarlyModuleCheck) {
181
182 assert(Id < Intrinsic::num_intrinsics && "Invalid intrinsic ID!");
183 assert((OverloadTys.empty() || Intrinsic::isOverloaded(Id)) &&
184 "This version of getName is for overloaded intrinsics only");
185 (void)EarlyModuleCheck;
186 assert((!EarlyModuleCheck || M ||
187 !any_of(OverloadTys, llvm::IsaPred<PointerType>)) &&
188 "Intrinsic overloading on pointer types need to provide a Module");
189 bool HasUnnamedType = false;
190 std::string Result(Intrinsic::getBaseName(Id));
191 for (Type *Ty : OverloadTys)
192 Result += "." + getMangledTypeStr(Ty, HasUnnamedType);
193 if (HasUnnamedType) {
194 assert(M && "unnamed types need a module");
195 if (!FT)
196 FT = Intrinsic::getType(M->getContext(), Id, OverloadTys);
197 else
198 assert(FT == Intrinsic::getType(M->getContext(), Id, OverloadTys) &&
199 "Provided FunctionType must match arguments");
200 return M->getUniqueIntrinsicName(Result, Id, FT);
201 }
202 return Result;
203}
204
205std::string Intrinsic::getName(ID Id, ArrayRef<Type *> OverloadTys, Module *M,
206 FunctionType *FT) {
207 assert(M && "We need to have a Module");
208 return getIntrinsicNameImpl(Id, OverloadTys, M, FT, true);
209}
210
212 ArrayRef<Type *> OverloadTys) {
213 return getIntrinsicNameImpl(Id, OverloadTys, nullptr, nullptr, false);
214}
215
216/// IIT_Info - These are enumerators that describe the entries returned by the
217/// getIntrinsicInfoTableEntries function.
218///
219/// Defined in Intrinsics.td.
221#define GET_INTRINSIC_IITINFO
222#include "llvm/IR/IntrinsicImpl.inc"
223};
224
225static_assert(IIT_Done == 0, "IIT_Done expected to be 0");
226
227static void
228DecodeIITType(unsigned &NextElt, ArrayRef<unsigned char> Infos,
230 using namespace Intrinsic;
231
232 auto IsScalableVector = [&]() {
233 IIT_Info NextInfo = IIT_Info(Infos[NextElt]);
234 if (NextInfo != IIT_SCALABLE_VEC)
235 return false;
236 // Eat the IIT_SCALABLE_VEC token.
237 ++NextElt;
238 return true;
239 };
240
241 IIT_Info Info = IIT_Info(Infos[NextElt++]);
242
243 switch (Info) {
244 case IIT_Done:
245 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Void, 0));
246 return;
247 case IIT_VARARG:
248 OutputTable.push_back(IITDescriptor::get(IITDescriptor::VarArg, 0));
249 return;
250 case IIT_MMX:
251 OutputTable.push_back(IITDescriptor::get(IITDescriptor::MMX, 0));
252 return;
253 case IIT_AMX:
254 OutputTable.push_back(IITDescriptor::get(IITDescriptor::AMX, 0));
255 return;
256 case IIT_TOKEN:
257 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Token, 0));
258 return;
259 case IIT_METADATA:
260 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Metadata, 0));
261 return;
262 case IIT_F16:
263 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Half, 0));
264 return;
265 case IIT_BF16:
266 OutputTable.push_back(IITDescriptor::get(IITDescriptor::BFloat, 0));
267 return;
268 case IIT_F32:
269 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Float, 0));
270 return;
271 case IIT_F64:
272 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Double, 0));
273 return;
274 case IIT_F128:
275 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Quad, 0));
276 return;
277 case IIT_PPCF128:
278 OutputTable.push_back(IITDescriptor::get(IITDescriptor::PPCQuad, 0));
279 return;
280 case IIT_I1:
281 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 1));
282 return;
283 case IIT_I2:
284 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 2));
285 return;
286 case IIT_I4:
287 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 4));
288 return;
289 case IIT_AARCH64_SVCOUNT:
290 OutputTable.push_back(IITDescriptor::get(IITDescriptor::AArch64Svcount, 0));
291 return;
292 case IIT_I8:
293 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 8));
294 return;
295 case IIT_I16:
296 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 16));
297 return;
298 case IIT_I32:
299 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 32));
300 return;
301 case IIT_I64:
302 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 64));
303 return;
304 case IIT_I128:
305 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Integer, 128));
306 return;
307 case IIT_V1:
308 OutputTable.push_back(IITDescriptor::getVector(1, IsScalableVector()));
309 DecodeIITType(NextElt, Infos, OutputTable);
310 return;
311 case IIT_V2:
312 OutputTable.push_back(IITDescriptor::getVector(2, IsScalableVector()));
313 DecodeIITType(NextElt, Infos, OutputTable);
314 return;
315 case IIT_V3:
316 OutputTable.push_back(IITDescriptor::getVector(3, IsScalableVector()));
317 DecodeIITType(NextElt, Infos, OutputTable);
318 return;
319 case IIT_V4:
320 OutputTable.push_back(IITDescriptor::getVector(4, IsScalableVector()));
321 DecodeIITType(NextElt, Infos, OutputTable);
322 return;
323 case IIT_V6:
324 OutputTable.push_back(IITDescriptor::getVector(6, IsScalableVector()));
325 DecodeIITType(NextElt, Infos, OutputTable);
326 return;
327 case IIT_V8:
328 OutputTable.push_back(IITDescriptor::getVector(8, IsScalableVector()));
329 DecodeIITType(NextElt, Infos, OutputTable);
330 return;
331 case IIT_V10:
332 OutputTable.push_back(IITDescriptor::getVector(10, IsScalableVector()));
333 DecodeIITType(NextElt, Infos, OutputTable);
334 return;
335 case IIT_V16:
336 OutputTable.push_back(IITDescriptor::getVector(16, IsScalableVector()));
337 DecodeIITType(NextElt, Infos, OutputTable);
338 return;
339 case IIT_V32:
340 OutputTable.push_back(IITDescriptor::getVector(32, IsScalableVector()));
341 DecodeIITType(NextElt, Infos, OutputTable);
342 return;
343 case IIT_V64:
344 OutputTable.push_back(IITDescriptor::getVector(64, IsScalableVector()));
345 DecodeIITType(NextElt, Infos, OutputTable);
346 return;
347 case IIT_V128:
348 OutputTable.push_back(IITDescriptor::getVector(128, IsScalableVector()));
349 DecodeIITType(NextElt, Infos, OutputTable);
350 return;
351 case IIT_V256:
352 OutputTable.push_back(IITDescriptor::getVector(256, IsScalableVector()));
353 DecodeIITType(NextElt, Infos, OutputTable);
354 return;
355 case IIT_V512:
356 OutputTable.push_back(IITDescriptor::getVector(512, IsScalableVector()));
357 DecodeIITType(NextElt, Infos, OutputTable);
358 return;
359 case IIT_V1024:
360 OutputTable.push_back(IITDescriptor::getVector(1024, IsScalableVector()));
361 DecodeIITType(NextElt, Infos, OutputTable);
362 return;
363 case IIT_V2048:
364 OutputTable.push_back(IITDescriptor::getVector(2048, IsScalableVector()));
365 DecodeIITType(NextElt, Infos, OutputTable);
366 return;
367 case IIT_V4096:
368 OutputTable.push_back(IITDescriptor::getVector(4096, IsScalableVector()));
369 DecodeIITType(NextElt, Infos, OutputTable);
370 return;
371 case IIT_EXTERNREF:
372 OutputTable.push_back(IITDescriptor::get(IITDescriptor::WasmExternref, 0));
373 return;
374 case IIT_FUNCREF:
375 OutputTable.push_back(IITDescriptor::get(IITDescriptor::WasmFuncref, 0));
376 return;
377 case IIT_PTR:
378 OutputTable.push_back(IITDescriptor::get(IITDescriptor::Pointer, 0));
379 return;
380 case IIT_PTR_AS: // pointer with address space.
381 OutputTable.push_back(
382 IITDescriptor::get(IITDescriptor::Pointer, Infos[NextElt++]));
383 return;
384 case IIT_ANY: {
385 unsigned OverloadIndex = Infos[NextElt++];
386 unsigned ArgKindEnums = Infos[NextElt++];
387 unsigned Packed = (ArgKindEnums << 8) | OverloadIndex;
388 OutputTable.push_back(
389 IITDescriptor::get(IITDescriptor::Overloaded, Packed));
390 return;
391 }
392 case IIT_MATCH: {
393 unsigned OverloadIndex = Infos[NextElt++];
394 OutputTable.push_back(
395 IITDescriptor::get(IITDescriptor::Match, OverloadIndex));
396 return;
397 }
398 case IIT_EXTEND_ARG: {
399 unsigned OverloadIndex = Infos[NextElt++];
400 OutputTable.push_back(
401 IITDescriptor::get(IITDescriptor::Extend, OverloadIndex));
402 return;
403 }
404 case IIT_TRUNC_ARG: {
405 unsigned OverloadIndex = Infos[NextElt++];
406 OutputTable.push_back(
407 IITDescriptor::get(IITDescriptor::Trunc, OverloadIndex));
408 return;
409 }
410 case IIT_ONE_NTH_ELTS_VEC_ARG: {
411 unsigned short OverloadIndex = Infos[NextElt++];
412 unsigned short N = Infos[NextElt++];
413 OutputTable.push_back(IITDescriptor::get(IITDescriptor::OneNthEltsVec,
414 /*Hi=*/N, /*Lo=*/OverloadIndex));
415 return;
416 }
417 case IIT_SAME_VEC_WIDTH_ARG: {
418 unsigned OverloadIndex = Infos[NextElt++];
419 OutputTable.push_back(
420 IITDescriptor::get(IITDescriptor::SameVecWidth, OverloadIndex));
421 // IIT_SAME_VEC_WIDTH_ARG entry is followed by the element type.
422 DecodeIITType(NextElt, Infos, OutputTable);
423 return;
424 }
425 case IIT_ANY_SAME_VEC_WIDTH_ARG: {
426 unsigned short OverloadIndex = Infos[NextElt++];
427 unsigned short RefOverloadIndex = Infos[NextElt++];
428 unsigned short ElementConstraint = Infos[NextElt++];
429 // Pack the element constraint into bits [4:7], leaving the low 4 bits for
430 // this type's overload index.
431 OutputTable.push_back(IITDescriptor::get(
432 IITDescriptor::AnySameVecWidth, /*Hi=*/RefOverloadIndex,
433 /*Lo=*/ElementConstraint << 4 | OverloadIndex));
434 return;
435 }
436 case IIT_STRUCT: {
437 unsigned StructElts = Infos[NextElt++] + 2;
438
439 OutputTable.push_back(
440 IITDescriptor::get(IITDescriptor::Struct, StructElts));
441
442 for (unsigned i = 0; i != StructElts; ++i)
443 DecodeIITType(NextElt, Infos, OutputTable);
444 return;
445 }
446 case IIT_SUBDIVIDE2_ARG: {
447 unsigned OverloadIndex = Infos[NextElt++];
448 OutputTable.push_back(
449 IITDescriptor::get(IITDescriptor::Subdivide2, OverloadIndex));
450 return;
451 }
452 case IIT_SUBDIVIDE4_ARG: {
453 unsigned OverloadIndex = Infos[NextElt++];
454 OutputTable.push_back(
455 IITDescriptor::get(IITDescriptor::Subdivide4, OverloadIndex));
456 return;
457 }
458 case IIT_VEC_ELEMENT: {
459 unsigned OverloadIndex = Infos[NextElt++];
460 OutputTable.push_back(
461 IITDescriptor::get(IITDescriptor::VecElement, OverloadIndex));
462 return;
463 }
464 case IIT_VEC_OF_BITCASTS_TO_INT: {
465 unsigned OverloadIndex = Infos[NextElt++];
466 OutputTable.push_back(
467 IITDescriptor::get(IITDescriptor::VecOfBitcastsToInt, OverloadIndex));
468 return;
469 }
470 case IIT_SCALABLE_VEC:
471 break;
472 }
473 llvm_unreachable("unhandled");
474}
475
476#define GET_INTRINSIC_GENERATOR_GLOBAL
477#include "llvm/IR/IntrinsicImpl.inc"
478
479std::tuple<ArrayRef<Intrinsic::IITDescriptor>, unsigned, bool>
482 // Note that `FixedEncodingTy` is defined in IntrinsicImpl.inc and can be
483 // uint16_t or uint32_t based on the the value of `Use16BitFixedEncoding` in
484 // IntrinsicEmitter.cpp.
485 constexpr unsigned FixedEncodingBits = sizeof(FixedEncodingTy) * CHAR_BIT;
486 constexpr unsigned MSBPosition = FixedEncodingBits - 1;
487 // Mask with all bits 1 except the most significant bit.
488 constexpr unsigned Mask = (1U << MSBPosition) - 1;
489
490 FixedEncodingTy TableVal = IIT_Table[id - 1];
491
492 // Array to hold the inlined fixed encoding values expanded from nibbles to
493 // bytes. Its size can be be atmost FixedEncodingBits / 4 i.e., number
494 // of nibbles that can fit in `FixedEncodingTy` + 1 (the IIT_Done terminator
495 // that is not explicitly encoded). Note that if there are trailing 0 bytes
496 // in the encoding (for example, payload following one of the IIT tokens),
497 // the inlined encoding does not encode the actual size of the encoding, so
498 // we always assume its size of this maximum length possible, followed by the
499 // IIT_Done terminator token (whose value is 0).
500 unsigned char IITValues[FixedEncodingBits / 4 + 1] = {0};
501
502 ArrayRef<unsigned char> IITEntries;
503 unsigned NextElt = 0;
504 // Check to see if the intrinsic's type was inlined in the fixed encoding
505 // table.
506 if (TableVal >> MSBPosition) {
507 // This is an offset into the IIT_LongEncodingTable.
508 IITEntries = IIT_LongEncodingTable;
509
510 // Strip sentinel bit.
511 NextElt = TableVal & Mask;
512 } else {
513 // If the entry was encoded into a single word in the table itself, decode
514 // it from an array of nibbles to an array of bytes.
515 do {
516 IITValues[NextElt++] = TableVal & 0xF;
517 TableVal >>= 4;
518 } while (TableVal);
519
520 IITEntries = IITValues;
521 NextElt = 0;
522 }
523
524 // Okay, decode the table into the output vector of IITDescriptors.
525 DecodeIITType(NextElt, IITEntries, T);
526 unsigned NumArgs = 0;
527 while (IITEntries[NextElt] != IIT_Done) {
528 DecodeIITType(NextElt, IITEntries, T);
529 ++NumArgs;
530 }
531
533
534 bool IsVarArg = false;
535 if (TableRef.back().Kind == Intrinsic::IITDescriptor::VarArg) {
536 IsVarArg = true;
537 TableRef.consume_back();
538 --NumArgs;
539 }
540 return {TableRef, NumArgs, IsVarArg};
541}
542
544 ArrayRef<Type *> OverloadTys,
545 LLVMContext &Context) {
546 using namespace Intrinsic;
547
548 IITDescriptor D = Infos.consume_front();
549
550 switch (D.Kind) {
551 case IITDescriptor::Void:
552 return Type::getVoidTy(Context);
553 case IITDescriptor::MMX:
555 case IITDescriptor::AMX:
556 return Type::getX86_AMXTy(Context);
557 case IITDescriptor::Token:
558 return Type::getTokenTy(Context);
559 case IITDescriptor::Metadata:
560 return Type::getMetadataTy(Context);
561 case IITDescriptor::Half:
562 return Type::getHalfTy(Context);
563 case IITDescriptor::BFloat:
564 return Type::getBFloatTy(Context);
565 case IITDescriptor::Float:
566 return Type::getFloatTy(Context);
567 case IITDescriptor::Double:
568 return Type::getDoubleTy(Context);
569 case IITDescriptor::Quad:
570 return Type::getFP128Ty(Context);
571 case IITDescriptor::PPCQuad:
572 return Type::getPPC_FP128Ty(Context);
573 case IITDescriptor::AArch64Svcount:
574 return TargetExtType::get(Context, "aarch64.svcount");
575 case IITDescriptor::WasmExternref:
576 return TargetExtType::get(Context, "wasm.externref");
577 case IITDescriptor::WasmFuncref:
578 return TargetExtType::get(Context, "wasm.funcref");
579 case IITDescriptor::Integer:
580 return IntegerType::get(Context, D.IntegerWidth);
581 case IITDescriptor::Vector:
582 return VectorType::get(DecodeFixedType(Infos, OverloadTys, Context),
583 D.VectorWidth);
584 case IITDescriptor::Pointer:
585 return PointerType::get(Context, D.PointerAddressSpace);
586 case IITDescriptor::Struct: {
588 for (unsigned i = 0, e = D.StructNumElements; i != e; ++i)
589 Elts.push_back(DecodeFixedType(Infos, OverloadTys, Context));
590 return StructType::get(Context, Elts);
591 }
592 // For any overload type or partially dependent type, substitute it with the
593 // corresponding concrete type from OverloadTys. Additionally, do the same
594 // for the fully dependent type that matches an overload type.
595 case IITDescriptor::Overloaded:
596 case IITDescriptor::AnySameVecWidth:
597 case IITDescriptor::Match:
598 return OverloadTys[D.getOverloadIndex()];
599 case IITDescriptor::Extend:
600 return OverloadTys[D.getOverloadIndex()]->getExtendedType();
601 case IITDescriptor::Trunc:
602 return OverloadTys[D.getOverloadIndex()]->getTruncatedType();
603 case IITDescriptor::Subdivide2:
604 case IITDescriptor::Subdivide4: {
605 Type *Ty = OverloadTys[D.getOverloadIndex()];
607 assert(VTy && "Expected overload type to be a Vector Type");
608 int SubDivs = D.Kind == IITDescriptor::Subdivide2 ? 1 : 2;
609 return VectorType::getSubdividedVectorType(VTy, SubDivs);
610 }
611 case IITDescriptor::OneNthEltsVec:
613 cast<VectorType>(OverloadTys[D.getOverloadIndex()]),
614 D.getVectorDivisor());
615 case IITDescriptor::SameVecWidth: {
616 Type *EltTy = DecodeFixedType(Infos, OverloadTys, Context);
617 Type *Ty = OverloadTys[D.getOverloadIndex()];
618 if (auto *VTy = dyn_cast<VectorType>(Ty))
619 return VectorType::get(EltTy, VTy->getElementCount());
620 return EltTy;
621 }
622 case IITDescriptor::VecElement: {
623 Type *Ty = OverloadTys[D.getOverloadIndex()];
624 if (VectorType *VTy = dyn_cast<VectorType>(Ty))
625 return VTy->getElementType();
626 llvm_unreachable("Expected overload type to be a Vector Type");
627 }
628 case IITDescriptor::VecOfBitcastsToInt: {
629 Type *Ty = OverloadTys[D.getOverloadIndex()];
631 assert(VTy && "Expected overload type to be a Vector Type");
632 return VectorType::getInteger(VTy);
633 }
634 case IITDescriptor::VarArg:
635 // VarArg token should be consumed by `getIntrinsicInfoTableEntries`, so we
636 // should never see it here.
637 llvm_unreachable("IITDescriptor::VarArg not expected");
638 }
639 llvm_unreachable("unhandled");
640}
641
643 ArrayRef<Type *> OverloadTys) {
645 auto [TableRef, _, IsVarArg] = getIntrinsicInfoTableEntries(id, Table);
646
647 Type *ResultTy = DecodeFixedType(TableRef, OverloadTys, Context);
648
650 while (!TableRef.empty())
651 ArgTys.push_back(DecodeFixedType(TableRef, OverloadTys, Context));
652 return FunctionType::get(ResultTy, ArgTys, IsVarArg);
653}
654
656#define GET_INTRINSIC_OVERLOAD_TABLE
657#include "llvm/IR/IntrinsicImpl.inc"
658}
659
661#define GET_INTRINSIC_SCALARIZABLE_TABLE
662#include "llvm/IR/IntrinsicImpl.inc"
663}
664
666#define GET_INTRINSIC_PRETTY_PRINT_TABLE
667#include "llvm/IR/IntrinsicImpl.inc"
668}
669
670/// Table of per-target intrinsic name tables.
671#define GET_INTRINSIC_TARGET_DATA
672#include "llvm/IR/IntrinsicImpl.inc"
673
675 return IID > TargetInfos[0].Count;
676}
677
678/// Looks up Name in NameTable via binary search. NameTable must be sorted
679/// and all entries must start with "llvm.". If NameTable contains an exact
680/// match for Name or a prefix of Name followed by a dot, its index in
681/// NameTable is returned. Otherwise, -1 is returned.
683 StringRef Name, StringRef Target = "") {
684 assert(Name.starts_with("llvm.") && "Unexpected intrinsic prefix");
685 assert(Name.drop_front(5).starts_with(Target) && "Unexpected target");
686
687 // Do successive binary searches of the dotted name components. For
688 // "llvm.gc.experimental.statepoint.p1i8.p1i32", we will find the range of
689 // intrinsics starting with "llvm.gc", then "llvm.gc.experimental", then
690 // "llvm.gc.experimental.statepoint", and then we will stop as the range is
691 // size 1. During the search, we can skip the prefix that we already know is
692 // identical. By using strncmp we consider names with differing suffixes to
693 // be part of the equal range.
694 size_t CmpEnd = 4; // Skip the "llvm" component.
695 if (!Target.empty())
696 CmpEnd += 1 + Target.size(); // skip the .target component.
697
698 const unsigned *Low = NameOffsetTable.begin();
699 const unsigned *High = NameOffsetTable.end();
700 const unsigned *LastLow = Low;
701 while (CmpEnd < Name.size() && High - Low > 0) {
702 size_t CmpStart = CmpEnd;
703 CmpEnd = Name.find('.', CmpStart + 1);
704 CmpEnd = CmpEnd == StringRef::npos ? Name.size() : CmpEnd;
705 auto Cmp = [CmpStart, CmpEnd](auto LHS, auto RHS) {
706 // `equal_range` requires the comparison to work with either side being an
707 // offset or the value. Detect which kind each side is to set up the
708 // compared strings.
709 const char *LHSStr;
710 if constexpr (std::is_integral_v<decltype(LHS)>)
711 LHSStr = IntrinsicNameTable.getCString(LHS);
712 else
713 LHSStr = LHS;
714
715 const char *RHSStr;
716 if constexpr (std::is_integral_v<decltype(RHS)>)
717 RHSStr = IntrinsicNameTable.getCString(RHS);
718 else
719 RHSStr = RHS;
720
721 return strncmp(LHSStr + CmpStart, RHSStr + CmpStart, CmpEnd - CmpStart) <
722 0;
723 };
724 LastLow = Low;
725 std::tie(Low, High) = std::equal_range(Low, High, Name.data(), Cmp);
726 }
727 if (High - Low > 0)
728 LastLow = Low;
729
730 if (LastLow == NameOffsetTable.end())
731 return -1;
732 StringRef NameFound = IntrinsicNameTable[*LastLow];
733 if (Name == NameFound ||
734 (Name.starts_with(NameFound) && Name[NameFound.size()] == '.'))
735 return LastLow - NameOffsetTable.begin();
736 return -1;
737}
738
739/// Find the segment of \c IntrinsicNameOffsetTable for intrinsics with the same
740/// target as \c Name, or the generic table if \c Name is not target specific.
741///
742/// Returns the relevant slice of \c IntrinsicNameOffsetTable and the target
743/// name.
744static std::pair<ArrayRef<unsigned>, StringRef>
746 assert(Name.starts_with("llvm."));
747
748 ArrayRef<IntrinsicTargetInfo> Targets(TargetInfos);
749 // Drop "llvm." and take the first dotted component. That will be the target
750 // if this is target specific.
751 StringRef Target = Name.drop_front(5).split('.').first;
752 auto It = partition_point(
753 Targets, [=](const IntrinsicTargetInfo &TI) { return TI.Name < Target; });
754 // We've either found the target or just fall back to the generic set, which
755 // is always first.
756 const auto &TI = It != Targets.end() && It->Name == Target ? *It : Targets[0];
757 return {ArrayRef(&IntrinsicNameOffsetTable[1] + TI.Offset, TI.Count),
758 TI.Name};
759}
760
761/// This does the actual lookup of an intrinsic ID which matches the given
762/// function name.
764 auto [NameOffsetTable, Target] = findTargetSubtable(Name);
765 int Idx = lookupLLVMIntrinsicByName(NameOffsetTable, Name, Target);
766 if (Idx == -1)
768
769 // Intrinsic IDs correspond to the location in IntrinsicNameTable, but we have
770 // an index into a sub-table.
771 int Adjust = NameOffsetTable.data() - IntrinsicNameOffsetTable;
772 Intrinsic::ID ID = static_cast<Intrinsic::ID>(Idx + Adjust);
773
774 // If the intrinsic is not overloaded, require an exact match. If it is
775 // overloaded, require either exact or prefix match.
776 const auto MatchSize = IntrinsicNameTable[NameOffsetTable[Idx]].size();
777 assert(Name.size() >= MatchSize && "Expected either exact or prefix match");
778 bool IsExactMatch = Name.size() == MatchSize;
779 return IsExactMatch || Intrinsic::isOverloaded(ID) ? ID
781}
782
783/// This defines the "Intrinsic::getAttributes(ID id)" method.
784#define GET_INTRINSIC_ATTRIBUTES
785#include "llvm/IR/IntrinsicImpl.inc"
786
787static Function *
789 ArrayRef<Type *> OverloadTys,
790 FunctionType *FT) {
791 std::string Name = OverloadTys.empty()
792 ? Intrinsic::getName(id).str()
793 : Intrinsic::getName(id, OverloadTys, M, FT);
794 Function *F = cast<Function>(M->getOrInsertFunction(Name, FT).getCallee());
795 if (F->getFunctionType() == FT)
796 return F;
797
798 // It's possible that a declaration for this intrinsic already exists with an
799 // incorrect signature, if the signature has changed, but this particular
800 // declaration has not been auto-upgraded yet. In that case, rename the
801 // invalid declaration and insert a new one with the correct signature. The
802 // invalid declaration will get upgraded later.
803 F->setName(F->getName() + ".invalid");
804 return cast<Function>(M->getOrInsertFunction(Name, FT).getCallee());
805}
806
808 ArrayRef<Type *> OverloadTys) {
809 // There can never be multiple globals with the same name of different types,
810 // because intrinsics must be a specific type.
811 FunctionType *FT = getType(M->getContext(), id, OverloadTys);
812 return getOrInsertIntrinsicDeclarationImpl(M, id, OverloadTys, FT);
813}
814
816 ArrayRef<Type *> ArgTys) {
817 // If the intrinsic is not overloaded, use the non-overloaded version.
819 return getOrInsertDeclaration(M, id);
820
821 // Get the intrinsic signature metadata.
823 auto [TableRef, NumArgs, IsVarArg] = getIntrinsicInfoTableEntries(id, Table);
824 FunctionType *FTy = FunctionType::get(RetTy, ArgTys, IsVarArg);
825
826 // Automatically determine the overloaded types.
827 SmallVector<Type *, 4> OverloadTys;
828 [[maybe_unused]] bool IsValid = ::isSignatureValid(
829 FTy, TableRef, NumArgs, IsVarArg, OverloadTys, nulls());
830 assert(IsValid && "intrinsic signature mismatch");
831 return getOrInsertIntrinsicDeclarationImpl(M, id, OverloadTys, FTy);
832}
833
835 return M->getFunction(getName(id));
836}
837
839 ArrayRef<Type *> OverloadTys,
840 FunctionType *FT) {
841 return M->getFunction(getName(id, OverloadTys, M, FT));
842}
843
844// This defines the "Intrinsic::getIntrinsicForClangBuiltin()" method.
845#define GET_LLVM_INTRINSIC_FOR_CLANG_BUILTIN
846#include "llvm/IR/IntrinsicImpl.inc"
847
848// This defines the "Intrinsic::getIntrinsicForMSBuiltin()" method.
849#define GET_LLVM_INTRINSIC_FOR_MS_BUILTIN
850#include "llvm/IR/IntrinsicImpl.inc"
851
853 switch (QID) {
854#define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC) \
855 case Intrinsic::INTRINSIC:
856#include "llvm/IR/ConstrainedOps.def"
857#undef INSTRUCTION
858 return true;
859 default:
860 return false;
861 }
862}
863
865 switch (QID) {
866#define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC) \
867 case Intrinsic::INTRINSIC: \
868 return ROUND_MODE == 1;
869#include "llvm/IR/ConstrainedOps.def"
870#undef INSTRUCTION
871 default:
872 return false;
873 }
874}
875
876// This class represents a position in the intrinsic's type signature and is
877// used to generate error messages in `matchIntrinsicType`. The printed position
878// can be of the following forms:
879//
880// return
881// return struct element 3
882// return vector element
883// return struct element 3 vector element
884// argument 3
885// argument 3 vector element
886//
887// To support deferred checks also being able to generate these error messages
888// we need to encode the position compactly so that it can be stashed into
889// DeferredIntrinsicMatchInfo below (without materializing it into a string).
890// The class below serves that purpose.
891//
892namespace {
893struct MatchPosition {
894 uint16_t IsRet : 1;
895 uint16_t Num : 15; // Argument number (when IsRet = false).
896 struct Index {
897 uint16_t IsStruct : 1; // If true, this is a struct element with element
898 // index `Num`, else its a vector element.
899 uint16_t Num : 15; // Struct element index.
900 };
901 // We expect this to be just 2 levels deep, since nested structs are not
902 // supported.
903 static constexpr unsigned INDEX_TABLE_SIZE = 2;
904 Index Indices[INDEX_TABLE_SIZE];
905 uint16_t NumIndices = 0;
906
907 void pop_index() {
908 assert(NumIndices > 0 && "cannot pop from empty indices");
909 --NumIndices;
910 }
911
912 void push_struct_element(unsigned ElementNum) {
913 assert(NumIndices < INDEX_TABLE_SIZE && "index table overflow");
914 assert(isInt<15>(ElementNum) && "Element index overflow");
915 Indices[NumIndices].IsStruct = true;
916 Indices[NumIndices++].Num = ElementNum;
917 }
918
919 void push_vector_element() {
920 assert(NumIndices < INDEX_TABLE_SIZE && "index table overflow");
921 Indices[NumIndices].IsStruct = false;
922 Indices[NumIndices++].Num = 0;
923 }
924};
925} // namespace
926
927static raw_ostream &operator<<(raw_ostream &OS, const MatchPosition &Pos) {
928 OS << "intrinsic ";
929
930 if (Pos.IsRet)
931 OS << "return";
932 else
933 OS << "argument " << Pos.Num;
934
935 for (const MatchPosition::Index &Idx :
936 ArrayRef(Pos.Indices).take_front(Pos.NumIndices)) {
937 if (Idx.IsStruct)
938 OS << " struct element " << Idx.Num;
939 else
940 OS << " vector element";
941 }
942 return OS;
943}
944
946 std::tuple<Type *, ArrayRef<Intrinsic::IITDescriptor>, MatchPosition>;
947
948/// Check whether \p Ty satisfies the given element constraint \p EC and return
949/// a description of the expected element kind for error messages.
950static std::pair<bool, StringRef>
952 Intrinsic::IITDescriptor::AnyKindElementConstraint EC) {
953 using namespace Intrinsic;
954
955 Type *EltTy = Ty->getScalarType();
956 switch (EC) {
957 case IITDescriptor::EC_None:
958 return {true, "value"};
959 case IITDescriptor::EC_Integer:
960 return {EltTy->isIntegerTy(), "integer"};
961 case IITDescriptor::EC_Float:
962 return {EltTy->isFloatingPointTy(), "fp"};
963 case IITDescriptor::EC_Pointer:
964 return {EltTy->isPointerTy(), "pointer"};
965 }
966 llvm_unreachable("invalid element constraint");
967}
968
969static bool
971 MatchPosition Position, SmallVectorImpl<Type *> &OverloadTys,
973 bool IsDeferredCheck, raw_ostream &OS) {
974 using namespace Intrinsic;
975
976 // If we ran out of descriptors, there are too many arguments or returns.
977 if (Infos.empty()) {
978 OS << Position << " too many "
979 << (Position.IsRet ? "returns" : "arguments");
980 return true;
981 }
982
983 // Do this before slicing off the 'front' part
984 auto InfosRef = Infos;
985 auto DeferCheck = [&DeferredChecks, &InfosRef, &Position](Type *T) {
986 DeferredChecks.emplace_back(T, InfosRef, Position);
987 return false;
988 };
989
990 IITDescriptor D = Infos.consume_front();
991
992 // Print error message when the (non-dependent) type for current position is
993 // invalid.
994 auto PrintMsg = [&OS, &Position,
995 Ty](bool IsValid, const Twine &Expected,
996 std::optional<unsigned> OIdx = std::nullopt) -> bool {
997 if (IsValid)
998 return false;
999 OS << Position << " type";
1000 if (OIdx)
1001 OS << " (overload type " << *OIdx << ")";
1002 OS << " expected " << Expected << ", but got " << *Ty;
1003 return true;
1004 };
1005
1006 // Print message when an overload type is invalid as a result of its use in
1007 // current dependent type. DependentQualifier describes the "function" applied
1008 // to the overload type to get the dependent type.
1009 auto PrintMsgInvalidOverloadTy =
1010 [&OS, &Position, &OverloadTys](const Twine &DependentQualifier,
1011 const Twine &Expected,
1012 unsigned OIdx) -> bool {
1013 OS << Position << " is " << DependentQualifier << " overload type " << OIdx
1014 << ", so overload type " << OIdx << " expected " << Expected
1015 << ", but got " << *OverloadTys[OIdx];
1016 return true;
1017 };
1018
1019 // Print message when a dependent type is invalid.
1020 auto PrintMsgInvalidDepType =
1021 [&OS, &Position, &OverloadTys,
1022 Ty](bool IsValid, const Twine &DependentQualifier, const Twine &Expected,
1023 unsigned OIdx) -> bool {
1024 if (IsValid)
1025 return false;
1026 bool IsMatching = DependentQualifier.isSingleStringRef() &&
1027 DependentQualifier.getSingleStringRef() == "matching";
1028 OS << Position << " type (" << DependentQualifier << " overload type "
1029 << OIdx << ") expected " << Expected;
1030 if (!IsMatching)
1031 OS << " (overload type " << OIdx << " is " << *OverloadTys[OIdx] << ")";
1032 OS << ", but got " << *Ty;
1033 return true;
1034 };
1035
1036 switch (D.Kind) {
1037 case IITDescriptor::Void:
1038 assert(Position.IsRet && Position.NumIndices == 0 &&
1039 "void descriptor expected only for return type");
1040 return PrintMsg(Ty->isVoidTy(), "void");
1041 case IITDescriptor::MMX: {
1043 return PrintMsg(VT && VT->getNumElements() == 1 &&
1044 VT->getElementType()->isIntegerTy(64),
1045 "x86_mmx (<1 x i64>)");
1046 }
1047 case IITDescriptor::AMX:
1048 return PrintMsg(Ty->isX86_AMXTy(), "x86_amx");
1049 case IITDescriptor::Token:
1050 return PrintMsg(Ty->isTokenTy(), "token");
1051 case IITDescriptor::Metadata:
1052 return PrintMsg(Ty->isMetadataTy(), "metadata");
1053 case IITDescriptor::Half:
1054 return PrintMsg(Ty->isHalfTy(), "half");
1055 case IITDescriptor::BFloat:
1056 return PrintMsg(Ty->isBFloatTy(), "bfloat");
1057 case IITDescriptor::Float:
1058 return PrintMsg(Ty->isFloatTy(), "float");
1059 case IITDescriptor::Double:
1060 return PrintMsg(Ty->isDoubleTy(), "double");
1061 case IITDescriptor::Quad:
1062 return PrintMsg(Ty->isFP128Ty(), "fp128");
1063 case IITDescriptor::PPCQuad:
1064 return PrintMsg(Ty->isPPC_FP128Ty(), "ppc_fp128");
1065 case IITDescriptor::Integer:
1066 return PrintMsg(Ty->isIntegerTy(D.IntegerWidth),
1067 "i" + Twine(D.IntegerWidth));
1068 case IITDescriptor::AArch64Svcount:
1069 return PrintMsg(isa<TargetExtType>(Ty) &&
1070 cast<TargetExtType>(Ty)->getName() == "aarch64.svcount",
1071 "aarch64.svcount");
1072 case IITDescriptor::WasmExternref:
1073 return PrintMsg(isa<TargetExtType>(Ty) &&
1074 cast<TargetExtType>(Ty)->getName() == "wasm.externref",
1075 "wasm.externref");
1076 case IITDescriptor::WasmFuncref:
1077 return PrintMsg(isa<TargetExtType>(Ty) &&
1078 cast<TargetExtType>(Ty)->getName() == "wasm.funcref",
1079 "wasm.funcref");
1080 case IITDescriptor::Vector: {
1082 StringRef Scalable = D.VectorWidth.isScalable() ? "vscale " : "";
1083 bool HasError =
1084 PrintMsg(VT && VT->getElementCount() == D.VectorWidth,
1085 Twine(Scalable) + "vector with " +
1086 Twine(D.VectorWidth.getKnownMinValue()) + " elements");
1087 if (HasError)
1088 return true;
1089 Position.push_vector_element();
1090 return matchIntrinsicType(VT->getElementType(), Infos, Position,
1091 OverloadTys, DeferredChecks, IsDeferredCheck, OS);
1092 }
1093 case IITDescriptor::Pointer: {
1095 unsigned AS = D.PointerAddressSpace;
1096 bool IsValid = PT && PT->getAddressSpace() == AS;
1097 if (AS == 0)
1098 return PrintMsg(IsValid, "ptr");
1099 return PrintMsg(IsValid, "ptr addrspace(" + Twine(AS) + ")");
1100 }
1101
1102 case IITDescriptor::Struct: {
1104 unsigned EC = D.StructNumElements;
1105 bool HasError = PrintMsg(
1106 ST && ST->isLiteral() && !ST->isPacked() && ST->getNumElements() == EC,
1107 "literal non-packed struct with " + Twine(EC) + " elements");
1108 if (HasError)
1109 return true;
1110
1111 for (const auto &[Idx, ETy] : llvm::enumerate(ST->elements())) {
1112 Position.push_struct_element(Idx);
1113 if (matchIntrinsicType(ETy, Infos, Position, OverloadTys, DeferredChecks,
1114 IsDeferredCheck, OS))
1115 return true;
1116 Position.pop_index();
1117 }
1118 return false;
1119 }
1120
1121 case IITDescriptor::Overloaded: {
1122 unsigned OIdx = D.getOverloadIndex();
1123 assert(OIdx == OverloadTys.size() && !IsDeferredCheck &&
1124 "Table consistency error");
1125 OverloadTys.push_back(Ty);
1126
1127 // Token has no mangling (see getMangledTypeStr), so it cannot be an
1128 // overload type; reject it with a signature error. Label is already
1129 // excluded from function signatures, so it never reaches here.
1130 if (Ty->isTokenTy())
1131 return PrintMsg(false, "any manglable type", OIdx);
1132
1133 IITDescriptor::AnyKindVectorConstraint VC;
1134 IITDescriptor::AnyKindElementConstraint EC;
1135 std::tie(VC, EC) = D.getOverloadConstraints();
1136
1137 bool IsValid = [&]() {
1138 switch (VC) {
1139 case IITDescriptor::VC_None:
1140 return true;
1141 case IITDescriptor::VC_Vector:
1142 return isa<VectorType>(Ty);
1143 case IITDescriptor::VC_Scalar:
1144 return !isa<VectorType>(Ty);
1145 }
1146 llvm_unreachable("invalid vector constraint");
1147 }();
1148
1149 auto [ElemValid, EK] = checkElementConstraint(Ty, EC);
1150 IsValid &= ElemValid;
1151
1152 if (IsValid)
1153 return false;
1154
1155 static constexpr StringLiteral VectorKinds[] = {
1156 "",
1157 "vector",
1158 "scalar",
1159 };
1160
1161 if (EC == IITDescriptor::EC_None) {
1162 // No constraint on element type.
1163 // Expected = any {vector | scalar} type.
1164 StringLiteral VK = ArrayRef(VectorKinds)[VC];
1165 return PrintMsg(false, formatv("any {} type", VK), OIdx);
1166 }
1167
1168 switch (VC) {
1169 case IITDescriptor::VC_None:
1170 // Expected = any EK or EK vector.
1171 return PrintMsg(false, formatv("any {0} or {0} vector", EK), OIdx);
1172 case IITDescriptor::VC_Vector:
1173 return PrintMsg(false, formatv("any {} vector", EK), OIdx);
1174 case IITDescriptor::VC_Scalar:
1175 return PrintMsg(false, formatv("any {} type", EK), OIdx);
1176 }
1177 llvm_unreachable("invalid vector constraint");
1178 }
1179
1180 case IITDescriptor::Match: {
1181 unsigned OIdx = D.getOverloadIndex();
1182 if (OIdx >= OverloadTys.size())
1183 return IsDeferredCheck || DeferCheck(Ty);
1184 return PrintMsgInvalidDepType(Ty == OverloadTys[OIdx], "matching",
1185 formatv("{}", *OverloadTys[OIdx]), OIdx);
1186 }
1187
1188 case IITDescriptor::Extend:
1189 case IITDescriptor::Trunc: {
1190 unsigned OIdx = D.getOverloadIndex();
1191 // If this is a forward reference, defer the check for later.
1192 if (OIdx >= OverloadTys.size())
1193 return IsDeferredCheck || DeferCheck(Ty);
1194
1195 Type *OTy = OverloadTys[OIdx];
1196 bool IsExtend = D.Kind == IITDescriptor::Extend;
1197 StringRef Qualifier = IsExtend ? "extended" : "truncated";
1198 if (!OTy->isIntOrIntVectorTy())
1199 return PrintMsgInvalidOverloadTy(Qualifier, "int or vector of int", OIdx);
1200
1201 Type *NewTy = IsExtend ? OTy->getExtendedType() : OTy->getTruncatedType();
1202 return PrintMsgInvalidDepType(Ty == NewTy, Qualifier, formatv("{}", *NewTy),
1203 OIdx);
1204 }
1205 case IITDescriptor::OneNthEltsVec: {
1206 unsigned OIdx = D.getOverloadIndex();
1207 unsigned Divisor = D.getVectorDivisor();
1208 // If this is a forward reference, defer the check for later.
1209 if (OIdx >= OverloadTys.size())
1210 return IsDeferredCheck || DeferCheck(Ty);
1211 Type *OTy = OverloadTys[OIdx];
1212 auto *OVecTy = dyn_cast<VectorType>(OTy);
1213 auto Qualifier = formatv("1/nth (n={}) elements vector of", Divisor);
1214 if (!OVecTy)
1215 return PrintMsgInvalidOverloadTy(Qualifier, "vector", OIdx);
1216 if (!OVecTy->getElementCount().isKnownMultipleOf(Divisor))
1217 return PrintMsgInvalidOverloadTy(
1218 Qualifier, formatv("vector with multiple of {} elements", Divisor),
1219 OIdx);
1221 return PrintMsgInvalidDepType(Expected == Ty, Qualifier,
1222 formatv("{}", *Expected), OIdx);
1223 }
1224 case IITDescriptor::SameVecWidth: {
1225 unsigned OIdx = D.getOverloadIndex();
1226 if (OIdx >= OverloadTys.size()) {
1227 // Defer check and subsequent check for the vector element type.
1228 Infos.consume_front();
1229 return IsDeferredCheck || DeferCheck(Ty);
1230 }
1231 auto *OVecTy = dyn_cast<VectorType>(OverloadTys[OIdx]);
1232 auto *ThisArgVecType = dyn_cast<VectorType>(Ty);
1233 // Both must be vectors of the same number of elements or neither.
1234 StringRef Qualifier = "same vector width of";
1235 if (OVecTy && !ThisArgVecType)
1236 return PrintMsgInvalidDepType(false, Qualifier, "vector", OIdx);
1237 if (!OVecTy && ThisArgVecType)
1238 return PrintMsgInvalidDepType(false, Qualifier, "scalar", OIdx);
1239 Type *EltTy = Ty;
1240 if (ThisArgVecType) {
1241 ElementCount Expected = OVecTy->getElementCount();
1242 if (Expected != ThisArgVecType->getElementCount())
1243 return PrintMsgInvalidDepType(
1244 false, Qualifier, formatv("vector with {} elements", Expected),
1245 OIdx);
1246 EltTy = ThisArgVecType->getElementType();
1247 Position.push_vector_element();
1248 }
1249 return matchIntrinsicType(EltTy, Infos, Position, OverloadTys,
1250 DeferredChecks, IsDeferredCheck, OS);
1251 }
1252 case IITDescriptor::AnySameVecWidth: {
1253 unsigned RefOverloadIndex = D.getRefOverloadIndex();
1254 if (RefOverloadIndex >= OverloadTys.size()) {
1255 if (IsDeferredCheck)
1256 return true;
1257 // If forward referencing, already add the type and defer the checks for
1258 // later.
1259 assert(D.getOverloadIndex() == OverloadTys.size() &&
1260 "Table consistency error");
1261 OverloadTys.push_back(Ty);
1262 return DeferCheck(Ty);
1263 }
1264
1265 if (!IsDeferredCheck) {
1266 assert(D.getOverloadIndex() == OverloadTys.size() &&
1267 "Table consistency error");
1268 OverloadTys.push_back(Ty);
1269 }
1270
1271 auto [ElemValid, Kind] =
1272 checkElementConstraint(Ty, D.getElementConstraint());
1273
1274 auto *ReferenceType = dyn_cast<VectorType>(OverloadTys[RefOverloadIndex]);
1275 auto *ThisArgVecTy = dyn_cast<VectorType>(Ty);
1276 StringRef Qualifier = "same vector width of";
1277 if (ReferenceType) {
1278 auto ExpectedCount = ReferenceType->getElementCount();
1279 auto Expected =
1280 formatv("{0} vector with {1} elements", Kind, ExpectedCount);
1281 if (!ThisArgVecTy)
1282 return PrintMsgInvalidDepType(false, Qualifier, Expected,
1283 RefOverloadIndex);
1284 bool IsValid =
1285 ThisArgVecTy->getElementCount() == ExpectedCount && ElemValid;
1286 return PrintMsgInvalidDepType(IsValid, Qualifier, Expected,
1287 RefOverloadIndex);
1288 }
1289
1290 auto Expected = formatv("scalar {}", Kind);
1291 if (ThisArgVecTy)
1292 return PrintMsgInvalidDepType(false, Qualifier, Expected,
1293 RefOverloadIndex);
1294 return PrintMsgInvalidDepType(ElemValid, Qualifier, Expected,
1295 RefOverloadIndex);
1296 }
1297 case IITDescriptor::VecElement: {
1298 unsigned OIdx = D.getOverloadIndex();
1299 if (OIdx >= OverloadTys.size())
1300 return IsDeferredCheck || DeferCheck(Ty);
1301 StringRef Qualifier = "vector element of";
1302 auto *OVecTy = dyn_cast<VectorType>(OverloadTys[OIdx]);
1303 if (!OVecTy)
1304 return PrintMsgInvalidOverloadTy(Qualifier, "vector", OIdx);
1305 Type *Expected = OVecTy->getElementType();
1306 return PrintMsgInvalidDepType(Expected == Ty, Qualifier,
1307 formatv("{}", *Expected), OIdx);
1308 }
1309 case IITDescriptor::Subdivide2:
1310 case IITDescriptor::Subdivide4: {
1311 unsigned OIdx = D.getOverloadIndex();
1312 // If this is a forward reference, defer the check for later.
1313 if (OIdx >= OverloadTys.size())
1314 return IsDeferredCheck || DeferCheck(Ty);
1315
1316 int SubDivs = D.Kind == IITDescriptor::Subdivide2 ? 1 : 2;
1317 auto *OVecTy = dyn_cast<VectorType>(OverloadTys[OIdx]);
1318 auto Qualifier =
1319 formatv("subdivided by {} vector of", SubDivs == 1 ? 2 : 4);
1320 if (!OVecTy)
1321 return PrintMsgInvalidOverloadTy(Qualifier, "vector", OIdx);
1322
1323 // TODO: Verify that the element type of the overload type is subdivisible
1324 // by 2 or 4.
1326 return PrintMsgInvalidDepType(Expected == Ty, Qualifier,
1327 formatv("{}", *Expected), OIdx);
1328 }
1329 case IITDescriptor::VecOfBitcastsToInt: {
1330 unsigned OIdx = D.getOverloadIndex();
1331 if (OIdx >= OverloadTys.size())
1332 return IsDeferredCheck || DeferCheck(Ty);
1333 auto *OVecTy = dyn_cast<VectorType>(OverloadTys[OIdx]);
1334 StringRef Qualifier = "vector of bitcasts to int of";
1335 if (!OVecTy)
1336 return PrintMsgInvalidOverloadTy(Qualifier, "vector", OIdx);
1338 return PrintMsgInvalidDepType(Expected == Ty, Qualifier,
1339 formatv("{}", *Expected), OIdx);
1340 }
1341 case IITDescriptor::VarArg:
1342 // VarArg token should be consumed by `getIntrinsicInfoTableEntries`, so we
1343 // should never see it here.
1344 llvm_unreachable("IITDescriptor::VarArg not expected");
1345 }
1346 llvm_unreachable("unhandled");
1347}
1348
1349/// Return true if the function type \p FTy is a valid type signature for the
1350/// type constraints specified in the .td file, represented by \p Infos and
1351/// \p IsVarArg. The overloaded types for the intrinsic are pushed to the
1352/// \p OverloadTys vector.
1353///
1354/// If \p NumMissingTrailingParams is non-zero, \p FTy may omit exactly that
1355/// many trailing parameters. Omitted parameters must have concrete integer
1356/// types and therefore cannot contribute an unresolved overload type.
1357///
1358/// If the type is not valid, returns false and prints an error message to
1359/// \p OS.
1362 unsigned NumArgs, bool IsVarArg,
1363 SmallVectorImpl<Type *> &OverloadTys,
1364 raw_ostream &OS,
1365 unsigned NumMissingTrailingParams) {
1367
1368 assert(!Infos.empty() && "Table consistency error");
1369
1370 MatchPosition Pos;
1371 Pos.IsRet = true;
1372 Pos.Num = 0;
1373
1374 if (matchIntrinsicType(FTy->getReturnType(), Infos, Pos, OverloadTys,
1375 DeferredChecks, false, OS))
1376 return false;
1377
1378 unsigned ProvidedArgs = FTy->getNumParams();
1379 if (ProvidedArgs + NumMissingTrailingParams != NumArgs) {
1380 OS << "intrinsic has incorrect number of args. Expected " << NumArgs
1381 << ", but got " << ProvidedArgs;
1382 return false;
1383 }
1384
1385 Pos.IsRet = false;
1386 for (const auto &[Idx, Ty] : llvm::enumerate(FTy->params())) {
1387 Pos.Num = Idx;
1388 if (matchIntrinsicType(Ty, Infos, Pos, OverloadTys, DeferredChecks, false,
1389 OS))
1390 return false;
1391 }
1392
1393 for (unsigned I = 0, E = DeferredChecks.size(); I != E; ++I) {
1394 auto &[DefTy, DefInfos, DefPosition] = DeferredChecks[I];
1395 if (matchIntrinsicType(DefTy, DefInfos, DefPosition, OverloadTys,
1396 DeferredChecks, true, OS))
1397 return false;
1398 }
1399
1400 // Default arguments are materialized as ConstantInt values, requiring one
1401 // concrete integer descriptor per omitted parameter.
1402 if (NumMissingTrailingParams != 0 &&
1403 (Infos.size() != NumMissingTrailingParams ||
1405 return D.Kind != Intrinsic::IITDescriptor::Integer;
1406 }))) {
1407 OS << "cannot omit trailing parameters that are overloaded or non-integer";
1408 return false;
1409 }
1410 Infos = Infos.drop_front(NumMissingTrailingParams);
1411
1412 if (!Infos.empty()) {
1413 OS << "intrinsic has too few arguments!";
1414 return false;
1415 }
1416
1417 if (FTy->isVarArg() != IsVarArg) {
1418 if (IsVarArg)
1419 OS << "intrinsic was not defined with variable arguments!";
1420 else
1421 OS << "intrinsic was defined with variable arguments!";
1422 return false;
1423 }
1424
1425 return true;
1426}
1427
1429 using namespace Intrinsic;
1432 return !Table.empty() && Table[0].Kind == IITDescriptor::Struct;
1433}
1434
1436 SmallVectorImpl<Type *> &OverloadTys,
1437 raw_ostream &OS) {
1438 return isSignatureValid(ID, FT, OverloadTys,
1439 /*NumMissingTrailingParams=*/0, OS);
1440}
1441
1443 SmallVectorImpl<Type *> &OverloadTys,
1444 unsigned NumMissingTrailingParams,
1445 raw_ostream &OS) {
1446 if (!ID)
1447 return false;
1448
1450 auto [TableRef, NumArgs, IsVarArg] = getIntrinsicInfoTableEntries(ID, Table);
1451
1452 return ::isSignatureValid(FT, TableRef, NumArgs, IsVarArg, OverloadTys, OS,
1453 NumMissingTrailingParams);
1454}
1455
1457 SmallVectorImpl<Type *> &OverloadTys,
1458 raw_ostream &OS) {
1459 return isSignatureValid(F->getIntrinsicID(), F->getFunctionType(),
1460 OverloadTys, OS);
1461}
1462
1464 SmallVector<Type *, 4> OverloadTys;
1465 if (!isSignatureValid(F, OverloadTys))
1466 return std::nullopt;
1467
1468 Intrinsic::ID ID = F->getIntrinsicID();
1469 StringRef Name = F->getName();
1470 std::string WantedName =
1471 Intrinsic::getName(ID, OverloadTys, F->getParent(), F->getFunctionType());
1472 if (Name == WantedName)
1473 return std::nullopt;
1474
1475 Function *NewDecl = [&] {
1476 if (auto *ExistingGV = F->getParent()->getNamedValue(WantedName)) {
1477 if (auto *ExistingF = dyn_cast<Function>(ExistingGV))
1478 if (ExistingF->getFunctionType() == F->getFunctionType())
1479 return ExistingF;
1480
1481 // The name already exists, but is not a function or has the wrong
1482 // prototype. Make place for the new one by renaming the old version.
1483 // Either this old version will be removed later on or the module is
1484 // invalid and we'll get an error.
1485 ExistingGV->setName(WantedName + ".renamed");
1486 }
1487 return Intrinsic::getOrInsertDeclaration(F->getParent(), ID, OverloadTys);
1488 }();
1489
1490 NewDecl->setCallingConv(F->getCallingConv());
1491 assert(NewDecl->getFunctionType() == F->getFunctionType() &&
1492 "Shouldn't change the signature");
1493 return NewDecl;
1494}
1495
1499
1501 {Intrinsic::vector_interleave2, Intrinsic::vector_deinterleave2},
1502 {Intrinsic::vector_interleave3, Intrinsic::vector_deinterleave3},
1503 {Intrinsic::vector_interleave4, Intrinsic::vector_deinterleave4},
1504 {Intrinsic::vector_interleave5, Intrinsic::vector_deinterleave5},
1505 {Intrinsic::vector_interleave6, Intrinsic::vector_deinterleave6},
1506 {Intrinsic::vector_interleave7, Intrinsic::vector_deinterleave7},
1507 {Intrinsic::vector_interleave8, Intrinsic::vector_deinterleave8},
1508};
1509
1511 assert(Factor >= 2 && Factor <= 8 && "Unexpected factor");
1512 return InterleaveIntrinsics[Factor - 2].Interleave;
1513}
1514
1516 assert(Factor >= 2 && Factor <= 8 && "Unexpected factor");
1517 return InterleaveIntrinsics[Factor - 2].Deinterleave;
1518}
1519
1521 const Constant *ImmArgVal) {
1522 uint64_t Val = cast<ConstantInt>(ImmArgVal)->getZExtValue();
1523 OS << static_cast<FPClassTest>(Val);
1524}
1525
1526#define GET_INTRINSIC_IMMARG_RANGE_SET_CHECKS
1527#include "llvm/IR/IntrinsicImpl.inc"
1528
1529#define GET_INTRINSIC_PRETTY_PRINT_ARGUMENTS
1530#include "llvm/IR/IntrinsicImpl.inc"
1531
1532// Emit the default-argument values table and lookup function
1533// (Intrinsic::getAllDefaultArgValues).
1534#define GET_INTRINSIC_DEFAULT_ARG_VALUES
1535#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 LLVM_ABI
Definition Compiler.h:211
#define _
Module.h This file contains the declarations for the Module class.
static bool matchIntrinsicType(Type *Ty, ArrayRef< Intrinsic::IITDescriptor > &Infos, MatchPosition Position, SmallVectorImpl< Type * > &OverloadTys, SmallVectorImpl< DeferredIntrinsicMatchInfo > &DeferredChecks, bool IsDeferredCheck, raw_ostream &OS)
static InterleaveIntrinsic InterleaveIntrinsics[]
static std::pair< bool, StringRef > checkElementConstraint(Type *Ty, Intrinsic::IITDescriptor::AnyKindElementConstraint EC)
Check whether Ty satisfies the given element constraint EC and return a description of the expected e...
std::tuple< Type *, ArrayRef< Intrinsic::IITDescriptor >, MatchPosition > DeferredIntrinsicMatchInfo
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)
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 isSignatureValid(FunctionType *FTy, ArrayRef< Intrinsic::IITDescriptor > &Infos, unsigned NumArgs, bool IsVarArg, SmallVectorImpl< Type * > &OverloadTys, raw_ostream &OS, unsigned NumMissingTrailingParams=0)
Return true if the function type FTy is a valid type signature for the type constraints specified in ...
#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,...
This file declares utility interfaces for PISA 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
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
ArrayRef< T > drop_front(size_t N=1) const
Drop the first N elements of the array.
Definition ArrayRef.h:194
iterator end() const
Definition ArrayRef.h:130
size_t size() const
Get the array size.
Definition ArrayRef.h:141
iterator begin() const
Definition ArrayRef.h:129
bool empty() const
Check if the array is empty.
Definition ArrayRef.h:136
const T & consume_front()
consume_front() - Returns the first element and drops it from ArrayRef.
Definition ArrayRef.h:156
This is an important base class in LLVM.
Definition Constant.h:44
Tagged union holding either a T or a Error.
Definition Error.h:485
Class to represent fixed width SIMD vectors.
unsigned getNumElements() const
static LLVM_ABI FixedVectorType * get(Type *ElementType, unsigned NumElts)
Definition Type.cpp:838
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:212
const Function & getFunction() const
Definition Function.h:167
void setCallingConv(CallingConv::ID CC)
Definition Function.h:277
static LLVM_ABI IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Definition Type.cpp:333
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:76
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
static LLVM_ABI PointerType * get(LLVMContext &C, unsigned AddressSpace)
This constructs an opaque pointer to an object in a numbered address space.
Definition Type.cpp:882
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.
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
Definition StringRef.h:880
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
static constexpr size_t npos
Definition StringRef.h:58
std::string str() const
Get the contents as an std::string.
Definition StringRef.h:222
constexpr size_t size() const
Get the string size.
Definition StringRef.h:144
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:462
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:931
Target - Wrapper for Target specific information.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
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:278
LLVM_ABI Type * getTruncatedType() const
Given scalar/vector integer type, returns a type with elements half as wide as in the original type.
static LLVM_ABI Type * getMetadataTy(LLVMContext &C)
Definition Type.cpp:273
static LLVM_ABI Type * getTokenTy(LLVMContext &C)
Definition Type.cpp:274
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
Definition Type.h:258
bool isPointerTy() const
True if this is an instance of PointerType.
Definition Type.h:277
static LLVM_ABI Type * getPPC_FP128Ty(LLVMContext &C)
Definition Type.cpp:277
static LLVM_ABI Type * getFP128Ty(LLVMContext &C)
Definition Type.cpp:276
@ 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:267
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
Definition Type.h:370
bool isFloatingPointTy() const
Return true if this is one of the floating-point types.
Definition Type.h:186
LLVM_ABI Type * getExtendedType() const
Given scalar/vector integer type, returns a type with elements twice as wide as in the original type.
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition Type.h:252
static LLVM_ABI Type * getDoubleTy(LLVMContext &C)
Definition Type.cpp:272
static LLVM_ABI Type * getFloatTy(LLVMContext &C)
Definition Type.cpp:271
static LLVM_ABI Type * getBFloatTy(LLVMContext &C)
Definition Type.cpp:270
static LLVM_ABI Type * getHalfTy(LLVMContext &C)
Definition Type.cpp:269
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 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.
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 printFPClassMask(raw_ostream &OS, const Constant *ImmArgVal)
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 std::tuple< ArrayRef< IITDescriptor >, unsigned, bool > getIntrinsicInfoTableEntries(ID id, SmallVectorImpl< IITDescriptor > &T)
Fill the IIT table descriptor for the intrinsic id into an array of IITDescriptors.
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 StringRef getRequiredTargetFeatures(ID id)
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
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
Definition MathExtras.h:166
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
Definition STLExtras.h:2575
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:2145
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:1762
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
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
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
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
This is a type descriptor which explains the type requirements of an intrinsic.
Definition Intrinsics.h:174