ac: add ac_build_buffer_store_format() helper
[mesa.git] / src / amd / common / ac_llvm_build.h
1 /*
2 * Copyright 2016 Bas Nieuwenhuizen
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sub license, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
15 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
16 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
17 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
18 * USE OR OTHER DEALINGS IN THE SOFTWARE.
19 *
20 * The above copyright notice and this permission notice (including the
21 * next paragraph) shall be included in all copies or substantial portions
22 * of the Software.
23 *
24 */
25 #ifndef AC_LLVM_BUILD_H
26 #define AC_LLVM_BUILD_H
27
28 #include <stdbool.h>
29 #include <llvm-c/TargetMachine.h>
30 #include "compiler/nir/nir.h"
31 #include "amd_family.h"
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 enum {
38 AC_ADDR_SPACE_FLAT = 0, /* Slower than global. */
39 AC_ADDR_SPACE_GLOBAL = 1,
40 AC_ADDR_SPACE_GDS = 2,
41 AC_ADDR_SPACE_LDS = 3,
42 AC_ADDR_SPACE_CONST = 4, /* Global allowing SMEM. */
43 AC_ADDR_SPACE_CONST_32BIT = 6, /* same as CONST, but the pointer type has 32 bits */
44 };
45
46 /* Combine these with & instead of |. */
47 #define NOOP_WAITCNT 0xcf7f
48 #define LGKM_CNT 0xc07f
49 #define EXP_CNT 0xcf0f
50 #define VM_CNT 0x0f70 /* On GFX9, vmcnt has 6 bits in [0:3] and [14:15] */
51
52 struct ac_llvm_flow;
53
54 struct ac_llvm_context {
55 LLVMContextRef context;
56 LLVMModuleRef module;
57 LLVMBuilderRef builder;
58
59 LLVMTypeRef voidt;
60 LLVMTypeRef i1;
61 LLVMTypeRef i8;
62 LLVMTypeRef i16;
63 LLVMTypeRef i32;
64 LLVMTypeRef i64;
65 LLVMTypeRef intptr;
66 LLVMTypeRef f16;
67 LLVMTypeRef f32;
68 LLVMTypeRef f64;
69 LLVMTypeRef v2i16;
70 LLVMTypeRef v2i32;
71 LLVMTypeRef v3i32;
72 LLVMTypeRef v4i32;
73 LLVMTypeRef v2f32;
74 LLVMTypeRef v4f32;
75 LLVMTypeRef v8i32;
76
77 LLVMValueRef i16_0;
78 LLVMValueRef i16_1;
79 LLVMValueRef i32_0;
80 LLVMValueRef i32_1;
81 LLVMValueRef i64_0;
82 LLVMValueRef i64_1;
83 LLVMValueRef f32_0;
84 LLVMValueRef f32_1;
85 LLVMValueRef f64_0;
86 LLVMValueRef f64_1;
87 LLVMValueRef i1true;
88 LLVMValueRef i1false;
89
90 struct ac_llvm_flow *flow;
91 unsigned flow_depth;
92 unsigned flow_depth_max;
93
94 unsigned range_md_kind;
95 unsigned invariant_load_md_kind;
96 unsigned uniform_md_kind;
97 unsigned fpmath_md_kind;
98 LLVMValueRef fpmath_md_2p5_ulp;
99 LLVMValueRef empty_md;
100
101 enum chip_class chip_class;
102 enum radeon_family family;
103
104 LLVMValueRef lds;
105 };
106
107 void
108 ac_llvm_context_init(struct ac_llvm_context *ctx,
109 enum chip_class chip_class, enum radeon_family family);
110
111 void
112 ac_llvm_context_dispose(struct ac_llvm_context *ctx);
113
114 int
115 ac_get_llvm_num_components(LLVMValueRef value);
116
117 int
118 ac_get_elem_bits(struct ac_llvm_context *ctx, LLVMTypeRef type);
119
120 LLVMValueRef
121 ac_llvm_extract_elem(struct ac_llvm_context *ac,
122 LLVMValueRef value,
123 int index);
124
125 unsigned ac_get_type_size(LLVMTypeRef type);
126
127 LLVMTypeRef ac_to_integer_type(struct ac_llvm_context *ctx, LLVMTypeRef t);
128 LLVMValueRef ac_to_integer(struct ac_llvm_context *ctx, LLVMValueRef v);
129 LLVMValueRef ac_to_integer_or_pointer(struct ac_llvm_context *ctx, LLVMValueRef v);
130 LLVMTypeRef ac_to_float_type(struct ac_llvm_context *ctx, LLVMTypeRef t);
131 LLVMValueRef ac_to_float(struct ac_llvm_context *ctx, LLVMValueRef v);
132
133 LLVMValueRef
134 ac_build_intrinsic(struct ac_llvm_context *ctx, const char *name,
135 LLVMTypeRef return_type, LLVMValueRef *params,
136 unsigned param_count, unsigned attrib_mask);
137
138 void ac_build_type_name_for_intr(LLVMTypeRef type, char *buf, unsigned bufsize);
139
140 LLVMValueRef
141 ac_build_phi(struct ac_llvm_context *ctx, LLVMTypeRef type,
142 unsigned count_incoming, LLVMValueRef *values,
143 LLVMBasicBlockRef *blocks);
144
145 void ac_build_s_barrier(struct ac_llvm_context *ctx);
146 void ac_build_optimization_barrier(struct ac_llvm_context *ctx,
147 LLVMValueRef *pvgpr);
148
149 LLVMValueRef ac_build_shader_clock(struct ac_llvm_context *ctx);
150
151 LLVMValueRef ac_build_ballot(struct ac_llvm_context *ctx, LLVMValueRef value);
152
153 LLVMValueRef ac_build_vote_all(struct ac_llvm_context *ctx, LLVMValueRef value);
154
155 LLVMValueRef ac_build_vote_any(struct ac_llvm_context *ctx, LLVMValueRef value);
156
157 LLVMValueRef ac_build_vote_eq(struct ac_llvm_context *ctx, LLVMValueRef value);
158
159 LLVMValueRef
160 ac_build_varying_gather_values(struct ac_llvm_context *ctx, LLVMValueRef *values,
161 unsigned value_count, unsigned component);
162
163 LLVMValueRef
164 ac_build_gather_values_extended(struct ac_llvm_context *ctx,
165 LLVMValueRef *values,
166 unsigned value_count,
167 unsigned value_stride,
168 bool load,
169 bool always_vector);
170 LLVMValueRef
171 ac_build_gather_values(struct ac_llvm_context *ctx,
172 LLVMValueRef *values,
173 unsigned value_count);
174 LLVMValueRef ac_build_expand_to_vec4(struct ac_llvm_context *ctx,
175 LLVMValueRef value,
176 unsigned num_channels);
177 LLVMValueRef ac_build_round(struct ac_llvm_context *ctx, LLVMValueRef value);
178
179 LLVMValueRef
180 ac_build_fdiv(struct ac_llvm_context *ctx,
181 LLVMValueRef num,
182 LLVMValueRef den);
183
184 LLVMValueRef ac_build_fast_udiv(struct ac_llvm_context *ctx,
185 LLVMValueRef num,
186 LLVMValueRef multiplier,
187 LLVMValueRef pre_shift,
188 LLVMValueRef post_shift,
189 LLVMValueRef increment);
190 LLVMValueRef ac_build_fast_udiv_nuw(struct ac_llvm_context *ctx,
191 LLVMValueRef num,
192 LLVMValueRef multiplier,
193 LLVMValueRef pre_shift,
194 LLVMValueRef post_shift,
195 LLVMValueRef increment);
196 LLVMValueRef ac_build_fast_udiv_u31_d_not_one(struct ac_llvm_context *ctx,
197 LLVMValueRef num,
198 LLVMValueRef multiplier,
199 LLVMValueRef post_shift);
200
201 void
202 ac_prepare_cube_coords(struct ac_llvm_context *ctx,
203 bool is_deriv, bool is_array, bool is_lod,
204 LLVMValueRef *coords_arg,
205 LLVMValueRef *derivs_arg);
206
207
208 LLVMValueRef
209 ac_build_fs_interp(struct ac_llvm_context *ctx,
210 LLVMValueRef llvm_chan,
211 LLVMValueRef attr_number,
212 LLVMValueRef params,
213 LLVMValueRef i,
214 LLVMValueRef j);
215
216 LLVMValueRef
217 ac_build_fs_interp_f16(struct ac_llvm_context *ctx,
218 LLVMValueRef llvm_chan,
219 LLVMValueRef attr_number,
220 LLVMValueRef params,
221 LLVMValueRef i,
222 LLVMValueRef j);
223
224 LLVMValueRef
225 ac_build_fs_interp_mov(struct ac_llvm_context *ctx,
226 LLVMValueRef parameter,
227 LLVMValueRef llvm_chan,
228 LLVMValueRef attr_number,
229 LLVMValueRef params);
230
231 LLVMValueRef
232 ac_build_gep_ptr(struct ac_llvm_context *ctx,
233 LLVMValueRef base_ptr,
234 LLVMValueRef index);
235
236 LLVMValueRef
237 ac_build_gep0(struct ac_llvm_context *ctx,
238 LLVMValueRef base_ptr,
239 LLVMValueRef index);
240 LLVMValueRef ac_build_pointer_add(struct ac_llvm_context *ctx, LLVMValueRef ptr,
241 LLVMValueRef index);
242
243 void
244 ac_build_indexed_store(struct ac_llvm_context *ctx,
245 LLVMValueRef base_ptr, LLVMValueRef index,
246 LLVMValueRef value);
247
248 LLVMValueRef ac_build_load(struct ac_llvm_context *ctx, LLVMValueRef base_ptr,
249 LLVMValueRef index);
250 LLVMValueRef ac_build_load_invariant(struct ac_llvm_context *ctx,
251 LLVMValueRef base_ptr, LLVMValueRef index);
252 LLVMValueRef ac_build_load_to_sgpr(struct ac_llvm_context *ctx,
253 LLVMValueRef base_ptr, LLVMValueRef index);
254 LLVMValueRef ac_build_load_to_sgpr_uint_wraparound(struct ac_llvm_context *ctx,
255 LLVMValueRef base_ptr, LLVMValueRef index);
256
257 void
258 ac_build_buffer_store_dword(struct ac_llvm_context *ctx,
259 LLVMValueRef rsrc,
260 LLVMValueRef vdata,
261 unsigned num_channels,
262 LLVMValueRef voffset,
263 LLVMValueRef soffset,
264 unsigned inst_offset,
265 bool glc,
266 bool slc,
267 bool writeonly_memory,
268 bool swizzle_enable_hint);
269
270 void
271 ac_build_buffer_store_format(struct ac_llvm_context *ctx,
272 LLVMValueRef rsrc,
273 LLVMValueRef data,
274 LLVMValueRef vindex,
275 LLVMValueRef voffset,
276 unsigned num_channels,
277 bool glc,
278 bool writeonly_memory);
279
280 LLVMValueRef
281 ac_build_buffer_load(struct ac_llvm_context *ctx,
282 LLVMValueRef rsrc,
283 int num_channels,
284 LLVMValueRef vindex,
285 LLVMValueRef voffset,
286 LLVMValueRef soffset,
287 unsigned inst_offset,
288 unsigned glc,
289 unsigned slc,
290 bool can_speculate,
291 bool allow_smem);
292
293 LLVMValueRef ac_build_buffer_load_format(struct ac_llvm_context *ctx,
294 LLVMValueRef rsrc,
295 LLVMValueRef vindex,
296 LLVMValueRef voffset,
297 unsigned num_channels,
298 bool glc,
299 bool can_speculate);
300
301 /* load_format that handles the stride & element count better if idxen is
302 * disabled by LLVM. */
303 LLVMValueRef ac_build_buffer_load_format_gfx9_safe(struct ac_llvm_context *ctx,
304 LLVMValueRef rsrc,
305 LLVMValueRef vindex,
306 LLVMValueRef voffset,
307 unsigned num_channels,
308 bool glc,
309 bool can_speculate);
310
311 LLVMValueRef
312 ac_build_tbuffer_load_short(struct ac_llvm_context *ctx,
313 LLVMValueRef rsrc,
314 LLVMValueRef voffset,
315 LLVMValueRef soffset,
316 LLVMValueRef immoffset,
317 bool glc);
318
319 LLVMValueRef
320 ac_build_struct_tbuffer_load(struct ac_llvm_context *ctx,
321 LLVMValueRef rsrc,
322 LLVMValueRef vindex,
323 LLVMValueRef voffset,
324 LLVMValueRef soffset,
325 LLVMValueRef immoffset,
326 unsigned num_channels,
327 unsigned dfmt,
328 unsigned nfmt,
329 bool glc,
330 bool slc,
331 bool can_speculate);
332
333 LLVMValueRef
334 ac_build_raw_tbuffer_load(struct ac_llvm_context *ctx,
335 LLVMValueRef rsrc,
336 LLVMValueRef voffset,
337 LLVMValueRef soffset,
338 LLVMValueRef immoffset,
339 unsigned num_channels,
340 unsigned dfmt,
341 unsigned nfmt,
342 bool glc,
343 bool slc,
344 bool can_speculate);
345
346 LLVMValueRef
347 ac_get_thread_id(struct ac_llvm_context *ctx);
348
349 #define AC_TID_MASK_TOP_LEFT 0xfffffffc
350 #define AC_TID_MASK_TOP 0xfffffffd
351 #define AC_TID_MASK_LEFT 0xfffffffe
352
353 LLVMValueRef
354 ac_build_ddxy(struct ac_llvm_context *ctx,
355 uint32_t mask,
356 int idx,
357 LLVMValueRef val);
358
359 #define AC_SENDMSG_GS 2
360 #define AC_SENDMSG_GS_DONE 3
361
362 #define AC_SENDMSG_GS_OP_NOP (0 << 4)
363 #define AC_SENDMSG_GS_OP_CUT (1 << 4)
364 #define AC_SENDMSG_GS_OP_EMIT (2 << 4)
365 #define AC_SENDMSG_GS_OP_EMIT_CUT (3 << 4)
366
367 void ac_build_sendmsg(struct ac_llvm_context *ctx,
368 uint32_t msg,
369 LLVMValueRef wave_id);
370
371 LLVMValueRef ac_build_imsb(struct ac_llvm_context *ctx,
372 LLVMValueRef arg,
373 LLVMTypeRef dst_type);
374
375 LLVMValueRef ac_build_umsb(struct ac_llvm_context *ctx,
376 LLVMValueRef arg,
377 LLVMTypeRef dst_type);
378 LLVMValueRef ac_build_fmin(struct ac_llvm_context *ctx, LLVMValueRef a,
379 LLVMValueRef b);
380 LLVMValueRef ac_build_fmax(struct ac_llvm_context *ctx, LLVMValueRef a,
381 LLVMValueRef b);
382 LLVMValueRef ac_build_imin(struct ac_llvm_context *ctx, LLVMValueRef a,
383 LLVMValueRef b);
384 LLVMValueRef ac_build_imax(struct ac_llvm_context *ctx, LLVMValueRef a,
385 LLVMValueRef b);
386 LLVMValueRef ac_build_umin(struct ac_llvm_context *ctx, LLVMValueRef a, LLVMValueRef b);
387 LLVMValueRef ac_build_clamp(struct ac_llvm_context *ctx, LLVMValueRef value);
388
389 struct ac_export_args {
390 LLVMValueRef out[4];
391 unsigned target;
392 unsigned enabled_channels;
393 bool compr;
394 bool done;
395 bool valid_mask;
396 };
397
398 void ac_build_export(struct ac_llvm_context *ctx, struct ac_export_args *a);
399
400 void ac_build_export_null(struct ac_llvm_context *ctx);
401
402 enum ac_image_opcode {
403 ac_image_sample,
404 ac_image_gather4,
405 ac_image_load,
406 ac_image_load_mip,
407 ac_image_store,
408 ac_image_store_mip,
409 ac_image_get_lod,
410 ac_image_get_resinfo,
411 ac_image_atomic,
412 ac_image_atomic_cmpswap,
413 };
414
415 enum ac_atomic_op {
416 ac_atomic_swap,
417 ac_atomic_add,
418 ac_atomic_sub,
419 ac_atomic_smin,
420 ac_atomic_umin,
421 ac_atomic_smax,
422 ac_atomic_umax,
423 ac_atomic_and,
424 ac_atomic_or,
425 ac_atomic_xor,
426 };
427
428 enum ac_image_dim {
429 ac_image_1d,
430 ac_image_2d,
431 ac_image_3d,
432 ac_image_cube, // includes cube arrays
433 ac_image_1darray,
434 ac_image_2darray,
435 ac_image_2dmsaa,
436 ac_image_2darraymsaa,
437 };
438
439 /* These cache policy bits match the definitions used by the LLVM intrinsics. */
440 enum ac_image_cache_policy {
441 ac_glc = 1 << 0,
442 ac_slc = 1 << 1,
443 };
444
445 struct ac_image_args {
446 enum ac_image_opcode opcode : 4;
447 enum ac_atomic_op atomic : 4; /* for the ac_image_atomic opcode */
448 enum ac_image_dim dim : 3;
449 unsigned dmask : 4;
450 unsigned cache_policy : 2;
451 bool unorm : 1;
452 bool level_zero : 1;
453 unsigned attributes; /* additional call-site specific AC_FUNC_ATTRs */
454
455 LLVMValueRef resource;
456 LLVMValueRef sampler;
457 LLVMValueRef data[2]; /* data[0] is source data (vector); data[1] is cmp for cmpswap */
458 LLVMValueRef offset;
459 LLVMValueRef bias;
460 LLVMValueRef compare;
461 LLVMValueRef derivs[6];
462 LLVMValueRef coords[4];
463 LLVMValueRef lod; // also used by ac_image_get_resinfo
464 };
465
466 LLVMValueRef ac_build_image_opcode(struct ac_llvm_context *ctx,
467 struct ac_image_args *a);
468 LLVMValueRef ac_build_cvt_pkrtz_f16(struct ac_llvm_context *ctx,
469 LLVMValueRef args[2]);
470 LLVMValueRef ac_build_cvt_pknorm_i16(struct ac_llvm_context *ctx,
471 LLVMValueRef args[2]);
472 LLVMValueRef ac_build_cvt_pknorm_u16(struct ac_llvm_context *ctx,
473 LLVMValueRef args[2]);
474 LLVMValueRef ac_build_cvt_pk_i16(struct ac_llvm_context *ctx,
475 LLVMValueRef args[2], unsigned bits, bool hi);
476 LLVMValueRef ac_build_cvt_pk_u16(struct ac_llvm_context *ctx,
477 LLVMValueRef args[2], unsigned bits, bool hi);
478 LLVMValueRef ac_build_wqm_vote(struct ac_llvm_context *ctx, LLVMValueRef i1);
479 void ac_build_kill_if_false(struct ac_llvm_context *ctx, LLVMValueRef i1);
480 LLVMValueRef ac_build_bfe(struct ac_llvm_context *ctx, LLVMValueRef input,
481 LLVMValueRef offset, LLVMValueRef width,
482 bool is_signed);
483 LLVMValueRef ac_build_imad(struct ac_llvm_context *ctx, LLVMValueRef s0,
484 LLVMValueRef s1, LLVMValueRef s2);
485 LLVMValueRef ac_build_fmad(struct ac_llvm_context *ctx, LLVMValueRef s0,
486 LLVMValueRef s1, LLVMValueRef s2);
487
488 void ac_build_waitcnt(struct ac_llvm_context *ctx, unsigned simm16);
489
490 LLVMValueRef ac_build_fract(struct ac_llvm_context *ctx, LLVMValueRef src0,
491 unsigned bitsize);
492
493 LLVMValueRef ac_build_isign(struct ac_llvm_context *ctx, LLVMValueRef src0,
494 unsigned bitsize);
495
496 LLVMValueRef ac_build_fsign(struct ac_llvm_context *ctx, LLVMValueRef src0,
497 unsigned bitsize);
498
499 LLVMValueRef ac_build_bit_count(struct ac_llvm_context *ctx, LLVMValueRef src0);
500
501 LLVMValueRef ac_build_bitfield_reverse(struct ac_llvm_context *ctx,
502 LLVMValueRef src0);
503
504 void ac_optimize_vs_outputs(struct ac_llvm_context *ac,
505 LLVMValueRef main_fn,
506 uint8_t *vs_output_param_offset,
507 uint32_t num_outputs,
508 uint8_t *num_param_exports);
509 void ac_init_exec_full_mask(struct ac_llvm_context *ctx);
510
511 void ac_declare_lds_as_pointer(struct ac_llvm_context *ac);
512 LLVMValueRef ac_lds_load(struct ac_llvm_context *ctx,
513 LLVMValueRef dw_addr);
514 void ac_lds_store(struct ac_llvm_context *ctx,
515 LLVMValueRef dw_addr, LLVMValueRef value);
516
517 LLVMValueRef ac_find_lsb(struct ac_llvm_context *ctx,
518 LLVMTypeRef dst_type,
519 LLVMValueRef src0);
520
521 LLVMTypeRef ac_array_in_const_addr_space(LLVMTypeRef elem_type);
522 LLVMTypeRef ac_array_in_const32_addr_space(LLVMTypeRef elem_type);
523
524 void ac_build_bgnloop(struct ac_llvm_context *ctx, int lable_id);
525 void ac_build_break(struct ac_llvm_context *ctx);
526 void ac_build_continue(struct ac_llvm_context *ctx);
527 void ac_build_else(struct ac_llvm_context *ctx, int lable_id);
528 void ac_build_endif(struct ac_llvm_context *ctx, int lable_id);
529 void ac_build_endloop(struct ac_llvm_context *ctx, int lable_id);
530 void ac_build_ifcc(struct ac_llvm_context *ctx, LLVMValueRef cond, int label_id);
531 void ac_build_if(struct ac_llvm_context *ctx, LLVMValueRef value,
532 int lable_id);
533 void ac_build_uif(struct ac_llvm_context *ctx, LLVMValueRef value,
534 int lable_id);
535
536 LLVMValueRef ac_build_alloca(struct ac_llvm_context *ac, LLVMTypeRef type,
537 const char *name);
538 LLVMValueRef ac_build_alloca_undef(struct ac_llvm_context *ac, LLVMTypeRef type,
539 const char *name);
540
541 LLVMValueRef ac_cast_ptr(struct ac_llvm_context *ctx, LLVMValueRef ptr,
542 LLVMTypeRef type);
543
544 LLVMValueRef ac_trim_vector(struct ac_llvm_context *ctx, LLVMValueRef value,
545 unsigned count);
546
547 LLVMValueRef ac_unpack_param(struct ac_llvm_context *ctx, LLVMValueRef param,
548 unsigned rshift, unsigned bitwidth);
549
550 void ac_apply_fmask_to_sample(struct ac_llvm_context *ac, LLVMValueRef fmask,
551 LLVMValueRef *addr, bool is_array_tex);
552
553 LLVMValueRef
554 ac_build_ds_swizzle(struct ac_llvm_context *ctx, LLVMValueRef src, unsigned mask);
555
556 LLVMValueRef
557 ac_build_readlane(struct ac_llvm_context *ctx, LLVMValueRef src, LLVMValueRef lane);
558
559 LLVMValueRef
560 ac_build_writelane(struct ac_llvm_context *ctx, LLVMValueRef src, LLVMValueRef value, LLVMValueRef lane);
561
562 LLVMValueRef
563 ac_build_mbcnt(struct ac_llvm_context *ctx, LLVMValueRef mask);
564
565 LLVMValueRef
566 ac_build_inclusive_scan(struct ac_llvm_context *ctx, LLVMValueRef src, nir_op op);
567
568 LLVMValueRef
569 ac_build_exclusive_scan(struct ac_llvm_context *ctx, LLVMValueRef src, nir_op op);
570
571 LLVMValueRef
572 ac_build_reduce(struct ac_llvm_context *ctx, LLVMValueRef src, nir_op op, unsigned cluster_size);
573
574 /**
575 * Common arguments for a scan/reduce operation that accumulates per-wave
576 * values across an entire workgroup, while respecting the order of waves.
577 */
578 struct ac_wg_scan {
579 bool enable_reduce;
580 bool enable_exclusive;
581 bool enable_inclusive;
582 nir_op op;
583 LLVMValueRef src; /* clobbered! */
584 LLVMValueRef result_reduce;
585 LLVMValueRef result_exclusive;
586 LLVMValueRef result_inclusive;
587 LLVMValueRef extra;
588 LLVMValueRef waveidx;
589 LLVMValueRef numwaves; /* only needed for "reduce" operations */
590
591 /* T addrspace(LDS) pointer to the same type as value, at least maxwaves entries */
592 LLVMValueRef scratch;
593 unsigned maxwaves;
594 };
595
596 void
597 ac_build_wg_wavescan_top(struct ac_llvm_context *ctx, struct ac_wg_scan *ws);
598 void
599 ac_build_wg_wavescan_bottom(struct ac_llvm_context *ctx, struct ac_wg_scan *ws);
600 void
601 ac_build_wg_wavescan(struct ac_llvm_context *ctx, struct ac_wg_scan *ws);
602
603 void
604 ac_build_wg_scan_top(struct ac_llvm_context *ctx, struct ac_wg_scan *ws);
605 void
606 ac_build_wg_scan_bottom(struct ac_llvm_context *ctx, struct ac_wg_scan *ws);
607 void
608 ac_build_wg_scan(struct ac_llvm_context *ctx, struct ac_wg_scan *ws);
609
610 LLVMValueRef
611 ac_build_quad_swizzle(struct ac_llvm_context *ctx, LLVMValueRef src,
612 unsigned lane0, unsigned lane1, unsigned lane2, unsigned lane3);
613
614 LLVMValueRef
615 ac_build_shuffle(struct ac_llvm_context *ctx, LLVMValueRef src, LLVMValueRef index);
616
617 #ifdef __cplusplus
618 }
619 #endif
620
621 #endif