From aec516ead66c74e7002b6918c4c94d2ebcb591c8 Mon Sep 17 00:00:00 2001 From: Caio Oliveira Date: Sun, 17 Sep 2023 23:11:58 -0700 Subject: [PATCH] util: Remove size from linear_parent creation MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit None of the callsites took advantage of this, so remove the feature. This will help to a next change that will add an opaque type to represent a linear parent. Reviewed-by: Marek Olšák Part-of: --- src/compiler/glsl/glcpp/glcpp-parse.y | 2 +- src/compiler/glsl/glsl_parser_extras.cpp | 2 +- src/compiler/glsl/glsl_symbol_table.cpp | 2 +- src/compiler/glsl/opt_dead_code_local.cpp | 2 +- src/compiler/glsl_types.cpp | 2 +- src/compiler/nir/nir_opt_combine_stores.c | 2 +- src/compiler/nir/nir_opt_copy_prop_vars.c | 2 +- src/compiler/nir/tests/vars_tests.cpp | 2 +- src/util/ralloc.c | 32 +++++++------------------------ src/util/ralloc.h | 14 +++----------- 10 files changed, 18 insertions(+), 44 deletions(-) diff --git a/src/compiler/glsl/glcpp/glcpp-parse.y b/src/compiler/glsl/glcpp/glcpp-parse.y index 3638560..15dcc14 100644 --- a/src/compiler/glsl/glcpp/glcpp-parse.y +++ b/src/compiler/glsl/glcpp/glcpp-parse.y @@ -1497,7 +1497,7 @@ glcpp_parser_create(struct gl_context *gl_ctx, glcpp_lex_init_extra (parser, &parser->scanner); parser->defines = _mesa_hash_table_create(NULL, _mesa_hash_string, _mesa_key_string_equal); - parser->linalloc = linear_alloc_parent(parser, 0); + parser->linalloc = linear_alloc_parent(parser); parser->active = NULL; parser->lexing_directive = 0; parser->lexing_version_directive = 0; diff --git a/src/compiler/glsl/glsl_parser_extras.cpp b/src/compiler/glsl/glsl_parser_extras.cpp index 7622fde..bade333 100644 --- a/src/compiler/glsl/glsl_parser_extras.cpp +++ b/src/compiler/glsl/glsl_parser_extras.cpp @@ -71,7 +71,7 @@ _mesa_glsl_parse_state::_mesa_glsl_parse_state(struct gl_context *_ctx, this->translation_unit.make_empty(); this->symbols = new(mem_ctx) glsl_symbol_table; - this->linalloc = linear_alloc_parent(this, 0); + this->linalloc = linear_alloc_parent(this); this->info_log = ralloc_strdup(mem_ctx, ""); this->error = false; diff --git a/src/compiler/glsl/glsl_symbol_table.cpp b/src/compiler/glsl/glsl_symbol_table.cpp index 9ae5fd3..7dc965d 100644 --- a/src/compiler/glsl/glsl_symbol_table.cpp +++ b/src/compiler/glsl/glsl_symbol_table.cpp @@ -106,7 +106,7 @@ glsl_symbol_table::glsl_symbol_table() this->separate_function_namespace = false; this->table = _mesa_symbol_table_ctor(); this->mem_ctx = ralloc_context(NULL); - this->linalloc = linear_alloc_parent(this->mem_ctx, 0); + this->linalloc = linear_alloc_parent(this->mem_ctx); } glsl_symbol_table::~glsl_symbol_table() diff --git a/src/compiler/glsl/opt_dead_code_local.cpp b/src/compiler/glsl/opt_dead_code_local.cpp index b89519b..afb242c 100644 --- a/src/compiler/glsl/opt_dead_code_local.cpp +++ b/src/compiler/glsl/opt_dead_code_local.cpp @@ -310,7 +310,7 @@ dead_code_local_basic_block(ir_instruction *first, bool progress = false; void *ctx = ralloc_context(NULL); - void *lin_ctx = linear_alloc_parent(ctx, 0); + void *lin_ctx = linear_alloc_parent(ctx); /* Safe looping, since process_assignment */ for (ir = first, ir_next = (ir_instruction *)first->next;; diff --git a/src/compiler/glsl_types.cpp b/src/compiler/glsl_types.cpp index ff2ce07..aa04855 100644 --- a/src/compiler/glsl_types.cpp +++ b/src/compiler/glsl_types.cpp @@ -455,7 +455,7 @@ glsl_type_singleton_init_or_ref() simple_mtx_lock(&glsl_type_cache_mutex); if (glsl_type_cache.users == 0) { glsl_type_cache.mem_ctx = ralloc_context(NULL); - glsl_type_cache.lin_ctx = linear_zalloc_parent(glsl_type_cache.mem_ctx, 0); + glsl_type_cache.lin_ctx = linear_alloc_parent(glsl_type_cache.mem_ctx); } glsl_type_cache.users++; simple_mtx_unlock(&glsl_type_cache_mutex); diff --git a/src/compiler/nir/nir_opt_combine_stores.c b/src/compiler/nir/nir_opt_combine_stores.c index 486905f..42e3b0f 100644 --- a/src/compiler/nir/nir_opt_combine_stores.c +++ b/src/compiler/nir/nir_opt_combine_stores.c @@ -417,7 +417,7 @@ nir_opt_combine_stores(nir_shader *shader, nir_variable_mode modes) void *mem_ctx = ralloc_context(NULL); struct combine_stores_state state = { .modes = modes, - .lin_ctx = linear_zalloc_parent(mem_ctx, 0), + .lin_ctx = linear_alloc_parent(mem_ctx), }; list_inithead(&state.pending); diff --git a/src/compiler/nir/nir_opt_copy_prop_vars.c b/src/compiler/nir/nir_opt_copy_prop_vars.c index efdd2dd..fd58b87 100644 --- a/src/compiler/nir/nir_opt_copy_prop_vars.c +++ b/src/compiler/nir/nir_opt_copy_prop_vars.c @@ -1482,7 +1482,7 @@ nir_copy_prop_vars_impl(nir_function_impl *impl) struct copy_prop_var_state state = { .impl = impl, .mem_ctx = mem_ctx, - .lin_ctx = linear_zalloc_parent(mem_ctx, 0), + .lin_ctx = linear_alloc_parent(mem_ctx), .vars_written_map = _mesa_pointer_hash_table_create(mem_ctx), }; diff --git a/src/compiler/nir/tests/vars_tests.cpp b/src/compiler/nir/tests/vars_tests.cpp index 53bf6cf..ee85208 100644 --- a/src/compiler/nir/tests/vars_tests.cpp +++ b/src/compiler/nir/tests/vars_tests.cpp @@ -96,7 +96,7 @@ protected: nir_vars_test::nir_vars_test() : nir_test::nir_test("nir_vars_test") { - lin_ctx = linear_alloc_parent(b->shader, 0); + lin_ctx = linear_alloc_parent(b->shader); } nir_vars_test::~nir_vars_test() diff --git a/src/util/ralloc.c b/src/util/ralloc.c index 278d671..d689285 100644 --- a/src/util/ralloc.c +++ b/src/util/ralloc.c @@ -991,10 +991,6 @@ struct linear_size_chunk { typedef struct linear_header linear_header; typedef struct linear_size_chunk linear_size_chunk; -#define LINEAR_PARENT_TO_HEADER(parent) \ - (linear_header*) \ - ((char*)(parent) - sizeof(linear_size_chunk) - sizeof(linear_header)) - /* Allocate the linear buffer with its header. */ static linear_header * create_linear_node(void *ralloc_ctx, unsigned min_size) @@ -1022,7 +1018,7 @@ create_linear_node(void *ralloc_ctx, unsigned min_size) void * linear_alloc_child(void *parent, unsigned size) { - linear_header *first = LINEAR_PARENT_TO_HEADER(parent); + linear_header *first = parent; linear_header *latest = first->latest; linear_header *new_node; linear_size_chunk *ptr; @@ -1054,22 +1050,18 @@ linear_alloc_child(void *parent, unsigned size) } void * -linear_alloc_parent(void *ralloc_ctx, unsigned size) +linear_alloc_parent(void *ralloc_ctx) { linear_header *node; if (unlikely(!ralloc_ctx)) return NULL; - size = ALIGN_POT(size, SUBALLOC_ALIGNMENT); - - node = create_linear_node(ralloc_ctx, size); + node = create_linear_node(ralloc_ctx, 0); if (unlikely(!node)) return NULL; - return linear_alloc_child((char*)node + - sizeof(linear_header) + - sizeof(linear_size_chunk), size); + return node; } void * @@ -1082,23 +1074,13 @@ linear_zalloc_child(void *parent, unsigned size) return ptr; } -void * -linear_zalloc_parent(void *parent, unsigned size) -{ - void *ptr = linear_alloc_parent(parent, size); - - if (likely(ptr)) - memset(ptr, 0, size); - return ptr; -} - void linear_free_parent(void *ptr) { if (unlikely(!ptr)) return; - linear_header *first = LINEAR_PARENT_TO_HEADER(ptr); + linear_header *first = ptr; assert(first->magic == LMAGIC); /* Other nodes are ralloc children of the first node. */ @@ -1111,7 +1093,7 @@ ralloc_steal_linear_parent(void *new_ralloc_ctx, void *ptr) if (unlikely(!ptr)) return; - linear_header *first = LINEAR_PARENT_TO_HEADER(ptr); + linear_header *first = ptr; assert(first->magic == LMAGIC); /* Other nodes are ralloc children of the first node. */ @@ -1121,7 +1103,7 @@ ralloc_steal_linear_parent(void *new_ralloc_ctx, void *ptr) void * ralloc_parent_of_linear_parent(void *ptr) { - linear_header *node = LINEAR_PARENT_TO_HEADER(ptr); + linear_header *node = ptr; assert(node->magic == LMAGIC); return PTR_FROM_HEADER(get_header(node)->parent); } diff --git a/src/util/ralloc.h b/src/util/ralloc.h index 5bb0f52..47a0f40 100644 --- a/src/util/ralloc.h +++ b/src/util/ralloc.h @@ -556,7 +556,6 @@ public: \ #define DECLARE_LINEAR_ZALLOC_CXX_OPERATORS(type) \ DECLARE_ALLOC_CXX_OPERATORS_TEMPLATE(type, linear_zalloc_child) - /** * Do a fast allocation from the linear buffer, also known as the child node * from the allocator's point of view. It can't be freed directly. You have @@ -568,14 +567,12 @@ public: \ void *linear_alloc_child(void *parent, unsigned size) MALLOCLIKE; /** - * Allocate a parent node that will hold linear buffers. The returned - * allocation is actually the first child node, but it's also the handle - * of the parent node. Use it for all child node allocations. + * Allocate a parent node that will hold linear buffers. + * Use it for all child node allocations. * * \param ralloc_ctx ralloc context, must not be NULL - * \param size size to allocate (max 32 bits) */ -void *linear_alloc_parent(void *ralloc_ctx, unsigned size) MALLOCLIKE; +void *linear_alloc_parent(void *ralloc_ctx); /** * Same as linear_alloc_child, but also clears memory. @@ -583,11 +580,6 @@ void *linear_alloc_parent(void *ralloc_ctx, unsigned size) MALLOCLIKE; void *linear_zalloc_child(void *parent, unsigned size) MALLOCLIKE; /** - * Same as linear_alloc_parent, but also clears memory. - */ -void *linear_zalloc_parent(void *ralloc_ctx, unsigned size) MALLOCLIKE; - -/** * Free the linear parent node. This will free all child nodes too. * Freeing the ralloc parent will also free this. */ -- 2.7.4