nir: Create function parameters in function_impl_create
[mesa.git] / src / compiler / nir / nir.h
1 /*
2 * Copyright © 2014 Connor Abbott
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Connor Abbott (cwabbott0@gmail.com)
25 *
26 */
27
28 #pragma once
29
30 #include "util/hash_table.h"
31 #include "compiler/glsl/list.h"
32 #include "GL/gl.h" /* GLenum */
33 #include "util/list.h"
34 #include "util/ralloc.h"
35 #include "util/set.h"
36 #include "util/bitset.h"
37 #include "compiler/nir_types.h"
38 #include "compiler/shader_enums.h"
39 #include <stdio.h>
40
41 #include "nir_opcodes.h"
42
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46
47 struct gl_program;
48 struct gl_shader_program;
49
50 #define NIR_FALSE 0u
51 #define NIR_TRUE (~0u)
52
53 /** Defines a cast function
54 *
55 * This macro defines a cast function from in_type to out_type where
56 * out_type is some structure type that contains a field of type out_type.
57 *
58 * Note that you have to be a bit careful as the generated cast function
59 * destroys constness.
60 */
61 #define NIR_DEFINE_CAST(name, in_type, out_type, field) \
62 static inline out_type * \
63 name(const in_type *parent) \
64 { \
65 return exec_node_data(out_type, parent, field); \
66 }
67
68 struct nir_function;
69 struct nir_shader;
70 struct nir_instr;
71
72
73 /**
74 * Description of built-in state associated with a uniform
75 *
76 * \sa nir_variable::state_slots
77 */
78 typedef struct {
79 int tokens[5];
80 int swizzle;
81 } nir_state_slot;
82
83 typedef enum {
84 nir_var_all = -1,
85 nir_var_shader_in,
86 nir_var_shader_out,
87 nir_var_global,
88 nir_var_local,
89 nir_var_uniform,
90 nir_var_shader_storage,
91 nir_var_system_value,
92 nir_var_param,
93 } nir_variable_mode;
94
95 /**
96 * Data stored in an nir_constant
97 */
98 union nir_constant_data {
99 unsigned u[16];
100 int i[16];
101 float f[16];
102 bool b[16];
103 };
104
105 typedef struct nir_constant {
106 /**
107 * Value of the constant.
108 *
109 * The field used to back the values supplied by the constant is determined
110 * by the type associated with the \c nir_variable. Constants may be
111 * scalars, vectors, or matrices.
112 */
113 union nir_constant_data value;
114
115 /* we could get this from the var->type but makes clone *much* easier to
116 * not have to care about the type.
117 */
118 unsigned num_elements;
119
120 /* Array elements / Structure Fields */
121 struct nir_constant **elements;
122 } nir_constant;
123
124 /**
125 * \brief Layout qualifiers for gl_FragDepth.
126 *
127 * The AMD/ARB_conservative_depth extensions allow gl_FragDepth to be redeclared
128 * with a layout qualifier.
129 */
130 typedef enum {
131 nir_depth_layout_none, /**< No depth layout is specified. */
132 nir_depth_layout_any,
133 nir_depth_layout_greater,
134 nir_depth_layout_less,
135 nir_depth_layout_unchanged
136 } nir_depth_layout;
137
138 /**
139 * Either a uniform, global variable, shader input, or shader output. Based on
140 * ir_variable - it should be easy to translate between the two.
141 */
142
143 typedef struct nir_variable {
144 struct exec_node node;
145
146 /**
147 * Declared type of the variable
148 */
149 const struct glsl_type *type;
150
151 /**
152 * Declared name of the variable
153 */
154 char *name;
155
156 struct nir_variable_data {
157
158 /**
159 * Is the variable read-only?
160 *
161 * This is set for variables declared as \c const, shader inputs,
162 * and uniforms.
163 */
164 unsigned read_only:1;
165 unsigned centroid:1;
166 unsigned sample:1;
167 unsigned patch:1;
168 unsigned invariant:1;
169
170 /**
171 * Storage class of the variable.
172 *
173 * \sa nir_variable_mode
174 */
175 nir_variable_mode mode:4;
176
177 /**
178 * Interpolation mode for shader inputs / outputs
179 *
180 * \sa glsl_interp_qualifier
181 */
182 unsigned interpolation:2;
183
184 /**
185 * \name ARB_fragment_coord_conventions
186 * @{
187 */
188 unsigned origin_upper_left:1;
189 unsigned pixel_center_integer:1;
190 /*@}*/
191
192 /**
193 * Was the location explicitly set in the shader?
194 *
195 * If the location is explicitly set in the shader, it \b cannot be changed
196 * by the linker or by the API (e.g., calls to \c glBindAttribLocation have
197 * no effect).
198 */
199 unsigned explicit_location:1;
200 unsigned explicit_index:1;
201
202 /**
203 * Was an initial binding explicitly set in the shader?
204 *
205 * If so, constant_initializer contains an integer nir_constant
206 * representing the initial binding point.
207 */
208 unsigned explicit_binding:1;
209
210 /**
211 * Does this variable have an initializer?
212 *
213 * This is used by the linker to cross-validiate initializers of global
214 * variables.
215 */
216 unsigned has_initializer:1;
217
218 /**
219 * If non-zero, then this variable may be packed along with other variables
220 * into a single varying slot, so this offset should be applied when
221 * accessing components. For example, an offset of 1 means that the x
222 * component of this variable is actually stored in component y of the
223 * location specified by \c location.
224 */
225 unsigned location_frac:2;
226
227 /**
228 * \brief Layout qualifier for gl_FragDepth.
229 *
230 * This is not equal to \c ir_depth_layout_none if and only if this
231 * variable is \c gl_FragDepth and a layout qualifier is specified.
232 */
233 nir_depth_layout depth_layout;
234
235 /**
236 * Storage location of the base of this variable
237 *
238 * The precise meaning of this field depends on the nature of the variable.
239 *
240 * - Vertex shader input: one of the values from \c gl_vert_attrib.
241 * - Vertex shader output: one of the values from \c gl_varying_slot.
242 * - Geometry shader input: one of the values from \c gl_varying_slot.
243 * - Geometry shader output: one of the values from \c gl_varying_slot.
244 * - Fragment shader input: one of the values from \c gl_varying_slot.
245 * - Fragment shader output: one of the values from \c gl_frag_result.
246 * - Uniforms: Per-stage uniform slot number for default uniform block.
247 * - Uniforms: Index within the uniform block definition for UBO members.
248 * - Non-UBO Uniforms: uniform slot number.
249 * - Other: This field is not currently used.
250 *
251 * If the variable is a uniform, shader input, or shader output, and the
252 * slot has not been assigned, the value will be -1.
253 */
254 int location;
255
256 /**
257 * The actual location of the variable in the IR. Only valid for inputs
258 * and outputs.
259 */
260 unsigned int driver_location;
261
262 /**
263 * output index for dual source blending.
264 */
265 int index;
266
267 /**
268 * Initial binding point for a sampler or UBO.
269 *
270 * For array types, this represents the binding point for the first element.
271 */
272 int binding;
273
274 /**
275 * Location an atomic counter is stored at.
276 */
277 unsigned offset;
278
279 /**
280 * ARB_shader_image_load_store qualifiers.
281 */
282 struct {
283 bool read_only; /**< "readonly" qualifier. */
284 bool write_only; /**< "writeonly" qualifier. */
285 bool coherent;
286 bool _volatile;
287 bool restrict_flag;
288
289 /** Image internal format if specified explicitly, otherwise GL_NONE. */
290 GLenum format;
291 } image;
292
293 /**
294 * Highest element accessed with a constant expression array index
295 *
296 * Not used for non-array variables.
297 */
298 unsigned max_array_access;
299
300 } data;
301
302 /**
303 * Built-in state that backs this uniform
304 *
305 * Once set at variable creation, \c state_slots must remain invariant.
306 * This is because, ideally, this array would be shared by all clones of
307 * this variable in the IR tree. In other words, we'd really like for it
308 * to be a fly-weight.
309 *
310 * If the variable is not a uniform, \c num_state_slots will be zero and
311 * \c state_slots will be \c NULL.
312 */
313 /*@{*/
314 unsigned num_state_slots; /**< Number of state slots used */
315 nir_state_slot *state_slots; /**< State descriptors. */
316 /*@}*/
317
318 /**
319 * Constant expression assigned in the initializer of the variable
320 */
321 nir_constant *constant_initializer;
322
323 /**
324 * For variables that are in an interface block or are an instance of an
325 * interface block, this is the \c GLSL_TYPE_INTERFACE type for that block.
326 *
327 * \sa ir_variable::location
328 */
329 const struct glsl_type *interface_type;
330 } nir_variable;
331
332 #define nir_foreach_variable(var, var_list) \
333 foreach_list_typed(nir_variable, var, node, var_list)
334
335 static inline bool
336 nir_variable_is_global(const nir_variable *var)
337 {
338 return var->data.mode != nir_var_local && var->data.mode != nir_var_param;
339 }
340
341 typedef struct nir_register {
342 struct exec_node node;
343
344 unsigned num_components; /** < number of vector components */
345 unsigned num_array_elems; /** < size of array (0 for no array) */
346
347 /** generic register index. */
348 unsigned index;
349
350 /** only for debug purposes, can be NULL */
351 const char *name;
352
353 /** whether this register is local (per-function) or global (per-shader) */
354 bool is_global;
355
356 /**
357 * If this flag is set to true, then accessing channels >= num_components
358 * is well-defined, and simply spills over to the next array element. This
359 * is useful for backends that can do per-component accessing, in
360 * particular scalar backends. By setting this flag and making
361 * num_components equal to 1, structures can be packed tightly into
362 * registers and then registers can be accessed per-component to get to
363 * each structure member, even if it crosses vec4 boundaries.
364 */
365 bool is_packed;
366
367 /** set of nir_src's where this register is used (read from) */
368 struct list_head uses;
369
370 /** set of nir_dest's where this register is defined (written to) */
371 struct list_head defs;
372
373 /** set of nir_if's where this register is used as a condition */
374 struct list_head if_uses;
375 } nir_register;
376
377 typedef enum {
378 nir_instr_type_alu,
379 nir_instr_type_call,
380 nir_instr_type_tex,
381 nir_instr_type_intrinsic,
382 nir_instr_type_load_const,
383 nir_instr_type_jump,
384 nir_instr_type_ssa_undef,
385 nir_instr_type_phi,
386 nir_instr_type_parallel_copy,
387 } nir_instr_type;
388
389 typedef struct nir_instr {
390 struct exec_node node;
391 nir_instr_type type;
392 struct nir_block *block;
393
394 /** generic instruction index. */
395 unsigned index;
396
397 /* A temporary for optimization and analysis passes to use for storing
398 * flags. For instance, DCE uses this to store the "dead/live" info.
399 */
400 uint8_t pass_flags;
401 } nir_instr;
402
403 static inline nir_instr *
404 nir_instr_next(nir_instr *instr)
405 {
406 struct exec_node *next = exec_node_get_next(&instr->node);
407 if (exec_node_is_tail_sentinel(next))
408 return NULL;
409 else
410 return exec_node_data(nir_instr, next, node);
411 }
412
413 static inline nir_instr *
414 nir_instr_prev(nir_instr *instr)
415 {
416 struct exec_node *prev = exec_node_get_prev(&instr->node);
417 if (exec_node_is_head_sentinel(prev))
418 return NULL;
419 else
420 return exec_node_data(nir_instr, prev, node);
421 }
422
423 static inline bool
424 nir_instr_is_first(nir_instr *instr)
425 {
426 return exec_node_is_head_sentinel(exec_node_get_prev(&instr->node));
427 }
428
429 static inline bool
430 nir_instr_is_last(nir_instr *instr)
431 {
432 return exec_node_is_tail_sentinel(exec_node_get_next(&instr->node));
433 }
434
435 typedef struct nir_ssa_def {
436 /** for debugging only, can be NULL */
437 const char* name;
438
439 /** generic SSA definition index. */
440 unsigned index;
441
442 /** Index into the live_in and live_out bitfields */
443 unsigned live_index;
444
445 nir_instr *parent_instr;
446
447 /** set of nir_instr's where this register is used (read from) */
448 struct list_head uses;
449
450 /** set of nir_if's where this register is used as a condition */
451 struct list_head if_uses;
452
453 uint8_t num_components;
454 } nir_ssa_def;
455
456 struct nir_src;
457
458 typedef struct {
459 nir_register *reg;
460 struct nir_src *indirect; /** < NULL for no indirect offset */
461 unsigned base_offset;
462
463 /* TODO use-def chain goes here */
464 } nir_reg_src;
465
466 typedef struct {
467 nir_instr *parent_instr;
468 struct list_head def_link;
469
470 nir_register *reg;
471 struct nir_src *indirect; /** < NULL for no indirect offset */
472 unsigned base_offset;
473
474 /* TODO def-use chain goes here */
475 } nir_reg_dest;
476
477 struct nir_if;
478
479 typedef struct nir_src {
480 union {
481 nir_instr *parent_instr;
482 struct nir_if *parent_if;
483 };
484
485 struct list_head use_link;
486
487 union {
488 nir_reg_src reg;
489 nir_ssa_def *ssa;
490 };
491
492 bool is_ssa;
493 } nir_src;
494
495 #define NIR_SRC_INIT (nir_src) { { NULL } }
496
497 #define nir_foreach_use(reg_or_ssa_def, src) \
498 list_for_each_entry(nir_src, src, &(reg_or_ssa_def)->uses, use_link)
499
500 #define nir_foreach_use_safe(reg_or_ssa_def, src) \
501 list_for_each_entry_safe(nir_src, src, &(reg_or_ssa_def)->uses, use_link)
502
503 #define nir_foreach_if_use(reg_or_ssa_def, src) \
504 list_for_each_entry(nir_src, src, &(reg_or_ssa_def)->if_uses, use_link)
505
506 #define nir_foreach_if_use_safe(reg_or_ssa_def, src) \
507 list_for_each_entry_safe(nir_src, src, &(reg_or_ssa_def)->if_uses, use_link)
508
509 typedef struct {
510 union {
511 nir_reg_dest reg;
512 nir_ssa_def ssa;
513 };
514
515 bool is_ssa;
516 } nir_dest;
517
518 #define NIR_DEST_INIT (nir_dest) { { { NULL } } }
519
520 #define nir_foreach_def(reg, dest) \
521 list_for_each_entry(nir_dest, dest, &(reg)->defs, reg.def_link)
522
523 #define nir_foreach_def_safe(reg, dest) \
524 list_for_each_entry_safe(nir_dest, dest, &(reg)->defs, reg.def_link)
525
526 static inline nir_src
527 nir_src_for_ssa(nir_ssa_def *def)
528 {
529 nir_src src = NIR_SRC_INIT;
530
531 src.is_ssa = true;
532 src.ssa = def;
533
534 return src;
535 }
536
537 static inline nir_src
538 nir_src_for_reg(nir_register *reg)
539 {
540 nir_src src = NIR_SRC_INIT;
541
542 src.is_ssa = false;
543 src.reg.reg = reg;
544 src.reg.indirect = NULL;
545 src.reg.base_offset = 0;
546
547 return src;
548 }
549
550 static inline nir_dest
551 nir_dest_for_reg(nir_register *reg)
552 {
553 nir_dest dest = NIR_DEST_INIT;
554
555 dest.reg.reg = reg;
556
557 return dest;
558 }
559
560 void nir_src_copy(nir_src *dest, const nir_src *src, void *instr_or_if);
561 void nir_dest_copy(nir_dest *dest, const nir_dest *src, nir_instr *instr);
562
563 typedef struct {
564 nir_src src;
565
566 /**
567 * \name input modifiers
568 */
569 /*@{*/
570 /**
571 * For inputs interpreted as floating point, flips the sign bit. For
572 * inputs interpreted as integers, performs the two's complement negation.
573 */
574 bool negate;
575
576 /**
577 * Clears the sign bit for floating point values, and computes the integer
578 * absolute value for integers. Note that the negate modifier acts after
579 * the absolute value modifier, therefore if both are set then all inputs
580 * will become negative.
581 */
582 bool abs;
583 /*@}*/
584
585 /**
586 * For each input component, says which component of the register it is
587 * chosen from. Note that which elements of the swizzle are used and which
588 * are ignored are based on the write mask for most opcodes - for example,
589 * a statement like "foo.xzw = bar.zyx" would have a writemask of 1101b and
590 * a swizzle of {2, x, 1, 0} where x means "don't care."
591 */
592 uint8_t swizzle[4];
593 } nir_alu_src;
594
595 typedef struct {
596 nir_dest dest;
597
598 /**
599 * \name saturate output modifier
600 *
601 * Only valid for opcodes that output floating-point numbers. Clamps the
602 * output to between 0.0 and 1.0 inclusive.
603 */
604
605 bool saturate;
606
607 unsigned write_mask : 4; /* ignored if dest.is_ssa is true */
608 } nir_alu_dest;
609
610 typedef enum {
611 nir_type_invalid = 0, /* Not a valid type */
612 nir_type_float,
613 nir_type_int,
614 nir_type_uint,
615 nir_type_bool
616 } nir_alu_type;
617
618 typedef enum {
619 NIR_OP_IS_COMMUTATIVE = (1 << 0),
620 NIR_OP_IS_ASSOCIATIVE = (1 << 1),
621 } nir_op_algebraic_property;
622
623 typedef struct {
624 const char *name;
625
626 unsigned num_inputs;
627
628 /**
629 * The number of components in the output
630 *
631 * If non-zero, this is the size of the output and input sizes are
632 * explicitly given; swizzle and writemask are still in effect, but if
633 * the output component is masked out, then the input component may
634 * still be in use.
635 *
636 * If zero, the opcode acts in the standard, per-component manner; the
637 * operation is performed on each component (except the ones that are
638 * masked out) with the input being taken from the input swizzle for
639 * that component.
640 *
641 * The size of some of the inputs may be given (i.e. non-zero) even
642 * though output_size is zero; in that case, the inputs with a zero
643 * size act per-component, while the inputs with non-zero size don't.
644 */
645 unsigned output_size;
646
647 /**
648 * The type of vector that the instruction outputs. Note that the
649 * staurate modifier is only allowed on outputs with the float type.
650 */
651
652 nir_alu_type output_type;
653
654 /**
655 * The number of components in each input
656 */
657 unsigned input_sizes[4];
658
659 /**
660 * The type of vector that each input takes. Note that negate and
661 * absolute value are only allowed on inputs with int or float type and
662 * behave differently on the two.
663 */
664 nir_alu_type input_types[4];
665
666 nir_op_algebraic_property algebraic_properties;
667 } nir_op_info;
668
669 extern const nir_op_info nir_op_infos[nir_num_opcodes];
670
671 typedef struct nir_alu_instr {
672 nir_instr instr;
673 nir_op op;
674 nir_alu_dest dest;
675 nir_alu_src src[];
676 } nir_alu_instr;
677
678 void nir_alu_src_copy(nir_alu_src *dest, const nir_alu_src *src,
679 nir_alu_instr *instr);
680 void nir_alu_dest_copy(nir_alu_dest *dest, const nir_alu_dest *src,
681 nir_alu_instr *instr);
682
683 /* is this source channel used? */
684 static inline bool
685 nir_alu_instr_channel_used(nir_alu_instr *instr, unsigned src, unsigned channel)
686 {
687 if (nir_op_infos[instr->op].input_sizes[src] > 0)
688 return channel < nir_op_infos[instr->op].input_sizes[src];
689
690 return (instr->dest.write_mask >> channel) & 1;
691 }
692
693 /*
694 * For instructions whose destinations are SSA, get the number of channels
695 * used for a source
696 */
697 static inline unsigned
698 nir_ssa_alu_instr_src_components(const nir_alu_instr *instr, unsigned src)
699 {
700 assert(instr->dest.dest.is_ssa);
701
702 if (nir_op_infos[instr->op].input_sizes[src] > 0)
703 return nir_op_infos[instr->op].input_sizes[src];
704
705 return instr->dest.dest.ssa.num_components;
706 }
707
708 typedef enum {
709 nir_deref_type_var,
710 nir_deref_type_array,
711 nir_deref_type_struct
712 } nir_deref_type;
713
714 typedef struct nir_deref {
715 nir_deref_type deref_type;
716 struct nir_deref *child;
717 const struct glsl_type *type;
718 } nir_deref;
719
720 typedef struct {
721 nir_deref deref;
722
723 nir_variable *var;
724 } nir_deref_var;
725
726 /* This enum describes how the array is referenced. If the deref is
727 * direct then the base_offset is used. If the deref is indirect then then
728 * offset is given by base_offset + indirect. If the deref is a wildcard
729 * then the deref refers to all of the elements of the array at the same
730 * time. Wildcard dereferences are only ever allowed in copy_var
731 * intrinsics and the source and destination derefs must have matching
732 * wildcards.
733 */
734 typedef enum {
735 nir_deref_array_type_direct,
736 nir_deref_array_type_indirect,
737 nir_deref_array_type_wildcard,
738 } nir_deref_array_type;
739
740 typedef struct {
741 nir_deref deref;
742
743 nir_deref_array_type deref_array_type;
744 unsigned base_offset;
745 nir_src indirect;
746 } nir_deref_array;
747
748 typedef struct {
749 nir_deref deref;
750
751 unsigned index;
752 } nir_deref_struct;
753
754 NIR_DEFINE_CAST(nir_deref_as_var, nir_deref, nir_deref_var, deref)
755 NIR_DEFINE_CAST(nir_deref_as_array, nir_deref, nir_deref_array, deref)
756 NIR_DEFINE_CAST(nir_deref_as_struct, nir_deref, nir_deref_struct, deref)
757
758 /* Returns the last deref in the chain. */
759 static inline nir_deref *
760 nir_deref_tail(nir_deref *deref)
761 {
762 while (deref->child)
763 deref = deref->child;
764 return deref;
765 }
766
767 typedef struct {
768 nir_instr instr;
769
770 unsigned num_params;
771 nir_deref_var **params;
772 nir_deref_var *return_deref;
773
774 struct nir_function *callee;
775 } nir_call_instr;
776
777 #define INTRINSIC(name, num_srcs, src_components, has_dest, dest_components, \
778 num_variables, num_indices, idx0, idx1, idx2, flags) \
779 nir_intrinsic_##name,
780
781 #define LAST_INTRINSIC(name) nir_last_intrinsic = nir_intrinsic_##name,
782
783 typedef enum {
784 #include "nir_intrinsics.h"
785 nir_num_intrinsics = nir_last_intrinsic + 1
786 } nir_intrinsic_op;
787
788 #undef INTRINSIC
789 #undef LAST_INTRINSIC
790
791 #define NIR_INTRINSIC_MAX_CONST_INDEX 3
792
793 /** Represents an intrinsic
794 *
795 * An intrinsic is an instruction type for handling things that are
796 * more-or-less regular operations but don't just consume and produce SSA
797 * values like ALU operations do. Intrinsics are not for things that have
798 * special semantic meaning such as phi nodes and parallel copies.
799 * Examples of intrinsics include variable load/store operations, system
800 * value loads, and the like. Even though texturing more-or-less falls
801 * under this category, texturing is its own instruction type because
802 * trying to represent texturing with intrinsics would lead to a
803 * combinatorial explosion of intrinsic opcodes.
804 *
805 * By having a single instruction type for handling a lot of different
806 * cases, optimization passes can look for intrinsics and, for the most
807 * part, completely ignore them. Each intrinsic type also has a few
808 * possible flags that govern whether or not they can be reordered or
809 * eliminated. That way passes like dead code elimination can still work
810 * on intrisics without understanding the meaning of each.
811 *
812 * Each intrinsic has some number of constant indices, some number of
813 * variables, and some number of sources. What these sources, variables,
814 * and indices mean depends on the intrinsic and is documented with the
815 * intrinsic declaration in nir_intrinsics.h. Intrinsics and texture
816 * instructions are the only types of instruction that can operate on
817 * variables.
818 */
819 typedef struct {
820 nir_instr instr;
821
822 nir_intrinsic_op intrinsic;
823
824 nir_dest dest;
825
826 /** number of components if this is a vectorized intrinsic
827 *
828 * Similarly to ALU operations, some intrinsics are vectorized.
829 * An intrinsic is vectorized if nir_intrinsic_infos.dest_components == 0.
830 * For vectorized intrinsics, the num_components field specifies the
831 * number of destination components and the number of source components
832 * for all sources with nir_intrinsic_infos.src_components[i] == 0.
833 */
834 uint8_t num_components;
835
836 int const_index[NIR_INTRINSIC_MAX_CONST_INDEX];
837
838 nir_deref_var *variables[2];
839
840 nir_src src[];
841 } nir_intrinsic_instr;
842
843 /**
844 * \name NIR intrinsics semantic flags
845 *
846 * information about what the compiler can do with the intrinsics.
847 *
848 * \sa nir_intrinsic_info::flags
849 */
850 typedef enum {
851 /**
852 * whether the intrinsic can be safely eliminated if none of its output
853 * value is not being used.
854 */
855 NIR_INTRINSIC_CAN_ELIMINATE = (1 << 0),
856
857 /**
858 * Whether the intrinsic can be reordered with respect to any other
859 * intrinsic, i.e. whether the only reordering dependencies of the
860 * intrinsic are due to the register reads/writes.
861 */
862 NIR_INTRINSIC_CAN_REORDER = (1 << 1),
863 } nir_intrinsic_semantic_flag;
864
865 /**
866 * \name NIR intrinsics const-index flag
867 *
868 * Indicates the usage of a const_index slot.
869 *
870 * \sa nir_intrinsic_info::index_map
871 */
872 typedef enum {
873 /**
874 * Generally instructions that take a offset src argument, can encode
875 * a constant 'base' value which is added to the offset.
876 */
877 NIR_INTRINSIC_BASE = 1,
878
879 /**
880 * For store instructions, a writemask for the store.
881 */
882 NIR_INTRINSIC_WRMASK = 2,
883
884 /**
885 * The stream-id for GS emit_vertex/end_primitive intrinsics.
886 */
887 NIR_INTRINSIC_STREAM_ID = 3,
888
889 /**
890 * The clip-plane id for load_user_clip_plane intrinsic.
891 */
892 NIR_INTRINSIC_UCP_ID = 4,
893
894 NIR_INTRINSIC_NUM_INDEX_FLAGS,
895
896 } nir_intrinsic_index_flag;
897
898 #define NIR_INTRINSIC_MAX_INPUTS 4
899
900 typedef struct {
901 const char *name;
902
903 unsigned num_srcs; /** < number of register/SSA inputs */
904
905 /** number of components of each input register
906 *
907 * If this value is 0, the number of components is given by the
908 * num_components field of nir_intrinsic_instr.
909 */
910 unsigned src_components[NIR_INTRINSIC_MAX_INPUTS];
911
912 bool has_dest;
913
914 /** number of components of the output register
915 *
916 * If this value is 0, the number of components is given by the
917 * num_components field of nir_intrinsic_instr.
918 */
919 unsigned dest_components;
920
921 /** the number of inputs/outputs that are variables */
922 unsigned num_variables;
923
924 /** the number of constant indices used by the intrinsic */
925 unsigned num_indices;
926
927 /** indicates the usage of intr->const_index[n] */
928 unsigned index_map[NIR_INTRINSIC_NUM_INDEX_FLAGS];
929
930 /** semantic flags for calls to this intrinsic */
931 nir_intrinsic_semantic_flag flags;
932 } nir_intrinsic_info;
933
934 extern const nir_intrinsic_info nir_intrinsic_infos[nir_num_intrinsics];
935
936
937 #define INTRINSIC_IDX_ACCESSORS(name, flag, type) \
938 static inline type \
939 nir_intrinsic_##name(nir_intrinsic_instr *instr) \
940 { \
941 const nir_intrinsic_info *info = &nir_intrinsic_infos[instr->intrinsic]; \
942 assert(info->index_map[NIR_INTRINSIC_##flag] > 0); \
943 return instr->const_index[info->index_map[NIR_INTRINSIC_##flag] - 1]; \
944 } \
945 static inline void \
946 nir_intrinsic_set_##name(nir_intrinsic_instr *instr, type val) \
947 { \
948 const nir_intrinsic_info *info = &nir_intrinsic_infos[instr->intrinsic]; \
949 assert(info->index_map[NIR_INTRINSIC_##flag] > 0); \
950 instr->const_index[info->index_map[NIR_INTRINSIC_##flag] - 1] = val; \
951 }
952
953 INTRINSIC_IDX_ACCESSORS(write_mask, WRMASK, unsigned)
954 INTRINSIC_IDX_ACCESSORS(base, BASE, int)
955 INTRINSIC_IDX_ACCESSORS(stream_id, STREAM_ID, unsigned)
956 INTRINSIC_IDX_ACCESSORS(ucp_id, UCP_ID, unsigned)
957
958 /**
959 * \group texture information
960 *
961 * This gives semantic information about textures which is useful to the
962 * frontend, the backend, and lowering passes, but not the optimizer.
963 */
964
965 typedef enum {
966 nir_tex_src_coord,
967 nir_tex_src_projector,
968 nir_tex_src_comparitor, /* shadow comparitor */
969 nir_tex_src_offset,
970 nir_tex_src_bias,
971 nir_tex_src_lod,
972 nir_tex_src_ms_index, /* MSAA sample index */
973 nir_tex_src_ddx,
974 nir_tex_src_ddy,
975 nir_tex_src_texture_offset, /* < dynamically uniform indirect offset */
976 nir_tex_src_sampler_offset, /* < dynamically uniform indirect offset */
977 nir_num_tex_src_types
978 } nir_tex_src_type;
979
980 typedef struct {
981 nir_src src;
982 nir_tex_src_type src_type;
983 } nir_tex_src;
984
985 typedef enum {
986 nir_texop_tex, /**< Regular texture look-up */
987 nir_texop_txb, /**< Texture look-up with LOD bias */
988 nir_texop_txl, /**< Texture look-up with explicit LOD */
989 nir_texop_txd, /**< Texture look-up with partial derivatvies */
990 nir_texop_txf, /**< Texel fetch with explicit LOD */
991 nir_texop_txf_ms, /**< Multisample texture fetch */
992 nir_texop_txs, /**< Texture size */
993 nir_texop_lod, /**< Texture lod query */
994 nir_texop_tg4, /**< Texture gather */
995 nir_texop_query_levels, /**< Texture levels query */
996 nir_texop_texture_samples, /**< Texture samples query */
997 nir_texop_samples_identical, /**< Query whether all samples are definitely
998 * identical.
999 */
1000 } nir_texop;
1001
1002 typedef struct {
1003 nir_instr instr;
1004
1005 enum glsl_sampler_dim sampler_dim;
1006 nir_alu_type dest_type;
1007
1008 nir_texop op;
1009 nir_dest dest;
1010 nir_tex_src *src;
1011 unsigned num_srcs, coord_components;
1012 bool is_array, is_shadow;
1013
1014 /**
1015 * If is_shadow is true, whether this is the old-style shadow that outputs 4
1016 * components or the new-style shadow that outputs 1 component.
1017 */
1018 bool is_new_style_shadow;
1019
1020 /* gather component selector */
1021 unsigned component : 2;
1022
1023 /** The texture index
1024 *
1025 * If this texture instruction has a nir_tex_src_texture_offset source,
1026 * then the texture index is given by texture_index + texture_offset.
1027 */
1028 unsigned texture_index;
1029
1030 /** The size of the texture array or 0 if it's not an array */
1031 unsigned texture_array_size;
1032
1033 /** The texture deref
1034 *
1035 * If this is null, use texture_index instead.
1036 */
1037 nir_deref_var *texture;
1038
1039 /** The sampler index
1040 *
1041 * The following operations do not require a sampler and, as such, this
1042 * field should be ignored:
1043 * - nir_texop_txf
1044 * - nir_texop_txf_ms
1045 * - nir_texop_txs
1046 * - nir_texop_lod
1047 * - nir_texop_tg4
1048 * - nir_texop_query_levels
1049 * - nir_texop_texture_samples
1050 * - nir_texop_samples_identical
1051 *
1052 * If this texture instruction has a nir_tex_src_sampler_offset source,
1053 * then the sampler index is given by sampler_index + sampler_offset.
1054 */
1055 unsigned sampler_index;
1056
1057 /** The sampler deref
1058 *
1059 * If this is null, use sampler_index instead.
1060 */
1061 nir_deref_var *sampler;
1062 } nir_tex_instr;
1063
1064 static inline unsigned
1065 nir_tex_instr_dest_size(nir_tex_instr *instr)
1066 {
1067 switch (instr->op) {
1068 case nir_texop_txs: {
1069 unsigned ret;
1070 switch (instr->sampler_dim) {
1071 case GLSL_SAMPLER_DIM_1D:
1072 case GLSL_SAMPLER_DIM_BUF:
1073 ret = 1;
1074 break;
1075 case GLSL_SAMPLER_DIM_2D:
1076 case GLSL_SAMPLER_DIM_CUBE:
1077 case GLSL_SAMPLER_DIM_MS:
1078 case GLSL_SAMPLER_DIM_RECT:
1079 case GLSL_SAMPLER_DIM_EXTERNAL:
1080 ret = 2;
1081 break;
1082 case GLSL_SAMPLER_DIM_3D:
1083 ret = 3;
1084 break;
1085 default:
1086 unreachable("not reached");
1087 }
1088 if (instr->is_array)
1089 ret++;
1090 return ret;
1091 }
1092
1093 case nir_texop_lod:
1094 return 2;
1095
1096 case nir_texop_texture_samples:
1097 case nir_texop_query_levels:
1098 case nir_texop_samples_identical:
1099 return 1;
1100
1101 default:
1102 if (instr->is_shadow && instr->is_new_style_shadow)
1103 return 1;
1104
1105 return 4;
1106 }
1107 }
1108
1109 /* Returns true if this texture operation queries something about the texture
1110 * rather than actually sampling it.
1111 */
1112 static inline bool
1113 nir_tex_instr_is_query(nir_tex_instr *instr)
1114 {
1115 switch (instr->op) {
1116 case nir_texop_txs:
1117 case nir_texop_lod:
1118 case nir_texop_texture_samples:
1119 case nir_texop_query_levels:
1120 return true;
1121 case nir_texop_tex:
1122 case nir_texop_txb:
1123 case nir_texop_txl:
1124 case nir_texop_txd:
1125 case nir_texop_txf:
1126 case nir_texop_txf_ms:
1127 case nir_texop_tg4:
1128 return false;
1129 default:
1130 unreachable("Invalid texture opcode");
1131 }
1132 }
1133
1134 static inline unsigned
1135 nir_tex_instr_src_size(nir_tex_instr *instr, unsigned src)
1136 {
1137 if (instr->src[src].src_type == nir_tex_src_coord)
1138 return instr->coord_components;
1139
1140
1141 if (instr->src[src].src_type == nir_tex_src_offset ||
1142 instr->src[src].src_type == nir_tex_src_ddx ||
1143 instr->src[src].src_type == nir_tex_src_ddy) {
1144 if (instr->is_array)
1145 return instr->coord_components - 1;
1146 else
1147 return instr->coord_components;
1148 }
1149
1150 return 1;
1151 }
1152
1153 static inline int
1154 nir_tex_instr_src_index(nir_tex_instr *instr, nir_tex_src_type type)
1155 {
1156 for (unsigned i = 0; i < instr->num_srcs; i++)
1157 if (instr->src[i].src_type == type)
1158 return (int) i;
1159
1160 return -1;
1161 }
1162
1163 typedef struct {
1164 union {
1165 float f[4];
1166 int32_t i[4];
1167 uint32_t u[4];
1168 };
1169 } nir_const_value;
1170
1171 typedef struct {
1172 nir_instr instr;
1173
1174 nir_const_value value;
1175
1176 nir_ssa_def def;
1177 } nir_load_const_instr;
1178
1179 typedef enum {
1180 nir_jump_return,
1181 nir_jump_break,
1182 nir_jump_continue,
1183 } nir_jump_type;
1184
1185 typedef struct {
1186 nir_instr instr;
1187 nir_jump_type type;
1188 } nir_jump_instr;
1189
1190 /* creates a new SSA variable in an undefined state */
1191
1192 typedef struct {
1193 nir_instr instr;
1194 nir_ssa_def def;
1195 } nir_ssa_undef_instr;
1196
1197 typedef struct {
1198 struct exec_node node;
1199
1200 /* The predecessor block corresponding to this source */
1201 struct nir_block *pred;
1202
1203 nir_src src;
1204 } nir_phi_src;
1205
1206 #define nir_foreach_phi_src(phi, entry) \
1207 foreach_list_typed(nir_phi_src, entry, node, &(phi)->srcs)
1208 #define nir_foreach_phi_src_safe(phi, entry) \
1209 foreach_list_typed_safe(nir_phi_src, entry, node, &(phi)->srcs)
1210
1211 typedef struct {
1212 nir_instr instr;
1213
1214 struct exec_list srcs; /** < list of nir_phi_src */
1215
1216 nir_dest dest;
1217 } nir_phi_instr;
1218
1219 typedef struct {
1220 struct exec_node node;
1221 nir_src src;
1222 nir_dest dest;
1223 } nir_parallel_copy_entry;
1224
1225 #define nir_foreach_parallel_copy_entry(pcopy, entry) \
1226 foreach_list_typed(nir_parallel_copy_entry, entry, node, &(pcopy)->entries)
1227
1228 typedef struct {
1229 nir_instr instr;
1230
1231 /* A list of nir_parallel_copy_entry's. The sources of all of the
1232 * entries are copied to the corresponding destinations "in parallel".
1233 * In other words, if we have two entries: a -> b and b -> a, the values
1234 * get swapped.
1235 */
1236 struct exec_list entries;
1237 } nir_parallel_copy_instr;
1238
1239 NIR_DEFINE_CAST(nir_instr_as_alu, nir_instr, nir_alu_instr, instr)
1240 NIR_DEFINE_CAST(nir_instr_as_call, nir_instr, nir_call_instr, instr)
1241 NIR_DEFINE_CAST(nir_instr_as_jump, nir_instr, nir_jump_instr, instr)
1242 NIR_DEFINE_CAST(nir_instr_as_tex, nir_instr, nir_tex_instr, instr)
1243 NIR_DEFINE_CAST(nir_instr_as_intrinsic, nir_instr, nir_intrinsic_instr, instr)
1244 NIR_DEFINE_CAST(nir_instr_as_load_const, nir_instr, nir_load_const_instr, instr)
1245 NIR_DEFINE_CAST(nir_instr_as_ssa_undef, nir_instr, nir_ssa_undef_instr, instr)
1246 NIR_DEFINE_CAST(nir_instr_as_phi, nir_instr, nir_phi_instr, instr)
1247 NIR_DEFINE_CAST(nir_instr_as_parallel_copy, nir_instr,
1248 nir_parallel_copy_instr, instr)
1249
1250 /*
1251 * Control flow
1252 *
1253 * Control flow consists of a tree of control flow nodes, which include
1254 * if-statements and loops. The leaves of the tree are basic blocks, lists of
1255 * instructions that always run start-to-finish. Each basic block also keeps
1256 * track of its successors (blocks which may run immediately after the current
1257 * block) and predecessors (blocks which could have run immediately before the
1258 * current block). Each function also has a start block and an end block which
1259 * all return statements point to (which is always empty). Together, all the
1260 * blocks with their predecessors and successors make up the control flow
1261 * graph (CFG) of the function. There are helpers that modify the tree of
1262 * control flow nodes while modifying the CFG appropriately; these should be
1263 * used instead of modifying the tree directly.
1264 */
1265
1266 typedef enum {
1267 nir_cf_node_block,
1268 nir_cf_node_if,
1269 nir_cf_node_loop,
1270 nir_cf_node_function
1271 } nir_cf_node_type;
1272
1273 typedef struct nir_cf_node {
1274 struct exec_node node;
1275 nir_cf_node_type type;
1276 struct nir_cf_node *parent;
1277 } nir_cf_node;
1278
1279 typedef struct nir_block {
1280 nir_cf_node cf_node;
1281
1282 struct exec_list instr_list; /** < list of nir_instr */
1283
1284 /** generic block index; generated by nir_index_blocks */
1285 unsigned index;
1286
1287 /*
1288 * Each block can only have up to 2 successors, so we put them in a simple
1289 * array - no need for anything more complicated.
1290 */
1291 struct nir_block *successors[2];
1292
1293 /* Set of nir_block predecessors in the CFG */
1294 struct set *predecessors;
1295
1296 /*
1297 * this node's immediate dominator in the dominance tree - set to NULL for
1298 * the start block.
1299 */
1300 struct nir_block *imm_dom;
1301
1302 /* This node's children in the dominance tree */
1303 unsigned num_dom_children;
1304 struct nir_block **dom_children;
1305
1306 /* Set of nir_block's on the dominance frontier of this block */
1307 struct set *dom_frontier;
1308
1309 /*
1310 * These two indices have the property that dom_{pre,post}_index for each
1311 * child of this block in the dominance tree will always be between
1312 * dom_pre_index and dom_post_index for this block, which makes testing if
1313 * a given block is dominated by another block an O(1) operation.
1314 */
1315 unsigned dom_pre_index, dom_post_index;
1316
1317 /* live in and out for this block; used for liveness analysis */
1318 BITSET_WORD *live_in;
1319 BITSET_WORD *live_out;
1320 } nir_block;
1321
1322 static inline nir_instr *
1323 nir_block_first_instr(nir_block *block)
1324 {
1325 struct exec_node *head = exec_list_get_head(&block->instr_list);
1326 return exec_node_data(nir_instr, head, node);
1327 }
1328
1329 static inline nir_instr *
1330 nir_block_last_instr(nir_block *block)
1331 {
1332 struct exec_node *tail = exec_list_get_tail(&block->instr_list);
1333 return exec_node_data(nir_instr, tail, node);
1334 }
1335
1336 #define nir_foreach_instr(block, instr) \
1337 foreach_list_typed(nir_instr, instr, node, &(block)->instr_list)
1338 #define nir_foreach_instr_reverse(block, instr) \
1339 foreach_list_typed_reverse(nir_instr, instr, node, &(block)->instr_list)
1340 #define nir_foreach_instr_safe(block, instr) \
1341 foreach_list_typed_safe(nir_instr, instr, node, &(block)->instr_list)
1342 #define nir_foreach_instr_reverse_safe(block, instr) \
1343 foreach_list_typed_reverse_safe(nir_instr, instr, node, &(block)->instr_list)
1344
1345 typedef struct nir_if {
1346 nir_cf_node cf_node;
1347 nir_src condition;
1348
1349 struct exec_list then_list; /** < list of nir_cf_node */
1350 struct exec_list else_list; /** < list of nir_cf_node */
1351 } nir_if;
1352
1353 static inline nir_cf_node *
1354 nir_if_first_then_node(nir_if *if_stmt)
1355 {
1356 struct exec_node *head = exec_list_get_head(&if_stmt->then_list);
1357 return exec_node_data(nir_cf_node, head, node);
1358 }
1359
1360 static inline nir_cf_node *
1361 nir_if_last_then_node(nir_if *if_stmt)
1362 {
1363 struct exec_node *tail = exec_list_get_tail(&if_stmt->then_list);
1364 return exec_node_data(nir_cf_node, tail, node);
1365 }
1366
1367 static inline nir_cf_node *
1368 nir_if_first_else_node(nir_if *if_stmt)
1369 {
1370 struct exec_node *head = exec_list_get_head(&if_stmt->else_list);
1371 return exec_node_data(nir_cf_node, head, node);
1372 }
1373
1374 static inline nir_cf_node *
1375 nir_if_last_else_node(nir_if *if_stmt)
1376 {
1377 struct exec_node *tail = exec_list_get_tail(&if_stmt->else_list);
1378 return exec_node_data(nir_cf_node, tail, node);
1379 }
1380
1381 typedef struct {
1382 nir_cf_node cf_node;
1383
1384 struct exec_list body; /** < list of nir_cf_node */
1385 } nir_loop;
1386
1387 static inline nir_cf_node *
1388 nir_loop_first_cf_node(nir_loop *loop)
1389 {
1390 return exec_node_data(nir_cf_node, exec_list_get_head(&loop->body), node);
1391 }
1392
1393 static inline nir_cf_node *
1394 nir_loop_last_cf_node(nir_loop *loop)
1395 {
1396 return exec_node_data(nir_cf_node, exec_list_get_tail(&loop->body), node);
1397 }
1398
1399 /**
1400 * Various bits of metadata that can may be created or required by
1401 * optimization and analysis passes
1402 */
1403 typedef enum {
1404 nir_metadata_none = 0x0,
1405 nir_metadata_block_index = 0x1,
1406 nir_metadata_dominance = 0x2,
1407 nir_metadata_live_ssa_defs = 0x4,
1408 nir_metadata_not_properly_reset = 0x8,
1409 } nir_metadata;
1410
1411 typedef struct {
1412 nir_cf_node cf_node;
1413
1414 /** pointer to the function of which this is an implementation */
1415 struct nir_function *function;
1416
1417 struct exec_list body; /** < list of nir_cf_node */
1418
1419 nir_block *end_block;
1420
1421 /** list for all local variables in the function */
1422 struct exec_list locals;
1423
1424 /** array of variables used as parameters */
1425 unsigned num_params;
1426 nir_variable **params;
1427
1428 /** variable used to hold the result of the function */
1429 nir_variable *return_var;
1430
1431 /** list of local registers in the function */
1432 struct exec_list registers;
1433
1434 /** next available local register index */
1435 unsigned reg_alloc;
1436
1437 /** next available SSA value index */
1438 unsigned ssa_alloc;
1439
1440 /* total number of basic blocks, only valid when block_index_dirty = false */
1441 unsigned num_blocks;
1442
1443 nir_metadata valid_metadata;
1444 } nir_function_impl;
1445
1446 static inline nir_block *
1447 nir_start_block(nir_function_impl *impl)
1448 {
1449 return (nir_block *) exec_list_get_head(&impl->body);
1450 }
1451
1452 static inline nir_cf_node *
1453 nir_cf_node_next(nir_cf_node *node)
1454 {
1455 struct exec_node *next = exec_node_get_next(&node->node);
1456 if (exec_node_is_tail_sentinel(next))
1457 return NULL;
1458 else
1459 return exec_node_data(nir_cf_node, next, node);
1460 }
1461
1462 static inline nir_cf_node *
1463 nir_cf_node_prev(nir_cf_node *node)
1464 {
1465 struct exec_node *prev = exec_node_get_prev(&node->node);
1466 if (exec_node_is_head_sentinel(prev))
1467 return NULL;
1468 else
1469 return exec_node_data(nir_cf_node, prev, node);
1470 }
1471
1472 static inline bool
1473 nir_cf_node_is_first(const nir_cf_node *node)
1474 {
1475 return exec_node_is_head_sentinel(node->node.prev);
1476 }
1477
1478 static inline bool
1479 nir_cf_node_is_last(const nir_cf_node *node)
1480 {
1481 return exec_node_is_tail_sentinel(node->node.next);
1482 }
1483
1484 NIR_DEFINE_CAST(nir_cf_node_as_block, nir_cf_node, nir_block, cf_node)
1485 NIR_DEFINE_CAST(nir_cf_node_as_if, nir_cf_node, nir_if, cf_node)
1486 NIR_DEFINE_CAST(nir_cf_node_as_loop, nir_cf_node, nir_loop, cf_node)
1487 NIR_DEFINE_CAST(nir_cf_node_as_function, nir_cf_node, nir_function_impl, cf_node)
1488
1489 typedef enum {
1490 nir_parameter_in,
1491 nir_parameter_out,
1492 nir_parameter_inout,
1493 } nir_parameter_type;
1494
1495 typedef struct {
1496 nir_parameter_type param_type;
1497 const struct glsl_type *type;
1498 } nir_parameter;
1499
1500 typedef struct nir_function {
1501 struct exec_node node;
1502
1503 const char *name;
1504 struct nir_shader *shader;
1505
1506 unsigned num_params;
1507 nir_parameter *params;
1508 const struct glsl_type *return_type;
1509
1510 /** The implementation of this function.
1511 *
1512 * If the function is only declared and not implemented, this is NULL.
1513 */
1514 nir_function_impl *impl;
1515 } nir_function;
1516
1517 typedef struct nir_shader_compiler_options {
1518 bool lower_fdiv;
1519 bool lower_ffma;
1520 bool lower_flrp;
1521 bool lower_fpow;
1522 bool lower_fsat;
1523 bool lower_fsqrt;
1524 bool lower_fmod;
1525 bool lower_bitfield_extract;
1526 bool lower_bitfield_insert;
1527 bool lower_uadd_carry;
1528 bool lower_usub_borrow;
1529 /** lowers fneg and ineg to fsub and isub. */
1530 bool lower_negate;
1531 /** lowers fsub and isub to fadd+fneg and iadd+ineg. */
1532 bool lower_sub;
1533
1534 /* lower {slt,sge,seq,sne} to {flt,fge,feq,fne} + b2f: */
1535 bool lower_scmp;
1536
1537 /* Does the native fdot instruction replicate its result for four
1538 * components? If so, then opt_algebraic_late will turn all fdotN
1539 * instructions into fdot_replicatedN instructions.
1540 */
1541 bool fdot_replicates;
1542
1543 /** lowers ffract to fsub+ffloor: */
1544 bool lower_ffract;
1545
1546 bool lower_pack_half_2x16;
1547 bool lower_pack_unorm_2x16;
1548 bool lower_pack_snorm_2x16;
1549 bool lower_pack_unorm_4x8;
1550 bool lower_pack_snorm_4x8;
1551 bool lower_unpack_half_2x16;
1552 bool lower_unpack_unorm_2x16;
1553 bool lower_unpack_snorm_2x16;
1554 bool lower_unpack_unorm_4x8;
1555 bool lower_unpack_snorm_4x8;
1556
1557 bool lower_extract_byte;
1558 bool lower_extract_word;
1559
1560 /**
1561 * Does the driver support real 32-bit integers? (Otherwise, integers
1562 * are simulated by floats.)
1563 */
1564 bool native_integers;
1565 } nir_shader_compiler_options;
1566
1567 typedef struct nir_shader_info {
1568 const char *name;
1569
1570 /* Descriptive name provided by the client; may be NULL */
1571 const char *label;
1572
1573 /* Number of textures used by this shader */
1574 unsigned num_textures;
1575 /* Number of uniform buffers used by this shader */
1576 unsigned num_ubos;
1577 /* Number of atomic buffers used by this shader */
1578 unsigned num_abos;
1579 /* Number of shader storage buffers used by this shader */
1580 unsigned num_ssbos;
1581 /* Number of images used by this shader */
1582 unsigned num_images;
1583
1584 /* Which inputs are actually read */
1585 uint64_t inputs_read;
1586 /* Which outputs are actually written */
1587 uint64_t outputs_written;
1588 /* Which system values are actually read */
1589 uint64_t system_values_read;
1590
1591 /* Which patch inputs are actually read */
1592 uint32_t patch_inputs_read;
1593 /* Which patch outputs are actually written */
1594 uint32_t patch_outputs_written;
1595
1596 /* Whether or not this shader ever uses textureGather() */
1597 bool uses_texture_gather;
1598
1599 /* Whether or not this shader uses the gl_ClipDistance output */
1600 bool uses_clip_distance_out;
1601
1602 /* Whether or not separate shader objects were used */
1603 bool separate_shader;
1604
1605 /** Was this shader linked with any transform feedback varyings? */
1606 bool has_transform_feedback_varyings;
1607
1608 union {
1609 struct {
1610 /** The number of vertices recieves per input primitive */
1611 unsigned vertices_in;
1612
1613 /** The output primitive type (GL enum value) */
1614 unsigned output_primitive;
1615
1616 /** The maximum number of vertices the geometry shader might write. */
1617 unsigned vertices_out;
1618
1619 /** 1 .. MAX_GEOMETRY_SHADER_INVOCATIONS */
1620 unsigned invocations;
1621
1622 /** Whether or not this shader uses EndPrimitive */
1623 bool uses_end_primitive;
1624
1625 /** Whether or not this shader uses non-zero streams */
1626 bool uses_streams;
1627 } gs;
1628
1629 struct {
1630 bool uses_discard;
1631
1632 /**
1633 * Whether early fragment tests are enabled as defined by
1634 * ARB_shader_image_load_store.
1635 */
1636 bool early_fragment_tests;
1637
1638 /** gl_FragDepth layout for ARB_conservative_depth. */
1639 enum gl_frag_depth_layout depth_layout;
1640 } fs;
1641
1642 struct {
1643 unsigned local_size[3];
1644 } cs;
1645
1646 struct {
1647 /** The number of vertices in the TCS output patch. */
1648 unsigned vertices_out;
1649 } tcs;
1650 };
1651 } nir_shader_info;
1652
1653 typedef struct nir_shader {
1654 /** list of uniforms (nir_variable) */
1655 struct exec_list uniforms;
1656
1657 /** list of inputs (nir_variable) */
1658 struct exec_list inputs;
1659
1660 /** list of outputs (nir_variable) */
1661 struct exec_list outputs;
1662
1663 /** Set of driver-specific options for the shader.
1664 *
1665 * The memory for the options is expected to be kept in a single static
1666 * copy by the driver.
1667 */
1668 const struct nir_shader_compiler_options *options;
1669
1670 /** Various bits of compile-time information about a given shader */
1671 struct nir_shader_info info;
1672
1673 /** list of global variables in the shader (nir_variable) */
1674 struct exec_list globals;
1675
1676 /** list of system value variables in the shader (nir_variable) */
1677 struct exec_list system_values;
1678
1679 struct exec_list functions; /** < list of nir_function */
1680
1681 /** list of global register in the shader */
1682 struct exec_list registers;
1683
1684 /** next available global register index */
1685 unsigned reg_alloc;
1686
1687 /**
1688 * the highest index a load_input_*, load_uniform_*, etc. intrinsic can
1689 * access plus one
1690 */
1691 unsigned num_inputs, num_uniforms, num_outputs;
1692
1693 /** The shader stage, such as MESA_SHADER_VERTEX. */
1694 gl_shader_stage stage;
1695 } nir_shader;
1696
1697 #define nir_foreach_function(shader, func) \
1698 foreach_list_typed(nir_function, func, node, &(shader)->functions)
1699
1700 nir_shader *nir_shader_create(void *mem_ctx,
1701 gl_shader_stage stage,
1702 const nir_shader_compiler_options *options);
1703
1704 /** creates a register, including assigning it an index and adding it to the list */
1705 nir_register *nir_global_reg_create(nir_shader *shader);
1706
1707 nir_register *nir_local_reg_create(nir_function_impl *impl);
1708
1709 void nir_reg_remove(nir_register *reg);
1710
1711 /** Adds a variable to the appropreate list in nir_shader */
1712 void nir_shader_add_variable(nir_shader *shader, nir_variable *var);
1713
1714 static inline void
1715 nir_function_impl_add_variable(nir_function_impl *impl, nir_variable *var)
1716 {
1717 assert(var->data.mode == nir_var_local);
1718 exec_list_push_tail(&impl->locals, &var->node);
1719 }
1720
1721 /** creates a variable, sets a few defaults, and adds it to the list */
1722 nir_variable *nir_variable_create(nir_shader *shader,
1723 nir_variable_mode mode,
1724 const struct glsl_type *type,
1725 const char *name);
1726 /** creates a local variable and adds it to the list */
1727 nir_variable *nir_local_variable_create(nir_function_impl *impl,
1728 const struct glsl_type *type,
1729 const char *name);
1730
1731 /** creates a function and adds it to the shader's list of functions */
1732 nir_function *nir_function_create(nir_shader *shader, const char *name);
1733
1734 nir_function_impl *nir_function_impl_create(nir_function *func);
1735 /** creates a function_impl that isn't tied to any particular function */
1736 nir_function_impl *nir_function_impl_create_bare(nir_shader *shader);
1737
1738 nir_block *nir_block_create(nir_shader *shader);
1739 nir_if *nir_if_create(nir_shader *shader);
1740 nir_loop *nir_loop_create(nir_shader *shader);
1741
1742 nir_function_impl *nir_cf_node_get_function(nir_cf_node *node);
1743
1744 /** requests that the given pieces of metadata be generated */
1745 void nir_metadata_require(nir_function_impl *impl, nir_metadata required);
1746 /** dirties all but the preserved metadata */
1747 void nir_metadata_preserve(nir_function_impl *impl, nir_metadata preserved);
1748
1749 /** creates an instruction with default swizzle/writemask/etc. with NULL registers */
1750 nir_alu_instr *nir_alu_instr_create(nir_shader *shader, nir_op op);
1751
1752 nir_jump_instr *nir_jump_instr_create(nir_shader *shader, nir_jump_type type);
1753
1754 nir_load_const_instr *nir_load_const_instr_create(nir_shader *shader,
1755 unsigned num_components);
1756
1757 nir_intrinsic_instr *nir_intrinsic_instr_create(nir_shader *shader,
1758 nir_intrinsic_op op);
1759
1760 nir_call_instr *nir_call_instr_create(nir_shader *shader,
1761 nir_function *callee);
1762
1763 nir_tex_instr *nir_tex_instr_create(nir_shader *shader, unsigned num_srcs);
1764
1765 nir_phi_instr *nir_phi_instr_create(nir_shader *shader);
1766
1767 nir_parallel_copy_instr *nir_parallel_copy_instr_create(nir_shader *shader);
1768
1769 nir_ssa_undef_instr *nir_ssa_undef_instr_create(nir_shader *shader,
1770 unsigned num_components);
1771
1772 nir_deref_var *nir_deref_var_create(void *mem_ctx, nir_variable *var);
1773 nir_deref_array *nir_deref_array_create(void *mem_ctx);
1774 nir_deref_struct *nir_deref_struct_create(void *mem_ctx, unsigned field_index);
1775
1776 nir_deref *nir_copy_deref(void *mem_ctx, nir_deref *deref);
1777
1778 nir_load_const_instr *
1779 nir_deref_get_const_initializer_load(nir_shader *shader, nir_deref_var *deref);
1780
1781 /**
1782 * NIR Cursors and Instruction Insertion API
1783 * @{
1784 *
1785 * A tiny struct representing a point to insert/extract instructions or
1786 * control flow nodes. Helps reduce the combinatorial explosion of possible
1787 * points to insert/extract.
1788 *
1789 * \sa nir_control_flow.h
1790 */
1791 typedef enum {
1792 nir_cursor_before_block,
1793 nir_cursor_after_block,
1794 nir_cursor_before_instr,
1795 nir_cursor_after_instr,
1796 } nir_cursor_option;
1797
1798 typedef struct {
1799 nir_cursor_option option;
1800 union {
1801 nir_block *block;
1802 nir_instr *instr;
1803 };
1804 } nir_cursor;
1805
1806 static inline nir_cursor
1807 nir_before_block(nir_block *block)
1808 {
1809 nir_cursor cursor;
1810 cursor.option = nir_cursor_before_block;
1811 cursor.block = block;
1812 return cursor;
1813 }
1814
1815 static inline nir_cursor
1816 nir_after_block(nir_block *block)
1817 {
1818 nir_cursor cursor;
1819 cursor.option = nir_cursor_after_block;
1820 cursor.block = block;
1821 return cursor;
1822 }
1823
1824 static inline nir_cursor
1825 nir_before_instr(nir_instr *instr)
1826 {
1827 nir_cursor cursor;
1828 cursor.option = nir_cursor_before_instr;
1829 cursor.instr = instr;
1830 return cursor;
1831 }
1832
1833 static inline nir_cursor
1834 nir_after_instr(nir_instr *instr)
1835 {
1836 nir_cursor cursor;
1837 cursor.option = nir_cursor_after_instr;
1838 cursor.instr = instr;
1839 return cursor;
1840 }
1841
1842 static inline nir_cursor
1843 nir_after_block_before_jump(nir_block *block)
1844 {
1845 nir_instr *last_instr = nir_block_last_instr(block);
1846 if (last_instr && last_instr->type == nir_instr_type_jump) {
1847 return nir_before_instr(last_instr);
1848 } else {
1849 return nir_after_block(block);
1850 }
1851 }
1852
1853 static inline nir_cursor
1854 nir_before_cf_node(nir_cf_node *node)
1855 {
1856 if (node->type == nir_cf_node_block)
1857 return nir_before_block(nir_cf_node_as_block(node));
1858
1859 return nir_after_block(nir_cf_node_as_block(nir_cf_node_prev(node)));
1860 }
1861
1862 static inline nir_cursor
1863 nir_after_cf_node(nir_cf_node *node)
1864 {
1865 if (node->type == nir_cf_node_block)
1866 return nir_after_block(nir_cf_node_as_block(node));
1867
1868 return nir_before_block(nir_cf_node_as_block(nir_cf_node_next(node)));
1869 }
1870
1871 static inline nir_cursor
1872 nir_before_cf_list(struct exec_list *cf_list)
1873 {
1874 nir_cf_node *first_node = exec_node_data(nir_cf_node,
1875 exec_list_get_head(cf_list), node);
1876 return nir_before_cf_node(first_node);
1877 }
1878
1879 static inline nir_cursor
1880 nir_after_cf_list(struct exec_list *cf_list)
1881 {
1882 nir_cf_node *last_node = exec_node_data(nir_cf_node,
1883 exec_list_get_tail(cf_list), node);
1884 return nir_after_cf_node(last_node);
1885 }
1886
1887 /**
1888 * Insert a NIR instruction at the given cursor.
1889 *
1890 * Note: This does not update the cursor.
1891 */
1892 void nir_instr_insert(nir_cursor cursor, nir_instr *instr);
1893
1894 static inline void
1895 nir_instr_insert_before(nir_instr *instr, nir_instr *before)
1896 {
1897 nir_instr_insert(nir_before_instr(instr), before);
1898 }
1899
1900 static inline void
1901 nir_instr_insert_after(nir_instr *instr, nir_instr *after)
1902 {
1903 nir_instr_insert(nir_after_instr(instr), after);
1904 }
1905
1906 static inline void
1907 nir_instr_insert_before_block(nir_block *block, nir_instr *before)
1908 {
1909 nir_instr_insert(nir_before_block(block), before);
1910 }
1911
1912 static inline void
1913 nir_instr_insert_after_block(nir_block *block, nir_instr *after)
1914 {
1915 nir_instr_insert(nir_after_block(block), after);
1916 }
1917
1918 static inline void
1919 nir_instr_insert_before_cf(nir_cf_node *node, nir_instr *before)
1920 {
1921 nir_instr_insert(nir_before_cf_node(node), before);
1922 }
1923
1924 static inline void
1925 nir_instr_insert_after_cf(nir_cf_node *node, nir_instr *after)
1926 {
1927 nir_instr_insert(nir_after_cf_node(node), after);
1928 }
1929
1930 static inline void
1931 nir_instr_insert_before_cf_list(struct exec_list *list, nir_instr *before)
1932 {
1933 nir_instr_insert(nir_before_cf_list(list), before);
1934 }
1935
1936 static inline void
1937 nir_instr_insert_after_cf_list(struct exec_list *list, nir_instr *after)
1938 {
1939 nir_instr_insert(nir_after_cf_list(list), after);
1940 }
1941
1942 void nir_instr_remove(nir_instr *instr);
1943
1944 /** @} */
1945
1946 typedef bool (*nir_foreach_ssa_def_cb)(nir_ssa_def *def, void *state);
1947 typedef bool (*nir_foreach_dest_cb)(nir_dest *dest, void *state);
1948 typedef bool (*nir_foreach_src_cb)(nir_src *src, void *state);
1949 bool nir_foreach_ssa_def(nir_instr *instr, nir_foreach_ssa_def_cb cb,
1950 void *state);
1951 bool nir_foreach_dest(nir_instr *instr, nir_foreach_dest_cb cb, void *state);
1952 bool nir_foreach_src(nir_instr *instr, nir_foreach_src_cb cb, void *state);
1953
1954 nir_const_value *nir_src_as_const_value(nir_src src);
1955 bool nir_src_is_dynamically_uniform(nir_src src);
1956 bool nir_srcs_equal(nir_src src1, nir_src src2);
1957 void nir_instr_rewrite_src(nir_instr *instr, nir_src *src, nir_src new_src);
1958 void nir_instr_move_src(nir_instr *dest_instr, nir_src *dest, nir_src *src);
1959 void nir_if_rewrite_condition(nir_if *if_stmt, nir_src new_src);
1960 void nir_instr_rewrite_dest(nir_instr *instr, nir_dest *dest,
1961 nir_dest new_dest);
1962
1963 void nir_ssa_dest_init(nir_instr *instr, nir_dest *dest,
1964 unsigned num_components, const char *name);
1965 void nir_ssa_def_init(nir_instr *instr, nir_ssa_def *def,
1966 unsigned num_components, const char *name);
1967 void nir_ssa_def_rewrite_uses(nir_ssa_def *def, nir_src new_src);
1968 void nir_ssa_def_rewrite_uses_after(nir_ssa_def *def, nir_src new_src,
1969 nir_instr *after_me);
1970
1971 /* visits basic blocks in source-code order */
1972 typedef bool (*nir_foreach_block_cb)(nir_block *block, void *state);
1973 bool nir_foreach_block(nir_function_impl *impl, nir_foreach_block_cb cb,
1974 void *state);
1975 bool nir_foreach_block_reverse(nir_function_impl *impl, nir_foreach_block_cb cb,
1976 void *state);
1977 bool nir_foreach_block_in_cf_node(nir_cf_node *node, nir_foreach_block_cb cb,
1978 void *state);
1979
1980 /* If the following CF node is an if, this function returns that if.
1981 * Otherwise, it returns NULL.
1982 */
1983 nir_if *nir_block_get_following_if(nir_block *block);
1984
1985 nir_loop *nir_block_get_following_loop(nir_block *block);
1986
1987 void nir_index_local_regs(nir_function_impl *impl);
1988 void nir_index_global_regs(nir_shader *shader);
1989 void nir_index_ssa_defs(nir_function_impl *impl);
1990 unsigned nir_index_instrs(nir_function_impl *impl);
1991
1992 void nir_index_blocks(nir_function_impl *impl);
1993
1994 void nir_print_shader(nir_shader *shader, FILE *fp);
1995 void nir_print_instr(const nir_instr *instr, FILE *fp);
1996
1997 nir_shader * nir_shader_clone(void *mem_ctx, const nir_shader *s);
1998
1999 #ifdef DEBUG
2000 void nir_validate_shader(nir_shader *shader);
2001 void nir_metadata_set_validation_flag(nir_shader *shader);
2002 void nir_metadata_check_validation_flag(nir_shader *shader);
2003
2004 #include "util/debug.h"
2005 static inline bool
2006 should_clone_nir(void)
2007 {
2008 static int should_clone = -1;
2009 if (should_clone < 0)
2010 should_clone = env_var_as_boolean("NIR_TEST_CLONE", false);
2011
2012 return should_clone;
2013 }
2014 #else
2015 static inline void nir_validate_shader(nir_shader *shader) { (void) shader; }
2016 static inline void nir_metadata_set_validation_flag(nir_shader *shader) { (void) shader; }
2017 static inline void nir_metadata_check_validation_flag(nir_shader *shader) { (void) shader; }
2018 static inline bool should_clone_nir(void) { return false; }
2019 #endif /* DEBUG */
2020
2021 #define _PASS(nir, do_pass) do { \
2022 do_pass \
2023 nir_validate_shader(nir); \
2024 if (should_clone_nir()) { \
2025 nir_shader *clone = nir_shader_clone(ralloc_parent(nir), nir); \
2026 ralloc_free(nir); \
2027 nir = clone; \
2028 } \
2029 } while (0)
2030
2031 #define NIR_PASS(progress, nir, pass, ...) _PASS(nir, \
2032 nir_metadata_set_validation_flag(nir); \
2033 if (pass(nir, ##__VA_ARGS__)) { \
2034 progress = true; \
2035 nir_metadata_check_validation_flag(nir); \
2036 } \
2037 )
2038
2039 #define NIR_PASS_V(nir, pass, ...) _PASS(nir, \
2040 pass(nir, ##__VA_ARGS__); \
2041 )
2042
2043 void nir_calc_dominance_impl(nir_function_impl *impl);
2044 void nir_calc_dominance(nir_shader *shader);
2045
2046 nir_block *nir_dominance_lca(nir_block *b1, nir_block *b2);
2047 bool nir_block_dominates(nir_block *parent, nir_block *child);
2048
2049 void nir_dump_dom_tree_impl(nir_function_impl *impl, FILE *fp);
2050 void nir_dump_dom_tree(nir_shader *shader, FILE *fp);
2051
2052 void nir_dump_dom_frontier_impl(nir_function_impl *impl, FILE *fp);
2053 void nir_dump_dom_frontier(nir_shader *shader, FILE *fp);
2054
2055 void nir_dump_cfg_impl(nir_function_impl *impl, FILE *fp);
2056 void nir_dump_cfg(nir_shader *shader, FILE *fp);
2057
2058 int nir_gs_count_vertices(const nir_shader *shader);
2059
2060 bool nir_split_var_copies(nir_shader *shader);
2061
2062 void nir_lower_var_copy_instr(nir_intrinsic_instr *copy, void *mem_ctx);
2063 void nir_lower_var_copies(nir_shader *shader);
2064
2065 bool nir_lower_global_vars_to_local(nir_shader *shader);
2066
2067 bool nir_lower_indirect_derefs(nir_shader *shader, uint32_t mode_mask);
2068
2069 bool nir_lower_locals_to_regs(nir_shader *shader);
2070
2071 void nir_lower_outputs_to_temporaries(nir_shader *shader);
2072
2073 void nir_assign_var_locations(struct exec_list *var_list,
2074 unsigned *size,
2075 int (*type_size)(const struct glsl_type *));
2076
2077 void nir_lower_io(nir_shader *shader,
2078 nir_variable_mode mode,
2079 int (*type_size)(const struct glsl_type *));
2080 nir_src *nir_get_io_offset_src(nir_intrinsic_instr *instr);
2081 nir_src *nir_get_io_vertex_index_src(nir_intrinsic_instr *instr);
2082
2083 void nir_lower_vars_to_ssa(nir_shader *shader);
2084
2085 bool nir_remove_dead_variables(nir_shader *shader);
2086
2087 void nir_move_vec_src_uses_to_dest(nir_shader *shader);
2088 bool nir_lower_vec_to_movs(nir_shader *shader);
2089 void nir_lower_alu_to_scalar(nir_shader *shader);
2090 void nir_lower_load_const_to_scalar(nir_shader *shader);
2091
2092 void nir_lower_phis_to_scalar(nir_shader *shader);
2093
2094 void nir_lower_samplers(nir_shader *shader,
2095 const struct gl_shader_program *shader_program);
2096
2097 bool nir_lower_system_values(nir_shader *shader);
2098
2099 typedef struct nir_lower_tex_options {
2100 /**
2101 * bitmask of (1 << GLSL_SAMPLER_DIM_x) to control for which
2102 * sampler types a texture projector is lowered.
2103 */
2104 unsigned lower_txp;
2105
2106 /**
2107 * If true, lower rect textures to 2D, using txs to fetch the
2108 * texture dimensions and dividing the texture coords by the
2109 * texture dims to normalize.
2110 */
2111 bool lower_rect;
2112
2113 /**
2114 * To emulate certain texture wrap modes, this can be used
2115 * to saturate the specified tex coord to [0.0, 1.0]. The
2116 * bits are according to sampler #, ie. if, for example:
2117 *
2118 * (conf->saturate_s & (1 << n))
2119 *
2120 * is true, then the s coord for sampler n is saturated.
2121 *
2122 * Note that clamping must happen *after* projector lowering
2123 * so any projected texture sample instruction with a clamped
2124 * coordinate gets automatically lowered, regardless of the
2125 * 'lower_txp' setting.
2126 */
2127 unsigned saturate_s;
2128 unsigned saturate_t;
2129 unsigned saturate_r;
2130
2131 /* Bitmask of textures that need swizzling.
2132 *
2133 * If (swizzle_result & (1 << texture_index)), then the swizzle in
2134 * swizzles[texture_index] is applied to the result of the texturing
2135 * operation.
2136 */
2137 unsigned swizzle_result;
2138
2139 /* A swizzle for each texture. Values 0-3 represent x, y, z, or w swizzles
2140 * while 4 and 5 represent 0 and 1 respectively.
2141 */
2142 uint8_t swizzles[32][4];
2143 } nir_lower_tex_options;
2144
2145 bool nir_lower_tex(nir_shader *shader,
2146 const nir_lower_tex_options *options);
2147
2148 void nir_lower_idiv(nir_shader *shader);
2149
2150 void nir_lower_clip_vs(nir_shader *shader, unsigned ucp_enables);
2151 void nir_lower_clip_fs(nir_shader *shader, unsigned ucp_enables);
2152
2153 void nir_lower_two_sided_color(nir_shader *shader);
2154
2155 void nir_lower_atomics(nir_shader *shader,
2156 const struct gl_shader_program *shader_program);
2157 void nir_lower_to_source_mods(nir_shader *shader);
2158
2159 bool nir_lower_gs_intrinsics(nir_shader *shader);
2160
2161 bool nir_normalize_cubemap_coords(nir_shader *shader);
2162
2163 void nir_live_ssa_defs_impl(nir_function_impl *impl);
2164 bool nir_ssa_defs_interfere(nir_ssa_def *a, nir_ssa_def *b);
2165
2166 void nir_convert_to_ssa_impl(nir_function_impl *impl);
2167 void nir_convert_to_ssa(nir_shader *shader);
2168
2169 /* If phi_webs_only is true, only convert SSA values involved in phi nodes to
2170 * registers. If false, convert all values (even those not involved in a phi
2171 * node) to registers.
2172 */
2173 void nir_convert_from_ssa(nir_shader *shader, bool phi_webs_only);
2174
2175 bool nir_opt_algebraic(nir_shader *shader);
2176 bool nir_opt_algebraic_late(nir_shader *shader);
2177 bool nir_opt_constant_folding(nir_shader *shader);
2178
2179 bool nir_opt_global_to_local(nir_shader *shader);
2180
2181 bool nir_copy_prop(nir_shader *shader);
2182
2183 bool nir_opt_cse(nir_shader *shader);
2184
2185 bool nir_opt_dce(nir_shader *shader);
2186
2187 bool nir_opt_dead_cf(nir_shader *shader);
2188
2189 void nir_opt_gcm(nir_shader *shader);
2190
2191 bool nir_opt_peephole_select(nir_shader *shader);
2192
2193 bool nir_opt_remove_phis(nir_shader *shader);
2194
2195 bool nir_opt_undef(nir_shader *shader);
2196
2197 void nir_sweep(nir_shader *shader);
2198
2199 nir_intrinsic_op nir_intrinsic_from_system_value(gl_system_value val);
2200 gl_system_value nir_system_value_from_intrinsic(nir_intrinsic_op intrin);
2201
2202 #ifdef __cplusplus
2203 } /* extern "C" */
2204 #endif