glsl: Convert piles of foreach_iter to foreach_list_safe.
authorKenneth Graunke <kenneth@whitecape.org>
Fri, 22 Nov 2013 10:10:15 +0000 (02:10 -0800)
committerKenneth Graunke <kenneth@whitecape.org>
Mon, 13 Jan 2014 19:38:19 +0000 (11:38 -0800)
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@whitecape.org>
Reviewed-by: Matt Turner <mattst88@gmail.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
12 files changed:
src/glsl/ir.cpp
src/glsl/ir_rvalue_visitor.cpp
src/glsl/lower_vec_index_to_cond_assign.cpp
src/glsl/lower_vec_index_to_swizzle.cpp
src/glsl/opt_array_splitting.cpp
src/glsl/opt_constant_propagation.cpp
src/glsl/opt_copy_propagation.cpp
src/glsl/opt_dead_code_local.cpp
src/glsl/opt_dead_functions.cpp
src/glsl/opt_function_inlining.cpp
src/glsl/opt_if_simplification.cpp
src/glsl/opt_structure_splitting.cpp

index 720fcdcd883eddd5d0b61f76482805dd9fcf17ff..6ffa987f6d20dbd821c424d41aacfb71b3d82582 100644 (file)
@@ -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);
    }
 }
 
index 9d8ccd94a06bacce373290a2e404d54398adadbb..fcbe9448d9c313d77cfb23be7d06e48d4328c066 100644 (file)
@@ -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);
 
index 8080006c1d0071496e6986c8e908374132dd36bd..fe6a3f208a165aca748565e180fa20a737bc18d0 100644 (file)
@@ -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) {
index 46985791ef63f8c37c9f9f6ebf41e09a8ff9a702..b5bb00c3027b8d40d59f112d9468a446460b4899 100644 (file)
@@ -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) {
index 70660eb0d9ddb42f8428b4e4b008dd525ce658a2..f37d0902201e4a2a49bd250423c5ad22e8d6aca2 100644 (file)
@@ -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",
index 6fe16a93f02b07ca8d2829018987b97c69066ae6..a2d1b0f7582ada3163ae6135be716f67c3aba0b8 100644 (file)
@@ -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;
index 887fdebda079804660f777faf6d3ee9a51061301..3a73342683b06151b2b8be0488424af594c64076 100644 (file)
@@ -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();
index 66522b9c766e4cc423f964153aba50fe87b7a608..e7d46edbe3e9c68e8320b223a6242687a43c6437 100644 (file)
@@ -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)
index 2896072abca7c6d2abe52b41858a9dc1c8bcfa34..8bb278e4537d06158aba42121b2c37d5cc5127e5 100644 (file)
@@ -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()) {
index 95c3f70d4521575b6b559420bed4b283eb021304..2ae18c14f537b44600b40e04da12e8a53d2e024a 100644 (file)
@@ -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);
 
index db59b131dbc219ad3c61d45fc1e8a81ed2a713bf..2bec8252ea510d67077a8caeb803a3c2d34929f4 100644 (file)
@@ -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);
         }
       }
index b668dc21c040706ff2866558384f9c1783d02387..1ec537b132bd28d1eff9a2fea85d1341ee505bb6 100644 (file)
@@ -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);