From 48dfb30f9231c22a6af6885dbc9ef86dc2edde1e Mon Sep 17 00:00:00 2001 From: Francisco Jerez Date: Wed, 9 Mar 2016 17:47:17 -0800 Subject: [PATCH] intel/compiler: Move all live interval analysis results into vec4_live_variables This moves the following methods that are currently defined in vec4_visitor (even though they are side products of the liveness analysis computation) and are already implemented in brw_vec4_live_variables.cpp: > int var_range_start(unsigned v, unsigned n) const; > int var_range_end(unsigned v, unsigned n) const; > bool virtual_grf_interferes(int a, int b) const; > int *virtual_grf_start; > int *virtual_grf_end; It makes sense for them to be part of the vec4_live_variables object, because they have the same lifetime as other liveness analysis results and because this will allow some extra validation to happen wherever they are accessed in order to make sure that we only ever use up-to-date liveness analysis results. The naming of the virtual_grf_start/end arrays was rather misleading, they were indexed by variable rather than by vgrf, this renames them start/end to match the FS liveness analysis pass. The churn in the definition of var_range_start/end is just in order to avoid a collision between the start/end arrays and local variables declared with the same name. Reviewed-by: Matt Turner Part-of: --- src/intel/compiler/brw_vec4.cpp | 3 +- src/intel/compiler/brw_vec4.h | 5 --- src/intel/compiler/brw_vec4_cse.cpp | 3 +- .../compiler/brw_vec4_live_variables.cpp | 35 +++++++++++-------- src/intel/compiler/brw_vec4_live_variables.h | 11 ++++++ src/intel/compiler/brw_vec4_reg_allocate.cpp | 2 +- src/intel/compiler/brw_vec4_visitor.cpp | 2 -- 7 files changed, 36 insertions(+), 25 deletions(-) diff --git a/src/intel/compiler/brw_vec4.cpp b/src/intel/compiler/brw_vec4.cpp index de2149f416b..514fab10820 100644 --- a/src/intel/compiler/brw_vec4.cpp +++ b/src/intel/compiler/brw_vec4.cpp @@ -1296,7 +1296,8 @@ vec4_visitor::opt_register_coalesce() /* Can't coalesce this GRF if someone else was going to * read it later. */ - if (var_range_end(var_from_reg(alloc, dst_reg(inst->src[0])), 8) > ip) + if (live_intervals->var_range_end( + var_from_reg(alloc, dst_reg(inst->src[0])), 8) > ip) continue; /* We need to check interference with the final destination between this diff --git a/src/intel/compiler/brw_vec4.h b/src/intel/compiler/brw_vec4.h index 606c31da833..b5d3fb1b0cd 100644 --- a/src/intel/compiler/brw_vec4.h +++ b/src/intel/compiler/brw_vec4.h @@ -105,8 +105,6 @@ public: int first_non_payload_grf; unsigned int max_grf; - int *virtual_grf_start; - int *virtual_grf_end; brw::vec4_live_variables *live_intervals; bool need_all_constants_in_pull_buffer; @@ -143,9 +141,6 @@ public: bool opt_vector_float(); bool opt_reduce_swizzle(); bool dead_code_eliminate(); - int var_range_start(unsigned v, unsigned n) const; - int var_range_end(unsigned v, unsigned n) const; - bool virtual_grf_interferes(int a, int b) const; bool opt_cmod_propagation(); bool opt_copy_propagation(bool do_constant_prop = true); bool opt_cse_local(bblock_t *block); diff --git a/src/intel/compiler/brw_vec4_cse.cpp b/src/intel/compiler/brw_vec4_cse.cpp index 2a4217249e8..c7d55788f00 100644 --- a/src/intel/compiler/brw_vec4_cse.cpp +++ b/src/intel/compiler/brw_vec4_cse.cpp @@ -288,7 +288,8 @@ vec4_visitor::opt_cse_local(bblock_t *block) * more -- a sure sign they'll fail operands_match(). */ if (src->file == VGRF) { - if (var_range_end(var_from_reg(alloc, dst_reg(*src)), 8) < ip) { + if (live_intervals->var_range_end( + var_from_reg(alloc, *src), 8) < ip) { entry->remove(); ralloc_free(entry); break; diff --git a/src/intel/compiler/brw_vec4_live_variables.cpp b/src/intel/compiler/brw_vec4_live_variables.cpp index 77d685647c4..61afa98276f 100644 --- a/src/intel/compiler/brw_vec4_live_variables.cpp +++ b/src/intel/compiler/brw_vec4_live_variables.cpp @@ -219,8 +219,7 @@ vec4_live_variables::~vec4_live_variables() * We could expose per-channel live intervals to the consumer based on the * information we computed in vec4_live_variables, except that our only * current user is virtual_grf_interferes(). So we instead union the - * per-channel ranges into a per-vgrf range for virtual_grf_start[] and - * virtual_grf_end[]. + * per-channel ranges into a per-vgrf range for vgrf_start[] and vgrf_end[]. * * We could potentially have virtual_grf_interferes() do the test per-channel, * which would let some interesting register allocation occur (particularly on @@ -238,10 +237,6 @@ vec4_visitor::calculate_live_intervals() int *start = ralloc_array(mem_ctx, int, this->alloc.total_size * 8); int *end = ralloc_array(mem_ctx, int, this->alloc.total_size * 8); - ralloc_free(this->virtual_grf_start); - ralloc_free(this->virtual_grf_end); - this->virtual_grf_start = start; - this->virtual_grf_end = end; for (unsigned i = 0; i < this->alloc.total_size * 8; i++) { start[i] = MAX_INSTRUCTION; @@ -286,6 +281,11 @@ vec4_visitor::calculate_live_intervals() * this point we're distilling it down to vgrfs. */ this->live_intervals = new(mem_ctx) vec4_live_variables(alloc, cfg); + /* XXX -- This belongs in the constructor of vec4_live_variables, will be + * cleaned up later. + */ + this->live_intervals->start = start; + this->live_intervals->end = end; foreach_block (block, cfg) { const struct vec4_live_variables::block_data *bd = @@ -308,34 +308,39 @@ vec4_visitor::calculate_live_intervals() void vec4_visitor::invalidate_live_intervals() { + /* XXX -- This belongs in the destructor of vec4_live_variables, will be + * cleaned up later. + */ + ralloc_free(live_intervals->start); + ralloc_free(live_intervals->end); ralloc_free(live_intervals); live_intervals = NULL; } int -vec4_visitor::var_range_start(unsigned v, unsigned n) const +vec4_live_variables::var_range_start(unsigned v, unsigned n) const { - int start = INT_MAX; + int ip = INT_MAX; for (unsigned i = 0; i < n; i++) - start = MIN2(start, virtual_grf_start[v + i]); + ip = MIN2(ip, start[v + i]); - return start; + return ip; } int -vec4_visitor::var_range_end(unsigned v, unsigned n) const +vec4_live_variables::var_range_end(unsigned v, unsigned n) const { - int end = INT_MIN; + int ip = INT_MIN; for (unsigned i = 0; i < n; i++) - end = MAX2(end, virtual_grf_end[v + i]); + ip = MAX2(ip, end[v + i]); - return end; + return ip; } bool -vec4_visitor::virtual_grf_interferes(int a, int b) const +vec4_live_variables::vgrfs_interfere(int a, int b) const { return !((var_range_end(8 * alloc.offsets[a], 8 * alloc.sizes[a]) <= var_range_start(8 * alloc.offsets[b], 8 * alloc.sizes[b])) || diff --git a/src/intel/compiler/brw_vec4_live_variables.h b/src/intel/compiler/brw_vec4_live_variables.h index 16eb258d7b4..8d89a77cf04 100644 --- a/src/intel/compiler/brw_vec4_live_variables.h +++ b/src/intel/compiler/brw_vec4_live_variables.h @@ -72,6 +72,17 @@ public: /** Per-basic-block information on live variables */ struct block_data *block_data; + /** @{ + * Final computed live ranges for each variable. + */ + int *start; + int *end; + /** @} */ + + int var_range_start(unsigned v, unsigned n) const; + int var_range_end(unsigned v, unsigned n) const; + bool vgrfs_interfere(int a, int b) const; + protected: void setup_def_use(); void compute_live_variables(); diff --git a/src/intel/compiler/brw_vec4_reg_allocate.cpp b/src/intel/compiler/brw_vec4_reg_allocate.cpp index 4e4f3431c6d..bb1cf371329 100644 --- a/src/intel/compiler/brw_vec4_reg_allocate.cpp +++ b/src/intel/compiler/brw_vec4_reg_allocate.cpp @@ -215,7 +215,7 @@ vec4_visitor::reg_allocate() ra_set_node_class(g, i, compiler->vec4_reg_set.classes[size - 1]); for (unsigned j = 0; j < i; j++) { - if (virtual_grf_interferes(i, j)) { + if (live_intervals->vgrfs_interfere(i, j)) { ra_add_node_interference(g, i, j); } } diff --git a/src/intel/compiler/brw_vec4_visitor.cpp b/src/intel/compiler/brw_vec4_visitor.cpp index 3b60ddf9573..29a558d07d9 100644 --- a/src/intel/compiler/brw_vec4_visitor.cpp +++ b/src/intel/compiler/brw_vec4_visitor.cpp @@ -1854,8 +1854,6 @@ vec4_visitor::vec4_visitor(const struct brw_compiler *compiler, memset(this->output_num_components, 0, sizeof(this->output_num_components)); - this->virtual_grf_start = NULL; - this->virtual_grf_end = NULL; this->live_intervals = NULL; this->max_grf = devinfo->gen >= 7 ? GEN7_MRF_HACK_START : BRW_MAX_GRF; -- 2.30.2