diff options
author | Jason Ekstrand <[email protected]> | 2015-12-14 18:56:59 -0800 |
---|---|---|
committer | Jason Ekstrand <[email protected]> | 2015-12-15 14:12:31 -0800 |
commit | d7cb1634d2819f6ac2586afe98d80f563e5db7c8 (patch) | |
tree | a7618ae4b45735c38919ee244f19a5ef76013da3 /src | |
parent | f6910f072a4117da442ca30d0358f6f79380667e (diff) |
nir/lower_system_values: Refactor and use the builder.
Now that we have a helper in the builder for system values and a helper in
core NIR to get the intrinsic opcode, there's really no point in having
things split out into a helper function. This commit "modernizes" this
pass to use helpers better and look more like newer passes.
Reviewed-by: Eric Anholt <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/glsl/nir/nir_lower_system_values.c | 60 |
1 files changed, 31 insertions, 29 deletions
diff --git a/src/glsl/nir/nir_lower_system_values.c b/src/glsl/nir/nir_lower_system_values.c index 03a98147ba9..402f98e319c 100644 --- a/src/glsl/nir/nir_lower_system_values.c +++ b/src/glsl/nir/nir_lower_system_values.c @@ -26,44 +26,43 @@ */ #include "nir.h" -#include "main/mtypes.h" +#include "nir_builder.h" + +struct lower_system_values_state { + nir_builder builder; + bool progress; +}; static bool -convert_instr(nir_intrinsic_instr *instr) +convert_block(nir_block *block, void *void_state) { - if (instr->intrinsic != nir_intrinsic_load_var) - return false; + struct lower_system_values_state *state = void_state; - nir_variable *var = instr->variables[0]->var; - if (var->data.mode != nir_var_system_value) - return false; + nir_builder *b = &state->builder; - void *mem_ctx = ralloc_parent(instr); + nir_foreach_instr_safe(block, instr) { + if (instr->type != nir_instr_type_intrinsic) + continue; - assert(instr->dest.is_ssa); + nir_intrinsic_instr *load_var = nir_instr_as_intrinsic(instr); - nir_intrinsic_op op = nir_intrinsic_from_system_value(var->data.location); - nir_intrinsic_instr *new_instr = nir_intrinsic_instr_create(mem_ctx, op); + if (load_var->intrinsic != nir_intrinsic_load_var) + continue; - nir_ssa_dest_init(&new_instr->instr, &new_instr->dest, - instr->dest.ssa.num_components, NULL); - nir_ssa_def_rewrite_uses(&instr->dest.ssa, - nir_src_for_ssa(&new_instr->dest.ssa)); + nir_variable *var = load_var->variables[0]->var; + if (var->data.mode != nir_var_system_value) + continue; - nir_instr_insert_before(&instr->instr, &new_instr->instr); - nir_instr_remove(&instr->instr); + b->cursor = nir_after_instr(&load_var->instr); - return true; -} + nir_intrinsic_op sysval_op = + nir_intrinsic_from_system_value(var->data.location); + nir_ssa_def *sysval = nir_load_system_value(b, sysval_op, 0); -static bool -convert_block(nir_block *block, void *state) -{ - bool *progress = state; + nir_ssa_def_rewrite_uses(&load_var->dest.ssa, nir_src_for_ssa(sysval)); + nir_instr_remove(&load_var->instr); - nir_foreach_instr_safe(block, instr) { - if (instr->type == nir_instr_type_intrinsic) - *progress = convert_instr(nir_instr_as_intrinsic(instr)) || *progress; + state->progress = true; } return true; @@ -72,12 +71,15 @@ convert_block(nir_block *block, void *state) static bool convert_impl(nir_function_impl *impl) { - bool progress = false; + struct lower_system_values_state state; - nir_foreach_block(impl, convert_block, &progress); + state.progress = false; + nir_builder_init(&state.builder, impl); + + nir_foreach_block(impl, convert_block, &state); nir_metadata_preserve(impl, nir_metadata_block_index | nir_metadata_dominance); - return progress; + return state.progress; } bool |