1 /*
2 * Copyright 2016 Bas Nieuwenhuizen
3 *
4 * SPDX-License-Identifier: MIT
5 */
6 #ifndef AC_LLVM_BUILD_H
7 #define AC_LLVM_BUILD_H
8
9 #include "ac_llvm_util.h"
10 #include "ac_shader_abi.h"
11 #include "ac_shader_args.h"
12 #include "ac_shader_util.h"
13 #include "amd_family.h"
14 #include "compiler/nir/nir.h"
15 #include <llvm-c/Core.h>
16
17 #include <stdbool.h>
18
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22
23 enum
24 {
25 AC_ADDR_SPACE_FLAT = 0, /* Slower than global. */
26 AC_ADDR_SPACE_GLOBAL = 1,
27 AC_ADDR_SPACE_GDS = 2,
28 AC_ADDR_SPACE_LDS = 3,
29 AC_ADDR_SPACE_CONST = 4, /* Global allowing SMEM. */
30 AC_ADDR_SPACE_CONST_32BIT = 6, /* same as CONST, but the pointer type has 32 bits */
31 };
32
33 #define AC_WAIT_LGKM (1 << 0) /* LDS, GDS, constant, message */
34 #define AC_WAIT_VLOAD (1 << 1) /* VMEM load/sample instructions */
35 #define AC_WAIT_VSTORE (1 << 2) /* VMEM store instructions */
36 #define AC_WAIT_EXP (1 << 3) /* EXP instructions */
37
38 struct ac_llvm_flow;
39 struct ac_llvm_compiler;
40 struct radeon_info;
41
42 struct ac_llvm_flow_state {
43 struct ac_llvm_flow *stack;
44 unsigned depth_max;
45 unsigned depth;
46 };
47
48 struct ac_llvm_pointer {
49 union {
50 LLVMValueRef value;
51 LLVMValueRef v;
52 };
53 /* Doesn't support complex types (pointer to pointer to etc...),
54 * but this isn't a problem since there's no place where this
55 * would be required.
56 */
57 union {
58 LLVMTypeRef pointee_type;
59 LLVMTypeRef t;
60 };
61 };
62
63 struct ac_llvm_context {
64 LLVMContextRef context;
65 LLVMModuleRef module;
66 LLVMBuilderRef builder;
67
68 struct ac_llvm_pointer main_function;
69
70 LLVMTypeRef voidt;
71 LLVMTypeRef i1;
72 LLVMTypeRef i8;
73 LLVMTypeRef i16;
74 LLVMTypeRef i32;
75 LLVMTypeRef i64;
76 LLVMTypeRef i128;
77 LLVMTypeRef intptr;
78 LLVMTypeRef f16;
79 LLVMTypeRef f32;
80 LLVMTypeRef f64;
81 LLVMTypeRef v4i8;
82 LLVMTypeRef v2i16;
83 LLVMTypeRef v4i16;
84 LLVMTypeRef v2f16;
85 LLVMTypeRef v4f16;
86 LLVMTypeRef v2i32;
87 LLVMTypeRef v3i32;
88 LLVMTypeRef v4i32;
89 LLVMTypeRef v2f32;
90 LLVMTypeRef v3f32;
91 LLVMTypeRef v4f32;
92 LLVMTypeRef v8i32;
93 LLVMTypeRef iN_wavemask;
94 LLVMTypeRef iN_ballotmask;
95
96 LLVMValueRef i8_0;
97 LLVMValueRef i8_1;
98 LLVMValueRef i16_0;
99 LLVMValueRef i16_1;
100 LLVMValueRef i32_0;
101 LLVMValueRef i32_1;
102 LLVMValueRef i64_0;
103 LLVMValueRef i64_1;
104 LLVMValueRef i128_0;
105 LLVMValueRef i128_1;
106 LLVMValueRef f16_0;
107 LLVMValueRef f16_1;
108 LLVMValueRef f32_0;
109 LLVMValueRef f32_1;
110 LLVMValueRef f64_0;
111 LLVMValueRef f64_1;
112 LLVMValueRef i1true;
113 LLVMValueRef i1false;
114
115 /* Since ac_nir_translate makes a local copy of ac_llvm_context, there
116 * are two ac_llvm_contexts. Declare a pointer here, so that the control
117 * flow stack is shared by both ac_llvm_contexts.
118 */
119 struct ac_llvm_flow_state *flow;
120
121 unsigned range_md_kind;
122 unsigned invariant_load_md_kind;
123 unsigned uniform_md_kind;
124 unsigned fpmath_md_kind;
125 LLVMValueRef empty_md;
126 LLVMValueRef three_md;
127
128 const struct radeon_info *info;
129 enum amd_gfx_level gfx_level;
130
131 unsigned wave_size;
132 unsigned ballot_mask_bits;
133
134 unsigned float_mode;
135
136 bool exports_color_null;
137 bool exports_mrtz;
138
139 struct ac_llvm_pointer lds;
140
141 LLVMValueRef ring_offsets;
142 int ring_offsets_index;
143 };
144
145 void ac_llvm_context_init(struct ac_llvm_context *ctx, struct ac_llvm_compiler *compiler,
146 const struct radeon_info *info, enum ac_float_mode float_mode,
147 unsigned wave_size, unsigned ballot_mask_bits, bool exports_color_null,
148 bool exports_mrtz);
149
150 void ac_llvm_context_dispose(struct ac_llvm_context *ctx);
151
152 int ac_get_llvm_num_components(LLVMValueRef value);
153
154 int ac_get_elem_bits(struct ac_llvm_context *ctx, LLVMTypeRef type);
155
156 LLVMValueRef ac_llvm_extract_elem(struct ac_llvm_context *ac, LLVMValueRef value, int index);
157
158 unsigned ac_get_type_size(LLVMTypeRef type);
159
160 LLVMTypeRef ac_to_integer_type(struct ac_llvm_context *ctx, LLVMTypeRef t);
161 LLVMValueRef ac_to_integer(struct ac_llvm_context *ctx, LLVMValueRef v);
162 LLVMValueRef ac_to_integer_or_pointer(struct ac_llvm_context *ctx, LLVMValueRef v);
163 LLVMTypeRef ac_to_float_type(struct ac_llvm_context *ctx, LLVMTypeRef t);
164 LLVMValueRef ac_to_float(struct ac_llvm_context *ctx, LLVMValueRef v);
165
166 LLVMValueRef ac_build_intrinsic(struct ac_llvm_context *ctx, const char *name,
167 LLVMTypeRef return_type, LLVMValueRef *params, unsigned param_count,
168 unsigned attrib_mask);
169
170 void ac_build_type_name_for_intr(LLVMTypeRef type, char *buf, unsigned bufsize);
171
172 LLVMValueRef ac_build_phi(struct ac_llvm_context *ctx, LLVMTypeRef type, unsigned count_incoming,
173 LLVMValueRef *values, LLVMBasicBlockRef *blocks);
174
175 void ac_build_s_barrier(struct ac_llvm_context *ctx, gl_shader_stage stage);
176 void ac_build_optimization_barrier(struct ac_llvm_context *ctx, LLVMValueRef *pgpr, bool sgpr);
177
178 LLVMValueRef ac_build_shader_clock(struct ac_llvm_context *ctx, mesa_scope scope);
179
180 LLVMValueRef ac_build_ballot(struct ac_llvm_context *ctx, LLVMValueRef value);
181 LLVMValueRef ac_get_i1_sgpr_mask(struct ac_llvm_context *ctx, LLVMValueRef value);
182
183 LLVMValueRef ac_build_vote_all(struct ac_llvm_context *ctx, LLVMValueRef value);
184
185 LLVMValueRef ac_build_vote_any(struct ac_llvm_context *ctx, LLVMValueRef value);
186
187 LLVMValueRef ac_build_vote_eq(struct ac_llvm_context *ctx, LLVMValueRef value);
188
189 LLVMValueRef ac_build_varying_gather_values(struct ac_llvm_context *ctx, LLVMValueRef *values,
190 unsigned value_count, unsigned component);
191
192 LLVMValueRef ac_build_gather_values_extended(struct ac_llvm_context *ctx, LLVMValueRef *values,
193 unsigned value_count, unsigned value_stride,
194 bool always_vector);
195 LLVMValueRef ac_build_gather_values(struct ac_llvm_context *ctx, LLVMValueRef *values,
196 unsigned value_count);
197
198 LLVMValueRef ac_build_concat(struct ac_llvm_context *ctx, LLVMValueRef a, LLVMValueRef b);
199
200 LLVMValueRef ac_extract_components(struct ac_llvm_context *ctx, LLVMValueRef value, unsigned start,
201 unsigned channels);
202
203 LLVMValueRef ac_build_expand(struct ac_llvm_context *ctx, LLVMValueRef value,
204 unsigned src_channels, unsigned dst_channels);
205
206 LLVMValueRef ac_build_expand_to_vec4(struct ac_llvm_context *ctx, LLVMValueRef value,
207 unsigned num_channels);
208 LLVMValueRef ac_build_round(struct ac_llvm_context *ctx, LLVMValueRef value);
209
210 LLVMValueRef ac_build_fdiv(struct ac_llvm_context *ctx, LLVMValueRef num, LLVMValueRef den);
211
212 LLVMValueRef ac_build_fast_udiv(struct ac_llvm_context *ctx, LLVMValueRef num,
213 LLVMValueRef multiplier, LLVMValueRef pre_shift,
214 LLVMValueRef post_shift, LLVMValueRef increment);
215 LLVMValueRef ac_build_fast_udiv_nuw(struct ac_llvm_context *ctx, LLVMValueRef num,
216 LLVMValueRef multiplier, LLVMValueRef pre_shift,
217 LLVMValueRef post_shift, LLVMValueRef increment);
218 LLVMValueRef ac_build_fast_udiv_u31_d_not_one(struct ac_llvm_context *ctx, LLVMValueRef num,
219 LLVMValueRef multiplier, LLVMValueRef post_shift);
220
221 LLVMValueRef ac_build_fs_interp(struct ac_llvm_context *ctx, LLVMValueRef llvm_chan,
222 LLVMValueRef attr_number, LLVMValueRef params, LLVMValueRef i,
223 LLVMValueRef j);
224
225 LLVMValueRef ac_build_fs_interp_f16(struct ac_llvm_context *ctx, LLVMValueRef llvm_chan,
226 LLVMValueRef attr_number, LLVMValueRef params, LLVMValueRef i,
227 LLVMValueRef j, bool high_16bits);
228
229 LLVMValueRef ac_build_fs_interp_mov(struct ac_llvm_context *ctx, unsigned parameter,
230 LLVMValueRef llvm_chan, LLVMValueRef attr_number,
231 LLVMValueRef params);
232
233 LLVMValueRef ac_build_gep_ptr(struct ac_llvm_context *ctx, LLVMTypeRef type, LLVMValueRef base_ptr,
234 LLVMValueRef index);
235
236 LLVMValueRef ac_build_pointer_add(struct ac_llvm_context *ctx, LLVMTypeRef type, LLVMValueRef ptr,
237 LLVMValueRef index);
238
239 LLVMTypeRef ac_build_gep0_type(LLVMTypeRef pointee_type, LLVMValueRef index);
240 LLVMValueRef ac_build_gep0(struct ac_llvm_context *ctx, struct ac_llvm_pointer ptr, LLVMValueRef index);
241
242 void ac_build_indexed_store(struct ac_llvm_context *ctx, struct ac_llvm_pointer ptr, LLVMValueRef index,
243 LLVMValueRef value);
244
245 LLVMValueRef ac_build_load(struct ac_llvm_context *ctx, struct ac_llvm_pointer ptr, LLVMValueRef index);
246 LLVMValueRef ac_build_load_invariant(struct ac_llvm_context *ctx, struct ac_llvm_pointer ptr,
247 LLVMValueRef index);
248 LLVMValueRef ac_build_load_to_sgpr(struct ac_llvm_context *ctx, struct ac_llvm_pointer ptr,
249 LLVMValueRef index);
250
251 LLVMValueRef ac_build_load_to_sgpr_uint_wraparound(struct ac_llvm_context *ctx, struct ac_llvm_pointer ptr,
252 LLVMValueRef index);
253
254 void ac_build_buffer_store_dword(struct ac_llvm_context *ctx, LLVMValueRef rsrc, LLVMValueRef vdata,
255 LLVMValueRef vindex, LLVMValueRef voffset, LLVMValueRef soffset,
256 enum gl_access_qualifier access);
257
258 void ac_build_buffer_store_format(struct ac_llvm_context *ctx, LLVMValueRef rsrc, LLVMValueRef data,
259 LLVMValueRef vindex, LLVMValueRef voffset, enum gl_access_qualifier access);
260
261 LLVMValueRef ac_build_buffer_load(struct ac_llvm_context *ctx, LLVMValueRef rsrc, int num_channels,
262 LLVMValueRef vindex, LLVMValueRef voffset, LLVMValueRef soffset,
263 LLVMTypeRef channel_type, enum gl_access_qualifier access,
264 bool can_speculate, bool allow_smem);
265
266 LLVMValueRef ac_build_buffer_load_format(struct ac_llvm_context *ctx, LLVMValueRef rsrc,
267 LLVMValueRef vindex, LLVMValueRef voffset,
268 unsigned num_channels, enum gl_access_qualifier access,
269 bool can_speculate, bool d16, bool tfe);
270
271 LLVMValueRef ac_build_buffer_load_short(struct ac_llvm_context *ctx, LLVMValueRef rsrc,
272 LLVMValueRef voffset, LLVMValueRef soffset,
273 enum gl_access_qualifier access);
274
275 LLVMValueRef ac_build_buffer_load_byte(struct ac_llvm_context *ctx, LLVMValueRef rsrc,
276 LLVMValueRef voffset, LLVMValueRef soffset,
277 enum gl_access_qualifier access);
278
279 LLVMValueRef ac_build_safe_tbuffer_load(struct ac_llvm_context *ctx, LLVMValueRef rsrc,
280 LLVMValueRef vindex, LLVMValueRef voffset,
281 LLVMValueRef soffset,
282 const enum pipe_format format,
283 unsigned channel_bit_size,
284 unsigned const_offset,
285 unsigned align_offset,
286 unsigned align_mul,
287 unsigned num_channels,
288 enum gl_access_qualifier access,
289 bool can_speculate);
290
291 void ac_build_buffer_store_short(struct ac_llvm_context *ctx, LLVMValueRef rsrc,
292 LLVMValueRef vdata, LLVMValueRef voffset, LLVMValueRef soffset,
293 enum gl_access_qualifier access);
294
295 void ac_build_buffer_store_byte(struct ac_llvm_context *ctx, LLVMValueRef rsrc, LLVMValueRef vdata,
296 LLVMValueRef voffset, LLVMValueRef soffset, enum gl_access_qualifier access);
297
298 void ac_set_range_metadata(struct ac_llvm_context *ctx, LLVMValueRef value, unsigned lo,
299 unsigned hi);
300 LLVMValueRef ac_get_thread_id(struct ac_llvm_context *ctx);
301
302 #define AC_TID_MASK_TOP_LEFT 0xfffffffc
303 #define AC_TID_MASK_TOP 0xfffffffd
304 #define AC_TID_MASK_LEFT 0xfffffffe
305
306 LLVMValueRef ac_build_ddxy(struct ac_llvm_context *ctx, uint32_t mask, int idx, LLVMValueRef val);
307
308 void ac_build_sendmsg(struct ac_llvm_context *ctx, uint32_t imm, LLVMValueRef m0_content);
309
310 LLVMValueRef ac_build_imsb(struct ac_llvm_context *ctx, LLVMValueRef arg, LLVMTypeRef dst_type);
311
312 LLVMValueRef ac_build_umsb(struct ac_llvm_context *ctx, LLVMValueRef arg, LLVMTypeRef dst_type,
313 bool rev);
314 LLVMValueRef ac_build_fmin(struct ac_llvm_context *ctx, LLVMValueRef a, LLVMValueRef b);
315 LLVMValueRef ac_build_fmax(struct ac_llvm_context *ctx, LLVMValueRef a, LLVMValueRef b);
316 LLVMValueRef ac_build_imin(struct ac_llvm_context *ctx, LLVMValueRef a, LLVMValueRef b);
317 LLVMValueRef ac_build_imax(struct ac_llvm_context *ctx, LLVMValueRef a, LLVMValueRef b);
318 LLVMValueRef ac_build_umin(struct ac_llvm_context *ctx, LLVMValueRef a, LLVMValueRef b);
319 LLVMValueRef ac_build_umax(struct ac_llvm_context *ctx, LLVMValueRef a, LLVMValueRef b);
320 LLVMValueRef ac_build_clamp(struct ac_llvm_context *ctx, LLVMValueRef value);
321
322 struct ac_export_args {
323 LLVMValueRef out[4];
324 unsigned target;
325 unsigned enabled_channels;
326 bool compr;
327 bool done;
328 bool valid_mask;
329 };
330
331 void ac_build_export(struct ac_llvm_context *ctx, struct ac_export_args *a);
332
333 void ac_build_export_null(struct ac_llvm_context *ctx, bool uses_discard);
334
335 enum ac_image_opcode
336 {
337 ac_image_sample,
338 ac_image_gather4,
339 ac_image_load,
340 ac_image_load_mip,
341 ac_image_store,
342 ac_image_store_mip,
343 ac_image_get_lod,
344 ac_image_get_resinfo,
345 ac_image_atomic,
346 ac_image_atomic_cmpswap,
347 };
348
349 enum ac_atomic_op
350 {
351 ac_atomic_swap,
352 ac_atomic_add,
353 ac_atomic_sub,
354 ac_atomic_smin,
355 ac_atomic_umin,
356 ac_atomic_smax,
357 ac_atomic_umax,
358 ac_atomic_and,
359 ac_atomic_or,
360 ac_atomic_xor,
361 ac_atomic_inc_wrap,
362 ac_atomic_dec_wrap,
363 ac_atomic_fmin,
364 ac_atomic_fmax,
365 };
366
367 struct ac_image_args {
368 enum ac_image_opcode opcode;
369 enum ac_atomic_op atomic; /* for the ac_image_atomic opcode */
370 enum ac_image_dim dim;
371 enum gl_access_qualifier access;
372 unsigned dmask : 4;
373 bool unorm : 1;
374 bool level_zero : 1;
375 bool d16 : 1; /* GFX8+: data and return values are 16-bit */
376 bool a16 : 1; /* GFX9+: address components except compare, offset and bias are 16-bit */
377 bool g16 : 1; /* GFX10+: derivatives are 16-bit; GFX<=9: must be equal to a16 */
378 bool tfe : 1;
379 unsigned attributes; /* additional call-site specific AC_FUNC_ATTRs */
380
381 LLVMValueRef resource;
382 LLVMValueRef sampler;
383 LLVMValueRef data[2]; /* data[0] is source data (vector); data[1] is cmp for cmpswap */
384 LLVMValueRef offset;
385 LLVMValueRef bias;
386 LLVMValueRef compare;
387 LLVMValueRef derivs[6];
388 LLVMValueRef coords[4];
389 LLVMValueRef lod; // also used by ac_image_get_resinfo
390 LLVMValueRef min_lod;
391 };
392
393 LLVMValueRef ac_build_image_opcode(struct ac_llvm_context *ctx, struct ac_image_args *a);
394 LLVMValueRef ac_build_image_get_sample_count(struct ac_llvm_context *ctx, LLVMValueRef rsrc);
395 LLVMValueRef ac_build_cvt_pkrtz_f16(struct ac_llvm_context *ctx, LLVMValueRef args[2]);
396 LLVMValueRef ac_build_cvt_pknorm_i16(struct ac_llvm_context *ctx, LLVMValueRef args[2]);
397 LLVMValueRef ac_build_cvt_pknorm_u16(struct ac_llvm_context *ctx, LLVMValueRef args[2]);
398 LLVMValueRef ac_build_cvt_pknorm_i16_f16(struct ac_llvm_context *ctx, LLVMValueRef args[2]);
399 LLVMValueRef ac_build_cvt_pknorm_u16_f16(struct ac_llvm_context *ctx, LLVMValueRef args[2]);
400 LLVMValueRef ac_build_cvt_pk_i16(struct ac_llvm_context *ctx, LLVMValueRef args[2], unsigned bits,
401 bool hi);
402 LLVMValueRef ac_build_cvt_pk_u16(struct ac_llvm_context *ctx, LLVMValueRef args[2], unsigned bits,
403 bool hi);
404 LLVMValueRef ac_build_wqm_vote(struct ac_llvm_context *ctx, LLVMValueRef i1);
405 void ac_build_kill_if_false(struct ac_llvm_context *ctx, LLVMValueRef i1);
406 LLVMValueRef ac_build_bfe(struct ac_llvm_context *ctx, LLVMValueRef input, LLVMValueRef offset,
407 LLVMValueRef width, bool is_signed);
408 LLVMValueRef ac_build_imad(struct ac_llvm_context *ctx, LLVMValueRef s0, LLVMValueRef s1,
409 LLVMValueRef s2);
410 LLVMValueRef ac_build_fmad(struct ac_llvm_context *ctx, LLVMValueRef s0, LLVMValueRef s1,
411 LLVMValueRef s2);
412
413 void ac_build_waitcnt(struct ac_llvm_context *ctx, unsigned wait_flags);
414
415 LLVMValueRef ac_build_fract(struct ac_llvm_context *ctx, LLVMValueRef src0, unsigned bitsize);
416 LLVMValueRef ac_const_uint_vec(struct ac_llvm_context *ctx, LLVMTypeRef type, uint64_t value);
417 LLVMValueRef ac_build_isign(struct ac_llvm_context *ctx, LLVMValueRef src0);
418 LLVMValueRef ac_build_fsign(struct ac_llvm_context *ctx, LLVMValueRef src);
419 LLVMValueRef ac_build_bit_count(struct ac_llvm_context *ctx, LLVMValueRef src0);
420
421 LLVMValueRef ac_build_fsat(struct ac_llvm_context *ctx, LLVMValueRef src,
422 LLVMTypeRef type);
423
424 LLVMValueRef ac_build_bitfield_reverse(struct ac_llvm_context *ctx, LLVMValueRef src0);
425
426 LLVMValueRef ac_build_sudot_4x8(struct ac_llvm_context *ctx, LLVMValueRef s0, LLVMValueRef s1,
427 LLVMValueRef s2, bool clamp, unsigned neg_lo);
428
429 void ac_init_exec_full_mask(struct ac_llvm_context *ctx);
430
431 void ac_declare_lds_as_pointer(struct ac_llvm_context *ac);
432 LLVMValueRef ac_lds_load(struct ac_llvm_context *ctx, LLVMValueRef dw_addr);
433 void ac_lds_store(struct ac_llvm_context *ctx, LLVMValueRef dw_addr, LLVMValueRef value);
434
435 LLVMValueRef ac_find_lsb(struct ac_llvm_context *ctx, LLVMTypeRef dst_type, LLVMValueRef src0);
436
437 LLVMTypeRef ac_array_in_const_addr_space(LLVMTypeRef elem_type);
438 LLVMTypeRef ac_array_in_const32_addr_space(LLVMTypeRef elem_type);
439
440 void ac_build_bgnloop(struct ac_llvm_context *ctx, int lable_id);
441 void ac_build_break(struct ac_llvm_context *ctx);
442 void ac_build_continue(struct ac_llvm_context *ctx);
443 void ac_build_else(struct ac_llvm_context *ctx, int lable_id);
444 void ac_build_endif(struct ac_llvm_context *ctx, int lable_id);
445 void ac_build_endloop(struct ac_llvm_context *ctx, int lable_id);
446 void ac_build_ifcc(struct ac_llvm_context *ctx, LLVMValueRef cond, int label_id);
447
448 LLVMValueRef ac_build_alloca(struct ac_llvm_context *ac, LLVMTypeRef type, const char *name);
449 LLVMValueRef ac_build_alloca_undef(struct ac_llvm_context *ac, LLVMTypeRef type, const char *name);
450 LLVMValueRef ac_build_alloca_init(struct ac_llvm_context *ac, LLVMValueRef val, const char *name);
451
452 LLVMValueRef ac_cast_ptr(struct ac_llvm_context *ctx, LLVMValueRef ptr, LLVMTypeRef type);
453
454 LLVMValueRef ac_trim_vector(struct ac_llvm_context *ctx, LLVMValueRef value, unsigned count);
455
456 LLVMValueRef ac_unpack_param(struct ac_llvm_context *ctx, LLVMValueRef param, unsigned rshift,
457 unsigned bitwidth);
458
459 LLVMValueRef ac_build_ds_swizzle(struct ac_llvm_context *ctx, LLVMValueRef src, unsigned mask);
460
461 LLVMValueRef ac_build_readlane_no_opt_barrier(struct ac_llvm_context *ctx, LLVMValueRef src,
462 LLVMValueRef lane);
463
464 LLVMValueRef ac_build_readlane(struct ac_llvm_context *ctx, LLVMValueRef src, LLVMValueRef lane);
465
466 LLVMValueRef ac_build_writelane(struct ac_llvm_context *ctx, LLVMValueRef src, LLVMValueRef value,
467 LLVMValueRef lane);
468
469 LLVMValueRef ac_build_mbcnt_add(struct ac_llvm_context *ctx, LLVMValueRef mask, LLVMValueRef add_src);
470 LLVMValueRef ac_build_mbcnt(struct ac_llvm_context *ctx, LLVMValueRef mask);
471
472 LLVMValueRef ac_build_wqm(struct ac_llvm_context *ctx, LLVMValueRef src);
473
474 LLVMValueRef ac_build_inclusive_scan(struct ac_llvm_context *ctx, LLVMValueRef src, nir_op op);
475
476 LLVMValueRef ac_build_exclusive_scan(struct ac_llvm_context *ctx, LLVMValueRef src, nir_op op);
477
478 LLVMValueRef ac_build_reduce(struct ac_llvm_context *ctx, LLVMValueRef src, nir_op op,
479 unsigned cluster_size);
480
481 LLVMValueRef ac_build_quad_swizzle(struct ac_llvm_context *ctx, LLVMValueRef src, unsigned lane0,
482 unsigned lane1, unsigned lane2, unsigned lane3);
483
484 LLVMValueRef ac_build_shuffle(struct ac_llvm_context *ctx, LLVMValueRef src, LLVMValueRef index);
485
486 LLVMValueRef ac_build_frexp_exp(struct ac_llvm_context *ctx, LLVMValueRef src0, unsigned bitsize);
487
488 LLVMValueRef ac_build_frexp_mant(struct ac_llvm_context *ctx, LLVMValueRef src0, unsigned bitsize);
489
490 LLVMValueRef ac_build_canonicalize(struct ac_llvm_context *ctx, LLVMValueRef src0,
491 unsigned bitsize);
492
493 LLVMValueRef ac_build_ddxy_interp(struct ac_llvm_context *ctx, LLVMValueRef interp_ij);
494
495 LLVMValueRef ac_build_load_helper_invocation(struct ac_llvm_context *ctx);
496
497 LLVMValueRef ac_build_call(struct ac_llvm_context *ctx, LLVMTypeRef fn_type, LLVMValueRef func,
498 LLVMValueRef *args, unsigned num_args);
499
500 LLVMValueRef ac_build_atomic_rmw(struct ac_llvm_context *ctx, LLVMAtomicRMWBinOp op,
501 LLVMValueRef ptr, LLVMValueRef val, const char *sync_scope);
502
503 LLVMValueRef ac_build_atomic_cmp_xchg(struct ac_llvm_context *ctx, LLVMValueRef ptr,
504 LLVMValueRef cmp, LLVMValueRef val, const char *sync_scope);
505
506 void ac_export_mrt_z(struct ac_llvm_context *ctx, LLVMValueRef depth, LLVMValueRef stencil,
507 LLVMValueRef samplemask, LLVMValueRef mrt0_alpha, bool is_last,
508 struct ac_export_args *args);
509
510 struct ac_ngg_prim {
511 unsigned num_vertices;
512 LLVMValueRef isnull;
513 LLVMValueRef index[3];
514 LLVMValueRef edgeflags;
515 LLVMValueRef passthrough;
516 };
517
518 LLVMTypeRef ac_arg_type_to_pointee_type(struct ac_llvm_context *ctx, enum ac_arg_type type);
519
ac_get_arg(struct ac_llvm_context * ctx,struct ac_arg arg)520 static inline LLVMValueRef ac_get_arg(struct ac_llvm_context *ctx, struct ac_arg arg)
521 {
522 assert(arg.used);
523 if (arg.arg_index == ctx->ring_offsets_index)
524 return ctx->ring_offsets;
525 int offset = arg.arg_index > ctx->ring_offsets_index ? -1 : 0;
526 return LLVMGetParam(ctx->main_function.value, arg.arg_index + offset);
527 }
528
529 static inline struct ac_llvm_pointer
ac_get_ptr_arg(struct ac_llvm_context * ctx,const struct ac_shader_args * args,struct ac_arg arg)530 ac_get_ptr_arg(struct ac_llvm_context *ctx, const struct ac_shader_args *args, struct ac_arg arg)
531 {
532 struct ac_llvm_pointer ptr;
533 ptr.pointee_type = ac_arg_type_to_pointee_type(ctx, args->args[arg.arg_index].type);
534 ptr.value = ac_get_arg(ctx, arg);
535 return ptr;
536 }
537
538 enum ac_llvm_calling_convention
539 {
540 AC_LLVM_AMDGPU_VS = 87,
541 AC_LLVM_AMDGPU_GS = 88,
542 AC_LLVM_AMDGPU_PS = 89,
543 AC_LLVM_AMDGPU_CS = 90,
544 AC_LLVM_AMDGPU_HS = 93,
545 };
546
547 struct ac_llvm_pointer ac_build_main(const struct ac_shader_args *args, struct ac_llvm_context *ctx,
548 enum ac_llvm_calling_convention convention, const char *name,
549 LLVMTypeRef ret_type, LLVMModuleRef module);
550 void ac_build_s_endpgm(struct ac_llvm_context *ctx);
551
552 LLVMValueRef ac_build_is_inf_or_nan(struct ac_llvm_context *ctx, LLVMValueRef a);
553
554 void ac_build_dual_src_blend_swizzle(struct ac_llvm_context *ctx,
555 struct ac_export_args *mrt0,
556 struct ac_export_args *mrt1);
557
558 #ifdef __cplusplus
559 }
560 #endif
561
562 #endif
563