ralloc: use rzalloc where it's necessary
authorMarek Olšák <marek.olsak@amd.com>
Thu, 6 Oct 2016 22:34:26 +0000 (00:34 +0200)
committerMarek Olšák <marek.olsak@amd.com>
Mon, 31 Oct 2016 10:53:38 +0000 (11:53 +0100)
No change in behavior. ralloc_size is equivalent to rzalloc_size.
That will change though.

Calls not switched to rzalloc_size:
- ralloc_vasprintf
- glsl_type::name allocation (it's filled with snprintf)
- C++ classes where valgrind didn't show uninitialized values

I switched most of non-glsl stuff to rzalloc without checking whether
it's really needed.

Reviewed-by: Edward O'Callaghan <funfunctor@folklore1984.net>
Tested-by: Edmondo Tommasina <edmondo.tommasina@gmail.com>
Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
src/compiler/glsl/ast.h
src/compiler/glsl/ast_to_hir.cpp
src/compiler/glsl/glsl_parser_extras.h
src/compiler/glsl/link_uniform_blocks.cpp
src/compiler/glsl/list.h
src/compiler/nir/nir.c
src/compiler/spirv/vtn_variables.c
src/gallium/drivers/freedreno/ir3/ir3.c
src/gallium/drivers/vc4/vc4_cl.c
src/gallium/drivers/vc4/vc4_program.c
src/mesa/drivers/dri/i965/brw_state_batch.c

index 55f009ac85792c395b062e6682e3a5d6b4dfe82a..063a9b43af059ba8052099ab80976bac694986b5 100644 (file)
@@ -49,7 +49,7 @@ struct YYLTYPE;
  */
 class ast_node {
 public:
-   DECLARE_RALLOC_CXX_OPERATORS(ast_node);
+   DECLARE_RZALLOC_CXX_OPERATORS(ast_node);
 
    /**
     * Print an AST node in something approximating the original GLSL code
index a9a1ba3c48cdec20ec5ba0f9470f38484503bc13..24067b6ac0c5eadacfe3923209b9f9147f41a387 100644 (file)
@@ -6639,8 +6639,8 @@ ast_process_struct_or_iface_block_members(exec_list *instructions,
     * the types to HIR.  This ensures that structure definitions embedded in
     * other structure definitions or in interface blocks are processed.
     */
-   glsl_struct_field *const fields = ralloc_array(state, glsl_struct_field,
-                                                  decl_count);
+   glsl_struct_field *const fields = rzalloc_array(state, glsl_struct_field,
+                                                   decl_count);
 
    bool first_member = true;
    bool first_member_has_explicit_location = false;
index 5bdebf684bb28e98a403b9149dbd121a4092f9f7..e50d08ad38cb0d9cc318a1bedfffc3999a3303b6 100644 (file)
@@ -76,7 +76,7 @@ struct _mesa_glsl_parse_state {
    _mesa_glsl_parse_state(struct gl_context *_ctx, gl_shader_stage stage,
                           void *mem_ctx);
 
-   DECLARE_RALLOC_CXX_OPERATORS(_mesa_glsl_parse_state);
+   DECLARE_RZALLOC_CXX_OPERATORS(_mesa_glsl_parse_state);
 
    /**
     * Generate a string representing the GLSL version currently being compiled
index c0bdfa934e0f03b0a704f92d04fda7cad6ff5d4d..1fc0e2d5109f2d20e57a66982c54990d157b04eb 100644 (file)
@@ -310,7 +310,7 @@ create_buffer_blocks(void *mem_ctx, struct gl_context *ctx,
    /* Allocate storage to hold all of the information related to uniform
     * blocks that can be queried through the API.
     */
-   struct gl_uniform_block *blocks = ralloc_array(mem_ctx, gl_uniform_block, num_blocks);
+   struct gl_uniform_block *blocks = rzalloc_array(mem_ctx, gl_uniform_block, num_blocks);
    gl_uniform_buffer_variable *variables =
       ralloc_array(blocks, gl_uniform_buffer_variable, num_variables);
 
index b5b5b362afd23c089a5895d6825b224e1bb3736d..6afb9dcef9437b27b5263e36179e2e2108fb7052 100644 (file)
@@ -56,7 +56,7 @@ struct exec_node {
    struct exec_node *prev;
 
 #ifdef __cplusplus
-   DECLARE_RALLOC_CXX_OPERATORS(exec_node)
+   DECLARE_RZALLOC_CXX_OPERATORS(exec_node)
 
    exec_node() : next(NULL), prev(NULL)
    {
index 31f0bcb8d81908c315474873f5cd1bf8bd910355..cfb032c68b9fdf6450a27402075cbdf4ef2b1bd0 100644 (file)
@@ -448,9 +448,10 @@ nir_alu_instr *
 nir_alu_instr_create(nir_shader *shader, nir_op op)
 {
    unsigned num_srcs = nir_op_infos[op].num_inputs;
+   /* TODO: don't use rzalloc */
    nir_alu_instr *instr =
-      ralloc_size(shader,
-                  sizeof(nir_alu_instr) + num_srcs * sizeof(nir_alu_src));
+      rzalloc_size(shader,
+                   sizeof(nir_alu_instr) + num_srcs * sizeof(nir_alu_src));
 
    instr_init(&instr->instr, nir_instr_type_alu);
    instr->op = op;
@@ -486,8 +487,9 @@ nir_intrinsic_instr *
 nir_intrinsic_instr_create(nir_shader *shader, nir_intrinsic_op op)
 {
    unsigned num_srcs = nir_intrinsic_infos[op].num_srcs;
+   /* TODO: don't use rzalloc */
    nir_intrinsic_instr *instr =
-      ralloc_size(shader,
+      rzalloc_size(shader,
                   sizeof(nir_intrinsic_instr) + num_srcs * sizeof(nir_src));
 
    instr_init(&instr->instr, nir_instr_type_intrinsic);
index c9744c4513d559f10eb1f1621d7de272178a9b50..bbcca14610702e6cea6df538adb3afe43b5bfa59 100644 (file)
@@ -35,7 +35,8 @@ vtn_access_chain_extend(struct vtn_builder *b, struct vtn_access_chain *old,
    struct vtn_access_chain *chain;
 
    unsigned new_len = old->length + new_ids;
-   chain = ralloc_size(b, sizeof(*chain) + new_len * sizeof(chain->link[0]));
+   /* TODO: don't use rzalloc */
+   chain = rzalloc_size(b, sizeof(*chain) + new_len * sizeof(chain->link[0]));
 
    chain->var = old->var;
    chain->length = new_len;
index 78ec1cc483e749304acc4c89dddefce918437aa8..9f2116a520f8c033a290cebcaa48ba6fbe4bf867 100644 (file)
@@ -40,7 +40,7 @@
  */
 void * ir3_alloc(struct ir3 *shader, int sz)
 {
-       return ralloc_size(shader, sz);
+       return rzalloc_size(shader, sz); /* TODO: don't use rzalloc */
 }
 
 struct ir3 * ir3_create(struct ir3_compiler *compiler,
index afb9987f400f01ea404db9ffa0024c851bd7dd00..91f51b02bb666e51e60cc03be17f58cab7ef9bd8 100644 (file)
@@ -28,7 +28,7 @@
 void
 vc4_init_cl(void *mem_ctx, struct vc4_cl *cl)
 {
-        cl->base = ralloc_size(mem_ctx, 1);
+        cl->base = rzalloc_size(mem_ctx, 1); /* TODO: don't use rzalloc */
         cl->next = cl->base;
         cl->size = 0;
 }
index 11066c133b58ffae93ada14f281f8ccd4de37471..809c96dda3dfb02dbb6ad2b7f909bca0d6ef0ae0 100644 (file)
@@ -2518,7 +2518,7 @@ vc4_get_compiled_shader(struct vc4_context *vc4, enum qstage stage,
         qir_compile_destroy(c);
 
         struct vc4_key *dup_key;
-        dup_key = ralloc_size(shader, key_size);
+        dup_key = rzalloc_size(shader, key_size); /* TODO: don't use rzalloc */
         memcpy(dup_key, key, key_size);
         _mesa_hash_table_insert(ht, dup_key, shader);
 
index d79e0ea00c763d2a2138a85ccc2f0c457ba8e312..9658b48ca138ed0af63bd4b0946c0e8cbdf37b9d 100644 (file)
@@ -46,9 +46,10 @@ brw_track_state_batch(struct brw_context *brw,
    if (!brw->state_batch_list) {
       /* Our structs are always aligned to at least 32 bytes, so
        * our array doesn't need to be any larger
+       * TODO: don't use rzalloc
        */
-      brw->state_batch_list = ralloc_size(brw, sizeof(*brw->state_batch_list) *
-                                         batch->bo->size / 32);
+      brw->state_batch_list = rzalloc_size(brw, sizeof(*brw->state_batch_list) *
+                                           batch->bo->size / 32);
    }
 
    brw->state_batch_list[brw->state_batch_count].offset = offset;