/* Number of instructions in the loop */
unsigned num_instructions;
- /* How many times the loop is run (if known) */
- unsigned trip_count;
- bool is_trip_count_known;
+ /* Maximum number of times the loop is run (if known) */
+ unsigned max_trip_count;
+
+ /* Do we know the exact number of times the loop will be run */
+ bool exact_trip_count_known;
/* Unroll the loop regardless of its size */
bool force_unroll;
{
bool trip_count_known = true;
nir_loop_terminator *limiting_terminator = NULL;
- int min_trip_count = -1;
+ int max_trip_count = -1;
list_for_each_entry(nir_loop_terminator, terminator,
&state->loop->info->loop_terminator_list,
* iterations than previously (we have identified a more limiting
* terminator) set the trip count and limiting terminator.
*/
- if (min_trip_count == -1 || iterations < min_trip_count) {
- min_trip_count = iterations;
+ if (max_trip_count == -1 || iterations < max_trip_count) {
+ max_trip_count = iterations;
limiting_terminator = terminator;
}
break;
}
}
- state->loop->info->is_trip_count_known = trip_count_known;
- if (min_trip_count > -1)
- state->loop->info->trip_count = min_trip_count;
+ state->loop->info->exact_trip_count_known = trip_count_known;
+ if (max_trip_count > -1)
+ state->loop->info->max_trip_count = max_trip_count;
state->loop->info->limiting_terminator = limiting_terminator;
}
nir_deref_instr *parent = nir_deref_instr_parent(d);
assert(glsl_type_is_array(parent->type) ||
glsl_type_is_matrix(parent->type));
- if (glsl_get_length(parent->type) == state->loop->info->trip_count)
+ if (glsl_get_length(parent->type) == state->loop->info->max_trip_count)
return true;
if (deref->mode & state->indirect_mask)
nir_cf_list unrolled_lp_body;
/* Clone loop header and append to the loop body */
- for (unsigned i = 0; i < loop->info->trip_count; i++) {
+ for (unsigned i = 0; i < loop->info->max_trip_count; i++) {
/* Clone loop body */
nir_cf_list_clone(&unrolled_lp_body, &loop_body, loop->cf_node.parent,
remap_table);
* trip count == 1 we execute the code above the break twice and the
* code below it once so we need clone things twice and so on.
*/
- num_times_to_clone = loop->info->trip_count + 1;
+ num_times_to_clone = loop->info->max_trip_count + 1;
} else {
/* Pluck out the loop header */
nir_cf_extract(&lp_header, nir_before_block(header_blk),
nir_cf_node_remove(&limiting_term->nif->cf_node);
- num_times_to_clone = loop->info->trip_count;
+ num_times_to_clone = loop->info->max_trip_count;
}
/* In the terminator that we have no trip count for move everything after
{
unsigned max_iter = shader->options->max_unroll_iterations;
- if (li->trip_count > max_iter)
+ if (li->max_trip_count > max_iter)
return false;
if (li->force_unroll)
return true;
bool loop_not_too_large =
- li->num_instructions * li->trip_count <= max_iter * LOOP_UNROLL_LIMIT;
+ li->num_instructions * li->max_trip_count <= max_iter * LOOP_UNROLL_LIMIT;
return loop_not_too_large;
}
if (!is_loop_small_enough_to_unroll(sh, loop->info))
goto exit;
- if (loop->info->is_trip_count_known) {
+ if (loop->info->exact_trip_count_known) {
simple_unroll(loop);
progress = true;
} else {
* limiting terminator just do a simple unroll as the second
* terminator can never be reached.
*/
- if (loop->info->trip_count == 0 && !limiting_term_second) {
+ if (loop->info->max_trip_count == 0 && !limiting_term_second) {
simple_unroll(loop);
} else {
complex_unroll(loop, terminator, limiting_term_second);