From 4f09ad9dee2b9231268dd5d32895268b33d89741 Mon Sep 17 00:00:00 2001 From: Caio Oliveira Date: Wed, 3 Jan 2024 11:13:14 -0800 Subject: [PATCH] intel/brw: Pull opt_combine_constants out of fs_visitor Reviewed-by: Lionel Landwerlin Reviewed-by: Ian Romanick Part-of: --- src/intel/compiler/brw_fs.cpp | 2 +- src/intel/compiler/brw_fs.h | 2 +- .../compiler/brw_fs_combine_constants.cpp | 37 ++++++++++--------- .../compiler/test_fs_combine_constants.cpp | 2 +- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/intel/compiler/brw_fs.cpp b/src/intel/compiler/brw_fs.cpp index 471b8dd3a95..89a3d0f96e5 100644 --- a/src/intel/compiler/brw_fs.cpp +++ b/src/intel/compiler/brw_fs.cpp @@ -5747,7 +5747,7 @@ fs_visitor::optimize() OPT(brw_fs_opt_dead_code_eliminate, *this); } - OPT(opt_combine_constants); + OPT(brw_fs_opt_combine_constants, *this); if (OPT(lower_integer_multiplication)) { /* If lower_integer_multiplication made progress, it may have produced * some 32x32-bit MULs in the process of lowering 64-bit MULs. Run it diff --git a/src/intel/compiler/brw_fs.h b/src/intel/compiler/brw_fs.h index 8edba4d3de0..9fe007a5455 100644 --- a/src/intel/compiler/brw_fs.h +++ b/src/intel/compiler/brw_fs.h @@ -298,7 +298,6 @@ public: bool lower_find_live_channel(); bool lower_scoreboard(); bool lower_sub_sat(); - bool opt_combine_constants(); void emit_repclear_shader(); void emit_interpolation_setup_gfx4(); @@ -623,6 +622,7 @@ bool brw_lower_dpas(fs_visitor &v); void nir_to_brw(fs_visitor *s); bool brw_fs_opt_cmod_propagation(fs_visitor &s); +bool brw_fs_opt_combine_constants(fs_visitor &s); bool brw_fs_opt_copy_propagation(fs_visitor &s); bool brw_fs_opt_dead_code_eliminate(fs_visitor &s); bool brw_fs_opt_saturate_propagation(fs_visitor &s); diff --git a/src/intel/compiler/brw_fs_combine_constants.cpp b/src/intel/compiler/brw_fs_combine_constants.cpp index ed5176153da..d4066ced9d8 100644 --- a/src/intel/compiler/brw_fs_combine_constants.cpp +++ b/src/intel/compiler/brw_fs_combine_constants.cpp @@ -1305,8 +1305,9 @@ parcel_out_registers(struct imm *imm, unsigned len, const bblock_t *cur_block, } bool -fs_visitor::opt_combine_constants() +brw_fs_opt_combine_constants(fs_visitor &s) { + const intel_device_info *devinfo = s.devinfo; void *const_ctx = ralloc_context(NULL); struct table table; @@ -1325,14 +1326,14 @@ fs_visitor::opt_combine_constants() table.num_boxes = 0; table.boxes = ralloc_array(const_ctx, fs_inst_box, table.size_boxes); - const brw::idom_tree &idom = idom_analysis.require(); + const brw::idom_tree &idom = s.idom_analysis.require(); unsigned ip = -1; /* Make a pass through all instructions and count the number of times each * constant is used by coissueable instructions or instructions that cannot * take immediate arguments. */ - foreach_block_and_inst(block, fs_inst, inst, cfg) { + foreach_block_and_inst(block, fs_inst, inst, s.cfg) { ip++; switch (inst->opcode) { @@ -1548,7 +1549,7 @@ fs_visitor::opt_combine_constants() ralloc_free(const_ctx); return false; } - if (cfg->num_blocks != 1) + if (s.cfg->num_blocks != 1) qsort(table.imm, table.len, sizeof(struct imm), compare); if (devinfo->ver > 7) { @@ -1560,14 +1561,14 @@ fs_visitor::opt_combine_constants() regs[i].avail = 0xffff; } - foreach_block(block, cfg) { + foreach_block(block, s.cfg) { parcel_out_registers(table.imm, table.len, block, regs, table.len, - alloc, devinfo->ver); + s.alloc, devinfo->ver); } free(regs); } else { - fs_reg reg(VGRF, alloc.allocate(1)); + fs_reg reg(VGRF, s.alloc.allocate(1)); reg.stride = 0; for (int i = 0; i < table.len; i++) { @@ -1581,7 +1582,7 @@ fs_visitor::opt_combine_constants() /* Ensure we have enough space in the register to copy the immediate */ if (reg.offset + imm->size > REG_SIZE) { - reg.nr = alloc.allocate(1); + reg.nr = s.alloc.allocate(1); reg.offset = 0; } @@ -1661,7 +1662,7 @@ fs_visitor::opt_combine_constants() * both HF slots within a DWord with the constant. */ const uint32_t width = devinfo->ver == 8 && imm->is_half_float ? 2 : 1; - const fs_builder ibld = fs_builder(this, width).at(insert_block, n).exec_all(); + const fs_builder ibld = fs_builder(&s, width).at(insert_block, n).exec_all(); fs_reg reg(VGRF, imm->nr); reg.offset = imm->subreg_offset; @@ -1680,7 +1681,7 @@ fs_visitor::opt_combine_constants() ibld.MOV(retype(reg, imm_reg.type), imm_reg); } - shader_stats.promoted_constants = table.len; + s.shader_stats.promoted_constants = table.len; /* Rewrite the immediate sources to refer to the new GRFs. */ for (int i = 0; i < table.len; i++) { @@ -1839,20 +1840,20 @@ fs_visitor::opt_combine_constants() * is used for membership in that list and in a block list. So we need * to pull them back before rebuilding the CFG. */ - assert(exec_list_length(&instructions) == 0); - foreach_block(block, cfg) { - exec_list_append(&instructions, &block->instructions); + assert(exec_list_length(&s.instructions) == 0); + foreach_block(block, s.cfg) { + exec_list_append(&s.instructions, &block->instructions); } - delete cfg; - cfg = NULL; - calculate_cfg(); + delete s.cfg; + s.cfg = NULL; + s.calculate_cfg(); } ralloc_free(const_ctx); - invalidate_analysis(DEPENDENCY_INSTRUCTIONS | DEPENDENCY_VARIABLES | - (rebuild_cfg ? DEPENDENCY_BLOCKS : DEPENDENCY_NOTHING)); + s.invalidate_analysis(DEPENDENCY_INSTRUCTIONS | DEPENDENCY_VARIABLES | + (rebuild_cfg ? DEPENDENCY_BLOCKS : DEPENDENCY_NOTHING)); return true; } diff --git a/src/intel/compiler/test_fs_combine_constants.cpp b/src/intel/compiler/test_fs_combine_constants.cpp index 805a78e0b50..d67e5a3e9db 100644 --- a/src/intel/compiler/test_fs_combine_constants.cpp +++ b/src/intel/compiler/test_fs_combine_constants.cpp @@ -56,7 +56,7 @@ struct FSCombineConstantsTest : public ::testing::Test { s->cfg->dump(); } - bool ret = s->opt_combine_constants(); + bool ret = brw_fs_opt_combine_constants(*s); if (print) { fprintf(stderr, "\n= After =\n");