diff --git a/src/compiler/nir/nir_algebraic.py b/src/compiler/nir/nir_algebraic.py index 548f87bafeb..3f48ff92a80 100644 --- a/src/compiler/nir/nir_algebraic.py +++ b/src/compiler/nir/nir_algebraic.py @@ -1062,7 +1062,7 @@ static const struct transform ${pass_name}_state${state_id}_xforms[] = { % endif % endfor -static const struct per_op_table ${pass_name}_table[nir_num_search_ops] = { +static const struct per_op_table ${pass_name}_pass_op_table[nir_num_search_ops] = { % for op in automaton.opcodes: [${get_c_opcode(op)}] = { .filter = (uint16_t []) { @@ -1106,6 +1106,12 @@ const uint16_t ${pass_name}_transform_counts[] = { % endfor }; +static const nir_algebraic_table ${pass_name}_table = { + .transforms = ${pass_name}_transforms, + .transform_counts = ${pass_name}_transform_counts, + .pass_op_table = ${pass_name}_pass_op_table, +}; + bool ${pass_name}(nir_shader *shader) { @@ -1123,9 +1129,7 @@ ${pass_name}(nir_shader *shader) nir_foreach_function(function, shader) { if (function->impl) { progress |= nir_algebraic_impl(function->impl, condition_flags, - ${pass_name}_transforms, - ${pass_name}_transform_counts, - ${pass_name}_table); + &${pass_name}_table); } } diff --git a/src/compiler/nir/nir_search.c b/src/compiler/nir/nir_search.c index a968c8a372c..e76853f38dd 100644 --- a/src/compiler/nir/nir_search.c +++ b/src/compiler/nir/nir_search.c @@ -859,10 +859,8 @@ static bool nir_algebraic_instr(nir_builder *build, nir_instr *instr, struct hash_table *range_ht, const bool *condition_flags, - const struct transform **transforms, - const uint16_t *transform_counts, + const nir_algebraic_table *table, struct util_dynarray *states, - const struct per_op_table *pass_op_table, nir_instr_worklist *worklist) { @@ -882,11 +880,11 @@ nir_algebraic_instr(nir_builder *build, nir_instr *instr, int xform_idx = *util_dynarray_element(states, uint16_t, alu->dest.dest.ssa.index); - for (uint16_t i = 0; i < transform_counts[xform_idx]; i++) { - const struct transform *xform = &transforms[xform_idx][i]; + for (uint16_t i = 0; i < table->transform_counts[xform_idx]; i++) { + const struct transform *xform = &table->transforms[xform_idx][i]; if (condition_flags[xform->condition_offset] && !(xform->search->inexact && ignore_inexact) && - nir_replace_instr(build, alu, range_ht, states, pass_op_table, + nir_replace_instr(build, alu, range_ht, states, table->pass_op_table, xform->search, xform->replace, worklist)) { _mesa_hash_table_clear(range_ht, NULL); return true; @@ -899,9 +897,7 @@ nir_algebraic_instr(nir_builder *build, nir_instr *instr, bool nir_algebraic_impl(nir_function_impl *impl, const bool *condition_flags, - const struct transform **transforms, - const uint16_t *transform_counts, - const struct per_op_table *pass_op_table) + const nir_algebraic_table *table) { bool progress = false; @@ -926,7 +922,7 @@ nir_algebraic_impl(nir_function_impl *impl, /* Walk top-to-bottom setting up the automaton state. */ nir_foreach_block(block, impl) { nir_foreach_instr(instr, block) { - nir_algebraic_automaton(instr, &states, pass_op_table); + nir_algebraic_automaton(instr, &states, table->pass_op_table); } } @@ -952,8 +948,7 @@ nir_algebraic_impl(nir_function_impl *impl, progress |= nir_algebraic_instr(&build, instr, range_ht, condition_flags, - transforms, transform_counts, &states, - pass_op_table, worklist); + table, &states, worklist); } nir_instr_worklist_destroy(worklist); diff --git a/src/compiler/nir/nir_search.h b/src/compiler/nir/nir_search.h index aca3f46da18..3699e215fb5 100644 --- a/src/compiler/nir/nir_search.h +++ b/src/compiler/nir/nir_search.h @@ -180,6 +180,13 @@ struct transform { unsigned condition_offset; }; +/* Generated data table for an algebraic optimization pass. */ +typedef struct { + const struct transform **transforms; + const uint16_t *transform_counts; + const struct per_op_table *pass_op_table; +} nir_algebraic_table; + /* Note: these must match the start states created in * TreeAutomaton._build_table() */ @@ -208,8 +215,6 @@ nir_replace_instr(struct nir_builder *b, nir_alu_instr *instr, bool nir_algebraic_impl(nir_function_impl *impl, const bool *condition_flags, - const struct transform **transforms, - const uint16_t *transform_counts, - const struct per_op_table *pass_op_table); + const nir_algebraic_table *table); #endif /* _NIR_SEARCH_ */