nir: clarify some nit_loop_info member names

Following commits will introduce additional fields such as
guessed_trip_count. Renaming these will help avoid confusion
as our unrolling feature set grows.

Reviewed-by: Thomas Helland <thomashelland90@gmail.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
This commit is contained in:
Timothy Arceri
2018-11-20 11:35:37 +11:00
parent de0aee7638
commit 03d7c65ad8
3 changed files with 19 additions and 17 deletions

View File

@@ -1886,9 +1886,11 @@ typedef struct {
/* Number of instructions in the loop */ /* Number of instructions in the loop */
unsigned num_instructions; unsigned num_instructions;
/* How many times the loop is run (if known) */ /* Maximum number of times the loop is run (if known) */
unsigned trip_count; unsigned max_trip_count;
bool is_trip_count_known;
/* 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 */ /* Unroll the loop regardless of its size */
bool force_unroll; bool force_unroll;

View File

@@ -527,7 +527,7 @@ find_trip_count(loop_info_state *state)
{ {
bool trip_count_known = true; bool trip_count_known = true;
nir_loop_terminator *limiting_terminator = NULL; nir_loop_terminator *limiting_terminator = NULL;
int min_trip_count = -1; int max_trip_count = -1;
list_for_each_entry(nir_loop_terminator, terminator, list_for_each_entry(nir_loop_terminator, terminator,
&state->loop->info->loop_terminator_list, &state->loop->info->loop_terminator_list,
@@ -606,8 +606,8 @@ find_trip_count(loop_info_state *state)
* iterations than previously (we have identified a more limiting * iterations than previously (we have identified a more limiting
* terminator) set the trip count and limiting terminator. * terminator) set the trip count and limiting terminator.
*/ */
if (min_trip_count == -1 || iterations < min_trip_count) { if (max_trip_count == -1 || iterations < max_trip_count) {
min_trip_count = iterations; max_trip_count = iterations;
limiting_terminator = terminator; limiting_terminator = terminator;
} }
break; break;
@@ -617,9 +617,9 @@ find_trip_count(loop_info_state *state)
} }
} }
state->loop->info->is_trip_count_known = trip_count_known; state->loop->info->exact_trip_count_known = trip_count_known;
if (min_trip_count > -1) if (max_trip_count > -1)
state->loop->info->trip_count = min_trip_count; state->loop->info->max_trip_count = max_trip_count;
state->loop->info->limiting_terminator = limiting_terminator; state->loop->info->limiting_terminator = limiting_terminator;
} }
@@ -639,7 +639,7 @@ force_unroll_array_access(loop_info_state *state, nir_deref_instr *deref)
nir_deref_instr *parent = nir_deref_instr_parent(d); nir_deref_instr *parent = nir_deref_instr_parent(d);
assert(glsl_type_is_array(parent->type) || assert(glsl_type_is_array(parent->type) ||
glsl_type_is_matrix(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; return true;
if (deref->mode & state->indirect_mask) if (deref->mode & state->indirect_mask)

View File

@@ -181,7 +181,7 @@ simple_unroll(nir_loop *loop)
nir_cf_list unrolled_lp_body; nir_cf_list unrolled_lp_body;
/* Clone loop header and append to the loop 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 */ /* Clone loop body */
nir_cf_list_clone(&unrolled_lp_body, &loop_body, loop->cf_node.parent, nir_cf_list_clone(&unrolled_lp_body, &loop_body, loop->cf_node.parent,
remap_table); remap_table);
@@ -340,7 +340,7 @@ complex_unroll(nir_loop *loop, nir_loop_terminator *unlimit_term,
* trip count == 1 we execute the code above the break twice and the * 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. * 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 { } else {
/* Pluck out the loop header */ /* Pluck out the loop header */
nir_cf_extract(&lp_header, nir_before_block(header_blk), nir_cf_extract(&lp_header, nir_before_block(header_blk),
@@ -368,7 +368,7 @@ complex_unroll(nir_loop *loop, nir_loop_terminator *unlimit_term,
nir_cf_node_remove(&limiting_term->nif->cf_node); 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 /* In the terminator that we have no trip count for move everything after
@@ -568,14 +568,14 @@ is_loop_small_enough_to_unroll(nir_shader *shader, nir_loop_info *li)
{ {
unsigned max_iter = shader->options->max_unroll_iterations; unsigned max_iter = shader->options->max_unroll_iterations;
if (li->trip_count > max_iter) if (li->max_trip_count > max_iter)
return false; return false;
if (li->force_unroll) if (li->force_unroll)
return true; return true;
bool loop_not_too_large = 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; return loop_not_too_large;
} }
@@ -641,7 +641,7 @@ process_loops(nir_shader *sh, nir_cf_node *cf_node, bool *has_nested_loop_out)
if (!is_loop_small_enough_to_unroll(sh, loop->info)) if (!is_loop_small_enough_to_unroll(sh, loop->info))
goto exit; goto exit;
if (loop->info->is_trip_count_known) { if (loop->info->exact_trip_count_known) {
simple_unroll(loop); simple_unroll(loop);
progress = true; progress = true;
} else { } else {
@@ -665,7 +665,7 @@ process_loops(nir_shader *sh, nir_cf_node *cf_node, bool *has_nested_loop_out)
* limiting terminator just do a simple unroll as the second * limiting terminator just do a simple unroll as the second
* terminator can never be reached. * 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); simple_unroll(loop);
} else { } else {
complex_unroll(loop, terminator, limiting_term_second); complex_unroll(loop, terminator, limiting_term_second);