From: Rhys Perry Date: Thu, 20 Aug 2020 13:01:23 +0000 (+0100) Subject: nir: add and use nir_intrinsic_has_ helpers X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=7530f66c1625388041877fea216ee89b659efd94;p=mesa.git nir: add and use nir_intrinsic_has_ helpers Signed-off-by: Rhys Perry Reviewed-by: Alyssa Rosenzweig Reviewed-by: Rob Clark Part-of: --- diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index 57e0d9ae092..a3189f5d3b3 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -1854,6 +1854,12 @@ nir_intrinsic_set_##name(nir_intrinsic_instr *instr, type val) \ const nir_intrinsic_info *info = &nir_intrinsic_infos[instr->intrinsic]; \ assert(info->index_map[NIR_INTRINSIC_##flag] > 0); \ instr->const_index[info->index_map[NIR_INTRINSIC_##flag] - 1] = val; \ +} \ +static inline bool \ +nir_intrinsic_has_##name(nir_intrinsic_instr *instr) \ +{ \ + const nir_intrinsic_info *info = &nir_intrinsic_infos[instr->intrinsic]; \ + return info->index_map[NIR_INTRINSIC_##flag] > 0; \ } INTRINSIC_IDX_ACCESSORS(write_mask, WRMASK, unsigned) diff --git a/src/compiler/nir/nir_lower_io.c b/src/compiler/nir/nir_lower_io.c index 18ef614123d..2e17ad70b36 100644 --- a/src/compiler/nir/nir_lower_io.c +++ b/src/compiler/nir/nir_lower_io.c @@ -910,7 +910,7 @@ build_explicit_io_load(nir_builder *b, nir_intrinsic_instr *intrin, load->src[1] = nir_src_for_ssa(addr_to_offset(b, addr, addr_format)); } - if (nir_intrinsic_infos[op].index_map[NIR_INTRINSIC_ACCESS] > 0) + if (nir_intrinsic_has_access(load)) nir_intrinsic_set_access(load, nir_intrinsic_access(intrin)); unsigned bit_size = intrin->dest.ssa.bit_size; @@ -1034,7 +1034,7 @@ build_explicit_io_store(nir_builder *b, nir_intrinsic_instr *intrin, nir_intrinsic_set_write_mask(store, write_mask); - if (nir_intrinsic_infos[op].index_map[NIR_INTRINSIC_ACCESS] > 0) + if (nir_intrinsic_has_access(store)) nir_intrinsic_set_access(store, nir_intrinsic_access(intrin)); /* TODO: We should try and provide a better alignment. For OpenCL, we need @@ -1107,7 +1107,7 @@ build_explicit_io_atomic(nir_builder *b, nir_intrinsic_instr *intrin, /* Global atomics don't have access flags because they assume that the * address may be non-uniform. */ - if (nir_intrinsic_infos[op].index_map[NIR_INTRINSIC_ACCESS] > 0) + if (nir_intrinsic_has_access(atomic)) nir_intrinsic_set_access(atomic, nir_intrinsic_access(intrin)); assert(intrin->dest.ssa.num_components == 1); diff --git a/src/compiler/nir/nir_lower_wrmasks.c b/src/compiler/nir/nir_lower_wrmasks.c index d8b4c2423ac..b3941ec84af 100644 --- a/src/compiler/nir/nir_lower_wrmasks.c +++ b/src/compiler/nir/nir_lower_wrmasks.c @@ -128,8 +128,8 @@ split_wrmask(nir_builder *b, nir_intrinsic_instr *intr) const int offset_units = value->bit_size / 8; - if (info->index_map[NIR_INTRINSIC_ALIGN_MUL]) { - assert(info->index_map[NIR_INTRINSIC_ALIGN_OFFSET]); + if (nir_intrinsic_has_align_mul(intr)) { + assert(nir_intrinsic_has_align_offset(intr)); unsigned align_mul = nir_intrinsic_align_mul(intr); unsigned align_off = nir_intrinsic_align_offset(intr); @@ -144,7 +144,7 @@ split_wrmask(nir_builder *b, nir_intrinsic_instr *intr) * instructions */ unsigned offset_adj = offset_units * first_component; - if (info->index_map[NIR_INTRINSIC_BASE]) { + if (nir_intrinsic_has_base(intr)) { nir_intrinsic_set_base(new_intr, nir_intrinsic_base(intr) + offset_adj); } else { @@ -196,10 +196,9 @@ nir_lower_wrmasks(nir_shader *shader, nir_instr_filter_cb cb, const void *data) continue; nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr); - const nir_intrinsic_info *info = &nir_intrinsic_infos[intr->intrinsic]; /* if no wrmask, then skip it: */ - if (!info->index_map[NIR_INTRINSIC_WRMASK]) + if (!nir_intrinsic_has_write_mask(intr)) continue; /* if wrmask is already contiguous, then nothing to do: */ diff --git a/src/compiler/nir/nir_opt_load_store_vectorize.c b/src/compiler/nir/nir_opt_load_store_vectorize.c index cf9626ff21d..0bb5a95bbe0 100644 --- a/src/compiler/nir/nir_opt_load_store_vectorize.c +++ b/src/compiler/nir/nir_opt_load_store_vectorize.c @@ -574,7 +574,7 @@ create_entry(struct vectorize_ctx *ctx, nir_ssa_def *base = entry->info->base_src >= 0 ? intrin->src[entry->info->base_src].ssa : NULL; uint64_t offset = 0; - if (nir_intrinsic_infos[intrin->intrinsic].index_map[NIR_INTRINSIC_BASE]) + if (nir_intrinsic_has_base(intrin)) offset += nir_intrinsic_base(intrin); entry->key = create_entry_key_from_offset(entry, base, 1, &offset); entry->offset = offset; @@ -586,7 +586,7 @@ create_entry(struct vectorize_ctx *ctx, if (entry->info->resource_src >= 0) entry->key->resource = intrin->src[entry->info->resource_src].ssa; - if (nir_intrinsic_infos[intrin->intrinsic].index_map[NIR_INTRINSIC_ACCESS]) + if (nir_intrinsic_has_access(intrin)) entry->access = nir_intrinsic_access(intrin); else if (entry->key->var) entry->access = entry->key->var->data.access; @@ -663,7 +663,7 @@ get_best_align(struct entry *entry) best_align = gcd(best_align, entry->key->offset_defs_mul[i]); } - if (nir_intrinsic_infos[entry->intrin->intrinsic].index_map[NIR_INTRINSIC_ALIGN_MUL]) + if (nir_intrinsic_has_align_mul(entry->intrin)) best_align = MAX2(best_align, nir_intrinsic_align(entry->intrin)); /* ensure the result is a power of two that fits in a int32_t */ @@ -766,9 +766,7 @@ static nir_deref_instr *subtract_deref(nir_builder *b, nir_deref_instr *deref, i static bool update_align(struct entry *entry) { - bool has_align_index = - nir_intrinsic_infos[entry->intrin->intrinsic].index_map[NIR_INTRINSIC_ALIGN_MUL]; - if (has_align_index) { + if (nir_intrinsic_has_align_mul(entry->intrin)) { unsigned align = get_best_align(entry); if (align != nir_intrinsic_align(entry->intrin)) { nir_intrinsic_set_align(entry->intrin, align, 0); @@ -850,10 +848,7 @@ vectorize_loads(nir_builder *b, struct vectorize_ctx *ctx, } /* update base/align */ - bool has_base_index = - nir_intrinsic_infos[first->intrin->intrinsic].index_map[NIR_INTRINSIC_BASE]; - - if (first != low && has_base_index) + if (first != low && nir_intrinsic_has_base(first->intrin)) nir_intrinsic_set_base(first->intrin, nir_intrinsic_base(low->intrin)); first->key = low->key; @@ -935,10 +930,7 @@ vectorize_stores(nir_builder *b, struct vectorize_ctx *ctx, } /* update base/align */ - bool has_base_index = - nir_intrinsic_infos[second->intrin->intrinsic].index_map[NIR_INTRINSIC_BASE]; - - if (second != low && has_base_index) + if (second != low && nir_intrinsic_has_base(second->intrin)) nir_intrinsic_set_base(second->intrin, nir_intrinsic_base(low->intrin)); second->key = low->key;