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"
37 struct ac_llvm_context
{
38 LLVMContextRef context
;
40 LLVMBuilderRef builder
;
60 unsigned range_md_kind
;
61 unsigned invariant_load_md_kind
;
62 unsigned uniform_md_kind
;
63 unsigned fpmath_md_kind
;
64 LLVMValueRef fpmath_md_2p5_ulp
;
65 LLVMValueRef empty_md
;
67 enum chip_class chip_class
;
71 ac_llvm_context_init(struct ac_llvm_context
*ctx
, LLVMContextRef context
,
72 enum chip_class chip_class
);
74 unsigned ac_get_type_size(LLVMTypeRef type
);
76 LLVMTypeRef
ac_to_integer_type(struct ac_llvm_context
*ctx
, LLVMTypeRef t
);
77 LLVMValueRef
ac_to_integer(struct ac_llvm_context
*ctx
, LLVMValueRef v
);
78 LLVMTypeRef
ac_to_float_type(struct ac_llvm_context
*ctx
, LLVMTypeRef t
);
79 LLVMValueRef
ac_to_float(struct ac_llvm_context
*ctx
, LLVMValueRef v
);
82 ac_build_intrinsic(struct ac_llvm_context
*ctx
, const char *name
,
83 LLVMTypeRef return_type
, LLVMValueRef
*params
,
84 unsigned param_count
, unsigned attrib_mask
);
86 void ac_build_type_name_for_intr(LLVMTypeRef type
, char *buf
, unsigned bufsize
);
89 ac_build_phi(struct ac_llvm_context
*ctx
, LLVMTypeRef type
,
90 unsigned count_incoming
, LLVMValueRef
*values
,
91 LLVMBasicBlockRef
*blocks
);
93 void ac_build_optimization_barrier(struct ac_llvm_context
*ctx
,
96 LLVMValueRef
ac_build_ballot(struct ac_llvm_context
*ctx
, LLVMValueRef value
);
98 LLVMValueRef
ac_build_vote_all(struct ac_llvm_context
*ctx
, LLVMValueRef value
);
100 LLVMValueRef
ac_build_vote_any(struct ac_llvm_context
*ctx
, LLVMValueRef value
);
102 LLVMValueRef
ac_build_vote_eq(struct ac_llvm_context
*ctx
, LLVMValueRef value
);
105 ac_build_gather_values_extended(struct ac_llvm_context
*ctx
,
106 LLVMValueRef
*values
,
107 unsigned value_count
,
108 unsigned value_stride
,
112 ac_build_gather_values(struct ac_llvm_context
*ctx
,
113 LLVMValueRef
*values
,
114 unsigned value_count
);
117 ac_build_fdiv(struct ac_llvm_context
*ctx
,
122 ac_prepare_cube_coords(struct ac_llvm_context
*ctx
,
123 bool is_deriv
, bool is_array
, bool is_lod
,
124 LLVMValueRef
*coords_arg
,
125 LLVMValueRef
*derivs_arg
);
129 ac_build_fs_interp(struct ac_llvm_context
*ctx
,
130 LLVMValueRef llvm_chan
,
131 LLVMValueRef attr_number
,
137 ac_build_fs_interp_mov(struct ac_llvm_context
*ctx
,
138 LLVMValueRef parameter
,
139 LLVMValueRef llvm_chan
,
140 LLVMValueRef attr_number
,
141 LLVMValueRef params
);
144 ac_build_gep0(struct ac_llvm_context
*ctx
,
145 LLVMValueRef base_ptr
,
149 ac_build_indexed_store(struct ac_llvm_context
*ctx
,
150 LLVMValueRef base_ptr
, LLVMValueRef index
,
153 LLVMValueRef
ac_build_load(struct ac_llvm_context
*ctx
, LLVMValueRef base_ptr
,
155 LLVMValueRef
ac_build_load_invariant(struct ac_llvm_context
*ctx
,
156 LLVMValueRef base_ptr
, LLVMValueRef index
);
157 LLVMValueRef
ac_build_load_to_sgpr(struct ac_llvm_context
*ctx
,
158 LLVMValueRef base_ptr
, LLVMValueRef index
);
161 ac_build_buffer_store_dword(struct ac_llvm_context
*ctx
,
164 unsigned num_channels
,
165 LLVMValueRef voffset
,
166 LLVMValueRef soffset
,
167 unsigned inst_offset
,
170 bool writeonly_memory
,
171 bool swizzle_enable_hint
);
173 ac_build_buffer_load(struct ac_llvm_context
*ctx
,
177 LLVMValueRef voffset
,
178 LLVMValueRef soffset
,
179 unsigned inst_offset
,
185 LLVMValueRef
ac_build_buffer_load_format(struct ac_llvm_context
*ctx
,
188 LLVMValueRef voffset
,
192 ac_get_thread_id(struct ac_llvm_context
*ctx
);
194 #define AC_TID_MASK_TOP_LEFT 0xfffffffc
195 #define AC_TID_MASK_TOP 0xfffffffd
196 #define AC_TID_MASK_LEFT 0xfffffffe
199 ac_build_ddxy(struct ac_llvm_context
*ctx
,
204 #define AC_SENDMSG_GS 2
205 #define AC_SENDMSG_GS_DONE 3
207 #define AC_SENDMSG_GS_OP_NOP (0 << 4)
208 #define AC_SENDMSG_GS_OP_CUT (1 << 4)
209 #define AC_SENDMSG_GS_OP_EMIT (2 << 4)
210 #define AC_SENDMSG_GS_OP_EMIT_CUT (3 << 4)
212 void ac_build_sendmsg(struct ac_llvm_context
*ctx
,
214 LLVMValueRef wave_id
);
216 LLVMValueRef
ac_build_imsb(struct ac_llvm_context
*ctx
,
218 LLVMTypeRef dst_type
);
220 LLVMValueRef
ac_build_umsb(struct ac_llvm_context
*ctx
,
222 LLVMTypeRef dst_type
);
224 LLVMValueRef
ac_build_umin(struct ac_llvm_context
*ctx
, LLVMValueRef a
, LLVMValueRef b
);
225 LLVMValueRef
ac_build_clamp(struct ac_llvm_context
*ctx
, LLVMValueRef value
);
227 struct ac_export_args
{
230 unsigned enabled_channels
;
236 void ac_build_export(struct ac_llvm_context
*ctx
, struct ac_export_args
*a
);
238 enum ac_image_opcode
{
244 ac_image_get_resinfo
,
247 struct ac_image_args
{
248 enum ac_image_opcode opcode
;
256 LLVMValueRef resource
;
257 LLVMValueRef sampler
;
264 LLVMValueRef
ac_build_image_opcode(struct ac_llvm_context
*ctx
,
265 struct ac_image_args
*a
);
266 LLVMValueRef
ac_build_cvt_pkrtz_f16(struct ac_llvm_context
*ctx
,
267 LLVMValueRef args
[2]);
268 void ac_build_kill(struct ac_llvm_context
*ctx
, LLVMValueRef value
);
269 LLVMValueRef
ac_build_bfe(struct ac_llvm_context
*ctx
, LLVMValueRef input
,
270 LLVMValueRef offset
, LLVMValueRef width
,
273 void ac_get_image_intr_name(const char *base_name
,
274 LLVMTypeRef data_type
,
275 LLVMTypeRef coords_type
,
276 LLVMTypeRef rsrc_type
,
277 char *out_name
, unsigned out_len
);
279 void ac_optimize_vs_outputs(struct ac_llvm_context
*ac
,
280 LLVMValueRef main_fn
,
281 uint8_t *vs_output_param_offset
,
282 uint32_t num_outputs
,
283 uint8_t *num_param_exports
);