1//===- Intrinsics.td - Defines all LLVM intrinsics ---------*- tablegen -*-===//
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 defines properties of all LLVM intrinsics.
10//
11//===----------------------------------------------------------------------===//
12
13include "llvm/CodeGen/ValueTypes.td"
14include "llvm/CodeGen/SDNodeProperties.td"
15
16//===----------------------------------------------------------------------===//
17//  Properties we keep track of for intrinsics.
18//===----------------------------------------------------------------------===//
19
20class IntrinsicProperty<bit is_default = false> {
21  bit IsDefault = is_default;
22}
23
24// Intr*Mem - Memory properties.  If no property is set, the worst case
25// is assumed (it may read and write any memory it can get access to and it may
26// have other side effects).
27
28// IntrNoMem - The intrinsic does not access memory or have any other side
29// effects.  It may be CSE'd deleted if dead, etc.
30def IntrNoMem : IntrinsicProperty;
31
32// IntrReadMem - This intrinsic only reads from memory. It does not write to
33// memory and has no other side effects. Therefore, it cannot be moved across
34// potentially aliasing stores. However, it can be reordered otherwise and can
35// be deleted if dead.
36def IntrReadMem : IntrinsicProperty;
37
38// IntrWriteMem - This intrinsic only writes to memory, but does not read from
39// memory, and has no other side effects. This means dead stores before calls
40// to this intrinsics may be removed.
41def IntrWriteMem : IntrinsicProperty;
42
43// IntrArgMemOnly - This intrinsic only accesses memory that its pointer-typed
44// argument(s) points to, but may access an unspecified amount. Other than
45// reads from and (possibly volatile) writes to memory, it has no side effects.
46def IntrArgMemOnly : IntrinsicProperty;
47
48// IntrInaccessibleMemOnly -- This intrinsic only accesses memory that is not
49// accessible by the module being compiled. This is a weaker form of IntrNoMem.
50def IntrInaccessibleMemOnly : IntrinsicProperty;
51
52// IntrInaccessibleMemOrArgMemOnly -- This intrinsic only accesses memory that
53// its pointer-typed arguments point to or memory that is not accessible
54// by the module being compiled. This is a weaker form of IntrArgMemOnly.
55def IntrInaccessibleMemOrArgMemOnly : IntrinsicProperty;
56
57// Commutative - This intrinsic is commutative: X op Y == Y op X.
58def Commutative : IntrinsicProperty;
59
60// Throws - This intrinsic can throw.
61def Throws : IntrinsicProperty;
62
63// Attribute index needs to match `AttrIndex` defined `Attributes.h`.
64class AttrIndex<int idx> {
65  int Value = idx;
66}
67def FuncIndex : AttrIndex<-1>;
68def RetIndex : AttrIndex<0>;
69class ArgIndex<int argNo> : AttrIndex<!add(argNo, 1)>;
70
71// NoCapture - The specified argument pointer is not captured by the intrinsic.
72class NoCapture<AttrIndex idx> : IntrinsicProperty {
73  int ArgNo = idx.Value;
74}
75
76// NoAlias - The specified argument pointer is not aliasing other "noalias" pointer
77// arguments of the intrinsic wrt. the intrinsic scope.
78class NoAlias<AttrIndex idx> : IntrinsicProperty {
79  int ArgNo = idx.Value;
80}
81
82// NoUndef - The specified argument is neither undef nor poison.
83class NoUndef<AttrIndex idx> : IntrinsicProperty {
84  int ArgNo = idx.Value;
85}
86
87// NonNull - The specified argument is not null.
88class NonNull<AttrIndex idx> : IntrinsicProperty {
89  int ArgNo = idx.Value;
90}
91
92class Align<AttrIndex idx, int align> : IntrinsicProperty {
93  int ArgNo = idx.Value;
94  int Align = align;
95}
96
97class Dereferenceable<AttrIndex idx, int bytes> : IntrinsicProperty {
98  int ArgNo = idx.Value;
99  int Bytes = bytes;
100}
101
102// Returned - The specified argument is always the return value of the
103// intrinsic.
104class Returned<AttrIndex idx> : IntrinsicProperty {
105  int ArgNo = idx.Value;
106}
107
108// ImmArg - The specified argument must be an immediate.
109class ImmArg<AttrIndex idx> : IntrinsicProperty {
110  int ArgNo = idx.Value;
111}
112
113// ReadOnly - The specified argument pointer is not written to through the
114// pointer by the intrinsic.
115class ReadOnly<AttrIndex idx> : IntrinsicProperty {
116  int ArgNo = idx.Value;
117}
118
119// WriteOnly - The intrinsic does not read memory through the specified
120// argument pointer.
121class WriteOnly<AttrIndex idx> : IntrinsicProperty {
122  int ArgNo = idx.Value;
123}
124
125// ReadNone - The specified argument pointer is not dereferenced by the
126// intrinsic.
127class ReadNone<AttrIndex idx> : IntrinsicProperty {
128  int ArgNo = idx.Value;
129}
130
131def IntrNoReturn : IntrinsicProperty;
132
133// Applied by default.
134def IntrNoCallback : IntrinsicProperty<1>;
135
136// IntrNoSync - Threads executing the intrinsic will not synchronize using
137// memory or other means. Applied by default.
138def IntrNoSync : IntrinsicProperty<1>;
139
140// Applied by default.
141def IntrNoFree : IntrinsicProperty<1>;
142
143// Applied by default.
144def IntrWillReturn : IntrinsicProperty<1>;
145
146// IntrCold - Calls to this intrinsic are cold.
147// Parallels the cold attribute on LLVM IR functions.
148def IntrCold : IntrinsicProperty;
149
150// IntrNoDuplicate - Calls to this intrinsic cannot be duplicated.
151// Parallels the noduplicate attribute on LLVM IR functions.
152def IntrNoDuplicate : IntrinsicProperty;
153
154// IntrNoMerge - Calls to this intrinsic cannot be merged
155// Parallels the nomerge attribute on LLVM IR functions.
156def IntrNoMerge : IntrinsicProperty;
157
158// IntrConvergent - Calls to this intrinsic are convergent and may not be made
159// control-dependent on any additional values.
160// Parallels the convergent attribute on LLVM IR functions.
161def IntrConvergent : IntrinsicProperty;
162
163// This property indicates that the intrinsic is safe to speculate.
164def IntrSpeculatable : IntrinsicProperty;
165
166// This property can be used to override the 'has no other side effects'
167// language of the IntrNoMem, IntrReadMem, IntrWriteMem, and IntrArgMemOnly
168// intrinsic properties.  By default, intrinsics are assumed to have side
169// effects, so this property is only necessary if you have defined one of
170// the memory properties listed above.
171// For this property, 'side effects' has the same meaning as 'side effects'
172// defined by the hasSideEffects property of the TableGen Instruction class.
173def IntrHasSideEffects : IntrinsicProperty;
174
175//===----------------------------------------------------------------------===//
176// IIT constants and utils
177//===----------------------------------------------------------------------===//
178
179// llvm::Intrinsic::IITDescriptor::ArgKind::AK_%
180def ArgKind {
181  int Any        = 0;
182  int AnyInteger = 1;
183  int AnyFloat   = 2;
184  int AnyVector  = 3;
185  int AnyPointer = 4;
186
187  int MatchType  = 7;
188}
189
190// Encode placeholder.
191// [15:8] is the ID used how to resolve ArgCode.
192
193// (ACIdx << 3) | ArgCode
194class EncAnyType<int ArgCode=0> {
195  int ID = 0x100;
196  int ret = !or(ID, ArgCode);
197}
198
199// (Mapping[Num] << 3) | AK.MatchType
200class EncMatchType<int Num=0> {
201  int ID = 0x200;
202  int ret = !or(ID, Num);
203}
204
205// (Mapping[Num] << 3) | ArgCodes[Mapping[Num]]
206class EncSameWidth<int Num=0> {
207  int ID = 0x300;
208  int ret = !or(ID, Num);
209}
210
211// ACIdx
212class EncNextArgA<int dummy=0> {
213  int ID = 0x400;
214  int ret = !or(ID, dummy);
215}
216
217// Mapping[Num]
218class EncNextArgN<int Num=0> {
219  int ID = 0x500;
220  int ret = !or(ID, Num);
221}
222
223class ResolveArgCode<
224    list<int> Mapping,
225    list<int> ArgCodes,
226    int ACIdx,
227    int ax> {
228  int ah = !and(ax, 0xFF00);
229  int al = !and(ax, 0x00FF);
230  int num = Mapping[al];
231  int ret = !cond(
232    !eq(ah, EncAnyType<>.ID)   : !or(!shl(ACIdx, 3), al),
233    !eq(ah, EncMatchType<>.ID) : !or(!shl(num, 3), ArgKind.MatchType),
234    !eq(ah, EncSameWidth<>.ID) : !or(!shl(num, 3), ArgCodes[num]),
235    !eq(ah, EncNextArgA<>.ID)  : ACIdx,
236    !eq(ah, EncNextArgN<>.ID)  : num,
237    true : al);
238}
239
240//===----------------------------------------------------------------------===//
241// IIT_Info
242//===----------------------------------------------------------------------===//
243
244class IIT_Base<int num> {
245  int Number = num;
246  list<ValueType> VTs = ?;
247}
248
249class IIT_VT<ValueType vt, int num> : IIT_Base<num> {
250  let VTs = [vt];
251}
252
253class IIT_Int<int size, int num> : IIT_Base<num> {
254  let VTs = !filter(vti, ValueTypes,
255    !and(vti.isInteger, !eq(vti.Size, size)));
256}
257
258class IIT_Vec<int nelem, int num> : IIT_Base<num> {
259  let VTs = !filter(vti, ValueTypes,
260    !and(vti.isVector, !eq(vti.nElem, nelem)));
261}
262
263defset list<IIT_Base> IIT_all = {
264def IIT_Done : IIT_Base<    0>;
265def IIT_I1   : IIT_Int<1,   1>;
266def IIT_I8   : IIT_Int<8,   2>;
267def IIT_I16  : IIT_Int<16,  3>;
268def IIT_I32  : IIT_Int<32,  4>;
269def IIT_I64  : IIT_Int<64,  5>;
270def IIT_F16  : IIT_VT<f16,  6>;
271def IIT_F32  : IIT_VT<f32,  7>;
272def IIT_F64  : IIT_VT<f64,  8>;
273def IIT_V2   : IIT_Vec<2,   9>;
274def IIT_V4   : IIT_Vec<4,  10>;
275def IIT_V8   : IIT_Vec<8,  11>;
276def IIT_V16  : IIT_Vec<16, 12>;
277def IIT_V32  : IIT_Vec<32, 13>;
278def IIT_PTR  : IIT_Base<   14>;
279def IIT_ARG  : IIT_Base<   15>;
280
281def IIT_V64 : IIT_Vec<64, 16>;
282def IIT_MMX : IIT_VT<x86mmx, 17>;
283def IIT_TOKEN : IIT_VT<token, 18>;
284def IIT_METADATA : IIT_VT<MetadataVT, 19>;
285def IIT_EMPTYSTRUCT : IIT_VT<OtherVT, 20>;
286def IIT_STRUCT2 : IIT_Base<21>;
287def IIT_STRUCT3 : IIT_Base<22>;
288def IIT_STRUCT4 : IIT_Base<23>;
289def IIT_STRUCT5 : IIT_Base<24>;
290def IIT_EXTEND_ARG : IIT_Base<25>;
291def IIT_TRUNC_ARG : IIT_Base<26>;
292def IIT_ANYPTR : IIT_Base<27>;
293def IIT_V1 : IIT_Vec<1, 28>;
294def IIT_VARARG : IIT_VT<isVoid, 29>;
295def IIT_HALF_VEC_ARG : IIT_Base<30>;
296def IIT_SAME_VEC_WIDTH_ARG : IIT_Base<31>;
297def IIT_VEC_OF_ANYPTRS_TO_ELT : IIT_Base<34>;
298def IIT_I128 : IIT_Int<128, 35>;
299def IIT_V512 : IIT_Vec<512, 36>;
300def IIT_V1024 : IIT_Vec<1024, 37>;
301def IIT_STRUCT6 : IIT_Base<38>;
302def IIT_STRUCT7 : IIT_Base<39>;
303def IIT_STRUCT8 : IIT_Base<40>;
304def IIT_F128 : IIT_VT<f128, 41>;
305def IIT_VEC_ELEMENT : IIT_Base<42>;
306def IIT_SCALABLE_VEC : IIT_Base<43>;
307def IIT_SUBDIVIDE2_ARG : IIT_Base<44>;
308def IIT_SUBDIVIDE4_ARG : IIT_Base<45>;
309def IIT_VEC_OF_BITCASTS_TO_INT : IIT_Base<46>;
310def IIT_V128 : IIT_Vec<128, 47>;
311def IIT_BF16 : IIT_VT<bf16, 48>;
312def IIT_STRUCT9 : IIT_Base<49>;
313def IIT_V256 : IIT_Vec<256, 50>;
314def IIT_AMX : IIT_VT<x86amx, 51>;
315def IIT_PPCF128 : IIT_VT<ppcf128, 52>;
316def IIT_V3 : IIT_Vec<3, 53>;
317def IIT_EXTERNREF : IIT_VT<externref, 54>;
318def IIT_FUNCREF : IIT_VT<funcref, 55>;
319def IIT_I2 : IIT_Int<2, 57>;
320def IIT_I4 : IIT_Int<4, 58>;
321def IIT_AARCH64_SVCOUNT : IIT_VT<aarch64svcount, 59>;
322}
323
324defvar IIT_all_FixedTypes = !filter(iit, IIT_all,
325  !or(!isa<IIT_VT>(iit), !isa<IIT_Int>(iit)));
326
327defvar IIT_all_VectorTypes = !filter(iit, IIT_all,
328  !isa<IIT_Vec>(iit));
329
330defvar IIT_RetNumbers = [
331  [IIT_Done.Number],
332  []<int>,
333  [IIT_STRUCT2.Number],
334  [IIT_STRUCT3.Number],
335  [IIT_STRUCT4.Number],
336  [IIT_STRUCT5.Number],
337  [IIT_STRUCT6.Number],
338  [IIT_STRUCT7.Number],
339  [IIT_STRUCT8.Number],
340  [IIT_STRUCT9.Number],
341];
342
343//===----------------------------------------------------------------------===//
344// Types used by intrinsics.
345//===----------------------------------------------------------------------===//
346
347class LLVMType<ValueType vt> {
348  ValueType VT = vt;
349  int isAny = vt.isOverloaded;
350
351  int ArgCode = ?;
352  int Number = ?;
353
354  list<IIT_Base> IITs = !filter(iit, IIT_all_FixedTypes,
355    !not(!empty(!filter(iit_vt, iit.VTs,
356      !eq(iit_vt, !if(vt.isVector, vt.ElementType, vt))))));
357  assert !le(!size(IITs), 1), "Duplicate type";
358
359  list<IIT_Base> IIT_Vecs = !if(vt.isVector,
360    !filter(iit, IIT_all_VectorTypes,
361      !not(!empty(!filter(iit_vt, iit.VTs, !and(
362        !eq(iit_vt.ElementType, vt.ElementType),
363        !eq(iit_vt.nElem, vt.nElem)))))),
364    []);
365  assert !le(!size(IIT_Vecs), 1), "Duplicate type";
366
367  list<int> Sig = !listconcat(
368    !if(vt.isScalable, [IIT_SCALABLE_VEC.Number], []),
369    !foreach(iit, IIT_Vecs, iit.Number),
370    !foreach(iit, IITs,     iit.Number));
371}
372
373class LLVMAnyType<ValueType vt> : LLVMType<vt> {
374  let ArgCode = !cond(
375    !eq(vt, Any)     : ArgKind.Any,
376    !eq(vt, iAny)    : ArgKind.AnyInteger,
377    !eq(vt, fAny)    : ArgKind.AnyFloat,
378    !eq(vt, vAny)    : ArgKind.AnyVector,
379    !eq(vt, iPTRAny) : ArgKind.AnyPointer,
380  );
381  let Sig = [
382    IIT_ARG.Number,
383    EncAnyType<ArgCode>.ret,
384  ];
385
386  assert isAny, "LLVMAnyType.VT should have isOverloaded";
387}
388
389class LLVMQualPointerType<int addrspace>
390  : LLVMType<iPTR> {
391  assert !and(!le(0, addrspace), !le(addrspace, 255)),
392    "Address space exceeds 255";
393
394  let Sig =
395    !if(addrspace, [
396      IIT_ANYPTR.Number,
397      addrspace,
398    ], [
399      IIT_PTR.Number,
400    ]);
401}
402
403class LLVMAnyPointerType : LLVMAnyType<iPTRAny> {
404  assert isAny, "iPTRAny should have isOverloaded";
405}
406
407// Match the type of another intrinsic parameter.  Number is an index into the
408// list of overloaded types for the intrinsic, excluding all the fixed types.
409// The Number value must refer to a previously listed type.  For example:
410//   Intrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_anyfloat_ty, LLVMMatchType<0>]>
411// has two overloaded types, the 2nd and 3rd arguments.  LLVMMatchType<0>
412// refers to the first overloaded type, which is the 2nd argument.
413class LLVMMatchType<int num, IIT_Base IIT_Info = IIT_ARG>
414  : LLVMType<OtherVT>{
415  let Number = num;
416  let Sig = [
417    IIT_Info.Number,
418    EncMatchType<num>.ret,
419  ];
420}
421
422class LLVMMatchTypeNextArg<int num, IIT_Base IIT_Info>
423  : LLVMMatchType<num, IIT_Info> {
424  let Sig = [
425    IIT_Info.Number,
426    EncNextArgA<>.ret,
427    EncNextArgN<num>.ret,
428  ];
429}
430
431// Match the type of another intrinsic parameter that is expected to be based on
432// an integral type (i.e. either iN or <N x iM>), but change the scalar size to
433// be twice as wide or half as wide as the other type.  This is only useful when
434// the intrinsic is overloaded, so the matched type should be declared as iAny.
435class LLVMExtendedType<int num> : LLVMMatchType<num, IIT_EXTEND_ARG>;
436class LLVMTruncatedType<int num> : LLVMMatchType<num, IIT_TRUNC_ARG>;
437
438// Match the scalar/vector of another intrinsic parameter but with a different
439// element type. Either both are scalars or both are vectors with the same
440// number of elements.
441class LLVMScalarOrSameVectorWidth<int idx, LLVMType elty>
442  : LLVMMatchType<idx, IIT_SAME_VEC_WIDTH_ARG> {
443  let Sig = !listconcat([
444    IIT_SAME_VEC_WIDTH_ARG.Number,
445    EncSameWidth<idx>.ret,
446  ], elty.Sig);
447}
448
449class LLVMVectorOfAnyPointersToElt<int num>
450  : LLVMMatchTypeNextArg<num, IIT_VEC_OF_ANYPTRS_TO_ELT>;
451class LLVMVectorElementType<int num> : LLVMMatchType<num, IIT_VEC_ELEMENT>;
452
453// Match the type of another intrinsic parameter that is expected to be a
454// vector type, but change the element count to be half as many.
455class LLVMHalfElementsVectorType<int num>
456  : LLVMMatchType<num, IIT_HALF_VEC_ARG>;
457
458// Match the type of another intrinsic parameter that is expected to be a
459// vector type (i.e. <N x iM>) but with each element subdivided to
460// form a vector with more elements that are smaller than the original.
461class LLVMSubdivide2VectorType<int num>
462  : LLVMMatchType<num, IIT_SUBDIVIDE2_ARG>;
463class LLVMSubdivide4VectorType<int num>
464  : LLVMMatchType<num, IIT_SUBDIVIDE4_ARG>;
465
466// Match the element count and bit width of another intrinsic parameter, but
467// change the element type to an integer.
468class LLVMVectorOfBitcastsToInt<int num>
469  : LLVMMatchType<num, IIT_VEC_OF_BITCASTS_TO_INT>;
470
471def llvm_void_ty       : LLVMType<isVoid>;
472
473def llvm_any_ty        : LLVMAnyType<Any>;
474def llvm_anyint_ty     : LLVMAnyType<iAny>;
475def llvm_anyfloat_ty   : LLVMAnyType<fAny>;
476def llvm_anyvector_ty  : LLVMAnyType<vAny>;
477
478def llvm_i1_ty         : LLVMType<i1>;
479def llvm_i8_ty         : LLVMType<i8>;
480def llvm_i16_ty        : LLVMType<i16>;
481def llvm_i32_ty        : LLVMType<i32>;
482def llvm_i64_ty        : LLVMType<i64>;
483def llvm_i128_ty       : LLVMType<i128>;
484def llvm_half_ty       : LLVMType<f16>;
485def llvm_bfloat_ty     : LLVMType<bf16>;
486def llvm_float_ty      : LLVMType<f32>;
487def llvm_double_ty     : LLVMType<f64>;
488def llvm_f80_ty        : LLVMType<f80>;
489def llvm_f128_ty       : LLVMType<f128>;
490def llvm_ppcf128_ty    : LLVMType<ppcf128>;
491def llvm_ptr_ty        : LLVMQualPointerType<0>; // ptr
492def llvm_anyptr_ty     : LLVMAnyPointerType;     // ptr addrspace(N)
493def llvm_empty_ty      : LLVMType<OtherVT>;      // { }
494def llvm_metadata_ty   : LLVMType<MetadataVT>;   // !{...}
495def llvm_token_ty      : LLVMType<token>;        // token
496
497def llvm_x86mmx_ty     : LLVMType<x86mmx>;
498
499def llvm_aarch64_svcount_ty : LLVMType<aarch64svcount>;
500
501def llvm_x86amx_ty     : LLVMType<x86amx>;
502
503def llvm_v2i1_ty       : LLVMType<v2i1>;     //   2 x i1
504def llvm_v4i1_ty       : LLVMType<v4i1>;     //   4 x i1
505def llvm_v8i1_ty       : LLVMType<v8i1>;     //   8 x i1
506def llvm_v16i1_ty      : LLVMType<v16i1>;    //  16 x i1
507def llvm_v32i1_ty      : LLVMType<v32i1>;    //  32 x i1
508def llvm_v64i1_ty      : LLVMType<v64i1>;    //  64 x i1
509def llvm_v128i1_ty     : LLVMType<v128i1>;   // 128 x i1
510def llvm_v256i1_ty     : LLVMType<v256i1>;   // 256 x i1
511def llvm_v512i1_ty     : LLVMType<v512i1>;   // 512 x i1
512def llvm_v1024i1_ty    : LLVMType<v1024i1>;  //1024 x i1
513def llvm_v2048i1_ty    : LLVMType<v2048i1>;  //2048 x i1
514
515def llvm_v1i8_ty       : LLVMType<v1i8>;     //  1 x i8
516def llvm_v2i8_ty       : LLVMType<v2i8>;     //  2 x i8
517def llvm_v3i8_ty       : LLVMType<v3i8>;     //  3 x i8
518def llvm_v4i8_ty       : LLVMType<v4i8>;     //  4 x i8
519def llvm_v8i8_ty       : LLVMType<v8i8>;     //  8 x i8
520def llvm_v16i8_ty      : LLVMType<v16i8>;    // 16 x i8
521def llvm_v32i8_ty      : LLVMType<v32i8>;    // 32 x i8
522def llvm_v64i8_ty      : LLVMType<v64i8>;    // 64 x i8
523def llvm_v128i8_ty     : LLVMType<v128i8>;   //128 x i8
524def llvm_v256i8_ty     : LLVMType<v256i8>;   //256 x i8
525
526def llvm_v1i16_ty      : LLVMType<v1i16>;    //  1 x i16
527def llvm_v2i16_ty      : LLVMType<v2i16>;    //  2 x i16
528def llvm_v4i16_ty      : LLVMType<v4i16>;    //  4 x i16
529def llvm_v8i16_ty      : LLVMType<v8i16>;    //  8 x i16
530def llvm_v16i16_ty     : LLVMType<v16i16>;   // 16 x i16
531def llvm_v32i16_ty     : LLVMType<v32i16>;   // 32 x i16
532def llvm_v64i16_ty     : LLVMType<v64i16>;   // 64 x i16
533def llvm_v128i16_ty    : LLVMType<v128i16>;  //128 x i16
534
535def llvm_v1i32_ty      : LLVMType<v1i32>;    //  1 x i32
536def llvm_v2i32_ty      : LLVMType<v2i32>;    //  2 x i32
537def llvm_v3i32_ty      : LLVMType<v3i32>;    //  3 x i32
538def llvm_v4i32_ty      : LLVMType<v4i32>;    //  4 x i32
539def llvm_v6i32_ty      : LLVMType<v6i32>;    //  6 x i32
540def llvm_v8i32_ty      : LLVMType<v8i32>;    //  8 x i32
541def llvm_v16i32_ty     : LLVMType<v16i32>;   // 16 x i32
542def llvm_v32i32_ty     : LLVMType<v32i32>;   // 32 x i32
543def llvm_v64i32_ty     : LLVMType<v64i32>;   // 64 x i32
544def llvm_v256i32_ty    : LLVMType<v256i32>;  //256 x i32
545
546def llvm_v1i64_ty      : LLVMType<v1i64>;    //  1 x i64
547def llvm_v2i64_ty      : LLVMType<v2i64>;    //  2 x i64
548def llvm_v4i64_ty      : LLVMType<v4i64>;    //  4 x i64
549def llvm_v8i64_ty      : LLVMType<v8i64>;    //  8 x i64
550def llvm_v16i64_ty     : LLVMType<v16i64>;   // 16 x i64
551def llvm_v32i64_ty     : LLVMType<v32i64>;   // 32 x i64
552
553def llvm_v1i128_ty     : LLVMType<v1i128>;   //  1 x i128
554
555def llvm_v2f16_ty      : LLVMType<v2f16>;    //  2 x half (__fp16)
556def llvm_v4f16_ty      : LLVMType<v4f16>;    //  4 x half (__fp16)
557def llvm_v8f16_ty      : LLVMType<v8f16>;    //  8 x half (__fp16)
558def llvm_v16f16_ty     : LLVMType<v16f16>;   // 16 x half (__fp16)
559def llvm_v32f16_ty     : LLVMType<v32f16>;   // 32 x half (__fp16)
560def llvm_v2bf16_ty     : LLVMType<v2bf16>;   //  2 x bfloat (__bf16)
561def llvm_v4bf16_ty     : LLVMType<v4bf16>;   //  4 x bfloat (__bf16)
562def llvm_v8bf16_ty     : LLVMType<v8bf16>;   //  8 x bfloat (__bf16)
563def llvm_v16bf16_ty    : LLVMType<v16bf16>;  // 16 x bfloat (__bf16)
564def llvm_v32bf16_ty    : LLVMType<v32bf16>;  // 32 x bfloat (__bf16)
565def llvm_v1f32_ty      : LLVMType<v1f32>;    //  1 x float
566def llvm_v2f32_ty      : LLVMType<v2f32>;    //  2 x float
567def llvm_v3f32_ty      : LLVMType<v3f32>;    //  3 x float
568def llvm_v4f32_ty      : LLVMType<v4f32>;    //  4 x float
569def llvm_v8f32_ty      : LLVMType<v8f32>;    //  8 x float
570def llvm_v16f32_ty     : LLVMType<v16f32>;   // 16 x float
571def llvm_v32f32_ty     : LLVMType<v32f32>;   // 32 x float
572def llvm_v1f64_ty      : LLVMType<v1f64>;    //  1 x double
573def llvm_v2f64_ty      : LLVMType<v2f64>;    //  2 x double
574def llvm_v4f64_ty      : LLVMType<v4f64>;    //  4 x double
575def llvm_v8f64_ty      : LLVMType<v8f64>;    //  8 x double
576def llvm_v16f64_ty     : LLVMType<v16f64>;   // 16 x double
577
578def llvm_vararg_ty     : LLVMType<isVoid>;   // this means vararg here
579
580def llvm_externref_ty  : LLVMType<externref>;
581def llvm_funcref_ty    : LLVMType<funcref>;
582
583//===----------------------------------------------------------------------===//
584
585class MakeIdx<list<int> Set> {
586  list<int> IdxsR = !foreach(i, !range(Set),
587    !if(Set[i],
588      !foldl(0, !range(0, i), m, j, !add(m, Set[j])),
589      -1));
590
591  list<int> RIdxsR = !foreach(i, !range(Set),
592    !foldl(-1, !range(Set), m, j,
593      !if(!and(Set[j], !eq(IdxsR[j], i)), j, m)));
594
595  list<int> Idxs  = !foreach(a, IdxsR,  !if(!ge(a, 0), a, ?));
596  list<int> RIdxs = !foreach(a, RIdxsR, !if(!ge(a, 0), a, ?));
597}
598
599class TypeInfoGen<
600    list<LLVMType> RetTypes,
601    list<LLVMType> ParamTypes> {
602  list<LLVMType> AllTypes = !listconcat(RetTypes, ParamTypes);
603
604  // ArgCodes for NextArg -- isAny or MatchTypeNextArg
605  list<int> ACIdxs = MakeIdx<
606    !foreach(ty, AllTypes,
607      !or(ty.isAny, !isa<LLVMMatchTypeNextArg>(ty)))>.Idxs;
608
609  // ArgCodes (only for isAny or MatchTypeNextArg)
610  list<LLVMType> ACTys = !filter(ty, AllTypes,
611    !or(ty.isAny, !isa<LLVMMatchTypeNextArg>(ty)));
612
613  list<int> ArgCodes = !foreach(ty, ACTys, ty.ArgCode);
614
615  // Mappings MatchTypeIdx to ACTys
616  list<int> MappingRIdxs = MakeIdx<
617    !foreach(ty, ACTys, ty.isAny)>.RIdxs;
618
619  // D63507: Exclude LLVMPointerType<llvm_any_ty>
620  bit isOverloaded = !not(!empty(!filter(ty, AllTypes,
621    !isa<LLVMAnyType>(ty))));
622
623  list<LLVMType> Types = !foreach(ty, AllTypes,
624    !if(!isa<LLVMMatchType>(ty), ACTys[MappingRIdxs[ty.Number]], ty));
625
626  list<list<int>> TypeSig = !listconcat(
627    [IIT_RetNumbers[!size(RetTypes)]],
628    !foreach(i, !range(AllTypes),
629      !foreach(a, AllTypes[i].Sig,
630        ResolveArgCode<
631          MappingRIdxs,
632          ArgCodes,
633          ACIdxs[i],
634          a>.ret)));
635}
636
637//===----------------------------------------------------------------------===//
638// Intrinsic Definitions.
639//===----------------------------------------------------------------------===//
640
641// Intrinsic class - This is used to define one LLVM intrinsic.  The name of the
642// intrinsic definition should start with "int_", then match the LLVM intrinsic
643// name with the "llvm." prefix removed, and all "."s turned into "_"s.  For
644// example, llvm.bswap.i16 -> int_bswap_i16.
645//
646//  * RetTypes is a list containing the return types expected for the
647//    intrinsic.
648//  * ParamTypes is a list containing the parameter types expected for the
649//    intrinsic.
650//  * Properties can be set to describe the behavior of the intrinsic.
651//
652class Intrinsic<list<LLVMType> ret_types,
653                list<LLVMType> param_types = [],
654                list<IntrinsicProperty> intr_properties = [],
655                string name = "",
656                list<SDNodeProperty> sd_properties = [],
657                bit disable_default_attributes = true> : SDPatternOperator {
658  string LLVMName = name;
659  string TargetPrefix = "";   // Set to a prefix for target-specific intrinsics.
660  list<LLVMType> RetTypes = ret_types;
661  list<LLVMType> ParamTypes = param_types;
662  list<IntrinsicProperty> IntrProperties = intr_properties;
663  let Properties = sd_properties;
664
665  // Disable applying IntrinsicProperties that are marked default with
666  // IntrinsicProperty<1>
667  bit DisableDefaultAttributes = disable_default_attributes;
668
669  bit isTarget = false;
670
671  TypeInfoGen TypeInfo = TypeInfoGen<RetTypes, ParamTypes>;
672  bit isOverloaded = TypeInfo.isOverloaded;
673  list<LLVMType> Types = TypeInfo.Types;
674  list<list<int>> TypeSig = TypeInfo.TypeSig;
675}
676
677// Intrinsic with default attributes (disable_default_attributes = false).
678class DefaultAttrsIntrinsic<list<LLVMType> ret_types,
679                list<LLVMType> param_types = [],
680                list<IntrinsicProperty> intr_properties = [],
681                string name = "",
682                list<SDNodeProperty> sd_properties = []>
683                : Intrinsic<ret_types, param_types,
684                            intr_properties, name,
685                            sd_properties, /*disable_default_attributes*/ 0> {}
686
687/// ClangBuiltin - If this intrinsic exactly corresponds to a Clang builtin, this
688/// specifies the name of the builtin.  This provides automatic CBE and CFE
689/// support.
690class ClangBuiltin<string name> {
691  string ClangBuiltinName = name;
692}
693
694class MSBuiltin<string name> {
695  string MSBuiltinName = name;
696}
697
698#ifndef TEST_INTRINSICS_SUPPRESS_DEFS
699
700//===--------------- Variable Argument Handling Intrinsics ----------------===//
701//
702
703def int_vastart : DefaultAttrsIntrinsic<[], [llvm_ptr_ty], [], "llvm.va_start">;
704def int_vacopy  : DefaultAttrsIntrinsic<[], [llvm_ptr_ty, llvm_ptr_ty], [],
705                            "llvm.va_copy">;
706def int_vaend   : DefaultAttrsIntrinsic<[], [llvm_ptr_ty], [], "llvm.va_end">;
707
708//===------------------- Garbage Collection Intrinsics --------------------===//
709//
710def int_gcroot  : Intrinsic<[],
711                            [llvm_ptr_ty, llvm_ptr_ty]>;
712def int_gcread  : Intrinsic<[llvm_ptr_ty],
713                            [llvm_ptr_ty, llvm_ptr_ty],
714                            [IntrReadMem, IntrArgMemOnly]>;
715def int_gcwrite : Intrinsic<[],
716                            [llvm_ptr_ty, llvm_ptr_ty, llvm_ptr_ty],
717                            [IntrArgMemOnly, NoCapture<ArgIndex<1>>,
718                             NoCapture<ArgIndex<2>>]>;
719
720//===------------------- ObjC ARC runtime Intrinsics --------------------===//
721//
722// Note these are to support the Objective-C ARC optimizer which wants to
723// eliminate retain and releases where possible.
724
725def int_objc_autorelease                    : Intrinsic<[llvm_ptr_ty],
726                                                        [llvm_ptr_ty],
727                                                        [Returned<ArgIndex<0>>]>;
728def int_objc_autoreleasePoolPop             : Intrinsic<[], [llvm_ptr_ty]>;
729def int_objc_autoreleasePoolPush            : Intrinsic<[llvm_ptr_ty], []>;
730def int_objc_autoreleaseReturnValue         : Intrinsic<[llvm_ptr_ty],
731                                                        [llvm_ptr_ty],
732                                                        [Returned<ArgIndex<0>>]>;
733def int_objc_copyWeak                       : Intrinsic<[],
734                                                        [llvm_ptr_ty,
735                                                         llvm_ptr_ty]>;
736def int_objc_destroyWeak                    : Intrinsic<[], [llvm_ptr_ty]>;
737def int_objc_initWeak                       : Intrinsic<[llvm_ptr_ty],
738                                                        [llvm_ptr_ty,
739                                                         llvm_ptr_ty]>;
740def int_objc_loadWeak                       : Intrinsic<[llvm_ptr_ty],
741                                                        [llvm_ptr_ty]>;
742def int_objc_loadWeakRetained               : Intrinsic<[llvm_ptr_ty],
743                                                        [llvm_ptr_ty]>;
744def int_objc_moveWeak                       : Intrinsic<[],
745                                                        [llvm_ptr_ty,
746                                                         llvm_ptr_ty]>;
747def int_objc_release                        : Intrinsic<[], [llvm_ptr_ty]>;
748def int_objc_retain                         : Intrinsic<[llvm_ptr_ty],
749                                                        [llvm_ptr_ty],
750                                                        [Returned<ArgIndex<0>>]>;
751def int_objc_retainAutorelease              : Intrinsic<[llvm_ptr_ty],
752                                                        [llvm_ptr_ty],
753                                                        [Returned<ArgIndex<0>>]>;
754def int_objc_retainAutoreleaseReturnValue   : Intrinsic<[llvm_ptr_ty],
755                                                        [llvm_ptr_ty],
756                                                        [Returned<ArgIndex<0>>]>;
757def int_objc_retainAutoreleasedReturnValue  : Intrinsic<[llvm_ptr_ty],
758                                                        [llvm_ptr_ty]>;
759def int_objc_retainBlock                    : Intrinsic<[llvm_ptr_ty],
760                                                        [llvm_ptr_ty]>;
761def int_objc_storeStrong                    : Intrinsic<[],
762                                                        [llvm_ptr_ty,
763                                                         llvm_ptr_ty]>;
764def int_objc_storeWeak                      : Intrinsic<[llvm_ptr_ty],
765                                                        [llvm_ptr_ty,
766                                                         llvm_ptr_ty]>;
767def int_objc_clang_arc_use                  : Intrinsic<[],
768                                                        [llvm_vararg_ty]>;
769def int_objc_clang_arc_noop_use : DefaultAttrsIntrinsic<[],
770                                                        [llvm_vararg_ty],
771                                                        [IntrInaccessibleMemOnly]>;
772def int_objc_unsafeClaimAutoreleasedReturnValue : Intrinsic<[llvm_ptr_ty],
773                                                            [llvm_ptr_ty]>;
774def int_objc_retainedObject                 : Intrinsic<[llvm_ptr_ty],
775                                                        [llvm_ptr_ty]>;
776def int_objc_unretainedObject               : Intrinsic<[llvm_ptr_ty],
777                                                        [llvm_ptr_ty]>;
778def int_objc_unretainedPointer              : Intrinsic<[llvm_ptr_ty],
779                                                        [llvm_ptr_ty]>;
780def int_objc_retain_autorelease             : Intrinsic<[llvm_ptr_ty],
781                                                        [llvm_ptr_ty],
782                                                        [Returned<ArgIndex<0>>]>;
783def int_objc_sync_enter                     : Intrinsic<[llvm_i32_ty],
784                                                        [llvm_ptr_ty]>;
785def int_objc_sync_exit                      : Intrinsic<[llvm_i32_ty],
786                                                        [llvm_ptr_ty]>;
787def int_objc_arc_annotation_topdown_bbstart : Intrinsic<[],
788                                                        [llvm_ptr_ty,
789                                                         llvm_ptr_ty]>;
790def int_objc_arc_annotation_topdown_bbend   : Intrinsic<[],
791                                                        [llvm_ptr_ty,
792                                                         llvm_ptr_ty]>;
793def int_objc_arc_annotation_bottomup_bbstart  : Intrinsic<[],
794                                                          [llvm_ptr_ty,
795                                                           llvm_ptr_ty]>;
796def int_objc_arc_annotation_bottomup_bbend  : Intrinsic<[],
797                                                        [llvm_ptr_ty,
798                                                         llvm_ptr_ty]>;
799//===--------------- Swift asynchronous context intrinsics ----------------===//
800
801// Returns the location of the Swift asynchronous context (usually stored just
802// before the frame pointer), and triggers the creation of a null context if it
803// would otherwise be unneeded.
804def int_swift_async_context_addr : Intrinsic<[llvm_ptr_ty], [], []>;
805
806//===--------------------- Code Generator Intrinsics ----------------------===//
807//
808def int_returnaddress : DefaultAttrsIntrinsic<[llvm_ptr_ty], [llvm_i32_ty],
809                                  [IntrNoMem, ImmArg<ArgIndex<0>>]>;
810def int_addressofreturnaddress : DefaultAttrsIntrinsic<[llvm_anyptr_ty], [], [IntrNoMem]>;
811def int_frameaddress : DefaultAttrsIntrinsic<[llvm_anyptr_ty], [llvm_i32_ty],
812                                 [IntrNoMem, ImmArg<ArgIndex<0>>]>;
813def int_sponentry  : DefaultAttrsIntrinsic<[llvm_anyptr_ty], [], [IntrNoMem]>;
814def int_read_register  : DefaultAttrsIntrinsic<[llvm_anyint_ty], [llvm_metadata_ty],
815                                   [IntrReadMem], "llvm.read_register">;
816def int_write_register : Intrinsic<[], [llvm_metadata_ty, llvm_anyint_ty],
817                                   [IntrNoCallback], "llvm.write_register">;
818def int_read_volatile_register  : Intrinsic<[llvm_anyint_ty], [llvm_metadata_ty],
819                                            [IntrHasSideEffects],
820                                             "llvm.read_volatile_register">;
821
822// Gets the address of the local variable area. This is typically a copy of the
823// stack, frame, or base pointer depending on the type of prologue.
824def int_localaddress : DefaultAttrsIntrinsic<[llvm_ptr_ty], [], [IntrNoMem]>;
825
826// Escapes local variables to allow access from other functions.
827def int_localescape : DefaultAttrsIntrinsic<[], [llvm_vararg_ty]>;
828
829// Given a function and the localaddress of a parent frame, returns a pointer
830// to an escaped allocation indicated by the index.
831def int_localrecover : DefaultAttrsIntrinsic<[llvm_ptr_ty],
832                                 [llvm_ptr_ty, llvm_ptr_ty, llvm_i32_ty],
833                                 [IntrNoMem, ImmArg<ArgIndex<2>>]>;
834
835// Given the frame pointer passed into an SEH filter function, returns a
836// pointer to the local variable area suitable for use with llvm.localrecover.
837def int_eh_recoverfp : DefaultAttrsIntrinsic<[llvm_ptr_ty],
838                                 [llvm_ptr_ty, llvm_ptr_ty],
839                                 [IntrNoMem]>;
840
841// To mark the beginning/end of a try-scope for Windows SEH -EHa
842//  calls/invokes to these intrinsics are placed to model control flows
843//    caused by HW exceptions under option -EHa.
844//  calls/invokes to these intrinsics will be discarded during a codegen pass
845//   after EH tables are generated
846def int_seh_try_begin : Intrinsic<[], [], [IntrWriteMem, IntrWillReturn]>;
847def int_seh_try_end : Intrinsic<[], [], [IntrWriteMem, IntrWillReturn]>;
848def int_seh_scope_begin : Intrinsic<[], [], [IntrNoMem]>;
849def int_seh_scope_end : Intrinsic<[], [], [IntrNoMem]>;
850
851// Note: we treat stacksave/stackrestore as writemem because we don't otherwise
852// model their dependencies on allocas.
853def int_stacksave     : DefaultAttrsIntrinsic<[llvm_anyptr_ty]>,
854                        ClangBuiltin<"__builtin_stack_save">;
855def int_stackrestore  : DefaultAttrsIntrinsic<[], [llvm_anyptr_ty]>,
856                        ClangBuiltin<"__builtin_stack_restore">;
857
858def int_get_dynamic_area_offset : DefaultAttrsIntrinsic<[llvm_anyint_ty]>;
859
860def int_thread_pointer : DefaultAttrsIntrinsic<[llvm_ptr_ty], [], [IntrNoMem]>,
861                         ClangBuiltin<"__builtin_thread_pointer">;
862
863// IntrInaccessibleMemOrArgMemOnly is a little more pessimistic than strictly
864// necessary for prefetch, however it does conveniently prevent the prefetch
865// from being reordered overly much with respect to nearby access to the same
866// memory while not impeding optimization.
867def int_prefetch
868    : DefaultAttrsIntrinsic<[], [ llvm_anyptr_ty, llvm_i32_ty, llvm_i32_ty, llvm_i32_ty ],
869                [IntrInaccessibleMemOrArgMemOnly, IntrWillReturn,
870                 ReadOnly<ArgIndex<0>>, NoCapture<ArgIndex<0>>,
871                 ImmArg<ArgIndex<1>>, ImmArg<ArgIndex<2>>, ImmArg<ArgIndex<3>>]>;
872def int_pcmarker      : DefaultAttrsIntrinsic<[], [llvm_i32_ty]>;
873
874def int_readcyclecounter : DefaultAttrsIntrinsic<[llvm_i64_ty]>;
875
876def int_readsteadycounter : DefaultAttrsIntrinsic<[llvm_i64_ty]>;
877
878// The assume intrinsic is marked InaccessibleMemOnly so that proper control
879// dependencies will be maintained.
880def int_assume : DefaultAttrsIntrinsic<
881    [], [llvm_i1_ty], [IntrWriteMem, IntrInaccessibleMemOnly, NoUndef<ArgIndex<0>>]>;
882
883// 'llvm.experimental.noalias.scope.decl' intrinsic: Inserted at the location of
884// noalias scope declaration. Makes it possible to identify that a noalias scope
885// is only valid inside the body of a loop.
886//
887// Purpose of the different arguments:
888// - arg0: id.scope: metadata representing the scope declaration.
889def int_experimental_noalias_scope_decl
890    : DefaultAttrsIntrinsic<[], [llvm_metadata_ty],
891        [IntrInaccessibleMemOnly]>; // blocks LICM and some more
892
893// Stack Protector Intrinsic - The stackprotector intrinsic writes the stack
894// guard to the correct place on the stack frame.
895def int_stackprotector : DefaultAttrsIntrinsic<[], [llvm_ptr_ty, llvm_ptr_ty], []>;
896def int_stackguard : DefaultAttrsIntrinsic<[llvm_ptr_ty], [], []>;
897
898// A cover for instrumentation based profiling.
899def int_instrprof_cover : Intrinsic<[], [llvm_ptr_ty, llvm_i64_ty,
900                                         llvm_i32_ty, llvm_i32_ty]>;
901
902// A counter increment for instrumentation based profiling.
903def int_instrprof_increment : Intrinsic<[],
904                                        [llvm_ptr_ty, llvm_i64_ty,
905                                         llvm_i32_ty, llvm_i32_ty]>;
906
907// A counter increment with step for instrumentation based profiling.
908def int_instrprof_increment_step : Intrinsic<[],
909                                        [llvm_ptr_ty, llvm_i64_ty,
910                                         llvm_i32_ty, llvm_i32_ty, llvm_i64_ty]>;
911
912// A timestamp for instrumentation based profiling.
913def int_instrprof_timestamp : Intrinsic<[], [llvm_ptr_ty, llvm_i64_ty,
914                                             llvm_i32_ty, llvm_i32_ty]>;
915
916// A call to profile runtime for value profiling of target expressions
917// through instrumentation based profiling.
918def int_instrprof_value_profile : Intrinsic<[],
919                                            [llvm_ptr_ty, llvm_i64_ty,
920                                             llvm_i64_ty, llvm_i32_ty,
921                                             llvm_i32_ty]>;
922
923// A parameter configuration for instrumentation based MCDC profiling.
924def int_instrprof_mcdc_parameters : Intrinsic<[],
925                                              [llvm_ptr_ty, llvm_i64_ty,
926                                               llvm_i32_ty]>;
927
928// A test vector bitmap update for instrumentation based MCDC profiling.
929def int_instrprof_mcdc_tvbitmap_update : Intrinsic<[],
930                                        [llvm_ptr_ty, llvm_i64_ty,
931                                         llvm_i32_ty, llvm_i32_ty, llvm_ptr_ty]>;
932
933// A condition bitmap value update for instrumentation based MCDC profiling.
934def int_instrprof_mcdc_condbitmap_update : Intrinsic<[],
935                                        [llvm_ptr_ty, llvm_i64_ty,
936                                         llvm_i32_ty, llvm_ptr_ty, llvm_i1_ty]>;
937
938def int_call_preallocated_setup : DefaultAttrsIntrinsic<[llvm_token_ty], [llvm_i32_ty]>;
939def int_call_preallocated_arg : DefaultAttrsIntrinsic<[llvm_ptr_ty], [llvm_token_ty, llvm_i32_ty]>;
940def int_call_preallocated_teardown : DefaultAttrsIntrinsic<[], [llvm_token_ty]>;
941
942// This intrinsic is intentionally undocumented and users shouldn't call it;
943// it's produced then quickly consumed during codegen.
944def int_callbr_landingpad : Intrinsic<[llvm_any_ty], [LLVMMatchType<0>],
945                                      [IntrNoMerge]>;
946
947//===------------------- Standard C Library Intrinsics --------------------===//
948//
949
950def int_memcpy  : Intrinsic<[],
951                            [llvm_anyptr_ty, llvm_anyptr_ty, llvm_anyint_ty,
952                             llvm_i1_ty],
953                            [IntrArgMemOnly, IntrWillReturn, IntrNoFree,
954                             IntrNoCallback,
955                             NoCapture<ArgIndex<0>>, NoCapture<ArgIndex<1>>,
956                             NoAlias<ArgIndex<0>>, NoAlias<ArgIndex<1>>,
957                             WriteOnly<ArgIndex<0>>, ReadOnly<ArgIndex<1>>,
958                             ImmArg<ArgIndex<3>>]>;
959
960// Memcpy semantic that is guaranteed to be inlined.
961// In particular this means that the generated code is not allowed to call any
962// external function.
963// The third argument (specifying the size) must be a constant.
964def int_memcpy_inline
965    : Intrinsic<[],
966      [llvm_anyptr_ty, llvm_anyptr_ty, llvm_anyint_ty, llvm_i1_ty],
967      [IntrArgMemOnly, IntrWillReturn, IntrNoFree, IntrNoCallback,
968       NoCapture<ArgIndex<0>>, NoCapture<ArgIndex<1>>,
969       NoAlias<ArgIndex<0>>, NoAlias<ArgIndex<1>>,
970       WriteOnly<ArgIndex<0>>, ReadOnly<ArgIndex<1>>,
971       ImmArg<ArgIndex<2>>, ImmArg<ArgIndex<3>>]>;
972
973def int_memmove : Intrinsic<[],
974                            [llvm_anyptr_ty, llvm_anyptr_ty, llvm_anyint_ty,
975                             llvm_i1_ty],
976                            [IntrArgMemOnly, IntrWillReturn, IntrNoFree,
977                             IntrNoCallback,
978                             NoCapture<ArgIndex<0>>, NoCapture<ArgIndex<1>>,
979                             WriteOnly<ArgIndex<0>>, ReadOnly<ArgIndex<1>>,
980                             ImmArg<ArgIndex<3>>]>;
981def int_memset  : Intrinsic<[],
982                            [llvm_anyptr_ty, llvm_i8_ty, llvm_anyint_ty,
983                             llvm_i1_ty],
984                            [IntrWriteMem, IntrArgMemOnly, IntrWillReturn,
985                             IntrNoFree, IntrNoCallback,
986                             NoCapture<ArgIndex<0>>, WriteOnly<ArgIndex<0>>,
987                             ImmArg<ArgIndex<3>>]>;
988
989// Memset version that is guaranteed to be inlined.
990// In particular this means that the generated code is not allowed to call any
991// external function.
992// The third argument (specifying the size) must be a constant.
993def int_memset_inline
994    : Intrinsic<[],
995      [llvm_anyptr_ty, llvm_i8_ty, llvm_anyint_ty, llvm_i1_ty],
996      [IntrWriteMem, IntrArgMemOnly, IntrWillReturn, IntrNoFree, IntrNoCallback,
997       NoCapture<ArgIndex<0>>, WriteOnly<ArgIndex<0>>,
998       ImmArg<ArgIndex<2>>, ImmArg<ArgIndex<3>>]>;
999
1000// FIXME: Add version of these floating point intrinsics which allow non-default
1001// rounding modes and FP exception handling.
1002
1003let IntrProperties = [IntrNoMem, IntrSpeculatable, IntrWillReturn] in {
1004  def int_fma  : DefaultAttrsIntrinsic<[llvm_anyfloat_ty],
1005                           [LLVMMatchType<0>, LLVMMatchType<0>,
1006                            LLVMMatchType<0>]>;
1007  def int_fmuladd : DefaultAttrsIntrinsic<[llvm_anyfloat_ty],
1008                              [LLVMMatchType<0>, LLVMMatchType<0>,
1009                               LLVMMatchType<0>]>;
1010
1011  // These functions do not read memory, but are sensitive to the
1012  // rounding mode. LLVM purposely does not model changes to the FP
1013  // environment so they can be treated as readnone.
1014  def int_sqrt : DefaultAttrsIntrinsic<[llvm_anyfloat_ty], [LLVMMatchType<0>]>;
1015  def int_powi : DefaultAttrsIntrinsic<[llvm_anyfloat_ty], [LLVMMatchType<0>, llvm_anyint_ty]>;
1016  def int_sin  : DefaultAttrsIntrinsic<[llvm_anyfloat_ty], [LLVMMatchType<0>]>;
1017  def int_cos  : DefaultAttrsIntrinsic<[llvm_anyfloat_ty], [LLVMMatchType<0>]>;
1018  def int_pow  : DefaultAttrsIntrinsic<[llvm_anyfloat_ty],
1019                           [LLVMMatchType<0>, LLVMMatchType<0>]>;
1020  def int_log  : DefaultAttrsIntrinsic<[llvm_anyfloat_ty], [LLVMMatchType<0>]>;
1021  def int_log10: DefaultAttrsIntrinsic<[llvm_anyfloat_ty], [LLVMMatchType<0>]>;
1022  def int_log2 : DefaultAttrsIntrinsic<[llvm_anyfloat_ty], [LLVMMatchType<0>]>;
1023  def int_exp  : DefaultAttrsIntrinsic<[llvm_anyfloat_ty], [LLVMMatchType<0>]>;
1024  def int_exp2 : DefaultAttrsIntrinsic<[llvm_anyfloat_ty], [LLVMMatchType<0>]>;
1025  def int_exp10 : DefaultAttrsIntrinsic<[llvm_anyfloat_ty], [LLVMMatchType<0>]>;
1026  def int_fabs : DefaultAttrsIntrinsic<[llvm_anyfloat_ty], [LLVMMatchType<0>]>;
1027  def int_copysign : DefaultAttrsIntrinsic<[llvm_anyfloat_ty],
1028                               [LLVMMatchType<0>, LLVMMatchType<0>]>;
1029  def int_floor : DefaultAttrsIntrinsic<[llvm_anyfloat_ty], [LLVMMatchType<0>]>;
1030  def int_ceil  : DefaultAttrsIntrinsic<[llvm_anyfloat_ty], [LLVMMatchType<0>]>;
1031  def int_trunc : DefaultAttrsIntrinsic<[llvm_anyfloat_ty], [LLVMMatchType<0>]>;
1032  def int_rint  : DefaultAttrsIntrinsic<[llvm_anyfloat_ty], [LLVMMatchType<0>]>;
1033  def int_nearbyint : DefaultAttrsIntrinsic<[llvm_anyfloat_ty], [LLVMMatchType<0>]>;
1034  def int_round : DefaultAttrsIntrinsic<[llvm_anyfloat_ty], [LLVMMatchType<0>]>;
1035  def int_roundeven    : DefaultAttrsIntrinsic<[llvm_anyfloat_ty], [LLVMMatchType<0>]>;
1036
1037  // Truncate a floating point number with a specific rounding mode
1038  def int_fptrunc_round : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ],
1039                                                [ llvm_anyfloat_ty, llvm_metadata_ty ]>;
1040
1041  def int_canonicalize : DefaultAttrsIntrinsic<[llvm_anyfloat_ty], [LLVMMatchType<0>],
1042                                   [IntrNoMem]>;
1043  // Arithmetic fence intrinsic.
1044  def int_arithmetic_fence : DefaultAttrsIntrinsic<[llvm_anyfloat_ty], [LLVMMatchType<0>],
1045                                                   [IntrNoMem]>;
1046
1047  def int_lround : DefaultAttrsIntrinsic<[llvm_anyint_ty], [llvm_anyfloat_ty]>;
1048  def int_llround : DefaultAttrsIntrinsic<[llvm_anyint_ty], [llvm_anyfloat_ty]>;
1049  def int_lrint : DefaultAttrsIntrinsic<[llvm_anyint_ty], [llvm_anyfloat_ty]>;
1050  def int_llrint : DefaultAttrsIntrinsic<[llvm_anyint_ty], [llvm_anyfloat_ty]>;
1051
1052  // TODO: int operand should be constrained to same number of elements as the result.
1053  def int_ldexp : DefaultAttrsIntrinsic<[llvm_anyfloat_ty], [LLVMMatchType<0>,
1054                                                             llvm_anyint_ty]>;
1055
1056  // TODO: Should constrain all element counts to match
1057  def int_frexp : DefaultAttrsIntrinsic<[llvm_anyfloat_ty, llvm_anyint_ty], [LLVMMatchType<0>]>;
1058}
1059
1060def int_minnum : DefaultAttrsIntrinsic<[llvm_anyfloat_ty],
1061  [LLVMMatchType<0>, LLVMMatchType<0>],
1062  [IntrNoMem, IntrSpeculatable, IntrWillReturn, Commutative]
1063>;
1064def int_maxnum : DefaultAttrsIntrinsic<[llvm_anyfloat_ty],
1065  [LLVMMatchType<0>, LLVMMatchType<0>],
1066  [IntrNoMem, IntrSpeculatable, IntrWillReturn, Commutative]
1067>;
1068def int_minimum : DefaultAttrsIntrinsic<[llvm_anyfloat_ty],
1069  [LLVMMatchType<0>, LLVMMatchType<0>],
1070  [IntrNoMem, IntrSpeculatable, IntrWillReturn, Commutative]
1071>;
1072def int_maximum : DefaultAttrsIntrinsic<[llvm_anyfloat_ty],
1073  [LLVMMatchType<0>, LLVMMatchType<0>],
1074  [IntrNoMem, IntrSpeculatable, IntrWillReturn, Commutative]
1075>;
1076
1077// Internal interface for object size checking
1078def int_objectsize : DefaultAttrsIntrinsic<[llvm_anyint_ty],
1079                               [llvm_anyptr_ty, llvm_i1_ty,
1080                                llvm_i1_ty, llvm_i1_ty],
1081                               [IntrNoMem, IntrSpeculatable, IntrWillReturn,
1082                                ImmArg<ArgIndex<1>>, ImmArg<ArgIndex<2>>,
1083                                ImmArg<ArgIndex<3>>]>,
1084                               ClangBuiltin<"__builtin_object_size">;
1085
1086//===--------------- Access to Floating Point Environment -----------------===//
1087//
1088
1089let IntrProperties = [IntrInaccessibleMemOnly, IntrWillReturn] in {
1090  def int_get_rounding  : DefaultAttrsIntrinsic<[llvm_i32_ty], []>;
1091  def int_set_rounding  : DefaultAttrsIntrinsic<[], [llvm_i32_ty]>;
1092  def int_get_fpenv     : DefaultAttrsIntrinsic<[llvm_anyint_ty], []>;
1093  def int_set_fpenv     : DefaultAttrsIntrinsic<[], [llvm_anyint_ty]>;
1094  def int_reset_fpenv   : DefaultAttrsIntrinsic<[], []>;
1095  def int_get_fpmode    : DefaultAttrsIntrinsic<[llvm_anyint_ty], []>;
1096  def int_set_fpmode    : DefaultAttrsIntrinsic<[], [llvm_anyint_ty]>;
1097  def int_reset_fpmode  : DefaultAttrsIntrinsic<[], []>;
1098}
1099
1100//===--------------- Floating Point Properties ----------------------------===//
1101//
1102
1103def int_is_fpclass
1104    : DefaultAttrsIntrinsic<[LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>],
1105                            [llvm_anyfloat_ty, llvm_i32_ty],
1106                            [IntrNoMem, IntrSpeculatable, ImmArg<ArgIndex<1>>]>;
1107
1108//===--------------- Constrained Floating Point Intrinsics ----------------===//
1109//
1110
1111/// IntrStrictFP - The intrinsic is allowed to be used in an alternate
1112/// floating point environment.
1113def IntrStrictFP : IntrinsicProperty;
1114
1115let IntrProperties = [IntrInaccessibleMemOnly, IntrWillReturn, IntrStrictFP] in {
1116  def int_experimental_constrained_fadd : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ],
1117                                                    [ LLVMMatchType<0>,
1118                                                      LLVMMatchType<0>,
1119                                                      llvm_metadata_ty,
1120                                                      llvm_metadata_ty ]>;
1121  def int_experimental_constrained_fsub : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ],
1122                                                    [ LLVMMatchType<0>,
1123                                                      LLVMMatchType<0>,
1124                                                      llvm_metadata_ty,
1125                                                      llvm_metadata_ty ]>;
1126  def int_experimental_constrained_fmul : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ],
1127                                                    [ LLVMMatchType<0>,
1128                                                      LLVMMatchType<0>,
1129                                                      llvm_metadata_ty,
1130                                                      llvm_metadata_ty ]>;
1131  def int_experimental_constrained_fdiv : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ],
1132                                                    [ LLVMMatchType<0>,
1133                                                      LLVMMatchType<0>,
1134                                                      llvm_metadata_ty,
1135                                                      llvm_metadata_ty ]>;
1136  def int_experimental_constrained_frem : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ],
1137                                                    [ LLVMMatchType<0>,
1138                                                      LLVMMatchType<0>,
1139                                                      llvm_metadata_ty,
1140                                                      llvm_metadata_ty ]>;
1141
1142  def int_experimental_constrained_fma : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ],
1143                                                    [ LLVMMatchType<0>,
1144                                                      LLVMMatchType<0>,
1145                                                      LLVMMatchType<0>,
1146                                                      llvm_metadata_ty,
1147                                                      llvm_metadata_ty ]>;
1148
1149  def int_experimental_constrained_fmuladd : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ],
1150                                                       [ LLVMMatchType<0>,
1151                                                         LLVMMatchType<0>,
1152                                                         LLVMMatchType<0>,
1153                                                         llvm_metadata_ty,
1154                                                         llvm_metadata_ty ]>;
1155
1156  def int_experimental_constrained_fptosi : DefaultAttrsIntrinsic<[ llvm_anyint_ty ],
1157                                                    [ llvm_anyfloat_ty,
1158                                                      llvm_metadata_ty ]>;
1159
1160  def int_experimental_constrained_fptoui : DefaultAttrsIntrinsic<[ llvm_anyint_ty ],
1161                                                    [ llvm_anyfloat_ty,
1162                                                      llvm_metadata_ty ]>;
1163
1164  def int_experimental_constrained_sitofp : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ],
1165                                                       [ llvm_anyint_ty,
1166                                                         llvm_metadata_ty,
1167                                                         llvm_metadata_ty ]>;
1168
1169  def int_experimental_constrained_uitofp : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ],
1170                                                       [ llvm_anyint_ty,
1171                                                         llvm_metadata_ty,
1172                                                         llvm_metadata_ty ]>;
1173
1174  def int_experimental_constrained_fptrunc : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ],
1175                                                       [ llvm_anyfloat_ty,
1176                                                         llvm_metadata_ty,
1177                                                         llvm_metadata_ty ]>;
1178
1179  def int_experimental_constrained_fpext : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ],
1180                                                     [ llvm_anyfloat_ty,
1181                                                       llvm_metadata_ty ]>;
1182
1183  // These intrinsics are sensitive to the rounding mode so we need constrained
1184  // versions of each of them.  When strict rounding and exception control are
1185  // not required the non-constrained versions of these intrinsics should be
1186  // used.
1187  def int_experimental_constrained_sqrt : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ],
1188                                                    [ LLVMMatchType<0>,
1189                                                      llvm_metadata_ty,
1190                                                      llvm_metadata_ty ]>;
1191  def int_experimental_constrained_powi : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ],
1192                                                    [ LLVMMatchType<0>,
1193                                                      llvm_i32_ty,
1194                                                      llvm_metadata_ty,
1195                                                      llvm_metadata_ty ]>;
1196  def int_experimental_constrained_ldexp : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ],
1197                                                    [ LLVMMatchType<0>,
1198                                                      llvm_anyint_ty,
1199                                                      llvm_metadata_ty,
1200                                                      llvm_metadata_ty ]>;
1201  def int_experimental_constrained_sin  : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ],
1202                                                    [ LLVMMatchType<0>,
1203                                                      llvm_metadata_ty,
1204                                                      llvm_metadata_ty ]>;
1205  def int_experimental_constrained_cos  : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ],
1206                                                    [ LLVMMatchType<0>,
1207                                                      llvm_metadata_ty,
1208                                                      llvm_metadata_ty ]>;
1209  def int_experimental_constrained_pow  : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ],
1210                                                    [ LLVMMatchType<0>,
1211                                                      LLVMMatchType<0>,
1212                                                      llvm_metadata_ty,
1213                                                      llvm_metadata_ty ]>;
1214  def int_experimental_constrained_log  : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ],
1215                                                    [ LLVMMatchType<0>,
1216                                                      llvm_metadata_ty,
1217                                                      llvm_metadata_ty ]>;
1218  def int_experimental_constrained_log10: DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ],
1219                                                    [ LLVMMatchType<0>,
1220                                                      llvm_metadata_ty,
1221                                                      llvm_metadata_ty ]>;
1222  def int_experimental_constrained_log2 : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ],
1223                                                    [ LLVMMatchType<0>,
1224                                                      llvm_metadata_ty,
1225                                                      llvm_metadata_ty ]>;
1226  def int_experimental_constrained_exp  : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ],
1227                                                    [ LLVMMatchType<0>,
1228                                                      llvm_metadata_ty,
1229                                                      llvm_metadata_ty ]>;
1230  def int_experimental_constrained_exp2 : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ],
1231                                                    [ LLVMMatchType<0>,
1232                                                      llvm_metadata_ty,
1233                                                      llvm_metadata_ty ]>;
1234  def int_experimental_constrained_rint  : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ],
1235                                                     [ LLVMMatchType<0>,
1236                                                       llvm_metadata_ty,
1237                                                       llvm_metadata_ty ]>;
1238  def int_experimental_constrained_nearbyint : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ],
1239                                                         [ LLVMMatchType<0>,
1240                                                           llvm_metadata_ty,
1241                                                           llvm_metadata_ty ]>;
1242  def int_experimental_constrained_lrint : DefaultAttrsIntrinsic<[ llvm_anyint_ty ],
1243                                                     [ llvm_anyfloat_ty,
1244                                                       llvm_metadata_ty,
1245                                                       llvm_metadata_ty ]>;
1246  def int_experimental_constrained_llrint : DefaultAttrsIntrinsic<[ llvm_anyint_ty ],
1247                                                      [ llvm_anyfloat_ty,
1248                                                        llvm_metadata_ty,
1249                                                        llvm_metadata_ty ]>;
1250  def int_experimental_constrained_maxnum : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ],
1251                                                      [ LLVMMatchType<0>,
1252                                                        LLVMMatchType<0>,
1253                                                        llvm_metadata_ty ]>;
1254  def int_experimental_constrained_minnum : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ],
1255                                                      [ LLVMMatchType<0>,
1256                                                        LLVMMatchType<0>,
1257                                                        llvm_metadata_ty ]>;
1258  def int_experimental_constrained_maximum : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ],
1259                                                       [ LLVMMatchType<0>,
1260                                                         LLVMMatchType<0>,
1261                                                         llvm_metadata_ty ]>;
1262  def int_experimental_constrained_minimum : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ],
1263                                                       [ LLVMMatchType<0>,
1264                                                         LLVMMatchType<0>,
1265                                                         llvm_metadata_ty ]>;
1266  def int_experimental_constrained_ceil : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ],
1267                                                    [ LLVMMatchType<0>,
1268                                                      llvm_metadata_ty ]>;
1269  def int_experimental_constrained_floor : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ],
1270                                                     [ LLVMMatchType<0>,
1271                                                       llvm_metadata_ty ]>;
1272  def int_experimental_constrained_lround : DefaultAttrsIntrinsic<[ llvm_anyint_ty ],
1273                                                      [ llvm_anyfloat_ty,
1274                                                        llvm_metadata_ty ]>;
1275  def int_experimental_constrained_llround : DefaultAttrsIntrinsic<[ llvm_anyint_ty ],
1276                                                       [ llvm_anyfloat_ty,
1277                                                         llvm_metadata_ty ]>;
1278  def int_experimental_constrained_round : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ],
1279                                                     [ LLVMMatchType<0>,
1280                                                      llvm_metadata_ty ]>;
1281  def int_experimental_constrained_roundeven : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ],
1282                                                         [ LLVMMatchType<0>,
1283                                                           llvm_metadata_ty ]>;
1284  def int_experimental_constrained_trunc : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ],
1285                                                     [ LLVMMatchType<0>,
1286                                                       llvm_metadata_ty ]>;
1287
1288  // Constrained floating-point comparison (quiet and signaling variants).
1289  // Third operand is the predicate represented as a metadata string.
1290  def int_experimental_constrained_fcmp
1291      : DefaultAttrsIntrinsic<[ LLVMScalarOrSameVectorWidth<0, llvm_i1_ty> ],
1292                  [ llvm_anyfloat_ty, LLVMMatchType<0>,
1293                    llvm_metadata_ty, llvm_metadata_ty ]>;
1294  def int_experimental_constrained_fcmps
1295      : DefaultAttrsIntrinsic<[ LLVMScalarOrSameVectorWidth<0, llvm_i1_ty> ],
1296                  [ llvm_anyfloat_ty, LLVMMatchType<0>,
1297                    llvm_metadata_ty, llvm_metadata_ty ]>;
1298}
1299// FIXME: Consider maybe adding intrinsics for sitofp, uitofp.
1300
1301
1302//===------------------------- Expect Intrinsics --------------------------===//
1303//
1304def int_expect : DefaultAttrsIntrinsic<[llvm_anyint_ty],
1305  [LLVMMatchType<0>, LLVMMatchType<0>], [IntrNoMem, IntrWillReturn]>;
1306
1307def int_expect_with_probability : DefaultAttrsIntrinsic<[llvm_anyint_ty],
1308  [LLVMMatchType<0>, LLVMMatchType<0>, llvm_double_ty],
1309  [IntrNoMem, IntrWillReturn, ImmArg<ArgIndex<2>>]>;
1310
1311//===-------------------- Bit Manipulation Intrinsics ---------------------===//
1312//
1313
1314// None of these intrinsics accesses memory at all.
1315let IntrProperties = [IntrNoMem, IntrSpeculatable, IntrWillReturn] in {
1316  def int_bswap: DefaultAttrsIntrinsic<[llvm_anyint_ty], [LLVMMatchType<0>]>;
1317  def int_ctpop: DefaultAttrsIntrinsic<[llvm_anyint_ty], [LLVMMatchType<0>]>;
1318  def int_bitreverse : DefaultAttrsIntrinsic<[llvm_anyint_ty], [LLVMMatchType<0>]>;
1319  def int_fshl : DefaultAttrsIntrinsic<[llvm_anyint_ty],
1320      [LLVMMatchType<0>, LLVMMatchType<0>, LLVMMatchType<0>]>;
1321  def int_fshr : DefaultAttrsIntrinsic<[llvm_anyint_ty],
1322      [LLVMMatchType<0>, LLVMMatchType<0>, LLVMMatchType<0>]>;
1323}
1324
1325let IntrProperties = [IntrNoMem, IntrSpeculatable, IntrWillReturn,
1326                      ImmArg<ArgIndex<1>>] in {
1327  def int_ctlz : DefaultAttrsIntrinsic<[llvm_anyint_ty], [LLVMMatchType<0>, llvm_i1_ty]>;
1328  def int_cttz : DefaultAttrsIntrinsic<[llvm_anyint_ty], [LLVMMatchType<0>, llvm_i1_ty]>;
1329}
1330
1331//===------------------------ Debugger Intrinsics -------------------------===//
1332//
1333
1334// None of these intrinsics accesses memory at all...but that doesn't
1335// mean the optimizers can change them aggressively.  Special handling
1336// needed in a few places. These synthetic intrinsics have no
1337// side-effects and just mark information about their operands.
1338let IntrProperties = [IntrNoMem, IntrSpeculatable, IntrWillReturn] in {
1339  def int_dbg_declare      : DefaultAttrsIntrinsic<[],
1340                                       [llvm_metadata_ty,
1341                                        llvm_metadata_ty,
1342                                        llvm_metadata_ty]>;
1343  def int_dbg_value        : DefaultAttrsIntrinsic<[],
1344                                       [llvm_metadata_ty,
1345                                        llvm_metadata_ty,
1346                                        llvm_metadata_ty]>;
1347  def int_dbg_assign        : DefaultAttrsIntrinsic<[],
1348                                       [llvm_metadata_ty,
1349                                        llvm_metadata_ty,
1350                                        llvm_metadata_ty,
1351                                        llvm_metadata_ty,
1352                                        llvm_metadata_ty,
1353                                        llvm_metadata_ty]>;
1354  def int_dbg_label        : DefaultAttrsIntrinsic<[],
1355                                       [llvm_metadata_ty]>;
1356}
1357
1358//===------------------ Exception Handling Intrinsics----------------------===//
1359//
1360
1361// The result of eh.typeid.for depends on the enclosing function, but inside a
1362// given function it is 'const' and may be CSE'd etc.
1363def int_eh_typeid_for : Intrinsic<[llvm_i32_ty], [llvm_ptr_ty], [IntrNoMem]>;
1364
1365def int_eh_return_i32 : Intrinsic<[], [llvm_i32_ty, llvm_ptr_ty]>;
1366def int_eh_return_i64 : Intrinsic<[], [llvm_i64_ty, llvm_ptr_ty]>;
1367
1368// eh.exceptionpointer returns the pointer to the exception caught by
1369// the given `catchpad`.
1370def int_eh_exceptionpointer : Intrinsic<[llvm_anyptr_ty], [llvm_token_ty],
1371                                        [IntrNoMem]>;
1372
1373// Gets the exception code from a catchpad token. Only used on some platforms.
1374def int_eh_exceptioncode : Intrinsic<[llvm_i32_ty], [llvm_token_ty], [IntrNoMem]>;
1375
1376// __builtin_unwind_init is an undocumented GCC intrinsic that causes all
1377// callee-saved registers to be saved and restored (regardless of whether they
1378// are used) in the calling function. It is used by libgcc_eh.
1379def int_eh_unwind_init: Intrinsic<[]>,
1380                        ClangBuiltin<"__builtin_unwind_init">;
1381
1382def int_eh_dwarf_cfa  : Intrinsic<[llvm_ptr_ty], [llvm_i32_ty]>;
1383
1384def int_eh_sjlj_lsda             : Intrinsic<[llvm_ptr_ty], [], [IntrNoMem]>;
1385def int_eh_sjlj_callsite         : Intrinsic<[], [llvm_i32_ty], [IntrNoMem, ImmArg<ArgIndex<0>>]>;
1386
1387def int_eh_sjlj_functioncontext : Intrinsic<[], [llvm_ptr_ty]>;
1388def int_eh_sjlj_setjmp          : Intrinsic<[llvm_i32_ty], [llvm_ptr_ty]>;
1389def int_eh_sjlj_longjmp         : Intrinsic<[], [llvm_ptr_ty], [IntrNoReturn]>;
1390def int_eh_sjlj_setup_dispatch  : Intrinsic<[], []>;
1391
1392//===---------------- Generic Variable Attribute Intrinsics----------------===//
1393//
1394def int_var_annotation : DefaultAttrsIntrinsic<
1395    [], [llvm_anyptr_ty, llvm_anyptr_ty, LLVMMatchType<1>, llvm_i32_ty, LLVMMatchType<1>],
1396    [IntrInaccessibleMemOnly], "llvm.var.annotation">;
1397
1398def int_ptr_annotation : DefaultAttrsIntrinsic<
1399    [llvm_anyptr_ty],
1400    [LLVMMatchType<0>, llvm_anyptr_ty, LLVMMatchType<1>, llvm_i32_ty, LLVMMatchType<1>],
1401    [IntrInaccessibleMemOnly], "llvm.ptr.annotation">;
1402
1403def int_annotation : DefaultAttrsIntrinsic<
1404    [llvm_anyint_ty],
1405    [LLVMMatchType<0>, llvm_anyptr_ty, LLVMMatchType<1>, llvm_i32_ty],
1406    [IntrInaccessibleMemOnly], "llvm.annotation">;
1407
1408// Annotates the current program point with metadata strings which are emitted
1409// as CodeView debug info records. This is expensive, as it disables inlining
1410// and is modelled as having side effects.
1411def int_codeview_annotation : DefaultAttrsIntrinsic<[], [llvm_metadata_ty],
1412                                        [IntrInaccessibleMemOnly, IntrNoDuplicate, IntrWillReturn],
1413                                        "llvm.codeview.annotation">;
1414
1415//===------------------------ Trampoline Intrinsics -----------------------===//
1416//
1417def int_init_trampoline : DefaultAttrsIntrinsic<
1418    [], [llvm_ptr_ty, llvm_ptr_ty, llvm_ptr_ty],
1419    [IntrArgMemOnly, NoCapture<ArgIndex<0>>, WriteOnly<ArgIndex<0>>,
1420     ReadNone<ArgIndex<1>>, ReadNone<ArgIndex<2>>]>,
1421    ClangBuiltin<"__builtin_init_trampoline">;
1422
1423def int_adjust_trampoline : DefaultAttrsIntrinsic<
1424    [llvm_ptr_ty], [llvm_ptr_ty], [IntrReadMem, IntrArgMemOnly]>,
1425    ClangBuiltin<"__builtin_adjust_trampoline">;
1426
1427//===------------------------ Overflow Intrinsics -------------------------===//
1428//
1429
1430// Expose the carry flag from add operations on two integrals.
1431let IntrProperties = [IntrNoMem, IntrSpeculatable, IntrWillReturn] in {
1432  def int_sadd_with_overflow : DefaultAttrsIntrinsic<[llvm_anyint_ty,
1433                                          LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>],
1434                                         [LLVMMatchType<0>, LLVMMatchType<0>]>;
1435  def int_uadd_with_overflow : DefaultAttrsIntrinsic<[llvm_anyint_ty,
1436                                          LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>],
1437                                         [LLVMMatchType<0>, LLVMMatchType<0>]>;
1438
1439  def int_ssub_with_overflow : DefaultAttrsIntrinsic<[llvm_anyint_ty,
1440                                          LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>],
1441                                         [LLVMMatchType<0>, LLVMMatchType<0>]>;
1442  def int_usub_with_overflow : DefaultAttrsIntrinsic<[llvm_anyint_ty,
1443                                          LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>],
1444                                         [LLVMMatchType<0>, LLVMMatchType<0>]>;
1445
1446  def int_smul_with_overflow : DefaultAttrsIntrinsic<[llvm_anyint_ty,
1447                                          LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>],
1448                                         [LLVMMatchType<0>, LLVMMatchType<0>]>;
1449  def int_umul_with_overflow : DefaultAttrsIntrinsic<[llvm_anyint_ty,
1450                                          LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>],
1451                                         [LLVMMatchType<0>, LLVMMatchType<0>]>;
1452}
1453//===------------------------- Saturation Arithmetic Intrinsics ---------------------===//
1454//
1455def int_sadd_sat : DefaultAttrsIntrinsic<[llvm_anyint_ty],
1456                             [LLVMMatchType<0>, LLVMMatchType<0>],
1457                             [IntrNoMem, IntrSpeculatable, IntrWillReturn, Commutative]>;
1458def int_uadd_sat : DefaultAttrsIntrinsic<[llvm_anyint_ty],
1459                             [LLVMMatchType<0>, LLVMMatchType<0>],
1460                             [IntrNoMem, IntrSpeculatable, IntrWillReturn, Commutative]>;
1461def int_ssub_sat : DefaultAttrsIntrinsic<[llvm_anyint_ty],
1462                             [LLVMMatchType<0>, LLVMMatchType<0>],
1463                             [IntrNoMem, IntrSpeculatable, IntrWillReturn]>;
1464def int_usub_sat : DefaultAttrsIntrinsic<[llvm_anyint_ty],
1465                             [LLVMMatchType<0>, LLVMMatchType<0>],
1466                             [IntrNoMem, IntrSpeculatable, IntrWillReturn]>;
1467def int_sshl_sat : DefaultAttrsIntrinsic<[llvm_anyint_ty],
1468                             [LLVMMatchType<0>, LLVMMatchType<0>],
1469                             [IntrNoMem, IntrSpeculatable, IntrWillReturn]>;
1470def int_ushl_sat : DefaultAttrsIntrinsic<[llvm_anyint_ty],
1471                             [LLVMMatchType<0>, LLVMMatchType<0>],
1472                             [IntrNoMem, IntrSpeculatable, IntrWillReturn]>;
1473
1474//===------------------------- Fixed Point Arithmetic Intrinsics ---------------------===//
1475//
1476def int_smul_fix : DefaultAttrsIntrinsic<[llvm_anyint_ty],
1477                             [LLVMMatchType<0>, LLVMMatchType<0>, llvm_i32_ty],
1478                             [IntrNoMem, IntrSpeculatable, IntrWillReturn,
1479                              Commutative, ImmArg<ArgIndex<2>>]>;
1480
1481def int_umul_fix : DefaultAttrsIntrinsic<[llvm_anyint_ty],
1482                             [LLVMMatchType<0>, LLVMMatchType<0>, llvm_i32_ty],
1483                             [IntrNoMem, IntrSpeculatable, IntrWillReturn,
1484                              Commutative, ImmArg<ArgIndex<2>>]>;
1485
1486def int_sdiv_fix : DefaultAttrsIntrinsic<[llvm_anyint_ty],
1487                             [LLVMMatchType<0>, LLVMMatchType<0>, llvm_i32_ty],
1488                             [IntrNoMem, ImmArg<ArgIndex<2>>]>;
1489
1490def int_udiv_fix : DefaultAttrsIntrinsic<[llvm_anyint_ty],
1491                             [LLVMMatchType<0>, LLVMMatchType<0>, llvm_i32_ty],
1492                             [IntrNoMem, ImmArg<ArgIndex<2>>]>;
1493
1494//===------------------- Fixed Point Saturation Arithmetic Intrinsics ----------------===//
1495//
1496def int_smul_fix_sat : DefaultAttrsIntrinsic<[llvm_anyint_ty],
1497                                 [LLVMMatchType<0>, LLVMMatchType<0>, llvm_i32_ty],
1498                                 [IntrNoMem, IntrSpeculatable, IntrWillReturn,
1499                                  Commutative, ImmArg<ArgIndex<2>>]>;
1500def int_umul_fix_sat : DefaultAttrsIntrinsic<[llvm_anyint_ty],
1501                                 [LLVMMatchType<0>, LLVMMatchType<0>, llvm_i32_ty],
1502                                 [IntrNoMem, IntrSpeculatable, IntrWillReturn,
1503                                  Commutative, ImmArg<ArgIndex<2>>]>;
1504
1505def int_sdiv_fix_sat : DefaultAttrsIntrinsic<[llvm_anyint_ty],
1506                                 [LLVMMatchType<0>, LLVMMatchType<0>, llvm_i32_ty],
1507                                 [IntrNoMem, ImmArg<ArgIndex<2>>]>;
1508
1509def int_udiv_fix_sat : DefaultAttrsIntrinsic<[llvm_anyint_ty],
1510                                 [LLVMMatchType<0>, LLVMMatchType<0>, llvm_i32_ty],
1511                                 [IntrNoMem, ImmArg<ArgIndex<2>>]>;
1512
1513//===------------------ Integer Min/Max/Abs Intrinsics --------------------===//
1514//
1515def int_abs : DefaultAttrsIntrinsic<
1516    [llvm_anyint_ty], [LLVMMatchType<0>, llvm_i1_ty],
1517    [IntrNoMem, IntrSpeculatable, IntrWillReturn, ImmArg<ArgIndex<1>>]>;
1518
1519def int_smax : DefaultAttrsIntrinsic<
1520    [llvm_anyint_ty], [LLVMMatchType<0>, LLVMMatchType<0>],
1521    [IntrNoMem, IntrSpeculatable, IntrWillReturn]>;
1522def int_smin : DefaultAttrsIntrinsic<
1523    [llvm_anyint_ty], [LLVMMatchType<0>, LLVMMatchType<0>],
1524    [IntrNoMem, IntrSpeculatable, IntrWillReturn]>;
1525def int_umax : DefaultAttrsIntrinsic<
1526    [llvm_anyint_ty], [LLVMMatchType<0>, LLVMMatchType<0>],
1527    [IntrNoMem, IntrSpeculatable, IntrWillReturn]>;
1528def int_umin : DefaultAttrsIntrinsic<
1529    [llvm_anyint_ty], [LLVMMatchType<0>, LLVMMatchType<0>],
1530    [IntrNoMem, IntrSpeculatable, IntrWillReturn]>;
1531
1532//===------------------------- Memory Use Markers -------------------------===//
1533//
1534def int_lifetime_start  : DefaultAttrsIntrinsic<[],
1535                                    [llvm_i64_ty, llvm_anyptr_ty],
1536                                    [IntrArgMemOnly, IntrWillReturn,
1537                                     NoCapture<ArgIndex<1>>,
1538                                     ImmArg<ArgIndex<0>>]>;
1539def int_lifetime_end    : DefaultAttrsIntrinsic<[],
1540                                    [llvm_i64_ty, llvm_anyptr_ty],
1541                                    [IntrArgMemOnly, IntrWillReturn,
1542                                     NoCapture<ArgIndex<1>>,
1543                                     ImmArg<ArgIndex<0>>]>;
1544def int_invariant_start : DefaultAttrsIntrinsic<[llvm_ptr_ty],
1545                                    [llvm_i64_ty, llvm_anyptr_ty],
1546                                    [IntrArgMemOnly, IntrWillReturn,
1547                                     NoCapture<ArgIndex<1>>,
1548                                     ImmArg<ArgIndex<0>>]>;
1549def int_invariant_end   : DefaultAttrsIntrinsic<[],
1550                                    [llvm_ptr_ty, llvm_i64_ty,
1551                                     llvm_anyptr_ty],
1552                                    [IntrArgMemOnly, IntrWillReturn,
1553                                     NoCapture<ArgIndex<2>>,
1554                                     ImmArg<ArgIndex<1>>]>;
1555
1556// launder.invariant.group can't be marked with 'readnone' (IntrNoMem),
1557// because it would cause CSE of two barriers with the same argument.
1558// Inaccessiblememonly says that the barrier doesn't read the argument,
1559// but it changes state not accessible to this module. This way
1560// we can DSE through the barrier because it doesn't read the value
1561// after store. Although the barrier doesn't modify any memory it
1562// can't be marked as readonly, because it would be possible to
1563// CSE 2 barriers with store in between.
1564// The argument also can't be marked with 'returned' attribute, because
1565// it would remove barrier.
1566// Note that it is still experimental, which means that its semantics
1567// might change in the future.
1568def int_launder_invariant_group : DefaultAttrsIntrinsic<[llvm_anyptr_ty],
1569                                            [LLVMMatchType<0>],
1570                                            [IntrInaccessibleMemOnly, IntrSpeculatable, IntrWillReturn]>;
1571
1572
1573def int_strip_invariant_group : DefaultAttrsIntrinsic<[llvm_anyptr_ty],
1574                                          [LLVMMatchType<0>],
1575                                          [IntrSpeculatable, IntrNoMem, IntrWillReturn]>;
1576
1577//===------------------------ Stackmap Intrinsics -------------------------===//
1578//
1579def int_experimental_stackmap : DefaultAttrsIntrinsic<[],
1580                                  [llvm_i64_ty, llvm_i32_ty, llvm_vararg_ty],
1581                                  [Throws]>;
1582def int_experimental_patchpoint_void : Intrinsic<[],
1583                                                 [llvm_i64_ty, llvm_i32_ty,
1584                                                  llvm_ptr_ty, llvm_i32_ty,
1585                                                  llvm_vararg_ty],
1586                                                  [Throws]>;
1587def int_experimental_patchpoint_i64 : Intrinsic<[llvm_i64_ty],
1588                                                [llvm_i64_ty, llvm_i32_ty,
1589                                                 llvm_ptr_ty, llvm_i32_ty,
1590                                                 llvm_vararg_ty],
1591                                                 [Throws]>;
1592
1593
1594//===------------------------ Garbage Collection Intrinsics ---------------===//
1595// These are documented in docs/Statepoint.rst
1596
1597def int_experimental_gc_statepoint : Intrinsic<[llvm_token_ty],
1598                               [llvm_i64_ty, llvm_i32_ty,
1599                                llvm_anyptr_ty, llvm_i32_ty,
1600                                llvm_i32_ty, llvm_vararg_ty],
1601                               [Throws, ImmArg<ArgIndex<0>>,
1602                                ImmArg<ArgIndex<1>>, ImmArg<ArgIndex<3>>,
1603                                ImmArg<ArgIndex<4>>]>;
1604
1605def int_experimental_gc_result : DefaultAttrsIntrinsic<
1606    [llvm_any_ty], [llvm_token_ty], [IntrNoMem]>;
1607
1608def int_experimental_gc_relocate : DefaultAttrsIntrinsic<
1609    [llvm_any_ty], [llvm_token_ty, llvm_i32_ty, llvm_i32_ty],
1610    [IntrNoMem, ImmArg<ArgIndex<1>>, ImmArg<ArgIndex<2>>]>;
1611
1612def int_experimental_gc_get_pointer_base : DefaultAttrsIntrinsic<
1613    [llvm_anyptr_ty], [llvm_anyptr_ty],
1614    [IntrNoMem, IntrWillReturn, ReadNone<ArgIndex<0>>, NoCapture<ArgIndex<0>>]>;
1615
1616def int_experimental_gc_get_pointer_offset : DefaultAttrsIntrinsic<
1617    [llvm_i64_ty], [llvm_anyptr_ty],
1618    [IntrNoMem, IntrWillReturn, ReadNone<ArgIndex<0>>, NoCapture<ArgIndex<0>>]>;
1619
1620//===------------------------ Coroutine Intrinsics ---------------===//
1621// These are documented in docs/Coroutines.rst
1622
1623// Coroutine Structure Intrinsics.
1624
1625def int_coro_id : DefaultAttrsIntrinsic<[llvm_token_ty],
1626    [llvm_i32_ty, llvm_ptr_ty, llvm_ptr_ty, llvm_ptr_ty],
1627    [IntrArgMemOnly, IntrReadMem, ReadNone<ArgIndex<1>>, ReadOnly<ArgIndex<2>>,
1628     NoCapture<ArgIndex<2>>]>;
1629def int_coro_id_retcon : Intrinsic<[llvm_token_ty],
1630    [llvm_i32_ty, llvm_i32_ty, llvm_ptr_ty,
1631     llvm_ptr_ty, llvm_ptr_ty, llvm_ptr_ty],
1632    []>;
1633def int_coro_id_retcon_once : Intrinsic<[llvm_token_ty],
1634    [llvm_i32_ty, llvm_i32_ty, llvm_ptr_ty,
1635     llvm_ptr_ty, llvm_ptr_ty, llvm_ptr_ty],
1636    []>;
1637def int_coro_alloc : Intrinsic<[llvm_i1_ty], [llvm_token_ty], []>;
1638def int_coro_id_async : Intrinsic<[llvm_token_ty],
1639  [llvm_i32_ty, llvm_i32_ty, llvm_i32_ty, llvm_ptr_ty],
1640  []>;
1641def int_coro_async_context_alloc : Intrinsic<[llvm_ptr_ty],
1642    [llvm_ptr_ty, llvm_ptr_ty],
1643    []>;
1644def int_coro_async_context_dealloc : Intrinsic<[],
1645    [llvm_ptr_ty],
1646    []>;
1647def int_coro_async_resume : Intrinsic<[llvm_ptr_ty],
1648    [],
1649    [IntrNoMerge]>;
1650def int_coro_async_size_replace : Intrinsic<[], [llvm_ptr_ty, llvm_ptr_ty], []>;
1651def int_coro_suspend_async
1652    : Intrinsic<[llvm_any_ty],
1653                [llvm_i32_ty, llvm_ptr_ty, llvm_ptr_ty, llvm_vararg_ty],
1654                [IntrNoMerge]>;
1655def int_coro_prepare_async : Intrinsic<[llvm_ptr_ty], [llvm_ptr_ty],
1656                                       [IntrNoMem]>;
1657def int_coro_begin : Intrinsic<[llvm_ptr_ty], [llvm_token_ty, llvm_ptr_ty],
1658                               [WriteOnly<ArgIndex<1>>]>;
1659
1660def int_coro_free : Intrinsic<[llvm_ptr_ty], [llvm_token_ty, llvm_ptr_ty],
1661                              [IntrReadMem, IntrArgMemOnly,
1662                               ReadOnly<ArgIndex<1>>,
1663                               NoCapture<ArgIndex<1>>]>;
1664def int_coro_end : Intrinsic<[llvm_i1_ty], [llvm_ptr_ty, llvm_i1_ty, llvm_token_ty], []>;
1665def int_coro_end_results : Intrinsic<[llvm_token_ty], [llvm_vararg_ty]>;
1666def int_coro_end_async
1667    : Intrinsic<[llvm_i1_ty], [llvm_ptr_ty, llvm_i1_ty, llvm_vararg_ty], []>;
1668
1669def int_coro_frame : Intrinsic<[llvm_ptr_ty], [], [IntrNoMem]>;
1670def int_coro_noop : Intrinsic<[llvm_ptr_ty], [], [IntrNoMem]>;
1671def int_coro_size : Intrinsic<[llvm_anyint_ty], [], [IntrNoMem]>;
1672def int_coro_align : Intrinsic<[llvm_anyint_ty], [], [IntrNoMem]>;
1673
1674def int_coro_save : Intrinsic<[llvm_token_ty], [llvm_ptr_ty], [IntrNoMerge]>;
1675def int_coro_suspend : Intrinsic<[llvm_i8_ty], [llvm_token_ty, llvm_i1_ty], []>;
1676def int_coro_suspend_retcon : Intrinsic<[llvm_any_ty], [llvm_vararg_ty], []>;
1677def int_coro_prepare_retcon : Intrinsic<[llvm_ptr_ty], [llvm_ptr_ty],
1678                                        [IntrNoMem]>;
1679def int_coro_alloca_alloc : Intrinsic<[llvm_token_ty],
1680                                      [llvm_anyint_ty, llvm_i32_ty], []>;
1681def int_coro_alloca_get : Intrinsic<[llvm_ptr_ty], [llvm_token_ty], []>;
1682def int_coro_alloca_free : Intrinsic<[], [llvm_token_ty], []>;
1683
1684// Coroutine Manipulation Intrinsics.
1685
1686def int_coro_resume : Intrinsic<[], [llvm_ptr_ty], [Throws]>;
1687def int_coro_destroy : Intrinsic<[], [llvm_ptr_ty], [Throws]>;
1688def int_coro_done : Intrinsic<[llvm_i1_ty], [llvm_ptr_ty],
1689                              [IntrArgMemOnly, ReadOnly<ArgIndex<0>>,
1690                               NoCapture<ArgIndex<0>>]>;
1691def int_coro_promise : Intrinsic<[llvm_ptr_ty],
1692                                 [llvm_ptr_ty, llvm_i32_ty, llvm_i1_ty],
1693                                 [IntrNoMem, NoCapture<ArgIndex<0>>]>;
1694
1695def int_coro_await_suspend_void : Intrinsic<[],
1696                                       [llvm_ptr_ty, llvm_ptr_ty, llvm_ptr_ty],
1697                                       [Throws]>;
1698
1699def int_coro_await_suspend_bool : Intrinsic<[llvm_i1_ty],
1700                                            [llvm_ptr_ty, llvm_ptr_ty, llvm_ptr_ty],
1701                                            [Throws]>;
1702
1703def int_coro_await_suspend_handle : Intrinsic<[llvm_ptr_ty],
1704                                              [llvm_ptr_ty, llvm_ptr_ty, llvm_ptr_ty],
1705                                              [Throws]>;
1706
1707// Coroutine Lowering Intrinsics. Used internally by coroutine passes.
1708
1709def int_coro_subfn_addr : DefaultAttrsIntrinsic<
1710    [llvm_ptr_ty], [llvm_ptr_ty, llvm_i8_ty],
1711    [IntrReadMem, IntrArgMemOnly, ReadOnly<ArgIndex<0>>,
1712     NoCapture<ArgIndex<0>>]>;
1713
1714///===-------------------------- Other Intrinsics --------------------------===//
1715//
1716// TODO: We should introduce a new memory kind fo traps (and other side effects
1717//       we only model to keep things alive).
1718def int_trap : Intrinsic<[], [], [IntrNoReturn, IntrCold, IntrInaccessibleMemOnly,
1719               IntrWriteMem]>, ClangBuiltin<"__builtin_trap">;
1720def int_debugtrap : Intrinsic<[]>,
1721                    ClangBuiltin<"__builtin_debugtrap">;
1722def int_ubsantrap : Intrinsic<[], [llvm_i8_ty],
1723                              [IntrNoReturn, IntrCold, ImmArg<ArgIndex<0>>]>;
1724
1725// Support for dynamic deoptimization (or de-specialization)
1726def int_experimental_deoptimize : Intrinsic<[llvm_any_ty], [llvm_vararg_ty],
1727                                            [Throws]>;
1728
1729// Support for speculative runtime guards
1730def int_experimental_guard : Intrinsic<[], [llvm_i1_ty, llvm_vararg_ty],
1731                                       [Throws]>;
1732
1733// Supports widenable conditions for guards represented as explicit branches.
1734def int_experimental_widenable_condition : DefaultAttrsIntrinsic<[llvm_i1_ty], [],
1735        [IntrInaccessibleMemOnly, IntrWillReturn, IntrSpeculatable, NoUndef<RetIndex>]>;
1736
1737// NOP: calls/invokes to this intrinsic are removed by codegen
1738def int_donothing : DefaultAttrsIntrinsic<[], [], [IntrNoMem, IntrWillReturn]>;
1739
1740// This instruction has no actual effect, though it is treated by the optimizer
1741// has having opaque side effects. This may be inserted into loops to ensure
1742// that they are not removed even if they turn out to be empty, for languages
1743// which specify that infinite loops must be preserved.
1744def int_sideeffect : DefaultAttrsIntrinsic<[], [], [IntrInaccessibleMemOnly, IntrWillReturn]>;
1745
1746// The pseudoprobe intrinsic works as a place holder to the block it probes.
1747// Like the sideeffect intrinsic defined above, this intrinsic is treated by the
1748// optimizer as having opaque side effects so that it won't be get rid of or moved
1749// out of the block it probes.
1750def int_pseudoprobe : DefaultAttrsIntrinsic<[], [llvm_i64_ty, llvm_i64_ty, llvm_i32_ty, llvm_i64_ty],
1751                                    [IntrInaccessibleMemOnly, IntrWillReturn]>;
1752
1753// Intrinsics to support half precision floating point format
1754let IntrProperties = [IntrNoMem, IntrWillReturn] in {
1755def int_convert_to_fp16   : DefaultAttrsIntrinsic<[llvm_i16_ty], [llvm_anyfloat_ty]>;
1756def int_convert_from_fp16 : DefaultAttrsIntrinsic<[llvm_anyfloat_ty], [llvm_i16_ty]>;
1757}
1758
1759// Saturating floating point to integer intrinsics
1760let IntrProperties = [IntrNoMem, IntrSpeculatable, IntrWillReturn] in {
1761def int_fptoui_sat : DefaultAttrsIntrinsic<[llvm_anyint_ty], [llvm_anyfloat_ty]>;
1762def int_fptosi_sat : DefaultAttrsIntrinsic<[llvm_anyint_ty], [llvm_anyfloat_ty]>;
1763}
1764
1765// Clear cache intrinsic, default to ignore (ie. emit nothing)
1766// maps to void __clear_cache() on supporting platforms
1767def int_clear_cache : Intrinsic<[], [llvm_ptr_ty, llvm_ptr_ty],
1768                                [], "llvm.clear_cache">;
1769
1770// Intrinsic to detect whether its argument is a constant.
1771def int_is_constant : DefaultAttrsIntrinsic<[llvm_i1_ty], [llvm_any_ty],
1772                                [IntrNoMem, IntrWillReturn, IntrConvergent],
1773                                "llvm.is.constant">;
1774
1775// Intrinsic to mask out bits of a pointer.
1776// First argument must be pointer or vector of pointer. This is checked by the
1777// verifier.
1778def int_ptrmask: DefaultAttrsIntrinsic<[llvm_any_ty], [LLVMMatchType<0>, llvm_anyint_ty],
1779                           [IntrNoMem, IntrSpeculatable, IntrWillReturn]>;
1780
1781// Intrinsic to wrap a thread local variable.
1782def int_threadlocal_address : DefaultAttrsIntrinsic<[llvm_anyptr_ty], [LLVMMatchType<0>],
1783                                                    [NonNull<RetIndex>, NonNull<ArgIndex<0>>,
1784                                                     IntrNoMem, IntrSpeculatable, IntrWillReturn]>;
1785
1786def int_experimental_stepvector : DefaultAttrsIntrinsic<[llvm_anyvector_ty],
1787                                                        [], [IntrNoMem]>;
1788
1789//===---------------- Vector Predication Intrinsics --------------===//
1790// Memory Intrinsics
1791def int_vp_store : DefaultAttrsIntrinsic<[],
1792                             [ llvm_anyvector_ty,
1793                               llvm_anyptr_ty,
1794                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
1795                               llvm_i32_ty],
1796                             [ NoCapture<ArgIndex<1>>, IntrNoSync, IntrWriteMem, IntrArgMemOnly, IntrWillReturn ]>;
1797
1798def int_vp_load  : DefaultAttrsIntrinsic<[ llvm_anyvector_ty],
1799                             [ llvm_anyptr_ty,
1800                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
1801                               llvm_i32_ty],
1802                             [ NoCapture<ArgIndex<0>>, IntrNoSync, IntrReadMem, IntrWillReturn, IntrArgMemOnly ]>;
1803
1804def int_vp_gather: DefaultAttrsIntrinsic<[ llvm_anyvector_ty],
1805                             [ LLVMVectorOfAnyPointersToElt<0>,
1806                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
1807                               llvm_i32_ty],
1808                             [ IntrReadMem, IntrNoSync, IntrWillReturn]>;
1809
1810def int_vp_scatter: DefaultAttrsIntrinsic<[],
1811                             [ llvm_anyvector_ty,
1812                               LLVMVectorOfAnyPointersToElt<0>,
1813                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
1814                               llvm_i32_ty],
1815                             [ IntrNoSync, IntrWillReturn ]>; // TODO allow IntrNoCapture for vectors of pointers
1816
1817// Experimental strided memory accesses
1818def int_experimental_vp_strided_store : DefaultAttrsIntrinsic<[],
1819                             [ llvm_anyvector_ty,
1820                               llvm_anyptr_ty,
1821                               llvm_anyint_ty, // Stride in bytes
1822                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
1823                               llvm_i32_ty],
1824                             [ NoCapture<ArgIndex<1>>, IntrNoSync, IntrWriteMem, IntrArgMemOnly, IntrWillReturn ]>;
1825
1826def int_experimental_vp_strided_load  : DefaultAttrsIntrinsic<[llvm_anyvector_ty],
1827                             [ llvm_anyptr_ty,
1828                               llvm_anyint_ty, // Stride in bytes
1829                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
1830                               llvm_i32_ty],
1831                             [ NoCapture<ArgIndex<0>>, IntrNoSync, IntrReadMem, IntrWillReturn, IntrArgMemOnly ]>;
1832
1833// Operators
1834let IntrProperties = [IntrNoMem, IntrNoSync, IntrWillReturn] in {
1835  // Integer arithmetic
1836  def int_vp_add : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
1837                             [ LLVMMatchType<0>,
1838                               LLVMMatchType<0>,
1839                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
1840                               llvm_i32_ty]>;
1841  def int_vp_sub : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
1842                             [ LLVMMatchType<0>,
1843                               LLVMMatchType<0>,
1844                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
1845                               llvm_i32_ty]>;
1846  def int_vp_mul  : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
1847                             [ LLVMMatchType<0>,
1848                               LLVMMatchType<0>,
1849                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
1850                               llvm_i32_ty]>;
1851  def int_vp_ashr : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
1852                             [ LLVMMatchType<0>,
1853                               LLVMMatchType<0>,
1854                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
1855                               llvm_i32_ty]>;
1856  def int_vp_lshr : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
1857                             [ LLVMMatchType<0>,
1858                               LLVMMatchType<0>,
1859                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
1860                               llvm_i32_ty]>;
1861  def int_vp_shl : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
1862                             [ LLVMMatchType<0>,
1863                               LLVMMatchType<0>,
1864                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
1865                               llvm_i32_ty]>;
1866  def int_vp_or : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
1867                             [ LLVMMatchType<0>,
1868                               LLVMMatchType<0>,
1869                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
1870                               llvm_i32_ty]>;
1871  def int_vp_and : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
1872                             [ LLVMMatchType<0>,
1873                               LLVMMatchType<0>,
1874                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
1875                               llvm_i32_ty]>;
1876  def int_vp_xor : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
1877                             [ LLVMMatchType<0>,
1878                               LLVMMatchType<0>,
1879                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
1880                               llvm_i32_ty]>;
1881  def int_vp_sdiv : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
1882                             [ LLVMMatchType<0>,
1883                               LLVMMatchType<0>,
1884                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
1885                               llvm_i32_ty]>;
1886  def int_vp_udiv : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
1887                             [ LLVMMatchType<0>,
1888                               LLVMMatchType<0>,
1889                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
1890                               llvm_i32_ty]>;
1891  def int_vp_srem : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
1892                             [ LLVMMatchType<0>,
1893                               LLVMMatchType<0>,
1894                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
1895                               llvm_i32_ty]>;
1896  def int_vp_urem : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
1897                             [ LLVMMatchType<0>,
1898                               LLVMMatchType<0>,
1899                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
1900                               llvm_i32_ty]>;
1901  def int_vp_abs : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
1902                             [ LLVMMatchType<0>,
1903                               llvm_i1_ty,
1904                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
1905                               llvm_i32_ty]>;
1906  def int_vp_smin : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
1907                             [ LLVMMatchType<0>,
1908                               LLVMMatchType<0>,
1909                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
1910                               llvm_i32_ty]>;
1911  def int_vp_smax : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
1912                             [ LLVMMatchType<0>,
1913                               LLVMMatchType<0>,
1914                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
1915                               llvm_i32_ty]>;
1916  def int_vp_umin : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
1917                             [ LLVMMatchType<0>,
1918                               LLVMMatchType<0>,
1919                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
1920                               llvm_i32_ty]>;
1921  def int_vp_umax : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
1922                             [ LLVMMatchType<0>,
1923                               LLVMMatchType<0>,
1924                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
1925                               llvm_i32_ty]>;
1926  def int_vp_bswap : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
1927                             [ LLVMMatchType<0>,
1928                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
1929                               llvm_i32_ty]>;
1930  def int_vp_bitreverse : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
1931                             [ LLVMMatchType<0>,
1932                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
1933                               llvm_i32_ty]>;
1934  def int_vp_ctpop : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
1935                             [ LLVMMatchType<0>,
1936                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
1937                               llvm_i32_ty]>;
1938  def int_vp_fshl : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
1939                             [ LLVMMatchType<0>,
1940                               LLVMMatchType<0>,
1941                               LLVMMatchType<0>,
1942                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
1943                               llvm_i32_ty]>;
1944  def int_vp_fshr : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
1945                             [ LLVMMatchType<0>,
1946                               LLVMMatchType<0>,
1947                               LLVMMatchType<0>,
1948                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
1949                               llvm_i32_ty]>;
1950  def int_vp_sadd_sat : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
1951                             [ LLVMMatchType<0>,
1952                               LLVMMatchType<0>,
1953                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
1954                               llvm_i32_ty]>;
1955  def int_vp_uadd_sat : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
1956                             [ LLVMMatchType<0>,
1957                               LLVMMatchType<0>,
1958                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
1959                               llvm_i32_ty]>;
1960  def int_vp_ssub_sat : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
1961                             [ LLVMMatchType<0>,
1962                               LLVMMatchType<0>,
1963                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
1964                               llvm_i32_ty]>;
1965  def int_vp_usub_sat : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
1966                             [ LLVMMatchType<0>,
1967                               LLVMMatchType<0>,
1968                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
1969                               llvm_i32_ty]>;
1970
1971  // Floating-point arithmetic
1972  def int_vp_fadd : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
1973                             [ LLVMMatchType<0>,
1974                               LLVMMatchType<0>,
1975                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
1976                               llvm_i32_ty]>;
1977  def int_vp_fsub : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
1978                             [ LLVMMatchType<0>,
1979                               LLVMMatchType<0>,
1980                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
1981                               llvm_i32_ty]>;
1982  def int_vp_fmul  : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
1983                             [ LLVMMatchType<0>,
1984                               LLVMMatchType<0>,
1985                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
1986                               llvm_i32_ty]>;
1987  def int_vp_fdiv : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
1988                             [ LLVMMatchType<0>,
1989                               LLVMMatchType<0>,
1990                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
1991                               llvm_i32_ty]>;
1992  def int_vp_frem : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
1993                             [ LLVMMatchType<0>,
1994                               LLVMMatchType<0>,
1995                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
1996                               llvm_i32_ty]>;
1997  def int_vp_fneg : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
1998                             [ LLVMMatchType<0>,
1999                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2000                               llvm_i32_ty]>;
2001  def int_vp_fabs : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
2002                             [ LLVMMatchType<0>,
2003                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2004                               llvm_i32_ty]>;
2005  def int_vp_sqrt : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
2006                             [ LLVMMatchType<0>,
2007                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2008                               llvm_i32_ty]>;
2009  def int_vp_fma : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
2010                             [ LLVMMatchType<0>,
2011                               LLVMMatchType<0>,
2012                               LLVMMatchType<0>,
2013                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2014                               llvm_i32_ty]>;
2015  def int_vp_fmuladd : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
2016                             [ LLVMMatchType<0>,
2017                               LLVMMatchType<0>,
2018                               LLVMMatchType<0>,
2019                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2020                               llvm_i32_ty]>;
2021  def int_vp_minnum : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
2022                             [ LLVMMatchType<0>,
2023                               LLVMMatchType<0>,
2024                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2025                               llvm_i32_ty]>;
2026  def int_vp_maxnum : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
2027                             [ LLVMMatchType<0>,
2028                               LLVMMatchType<0>,
2029                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2030                               llvm_i32_ty]>;
2031  def int_vp_minimum : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
2032                             [ LLVMMatchType<0>,
2033                               LLVMMatchType<0>,
2034                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2035                               llvm_i32_ty]>;
2036  def int_vp_maximum : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
2037                             [ LLVMMatchType<0>,
2038                               LLVMMatchType<0>,
2039                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2040                               llvm_i32_ty]>;
2041  def int_vp_copysign : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
2042                             [ LLVMMatchType<0>,
2043                               LLVMMatchType<0>,
2044                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2045                               llvm_i32_ty]>;
2046  def int_vp_ceil : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
2047                             [ LLVMMatchType<0>,
2048                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2049                               llvm_i32_ty]>;
2050  def int_vp_floor : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
2051                             [ LLVMMatchType<0>,
2052                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2053                               llvm_i32_ty]>;
2054  def int_vp_round : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
2055                             [ LLVMMatchType<0>,
2056                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2057                               llvm_i32_ty]>;
2058  def int_vp_roundeven : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
2059                             [ LLVMMatchType<0>,
2060                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2061                               llvm_i32_ty]>;
2062  def int_vp_roundtozero : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
2063                             [ LLVMMatchType<0>,
2064                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2065                               llvm_i32_ty]>;
2066  def int_vp_rint : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
2067                             [ LLVMMatchType<0>,
2068                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2069                               llvm_i32_ty]>;
2070  def int_vp_nearbyint : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
2071                             [ LLVMMatchType<0>,
2072                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2073                               llvm_i32_ty]>;
2074  def int_vp_lrint : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
2075                             [ llvm_anyvector_ty,
2076                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2077                               llvm_i32_ty]>;
2078  def int_vp_llrint : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
2079                             [ llvm_anyvector_ty,
2080                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2081                               llvm_i32_ty]>;
2082
2083  // Casts
2084  def int_vp_trunc : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
2085                             [ llvm_anyvector_ty,
2086                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2087                               llvm_i32_ty]>;
2088  def int_vp_zext : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
2089                             [ llvm_anyvector_ty,
2090                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2091                               llvm_i32_ty]>;
2092  def int_vp_sext : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
2093                             [ llvm_anyvector_ty,
2094                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2095                               llvm_i32_ty]>;
2096  def int_vp_fptrunc : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
2097                             [ llvm_anyvector_ty,
2098                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2099                               llvm_i32_ty]>;
2100  def int_vp_fpext : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
2101                             [ llvm_anyvector_ty,
2102                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2103                               llvm_i32_ty]>;
2104  def int_vp_fptoui : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
2105                             [ llvm_anyvector_ty,
2106                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2107                               llvm_i32_ty]>;
2108  def int_vp_fptosi : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
2109                             [ llvm_anyvector_ty,
2110                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2111                               llvm_i32_ty]>;
2112  def int_vp_uitofp : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
2113                             [ llvm_anyvector_ty,
2114                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2115                               llvm_i32_ty]>;
2116  def int_vp_sitofp : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
2117                             [ llvm_anyvector_ty,
2118                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2119                               llvm_i32_ty]>;
2120  def int_vp_ptrtoint : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
2121                             [ llvm_anyvector_ty,
2122                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2123                               llvm_i32_ty]>;
2124  def int_vp_inttoptr : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
2125                             [ llvm_anyvector_ty,
2126                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2127                               llvm_i32_ty]>;
2128  // Shuffles
2129  def int_vp_select : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
2130                             [ LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2131                               LLVMMatchType<0>,
2132                               LLVMMatchType<0>,
2133                               llvm_i32_ty]>;
2134  def int_vp_merge : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
2135                             [ LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2136                               LLVMMatchType<0>,
2137                               LLVMMatchType<0>,
2138                               llvm_i32_ty]>;
2139
2140  // Comparisons
2141  def int_vp_fcmp : DefaultAttrsIntrinsic<[ LLVMScalarOrSameVectorWidth<0, llvm_i1_ty> ],
2142                             [ llvm_anyvector_ty,
2143                               LLVMMatchType<0>,
2144                               llvm_metadata_ty,
2145                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2146                               llvm_i32_ty]>;
2147  def int_vp_icmp : DefaultAttrsIntrinsic<[ LLVMScalarOrSameVectorWidth<0, llvm_i1_ty> ],
2148                             [ llvm_anyvector_ty,
2149                               LLVMMatchType<0>,
2150                               llvm_metadata_ty,
2151                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2152                               llvm_i32_ty]>;
2153
2154  // Reductions
2155  def int_vp_reduce_fadd : DefaultAttrsIntrinsic<[LLVMVectorElementType<0>],
2156                             [ LLVMVectorElementType<0>,
2157                               llvm_anyvector_ty,
2158                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2159                               llvm_i32_ty]>;
2160  def int_vp_reduce_fmul : DefaultAttrsIntrinsic<[LLVMVectorElementType<0>],
2161                             [ LLVMVectorElementType<0>,
2162                               llvm_anyvector_ty,
2163                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2164                               llvm_i32_ty]>;
2165  def int_vp_reduce_add  : DefaultAttrsIntrinsic<[LLVMVectorElementType<0>],
2166                             [ LLVMVectorElementType<0>,
2167                               llvm_anyvector_ty,
2168                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2169                               llvm_i32_ty]>;
2170  def int_vp_reduce_mul : DefaultAttrsIntrinsic<[LLVMVectorElementType<0>],
2171                             [ LLVMVectorElementType<0>,
2172                               llvm_anyvector_ty,
2173                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2174                               llvm_i32_ty]>;
2175  def int_vp_reduce_and : DefaultAttrsIntrinsic<[LLVMVectorElementType<0>],
2176                             [ LLVMVectorElementType<0>,
2177                               llvm_anyvector_ty,
2178                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2179                               llvm_i32_ty]>;
2180  def int_vp_reduce_or : DefaultAttrsIntrinsic<[LLVMVectorElementType<0>],
2181                             [ LLVMVectorElementType<0>,
2182                               llvm_anyvector_ty,
2183                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2184                               llvm_i32_ty]>;
2185  def int_vp_reduce_xor : DefaultAttrsIntrinsic<[LLVMVectorElementType<0>],
2186                             [ LLVMVectorElementType<0>,
2187                               llvm_anyvector_ty,
2188                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2189                               llvm_i32_ty]>;
2190  def int_vp_reduce_smax : DefaultAttrsIntrinsic<[LLVMVectorElementType<0>],
2191                             [ LLVMVectorElementType<0>,
2192                               llvm_anyvector_ty,
2193                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2194                               llvm_i32_ty]>;
2195  def int_vp_reduce_smin : DefaultAttrsIntrinsic<[LLVMVectorElementType<0>],
2196                             [ LLVMVectorElementType<0>,
2197                               llvm_anyvector_ty,
2198                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2199                               llvm_i32_ty]>;
2200  def int_vp_reduce_umax : DefaultAttrsIntrinsic<[LLVMVectorElementType<0>],
2201                             [ LLVMVectorElementType<0>,
2202                               llvm_anyvector_ty,
2203                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2204                               llvm_i32_ty]>;
2205  def int_vp_reduce_umin : DefaultAttrsIntrinsic<[LLVMVectorElementType<0>],
2206                             [ LLVMVectorElementType<0>,
2207                               llvm_anyvector_ty,
2208                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2209                               llvm_i32_ty]>;
2210  def int_vp_reduce_fmax : DefaultAttrsIntrinsic<[LLVMVectorElementType<0>],
2211                             [ LLVMVectorElementType<0>,
2212                               llvm_anyvector_ty,
2213                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2214                               llvm_i32_ty]>;
2215  def int_vp_reduce_fmin : DefaultAttrsIntrinsic<[LLVMVectorElementType<0>],
2216                             [ LLVMVectorElementType<0>,
2217                               llvm_anyvector_ty,
2218                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2219                               llvm_i32_ty]>;
2220}
2221
2222let IntrProperties = [IntrNoMem, IntrNoSync, IntrWillReturn, ImmArg<ArgIndex<1>>] in {
2223  def int_vp_ctlz : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
2224                             [ LLVMMatchType<0>,
2225                               llvm_i1_ty,
2226                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2227                               llvm_i32_ty]>;
2228  def int_vp_cttz : DefaultAttrsIntrinsic<[ llvm_anyvector_ty ],
2229                             [ LLVMMatchType<0>,
2230                               llvm_i1_ty,
2231                               LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2232                               llvm_i32_ty]>;
2233}
2234
2235def int_get_active_lane_mask:
2236  DefaultAttrsIntrinsic<[llvm_anyvector_ty],
2237            [llvm_anyint_ty, LLVMMatchType<1>],
2238            [IntrNoMem, IntrNoSync, IntrWillReturn]>;
2239
2240def int_experimental_get_vector_length:
2241  DefaultAttrsIntrinsic<[llvm_i32_ty],
2242                        [llvm_anyint_ty, llvm_i32_ty, llvm_i1_ty],
2243                        [IntrNoMem, IntrNoSync, IntrWillReturn,
2244                         ImmArg<ArgIndex<1>>, ImmArg<ArgIndex<2>>]>;
2245
2246def int_experimental_cttz_elts:
2247  DefaultAttrsIntrinsic<[llvm_anyint_ty],
2248            [llvm_anyvector_ty, llvm_i1_ty],
2249            [IntrNoMem, IntrNoSync, IntrWillReturn, ImmArg<ArgIndex<1>>]>;
2250
2251def int_experimental_vp_splice:
2252  DefaultAttrsIntrinsic<[llvm_anyvector_ty],
2253            [LLVMMatchType<0>,
2254             LLVMMatchType<0>,
2255             llvm_i32_ty,
2256             LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2257             llvm_i32_ty, llvm_i32_ty],
2258            [IntrNoMem, ImmArg<ArgIndex<2>>]>;
2259
2260def int_experimental_vp_reverse:
2261  DefaultAttrsIntrinsic<[llvm_anyvector_ty],
2262                        [LLVMMatchType<0>,
2263                         LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2264                         llvm_i32_ty],
2265                        [IntrNoMem]>;
2266
2267def int_vp_is_fpclass:
2268      DefaultAttrsIntrinsic<[ LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>],
2269                              [ llvm_anyvector_ty,
2270                                llvm_i32_ty,
2271                                LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2272                                llvm_i32_ty],
2273                              [IntrNoMem, IntrSpeculatable, ImmArg<ArgIndex<1>>]>;
2274
2275//===-------------------------- Masked Intrinsics -------------------------===//
2276//
2277def int_masked_load:
2278  DefaultAttrsIntrinsic<[llvm_anyvector_ty],
2279            [llvm_anyptr_ty, llvm_i32_ty,
2280             LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>, LLVMMatchType<0>],
2281            [IntrReadMem, IntrArgMemOnly, IntrWillReturn, ImmArg<ArgIndex<1>>,
2282             NoCapture<ArgIndex<0>>]>;
2283
2284def int_masked_store:
2285  DefaultAttrsIntrinsic<[],
2286            [llvm_anyvector_ty, llvm_anyptr_ty,
2287             llvm_i32_ty, LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>],
2288            [IntrWriteMem, IntrArgMemOnly, IntrWillReturn,
2289             ImmArg<ArgIndex<2>>, NoCapture<ArgIndex<1>>]>;
2290
2291def int_masked_gather:
2292  DefaultAttrsIntrinsic<[llvm_anyvector_ty],
2293            [LLVMVectorOfAnyPointersToElt<0>, llvm_i32_ty,
2294             LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>, LLVMMatchType<0>],
2295            [IntrReadMem, IntrWillReturn, ImmArg<ArgIndex<1>>]>;
2296
2297def int_masked_scatter:
2298  DefaultAttrsIntrinsic<[],
2299            [llvm_anyvector_ty, LLVMVectorOfAnyPointersToElt<0>, llvm_i32_ty,
2300             LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>],
2301            [IntrWriteMem, IntrWillReturn, ImmArg<ArgIndex<2>>]>;
2302
2303def int_masked_expandload:
2304  DefaultAttrsIntrinsic<[llvm_anyvector_ty],
2305            [llvm_ptr_ty, LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
2306             LLVMMatchType<0>],
2307            [IntrReadMem, IntrWillReturn, NoCapture<ArgIndex<0>>]>;
2308
2309def int_masked_compressstore:
2310  DefaultAttrsIntrinsic<[],
2311            [llvm_anyvector_ty, llvm_ptr_ty,
2312             LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>],
2313            [IntrWriteMem, IntrArgMemOnly, IntrWillReturn,
2314             NoCapture<ArgIndex<1>>]>;
2315
2316// Test whether a pointer is associated with a type metadata identifier.
2317def int_type_test : DefaultAttrsIntrinsic<[llvm_i1_ty], [llvm_ptr_ty, llvm_metadata_ty],
2318                              [IntrNoMem, IntrWillReturn, IntrSpeculatable]>;
2319
2320// Safely loads a function pointer from a virtual table pointer using type metadata.
2321def int_type_checked_load : DefaultAttrsIntrinsic<[llvm_ptr_ty, llvm_i1_ty],
2322                                      [llvm_ptr_ty, llvm_i32_ty, llvm_metadata_ty],
2323                                      [IntrNoMem, IntrWillReturn]>;
2324
2325// Safely loads a relative function pointer from a virtual table pointer using type metadata.
2326def int_type_checked_load_relative : DefaultAttrsIntrinsic<[llvm_ptr_ty, llvm_i1_ty],
2327                                      [llvm_ptr_ty, llvm_i32_ty, llvm_metadata_ty],
2328                                      [IntrNoMem, IntrWillReturn]>;
2329
2330// Test whether a pointer is associated with a type metadata identifier. Used
2331// for public visibility classes that may later be refined to private
2332// visibility.
2333def int_public_type_test : DefaultAttrsIntrinsic<[llvm_i1_ty], [llvm_ptr_ty, llvm_metadata_ty],
2334                              [IntrNoMem, IntrWillReturn, IntrSpeculatable]>;
2335
2336// Create a branch funnel that implements an indirect call to a limited set of
2337// callees. This needs to be a musttail call.
2338def int_icall_branch_funnel : DefaultAttrsIntrinsic<[], [llvm_vararg_ty], []>;
2339
2340def int_load_relative: DefaultAttrsIntrinsic<[llvm_ptr_ty], [llvm_ptr_ty, llvm_anyint_ty],
2341                                 [IntrReadMem, IntrArgMemOnly]>;
2342
2343def int_asan_check_memaccess :
2344  Intrinsic<[],[llvm_ptr_ty, llvm_i32_ty], [ImmArg<ArgIndex<1>>]>;
2345
2346def int_hwasan_check_memaccess :
2347  Intrinsic<[], [llvm_ptr_ty, llvm_ptr_ty, llvm_i32_ty],
2348            [ImmArg<ArgIndex<2>>]>;
2349def int_hwasan_check_memaccess_shortgranules :
2350  Intrinsic<[], [llvm_ptr_ty, llvm_ptr_ty, llvm_i32_ty],
2351            [ImmArg<ArgIndex<2>>]>;
2352
2353// Xray intrinsics
2354//===----------------------------------------------------------------------===//
2355// Custom event logging for x-ray.
2356// Takes a pointer to a string and the length of the string.
2357def int_xray_customevent : Intrinsic<[], [llvm_ptr_ty, llvm_i64_ty],
2358                                     [IntrWriteMem, NoCapture<ArgIndex<0>>,
2359                                      ReadOnly<ArgIndex<0>>]>;
2360// Typed event logging for x-ray.
2361// Takes a numeric type tag, a pointer to a string and the length of the string.
2362def int_xray_typedevent : Intrinsic<[], [llvm_i64_ty, llvm_ptr_ty, llvm_i64_ty],
2363                                        [IntrWriteMem, NoCapture<ArgIndex<1>>,
2364                                         ReadOnly<ArgIndex<1>>]>;
2365//===----------------------------------------------------------------------===//
2366
2367//===------ Memory intrinsics with element-wise atomicity guarantees ------===//
2368//
2369
2370// @llvm.memcpy.element.unordered.atomic.*(dest, src, length, elementsize)
2371def int_memcpy_element_unordered_atomic
2372    : Intrinsic<[],
2373                [llvm_anyptr_ty, llvm_anyptr_ty, llvm_anyint_ty, llvm_i32_ty],
2374                [IntrArgMemOnly, IntrWillReturn, IntrNoSync,
2375                 NoCapture<ArgIndex<0>>, NoCapture<ArgIndex<1>>,
2376                 WriteOnly<ArgIndex<0>>, ReadOnly<ArgIndex<1>>,
2377                 ImmArg<ArgIndex<3>>]>;
2378
2379// @llvm.memmove.element.unordered.atomic.*(dest, src, length, elementsize)
2380def int_memmove_element_unordered_atomic
2381    : Intrinsic<[],
2382                [llvm_anyptr_ty, llvm_anyptr_ty, llvm_anyint_ty, llvm_i32_ty],
2383                [IntrArgMemOnly, IntrWillReturn, IntrNoSync,
2384                 NoCapture<ArgIndex<0>>, NoCapture<ArgIndex<1>>,
2385                 WriteOnly<ArgIndex<0>>, ReadOnly<ArgIndex<1>>,
2386                 ImmArg<ArgIndex<3>>]>;
2387
2388// @llvm.memset.element.unordered.atomic.*(dest, value, length, elementsize)
2389def int_memset_element_unordered_atomic
2390    : Intrinsic<[], [llvm_anyptr_ty, llvm_i8_ty, llvm_anyint_ty, llvm_i32_ty],
2391                [IntrWriteMem, IntrArgMemOnly, IntrWillReturn, IntrNoSync,
2392                 NoCapture<ArgIndex<0>>, WriteOnly<ArgIndex<0>>,
2393                 ImmArg<ArgIndex<3>>]>;
2394
2395//===------------------------ Reduction Intrinsics ------------------------===//
2396//
2397let IntrProperties = [IntrNoMem, IntrSpeculatable] in {
2398
2399  def int_vector_reduce_fadd : DefaultAttrsIntrinsic<[LLVMVectorElementType<0>],
2400                                         [LLVMVectorElementType<0>,
2401                                          llvm_anyvector_ty]>;
2402  def int_vector_reduce_fmul : DefaultAttrsIntrinsic<[LLVMVectorElementType<0>],
2403                                         [LLVMVectorElementType<0>,
2404                                          llvm_anyvector_ty]>;
2405  def int_vector_reduce_add : DefaultAttrsIntrinsic<[LLVMVectorElementType<0>],
2406                                        [llvm_anyvector_ty]>;
2407  def int_vector_reduce_mul : DefaultAttrsIntrinsic<[LLVMVectorElementType<0>],
2408                                        [llvm_anyvector_ty]>;
2409  def int_vector_reduce_and : DefaultAttrsIntrinsic<[LLVMVectorElementType<0>],
2410                                        [llvm_anyvector_ty]>;
2411  def int_vector_reduce_or : DefaultAttrsIntrinsic<[LLVMVectorElementType<0>],
2412                                       [llvm_anyvector_ty]>;
2413  def int_vector_reduce_xor : DefaultAttrsIntrinsic<[LLVMVectorElementType<0>],
2414                                        [llvm_anyvector_ty]>;
2415  def int_vector_reduce_smax : DefaultAttrsIntrinsic<[LLVMVectorElementType<0>],
2416                                         [llvm_anyvector_ty]>;
2417  def int_vector_reduce_smin : DefaultAttrsIntrinsic<[LLVMVectorElementType<0>],
2418                                         [llvm_anyvector_ty]>;
2419  def int_vector_reduce_umax : DefaultAttrsIntrinsic<[LLVMVectorElementType<0>],
2420                                         [llvm_anyvector_ty]>;
2421  def int_vector_reduce_umin : DefaultAttrsIntrinsic<[LLVMVectorElementType<0>],
2422                                         [llvm_anyvector_ty]>;
2423  def int_vector_reduce_fmax : DefaultAttrsIntrinsic<[LLVMVectorElementType<0>],
2424                                         [llvm_anyvector_ty]>;
2425  def int_vector_reduce_fmin : DefaultAttrsIntrinsic<[LLVMVectorElementType<0>],
2426                                         [llvm_anyvector_ty]>;
2427  def int_vector_reduce_fminimum: DefaultAttrsIntrinsic<[LLVMVectorElementType<0>],
2428                                         [llvm_anyvector_ty]>;
2429  def int_vector_reduce_fmaximum: DefaultAttrsIntrinsic<[LLVMVectorElementType<0>],
2430                                         [llvm_anyvector_ty]>;
2431}
2432
2433//===----- Matrix intrinsics ---------------------------------------------===//
2434
2435def int_matrix_transpose
2436  : DefaultAttrsIntrinsic<[llvm_anyvector_ty],
2437              [LLVMMatchType<0>, llvm_i32_ty, llvm_i32_ty],
2438              [ IntrNoSync, IntrWillReturn, IntrNoMem, IntrSpeculatable, ImmArg<ArgIndex<1>>,
2439               ImmArg<ArgIndex<2>>]>;
2440
2441def int_matrix_multiply
2442  : DefaultAttrsIntrinsic<[llvm_anyvector_ty],
2443              [llvm_anyvector_ty, llvm_anyvector_ty, llvm_i32_ty, llvm_i32_ty,
2444               llvm_i32_ty],
2445              [IntrNoSync, IntrWillReturn, IntrNoMem, IntrSpeculatable, ImmArg<ArgIndex<2>>,
2446               ImmArg<ArgIndex<3>>, ImmArg<ArgIndex<4>>]>;
2447
2448def int_matrix_column_major_load
2449  : DefaultAttrsIntrinsic<[llvm_anyvector_ty],
2450              [llvm_ptr_ty, llvm_anyint_ty, llvm_i1_ty,
2451               llvm_i32_ty, llvm_i32_ty],
2452              [IntrNoSync, IntrWillReturn, IntrArgMemOnly, IntrReadMem,
2453               NoCapture<ArgIndex<0>>, ImmArg<ArgIndex<2>>, ImmArg<ArgIndex<3>>,
2454               ImmArg<ArgIndex<4>>]>;
2455
2456def int_matrix_column_major_store
2457  : DefaultAttrsIntrinsic<[],
2458              [llvm_anyvector_ty, llvm_ptr_ty,
2459               llvm_anyint_ty, llvm_i1_ty, llvm_i32_ty, llvm_i32_ty],
2460              [IntrNoSync, IntrWillReturn, IntrArgMemOnly, IntrWriteMem,
2461               WriteOnly<ArgIndex<1>>, NoCapture<ArgIndex<1>>,
2462               ImmArg<ArgIndex<3>>, ImmArg<ArgIndex<4>>, ImmArg<ArgIndex<5>>]>;
2463
2464//===---------- Intrinsics to control hardware supported loops ----------===//
2465
2466// Specify that the value given is the number of iterations that the next loop
2467// will execute.
2468def int_set_loop_iterations :
2469  DefaultAttrsIntrinsic<[], [llvm_anyint_ty], [IntrNoDuplicate]>;
2470
2471// Same as the above, but produces a value (the same as the input operand) to
2472// be fed into the loop.
2473def int_start_loop_iterations :
2474  DefaultAttrsIntrinsic<[llvm_anyint_ty], [LLVMMatchType<0>], [IntrNoDuplicate]>;
2475
2476// Specify that the value given is the number of iterations that the next loop
2477// will execute. Also test that the given count is not zero, allowing it to
2478// control entry to a 'while' loop.
2479def int_test_set_loop_iterations :
2480  DefaultAttrsIntrinsic<[llvm_i1_ty], [llvm_anyint_ty], [IntrNoDuplicate]>;
2481
2482// Same as the above, but produces an extra value (the same as the input
2483// operand) to be fed into the loop.
2484def int_test_start_loop_iterations :
2485  DefaultAttrsIntrinsic<[llvm_anyint_ty, llvm_i1_ty], [LLVMMatchType<0>],
2486                        [IntrNoDuplicate]>;
2487
2488// Decrement loop counter by the given argument. Return false if the loop
2489// should exit.
2490def int_loop_decrement :
2491  DefaultAttrsIntrinsic<[llvm_i1_ty], [llvm_anyint_ty], [IntrNoDuplicate]>;
2492
2493// Decrement the first operand (the loop counter) by the second operand (the
2494// maximum number of elements processed in an iteration). Return the remaining
2495// number of iterations still to be executed. This is effectively a sub which
2496// can be used with a phi, icmp and br to control the number of iterations
2497// executed, as usual. Any optimisations are allowed to treat it is a sub, and
2498// it's scevable, so it's the backends responsibility to handle cases where it
2499// may be optimised.
2500def int_loop_decrement_reg :
2501  DefaultAttrsIntrinsic<[llvm_anyint_ty],
2502            [LLVMMatchType<0>, LLVMMatchType<0>], [IntrNoDuplicate]>;
2503
2504//===----- Intrinsics that are used to provide predicate information -----===//
2505
2506def int_ssa_copy : DefaultAttrsIntrinsic<[llvm_any_ty], [LLVMMatchType<0>],
2507                             [IntrNoMem, Returned<ArgIndex<0>>]>;
2508
2509//===------- Intrinsics that are used to preserve debug information -------===//
2510
2511def int_preserve_array_access_index : DefaultAttrsIntrinsic<[llvm_anyptr_ty],
2512                                                [llvm_anyptr_ty, llvm_i32_ty,
2513                                                 llvm_i32_ty],
2514                                                [IntrNoMem,
2515                                                 ImmArg<ArgIndex<1>>,
2516                                                 ImmArg<ArgIndex<2>>]>;
2517def int_preserve_union_access_index : DefaultAttrsIntrinsic<[llvm_anyptr_ty],
2518                                                [llvm_anyptr_ty, llvm_i32_ty],
2519                                                [IntrNoMem,
2520                                                 ImmArg<ArgIndex<1>>]>;
2521def int_preserve_struct_access_index : DefaultAttrsIntrinsic<[llvm_anyptr_ty],
2522                                                 [llvm_anyptr_ty, llvm_i32_ty,
2523                                                  llvm_i32_ty],
2524                                                 [IntrNoMem,
2525                                                  ImmArg<ArgIndex<1>>,
2526                                                  ImmArg<ArgIndex<2>>]>;
2527def int_preserve_static_offset : DefaultAttrsIntrinsic<[llvm_ptr_ty],
2528                                                       [llvm_ptr_ty],
2529                                                       [IntrNoMem, IntrSpeculatable,
2530                                                        ReadNone <ArgIndex<0>>]>;
2531
2532//===------------ Intrinsics to perform common vector shuffles ------------===//
2533
2534def int_experimental_vector_reverse : DefaultAttrsIntrinsic<[llvm_anyvector_ty],
2535                                                            [LLVMMatchType<0>],
2536                                                            [IntrNoMem]>;
2537
2538def int_experimental_vector_splice : DefaultAttrsIntrinsic<[llvm_anyvector_ty],
2539                                                           [LLVMMatchType<0>,
2540                                                            LLVMMatchType<0>,
2541                                                            llvm_i32_ty],
2542                                                           [IntrNoMem, ImmArg<ArgIndex<2>>]>;
2543
2544//===---------- Intrinsics to query properties of scalable vectors --------===//
2545def int_vscale : DefaultAttrsIntrinsic<[llvm_anyint_ty], [], [IntrNoMem]>;
2546
2547//===---------- Intrinsics to perform subvector insertion/extraction ------===//
2548def int_vector_insert : DefaultAttrsIntrinsic<[llvm_anyvector_ty],
2549                                              [LLVMMatchType<0>, llvm_anyvector_ty, llvm_i64_ty],
2550                                              [IntrNoMem, IntrSpeculatable, ImmArg<ArgIndex<2>>]>;
2551
2552def int_vector_extract : DefaultAttrsIntrinsic<[llvm_anyvector_ty],
2553                                               [llvm_anyvector_ty, llvm_i64_ty],
2554                                               [IntrNoMem, IntrSpeculatable, ImmArg<ArgIndex<1>>]>;
2555
2556
2557def int_experimental_vector_interleave2   : DefaultAttrsIntrinsic<[llvm_anyvector_ty],
2558                                                                  [LLVMHalfElementsVectorType<0>,
2559                                                                   LLVMHalfElementsVectorType<0>],
2560                                                                  [IntrNoMem]>;
2561
2562def int_experimental_vector_deinterleave2 : DefaultAttrsIntrinsic<[LLVMHalfElementsVectorType<0>,
2563                                                                   LLVMHalfElementsVectorType<0>],
2564                                                                  [llvm_anyvector_ty],
2565                                                                  [IntrNoMem]>;
2566
2567//===----------------- Pointer Authentication Intrinsics ------------------===//
2568//
2569
2570// Sign an unauthenticated pointer using the specified key and discriminator,
2571// passed in that order.
2572// Returns the first argument, with some known bits replaced with a signature.
2573def int_ptrauth_sign :
2574  DefaultAttrsIntrinsic<[llvm_i64_ty], [llvm_i64_ty, llvm_i32_ty, llvm_i64_ty],
2575                        [IntrNoMem, ImmArg<ArgIndex<1>>]>;
2576
2577// Authenticate a signed pointer, using the specified key and discriminator.
2578// Returns the first argument, with the signature bits removed.
2579// The signature must be valid.
2580def int_ptrauth_auth : Intrinsic<[llvm_i64_ty],
2581                                 [llvm_i64_ty, llvm_i32_ty, llvm_i64_ty],
2582                                 [IntrNoMem,ImmArg<ArgIndex<1>>]>;
2583
2584// Authenticate a signed pointer and resign it.
2585// The second (key) and third (discriminator) arguments specify the signing
2586// schema used for authenticating.
2587// The fourth and fifth arguments specify the schema used for signing.
2588// The signature must be valid.
2589// This is a combined form of @llvm.ptrauth.sign and @llvm.ptrauth.auth, with
2590// an additional integrity guarantee on the intermediate value.
2591def int_ptrauth_resign : Intrinsic<[llvm_i64_ty],
2592                                   [llvm_i64_ty, llvm_i32_ty, llvm_i64_ty,
2593                                    llvm_i32_ty, llvm_i64_ty],
2594                                   [IntrNoMem, ImmArg<ArgIndex<1>>,
2595                                    ImmArg<ArgIndex<3>>]>;
2596
2597// Strip the embedded signature out of a signed pointer.
2598// The second argument specifies the key.
2599// This behaves like @llvm.ptrauth.auth, but doesn't require the signature to
2600// be valid.
2601def int_ptrauth_strip :
2602  DefaultAttrsIntrinsic<[llvm_i64_ty], [llvm_i64_ty, llvm_i32_ty],
2603                        [IntrNoMem, ImmArg<ArgIndex<1>>]>;
2604
2605// Blend a small integer discriminator with an address discriminator, producing
2606// a new discriminator value.
2607def int_ptrauth_blend :
2608  DefaultAttrsIntrinsic<[llvm_i64_ty], [llvm_i64_ty, llvm_i64_ty], [IntrNoMem]>;
2609
2610// Compute the signature of a value, using a given discriminator.
2611// This differs from @llvm.ptrauth.sign in that it doesn't embed the computed
2612// signature in the pointer, but instead returns the signature as a value.
2613// That allows it to be used to sign non-pointer data: in that sense, it is
2614// generic.  There is no generic @llvm.ptrauth.auth: instead, the signature
2615// can be computed using @llvm.ptrauth.sign_generic, and compared with icmp.
2616def int_ptrauth_sign_generic :
2617  DefaultAttrsIntrinsic<[llvm_i64_ty], [llvm_i64_ty, llvm_i64_ty], [IntrNoMem]>;
2618
2619//===----------------------------------------------------------------------===//
2620//===------- Convergence Intrinsics ---------------------------------------===//
2621
2622def int_experimental_convergence_entry
2623  : DefaultAttrsIntrinsic<[llvm_token_ty], [], [IntrNoMem, IntrConvergent]>;
2624def int_experimental_convergence_anchor
2625  : DefaultAttrsIntrinsic<[llvm_token_ty], [], [IntrNoMem, IntrConvergent]>;
2626def int_experimental_convergence_loop
2627  : DefaultAttrsIntrinsic<[llvm_token_ty], [], [IntrNoMem, IntrConvergent]>;
2628
2629//===----------------------------------------------------------------------===//
2630// Target-specific intrinsics
2631//===----------------------------------------------------------------------===//
2632
2633include "llvm/IR/IntrinsicsPowerPC.td"
2634include "llvm/IR/IntrinsicsX86.td"
2635include "llvm/IR/IntrinsicsARM.td"
2636include "llvm/IR/IntrinsicsAArch64.td"
2637include "llvm/IR/IntrinsicsXCore.td"
2638include "llvm/IR/IntrinsicsHexagon.td"
2639include "llvm/IR/IntrinsicsNVVM.td"
2640include "llvm/IR/IntrinsicsMips.td"
2641include "llvm/IR/IntrinsicsAMDGPU.td"
2642include "llvm/IR/IntrinsicsBPF.td"
2643include "llvm/IR/IntrinsicsSystemZ.td"
2644include "llvm/IR/IntrinsicsWebAssembly.td"
2645include "llvm/IR/IntrinsicsRISCV.td"
2646include "llvm/IR/IntrinsicsSPIRV.td"
2647include "llvm/IR/IntrinsicsVE.td"
2648include "llvm/IR/IntrinsicsDirectX.td"
2649include "llvm/IR/IntrinsicsLoongArch.td"
2650
2651#endif // TEST_INTRINSICS_SUPPRESS_DEFS
2652