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