Debian Codegraph @

suite/synctools/tablegen/include/llvm/IR/IntrinsicsAMDGPU.td

raw
1 //===- IntrinsicsAMDGPU.td - Defines AMDGPU 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 all of the R600-specific intrinsics.
10 //
11 //===----------------------------------------------------------------------===//
12
13 class AMDGPUReadPreloadRegisterIntrinsic
14 : Intrinsic<[llvm_i32_ty], [], [IntrNoMem, IntrSpeculatable, IntrWillReturn]>;
15
16 class AMDGPUReadPreloadRegisterIntrinsicNamed<string name>
17 : Intrinsic<[llvm_i32_ty], [], [IntrNoMem, IntrSpeculatable, IntrWillReturn]>, GCCBuiltin<name>;
18
19 // Used to tag image and resource intrinsics with information used to generate
20 // mem operands.
21 class AMDGPURsrcIntrinsic<int rsrcarg, bit isimage = false> {
22 int RsrcArg = rsrcarg;
23 bit IsImage = isimage;
24 }
25
26 let TargetPrefix = "r600" in {
27
28 multiclass AMDGPUReadPreloadRegisterIntrinsic_xyz {
29 def _x : AMDGPUReadPreloadRegisterIntrinsic;
30 def _y : AMDGPUReadPreloadRegisterIntrinsic;
31 def _z : AMDGPUReadPreloadRegisterIntrinsic;
32 }
33
34 multiclass AMDGPUReadPreloadRegisterIntrinsic_xyz_named<string prefix> {
35 def _x : AMDGPUReadPreloadRegisterIntrinsicNamed<!strconcat(prefix, "_x")>;
36 def _y : AMDGPUReadPreloadRegisterIntrinsicNamed<!strconcat(prefix, "_y")>;
37 def _z : AMDGPUReadPreloadRegisterIntrinsicNamed<!strconcat(prefix, "_z")>;
38 }
39
40 defm int_r600_read_global_size : AMDGPUReadPreloadRegisterIntrinsic_xyz_named
41 <"__builtin_r600_read_global_size">;
42 defm int_r600_read_ngroups : AMDGPUReadPreloadRegisterIntrinsic_xyz_named
43 <"__builtin_r600_read_ngroups">;
44 defm int_r600_read_tgid : AMDGPUReadPreloadRegisterIntrinsic_xyz_named
45 <"__builtin_r600_read_tgid">;
46
47 defm int_r600_read_local_size : AMDGPUReadPreloadRegisterIntrinsic_xyz;
48 defm int_r600_read_tidig : AMDGPUReadPreloadRegisterIntrinsic_xyz;
49
50 def int_r600_group_barrier : GCCBuiltin<"__builtin_r600_group_barrier">,
51 Intrinsic<[], [], [IntrConvergent, IntrWillReturn]>;
52
53 // AS 7 is PARAM_I_ADDRESS, used for kernel arguments
54 def int_r600_implicitarg_ptr :
55 GCCBuiltin<"__builtin_r600_implicitarg_ptr">,
56 Intrinsic<[LLVMQualPointerType<llvm_i8_ty, 7>], [],
57 [IntrNoMem, IntrSpeculatable, IntrWillReturn]>;
58
59 def int_r600_rat_store_typed :
60 // 1st parameter: Data
61 // 2nd parameter: Index
62 // 3rd parameter: Constant RAT ID
63 Intrinsic<[], [llvm_v4i32_ty, llvm_v4i32_ty, llvm_i32_ty], [IntrWillReturn]>,
64 GCCBuiltin<"__builtin_r600_rat_store_typed">;
65
66 def int_r600_recipsqrt_ieee : Intrinsic<
67 [llvm_anyfloat_ty], [LLVMMatchType<0>], [IntrNoMem, IntrSpeculatable, IntrWillReturn]
68 >;
69
70 def int_r600_recipsqrt_clamped : Intrinsic<
71 [llvm_anyfloat_ty], [LLVMMatchType<0>], [IntrNoMem, IntrSpeculatable, IntrWillReturn]
72 >;
73
74 def int_r600_cube : Intrinsic<
75 [llvm_v4f32_ty], [llvm_v4f32_ty], [IntrNoMem, IntrSpeculatable, IntrWillReturn]
76 >;
77
78 def int_r600_store_stream_output : Intrinsic<
79 [], [llvm_v4f32_ty, llvm_i32_ty, llvm_i32_ty, llvm_i32_ty], [IntrWillReturn]
80 >;
81
82 class TextureIntrinsicFloatInput : Intrinsic<[llvm_v4f32_ty], [
83 llvm_v4f32_ty, // Coord
84 llvm_i32_ty, // offset_x
85 llvm_i32_ty, // offset_y,
86 llvm_i32_ty, // offset_z,
87 llvm_i32_ty, // resource_id
88 llvm_i32_ty, // samplerid
89 llvm_i32_ty, // coord_type_x
90 llvm_i32_ty, // coord_type_y
91 llvm_i32_ty, // coord_type_z
92 llvm_i32_ty], // coord_type_w
93 [IntrNoMem, IntrWillReturn]
94 >;
95
96 class TextureIntrinsicInt32Input : Intrinsic<[llvm_v4i32_ty], [
97 llvm_v4i32_ty, // Coord
98 llvm_i32_ty, // offset_x
99 llvm_i32_ty, // offset_y,
100 llvm_i32_ty, // offset_z,
101 llvm_i32_ty, // resource_id
102 llvm_i32_ty, // samplerid
103 llvm_i32_ty, // coord_type_x
104 llvm_i32_ty, // coord_type_y
105 llvm_i32_ty, // coord_type_z
106 llvm_i32_ty], // coord_type_w
107 [IntrNoMem, IntrWillReturn]
108 >;
109
110 def int_r600_store_swizzle :
111 Intrinsic<[], [llvm_v4f32_ty, llvm_i32_ty, llvm_i32_ty], [IntrWillReturn]
112 >;
113
114 def int_r600_tex : TextureIntrinsicFloatInput;
115 def int_r600_texc : TextureIntrinsicFloatInput;
116 def int_r600_txl : TextureIntrinsicFloatInput;
117 def int_r600_txlc : TextureIntrinsicFloatInput;
118 def int_r600_txb : TextureIntrinsicFloatInput;
119 def int_r600_txbc : TextureIntrinsicFloatInput;
120 def int_r600_txf : TextureIntrinsicInt32Input;
121 def int_r600_txq : TextureIntrinsicInt32Input;
122 def int_r600_ddx : TextureIntrinsicFloatInput;
123 def int_r600_ddy : TextureIntrinsicFloatInput;
124
125 def int_r600_dot4 : Intrinsic<[llvm_float_ty],
126 [llvm_v4f32_ty, llvm_v4f32_ty], [IntrNoMem, IntrSpeculatable, IntrWillReturn]
127 >;
128
129 def int_r600_kill : Intrinsic<[], [llvm_float_ty], [IntrWillReturn]>;
130
131 } // End TargetPrefix = "r600"
132
133 let TargetPrefix = "amdgcn" in {
134
135 //===----------------------------------------------------------------------===//
136 // ABI Special Intrinsics
137 //===----------------------------------------------------------------------===//
138
139 defm int_amdgcn_workitem_id : AMDGPUReadPreloadRegisterIntrinsic_xyz;
140 defm int_amdgcn_workgroup_id : AMDGPUReadPreloadRegisterIntrinsic_xyz_named
141 <"__builtin_amdgcn_workgroup_id">;
142
143 def int_amdgcn_dispatch_ptr :
144 Intrinsic<[LLVMQualPointerType<llvm_i8_ty, 4>], [],
145 [Align<RetIndex, 4>, IntrNoMem, IntrSpeculatable, IntrWillReturn]>;
146
147 def int_amdgcn_queue_ptr :
148 GCCBuiltin<"__builtin_amdgcn_queue_ptr">,
149 Intrinsic<[LLVMQualPointerType<llvm_i8_ty, 4>], [],
150 [Align<RetIndex, 4>, IntrNoMem, IntrSpeculatable, IntrWillReturn]>;
151
152 def int_amdgcn_kernarg_segment_ptr :
153 GCCBuiltin<"__builtin_amdgcn_kernarg_segment_ptr">,
154 Intrinsic<[LLVMQualPointerType<llvm_i8_ty, 4>], [],
155 [Align<RetIndex, 4>, IntrNoMem, IntrSpeculatable, IntrWillReturn]>;
156
157 def int_amdgcn_implicitarg_ptr :
158 GCCBuiltin<"__builtin_amdgcn_implicitarg_ptr">,
159 Intrinsic<[LLVMQualPointerType<llvm_i8_ty, 4>], [],
160 [Align<RetIndex, 4>, IntrNoMem, IntrSpeculatable, IntrWillReturn]>;
161
162 def int_amdgcn_groupstaticsize :
163 GCCBuiltin<"__builtin_amdgcn_groupstaticsize">,
164 Intrinsic<[llvm_i32_ty], [], [IntrNoMem, IntrSpeculatable, IntrWillReturn]>;
165
166 def int_amdgcn_dispatch_id :
167 GCCBuiltin<"__builtin_amdgcn_dispatch_id">,
168 Intrinsic<[llvm_i64_ty], [], [IntrNoMem, IntrSpeculatable, IntrWillReturn]>;
169
170 def int_amdgcn_implicit_buffer_ptr :
171 GCCBuiltin<"__builtin_amdgcn_implicit_buffer_ptr">,
172 Intrinsic<[LLVMQualPointerType<llvm_i8_ty, 4>], [],
173 [Align<RetIndex, 4>, IntrNoMem, IntrSpeculatable, IntrWillReturn]>;
174
175 // Set EXEC to the 64-bit value given.
176 // This is always moved to the beginning of the basic block.
177 // FIXME: Should be mangled for wave size.
178 def int_amdgcn_init_exec : Intrinsic<[],
179 [llvm_i64_ty], // 64-bit literal constant
180 [IntrConvergent, ImmArg<ArgIndex<0>>]>;
181
182 // Set EXEC according to a thread count packed in an SGPR input:
183 // thread_count = (input >> bitoffset) & 0x7f;
184 // This is always moved to the beginning of the basic block.
185 // Note: only inreg arguments to the parent function are valid as
186 // inputs to this intrinsic, computed values cannot be used.
187 def int_amdgcn_init_exec_from_input : Intrinsic<[],
188 [llvm_i32_ty, // 32-bit SGPR input
189 llvm_i32_ty], // bit offset of the thread count
190 [IntrConvergent, ImmArg<ArgIndex<1>>]>;
191
192 def int_amdgcn_wavefrontsize :
193 GCCBuiltin<"__builtin_amdgcn_wavefrontsize">,
194 Intrinsic<[llvm_i32_ty], [], [IntrNoMem, IntrSpeculatable, IntrWillReturn]>;
195
196
197 //===----------------------------------------------------------------------===//
198 // Instruction Intrinsics
199 //===----------------------------------------------------------------------===//
200
201 // The first parameter is s_sendmsg immediate (i16),
202 // the second one is copied to m0
203 def int_amdgcn_s_sendmsg : GCCBuiltin<"__builtin_amdgcn_s_sendmsg">,
204 Intrinsic <[], [llvm_i32_ty, llvm_i32_ty],
205 [ImmArg<ArgIndex<0>>, IntrNoMem, IntrHasSideEffects]>;
206 def int_amdgcn_s_sendmsghalt : GCCBuiltin<"__builtin_amdgcn_s_sendmsghalt">,
207 Intrinsic <[], [llvm_i32_ty, llvm_i32_ty],
208 [ImmArg<ArgIndex<0>>, IntrNoMem, IntrHasSideEffects]>;
209
210 def int_amdgcn_s_barrier : GCCBuiltin<"__builtin_amdgcn_s_barrier">,
211 Intrinsic<[], [], [IntrNoMem, IntrHasSideEffects, IntrConvergent, IntrWillReturn]>;
212
213 def int_amdgcn_wave_barrier : GCCBuiltin<"__builtin_amdgcn_wave_barrier">,
214 Intrinsic<[], [], [IntrNoMem, IntrHasSideEffects, IntrConvergent, IntrWillReturn]>;
215
216 def int_amdgcn_s_waitcnt : GCCBuiltin<"__builtin_amdgcn_s_waitcnt">,
217 Intrinsic<[], [llvm_i32_ty], [ImmArg<ArgIndex<0>>, IntrNoMem, IntrHasSideEffects, IntrWillReturn]>;
218
219 def int_amdgcn_div_scale : Intrinsic<
220 // 1st parameter: Numerator
221 // 2nd parameter: Denominator
222 // 3rd parameter: Select quotient. Must equal Numerator or Denominator.
223 // (0 = Denominator, 1 = Numerator).
224 [llvm_anyfloat_ty, llvm_i1_ty],
225 [LLVMMatchType<0>, LLVMMatchType<0>, llvm_i1_ty],
226 [IntrNoMem, IntrSpeculatable, ImmArg<ArgIndex<2>>, IntrWillReturn]
227 >;
228
229 def int_amdgcn_div_fmas : Intrinsic<[llvm_anyfloat_ty],
230 [LLVMMatchType<0>, LLVMMatchType<0>, LLVMMatchType<0>, llvm_i1_ty],
231 [IntrNoMem, IntrSpeculatable, IntrWillReturn]
232 >;
233
234 def int_amdgcn_div_fixup : Intrinsic<[llvm_anyfloat_ty],
235 [LLVMMatchType<0>, LLVMMatchType<0>, LLVMMatchType<0>],
236 [IntrNoMem, IntrSpeculatable, IntrWillReturn]
237 >;
238
239 // Look Up 2.0 / pi src0 with segment select src1[4:0]
240 def int_amdgcn_trig_preop : Intrinsic<
241 [llvm_anyfloat_ty], [LLVMMatchType<0>, llvm_i32_ty],
242 [IntrNoMem, IntrSpeculatable, IntrWillReturn]
243 >;
244
245 def int_amdgcn_sin : Intrinsic<
246 [llvm_anyfloat_ty], [LLVMMatchType<0>],
247 [IntrNoMem, IntrSpeculatable, IntrWillReturn]
248 >;
249
250 def int_amdgcn_cos : Intrinsic<
251 [llvm_anyfloat_ty], [LLVMMatchType<0>], [IntrNoMem, IntrSpeculatable, IntrWillReturn]
252 >;
253
254 def int_amdgcn_log_clamp : Intrinsic<
255 [llvm_anyfloat_ty], [LLVMMatchType<0>], [IntrNoMem, IntrSpeculatable, IntrWillReturn]
256 >;
257
258 def int_amdgcn_fmul_legacy : GCCBuiltin<"__builtin_amdgcn_fmul_legacy">,
259 Intrinsic<[llvm_float_ty], [llvm_float_ty, llvm_float_ty],
260 [IntrNoMem, IntrSpeculatable, IntrWillReturn, Commutative]
261 >;
262
263 // Fused single-precision multiply-add with legacy behaviour for the multiply,
264 // which is that +/- 0.0 * anything (even NaN or infinity) is +0.0. This is
265 // intended for use on subtargets that have the v_fma_legacy_f32 and/or
266 // v_fmac_legacy_f32 instructions. (Note that v_fma_legacy_f16 is unrelated and
267 // has a completely different kind of legacy behaviour.)
268 def int_amdgcn_fma_legacy :
269 Intrinsic<[llvm_float_ty], [llvm_float_ty, llvm_float_ty, llvm_float_ty],
270 [IntrNoMem, IntrSpeculatable, IntrWillReturn, Commutative]
271 >;
272
273 def int_amdgcn_rcp : Intrinsic<
274 [llvm_anyfloat_ty], [LLVMMatchType<0>], [IntrNoMem, IntrSpeculatable, IntrWillReturn]
275 >;
276
277 def int_amdgcn_rcp_legacy : GCCBuiltin<"__builtin_amdgcn_rcp_legacy">,
278 Intrinsic<[llvm_float_ty], [llvm_float_ty],
279 [IntrNoMem, IntrSpeculatable, IntrWillReturn]
280 >;
281
282 def int_amdgcn_sqrt : Intrinsic<
283 [llvm_anyfloat_ty], [LLVMMatchType<0>], [IntrNoMem, IntrSpeculatable, IntrWillReturn]
284 >;
285
286 def int_amdgcn_rsq : Intrinsic<
287 [llvm_anyfloat_ty], [LLVMMatchType<0>], [IntrNoMem, IntrSpeculatable, IntrWillReturn]
288 >;
289
290 def int_amdgcn_rsq_legacy : GCCBuiltin<"__builtin_amdgcn_rsq_legacy">,
291 Intrinsic<
292 [llvm_float_ty], [llvm_float_ty], [IntrNoMem, IntrSpeculatable, IntrWillReturn]
293 >;
294
295 // out = 1.0 / sqrt(a) result clamped to +/- max_float.
296 def int_amdgcn_rsq_clamp : Intrinsic<
297 [llvm_anyfloat_ty], [LLVMMatchType<0>], [IntrNoMem, IntrSpeculatable, IntrWillReturn]>;
298
299 def int_amdgcn_ldexp : Intrinsic<
300 [llvm_anyfloat_ty], [LLVMMatchType<0>, llvm_i32_ty],
301 [IntrNoMem, IntrSpeculatable, IntrWillReturn]
302 >;
303
304 def int_amdgcn_frexp_mant : Intrinsic<
305 [llvm_anyfloat_ty], [LLVMMatchType<0>], [IntrNoMem, IntrSpeculatable, IntrWillReturn]
306 >;
307
308 def int_amdgcn_frexp_exp : Intrinsic<
309 [llvm_anyint_ty], [llvm_anyfloat_ty], [IntrNoMem, IntrSpeculatable, IntrWillReturn]
310 >;
311
312 // v_fract is buggy on SI/CI. It mishandles infinities, may return 1.0
313 // and always uses rtz, so is not suitable for implementing the OpenCL
314 // fract function. It should be ok on VI.
315 def int_amdgcn_fract : Intrinsic<
316 [llvm_anyfloat_ty], [LLVMMatchType<0>], [IntrNoMem, IntrSpeculatable, IntrWillReturn]
317 >;
318
319 def int_amdgcn_cvt_pkrtz : GCCBuiltin<"__builtin_amdgcn_cvt_pkrtz">,
320 Intrinsic<[llvm_v2f16_ty], [llvm_float_ty, llvm_float_ty],
321 [IntrNoMem, IntrSpeculatable, IntrWillReturn]
322 >;
323
324 def int_amdgcn_cvt_pknorm_i16 :
325 GCCBuiltin<"__builtin_amdgcn_cvt_pknorm_i16">,
326 Intrinsic<[llvm_v2i16_ty], [llvm_float_ty, llvm_float_ty],
327 [IntrNoMem, IntrSpeculatable, IntrWillReturn]
328 >;
329
330 def int_amdgcn_cvt_pknorm_u16 :
331 GCCBuiltin<"__builtin_amdgcn_cvt_pknorm_u16">,
332 Intrinsic<[llvm_v2i16_ty], [llvm_float_ty, llvm_float_ty],
333 [IntrNoMem, IntrSpeculatable, IntrWillReturn]
334 >;
335
336 def int_amdgcn_cvt_pk_i16 :
337 GCCBuiltin<"__builtin_amdgcn_cvt_pk_i16">,
338 Intrinsic<
339 [llvm_v2i16_ty], [llvm_i32_ty, llvm_i32_ty],
340 [IntrNoMem, IntrSpeculatable, IntrWillReturn]
341 >;
342
343 def int_amdgcn_cvt_pk_u16 : GCCBuiltin<"__builtin_amdgcn_cvt_pk_u16">,
344 Intrinsic<[llvm_v2i16_ty], [llvm_i32_ty, llvm_i32_ty],
345 [IntrNoMem, IntrSpeculatable, IntrWillReturn]
346 >;
347
348 def int_amdgcn_class : Intrinsic<
349 [llvm_i1_ty], [llvm_anyfloat_ty, llvm_i32_ty],
350 [IntrNoMem, IntrSpeculatable, IntrWillReturn]
351 >;
352
353 def int_amdgcn_fmed3 : GCCBuiltin<"__builtin_amdgcn_fmed3">,
354 Intrinsic<[llvm_anyfloat_ty],
355 [LLVMMatchType<0>, LLVMMatchType<0>, LLVMMatchType<0>],
356 [IntrNoMem, IntrSpeculatable, IntrWillReturn]
357 >;
358
359 def int_amdgcn_cubeid : GCCBuiltin<"__builtin_amdgcn_cubeid">,
360 Intrinsic<[llvm_float_ty],
361 [llvm_float_ty, llvm_float_ty, llvm_float_ty],
362 [IntrNoMem, IntrSpeculatable, IntrWillReturn]
363 >;
364
365 def int_amdgcn_cubema : GCCBuiltin<"__builtin_amdgcn_cubema">,
366 Intrinsic<[llvm_float_ty],
367 [llvm_float_ty, llvm_float_ty, llvm_float_ty],
368 [IntrNoMem, IntrSpeculatable, IntrWillReturn]
369 >;
370
371 def int_amdgcn_cubesc : GCCBuiltin<"__builtin_amdgcn_cubesc">,
372 Intrinsic<[llvm_float_ty],
373 [llvm_float_ty, llvm_float_ty, llvm_float_ty],
374 [IntrNoMem, IntrSpeculatable, IntrWillReturn]
375 >;
376
377 def int_amdgcn_cubetc : GCCBuiltin<"__builtin_amdgcn_cubetc">,
378 Intrinsic<[llvm_float_ty],
379 [llvm_float_ty, llvm_float_ty, llvm_float_ty],
380 [IntrNoMem, IntrSpeculatable, IntrWillReturn]
381 >;
382
383 // v_ffbh_i32, as opposed to v_ffbh_u32. For v_ffbh_u32, llvm.ctlz
384 // should be used.
385 def int_amdgcn_sffbh :
386 Intrinsic<[llvm_anyint_ty], [LLVMMatchType<0>],
387 [IntrNoMem, IntrSpeculatable, IntrWillReturn]
388 >;
389
390 // v_mad_f32|f16/v_mac_f32|f16, selected regardless of denorm support.
391 def int_amdgcn_fmad_ftz :
392 Intrinsic<[llvm_anyfloat_ty],
393 [LLVMMatchType<0>, LLVMMatchType<0>, LLVMMatchType<0>],
394 [IntrNoMem, IntrSpeculatable, IntrWillReturn]
395 >;
396
397 // Fields should mirror atomicrmw
398 class AMDGPUAtomicIncIntrin : Intrinsic<[llvm_anyint_ty],
399 [llvm_anyptr_ty,
400 LLVMMatchType<0>,
401 llvm_i32_ty, // ordering
402 llvm_i32_ty, // scope
403 llvm_i1_ty], // isVolatile
404 [IntrArgMemOnly, IntrWillReturn, NoCapture<ArgIndex<0>>,
405 ImmArg<ArgIndex<2>>, ImmArg<ArgIndex<3>>, ImmArg<ArgIndex<4>>], "",
406 [SDNPMemOperand]
407 >;
408
409 def int_amdgcn_atomic_inc : AMDGPUAtomicIncIntrin;
410 def int_amdgcn_atomic_dec : AMDGPUAtomicIncIntrin;
411
412 class AMDGPULDSIntrin :
413 Intrinsic<[llvm_any_ty],
414 [LLVMQualPointerType<LLVMMatchType<0>, 3>,
415 LLVMMatchType<0>,
416 llvm_i32_ty, // ordering
417 llvm_i32_ty, // scope
418 llvm_i1_ty], // isVolatile
419 [IntrArgMemOnly, IntrWillReturn, NoCapture<ArgIndex<0>>,
420 ImmArg<ArgIndex<2>>, ImmArg<ArgIndex<3>>, ImmArg<ArgIndex<4>>]
421 >;
422
423 // FIXME: The m0 argument should be moved after the normal arguments
424 class AMDGPUDSOrderedIntrinsic : Intrinsic<
425 [llvm_i32_ty],
426 // M0 = {hi16:address, lo16:waveID}. Allow passing M0 as a pointer, so that
427 // the bit packing can be optimized at the IR level.
428 [LLVMQualPointerType<llvm_i32_ty, 2>, // IntToPtr(M0)
429 llvm_i32_ty, // value to add or swap
430 llvm_i32_ty, // ordering
431 llvm_i32_ty, // scope
432 llvm_i1_ty, // isVolatile
433 llvm_i32_ty, // ordered count index (OA index), also added to the address
434 // gfx10: bits 24-27 indicate the number of active threads/dwords
435 llvm_i1_ty, // wave release, usually set to 1
436 llvm_i1_ty], // wave done, set to 1 for the last ordered instruction
437 [IntrWillReturn, NoCapture<ArgIndex<0>>,
438 ImmArg<ArgIndex<2>>, ImmArg<ArgIndex<3>>, ImmArg<ArgIndex<4>>,
439 ImmArg<ArgIndex<5>>, ImmArg<ArgIndex<6>>, ImmArg<ArgIndex<7>>
440 ]
441 >;
442
443 class AMDGPUDSAppendConsumedIntrinsic : Intrinsic<
444 [llvm_i32_ty],
445 [llvm_anyptr_ty, // LDS or GDS ptr
446 llvm_i1_ty], // isVolatile
447 [IntrConvergent, IntrWillReturn, IntrArgMemOnly,
448 NoCapture<ArgIndex<0>>, ImmArg<ArgIndex<1>>],
449 "",
450 [SDNPMemOperand]
451 >;
452
453 def int_amdgcn_ds_ordered_add : AMDGPUDSOrderedIntrinsic;
454 def int_amdgcn_ds_ordered_swap : AMDGPUDSOrderedIntrinsic;
455
456 // The pointer argument is assumed to be dynamically uniform if a VGPR.
457 def int_amdgcn_ds_append : AMDGPUDSAppendConsumedIntrinsic;
458 def int_amdgcn_ds_consume : AMDGPUDSAppendConsumedIntrinsic;
459
460 def int_amdgcn_ds_fadd : AMDGPULDSIntrin;
461 def int_amdgcn_ds_fmin : AMDGPULDSIntrin;
462 def int_amdgcn_ds_fmax : AMDGPULDSIntrin;
463
464 } // TargetPrefix = "amdgcn"
465
466 // New-style image intrinsics
467
468 //////////////////////////////////////////////////////////////////////////
469 // Dimension-aware image intrinsics framework
470 //////////////////////////////////////////////////////////////////////////
471
472 // Helper class to represent (type, name) combinations of arguments. The
473 // argument names are explanatory and used as DAG operand names for codegen
474 // pattern matching.
475 class AMDGPUArg<LLVMType ty, string name> {
476 LLVMType Type = ty;
477 string Name = name;
478 }
479
480 // Return [AMDGPUArg<basety, names[0]>, AMDGPUArg<LLVMMatchType<0>, names[1]>, ...]
481 class makeArgList<list<string> names, LLVMType basety> {
482 list<AMDGPUArg> ret =
483 !listconcat([AMDGPUArg<basety, names[0]>],
484 !foreach(name, !tail(names), AMDGPUArg<LLVMMatchType<0>, name>));
485 }
486
487 // Return arglist, with LLVMMatchType's references shifted by 'shift'.
488 class arglistmatchshift<list<AMDGPUArg> arglist, int shift> {
489 list<AMDGPUArg> ret =
490 !foreach(arg, arglist,
491 !if(!isa<LLVMMatchType>(arg.Type),
492 AMDGPUArg<LLVMMatchType<!add(!cast<LLVMMatchType>(arg.Type).Number, shift)>,
493 arg.Name>,
494 arg));
495 }
496
497 // Return the concatenation of the given arglists. LLVMMatchType's are adjusted
498 // accordingly, and shifted by an additional 'shift'.
499 class arglistconcat<list<list<AMDGPUArg>> arglists, int shift = 0> {
500 list<AMDGPUArg> ret =
501 !foldl([]<AMDGPUArg>, arglists, lhs, rhs,
502 !listconcat(
503 lhs,
504 arglistmatchshift<rhs,
505 !add(shift, !foldl(0, lhs, a, b,
506 !add(a, b.Type.isAny)))>.ret));
507 }
508
509 // Represent texture/image types / dimensionality.
510 class AMDGPUDimProps<bits<3> enc, string name, string asmsuffix,
511 list<string> coord_names, list<string> slice_names,
512 bit msaa = 0> {
513 AMDGPUDimProps Dim = !cast<AMDGPUDimProps>(NAME);
514 string Name = name; // e.g. "2darraymsaa"
515 string AsmSuffix = asmsuffix; // e.g. 2D_MSAA_ARRAY (used in assembly strings)
516 bits<3> Encoding = enc;
517 bit DA = 0; // DA bit in MIMG encoding
518 bit MSAA = msaa;
519
520 list<AMDGPUArg> CoordSliceArgs =
521 makeArgList<!listconcat(coord_names, slice_names), llvm_anyfloat_ty>.ret;
522 list<AMDGPUArg> CoordSliceIntArgs =
523 makeArgList<!listconcat(coord_names, slice_names), llvm_anyint_ty>.ret;
524 list<AMDGPUArg> GradientArgs =
525 makeArgList<!listconcat(!foreach(name, coord_names, "d" # name # "dh"),
526 !foreach(name, coord_names, "d" # name # "dv")),
527 llvm_anyfloat_ty>.ret;
528
529 bits<8> NumCoords = !size(CoordSliceArgs);
530 bits<8> NumGradients = !size(GradientArgs);
531 }
532
533 def AMDGPUDim1D : AMDGPUDimProps<0x0, "1d", "1D", ["s"], []>;
534 def AMDGPUDim2D : AMDGPUDimProps<0x1, "2d", "2D", ["s", "t"], []>;
535 def AMDGPUDim3D : AMDGPUDimProps<0x2, "3d", "3D", ["s", "t", "r"], []>;
536 let DA = 1 in {
537 def AMDGPUDimCube : AMDGPUDimProps<0x3, "cube", "CUBE", ["s", "t"], ["face"]>;
538 def AMDGPUDim1DArray : AMDGPUDimProps<0x4, "1darray", "1D_ARRAY", ["s"], ["slice"]>;
539 def AMDGPUDim2DArray : AMDGPUDimProps<0x5, "2darray", "2D_ARRAY", ["s", "t"], ["slice"]>;
540 }
541 def AMDGPUDim2DMsaa : AMDGPUDimProps<0x6, "2dmsaa", "2D_MSAA", ["s", "t"], ["fragid"], 1>;
542 let DA = 1 in {
543 def AMDGPUDim2DArrayMsaa : AMDGPUDimProps<0x7, "2darraymsaa", "2D_MSAA_ARRAY", ["s", "t"], ["slice", "fragid"], 1>;
544 }
545
546 def AMDGPUDims {
547 list<AMDGPUDimProps> NoMsaa = [AMDGPUDim1D, AMDGPUDim2D, AMDGPUDim3D,
548 AMDGPUDimCube, AMDGPUDim1DArray,
549 AMDGPUDim2DArray];
550 list<AMDGPUDimProps> Msaa = [AMDGPUDim2DMsaa, AMDGPUDim2DArrayMsaa];
551 list<AMDGPUDimProps> All = !listconcat(NoMsaa, Msaa);
552 }
553
554 // Represent sample variants, i.e. _C, _O, _B, ... and combinations thereof.
555 class AMDGPUSampleVariant<string ucmod, string lcmod, list<AMDGPUArg> extra_addr> {
556 string UpperCaseMod = ucmod;
557 string LowerCaseMod = lcmod;
558
559 // {offset} {bias} {z-compare}
560 list<AMDGPUArg> ExtraAddrArgs = extra_addr;
561 bit Offset = false;
562 bit Bias = false;
563 bit ZCompare = false;
564 bit Gradients = false;
565
566 // Name of the {lod} or {clamp} argument that is appended to the coordinates,
567 // if any.
568 string LodOrClamp = "";
569 }
570
571 // AMDGPUSampleVariants: all variants supported by IMAGE_SAMPLE
572 // AMDGPUSampleVariantsNoGradients: variants supported by IMAGE_GATHER4
573 defset list<AMDGPUSampleVariant> AMDGPUSampleVariants = {
574 multiclass AMDGPUSampleHelper_Offset<string ucmod, string lcmod,
575 list<AMDGPUArg> extra_addr> {
576 def NAME#lcmod : AMDGPUSampleVariant<ucmod, lcmod, extra_addr>;
577 let Offset = true in
578 def NAME#lcmod#_o : AMDGPUSampleVariant<
579 ucmod#"_O", lcmod#"_o", !listconcat([AMDGPUArg<llvm_i32_ty, "offset">], extra_addr)>;
580 }
581
582 multiclass AMDGPUSampleHelper_Compare<string ucmod, string lcmod,
583 list<AMDGPUArg> extra_addr> {
584 defm NAME : AMDGPUSampleHelper_Offset<ucmod, lcmod, extra_addr>;
585 let ZCompare = true in
586 defm NAME : AMDGPUSampleHelper_Offset<
587 "_C"#ucmod, "_c"#lcmod, !listconcat(extra_addr, [AMDGPUArg<llvm_float_ty, "zcompare">])>;
588 }
589
590 multiclass AMDGPUSampleHelper_Clamp<string ucmod, string lcmod,
591 list<AMDGPUArg> extra_addr> {
592 defm NAME : AMDGPUSampleHelper_Compare<ucmod, lcmod, extra_addr>;
593 let LodOrClamp = "clamp" in
594 defm NAME : AMDGPUSampleHelper_Compare<ucmod#"_CL", lcmod#"_cl", extra_addr>;
595 }
596
597 defset list<AMDGPUSampleVariant> AMDGPUSampleVariantsNoGradients = {
598 defm AMDGPUSample : AMDGPUSampleHelper_Clamp<"", "", []>;
599 let Bias = true in
600 defm AMDGPUSample : AMDGPUSampleHelper_Clamp<
601 "_B", "_b", [AMDGPUArg<llvm_anyfloat_ty, "bias">]>;
602 let LodOrClamp = "lod" in
603 defm AMDGPUSample : AMDGPUSampleHelper_Compare<"_L", "_l", []>;
604 defm AMDGPUSample : AMDGPUSampleHelper_Compare<"_LZ", "_lz", []>;
605 }
606
607 let Gradients = true in {
608 defm AMDGPUSample : AMDGPUSampleHelper_Clamp<"_D", "_d", []>;
609 defm AMDGPUSample : AMDGPUSampleHelper_Clamp<"_CD", "_cd", []>;
610 }
611 }
612
613 // Helper class to capture the profile of a dimension-aware image intrinsic.
614 // This information is used to generate the intrinsic's type and to inform
615 // codegen pattern matching.
616 class AMDGPUDimProfile<string opmod,
617 AMDGPUDimProps dim> {
618 AMDGPUDimProps Dim = dim;
619 string OpMod = opmod; // the corresponding instruction is named IMAGE_OpMod
620
621 // These are intended to be overwritten by subclasses
622 bit IsSample = false;
623 bit IsAtomic = false;
624 list<LLVMType> RetTypes = [];
625 list<AMDGPUArg> DataArgs = [];
626 list<AMDGPUArg> ExtraAddrArgs = [];
627 bit Offset = false;
628 bit Bias = false;
629 bit ZCompare = false;
630 bit Gradients = false;
631 string LodClampMip = "";
632
633 int NumRetAndDataAnyTypes =
634 !foldl(0, !listconcat(RetTypes, !foreach(arg, DataArgs, arg.Type)), a, b,
635 !add(a, b.isAny));
636
637 list<AMDGPUArg> AddrArgs =
638 arglistconcat<[ExtraAddrArgs,
639 !if(Gradients, dim.GradientArgs, []),
640 !listconcat(!if(IsSample, dim.CoordSliceArgs, dim.CoordSliceIntArgs),
641 !if(!empty(LodClampMip),
642 []<AMDGPUArg>,
643 [AMDGPUArg<LLVMMatchType<0>, LodClampMip>]))],
644 NumRetAndDataAnyTypes>.ret;
645 list<LLVMType> AddrTypes = !foreach(arg, AddrArgs, arg.Type);
646 list<AMDGPUArg> AddrDefaultArgs =
647 !foreach(arg, AddrArgs,
648 AMDGPUArg<!if(!or(arg.Type.isAny, !isa<LLVMMatchType>(arg.Type)),
649 !if(IsSample, llvm_float_ty, llvm_i32_ty), arg.Type),
650 arg.Name>);
651 list<AMDGPUArg> AddrA16Args =
652 !foreach(arg, AddrArgs,
653 AMDGPUArg<!if(!or(arg.Type.isAny, !isa<LLVMMatchType>(arg.Type)),
654 !if(IsSample, llvm_half_ty, llvm_i16_ty), arg.Type),
655 arg.Name>);
656 }
657
658 class AMDGPUDimProfileCopy<AMDGPUDimProfile base> : AMDGPUDimProfile<base.OpMod, base.Dim> {
659 let IsSample = base.IsSample;
660 let IsAtomic = base.IsAtomic;
661 let RetTypes = base.RetTypes;
662 let DataArgs = base.DataArgs;
663 let ExtraAddrArgs = base.ExtraAddrArgs;
664 let Offset = base.Offset;
665 let Bias = base.Bias;
666 let ZCompare = base.ZCompare;
667 let Gradients = base.Gradients;
668 let LodClampMip = base.LodClampMip;
669 }
670
671 class AMDGPUDimSampleProfile<string opmod,
672 AMDGPUDimProps dim,
673 AMDGPUSampleVariant sample> : AMDGPUDimProfile<opmod, dim> {
674 let IsSample = true;
675 let RetTypes = [llvm_any_ty];
676 let ExtraAddrArgs = sample.ExtraAddrArgs;
677 let Offset = sample.Offset;
678 let Bias = sample.Bias;
679 let ZCompare = sample.ZCompare;
680 let Gradients = sample.Gradients;
681 let LodClampMip = sample.LodOrClamp;
682 }
683
684 class AMDGPUDimNoSampleProfile<string opmod,
685 AMDGPUDimProps dim,
686 list<LLVMType> retty,
687 list<AMDGPUArg> dataargs,
688 bit Mip = false> : AMDGPUDimProfile<opmod, dim> {
689 let RetTypes = retty;
690 let DataArgs = dataargs;
691 let LodClampMip = !if(Mip, "mip", "");
692 }
693
694 class AMDGPUDimAtomicProfile<string opmod,
695 AMDGPUDimProps dim,
696 list<AMDGPUArg> dataargs> : AMDGPUDimProfile<opmod, dim> {
697 let RetTypes = [llvm_anyint_ty];
698 let DataArgs = dataargs;
699 let IsAtomic = true;
700 }
701
702 class AMDGPUDimAtomicFloatProfile<string opmod, AMDGPUDimProps dim,
703 list<AMDGPUArg> dataargs>
704 : AMDGPUDimAtomicProfile<opmod, dim, dataargs> {
705 let RetTypes = [llvm_anyfloat_ty];
706 }
707
708 class AMDGPUDimGetResInfoProfile<AMDGPUDimProps dim>
709 : AMDGPUDimProfile<"GET_RESINFO", dim> {
710 let RetTypes = [llvm_anyfloat_ty];
711 let DataArgs = [];
712 let AddrArgs = [AMDGPUArg<llvm_anyint_ty, "mip">];
713 let LodClampMip = "mip";
714 }
715
716 // Helper class for figuring out image intrinsic argument indexes.
717 class AMDGPUImageDimIntrinsicEval<AMDGPUDimProfile P_> {
718 int NumDataArgs = !size(P_.DataArgs);
719 int NumDmaskArgs = !not(P_.IsAtomic);
720 int NumOffsetArgs = !if(P_.Offset, 1, 0);
721 int NumBiasArgs = !if(P_.Bias, 1, 0);
722 int NumZCompareArgs = !if(P_.ZCompare, 1, 0);
723 int NumExtraAddrArgs = !add(NumOffsetArgs, NumBiasArgs, NumZCompareArgs);
724 int NumVAddrArgs = !size(P_.AddrArgs);
725 int NumGradientArgs = !if(P_.Gradients, !size(P_.Dim.GradientArgs), 0);
726 int NumCoordArgs = !if(P_.IsSample, !size(P_.Dim.CoordSliceArgs), !size(P_.Dim.CoordSliceIntArgs));
727 int NumRSrcArgs = 1;
728 int NumSampArgs = !if(P_.IsSample, 2, 0);
729 int DmaskArgIndex = NumDataArgs;
730 int VAddrArgIndex = !add(DmaskArgIndex, NumDmaskArgs);
731 int OffsetArgIndex = VAddrArgIndex;
732 int BiasArgIndex = !add(VAddrArgIndex, NumOffsetArgs);
733 int ZCompareArgIndex = !add(BiasArgIndex, NumBiasArgs);
734 int GradientArgIndex = !add(VAddrArgIndex, NumExtraAddrArgs);
735 int CoordArgIndex = !add(GradientArgIndex, NumGradientArgs);
736 int LodArgIndex = !add(VAddrArgIndex, NumVAddrArgs, -1);
737 int MipArgIndex = LodArgIndex;
738 int RsrcArgIndex = !add(VAddrArgIndex, NumVAddrArgs);
739 int SampArgIndex = !add(RsrcArgIndex, NumRSrcArgs);
740 int UnormArgIndex = !add(SampArgIndex, 1);
741 int TexFailCtrlArgIndex = !add(SampArgIndex, NumSampArgs);
742 int CachePolicyArgIndex = !add(TexFailCtrlArgIndex, 1);
743 }
744
745 // All dimension-aware intrinsics are derived from this class.
746 class AMDGPUImageDimIntrinsic<AMDGPUDimProfile P_,
747 list<IntrinsicProperty> props,
748 list<SDNodeProperty> sdnodeprops> : Intrinsic<
749 P_.RetTypes, // vdata(VGPR) -- for load/atomic-with-return
750 !listconcat(
751 !foreach(arg, P_.DataArgs, arg.Type), // vdata(VGPR) -- for store/atomic
752 !if(P_.IsAtomic, [], [llvm_i32_ty]), // dmask(imm)
753 P_.AddrTypes, // vaddr(VGPR)
754 [llvm_v8i32_ty], // rsrc(SGPR)
755 !if(P_.IsSample, [llvm_v4i32_ty, // samp(SGPR)
756 llvm_i1_ty], []), // unorm(imm)
757 [llvm_i32_ty, // texfailctrl(imm; bit 0 = tfe, bit 1 = lwe)
758 llvm_i32_ty]), // cachepolicy(imm; bit 0 = glc, bit 1 = slc, bit 2 = dlc)
759
760 !listconcat(props,
761 !if(P_.IsAtomic, [], [ImmArg<ArgIndex<AMDGPUImageDimIntrinsicEval<P_>.DmaskArgIndex>>]),
762 !if(P_.IsSample, [ImmArg<ArgIndex<AMDGPUImageDimIntrinsicEval<P_>.UnormArgIndex>>], []),
763 [IntrWillReturn],
764 [ImmArg<ArgIndex<AMDGPUImageDimIntrinsicEval<P_>.TexFailCtrlArgIndex>>,
765 ImmArg<ArgIndex<AMDGPUImageDimIntrinsicEval<P_>.CachePolicyArgIndex>>]),
766
767
768 "", sdnodeprops>,
769 AMDGPURsrcIntrinsic<!add(!size(P_.DataArgs), !size(P_.AddrTypes),
770 !if(P_.IsAtomic, 0, 1)), 1> {
771 AMDGPUDimProfile P = P_;
772
773 AMDGPUImageDimIntrinsic Intr = !cast<AMDGPUImageDimIntrinsic>(NAME);
774
775 let TargetPrefix = "amdgcn";
776 }
777
778 // Marker class for intrinsics with a DMask that determines the returned
779 // channels.
780 class AMDGPUImageDMaskIntrinsic;
781
782 defset list<AMDGPUImageDimIntrinsic> AMDGPUImageDimIntrinsics = {
783
784 //////////////////////////////////////////////////////////////////////////
785 // Load and store intrinsics
786 //////////////////////////////////////////////////////////////////////////
787 multiclass AMDGPUImageDimIntrinsicsNoMsaa<string opmod,
788 list<LLVMType> retty,
789 list<AMDGPUArg> dataargs,
790 list<IntrinsicProperty> props,
791 list<SDNodeProperty> sdnodeprops,
792 bit Mip = false> {
793 foreach dim = AMDGPUDims.NoMsaa in {
794 def !strconcat(NAME, "_", dim.Name)
795 : AMDGPUImageDimIntrinsic<
796 AMDGPUDimNoSampleProfile<opmod, dim, retty, dataargs, Mip>,
797 props, sdnodeprops>;
798 }
799 }
800
801 multiclass AMDGPUImageDimIntrinsicsAll<string opmod,
802 list<LLVMType> retty,
803 list<AMDGPUArg> dataargs,
804 list<IntrinsicProperty> props,
805 list<SDNodeProperty> sdnodeprops,
806 bit Mip = false> {
807 foreach dim = AMDGPUDims.All in {
808 def !strconcat(NAME, "_", dim.Name)
809 : AMDGPUImageDimIntrinsic<
810 AMDGPUDimNoSampleProfile<opmod, dim, retty, dataargs, Mip>,
811 props, sdnodeprops>;
812 }
813 }
814
815 defm int_amdgcn_image_load
816 : AMDGPUImageDimIntrinsicsAll<"LOAD", [llvm_any_ty], [], [IntrReadMem],
817 [SDNPMemOperand]>,
818 AMDGPUImageDMaskIntrinsic;
819 defm int_amdgcn_image_load_mip
820 : AMDGPUImageDimIntrinsicsNoMsaa<"LOAD_MIP", [llvm_any_ty], [],
821 [IntrReadMem, IntrWillReturn], [SDNPMemOperand], 1>,
822 AMDGPUImageDMaskIntrinsic;
823
824 defm int_amdgcn_image_store : AMDGPUImageDimIntrinsicsAll<
825 "STORE", [], [AMDGPUArg<llvm_anyfloat_ty, "vdata">],
826 [IntrWriteMem, IntrWillReturn], [SDNPMemOperand]>;
827 defm int_amdgcn_image_store_mip : AMDGPUImageDimIntrinsicsNoMsaa<
828 "STORE_MIP", [], [AMDGPUArg<llvm_anyfloat_ty, "vdata">],
829 [IntrWriteMem, IntrWillReturn], [SDNPMemOperand], 1>;
830
831 //////////////////////////////////////////////////////////////////////////
832 // MSAA intrinsics
833 //////////////////////////////////////////////////////////////////////////
834 foreach dim = AMDGPUDims.Msaa in {
835 def int_amdgcn_image_msaa_load_x # _ # dim.Name:
836 AMDGPUImageDimIntrinsic<
837 AMDGPUDimNoSampleProfile<"MSAA_LOAD_X", dim, [llvm_any_ty], []>,
838 [IntrReadMem], [SDNPMemOperand]>;
839 }
840
841 //////////////////////////////////////////////////////////////////////////
842 // sample and getlod intrinsics
843 //////////////////////////////////////////////////////////////////////////
844 multiclass AMDGPUImageDimSampleDims<string opmod,
845 AMDGPUSampleVariant sample,
846 bit NoMem = false> {
847 foreach dim = AMDGPUDims.NoMsaa in {
848 def !strconcat(NAME, "_", dim.Name) : AMDGPUImageDimIntrinsic<
849 AMDGPUDimSampleProfile<opmod, dim, sample>,
850 !if(NoMem, [IntrNoMem], [IntrReadMem]),
851 !if(NoMem, [], [SDNPMemOperand])>;
852 }
853 }
854
855 foreach sample = AMDGPUSampleVariants in {
856 defm int_amdgcn_image_sample # sample.LowerCaseMod
857 : AMDGPUImageDimSampleDims<"SAMPLE" # sample.UpperCaseMod, sample>,
858 AMDGPUImageDMaskIntrinsic;
859 }
860
861 defm int_amdgcn_image_getlod
862 : AMDGPUImageDimSampleDims<"GET_LOD", AMDGPUSample, 1>,
863 AMDGPUImageDMaskIntrinsic;
864
865 //////////////////////////////////////////////////////////////////////////
866 // getresinfo intrinsics
867 //////////////////////////////////////////////////////////////////////////
868 foreach dim = AMDGPUDims.All in {
869 def !strconcat("int_amdgcn_image_getresinfo_", dim.Name)
870 : AMDGPUImageDimIntrinsic<AMDGPUDimGetResInfoProfile<dim>, [IntrNoMem], []>,
871 AMDGPUImageDMaskIntrinsic;
872 }
873
874 //////////////////////////////////////////////////////////////////////////
875 // gather4 intrinsics
876 //////////////////////////////////////////////////////////////////////////
877 foreach sample = AMDGPUSampleVariantsNoGradients in {
878 foreach dim = [AMDGPUDim2D, AMDGPUDimCube, AMDGPUDim2DArray] in {
879 def int_amdgcn_image_gather4 # sample.LowerCaseMod # _ # dim.Name:
880 AMDGPUImageDimIntrinsic<
881 AMDGPUDimSampleProfile<"GATHER4" # sample.UpperCaseMod, dim, sample>,
882 [IntrReadMem], [SDNPMemOperand]>;
883 }
884 }
885 }
886
887 //////////////////////////////////////////////////////////////////////////
888 // atomic intrinsics
889 //////////////////////////////////////////////////////////////////////////
890 defset list<AMDGPUImageDimIntrinsic> AMDGPUImageDimAtomicIntrinsics = {
891 multiclass AMDGPUImageDimAtomicX<string opmod, list<AMDGPUArg> dataargs,
892 int isFloat = 0> {
893 foreach dim = AMDGPUDims.All in {
894 def !strconcat(NAME, "_", dim.Name): AMDGPUImageDimIntrinsic<
895 !if (isFloat, AMDGPUDimAtomicFloatProfile<opmod, dim, dataargs>,
896 AMDGPUDimAtomicProfile<opmod, dim, dataargs>),
897 [], [SDNPMemOperand]>;
898 }
899 }
900
901 multiclass AMDGPUImageDimAtomic<string opmod, int isFloat = 0> {
902 defm ""
903 : AMDGPUImageDimAtomicX<opmod, [AMDGPUArg<LLVMMatchType<0>, "vdata">],
904 isFloat>;
905 }
906
907 multiclass AMDGPUImageDimFloatAtomic<string opmod> {
908 defm "" : AMDGPUImageDimAtomic<opmod, 1 /*isFloat*/>;
909 }
910
911 defm int_amdgcn_image_atomic_swap : AMDGPUImageDimAtomic<"ATOMIC_SWAP">;
912 defm int_amdgcn_image_atomic_add : AMDGPUImageDimAtomic<"ATOMIC_ADD">;
913 defm int_amdgcn_image_atomic_sub : AMDGPUImageDimAtomic<"ATOMIC_SUB">;
914 defm int_amdgcn_image_atomic_smin : AMDGPUImageDimAtomic<"ATOMIC_SMIN">;
915 defm int_amdgcn_image_atomic_umin : AMDGPUImageDimAtomic<"ATOMIC_UMIN">;
916 defm int_amdgcn_image_atomic_fmin : AMDGPUImageDimFloatAtomic<"ATOMIC_FMIN">;
917 defm int_amdgcn_image_atomic_smax : AMDGPUImageDimAtomic<"ATOMIC_SMAX">;
918 defm int_amdgcn_image_atomic_umax : AMDGPUImageDimAtomic<"ATOMIC_UMAX">;
919 defm int_amdgcn_image_atomic_fmax : AMDGPUImageDimFloatAtomic<"ATOMIC_FMAX">;
920 defm int_amdgcn_image_atomic_and : AMDGPUImageDimAtomic<"ATOMIC_AND">;
921 defm int_amdgcn_image_atomic_or : AMDGPUImageDimAtomic<"ATOMIC_OR">;
922 defm int_amdgcn_image_atomic_xor : AMDGPUImageDimAtomic<"ATOMIC_XOR">;
923 defm int_amdgcn_image_atomic_inc : AMDGPUImageDimAtomic<"ATOMIC_INC">;
924 defm int_amdgcn_image_atomic_dec : AMDGPUImageDimAtomic<"ATOMIC_DEC">;
925
926 defm int_amdgcn_image_atomic_cmpswap :
927 AMDGPUImageDimAtomicX<"ATOMIC_CMPSWAP", [AMDGPUArg<LLVMMatchType<0>, "src">,
928 AMDGPUArg<LLVMMatchType<0>, "cmp">]>;
929 }
930
931 //////////////////////////////////////////////////////////////////////////
932 // Buffer intrinsics
933 //////////////////////////////////////////////////////////////////////////
934
935 let TargetPrefix = "amdgcn" in {
936
937 defset list<AMDGPURsrcIntrinsic> AMDGPUBufferIntrinsics = {
938
939 class AMDGPUBufferLoad<LLVMType data_ty = llvm_any_ty> : Intrinsic <
940 [data_ty],
941 [llvm_v4i32_ty, // rsrc(SGPR)
942 llvm_i32_ty, // vindex(VGPR)
943 llvm_i32_ty, // offset(SGPR/VGPR/imm)
944 llvm_i1_ty, // glc(imm)
945 llvm_i1_ty], // slc(imm)
946 [IntrReadMem, IntrWillReturn,
947 ImmArg<ArgIndex<3>>, ImmArg<ArgIndex<4>>], "", [SDNPMemOperand]>,
948 AMDGPURsrcIntrinsic<0>;
949 def int_amdgcn_buffer_load_format : AMDGPUBufferLoad<llvm_anyfloat_ty>;
950 def int_amdgcn_buffer_load : AMDGPUBufferLoad;
951
952 def int_amdgcn_s_buffer_load : Intrinsic <
953 [llvm_any_ty],
954 [llvm_v4i32_ty, // rsrc(SGPR)
955 llvm_i32_ty, // byte offset(SGPR/imm)
956 llvm_i32_ty], // cachepolicy(imm; bit 0 = glc, bit 2 = dlc)
957 [IntrNoMem, IntrWillReturn, ImmArg<ArgIndex<2>>]>,
958 AMDGPURsrcIntrinsic<0>;
959
960 class AMDGPUBufferStore<LLVMType data_ty = llvm_any_ty> : Intrinsic <
961 [],
962 [data_ty, // vdata(VGPR)
963 llvm_v4i32_ty, // rsrc(SGPR)
964 llvm_i32_ty, // vindex(VGPR)
965 llvm_i32_ty, // offset(SGPR/VGPR/imm)
966 llvm_i1_ty, // glc(imm)
967 llvm_i1_ty], // slc(imm)
968 [IntrWriteMem, IntrWillReturn,
969 ImmArg<ArgIndex<4>>, ImmArg<ArgIndex<5>>], "", [SDNPMemOperand]>,
970 AMDGPURsrcIntrinsic<1>;
971 def int_amdgcn_buffer_store_format : AMDGPUBufferStore<llvm_anyfloat_ty>;
972 def int_amdgcn_buffer_store : AMDGPUBufferStore;
973
974 // New buffer intrinsics with separate raw and struct variants. The raw
975 // variant never has an index. The struct variant always has an index, even if
976 // it is const 0. A struct intrinsic with constant 0 index is different to the
977 // corresponding raw intrinsic on gfx9+ because the behavior of bound checking
978 // and swizzling changes depending on whether idxen is set in the instruction.
979 // These new instrinsics also keep the offset and soffset arguments separate as
980 // they behave differently in bounds checking and swizzling.
981 class AMDGPURawBufferLoad<LLVMType data_ty = llvm_any_ty> : Intrinsic <
982 [data_ty],
983 [llvm_v4i32_ty, // rsrc(SGPR)
984 llvm_i32_ty, // offset(VGPR/imm, included in bounds checking and swizzling)
985 llvm_i32_ty, // soffset(SGPR/imm, excluded from bounds checking and swizzling)
986 llvm_i32_ty], // auxiliary data (imm, cachepolicy (bit 0 = glc,
987 // bit 1 = slc,
988 // bit 2 = dlc on gfx10+),
989 // swizzled buffer (bit 3 = swz))
990 [IntrReadMem, IntrWillReturn, ImmArg<ArgIndex<3>>], "", [SDNPMemOperand]>,
991 AMDGPURsrcIntrinsic<0>;
992 def int_amdgcn_raw_buffer_load_format : AMDGPURawBufferLoad<llvm_anyfloat_ty>;
993 def int_amdgcn_raw_buffer_load : AMDGPURawBufferLoad;
994
995 class AMDGPUStructBufferLoad<LLVMType data_ty = llvm_any_ty> : Intrinsic <
996 [data_ty],
997 [llvm_v4i32_ty, // rsrc(SGPR)
998 llvm_i32_ty, // vindex(VGPR)
999 llvm_i32_ty, // offset(VGPR/imm, included in bounds checking and swizzling)
1000 llvm_i32_ty, // soffset(SGPR/imm, excluded from bounds checking and swizzling)
1001 llvm_i32_ty], // auxiliary data (imm, cachepolicy (bit 0 = glc,
1002 // bit 1 = slc,
1003 // bit 2 = dlc on gfx10+),
1004 // swizzled buffer (bit 3 = swz))
1005 [IntrReadMem, IntrWillReturn, ImmArg<ArgIndex<4>>], "", [SDNPMemOperand]>,
1006 AMDGPURsrcIntrinsic<0>;
1007 def int_amdgcn_struct_buffer_load_format : AMDGPUStructBufferLoad;
1008 def int_amdgcn_struct_buffer_load : AMDGPUStructBufferLoad;
1009
1010 class AMDGPURawBufferStore<LLVMType data_ty = llvm_any_ty> : Intrinsic <
1011 [],
1012 [data_ty, // vdata(VGPR)
1013 llvm_v4i32_ty, // rsrc(SGPR)
1014 llvm_i32_ty, // offset(VGPR/imm, included in bounds checking and swizzling)
1015 llvm_i32_ty, // soffset(SGPR/imm, excluded from bounds checking and swizzling)
1016 llvm_i32_ty], // auxiliary data (imm, cachepolicy (bit 0 = glc,
1017 // bit 1 = slc,
1018 // bit 2 = dlc on gfx10+),
1019 // swizzled buffer (bit 3 = swz))
1020 [IntrWriteMem, IntrWillReturn, ImmArg<ArgIndex<4>>], "", [SDNPMemOperand]>,
1021 AMDGPURsrcIntrinsic<1>;
1022 def int_amdgcn_raw_buffer_store_format : AMDGPURawBufferStore<llvm_anyfloat_ty>;
1023 def int_amdgcn_raw_buffer_store : AMDGPURawBufferStore;
1024
1025 class AMDGPUStructBufferStore<LLVMType data_ty = llvm_any_ty> : Intrinsic <
1026 [],
1027 [data_ty, // vdata(VGPR)
1028 llvm_v4i32_ty, // rsrc(SGPR)
1029 llvm_i32_ty, // vindex(VGPR)
1030 llvm_i32_ty, // offset(VGPR/imm, included in bounds checking and swizzling)
1031 llvm_i32_ty, // soffset(SGPR/imm, excluded from bounds checking and swizzling)
1032 llvm_i32_ty], // auxiliary data (imm, cachepolicy (bit 0 = glc,
1033 // bit 1 = slc,
1034 // bit 2 = dlc on gfx10+),
1035 // swizzled buffer (bit 3 = swz))
1036 [IntrWriteMem, IntrWillReturn, ImmArg<ArgIndex<5>>], "", [SDNPMemOperand]>,
1037 AMDGPURsrcIntrinsic<1>;
1038 def int_amdgcn_struct_buffer_store_format : AMDGPUStructBufferStore;
1039 def int_amdgcn_struct_buffer_store : AMDGPUStructBufferStore;
1040
1041 class AMDGPURawBufferAtomic<LLVMType data_ty = llvm_any_ty, bit NoRtn = false> : Intrinsic <
1042 !if(NoRtn, [], [data_ty]),
1043 [!if(NoRtn, data_ty, LLVMMatchType<0>), // vdata(VGPR)
1044 llvm_v4i32_ty, // rsrc(SGPR)
1045 llvm_i32_ty, // offset(VGPR/imm, included in bounds checking and swizzling)
1046 llvm_i32_ty, // soffset(SGPR/imm, excluded from bounds checking and swizzling)
1047 llvm_i32_ty], // cachepolicy(imm; bit 1 = slc)
1048 [ImmArg<ArgIndex<4>>, IntrWillReturn], "", [SDNPMemOperand]>,
1049 AMDGPURsrcIntrinsic<1, 0>;
1050 def int_amdgcn_raw_buffer_atomic_swap : AMDGPURawBufferAtomic;
1051 def int_amdgcn_raw_buffer_atomic_add : AMDGPURawBufferAtomic;
1052 def int_amdgcn_raw_buffer_atomic_sub : AMDGPURawBufferAtomic;
1053 def int_amdgcn_raw_buffer_atomic_smin : AMDGPURawBufferAtomic;
1054 def int_amdgcn_raw_buffer_atomic_umin : AMDGPURawBufferAtomic;
1055 def int_amdgcn_raw_buffer_atomic_fmin : AMDGPURawBufferAtomic<llvm_anyfloat_ty>;
1056 def int_amdgcn_raw_buffer_atomic_smax : AMDGPURawBufferAtomic;
1057 def int_amdgcn_raw_buffer_atomic_umax : AMDGPURawBufferAtomic;
1058 def int_amdgcn_raw_buffer_atomic_fmax : AMDGPURawBufferAtomic<llvm_anyfloat_ty>;
1059 def int_amdgcn_raw_buffer_atomic_and : AMDGPURawBufferAtomic;
1060 def int_amdgcn_raw_buffer_atomic_or : AMDGPURawBufferAtomic;
1061 def int_amdgcn_raw_buffer_atomic_xor : AMDGPURawBufferAtomic;
1062 def int_amdgcn_raw_buffer_atomic_inc : AMDGPURawBufferAtomic;
1063 def int_amdgcn_raw_buffer_atomic_dec : AMDGPURawBufferAtomic;
1064 def int_amdgcn_raw_buffer_atomic_cmpswap : Intrinsic<
1065 [llvm_anyint_ty],
1066 [LLVMMatchType<0>, // src(VGPR)
1067 LLVMMatchType<0>, // cmp(VGPR)
1068 llvm_v4i32_ty, // rsrc(SGPR)
1069 llvm_i32_ty, // offset(VGPR/imm, included in bounds checking and swizzling)
1070 llvm_i32_ty, // soffset(SGPR/imm, excluded from bounds checking and swizzling)
1071 llvm_i32_ty], // cachepolicy(imm; bit 1 = slc)
1072 [ImmArg<ArgIndex<5>>, IntrWillReturn], "", [SDNPMemOperand]>,
1073 AMDGPURsrcIntrinsic<2, 0>;
1074
1075 // gfx908 intrinsic
1076 def int_amdgcn_raw_buffer_atomic_fadd : AMDGPURawBufferAtomic<llvm_anyfloat_ty>;
1077
1078 class AMDGPUStructBufferAtomic<LLVMType data_ty = llvm_any_ty, bit NoRtn = false> : Intrinsic <
1079 !if(NoRtn, [], [data_ty]),
1080 [!if(NoRtn, data_ty, LLVMMatchType<0>), // vdata(VGPR)
1081 llvm_v4i32_ty, // rsrc(SGPR)
1082 llvm_i32_ty, // vindex(VGPR)
1083 llvm_i32_ty, // offset(VGPR/imm, included in bounds checking and swizzling)
1084 llvm_i32_ty, // soffset(SGPR/imm, excluded from bounds checking and swizzling)
1085 llvm_i32_ty], // cachepolicy(imm; bit 1 = slc)
1086 [ImmArg<ArgIndex<5>>, IntrWillReturn], "", [SDNPMemOperand]>,
1087 AMDGPURsrcIntrinsic<1, 0>;
1088 def int_amdgcn_struct_buffer_atomic_swap : AMDGPUStructBufferAtomic;
1089 def int_amdgcn_struct_buffer_atomic_add : AMDGPUStructBufferAtomic;
1090 def int_amdgcn_struct_buffer_atomic_sub : AMDGPUStructBufferAtomic;
1091 def int_amdgcn_struct_buffer_atomic_smin : AMDGPUStructBufferAtomic;
1092 def int_amdgcn_struct_buffer_atomic_umin : AMDGPUStructBufferAtomic;
1093 def int_amdgcn_struct_buffer_atomic_smax : AMDGPUStructBufferAtomic;
1094 def int_amdgcn_struct_buffer_atomic_umax : AMDGPUStructBufferAtomic;
1095 def int_amdgcn_struct_buffer_atomic_and : AMDGPUStructBufferAtomic;
1096 def int_amdgcn_struct_buffer_atomic_or : AMDGPUStructBufferAtomic;
1097 def int_amdgcn_struct_buffer_atomic_xor : AMDGPUStructBufferAtomic;
1098 def int_amdgcn_struct_buffer_atomic_inc : AMDGPUStructBufferAtomic;
1099 def int_amdgcn_struct_buffer_atomic_dec : AMDGPUStructBufferAtomic;
1100 def int_amdgcn_struct_buffer_atomic_cmpswap : Intrinsic<
1101 [llvm_anyint_ty],
1102 [LLVMMatchType<0>, // src(VGPR)
1103 LLVMMatchType<0>, // cmp(VGPR)
1104 llvm_v4i32_ty, // rsrc(SGPR)
1105 llvm_i32_ty, // vindex(VGPR)
1106 llvm_i32_ty, // offset(VGPR/imm, included in bounds checking and swizzling)
1107 llvm_i32_ty, // soffset(SGPR/imm, excluded from bounds checking and swizzling)
1108 llvm_i32_ty], // cachepolicy(imm; bit 1 = slc)
1109 [ImmArg<ArgIndex<6>>, IntrWillReturn], "", [SDNPMemOperand]>,
1110 AMDGPURsrcIntrinsic<2, 0>;
1111
1112 // gfx908 intrinsic
1113 def int_amdgcn_struct_buffer_atomic_fadd : AMDGPUStructBufferAtomic<llvm_anyfloat_ty>;
1114
1115 // gfx90a intrinsics
1116 def int_amdgcn_struct_buffer_atomic_fmin : AMDGPUStructBufferAtomic<llvm_anyfloat_ty>;
1117 def int_amdgcn_struct_buffer_atomic_fmax : AMDGPUStructBufferAtomic<llvm_anyfloat_ty>;
1118
1119
1120 // Obsolescent tbuffer intrinsics.
1121 def int_amdgcn_tbuffer_load : Intrinsic <
1122 [llvm_any_ty], // overloaded for types f32/i32, v2f32/v2i32, v4f32/v4i32
1123 [llvm_v4i32_ty, // rsrc(SGPR)
1124 llvm_i32_ty, // vindex(VGPR)
1125 llvm_i32_ty, // voffset(VGPR)
1126 llvm_i32_ty, // soffset(SGPR)
1127 llvm_i32_ty, // offset(imm)
1128 llvm_i32_ty, // dfmt(imm)
1129 llvm_i32_ty, // nfmt(imm)
1130 llvm_i1_ty, // glc(imm)
1131 llvm_i1_ty], // slc(imm)
1132 [IntrReadMem, IntrWillReturn,
1133 ImmArg<ArgIndex<4>>, ImmArg<ArgIndex<5>>, ImmArg<ArgIndex<6>>,
1134 ImmArg<ArgIndex<7>>, ImmArg<ArgIndex<8>>], "", [SDNPMemOperand]>,
1135 AMDGPURsrcIntrinsic<0>;
1136
1137 def int_amdgcn_tbuffer_store : Intrinsic <
1138 [],
1139 [llvm_any_ty, // vdata(VGPR), overloaded for types f32/i32, v2f32/v2i32, v4f32/v4i32
1140 llvm_v4i32_ty, // rsrc(SGPR)
1141 llvm_i32_ty, // vindex(VGPR)
1142 llvm_i32_ty, // voffset(VGPR)
1143 llvm_i32_ty, // soffset(SGPR)
1144 llvm_i32_ty, // offset(imm)
1145 llvm_i32_ty, // dfmt(imm)
1146 llvm_i32_ty, // nfmt(imm)
1147 llvm_i1_ty, // glc(imm)
1148 llvm_i1_ty], // slc(imm)
1149 [IntrWriteMem, IntrWillReturn, ImmArg<ArgIndex<5>>,
1150 ImmArg<ArgIndex<6>>, ImmArg<ArgIndex<7>>,
1151 ImmArg<ArgIndex<8>>, ImmArg<ArgIndex<9>>], "", [SDNPMemOperand]>,
1152 AMDGPURsrcIntrinsic<1>;
1153
1154 // New tbuffer intrinsics, with:
1155 // - raw and struct variants
1156 // - joint format field
1157 // - joint cachepolicy field
1158 def int_amdgcn_raw_tbuffer_load : Intrinsic <
1159 [llvm_any_ty], // overloaded for types f32/i32, v2f32/v2i32, v4f32/v4i32
1160 [llvm_v4i32_ty, // rsrc(SGPR)
1161 llvm_i32_ty, // offset(VGPR/imm, included in bounds checking and swizzling)
1162 llvm_i32_ty, // soffset(SGPR/imm, excluded from bounds checking and swizzling)
1163 llvm_i32_ty, // format(imm; bits 3..0 = dfmt, bits 6..4 = nfmt)
1164 llvm_i32_ty], // auxiliary data (imm, cachepolicy (bit 0 = glc,
1165 // bit 1 = slc,
1166 // bit 2 = dlc on gfx10+),
1167 // swizzled buffer (bit 3 = swz))
1168 [IntrReadMem, IntrWillReturn,
1169 ImmArg<ArgIndex<3>>, ImmArg<ArgIndex<4>>], "", [SDNPMemOperand]>,
1170 AMDGPURsrcIntrinsic<0>;
1171
1172 def int_amdgcn_raw_tbuffer_store : Intrinsic <
1173 [],
1174 [llvm_any_ty, // vdata(VGPR), overloaded for types f32/i32, v2f32/v2i32, v4f32/v4i32
1175 llvm_v4i32_ty, // rsrc(SGPR)
1176 llvm_i32_ty, // offset(VGPR/imm, included in bounds checking and swizzling)
1177 llvm_i32_ty, // soffset(SGPR/imm, excluded from bounds checking and swizzling)
1178 llvm_i32_ty, // format(imm; bits 3..0 = dfmt, bits 6..4 = nfmt)
1179 llvm_i32_ty], // auxiliary data (imm, cachepolicy (bit 0 = glc,
1180 // bit 1 = slc,
1181 // bit 2 = dlc on gfx10+),
1182 // swizzled buffer (bit 3 = swz))
1183 [IntrWriteMem, IntrWillReturn,
1184 ImmArg<ArgIndex<4>>, ImmArg<ArgIndex<5>>], "", [SDNPMemOperand]>,
1185 AMDGPURsrcIntrinsic<1>;
1186
1187 def int_amdgcn_struct_tbuffer_load : Intrinsic <
1188 [llvm_any_ty], // overloaded for types f32/i32, v2f32/v2i32, v4f32/v4i32
1189 [llvm_v4i32_ty, // rsrc(SGPR)
1190 llvm_i32_ty, // vindex(VGPR)
1191 llvm_i32_ty, // offset(VGPR/imm, included in bounds checking and swizzling)
1192 llvm_i32_ty, // soffset(SGPR/imm, excluded from bounds checking and swizzling)
1193 llvm_i32_ty, // format(imm; bits 3..0 = dfmt, bits 6..4 = nfmt)
1194 llvm_i32_ty], // auxiliary data (imm, cachepolicy (bit 0 = glc,
1195 // bit 1 = slc,
1196 // bit 2 = dlc on gfx10+),
1197 // swizzled buffer (bit 3 = swz))
1198 [IntrReadMem, IntrWillReturn,
1199 ImmArg<ArgIndex<4>>, ImmArg<ArgIndex<5>>], "", [SDNPMemOperand]>,
1200 AMDGPURsrcIntrinsic<0>;
1201
1202 def int_amdgcn_struct_tbuffer_store : Intrinsic <
1203 [],
1204 [llvm_any_ty, // vdata(VGPR), overloaded for types f32/i32, v2f32/v2i32, v4f32/v4i32
1205 llvm_v4i32_ty, // rsrc(SGPR)
1206 llvm_i32_ty, // vindex(VGPR)
1207 llvm_i32_ty, // offset(VGPR/imm, included in bounds checking and swizzling)
1208 llvm_i32_ty, // soffset(SGPR/imm, excluded from bounds checking and swizzling)
1209 llvm_i32_ty, // format(imm; bits 3..0 = dfmt, bits 6..4 = nfmt)
1210 llvm_i32_ty], // auxiliary data (imm, cachepolicy (bit 0 = glc,
1211 // bit 1 = slc,
1212 // bit 2 = dlc on gfx10+),
1213 // swizzled buffer (bit 3 = swz))
1214 [IntrWriteMem, IntrWillReturn,
1215 ImmArg<ArgIndex<5>>, ImmArg<ArgIndex<6>>], "", [SDNPMemOperand]>,
1216 AMDGPURsrcIntrinsic<1>;
1217
1218 class AMDGPUBufferAtomic : Intrinsic <
1219 [llvm_anyint_ty],
1220 [LLVMMatchType<0>, // vdata(VGPR)
1221 llvm_v4i32_ty, // rsrc(SGPR)
1222 llvm_i32_ty, // vindex(VGPR)
1223 llvm_i32_ty, // offset(SGPR/VGPR/imm)
1224 llvm_i1_ty], // slc(imm)
1225 [ImmArg<ArgIndex<4>>, IntrWillReturn], "", [SDNPMemOperand]>,
1226 AMDGPURsrcIntrinsic<1, 0>;
1227 def int_amdgcn_buffer_atomic_swap : AMDGPUBufferAtomic;
1228 def int_amdgcn_buffer_atomic_add : AMDGPUBufferAtomic;
1229 def int_amdgcn_buffer_atomic_sub : AMDGPUBufferAtomic;
1230 def int_amdgcn_buffer_atomic_smin : AMDGPUBufferAtomic;
1231 def int_amdgcn_buffer_atomic_umin : AMDGPUBufferAtomic;
1232 def int_amdgcn_buffer_atomic_smax : AMDGPUBufferAtomic;
1233 def int_amdgcn_buffer_atomic_umax : AMDGPUBufferAtomic;
1234 def int_amdgcn_buffer_atomic_and : AMDGPUBufferAtomic;
1235 def int_amdgcn_buffer_atomic_or : AMDGPUBufferAtomic;
1236 def int_amdgcn_buffer_atomic_xor : AMDGPUBufferAtomic;
1237 def int_amdgcn_buffer_atomic_cmpswap : Intrinsic<
1238 [llvm_i32_ty],
1239 [llvm_i32_ty, // src(VGPR)
1240 llvm_i32_ty, // cmp(VGPR)
1241 llvm_v4i32_ty, // rsrc(SGPR)
1242 llvm_i32_ty, // vindex(VGPR)
1243 llvm_i32_ty, // offset(SGPR/VGPR/imm)
1244 llvm_i1_ty], // slc(imm)
1245 [ImmArg<ArgIndex<5>>, IntrWillReturn], "", [SDNPMemOperand]>,
1246 AMDGPURsrcIntrinsic<2, 0>;
1247
1248 def int_amdgcn_buffer_atomic_csub : AMDGPUBufferAtomic;
1249
1250 class AMDGPUBufferAtomicFP : Intrinsic <
1251 [llvm_anyfloat_ty],
1252 [LLVMMatchType<0>, // vdata(VGPR)
1253 llvm_v4i32_ty, // rsrc(SGPR)
1254 llvm_i32_ty, // vindex(VGPR)
1255 llvm_i32_ty, // offset(SGPR/VGPR/imm)
1256 llvm_i1_ty], // slc(imm)
1257 [ImmArg<ArgIndex<4>>, IntrWillReturn], "", [SDNPMemOperand]>,
1258 AMDGPURsrcIntrinsic<1, 0>;
1259
1260 // Legacy form of the intrinsic. raw and struct forms should be preferred.
1261 def int_amdgcn_buffer_atomic_fadd : AMDGPUBufferAtomicFP;
1262 } // defset AMDGPUBufferIntrinsics
1263
1264 // Uses that do not set the done bit should set IntrWriteMem on the
1265 // call site.
1266 def int_amdgcn_exp : Intrinsic <[], [
1267 llvm_i32_ty, // tgt,
1268 llvm_i32_ty, // en
1269 llvm_any_ty, // src0 (f32 or i32)
1270 LLVMMatchType<0>, // src1
1271 LLVMMatchType<0>, // src2
1272 LLVMMatchType<0>, // src3
1273 llvm_i1_ty, // done
1274 llvm_i1_ty // vm
1275 ],
1276 [ImmArg<ArgIndex<0>>, ImmArg<ArgIndex<1>>, ImmArg<ArgIndex<6>>,
1277 ImmArg<ArgIndex<7>>, IntrWriteMem, IntrInaccessibleMemOnly,
1278 IntrWillReturn]
1279 >;
1280
1281 // exp with compr bit set.
1282 def int_amdgcn_exp_compr : Intrinsic <[], [
1283 llvm_i32_ty, // tgt,
1284 llvm_i32_ty, // en
1285 llvm_anyvector_ty, // src0 (v2f16 or v2i16)
1286 LLVMMatchType<0>, // src1
1287 llvm_i1_ty, // done
1288 llvm_i1_ty], // vm
1289 [ImmArg<ArgIndex<0>>, ImmArg<ArgIndex<1>>, ImmArg<ArgIndex<4>>,
1290 ImmArg<ArgIndex<5>>, IntrWriteMem, IntrInaccessibleMemOnly,
1291 IntrWillReturn]
1292 >;
1293
1294 def int_amdgcn_buffer_wbinvl1_sc :
1295 GCCBuiltin<"__builtin_amdgcn_buffer_wbinvl1_sc">,
1296 Intrinsic<[], [], [IntrNoMem, IntrHasSideEffects, IntrWillReturn]>;
1297
1298 def int_amdgcn_buffer_wbinvl1 :
1299 GCCBuiltin<"__builtin_amdgcn_buffer_wbinvl1">,
1300 Intrinsic<[], [], [IntrNoMem, IntrHasSideEffects, IntrWillReturn]>;
1301
1302 def int_amdgcn_s_dcache_inv :
1303 GCCBuiltin<"__builtin_amdgcn_s_dcache_inv">,
1304 Intrinsic<[], [], [IntrNoMem, IntrHasSideEffects, IntrWillReturn]>;
1305
1306 def int_amdgcn_s_memtime :
1307 GCCBuiltin<"__builtin_amdgcn_s_memtime">,
1308 Intrinsic<[llvm_i64_ty], [], [IntrNoMem, IntrHasSideEffects, IntrWillReturn]>;
1309
1310 def int_amdgcn_s_sleep :
1311 GCCBuiltin<"__builtin_amdgcn_s_sleep">,
1312 Intrinsic<[], [llvm_i32_ty], [ImmArg<ArgIndex<0>>, IntrNoMem,
1313 IntrHasSideEffects, IntrWillReturn]> {
1314 }
1315
1316 def int_amdgcn_s_incperflevel :
1317 GCCBuiltin<"__builtin_amdgcn_s_incperflevel">,
1318 Intrinsic<[], [llvm_i32_ty], [ImmArg<ArgIndex<0>>, IntrNoMem,
1319 IntrHasSideEffects, IntrWillReturn]> {
1320 }
1321
1322 def int_amdgcn_s_decperflevel :
1323 GCCBuiltin<"__builtin_amdgcn_s_decperflevel">,
1324 Intrinsic<[], [llvm_i32_ty], [ImmArg<ArgIndex<0>>, IntrNoMem,
1325 IntrHasSideEffects, IntrWillReturn]> {
1326 }
1327
1328 def int_amdgcn_s_sethalt :
1329 Intrinsic<[], [llvm_i32_ty], [ImmArg<ArgIndex<0>>, IntrNoMem,
1330 IntrHasSideEffects, IntrWillReturn]>;
1331
1332 def int_amdgcn_s_getreg :
1333 GCCBuiltin<"__builtin_amdgcn_s_getreg">,
1334 Intrinsic<[llvm_i32_ty], [llvm_i32_ty],
1335 [IntrInaccessibleMemOnly, IntrReadMem, IntrSpeculatable,
1336 IntrWillReturn, ImmArg<ArgIndex<0>>]
1337 >;
1338
1339 // Note this can be used to set FP environment properties that are
1340 // unsafe to change in non-strictfp functions. The register properties
1341 // available (and value required to access them) may differ per
1342 // subtarget. llvm.amdgcn.s.setreg(hwmode, value)
1343 def int_amdgcn_s_setreg :
1344 GCCBuiltin<"__builtin_amdgcn_s_setreg">,
1345 Intrinsic<[], [llvm_i32_ty, llvm_i32_ty],
1346 [IntrNoMem, IntrHasSideEffects, IntrWillReturn, ImmArg<ArgIndex<0>>]
1347 >;
1348
1349 // int_amdgcn_s_getpc is provided to allow a specific style of position
1350 // independent code to determine the high part of its address when it is
1351 // known (through convention) that the code and any data of interest does
1352 // not cross a 4Gb address boundary. Use for any other purpose may not
1353 // produce the desired results as optimizations may cause code movement,
1354 // especially as we explicitly use IntrNoMem to allow optimizations.
1355 def int_amdgcn_s_getpc :
1356 GCCBuiltin<"__builtin_amdgcn_s_getpc">,
1357 Intrinsic<[llvm_i64_ty], [], [IntrNoMem, IntrSpeculatable,
1358 IntrWillReturn]>;
1359
1360 // __builtin_amdgcn_interp_mov <param>, <attr_chan>, <attr>, <m0>
1361 // param values: 0 = P10, 1 = P20, 2 = P0
1362 def int_amdgcn_interp_mov :
1363 GCCBuiltin<"__builtin_amdgcn_interp_mov">,
1364 Intrinsic<[llvm_float_ty],
1365 [llvm_i32_ty, llvm_i32_ty, llvm_i32_ty, llvm_i32_ty],
1366 [IntrNoMem, IntrSpeculatable, IntrWillReturn,
1367 ImmArg<ArgIndex<0>>, ImmArg<ArgIndex<1>>, ImmArg<ArgIndex<2>>]>;
1368
1369 // __builtin_amdgcn_interp_p1 <i>, <attr_chan>, <attr>, <m0>
1370 // This intrinsic reads from lds, but the memory values are constant,
1371 // so it behaves like IntrNoMem.
1372 def int_amdgcn_interp_p1 :
1373 GCCBuiltin<"__builtin_amdgcn_interp_p1">,
1374 Intrinsic<[llvm_float_ty],
1375 [llvm_float_ty, llvm_i32_ty, llvm_i32_ty, llvm_i32_ty],
1376 [IntrNoMem, IntrSpeculatable, IntrWillReturn,
1377 ImmArg<ArgIndex<1>>, ImmArg<ArgIndex<2>>]>;
1378
1379 // __builtin_amdgcn_interp_p2 <p1>, <j>, <attr_chan>, <attr>, <m0>
1380 def int_amdgcn_interp_p2 :
1381 GCCBuiltin<"__builtin_amdgcn_interp_p2">,
1382 Intrinsic<[llvm_float_ty],
1383 [llvm_float_ty, llvm_float_ty, llvm_i32_ty, llvm_i32_ty, llvm_i32_ty],
1384 [IntrNoMem, IntrSpeculatable, IntrWillReturn,
1385 ImmArg<ArgIndex<2>>, ImmArg<ArgIndex<3>>]>;
1386 // See int_amdgcn_v_interp_p1 for why this is IntrNoMem.
1387
1388 // __builtin_amdgcn_interp_p1_f16 <i>, <attr_chan>, <attr>, <high>, <m0>
1389 // high selects whether high or low 16-bits are loaded from LDS
1390 def int_amdgcn_interp_p1_f16 :
1391 GCCBuiltin<"__builtin_amdgcn_interp_p1_f16">,
1392 Intrinsic<[llvm_float_ty],
1393 [llvm_float_ty, llvm_i32_ty, llvm_i32_ty, llvm_i1_ty, llvm_i32_ty],
1394 [IntrNoMem, IntrSpeculatable, IntrWillReturn,
1395 ImmArg<ArgIndex<1>>, ImmArg<ArgIndex<2>>, ImmArg<ArgIndex<3>>]>;
1396
1397 // __builtin_amdgcn_interp_p2_f16 <p1>, <j>, <attr_chan>, <attr>, <high>, <m0>
1398 // high selects whether high or low 16-bits are loaded from LDS
1399 def int_amdgcn_interp_p2_f16 :
1400 GCCBuiltin<"__builtin_amdgcn_interp_p2_f16">,
1401 Intrinsic<[llvm_half_ty],
1402 [llvm_float_ty, llvm_float_ty, llvm_i32_ty, llvm_i32_ty, llvm_i1_ty, llvm_i32_ty],
1403 [IntrNoMem, IntrSpeculatable, IntrWillReturn,
1404 ImmArg<ArgIndex<2>>, ImmArg<ArgIndex<3>>, ImmArg<ArgIndex<4>>]>;
1405
1406 // Deprecated: use llvm.amdgcn.live.mask instead.
1407 def int_amdgcn_ps_live : Intrinsic <
1408 [llvm_i1_ty],
1409 [],
1410 [IntrNoMem, IntrWillReturn]>;
1411
1412 // Query currently live lanes.
1413 // Returns true if lane is live (and not a helper lane).
1414 def int_amdgcn_live_mask : Intrinsic <[llvm_i1_ty],
1415 [], [IntrReadMem, IntrInaccessibleMemOnly, IntrWillReturn]
1416 >;
1417
1418 def int_amdgcn_mbcnt_lo :
1419 GCCBuiltin<"__builtin_amdgcn_mbcnt_lo">,
1420 Intrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty],
1421 [IntrNoMem, IntrWillReturn]>;
1422
1423 def int_amdgcn_mbcnt_hi :
1424 GCCBuiltin<"__builtin_amdgcn_mbcnt_hi">,
1425 Intrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty],
1426 [IntrNoMem, IntrWillReturn]>;
1427
1428 // llvm.amdgcn.ds.swizzle src offset
1429 def int_amdgcn_ds_swizzle :
1430 GCCBuiltin<"__builtin_amdgcn_ds_swizzle">,
1431 Intrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty],
1432 [IntrNoMem, IntrConvergent, IntrWillReturn,
1433 ImmArg<ArgIndex<1>>]>;
1434
1435 def int_amdgcn_ubfe : Intrinsic<[llvm_anyint_ty],
1436 [LLVMMatchType<0>, llvm_i32_ty, llvm_i32_ty],
1437 [IntrNoMem, IntrSpeculatable, IntrWillReturn]
1438 >;
1439
1440 def int_amdgcn_sbfe : Intrinsic<[llvm_anyint_ty],
1441 [LLVMMatchType<0>, llvm_i32_ty, llvm_i32_ty],
1442 [IntrNoMem, IntrSpeculatable, IntrWillReturn]
1443 >;
1444
1445 def int_amdgcn_lerp :
1446 GCCBuiltin<"__builtin_amdgcn_lerp">,
1447 Intrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty, llvm_i32_ty],
1448 [IntrNoMem, IntrSpeculatable, IntrWillReturn]
1449 >;
1450
1451 def int_amdgcn_sad_u8 :
1452 GCCBuiltin<"__builtin_amdgcn_sad_u8">,
1453 Intrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty, llvm_i32_ty],
1454 [IntrNoMem, IntrSpeculatable, IntrWillReturn]
1455 >;
1456
1457 def int_amdgcn_msad_u8 :
1458 GCCBuiltin<"__builtin_amdgcn_msad_u8">,
1459 Intrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty, llvm_i32_ty],
1460 [IntrNoMem, IntrSpeculatable, IntrWillReturn]
1461 >;
1462
1463 def int_amdgcn_sad_hi_u8 :
1464 GCCBuiltin<"__builtin_amdgcn_sad_hi_u8">,
1465 Intrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty, llvm_i32_ty],
1466 [IntrNoMem, IntrSpeculatable, IntrWillReturn]
1467 >;
1468
1469 def int_amdgcn_sad_u16 :
1470 GCCBuiltin<"__builtin_amdgcn_sad_u16">,
1471 Intrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty, llvm_i32_ty],
1472 [IntrNoMem, IntrSpeculatable, IntrWillReturn]
1473 >;
1474
1475 def int_amdgcn_qsad_pk_u16_u8 :
1476 GCCBuiltin<"__builtin_amdgcn_qsad_pk_u16_u8">,
1477 Intrinsic<[llvm_i64_ty], [llvm_i64_ty, llvm_i32_ty, llvm_i64_ty],
1478 [IntrNoMem, IntrSpeculatable, IntrWillReturn]
1479 >;
1480
1481 def int_amdgcn_mqsad_pk_u16_u8 :
1482 GCCBuiltin<"__builtin_amdgcn_mqsad_pk_u16_u8">,
1483 Intrinsic<[llvm_i64_ty], [llvm_i64_ty, llvm_i32_ty, llvm_i64_ty],
1484 [IntrNoMem, IntrSpeculatable, IntrWillReturn]
1485 >;
1486
1487 def int_amdgcn_mqsad_u32_u8 :
1488 GCCBuiltin<"__builtin_amdgcn_mqsad_u32_u8">,
1489 Intrinsic<[llvm_v4i32_ty], [llvm_i64_ty, llvm_i32_ty, llvm_v4i32_ty],
1490 [IntrNoMem, IntrSpeculatable, IntrWillReturn]
1491 >;
1492
1493 def int_amdgcn_cvt_pk_u8_f32 :
1494 GCCBuiltin<"__builtin_amdgcn_cvt_pk_u8_f32">,
1495 Intrinsic<[llvm_i32_ty], [llvm_float_ty, llvm_i32_ty, llvm_i32_ty],
1496 [IntrNoMem, IntrSpeculatable, IntrWillReturn]
1497 >;
1498
1499 def int_amdgcn_icmp :
1500 Intrinsic<[llvm_anyint_ty], [llvm_anyint_ty, LLVMMatchType<1>, llvm_i32_ty],
1501 [IntrNoMem, IntrConvergent, IntrWillReturn,
1502 ImmArg<ArgIndex<2>>]>;
1503
1504 def int_amdgcn_fcmp :
1505 Intrinsic<[llvm_anyint_ty], [llvm_anyfloat_ty, LLVMMatchType<1>, llvm_i32_ty],
1506 [IntrNoMem, IntrConvergent, IntrWillReturn,
1507 ImmArg<ArgIndex<2>>]>;
1508
1509 def int_amdgcn_ballot :
1510 Intrinsic<[llvm_anyint_ty], [llvm_i1_ty],
1511 [IntrNoMem, IntrConvergent, IntrWillReturn]>;
1512
1513 def int_amdgcn_readfirstlane :
1514 GCCBuiltin<"__builtin_amdgcn_readfirstlane">,
1515 Intrinsic<[llvm_i32_ty], [llvm_i32_ty],
1516 [IntrNoMem, IntrConvergent, IntrWillReturn]>;
1517
1518 // The lane argument must be uniform across the currently active threads of the
1519 // current wave. Otherwise, the result is undefined.
1520 def int_amdgcn_readlane :
1521 GCCBuiltin<"__builtin_amdgcn_readlane">,
1522 Intrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty],
1523 [IntrNoMem, IntrConvergent, IntrWillReturn]>;
1524
1525 // The value to write and lane select arguments must be uniform across the
1526 // currently active threads of the current wave. Otherwise, the result is
1527 // undefined.
1528 def int_amdgcn_writelane :
1529 GCCBuiltin<"__builtin_amdgcn_writelane">,
1530 Intrinsic<[llvm_i32_ty], [
1531 llvm_i32_ty, // uniform value to write: returned by the selected lane
1532 llvm_i32_ty, // uniform lane select
1533 llvm_i32_ty // returned by all lanes other than the selected one
1534 ],
1535 [IntrNoMem, IntrConvergent, IntrWillReturn]
1536 >;
1537
1538 def int_amdgcn_alignbyte : GCCBuiltin<"__builtin_amdgcn_alignbyte">,
1539 Intrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty, llvm_i32_ty],
1540 [IntrNoMem, IntrSpeculatable, IntrWillReturn]
1541 >;
1542
1543 def int_amdgcn_mul_i24 : Intrinsic<[llvm_i32_ty],
1544 [llvm_i32_ty, llvm_i32_ty],
1545 [IntrNoMem, IntrSpeculatable, IntrWillReturn]
1546 >;
1547
1548 def int_amdgcn_mul_u24 : Intrinsic<[llvm_i32_ty],
1549 [llvm_i32_ty, llvm_i32_ty],
1550 [IntrNoMem, IntrSpeculatable, IntrWillReturn]
1551 >;
1552
1553 def int_amdgcn_mulhi_i24 : Intrinsic<[llvm_i32_ty],
1554 [llvm_i32_ty, llvm_i32_ty],
1555 [IntrNoMem, IntrSpeculatable, IntrWillReturn]
1556 >;
1557
1558 def int_amdgcn_mulhi_u24 : Intrinsic<[llvm_i32_ty],
1559 [llvm_i32_ty, llvm_i32_ty],
1560 [IntrNoMem, IntrSpeculatable, IntrWillReturn]
1561 >;
1562
1563 // llvm.amdgcn.ds.gws.init(i32 bar_val, i32 resource_id)
1564 //
1565 // bar_val is the total number of waves that will wait on this
1566 // barrier, minus 1.
1567 def int_amdgcn_ds_gws_init :
1568 GCCBuiltin<"__builtin_amdgcn_ds_gws_init">,
1569 Intrinsic<[],
1570 [llvm_i32_ty, llvm_i32_ty],
1571 [IntrConvergent, IntrWriteMem,
1572 IntrInaccessibleMemOnly, IntrWillReturn], "",
1573 [SDNPMemOperand]
1574 >;
1575
1576 // llvm.amdgcn.ds.gws.barrier(i32 vsrc0, i32 resource_id)
1577 // bar_val is the total number of waves that will wait on this
1578 // barrier, minus 1.
1579 def int_amdgcn_ds_gws_barrier :
1580 GCCBuiltin<"__builtin_amdgcn_ds_gws_barrier">,
1581 Intrinsic<[],
1582 [llvm_i32_ty, llvm_i32_ty],
1583 [IntrConvergent, IntrInaccessibleMemOnly, IntrWillReturn], "",
1584 [SDNPMemOperand]
1585 >;
1586
1587 // llvm.amdgcn.ds.gws.sema.v(i32 resource_id)
1588 def int_amdgcn_ds_gws_sema_v :
1589 GCCBuiltin<"__builtin_amdgcn_ds_gws_sema_v">,
1590 Intrinsic<[],
1591 [llvm_i32_ty],
1592 [IntrConvergent, IntrInaccessibleMemOnly, IntrWillReturn], "",
1593 [SDNPMemOperand]
1594 >;
1595
1596 // llvm.amdgcn.ds.gws.sema.br(i32 vsrc, i32 resource_id)
1597 def int_amdgcn_ds_gws_sema_br :
1598 GCCBuiltin<"__builtin_amdgcn_ds_gws_sema_br">,
1599 Intrinsic<[],
1600 [llvm_i32_ty, llvm_i32_ty],
1601 [IntrConvergent, IntrInaccessibleMemOnly, IntrWillReturn], "",
1602 [SDNPMemOperand]
1603 >;
1604
1605 // llvm.amdgcn.ds.gws.sema.p(i32 resource_id)
1606 def int_amdgcn_ds_gws_sema_p :
1607 GCCBuiltin<"__builtin_amdgcn_ds_gws_sema_p">,
1608 Intrinsic<[],
1609 [llvm_i32_ty],
1610 [IntrConvergent, IntrInaccessibleMemOnly, IntrWillReturn], "",
1611 [SDNPMemOperand]
1612 >;
1613
1614 // llvm.amdgcn.ds.gws.sema.release.all(i32 resource_id)
1615 def int_amdgcn_ds_gws_sema_release_all :
1616 GCCBuiltin<"__builtin_amdgcn_ds_gws_sema_release_all">,
1617 Intrinsic<[],
1618 [llvm_i32_ty],
1619 [IntrConvergent, IntrInaccessibleMemOnly, IntrWillReturn], "",
1620 [SDNPMemOperand]
1621 >;
1622
1623
1624 // Copies the source value to the destination value, with the guarantee that
1625 // the source value is computed as if the entire program were executed in WQM.
1626 def int_amdgcn_wqm : Intrinsic<[llvm_any_ty],
1627 [LLVMMatchType<0>], [IntrNoMem, IntrSpeculatable, IntrWillReturn]
1628 >;
1629
1630 // Copies the source value to the destination value, such that the source
1631 // is computed as if the entire program were executed in WQM if any other
1632 // program code executes in WQM.
1633 def int_amdgcn_softwqm : Intrinsic<[llvm_any_ty],
1634 [LLVMMatchType<0>], [IntrNoMem, IntrSpeculatable, IntrWillReturn]
1635 >;
1636
1637 // Return true if at least one thread within the pixel quad passes true into
1638 // the function.
1639 def int_amdgcn_wqm_vote : Intrinsic<[llvm_i1_ty],
1640 [llvm_i1_ty], [IntrNoMem, IntrConvergent, IntrWillReturn]
1641 >;
1642
1643 // If false, set EXEC=0 for the current thread until the end of program.
1644 // FIXME: Should this be IntrNoMem, IntrHasSideEffects, or IntrWillReturn?
1645 def int_amdgcn_kill : Intrinsic<[], [llvm_i1_ty], []>;
1646
1647 def int_amdgcn_endpgm : GCCBuiltin<"__builtin_amdgcn_endpgm">,
1648 Intrinsic<[], [], [IntrNoReturn, IntrCold, IntrNoMem, IntrHasSideEffects]
1649 >;
1650
1651 // If false, mark all active lanes as helper lanes until the end of program.
1652 def int_amdgcn_wqm_demote : Intrinsic<[],
1653 [llvm_i1_ty], [IntrWriteMem, IntrInaccessibleMemOnly]
1654 >;
1655
1656 // Copies the active channels of the source value to the destination value,
1657 // with the guarantee that the source value is computed as if the entire
1658 // program were executed in Whole Wavefront Mode, i.e. with all channels
1659 // enabled, with a few exceptions: - Phi nodes which require WWM return an
1660 // undefined value.
1661 def int_amdgcn_strict_wwm : Intrinsic<[llvm_any_ty],
1662 [LLVMMatchType<0>], [IntrNoMem, IntrSpeculatable,
1663 IntrConvergent, IntrWillReturn]
1664 >;
1665 // Deprecated. Use int_amdgcn_strict_wwm instead.
1666 def int_amdgcn_wwm : Intrinsic<[llvm_any_ty],
1667 [LLVMMatchType<0>], [IntrNoMem, IntrSpeculatable,
1668 IntrConvergent, IntrWillReturn]
1669 >;
1670 def int_amdgcn_strict_wqm : Intrinsic<[llvm_any_ty],
1671 [LLVMMatchType<0>], [IntrNoMem, IntrSpeculatable,
1672 IntrConvergent, IntrWillReturn]
1673 >;
1674
1675 // Given a value, copies it while setting all the inactive lanes to a given
1676 // value. Note that OpenGL helper lanes are considered active, so if the
1677 // program ever uses WQM, then the instruction and the first source will be
1678 // computed in WQM.
1679 def int_amdgcn_set_inactive :
1680 Intrinsic<[llvm_anyint_ty],
1681 [LLVMMatchType<0>, // value to be copied
1682 LLVMMatchType<0>], // value for the inactive lanes to take
1683 [IntrNoMem, IntrConvergent, IntrWillReturn]>;
1684
1685 // Return if the given flat pointer points to a local memory address.
1686 def int_amdgcn_is_shared : GCCBuiltin<"__builtin_amdgcn_is_shared">,
1687 Intrinsic<[llvm_i1_ty], [llvm_ptr_ty],
1688 [IntrNoMem, IntrSpeculatable, NoCapture<ArgIndex<0>>, IntrWillReturn]
1689 >;
1690
1691 // Return if the given flat pointer points to a prvate memory address.
1692 def int_amdgcn_is_private : GCCBuiltin<"__builtin_amdgcn_is_private">,
1693 Intrinsic<[llvm_i1_ty], [llvm_ptr_ty],
1694 [IntrNoMem, IntrSpeculatable, NoCapture<ArgIndex<0>>, IntrWillReturn]
1695 >;
1696
1697 //===----------------------------------------------------------------------===//
1698 // CI+ Intrinsics
1699 //===----------------------------------------------------------------------===//
1700
1701 def int_amdgcn_s_dcache_inv_vol :
1702 GCCBuiltin<"__builtin_amdgcn_s_dcache_inv_vol">,
1703 Intrinsic<[], [], [IntrNoMem, IntrHasSideEffects, IntrWillReturn]>;
1704
1705 def int_amdgcn_buffer_wbinvl1_vol :
1706 GCCBuiltin<"__builtin_amdgcn_buffer_wbinvl1_vol">,
1707 Intrinsic<[], [], [IntrNoMem, IntrHasSideEffects, IntrWillReturn]>;
1708
1709 //===----------------------------------------------------------------------===//
1710 // VI Intrinsics
1711 //===----------------------------------------------------------------------===//
1712
1713 // llvm.amdgcn.mov.dpp.i32 <src> <dpp_ctrl> <row_mask> <bank_mask> <bound_ctrl>
1714 def int_amdgcn_mov_dpp :
1715 Intrinsic<[llvm_anyint_ty],
1716 [LLVMMatchType<0>, llvm_i32_ty, llvm_i32_ty, llvm_i32_ty,
1717 llvm_i1_ty],
1718 [IntrNoMem, IntrConvergent, IntrWillReturn,
1719 ImmArg<ArgIndex<1>>, ImmArg<ArgIndex<2>>,
1720 ImmArg<ArgIndex<3>>, ImmArg<ArgIndex<4>>]>;
1721
1722 // llvm.amdgcn.update.dpp.i32 <old> <src> <dpp_ctrl> <row_mask> <bank_mask> <bound_ctrl>
1723 // Should be equivalent to:
1724 // v_mov_b32 <dest> <old>
1725 // v_mov_b32 <dest> <src> <dpp_ctrl> <row_mask> <bank_mask> <bound_ctrl>
1726 def int_amdgcn_update_dpp :
1727 Intrinsic<[llvm_anyint_ty],
1728 [LLVMMatchType<0>, LLVMMatchType<0>, llvm_i32_ty,
1729 llvm_i32_ty, llvm_i32_ty, llvm_i1_ty],
1730 [IntrNoMem, IntrConvergent, IntrWillReturn,
1731 ImmArg<ArgIndex<2>>, ImmArg<ArgIndex<3>>,
1732 ImmArg<ArgIndex<4>>, ImmArg<ArgIndex<5>>]>;
1733
1734 def int_amdgcn_s_dcache_wb :
1735 GCCBuiltin<"__builtin_amdgcn_s_dcache_wb">,
1736 Intrinsic<[], [], [IntrNoMem, IntrHasSideEffects, IntrWillReturn]>;
1737
1738 def int_amdgcn_s_dcache_wb_vol :
1739 GCCBuiltin<"__builtin_amdgcn_s_dcache_wb_vol">,
1740 Intrinsic<[], [], [IntrNoMem, IntrHasSideEffects, IntrWillReturn]>;
1741
1742 def int_amdgcn_s_memrealtime :
1743 GCCBuiltin<"__builtin_amdgcn_s_memrealtime">,
1744 Intrinsic<[llvm_i64_ty], [], [IntrNoMem, IntrHasSideEffects, IntrWillReturn]>;
1745
1746 // llvm.amdgcn.ds.permute <index> <src>
1747 def int_amdgcn_ds_permute :
1748 GCCBuiltin<"__builtin_amdgcn_ds_permute">,
1749 Intrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty],
1750 [IntrNoMem, IntrConvergent, IntrWillReturn]>;
1751
1752 // llvm.amdgcn.ds.bpermute <index> <src>
1753 def int_amdgcn_ds_bpermute :
1754 GCCBuiltin<"__builtin_amdgcn_ds_bpermute">,
1755 Intrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty],
1756 [IntrNoMem, IntrConvergent, IntrWillReturn]>;
1757
1758 // llvm.amdgcn.perm <src0> <src1> <selector>
1759 def int_amdgcn_perm :
1760 GCCBuiltin<"__builtin_amdgcn_perm">,
1761 Intrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty, llvm_i32_ty],
1762 [IntrNoMem, IntrSpeculatable, IntrWillReturn]>;
1763
1764 //===----------------------------------------------------------------------===//
1765 // GFX10 Intrinsics
1766 //===----------------------------------------------------------------------===//
1767
1768 // llvm.amdgcn.permlane16 <old> <src0> <src1> <src2> <fi> <bound_control>
1769 def int_amdgcn_permlane16 : GCCBuiltin<"__builtin_amdgcn_permlane16">,
1770 Intrinsic<[llvm_i32_ty],
1771 [llvm_i32_ty, llvm_i32_ty, llvm_i32_ty, llvm_i32_ty, llvm_i1_ty, llvm_i1_ty],
1772 [IntrNoMem, IntrConvergent, IntrWillReturn,
1773 ImmArg<ArgIndex<4>>, ImmArg<ArgIndex<5>>]>;
1774
1775 // llvm.amdgcn.permlanex16 <old> <src0> <src1> <src2> <fi> <bound_control>
1776 def int_amdgcn_permlanex16 : GCCBuiltin<"__builtin_amdgcn_permlanex16">,
1777 Intrinsic<[llvm_i32_ty],
1778 [llvm_i32_ty, llvm_i32_ty, llvm_i32_ty, llvm_i32_ty, llvm_i1_ty, llvm_i1_ty],
1779 [IntrNoMem, IntrConvergent, IntrWillReturn,
1780 ImmArg<ArgIndex<4>>, ImmArg<ArgIndex<5>>]>;
1781
1782 // llvm.amdgcn.mov.dpp8.i32 <src> <sel>
1783 // <sel> is a 32-bit constant whose high 8 bits must be zero which selects
1784 // the lanes to read from.
1785 def int_amdgcn_mov_dpp8 :
1786 Intrinsic<[llvm_anyint_ty],
1787 [LLVMMatchType<0>, llvm_i32_ty],
1788 [IntrNoMem, IntrConvergent, IntrWillReturn,
1789 ImmArg<ArgIndex<1>>]>;
1790
1791 def int_amdgcn_s_get_waveid_in_workgroup :
1792 GCCBuiltin<"__builtin_amdgcn_s_get_waveid_in_workgroup">,
1793 Intrinsic<[llvm_i32_ty], [],
1794 [IntrReadMem, IntrInaccessibleMemOnly, IntrWillReturn]>;
1795
1796 class AMDGPUGlobalAtomicRtn<LLVMType vt> : Intrinsic <
1797 [vt],
1798 [llvm_anyptr_ty, // vaddr
1799 vt], // vdata(VGPR)
1800 [IntrArgMemOnly, IntrWillReturn, NoCapture<ArgIndex<0>>], "",
1801 [SDNPMemOperand]>;
1802
1803 def int_amdgcn_global_atomic_csub : AMDGPUGlobalAtomicRtn<llvm_i32_ty>;
1804
1805 // uint4 llvm.amdgcn.image.bvh.intersect.ray <node_ptr>, <ray_extent>, <ray_origin>,
1806 // <ray_dir>, <ray_inv_dir>, <texture_descr>
1807 // <node_ptr> is i32 or i64.
1808 // <ray_dir> and <ray_inv_dir> are both v3f16 or both v3f32.
1809 def int_amdgcn_image_bvh_intersect_ray :
1810 Intrinsic<[llvm_v4i32_ty],
1811 [llvm_anyint_ty, llvm_float_ty, llvm_v3f32_ty, llvm_anyvector_ty,
1812 LLVMMatchType<1>, llvm_v4i32_ty],
1813 [IntrReadMem, IntrWillReturn]>;
1814
1815 //===----------------------------------------------------------------------===//
1816 // Deep learning intrinsics.
1817 //===----------------------------------------------------------------------===//
1818
1819 // f32 %r = llvm.amdgcn.fdot2(v2f16 %a, v2f16 %b, f32 %c, i1 %clamp)
1820 // %r = %a[0] * %b[0] + %a[1] * %b[1] + %c
1821 def int_amdgcn_fdot2 :
1822 GCCBuiltin<"__builtin_amdgcn_fdot2">,
1823 Intrinsic<
1824 [llvm_float_ty], // %r
1825 [
1826 llvm_v2f16_ty, // %a
1827 llvm_v2f16_ty, // %b
1828 llvm_float_ty, // %c
1829 llvm_i1_ty // %clamp
1830 ],
1831 [IntrNoMem, IntrSpeculatable, IntrWillReturn, ImmArg<ArgIndex<3>>]
1832 >;
1833
1834 // i32 %r = llvm.amdgcn.sdot2(v2i16 %a, v2i16 %b, i32 %c, i1 %clamp)
1835 // %r = %a[0] * %b[0] + %a[1] * %b[1] + %c
1836 def int_amdgcn_sdot2 :
1837 GCCBuiltin<"__builtin_amdgcn_sdot2">,
1838 Intrinsic<
1839 [llvm_i32_ty], // %r
1840 [
1841 llvm_v2i16_ty, // %a
1842 llvm_v2i16_ty, // %b
1843 llvm_i32_ty, // %c
1844 llvm_i1_ty // %clamp
1845 ],
1846 [IntrNoMem, IntrSpeculatable, IntrWillReturn, ImmArg<ArgIndex<3>>]
1847 >;
1848
1849 // u32 %r = llvm.amdgcn.udot2(v2u16 %a, v2u16 %b, u32 %c, i1 %clamp)
1850 // %r = %a[0] * %b[0] + %a[1] * %b[1] + %c
1851 def int_amdgcn_udot2 :
1852 GCCBuiltin<"__builtin_amdgcn_udot2">,
1853 Intrinsic<
1854 [llvm_i32_ty], // %r
1855 [
1856 llvm_v2i16_ty, // %a
1857 llvm_v2i16_ty, // %b
1858 llvm_i32_ty, // %c
1859 llvm_i1_ty // %clamp
1860 ],
1861 [IntrNoMem, IntrSpeculatable, IntrWillReturn, ImmArg<ArgIndex<3>>]
1862 >;
1863
1864 // i32 %r = llvm.amdgcn.sdot4(v4i8 (as i32) %a, v4i8 (as i32) %b, i32 %c, i1 %clamp)
1865 // %r = %a[0] * %b[0] + %a[1] * %b[1] + %a[2] * %b[2] + %a[3] * %b[3] + %c
1866 def int_amdgcn_sdot4 :
1867 GCCBuiltin<"__builtin_amdgcn_sdot4">,
1868 Intrinsic<
1869 [llvm_i32_ty], // %r
1870 [
1871 llvm_i32_ty, // %a
1872 llvm_i32_ty, // %b
1873 llvm_i32_ty, // %c
1874 llvm_i1_ty // %clamp
1875 ],
1876 [IntrNoMem, IntrSpeculatable, IntrWillReturn, ImmArg<ArgIndex<3>>]
1877 >;
1878
1879 // u32 %r = llvm.amdgcn.udot4(v4u8 (as u32) %a, v4u8 (as u32) %b, u32 %c, i1 %clamp)
1880 // %r = %a[0] * %b[0] + %a[1] * %b[1] + %a[2] * %b[2] + %a[3] * %b[3] + %c
1881 def int_amdgcn_udot4 :
1882 GCCBuiltin<"__builtin_amdgcn_udot4">,
1883 Intrinsic<
1884 [llvm_i32_ty], // %r
1885 [
1886 llvm_i32_ty, // %a
1887 llvm_i32_ty, // %b
1888 llvm_i32_ty, // %c
1889 llvm_i1_ty // %clamp
1890 ],
1891 [IntrNoMem, IntrSpeculatable, IntrWillReturn, ImmArg<ArgIndex<3>>]
1892 >;
1893
1894 // i32 %r = llvm.amdgcn.sdot8(v8i4 (as i32) %a, v8i4 (as i32) %b, i32 %c, i1 %clamp)
1895 // %r = %a[0] * %b[0] + %a[1] * %b[1] + %a[2] * %b[2] + %a[3] * %b[3] +
1896 // %a[4] * %b[4] + %a[5] * %b[5] + %a[6] * %b[6] + %a[7] * %b[7] + %c
1897 def int_amdgcn_sdot8 :
1898 GCCBuiltin<"__builtin_amdgcn_sdot8">,
1899 Intrinsic<
1900 [llvm_i32_ty], // %r
1901 [
1902 llvm_i32_ty, // %a
1903 llvm_i32_ty, // %b
1904 llvm_i32_ty, // %c
1905 llvm_i1_ty // %clamp
1906 ],
1907 [IntrNoMem, IntrSpeculatable, IntrWillReturn, ImmArg<ArgIndex<3>>]
1908 >;
1909
1910 // u32 %r = llvm.amdgcn.udot8(v8u4 (as u32) %a, v8u4 (as u32) %b, u32 %c, i1 %clamp)
1911 // %r = %a[0] * %b[0] + %a[1] * %b[1] + %a[2] * %b[2] + %a[3] * %b[3] +
1912 // %a[4] * %b[4] + %a[5] * %b[5] + %a[6] * %b[6] + %a[7] * %b[7] + %c
1913 def int_amdgcn_udot8 :
1914 GCCBuiltin<"__builtin_amdgcn_udot8">,
1915 Intrinsic<
1916 [llvm_i32_ty], // %r
1917 [
1918 llvm_i32_ty, // %a
1919 llvm_i32_ty, // %b
1920 llvm_i32_ty, // %c
1921 llvm_i1_ty // %clamp
1922 ],
1923 [IntrNoMem, IntrSpeculatable, IntrWillReturn, ImmArg<ArgIndex<3>>]
1924 >;
1925
1926 //===----------------------------------------------------------------------===//
1927 // gfx908 intrinsics
1928 // ===----------------------------------------------------------------------===//
1929
1930 def int_amdgcn_global_atomic_fadd : AMDGPUGlobalAtomicRtn<llvm_anyfloat_ty>;
1931
1932 // llvm.amdgcn.mfma.*.* vdst, srcA, srcB, srcC, cbsz, abid, blgp
1933 class AMDGPUMfmaIntrinsic<LLVMType DestTy, LLVMType SrcABTy> :
1934 GCCBuiltin<!subst("int", "__builtin", NAME)>,
1935 Intrinsic<[DestTy],
1936 [SrcABTy, SrcABTy, DestTy,
1937 llvm_i32_ty, llvm_i32_ty, llvm_i32_ty],
1938 [IntrConvergent, IntrNoMem, IntrWillReturn,
1939 ImmArg<ArgIndex<3>>, ImmArg<ArgIndex<4>>, ImmArg<ArgIndex<5>>]>;
1940
1941 def int_amdgcn_mfma_f32_32x32x1f32 : AMDGPUMfmaIntrinsic<llvm_v32f32_ty, llvm_float_ty>;
1942 def int_amdgcn_mfma_f32_16x16x1f32 : AMDGPUMfmaIntrinsic<llvm_v16f32_ty, llvm_float_ty>;
1943 def int_amdgcn_mfma_f32_4x4x1f32 : AMDGPUMfmaIntrinsic<llvm_v4f32_ty, llvm_float_ty>;
1944 def int_amdgcn_mfma_f32_32x32x2f32 : AMDGPUMfmaIntrinsic<llvm_v16f32_ty, llvm_float_ty>;
1945 def int_amdgcn_mfma_f32_16x16x4f32 : AMDGPUMfmaIntrinsic<llvm_v4f32_ty, llvm_float_ty>;
1946 def int_amdgcn_mfma_f32_32x32x4f16 : AMDGPUMfmaIntrinsic<llvm_v32f32_ty, llvm_v4f16_ty>;
1947 def int_amdgcn_mfma_f32_16x16x4f16 : AMDGPUMfmaIntrinsic<llvm_v16f32_ty, llvm_v4f16_ty>;
1948 def int_amdgcn_mfma_f32_4x4x4f16 : AMDGPUMfmaIntrinsic<llvm_v4f32_ty, llvm_v4f16_ty>;
1949 def int_amdgcn_mfma_f32_32x32x8f16 : AMDGPUMfmaIntrinsic<llvm_v16f32_ty, llvm_v4f16_ty>;
1950 def int_amdgcn_mfma_f32_16x16x16f16 : AMDGPUMfmaIntrinsic<llvm_v4f32_ty, llvm_v4f16_ty>;
1951 def int_amdgcn_mfma_i32_32x32x4i8 : AMDGPUMfmaIntrinsic<llvm_v32i32_ty, llvm_i32_ty>;
1952 def int_amdgcn_mfma_i32_16x16x4i8 : AMDGPUMfmaIntrinsic<llvm_v16i32_ty, llvm_i32_ty>;
1953 def int_amdgcn_mfma_i32_4x4x4i8 : AMDGPUMfmaIntrinsic<llvm_v4i32_ty, llvm_i32_ty>;
1954 def int_amdgcn_mfma_i32_32x32x8i8 : AMDGPUMfmaIntrinsic<llvm_v16i32_ty, llvm_i32_ty>;
1955 def int_amdgcn_mfma_i32_16x16x16i8 : AMDGPUMfmaIntrinsic<llvm_v4i32_ty, llvm_i32_ty>;
1956 def int_amdgcn_mfma_f32_32x32x2bf16 : AMDGPUMfmaIntrinsic<llvm_v32f32_ty, llvm_v2i16_ty>;
1957 def int_amdgcn_mfma_f32_16x16x2bf16 : AMDGPUMfmaIntrinsic<llvm_v16f32_ty, llvm_v2i16_ty>;
1958 def int_amdgcn_mfma_f32_4x4x2bf16 : AMDGPUMfmaIntrinsic<llvm_v4f32_ty, llvm_v2i16_ty>;
1959 def int_amdgcn_mfma_f32_32x32x4bf16 : AMDGPUMfmaIntrinsic<llvm_v16f32_ty, llvm_v2i16_ty>;
1960 def int_amdgcn_mfma_f32_16x16x8bf16 : AMDGPUMfmaIntrinsic<llvm_v4f32_ty, llvm_v2i16_ty>;
1961
1962 //===----------------------------------------------------------------------===//
1963 // gfx90a intrinsics
1964 // ===----------------------------------------------------------------------===//
1965
1966 def int_amdgcn_global_atomic_fmin : AMDGPUGlobalAtomicRtn<llvm_anyfloat_ty>;
1967 def int_amdgcn_global_atomic_fmax : AMDGPUGlobalAtomicRtn<llvm_anyfloat_ty>;
1968 def int_amdgcn_flat_atomic_fadd : AMDGPUGlobalAtomicRtn<llvm_anyfloat_ty>;
1969 def int_amdgcn_flat_atomic_fmin : AMDGPUGlobalAtomicRtn<llvm_anyfloat_ty>;
1970 def int_amdgcn_flat_atomic_fmax : AMDGPUGlobalAtomicRtn<llvm_anyfloat_ty>;
1971
1972 def int_amdgcn_mfma_f32_32x32x4bf16_1k : AMDGPUMfmaIntrinsic<llvm_v32f32_ty, llvm_v4i16_ty>;
1973 def int_amdgcn_mfma_f32_16x16x4bf16_1k : AMDGPUMfmaIntrinsic<llvm_v16f32_ty, llvm_v4i16_ty>;
1974 def int_amdgcn_mfma_f32_4x4x4bf16_1k : AMDGPUMfmaIntrinsic<llvm_v4f32_ty, llvm_v4i16_ty>;
1975 def int_amdgcn_mfma_f32_32x32x8bf16_1k : AMDGPUMfmaIntrinsic<llvm_v16f32_ty, llvm_v4i16_ty>;
1976 def int_amdgcn_mfma_f32_16x16x16bf16_1k : AMDGPUMfmaIntrinsic<llvm_v4f32_ty, llvm_v4i16_ty>;
1977
1978 def int_amdgcn_mfma_f64_16x16x4f64 : AMDGPUMfmaIntrinsic<llvm_v4f64_ty, llvm_double_ty>;
1979 def int_amdgcn_mfma_f64_4x4x4f64 : AMDGPUMfmaIntrinsic<llvm_double_ty, llvm_double_ty>;
1980
1981 //===----------------------------------------------------------------------===//
1982 // Special Intrinsics for backend internal use only. No frontend
1983 // should emit calls to these.
1984 // ===----------------------------------------------------------------------===//
1985 def int_amdgcn_if : Intrinsic<[llvm_i1_ty, llvm_anyint_ty],
1986 [llvm_i1_ty], [IntrConvergent, IntrWillReturn]
1987 >;
1988
1989 def int_amdgcn_else : Intrinsic<[llvm_i1_ty, llvm_anyint_ty],
1990 [llvm_anyint_ty], [IntrConvergent, IntrWillReturn]
1991 >;
1992
1993 def int_amdgcn_if_break : Intrinsic<[llvm_anyint_ty],
1994 [llvm_i1_ty, LLVMMatchType<0>],
1995 [IntrNoMem, IntrConvergent, IntrWillReturn]
1996 >;
1997
1998 def int_amdgcn_loop : Intrinsic<[llvm_i1_ty],
1999 [llvm_anyint_ty], [IntrConvergent, IntrWillReturn]
2000 >;
2001
2002 def int_amdgcn_end_cf : Intrinsic<[], [llvm_anyint_ty],
2003 [IntrConvergent, IntrWillReturn]>;
2004
2005 // Represent unreachable in a divergent region.
2006 def int_amdgcn_unreachable : Intrinsic<[], [], [IntrConvergent]>;
2007
2008 // Emit 2.5 ulp, no denormal division. Should only be inserted by
2009 // pass based on !fpmath metadata.
2010 def int_amdgcn_fdiv_fast : Intrinsic<
2011 [llvm_float_ty], [llvm_float_ty, llvm_float_ty],
2012 [IntrNoMem, IntrSpeculatable, IntrWillReturn]
2013 >;
2014
2015 // Represent a relocation constant.
2016 def int_amdgcn_reloc_constant : Intrinsic<
2017 [llvm_i32_ty], [llvm_metadata_ty],
2018 [IntrNoMem, IntrSpeculatable, IntrWillReturn]
2019 >;
2020 }