diff options
author | Kenneth Graunke <[email protected]> | 2014-01-10 16:39:17 -0800 |
---|---|---|
committer | Kenneth Graunke <[email protected]> | 2014-01-13 11:49:42 -0800 |
commit | 48d0faaa4388f411ea64fef8f4be04c22d02a4cf (patch) | |
tree | 437426abb4ce6ec3e6c67cd0758d8831f1b38dc0 /src/glsl/opt_function_inlining.cpp | |
parent | 02ff2a275892aa180c84fa2fbb5b44409218c0f3 (diff) |
glsl: Use a new foreach_two_lists macro for walking two lists at once.
When handling function calls, we often want to walk through the list of
formal parameters and list of actual parameters at the same time.
(Both are guaranteed to be the same length.)
Previously, we used a pattern of:
exec_list_iterator 1st_iter = <1st list>.iterator();
foreach_iter(exec_list_iterator, 2nd_iter, <2nd list>) {
...
1st_iter.next();
}
This was awkward, since you had to manually iterate through one of
the two lists.
This patch introduces a foreach_two_lists macro which safely walks
through two lists at the same time, so you can simply do:
foreach_two_lists(1st_node, <1st list>, 2nd_node, <2nd list>) {
...
}
v2: Rename macro from foreach_list2 to foreach_two_lists, as suggested
by Ian Romanick.
Signed-off-by: Kenneth Graunke <[email protected]>
Reviewed-by: Matt Turner <[email protected]>
Reviewed-by: Ian Romanick <[email protected]>
Diffstat (limited to 'src/glsl/opt_function_inlining.cpp')
-rw-r--r-- | src/glsl/opt_function_inlining.cpp | 35 |
1 files changed, 14 insertions, 21 deletions
diff --git a/src/glsl/opt_function_inlining.cpp b/src/glsl/opt_function_inlining.cpp index a140ed335e0..9649598dd2b 100644 --- a/src/glsl/opt_function_inlining.cpp +++ b/src/glsl/opt_function_inlining.cpp @@ -116,11 +116,10 @@ ir_call::generate_inline(ir_instruction *next_ir) * and set up the mapping of real function body variables to ours. */ i = 0; - exec_list_iterator sig_param_iter = this->callee->parameters.iterator(); - exec_list_iterator param_iter = this->actual_parameters.iterator(); - for (i = 0; i < num_parameters; i++) { - ir_variable *sig_param = (ir_variable *) sig_param_iter.get(); - ir_rvalue *param = (ir_rvalue *) param_iter.get(); + foreach_two_lists(formal_node, &this->callee->parameters, + actual_node, &this->actual_parameters) { + ir_variable *sig_param = (ir_variable *) formal_node; + ir_rvalue *param = (ir_rvalue *) actual_node; /* Generate a new variable for the parameter. */ if (sig_param->type->contains_opaque()) { @@ -154,8 +153,7 @@ ir_call::generate_inline(ir_instruction *next_ir) next_ir->insert_before(assign); } - sig_param_iter.next(); - param_iter.next(); + ++i; } exec_list new_instructions; @@ -172,11 +170,10 @@ ir_call::generate_inline(ir_instruction *next_ir) /* If any opaque types were passed in, replace any deref of the * opaque variable with a deref of the argument. */ - param_iter = this->actual_parameters.iterator(); - sig_param_iter = this->callee->parameters.iterator(); - for (i = 0; i < num_parameters; i++) { - ir_rvalue *const param = (ir_rvalue *) param_iter.get(); - ir_variable *sig_param = (ir_variable *) sig_param_iter.get(); + foreach_two_lists(formal_node, &this->callee->parameters, + actual_node, &this->actual_parameters) { + ir_rvalue *const param = (ir_rvalue *) actual_node; + ir_variable *sig_param = (ir_variable *) formal_node; if (sig_param->type->contains_opaque()) { ir_dereference *deref = param->as_dereference(); @@ -184,8 +181,6 @@ ir_call::generate_inline(ir_instruction *next_ir) assert(deref); do_variable_replacement(&new_instructions, sig_param, deref); } - param_iter.next(); - sig_param_iter.next(); } /* Now push those new instructions in. */ @@ -195,11 +190,10 @@ ir_call::generate_inline(ir_instruction *next_ir) * variables to our own. */ i = 0; - param_iter = this->actual_parameters.iterator(); - sig_param_iter = this->callee->parameters.iterator(); - for (i = 0; i < num_parameters; i++) { - ir_rvalue *const param = (ir_rvalue *) param_iter.get(); - const ir_variable *const sig_param = (ir_variable *) sig_param_iter.get(); + foreach_two_lists(formal_node, &this->callee->parameters, + actual_node, &this->actual_parameters) { + ir_rvalue *const param = (ir_rvalue *) actual_node; + const ir_variable *const sig_param = (ir_variable *) formal_node; /* Move our param variable into the actual param if it's an 'out' type. */ if (parameters[i] && (sig_param->data.mode == ir_var_function_out || @@ -212,8 +206,7 @@ ir_call::generate_inline(ir_instruction *next_ir) next_ir->insert_before(assign); } - param_iter.next(); - sig_param_iter.next(); + ++i; } delete [] parameters; |