brw: Move insert/remove code to the block

Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34681>
This commit is contained in:
Caio Oliveira 2025-04-02 17:53:03 -07:00 committed by Marge Bot
parent d28ff8050a
commit 6c5132ec9a
5 changed files with 41 additions and 35 deletions

View file

@ -362,7 +362,7 @@ public:
#endif
if (block)
static_cast<brw_inst *>(cursor)->insert_before(block, inst);
block->insert_before(inst, cursor);
else
cursor->insert_before(inst);

View file

@ -77,6 +77,42 @@ bblock_t::add_successor(void *mem_ctx, bblock_t *successor,
children.push_tail(::link(mem_ctx, successor, kind));
}
void
bblock_t::insert_before(brw_inst *inst, exec_node *ref)
{
assert(inst != ref);
assert(!inst->block || inst->block == this);
num_instructions++;
cfg->total_instructions++;
ref->exec_node::insert_before(inst);
inst->block = this;
}
void
bblock_t::remove(brw_inst *inst)
{
if (exec_list_is_singular(&instructions)) {
inst->opcode = BRW_OPCODE_NOP;
inst->resize_sources(0);
inst->dst = brw_reg();
inst->size_written = 0;
return;
}
assert(num_instructions > 0);
assert(cfg->total_instructions > 0);
num_instructions--;
cfg->total_instructions--;
inst->exec_node::remove();
inst->block = NULL;
if (num_instructions == 0)
cfg->remove_block(this);
}
static void
append_inst(bblock_t *block, brw_inst *inst)
{

View file

@ -94,6 +94,9 @@ struct bblock_t {
brw_inst *last_non_control_flow_inst();
void insert_before(brw_inst *inst, exec_node *ref);
void remove(brw_inst *inst);
struct exec_node link;
struct cfg_t *cfg;

View file

@ -962,43 +962,11 @@ brw_inst::is_volatile() const
opcode == SHADER_OPCODE_SEND_GATHER) && send_is_volatile);
}
void
brw_inst::insert_before(bblock_t *block, brw_inst *inst)
{
assert(this != inst);
assert(!inst->block || inst->block == block);
exec_node::insert_before(inst);
inst->block = block;
inst->block->num_instructions++;
inst->block->cfg->total_instructions++;
}
void
brw_inst::remove()
{
assert(block);
if (exec_list_is_singular(&block->instructions)) {
this->opcode = BRW_OPCODE_NOP;
this->resize_sources(0);
this->dst = brw_reg();
this->size_written = 0;
return;
}
assert(block->num_instructions > 0);
assert(block->cfg->total_instructions > 0);
block->num_instructions--;
block->cfg->total_instructions--;
if (block->num_instructions == 0)
block->cfg->remove_block(block);
exec_node::remove();
block = NULL;
block->remove(this);
}
enum brw_reg_type

View file

@ -92,7 +92,6 @@ public:
bool uses_indirect_addressing() const;
void remove();
void insert_before(bblock_t *block, brw_inst *inst);
/**
* True if the instruction has side effects other than writing to