glsl/loops: Move some analysis from loop_controls to loop_analysis.

Previously, the sole responsibility of loop_analysis was to find all
the variables referenced in the loop that are either loop constant or
induction variables, and find all of the simple if statements that
might terminate the loop.  The remainder of the analysis necessary to
determine how many times a loop executed was performed by
loop_controls.

This patch makes loop_analysis also responsible for determining the
number of iterations after which each loop terminator will terminate
the loop, and for figuring out which terminator will terminate the
loop first (I'm calling this the "limiting terminator").

This will allow loop unrolling to make use of information that was
previously only visible from loop_controls, namely the identity of the
limiting terminator.

Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
This commit is contained in:
Paul Berry
2013-11-28 14:40:19 -08:00
parent 4bbf6d1d2b
commit ffc29120c4
3 changed files with 122 additions and 77 deletions

View File

@@ -58,6 +58,13 @@ set_loop_controls(exec_list *instructions, loop_state *ls);
extern bool
unroll_loops(exec_list *instructions, loop_state *ls, unsigned max_iterations);
ir_rvalue *
find_initial_value(ir_loop *loop, ir_variable *var);
int
calculate_iterations(ir_rvalue *from, ir_rvalue *to, ir_rvalue *increment,
enum ir_expression_operation op);
/**
* Tracking for all variables used in a loop
@@ -98,6 +105,14 @@ public:
*/
exec_list terminators;
/**
* If any of the terminators in \c terminators leads to termination of the
* loop after a constant number of iterations, this is the terminator that
* leads to termination after the smallest number of iterations. Otherwise
* NULL.
*/
loop_terminator *limiting_terminator;
/**
* Hash table containing all variables accessed in this loop
*/
@@ -129,6 +144,7 @@ public:
this->contains_calls = false;
this->var_hash = hash_table_ctor(0, hash_table_pointer_hash,
hash_table_pointer_compare);
this->limiting_terminator = NULL;
}
~loop_variable_state()
@@ -227,7 +243,21 @@ public:
class loop_terminator : public exec_node {
public:
loop_terminator()
: ir(NULL), iterations(-1)
{
}
/**
* Statement which terminates the loop.
*/
ir_if *ir;
/**
* The number of iterations after which the terminator is known to
* terminate the loop (if that is a fixed value). Otherwise -1.
*/
int iterations;
};