amd/common: add ac_vgt_gs_mode() helper
[mesa.git] / src / amd / common / ac_llvm_build.h
1 /*
2 * Copyright 2016 Bas Nieuwenhuizen
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sub license, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
15 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
16 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
17 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
18 * USE OR OTHER DEALINGS IN THE SOFTWARE.
19 *
20 * The above copyright notice and this permission notice (including the
21 * next paragraph) shall be included in all copies or substantial portions
22 * of the Software.
23 *
24 */
25 #ifndef AC_LLVM_BUILD_H
26 #define AC_LLVM_BUILD_H
27
28 #include <stdbool.h>
29 #include <llvm-c/TargetMachine.h>
30
31 #include "amd_family.h"
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 enum {
38 AC_LOCAL_ADDR_SPACE = 3,
39 };
40
41 struct ac_llvm_context {
42 LLVMContextRef context;
43 LLVMModuleRef module;
44 LLVMBuilderRef builder;
45
46 LLVMTypeRef voidt;
47 LLVMTypeRef i1;
48 LLVMTypeRef i8;
49 LLVMTypeRef i16;
50 LLVMTypeRef i32;
51 LLVMTypeRef i64;
52 LLVMTypeRef f16;
53 LLVMTypeRef f32;
54 LLVMTypeRef f64;
55 LLVMTypeRef v2i32;
56 LLVMTypeRef v3i32;
57 LLVMTypeRef v4i32;
58 LLVMTypeRef v2f32;
59 LLVMTypeRef v4f32;
60 LLVMTypeRef v8i32;
61
62 LLVMValueRef i32_0;
63 LLVMValueRef i32_1;
64 LLVMValueRef f32_0;
65 LLVMValueRef f32_1;
66 LLVMValueRef i1true;
67 LLVMValueRef i1false;
68
69 unsigned range_md_kind;
70 unsigned invariant_load_md_kind;
71 unsigned uniform_md_kind;
72 unsigned fpmath_md_kind;
73 LLVMValueRef fpmath_md_2p5_ulp;
74 LLVMValueRef empty_md;
75
76 enum chip_class chip_class;
77
78 LLVMValueRef lds;
79 };
80
81 void
82 ac_llvm_context_init(struct ac_llvm_context *ctx, LLVMContextRef context,
83 enum chip_class chip_class);
84
85 unsigned ac_get_type_size(LLVMTypeRef type);
86
87 LLVMTypeRef ac_to_integer_type(struct ac_llvm_context *ctx, LLVMTypeRef t);
88 LLVMValueRef ac_to_integer(struct ac_llvm_context *ctx, LLVMValueRef v);
89 LLVMTypeRef ac_to_float_type(struct ac_llvm_context *ctx, LLVMTypeRef t);
90 LLVMValueRef ac_to_float(struct ac_llvm_context *ctx, LLVMValueRef v);
91
92 LLVMValueRef
93 ac_build_intrinsic(struct ac_llvm_context *ctx, const char *name,
94 LLVMTypeRef return_type, LLVMValueRef *params,
95 unsigned param_count, unsigned attrib_mask);
96
97 void ac_build_type_name_for_intr(LLVMTypeRef type, char *buf, unsigned bufsize);
98
99 LLVMValueRef
100 ac_build_phi(struct ac_llvm_context *ctx, LLVMTypeRef type,
101 unsigned count_incoming, LLVMValueRef *values,
102 LLVMBasicBlockRef *blocks);
103
104 void ac_build_optimization_barrier(struct ac_llvm_context *ctx,
105 LLVMValueRef *pvgpr);
106
107 LLVMValueRef ac_build_ballot(struct ac_llvm_context *ctx, LLVMValueRef value);
108
109 LLVMValueRef ac_build_vote_all(struct ac_llvm_context *ctx, LLVMValueRef value);
110
111 LLVMValueRef ac_build_vote_any(struct ac_llvm_context *ctx, LLVMValueRef value);
112
113 LLVMValueRef ac_build_vote_eq(struct ac_llvm_context *ctx, LLVMValueRef value);
114
115 LLVMValueRef
116 ac_build_varying_gather_values(struct ac_llvm_context *ctx, LLVMValueRef *values,
117 unsigned value_count, unsigned component);
118
119 LLVMValueRef
120 ac_build_gather_values_extended(struct ac_llvm_context *ctx,
121 LLVMValueRef *values,
122 unsigned value_count,
123 unsigned value_stride,
124 bool load,
125 bool always_vector);
126 LLVMValueRef
127 ac_build_gather_values(struct ac_llvm_context *ctx,
128 LLVMValueRef *values,
129 unsigned value_count);
130
131 LLVMValueRef
132 ac_build_fdiv(struct ac_llvm_context *ctx,
133 LLVMValueRef num,
134 LLVMValueRef den);
135
136 void
137 ac_prepare_cube_coords(struct ac_llvm_context *ctx,
138 bool is_deriv, bool is_array, bool is_lod,
139 LLVMValueRef *coords_arg,
140 LLVMValueRef *derivs_arg);
141
142
143 LLVMValueRef
144 ac_build_fs_interp(struct ac_llvm_context *ctx,
145 LLVMValueRef llvm_chan,
146 LLVMValueRef attr_number,
147 LLVMValueRef params,
148 LLVMValueRef i,
149 LLVMValueRef j);
150
151 LLVMValueRef
152 ac_build_fs_interp_mov(struct ac_llvm_context *ctx,
153 LLVMValueRef parameter,
154 LLVMValueRef llvm_chan,
155 LLVMValueRef attr_number,
156 LLVMValueRef params);
157
158 LLVMValueRef
159 ac_build_gep0(struct ac_llvm_context *ctx,
160 LLVMValueRef base_ptr,
161 LLVMValueRef index);
162
163 void
164 ac_build_indexed_store(struct ac_llvm_context *ctx,
165 LLVMValueRef base_ptr, LLVMValueRef index,
166 LLVMValueRef value);
167
168 LLVMValueRef ac_build_load(struct ac_llvm_context *ctx, LLVMValueRef base_ptr,
169 LLVMValueRef index);
170 LLVMValueRef ac_build_load_invariant(struct ac_llvm_context *ctx,
171 LLVMValueRef base_ptr, LLVMValueRef index);
172 LLVMValueRef ac_build_load_to_sgpr(struct ac_llvm_context *ctx,
173 LLVMValueRef base_ptr, LLVMValueRef index);
174
175 void
176 ac_build_buffer_store_dword(struct ac_llvm_context *ctx,
177 LLVMValueRef rsrc,
178 LLVMValueRef vdata,
179 unsigned num_channels,
180 LLVMValueRef voffset,
181 LLVMValueRef soffset,
182 unsigned inst_offset,
183 bool glc,
184 bool slc,
185 bool writeonly_memory,
186 bool swizzle_enable_hint);
187 LLVMValueRef
188 ac_build_buffer_load(struct ac_llvm_context *ctx,
189 LLVMValueRef rsrc,
190 int num_channels,
191 LLVMValueRef vindex,
192 LLVMValueRef voffset,
193 LLVMValueRef soffset,
194 unsigned inst_offset,
195 unsigned glc,
196 unsigned slc,
197 bool can_speculate,
198 bool allow_smem);
199
200 LLVMValueRef ac_build_buffer_load_format(struct ac_llvm_context *ctx,
201 LLVMValueRef rsrc,
202 LLVMValueRef vindex,
203 LLVMValueRef voffset,
204 bool can_speculate);
205
206 LLVMValueRef
207 ac_get_thread_id(struct ac_llvm_context *ctx);
208
209 #define AC_TID_MASK_TOP_LEFT 0xfffffffc
210 #define AC_TID_MASK_TOP 0xfffffffd
211 #define AC_TID_MASK_LEFT 0xfffffffe
212
213 LLVMValueRef
214 ac_build_ddxy(struct ac_llvm_context *ctx,
215 uint32_t mask,
216 int idx,
217 LLVMValueRef val);
218
219 #define AC_SENDMSG_GS 2
220 #define AC_SENDMSG_GS_DONE 3
221
222 #define AC_SENDMSG_GS_OP_NOP (0 << 4)
223 #define AC_SENDMSG_GS_OP_CUT (1 << 4)
224 #define AC_SENDMSG_GS_OP_EMIT (2 << 4)
225 #define AC_SENDMSG_GS_OP_EMIT_CUT (3 << 4)
226
227 void ac_build_sendmsg(struct ac_llvm_context *ctx,
228 uint32_t msg,
229 LLVMValueRef wave_id);
230
231 LLVMValueRef ac_build_imsb(struct ac_llvm_context *ctx,
232 LLVMValueRef arg,
233 LLVMTypeRef dst_type);
234
235 LLVMValueRef ac_build_umsb(struct ac_llvm_context *ctx,
236 LLVMValueRef arg,
237 LLVMTypeRef dst_type);
238
239 LLVMValueRef ac_build_umin(struct ac_llvm_context *ctx, LLVMValueRef a, LLVMValueRef b);
240 LLVMValueRef ac_build_clamp(struct ac_llvm_context *ctx, LLVMValueRef value);
241
242 struct ac_export_args {
243 LLVMValueRef out[4];
244 unsigned target;
245 unsigned enabled_channels;
246 bool compr;
247 bool done;
248 bool valid_mask;
249 };
250
251 void ac_build_export(struct ac_llvm_context *ctx, struct ac_export_args *a);
252
253 enum ac_image_opcode {
254 ac_image_sample,
255 ac_image_gather4,
256 ac_image_load,
257 ac_image_load_mip,
258 ac_image_get_lod,
259 ac_image_get_resinfo,
260 };
261
262 struct ac_image_args {
263 enum ac_image_opcode opcode;
264 bool level_zero;
265 bool bias;
266 bool lod;
267 bool deriv;
268 bool compare;
269 bool offset;
270
271 LLVMValueRef resource;
272 LLVMValueRef sampler;
273 LLVMValueRef addr;
274 unsigned dmask;
275 bool unorm;
276 bool da;
277 };
278
279 LLVMValueRef ac_build_image_opcode(struct ac_llvm_context *ctx,
280 struct ac_image_args *a);
281 LLVMValueRef ac_build_cvt_pkrtz_f16(struct ac_llvm_context *ctx,
282 LLVMValueRef args[2]);
283 LLVMValueRef ac_build_wqm_vote(struct ac_llvm_context *ctx, LLVMValueRef i1);
284 void ac_build_kill_if_false(struct ac_llvm_context *ctx, LLVMValueRef i1);
285 LLVMValueRef ac_build_bfe(struct ac_llvm_context *ctx, LLVMValueRef input,
286 LLVMValueRef offset, LLVMValueRef width,
287 bool is_signed);
288
289 void ac_build_waitcnt(struct ac_llvm_context *ctx, unsigned simm16);
290
291 void ac_get_image_intr_name(const char *base_name,
292 LLVMTypeRef data_type,
293 LLVMTypeRef coords_type,
294 LLVMTypeRef rsrc_type,
295 char *out_name, unsigned out_len);
296
297 void ac_optimize_vs_outputs(struct ac_llvm_context *ac,
298 LLVMValueRef main_fn,
299 uint8_t *vs_output_param_offset,
300 uint32_t num_outputs,
301 uint8_t *num_param_exports);
302 void ac_init_exec_full_mask(struct ac_llvm_context *ctx);
303
304 void ac_declare_lds_as_pointer(struct ac_llvm_context *ac);
305 LLVMValueRef ac_lds_load(struct ac_llvm_context *ctx,
306 LLVMValueRef dw_addr);
307 void ac_lds_store(struct ac_llvm_context *ctx,
308 LLVMValueRef dw_addr, LLVMValueRef value);
309
310 LLVMValueRef ac_find_lsb(struct ac_llvm_context *ctx,
311 LLVMTypeRef dst_type,
312 LLVMValueRef src0);
313 #ifdef __cplusplus
314 }
315 #endif
316
317 #endif