2 * Copyright © 2015 Thomas Helland
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
25 #include "nir_constant_expressions.h"
26 #include "nir_loop_analyze.h"
33 } nir_loop_variable_type
;
35 struct nir_basic_induction_var
;
38 /* A link for the work list */
39 struct list_head process_link
;
43 /* The ssa_def associated with this info */
46 /* The type of this ssa_def */
47 nir_loop_variable_type type
;
49 /* If this is of type basic_induction */
50 struct nir_basic_induction_var
*ind
;
52 /* True if variable is in an if branch */
55 /* True if variable is in a nested loop */
60 typedef struct nir_basic_induction_var
{
61 nir_op alu_op
; /* The type of alu-operation */
62 nir_loop_variable
*alu_def
; /* The def of the alu-operation */
63 nir_loop_variable
*invariant
; /* The invariant alu-operand */
64 nir_loop_variable
*def_outside_loop
; /* The phi-src outside the loop */
65 } nir_basic_induction_var
;
68 /* The loop we store information for */
71 /* Loop_variable for all ssa_defs in function */
72 nir_loop_variable
*loop_vars
;
74 /* A list of the loop_vars to analyze */
75 struct list_head process_list
;
77 nir_variable_mode indirect_mask
;
81 static nir_loop_variable
*
82 get_loop_var(nir_ssa_def
*value
, loop_info_state
*state
)
84 return &(state
->loop_vars
[value
->index
]);
88 loop_info_state
*state
;
94 init_loop_def(nir_ssa_def
*def
, void *void_init_loop_state
)
96 init_loop_state
*loop_init_state
= void_init_loop_state
;
97 nir_loop_variable
*var
= get_loop_var(def
, loop_init_state
->state
);
99 if (loop_init_state
->in_nested_loop
) {
100 var
->in_nested_loop
= true;
101 } else if (loop_init_state
->in_if_branch
) {
102 var
->in_if_branch
= true;
104 /* Add to the tail of the list. That way we start at the beginning of
105 * the defs in the loop instead of the end when walking the list. This
106 * means less recursive calls. Only add defs that are not in nested
107 * loops or conditional blocks.
109 list_addtail(&var
->process_link
, &loop_init_state
->state
->process_list
);
118 init_loop_block(nir_block
*block
, loop_info_state
*state
,
119 bool in_if_branch
, bool in_nested_loop
)
121 init_loop_state init_state
= {.in_if_branch
= in_if_branch
,
122 .in_nested_loop
= in_nested_loop
,
125 nir_foreach_instr(instr
, block
) {
126 if (instr
->type
== nir_instr_type_intrinsic
||
127 instr
->type
== nir_instr_type_alu
||
128 instr
->type
== nir_instr_type_tex
) {
129 state
->loop
->info
->num_instructions
++;
132 nir_foreach_ssa_def(instr
, init_loop_def
, &init_state
);
139 is_var_alu(nir_loop_variable
*var
)
141 return var
->def
->parent_instr
->type
== nir_instr_type_alu
;
145 is_var_constant(nir_loop_variable
*var
)
147 return var
->def
->parent_instr
->type
== nir_instr_type_load_const
;
151 is_var_phi(nir_loop_variable
*var
)
153 return var
->def
->parent_instr
->type
== nir_instr_type_phi
;
157 mark_invariant(nir_ssa_def
*def
, loop_info_state
*state
)
159 nir_loop_variable
*var
= get_loop_var(def
, state
);
161 if (var
->type
== invariant
)
165 var
->type
= invariant
;
169 if (var
->type
== not_invariant
)
172 if (is_var_alu(var
)) {
173 nir_alu_instr
*alu
= nir_instr_as_alu(def
->parent_instr
);
175 for (unsigned i
= 0; i
< nir_op_infos
[alu
->op
].num_inputs
; i
++) {
176 if (!mark_invariant(alu
->src
[i
].src
.ssa
, state
)) {
177 var
->type
= not_invariant
;
181 var
->type
= invariant
;
185 /* Phis shouldn't be invariant except if one operand is invariant, and the
186 * other is the phi itself. These should be removed by opt_remove_phis.
187 * load_consts are already set to invariant and constant during init,
188 * and so should return earlier. Remaining op_codes are set undefined.
190 var
->type
= not_invariant
;
195 compute_invariance_information(loop_info_state
*state
)
197 /* An expression is invariant in a loop L if:
200 * – it’s a variable use, all of whose single defs are outside of L
202 * – it’s a pure computation all of whose args are loop invariant
203 * – it’s a variable use whose single reaching def, and the
204 * rhs of that def is loop-invariant
206 list_for_each_entry_safe(nir_loop_variable
, var
, &state
->process_list
,
208 assert(!var
->in_if_branch
&& !var
->in_nested_loop
);
210 if (mark_invariant(var
->def
, state
))
211 list_del(&var
->process_link
);
216 compute_induction_information(loop_info_state
*state
)
218 bool found_induction_var
= false;
219 list_for_each_entry_safe(nir_loop_variable
, var
, &state
->process_list
,
222 /* It can't be an induction variable if it is invariant. Invariants and
223 * things in nested loops or conditionals should have been removed from
224 * the list by compute_invariance_information().
226 assert(!var
->in_if_branch
&& !var
->in_nested_loop
&&
227 var
->type
!= invariant
);
229 /* We are only interested in checking phis for the basic induction
230 * variable case as its simple to detect. All basic induction variables
233 if (!is_var_phi(var
))
236 nir_phi_instr
*phi
= nir_instr_as_phi(var
->def
->parent_instr
);
237 nir_basic_induction_var
*biv
= rzalloc(state
, nir_basic_induction_var
);
239 nir_foreach_phi_src(src
, phi
) {
240 nir_loop_variable
*src_var
= get_loop_var(src
->src
.ssa
, state
);
242 /* If one of the sources is in an if branch or nested loop then don't
243 * attempt to go any further.
245 if (src_var
->in_if_branch
|| src_var
->in_nested_loop
)
248 if (!src_var
->in_loop
) {
249 biv
->def_outside_loop
= src_var
;
250 } else if (is_var_alu(src_var
)) {
251 nir_alu_instr
*alu
= nir_instr_as_alu(src_var
->def
->parent_instr
);
253 if (nir_op_infos
[alu
->op
].num_inputs
== 2) {
254 biv
->alu_def
= src_var
;
255 biv
->alu_op
= alu
->op
;
257 for (unsigned i
= 0; i
< 2; i
++) {
258 /* Is one of the operands const, and the other the phi */
259 if (alu
->src
[i
].src
.ssa
->parent_instr
->type
== nir_instr_type_load_const
&&
260 alu
->src
[1-i
].src
.ssa
== &phi
->dest
.ssa
)
261 biv
->invariant
= get_loop_var(alu
->src
[i
].src
.ssa
, state
);
267 if (biv
->alu_def
&& biv
->def_outside_loop
&& biv
->invariant
&&
268 is_var_constant(biv
->def_outside_loop
)) {
269 assert(is_var_constant(biv
->invariant
));
270 biv
->alu_def
->type
= basic_induction
;
271 biv
->alu_def
->ind
= biv
;
272 var
->type
= basic_induction
;
275 found_induction_var
= true;
280 return found_induction_var
;
284 initialize_ssa_def(nir_ssa_def
*def
, void *void_state
)
286 loop_info_state
*state
= void_state
;
287 nir_loop_variable
*var
= get_loop_var(def
, state
);
289 var
->in_loop
= false;
292 if (def
->parent_instr
->type
== nir_instr_type_load_const
) {
293 var
->type
= invariant
;
295 var
->type
= undefined
;
302 find_loop_terminators(loop_info_state
*state
)
304 bool success
= false;
305 foreach_list_typed_safe(nir_cf_node
, node
, node
, &state
->loop
->body
) {
306 if (node
->type
== nir_cf_node_if
) {
307 nir_if
*nif
= nir_cf_node_as_if(node
);
309 nir_block
*break_blk
= NULL
;
310 nir_block
*continue_from_blk
= NULL
;
311 bool continue_from_then
= true;
313 nir_block
*last_then
= nir_if_last_then_block(nif
);
314 nir_block
*last_else
= nir_if_last_else_block(nif
);
315 if (nir_block_ends_in_break(last_then
)) {
316 break_blk
= last_then
;
317 continue_from_blk
= last_else
;
318 continue_from_then
= false;
319 } else if (nir_block_ends_in_break(last_else
)) {
320 break_blk
= last_else
;
321 continue_from_blk
= last_then
;
324 /* If there is a break then we should find a terminator. If we can
325 * not find a loop terminator, but there is a break-statement then
326 * we should return false so that we do not try to find trip-count
328 if (!nir_is_trivial_loop_if(nif
, break_blk
)) {
329 state
->loop
->info
->complex_loop
= true;
333 /* Continue if the if contained no jumps at all */
337 if (nif
->condition
.ssa
->parent_instr
->type
== nir_instr_type_phi
) {
338 state
->loop
->info
->complex_loop
= true;
342 nir_loop_terminator
*terminator
=
343 rzalloc(state
->loop
->info
, nir_loop_terminator
);
345 list_addtail(&terminator
->loop_terminator_link
,
346 &state
->loop
->info
->loop_terminator_list
);
348 terminator
->nif
= nif
;
349 terminator
->break_block
= break_blk
;
350 terminator
->continue_from_block
= continue_from_blk
;
351 terminator
->continue_from_then
= continue_from_then
;
352 terminator
->conditional_instr
= nif
->condition
.ssa
->parent_instr
;
361 /* This function looks for an array access within a loop that uses an
362 * induction variable for the array index. If found it returns the size of the
363 * array, otherwise 0 is returned. If we find an induction var we pass it back
364 * to the caller via array_index_out.
367 find_array_access_via_induction(loop_info_state
*state
,
368 nir_deref_instr
*deref
,
369 nir_loop_variable
**array_index_out
)
371 for (nir_deref_instr
*d
= deref
; d
; d
= nir_deref_instr_parent(d
)) {
372 if (d
->deref_type
!= nir_deref_type_array
)
375 assert(d
->arr
.index
.is_ssa
);
376 nir_loop_variable
*array_index
= get_loop_var(d
->arr
.index
.ssa
, state
);
378 if (array_index
->type
!= basic_induction
)
382 *array_index_out
= array_index
;
384 nir_deref_instr
*parent
= nir_deref_instr_parent(d
);
385 assert(glsl_type_is_array_or_matrix(parent
->type
));
387 return glsl_get_length(parent
->type
);
394 get_iteration(nir_op cond_op
, nir_const_value
*initial
, nir_const_value
*step
,
395 nir_const_value
*limit
)
404 int32_t initial_val
= initial
->i32
[0];
405 int32_t span
= limit
->i32
[0] - initial_val
;
406 iter
= span
/ step
->i32
[0];
411 uint32_t initial_val
= initial
->u32
[0];
412 uint32_t span
= limit
->u32
[0] - initial_val
;
413 iter
= span
/ step
->u32
[0];
420 float initial_val
= initial
->f32
[0];
421 float span
= limit
->f32
[0] - initial_val
;
422 iter
= span
/ step
->f32
[0];
433 test_iterations(int32_t iter_int
, nir_const_value
*step
,
434 nir_const_value
*limit
, nir_op cond_op
, unsigned bit_size
,
435 nir_alu_type induction_base_type
,
436 nir_const_value
*initial
, bool limit_rhs
, bool invert_cond
)
438 assert(nir_op_infos
[cond_op
].num_inputs
== 2);
440 nir_const_value iter_src
= { {0, } };
443 switch (induction_base_type
) {
445 iter_src
.f32
[0] = (float) iter_int
;
446 mul_op
= nir_op_fmul
;
447 add_op
= nir_op_fadd
;
451 iter_src
.i32
[0] = iter_int
;
452 mul_op
= nir_op_imul
;
453 add_op
= nir_op_iadd
;
456 unreachable("Unhandled induction variable base type!");
459 /* Multiple the iteration count we are testing by the number of times we
460 * step the induction variable each iteration.
462 nir_const_value mul_src
[2] = { iter_src
, *step
};
463 nir_const_value mul_result
=
464 nir_eval_const_opcode(mul_op
, 1, bit_size
, mul_src
);
466 /* Add the initial value to the accumulated induction variable total */
467 nir_const_value add_src
[2] = { mul_result
, *initial
};
468 nir_const_value add_result
=
469 nir_eval_const_opcode(add_op
, 1, bit_size
, add_src
);
471 nir_const_value src
[2] = { { {0, } }, { {0, } } };
472 src
[limit_rhs
? 0 : 1] = add_result
;
473 src
[limit_rhs
? 1 : 0] = *limit
;
475 /* Evaluate the loop exit condition */
476 nir_const_value result
= nir_eval_const_opcode(cond_op
, 1, bit_size
, src
);
478 return invert_cond
? (result
.u32
[0] == 0) : (result
.u32
[0] != 0);
482 calculate_iterations(nir_const_value
*initial
, nir_const_value
*step
,
483 nir_const_value
*limit
, nir_loop_variable
*alu_def
,
484 nir_alu_instr
*cond_alu
, bool limit_rhs
, bool invert_cond
)
486 assert(initial
!= NULL
&& step
!= NULL
&& limit
!= NULL
);
488 nir_alu_instr
*alu
= nir_instr_as_alu(alu_def
->def
->parent_instr
);
490 /* nir_op_isub should have been lowered away by this point */
491 assert(alu
->op
!= nir_op_isub
);
493 /* Make sure the alu type for our induction variable is compatible with the
494 * conditional alus input type. If its not something has gone really wrong.
496 nir_alu_type induction_base_type
=
497 nir_alu_type_get_base_type(nir_op_infos
[alu
->op
].output_type
);
498 if (induction_base_type
== nir_type_int
|| induction_base_type
== nir_type_uint
) {
499 assert(nir_alu_type_get_base_type(nir_op_infos
[cond_alu
->op
].input_types
[1]) == nir_type_int
||
500 nir_alu_type_get_base_type(nir_op_infos
[cond_alu
->op
].input_types
[1]) == nir_type_uint
);
502 assert(nir_alu_type_get_base_type(nir_op_infos
[cond_alu
->op
].input_types
[0]) ==
503 induction_base_type
);
506 /* Check for nsupported alu operations */
507 if (alu
->op
!= nir_op_iadd
&& alu
->op
!= nir_op_fadd
)
510 /* do-while loops can increment the starting value before the condition is
517 * Here we check if the induction variable is used directly by the loop
518 * condition and if so we assume we need to step the initial value.
520 unsigned trip_offset
= 0;
521 if (cond_alu
->src
[0].src
.ssa
== alu_def
->def
||
522 cond_alu
->src
[1].src
.ssa
== alu_def
->def
) {
526 int iter_int
= get_iteration(cond_alu
->op
, initial
, step
, limit
);
528 /* If iter_int is negative the loop is ill-formed or is the conditional is
529 * unsigned with a huge iteration count so don't bother going any further.
534 /* An explanation from the GLSL unrolling pass:
536 * Make sure that the calculated number of iterations satisfies the exit
537 * condition. This is needed to catch off-by-one errors and some types of
538 * ill-formed loops. For example, we need to detect that the following
539 * loop does not have a maximum iteration count.
541 * for (float x = 0.0; x != 0.9; x += 0.2);
543 assert(nir_src_bit_size(alu
->src
[0].src
) ==
544 nir_src_bit_size(alu
->src
[1].src
));
545 unsigned bit_size
= nir_src_bit_size(alu
->src
[0].src
);
546 for (int bias
= -1; bias
<= 1; bias
++) {
547 const int iter_bias
= iter_int
+ bias
;
549 if (test_iterations(iter_bias
, step
, limit
, cond_alu
->op
, bit_size
,
550 induction_base_type
, initial
,
551 limit_rhs
, invert_cond
)) {
552 return iter_bias
> 0 ? iter_bias
- trip_offset
: iter_bias
;
559 /* Run through each of the terminators of the loop and try to infer a possible
560 * trip-count. We need to check them all, and set the lowest trip-count as the
561 * trip-count of our loop. If one of the terminators has an undecidable
562 * trip-count we can not safely assume anything about the duration of the
566 find_trip_count(loop_info_state
*state
)
568 bool trip_count_known
= true;
569 nir_loop_terminator
*limiting_terminator
= NULL
;
570 int max_trip_count
= -1;
572 list_for_each_entry(nir_loop_terminator
, terminator
,
573 &state
->loop
->info
->loop_terminator_list
,
574 loop_terminator_link
) {
576 if (terminator
->conditional_instr
->type
!= nir_instr_type_alu
) {
577 /* If we get here the loop is dead and will get cleaned up by the
578 * nir_opt_dead_cf pass.
580 trip_count_known
= false;
584 nir_alu_instr
*alu
= nir_instr_as_alu(terminator
->conditional_instr
);
585 nir_loop_variable
*basic_ind
= NULL
;
586 nir_loop_variable
*limit
= NULL
;
587 bool limit_rhs
= true;
590 case nir_op_fge
: case nir_op_ige
: case nir_op_uge
:
591 case nir_op_flt
: case nir_op_ilt
: case nir_op_ult
:
592 case nir_op_feq
: case nir_op_ieq
:
593 case nir_op_fne
: case nir_op_ine
:
595 /* We assume that the limit is the "right" operand */
596 basic_ind
= get_loop_var(alu
->src
[0].src
.ssa
, state
);
597 limit
= get_loop_var(alu
->src
[1].src
.ssa
, state
);
599 if (basic_ind
->type
!= basic_induction
) {
600 /* We had it the wrong way, flip things around */
601 basic_ind
= get_loop_var(alu
->src
[1].src
.ssa
, state
);
602 limit
= get_loop_var(alu
->src
[0].src
.ssa
, state
);
606 /* The comparison has to have a basic induction variable
607 * and a constant for us to be able to find trip counts
609 if (basic_ind
->type
!= basic_induction
|| !is_var_constant(limit
)) {
610 trip_count_known
= false;
614 /* We have determined that we have the following constants:
615 * (With the typical int i = 0; i < x; i++; as an example)
618 * - Step / iteration size
619 * Thats all thats needed to calculate the trip-count
622 nir_const_value initial_val
=
623 nir_instr_as_load_const(basic_ind
->ind
->def_outside_loop
->
624 def
->parent_instr
)->value
;
626 nir_const_value step_val
=
627 nir_instr_as_load_const(basic_ind
->ind
->invariant
->def
->
628 parent_instr
)->value
;
630 nir_const_value limit_val
=
631 nir_instr_as_load_const(limit
->def
->parent_instr
)->value
;
633 int iterations
= calculate_iterations(&initial_val
, &step_val
,
635 basic_ind
->ind
->alu_def
, alu
,
637 terminator
->continue_from_then
);
639 /* Where we not able to calculate the iteration count */
640 if (iterations
== -1) {
641 trip_count_known
= false;
645 /* If this is the first run or we have found a smaller amount of
646 * iterations than previously (we have identified a more limiting
647 * terminator) set the trip count and limiting terminator.
649 if (max_trip_count
== -1 || iterations
< max_trip_count
) {
650 max_trip_count
= iterations
;
651 limiting_terminator
= terminator
;
656 trip_count_known
= false;
660 state
->loop
->info
->exact_trip_count_known
= trip_count_known
;
661 if (max_trip_count
> -1)
662 state
->loop
->info
->max_trip_count
= max_trip_count
;
663 state
->loop
->info
->limiting_terminator
= limiting_terminator
;
667 force_unroll_array_access(loop_info_state
*state
, nir_deref_instr
*deref
)
669 unsigned array_size
= find_array_access_via_induction(state
, deref
, NULL
);
671 if (array_size
== state
->loop
->info
->max_trip_count
)
674 if (deref
->mode
& state
->indirect_mask
)
682 force_unroll_heuristics(loop_info_state
*state
, nir_block
*block
)
684 nir_foreach_instr(instr
, block
) {
685 if (instr
->type
!= nir_instr_type_intrinsic
)
688 nir_intrinsic_instr
*intrin
= nir_instr_as_intrinsic(instr
);
690 /* Check for arrays variably-indexed by a loop induction variable.
691 * Unrolling the loop may convert that access into constant-indexing.
693 if (intrin
->intrinsic
== nir_intrinsic_load_deref
||
694 intrin
->intrinsic
== nir_intrinsic_store_deref
||
695 intrin
->intrinsic
== nir_intrinsic_copy_deref
) {
696 if (force_unroll_array_access(state
,
697 nir_src_as_deref(intrin
->src
[0])))
700 if (intrin
->intrinsic
== nir_intrinsic_copy_deref
&&
701 force_unroll_array_access(state
,
702 nir_src_as_deref(intrin
->src
[1])))
711 get_loop_info(loop_info_state
*state
, nir_function_impl
*impl
)
713 /* Initialize all variables to "outside_loop". This also marks defs
714 * invariant and constant if they are nir_instr_type_load_consts
716 nir_foreach_block(block
, impl
) {
717 nir_foreach_instr(instr
, block
)
718 nir_foreach_ssa_def(instr
, initialize_ssa_def
, state
);
721 /* Add all entries in the outermost part of the loop to the processing list
722 * Mark the entries in conditionals or in nested loops accordingly
724 foreach_list_typed_safe(nir_cf_node
, node
, node
, &state
->loop
->body
) {
725 switch (node
->type
) {
727 case nir_cf_node_block
:
728 init_loop_block(nir_cf_node_as_block(node
), state
, false, false);
732 nir_foreach_block_in_cf_node(block
, node
)
733 init_loop_block(block
, state
, true, false);
736 case nir_cf_node_loop
:
737 nir_foreach_block_in_cf_node(block
, node
) {
738 init_loop_block(block
, state
, false, true);
742 case nir_cf_node_function
:
747 /* Try to find all simple terminators of the loop. If we can't find any,
748 * or we find possible terminators that have side effects then bail.
750 if (!find_loop_terminators(state
)) {
751 list_for_each_entry_safe(nir_loop_terminator
, terminator
,
752 &state
->loop
->info
->loop_terminator_list
,
753 loop_terminator_link
) {
754 list_del(&terminator
->loop_terminator_link
);
755 ralloc_free(terminator
);
760 /* Induction analysis needs invariance information so get that first */
761 compute_invariance_information(state
);
763 /* We have invariance information so try to find induction variables */
764 if (!compute_induction_information(state
))
767 /* Run through each of the terminators and try to compute a trip-count */
768 find_trip_count(state
);
770 nir_shader
*ns
= impl
->function
->shader
;
771 nir_foreach_block_in_cf_node(block
, &state
->loop
->cf_node
) {
772 if (force_unroll_heuristics(state
, block
)) {
773 state
->loop
->info
->force_unroll
= true;
779 static loop_info_state
*
780 initialize_loop_info_state(nir_loop
*loop
, void *mem_ctx
,
781 nir_function_impl
*impl
)
783 loop_info_state
*state
= rzalloc(mem_ctx
, loop_info_state
);
784 state
->loop_vars
= rzalloc_array(mem_ctx
, nir_loop_variable
,
788 list_inithead(&state
->process_list
);
791 ralloc_free(loop
->info
);
793 loop
->info
= rzalloc(loop
, nir_loop_info
);
795 list_inithead(&loop
->info
->loop_terminator_list
);
801 process_loops(nir_cf_node
*cf_node
, nir_variable_mode indirect_mask
)
803 switch (cf_node
->type
) {
804 case nir_cf_node_block
:
806 case nir_cf_node_if
: {
807 nir_if
*if_stmt
= nir_cf_node_as_if(cf_node
);
808 foreach_list_typed(nir_cf_node
, nested_node
, node
, &if_stmt
->then_list
)
809 process_loops(nested_node
, indirect_mask
);
810 foreach_list_typed(nir_cf_node
, nested_node
, node
, &if_stmt
->else_list
)
811 process_loops(nested_node
, indirect_mask
);
814 case nir_cf_node_loop
: {
815 nir_loop
*loop
= nir_cf_node_as_loop(cf_node
);
816 foreach_list_typed(nir_cf_node
, nested_node
, node
, &loop
->body
)
817 process_loops(nested_node
, indirect_mask
);
821 unreachable("unknown cf node type");
824 nir_loop
*loop
= nir_cf_node_as_loop(cf_node
);
825 nir_function_impl
*impl
= nir_cf_node_get_function(cf_node
);
826 void *mem_ctx
= ralloc_context(NULL
);
828 loop_info_state
*state
= initialize_loop_info_state(loop
, mem_ctx
, impl
);
829 state
->indirect_mask
= indirect_mask
;
831 get_loop_info(state
, impl
);
833 ralloc_free(mem_ctx
);
837 nir_loop_analyze_impl(nir_function_impl
*impl
,
838 nir_variable_mode indirect_mask
)
840 nir_index_ssa_defs(impl
);
841 foreach_list_typed(nir_cf_node
, node
, node
, &impl
->body
)
842 process_loops(node
, indirect_mask
);