From 10660f5adfeed943fdc653554dcaf661f0adacb6 Mon Sep 17 00:00:00 2001 From: Caio Oliveira Date: Fri, 7 Mar 2025 23:05:43 -0800 Subject: [PATCH] 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 Part-of: --- src/intel/compiler/brw_analysis.cpp | 43 +++++++++++++++++++++++++++++ src/intel/compiler/brw_analysis.h | 32 +++++++++++++++++++++ src/intel/compiler/brw_shader.cpp | 3 ++ src/intel/compiler/brw_shader.h | 1 + 4 files changed, 79 insertions(+) diff --git a/src/intel/compiler/brw_analysis.cpp b/src/intel/compiler/brw_analysis.cpp index 2b2a866c997..fb05e242bd8 100644 --- a/src/intel/compiler/brw_analysis.cpp +++ b/src/intel/compiler/brw_analysis.cpp @@ -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(); diff --git a/src/intel/compiler/brw_analysis.h b/src/intel/compiler/brw_analysis.h index 8200858c03b..c127efbce22 100644 --- a/src/intel/compiler/brw_analysis.h +++ b/src/intel/compiler/brw_analysis.h @@ -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. diff --git a/src/intel/compiler/brw_shader.cpp b/src/intel/compiler/brw_shader.cpp index 74ed1f4f2e6..4e9141b08c8 100644 --- a/src/intel/compiler/brw_shader.cpp +++ b/src/intel/compiler/brw_shader.cpp @@ -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 diff --git a/src/intel/compiler/brw_shader.h b/src/intel/compiler/brw_shader.h index 6a4ab528540..ebe55bd9dbf 100644 --- a/src/intel/compiler/brw_shader.h +++ b/src/intel/compiler/brw_shader.h @@ -139,6 +139,7 @@ public: brw_analysis performance_analysis; brw_analysis idom_analysis; brw_analysis def_analysis; + brw_analysis ip_ranges_analysis; /** Number of uniform variable components visited. */ unsigned uniforms;