aboutsummaryrefslogtreecommitdiffstats
path: root/src/glsl
diff options
context:
space:
mode:
authorJose Fonseca <[email protected]>2015-02-26 16:37:48 +0000
committerJose Fonseca <[email protected]>2015-02-27 14:30:36 +0000
commitf320ecf218ab24ef4883f918a9007b2a6cfdac5e (patch)
tree2548b93631d89800ac4bd7172a45d04d5b8cebff /src/glsl
parent84a1e3d61e6df449571e41426ec64b115fedc7c3 (diff)
nir: Use alloca instead of variable length arrays.
This is to enable the code to build with -Werror=vla in the short term, and enable the code to build with MSVC2013 soon after. Reviewed-by: Brian Paul <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
Diffstat (limited to 'src/glsl')
-rw-r--r--src/glsl/nir/nir_from_ssa.c19
-rw-r--r--src/glsl/nir/nir_live_variables.c5
-rw-r--r--src/glsl/nir/nir_lower_vars_to_ssa.c13
3 files changed, 21 insertions, 16 deletions
diff --git a/src/glsl/nir/nir_from_ssa.c b/src/glsl/nir/nir_from_ssa.c
index c695c951f31..66339f3b483 100644
--- a/src/glsl/nir/nir_from_ssa.c
+++ b/src/glsl/nir/nir_from_ssa.c
@@ -26,6 +26,7 @@
*/
#include "nir.h"
+#include "c99_alloca.h"
/*
* This file implements an out-of-SSA pass as described in "Revisiting
@@ -181,7 +182,7 @@ merge_merge_sets(merge_set *a, merge_set *b)
static bool
merge_sets_interfere(merge_set *a, merge_set *b)
{
- merge_node *dom[a->size + b->size];
+ merge_node **dom = alloca((a->size + b->size) * sizeof *dom);
int dom_idx = -1;
struct exec_node *an = exec_list_get_head(&a->nodes);
@@ -673,21 +674,21 @@ resolve_parallel_copy(nir_parallel_copy_instr *pcopy,
}
/* The register/source corresponding to the given index */
- nir_src values[num_copies * 2];
- memset(values, 0, sizeof values);
+ nir_src *values = alloca(num_copies * 2 * sizeof *values);
+ memset(values, 0, num_copies * 2 * sizeof *values);
/* The current location of a given piece of data */
- int loc[num_copies * 2];
+ int *loc = alloca(num_copies * 2 * sizeof *loc);
/* The piece of data that the given piece of data is to be copied from */
- int pred[num_copies * 2];
+ int *pred = alloca(num_copies * 2 * sizeof *pred);
/* Initialize loc and pred. We will use -1 for "null" */
- memset(loc, -1, sizeof loc);
- memset(pred, -1, sizeof pred);
+ memset(loc, -1, num_copies * 2 * sizeof *loc);
+ memset(pred, -1, num_copies * 2 * sizeof *pred);
/* The destinations we have yet to properly fill */
- int to_do[num_copies * 2];
+ int *to_do = alloca(num_copies * 2 * sizeof *to_do);
int to_do_idx = -1;
/* Now we set everything up:
@@ -737,7 +738,7 @@ resolve_parallel_copy(nir_parallel_copy_instr *pcopy,
}
/* Currently empty destinations we can go ahead and fill */
- int ready[num_copies * 2];
+ int *ready = alloca(num_copies * 2 * sizeof *ready);
int ready_idx = -1;
/* Mark the ones that are ready for copying. We know an index is a
diff --git a/src/glsl/nir/nir_live_variables.c b/src/glsl/nir/nir_live_variables.c
index 7402dc0877e..b57ca3a2780 100644
--- a/src/glsl/nir/nir_live_variables.c
+++ b/src/glsl/nir/nir_live_variables.c
@@ -26,6 +26,7 @@
#include "nir.h"
#include "nir_worklist.h"
+#include "c99_alloca.h"
/*
* Basic liveness analysis. This works only in SSA form.
@@ -130,8 +131,8 @@ static bool
propagate_across_edge(nir_block *pred, nir_block *succ,
struct live_variables_state *state)
{
- BITSET_WORD live[state->bitset_words];
- memcpy(live, succ->live_in, sizeof live);
+ BITSET_WORD *live = alloca(state->bitset_words * sizeof *live);
+ memcpy(live, succ->live_in, state->bitset_words * sizeof *live);
nir_foreach_instr(succ, instr) {
if (instr->type != nir_instr_type_phi)
diff --git a/src/glsl/nir/nir_lower_vars_to_ssa.c b/src/glsl/nir/nir_lower_vars_to_ssa.c
index 8af75302986..f54d1b7e70e 100644
--- a/src/glsl/nir/nir_lower_vars_to_ssa.c
+++ b/src/glsl/nir/nir_lower_vars_to_ssa.c
@@ -27,6 +27,9 @@
#include "nir.h"
+#include "c99_alloca.h"
+
+
struct deref_node {
struct deref_node *parent;
const struct glsl_type *type;
@@ -899,8 +902,8 @@ rename_variables_block(nir_block *block, struct lower_variables_state *state)
static void
insert_phi_nodes(struct lower_variables_state *state)
{
- unsigned work[state->impl->num_blocks];
- unsigned has_already[state->impl->num_blocks];
+ unsigned *work = alloca(state->impl->num_blocks * sizeof *work);
+ unsigned *has_already = alloca(state->impl->num_blocks * sizeof *has_already);
/*
* Since the work flags already prevent us from inserting a node that has
@@ -910,10 +913,10 @@ insert_phi_nodes(struct lower_variables_state *state)
* function. So all we need to handle W is an array and a pointer to the
* next element to be inserted and the next element to be removed.
*/
- nir_block *W[state->impl->num_blocks];
+ nir_block **W = alloca(state->impl->num_blocks * sizeof *W);
- memset(work, 0, sizeof work);
- memset(has_already, 0, sizeof has_already);
+ memset(work, 0, state->impl->num_blocks * sizeof *work);
+ memset(has_already, 0, state->impl->num_blocks * sizeof *has_already);
unsigned w_start, w_end;
unsigned iter_count = 0;