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
= ir_validate::validate_ir
;
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_loop
*ir
);
67 virtual ir_visitor_status
visit_leave(ir_loop
*ir
);
68 virtual ir_visitor_status
visit_enter(ir_function
*ir
);
69 virtual ir_visitor_status
visit_leave(ir_function
*ir
);
70 virtual ir_visitor_status
visit_enter(ir_function_signature
*ir
);
72 virtual ir_visitor_status
visit_leave(ir_expression
*ir
);
73 virtual ir_visitor_status
visit_leave(ir_swizzle
*ir
);
75 virtual ir_visitor_status
visit_enter(class ir_dereference_array
*);
77 virtual ir_visitor_status
visit_enter(ir_assignment
*ir
);
78 virtual ir_visitor_status
visit_enter(ir_call
*ir
);
80 static void validate_ir(ir_instruction
*ir
, void *data
);
82 ir_function
*current_function
;
84 struct hash_table
*ht
;
87 } /* anonymous namespace */
90 ir_validate::visit(ir_dereference_variable
*ir
)
92 if ((ir
->var
== NULL
) || (ir
->var
->as_variable() == NULL
)) {
93 printf("ir_dereference_variable @ %p does not specify a variable %p\n",
94 (void *) ir
, (void *) ir
->var
);
98 if (hash_table_find(ht
, ir
->var
) == NULL
) {
99 printf("ir_dereference_variable @ %p specifies undeclared variable "
101 (void *) ir
, ir
->var
->name
, (void *) ir
->var
);
105 this->validate_ir(ir
, this->data
);
107 return visit_continue
;
111 ir_validate::visit_enter(class ir_dereference_array
*ir
)
113 if (!ir
->array
->type
->is_array() && !ir
->array
->type
->is_matrix()) {
114 printf("ir_dereference_array @ %p does not specify an array or a "
122 if (!ir
->array_index
->type
->is_scalar()) {
123 printf("ir_dereference_array @ %p does not have scalar index: %s\n",
124 (void *) ir
, ir
->array_index
->type
->name
);
128 if (!ir
->array_index
->type
->is_integer()) {
129 printf("ir_dereference_array @ %p does not have integer index: %s\n",
130 (void *) ir
, ir
->array_index
->type
->name
);
134 return visit_continue
;
138 ir_validate::visit_enter(ir_if
*ir
)
140 if (ir
->condition
->type
!= glsl_type::bool_type
) {
141 printf("ir_if condition %s type instead of bool.\n",
142 ir
->condition
->type
->name
);
148 return visit_continue
;
153 ir_validate::visit_enter(ir_loop
*ir
)
155 if (ir
->counter
!= NULL
&& hash_table_find(ht
, ir
->counter
) != NULL
) {
156 printf("ir_loop @ %p specifies already-declared variable `%s' @ %p\n",
157 (void *) ir
, ir
->counter
->name
, (void *) ir
->counter
);
160 return visit_continue
;
165 ir_validate::visit_leave(ir_loop
*ir
)
167 if (ir
->counter
!= NULL
) {
168 if ((ir
->from
== NULL
) || (ir
->to
== NULL
) || (ir
->increment
== NULL
)) {
169 printf("ir_loop has invalid loop controls:\n"
174 (void *) ir
->counter
, (void *) ir
->from
, (void *) ir
->to
,
175 (void *) ir
->increment
);
179 if ((ir
->cmp
< ir_binop_less
) || (ir
->cmp
> ir_binop_nequal
)) {
180 printf("ir_loop has invalid comparitor %d\n", ir
->cmp
);
184 if ((ir
->from
!= NULL
) || (ir
->to
!= NULL
) || (ir
->increment
!= NULL
)) {
185 printf("ir_loop has invalid loop controls:\n"
190 (void *) ir
->counter
, (void *) ir
->from
, (void *) ir
->to
,
191 (void *) ir
->increment
);
196 return visit_continue
;
201 ir_validate::visit_enter(ir_function
*ir
)
203 /* Function definitions cannot be nested.
205 if (this->current_function
!= NULL
) {
206 printf("Function definition nested inside another function "
208 printf("%s %p inside %s %p\n",
209 ir
->name
, (void *) ir
,
210 this->current_function
->name
, (void *) this->current_function
);
214 /* Store the current function hierarchy being traversed. This is used
215 * by the function signature visitor to ensure that the signatures are
216 * linked with the correct functions.
218 this->current_function
= ir
;
220 this->validate_ir(ir
, this->data
);
222 /* Verify that all of the things stored in the list of signatures are,
223 * in fact, function signatures.
225 foreach_list(node
, &ir
->signatures
) {
226 ir_instruction
*sig
= (ir_instruction
*) node
;
228 if (sig
->ir_type
!= ir_type_function_signature
) {
229 printf("Non-signature in signature list of function `%s'\n",
235 return visit_continue
;
239 ir_validate::visit_leave(ir_function
*ir
)
241 assert(ralloc_parent(ir
->name
) == ir
);
243 this->current_function
= NULL
;
244 return visit_continue
;
248 ir_validate::visit_enter(ir_function_signature
*ir
)
250 if (this->current_function
!= ir
->function()) {
251 printf("Function signature nested inside wrong function "
253 printf("%p inside %s %p instead of %s %p\n",
255 this->current_function
->name
, (void *) this->current_function
,
256 ir
->function_name(), (void *) ir
->function());
260 if (ir
->return_type
== NULL
) {
261 printf("Function signature %p for function %s has NULL return type.\n",
262 (void *) ir
, ir
->function_name());
266 this->validate_ir(ir
, this->data
);
268 return visit_continue
;
272 ir_validate::visit_leave(ir_expression
*ir
)
274 switch (ir
->operation
) {
275 case ir_unop_bit_not
:
276 assert(ir
->operands
[0]->type
== ir
->type
);
278 case ir_unop_logic_not
:
279 assert(ir
->type
->base_type
== GLSL_TYPE_BOOL
);
280 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_BOOL
);
289 assert(ir
->type
== ir
->operands
[0]->type
);
296 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
297 assert(ir
->type
== ir
->operands
[0]->type
);
301 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
302 assert(ir
->type
->base_type
== GLSL_TYPE_INT
);
305 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
306 assert(ir
->type
->base_type
== GLSL_TYPE_UINT
);
309 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_INT
);
310 assert(ir
->type
->base_type
== GLSL_TYPE_FLOAT
);
313 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
314 assert(ir
->type
->base_type
== GLSL_TYPE_BOOL
);
317 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_BOOL
);
318 assert(ir
->type
->base_type
== GLSL_TYPE_FLOAT
);
321 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_INT
);
322 assert(ir
->type
->base_type
== GLSL_TYPE_BOOL
);
325 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_BOOL
);
326 assert(ir
->type
->base_type
== GLSL_TYPE_INT
);
329 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_UINT
);
330 assert(ir
->type
->base_type
== GLSL_TYPE_FLOAT
);
333 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_INT
);
334 assert(ir
->type
->base_type
== GLSL_TYPE_UINT
);
337 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_UINT
);
338 assert(ir
->type
->base_type
== GLSL_TYPE_INT
);
340 case ir_unop_bitcast_i2f
:
341 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_INT
);
342 assert(ir
->type
->base_type
== GLSL_TYPE_FLOAT
);
344 case ir_unop_bitcast_f2i
:
345 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
346 assert(ir
->type
->base_type
== GLSL_TYPE_INT
);
348 case ir_unop_bitcast_u2f
:
349 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_UINT
);
350 assert(ir
->type
->base_type
== GLSL_TYPE_FLOAT
);
352 case ir_unop_bitcast_f2u
:
353 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
354 assert(ir
->type
->base_type
== GLSL_TYPE_UINT
);
358 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_BOOL
);
359 assert(ir
->type
== glsl_type::bool_type
);
363 case ir_unop_round_even
:
369 case ir_unop_sin_reduced
:
370 case ir_unop_cos_reduced
:
373 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
374 assert(ir
->operands
[0]->type
== ir
->type
);
377 case ir_unop_pack_snorm_2x16
:
378 case ir_unop_pack_unorm_2x16
:
379 case ir_unop_pack_half_2x16
:
380 assert(ir
->type
== glsl_type::uint_type
);
381 assert(ir
->operands
[0]->type
== glsl_type::vec2_type
);
384 case ir_unop_pack_snorm_4x8
:
385 case ir_unop_pack_unorm_4x8
:
386 assert(ir
->type
== glsl_type::uint_type
);
387 assert(ir
->operands
[0]->type
== glsl_type::vec4_type
);
390 case ir_unop_unpack_snorm_2x16
:
391 case ir_unop_unpack_unorm_2x16
:
392 case ir_unop_unpack_half_2x16
:
393 assert(ir
->type
== glsl_type::vec2_type
);
394 assert(ir
->operands
[0]->type
== glsl_type::uint_type
);
397 case ir_unop_unpack_snorm_4x8
:
398 case ir_unop_unpack_unorm_4x8
:
399 assert(ir
->type
== glsl_type::vec4_type
);
400 assert(ir
->operands
[0]->type
== glsl_type::uint_type
);
403 case ir_unop_unpack_half_2x16_split_x
:
404 case ir_unop_unpack_half_2x16_split_y
:
405 assert(ir
->type
== glsl_type::float_type
);
406 assert(ir
->operands
[0]->type
== glsl_type::uint_type
);
409 case ir_unop_bitfield_reverse
:
410 assert(ir
->operands
[0]->type
== ir
->type
);
411 assert(ir
->type
->is_integer());
414 case ir_unop_bit_count
:
415 case ir_unop_find_msb
:
416 case ir_unop_find_lsb
:
417 assert(ir
->operands
[0]->type
->vector_elements
== ir
->type
->vector_elements
);
418 assert(ir
->operands
[0]->type
->is_integer());
419 assert(ir
->type
->base_type
== GLSL_TYPE_INT
);
423 /* XXX what can we assert here? */
434 if (ir
->operands
[0]->type
->is_scalar())
435 assert(ir
->operands
[1]->type
== ir
->type
);
436 else if (ir
->operands
[1]->type
->is_scalar())
437 assert(ir
->operands
[0]->type
== ir
->type
);
438 else if (ir
->operands
[0]->type
->is_vector() &&
439 ir
->operands
[1]->type
->is_vector()) {
440 assert(ir
->operands
[0]->type
== ir
->operands
[1]->type
);
441 assert(ir
->operands
[0]->type
== ir
->type
);
445 case ir_binop_imul_high
:
446 assert(ir
->type
== ir
->operands
[0]->type
);
447 assert(ir
->type
== ir
->operands
[1]->type
);
448 assert(ir
->type
->is_integer());
452 case ir_binop_borrow
:
453 assert(ir
->type
== ir
->operands
[0]->type
);
454 assert(ir
->type
== ir
->operands
[1]->type
);
455 assert(ir
->type
->base_type
== GLSL_TYPE_UINT
);
459 case ir_binop_greater
:
460 case ir_binop_lequal
:
461 case ir_binop_gequal
:
463 case ir_binop_nequal
:
464 /* The semantics of the IR operators differ from the GLSL <, >, <=, >=,
465 * ==, and != operators. The IR operators perform a component-wise
466 * comparison on scalar or vector types and return a boolean scalar or
467 * vector type of the same size.
469 assert(ir
->type
->base_type
== GLSL_TYPE_BOOL
);
470 assert(ir
->operands
[0]->type
== ir
->operands
[1]->type
);
471 assert(ir
->operands
[0]->type
->is_vector()
472 || ir
->operands
[0]->type
->is_scalar());
473 assert(ir
->operands
[0]->type
->vector_elements
474 == ir
->type
->vector_elements
);
477 case ir_binop_all_equal
:
478 case ir_binop_any_nequal
:
479 /* GLSL == and != operate on scalars, vectors, matrices and arrays, and
480 * return a scalar boolean. The IR matches that.
482 assert(ir
->type
== glsl_type::bool_type
);
483 assert(ir
->operands
[0]->type
== ir
->operands
[1]->type
);
486 case ir_binop_lshift
:
487 case ir_binop_rshift
:
488 assert(ir
->operands
[0]->type
->is_integer() &&
489 ir
->operands
[1]->type
->is_integer());
490 if (ir
->operands
[0]->type
->is_scalar()) {
491 assert(ir
->operands
[1]->type
->is_scalar());
493 if (ir
->operands
[0]->type
->is_vector() &&
494 ir
->operands
[1]->type
->is_vector()) {
495 assert(ir
->operands
[0]->type
->components() ==
496 ir
->operands
[1]->type
->components());
498 assert(ir
->type
== ir
->operands
[0]->type
);
501 case ir_binop_bit_and
:
502 case ir_binop_bit_xor
:
503 case ir_binop_bit_or
:
504 assert(ir
->operands
[0]->type
->base_type
==
505 ir
->operands
[1]->type
->base_type
);
506 assert(ir
->type
->is_integer());
507 if (ir
->operands
[0]->type
->is_vector() &&
508 ir
->operands
[1]->type
->is_vector()) {
509 assert(ir
->operands
[0]->type
->vector_elements
==
510 ir
->operands
[1]->type
->vector_elements
);
514 case ir_binop_logic_and
:
515 case ir_binop_logic_xor
:
516 case ir_binop_logic_or
:
517 assert(ir
->type
== glsl_type::bool_type
);
518 assert(ir
->operands
[0]->type
== glsl_type::bool_type
);
519 assert(ir
->operands
[1]->type
== glsl_type::bool_type
);
523 assert(ir
->type
== glsl_type::float_type
);
524 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
525 assert(ir
->operands
[0]->type
->is_vector());
526 assert(ir
->operands
[0]->type
== ir
->operands
[1]->type
);
529 case ir_binop_pack_half_2x16_split
:
530 assert(ir
->type
== glsl_type::uint_type
);
531 assert(ir
->operands
[0]->type
== glsl_type::float_type
);
532 assert(ir
->operands
[1]->type
== glsl_type::float_type
);
536 assert(ir
->type
->is_integer());
537 assert(ir
->operands
[0]->type
->is_integer());
538 assert(ir
->operands
[1]->type
->is_integer());
541 case ir_binop_ubo_load
:
542 assert(ir
->operands
[0]->as_constant());
543 assert(ir
->operands
[0]->type
== glsl_type::uint_type
);
545 assert(ir
->operands
[1]->type
== glsl_type::uint_type
);
549 assert(ir
->operands
[0]->type
== ir
->type
);
550 assert(ir
->operands
[0]->type
->is_float());
551 assert(ir
->operands
[1]->type
->base_type
== GLSL_TYPE_INT
);
552 assert(ir
->operands
[0]->type
->components() ==
553 ir
->operands
[1]->type
->components());
556 case ir_binop_vector_extract
:
557 assert(ir
->operands
[0]->type
->is_vector());
558 assert(ir
->operands
[1]->type
->is_scalar()
559 && ir
->operands
[1]->type
->is_integer());
563 assert(ir
->type
->base_type
== GLSL_TYPE_FLOAT
);
564 assert(ir
->type
== ir
->operands
[0]->type
);
565 assert(ir
->type
== ir
->operands
[1]->type
);
566 assert(ir
->type
== ir
->operands
[2]->type
);
570 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
571 assert(ir
->operands
[0]->type
== ir
->operands
[1]->type
);
572 assert(ir
->operands
[2]->type
== ir
->operands
[0]->type
|| ir
->operands
[2]->type
== glsl_type::float_type
);
576 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_BOOL
);
577 assert(ir
->type
->vector_elements
== ir
->operands
[0]->type
->vector_elements
);
578 assert(ir
->type
== ir
->operands
[1]->type
);
579 assert(ir
->type
== ir
->operands
[2]->type
);
583 assert(ir
->operands
[0]->type
->is_integer());
584 assert(ir
->operands
[1]->type
== ir
->operands
[2]->type
);
585 assert(ir
->operands
[1]->type
== ir
->type
);
588 case ir_triop_bitfield_extract
:
589 assert(ir
->operands
[0]->type
== ir
->type
);
590 assert(ir
->operands
[1]->type
== glsl_type::int_type
);
591 assert(ir
->operands
[2]->type
== glsl_type::int_type
);
594 case ir_triop_vector_insert
:
595 assert(ir
->operands
[0]->type
->is_vector());
596 assert(ir
->operands
[1]->type
->is_scalar());
597 assert(ir
->operands
[0]->type
->base_type
== ir
->operands
[1]->type
->base_type
);
598 assert(ir
->operands
[2]->type
->is_scalar()
599 && ir
->operands
[2]->type
->is_integer());
600 assert(ir
->type
== ir
->operands
[0]->type
);
603 case ir_quadop_bitfield_insert
:
604 assert(ir
->operands
[0]->type
== ir
->type
);
605 assert(ir
->operands
[1]->type
== ir
->type
);
606 assert(ir
->operands
[2]->type
== glsl_type::int_type
);
607 assert(ir
->operands
[3]->type
== glsl_type::int_type
);
610 case ir_quadop_vector
:
611 /* The vector operator collects some number of scalars and generates a
614 * - All of the operands must be scalar.
615 * - Number of operands must matche the size of the resulting vector.
616 * - Base type of the operands must match the base type of the result.
618 assert(ir
->type
->is_vector());
619 switch (ir
->type
->vector_elements
) {
621 assert(ir
->operands
[0]->type
->is_scalar());
622 assert(ir
->operands
[0]->type
->base_type
== ir
->type
->base_type
);
623 assert(ir
->operands
[1]->type
->is_scalar());
624 assert(ir
->operands
[1]->type
->base_type
== ir
->type
->base_type
);
625 assert(ir
->operands
[2] == NULL
);
626 assert(ir
->operands
[3] == NULL
);
629 assert(ir
->operands
[0]->type
->is_scalar());
630 assert(ir
->operands
[0]->type
->base_type
== ir
->type
->base_type
);
631 assert(ir
->operands
[1]->type
->is_scalar());
632 assert(ir
->operands
[1]->type
->base_type
== ir
->type
->base_type
);
633 assert(ir
->operands
[2]->type
->is_scalar());
634 assert(ir
->operands
[2]->type
->base_type
== ir
->type
->base_type
);
635 assert(ir
->operands
[3] == NULL
);
638 assert(ir
->operands
[0]->type
->is_scalar());
639 assert(ir
->operands
[0]->type
->base_type
== ir
->type
->base_type
);
640 assert(ir
->operands
[1]->type
->is_scalar());
641 assert(ir
->operands
[1]->type
->base_type
== ir
->type
->base_type
);
642 assert(ir
->operands
[2]->type
->is_scalar());
643 assert(ir
->operands
[2]->type
->base_type
== ir
->type
->base_type
);
644 assert(ir
->operands
[3]->type
->is_scalar());
645 assert(ir
->operands
[3]->type
->base_type
== ir
->type
->base_type
);
648 /* The is_vector assertion above should prevent execution from ever
651 assert(!"Should not get here.");
656 return visit_continue
;
660 ir_validate::visit_leave(ir_swizzle
*ir
)
662 unsigned int chans
[4] = {ir
->mask
.x
, ir
->mask
.y
, ir
->mask
.z
, ir
->mask
.w
};
664 for (unsigned int i
= 0; i
< ir
->type
->vector_elements
; i
++) {
665 if (chans
[i
] >= ir
->val
->type
->vector_elements
) {
666 printf("ir_swizzle @ %p specifies a channel not present "
667 "in the value.\n", (void *) ir
);
673 return visit_continue
;
677 ir_validate::visit(ir_variable
*ir
)
679 /* An ir_variable is the one thing that can (and will) appear multiple times
680 * in an IR tree. It is added to the hashtable so that it can be used
681 * in the ir_dereference_variable handler to ensure that a variable is
682 * declared before it is dereferenced.
685 assert(ralloc_parent(ir
->name
) == ir
);
687 hash_table_insert(ht
, ir
, ir
);
690 /* If a variable is an array, verify that the maximum array index is in
691 * bounds. There was once an error in AST-to-HIR conversion that set this
692 * to be out of bounds.
694 if (ir
->type
->array_size() > 0) {
695 if (ir
->max_array_access
>= ir
->type
->length
) {
696 printf("ir_variable has maximum access out of bounds (%d vs %d)\n",
697 ir
->max_array_access
, ir
->type
->length
- 1);
703 /* If a variable is an interface block (or an array of interface blocks),
704 * verify that the maximum array index for each interface member is in
707 if (ir
->is_interface_instance()) {
708 const glsl_struct_field
*fields
=
709 ir
->get_interface_type()->fields
.structure
;
710 for (unsigned i
= 0; i
< ir
->get_interface_type()->length
; i
++) {
711 if (fields
[i
].type
->array_size() > 0) {
712 if (ir
->max_ifc_array_access
[i
] >= fields
[i
].type
->length
) {
713 printf("ir_variable has maximum access out of bounds for "
714 "field %s (%d vs %d)\n", fields
[i
].name
,
715 ir
->max_ifc_array_access
[i
], fields
[i
].type
->length
);
723 if (ir
->constant_initializer
!= NULL
&& !ir
->has_initializer
) {
724 printf("ir_variable didn't have an initializer, but has a constant "
725 "initializer value.\n");
730 return visit_continue
;
734 ir_validate::visit_enter(ir_assignment
*ir
)
736 const ir_dereference
*const lhs
= ir
->lhs
;
737 if (lhs
->type
->is_scalar() || lhs
->type
->is_vector()) {
738 if (ir
->write_mask
== 0) {
739 printf("Assignment LHS is %s, but write mask is 0:\n",
740 lhs
->type
->is_scalar() ? "scalar" : "vector");
745 int lhs_components
= 0;
746 for (int i
= 0; i
< 4; i
++) {
747 if (ir
->write_mask
& (1 << i
))
751 if (lhs_components
!= ir
->rhs
->type
->vector_elements
) {
752 printf("Assignment count of LHS write mask channels enabled not\n"
753 "matching RHS vector size (%d LHS, %d RHS).\n",
754 lhs_components
, ir
->rhs
->type
->vector_elements
);
760 this->validate_ir(ir
, this->data
);
762 return visit_continue
;
766 ir_validate::visit_enter(ir_call
*ir
)
768 ir_function_signature
*const callee
= ir
->callee
;
770 if (callee
->ir_type
!= ir_type_function_signature
) {
771 printf("IR called by ir_call is not ir_function_signature!\n");
775 if (ir
->return_deref
) {
776 if (ir
->return_deref
->type
!= callee
->return_type
) {
777 printf("callee type %s does not match return storage type %s\n",
778 callee
->return_type
->name
, ir
->return_deref
->type
->name
);
781 } else if (callee
->return_type
!= glsl_type::void_type
) {
782 printf("ir_call has non-void callee but no return storage\n");
786 const exec_node
*formal_param_node
= callee
->parameters
.head
;
787 const exec_node
*actual_param_node
= ir
->actual_parameters
.head
;
789 if (formal_param_node
->is_tail_sentinel()
790 != actual_param_node
->is_tail_sentinel()) {
791 printf("ir_call has the wrong number of parameters:\n");
794 if (formal_param_node
->is_tail_sentinel()) {
797 const ir_variable
*formal_param
798 = (const ir_variable
*) formal_param_node
;
799 const ir_rvalue
*actual_param
800 = (const ir_rvalue
*) actual_param_node
;
801 if (formal_param
->type
!= actual_param
->type
) {
802 printf("ir_call parameter type mismatch:\n");
805 if (formal_param
->mode
== ir_var_function_out
806 || formal_param
->mode
== ir_var_function_inout
) {
807 if (!actual_param
->is_lvalue()) {
808 printf("ir_call out/inout parameters must be lvalues:\n");
812 formal_param_node
= formal_param_node
->next
;
813 actual_param_node
= actual_param_node
->next
;
816 return visit_continue
;
827 ir_validate::validate_ir(ir_instruction
*ir
, void *data
)
829 struct hash_table
*ht
= (struct hash_table
*) data
;
831 if (hash_table_find(ht
, ir
)) {
832 printf("Instruction node present twice in ir tree:\n");
837 hash_table_insert(ht
, ir
, ir
);
841 check_node_type(ir_instruction
*ir
, void *data
)
845 if (ir
->ir_type
<= ir_type_unset
|| ir
->ir_type
>= ir_type_max
) {
846 printf("Instruction node with unset type\n");
847 ir
->print(); printf("\n");
849 ir_rvalue
*value
= ir
->as_rvalue();
851 assert(value
->type
!= glsl_type::error_type
);
855 validate_ir_tree(exec_list
*instructions
)
857 /* We shouldn't have any reason to validate IR in a release build,
858 * and it's half composed of assert()s anyway which wouldn't do
866 foreach_iter(exec_list_iterator
, iter
, *instructions
) {
867 ir_instruction
*ir
= (ir_instruction
*)iter
.get();
869 visit_tree(ir
, check_node_type
, NULL
);