[Mesa-dev] [PATCH 22/30] i965/vec4: Add live interval validation pass.

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


This could be improved somewhat with additional validation of the
calculated live in/out sets and by checking that the calculated live
intervals are minimal (which isn't strictly necessary to guarantee the
correctness of the program).  This should be good enough though to
catch accidental use of stale liveness results due to missing or
incorrect analysis invalidation.
---
 .../drivers/dri/i965/brw_vec4_live_variables.cpp   | 43 ++++++++++++++++++++++
 .../drivers/dri/i965/brw_vec4_live_variables.h     |  3 ++
 2 files changed, 46 insertions(+)

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 297d027..a7c991f 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4_live_variables.cpp
+++ b/src/mesa/drivers/dri/i965/brw_vec4_live_variables.cpp
@@ -294,6 +294,49 @@ vec4_visitor::invalidate_live_intervals()
    live_intervals = NULL;
 }
 
+static bool
+check_register_live_range(const vec4_live_variables *live, int ip,
+                          unsigned var, unsigned n)
+{
+   for (unsigned j = 0; j < n; j += 4) {
+      if (var + j >= unsigned(live->num_vars) ||
+          live->start[var + j] > ip || live->end[var + j] < ip)
+         return false;
+   }
+
+   return true;
+}
+
+bool
+vec4_live_variables::validate(const backend_shader *s) const
+{
+   unsigned ip = 0;
+
+   foreach_block_and_inst(block, vec4_instruction, inst, s->cfg) {
+      for (unsigned c = 0; c < 4; c++) {
+         if (inst->dst.writemask & (1 << c)) {
+            for (unsigned i = 0; i < 3; i++) {
+               if (inst->src[i].file == VGRF &&
+                   !check_register_live_range(this, ip,
+                                              var_from_reg(alloc, inst->src[i], c),
+                                              inst->regs_read(i)))
+                  return false;
+            }
+
+            if (inst->dst.file == VGRF &&
+                !check_register_live_range(this, ip,
+                                           var_from_reg(alloc, inst->dst, c),
+                                           inst->regs_written))
+               return false;
+         }
+      }
+
+      ip++;
+   }
+
+   return true;
+}
+
 int
 vec4_live_variables::var_range_start(unsigned v, unsigned n) const
 {
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 7384f04..f6cefa0 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4_live_variables.h
+++ b/src/mesa/drivers/dri/i965/brw_vec4_live_variables.h
@@ -68,6 +68,9 @@ public:
    vec4_live_variables(const backend_shader *s);
    ~vec4_live_variables();
 
+   bool
+   validate(const backend_shader *s) const;
+
    int num_vars;
    int bitset_words;
 
-- 
2.7.0



More information about the mesa-dev mailing list