From 08da7edc0e7ca0404d5c412ad70d17c5553b5991 Mon Sep 17 00:00:00 2001 From: Caio Oliveira Date: Fri, 12 Jan 2024 11:49:11 -0800 Subject: [PATCH] intel/brw: Track the number of uses of each def in def_analysis Even without a full use list, simply tracking the number of uses will let us tell "this is the only use of the def" or "we've just replaced all uses of a def". It's inexpensive to calculate and will be useful. (rebased by Kenneth Graunke) Reviewed-by: Kenneth Graunke Part-of: --- src/intel/compiler/brw_def_analysis.cpp | 8 ++++++-- src/intel/compiler/brw_fs.h | 8 ++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/intel/compiler/brw_def_analysis.cpp b/src/intel/compiler/brw_def_analysis.cpp index e8c877d2669..60074c69ad6 100644 --- a/src/intel/compiler/brw_def_analysis.cpp +++ b/src/intel/compiler/brw_def_analysis.cpp @@ -73,6 +73,8 @@ def_analysis::update_for_reads(const idom_tree &idom, continue; } + def_use_counts[nr]++; + if (def_insts[nr]) { /* Mark the source def invalid in two cases: * @@ -130,8 +132,9 @@ def_analysis::def_analysis(const fs_visitor *v) def_count = v->alloc.count; - def_insts = new fs_inst*[def_count](); - def_blocks = new bblock_t*[def_count](); + def_insts = new fs_inst*[def_count](); + def_blocks = new bblock_t*[def_count](); + def_use_counts = new uint32_t[def_count](); for (unsigned i = 0; i < def_count; i++) def_insts[i] = UNSEEN; @@ -177,6 +180,7 @@ def_analysis::~def_analysis() { delete[] def_insts; delete[] def_blocks; + delete[] def_use_counts; } bool diff --git a/src/intel/compiler/brw_fs.h b/src/intel/compiler/brw_fs.h index a5150192204..7d4e0019cb2 100644 --- a/src/intel/compiler/brw_fs.h +++ b/src/intel/compiler/brw_fs.h @@ -89,6 +89,13 @@ namespace brw { def_blocks[reg.nr] : NULL; } + uint32_t + get_use_count(const fs_reg ®) const + { + return reg.file == VGRF && reg.nr < def_count ? + def_use_counts[reg.nr] : 0; + } + unsigned count() const { return def_count; } void print_stats(const fs_visitor *) const; @@ -112,6 +119,7 @@ namespace brw { fs_inst **def_insts; bblock_t **def_blocks; + uint32_t *def_use_counts; unsigned def_count; }; }