aco: Don't use nir_selection_control in aco_ir.
authorTimur Kristóf <timur.kristof@gmail.com>
Fri, 31 Mar 2023 19:31:13 +0000 (21:31 +0200)
committerMarge Bot <emma+marge@anholt.net>
Mon, 10 Apr 2023 20:01:28 +0000 (20:01 +0000)
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 <timur.kristof@gmail.com>
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22241>

src/amd/compiler/aco_insert_exec_mask.cpp
src/amd/compiler/aco_instruction_selection.cpp
src/amd/compiler/aco_ir.h
src/amd/compiler/aco_lower_to_hw_instr.cpp

index a6307ac..16374f9 100644 (file)
@@ -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;
    }
 
index ed86cdd..da627f5 100644 (file)
@@ -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<Pseudo_branch_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;
index fc3e778..122221e 100644 (file)
@@ -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");
 
index 439b043..6f82879 100644 (file)
@@ -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;