brw: Make brw_range use half-open 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-27 08:23:36 -07:00
committed by Marge Bot
parent 6509f8139d
commit 7457c4ecfd
4 changed files with 16 additions and 25 deletions
+2 -3
View File
@@ -112,8 +112,7 @@ brw_ip_ranges::validate(const brw_shader *s) const
if (num_blocks) {
bblock_t *last_block = s->cfg->blocks[num_blocks - 1];
unsigned last_ip = range(last_block).end;
if (last_ip + 1 != s->cfg->total_instructions)
if (range(last_block).end != (int)s->cfg->total_instructions)
return false;
}
@@ -129,7 +128,7 @@ brw_register_pressure::brw_register_pressure(const brw_shader *v)
for (unsigned reg = 0; reg < v->alloc.count; reg++) {
brw_range range = live.vgrf_range[reg];
for (int ip = range.start; ip <= range.end; ip++)
for (int ip = range.start; ip < range.end; ip++)
regs_live_at_ip[ip] += v->alloc.sizes[reg];
}
+10 -12
View File
@@ -232,7 +232,6 @@ private:
bblock_t **parents;
};
/* TODO: Make these exclusive ranges, i.e. half-open at the end. */
struct brw_range {
int start;
int end;
@@ -240,22 +239,22 @@ struct brw_range {
/* If range not empty, this is the last value inside the range. */
inline int last() const
{
return end;
return end - 1;
}
inline bool is_empty() const
{
return end < start;
return end <= start;
}
inline int len() const
{
return end - start + 1;
return end - start;
}
inline bool contains(int x) const
{
return start <= x && x <= end;
return start <= x && x < end;
}
inline bool contains(brw_range r) const
@@ -278,15 +277,15 @@ inline brw_range
merge(brw_range r, int x)
{
if (r.is_empty())
return { x, x };
return { MIN2(r.start, x), MAX2(r.end, x) };
return { x, x + 1 };
return { MIN2(r.start, x), MAX2(r.end, x + 1) };
}
inline bool
overlaps(brw_range a, brw_range b)
{
return a.start <= b.end &&
b.start <= a.end;
return a.start < b.end &&
b.start < a.end;
}
inline brw_range
@@ -296,10 +295,9 @@ intersect(brw_range a, brw_range b)
return { MAX2(a.start, b.start),
MIN2(a.end, b.end) };
else
return { 0, -1 };
return { 0, 0 };
}
inline brw_range
clip_end(brw_range r, int n)
{
@@ -322,7 +320,7 @@ struct brw_ip_ranges {
brw_range range(const bblock_t *block) const {
int start = start_ip[block->num];
return { start, start + (int)block->num_instructions - 1 };
return { start, start + (int)block->num_instructions };
}
private:
+3 -9
View File
@@ -106,7 +106,7 @@ brw_live_variables::setup_def_use()
assert(ip == bd->ip_range.start);
if (block->num > 0)
assert(block_data[block->num - 1].ip_range.end == ip - 1);
assert(block_data[block->num - 1].ip_range.end == ip);
foreach_inst_in_block(brw_inst, inst, block) {
/* Set use[] for this instruction */
@@ -259,14 +259,8 @@ brw_live_variables::brw_live_variables(const brw_shader *s)
}
}
vars_range = linear_alloc_array(lin_ctx, brw_range, num_vars);
for (int i = 0; i < num_vars; i++)
vars_range[i] = { MAX_INSTRUCTION, -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 };
vars_range = linear_zalloc_array(lin_ctx, brw_range, num_vars);
vgrf_range = linear_zalloc_array(lin_ctx, brw_range, num_vgrfs);
block_data = linear_alloc_array(lin_ctx, struct block_data, cfg->num_blocks);
bitset_words = BITSET_WORDS(num_vars);
+1 -1
View File
@@ -1086,7 +1086,7 @@ brw_reg_alloc::alloc_spill_reg(unsigned size, int ip)
assert(n == first_vgrf_node + vgrf);
assert(n == first_spill_node + spill_node_count);
brw_range spill_reg_range{ ip - 1, ip + 1 };
brw_range spill_reg_range{ ip - 1, ip + 2 };
setup_live_interference(n, spill_reg_range);
/* Add interference between this spill node and any other spill nodes for