From: Dave Airlie <airl...@redhat.com>

The new structs are pretty much based on the radeonsi code,
so it just ports over the uses to them.
---
 src/gallium/drivers/radeonsi/si_compute.c     |  2 +-
 src/gallium/drivers/radeonsi/si_pipe.c        | 50 ++++---------------
 src/gallium/drivers/radeonsi/si_pipe.h        |  6 +--
 src/gallium/drivers/radeonsi/si_shader.c      | 24 ++++-----
 src/gallium/drivers/radeonsi/si_shader.h      | 18 ++-----
 .../drivers/radeonsi/si_shader_internal.h     |  6 +--
 .../drivers/radeonsi/si_shader_tgsi_setup.c   |  9 ++--
 .../drivers/radeonsi/si_state_shaders.c       |  4 +-
 8 files changed, 40 insertions(+), 79 deletions(-)

diff --git a/src/gallium/drivers/radeonsi/si_compute.c 
b/src/gallium/drivers/radeonsi/si_compute.c
index cb320323db3..e8ad6ce0e16 100644
--- a/src/gallium/drivers/radeonsi/si_compute.c
+++ b/src/gallium/drivers/radeonsi/si_compute.c
@@ -86,7 +86,7 @@ static void si_create_compute_state_async(void *job, int 
thread_index)
        struct si_compute *program = (struct si_compute *)job;
        struct si_shader *shader = &program->shader;
        struct si_shader_selector sel;
-       struct si_compiler *compiler;
+       struct ac_llvm_compiler_info *compiler;
        struct pipe_debug_callback *debug = &program->compiler_ctx_state.debug;
 
        assert(!debug->debug_message || debug->async);
