153cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt/*
253cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt * Copyright © 2010 Intel Corporation
353cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt *
453cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt * Permission is hereby granted, free of charge, to any person obtaining a
553cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt * copy of this software and associated documentation files (the "Software"),
653cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt * to deal in the Software without restriction, including without limitation
753cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt * the rights to use, copy, modify, merge, publish, distribute, sublicense,
853cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt * and/or sell copies of the Software, and to permit persons to whom the
953cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt * Software is furnished to do so, subject to the following conditions:
1053cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt *
1153cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt * The above copyright notice and this permission notice (including the next
1253cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt * paragraph) shall be included in all copies or substantial portions of the
1353cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt * Software.
1453cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt *
1553cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1653cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1753cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
1853cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1953cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
2053cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2153cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt * DEALINGS IN THE SOFTWARE.
2253cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt */
2353cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt
2453cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt/**
2553cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt * \file ir_validate.cpp
2653cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt *
2753cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt * Attempts to verify that various invariants of the IR tree are true.
2853cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt *
2953cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt * In particular, at the moment it makes sure that no single
3053cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt * ir_instruction node except for ir_variable appears multiple times
3153cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt * in the ir tree.  ir_variable does appear multiple times: Once as a
3253cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt * declaration in an exec_list, and multiple times as the endpoint of
3353cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt * a dereference chain.
3453cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt */
3553cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt
3653cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt#include "ir.h"
37865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanick#include "ir_hierarchical_visitor.h"
3831747155ea3a24190277b125bd188ac8689af719Aras Pranckevicius#include "program/hash_table.h"
39f141fa63a4391621cc92cd2c39724a952b297a58Eric Anholt#include "glsl_types.h"
4053cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt
41865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanickclass ir_validate : public ir_hierarchical_visitor {
42865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanickpublic:
43865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanick   ir_validate()
44865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanick   {
45d1a1ee583e7e8338243b3e9768d2fc5312a1145dIan Romanick      this->ht = hash_table_ctor(0, hash_table_pointer_hash,
46d1a1ee583e7e8338243b3e9768d2fc5312a1145dIan Romanick				 hash_table_pointer_compare);
4753cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt
48c67016de960c988c748ffdb11247072543a8f328Ian Romanick      this->current_function = NULL;
49c67016de960c988c748ffdb11247072543a8f328Ian Romanick
50865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanick      this->callback = ir_validate::validate_ir;
51865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanick      this->data = ht;
52865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanick   }
5353cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt
54865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanick   ~ir_validate()
55865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanick   {
56865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanick      hash_table_dtor(this->ht);
57865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanick   }
5853cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt
59865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanick   virtual ir_visitor_status visit(ir_variable *v);
608baf21b1a4d50efca086679cc43bb0cfc3fee03aIan Romanick   virtual ir_visitor_status visit(ir_dereference_variable *ir);
616c8ea1eed66e9da82fb2b49b1e7f6d7f6064dbc4Kenneth Graunke
626c8ea1eed66e9da82fb2b49b1e7f6d7f6064dbc4Kenneth Graunke   virtual ir_visitor_status visit_enter(ir_if *ir);
6353cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt
6453acbd87d712555f9e7a1c304843be7b39641413Ian Romanick   virtual ir_visitor_status visit_leave(ir_loop *ir);
65c67016de960c988c748ffdb11247072543a8f328Ian Romanick   virtual ir_visitor_status visit_enter(ir_function *ir);
66c67016de960c988c748ffdb11247072543a8f328Ian Romanick   virtual ir_visitor_status visit_leave(ir_function *ir);
67c67016de960c988c748ffdb11247072543a8f328Ian Romanick   virtual ir_visitor_status visit_enter(ir_function_signature *ir);
68c67016de960c988c748ffdb11247072543a8f328Ian Romanick
695533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   virtual ir_visitor_status visit_leave(ir_expression *ir);
705e8ed7a79b381d559b059987bd99c68d40f641caEric Anholt   virtual ir_visitor_status visit_leave(ir_swizzle *ir);
715533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt
726235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick   virtual ir_visitor_status visit_enter(ir_assignment *ir);
738bbfbb14eee53e42a488ba24c0cfc9ffa1cf6318Ian Romanick   virtual ir_visitor_status visit_enter(ir_call *ir);
746235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick
75865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanick   static void validate_ir(ir_instruction *ir, void *data);
7653cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt
77c67016de960c988c748ffdb11247072543a8f328Ian Romanick   ir_function *current_function;
78c67016de960c988c748ffdb11247072543a8f328Ian Romanick
79865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanick   struct hash_table *ht;
80865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanick};
8153cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt
828baf21b1a4d50efca086679cc43bb0cfc3fee03aIan Romanick
838baf21b1a4d50efca086679cc43bb0cfc3fee03aIan Romanickir_visitor_status
848baf21b1a4d50efca086679cc43bb0cfc3fee03aIan Romanickir_validate::visit(ir_dereference_variable *ir)
858baf21b1a4d50efca086679cc43bb0cfc3fee03aIan Romanick{
868baf21b1a4d50efca086679cc43bb0cfc3fee03aIan Romanick   if ((ir->var == NULL) || (ir->var->as_variable() == NULL)) {
878baf21b1a4d50efca086679cc43bb0cfc3fee03aIan Romanick      printf("ir_dereference_variable @ %p does not specify a variable %p\n",
889f9386d22aca8d14d1b1e6d4de9b24dcb183ca10Brian Paul	     (void *) ir, (void *) ir->var);
898baf21b1a4d50efca086679cc43bb0cfc3fee03aIan Romanick      abort();
908baf21b1a4d50efca086679cc43bb0cfc3fee03aIan Romanick   }
918baf21b1a4d50efca086679cc43bb0cfc3fee03aIan Romanick
928baf21b1a4d50efca086679cc43bb0cfc3fee03aIan Romanick   if (hash_table_find(ht, ir->var) == NULL) {
938baf21b1a4d50efca086679cc43bb0cfc3fee03aIan Romanick      printf("ir_dereference_variable @ %p specifies undeclared variable "
948baf21b1a4d50efca086679cc43bb0cfc3fee03aIan Romanick	     "`%s' @ %p\n",
959f9386d22aca8d14d1b1e6d4de9b24dcb183ca10Brian Paul	     (void *) ir, ir->var->name, (void *) ir->var);
968baf21b1a4d50efca086679cc43bb0cfc3fee03aIan Romanick      abort();
978baf21b1a4d50efca086679cc43bb0cfc3fee03aIan Romanick   }
988baf21b1a4d50efca086679cc43bb0cfc3fee03aIan Romanick
99506880bc32e7bb98fd1896a9b2fe3614abab904fIan Romanick   this->validate_ir(ir, this->data);
100506880bc32e7bb98fd1896a9b2fe3614abab904fIan Romanick
1018baf21b1a4d50efca086679cc43bb0cfc3fee03aIan Romanick   return visit_continue;
1028baf21b1a4d50efca086679cc43bb0cfc3fee03aIan Romanick}
1038baf21b1a4d50efca086679cc43bb0cfc3fee03aIan Romanick
104432b787b29202301dbfc139c3289521b0bfc3decEric Anholtir_visitor_status
1056c8ea1eed66e9da82fb2b49b1e7f6d7f6064dbc4Kenneth Graunkeir_validate::visit_enter(ir_if *ir)
106432b787b29202301dbfc139c3289521b0bfc3decEric Anholt{
107432b787b29202301dbfc139c3289521b0bfc3decEric Anholt   if (ir->condition->type != glsl_type::bool_type) {
108432b787b29202301dbfc139c3289521b0bfc3decEric Anholt      printf("ir_if condition %s type instead of bool.\n",
109432b787b29202301dbfc139c3289521b0bfc3decEric Anholt	     ir->condition->type->name);
110432b787b29202301dbfc139c3289521b0bfc3decEric Anholt      ir->print();
111432b787b29202301dbfc139c3289521b0bfc3decEric Anholt      printf("\n");
112432b787b29202301dbfc139c3289521b0bfc3decEric Anholt      abort();
113432b787b29202301dbfc139c3289521b0bfc3decEric Anholt   }
1146a1401eb889b5e535c212c414743cc7ea07f6622Eric Anholt
1156a1401eb889b5e535c212c414743cc7ea07f6622Eric Anholt   return visit_continue;
116432b787b29202301dbfc139c3289521b0bfc3decEric Anholt}
117432b787b29202301dbfc139c3289521b0bfc3decEric Anholt
1188baf21b1a4d50efca086679cc43bb0cfc3fee03aIan Romanick
11953cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholtir_visitor_status
12053acbd87d712555f9e7a1c304843be7b39641413Ian Romanickir_validate::visit_leave(ir_loop *ir)
12153acbd87d712555f9e7a1c304843be7b39641413Ian Romanick{
12253acbd87d712555f9e7a1c304843be7b39641413Ian Romanick   if (ir->counter != NULL) {
123a00623174b629525fa5a9ba651ba31809b23b6e7Dave Airlie      if ((ir->from == NULL) || (ir->to == NULL) || (ir->increment == NULL)) {
12453acbd87d712555f9e7a1c304843be7b39641413Ian Romanick	 printf("ir_loop has invalid loop controls:\n"
12553acbd87d712555f9e7a1c304843be7b39641413Ian Romanick		"    counter:   %p\n"
12653acbd87d712555f9e7a1c304843be7b39641413Ian Romanick		"    from:      %p\n"
12753acbd87d712555f9e7a1c304843be7b39641413Ian Romanick		"    to:        %p\n"
12853acbd87d712555f9e7a1c304843be7b39641413Ian Romanick		"    increment: %p\n",
12917391241599137b9729e9ee6c5487d05e04d8aeeBrian Paul		(void *) ir->counter, (void *) ir->from, (void *) ir->to,
13017391241599137b9729e9ee6c5487d05e04d8aeeBrian Paul                (void *) ir->increment);
13153acbd87d712555f9e7a1c304843be7b39641413Ian Romanick	 abort();
13253acbd87d712555f9e7a1c304843be7b39641413Ian Romanick      }
13353acbd87d712555f9e7a1c304843be7b39641413Ian Romanick
13453acbd87d712555f9e7a1c304843be7b39641413Ian Romanick      if ((ir->cmp < ir_binop_less) || (ir->cmp > ir_binop_nequal)) {
13553acbd87d712555f9e7a1c304843be7b39641413Ian Romanick	 printf("ir_loop has invalid comparitor %d\n", ir->cmp);
13653acbd87d712555f9e7a1c304843be7b39641413Ian Romanick	 abort();
13753acbd87d712555f9e7a1c304843be7b39641413Ian Romanick      }
13853acbd87d712555f9e7a1c304843be7b39641413Ian Romanick   } else {
139a00623174b629525fa5a9ba651ba31809b23b6e7Dave Airlie      if ((ir->from != NULL) || (ir->to != NULL) || (ir->increment != NULL)) {
14053acbd87d712555f9e7a1c304843be7b39641413Ian Romanick	 printf("ir_loop has invalid loop controls:\n"
14153acbd87d712555f9e7a1c304843be7b39641413Ian Romanick		"    counter:   %p\n"
14253acbd87d712555f9e7a1c304843be7b39641413Ian Romanick		"    from:      %p\n"
14353acbd87d712555f9e7a1c304843be7b39641413Ian Romanick		"    to:        %p\n"
14453acbd87d712555f9e7a1c304843be7b39641413Ian Romanick		"    increment: %p\n",
14517391241599137b9729e9ee6c5487d05e04d8aeeBrian Paul		(void *) ir->counter, (void *) ir->from, (void *) ir->to,
14617391241599137b9729e9ee6c5487d05e04d8aeeBrian Paul                (void *) ir->increment);
14753acbd87d712555f9e7a1c304843be7b39641413Ian Romanick	 abort();
14853acbd87d712555f9e7a1c304843be7b39641413Ian Romanick      }
14953acbd87d712555f9e7a1c304843be7b39641413Ian Romanick   }
15053acbd87d712555f9e7a1c304843be7b39641413Ian Romanick
15153acbd87d712555f9e7a1c304843be7b39641413Ian Romanick   return visit_continue;
15253acbd87d712555f9e7a1c304843be7b39641413Ian Romanick}
15353acbd87d712555f9e7a1c304843be7b39641413Ian Romanick
15453acbd87d712555f9e7a1c304843be7b39641413Ian Romanick
15553acbd87d712555f9e7a1c304843be7b39641413Ian Romanickir_visitor_status
156c67016de960c988c748ffdb11247072543a8f328Ian Romanickir_validate::visit_enter(ir_function *ir)
157c67016de960c988c748ffdb11247072543a8f328Ian Romanick{
158c67016de960c988c748ffdb11247072543a8f328Ian Romanick   /* Function definitions cannot be nested.
159c67016de960c988c748ffdb11247072543a8f328Ian Romanick    */
160c67016de960c988c748ffdb11247072543a8f328Ian Romanick   if (this->current_function != NULL) {
161c67016de960c988c748ffdb11247072543a8f328Ian Romanick      printf("Function definition nested inside another function "
162c67016de960c988c748ffdb11247072543a8f328Ian Romanick	     "definition:\n");
163c67016de960c988c748ffdb11247072543a8f328Ian Romanick      printf("%s %p inside %s %p\n",
1649f9386d22aca8d14d1b1e6d4de9b24dcb183ca10Brian Paul	     ir->name, (void *) ir,
1659f9386d22aca8d14d1b1e6d4de9b24dcb183ca10Brian Paul	     this->current_function->name, (void *) this->current_function);
166c67016de960c988c748ffdb11247072543a8f328Ian Romanick      abort();
167c67016de960c988c748ffdb11247072543a8f328Ian Romanick   }
168c67016de960c988c748ffdb11247072543a8f328Ian Romanick
169c67016de960c988c748ffdb11247072543a8f328Ian Romanick   /* Store the current function hierarchy being traversed.  This is used
170c67016de960c988c748ffdb11247072543a8f328Ian Romanick    * by the function signature visitor to ensure that the signatures are
171c67016de960c988c748ffdb11247072543a8f328Ian Romanick    * linked with the correct functions.
172c67016de960c988c748ffdb11247072543a8f328Ian Romanick    */
173c67016de960c988c748ffdb11247072543a8f328Ian Romanick   this->current_function = ir;
174c67016de960c988c748ffdb11247072543a8f328Ian Romanick
175c67016de960c988c748ffdb11247072543a8f328Ian Romanick   this->validate_ir(ir, this->data);
176c67016de960c988c748ffdb11247072543a8f328Ian Romanick
1778bbfbb14eee53e42a488ba24c0cfc9ffa1cf6318Ian Romanick   /* Verify that all of the things stored in the list of signatures are,
1788bbfbb14eee53e42a488ba24c0cfc9ffa1cf6318Ian Romanick    * in fact, function signatures.
1798bbfbb14eee53e42a488ba24c0cfc9ffa1cf6318Ian Romanick    */
1808bbfbb14eee53e42a488ba24c0cfc9ffa1cf6318Ian Romanick   foreach_list(node, &ir->signatures) {
1818bbfbb14eee53e42a488ba24c0cfc9ffa1cf6318Ian Romanick      ir_instruction *sig = (ir_instruction *) node;
1828bbfbb14eee53e42a488ba24c0cfc9ffa1cf6318Ian Romanick
1838bbfbb14eee53e42a488ba24c0cfc9ffa1cf6318Ian Romanick      if (sig->ir_type != ir_type_function_signature) {
1848bbfbb14eee53e42a488ba24c0cfc9ffa1cf6318Ian Romanick	 printf("Non-signature in signature list of function `%s'\n",
1858bbfbb14eee53e42a488ba24c0cfc9ffa1cf6318Ian Romanick		ir->name);
1868bbfbb14eee53e42a488ba24c0cfc9ffa1cf6318Ian Romanick	 abort();
1878bbfbb14eee53e42a488ba24c0cfc9ffa1cf6318Ian Romanick      }
1888bbfbb14eee53e42a488ba24c0cfc9ffa1cf6318Ian Romanick   }
1898bbfbb14eee53e42a488ba24c0cfc9ffa1cf6318Ian Romanick
190c67016de960c988c748ffdb11247072543a8f328Ian Romanick   return visit_continue;
191c67016de960c988c748ffdb11247072543a8f328Ian Romanick}
192c67016de960c988c748ffdb11247072543a8f328Ian Romanick
193c67016de960c988c748ffdb11247072543a8f328Ian Romanickir_visitor_status
194c67016de960c988c748ffdb11247072543a8f328Ian Romanickir_validate::visit_leave(ir_function *ir)
195c67016de960c988c748ffdb11247072543a8f328Ian Romanick{
196d3073f58c17d8675a2ecdd5dfa83e5520c78e1a8Kenneth Graunke   assert(ralloc_parent(ir->name) == ir);
197c67016de960c988c748ffdb11247072543a8f328Ian Romanick
198c67016de960c988c748ffdb11247072543a8f328Ian Romanick   this->current_function = NULL;
199c67016de960c988c748ffdb11247072543a8f328Ian Romanick   return visit_continue;
200c67016de960c988c748ffdb11247072543a8f328Ian Romanick}
201c67016de960c988c748ffdb11247072543a8f328Ian Romanick
202c67016de960c988c748ffdb11247072543a8f328Ian Romanickir_visitor_status
203c67016de960c988c748ffdb11247072543a8f328Ian Romanickir_validate::visit_enter(ir_function_signature *ir)
204c67016de960c988c748ffdb11247072543a8f328Ian Romanick{
205c67016de960c988c748ffdb11247072543a8f328Ian Romanick   if (this->current_function != ir->function()) {
206c67016de960c988c748ffdb11247072543a8f328Ian Romanick      printf("Function signature nested inside wrong function "
207c67016de960c988c748ffdb11247072543a8f328Ian Romanick	     "definition:\n");
208c67016de960c988c748ffdb11247072543a8f328Ian Romanick      printf("%p inside %s %p instead of %s %p\n",
2099f9386d22aca8d14d1b1e6d4de9b24dcb183ca10Brian Paul	     (void *) ir,
2109f9386d22aca8d14d1b1e6d4de9b24dcb183ca10Brian Paul	     this->current_function->name, (void *) this->current_function,
2119f9386d22aca8d14d1b1e6d4de9b24dcb183ca10Brian Paul	     ir->function_name(), (void *) ir->function());
212c67016de960c988c748ffdb11247072543a8f328Ian Romanick      abort();
213c67016de960c988c748ffdb11247072543a8f328Ian Romanick   }
214c67016de960c988c748ffdb11247072543a8f328Ian Romanick
2152df56b002dcc5d7e91515bd0ca741677f0172b38Ian Romanick   if (ir->return_type == NULL) {
2162df56b002dcc5d7e91515bd0ca741677f0172b38Ian Romanick      printf("Function signature %p for function %s has NULL return type.\n",
2170eab3a8a976ea282063710d5aa7d1709abc182c5Brian Paul	     (void *) ir, ir->function_name());
2182df56b002dcc5d7e91515bd0ca741677f0172b38Ian Romanick      abort();
2192df56b002dcc5d7e91515bd0ca741677f0172b38Ian Romanick   }
2202df56b002dcc5d7e91515bd0ca741677f0172b38Ian Romanick
221c67016de960c988c748ffdb11247072543a8f328Ian Romanick   this->validate_ir(ir, this->data);
222c67016de960c988c748ffdb11247072543a8f328Ian Romanick
223c67016de960c988c748ffdb11247072543a8f328Ian Romanick   return visit_continue;
224c67016de960c988c748ffdb11247072543a8f328Ian Romanick}
225c67016de960c988c748ffdb11247072543a8f328Ian Romanick
226c67016de960c988c748ffdb11247072543a8f328Ian Romanickir_visitor_status
2275533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholtir_validate::visit_leave(ir_expression *ir)
2285533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt{
2295533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   switch (ir->operation) {
2305533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_bit_not:
2315533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->operands[0]->type == ir->type);
2325533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      break;
2335533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_logic_not:
234e75dbf66d011d76b6944dc4ee55e339ee285510cEric Anholt      assert(ir->type->base_type == GLSL_TYPE_BOOL);
235e75dbf66d011d76b6944dc4ee55e339ee285510cEric Anholt      assert(ir->operands[0]->type->base_type == GLSL_TYPE_BOOL);
2365533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      break;
2375533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt
2385533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_neg:
2395533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_abs:
2405533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_sign:
2415533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_rcp:
2425533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_rsq:
2435533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_sqrt:
244bc4034b243975089c06c4415d4e26edaaaec7a46Eric Anholt      assert(ir->type == ir->operands[0]->type);
245bc4034b243975089c06c4415d4e26edaaaec7a46Eric Anholt      break;
246bc4034b243975089c06c4415d4e26edaaaec7a46Eric Anholt
2475533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_exp:
2485533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_log:
2495533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_exp2:
2505533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_log2:
251bc4034b243975089c06c4415d4e26edaaaec7a46Eric Anholt      assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT);
2525533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->type == ir->operands[0]->type);
2535533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      break;
2545533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt
2555533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_f2i:
2565533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT);
2573283e362e313f8a45fd6ee812efb737c0becc38cKenneth Graunke      assert(ir->type->base_type == GLSL_TYPE_INT);
2585533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      break;
2598e31f961e6cfd9680b33647c053b0f708abb8a18Paul Berry   case ir_unop_f2u:
2608e31f961e6cfd9680b33647c053b0f708abb8a18Paul Berry      assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT);
2618e31f961e6cfd9680b33647c053b0f708abb8a18Paul Berry      assert(ir->type->base_type == GLSL_TYPE_UINT);
2628e31f961e6cfd9680b33647c053b0f708abb8a18Paul Berry      break;
2635533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_i2f:
2645533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT);
2655533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->type->base_type == GLSL_TYPE_FLOAT);
2665533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      break;
2675533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_f2b:
2685533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT);
2695533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->type->base_type == GLSL_TYPE_BOOL);
2705533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      break;
2715533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_b2f:
2725533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->operands[0]->type->base_type == GLSL_TYPE_BOOL);
2735533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->type->base_type == GLSL_TYPE_FLOAT);
2745533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      break;
2755533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_i2b:
2763283e362e313f8a45fd6ee812efb737c0becc38cKenneth Graunke      assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT);
2775533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->type->base_type == GLSL_TYPE_BOOL);
2785533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      break;
2795533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_b2i:
2805533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->operands[0]->type->base_type == GLSL_TYPE_BOOL);
2813283e362e313f8a45fd6ee812efb737c0becc38cKenneth Graunke      assert(ir->type->base_type == GLSL_TYPE_INT);
2825533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      break;
2835533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_u2f:
2845533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT);
2855533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->type->base_type == GLSL_TYPE_FLOAT);
2865533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      break;
28720ef96c7ff3f17fbf97e0452a37553249b2b005cBryan Cain   case ir_unop_i2u:
28820ef96c7ff3f17fbf97e0452a37553249b2b005cBryan Cain      assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT);
28920ef96c7ff3f17fbf97e0452a37553249b2b005cBryan Cain      assert(ir->type->base_type == GLSL_TYPE_UINT);
29020ef96c7ff3f17fbf97e0452a37553249b2b005cBryan Cain      break;
29120ef96c7ff3f17fbf97e0452a37553249b2b005cBryan Cain   case ir_unop_u2i:
29220ef96c7ff3f17fbf97e0452a37553249b2b005cBryan Cain      assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT);
29320ef96c7ff3f17fbf97e0452a37553249b2b005cBryan Cain      assert(ir->type->base_type == GLSL_TYPE_INT);
29420ef96c7ff3f17fbf97e0452a37553249b2b005cBryan Cain      break;
2951b8a3aad09d67e72903fdcc79beadfc3c77cae62Olivier Galibert   case ir_unop_bitcast_i2f:
2961b8a3aad09d67e72903fdcc79beadfc3c77cae62Olivier Galibert      assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT);
2971b8a3aad09d67e72903fdcc79beadfc3c77cae62Olivier Galibert      assert(ir->type->base_type == GLSL_TYPE_FLOAT);
2981b8a3aad09d67e72903fdcc79beadfc3c77cae62Olivier Galibert      break;
2991b8a3aad09d67e72903fdcc79beadfc3c77cae62Olivier Galibert   case ir_unop_bitcast_f2i:
3001b8a3aad09d67e72903fdcc79beadfc3c77cae62Olivier Galibert      assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT);
3011b8a3aad09d67e72903fdcc79beadfc3c77cae62Olivier Galibert      assert(ir->type->base_type == GLSL_TYPE_INT);
3021b8a3aad09d67e72903fdcc79beadfc3c77cae62Olivier Galibert      break;
3031b8a3aad09d67e72903fdcc79beadfc3c77cae62Olivier Galibert   case ir_unop_bitcast_u2f:
3041b8a3aad09d67e72903fdcc79beadfc3c77cae62Olivier Galibert      assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT);
3051b8a3aad09d67e72903fdcc79beadfc3c77cae62Olivier Galibert      assert(ir->type->base_type == GLSL_TYPE_FLOAT);
3061b8a3aad09d67e72903fdcc79beadfc3c77cae62Olivier Galibert      break;
3071b8a3aad09d67e72903fdcc79beadfc3c77cae62Olivier Galibert   case ir_unop_bitcast_f2u:
3081b8a3aad09d67e72903fdcc79beadfc3c77cae62Olivier Galibert      assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT);
3091b8a3aad09d67e72903fdcc79beadfc3c77cae62Olivier Galibert      assert(ir->type->base_type == GLSL_TYPE_UINT);
3101b8a3aad09d67e72903fdcc79beadfc3c77cae62Olivier Galibert      break;
3115533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt
3125e9ac94cc44ef4f97063d7b696411b2a4be16f36Eric Anholt   case ir_unop_any:
3135e9ac94cc44ef4f97063d7b696411b2a4be16f36Eric Anholt      assert(ir->operands[0]->type->base_type == GLSL_TYPE_BOOL);
3145e9ac94cc44ef4f97063d7b696411b2a4be16f36Eric Anholt      assert(ir->type == glsl_type::bool_type);
3155e9ac94cc44ef4f97063d7b696411b2a4be16f36Eric Anholt      break;
3165e9ac94cc44ef4f97063d7b696411b2a4be16f36Eric Anholt
3175533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_trunc:
318b2578ef873c4c9dd831a23501a677bf523de90fcBrian Paul   case ir_unop_round_even:
3195533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_ceil:
3205533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_floor:
3215533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_fract:
3225533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_sin:
3235533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_cos:
324f2616e56de8a48360cae8f269727b58490555f4dIan Romanick   case ir_unop_sin_reduced:
325f2616e56de8a48360cae8f269727b58490555f4dIan Romanick   case ir_unop_cos_reduced:
3265533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_dFdx:
3275533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_dFdy:
3285533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT);
3295533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->operands[0]->type == ir->type);
3305533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      break;
3315533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt
3321c0644e9dac946131594216e23953a9c85335282Brian Paul   case ir_unop_noise:
3331c0644e9dac946131594216e23953a9c85335282Brian Paul      /* XXX what can we assert here? */
3341c0644e9dac946131594216e23953a9c85335282Brian Paul      break;
3351c0644e9dac946131594216e23953a9c85335282Brian Paul
3365533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_binop_add:
3375533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_binop_sub:
3385533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_binop_mul:
3395533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_binop_div:
3405533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_binop_mod:
3415533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_binop_min:
3425533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_binop_max:
3435533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_binop_pow:
3445533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      if (ir->operands[0]->type->is_scalar())
3455533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt	 assert(ir->operands[1]->type == ir->type);
3465533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      else if (ir->operands[1]->type->is_scalar())
3475533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt	 assert(ir->operands[0]->type == ir->type);
3485533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      else if (ir->operands[0]->type->is_vector() &&
3495533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt	       ir->operands[1]->type->is_vector()) {
3505533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt	 assert(ir->operands[0]->type == ir->operands[1]->type);
3515533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt	 assert(ir->operands[0]->type == ir->type);
3525533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      }
3535533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      break;
3544dfb89904c0a3d2166e9a3fc0253a254680e91bcLuca Barbieri
3555533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_binop_less:
3565533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_binop_greater:
3575533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_binop_lequal:
3585533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_binop_gequal:
3594dfb89904c0a3d2166e9a3fc0253a254680e91bcLuca Barbieri   case ir_binop_equal:
3604dfb89904c0a3d2166e9a3fc0253a254680e91bcLuca Barbieri   case ir_binop_nequal:
3614dfb89904c0a3d2166e9a3fc0253a254680e91bcLuca Barbieri      /* The semantics of the IR operators differ from the GLSL <, >, <=, >=,
3624dfb89904c0a3d2166e9a3fc0253a254680e91bcLuca Barbieri       * ==, and != operators.  The IR operators perform a component-wise
3634dfb89904c0a3d2166e9a3fc0253a254680e91bcLuca Barbieri       * comparison on scalar or vector types and return a boolean scalar or
3644dfb89904c0a3d2166e9a3fc0253a254680e91bcLuca Barbieri       * vector type of the same size.
3655533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt       */
3664dfb89904c0a3d2166e9a3fc0253a254680e91bcLuca Barbieri      assert(ir->type->base_type == GLSL_TYPE_BOOL);
3675533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->operands[0]->type == ir->operands[1]->type);
3684dfb89904c0a3d2166e9a3fc0253a254680e91bcLuca Barbieri      assert(ir->operands[0]->type->is_vector()
3694dfb89904c0a3d2166e9a3fc0253a254680e91bcLuca Barbieri	     || ir->operands[0]->type->is_scalar());
3704dfb89904c0a3d2166e9a3fc0253a254680e91bcLuca Barbieri      assert(ir->operands[0]->type->vector_elements
3714dfb89904c0a3d2166e9a3fc0253a254680e91bcLuca Barbieri	     == ir->type->vector_elements);
3725533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      break;
3735533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt
3744dfb89904c0a3d2166e9a3fc0253a254680e91bcLuca Barbieri   case ir_binop_all_equal:
3754dfb89904c0a3d2166e9a3fc0253a254680e91bcLuca Barbieri   case ir_binop_any_nequal:
3764dfb89904c0a3d2166e9a3fc0253a254680e91bcLuca Barbieri      /* GLSL == and != operate on scalars, vectors, matrices and arrays, and
3774dfb89904c0a3d2166e9a3fc0253a254680e91bcLuca Barbieri       * return a scalar boolean.  The IR matches that.
3785533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt       */
3795533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->type == glsl_type::bool_type);
3805533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->operands[0]->type == ir->operands[1]->type);
3815533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      break;
3825533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt
3835533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_binop_lshift:
3845533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_binop_rshift:
3855c4c36f7f3842e287b303b1eca8d260c37e3580bChad Versace      assert(ir->operands[0]->type->is_integer() &&
3865c4c36f7f3842e287b303b1eca8d260c37e3580bChad Versace             ir->operands[1]->type->is_integer());
3875c4c36f7f3842e287b303b1eca8d260c37e3580bChad Versace      if (ir->operands[0]->type->is_scalar()) {
3885c4c36f7f3842e287b303b1eca8d260c37e3580bChad Versace          assert(ir->operands[1]->type->is_scalar());
3895c4c36f7f3842e287b303b1eca8d260c37e3580bChad Versace      }
3905c4c36f7f3842e287b303b1eca8d260c37e3580bChad Versace      if (ir->operands[0]->type->is_vector() &&
3915c4c36f7f3842e287b303b1eca8d260c37e3580bChad Versace          ir->operands[1]->type->is_vector()) {
3925c4c36f7f3842e287b303b1eca8d260c37e3580bChad Versace          assert(ir->operands[0]->type->components() ==
3935c4c36f7f3842e287b303b1eca8d260c37e3580bChad Versace                 ir->operands[1]->type->components());
3945c4c36f7f3842e287b303b1eca8d260c37e3580bChad Versace      }
3955c4c36f7f3842e287b303b1eca8d260c37e3580bChad Versace      assert(ir->type == ir->operands[0]->type);
3965c4c36f7f3842e287b303b1eca8d260c37e3580bChad Versace      break;
3975c4c36f7f3842e287b303b1eca8d260c37e3580bChad Versace
3985533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_binop_bit_and:
3995533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_binop_bit_xor:
4005533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_binop_bit_or:
401e2c1fe3eb0fa47f5501b4ec8cd6b732db7ca84beChad Versace       assert(ir->operands[0]->type->base_type ==
402e2c1fe3eb0fa47f5501b4ec8cd6b732db7ca84beChad Versace              ir->operands[1]->type->base_type);
403e2c1fe3eb0fa47f5501b4ec8cd6b732db7ca84beChad Versace       assert(ir->type->is_integer());
404e2c1fe3eb0fa47f5501b4ec8cd6b732db7ca84beChad Versace       if (ir->operands[0]->type->is_vector() &&
405e2c1fe3eb0fa47f5501b4ec8cd6b732db7ca84beChad Versace           ir->operands[1]->type->is_vector()) {
406e2c1fe3eb0fa47f5501b4ec8cd6b732db7ca84beChad Versace           assert(ir->operands[0]->type->vector_elements ==
407e2c1fe3eb0fa47f5501b4ec8cd6b732db7ca84beChad Versace                  ir->operands[1]->type->vector_elements);
408e2c1fe3eb0fa47f5501b4ec8cd6b732db7ca84beChad Versace       }
409e2c1fe3eb0fa47f5501b4ec8cd6b732db7ca84beChad Versace       break;
4105533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt
4115533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_binop_logic_and:
4125533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_binop_logic_xor:
4135533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_binop_logic_or:
4145533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->type == glsl_type::bool_type);
4155533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->operands[0]->type == glsl_type::bool_type);
4165533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->operands[1]->type == glsl_type::bool_type);
4175533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      break;
4185533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt
4195533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_binop_dot:
4205533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->type == glsl_type::float_type);
4215533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT);
422368dc76f04e19f5070d1f41795ea8cde2964639fKenneth Graunke      assert(ir->operands[0]->type->is_vector());
4235533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->operands[0]->type == ir->operands[1]->type);
4245533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      break;
42511d6f1c69871d0b7edc28f639256460839fccd2dIan Romanick
4262ea3ab14f2182978f471674c9dfce029d37f70a7Eric Anholt   case ir_binop_ubo_load:
4272ea3ab14f2182978f471674c9dfce029d37f70a7Eric Anholt      assert(ir->operands[0]->as_constant());
4282ea3ab14f2182978f471674c9dfce029d37f70a7Eric Anholt      assert(ir->operands[0]->type == glsl_type::uint_type);
4292ea3ab14f2182978f471674c9dfce029d37f70a7Eric Anholt
4302ea3ab14f2182978f471674c9dfce029d37f70a7Eric Anholt      assert(ir->operands[1]->type == glsl_type::uint_type);
4312ea3ab14f2182978f471674c9dfce029d37f70a7Eric Anholt      break;
4322ea3ab14f2182978f471674c9dfce029d37f70a7Eric Anholt
43311d6f1c69871d0b7edc28f639256460839fccd2dIan Romanick   case ir_quadop_vector:
43411d6f1c69871d0b7edc28f639256460839fccd2dIan Romanick      /* The vector operator collects some number of scalars and generates a
43511d6f1c69871d0b7edc28f639256460839fccd2dIan Romanick       * vector from them.
43611d6f1c69871d0b7edc28f639256460839fccd2dIan Romanick       *
43711d6f1c69871d0b7edc28f639256460839fccd2dIan Romanick       *  - All of the operands must be scalar.
43811d6f1c69871d0b7edc28f639256460839fccd2dIan Romanick       *  - Number of operands must matche the size of the resulting vector.
43911d6f1c69871d0b7edc28f639256460839fccd2dIan Romanick       *  - Base type of the operands must match the base type of the result.
44011d6f1c69871d0b7edc28f639256460839fccd2dIan Romanick       */
44111d6f1c69871d0b7edc28f639256460839fccd2dIan Romanick      assert(ir->type->is_vector());
44211d6f1c69871d0b7edc28f639256460839fccd2dIan Romanick      switch (ir->type->vector_elements) {
44311d6f1c69871d0b7edc28f639256460839fccd2dIan Romanick      case 2:
44411d6f1c69871d0b7edc28f639256460839fccd2dIan Romanick	 assert(ir->operands[0]->type->is_scalar());
44511d6f1c69871d0b7edc28f639256460839fccd2dIan Romanick	 assert(ir->operands[0]->type->base_type == ir->type->base_type);
44611d6f1c69871d0b7edc28f639256460839fccd2dIan Romanick	 assert(ir->operands[1]->type->is_scalar());
44711d6f1c69871d0b7edc28f639256460839fccd2dIan Romanick	 assert(ir->operands[1]->type->base_type == ir->type->base_type);
44811d6f1c69871d0b7edc28f639256460839fccd2dIan Romanick	 assert(ir->operands[2] == NULL);
44911d6f1c69871d0b7edc28f639256460839fccd2dIan Romanick	 assert(ir->operands[3] == NULL);
45011d6f1c69871d0b7edc28f639256460839fccd2dIan Romanick	 break;
45111d6f1c69871d0b7edc28f639256460839fccd2dIan Romanick      case 3:
45211d6f1c69871d0b7edc28f639256460839fccd2dIan Romanick	 assert(ir->operands[0]->type->is_scalar());
45311d6f1c69871d0b7edc28f639256460839fccd2dIan Romanick	 assert(ir->operands[0]->type->base_type == ir->type->base_type);
45411d6f1c69871d0b7edc28f639256460839fccd2dIan Romanick	 assert(ir->operands[1]->type->is_scalar());
45511d6f1c69871d0b7edc28f639256460839fccd2dIan Romanick	 assert(ir->operands[1]->type->base_type == ir->type->base_type);
45611d6f1c69871d0b7edc28f639256460839fccd2dIan Romanick	 assert(ir->operands[2]->type->is_scalar());
45711d6f1c69871d0b7edc28f639256460839fccd2dIan Romanick	 assert(ir->operands[2]->type->base_type == ir->type->base_type);
45811d6f1c69871d0b7edc28f639256460839fccd2dIan Romanick	 assert(ir->operands[3] == NULL);
45911d6f1c69871d0b7edc28f639256460839fccd2dIan Romanick	 break;
46011d6f1c69871d0b7edc28f639256460839fccd2dIan Romanick      case 4:
46111d6f1c69871d0b7edc28f639256460839fccd2dIan Romanick	 assert(ir->operands[0]->type->is_scalar());
46211d6f1c69871d0b7edc28f639256460839fccd2dIan Romanick	 assert(ir->operands[0]->type->base_type == ir->type->base_type);
46311d6f1c69871d0b7edc28f639256460839fccd2dIan Romanick	 assert(ir->operands[1]->type->is_scalar());
46411d6f1c69871d0b7edc28f639256460839fccd2dIan Romanick	 assert(ir->operands[1]->type->base_type == ir->type->base_type);
46511d6f1c69871d0b7edc28f639256460839fccd2dIan Romanick	 assert(ir->operands[2]->type->is_scalar());
46611d6f1c69871d0b7edc28f639256460839fccd2dIan Romanick	 assert(ir->operands[2]->type->base_type == ir->type->base_type);
46711d6f1c69871d0b7edc28f639256460839fccd2dIan Romanick	 assert(ir->operands[3]->type->is_scalar());
46811d6f1c69871d0b7edc28f639256460839fccd2dIan Romanick	 assert(ir->operands[3]->type->base_type == ir->type->base_type);
46911d6f1c69871d0b7edc28f639256460839fccd2dIan Romanick	 break;
47011d6f1c69871d0b7edc28f639256460839fccd2dIan Romanick      default:
47111d6f1c69871d0b7edc28f639256460839fccd2dIan Romanick	 /* The is_vector assertion above should prevent execution from ever
47211d6f1c69871d0b7edc28f639256460839fccd2dIan Romanick	  * getting here.
47311d6f1c69871d0b7edc28f639256460839fccd2dIan Romanick	  */
47411d6f1c69871d0b7edc28f639256460839fccd2dIan Romanick	 assert(!"Should not get here.");
47511d6f1c69871d0b7edc28f639256460839fccd2dIan Romanick	 break;
47611d6f1c69871d0b7edc28f639256460839fccd2dIan Romanick      }
4775533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   }
4785533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt
4795533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   return visit_continue;
4805533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt}
4815533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt
4825533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholtir_visitor_status
4835e8ed7a79b381d559b059987bd99c68d40f641caEric Anholtir_validate::visit_leave(ir_swizzle *ir)
4845e8ed7a79b381d559b059987bd99c68d40f641caEric Anholt{
485ba3a4d79a7bad959c0d9efbe0daa8d73c281d664Dave Airlie   unsigned int chans[4] = {ir->mask.x, ir->mask.y, ir->mask.z, ir->mask.w};
4865e8ed7a79b381d559b059987bd99c68d40f641caEric Anholt
4875e8ed7a79b381d559b059987bd99c68d40f641caEric Anholt   for (unsigned int i = 0; i < ir->type->vector_elements; i++) {
4885e8ed7a79b381d559b059987bd99c68d40f641caEric Anholt      if (chans[i] >= ir->val->type->vector_elements) {
4895e8ed7a79b381d559b059987bd99c68d40f641caEric Anholt	 printf("ir_swizzle @ %p specifies a channel not present "
4905e8ed7a79b381d559b059987bd99c68d40f641caEric Anholt		"in the value.\n", (void *) ir);
4915e8ed7a79b381d559b059987bd99c68d40f641caEric Anholt	 ir->print();
4925e8ed7a79b381d559b059987bd99c68d40f641caEric Anholt	 abort();
4935e8ed7a79b381d559b059987bd99c68d40f641caEric Anholt      }
4945e8ed7a79b381d559b059987bd99c68d40f641caEric Anholt   }
4955e8ed7a79b381d559b059987bd99c68d40f641caEric Anholt
4965e8ed7a79b381d559b059987bd99c68d40f641caEric Anholt   return visit_continue;
4975e8ed7a79b381d559b059987bd99c68d40f641caEric Anholt}
4985e8ed7a79b381d559b059987bd99c68d40f641caEric Anholt
4995e8ed7a79b381d559b059987bd99c68d40f641caEric Anholtir_visitor_status
500865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanickir_validate::visit(ir_variable *ir)
50153cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt{
502865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanick   /* An ir_variable is the one thing that can (and will) appear multiple times
5038baf21b1a4d50efca086679cc43bb0cfc3fee03aIan Romanick    * in an IR tree.  It is added to the hashtable so that it can be used
5048baf21b1a4d50efca086679cc43bb0cfc3fee03aIan Romanick    * in the ir_dereference_variable handler to ensure that a variable is
5058baf21b1a4d50efca086679cc43bb0cfc3fee03aIan Romanick    * declared before it is dereferenced.
506865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanick    */
507c22dee721695402d9f2678c100d2fff5c0c3f21fEric Anholt   if (ir->name)
508d3073f58c17d8675a2ecdd5dfa83e5520c78e1a8Kenneth Graunke      assert(ralloc_parent(ir->name) == ir);
509ee7666b5ac2fc7de64baf60835271e15baf89474Eric Anholt
5108baf21b1a4d50efca086679cc43bb0cfc3fee03aIan Romanick   hash_table_insert(ht, ir, ir);
511bc83f6bd585bba6dee3fa2264d32ab59e9a9c99eIan Romanick
512bc83f6bd585bba6dee3fa2264d32ab59e9a9c99eIan Romanick
513bc83f6bd585bba6dee3fa2264d32ab59e9a9c99eIan Romanick   /* If a variable is an array, verify that the maximum array index is in
514bc83f6bd585bba6dee3fa2264d32ab59e9a9c99eIan Romanick    * bounds.  There was once an error in AST-to-HIR conversion that set this
515bc83f6bd585bba6dee3fa2264d32ab59e9a9c99eIan Romanick    * to be out of bounds.
516bc83f6bd585bba6dee3fa2264d32ab59e9a9c99eIan Romanick    */
517bc83f6bd585bba6dee3fa2264d32ab59e9a9c99eIan Romanick   if (ir->type->array_size() > 0) {
518bc83f6bd585bba6dee3fa2264d32ab59e9a9c99eIan Romanick      if (ir->max_array_access >= ir->type->length) {
519bc83f6bd585bba6dee3fa2264d32ab59e9a9c99eIan Romanick	 printf("ir_variable has maximum access out of bounds (%d vs %d)\n",
520bc83f6bd585bba6dee3fa2264d32ab59e9a9c99eIan Romanick		ir->max_array_access, ir->type->length - 1);
521bc83f6bd585bba6dee3fa2264d32ab59e9a9c99eIan Romanick	 ir->print();
522bc83f6bd585bba6dee3fa2264d32ab59e9a9c99eIan Romanick	 abort();
523bc83f6bd585bba6dee3fa2264d32ab59e9a9c99eIan Romanick      }
524bc83f6bd585bba6dee3fa2264d32ab59e9a9c99eIan Romanick   }
525bc83f6bd585bba6dee3fa2264d32ab59e9a9c99eIan Romanick
526f37b1ad937dd2c420f4c9fd9aa5887942bd31f3fIan Romanick   if (ir->constant_initializer != NULL && !ir->has_initializer) {
527f37b1ad937dd2c420f4c9fd9aa5887942bd31f3fIan Romanick      printf("ir_variable didn't have an initializer, but has a constant "
528f37b1ad937dd2c420f4c9fd9aa5887942bd31f3fIan Romanick	     "initializer value.\n");
529f37b1ad937dd2c420f4c9fd9aa5887942bd31f3fIan Romanick      ir->print();
530f37b1ad937dd2c420f4c9fd9aa5887942bd31f3fIan Romanick      abort();
531f37b1ad937dd2c420f4c9fd9aa5887942bd31f3fIan Romanick   }
532f37b1ad937dd2c420f4c9fd9aa5887942bd31f3fIan Romanick
53353cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt   return visit_continue;
53453cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt}
53553cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt
5366235c6a83855fe2818affda3c82e1a245bd0232eIan Romanickir_visitor_status
5376235c6a83855fe2818affda3c82e1a245bd0232eIan Romanickir_validate::visit_enter(ir_assignment *ir)
5386235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick{
5396235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick   const ir_dereference *const lhs = ir->lhs;
5406235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick   if (lhs->type->is_scalar() || lhs->type->is_vector()) {
5416235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick      if (ir->write_mask == 0) {
5426235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick	 printf("Assignment LHS is %s, but write mask is 0:\n",
5436235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick		lhs->type->is_scalar() ? "scalar" : "vector");
5446235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick	 ir->print();
5456235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick	 abort();
5466235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick      }
5476235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick
548b39e6f33b60ef9bbaf81f320aaca6a440d8a6a8fEric Anholt      int lhs_components = 0;
549b39e6f33b60ef9bbaf81f320aaca6a440d8a6a8fEric Anholt      for (int i = 0; i < 4; i++) {
550b39e6f33b60ef9bbaf81f320aaca6a440d8a6a8fEric Anholt	 if (ir->write_mask & (1 << i))
551b39e6f33b60ef9bbaf81f320aaca6a440d8a6a8fEric Anholt	    lhs_components++;
552b39e6f33b60ef9bbaf81f320aaca6a440d8a6a8fEric Anholt      }
5536235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick
554b39e6f33b60ef9bbaf81f320aaca6a440d8a6a8fEric Anholt      if (lhs_components != ir->rhs->type->vector_elements) {
555b39e6f33b60ef9bbaf81f320aaca6a440d8a6a8fEric Anholt	 printf("Assignment count of LHS write mask channels enabled not\n"
556b39e6f33b60ef9bbaf81f320aaca6a440d8a6a8fEric Anholt		"matching RHS vector size (%d LHS, %d RHS).\n",
557b39e6f33b60ef9bbaf81f320aaca6a440d8a6a8fEric Anholt		lhs_components, ir->rhs->type->vector_elements);
5586235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick	 ir->print();
5596235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick	 abort();
5606235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick      }
5616235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick   }
5626235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick
5636235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick   this->validate_ir(ir, this->data);
5646235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick
5656235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick   return visit_continue;
5666235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick}
5676235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick
5688bbfbb14eee53e42a488ba24c0cfc9ffa1cf6318Ian Romanickir_visitor_status
5698bbfbb14eee53e42a488ba24c0cfc9ffa1cf6318Ian Romanickir_validate::visit_enter(ir_call *ir)
5708bbfbb14eee53e42a488ba24c0cfc9ffa1cf6318Ian Romanick{
57182065fa20ee3f2880a070f1f4f75509b910ceddeKenneth Graunke   ir_function_signature *const callee = ir->callee;
5728bbfbb14eee53e42a488ba24c0cfc9ffa1cf6318Ian Romanick
5738bbfbb14eee53e42a488ba24c0cfc9ffa1cf6318Ian Romanick   if (callee->ir_type != ir_type_function_signature) {
5748bbfbb14eee53e42a488ba24c0cfc9ffa1cf6318Ian Romanick      printf("IR called by ir_call is not ir_function_signature!\n");
5758bbfbb14eee53e42a488ba24c0cfc9ffa1cf6318Ian Romanick      abort();
5768bbfbb14eee53e42a488ba24c0cfc9ffa1cf6318Ian Romanick   }
5778bbfbb14eee53e42a488ba24c0cfc9ffa1cf6318Ian Romanick
578d884f60861f270cdcf7d9d47765efcf1e1de30b6Kenneth Graunke   if (ir->return_deref) {
579d884f60861f270cdcf7d9d47765efcf1e1de30b6Kenneth Graunke      if (ir->return_deref->type != callee->return_type) {
580d884f60861f270cdcf7d9d47765efcf1e1de30b6Kenneth Graunke	 printf("callee type %s does not match return storage type %s\n",
581d884f60861f270cdcf7d9d47765efcf1e1de30b6Kenneth Graunke	        callee->return_type->name, ir->return_deref->type->name);
582d884f60861f270cdcf7d9d47765efcf1e1de30b6Kenneth Graunke	 abort();
583d884f60861f270cdcf7d9d47765efcf1e1de30b6Kenneth Graunke      }
584d884f60861f270cdcf7d9d47765efcf1e1de30b6Kenneth Graunke   } else if (callee->return_type != glsl_type::void_type) {
585d884f60861f270cdcf7d9d47765efcf1e1de30b6Kenneth Graunke      printf("ir_call has non-void callee but no return storage\n");
586d884f60861f270cdcf7d9d47765efcf1e1de30b6Kenneth Graunke      abort();
587d884f60861f270cdcf7d9d47765efcf1e1de30b6Kenneth Graunke   }
588d884f60861f270cdcf7d9d47765efcf1e1de30b6Kenneth Graunke
589303e05cc249df3baeb3ed7654b0de00e7b9358fcPaul Berry   const exec_node *formal_param_node = callee->parameters.head;
590303e05cc249df3baeb3ed7654b0de00e7b9358fcPaul Berry   const exec_node *actual_param_node = ir->actual_parameters.head;
591303e05cc249df3baeb3ed7654b0de00e7b9358fcPaul Berry   while (true) {
592303e05cc249df3baeb3ed7654b0de00e7b9358fcPaul Berry      if (formal_param_node->is_tail_sentinel()
593303e05cc249df3baeb3ed7654b0de00e7b9358fcPaul Berry          != actual_param_node->is_tail_sentinel()) {
594303e05cc249df3baeb3ed7654b0de00e7b9358fcPaul Berry         printf("ir_call has the wrong number of parameters:\n");
595303e05cc249df3baeb3ed7654b0de00e7b9358fcPaul Berry         goto dump_ir;
596303e05cc249df3baeb3ed7654b0de00e7b9358fcPaul Berry      }
597303e05cc249df3baeb3ed7654b0de00e7b9358fcPaul Berry      if (formal_param_node->is_tail_sentinel()) {
598303e05cc249df3baeb3ed7654b0de00e7b9358fcPaul Berry         break;
599303e05cc249df3baeb3ed7654b0de00e7b9358fcPaul Berry      }
600303e05cc249df3baeb3ed7654b0de00e7b9358fcPaul Berry      const ir_variable *formal_param
601303e05cc249df3baeb3ed7654b0de00e7b9358fcPaul Berry         = (const ir_variable *) formal_param_node;
602303e05cc249df3baeb3ed7654b0de00e7b9358fcPaul Berry      const ir_rvalue *actual_param
603303e05cc249df3baeb3ed7654b0de00e7b9358fcPaul Berry         = (const ir_rvalue *) actual_param_node;
604303e05cc249df3baeb3ed7654b0de00e7b9358fcPaul Berry      if (formal_param->type != actual_param->type) {
605303e05cc249df3baeb3ed7654b0de00e7b9358fcPaul Berry         printf("ir_call parameter type mismatch:\n");
606303e05cc249df3baeb3ed7654b0de00e7b9358fcPaul Berry         goto dump_ir;
607303e05cc249df3baeb3ed7654b0de00e7b9358fcPaul Berry      }
608303e05cc249df3baeb3ed7654b0de00e7b9358fcPaul Berry      if (formal_param->mode == ir_var_out
609303e05cc249df3baeb3ed7654b0de00e7b9358fcPaul Berry          || formal_param->mode == ir_var_inout) {
610303e05cc249df3baeb3ed7654b0de00e7b9358fcPaul Berry         if (!actual_param->is_lvalue()) {
611303e05cc249df3baeb3ed7654b0de00e7b9358fcPaul Berry            printf("ir_call out/inout parameters must be lvalues:\n");
612303e05cc249df3baeb3ed7654b0de00e7b9358fcPaul Berry            goto dump_ir;
613303e05cc249df3baeb3ed7654b0de00e7b9358fcPaul Berry         }
614303e05cc249df3baeb3ed7654b0de00e7b9358fcPaul Berry      }
615303e05cc249df3baeb3ed7654b0de00e7b9358fcPaul Berry      formal_param_node = formal_param_node->next;
616303e05cc249df3baeb3ed7654b0de00e7b9358fcPaul Berry      actual_param_node = actual_param_node->next;
617303e05cc249df3baeb3ed7654b0de00e7b9358fcPaul Berry   }
618303e05cc249df3baeb3ed7654b0de00e7b9358fcPaul Berry
6198bbfbb14eee53e42a488ba24c0cfc9ffa1cf6318Ian Romanick   return visit_continue;
620303e05cc249df3baeb3ed7654b0de00e7b9358fcPaul Berry
621303e05cc249df3baeb3ed7654b0de00e7b9358fcPaul Berrydump_ir:
622303e05cc249df3baeb3ed7654b0de00e7b9358fcPaul Berry   ir->print();
623303e05cc249df3baeb3ed7654b0de00e7b9358fcPaul Berry   printf("callee:\n");
624303e05cc249df3baeb3ed7654b0de00e7b9358fcPaul Berry   callee->print();
625303e05cc249df3baeb3ed7654b0de00e7b9358fcPaul Berry   abort();
62698ebe833fea8060ae2b0211e4fe9990f0670bb20Brian Paul   return visit_stop;
6278bbfbb14eee53e42a488ba24c0cfc9ffa1cf6318Ian Romanick}
6288bbfbb14eee53e42a488ba24c0cfc9ffa1cf6318Ian Romanick
629865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanickvoid
630865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanickir_validate::validate_ir(ir_instruction *ir, void *data)
63153cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt{
632865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanick   struct hash_table *ht = (struct hash_table *) data;
63353cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt
634865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanick   if (hash_table_find(ht, ir)) {
635865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanick      printf("Instruction node present twice in ir tree:\n");
636865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanick      ir->print();
637865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanick      printf("\n");
638865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanick      abort();
639865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanick   }
640865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanick   hash_table_insert(ht, ir, ir);
64153cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt}
64253cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt
64353cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholtvoid
644d16044ad4d6176fec6164f96450a25f76b7677f1Eric Anholtcheck_node_type(ir_instruction *ir, void *data)
645d16044ad4d6176fec6164f96450a25f76b7677f1Eric Anholt{
6467ffe40532f6b22d9b80caeac0fc3b9495619186aIan Romanick   (void) data;
6477ffe40532f6b22d9b80caeac0fc3b9495619186aIan Romanick
648d16044ad4d6176fec6164f96450a25f76b7677f1Eric Anholt   if (ir->ir_type <= ir_type_unset || ir->ir_type >= ir_type_max) {
649d16044ad4d6176fec6164f96450a25f76b7677f1Eric Anholt      printf("Instruction node with unset type\n");
650d16044ad4d6176fec6164f96450a25f76b7677f1Eric Anholt      ir->print(); printf("\n");
651d16044ad4d6176fec6164f96450a25f76b7677f1Eric Anholt   }
652f75c2d53146ea14f8dfedcc5b7a4704278ba0792Kenneth Graunke   ir_rvalue *value = ir->as_rvalue();
653f75c2d53146ea14f8dfedcc5b7a4704278ba0792Kenneth Graunke   if (value != NULL)
654f75c2d53146ea14f8dfedcc5b7a4704278ba0792Kenneth Graunke      assert(value->type != glsl_type::error_type);
655d16044ad4d6176fec6164f96450a25f76b7677f1Eric Anholt}
656d16044ad4d6176fec6164f96450a25f76b7677f1Eric Anholt
657d16044ad4d6176fec6164f96450a25f76b7677f1Eric Anholtvoid
65853cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholtvalidate_ir_tree(exec_list *instructions)
65953cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt{
66053cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt   ir_validate v;
66153cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt
66253cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt   v.run(instructions);
663d16044ad4d6176fec6164f96450a25f76b7677f1Eric Anholt
664d16044ad4d6176fec6164f96450a25f76b7677f1Eric Anholt   foreach_iter(exec_list_iterator, iter, *instructions) {
665d16044ad4d6176fec6164f96450a25f76b7677f1Eric Anholt      ir_instruction *ir = (ir_instruction *)iter.get();
666d16044ad4d6176fec6164f96450a25f76b7677f1Eric Anholt
667d16044ad4d6176fec6164f96450a25f76b7677f1Eric Anholt      visit_tree(ir, check_node_type, NULL);
668d16044ad4d6176fec6164f96450a25f76b7677f1Eric Anholt   }
66953cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt}
670