From 0b4a3c0ff65710e06b70acfaa3cf79aefddac348 Mon Sep 17 00:00:00 2001 From: Caio Oliveira Date: Wed, 26 Mar 2025 14:16:16 -0700 Subject: [PATCH] brw: Use brw_range to store VGRF ranges Reviewed-by: Ian Romanick Part-of: --- src/intel/compiler/brw_analysis.cpp | 3 ++- src/intel/compiler/brw_analysis.h | 3 +-- src/intel/compiler/brw_analysis_liveness.cpp | 23 ++++++------------- .../compiler/brw_opt_copy_propagation.cpp | 3 +-- src/intel/compiler/brw_reg_allocate.cpp | 13 ++++------- .../compiler/brw_schedule_instructions.cpp | 2 +- 6 files changed, 16 insertions(+), 31 deletions(-) diff --git a/src/intel/compiler/brw_analysis.cpp b/src/intel/compiler/brw_analysis.cpp index e378032c472..711819e428f 100644 --- a/src/intel/compiler/brw_analysis.cpp +++ b/src/intel/compiler/brw_analysis.cpp @@ -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]; } diff --git a/src/intel/compiler/brw_analysis.h b/src/intel/compiler/brw_analysis.h index d32239ad98b..6fff36077b9 100644 --- a/src/intel/compiler/brw_analysis.h +++ b/src/intel/compiler/brw_analysis.h @@ -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 */ diff --git a/src/intel/compiler/brw_analysis_liveness.cpp b/src/intel/compiler/brw_analysis_liveness.cpp index ae1c834557a..ef58cef1762 100644 --- a/src/intel/compiler/brw_analysis_liveness.cpp +++ b/src/intel/compiler/brw_analysis_liveness.cpp @@ -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 ®, 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)); } diff --git a/src/intel/compiler/brw_opt_copy_propagation.cpp b/src/intel/compiler/brw_opt_copy_propagation.cpp index 4c62ef0602c..34cba38115f 100644 --- a/src/intel/compiler/brw_opt_copy_propagation.cpp +++ b/src/intel/compiler/brw_opt_copy_propagation.cpp @@ -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); diff --git a/src/intel/compiler/brw_reg_allocate.cpp b/src/intel/compiler/brw_reg_allocate.cpp index 30bce0cf9bc..5443d0fb0ef 100644 --- a/src/intel/compiler/brw_reg_allocate.cpp +++ b/src/intel/compiler/brw_reg_allocate.cpp @@ -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; diff --git a/src/intel/compiler/brw_schedule_instructions.cpp b/src/intel/compiler/brw_schedule_instructions.cpp index 7459c2700c8..ff1731661d3 100644 --- a/src/intel/compiler/brw_schedule_instructions.cpp +++ b/src/intel/compiler/brw_schedule_instructions.cpp @@ -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)) {