2 * Copyright 2016 Bas Nieuwenhuizen
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:
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.
20 * The above copyright notice and this permission notice (including the
21 * next paragraph) shall be included in all copies or substantial portions
25 #ifndef AC_LLVM_BUILD_H
26 #define AC_LLVM_BUILD_H
29 #include <llvm-c/TargetMachine.h>
35 struct ac_llvm_context
{
36 LLVMContextRef context
;
38 LLVMBuilderRef builder
;
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
;
67 ac_llvm_context_init(struct ac_llvm_context
*ctx
, LLVMContextRef context
);
69 unsigned ac_get_type_size(LLVMTypeRef type
);
72 ac_build_intrinsic(struct ac_llvm_context
*ctx
, const char *name
,
73 LLVMTypeRef return_type
, LLVMValueRef
*params
,
74 unsigned param_count
, unsigned attrib_mask
);
76 void ac_build_type_name_for_intr(LLVMTypeRef type
, char *buf
, unsigned bufsize
);
78 void ac_build_optimization_barrier(struct ac_llvm_context
*ctx
,
81 ac_build_gather_values_extended(struct ac_llvm_context
*ctx
,
84 unsigned value_stride
,
88 ac_build_gather_values(struct ac_llvm_context
*ctx
,
90 unsigned value_count
);
93 ac_build_fdiv(struct ac_llvm_context
*ctx
,
98 ac_prepare_cube_coords(struct ac_llvm_context
*ctx
,
99 bool is_deriv
, bool is_array
,
100 LLVMValueRef
*coords_arg
,
101 LLVMValueRef
*derivs_arg
);
105 ac_build_fs_interp(struct ac_llvm_context
*ctx
,
106 LLVMValueRef llvm_chan
,
107 LLVMValueRef attr_number
,
113 ac_build_fs_interp_mov(struct ac_llvm_context
*ctx
,
114 LLVMValueRef parameter
,
115 LLVMValueRef llvm_chan
,
116 LLVMValueRef attr_number
,
117 LLVMValueRef params
);
120 ac_build_gep0(struct ac_llvm_context
*ctx
,
121 LLVMValueRef base_ptr
,
125 ac_build_indexed_store(struct ac_llvm_context
*ctx
,
126 LLVMValueRef base_ptr
, LLVMValueRef index
,
130 ac_build_indexed_load(struct ac_llvm_context
*ctx
,
131 LLVMValueRef base_ptr
, LLVMValueRef index
,
135 ac_build_indexed_load_const(struct ac_llvm_context
*ctx
,
136 LLVMValueRef base_ptr
, LLVMValueRef index
);
139 ac_build_buffer_store_dword(struct ac_llvm_context
*ctx
,
142 unsigned num_channels
,
143 LLVMValueRef voffset
,
144 LLVMValueRef soffset
,
145 unsigned inst_offset
,
148 bool writeonly_memory
,
151 ac_build_buffer_load(struct ac_llvm_context
*ctx
,
155 LLVMValueRef voffset
,
156 LLVMValueRef soffset
,
157 unsigned inst_offset
,
163 LLVMValueRef
ac_build_buffer_load_format(struct ac_llvm_context
*ctx
,
166 LLVMValueRef voffset
,
170 ac_get_thread_id(struct ac_llvm_context
*ctx
);
172 #define AC_TID_MASK_TOP_LEFT 0xfffffffc
173 #define AC_TID_MASK_TOP 0xfffffffd
174 #define AC_TID_MASK_LEFT 0xfffffffe
177 ac_build_ddxy(struct ac_llvm_context
*ctx
,
178 bool has_ds_bpermute
,
183 #define AC_SENDMSG_GS 2
184 #define AC_SENDMSG_GS_DONE 3
186 #define AC_SENDMSG_GS_OP_NOP (0 << 4)
187 #define AC_SENDMSG_GS_OP_CUT (1 << 4)
188 #define AC_SENDMSG_GS_OP_EMIT (2 << 4)
189 #define AC_SENDMSG_GS_OP_EMIT_CUT (3 << 4)
191 void ac_build_sendmsg(struct ac_llvm_context
*ctx
,
193 LLVMValueRef wave_id
);
195 LLVMValueRef
ac_build_imsb(struct ac_llvm_context
*ctx
,
197 LLVMTypeRef dst_type
);
199 LLVMValueRef
ac_build_umsb(struct ac_llvm_context
*ctx
,
201 LLVMTypeRef dst_type
);
203 LLVMValueRef
ac_build_umin(struct ac_llvm_context
*ctx
, LLVMValueRef a
, LLVMValueRef b
);
204 LLVMValueRef
ac_build_clamp(struct ac_llvm_context
*ctx
, LLVMValueRef value
);
206 struct ac_export_args
{
209 unsigned enabled_channels
;
215 void ac_build_export(struct ac_llvm_context
*ctx
, struct ac_export_args
*a
);
217 enum ac_image_opcode
{
223 ac_image_get_resinfo
,
226 struct ac_image_args
{
227 enum ac_image_opcode opcode
;
235 LLVMValueRef resource
;
236 LLVMValueRef sampler
;
243 LLVMValueRef
ac_build_image_opcode(struct ac_llvm_context
*ctx
,
244 struct ac_image_args
*a
);
245 LLVMValueRef
ac_build_cvt_pkrtz_f16(struct ac_llvm_context
*ctx
,
246 LLVMValueRef args
[2]);
247 void ac_build_kill(struct ac_llvm_context
*ctx
, LLVMValueRef value
);
248 LLVMValueRef
ac_build_bfe(struct ac_llvm_context
*ctx
, LLVMValueRef input
,
249 LLVMValueRef offset
, LLVMValueRef width
,
252 void ac_get_image_intr_name(const char *base_name
,
253 LLVMTypeRef data_type
,
254 LLVMTypeRef coords_type
,
255 LLVMTypeRef rsrc_type
,
256 char *out_name
, unsigned out_len
);
258 void ac_optimize_vs_outputs(struct ac_llvm_context
*ac
,
259 LLVMValueRef main_fn
,
260 uint8_t *vs_output_param_offset
,
261 uint32_t num_outputs
,
262 uint8_t *num_param_exports
);