treewide: Use nir_before/after_impl for more elaborate cases
authorAlyssa Rosenzweig <alyssa@rosenzweig.io>
Mon, 28 Aug 2023 17:58:57 +0000 (13:58 -0400)
committerMarge Bot <emma+marge@anholt.net>
Wed, 30 Aug 2023 19:30:58 +0000 (19:30 +0000)
Via Coccinelle patch:

    @@
    expression func_impl;
    @@

    -nir_before_block(nir_start_block(func_impl))
    +nir_before_impl(func_impl)

    @@
    expression func_impl;
    @@

    -nir_after_block(nir_impl_last_block(func_impl))
    +nir_after_impl(func_impl)

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Acked-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24910>

29 files changed:
src/asahi/compiler/agx_nir_lower_frag_sidefx.c
src/asahi/lib/agx_nir_lower_msaa.c
src/asahi/lib/agx_nir_lower_tilebuffer.c
src/broadcom/compiler/v3d_nir_lower_line_smooth.c
src/compiler/glsl/gl_nir_linker.c
src/compiler/glsl/gl_nir_lower_blend_equation_advanced.c
src/compiler/glsl/gl_nir_lower_packed_varyings.c
src/compiler/glsl/gl_nir_lower_xfb_varying.c
src/compiler/nir/nir_lower_goto_ifs.c
src/compiler/nir/nir_lower_io_to_temporaries.c
src/compiler/nir/nir_opt_move_discards_to_top.c
src/gallium/auxiliary/nir/tgsi_to_nir.c
src/gallium/drivers/asahi/agx_streamout.c
src/gallium/drivers/crocus/crocus_program.c
src/gallium/drivers/iris/iris_program.c
src/gallium/drivers/vc4/vc4_nir_lower_blend.c
src/gallium/drivers/zink/zink_compiler.c
src/intel/compiler/brw_mesh.cpp
src/intel/compiler/brw_nir_lower_ray_queries.c
src/intel/compiler/brw_nir_lower_rt_intrinsics.c
src/intel/compiler/brw_nir_lower_shader_calls.c
src/intel/vulkan/anv_nir_lower_multiview.c
src/intel/vulkan/anv_pipeline.c
src/intel/vulkan_hasvk/anv_nir_lower_multiview.c
src/mesa/state_tracker/st_nir_lower_fog.c
src/mesa/state_tracker/st_nir_lower_position_invariant.c
src/microsoft/clc/clc_nir.c
src/microsoft/compiler/dxil_nir.c
src/microsoft/spirv_to_dxil/dxil_spirv_nir.c

index 6202ca0..bbeeef2 100644 (file)
@@ -89,8 +89,7 @@ agx_nir_lower_frag_sidefx(nir_shader *s)
    /* If there's no render targets written, just put the write at the end */
    if (!done) {
       nir_function_impl *impl = nir_shader_get_entrypoint(s);
-      nir_builder b =
-         nir_builder_at(nir_after_block(nir_impl_last_block(impl)));
+      nir_builder b = nir_builder_at(nir_after_impl(impl));
 
       insert_z_write(&b);
    }
index 5b98871..78db4e0 100644 (file)
@@ -61,8 +61,7 @@ agx_nir_wrap_per_sample_loop(nir_shader *shader, uint8_t nr_samples)
    nir_function_impl *impl = nir_shader_get_entrypoint(shader);
 
    nir_cf_list list;
-   nir_cf_extract(&list, nir_before_block(nir_start_block(impl)),
-                  nir_after_block(nir_impl_last_block(impl)));
+   nir_cf_extract(&list, nir_before_impl(impl), nir_after_impl(impl));
 
    /* Create a builder for the wrapped function */
    nir_builder b = nir_builder_at(nir_after_block(nir_start_block(impl)));
