treewide: Use nir_before/after_impl for more elaborate cases

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>
This commit is contained in:
Alyssa Rosenzweig
2023-08-28 13:58:57 -04:00
committed by Marge Bot
parent 25cc04c59b
commit f80c57c38f
29 changed files with 35 additions and 39 deletions

View 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);
}

View 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)));

View 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);
}

View 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);

View 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);

View 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(),

View 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.

View 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;

View 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);

View 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);

View 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)

View 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);

View 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)));

View 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;

View 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);

View 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));
}

View 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);

View 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);

View 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);

View 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;

View 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);

View 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) {

View 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);
}

View 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) {

View 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

View 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++) {

View 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) {

View 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

View 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);
}
}