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 "util/hash_table.h"
40 #include "compiler/glsl_types.h"
44 class ir_validate
: public ir_hierarchical_visitor
{
48 this->ir_set
= _mesa_set_create(NULL
, _mesa_hash_pointer
,
49 _mesa_key_pointer_equal
);
51 this->current_function
= NULL
;
53 this->callback_enter
= ir_validate::validate_ir
;
54 this->data_enter
= ir_set
;
59 _mesa_set_destroy(this->ir_set
, NULL
);
62 virtual ir_visitor_status
visit(ir_variable
*v
);
63 virtual ir_visitor_status
visit(ir_dereference_variable
*ir
);
65 virtual ir_visitor_status
visit_enter(ir_discard
*ir
);
66 virtual ir_visitor_status
visit_enter(ir_if
*ir
);
68 virtual ir_visitor_status
visit_enter(ir_function
*ir
);
69 virtual ir_visitor_status
visit_leave(ir_function
*ir
);
70 virtual ir_visitor_status
visit_enter(ir_function_signature
*ir
);
72 virtual ir_visitor_status
visit_leave(ir_expression
*ir
);
73 virtual ir_visitor_status
visit_leave(ir_swizzle
*ir
);
75 virtual ir_visitor_status
visit_enter(class ir_dereference_array
*);
77 virtual ir_visitor_status
visit_enter(ir_assignment
*ir
);
78 virtual ir_visitor_status
visit_enter(ir_call
*ir
);
80 static void validate_ir(ir_instruction
*ir
, void *data
);
82 ir_function
*current_function
;
87 } /* anonymous namespace */
90 ir_validate::visit(ir_dereference_variable
*ir
)
92 if ((ir
->var
== NULL
) || (ir
->var
->as_variable() == NULL
)) {
93 printf("ir_dereference_variable @ %p does not specify a variable %p\n",
94 (void *) ir
, (void *) ir
->var
);
98 if (_mesa_set_search(ir_set
, ir
->var
) == NULL
) {
99 printf("ir_dereference_variable @ %p specifies undeclared variable "
101 (void *) ir
, ir
->var
->name
, (void *) ir
->var
);
105 this->validate_ir(ir
, this->data_enter
);
107 return visit_continue
;
111 ir_validate::visit_enter(class ir_dereference_array
*ir
)
113 if (!ir
->array
->type
->is_array() && !ir
->array
->type
->is_matrix() &&
114 !ir
->array
->type
->is_vector()) {
115 printf("ir_dereference_array @ %p does not specify an array, a vector "
123 if (!ir
->array_index
->type
->is_scalar()) {
124 printf("ir_dereference_array @ %p does not have scalar index: %s\n",
125 (void *) ir
, ir
->array_index
->type
->name
);
129 if (!ir
->array_index
->type
->is_integer()) {
130 printf("ir_dereference_array @ %p does not have integer index: %s\n",
131 (void *) ir
, ir
->array_index
->type
->name
);
135 return visit_continue
;
139 ir_validate::visit_enter(ir_discard
*ir
)
141 if (ir
->condition
&& ir
->condition
->type
!= glsl_type::bool_type
) {
142 printf("ir_discard condition %s type instead of bool.\n",
143 ir
->condition
->type
->name
);
149 return visit_continue
;
153 ir_validate::visit_enter(ir_if
*ir
)
155 if (ir
->condition
->type
!= glsl_type::bool_type
) {
156 printf("ir_if condition %s type instead of bool.\n",
157 ir
->condition
->type
->name
);
163 return visit_continue
;
168 ir_validate::visit_enter(ir_function
*ir
)
170 /* Function definitions cannot be nested.
172 if (this->current_function
!= NULL
) {
173 printf("Function definition nested inside another function "
175 printf("%s %p inside %s %p\n",
176 ir
->name
, (void *) ir
,
177 this->current_function
->name
, (void *) this->current_function
);
181 /* Store the current function hierarchy being traversed. This is used
182 * by the function signature visitor to ensure that the signatures are
183 * linked with the correct functions.
185 this->current_function
= ir
;
187 this->validate_ir(ir
, this->data_enter
);
189 /* Verify that all of the things stored in the list of signatures are,
190 * in fact, function signatures.
192 foreach_in_list(ir_instruction
, sig
, &ir
->signatures
) {
193 if (sig
->ir_type
!= ir_type_function_signature
) {
194 printf("Non-signature in signature list of function `%s'\n",
200 return visit_continue
;
204 ir_validate::visit_leave(ir_function
*ir
)
206 assert(ralloc_parent(ir
->name
) == ir
);
208 this->current_function
= NULL
;
209 return visit_continue
;
213 ir_validate::visit_enter(ir_function_signature
*ir
)
215 if (this->current_function
!= ir
->function()) {
216 printf("Function signature nested inside wrong function "
218 printf("%p inside %s %p instead of %s %p\n",
220 this->current_function
->name
, (void *) this->current_function
,
221 ir
->function_name(), (void *) ir
->function());
225 if (ir
->return_type
== NULL
) {
226 printf("Function signature %p for function %s has NULL return type.\n",
227 (void *) ir
, ir
->function_name());
231 this->validate_ir(ir
, this->data_enter
);
233 return visit_continue
;
237 ir_validate::visit_leave(ir_expression
*ir
)
239 switch (ir
->operation
) {
240 case ir_unop_bit_not
:
241 assert(ir
->operands
[0]->type
== ir
->type
);
243 case ir_unop_logic_not
:
244 assert(ir
->type
->is_boolean());
245 assert(ir
->operands
[0]->type
->is_boolean());
249 assert(ir
->type
== ir
->operands
[0]->type
);
254 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_INT
||
255 ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
||
256 ir
->operands
[0]->type
->is_double() ||
257 ir
->operands
[0]->type
->base_type
== GLSL_TYPE_INT64
);
258 assert(ir
->type
== ir
->operands
[0]->type
);
264 assert(ir
->type
->base_type
== GLSL_TYPE_FLOAT
||
265 ir
->type
->is_double());
266 assert(ir
->type
== ir
->operands
[0]->type
);
273 case ir_unop_saturate
:
274 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
275 assert(ir
->type
== ir
->operands
[0]->type
);
279 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
280 assert(ir
->type
->base_type
== GLSL_TYPE_INT
);
283 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
284 assert(ir
->type
->base_type
== GLSL_TYPE_UINT
);
287 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_INT
);
288 assert(ir
->type
->base_type
== GLSL_TYPE_FLOAT
);
291 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
292 assert(ir
->type
->is_boolean());
295 assert(ir
->operands
[0]->type
->is_boolean());
296 assert(ir
->type
->base_type
== GLSL_TYPE_FLOAT
);
299 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_INT
);
300 assert(ir
->type
->is_boolean());
303 assert(ir
->operands
[0]->type
->is_boolean());
304 assert(ir
->type
->base_type
== GLSL_TYPE_INT
);
307 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_UINT
);
308 assert(ir
->type
->base_type
== GLSL_TYPE_FLOAT
);
311 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_INT
);
312 assert(ir
->type
->base_type
== GLSL_TYPE_UINT
);
315 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_UINT
);
316 assert(ir
->type
->base_type
== GLSL_TYPE_INT
);
318 case ir_unop_bitcast_i2f
:
319 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_INT
);
320 assert(ir
->type
->base_type
== GLSL_TYPE_FLOAT
);
322 case ir_unop_bitcast_f2i
:
323 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
324 assert(ir
->type
->base_type
== GLSL_TYPE_INT
);
326 case ir_unop_bitcast_u2f
:
327 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_UINT
);
328 assert(ir
->type
->base_type
== GLSL_TYPE_FLOAT
);
330 case ir_unop_bitcast_f2u
:
331 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
332 assert(ir
->type
->base_type
== GLSL_TYPE_UINT
);
335 case ir_unop_bitcast_u642d
:
336 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_UINT64
);
337 assert(ir
->type
->is_double());
339 case ir_unop_bitcast_i642d
:
340 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_INT64
);
341 assert(ir
->type
->is_double());
343 case ir_unop_bitcast_d2u64
:
344 assert(ir
->operands
[0]->type
->is_double());
345 assert(ir
->type
->base_type
== GLSL_TYPE_UINT64
);
347 case ir_unop_bitcast_d2i64
:
348 assert(ir
->operands
[0]->type
->is_double());
349 assert(ir
->type
->base_type
== GLSL_TYPE_INT64
);
352 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_INT64
);
353 assert(ir
->type
->base_type
== GLSL_TYPE_INT
);
356 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_UINT64
);
357 assert(ir
->type
->base_type
== GLSL_TYPE_INT
);
360 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_INT64
);
361 assert(ir
->type
->base_type
== GLSL_TYPE_UINT
);
364 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_UINT64
);
365 assert(ir
->type
->base_type
== GLSL_TYPE_UINT
);
368 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_INT64
);
369 assert(ir
->type
->is_boolean());
372 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_INT64
);
373 assert(ir
->type
->base_type
== GLSL_TYPE_FLOAT
);
376 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_UINT64
);
377 assert(ir
->type
->base_type
== GLSL_TYPE_FLOAT
);
380 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_INT64
);
381 assert(ir
->type
->is_double());
384 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_UINT64
);
385 assert(ir
->type
->is_double());
388 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_INT
);
389 assert(ir
->type
->base_type
== GLSL_TYPE_INT64
);
392 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_UINT
);
393 assert(ir
->type
->base_type
== GLSL_TYPE_INT64
);
396 assert(ir
->operands
[0]->type
->is_boolean());
397 assert(ir
->type
->base_type
== GLSL_TYPE_INT64
);
400 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
401 assert(ir
->type
->base_type
== GLSL_TYPE_INT64
);
404 assert(ir
->operands
[0]->type
->is_double());
405 assert(ir
->type
->base_type
== GLSL_TYPE_INT64
);
408 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_INT
);
409 assert(ir
->type
->base_type
== GLSL_TYPE_UINT64
);
412 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_UINT
);
413 assert(ir
->type
->base_type
== GLSL_TYPE_UINT64
);
416 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
417 assert(ir
->type
->base_type
== GLSL_TYPE_UINT64
);
420 assert(ir
->operands
[0]->type
->is_double());
421 assert(ir
->type
->base_type
== GLSL_TYPE_UINT64
);
423 case ir_unop_u642i64
:
424 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_UINT64
);
425 assert(ir
->type
->base_type
== GLSL_TYPE_INT64
);
427 case ir_unop_i642u64
:
428 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_INT64
);
429 assert(ir
->type
->base_type
== GLSL_TYPE_UINT64
);
432 case ir_unop_round_even
:
436 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
||
437 ir
->operands
[0]->type
->is_double());
438 assert(ir
->operands
[0]->type
== ir
->type
);
443 case ir_unop_dFdx_coarse
:
444 case ir_unop_dFdx_fine
:
446 case ir_unop_dFdy_coarse
:
447 case ir_unop_dFdy_fine
:
448 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
449 assert(ir
->operands
[0]->type
== ir
->type
);
452 case ir_unop_pack_snorm_2x16
:
453 case ir_unop_pack_unorm_2x16
:
454 case ir_unop_pack_half_2x16
:
455 assert(ir
->type
== glsl_type::uint_type
);
456 assert(ir
->operands
[0]->type
== glsl_type::vec2_type
);
459 case ir_unop_pack_snorm_4x8
:
460 case ir_unop_pack_unorm_4x8
:
461 assert(ir
->type
== glsl_type::uint_type
);
462 assert(ir
->operands
[0]->type
== glsl_type::vec4_type
);
465 case ir_unop_pack_double_2x32
:
466 assert(ir
->type
== glsl_type::double_type
);
467 assert(ir
->operands
[0]->type
== glsl_type::uvec2_type
);
470 case ir_unop_pack_int_2x32
:
471 assert(ir
->type
== glsl_type::int64_t_type
);
472 assert(ir
->operands
[0]->type
== glsl_type::ivec2_type
);
475 case ir_unop_pack_uint_2x32
:
476 assert(ir
->type
== glsl_type::uint64_t_type
);
477 assert(ir
->operands
[0]->type
== glsl_type::uvec2_type
);
480 case ir_unop_unpack_snorm_2x16
:
481 case ir_unop_unpack_unorm_2x16
:
482 case ir_unop_unpack_half_2x16
:
483 assert(ir
->type
== glsl_type::vec2_type
);
484 assert(ir
->operands
[0]->type
== glsl_type::uint_type
);
487 case ir_unop_unpack_snorm_4x8
:
488 case ir_unop_unpack_unorm_4x8
:
489 assert(ir
->type
== glsl_type::vec4_type
);
490 assert(ir
->operands
[0]->type
== glsl_type::uint_type
);
493 case ir_unop_unpack_double_2x32
:
494 assert(ir
->type
== glsl_type::uvec2_type
);
495 assert(ir
->operands
[0]->type
== glsl_type::double_type
);
498 case ir_unop_unpack_int_2x32
:
499 assert(ir
->type
== glsl_type::ivec2_type
);
500 assert(ir
->operands
[0]->type
== glsl_type::int64_t_type
);
503 case ir_unop_unpack_uint_2x32
:
504 assert(ir
->type
== glsl_type::uvec2_type
);
505 assert(ir
->operands
[0]->type
== glsl_type::uint64_t_type
);
508 case ir_unop_bitfield_reverse
:
509 assert(ir
->operands
[0]->type
== ir
->type
);
510 assert(ir
->type
->is_integer());
513 case ir_unop_bit_count
:
514 case ir_unop_find_msb
:
515 case ir_unop_find_lsb
:
516 assert(ir
->operands
[0]->type
->vector_elements
== ir
->type
->vector_elements
);
517 assert(ir
->operands
[0]->type
->is_integer());
518 assert(ir
->type
->base_type
== GLSL_TYPE_INT
);
522 /* XXX what can we assert here? */
525 case ir_unop_interpolate_at_centroid
:
526 assert(ir
->operands
[0]->type
== ir
->type
);
527 assert(ir
->operands
[0]->type
->is_float());
530 case ir_unop_get_buffer_size
:
531 assert(ir
->type
== glsl_type::int_type
);
532 assert(ir
->operands
[0]->type
== glsl_type::uint_type
);
535 case ir_unop_ssbo_unsized_array_length
:
536 assert(ir
->type
== glsl_type::int_type
);
537 assert(ir
->operands
[0]->type
->is_array());
538 assert(ir
->operands
[0]->type
->is_unsized_array());
542 assert(ir
->operands
[0]->type
->is_double());
543 assert(ir
->type
->base_type
== GLSL_TYPE_FLOAT
);
546 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
);
547 assert(ir
->type
->is_double());
550 assert(ir
->operands
[0]->type
->is_double());
551 assert(ir
->type
->base_type
== GLSL_TYPE_INT
);
554 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_INT
);
555 assert(ir
->type
->is_double());
558 assert(ir
->operands
[0]->type
->is_double());
559 assert(ir
->type
->base_type
== GLSL_TYPE_UINT
);
562 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_UINT
);
563 assert(ir
->type
->is_double());
566 assert(ir
->operands
[0]->type
->is_double());
567 assert(ir
->type
->is_boolean());
570 case ir_unop_frexp_sig
:
571 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
||
572 ir
->operands
[0]->type
->is_double());
573 assert(ir
->type
->is_double());
575 case ir_unop_frexp_exp
:
576 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
||
577 ir
->operands
[0]->type
->is_double());
578 assert(ir
->type
->base_type
== GLSL_TYPE_INT
);
580 case ir_unop_subroutine_to_int
:
581 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_SUBROUTINE
);
582 assert(ir
->type
->base_type
== GLSL_TYPE_INT
);
586 assert(ir
->type
== glsl_type::uint64_t_type
);
587 assert(ir
->operands
[0]->type
== glsl_type::bool_type
);
590 case ir_binop_read_invocation
:
591 assert(ir
->operands
[1]->type
== glsl_type::uint_type
);
593 case ir_unop_read_first_invocation
:
594 assert(ir
->type
== ir
->operands
[0]->type
);
595 assert(ir
->type
->is_scalar() || ir
->type
->is_vector());
596 assert(ir
->type
->base_type
== GLSL_TYPE_FLOAT
||
597 ir
->type
->base_type
== GLSL_TYPE_INT
||
598 ir
->type
->base_type
== GLSL_TYPE_UINT
);
601 case ir_unop_vote_any
:
602 case ir_unop_vote_all
:
603 case ir_unop_vote_eq
:
604 assert(ir
->type
== glsl_type::bool_type
);
605 assert(ir
->operands
[0]->type
== glsl_type::bool_type
);
616 assert(ir
->operands
[0]->type
->base_type
==
617 ir
->operands
[1]->type
->base_type
);
619 if (ir
->operands
[0]->type
->is_scalar())
620 assert(ir
->operands
[1]->type
== ir
->type
);
621 else if (ir
->operands
[1]->type
->is_scalar())
622 assert(ir
->operands
[0]->type
== ir
->type
);
623 else if (ir
->operands
[0]->type
->is_vector() &&
624 ir
->operands
[1]->type
->is_vector()) {
625 assert(ir
->operands
[0]->type
== ir
->operands
[1]->type
);
626 assert(ir
->operands
[0]->type
== ir
->type
);
630 case ir_binop_imul_high
:
631 assert(ir
->type
== ir
->operands
[0]->type
);
632 assert(ir
->type
== ir
->operands
[1]->type
);
633 assert(ir
->type
->is_integer());
637 case ir_binop_borrow
:
638 assert(ir
->type
== ir
->operands
[0]->type
);
639 assert(ir
->type
== ir
->operands
[1]->type
);
640 assert(ir
->type
->base_type
== GLSL_TYPE_UINT
);
644 case ir_binop_greater
:
645 case ir_binop_lequal
:
646 case ir_binop_gequal
:
648 case ir_binop_nequal
:
649 /* The semantics of the IR operators differ from the GLSL <, >, <=, >=,
650 * ==, and != operators. The IR operators perform a component-wise
651 * comparison on scalar or vector types and return a boolean scalar or
652 * vector type of the same size.
654 assert(ir
->type
->is_boolean());
655 assert(ir
->operands
[0]->type
== ir
->operands
[1]->type
);
656 assert(ir
->operands
[0]->type
->is_vector()
657 || ir
->operands
[0]->type
->is_scalar());
658 assert(ir
->operands
[0]->type
->vector_elements
659 == ir
->type
->vector_elements
);
662 case ir_binop_all_equal
:
663 case ir_binop_any_nequal
:
664 /* GLSL == and != operate on scalars, vectors, matrices and arrays, and
665 * return a scalar boolean. The IR matches that.
667 assert(ir
->type
== glsl_type::bool_type
);
668 assert(ir
->operands
[0]->type
== ir
->operands
[1]->type
);
671 case ir_binop_lshift
:
672 case ir_binop_rshift
:
673 assert(ir
->operands
[0]->type
->is_integer_32_64() &&
674 ir
->operands
[1]->type
->is_integer());
675 if (ir
->operands
[0]->type
->is_scalar()) {
676 assert(ir
->operands
[1]->type
->is_scalar());
678 if (ir
->operands
[0]->type
->is_vector() &&
679 ir
->operands
[1]->type
->is_vector()) {
680 assert(ir
->operands
[0]->type
->components() ==
681 ir
->operands
[1]->type
->components());
683 assert(ir
->type
== ir
->operands
[0]->type
);
686 case ir_binop_bit_and
:
687 case ir_binop_bit_xor
:
688 case ir_binop_bit_or
:
689 assert(ir
->operands
[0]->type
->base_type
==
690 ir
->operands
[1]->type
->base_type
);
691 assert(ir
->type
->is_integer_32_64());
692 if (ir
->operands
[0]->type
->is_vector() &&
693 ir
->operands
[1]->type
->is_vector()) {
694 assert(ir
->operands
[0]->type
->vector_elements
==
695 ir
->operands
[1]->type
->vector_elements
);
699 case ir_binop_logic_and
:
700 case ir_binop_logic_xor
:
701 case ir_binop_logic_or
:
702 assert(ir
->type
->is_boolean());
703 assert(ir
->operands
[0]->type
->is_boolean());
704 assert(ir
->operands
[1]->type
->is_boolean());
708 assert(ir
->type
== glsl_type::float_type
||
709 ir
->type
== glsl_type::double_type
);
710 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
||
711 ir
->operands
[0]->type
->is_double());
712 assert(ir
->operands
[0]->type
->is_vector());
713 assert(ir
->operands
[0]->type
== ir
->operands
[1]->type
);
716 case ir_binop_ubo_load
:
717 assert(ir
->operands
[0]->type
== glsl_type::uint_type
);
719 assert(ir
->operands
[1]->type
== glsl_type::uint_type
);
723 assert(ir
->operands
[0]->type
== ir
->type
);
724 assert(ir
->operands
[0]->type
->is_float() ||
725 ir
->operands
[0]->type
->is_double());
726 assert(ir
->operands
[1]->type
->base_type
== GLSL_TYPE_INT
);
727 assert(ir
->operands
[0]->type
->components() ==
728 ir
->operands
[1]->type
->components());
731 case ir_binop_vector_extract
:
732 assert(ir
->operands
[0]->type
->is_vector());
733 assert(ir
->operands
[1]->type
->is_scalar()
734 && ir
->operands
[1]->type
->is_integer());
737 case ir_binop_interpolate_at_offset
:
738 assert(ir
->operands
[0]->type
== ir
->type
);
739 assert(ir
->operands
[0]->type
->is_float());
740 assert(ir
->operands
[1]->type
->components() == 2);
741 assert(ir
->operands
[1]->type
->is_float());
744 case ir_binop_interpolate_at_sample
:
745 assert(ir
->operands
[0]->type
== ir
->type
);
746 assert(ir
->operands
[0]->type
->is_float());
747 assert(ir
->operands
[1]->type
== glsl_type::int_type
);
751 assert(ir
->type
->base_type
== GLSL_TYPE_FLOAT
||
752 ir
->type
->is_double());
753 assert(ir
->type
== ir
->operands
[0]->type
);
754 assert(ir
->type
== ir
->operands
[1]->type
);
755 assert(ir
->type
== ir
->operands
[2]->type
);
759 assert(ir
->operands
[0]->type
->base_type
== GLSL_TYPE_FLOAT
||
760 ir
->operands
[0]->type
->is_double());
761 assert(ir
->operands
[0]->type
== ir
->operands
[1]->type
);
762 assert(ir
->operands
[2]->type
== ir
->operands
[0]->type
||
763 ir
->operands
[2]->type
== glsl_type::float_type
||
764 ir
->operands
[2]->type
== glsl_type::double_type
);
768 assert(ir
->operands
[0]->type
->is_boolean());
769 assert(ir
->type
->vector_elements
== ir
->operands
[0]->type
->vector_elements
);
770 assert(ir
->type
== ir
->operands
[1]->type
);
771 assert(ir
->type
== ir
->operands
[2]->type
);
774 case ir_triop_bitfield_extract
:
775 assert(ir
->type
->is_integer());
776 assert(ir
->operands
[0]->type
== ir
->type
);
777 assert(ir
->operands
[1]->type
== ir
->type
);
778 assert(ir
->operands
[2]->type
== ir
->type
);
781 case ir_triop_vector_insert
:
782 assert(ir
->operands
[0]->type
->is_vector());
783 assert(ir
->operands
[1]->type
->is_scalar());
784 assert(ir
->operands
[0]->type
->base_type
== ir
->operands
[1]->type
->base_type
);
785 assert(ir
->operands
[2]->type
->is_scalar()
786 && ir
->operands
[2]->type
->is_integer());
787 assert(ir
->type
== ir
->operands
[0]->type
);
790 case ir_quadop_bitfield_insert
:
791 assert(ir
->type
->is_integer());
792 assert(ir
->operands
[0]->type
== ir
->type
);
793 assert(ir
->operands
[1]->type
== ir
->type
);
794 assert(ir
->operands
[2]->type
== ir
->type
);
795 assert(ir
->operands
[3]->type
== ir
->type
);
798 case ir_quadop_vector
:
799 /* The vector operator collects some number of scalars and generates a
802 * - All of the operands must be scalar.
803 * - Number of operands must matche the size of the resulting vector.
804 * - Base type of the operands must match the base type of the result.
806 assert(ir
->type
->is_vector());
807 switch (ir
->type
->vector_elements
) {
809 assert(ir
->operands
[0]->type
->is_scalar());
810 assert(ir
->operands
[0]->type
->base_type
== ir
->type
->base_type
);
811 assert(ir
->operands
[1]->type
->is_scalar());
812 assert(ir
->operands
[1]->type
->base_type
== ir
->type
->base_type
);
813 assert(ir
->operands
[2] == NULL
);
814 assert(ir
->operands
[3] == NULL
);
817 assert(ir
->operands
[0]->type
->is_scalar());
818 assert(ir
->operands
[0]->type
->base_type
== ir
->type
->base_type
);
819 assert(ir
->operands
[1]->type
->is_scalar());
820 assert(ir
->operands
[1]->type
->base_type
== ir
->type
->base_type
);
821 assert(ir
->operands
[2]->type
->is_scalar());
822 assert(ir
->operands
[2]->type
->base_type
== ir
->type
->base_type
);
823 assert(ir
->operands
[3] == NULL
);
826 assert(ir
->operands
[0]->type
->is_scalar());
827 assert(ir
->operands
[0]->type
->base_type
== ir
->type
->base_type
);
828 assert(ir
->operands
[1]->type
->is_scalar());
829 assert(ir
->operands
[1]->type
->base_type
== ir
->type
->base_type
);
830 assert(ir
->operands
[2]->type
->is_scalar());
831 assert(ir
->operands
[2]->type
->base_type
== ir
->type
->base_type
);
832 assert(ir
->operands
[3]->type
->is_scalar());
833 assert(ir
->operands
[3]->type
->base_type
== ir
->type
->base_type
);
836 /* The is_vector assertion above should prevent execution from ever
839 assert(!"Should not get here.");
844 return visit_continue
;
848 ir_validate::visit_leave(ir_swizzle
*ir
)
850 unsigned int chans
[4] = {ir
->mask
.x
, ir
->mask
.y
, ir
->mask
.z
, ir
->mask
.w
};
852 for (unsigned int i
= 0; i
< ir
->type
->vector_elements
; i
++) {
853 if (chans
[i
] >= ir
->val
->type
->vector_elements
) {
854 printf("ir_swizzle @ %p specifies a channel not present "
855 "in the value.\n", (void *) ir
);
861 return visit_continue
;
865 ir_validate::visit(ir_variable
*ir
)
867 /* An ir_variable is the one thing that can (and will) appear multiple times
868 * in an IR tree. It is added to the hashtable so that it can be used
869 * in the ir_dereference_variable handler to ensure that a variable is
870 * declared before it is dereferenced.
872 if (ir
->name
&& ir
->is_name_ralloced())
873 assert(ralloc_parent(ir
->name
) == ir
);
875 _mesa_set_add(ir_set
, ir
);
877 /* If a variable is an array, verify that the maximum array index is in
878 * bounds. There was once an error in AST-to-HIR conversion that set this
879 * to be out of bounds.
881 if (ir
->type
->array_size() > 0) {
882 if (ir
->data
.max_array_access
>= (int)ir
->type
->length
) {
883 printf("ir_variable has maximum access out of bounds (%d vs %d)\n",
884 ir
->data
.max_array_access
, ir
->type
->length
- 1);
890 /* If a variable is an interface block (or an array of interface blocks),
891 * verify that the maximum array index for each interface member is in
894 if (ir
->is_interface_instance()) {
895 const glsl_struct_field
*fields
=
896 ir
->get_interface_type()->fields
.structure
;
897 for (unsigned i
= 0; i
< ir
->get_interface_type()->length
; i
++) {
898 if (fields
[i
].type
->array_size() > 0 &&
899 !fields
[i
].implicit_sized_array
) {
900 const int *const max_ifc_array_access
=
901 ir
->get_max_ifc_array_access();
903 assert(max_ifc_array_access
!= NULL
);
905 if (max_ifc_array_access
[i
] >= (int)fields
[i
].type
->length
) {
906 printf("ir_variable has maximum access out of bounds for "
907 "field %s (%d vs %d)\n", fields
[i
].name
,
908 max_ifc_array_access
[i
], fields
[i
].type
->length
);
916 if (ir
->constant_initializer
!= NULL
&& !ir
->data
.has_initializer
) {
917 printf("ir_variable didn't have an initializer, but has a constant "
918 "initializer value.\n");
923 if (ir
->data
.mode
== ir_var_uniform
924 && is_gl_identifier(ir
->name
)
925 && ir
->get_state_slots() == NULL
) {
926 printf("built-in uniform has no state\n");
931 return visit_continue
;
935 ir_validate::visit_enter(ir_assignment
*ir
)
937 const ir_dereference
*const lhs
= ir
->lhs
;
938 if (lhs
->type
->is_scalar() || lhs
->type
->is_vector()) {
939 if (ir
->write_mask
== 0) {
940 printf("Assignment LHS is %s, but write mask is 0:\n",
941 lhs
->type
->is_scalar() ? "scalar" : "vector");
946 int lhs_components
= 0;
947 for (int i
= 0; i
< 4; i
++) {
948 if (ir
->write_mask
& (1 << i
))
952 if (lhs_components
!= ir
->rhs
->type
->vector_elements
) {
953 printf("Assignment count of LHS write mask channels enabled not\n"
954 "matching RHS vector size (%d LHS, %d RHS).\n",
955 lhs_components
, ir
->rhs
->type
->vector_elements
);
961 this->validate_ir(ir
, this->data_enter
);
963 return visit_continue
;
967 ir_validate::visit_enter(ir_call
*ir
)
969 ir_function_signature
*const callee
= ir
->callee
;
971 if (callee
->ir_type
!= ir_type_function_signature
) {
972 printf("IR called by ir_call is not ir_function_signature!\n");
976 if (ir
->return_deref
) {
977 if (ir
->return_deref
->type
!= callee
->return_type
) {
978 printf("callee type %s does not match return storage type %s\n",
979 callee
->return_type
->name
, ir
->return_deref
->type
->name
);
982 } else if (callee
->return_type
!= glsl_type::void_type
) {
983 printf("ir_call has non-void callee but no return storage\n");
987 const exec_node
*formal_param_node
= callee
->parameters
.get_head_raw();
988 const exec_node
*actual_param_node
= ir
->actual_parameters
.get_head_raw();
990 if (formal_param_node
->is_tail_sentinel()
991 != actual_param_node
->is_tail_sentinel()) {
992 printf("ir_call has the wrong number of parameters:\n");
995 if (formal_param_node
->is_tail_sentinel()) {
998 const ir_variable
*formal_param
999 = (const ir_variable
*) formal_param_node
;
1000 const ir_rvalue
*actual_param
1001 = (const ir_rvalue
*) actual_param_node
;
1002 if (formal_param
->type
!= actual_param
->type
) {
1003 printf("ir_call parameter type mismatch:\n");
1006 if (formal_param
->data
.mode
== ir_var_function_out
1007 || formal_param
->data
.mode
== ir_var_function_inout
) {
1008 if (!actual_param
->is_lvalue()) {
1009 printf("ir_call out/inout parameters must be lvalues:\n");
1013 formal_param_node
= formal_param_node
->next
;
1014 actual_param_node
= actual_param_node
->next
;
1017 return visit_continue
;
1021 printf("callee:\n");
1028 ir_validate::validate_ir(ir_instruction
*ir
, void *data
)
1030 struct set
*ir_set
= (struct set
*) data
;
1032 if (_mesa_set_search(ir_set
, ir
)) {
1033 printf("Instruction node present twice in ir tree:\n");
1038 _mesa_set_add(ir_set
, ir
);
1042 check_node_type(ir_instruction
*ir
, void *data
)
1046 if (ir
->ir_type
>= ir_type_max
) {
1047 printf("Instruction node with unset type\n");
1048 ir
->print(); printf("\n");
1050 ir_rvalue
*value
= ir
->as_rvalue();
1052 assert(value
->type
!= glsl_type::error_type
);
1056 validate_ir_tree(exec_list
*instructions
)
1058 /* We shouldn't have any reason to validate IR in a release build,
1059 * and it's half composed of assert()s anyway which wouldn't do
1065 v
.run(instructions
);
1067 foreach_in_list(ir_instruction
, ir
, instructions
) {
1068 visit_tree(ir
, check_node_type
, NULL
);