extern class loop_state *
analyze_loop_variables(exec_list *instructions);
+static inline bool
+is_break(ir_instruction *ir)
+{
+ return ir != NULL && ir->ir_type == ir_type_loop_jump &&
+ ((ir_loop_jump *) ir)->is_break();
+}
+
extern bool
unroll_loops(exec_list *instructions, loop_state *ls,
} /* anonymous namespace */
-static bool
-is_break(ir_instruction *ir)
-{
- return ir != NULL && ir->ir_type == ir_type_loop_jump
- && ((ir_loop_jump *) ir)->is_break();
-}
-
class loop_unroll_count : public ir_hierarchical_visitor {
public:
int nodes;
* bound, then that terminates the loop, so we don't even need the limiting
* terminator.
*/
- foreach_in_list(loop_terminator, t, &ls->terminators) {
+ foreach_in_list_safe(loop_terminator, t, &ls->terminators) {
if (t->iterations < 0)
continue;
+ exec_list *branch_instructions;
if (t != ls->limiting_terminator) {
+ ir_instruction *ir_if_last = (ir_instruction *)
+ t->ir->then_instructions.get_tail();
+ if (is_break(ir_if_last)) {
+ branch_instructions = &t->ir->else_instructions;
+ } else {
+ branch_instructions = &t->ir->then_instructions;
+ assert(is_break((ir_instruction *)
+ t->ir->else_instructions.get_tail()));
+ }
+
+ exec_list copy_list;
+ copy_list.make_empty();
+ clone_ir_list(ir, ©_list, branch_instructions);
+
+ t->ir->insert_before(©_list);
t->ir->remove();
assert(ls->num_loop_jumps > 0);
ls->num_loop_jumps--;
+ /* Also remove it from the terminator list */
+ t->remove();
+
this->progress = true;
}
}