[Mesa-dev] [PATCH 04/14] nir: Move nir_array to util, and rename to dyn_array
Thomas Helland
thomashelland90 at gmail.com
Sun Jan 1 18:37:48 UTC 2017
------
We might want to merge u_vector and this array, or just replace this
implementation completely. Having two separate implementations, where
one of them has one sole user seems a bit wierd.
---
src/compiler/Makefile.sources | 1 -
src/compiler/spirv/vtn_cfg.c | 6 +++---
src/compiler/spirv/vtn_private.h | 4 ++--
src/util/Makefile.sources | 1 +
src/{compiler/nir/nir_array.h => util/dyn_array.h} | 18 +++++++++---------
5 files changed, 15 insertions(+), 15 deletions(-)
rename src/{compiler/nir/nir_array.h => util/dyn_array.h} (86%)
diff --git a/src/compiler/Makefile.sources b/src/compiler/Makefile.sources
index be2215cc10..9c8f802cd2 100644
--- a/src/compiler/Makefile.sources
+++ b/src/compiler/Makefile.sources
@@ -178,7 +178,6 @@ NIR_GENERATED_FILES = \
NIR_FILES = \
nir/nir.c \
nir/nir.h \
- nir/nir_array.h \
nir/nir_builder.h \
nir/nir_clone.c \
nir/nir_constant_expressions.h \
diff --git a/src/compiler/spirv/vtn_cfg.c b/src/compiler/spirv/vtn_cfg.c
index 62b9056990..14255798cb 100644
--- a/src/compiler/spirv/vtn_cfg.c
+++ b/src/compiler/spirv/vtn_cfg.c
@@ -183,7 +183,7 @@ vtn_add_case(struct vtn_builder *b, struct vtn_switch *swtch,
list_inithead(&c->body);
c->start_block = case_block;
c->fallthrough = NULL;
- nir_array_init(&c->values, b);
+ dyn_array_init(&c->values, b);
c->is_default = false;
c->visited = false;
@@ -195,7 +195,7 @@ vtn_add_case(struct vtn_builder *b, struct vtn_switch *swtch,
if (is_default) {
case_block->switch_case->is_default = true;
} else {
- nir_array_add(&case_block->switch_case->values, uint32_t, val);
+ dyn_array_add(&case_block->switch_case->values, uint32_t, val);
}
}
@@ -722,7 +722,7 @@ vtn_emit_cf_list(struct vtn_builder *b, struct list_head *cf_list,
}
nir_ssa_def *cond = NULL;
- nir_array_foreach(&cse->values, uint32_t, val) {
+ dyn_array_foreach(&cse->values, uint32_t, val) {
nir_ssa_def *is_val =
nir_ieq(&b->nb, sel, nir_imm_int(&b->nb, *val));
diff --git a/src/compiler/spirv/vtn_private.h b/src/compiler/spirv/vtn_private.h
index 9302611803..9e0a2137e2 100644
--- a/src/compiler/spirv/vtn_private.h
+++ b/src/compiler/spirv/vtn_private.h
@@ -27,7 +27,7 @@
#include "nir/nir.h"
#include "nir/nir_builder.h"
-#include "nir/nir_array.h"
+#include "util/dyn_array.h"
#include "nir_spirv.h"
#include "spirv.h"
@@ -112,7 +112,7 @@ struct vtn_case {
struct vtn_case *fallthrough;
/* The uint32_t values that map to this case */
- nir_array values;
+ dyn_array values;
/* True if this is the default case */
bool is_default;
diff --git a/src/util/Makefile.sources b/src/util/Makefile.sources
index d2ae5e734d..b24611a363 100644
--- a/src/util/Makefile.sources
+++ b/src/util/Makefile.sources
@@ -8,6 +8,7 @@ MESA_UTIL_FILES := \
debug.h \
disk_cache.c \
disk_cache.h \
+ dyn_array.h \
format_r11g11b10f.h \
format_rgb9e5.h \
format_srgb.h \
diff --git a/src/compiler/nir/nir_array.h b/src/util/dyn_array.h
similarity index 86%
rename from src/compiler/nir/nir_array.h
rename to src/util/dyn_array.h
index 1db4e8cea3..8a06990ab4 100644
--- a/src/compiler/nir/nir_array.h
+++ b/src/util/dyn_array.h
@@ -36,10 +36,10 @@ typedef struct {
size_t size;
size_t alloc;
void *data;
-} nir_array;
+} dyn_array;
static inline void
-nir_array_init(nir_array *arr, void *mem_ctx)
+dyn_array_init(dyn_array *arr, void *mem_ctx)
{
arr->mem_ctx = mem_ctx;
arr->size = 0;
@@ -48,7 +48,7 @@ nir_array_init(nir_array *arr, void *mem_ctx)
}
static inline void
-nir_array_fini(nir_array *arr)
+dyn_array_fini(dyn_array *arr)
{
if (arr->mem_ctx)
ralloc_free(arr->data);
@@ -56,18 +56,18 @@ nir_array_fini(nir_array *arr)
free(arr->data);
}
-#define NIR_ARRAY_INITIAL_SIZE 64
+#define DYN_ARRAY_INITIAL_SIZE 64
/* Increments the size of the array by the given ammount and returns a
* pointer to the beginning of the newly added space.
*/
static inline void *
-nir_array_grow(nir_array *arr, size_t additional)
+dyn_array_grow(dyn_array *arr, size_t additional)
{
size_t new_size = arr->size + additional;
if (new_size > arr->alloc) {
if (arr->alloc == 0)
- arr->alloc = NIR_ARRAY_INITIAL_SIZE;
+ arr->alloc = DYN_ARRAY_INITIAL_SIZE;
while (new_size > arr->alloc)
arr->alloc *= 2;
@@ -84,10 +84,10 @@ nir_array_grow(nir_array *arr, size_t additional)
return ptr;
}
-#define nir_array_add(arr, type, elem) \
- *(type *)nir_array_grow(arr, sizeof(type)) = (elem)
+#define dyn_array_add(arr, type, elem) \
+ *(type *)dyn_array_grow(arr, sizeof(type)) = (elem)
-#define nir_array_foreach(arr, type, elem) \
+#define dyn_array_foreach(arr, type, elem) \
for (type *elem = (type *)(arr)->data; \
elem < (type *)((char *)(arr)->data + (arr)->size); elem++)
--
2.11.0
More information about the mesa-dev
mailing list