diff options
author | Connor Abbott <[email protected]> | 2016-04-08 15:24:36 -0400 |
---|---|---|
committer | Jason Ekstrand <[email protected]> | 2016-04-28 15:52:17 -0700 |
commit | 34af78edb38bc75427f4b88ad5689f2be55afe6b (patch) | |
tree | 7a77b649110fbc89248b205581954926a6e168fa | |
parent | b23e59e1726d75790d0e2f8c8bab54446a50a6bf (diff) |
nir/inline_functions: fixup for new foreach_block()
Reviewed-by: Jason Ekstrand <[email protected]>
-rw-r--r-- | src/compiler/nir/nir_inline_functions.c | 53 |
1 files changed, 23 insertions, 30 deletions
diff --git a/src/compiler/nir/nir_inline_functions.c b/src/compiler/nir/nir_inline_functions.c index 30221326dfe..a639814140c 100644 --- a/src/compiler/nir/nir_inline_functions.c +++ b/src/compiler/nir/nir_inline_functions.c @@ -25,19 +25,11 @@ #include "nir_builder.h" #include "nir_control_flow.h" -struct inline_functions_state { - struct set *inlined; - nir_builder builder; - bool progress; -}; - static bool inline_function_impl(nir_function_impl *impl, struct set *inlined); static bool -rewrite_param_derefs_block(nir_block *block, void *void_state) +rewrite_param_derefs_block(nir_block *block, nir_call_instr *call) { - nir_call_instr *call = void_state; - nir_foreach_instr_safe(block, instr) { if (instr->type != nir_instr_type_intrinsic) continue; @@ -95,10 +87,8 @@ lower_param_to_local(nir_variable *param, nir_function_impl *impl, bool write) } static bool -lower_params_to_locals_block(nir_block *block, void *void_state) +lower_params_to_locals_block(nir_block *block, nir_function_impl *impl) { - nir_function_impl *impl = void_state; - nir_foreach_instr_safe(block, instr) { if (instr->type != nir_instr_type_intrinsic) continue; @@ -134,12 +124,10 @@ lower_params_to_locals_block(nir_block *block, void *void_state) } static bool -inline_functions_block(nir_block *block, void *void_state) +inline_functions_block(nir_block *block, nir_builder *b, + struct set *inlined) { - struct inline_functions_state *state = void_state; - - nir_builder *b = &state->builder; - + bool progress = false; /* This is tricky. We're iterating over instructions in a block but, as * we go, the block and its instruction list are being split into * pieces. However, this *should* be safe since foreach_safe always @@ -151,12 +139,12 @@ inline_functions_block(nir_block *block, void *void_state) if (instr->type != nir_instr_type_call) continue; - state->progress = true; + progress = true; nir_call_instr *call = nir_instr_as_call(instr); assert(call->callee->impl); - inline_function_impl(call->callee->impl, state->inlined); + inline_function_impl(call->callee->impl, inlined); nir_function_impl *callee_copy = nir_function_impl_clone(call->callee->impl); @@ -181,7 +169,10 @@ inline_functions_block(nir_block *block, void *void_state) */ /* Figure out when we need to lower to a shadow local */ - nir_foreach_block_call(callee_copy, lower_params_to_locals_block, callee_copy); + nir_foreach_block(block, callee_copy) { + lower_params_to_locals_block(block, callee_copy); + } + for (unsigned i = 0; i < callee_copy->num_params; i++) { nir_variable *param = callee_copy->params[i]; @@ -192,7 +183,9 @@ inline_functions_block(nir_block *block, void *void_state) } } - nir_foreach_block_call(callee_copy, rewrite_param_derefs_block, call); + nir_foreach_block(block, callee_copy) { + rewrite_param_derefs_block(block, call); + } /* Pluck the body out of the function and place it here */ nir_cf_list body; @@ -222,7 +215,7 @@ inline_functions_block(nir_block *block, void *void_state) nir_instr_remove(&call->instr); } - return true; + return progress; } static bool @@ -231,15 +224,15 @@ inline_function_impl(nir_function_impl *impl, struct set *inlined) if (_mesa_set_search(inlined, impl)) return false; /* Already inlined */ - struct inline_functions_state state; - - state.inlined = inlined; - state.progress = false; - nir_builder_init(&state.builder, impl); + nir_builder b; + nir_builder_init(&b, impl); - nir_foreach_block_call(impl, inline_functions_block, &state); + bool progress = false; + nir_foreach_block_safe(block, impl) { + progress |= inline_functions_block(block, &b, inlined); + } - if (state.progress) { + if (progress) { /* SSA and register indices are completely messed up now */ nir_index_ssa_defs(impl); nir_index_local_regs(impl); @@ -249,7 +242,7 @@ inline_function_impl(nir_function_impl *impl, struct set *inlined) _mesa_set_add(inlined, impl); - return state.progress; + return progress; } bool |