mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-01-17 00:30:19 +01:00
Totals from 6651 (8.38% of 79377) affected shaders: (Navi31) Instrs: 14722896 -> 14722290 (-0.00%); split: -0.01%, +0.00% CodeSize: 77992072 -> 77989284 (-0.00%); split: -0.01%, +0.00% Latency: 160542885 -> 160541215 (-0.00%); split: -0.00%, +0.00% InvThroughput: 24543177 -> 24542710 (-0.00%); split: -0.00%, +0.00% Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33527>
97 lines
2.9 KiB
C++
97 lines
2.9 KiB
C++
/*
|
|
* Copyright © 2018 Valve Corporation
|
|
*
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
#include "aco_ir.h"
|
|
|
|
#include <vector>
|
|
|
|
namespace aco {
|
|
namespace {
|
|
|
|
struct phi_info {
|
|
std::vector<std::pair<Definition, Operand>> copies;
|
|
PhysReg scratch_sgpr;
|
|
bool needs_scratch_reg = false;
|
|
};
|
|
|
|
struct ssa_elimination_ctx {
|
|
/* The outer vectors should be indexed by block index.
|
|
* The inner vectors store phi information for each block.
|
|
*/
|
|
std::vector<phi_info> phi_infos;
|
|
Program* program;
|
|
|
|
ssa_elimination_ctx(Program* program_) : phi_infos(program_->blocks.size()), program(program_) {}
|
|
};
|
|
|
|
void
|
|
collect_phi_info(ssa_elimination_ctx& ctx)
|
|
{
|
|
for (Block& block : ctx.program->blocks) {
|
|
for (aco_ptr<Instruction>& phi : block.instructions) {
|
|
if (phi->opcode != aco_opcode::p_phi && phi->opcode != aco_opcode::p_linear_phi)
|
|
break;
|
|
|
|
for (unsigned i = 0; i < phi->operands.size(); i++) {
|
|
if (phi->operands[i].isUndefined())
|
|
continue;
|
|
if (phi->operands[i].physReg() == phi->definitions[0].physReg())
|
|
continue;
|
|
|
|
assert(phi->definitions[0].size() == phi->operands[i].size());
|
|
|
|
Block::edge_vec& preds =
|
|
phi->opcode == aco_opcode::p_phi ? block.logical_preds : block.linear_preds;
|
|
auto& info = ctx.phi_infos[preds[i]];
|
|
info.copies.emplace_back(phi->definitions[0], phi->operands[i]);
|
|
if (phi->pseudo().needs_scratch_reg) {
|
|
info.needs_scratch_reg = true;
|
|
info.scratch_sgpr = phi->pseudo().scratch_sgpr;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void
|
|
insert_parallelcopies(ssa_elimination_ctx& ctx)
|
|
{
|
|
/* insert parallelcopies for the phis at the end of blocks just before the branch */
|
|
for (unsigned block_idx = 0; block_idx < ctx.program->blocks.size(); ++block_idx) {
|
|
auto& phi_info = ctx.phi_infos[block_idx];
|
|
if (phi_info.copies.empty())
|
|
continue;
|
|
|
|
Block& block = ctx.program->blocks[block_idx];
|
|
aco_ptr<Instruction> pc{create_instruction(aco_opcode::p_parallelcopy, Format::PSEUDO,
|
|
phi_info.copies.size(), phi_info.copies.size())};
|
|
unsigned i = 0;
|
|
for (auto& pair : phi_info.copies) {
|
|
pc->definitions[i] = pair.first;
|
|
pc->operands[i] = pair.second;
|
|
i++;
|
|
}
|
|
pc->pseudo().scratch_sgpr = phi_info.scratch_sgpr;
|
|
pc->pseudo().needs_scratch_reg = phi_info.needs_scratch_reg;
|
|
auto it = std::prev(block.instructions.end());
|
|
block.instructions.insert(it, std::move(pc));
|
|
}
|
|
}
|
|
|
|
} /* end namespace */
|
|
|
|
void
|
|
ssa_elimination(Program* program)
|
|
{
|
|
ssa_elimination_ctx ctx(program);
|
|
|
|
/* Collect information about every phi-instruction */
|
|
collect_phi_info(ctx);
|
|
|
|
/* insert parallelcopies from SSA elimination */
|
|
insert_parallelcopies(ctx);
|
|
}
|
|
} // namespace aco
|