[Mesa-dev] [PATCH 05/16] glsl: Use typed foreach_in_list_safe instead of foreach_list_safe.

Matt Turner mattst88 at gmail.com
Wed Jun 25 11:51:06 PDT 2014


---
 src/glsl/ast_function.cpp                   | 14 ++++----------
 src/glsl/ast_to_hir.cpp                     | 12 ++++++------
 src/glsl/ir.cpp                             |  4 ++--
 src/glsl/ir_function_detect_recursion.cpp   |  8 +++-----
 src/glsl/ir_hv_accept.cpp                   |  3 +--
 src/glsl/ir_rvalue_visitor.cpp              |  3 +--
 src/glsl/linker.cpp                         |  4 +---
 src/glsl/loop_analysis.cpp                  | 12 +++---------
 src/glsl/lower_if_to_cond_assign.cpp        |  4 +---
 src/glsl/lower_named_interface_blocks.cpp   |  4 ++--
 src/glsl/lower_vec_index_to_cond_assign.cpp |  3 +--
 src/glsl/lower_vec_index_to_swizzle.cpp     |  3 +--
 src/glsl/opt_array_splitting.cpp            |  4 +---
 src/glsl/opt_constant_propagation.cpp       |  4 +---
 src/glsl/opt_copy_propagation.cpp           |  4 +---
 src/glsl/opt_copy_propagation_elements.cpp  | 10 +++-------
 src/glsl/opt_dead_code_local.cpp            | 15 ++++-----------
 src/glsl/opt_dead_functions.cpp             |  7 ++-----
 src/glsl/opt_function_inlining.cpp          |  3 +--
 src/glsl/opt_structure_splitting.cpp        |  7 ++-----
 20 files changed, 41 insertions(+), 87 deletions(-)

