3 * Copyright © 2010 Intel Corporation
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
37 #include "ir_visitor.h"
38 #include "ir_hierarchical_visitor.h"
41 #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
50 ir_type_dereference_array,
51 ir_type_dereference_record,
52 ir_type_dereference_variable,
56 ir_type_function_signature,
63 ir_type_max /**< maximum ir_type enum number, for validation */
67 * Base class of all IR instructions
69 class ir_instruction : public exec_node {
71 enum ir_node_type ir_type;
72 const struct glsl_type *type;
74 /** ir_print_visitor helper for debugging. */
75 void print(void) const;
77 virtual void accept(ir_visitor *) = 0;
78 virtual ir_visitor_status accept(ir_hierarchical_visitor *) = 0;
79 virtual ir_instruction *clone(void *mem_ctx,
80 struct hash_table *ht) const = 0;
83 * \name IR instruction downcast functions
85 * These functions either cast the object to a derived class or return
86 * \c NULL if the object's type does not match the specified derived class.
87 * Additional downcast functions will be added as needed.
90 virtual class ir_variable * as_variable() { return NULL; }
91 virtual class ir_function * as_function() { return NULL; }
92 virtual class ir_dereference * as_dereference() { return NULL; }
93 virtual class ir_dereference_array * as_dereference_array() { return NULL; }
94 virtual class ir_dereference_variable *as_dereference_variable() { return NULL; }
95 virtual class ir_expression * as_expression() { return NULL; }
96 virtual class ir_rvalue * as_rvalue() { return NULL; }
97 virtual class ir_loop * as_loop() { return NULL; }
98 virtual class ir_assignment * as_assignment() { return NULL; }
99 virtual class ir_call * as_call() { return NULL; }
100 virtual class ir_return * as_return() { return NULL; }
101 virtual class ir_if * as_if() { return NULL; }
102 virtual class ir_swizzle * as_swizzle() { return NULL; }
103 virtual class ir_constant * as_constant() { return NULL; }
109 ir_type = ir_type_unset;
115 class ir_rvalue : public ir_instruction {
117 virtual ir_rvalue *clone(void *mem_ctx, struct hash_table *) const = 0;
119 virtual ir_constant *constant_expression_value() = 0;
121 virtual ir_rvalue * as_rvalue()
126 virtual bool is_lvalue()
132 * Get the variable that is ultimately referenced by an r-value
134 virtual ir_variable *variable_referenced()
141 * If an r-value is a reference to a whole variable, get that variable
144 * Pointer to a variable that is completely dereferenced by the r-value. If
145 * the r-value is not a dereference or the dereference does not access the
146 * entire variable (i.e., it's just one array element, struct field), \c NULL
149 virtual ir_variable *whole_variable_referenced()
159 enum ir_variable_mode {
165 ir_var_temporary /**< Temporary variable generated during compilation. */
168 enum ir_variable_interpolation {
175 class ir_variable : public ir_instruction {
177 ir_variable(const struct glsl_type *, const char *, ir_variable_mode);
179 virtual ir_variable *clone(void *mem_ctx, struct hash_table *ht) const;
181 virtual ir_variable *as_variable()
186 virtual void accept(ir_visitor *v)
191 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
195 * Get the string value for the interpolation qualifier
197 * \return The string that would be used in a shader to specify \c
198 * mode will be returned.
200 * This function should only be used on a shader input or output variable.
202 const char *interpolation_string() const;
205 * Calculate the number of slots required to hold this variable
207 * This is used to determine how many uniform or varying locations a variable
208 * occupies. The count is in units of floating point components.
210 unsigned component_slots() const;
215 * Highest element accessed with a constant expression array index
217 * Not used for non-array variables.
219 unsigned max_array_access;
221 unsigned read_only:1;
223 unsigned invariant:1;
226 unsigned interpolation:2;
229 * Flag that the whole array is assignable
231 * In GLSL 1.20 and later whole arrays are assignable (and comparable for
232 * equality). This flag enables this behavior.
234 unsigned array_lvalue:1;
236 /* ARB_fragment_coord_conventions */
237 unsigned origin_upper_left:1;
238 unsigned pixel_center_integer:1;
241 * Storage location of the base of this variable
243 * The precise meaning of this field depends on the nature of the variable.
245 * - Vertex shader input: one of the values from \c gl_vert_attrib.
246 * - Vertex shader output: one of the values from \c gl_vert_result.
247 * - Fragment shader input: one of the values from \c gl_frag_attrib.
248 * - Fragment shader output: one of the values from \c gl_frag_result.
249 * - Uniforms: Per-stage uniform slot number.
250 * - Other: This field is not currently used.
252 * If the variable is a uniform, shader input, or shader output, and the
253 * slot has not been assigned, the value will be -1.
258 * Emit a warning if this variable is accessed.
260 const char *warn_extension;
263 * Value assigned in the initializer of a variable declared "const"
265 ir_constant *constant_value;
271 * The representation of a function instance; may be the full definition or
272 * simply a prototype.
274 class ir_function_signature : public ir_instruction {
275 /* An ir_function_signature will be part of the list of signatures in
279 ir_function_signature(const glsl_type *return_type);
281 virtual ir_function_signature *clone(void *mem_ctx,
282 struct hash_table *ht) const;
284 virtual void accept(ir_visitor *v)
289 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
292 * Get the name of the function for which this is a signature
294 const char *function_name() const;
297 * Get a handle to the function for which this is a signature
299 * There is no setter function, this function returns a \c const pointer,
300 * and \c ir_function_signature::_function is private for a reason. The
301 * only way to make a connection between a function and function signature
302 * is via \c ir_function::add_signature. This helps ensure that certain
303 * invariants (i.e., a function signature is in the list of signatures for
304 * its \c _function) are met.
306 * \sa ir_function::add_signature
308 inline const class ir_function *function() const
310 return this->_function;
314 * Check whether the qualifiers match between this signature's parameters
315 * and the supplied parameter list. If not, returns the name of the first
316 * parameter with mismatched qualifiers (for use in error messages).
318 const char *qualifiers_match(exec_list *params);
321 * Replace the current parameter list with the given one. This is useful
322 * if the current information came from a prototype, and either has invalid
323 * or missing parameter names.
325 void replace_parameters(exec_list *new_params);
328 * Function return type.
330 * \note This discards the optional precision qualifier.
332 const struct glsl_type *return_type;
335 * List of ir_variable of function parameters.
337 * This represents the storage. The paramaters passed in a particular
338 * call will be in ir_call::actual_paramaters.
340 struct exec_list parameters;
342 /** Whether or not this function has a body (which may be empty). */
343 unsigned is_defined:1;
345 /** Whether or not this function signature is a built-in. */
346 unsigned is_builtin:1;
348 /** Body of instructions in the function. */
349 struct exec_list body;
352 /** Function of which this signature is one overload. */
353 class ir_function *_function;
355 friend class ir_function;
360 * Header for tracking multiple overloaded functions with the same name.
361 * Contains a list of ir_function_signatures representing each of the
364 class ir_function : public ir_instruction {
366 ir_function(const char *name);
368 virtual ir_function *clone(void *mem_ctx, struct hash_table *ht) const;
370 virtual ir_function *as_function()
375 virtual void accept(ir_visitor *v)
380 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
382 void add_signature(ir_function_signature *sig)
384 sig->_function = this;
385 this->signatures.push_tail(sig);
389 * Get an iterator for the set of function signatures
391 exec_list_iterator iterator()
393 return signatures.iterator();
397 * Find a signature that matches a set of actual parameters, taking implicit
398 * conversions into account.
400 ir_function_signature *matching_signature(const exec_list *actual_param);
403 * Find a signature that exactly matches a set of actual parameters without
404 * any implicit type conversions.
406 ir_function_signature *exact_matching_signature(const exec_list *actual_ps);
409 * Name of the function.
413 /** Whether or not this function has a signature that is a built-in. */
414 bool has_builtin_signature();
417 * List of ir_function_signature for each overloaded function with this name.
419 struct exec_list signatures;
422 inline const char *ir_function_signature::function_name() const
424 return this->_function->name;
430 * IR instruction representing high-level if-statements
432 class ir_if : public ir_instruction {
434 ir_if(ir_rvalue *condition)
435 : condition(condition)
437 ir_type = ir_type_if;
440 virtual ir_if *clone(void *mem_ctx, struct hash_table *ht) const;
442 virtual ir_if *as_if()
447 virtual void accept(ir_visitor *v)
452 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
454 ir_rvalue *condition;
455 /** List of ir_instruction for the body of the then branch */
456 exec_list then_instructions;
457 /** List of ir_instruction for the body of the else branch */
458 exec_list else_instructions;
463 * IR instruction representing a high-level loop structure.
465 class ir_loop : public ir_instruction {
469 virtual ir_loop *clone(void *mem_ctx, struct hash_table *ht) const;
471 virtual void accept(ir_visitor *v)
476 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
478 virtual ir_loop *as_loop()
484 * Get an iterator for the instructions of the loop body
486 exec_list_iterator iterator()
488 return body_instructions.iterator();
491 /** List of ir_instruction that make up the body of the loop. */
492 exec_list body_instructions;
495 * \name Loop counter and controls
497 * Represents a loop like a FORTRAN \c do-loop.
500 * If \c from and \c to are the same value, the loop will execute once.
503 ir_rvalue *from; /** Value of the loop counter on the first
504 * iteration of the loop.
506 ir_rvalue *to; /** Value of the loop counter on the last
507 * iteration of the loop.
509 ir_rvalue *increment;
510 ir_variable *counter;
513 * Comparison operation in the loop terminator.
515 * If any of the loop control fields are non-\c NULL, this field must be
516 * one of \c ir_binop_less, \c ir_binop_greater, \c ir_binop_lequal,
517 * \c ir_binop_gequal, \c ir_binop_equal, or \c ir_binop_nequal.
524 class ir_assignment : public ir_instruction {
526 ir_assignment(ir_rvalue *lhs, ir_rvalue *rhs, ir_rvalue *condition);
529 * Construct an assignment with an explicit write mask
532 * Since a write mask is supplied, the LHS must already be a bare
533 * \c ir_dereference. The cannot be any swizzles in the LHS.
535 ir_assignment(ir_dereference *lhs, ir_rvalue *rhs, ir_rvalue *condition,
536 unsigned write_mask);
538 virtual ir_assignment *clone(void *mem_ctx, struct hash_table *ht) const;
540 virtual ir_constant *constant_expression_value();
542 virtual void accept(ir_visitor *v)
547 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
549 virtual ir_assignment * as_assignment()
555 * Get a whole variable written by an assignment
557 * If the LHS of the assignment writes a whole variable, the variable is
558 * returned. Otherwise \c NULL is returned. Examples of whole-variable
561 * - Assigning to a scalar
562 * - Assigning to all components of a vector
563 * - Whole array (or matrix) assignment
564 * - Whole structure assignment
566 ir_variable *whole_variable_written();
569 * Set the LHS of an assignment
571 void set_lhs(ir_rvalue *lhs);
574 * Left-hand side of the assignment.
576 * This should be treated as read only. If you need to set the LHS of an
577 * assignment, use \c ir_assignment::set_lhs.
582 * Value being assigned
587 * Optional condition for the assignment.
589 ir_rvalue *condition;
593 * Component mask written
595 * For non-vector types in the LHS, this field will be zero. For vector
596 * types, a bit will be set for each component that is written. Note that
597 * for \c vec2 and \c vec3 types only the lower bits will ever be set.
599 unsigned write_mask:4;
602 /* Update ir_expression::num_operands() and operator_strs when
603 * updating this list.
605 enum ir_expression_operation {
614 ir_unop_exp, /**< Log base e on gentype */
615 ir_unop_log, /**< Natural log on gentype */
618 ir_unop_f2i, /**< Float-to-integer conversion. */
619 ir_unop_i2f, /**< Integer-to-float conversion. */
620 ir_unop_f2b, /**< Float-to-boolean conversion */
621 ir_unop_b2f, /**< Boolean-to-float conversion */
622 ir_unop_i2b, /**< int-to-boolean conversion */
623 ir_unop_b2i, /**< Boolean-to-int conversion */
624 ir_unop_u2f, /**< Unsigned-to-float conversion. */
628 * \name Unary floating-point rounding operations.
638 * \name Trigonometric operations.
646 * \name Partial derivatives.
659 * Takes one of two combinations of arguments:
664 * Does not take integer types.
669 * \name Binary comparison operators
677 * Returns single boolean for whether all components of operands[0]
678 * equal the components of operands[1].
682 * Returns single boolean for whether any component of operands[0]
683 * is not equal to the corresponding component of operands[1].
689 * \name Bit-wise binary operations.
711 class ir_expression : public ir_rvalue {
713 ir_expression(int op, const struct glsl_type *type,
714 ir_rvalue *, ir_rvalue *);
716 virtual ir_expression *as_expression()
721 virtual ir_expression *clone(void *mem_ctx, struct hash_table *ht) const;
723 virtual ir_constant *constant_expression_value();
725 static unsigned int get_num_operands(ir_expression_operation);
726 unsigned int get_num_operands() const
728 return get_num_operands(operation);
732 * Return a string representing this expression's operator.
734 const char *operator_string();
737 * Return a string representing this expression's operator.
739 static const char *operator_string(ir_expression_operation);
743 * Do a reverse-lookup to translate the given string into an operator.
745 static ir_expression_operation get_operator(const char *);
747 virtual void accept(ir_visitor *v)
752 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
754 ir_expression_operation operation;
755 ir_rvalue *operands[2];
760 * IR instruction representing a function call
762 class ir_call : public ir_rvalue {
764 ir_call(ir_function_signature *callee, exec_list *actual_parameters)
767 ir_type = ir_type_call;
768 assert(callee->return_type != NULL);
769 type = callee->return_type;
770 actual_parameters->move_nodes_to(& this->actual_parameters);
773 virtual ir_call *clone(void *mem_ctx, struct hash_table *ht) const;
775 virtual ir_constant *constant_expression_value();
777 virtual ir_call *as_call()
782 virtual void accept(ir_visitor *v)
787 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
790 * Get a generic ir_call object when an error occurs
792 * Any allocation will be performed with 'ctx' as talloc owner.
794 static ir_call *get_error_instruction(void *ctx);
797 * Get an iterator for the set of acutal parameters
799 exec_list_iterator iterator()
801 return actual_parameters.iterator();
805 * Get the name of the function being called.
807 const char *callee_name() const
809 return callee->function_name();
812 ir_function_signature *get_callee()
818 * Set the function call target
820 void set_callee(ir_function_signature *sig);
823 * Generates an inline version of the function before @ir,
824 * returning the return value of the function.
826 ir_rvalue *generate_inline(ir_instruction *ir);
828 /* List of ir_rvalue of paramaters passed in this call. */
829 exec_list actual_parameters;
835 this->ir_type = ir_type_call;
838 ir_function_signature *callee;
843 * \name Jump-like IR instructions.
845 * These include \c break, \c continue, \c return, and \c discard.
848 class ir_jump : public ir_instruction {
852 ir_type = ir_type_unset;
856 class ir_return : public ir_jump {
861 this->ir_type = ir_type_return;
864 ir_return(ir_rvalue *value)
867 this->ir_type = ir_type_return;
870 virtual ir_return *clone(void *mem_ctx, struct hash_table *) const;
872 virtual ir_return *as_return()
877 ir_rvalue *get_value() const
882 virtual void accept(ir_visitor *v)
887 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
894 * Jump instructions used inside loops
896 * These include \c break and \c continue. The \c break within a loop is
897 * different from the \c break within a switch-statement.
901 class ir_loop_jump : public ir_jump {
908 ir_loop_jump(jump_mode mode)
910 this->ir_type = ir_type_loop_jump;
915 virtual ir_loop_jump *clone(void *mem_ctx, struct hash_table *) const;
917 virtual void accept(ir_visitor *v)
922 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
924 bool is_break() const
926 return mode == jump_break;
929 bool is_continue() const
931 return mode == jump_continue;
934 /** Mode selector for the jump instruction. */
937 /** Loop containing this break instruction. */
942 * IR instruction representing discard statements.
944 class ir_discard : public ir_jump {
948 this->ir_type = ir_type_discard;
949 this->condition = NULL;
952 ir_discard(ir_rvalue *cond)
954 this->ir_type = ir_type_discard;
955 this->condition = cond;
958 virtual ir_discard *clone(void *mem_ctx, struct hash_table *ht) const;
960 virtual void accept(ir_visitor *v)
965 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
967 ir_rvalue *condition;
973 * Texture sampling opcodes used in ir_texture
975 enum ir_texture_opcode {
976 ir_tex, /* Regular texture look-up */
977 ir_txb, /* Texture look-up with LOD bias */
978 ir_txl, /* Texture look-up with explicit LOD */
979 ir_txd, /* Texture look-up with partial derivatvies */
980 ir_txf /* Texel fetch with explicit LOD */
985 * IR instruction to sample a texture
987 * The specific form of the IR instruction depends on the \c mode value
988 * selected from \c ir_texture_opcodes. In the printed IR, these will
992 * | Projection divisor
993 * | | Shadow comparitor
996 * (tex (sampler) (coordinate) (0 0 0) (1) ( ))
997 * (txb (sampler) (coordinate) (0 0 0) (1) ( ) (bias))
998 * (txl (sampler) (coordinate) (0 0 0) (1) ( ) (lod))
999 * (txd (sampler) (coordinate) (0 0 0) (1) ( ) (dPdx dPdy))
1000 * (txf (sampler) (coordinate) (0 0 0) (lod))
1002 class ir_texture : public ir_rvalue {
1004 ir_texture(enum ir_texture_opcode op)
1005 : op(op), projector(NULL), shadow_comparitor(NULL)
1007 this->ir_type = ir_type_texture;
1010 virtual ir_texture *clone(void *mem_ctx, struct hash_table *) const;
1012 virtual ir_constant *constant_expression_value();
1014 virtual void accept(ir_visitor *v)
1019 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
1022 * Return a string representing the ir_texture_opcode.
1024 const char *opcode_string();
1026 /** Set the sampler and infer the type. */
1027 void set_sampler(ir_dereference *sampler);
1030 * Do a reverse-lookup to translate a string into an ir_texture_opcode.
1032 static ir_texture_opcode get_opcode(const char *);
1034 enum ir_texture_opcode op;
1036 /** Sampler to use for the texture access. */
1037 ir_dereference *sampler;
1039 /** Texture coordinate to sample */
1040 ir_rvalue *coordinate;
1043 * Value used for projective divide.
1045 * If there is no projective divide (the common case), this will be
1046 * \c NULL. Optimization passes should check for this to point to a constant
1047 * of 1.0 and replace that with \c NULL.
1049 ir_rvalue *projector;
1052 * Coordinate used for comparison on shadow look-ups.
1054 * If there is no shadow comparison, this will be \c NULL. For the
1055 * \c ir_txf opcode, this *must* be \c NULL.
1057 ir_rvalue *shadow_comparitor;
1059 /** Explicit texel offsets. */
1060 signed char offsets[3];
1063 ir_rvalue *lod; /**< Floating point LOD */
1064 ir_rvalue *bias; /**< Floating point LOD bias */
1066 ir_rvalue *dPdx; /**< Partial derivative of coordinate wrt X */
1067 ir_rvalue *dPdy; /**< Partial derivative of coordinate wrt Y */
1073 struct ir_swizzle_mask {
1080 * Number of components in the swizzle.
1082 unsigned num_components:3;
1085 * Does the swizzle contain duplicate components?
1087 * L-value swizzles cannot contain duplicate components.
1089 unsigned has_duplicates:1;
1093 class ir_swizzle : public ir_rvalue {
1095 ir_swizzle(ir_rvalue *, unsigned x, unsigned y, unsigned z, unsigned w,
1098 ir_swizzle(ir_rvalue *val, const unsigned *components, unsigned count);
1100 ir_swizzle(ir_rvalue *val, ir_swizzle_mask mask);
1102 virtual ir_swizzle *clone(void *mem_ctx, struct hash_table *) const;
1104 virtual ir_constant *constant_expression_value();
1106 virtual ir_swizzle *as_swizzle()
1112 * Construct an ir_swizzle from the textual representation. Can fail.
1114 static ir_swizzle *create(ir_rvalue *, const char *, unsigned vector_length);
1116 virtual void accept(ir_visitor *v)
1121 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
1125 return val->is_lvalue() && !mask.has_duplicates;
1129 * Get the variable that is ultimately referenced by an r-value
1131 virtual ir_variable *variable_referenced();
1134 ir_swizzle_mask mask;
1138 * Initialize the mask component of a swizzle
1140 * This is used by the \c ir_swizzle constructors.
1142 void init_mask(const unsigned *components, unsigned count);
1146 class ir_dereference : public ir_rvalue {
1148 virtual ir_dereference *clone(void *mem_ctx, struct hash_table *) const = 0;
1150 virtual ir_dereference *as_dereference()
1158 * Get the variable that is ultimately referenced by an r-value
1160 virtual ir_variable *variable_referenced() = 0;
1164 class ir_dereference_variable : public ir_dereference {
1166 ir_dereference_variable(ir_variable *var);
1168 virtual ir_dereference_variable *clone(void *mem_ctx,
1169 struct hash_table *) const;
1171 virtual ir_constant *constant_expression_value();
1173 virtual ir_dereference_variable *as_dereference_variable()
1179 * Get the variable that is ultimately referenced by an r-value
1181 virtual ir_variable *variable_referenced()
1186 virtual ir_variable *whole_variable_referenced()
1188 /* ir_dereference_variable objects always dereference the entire
1189 * variable. However, if this dereference is dereferenced by anything
1190 * else, the complete deferefernce chain is not a whole-variable
1191 * dereference. This method should only be called on the top most
1192 * ir_rvalue in a dereference chain.
1197 virtual void accept(ir_visitor *v)
1202 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
1205 * Object being dereferenced.
1211 class ir_dereference_array : public ir_dereference {
1213 ir_dereference_array(ir_rvalue *value, ir_rvalue *array_index);
1215 ir_dereference_array(ir_variable *var, ir_rvalue *array_index);
1217 virtual ir_dereference_array *clone(void *mem_ctx,
1218 struct hash_table *) const;
1220 virtual ir_constant *constant_expression_value();
1222 virtual ir_dereference_array *as_dereference_array()
1228 * Get the variable that is ultimately referenced by an r-value
1230 virtual ir_variable *variable_referenced()
1232 return this->array->variable_referenced();
1235 virtual void accept(ir_visitor *v)
1240 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
1243 ir_rvalue *array_index;
1246 void set_array(ir_rvalue *value);
1250 class ir_dereference_record : public ir_dereference {
1252 ir_dereference_record(ir_rvalue *value, const char *field);
1254 ir_dereference_record(ir_variable *var, const char *field);
1256 virtual ir_dereference_record *clone(void *mem_ctx,
1257 struct hash_table *) const;
1259 virtual ir_constant *constant_expression_value();
1262 * Get the variable that is ultimately referenced by an r-value
1264 virtual ir_variable *variable_referenced()
1266 return this->record->variable_referenced();
1269 virtual void accept(ir_visitor *v)
1274 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
1282 * Data stored in an ir_constant
1284 union ir_constant_data {
1292 class ir_constant : public ir_rvalue {
1294 ir_constant(const struct glsl_type *type, const ir_constant_data *data);
1295 ir_constant(bool b);
1296 ir_constant(unsigned int u);
1298 ir_constant(float f);
1301 * Construct an ir_constant from a list of ir_constant values
1303 ir_constant(const struct glsl_type *type, exec_list *values);
1306 * Construct an ir_constant from a scalar component of another ir_constant
1308 * The new \c ir_constant inherits the type of the component from the
1312 * In the case of a matrix constant, the new constant is a scalar, \b not
1315 ir_constant(const ir_constant *c, unsigned i);
1318 * Return a new ir_constant of the specified type containing all zeros.
1320 static ir_constant *zero(void *mem_ctx, const glsl_type *type);
1322 virtual ir_constant *clone(void *mem_ctx, struct hash_table *) const;
1324 virtual ir_constant *constant_expression_value();
1326 virtual ir_constant *as_constant()
1331 virtual void accept(ir_visitor *v)
1336 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
1339 * Get a particular component of a constant as a specific type
1341 * This is useful, for example, to get a value from an integer constant
1342 * as a float or bool. This appears frequently when constructors are
1343 * called with all constant parameters.
1346 bool get_bool_component(unsigned i) const;
1347 float get_float_component(unsigned i) const;
1348 int get_int_component(unsigned i) const;
1349 unsigned get_uint_component(unsigned i) const;
1352 ir_constant *get_array_element(unsigned i) const;
1354 ir_constant *get_record_field(const char *name);
1357 * Determine whether a constant has the same value as another constant
1359 bool has_value(const ir_constant *) const;
1362 * Value of the constant.
1364 * The field used to back the values supplied by the constant is determined
1365 * by the type associated with the \c ir_instruction. Constants may be
1366 * scalars, vectors, or matrices.
1368 union ir_constant_data value;
1370 /* Array elements */
1371 ir_constant **array_elements;
1373 /* Structure fields */
1374 exec_list components;
1378 * Parameterless constructor only used by the clone method
1384 visit_exec_list(exec_list *list, ir_visitor *visitor);
1386 void validate_ir_tree(exec_list *instructions);
1389 * Make a clone of each IR instruction in a list
1391 * \param in List of IR instructions that are to be cloned
1392 * \param out List to hold the cloned instructions
1395 clone_ir_list(void *mem_ctx, exec_list *out, const exec_list *in);
1398 _mesa_glsl_initialize_variables(exec_list *instructions,
1399 struct _mesa_glsl_parse_state *state);
1402 _mesa_glsl_initialize_functions(exec_list *instructions,
1403 struct _mesa_glsl_parse_state *state);
1406 _mesa_glsl_release_functions(void);
1409 reparent_ir(exec_list *list, void *mem_ctx);
1411 struct glsl_symbol_table;
1414 import_prototypes(const exec_list *source, exec_list *dest,
1415 struct glsl_symbol_table *symbols, void *mem_ctx);
1418 ir_has_call(ir_instruction *ir);
1421 do_set_program_inouts(exec_list *instructions, struct gl_program *prog);