0ff04e4c703599c7b685aecbd7e2995818865a13
[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 i32;
44 LLVMTypeRef f32;
45 LLVMTypeRef v4i32;
46 LLVMTypeRef v4f32;
47 LLVMTypeRef v16i8;
48
49 unsigned range_md_kind;
50 unsigned invariant_load_md_kind;
51 unsigned uniform_md_kind;
52 unsigned fpmath_md_kind;
53 LLVMValueRef fpmath_md_2p5_ulp;
54 LLVMValueRef empty_md;
55 };
56
57 void
58 ac_llvm_context_init(struct ac_llvm_context *ctx, LLVMContextRef context);
59
60 LLVMValueRef
61 ac_emit_llvm_intrinsic(struct ac_llvm_context *ctx, const char *name,
62 LLVMTypeRef return_type, LLVMValueRef *params,
63 unsigned param_count, unsigned attrib_mask);
64
65 LLVMValueRef
66 ac_build_gather_values_extended(struct ac_llvm_context *ctx,
67 LLVMValueRef *values,
68 unsigned value_count,
69 unsigned value_stride,
70 bool load);
71 LLVMValueRef
72 ac_build_gather_values(struct ac_llvm_context *ctx,
73 LLVMValueRef *values,
74 unsigned value_count);
75
76 LLVMValueRef
77 ac_emit_fdiv(struct ac_llvm_context *ctx,
78 LLVMValueRef num,
79 LLVMValueRef den);
80
81 void
82 ac_prepare_cube_coords(struct ac_llvm_context *ctx,
83 bool is_deriv, bool is_array,
84 LLVMValueRef *coords_arg,
85 LLVMValueRef *derivs_arg);
86
87
88 LLVMValueRef
89 ac_build_fs_interp(struct ac_llvm_context *ctx,
90 LLVMValueRef llvm_chan,
91 LLVMValueRef attr_number,
92 LLVMValueRef params,
93 LLVMValueRef i,
94 LLVMValueRef j);
95
96 LLVMValueRef
97 ac_build_fs_interp_mov(struct ac_llvm_context *ctx,
98 LLVMValueRef parameter,
99 LLVMValueRef llvm_chan,
100 LLVMValueRef attr_number,
101 LLVMValueRef params);
102
103 LLVMValueRef
104 ac_build_gep0(struct ac_llvm_context *ctx,
105 LLVMValueRef base_ptr,
106 LLVMValueRef index);
107
108 void
109 ac_build_indexed_store(struct ac_llvm_context *ctx,
110 LLVMValueRef base_ptr, LLVMValueRef index,
111 LLVMValueRef value);
112
113 LLVMValueRef
114 ac_build_indexed_load(struct ac_llvm_context *ctx,
115 LLVMValueRef base_ptr, LLVMValueRef index,
116 bool uniform);
117
118 LLVMValueRef
119 ac_build_indexed_load_const(struct ac_llvm_context *ctx,
120 LLVMValueRef base_ptr, LLVMValueRef index);
121
122 void
123 ac_build_tbuffer_store_dwords(struct ac_llvm_context *ctx,
124 LLVMValueRef rsrc,
125 LLVMValueRef vdata,
126 unsigned num_channels,
127 LLVMValueRef vaddr,
128 LLVMValueRef soffset,
129 unsigned inst_offset);
130
131 void
132 ac_build_tbuffer_store(struct ac_llvm_context *ctx,
133 LLVMValueRef rsrc,
134 LLVMValueRef vdata,
135 unsigned num_channels,
136 LLVMValueRef vaddr,
137 LLVMValueRef soffset,
138 unsigned inst_offset,
139 unsigned dfmt,
140 unsigned nfmt,
141 unsigned offen,
142 unsigned idxen,
143 unsigned glc,
144 unsigned slc,
145 unsigned tfe);
146
147 LLVMValueRef
148 ac_build_buffer_load(struct ac_llvm_context *ctx,
149 LLVMValueRef rsrc,
150 int num_channels,
151 LLVMValueRef vindex,
152 LLVMValueRef voffset,
153 LLVMValueRef soffset,
154 unsigned inst_offset,
155 unsigned glc,
156 unsigned slc);
157
158 LLVMValueRef
159 ac_get_thread_id(struct ac_llvm_context *ctx);
160
161 #define AC_TID_MASK_TOP_LEFT 0xfffffffc
162 #define AC_TID_MASK_TOP 0xfffffffd
163 #define AC_TID_MASK_LEFT 0xfffffffe
164
165 LLVMValueRef
166 ac_emit_ddxy(struct ac_llvm_context *ctx,
167 bool has_ds_bpermute,
168 uint32_t mask,
169 int idx,
170 LLVMValueRef lds,
171 LLVMValueRef val);
172
173 #define AC_SENDMSG_GS 2
174 #define AC_SENDMSG_GS_DONE 3
175
176 #define AC_SENDMSG_GS_OP_NOP (0 << 4)
177 #define AC_SENDMSG_GS_OP_CUT (1 << 4)
178 #define AC_SENDMSG_GS_OP_EMIT (2 << 4)
179 #define AC_SENDMSG_GS_OP_EMIT_CUT (3 << 4)
180
181 void ac_emit_sendmsg(struct ac_llvm_context *ctx,
182 uint32_t msg,
183 LLVMValueRef wave_id);
184
185 LLVMValueRef ac_emit_imsb(struct ac_llvm_context *ctx,
186 LLVMValueRef arg,
187 LLVMTypeRef dst_type);
188
189 #ifdef __cplusplus
190 }
191 #endif
192
193 #endif