2 * Copyright © 2014 Intel Corporation
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:
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
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
24 * Connor Abbott (cwabbott0@gmail.com)
31 global_to_local(nir_register
*reg
)
33 nir_function_impl
*impl
= NULL
;
35 assert(reg
->is_global
);
37 struct set_entry
*entry
;
38 set_foreach(reg
->defs
, entry
) {
39 nir_instr
*instr
= (nir_instr
*) entry
->key
;
40 nir_function_impl
*instr_impl
=
41 nir_cf_node_get_function(&instr
->block
->cf_node
);
43 if (impl
!= instr_impl
)
50 set_foreach(reg
->uses
, entry
) {
51 nir_instr
*instr
= (nir_instr
*) entry
->key
;
52 nir_function_impl
*instr_impl
=
53 nir_cf_node_get_function(&instr
->block
->cf_node
);
55 if (impl
!= instr_impl
)
62 set_foreach(reg
->if_uses
, entry
) {
63 nir_if
*if_stmt
= (nir_if
*) entry
->key
;
64 nir_function_impl
*if_impl
= nir_cf_node_get_function(&if_stmt
->cf_node
);
74 /* this instruction is never used/defined, delete it */
80 * if we've gotten to this point, the register is always used/defined in
81 * the same implementation so we can move it to be local to that
85 exec_node_remove(®
->node
);
86 exec_list_push_tail(&impl
->registers
, ®
->node
);
87 reg
->index
= impl
->reg_alloc
++;
88 reg
->is_global
= false;
93 nir_opt_global_to_local(nir_shader
*shader
)
95 bool progress
= false;
97 foreach_list_typed_safe(nir_register
, reg
, node
, &shader
->registers
) {
98 if (global_to_local(reg
))