brw: Use brw_range to store VGRF ranges

Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34253>
This commit is contained in:
Caio Oliveira 2025-03-26 14:16:16 -07:00 committed by Marge Bot
parent e644b42e59
commit 0b4a3c0ff6
6 changed files with 16 additions and 31 deletions

View file

@ -128,7 +128,8 @@ brw_register_pressure::brw_register_pressure(const brw_shader *v)
regs_live_at_ip = new unsigned[num_instructions]();
for (unsigned reg = 0; reg < v->alloc.count; reg++) {
for (int ip = live.vgrf_start[reg]; ip <= live.vgrf_end[reg]; ip++)
brw_range range = live.vgrf_range[reg];
for (int ip = range.start; ip <= range.end; ip++)
regs_live_at_ip[ip] += v->alloc.sizes[reg];
}

View file

@ -484,8 +484,7 @@ public:
/** @{
* Final computed live ranges for each VGRF.
*/
int *vgrf_start;
int *vgrf_end;
brw_range *vgrf_range;
/** @} */
/** Per-basic-block information on live variables */

View file

@ -272,12 +272,9 @@ brw_live_variables::brw_live_variables(const brw_shader *s)
end[i] = -1;
}
vgrf_start = linear_alloc_array(lin_ctx, int, num_vgrfs);
vgrf_end = linear_alloc_array(lin_ctx, int, num_vgrfs);
for (int i = 0; i < num_vgrfs; i++) {
vgrf_start[i] = MAX_INSTRUCTION;
vgrf_end[i] = -1;
}
vgrf_range = linear_alloc_array(lin_ctx, brw_range, num_vgrfs);
for (int i = 0; i < num_vgrfs; i++)
vgrf_range[i] = { MAX_INSTRUCTION, -1 };
block_data = linear_alloc_array(lin_ctx, struct block_data, cfg->num_blocks);
@ -307,8 +304,7 @@ brw_live_variables::brw_live_variables(const brw_shader *s)
/* Merge the per-component live ranges to whole VGRF live ranges. */
for (int i = 0; i < num_vars; i++) {
const unsigned vgrf = vgrf_from_var[i];
vgrf_start[vgrf] = MIN2(vgrf_start[vgrf], start[i]);
vgrf_end[vgrf] = MAX2(vgrf_end[vgrf], end[i]);
vgrf_range[vgrf] = merge(vgrf_range[vgrf], { start[i], end[i] });
}
}
@ -322,11 +318,9 @@ check_register_live_range(const brw_live_variables *live, int ip,
const brw_reg &reg, unsigned n)
{
const unsigned var = live->var_from_reg(reg);
const brw_range reg_range{ live->vgrf_start[reg.nr],
live->vgrf_end[reg.nr] };
if (var + n > unsigned(live->num_vars) ||
!reg_range.contains(ip))
!live->vgrf_range[reg.nr].contains(ip))
return false;
for (unsigned j = 0; j < n; j++) {
@ -388,9 +382,6 @@ brw_live_variables::vgrfs_interfere(int a, int b) const
*
* Clip the ranges to cover this edge case.
*/
brw_range ra{vgrf_start[a], vgrf_end[a]};
brw_range rb{vgrf_start[b], vgrf_end[b]};
return overlaps(clip_end(ra, 1),
clip_end(rb, 1));
return overlaps(clip_end(vgrf_range[a], 1),
clip_end(vgrf_range[b], 1));
}

View file

@ -1527,8 +1527,7 @@ brw_opt_copy_propagation(brw_shader &s)
assert((*iter)->dst.file == VGRF);
brw_range block_range = ips.range(block);
brw_range vgrf_range{live.vgrf_start[(*iter)->dst.nr],
live.vgrf_end[(*iter)->dst.nr]};
brw_range vgrf_range = live.vgrf_range[(*iter)->dst.nr];
if (block_range.contains(vgrf_range))
out_acp[block->num].remove(*iter);

View file

@ -398,9 +398,7 @@ brw_reg_alloc::setup_live_interference(unsigned node, brw_range ip_range)
/* Clip the ranges so the end of a live range can overlap with
* the start of another live range. See details in vgrfs_interfere().
*/
brw_range vgrf_range { live.vgrf_start[vgrf],
live.vgrf_end[vgrf] };
if (overlaps(clip_end(vgrf_range, 1),
if (overlaps(clip_end(live.vgrf_range[vgrf], 1),
clipped_ip_range))
ra_add_node_interference(g, node, n2);
}
@ -668,11 +666,8 @@ brw_reg_alloc::build_interference_graph(bool allow_spilling)
}
/* Add interference based on the live range of the register */
for (unsigned i = 0; i < fs->alloc.count; i++) {
brw_range vgrf_range{ live.vgrf_start[i],
live.vgrf_end[i] };
setup_live_interference(first_vgrf_node + i, vgrf_range);
}
for (unsigned i = 0; i < fs->alloc.count; i++)
setup_live_interference(first_vgrf_node + i, live.vgrf_range[i]);
/* Add interference based on the instructions in which a register is used.
*/
@ -1048,7 +1043,7 @@ brw_reg_alloc::set_spill_costs()
if (isinf(spill_costs[i]))
continue;
int live_length = live.vgrf_end[i] - live.vgrf_start[i];
int live_length = live.vgrf_range[i].end - live.vgrf_range[i].start;
if (live_length <= 0)
continue;

View file

@ -857,7 +857,7 @@ brw_instruction_scheduler::setup_liveness(cfg_t *cfg)
for (int block = 0; block < cfg->num_blocks - 1; block++) {
for (int i = 0; i < grf_count; i++) {
const int block_end = ips.range(cfg->blocks[block]).end;
const brw_range vgrf_range{live.vgrf_start[i], live.vgrf_end[i]};
const brw_range vgrf_range = live.vgrf_range[i];
if (vgrf_range.contains(block_end) &&
vgrf_range.contains(block_end + 1)) {