treewide: Use nir_builder_create more
authorAlyssa Rosenzweig <alyssa@rosenzweig.io>
Mon, 26 Jun 2023 14:42:47 +0000 (10:42 -0400)
committerMarge Bot <emma+marge@anholt.net>
Tue, 27 Jun 2023 18:13:02 +0000 (18:13 +0000)
perl -p0e 's/nir_builder_init\(&([^,]*), /\1 = nir_builder_create(/g' -i $(git grep -l nir_builder_init)

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Konstantin Seurer <konstantin.seurer@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23860>

34 files changed:
src/amd/common/ac_nir_lower_tex.c
src/amd/vulkan/nir/radv_nir_apply_pipeline_layout.c
src/amd/vulkan/nir/radv_nir_lower_fs_barycentric.c
src/amd/vulkan/radv_rt_shader.c
src/asahi/lib/agx_nir_lower_msaa.c
src/compiler/glsl/gl_nir_lower_packed_varyings.c
src/compiler/glsl/glsl_to_nir.cpp
src/compiler/nir/nir_deref.c
src/compiler/nir/nir_from_ssa.c
src/compiler/nir/nir_lower_clip.c
src/compiler/nir/nir_lower_io.c
src/compiler/nir/nir_lower_locals_to_regs.c
src/compiler/nir/nir_lower_passthrough_edgeflags.c
src/compiler/nir/nir_lower_pntc_ytransform.c
src/compiler/nir/nir_lower_point_size_mov.c
src/compiler/nir/nir_lower_returns.c
src/compiler/nir/nir_lower_shader_calls.c
src/compiler/nir/nir_opt_combine_stores.c
src/compiler/nir/nir_opt_comparison_pre.c
src/compiler/nir/nir_opt_conditional_discard.c
src/compiler/nir/nir_opt_find_array_copies.c
src/compiler/spirv/spirv_to_nir.c
src/compiler/spirv/vtn_cfg.c
src/gallium/drivers/d3d12/d3d12_nir_passes.c
src/gallium/drivers/zink/zink_compiler.c
src/imagination/rogue/nir/rogue_nir_pfo.c
src/intel/compiler/brw_mesh.cpp
src/intel/compiler/brw_nir_lower_cs_intrinsics.c
src/intel/compiler/brw_nir_lower_ray_queries.c
src/intel/compiler/brw_nir_rt.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_glsl_to_nir.cpp

index 90ba042..ca4930b 100644 (file)
@@ -523,7 +523,7 @@ ac_nir_lower_tex(nir_shader *nir, const ac_nir_lower_tex_options *options)
       nir_function_impl *impl = nir_shader_get_entrypoint(nir);
 
       struct move_tex_coords_state state;
-      nir_builder_init(&state.toplevel_b, impl);
+      state.toplevel_b = nir_builder_create(impl);
       state.options = options;
       state.num_wqm_vgprs = 0;
 
