Commit 088494aa authored by Paul Berry's avatar Paul Berry

glsl/loops: Get rid of lower_bounded_loops and ir_loop::normative_bound.

Now that loop_controls no longer creates normatively bound loops,
there is no need for ir_loop::normative_bound or the
lower_bounded_loops pass.
Reviewed-by: default avatarIan Romanick <ian.d.romanick@intel.com>
parent 7ea3baa6
......@@ -59,7 +59,6 @@ LIBGLSL_FILES = \
$(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 \
......
......@@ -1277,7 +1277,6 @@ ir_constant::is_basis() const
ir_loop::ir_loop()
{
this->ir_type = ir_type_loop;
this->normative_bound = -1;
}
......
......@@ -1024,13 +1024,6 @@ public:
/** 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;
};
......
......@@ -158,8 +158,6 @@ ir_loop::clone(void *mem_ctx, struct hash_table *ht) const
{
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));
......
......@@ -101,7 +101,6 @@ bool do_swizzle_swizzle(exec_list *instructions);
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);
......
......@@ -523,10 +523,7 @@ ir_print_visitor::visit(ir_if *ir)
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) {
......
......@@ -488,34 +488,16 @@ ir_reader::read_if(s_expression *expr, ir_loop *loop_ctx)
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;
......
......@@ -193,13 +193,6 @@ loop_control_visitor::visit_leave(ir_loop *ir)
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
......@@ -215,7 +208,7 @@ loop_control_visitor::visit_leave(ir_loop *ir)
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);
......
......@@ -228,9 +228,6 @@ loop_unroll_visitor::visit_leave(ir_loop *ir)
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.
*/
......
/*
* 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;
}
......@@ -8,6 +8,6 @@
((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))))))
......@@ -8,7 +8,7 @@
((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)
())))))))
......@@ -9,7 +9,7 @@
((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)
......
......@@ -8,7 +8,7 @@
((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))))))))
......@@ -9,7 +9,7 @@
((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))))))))
......@@ -12,7 +12,7 @@
(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)))
......
......@@ -5,7 +5,7 @@
(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)))
......
......@@ -10,7 +10,7 @@
((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)
......
......@@ -3,7 +3,7 @@
(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)))
......
......@@ -19,7 +19,7 @@
((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)))
......
......@@ -14,7 +14,7 @@
()))
())
(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)))
......
......@@ -8,6 +8,6 @@
((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)))))))))
......@@ -8,7 +8,7 @@
((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)))
......
......@@ -8,7 +8,7 @@
((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)))
......
......@@ -6,7 +6,7 @@
(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)))
......
......@@ -8,7 +8,7 @@
((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)))
......
......@@ -6,7 +6,7 @@
(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)))
......
......@@ -8,7 +8,7 @@
((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)))))))
......@@ -8,7 +8,7 @@
((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
......@@ -3,7 +3,7 @@
(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))
......
......@@ -8,7 +8,7 @@
((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
......@@ -3,7 +3,7 @@
(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))
......
......@@ -2181,11 +2181,6 @@ fs_visitor::visit(ir_if *ir)
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");
}
......
......@@ -213,8 +213,6 @@ brw_link_shader(struct gl_context *ctx, struct gl_shader_program *shProg)
|| 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
......
......@@ -1007,11 +1007,6 @@ vec4_visitor::visit(ir_variable *ir)
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.
*/
......
......@@ -759,11 +759,6 @@ ir_to_mesa_visitor::visit(ir_variable *ir)
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);
......@@ -3057,8 +3052,6 @@ _mesa_ir_link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
progress = lower_vector_insert(ir, true) || progress;
} while (progress);
lower_bounded_loops(ir);
validate_ir_tree(ir);
}
......
......@@ -1137,11 +1137,6 @@ glsl_to_tgsi_visitor::visit(ir_variable *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);
......@@ -5307,8 +5302,6 @@ st_link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
} while (progress);
lower_bounded_loops(ir);
validate_ir_tree(ir);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment