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