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