• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
186 LLVMValueRef ac_build_vote_all(struct ac_llvm_context *ctx, LLVMValueRef value);
187 
188 LLVMValueRef ac_build_vote_any(struct ac_llvm_context *ctx, LLVMValueRef value);
189 
190 LLVMValueRef ac_build_varying_gather_values(struct ac_llvm_context *ctx, LLVMValueRef *values,
191                                             unsigned value_count, unsigned component);
192 
193 LLVMValueRef ac_build_gather_values_extended(struct ac_llvm_context *ctx, LLVMValueRef *values,
194                                              unsigned value_count, unsigned value_stride,
195                                              bool always_vector);
196 LLVMValueRef ac_build_gather_values(struct ac_llvm_context *ctx, LLVMValueRef *values,
197                                     unsigned value_count);
198 
199 LLVMValueRef ac_build_concat(struct ac_llvm_context *ctx, LLVMValueRef a, LLVMValueRef b);
200 
201 LLVMValueRef ac_extract_components(struct ac_llvm_context *ctx, LLVMValueRef value, unsigned start,
202                                    unsigned channels);
203 
204 LLVMValueRef ac_build_expand(struct ac_llvm_context *ctx, LLVMValueRef value,
205                              unsigned src_channels, unsigned dst_channels);
206 
207 LLVMValueRef ac_build_expand_to_vec4(struct ac_llvm_context *ctx, LLVMValueRef value,
208                                      unsigned num_channels);
209 LLVMValueRef ac_build_fdiv(struct ac_llvm_context *ctx, LLVMValueRef num, LLVMValueRef den);
210 
211 LLVMValueRef ac_build_fs_interp(struct ac_llvm_context *ctx, LLVMValueRef llvm_chan,
212                                 LLVMValueRef attr_number, LLVMValueRef params, LLVMValueRef i,
213                                 LLVMValueRef j);
214 
215 LLVMValueRef ac_build_fs_interp_f16(struct ac_llvm_context *ctx, LLVMValueRef llvm_chan,
216                                     LLVMValueRef attr_number, LLVMValueRef params, LLVMValueRef i,
217                                     LLVMValueRef j, bool high_16bits);
218 
219 LLVMValueRef ac_build_fs_interp_mov(struct ac_llvm_context *ctx, unsigned parameter,
220                                     LLVMValueRef llvm_chan, LLVMValueRef attr_number,
221                                     LLVMValueRef params);
222 
223 LLVMValueRef ac_build_gep0(struct ac_llvm_context *ctx, struct ac_llvm_pointer ptr, LLVMValueRef index);
224 
225 void ac_build_indexed_store(struct ac_llvm_context *ctx, struct ac_llvm_pointer ptr, LLVMValueRef index,
226                             LLVMValueRef value);
227 
228 LLVMValueRef ac_build_load_invariant(struct ac_llvm_context *ctx, struct ac_llvm_pointer ptr,
229                                      LLVMValueRef index);
230 LLVMValueRef ac_build_load_to_sgpr(struct ac_llvm_context *ctx, struct ac_llvm_pointer ptr,
231                                    LLVMValueRef index);
232 
233 void ac_build_buffer_store_dword(struct ac_llvm_context *ctx, LLVMValueRef rsrc, LLVMValueRef vdata,
234                                  LLVMValueRef vindex, LLVMValueRef voffset, LLVMValueRef soffset,
235                                  enum gl_access_qualifier access);
236 
237 void ac_build_buffer_store_format(struct ac_llvm_context *ctx, LLVMValueRef rsrc, LLVMValueRef data,
238                                   LLVMValueRef vindex, LLVMValueRef voffset, enum gl_access_qualifier access);
239 
240 LLVMValueRef ac_build_buffer_load(struct ac_llvm_context *ctx, LLVMValueRef rsrc, int num_channels,
241                                   LLVMValueRef vindex, LLVMValueRef voffset, LLVMValueRef soffset,
242                                   LLVMTypeRef channel_type, enum gl_access_qualifier access,
243                                   bool can_speculate, bool allow_smem);
244 
245 LLVMValueRef ac_build_buffer_load_format(struct ac_llvm_context *ctx, LLVMValueRef rsrc,
246                                          LLVMValueRef vindex, LLVMValueRef voffset,
247                                          unsigned num_channels, enum gl_access_qualifier access,
248                                          bool can_speculate, bool d16, bool tfe);
249 
250 LLVMValueRef ac_build_buffer_load_short(struct ac_llvm_context *ctx, LLVMValueRef rsrc,
251                                         LLVMValueRef voffset, LLVMValueRef soffset,
252                                         enum gl_access_qualifier access);
253 
254 LLVMValueRef ac_build_buffer_load_byte(struct ac_llvm_context *ctx, LLVMValueRef rsrc,
255                                        LLVMValueRef voffset, LLVMValueRef soffset,
256                                        enum gl_access_qualifier access);
257 
258 LLVMValueRef ac_build_safe_tbuffer_load(struct ac_llvm_context *ctx, LLVMValueRef rsrc,
259                                         LLVMValueRef vindex, LLVMValueRef voffset,
260                                         LLVMValueRef soffset,
261                                         const enum pipe_format format,
262                                         unsigned channel_bit_size,
263                                         unsigned const_offset,
264                                         unsigned align_offset,
265                                         unsigned align_mul,
266                                         unsigned num_channels,
267                                         enum gl_access_qualifier access,
268                                         bool can_speculate);
269 
270 void ac_build_buffer_store_short(struct ac_llvm_context *ctx, LLVMValueRef rsrc,
271                                  LLVMValueRef vdata, LLVMValueRef voffset, LLVMValueRef soffset,
272                                  enum gl_access_qualifier access);
273 
274 void ac_build_buffer_store_byte(struct ac_llvm_context *ctx, LLVMValueRef rsrc, LLVMValueRef vdata,
275                                 LLVMValueRef voffset, LLVMValueRef soffset, enum gl_access_qualifier access);
276 
277 void ac_set_range_metadata(struct ac_llvm_context *ctx, LLVMValueRef value, unsigned lo,
278                            unsigned hi);
279 LLVMValueRef ac_get_thread_id(struct ac_llvm_context *ctx);
280 
281 #define AC_TID_MASK_TOP_LEFT 0xfffffffc
282 #define AC_TID_MASK_TOP      0xfffffffd
283 #define AC_TID_MASK_LEFT     0xfffffffe
284 
285 LLVMValueRef ac_build_ddxy(struct ac_llvm_context *ctx, uint32_t mask, int idx, LLVMValueRef val);
286 
287 void ac_build_sendmsg(struct ac_llvm_context *ctx, uint32_t imm, LLVMValueRef m0_content);
288 
289 LLVMValueRef ac_build_imsb(struct ac_llvm_context *ctx, LLVMValueRef arg, LLVMTypeRef dst_type);
290 
291 LLVMValueRef ac_build_umsb(struct ac_llvm_context *ctx, LLVMValueRef arg, LLVMTypeRef dst_type,
292                            bool rev);
293 LLVMValueRef ac_build_fmin(struct ac_llvm_context *ctx, LLVMValueRef a, LLVMValueRef b);
294 LLVMValueRef ac_build_fmax(struct ac_llvm_context *ctx, LLVMValueRef a, LLVMValueRef b);
295 LLVMValueRef ac_build_imin(struct ac_llvm_context *ctx, LLVMValueRef a, LLVMValueRef b);
296 LLVMValueRef ac_build_imax(struct ac_llvm_context *ctx, LLVMValueRef a, LLVMValueRef b);
297 LLVMValueRef ac_build_umin(struct ac_llvm_context *ctx, LLVMValueRef a, LLVMValueRef b);
298 LLVMValueRef ac_build_umax(struct ac_llvm_context *ctx, LLVMValueRef a, LLVMValueRef b);
299 LLVMValueRef ac_build_clamp(struct ac_llvm_context *ctx, LLVMValueRef value);
300 
301 struct ac_export_args {
302    LLVMValueRef out[4];
303    unsigned target;
304    unsigned enabled_channels;
305    bool compr;
306    bool done;
307    bool valid_mask;
308 };
309 
310 void ac_build_export(struct ac_llvm_context *ctx, struct ac_export_args *a);
311 
312 void ac_build_export_null(struct ac_llvm_context *ctx, bool uses_discard);
313 
314 enum ac_image_opcode
315 {
316    ac_image_sample,
317    ac_image_gather4,
318    ac_image_load,
319    ac_image_load_mip,
320    ac_image_store,
321    ac_image_store_mip,
322    ac_image_get_lod,
323    ac_image_get_resinfo,
324    ac_image_atomic,
325    ac_image_atomic_cmpswap,
326 };
327 
328 enum ac_atomic_op
329 {
330    ac_atomic_swap,
331    ac_atomic_add,
332    ac_atomic_sub,
333    ac_atomic_smin,
334    ac_atomic_umin,
335    ac_atomic_smax,
336    ac_atomic_umax,
337    ac_atomic_and,
338    ac_atomic_or,
339    ac_atomic_xor,
340    ac_atomic_inc_wrap,
341    ac_atomic_dec_wrap,
342    ac_atomic_fmin,
343    ac_atomic_fmax,
344 };
345 
346 struct ac_image_args {
347    enum ac_image_opcode opcode;
348    enum ac_atomic_op atomic; /* for the ac_image_atomic opcode */
349    enum ac_image_dim dim;
350    enum gl_access_qualifier access;
351    unsigned dmask : 4;
352    bool unorm : 1;
353    bool level_zero : 1;
354    bool d16 : 1;        /* GFX8+: data and return values are 16-bit */
355    bool a16 : 1;        /* GFX9+: address components except compare, offset and bias are 16-bit */
356    bool g16 : 1;        /* GFX10+: derivatives are 16-bit; GFX<=9: must be equal to a16 */
357    bool tfe : 1;
358    unsigned attributes; /* additional call-site specific AC_FUNC_ATTRs */
359 
360    LLVMValueRef resource;
361    LLVMValueRef sampler;
362    LLVMValueRef data[2]; /* data[0] is source data (vector); data[1] is cmp for cmpswap */
363    LLVMValueRef offset;
364    LLVMValueRef bias;
365    LLVMValueRef compare;
366    LLVMValueRef derivs[6];
367    LLVMValueRef coords[4];
368    LLVMValueRef lod; // also used by ac_image_get_resinfo
369    LLVMValueRef min_lod;
370 };
371 
372 LLVMValueRef ac_build_image_opcode(struct ac_llvm_context *ctx, struct ac_image_args *a);
373 LLVMValueRef ac_build_cvt_pkrtz_f16(struct ac_llvm_context *ctx, LLVMValueRef args[2]);
374 LLVMValueRef ac_build_cvt_pknorm_i16(struct ac_llvm_context *ctx, LLVMValueRef args[2]);
375 LLVMValueRef ac_build_cvt_pknorm_u16(struct ac_llvm_context *ctx, LLVMValueRef args[2]);
376 LLVMValueRef ac_build_cvt_pknorm_i16_f16(struct ac_llvm_context *ctx, LLVMValueRef args[2]);
377 LLVMValueRef ac_build_cvt_pknorm_u16_f16(struct ac_llvm_context *ctx, LLVMValueRef args[2]);
378 LLVMValueRef ac_build_cvt_pk_i16(struct ac_llvm_context *ctx, LLVMValueRef args[2], unsigned bits,
379                                  bool hi);
380 LLVMValueRef ac_build_cvt_pk_u16(struct ac_llvm_context *ctx, LLVMValueRef args[2], unsigned bits,
381                                  bool hi);
382 LLVMValueRef ac_build_wqm_vote(struct ac_llvm_context *ctx, LLVMValueRef i1);
383 void ac_build_kill_if_false(struct ac_llvm_context *ctx, LLVMValueRef i1);
384 LLVMValueRef ac_build_bfe(struct ac_llvm_context *ctx, LLVMValueRef input, LLVMValueRef offset,
385                           LLVMValueRef width, bool is_signed);
386 LLVMValueRef ac_build_imad(struct ac_llvm_context *ctx, LLVMValueRef s0, LLVMValueRef s1,
387                            LLVMValueRef s2);
388 LLVMValueRef ac_build_fmad(struct ac_llvm_context *ctx, LLVMValueRef s0, LLVMValueRef s1,
389                            LLVMValueRef s2);
390 
391 void ac_build_waitcnt(struct ac_llvm_context *ctx, unsigned wait_flags);
392 
393 LLVMValueRef ac_build_fract(struct ac_llvm_context *ctx, LLVMValueRef src0, unsigned bitsize);
394 LLVMValueRef ac_const_uint_vec(struct ac_llvm_context *ctx, LLVMTypeRef type, uint64_t value);
395 LLVMValueRef ac_build_isign(struct ac_llvm_context *ctx, LLVMValueRef src0);
396 LLVMValueRef ac_build_fsign(struct ac_llvm_context *ctx, LLVMValueRef src);
397 LLVMValueRef ac_build_bit_count(struct ac_llvm_context *ctx, LLVMValueRef src0);
398 
399 LLVMValueRef ac_build_fsat(struct ac_llvm_context *ctx, LLVMValueRef src,
400                            LLVMTypeRef type);
401 
402 LLVMValueRef ac_build_bitfield_reverse(struct ac_llvm_context *ctx, LLVMValueRef src0);
403 
404 LLVMValueRef ac_build_sudot_4x8(struct ac_llvm_context *ctx, LLVMValueRef s0, LLVMValueRef s1,
405                                 LLVMValueRef s2, bool clamp, unsigned neg_lo);
406 
407 void ac_init_exec_full_mask(struct ac_llvm_context *ctx);
408 
409 void ac_declare_lds_as_pointer(struct ac_llvm_context *ac);
410 
411 LLVMValueRef ac_find_lsb(struct ac_llvm_context *ctx, LLVMTypeRef dst_type, LLVMValueRef src0);
412 
413 LLVMTypeRef ac_array_in_const_addr_space(LLVMTypeRef elem_type);
414 LLVMTypeRef ac_array_in_const32_addr_space(LLVMTypeRef elem_type);
415 
416 void ac_build_bgnloop(struct ac_llvm_context *ctx, int lable_id);
417 void ac_build_break(struct ac_llvm_context *ctx);
418 void ac_build_continue(struct ac_llvm_context *ctx);
419 void ac_build_else(struct ac_llvm_context *ctx, int lable_id);
420 void ac_build_endif(struct ac_llvm_context *ctx, int lable_id);
421 void ac_build_endloop(struct ac_llvm_context *ctx, int lable_id);
422 void ac_build_ifcc(struct ac_llvm_context *ctx, LLVMValueRef cond, int label_id);
423 
424 LLVMValueRef ac_build_alloca_undef(struct ac_llvm_context *ac, LLVMTypeRef type, const char *name);
425 
426 LLVMValueRef ac_trim_vector(struct ac_llvm_context *ctx, LLVMValueRef value, unsigned count);
427 
428 LLVMValueRef ac_unpack_param(struct ac_llvm_context *ctx, LLVMValueRef param, unsigned rshift,
429                              unsigned bitwidth);
430 
431 LLVMValueRef ac_build_ds_swizzle(struct ac_llvm_context *ctx, LLVMValueRef src, unsigned mask);
432 
433 LLVMValueRef ac_build_readlane(struct ac_llvm_context *ctx, LLVMValueRef src, LLVMValueRef lane);
434 
435 LLVMValueRef ac_build_writelane(struct ac_llvm_context *ctx, LLVMValueRef src, LLVMValueRef value,
436                                 LLVMValueRef lane);
437 
438 LLVMValueRef ac_build_mbcnt_add(struct ac_llvm_context *ctx, LLVMValueRef mask, LLVMValueRef add_src);
439 LLVMValueRef ac_build_mbcnt(struct ac_llvm_context *ctx, LLVMValueRef mask);
440 
441 LLVMValueRef ac_build_wqm(struct ac_llvm_context *ctx, LLVMValueRef src);
442 
443 LLVMValueRef ac_build_inclusive_scan(struct ac_llvm_context *ctx, LLVMValueRef src, nir_op op);
444 
445 LLVMValueRef ac_build_exclusive_scan(struct ac_llvm_context *ctx, LLVMValueRef src, nir_op op);
446 
447 LLVMValueRef ac_build_reduce(struct ac_llvm_context *ctx, LLVMValueRef src, nir_op op,
448                              unsigned cluster_size);
449 
450 LLVMValueRef ac_build_quad_swizzle(struct ac_llvm_context *ctx, LLVMValueRef src, unsigned lane0,
451                                    unsigned lane1, unsigned lane2, unsigned lane3,
452                                    bool use_wqm);
453 
454 LLVMValueRef ac_build_shuffle(struct ac_llvm_context *ctx, LLVMValueRef src, LLVMValueRef index);
455 
456 LLVMValueRef ac_build_frexp_exp(struct ac_llvm_context *ctx, LLVMValueRef src0, unsigned bitsize);
457 
458 LLVMValueRef ac_build_frexp_mant(struct ac_llvm_context *ctx, LLVMValueRef src0, unsigned bitsize);
459 
460 LLVMValueRef ac_build_canonicalize(struct ac_llvm_context *ctx, LLVMValueRef src0,
461                                    unsigned bitsize);
462 
463 LLVMValueRef ac_build_load_helper_invocation(struct ac_llvm_context *ctx);
464 
465 LLVMValueRef ac_build_call(struct ac_llvm_context *ctx, LLVMTypeRef fn_type, LLVMValueRef func,
466                            LLVMValueRef *args, unsigned num_args);
467 
468 LLVMValueRef ac_build_atomic_rmw(struct ac_llvm_context *ctx, LLVMAtomicRMWBinOp op,
469                                  LLVMValueRef ptr, LLVMValueRef val, const char *sync_scope);
470 
471 LLVMValueRef ac_build_atomic_cmp_xchg(struct ac_llvm_context *ctx, LLVMValueRef ptr,
472                                       LLVMValueRef cmp, LLVMValueRef val, const char *sync_scope);
473 
474 void ac_export_mrt_z(struct ac_llvm_context *ctx, LLVMValueRef depth, LLVMValueRef stencil,
475                      LLVMValueRef samplemask, LLVMValueRef mrt0_alpha, bool is_last,
476                      struct ac_export_args *args);
477 
478 struct ac_ngg_prim {
479    unsigned num_vertices;
480    LLVMValueRef isnull;
481    LLVMValueRef index[3];
482    LLVMValueRef edgeflags;
483    LLVMValueRef passthrough;
484 };
485 
486 LLVMTypeRef ac_arg_type_to_pointee_type(struct ac_llvm_context *ctx, enum ac_arg_type type);
487 
ac_get_arg(struct ac_llvm_context * ctx,struct ac_arg arg)488 static inline LLVMValueRef ac_get_arg(struct ac_llvm_context *ctx, struct ac_arg arg)
489 {
490    assert(arg.used);
491    if (arg.arg_index == ctx->ring_offsets_index)
492       return ctx->ring_offsets;
493    int offset = arg.arg_index > ctx->ring_offsets_index ? -1 : 0;
494    return LLVMGetParam(ctx->main_function.value, arg.arg_index + offset);
495 }
496 
497 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)498 ac_get_ptr_arg(struct ac_llvm_context *ctx, const struct ac_shader_args *args, struct ac_arg arg)
499 {
500    struct ac_llvm_pointer ptr;
501    ptr.pointee_type = ac_arg_type_to_pointee_type(ctx, args->args[arg.arg_index].type);
502    ptr.value = ac_get_arg(ctx, arg);
503    return ptr;
504 }
505 
506 enum ac_llvm_calling_convention
507 {
508    AC_LLVM_AMDGPU_VS = 87,
509    AC_LLVM_AMDGPU_GS = 88,
510    AC_LLVM_AMDGPU_PS = 89,
511    AC_LLVM_AMDGPU_CS = 90,
512    AC_LLVM_AMDGPU_HS = 93,
513 };
514 
515 struct ac_llvm_pointer ac_build_main(const struct ac_shader_args *args, struct ac_llvm_context *ctx,
516                                      enum ac_llvm_calling_convention convention, const char *name,
517                                      LLVMTypeRef ret_type, LLVMModuleRef module);
518 
519 LLVMValueRef ac_build_is_inf_or_nan(struct ac_llvm_context *ctx, LLVMValueRef a);
520 
521 void ac_build_dual_src_blend_swizzle(struct ac_llvm_context *ctx,
522                                      struct ac_export_args *mrt0,
523                                      struct ac_export_args *mrt1);
524 
525 #ifdef __cplusplus
526 }
527 #endif
528 
529 #endif
530