nir/validate: Use a ralloc context for our temporary data
authorJason Ekstrand <jason@jlekstrand.net>
Fri, 10 May 2019 19:44:45 +0000 (14:44 -0500)
committerJason Ekstrand <jason@jlekstrand.net>
Mon, 13 May 2019 14:43:47 +0000 (14:43 +0000)
All of our hash tables and sets are already using ralloc.  There's
really no good reason why we don't just make a ralloc context rather
than try to remember to clean everything up manually.

Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Thomas Helland <thomashelland90@gmail.com>
src/compiler/nir/nir_validate.c

index 7746c391abcab9f3e1b288501a3a80d256c535e1..3b3244b317eda95a1a0d954e651bcacb280ab90a 100644 (file)
@@ -61,6 +61,8 @@ typedef struct {
 } ssa_def_validate_state;
 
 typedef struct {
 } ssa_def_validate_state;
 
 typedef struct {
+   void *mem_ctx;
+
    /* map of register -> validation state (struct above) */
    struct hash_table *regs;
 
    /* map of register -> validation state (struct above) */
    struct hash_table *regs;
 
@@ -1135,9 +1137,8 @@ validate_function_impl(nir_function_impl *impl, validate_state *state)
       validate_var_decl(var, false, state);
    }
 
       validate_var_decl(var, false, state);
    }
 
-   state->regs_found = realloc(state->regs_found,
-                               BITSET_WORDS(impl->reg_alloc) *
-                               sizeof(BITSET_WORD));
+   state->regs_found = reralloc(state->mem_ctx, state->regs_found,
+                                BITSET_WORD, BITSET_WORDS(impl->reg_alloc));
    memset(state->regs_found, 0, BITSET_WORDS(impl->reg_alloc) *
                                 sizeof(BITSET_WORD));
    exec_list_validate(&impl->registers);
    memset(state->regs_found, 0, BITSET_WORDS(impl->reg_alloc) *
                                 sizeof(BITSET_WORD));
    exec_list_validate(&impl->registers);
@@ -1145,9 +1146,8 @@ validate_function_impl(nir_function_impl *impl, validate_state *state)
       prevalidate_reg_decl(reg, state);
    }
 
       prevalidate_reg_decl(reg, state);
    }
 
-   state->ssa_defs_found = realloc(state->ssa_defs_found,
-                                   BITSET_WORDS(impl->ssa_alloc) *
-                                   sizeof(BITSET_WORD));
+   state->ssa_defs_found = reralloc(state->mem_ctx, state->ssa_defs_found,
+                                    BITSET_WORD, BITSET_WORDS(impl->ssa_alloc));
    memset(state->ssa_defs_found, 0, BITSET_WORDS(impl->ssa_alloc) *
                                     sizeof(BITSET_WORD));
    exec_list_validate(&impl->body);
    memset(state->ssa_defs_found, 0, BITSET_WORDS(impl->ssa_alloc) *
                                     sizeof(BITSET_WORD));
    exec_list_validate(&impl->body);
@@ -1177,12 +1177,13 @@ validate_function(nir_function *func, validate_state *state)
 static void
 init_validate_state(validate_state *state)
 {
 static void
 init_validate_state(validate_state *state)
 {
-   state->regs = _mesa_pointer_hash_table_create(NULL);
-   state->ssa_defs = _mesa_pointer_hash_table_create(NULL);
+   state->mem_ctx = ralloc_context(NULL);
+   state->regs = _mesa_pointer_hash_table_create(state->mem_ctx);
+   state->ssa_defs = _mesa_pointer_hash_table_create(state->mem_ctx);
    state->ssa_defs_found = NULL;
    state->regs_found = NULL;
    state->ssa_defs_found = NULL;
    state->regs_found = NULL;
-   state->var_defs = _mesa_pointer_hash_table_create(NULL);
-   state->errors = _mesa_pointer_hash_table_create(NULL);
+   state->var_defs = _mesa_pointer_hash_table_create(state->mem_ctx);
+   state->errors = _mesa_pointer_hash_table_create(state->mem_ctx);
 
    state->loop = NULL;
    state->instr = NULL;
 
    state->loop = NULL;
    state->instr = NULL;
@@ -1192,12 +1193,7 @@ init_validate_state(validate_state *state)
 static void
 destroy_validate_state(validate_state *state)
 {
 static void
 destroy_validate_state(validate_state *state)
 {
-   _mesa_hash_table_destroy(state->regs, NULL);
-   _mesa_hash_table_destroy(state->ssa_defs, NULL);
-   free(state->ssa_defs_found);
-   free(state->regs_found);
-   _mesa_hash_table_destroy(state->var_defs, NULL);
-   _mesa_hash_table_destroy(state->errors, NULL);
+   ralloc_free(state->mem_ctx);
 }
 
 mtx_t fail_dump_mutex = _MTX_INITIALIZER_NP;
 }
 
 mtx_t fail_dump_mutex = _MTX_INITIALIZER_NP;