1bf215546Sopenharmony_ci/**************************************************************************
2bf215546Sopenharmony_ci *
3bf215546Sopenharmony_ci * Copyright 2019 Red Hat.
4bf215546Sopenharmony_ci * All Rights Reserved.
5bf215546Sopenharmony_ci *
6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
8bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
9bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
11bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
12bf215546Sopenharmony_ci *
13bf215546Sopenharmony_ci * The above copyright notice and this permission notice shall be included
14bf215546Sopenharmony_ci * in all copies or substantial portions of the Software.
15bf215546Sopenharmony_ci *
16bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21bf215546Sopenharmony_ci * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22bf215546Sopenharmony_ci * SOFTWARE.
23bf215546Sopenharmony_ci *
24bf215546Sopenharmony_ci **************************************************************************/
25bf215546Sopenharmony_ci
26bf215546Sopenharmony_ci#ifndef LP_BLD_NIR_H
27bf215546Sopenharmony_ci#define LP_BLD_NIR_H
28bf215546Sopenharmony_ci
29bf215546Sopenharmony_ci#include "gallivm/lp_bld.h"
30bf215546Sopenharmony_ci#include "gallivm/lp_bld_limits.h"
31bf215546Sopenharmony_ci#include "lp_bld_type.h"
32bf215546Sopenharmony_ci
33bf215546Sopenharmony_ci#include "gallivm/lp_bld_tgsi.h"
34bf215546Sopenharmony_ci#include "nir.h"
35bf215546Sopenharmony_ci
36bf215546Sopenharmony_cistruct nir_shader;
37bf215546Sopenharmony_ci
38bf215546Sopenharmony_civoid lp_build_nir_soa(struct gallivm_state *gallivm,
39bf215546Sopenharmony_ci                      struct nir_shader *shader,
40bf215546Sopenharmony_ci                      const struct lp_build_tgsi_params *params,
41bf215546Sopenharmony_ci                      LLVMValueRef (*outputs)[4]);
42bf215546Sopenharmony_ci
43bf215546Sopenharmony_civoid lp_build_nir_aos(struct gallivm_state *gallivm,
44bf215546Sopenharmony_ci                      struct nir_shader *shader,
45bf215546Sopenharmony_ci                      struct lp_type type,
46bf215546Sopenharmony_ci                      const unsigned char swizzles[4],
47bf215546Sopenharmony_ci                      LLVMValueRef consts_ptr,
48bf215546Sopenharmony_ci                      const LLVMValueRef *inputs,
49bf215546Sopenharmony_ci                      LLVMValueRef *outputs,
50bf215546Sopenharmony_ci                      const struct lp_build_sampler_aos *sampler,
51bf215546Sopenharmony_ci                      const struct tgsi_shader_info *info);
52bf215546Sopenharmony_ci
53bf215546Sopenharmony_cistruct lp_build_nir_context
54bf215546Sopenharmony_ci{
55bf215546Sopenharmony_ci   struct lp_build_context base;
56bf215546Sopenharmony_ci   struct lp_build_context uint_bld;
57bf215546Sopenharmony_ci   struct lp_build_context int_bld;
58bf215546Sopenharmony_ci   struct lp_build_context uint8_bld;
59bf215546Sopenharmony_ci   struct lp_build_context int8_bld;
60bf215546Sopenharmony_ci   struct lp_build_context uint16_bld;
61bf215546Sopenharmony_ci   struct lp_build_context int16_bld;
62bf215546Sopenharmony_ci   struct lp_build_context half_bld;
63bf215546Sopenharmony_ci   struct lp_build_context dbl_bld;
64bf215546Sopenharmony_ci   struct lp_build_context uint64_bld;
65bf215546Sopenharmony_ci   struct lp_build_context int64_bld;
66bf215546Sopenharmony_ci
67bf215546Sopenharmony_ci   LLVMValueRef *ssa_defs;
68bf215546Sopenharmony_ci   struct hash_table *regs;
69bf215546Sopenharmony_ci   struct hash_table *vars;
70bf215546Sopenharmony_ci
71bf215546Sopenharmony_ci   /** Value range analysis hash table used in code generation. */
72bf215546Sopenharmony_ci   struct hash_table *range_ht;
73bf215546Sopenharmony_ci
74bf215546Sopenharmony_ci   LLVMValueRef aniso_filter_table;
75bf215546Sopenharmony_ci
76bf215546Sopenharmony_ci   nir_shader *shader;
77bf215546Sopenharmony_ci
78bf215546Sopenharmony_ci   void (*load_ubo)(struct lp_build_nir_context *bld_base,
79bf215546Sopenharmony_ci                    unsigned nc,
80bf215546Sopenharmony_ci                    unsigned bit_size,
81bf215546Sopenharmony_ci                    bool offset_is_uniform,
82bf215546Sopenharmony_ci                    LLVMValueRef index, LLVMValueRef offset, LLVMValueRef result[NIR_MAX_VEC_COMPONENTS]);
83bf215546Sopenharmony_ci
84bf215546Sopenharmony_ci   void (*load_kernel_arg)(struct lp_build_nir_context *bld_base,
85bf215546Sopenharmony_ci                           unsigned nc,
86bf215546Sopenharmony_ci                           unsigned bit_size,
87bf215546Sopenharmony_ci                           unsigned offset_bit_size,
88bf215546Sopenharmony_ci                           bool offset_is_uniform,
89bf215546Sopenharmony_ci                           LLVMValueRef offset, LLVMValueRef result[NIR_MAX_VEC_COMPONENTS]);
90bf215546Sopenharmony_ci
91bf215546Sopenharmony_ci   void (*load_global)(struct lp_build_nir_context *bld_base,
92bf215546Sopenharmony_ci                       unsigned nc, unsigned bit_size,
93bf215546Sopenharmony_ci                       unsigned offset_bit_size,
94bf215546Sopenharmony_ci                       bool offset_is_global,
95bf215546Sopenharmony_ci                       LLVMValueRef offset, LLVMValueRef result[NIR_MAX_VEC_COMPONENTS]);
96bf215546Sopenharmony_ci
97bf215546Sopenharmony_ci   void (*store_global)(struct lp_build_nir_context *bld_base,
98bf215546Sopenharmony_ci                        unsigned writemask,
99bf215546Sopenharmony_ci                        unsigned nc, unsigned bit_size,
100bf215546Sopenharmony_ci                        unsigned addr_bit_size,
101bf215546Sopenharmony_ci                        LLVMValueRef addr, LLVMValueRef dst);
102bf215546Sopenharmony_ci
103bf215546Sopenharmony_ci   void (*atomic_global)(struct lp_build_nir_context *bld_base,
104bf215546Sopenharmony_ci                         nir_intrinsic_op op,
105bf215546Sopenharmony_ci                         unsigned addr_bit_size,
106bf215546Sopenharmony_ci                         unsigned val_bit_size,
107bf215546Sopenharmony_ci                         LLVMValueRef addr,
108bf215546Sopenharmony_ci                         LLVMValueRef val, LLVMValueRef val2,
109bf215546Sopenharmony_ci                         LLVMValueRef *result);
110bf215546Sopenharmony_ci
111bf215546Sopenharmony_ci   /* for SSBO and shared memory */
112bf215546Sopenharmony_ci   void (*load_mem)(struct lp_build_nir_context *bld_base,
113bf215546Sopenharmony_ci                    unsigned nc, unsigned bit_size,
114bf215546Sopenharmony_ci                    bool index_and_offset_are_uniform,
115bf215546Sopenharmony_ci                    LLVMValueRef index, LLVMValueRef offset, LLVMValueRef result[NIR_MAX_VEC_COMPONENTS]);
116bf215546Sopenharmony_ci   void (*store_mem)(struct lp_build_nir_context *bld_base,
117bf215546Sopenharmony_ci                     unsigned writemask, unsigned nc, unsigned bit_size,
118bf215546Sopenharmony_ci                     bool index_and_offset_are_uniform,
119bf215546Sopenharmony_ci                     LLVMValueRef index, LLVMValueRef offset, LLVMValueRef dst);
120bf215546Sopenharmony_ci
121bf215546Sopenharmony_ci   void (*atomic_mem)(struct lp_build_nir_context *bld_base,
122bf215546Sopenharmony_ci                      nir_intrinsic_op op,
123bf215546Sopenharmony_ci                      unsigned bit_size,
124bf215546Sopenharmony_ci                      LLVMValueRef index, LLVMValueRef offset,
125bf215546Sopenharmony_ci                      LLVMValueRef val, LLVMValueRef val2,
126bf215546Sopenharmony_ci                      LLVMValueRef *result);
127bf215546Sopenharmony_ci
128bf215546Sopenharmony_ci   void (*barrier)(struct lp_build_nir_context *bld_base);
129bf215546Sopenharmony_ci
130bf215546Sopenharmony_ci   void (*image_op)(struct lp_build_nir_context *bld_base,
131bf215546Sopenharmony_ci                    struct lp_img_params *params);
132bf215546Sopenharmony_ci   void (*image_size)(struct lp_build_nir_context *bld_base,
133bf215546Sopenharmony_ci                      struct lp_sampler_size_query_params *params);
134bf215546Sopenharmony_ci   LLVMValueRef (*get_ssbo_size)(struct lp_build_nir_context *bld_base,
135bf215546Sopenharmony_ci                                 LLVMValueRef index);
136bf215546Sopenharmony_ci
137bf215546Sopenharmony_ci   void (*load_const)(struct lp_build_nir_context *bld_base,
138bf215546Sopenharmony_ci                      const nir_load_const_instr *instr,
139bf215546Sopenharmony_ci                      LLVMValueRef result[NIR_MAX_VEC_COMPONENTS]);
140bf215546Sopenharmony_ci   void (*load_var)(struct lp_build_nir_context *bld_base,
141bf215546Sopenharmony_ci                    nir_variable_mode deref_mode,
142bf215546Sopenharmony_ci                    unsigned num_components,
143bf215546Sopenharmony_ci                    unsigned bit_size,
144bf215546Sopenharmony_ci                    nir_variable *var,
145bf215546Sopenharmony_ci                    unsigned vertex_index,
146bf215546Sopenharmony_ci                    LLVMValueRef indir_vertex_index,
147bf215546Sopenharmony_ci                    unsigned const_index,
148bf215546Sopenharmony_ci                    LLVMValueRef indir_index,
149bf215546Sopenharmony_ci                    LLVMValueRef result[NIR_MAX_VEC_COMPONENTS]);
150bf215546Sopenharmony_ci   void (*store_var)(struct lp_build_nir_context *bld_base,
151bf215546Sopenharmony_ci                     nir_variable_mode deref_mode,
152bf215546Sopenharmony_ci                     unsigned num_components,
153bf215546Sopenharmony_ci                     unsigned bit_size,
154bf215546Sopenharmony_ci                     nir_variable *var,
155bf215546Sopenharmony_ci                     unsigned writemask,
156bf215546Sopenharmony_ci                     LLVMValueRef indir_vertex_index,
157bf215546Sopenharmony_ci                     unsigned const_index,
158bf215546Sopenharmony_ci                     LLVMValueRef indir_index,
159bf215546Sopenharmony_ci                     LLVMValueRef dst);
160bf215546Sopenharmony_ci
161bf215546Sopenharmony_ci   LLVMValueRef (*load_reg)(struct lp_build_nir_context *bld_base,
162bf215546Sopenharmony_ci                            struct lp_build_context *reg_bld,
163bf215546Sopenharmony_ci                            const nir_reg_src *reg,
164bf215546Sopenharmony_ci                            LLVMValueRef indir_src,
165bf215546Sopenharmony_ci                            LLVMValueRef reg_storage);
166bf215546Sopenharmony_ci   void (*store_reg)(struct lp_build_nir_context *bld_base,
167bf215546Sopenharmony_ci                     struct lp_build_context *reg_bld,
168bf215546Sopenharmony_ci                     const nir_reg_dest *reg,
169bf215546Sopenharmony_ci                     unsigned writemask,
170bf215546Sopenharmony_ci                     LLVMValueRef indir_src,
171bf215546Sopenharmony_ci                     LLVMValueRef reg_storage,
172bf215546Sopenharmony_ci                     LLVMValueRef dst[NIR_MAX_VEC_COMPONENTS]);
173bf215546Sopenharmony_ci
174bf215546Sopenharmony_ci   void (*load_scratch)(struct lp_build_nir_context *bld_base,
175bf215546Sopenharmony_ci                        unsigned nc, unsigned bit_size,
176bf215546Sopenharmony_ci                        LLVMValueRef offset,
177bf215546Sopenharmony_ci                        LLVMValueRef result[NIR_MAX_VEC_COMPONENTS]);
178bf215546Sopenharmony_ci   void (*store_scratch)(struct lp_build_nir_context *bld_base,
179bf215546Sopenharmony_ci                         unsigned writemask, unsigned nc,
180bf215546Sopenharmony_ci                         unsigned bit_size, LLVMValueRef offset,
181bf215546Sopenharmony_ci                         LLVMValueRef val);
182bf215546Sopenharmony_ci
183bf215546Sopenharmony_ci   void (*emit_var_decl)(struct lp_build_nir_context *bld_base,
184bf215546Sopenharmony_ci                         nir_variable *var);
185bf215546Sopenharmony_ci
186bf215546Sopenharmony_ci   void (*tex)(struct lp_build_nir_context *bld_base,
187bf215546Sopenharmony_ci               struct lp_sampler_params *params);
188bf215546Sopenharmony_ci
189bf215546Sopenharmony_ci   void (*tex_size)(struct lp_build_nir_context *bld_base,
190bf215546Sopenharmony_ci                    struct lp_sampler_size_query_params *params);
191bf215546Sopenharmony_ci
192bf215546Sopenharmony_ci   void (*sysval_intrin)(struct lp_build_nir_context *bld_base,
193bf215546Sopenharmony_ci                         nir_intrinsic_instr *instr,
194bf215546Sopenharmony_ci                         LLVMValueRef result[NIR_MAX_VEC_COMPONENTS]);
195bf215546Sopenharmony_ci   void (*discard)(struct lp_build_nir_context *bld_base,
196bf215546Sopenharmony_ci                   LLVMValueRef cond);
197bf215546Sopenharmony_ci
198bf215546Sopenharmony_ci   void (*bgnloop)(struct lp_build_nir_context *bld_base);
199bf215546Sopenharmony_ci   void (*endloop)(struct lp_build_nir_context *bld_base);
200bf215546Sopenharmony_ci   void (*if_cond)(struct lp_build_nir_context *bld_base, LLVMValueRef cond);
201bf215546Sopenharmony_ci   void (*else_stmt)(struct lp_build_nir_context *bld_base);
202bf215546Sopenharmony_ci   void (*endif_stmt)(struct lp_build_nir_context *bld_base);
203bf215546Sopenharmony_ci   void (*break_stmt)(struct lp_build_nir_context *bld_base);
204bf215546Sopenharmony_ci   void (*continue_stmt)(struct lp_build_nir_context *bld_base);
205bf215546Sopenharmony_ci
206bf215546Sopenharmony_ci   void (*emit_vertex)(struct lp_build_nir_context *bld_base, uint32_t stream_id);
207bf215546Sopenharmony_ci   void (*end_primitive)(struct lp_build_nir_context *bld_base, uint32_t stream_id);
208bf215546Sopenharmony_ci
209bf215546Sopenharmony_ci   void (*vote)(struct lp_build_nir_context *bld_base, LLVMValueRef src, nir_intrinsic_instr *instr, LLVMValueRef dst[4]);
210bf215546Sopenharmony_ci   void (*elect)(struct lp_build_nir_context *bld_base, LLVMValueRef dst[4]);
211bf215546Sopenharmony_ci   void (*reduce)(struct lp_build_nir_context *bld_base, LLVMValueRef src, nir_intrinsic_instr *instr, LLVMValueRef dst[4]);
212bf215546Sopenharmony_ci   void (*ballot)(struct lp_build_nir_context *bld_base, LLVMValueRef src, nir_intrinsic_instr *instr, LLVMValueRef dst[4]);
213bf215546Sopenharmony_ci#if LLVM_VERSION_MAJOR >= 10
214bf215546Sopenharmony_ci   void (*shuffle)(struct lp_build_nir_context *bld_base,
215bf215546Sopenharmony_ci                   LLVMValueRef src,
216bf215546Sopenharmony_ci                   LLVMValueRef index,
217bf215546Sopenharmony_ci                   nir_intrinsic_instr *instr,
218bf215546Sopenharmony_ci                   LLVMValueRef dst[4]);
219bf215546Sopenharmony_ci#endif
220bf215546Sopenharmony_ci   void (*read_invocation)(struct lp_build_nir_context *bld_base,
221bf215546Sopenharmony_ci                           LLVMValueRef src, unsigned bit_size, LLVMValueRef invoc,
222bf215546Sopenharmony_ci                           LLVMValueRef dst[4]);
223bf215546Sopenharmony_ci   void (*helper_invocation)(struct lp_build_nir_context *bld_base, LLVMValueRef *dst);
224bf215546Sopenharmony_ci
225bf215546Sopenharmony_ci   void (*interp_at)(struct lp_build_nir_context *bld_base,
226bf215546Sopenharmony_ci                     unsigned num_components,
227bf215546Sopenharmony_ci                     nir_variable *var,
228bf215546Sopenharmony_ci                     bool centroid, bool sample,
229bf215546Sopenharmony_ci                     unsigned const_index,
230bf215546Sopenharmony_ci                     LLVMValueRef indir_index,
231bf215546Sopenharmony_ci                     LLVMValueRef offsets[2], LLVMValueRef dst[4]);
232bf215546Sopenharmony_ci//   LLVMValueRef main_function
233bf215546Sopenharmony_ci};
234bf215546Sopenharmony_ci
235bf215546Sopenharmony_cistruct lp_build_nir_soa_context
236bf215546Sopenharmony_ci{
237bf215546Sopenharmony_ci   struct lp_build_nir_context bld_base;
238bf215546Sopenharmony_ci
239bf215546Sopenharmony_ci   /* Builder for scalar elements of shader's data type (float) */
240bf215546Sopenharmony_ci   struct lp_build_context elem_bld;
241bf215546Sopenharmony_ci   struct lp_build_context uint_elem_bld;
242bf215546Sopenharmony_ci
243bf215546Sopenharmony_ci   LLVMValueRef consts_ptr;
244bf215546Sopenharmony_ci   LLVMValueRef const_sizes_ptr;
245bf215546Sopenharmony_ci   LLVMValueRef consts[LP_MAX_TGSI_CONST_BUFFERS];
246bf215546Sopenharmony_ci   LLVMValueRef consts_sizes[LP_MAX_TGSI_CONST_BUFFERS];
247bf215546Sopenharmony_ci   const LLVMValueRef (*inputs)[TGSI_NUM_CHANNELS];
248bf215546Sopenharmony_ci   LLVMValueRef (*outputs)[TGSI_NUM_CHANNELS];
249bf215546Sopenharmony_ci   LLVMValueRef context_ptr;
250bf215546Sopenharmony_ci   LLVMValueRef thread_data_ptr;
251bf215546Sopenharmony_ci
252bf215546Sopenharmony_ci   LLVMValueRef ssbo_ptr;
253bf215546Sopenharmony_ci   LLVMValueRef ssbo_sizes_ptr;
254bf215546Sopenharmony_ci   LLVMValueRef ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
255bf215546Sopenharmony_ci   LLVMValueRef ssbo_sizes[LP_MAX_TGSI_SHADER_BUFFERS];
256bf215546Sopenharmony_ci
257bf215546Sopenharmony_ci   LLVMValueRef shared_ptr;
258bf215546Sopenharmony_ci   LLVMValueRef scratch_ptr;
259bf215546Sopenharmony_ci   unsigned scratch_size;
260bf215546Sopenharmony_ci
261bf215546Sopenharmony_ci   const struct lp_build_coro_suspend_info *coro;
262bf215546Sopenharmony_ci
263bf215546Sopenharmony_ci   const struct lp_build_sampler_soa *sampler;
264bf215546Sopenharmony_ci   const struct lp_build_image_soa *image;
265bf215546Sopenharmony_ci
266bf215546Sopenharmony_ci   const struct lp_build_gs_iface *gs_iface;
267bf215546Sopenharmony_ci   const struct lp_build_tcs_iface *tcs_iface;
268bf215546Sopenharmony_ci   const struct lp_build_tes_iface *tes_iface;
269bf215546Sopenharmony_ci   const struct lp_build_fs_iface *fs_iface;
270bf215546Sopenharmony_ci   LLVMValueRef emitted_prims_vec_ptr[PIPE_MAX_VERTEX_STREAMS];
271bf215546Sopenharmony_ci   LLVMValueRef total_emitted_vertices_vec_ptr[PIPE_MAX_VERTEX_STREAMS];
272bf215546Sopenharmony_ci   LLVMValueRef emitted_vertices_vec_ptr[PIPE_MAX_VERTEX_STREAMS];
273bf215546Sopenharmony_ci   LLVMValueRef max_output_vertices_vec;
274bf215546Sopenharmony_ci   struct lp_bld_tgsi_system_values system_values;
275bf215546Sopenharmony_ci
276bf215546Sopenharmony_ci   nir_variable_mode indirects;
277bf215546Sopenharmony_ci   struct lp_build_mask_context *mask;
278bf215546Sopenharmony_ci   struct lp_exec_mask exec_mask;
279bf215546Sopenharmony_ci
280bf215546Sopenharmony_ci   /* We allocate/use this array of inputs if (indirects & nir_var_shader_in) is
281bf215546Sopenharmony_ci    * set. The inputs[] array above is unused then.
282bf215546Sopenharmony_ci    */
283bf215546Sopenharmony_ci   LLVMValueRef inputs_array;
284bf215546Sopenharmony_ci
285bf215546Sopenharmony_ci   LLVMValueRef kernel_args_ptr;
286bf215546Sopenharmony_ci   unsigned gs_vertex_streams;
287bf215546Sopenharmony_ci};
288bf215546Sopenharmony_ci
289bf215546Sopenharmony_cistruct lp_build_nir_aos_context
290bf215546Sopenharmony_ci{
291bf215546Sopenharmony_ci   struct lp_build_nir_context bld_base;
292bf215546Sopenharmony_ci
293bf215546Sopenharmony_ci   /* Builder for integer masks and indices */
294bf215546Sopenharmony_ci   struct lp_build_context int_bld;
295bf215546Sopenharmony_ci
296bf215546Sopenharmony_ci   /*
297bf215546Sopenharmony_ci    * AoS swizzle used:
298bf215546Sopenharmony_ci    * - swizzles[0] = red index
299bf215546Sopenharmony_ci    * - swizzles[1] = green index
300bf215546Sopenharmony_ci    * - swizzles[2] = blue index
301bf215546Sopenharmony_ci    * - swizzles[3] = alpha index
302bf215546Sopenharmony_ci    */
303bf215546Sopenharmony_ci   unsigned char swizzles[4];
304bf215546Sopenharmony_ci   unsigned char inv_swizzles[4];
305bf215546Sopenharmony_ci
306bf215546Sopenharmony_ci   LLVMValueRef consts_ptr;
307bf215546Sopenharmony_ci   const LLVMValueRef *inputs;
308bf215546Sopenharmony_ci   LLVMValueRef *outputs;
309bf215546Sopenharmony_ci
310bf215546Sopenharmony_ci   const struct lp_build_sampler_aos *sampler;
311bf215546Sopenharmony_ci};
312bf215546Sopenharmony_ci
313bf215546Sopenharmony_ci
314bf215546Sopenharmony_cibool
315bf215546Sopenharmony_cilp_build_nir_llvm(struct lp_build_nir_context *bld_base,
316bf215546Sopenharmony_ci                  struct nir_shader *nir);
317bf215546Sopenharmony_ci
318bf215546Sopenharmony_civoid
319bf215546Sopenharmony_cilp_build_opt_nir(struct nir_shader *nir);
320bf215546Sopenharmony_ci
321bf215546Sopenharmony_ci
322bf215546Sopenharmony_cistatic inline LLVMValueRef
323bf215546Sopenharmony_cilp_nir_array_build_gather_values(LLVMBuilderRef builder,
324bf215546Sopenharmony_ci                                 LLVMValueRef * values,
325bf215546Sopenharmony_ci                                 unsigned value_count)
326bf215546Sopenharmony_ci{
327bf215546Sopenharmony_ci   LLVMTypeRef arr_type = LLVMArrayType(LLVMTypeOf(values[0]), value_count);
328bf215546Sopenharmony_ci   LLVMValueRef arr = LLVMGetUndef(arr_type);
329bf215546Sopenharmony_ci
330bf215546Sopenharmony_ci   for (unsigned i = 0; i < value_count; i++) {
331bf215546Sopenharmony_ci      arr = LLVMBuildInsertValue(builder, arr, values[i], i, "");
332bf215546Sopenharmony_ci   }
333bf215546Sopenharmony_ci   return arr;
334bf215546Sopenharmony_ci}
335bf215546Sopenharmony_ci
336bf215546Sopenharmony_ci
337bf215546Sopenharmony_cistatic inline struct lp_build_context *
338bf215546Sopenharmony_ciget_flt_bld(struct lp_build_nir_context *bld_base,
339bf215546Sopenharmony_ci            unsigned op_bit_size)
340bf215546Sopenharmony_ci{
341bf215546Sopenharmony_ci   switch (op_bit_size) {
342bf215546Sopenharmony_ci   case 64:
343bf215546Sopenharmony_ci      return &bld_base->dbl_bld;
344bf215546Sopenharmony_ci   case 16:
345bf215546Sopenharmony_ci      return &bld_base->half_bld;
346bf215546Sopenharmony_ci   default:
347bf215546Sopenharmony_ci   case 32:
348bf215546Sopenharmony_ci      return &bld_base->base;
349bf215546Sopenharmony_ci   }
350bf215546Sopenharmony_ci}
351bf215546Sopenharmony_ci
352bf215546Sopenharmony_ci
353bf215546Sopenharmony_cistatic inline struct lp_build_context *
354bf215546Sopenharmony_ciget_int_bld(struct lp_build_nir_context *bld_base,
355bf215546Sopenharmony_ci            bool is_unsigned,
356bf215546Sopenharmony_ci            unsigned op_bit_size)
357bf215546Sopenharmony_ci{
358bf215546Sopenharmony_ci   if (is_unsigned) {
359bf215546Sopenharmony_ci      switch (op_bit_size) {
360bf215546Sopenharmony_ci      case 64:
361bf215546Sopenharmony_ci         return &bld_base->uint64_bld;
362bf215546Sopenharmony_ci      case 32:
363bf215546Sopenharmony_ci      default:
364bf215546Sopenharmony_ci         return &bld_base->uint_bld;
365bf215546Sopenharmony_ci      case 16:
366bf215546Sopenharmony_ci         return &bld_base->uint16_bld;
367bf215546Sopenharmony_ci      case 8:
368bf215546Sopenharmony_ci         return &bld_base->uint8_bld;
369bf215546Sopenharmony_ci      }
370bf215546Sopenharmony_ci   } else {
371bf215546Sopenharmony_ci      switch (op_bit_size) {
372bf215546Sopenharmony_ci      case 64:
373bf215546Sopenharmony_ci         return &bld_base->int64_bld;
374bf215546Sopenharmony_ci      default:
375bf215546Sopenharmony_ci      case 32:
376bf215546Sopenharmony_ci         return &bld_base->int_bld;
377bf215546Sopenharmony_ci      case 16:
378bf215546Sopenharmony_ci         return &bld_base->int16_bld;
379bf215546Sopenharmony_ci      case 8:
380bf215546Sopenharmony_ci         return &bld_base->int8_bld;
381bf215546Sopenharmony_ci      }
382bf215546Sopenharmony_ci   }
383bf215546Sopenharmony_ci}
384bf215546Sopenharmony_ci
385bf215546Sopenharmony_ci
386bf215546Sopenharmony_cistatic inline struct lp_build_nir_aos_context *
387bf215546Sopenharmony_cilp_nir_aos_context(struct lp_build_nir_context *bld_base)
388bf215546Sopenharmony_ci{
389bf215546Sopenharmony_ci   return (struct lp_build_nir_aos_context *) bld_base;
390bf215546Sopenharmony_ci}
391bf215546Sopenharmony_ci
392bf215546Sopenharmony_ci
393bf215546Sopenharmony_ciLLVMValueRef
394bf215546Sopenharmony_cilp_nir_aos_conv_const(struct gallivm_state *gallivm,
395bf215546Sopenharmony_ci                      LLVMValueRef constval, int nc);
396bf215546Sopenharmony_ci
397bf215546Sopenharmony_ci#endif
398