16203af9cfb25e0c0a918e6b4b0437127c6360b5
[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_sampler_offset, /* < dynamically uniform indirect offset */
969 nir_num_tex_src_types
970 } nir_tex_src_type;
971
972 typedef struct {
973 nir_src src;
974 nir_tex_src_type src_type;
975 } nir_tex_src;
976
977 typedef enum {
978 nir_texop_tex, /**< Regular texture look-up */
979 nir_texop_txb, /**< Texture look-up with LOD bias */
980 nir_texop_txl, /**< Texture look-up with explicit LOD */
981 nir_texop_txd, /**< Texture look-up with partial derivatvies */
982 nir_texop_txf, /**< Texel fetch with explicit LOD */
983 nir_texop_txf_ms, /**< Multisample texture fetch */
984 nir_texop_txs, /**< Texture size */
985 nir_texop_lod, /**< Texture lod query */
986 nir_texop_tg4, /**< Texture gather */
987 nir_texop_query_levels, /**< Texture levels query */
988 nir_texop_texture_samples, /**< Texture samples query */
989 nir_texop_samples_identical, /**< Query whether all samples are definitely
990 * identical.
991 */
992 } nir_texop;
993
994 typedef struct {
995 nir_instr instr;
996
997 enum glsl_sampler_dim sampler_dim;
998 nir_alu_type dest_type;
999
1000 nir_texop op;
1001 nir_dest dest;
1002 nir_tex_src *src;
1003 unsigned num_srcs, coord_components;
1004 bool is_array, is_shadow;
1005
1006 /**
1007 * If is_shadow is true, whether this is the old-style shadow that outputs 4
1008 * components or the new-style shadow that outputs 1 component.
1009 */
1010 bool is_new_style_shadow;
1011
1012 /* constant offset - must be 0 if the offset source is used */
1013 int const_offset[4];
1014
1015 /* gather component selector */
1016 unsigned component : 2;
1017
1018 /** The sampler index
1019 *
1020 * If this texture instruction has a nir_tex_src_sampler_offset source,
1021 * then the sampler index is given by sampler_index + sampler_offset.
1022 */
1023 unsigned sampler_index;
1024
1025 /** The size of the sampler array or 0 if it's not an array */
1026 unsigned sampler_array_size;
1027
1028 nir_deref_var *sampler; /* if this is NULL, use sampler_index instead */
1029 } nir_tex_instr;
1030
1031 static inline unsigned
1032 nir_tex_instr_dest_size(nir_tex_instr *instr)
1033 {
1034 switch (instr->op) {
1035 case nir_texop_txs: {
1036 unsigned ret;
1037 switch (instr->sampler_dim) {
1038 case GLSL_SAMPLER_DIM_1D:
1039 case GLSL_SAMPLER_DIM_BUF:
1040 ret = 1;
1041 break;
1042 case GLSL_SAMPLER_DIM_2D:
1043 case GLSL_SAMPLER_DIM_CUBE:
1044 case GLSL_SAMPLER_DIM_MS:
1045 case GLSL_SAMPLER_DIM_RECT:
1046 case GLSL_SAMPLER_DIM_EXTERNAL:
1047 ret = 2;
1048 break;
1049 case GLSL_SAMPLER_DIM_3D:
1050 ret = 3;
1051 break;
1052 default:
1053 unreachable("not reached");
1054 }
1055 if (instr->is_array)
1056 ret++;
1057 return ret;
1058 }
1059
1060 case nir_texop_lod:
1061 return 2;
1062
1063 case nir_texop_texture_samples:
1064 case nir_texop_query_levels:
1065 case nir_texop_samples_identical:
1066 return 1;
1067
1068 default:
1069 if (instr->is_shadow && instr->is_new_style_shadow)
1070 return 1;
1071
1072 return 4;
1073 }
1074 }
1075
1076 /* Returns true if this texture operation queries something about the texture
1077 * rather than actually sampling it.
1078 */
1079 static inline bool
1080 nir_tex_instr_is_query(nir_tex_instr *instr)
1081 {
1082 switch (instr->op) {
1083 case nir_texop_txs:
1084 case nir_texop_lod:
1085 case nir_texop_texture_samples:
1086 case nir_texop_query_levels:
1087 return true;
1088 case nir_texop_tex:
1089 case nir_texop_txb:
1090 case nir_texop_txl:
1091 case nir_texop_txd:
1092 case nir_texop_txf:
1093 case nir_texop_txf_ms:
1094 case nir_texop_tg4:
1095 return false;
1096 default:
1097 unreachable("Invalid texture opcode");
1098 }
1099 }
1100
1101 static inline unsigned
1102 nir_tex_instr_src_size(nir_tex_instr *instr, unsigned src)
1103 {
1104 if (instr->src[src].src_type == nir_tex_src_coord)
1105 return instr->coord_components;
1106
1107
1108 if (instr->src[src].src_type == nir_tex_src_offset ||
1109 instr->src[src].src_type == nir_tex_src_ddx ||
1110 instr->src[src].src_type == nir_tex_src_ddy) {
1111 if (instr->is_array)
1112 return instr->coord_components - 1;
1113 else
1114 return instr->coord_components;
1115 }
1116
1117 return 1;
1118 }
1119
1120 static inline int
1121 nir_tex_instr_src_index(nir_tex_instr *instr, nir_tex_src_type type)
1122 {
1123 for (unsigned i = 0; i < instr->num_srcs; i++)
1124 if (instr->src[i].src_type == type)
1125 return (int) i;
1126
1127 return -1;
1128 }
1129
1130 typedef struct {
1131 union {
1132 float f[4];
1133 int32_t i[4];
1134 uint32_t u[4];
1135 };
1136 } nir_const_value;
1137
1138 typedef struct {
1139 nir_instr instr;
1140
1141 nir_const_value value;
1142
1143 nir_ssa_def def;
1144 } nir_load_const_instr;
1145
1146 typedef enum {
1147 nir_jump_return,
1148 nir_jump_break,
1149 nir_jump_continue,
1150 } nir_jump_type;
1151
1152 typedef struct {
1153 nir_instr instr;
1154 nir_jump_type type;
1155 } nir_jump_instr;
1156
1157 /* creates a new SSA variable in an undefined state */
1158
1159 typedef struct {
1160 nir_instr instr;
1161 nir_ssa_def def;
1162 } nir_ssa_undef_instr;
1163
1164 typedef struct {
1165 struct exec_node node;
1166
1167 /* The predecessor block corresponding to this source */
1168 struct nir_block *pred;
1169
1170 nir_src src;
1171 } nir_phi_src;
1172
1173 #define nir_foreach_phi_src(phi, entry) \
1174 foreach_list_typed(nir_phi_src, entry, node, &(phi)->srcs)
1175 #define nir_foreach_phi_src_safe(phi, entry) \
1176 foreach_list_typed_safe(nir_phi_src, entry, node, &(phi)->srcs)
1177
1178 typedef struct {
1179 nir_instr instr;
1180
1181 struct exec_list srcs; /** < list of nir_phi_src */
1182
1183 nir_dest dest;
1184 } nir_phi_instr;
1185
1186 typedef struct {
1187 struct exec_node node;
1188 nir_src src;
1189 nir_dest dest;
1190 } nir_parallel_copy_entry;
1191
1192 #define nir_foreach_parallel_copy_entry(pcopy, entry) \
1193 foreach_list_typed(nir_parallel_copy_entry, entry, node, &(pcopy)->entries)
1194
1195 typedef struct {
1196 nir_instr instr;
1197
1198 /* A list of nir_parallel_copy_entry's. The sources of all of the
1199 * entries are copied to the corresponding destinations "in parallel".
1200 * In other words, if we have two entries: a -> b and b -> a, the values
1201 * get swapped.
1202 */
1203 struct exec_list entries;
1204 } nir_parallel_copy_instr;
1205
1206 NIR_DEFINE_CAST(nir_instr_as_alu, nir_instr, nir_alu_instr, instr)
1207 NIR_DEFINE_CAST(nir_instr_as_call, nir_instr, nir_call_instr, instr)
1208 NIR_DEFINE_CAST(nir_instr_as_jump, nir_instr, nir_jump_instr, instr)
1209 NIR_DEFINE_CAST(nir_instr_as_tex, nir_instr, nir_tex_instr, instr)
1210 NIR_DEFINE_CAST(nir_instr_as_intrinsic, nir_instr, nir_intrinsic_instr, instr)
1211 NIR_DEFINE_CAST(nir_instr_as_load_const, nir_instr, nir_load_const_instr, instr)
1212 NIR_DEFINE_CAST(nir_instr_as_ssa_undef, nir_instr, nir_ssa_undef_instr, instr)
1213 NIR_DEFINE_CAST(nir_instr_as_phi, nir_instr, nir_phi_instr, instr)
1214 NIR_DEFINE_CAST(nir_instr_as_parallel_copy, nir_instr,
1215 nir_parallel_copy_instr, instr)
1216
1217 /*
1218 * Control flow
1219 *
1220 * Control flow consists of a tree of control flow nodes, which include
1221 * if-statements and loops. The leaves of the tree are basic blocks, lists of
1222 * instructions that always run start-to-finish. Each basic block also keeps
1223 * track of its successors (blocks which may run immediately after the current
1224 * block) and predecessors (blocks which could have run immediately before the
1225 * current block). Each function also has a start block and an end block which
1226 * all return statements point to (which is always empty). Together, all the
1227 * blocks with their predecessors and successors make up the control flow
1228 * graph (CFG) of the function. There are helpers that modify the tree of
1229 * control flow nodes while modifying the CFG appropriately; these should be
1230 * used instead of modifying the tree directly.
1231 */
1232
1233 typedef enum {
1234 nir_cf_node_block,
1235 nir_cf_node_if,
1236 nir_cf_node_loop,
1237 nir_cf_node_function
1238 } nir_cf_node_type;
1239
1240 typedef struct nir_cf_node {
1241 struct exec_node node;
1242 nir_cf_node_type type;
1243 struct nir_cf_node *parent;
1244 } nir_cf_node;
1245
1246 typedef struct nir_block {
1247 nir_cf_node cf_node;
1248
1249 struct exec_list instr_list; /** < list of nir_instr */
1250
1251 /** generic block index; generated by nir_index_blocks */
1252 unsigned index;
1253
1254 /*
1255 * Each block can only have up to 2 successors, so we put them in a simple
1256 * array - no need for anything more complicated.
1257 */
1258 struct nir_block *successors[2];
1259
1260 /* Set of nir_block predecessors in the CFG */
1261 struct set *predecessors;
1262
1263 /*
1264 * this node's immediate dominator in the dominance tree - set to NULL for
1265 * the start block.
1266 */
1267 struct nir_block *imm_dom;
1268
1269 /* This node's children in the dominance tree */
1270 unsigned num_dom_children;
1271 struct nir_block **dom_children;
1272
1273 /* Set of nir_block's on the dominance frontier of this block */
1274 struct set *dom_frontier;
1275
1276 /*
1277 * These two indices have the property that dom_{pre,post}_index for each
1278 * child of this block in the dominance tree will always be between
1279 * dom_pre_index and dom_post_index for this block, which makes testing if
1280 * a given block is dominated by another block an O(1) operation.
1281 */
1282 unsigned dom_pre_index, dom_post_index;
1283
1284 /* live in and out for this block; used for liveness analysis */
1285 BITSET_WORD *live_in;
1286 BITSET_WORD *live_out;
1287 } nir_block;
1288
1289 static inline nir_instr *
1290 nir_block_first_instr(nir_block *block)
1291 {
1292 struct exec_node *head = exec_list_get_head(&block->instr_list);
1293 return exec_node_data(nir_instr, head, node);
1294 }
1295
1296 static inline nir_instr *
1297 nir_block_last_instr(nir_block *block)
1298 {
1299 struct exec_node *tail = exec_list_get_tail(&block->instr_list);
1300 return exec_node_data(nir_instr, tail, node);
1301 }
1302
1303 #define nir_foreach_instr(block, instr) \
1304 foreach_list_typed(nir_instr, instr, node, &(block)->instr_list)
1305 #define nir_foreach_instr_reverse(block, instr) \
1306 foreach_list_typed_reverse(nir_instr, instr, node, &(block)->instr_list)
1307 #define nir_foreach_instr_safe(block, instr) \
1308 foreach_list_typed_safe(nir_instr, instr, node, &(block)->instr_list)
1309 #define nir_foreach_instr_reverse_safe(block, instr) \
1310 foreach_list_typed_reverse_safe(nir_instr, instr, node, &(block)->instr_list)
1311
1312 typedef struct nir_if {
1313 nir_cf_node cf_node;
1314 nir_src condition;
1315
1316 struct exec_list then_list; /** < list of nir_cf_node */
1317 struct exec_list else_list; /** < list of nir_cf_node */
1318 } nir_if;
1319
1320 static inline nir_cf_node *
1321 nir_if_first_then_node(nir_if *if_stmt)
1322 {
1323 struct exec_node *head = exec_list_get_head(&if_stmt->then_list);
1324 return exec_node_data(nir_cf_node, head, node);
1325 }
1326
1327 static inline nir_cf_node *
1328 nir_if_last_then_node(nir_if *if_stmt)
1329 {
1330 struct exec_node *tail = exec_list_get_tail(&if_stmt->then_list);
1331 return exec_node_data(nir_cf_node, tail, node);
1332 }
1333
1334 static inline nir_cf_node *
1335 nir_if_first_else_node(nir_if *if_stmt)
1336 {
1337 struct exec_node *head = exec_list_get_head(&if_stmt->else_list);
1338 return exec_node_data(nir_cf_node, head, node);
1339 }
1340
1341 static inline nir_cf_node *
1342 nir_if_last_else_node(nir_if *if_stmt)
1343 {
1344 struct exec_node *tail = exec_list_get_tail(&if_stmt->else_list);
1345 return exec_node_data(nir_cf_node, tail, node);
1346 }
1347
1348 typedef struct {
1349 nir_cf_node cf_node;
1350
1351 struct exec_list body; /** < list of nir_cf_node */
1352 } nir_loop;
1353
1354 static inline nir_cf_node *
1355 nir_loop_first_cf_node(nir_loop *loop)
1356 {
1357 return exec_node_data(nir_cf_node, exec_list_get_head(&loop->body), node);
1358 }
1359
1360 static inline nir_cf_node *
1361 nir_loop_last_cf_node(nir_loop *loop)
1362 {
1363 return exec_node_data(nir_cf_node, exec_list_get_tail(&loop->body), node);
1364 }
1365
1366 /**
1367 * Various bits of metadata that can may be created or required by
1368 * optimization and analysis passes
1369 */
1370 typedef enum {
1371 nir_metadata_none = 0x0,
1372 nir_metadata_block_index = 0x1,
1373 nir_metadata_dominance = 0x2,
1374 nir_metadata_live_ssa_defs = 0x4,
1375 nir_metadata_not_properly_reset = 0x8,
1376 } nir_metadata;
1377
1378 typedef struct {
1379 nir_cf_node cf_node;
1380
1381 /** pointer to the function of which this is an implementation */
1382 struct nir_function *function;
1383
1384 struct exec_list body; /** < list of nir_cf_node */
1385
1386 nir_block *end_block;
1387
1388 /** list for all local variables in the function */
1389 struct exec_list locals;
1390
1391 /** array of variables used as parameters */
1392 unsigned num_params;
1393 nir_variable **params;
1394
1395 /** variable used to hold the result of the function */
1396 nir_variable *return_var;
1397
1398 /** list of local registers in the function */
1399 struct exec_list registers;
1400
1401 /** next available local register index */
1402 unsigned reg_alloc;
1403
1404 /** next available SSA value index */
1405 unsigned ssa_alloc;
1406
1407 /* total number of basic blocks, only valid when block_index_dirty = false */
1408 unsigned num_blocks;
1409
1410 nir_metadata valid_metadata;
1411 } nir_function_impl;
1412
1413 static inline nir_block *
1414 nir_start_block(nir_function_impl *impl)
1415 {
1416 return (nir_block *) exec_list_get_head(&impl->body);
1417 }
1418
1419 static inline nir_cf_node *
1420 nir_cf_node_next(nir_cf_node *node)
1421 {
1422 struct exec_node *next = exec_node_get_next(&node->node);
1423 if (exec_node_is_tail_sentinel(next))
1424 return NULL;
1425 else
1426 return exec_node_data(nir_cf_node, next, node);
1427 }
1428
1429 static inline nir_cf_node *
1430 nir_cf_node_prev(nir_cf_node *node)
1431 {
1432 struct exec_node *prev = exec_node_get_prev(&node->node);
1433 if (exec_node_is_head_sentinel(prev))
1434 return NULL;
1435 else
1436 return exec_node_data(nir_cf_node, prev, node);
1437 }
1438
1439 static inline bool
1440 nir_cf_node_is_first(const nir_cf_node *node)
1441 {
1442 return exec_node_is_head_sentinel(node->node.prev);
1443 }
1444
1445 static inline bool
1446 nir_cf_node_is_last(const nir_cf_node *node)
1447 {
1448 return exec_node_is_tail_sentinel(node->node.next);
1449 }
1450
1451 NIR_DEFINE_CAST(nir_cf_node_as_block, nir_cf_node, nir_block, cf_node)
1452 NIR_DEFINE_CAST(nir_cf_node_as_if, nir_cf_node, nir_if, cf_node)
1453 NIR_DEFINE_CAST(nir_cf_node_as_loop, nir_cf_node, nir_loop, cf_node)
1454 NIR_DEFINE_CAST(nir_cf_node_as_function, nir_cf_node, nir_function_impl, cf_node)
1455
1456 typedef enum {
1457 nir_parameter_in,
1458 nir_parameter_out,
1459 nir_parameter_inout,
1460 } nir_parameter_type;
1461
1462 typedef struct {
1463 nir_parameter_type param_type;
1464 const struct glsl_type *type;
1465 } nir_parameter;
1466
1467 typedef struct nir_function {
1468 struct exec_node node;
1469
1470 const char *name;
1471 struct nir_shader *shader;
1472
1473 unsigned num_params;
1474 nir_parameter *params;
1475 const struct glsl_type *return_type;
1476
1477 /** The implementation of this function.
1478 *
1479 * If the function is only declared and not implemented, this is NULL.
1480 */
1481 nir_function_impl *impl;
1482 } nir_function;
1483
1484 typedef struct nir_shader_compiler_options {
1485 bool lower_fdiv;
1486 bool lower_ffma;
1487 bool lower_flrp;
1488 bool lower_fpow;
1489 bool lower_fsat;
1490 bool lower_fsqrt;
1491 bool lower_fmod;
1492 bool lower_bitfield_extract;
1493 bool lower_bitfield_insert;
1494 bool lower_uadd_carry;
1495 bool lower_usub_borrow;
1496 /** lowers fneg and ineg to fsub and isub. */
1497 bool lower_negate;
1498 /** lowers fsub and isub to fadd+fneg and iadd+ineg. */
1499 bool lower_sub;
1500
1501 /* lower {slt,sge,seq,sne} to {flt,fge,feq,fne} + b2f: */
1502 bool lower_scmp;
1503
1504 /* Does the native fdot instruction replicate its result for four
1505 * components? If so, then opt_algebraic_late will turn all fdotN
1506 * instructions into fdot_replicatedN instructions.
1507 */
1508 bool fdot_replicates;
1509
1510 /** lowers ffract to fsub+ffloor: */
1511 bool lower_ffract;
1512
1513 bool lower_pack_half_2x16;
1514 bool lower_pack_unorm_2x16;
1515 bool lower_pack_snorm_2x16;
1516 bool lower_pack_unorm_4x8;
1517 bool lower_pack_snorm_4x8;
1518 bool lower_unpack_half_2x16;
1519 bool lower_unpack_unorm_2x16;
1520 bool lower_unpack_snorm_2x16;
1521 bool lower_unpack_unorm_4x8;
1522 bool lower_unpack_snorm_4x8;
1523
1524 bool lower_extract_byte;
1525 bool lower_extract_word;
1526
1527 /**
1528 * Does the driver support real 32-bit integers? (Otherwise, integers
1529 * are simulated by floats.)
1530 */
1531 bool native_integers;
1532 } nir_shader_compiler_options;
1533
1534 typedef struct nir_shader_info {
1535 const char *name;
1536
1537 /* Descriptive name provided by the client; may be NULL */
1538 const char *label;
1539
1540 /* Number of textures used by this shader */
1541 unsigned num_textures;
1542 /* Number of uniform buffers used by this shader */
1543 unsigned num_ubos;
1544 /* Number of atomic buffers used by this shader */
1545 unsigned num_abos;
1546 /* Number of shader storage buffers used by this shader */
1547 unsigned num_ssbos;
1548 /* Number of images used by this shader */
1549 unsigned num_images;
1550
1551 /* Which inputs are actually read */
1552 uint64_t inputs_read;
1553 /* Which outputs are actually written */
1554 uint64_t outputs_written;
1555 /* Which system values are actually read */
1556 uint64_t system_values_read;
1557
1558 /* Which patch inputs are actually read */
1559 uint32_t patch_inputs_read;
1560 /* Which patch outputs are actually written */
1561 uint32_t patch_outputs_written;
1562
1563 /* Whether or not this shader ever uses textureGather() */
1564 bool uses_texture_gather;
1565
1566 /* Whether or not this shader uses the gl_ClipDistance output */
1567 bool uses_clip_distance_out;
1568
1569 /* Whether or not separate shader objects were used */
1570 bool separate_shader;
1571
1572 /** Was this shader linked with any transform feedback varyings? */
1573 bool has_transform_feedback_varyings;
1574
1575 union {
1576 struct {
1577 /** The number of vertices recieves per input primitive */
1578 unsigned vertices_in;
1579
1580 /** The output primitive type (GL enum value) */
1581 unsigned output_primitive;
1582
1583 /** The maximum number of vertices the geometry shader might write. */
1584 unsigned vertices_out;
1585
1586 /** 1 .. MAX_GEOMETRY_SHADER_INVOCATIONS */
1587 unsigned invocations;
1588
1589 /** Whether or not this shader uses EndPrimitive */
1590 bool uses_end_primitive;
1591
1592 /** Whether or not this shader uses non-zero streams */
1593 bool uses_streams;
1594 } gs;
1595
1596 struct {
1597 bool uses_discard;
1598
1599 /**
1600 * Whether early fragment tests are enabled as defined by
1601 * ARB_shader_image_load_store.
1602 */
1603 bool early_fragment_tests;
1604
1605 /** gl_FragDepth layout for ARB_conservative_depth. */
1606 enum gl_frag_depth_layout depth_layout;
1607 } fs;
1608
1609 struct {
1610 unsigned local_size[3];
1611 } cs;
1612
1613 struct {
1614 /** The number of vertices in the TCS output patch. */
1615 unsigned vertices_out;
1616 } tcs;
1617 };
1618 } nir_shader_info;
1619
1620 typedef struct nir_shader {
1621 /** list of uniforms (nir_variable) */
1622 struct exec_list uniforms;
1623
1624 /** list of inputs (nir_variable) */
1625 struct exec_list inputs;
1626
1627 /** list of outputs (nir_variable) */
1628 struct exec_list outputs;
1629
1630 /** Set of driver-specific options for the shader.
1631 *
1632 * The memory for the options is expected to be kept in a single static
1633 * copy by the driver.
1634 */
1635 const struct nir_shader_compiler_options *options;
1636
1637 /** Various bits of compile-time information about a given shader */
1638 struct nir_shader_info info;
1639
1640 /** list of global variables in the shader (nir_variable) */
1641 struct exec_list globals;
1642
1643 /** list of system value variables in the shader (nir_variable) */
1644 struct exec_list system_values;
1645
1646 struct exec_list functions; /** < list of nir_function */
1647
1648 /** list of global register in the shader */
1649 struct exec_list registers;
1650
1651 /** next available global register index */
1652 unsigned reg_alloc;
1653
1654 /**
1655 * the highest index a load_input_*, load_uniform_*, etc. intrinsic can
1656 * access plus one
1657 */
1658 unsigned num_inputs, num_uniforms, num_outputs;
1659
1660 /** The shader stage, such as MESA_SHADER_VERTEX. */
1661 gl_shader_stage stage;
1662 } nir_shader;
1663
1664 #define nir_foreach_function(shader, func) \
1665 foreach_list_typed(nir_function, func, node, &(shader)->functions)
1666
1667 nir_shader *nir_shader_create(void *mem_ctx,
1668 gl_shader_stage stage,
1669 const nir_shader_compiler_options *options);
1670
1671 /** creates a register, including assigning it an index and adding it to the list */
1672 nir_register *nir_global_reg_create(nir_shader *shader);
1673
1674 nir_register *nir_local_reg_create(nir_function_impl *impl);
1675
1676 void nir_reg_remove(nir_register *reg);
1677
1678 /** Adds a variable to the appropreate list in nir_shader */
1679 void nir_shader_add_variable(nir_shader *shader, nir_variable *var);
1680
1681 static inline void
1682 nir_function_impl_add_variable(nir_function_impl *impl, nir_variable *var)
1683 {
1684 assert(var->data.mode == nir_var_local);
1685 exec_list_push_tail(&impl->locals, &var->node);
1686 }
1687
1688 /** creates a variable, sets a few defaults, and adds it to the list */
1689 nir_variable *nir_variable_create(nir_shader *shader,
1690 nir_variable_mode mode,
1691 const struct glsl_type *type,
1692 const char *name);
1693 /** creates a local variable and adds it to the list */
1694 nir_variable *nir_local_variable_create(nir_function_impl *impl,
1695 const struct glsl_type *type,
1696 const char *name);
1697
1698 /** creates a function and adds it to the shader's list of functions */
1699 nir_function *nir_function_create(nir_shader *shader, const char *name);
1700
1701 nir_function_impl *nir_function_impl_create(nir_function *func);
1702
1703 nir_block *nir_block_create(nir_shader *shader);
1704 nir_if *nir_if_create(nir_shader *shader);
1705 nir_loop *nir_loop_create(nir_shader *shader);
1706
1707 nir_function_impl *nir_cf_node_get_function(nir_cf_node *node);
1708
1709 /** requests that the given pieces of metadata be generated */
1710 void nir_metadata_require(nir_function_impl *impl, nir_metadata required);
1711 /** dirties all but the preserved metadata */
1712 void nir_metadata_preserve(nir_function_impl *impl, nir_metadata preserved);
1713
1714 /** creates an instruction with default swizzle/writemask/etc. with NULL registers */
1715 nir_alu_instr *nir_alu_instr_create(nir_shader *shader, nir_op op);
1716
1717 nir_jump_instr *nir_jump_instr_create(nir_shader *shader, nir_jump_type type);
1718
1719 nir_load_const_instr *nir_load_const_instr_create(nir_shader *shader,
1720 unsigned num_components);
1721
1722 nir_intrinsic_instr *nir_intrinsic_instr_create(nir_shader *shader,
1723 nir_intrinsic_op op);
1724
1725 nir_call_instr *nir_call_instr_create(nir_shader *shader,
1726 nir_function *callee);
1727
1728 nir_tex_instr *nir_tex_instr_create(nir_shader *shader, unsigned num_srcs);
1729
1730 nir_phi_instr *nir_phi_instr_create(nir_shader *shader);
1731
1732 nir_parallel_copy_instr *nir_parallel_copy_instr_create(nir_shader *shader);
1733
1734 nir_ssa_undef_instr *nir_ssa_undef_instr_create(nir_shader *shader,
1735 unsigned num_components);
1736
1737 nir_deref_var *nir_deref_var_create(void *mem_ctx, nir_variable *var);
1738 nir_deref_array *nir_deref_array_create(void *mem_ctx);
1739 nir_deref_struct *nir_deref_struct_create(void *mem_ctx, unsigned field_index);
1740
1741 nir_deref *nir_copy_deref(void *mem_ctx, nir_deref *deref);
1742
1743 nir_load_const_instr *
1744 nir_deref_get_const_initializer_load(nir_shader *shader, nir_deref_var *deref);
1745
1746 /**
1747 * NIR Cursors and Instruction Insertion API
1748 * @{
1749 *
1750 * A tiny struct representing a point to insert/extract instructions or
1751 * control flow nodes. Helps reduce the combinatorial explosion of possible
1752 * points to insert/extract.
1753 *
1754 * \sa nir_control_flow.h
1755 */
1756 typedef enum {
1757 nir_cursor_before_block,
1758 nir_cursor_after_block,
1759 nir_cursor_before_instr,
1760 nir_cursor_after_instr,
1761 } nir_cursor_option;
1762
1763 typedef struct {
1764 nir_cursor_option option;
1765 union {
1766 nir_block *block;
1767 nir_instr *instr;
1768 };
1769 } nir_cursor;
1770
1771 static inline nir_cursor
1772 nir_before_block(nir_block *block)
1773 {
1774 nir_cursor cursor;
1775 cursor.option = nir_cursor_before_block;
1776 cursor.block = block;
1777 return cursor;
1778 }
1779
1780 static inline nir_cursor
1781 nir_after_block(nir_block *block)
1782 {
1783 nir_cursor cursor;
1784 cursor.option = nir_cursor_after_block;
1785 cursor.block = block;
1786 return cursor;
1787 }
1788
1789 static inline nir_cursor
1790 nir_before_instr(nir_instr *instr)
1791 {
1792 nir_cursor cursor;
1793 cursor.option = nir_cursor_before_instr;
1794 cursor.instr = instr;
1795 return cursor;
1796 }
1797
1798 static inline nir_cursor
1799 nir_after_instr(nir_instr *instr)
1800 {
1801 nir_cursor cursor;
1802 cursor.option = nir_cursor_after_instr;
1803 cursor.instr = instr;
1804 return cursor;
1805 }
1806
1807 static inline nir_cursor
1808 nir_after_block_before_jump(nir_block *block)
1809 {
1810 nir_instr *last_instr = nir_block_last_instr(block);
1811 if (last_instr && last_instr->type == nir_instr_type_jump) {
1812 return nir_before_instr(last_instr);
1813 } else {
1814 return nir_after_block(block);
1815 }
1816 }
1817
1818 static inline nir_cursor
1819 nir_before_cf_node(nir_cf_node *node)
1820 {
1821 if (node->type == nir_cf_node_block)
1822 return nir_before_block(nir_cf_node_as_block(node));
1823
1824 return nir_after_block(nir_cf_node_as_block(nir_cf_node_prev(node)));
1825 }
1826
1827 static inline nir_cursor
1828 nir_after_cf_node(nir_cf_node *node)
1829 {
1830 if (node->type == nir_cf_node_block)
1831 return nir_after_block(nir_cf_node_as_block(node));
1832
1833 return nir_before_block(nir_cf_node_as_block(nir_cf_node_next(node)));
1834 }
1835
1836 static inline nir_cursor
1837 nir_before_cf_list(struct exec_list *cf_list)
1838 {
1839 nir_cf_node *first_node = exec_node_data(nir_cf_node,
1840 exec_list_get_head(cf_list), node);
1841 return nir_before_cf_node(first_node);
1842 }
1843
1844 static inline nir_cursor
1845 nir_after_cf_list(struct exec_list *cf_list)
1846 {
1847 nir_cf_node *last_node = exec_node_data(nir_cf_node,
1848 exec_list_get_tail(cf_list), node);
1849 return nir_after_cf_node(last_node);
1850 }
1851
1852 /**
1853 * Insert a NIR instruction at the given cursor.
1854 *
1855 * Note: This does not update the cursor.
1856 */
1857 void nir_instr_insert(nir_cursor cursor, nir_instr *instr);
1858
1859 static inline void
1860 nir_instr_insert_before(nir_instr *instr, nir_instr *before)
1861 {
1862 nir_instr_insert(nir_before_instr(instr), before);
1863 }
1864
1865 static inline void
1866 nir_instr_insert_after(nir_instr *instr, nir_instr *after)
1867 {
1868 nir_instr_insert(nir_after_instr(instr), after);
1869 }
1870
1871 static inline void
1872 nir_instr_insert_before_block(nir_block *block, nir_instr *before)
1873 {
1874 nir_instr_insert(nir_before_block(block), before);
1875 }
1876
1877 static inline void
1878 nir_instr_insert_after_block(nir_block *block, nir_instr *after)
1879 {
1880 nir_instr_insert(nir_after_block(block), after);
1881 }
1882
1883 static inline void
1884 nir_instr_insert_before_cf(nir_cf_node *node, nir_instr *before)
1885 {
1886 nir_instr_insert(nir_before_cf_node(node), before);
1887 }
1888
1889 static inline void
1890 nir_instr_insert_after_cf(nir_cf_node *node, nir_instr *after)
1891 {
1892 nir_instr_insert(nir_after_cf_node(node), after);
1893 }
1894
1895 static inline void
1896 nir_instr_insert_before_cf_list(struct exec_list *list, nir_instr *before)
1897 {
1898 nir_instr_insert(nir_before_cf_list(list), before);
1899 }
1900
1901 static inline void
1902 nir_instr_insert_after_cf_list(struct exec_list *list, nir_instr *after)
1903 {
1904 nir_instr_insert(nir_after_cf_list(list), after);
1905 }
1906
1907 void nir_instr_remove(nir_instr *instr);
1908
1909 /** @} */
1910
1911 typedef bool (*nir_foreach_ssa_def_cb)(nir_ssa_def *def, void *state);
1912 typedef bool (*nir_foreach_dest_cb)(nir_dest *dest, void *state);
1913 typedef bool (*nir_foreach_src_cb)(nir_src *src, void *state);
1914 bool nir_foreach_ssa_def(nir_instr *instr, nir_foreach_ssa_def_cb cb,
1915 void *state);
1916 bool nir_foreach_dest(nir_instr *instr, nir_foreach_dest_cb cb, void *state);
1917 bool nir_foreach_src(nir_instr *instr, nir_foreach_src_cb cb, void *state);
1918
1919 nir_const_value *nir_src_as_const_value(nir_src src);
1920 bool nir_src_is_dynamically_uniform(nir_src src);
1921 bool nir_srcs_equal(nir_src src1, nir_src src2);
1922 void nir_instr_rewrite_src(nir_instr *instr, nir_src *src, nir_src new_src);
1923 void nir_instr_move_src(nir_instr *dest_instr, nir_src *dest, nir_src *src);
1924 void nir_if_rewrite_condition(nir_if *if_stmt, nir_src new_src);
1925 void nir_instr_rewrite_dest(nir_instr *instr, nir_dest *dest,
1926 nir_dest new_dest);
1927
1928 void nir_ssa_dest_init(nir_instr *instr, nir_dest *dest,
1929 unsigned num_components, const char *name);
1930 void nir_ssa_def_init(nir_instr *instr, nir_ssa_def *def,
1931 unsigned num_components, const char *name);
1932 void nir_ssa_def_rewrite_uses(nir_ssa_def *def, nir_src new_src);
1933 void nir_ssa_def_rewrite_uses_after(nir_ssa_def *def, nir_src new_src,
1934 nir_instr *after_me);
1935
1936 /* visits basic blocks in source-code order */
1937 typedef bool (*nir_foreach_block_cb)(nir_block *block, void *state);
1938 bool nir_foreach_block(nir_function_impl *impl, nir_foreach_block_cb cb,
1939 void *state);
1940 bool nir_foreach_block_reverse(nir_function_impl *impl, nir_foreach_block_cb cb,
1941 void *state);
1942 bool nir_foreach_block_in_cf_node(nir_cf_node *node, nir_foreach_block_cb cb,
1943 void *state);
1944
1945 /* If the following CF node is an if, this function returns that if.
1946 * Otherwise, it returns NULL.
1947 */
1948 nir_if *nir_block_get_following_if(nir_block *block);
1949
1950 nir_loop *nir_block_get_following_loop(nir_block *block);
1951
1952 void nir_index_local_regs(nir_function_impl *impl);
1953 void nir_index_global_regs(nir_shader *shader);
1954 void nir_index_ssa_defs(nir_function_impl *impl);
1955 unsigned nir_index_instrs(nir_function_impl *impl);
1956
1957 void nir_index_blocks(nir_function_impl *impl);
1958
1959 void nir_print_shader(nir_shader *shader, FILE *fp);
1960 void nir_print_instr(const nir_instr *instr, FILE *fp);
1961
1962 nir_shader * nir_shader_clone(void *mem_ctx, const nir_shader *s);
1963
1964 #ifdef DEBUG
1965 void nir_validate_shader(nir_shader *shader);
1966 void nir_metadata_set_validation_flag(nir_shader *shader);
1967 void nir_metadata_check_validation_flag(nir_shader *shader);
1968
1969 #include "util/debug.h"
1970 static inline bool
1971 should_clone_nir(void)
1972 {
1973 static int should_clone = -1;
1974 if (should_clone < 0)
1975 should_clone = env_var_as_boolean("NIR_TEST_CLONE", false);
1976
1977 return should_clone;
1978 }
1979 #else
1980 static inline void nir_validate_shader(nir_shader *shader) { (void) shader; }
1981 static inline void nir_metadata_set_validation_flag(nir_shader *shader) { (void) shader; }
1982 static inline void nir_metadata_check_validation_flag(nir_shader *shader) { (void) shader; }
1983 static inline bool should_clone_nir(void) { return false; }
1984 #endif /* DEBUG */
1985
1986 #define _PASS(nir, do_pass) do { \
1987 do_pass \
1988 nir_validate_shader(nir); \
1989 if (should_clone_nir()) { \
1990 nir_shader *clone = nir_shader_clone(ralloc_parent(nir), nir); \
1991 ralloc_free(nir); \
1992 nir = clone; \
1993 } \
1994 } while (0)
1995
1996 #define NIR_PASS(progress, nir, pass, ...) _PASS(nir, \
1997 nir_metadata_set_validation_flag(nir); \
1998 if (pass(nir, ##__VA_ARGS__)) { \
1999 progress = true; \
2000 nir_metadata_check_validation_flag(nir); \
2001 } \
2002 )
2003
2004 #define NIR_PASS_V(nir, pass, ...) _PASS(nir, \
2005 pass(nir, ##__VA_ARGS__); \
2006 )
2007
2008 void nir_calc_dominance_impl(nir_function_impl *impl);
2009 void nir_calc_dominance(nir_shader *shader);
2010
2011 nir_block *nir_dominance_lca(nir_block *b1, nir_block *b2);
2012 bool nir_block_dominates(nir_block *parent, nir_block *child);
2013
2014 void nir_dump_dom_tree_impl(nir_function_impl *impl, FILE *fp);
2015 void nir_dump_dom_tree(nir_shader *shader, FILE *fp);
2016
2017 void nir_dump_dom_frontier_impl(nir_function_impl *impl, FILE *fp);
2018 void nir_dump_dom_frontier(nir_shader *shader, FILE *fp);
2019
2020 void nir_dump_cfg_impl(nir_function_impl *impl, FILE *fp);
2021 void nir_dump_cfg(nir_shader *shader, FILE *fp);
2022
2023 int nir_gs_count_vertices(const nir_shader *shader);
2024
2025 bool nir_split_var_copies(nir_shader *shader);
2026
2027 void nir_lower_var_copy_instr(nir_intrinsic_instr *copy, void *mem_ctx);
2028 void nir_lower_var_copies(nir_shader *shader);
2029
2030 bool nir_lower_global_vars_to_local(nir_shader *shader);
2031
2032 bool nir_lower_locals_to_regs(nir_shader *shader);
2033
2034 void nir_lower_outputs_to_temporaries(nir_shader *shader);
2035
2036 void nir_assign_var_locations(struct exec_list *var_list,
2037 unsigned *size,
2038 int (*type_size)(const struct glsl_type *));
2039
2040 void nir_lower_io(nir_shader *shader,
2041 nir_variable_mode mode,
2042 int (*type_size)(const struct glsl_type *));
2043 nir_src *nir_get_io_offset_src(nir_intrinsic_instr *instr);
2044 nir_src *nir_get_io_vertex_index_src(nir_intrinsic_instr *instr);
2045
2046 void nir_lower_vars_to_ssa(nir_shader *shader);
2047
2048 bool nir_remove_dead_variables(nir_shader *shader);
2049
2050 void nir_move_vec_src_uses_to_dest(nir_shader *shader);
2051 bool nir_lower_vec_to_movs(nir_shader *shader);
2052 void nir_lower_alu_to_scalar(nir_shader *shader);
2053 void nir_lower_load_const_to_scalar(nir_shader *shader);
2054
2055 void nir_lower_phis_to_scalar(nir_shader *shader);
2056
2057 void nir_lower_samplers(nir_shader *shader,
2058 const struct gl_shader_program *shader_program);
2059
2060 bool nir_lower_system_values(nir_shader *shader);
2061
2062 typedef struct nir_lower_tex_options {
2063 /**
2064 * bitmask of (1 << GLSL_SAMPLER_DIM_x) to control for which
2065 * sampler types a texture projector is lowered.
2066 */
2067 unsigned lower_txp;
2068
2069 /**
2070 * If true, lower rect textures to 2D, using txs to fetch the
2071 * texture dimensions and dividing the texture coords by the
2072 * texture dims to normalize.
2073 */
2074 bool lower_rect;
2075
2076 /**
2077 * To emulate certain texture wrap modes, this can be used
2078 * to saturate the specified tex coord to [0.0, 1.0]. The
2079 * bits are according to sampler #, ie. if, for example:
2080 *
2081 * (conf->saturate_s & (1 << n))
2082 *
2083 * is true, then the s coord for sampler n is saturated.
2084 *
2085 * Note that clamping must happen *after* projector lowering
2086 * so any projected texture sample instruction with a clamped
2087 * coordinate gets automatically lowered, regardless of the
2088 * 'lower_txp' setting.
2089 */
2090 unsigned saturate_s;
2091 unsigned saturate_t;
2092 unsigned saturate_r;
2093
2094 /* Bitmask of samplers that need swizzling.
2095 *
2096 * If (swizzle_result & (1 << sampler_index)), then the swizzle in
2097 * swizzles[sampler_index] is applied to the result of the texturing
2098 * operation.
2099 */
2100 unsigned swizzle_result;
2101
2102 /* A swizzle for each sampler. Values 0-3 represent x, y, z, or w swizzles
2103 * while 4 and 5 represent 0 and 1 respectively.
2104 */
2105 uint8_t swizzles[32][4];
2106 } nir_lower_tex_options;
2107
2108 bool nir_lower_tex(nir_shader *shader,
2109 const nir_lower_tex_options *options);
2110
2111 void nir_lower_idiv(nir_shader *shader);
2112
2113 void nir_lower_clip_vs(nir_shader *shader, unsigned ucp_enables);
2114 void nir_lower_clip_fs(nir_shader *shader, unsigned ucp_enables);
2115
2116 void nir_lower_two_sided_color(nir_shader *shader);
2117
2118 void nir_lower_atomics(nir_shader *shader,
2119 const struct gl_shader_program *shader_program);
2120 void nir_lower_to_source_mods(nir_shader *shader);
2121
2122 bool nir_lower_gs_intrinsics(nir_shader *shader);
2123
2124 bool nir_normalize_cubemap_coords(nir_shader *shader);
2125
2126 void nir_live_ssa_defs_impl(nir_function_impl *impl);
2127 bool nir_ssa_defs_interfere(nir_ssa_def *a, nir_ssa_def *b);
2128
2129 void nir_convert_to_ssa_impl(nir_function_impl *impl);
2130 void nir_convert_to_ssa(nir_shader *shader);
2131
2132 /* If phi_webs_only is true, only convert SSA values involved in phi nodes to
2133 * registers. If false, convert all values (even those not involved in a phi
2134 * node) to registers.
2135 */
2136 void nir_convert_from_ssa(nir_shader *shader, bool phi_webs_only);
2137
2138 bool nir_opt_algebraic(nir_shader *shader);
2139 bool nir_opt_algebraic_late(nir_shader *shader);
2140 bool nir_opt_constant_folding(nir_shader *shader);
2141
2142 bool nir_opt_global_to_local(nir_shader *shader);
2143
2144 bool nir_copy_prop(nir_shader *shader);
2145
2146 bool nir_opt_cse(nir_shader *shader);
2147
2148 bool nir_opt_dce(nir_shader *shader);
2149
2150 bool nir_opt_dead_cf(nir_shader *shader);
2151
2152 void nir_opt_gcm(nir_shader *shader);
2153
2154 bool nir_opt_peephole_select(nir_shader *shader);
2155
2156 bool nir_opt_remove_phis(nir_shader *shader);
2157
2158 bool nir_opt_undef(nir_shader *shader);
2159
2160 void nir_sweep(nir_shader *shader);
2161
2162 nir_intrinsic_op nir_intrinsic_from_system_value(gl_system_value val);
2163 gl_system_value nir_system_value_from_intrinsic(nir_intrinsic_op intrin);
2164
2165 #ifdef __cplusplus
2166 } /* extern "C" */
2167 #endif