brw: Add analysis for block IP ranges

Calculate the IP ranges of the shader as an analysis pass.  This will
later replace the existing tracking of start_ip/end_ip as the blocks are
changed (and the defer/adjust scheme to avoid too much churn when that
happen).

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34012>
This commit is contained in:
Caio Oliveira
2025-03-07 23:05:43 -08:00
committed by Marge Bot
parent fd6045cca9
commit 10660f5adf
4 changed files with 79 additions and 0 deletions
+43
View File
@@ -77,6 +77,49 @@ brw_idom_tree::dump(FILE *file) const
fprintf(file, "}\n");
}
brw_ip_ranges::brw_ip_ranges(const brw_shader *shader)
{
num_blocks = shader->cfg->num_blocks;
start_ip = new int[num_blocks];
unsigned next_ip = 0;
for (int i = 0; i < num_blocks; i++) {
start_ip[i] = next_ip;
bblock_t *block = shader->cfg->blocks[i];
next_ip += block->num_instructions;
}
}
brw_ip_ranges::~brw_ip_ranges()
{
delete[] start_ip;
}
bool
brw_ip_ranges::validate(const brw_shader *s) const
{
if (s->cfg->num_blocks != num_blocks)
return false;
int ip = 0;
for (int i = 0; i < num_blocks; i++) {
bblock_t *block = s->cfg->blocks[i];
if (start_ip[i] != ip)
return false;
ip += block->num_instructions;
}
if (num_blocks) {
bblock_t *last_block = s->cfg->blocks[num_blocks - 1];
unsigned last_ip = end(last_block);
if (last_ip + 1 != s->cfg->total_instructions)
return false;
}
return true;
}
brw_register_pressure::brw_register_pressure(const brw_shader *v)
{
const brw_live_variables &live = v->live_analysis.require();
+32
View File
@@ -232,6 +232,38 @@ private:
bblock_t **parents;
};
struct brw_ip_ranges {
brw_ip_ranges(const brw_shader *s);
~brw_ip_ranges();
bool validate(const brw_shader *) const;
brw_analysis_dependency_class
dependency_class() const
{
return BRW_DEPENDENCY_INSTRUCTION_IDENTITY |
BRW_DEPENDENCY_BLOCKS;
}
int
start(const bblock_t *block) const
{
assert(block->num < num_blocks);
return start_ip[block->num];
}
int
end(const bblock_t *block) const
{
assert(block->num < num_blocks);
return start_ip[block->num] + block->num_instructions - 1;
}
private:
int num_blocks;
int *start_ip;
};
/**
* Register pressure analysis of a shader. Estimates how many registers
* are live at any point of the program in GRF units.
+3
View File
@@ -409,6 +409,7 @@ brw_shader::brw_shader(const struct brw_compiler *compiler,
key(key), prog_data(prog_data),
live_analysis(this), regpressure_analysis(this),
performance_analysis(this), idom_analysis(this), def_analysis(this),
ip_ranges_analysis(this),
needs_register_pressure(needs_register_pressure),
dispatch_width(dispatch_width),
max_polygons(0),
@@ -433,6 +434,7 @@ brw_shader::brw_shader(const struct brw_compiler *compiler,
key(&key->base), prog_data(&prog_data->base),
live_analysis(this), regpressure_analysis(this),
performance_analysis(this), idom_analysis(this), def_analysis(this),
ip_ranges_analysis(this),
needs_register_pressure(needs_register_pressure),
dispatch_width(dispatch_width),
max_polygons(max_polygons),
@@ -957,6 +959,7 @@ brw_shader::invalidate_analysis(brw_analysis_dependency_class c)
performance_analysis.invalidate(c);
idom_analysis.invalidate(c);
def_analysis.invalidate(c);
ip_ranges_analysis.invalidate(c);
}
void
+1
View File
@@ -139,6 +139,7 @@ public:
brw_analysis<brw_performance, brw_shader> performance_analysis;
brw_analysis<brw_idom_tree, brw_shader> idom_analysis;
brw_analysis<brw_def_analysis, brw_shader> def_analysis;
brw_analysis<brw_ip_ranges, brw_shader> ip_ranges_analysis;
/** Number of uniform variable components visited. */
unsigned uniforms;