@@ -162,7 +161,7 @@ insert_sample_mask_write(nir_shader *s)
 {
    nir_builder b;
    nir_function_impl *impl = nir_shader_get_entrypoint(s);
-   b = nir_builder_at(nir_before_block(nir_start_block(impl)));
+   b = nir_builder_at(nir_before_impl(impl));
 
    /* Kill samples that are NOT covered by the mask */
    nir_discard_agx(&b, nir_inot(&b, nir_load_api_sample_mask_agx(&b)));
index a16cbc3..1edfe50 100644 (file)
@@ -311,8 +311,7 @@ agx_nir_lower_tilebuffer(nir_shader *shader, struct agx_tilebuffer_layout *tib,
    /* Flush at end */
    if (ctx.any_memory_stores) {
       nir_function_impl *impl = nir_shader_get_entrypoint(shader);
-      nir_builder b =
-         nir_builder_at(nir_after_block(nir_impl_last_block(impl)));
+      nir_builder b = nir_builder_at(nir_after_impl(impl));
       nir_fence_pbe_to_tex_pixel_agx(&b);
    }
 
index 32d59a0..1260248 100644 (file)
@@ -85,7 +85,7 @@ static void
 initialise_coverage_var(struct lower_line_smooth_state *state,
                         nir_function_impl *impl)
 {
-        nir_builder b = nir_builder_at(nir_before_block(nir_start_block(impl)));
+        nir_builder b = nir_builder_at(nir_before_impl(impl));
 
         nir_def *line_width = nir_load_line_width(&b);
 
index 7ce9ce1..e8fa0f2 100644 (file)
@@ -957,7 +957,7 @@ gl_nir_zero_initialize_clip_distance(nir_shader *nir)
       return false;
 
    nir_function_impl *impl = nir_shader_get_entrypoint(nir);
-   nir_builder b = nir_builder_at(nir_before_block(nir_start_block(impl)));
+   nir_builder b = nir_builder_at(nir_before_impl(impl));
    if (clip_dist0)
       zero_array_members(&b, clip_dist0);
 
index 0792603..dffd946 100644 (file)
@@ -458,7 +458,7 @@ calc_blend_result(nir_builder *b,
    nir_store_var(b, result, nir_vec4(b, val, val, val, val), 0x8);
 
    /* reset cursor to the end of the main function */
-   b->cursor = nir_after_block(nir_impl_last_block(b->impl));
+   b->cursor = nir_after_impl(b->impl);
 
    return result;
 }
@@ -495,7 +495,7 @@ gl_nir_lower_blend_equation_advanced(nir_shader *sh, bool coherent)
 
    sh->info.fs.uses_sample_shading = true;
 
-   nir_builder b = nir_builder_at(nir_after_block(nir_impl_last_block(impl)));
+   nir_builder b = nir_builder_at(nir_after_impl(impl));
 
    nir_variable *fb = nir_variable_create(sh, nir_var_shader_out,
                                           glsl_vec4_type(),
index 66ccbce..1bec7ee 100644 (file)
@@ -937,7 +937,7 @@ lower_packed_inputs(struct lower_packed_varyings_state *state)
    /* Shader inputs need to be lowered at the beginning of main() so set bulder
     * cursor to insert packing code at the start of the main function.
     */
-   state->b.cursor = nir_before_block(nir_start_block(state->impl));
+   state->b.cursor = nir_before_impl(state->impl);
 
    /* insert new varyings, lower old ones to locals and add unpacking code a
     * the start of the shader.
index 61e4470..5328b15 100644 (file)
@@ -155,7 +155,7 @@ gl_nir_lower_xfb_varying(nir_shader *shader, const char *old_var_name,
 {
    nir_function_impl *impl = nir_shader_get_entrypoint(shader);
 
-   nir_builder b = nir_builder_at(nir_before_block(nir_start_block(impl)));
+   nir_builder b = nir_builder_at(nir_before_impl(impl));
 
    nir_deref_instr *deref = NULL;
    const struct glsl_type *type = NULL;
index c61e4b0..26737b1 100644 (file)
@@ -935,7 +935,7 @@ nir_lower_goto_ifs_impl(nir_function_impl *impl)
    /* From this point on, it's structured */
    impl->structured = true;
 
-   nir_builder b = nir_builder_at(nir_before_block(nir_start_block(impl)));
+   nir_builder b = nir_builder_at(nir_before_impl(impl));
 
    void *mem_ctx = ralloc_context(b.shader);
 
index 7a26be9..8213a2e 100644 (file)
@@ -98,7 +98,7 @@ emit_output_copies_impl(struct lower_io_state *state, nir_function_impl *impl)
          }
       }
    } else if (impl == state->entrypoint) {
-      b.cursor = nir_before_block(nir_start_block(impl));
+      b.cursor = nir_before_impl(impl);
       emit_copies(&b, &state->old_outputs, &state->new_outputs);
 
       /* For all other shader types, we need to do the copies right before
@@ -275,7 +275,7 @@ static void
 emit_input_copies_impl(struct lower_io_state *state, nir_function_impl *impl)
 {
    if (impl == state->entrypoint) {
-      nir_builder b = nir_builder_at(nir_before_block(nir_start_block(impl)));
+      nir_builder b = nir_builder_at(nir_before_impl(impl));
       emit_copies(&b, &state->old_inputs, &state->new_inputs);
       if (state->shader->info.stage == MESA_SHADER_FRAGMENT)
          fixup_interpolation(state, impl, &b);
index cc2994b..fe93e8d 100644 (file)
@@ -207,7 +207,7 @@ break_all:
        * This provides stability for the algorithm and ensures that we don't
        * accidentally get dependencies out-of-order.
        */
-      nir_cursor cursor = nir_before_block(nir_start_block(impl));
+      nir_cursor cursor = nir_before_impl(impl);
       nir_foreach_block(block, impl) {
          nir_foreach_instr_safe(instr, block) {
             if (instr->pass_flags == STOP_PROCESSING_INSTR_FLAG)
index 5f6ed66..17c5d37 100644 (file)
@@ -2437,7 +2437,7 @@ lower_clipdistance_to_array(nir_shader *nir)
    struct set *deletes = _mesa_set_create(NULL, _mesa_hash_pointer, _mesa_key_pointer_equal);
    nir_foreach_function_impl(impl, nir) {
       bool func_progress = false;
-      nir_builder b = nir_builder_at(nir_before_block(nir_start_block(impl)));
+      nir_builder b = nir_builder_at(nir_before_impl(impl));
       /* create a new deref for the arrayed clipdistance variable at the start of the function */
       nir_deref_instr *clipdist_deref = nir_build_deref_var(&b, dist0);
       nir_def *zero = nir_imm_zero(&b, 1, 32);
index e7f79d9..66d05bf 100644 (file)
@@ -340,8 +340,7 @@ insert_overflow_check(nir_shader *nir, struct agx_xfb_key *key)
 
    /* Extract the current transform feedback shader */
    nir_cf_list list;
-   nir_cf_extract(&list, nir_before_block(nir_start_block(impl)),
-                  nir_after_block(nir_impl_last_block(impl)));
+   nir_cf_extract(&list, nir_before_impl(impl), nir_after_impl(impl));
 
    /* Get a builder for the (now empty) shader */
    nir_builder b = nir_builder_at(nir_after_block(nir_start_block(impl)));
index 6977a9b..eef7b43 100644 (file)
@@ -449,7 +449,7 @@ crocus_setup_uniforms(ASSERTED const struct intel_device_info *devinfo,
 
    nir_function_impl *impl = nir_shader_get_entrypoint(nir);
 
-   nir_builder b = nir_builder_at(nir_before_block(nir_start_block(impl)));
+   nir_builder b = nir_builder_at(nir_before_impl(impl));
 
    nir_def *temp_ubo_name = nir_undef(&b, 1, 32);
    nir_def *temp_const_ubo_name = NULL;
index 32cb731..79ebbcf 100644 (file)
@@ -462,7 +462,7 @@ iris_setup_uniforms(ASSERTED const struct intel_device_info *devinfo,
 
    nir_function_impl *impl = nir_shader_get_entrypoint(nir);
 
-   nir_builder b = nir_builder_at(nir_before_block(nir_start_block(impl)));
+   nir_builder b = nir_builder_at(nir_before_impl(impl));
 
    nir_def *temp_ubo_name = nir_undef(&b, 1, 32);
 
index b73cc5d..0b1bb78 100644 (file)
@@ -612,7 +612,7 @@ vc4_nir_lower_blend(nir_shader *s, struct vc4_compile *c)
          */
         if (c->fs_key->sample_coverage && !c->fs_key->sample_alpha_to_coverage) {
                 nir_function_impl *impl = nir_shader_get_entrypoint(s);
-                nir_builder b = nir_builder_at(nir_after_block(nir_impl_last_block(impl)));
+                nir_builder b = nir_builder_at(nir_after_impl(impl));
 
                 vc4_nir_store_sample_mask(c, &b, nir_load_sample_mask_in(&b));
         }
index 616ead5..4710dbe 100644 (file)
@@ -5093,7 +5093,7 @@ rework_io_vars(nir_shader *nir, nir_variable_mode mode)
          nir_shader_add_variable(nir, var);
          store_location_var(vars, var, nir);
          /* write zero so it doesn't get pruned */
-         nir_builder b = nir_builder_at(nir_after_block(nir_impl_last_block(nir_shader_get_entrypoint(nir))));
+         nir_builder b = nir_builder_at(nir_after_impl(nir_shader_get_entrypoint(nir)));
          nir_def *store = nir_imm_intN_t(&b, j == 3 ? 1 : 0, glsl_type_is_64bit(glsl_without_array(var->type)) ? 64 : 32);
          if (nir_is_arrayed_io(copy, nir->info.stage)) {
             var->type = glsl_array_type(var->type, glsl_array_size(ref->type), glsl_get_explicit_stride(ref->type));
@@ -5605,7 +5605,7 @@ zink_shader_tcs_create(struct zink_screen *screen, nir_shader *tes, unsigned ver
    fn->is_entrypoint = true;
    nir_function_impl *impl = nir_function_impl_create(fn);
 
-   nir_builder b = nir_builder_at(nir_before_block(nir_start_block(impl)));
+   nir_builder b = nir_builder_at(nir_before_impl(impl));
 
    nir_def *invocation_id = nir_load_invocation_id(&b);
 
index 3f819da..759a533 100644 (file)
@@ -1094,7 +1094,7 @@ brw_nir_initialize_mue(nir_shader *nir,
 
    nir_builder b;
    nir_function_impl *entrypoint = nir_shader_get_entrypoint(nir);
-   b = nir_builder_at(nir_before_block(nir_start_block(entrypoint)));
+   b = nir_builder_at(nir_before_impl(entrypoint));
 
    nir_def *dw_off = nir_imm_int(&b, 0);
    nir_def *zerovec = nir_imm_vec4(&b, 0, 0, 0, 0);
index 4ca2496..5a3aaae 100644 (file)
@@ -503,7 +503,7 @@ static void
 lower_ray_query_impl(nir_function_impl *impl, struct lowering_state *state)
 {
    nir_builder _b, *b = &_b;
-   _b = nir_builder_at(nir_before_block(nir_start_block(impl)));
+   _b = nir_builder_at(nir_before_impl(impl));
 
    state->rq_globals = nir_load_ray_query_global_intel(b);
 
index 353e918..d365325 100644 (file)
@@ -50,7 +50,7 @@ lower_rt_intrinsics_impl(nir_function_impl *impl,
 {
    bool progress = false;
 
-   nir_builder build = nir_builder_at(nir_before_block(nir_start_block(impl)));
+   nir_builder build = nir_builder_at(nir_before_impl(impl));
    nir_builder *b = &build;
 
    struct brw_nir_rt_globals_defs globals;
index b8e4cc1..040c631 100644 (file)
@@ -337,7 +337,7 @@ brw_nir_create_trivial_return_shader(const struct brw_compiler *compiler,
 
       nir_function_impl *impl = nir_shader_get_entrypoint(nir);
 
-      b->cursor = nir_before_block(nir_start_block(impl));
+      b->cursor = nir_before_impl(impl);
 
       nir_def *shader_type = nir_load_btd_shader_type_intel(b);
 
index 30858dd..ea5405b 100644 (file)
@@ -54,7 +54,7 @@ build_instance_id(struct lower_multiview_state *state)
    if (state->instance_id == NULL) {
       nir_builder *b = &state->builder;
 
-      b->cursor = nir_before_block(nir_start_block(b->impl));
+      b->cursor = nir_before_impl(b->impl);
 
       /* We use instancing for implementing multiview.  The actual instance id
        * is given by dividing instance_id by the number of views in this
@@ -76,7 +76,7 @@ build_view_index(struct lower_multiview_state *state)
    if (state->view_index == NULL) {
       nir_builder *b = &state->builder;
 
-      b->cursor = nir_before_block(nir_start_block(b->impl));
+      b->cursor = nir_before_impl(b->impl);
 
       assert(state->view_mask != 0);
       if (util_bitcount(state->view_mask) == 1) {
index 9b4e3f9..e81adb7 100644 (file)
@@ -116,7 +116,7 @@ anv_nir_lower_set_vtx_and_prim_count(nir_shader *nir)
    if (state.primitive_count == NULL) {
       nir_builder b;
       nir_function_impl *entrypoint = nir_shader_get_entrypoint(nir);
-      b = nir_builder_at(nir_before_block(nir_start_block(entrypoint)));
+      b = nir_builder_at(nir_before_impl(entrypoint));
       nir_def *zero = nir_imm_int(&b, 0);
       state.primitive_count = anv_nir_prim_count_store(&b, zero);
    }
index b66bebe..d9a5f8e 100644 (file)
@@ -54,7 +54,7 @@ build_instance_id(struct lower_multiview_state *state)
    if (state->instance_id == NULL) {
       nir_builder *b = &state->builder;
 
-      b->cursor = nir_before_block(nir_start_block(b->impl));
+      b->cursor = nir_before_impl(b->impl);
 
       /* We use instancing for implementing multiview.  The actual instance id
        * is given by dividing instance_id by the number of views in this
@@ -76,7 +76,7 @@ build_view_index(struct lower_multiview_state *state)
    if (state->view_index == NULL) {
       nir_builder *b = &state->builder;
 
-      b->cursor = nir_before_block(nir_start_block(b->impl));
+      b->cursor = nir_before_impl(b->impl);
 
       assert(state->view_mask != 0);
       if (util_bitcount(state->view_mask) == 1) {
index 2b016dc..674b6d6 100644 (file)
@@ -130,7 +130,7 @@ st_nir_lower_fog(nir_shader *s, enum gl_fog_mode fog_mode, struct gl_program_par
       }
 
       nir_function_impl *impl = nir_shader_get_entrypoint(s);
-      nir_builder b = nir_builder_at(nir_after_block(nir_impl_last_block(impl)));
+      nir_builder b = nir_builder_at(nir_after_impl(impl));
 
       /* Note: while ARB_fragment_program plus ARB_draw_buffers allows an array
        * of result colors, prog_to_nir generates separate vars per slot so we
index c57dae2..61ff161 100644 (file)
@@ -21,7 +21,7 @@ st_nir_lower_position_invariant(struct nir_shader *s, bool aos,
                                 struct gl_program_parameter_list *paramList)
 {
    nir_function_impl *impl = nir_shader_get_entrypoint(s);
-   nir_builder b = nir_builder_at(nir_before_block(nir_start_block(impl)));
+   nir_builder b = nir_builder_at(nir_before_impl(impl));
 
    nir_def *mvp[4];
    for (int i = 0; i < 4; i++) {
index 9dbbf4c..d5305e8 100644 (file)
@@ -231,7 +231,7 @@ clc_lower_printf_base(nir_shader *nir, unsigned uav_id)
    nir_variable *printf_var = NULL;
    nir_def *printf_deref = NULL;
    nir_foreach_function_impl(impl, nir) {
-      nir_builder b = nir_builder_at(nir_before_block(nir_start_block(impl)));
+      nir_builder b = nir_builder_at(nir_before_impl(impl));
       bool progress = false;
 
       nir_foreach_block(block, impl) {
index 52afe51..108d3b5 100644 (file)
@@ -1894,7 +1894,7 @@ lower_subgroup_id(nir_builder *b, nir_intrinsic_instr *intr, void *data)
    if (intr->intrinsic != nir_intrinsic_load_subgroup_id)
       return false;
 
-   b->cursor = nir_before_block(nir_start_block(b->impl));
+   b->cursor = nir_before_impl(b->impl);
    if (b->shader->info.workgroup_size[1] == 1 &&
        b->shader->info.workgroup_size[2] == 1) {
       /* When using Nx1x1 groups, use a simple stable algorithm
index 8adf491..20bbe1e 100644 (file)
@@ -879,7 +879,7 @@ lower_view_index_to_rt_layer(nir_shader *nir)
                                    nir_metadata_loop_analysis, var);
    } else {
       nir_function_impl *func = nir_shader_get_entrypoint(nir);
-      nir_builder b = nir_builder_at(nir_after_block(nir_impl_last_block(func)));
+      nir_builder b = nir_builder_at(nir_after_impl(func));
       add_layer_write(&b, NULL, var);
    }
 }