Mesa (master): nir: Use a switch in build_deref_offset()/deref_instr_get_const_offset()
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Thu Jul 30 16:12:08 UTC 2020
Module: Mesa
Branch: master
Commit: 6a1382399cbcdab1a3f1fcbec49ad9964961e904
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=6a1382399cbcdab1a3f1fcbec49ad9964961e904
Author: Boris Brezillon <boris.brezillon at collabora.com>
Date: Mon Jul 13 14:40:38 2020 +0200
nir: Use a switch in build_deref_offset()/deref_instr_get_const_offset()
We are about to add support for casts when calculating offset, but let's
first turn the if()/else if()/else block into a switch() statement to
ease addition of new cases.
Signed-off-by: Boris Brezillon <boris.brezillon at collabora.com>
Reviewed-by: Jason Ekstrand <jason at jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5682>
---
src/compiler/nir/nir_deref.c | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/src/compiler/nir/nir_deref.c b/src/compiler/nir/nir_deref.c
index 79ca329391b..83c401282c5 100644
--- a/src/compiler/nir/nir_deref.c
+++ b/src/compiler/nir/nir_deref.c
@@ -283,15 +283,19 @@ nir_deref_instr_get_const_offset(nir_deref_instr *deref,
unsigned offset = 0;
for (nir_deref_instr **p = &path.path[1]; *p; p++) {
- if ((*p)->deref_type == nir_deref_type_array) {
+ switch ((*p)->deref_type) {
+ case nir_deref_type_array:
offset += nir_src_as_uint((*p)->arr.index) *
type_get_array_stride((*p)->type, size_align);
- } else if ((*p)->deref_type == nir_deref_type_struct) {
+ break;
+ case nir_deref_type_struct: {
/* p starts at path[1], so this is safe */
nir_deref_instr *parent = *(p - 1);
offset += struct_type_get_field_offset(parent->type, size_align,
(*p)->strct.index);
- } else {
+ break;
+ }
+ default:
unreachable("Unsupported deref type");
}
}
@@ -312,18 +316,23 @@ nir_build_deref_offset(nir_builder *b, nir_deref_instr *deref,
nir_ssa_def *offset = nir_imm_intN_t(b, 0, deref->dest.ssa.bit_size);
for (nir_deref_instr **p = &path.path[1]; *p; p++) {
- if ((*p)->deref_type == nir_deref_type_array) {
+ switch ((*p)->deref_type) {
+ case nir_deref_type_array: {
nir_ssa_def *index = nir_ssa_for_src(b, (*p)->arr.index, 1);
int stride = type_get_array_stride((*p)->type, size_align);
offset = nir_iadd(b, offset, nir_amul_imm(b, index, stride));
- } else if ((*p)->deref_type == nir_deref_type_struct) {
+ break;
+ }
+ case nir_deref_type_struct: {
/* p starts at path[1], so this is safe */
nir_deref_instr *parent = *(p - 1);
unsigned field_offset =
struct_type_get_field_offset(parent->type, size_align,
(*p)->strct.index);
offset = nir_iadd_imm(b, offset, field_offset);
- } else {
+ break;
+ }
+ default:
unreachable("Unsupported deref type");
}
}
More information about the mesa-commit
mailing list