virtual ir_visitor_status visit(ir_loop_jump *);
virtual ir_visitor_status visit(ir_dereference_variable *);
+ virtual ir_visitor_status visit_enter(ir_call *);
+
virtual ir_visitor_status visit_enter(ir_loop *);
virtual ir_visitor_status visit_leave(ir_loop *);
virtual ir_visitor_status visit_enter(ir_assignment *);
}
+ir_visitor_status
+loop_analysis::visit_enter(ir_call *ir)
+{
+ /* If we're not somewhere inside a loop, there's nothing to do. */
+ if (this->state.is_empty())
+ return visit_continue;
+
+ loop_variable_state *const ls =
+ (loop_variable_state *) this->state.get_head();
+
+ ls->contains_calls = true;
+ return visit_continue_with_parent;
+}
+
+
ir_visitor_status
loop_analysis::visit(ir_dereference_variable *ir)
{
loop_variable_state *const ls =
(loop_variable_state *) this->state.pop_head();
+ /* Function calls may contain side effects. These could alter any of our
+ * variables in ways that cannot be known, and may even terminate shader
+ * execution (say, calling discard in the fragment shader). So we can't
+ * rely on any of our analysis about assignments to variables.
+ *
+ * We could perform some conservative analysis (prove there's no statically
+ * possible assignment, etc.) but it isn't worth it for now; function
+ * inlining will allow us to unroll loops anyway.
+ */
+ if (ls->contains_calls)
+ return visit_continue;
foreach_list(node, &ir->body_instructions) {
/* Skip over declarations at the start of a loop.
*/
unsigned num_loop_jumps;
+ /**
+ * Whether this loop contains any function calls.
+ */
+ bool contains_calls;
+
loop_variable_state()
{
this->max_iterations = -1;
this->num_loop_jumps = 0;
+ this->contains_calls = false;
this->var_hash = hash_table_ctor(0, hash_table_pointer_hash,
hash_table_pointer_compare);
}