From: Matt Turner Date: Wed, 25 Jun 2014 04:58:35 +0000 (-0700) Subject: glsl: Use typed foreach_in_list_safe instead of foreach_list_safe. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c6a16f6d0e489e6d2a1a75bcf34be00e892b3120;p=mesa.git glsl: Use typed foreach_in_list_safe instead of foreach_list_safe. Reviewed-by: Ian Romanick --- diff --git a/src/glsl/ast_function.cpp b/src/glsl/ast_function.cpp index 394d6dced43..b4c4b788cc7 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 eb9fe4b97b7..dd4a46c22be 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; @@ -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); diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp index 9fb41574422..1d8bb6e7b66 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 5813315b613..b2334d2e403 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 3ca7a58871a..be5b3eaa00d 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 0370170b3bf..34cdb1c98a0 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 8bb1104961a..d588bc63ec4 100644 --- a/src/glsl/linker.cpp +++ b/src/glsl/linker.cpp @@ -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; diff --git a/src/glsl/loop_analysis.cpp b/src/glsl/loop_analysis.cpp index 0e232e7b514..21d46ebce53 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 89b4a4a297c..3232ce92aab 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 04e0d36e675..7304c51399a 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 fe6a3f208a1..0c3394a504b 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 b5bb00c3027..4d4d2f17ef6 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 7d29fbcddae..ebb076b223e 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 42bdad4eb0b..c334e127606 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 c78cf0cdc08..5c65af66b84 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 bcd79187a4d..f5f59b7d34a 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 d9bc5ed7c1b..4770fcff2ea 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 81c46d58217..5dff165215a 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 7212123a741..b84bb8e11bb 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 2abd7e42f99..5e82fe93aa7 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);