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