nir/algebraic: Move some generated-code algebraic opt args into a struct.
I'm going to be adding some more tables to reduce relocations in the generated code, so move the current tables to a struct for arg-passing sanity. Reviewed-by: Adam Jackson <ajax@redhat.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13987>
This commit is contained in:
@@ -1062,7 +1062,7 @@ static const struct transform ${pass_name}_state${state_id}_xforms[] = {
|
|||||||
% endif
|
% endif
|
||||||
% endfor
|
% 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:
|
% for op in automaton.opcodes:
|
||||||
[${get_c_opcode(op)}] = {
|
[${get_c_opcode(op)}] = {
|
||||||
.filter = (uint16_t []) {
|
.filter = (uint16_t []) {
|
||||||
@@ -1106,6 +1106,12 @@ const uint16_t ${pass_name}_transform_counts[] = {
|
|||||||
% endfor
|
% 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
|
bool
|
||||||
${pass_name}(nir_shader *shader)
|
${pass_name}(nir_shader *shader)
|
||||||
{
|
{
|
||||||
@@ -1123,9 +1129,7 @@ ${pass_name}(nir_shader *shader)
|
|||||||
nir_foreach_function(function, shader) {
|
nir_foreach_function(function, shader) {
|
||||||
if (function->impl) {
|
if (function->impl) {
|
||||||
progress |= nir_algebraic_impl(function->impl, condition_flags,
|
progress |= nir_algebraic_impl(function->impl, condition_flags,
|
||||||
${pass_name}_transforms,
|
&${pass_name}_table);
|
||||||
${pass_name}_transform_counts,
|
|
||||||
${pass_name}_table);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -859,10 +859,8 @@ static bool
|
|||||||
nir_algebraic_instr(nir_builder *build, nir_instr *instr,
|
nir_algebraic_instr(nir_builder *build, nir_instr *instr,
|
||||||
struct hash_table *range_ht,
|
struct hash_table *range_ht,
|
||||||
const bool *condition_flags,
|
const bool *condition_flags,
|
||||||
const struct transform **transforms,
|
const nir_algebraic_table *table,
|
||||||
const uint16_t *transform_counts,
|
|
||||||
struct util_dynarray *states,
|
struct util_dynarray *states,
|
||||||
const struct per_op_table *pass_op_table,
|
|
||||||
nir_instr_worklist *worklist)
|
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,
|
int xform_idx = *util_dynarray_element(states, uint16_t,
|
||||||
alu->dest.dest.ssa.index);
|
alu->dest.dest.ssa.index);
|
||||||
for (uint16_t i = 0; i < transform_counts[xform_idx]; i++) {
|
for (uint16_t i = 0; i < table->transform_counts[xform_idx]; i++) {
|
||||||
const struct transform *xform = &transforms[xform_idx][i];
|
const struct transform *xform = &table->transforms[xform_idx][i];
|
||||||
if (condition_flags[xform->condition_offset] &&
|
if (condition_flags[xform->condition_offset] &&
|
||||||
!(xform->search->inexact && ignore_inexact) &&
|
!(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)) {
|
xform->search, xform->replace, worklist)) {
|
||||||
_mesa_hash_table_clear(range_ht, NULL);
|
_mesa_hash_table_clear(range_ht, NULL);
|
||||||
return true;
|
return true;
|
||||||
@@ -899,9 +897,7 @@ nir_algebraic_instr(nir_builder *build, nir_instr *instr,
|
|||||||
bool
|
bool
|
||||||
nir_algebraic_impl(nir_function_impl *impl,
|
nir_algebraic_impl(nir_function_impl *impl,
|
||||||
const bool *condition_flags,
|
const bool *condition_flags,
|
||||||
const struct transform **transforms,
|
const nir_algebraic_table *table)
|
||||||
const uint16_t *transform_counts,
|
|
||||||
const struct per_op_table *pass_op_table)
|
|
||||||
{
|
{
|
||||||
bool progress = false;
|
bool progress = false;
|
||||||
|
|
||||||
@@ -926,7 +922,7 @@ nir_algebraic_impl(nir_function_impl *impl,
|
|||||||
/* Walk top-to-bottom setting up the automaton state. */
|
/* Walk top-to-bottom setting up the automaton state. */
|
||||||
nir_foreach_block(block, impl) {
|
nir_foreach_block(block, impl) {
|
||||||
nir_foreach_instr(instr, block) {
|
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,
|
progress |= nir_algebraic_instr(&build, instr,
|
||||||
range_ht, condition_flags,
|
range_ht, condition_flags,
|
||||||
transforms, transform_counts, &states,
|
table, &states, worklist);
|
||||||
pass_op_table, worklist);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nir_instr_worklist_destroy(worklist);
|
nir_instr_worklist_destroy(worklist);
|
||||||
|
@@ -180,6 +180,13 @@ struct transform {
|
|||||||
unsigned condition_offset;
|
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
|
/* Note: these must match the start states created in
|
||||||
* TreeAutomaton._build_table()
|
* TreeAutomaton._build_table()
|
||||||
*/
|
*/
|
||||||
@@ -208,8 +215,6 @@ nir_replace_instr(struct nir_builder *b, nir_alu_instr *instr,
|
|||||||
bool
|
bool
|
||||||
nir_algebraic_impl(nir_function_impl *impl,
|
nir_algebraic_impl(nir_function_impl *impl,
|
||||||
const bool *condition_flags,
|
const bool *condition_flags,
|
||||||
const struct transform **transforms,
|
const nir_algebraic_table *table);
|
||||||
const uint16_t *transform_counts,
|
|
||||||
const struct per_op_table *pass_op_table);
|
|
||||||
|
|
||||||
#endif /* _NIR_SEARCH_ */
|
#endif /* _NIR_SEARCH_ */
|
||||||
|
Reference in New Issue
Block a user