glsl: Use typed foreach_in_list_safe instead of foreach_list_safe.
authorMatt Turner <mattst88@gmail.com>
Wed, 25 Jun 2014 04:58:35 +0000 (21:58 -0700)
committerMatt Turner <mattst88@gmail.com>
Tue, 1 Jul 2014 15:55:51 +0000 (08:55 -0700)
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
20 files changed:
src/glsl/ast_function.cpp
src/glsl/ast_to_hir.cpp
src/glsl/ir.cpp
src/glsl/ir_function_detect_recursion.cpp
src/glsl/ir_hv_accept.cpp
src/glsl/ir_rvalue_visitor.cpp
src/glsl/linker.cpp
src/glsl/loop_analysis.cpp
src/glsl/lower_if_to_cond_assign.cpp
src/glsl/lower_named_interface_blocks.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_copy_propagation_elements.cpp
src/glsl/opt_dead_code_local.cpp
src/glsl/opt_dead_functions.cpp
src/glsl/opt_function_inlining.cpp
src/glsl/opt_structure_splitting.cpp

index 394d6dced4334cb3add91ac845d38655447c4d44..b4c4b788cc747e43f176aba23327307cd2c2b9ec 100644 (file)
@@ -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,
index eb9fe4b97b712736fa258a09c95ef3d48c572b3d..dd4a46c22be1b9e8eec41ffff3a858e97281e7df 100644 (file)
@@ -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;
@@ -5619,8 +5619,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) {
@@ -5884,8 +5884,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);
index 9fb4157442202aa420c54c8d668f2324304f638e..1d8bb6e7b66c1b5c5a9d3ec6046c7378eb847d85 100644 (file)
@@ -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);
    }
 }
 
index 5813315b613e1cb7528e67e7e674ab1e758f11f6..b2334d2e403316a3cb0c6c820bb012abfc31160b 100644 (file)
@@ -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();
    }
 }
 
index 3ca7a58871a02aaa5d0e3f4696a5aa6bb987f506..be5b3eaa00de88c88bc4858316dea42adfce42d5 100644 (file)
@@ -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);
index 0370170b3bfcfaa8bba06ac2e8bd6c2e33281dc3..34cdb1c98a02c401ab448610c0f4eab0947b6cfd 100644 (file)
@@ -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);
 
index 8bb1104961a8cff3baaefd507f60d5a2759280c4..d588bc63ec42f49efec0901f7652ebec06b35b1e 100644 (file)
@@ -1078,9 +1078,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;
 
index 0e232e7b5141f3400edddcda07c90901dd447431..21d46ebce536129198256f4520b8392f154c3fe2 100644 (file)
@@ -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
index 89b4a4a297c4475801a920fe9e552cdf290c7a01..3232ce92aab230ce9d4824dd3b3e9be96f90eebb 100644 (file)
@@ -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;
 
index 04e0d36e675b2cca038867e77df6c2450f6db455..7304c51399ae20cd78c3f8b767f94ad9489a8e65 100644 (file)
@@ -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;
 
index fe6a3f208a165aca748565e180fa20a737bc18d0..0c3394a504bcf373601e7f460513d692d8debe34 100644 (file)
@@ -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) {
index b5bb00c3027b8d40d59f112d9468a446460b4899..4d4d2f17ef69ed4eb08664f93b95ed8257e70fa7 100644 (file)
@@ -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) {
index 7d29fbcddaee6c9c5e427f8ddca010d1670517e2..ebb076b223ebe1d1cfd84a535200582760ae78de 100644 (file)
@@ -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,
index 42bdad4eb0b0b4a50fdcb9b0cf91e7d4b06002f5..c334e127606fd1a9c128430198dfbf557db07d70 100644 (file)
@@ -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)
index c78cf0cdc0895e6626948c868e4a2fa5cac3a273..5c65af66b84f6da2f581f2e5b42f137a2daa6a3c 100644 (file)
@@ -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();
       }
index bcd79187a4d9fade2fe5e30a9bc3e55f7c92bcd0..f5f59b7d34a6a7e7a0b76161f371b9a8403f6f06 100644 (file)
@@ -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) {
index d9bc5ed7c1bc266a1b8cd13161788a8a9af327b7..4770fcff2ea90bfb0684d52b8a3e74ee221043f2 100644 (file)
@@ -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);
index 81c46d58217c28cc13f21e9c440f9e7b7997bb29..5dff165215a34b3819e05804f8672a3153a48c32 100644 (file)
@@ -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()) {
index 7212123a741b1a6ee332b53cbe737ec6724759b9..b84bb8e11bb7f1e8e3c24f7b1d8575abe2ae799b 100644 (file)
@@ -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);
 
index 2abd7e42f9962c8a09fde44cbb4c95c5f4265294..5e82fe93aa7df62ad5a6d0299f1dd183234cff83 100644 (file)
@@ -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);