diff options
Diffstat (limited to 'ir_function_inlining.cpp')
-rw-r--r-- | ir_function_inlining.cpp | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/ir_function_inlining.cpp b/ir_function_inlining.cpp index 8a1cf4f1d2..e55780c940 100644 --- a/ir_function_inlining.cpp +++ b/ir_function_inlining.cpp @@ -91,6 +91,27 @@ do_function_inlining(exec_list *instructions) return v.progress; } +static void +replace_return_with_assignment(ir_instruction *ir, void *data) +{ + void *ctx = talloc_parent(ir); + ir_variable *retval = (ir_variable *)data; + ir_return *ret = ir->as_return(); + + if (ret) { + if (ret->value) { + ir_rvalue *lhs = new(ctx) ir_dereference_variable(retval); + ret->insert_before(new(ctx) ir_assignment(lhs, ret->value, NULL)); + ret->remove(); + } else { + /* un-valued return has to be the last return, or we shouldn't + * have reached here. (see can_inline()). + */ + assert(!ret->next->is_tail_sentinal()); + } + } +} + ir_rvalue * ir_call::generate_inline(ir_instruction *next_ir) { @@ -127,11 +148,12 @@ ir_call::generate_inline(ir_instruction *next_ir) /* Generate a new variable for the parameter. */ parameters[i] = (ir_variable *)sig_param->clone(ht); + parameters[i]->mode = ir_var_auto; next_ir->insert_before(parameters[i]); /* Move the actual param into our param variable if it's an 'in' type. */ - if (parameters[i]->mode == ir_var_in || - parameters[i]->mode == ir_var_inout) { + if (sig_param->mode == ir_var_in || + sig_param->mode == ir_var_inout) { ir_assignment *assign; assign = new(ctx) ir_assignment(new(ctx) ir_dereference_variable(parameters[i]), @@ -146,8 +168,10 @@ ir_call::generate_inline(ir_instruction *next_ir) /* Generate the inlined body of the function. */ foreach_iter(exec_list_iterator, iter, callee->body) { ir_instruction *ir = (ir_instruction *)iter.get(); + ir_instruction *new_ir = ir->clone(ht); - next_ir->insert_before(ir->clone(ht)); + next_ir->insert_before(new_ir); + visit_tree(new_ir, replace_return_with_assignment, retval); } /* Copy back the value of any 'out' parameters from the function body |