From 8e9d269da6aff0ecce8088c68cddfa43a2126175 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Timur=20Krist=C3=B3f?= Date: Fri, 31 Mar 2023 21:31:13 +0200 Subject: [PATCH] aco: Don't use nir_selection_control in aco_ir. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit We don't want to rely on any NIR structures in ACO, because we would like to avoid the need to include nir.h in aco_ir. Signed-off-by: Timur Kristóf Reviewed-by: Rhys Perry Part-of: --- src/amd/compiler/aco_insert_exec_mask.cpp | 8 ++++---- src/amd/compiler/aco_instruction_selection.cpp | 6 ++++-- src/amd/compiler/aco_ir.h | 6 +++++- src/amd/compiler/aco_lower_to_hw_instr.cpp | 4 +--- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/amd/compiler/aco_insert_exec_mask.cpp b/src/amd/compiler/aco_insert_exec_mask.cpp index a6307ac..16374f9 100644 --- a/src/amd/compiler/aco_insert_exec_mask.cpp +++ b/src/amd/compiler/aco_insert_exec_mask.cpp @@ -804,7 +804,7 @@ add_branch_code(exec_ctx& ctx, Block* block) assert(block->linear_succs.size() == 2); assert(block->instructions.back()->opcode == aco_opcode::p_cbranch_z); Temp cond = block->instructions.back()->operands[0].getTemp(); - nir_selection_control sel_ctrl = block->instructions.back()->branch().selection_control; + const bool sel_ctrl = block->instructions.back()->branch().selection_control_remove; block->instructions.pop_back(); uint8_t mask_type = ctx.info[idx].exec.back().second & (mask_type_wqm | mask_type_exact); @@ -822,14 +822,14 @@ add_branch_code(exec_ctx& ctx, Block* block) Builder::Result r = bld.branch(aco_opcode::p_cbranch_z, bld.def(s2), Operand(exec, bld.lm), block->linear_succs[1], block->linear_succs[0]); - r->branch().selection_control = sel_ctrl; + r->branch().selection_control_remove = sel_ctrl; return; } if (block->kind & block_kind_invert) { // exec = s_andn2_b64 (original_exec, exec) assert(block->instructions.back()->opcode == aco_opcode::p_branch); - nir_selection_control sel_ctrl = block->instructions.back()->branch().selection_control; + const bool sel_ctrl = block->instructions.back()->branch().selection_control_remove; block->instructions.pop_back(); assert(ctx.info[idx].exec.size() >= 2); Operand orig_exec = ctx.info[idx].exec[ctx.info[idx].exec.size() - 2].first; @@ -838,7 +838,7 @@ add_branch_code(exec_ctx& ctx, Block* block) Builder::Result r = bld.branch(aco_opcode::p_cbranch_z, bld.def(s2), Operand(exec, bld.lm), block->linear_succs[1], block->linear_succs[0]); - r->branch().selection_control = sel_ctrl; + r->branch().selection_control_remove = sel_ctrl; return; } diff --git a/src/amd/compiler/aco_instruction_selection.cpp b/src/amd/compiler/aco_instruction_selection.cpp index ed86cdd..da627f5 100644 --- a/src/amd/compiler/aco_instruction_selection.cpp +++ b/src/amd/compiler/aco_instruction_selection.cpp @@ -10365,7 +10365,8 @@ begin_divergent_if_then(isel_context* ctx, if_context* ic, Temp cond, Format::PSEUDO_BRANCH, 1, 1)); branch->definitions[0] = Definition(ctx->program->allocateTmp(s2)); branch->operands[0] = Operand(cond); - branch->selection_control = sel_ctrl; + branch->selection_control_remove = sel_ctrl == nir_selection_control_flatten || + sel_ctrl == nir_selection_control_divergent_always_taken; ctx->block->instructions.push_back(std::move(branch)); ic->BB_if_idx = ctx->block->index; @@ -10436,7 +10437,8 @@ begin_divergent_if_else(isel_context* ctx, if_context* ic, branch.reset(create_instruction(aco_opcode::p_branch, Format::PSEUDO_BRANCH, 0, 1)); branch->definitions[0] = Definition(ctx->program->allocateTmp(s2)); - branch->selection_control = sel_ctrl; + branch->selection_control_remove = sel_ctrl == nir_selection_control_flatten || + sel_ctrl == nir_selection_control_divergent_always_taken; ctx->block->instructions.push_back(std::move(branch)); ic->exec_potentially_empty_discard_old |= ctx->cf_info.exec_potentially_empty_discard; diff --git a/src/amd/compiler/aco_ir.h b/src/amd/compiler/aco_ir.h index fc3e778..122221e 100644 --- a/src/amd/compiler/aco_ir.h +++ b/src/amd/compiler/aco_ir.h @@ -1664,7 +1664,11 @@ struct Pseudo_branch_instruction : public Instruction { * A value of 0 means the target has not been initialized (BB0 cannot be a branch target). */ uint32_t target[2]; - nir_selection_control selection_control; + + /* Indicates that selection control prefers to remove this instruction if possible. + * This is set when the branch is divergent and always taken, or flattened. + */ + bool selection_control_remove; }; static_assert(sizeof(Pseudo_branch_instruction) == sizeof(Instruction) + 12, "Unexpected padding"); diff --git a/src/amd/compiler/aco_lower_to_hw_instr.cpp b/src/amd/compiler/aco_lower_to_hw_instr.cpp index 439b043..6f82879 100644 --- a/src/amd/compiler/aco_lower_to_hw_instr.cpp +++ b/src/amd/compiler/aco_lower_to_hw_instr.cpp @@ -2642,9 +2642,7 @@ lower_to_hw_instr(Program* program) * - The compiler stack knows that it's a divergent branch always taken */ const bool prefer_remove = - (branch->selection_control == nir_selection_control_flatten || - branch->selection_control == nir_selection_control_divergent_always_taken) && - ctx.program->gfx_level >= GFX10; + branch->selection_control_remove && ctx.program->gfx_level >= GFX10; bool can_remove = block->index < target; unsigned num_scalar = 0; unsigned num_vector = 0; -- 2.7.4