diff --git a/src/amd/compiler/aco_live_var_analysis.cpp b/src/amd/compiler/aco_live_var_analysis.cpp index 1bfdc3bb582..d278087d0b0 100644 --- a/src/amd/compiler/aco_live_var_analysis.cpp +++ b/src/amd/compiler/aco_live_var_analysis.cpp @@ -193,6 +193,8 @@ get_demand_for_reg(live_ctx& ctx, T op_or_def) void process_live_temps_per_block(live_ctx& ctx, Block* block) { + ctx.m.release_reallocate(); + RegisterDemand new_demand; unsigned num_linear_vgprs = 0; block->register_demand = RegisterDemand(); diff --git a/src/amd/compiler/aco_util.h b/src/amd/compiler/aco_util.h index c49b682e686..ca1f62b74d9 100644 --- a/src/amd/compiler/aco_util.h +++ b/src/amd/compiler/aco_util.h @@ -298,6 +298,38 @@ public: buffer->current_idx = 0; } + /* Release all memory, with the expectation that a similar amount will be allocated again. */ + void release_reallocate() + { + size_t size = 0; + for (Buffer* buf = buffer; buf; buf = buf->next) + size += buf->current_idx; + + if (buffer->data_size >= size) { + Buffer* buf = buffer->next; + while (buf) { + Buffer* next = buf->next; + free(buf); + buf = next; + } + buffer->next = NULL; + buffer->current_idx = 0; + return; + } + + release(); + free(buffer); + + size_t total_size = initial_size; + do { + total_size *= 2; + } while (total_size - sizeof(Buffer) < size); + buffer = (Buffer*)malloc(total_size); + buffer->next = NULL; + buffer->data_size = total_size - sizeof(Buffer); + buffer->current_idx = 0; + } + bool operator==(const monotonic_buffer_resource& other) const { return buffer == other.buffer; } private: