ac: add f64_0 to the llvm build context
[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 f64_0;
67 LLVMValueRef f64_1;
68 LLVMValueRef i1true;
69 LLVMValueRef i1false;
70
71 unsigned range_md_kind;
72 unsigned invariant_load_md_kind;
73 unsigned uniform_md_kind;
74 unsigned fpmath_md_kind;
75 LLVMValueRef fpmath_md_2p5_ulp;
76 LLVMValueRef empty_md;
77
78 enum chip_class chip_class;
79 enum radeon_family family;
80
81 LLVMValueRef lds;
82 };
83
84 void
85 ac_llvm_context_init(struct ac_llvm_context *ctx, LLVMContextRef context,
86 enum chip_class chip_class, enum radeon_family family);
87
88 int
89 ac_get_llvm_num_components(LLVMValueRef value);
90
91 LLVMValueRef
92 ac_llvm_extract_elem(struct ac_llvm_context *ac,
93 LLVMValueRef value,
94 int index);
95
96 unsigned ac_get_type_size(LLVMTypeRef type);
97
98 LLVMTypeRef ac_to_integer_type(struct ac_llvm_context *ctx, LLVMTypeRef t);
99 LLVMValueRef ac_to_integer(struct ac_llvm_context *ctx, LLVMValueRef v);
100 LLVMTypeRef ac_to_float_type(struct ac_llvm_context *ctx, LLVMTypeRef t);
101 LLVMValueRef ac_to_float(struct ac_llvm_context *ctx, LLVMValueRef v);
102
103 LLVMValueRef
104 ac_build_intrinsic(struct ac_llvm_context *ctx, const char *name,
105 LLVMTypeRef return_type, LLVMValueRef *params,
106 unsigned param_count, unsigned attrib_mask);
107
108 void ac_build_type_name_for_intr(LLVMTypeRef type, char *buf, unsigned bufsize);
109
110 LLVMValueRef
111 ac_build_phi(struct ac_llvm_context *ctx, LLVMTypeRef type,
112 unsigned count_incoming, LLVMValueRef *values,
113 LLVMBasicBlockRef *blocks);
114
115 void ac_build_optimization_barrier(struct ac_llvm_context *ctx,
116 LLVMValueRef *pvgpr);
117
118 LLVMValueRef ac_build_ballot(struct ac_llvm_context *ctx, LLVMValueRef value);
119
120 LLVMValueRef ac_build_vote_all(struct ac_llvm_context *ctx, LLVMValueRef value);
121
122 LLVMValueRef ac_build_vote_any(struct ac_llvm_context *ctx, LLVMValueRef value);
123
124 LLVMValueRef ac_build_vote_eq(struct ac_llvm_context *ctx, LLVMValueRef value);
125
126 LLVMValueRef
127 ac_build_varying_gather_values(struct ac_llvm_context *ctx, LLVMValueRef *values,
128 unsigned value_count, unsigned component);
129
130 LLVMValueRef
131 ac_build_gather_values_extended(struct ac_llvm_context *ctx,
132 LLVMValueRef *values,
133 unsigned value_count,
134 unsigned value_stride,
135 bool load,
136 bool always_vector);
137 LLVMValueRef
138 ac_build_gather_values(struct ac_llvm_context *ctx,
139 LLVMValueRef *values,
140 unsigned value_count);
141
142 LLVMValueRef
143 ac_build_fdiv(struct ac_llvm_context *ctx,
144 LLVMValueRef num,
145 LLVMValueRef den);
146
147 void
148 ac_prepare_cube_coords(struct ac_llvm_context *ctx,
149 bool is_deriv, bool is_array, bool is_lod,
150 LLVMValueRef *coords_arg,
151 LLVMValueRef *derivs_arg);
152
153
154 LLVMValueRef
155 ac_build_fs_interp(struct ac_llvm_context *ctx,
156 LLVMValueRef llvm_chan,
157 LLVMValueRef attr_number,
158 LLVMValueRef params,
159 LLVMValueRef i,
160 LLVMValueRef j);
161
162 LLVMValueRef
163 ac_build_fs_interp_mov(struct ac_llvm_context *ctx,
164 LLVMValueRef parameter,
165 LLVMValueRef llvm_chan,
166 LLVMValueRef attr_number,
167 LLVMValueRef params);
168
169 LLVMValueRef
170 ac_build_gep0(struct ac_llvm_context *ctx,
171 LLVMValueRef base_ptr,
172 LLVMValueRef index);
173
174 void
175 ac_build_indexed_store(struct ac_llvm_context *ctx,
176 LLVMValueRef base_ptr, LLVMValueRef index,
177 LLVMValueRef value);
178
179 LLVMValueRef ac_build_load(struct ac_llvm_context *ctx, LLVMValueRef base_ptr,
180 LLVMValueRef index);
181 LLVMValueRef ac_build_load_invariant(struct ac_llvm_context *ctx,
182 LLVMValueRef base_ptr, LLVMValueRef index);
183 LLVMValueRef ac_build_load_to_sgpr(struct ac_llvm_context *ctx,
184 LLVMValueRef base_ptr, LLVMValueRef index);
185
186 void
187 ac_build_buffer_store_dword(struct ac_llvm_context *ctx,
188 LLVMValueRef rsrc,
189 LLVMValueRef vdata,
190 unsigned num_channels,
191 LLVMValueRef voffset,
192 LLVMValueRef soffset,
193 unsigned inst_offset,
194 bool glc,
195 bool slc,
196 bool writeonly_memory,
197 bool swizzle_enable_hint);
198 LLVMValueRef
199 ac_build_buffer_load(struct ac_llvm_context *ctx,
200 LLVMValueRef rsrc,
201 int num_channels,
202 LLVMValueRef vindex,
203 LLVMValueRef voffset,
204 LLVMValueRef soffset,
205 unsigned inst_offset,
206 unsigned glc,
207 unsigned slc,
208 bool can_speculate,
209 bool allow_smem);
210
211 LLVMValueRef ac_build_buffer_load_format(struct ac_llvm_context *ctx,
212 LLVMValueRef rsrc,
213 LLVMValueRef vindex,
214 LLVMValueRef voffset,
215 bool can_speculate);
216
217 LLVMValueRef
218 ac_get_thread_id(struct ac_llvm_context *ctx);
219
220 #define AC_TID_MASK_TOP_LEFT 0xfffffffc
221 #define AC_TID_MASK_TOP 0xfffffffd
222 #define AC_TID_MASK_LEFT 0xfffffffe
223
224 LLVMValueRef
225 ac_build_ddxy(struct ac_llvm_context *ctx,
226 uint32_t mask,
227 int idx,
228 LLVMValueRef val);
229
230 #define AC_SENDMSG_GS 2
231 #define AC_SENDMSG_GS_DONE 3
232
233 #define AC_SENDMSG_GS_OP_NOP (0 << 4)
234 #define AC_SENDMSG_GS_OP_CUT (1 << 4)
235 #define AC_SENDMSG_GS_OP_EMIT (2 << 4)
236 #define AC_SENDMSG_GS_OP_EMIT_CUT (3 << 4)
237
238 void ac_build_sendmsg(struct ac_llvm_context *ctx,
239 uint32_t msg,
240 LLVMValueRef wave_id);
241
242 LLVMValueRef ac_build_imsb(struct ac_llvm_context *ctx,
243 LLVMValueRef arg,
244 LLVMTypeRef dst_type);
245
246 LLVMValueRef ac_build_umsb(struct ac_llvm_context *ctx,
247 LLVMValueRef arg,
248 LLVMTypeRef dst_type);
249 LLVMValueRef ac_build_fmin(struct ac_llvm_context *ctx, LLVMValueRef a,
250 LLVMValueRef b);
251 LLVMValueRef ac_build_fmax(struct ac_llvm_context *ctx, LLVMValueRef a,
252 LLVMValueRef b);
253 LLVMValueRef ac_build_umin(struct ac_llvm_context *ctx, LLVMValueRef a, LLVMValueRef b);
254 LLVMValueRef ac_build_clamp(struct ac_llvm_context *ctx, LLVMValueRef value);
255
256 struct ac_export_args {
257 LLVMValueRef out[4];
258 unsigned target;
259 unsigned enabled_channels;
260 bool compr;
261 bool done;
262 bool valid_mask;
263 };
264
265 void ac_build_export(struct ac_llvm_context *ctx, struct ac_export_args *a);
266
267 enum ac_image_opcode {
268 ac_image_sample,
269 ac_image_gather4,
270 ac_image_load,
271 ac_image_load_mip,
272 ac_image_get_lod,
273 ac_image_get_resinfo,
274 };
275
276 struct ac_image_args {
277 enum ac_image_opcode opcode;
278 bool level_zero;
279 bool bias;
280 bool lod;
281 bool deriv;
282 bool compare;
283 bool offset;
284
285 LLVMValueRef resource;
286 LLVMValueRef sampler;
287 LLVMValueRef addr;
288 unsigned dmask;
289 bool unorm;
290 bool da;
291 };
292
293 LLVMValueRef ac_build_image_opcode(struct ac_llvm_context *ctx,
294 struct ac_image_args *a);
295 LLVMValueRef ac_build_cvt_pkrtz_f16(struct ac_llvm_context *ctx,
296 LLVMValueRef args[2]);
297 LLVMValueRef ac_build_wqm_vote(struct ac_llvm_context *ctx, LLVMValueRef i1);
298 void ac_build_kill_if_false(struct ac_llvm_context *ctx, LLVMValueRef i1);
299 LLVMValueRef ac_build_bfe(struct ac_llvm_context *ctx, LLVMValueRef input,
300 LLVMValueRef offset, LLVMValueRef width,
301 bool is_signed);
302
303 void ac_build_waitcnt(struct ac_llvm_context *ctx, unsigned simm16);
304
305 void ac_get_image_intr_name(const char *base_name,
306 LLVMTypeRef data_type,
307 LLVMTypeRef coords_type,
308 LLVMTypeRef rsrc_type,
309 char *out_name, unsigned out_len);
310
311 void ac_optimize_vs_outputs(struct ac_llvm_context *ac,
312 LLVMValueRef main_fn,
313 uint8_t *vs_output_param_offset,
314 uint32_t num_outputs,
315 uint8_t *num_param_exports);
316 void ac_init_exec_full_mask(struct ac_llvm_context *ctx);
317
318 void ac_declare_lds_as_pointer(struct ac_llvm_context *ac);
319 LLVMValueRef ac_lds_load(struct ac_llvm_context *ctx,
320 LLVMValueRef dw_addr);
321 void ac_lds_store(struct ac_llvm_context *ctx,
322 LLVMValueRef dw_addr, LLVMValueRef value);
323
324 LLVMValueRef ac_find_lsb(struct ac_llvm_context *ctx,
325 LLVMTypeRef dst_type,
326 LLVMValueRef src0);
327 #ifdef __cplusplus
328 }
329 #endif
330
331 #endif