diff --git a/src/glsl/ast_function.cpp b/src/glsl/ast_function.cpp
index 394d6dc..b4c4b78 100644
--- a/src/glsl/ast_function.cpp
+++ b/src/glsl/ast_function.cpp
@@ -685,8 +685,7 @@ process_vec_mat_constructor(exec_list *instructions,
    bool all_parameters_are_constant = true;
 
    /* Type cast each parameter and, if possible, fold constants. */
-   foreach_list_safe(n, &actual_parameters) {
-      ir_rvalue *ir = (ir_rvalue *) n;
+   foreach_in_list_safe(ir_rvalue, ir, &actual_parameters) {
       ir_rvalue *result = ir;
 
       /* Apply implicit conversions (not the scalar constructor rules!). See
@@ -813,8 +812,7 @@ process_array_constructor(exec_list *instructions,
    bool all_parameters_are_constant = true;
 
    /* Type cast each parameter and, if possible, fold constants. */
-   foreach_list_safe(n, &actual_parameters) {
-      ir_rvalue *ir = (ir_rvalue *) n;
+   foreach_in_list_safe(ir_rvalue, ir, &actual_parameters) {
       ir_rvalue *result = ir;
 
       /* Apply implicit conversions (not the scalar constructor rules!). See
@@ -1629,9 +1627,7 @@ ast_function_expression::hir(exec_list *instructions,
        * need to break them up into a series of column vectors.
        */
       if (constructor_type->base_type != GLSL_TYPE_FLOAT) {
-	 foreach_list_safe(n, &actual_parameters) {
-	    ir_rvalue *matrix = (ir_rvalue *) n;
-
+	 foreach_in_list_safe(ir_rvalue, matrix, &actual_parameters) {
 	    if (!matrix->type->is_matrix())
 	       continue;
 
@@ -1655,9 +1651,7 @@ ast_function_expression::hir(exec_list *instructions,
       bool all_parameters_are_constant = true;
 
       /* Type cast each parameter and, if possible, fold constants.*/
-      foreach_list_safe(n, &actual_parameters) {
-	 ir_rvalue *ir = (ir_rvalue *) n;
-
+      foreach_in_list_safe(ir_rvalue, ir, &actual_parameters) {
 	 const glsl_type *desired_type =
 	    glsl_type::get_instance(constructor_type->base_type,
 				    ir->type->vector_elements,
diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index 9d8d371..cf423ec 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -112,8 +112,8 @@ _mesa_ast_to_hir(exec_list *instructions, struct _mesa_glsl_parse_state *state)
     * applications depend on this behavior, and it matches what nearly all
     * other drivers do.
     */
-   foreach_list_safe(node, instructions) {
-      ir_variable *const var = ((ir_instruction *) node)->as_variable();
+   foreach_in_list_safe(ir_instruction, node, instructions) {
+      ir_variable *const var = node->as_variable();
 
       if (var == NULL)
          continue;
@@ -5585,8 +5585,8 @@ ast_interface_block::hir(exec_list *instructions,
           * thinking there are conflicting definitions of gl_PerVertex in the
           * shader.
           */
-         foreach_list_safe(node, instructions) {
-            ir_variable *const var = ((ir_instruction *) node)->as_variable();
+         foreach_in_list_safe(ir_instruction, node, instructions) {
+            ir_variable *const var = node->as_variable();
             if (var != NULL &&
                 var->get_interface_type() == earlier_per_vertex &&
                 var->data.mode == var_mode) {
@@ -5850,8 +5850,8 @@ remove_per_vertex_blocks(exec_list *instructions,
    /* Remove any ir_variable declarations that refer to the interface block
     * we're removing.
     */
-   foreach_list_safe(node, instructions) {
-      ir_variable *const var = ((ir_instruction *) node)->as_variable();
+   foreach_in_list_safe(ir_instruction, node, instructions) {
+      ir_variable *const var = node->as_variable();
       if (var != NULL && var->get_interface_type() == per_vertex &&
           var->data.mode == mode) {
          state->symbols->disable_variable(var->name);
diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp
index 9fb4157..1d8bb6e 100644
--- a/src/glsl/ir.cpp
+++ b/src/glsl/ir.cpp
@@ -1720,8 +1720,8 @@ ir_rvalue::error_value(void *mem_ctx)
 void
 visit_exec_list(exec_list *list, ir_visitor *visitor)
 {
-   foreach_list_safe(n, list) {
-      ((ir_instruction *) n)->accept(visitor);
+   foreach_in_list_safe(ir_instruction, node, list) {
+      node->accept(visitor);
    }
 }
 
diff --git a/src/glsl/ir_function_detect_recursion.cpp b/src/glsl/ir_function_detect_recursion.cpp
index 5813315..b2334d2 100644
--- a/src/glsl/ir_function_detect_recursion.cpp
+++ b/src/glsl/ir_function_detect_recursion.cpp
@@ -229,15 +229,13 @@ public:
 static void
 destroy_links(exec_list *list, function *f)
 {
-   foreach_list_safe(node, list) {
-      struct call_node *n = (struct call_node *) node;
-
+   foreach_in_list_safe(call_node, node, list) {
       /* If this is the right function, remove it.  Note that the loop cannot
        * terminate now.  There can be multiple links to a function if it is
        * either called multiple times or calls multiple times.
        */
-      if (n->func == f)
-	 n->remove();
+      if (node->func == f)
+	 node->remove();
    }
 }
 
diff --git a/src/glsl/ir_hv_accept.cpp b/src/glsl/ir_hv_accept.cpp
index 2a1f70e..7fcab6d 100644
--- a/src/glsl/ir_hv_accept.cpp
+++ b/src/glsl/ir_hv_accept.cpp
@@ -49,8 +49,7 @@ visit_list_elements(ir_hierarchical_visitor *v, exec_list *l,
 {
    ir_instruction *prev_base_ir = v->base_ir;
 
-   foreach_list_safe(n, l) {
-      ir_instruction *const ir = (ir_instruction *) n;
+   foreach_in_list_safe(ir_instruction, ir, l) {
       if (statement_list)
          v->base_ir = ir;
       ir_visitor_status s = ir->accept(v);
diff --git a/src/glsl/ir_rvalue_visitor.cpp b/src/glsl/ir_rvalue_visitor.cpp
index fcbe944..314173b 100644
--- a/src/glsl/ir_rvalue_visitor.cpp
+++ b/src/glsl/ir_rvalue_visitor.cpp
@@ -123,8 +123,7 @@ ir_rvalue_base_visitor::rvalue_visit(ir_assignment *ir)
 ir_visitor_status
 ir_rvalue_base_visitor::rvalue_visit(ir_call *ir)
 {
-   foreach_list_safe(n, &ir->actual_parameters) {
-      ir_rvalue *param = (ir_rvalue *) n;
+   foreach_in_list_safe(ir_rvalue, param, &ir->actual_parameters) {
       ir_rvalue *new_param = param;
       handle_rvalue(&new_param);
 
diff --git a/src/glsl/linker.cpp b/src/glsl/linker.cpp
index 1737359..47ae3f9 100644
--- a/src/glsl/linker.cpp
+++ b/src/glsl/linker.cpp
@@ -961,9 +961,7 @@ move_non_declarations(exec_list *instructions, exec_node *last,
       temps = hash_table_ctor(0, hash_table_pointer_hash,
 			      hash_table_pointer_compare);
 
-   foreach_list_safe(node, instructions) {
-      ir_instruction *inst = (ir_instruction *) node;
-
+   foreach_in_list_safe(ir_instruction, inst, instructions) {
       if (inst->as_function())
 	 continue;
 
diff --git a/src/glsl/loop_analysis.cpp b/src/glsl/loop_analysis.cpp
index 0e232e7..21d46eb 100644
--- a/src/glsl/loop_analysis.cpp
+++ b/src/glsl/loop_analysis.cpp
@@ -300,9 +300,7 @@ loop_analysis::visit_leave(ir_loop *ir)
    }
 
 
-   foreach_list_safe(node, &ls->variables) {
-      loop_variable *lv = (loop_variable *) node;
-
+   foreach_in_list_safe(loop_variable, lv, &ls->variables) {
       /* Move variables that are already marked as being loop constant to
        * a separate list.  These trivially don't need to be tested.
        */
@@ -330,9 +328,7 @@ loop_analysis::visit_leave(ir_loop *ir)
    do {
       progress = false;
 
-      foreach_list_safe(node, &ls->variables) {
-	 loop_variable *lv = (loop_variable *) node;
-
+      foreach_in_list_safe(loop_variable, lv, &ls->variables) {
 	 if (lv->conditional_or_nested_assignment || (lv->num_assignments > 1))
 	    continue;
 
@@ -356,9 +352,7 @@ loop_analysis::visit_leave(ir_loop *ir)
    /* The remaining variables that are not loop invariant might be loop
     * induction variables.
     */
-   foreach_list_safe(node, &ls->variables) {
-      loop_variable *lv = (loop_variable *) node;
-
+   foreach_in_list_safe(loop_variable, lv, &ls->variables) {
       /* If there is more than one assignment to a variable, it cannot be a
        * loop induction variable.  This isn't strictly true, but this is a
        * very simple induction variable detector, and it can't handle more
diff --git a/src/glsl/lower_if_to_cond_assign.cpp b/src/glsl/lower_if_to_cond_assign.cpp
index 89b4a4a..3232ce9 100644
--- a/src/glsl/lower_if_to_cond_assign.cpp
+++ b/src/glsl/lower_if_to_cond_assign.cpp
@@ -116,9 +116,7 @@ move_block_to_cond_assign(void *mem_ctx,
 			  exec_list *instructions,
 			  struct hash_table *ht)
 {
-   foreach_list_safe(node, instructions) {
-      ir_instruction *ir = (ir_instruction *) node;
-
+   foreach_in_list_safe(ir_instruction, ir, instructions) {
       if (ir->ir_type == ir_type_assignment) {
 	 ir_assignment *assign = (ir_assignment *)ir;
 
diff --git a/src/glsl/lower_named_interface_blocks.cpp b/src/glsl/lower_named_interface_blocks.cpp
index 04e0d36..7304c51 100644
--- a/src/glsl/lower_named_interface_blocks.cpp
+++ b/src/glsl/lower_named_interface_blocks.cpp
@@ -99,8 +99,8 @@ flatten_named_interface_blocks_declarations::run(exec_list *instructions)
     * The interface block variables are stored in the interface_namespace
     * hash table so they can be used in the second pass.
     */
-   foreach_list_safe(node, instructions) {
-      ir_variable *var = ((ir_instruction *) node)->as_variable();
+   foreach_in_list_safe(ir_instruction, node, instructions) {
+      ir_variable *var = node->as_variable();
       if (!var || !var->is_interface_instance())
          continue;
 
diff --git a/src/glsl/lower_vec_index_to_cond_assign.cpp b/src/glsl/lower_vec_index_to_cond_assign.cpp
index fe6a3f2..0c3394a 100644
--- a/src/glsl/lower_vec_index_to_cond_assign.cpp
+++ b/src/glsl/lower_vec_index_to_cond_assign.cpp
@@ -197,8 +197,7 @@ ir_vec_index_to_cond_assign_visitor::visit_leave(ir_assignment *ir)
 ir_visitor_status
 ir_vec_index_to_cond_assign_visitor::visit_enter(ir_call *ir)
 {
-   foreach_list_safe(n, &ir->actual_parameters) {
-      ir_rvalue *param = (ir_rvalue *) n;
+   foreach_in_list_safe(ir_rvalue, param, &ir->actual_parameters) {
       ir_rvalue *new_param = convert_vector_extract_to_cond_assign(param);
 
       if (new_param != param) {
diff --git a/src/glsl/lower_vec_index_to_swizzle.cpp b/src/glsl/lower_vec_index_to_swizzle.cpp
index b5bb00c..4d4d2f1 100644
--- a/src/glsl/lower_vec_index_to_swizzle.cpp
+++ b/src/glsl/lower_vec_index_to_swizzle.cpp
@@ -131,8 +131,7 @@ ir_vec_index_to_swizzle_visitor::visit_enter(ir_assignment *ir)
 ir_visitor_status
 ir_vec_index_to_swizzle_visitor::visit_enter(ir_call *ir)
 {
-   foreach_list_safe(n, &ir->actual_parameters) {
-      ir_rvalue *param = (ir_rvalue *) n;
+   foreach_in_list_safe(ir_rvalue, param, &ir->actual_parameters) {
       ir_rvalue *new_param = convert_vector_extract_to_swizzle(param);
 
       if (new_param != param) {
diff --git a/src/glsl/opt_array_splitting.cpp b/src/glsl/opt_array_splitting.cpp
index 7d29fbc..ebb076b 100644
--- a/src/glsl/opt_array_splitting.cpp
+++ b/src/glsl/opt_array_splitting.cpp
@@ -223,9 +223,7 @@ ir_array_reference_visitor::get_split_list(exec_list *instructions,
    }
 
    /* Trim out variables we found that we can't split. */
-   foreach_list_safe(n, &variable_list) {
-      variable_entry *entry = (variable_entry *) n;
-
+   foreach_in_list_safe(variable_entry, entry, &variable_list) {
       if (debug) {
 	 printf("array %s@%p: decl %d, split %d\n",
 		entry->var->name, (void *) entry->var, entry->declaration,
diff --git a/src/glsl/opt_constant_propagation.cpp b/src/glsl/opt_constant_propagation.cpp
index 42bdad4..c334e12 100644
--- a/src/glsl/opt_constant_propagation.cpp
+++ b/src/glsl/opt_constant_propagation.cpp
@@ -393,9 +393,7 @@ ir_constant_propagation_visitor::kill(ir_variable *var, unsigned write_mask)
       return;
 
    /* Remove any entries currently in the ACP for this kill. */
-   foreach_list_safe(n, this->acp) {
-      acp_entry *entry = (acp_entry *) n;
-
+   foreach_in_list_safe(acp_entry, entry, this->acp) {
       if (entry->var == var) {
 	 entry->write_mask &= ~write_mask;
 	 if (entry->write_mask == 0)
diff --git a/src/glsl/opt_copy_propagation.cpp b/src/glsl/opt_copy_propagation.cpp
index c78cf0c..5c65af6 100644
--- a/src/glsl/opt_copy_propagation.cpp
+++ b/src/glsl/opt_copy_propagation.cpp
@@ -286,9 +286,7 @@ ir_copy_propagation_visitor::kill(ir_variable *var)
    assert(var != NULL);
 
    /* Remove any entries currently in the ACP for this kill. */
-   foreach_list_safe(n, acp) {
-      acp_entry *entry = (acp_entry *) n;
-
+   foreach_in_list_safe(acp_entry, entry, acp) {
       if (entry->lhs == var || entry->rhs == var) {
 	 entry->remove();
       }
diff --git a/src/glsl/opt_copy_propagation_elements.cpp b/src/glsl/opt_copy_propagation_elements.cpp
index bcd7918..f5f59b7 100644
--- a/src/glsl/opt_copy_propagation_elements.cpp
+++ b/src/glsl/opt_copy_propagation_elements.cpp
@@ -340,8 +340,7 @@ ir_copy_propagation_elements_visitor::handle_if_block(exec_list *instructions)
    /* Move the new kills into the parent block's list, removing them
     * from the parent's ACP list in the process.
     */
-   foreach_list_safe(node, new_kills) {
-      kill_entry *k = (kill_entry *)node;
+   foreach_in_list_safe(kill_entry, k, new_kills) {
       kill(k);
    }
 }
@@ -384,8 +383,7 @@ ir_copy_propagation_elements_visitor::visit_enter(ir_loop *ir)
    this->acp = orig_acp;
    this->killed_all = this->killed_all || orig_killed_all;
 
-   foreach_list_safe(node, new_kills) {
-      kill_entry *k = (kill_entry *)node;
+   foreach_in_list_safe(kill_entry, k, new_kills) {
       kill(k);
    }
 
@@ -397,9 +395,7 @@ ir_copy_propagation_elements_visitor::visit_enter(ir_loop *ir)
 void
 ir_copy_propagation_elements_visitor::kill(kill_entry *k)
 {
-   foreach_list_safe(node, acp) {
-      acp_entry *entry = (acp_entry *)node;
-
+   foreach_in_list_safe(acp_entry, entry, acp) {
       if (entry->lhs == k->var) {
 	 entry->write_mask = entry->write_mask & ~k->write_mask;
 	 if (entry->write_mask == 0) {
diff --git a/src/glsl/opt_dead_code_local.cpp b/src/glsl/opt_dead_code_local.cpp
index a85a59c..800e96a 100644
--- a/src/glsl/opt_dead_code_local.cpp
+++ b/src/glsl/opt_dead_code_local.cpp
@@ -70,9 +70,7 @@ public:
 
    void use_channels(ir_variable *const var, int used)
    {
-      foreach_list_safe(n, this->assignments) {
-	 assignment_entry *entry = (assignment_entry *) n;
-
+      foreach_in_list_safe(assignment_entry, entry, this->assignments) {
 	 if (entry->lhs == var) {
 	    if (var->type->is_scalar() || var->type->is_vector()) {
 	       if (debug)
@@ -119,8 +117,7 @@ public:
       /* For the purpose of dead code elimination, emitting a vertex counts as
        * "reading" all of the currently assigned output variables.
        */
-      foreach_list_safe(n, this->assignments) {
-         assignment_entry *entry = (assignment_entry *) n;
+      foreach_in_list_safe(assignment_entry, entry, this->assignments) {
          if (entry->lhs->data.mode == ir_var_shader_out) {
             if (debug)
                printf("kill %s\n", entry->lhs->name);
@@ -196,9 +193,7 @@ process_assignment(void *ctx, ir_assignment *ir, exec_list *assignments)
 	    printf("looking for %s.0x%01x to remove\n", var->name,
 		   ir->write_mask);
 
-	 foreach_list_safe(n, assignments) {
-	    assignment_entry *entry = (assignment_entry *) n;
-
+	 foreach_in_list_safe(assignment_entry, entry, assignments) {
 	    if (entry->lhs != var)
 	       continue;
 
@@ -258,9 +253,7 @@ process_assignment(void *ctx, ir_assignment *ir, exec_list *assignments)
 	  */
 	 if (debug)
 	    printf("looking for %s to remove\n", var->name);
-	 foreach_list_safe(n, assignments) {
-	    assignment_entry *entry = (assignment_entry *) n;
-
+	 foreach_in_list_safe(assignment_entry, entry, assignments) {
 	    if (entry->lhs == var) {
 	       if (debug)
 		  printf("removing %s\n", var->name);
diff --git a/src/glsl/opt_dead_functions.cpp b/src/glsl/opt_dead_functions.cpp
index 81c46d5..5dff165 100644
--- a/src/glsl/opt_dead_functions.cpp
+++ b/src/glsl/opt_dead_functions.cpp
@@ -122,9 +122,7 @@ do_dead_functions(exec_list *instructions)
     * the unused ones, and remove function definitions that have no more
     * signatures.
     */
-    foreach_list_safe(n, &v.signature_list) {
-      signature_entry *entry = (signature_entry *) n;
-
+    foreach_in_list_safe(signature_entry, entry, &v.signature_list) {
       if (!entry->used) {
 	 entry->signature->remove();
 	 delete entry->signature;
@@ -136,8 +134,7 @@ do_dead_functions(exec_list *instructions)
    /* We don't just do this above when we nuked a signature because of
     * const pointers.
     */
-   foreach_list_safe(n, instructions) {
-      ir_instruction *ir = (ir_instruction *) n;
+   foreach_in_list_safe(ir_instruction, ir, instructions) {
       ir_function *func = ir->as_function();
 
       if (func && func->signatures.is_empty()) {
diff --git a/src/glsl/opt_function_inlining.cpp b/src/glsl/opt_function_inlining.cpp
index 7212123..b84bb8e 100644
--- a/src/glsl/opt_function_inlining.cpp
+++ b/src/glsl/opt_function_inlining.cpp
@@ -341,8 +341,7 @@ ir_variable_replacement_visitor::visit_leave(ir_dereference_record *ir)
 ir_visitor_status
 ir_variable_replacement_visitor::visit_leave(ir_call *ir)
 {
-   foreach_list_safe(n, &ir->actual_parameters) {
-      ir_rvalue *param = (ir_rvalue *) n;
+   foreach_in_list_safe(ir_rvalue, param, &ir->actual_parameters) {
       ir_rvalue *new_param = param;
       replace_rvalue(&new_param);
 
diff --git a/src/glsl/opt_structure_splitting.cpp b/src/glsl/opt_structure_splitting.cpp
index 2abd7e4..5e82fe9 100644
--- a/src/glsl/opt_structure_splitting.cpp
+++ b/src/glsl/opt_structure_splitting.cpp
@@ -313,9 +313,7 @@ do_structure_splitting(exec_list *instructions)
    visit_list_elements(&refs, instructions);
 
    /* Trim out variables we can't split. */
-   foreach_list_safe(n, &refs.variable_list) {
-      variable_entry *entry = (variable_entry *) n;
-
+   foreach_in_list_safe(variable_entry, entry, &refs.variable_list) {
       if (debug) {
 	 printf("structure %s@%p: decl %d, whole_access %d\n",
 		entry->var->name, (void *) entry->var, entry->declaration,
@@ -335,8 +333,7 @@ do_structure_splitting(exec_list *instructions)
    /* Replace the decls of the structures to be split with their split
     * components.
     */
-   foreach_list_safe(n, &refs.variable_list) {
-      variable_entry *entry = (variable_entry *) n;
+   foreach_in_list_safe(variable_entry, entry, &refs.variable_list) {
       const struct glsl_type *type = entry->var->type;
 
       entry->mem_ctx = ralloc_parent(entry->var);
-- 
1.8.3.2



More information about the mesa-dev mailing list