*/
static nir_instr *
-instr_try_combine(struct nir_shader *nir, nir_instr *instr1, nir_instr *instr2)
+instr_try_combine(struct nir_shader *nir, nir_instr *instr1, nir_instr *instr2,
+ nir_opt_vectorize_cb filter, void *data)
{
assert(instr1->type == nir_instr_type_alu);
assert(instr2->type == nir_instr_type_alu);
(total_components > 2 || alu1->dest.dest.ssa.bit_size != 16))
return NULL;
+ if (filter && !filter(&alu1->instr, &alu2->instr, data))
+ return NULL;
+
nir_builder b;
nir_builder_init(&b, nir_cf_node_get_function(&instr1->block->cf_node));
b.cursor = nir_after_instr(instr1);
static bool
vec_instr_stack_push(struct nir_shader *nir, struct util_dynarray *stack,
- nir_instr *instr)
+ nir_instr *instr,
+ nir_opt_vectorize_cb filter, void *data)
{
/* Walk the stack from child to parent to make live ranges shorter by
* matching the closest thing we can
*/
util_dynarray_foreach_reverse(stack, nir_instr *, stack_instr) {
- nir_instr *new_instr = instr_try_combine(nir, *stack_instr, instr);
+ nir_instr *new_instr = instr_try_combine(nir, *stack_instr, instr,
+ filter, data);
if (new_instr) {
*stack_instr = new_instr;
return true;
static bool
vec_instr_set_add_or_rewrite(struct nir_shader *nir, struct set *instr_set,
- nir_instr *instr)
+ nir_instr *instr,
+ nir_opt_vectorize_cb filter, void *data)
{
if (!instr_can_rewrite(instr))
return false;
struct util_dynarray *new_stack = vec_instr_stack_create(instr_set);
- vec_instr_stack_push(nir, new_stack, instr);
+ vec_instr_stack_push(nir, new_stack, instr, filter, data);
struct set_entry *entry = _mesa_set_search(instr_set, new_stack);
if (entry) {
ralloc_free(new_stack);
struct util_dynarray *stack = (struct util_dynarray *) entry->key;
- return vec_instr_stack_push(nir, stack, instr);
+ return vec_instr_stack_push(nir, stack, instr, filter, data);
}
_mesa_set_add(instr_set, new_stack);
static void
vec_instr_set_remove(struct nir_shader *nir, struct set *instr_set,
- nir_instr *instr)
+ nir_instr *instr, nir_opt_vectorize_cb filter, void *data)
{
if (!instr_can_rewrite(instr))
return;
* comparison function as well.
*/
struct util_dynarray *temp = vec_instr_stack_create(instr_set);
- vec_instr_stack_push(nir, temp, instr);
+ vec_instr_stack_push(nir, temp, instr, filter, data);
struct set_entry *entry = _mesa_set_search(instr_set, temp);
ralloc_free(temp);
static bool
vectorize_block(struct nir_shader *nir, nir_block *block,
- struct set *instr_set)
+ struct set *instr_set,
+ nir_opt_vectorize_cb filter, void *data)
{
bool progress = false;
nir_foreach_instr_safe(instr, block) {
- if (vec_instr_set_add_or_rewrite(nir, instr_set, instr))
+ if (vec_instr_set_add_or_rewrite(nir, instr_set, instr, filter, data))
progress = true;
}
for (unsigned i = 0; i < block->num_dom_children; i++) {
nir_block *child = block->dom_children[i];
- progress |= vectorize_block(nir, child, instr_set);
+ progress |= vectorize_block(nir, child, instr_set, filter, data);
}
nir_foreach_instr_reverse(instr, block)
- vec_instr_set_remove(nir, instr_set, instr);
+ vec_instr_set_remove(nir, instr_set, instr, filter, data);
return progress;
}
static bool
-nir_opt_vectorize_impl(struct nir_shader *nir, nir_function_impl *impl)
+nir_opt_vectorize_impl(struct nir_shader *nir, nir_function_impl *impl,
+ nir_opt_vectorize_cb filter, void *data)
{
struct set *instr_set = vec_instr_set_create();
nir_metadata_require(impl, nir_metadata_dominance);
- bool progress = vectorize_block(nir, nir_start_block(impl), instr_set);
+ bool progress = vectorize_block(nir, nir_start_block(impl), instr_set,
+ filter, data);
if (progress)
nir_metadata_preserve(impl, nir_metadata_block_index |
}
bool
-nir_opt_vectorize(nir_shader *shader)
+nir_opt_vectorize(nir_shader *shader, nir_opt_vectorize_cb filter,
+ void *data)
{
bool progress = false;
nir_foreach_function(function, shader) {
if (function->impl)
- progress |= nir_opt_vectorize_impl(shader, function->impl);
+ progress |= nir_opt_vectorize_impl(shader, function->impl, filter, data);
}
return progress;