From 1e5ef4c60c69b55ff4284cb1514936fc88bb4cd6 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Mon, 1 Mar 2021 15:04:25 -0800 Subject: [PATCH] nir: Add a nir_src_is_undef() helper, like nir_src_is_const(). Reviewed-by: Jason Ekstrand Part-of: --- src/compiler/nir/nir.h | 7 +++++++ src/compiler/nir/nir_divergence_analysis.c | 2 +- src/compiler/nir/nir_gather_ssa_types.c | 3 +-- src/compiler/nir/nir_liveness.c | 2 +- src/compiler/nir/nir_opt_remove_phis.c | 2 +- src/intel/compiler/brw_fs_nir.cpp | 2 +- 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index ed7e8f7..9622085 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -971,6 +971,13 @@ nir_src_is_const(nir_src src) } static inline bool +nir_src_is_undef(nir_src src) +{ + return src.is_ssa && + src.ssa->parent_instr->type == nir_instr_type_ssa_undef; +} + +static inline bool nir_src_is_divergent(nir_src src) { return src.is_ssa ? src.ssa->divergent : src.reg.reg->divergent; diff --git a/src/compiler/nir/nir_divergence_analysis.c b/src/compiler/nir/nir_divergence_analysis.c index 7c0fc12..fa9cf81 100644 --- a/src/compiler/nir/nir_divergence_analysis.c +++ b/src/compiler/nir/nir_divergence_analysis.c @@ -746,7 +746,7 @@ visit_loop_header_phi(nir_phi_instr *phi, nir_block *preheader, bool divergent_c if (src->pred == preheader) continue; /* skip undef values */ - if (src->src.ssa->parent_instr->type == nir_instr_type_ssa_undef) + if (nir_src_is_undef(src->src)) continue; /* check if all loop-carried values are from the same ssa-def */ diff --git a/src/compiler/nir/nir_gather_ssa_types.c b/src/compiler/nir/nir_gather_ssa_types.c index c7c073c..ed1ee8a 100644 --- a/src/compiler/nir/nir_gather_ssa_types.c +++ b/src/compiler/nir/nir_gather_ssa_types.c @@ -72,8 +72,7 @@ static void copy_types(nir_src src, nir_dest *dest, BITSET_WORD *float_types, BITSET_WORD *int_types, bool *progress) { - bool src_is_sink = nir_src_is_const(src) || - src.ssa->parent_instr->type == nir_instr_type_ssa_undef; + bool src_is_sink = nir_src_is_const(src) || nir_src_is_undef(src); copy_type(src.ssa->index, dest->ssa.index, src_is_sink, float_types, progress); copy_type(src.ssa->index, dest->ssa.index, src_is_sink, int_types, progress); } diff --git a/src/compiler/nir/nir_liveness.c b/src/compiler/nir/nir_liveness.c index c748db6..941ed1c 100644 --- a/src/compiler/nir/nir_liveness.c +++ b/src/compiler/nir/nir_liveness.c @@ -77,7 +77,7 @@ set_src_live(nir_src *src, void *void_live) if (!src->is_ssa) return true; - if (src->ssa->parent_instr->type == nir_instr_type_ssa_undef) + if (nir_src_is_undef(*src)) return true; /* undefined variables are never live */ BITSET_SET(live, src->ssa->index); diff --git a/src/compiler/nir/nir_opt_remove_phis.c b/src/compiler/nir/nir_opt_remove_phis.c index db58c61..97cdcfe 100644 --- a/src/compiler/nir/nir_opt_remove_phis.c +++ b/src/compiler/nir/nir_opt_remove_phis.c @@ -98,7 +98,7 @@ remove_phis_block(nir_block *block, nir_builder *b) if (def == NULL) { def = src->src.ssa; mov = get_parent_mov(def); - } else if (src->src.ssa->parent_instr->type == nir_instr_type_ssa_undef && + } else if (nir_src_is_undef(src->src) && nir_block_dominates(def->parent_instr->block, src->pred)) { /* Ignore this undef source. */ } else { diff --git a/src/intel/compiler/brw_fs_nir.cpp b/src/intel/compiler/brw_fs_nir.cpp index 91a92d4..05ab5a6 100644 --- a/src/intel/compiler/brw_fs_nir.cpp +++ b/src/intel/compiler/brw_fs_nir.cpp @@ -1918,7 +1918,7 @@ fs_visitor::get_nir_src(const nir_src &src) { fs_reg reg; if (src.is_ssa) { - if (src.ssa->parent_instr->type == nir_instr_type_ssa_undef) { + if (nir_src_is_undef(src)) { const brw_reg_type reg_type = brw_reg_type_from_bit_size(src.ssa->bit_size, BRW_REGISTER_TYPE_D); reg = bld.vgrf(reg_type, src.ssa->num_components); -- 2.7.4