From 24535604aa645651987e41a3bce8eee9e0b871bd Mon Sep 17 00:00:00 2001 From: Francisco Jerez Date: Wed, 9 Mar 2016 22:41:31 -0800 Subject: [PATCH] intel/compiler/fs: Add live interval validation pass 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. Reviewed-by: Matt Turner Part-of: --- src/intel/compiler/brw_fs_live_variables.cpp | 41 ++++++++++++++++++++ src/intel/compiler/brw_fs_live_variables.h | 2 + 2 files changed, 43 insertions(+) diff --git a/src/intel/compiler/brw_fs_live_variables.cpp b/src/intel/compiler/brw_fs_live_variables.cpp index 8554296f230..6debf50be8f 100644 --- a/src/intel/compiler/brw_fs_live_variables.cpp +++ b/src/intel/compiler/brw_fs_live_variables.cpp @@ -323,6 +323,47 @@ fs_live_variables::~fs_live_variables() ralloc_free(mem_ctx); } +static bool +check_register_live_range(const fs_live_variables *live, int ip, + const fs_reg ®, unsigned n) +{ + const unsigned var = live->var_from_reg(reg); + + if (var + n > unsigned(live->num_vars) || + live->vgrf_start[reg.nr] > ip || live->vgrf_end[reg.nr] < ip) + return false; + + for (unsigned j = 0; j < n; j++) { + if (live->start[var + j] > ip || live->end[var + j] < ip) + return false; + } + + return true; +} + +bool +fs_live_variables::validate(const backend_shader *s) const +{ + int ip = 0; + + foreach_block_and_inst(block, fs_inst, inst, s->cfg) { + for (unsigned i = 0; i < inst->sources; i++) { + if (inst->src[i].file == VGRF && + !check_register_live_range(this, ip, + inst->src[i], regs_read(inst, i))) + return false; + } + + if (inst->dst.file == VGRF && + !check_register_live_range(this, ip, inst->dst, regs_written(inst))) + return false; + + ip++; + } + + return true; +} + void fs_visitor::invalidate_live_intervals() { diff --git a/src/intel/compiler/brw_fs_live_variables.h b/src/intel/compiler/brw_fs_live_variables.h index 9d59620aed5..ba2e841f1cc 100644 --- a/src/intel/compiler/brw_fs_live_variables.h +++ b/src/intel/compiler/brw_fs_live_variables.h @@ -81,6 +81,8 @@ public: fs_live_variables(const backend_shader *s); ~fs_live_variables(); + bool validate(const backend_shader *s) const; + bool vars_interfere(int a, int b) const; bool vgrfs_interfere(int a, int b) const; int var_from_reg(const fs_reg ®) const -- 2.30.2