ac: clean up ac_build_indexed_load function interfaces
[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 struct ac_llvm_context {
38 LLVMContextRef context;
39 LLVMModuleRef module;
40 LLVMBuilderRef builder;
41
42 LLVMTypeRef voidt;
43 LLVMTypeRef i1;
44 LLVMTypeRef i8;
45 LLVMTypeRef i16;
46 LLVMTypeRef i32;
47 LLVMTypeRef i64;
48 LLVMTypeRef f16;
49 LLVMTypeRef f32;
50 LLVMTypeRef f64;
51 LLVMTypeRef v4i32;
52 LLVMTypeRef v4f32;
53 LLVMTypeRef v8i32;
54
55 LLVMValueRef i32_0;
56 LLVMValueRef i32_1;
57 LLVMValueRef f32_0;
58 LLVMValueRef f32_1;
59
60 unsigned range_md_kind;
61 unsigned invariant_load_md_kind;
62 unsigned uniform_md_kind;
63 unsigned fpmath_md_kind;
64 LLVMValueRef fpmath_md_2p5_ulp;
65 LLVMValueRef empty_md;
66
67 enum chip_class chip_class;
68 };
69
70 void
71 ac_llvm_context_init(struct ac_llvm_context *ctx, LLVMContextRef context,
72 enum chip_class chip_class);
73
74 unsigned ac_get_type_size(LLVMTypeRef type);
75
76 LLVMTypeRef ac_to_integer_type(struct ac_llvm_context *ctx, LLVMTypeRef t);
77 LLVMValueRef ac_to_integer(struct ac_llvm_context *ctx, LLVMValueRef v);
78 LLVMTypeRef ac_to_float_type(struct ac_llvm_context *ctx, LLVMTypeRef t);
79 LLVMValueRef ac_to_float(struct ac_llvm_context *ctx, LLVMValueRef v);
80
81 LLVMValueRef
82 ac_build_intrinsic(struct ac_llvm_context *ctx, const char *name,
83 LLVMTypeRef return_type, LLVMValueRef *params,
84 unsigned param_count, unsigned attrib_mask);
85
86 void ac_build_type_name_for_intr(LLVMTypeRef type, char *buf, unsigned bufsize);
87
88 LLVMValueRef
89 ac_build_phi(struct ac_llvm_context *ctx, LLVMTypeRef type,
90 unsigned count_incoming, LLVMValueRef *values,
91 LLVMBasicBlockRef *blocks);
92
93 void ac_build_optimization_barrier(struct ac_llvm_context *ctx,
94 LLVMValueRef *pvgpr);
95
96 LLVMValueRef ac_build_ballot(struct ac_llvm_context *ctx, LLVMValueRef value);
97
98 LLVMValueRef ac_build_vote_all(struct ac_llvm_context *ctx, LLVMValueRef value);
99
100 LLVMValueRef ac_build_vote_any(struct ac_llvm_context *ctx, LLVMValueRef value);
101
102 LLVMValueRef ac_build_vote_eq(struct ac_llvm_context *ctx, LLVMValueRef value);
103
104 LLVMValueRef
105 ac_build_gather_values_extended(struct ac_llvm_context *ctx,
106 LLVMValueRef *values,
107 unsigned value_count,
108 unsigned value_stride,
109 bool load,
110 bool always_vector);
111 LLVMValueRef
112 ac_build_gather_values(struct ac_llvm_context *ctx,
113 LLVMValueRef *values,
114 unsigned value_count);
115
116 LLVMValueRef
117 ac_build_fdiv(struct ac_llvm_context *ctx,
118 LLVMValueRef num,
119 LLVMValueRef den);
120
121 void
122 ac_prepare_cube_coords(struct ac_llvm_context *ctx,
123 bool is_deriv, bool is_array, bool is_lod,
124 LLVMValueRef *coords_arg,
125 LLVMValueRef *derivs_arg);
126
127
128 LLVMValueRef
129 ac_build_fs_interp(struct ac_llvm_context *ctx,
130 LLVMValueRef llvm_chan,
131 LLVMValueRef attr_number,
132 LLVMValueRef params,
133 LLVMValueRef i,
134 LLVMValueRef j);
135
136 LLVMValueRef
137 ac_build_fs_interp_mov(struct ac_llvm_context *ctx,
138 LLVMValueRef parameter,
139 LLVMValueRef llvm_chan,
140 LLVMValueRef attr_number,
141 LLVMValueRef params);
142
143 LLVMValueRef
144 ac_build_gep0(struct ac_llvm_context *ctx,
145 LLVMValueRef base_ptr,
146 LLVMValueRef index);
147
148 void
149 ac_build_indexed_store(struct ac_llvm_context *ctx,
150 LLVMValueRef base_ptr, LLVMValueRef index,
151 LLVMValueRef value);
152
153 LLVMValueRef ac_build_load(struct ac_llvm_context *ctx, LLVMValueRef base_ptr,
154 LLVMValueRef index);
155 LLVMValueRef ac_build_load_invariant(struct ac_llvm_context *ctx,
156 LLVMValueRef base_ptr, LLVMValueRef index);
157 LLVMValueRef ac_build_load_to_sgpr(struct ac_llvm_context *ctx,
158 LLVMValueRef base_ptr, LLVMValueRef index);
159
160 void
161 ac_build_buffer_store_dword(struct ac_llvm_context *ctx,
162 LLVMValueRef rsrc,
163 LLVMValueRef vdata,
164 unsigned num_channels,
165 LLVMValueRef voffset,
166 LLVMValueRef soffset,
167 unsigned inst_offset,
168 bool glc,
169 bool slc,
170 bool writeonly_memory,
171 bool swizzle_enable_hint);
172 LLVMValueRef
173 ac_build_buffer_load(struct ac_llvm_context *ctx,
174 LLVMValueRef rsrc,
175 int num_channels,
176 LLVMValueRef vindex,
177 LLVMValueRef voffset,
178 LLVMValueRef soffset,
179 unsigned inst_offset,
180 unsigned glc,
181 unsigned slc,
182 bool can_speculate,
183 bool allow_smem);
184
185 LLVMValueRef ac_build_buffer_load_format(struct ac_llvm_context *ctx,
186 LLVMValueRef rsrc,
187 LLVMValueRef vindex,
188 LLVMValueRef voffset,
189 bool can_speculate);
190
191 LLVMValueRef
192 ac_get_thread_id(struct ac_llvm_context *ctx);
193
194 #define AC_TID_MASK_TOP_LEFT 0xfffffffc
195 #define AC_TID_MASK_TOP 0xfffffffd
196 #define AC_TID_MASK_LEFT 0xfffffffe
197
198 LLVMValueRef
199 ac_build_ddxy(struct ac_llvm_context *ctx,
200 uint32_t mask,
201 int idx,
202 LLVMValueRef val);
203
204 #define AC_SENDMSG_GS 2
205 #define AC_SENDMSG_GS_DONE 3
206
207 #define AC_SENDMSG_GS_OP_NOP (0 << 4)
208 #define AC_SENDMSG_GS_OP_CUT (1 << 4)
209 #define AC_SENDMSG_GS_OP_EMIT (2 << 4)
210 #define AC_SENDMSG_GS_OP_EMIT_CUT (3 << 4)
211
212 void ac_build_sendmsg(struct ac_llvm_context *ctx,
213 uint32_t msg,
214 LLVMValueRef wave_id);
215
216 LLVMValueRef ac_build_imsb(struct ac_llvm_context *ctx,
217 LLVMValueRef arg,
218 LLVMTypeRef dst_type);
219
220 LLVMValueRef ac_build_umsb(struct ac_llvm_context *ctx,
221 LLVMValueRef arg,
222 LLVMTypeRef dst_type);
223
224 LLVMValueRef ac_build_umin(struct ac_llvm_context *ctx, LLVMValueRef a, LLVMValueRef b);
225 LLVMValueRef ac_build_clamp(struct ac_llvm_context *ctx, LLVMValueRef value);
226
227 struct ac_export_args {
228 LLVMValueRef out[4];
229 unsigned target;
230 unsigned enabled_channels;
231 bool compr;
232 bool done;
233 bool valid_mask;
234 };
235
236 void ac_build_export(struct ac_llvm_context *ctx, struct ac_export_args *a);
237
238 enum ac_image_opcode {
239 ac_image_sample,
240 ac_image_gather4,
241 ac_image_load,
242 ac_image_load_mip,
243 ac_image_get_lod,
244 ac_image_get_resinfo,
245 };
246
247 struct ac_image_args {
248 enum ac_image_opcode opcode;
249 bool level_zero;
250 bool bias;
251 bool lod;
252 bool deriv;
253 bool compare;
254 bool offset;
255
256 LLVMValueRef resource;
257 LLVMValueRef sampler;
258 LLVMValueRef addr;
259 unsigned dmask;
260 bool unorm;
261 bool da;
262 };
263
264 LLVMValueRef ac_build_image_opcode(struct ac_llvm_context *ctx,
265 struct ac_image_args *a);
266 LLVMValueRef ac_build_cvt_pkrtz_f16(struct ac_llvm_context *ctx,
267 LLVMValueRef args[2]);
268 void ac_build_kill(struct ac_llvm_context *ctx, LLVMValueRef value);
269 LLVMValueRef ac_build_bfe(struct ac_llvm_context *ctx, LLVMValueRef input,
270 LLVMValueRef offset, LLVMValueRef width,
271 bool is_signed);
272
273 void ac_get_image_intr_name(const char *base_name,
274 LLVMTypeRef data_type,
275 LLVMTypeRef coords_type,
276 LLVMTypeRef rsrc_type,
277 char *out_name, unsigned out_len);
278
279 void ac_optimize_vs_outputs(struct ac_llvm_context *ac,
280 LLVMValueRef main_fn,
281 uint8_t *vs_output_param_offset,
282 uint32_t num_outputs,
283 uint8_t *num_param_exports);
284 #ifdef __cplusplus
285 }
286 #endif
287
288 #endif