glsl: Add ir node for barrier
[mesa.git] / src / glsl / nir / glsl_to_nir.cpp
1 /*
2 * Copyright © 2014 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Connor Abbott (cwabbott0@gmail.com)
25 *
26 */
27
28 #include "glsl_to_nir.h"
29 #include "ir_visitor.h"
30 #include "ir_hierarchical_visitor.h"
31 #include "ir.h"
32
33 /*
34 * pass to lower GLSL IR to NIR
35 *
36 * This will lower variable dereferences to loads/stores of corresponding
37 * variables in NIR - the variables will be converted to registers in a later
38 * pass.
39 */
40
41 namespace {
42
43 class nir_visitor : public ir_visitor
44 {
45 public:
46 nir_visitor(nir_shader *shader, gl_shader_stage stage);
47 ~nir_visitor();
48
49 virtual void visit(ir_variable *);
50 virtual void visit(ir_function *);
51 virtual void visit(ir_function_signature *);
52 virtual void visit(ir_loop *);
53 virtual void visit(ir_if *);
54 virtual void visit(ir_discard *);
55 virtual void visit(ir_loop_jump *);
56 virtual void visit(ir_return *);
57 virtual void visit(ir_call *);
58 virtual void visit(ir_assignment *);
59 virtual void visit(ir_emit_vertex *);
60 virtual void visit(ir_end_primitive *);
61 virtual void visit(ir_expression *);
62 virtual void visit(ir_swizzle *);
63 virtual void visit(ir_texture *);
64 virtual void visit(ir_constant *);
65 virtual void visit(ir_dereference_variable *);
66 virtual void visit(ir_dereference_record *);
67 virtual void visit(ir_dereference_array *);
68 virtual void visit(ir_barrier *);
69
70 void create_function(ir_function *ir);
71
72 private:
73 void create_overload(ir_function_signature *ir, nir_function *function);
74 void add_instr(nir_instr *instr, unsigned num_components);
75 nir_src evaluate_rvalue(ir_rvalue *ir);
76
77 nir_alu_instr *emit(nir_op op, unsigned dest_size, nir_src *srcs);
78 nir_alu_instr *emit(nir_op op, unsigned dest_size, nir_src src1);
79 nir_alu_instr *emit(nir_op op, unsigned dest_size, nir_src src1,
80 nir_src src2);
81 nir_alu_instr *emit(nir_op op, unsigned dest_size, nir_src src1,
82 nir_src src2, nir_src src3);
83
84 bool supports_ints;
85
86 nir_shader *shader;
87 gl_shader_stage stage;
88 nir_function_impl *impl;
89 exec_list *cf_node_list;
90 nir_instr *result; /* result of the expression tree last visited */
91
92 nir_deref_var *evaluate_deref(nir_instr *mem_ctx, ir_instruction *ir);
93
94 /* the head of the dereference chain we're creating */
95 nir_deref_var *deref_head;
96 /* the tail of the dereference chain we're creating */
97 nir_deref *deref_tail;
98
99 nir_variable *var; /* variable created by ir_variable visitor */
100
101 /* whether the IR we're operating on is per-function or global */
102 bool is_global;
103
104 /* map of ir_variable -> nir_variable */
105 struct hash_table *var_table;
106
107 /* map of ir_function_signature -> nir_function_overload */
108 struct hash_table *overload_table;
109 };
110
111 /*
112 * This visitor runs before the main visitor, calling create_function() for
113 * each function so that the main visitor can resolve forward references in
114 * calls.
115 */
116
117 class nir_function_visitor : public ir_hierarchical_visitor
118 {
119 public:
120 nir_function_visitor(nir_visitor *v) : visitor(v)
121 {
122 }
123 virtual ir_visitor_status visit_enter(ir_function *);
124
125 private:
126 nir_visitor *visitor;
127 };
128
129 }; /* end of anonymous namespace */
130
131 nir_shader *
132 glsl_to_nir(struct gl_shader *sh, const nir_shader_compiler_options *options)
133 {
134 nir_shader *shader = nir_shader_create(NULL, options);
135
136 nir_visitor v1(shader, sh->Stage);
137 nir_function_visitor v2(&v1);
138 v2.run(sh->ir);
139 visit_exec_list(sh->ir, &v1);
140
141 return shader;
142 }
143
144 nir_visitor::nir_visitor(nir_shader *shader, gl_shader_stage stage)
145 {
146 this->supports_ints = shader->options->native_integers;
147 this->shader = shader;
148 this->stage = stage;
149 this->is_global = true;
150 this->var_table = _mesa_hash_table_create(NULL, _mesa_hash_pointer,
151 _mesa_key_pointer_equal);
152 this->overload_table = _mesa_hash_table_create(NULL, _mesa_hash_pointer,
153 _mesa_key_pointer_equal);
154 }
155
156 nir_visitor::~nir_visitor()
157 {
158 _mesa_hash_table_destroy(this->var_table, NULL);
159 _mesa_hash_table_destroy(this->overload_table, NULL);
160 }
161
162 nir_deref_var *
163 nir_visitor::evaluate_deref(nir_instr *mem_ctx, ir_instruction *ir)
164 {
165 ir->accept(this);
166 ralloc_steal(mem_ctx, this->deref_head);
167 return this->deref_head;
168 }
169
170 static nir_constant *
171 constant_copy(ir_constant *ir, void *mem_ctx)
172 {
173 if (ir == NULL)
174 return NULL;
175
176 nir_constant *ret = ralloc(mem_ctx, nir_constant);
177
178 unsigned total_elems = ir->type->components();
179 unsigned i;
180 switch (ir->type->base_type) {
181 case GLSL_TYPE_UINT:
182 for (i = 0; i < total_elems; i++)
183 ret->value.u[i] = ir->value.u[i];
184 break;
185
186 case GLSL_TYPE_INT:
187 for (i = 0; i < total_elems; i++)
188 ret->value.i[i] = ir->value.i[i];
189 break;
190
191 case GLSL_TYPE_FLOAT:
192 for (i = 0; i < total_elems; i++)
193 ret->value.f[i] = ir->value.f[i];
194 break;
195
196 case GLSL_TYPE_BOOL:
197 for (i = 0; i < total_elems; i++)
198 ret->value.b[i] = ir->value.b[i];
199 break;
200
201 case GLSL_TYPE_STRUCT:
202 ret->elements = ralloc_array(mem_ctx, nir_constant *,
203 ir->type->length);
204 i = 0;
205 foreach_in_list(ir_constant, field, &ir->components) {
206 ret->elements[i] = constant_copy(field, mem_ctx);
207 i++;
208 }
209 break;
210
211 case GLSL_TYPE_ARRAY:
212 ret->elements = ralloc_array(mem_ctx, nir_constant *,
213 ir->type->length);
214
215 for (i = 0; i < ir->type->length; i++)
216 ret->elements[i] = constant_copy(ir->array_elements[i], mem_ctx);
217 break;
218
219 default:
220 unreachable("not reached");
221 }
222
223 return ret;
224 }
225
226 void
227 nir_visitor::visit(ir_variable *ir)
228 {
229 nir_variable *var = ralloc(shader, nir_variable);
230 var->type = ir->type;
231 var->name = ralloc_strdup(var, ir->name);
232
233 if (ir->is_interface_instance() && ir->get_max_ifc_array_access() != NULL) {
234 unsigned size = ir->get_interface_type()->length;
235 var->max_ifc_array_access = ralloc_array(var, unsigned, size);
236 memcpy(var->max_ifc_array_access, ir->get_max_ifc_array_access(),
237 size * sizeof(unsigned));
238 } else {
239 var->max_ifc_array_access = NULL;
240 }
241
242 var->data.read_only = ir->data.read_only;
243 var->data.centroid = ir->data.centroid;
244 var->data.sample = ir->data.sample;
245 var->data.invariant = ir->data.invariant;
246 var->data.location = ir->data.location;
247
248 switch(ir->data.mode) {
249 case ir_var_auto:
250 case ir_var_temporary:
251 if (is_global)
252 var->data.mode = nir_var_global;
253 else
254 var->data.mode = nir_var_local;
255 break;
256
257 case ir_var_function_in:
258 case ir_var_function_out:
259 case ir_var_function_inout:
260 case ir_var_const_in:
261 var->data.mode = nir_var_local;
262 break;
263
264 case ir_var_shader_in:
265 if (stage == MESA_SHADER_FRAGMENT &&
266 ir->data.location == VARYING_SLOT_FACE) {
267 /* For whatever reason, GLSL IR makes gl_FrontFacing an input */
268 var->data.location = SYSTEM_VALUE_FRONT_FACE;
269 var->data.mode = nir_var_system_value;
270 } else {
271 var->data.mode = nir_var_shader_in;
272 }
273 break;
274
275 case ir_var_shader_out:
276 var->data.mode = nir_var_shader_out;
277 break;
278
279 case ir_var_uniform:
280 var->data.mode = nir_var_uniform;
281 break;
282
283
284 case ir_var_system_value:
285 var->data.mode = nir_var_system_value;
286 break;
287
288 default:
289 unreachable("not reached");
290 }
291
292 var->data.interpolation = ir->data.interpolation;
293 var->data.origin_upper_left = ir->data.origin_upper_left;
294 var->data.pixel_center_integer = ir->data.pixel_center_integer;
295 var->data.explicit_location = ir->data.explicit_location;
296 var->data.explicit_index = ir->data.explicit_index;
297 var->data.explicit_binding = ir->data.explicit_binding;
298 var->data.has_initializer = ir->data.has_initializer;
299 var->data.is_unmatched_generic_inout = ir->data.is_unmatched_generic_inout;
300 var->data.location_frac = ir->data.location_frac;
301 var->data.from_named_ifc_block_array = ir->data.from_named_ifc_block_array;
302 var->data.from_named_ifc_block_nonarray = ir->data.from_named_ifc_block_nonarray;
303
304 switch (ir->data.depth_layout) {
305 case ir_depth_layout_none:
306 var->data.depth_layout = nir_depth_layout_none;
307 break;
308 case ir_depth_layout_any:
309 var->data.depth_layout = nir_depth_layout_any;
310 break;
311 case ir_depth_layout_greater:
312 var->data.depth_layout = nir_depth_layout_greater;
313 break;
314 case ir_depth_layout_less:
315 var->data.depth_layout = nir_depth_layout_less;
316 break;
317 case ir_depth_layout_unchanged:
318 var->data.depth_layout = nir_depth_layout_unchanged;
319 break;
320 default:
321 unreachable("not reached");
322 }
323
324 var->data.index = ir->data.index;
325 var->data.binding = ir->data.binding;
326 /* XXX Get rid of buffer_index */
327 var->data.atomic.buffer_index = ir->data.binding;
328 var->data.atomic.offset = ir->data.atomic.offset;
329 var->data.image.read_only = ir->data.image_read_only;
330 var->data.image.write_only = ir->data.image_write_only;
331 var->data.image.coherent = ir->data.image_coherent;
332 var->data.image._volatile = ir->data.image_volatile;
333 var->data.image.restrict_flag = ir->data.image_restrict;
334 var->data.image.format = ir->data.image_format;
335 var->data.max_array_access = ir->data.max_array_access;
336
337 var->num_state_slots = ir->get_num_state_slots();
338 if (var->num_state_slots > 0) {
339 var->state_slots = ralloc_array(var, nir_state_slot,
340 var->num_state_slots);
341
342 ir_state_slot *state_slots = ir->get_state_slots();
343 for (unsigned i = 0; i < var->num_state_slots; i++) {
344 for (unsigned j = 0; j < 5; j++)
345 var->state_slots[i].tokens[j] = state_slots[i].tokens[j];
346 var->state_slots[i].swizzle = state_slots[i].swizzle;
347 }
348 } else {
349 var->state_slots = NULL;
350 }
351
352 var->constant_initializer = constant_copy(ir->constant_initializer, var);
353
354 var->interface_type = ir->get_interface_type();
355
356 switch (var->data.mode) {
357 case nir_var_local:
358 exec_list_push_tail(&impl->locals, &var->node);
359 break;
360
361 case nir_var_global:
362 exec_list_push_tail(&shader->globals, &var->node);
363 break;
364
365 case nir_var_shader_in:
366 exec_list_push_tail(&shader->inputs, &var->node);
367 break;
368
369 case nir_var_shader_out:
370 exec_list_push_tail(&shader->outputs, &var->node);
371 break;
372
373 case nir_var_uniform:
374 exec_list_push_tail(&shader->uniforms, &var->node);
375 break;
376
377 case nir_var_system_value:
378 exec_list_push_tail(&shader->system_values, &var->node);
379 break;
380
381 default:
382 unreachable("not reached");
383 }
384
385 _mesa_hash_table_insert(var_table, ir, var);
386 this->var = var;
387 }
388
389 ir_visitor_status
390 nir_function_visitor::visit_enter(ir_function *ir)
391 {
392 visitor->create_function(ir);
393 return visit_continue_with_parent;
394 }
395
396
397 void
398 nir_visitor::create_function(ir_function *ir)
399 {
400 nir_function *func = nir_function_create(this->shader, ir->name);
401 foreach_in_list(ir_function_signature, sig, &ir->signatures) {
402 create_overload(sig, func);
403 }
404 }
405
406
407
408 void
409 nir_visitor::create_overload(ir_function_signature *ir, nir_function *function)
410 {
411 if (ir->is_intrinsic)
412 return;
413
414 nir_function_overload *overload = nir_function_overload_create(function);
415
416 unsigned num_params = ir->parameters.length();
417 overload->num_params = num_params;
418 overload->params = ralloc_array(shader, nir_parameter, num_params);
419
420 unsigned i = 0;
421 foreach_in_list(ir_variable, param, &ir->parameters) {
422 switch (param->data.mode) {
423 case ir_var_function_in:
424 overload->params[i].param_type = nir_parameter_in;
425 break;
426
427 case ir_var_function_out:
428 overload->params[i].param_type = nir_parameter_out;
429 break;
430
431 case ir_var_function_inout:
432 overload->params[i].param_type = nir_parameter_inout;
433 break;
434
435 default:
436 unreachable("not reached");
437 }
438
439 overload->params[i].type = param->type;
440 i++;
441 }
442
443 overload->return_type = ir->return_type;
444
445 _mesa_hash_table_insert(this->overload_table, ir, overload);
446 }
447
448 void
449 nir_visitor::visit(ir_function *ir)
450 {
451 foreach_in_list(ir_function_signature, sig, &ir->signatures)
452 sig->accept(this);
453 }
454
455 void
456 nir_visitor::visit(ir_function_signature *ir)
457 {
458 if (ir->is_intrinsic)
459 return;
460
461 struct hash_entry *entry =
462 _mesa_hash_table_search(this->overload_table, ir);
463
464 assert(entry);
465 nir_function_overload *overload = (nir_function_overload *) entry->data;
466
467 if (ir->is_defined) {
468 nir_function_impl *impl = nir_function_impl_create(overload);
469 this->impl = impl;
470
471 unsigned num_params = overload->num_params;
472 impl->num_params = num_params;
473 impl->params = ralloc_array(this->shader, nir_variable *, num_params);
474 unsigned i = 0;
475 foreach_in_list(ir_variable, param, &ir->parameters) {
476 param->accept(this);
477 impl->params[i] = this->var;
478 i++;
479 }
480
481 if (overload->return_type == glsl_type::void_type) {
482 impl->return_var = NULL;
483 } else {
484 impl->return_var = ralloc(this->shader, nir_variable);
485 impl->return_var->name = ralloc_strdup(impl->return_var,
486 "return_var");
487 impl->return_var->type = overload->return_type;
488 }
489
490 this->is_global = false;
491
492 this->cf_node_list = &impl->body;
493 visit_exec_list(&ir->body, this);
494
495 this->is_global = true;
496 } else {
497 overload->impl = NULL;
498 }
499 }
500
501 void
502 nir_visitor::visit(ir_loop *ir)
503 {
504 exec_list *old_list = this->cf_node_list;
505
506 nir_loop *loop = nir_loop_create(this->shader);
507 nir_cf_node_insert_end(old_list, &loop->cf_node);
508 this->cf_node_list = &loop->body;
509 visit_exec_list(&ir->body_instructions, this);
510
511 this->cf_node_list = old_list;
512 }
513
514 void
515 nir_visitor::visit(ir_if *ir)
516 {
517 nir_src condition = evaluate_rvalue(ir->condition);
518
519 exec_list *old_list = this->cf_node_list;
520
521 nir_if *if_stmt = nir_if_create(this->shader);
522 if_stmt->condition = condition;
523 nir_cf_node_insert_end(old_list, &if_stmt->cf_node);
524
525 this->cf_node_list = &if_stmt->then_list;
526 visit_exec_list(&ir->then_instructions, this);
527
528 this->cf_node_list = &if_stmt->else_list;
529 visit_exec_list(&ir->else_instructions, this);
530
531 this->cf_node_list = old_list;
532 }
533
534 void
535 nir_visitor::visit(ir_discard *ir)
536 {
537 /*
538 * discards aren't treated as control flow, because before we lower them
539 * they can appear anywhere in the shader and the stuff after them may still
540 * be executed (yay, crazy GLSL rules!). However, after lowering, all the
541 * discards will be immediately followed by a return.
542 */
543
544 nir_intrinsic_instr *discard;
545 if (ir->condition) {
546 discard = nir_intrinsic_instr_create(this->shader,
547 nir_intrinsic_discard_if);
548 discard->src[0] = evaluate_rvalue(ir->condition);
549 } else {
550 discard = nir_intrinsic_instr_create(this->shader, nir_intrinsic_discard);
551 }
552 nir_instr_insert_after_cf_list(this->cf_node_list, &discard->instr);
553 }
554
555 void
556 nir_visitor::visit(ir_emit_vertex *ir)
557 {
558 nir_intrinsic_instr *instr =
559 nir_intrinsic_instr_create(this->shader, nir_intrinsic_emit_vertex);
560 instr->const_index[0] = ir->stream_id();
561 nir_instr_insert_after_cf_list(this->cf_node_list, &instr->instr);
562 }
563
564 void
565 nir_visitor::visit(ir_end_primitive *ir)
566 {
567 nir_intrinsic_instr *instr =
568 nir_intrinsic_instr_create(this->shader, nir_intrinsic_end_primitive);
569 instr->const_index[0] = ir->stream_id();
570 nir_instr_insert_after_cf_list(this->cf_node_list, &instr->instr);
571 }
572
573 void
574 nir_visitor::visit(ir_loop_jump *ir)
575 {
576 nir_jump_type type;
577 switch (ir->mode) {
578 case ir_loop_jump::jump_break:
579 type = nir_jump_break;
580 break;
581 case ir_loop_jump::jump_continue:
582 type = nir_jump_continue;
583 break;
584 default:
585 unreachable("not reached");
586 }
587
588 nir_jump_instr *instr = nir_jump_instr_create(this->shader, type);
589 nir_instr_insert_after_cf_list(this->cf_node_list, &instr->instr);
590 }
591
592 void
593 nir_visitor::visit(ir_return *ir)
594 {
595 if (ir->value != NULL) {
596 nir_intrinsic_instr *copy =
597 nir_intrinsic_instr_create(this->shader, nir_intrinsic_copy_var);
598
599 copy->variables[0] = nir_deref_var_create(copy, this->impl->return_var);
600 copy->variables[1] = evaluate_deref(&copy->instr, ir->value);
601 }
602
603 nir_jump_instr *instr = nir_jump_instr_create(this->shader, nir_jump_return);
604 nir_instr_insert_after_cf_list(this->cf_node_list, &instr->instr);
605 }
606
607 void
608 nir_visitor::visit(ir_call *ir)
609 {
610 if (ir->callee->is_intrinsic) {
611 nir_intrinsic_op op;
612 if (strcmp(ir->callee_name(), "__intrinsic_atomic_read") == 0) {
613 op = nir_intrinsic_atomic_counter_read_var;
614 } else if (strcmp(ir->callee_name(), "__intrinsic_atomic_increment") == 0) {
615 op = nir_intrinsic_atomic_counter_inc_var;
616 } else if (strcmp(ir->callee_name(), "__intrinsic_atomic_predecrement") == 0) {
617 op = nir_intrinsic_atomic_counter_dec_var;
618 } else if (strcmp(ir->callee_name(), "__intrinsic_image_load") == 0) {
619 op = nir_intrinsic_image_load;
620 } else if (strcmp(ir->callee_name(), "__intrinsic_image_store") == 0) {
621 op = nir_intrinsic_image_store;
622 } else if (strcmp(ir->callee_name(), "__intrinsic_image_atomic_add") == 0) {
623 op = nir_intrinsic_image_atomic_add;
624 } else if (strcmp(ir->callee_name(), "__intrinsic_image_atomic_min") == 0) {
625 op = nir_intrinsic_image_atomic_min;
626 } else if (strcmp(ir->callee_name(), "__intrinsic_image_atomic_max") == 0) {
627 op = nir_intrinsic_image_atomic_max;
628 } else if (strcmp(ir->callee_name(), "__intrinsic_image_atomic_and") == 0) {
629 op = nir_intrinsic_image_atomic_and;
630 } else if (strcmp(ir->callee_name(), "__intrinsic_image_atomic_or") == 0) {
631 op = nir_intrinsic_image_atomic_or;
632 } else if (strcmp(ir->callee_name(), "__intrinsic_image_atomic_xor") == 0) {
633 op = nir_intrinsic_image_atomic_xor;
634 } else if (strcmp(ir->callee_name(), "__intrinsic_image_atomic_exchange") == 0) {
635 op = nir_intrinsic_image_atomic_exchange;
636 } else if (strcmp(ir->callee_name(), "__intrinsic_image_atomic_comp_swap") == 0) {
637 op = nir_intrinsic_image_atomic_comp_swap;
638 } else if (strcmp(ir->callee_name(), "__intrinsic_memory_barrier") == 0) {
639 op = nir_intrinsic_memory_barrier;
640 } else {
641 unreachable("not reached");
642 }
643
644 nir_intrinsic_instr *instr = nir_intrinsic_instr_create(shader, op);
645
646 switch (op) {
647 case nir_intrinsic_atomic_counter_read_var:
648 case nir_intrinsic_atomic_counter_inc_var:
649 case nir_intrinsic_atomic_counter_dec_var: {
650 ir_dereference *param =
651 (ir_dereference *) ir->actual_parameters.get_head();
652 instr->variables[0] = evaluate_deref(&instr->instr, param);
653 nir_ssa_dest_init(&instr->instr, &instr->dest, 1, NULL);
654 break;
655 }
656 case nir_intrinsic_image_load:
657 case nir_intrinsic_image_store:
658 case nir_intrinsic_image_atomic_add:
659 case nir_intrinsic_image_atomic_min:
660 case nir_intrinsic_image_atomic_max:
661 case nir_intrinsic_image_atomic_and:
662 case nir_intrinsic_image_atomic_or:
663 case nir_intrinsic_image_atomic_xor:
664 case nir_intrinsic_image_atomic_exchange:
665 case nir_intrinsic_image_atomic_comp_swap: {
666 nir_ssa_undef_instr *instr_undef =
667 nir_ssa_undef_instr_create(shader, 1);
668 nir_instr_insert_after_cf_list(this->cf_node_list,
669 &instr_undef->instr);
670
671 /* Set the image variable dereference. */
672 exec_node *param = ir->actual_parameters.get_head();
673 ir_dereference *image = (ir_dereference *)param;
674 const glsl_type *type =
675 image->variable_referenced()->type->without_array();
676
677 instr->variables[0] = evaluate_deref(&instr->instr, image);
678 param = param->get_next();
679
680 /* Set the address argument, extending the coordinate vector to four
681 * components.
682 */
683 const nir_src src_addr = evaluate_rvalue((ir_dereference *)param);
684 nir_alu_instr *instr_addr = nir_alu_instr_create(shader, nir_op_vec4);
685 nir_ssa_dest_init(&instr_addr->instr, &instr_addr->dest.dest, 4, NULL);
686
687 for (int i = 0; i < 4; i++) {
688 if (i < type->coordinate_components()) {
689 instr_addr->src[i].src = src_addr;
690 instr_addr->src[i].swizzle[0] = i;
691 } else {
692 instr_addr->src[i].src = nir_src_for_ssa(&instr_undef->def);
693 }
694 }
695
696 nir_instr_insert_after_cf_list(cf_node_list, &instr_addr->instr);
697 instr->src[0] = nir_src_for_ssa(&instr_addr->dest.dest.ssa);
698 param = param->get_next();
699
700 /* Set the sample argument, which is undefined for single-sample
701 * images.
702 */
703 if (type->sampler_dimensionality == GLSL_SAMPLER_DIM_MS) {
704 instr->src[1] = evaluate_rvalue((ir_dereference *)param);
705 param = param->get_next();
706 } else {
707 instr->src[1] = nir_src_for_ssa(&instr_undef->def);
708 }
709
710 /* Set the intrinsic parameters. */
711 if (!param->is_tail_sentinel()) {
712 instr->src[2] = evaluate_rvalue((ir_dereference *)param);
713 param = param->get_next();
714 }
715
716 if (!param->is_tail_sentinel()) {
717 instr->src[3] = evaluate_rvalue((ir_dereference *)param);
718 param = param->get_next();
719 }
720
721 /* Set the intrinsic destination. */
722 if (ir->return_deref)
723 nir_ssa_dest_init(&instr->instr, &instr->dest,
724 ir->return_deref->type->vector_elements, NULL);
725 break;
726 }
727 case nir_intrinsic_memory_barrier:
728 break;
729 default:
730 unreachable("not reached");
731 }
732
733 nir_instr_insert_after_cf_list(this->cf_node_list, &instr->instr);
734
735 if (ir->return_deref) {
736 nir_intrinsic_instr *store_instr =
737 nir_intrinsic_instr_create(shader, nir_intrinsic_store_var);
738 store_instr->num_components = ir->return_deref->type->vector_elements;
739
740 store_instr->variables[0] =
741 evaluate_deref(&store_instr->instr, ir->return_deref);
742 store_instr->src[0] = nir_src_for_ssa(&instr->dest.ssa);
743
744 nir_instr_insert_after_cf_list(this->cf_node_list,
745 &store_instr->instr);
746 }
747
748 return;
749 }
750
751 struct hash_entry *entry =
752 _mesa_hash_table_search(this->overload_table, ir->callee);
753 assert(entry);
754 nir_function_overload *callee = (nir_function_overload *) entry->data;
755
756 nir_call_instr *instr = nir_call_instr_create(this->shader, callee);
757
758 unsigned i = 0;
759 foreach_in_list(ir_dereference, param, &ir->actual_parameters) {
760 instr->params[i] = evaluate_deref(&instr->instr, param);
761 i++;
762 }
763
764 instr->return_deref = evaluate_deref(&instr->instr, ir->return_deref);
765 nir_instr_insert_after_cf_list(this->cf_node_list, &instr->instr);
766 }
767
768 void
769 nir_visitor::visit(ir_assignment *ir)
770 {
771 unsigned num_components = ir->lhs->type->vector_elements;
772
773 if ((ir->rhs->as_dereference() || ir->rhs->as_constant()) &&
774 (ir->write_mask == (1 << num_components) - 1 || ir->write_mask == 0)) {
775 /* We're doing a plain-as-can-be copy, so emit a copy_var */
776 nir_intrinsic_instr *copy =
777 nir_intrinsic_instr_create(this->shader, nir_intrinsic_copy_var);
778
779 copy->variables[0] = evaluate_deref(&copy->instr, ir->lhs);
780 copy->variables[1] = evaluate_deref(&copy->instr, ir->rhs);
781
782 if (ir->condition) {
783 nir_if *if_stmt = nir_if_create(this->shader);
784 if_stmt->condition = evaluate_rvalue(ir->condition);
785 nir_cf_node_insert_end(this->cf_node_list, &if_stmt->cf_node);
786 nir_instr_insert_after_cf_list(&if_stmt->then_list, &copy->instr);
787 } else {
788 nir_instr_insert_after_cf_list(this->cf_node_list, &copy->instr);
789 }
790 return;
791 }
792
793 assert(ir->rhs->type->is_scalar() || ir->rhs->type->is_vector());
794
795 ir->lhs->accept(this);
796 nir_deref_var *lhs_deref = this->deref_head;
797 nir_src src = evaluate_rvalue(ir->rhs);
798
799 if (ir->write_mask != (1 << num_components) - 1 && ir->write_mask != 0) {
800 /*
801 * We have no good way to update only part of a variable, so just load
802 * the LHS and do a vec operation to combine the old with the new, and
803 * then store it
804 * back into the LHS. Copy propagation should get rid of the mess.
805 */
806
807 nir_intrinsic_instr *load =
808 nir_intrinsic_instr_create(this->shader, nir_intrinsic_load_var);
809 load->num_components = ir->lhs->type->vector_elements;
810 nir_ssa_dest_init(&load->instr, &load->dest, num_components, NULL);
811 load->variables[0] = lhs_deref;
812 ralloc_steal(load, load->variables[0]);
813 nir_instr_insert_after_cf_list(this->cf_node_list, &load->instr);
814
815 nir_op vec_op;
816 switch (ir->lhs->type->vector_elements) {
817 case 1: vec_op = nir_op_imov; break;
818 case 2: vec_op = nir_op_vec2; break;
819 case 3: vec_op = nir_op_vec3; break;
820 case 4: vec_op = nir_op_vec4; break;
821 default: unreachable("Invalid number of components"); break;
822 }
823 nir_alu_instr *vec = nir_alu_instr_create(this->shader, vec_op);
824 nir_ssa_dest_init(&vec->instr, &vec->dest.dest, num_components, NULL);
825 vec->dest.write_mask = (1 << num_components) - 1;
826
827 unsigned component = 0;
828 for (unsigned i = 0; i < ir->lhs->type->vector_elements; i++) {
829 if (ir->write_mask & (1 << i)) {
830 vec->src[i].src = src;
831
832 /* GLSL IR will give us the input to the write-masked assignment
833 * in a single packed vector. So, for example, if the
834 * writemask is xzw, then we have to swizzle x -> x, y -> z,
835 * and z -> w and get the y component from the load.
836 */
837 vec->src[i].swizzle[0] = component++;
838 } else {
839 vec->src[i].src.is_ssa = true;
840 vec->src[i].src.ssa = &load->dest.ssa;
841 vec->src[i].swizzle[0] = i;
842 }
843 }
844
845 nir_instr_insert_after_cf_list(this->cf_node_list, &vec->instr);
846
847 src.is_ssa = true;
848 src.ssa = &vec->dest.dest.ssa;
849 }
850
851 nir_intrinsic_instr *store =
852 nir_intrinsic_instr_create(this->shader, nir_intrinsic_store_var);
853 store->num_components = ir->lhs->type->vector_elements;
854 nir_deref *store_deref = nir_copy_deref(store, &lhs_deref->deref);
855 store->variables[0] = nir_deref_as_var(store_deref);
856 store->src[0] = src;
857
858 if (ir->condition) {
859 nir_if *if_stmt = nir_if_create(this->shader);
860 if_stmt->condition = evaluate_rvalue(ir->condition);
861 nir_cf_node_insert_end(this->cf_node_list, &if_stmt->cf_node);
862 nir_instr_insert_after_cf_list(&if_stmt->then_list, &store->instr);
863 } else {
864 nir_instr_insert_after_cf_list(this->cf_node_list, &store->instr);
865 }
866 }
867
868 /*
869 * Given an instruction, returns a pointer to its destination or NULL if there
870 * is no destination.
871 *
872 * Note that this only handles instructions we generate at this level.
873 */
874 static nir_dest *
875 get_instr_dest(nir_instr *instr)
876 {
877 nir_alu_instr *alu_instr;
878 nir_intrinsic_instr *intrinsic_instr;
879 nir_tex_instr *tex_instr;
880
881 switch (instr->type) {
882 case nir_instr_type_alu:
883 alu_instr = nir_instr_as_alu(instr);
884 return &alu_instr->dest.dest;
885
886 case nir_instr_type_intrinsic:
887 intrinsic_instr = nir_instr_as_intrinsic(instr);
888 if (nir_intrinsic_infos[intrinsic_instr->intrinsic].has_dest)
889 return &intrinsic_instr->dest;
890 else
891 return NULL;
892
893 case nir_instr_type_tex:
894 tex_instr = nir_instr_as_tex(instr);
895 return &tex_instr->dest;
896
897 default:
898 unreachable("not reached");
899 }
900
901 return NULL;
902 }
903
904 void
905 nir_visitor::add_instr(nir_instr *instr, unsigned num_components)
906 {
907 nir_dest *dest = get_instr_dest(instr);
908
909 nir_ssa_dest_init(instr, dest, num_components, NULL);
910
911 nir_instr_insert_after_cf_list(this->cf_node_list, instr);
912 this->result = instr;
913 }
914
915 nir_src
916 nir_visitor::evaluate_rvalue(ir_rvalue* ir)
917 {
918 ir->accept(this);
919 if (ir->as_dereference() || ir->as_constant()) {
920 /*
921 * A dereference is being used on the right hand side, which means we
922 * must emit a variable load.
923 */
924
925 nir_intrinsic_instr *load_instr =
926 nir_intrinsic_instr_create(this->shader, nir_intrinsic_load_var);
927 load_instr->num_components = ir->type->vector_elements;
928 load_instr->variables[0] = this->deref_head;
929 ralloc_steal(load_instr, load_instr->variables[0]);
930 add_instr(&load_instr->instr, ir->type->vector_elements);
931 }
932
933 nir_dest *dest = get_instr_dest(this->result);
934 assert(dest->is_ssa);
935
936 return nir_src_for_ssa(&dest->ssa);
937 }
938
939 nir_alu_instr *
940 nir_visitor::emit(nir_op op, unsigned dest_size, nir_src *srcs)
941 {
942 nir_alu_instr *instr = nir_alu_instr_create(this->shader, op);
943 for (unsigned i = 0; i < nir_op_infos[op].num_inputs; i++)
944 instr->src[i].src = srcs[i];
945 instr->dest.write_mask = (1 << dest_size) - 1;
946 add_instr(&instr->instr, dest_size);
947 return instr;
948 }
949
950 nir_alu_instr *
951 nir_visitor::emit(nir_op op, unsigned dest_size, nir_src src1)
952 {
953 assert(nir_op_infos[op].num_inputs == 1);
954 return emit(op, dest_size, &src1);
955 }
956
957 nir_alu_instr *
958 nir_visitor::emit(nir_op op, unsigned dest_size, nir_src src1,
959 nir_src src2)
960 {
961 assert(nir_op_infos[op].num_inputs == 2);
962 nir_src srcs[] = { src1, src2 };
963 return emit(op, dest_size, srcs);
964 }
965
966 nir_alu_instr *
967 nir_visitor::emit(nir_op op, unsigned dest_size, nir_src src1,
968 nir_src src2, nir_src src3)
969 {
970 assert(nir_op_infos[op].num_inputs == 3);
971 nir_src srcs[] = { src1, src2, src3 };
972 return emit(op, dest_size, srcs);
973 }
974
975 void
976 nir_visitor::visit(ir_expression *ir)
977 {
978 /* Some special cases */
979 switch (ir->operation) {
980 case ir_binop_ubo_load: {
981 ir_constant *const_index = ir->operands[1]->as_constant();
982
983 nir_intrinsic_op op;
984 if (const_index) {
985 op = nir_intrinsic_load_ubo;
986 } else {
987 op = nir_intrinsic_load_ubo_indirect;
988 }
989 nir_intrinsic_instr *load = nir_intrinsic_instr_create(this->shader, op);
990 load->num_components = ir->type->vector_elements;
991 load->const_index[0] = const_index ? const_index->value.u[0] : 0; /* base offset */
992 load->const_index[1] = 1; /* number of vec4's */
993 load->src[0] = evaluate_rvalue(ir->operands[0]);
994 if (!const_index)
995 load->src[1] = evaluate_rvalue(ir->operands[1]);
996 add_instr(&load->instr, ir->type->vector_elements);
997
998 /*
999 * In UBO's, a true boolean value is any non-zero value, but we consider
1000 * a true boolean to be ~0. Fix this up with a != 0 comparison.
1001 */
1002
1003 if (ir->type->base_type == GLSL_TYPE_BOOL) {
1004 nir_load_const_instr *const_zero = nir_load_const_instr_create(shader, 1);
1005 const_zero->value.u[0] = 0;
1006 nir_instr_insert_after_cf_list(this->cf_node_list, &const_zero->instr);
1007
1008 nir_alu_instr *compare = nir_alu_instr_create(shader, nir_op_ine);
1009 compare->src[0].src.is_ssa = true;
1010 compare->src[0].src.ssa = &load->dest.ssa;
1011 compare->src[1].src.is_ssa = true;
1012 compare->src[1].src.ssa = &const_zero->def;
1013 for (unsigned i = 0; i < ir->type->vector_elements; i++)
1014 compare->src[1].swizzle[i] = 0;
1015 compare->dest.write_mask = (1 << ir->type->vector_elements) - 1;
1016
1017 add_instr(&compare->instr, ir->type->vector_elements);
1018 }
1019
1020 return;
1021 }
1022
1023 case ir_unop_interpolate_at_centroid:
1024 case ir_binop_interpolate_at_offset:
1025 case ir_binop_interpolate_at_sample: {
1026 ir_dereference *deref = ir->operands[0]->as_dereference();
1027 ir_swizzle *swizzle = NULL;
1028 if (!deref) {
1029 /* the api does not allow a swizzle here, but the varying packing code
1030 * may have pushed one into here.
1031 */
1032 swizzle = ir->operands[0]->as_swizzle();
1033 assert(swizzle);
1034 deref = swizzle->val->as_dereference();
1035 assert(deref);
1036 }
1037
1038 deref->accept(this);
1039
1040 nir_intrinsic_op op;
1041 if (this->deref_head->var->data.mode == nir_var_shader_in) {
1042 switch (ir->operation) {
1043 case ir_unop_interpolate_at_centroid:
1044 op = nir_intrinsic_interp_var_at_centroid;
1045 break;
1046 case ir_binop_interpolate_at_offset:
1047 op = nir_intrinsic_interp_var_at_offset;
1048 break;
1049 case ir_binop_interpolate_at_sample:
1050 op = nir_intrinsic_interp_var_at_sample;
1051 break;
1052 default:
1053 unreachable("Invalid interpolation intrinsic");
1054 }
1055 } else {
1056 /* This case can happen if the vertex shader does not write the
1057 * given varying. In this case, the linker will lower it to a
1058 * global variable. Since interpolating a variable makes no
1059 * sense, we'll just turn it into a load which will probably
1060 * eventually end up as an SSA definition.
1061 */
1062 assert(this->deref_head->var->data.mode == nir_var_global);
1063 op = nir_intrinsic_load_var;
1064 }
1065
1066 nir_intrinsic_instr *intrin = nir_intrinsic_instr_create(shader, op);
1067 intrin->num_components = deref->type->vector_elements;
1068 intrin->variables[0] = this->deref_head;
1069 ralloc_steal(intrin, intrin->variables[0]);
1070
1071 if (intrin->intrinsic == nir_intrinsic_interp_var_at_offset ||
1072 intrin->intrinsic == nir_intrinsic_interp_var_at_sample)
1073 intrin->src[0] = evaluate_rvalue(ir->operands[1]);
1074
1075 add_instr(&intrin->instr, deref->type->vector_elements);
1076
1077 if (swizzle) {
1078 nir_alu_instr *mov = nir_alu_instr_create(shader, nir_op_imov);
1079 mov->dest.write_mask = (1 << swizzle->type->vector_elements) - 1;
1080 mov->src[0].src.is_ssa = true;
1081 mov->src[0].src.ssa = &intrin->dest.ssa;
1082
1083 mov->src[0].swizzle[0] = swizzle->mask.x;
1084 mov->src[0].swizzle[1] = swizzle->mask.y;
1085 mov->src[0].swizzle[2] = swizzle->mask.z;
1086 mov->src[0].swizzle[3] = swizzle->mask.w;
1087 for (unsigned i = deref->type->vector_elements; i < 4; i++)
1088 mov->src[0].swizzle[i] = 0;
1089
1090 add_instr(&mov->instr, swizzle->type->vector_elements);
1091 }
1092
1093 return;
1094 }
1095
1096 default:
1097 break;
1098 }
1099
1100 nir_src srcs[4];
1101 for (unsigned i = 0; i < ir->get_num_operands(); i++)
1102 srcs[i] = evaluate_rvalue(ir->operands[i]);
1103
1104 glsl_base_type types[4];
1105 for (unsigned i = 0; i < ir->get_num_operands(); i++)
1106 if (supports_ints)
1107 types[i] = ir->operands[i]->type->base_type;
1108 else
1109 types[i] = GLSL_TYPE_FLOAT;
1110
1111 glsl_base_type out_type;
1112 if (supports_ints)
1113 out_type = ir->type->base_type;
1114 else
1115 out_type = GLSL_TYPE_FLOAT;
1116
1117 unsigned dest_size = ir->type->vector_elements;
1118
1119 nir_alu_instr *instr;
1120 nir_op op;
1121
1122 switch (ir->operation) {
1123 case ir_unop_bit_not: emit(nir_op_inot, dest_size, srcs); break;
1124 case ir_unop_logic_not:
1125 emit(supports_ints ? nir_op_inot : nir_op_fnot, dest_size, srcs);
1126 break;
1127 case ir_unop_neg:
1128 instr = emit(types[0] == GLSL_TYPE_FLOAT ? nir_op_fneg : nir_op_ineg,
1129 dest_size, srcs);
1130 break;
1131 case ir_unop_abs:
1132 instr = emit(types[0] == GLSL_TYPE_FLOAT ? nir_op_fabs : nir_op_iabs,
1133 dest_size, srcs);
1134 break;
1135 case ir_unop_saturate:
1136 assert(types[0] == GLSL_TYPE_FLOAT);
1137 instr = emit(nir_op_fsat, dest_size, srcs);
1138 break;
1139 case ir_unop_sign:
1140 emit(types[0] == GLSL_TYPE_FLOAT ? nir_op_fsign : nir_op_isign,
1141 dest_size, srcs);
1142 break;
1143 case ir_unop_rcp: emit(nir_op_frcp, dest_size, srcs); break;
1144 case ir_unop_rsq: emit(nir_op_frsq, dest_size, srcs); break;
1145 case ir_unop_sqrt: emit(nir_op_fsqrt, dest_size, srcs); break;
1146 case ir_unop_exp: unreachable("ir_unop_exp should have been lowered");
1147 case ir_unop_log: unreachable("ir_unop_log should have been lowered");
1148 case ir_unop_exp2: emit(nir_op_fexp2, dest_size, srcs); break;
1149 case ir_unop_log2: emit(nir_op_flog2, dest_size, srcs); break;
1150 case ir_unop_i2f:
1151 emit(supports_ints ? nir_op_i2f : nir_op_fmov, dest_size, srcs);
1152 break;
1153 case ir_unop_u2f:
1154 emit(supports_ints ? nir_op_u2f : nir_op_fmov, dest_size, srcs);
1155 break;
1156 case ir_unop_b2f:
1157 emit(supports_ints ? nir_op_b2f : nir_op_fmov, dest_size, srcs);
1158 break;
1159 case ir_unop_f2i: emit(nir_op_f2i, dest_size, srcs); break;
1160 case ir_unop_f2u: emit(nir_op_f2u, dest_size, srcs); break;
1161 case ir_unop_f2b: emit(nir_op_f2b, dest_size, srcs); break;
1162 case ir_unop_i2b: emit(nir_op_i2b, dest_size, srcs); break;
1163 case ir_unop_b2i: emit(nir_op_b2i, dest_size, srcs); break;
1164 case ir_unop_i2u:
1165 case ir_unop_u2i:
1166 case ir_unop_bitcast_i2f:
1167 case ir_unop_bitcast_f2i:
1168 case ir_unop_bitcast_u2f:
1169 case ir_unop_bitcast_f2u:
1170 /* no-op */
1171 emit(nir_op_imov, dest_size, srcs);
1172 break;
1173 case ir_unop_any:
1174 switch (ir->operands[0]->type->vector_elements) {
1175 case 2:
1176 emit(supports_ints ? nir_op_bany2 : nir_op_fany2,
1177 dest_size, srcs);
1178 break;
1179 case 3:
1180 emit(supports_ints ? nir_op_bany3 : nir_op_fany3,
1181 dest_size, srcs);
1182 break;
1183 case 4:
1184 emit(supports_ints ? nir_op_bany4 : nir_op_fany4,
1185 dest_size, srcs);
1186 break;
1187 default:
1188 unreachable("not reached");
1189 }
1190 break;
1191 case ir_unop_trunc: emit(nir_op_ftrunc, dest_size, srcs); break;
1192 case ir_unop_ceil: emit(nir_op_fceil, dest_size, srcs); break;
1193 case ir_unop_floor: emit(nir_op_ffloor, dest_size, srcs); break;
1194 case ir_unop_fract: emit(nir_op_ffract, dest_size, srcs); break;
1195 case ir_unop_round_even: emit(nir_op_fround_even, dest_size, srcs); break;
1196 case ir_unop_sin: emit(nir_op_fsin, dest_size, srcs); break;
1197 case ir_unop_cos: emit(nir_op_fcos, dest_size, srcs); break;
1198 case ir_unop_dFdx: emit(nir_op_fddx, dest_size, srcs); break;
1199 case ir_unop_dFdy: emit(nir_op_fddy, dest_size, srcs); break;
1200 case ir_unop_dFdx_fine: emit(nir_op_fddx_fine, dest_size, srcs); break;
1201 case ir_unop_dFdy_fine: emit(nir_op_fddy_fine, dest_size, srcs); break;
1202 case ir_unop_dFdx_coarse: emit(nir_op_fddx_coarse, dest_size, srcs); break;
1203 case ir_unop_dFdy_coarse: emit(nir_op_fddy_coarse, dest_size, srcs); break;
1204 case ir_unop_pack_snorm_2x16:
1205 emit(nir_op_pack_snorm_2x16, dest_size, srcs);
1206 break;
1207 case ir_unop_pack_snorm_4x8:
1208 emit(nir_op_pack_snorm_4x8, dest_size, srcs);
1209 break;
1210 case ir_unop_pack_unorm_2x16:
1211 emit(nir_op_pack_unorm_2x16, dest_size, srcs);
1212 break;
1213 case ir_unop_pack_unorm_4x8:
1214 emit(nir_op_pack_unorm_4x8, dest_size, srcs);
1215 break;
1216 case ir_unop_pack_half_2x16:
1217 emit(nir_op_pack_half_2x16, dest_size, srcs);
1218 break;
1219 case ir_unop_unpack_snorm_2x16:
1220 emit(nir_op_unpack_snorm_2x16, dest_size, srcs);
1221 break;
1222 case ir_unop_unpack_snorm_4x8:
1223 emit(nir_op_unpack_snorm_4x8, dest_size, srcs);
1224 break;
1225 case ir_unop_unpack_unorm_2x16:
1226 emit(nir_op_unpack_unorm_2x16, dest_size, srcs);
1227 break;
1228 case ir_unop_unpack_unorm_4x8:
1229 emit(nir_op_unpack_unorm_4x8, dest_size, srcs);
1230 break;
1231 case ir_unop_unpack_half_2x16:
1232 emit(nir_op_unpack_half_2x16, dest_size, srcs);
1233 break;
1234 case ir_unop_unpack_half_2x16_split_x:
1235 emit(nir_op_unpack_half_2x16_split_x, dest_size, srcs);
1236 break;
1237 case ir_unop_unpack_half_2x16_split_y:
1238 emit(nir_op_unpack_half_2x16_split_y, dest_size, srcs);
1239 break;
1240 case ir_unop_bitfield_reverse:
1241 emit(nir_op_bitfield_reverse, dest_size, srcs);
1242 break;
1243 case ir_unop_bit_count:
1244 emit(nir_op_bit_count, dest_size, srcs);
1245 break;
1246 case ir_unop_find_msb:
1247 switch (types[0]) {
1248 case GLSL_TYPE_UINT:
1249 emit(nir_op_ufind_msb, dest_size, srcs);
1250 break;
1251 case GLSL_TYPE_INT:
1252 emit(nir_op_ifind_msb, dest_size, srcs);
1253 break;
1254 default:
1255 unreachable("Invalid type for findMSB()");
1256 }
1257 break;
1258 case ir_unop_find_lsb:
1259 emit(nir_op_find_lsb, dest_size, srcs);
1260 break;
1261
1262 case ir_unop_noise:
1263 switch (ir->type->vector_elements) {
1264 case 1:
1265 switch (ir->operands[0]->type->vector_elements) {
1266 case 1: emit(nir_op_fnoise1_1, dest_size, srcs); break;
1267 case 2: emit(nir_op_fnoise1_2, dest_size, srcs); break;
1268 case 3: emit(nir_op_fnoise1_3, dest_size, srcs); break;
1269 case 4: emit(nir_op_fnoise1_4, dest_size, srcs); break;
1270 default: unreachable("not reached");
1271 }
1272 break;
1273 case 2:
1274 switch (ir->operands[0]->type->vector_elements) {
1275 case 1: emit(nir_op_fnoise2_1, dest_size, srcs); break;
1276 case 2: emit(nir_op_fnoise2_2, dest_size, srcs); break;
1277 case 3: emit(nir_op_fnoise2_3, dest_size, srcs); break;
1278 case 4: emit(nir_op_fnoise2_4, dest_size, srcs); break;
1279 default: unreachable("not reached");
1280 }
1281 break;
1282 case 3:
1283 switch (ir->operands[0]->type->vector_elements) {
1284 case 1: emit(nir_op_fnoise3_1, dest_size, srcs); break;
1285 case 2: emit(nir_op_fnoise3_2, dest_size, srcs); break;
1286 case 3: emit(nir_op_fnoise3_3, dest_size, srcs); break;
1287 case 4: emit(nir_op_fnoise3_4, dest_size, srcs); break;
1288 default: unreachable("not reached");
1289 }
1290 break;
1291 case 4:
1292 switch (ir->operands[0]->type->vector_elements) {
1293 case 1: emit(nir_op_fnoise4_1, dest_size, srcs); break;
1294 case 2: emit(nir_op_fnoise4_2, dest_size, srcs); break;
1295 case 3: emit(nir_op_fnoise4_3, dest_size, srcs); break;
1296 case 4: emit(nir_op_fnoise4_4, dest_size, srcs); break;
1297 default: unreachable("not reached");
1298 }
1299 break;
1300 default:
1301 unreachable("not reached");
1302 }
1303 break;
1304 case ir_binop_add:
1305 case ir_binop_sub:
1306 case ir_binop_mul:
1307 case ir_binop_div:
1308 case ir_binop_mod:
1309 case ir_binop_min:
1310 case ir_binop_max:
1311 case ir_binop_pow:
1312 case ir_binop_bit_and:
1313 case ir_binop_bit_or:
1314 case ir_binop_bit_xor:
1315 case ir_binop_logic_and:
1316 case ir_binop_logic_or:
1317 case ir_binop_logic_xor:
1318 case ir_binop_lshift:
1319 case ir_binop_rshift:
1320 switch (ir->operation) {
1321 case ir_binop_add:
1322 if (out_type == GLSL_TYPE_FLOAT)
1323 op = nir_op_fadd;
1324 else
1325 op = nir_op_iadd;
1326 break;
1327 case ir_binop_sub:
1328 if (out_type == GLSL_TYPE_FLOAT)
1329 op = nir_op_fsub;
1330 else
1331 op = nir_op_isub;
1332 break;
1333 case ir_binop_mul:
1334 if (out_type == GLSL_TYPE_FLOAT)
1335 op = nir_op_fmul;
1336 else
1337 op = nir_op_imul;
1338 break;
1339 case ir_binop_div:
1340 if (out_type == GLSL_TYPE_FLOAT)
1341 op = nir_op_fdiv;
1342 else if (out_type == GLSL_TYPE_INT)
1343 op = nir_op_idiv;
1344 else
1345 op = nir_op_udiv;
1346 break;
1347 case ir_binop_mod:
1348 if (out_type == GLSL_TYPE_FLOAT)
1349 op = nir_op_fmod;
1350 else
1351 op = nir_op_umod;
1352 break;
1353 case ir_binop_min:
1354 if (out_type == GLSL_TYPE_FLOAT)
1355 op = nir_op_fmin;
1356 else if (out_type == GLSL_TYPE_INT)
1357 op = nir_op_imin;
1358 else
1359 op = nir_op_umin;
1360 break;
1361 case ir_binop_max:
1362 if (out_type == GLSL_TYPE_FLOAT)
1363 op = nir_op_fmax;
1364 else if (out_type == GLSL_TYPE_INT)
1365 op = nir_op_imax;
1366 else
1367 op = nir_op_umax;
1368 break;
1369 case ir_binop_bit_and:
1370 op = nir_op_iand;
1371 break;
1372 case ir_binop_bit_or:
1373 op = nir_op_ior;
1374 break;
1375 case ir_binop_bit_xor:
1376 op = nir_op_ixor;
1377 break;
1378 case ir_binop_logic_and:
1379 if (supports_ints)
1380 op = nir_op_iand;
1381 else
1382 op = nir_op_fand;
1383 break;
1384 case ir_binop_logic_or:
1385 if (supports_ints)
1386 op = nir_op_ior;
1387 else
1388 op = nir_op_for;
1389 break;
1390 case ir_binop_logic_xor:
1391 if (supports_ints)
1392 op = nir_op_ixor;
1393 else
1394 op = nir_op_fxor;
1395 break;
1396 case ir_binop_lshift:
1397 op = nir_op_ishl;
1398 break;
1399 case ir_binop_rshift:
1400 if (out_type == GLSL_TYPE_INT)
1401 op = nir_op_ishr;
1402 else
1403 op = nir_op_ushr;
1404 break;
1405 case ir_binop_pow:
1406 op = nir_op_fpow;
1407 break;
1408
1409 default:
1410 unreachable("not reached");
1411 }
1412
1413 instr = emit(op, dest_size, srcs);
1414
1415 if (ir->operands[0]->type->vector_elements != 1 &&
1416 ir->operands[1]->type->vector_elements == 1) {
1417 for (unsigned i = 0; i < ir->operands[0]->type->vector_elements;
1418 i++) {
1419 instr->src[1].swizzle[i] = 0;
1420 }
1421 }
1422
1423 if (ir->operands[1]->type->vector_elements != 1 &&
1424 ir->operands[0]->type->vector_elements == 1) {
1425 for (unsigned i = 0; i < ir->operands[1]->type->vector_elements;
1426 i++) {
1427 instr->src[0].swizzle[i] = 0;
1428 }
1429 }
1430
1431 break;
1432 case ir_binop_imul_high:
1433 emit(out_type == GLSL_TYPE_UINT ? nir_op_umul_high : nir_op_imul_high,
1434 dest_size, srcs);
1435 break;
1436 case ir_binop_carry: emit(nir_op_uadd_carry, dest_size, srcs); break;
1437 case ir_binop_borrow: emit(nir_op_usub_borrow, dest_size, srcs); break;
1438 case ir_binop_less:
1439 if (supports_ints) {
1440 if (types[0] == GLSL_TYPE_FLOAT)
1441 emit(nir_op_flt, dest_size, srcs);
1442 else if (types[0] == GLSL_TYPE_INT)
1443 emit(nir_op_ilt, dest_size, srcs);
1444 else
1445 emit(nir_op_ult, dest_size, srcs);
1446 } else {
1447 emit(nir_op_slt, dest_size, srcs);
1448 }
1449 break;
1450 case ir_binop_greater:
1451 if (supports_ints) {
1452 if (types[0] == GLSL_TYPE_FLOAT)
1453 emit(nir_op_flt, dest_size, srcs[1], srcs[0]);
1454 else if (types[0] == GLSL_TYPE_INT)
1455 emit(nir_op_ilt, dest_size, srcs[1], srcs[0]);
1456 else
1457 emit(nir_op_ult, dest_size, srcs[1], srcs[0]);
1458 } else {
1459 emit(nir_op_slt, dest_size, srcs[1], srcs[0]);
1460 }
1461 break;
1462 case ir_binop_lequal:
1463 if (supports_ints) {
1464 if (types[0] == GLSL_TYPE_FLOAT)
1465 emit(nir_op_fge, dest_size, srcs[1], srcs[0]);
1466 else if (types[0] == GLSL_TYPE_INT)
1467 emit(nir_op_ige, dest_size, srcs[1], srcs[0]);
1468 else
1469 emit(nir_op_uge, dest_size, srcs[1], srcs[0]);
1470 } else {
1471 emit(nir_op_slt, dest_size, srcs[1], srcs[0]);
1472 }
1473 break;
1474 case ir_binop_gequal:
1475 if (supports_ints) {
1476 if (types[0] == GLSL_TYPE_FLOAT)
1477 emit(nir_op_fge, dest_size, srcs);
1478 else if (types[0] == GLSL_TYPE_INT)
1479 emit(nir_op_ige, dest_size, srcs);
1480 else
1481 emit(nir_op_uge, dest_size, srcs);
1482 } else {
1483 emit(nir_op_slt, dest_size, srcs);
1484 }
1485 break;
1486 case ir_binop_equal:
1487 if (supports_ints) {
1488 if (types[0] == GLSL_TYPE_FLOAT)
1489 emit(nir_op_feq, dest_size, srcs);
1490 else
1491 emit(nir_op_ieq, dest_size, srcs);
1492 } else {
1493 emit(nir_op_seq, dest_size, srcs);
1494 }
1495 break;
1496 case ir_binop_nequal:
1497 if (supports_ints) {
1498 if (types[0] == GLSL_TYPE_FLOAT)
1499 emit(nir_op_fne, dest_size, srcs);
1500 else
1501 emit(nir_op_ine, dest_size, srcs);
1502 } else {
1503 emit(nir_op_sne, dest_size, srcs);
1504 }
1505 break;
1506 case ir_binop_all_equal:
1507 if (supports_ints) {
1508 if (types[0] == GLSL_TYPE_FLOAT) {
1509 switch (ir->operands[0]->type->vector_elements) {
1510 case 1: emit(nir_op_feq, dest_size, srcs); break;
1511 case 2: emit(nir_op_ball_fequal2, dest_size, srcs); break;
1512 case 3: emit(nir_op_ball_fequal3, dest_size, srcs); break;
1513 case 4: emit(nir_op_ball_fequal4, dest_size, srcs); break;
1514 default:
1515 unreachable("not reached");
1516 }
1517 } else {
1518 switch (ir->operands[0]->type->vector_elements) {
1519 case 1: emit(nir_op_ieq, dest_size, srcs); break;
1520 case 2: emit(nir_op_ball_iequal2, dest_size, srcs); break;
1521 case 3: emit(nir_op_ball_iequal3, dest_size, srcs); break;
1522 case 4: emit(nir_op_ball_iequal4, dest_size, srcs); break;
1523 default:
1524 unreachable("not reached");
1525 }
1526 }
1527 } else {
1528 switch (ir->operands[0]->type->vector_elements) {
1529 case 1: emit(nir_op_seq, dest_size, srcs); break;
1530 case 2: emit(nir_op_fall_equal2, dest_size, srcs); break;
1531 case 3: emit(nir_op_fall_equal3, dest_size, srcs); break;
1532 case 4: emit(nir_op_fall_equal4, dest_size, srcs); break;
1533 default:
1534 unreachable("not reached");
1535 }
1536 }
1537 break;
1538 case ir_binop_any_nequal:
1539 if (supports_ints) {
1540 if (types[0] == GLSL_TYPE_FLOAT) {
1541 switch (ir->operands[0]->type->vector_elements) {
1542 case 1: emit(nir_op_fne, dest_size, srcs); break;
1543 case 2: emit(nir_op_bany_fnequal2, dest_size, srcs); break;
1544 case 3: emit(nir_op_bany_fnequal3, dest_size, srcs); break;
1545 case 4: emit(nir_op_bany_fnequal4, dest_size, srcs); break;
1546 default:
1547 unreachable("not reached");
1548 }
1549 } else {
1550 switch (ir->operands[0]->type->vector_elements) {
1551 case 1: emit(nir_op_ine, dest_size, srcs); break;
1552 case 2: emit(nir_op_bany_inequal2, dest_size, srcs); break;
1553 case 3: emit(nir_op_bany_inequal3, dest_size, srcs); break;
1554 case 4: emit(nir_op_bany_inequal4, dest_size, srcs); break;
1555 default:
1556 unreachable("not reached");
1557 }
1558 }
1559 } else {
1560 switch (ir->operands[0]->type->vector_elements) {
1561 case 1: emit(nir_op_sne, dest_size, srcs); break;
1562 case 2: emit(nir_op_fany_nequal2, dest_size, srcs); break;
1563 case 3: emit(nir_op_fany_nequal3, dest_size, srcs); break;
1564 case 4: emit(nir_op_fany_nequal4, dest_size, srcs); break;
1565 default:
1566 unreachable("not reached");
1567 }
1568 }
1569 break;
1570 case ir_binop_dot:
1571 switch (ir->operands[0]->type->vector_elements) {
1572 case 2: emit(nir_op_fdot2, dest_size, srcs); break;
1573 case 3: emit(nir_op_fdot3, dest_size, srcs); break;
1574 case 4: emit(nir_op_fdot4, dest_size, srcs); break;
1575 default:
1576 unreachable("not reached");
1577 }
1578 break;
1579
1580 case ir_binop_pack_half_2x16_split:
1581 emit(nir_op_pack_half_2x16_split, dest_size, srcs);
1582 break;
1583 case ir_binop_bfm: emit(nir_op_bfm, dest_size, srcs); break;
1584 case ir_binop_ldexp: emit(nir_op_ldexp, dest_size, srcs); break;
1585 case ir_triop_fma: emit(nir_op_ffma, dest_size, srcs); break;
1586 case ir_triop_lrp:
1587 instr = emit(nir_op_flrp, dest_size, srcs);
1588 if (ir->operands[0]->type->vector_elements != 1 &&
1589 ir->operands[2]->type->vector_elements == 1) {
1590 for (unsigned i = 0; i < ir->operands[0]->type->vector_elements;
1591 i++) {
1592 instr->src[2].swizzle[i] = 0;
1593 }
1594 }
1595 break;
1596 case ir_triop_csel:
1597 if (supports_ints)
1598 emit(nir_op_bcsel, dest_size, srcs);
1599 else
1600 emit(nir_op_fcsel, dest_size, srcs);
1601 break;
1602 case ir_triop_bfi:
1603 instr = emit(nir_op_bfi, dest_size, srcs);
1604 for (unsigned i = 0; i < ir->operands[1]->type->vector_elements; i++) {
1605 instr->src[0].swizzle[i] = 0;
1606 }
1607 break;
1608 case ir_triop_bitfield_extract:
1609 instr = emit(out_type == GLSL_TYPE_INT ? nir_op_ibitfield_extract :
1610 nir_op_ubitfield_extract, dest_size, srcs);
1611 for (unsigned i = 0; i < ir->operands[0]->type->vector_elements; i++) {
1612 instr->src[1].swizzle[i] = 0;
1613 instr->src[2].swizzle[i] = 0;
1614 }
1615 break;
1616 case ir_quadop_bitfield_insert:
1617 instr = emit(nir_op_bitfield_insert, dest_size, srcs);
1618 for (unsigned i = 0; i < ir->operands[0]->type->vector_elements; i++) {
1619 instr->src[2].swizzle[i] = 0;
1620 instr->src[3].swizzle[i] = 0;
1621 }
1622 break;
1623 case ir_quadop_vector:
1624 switch (ir->type->vector_elements) {
1625 case 2: emit(nir_op_vec2, dest_size, srcs); break;
1626 case 3: emit(nir_op_vec3, dest_size, srcs); break;
1627 case 4: emit(nir_op_vec4, dest_size, srcs); break;
1628 default: unreachable("not reached");
1629 }
1630 break;
1631
1632 default:
1633 unreachable("not reached");
1634 }
1635 }
1636
1637 void
1638 nir_visitor::visit(ir_swizzle *ir)
1639 {
1640 nir_alu_instr *instr = emit(supports_ints ? nir_op_imov : nir_op_fmov,
1641 ir->type->vector_elements,
1642 evaluate_rvalue(ir->val));
1643
1644 unsigned swizzle[4] = { ir->mask.x, ir->mask.y, ir->mask.z, ir->mask.w };
1645 for (unsigned i = 0; i < ir->type->vector_elements; i++)
1646 instr->src[0].swizzle[i] = swizzle[i];
1647 }
1648
1649 void
1650 nir_visitor::visit(ir_texture *ir)
1651 {
1652 unsigned num_srcs;
1653 nir_texop op;
1654 switch (ir->op) {
1655 case ir_tex:
1656 op = nir_texop_tex;
1657 num_srcs = 1; /* coordinate */
1658 break;
1659
1660 case ir_txb:
1661 case ir_txl:
1662 op = (ir->op == ir_txb) ? nir_texop_txb : nir_texop_txl;
1663 num_srcs = 2; /* coordinate, bias/lod */
1664 break;
1665
1666 case ir_txd:
1667 op = nir_texop_txd; /* coordinate, dPdx, dPdy */
1668 num_srcs = 3;
1669 break;
1670
1671 case ir_txf:
1672 op = nir_texop_txf;
1673 if (ir->lod_info.lod != NULL)
1674 num_srcs = 2; /* coordinate, lod */
1675 else
1676 num_srcs = 1; /* coordinate */
1677 break;
1678
1679 case ir_txf_ms:
1680 op = nir_texop_txf_ms;
1681 num_srcs = 2; /* coordinate, sample_index */
1682 break;
1683
1684 case ir_txs:
1685 op = nir_texop_txs;
1686 if (ir->lod_info.lod != NULL)
1687 num_srcs = 1; /* lod */
1688 else
1689 num_srcs = 0;
1690 break;
1691
1692 case ir_lod:
1693 op = nir_texop_lod;
1694 num_srcs = 1; /* coordinate */
1695 break;
1696
1697 case ir_tg4:
1698 op = nir_texop_tg4;
1699 num_srcs = 1; /* coordinate */
1700 break;
1701
1702 case ir_query_levels:
1703 op = nir_texop_query_levels;
1704 num_srcs = 0;
1705 break;
1706
1707 default:
1708 unreachable("not reached");
1709 }
1710
1711 if (ir->projector != NULL)
1712 num_srcs++;
1713 if (ir->shadow_comparitor != NULL)
1714 num_srcs++;
1715 if (ir->offset != NULL && ir->offset->as_constant() == NULL)
1716 num_srcs++;
1717
1718 nir_tex_instr *instr = nir_tex_instr_create(this->shader, num_srcs);
1719
1720 instr->op = op;
1721 instr->sampler_dim =
1722 (glsl_sampler_dim) ir->sampler->type->sampler_dimensionality;
1723 instr->is_array = ir->sampler->type->sampler_array;
1724 instr->is_shadow = ir->sampler->type->sampler_shadow;
1725 if (instr->is_shadow)
1726 instr->is_new_style_shadow = (ir->type->vector_elements == 1);
1727 switch (ir->type->base_type) {
1728 case GLSL_TYPE_FLOAT:
1729 instr->dest_type = nir_type_float;
1730 break;
1731 case GLSL_TYPE_INT:
1732 instr->dest_type = nir_type_int;
1733 break;
1734 case GLSL_TYPE_UINT:
1735 instr->dest_type = nir_type_unsigned;
1736 break;
1737 default:
1738 unreachable("not reached");
1739 }
1740
1741 instr->sampler = evaluate_deref(&instr->instr, ir->sampler);
1742
1743 unsigned src_number = 0;
1744
1745 if (ir->coordinate != NULL) {
1746 instr->coord_components = ir->coordinate->type->vector_elements;
1747 instr->src[src_number].src = evaluate_rvalue(ir->coordinate);
1748 instr->src[src_number].src_type = nir_tex_src_coord;
1749 src_number++;
1750 }
1751
1752 if (ir->projector != NULL) {
1753 instr->src[src_number].src = evaluate_rvalue(ir->projector);
1754 instr->src[src_number].src_type = nir_tex_src_projector;
1755 src_number++;
1756 }
1757
1758 if (ir->shadow_comparitor != NULL) {
1759 instr->src[src_number].src = evaluate_rvalue(ir->shadow_comparitor);
1760 instr->src[src_number].src_type = nir_tex_src_comparitor;
1761 src_number++;
1762 }
1763
1764 if (ir->offset != NULL) {
1765 /* we don't support multiple offsets yet */
1766 assert(ir->offset->type->is_vector() || ir->offset->type->is_scalar());
1767
1768 ir_constant *const_offset = ir->offset->as_constant();
1769 if (const_offset != NULL) {
1770 for (unsigned i = 0; i < const_offset->type->vector_elements; i++)
1771 instr->const_offset[i] = const_offset->value.i[i];
1772 } else {
1773 instr->src[src_number].src = evaluate_rvalue(ir->offset);
1774 instr->src[src_number].src_type = nir_tex_src_offset;
1775 src_number++;
1776 }
1777 }
1778
1779 switch (ir->op) {
1780 case ir_txb:
1781 instr->src[src_number].src = evaluate_rvalue(ir->lod_info.bias);
1782 instr->src[src_number].src_type = nir_tex_src_bias;
1783 src_number++;
1784 break;
1785
1786 case ir_txl:
1787 case ir_txf:
1788 case ir_txs:
1789 if (ir->lod_info.lod != NULL) {
1790 instr->src[src_number].src = evaluate_rvalue(ir->lod_info.lod);
1791 instr->src[src_number].src_type = nir_tex_src_lod;
1792 src_number++;
1793 }
1794 break;
1795
1796 case ir_txd:
1797 instr->src[src_number].src = evaluate_rvalue(ir->lod_info.grad.dPdx);
1798 instr->src[src_number].src_type = nir_tex_src_ddx;
1799 src_number++;
1800 instr->src[src_number].src = evaluate_rvalue(ir->lod_info.grad.dPdy);
1801 instr->src[src_number].src_type = nir_tex_src_ddy;
1802 src_number++;
1803 break;
1804
1805 case ir_txf_ms:
1806 instr->src[src_number].src = evaluate_rvalue(ir->lod_info.sample_index);
1807 instr->src[src_number].src_type = nir_tex_src_ms_index;
1808 src_number++;
1809 break;
1810
1811 case ir_tg4:
1812 instr->component = ir->lod_info.component->as_constant()->value.u[0];
1813 break;
1814
1815 default:
1816 break;
1817 }
1818
1819 assert(src_number == num_srcs);
1820
1821 add_instr(&instr->instr, nir_tex_instr_dest_size(instr));
1822 }
1823
1824 void
1825 nir_visitor::visit(ir_constant *ir)
1826 {
1827 /*
1828 * We don't know if this variable is an an array or struct that gets
1829 * dereferenced, so do the safe thing an make it a variable with a
1830 * constant initializer and return a dereference.
1831 */
1832
1833 nir_variable *var = ralloc(this->shader, nir_variable);
1834 var->name = ralloc_strdup(var, "const_temp");
1835 var->type = ir->type;
1836 var->data.mode = nir_var_local;
1837 var->data.read_only = true;
1838 var->constant_initializer = constant_copy(ir, var);
1839 exec_list_push_tail(&this->impl->locals, &var->node);
1840
1841 this->deref_head = nir_deref_var_create(this->shader, var);
1842 this->deref_tail = &this->deref_head->deref;
1843 }
1844
1845 void
1846 nir_visitor::visit(ir_dereference_variable *ir)
1847 {
1848 struct hash_entry *entry =
1849 _mesa_hash_table_search(this->var_table, ir->var);
1850 assert(entry);
1851 nir_variable *var = (nir_variable *) entry->data;
1852
1853 nir_deref_var *deref = nir_deref_var_create(this->shader, var);
1854 this->deref_head = deref;
1855 this->deref_tail = &deref->deref;
1856 }
1857
1858 void
1859 nir_visitor::visit(ir_dereference_record *ir)
1860 {
1861 ir->record->accept(this);
1862
1863 int field_index = this->deref_tail->type->field_index(ir->field);
1864 assert(field_index >= 0);
1865
1866 nir_deref_struct *deref = nir_deref_struct_create(this->deref_tail, field_index);
1867 deref->deref.type = ir->type;
1868 this->deref_tail->child = &deref->deref;
1869 this->deref_tail = &deref->deref;
1870 }
1871
1872 void
1873 nir_visitor::visit(ir_dereference_array *ir)
1874 {
1875 nir_deref_array *deref = nir_deref_array_create(this->shader);
1876 deref->deref.type = ir->type;
1877
1878 ir_constant *const_index = ir->array_index->as_constant();
1879 if (const_index != NULL) {
1880 deref->deref_array_type = nir_deref_array_type_direct;
1881 deref->base_offset = const_index->value.u[0];
1882 } else {
1883 deref->deref_array_type = nir_deref_array_type_indirect;
1884 deref->indirect = evaluate_rvalue(ir->array_index);
1885 }
1886
1887 ir->array->accept(this);
1888
1889 this->deref_tail->child = &deref->deref;
1890 ralloc_steal(this->deref_tail, deref);
1891 this->deref_tail = &deref->deref;
1892 }
1893
1894 void
1895 nir_visitor::visit(ir_barrier *ir)
1896 {
1897 unreachable("Not implemented!");
1898 }