[Mesa-dev] [PATCH 10/11] i965/vec4: Calculate live intervals with subregister granularity.
Francisco Jerez
currojerez at riseup.net
Fri Mar 20 07:50:45 PDT 2015
---
src/mesa/drivers/dri/i965/brw_vec4.h | 4 +-
.../drivers/dri/i965/brw_vec4_live_variables.cpp | 74 ++++++++++++----------
.../drivers/dri/i965/brw_vec4_live_variables.h | 11 ++--
3 files changed, 51 insertions(+), 38 deletions(-)
diff --git a/src/mesa/drivers/dri/i965/brw_vec4.h b/src/mesa/drivers/dri/i965/brw_vec4.h
index f1b3000..46670a4 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4.h
+++ b/src/mesa/drivers/dri/i965/brw_vec4.h
@@ -201,8 +201,8 @@ public:
bool opt_vector_float();
bool opt_reduce_swizzle();
bool dead_code_eliminate();
- int var_range_start(unsigned var, unsigned n) const;
- int var_range_end(unsigned var, unsigned n) const;
+ 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);
bool opt_copy_propagation(bool do_constant_prop = true);
bool opt_cse_local(bblock_t *block);
diff --git a/src/mesa/drivers/dri/i965/brw_vec4_live_variables.cpp b/src/mesa/drivers/dri/i965/brw_vec4_live_variables.cpp
index 4b87af2..34df61e 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4_live_variables.cpp
+++ b/src/mesa/drivers/dri/i965/brw_vec4_live_variables.cpp
@@ -76,10 +76,13 @@ vec4_live_variables::setup_def_use()
/* Set use[] for this instruction */
for (unsigned int i = 0; i < 3; i++) {
if (inst->src[i].file == GRF) {
- for (int c = 0; c < 4; c++) {
- const unsigned v = var_from_reg(alloc, inst->src[i], c);
- if (!BITSET_TEST(bd->def, v))
- BITSET_SET(bd->use, v);
+ for (unsigned j = 0; j < inst->regs_read(i); j++) {
+ for (int c = 0; c < 4; c++) {
+ const unsigned v =
+ var_from_reg(alloc, offset(inst->src[i], j), c);
+ if (!BITSET_TEST(bd->def, v))
+ BITSET_SET(bd->use, v);
+ }
}
}
}
@@ -93,14 +96,15 @@ vec4_live_variables::setup_def_use()
* are the things that screen off preceding definitions of a
* variable, and thus qualify for being in def[].
*/
- if (inst->dst.file == GRF &&
- alloc.sizes[inst->dst.reg] == 1 &&
- !inst->predicate) {
- for (int c = 0; c < 4; c++) {
- if (inst->dst.writemask & (1 << c)) {
- const unsigned v = var_from_reg(alloc, inst->dst, c);
- if (!BITSET_TEST(bd->use, v))
- BITSET_SET(bd->def, v);
+ if (inst->dst.file == GRF && !inst->predicate) {
+ for (unsigned i = 0; i < inst->regs_written; i++) {
+ for (int c = 0; c < 4; c++) {
+ if (inst->dst.writemask & (1 << c)) {
+ const unsigned v =
+ var_from_reg(alloc, offset(inst->dst, i), c);
+ if (!BITSET_TEST(bd->use, v))
+ BITSET_SET(bd->def, v);
+ }
}
}
}
@@ -179,7 +183,7 @@ vec4_live_variables::vec4_live_variables(const simple_allocator &alloc,
{
mem_ctx = ralloc_context(NULL);
- num_vars = alloc.count * 4;
+ num_vars = alloc.total_size * 4;
block_data = rzalloc_array(mem_ctx, struct block_data, cfg->num_blocks);
bitset_words = BITSET_WORDS(num_vars);
@@ -229,14 +233,14 @@ vec4_visitor::calculate_live_intervals()
if (this->live_intervals)
return;
- int *start = ralloc_array(mem_ctx, int, this->alloc.count * 4);
- int *end = ralloc_array(mem_ctx, int, this->alloc.count * 4);
+ int *start = ralloc_array(mem_ctx, int, this->alloc.total_size * 4);
+ int *end = ralloc_array(mem_ctx, int, this->alloc.total_size * 4);
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.count * 4; i++) {
+ for (unsigned i = 0; i < this->alloc.total_size * 4; i++) {
start[i] = MAX_INSTRUCTION;
end[i] = -1;
}
@@ -248,20 +252,26 @@ vec4_visitor::calculate_live_intervals()
foreach_block_and_inst(block, vec4_instruction, inst, cfg) {
for (unsigned int i = 0; i < 3; i++) {
if (inst->src[i].file == GRF) {
- for (int c = 0; c < 4; c++) {
- const unsigned v = var_from_reg(alloc, inst->src[i], c);
- start[v] = MIN2(start[v], ip);
- end[v] = ip;
+ for (unsigned j = 0; j < inst->regs_read(i); j++) {
+ for (int c = 0; c < 4; c++) {
+ const unsigned v =
+ var_from_reg(alloc, offset(inst->src[i], j), c);
+ start[v] = MIN2(start[v], ip);
+ end[v] = ip;
+ }
}
}
}
if (inst->dst.file == GRF) {
- for (int c = 0; c < 4; c++) {
- if (inst->dst.writemask & (1 << c)) {
- const unsigned v = var_from_reg(alloc, inst->dst, c);
- start[v] = MIN2(start[v], ip);
- end[v] = ip;
+ for (unsigned i = 0; i < inst->regs_written; i++) {
+ for (int c = 0; c < 4; c++) {
+ if (inst->dst.writemask & (1 << c)) {
+ const unsigned v =
+ var_from_reg(alloc, offset(inst->dst, i), c);
+ start[v] = MIN2(start[v], ip);
+ end[v] = ip;
+ }
}
}
}
@@ -301,7 +311,7 @@ vec4_visitor::invalidate_live_intervals()
}
int
-vec4_visitor::var_range_start(unsigned var, unsigned n) const
+vec4_visitor::var_range_start(unsigned v, unsigned n) const
{
int start = INT_MAX;
@@ -312,12 +322,12 @@ vec4_visitor::var_range_start(unsigned var, unsigned n) const
}
int
-vec4_visitor::var_range_end(unsigned var, unsigned n) const
+vec4_visitor::var_range_end(unsigned v, unsigned n) const
{
int end = INT_MIN;
for (unsigned i = 0; i < n; ++i)
- end = MAX2(end, virtual_grf_end[var + i]);
+ end = MAX2(end, virtual_grf_end[v + i]);
return end;
}
@@ -325,8 +335,8 @@ vec4_visitor::var_range_end(unsigned var, unsigned n) const
bool
vec4_visitor::virtual_grf_interferes(int a, int b)
{
- return !((virtual_grf_range_end(4 * a, 4) <=
- virtual_grf_range_start(4 * b, 4)) ||
- (virtual_grf_range_end(4 * b, 4) <=
- virtual_grf_range_start(4 * a, 4)));
+ return !((var_range_end(4 * alloc.offsets[a], 4 * alloc.sizes[a]) <=
+ var_range_start(4 * alloc.offsets[b], 4 * alloc.sizes[b])) ||
+ (var_range_end(4 * alloc.offsets[b], 4 * alloc.sizes[b]) <=
+ var_range_start(4 * alloc.offsets[a], 4 * alloc.sizes[a])));
}
diff --git a/src/mesa/drivers/dri/i965/brw_vec4_live_variables.h b/src/mesa/drivers/dri/i965/brw_vec4_live_variables.h
index cef55f7..e7929ec 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4_live_variables.h
+++ b/src/mesa/drivers/dri/i965/brw_vec4_live_variables.h
@@ -82,16 +82,19 @@ inline unsigned
var_from_reg(const simple_allocator &alloc, const src_reg ®,
unsigned c = 0)
{
- assert(reg.file == GRF && reg.reg < alloc.count && c < 4);
- return 4 * reg.reg + BRW_GET_SWZ(reg.swizzle, c);
+ assert(reg.file == GRF && reg.reg < alloc.count &&
+ reg.reg_offset < alloc.sizes[reg.reg] && c < 4);
+ return (4 * (alloc.offsets[reg.reg] + reg.reg_offset) +
+ BRW_GET_SWZ(reg.swizzle, c));
}
inline unsigned
var_from_reg(const simple_allocator &alloc, const dst_reg ®,
unsigned c = 0)
{
- assert(reg.file == GRF && reg.reg < alloc.count && c < 4);
- return 4 * reg.reg + c;
+ assert(reg.file == GRF && reg.reg < alloc.count &&
+ reg.reg_offset < alloc.sizes[reg.reg] && c < 4);
+ return 4 * (alloc.offsets[reg.reg] + reg.reg_offset) + c;
}
} /* namespace brw */
--
2.1.3
More information about the mesa-dev
mailing list