$(GLSL_SRCDIR)/loop_analysis.cpp \
$(GLSL_SRCDIR)/loop_controls.cpp \
$(GLSL_SRCDIR)/loop_unroll.cpp \
- $(GLSL_SRCDIR)/lower_bounded_loops.cpp \
$(GLSL_SRCDIR)/lower_clip_distance.cpp \
$(GLSL_SRCDIR)/lower_discard.cpp \
$(GLSL_SRCDIR)/lower_discard_flow.cpp \
ir_loop::ir_loop()
{
this->ir_type = ir_type_loop;
- this->normative_bound = -1;
}
/** List of ir_instruction that make up the body of the loop. */
exec_list body_instructions;
-
- /**
- * Normative bound for the loop. If this value is >= 0, the back-end
- * should generate instructions to ensure that the loop executes no more
- * than this many times.
- */
- int normative_bound;
};
{
ir_loop *new_loop = new(mem_ctx) ir_loop();
- new_loop->normative_bound = this->normative_bound;
-
foreach_iter(exec_list_iterator, iter, this->body_instructions) {
ir_instruction *ir = (ir_instruction *)iter.get();
new_loop->body_instructions.push_tail(ir->clone(mem_ctx, ht));
bool do_tree_grafting(exec_list *instructions);
bool do_vec_index_to_cond_assign(exec_list *instructions);
bool do_vec_index_to_swizzle(exec_list *instructions);
-bool lower_bounded_loops(exec_list *instructions);
bool lower_discard(exec_list *instructions);
void lower_discard_flow(exec_list *instructions);
bool lower_instructions(exec_list *instructions, unsigned what_to_lower);
void
ir_print_visitor::visit(ir_loop *ir)
{
- printf("(loop (");
- if (ir->normative_bound >= 0)
- printf("%d", ir->normative_bound);
- printf(") (\n");
+ printf("(loop (\n");
indentation++;
foreach_iter(exec_list_iterator, iter, ir->body_instructions) {
ir_loop *
ir_reader::read_loop(s_expression *expr)
{
- s_expression *s_bound_expr, *s_body, *s_bound;
+ s_expression *s_body;
- s_pattern loop_pat[] = { "loop", s_bound_expr, s_body };
- s_pattern no_bound_pat[] = { };
- s_pattern bound_pat[] = { s_bound };
+ s_pattern loop_pat[] = { "loop", s_body };
if (!MATCH(expr, loop_pat)) {
- ir_read_error(expr, "expected (loop <bound> <body>)");
+ ir_read_error(expr, "expected (loop <body>)");
return NULL;
}
ir_loop *loop = new(mem_ctx) ir_loop;
- if (MATCH(s_bound_expr, no_bound_pat)) {
- loop->normative_bound = -1;
- } else if (MATCH(s_bound_expr, bound_pat)) {
- s_int *value = SX_AS_INT(s_bound);
- if (value == NULL) {
- ir_read_error(s_bound_expr, "malformed loop bound");
- delete loop;
- return NULL;
- }
- loop->normative_bound = value->value();
- } else {
- ir_read_error(s_bound_expr, "malformed loop bound");
- delete loop;
- return NULL;
- }
-
read_instructions(&loop->body_instructions, s_body, loop);
if (state->error) {
delete loop;
this->progress = true;
return visit_continue;
}
-
- /* If the limiting terminator has a lower iteration count than the
- * normative loop bound (if any), then the loop doesn't need a normative
- * bound anymore.
- */
- if (ir->normative_bound >= 0 && iterations < ir->normative_bound)
- ir->normative_bound = -1;
}
/* Remove the conditional break statements associated with all terminators
if (t->iterations < 0)
continue;
- if (ir->normative_bound >= 0 || t != ls->limiting_terminator) {
+ if (t != ls->limiting_terminator) {
t->ir->remove();
assert(ls->num_loop_jumps > 0);
loop_variable_state *const ls = this->state->get(ir);
int iterations;
- /* Note: normatively-bounded loops aren't created anymore. */
- assert(ir->normative_bound < 0);
-
/* If we've entered a loop that hasn't been analyzed, something really,
* really bad has happened.
*/
+++ /dev/null
-/*
- * Copyright © 2013 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-/** \file
- *
- * This pass converts bounded loops (those whose ir_loop contains non-null
- * values for \c from, \c to, \c increment, and \c counter) into unbounded
- * loops.
- *
- * For instance:
- *
- * (loop (declare () uint i) (constant uint 0) (constant uint 4)
- * (constant uint 1)
- * ...loop body...)
- *
- * Is transformed into:
- *
- * (declare () uint i)
- * (assign (x) (var_ref i) (constant uint 0))
- * (loop
- * (if (expression bool >= (var_ref i) (constant uint 4))
- * (break)
- * ())
- * ...loop body...
- * (assign (x) (var_ref i)
- * (expression uint + (var_ref i) (constant uint 1))))
- */
-
-#include "ir_hierarchical_visitor.h"
-#include "ir.h"
-#include "ir_builder.h"
-
-using namespace ir_builder;
-
-namespace {
-
-class lower_bounded_loops_visitor : public ir_hierarchical_visitor {
-public:
- lower_bounded_loops_visitor()
- : progress(false)
- {
- }
-
- virtual ir_visitor_status visit_leave(ir_loop *ir);
-
- bool progress;
-};
-
-} /* anonymous namespace */
-
-
-ir_visitor_status
-lower_bounded_loops_visitor::visit_leave(ir_loop *ir)
-{
- if (ir->normative_bound < 0)
- return visit_continue;
-
- exec_list new_instructions;
- ir_factory f(&new_instructions, ralloc_parent(ir));
-
- /* Before the loop, declare the counter and initialize it to zero. */
- ir_variable *counter = f.make_temp(glsl_type::uint_type, "counter");
- f.emit(assign(counter, f.constant(0u)));
- ir->insert_before(&new_instructions);
-
- /* At the top of the loop, compare the counter to normative_bound, and
- * break if the comparison succeeds.
- */
- ir_loop_jump *brk = new(f.mem_ctx) ir_loop_jump(ir_loop_jump::jump_break);
- ir_if *if_inst = if_tree(gequal(counter,
- f.constant((unsigned) ir->normative_bound)),
- brk);
- ir->body_instructions.push_head(if_inst);
-
- /* At the bottom of the loop, increment the counter. */
- ir->body_instructions.push_tail(assign(counter,
- add(counter, f.constant(1u))));
-
- /* Since we've explicitly added instructions to terminate the loop, we no
- * longer need it to have a normative bound.
- */
- ir->normative_bound = -1;
-
- this->progress = true;
- return visit_continue;
-}
-
-
-bool
-lower_bounded_loops(exec_list *instructions)
-{
- lower_bounded_loops_visitor v;
-
- visit_list_elements(&v, instructions);
-
- return v.progress;
-}
((declare (out) float a)
(function main
(signature void (parameters)
- ((loop ()
+ ((loop
((assign (x) (var_ref a) (constant float (1.000000))) break))))))
EOF
((declare (out) float a)
(function main
(signature void (parameters)
- ((loop ()
+ ((loop
((assign (x) (var_ref a) (constant float (1.000000))) break))))))
((declare (in) float b) (declare (out) float a)
(function main
(signature void (parameters)
- ((loop ()
+ ((loop
((assign (x) (var_ref a) (constant float (1.000000)))
(if (expression bool > (var_ref b) (constant float (0.000000))) (break)
())))))))
((declare (in) float b) (declare (out) float a)
(function main
(signature void (parameters)
- ((loop ()
+ ((loop
((assign (x) (var_ref a) (constant float (1.000000)))
(if (expression bool > (var_ref b) (constant float (0.0))) (break)
())))))))
((declare (in) float b) (declare (out) float a) (declare (out) float c)
(function main
(signature void (parameters)
- ((loop ()
+ ((loop
((assign (x) (var_ref a) (constant float (1.000000)))
(if (expression bool > (var_ref b) (constant float (0.000000)))
((assign (x) (var_ref c) (constant float (1.000000))) break)
((declare (in) float b) (declare (out) float a) (declare (out) float c)
(function main
(signature void (parameters)
- ((loop ()
+ ((loop
((assign (x) (var_ref a) (constant float (1.000000)))
(if (expression bool > (var_ref b) (constant float (0.0)))
((assign (x) (var_ref c) (constant float (1.000000))) break)
((declare (in) float b) (declare (out) float a)
(function main
(signature void (parameters)
- ((loop ()
+ ((loop
((assign (x) (var_ref a) (constant float (1.000000)))
(if (expression bool > (var_ref b) (constant float (0.000000))) ()
(break))))))))
((declare (in) float b) (declare (out) float a)
(function main
(signature void (parameters)
- ((loop ()
+ ((loop
((assign (x) (var_ref a) (constant float (1.000000)))
(if (expression bool > (var_ref b) (constant float (0.0))) ()
(break))))))))
((declare (in) float b) (declare (out) float a) (declare (out) float c)
(function main
(signature void (parameters)
- ((loop ()
+ ((loop
((assign (x) (var_ref a) (constant float (1.000000)))
(if (expression bool > (var_ref b) (constant float (0.000000))) ()
((assign (x) (var_ref c) (constant float (1.000000))) break))))))))
((declare (in) float b) (declare (out) float a) (declare (out) float c)
(function main
(signature void (parameters)
- ((loop ()
+ ((loop
((assign (x) (var_ref a) (constant float (1.000000)))
(if (expression bool > (var_ref b) (constant float (0.0))) ()
((assign (x) (var_ref c) (constant float (1.000000))) break))))))))
(declare (in) float cb)
(function main
(signature void (parameters)
- ((loop ()
+ ((loop
((if (expression bool > (var_ref a) (constant float (0.000000)))
((if (expression bool > (var_ref ba) (constant float (0.000000)))
((if (expression bool > (var_ref bb) (constant float (0.000000)))
(signature void (parameters)
((declare (temporary) bool break_flag)
(assign (x) (var_ref break_flag) (constant bool (0)))
- (loop ()
+ (loop
((declare (temporary) bool execute_flag)
(assign (x) (var_ref execute_flag) (constant bool (1)))
(if (expression bool > (var_ref a) (constant float (0.0)))
((declare (in) float aa) (declare (in) float ab) (declare (in) float b)
(function main
(signature void (parameters)
- ((loop ()
+ ((loop
((if (expression bool > (var_ref aa) (constant float (0.000000)))
((if (expression bool > (var_ref ab) (constant float (0.000000)))
(continue)
(signature void (parameters)
((declare (temporary) bool break_flag)
(assign (x) (var_ref break_flag) (constant bool (0)))
- (loop ()
+ (loop
((declare (temporary) bool execute_flag)
(assign (x) (var_ref execute_flag) (constant bool (1)))
(if (expression bool > (var_ref aa) (constant float (0.0)))
((return))
()))
())
- (loop ()
+ (loop
((if (expression bool > (var_ref b) (constant float (0.000000)))
((if (expression bool > (var_ref c) (constant float (0.000000))) (break)
(continue)))
()))
())
(if (var_ref execute_flag)
- ((loop ()
+ ((loop
((if (expression bool > (var_ref b) (constant float (0.0)))
((if (expression bool > (var_ref c) (constant float (0.0))) ()
(continue)))
((declare (out) float a)
(function main
(signature void (parameters)
- ((loop ()
+ ((loop
((assign (x) (var_ref a) (constant float (1.000000))) continue))))))
EOF
((declare (out) float a)
(function main
(signature void (parameters)
- ((loop ()
+ ((loop
((assign (x) (var_ref a) (constant float (1.000000)))))))))
((declare (out) float a) (declare (out) float b)
(function sub
(signature float (parameters)
- ((loop ()
+ ((loop
((assign (x) (var_ref a) (constant float (1.000000)))
(return (constant float (2.000000)))))
(assign (x) (var_ref b) (constant float (3.000000)))
((declare (out) float a) (declare (out) float b)
(function sub
(signature float (parameters)
- ((loop ()
+ ((loop
((assign (x) (var_ref a) (constant float (1.000000)))
(return (constant float (2.000000)))))
(assign (x) (var_ref b) (constant float (3.000000)))
((declare (out) float a) (declare (out) float b)
(function sub
(signature float (parameters)
- ((loop ()
+ ((loop
((assign (x) (var_ref a) (constant float (1.000000)))
(return (constant float (2.000000)))))
(assign (x) (var_ref b) (constant float (3.000000)))
(declare (temporary) float return_value)
(declare (temporary) bool return_flag)
(assign (x) (var_ref return_flag) (constant bool (0)))
- (loop ()
+ (loop
((assign (x) (var_ref a) (constant float (1.000000)))
(assign (x) (var_ref return_value) (constant float (2.000000)))
(assign (x) (var_ref return_flag) (constant bool (1)))
((declare (out) float a) (declare (out) float b)
(function sub
(signature float (parameters)
- ((loop ()
+ ((loop
((assign (x) (var_ref a) (constant float (1.000000)))
(return (constant float (2.000000)))))
(assign (x) (var_ref b) (constant float (3.000000)))
(declare (temporary) float return_value)
(declare (temporary) bool return_flag)
(assign (x) (var_ref return_flag) (constant bool (0)))
- (loop ()
+ (loop
((assign (x) (var_ref a) (constant float (1.000000)))
(assign (x) (var_ref return_value) (constant float (2.000000)))
(assign (x) (var_ref return_flag) (constant bool (1)))
((declare (out) float a) (declare (out) float b)
(function main
(signature void (parameters)
- ((loop ()
+ ((loop
((assign (x) (var_ref a) (constant float (1.000000))) (return)))
(assign (x) (var_ref b) (constant float (2.000000)))))))
EOF
((declare (out) float a) (declare (out) float b)
(function main
(signature void (parameters)
- ((loop ()
+ ((loop
((assign (x) (var_ref a) (constant float (1.000000))) (return)))
(assign (x) (var_ref b) (constant float (2.000000)))))))
((declare (out) float a) (declare (out) float b)
(function main
(signature void (parameters)
- ((loop ()
+ ((loop
((assign (x) (var_ref a) (constant float (1.000000))) (return)))
(assign (x) (var_ref b) (constant float (2.000000)))))))
EOF
(signature void (parameters)
((declare (temporary) bool return_flag)
(assign (x) (var_ref return_flag) (constant bool (0)))
- (loop ()
+ (loop
((assign (x) (var_ref a) (constant float (1.000000)))
(assign (x) (var_ref return_flag) (constant bool (1)))
break))
((declare (out) float a) (declare (out) float b)
(function main
(signature void (parameters)
- ((loop ()
+ ((loop
((assign (x) (var_ref a) (constant float (1.000000))) (return)))
(assign (x) (var_ref b) (constant float (2.000000)))))))
EOF
(signature void (parameters)
((declare (temporary) bool return_flag)
(assign (x) (var_ref return_flag) (constant bool (0)))
- (loop ()
+ (loop
((assign (x) (var_ref a) (constant float (1.000000)))
(assign (x) (var_ref return_flag) (constant bool (1)))
break))
void
fs_visitor::visit(ir_loop *ir)
{
- /* Any normative loop bounds should have been lowered by
- * lower_bounded_loops().
- */
- assert(ir->normative_bound < 0);
-
if (brw->gen < 6 && dispatch_width == 16) {
fail("Can't support (non-uniform) control flow on 16-wide\n");
}
|| progress;
} while (progress);
- lower_bounded_loops(shader->ir);
-
/* Make a pass over the IR to add state references for any built-in
* uniforms that are used. This has to be done now (during linking).
* Code generation doesn't happen until the first time this shader is
void
vec4_visitor::visit(ir_loop *ir)
{
- /* Any normative loop bounds should have been lowered by
- * lower_bounded_loops().
- */
- assert(ir->normative_bound < 0);
-
/* We don't want debugging output to print the whole body of the
* loop as the annotation.
*/
void
ir_to_mesa_visitor::visit(ir_loop *ir)
{
- /* Any normative loop bounds should have been lowered by
- * lower_bounded_loops().
- */
- assert(ir->normative_bound < 0);
-
emit(NULL, OPCODE_BGNLOOP);
visit_exec_list(&ir->body_instructions, this);
progress = lower_vector_insert(ir, true) || progress;
} while (progress);
- lower_bounded_loops(ir);
-
validate_ir_tree(ir);
}
void
glsl_to_tgsi_visitor::visit(ir_loop *ir)
{
- /* Any normative loop bounds should have been lowered by
- * lower_bounded_loops().
- */
- assert(ir->normative_bound < 0);
-
emit(NULL, TGSI_OPCODE_BGNLOOP);
visit_exec_list(&ir->body_instructions, this);
} while (progress);
- lower_bounded_loops(ir);
-
validate_ir_tree(ir);
}