[Mesa-dev] [PATCH 16/30] i965/fs: Move all live interval analysis results into fs_live_variables.

Francisco Jerez currojerez at riseup.net
Mon Mar 14 03:47:20 UTC 2016


This moves the following methods that are currently defined in
fs_visitor (even though they are side products of the liveness
analysis computation) and are already implemented in
brw_fs_live_variables.cpp:

> 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 fs_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.

This shortens the virtual_grf prefix in order to compensate for the
slightly increased lexical overhead from the live_intervals pointer
dereference.
---
 src/mesa/drivers/dri/i965/brw_fs.cpp               |  5 +--
 src/mesa/drivers/dri/i965/brw_fs.h                 |  3 --
 src/mesa/drivers/dri/i965/brw_fs_cse.cpp           |  3 +-
 .../drivers/dri/i965/brw_fs_live_variables.cpp     | 40 +++++++++-------------
 src/mesa/drivers/dri/i965/brw_fs_live_variables.h  |  8 +++++
 src/mesa/drivers/dri/i965/brw_fs_reg_allocate.cpp  |  4 +--
 src/mesa/drivers/dri/i965/brw_fs_visitor.cpp       |  2 --
 .../drivers/dri/i965/brw_schedule_instructions.cpp |  4 +--
 8 files changed, 34 insertions(+), 35 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp b/src/mesa/drivers/dri/i965/brw_fs.cpp
index 9183d1f..afa1db9 100644
--- a/src/mesa/drivers/dri/i965/brw_fs.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs.cpp
@@ -2627,7 +2627,7 @@ fs_visitor::compute_to_mrf()
       /* Can't compute-to-MRF this GRF if someone else was going to
        * read it later.
        */
-      if (this->virtual_grf_end[inst->src[0].nr] > ip)
+      if (live_intervals->vgrf_end[inst->src[0].nr] > ip)
 	 continue;
 
       /* Found a move of a GRF to a MRF.  Let's see if we can go
@@ -5074,7 +5074,8 @@ fs_visitor::calculate_register_pressure()
    regs_live_at_ip = rzalloc_array(mem_ctx, int, num_instructions);
 
    for (unsigned reg = 0; reg < alloc.count; reg++) {
-      for (int ip = virtual_grf_start[reg]; ip <= virtual_grf_end[reg]; ip++)
+      for (int ip = live_intervals->vgrf_start[reg];
+           ip <= live_intervals->vgrf_end[reg]; ip++)
          regs_live_at_ip[ip] += alloc.sizes[reg];
    }
 }
diff --git a/src/mesa/drivers/dri/i965/brw_fs.h b/src/mesa/drivers/dri/i965/brw_fs.h
index 4f5d085..82d5d63 100644
--- a/src/mesa/drivers/dri/i965/brw_fs.h
+++ b/src/mesa/drivers/dri/i965/brw_fs.h
@@ -162,7 +162,6 @@ public:
    bool remove_duplicate_mrf_writes();
 
    bool opt_sampler_eot();
-   bool virtual_grf_interferes(int a, int b) const;
    void schedule_instructions(instruction_scheduler_mode mode);
    void insert_gen4_send_dependency_workarounds();
    void insert_gen4_pre_send_dependency_workarounds(bblock_t *block,
@@ -329,8 +328,6 @@ public:
 
    int *param_size;
 
-   int *virtual_grf_start;
-   int *virtual_grf_end;
    brw::fs_live_variables *live_intervals;
 
    int *regs_live_at_ip;
diff --git a/src/mesa/drivers/dri/i965/brw_fs_cse.cpp b/src/mesa/drivers/dri/i965/brw_fs_cse.cpp
index a484caf..d112378 100644
--- a/src/mesa/drivers/dri/i965/brw_fs_cse.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs_cse.cpp
@@ -328,7 +328,8 @@ fs_visitor::opt_cse_local(bblock_t *block)
             /* Kill any AEB entries using registers that don't get reused any
              * more -- a sure sign they'll fail operands_match().
              */
-            if (src_reg->file == VGRF && virtual_grf_end[src_reg->nr] < ip) {
+            if (src_reg->file == VGRF &&
+                live_intervals->vgrf_end[src_reg->nr] < ip) {
                entry->remove();
                ralloc_free(entry);
                break;
diff --git a/src/mesa/drivers/dri/i965/brw_fs_live_variables.cpp b/src/mesa/drivers/dri/i965/brw_fs_live_variables.cpp
index 676619a..6da026e 100644
--- a/src/mesa/drivers/dri/i965/brw_fs_live_variables.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs_live_variables.cpp
@@ -265,6 +265,13 @@ fs_live_variables::fs_live_variables(fs_visitor *v, const cfg_t *cfg)
       end[i] = -1;
    }
 
+   vgrf_start = ralloc_array(mem_ctx, int, num_vgrfs);
+   vgrf_end = ralloc_array(mem_ctx, int, num_vgrfs);
+   for (int i = 0; i < num_vgrfs; i++) {
+      vgrf_start[i] = MAX_INSTRUCTION;
+      vgrf_end[i] = -1;
+   }
+
    block_data= rzalloc_array(mem_ctx, struct block_data, cfg->num_blocks);
 
    bitset_words = BITSET_WORDS(num_vars);
@@ -283,6 +290,13 @@ fs_live_variables::fs_live_variables(fs_visitor *v, const cfg_t *cfg)
    setup_def_use();
    compute_live_variables();
    compute_start_end();
+
+   /* Merge the per-component live ranges to whole VGRF live ranges. */
+   for (int i = 0; i < num_vars; i++) {
+      const unsigned vgrf = vgrf_from_var[i];
+      vgrf_start[vgrf] = MIN2(vgrf_start[vgrf], start[i]);
+      vgrf_end[vgrf] = MAX2(vgrf_end[vgrf], end[i]);
+   }
 }
 
 fs_live_variables::~fs_live_variables()
