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_enter
= ir_validate::validate_ir
;
53 this->data_enter
= ht
;
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_enter
);
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_enter
);
172 /* Verify that all of the things stored in the list of signatures are,
173 * in fact, function signatures.
175 foreach_in_list(ir_instruction
, sig
, &ir
->signatures
) {
176 if (sig
->ir_type
!= ir_type_function_signature
) {
177 printf("Non-signature in signature list of function `%s'\n",
183 return visit_continue
;
187 ir_validate::visit_leave(ir_function
*ir
)
189 assert(ralloc_parent(ir
->name
) == ir
);
191 this->current_function
= NULL
;
192 return visit_continue
;
196 ir_validate::visit_enter(ir_function_signature
*ir
)
198 if (this->current_function
!= ir
->function()) {
199 printf("Function signature nested inside wrong function "
201 printf("%p inside %s %p instead of %s %p\n",
203 this->current_function
->name
, (void *) this->current_function
,
204 ir
->function_name(), (void *) ir
->function());
208 if (ir
->return_type
== NULL
) {
209 printf("Function signature %p for function %s has NULL return type.\n",
210 (void *) ir
, ir
->function_name());
214 this->validate_ir(ir
, this->data_enter
);
216 return visit_continue
;
220 ir_validate::visit_leave(ir_expression
*ir
)
222 switch (ir
->operation
) {
223 case ir_unop_bit_not
:
224 assert(ir
->operands
[0]->type
== ir
->type
);
226 case ir_unop_logic_not
:
227 assert(ir
->type
->base_type
== GLSL_TYPE_BOOL
);
228 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_BOOL
);
237 assert(ir
->type
== ir
->operands
[0]->type
);
244 case ir_unop_saturate
:
245 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
246 assert(ir
->type
== ir
->operands
[0]->type
);
250 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
251 assert(ir
->type
->base_type
== GLSL_TYPE_INT
);
254 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
255 assert(ir
->type
->base_type
== GLSL_TYPE_UINT
);
258 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_INT
);
259 assert(ir
->type
->base_type
== GLSL_TYPE_FLOAT
);
262 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
263 assert(ir
->type
->base_type
== GLSL_TYPE_BOOL
);
266 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_BOOL
);
267 assert(ir
->type
->base_type
== GLSL_TYPE_FLOAT
);
270 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_INT
);
271 assert(ir
->type
->base_type
== GLSL_TYPE_BOOL
);
274 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_BOOL
);
275 assert(ir
->type
->base_type
== GLSL_TYPE_INT
);
278 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_UINT
);
279 assert(ir
->type
->base_type
== GLSL_TYPE_FLOAT
);
282 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_INT
);
283 assert(ir
->type
->base_type
== GLSL_TYPE_UINT
);
286 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_UINT
);
287 assert(ir
->type
->base_type
== GLSL_TYPE_INT
);
289 case ir_unop_bitcast_i2f
:
290 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_INT
);
291 assert(ir
->type
->base_type
== GLSL_TYPE_FLOAT
);
293 case ir_unop_bitcast_f2i
:
294 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
295 assert(ir
->type
->base_type
== GLSL_TYPE_INT
);
297 case ir_unop_bitcast_u2f
:
298 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_UINT
);
299 assert(ir
->type
->base_type
== GLSL_TYPE_FLOAT
);
301 case ir_unop_bitcast_f2u
:
302 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
303 assert(ir
->type
->base_type
== GLSL_TYPE_UINT
);
307 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_BOOL
);
308 assert(ir
->type
== glsl_type::bool_type
);
312 case ir_unop_round_even
:
318 case ir_unop_sin_reduced
:
319 case ir_unop_cos_reduced
:
321 case ir_unop_dFdx_coarse
:
322 case ir_unop_dFdx_fine
:
324 case ir_unop_dFdy_coarse
:
325 case ir_unop_dFdy_fine
:
326 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
327 assert(ir
->operands
[0]->type
== ir
->type
);
330 case ir_unop_pack_snorm_2x16
:
331 case ir_unop_pack_unorm_2x16
:
332 case ir_unop_pack_half_2x16
:
333 assert(ir
->type
== glsl_type::uint_type
);
334 assert(ir
->operands
[0]->type
== glsl_type::vec2_type
);
337 case ir_unop_pack_snorm_4x8
:
338 case ir_unop_pack_unorm_4x8
:
339 assert(ir
->type
== glsl_type::uint_type
);
340 assert(ir
->operands
[0]->type
== glsl_type::vec4_type
);
343 case ir_unop_unpack_snorm_2x16
:
344 case ir_unop_unpack_unorm_2x16
:
345 case ir_unop_unpack_half_2x16
:
346 assert(ir
->type
== glsl_type::vec2_type
);
347 assert(ir
->operands
[0]->type
== glsl_type::uint_type
);
350 case ir_unop_unpack_snorm_4x8
:
351 case ir_unop_unpack_unorm_4x8
:
352 assert(ir
->type
== glsl_type::vec4_type
);
353 assert(ir
->operands
[0]->type
== glsl_type::uint_type
);
356 case ir_unop_unpack_half_2x16_split_x
:
357 case ir_unop_unpack_half_2x16_split_y
:
358 assert(ir
->type
== glsl_type::float_type
);
359 assert(ir
->operands
[0]->type
== glsl_type::uint_type
);
362 case ir_unop_bitfield_reverse
:
363 assert(ir
->operands
[0]->type
== ir
->type
);
364 assert(ir
->type
->is_integer());
367 case ir_unop_bit_count
:
368 case ir_unop_find_msb
:
369 case ir_unop_find_lsb
:
370 assert(ir
->operands
[0]->type
->vector_elements
== ir
->type
->vector_elements
);
371 assert(ir
->operands
[0]->type
->is_integer());
372 assert(ir
->type
->base_type
== GLSL_TYPE_INT
);
376 /* XXX what can we assert here? */
379 case ir_unop_interpolate_at_centroid
:
380 assert(ir
->operands
[0]->type
== ir
->type
);
381 assert(ir
->operands
[0]->type
->is_float());
392 assert(ir
->operands
[0]->type
->base_type
==
393 ir
->operands
[1]->type
->base_type
);
395 if (ir
->operands
[0]->type
->is_scalar())
396 assert(ir
->operands
[1]->type
== ir
->type
);
397 else if (ir
->operands
[1]->type
->is_scalar())
398 assert(ir
->operands
[0]->type
== ir
->type
);
399 else if (ir
->operands
[0]->type
->is_vector() &&
400 ir
->operands
[1]->type
->is_vector()) {
401 assert(ir
->operands
[0]->type
== ir
->operands
[1]->type
);
402 assert(ir
->operands
[0]->type
== ir
->type
);
406 case ir_binop_imul_high
:
407 assert(ir
->type
== ir
->operands
[0]->type
);
408 assert(ir
->type
== ir
->operands
[1]->type
);
409 assert(ir
->type
->is_integer());
413 case ir_binop_borrow
:
414 assert(ir
->type
== ir
->operands
[0]->type
);
415 assert(ir
->type
== ir
->operands
[1]->type
);
416 assert(ir
->type
->base_type
== GLSL_TYPE_UINT
);
420 case ir_binop_greater
:
421 case ir_binop_lequal
:
422 case ir_binop_gequal
:
424 case ir_binop_nequal
:
425 /* The semantics of the IR operators differ from the GLSL <, >, <=, >=,
426 * ==, and != operators. The IR operators perform a component-wise
427 * comparison on scalar or vector types and return a boolean scalar or
428 * vector type of the same size.
430 assert(ir
->type
->base_type
== GLSL_TYPE_BOOL
);
431 assert(ir
->operands
[0]->type
== ir
->operands
[1]->type
);
432 assert(ir
->operands
[0]->type
->is_vector()
433 || ir
->operands
[0]->type
->is_scalar());
434 assert(ir
->operands
[0]->type
->vector_elements
435 == ir
->type
->vector_elements
);
438 case ir_binop_all_equal
:
439 case ir_binop_any_nequal
:
440 /* GLSL == and != operate on scalars, vectors, matrices and arrays, and
441 * return a scalar boolean. The IR matches that.
443 assert(ir
->type
== glsl_type::bool_type
);
444 assert(ir
->operands
[0]->type
== ir
->operands
[1]->type
);
447 case ir_binop_lshift
:
448 case ir_binop_rshift
:
449 assert(ir
->operands
[0]->type
->is_integer() &&
450 ir
->operands
[1]->type
->is_integer());
451 if (ir
->operands
[0]->type
->is_scalar()) {
452 assert(ir
->operands
[1]->type
->is_scalar());
454 if (ir
->operands
[0]->type
->is_vector() &&
455 ir
->operands
[1]->type
->is_vector()) {
456 assert(ir
->operands
[0]->type
->components() ==
457 ir
->operands
[1]->type
->components());
459 assert(ir
->type
== ir
->operands
[0]->type
);
462 case ir_binop_bit_and
:
463 case ir_binop_bit_xor
:
464 case ir_binop_bit_or
:
465 assert(ir
->operands
[0]->type
->base_type
==
466 ir
->operands
[1]->type
->base_type
);
467 assert(ir
->type
->is_integer());
468 if (ir
->operands
[0]->type
->is_vector() &&
469 ir
->operands
[1]->type
->is_vector()) {
470 assert(ir
->operands
[0]->type
->vector_elements
==
471 ir
->operands
[1]->type
->vector_elements
);
475 case ir_binop_logic_and
:
476 case ir_binop_logic_xor
:
477 case ir_binop_logic_or
:
478 assert(ir
->type
== glsl_type::bool_type
);
479 assert(ir
->operands
[0]->type
== glsl_type::bool_type
);
480 assert(ir
->operands
[1]->type
== glsl_type::bool_type
);
484 assert(ir
->type
== glsl_type::float_type
);
485 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
486 assert(ir
->operands
[0]->type
->is_vector());
487 assert(ir
->operands
[0]->type
== ir
->operands
[1]->type
);
490 case ir_binop_pack_half_2x16_split
:
491 assert(ir
->type
== glsl_type::uint_type
);
492 assert(ir
->operands
[0]->type
== glsl_type::float_type
);
493 assert(ir
->operands
[1]->type
== glsl_type::float_type
);
497 assert(ir
->type
->is_integer());
498 assert(ir
->operands
[0]->type
->is_integer());
499 assert(ir
->operands
[1]->type
->is_integer());
502 case ir_binop_ubo_load
:
503 assert(ir
->operands
[0]->type
== glsl_type::uint_type
);
505 assert(ir
->operands
[1]->type
== glsl_type::uint_type
);
509 assert(ir
->operands
[0]->type
== ir
->type
);
510 assert(ir
->operands
[0]->type
->is_float());
511 assert(ir
->operands
[1]->type
->base_type
== GLSL_TYPE_INT
);
512 assert(ir
->operands
[0]->type
->components() ==
513 ir
->operands
[1]->type
->components());
516 case ir_binop_vector_extract
:
517 assert(ir
->operands
[0]->type
->is_vector());
518 assert(ir
->operands
[1]->type
->is_scalar()
519 && ir
->operands
[1]->type
->is_integer());
522 case ir_binop_interpolate_at_offset
:
523 assert(ir
->operands
[0]->type
== ir
->type
);
524 assert(ir
->operands
[0]->type
->is_float());
525 assert(ir
->operands
[1]->type
->components() == 2);
526 assert(ir
->operands
[1]->type
->is_float());
529 case ir_binop_interpolate_at_sample
:
530 assert(ir
->operands
[0]->type
== ir
->type
);
531 assert(ir
->operands
[0]->type
->is_float());
532 assert(ir
->operands
[1]->type
== glsl_type::int_type
);
536 assert(ir
->type
->base_type
== GLSL_TYPE_FLOAT
);
537 assert(ir
->type
== ir
->operands
[0]->type
);
538 assert(ir
->type
== ir
->operands
[1]->type
);
539 assert(ir
->type
== ir
->operands
[2]->type
);
543 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
544 assert(ir
->operands
[0]->type
== ir
->operands
[1]->type
);
545 assert(ir
->operands
[2]->type
== ir
->operands
[0]->type
|| ir
->operands
[2]->type
== glsl_type::float_type
);
549 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_BOOL
);
550 assert(ir
->type
->vector_elements
== ir
->operands
[0]->type
->vector_elements
);
551 assert(ir
->type
== ir
->operands
[1]->type
);
552 assert(ir
->type
== ir
->operands
[2]->type
);
556 assert(ir
->operands
[0]->type
->is_integer());
557 assert(ir
->operands
[1]->type
== ir
->operands
[2]->type
);
558 assert(ir
->operands
[1]->type
== ir
->type
);
561 case ir_triop_bitfield_extract
:
562 assert(ir
->operands
[0]->type
== ir
->type
);
563 assert(ir
->operands
[1]->type
== glsl_type::int_type
);
564 assert(ir
->operands
[2]->type
== glsl_type::int_type
);
567 case ir_triop_vector_insert
:
568 assert(ir
->operands
[0]->type
->is_vector());
569 assert(ir
->operands
[1]->type
->is_scalar());
570 assert(ir
->operands
[0]->type
->base_type
== ir
->operands
[1]->type
->base_type
);
571 assert(ir
->operands
[2]->type
->is_scalar()
572 && ir
->operands
[2]->type
->is_integer());
573 assert(ir
->type
== ir
->operands
[0]->type
);
576 case ir_quadop_bitfield_insert
:
577 assert(ir
->operands
[0]->type
== ir
->type
);
578 assert(ir
->operands
[1]->type
== ir
->type
);
579 assert(ir
->operands
[2]->type
== glsl_type::int_type
);
580 assert(ir
->operands
[3]->type
== glsl_type::int_type
);
583 case ir_quadop_vector
:
584 /* The vector operator collects some number of scalars and generates a
587 * - All of the operands must be scalar.
588 * - Number of operands must matche the size of the resulting vector.
589 * - Base type of the operands must match the base type of the result.
591 assert(ir
->type
->is_vector());
592 switch (ir
->type
->vector_elements
) {
594 assert(ir
->operands
[0]->type
->is_scalar());
595 assert(ir
->operands
[0]->type
->base_type
== ir
->type
->base_type
);
596 assert(ir
->operands
[1]->type
->is_scalar());
597 assert(ir
->operands
[1]->type
->base_type
== ir
->type
->base_type
);
598 assert(ir
->operands
[2] == NULL
);
599 assert(ir
->operands
[3] == NULL
);
602 assert(ir
->operands
[0]->type
->is_scalar());
603 assert(ir
->operands
[0]->type
->base_type
== ir
->type
->base_type
);
604 assert(ir
->operands
[1]->type
->is_scalar());
605 assert(ir
->operands
[1]->type
->base_type
== ir
->type
->base_type
);
606 assert(ir
->operands
[2]->type
->is_scalar());
607 assert(ir
->operands
[2]->type
->base_type
== ir
->type
->base_type
);
608 assert(ir
->operands
[3] == NULL
);
611 assert(ir
->operands
[0]->type
->is_scalar());
612 assert(ir
->operands
[0]->type
->base_type
== ir
->type
->base_type
);
613 assert(ir
->operands
[1]->type
->is_scalar());
614 assert(ir
->operands
[1]->type
->base_type
== ir
->type
->base_type
);
615 assert(ir
->operands
[2]->type
->is_scalar());
616 assert(ir
->operands
[2]->type
->base_type
== ir
->type
->base_type
);
617 assert(ir
->operands
[3]->type
->is_scalar());
618 assert(ir
->operands
[3]->type
->base_type
== ir
->type
->base_type
);
621 /* The is_vector assertion above should prevent execution from ever
624 assert(!"Should not get here.");
629 return visit_continue
;
633 ir_validate::visit_leave(ir_swizzle
*ir
)
635 unsigned int chans
[4] = {ir
->mask
.x
, ir
->mask
.y
, ir
->mask
.z
, ir
->mask
.w
};
637 for (unsigned int i
= 0; i
< ir
->type
->vector_elements
; i
++) {
638 if (chans
[i
] >= ir
->val
->type
->vector_elements
) {
639 printf("ir_swizzle @ %p specifies a channel not present "
640 "in the value.\n", (void *) ir
);
646 return visit_continue
;
650 ir_validate::visit(ir_variable
*ir
)
652 /* An ir_variable is the one thing that can (and will) appear multiple times
653 * in an IR tree. It is added to the hashtable so that it can be used
654 * in the ir_dereference_variable handler to ensure that a variable is
655 * declared before it is dereferenced.
657 if (ir
->name
&& ir
->is_name_ralloced())
658 assert(ralloc_parent(ir
->name
) == ir
);
660 hash_table_insert(ht
, ir
, ir
);
663 /* If a variable is an array, verify that the maximum array index is in
664 * bounds. There was once an error in AST-to-HIR conversion that set this
665 * to be out of bounds.
667 if (ir
->type
->array_size() > 0) {
668 if (ir
->data
.max_array_access
>= ir
->type
->length
) {
669 printf("ir_variable has maximum access out of bounds (%d vs %d)\n",
670 ir
->data
.max_array_access
, ir
->type
->length
- 1);
676 /* If a variable is an interface block (or an array of interface blocks),
677 * verify that the maximum array index for each interface member is in
680 if (ir
->is_interface_instance()) {
681 const glsl_struct_field
*fields
=
682 ir
->get_interface_type()->fields
.structure
;
683 for (unsigned i
= 0; i
< ir
->get_interface_type()->length
; i
++) {
684 if (fields
[i
].type
->array_size() > 0) {
685 const unsigned *const max_ifc_array_access
=
686 ir
->get_max_ifc_array_access();
688 assert(max_ifc_array_access
!= NULL
);
690 if (max_ifc_array_access
[i
] >= fields
[i
].type
->length
) {
691 printf("ir_variable has maximum access out of bounds for "
692 "field %s (%d vs %d)\n", fields
[i
].name
,
693 max_ifc_array_access
[i
], fields
[i
].type
->length
);
701 if (ir
->constant_initializer
!= NULL
&& !ir
->data
.has_initializer
) {
702 printf("ir_variable didn't have an initializer, but has a constant "
703 "initializer value.\n");
708 if (ir
->data
.mode
== ir_var_uniform
709 && is_gl_identifier(ir
->name
)
710 && ir
->get_state_slots() == NULL
) {
711 printf("built-in uniform has no state\n");
716 return visit_continue
;
720 ir_validate::visit_enter(ir_assignment
*ir
)
722 const ir_dereference
*const lhs
= ir
->lhs
;
723 if (lhs
->type
->is_scalar() || lhs
->type
->is_vector()) {
724 if (ir
->write_mask
== 0) {
725 printf("Assignment LHS is %s, but write mask is 0:\n",
726 lhs
->type
->is_scalar() ? "scalar" : "vector");
731 int lhs_components
= 0;
732 for (int i
= 0; i
< 4; i
++) {
733 if (ir
->write_mask
& (1 << i
))
737 if (lhs_components
!= ir
->rhs
->type
->vector_elements
) {
738 printf("Assignment count of LHS write mask channels enabled not\n"
739 "matching RHS vector size (%d LHS, %d RHS).\n",
740 lhs_components
, ir
->rhs
->type
->vector_elements
);
746 this->validate_ir(ir
, this->data_enter
);
748 return visit_continue
;
752 ir_validate::visit_enter(ir_call
*ir
)
754 ir_function_signature
*const callee
= ir
->callee
;
756 if (callee
->ir_type
!= ir_type_function_signature
) {
757 printf("IR called by ir_call is not ir_function_signature!\n");
761 if (ir
->return_deref
) {
762 if (ir
->return_deref
->type
!= callee
->return_type
) {
763 printf("callee type %s does not match return storage type %s\n",
764 callee
->return_type
->name
, ir
->return_deref
->type
->name
);
767 } else if (callee
->return_type
!= glsl_type::void_type
) {
768 printf("ir_call has non-void callee but no return storage\n");
772 const exec_node
*formal_param_node
= callee
->parameters
.head
;
773 const exec_node
*actual_param_node
= ir
->actual_parameters
.head
;
775 if (formal_param_node
->is_tail_sentinel()
776 != actual_param_node
->is_tail_sentinel()) {
777 printf("ir_call has the wrong number of parameters:\n");
780 if (formal_param_node
->is_tail_sentinel()) {
783 const ir_variable
*formal_param
784 = (const ir_variable
*) formal_param_node
;
785 const ir_rvalue
*actual_param
786 = (const ir_rvalue
*) actual_param_node
;
787 if (formal_param
->type
!= actual_param
->type
) {
788 printf("ir_call parameter type mismatch:\n");
791 if (formal_param
->data
.mode
== ir_var_function_out
792 || formal_param
->data
.mode
== ir_var_function_inout
) {
793 if (!actual_param
->is_lvalue()) {
794 printf("ir_call out/inout parameters must be lvalues:\n");
798 formal_param_node
= formal_param_node
->next
;
799 actual_param_node
= actual_param_node
->next
;
802 return visit_continue
;
813 ir_validate::validate_ir(ir_instruction
*ir
, void *data
)
815 struct hash_table
*ht
= (struct hash_table
*) data
;
817 if (hash_table_find(ht
, ir
)) {
818 printf("Instruction node present twice in ir tree:\n");
823 hash_table_insert(ht
, ir
, ir
);
827 check_node_type(ir_instruction
*ir
, void *data
)
831 if (ir
->ir_type
>= ir_type_max
) {
832 printf("Instruction node with unset type\n");
833 ir
->print(); printf("\n");
835 ir_rvalue
*value
= ir
->as_rvalue();
837 assert(value
->type
!= glsl_type::error_type
);
841 validate_ir_tree(exec_list
*instructions
)
843 /* We shouldn't have any reason to validate IR in a release build,
844 * and it's half composed of assert()s anyway which wouldn't do
852 foreach_in_list(ir_instruction
, ir
, instructions
) {
853 visit_tree(ir
, check_node_type
, NULL
);