[Mesa-dev] [PATCH 1/7] glsl/lower_if: move and rename found_control_flow

Marek Olšák maraeo at gmail.com
Fri Oct 28 23:13:36 UTC 2016


From: Marek Olšák <marek.olsak at amd.com>

I'll want to update more variables in check_control_flow, so using
the visitor is convenient.
---
 src/compiler/glsl/lower_if_to_cond_assign.cpp | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/src/compiler/glsl/lower_if_to_cond_assign.cpp b/src/compiler/glsl/lower_if_to_cond_assign.cpp
index a948466..2875e79 100644
--- a/src/compiler/glsl/lower_if_to_cond_assign.cpp
+++ b/src/compiler/glsl/lower_if_to_cond_assign.cpp
@@ -66,20 +66,21 @@ public:
    }
 
    ~ir_if_to_cond_assign_visitor()
    {
       _mesa_set_destroy(this->condition_variables, NULL);
    }
 
    ir_visitor_status visit_enter(ir_if *);
    ir_visitor_status visit_leave(ir_if *);
 
+   bool found_unsupported_op;
    bool progress;
    unsigned max_depth;
    unsigned depth;
 
    struct set *condition_variables;
 };
 
 } /* anonymous namespace */
 
 bool
@@ -91,28 +92,29 @@ lower_if_to_cond_assign(exec_list *instructions, unsigned max_depth)
    ir_if_to_cond_assign_visitor v(max_depth);
 
    visit_list_elements(&v, instructions);
 
    return v.progress;
 }
 
 void
 check_control_flow(ir_instruction *ir, void *data)
 {
-   bool *found_control_flow = (bool *)data;
+   ir_if_to_cond_assign_visitor *v = (ir_if_to_cond_assign_visitor *)data;
+
    switch (ir->ir_type) {
    case ir_type_call:
    case ir_type_discard:
    case ir_type_loop:
    case ir_type_loop_jump:
    case ir_type_return:
-      *found_control_flow = true;
+      v->found_unsupported_op = true;
       break;
    default:
       break;
    }
 }
 
 void
 move_block_to_cond_assign(void *mem_ctx,
 			  ir_if *if_ir, ir_rvalue *cond_expr,
 			  exec_list *instructions,
@@ -168,32 +170,33 @@ ir_if_to_cond_assign_visitor::visit_enter(ir_if *ir)
    return visit_continue;
 }
 
 ir_visitor_status
 ir_if_to_cond_assign_visitor::visit_leave(ir_if *ir)
 {
    /* Only flatten when beyond the GPU's maximum supported nesting depth. */
    if (this->depth-- <= this->max_depth)
       return visit_continue;
 
-   bool found_control_flow = false;
+   this->found_unsupported_op = false;
+
    ir_assignment *assign;
 
    /* Check that both blocks don't contain anything we can't support. */
    foreach_in_list(ir_instruction, then_ir, &ir->then_instructions) {
-      visit_tree(then_ir, check_control_flow, &found_control_flow);
+      visit_tree(then_ir, check_control_flow, this);
    }
    foreach_in_list(ir_instruction, else_ir, &ir->else_instructions) {
-      visit_tree(else_ir, check_control_flow, &found_control_flow);
+      visit_tree(else_ir, check_control_flow, this);
    }
-   if (found_control_flow)
-      return visit_continue;
+   if (this->found_unsupported_op)
+      return visit_continue; /* can't handle inner unsupported opcodes */
 
    void *mem_ctx = ralloc_parent(ir);
 
    /* Store the condition to a variable.  Move all of the instructions from
     * the then-clause of the if-statement.  Use the condition variable as a
     * condition for all assignments.
     */
    ir_variable *const then_var =
       new(mem_ctx) ir_variable(glsl_type::bool_type,
 			       "if_to_cond_assign_then",
-- 
2.7.4



More information about the mesa-dev mailing list