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