i965/vec4: Define helpers to calculate the common live interval of a range of variables.
authorFrancisco Jerez <currojerez@riseup.net>
Wed, 18 Mar 2015 18:49:43 +0000 (20:49 +0200)
committerFrancisco Jerez <currojerez@riseup.net>
Mon, 23 Mar 2015 12:52:49 +0000 (14:52 +0200)
These will be especially useful when we start keeping track of
liveness information for each subregister.

Reviewed-by: Matt Turner <mattst88@gmail.com>
src/mesa/drivers/dri/i965/brw_vec4.cpp
src/mesa/drivers/dri/i965/brw_vec4.h
src/mesa/drivers/dri/i965/brw_vec4_cse.cpp
src/mesa/drivers/dri/i965/brw_vec4_live_variables.cpp

index 2c4a3d6f2daf84c3e445404a30ff5f448168f448..918519c93948b4a0366d4d446973c23f1f5ef652 100644 (file)
@@ -25,6 +25,7 @@
 #include "brw_fs.h"
 #include "brw_cfg.h"
 #include "brw_vs.h"
+#include "brw_vec4_live_variables.h"
 #include "brw_dead_control_flow.h"
 
 extern "C" {
@@ -981,10 +982,7 @@ vec4_visitor::opt_register_coalesce()
       /* Can't coalesce this GRF if someone else was going to
        * read it later.
        */
-      if (this->virtual_grf_end[inst->src[0].reg * 4 + 0] > ip ||
-          this->virtual_grf_end[inst->src[0].reg * 4 + 1] > ip ||
-          this->virtual_grf_end[inst->src[0].reg * 4 + 2] > ip ||
-          this->virtual_grf_end[inst->src[0].reg * 4 + 3] > ip)
+      if (var_range_end(var_from_reg(alloc, inst->src[0]), 4) > ip)
         continue;
 
       /* We need to check interference with the final destination between this
index 2fd2f29c4beb3533d1ae8744108799040a1b6c78..33297aea827d258ed1749f519b7c3e454ffd31e6 100644 (file)
@@ -201,6 +201,8 @@ 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);
    bool opt_copy_propagation(bool do_constant_prop = true);
    bool opt_cse_local(bblock_t *block);
index 489248ee351cc493b8e3cc71335416a2232c3622..100e511a56c84b02b47e4bfa5a41ab9117dee3c0 100644 (file)
@@ -232,13 +232,7 @@ vec4_visitor::opt_cse_local(bblock_t *block)
              * more -- a sure sign they'll fail operands_match().
              */
             if (src->file == GRF) {
-               assert((unsigned)(src->reg * 4 + 3) < (alloc.count * 4));
-
-               int last_reg_use = MAX2(MAX2(virtual_grf_end[src->reg * 4 + 0],
-                                            virtual_grf_end[src->reg * 4 + 1]),
-                                       MAX2(virtual_grf_end[src->reg * 4 + 2],
-                                            virtual_grf_end[src->reg * 4 + 3]));
-               if (last_reg_use < ip) {
+               if (var_range_end(var_from_reg(alloc, *src), 4) < ip) {
                   entry->remove();
                   ralloc_free(entry);
                   break;
index 5b2e13c144bef79317089c3f9ef339afe290f9a9..66beb21397b7af52265b881bd29d5f51a7e9f52b 100644 (file)
@@ -300,25 +300,33 @@ vec4_visitor::invalidate_live_intervals()
    live_intervals = NULL;
 }
 
+int
+vec4_visitor::var_range_start(unsigned v, unsigned n) const
+{
+   int start = INT_MAX;
+
+   for (unsigned i = 0; i < n; i++)
+      start = MIN2(start, virtual_grf_start[v + i]);
+
+   return start;
+}
+
+int
+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[v + i]);
+
+   return end;
+}
+
 bool
 vec4_visitor::virtual_grf_interferes(int a, int b)
 {
-   int start_a = MIN2(MIN2(virtual_grf_start[a * 4 + 0],
-                           virtual_grf_start[a * 4 + 1]),
-                      MIN2(virtual_grf_start[a * 4 + 2],
-                           virtual_grf_start[a * 4 + 3]));
-   int start_b = MIN2(MIN2(virtual_grf_start[b * 4 + 0],
-                           virtual_grf_start[b * 4 + 1]),
-                      MIN2(virtual_grf_start[b * 4 + 2],
-                           virtual_grf_start[b * 4 + 3]));
-   int end_a = MAX2(MAX2(virtual_grf_end[a * 4 + 0],
-                         virtual_grf_end[a * 4 + 1]),
-                    MAX2(virtual_grf_end[a * 4 + 2],
-                         virtual_grf_end[a * 4 + 3]));
-   int end_b = MAX2(MAX2(virtual_grf_end[b * 4 + 0],
-                         virtual_grf_end[b * 4 + 1]),
-                    MAX2(virtual_grf_end[b * 4 + 2],
-                         virtual_grf_end[b * 4 + 3]));
-   return !(end_a <= start_b ||
-            end_b <= start_a);
+   return !((var_range_end(4 * a, 4) <=
+             var_range_start(4 * b, 4)) ||
+            (var_range_end(4 * b, 4) <=
+             var_range_start(4 * a, 4)));
 }