nir: add and use nir_intrinsic_has_ helpers
authorRhys Perry <pendingchaos02@gmail.com>
Thu, 20 Aug 2020 13:01:23 +0000 (14:01 +0100)
committerMarge Bot <eric+marge@anholt.net>
Fri, 21 Aug 2020 16:47:00 +0000 (16:47 +0000)
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Rob Clark <robdclark@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6402>

src/compiler/nir/nir.h
src/compiler/nir/nir_lower_io.c
src/compiler/nir/nir_lower_wrmasks.c
src/compiler/nir/nir_opt_load_store_vectorize.c

index 57e0d9ae0922a7e56e703f87920e6f5ed60c6f67..a3189f5d3b3f385ad98fe2407798e7fa52b60492 100644 (file)
@@ -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)
index 18ef614123d695659d03ca3e90a06e1d361c3f9f..2e17ad70b36b2464d7820d89e40387de7ab050de 100644 (file)
@@ -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);
index d8b4c2423acae17056c026f782db3856adea8053..b3941ec84afbd473f11eaed5b2f3197ef7975562 100644 (file)
@@ -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: */
index cf9626ff21d219d6be7bdf3de7c01c2660b5f5bc..0bb5a95bbe01764a0b134e7cdc481d0487f01be9 100644 (file)
@@ -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;