aco: use std::vector::reserve() more often
This removes the majority of vector re-allocations. Reviewed-by: Rhys Perry <pendingchaos02@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18105>
This commit is contained in:
committed by
Marge Bot
parent
902bf8ce07
commit
3d6ea4f666
@@ -10290,6 +10290,8 @@ visit_jump(isel_context* ctx, nir_jump_instr* instr)
|
||||
void
|
||||
visit_block(isel_context* ctx, nir_block* block)
|
||||
{
|
||||
ctx->block->instructions.reserve(ctx->block->instructions.size() +
|
||||
exec_list_length(&block->instr_list) * 2);
|
||||
nir_foreach_instr (instr, block) {
|
||||
switch (instr->type) {
|
||||
case nir_instr_type_alu: visit_alu_instr(ctx, nir_instr_as_alu(instr)); break;
|
||||
|
||||
@@ -934,6 +934,10 @@ setup_isel_context(Program* program, unsigned shader_count, struct nir_shader* c
|
||||
|
||||
ctx.program->config->scratch_bytes_per_wave = align(scratch_size * ctx.program->wave_size, 1024);
|
||||
|
||||
unsigned nir_num_blocks = 0;
|
||||
for (unsigned i = 0; i < shader_count; i++)
|
||||
nir_num_blocks += nir_shader_get_entrypoint(shaders[i])->num_blocks;
|
||||
ctx.program->blocks.reserve(nir_num_blocks * 2);
|
||||
ctx.block = ctx.program->create_and_insert_block();
|
||||
ctx.block->kind = block_kind_top_level;
|
||||
|
||||
|
||||
@@ -2009,6 +2009,7 @@ lower_to_hw_instr(Program* program)
|
||||
lower_context ctx;
|
||||
ctx.program = program;
|
||||
ctx.block = block;
|
||||
ctx.instructions.reserve(block->instructions.size());
|
||||
Builder bld(program, &ctx.instructions);
|
||||
|
||||
emit_set_mode_from_block(bld, *program, block, (block_idx == 0));
|
||||
@@ -2520,7 +2521,7 @@ lower_to_hw_instr(Program* program)
|
||||
ctx.instructions.emplace_back(std::move(instr));
|
||||
}
|
||||
}
|
||||
block->instructions.swap(ctx.instructions);
|
||||
block->instructions = std::move(ctx.instructions);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4828,11 +4828,11 @@ optimize(Program* program)
|
||||
|
||||
/* 4. Add literals to instructions */
|
||||
for (Block& block : program->blocks) {
|
||||
ctx.instructions.clear();
|
||||
ctx.instructions.reserve(block.instructions.size());
|
||||
ctx.fp_mode = block.fp_mode;
|
||||
for (aco_ptr<Instruction>& instr : block.instructions)
|
||||
apply_literals(ctx, instr);
|
||||
block.instructions.swap(ctx.instructions);
|
||||
block.instructions = std::move(ctx.instructions);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2674,6 +2674,7 @@ register_allocation(Program* program, std::vector<IDSet>& live_out_per_block, ra
|
||||
ctx.war_hint.reset();
|
||||
|
||||
std::vector<aco_ptr<Instruction>> instructions;
|
||||
instructions.reserve(block.instructions.size());
|
||||
|
||||
/* this is a slight adjustment from the paper as we already have phi nodes:
|
||||
* We consider them incomplete phis and only handle the definition. */
|
||||
|
||||
Reference in New Issue
Block a user