From 1139ede508579b3abebf4c780691ef4509a3df8d Mon Sep 17 00:00:00 2001 From: Caio Oliveira Date: Fri, 7 Mar 2025 22:08:32 -0800 Subject: [PATCH] brw: Track num_instructions in a block Reviewed-by: Kenneth Graunke Part-of: --- src/intel/compiler/brw_cfg.cpp | 7 ++++++- src/intel/compiler/brw_cfg.h | 2 ++ src/intel/compiler/brw_inst.cpp | 6 +++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/intel/compiler/brw_cfg.cpp b/src/intel/compiler/brw_cfg.cpp index e9cf954df10..be9372a4fea 100644 --- a/src/intel/compiler/brw_cfg.cpp +++ b/src/intel/compiler/brw_cfg.cpp @@ -62,7 +62,8 @@ push_stack(exec_list *list, void *mem_ctx, bblock_t *block) } bblock_t::bblock_t(cfg_t *cfg) : - cfg(cfg), start_ip(0), end_ip(0), end_ip_delta(0), num(0) + cfg(cfg), start_ip(0), end_ip(0), end_ip_delta(0), + num_instructions(0), num(0) { instructions.make_empty(); parents.make_empty(); @@ -83,6 +84,7 @@ append_inst(bblock_t *block, brw_inst *inst) assert(inst->block == NULL); inst->block = block; block->instructions.push_tail(inst); + block->num_instructions++; } cfg_t::cfg_t(brw_shader *s, exec_list *instructions) : @@ -571,9 +573,12 @@ cfg_t::validate(const char *stage_abbrev) cfgv_assert(!block->instructions.is_empty()); + unsigned num_instructions = 0; foreach_inst_in_block(brw_inst, inst, block) { cfgv_assert(block == inst->block); + num_instructions++; } + cfgv_assert(num_instructions == block->num_instructions); brw_inst *first_inst = block->start(); if (first_inst->opcode == BRW_OPCODE_DO) { diff --git a/src/intel/compiler/brw_cfg.h b/src/intel/compiler/brw_cfg.h index de5125e0ec5..a6ecac96ac2 100644 --- a/src/intel/compiler/brw_cfg.h +++ b/src/intel/compiler/brw_cfg.h @@ -105,6 +105,8 @@ struct bblock_t { */ int end_ip_delta; + unsigned num_instructions; + struct exec_list instructions; struct exec_list parents; struct exec_list children; diff --git a/src/intel/compiler/brw_inst.cpp b/src/intel/compiler/brw_inst.cpp index d3f516c6226..5ffc5878428 100644 --- a/src/intel/compiler/brw_inst.cpp +++ b/src/intel/compiler/brw_inst.cpp @@ -982,6 +982,7 @@ brw_inst::insert_before(bblock_t *block, brw_inst *inst) exec_node::insert_before(inst); inst->block = block; + inst->block->num_instructions++; } void @@ -997,6 +998,9 @@ brw_inst::remove(bool defer_later_block_ip_updates) return; } + assert(block->num_instructions > 0); + block->num_instructions--; + if (defer_later_block_ip_updates) { block->end_ip_delta--; } else { @@ -1004,7 +1008,7 @@ brw_inst::remove(bool defer_later_block_ip_updates) adjust_later_block_ips(block, -1); } - if (block->start_ip == block->end_ip) { + if (block->num_instructions == 0) { if (block->end_ip_delta != 0) { adjust_later_block_ips(block, block->end_ip_delta); block->end_ip_delta = 0;