ac/nir: Implement LLVM9 64-bit buffer compare & exchange.
[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/Core.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 #define AC_WAIT_LGKM (1 << 0) /* LDS, GDS, constant, message */
47 #define AC_WAIT_VLOAD (1 << 1) /* VMEM load/sample instructions */
48 #define AC_WAIT_VSTORE (1 << 2) /* VMEM store instructions */
49
50 struct ac_llvm_flow;
51 struct ac_llvm_compiler;
52 enum ac_float_mode;
53
54 struct ac_llvm_flow_state {
55 struct ac_llvm_flow *stack;
56 unsigned depth_max;
57 unsigned depth;
58 };
59
60 struct ac_llvm_context {
61 LLVMContextRef context;
62 LLVMModuleRef module;
63 LLVMBuilderRef builder;
64
65 LLVMTypeRef voidt;
66 LLVMTypeRef i1;
67 LLVMTypeRef i8;
68 LLVMTypeRef i16;
69 LLVMTypeRef i32;
70 LLVMTypeRef i64;
71 LLVMTypeRef intptr;
72 LLVMTypeRef f16;
73 LLVMTypeRef f32;
74 LLVMTypeRef f64;
75 LLVMTypeRef v2i16;
76 LLVMTypeRef v2i32;
77 LLVMTypeRef v3i32;
78 LLVMTypeRef v4i32;
79 LLVMTypeRef v2f32;
80 LLVMTypeRef v3f32;
81 LLVMTypeRef v4f32;
82 LLVMTypeRef v8i32;
83 LLVMTypeRef iN_wavemask;
84
85 LLVMValueRef i8_0;
86 LLVMValueRef i8_1;
87 LLVMValueRef i16_0;
88 LLVMValueRef i16_1;
89 LLVMValueRef i32_0;
90 LLVMValueRef i32_1;
91 LLVMValueRef i64_0;
92 LLVMValueRef i64_1;
93 LLVMValueRef f16_0;
94 LLVMValueRef f16_1;
95 LLVMValueRef f32_0;
96 LLVMValueRef f32_1;
97 LLVMValueRef f64_0;
98 LLVMValueRef f64_1;
99 LLVMValueRef i1true;
100 LLVMValueRef i1false;
101
102 /* Since ac_nir_translate makes a local copy of ac_llvm_context, there
103 * are two ac_llvm_contexts. Declare a pointer here, so that the control
104 * flow stack is shared by both ac_llvm_contexts.
105 */
106 struct ac_llvm_flow_state *flow;
107
108 unsigned range_md_kind;
109 unsigned invariant_load_md_kind;
110 unsigned uniform_md_kind;
111 unsigned fpmath_md_kind;
112 LLVMValueRef fpmath_md_2p5_ulp;
113 LLVMValueRef empty_md;
114
115 enum chip_class chip_class;
116 enum radeon_family family;
117 unsigned wave_size;
118
119 LLVMValueRef lds;
120 };
121
122 void
123 ac_llvm_context_init(struct ac_llvm_context *ctx,
124 struct ac_llvm_compiler *compiler,
125 enum chip_class chip_class, enum radeon_family family,
126 enum ac_float_mode float_mode, unsigned wave_size);
127
128 void
129 ac_llvm_context_dispose(struct ac_llvm_context *ctx);
130
131 int
132 ac_get_llvm_num_components(LLVMValueRef value);
133
134 int
135 ac_get_elem_bits(struct ac_llvm_context *ctx, LLVMTypeRef type);
136
137 LLVMValueRef
138 ac_llvm_extract_elem(struct ac_llvm_context *ac,
139 LLVMValueRef value,
140 int index);
141
142 unsigned ac_get_type_size(LLVMTypeRef type);
143
144 LLVMTypeRef ac_to_integer_type(struct ac_llvm_context *ctx, LLVMTypeRef t);
145 LLVMValueRef ac_to_integer(struct ac_llvm_context *ctx, LLVMValueRef v);
146 LLVMValueRef ac_to_integer_or_pointer(struct ac_llvm_context *ctx, LLVMValueRef v);
147 LLVMTypeRef ac_to_float_type(struct ac_llvm_context *ctx, LLVMTypeRef t);
148 LLVMValueRef ac_to_float(struct ac_llvm_context *ctx, LLVMValueRef v);
149
150 LLVMValueRef
151 ac_build_intrinsic(struct ac_llvm_context *ctx, const char *name,
152 LLVMTypeRef return_type, LLVMValueRef *params,
153 unsigned param_count, unsigned attrib_mask);
154
155 void ac_build_type_name_for_intr(LLVMTypeRef type, char *buf, unsigned bufsize);
156
157 LLVMValueRef
158 ac_build_phi(struct ac_llvm_context *ctx, LLVMTypeRef type,
159 unsigned count_incoming, LLVMValueRef *values,
160 LLVMBasicBlockRef *blocks);
161
162 void ac_build_s_barrier(struct ac_llvm_context *ctx);
163 void ac_build_optimization_barrier(struct ac_llvm_context *ctx,
164 LLVMValueRef *pvgpr);
165
166 LLVMValueRef ac_build_shader_clock(struct ac_llvm_context *ctx);
167
168 LLVMValueRef ac_build_ballot(struct ac_llvm_context *ctx, LLVMValueRef value);
169 LLVMValueRef ac_get_i1_sgpr_mask(struct ac_llvm_context *ctx,
170 LLVMValueRef value);
171
172 LLVMValueRef ac_build_vote_all(struct ac_llvm_context *ctx, LLVMValueRef value);
173
174 LLVMValueRef ac_build_vote_any(struct ac_llvm_context *ctx, LLVMValueRef value);
175
176 LLVMValueRef ac_build_vote_eq(struct ac_llvm_context *ctx, LLVMValueRef value);
177
178 LLVMValueRef
179 ac_build_varying_gather_values(struct ac_llvm_context *ctx, LLVMValueRef *values,
180 unsigned value_count, unsigned component);
181
182 LLVMValueRef
183 ac_build_gather_values_extended(struct ac_llvm_context *ctx,
184 LLVMValueRef *values,
185 unsigned value_count,
186 unsigned value_stride,
187 bool load,
188 bool always_vector);
189 LLVMValueRef
190 ac_build_gather_values(struct ac_llvm_context *ctx,
191 LLVMValueRef *values,
192 unsigned value_count);
193 LLVMValueRef ac_build_expand_to_vec4(struct ac_llvm_context *ctx,
194 LLVMValueRef value,
195 unsigned num_channels);
196 LLVMValueRef ac_build_round(struct ac_llvm_context *ctx, LLVMValueRef value);
197
198 LLVMValueRef
199 ac_build_fdiv(struct ac_llvm_context *ctx,
200 LLVMValueRef num,
201 LLVMValueRef den);
202
203 LLVMValueRef ac_build_fast_udiv(struct ac_llvm_context *ctx,
204 LLVMValueRef num,
205 LLVMValueRef multiplier,
206 LLVMValueRef pre_shift,
207 LLVMValueRef post_shift,
208 LLVMValueRef increment);
209 LLVMValueRef ac_build_fast_udiv_nuw(struct ac_llvm_context *ctx,
210 LLVMValueRef num,
211 LLVMValueRef multiplier,
212 LLVMValueRef pre_shift,
213 LLVMValueRef post_shift,
214 LLVMValueRef increment);
215 LLVMValueRef ac_build_fast_udiv_u31_d_not_one(struct ac_llvm_context *ctx,
216 LLVMValueRef num,
217 LLVMValueRef multiplier,
218 LLVMValueRef post_shift);
219
220 void
221 ac_prepare_cube_coords(struct ac_llvm_context *ctx,
222 bool is_deriv, bool is_array, bool is_lod,
223 LLVMValueRef *coords_arg,
224 LLVMValueRef *derivs_arg);
225
226
227 LLVMValueRef
228 ac_build_fs_interp(struct ac_llvm_context *ctx,
229 LLVMValueRef llvm_chan,
230 LLVMValueRef attr_number,
231 LLVMValueRef params,
232 LLVMValueRef i,
233 LLVMValueRef j);
234
235 LLVMValueRef
236 ac_build_fs_interp_f16(struct ac_llvm_context *ctx,
237 LLVMValueRef llvm_chan,
238 LLVMValueRef attr_number,
239 LLVMValueRef params,
240 LLVMValueRef i,
241 LLVMValueRef j);
242
243 LLVMValueRef
244 ac_build_fs_interp_mov(struct ac_llvm_context *ctx,
245 LLVMValueRef parameter,
246 LLVMValueRef llvm_chan,
247 LLVMValueRef attr_number,
248 LLVMValueRef params);
249
250 LLVMValueRef
251 ac_build_gep_ptr(struct ac_llvm_context *ctx,
252 LLVMValueRef base_ptr,
253 LLVMValueRef index);
254
255 LLVMValueRef
256 ac_build_gep0(struct ac_llvm_context *ctx,
257 LLVMValueRef base_ptr,
258 LLVMValueRef index);
259 LLVMValueRef ac_build_pointer_add(struct ac_llvm_context *ctx, LLVMValueRef ptr,
260 LLVMValueRef index);
261
262 void
263 ac_build_indexed_store(struct ac_llvm_context *ctx,
264 LLVMValueRef base_ptr, LLVMValueRef index,
265 LLVMValueRef value);
266
267 LLVMValueRef ac_build_load(struct ac_llvm_context *ctx, LLVMValueRef base_ptr,
268 LLVMValueRef index);
269 LLVMValueRef ac_build_load_invariant(struct ac_llvm_context *ctx,
270 LLVMValueRef base_ptr, LLVMValueRef index);
271 LLVMValueRef ac_build_load_to_sgpr(struct ac_llvm_context *ctx,
272 LLVMValueRef base_ptr, LLVMValueRef index);
273 LLVMValueRef ac_build_load_to_sgpr_uint_wraparound(struct ac_llvm_context *ctx,
274 LLVMValueRef base_ptr, LLVMValueRef index);
275
276 void
277 ac_build_buffer_store_dword(struct ac_llvm_context *ctx,
278 LLVMValueRef rsrc,
279 LLVMValueRef vdata,
280 unsigned num_channels,
281 LLVMValueRef voffset,
282 LLVMValueRef soffset,
283 unsigned inst_offset,
284 unsigned cache_policy,
285 bool swizzle_enable_hint);
286
287 void
288 ac_build_buffer_store_format(struct ac_llvm_context *ctx,
289 LLVMValueRef rsrc,
290 LLVMValueRef data,
291 LLVMValueRef vindex,
292 LLVMValueRef voffset,
293 unsigned num_channels,
294 unsigned cache_policy);
295
296 LLVMValueRef
297 ac_build_buffer_load(struct ac_llvm_context *ctx,
298 LLVMValueRef rsrc,
299 int num_channels,
300 LLVMValueRef vindex,
301 LLVMValueRef voffset,
302 LLVMValueRef soffset,
303 unsigned inst_offset,
304 unsigned cache_policy,
305 bool can_speculate,
306 bool allow_smem);
307
308 LLVMValueRef ac_build_buffer_load_format(struct ac_llvm_context *ctx,
309 LLVMValueRef rsrc,
310 LLVMValueRef vindex,
311 LLVMValueRef voffset,
312 unsigned num_channels,
313 unsigned cache_policy,
314 bool can_speculate);
315
316 /* load_format that handles the stride & element count better if idxen is
317 * disabled by LLVM. */
318 LLVMValueRef ac_build_buffer_load_format_gfx9_safe(struct ac_llvm_context *ctx,
319 LLVMValueRef rsrc,
320 LLVMValueRef vindex,
321 LLVMValueRef voffset,
322 unsigned num_channels,
323 unsigned cache_policy,
324 bool can_speculate);
325
326 LLVMValueRef
327 ac_build_tbuffer_load_short(struct ac_llvm_context *ctx,
328 LLVMValueRef rsrc,
329 LLVMValueRef voffset,
330 LLVMValueRef soffset,
331 LLVMValueRef immoffset,
332 unsigned cache_policy);
333
334 LLVMValueRef
335 ac_build_tbuffer_load_byte(struct ac_llvm_context *ctx,
336 LLVMValueRef rsrc,
337 LLVMValueRef voffset,
338 LLVMValueRef soffset,
339 LLVMValueRef immoffset,
340 unsigned cache_policy);
341
342 LLVMValueRef
343 ac_build_struct_tbuffer_load(struct ac_llvm_context *ctx,
344 LLVMValueRef rsrc,
345 LLVMValueRef vindex,
346 LLVMValueRef voffset,
347 LLVMValueRef soffset,
348 LLVMValueRef immoffset,
349 unsigned num_channels,
350 unsigned dfmt,
351 unsigned nfmt,
352 unsigned cache_policy,
353 bool can_speculate);
354
355 LLVMValueRef
356 ac_build_raw_tbuffer_load(struct ac_llvm_context *ctx,
357 LLVMValueRef rsrc,
358 LLVMValueRef voffset,
359 LLVMValueRef soffset,
360 LLVMValueRef immoffset,
361 unsigned num_channels,
362 unsigned dfmt,
363 unsigned nfmt,
364 unsigned cache_policy,
365 bool can_speculate);
366
367 /* For ac_build_fetch_format.
368 *
369 * Note: FLOAT must be 0 (used for convenience of encoding in radeonsi).
370 */
371 enum {
372 AC_FETCH_FORMAT_FLOAT = 0,
373 AC_FETCH_FORMAT_FIXED,
374 AC_FETCH_FORMAT_UNORM,
375 AC_FETCH_FORMAT_SNORM,
376 AC_FETCH_FORMAT_USCALED,
377 AC_FETCH_FORMAT_SSCALED,
378 AC_FETCH_FORMAT_UINT,
379 AC_FETCH_FORMAT_SINT,
380 };
381
382 LLVMValueRef
383 ac_build_opencoded_load_format(struct ac_llvm_context *ctx,
384 unsigned log_size,
385 unsigned num_channels,
386 unsigned format,
387 bool reverse,
388 bool known_aligned,
389 LLVMValueRef rsrc,
390 LLVMValueRef vindex,
391 LLVMValueRef voffset,
392 LLVMValueRef soffset,
393 unsigned cache_policy,
394 bool can_speculate);
395
396 void
397 ac_build_tbuffer_store_short(struct ac_llvm_context *ctx,
398 LLVMValueRef rsrc,
399 LLVMValueRef vdata,
400 LLVMValueRef voffset,
401 LLVMValueRef soffset,
402 unsigned cache_policy);
403
404 void
405 ac_build_tbuffer_store_byte(struct ac_llvm_context *ctx,
406 LLVMValueRef rsrc,
407 LLVMValueRef vdata,
408 LLVMValueRef voffset,
409 LLVMValueRef soffset,
410 unsigned cache_policy);
411
412 void
413 ac_build_struct_tbuffer_store(struct ac_llvm_context *ctx,
414 LLVMValueRef rsrc,
415 LLVMValueRef vdata,
416 LLVMValueRef vindex,
417 LLVMValueRef voffset,
418 LLVMValueRef soffset,
419 LLVMValueRef immoffset,
420 unsigned num_channels,
421 unsigned dfmt,
422 unsigned nfmt,
423 unsigned cache_policy);
424
425 void
426 ac_build_raw_tbuffer_store(struct ac_llvm_context *ctx,
427 LLVMValueRef rsrc,
428 LLVMValueRef vdata,
429 LLVMValueRef voffset,
430 LLVMValueRef soffset,
431 LLVMValueRef immoffset,
432 unsigned num_channels,
433 unsigned dfmt,
434 unsigned nfmt,
435 unsigned cache_policy);
436
437 LLVMValueRef
438 ac_get_thread_id(struct ac_llvm_context *ctx);
439
440 #define AC_TID_MASK_TOP_LEFT 0xfffffffc
441 #define AC_TID_MASK_TOP 0xfffffffd
442 #define AC_TID_MASK_LEFT 0xfffffffe
443
444 LLVMValueRef
445 ac_build_ddxy(struct ac_llvm_context *ctx,
446 uint32_t mask,
447 int idx,
448 LLVMValueRef val);
449
450 #define AC_SENDMSG_GS 2
451 #define AC_SENDMSG_GS_DONE 3
452 #define AC_SENDMSG_GS_ALLOC_REQ 9
453
454 #define AC_SENDMSG_GS_OP_NOP (0 << 4)
455 #define AC_SENDMSG_GS_OP_CUT (1 << 4)
456 #define AC_SENDMSG_GS_OP_EMIT (2 << 4)
457 #define AC_SENDMSG_GS_OP_EMIT_CUT (3 << 4)
458
459 void ac_build_sendmsg(struct ac_llvm_context *ctx,
460 uint32_t msg,
461 LLVMValueRef wave_id);
462
463 LLVMValueRef ac_build_imsb(struct ac_llvm_context *ctx,
464 LLVMValueRef arg,
465 LLVMTypeRef dst_type);
466
467 LLVMValueRef ac_build_umsb(struct ac_llvm_context *ctx,
468 LLVMValueRef arg,
469 LLVMTypeRef dst_type);
470 LLVMValueRef ac_build_fmin(struct ac_llvm_context *ctx, LLVMValueRef a,
471 LLVMValueRef b);
472 LLVMValueRef ac_build_fmax(struct ac_llvm_context *ctx, LLVMValueRef a,
473 LLVMValueRef b);
474 LLVMValueRef ac_build_imin(struct ac_llvm_context *ctx, LLVMValueRef a,
475 LLVMValueRef b);
476 LLVMValueRef ac_build_imax(struct ac_llvm_context *ctx, LLVMValueRef a,
477 LLVMValueRef b);
478 LLVMValueRef ac_build_umin(struct ac_llvm_context *ctx, LLVMValueRef a, LLVMValueRef b);
479 LLVMValueRef ac_build_umax(struct ac_llvm_context *ctx, LLVMValueRef a, LLVMValueRef b);
480 LLVMValueRef ac_build_clamp(struct ac_llvm_context *ctx, LLVMValueRef value);
481
482 struct ac_export_args {
483 LLVMValueRef out[4];
484 unsigned target;
485 unsigned enabled_channels;
486 bool compr;
487 bool done;
488 bool valid_mask;
489 };
490
491 void ac_build_export(struct ac_llvm_context *ctx, struct ac_export_args *a);
492
493 void ac_build_export_null(struct ac_llvm_context *ctx);
494
495 enum ac_image_opcode {
496 ac_image_sample,
497 ac_image_gather4,
498 ac_image_load,
499 ac_image_load_mip,
500 ac_image_store,
501 ac_image_store_mip,
502 ac_image_get_lod,
503 ac_image_get_resinfo,
504 ac_image_atomic,
505 ac_image_atomic_cmpswap,
506 };
507
508 enum ac_atomic_op {
509 ac_atomic_swap,
510 ac_atomic_add,
511 ac_atomic_sub,
512 ac_atomic_smin,
513 ac_atomic_umin,
514 ac_atomic_smax,
515 ac_atomic_umax,
516 ac_atomic_and,
517 ac_atomic_or,
518 ac_atomic_xor,
519 };
520
521 enum ac_image_dim {
522 ac_image_1d,
523 ac_image_2d,
524 ac_image_3d,
525 ac_image_cube, // includes cube arrays
526 ac_image_1darray,
527 ac_image_2darray,
528 ac_image_2dmsaa,
529 ac_image_2darraymsaa,
530 };
531
532 /* These cache policy bits match the definitions used by the LLVM intrinsics. */
533 enum ac_image_cache_policy {
534 ac_glc = 1 << 0, /* per-CU cache control */
535 ac_slc = 1 << 1, /* global L2 cache control */
536 ac_dlc = 1 << 2, /* per-shader-array cache control */
537 };
538
539 struct ac_image_args {
540 enum ac_image_opcode opcode : 4;
541 enum ac_atomic_op atomic : 4; /* for the ac_image_atomic opcode */
542 enum ac_image_dim dim : 3;
543 unsigned dmask : 4;
544 unsigned cache_policy : 3;
545 bool unorm : 1;
546 bool level_zero : 1;
547 unsigned attributes; /* additional call-site specific AC_FUNC_ATTRs */
548
549 LLVMValueRef resource;
550 LLVMValueRef sampler;
551 LLVMValueRef data[2]; /* data[0] is source data (vector); data[1] is cmp for cmpswap */
552 LLVMValueRef offset;
553 LLVMValueRef bias;
554 LLVMValueRef compare;
555 LLVMValueRef derivs[6];
556 LLVMValueRef coords[4];
557 LLVMValueRef lod; // also used by ac_image_get_resinfo
558 };
559
560 LLVMValueRef ac_build_image_opcode(struct ac_llvm_context *ctx,
561 struct ac_image_args *a);
562 LLVMValueRef ac_build_cvt_pkrtz_f16(struct ac_llvm_context *ctx,
563 LLVMValueRef args[2]);
564 LLVMValueRef ac_build_cvt_pknorm_i16(struct ac_llvm_context *ctx,
565 LLVMValueRef args[2]);
566 LLVMValueRef ac_build_cvt_pknorm_u16(struct ac_llvm_context *ctx,
567 LLVMValueRef args[2]);
568 LLVMValueRef ac_build_cvt_pk_i16(struct ac_llvm_context *ctx,
569 LLVMValueRef args[2], unsigned bits, bool hi);
570 LLVMValueRef ac_build_cvt_pk_u16(struct ac_llvm_context *ctx,
571 LLVMValueRef args[2], unsigned bits, bool hi);
572 LLVMValueRef ac_build_wqm_vote(struct ac_llvm_context *ctx, LLVMValueRef i1);
573 void ac_build_kill_if_false(struct ac_llvm_context *ctx, LLVMValueRef i1);
574 LLVMValueRef ac_build_bfe(struct ac_llvm_context *ctx, LLVMValueRef input,
575 LLVMValueRef offset, LLVMValueRef width,
576 bool is_signed);
577 LLVMValueRef ac_build_imad(struct ac_llvm_context *ctx, LLVMValueRef s0,
578 LLVMValueRef s1, LLVMValueRef s2);
579 LLVMValueRef ac_build_fmad(struct ac_llvm_context *ctx, LLVMValueRef s0,
580 LLVMValueRef s1, LLVMValueRef s2);
581
582 void ac_build_waitcnt(struct ac_llvm_context *ctx, unsigned wait_flags);
583
584 LLVMValueRef ac_build_fract(struct ac_llvm_context *ctx, LLVMValueRef src0,
585 unsigned bitsize);
586
587 LLVMValueRef ac_build_fmed3(struct ac_llvm_context *ctx, LLVMValueRef src0,
588 LLVMValueRef src1, LLVMValueRef src2,
589 unsigned bitsize);
590
591 LLVMValueRef ac_build_isign(struct ac_llvm_context *ctx, LLVMValueRef src0,
592 unsigned bitsize);
593
594 LLVMValueRef ac_build_fsign(struct ac_llvm_context *ctx, LLVMValueRef src0,
595 unsigned bitsize);
596
597 LLVMValueRef ac_build_bit_count(struct ac_llvm_context *ctx, LLVMValueRef src0);
598
599 LLVMValueRef ac_build_bitfield_reverse(struct ac_llvm_context *ctx,
600 LLVMValueRef src0);
601
602 void ac_optimize_vs_outputs(struct ac_llvm_context *ac,
603 LLVMValueRef main_fn,
604 uint8_t *vs_output_param_offset,
605 uint32_t num_outputs,
606 uint8_t *num_param_exports);
607 void ac_init_exec_full_mask(struct ac_llvm_context *ctx);
608
609 void ac_declare_lds_as_pointer(struct ac_llvm_context *ac);
610 LLVMValueRef ac_lds_load(struct ac_llvm_context *ctx,
611 LLVMValueRef dw_addr);
612 void ac_lds_store(struct ac_llvm_context *ctx,
613 LLVMValueRef dw_addr, LLVMValueRef value);
614
615 LLVMValueRef ac_find_lsb(struct ac_llvm_context *ctx,
616 LLVMTypeRef dst_type,
617 LLVMValueRef src0);
618
619 LLVMTypeRef ac_array_in_const_addr_space(LLVMTypeRef elem_type);
620 LLVMTypeRef ac_array_in_const32_addr_space(LLVMTypeRef elem_type);
621
622 void ac_build_bgnloop(struct ac_llvm_context *ctx, int lable_id);
623 void ac_build_break(struct ac_llvm_context *ctx);
624 void ac_build_continue(struct ac_llvm_context *ctx);
625 void ac_build_else(struct ac_llvm_context *ctx, int lable_id);
626 void ac_build_endif(struct ac_llvm_context *ctx, int lable_id);
627 void ac_build_endloop(struct ac_llvm_context *ctx, int lable_id);
628 void ac_build_ifcc(struct ac_llvm_context *ctx, LLVMValueRef cond, int label_id);
629 void ac_build_if(struct ac_llvm_context *ctx, LLVMValueRef value,
630 int lable_id);
631 void ac_build_uif(struct ac_llvm_context *ctx, LLVMValueRef value,
632 int lable_id);
633
634 LLVMValueRef ac_build_alloca(struct ac_llvm_context *ac, LLVMTypeRef type,
635 const char *name);
636 LLVMValueRef ac_build_alloca_undef(struct ac_llvm_context *ac, LLVMTypeRef type,
637 const char *name);
638
639 LLVMValueRef ac_cast_ptr(struct ac_llvm_context *ctx, LLVMValueRef ptr,
640 LLVMTypeRef type);
641
642 LLVMValueRef ac_trim_vector(struct ac_llvm_context *ctx, LLVMValueRef value,
643 unsigned count);
644
645 LLVMValueRef ac_unpack_param(struct ac_llvm_context *ctx, LLVMValueRef param,
646 unsigned rshift, unsigned bitwidth);
647
648 void ac_apply_fmask_to_sample(struct ac_llvm_context *ac, LLVMValueRef fmask,
649 LLVMValueRef *addr, bool is_array_tex);
650
651 LLVMValueRef
652 ac_build_ds_swizzle(struct ac_llvm_context *ctx, LLVMValueRef src, unsigned mask);
653
654 LLVMValueRef
655 ac_build_readlane(struct ac_llvm_context *ctx, LLVMValueRef src, LLVMValueRef lane);
656
657 LLVMValueRef
658 ac_build_writelane(struct ac_llvm_context *ctx, LLVMValueRef src, LLVMValueRef value, LLVMValueRef lane);
659
660 LLVMValueRef
661 ac_build_mbcnt(struct ac_llvm_context *ctx, LLVMValueRef mask);
662
663 LLVMValueRef
664 ac_build_inclusive_scan(struct ac_llvm_context *ctx, LLVMValueRef src, nir_op op);
665
666 LLVMValueRef
667 ac_build_exclusive_scan(struct ac_llvm_context *ctx, LLVMValueRef src, nir_op op);
668
669 LLVMValueRef
670 ac_build_reduce(struct ac_llvm_context *ctx, LLVMValueRef src, nir_op op, unsigned cluster_size);
671
672 /**
673 * Common arguments for a scan/reduce operation that accumulates per-wave
674 * values across an entire workgroup, while respecting the order of waves.
675 */
676 struct ac_wg_scan {
677 bool enable_reduce;
678 bool enable_exclusive;
679 bool enable_inclusive;
680 nir_op op;
681 LLVMValueRef src; /* clobbered! */
682 LLVMValueRef result_reduce;
683 LLVMValueRef result_exclusive;
684 LLVMValueRef result_inclusive;
685 LLVMValueRef extra;
686 LLVMValueRef waveidx;
687 LLVMValueRef numwaves; /* only needed for "reduce" operations */
688
689 /* T addrspace(LDS) pointer to the same type as value, at least maxwaves entries */
690 LLVMValueRef scratch;
691 unsigned maxwaves;
692 };
693
694 void
695 ac_build_wg_wavescan_top(struct ac_llvm_context *ctx, struct ac_wg_scan *ws);
696 void
697 ac_build_wg_wavescan_bottom(struct ac_llvm_context *ctx, struct ac_wg_scan *ws);
698 void
699 ac_build_wg_wavescan(struct ac_llvm_context *ctx, struct ac_wg_scan *ws);
700
701 void
702 ac_build_wg_scan_top(struct ac_llvm_context *ctx, struct ac_wg_scan *ws);
703 void
704 ac_build_wg_scan_bottom(struct ac_llvm_context *ctx, struct ac_wg_scan *ws);
705 void
706 ac_build_wg_scan(struct ac_llvm_context *ctx, struct ac_wg_scan *ws);
707
708 LLVMValueRef
709 ac_build_quad_swizzle(struct ac_llvm_context *ctx, LLVMValueRef src,
710 unsigned lane0, unsigned lane1, unsigned lane2, unsigned lane3);
711
712 LLVMValueRef
713 ac_build_shuffle(struct ac_llvm_context *ctx, LLVMValueRef src, LLVMValueRef index);
714
715 LLVMValueRef
716 ac_build_frexp_exp(struct ac_llvm_context *ctx, LLVMValueRef src0,
717 unsigned bitsize);
718
719 LLVMValueRef
720 ac_build_frexp_mant(struct ac_llvm_context *ctx, LLVMValueRef src0,
721 unsigned bitsize);
722
723 LLVMValueRef
724 ac_build_ddxy_interp(struct ac_llvm_context *ctx, LLVMValueRef interp_ij);
725
726 LLVMValueRef
727 ac_build_load_helper_invocation(struct ac_llvm_context *ctx);
728
729 LLVMValueRef ac_build_call(struct ac_llvm_context *ctx, LLVMValueRef func,
730 LLVMValueRef *args, unsigned num_args);
731
732 LLVMValueRef ac_build_atomic_rmw(struct ac_llvm_context *ctx, LLVMAtomicRMWBinOp op,
733 LLVMValueRef ptr, LLVMValueRef val,
734 const char *sync_scope);
735
736 LLVMValueRef ac_build_atomic_cmp_xchg(struct ac_llvm_context *ctx, LLVMValueRef ptr,
737 LLVMValueRef cmp, LLVMValueRef val,
738 const char *sync_scope);
739
740 #ifdef __cplusplus
741 }
742 #endif
743
744 #endif