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