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>
31 #include "amd_family.h"
38 AC_LOCAL_ADDR_SPACE
= 3,
41 struct ac_llvm_context
{
42 LLVMContextRef context
;
44 LLVMBuilderRef builder
;
69 unsigned range_md_kind
;
70 unsigned invariant_load_md_kind
;
71 unsigned uniform_md_kind
;
72 unsigned fpmath_md_kind
;
73 LLVMValueRef fpmath_md_2p5_ulp
;
74 LLVMValueRef empty_md
;
76 enum chip_class chip_class
;
77 enum radeon_family family
;
83 ac_llvm_context_init(struct ac_llvm_context
*ctx
, LLVMContextRef context
,
84 enum chip_class chip_class
, enum radeon_family family
);
86 unsigned ac_get_type_size(LLVMTypeRef type
);
88 LLVMTypeRef
ac_to_integer_type(struct ac_llvm_context
*ctx
, LLVMTypeRef t
);
89 LLVMValueRef
ac_to_integer(struct ac_llvm_context
*ctx
, LLVMValueRef v
);
90 LLVMTypeRef
ac_to_float_type(struct ac_llvm_context
*ctx
, LLVMTypeRef t
);
91 LLVMValueRef
ac_to_float(struct ac_llvm_context
*ctx
, LLVMValueRef v
);
94 ac_build_intrinsic(struct ac_llvm_context
*ctx
, const char *name
,
95 LLVMTypeRef return_type
, LLVMValueRef
*params
,
96 unsigned param_count
, unsigned attrib_mask
);
98 void ac_build_type_name_for_intr(LLVMTypeRef type
, char *buf
, unsigned bufsize
);
101 ac_build_phi(struct ac_llvm_context
*ctx
, LLVMTypeRef type
,
102 unsigned count_incoming
, LLVMValueRef
*values
,
103 LLVMBasicBlockRef
*blocks
);
105 void ac_build_optimization_barrier(struct ac_llvm_context
*ctx
,
106 LLVMValueRef
*pvgpr
);
108 LLVMValueRef
ac_build_ballot(struct ac_llvm_context
*ctx
, LLVMValueRef value
);
110 LLVMValueRef
ac_build_vote_all(struct ac_llvm_context
*ctx
, LLVMValueRef value
);
112 LLVMValueRef
ac_build_vote_any(struct ac_llvm_context
*ctx
, LLVMValueRef value
);
114 LLVMValueRef
ac_build_vote_eq(struct ac_llvm_context
*ctx
, LLVMValueRef value
);
117 ac_build_varying_gather_values(struct ac_llvm_context
*ctx
, LLVMValueRef
*values
,
118 unsigned value_count
, unsigned component
);
121 ac_build_gather_values_extended(struct ac_llvm_context
*ctx
,
122 LLVMValueRef
*values
,
123 unsigned value_count
,
124 unsigned value_stride
,
128 ac_build_gather_values(struct ac_llvm_context
*ctx
,
129 LLVMValueRef
*values
,
130 unsigned value_count
);
133 ac_build_fdiv(struct ac_llvm_context
*ctx
,
138 ac_prepare_cube_coords(struct ac_llvm_context
*ctx
,
139 bool is_deriv
, bool is_array
, bool is_lod
,
140 LLVMValueRef
*coords_arg
,
141 LLVMValueRef
*derivs_arg
);
145 ac_build_fs_interp(struct ac_llvm_context
*ctx
,
146 LLVMValueRef llvm_chan
,
147 LLVMValueRef attr_number
,
153 ac_build_fs_interp_mov(struct ac_llvm_context
*ctx
,
154 LLVMValueRef parameter
,
155 LLVMValueRef llvm_chan
,
156 LLVMValueRef attr_number
,
157 LLVMValueRef params
);
160 ac_build_gep0(struct ac_llvm_context
*ctx
,
161 LLVMValueRef base_ptr
,
165 ac_build_indexed_store(struct ac_llvm_context
*ctx
,
166 LLVMValueRef base_ptr
, LLVMValueRef index
,
169 LLVMValueRef
ac_build_load(struct ac_llvm_context
*ctx
, LLVMValueRef base_ptr
,
171 LLVMValueRef
ac_build_load_invariant(struct ac_llvm_context
*ctx
,
172 LLVMValueRef base_ptr
, LLVMValueRef index
);
173 LLVMValueRef
ac_build_load_to_sgpr(struct ac_llvm_context
*ctx
,
174 LLVMValueRef base_ptr
, LLVMValueRef index
);
177 ac_build_buffer_store_dword(struct ac_llvm_context
*ctx
,
180 unsigned num_channels
,
181 LLVMValueRef voffset
,
182 LLVMValueRef soffset
,
183 unsigned inst_offset
,
186 bool writeonly_memory
,
187 bool swizzle_enable_hint
);
189 ac_build_buffer_load(struct ac_llvm_context
*ctx
,
193 LLVMValueRef voffset
,
194 LLVMValueRef soffset
,
195 unsigned inst_offset
,
201 LLVMValueRef
ac_build_buffer_load_format(struct ac_llvm_context
*ctx
,
204 LLVMValueRef voffset
,
208 ac_get_thread_id(struct ac_llvm_context
*ctx
);
210 #define AC_TID_MASK_TOP_LEFT 0xfffffffc
211 #define AC_TID_MASK_TOP 0xfffffffd
212 #define AC_TID_MASK_LEFT 0xfffffffe
215 ac_build_ddxy(struct ac_llvm_context
*ctx
,
220 #define AC_SENDMSG_GS 2
221 #define AC_SENDMSG_GS_DONE 3
223 #define AC_SENDMSG_GS_OP_NOP (0 << 4)
224 #define AC_SENDMSG_GS_OP_CUT (1 << 4)
225 #define AC_SENDMSG_GS_OP_EMIT (2 << 4)
226 #define AC_SENDMSG_GS_OP_EMIT_CUT (3 << 4)
228 void ac_build_sendmsg(struct ac_llvm_context
*ctx
,
230 LLVMValueRef wave_id
);
232 LLVMValueRef
ac_build_imsb(struct ac_llvm_context
*ctx
,
234 LLVMTypeRef dst_type
);
236 LLVMValueRef
ac_build_umsb(struct ac_llvm_context
*ctx
,
238 LLVMTypeRef dst_type
);
240 LLVMValueRef
ac_build_umin(struct ac_llvm_context
*ctx
, LLVMValueRef a
, LLVMValueRef b
);
241 LLVMValueRef
ac_build_clamp(struct ac_llvm_context
*ctx
, LLVMValueRef value
);
243 struct ac_export_args
{
246 unsigned enabled_channels
;
252 void ac_build_export(struct ac_llvm_context
*ctx
, struct ac_export_args
*a
);
254 enum ac_image_opcode
{
260 ac_image_get_resinfo
,
263 struct ac_image_args
{
264 enum ac_image_opcode opcode
;
272 LLVMValueRef resource
;
273 LLVMValueRef sampler
;
280 LLVMValueRef
ac_build_image_opcode(struct ac_llvm_context
*ctx
,
281 struct ac_image_args
*a
);
282 LLVMValueRef
ac_build_cvt_pkrtz_f16(struct ac_llvm_context
*ctx
,
283 LLVMValueRef args
[2]);
284 LLVMValueRef
ac_build_wqm_vote(struct ac_llvm_context
*ctx
, LLVMValueRef i1
);
285 void ac_build_kill_if_false(struct ac_llvm_context
*ctx
, LLVMValueRef i1
);
286 LLVMValueRef
ac_build_bfe(struct ac_llvm_context
*ctx
, LLVMValueRef input
,
287 LLVMValueRef offset
, LLVMValueRef width
,
290 void ac_build_waitcnt(struct ac_llvm_context
*ctx
, unsigned simm16
);
292 void ac_get_image_intr_name(const char *base_name
,
293 LLVMTypeRef data_type
,
294 LLVMTypeRef coords_type
,
295 LLVMTypeRef rsrc_type
,
296 char *out_name
, unsigned out_len
);
298 void ac_optimize_vs_outputs(struct ac_llvm_context
*ac
,
299 LLVMValueRef main_fn
,
300 uint8_t *vs_output_param_offset
,
301 uint32_t num_outputs
,
302 uint8_t *num_param_exports
);
303 void ac_init_exec_full_mask(struct ac_llvm_context
*ctx
);
305 void ac_declare_lds_as_pointer(struct ac_llvm_context
*ac
);
306 LLVMValueRef
ac_lds_load(struct ac_llvm_context
*ctx
,
307 LLVMValueRef dw_addr
);
308 void ac_lds_store(struct ac_llvm_context
*ctx
,
309 LLVMValueRef dw_addr
, LLVMValueRef value
);
311 LLVMValueRef
ac_find_lsb(struct ac_llvm_context
*ctx
,
312 LLVMTypeRef dst_type
,