aco/optimize_postRA: Use iterators instead of operator[] of std::array.

Also add a few more assertions to make sure the registers are
within the bounds of the array.

Cc: mesa-stable
Signed-off-by: Timur Kristóf <timur.kristof@gmail.com>
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Tony Wasserka <tony.wasserka@gmx.de>
Reviewed-by: Joshua Ashton <joshua@froggi.es>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12682>
This commit is contained in:
Timur Kristóf
2021-09-01 18:28:51 +02:00
committed by Marge Bot
parent bb956464cb
commit 268158a758
+6 -4
View File
@@ -112,8 +112,8 @@ save_reg_writes(pr_opt_ctx& ctx, aco_ptr<Instruction>& instr)
assert((r + dw_size) <= max_reg_cnt);
assert(def.size() == dw_size || def.regClass().is_subdword());
std::fill(&ctx.instr_idx_by_regs[ctx.current_block->index][r],
&ctx.instr_idx_by_regs[ctx.current_block->index][r] + dw_size, idx);
std::fill(ctx.instr_idx_by_regs[ctx.current_block->index].begin() + r,
ctx.instr_idx_by_regs[ctx.current_block->index].begin() + r + dw_size, idx);
}
}
@@ -121,11 +121,12 @@ Idx
last_writer_idx(pr_opt_ctx& ctx, PhysReg physReg, RegClass rc)
{
/* Verify that all of the operand's registers are written by the same instruction. */
assert(physReg.reg() < max_reg_cnt);
Idx instr_idx = ctx.instr_idx_by_regs[ctx.current_block->index][physReg.reg()];
unsigned dw_size = DIV_ROUND_UP(rc.bytes(), 4u);
unsigned r = physReg.reg();
bool all_same = std::all_of(&ctx.instr_idx_by_regs[ctx.current_block->index][r],
&ctx.instr_idx_by_regs[ctx.current_block->index][r + dw_size],
bool all_same = std::all_of(ctx.instr_idx_by_regs[ctx.current_block->index].begin() + r,
ctx.instr_idx_by_regs[ctx.current_block->index].begin() + r + dw_size,
[instr_idx](Idx i) { return i == instr_idx; });
return all_same ? instr_idx : written_by_multiple_instrs;
@@ -137,6 +138,7 @@ last_writer_idx(pr_opt_ctx& ctx, const Operand& op)
if (op.isConstant() || op.isUndefined())
return const_or_undef;
assert(op.physReg().reg() < max_reg_cnt);
Idx instr_idx = ctx.instr_idx_by_regs[ctx.current_block->index][op.physReg().reg()];
#ifndef NDEBUG