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