[Mesa-dev] [PATCH 06/19] glsl: Add structures to track accessed elements of a single array

Ian Romanick idr at freedesktop.org
Fri Dec 16 04:10:18 UTC 2016


From: Ian Romanick <ian.d.romanick at intel.com>

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
Cc: mesa-stable at lists.freedesktop.org
---
 src/compiler/glsl/ir_array_refcount.cpp | 21 ++++++++++++++++++++
 src/compiler/glsl/ir_array_refcount.h   | 35 +++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+)

diff --git a/src/compiler/glsl/ir_array_refcount.cpp b/src/compiler/glsl/ir_array_refcount.cpp
index fd831a8..fa26128 100644
--- a/src/compiler/glsl/ir_array_refcount.cpp
+++ b/src/compiler/glsl/ir_array_refcount.cpp
@@ -34,6 +34,7 @@
 #include "util/hash_table.h"
 
 ir_array_refcount_visitor::ir_array_refcount_visitor()
+   : derefs(0), num_derefs(0), derefs_size(0)
 {
    this->mem_ctx = ralloc_context(NULL);
    this->ht = _mesa_hash_table_create(NULL, _mesa_hash_pointer,
@@ -84,6 +85,26 @@ ir_array_refcount_visitor::get_variable_entry(ir_variable *var)
 }
 
 
+array_deref_range *
+ir_array_refcount_visitor::get_array_deref()
+{
+   if ((num_derefs + 1) * sizeof(array_deref_range) > derefs_size) {
+      void *ptr = reralloc_size(mem_ctx, derefs, derefs_size + 4096);
+
+      if (ptr == NULL)
+         return NULL;
+
+      derefs_size += 4096;
+      derefs = (array_deref_range *)ptr;
+   }
+
+   array_deref_range *d = &derefs[num_derefs];
+   num_derefs++;
+
+   return d;
+}
+
+
 ir_visitor_status
 ir_array_refcount_visitor::visit(ir_dereference_variable *ir)
 {
diff --git a/src/compiler/glsl/ir_array_refcount.h b/src/compiler/glsl/ir_array_refcount.h
index 4296e4b..1e7f343 100644
--- a/src/compiler/glsl/ir_array_refcount.h
+++ b/src/compiler/glsl/ir_array_refcount.h
@@ -32,6 +32,23 @@
 #include "compiler/glsl_types.h"
 #include "util/bitset.h"
 
+/**
+ * Describes an access of an array element or an access of the whole array
+ */
+struct array_deref_range {
+   /**
+    * Index that was accessed.
+    *
+    * All valid array indices are less than the size of the array.  If index
+    * is equal to the size of the array, this means the entire array has been
+    * accessed (e.g., due to use of a non-constant index).
+    */
+   unsigned index;
+
+   /** Size of the array.  Used for offset calculations. */
+   unsigned size;
+};
+
 class ir_array_refcount_entry
 {
 public:
@@ -86,4 +103,22 @@ public:
    struct hash_table *ht;
 
    void *mem_ctx;
+
+private:
+   /** Get an array_deref_range element from private tracking. */
+   array_deref_range *get_array_deref();
+
+   /**
+    * \name array_deref_range tracking
+    */
+   /*@{*/
+   /** Currently allocated block of derefs. */
+   array_deref_range *derefs;
+
+   /** Number of derefs used in current processing. */
+   unsigned num_derefs;
+
+   /** Size of the derefs buffer in bytes. */
+   unsigned derefs_size;
+   /*@}*/
 };
-- 
2.7.4



More information about the mesa-dev mailing list