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 if (ir
->operands
[0]->type
->is_scalar())
385 assert(ir
->operands
[1]->type
== ir
->type
);
386 else if (ir
->operands
[1]->type
->is_scalar())
387 assert(ir
->operands
[0]->type
== ir
->type
);
388 else if (ir
->operands
[0]->type
->is_vector() &&
389 ir
->operands
[1]->type
->is_vector()) {
390 assert(ir
->operands
[0]->type
== ir
->operands
[1]->type
);
391 assert(ir
->operands
[0]->type
== ir
->type
);
395 case ir_binop_imul_high
:
396 assert(ir
->type
== ir
->operands
[0]->type
);
397 assert(ir
->type
== ir
->operands
[1]->type
);
398 assert(ir
->type
->is_integer());
402 case ir_binop_borrow
:
403 assert(ir
->type
== ir
->operands
[0]->type
);
404 assert(ir
->type
== ir
->operands
[1]->type
);
405 assert(ir
->type
->base_type
== GLSL_TYPE_UINT
);
409 case ir_binop_greater
:
410 case ir_binop_lequal
:
411 case ir_binop_gequal
:
413 case ir_binop_nequal
:
414 /* The semantics of the IR operators differ from the GLSL <, >, <=, >=,
415 * ==, and != operators. The IR operators perform a component-wise
416 * comparison on scalar or vector types and return a boolean scalar or
417 * vector type of the same size.
419 assert(ir
->type
->base_type
== GLSL_TYPE_BOOL
);
420 assert(ir
->operands
[0]->type
== ir
->operands
[1]->type
);
421 assert(ir
->operands
[0]->type
->is_vector()
422 || ir
->operands
[0]->type
->is_scalar());
423 assert(ir
->operands
[0]->type
->vector_elements
424 == ir
->type
->vector_elements
);
427 case ir_binop_all_equal
:
428 case ir_binop_any_nequal
:
429 /* GLSL == and != operate on scalars, vectors, matrices and arrays, and
430 * return a scalar boolean. The IR matches that.
432 assert(ir
->type
== glsl_type::bool_type
);
433 assert(ir
->operands
[0]->type
== ir
->operands
[1]->type
);
436 case ir_binop_lshift
:
437 case ir_binop_rshift
:
438 assert(ir
->operands
[0]->type
->is_integer() &&
439 ir
->operands
[1]->type
->is_integer());
440 if (ir
->operands
[0]->type
->is_scalar()) {
441 assert(ir
->operands
[1]->type
->is_scalar());
443 if (ir
->operands
[0]->type
->is_vector() &&
444 ir
->operands
[1]->type
->is_vector()) {
445 assert(ir
->operands
[0]->type
->components() ==
446 ir
->operands
[1]->type
->components());
448 assert(ir
->type
== ir
->operands
[0]->type
);
451 case ir_binop_bit_and
:
452 case ir_binop_bit_xor
:
453 case ir_binop_bit_or
:
454 assert(ir
->operands
[0]->type
->base_type
==
455 ir
->operands
[1]->type
->base_type
);
456 assert(ir
->type
->is_integer());
457 if (ir
->operands
[0]->type
->is_vector() &&
458 ir
->operands
[1]->type
->is_vector()) {
459 assert(ir
->operands
[0]->type
->vector_elements
==
460 ir
->operands
[1]->type
->vector_elements
);
464 case ir_binop_logic_and
:
465 case ir_binop_logic_xor
:
466 case ir_binop_logic_or
:
467 assert(ir
->type
== glsl_type::bool_type
);
468 assert(ir
->operands
[0]->type
== glsl_type::bool_type
);
469 assert(ir
->operands
[1]->type
== glsl_type::bool_type
);
473 assert(ir
->type
== glsl_type::float_type
);
474 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
475 assert(ir
->operands
[0]->type
->is_vector());
476 assert(ir
->operands
[0]->type
== ir
->operands
[1]->type
);
479 case ir_binop_pack_half_2x16_split
:
480 assert(ir
->type
== glsl_type::uint_type
);
481 assert(ir
->operands
[0]->type
== glsl_type::float_type
);
482 assert(ir
->operands
[1]->type
== glsl_type::float_type
);
486 assert(ir
->type
->is_integer());
487 assert(ir
->operands
[0]->type
->is_integer());
488 assert(ir
->operands
[1]->type
->is_integer());
491 case ir_binop_ubo_load
:
492 assert(ir
->operands
[0]->as_constant());
493 assert(ir
->operands
[0]->type
== glsl_type::uint_type
);
495 assert(ir
->operands
[1]->type
== glsl_type::uint_type
);
499 assert(ir
->operands
[0]->type
== ir
->type
);
500 assert(ir
->operands
[0]->type
->is_float());
501 assert(ir
->operands
[1]->type
->base_type
== GLSL_TYPE_INT
);
502 assert(ir
->operands
[0]->type
->components() ==
503 ir
->operands
[1]->type
->components());
506 case ir_binop_vector_extract
:
507 assert(ir
->operands
[0]->type
->is_vector());
508 assert(ir
->operands
[1]->type
->is_scalar()
509 && ir
->operands
[1]->type
->is_integer());
513 assert(ir
->type
->base_type
== GLSL_TYPE_FLOAT
);
514 assert(ir
->type
== ir
->operands
[0]->type
);
515 assert(ir
->type
== ir
->operands
[1]->type
);
516 assert(ir
->type
== ir
->operands
[2]->type
);
520 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
521 assert(ir
->operands
[0]->type
== ir
->operands
[1]->type
);
522 assert(ir
->operands
[2]->type
== ir
->operands
[0]->type
|| ir
->operands
[2]->type
== glsl_type::float_type
);
526 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_BOOL
);
527 assert(ir
->type
->vector_elements
== ir
->operands
[0]->type
->vector_elements
);
528 assert(ir
->type
== ir
->operands
[1]->type
);
529 assert(ir
->type
== ir
->operands
[2]->type
);
533 assert(ir
->operands
[0]->type
->is_integer());
534 assert(ir
->operands
[1]->type
== ir
->operands
[2]->type
);
535 assert(ir
->operands
[1]->type
== ir
->type
);
538 case ir_triop_bitfield_extract
:
539 assert(ir
->operands
[0]->type
== ir
->type
);
540 assert(ir
->operands
[1]->type
== glsl_type::int_type
);
541 assert(ir
->operands
[2]->type
== glsl_type::int_type
);
544 case ir_triop_vector_insert
:
545 assert(ir
->operands
[0]->type
->is_vector());
546 assert(ir
->operands
[1]->type
->is_scalar());
547 assert(ir
->operands
[0]->type
->base_type
== ir
->operands
[1]->type
->base_type
);
548 assert(ir
->operands
[2]->type
->is_scalar()
549 && ir
->operands
[2]->type
->is_integer());
550 assert(ir
->type
== ir
->operands
[0]->type
);
553 case ir_quadop_bitfield_insert
:
554 assert(ir
->operands
[0]->type
== ir
->type
);
555 assert(ir
->operands
[1]->type
== ir
->type
);
556 assert(ir
->operands
[2]->type
== glsl_type::int_type
);
557 assert(ir
->operands
[3]->type
== glsl_type::int_type
);
560 case ir_quadop_vector
:
561 /* The vector operator collects some number of scalars and generates a
564 * - All of the operands must be scalar.
565 * - Number of operands must matche the size of the resulting vector.
566 * - Base type of the operands must match the base type of the result.
568 assert(ir
->type
->is_vector());
569 switch (ir
->type
->vector_elements
) {
571 assert(ir
->operands
[0]->type
->is_scalar());
572 assert(ir
->operands
[0]->type
->base_type
== ir
->type
->base_type
);
573 assert(ir
->operands
[1]->type
->is_scalar());
574 assert(ir
->operands
[1]->type
->base_type
== ir
->type
->base_type
);
575 assert(ir
->operands
[2] == NULL
);
576 assert(ir
->operands
[3] == NULL
);
579 assert(ir
->operands
[0]->type
->is_scalar());
580 assert(ir
->operands
[0]->type
->base_type
== ir
->type
->base_type
);
581 assert(ir
->operands
[1]->type
->is_scalar());
582 assert(ir
->operands
[1]->type
->base_type
== ir
->type
->base_type
);
583 assert(ir
->operands
[2]->type
->is_scalar());
584 assert(ir
->operands
[2]->type
->base_type
== ir
->type
->base_type
);
585 assert(ir
->operands
[3] == NULL
);
588 assert(ir
->operands
[0]->type
->is_scalar());
589 assert(ir
->operands
[0]->type
->base_type
== ir
->type
->base_type
);
590 assert(ir
->operands
[1]->type
->is_scalar());
591 assert(ir
->operands
[1]->type
->base_type
== ir
->type
->base_type
);
592 assert(ir
->operands
[2]->type
->is_scalar());
593 assert(ir
->operands
[2]->type
->base_type
== ir
->type
->base_type
);
594 assert(ir
->operands
[3]->type
->is_scalar());
595 assert(ir
->operands
[3]->type
->base_type
== ir
->type
->base_type
);
598 /* The is_vector assertion above should prevent execution from ever
601 assert(!"Should not get here.");
606 return visit_continue
;
610 ir_validate::visit_leave(ir_swizzle
*ir
)
612 unsigned int chans
[4] = {ir
->mask
.x
, ir
->mask
.y
, ir
->mask
.z
, ir
->mask
.w
};
614 for (unsigned int i
= 0; i
< ir
->type
->vector_elements
; i
++) {
615 if (chans
[i
] >= ir
->val
->type
->vector_elements
) {
616 printf("ir_swizzle @ %p specifies a channel not present "
617 "in the value.\n", (void *) ir
);
623 return visit_continue
;
627 ir_validate::visit(ir_variable
*ir
)
629 /* An ir_variable is the one thing that can (and will) appear multiple times
630 * in an IR tree. It is added to the hashtable so that it can be used
631 * in the ir_dereference_variable handler to ensure that a variable is
632 * declared before it is dereferenced.
635 assert(ralloc_parent(ir
->name
) == ir
);
637 hash_table_insert(ht
, ir
, ir
);
640 /* If a variable is an array, verify that the maximum array index is in
641 * bounds. There was once an error in AST-to-HIR conversion that set this
642 * to be out of bounds.
644 if (ir
->type
->array_size() > 0) {
645 if (ir
->data
.max_array_access
>= ir
->type
->length
) {
646 printf("ir_variable has maximum access out of bounds (%d vs %d)\n",
647 ir
->data
.max_array_access
, ir
->type
->length
- 1);
653 /* If a variable is an interface block (or an array of interface blocks),
654 * verify that the maximum array index for each interface member is in
657 if (ir
->is_interface_instance()) {
658 const glsl_struct_field
*fields
=
659 ir
->get_interface_type()->fields
.structure
;
660 for (unsigned i
= 0; i
< ir
->get_interface_type()->length
; i
++) {
661 if (fields
[i
].type
->array_size() > 0) {
662 if (ir
->max_ifc_array_access
[i
] >= fields
[i
].type
->length
) {
663 printf("ir_variable has maximum access out of bounds for "
664 "field %s (%d vs %d)\n", fields
[i
].name
,
665 ir
->max_ifc_array_access
[i
], fields
[i
].type
->length
);
673 if (ir
->constant_initializer
!= NULL
&& !ir
->data
.has_initializer
) {
674 printf("ir_variable didn't have an initializer, but has a constant "
675 "initializer value.\n");
680 return visit_continue
;
684 ir_validate::visit_enter(ir_assignment
*ir
)
686 const ir_dereference
*const lhs
= ir
->lhs
;
687 if (lhs
->type
->is_scalar() || lhs
->type
->is_vector()) {
688 if (ir
->write_mask
== 0) {
689 printf("Assignment LHS is %s, but write mask is 0:\n",
690 lhs
->type
->is_scalar() ? "scalar" : "vector");
695 int lhs_components
= 0;
696 for (int i
= 0; i
< 4; i
++) {
697 if (ir
->write_mask
& (1 << i
))
701 if (lhs_components
!= ir
->rhs
->type
->vector_elements
) {
702 printf("Assignment count of LHS write mask channels enabled not\n"
703 "matching RHS vector size (%d LHS, %d RHS).\n",
704 lhs_components
, ir
->rhs
->type
->vector_elements
);
710 this->validate_ir(ir
, this->data
);
712 return visit_continue
;
716 ir_validate::visit_enter(ir_call
*ir
)
718 ir_function_signature
*const callee
= ir
->callee
;
720 if (callee
->ir_type
!= ir_type_function_signature
) {
721 printf("IR called by ir_call is not ir_function_signature!\n");
725 if (ir
->return_deref
) {
726 if (ir
->return_deref
->type
!= callee
->return_type
) {
727 printf("callee type %s does not match return storage type %s\n",
728 callee
->return_type
->name
, ir
->return_deref
->type
->name
);
731 } else if (callee
->return_type
!= glsl_type::void_type
) {
732 printf("ir_call has non-void callee but no return storage\n");
736 const exec_node
*formal_param_node
= callee
->parameters
.head
;
737 const exec_node
*actual_param_node
= ir
->actual_parameters
.head
;
739 if (formal_param_node
->is_tail_sentinel()
740 != actual_param_node
->is_tail_sentinel()) {
741 printf("ir_call has the wrong number of parameters:\n");
744 if (formal_param_node
->is_tail_sentinel()) {
747 const ir_variable
*formal_param
748 = (const ir_variable
*) formal_param_node
;
749 const ir_rvalue
*actual_param
750 = (const ir_rvalue
*) actual_param_node
;
751 if (formal_param
->type
!= actual_param
->type
) {
752 printf("ir_call parameter type mismatch:\n");
755 if (formal_param
->data
.mode
== ir_var_function_out
756 || formal_param
->data
.mode
== ir_var_function_inout
) {
757 if (!actual_param
->is_lvalue()) {
758 printf("ir_call out/inout parameters must be lvalues:\n");
762 formal_param_node
= formal_param_node
->next
;
763 actual_param_node
= actual_param_node
->next
;
766 return visit_continue
;
777 ir_validate::validate_ir(ir_instruction
*ir
, void *data
)
779 struct hash_table
*ht
= (struct hash_table
*) data
;
781 if (hash_table_find(ht
, ir
)) {
782 printf("Instruction node present twice in ir tree:\n");
787 hash_table_insert(ht
, ir
, ir
);
791 check_node_type(ir_instruction
*ir
, void *data
)
795 if (ir
->ir_type
<= ir_type_unset
|| ir
->ir_type
>= ir_type_max
) {
796 printf("Instruction node with unset type\n");
797 ir
->print(); printf("\n");
799 ir_rvalue
*value
= ir
->as_rvalue();
801 assert(value
->type
!= glsl_type::error_type
);
805 validate_ir_tree(exec_list
*instructions
)
807 /* We shouldn't have any reason to validate IR in a release build,
808 * and it's half composed of assert()s anyway which wouldn't do
816 foreach_iter(exec_list_iterator
, iter
, *instructions
) {
817 ir_instruction
*ir
= (ir_instruction
*)iter
.get();
819 visit_tree(ir
, check_node_type
, NULL
);