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_leave(ir_loop
*ir
);
67 virtual ir_visitor_status
visit_enter(ir_function
*ir
);
68 virtual ir_visitor_status
visit_leave(ir_function
*ir
);
69 virtual ir_visitor_status
visit_enter(ir_function_signature
*ir
);
71 virtual ir_visitor_status
visit_leave(ir_expression
*ir
);
72 virtual ir_visitor_status
visit_leave(ir_swizzle
*ir
);
74 virtual ir_visitor_status
visit_enter(class ir_dereference_array
*);
76 virtual ir_visitor_status
visit_enter(ir_assignment
*ir
);
77 virtual ir_visitor_status
visit_enter(ir_call
*ir
);
79 static void validate_ir(ir_instruction
*ir
, void *data
);
81 ir_function
*current_function
;
83 struct hash_table
*ht
;
86 } /* anonymous namespace */
89 ir_validate::visit(ir_dereference_variable
*ir
)
91 if ((ir
->var
== NULL
) || (ir
->var
->as_variable() == NULL
)) {
92 printf("ir_dereference_variable @ %p does not specify a variable %p\n",
93 (void *) ir
, (void *) ir
->var
);
97 if (hash_table_find(ht
, ir
->var
) == NULL
) {
98 printf("ir_dereference_variable @ %p specifies undeclared variable "
100 (void *) ir
, ir
->var
->name
, (void *) ir
->var
);
104 this->validate_ir(ir
, this->data
);
106 return visit_continue
;
110 ir_validate::visit_enter(class ir_dereference_array
*ir
)
112 if (!ir
->array
->type
->is_array() && !ir
->array
->type
->is_matrix()) {
113 printf("ir_dereference_array @ %p does not specify an array or a "
121 if (!ir
->array_index
->type
->is_scalar()) {
122 printf("ir_dereference_array @ %p does not have scalar index: %s\n",
123 (void *) ir
, ir
->array_index
->type
->name
);
127 if (!ir
->array_index
->type
->is_integer()) {
128 printf("ir_dereference_array @ %p does not have integer index: %s\n",
129 (void *) ir
, ir
->array_index
->type
->name
);
133 return visit_continue
;
137 ir_validate::visit_enter(ir_if
*ir
)
139 if (ir
->condition
->type
!= glsl_type::bool_type
) {
140 printf("ir_if condition %s type instead of bool.\n",
141 ir
->condition
->type
->name
);
147 return visit_continue
;
152 ir_validate::visit_leave(ir_loop
*ir
)
154 if (ir
->counter
!= NULL
) {
155 if ((ir
->from
== NULL
) || (ir
->to
== NULL
) || (ir
->increment
== NULL
)) {
156 printf("ir_loop has invalid loop controls:\n"
161 (void *) ir
->counter
, (void *) ir
->from
, (void *) ir
->to
,
162 (void *) ir
->increment
);
166 if ((ir
->cmp
< ir_binop_less
) || (ir
->cmp
> ir_binop_nequal
)) {
167 printf("ir_loop has invalid comparitor %d\n", ir
->cmp
);
171 if ((ir
->from
!= NULL
) || (ir
->to
!= NULL
) || (ir
->increment
!= NULL
)) {
172 printf("ir_loop has invalid loop controls:\n"
177 (void *) ir
->counter
, (void *) ir
->from
, (void *) ir
->to
,
178 (void *) ir
->increment
);
183 return visit_continue
;
188 ir_validate::visit_enter(ir_function
*ir
)
190 /* Function definitions cannot be nested.
192 if (this->current_function
!= NULL
) {
193 printf("Function definition nested inside another function "
195 printf("%s %p inside %s %p\n",
196 ir
->name
, (void *) ir
,
197 this->current_function
->name
, (void *) this->current_function
);
201 /* Store the current function hierarchy being traversed. This is used
202 * by the function signature visitor to ensure that the signatures are
203 * linked with the correct functions.
205 this->current_function
= ir
;
207 this->validate_ir(ir
, this->data
);
209 /* Verify that all of the things stored in the list of signatures are,
210 * in fact, function signatures.
212 foreach_list(node
, &ir
->signatures
) {
213 ir_instruction
*sig
= (ir_instruction
*) node
;
215 if (sig
->ir_type
!= ir_type_function_signature
) {
216 printf("Non-signature in signature list of function `%s'\n",
222 return visit_continue
;
226 ir_validate::visit_leave(ir_function
*ir
)
228 assert(ralloc_parent(ir
->name
) == ir
);
230 this->current_function
= NULL
;
231 return visit_continue
;
235 ir_validate::visit_enter(ir_function_signature
*ir
)
237 if (this->current_function
!= ir
->function()) {
238 printf("Function signature nested inside wrong function "
240 printf("%p inside %s %p instead of %s %p\n",
242 this->current_function
->name
, (void *) this->current_function
,
243 ir
->function_name(), (void *) ir
->function());
247 if (ir
->return_type
== NULL
) {
248 printf("Function signature %p for function %s has NULL return type.\n",
249 (void *) ir
, ir
->function_name());
253 this->validate_ir(ir
, this->data
);
255 return visit_continue
;
259 ir_validate::visit_leave(ir_expression
*ir
)
261 switch (ir
->operation
) {
262 case ir_unop_bit_not
:
263 assert(ir
->operands
[0]->type
== ir
->type
);
265 case ir_unop_logic_not
:
266 assert(ir
->type
->base_type
== GLSL_TYPE_BOOL
);
267 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_BOOL
);
276 assert(ir
->type
== ir
->operands
[0]->type
);
283 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
284 assert(ir
->type
== ir
->operands
[0]->type
);
288 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
289 assert(ir
->type
->base_type
== GLSL_TYPE_INT
);
292 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
293 assert(ir
->type
->base_type
== GLSL_TYPE_UINT
);
296 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_INT
);
297 assert(ir
->type
->base_type
== GLSL_TYPE_FLOAT
);
300 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
301 assert(ir
->type
->base_type
== GLSL_TYPE_BOOL
);
304 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_BOOL
);
305 assert(ir
->type
->base_type
== GLSL_TYPE_FLOAT
);
308 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_INT
);
309 assert(ir
->type
->base_type
== GLSL_TYPE_BOOL
);
312 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_BOOL
);
313 assert(ir
->type
->base_type
== GLSL_TYPE_INT
);
316 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_UINT
);
317 assert(ir
->type
->base_type
== GLSL_TYPE_FLOAT
);
320 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_INT
);
321 assert(ir
->type
->base_type
== GLSL_TYPE_UINT
);
324 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_UINT
);
325 assert(ir
->type
->base_type
== GLSL_TYPE_INT
);
327 case ir_unop_bitcast_i2f
:
328 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_INT
);
329 assert(ir
->type
->base_type
== GLSL_TYPE_FLOAT
);
331 case ir_unop_bitcast_f2i
:
332 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
333 assert(ir
->type
->base_type
== GLSL_TYPE_INT
);
335 case ir_unop_bitcast_u2f
:
336 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_UINT
);
337 assert(ir
->type
->base_type
== GLSL_TYPE_FLOAT
);
339 case ir_unop_bitcast_f2u
:
340 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
341 assert(ir
->type
->base_type
== GLSL_TYPE_UINT
);
345 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_BOOL
);
346 assert(ir
->type
== glsl_type::bool_type
);
350 case ir_unop_round_even
:
356 case ir_unop_sin_reduced
:
357 case ir_unop_cos_reduced
:
360 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
361 assert(ir
->operands
[0]->type
== ir
->type
);
364 case ir_unop_pack_snorm_2x16
:
365 case ir_unop_pack_unorm_2x16
:
366 case ir_unop_pack_half_2x16
:
367 assert(ir
->type
== glsl_type::uint_type
);
368 assert(ir
->operands
[0]->type
== glsl_type::vec2_type
);
371 case ir_unop_pack_snorm_4x8
:
372 case ir_unop_pack_unorm_4x8
:
373 assert(ir
->type
== glsl_type::uint_type
);
374 assert(ir
->operands
[0]->type
== glsl_type::vec4_type
);
377 case ir_unop_unpack_snorm_2x16
:
378 case ir_unop_unpack_unorm_2x16
:
379 case ir_unop_unpack_half_2x16
:
380 assert(ir
->type
== glsl_type::vec2_type
);
381 assert(ir
->operands
[0]->type
== glsl_type::uint_type
);
384 case ir_unop_unpack_snorm_4x8
:
385 case ir_unop_unpack_unorm_4x8
:
386 assert(ir
->type
== glsl_type::vec4_type
);
387 assert(ir
->operands
[0]->type
== glsl_type::uint_type
);
390 case ir_unop_unpack_half_2x16_split_x
:
391 case ir_unop_unpack_half_2x16_split_y
:
392 assert(ir
->type
== glsl_type::float_type
);
393 assert(ir
->operands
[0]->type
== glsl_type::uint_type
);
396 case ir_unop_bitfield_reverse
:
397 assert(ir
->operands
[0]->type
== ir
->type
);
398 assert(ir
->type
->is_integer());
401 case ir_unop_bit_count
:
402 case ir_unop_find_msb
:
403 case ir_unop_find_lsb
:
404 assert(ir
->operands
[0]->type
->vector_elements
== ir
->type
->vector_elements
);
405 assert(ir
->operands
[0]->type
->is_integer());
406 assert(ir
->type
->base_type
== GLSL_TYPE_INT
);
410 /* XXX what can we assert here? */
421 if (ir
->operands
[0]->type
->is_scalar())
422 assert(ir
->operands
[1]->type
== ir
->type
);
423 else if (ir
->operands
[1]->type
->is_scalar())
424 assert(ir
->operands
[0]->type
== ir
->type
);
425 else if (ir
->operands
[0]->type
->is_vector() &&
426 ir
->operands
[1]->type
->is_vector()) {
427 assert(ir
->operands
[0]->type
== ir
->operands
[1]->type
);
428 assert(ir
->operands
[0]->type
== ir
->type
);
432 case ir_binop_imul_high
:
433 assert(ir
->type
== ir
->operands
[0]->type
);
434 assert(ir
->type
== ir
->operands
[1]->type
);
435 assert(ir
->type
->is_integer());
439 case ir_binop_borrow
:
440 assert(ir
->type
== ir
->operands
[0]->type
);
441 assert(ir
->type
== ir
->operands
[1]->type
);
442 assert(ir
->type
->base_type
== GLSL_TYPE_UINT
);
446 case ir_binop_greater
:
447 case ir_binop_lequal
:
448 case ir_binop_gequal
:
450 case ir_binop_nequal
:
451 /* The semantics of the IR operators differ from the GLSL <, >, <=, >=,
452 * ==, and != operators. The IR operators perform a component-wise
453 * comparison on scalar or vector types and return a boolean scalar or
454 * vector type of the same size.
456 assert(ir
->type
->base_type
== GLSL_TYPE_BOOL
);
457 assert(ir
->operands
[0]->type
== ir
->operands
[1]->type
);
458 assert(ir
->operands
[0]->type
->is_vector()
459 || ir
->operands
[0]->type
->is_scalar());
460 assert(ir
->operands
[0]->type
->vector_elements
461 == ir
->type
->vector_elements
);
464 case ir_binop_all_equal
:
465 case ir_binop_any_nequal
:
466 /* GLSL == and != operate on scalars, vectors, matrices and arrays, and
467 * return a scalar boolean. The IR matches that.
469 assert(ir
->type
== glsl_type::bool_type
);
470 assert(ir
->operands
[0]->type
== ir
->operands
[1]->type
);
473 case ir_binop_lshift
:
474 case ir_binop_rshift
:
475 assert(ir
->operands
[0]->type
->is_integer() &&
476 ir
->operands
[1]->type
->is_integer());
477 if (ir
->operands
[0]->type
->is_scalar()) {
478 assert(ir
->operands
[1]->type
->is_scalar());
480 if (ir
->operands
[0]->type
->is_vector() &&
481 ir
->operands
[1]->type
->is_vector()) {
482 assert(ir
->operands
[0]->type
->components() ==
483 ir
->operands
[1]->type
->components());
485 assert(ir
->type
== ir
->operands
[0]->type
);
488 case ir_binop_bit_and
:
489 case ir_binop_bit_xor
:
490 case ir_binop_bit_or
:
491 assert(ir
->operands
[0]->type
->base_type
==
492 ir
->operands
[1]->type
->base_type
);
493 assert(ir
->type
->is_integer());
494 if (ir
->operands
[0]->type
->is_vector() &&
495 ir
->operands
[1]->type
->is_vector()) {
496 assert(ir
->operands
[0]->type
->vector_elements
==
497 ir
->operands
[1]->type
->vector_elements
);
501 case ir_binop_logic_and
:
502 case ir_binop_logic_xor
:
503 case ir_binop_logic_or
:
504 assert(ir
->type
== glsl_type::bool_type
);
505 assert(ir
->operands
[0]->type
== glsl_type::bool_type
);
506 assert(ir
->operands
[1]->type
== glsl_type::bool_type
);
510 assert(ir
->type
== glsl_type::float_type
);
511 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
512 assert(ir
->operands
[0]->type
->is_vector());
513 assert(ir
->operands
[0]->type
== ir
->operands
[1]->type
);
516 case ir_binop_pack_half_2x16_split
:
517 assert(ir
->type
== glsl_type::uint_type
);
518 assert(ir
->operands
[0]->type
== glsl_type::float_type
);
519 assert(ir
->operands
[1]->type
== glsl_type::float_type
);
523 assert(ir
->type
->is_integer());
524 assert(ir
->operands
[0]->type
->is_integer());
525 assert(ir
->operands
[1]->type
->is_integer());
528 case ir_binop_ubo_load
:
529 assert(ir
->operands
[0]->as_constant());
530 assert(ir
->operands
[0]->type
== glsl_type::uint_type
);
532 assert(ir
->operands
[1]->type
== glsl_type::uint_type
);
536 assert(ir
->operands
[0]->type
== ir
->type
);
537 assert(ir
->operands
[0]->type
->is_float());
538 assert(ir
->operands
[1]->type
->base_type
== GLSL_TYPE_INT
);
539 assert(ir
->operands
[0]->type
->components() ==
540 ir
->operands
[1]->type
->components());
543 case ir_binop_vector_extract
:
544 assert(ir
->operands
[0]->type
->is_vector());
545 assert(ir
->operands
[1]->type
->is_scalar()
546 && ir
->operands
[1]->type
->is_integer());
550 assert(ir
->type
->base_type
== GLSL_TYPE_FLOAT
);
551 assert(ir
->type
== ir
->operands
[0]->type
);
552 assert(ir
->type
== ir
->operands
[1]->type
);
553 assert(ir
->type
== ir
->operands
[2]->type
);
557 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
558 assert(ir
->operands
[0]->type
== ir
->operands
[1]->type
);
559 assert(ir
->operands
[2]->type
== ir
->operands
[0]->type
|| ir
->operands
[2]->type
== glsl_type::float_type
);
563 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_BOOL
);
564 assert(ir
->type
->vector_elements
== ir
->operands
[0]->type
->vector_elements
);
565 assert(ir
->type
== ir
->operands
[1]->type
);
566 assert(ir
->type
== ir
->operands
[2]->type
);
570 assert(ir
->operands
[0]->type
->is_integer());
571 assert(ir
->operands
[1]->type
== ir
->operands
[2]->type
);
572 assert(ir
->operands
[1]->type
== ir
->type
);
575 case ir_triop_bitfield_extract
:
576 assert(ir
->operands
[0]->type
== ir
->type
);
577 assert(ir
->operands
[1]->type
== glsl_type::int_type
);
578 assert(ir
->operands
[2]->type
== glsl_type::int_type
);
581 case ir_triop_vector_insert
:
582 assert(ir
->operands
[0]->type
->is_vector());
583 assert(ir
->operands
[1]->type
->is_scalar());
584 assert(ir
->operands
[0]->type
->base_type
== ir
->operands
[1]->type
->base_type
);
585 assert(ir
->operands
[2]->type
->is_scalar()
586 && ir
->operands
[2]->type
->is_integer());
587 assert(ir
->type
== ir
->operands
[0]->type
);
590 case ir_quadop_bitfield_insert
:
591 assert(ir
->operands
[0]->type
== ir
->type
);
592 assert(ir
->operands
[1]->type
== ir
->type
);
593 assert(ir
->operands
[2]->type
== glsl_type::int_type
);
594 assert(ir
->operands
[3]->type
== glsl_type::int_type
);
597 case ir_quadop_vector
:
598 /* The vector operator collects some number of scalars and generates a
601 * - All of the operands must be scalar.
602 * - Number of operands must matche the size of the resulting vector.
603 * - Base type of the operands must match the base type of the result.
605 assert(ir
->type
->is_vector());
606 switch (ir
->type
->vector_elements
) {
608 assert(ir
->operands
[0]->type
->is_scalar());
609 assert(ir
->operands
[0]->type
->base_type
== ir
->type
->base_type
);
610 assert(ir
->operands
[1]->type
->is_scalar());
611 assert(ir
->operands
[1]->type
->base_type
== ir
->type
->base_type
);
612 assert(ir
->operands
[2] == NULL
);
613 assert(ir
->operands
[3] == NULL
);
616 assert(ir
->operands
[0]->type
->is_scalar());
617 assert(ir
->operands
[0]->type
->base_type
== ir
->type
->base_type
);
618 assert(ir
->operands
[1]->type
->is_scalar());
619 assert(ir
->operands
[1]->type
->base_type
== ir
->type
->base_type
);
620 assert(ir
->operands
[2]->type
->is_scalar());
621 assert(ir
->operands
[2]->type
->base_type
== ir
->type
->base_type
);
622 assert(ir
->operands
[3] == NULL
);
625 assert(ir
->operands
[0]->type
->is_scalar());
626 assert(ir
->operands
[0]->type
->base_type
== ir
->type
->base_type
);
627 assert(ir
->operands
[1]->type
->is_scalar());
628 assert(ir
->operands
[1]->type
->base_type
== ir
->type
->base_type
);
629 assert(ir
->operands
[2]->type
->is_scalar());
630 assert(ir
->operands
[2]->type
->base_type
== ir
->type
->base_type
);
631 assert(ir
->operands
[3]->type
->is_scalar());
632 assert(ir
->operands
[3]->type
->base_type
== ir
->type
->base_type
);
635 /* The is_vector assertion above should prevent execution from ever
638 assert(!"Should not get here.");
643 return visit_continue
;
647 ir_validate::visit_leave(ir_swizzle
*ir
)
649 unsigned int chans
[4] = {ir
->mask
.x
, ir
->mask
.y
, ir
->mask
.z
, ir
->mask
.w
};
651 for (unsigned int i
= 0; i
< ir
->type
->vector_elements
; i
++) {
652 if (chans
[i
] >= ir
->val
->type
->vector_elements
) {
653 printf("ir_swizzle @ %p specifies a channel not present "
654 "in the value.\n", (void *) ir
);
660 return visit_continue
;
664 ir_validate::visit(ir_variable
*ir
)
666 /* An ir_variable is the one thing that can (and will) appear multiple times
667 * in an IR tree. It is added to the hashtable so that it can be used
668 * in the ir_dereference_variable handler to ensure that a variable is
669 * declared before it is dereferenced.
672 assert(ralloc_parent(ir
->name
) == ir
);
674 hash_table_insert(ht
, ir
, ir
);
677 /* If a variable is an array, verify that the maximum array index is in
678 * bounds. There was once an error in AST-to-HIR conversion that set this
679 * to be out of bounds.
681 if (ir
->type
->array_size() > 0) {
682 if (ir
->max_array_access
>= ir
->type
->length
) {
683 printf("ir_variable has maximum access out of bounds (%d vs %d)\n",
684 ir
->max_array_access
, ir
->type
->length
- 1);
690 if (ir
->constant_initializer
!= NULL
&& !ir
->has_initializer
) {
691 printf("ir_variable didn't have an initializer, but has a constant "
692 "initializer value.\n");
697 return visit_continue
;
701 ir_validate::visit_enter(ir_assignment
*ir
)
703 const ir_dereference
*const lhs
= ir
->lhs
;
704 if (lhs
->type
->is_scalar() || lhs
->type
->is_vector()) {
705 if (ir
->write_mask
== 0) {
706 printf("Assignment LHS is %s, but write mask is 0:\n",
707 lhs
->type
->is_scalar() ? "scalar" : "vector");
712 int lhs_components
= 0;
713 for (int i
= 0; i
< 4; i
++) {
714 if (ir
->write_mask
& (1 << i
))
718 if (lhs_components
!= ir
->rhs
->type
->vector_elements
) {
719 printf("Assignment count of LHS write mask channels enabled not\n"
720 "matching RHS vector size (%d LHS, %d RHS).\n",
721 lhs_components
, ir
->rhs
->type
->vector_elements
);
727 this->validate_ir(ir
, this->data
);
729 return visit_continue
;
733 ir_validate::visit_enter(ir_call
*ir
)
735 ir_function_signature
*const callee
= ir
->callee
;
737 if (callee
->ir_type
!= ir_type_function_signature
) {
738 printf("IR called by ir_call is not ir_function_signature!\n");
742 if (ir
->return_deref
) {
743 if (ir
->return_deref
->type
!= callee
->return_type
) {
744 printf("callee type %s does not match return storage type %s\n",
745 callee
->return_type
->name
, ir
->return_deref
->type
->name
);
748 } else if (callee
->return_type
!= glsl_type::void_type
) {
749 printf("ir_call has non-void callee but no return storage\n");
753 const exec_node
*formal_param_node
= callee
->parameters
.head
;
754 const exec_node
*actual_param_node
= ir
->actual_parameters
.head
;
756 if (formal_param_node
->is_tail_sentinel()
757 != actual_param_node
->is_tail_sentinel()) {
758 printf("ir_call has the wrong number of parameters:\n");
761 if (formal_param_node
->is_tail_sentinel()) {
764 const ir_variable
*formal_param
765 = (const ir_variable
*) formal_param_node
;
766 const ir_rvalue
*actual_param
767 = (const ir_rvalue
*) actual_param_node
;
768 if (formal_param
->type
!= actual_param
->type
) {
769 printf("ir_call parameter type mismatch:\n");
772 if (formal_param
->mode
== ir_var_function_out
773 || formal_param
->mode
== ir_var_function_inout
) {
774 if (!actual_param
->is_lvalue()) {
775 printf("ir_call out/inout parameters must be lvalues:\n");
779 formal_param_node
= formal_param_node
->next
;
780 actual_param_node
= actual_param_node
->next
;
783 return visit_continue
;
794 ir_validate::validate_ir(ir_instruction
*ir
, void *data
)
796 struct hash_table
*ht
= (struct hash_table
*) data
;
798 if (hash_table_find(ht
, ir
)) {
799 printf("Instruction node present twice in ir tree:\n");
804 hash_table_insert(ht
, ir
, ir
);
808 check_node_type(ir_instruction
*ir
, void *data
)
812 if (ir
->ir_type
<= ir_type_unset
|| ir
->ir_type
>= ir_type_max
) {
813 printf("Instruction node with unset type\n");
814 ir
->print(); printf("\n");
816 ir_rvalue
*value
= ir
->as_rvalue();
818 assert(value
->type
!= glsl_type::error_type
);
822 validate_ir_tree(exec_list
*instructions
)
824 /* We shouldn't have any reason to validate IR in a release build,
825 * and it's half composed of assert()s anyway which wouldn't do
833 foreach_iter(exec_list_iterator
, iter
, *instructions
) {
834 ir_instruction
*ir
= (ir_instruction
*)iter
.get();
836 visit_tree(ir
, check_node_type
, NULL
);