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