util: Remove size from linear_parent creation

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 <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25280>
This commit is contained in:
Caio Oliveira
2023-09-17 23:11:58 -07:00
committed by Marge Bot
parent 4519421db5
commit aec516ead6
10 changed files with 18 additions and 44 deletions

View File

@@ -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;

View File

@@ -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;

View File

@@ -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()

View File

@@ -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;;

View File

@@ -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);

View File

@@ -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);

View File

@@ -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),
};

View File

@@ -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()

View File

@@ -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);
}

View File

@@ -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,25 +567,18 @@ 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.
*/
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.