OSDN Git Service

i965/vec4: Define helper functions to convert a register to a variable index.
authorFrancisco Jerez <currojerez@riseup.net>
Wed, 18 Mar 2015 18:17:23 +0000 (20:17 +0200)
committerFrancisco Jerez <currojerez@riseup.net>
Mon, 23 Mar 2015 12:13:05 +0000 (14:13 +0200)
Reviewed-by: Matt Turner <mattst88@gmail.com>
src/mesa/drivers/dri/i965/brw_vec4_cse.cpp
src/mesa/drivers/dri/i965/brw_vec4_dead_code_eliminate.cpp
src/mesa/drivers/dri/i965/brw_vec4_live_variables.cpp
src/mesa/drivers/dri/i965/brw_vec4_live_variables.h

index 31c01d6..489248e 100644 (file)
@@ -22,6 +22,7 @@
  */
 
 #include "brw_vec4.h"
+#include "brw_vec4_live_variables.h"
 #include "brw_cfg.h"
 
 using namespace brw;
index 9604e60..e4ce496 100644 (file)
@@ -81,8 +81,7 @@ vec4_visitor::dead_code_eliminate()
             bool result_live[4] = { false };
 
             for (int c = 0; c < 4; c++) {
-               int var = inst->dst.reg * 4 + c;
-               result_live[c] = BITSET_TEST(live, var);
+               result_live[c] = BITSET_TEST(live, var_from_reg(alloc, inst->dst, c));
             }
 
             /* If the instruction can't do writemasking, then it's all or
@@ -125,8 +124,7 @@ vec4_visitor::dead_code_eliminate()
          if (inst->dst.file == GRF && !inst->predicate) {
             for (int c = 0; c < 4; c++) {
                if (inst->dst.writemask & (1 << c)) {
-                  int var = inst->dst.reg * 4 + c;
-                  BITSET_CLEAR(live, var);
+                  BITSET_CLEAR(live, var_from_reg(alloc, inst->dst, c));
                }
             }
          }
@@ -138,10 +136,7 @@ vec4_visitor::dead_code_eliminate()
          for (int i = 0; i < 3; i++) {
             if (inst->src[i].file == GRF) {
                for (int c = 0; c < 4; c++) {
-                  int swiz = BRW_GET_SWZ(inst->src[i].swizzle, c);
-                  int var = inst->src[i].reg * 4 + swiz;
-
-                  BITSET_SET(live, var);
+                  BITSET_SET(live, var_from_reg(alloc, inst->src[i], c));
                }
             }
          }
index 022661d..5b2e13c 100644 (file)
@@ -76,12 +76,10 @@ 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) {
-              int reg = inst->src[i].reg;
-
-               for (int j = 0; j < 4; j++) {
-                  int c = BRW_GET_SWZ(inst->src[i].swizzle, j);
-                  if (!BITSET_TEST(bd->def, reg * 4 + c))
-                     BITSET_SET(bd->use, reg * 4 + c);
+               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);
                }
            }
         }
@@ -100,9 +98,9 @@ vec4_live_variables::setup_def_use()
             !inst->predicate) {
             for (int c = 0; c < 4; c++) {
                if (inst->dst.writemask & (1 << c)) {
-                  int reg = inst->dst.reg;
-                  if (!BITSET_TEST(bd->use, reg * 4 + c))
-                     BITSET_SET(bd->def, reg * 4 + c);
+                  const unsigned v = var_from_reg(alloc, inst->dst, c);
+                  if (!BITSET_TEST(bd->use, v))
+                     BITSET_SET(bd->def, v);
                }
             }
          }
@@ -250,24 +248,20 @@ 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) {
-           int reg = inst->src[i].reg;
-
-            for (int j = 0; j < 4; j++) {
-               int c = BRW_GET_SWZ(inst->src[i].swizzle, j);
-
-               start[reg * 4 + c] = MIN2(start[reg * 4 + c], ip);
-               end[reg * 4 + c] = ip;
+            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;
             }
         }
       }
 
       if (inst->dst.file == GRF) {
-         int reg = inst->dst.reg;
-
          for (int c = 0; c < 4; c++) {
             if (inst->dst.writemask & (1 << c)) {
-               start[reg * 4 + c] = MIN2(start[reg * 4 + c], ip);
-               end[reg * 4 + c] = ip;
+               const unsigned v = var_from_reg(alloc, inst->dst, c);
+               start[v] = MIN2(start[v], ip);
+               end[v] = ip;
             }
          }
       }
index c5c6ff3..cef55f7 100644 (file)
@@ -78,4 +78,20 @@ protected:
    void *mem_ctx;
 };
 
+inline unsigned
+var_from_reg(const simple_allocator &alloc, const src_reg &reg,
+             unsigned c = 0)
+{
+   assert(reg.file == GRF && reg.reg < alloc.count && c < 4);
+   return 4 * reg.reg + BRW_GET_SWZ(reg.swizzle, c);
+}
+
+inline unsigned
+var_from_reg(const simple_allocator &alloc, const dst_reg &reg,
+             unsigned c = 0)
+{
+   assert(reg.file == GRF && reg.reg < alloc.count && c < 4);
+   return 4 * reg.reg + c;
+}
+
 } /* namespace brw */