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
);
433 case ir_binop_greater
:
434 case ir_binop_lequal
:
435 case ir_binop_gequal
:
437 case ir_binop_nequal
:
438 /* The semantics of the IR operators differ from the GLSL <, >, <=, >=,
439 * ==, and != operators. The IR operators perform a component-wise
440 * comparison on scalar or vector types and return a boolean scalar or
441 * vector type of the same size.
443 assert(ir
->type
->base_type
== GLSL_TYPE_BOOL
);
444 assert(ir
->operands
[0]->type
== ir
->operands
[1]->type
);
445 assert(ir
->operands
[0]->type
->is_vector()
446 || ir
->operands
[0]->type
->is_scalar());
447 assert(ir
->operands
[0]->type
->vector_elements
448 == ir
->type
->vector_elements
);
451 case ir_binop_all_equal
:
452 case ir_binop_any_nequal
:
453 /* GLSL == and != operate on scalars, vectors, matrices and arrays, and
454 * return a scalar boolean. The IR matches that.
456 assert(ir
->type
== glsl_type::bool_type
);
457 assert(ir
->operands
[0]->type
== ir
->operands
[1]->type
);
460 case ir_binop_lshift
:
461 case ir_binop_rshift
:
462 assert(ir
->operands
[0]->type
->is_integer() &&
463 ir
->operands
[1]->type
->is_integer());
464 if (ir
->operands
[0]->type
->is_scalar()) {
465 assert(ir
->operands
[1]->type
->is_scalar());
467 if (ir
->operands
[0]->type
->is_vector() &&
468 ir
->operands
[1]->type
->is_vector()) {
469 assert(ir
->operands
[0]->type
->components() ==
470 ir
->operands
[1]->type
->components());
472 assert(ir
->type
== ir
->operands
[0]->type
);
475 case ir_binop_bit_and
:
476 case ir_binop_bit_xor
:
477 case ir_binop_bit_or
:
478 assert(ir
->operands
[0]->type
->base_type
==
479 ir
->operands
[1]->type
->base_type
);
480 assert(ir
->type
->is_integer());
481 if (ir
->operands
[0]->type
->is_vector() &&
482 ir
->operands
[1]->type
->is_vector()) {
483 assert(ir
->operands
[0]->type
->vector_elements
==
484 ir
->operands
[1]->type
->vector_elements
);
488 case ir_binop_logic_and
:
489 case ir_binop_logic_xor
:
490 case ir_binop_logic_or
:
491 assert(ir
->type
== glsl_type::bool_type
);
492 assert(ir
->operands
[0]->type
== glsl_type::bool_type
);
493 assert(ir
->operands
[1]->type
== glsl_type::bool_type
);
497 assert(ir
->type
== glsl_type::float_type
);
498 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
499 assert(ir
->operands
[0]->type
->is_vector());
500 assert(ir
->operands
[0]->type
== ir
->operands
[1]->type
);
503 case ir_binop_pack_half_2x16_split
:
504 assert(ir
->type
== glsl_type::uint_type
);
505 assert(ir
->operands
[0]->type
== glsl_type::float_type
);
506 assert(ir
->operands
[1]->type
== glsl_type::float_type
);
510 assert(ir
->type
->is_integer());
511 assert(ir
->operands
[0]->type
->is_integer());
512 assert(ir
->operands
[1]->type
->is_integer());
515 case ir_binop_ubo_load
:
516 assert(ir
->operands
[0]->as_constant());
517 assert(ir
->operands
[0]->type
== glsl_type::uint_type
);
519 assert(ir
->operands
[1]->type
== glsl_type::uint_type
);
523 assert(ir
->operands
[0]->type
== ir
->type
);
524 assert(ir
->operands
[0]->type
->is_float());
525 assert(ir
->operands
[1]->type
->base_type
== GLSL_TYPE_INT
);
526 assert(ir
->operands
[0]->type
->components() ==
527 ir
->operands
[1]->type
->components());
530 case ir_binop_vector_extract
:
531 assert(ir
->operands
[0]->type
->is_vector());
532 assert(ir
->operands
[1]->type
->is_scalar()
533 && ir
->operands
[1]->type
->is_integer());
537 assert(ir
->type
->base_type
== GLSL_TYPE_FLOAT
);
538 assert(ir
->type
== ir
->operands
[0]->type
);
539 assert(ir
->type
== ir
->operands
[1]->type
);
540 assert(ir
->type
== ir
->operands
[2]->type
);
544 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
545 assert(ir
->operands
[0]->type
== ir
->operands
[1]->type
);
546 assert(ir
->operands
[2]->type
== ir
->operands
[0]->type
|| ir
->operands
[2]->type
== glsl_type::float_type
);
550 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_BOOL
);
551 assert(ir
->type
->vector_elements
== ir
->operands
[0]->type
->vector_elements
);
552 assert(ir
->type
== ir
->operands
[1]->type
);
553 assert(ir
->type
== ir
->operands
[2]->type
);
557 assert(ir
->operands
[0]->type
->is_integer());
558 assert(ir
->operands
[1]->type
== ir
->operands
[2]->type
);
559 assert(ir
->operands
[1]->type
== ir
->type
);
562 case ir_triop_bitfield_extract
:
563 assert(ir
->operands
[0]->type
== ir
->type
);
564 assert(ir
->operands
[1]->type
== glsl_type::int_type
);
565 assert(ir
->operands
[2]->type
== glsl_type::int_type
);
568 case ir_triop_vector_insert
:
569 assert(ir
->operands
[0]->type
->is_vector());
570 assert(ir
->operands
[1]->type
->is_scalar());
571 assert(ir
->operands
[0]->type
->base_type
== ir
->operands
[1]->type
->base_type
);
572 assert(ir
->operands
[2]->type
->is_scalar()
573 && ir
->operands
[2]->type
->is_integer());
574 assert(ir
->type
== ir
->operands
[0]->type
);
577 case ir_quadop_bitfield_insert
:
578 assert(ir
->operands
[0]->type
== ir
->type
);
579 assert(ir
->operands
[1]->type
== ir
->type
);
580 assert(ir
->operands
[2]->type
== glsl_type::int_type
);
581 assert(ir
->operands
[3]->type
== glsl_type::int_type
);
584 case ir_quadop_vector
:
585 /* The vector operator collects some number of scalars and generates a
588 * - All of the operands must be scalar.
589 * - Number of operands must matche the size of the resulting vector.
590 * - Base type of the operands must match the base type of the result.
592 assert(ir
->type
->is_vector());
593 switch (ir
->type
->vector_elements
) {
595 assert(ir
->operands
[0]->type
->is_scalar());
596 assert(ir
->operands
[0]->type
->base_type
== ir
->type
->base_type
);
597 assert(ir
->operands
[1]->type
->is_scalar());
598 assert(ir
->operands
[1]->type
->base_type
== ir
->type
->base_type
);
599 assert(ir
->operands
[2] == NULL
);
600 assert(ir
->operands
[3] == NULL
);
603 assert(ir
->operands
[0]->type
->is_scalar());
604 assert(ir
->operands
[0]->type
->base_type
== ir
->type
->base_type
);
605 assert(ir
->operands
[1]->type
->is_scalar());
606 assert(ir
->operands
[1]->type
->base_type
== ir
->type
->base_type
);
607 assert(ir
->operands
[2]->type
->is_scalar());
608 assert(ir
->operands
[2]->type
->base_type
== ir
->type
->base_type
);
609 assert(ir
->operands
[3] == NULL
);
612 assert(ir
->operands
[0]->type
->is_scalar());
613 assert(ir
->operands
[0]->type
->base_type
== ir
->type
->base_type
);
614 assert(ir
->operands
[1]->type
->is_scalar());
615 assert(ir
->operands
[1]->type
->base_type
== ir
->type
->base_type
);
616 assert(ir
->operands
[2]->type
->is_scalar());
617 assert(ir
->operands
[2]->type
->base_type
== ir
->type
->base_type
);
618 assert(ir
->operands
[3]->type
->is_scalar());
619 assert(ir
->operands
[3]->type
->base_type
== ir
->type
->base_type
);
622 /* The is_vector assertion above should prevent execution from ever
625 assert(!"Should not get here.");
630 return visit_continue
;
634 ir_validate::visit_leave(ir_swizzle
*ir
)
636 unsigned int chans
[4] = {ir
->mask
.x
, ir
->mask
.y
, ir
->mask
.z
, ir
->mask
.w
};
638 for (unsigned int i
= 0; i
< ir
->type
->vector_elements
; i
++) {
639 if (chans
[i
] >= ir
->val
->type
->vector_elements
) {
640 printf("ir_swizzle @ %p specifies a channel not present "
641 "in the value.\n", (void *) ir
);
647 return visit_continue
;
651 ir_validate::visit(ir_variable
*ir
)
653 /* An ir_variable is the one thing that can (and will) appear multiple times
654 * in an IR tree. It is added to the hashtable so that it can be used
655 * in the ir_dereference_variable handler to ensure that a variable is
656 * declared before it is dereferenced.
659 assert(ralloc_parent(ir
->name
) == ir
);
661 hash_table_insert(ht
, ir
, ir
);
664 /* If a variable is an array, verify that the maximum array index is in
665 * bounds. There was once an error in AST-to-HIR conversion that set this
666 * to be out of bounds.
668 if (ir
->type
->array_size() > 0) {
669 if (ir
->max_array_access
>= ir
->type
->length
) {
670 printf("ir_variable has maximum access out of bounds (%d vs %d)\n",
671 ir
->max_array_access
, ir
->type
->length
- 1);
677 if (ir
->constant_initializer
!= NULL
&& !ir
->has_initializer
) {
678 printf("ir_variable didn't have an initializer, but has a constant "
679 "initializer value.\n");
684 return visit_continue
;
688 ir_validate::visit_enter(ir_assignment
*ir
)
690 const ir_dereference
*const lhs
= ir
->lhs
;
691 if (lhs
->type
->is_scalar() || lhs
->type
->is_vector()) {
692 if (ir
->write_mask
== 0) {
693 printf("Assignment LHS is %s, but write mask is 0:\n",
694 lhs
->type
->is_scalar() ? "scalar" : "vector");
699 int lhs_components
= 0;
700 for (int i
= 0; i
< 4; i
++) {
701 if (ir
->write_mask
& (1 << i
))
705 if (lhs_components
!= ir
->rhs
->type
->vector_elements
) {
706 printf("Assignment count of LHS write mask channels enabled not\n"
707 "matching RHS vector size (%d LHS, %d RHS).\n",
708 lhs_components
, ir
->rhs
->type
->vector_elements
);
714 this->validate_ir(ir
, this->data
);
716 return visit_continue
;
720 ir_validate::visit_enter(ir_call
*ir
)
722 ir_function_signature
*const callee
= ir
->callee
;
724 if (callee
->ir_type
!= ir_type_function_signature
) {
725 printf("IR called by ir_call is not ir_function_signature!\n");
729 if (ir
->return_deref
) {
730 if (ir
->return_deref
->type
!= callee
->return_type
) {
731 printf("callee type %s does not match return storage type %s\n",
732 callee
->return_type
->name
, ir
->return_deref
->type
->name
);
735 } else if (callee
->return_type
!= glsl_type::void_type
) {
736 printf("ir_call has non-void callee but no return storage\n");
740 const exec_node
*formal_param_node
= callee
->parameters
.head
;
741 const exec_node
*actual_param_node
= ir
->actual_parameters
.head
;
743 if (formal_param_node
->is_tail_sentinel()
744 != actual_param_node
->is_tail_sentinel()) {
745 printf("ir_call has the wrong number of parameters:\n");
748 if (formal_param_node
->is_tail_sentinel()) {
751 const ir_variable
*formal_param
752 = (const ir_variable
*) formal_param_node
;
753 const ir_rvalue
*actual_param
754 = (const ir_rvalue
*) actual_param_node
;
755 if (formal_param
->type
!= actual_param
->type
) {
756 printf("ir_call parameter type mismatch:\n");
759 if (formal_param
->mode
== ir_var_function_out
760 || formal_param
->mode
== ir_var_function_inout
) {
761 if (!actual_param
->is_lvalue()) {
762 printf("ir_call out/inout parameters must be lvalues:\n");
766 formal_param_node
= formal_param_node
->next
;
767 actual_param_node
= actual_param_node
->next
;
770 return visit_continue
;
781 ir_validate::validate_ir(ir_instruction
*ir
, void *data
)
783 struct hash_table
*ht
= (struct hash_table
*) data
;
785 if (hash_table_find(ht
, ir
)) {
786 printf("Instruction node present twice in ir tree:\n");
791 hash_table_insert(ht
, ir
, ir
);
795 check_node_type(ir_instruction
*ir
, void *data
)
799 if (ir
->ir_type
<= ir_type_unset
|| ir
->ir_type
>= ir_type_max
) {
800 printf("Instruction node with unset type\n");
801 ir
->print(); printf("\n");
803 ir_rvalue
*value
= ir
->as_rvalue();
805 assert(value
->type
!= glsl_type::error_type
);
809 validate_ir_tree(exec_list
*instructions
)
811 /* We shouldn't have any reason to validate IR in a release build,
812 * and it's half composed of assert()s anyway which wouldn't do
820 foreach_iter(exec_list_iterator
, iter
, *instructions
) {
821 ir_instruction
*ir
= (ir_instruction
*)iter
.get();
823 visit_tree(ir
, check_node_type
, NULL
);