From 3f71aab327dd7743782e4c053addac2e15becc4c Mon Sep 17 00:00:00 2001 From: Caio Oliveira Date: Fri, 8 May 2026 12:17:29 -0700 Subject: [PATCH] brw: Pass VGRF numbers to liveness helpers Compute var_from_reg() once in setup_def_use() and pass the variable number to setup_one_read() and setup_one_write(). This lets the loops walk consecutive variable numbers directly instead of mutating a brw_reg offset. Also: setup_one_write() is only called for VGRFs, so remove the check for VGRF there. Reviewed-by: Ian Romanick Part-of: --- src/intel/compiler/brw/brw_analysis.h | 5 ++- .../compiler/brw/brw_analysis_liveness.cpp | 33 +++++++------------ 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/src/intel/compiler/brw/brw_analysis.h b/src/intel/compiler/brw/brw_analysis.h index afb9cc0833f..2bb5f167220 100644 --- a/src/intel/compiler/brw/brw_analysis.h +++ b/src/intel/compiler/brw/brw_analysis.h @@ -503,9 +503,8 @@ public: protected: void setup_def_use(); - void setup_one_read(struct block_data *bd, int ip, const brw_reg ®); - void setup_one_write(struct block_data *bd, brw_inst *inst, int ip, - const brw_reg ®); + void setup_one_read(struct block_data *bd, int ip, int var); + void setup_one_write(struct block_data *bd, brw_inst *inst, int ip, int var); void compute_live_variables(); void compute_start_end(); diff --git a/src/intel/compiler/brw/brw_analysis_liveness.cpp b/src/intel/compiler/brw/brw_analysis_liveness.cpp index 7f31ab3283f..99308d5c686 100644 --- a/src/intel/compiler/brw/brw_analysis_liveness.cpp +++ b/src/intel/compiler/brw/brw_analysis_liveness.cpp @@ -30,9 +30,8 @@ void brw_live_variables::setup_one_read(struct block_data *bd, - int ip, const brw_reg ®) + int ip, int var) { - int var = var_from_reg(reg); assert(var < num_vars); vars_range[var] = merge(vars_range[var], ip); @@ -47,9 +46,8 @@ brw_live_variables::setup_one_read(struct block_data *bd, void brw_live_variables::setup_one_write(struct block_data *bd, brw_inst *inst, - int ip, const brw_reg ®) + int ip, int var) { - int var = var_from_reg(reg); assert(var < num_vars); vars_range[var] = merge(vars_range[var], ip); @@ -57,12 +55,10 @@ brw_live_variables::setup_one_write(struct block_data *bd, brw_inst *inst, /* The def[] bitset marks when an initialization in a block completely * screens off previous updates of that variable (VGRF channel). */ - if (inst->dst.file == VGRF) { - if (!inst->is_partial_write() && !BITSET_TEST(bd->use, var)) - BITSET_SET(bd->def, var); + if (!inst->is_partial_write() && !BITSET_TEST(bd->use, var)) + BITSET_SET(bd->def, var); - BITSET_SET(bd->defout, var); - } + BITSET_SET(bd->defout, var); } /** @@ -89,26 +85,21 @@ brw_live_variables::setup_def_use() foreach_inst_in_block(brw_inst, inst, block) { /* Set use[] for this instruction */ for (unsigned int i = 0; i < inst->sources; i++) { - brw_reg reg = inst->src[i]; - - if (reg.file != VGRF) + if (inst->src[i].file != VGRF) continue; - for (unsigned j = 0; j < regs_read(devinfo, inst, i); j++) { - setup_one_read(bd, ip, reg); - reg.offset += REG_SIZE; - } + const int var = var_from_reg(inst->src[i]); + for (unsigned j = 0; j < regs_read(devinfo, inst, i); j++) + setup_one_read(bd, ip, var + j); } bd->flag_use[0] |= inst->flags_read(devinfo) & ~bd->flag_def[0]; /* Set def[] for this instruction */ if (inst->dst.file == VGRF) { - brw_reg reg = inst->dst; - for (unsigned j = 0; j < regs_written(inst); j++) { - setup_one_write(bd, inst, ip, reg); - reg.offset += REG_SIZE; - } + const int var = var_from_reg(inst->dst); + for (unsigned j = 0; j < regs_written(inst); j++) + setup_one_write(bd, inst, ip, var + j); } if (!inst->predicate && inst->exec_size >= 8)