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