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