1 /*
2 * Copyright © 2010 Intel Corporation
3 *
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:
10 *
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
13 * Software.
14 *
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.
22 */
23
24 /**
25 * \file ir_validate.cpp
26 *
27 * Attempts to verify that various invariants of the IR tree are true.
28 *
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.
34 */
35
36 #include "ir.h"
37 #include "ir_hierarchical_visitor.h"
38 #include "linker_util.h"
39 #include "util/u_debug.h"
40 #include "util/hash_table.h"
41 #include "util/macros.h"
42 #include "util/set.h"
43 #include "compiler/glsl_types.h"
44
45 namespace {
46
47 class ir_validate : public ir_hierarchical_visitor {
48 public:
ir_validate()49 ir_validate()
50 {
51 this->ir_set = _mesa_pointer_set_create(NULL);
52
53 this->current_function = NULL;
54
55 this->callback_enter = ir_validate::validate_ir;
56 this->data_enter = ir_set;
57 }
58
59 ir_validate(const ir_validate &) = delete;
60 ir_validate & operator=(const ir_validate &) = delete;
61
~ir_validate()62 ~ir_validate()
63 {
64 _mesa_set_destroy(this->ir_set, NULL);
65 }
66
67 virtual ir_visitor_status visit(ir_variable *v);
68 virtual ir_visitor_status visit(ir_dereference_variable *ir);
69
70 virtual ir_visitor_status visit_enter(ir_discard *ir);
71 virtual ir_visitor_status visit_enter(ir_if *ir);
72
73 virtual ir_visitor_status visit_enter(ir_function *ir);
74 virtual ir_visitor_status visit_leave(ir_function *ir);
75 virtual ir_visitor_status visit_enter(ir_function_signature *ir);
76 virtual ir_visitor_status visit_enter(ir_return *ir);
77
78 virtual ir_visitor_status visit_leave(ir_expression *ir);
79 virtual ir_visitor_status visit_leave(ir_swizzle *ir);
80
81 virtual ir_visitor_status visit_enter(class ir_dereference_array *);
82 virtual ir_visitor_status visit_enter(class ir_dereference_record *);
83
84 virtual ir_visitor_status visit_enter(ir_assignment *ir);
85 virtual ir_visitor_status visit_enter(ir_call *ir);
86
87 static void validate_ir(ir_instruction *ir, void *data);
88
89 ir_function *current_function;
90
91 struct set *ir_set;
92 };
93
94 } /* anonymous namespace */
95
96 ir_visitor_status
visit(ir_dereference_variable * ir)97 ir_validate::visit(ir_dereference_variable *ir)
98 {
99 if ((ir->var == NULL) || (ir->var->as_variable() == NULL)) {
100 printf("ir_dereference_variable @ %p does not specify a variable %p\n",
101 (void *) ir, (void *) ir->var);
102 abort();
103 }
104
105 /* Compare types without arrays, because one side can be sized and
106 * the other unsized.
107 */
108 if (glsl_without_array(ir->var->type) != glsl_without_array(ir->type)) {
109 printf("ir_dereference_variable type is not equal to variable type: ");
110 ir->print();
111 printf("\n");
112 abort();
113 }
114
115 if (_mesa_set_search(ir_set, ir->var) == NULL) {
116 printf("ir_dereference_variable @ %p specifies undeclared variable "
117 "`%s' @ %p\n",
118 (void *) ir, ir->var->name, (void *) ir->var);
119 abort();
120 }
121
122 this->validate_ir(ir, this->data_enter);
123
124 return visit_continue;
125 }
126
127 ir_visitor_status
visit_enter(class ir_dereference_array * ir)128 ir_validate::visit_enter(class ir_dereference_array *ir)
129 {
130 if (!glsl_type_is_array(ir->array->type) && !glsl_type_is_matrix(ir->array->type) &&
131 !glsl_type_is_vector(ir->array->type)) {
132 printf("ir_dereference_array @ %p does not specify an array, a vector "
133 "or a matrix\n",
134 (void *) ir);
135 ir->print();
136 printf("\n");
137 abort();
138 }
139
140 if (glsl_type_is_array(ir->array->type)) {
141 if (ir->array->type->fields.array != ir->type) {
142 printf("ir_dereference_array type is not equal to the array "
143 "element type: ");
144 ir->print();
145 printf("\n");
146 abort();
147 }
148 } else if (ir->array->type->base_type != ir->type->base_type) {
149 printf("ir_dereference_array base types are not equal: ");
150 ir->print();
151 printf("\n");
152 abort();
153 }
154
155 if (!glsl_type_is_scalar(ir->array_index->type)) {
156 printf("ir_dereference_array @ %p does not have scalar index: %s\n",
157 (void *) ir, glsl_get_type_name(ir->array_index->type));
158 abort();
159 }
160
161 if (!glsl_type_is_integer_16_32(ir->array_index->type)) {
162 printf("ir_dereference_array @ %p does not have integer index: %s\n",
163 (void *) ir, glsl_get_type_name(ir->array_index->type));
164 abort();
165 }
166
167 return visit_continue;
168 }
169
170 ir_visitor_status
visit_enter(class ir_dereference_record * ir)171 ir_validate::visit_enter(class ir_dereference_record *ir)
172 {
173 if (!glsl_type_is_struct(ir->record->type) && !glsl_type_is_interface(ir->record->type)) {
174 printf("ir_dereference_record @ %p does not specify a record\n",
175 (void *) ir);
176 ir->print();
177 printf("\n");
178 abort();
179 }
180
181 if (ir->record->type->fields.structure[ir->field_idx].type != ir->type) {
182 printf("ir_dereference_record type is not equal to the record "
183 "field type: ");
184 ir->print();
185 printf("\n");
186 abort();
187 }
188
189 return visit_continue;
190 }
191
192 ir_visitor_status
visit_enter(ir_discard * ir)193 ir_validate::visit_enter(ir_discard *ir)
194 {
195 if (ir->condition && ir->condition->type != &glsl_type_builtin_bool) {
196 printf("ir_discard condition %s type instead of bool.\n",
197 glsl_get_type_name(ir->condition->type));
198 ir->print();
199 printf("\n");
200 abort();
201 }
202
203 return visit_continue;
204 }
205
206 ir_visitor_status
visit_enter(ir_if * ir)207 ir_validate::visit_enter(ir_if *ir)
208 {
209 if (ir->condition->type != &glsl_type_builtin_bool) {
210 printf("ir_if condition %s type instead of bool.\n",
211 glsl_get_type_name(ir->condition->type));
212 ir->print();
213 printf("\n");
214 abort();
215 }
216
217 return visit_continue;
218 }
219
220
221 ir_visitor_status
visit_enter(ir_function * ir)222 ir_validate::visit_enter(ir_function *ir)
223 {
224 /* Function definitions cannot be nested.
225 */
226 if (this->current_function != NULL) {
227 printf("Function definition nested inside another function "
228 "definition:\n");
229 printf("%s %p inside %s %p\n",
230 ir->name, (void *) ir,
231 this->current_function->name, (void *) this->current_function);
232 abort();
233 }
234
235 /* Store the current function hierarchy being traversed. This is used
236 * by the function signature visitor to ensure that the signatures are
237 * linked with the correct functions.
238 */
239 this->current_function = ir;
240
241 this->validate_ir(ir, this->data_enter);
242
243 /* Verify that all of the things stored in the list of signatures are,
244 * in fact, function signatures.
245 */
246 foreach_in_list(ir_instruction, sig, &ir->signatures) {
247 if (sig->ir_type != ir_type_function_signature) {
248 printf("Non-signature in signature list of function `%s'\n",
249 ir->name);
250 abort();
251 }
252 }
253
254 return visit_continue;
255 }
256
257 ir_visitor_status
visit_leave(ir_function * ir)258 ir_validate::visit_leave(ir_function *ir)
259 {
260 assert(ralloc_parent(ir->name) == ir);
261
262 this->current_function = NULL;
263 return visit_continue;
264 }
265
266 ir_visitor_status
visit_enter(ir_function_signature * ir)267 ir_validate::visit_enter(ir_function_signature *ir)
268 {
269 if (this->current_function != ir->function()) {
270 printf("Function signature nested inside wrong function "
271 "definition:\n");
272 printf("%p inside %s %p instead of %s %p\n",
273 (void *) ir,
274 this->current_function->name, (void *) this->current_function,
275 ir->function_name(), (void *) ir->function());
276 abort();
277 }
278
279 if (ir->return_type == NULL) {
280 printf("Function signature %p for function %s has NULL return type.\n",
281 (void *) ir, ir->function_name());
282 abort();
283 }
284
285 this->validate_ir(ir, this->data_enter);
286
287 return visit_continue;
288 }
289
290 ir_visitor_status
visit_enter(ir_return * ir)291 ir_validate::visit_enter(ir_return *ir)
292 {
293 if (!this->current_function) {
294 printf("Return statement outside of a function\n");
295 abort();
296 }
297
298 return visit_continue;
299 }
300
301 ir_visitor_status
visit_leave(ir_expression * ir)302 ir_validate::visit_leave(ir_expression *ir)
303 {
304 for (unsigned i = ir->num_operands; i < 4; i++) {
305 assert(ir->operands[i] == NULL);
306 }
307
308 for (unsigned i = 0; i < ir->num_operands; i++) {
309 assert(ir->operands[i] != NULL);
310 }
311
312 switch (ir->operation) {
313 case ir_unop_bit_not:
314 assert(ir->operands[0]->type == ir->type);
315 break;
316 case ir_unop_logic_not:
317 assert(glsl_type_is_boolean(ir->type));
318 assert(glsl_type_is_boolean(ir->operands[0]->type));
319 break;
320
321 case ir_unop_neg:
322 assert(ir->type == ir->operands[0]->type);
323 break;
324
325 case ir_unop_abs:
326 case ir_unop_sign:
327 assert(glsl_type_is_int_16_32_64(ir->operands[0]->type) ||
328 glsl_type_is_float_16_32_64(ir->operands[0]->type));
329 assert(ir->type == ir->operands[0]->type);
330 break;
331
332 case ir_unop_rcp:
333 case ir_unop_rsq:
334 case ir_unop_sqrt:
335 assert(glsl_type_is_float_16_32_64(ir->type));
336 assert(ir->type == ir->operands[0]->type);
337 break;
338
339 case ir_unop_exp:
340 case ir_unop_log:
341 case ir_unop_exp2:
342 case ir_unop_log2:
343 case ir_unop_saturate:
344 assert(glsl_type_is_float_16_32(ir->operands[0]->type));
345 assert(ir->type == ir->operands[0]->type);
346 break;
347
348 case ir_unop_f2i:
349 assert(glsl_type_is_float_16_32(ir->operands[0]->type));
350 assert(glsl_type_is_int_16_32(ir->type));
351 break;
352 case ir_unop_f2u:
353 assert(glsl_type_is_float_16_32(ir->operands[0]->type));
354 assert(glsl_type_is_uint_16_32(ir->type));
355 break;
356 case ir_unop_i2f:
357 assert(glsl_type_is_int_16_32(ir->operands[0]->type));
358 assert(glsl_type_is_float_16_32(ir->type));
359 break;
360 case ir_unop_f2b:
361 assert(glsl_type_is_float_16_32(ir->operands[0]->type));
362 assert(glsl_type_is_boolean(ir->type));
363 break;
364 case ir_unop_f162b:
365 assert(ir->operands[0]->type->base_type ==
366 GLSL_TYPE_FLOAT16);
367 assert(glsl_type_is_boolean(ir->type));
368 break;
369 case ir_unop_b2f:
370 assert(glsl_type_is_boolean(ir->operands[0]->type));
371 assert(glsl_type_is_float_16_32(ir->type));
372 break;
373 case ir_unop_b2f16:
374 assert(glsl_type_is_boolean(ir->operands[0]->type));
375 assert(ir->type->base_type == GLSL_TYPE_FLOAT16);
376 break;
377 case ir_unop_i2b:
378 assert(glsl_type_is_int_16_32(ir->operands[0]->type));
379 assert(glsl_type_is_boolean(ir->type));
380 break;
381 case ir_unop_b2i:
382 assert(glsl_type_is_boolean(ir->operands[0]->type));
383 assert(glsl_type_is_int_16_32(ir->type));
384 break;
385 case ir_unop_u2f:
386 assert(glsl_type_is_uint_16_32(ir->operands[0]->type));
387 assert(glsl_type_is_float_16_32(ir->type));
388 break;
389 case ir_unop_i2u:
390 assert(glsl_type_is_int_16_32(ir->operands[0]->type));
391 assert(glsl_type_is_uint_16_32(ir->type));
392 break;
393 case ir_unop_u2i:
394 assert(glsl_type_is_uint_16_32(ir->operands[0]->type));
395 assert(glsl_type_is_int_16_32(ir->type));
396 break;
397 case ir_unop_bitcast_i2f:
398 assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT);
399 assert(ir->type->base_type == GLSL_TYPE_FLOAT);
400 break;
401 case ir_unop_bitcast_f2i:
402 assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT);
403 assert(ir->type->base_type == GLSL_TYPE_INT);
404 break;
405 case ir_unop_bitcast_u2f:
406 assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT);
407 assert(ir->type->base_type == GLSL_TYPE_FLOAT);
408 break;
409 case ir_unop_bitcast_f2u:
410 assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT);
411 assert(ir->type->base_type == GLSL_TYPE_UINT);
412 break;
413
414 case ir_unop_bitcast_u642d:
415 assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT64);
416 assert(glsl_type_is_double(ir->type));
417 break;
418 case ir_unop_bitcast_i642d:
419 assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT64);
420 assert(glsl_type_is_double(ir->type));
421 break;
422 case ir_unop_bitcast_d2u64:
423 assert(glsl_type_is_double(ir->operands[0]->type));
424 assert(ir->type->base_type == GLSL_TYPE_UINT64);
425 break;
426 case ir_unop_bitcast_d2i64:
427 assert(glsl_type_is_double(ir->operands[0]->type));
428 assert(ir->type->base_type == GLSL_TYPE_INT64);
429 break;
430 case ir_unop_i642i:
431 assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT64);
432 assert(glsl_type_is_int_16_32(ir->type));
433 break;
434 case ir_unop_u642i:
435 assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT64);
436 assert(glsl_type_is_int_16_32(ir->type));
437 break;
438 case ir_unop_i642u:
439 assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT64);
440 assert(glsl_type_is_uint_16_32(ir->type));
441 break;
442 case ir_unop_u642u:
443 assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT64);
444 assert(glsl_type_is_uint_16_32(ir->type));
445 break;
446 case ir_unop_i642b:
447 assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT64);
448 assert(glsl_type_is_boolean(ir->type));
449 break;
450 case ir_unop_i642f:
451 assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT64);
452 assert(glsl_type_is_float(ir->type));
453 break;
454 case ir_unop_u642f:
455 assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT64);
456 assert(glsl_type_is_float(ir->type));
457 break;
458 case ir_unop_i642d:
459 assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT64);
460 assert(glsl_type_is_double(ir->type));
461 break;
462 case ir_unop_u642d:
463 assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT64);
464 assert(glsl_type_is_double(ir->type));
465 break;
466 case ir_unop_i2i64:
467 assert(glsl_type_is_int_16_32(ir->operands[0]->type));
468 assert(ir->type->base_type == GLSL_TYPE_INT64);
469 break;
470 case ir_unop_u2i64:
471 assert(glsl_type_is_uint_16_32(ir->operands[0]->type));
472 assert(ir->type->base_type == GLSL_TYPE_INT64);
473 break;
474 case ir_unop_b2i64:
475 assert(glsl_type_is_boolean(ir->operands[0]->type));
476 assert(ir->type->base_type == GLSL_TYPE_INT64);
477 break;
478 case ir_unop_f2i64:
479 assert(glsl_type_is_float(ir->operands[0]->type));
480 assert(ir->type->base_type == GLSL_TYPE_INT64);
481 break;
482 case ir_unop_d2i64:
483 assert(glsl_type_is_double(ir->operands[0]->type));
484 assert(ir->type->base_type == GLSL_TYPE_INT64);
485 break;
486 case ir_unop_i2u64:
487 assert(glsl_type_is_int_16_32(ir->operands[0]->type));
488 assert(ir->type->base_type == GLSL_TYPE_UINT64);
489 break;
490 case ir_unop_u2u64:
491 assert(glsl_type_is_uint_16_32(ir->operands[0]->type));
492 assert(ir->type->base_type == GLSL_TYPE_UINT64);
493 break;
494 case ir_unop_f2u64:
495 assert(glsl_type_is_float(ir->operands[0]->type));
496 assert(ir->type->base_type == GLSL_TYPE_UINT64);
497 break;
498 case ir_unop_d2u64:
499 assert(glsl_type_is_double(ir->operands[0]->type));
500 assert(ir->type->base_type == GLSL_TYPE_UINT64);
501 break;
502 case ir_unop_u642i64:
503 assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT64);
504 assert(ir->type->base_type == GLSL_TYPE_INT64);
505 break;
506 case ir_unop_i642u64:
507 assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT64);
508 assert(ir->type->base_type == GLSL_TYPE_UINT64);
509 break;
510 case ir_unop_trunc:
511 case ir_unop_round_even:
512 case ir_unop_ceil:
513 case ir_unop_floor:
514 case ir_unop_fract:
515 assert(glsl_type_is_float_16_32_64(ir->operands[0]->type));
516 assert(ir->operands[0]->type == ir->type);
517 break;
518 case ir_unop_sin:
519 case ir_unop_cos:
520 case ir_unop_dFdx:
521 case ir_unop_dFdx_coarse:
522 case ir_unop_dFdx_fine:
523 case ir_unop_dFdy:
524 case ir_unop_dFdy_coarse:
525 case ir_unop_dFdy_fine:
526 assert(glsl_type_is_float_16_32(ir->operands[0]->type));
527 assert(ir->operands[0]->type == ir->type);
528 break;
529
530 case ir_unop_pack_snorm_2x16:
531 case ir_unop_pack_unorm_2x16:
532 case ir_unop_pack_half_2x16:
533 assert(ir->type == &glsl_type_builtin_uint);
534 assert(ir->operands[0]->type == &glsl_type_builtin_vec2);
535 break;
536
537 case ir_unop_pack_snorm_4x8:
538 case ir_unop_pack_unorm_4x8:
539 assert(ir->type == &glsl_type_builtin_uint);
540 assert(ir->operands[0]->type == &glsl_type_builtin_vec4);
541 break;
542
543 case ir_unop_pack_double_2x32:
544 assert(ir->type == &glsl_type_builtin_double);
545 assert(ir->operands[0]->type == &glsl_type_builtin_uvec2);
546 break;
547
548 case ir_unop_pack_int_2x32:
549 assert(ir->type == &glsl_type_builtin_int64_t);
550 assert(ir->operands[0]->type == &glsl_type_builtin_ivec2);
551 break;
552
553 case ir_unop_pack_uint_2x32:
554 assert(ir->type == &glsl_type_builtin_uint64_t);
555 assert(ir->operands[0]->type == &glsl_type_builtin_uvec2);
556 break;
557
558 case ir_unop_pack_sampler_2x32:
559 assert(glsl_type_is_sampler(ir->type));
560 assert(ir->operands[0]->type == &glsl_type_builtin_uvec2);
561 break;
562
563 case ir_unop_pack_image_2x32:
564 assert(glsl_type_is_image(ir->type));
565 assert(ir->operands[0]->type == &glsl_type_builtin_uvec2);
566 break;
567
568 case ir_unop_unpack_snorm_2x16:
569 case ir_unop_unpack_unorm_2x16:
570 case ir_unop_unpack_half_2x16:
571 assert(ir->type == &glsl_type_builtin_vec2);
572 assert(ir->operands[0]->type == &glsl_type_builtin_uint);
573 break;
574
575 case ir_unop_unpack_snorm_4x8:
576 case ir_unop_unpack_unorm_4x8:
577 assert(ir->type == &glsl_type_builtin_vec4);
578 assert(ir->operands[0]->type == &glsl_type_builtin_uint);
579 break;
580
581 case ir_unop_unpack_double_2x32:
582 assert(ir->type == &glsl_type_builtin_uvec2);
583 assert(ir->operands[0]->type == &glsl_type_builtin_double);
584 break;
585
586 case ir_unop_unpack_int_2x32:
587 assert(ir->type == &glsl_type_builtin_ivec2);
588 assert(ir->operands[0]->type == &glsl_type_builtin_int64_t);
589 break;
590
591 case ir_unop_unpack_uint_2x32:
592 assert(ir->type == &glsl_type_builtin_uvec2);
593 assert(ir->operands[0]->type == &glsl_type_builtin_uint64_t);
594 break;
595
596 case ir_unop_unpack_sampler_2x32:
597 assert(ir->type == &glsl_type_builtin_uvec2);
598 assert(glsl_type_is_sampler(ir->operands[0]->type));
599 break;
600
601 case ir_unop_unpack_image_2x32:
602 assert(ir->type == &glsl_type_builtin_uvec2);
603 assert(glsl_type_is_image(ir->operands[0]->type));
604 break;
605
606 case ir_unop_bitfield_reverse:
607 assert(ir->operands[0]->type == ir->type);
608 assert(glsl_type_is_integer_32(ir->type));
609 break;
610
611 case ir_unop_bit_count:
612 case ir_unop_find_msb:
613 case ir_unop_find_lsb:
614 assert(ir->operands[0]->type->vector_elements == ir->type->vector_elements);
615 assert(glsl_type_is_integer_16_32(ir->operands[0]->type));
616 assert(glsl_type_is_int_16_32(ir->type));
617 break;
618
619 case ir_unop_clz:
620 assert(ir->operands[0]->type == ir->type);
621 assert(glsl_type_is_uint_16_32(ir->type));
622 break;
623
624 case ir_unop_interpolate_at_centroid:
625 assert(ir->operands[0]->type == ir->type);
626 assert(glsl_type_is_float_16_32(ir->operands[0]->type));
627 break;
628
629 case ir_unop_get_buffer_size:
630 assert(ir->type == &glsl_type_builtin_int);
631 assert(ir->operands[0]->type == &glsl_type_builtin_uint);
632 break;
633
634 case ir_unop_ssbo_unsized_array_length:
635 assert(ir->type == &glsl_type_builtin_int);
636 assert(glsl_type_is_array(ir->operands[0]->type));
637 assert(glsl_type_is_unsized_array(ir->operands[0]->type));
638 break;
639
640 case ir_unop_implicitly_sized_array_length:
641 assert(ir->type == &glsl_type_builtin_int);
642 assert(glsl_type_is_array(ir->operands[0]->type));
643 break;
644
645 case ir_unop_d2f:
646 assert(glsl_type_is_double(ir->operands[0]->type));
647 assert(glsl_type_is_float(ir->type));
648 break;
649 case ir_unop_f2d:
650 assert(glsl_type_is_float(ir->operands[0]->type));
651 assert(glsl_type_is_double(ir->type));
652 break;
653 case ir_unop_f162f:
654 assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT16);
655 assert(glsl_type_is_float(ir->type));
656 break;
657 case ir_unop_f2f16:
658 case ir_unop_f2fmp:
659 assert(glsl_type_is_float(ir->operands[0]->type));
660 assert(ir->type->base_type == GLSL_TYPE_FLOAT16);
661 break;
662 case ir_unop_i2i:
663 assert(glsl_type_is_int_16_32(ir->operands[0]->type));
664 assert(glsl_type_is_int_16_32(ir->type));
665 assert(ir->type->base_type != ir->operands[0]->type->base_type);
666 break;
667 case ir_unop_u2u:
668 assert(glsl_type_is_uint_16_32(ir->operands[0]->type));
669 assert(glsl_type_is_uint_16_32(ir->type));
670 assert(ir->type->base_type != ir->operands[0]->type->base_type);
671 break;
672 case ir_unop_i2imp:
673 assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT);
674 assert(ir->type->base_type == GLSL_TYPE_INT16);
675 break;
676 case ir_unop_u2ump:
677 assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT);
678 assert(ir->type->base_type == GLSL_TYPE_UINT16);
679 break;
680 case ir_unop_d2i:
681 assert(glsl_type_is_double(ir->operands[0]->type));
682 assert(glsl_type_is_int_16_32(ir->type));
683 break;
684 case ir_unop_i2d:
685 assert(glsl_type_is_int_16_32(ir->operands[0]->type));
686 assert(glsl_type_is_double(ir->type));
687 break;
688 case ir_unop_d2u:
689 assert(glsl_type_is_double(ir->operands[0]->type));
690 assert(glsl_type_is_uint_16_32(ir->type));
691 break;
692 case ir_unop_u2d:
693 assert(glsl_type_is_uint_16_32(ir->operands[0]->type));
694 assert(glsl_type_is_double(ir->type));
695 break;
696 case ir_unop_d2b:
697 assert(glsl_type_is_double(ir->operands[0]->type));
698 assert(glsl_type_is_boolean(ir->type));
699 break;
700 case ir_unop_u2f16:
701 assert(ir->type->base_type == GLSL_TYPE_FLOAT16);
702 assert(glsl_type_is_uint_16_32(ir->operands[0]->type));
703 break;
704 case ir_unop_f162u:
705 assert(glsl_type_is_uint_16_32(ir->type));
706 assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT16);
707 break;
708 case ir_unop_i2f16:
709 assert(ir->type->base_type == GLSL_TYPE_FLOAT16);
710 assert(glsl_type_is_int_16_32(ir->operands[0]->type));
711 break;
712 case ir_unop_f162i:
713 assert(glsl_type_is_int_16_32(ir->type));
714 assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT16);
715 break;
716 case ir_unop_d2f16:
717 assert(ir->type->base_type == GLSL_TYPE_FLOAT16);
718 assert(glsl_type_is_double(ir->operands[0]->type));
719 break;
720 case ir_unop_f162d:
721 assert(glsl_type_is_double(ir->type));
722 assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT16);
723 break;
724 case ir_unop_u642f16:
725 assert(ir->type->base_type == GLSL_TYPE_FLOAT16);
726 assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT64);
727 break;
728 case ir_unop_f162u64:
729 assert(ir->type->base_type == GLSL_TYPE_UINT64);
730 assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT16);
731 break;
732 case ir_unop_i642f16:
733 assert(ir->type->base_type == GLSL_TYPE_FLOAT16);
734 assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT64);
735 break;
736 case ir_unop_f162i64:
737 assert(ir->type->base_type == GLSL_TYPE_INT64);
738 assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT16);
739 break;
740
741 case ir_unop_frexp_sig:
742 assert(glsl_type_is_float_16_32_64(ir->operands[0]->type));
743 break;
744 case ir_unop_frexp_exp:
745 assert(glsl_type_is_float_16_32_64(ir->operands[0]->type));
746 assert(ir->type->base_type == GLSL_TYPE_INT);
747 break;
748 case ir_unop_subroutine_to_int:
749 assert(ir->operands[0]->type->base_type == GLSL_TYPE_SUBROUTINE);
750 assert(ir->type->base_type == GLSL_TYPE_INT);
751 break;
752
753 case ir_unop_atan:
754 assert(glsl_type_is_float_16_32_64(ir->operands[0]->type));
755 assert(ir->type == ir->operands[0]->type);
756 break;
757
758 case ir_binop_add:
759 case ir_binop_sub:
760 case ir_binop_mul:
761 case ir_binop_div:
762 case ir_binop_mod:
763 case ir_binop_min:
764 case ir_binop_max:
765 case ir_binop_pow:
766 assert(ir->operands[0]->type->base_type ==
767 ir->operands[1]->type->base_type);
768
769 if (ir->operation == ir_binop_mul &&
770 (ir->type->base_type == GLSL_TYPE_UINT64 ||
771 ir->type->base_type == GLSL_TYPE_INT64) &&
772 (glsl_type_is_int_16_32(ir->operands[0]->type)||
773 glsl_type_is_int_16_32(ir->operands[1]->type)||
774 glsl_type_is_uint_16_32(ir->operands[0]->type) ||
775 glsl_type_is_uint_16_32(ir->operands[1]->type))) {
776 assert(ir->operands[0]->type == ir->operands[1]->type);
777 break;
778 }
779
780 if (glsl_type_is_scalar(ir->operands[0]->type))
781 assert(ir->operands[1]->type == ir->type);
782 else if (glsl_type_is_scalar(ir->operands[1]->type))
783 assert(ir->operands[0]->type == ir->type);
784 else if (glsl_type_is_vector(ir->operands[0]->type) &&
785 glsl_type_is_vector(ir->operands[1]->type)) {
786 assert(ir->operands[0]->type == ir->operands[1]->type);
787 assert(ir->operands[0]->type == ir->type);
788 }
789 break;
790
791 case ir_binop_abs_sub:
792 assert(ir->operands[0]->type == ir->operands[1]->type);
793 assert(glsl_type_is_integer_16_32_64(ir->operands[0]->type));
794 assert(ir->operands[0]->type->vector_elements ==
795 ir->type->vector_elements);
796 assert(glsl_type_is_uint_16_32_64(ir->type));
797 break;
798
799 case ir_binop_add_sat:
800 case ir_binop_sub_sat:
801 case ir_binop_avg:
802 case ir_binop_avg_round:
803 assert(ir->type == ir->operands[0]->type);
804 assert(ir->type == ir->operands[1]->type);
805 assert(glsl_type_is_integer_16_32_64(ir->type));
806 break;
807
808 case ir_binop_mul_32x16:
809 case ir_binop_imul_high:
810 assert(ir->type == ir->operands[0]->type);
811 assert(ir->type == ir->operands[1]->type);
812 assert(glsl_type_is_integer_32(ir->type));
813 break;
814
815 case ir_binop_carry:
816 case ir_binop_borrow:
817 assert(ir->type == ir->operands[0]->type);
818 assert(ir->type == ir->operands[1]->type);
819 assert(ir->type->base_type == GLSL_TYPE_UINT);
820 break;
821
822 case ir_binop_less:
823 case ir_binop_gequal:
824 case ir_binop_equal:
825 case ir_binop_nequal:
826 /* The semantics of the IR operators differ from the GLSL <, >, <=, >=,
827 * ==, and != operators. The IR operators perform a component-wise
828 * comparison on scalar or vector types and return a boolean scalar or
829 * vector type of the same size.
830 */
831 assert(glsl_type_is_boolean(ir->type));
832 assert(ir->operands[0]->type == ir->operands[1]->type);
833 assert(glsl_type_is_vector(ir->operands[0]->type)
834 || glsl_type_is_scalar(ir->operands[0]->type));
835 assert(ir->operands[0]->type->vector_elements
836 == ir->type->vector_elements);
837 break;
838
839 case ir_binop_all_equal:
840 case ir_binop_any_nequal:
841 /* GLSL == and != operate on scalars, vectors, matrices and arrays, and
842 * return a scalar boolean. The IR matches that.
843 */
844 assert(ir->type == &glsl_type_builtin_bool);
845 assert(ir->operands[0]->type == ir->operands[1]->type);
846 break;
847
848 case ir_binop_lshift:
849 case ir_binop_rshift:
850 assert(glsl_type_is_integer_16_32_64(ir->operands[0]->type) &&
851 glsl_type_is_integer_16_32_64(ir->operands[1]->type));
852 if (glsl_type_is_scalar(ir->operands[0]->type)) {
853 assert(glsl_type_is_scalar(ir->operands[1]->type));
854 }
855 if (glsl_type_is_vector(ir->operands[0]->type) &&
856 glsl_type_is_vector(ir->operands[1]->type)) {
857 assert(glsl_get_components(ir->operands[0]->type) ==
858 glsl_get_components(ir->operands[1]->type));
859 }
860 assert(ir->type == ir->operands[0]->type);
861 break;
862
863 case ir_binop_bit_and:
864 case ir_binop_bit_xor:
865 case ir_binop_bit_or:
866 assert(ir->operands[0]->type->base_type ==
867 ir->operands[1]->type->base_type);
868 assert(glsl_type_is_integer_16_32_64(ir->type));
869 if (glsl_type_is_vector(ir->operands[0]->type) &&
870 glsl_type_is_vector(ir->operands[1]->type)) {
871 assert(ir->operands[0]->type->vector_elements ==
872 ir->operands[1]->type->vector_elements);
873 }
874 break;
875
876 case ir_binop_logic_and:
877 case ir_binop_logic_xor:
878 case ir_binop_logic_or:
879 assert(glsl_type_is_boolean(ir->type));
880 assert(glsl_type_is_boolean(ir->operands[0]->type));
881 assert(glsl_type_is_boolean(ir->operands[1]->type));
882 break;
883
884 case ir_binop_dot:
885 assert(ir->type == &glsl_type_builtin_float ||
886 ir->type == &glsl_type_builtin_double ||
887 ir->type == &glsl_type_builtin_float16_t);
888 assert(glsl_type_is_float_16_32_64(ir->operands[0]->type));
889 assert(glsl_type_is_vector(ir->operands[0]->type));
890 assert(ir->operands[0]->type == ir->operands[1]->type);
891 break;
892
893 case ir_binop_ldexp:
894 assert(ir->operands[0]->type == ir->type);
895 assert(glsl_type_is_float_16_32_64(ir->operands[0]->type));
896 assert(ir->operands[1]->type->base_type == GLSL_TYPE_INT);
897 assert(glsl_get_components(ir->operands[0]->type) ==
898 glsl_get_components(ir->operands[1]->type));
899 break;
900
901 case ir_binop_vector_extract:
902 assert(glsl_type_is_vector(ir->operands[0]->type));
903 assert(glsl_type_is_scalar(ir->operands[1]->type)
904 && glsl_type_is_integer_16_32(ir->operands[1]->type));
905 break;
906
907 case ir_binop_interpolate_at_offset:
908 assert(ir->operands[0]->type == ir->type);
909 assert(glsl_type_is_float_16_32(ir->operands[0]->type));
910 assert(glsl_get_components(ir->operands[1]->type) == 2);
911 assert(glsl_type_is_float_16_32(ir->operands[1]->type));
912 break;
913
914 case ir_binop_interpolate_at_sample:
915 assert(ir->operands[0]->type == ir->type);
916 assert(glsl_type_is_float_16_32(ir->operands[0]->type));
917 assert(ir->operands[1]->type == &glsl_type_builtin_int ||
918 ir->operands[1]->type == &glsl_type_builtin_int16_t);
919 break;
920
921 case ir_binop_atan2:
922 assert(glsl_type_is_float_16_32_64(ir->operands[0]->type));
923 assert(ir->operands[1]->type == ir->operands[0]->type);
924 assert(ir->type == ir->operands[0]->type);
925 break;
926
927 case ir_triop_fma:
928 assert(glsl_type_is_float_16_32_64(ir->type));
929 assert(ir->type == ir->operands[0]->type);
930 assert(ir->type == ir->operands[1]->type);
931 assert(ir->type == ir->operands[2]->type);
932 break;
933
934 case ir_triop_lrp:
935 assert(glsl_type_is_float_16_32_64(ir->operands[0]->type));
936 assert(ir->operands[0]->type == ir->operands[1]->type);
937 assert(ir->operands[2]->type == ir->operands[0]->type ||
938 ir->operands[2]->type == &glsl_type_builtin_float ||
939 ir->operands[2]->type == &glsl_type_builtin_double ||
940 ir->operands[2]->type == &glsl_type_builtin_float16_t);
941 break;
942
943 case ir_triop_csel:
944 assert(glsl_type_is_boolean(ir->operands[0]->type));
945 assert(ir->type->vector_elements == ir->operands[0]->type->vector_elements);
946 assert(ir->type == ir->operands[1]->type);
947 assert(ir->type == ir->operands[2]->type);
948 break;
949
950 case ir_triop_bitfield_extract:
951 assert(glsl_type_is_integer_16_32(ir->type));
952 assert(ir->operands[0]->type == ir->type);
953 assert(ir->operands[1]->type == ir->type);
954 assert(ir->operands[2]->type == ir->type);
955 break;
956
957 case ir_triop_vector_insert:
958 assert(glsl_type_is_vector(ir->operands[0]->type));
959 assert(glsl_type_is_scalar(ir->operands[1]->type));
960 assert(ir->operands[0]->type->base_type == ir->operands[1]->type->base_type);
961 assert(glsl_type_is_scalar(ir->operands[2]->type)
962 && glsl_type_is_integer_16_32(ir->operands[2]->type));
963 assert(ir->type == ir->operands[0]->type);
964 break;
965
966 case ir_quadop_bitfield_insert:
967 assert(glsl_type_is_integer_16_32(ir->type));
968 assert(ir->operands[0]->type == ir->type);
969 assert(ir->operands[1]->type == ir->type);
970 assert(ir->operands[2]->type == ir->type);
971 assert(ir->operands[3]->type == ir->type);
972 break;
973
974 case ir_quadop_vector:
975 /* The vector operator collects some number of scalars and generates a
976 * vector from them.
977 *
978 * - All of the operands must be scalar.
979 * - Number of operands must matche the size of the resulting vector.
980 * - Base type of the operands must match the base type of the result.
981 */
982 switch (ir->type->vector_elements) {
983 case 1:
984 assert(glsl_type_is_scalar(ir->operands[0]->type));
985 assert(ir->operands[0]->type->base_type == ir->type->base_type);
986 assert(ir->operands[1] == NULL);
987 assert(ir->operands[2] == NULL);
988 assert(ir->operands[3] == NULL);
989 break;
990 case 2:
991 assert(glsl_type_is_scalar(ir->operands[0]->type));
992 assert(ir->operands[0]->type->base_type == ir->type->base_type);
993 assert(glsl_type_is_scalar(ir->operands[1]->type));
994 assert(ir->operands[1]->type->base_type == ir->type->base_type);
995 assert(ir->operands[2] == NULL);
996 assert(ir->operands[3] == NULL);
997 break;
998 case 3:
999 assert(glsl_type_is_scalar(ir->operands[0]->type));
1000 assert(ir->operands[0]->type->base_type == ir->type->base_type);
1001 assert(glsl_type_is_scalar(ir->operands[1]->type));
1002 assert(ir->operands[1]->type->base_type == ir->type->base_type);
1003 assert(glsl_type_is_scalar(ir->operands[2]->type));
1004 assert(ir->operands[2]->type->base_type == ir->type->base_type);
1005 assert(ir->operands[3] == NULL);
1006 break;
1007 case 4:
1008 assert(glsl_type_is_scalar(ir->operands[0]->type));
1009 assert(ir->operands[0]->type->base_type == ir->type->base_type);
1010 assert(glsl_type_is_scalar(ir->operands[1]->type));
1011 assert(ir->operands[1]->type->base_type == ir->type->base_type);
1012 assert(glsl_type_is_scalar(ir->operands[2]->type));
1013 assert(ir->operands[2]->type->base_type == ir->type->base_type);
1014 assert(glsl_type_is_scalar(ir->operands[3]->type));
1015 assert(ir->operands[3]->type->base_type == ir->type->base_type);
1016 break;
1017 default:
1018 /* The is_vector assertion above should prevent execution from ever
1019 * getting here.
1020 */
1021 assert(!"Should not get here.");
1022 break;
1023 }
1024 }
1025
1026 return visit_continue;
1027 }
1028
1029 ir_visitor_status
visit_leave(ir_swizzle * ir)1030 ir_validate::visit_leave(ir_swizzle *ir)
1031 {
1032 unsigned int chans[4] = {ir->mask.x, ir->mask.y, ir->mask.z, ir->mask.w};
1033
1034 for (unsigned int i = 0; i < ir->type->vector_elements; i++) {
1035 if (chans[i] >= ir->val->type->vector_elements) {
1036 printf("ir_swizzle @ %p specifies a channel not present "
1037 "in the value.\n", (void *) ir);
1038 ir->print();
1039 abort();
1040 }
1041 }
1042
1043 return visit_continue;
1044 }
1045
1046 ir_visitor_status
visit(ir_variable * ir)1047 ir_validate::visit(ir_variable *ir)
1048 {
1049 /* An ir_variable is the one thing that can (and will) appear multiple times
1050 * in an IR tree. It is added to the hashtable so that it can be used
1051 * in the ir_dereference_variable handler to ensure that a variable is
1052 * declared before it is dereferenced.
1053 */
1054 if (ir->name && ir->is_name_ralloced())
1055 assert(ralloc_parent(ir->name) == ir);
1056
1057 _mesa_set_add(ir_set, ir);
1058
1059 /* If a variable is an array, verify that the maximum array index is in
1060 * bounds. There was once an error in AST-to-HIR conversion that set this
1061 * to be out of bounds.
1062 */
1063 if (glsl_array_size(ir->type) > 0) {
1064 if (ir->data.max_array_access >= (int)ir->type->length) {
1065 printf("ir_variable has maximum access out of bounds (%d vs %d)\n",
1066 ir->data.max_array_access, ir->type->length - 1);
1067 ir->print();
1068 abort();
1069 }
1070 }
1071
1072 /* If a variable is an interface block (or an array of interface blocks),
1073 * verify that the maximum array index for each interface member is in
1074 * bounds.
1075 */
1076 if (ir->is_interface_instance()) {
1077 const glsl_struct_field *fields =
1078 ir->get_interface_type()->fields.structure;
1079 for (unsigned i = 0; i < ir->get_interface_type()->length; i++) {
1080 if (glsl_array_size(fields[i].type) > 0 &&
1081 !fields[i].implicit_sized_array) {
1082 const int *const max_ifc_array_access =
1083 ir->get_max_ifc_array_access();
1084
1085 assert(max_ifc_array_access != NULL);
1086
1087 if (max_ifc_array_access[i] >= (int)fields[i].type->length) {
1088 printf("ir_variable has maximum access out of bounds for "
1089 "field %s (%d vs %d)\n", fields[i].name,
1090 max_ifc_array_access[i], fields[i].type->length);
1091 ir->print();
1092 abort();
1093 }
1094 }
1095 }
1096 }
1097
1098 if (ir->constant_initializer != NULL && !ir->data.has_initializer) {
1099 printf("ir_variable didn't have an initializer, but has a constant "
1100 "initializer value.\n");
1101 ir->print();
1102 abort();
1103 }
1104
1105 if (ir->data.mode == ir_var_uniform
1106 && is_gl_identifier(ir->name)
1107 && ir->get_state_slots() == NULL) {
1108 printf("built-in uniform has no state\n");
1109 ir->print();
1110 abort();
1111 }
1112
1113 return visit_continue;
1114 }
1115
1116 ir_visitor_status
visit_enter(ir_assignment * ir)1117 ir_validate::visit_enter(ir_assignment *ir)
1118 {
1119 const ir_dereference *const lhs = ir->lhs;
1120 if (glsl_type_is_scalar(lhs->type) || glsl_type_is_vector(lhs->type)) {
1121 if (ir->write_mask == 0) {
1122 printf("Assignment LHS is %s, but write mask is 0:\n",
1123 glsl_type_is_scalar(lhs->type) ? "scalar" : "vector");
1124 ir->print();
1125 abort();
1126 }
1127
1128 int lhs_components = 0;
1129 for (int i = 0; i < 4; i++) {
1130 if (ir->write_mask & (1 << i))
1131 lhs_components++;
1132 }
1133
1134 if (lhs_components != ir->rhs->type->vector_elements) {
1135 printf("Assignment count of LHS write mask channels enabled not\n"
1136 "matching RHS vector size (%d LHS, %d RHS).\n",
1137 lhs_components, ir->rhs->type->vector_elements);
1138 ir->print();
1139 abort();
1140 }
1141 }
1142
1143 if (lhs->type->base_type != ir->rhs->type->base_type) {
1144 printf("Assignment LHS and RHS base types are different:\n");
1145 lhs->print();
1146 printf("\n");
1147 ir->rhs->print();
1148 printf("\n");
1149 abort();
1150 }
1151
1152 this->validate_ir(ir, this->data_enter);
1153
1154 return visit_continue;
1155 }
1156
1157 ir_visitor_status
visit_enter(ir_call * ir)1158 ir_validate::visit_enter(ir_call *ir)
1159 {
1160 ir_function_signature *const callee = ir->callee;
1161
1162 if (callee->ir_type != ir_type_function_signature) {
1163 printf("IR called by ir_call is not ir_function_signature!\n");
1164 abort();
1165 }
1166
1167 if (ir->return_deref) {
1168 if (ir->return_deref->type != callee->return_type) {
1169 printf("callee type %s does not match return storage type %s\n",
1170 glsl_get_type_name(callee->return_type), glsl_get_type_name(ir->return_deref->type));
1171 abort();
1172 }
1173 } else if (callee->return_type != &glsl_type_builtin_void) {
1174 printf("ir_call has non-void callee but no return storage\n");
1175 abort();
1176 }
1177
1178 const exec_node *formal_param_node = callee->parameters.get_head_raw();
1179 const exec_node *actual_param_node = ir->actual_parameters.get_head_raw();
1180 while (true) {
1181 if (formal_param_node->is_tail_sentinel()
1182 != actual_param_node->is_tail_sentinel()) {
1183 printf("ir_call has the wrong number of parameters:\n");
1184 goto dump_ir;
1185 }
1186 if (formal_param_node->is_tail_sentinel()) {
1187 break;
1188 }
1189 const ir_variable *formal_param
1190 = (const ir_variable *) formal_param_node;
1191 const ir_rvalue *actual_param
1192 = (const ir_rvalue *) actual_param_node;
1193 if (formal_param->type != actual_param->type) {
1194 printf("ir_call parameter type mismatch:\n");
1195 goto dump_ir;
1196 }
1197 if (formal_param->data.mode == ir_var_function_out
1198 || formal_param->data.mode == ir_var_function_inout) {
1199 if (!actual_param->is_lvalue()) {
1200 printf("ir_call out/inout parameters must be lvalues:\n");
1201 goto dump_ir;
1202 }
1203 }
1204 formal_param_node = formal_param_node->next;
1205 actual_param_node = actual_param_node->next;
1206 }
1207
1208 return visit_continue;
1209
1210 dump_ir:
1211 ir->print();
1212 printf("callee:\n");
1213 callee->print();
1214 abort();
1215 return visit_stop;
1216 }
1217
1218 void
validate_ir(ir_instruction * ir,void * data)1219 ir_validate::validate_ir(ir_instruction *ir, void *data)
1220 {
1221 struct set *ir_set = (struct set *) data;
1222
1223 if (_mesa_set_search(ir_set, ir)) {
1224 printf("Instruction node present twice in ir tree:\n");
1225 ir->print();
1226 printf("\n");
1227 abort();
1228 }
1229 _mesa_set_add(ir_set, ir);
1230 }
1231
1232 static void
check_node_type(ir_instruction * ir,void * data)1233 check_node_type(ir_instruction *ir, void *data)
1234 {
1235 (void) data;
1236
1237 if (ir->ir_type >= ir_type_max) {
1238 printf("Instruction node with unset type\n");
1239 ir->print(); printf("\n");
1240 }
1241 ir_rvalue *value = ir->as_rvalue();
1242 if (value != NULL)
1243 assert(value->type != &glsl_type_builtin_error);
1244 }
1245
1246 void
validate_ir_tree(exec_list * instructions)1247 validate_ir_tree(exec_list *instructions)
1248 {
1249 /* We shouldn't have any reason to validate IR in a release build,
1250 * and it's half composed of assert()s anyway which wouldn't do
1251 * anything.
1252 */
1253 #if !MESA_DEBUG
1254 if (!debug_get_bool_option("GLSL_VALIDATE", false))
1255 return;
1256 #endif
1257 ir_validate v;
1258
1259 v.run(instructions);
1260
1261 foreach_in_list(ir_instruction, ir, instructions) {
1262 visit_tree(ir, check_node_type, NULL);
1263 }
1264 }
1265