2 * Copyright © 2010 Intel Corporation
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:
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
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
21 * DEALINGS IN THE SOFTWARE.
25 * \file ir_validate.cpp
27 * Attempts to verify that various invariants of the IR tree are true.
29 * In particular, at the moment it makes sure that no single
30 * ir_instruction node except for ir_variable appears multiple times
31 * in the ir tree. ir_variable does appear multiple times: Once as a
32 * declaration in an exec_list, and multiple times as the endpoint of
33 * a dereference chain.
37 #include "ir_hierarchical_visitor.h"
38 #include "program/hash_table.h"
39 #include "glsl_types.h"
43 class ir_validate
: public ir_hierarchical_visitor
{
47 this->ht
= hash_table_ctor(0, hash_table_pointer_hash
,
48 hash_table_pointer_compare
);
50 this->current_function
= NULL
;
52 this->callback_enter
= ir_validate::validate_ir
;
53 this->data_enter
= ht
;
58 hash_table_dtor(this->ht
);
61 virtual ir_visitor_status
visit(ir_variable
*v
);
62 virtual ir_visitor_status
visit(ir_dereference_variable
*ir
);
64 virtual ir_visitor_status
visit_enter(ir_if
*ir
);
66 virtual ir_visitor_status
visit_enter(ir_function
*ir
);
67 virtual ir_visitor_status
visit_leave(ir_function
*ir
);
68 virtual ir_visitor_status
visit_enter(ir_function_signature
*ir
);
70 virtual ir_visitor_status
visit_leave(ir_expression
*ir
);
71 virtual ir_visitor_status
visit_leave(ir_swizzle
*ir
);
73 virtual ir_visitor_status
visit_enter(class ir_dereference_array
*);
75 virtual ir_visitor_status
visit_enter(ir_assignment
*ir
);
76 virtual ir_visitor_status
visit_enter(ir_call
*ir
);
78 static void validate_ir(ir_instruction
*ir
, void *data
);
80 ir_function
*current_function
;
82 struct hash_table
*ht
;
85 } /* anonymous namespace */
88 ir_validate::visit(ir_dereference_variable
*ir
)
90 if ((ir
->var
== NULL
) || (ir
->var
->as_variable() == NULL
)) {
91 printf("ir_dereference_variable @ %p does not specify a variable %p\n",
92 (void *) ir
, (void *) ir
->var
);
96 if (hash_table_find(ht
, ir
->var
) == NULL
) {
97 printf("ir_dereference_variable @ %p specifies undeclared variable "
99 (void *) ir
, ir
->var
->name
, (void *) ir
->var
);
103 this->validate_ir(ir
, this->data_enter
);
105 return visit_continue
;
109 ir_validate::visit_enter(class ir_dereference_array
*ir
)
111 if (!ir
->array
->type
->is_array() && !ir
->array
->type
->is_matrix()) {
112 printf("ir_dereference_array @ %p does not specify an array or a "
120 if (!ir
->array_index
->type
->is_scalar()) {
121 printf("ir_dereference_array @ %p does not have scalar index: %s\n",
122 (void *) ir
, ir
->array_index
->type
->name
);
126 if (!ir
->array_index
->type
->is_integer()) {
127 printf("ir_dereference_array @ %p does not have integer index: %s\n",
128 (void *) ir
, ir
->array_index
->type
->name
);
132 return visit_continue
;
136 ir_validate::visit_enter(ir_if
*ir
)
138 if (ir
->condition
->type
!= glsl_type::bool_type
) {
139 printf("ir_if condition %s type instead of bool.\n",
140 ir
->condition
->type
->name
);
146 return visit_continue
;
151 ir_validate::visit_enter(ir_function
*ir
)
153 /* Function definitions cannot be nested.
155 if (this->current_function
!= NULL
) {
156 printf("Function definition nested inside another function "
158 printf("%s %p inside %s %p\n",
159 ir
->name
, (void *) ir
,
160 this->current_function
->name
, (void *) this->current_function
);
164 /* Store the current function hierarchy being traversed. This is used
165 * by the function signature visitor to ensure that the signatures are
166 * linked with the correct functions.
168 this->current_function
= ir
;
170 this->validate_ir(ir
, this->data_enter
);
172 /* Verify that all of the things stored in the list of signatures are,
173 * in fact, function signatures.
175 foreach_in_list(ir_instruction
, sig
, &ir
->signatures
) {
176 if (sig
->ir_type
!= ir_type_function_signature
) {
177 printf("Non-signature in signature list of function `%s'\n",
183 return visit_continue
;
187 ir_validate::visit_leave(ir_function
*ir
)
189 assert(ralloc_parent(ir
->name
) == ir
);
191 this->current_function
= NULL
;
192 return visit_continue
;
196 ir_validate::visit_enter(ir_function_signature
*ir
)
198 if (this->current_function
!= ir
->function()) {
199 printf("Function signature nested inside wrong function "
201 printf("%p inside %s %p instead of %s %p\n",
203 this->current_function
->name
, (void *) this->current_function
,
204 ir
->function_name(), (void *) ir
->function());
208 if (ir
->return_type
== NULL
) {
209 printf("Function signature %p for function %s has NULL return type.\n",
210 (void *) ir
, ir
->function_name());
214 this->validate_ir(ir
, this->data_enter
);
216 return visit_continue
;
220 ir_validate::visit_leave(ir_expression
*ir
)
222 switch (ir
->operation
) {
223 case ir_unop_bit_not
:
224 assert(ir
->operands
[0]->type
== ir
->type
);
226 case ir_unop_logic_not
:
227 assert(ir
->type
->base_type
== GLSL_TYPE_BOOL
);
228 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_BOOL
);
237 assert(ir
->type
== ir
->operands
[0]->type
);
244 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
245 assert(ir
->type
== ir
->operands
[0]->type
);
249 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
250 assert(ir
->type
->base_type
== GLSL_TYPE_INT
);
253 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
254 assert(ir
->type
->base_type
== GLSL_TYPE_UINT
);
257 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_INT
);
258 assert(ir
->type
->base_type
== GLSL_TYPE_FLOAT
);
261 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
262 assert(ir
->type
->base_type
== GLSL_TYPE_BOOL
);
265 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_BOOL
);
266 assert(ir
->type
->base_type
== GLSL_TYPE_FLOAT
);
269 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_INT
);
270 assert(ir
->type
->base_type
== GLSL_TYPE_BOOL
);
273 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_BOOL
);
274 assert(ir
->type
->base_type
== GLSL_TYPE_INT
);
277 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_UINT
);
278 assert(ir
->type
->base_type
== GLSL_TYPE_FLOAT
);
281 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_INT
);
282 assert(ir
->type
->base_type
== GLSL_TYPE_UINT
);
285 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_UINT
);
286 assert(ir
->type
->base_type
== GLSL_TYPE_INT
);
288 case ir_unop_bitcast_i2f
:
289 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_INT
);
290 assert(ir
->type
->base_type
== GLSL_TYPE_FLOAT
);
292 case ir_unop_bitcast_f2i
:
293 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
294 assert(ir
->type
->base_type
== GLSL_TYPE_INT
);
296 case ir_unop_bitcast_u2f
:
297 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_UINT
);
298 assert(ir
->type
->base_type
== GLSL_TYPE_FLOAT
);
300 case ir_unop_bitcast_f2u
:
301 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
302 assert(ir
->type
->base_type
== GLSL_TYPE_UINT
);
306 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_BOOL
);
307 assert(ir
->type
== glsl_type::bool_type
);
311 case ir_unop_round_even
:
317 case ir_unop_sin_reduced
:
318 case ir_unop_cos_reduced
:
320 case ir_unop_dFdx_coarse
:
321 case ir_unop_dFdx_fine
:
323 case ir_unop_dFdy_coarse
:
324 case ir_unop_dFdy_fine
:
325 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
326 assert(ir
->operands
[0]->type
== ir
->type
);
329 case ir_unop_pack_snorm_2x16
:
330 case ir_unop_pack_unorm_2x16
:
331 case ir_unop_pack_half_2x16
:
332 assert(ir
->type
== glsl_type::uint_type
);
333 assert(ir
->operands
[0]->type
== glsl_type::vec2_type
);
336 case ir_unop_pack_snorm_4x8
:
337 case ir_unop_pack_unorm_4x8
:
338 assert(ir
->type
== glsl_type::uint_type
);
339 assert(ir
->operands
[0]->type
== glsl_type::vec4_type
);
342 case ir_unop_unpack_snorm_2x16
:
343 case ir_unop_unpack_unorm_2x16
:
344 case ir_unop_unpack_half_2x16
:
345 assert(ir
->type
== glsl_type::vec2_type
);
346 assert(ir
->operands
[0]->type
== glsl_type::uint_type
);
349 case ir_unop_unpack_snorm_4x8
:
350 case ir_unop_unpack_unorm_4x8
:
351 assert(ir
->type
== glsl_type::vec4_type
);
352 assert(ir
->operands
[0]->type
== glsl_type::uint_type
);
355 case ir_unop_unpack_half_2x16_split_x
:
356 case ir_unop_unpack_half_2x16_split_y
:
357 assert(ir
->type
== glsl_type::float_type
);
358 assert(ir
->operands
[0]->type
== glsl_type::uint_type
);
361 case ir_unop_bitfield_reverse
:
362 assert(ir
->operands
[0]->type
== ir
->type
);
363 assert(ir
->type
->is_integer());
366 case ir_unop_bit_count
:
367 case ir_unop_find_msb
:
368 case ir_unop_find_lsb
:
369 assert(ir
->operands
[0]->type
->vector_elements
== ir
->type
->vector_elements
);
370 assert(ir
->operands
[0]->type
->is_integer());
371 assert(ir
->type
->base_type
== GLSL_TYPE_INT
);
375 /* XXX what can we assert here? */
378 case ir_unop_interpolate_at_centroid
:
379 assert(ir
->operands
[0]->type
== ir
->type
);
380 assert(ir
->operands
[0]->type
->is_float());
391 assert(ir
->operands
[0]->type
->base_type
==
392 ir
->operands
[1]->type
->base_type
);
394 if (ir
->operands
[0]->type
->is_scalar())
395 assert(ir
->operands
[1]->type
== ir
->type
);
396 else if (ir
->operands
[1]->type
->is_scalar())
397 assert(ir
->operands
[0]->type
== ir
->type
);
398 else if (ir
->operands
[0]->type
->is_vector() &&
399 ir
->operands
[1]->type
->is_vector()) {
400 assert(ir
->operands
[0]->type
== ir
->operands
[1]->type
);
401 assert(ir
->operands
[0]->type
== ir
->type
);
405 case ir_binop_imul_high
:
406 assert(ir
->type
== ir
->operands
[0]->type
);
407 assert(ir
->type
== ir
->operands
[1]->type
);
408 assert(ir
->type
->is_integer());
412 case ir_binop_borrow
:
413 assert(ir
->type
== ir
->operands
[0]->type
);
414 assert(ir
->type
== ir
->operands
[1]->type
);
415 assert(ir
->type
->base_type
== GLSL_TYPE_UINT
);
419 case ir_binop_greater
:
420 case ir_binop_lequal
:
421 case ir_binop_gequal
:
423 case ir_binop_nequal
:
424 /* The semantics of the IR operators differ from the GLSL <, >, <=, >=,
425 * ==, and != operators. The IR operators perform a component-wise
426 * comparison on scalar or vector types and return a boolean scalar or
427 * vector type of the same size.
429 assert(ir
->type
->base_type
== GLSL_TYPE_BOOL
);
430 assert(ir
->operands
[0]->type
== ir
->operands
[1]->type
);
431 assert(ir
->operands
[0]->type
->is_vector()
432 || ir
->operands
[0]->type
->is_scalar());
433 assert(ir
->operands
[0]->type
->vector_elements
434 == ir
->type
->vector_elements
);
437 case ir_binop_all_equal
:
438 case ir_binop_any_nequal
:
439 /* GLSL == and != operate on scalars, vectors, matrices and arrays, and
440 * return a scalar boolean. The IR matches that.
442 assert(ir
->type
== glsl_type::bool_type
);
443 assert(ir
->operands
[0]->type
== ir
->operands
[1]->type
);
446 case ir_binop_lshift
:
447 case ir_binop_rshift
:
448 assert(ir
->operands
[0]->type
->is_integer() &&
449 ir
->operands
[1]->type
->is_integer());
450 if (ir
->operands
[0]->type
->is_scalar()) {
451 assert(ir
->operands
[1]->type
->is_scalar());
453 if (ir
->operands
[0]->type
->is_vector() &&
454 ir
->operands
[1]->type
->is_vector()) {
455 assert(ir
->operands
[0]->type
->components() ==
456 ir
->operands
[1]->type
->components());
458 assert(ir
->type
== ir
->operands
[0]->type
);
461 case ir_binop_bit_and
:
462 case ir_binop_bit_xor
:
463 case ir_binop_bit_or
:
464 assert(ir
->operands
[0]->type
->base_type
==
465 ir
->operands
[1]->type
->base_type
);
466 assert(ir
->type
->is_integer());
467 if (ir
->operands
[0]->type
->is_vector() &&
468 ir
->operands
[1]->type
->is_vector()) {
469 assert(ir
->operands
[0]->type
->vector_elements
==
470 ir
->operands
[1]->type
->vector_elements
);
474 case ir_binop_logic_and
:
475 case ir_binop_logic_xor
:
476 case ir_binop_logic_or
:
477 assert(ir
->type
== glsl_type::bool_type
);
478 assert(ir
->operands
[0]->type
== glsl_type::bool_type
);
479 assert(ir
->operands
[1]->type
== glsl_type::bool_type
);
483 assert(ir
->type
== glsl_type::float_type
);
484 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
485 assert(ir
->operands
[0]->type
->is_vector());
486 assert(ir
->operands
[0]->type
== ir
->operands
[1]->type
);
489 case ir_binop_pack_half_2x16_split
:
490 assert(ir
->type
== glsl_type::uint_type
);
491 assert(ir
->operands
[0]->type
== glsl_type::float_type
);
492 assert(ir
->operands
[1]->type
== glsl_type::float_type
);
496 assert(ir
->type
->is_integer());
497 assert(ir
->operands
[0]->type
->is_integer());
498 assert(ir
->operands
[1]->type
->is_integer());
501 case ir_binop_ubo_load
:
502 assert(ir
->operands
[0]->type
== glsl_type::uint_type
);
504 assert(ir
->operands
[1]->type
== glsl_type::uint_type
);
508 assert(ir
->operands
[0]->type
== ir
->type
);
509 assert(ir
->operands
[0]->type
->is_float());
510 assert(ir
->operands
[1]->type
->base_type
== GLSL_TYPE_INT
);
511 assert(ir
->operands
[0]->type
->components() ==
512 ir
->operands
[1]->type
->components());
515 case ir_binop_vector_extract
:
516 assert(ir
->operands
[0]->type
->is_vector());
517 assert(ir
->operands
[1]->type
->is_scalar()
518 && ir
->operands
[1]->type
->is_integer());
521 case ir_binop_interpolate_at_offset
:
522 assert(ir
->operands
[0]->type
== ir
->type
);
523 assert(ir
->operands
[0]->type
->is_float());
524 assert(ir
->operands
[1]->type
->components() == 2);
525 assert(ir
->operands
[1]->type
->is_float());
528 case ir_binop_interpolate_at_sample
:
529 assert(ir
->operands
[0]->type
== ir
->type
);
530 assert(ir
->operands
[0]->type
->is_float());
531 assert(ir
->operands
[1]->type
== glsl_type::int_type
);
535 assert(ir
->type
->base_type
== GLSL_TYPE_FLOAT
);
536 assert(ir
->type
== ir
->operands
[0]->type
);
537 assert(ir
->type
== ir
->operands
[1]->type
);
538 assert(ir
->type
== ir
->operands
[2]->type
);
542 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
543 assert(ir
->operands
[0]->type
== ir
->operands
[1]->type
);
544 assert(ir
->operands
[2]->type
== ir
->operands
[0]->type
|| ir
->operands
[2]->type
== glsl_type::float_type
);
548 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_BOOL
);
549 assert(ir
->type
->vector_elements
== ir
->operands
[0]->type
->vector_elements
);
550 assert(ir
->type
== ir
->operands
[1]->type
);
551 assert(ir
->type
== ir
->operands
[2]->type
);
555 assert(ir
->operands
[0]->type
->is_integer());
556 assert(ir
->operands
[1]->type
== ir
->operands
[2]->type
);
557 assert(ir
->operands
[1]->type
== ir
->type
);
560 case ir_triop_bitfield_extract
:
561 assert(ir
->operands
[0]->type
== ir
->type
);
562 assert(ir
->operands
[1]->type
== glsl_type::int_type
);
563 assert(ir
->operands
[2]->type
== glsl_type::int_type
);
566 case ir_triop_vector_insert
:
567 assert(ir
->operands
[0]->type
->is_vector());
568 assert(ir
->operands
[1]->type
->is_scalar());
569 assert(ir
->operands
[0]->type
->base_type
== ir
->operands
[1]->type
->base_type
);
570 assert(ir
->operands
[2]->type
->is_scalar()
571 && ir
->operands
[2]->type
->is_integer());
572 assert(ir
->type
== ir
->operands
[0]->type
);
575 case ir_quadop_bitfield_insert
:
576 assert(ir
->operands
[0]->type
== ir
->type
);
577 assert(ir
->operands
[1]->type
== ir
->type
);
578 assert(ir
->operands
[2]->type
== glsl_type::int_type
);
579 assert(ir
->operands
[3]->type
== glsl_type::int_type
);
582 case ir_quadop_vector
:
583 /* The vector operator collects some number of scalars and generates a
586 * - All of the operands must be scalar.
587 * - Number of operands must matche the size of the resulting vector.
588 * - Base type of the operands must match the base type of the result.
590 assert(ir
->type
->is_vector());
591 switch (ir
->type
->vector_elements
) {
593 assert(ir
->operands
[0]->type
->is_scalar());
594 assert(ir
->operands
[0]->type
->base_type
== ir
->type
->base_type
);
595 assert(ir
->operands
[1]->type
->is_scalar());
596 assert(ir
->operands
[1]->type
->base_type
== ir
->type
->base_type
);
597 assert(ir
->operands
[2] == NULL
);
598 assert(ir
->operands
[3] == NULL
);
601 assert(ir
->operands
[0]->type
->is_scalar());
602 assert(ir
->operands
[0]->type
->base_type
== ir
->type
->base_type
);
603 assert(ir
->operands
[1]->type
->is_scalar());
604 assert(ir
->operands
[1]->type
->base_type
== ir
->type
->base_type
);
605 assert(ir
->operands
[2]->type
->is_scalar());
606 assert(ir
->operands
[2]->type
->base_type
== ir
->type
->base_type
);
607 assert(ir
->operands
[3] == NULL
);
610 assert(ir
->operands
[0]->type
->is_scalar());
611 assert(ir
->operands
[0]->type
->base_type
== ir
->type
->base_type
);
612 assert(ir
->operands
[1]->type
->is_scalar());
613 assert(ir
->operands
[1]->type
->base_type
== ir
->type
->base_type
);
614 assert(ir
->operands
[2]->type
->is_scalar());
615 assert(ir
->operands
[2]->type
->base_type
== ir
->type
->base_type
);
616 assert(ir
->operands
[3]->type
->is_scalar());
617 assert(ir
->operands
[3]->type
->base_type
== ir
->type
->base_type
);
620 /* The is_vector assertion above should prevent execution from ever
623 assert(!"Should not get here.");
628 return visit_continue
;
632 ir_validate::visit_leave(ir_swizzle
*ir
)
634 unsigned int chans
[4] = {ir
->mask
.x
, ir
->mask
.y
, ir
->mask
.z
, ir
->mask
.w
};
636 for (unsigned int i
= 0; i
< ir
->type
->vector_elements
; i
++) {
637 if (chans
[i
] >= ir
->val
->type
->vector_elements
) {
638 printf("ir_swizzle @ %p specifies a channel not present "
639 "in the value.\n", (void *) ir
);
645 return visit_continue
;
649 ir_validate::visit(ir_variable
*ir
)
651 /* An ir_variable is the one thing that can (and will) appear multiple times
652 * in an IR tree. It is added to the hashtable so that it can be used
653 * in the ir_dereference_variable handler to ensure that a variable is
654 * declared before it is dereferenced.
657 assert(ralloc_parent(ir
->name
) == ir
);
659 hash_table_insert(ht
, ir
, ir
);
662 /* If a variable is an array, verify that the maximum array index is in
663 * bounds. There was once an error in AST-to-HIR conversion that set this
664 * to be out of bounds.
666 if (ir
->type
->array_size() > 0) {
667 if (ir
->data
.max_array_access
>= ir
->type
->length
) {
668 printf("ir_variable has maximum access out of bounds (%d vs %d)\n",
669 ir
->data
.max_array_access
, ir
->type
->length
- 1);
675 /* If a variable is an interface block (or an array of interface blocks),
676 * verify that the maximum array index for each interface member is in
679 if (ir
->is_interface_instance()) {
680 const glsl_struct_field
*fields
=
681 ir
->get_interface_type()->fields
.structure
;
682 for (unsigned i
= 0; i
< ir
->get_interface_type()->length
; i
++) {
683 if (fields
[i
].type
->array_size() > 0) {
684 if (ir
->max_ifc_array_access
[i
] >= fields
[i
].type
->length
) {
685 printf("ir_variable has maximum access out of bounds for "
686 "field %s (%d vs %d)\n", fields
[i
].name
,
687 ir
->max_ifc_array_access
[i
], fields
[i
].type
->length
);
695 if (ir
->constant_initializer
!= NULL
&& !ir
->data
.has_initializer
) {
696 printf("ir_variable didn't have an initializer, but has a constant "
697 "initializer value.\n");
702 return visit_continue
;
706 ir_validate::visit_enter(ir_assignment
*ir
)
708 const ir_dereference
*const lhs
= ir
->lhs
;
709 if (lhs
->type
->is_scalar() || lhs
->type
->is_vector()) {
710 if (ir
->write_mask
== 0) {
711 printf("Assignment LHS is %s, but write mask is 0:\n",
712 lhs
->type
->is_scalar() ? "scalar" : "vector");
717 int lhs_components
= 0;
718 for (int i
= 0; i
< 4; i
++) {
719 if (ir
->write_mask
& (1 << i
))
723 if (lhs_components
!= ir
->rhs
->type
->vector_elements
) {
724 printf("Assignment count of LHS write mask channels enabled not\n"
725 "matching RHS vector size (%d LHS, %d RHS).\n",
726 lhs_components
, ir
->rhs
->type
->vector_elements
);
732 this->validate_ir(ir
, this->data_enter
);
734 return visit_continue
;
738 ir_validate::visit_enter(ir_call
*ir
)
740 ir_function_signature
*const callee
= ir
->callee
;
742 if (callee
->ir_type
!= ir_type_function_signature
) {
743 printf("IR called by ir_call is not ir_function_signature!\n");
747 if (ir
->return_deref
) {
748 if (ir
->return_deref
->type
!= callee
->return_type
) {
749 printf("callee type %s does not match return storage type %s\n",
750 callee
->return_type
->name
, ir
->return_deref
->type
->name
);
753 } else if (callee
->return_type
!= glsl_type::void_type
) {
754 printf("ir_call has non-void callee but no return storage\n");
758 const exec_node
*formal_param_node
= callee
->parameters
.head
;
759 const exec_node
*actual_param_node
= ir
->actual_parameters
.head
;
761 if (formal_param_node
->is_tail_sentinel()
762 != actual_param_node
->is_tail_sentinel()) {
763 printf("ir_call has the wrong number of parameters:\n");
766 if (formal_param_node
->is_tail_sentinel()) {
769 const ir_variable
*formal_param
770 = (const ir_variable
*) formal_param_node
;
771 const ir_rvalue
*actual_param
772 = (const ir_rvalue
*) actual_param_node
;
773 if (formal_param
->type
!= actual_param
->type
) {
774 printf("ir_call parameter type mismatch:\n");
777 if (formal_param
->data
.mode
== ir_var_function_out
778 || formal_param
->data
.mode
== ir_var_function_inout
) {
779 if (!actual_param
->is_lvalue()) {
780 printf("ir_call out/inout parameters must be lvalues:\n");
784 formal_param_node
= formal_param_node
->next
;
785 actual_param_node
= actual_param_node
->next
;
788 return visit_continue
;
799 ir_validate::validate_ir(ir_instruction
*ir
, void *data
)
801 struct hash_table
*ht
= (struct hash_table
*) data
;
803 if (hash_table_find(ht
, ir
)) {
804 printf("Instruction node present twice in ir tree:\n");
809 hash_table_insert(ht
, ir
, ir
);
813 check_node_type(ir_instruction
*ir
, void *data
)
817 if (ir
->ir_type
>= ir_type_max
) {
818 printf("Instruction node with unset type\n");
819 ir
->print(); printf("\n");
821 ir_rvalue
*value
= ir
->as_rvalue();
823 assert(value
->type
!= glsl_type::error_type
);
827 validate_ir_tree(exec_list
*instructions
)
829 /* We shouldn't have any reason to validate IR in a release build,
830 * and it's half composed of assert()s anyway which wouldn't do
838 foreach_in_list(ir_instruction
, ir
, instructions
) {
839 visit_tree(ir
, check_node_type
, NULL
);