diff options
author | Rob Clark <[email protected]> | 2020-05-06 13:35:51 -0700 |
---|---|---|
committer | Rob Clark <[email protected]> | 2020-05-13 20:24:45 -0700 |
commit | a506d49faecf06d5cd2fd2d049319d907b273b83 (patch) | |
tree | a12a566be3b55798ec42a4ef02da120b27a66524 /src/compiler | |
parent | 3d3cfea78b799af71012dcd6b84cc38a9d172e05 (diff) |
nir: add helper to copy const_index[]
It seems less brittle to not assume they are in the same order for src
and dst instructions.
Signed-off-by: Rob Clark <[email protected]>
Reviewed-by: Kristian H. Kristensen <[email protected]>
Reviewed-by: Eric Anholt <[email protected]>
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/nir/nir.h | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index c2a0053c382..b12deb2cd78 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -1763,6 +1763,33 @@ nir_intrinsic_dest_components(nir_intrinsic_instr *intr) return intr->num_components; } +/** + * Helper to copy const_index[] from src to dst, without assuming they + * match in order. + */ +static inline void +nir_intrinsic_copy_const_indices(nir_intrinsic_instr *dst, nir_intrinsic_instr *src) +{ + if (src->intrinsic == dst->intrinsic) { + memcpy(dst->const_index, src->const_index, sizeof(dst->const_index)); + return; + } + + const nir_intrinsic_info *src_info = &nir_intrinsic_infos[src->intrinsic]; + const nir_intrinsic_info *dst_info = &nir_intrinsic_infos[dst->intrinsic]; + + for (unsigned i = 0; i < NIR_INTRINSIC_NUM_INDEX_FLAGS; i++) { + if (src_info->index_map[i] == 0) + continue; + + /* require that dst instruction also uses the same const_index[]: */ + assert(dst_info->index_map[i] > 0); + + dst->const_index[dst_info->index_map[i] - 1] = + src->const_index[src_info->index_map[i] - 1]; + } +} + #define INTRINSIC_IDX_ACCESSORS(name, flag, type) \ static inline type \ nir_intrinsic_##name(const nir_intrinsic_instr *instr) \ |