diff --git a/src/gallium/drivers/radeonsi/si_pipe.c 
b/src/gallium/drivers/radeonsi/si_pipe.c
index aca61670765..e4906a479c9 100644
--- a/src/gallium/drivers/radeonsi/si_pipe.c
+++ b/src/gallium/drivers/radeonsi/si_pipe.c
@@ -105,51 +105,21 @@ static const struct debug_named_value debug_options[] = {
 };
 
 static void si_init_compiler(struct si_screen *sscreen,
-                            struct si_compiler *compiler)
+                            struct ac_llvm_compiler_info *compiler)
 {
        enum ac_target_machine_options tm_options =
                (sscreen->debug_flags & DBG(SI_SCHED) ? AC_TM_SISCHED : 0) |
                (sscreen->info.chip_class >= GFX9 ? AC_TM_FORCE_ENABLE_XNACK : 
0) |
                (sscreen->info.chip_class < GFX9 ? AC_TM_FORCE_DISABLE_XNACK : 
0) |
-               (!sscreen->llvm_has_working_vgpr_indexing ? 
AC_TM_PROMOTE_ALLOCA_TO_SCRATCH : 0);
+               (!sscreen->llvm_has_working_vgpr_indexing ? 
AC_TM_PROMOTE_ALLOCA_TO_SCRATCH : 0) |
+               (sscreen->debug_flags & DBG(CHECK_IR) ? AC_TM_CHECK_IR : 0);
 
        ac_init_llvm_once();
-       compiler->tm = ac_create_target_machine(sscreen->info.family,
-                                               tm_options, &compiler->triple);
-       if (!compiler->tm)
-               return;
-
-       compiler->target_library_info =
-               gallivm_create_target_library_info(compiler->triple);
-       if (!compiler->target_library_info)
-               return;
-
-       compiler->passmgr = ac_init_passmgr(compiler->target_library_info,
-                                           (sscreen->debug_flags & 
DBG(CHECK_IR)));
-       if (!compiler->passmgr)
-               return;
 
-       /* Get the data layout. */
-       LLVMTargetDataRef data_layout = 
LLVMCreateTargetDataLayout(compiler->tm);
-       if (!data_layout)
-               return;
-       compiler->data_layout = LLVMCopyStringRepOfTargetData(data_layout);
-       LLVMDisposeTargetData(data_layout);
-}
-
-static void si_destroy_compiler(struct si_compiler *compiler)
-{
-       if (compiler->data_layout)
-               LLVMDisposeMessage((char*)compiler->data_layout);
-       if (compiler->passmgr)
-               LLVMDisposePassManager(compiler->passmgr);
-#if HAVE_LLVM >= 0x0700
-       /* This crashes on LLVM 5.0 and 6.0 and Ubuntu 18.04, so leak it there. 
*/
-       if (compiler->target_library_info)
-               
gallivm_dispose_target_library_info(compiler->target_library_info);
-#endif
-       if (compiler->tm)
-               LLVMDisposeTargetMachine(compiler->tm);
+       ac_llvm_compiler_init(compiler,
+                             true,
+                             sscreen->info.family,
+                             tm_options);
 }
 
 /*
@@ -250,7 +220,7 @@ static void si_destroy_context(struct pipe_context *context)
        sctx->ws->fence_reference(&sctx->last_sdma_fence, NULL);
        r600_resource_reference(&sctx->eop_bug_scratch, NULL);
 
-       si_destroy_compiler(&sctx->compiler);
+       ac_llvm_compiler_dispose(&sctx->compiler);
 
        si_saved_cs_reference(&sctx->current_saved_cs, NULL);
 
@@ -659,10 +629,10 @@ static void si_destroy_screen(struct pipe_screen* pscreen)
        util_queue_destroy(&sscreen->shader_compiler_queue_low_priority);
 
        for (i = 0; i < ARRAY_SIZE(sscreen->compiler); i++)
-               si_destroy_compiler(&sscreen->compiler[i]);
+               ac_llvm_compiler_dispose(&sscreen->compiler[i]);
 
        for (i = 0; i < ARRAY_SIZE(sscreen->compiler_lowp); i++)
-               si_destroy_compiler(&sscreen->compiler_lowp[i]);
+               ac_llvm_compiler_dispose(&sscreen->compiler_lowp[i]);
 
        /* Free shader parts. */
        for (i = 0; i < ARRAY_SIZE(parts); i++) {
diff --git a/src/gallium/drivers/radeonsi/si_pipe.h 
b/src/gallium/drivers/radeonsi/si_pipe.h
index bd857f8a349..210e28fe105 100644
--- a/src/gallium/drivers/radeonsi/si_pipe.h
+++ b/src/gallium/drivers/radeonsi/si_pipe.h
@@ -515,12 +515,12 @@ struct si_screen {
        /* Use at most 3 normal compiler threads on quadcore and better.
         * Hyperthreaded CPUs report the number of threads, but we want
         * the number of cores. We only need this many threads for shader-db. */
-       struct si_compiler              compiler[24]; /* used by the queue only 
*/
+       struct ac_llvm_compiler_info    compiler[24]; /* used by the queue only 
*/
 
        struct util_queue               shader_compiler_queue_low_priority;
        /* Use at most 2 low priority threads on quadcore and better.
         * We want to minimize the impact on multithreaded Mesa. */
-       struct si_compiler              compiler_lowp[10];
+       struct ac_llvm_compiler_info    compiler_lowp[10];
 };
 
 struct si_blend_color {
@@ -762,7 +762,7 @@ struct si_context {
        void                            *vs_blit_texcoord;
        struct si_screen                *screen;
        struct pipe_debug_callback      debug;
-       struct si_compiler              compiler; /* only non-threaded 
compilation */
+       struct ac_llvm_compiler_info    compiler; /* only non-threaded 
compilation */
        struct si_shader_ctx_state      fixed_func_tcs_shader;
        struct r600_resource            *wait_mem_scratch;
        unsigned                        wait_mem_number;
diff --git a/src/gallium/drivers/radeonsi/si_shader.c 
b/src/gallium/drivers/radeonsi/si_shader.c
index b04ad217ce3..c7bcf2d3674 100644
--- a/src/gallium/drivers/radeonsi/si_shader.c
+++ b/src/gallium/drivers/radeonsi/si_shader.c
@@ -69,7 +69,7 @@ enum si_arg_regfile {
 
 static void si_init_shader_ctx(struct si_shader_context *ctx,
                               struct si_screen *sscreen,
-                              struct si_compiler *compiler);
+                              struct ac_llvm_compiler_info *compiler);
 
 static void si_llvm_emit_barrier(const struct lp_build_tgsi_action *action,
                                 struct lp_build_tgsi_context *bld_base,
@@ -5642,7 +5642,7 @@ void si_shader_dump(struct si_screen *sscreen, const 
struct si_shader *shader,
 static int si_compile_llvm(struct si_screen *sscreen,
                           struct ac_shader_binary *binary,
                           struct si_shader_config *conf,
-                          struct si_compiler *compiler,
+                          struct ac_llvm_compiler_info *compiler,
                           LLVMModuleRef mod,
                           struct pipe_debug_callback *debug,
                           unsigned processor,
@@ -5720,7 +5720,7 @@ static void si_llvm_build_ret(struct si_shader_context 
*ctx, LLVMValueRef ret)
 /* Generate code for the hardware VS shader stage to go with a geometry shader 
*/
 struct si_shader *
 si_generate_gs_copy_shader(struct si_screen *sscreen,
-                          struct si_compiler *compiler,
+                          struct ac_llvm_compiler_info *compiler,
                           struct si_shader_selector *gs_selector,
                           struct pipe_debug_callback *debug)
 {
@@ -5967,7 +5967,7 @@ static void si_dump_shader_key(unsigned processor, const 
struct si_shader *shade
 
 static void si_init_shader_ctx(struct si_shader_context *ctx,
                               struct si_screen *sscreen,
-                              struct si_compiler *compiler)
+                              struct ac_llvm_compiler_info *compiler)
 {
        struct lp_build_tgsi_context *bld_base;
 
@@ -6749,7 +6749,7 @@ static void si_build_wrapper_function(struct 
si_shader_context *ctx,
 }
 
 int si_compile_tgsi_shader(struct si_screen *sscreen,
-                          struct si_compiler *compiler,
+                          struct ac_llvm_compiler_info *compiler,
                           struct si_shader *shader,
                           struct pipe_debug_callback *debug)
 {
@@ -7090,7 +7090,7 @@ si_get_shader_part(struct si_screen *sscreen,
                   enum pipe_shader_type type,
                   bool prolog,
                   union si_shader_part_key *key,
-                  struct si_compiler *compiler,
+                  struct ac_llvm_compiler_info *compiler,
                   struct pipe_debug_callback *debug,
                   void (*build)(struct si_shader_context *,
                                 union si_shader_part_key *),
@@ -7336,7 +7336,7 @@ static void si_build_vs_prolog_function(struct 
si_shader_context *ctx,
 }
 
 static bool si_get_vs_prolog(struct si_screen *sscreen,
-                            struct si_compiler *compiler,
+                            struct ac_llvm_compiler_info *compiler,
                             struct si_shader *shader,
                             struct pipe_debug_callback *debug,
                             struct si_shader *main_part,
@@ -7364,7 +7364,7 @@ static bool si_get_vs_prolog(struct si_screen *sscreen,
  * Select and compile (or reuse) vertex shader parts (prolog & epilog).
  */
 static bool si_shader_select_vs_parts(struct si_screen *sscreen,
-                                     struct si_compiler *compiler,
+                                     struct ac_llvm_compiler_info *compiler,
                                      struct si_shader *shader,
                                      struct pipe_debug_callback *debug)
 {
@@ -7453,7 +7453,7 @@ static void si_build_tcs_epilog_function(struct 
si_shader_context *ctx,
  * Select and compile (or reuse) TCS parts (epilog).
  */
 static bool si_shader_select_tcs_parts(struct si_screen *sscreen,
-                                      struct si_compiler *compiler,
+                                      struct ac_llvm_compiler_info *compiler,
                                       struct si_shader *shader,
                                       struct pipe_debug_callback *debug)
 {
@@ -7485,7 +7485,7 @@ static bool si_shader_select_tcs_parts(struct si_screen 
*sscreen,
  * Select and compile (or reuse) GS parts (prolog).
  */
 static bool si_shader_select_gs_parts(struct si_screen *sscreen,
-                                     struct si_compiler *compiler,
+                                     struct ac_llvm_compiler_info *compiler,
                                      struct si_shader *shader,
                                      struct pipe_debug_callback *debug)
 {
@@ -7898,7 +7898,7 @@ static void si_build_ps_epilog_function(struct 
si_shader_context *ctx,
  * Select and compile (or reuse) pixel shader parts (prolog & epilog).
  */
 static bool si_shader_select_ps_parts(struct si_screen *sscreen,
-                                     struct si_compiler *compiler,
+                                     struct ac_llvm_compiler_info *compiler,
                                      struct si_shader *shader,
                                      struct pipe_debug_callback *debug)
 {
@@ -8029,7 +8029,7 @@ static void si_fix_resource_usage(struct si_screen 
*sscreen,
        }
 }
 
-int si_shader_create(struct si_screen *sscreen, struct si_compiler *compiler,
+int si_shader_create(struct si_screen *sscreen, struct ac_llvm_compiler_info 
*compiler,
                     struct si_shader *shader,
                     struct pipe_debug_callback *debug)
 {
diff --git a/src/gallium/drivers/radeonsi/si_shader.h 
b/src/gallium/drivers/radeonsi/si_shader.h
index 0ca0a6b9679..78a5d2b4bcc 100644
--- a/src/gallium/drivers/radeonsi/si_shader.h
+++ b/src/gallium/drivers/radeonsi/si_shader.h
@@ -139,6 +139,7 @@
 
 #include "ac_binary.h"
 #include "ac_llvm_build.h"
+#include "ac_llvm_util.h"
 
 #include <stdio.h>
 
@@ -311,20 +312,11 @@ enum {
 
 struct si_shader;
 
-/* Per-thread persistent LLVM objects. */
-struct si_compiler {
-       LLVMTargetMachineRef            tm;
-       const char                      *triple;
-       const char                      *data_layout;
-       LLVMTargetLibraryInfoRef        target_library_info;
-       LLVMPassManagerRef              passmgr;
-};
-
 /* State of the context creating the shader object. */
 struct si_compiler_ctx_state {
        /* Should only be used by si_init_shader_selector_async and
         * si_build_shader_variant if thread_index == -1 (non-threaded). */
-       struct si_compiler              *compiler;
+       struct ac_llvm_compiler_info            *compiler;
 
        /* Used if thread_index == -1 or if debug.async is true. */
        struct pipe_debug_callback      debug;
@@ -656,14 +648,14 @@ struct si_shader_part {
 /* si_shader.c */
 struct si_shader *
 si_generate_gs_copy_shader(struct si_screen *sscreen,
-                          struct si_compiler *compiler,
+                          struct ac_llvm_compiler_info *compiler,
                           struct si_shader_selector *gs_selector,
                           struct pipe_debug_callback *debug);
 int si_compile_tgsi_shader(struct si_screen *sscreen,
-                          struct si_compiler *compiler,
+                          struct ac_llvm_compiler_info *compiler,
                           struct si_shader *shader,
                           struct pipe_debug_callback *debug);
-int si_shader_create(struct si_screen *sscreen, struct si_compiler *compiler,
+int si_shader_create(struct si_screen *sscreen, struct ac_llvm_compiler_info 
*compiler,
                     struct si_shader *shader,
                     struct pipe_debug_callback *debug);
 void si_shader_destroy(struct si_shader *shader);
diff --git a/src/gallium/drivers/radeonsi/si_shader_internal.h 
b/src/gallium/drivers/radeonsi/si_shader_internal.h
index 5c275ab6d9f..2832d9db19f 100644
--- a/src/gallium/drivers/radeonsi/si_shader_internal.h
+++ b/src/gallium/drivers/radeonsi/si_shader_internal.h
@@ -174,7 +174,7 @@ struct si_shader_context {
        /* CS */
        int param_block_size;
 
-       struct si_compiler *compiler;
+       struct ac_llvm_compiler_info *compiler;
 
        /* Preloaded descriptors. */
        LLVMValueRef esgs_ring;
@@ -216,7 +216,7 @@ si_shader_context_from_abi(struct ac_shader_abi *abi)
 }
 
 unsigned si_llvm_compile(LLVMModuleRef M, struct ac_shader_binary *binary,
-                        struct si_compiler *compiler,
+                        struct ac_llvm_compiler_info *compiler,
                         struct pipe_debug_callback *debug);
 
 LLVMTypeRef tgsi2llvmtype(struct lp_build_tgsi_context *bld_base,
@@ -231,7 +231,7 @@ LLVMValueRef si_llvm_bound_index(struct si_shader_context 
*ctx,
 
 void si_llvm_context_init(struct si_shader_context *ctx,
                          struct si_screen *sscreen,
-                         struct si_compiler *compiler);
+                         struct ac_llvm_compiler_info *compiler);
 void si_llvm_context_set_tgsi(struct si_shader_context *ctx,
                              struct si_shader *shader);
 
diff --git a/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c 
b/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c
index de3a6cbf0d7..736fa4b7828 100644
--- a/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c
+++ b/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c
@@ -81,7 +81,7 @@ static void si_diagnostic_handler(LLVMDiagnosticInfoRef di, 
void *context)
  * @returns 0 for success, 1 for failure
  */
 unsigned si_llvm_compile(LLVMModuleRef M, struct ac_shader_binary *binary,
-                        struct si_compiler *compiler,
+                        struct ac_llvm_compiler_info *compiler,
                         struct pipe_debug_callback *debug)
 {
        struct si_llvm_diagnostics diag;
@@ -101,9 +101,8 @@ unsigned si_llvm_compile(LLVMModuleRef M, struct 
ac_shader_binary *binary,
        LLVMContextSetDiagnosticHandler(llvm_ctx, si_diagnostic_handler, &diag);
 
        /* Compile IR*/
-       mem_err = LLVMTargetMachineEmitToMemoryBuffer(compiler->tm, M,
-                                                     LLVMObjectFile, &err,
-                                                     &out_buffer);
+       mem_err = ac_compile_to_memory_buffer(compiler, M,
+                                             &err, &out_buffer);
 
        /* Process Errors/Warnings */
        if (mem_err) {
@@ -972,7 +971,7 @@ static void emit_immediate(struct lp_build_tgsi_context 
*bld_base,
 
 void si_llvm_context_init(struct si_shader_context *ctx,
                          struct si_screen *sscreen,
-                         struct si_compiler *compiler)
+                         struct ac_llvm_compiler_info *compiler)
 {
        struct lp_type type;
 
diff --git a/src/gallium/drivers/radeonsi/si_state_shaders.c 
b/src/gallium/drivers/radeonsi/si_state_shaders.c
index f2569a53be3..74500e899bc 100644
--- a/src/gallium/drivers/radeonsi/si_state_shaders.c
+++ b/src/gallium/drivers/radeonsi/si_state_shaders.c
@@ -1511,7 +1511,7 @@ static void si_build_shader_variant(struct si_shader 
*shader,
 {
        struct si_shader_selector *sel = shader->selector;
        struct si_screen *sscreen = sel->screen;
-       struct si_compiler *compiler;
+       struct ac_llvm_compiler_info *compiler;
        struct pipe_debug_callback *debug = &shader->compiler_ctx_state.debug;
        int r;
 
@@ -1858,7 +1858,7 @@ static void si_init_shader_selector_async(void *job, int 
thread_index)
 {
        struct si_shader_selector *sel = (struct si_shader_selector *)job;
        struct si_screen *sscreen = sel->screen;
-       struct si_compiler *compiler;
+       struct ac_llvm_compiler_info *compiler;
        struct pipe_debug_callback *debug = &sel->compiler_ctx_state.debug;
 
        assert(!debug->debug_message || debug->async);
-- 
2.17.1

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to