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>
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;
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;
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));
ctx.instructions.emplace_back(std::move(instr));
}
}
- block->instructions.swap(ctx.instructions);
+ block->instructions = std::move(ctx.instructions);
}
}
/* 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);
}
}
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. */