ir_validate.cpp revision 4dfb89904c0a3d2166e9a3fc0253a254680e91bc
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
369349379d1acca23e7a2442549e49e9b58515d731José Fonseca#include <inttypes.h>
3753cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt#include "ir.h"
38865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanick#include "ir_hierarchical_visitor.h"
3931747155ea3a24190277b125bd188ac8689af719Aras Pranckevicius#include "program/hash_table.h"
40f141fa63a4391621cc92cd2c39724a952b297a58Eric Anholt#include "glsl_types.h"
4153cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt
42865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanickclass ir_validate : public ir_hierarchical_visitor {
43865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanickpublic:
44865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanick   ir_validate()
45865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanick   {
46d1a1ee583e7e8338243b3e9768d2fc5312a1145dIan Romanick      this->ht = hash_table_ctor(0, hash_table_pointer_hash,
47d1a1ee583e7e8338243b3e9768d2fc5312a1145dIan Romanick				 hash_table_pointer_compare);
4853cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt
49c67016de960c988c748ffdb11247072543a8f328Ian Romanick      this->current_function = NULL;
50c67016de960c988c748ffdb11247072543a8f328Ian Romanick
51865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanick      this->callback = ir_validate::validate_ir;
52865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanick      this->data = ht;
53865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanick   }
5453cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt
55865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanick   ~ir_validate()
56865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanick   {
57865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanick      hash_table_dtor(this->ht);
58865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanick   }
5953cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt
60865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanick   virtual ir_visitor_status visit(ir_variable *v);
618baf21b1a4d50efca086679cc43bb0cfc3fee03aIan Romanick   virtual ir_visitor_status visit(ir_dereference_variable *ir);
62432b787b29202301dbfc139c3289521b0bfc3decEric Anholt   virtual ir_visitor_status visit(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);
705533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt
716235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick   virtual ir_visitor_status visit_enter(ir_assignment *ir);
726235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick
73865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanick   static void validate_ir(ir_instruction *ir, void *data);
7453cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt
75c67016de960c988c748ffdb11247072543a8f328Ian Romanick   ir_function *current_function;
76c67016de960c988c748ffdb11247072543a8f328Ian Romanick
77865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanick   struct hash_table *ht;
78865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanick};
7953cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt
808baf21b1a4d50efca086679cc43bb0cfc3fee03aIan Romanick
818baf21b1a4d50efca086679cc43bb0cfc3fee03aIan Romanickir_visitor_status
828baf21b1a4d50efca086679cc43bb0cfc3fee03aIan Romanickir_validate::visit(ir_dereference_variable *ir)
838baf21b1a4d50efca086679cc43bb0cfc3fee03aIan Romanick{
848baf21b1a4d50efca086679cc43bb0cfc3fee03aIan Romanick   if ((ir->var == NULL) || (ir->var->as_variable() == NULL)) {
858baf21b1a4d50efca086679cc43bb0cfc3fee03aIan Romanick      printf("ir_dereference_variable @ %p does not specify a variable %p\n",
869f9386d22aca8d14d1b1e6d4de9b24dcb183ca10Brian Paul	     (void *) ir, (void *) ir->var);
878baf21b1a4d50efca086679cc43bb0cfc3fee03aIan Romanick      abort();
888baf21b1a4d50efca086679cc43bb0cfc3fee03aIan Romanick   }
898baf21b1a4d50efca086679cc43bb0cfc3fee03aIan Romanick
908baf21b1a4d50efca086679cc43bb0cfc3fee03aIan Romanick   if (hash_table_find(ht, ir->var) == NULL) {
918baf21b1a4d50efca086679cc43bb0cfc3fee03aIan Romanick      printf("ir_dereference_variable @ %p specifies undeclared variable "
928baf21b1a4d50efca086679cc43bb0cfc3fee03aIan Romanick	     "`%s' @ %p\n",
939f9386d22aca8d14d1b1e6d4de9b24dcb183ca10Brian Paul	     (void *) ir, ir->var->name, (void *) ir->var);
948baf21b1a4d50efca086679cc43bb0cfc3fee03aIan Romanick      abort();
958baf21b1a4d50efca086679cc43bb0cfc3fee03aIan Romanick   }
968baf21b1a4d50efca086679cc43bb0cfc3fee03aIan Romanick
97506880bc32e7bb98fd1896a9b2fe3614abab904fIan Romanick   this->validate_ir(ir, this->data);
98506880bc32e7bb98fd1896a9b2fe3614abab904fIan Romanick
998baf21b1a4d50efca086679cc43bb0cfc3fee03aIan Romanick   return visit_continue;
1008baf21b1a4d50efca086679cc43bb0cfc3fee03aIan Romanick}
1018baf21b1a4d50efca086679cc43bb0cfc3fee03aIan Romanick
102432b787b29202301dbfc139c3289521b0bfc3decEric Anholtir_visitor_status
103432b787b29202301dbfc139c3289521b0bfc3decEric Anholtir_validate::visit(ir_if *ir)
104432b787b29202301dbfc139c3289521b0bfc3decEric Anholt{
105432b787b29202301dbfc139c3289521b0bfc3decEric Anholt   if (ir->condition->type != glsl_type::bool_type) {
106432b787b29202301dbfc139c3289521b0bfc3decEric Anholt      printf("ir_if condition %s type instead of bool.\n",
107432b787b29202301dbfc139c3289521b0bfc3decEric Anholt	     ir->condition->type->name);
108432b787b29202301dbfc139c3289521b0bfc3decEric Anholt      ir->print();
109432b787b29202301dbfc139c3289521b0bfc3decEric Anholt      printf("\n");
110432b787b29202301dbfc139c3289521b0bfc3decEric Anholt      abort();
111432b787b29202301dbfc139c3289521b0bfc3decEric Anholt   }
1126a1401eb889b5e535c212c414743cc7ea07f6622Eric Anholt
1136a1401eb889b5e535c212c414743cc7ea07f6622Eric Anholt   return visit_continue;
114432b787b29202301dbfc139c3289521b0bfc3decEric Anholt}
115432b787b29202301dbfc139c3289521b0bfc3decEric Anholt
1168baf21b1a4d50efca086679cc43bb0cfc3fee03aIan Romanick
11753cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholtir_visitor_status
11853acbd87d712555f9e7a1c304843be7b39641413Ian Romanickir_validate::visit_leave(ir_loop *ir)
11953acbd87d712555f9e7a1c304843be7b39641413Ian Romanick{
12053acbd87d712555f9e7a1c304843be7b39641413Ian Romanick   if (ir->counter != NULL) {
12153acbd87d712555f9e7a1c304843be7b39641413Ian Romanick      if ((ir->from == NULL) || (ir->from == NULL) || (ir->increment == NULL)) {
12253acbd87d712555f9e7a1c304843be7b39641413Ian Romanick	 printf("ir_loop has invalid loop controls:\n"
12353acbd87d712555f9e7a1c304843be7b39641413Ian Romanick		"    counter:   %p\n"
12453acbd87d712555f9e7a1c304843be7b39641413Ian Romanick		"    from:      %p\n"
12553acbd87d712555f9e7a1c304843be7b39641413Ian Romanick		"    to:        %p\n"
12653acbd87d712555f9e7a1c304843be7b39641413Ian Romanick		"    increment: %p\n",
12753acbd87d712555f9e7a1c304843be7b39641413Ian Romanick		ir->counter, ir->from, ir->to, ir->increment);
12853acbd87d712555f9e7a1c304843be7b39641413Ian Romanick	 abort();
12953acbd87d712555f9e7a1c304843be7b39641413Ian Romanick      }
13053acbd87d712555f9e7a1c304843be7b39641413Ian Romanick
13153acbd87d712555f9e7a1c304843be7b39641413Ian Romanick      if ((ir->cmp < ir_binop_less) || (ir->cmp > ir_binop_nequal)) {
13253acbd87d712555f9e7a1c304843be7b39641413Ian Romanick	 printf("ir_loop has invalid comparitor %d\n", ir->cmp);
13353acbd87d712555f9e7a1c304843be7b39641413Ian Romanick	 abort();
13453acbd87d712555f9e7a1c304843be7b39641413Ian Romanick      }
13553acbd87d712555f9e7a1c304843be7b39641413Ian Romanick   } else {
13653acbd87d712555f9e7a1c304843be7b39641413Ian Romanick      if ((ir->from != NULL) || (ir->from != NULL) || (ir->increment != NULL)) {
13753acbd87d712555f9e7a1c304843be7b39641413Ian Romanick	 printf("ir_loop has invalid loop controls:\n"
13853acbd87d712555f9e7a1c304843be7b39641413Ian Romanick		"    counter:   %p\n"
13953acbd87d712555f9e7a1c304843be7b39641413Ian Romanick		"    from:      %p\n"
14053acbd87d712555f9e7a1c304843be7b39641413Ian Romanick		"    to:        %p\n"
14153acbd87d712555f9e7a1c304843be7b39641413Ian Romanick		"    increment: %p\n",
14253acbd87d712555f9e7a1c304843be7b39641413Ian Romanick		ir->counter, ir->from, ir->to, ir->increment);
14353acbd87d712555f9e7a1c304843be7b39641413Ian Romanick	 abort();
14453acbd87d712555f9e7a1c304843be7b39641413Ian Romanick      }
14553acbd87d712555f9e7a1c304843be7b39641413Ian Romanick   }
14653acbd87d712555f9e7a1c304843be7b39641413Ian Romanick
14753acbd87d712555f9e7a1c304843be7b39641413Ian Romanick   return visit_continue;
14853acbd87d712555f9e7a1c304843be7b39641413Ian Romanick}
14953acbd87d712555f9e7a1c304843be7b39641413Ian Romanick
15053acbd87d712555f9e7a1c304843be7b39641413Ian Romanick
15153acbd87d712555f9e7a1c304843be7b39641413Ian Romanickir_visitor_status
152c67016de960c988c748ffdb11247072543a8f328Ian Romanickir_validate::visit_enter(ir_function *ir)
153c67016de960c988c748ffdb11247072543a8f328Ian Romanick{
154c67016de960c988c748ffdb11247072543a8f328Ian Romanick   /* Function definitions cannot be nested.
155c67016de960c988c748ffdb11247072543a8f328Ian Romanick    */
156c67016de960c988c748ffdb11247072543a8f328Ian Romanick   if (this->current_function != NULL) {
157c67016de960c988c748ffdb11247072543a8f328Ian Romanick      printf("Function definition nested inside another function "
158c67016de960c988c748ffdb11247072543a8f328Ian Romanick	     "definition:\n");
159c67016de960c988c748ffdb11247072543a8f328Ian Romanick      printf("%s %p inside %s %p\n",
1609f9386d22aca8d14d1b1e6d4de9b24dcb183ca10Brian Paul	     ir->name, (void *) ir,
1619f9386d22aca8d14d1b1e6d4de9b24dcb183ca10Brian Paul	     this->current_function->name, (void *) this->current_function);
162c67016de960c988c748ffdb11247072543a8f328Ian Romanick      abort();
163c67016de960c988c748ffdb11247072543a8f328Ian Romanick   }
164c67016de960c988c748ffdb11247072543a8f328Ian Romanick
165c67016de960c988c748ffdb11247072543a8f328Ian Romanick   /* Store the current function hierarchy being traversed.  This is used
166c67016de960c988c748ffdb11247072543a8f328Ian Romanick    * by the function signature visitor to ensure that the signatures are
167c67016de960c988c748ffdb11247072543a8f328Ian Romanick    * linked with the correct functions.
168c67016de960c988c748ffdb11247072543a8f328Ian Romanick    */
169c67016de960c988c748ffdb11247072543a8f328Ian Romanick   this->current_function = ir;
170c67016de960c988c748ffdb11247072543a8f328Ian Romanick
171c67016de960c988c748ffdb11247072543a8f328Ian Romanick   this->validate_ir(ir, this->data);
172c67016de960c988c748ffdb11247072543a8f328Ian Romanick
173c67016de960c988c748ffdb11247072543a8f328Ian Romanick   return visit_continue;
174c67016de960c988c748ffdb11247072543a8f328Ian Romanick}
175c67016de960c988c748ffdb11247072543a8f328Ian Romanick
176c67016de960c988c748ffdb11247072543a8f328Ian Romanickir_visitor_status
177c67016de960c988c748ffdb11247072543a8f328Ian Romanickir_validate::visit_leave(ir_function *ir)
178c67016de960c988c748ffdb11247072543a8f328Ian Romanick{
179ee7666b5ac2fc7de64baf60835271e15baf89474Eric Anholt   assert(talloc_parent(ir->name) == ir);
180c67016de960c988c748ffdb11247072543a8f328Ian Romanick
181c67016de960c988c748ffdb11247072543a8f328Ian Romanick   this->current_function = NULL;
182c67016de960c988c748ffdb11247072543a8f328Ian Romanick   return visit_continue;
183c67016de960c988c748ffdb11247072543a8f328Ian Romanick}
184c67016de960c988c748ffdb11247072543a8f328Ian Romanick
185c67016de960c988c748ffdb11247072543a8f328Ian Romanickir_visitor_status
186c67016de960c988c748ffdb11247072543a8f328Ian Romanickir_validate::visit_enter(ir_function_signature *ir)
187c67016de960c988c748ffdb11247072543a8f328Ian Romanick{
188c67016de960c988c748ffdb11247072543a8f328Ian Romanick   if (this->current_function != ir->function()) {
189c67016de960c988c748ffdb11247072543a8f328Ian Romanick      printf("Function signature nested inside wrong function "
190c67016de960c988c748ffdb11247072543a8f328Ian Romanick	     "definition:\n");
191c67016de960c988c748ffdb11247072543a8f328Ian Romanick      printf("%p inside %s %p instead of %s %p\n",
1929f9386d22aca8d14d1b1e6d4de9b24dcb183ca10Brian Paul	     (void *) ir,
1939f9386d22aca8d14d1b1e6d4de9b24dcb183ca10Brian Paul	     this->current_function->name, (void *) this->current_function,
1949f9386d22aca8d14d1b1e6d4de9b24dcb183ca10Brian Paul	     ir->function_name(), (void *) ir->function());
195c67016de960c988c748ffdb11247072543a8f328Ian Romanick      abort();
196c67016de960c988c748ffdb11247072543a8f328Ian Romanick   }
197c67016de960c988c748ffdb11247072543a8f328Ian Romanick
198c67016de960c988c748ffdb11247072543a8f328Ian Romanick   this->validate_ir(ir, this->data);
199c67016de960c988c748ffdb11247072543a8f328Ian Romanick
200c67016de960c988c748ffdb11247072543a8f328Ian Romanick   return visit_continue;
201c67016de960c988c748ffdb11247072543a8f328Ian Romanick}
202c67016de960c988c748ffdb11247072543a8f328Ian Romanick
203c67016de960c988c748ffdb11247072543a8f328Ian Romanickir_visitor_status
2045533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholtir_validate::visit_leave(ir_expression *ir)
2055533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt{
2065533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   switch (ir->operation) {
2075533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_bit_not:
2085533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->operands[0]->type == ir->type);
2095533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      break;
2105533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_logic_not:
211e75dbf66d011d76b6944dc4ee55e339ee285510cEric Anholt      assert(ir->type->base_type == GLSL_TYPE_BOOL);
212e75dbf66d011d76b6944dc4ee55e339ee285510cEric Anholt      assert(ir->operands[0]->type->base_type == GLSL_TYPE_BOOL);
2135533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      break;
2145533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt
2155533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_neg:
2165533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_abs:
2175533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_sign:
2185533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_rcp:
2195533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_rsq:
2205533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_sqrt:
221bc4034b243975089c06c4415d4e26edaaaec7a46Eric Anholt      assert(ir->type == ir->operands[0]->type);
222bc4034b243975089c06c4415d4e26edaaaec7a46Eric Anholt      break;
223bc4034b243975089c06c4415d4e26edaaaec7a46Eric Anholt
2245533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_exp:
2255533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_log:
2265533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_exp2:
2275533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_log2:
228bc4034b243975089c06c4415d4e26edaaaec7a46Eric Anholt      assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT);
2295533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->type == ir->operands[0]->type);
2305533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      break;
2315533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt
2325533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_f2i:
2335533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT);
2345533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->type->base_type == GLSL_TYPE_INT);
2355533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      break;
2365533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_i2f:
2375533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT);
2385533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->type->base_type == GLSL_TYPE_FLOAT);
2395533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      break;
2405533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_f2b:
2415533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT);
2425533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->type->base_type == GLSL_TYPE_BOOL);
2435533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      break;
2445533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_b2f:
2455533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->operands[0]->type->base_type == GLSL_TYPE_BOOL);
2465533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->type->base_type == GLSL_TYPE_FLOAT);
2475533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      break;
2485533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_i2b:
2495533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT);
2505533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->type->base_type == GLSL_TYPE_BOOL);
2515533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      break;
2525533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_b2i:
2535533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->operands[0]->type->base_type == GLSL_TYPE_BOOL);
2545533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->type->base_type == GLSL_TYPE_INT);
2555533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      break;
2565533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_u2f:
2575533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT);
2585533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->type->base_type == GLSL_TYPE_FLOAT);
2595533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      break;
2605533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt
2615e9ac94cc44ef4f97063d7b696411b2a4be16f36Eric Anholt   case ir_unop_any:
2625e9ac94cc44ef4f97063d7b696411b2a4be16f36Eric Anholt      assert(ir->operands[0]->type->base_type == GLSL_TYPE_BOOL);
2635e9ac94cc44ef4f97063d7b696411b2a4be16f36Eric Anholt      assert(ir->type == glsl_type::bool_type);
2645e9ac94cc44ef4f97063d7b696411b2a4be16f36Eric Anholt      break;
2655e9ac94cc44ef4f97063d7b696411b2a4be16f36Eric Anholt
2665533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_trunc:
2675533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_ceil:
2685533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_floor:
2695533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_fract:
2705533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_sin:
2715533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_cos:
2725533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_dFdx:
2735533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_unop_dFdy:
2745533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT);
2755533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->operands[0]->type == ir->type);
2765533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      break;
2775533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt
2785533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_binop_add:
2795533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_binop_sub:
2805533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_binop_mul:
2815533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_binop_div:
2825533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_binop_mod:
2835533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_binop_min:
2845533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_binop_max:
2855533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_binop_pow:
2865533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      if (ir->operands[0]->type->is_scalar())
2875533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt	 assert(ir->operands[1]->type == ir->type);
2885533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      else if (ir->operands[1]->type->is_scalar())
2895533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt	 assert(ir->operands[0]->type == ir->type);
2905533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      else if (ir->operands[0]->type->is_vector() &&
2915533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt	       ir->operands[1]->type->is_vector()) {
2925533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt	 assert(ir->operands[0]->type == ir->operands[1]->type);
2935533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt	 assert(ir->operands[0]->type == ir->type);
2945533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      }
2955533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      break;
2964dfb89904c0a3d2166e9a3fc0253a254680e91bcLuca Barbieri
2975533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_binop_less:
2985533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_binop_greater:
2995533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_binop_lequal:
3005533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_binop_gequal:
3014dfb89904c0a3d2166e9a3fc0253a254680e91bcLuca Barbieri   case ir_binop_equal:
3024dfb89904c0a3d2166e9a3fc0253a254680e91bcLuca Barbieri   case ir_binop_nequal:
3034dfb89904c0a3d2166e9a3fc0253a254680e91bcLuca Barbieri      /* The semantics of the IR operators differ from the GLSL <, >, <=, >=,
3044dfb89904c0a3d2166e9a3fc0253a254680e91bcLuca Barbieri       * ==, and != operators.  The IR operators perform a component-wise
3054dfb89904c0a3d2166e9a3fc0253a254680e91bcLuca Barbieri       * comparison on scalar or vector types and return a boolean scalar or
3064dfb89904c0a3d2166e9a3fc0253a254680e91bcLuca Barbieri       * vector type of the same size.
3075533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt       */
3084dfb89904c0a3d2166e9a3fc0253a254680e91bcLuca Barbieri      assert(ir->type->base_type == GLSL_TYPE_BOOL);
3095533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->operands[0]->type == ir->operands[1]->type);
3104dfb89904c0a3d2166e9a3fc0253a254680e91bcLuca Barbieri      assert(ir->operands[0]->type->is_vector()
3114dfb89904c0a3d2166e9a3fc0253a254680e91bcLuca Barbieri	     || ir->operands[0]->type->is_scalar());
3124dfb89904c0a3d2166e9a3fc0253a254680e91bcLuca Barbieri      assert(ir->operands[0]->type->vector_elements
3134dfb89904c0a3d2166e9a3fc0253a254680e91bcLuca Barbieri	     == ir->type->vector_elements);
3145533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      break;
3155533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt
3164dfb89904c0a3d2166e9a3fc0253a254680e91bcLuca Barbieri   case ir_binop_all_equal:
3174dfb89904c0a3d2166e9a3fc0253a254680e91bcLuca Barbieri   case ir_binop_any_nequal:
3184dfb89904c0a3d2166e9a3fc0253a254680e91bcLuca Barbieri      /* GLSL == and != operate on scalars, vectors, matrices and arrays, and
3194dfb89904c0a3d2166e9a3fc0253a254680e91bcLuca Barbieri       * return a scalar boolean.  The IR matches that.
3205533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt       */
3215533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->type == glsl_type::bool_type);
3225533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->operands[0]->type == ir->operands[1]->type);
3235533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      break;
3245533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt
3255533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_binop_lshift:
3265533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_binop_rshift:
3275533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_binop_bit_and:
3285533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_binop_bit_xor:
3295533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_binop_bit_or:
3305533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->operands[0]->type == ir->operands[1]->type);
3315533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->type == ir->operands[0]->type);
3325533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->type->base_type == GLSL_TYPE_INT ||
3335533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt	     ir->type->base_type == GLSL_TYPE_UINT);
3345533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      break;
3355533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt
3365533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_binop_logic_and:
3375533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_binop_logic_xor:
3385533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_binop_logic_or:
3395533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->type == glsl_type::bool_type);
3405533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->operands[0]->type == glsl_type::bool_type);
3415533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->operands[1]->type == glsl_type::bool_type);
3425533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      break;
3435533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt
3445533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_binop_dot:
3455533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->type == glsl_type::float_type);
3465533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT);
347368dc76f04e19f5070d1f41795ea8cde2964639fKenneth Graunke      assert(ir->operands[0]->type->is_vector());
3485533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->operands[0]->type == ir->operands[1]->type);
3495533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      break;
3505533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt
3515533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   case ir_binop_cross:
3525533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->operands[0]->type == glsl_type::vec3_type);
3535533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->operands[1]->type == glsl_type::vec3_type);
3545533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      assert(ir->type == glsl_type::vec3_type);
3555533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt      break;
3565533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   }
3575533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt
3585533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt   return visit_continue;
3595533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt}
3605533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholt
3615533c6e38030ff6e26375a1a4e4bfa9ab2204d4cEric Anholtir_visitor_status
362865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanickir_validate::visit(ir_variable *ir)
36353cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt{
364865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanick   /* An ir_variable is the one thing that can (and will) appear multiple times
3658baf21b1a4d50efca086679cc43bb0cfc3fee03aIan Romanick    * in an IR tree.  It is added to the hashtable so that it can be used
3668baf21b1a4d50efca086679cc43bb0cfc3fee03aIan Romanick    * in the ir_dereference_variable handler to ensure that a variable is
3678baf21b1a4d50efca086679cc43bb0cfc3fee03aIan Romanick    * declared before it is dereferenced.
368865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanick    */
369c22dee721695402d9f2678c100d2fff5c0c3f21fEric Anholt   if (ir->name)
370c22dee721695402d9f2678c100d2fff5c0c3f21fEric Anholt      assert(talloc_parent(ir->name) == ir);
371ee7666b5ac2fc7de64baf60835271e15baf89474Eric Anholt
3728baf21b1a4d50efca086679cc43bb0cfc3fee03aIan Romanick   hash_table_insert(ht, ir, ir);
37353cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt   return visit_continue;
37453cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt}
37553cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt
3766235c6a83855fe2818affda3c82e1a245bd0232eIan Romanickir_visitor_status
3776235c6a83855fe2818affda3c82e1a245bd0232eIan Romanickir_validate::visit_enter(ir_assignment *ir)
3786235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick{
3796235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick   const ir_dereference *const lhs = ir->lhs;
3806235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick   if (lhs->type->is_scalar() || lhs->type->is_vector()) {
3816235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick      if (ir->write_mask == 0) {
3826235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick	 printf("Assignment LHS is %s, but write mask is 0:\n",
3836235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick		lhs->type->is_scalar() ? "scalar" : "vector");
3846235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick	 ir->print();
3856235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick	 abort();
3866235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick      }
3876235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick
3886235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick      /* Mask of fields that do not exist in the destination.  These should
3896235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick       * not be written by the assignment.
3906235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick       */
3916235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick      const unsigned invalid_mask = ~((1U << lhs->type->components()) - 1);
3926235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick
3936235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick      if ((invalid_mask & ir->write_mask) != 0) {
3946235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick	 printf("Assignment write mask enables invalid components for "
3956235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick		"type %s:\n", lhs->type->name);
3966235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick	 ir->print();
3976235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick	 abort();
3986235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick      }
3996235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick   }
4006235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick
4016235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick   this->validate_ir(ir, this->data);
4026235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick
4036235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick   return visit_continue;
4046235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick}
4056235c6a83855fe2818affda3c82e1a245bd0232eIan Romanick
406865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanickvoid
407865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanickir_validate::validate_ir(ir_instruction *ir, void *data)
40853cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt{
409865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanick   struct hash_table *ht = (struct hash_table *) data;
41053cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt
411865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanick   if (hash_table_find(ht, ir)) {
412865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanick      printf("Instruction node present twice in ir tree:\n");
413865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanick      ir->print();
414865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanick      printf("\n");
415865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanick      abort();
416865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanick   }
417865cf2d1f5e499916d360a246ad85554f3ff5b02Ian Romanick   hash_table_insert(ht, ir, ir);
41853cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt}
41953cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt
42053cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholtvoid
421d16044ad4d6176fec6164f96450a25f76b7677f1Eric Anholtcheck_node_type(ir_instruction *ir, void *data)
422d16044ad4d6176fec6164f96450a25f76b7677f1Eric Anholt{
4237ffe40532f6b22d9b80caeac0fc3b9495619186aIan Romanick   (void) data;
4247ffe40532f6b22d9b80caeac0fc3b9495619186aIan Romanick
425d16044ad4d6176fec6164f96450a25f76b7677f1Eric Anholt   if (ir->ir_type <= ir_type_unset || ir->ir_type >= ir_type_max) {
426d16044ad4d6176fec6164f96450a25f76b7677f1Eric Anholt      printf("Instruction node with unset type\n");
427d16044ad4d6176fec6164f96450a25f76b7677f1Eric Anholt      ir->print(); printf("\n");
428d16044ad4d6176fec6164f96450a25f76b7677f1Eric Anholt   }
429f141fa63a4391621cc92cd2c39724a952b297a58Eric Anholt   assert(ir->type != glsl_type::error_type);
430d16044ad4d6176fec6164f96450a25f76b7677f1Eric Anholt}
431d16044ad4d6176fec6164f96450a25f76b7677f1Eric Anholt
432d16044ad4d6176fec6164f96450a25f76b7677f1Eric Anholtvoid
43353cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholtvalidate_ir_tree(exec_list *instructions)
43453cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt{
43553cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt   ir_validate v;
43653cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt
43753cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt   v.run(instructions);
438d16044ad4d6176fec6164f96450a25f76b7677f1Eric Anholt
439d16044ad4d6176fec6164f96450a25f76b7677f1Eric Anholt   foreach_iter(exec_list_iterator, iter, *instructions) {
440d16044ad4d6176fec6164f96450a25f76b7677f1Eric Anholt      ir_instruction *ir = (ir_instruction *)iter.get();
441d16044ad4d6176fec6164f96450a25f76b7677f1Eric Anholt
442d16044ad4d6176fec6164f96450a25f76b7677f1Eric Anholt      visit_tree(ir, check_node_type, NULL);
443d16044ad4d6176fec6164f96450a25f76b7677f1Eric Anholt   }
44453cdb7e51d85d4b4a35fba3ec200b27991b8488bEric Anholt}
445