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_CONST_ADDR_SPACE
= 2, /* CONST is the only address space that selects SMEM loads */
39 AC_LOCAL_ADDR_SPACE
= 3,
42 struct ac_llvm_context
{
43 LLVMContextRef context
;
45 LLVMBuilderRef builder
;
74 unsigned range_md_kind
;
75 unsigned invariant_load_md_kind
;
76 unsigned uniform_md_kind
;
77 unsigned fpmath_md_kind
;
78 LLVMValueRef fpmath_md_2p5_ulp
;
79 LLVMValueRef empty_md
;
81 enum chip_class chip_class
;
82 enum radeon_family family
;
88 ac_llvm_context_init(struct ac_llvm_context
*ctx
, LLVMContextRef context
,
89 enum chip_class chip_class
, enum radeon_family family
);
92 ac_get_llvm_num_components(LLVMValueRef value
);
95 ac_llvm_extract_elem(struct ac_llvm_context
*ac
,
99 unsigned ac_get_type_size(LLVMTypeRef type
);
101 LLVMTypeRef
ac_to_integer_type(struct ac_llvm_context
*ctx
, LLVMTypeRef t
);
102 LLVMValueRef
ac_to_integer(struct ac_llvm_context
*ctx
, LLVMValueRef v
);
103 LLVMTypeRef
ac_to_float_type(struct ac_llvm_context
*ctx
, LLVMTypeRef t
);
104 LLVMValueRef
ac_to_float(struct ac_llvm_context
*ctx
, LLVMValueRef v
);
107 ac_build_intrinsic(struct ac_llvm_context
*ctx
, const char *name
,
108 LLVMTypeRef return_type
, LLVMValueRef
*params
,
109 unsigned param_count
, unsigned attrib_mask
);
111 void ac_build_type_name_for_intr(LLVMTypeRef type
, char *buf
, unsigned bufsize
);
114 ac_build_phi(struct ac_llvm_context
*ctx
, LLVMTypeRef type
,
115 unsigned count_incoming
, LLVMValueRef
*values
,
116 LLVMBasicBlockRef
*blocks
);
118 void ac_build_optimization_barrier(struct ac_llvm_context
*ctx
,
119 LLVMValueRef
*pvgpr
);
121 LLVMValueRef
ac_build_ballot(struct ac_llvm_context
*ctx
, LLVMValueRef value
);
123 LLVMValueRef
ac_build_vote_all(struct ac_llvm_context
*ctx
, LLVMValueRef value
);
125 LLVMValueRef
ac_build_vote_any(struct ac_llvm_context
*ctx
, LLVMValueRef value
);
127 LLVMValueRef
ac_build_vote_eq(struct ac_llvm_context
*ctx
, LLVMValueRef value
);
130 ac_build_varying_gather_values(struct ac_llvm_context
*ctx
, LLVMValueRef
*values
,
131 unsigned value_count
, unsigned component
);
134 ac_build_gather_values_extended(struct ac_llvm_context
*ctx
,
135 LLVMValueRef
*values
,
136 unsigned value_count
,
137 unsigned value_stride
,
141 ac_build_gather_values(struct ac_llvm_context
*ctx
,
142 LLVMValueRef
*values
,
143 unsigned value_count
);
146 ac_build_fdiv(struct ac_llvm_context
*ctx
,
151 ac_prepare_cube_coords(struct ac_llvm_context
*ctx
,
152 bool is_deriv
, bool is_array
, bool is_lod
,
153 LLVMValueRef
*coords_arg
,
154 LLVMValueRef
*derivs_arg
);
158 ac_build_fs_interp(struct ac_llvm_context
*ctx
,
159 LLVMValueRef llvm_chan
,
160 LLVMValueRef attr_number
,
166 ac_build_fs_interp_mov(struct ac_llvm_context
*ctx
,
167 LLVMValueRef parameter
,
168 LLVMValueRef llvm_chan
,
169 LLVMValueRef attr_number
,
170 LLVMValueRef params
);
173 ac_build_gep0(struct ac_llvm_context
*ctx
,
174 LLVMValueRef base_ptr
,
178 ac_build_indexed_store(struct ac_llvm_context
*ctx
,
179 LLVMValueRef base_ptr
, LLVMValueRef index
,
182 LLVMValueRef
ac_build_load(struct ac_llvm_context
*ctx
, LLVMValueRef base_ptr
,
184 LLVMValueRef
ac_build_load_invariant(struct ac_llvm_context
*ctx
,
185 LLVMValueRef base_ptr
, LLVMValueRef index
);
186 LLVMValueRef
ac_build_load_to_sgpr(struct ac_llvm_context
*ctx
,
187 LLVMValueRef base_ptr
, LLVMValueRef index
);
190 ac_build_buffer_store_dword(struct ac_llvm_context
*ctx
,
193 unsigned num_channels
,
194 LLVMValueRef voffset
,
195 LLVMValueRef soffset
,
196 unsigned inst_offset
,
199 bool writeonly_memory
,
200 bool swizzle_enable_hint
);
202 ac_build_buffer_load(struct ac_llvm_context
*ctx
,
206 LLVMValueRef voffset
,
207 LLVMValueRef soffset
,
208 unsigned inst_offset
,
214 LLVMValueRef
ac_build_buffer_load_format(struct ac_llvm_context
*ctx
,
217 LLVMValueRef voffset
,
218 unsigned num_channels
,
222 ac_get_thread_id(struct ac_llvm_context
*ctx
);
224 #define AC_TID_MASK_TOP_LEFT 0xfffffffc
225 #define AC_TID_MASK_TOP 0xfffffffd
226 #define AC_TID_MASK_LEFT 0xfffffffe
229 ac_build_ddxy(struct ac_llvm_context
*ctx
,
234 #define AC_SENDMSG_GS 2
235 #define AC_SENDMSG_GS_DONE 3
237 #define AC_SENDMSG_GS_OP_NOP (0 << 4)
238 #define AC_SENDMSG_GS_OP_CUT (1 << 4)
239 #define AC_SENDMSG_GS_OP_EMIT (2 << 4)
240 #define AC_SENDMSG_GS_OP_EMIT_CUT (3 << 4)
242 void ac_build_sendmsg(struct ac_llvm_context
*ctx
,
244 LLVMValueRef wave_id
);
246 LLVMValueRef
ac_build_imsb(struct ac_llvm_context
*ctx
,
248 LLVMTypeRef dst_type
);
250 LLVMValueRef
ac_build_umsb(struct ac_llvm_context
*ctx
,
252 LLVMTypeRef dst_type
);
253 LLVMValueRef
ac_build_fmin(struct ac_llvm_context
*ctx
, LLVMValueRef a
,
255 LLVMValueRef
ac_build_fmax(struct ac_llvm_context
*ctx
, LLVMValueRef a
,
257 LLVMValueRef
ac_build_umin(struct ac_llvm_context
*ctx
, LLVMValueRef a
, LLVMValueRef b
);
258 LLVMValueRef
ac_build_clamp(struct ac_llvm_context
*ctx
, LLVMValueRef value
);
260 struct ac_export_args
{
263 unsigned enabled_channels
;
269 void ac_build_export(struct ac_llvm_context
*ctx
, struct ac_export_args
*a
);
271 enum ac_image_opcode
{
277 ac_image_get_resinfo
,
280 struct ac_image_args
{
281 enum ac_image_opcode opcode
;
289 LLVMValueRef resource
;
290 LLVMValueRef sampler
;
297 LLVMValueRef
ac_build_image_opcode(struct ac_llvm_context
*ctx
,
298 struct ac_image_args
*a
);
299 LLVMValueRef
ac_build_cvt_pkrtz_f16(struct ac_llvm_context
*ctx
,
300 LLVMValueRef args
[2]);
301 LLVMValueRef
ac_build_wqm_vote(struct ac_llvm_context
*ctx
, LLVMValueRef i1
);
302 void ac_build_kill_if_false(struct ac_llvm_context
*ctx
, LLVMValueRef i1
);
303 LLVMValueRef
ac_build_bfe(struct ac_llvm_context
*ctx
, LLVMValueRef input
,
304 LLVMValueRef offset
, LLVMValueRef width
,
307 void ac_build_waitcnt(struct ac_llvm_context
*ctx
, unsigned simm16
);
309 void ac_get_image_intr_name(const char *base_name
,
310 LLVMTypeRef data_type
,
311 LLVMTypeRef coords_type
,
312 LLVMTypeRef rsrc_type
,
313 char *out_name
, unsigned out_len
);
315 void ac_optimize_vs_outputs(struct ac_llvm_context
*ac
,
316 LLVMValueRef main_fn
,
317 uint8_t *vs_output_param_offset
,
318 uint32_t num_outputs
,
319 uint8_t *num_param_exports
);
320 void ac_init_exec_full_mask(struct ac_llvm_context
*ctx
);
322 void ac_declare_lds_as_pointer(struct ac_llvm_context
*ac
);
323 LLVMValueRef
ac_lds_load(struct ac_llvm_context
*ctx
,
324 LLVMValueRef dw_addr
);
325 void ac_lds_store(struct ac_llvm_context
*ctx
,
326 LLVMValueRef dw_addr
, LLVMValueRef value
);
328 LLVMValueRef
ac_find_lsb(struct ac_llvm_context
*ctx
,
329 LLVMTypeRef dst_type
,
332 LLVMTypeRef
ac_array_in_const_addr_space(LLVMTypeRef elem_type
);