Mesa (master): nir/deref: add helpers to lazily create paths

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Nov 20 14:40:18 UTC 2020


Module: Mesa
Branch: master
Commit: abc3225927453786de240b4493507318e8ecfa4f
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=abc3225927453786de240b4493507318e8ecfa4f

Author: Rhys Perry <pendingchaos02 at gmail.com>
Date:   Tue Nov 10 10:13:04 2020 +0000

nir/deref: add helpers to lazily create paths

Signed-off-by: Rhys Perry <pendingchaos02 at gmail.com>
Reviewed-by: Daniel Schürmann <daniel at schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7511>

---

 src/compiler/nir/nir_deref.c | 20 ++++++++++++++++++++
 src/compiler/nir/nir_deref.h | 10 ++++++++++
 2 files changed, 30 insertions(+)

diff --git a/src/compiler/nir/nir_deref.c b/src/compiler/nir/nir_deref.c
index a5282ce128f..4735175b786 100644
--- a/src/compiler/nir/nir_deref.c
+++ b/src/compiler/nir/nir_deref.c
@@ -641,6 +641,26 @@ nir_compare_derefs(nir_deref_instr *a, nir_deref_instr *b)
    return result;
 }
 
+nir_deref_path *nir_get_deref_path(void *mem_ctx, nir_deref_and_path *deref)
+{
+   if (!deref->_path) {
+      deref->_path = ralloc(mem_ctx, nir_deref_path);
+      nir_deref_path_init(deref->_path, deref->instr, mem_ctx);
+   }
+   return deref->_path;
+}
+
+nir_deref_compare_result nir_compare_derefs_and_paths(void *mem_ctx,
+                                                      nir_deref_and_path *a,
+                                                      nir_deref_and_path *b)
+{
+   if (a->instr == b->instr) /* nir_compare_derefs has a fast path if a == b */
+      return nir_compare_derefs(a->instr, b->instr);
+
+   return nir_compare_deref_paths(nir_get_deref_path(mem_ctx, a),
+                                  nir_get_deref_path(mem_ctx, b));
+}
+
 struct rematerialize_deref_state {
    bool progress;
    nir_builder builder;
diff --git a/src/compiler/nir/nir_deref.h b/src/compiler/nir/nir_deref.h
index 20d40377e6e..a7ada23f006 100644
--- a/src/compiler/nir/nir_deref.h
+++ b/src/compiler/nir/nir_deref.h
@@ -44,6 +44,11 @@ typedef struct {
    nir_deref_instr **path;
 } nir_deref_path;
 
+typedef struct {
+   nir_deref_instr *instr;
+   nir_deref_path *_path;
+} nir_deref_and_path;
+
 void nir_deref_path_init(nir_deref_path *path,
                          nir_deref_instr *deref, void *mem_ctx);
 void nir_deref_path_finish(nir_deref_path *path);
@@ -54,6 +59,8 @@ unsigned nir_deref_instr_get_const_offset(nir_deref_instr *deref,
 nir_ssa_def *nir_build_deref_offset(nir_builder *b, nir_deref_instr *deref,
                                     glsl_type_size_align_func size_align);
 
+nir_deref_path *nir_get_deref_path(void *mem_ctx, nir_deref_and_path *deref);
+
 typedef enum {
    nir_derefs_do_not_alias     = 0,
    nir_derefs_equal_bit        = (1 << 0),
@@ -64,6 +71,9 @@ typedef enum {
 
 nir_deref_compare_result nir_compare_deref_paths(nir_deref_path *a_path, nir_deref_path *b_path);
 nir_deref_compare_result nir_compare_derefs(nir_deref_instr *a, nir_deref_instr *b);
+nir_deref_compare_result nir_compare_derefs_and_paths(void *mem_ctx,
+                                                      nir_deref_and_path *a,
+                                                      nir_deref_and_path *b);
 
 #ifdef __cplusplus
 } /* extern "C" */



More information about the mesa-commit mailing list