--- /dev/null
+/**************************************************************************
+ *
+ * Copyright 2015 VMware, Inc.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#ifndef _C99_ALLOCA_H_
+#define _C99_ALLOCA_H_
+
+
+#if defined(_MSC_VER)
+
+# include <malloc.h>
+
+# define alloca _alloca
+
+#else /* !defined(_MSC_VER) */
+
+# include <alloca.h>
+
+#endif /* !defined(_MSC_VER) */
+
+
+#endif
*/
#include "nir.h"
+#include "c99_alloca.h"
/*
* This file implements an out-of-SSA pass as described in "Revisiting
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);
}
/* 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:
}
/* 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
#include "nir.h"
#include "nir_worklist.h"
+#include "c99_alloca.h"
/*
* Basic liveness analysis. This works only in SSA form.
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)
#include "nir.h"
+#include "c99_alloca.h"
+
+
struct deref_node {
struct deref_node *parent;
const struct glsl_type *type;
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
* 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;