Construct an ir_constant from a scalar component of another ir_constant
[mesa.git] / ir.h
1 /* -*- c++ -*- */
2 /*
3 * Copyright © 2010 Intel Corporation
4 *
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:
11 *
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
14 * Software.
15 *
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.
23 */
24
25 #pragma once
26 #ifndef IR_H
27 #define IR_H
28
29 #include "list.h"
30 #include "ir_visitor.h"
31 #include "ir_hierarchical_visitor.h"
32
33 struct ir_program {
34 void *bong_hits;
35 };
36
37 /**
38 * Base class of all IR instructions
39 */
40 class ir_instruction : public exec_node {
41 public:
42 const struct glsl_type *type;
43
44 class ir_constant *constant_expression_value();
45 virtual void accept(ir_visitor *) = 0;
46 virtual ir_visitor_status accept(ir_hierarchical_visitor *) = 0;
47
48 /**
49 * \name IR instruction downcast functions
50 *
51 * These functions either cast the object to a derived class or return
52 * \c NULL if the object's type does not match the specified derived class.
53 * Additional downcast functions will be added as needed.
54 */
55 /*@{*/
56 virtual class ir_variable * as_variable() { return NULL; }
57 virtual class ir_function * as_function() { return NULL; }
58 virtual class ir_dereference * as_dereference() { return NULL; }
59 virtual class ir_dereference_array * as_dereference_array() { return NULL; }
60 virtual class ir_rvalue * as_rvalue() { return NULL; }
61 virtual class ir_loop * as_loop() { return NULL; }
62 virtual class ir_assignment * as_assignment() { return NULL; }
63 virtual class ir_call * as_call() { return NULL; }
64 virtual class ir_return * as_return() { return NULL; }
65 virtual class ir_if * as_if() { return NULL; }
66 virtual class ir_swizzle * as_swizzle() { return NULL; }
67 virtual class ir_constant * as_constant() { return NULL; }
68 /*@}*/
69
70 protected:
71 ir_instruction()
72 {
73 /* empty */
74 }
75 };
76
77
78 class ir_rvalue : public ir_instruction {
79 public:
80 virtual ir_rvalue * as_rvalue()
81 {
82 return this;
83 }
84
85 virtual bool is_lvalue()
86 {
87 return false;
88 }
89
90 /**
91 * Get the variable that is ultimately referenced by an r-value
92 */
93 virtual ir_variable *variable_referenced()
94 {
95 return NULL;
96 }
97
98
99 /**
100 * If an r-value is a reference to a whole variable, get that variable
101 *
102 * \return
103 * Pointer to a variable that is completely dereferenced by the r-value. If
104 * the r-value is not a dereference or the dereference does not access the
105 * entire variable (i.e., it's just one array element, struct field), \c NULL
106 * is returned.
107 */
108 virtual ir_variable *whole_variable_referenced()
109 {
110 return NULL;
111 }
112
113 protected:
114 ir_rvalue()
115 {
116 /* empty */
117 }
118 };
119
120
121 enum ir_variable_mode {
122 ir_var_auto = 0,
123 ir_var_uniform,
124 ir_var_in,
125 ir_var_out,
126 ir_var_inout
127 };
128
129 enum ir_varaible_interpolation {
130 ir_var_smooth = 0,
131 ir_var_flat,
132 ir_var_noperspective
133 };
134
135
136 class ir_variable : public ir_instruction {
137 public:
138 ir_variable(const struct glsl_type *, const char *);
139
140 virtual ir_variable *as_variable()
141 {
142 return this;
143 }
144
145 virtual void accept(ir_visitor *v)
146 {
147 v->visit(this);
148 }
149
150 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
151
152 /**
153 * Duplicate an IR variable
154 *
155 * \note
156 * This will probably be made \c virtual and moved to the base class
157 * eventually.
158 */
159 ir_variable *clone() const
160 {
161 ir_variable *var = new ir_variable(type, name);
162
163 var->max_array_access = this->max_array_access;
164 var->read_only = this->read_only;
165 var->centroid = this->centroid;
166 var->invariant = this->invariant;
167 var->mode = this->mode;
168 var->interpolation = this->interpolation;
169
170 return var;
171 }
172
173 const char *name;
174
175 /**
176 * Highest element accessed with a constant expression array index
177 *
178 * Not used for non-array variables.
179 */
180 unsigned max_array_access;
181
182 unsigned read_only:1;
183 unsigned centroid:1;
184 unsigned invariant:1;
185 /** If the variable is initialized outside of the scope of the shader */
186 unsigned shader_in:1;
187 /**
188 * If the variable value is later used outside of the scope of the shader.
189 */
190 unsigned shader_out:1;
191
192 unsigned mode:3;
193 unsigned interpolation:2;
194
195 /**
196 * Flag that the whole array is assignable
197 *
198 * In GLSL 1.20 and later whole arrays are assignable (and comparable for
199 * equality). This flag enables this behavior.
200 */
201 unsigned array_lvalue:1;
202
203 /**
204 * Emit a warning if this variable is accessed.
205 */
206 const char *warn_extension;
207
208 /**
209 * Value assigned in the initializer of a variable declared "const"
210 */
211 ir_constant *constant_value;
212 };
213
214
215 /*@{*/
216 /**
217 * The representation of a function instance; may be the full definition or
218 * simply a prototype.
219 */
220 class ir_function_signature : public ir_instruction {
221 /* An ir_function_signature will be part of the list of signatures in
222 * an ir_function.
223 */
224 public:
225 ir_function_signature(const glsl_type *return_type);
226
227 virtual void accept(ir_visitor *v)
228 {
229 v->visit(this);
230 }
231
232 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
233
234 /**
235 * Get the name of the function for which this is a signature
236 */
237 const char *function_name() const;
238
239 /**
240 * Check whether the qualifiers match between this signature's parameters
241 * and the supplied parameter list. If not, returns the name of the first
242 * parameter with mismatched qualifiers (for use in error messages).
243 */
244 const char *qualifiers_match(exec_list *params);
245
246 /**
247 * Replace the current parameter list with the given one. This is useful
248 * if the current information came from a prototype, and either has invalid
249 * or missing parameter names.
250 */
251 void replace_parameters(exec_list *new_params);
252
253 /**
254 * Function return type.
255 *
256 * \note This discards the optional precision qualifier.
257 */
258 const struct glsl_type *return_type;
259
260 /**
261 * List of ir_variable of function parameters.
262 *
263 * This represents the storage. The paramaters passed in a particular
264 * call will be in ir_call::actual_paramaters.
265 */
266 struct exec_list parameters;
267
268 /** Whether or not this function has a body (which may be empty). */
269 unsigned is_defined:1;
270
271 /** Body of instructions in the function. */
272 struct exec_list body;
273
274 private:
275 /** Function of which this signature is one overload. */
276 class ir_function *function;
277
278 friend class ir_function;
279 };
280
281
282 /**
283 * Header for tracking multiple overloaded functions with the same name.
284 * Contains a list of ir_function_signatures representing each of the
285 * actual functions.
286 */
287 class ir_function : public ir_instruction {
288 public:
289 ir_function(const char *name);
290
291 virtual ir_function *as_function()
292 {
293 return this;
294 }
295
296 virtual void accept(ir_visitor *v)
297 {
298 v->visit(this);
299 }
300
301 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
302
303 void add_signature(ir_function_signature *sig)
304 {
305 sig->function = this;
306 signatures.push_tail(sig);
307 }
308
309 /**
310 * Get an iterator for the set of function signatures
311 */
312 exec_list_iterator iterator()
313 {
314 return signatures.iterator();
315 }
316
317 /**
318 * Find a signature that matches a set of actual parameters, taking implicit
319 * conversions into account.
320 */
321 const ir_function_signature *matching_signature(exec_list *actual_param);
322
323 /**
324 * Find a signature that exactly matches a set of actual parameters without
325 * any implicit type conversions.
326 */
327 ir_function_signature *exact_matching_signature(exec_list *actual_ps);
328
329 /**
330 * Name of the function.
331 */
332 const char *name;
333
334 private:
335 /**
336 * List of ir_function_signature for each overloaded function with this name.
337 */
338 struct exec_list signatures;
339 };
340
341 inline const char *ir_function_signature::function_name() const
342 {
343 return function->name;
344 }
345 /*@}*/
346
347
348 /**
349 * IR instruction representing high-level if-statements
350 */
351 class ir_if : public ir_instruction {
352 public:
353 ir_if(ir_rvalue *condition)
354 : condition(condition)
355 {
356 /* empty */
357 }
358
359 virtual ir_if *as_if()
360 {
361 return this;
362 }
363
364 virtual void accept(ir_visitor *v)
365 {
366 v->visit(this);
367 }
368
369 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
370
371 ir_rvalue *condition;
372 /** List of ir_instruction for the body of the then branch */
373 exec_list then_instructions;
374 /** List of ir_instruction for the body of the else branch */
375 exec_list else_instructions;
376 };
377
378
379 /**
380 * IR instruction representing a high-level loop structure.
381 */
382 class ir_loop : public ir_instruction {
383 public:
384 ir_loop() : from(NULL), to(NULL), increment(NULL), counter(NULL)
385 {
386 /* empty */
387 }
388
389 virtual void accept(ir_visitor *v)
390 {
391 v->visit(this);
392 }
393
394 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
395
396 virtual ir_loop *as_loop()
397 {
398 return this;
399 }
400
401 /**
402 * Get an iterator for the instructions of the loop body
403 */
404 exec_list_iterator iterator()
405 {
406 return body_instructions.iterator();
407 }
408
409 /** List of ir_instruction that make up the body of the loop. */
410 exec_list body_instructions;
411
412 /**
413 * \name Loop counter and controls
414 */
415 /*@{*/
416 ir_rvalue *from;
417 ir_rvalue *to;
418 ir_rvalue *increment;
419 ir_variable *counter;
420 /*@}*/
421 };
422
423
424 class ir_assignment : public ir_rvalue {
425 public:
426 ir_assignment(ir_rvalue *lhs, ir_rvalue *rhs, ir_rvalue *condition);
427
428 virtual void accept(ir_visitor *v)
429 {
430 v->visit(this);
431 }
432
433 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
434
435 virtual ir_assignment * as_assignment()
436 {
437 return this;
438 }
439
440 /**
441 * Left-hand side of the assignment.
442 */
443 ir_rvalue *lhs;
444
445 /**
446 * Value being assigned
447 */
448 ir_rvalue *rhs;
449
450 /**
451 * Optional condition for the assignment.
452 */
453 ir_rvalue *condition;
454 };
455
456 /* Update ir_expression::num_operands() and operator_strs when
457 * updating this list.
458 */
459 enum ir_expression_operation {
460 ir_unop_bit_not,
461 ir_unop_logic_not,
462 ir_unop_neg,
463 ir_unop_abs,
464 ir_unop_sign,
465 ir_unop_rcp,
466 ir_unop_rsq,
467 ir_unop_sqrt,
468 ir_unop_exp,
469 ir_unop_log,
470 ir_unop_exp2,
471 ir_unop_log2,
472 ir_unop_f2i, /**< Float-to-integer conversion. */
473 ir_unop_i2f, /**< Integer-to-float conversion. */
474 ir_unop_f2b, /**< Float-to-boolean conversion */
475 ir_unop_b2f, /**< Boolean-to-float conversion */
476 ir_unop_i2b, /**< int-to-boolean conversion */
477 ir_unop_b2i, /**< Boolean-to-int conversion */
478 ir_unop_u2f, /**< Unsigned-to-float conversion. */
479
480 /**
481 * \name Unary floating-point rounding operations.
482 */
483 /*@{*/
484 ir_unop_trunc,
485 ir_unop_ceil,
486 ir_unop_floor,
487 /*@}*/
488
489 /**
490 * \name Trigonometric operations.
491 */
492 /*@{*/
493 ir_unop_sin,
494 ir_unop_cos,
495 /*@}*/
496
497 /**
498 * \name Partial derivatives.
499 */
500 /*@{*/
501 ir_unop_dFdx,
502 ir_unop_dFdy,
503 /*@}*/
504
505 ir_binop_add,
506 ir_binop_sub,
507 ir_binop_mul,
508 ir_binop_div,
509 ir_binop_mod,
510
511 /**
512 * \name Binary comparison operators
513 */
514 /*@{*/
515 ir_binop_less,
516 ir_binop_greater,
517 ir_binop_lequal,
518 ir_binop_gequal,
519 ir_binop_equal,
520 ir_binop_nequal,
521 /*@}*/
522
523 /**
524 * \name Bit-wise binary operations.
525 */
526 /*@{*/
527 ir_binop_lshift,
528 ir_binop_rshift,
529 ir_binop_bit_and,
530 ir_binop_bit_xor,
531 ir_binop_bit_or,
532 /*@}*/
533
534 ir_binop_logic_and,
535 ir_binop_logic_xor,
536 ir_binop_logic_or,
537
538 ir_binop_dot,
539 ir_binop_min,
540 ir_binop_max,
541
542 ir_binop_pow
543 };
544
545 class ir_expression : public ir_rvalue {
546 public:
547 ir_expression(int op, const struct glsl_type *type,
548 ir_rvalue *, ir_rvalue *);
549
550 static unsigned int get_num_operands(ir_expression_operation);
551 unsigned int get_num_operands()
552 {
553 return get_num_operands(operation);
554 }
555
556 /**
557 * Return a string representing this expression's operator.
558 */
559 const char *operator_string();
560
561 /**
562 * Do a reverse-lookup to translate the given string into an operator.
563 */
564 static ir_expression_operation get_operator(const char *);
565
566 virtual void accept(ir_visitor *v)
567 {
568 v->visit(this);
569 }
570
571 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
572
573 ir_expression *clone();
574
575 ir_expression_operation operation;
576 ir_rvalue *operands[2];
577 };
578
579
580 /**
581 * IR instruction representing a function call
582 */
583 class ir_call : public ir_rvalue {
584 public:
585 ir_call(const ir_function_signature *callee, exec_list *actual_parameters)
586 : callee(callee)
587 {
588 assert(callee->return_type != NULL);
589 type = callee->return_type;
590 actual_parameters->move_nodes_to(& this->actual_parameters);
591 }
592
593 virtual ir_call *as_call()
594 {
595 return this;
596 }
597
598 virtual void accept(ir_visitor *v)
599 {
600 v->visit(this);
601 }
602
603 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
604
605 /**
606 * Get a generic ir_call object when an error occurs
607 */
608 static ir_call *get_error_instruction();
609
610 /**
611 * Get an iterator for the set of acutal parameters
612 */
613 exec_list_iterator iterator()
614 {
615 return actual_parameters.iterator();
616 }
617
618 /**
619 * Get the name of the function being called.
620 */
621 const char *callee_name() const
622 {
623 return callee->function_name();
624 }
625
626 const ir_function_signature *get_callee()
627 {
628 return callee;
629 }
630
631 /**
632 * Generates an inline version of the function before @ir,
633 * returning the return value of the function.
634 */
635 ir_rvalue *generate_inline(ir_instruction *ir);
636
637 private:
638 ir_call()
639 : callee(NULL)
640 {
641 /* empty */
642 }
643
644 const ir_function_signature *callee;
645
646 /* List of ir_rvalue of paramaters passed in this call. */
647 exec_list actual_parameters;
648 };
649
650
651 /**
652 * \name Jump-like IR instructions.
653 *
654 * These include \c break, \c continue, \c return, and \c discard.
655 */
656 /*@{*/
657 class ir_jump : public ir_instruction {
658 protected:
659 ir_jump()
660 {
661 /* empty */
662 }
663 };
664
665 class ir_return : public ir_jump {
666 public:
667 ir_return()
668 : value(NULL)
669 {
670 /* empty */
671 }
672
673 ir_return(ir_rvalue *value)
674 : value(value)
675 {
676 /* empty */
677 }
678
679 virtual ir_return *as_return()
680 {
681 return this;
682 }
683
684 ir_rvalue *get_value() const
685 {
686 return value;
687 }
688
689 virtual void accept(ir_visitor *v)
690 {
691 v->visit(this);
692 }
693
694 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
695
696 ir_rvalue *value;
697 };
698
699
700 /**
701 * Jump instructions used inside loops
702 *
703 * These include \c break and \c continue. The \c break within a loop is
704 * different from the \c break within a switch-statement.
705 *
706 * \sa ir_switch_jump
707 */
708 class ir_loop_jump : public ir_jump {
709 public:
710 enum jump_mode {
711 jump_break,
712 jump_continue
713 };
714
715 ir_loop_jump(ir_loop *loop, jump_mode mode)
716 : loop(loop), mode(mode)
717 {
718 /* empty */
719 }
720
721 virtual void accept(ir_visitor *v)
722 {
723 v->visit(this);
724 }
725
726 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
727
728 bool is_break() const
729 {
730 return mode == jump_break;
731 }
732
733 bool is_continue() const
734 {
735 return mode == jump_continue;
736 }
737
738 private:
739 /** Loop containing this break instruction. */
740 ir_loop *loop;
741
742 /** Mode selector for the jump instruction. */
743 enum jump_mode mode;
744 };
745 /*@}*/
746
747
748 /**
749 * Texture sampling opcodes used in ir_texture
750 */
751 enum ir_texture_opcode {
752 ir_tex, /* Regular texture look-up */
753 ir_txb, /* Texture look-up with LOD bias */
754 ir_txl, /* Texture look-up with explicit LOD */
755 ir_txd, /* Texture look-up with partial derivatvies */
756 ir_txf /* Texel fetch with explicit LOD */
757 };
758
759
760 /**
761 * IR instruction to sample a texture
762 *
763 * The specific form of the IR instruction depends on the \c mode value
764 * selected from \c ir_texture_opcodes. In the printed IR, these will
765 * appear as:
766 *
767 * Texel offset
768 * | Projection divisor
769 * | | Shadow comparitor
770 * | | |
771 * v v v
772 * (tex (sampler) (coordinate) (0 0 0) (1) ( ))
773 * (txb (sampler) (coordinate) (0 0 0) (1) ( ) (bias))
774 * (txl (sampler) (coordinate) (0 0 0) (1) ( ) (lod))
775 * (txd (sampler) (coordinate) (0 0 0) (1) ( ) (dPdx dPdy))
776 * (txf (sampler) (coordinate) (0 0 0) (lod))
777 */
778 class ir_texture : public ir_rvalue {
779 public:
780 ir_texture(enum ir_texture_opcode op)
781 : op(op), projector(NULL), shadow_comparitor(NULL)
782 {
783 /* empty */
784 }
785
786 virtual void accept(ir_visitor *v)
787 {
788 v->visit(this);
789 }
790
791 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
792
793 /**
794 * Return a string representing the ir_texture_opcode.
795 */
796 const char *opcode_string();
797
798 /** Set the sampler and infer the type. */
799 void set_sampler(ir_dereference *sampler);
800
801 /**
802 * Do a reverse-lookup to translate a string into an ir_texture_opcode.
803 */
804 static ir_texture_opcode get_opcode(const char *);
805
806 enum ir_texture_opcode op;
807
808 /** Sampler to use for the texture access. */
809 ir_dereference *sampler;
810
811 /** Texture coordinate to sample */
812 ir_rvalue *coordinate;
813
814 /**
815 * Value used for projective divide.
816 *
817 * If there is no projective divide (the common case), this will be
818 * \c NULL. Optimization passes should check for this to point to a constant
819 * of 1.0 and replace that with \c NULL.
820 */
821 ir_rvalue *projector;
822
823 /**
824 * Coordinate used for comparison on shadow look-ups.
825 *
826 * If there is no shadow comparison, this will be \c NULL. For the
827 * \c ir_txf opcode, this *must* be \c NULL.
828 */
829 ir_rvalue *shadow_comparitor;
830
831 /** Explicit texel offsets. */
832 signed char offsets[3];
833
834 union {
835 ir_rvalue *lod; /**< Floating point LOD */
836 ir_rvalue *bias; /**< Floating point LOD bias */
837 struct {
838 ir_rvalue *dPdx; /**< Partial derivative of coordinate wrt X */
839 ir_rvalue *dPdy; /**< Partial derivative of coordinate wrt Y */
840 } grad;
841 } lod_info;
842 };
843
844
845 struct ir_swizzle_mask {
846 unsigned x:2;
847 unsigned y:2;
848 unsigned z:2;
849 unsigned w:2;
850
851 /**
852 * Number of components in the swizzle.
853 */
854 unsigned num_components:3;
855
856 /**
857 * Does the swizzle contain duplicate components?
858 *
859 * L-value swizzles cannot contain duplicate components.
860 */
861 unsigned has_duplicates:1;
862 };
863
864
865 class ir_swizzle : public ir_rvalue {
866 public:
867 ir_swizzle(ir_rvalue *, unsigned x, unsigned y, unsigned z, unsigned w,
868 unsigned count);
869 ir_swizzle(ir_rvalue *val, ir_swizzle_mask mask);
870
871 virtual ir_swizzle *as_swizzle()
872 {
873 return this;
874 }
875
876 ir_swizzle *clone()
877 {
878 return new ir_swizzle(this->val, this->mask);
879 }
880
881 /**
882 * Construct an ir_swizzle from the textual representation. Can fail.
883 */
884 static ir_swizzle *create(ir_rvalue *, const char *, unsigned vector_length);
885
886 virtual void accept(ir_visitor *v)
887 {
888 v->visit(this);
889 }
890
891 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
892
893 bool is_lvalue()
894 {
895 return val->is_lvalue() && !mask.has_duplicates;
896 }
897
898 /**
899 * Get the variable that is ultimately referenced by an r-value
900 */
901 virtual ir_variable *variable_referenced();
902
903 ir_rvalue *val;
904 ir_swizzle_mask mask;
905 };
906
907
908 class ir_dereference : public ir_rvalue {
909 public:
910 virtual ir_dereference *as_dereference()
911 {
912 return this;
913 }
914
915 bool is_lvalue();
916
917 /**
918 * Get the variable that is ultimately referenced by an r-value
919 */
920 virtual ir_variable *variable_referenced() = 0;
921 };
922
923
924 class ir_dereference_variable : public ir_dereference {
925 public:
926 ir_dereference_variable(ir_variable *var);
927
928 /**
929 * Get the variable that is ultimately referenced by an r-value
930 */
931 virtual ir_variable *variable_referenced()
932 {
933 return this->var;
934 }
935
936 virtual ir_variable *whole_variable_referenced()
937 {
938 /* ir_dereference_variable objects always dereference the entire
939 * variable. However, if this dereference is dereferenced by anything
940 * else, the complete deferefernce chain is not a whole-variable
941 * dereference. This method should only be called on the top most
942 * ir_rvalue in a dereference chain.
943 */
944 return this->var;
945 }
946
947 virtual void accept(ir_visitor *v)
948 {
949 v->visit(this);
950 }
951
952 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
953
954 /**
955 * Object being dereferenced.
956 */
957 ir_variable *var;
958 };
959
960
961 class ir_dereference_array : public ir_dereference {
962 public:
963 ir_dereference_array(ir_rvalue *value, ir_rvalue *array_index);
964
965 ir_dereference_array(ir_variable *var, ir_rvalue *array_index);
966
967 virtual ir_dereference_array *as_dereference_array()
968 {
969 return this;
970 }
971
972 /**
973 * Get the variable that is ultimately referenced by an r-value
974 */
975 virtual ir_variable *variable_referenced()
976 {
977 return this->array->variable_referenced();
978 }
979
980 virtual void accept(ir_visitor *v)
981 {
982 v->visit(this);
983 }
984
985 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
986
987 ir_rvalue *array;
988 ir_rvalue *array_index;
989
990 private:
991 void set_array(ir_rvalue *value);
992 };
993
994
995 class ir_dereference_record : public ir_dereference {
996 public:
997 ir_dereference_record(ir_rvalue *value, const char *field);
998
999 ir_dereference_record(ir_variable *var, const char *field);
1000
1001 /**
1002 * Get the variable that is ultimately referenced by an r-value
1003 */
1004 virtual ir_variable *variable_referenced()
1005 {
1006 return this->record->variable_referenced();
1007 }
1008
1009 virtual void accept(ir_visitor *v)
1010 {
1011 v->visit(this);
1012 }
1013
1014 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
1015
1016 ir_rvalue *record;
1017 const char *field;
1018 };
1019
1020
1021 class ir_constant : public ir_rvalue {
1022 public:
1023 ir_constant(const struct glsl_type *type, const void *data);
1024 ir_constant(bool b);
1025 ir_constant(unsigned int u);
1026 ir_constant(int i);
1027 ir_constant(float f);
1028
1029 /**
1030 * Construct an ir_constant from a scalar component of another ir_constant
1031 *
1032 * The new \c ir_constant inherits the type of the component from the
1033 * source constant.
1034 *
1035 * \note
1036 * In the case of a matrix constant, the new constant is a scalar, \b not
1037 * a vector.
1038 */
1039 ir_constant(const ir_constant *c, unsigned i);
1040
1041 virtual ir_constant *as_constant()
1042 {
1043 return this;
1044 }
1045
1046 virtual void accept(ir_visitor *v)
1047 {
1048 v->visit(this);
1049 }
1050
1051 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
1052
1053 ir_constant *clone()
1054 {
1055 return new ir_constant(this->type, &this->value);
1056 }
1057
1058 /**
1059 * Value of the constant.
1060 *
1061 * The field used to back the values supplied by the constant is determined
1062 * by the type associated with the \c ir_instruction. Constants may be
1063 * scalars, vectors, or matrices.
1064 */
1065 union {
1066 unsigned u[16];
1067 int i[16];
1068 float f[16];
1069 bool b[16];
1070 } value;
1071 };
1072
1073 void
1074 visit_exec_list(exec_list *list, ir_visitor *visitor);
1075
1076 extern void
1077 _mesa_glsl_initialize_variables(exec_list *instructions,
1078 struct _mesa_glsl_parse_state *state);
1079
1080 extern void
1081 _mesa_glsl_initialize_functions(exec_list *instructions,
1082 struct _mesa_glsl_parse_state *state);
1083
1084 #endif /* IR_H */