index 76fba73..a857c28 100644 (file)
@@ -518,7 +518,7 @@ radv_nir_apply_pipeline_layout(nir_shader *shader, struct radv_device *device,
       if (!function->impl)
          continue;
 
-      nir_builder_init(&b, function->impl);
+      b = nir_builder_create(function->impl);
 
       /* Iterate in reverse so load_ubo lowering can look at
        * the vulkan_resource_index to tell if it's an inline
index af98cc4..c035572 100644 (file)
@@ -274,7 +274,7 @@ radv_nir_lower_fs_barycentric(nir_shader *shader, const struct radv_pipeline_key
       if (!function->impl)
          continue;
 
-      nir_builder_init(&b, function->impl);
+      b = nir_builder_create(function->impl);
 
       nir_foreach_block (block, impl) {
          nir_foreach_instr_safe (instr, block) {
index 1b67e95..022306d 100644 (file)
@@ -1534,7 +1534,7 @@ radv_nir_lower_rt_abi(nir_shader *shader, const VkRayTracingPipelineCreateInfoKH
 {
    nir_builder b;
    nir_function_impl *impl = nir_shader_get_entrypoint(shader);
-   nir_builder_init(&b, impl);
+   b = nir_builder_create(impl);
 
    struct rt_variables vars = create_rt_variables(shader, pCreateInfo->flags);
    lower_rt_instructions(shader, &vars, 0);
index 2c60915..c859831 100644 (file)
@@ -167,7 +167,7 @@ insert_sample_mask_write(nir_shader *s)
 {
    nir_builder b;
    nir_function_impl *impl = nir_shader_get_entrypoint(s);
-   nir_builder_init(&b, impl);
+   b = nir_builder_create(impl);
    b.cursor = nir_before_block(nir_start_block(impl));
 
    /* Kill samples that are NOT covered by the mask */
index 939fcf5..0eeedd3 100644 (file)
@@ -1010,7 +1010,7 @@ gl_nir_lower_packed_varyings(const struct gl_constants *consts,
       assert(f->impl == impl);
    }
 
-   nir_builder_init(&state.b, impl);
+   state.b = nir_builder_create(impl);
    state.consts = consts;
    state.prog = prog;
    state.mem_ctx = mem_ctx;
index 7eb7cdc..dda2b63 100644 (file)
@@ -805,7 +805,7 @@ nir_visitor::visit(ir_function_signature *ir)
 
       this->is_global = false;
 
-      nir_builder_init(&b, impl);
+      b = nir_builder_create(impl);
       b.cursor = nir_after_cf_list(&impl->body);
 
       unsigned i = (ir->return_type != glsl_type::void_type) ? 1 : 0;
index 95f9a38..186f58b 100644 (file)
@@ -833,7 +833,7 @@ bool
 nir_rematerialize_derefs_in_use_blocks_impl(nir_function_impl *impl)
 {
    struct rematerialize_deref_state state = { 0 };
-   nir_builder_init(&state.builder, impl);
+   state.builder = nir_builder_create(impl);
 
    nir_foreach_block_unstructured(block, impl) {
       state.block = block;
index 0207d72..ee84730 100644 (file)
@@ -856,7 +856,7 @@ nir_convert_from_ssa_impl(nir_function_impl *impl, bool phi_webs_only)
 
    struct from_ssa_state state;
 
-   nir_builder_init(&state.builder, impl);
+   state.builder = nir_builder_create(impl);
    state.dead_ctx = ralloc_context(NULL);
    state.phi_webs_only = phi_webs_only;
    state.merge_node_table = _mesa_pointer_hash_table_create(NULL);
index e189dc8..eb74c26 100644 (file)
@@ -328,7 +328,7 @@ nir_lower_clip_vs(nir_shader *shader, unsigned ucp_enables, bool use_vars,
    if (!ucp_enables)
       return false;
 
-   nir_builder_init(&b, impl);
+   b = nir_builder_create(impl);
 
    /* NIR should ensure that, even in case of loops/if-else, there
     * should be only a single predecessor block to end_block, which
@@ -409,7 +409,7 @@ nir_lower_clip_gs(nir_shader *shader, unsigned ucp_enables,
    create_clipdist_vars(shader, out, ucp_enables, true,
                         use_clipdist_array);
 
-   nir_builder_init(&b, impl);
+   b = nir_builder_create(impl);
 
    nir_foreach_block(block, impl)
       lower_clip_in_gs_block(&b, block, position, clipvertex, out,
index f25feff..33411bf 100644 (file)
@@ -718,7 +718,7 @@ nir_lower_io_impl(nir_function_impl *impl,
    struct lower_io_state state;
    bool progress = false;
 
-   nir_builder_init(&state.builder, impl);
+   state.builder = nir_builder_create(impl);
    state.dead_ctx = ralloc_context(NULL);
    state.modes = modes;
    state.type_size = type_size;
index 80e7a12..91cb940 100644 (file)
@@ -298,7 +298,7 @@ nir_lower_locals_to_regs_impl(nir_function_impl *impl, uint8_t bool_bitsize)
 {
    struct locals_to_regs_state state;
 
-   nir_builder_init(&state.builder, impl);
+   state.builder = nir_builder_create(impl);
    state.progress = false;
    state.regs_table = _mesa_hash_table_create(NULL, hash_deref, derefs_equal);
    state.bool_bitsize = bool_bitsize;
index 0a73622..2c47deb 100644 (file)
@@ -32,7 +32,7 @@ lower_impl(nir_function_impl *impl)
    nir_variable *in, *out;
    nir_ssa_def *def;
 
-   nir_builder_init(&b, impl);
+   b = nir_builder_create(impl);
    b.cursor = nir_before_cf_list(&impl->body);
 
    /* The edge flag is the last input in st/mesa.  This code is also called by
index 39cb1f3..91626f8 100644 (file)
@@ -116,7 +116,7 @@ nir_lower_pntc_ytransform(nir_shader *shader,
 
    nir_foreach_function(function, shader) {
       if (function->impl) {
-         nir_builder_init(&state.b, function->impl);
+         state.b = nir_builder_create(function->impl);
 
          nir_foreach_block(block, function->impl) {
             lower_pntc_ytransform_block(&state, block);
index bcd9e63..5edb29d 100644 (file)
@@ -40,7 +40,7 @@ lower_impl(nir_function_impl *impl,
    nir_builder b;
    nir_variable *in, *new_out = NULL;
 
-   nir_builder_init(&b, impl);
+   b = nir_builder_create(impl);
 
    in = nir_state_variable_create(shader, glsl_vec4_type(),
                                   "gl_PointSizeClampedMESA",
index d5d43ee..553cf03 100644 (file)
@@ -280,7 +280,7 @@ nir_lower_returns_impl(nir_function_impl *impl)
    state.return_flag = NULL;
    state.has_predicated_return = false;
    state.removed_unreachable_code = false;
-   nir_builder_init(&state.builder, impl);
+   state.builder = nir_builder_create(impl);
 
    bool progress = lower_returns_in_cf_list(&impl->body, &state);
    progress = progress || state.removed_unreachable_code;
index 533a1e4..762db4b 100644 (file)
@@ -560,8 +560,8 @@ spill_ssa_defs_and_lower_shader_calls(nir_shader *shader, uint32_t num_calls,
    }
 
    nir_builder before, after;
-   nir_builder_init(&before, impl);
-   nir_builder_init(&after, impl);
+   before = nir_builder_create(impl);
+   after = nir_builder_create(impl);
 
    call_idx = 0;
    unsigned max_scratch_size = shader->scratch_size;
index e849f54..9bc513c 100644 (file)
@@ -400,7 +400,7 @@ static bool
 combine_stores_impl(struct combine_stores_state *state, nir_function_impl *impl)
 {
    state->progress = false;
-   nir_builder_init(&state->b, impl);
+   state->b = nir_builder_create(impl);
 
    nir_foreach_block(block, impl)
       combine_stores_block(state, block);
index 33e6c51..8ae1070 100644 (file)
@@ -379,7 +379,7 @@ nir_opt_comparison_pre_impl(nir_function_impl *impl)
    nir_builder bld;
 
    block_queue_init(&bq);
-   nir_builder_init(&bld, impl);
+   bld = nir_builder_create(impl);
 
    nir_metadata_require(impl, nir_metadata_dominance);
 
index ba3d0b8..1b24056 100644 (file)
@@ -124,7 +124,7 @@ nir_opt_conditional_discard(nir_shader *shader)
 
    nir_foreach_function(function, shader) {
       if (function->impl) {
-         nir_builder_init(&builder, function->impl);
+         builder = nir_builder_create(function->impl);
 
          bool impl_progress = false;
          nir_foreach_block_safe(block, function->impl) {
index 28626a2..0d1eac9 100644 (file)
@@ -640,7 +640,7 @@ opt_find_array_copies_impl(nir_function_impl *impl)
    s.dead_ctx = ralloc_context(NULL);
    s.var_nodes = _mesa_pointer_hash_table_create(s.dead_ctx);
    s.cast_nodes = _mesa_pointer_hash_table_create(s.dead_ctx);
-   nir_builder_init(&s.builder, impl);
+   s.builder = nir_builder_create(impl);
 
    nir_foreach_block(block, impl) {
       if (opt_find_array_copies_block(&b, block, &s))
index 027bec4..1fd3e0d 100644 (file)
@@ -6629,7 +6629,7 @@ vtn_emit_kernel_entry_point_wrapper(struct vtn_builder *b,
 
    nir_function *main_entry_point = nir_function_create(b->shader, func_name);
    nir_function_impl *impl = nir_function_impl_create(main_entry_point);
-   nir_builder_init(&b->nb, impl);
+   b->nb = nir_builder_create(impl);
    b->nb.cursor = nir_after_cf_list(&impl->body);
    b->func_param_idx = 0;
 
index 4182a1a..4011186 100644 (file)
@@ -225,7 +225,7 @@ vtn_cfg_handle_prepass_instruction(struct vtn_builder *b, SpvOp opcode,
        * directly in our OpFunctionParameter handler.
        */
       nir_function_impl *impl = nir_function_impl_create(func);
-      nir_builder_init(&b->nb, impl);
+      b->nb = nir_builder_create(impl);
       b->nb.cursor = nir_before_cf_list(&impl->body);
       b->nb.exact = b->exact;
 
@@ -627,7 +627,7 @@ vtn_function_emit(struct vtn_builder *b, struct vtn_function *func,
    }
 
    nir_function_impl *impl = func->nir_func->impl;
-   nir_builder_init(&b->nb, impl);
+   b->nb = nir_builder_create(impl);
    b->func = func;
    b->nb.cursor = nir_after_cf_list(&impl->body);
    b->nb.exact = b->exact;
index b606dd8..8a3f236 100644 (file)
@@ -600,7 +600,7 @@ d3d12_add_missing_dual_src_target(struct nir_shader *s,
    assert(missing_mask != 0);
    nir_builder b;
    nir_function_impl *impl = nir_shader_get_entrypoint(s);
-   nir_builder_init(&b, impl);
+   b = nir_builder_create(impl);
    b.cursor = nir_before_cf_list(&impl->body);
 
    nir_ssa_def *zero = nir_imm_zero(&b, 4, 32);
@@ -629,7 +629,7 @@ d3d12_lower_primitive_id(nir_shader *shader)
    nir_builder b;
    nir_function_impl *impl = nir_shader_get_entrypoint(shader);
    nir_ssa_def *primitive_id;
-   nir_builder_init(&b, impl);
+   b = nir_builder_create(impl);
 
    nir_variable *primitive_id_var = nir_variable_create(shader, nir_var_shader_out,
                                                         glsl_uint_type(), "primitive_id");
@@ -745,7 +745,7 @@ d3d12_lower_triangle_strip(nir_shader *shader)
    nir_function_impl *impl = nir_shader_get_entrypoint(shader);
    nir_variable *tmp_vars[VARYING_SLOT_MAX] = {0};
    nir_variable *out_vars[VARYING_SLOT_MAX] = {0};
-   nir_builder_init(&b, impl);
+   b = nir_builder_create(impl);
 
    shader->info.gs.vertices_out = (shader->info.gs.vertices_out - 2) * 3;
 
index 97470fa..638f93a 100644 (file)
@@ -398,7 +398,7 @@ lower_gl_point_gs(nir_shader *shader)
       return false;
 
    nir_function_impl *entry = nir_shader_get_entrypoint(shader);
-   nir_builder_init(&b, entry);
+   b = nir_builder_create(entry);
    b.cursor = nir_before_cf_list(&entry->body);
 
    return nir_shader_instructions_pass(shader, lower_gl_point_gs_instr,
@@ -640,7 +640,7 @@ lower_pv_mode_gs(nir_shader *shader, unsigned prim)
    memset(state.varyings, 0, sizeof(state.varyings));
 
    nir_function_impl *entry = nir_shader_get_entrypoint(shader);
-   nir_builder_init(&b, entry);
+   b = nir_builder_create(entry);
    b.cursor = nir_before_cf_list(&entry->body);
 
    state.primitive_vert_count =
@@ -793,7 +793,7 @@ lower_line_stipple_gs(nir_shader *shader, bool line_rectangular)
    state.line_rectangular = line_rectangular;
    // initialize pos_counter and stipple_counter
    nir_function_impl *entry = nir_shader_get_entrypoint(shader);
-   nir_builder_init(&b, entry);
+   b = nir_builder_create(entry);
    b.cursor = nir_before_cf_list(&entry->body);
    nir_store_var(&b, state.pos_counter, nir_imm_int(&b, 0), 1);
    nir_store_var(&b, state.stipple_counter, nir_imm_float(&b, 0), 1);
@@ -807,7 +807,7 @@ lower_line_stipple_fs(nir_shader *shader)
 {
    nir_builder b;
    nir_function_impl *entry = nir_shader_get_entrypoint(shader);
-   nir_builder_init(&b, entry);
+   b = nir_builder_create(entry);
 
    // create stipple counter
    nir_variable *stipple = nir_variable_create(shader, nir_var_shader_in,
@@ -1122,7 +1122,7 @@ lower_line_smooth_gs(nir_shader *shader)
 
    // initialize pos_counter
    nir_function_impl *entry = nir_shader_get_entrypoint(shader);
-   nir_builder_init(&b, entry);
+   b = nir_builder_create(entry);
    b.cursor = nir_before_cf_list(&entry->body);
    nir_store_var(&b, state.pos_counter, nir_imm_int(&b, 0), 1);
 
@@ -1156,7 +1156,7 @@ lower_line_smooth_fs(nir_shader *shader, bool lower_stipple)
 
       // initialize stipple_pattern
       nir_function_impl *entry = nir_shader_get_entrypoint(shader);
-      nir_builder_init(&b, entry);
+      b = nir_builder_create(entry);
       b.cursor = nir_before_cf_list(&entry->body);
       nir_ssa_def *pattern = nir_load_push_constant(&b, 1, 32,
                                                    nir_imm_int(&b, ZINK_GFX_PUSHCONST_LINE_STIPPLE_PATTERN),
@@ -2540,7 +2540,7 @@ clamp_layer_output(nir_shader *vs, nir_shader *fs, unsigned *next_location)
    } else {
       nir_builder b;
       nir_function_impl *impl = nir_shader_get_entrypoint(vs);
-      nir_builder_init(&b, impl);
+      b = nir_builder_create(impl);
       assert(impl->end_block->predecessors->entries == 1);
       b.cursor = nir_after_cf_list(&impl->body);
       clamp_layer_output_emit(&b, &state);
index c376c45..8ffc0bf 100644 (file)
@@ -61,7 +61,7 @@ void rogue_nir_pfo(nir_shader *shader)
    if (shader->info.stage != MESA_SHADER_FRAGMENT)
       return;
 
-   nir_builder_init(&b, impl);
+   b = nir_builder_create(impl);
 
    nir_foreach_block (block, impl) {
       nir_foreach_instr_safe (instr, block) {
index d558bc9..50e0a19 100644 (file)
@@ -639,7 +639,7 @@ brw_nir_initialize_mue(nir_shader *nir,
 
    nir_builder b;
    nir_function_impl *entrypoint = nir_shader_get_entrypoint(nir);
-   nir_builder_init(&b, entrypoint);
+   b = nir_builder_create(entrypoint);
    b.cursor = nir_before_block(nir_start_block(entrypoint));
 
    nir_ssa_def *dw_off = nir_imm_int(&b, 0);
index be2f772..f5a7b58 100644 (file)
@@ -277,7 +277,7 @@ lower_cs_intrinsics_convert_block(struct lower_intrinsics_state *state,
 static void
 lower_cs_intrinsics_convert_impl(struct lower_intrinsics_state *state)
 {
-   nir_builder_init(&state->builder, state->impl);
+   state->builder = nir_builder_create(state->impl);
 
    nir_foreach_block(block, state->impl) {
       lower_cs_intrinsics_convert_block(state, block);
index 50a287f..c1a9217 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;
-   nir_builder_init(&_b, impl);
+   _b = nir_builder_create(impl);
 
    b->cursor = nir_before_block(nir_start_block(b->impl));
 
index f1c70bd..97402bd 100644 (file)
@@ -505,7 +505,7 @@ brw_nir_create_raygen_trampoline(const struct brw_compiler *compiler,
 
    NIR_PASS_V(nir, brw_nir_lower_rt_intrinsics, devinfo);
 
-   nir_builder_init(&b, nir_shader_get_entrypoint(b.shader));
+   b = nir_builder_create(nir_shader_get_entrypoint(b.shader));
    /* brw_nir_lower_rt_intrinsics will leave us with a btd_global_arg_addr
     * intrinsic which doesn't exist in compute shaders.  We also created one
     * above when we generated the BTD spawn intrinsic.  Now we go through and
index 46a3a2c..4b4ebb5 100644 (file)
@@ -224,7 +224,7 @@ anv_nir_lower_multiview(nir_shader *shader, uint32_t view_mask,
       .view_mask = view_mask,
    };
 
-   nir_builder_init(&state.builder, entrypoint);
+   state.builder = nir_builder_create(entrypoint);
 
    nir_foreach_block(block, entrypoint) {
       nir_foreach_instr_safe(instr, block) {
index 03360bb..786e056 100644 (file)
@@ -122,7 +122,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);
-      nir_builder_init(&b, entrypoint);
+      b = nir_builder_create(entrypoint);
       b.cursor = nir_before_block(nir_start_block(entrypoint));
       nir_ssa_def *zero = nir_imm_int(&b, 0);
       state.primitive_count = anv_nir_prim_count_store(&b, zero);
index 3375714..576439d 100644 (file)
@@ -198,7 +198,7 @@ anv_nir_lower_multiview(nir_shader *shader, uint32_t view_mask)
       .view_mask = view_mask,
    };
 
-   nir_builder_init(&state.builder, entrypoint);
+   state.builder = nir_builder_create(entrypoint);
 
    nir_foreach_block(block, entrypoint) {
       nir_foreach_instr_safe(instr, block) {
index bec2d85..c1f4607 100644 (file)
@@ -241,7 +241,7 @@ st_nir_add_point_size(nir_shader *nir)
 
    nir_builder b;
    nir_function_impl *impl = nir_shader_get_entrypoint(nir);
-   nir_builder_init(&b, impl);
+   b = nir_builder_create(impl);
    bool found = false;
    nir_foreach_block_safe(block, impl) {
       nir_foreach_instr_safe(instr, block) {
@@ -315,7 +315,7 @@ st_nir_zero_initialize_clip_distance(nir_shader *nir)
       return false;
    nir_builder b;
    nir_function_impl *impl = nir_shader_get_entrypoint(nir);
-   nir_builder_init(&b, impl);
+   b = nir_builder_create(impl);
    b.cursor = nir_before_block(nir_start_block(impl));
    if (clip_dist0)
       zero_array_members(&b, clip_dist0);