@@ -309,27 +323,7 @@ fs_visitor::calculate_live_intervals()
    if (this->live_intervals)
       return;
 
-   int num_vgrfs = this->alloc.count;
-   ralloc_free(this->virtual_grf_start);
-   ralloc_free(this->virtual_grf_end);
-   virtual_grf_start = ralloc_array(mem_ctx, int, num_vgrfs);
-   virtual_grf_end = ralloc_array(mem_ctx, int, num_vgrfs);
-
-   for (int i = 0; i < num_vgrfs; i++) {
-      virtual_grf_start[i] = MAX_INSTRUCTION;
-      virtual_grf_end[i] = -1;
-   }
-
    this->live_intervals = new(mem_ctx) fs_live_variables(this, cfg);
-
-   /* Merge the per-component live ranges to whole VGRF live ranges. */
-   for (int i = 0; i < live_intervals->num_vars; i++) {
-      int vgrf = live_intervals->vgrf_from_var[i];
-      virtual_grf_start[vgrf] = MIN2(virtual_grf_start[vgrf],
-                                     live_intervals->start[i]);
-      virtual_grf_end[vgrf] = MAX2(virtual_grf_end[vgrf],
-                                   live_intervals->end[i]);
-   }
 }
 
 bool
@@ -340,8 +334,8 @@ fs_live_variables::vars_interfere(int a, int b) const
 }
 
 bool
-fs_visitor::virtual_grf_interferes(int a, int b) const
+fs_live_variables::vgrfs_interfere(int a, int b) const
 {
-   return !(virtual_grf_end[a] <= virtual_grf_start[b] ||
-            virtual_grf_end[b] <= virtual_grf_start[a]);
+   return !(vgrf_end[a] <= vgrf_start[b] ||
+            vgrf_end[b] <= vgrf_start[a]);
 }
diff --git a/src/mesa/drivers/dri/i965/brw_fs_live_variables.h b/src/mesa/drivers/dri/i965/brw_fs_live_variables.h
index fb5aee7..c0943c7 100644
--- a/src/mesa/drivers/dri/i965/brw_fs_live_variables.h
+++ b/src/mesa/drivers/dri/i965/brw_fs_live_variables.h
@@ -70,6 +70,7 @@ public:
    ~fs_live_variables();
 
    bool vars_interfere(int a, int b) const;
+   bool vgrfs_interfere(int a, int b) const;
    int var_from_reg(const fs_reg &reg) const
    {
       return var_from_vgrf[reg.nr] + reg.reg_offset;
@@ -98,6 +99,13 @@ public:
    int *end;
    /** @} */
 
+   /** @{
+    * Final computed live ranges for each VGRF.
+    */
+   int *vgrf_start;
+   int *vgrf_end;
+   /** @} */
+
    /** Per-basic-block information on live variables */
    struct block_data *block_data;
 
diff --git a/src/mesa/drivers/dri/i965/brw_fs_reg_allocate.cpp b/src/mesa/drivers/dri/i965/brw_fs_reg_allocate.cpp
index f880206..efb5d6f 100644
--- a/src/mesa/drivers/dri/i965/brw_fs_reg_allocate.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs_reg_allocate.cpp
@@ -446,7 +446,7 @@ fs_visitor::setup_payload_interference(struct ra_graph *g,
           * in order to not have to worry about the uniform issue described in
           * calculate_live_intervals().
           */
-         if (this->virtual_grf_start[j] <= payload_last_use_ip[i]) {
+         if (live_intervals->vgrf_start[j] <= payload_last_use_ip[i]) {
             ra_add_node_interference(g, first_payload_node + i, j);
          }
       }
@@ -591,7 +591,7 @@ fs_visitor::assign_regs(bool allow_spilling)
       ra_set_node_class(g, i, c);
 
       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/mesa/drivers/dri/i965/brw_fs_visitor.cpp b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
index dc61d09..b9fde5d 100644
--- a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
@@ -1049,8 +1049,6 @@ fs_visitor::init()
    this->first_non_payload_grf = 0;
    this->max_grf = devinfo->gen >= 7 ? GEN7_MRF_HACK_START : BRW_MAX_GRF;
 
-   this->virtual_grf_start = NULL;
-   this->virtual_grf_end = NULL;
    this->live_intervals = NULL;
    this->regs_live_at_ip = NULL;
 
diff --git a/src/mesa/drivers/dri/i965/brw_schedule_instructions.cpp b/src/mesa/drivers/dri/i965/brw_schedule_instructions.cpp
index 8f7ee5c..4bcefe5 100644
--- a/src/mesa/drivers/dri/i965/brw_schedule_instructions.cpp
+++ b/src/mesa/drivers/dri/i965/brw_schedule_instructions.cpp
@@ -620,8 +620,8 @@ fs_instruction_scheduler::setup_liveness(cfg_t *cfg)
     */
    for (int block = 0; block < cfg->num_blocks - 1; block++) {
       for (int i = 0; i < grf_count; i++) {
-         if (v->virtual_grf_start[i] <= cfg->blocks[block]->end_ip &&
-             v->virtual_grf_end[i] >= cfg->blocks[block + 1]->start_ip) {
+         if (v->live_intervals->vgrf_start[i] <= cfg->blocks[block]->end_ip &&
+             v->live_intervals->vgrf_end[i] >= cfg->blocks[block + 1]->start_ip) {
             if (!BITSET_TEST(livein[block + 1], i)) {
                 reg_pressure_in[block + 1] += v->alloc.sizes[i];
                 BITSET_SET(livein[block + 1], i);
-- 
2.7.0



More information about the mesa-dev mailing list