Module: Mesa
Branch: main
Commit: 5bae345fb78dee8310f73b997b01bf80a140e853
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=5bae345fb78dee8310f73b997b01bf80a140e853

Author: Qiang Yu <[email protected]>
Date:   Mon Oct 16 11:46:55 2023 +0800

radeonsi: move llvm compiler alloc/free into create/destroy funcntion

Reviewed-by: Marek Olšák <[email protected]>
Signed-off-by: Qiang Yu <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25632>

---

 src/gallium/drivers/radeonsi/si_compute.c         |  6 ++--
 src/gallium/drivers/radeonsi/si_pipe.c            | 35 +++++++++++------------
 src/gallium/drivers/radeonsi/si_pipe.h            |  2 +-
 src/gallium/drivers/radeonsi/si_state_shaders.cpp | 18 ++++--------
 4 files changed, 26 insertions(+), 35 deletions(-)

diff --git a/src/gallium/drivers/radeonsi/si_compute.c 
b/src/gallium/drivers/radeonsi/si_compute.c
index c84d6e595f9..ce3e29235cb 100644
--- a/src/gallium/drivers/radeonsi/si_compute.c
+++ b/src/gallium/drivers/radeonsi/si_compute.c
@@ -100,10 +100,8 @@ static void si_create_compute_state_async(void *job, void 
*gdata, int thread_ind
    assert(thread_index < ARRAY_SIZE(sscreen->compiler));
    compiler = &sscreen->compiler[thread_index];
 
-   if (!*compiler) {
-      *compiler = CALLOC_STRUCT(ac_llvm_compiler);
-      si_init_compiler(sscreen, *compiler);
-   }
+   if (!*compiler)
+      *compiler = si_create_llvm_compiler(sscreen);
 
    assert(program->ir_type == PIPE_SHADER_IR_NIR);
    si_nir_scan_shader(sscreen, sel->nir, &sel->info);
diff --git a/src/gallium/drivers/radeonsi/si_pipe.c 
b/src/gallium/drivers/radeonsi/si_pipe.c
index 741a47a6d64..f44151616e0 100644
--- a/src/gallium/drivers/radeonsi/si_pipe.c
+++ b/src/gallium/drivers/radeonsi/si_pipe.c
@@ -130,8 +130,12 @@ static const struct debug_named_value test_options[] = {
    DEBUG_NAMED_VALUE_END /* must be last */
 };
 
-bool si_init_compiler(struct si_screen *sscreen, struct ac_llvm_compiler 
*compiler)
+struct ac_llvm_compiler *si_create_llvm_compiler(struct si_screen *sscreen)
 {
+   struct ac_llvm_compiler *compiler = CALLOC_STRUCT(ac_llvm_compiler);
+   if (!compiler)
+      return NULL;
+
    /* Only create the less-optimizing version of the compiler on APUs
     * predating Ryzen (Raven). */
    bool create_low_opt_compiler =
@@ -142,13 +146,13 @@ bool si_init_compiler(struct si_screen *sscreen, struct 
ac_llvm_compiler *compil
       (create_low_opt_compiler ? AC_TM_CREATE_LOW_OPT : 0);
 
    if (!ac_init_llvm_compiler(compiler, sscreen->info.family, tm_options))
-      return false;
+      return NULL;
 
    compiler->passes = ac_create_llvm_passes(compiler->tm);
    if (compiler->low_opt_tm)
       compiler->low_opt_passes = ac_create_llvm_passes(compiler->low_opt_tm);
 
-   return true;
+   return compiler;
 }
 
 void si_init_aux_async_compute_ctx(struct si_screen *sscreen)
@@ -166,9 +170,10 @@ void si_init_aux_async_compute_ctx(struct si_screen 
*sscreen)
       ((struct 
si_context*)sscreen->async_compute_context)->cs_max_waves_per_sh = 2;
 }
 
-static void si_destroy_compiler(struct ac_llvm_compiler *compiler)
+static void si_destroy_llvm_compiler(struct ac_llvm_compiler *compiler)
 {
    ac_destroy_llvm_compiler(compiler);
+   FREE(compiler);
 }
 
 
@@ -341,10 +346,8 @@ static void si_destroy_context(struct pipe_context 
*context)
    si_resource_reference(&sctx->shadowing.registers, NULL);
    si_resource_reference(&sctx->shadowing.csa, NULL);
 
-   if (sctx->compiler) {
-      si_destroy_compiler(sctx->compiler);
-      FREE(sctx->compiler);
-   }
+   if (sctx->compiler)
+      si_destroy_llvm_compiler(sctx->compiler);
 
    si_saved_cs_reference(&sctx->current_saved_cs, NULL);
 
@@ -996,17 +999,13 @@ static void si_destroy_screen(struct pipe_screen *pscreen)
    glsl_type_singleton_decref();
 
    for (i = 0; i < ARRAY_SIZE(sscreen->compiler); i++) {
-      if (sscreen->compiler[i]) {
-         si_destroy_compiler(sscreen->compiler[i]);
-         FREE(sscreen->compiler[i]);
-      }
+      if (sscreen->compiler[i])
+         si_destroy_llvm_compiler(sscreen->compiler[i]);
    }
 
    for (i = 0; i < ARRAY_SIZE(sscreen->compiler_lowp); i++) {
-      if (sscreen->compiler_lowp[i]) {
-         si_destroy_compiler(sscreen->compiler_lowp[i]);
-         FREE(sscreen->compiler_lowp[i]);
-      }
+      if (sscreen->compiler_lowp[i])
+         si_destroy_llvm_compiler(sscreen->compiler_lowp[i]);
    }
 
    /* Free shader parts. */
@@ -1209,8 +1208,8 @@ static struct pipe_screen 
*radeonsi_screen_create_impl(struct radeon_winsys *ws,
    /* Initialize just one compiler instance to check for errors. The other 
compiler instances are
     * initialized on demand.
     */
-   sscreen->compiler[0] = CALLOC_STRUCT(ac_llvm_compiler);
-   if (!si_init_compiler(sscreen, sscreen->compiler[0])) {
+   sscreen->compiler[0] = si_create_llvm_compiler(sscreen);
+   if (!sscreen->compiler[0]) {
       /* The callee prints the error message. */
       FREE(sscreen->nir_options);
       FREE(sscreen);
diff --git a/src/gallium/drivers/radeonsi/si_pipe.h 
b/src/gallium/drivers/radeonsi/si_pipe.h
index 3bfaf6d426b..0901e0c759e 100644
--- a/src/gallium/drivers/radeonsi/si_pipe.h
+++ b/src/gallium/drivers/radeonsi/si_pipe.h
@@ -1585,7 +1585,7 @@ void si_emit_initial_compute_regs(struct si_context 
*sctx, struct radeon_cmdbuf
 void si_init_compute_functions(struct si_context *sctx);
 
 /* si_pipe.c */
-bool si_init_compiler(struct si_screen *sscreen, struct ac_llvm_compiler 
*compiler);
+struct ac_llvm_compiler *si_create_llvm_compiler(struct si_screen *sscreen);
 void si_init_aux_async_compute_ctx(struct si_screen *sscreen);
 struct si_context *si_get_aux_context(struct si_aux_context *ctx);
 void si_put_aux_context_flush(struct si_aux_context *ctx);
diff --git a/src/gallium/drivers/radeonsi/si_state_shaders.cpp 
b/src/gallium/drivers/radeonsi/si_state_shaders.cpp
index c6d0010e6c2..14f9ef17ecb 100644
--- a/src/gallium/drivers/radeonsi/si_state_shaders.cpp
+++ b/src/gallium/drivers/radeonsi/si_state_shaders.cpp
@@ -2482,10 +2482,8 @@ static void si_build_shader_variant(struct si_shader 
*shader, int thread_index,
       compiler = &shader->compiler_ctx_state.compiler;
    }
 
-   if (!*compiler) {
-      *compiler = CALLOC_STRUCT(ac_llvm_compiler);
-      si_init_compiler(sscreen, *compiler);
-   }
+   if (!*compiler)
+      *compiler = si_create_llvm_compiler(sscreen);
 
    if (unlikely(!si_create_shader_variant(sscreen, *compiler, shader, debug))) 
{
       PRINT_ERR("Failed to build shader variant (type=%u)\n", sel->stage);
@@ -2700,10 +2698,8 @@ current_not_ready:
 
    util_queue_fence_init(&shader->ready);
 
-   if (!sctx->compiler) {
-      sctx->compiler = CALLOC_STRUCT(ac_llvm_compiler);
-      si_init_compiler(sctx->screen, sctx->compiler);
-   }
+   if (!sctx->compiler)
+      sctx->compiler = si_create_llvm_compiler(sctx->screen);
 
    shader->selector = sel;
    *((SHADER_KEY_TYPE*)&shader->key) = *key;
@@ -2912,10 +2908,8 @@ static void si_init_shader_selector_async(void *job, 
void *gdata, int thread_ind
    assert(thread_index < (int)ARRAY_SIZE(sscreen->compiler));
    compiler = &sscreen->compiler[thread_index];
 
-   if (!*compiler) {
-      *compiler = CALLOC_STRUCT(ac_llvm_compiler);
-      si_init_compiler(sscreen, *compiler);
-   }
+   if (!*compiler)
+      *compiler = si_create_llvm_compiler(sscreen);
 
    /* Serialize NIR to save memory. Monolithic shader variants
     * have to deserialize NIR before compilation.

Reply via email to