nir: Remove a bunch of large stack arrays
authorJason Ekstrand <jason@jlekstrand.net>
Mon, 22 Jul 2019 05:51:24 +0000 (00:51 -0500)
committerJason Ekstrand <jason@jlekstrand.net>
Mon, 22 Jul 2019 21:17:18 +0000 (16:17 -0500)
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Matt Turner <mattst88@gmail.com>
src/compiler/nir/nir_liveness.c
src/compiler/nir/nir_lower_regs_to_ssa.c
src/compiler/nir/nir_lower_vars_to_ssa.c
src/compiler/nir/nir_phi_builder.c

index 03e252fbfd83950280bf2bcb1f7f142b3d988f35..16dbeb4a22302a231ba3d662a1b61ec9544b69c3 100644 (file)
@@ -46,6 +46,9 @@ struct live_ssa_defs_state {
    unsigned num_ssa_defs;
    unsigned bitset_words;
 
+   /* Used in propagate_across_edge() */
+   BITSET_WORD *tmp_live;
+
    nir_block_worklist worklist;
 };
 
@@ -121,7 +124,7 @@ static bool
 propagate_across_edge(nir_block *pred, nir_block *succ,
                       struct live_ssa_defs_state *state)
 {
-   NIR_VLA(BITSET_WORD, live, state->bitset_words);
+   BITSET_WORD *live = state->tmp_live;
    memcpy(live, succ->live_in, state->bitset_words * sizeof *live);
 
    nir_foreach_instr(instr, succ) {
@@ -176,6 +179,7 @@ nir_live_ssa_defs_impl(nir_function_impl *impl)
     * blocks to the worklist.
     */
    state.bitset_words = BITSET_WORDS(state.num_ssa_defs);
+   state.tmp_live = rzalloc_array(impl, BITSET_WORD, state.bitset_words);
    nir_foreach_block(block, impl) {
       init_liveness_block(block, &state);
    }
@@ -225,6 +229,7 @@ nir_live_ssa_defs_impl(nir_function_impl *impl)
       }
    }
 
+   ralloc_free(state.tmp_live);
    nir_block_worklist_fini(&state.worklist);
 }
 
index 76ed1287379d1256e46b46d8bacc4ce19f4f723b..b755d1df99e0ec79b18e787b4ca40d706f1fa155 100644 (file)
@@ -220,14 +220,16 @@ nir_lower_regs_to_ssa_impl(nir_function_impl *impl)
                               nir_metadata_dominance);
    nir_index_local_regs(impl);
 
+   void *dead_ctx = ralloc_context(NULL);
    struct regs_to_ssa_state state;
    state.shader = impl->function->shader;
-   state.values = malloc(impl->reg_alloc * sizeof(*state.values));
+   state.values = ralloc_array(dead_ctx, struct nir_phi_builder_value *,
+                               impl->reg_alloc);
 
    struct nir_phi_builder *phi_build = nir_phi_builder_create(impl);
 
    const unsigned block_set_words = BITSET_WORDS(impl->num_blocks);
-   NIR_VLA(BITSET_WORD, defs, block_set_words);
+   BITSET_WORD *defs = ralloc_array(dead_ctx, BITSET_WORD, block_set_words);
 
    nir_foreach_register(reg, &impl->registers) {
       if (reg->num_array_elems != 0) {
@@ -305,7 +307,7 @@ nir_lower_regs_to_ssa_impl(nir_function_impl *impl)
       }
    }
 
-   free(state.values);
+   ralloc_free(dead_ctx);
 
    nir_metadata_preserve(impl, nir_metadata_block_index |
                                nir_metadata_dominance);
index 4375f93dc3ca505464f6cdbcea8b0c1715075096..c685b7ffa0cbffddee650d31b75c05720d0540f8 100644 (file)
@@ -768,7 +768,9 @@ nir_lower_vars_to_ssa_impl(nir_function_impl *impl)
 
    state.phi_builder = nir_phi_builder_create(state.impl);
 
-   NIR_VLA(BITSET_WORD, store_blocks, BITSET_WORDS(state.impl->num_blocks));
+   BITSET_WORD *store_blocks =
+      ralloc_array(state.dead_ctx, BITSET_WORD,
+                   BITSET_WORDS(state.impl->num_blocks));
    foreach_list_typed(struct deref_node, node, direct_derefs_link,
                       &state.direct_deref_nodes) {
       if (!node->lower_to_ssa)
index 621777d6ecc8d7aa03fe0d134ec9b6082dd79712..97edea777f4dfabfcc437effbc9d9fdba4a32698 100644 (file)
@@ -277,7 +277,7 @@ void
 nir_phi_builder_finish(struct nir_phi_builder *pb)
 {
    const unsigned num_blocks = pb->num_blocks;
-   NIR_VLA(nir_block *, preds, num_blocks);
+   nir_block **preds = rzalloc_array(pb, nir_block *, num_blocks);
 
    foreach_list_typed(struct nir_phi_builder_value, val, node, &pb->values) {
       /* We treat the linked list of phi nodes like a worklist.  The list is