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