aco/ra: use live-in variables directly rather than computing them

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30120>
This commit is contained in:
Daniel Schürmann 2024-07-08 18:46:12 +02:00 committed by Marge Bot
parent 29262f8cf3
commit 162876c875

View file

@ -2605,7 +2605,7 @@ sop2_can_use_sopk(ra_ctx& ctx, Instruction* instr)
}
void
get_affinities(ra_ctx& ctx, std::vector<IDSet>& live_out_per_block)
get_affinities(ra_ctx& ctx)
{
std::vector<std::vector<Temp>> phi_resources;
std::unordered_map<unsigned, unsigned> temp_to_phi_resources;
@ -2614,9 +2614,6 @@ get_affinities(ra_ctx& ctx, std::vector<IDSet>& live_out_per_block)
block_rit++) {
Block& block = *block_rit;
/* first, compute the death points of all live vars within the block */
IDSet& live = live_out_per_block[block.index];
std::vector<aco_ptr<Instruction>>::reverse_iterator rit;
for (rit = block.instructions.rbegin(); rit != block.instructions.rend(); ++rit) {
aco_ptr<Instruction>& instr = *rit;
@ -2658,19 +2655,11 @@ get_affinities(ra_ctx& ctx, std::vector<IDSet>& live_out_per_block)
ctx.assignments[instr->operands[0].tempId()].m0 = true;
}
/* add operands to live variables */
for (const Operand& op : instr->operands) {
if (op.isTemp())
live.insert(op.tempId());
}
/* erase definitions from live */
int op_fixed_to_def0 = get_op_fixed_to_def(instr.get());
for (unsigned i = 0; i < instr->definitions.size(); i++) {
const Definition& def = instr->definitions[i];
if (!def.isTemp())
continue;
live.erase(def.tempId());
/* mark last-seen phi operand */
std::unordered_map<unsigned, unsigned>::iterator it =
temp_to_phi_resources.find(def.tempId());
@ -2704,7 +2693,6 @@ get_affinities(ra_ctx& ctx, std::vector<IDSet>& live_out_per_block)
aco_ptr<Instruction>& instr = *rit;
assert(is_phi(instr));
live.erase(instr->definitions[0].tempId());
if (instr->definitions[0].isKill() || instr->definitions[0].isFixed())
continue;
@ -2968,15 +2956,14 @@ emit_parallel_copy(ra_ctx& ctx, std::vector<std::pair<Operand, Definition>>& par
void
register_allocation(Program* program, ra_test_policy policy)
{
std::vector<IDSet>& live_out_per_block = program->live.live_out;
ra_ctx ctx(program, policy);
get_affinities(ctx, live_out_per_block);
get_affinities(ctx);
for (Block& block : program->blocks) {
ctx.block = &block;
/* initialize register file */
RegisterFile register_file = init_reg_file(ctx, live_out_per_block, block);
RegisterFile register_file = init_reg_file(ctx, program->live.live_in, block);
ctx.war_hint.reset();
ctx.rr_vgpr_it = {PhysReg{256}};
ctx.rr_sgpr_it = {PhysReg{0}};
@ -2986,7 +2973,8 @@ register_allocation(Program* program, ra_test_policy policy)
/* this is a slight adjustment from the paper as we already have phi nodes:
* We consider them incomplete phis and only handle the definition. */
get_regs_for_phis(ctx, block, register_file, instructions, live_out_per_block[block.index]);
get_regs_for_phis(ctx, block, register_file, instructions,
program->live.live_in[block.index]);
/* If this is a merge block, the state of the register file at the branch instruction of the
* predecessors corresponds to the state after phis at the merge block. So, we allocate a
@ -2995,7 +2983,7 @@ register_allocation(Program* program, ra_test_policy policy)
if (!block.linear_preds.empty() &&
(block.linear_preds.size() != 1 ||
program->blocks[block.linear_preds[0]].linear_succs.size() == 1)) {
PhysReg br_reg = get_reg_phi(ctx, live_out_per_block[block.index], register_file,
PhysReg br_reg = get_reg_phi(ctx, program->live.live_in[block.index], register_file,
instructions, block, ctx.phi_dummy, Temp(0, s2));
for (unsigned pred : block.linear_preds) {
program->blocks[pred].scc_live_out = register_file[scc];