diff options
author | Jason Ekstrand <[email protected]> | 2015-10-09 08:13:43 -0700 |
---|---|---|
committer | Kenneth Graunke <[email protected]> | 2016-04-26 19:55:04 -0700 |
commit | d800b7daa5440f6b49b5e0ae6e404d240c6a4ddc (patch) | |
tree | a92cbc618f16c62fff1bf65c75c41f1b6e126af7 /src | |
parent | acc2f1fe361af87ce4d50b7e2b58e0da093477e1 (diff) |
nir: Add a helper for figuring out what channels of an SSA def are read
Reviewed-by: Kenneth Graunke <[email protected]>
Reviewed-by: Topi Pohjolainen <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/nir/nir.c | 25 | ||||
-rw-r--r-- | src/compiler/nir/nir.h | 2 |
2 files changed, 27 insertions, 0 deletions
diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c index 5cafc41ec81..92bbc378ec1 100644 --- a/src/compiler/nir/nir.c +++ b/src/compiler/nir/nir.c @@ -1476,6 +1476,31 @@ nir_ssa_def_rewrite_uses_after(nir_ssa_def *def, nir_src new_src, nir_if_rewrite_condition(use_src->parent_if, new_src); } +uint8_t +nir_ssa_def_components_read(nir_ssa_def *def) +{ + uint8_t read_mask = 0; + nir_foreach_use(def, use) { + if (use->parent_instr->type == nir_instr_type_alu) { + nir_alu_instr *alu = nir_instr_as_alu(use->parent_instr); + nir_alu_src *alu_src = exec_node_data(nir_alu_src, use, src); + int src_idx = alu_src - &alu->src[0]; + assert(src_idx >= 0 && src_idx < nir_op_infos[alu->op].num_inputs); + + for (unsigned c = 0; c < 4; c++) { + if (!nir_alu_instr_channel_used(alu, src_idx, c)) + continue; + + read_mask |= (1 << alu_src->swizzle[c]); + } + } else { + return (1 << def->num_components) - 1; + } + } + + return read_mask; +} + static bool foreach_cf_node(nir_cf_node *node, nir_foreach_block_cb cb, bool reverse, void *state); diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index 4693ab58a59..a55e6821cbe 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -2119,6 +2119,8 @@ void nir_ssa_def_rewrite_uses(nir_ssa_def *def, nir_src new_src); void nir_ssa_def_rewrite_uses_after(nir_ssa_def *def, nir_src new_src, nir_instr *after_me); +uint8_t nir_ssa_def_components_read(nir_ssa_def *def); + /* visits basic blocks in source-code order */ typedef bool (*nir_foreach_block_cb)(nir_block *block, void *state); bool nir_foreach_block_call(nir_function_impl *impl, nir_foreach_block_cb cb, |