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