treewide: use nir_shader_alu_pass

@def@
        typedef bool;
        typedef nir_builder;
        typedef nir_instr;
        typedef nir_def;
        identifier fn, instr, intr, x, builder, data;
        @@

        static fn(nir_builder* builder,
        -nir_instr *instr,
        +nir_alu_instr *intr,
        ...)
        {
        (
        -   if (instr->type != nir_instr_type_alu)
        -      return false;
        -   nir_alu_instr *intr = nir_instr_as_alu(instr);
        |
        -   nir_alu_instr *intr = nir_instr_as_alu(instr);
        -   if (instr->type != nir_instr_type_alu)
        -      return false;
        )

        <...
        (
        -instr->x
        +intr->instr.x
        |
        -instr
        +&intr->instr
        )
        ...>

        }

        @pass depends on def@
        identifier def.fn;
        expression shader, progress;
        @@

        (
        -nir_shader_instructions_pass(shader, fn,
        +nir_shader_alu_pass(shader, fn,
        ...)
        |
        -NIR_PASS_V(shader, nir_shader_instructions_pass, fn,
        +NIR_PASS_V(shader, nir_shader_alu_pass, fn,
        ...)
        |
        -NIR_PASS(progress, shader, nir_shader_instructions_pass, fn,
        +NIR_PASS(progress, shader, nir_shader_alu_pass, fn,
        ...)
        )

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Reviewed-by: Christian Gmeiner <cgmeiner@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30582>
This commit is contained in:
Alyssa Rosenzweig 2024-08-08 22:25:29 -04:00 committed by Marge Bot
parent cc1f092b62
commit 9b07550908
4 changed files with 17 additions and 36 deletions

View file

@ -455,16 +455,12 @@ nir_lower_alu_to_scalar(nir_shader *shader, nir_instr_filter_cb cb, const void *
}
static bool
lower_alu_vec8_16_src(nir_builder *b, nir_instr *instr, void *_data)
lower_alu_vec8_16_src(nir_builder *b, nir_alu_instr *alu, void *_data)
{
if (instr->type != nir_instr_type_alu)
return false;
nir_alu_instr *alu = nir_instr_as_alu(instr);
const nir_op_info *info = &nir_op_infos[alu->op];
bool changed = false;
b->cursor = nir_before_instr(instr);
b->cursor = nir_before_instr(&alu->instr);
for (int i = 0; i < info->num_inputs; i++) {
if (alu->src[i].src.ssa->num_components < 8 || info->input_sizes[i])
continue;
@ -492,7 +488,7 @@ lower_alu_vec8_16_src(nir_builder *b, nir_instr *instr, void *_data)
bool
nir_lower_alu_vec8_16_srcs(nir_shader *shader)
{
return nir_shader_instructions_pass(shader, lower_alu_vec8_16_src,
nir_metadata_control_flow,
NULL);
return nir_shader_alu_pass(shader, lower_alu_vec8_16_src,
nir_metadata_control_flow,
NULL);
}

View file

@ -82,13 +82,8 @@ is_comparison(nir_instr *instr)
}
static bool
r300_nir_lower_fcsel_instr(nir_builder *b, nir_instr *instr, void *data)
r300_nir_lower_fcsel_instr(nir_builder *b, nir_alu_instr *alu, void *data)
{
if (instr->type != nir_instr_type_alu)
return false;
nir_alu_instr *alu = nir_instr_as_alu(instr);
if (alu->op != nir_op_fcsel && alu->op != nir_op_fcsel_ge && alu->op != nir_op_fcsel_gt)
return false;
@ -126,9 +121,6 @@ r300_nir_lower_fcsel_instr(nir_builder *b, nir_instr *instr, void *data)
bool
r300_nir_lower_fcsel_r500(nir_shader *shader)
{
bool progress = nir_shader_instructions_pass(shader,
r300_nir_lower_fcsel_instr,
nir_metadata_control_flow,
NULL);
return progress;
return nir_shader_alu_pass(shader, r300_nir_lower_fcsel_instr,
nir_metadata_control_flow, NULL);
}

View file

@ -4896,11 +4896,8 @@ match_tex_dests(nir_shader *shader, struct zink_shader *zs, bool pre_mangle)
}
static bool
split_bitfields_instr(nir_builder *b, nir_instr *in, void *data)
split_bitfields_instr(nir_builder *b, nir_alu_instr *alu, void *data)
{
if (in->type != nir_instr_type_alu)
return false;
nir_alu_instr *alu = nir_instr_as_alu(in);
switch (alu->op) {
case nir_op_ubitfield_extract:
case nir_op_ibitfield_extract:
@ -4912,7 +4909,7 @@ split_bitfields_instr(nir_builder *b, nir_instr *in, void *data)
unsigned num_components = alu->def.num_components;
if (num_components == 1)
return false;
b->cursor = nir_before_instr(in);
b->cursor = nir_before_instr(&alu->instr);
nir_def *dests[NIR_MAX_VEC_COMPONENTS];
for (unsigned i = 0; i < num_components; i++) {
if (alu->op == nir_op_bitfield_insert)
@ -4933,8 +4930,8 @@ split_bitfields_instr(nir_builder *b, nir_instr *in, void *data)
nir_channel(b, alu->src[2].src.ssa, alu->src[2].swizzle[i]));
}
nir_def *dest = nir_vec(b, dests, num_components);
nir_def_rewrite_uses_after(&alu->def, dest, in);
nir_instr_remove(in);
nir_def_rewrite_uses_after(&alu->def, dest, &alu->instr);
nir_instr_remove(&alu->instr);
return true;
}
@ -4942,7 +4939,8 @@ split_bitfields_instr(nir_builder *b, nir_instr *in, void *data)
static bool
split_bitfields(nir_shader *shader)
{
return nir_shader_instructions_pass(shader, split_bitfields_instr, nir_metadata_dominance, NULL);
return nir_shader_alu_pass(shader, split_bitfields_instr,
nir_metadata_dominance, NULL);
}
static bool

View file

@ -9,12 +9,8 @@
#include "nir_opcodes.h"
static bool
pass(nir_builder *b, nir_instr *instr, void *data)
pass(nir_builder *b, nir_alu_instr *alu, void *data)
{
if (instr->type != nir_instr_type_alu)
return false;
nir_alu_instr *alu = nir_instr_as_alu(instr);
if (alu->op != nir_op_b32csel)
return false;
@ -37,9 +33,8 @@ midgard_nir_type_csel(nir_shader *shader)
calloc(BITSET_WORDS(impl->ssa_alloc), sizeof(BITSET_WORD));
nir_gather_types(impl, float_types, NULL);
nir_shader_instructions_pass(
shader, pass, nir_metadata_control_flow,
float_types);
nir_shader_alu_pass(shader, pass, nir_metadata_control_flow,
float_types);
free(float_types);
}