[Mesa-dev] [PATCH 2/8] glsl: Convert piles of foreach_iter to foreach_list_safe.

Kenneth Graunke kenneth at whitecape.org
Sat Jan 11 02:37:06 PST 2014


In these cases, we edit the list (or at least might be), so we use the
foreach_list_safe variant.

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
---
 src/glsl/ir.cpp                             |  4 ++--
 src/glsl/ir_rvalue_visitor.cpp              |  4 ++--
 src/glsl/lower_vec_index_to_cond_assign.cpp |  4 ++--
 src/glsl/lower_vec_index_to_swizzle.cpp     |  4 ++--
 src/glsl/opt_array_splitting.cpp            |  4 ++--
 src/glsl/opt_constant_propagation.cpp       |  4 ++--
 src/glsl/opt_copy_propagation.cpp           |  4 ++--
 src/glsl/opt_dead_code_local.cpp            | 16 ++++++++--------
 src/glsl/opt_dead_functions.cpp             |  8 ++++----
 src/glsl/opt_function_inlining.cpp          |  4 ++--
 src/glsl/opt_if_simplification.cpp          |  8 ++++----
 src/glsl/opt_structure_splitting.cpp        |  8 ++++----
 12 files changed, 36 insertions(+), 36 deletions(-)

diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp
index 720fcdc..6ffa987 100644
--- a/src/glsl/ir.cpp
+++ b/src/glsl/ir.cpp
@@ -1717,8 +1717,8 @@ ir_rvalue::error_value(void *mem_ctx)
 void
 visit_exec_list(exec_list *list, ir_visitor *visitor)
 {
-   foreach_iter(exec_list_iterator, iter, *list) {
-      ((ir_instruction *)iter.get())->accept(visitor);
+   foreach_list_safe(n, list) {
+      ((ir_instruction *) n)->accept(visitor);
    }
 }
 
diff --git a/src/glsl/ir_rvalue_visitor.cpp b/src/glsl/ir_rvalue_visitor.cpp
index 9d8ccd9..fcbe944 100644
--- a/src/glsl/ir_rvalue_visitor.cpp
+++ b/src/glsl/ir_rvalue_visitor.cpp
@@ -123,8 +123,8 @@ ir_rvalue_base_visitor::rvalue_visit(ir_assignment *ir)
 ir_visitor_status
 ir_rvalue_base_visitor::rvalue_visit(ir_call *ir)
 {
-   foreach_iter(exec_list_iterator, iter, *ir) {
-      ir_rvalue *param = (ir_rvalue *)iter.get();
+   foreach_list_safe(n, &ir->actual_parameters) {
+      ir_rvalue *param = (ir_rvalue *) n;
       ir_rvalue *new_param = param;
       handle_rvalue(&new_param);
 
diff --git a/src/glsl/lower_vec_index_to_cond_assign.cpp b/src/glsl/lower_vec_index_to_cond_assign.cpp
index 8080006..fe6a3f2 100644
--- a/src/glsl/lower_vec_index_to_cond_assign.cpp
+++ b/src/glsl/lower_vec_index_to_cond_assign.cpp
@@ -197,8 +197,8 @@ 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_iter(exec_list_iterator, iter, *ir) {
-      ir_rvalue *param = (ir_rvalue *)iter.get();
+   foreach_list_safe(n, &ir->actual_parameters) {
+      ir_rvalue *param = (ir_rvalue *) n;
       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 4698579..b5bb00c 100644
--- a/src/glsl/lower_vec_index_to_swizzle.cpp
+++ b/src/glsl/lower_vec_index_to_swizzle.cpp
@@ -131,8 +131,8 @@ 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_iter(exec_list_iterator, iter, *ir) {
-      ir_rvalue *param = (ir_rvalue *)iter.get();
+   foreach_list_safe(n, &ir->actual_parameters) {
+      ir_rvalue *param = (ir_rvalue *) n;
       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 70660eb..f37d090 100644
--- a/src/glsl/opt_array_splitting.cpp
+++ b/src/glsl/opt_array_splitting.cpp
@@ -224,8 +224,8 @@ ir_array_reference_visitor::get_split_list(exec_list *instructions,
    }
 
    /* Trim out variables we found that we can't split. */
-   foreach_iter(exec_list_iterator, iter, variable_list) {
-      variable_entry *entry = (variable_entry *)iter.get();
+   foreach_list_safe(n, &variable_list) {
+      variable_entry *entry = (variable_entry *) n;
 
       if (debug) {
 	 printf("array %s@%p: decl %d, split %d\n",
diff --git a/src/glsl/opt_constant_propagation.cpp b/src/glsl/opt_constant_propagation.cpp
index 6fe16a9..a2d1b0f 100644
--- a/src/glsl/opt_constant_propagation.cpp
+++ b/src/glsl/opt_constant_propagation.cpp
@@ -398,8 +398,8 @@ ir_constant_propagation_visitor::kill(ir_variable *var, unsigned write_mask)
       return;
 
    /* Remove any entries currently in the ACP for this kill. */
-   foreach_iter(exec_list_iterator, iter, *this->acp) {
-      acp_entry *entry = (acp_entry *)iter.get();
+   foreach_list_safe(n, this->acp) {
+      acp_entry *entry = (acp_entry *) n;
 
       if (entry->var == var) {
 	 entry->write_mask &= ~write_mask;
diff --git a/src/glsl/opt_copy_propagation.cpp b/src/glsl/opt_copy_propagation.cpp
index 887fdeb..3a73342 100644
--- a/src/glsl/opt_copy_propagation.cpp
+++ b/src/glsl/opt_copy_propagation.cpp
@@ -292,8 +292,8 @@ ir_copy_propagation_visitor::kill(ir_variable *var)
    assert(var != NULL);
 
    /* Remove any entries currently in the ACP for this kill. */
-   foreach_iter(exec_list_iterator, iter, *acp) {
-      acp_entry *entry = (acp_entry *)iter.get();
+   foreach_list_safe(n, acp) {
+      acp_entry *entry = (acp_entry *) n;
 
       if (entry->lhs == var || entry->rhs == var) {
 	 entry->remove();
diff --git a/src/glsl/opt_dead_code_local.cpp b/src/glsl/opt_dead_code_local.cpp
index 66522b9..e7d46ed 100644
--- a/src/glsl/opt_dead_code_local.cpp
+++ b/src/glsl/opt_dead_code_local.cpp
@@ -70,8 +70,8 @@ public:
 
    void kill_channels(ir_variable *const var, int used)
    {
-      foreach_iter(exec_list_iterator, iter, *this->assignments) {
-	 assignment_entry *entry = (assignment_entry *)iter.get();
+      foreach_list_safe(n, this->assignments) {
+	 assignment_entry *entry = (assignment_entry *) n;
 
 	 if (entry->lhs == var) {
 	    if (var->type->is_scalar() || var->type->is_vector()) {
@@ -119,8 +119,8 @@ public:
       /* For the purpose of dead code elimination, emitting a vertex counts as
        * "reading" all of the currently assigned output variables.
        */
-      foreach_iter(exec_list_iterator, iter, *this->assignments) {
-         assignment_entry *entry = (assignment_entry *)iter.get();
+      foreach_list_safe(n, this->assignments) {
+         assignment_entry *entry = (assignment_entry *) n;
          if (entry->lhs->data.mode == ir_var_shader_out) {
             if (debug)
                printf("kill %s\n", entry->lhs->name);
@@ -196,8 +196,8 @@ 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_iter(exec_list_iterator, iter, *assignments) {
-	    assignment_entry *entry = (assignment_entry *)iter.get();
+	 foreach_list_safe(n, assignments) {
+	    assignment_entry *entry = (assignment_entry *) n;
 
 	    if (entry->lhs != var)
 	       continue;
@@ -258,8 +258,8 @@ process_assignment(void *ctx, ir_assignment *ir, exec_list *assignments)
 	  */
 	 if (debug)
 	    printf("looking for %s to remove\n", var->name);
-	 foreach_iter(exec_list_iterator, iter, *assignments) {
-	    assignment_entry *entry = (assignment_entry *)iter.get();
+	 foreach_list_safe(n, assignments) {
+	    assignment_entry *entry = (assignment_entry *) n;
 
 	    if (entry->lhs == var) {
 	       if (debug)
diff --git a/src/glsl/opt_dead_functions.cpp b/src/glsl/opt_dead_functions.cpp
index 2896072..8bb278e 100644
--- a/src/glsl/opt_dead_functions.cpp
+++ b/src/glsl/opt_dead_functions.cpp
@@ -123,8 +123,8 @@ do_dead_functions(exec_list *instructions)
     * the unused ones, and remove function definitions that have no more
     * signatures.
     */
-    foreach_iter(exec_list_iterator, iter, v.signature_list) {
-      signature_entry *entry = (signature_entry *)iter.get();
+    foreach_list_safe(n, &v.signature_list) {
+      signature_entry *entry = (signature_entry *) n;
 
       if (!entry->used) {
 	 entry->signature->remove();
@@ -137,8 +137,8 @@ do_dead_functions(exec_list *instructions)
    /* We don't just do this above when we nuked a signature because of
     * const pointers.
     */
-   foreach_iter(exec_list_iterator, iter, *instructions) {
-      ir_instruction *ir = (ir_instruction *)iter.get();
+   foreach_list_safe(n, instructions) {
+      ir_instruction *ir = (ir_instruction *) n;
       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 95c3f70..2ae18c1 100644
--- a/src/glsl/opt_function_inlining.cpp
+++ b/src/glsl/opt_function_inlining.cpp
@@ -349,8 +349,8 @@ ir_variable_replacement_visitor::visit_leave(ir_dereference_record *ir)
 ir_visitor_status
 ir_variable_replacement_visitor::visit_leave(ir_call *ir)
 {
-   foreach_iter(exec_list_iterator, iter, *ir) {
-      ir_rvalue *param = (ir_rvalue *)iter.get();
+   foreach_list_safe(n, &ir->actual_parameters) {
+      ir_rvalue *param = (ir_rvalue *) n;
       ir_rvalue *new_param = param;
       replace_rvalue(&new_param);
 
diff --git a/src/glsl/opt_if_simplification.cpp b/src/glsl/opt_if_simplification.cpp
index db59b13..2bec825 100644
--- a/src/glsl/opt_if_simplification.cpp
+++ b/src/glsl/opt_if_simplification.cpp
@@ -90,13 +90,13 @@ ir_if_simplification_visitor::visit_leave(ir_if *ir)
        * that matters out.
        */
       if (condition_constant->value.b[0]) {
-	 foreach_iter(exec_list_iterator, then_iter, ir->then_instructions) {
-	    ir_instruction *then_ir = (ir_instruction *)then_iter.get();
+	 foreach_list_safe(n, &ir->then_instructions) {
+	    ir_instruction *then_ir = (ir_instruction *) n;
 	    ir->insert_before(then_ir);
 	 }
       } else {
-	 foreach_iter(exec_list_iterator, else_iter, ir->else_instructions) {
-	    ir_instruction *else_ir = (ir_instruction *)else_iter.get();
+	 foreach_list_safe(n, &ir->else_instructions) {
+	    ir_instruction *else_ir = (ir_instruction *) n;
 	    ir->insert_before(else_ir);
 	 }
       }
diff --git a/src/glsl/opt_structure_splitting.cpp b/src/glsl/opt_structure_splitting.cpp
index b668dc2..1ec537b 100644
--- a/src/glsl/opt_structure_splitting.cpp
+++ b/src/glsl/opt_structure_splitting.cpp
@@ -315,8 +315,8 @@ do_structure_splitting(exec_list *instructions)
    visit_list_elements(&refs, instructions);
 
    /* Trim out variables we can't split. */
-   foreach_iter(exec_list_iterator, iter, refs.variable_list) {
-      variable_entry *entry = (variable_entry *)iter.get();
+   foreach_list_safe(n, &refs.variable_list) {
+      variable_entry *entry = (variable_entry *) n;
 
       if (debug) {
 	 printf("structure %s@%p: decl %d, whole_access %d\n",
@@ -337,8 +337,8 @@ do_structure_splitting(exec_list *instructions)
    /* Replace the decls of the structures to be split with their split
     * components.
     */
-   foreach_iter(exec_list_iterator, iter, refs.variable_list) {
-      variable_entry *entry = (variable_entry *)iter.get();
+   foreach_list_safe(n, &refs.variable_list) {
+      variable_entry *entry = (variable_entry *) n;
       const struct glsl_type *type = entry->var->type;
 
       entry->mem_ctx = ralloc_parent(entry->var);
-- 
1.8.5.2



More information about the mesa-dev mailing list