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