6848a7ca082f6cf733be6079363bbfd15b0ffd7b
[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
194 LLVMValueRef
195 ac_extract_components(struct ac_llvm_context *ctx,
196 LLVMValueRef value,
197 unsigned start,
198 unsigned channels);
199
200 LLVMValueRef ac_build_expand_to_vec4(struct ac_llvm_context *ctx,
201 LLVMValueRef value,
202 unsigned num_channels);
203 LLVMValueRef ac_build_round(struct ac_llvm_context *ctx, LLVMValueRef value);
204
205 LLVMValueRef
206 ac_build_fdiv(struct ac_llvm_context *ctx,
207 LLVMValueRef num,
208 LLVMValueRef den);
209
210 LLVMValueRef ac_build_fast_udiv(struct ac_llvm_context *ctx,
211 LLVMValueRef num,
212 LLVMValueRef multiplier,
213 LLVMValueRef pre_shift,
214 LLVMValueRef post_shift,
215 LLVMValueRef increment);
216 LLVMValueRef ac_build_fast_udiv_nuw(struct ac_llvm_context *ctx,
217 LLVMValueRef num,
218 LLVMValueRef multiplier,
219 LLVMValueRef pre_shift,
220 LLVMValueRef post_shift,
221 LLVMValueRef increment);
222 LLVMValueRef ac_build_fast_udiv_u31_d_not_one(struct ac_llvm_context *ctx,
223 LLVMValueRef num,
224 LLVMValueRef multiplier,
225 LLVMValueRef post_shift);
226
227 void
228 ac_prepare_cube_coords(struct ac_llvm_context *ctx,
229 bool is_deriv, bool is_array, bool is_lod,
230 LLVMValueRef *coords_arg,
231 LLVMValueRef *derivs_arg);
232
233
234 LLVMValueRef
235 ac_build_fs_interp(struct ac_llvm_context *ctx,
236 LLVMValueRef llvm_chan,
237 LLVMValueRef attr_number,
238 LLVMValueRef params,
239 LLVMValueRef i,
240 LLVMValueRef j);
241
242 LLVMValueRef
243 ac_build_fs_interp_f16(struct ac_llvm_context *ctx,
244 LLVMValueRef llvm_chan,
245 LLVMValueRef attr_number,
246 LLVMValueRef params,
247 LLVMValueRef i,
248 LLVMValueRef j);
249
250 LLVMValueRef
251 ac_build_fs_interp_mov(struct ac_llvm_context *ctx,
252 LLVMValueRef parameter,
253 LLVMValueRef llvm_chan,
254 LLVMValueRef attr_number,
255 LLVMValueRef params);
256
257 LLVMValueRef
258 ac_build_gep_ptr(struct ac_llvm_context *ctx,
259 LLVMValueRef base_ptr,
260 LLVMValueRef index);
261
262 LLVMValueRef
263 ac_build_gep0(struct ac_llvm_context *ctx,
264 LLVMValueRef base_ptr,
265 LLVMValueRef index);
266 LLVMValueRef ac_build_pointer_add(struct ac_llvm_context *ctx, LLVMValueRef ptr,
267 LLVMValueRef index);
268
269 void
270 ac_build_indexed_store(struct ac_llvm_context *ctx,
271 LLVMValueRef base_ptr, LLVMValueRef index,
272 LLVMValueRef value);
273
274 LLVMValueRef ac_build_load(struct ac_llvm_context *ctx, LLVMValueRef base_ptr,
275 LLVMValueRef index);
276 LLVMValueRef ac_build_load_invariant(struct ac_llvm_context *ctx,
277 LLVMValueRef base_ptr, LLVMValueRef index);
278 LLVMValueRef ac_build_load_to_sgpr(struct ac_llvm_context *ctx,
279 LLVMValueRef base_ptr, LLVMValueRef index);
280 LLVMValueRef ac_build_load_to_sgpr_uint_wraparound(struct ac_llvm_context *ctx,
281 LLVMValueRef base_ptr, LLVMValueRef index);
282
283 void
284 ac_build_buffer_store_dword(struct ac_llvm_context *ctx,
285 LLVMValueRef rsrc,
286 LLVMValueRef vdata,
287 unsigned num_channels,
288 LLVMValueRef voffset,
289 LLVMValueRef soffset,
290 unsigned inst_offset,
291 unsigned cache_policy,
292 bool swizzle_enable_hint);
293
294 void
295 ac_build_buffer_store_format(struct ac_llvm_context *ctx,
296 LLVMValueRef rsrc,
297 LLVMValueRef data,
298 LLVMValueRef vindex,
299 LLVMValueRef voffset,
300 unsigned num_channels,
301 unsigned cache_policy);
302
303 LLVMValueRef
304 ac_build_buffer_load(struct ac_llvm_context *ctx,
305 LLVMValueRef rsrc,
306 int num_channels,
307 LLVMValueRef vindex,
308 LLVMValueRef voffset,
309 LLVMValueRef soffset,
310 unsigned inst_offset,
311 unsigned cache_policy,
312 bool can_speculate,
313 bool allow_smem);
314
315 LLVMValueRef ac_build_buffer_load_format(struct ac_llvm_context *ctx,
316 LLVMValueRef rsrc,
317 LLVMValueRef vindex,
318 LLVMValueRef voffset,
319 unsigned num_channels,
320 unsigned cache_policy,
321 bool can_speculate);
322
323 /* load_format that handles the stride & element count better if idxen is
324 * disabled by LLVM. */
325 LLVMValueRef ac_build_buffer_load_format_gfx9_safe(struct ac_llvm_context *ctx,
326 LLVMValueRef rsrc,
327 LLVMValueRef vindex,
328 LLVMValueRef voffset,
329 unsigned num_channels,
330 unsigned cache_policy,
331 bool can_speculate);
332
333 LLVMValueRef
334 ac_build_tbuffer_load_short(struct ac_llvm_context *ctx,
335 LLVMValueRef rsrc,
336 LLVMValueRef voffset,
337 LLVMValueRef soffset,
338 LLVMValueRef immoffset,
339 unsigned cache_policy);
340
341 LLVMValueRef
342 ac_build_tbuffer_load_byte(struct ac_llvm_context *ctx,
343 LLVMValueRef rsrc,
344 LLVMValueRef voffset,
345 LLVMValueRef soffset,
346 LLVMValueRef immoffset,
347 unsigned cache_policy);
348
349 LLVMValueRef
350 ac_build_struct_tbuffer_load(struct ac_llvm_context *ctx,
351 LLVMValueRef rsrc,
352 LLVMValueRef vindex,
353 LLVMValueRef voffset,
354 LLVMValueRef soffset,
355 LLVMValueRef immoffset,
356 unsigned num_channels,
357 unsigned dfmt,
358 unsigned nfmt,
359 unsigned cache_policy,
360 bool can_speculate);
361
362 LLVMValueRef
363 ac_build_raw_tbuffer_load(struct ac_llvm_context *ctx,
364 LLVMValueRef rsrc,
365 LLVMValueRef voffset,
366 LLVMValueRef soffset,
367 LLVMValueRef immoffset,
368 unsigned num_channels,
369 unsigned dfmt,
370 unsigned nfmt,
371 unsigned cache_policy,
372 bool can_speculate);
373
374 /* For ac_build_fetch_format.
375 *
376 * Note: FLOAT must be 0 (used for convenience of encoding in radeonsi).
377 */
378 enum {
379 AC_FETCH_FORMAT_FLOAT = 0,
380 AC_FETCH_FORMAT_FIXED,
381 AC_FETCH_FORMAT_UNORM,
382 AC_FETCH_FORMAT_SNORM,
383 AC_FETCH_FORMAT_USCALED,
384 AC_FETCH_FORMAT_SSCALED,
385 AC_FETCH_FORMAT_UINT,
386 AC_FETCH_FORMAT_SINT,
387 };
388
389 LLVMValueRef
390 ac_build_opencoded_load_format(struct ac_llvm_context *ctx,
391 unsigned log_size,
392 unsigned num_channels,
393 unsigned format,
394 bool reverse,
395 bool known_aligned,
396 LLVMValueRef rsrc,
397 LLVMValueRef vindex,
398 LLVMValueRef voffset,
399 LLVMValueRef soffset,
400 unsigned cache_policy,
401 bool can_speculate);
402
403 void
404 ac_build_tbuffer_store_short(struct ac_llvm_context *ctx,
405 LLVMValueRef rsrc,
406 LLVMValueRef vdata,
407 LLVMValueRef voffset,
408 LLVMValueRef soffset,
409 unsigned cache_policy);
410
411 void
412 ac_build_tbuffer_store_byte(struct ac_llvm_context *ctx,
413 LLVMValueRef rsrc,
414 LLVMValueRef vdata,
415 LLVMValueRef voffset,
416 LLVMValueRef soffset,
417 unsigned cache_policy);
418
419 void
420 ac_build_struct_tbuffer_store(struct ac_llvm_context *ctx,
421 LLVMValueRef rsrc,
422 LLVMValueRef vdata,
423 LLVMValueRef vindex,
424 LLVMValueRef voffset,
425 LLVMValueRef soffset,
426 LLVMValueRef immoffset,
427 unsigned num_channels,
428 unsigned dfmt,
429 unsigned nfmt,
430 unsigned cache_policy);
431
432 void
433 ac_build_raw_tbuffer_store(struct ac_llvm_context *ctx,
434 LLVMValueRef rsrc,
435 LLVMValueRef vdata,
436 LLVMValueRef voffset,
437 LLVMValueRef soffset,
438 LLVMValueRef immoffset,
439 unsigned num_channels,
440 unsigned dfmt,
441 unsigned nfmt,
442 unsigned cache_policy);
443
444 LLVMValueRef
445 ac_get_thread_id(struct ac_llvm_context *ctx);
446
447 #define AC_TID_MASK_TOP_LEFT 0xfffffffc
448 #define AC_TID_MASK_TOP 0xfffffffd
449 #define AC_TID_MASK_LEFT 0xfffffffe
450
451 LLVMValueRef
452 ac_build_ddxy(struct ac_llvm_context *ctx,
453 uint32_t mask,
454 int idx,
455 LLVMValueRef val);
456
457 #define AC_SENDMSG_GS 2
458 #define AC_SENDMSG_GS_DONE 3
459 #define AC_SENDMSG_GS_ALLOC_REQ 9
460
461 #define AC_SENDMSG_GS_OP_NOP (0 << 4)
462 #define AC_SENDMSG_GS_OP_CUT (1 << 4)
463 #define AC_SENDMSG_GS_OP_EMIT (2 << 4)
464 #define AC_SENDMSG_GS_OP_EMIT_CUT (3 << 4)
465
466 void ac_build_sendmsg(struct ac_llvm_context *ctx,
467 uint32_t msg,
468 LLVMValueRef wave_id);
469
470 LLVMValueRef ac_build_imsb(struct ac_llvm_context *ctx,
471 LLVMValueRef arg,
472 LLVMTypeRef dst_type);
473
474 LLVMValueRef ac_build_umsb(struct ac_llvm_context *ctx,
475 LLVMValueRef arg,
476 LLVMTypeRef dst_type);
477 LLVMValueRef ac_build_fmin(struct ac_llvm_context *ctx, LLVMValueRef a,
478 LLVMValueRef b);
479 LLVMValueRef ac_build_fmax(struct ac_llvm_context *ctx, LLVMValueRef a,
480 LLVMValueRef b);
481 LLVMValueRef ac_build_imin(struct ac_llvm_context *ctx, LLVMValueRef a,
482 LLVMValueRef b);
483 LLVMValueRef ac_build_imax(struct ac_llvm_context *ctx, LLVMValueRef a,
484 LLVMValueRef b);
485 LLVMValueRef ac_build_umin(struct ac_llvm_context *ctx, LLVMValueRef a, LLVMValueRef b);
486 LLVMValueRef ac_build_umax(struct ac_llvm_context *ctx, LLVMValueRef a, LLVMValueRef b);
487 LLVMValueRef ac_build_clamp(struct ac_llvm_context *ctx, LLVMValueRef value);
488
489 struct ac_export_args {
490 LLVMValueRef out[4];
491 unsigned target;
492 unsigned enabled_channels;
493 bool compr;
494 bool done;
495 bool valid_mask;
496 };
497
498 void ac_build_export(struct ac_llvm_context *ctx, struct ac_export_args *a);
499
500 void ac_build_export_null(struct ac_llvm_context *ctx);
501
502 enum ac_image_opcode {
503 ac_image_sample,
504 ac_image_gather4,
505 ac_image_load,
506 ac_image_load_mip,
507 ac_image_store,
508 ac_image_store_mip,
509 ac_image_get_lod,
510 ac_image_get_resinfo,
511 ac_image_atomic,
512 ac_image_atomic_cmpswap,
513 };
514
515 enum ac_atomic_op {
516 ac_atomic_swap,
517 ac_atomic_add,
518 ac_atomic_sub,
519 ac_atomic_smin,
520 ac_atomic_umin,
521 ac_atomic_smax,
522 ac_atomic_umax,
523 ac_atomic_and,
524 ac_atomic_or,
525 ac_atomic_xor,
526 ac_atomic_inc_wrap,
527 ac_atomic_dec_wrap,
528 };
529
530 enum ac_image_dim {
531 ac_image_1d,
532 ac_image_2d,
533 ac_image_3d,
534 ac_image_cube, // includes cube arrays
535 ac_image_1darray,
536 ac_image_2darray,
537 ac_image_2dmsaa,
538 ac_image_2darraymsaa,
539 };
540
541 /* These cache policy bits match the definitions used by the LLVM intrinsics. */
542 enum ac_image_cache_policy {
543 ac_glc = 1 << 0, /* per-CU cache control */
544 ac_slc = 1 << 1, /* global L2 cache control */
545 ac_dlc = 1 << 2, /* per-shader-array cache control */
546 };
547
548 struct ac_image_args {
549 enum ac_image_opcode opcode : 4;
550 enum ac_atomic_op atomic : 4; /* for the ac_image_atomic opcode */
551 enum ac_image_dim dim : 3;
552 unsigned dmask : 4;
553 unsigned cache_policy : 3;
554 bool unorm : 1;
555 bool level_zero : 1;
556 unsigned attributes; /* additional call-site specific AC_FUNC_ATTRs */
557
558 LLVMValueRef resource;
559 LLVMValueRef sampler;
560 LLVMValueRef data[2]; /* data[0] is source data (vector); data[1] is cmp for cmpswap */
561 LLVMValueRef offset;
562 LLVMValueRef bias;
563 LLVMValueRef compare;
564 LLVMValueRef derivs[6];
565 LLVMValueRef coords[4];
566 LLVMValueRef lod; // also used by ac_image_get_resinfo
567 };
568
569 LLVMValueRef ac_build_image_opcode(struct ac_llvm_context *ctx,
570 struct ac_image_args *a);
571 LLVMValueRef ac_build_cvt_pkrtz_f16(struct ac_llvm_context *ctx,
572 LLVMValueRef args[2]);
573 LLVMValueRef ac_build_cvt_pknorm_i16(struct ac_llvm_context *ctx,
574 LLVMValueRef args[2]);
575 LLVMValueRef ac_build_cvt_pknorm_u16(struct ac_llvm_context *ctx,
576 LLVMValueRef args[2]);
577 LLVMValueRef ac_build_cvt_pk_i16(struct ac_llvm_context *ctx,
578 LLVMValueRef args[2], unsigned bits, bool hi);
579 LLVMValueRef ac_build_cvt_pk_u16(struct ac_llvm_context *ctx,
580 LLVMValueRef args[2], unsigned bits, bool hi);
581 LLVMValueRef ac_build_wqm_vote(struct ac_llvm_context *ctx, LLVMValueRef i1);
582 void ac_build_kill_if_false(struct ac_llvm_context *ctx, LLVMValueRef i1);
583 LLVMValueRef ac_build_bfe(struct ac_llvm_context *ctx, LLVMValueRef input,
584 LLVMValueRef offset, LLVMValueRef width,
585 bool is_signed);
586 LLVMValueRef ac_build_imad(struct ac_llvm_context *ctx, LLVMValueRef s0,
587 LLVMValueRef s1, LLVMValueRef s2);
588 LLVMValueRef ac_build_fmad(struct ac_llvm_context *ctx, LLVMValueRef s0,
589 LLVMValueRef s1, LLVMValueRef s2);
590
591 void ac_build_waitcnt(struct ac_llvm_context *ctx, unsigned wait_flags);
592
593 LLVMValueRef ac_build_fract(struct ac_llvm_context *ctx, LLVMValueRef src0,
594 unsigned bitsize);
595
596 LLVMValueRef ac_build_fmed3(struct ac_llvm_context *ctx, LLVMValueRef src0,
597 LLVMValueRef src1, LLVMValueRef src2,
598 unsigned bitsize);
599
600 LLVMValueRef ac_build_isign(struct ac_llvm_context *ctx, LLVMValueRef src0,
601 unsigned bitsize);
602
603 LLVMValueRef ac_build_fsign(struct ac_llvm_context *ctx, LLVMValueRef src0,
604 unsigned bitsize);
605
606 LLVMValueRef ac_build_bit_count(struct ac_llvm_context *ctx, LLVMValueRef src0);
607
608 LLVMValueRef ac_build_bitfield_reverse(struct ac_llvm_context *ctx,
609 LLVMValueRef src0);
610
611 void ac_optimize_vs_outputs(struct ac_llvm_context *ac,
612 LLVMValueRef main_fn,
613 uint8_t *vs_output_param_offset,
614 uint32_t num_outputs,
615 uint8_t *num_param_exports);
616 void ac_init_exec_full_mask(struct ac_llvm_context *ctx);
617
618 void ac_declare_lds_as_pointer(struct ac_llvm_context *ac);
619 LLVMValueRef ac_lds_load(struct ac_llvm_context *ctx,
620 LLVMValueRef dw_addr);
621 void ac_lds_store(struct ac_llvm_context *ctx,
622 LLVMValueRef dw_addr, LLVMValueRef value);
623
624 LLVMValueRef ac_find_lsb(struct ac_llvm_context *ctx,
625 LLVMTypeRef dst_type,
626 LLVMValueRef src0);
627
628 LLVMTypeRef ac_array_in_const_addr_space(LLVMTypeRef elem_type);
629 LLVMTypeRef ac_array_in_const32_addr_space(LLVMTypeRef elem_type);
630
631 void ac_build_bgnloop(struct ac_llvm_context *ctx, int lable_id);
632 void ac_build_break(struct ac_llvm_context *ctx);
633 void ac_build_continue(struct ac_llvm_context *ctx);
634 void ac_build_else(struct ac_llvm_context *ctx, int lable_id);
635 void ac_build_endif(struct ac_llvm_context *ctx, int lable_id);
636 void ac_build_endloop(struct ac_llvm_context *ctx, int lable_id);
637 void ac_build_ifcc(struct ac_llvm_context *ctx, LLVMValueRef cond, int label_id);
638 void ac_build_if(struct ac_llvm_context *ctx, LLVMValueRef value,
639 int lable_id);
640 void ac_build_uif(struct ac_llvm_context *ctx, LLVMValueRef value,
641 int lable_id);
642
643 LLVMValueRef ac_build_alloca(struct ac_llvm_context *ac, LLVMTypeRef type,
644 const char *name);
645 LLVMValueRef ac_build_alloca_undef(struct ac_llvm_context *ac, LLVMTypeRef type,
646 const char *name);
647
648 LLVMValueRef ac_cast_ptr(struct ac_llvm_context *ctx, LLVMValueRef ptr,
649 LLVMTypeRef type);
650
651 LLVMValueRef ac_trim_vector(struct ac_llvm_context *ctx, LLVMValueRef value,
652 unsigned count);
653
654 LLVMValueRef ac_unpack_param(struct ac_llvm_context *ctx, LLVMValueRef param,
655 unsigned rshift, unsigned bitwidth);
656
657 void ac_apply_fmask_to_sample(struct ac_llvm_context *ac, LLVMValueRef fmask,
658 LLVMValueRef *addr, bool is_array_tex);
659
660 LLVMValueRef
661 ac_build_ds_swizzle(struct ac_llvm_context *ctx, LLVMValueRef src, unsigned mask);
662
663 LLVMValueRef
664 ac_build_readlane(struct ac_llvm_context *ctx, LLVMValueRef src, LLVMValueRef lane);
665
666 LLVMValueRef
667 ac_build_writelane(struct ac_llvm_context *ctx, LLVMValueRef src, LLVMValueRef value, LLVMValueRef lane);
668
669 LLVMValueRef
670 ac_build_mbcnt(struct ac_llvm_context *ctx, LLVMValueRef mask);
671
672 LLVMValueRef
673 ac_build_inclusive_scan(struct ac_llvm_context *ctx, LLVMValueRef src, nir_op op);
674
675 LLVMValueRef
676 ac_build_exclusive_scan(struct ac_llvm_context *ctx, LLVMValueRef src, nir_op op);
677
678 LLVMValueRef
679 ac_build_reduce(struct ac_llvm_context *ctx, LLVMValueRef src, nir_op op, unsigned cluster_size);
680
681 /**
682 * Common arguments for a scan/reduce operation that accumulates per-wave
683 * values across an entire workgroup, while respecting the order of waves.
684 */
685 struct ac_wg_scan {
686 bool enable_reduce;
687 bool enable_exclusive;
688 bool enable_inclusive;
689 nir_op op;
690 LLVMValueRef src; /* clobbered! */
691 LLVMValueRef result_reduce;
692 LLVMValueRef result_exclusive;
693 LLVMValueRef result_inclusive;
694 LLVMValueRef extra;
695 LLVMValueRef waveidx;
696 LLVMValueRef numwaves; /* only needed for "reduce" operations */
697
698 /* T addrspace(LDS) pointer to the same type as value, at least maxwaves entries */
699 LLVMValueRef scratch;
700 unsigned maxwaves;
701 };
702
703 void
704 ac_build_wg_wavescan_top(struct ac_llvm_context *ctx, struct ac_wg_scan *ws);
705 void
706 ac_build_wg_wavescan_bottom(struct ac_llvm_context *ctx, struct ac_wg_scan *ws);
707 void
708 ac_build_wg_wavescan(struct ac_llvm_context *ctx, struct ac_wg_scan *ws);
709
710 void
711 ac_build_wg_scan_top(struct ac_llvm_context *ctx, struct ac_wg_scan *ws);
712 void
713 ac_build_wg_scan_bottom(struct ac_llvm_context *ctx, struct ac_wg_scan *ws);
714 void
715 ac_build_wg_scan(struct ac_llvm_context *ctx, struct ac_wg_scan *ws);
716
717 LLVMValueRef
718 ac_build_quad_swizzle(struct ac_llvm_context *ctx, LLVMValueRef src,
719 unsigned lane0, unsigned lane1, unsigned lane2, unsigned lane3);
720
721 LLVMValueRef
722 ac_build_shuffle(struct ac_llvm_context *ctx, LLVMValueRef src, LLVMValueRef index);
723
724 LLVMValueRef
725 ac_build_frexp_exp(struct ac_llvm_context *ctx, LLVMValueRef src0,
726 unsigned bitsize);
727
728 LLVMValueRef
729 ac_build_frexp_mant(struct ac_llvm_context *ctx, LLVMValueRef src0,
730 unsigned bitsize);
731
732 LLVMValueRef
733 ac_build_ddxy_interp(struct ac_llvm_context *ctx, LLVMValueRef interp_ij);
734
735 LLVMValueRef
736 ac_build_load_helper_invocation(struct ac_llvm_context *ctx);
737
738 LLVMValueRef ac_build_call(struct ac_llvm_context *ctx, LLVMValueRef func,
739 LLVMValueRef *args, unsigned num_args);
740
741 LLVMValueRef ac_build_atomic_rmw(struct ac_llvm_context *ctx, LLVMAtomicRMWBinOp op,
742 LLVMValueRef ptr, LLVMValueRef val,
743 const char *sync_scope);
744
745 LLVMValueRef ac_build_atomic_cmp_xchg(struct ac_llvm_context *ctx, LLVMValueRef ptr,
746 LLVMValueRef cmp, LLVMValueRef val,
747 const char *sync_scope);
748
749 #ifdef __cplusplus
750 }
751 #endif
752
753 #endif