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