From 646903ed7a940c584ec90aa6f34170b1139953f3 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Fri, 17 Jan 2025 10:53:03 -0500 Subject: [PATCH] nir/print: extract nir_print_function_body this will be used for more concise prints in vtn_bindgen2. Signed-off-by: Alyssa Rosenzweig Reviewed-by: Lionel Landwerlin Reviewed-by: Mary Guillemard Part-of: --- src/compiler/nir/nir.h | 1 + src/compiler/nir/nir_print.c | 26 +++++++++++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index da059443d84..62703855e1c 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -5278,6 +5278,7 @@ unsigned nir_shader_index_vars(nir_shader *shader, nir_variable_mode modes); unsigned nir_function_impl_index_vars(nir_function_impl *impl); void nir_print_shader(nir_shader *shader, FILE *fp); +void nir_print_function_body(nir_function_impl *impl, FILE *fp); void nir_print_shader_annotated(nir_shader *shader, FILE *fp, struct hash_table *errors); void nir_print_instr(const nir_instr *instr, FILE *fp); void nir_print_deref(const nir_deref_instr *deref, FILE *fp); diff --git a/src/compiler/nir/nir_print.c b/src/compiler/nir/nir_print.c index 9dfa5d5b454..11900390946 100644 --- a/src/compiler/nir/nir_print.c +++ b/src/compiler/nir/nir_print.c @@ -2291,15 +2291,17 @@ print_cf_node(nir_cf_node *node, print_state *state, unsigned int tabs) } static void -print_function_impl(nir_function_impl *impl, print_state *state) +print_function_impl(nir_function_impl *impl, print_state *state, bool print_name) { FILE *fp = state->fp; state->max_dest_index = impl->ssa_alloc; - fprintf(fp, "\nimpl %s ", impl->function->name); + if (print_name) { + fprintf(fp, "\nimpl %s ", impl->function->name); - fprintf(fp, "{\n"); + fprintf(fp, "{\n"); + } if (impl->preamble) { print_indentation(1, fp); @@ -2328,7 +2330,11 @@ print_function_impl(nir_function_impl *impl, print_state *state) } print_indentation(1, fp); - fprintf(fp, "block b%u:\n}\n\n", impl->end_block->index); + fprintf(fp, "block b%u:\n", impl->end_block->index); + + if (print_name) { + fprintf(fp, "}\n\n"); + } free(state->float_types); free(state->int_types); @@ -2380,7 +2386,7 @@ print_function(nir_function *function, print_state *state) fprintf(fp, "\n"); if (function->impl != NULL) { - print_function_impl(function->impl, state); + print_function_impl(function->impl, state, true); return; } } @@ -2740,6 +2746,16 @@ print_shader_info(const struct shader_info *info, FILE *fp) } } +void +nir_print_function_body(nir_function_impl *impl, FILE *fp) +{ + print_state state = { 0 }; + init_print_state(&state, impl->function->shader, fp); + state.def_prefix = "%"; + print_function_impl(impl, &state, false); + destroy_print_state(&state); +} + static void _nir_print_shader_annotated(nir_shader *shader, FILE *fp, struct hash_table *annotations,