glsl: check if induction var incremented before use in terminator
[mesa.git] / src / compiler / glsl / loop_analysis.cpp
1 /*
2 * Copyright © 2010 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24 #include "compiler/glsl_types.h"
25 #include "loop_analysis.h"
26 #include "ir_hierarchical_visitor.h"
27
28 static bool is_loop_terminator(ir_if *ir);
29
30 static bool all_expression_operands_are_loop_constant(ir_rvalue *,
31 hash_table *);
32
33 static ir_rvalue *get_basic_induction_increment(ir_assignment *, hash_table *);
34
35 /**
36 * Find an initializer of a variable outside a loop
37 *
38 * Works backwards from the loop to find the pre-loop value of the variable.
39 * This is used, for example, to find the initial value of loop induction
40 * variables.
41 *
42 * \param loop Loop where \c var is an induction variable
43 * \param var Variable whose initializer is to be found
44 *
45 * \return
46 * The \c ir_rvalue assigned to the variable outside the loop. May return
47 * \c NULL if no initializer can be found.
48 */
49 static ir_rvalue *
50 find_initial_value(ir_loop *loop, ir_variable *var)
51 {
52 for (exec_node *node = loop->prev; !node->is_head_sentinel();
53 node = node->prev) {
54 ir_instruction *ir = (ir_instruction *) node;
55
56 switch (ir->ir_type) {
57 case ir_type_call:
58 case ir_type_loop:
59 case ir_type_loop_jump:
60 case ir_type_return:
61 case ir_type_if:
62 return NULL;
63
64 case ir_type_function:
65 case ir_type_function_signature:
66 assert(!"Should not get here.");
67 return NULL;
68
69 case ir_type_assignment: {
70 ir_assignment *assign = ir->as_assignment();
71 ir_variable *assignee = assign->lhs->whole_variable_referenced();
72
73 if (assignee == var)
74 return (assign->condition != NULL) ? NULL : assign->rhs;
75
76 break;
77 }
78
79 default:
80 break;
81 }
82 }
83
84 return NULL;
85 }
86
87
88 static int
89 calculate_iterations(ir_rvalue *from, ir_rvalue *to, ir_rvalue *increment,
90 enum ir_expression_operation op)
91 {
92 if (from == NULL || to == NULL || increment == NULL)
93 return -1;
94
95 void *mem_ctx = ralloc_context(NULL);
96
97 ir_expression *const sub =
98 new(mem_ctx) ir_expression(ir_binop_sub, from->type, to, from);
99
100 ir_expression *const div =
101 new(mem_ctx) ir_expression(ir_binop_div, sub->type, sub, increment);
102
103 ir_constant *iter = div->constant_expression_value(mem_ctx);
104 if (iter == NULL) {
105 ralloc_free(mem_ctx);
106 return -1;
107 }
108
109 if (!iter->type->is_integer()) {
110 const ir_expression_operation op = iter->type->is_double()
111 ? ir_unop_d2i : ir_unop_f2i;
112 ir_rvalue *cast =
113 new(mem_ctx) ir_expression(op, glsl_type::int_type, iter, NULL);
114
115 iter = cast->constant_expression_value(mem_ctx);
116 }
117
118 int iter_value = iter->get_int_component(0);
119
120 /* Make sure that the calculated number of iterations satisfies the exit
121 * condition. This is needed to catch off-by-one errors and some types of
122 * ill-formed loops. For example, we need to detect that the following
123 * loop does not have a maximum iteration count.
124 *
125 * for (float x = 0.0; x != 0.9; x += 0.2)
126 * ;
127 */
128 const int bias[] = { -1, 0, 1 };
129 bool valid_loop = false;
130
131 for (unsigned i = 0; i < ARRAY_SIZE(bias); i++) {
132 /* Increment may be of type int, uint or float. */
133 switch (increment->type->base_type) {
134 case GLSL_TYPE_INT:
135 iter = new(mem_ctx) ir_constant(iter_value + bias[i]);
136 break;
137 case GLSL_TYPE_UINT:
138 iter = new(mem_ctx) ir_constant(unsigned(iter_value + bias[i]));
139 break;
140 case GLSL_TYPE_FLOAT:
141 iter = new(mem_ctx) ir_constant(float(iter_value + bias[i]));
142 break;
143 case GLSL_TYPE_DOUBLE:
144 iter = new(mem_ctx) ir_constant(double(iter_value + bias[i]));
145 break;
146 default:
147 unreachable("Unsupported type for loop iterator.");
148 }
149
150 ir_expression *const mul =
151 new(mem_ctx) ir_expression(ir_binop_mul, increment->type, iter,
152 increment);
153
154 ir_expression *const add =
155 new(mem_ctx) ir_expression(ir_binop_add, mul->type, mul, from);
156
157 ir_expression *const cmp =
158 new(mem_ctx) ir_expression(op, glsl_type::bool_type, add, to);
159
160 ir_constant *const cmp_result = cmp->constant_expression_value(mem_ctx);
161
162 assert(cmp_result != NULL);
163 if (cmp_result->get_bool_component(0)) {
164 iter_value += bias[i];
165 valid_loop = true;
166 break;
167 }
168 }
169
170 ralloc_free(mem_ctx);
171 return (valid_loop) ? iter_value : -1;
172 }
173
174 static bool
175 incremented_before_terminator(ir_loop *loop, ir_variable *var,
176 ir_if *terminator)
177 {
178 for (exec_node *node = loop->body_instructions.get_head();
179 !node->is_tail_sentinel();
180 node = node->get_next()) {
181 ir_instruction *ir = (ir_instruction *) node;
182
183 switch (ir->ir_type) {
184 case ir_type_if:
185 if (ir->as_if() == terminator)
186 return false;
187 break;
188
189 case ir_type_assignment: {
190 ir_assignment *assign = ir->as_assignment();
191 ir_variable *assignee = assign->lhs->whole_variable_referenced();
192
193 if (assignee == var) {
194 assert(assign->condition == NULL);
195 return true;
196 }
197
198 break;
199 }
200
201 default:
202 break;
203 }
204 }
205
206 unreachable("Unable to find induction variable");
207 }
208
209 /**
210 * Record the fact that the given loop variable was referenced inside the loop.
211 *
212 * \arg in_assignee is true if the reference was on the LHS of an assignment.
213 *
214 * \arg in_conditional_code_or_nested_loop is true if the reference occurred
215 * inside an if statement or a nested loop.
216 *
217 * \arg current_assignment is the ir_assignment node that the loop variable is
218 * on the LHS of, if any (ignored if \c in_assignee is false).
219 */
220 void
221 loop_variable::record_reference(bool in_assignee,
222 bool in_conditional_code_or_nested_loop,
223 ir_assignment *current_assignment)
224 {
225 if (in_assignee) {
226 assert(current_assignment != NULL);
227
228 if (in_conditional_code_or_nested_loop ||
229 current_assignment->condition != NULL) {
230 this->conditional_or_nested_assignment = true;
231 }
232
233 if (this->first_assignment == NULL) {
234 assert(this->num_assignments == 0);
235
236 this->first_assignment = current_assignment;
237 }
238
239 this->num_assignments++;
240 } else if (this->first_assignment == current_assignment) {
241 /* This catches the case where the variable is used in the RHS of an
242 * assignment where it is also in the LHS.
243 */
244 this->read_before_write = true;
245 }
246 }
247
248
249 loop_state::loop_state()
250 {
251 this->ht = _mesa_hash_table_create(NULL, _mesa_hash_pointer,
252 _mesa_key_pointer_equal);
253 this->mem_ctx = ralloc_context(NULL);
254 this->loop_found = false;
255 }
256
257
258 loop_state::~loop_state()
259 {
260 _mesa_hash_table_destroy(this->ht, NULL);
261 ralloc_free(this->mem_ctx);
262 }
263
264
265 loop_variable_state *
266 loop_state::insert(ir_loop *ir)
267 {
268 loop_variable_state *ls = new(this->mem_ctx) loop_variable_state;
269
270 _mesa_hash_table_insert(this->ht, ir, ls);
271 this->loop_found = true;
272
273 return ls;
274 }
275
276
277 loop_variable_state *
278 loop_state::get(const ir_loop *ir)
279 {
280 hash_entry *entry = _mesa_hash_table_search(this->ht, ir);
281 return entry ? (loop_variable_state *) entry->data : NULL;
282 }
283
284
285 loop_variable *
286 loop_variable_state::get(const ir_variable *ir)
287 {
288 hash_entry *entry = _mesa_hash_table_search(this->var_hash, ir);
289 return entry ? (loop_variable *) entry->data : NULL;
290 }
291
292
293 loop_variable *
294 loop_variable_state::insert(ir_variable *var)
295 {
296 void *mem_ctx = ralloc_parent(this);
297 loop_variable *lv = rzalloc(mem_ctx, loop_variable);
298
299 lv->var = var;
300
301 _mesa_hash_table_insert(this->var_hash, lv->var, lv);
302 this->variables.push_tail(lv);
303
304 return lv;
305 }
306
307
308 loop_terminator *
309 loop_variable_state::insert(ir_if *if_stmt)
310 {
311 void *mem_ctx = ralloc_parent(this);
312 loop_terminator *t = new(mem_ctx) loop_terminator();
313
314 t->ir = if_stmt;
315 this->terminators.push_tail(t);
316
317 return t;
318 }
319
320
321 /**
322 * If the given variable already is recorded in the state for this loop,
323 * return the corresponding loop_variable object that records information
324 * about it.
325 *
326 * Otherwise, create a new loop_variable object to record information about
327 * the variable, and set its \c read_before_write field appropriately based on
328 * \c in_assignee.
329 *
330 * \arg in_assignee is true if this variable was encountered on the LHS of an
331 * assignment.
332 */
333 loop_variable *
334 loop_variable_state::get_or_insert(ir_variable *var, bool in_assignee)
335 {
336 loop_variable *lv = this->get(var);
337
338 if (lv == NULL) {
339 lv = this->insert(var);
340 lv->read_before_write = !in_assignee;
341 }
342
343 return lv;
344 }
345
346
347 namespace {
348
349 class loop_analysis : public ir_hierarchical_visitor {
350 public:
351 loop_analysis(loop_state *loops);
352
353 virtual ir_visitor_status visit(ir_loop_jump *);
354 virtual ir_visitor_status visit(ir_dereference_variable *);
355
356 virtual ir_visitor_status visit_enter(ir_call *);
357
358 virtual ir_visitor_status visit_enter(ir_loop *);
359 virtual ir_visitor_status visit_leave(ir_loop *);
360 virtual ir_visitor_status visit_enter(ir_assignment *);
361 virtual ir_visitor_status visit_leave(ir_assignment *);
362 virtual ir_visitor_status visit_enter(ir_if *);
363 virtual ir_visitor_status visit_leave(ir_if *);
364
365 loop_state *loops;
366
367 int if_statement_depth;
368
369 ir_assignment *current_assignment;
370
371 exec_list state;
372 };
373
374 } /* anonymous namespace */
375
376 loop_analysis::loop_analysis(loop_state *loops)
377 : loops(loops), if_statement_depth(0), current_assignment(NULL)
378 {
379 /* empty */
380 }
381
382
383 ir_visitor_status
384 loop_analysis::visit(ir_loop_jump *ir)
385 {
386 (void) ir;
387
388 assert(!this->state.is_empty());
389
390 loop_variable_state *const ls =
391 (loop_variable_state *) this->state.get_head();
392
393 ls->num_loop_jumps++;
394
395 return visit_continue;
396 }
397
398
399 ir_visitor_status
400 loop_analysis::visit_enter(ir_call *)
401 {
402 /* Mark every loop that we're currently analyzing as containing an ir_call
403 * (even those at outer nesting levels).
404 */
405 foreach_in_list(loop_variable_state, ls, &this->state) {
406 ls->contains_calls = true;
407 }
408
409 return visit_continue_with_parent;
410 }
411
412
413 ir_visitor_status
414 loop_analysis::visit(ir_dereference_variable *ir)
415 {
416 /* If we're not somewhere inside a loop, there's nothing to do.
417 */
418 if (this->state.is_empty())
419 return visit_continue;
420
421 bool nested = false;
422
423 foreach_in_list(loop_variable_state, ls, &this->state) {
424 ir_variable *var = ir->variable_referenced();
425 loop_variable *lv = ls->get_or_insert(var, this->in_assignee);
426
427 lv->record_reference(this->in_assignee,
428 nested || this->if_statement_depth > 0,
429 this->current_assignment);
430 nested = true;
431 }
432
433 return visit_continue;
434 }
435
436 ir_visitor_status
437 loop_analysis::visit_enter(ir_loop *ir)
438 {
439 loop_variable_state *ls = this->loops->insert(ir);
440 this->state.push_head(ls);
441
442 return visit_continue;
443 }
444
445 ir_visitor_status
446 loop_analysis::visit_leave(ir_loop *ir)
447 {
448 loop_variable_state *const ls =
449 (loop_variable_state *) this->state.pop_head();
450
451 /* Function calls may contain side effects. These could alter any of our
452 * variables in ways that cannot be known, and may even terminate shader
453 * execution (say, calling discard in the fragment shader). So we can't
454 * rely on any of our analysis about assignments to variables.
455 *
456 * We could perform some conservative analysis (prove there's no statically
457 * possible assignment, etc.) but it isn't worth it for now; function
458 * inlining will allow us to unroll loops anyway.
459 */
460 if (ls->contains_calls)
461 return visit_continue;
462
463 foreach_in_list(ir_instruction, node, &ir->body_instructions) {
464 /* Skip over declarations at the start of a loop.
465 */
466 if (node->as_variable())
467 continue;
468
469 ir_if *if_stmt = ((ir_instruction *) node)->as_if();
470
471 if ((if_stmt != NULL) && is_loop_terminator(if_stmt))
472 ls->insert(if_stmt);
473 else
474 break;
475 }
476
477
478 foreach_in_list_safe(loop_variable, lv, &ls->variables) {
479 /* Move variables that are already marked as being loop constant to
480 * a separate list. These trivially don't need to be tested.
481 */
482 if (lv->is_loop_constant()) {
483 lv->remove();
484 ls->constants.push_tail(lv);
485 }
486 }
487
488 /* Each variable assigned in the loop that isn't already marked as being loop
489 * constant might still be loop constant. The requirements at this point
490 * are:
491 *
492 * - Variable is written before it is read.
493 *
494 * - Only one assignment to the variable.
495 *
496 * - All operands on the RHS of the assignment are also loop constants.
497 *
498 * The last requirement is the reason for the progress loop. A variable
499 * marked as a loop constant on one pass may allow other variables to be
500 * marked as loop constant on following passes.
501 */
502 bool progress;
503 do {
504 progress = false;
505
506 foreach_in_list_safe(loop_variable, lv, &ls->variables) {
507 if (lv->conditional_or_nested_assignment || (lv->num_assignments > 1))
508 continue;
509
510 /* Process the RHS of the assignment. If all of the variables
511 * accessed there are loop constants, then add this
512 */
513 ir_rvalue *const rhs = lv->first_assignment->rhs;
514 if (all_expression_operands_are_loop_constant(rhs, ls->var_hash)) {
515 lv->rhs_clean = true;
516
517 if (lv->is_loop_constant()) {
518 progress = true;
519
520 lv->remove();
521 ls->constants.push_tail(lv);
522 }
523 }
524 }
525 } while (progress);
526
527 /* The remaining variables that are not loop invariant might be loop
528 * induction variables.
529 */
530 foreach_in_list_safe(loop_variable, lv, &ls->variables) {
531 /* If there is more than one assignment to a variable, it cannot be a
532 * loop induction variable. This isn't strictly true, but this is a
533 * very simple induction variable detector, and it can't handle more
534 * complex cases.
535 */
536 if (lv->num_assignments > 1)
537 continue;
538
539 /* All of the variables with zero assignments in the loop are loop
540 * invariant, and they should have already been filtered out.
541 */
542 assert(lv->num_assignments == 1);
543 assert(lv->first_assignment != NULL);
544
545 /* The assignment to the variable in the loop must be unconditional and
546 * not inside a nested loop.
547 */
548 if (lv->conditional_or_nested_assignment)
549 continue;
550
551 /* Basic loop induction variables have a single assignment in the loop
552 * that has the form 'VAR = VAR + i' or 'VAR = VAR - i' where i is a
553 * loop invariant.
554 */
555 ir_rvalue *const inc =
556 get_basic_induction_increment(lv->first_assignment, ls->var_hash);
557 if (inc != NULL) {
558 lv->increment = inc;
559
560 lv->remove();
561 ls->induction_variables.push_tail(lv);
562 }
563 }
564
565 /* Search the loop terminating conditions for those of the form 'i < c'
566 * where i is a loop induction variable, c is a constant, and < is any
567 * relative operator. From each of these we can infer an iteration count.
568 * Also figure out which terminator (if any) produces the smallest
569 * iteration count--this is the limiting terminator.
570 */
571 foreach_in_list(loop_terminator, t, &ls->terminators) {
572 ir_if *if_stmt = t->ir;
573
574 /* If-statements can be either 'if (expr)' or 'if (deref)'. We only care
575 * about the former here.
576 */
577 ir_expression *cond = if_stmt->condition->as_expression();
578 if (cond == NULL)
579 continue;
580
581 switch (cond->operation) {
582 case ir_binop_less:
583 case ir_binop_greater:
584 case ir_binop_lequal:
585 case ir_binop_gequal: {
586 /* The expressions that we care about will either be of the form
587 * 'counter < limit' or 'limit < counter'. Figure out which is
588 * which.
589 */
590 ir_rvalue *counter = cond->operands[0]->as_dereference_variable();
591 ir_constant *limit = cond->operands[1]->as_constant();
592 enum ir_expression_operation cmp = cond->operation;
593
594 if (limit == NULL) {
595 counter = cond->operands[1]->as_dereference_variable();
596 limit = cond->operands[0]->as_constant();
597
598 switch (cmp) {
599 case ir_binop_less: cmp = ir_binop_greater; break;
600 case ir_binop_greater: cmp = ir_binop_less; break;
601 case ir_binop_lequal: cmp = ir_binop_gequal; break;
602 case ir_binop_gequal: cmp = ir_binop_lequal; break;
603 default: assert(!"Should not get here.");
604 }
605 }
606
607 if ((counter == NULL) || (limit == NULL))
608 break;
609
610 ir_variable *var = counter->variable_referenced();
611
612 ir_rvalue *init = find_initial_value(ir, var);
613
614 loop_variable *lv = ls->get(var);
615 if (lv != NULL && lv->is_induction_var()) {
616 t->iterations = calculate_iterations(init, limit, lv->increment,
617 cmp);
618
619 if (incremented_before_terminator(ir, var, t->ir)) {
620 t->iterations--;
621 }
622
623 if (t->iterations >= 0 &&
624 (ls->limiting_terminator == NULL ||
625 t->iterations < ls->limiting_terminator->iterations)) {
626 ls->limiting_terminator = t;
627 }
628 }
629 break;
630 }
631
632 default:
633 break;
634 }
635 }
636
637 return visit_continue;
638 }
639
640 ir_visitor_status
641 loop_analysis::visit_enter(ir_if *ir)
642 {
643 (void) ir;
644
645 if (!this->state.is_empty())
646 this->if_statement_depth++;
647
648 return visit_continue;
649 }
650
651 ir_visitor_status
652 loop_analysis::visit_leave(ir_if *ir)
653 {
654 (void) ir;
655
656 if (!this->state.is_empty())
657 this->if_statement_depth--;
658
659 return visit_continue;
660 }
661
662 ir_visitor_status
663 loop_analysis::visit_enter(ir_assignment *ir)
664 {
665 /* If we're not somewhere inside a loop, there's nothing to do.
666 */
667 if (this->state.is_empty())
668 return visit_continue_with_parent;
669
670 this->current_assignment = ir;
671
672 return visit_continue;
673 }
674
675 ir_visitor_status
676 loop_analysis::visit_leave(ir_assignment *ir)
677 {
678 /* Since the visit_enter exits with visit_continue_with_parent for this
679 * case, the loop state stack should never be empty here.
680 */
681 assert(!this->state.is_empty());
682
683 assert(this->current_assignment == ir);
684 this->current_assignment = NULL;
685
686 return visit_continue;
687 }
688
689
690 class examine_rhs : public ir_hierarchical_visitor {
691 public:
692 examine_rhs(hash_table *loop_variables)
693 {
694 this->only_uses_loop_constants = true;
695 this->loop_variables = loop_variables;
696 }
697
698 virtual ir_visitor_status visit(ir_dereference_variable *ir)
699 {
700 hash_entry *entry = _mesa_hash_table_search(this->loop_variables,
701 ir->var);
702 loop_variable *lv = entry ? (loop_variable *) entry->data : NULL;
703
704 assert(lv != NULL);
705
706 if (lv->is_loop_constant()) {
707 return visit_continue;
708 } else {
709 this->only_uses_loop_constants = false;
710 return visit_stop;
711 }
712 }
713
714 hash_table *loop_variables;
715 bool only_uses_loop_constants;
716 };
717
718
719 bool
720 all_expression_operands_are_loop_constant(ir_rvalue *ir, hash_table *variables)
721 {
722 examine_rhs v(variables);
723
724 ir->accept(&v);
725
726 return v.only_uses_loop_constants;
727 }
728
729
730 ir_rvalue *
731 get_basic_induction_increment(ir_assignment *ir, hash_table *var_hash)
732 {
733 /* The RHS must be a binary expression.
734 */
735 ir_expression *const rhs = ir->rhs->as_expression();
736 if ((rhs == NULL)
737 || ((rhs->operation != ir_binop_add)
738 && (rhs->operation != ir_binop_sub)))
739 return NULL;
740
741 /* One of the of operands of the expression must be the variable assigned.
742 * If the operation is subtraction, the variable in question must be the
743 * "left" operand.
744 */
745 ir_variable *const var = ir->lhs->variable_referenced();
746
747 ir_variable *const op0 = rhs->operands[0]->variable_referenced();
748 ir_variable *const op1 = rhs->operands[1]->variable_referenced();
749
750 if (((op0 != var) && (op1 != var))
751 || ((op1 == var) && (rhs->operation == ir_binop_sub)))
752 return NULL;
753
754 ir_rvalue *inc = (op0 == var) ? rhs->operands[1] : rhs->operands[0];
755
756 if (inc->as_constant() == NULL) {
757 ir_variable *const inc_var = inc->variable_referenced();
758 if (inc_var != NULL) {
759 hash_entry *entry = _mesa_hash_table_search(var_hash, inc_var);
760 loop_variable *lv = entry ? (loop_variable *) entry->data : NULL;
761
762 if (lv == NULL || !lv->is_loop_constant()) {
763 assert(lv != NULL);
764 inc = NULL;
765 }
766 } else
767 inc = NULL;
768 }
769
770 if ((inc != NULL) && (rhs->operation == ir_binop_sub)) {
771 void *mem_ctx = ralloc_parent(ir);
772
773 inc = new(mem_ctx) ir_expression(ir_unop_neg,
774 inc->type,
775 inc->clone(mem_ctx, NULL),
776 NULL);
777 }
778
779 return inc;
780 }
781
782
783 /**
784 * Detect whether an if-statement is a loop terminating condition
785 *
786 * Detects if-statements of the form
787 *
788 * (if (expression bool ...) (break))
789 */
790 bool
791 is_loop_terminator(ir_if *ir)
792 {
793 if (!ir->else_instructions.is_empty())
794 return false;
795
796 ir_instruction *const inst =
797 (ir_instruction *) ir->then_instructions.get_head();
798 if (inst == NULL)
799 return false;
800
801 if (inst->ir_type != ir_type_loop_jump)
802 return false;
803
804 ir_loop_jump *const jump = (ir_loop_jump *) inst;
805 if (jump->mode != ir_loop_jump::jump_break)
806 return false;
807
808 return true;
809 }
810
811
812 loop_state *
813 analyze_loop_variables(exec_list *instructions)
814 {
815 loop_state *loops = new loop_state;
816 loop_analysis v(loops);
817
818 v.run(instructions);
819 return v.loops;
820 }