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_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
);
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
);
172 /* Verify that all of the things stored in the list of signatures are,
173 * in fact, function signatures.
175 foreach_list(node
, &ir
->signatures
) {
176 ir_instruction
*sig
= (ir_instruction
*) node
;
178 if (sig
->ir_type
!= ir_type_function_signature
) {
179 printf("Non-signature in signature list of function `%s'\n",
185 return visit_continue
;
189 ir_validate::visit_leave(ir_function
*ir
)
191 assert(ralloc_parent(ir
->name
) == ir
);
193 this->current_function
= NULL
;
194 return visit_continue
;
198 ir_validate::visit_enter(ir_function_signature
*ir
)
200 if (this->current_function
!= ir
->function()) {
201 printf("Function signature nested inside wrong function "
203 printf("%p inside %s %p instead of %s %p\n",
205 this->current_function
->name
, (void *) this->current_function
,
206 ir
->function_name(), (void *) ir
->function());
210 if (ir
->return_type
== NULL
) {
211 printf("Function signature %p for function %s has NULL return type.\n",
212 (void *) ir
, ir
->function_name());
216 this->validate_ir(ir
, this->data
);
218 return visit_continue
;
222 ir_validate::visit_leave(ir_expression
*ir
)
224 switch (ir
->operation
) {
225 case ir_unop_bit_not
:
226 assert(ir
->operands
[0]->type
== ir
->type
);
228 case ir_unop_logic_not
:
229 assert(ir
->type
->base_type
== GLSL_TYPE_BOOL
);
230 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_BOOL
);
239 assert(ir
->type
== ir
->operands
[0]->type
);
246 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
247 assert(ir
->type
== ir
->operands
[0]->type
);
251 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
252 assert(ir
->type
->base_type
== GLSL_TYPE_INT
);
255 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
256 assert(ir
->type
->base_type
== GLSL_TYPE_UINT
);
259 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_INT
);
260 assert(ir
->type
->base_type
== GLSL_TYPE_FLOAT
);
263 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
264 assert(ir
->type
->base_type
== GLSL_TYPE_BOOL
);
267 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_BOOL
);
268 assert(ir
->type
->base_type
== GLSL_TYPE_FLOAT
);
271 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_INT
);
272 assert(ir
->type
->base_type
== GLSL_TYPE_BOOL
);
275 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_BOOL
);
276 assert(ir
->type
->base_type
== GLSL_TYPE_INT
);
279 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_UINT
);
280 assert(ir
->type
->base_type
== GLSL_TYPE_FLOAT
);
283 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_INT
);
284 assert(ir
->type
->base_type
== GLSL_TYPE_UINT
);
287 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_UINT
);
288 assert(ir
->type
->base_type
== GLSL_TYPE_INT
);
290 case ir_unop_bitcast_i2f
:
291 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_INT
);
292 assert(ir
->type
->base_type
== GLSL_TYPE_FLOAT
);
294 case ir_unop_bitcast_f2i
:
295 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
296 assert(ir
->type
->base_type
== GLSL_TYPE_INT
);
298 case ir_unop_bitcast_u2f
:
299 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_UINT
);
300 assert(ir
->type
->base_type
== GLSL_TYPE_FLOAT
);
302 case ir_unop_bitcast_f2u
:
303 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
304 assert(ir
->type
->base_type
== GLSL_TYPE_UINT
);
308 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_BOOL
);
309 assert(ir
->type
== glsl_type::bool_type
);
313 case ir_unop_round_even
:
319 case ir_unop_sin_reduced
:
320 case ir_unop_cos_reduced
:
323 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
324 assert(ir
->operands
[0]->type
== ir
->type
);
327 case ir_unop_pack_snorm_2x16
:
328 case ir_unop_pack_unorm_2x16
:
329 case ir_unop_pack_half_2x16
:
330 assert(ir
->type
== glsl_type::uint_type
);
331 assert(ir
->operands
[0]->type
== glsl_type::vec2_type
);
334 case ir_unop_pack_snorm_4x8
:
335 case ir_unop_pack_unorm_4x8
:
336 assert(ir
->type
== glsl_type::uint_type
);
337 assert(ir
->operands
[0]->type
== glsl_type::vec4_type
);
340 case ir_unop_unpack_snorm_2x16
:
341 case ir_unop_unpack_unorm_2x16
:
342 case ir_unop_unpack_half_2x16
:
343 assert(ir
->type
== glsl_type::vec2_type
);
344 assert(ir
->operands
[0]->type
== glsl_type::uint_type
);
347 case ir_unop_unpack_snorm_4x8
:
348 case ir_unop_unpack_unorm_4x8
:
349 assert(ir
->type
== glsl_type::vec4_type
);
350 assert(ir
->operands
[0]->type
== glsl_type::uint_type
);
353 case ir_unop_unpack_half_2x16_split_x
:
354 case ir_unop_unpack_half_2x16_split_y
:
355 assert(ir
->type
== glsl_type::float_type
);
356 assert(ir
->operands
[0]->type
== glsl_type::uint_type
);
359 case ir_unop_bitfield_reverse
:
360 assert(ir
->operands
[0]->type
== ir
->type
);
361 assert(ir
->type
->is_integer());
364 case ir_unop_bit_count
:
365 case ir_unop_find_msb
:
366 case ir_unop_find_lsb
:
367 assert(ir
->operands
[0]->type
->vector_elements
== ir
->type
->vector_elements
);
368 assert(ir
->operands
[0]->type
->is_integer());
369 assert(ir
->type
->base_type
== GLSL_TYPE_INT
);
373 /* XXX what can we assert here? */
384 assert(ir
->operands
[0]->type
->base_type
==
385 ir
->operands
[1]->type
->base_type
);
387 if (ir
->operands
[0]->type
->is_scalar())
388 assert(ir
->operands
[1]->type
== ir
->type
);
389 else if (ir
->operands
[1]->type
->is_scalar())
390 assert(ir
->operands
[0]->type
== ir
->type
);
391 else if (ir
->operands
[0]->type
->is_vector() &&
392 ir
->operands
[1]->type
->is_vector()) {
393 assert(ir
->operands
[0]->type
== ir
->operands
[1]->type
);
394 assert(ir
->operands
[0]->type
== ir
->type
);
398 case ir_binop_imul_high
:
399 assert(ir
->type
== ir
->operands
[0]->type
);
400 assert(ir
->type
== ir
->operands
[1]->type
);
401 assert(ir
->type
->is_integer());
405 case ir_binop_borrow
:
406 assert(ir
->type
== ir
->operands
[0]->type
);
407 assert(ir
->type
== ir
->operands
[1]->type
);
408 assert(ir
->type
->base_type
== GLSL_TYPE_UINT
);
412 case ir_binop_greater
:
413 case ir_binop_lequal
:
414 case ir_binop_gequal
:
416 case ir_binop_nequal
:
417 /* The semantics of the IR operators differ from the GLSL <, >, <=, >=,
418 * ==, and != operators. The IR operators perform a component-wise
419 * comparison on scalar or vector types and return a boolean scalar or
420 * vector type of the same size.
422 assert(ir
->type
->base_type
== GLSL_TYPE_BOOL
);
423 assert(ir
->operands
[0]->type
== ir
->operands
[1]->type
);
424 assert(ir
->operands
[0]->type
->is_vector()
425 || ir
->operands
[0]->type
->is_scalar());
426 assert(ir
->operands
[0]->type
->vector_elements
427 == ir
->type
->vector_elements
);
430 case ir_binop_all_equal
:
431 case ir_binop_any_nequal
:
432 /* GLSL == and != operate on scalars, vectors, matrices and arrays, and
433 * return a scalar boolean. The IR matches that.
435 assert(ir
->type
== glsl_type::bool_type
);
436 assert(ir
->operands
[0]->type
== ir
->operands
[1]->type
);
439 case ir_binop_lshift
:
440 case ir_binop_rshift
:
441 assert(ir
->operands
[0]->type
->is_integer() &&
442 ir
->operands
[1]->type
->is_integer());
443 if (ir
->operands
[0]->type
->is_scalar()) {
444 assert(ir
->operands
[1]->type
->is_scalar());
446 if (ir
->operands
[0]->type
->is_vector() &&
447 ir
->operands
[1]->type
->is_vector()) {
448 assert(ir
->operands
[0]->type
->components() ==
449 ir
->operands
[1]->type
->components());
451 assert(ir
->type
== ir
->operands
[0]->type
);
454 case ir_binop_bit_and
:
455 case ir_binop_bit_xor
:
456 case ir_binop_bit_or
:
457 assert(ir
->operands
[0]->type
->base_type
==
458 ir
->operands
[1]->type
->base_type
);
459 assert(ir
->type
->is_integer());
460 if (ir
->operands
[0]->type
->is_vector() &&
461 ir
->operands
[1]->type
->is_vector()) {
462 assert(ir
->operands
[0]->type
->vector_elements
==
463 ir
->operands
[1]->type
->vector_elements
);
467 case ir_binop_logic_and
:
468 case ir_binop_logic_xor
:
469 case ir_binop_logic_or
:
470 assert(ir
->type
== glsl_type::bool_type
);
471 assert(ir
->operands
[0]->type
== glsl_type::bool_type
);
472 assert(ir
->operands
[1]->type
== glsl_type::bool_type
);
476 assert(ir
->type
== glsl_type::float_type
);
477 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
478 assert(ir
->operands
[0]->type
->is_vector());
479 assert(ir
->operands
[0]->type
== ir
->operands
[1]->type
);
482 case ir_binop_pack_half_2x16_split
:
483 assert(ir
->type
== glsl_type::uint_type
);
484 assert(ir
->operands
[0]->type
== glsl_type::float_type
);
485 assert(ir
->operands
[1]->type
== glsl_type::float_type
);
489 assert(ir
->type
->is_integer());
490 assert(ir
->operands
[0]->type
->is_integer());
491 assert(ir
->operands
[1]->type
->is_integer());
494 case ir_binop_ubo_load
:
495 assert(ir
->operands
[0]->as_constant());
496 assert(ir
->operands
[0]->type
== glsl_type::uint_type
);
498 assert(ir
->operands
[1]->type
== glsl_type::uint_type
);
502 assert(ir
->operands
[0]->type
== ir
->type
);
503 assert(ir
->operands
[0]->type
->is_float());
504 assert(ir
->operands
[1]->type
->base_type
== GLSL_TYPE_INT
);
505 assert(ir
->operands
[0]->type
->components() ==
506 ir
->operands
[1]->type
->components());
509 case ir_binop_vector_extract
:
510 assert(ir
->operands
[0]->type
->is_vector());
511 assert(ir
->operands
[1]->type
->is_scalar()
512 && ir
->operands
[1]->type
->is_integer());
516 assert(ir
->type
->base_type
== GLSL_TYPE_FLOAT
);
517 assert(ir
->type
== ir
->operands
[0]->type
);
518 assert(ir
->type
== ir
->operands
[1]->type
);
519 assert(ir
->type
== ir
->operands
[2]->type
);
523 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
524 assert(ir
->operands
[0]->type
== ir
->operands
[1]->type
);
525 assert(ir
->operands
[2]->type
== ir
->operands
[0]->type
|| ir
->operands
[2]->type
== glsl_type::float_type
);
529 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_BOOL
);
530 assert(ir
->type
->vector_elements
== ir
->operands
[0]->type
->vector_elements
);
531 assert(ir
->type
== ir
->operands
[1]->type
);
532 assert(ir
->type
== ir
->operands
[2]->type
);
536 assert(ir
->operands
[0]->type
->is_integer());
537 assert(ir
->operands
[1]->type
== ir
->operands
[2]->type
);
538 assert(ir
->operands
[1]->type
== ir
->type
);
541 case ir_triop_bitfield_extract
:
542 assert(ir
->operands
[0]->type
== ir
->type
);
543 assert(ir
->operands
[1]->type
== glsl_type::int_type
);
544 assert(ir
->operands
[2]->type
== glsl_type::int_type
);
547 case ir_triop_vector_insert
:
548 assert(ir
->operands
[0]->type
->is_vector());
549 assert(ir
->operands
[1]->type
->is_scalar());
550 assert(ir
->operands
[0]->type
->base_type
== ir
->operands
[1]->type
->base_type
);
551 assert(ir
->operands
[2]->type
->is_scalar()
552 && ir
->operands
[2]->type
->is_integer());
553 assert(ir
->type
== ir
->operands
[0]->type
);
556 case ir_quadop_bitfield_insert
:
557 assert(ir
->operands
[0]->type
== ir
->type
);
558 assert(ir
->operands
[1]->type
== ir
->type
);
559 assert(ir
->operands
[2]->type
== glsl_type::int_type
);
560 assert(ir
->operands
[3]->type
== glsl_type::int_type
);
563 case ir_quadop_vector
:
564 /* The vector operator collects some number of scalars and generates a
567 * - All of the operands must be scalar.
568 * - Number of operands must matche the size of the resulting vector.
569 * - Base type of the operands must match the base type of the result.
571 assert(ir
->type
->is_vector());
572 switch (ir
->type
->vector_elements
) {
574 assert(ir
->operands
[0]->type
->is_scalar());
575 assert(ir
->operands
[0]->type
->base_type
== ir
->type
->base_type
);
576 assert(ir
->operands
[1]->type
->is_scalar());
577 assert(ir
->operands
[1]->type
->base_type
== ir
->type
->base_type
);
578 assert(ir
->operands
[2] == NULL
);
579 assert(ir
->operands
[3] == NULL
);
582 assert(ir
->operands
[0]->type
->is_scalar());
583 assert(ir
->operands
[0]->type
->base_type
== ir
->type
->base_type
);
584 assert(ir
->operands
[1]->type
->is_scalar());
585 assert(ir
->operands
[1]->type
->base_type
== ir
->type
->base_type
);
586 assert(ir
->operands
[2]->type
->is_scalar());
587 assert(ir
->operands
[2]->type
->base_type
== ir
->type
->base_type
);
588 assert(ir
->operands
[3] == NULL
);
591 assert(ir
->operands
[0]->type
->is_scalar());
592 assert(ir
->operands
[0]->type
->base_type
== ir
->type
->base_type
);
593 assert(ir
->operands
[1]->type
->is_scalar());
594 assert(ir
->operands
[1]->type
->base_type
== ir
->type
->base_type
);
595 assert(ir
->operands
[2]->type
->is_scalar());
596 assert(ir
->operands
[2]->type
->base_type
== ir
->type
->base_type
);
597 assert(ir
->operands
[3]->type
->is_scalar());
598 assert(ir
->operands
[3]->type
->base_type
== ir
->type
->base_type
);
601 /* The is_vector assertion above should prevent execution from ever
604 assert(!"Should not get here.");
609 return visit_continue
;
613 ir_validate::visit_leave(ir_swizzle
*ir
)
615 unsigned int chans
[4] = {ir
->mask
.x
, ir
->mask
.y
, ir
->mask
.z
, ir
->mask
.w
};
617 for (unsigned int i
= 0; i
< ir
->type
->vector_elements
; i
++) {
618 if (chans
[i
] >= ir
->val
->type
->vector_elements
) {
619 printf("ir_swizzle @ %p specifies a channel not present "
620 "in the value.\n", (void *) ir
);
626 return visit_continue
;
630 ir_validate::visit(ir_variable
*ir
)
632 /* An ir_variable is the one thing that can (and will) appear multiple times
633 * in an IR tree. It is added to the hashtable so that it can be used
634 * in the ir_dereference_variable handler to ensure that a variable is
635 * declared before it is dereferenced.
638 assert(ralloc_parent(ir
->name
) == ir
);
640 hash_table_insert(ht
, ir
, ir
);
643 /* If a variable is an array, verify that the maximum array index is in
644 * bounds. There was once an error in AST-to-HIR conversion that set this
645 * to be out of bounds.
647 if (ir
->type
->array_size() > 0) {
648 if (ir
->data
.max_array_access
>= ir
->type
->length
) {
649 printf("ir_variable has maximum access out of bounds (%d vs %d)\n",
650 ir
->data
.max_array_access
, ir
->type
->length
- 1);
656 /* If a variable is an interface block (or an array of interface blocks),
657 * verify that the maximum array index for each interface member is in
660 if (ir
->is_interface_instance()) {
661 const glsl_struct_field
*fields
=
662 ir
->get_interface_type()->fields
.structure
;
663 for (unsigned i
= 0; i
< ir
->get_interface_type()->length
; i
++) {
664 if (fields
[i
].type
->array_size() > 0) {
665 if (ir
->max_ifc_array_access
[i
] >= fields
[i
].type
->length
) {
666 printf("ir_variable has maximum access out of bounds for "
667 "field %s (%d vs %d)\n", fields
[i
].name
,
668 ir
->max_ifc_array_access
[i
], fields
[i
].type
->length
);
676 if (ir
->constant_initializer
!= NULL
&& !ir
->data
.has_initializer
) {
677 printf("ir_variable didn't have an initializer, but has a constant "
678 "initializer value.\n");
683 return visit_continue
;
687 ir_validate::visit_enter(ir_assignment
*ir
)
689 const ir_dereference
*const lhs
= ir
->lhs
;
690 if (lhs
->type
->is_scalar() || lhs
->type
->is_vector()) {
691 if (ir
->write_mask
== 0) {
692 printf("Assignment LHS is %s, but write mask is 0:\n",
693 lhs
->type
->is_scalar() ? "scalar" : "vector");
698 int lhs_components
= 0;
699 for (int i
= 0; i
< 4; i
++) {
700 if (ir
->write_mask
& (1 << i
))
704 if (lhs_components
!= ir
->rhs
->type
->vector_elements
) {
705 printf("Assignment count of LHS write mask channels enabled not\n"
706 "matching RHS vector size (%d LHS, %d RHS).\n",
707 lhs_components
, ir
->rhs
->type
->vector_elements
);
713 this->validate_ir(ir
, this->data
);
715 return visit_continue
;
719 ir_validate::visit_enter(ir_call
*ir
)
721 ir_function_signature
*const callee
= ir
->callee
;
723 if (callee
->ir_type
!= ir_type_function_signature
) {
724 printf("IR called by ir_call is not ir_function_signature!\n");
728 if (ir
->return_deref
) {
729 if (ir
->return_deref
->type
!= callee
->return_type
) {
730 printf("callee type %s does not match return storage type %s\n",
731 callee
->return_type
->name
, ir
->return_deref
->type
->name
);
734 } else if (callee
->return_type
!= glsl_type::void_type
) {
735 printf("ir_call has non-void callee but no return storage\n");
739 const exec_node
*formal_param_node
= callee
->parameters
.head
;
740 const exec_node
*actual_param_node
= ir
->actual_parameters
.head
;
742 if (formal_param_node
->is_tail_sentinel()
743 != actual_param_node
->is_tail_sentinel()) {
744 printf("ir_call has the wrong number of parameters:\n");
747 if (formal_param_node
->is_tail_sentinel()) {
750 const ir_variable
*formal_param
751 = (const ir_variable
*) formal_param_node
;
752 const ir_rvalue
*actual_param
753 = (const ir_rvalue
*) actual_param_node
;
754 if (formal_param
->type
!= actual_param
->type
) {
755 printf("ir_call parameter type mismatch:\n");
758 if (formal_param
->data
.mode
== ir_var_function_out
759 || formal_param
->data
.mode
== ir_var_function_inout
) {
760 if (!actual_param
->is_lvalue()) {
761 printf("ir_call out/inout parameters must be lvalues:\n");
765 formal_param_node
= formal_param_node
->next
;
766 actual_param_node
= actual_param_node
->next
;
769 return visit_continue
;
780 ir_validate::validate_ir(ir_instruction
*ir
, void *data
)
782 struct hash_table
*ht
= (struct hash_table
*) data
;
784 if (hash_table_find(ht
, ir
)) {
785 printf("Instruction node present twice in ir tree:\n");
790 hash_table_insert(ht
, ir
, ir
);
794 check_node_type(ir_instruction
*ir
, void *data
)
798 if (ir
->ir_type
<= ir_type_unset
|| ir
->ir_type
>= ir_type_max
) {
799 printf("Instruction node with unset type\n");
800 ir
->print(); printf("\n");
802 ir_rvalue
*value
= ir
->as_rvalue();
804 assert(value
->type
!= glsl_type::error_type
);
808 validate_ir_tree(exec_list
*instructions
)
810 /* We shouldn't have any reason to validate IR in a release build,
811 * and it's half composed of assert()s anyway which wouldn't do
819 foreach_list(n
, instructions
) {
820 ir_instruction
*ir
= (ir_instruction
*) n
;
822 visit_tree(ir
, check_node_type
, NULL
);