OSDN Git Service

radeonsi: add struct si_compiler containing LLVMTargetMachineRef
authorMarek Olšák <marek.olsak@amd.com>
Mon, 9 Apr 2018 22:26:05 +0000 (18:26 -0400)
committerMarek Olšák <marek.olsak@amd.com>
Fri, 27 Apr 2018 21:56:04 +0000 (17:56 -0400)
It will contain more variables.

Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
Tested-by: Benedikt Schemmer <ben at besd.de>
Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
src/gallium/drivers/radeonsi/si_compute.c
src/gallium/drivers/radeonsi/si_pipe.c
src/gallium/drivers/radeonsi/si_pipe.h
src/gallium/drivers/radeonsi/si_shader.c
src/gallium/drivers/radeonsi/si_shader.h
src/gallium/drivers/radeonsi/si_shader_internal.h
src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c
src/gallium/drivers/radeonsi/si_state_shaders.c

index 69c3dce..e95e79c 100644 (file)
@@ -86,13 +86,13 @@ 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;
-       LLVMTargetMachineRef tm;
+       struct si_compiler *compiler;
        struct pipe_debug_callback *debug = &program->compiler_ctx_state.debug;
 
        assert(!debug->debug_message || debug->async);
        assert(thread_index >= 0);
-       assert(thread_index < ARRAY_SIZE(program->screen->tm));
-       tm = program->screen->tm[thread_index];
+       assert(thread_index < ARRAY_SIZE(program->screen->compiler));
+       compiler = &program->screen->compiler[thread_index];
 
        memset(&sel, 0, sizeof(sel));
 
@@ -123,7 +123,7 @@ static void si_create_compute_state_async(void *job, int thread_index)
        program->uses_bindless_samplers = sel.info.uses_bindless_samplers;
        program->uses_bindless_images = sel.info.uses_bindless_images;
 
-       if (si_shader_create(program->screen, tm, &program->shader, debug)) {
+       if (si_shader_create(program->screen, compiler, &program->shader, debug)) {
                program->shader.compilation_failed = true;
        } else {
                bool scratch_enabled = shader->config.scratch_bytes_per_wave > 0;
index c5ee9f4..60bc189 100644 (file)
@@ -102,6 +102,24 @@ static const struct debug_named_value debug_options[] = {
        DEBUG_NAMED_VALUE_END /* must be last */
 };
 
+static void si_init_compiler(struct si_screen *sscreen,
+                            struct si_compiler *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);
+
+       compiler->tm = ac_create_target_machine(sscreen->info.family, tm_options);
+}
+
+static void si_destroy_compiler(struct si_compiler *compiler)
+{
+       if (compiler->tm)
+               LLVMDisposeTargetMachine(compiler->tm);
+}
+
 /*
  * pipe_context
  */
@@ -200,7 +218,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);
 
-       LLVMDisposeTargetMachine(sctx->tm);
+       si_destroy_compiler(&sctx->compiler);
 
        si_saved_cs_reference(&sctx->current_saved_cs, NULL);
 
@@ -285,18 +303,6 @@ static void si_emit_string_marker(struct pipe_context *ctx,
                u_log_printf(sctx->log, "\nString marker: %*s\n", len, string);
 }
 
-static LLVMTargetMachineRef
-si_create_llvm_target_machine(struct si_screen *sscreen)
-{
-       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);
-
-       return ac_create_target_machine(sscreen->info.family, tm_options);
-}
-
 static void si_set_debug_callback(struct pipe_context *ctx,
                                  const struct pipe_debug_callback *cb)
 {
@@ -549,7 +555,7 @@ static struct pipe_context *si_create_context(struct pipe_screen *screen,
        sctx->scratch_waves = MAX2(32 * sscreen->info.num_good_compute_units,
                                   max_threads_per_block / 64);
 
-       sctx->tm = si_create_llvm_target_machine(sscreen);
+       si_init_compiler(sscreen, &sctx->compiler);
 
        /* Bindless handles. */
        sctx->tex_handles = _mesa_hash_table_create(NULL, _mesa_hash_pointer,
@@ -624,13 +630,11 @@ static void si_destroy_screen(struct pipe_screen* pscreen)
        util_queue_destroy(&sscreen->shader_compiler_queue);
        util_queue_destroy(&sscreen->shader_compiler_queue_low_priority);
 
-       for (i = 0; i < ARRAY_SIZE(sscreen->tm); i++)
-               if (sscreen->tm[i])
-                       LLVMDisposeTargetMachine(sscreen->tm[i]);
+       for (i = 0; i < ARRAY_SIZE(sscreen->compiler); i++)
+               si_destroy_compiler(&sscreen->compiler[i]);
 
-       for (i = 0; i < ARRAY_SIZE(sscreen->tm_low_priority); i++)
-               if (sscreen->tm_low_priority[i])
-                       LLVMDisposeTargetMachine(sscreen->tm_low_priority[i]);
+       for (i = 0; i < ARRAY_SIZE(sscreen->compiler_lowp); i++)
+               si_destroy_compiler(&sscreen->compiler_lowp[i]);
 
        /* Free shader parts. */
        for (i = 0; i < ARRAY_SIZE(parts); i++) {
@@ -837,9 +841,9 @@ struct pipe_screen *radeonsi_screen_create(struct radeon_winsys *ws,
         */
        num_threads = sysconf(_SC_NPROCESSORS_ONLN);
        num_threads = MAX2(1, num_threads - 1);
-       num_compiler_threads = MIN2(num_threads, ARRAY_SIZE(sscreen->tm));
+       num_compiler_threads = MIN2(num_threads, ARRAY_SIZE(sscreen->compiler));
        num_compiler_threads_lowprio =
-               MIN2(num_threads, ARRAY_SIZE(sscreen->tm_low_priority));
+               MIN2(num_threads, ARRAY_SIZE(sscreen->compiler_lowp));
 
        if (!util_queue_init(&sscreen->shader_compiler_queue, "si_shader",
                             32, num_compiler_threads,
@@ -1003,9 +1007,9 @@ struct pipe_screen *radeonsi_screen_create(struct radeon_winsys *ws,
                sscreen->debug_flags |= DBG_ALL_SHADERS;
 
        for (i = 0; i < num_compiler_threads; i++)
-               sscreen->tm[i] = si_create_llvm_target_machine(sscreen);
+               si_init_compiler(sscreen, &sscreen->compiler[i]);
        for (i = 0; i < num_compiler_threads_lowprio; i++)
-               sscreen->tm_low_priority[i] = si_create_llvm_target_machine(sscreen);
+               si_init_compiler(sscreen, &sscreen->compiler_lowp[i]);
 
        /* Create the auxiliary context. This must be done last. */
        sscreen->aux_context = si_create_context(&sscreen->b, 0);
index 8235095..54c9b72 100644 (file)
@@ -530,12 +530,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. */
-       LLVMTargetMachineRef            tm[3]; /* used by the queue only */
+       struct si_compiler              compiler[3]; /* 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. */
-       LLVMTargetMachineRef            tm_low_priority[2]; /* at most 2 threads */
+       struct si_compiler              compiler_lowp[2]; /* at most 2 threads */
 };
 
 struct si_blend_color {
@@ -776,7 +776,7 @@ struct si_context {
        void                            *vs_blit_texcoord;
        struct si_screen                *screen;
        struct pipe_debug_callback      debug;
-       LLVMTargetMachineRef            tm; /* only non-threaded compilation */
+       struct si_compiler              compiler; /* only non-threaded compilation */
        struct si_shader_ctx_state      fixed_func_tcs_shader;
        struct r600_resource            *wait_mem_scratch;
        unsigned                        wait_mem_number;
index 9c27c5a..e8d08cd 100644 (file)
@@ -77,7 +77,7 @@ enum si_arg_regfile {
 
 static void si_init_shader_ctx(struct si_shader_context *ctx,
                               struct si_screen *sscreen,
-                              LLVMTargetMachineRef tm);
+                              struct si_compiler *compiler);
 
 static void si_llvm_emit_barrier(const struct lp_build_tgsi_action *action,
                                 struct lp_build_tgsi_context *bld_base,
@@ -5640,7 +5640,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,
-                          LLVMTargetMachineRef tm,
+                          struct si_compiler *compiler,
                           LLVMModuleRef mod,
                           struct pipe_debug_callback *debug,
                           unsigned processor,
@@ -5666,7 +5666,7 @@ static int si_compile_llvm(struct si_screen *sscreen,
        }
 
        if (!si_replace_shader(count, binary)) {
-               r = si_llvm_compile(mod, binary, tm, debug);
+               r = si_llvm_compile(mod, binary, compiler, debug);
                if (r)
                        return r;
        }
@@ -5718,7 +5718,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,
-                          LLVMTargetMachineRef tm,
+                          struct si_compiler *compiler,
                           struct si_shader_selector *gs_selector,
                           struct pipe_debug_callback *debug)
 {
@@ -5749,7 +5749,7 @@ si_generate_gs_copy_shader(struct si_screen *sscreen,
        shader->selector = gs_selector;
        shader->is_gs_copy_shader = true;
 
-       si_init_shader_ctx(&ctx, sscreen, tm);
+       si_init_shader_ctx(&ctx, sscreen, compiler);
        ctx.shader = shader;
        ctx.type = PIPE_SHADER_VERTEX;
 
@@ -5844,7 +5844,7 @@ si_generate_gs_copy_shader(struct si_screen *sscreen,
        si_llvm_optimize_module(&ctx);
 
        r = si_compile_llvm(sscreen, &ctx.shader->binary,
-                           &ctx.shader->config, ctx.tm,
+                           &ctx.shader->config, ctx.compiler,
                            ctx.gallivm.module,
                            debug, PIPE_SHADER_GEOMETRY,
                            "GS Copy Shader");
@@ -5966,11 +5966,11 @@ 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,
-                              LLVMTargetMachineRef tm)
+                              struct si_compiler *compiler)
 {
        struct lp_build_tgsi_context *bld_base;
 
-       si_llvm_context_init(ctx, sscreen, tm);
+       si_llvm_context_init(ctx, sscreen, compiler);
 
        bld_base = &ctx->bld_base;
        bld_base->emit_fetch_funcs[TGSI_FILE_CONSTANT] = fetch_constant;
@@ -6748,7 +6748,7 @@ static void si_build_wrapper_function(struct si_shader_context *ctx,
 }
 
 int si_compile_tgsi_shader(struct si_screen *sscreen,
-                          LLVMTargetMachineRef tm,
+                          struct si_compiler *compiler,
                           struct si_shader *shader,
                           bool is_monolithic,
                           struct pipe_debug_callback *debug)
@@ -6768,7 +6768,7 @@ int si_compile_tgsi_shader(struct si_screen *sscreen,
                si_dump_streamout(&sel->so);
        }
 
-       si_init_shader_ctx(&ctx, sscreen, tm);
+       si_init_shader_ctx(&ctx, sscreen, compiler);
        si_llvm_context_set_tgsi(&ctx, shader);
        ctx.separate_prolog = !is_monolithic;
 
@@ -6978,7 +6978,7 @@ int si_compile_tgsi_shader(struct si_screen *sscreen,
               LLVMPointerTypeKind);
 
        /* Compile to bytecode. */
-       r = si_compile_llvm(sscreen, &shader->binary, &shader->config, tm,
+       r = si_compile_llvm(sscreen, &shader->binary, &shader->config, compiler,
                            ctx.gallivm.module, debug, ctx.type, "TGSI shader");
        si_llvm_dispose(&ctx);
        if (r) {
@@ -7089,7 +7089,7 @@ si_get_shader_part(struct si_screen *sscreen,
                   enum pipe_shader_type type,
                   bool prolog,
                   union si_shader_part_key *key,
-                  LLVMTargetMachineRef tm,
+                  struct si_compiler *compiler,
                   struct pipe_debug_callback *debug,
                   void (*build)(struct si_shader_context *,
                                 union si_shader_part_key *),
@@ -7114,7 +7114,7 @@ si_get_shader_part(struct si_screen *sscreen,
        struct si_shader shader = {};
        struct si_shader_context ctx;
 
-       si_init_shader_ctx(&ctx, sscreen, tm);
+       si_init_shader_ctx(&ctx, sscreen, compiler);
        ctx.shader = &shader;
        ctx.type = type;
 
@@ -7145,7 +7145,7 @@ si_get_shader_part(struct si_screen *sscreen,
        /* Compile. */
        si_llvm_optimize_module(&ctx);
 
-       if (si_compile_llvm(sscreen, &result->binary, &result->config, tm,
+       if (si_compile_llvm(sscreen, &result->binary, &result->config, compiler,
                            ctx.ac.module, debug, ctx.type, name)) {
                FREE(result);
                result = NULL;
@@ -7335,7 +7335,7 @@ static void si_build_vs_prolog_function(struct si_shader_context *ctx,
 }
 
 static bool si_get_vs_prolog(struct si_screen *sscreen,
-                            LLVMTargetMachineRef tm,
+                            struct si_compiler *compiler,
                             struct si_shader *shader,
                             struct pipe_debug_callback *debug,
                             struct si_shader *main_part,
@@ -7353,7 +7353,7 @@ static bool si_get_vs_prolog(struct si_screen *sscreen,
 
        shader->prolog =
                si_get_shader_part(sscreen, &sscreen->vs_prologs,
-                                  PIPE_SHADER_VERTEX, true, &prolog_key, tm,
+                                  PIPE_SHADER_VERTEX, true, &prolog_key, compiler,
                                   debug, si_build_vs_prolog_function,
                                   "Vertex Shader Prolog");
        return shader->prolog != NULL;
@@ -7363,11 +7363,11 @@ 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,
-                                     LLVMTargetMachineRef tm,
+                                     struct si_compiler *compiler,
                                      struct si_shader *shader,
                                      struct pipe_debug_callback *debug)
 {
-       return si_get_vs_prolog(sscreen, tm, shader, debug, shader,
+       return si_get_vs_prolog(sscreen, compiler, shader, debug, shader,
                                &shader->key.part.vs.prolog);
 }
 
@@ -7452,7 +7452,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,
-                                      LLVMTargetMachineRef tm,
+                                      struct si_compiler *compiler,
                                       struct si_shader *shader,
                                       struct pipe_debug_callback *debug)
 {
@@ -7460,7 +7460,7 @@ static bool si_shader_select_tcs_parts(struct si_screen *sscreen,
                struct si_shader *ls_main_part =
                        shader->key.part.tcs.ls->main_shader_part_ls;
 
-               if (!si_get_vs_prolog(sscreen, tm, shader, debug, ls_main_part,
+               if (!si_get_vs_prolog(sscreen, compiler, shader, debug, ls_main_part,
                                      &shader->key.part.tcs.ls_prolog))
                        return false;
 
@@ -7474,7 +7474,7 @@ static bool si_shader_select_tcs_parts(struct si_screen *sscreen,
 
        shader->epilog = si_get_shader_part(sscreen, &sscreen->tcs_epilogs,
                                            PIPE_SHADER_TESS_CTRL, false,
-                                           &epilog_key, tm, debug,
+                                           &epilog_key, compiler, debug,
                                            si_build_tcs_epilog_function,
                                            "Tessellation Control Shader Epilog");
        return shader->epilog != NULL;
@@ -7484,7 +7484,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,
-                                     LLVMTargetMachineRef tm,
+                                     struct si_compiler *compiler,
                                      struct si_shader *shader,
                                      struct pipe_debug_callback *debug)
 {
@@ -7493,7 +7493,7 @@ static bool si_shader_select_gs_parts(struct si_screen *sscreen,
                        shader->key.part.gs.es->main_shader_part_es;
 
                if (shader->key.part.gs.es->type == PIPE_SHADER_VERTEX &&
-                   !si_get_vs_prolog(sscreen, tm, shader, debug, es_main_part,
+                   !si_get_vs_prolog(sscreen, compiler, shader, debug, es_main_part,
                                      &shader->key.part.gs.vs_prolog))
                        return false;
 
@@ -7509,7 +7509,7 @@ static bool si_shader_select_gs_parts(struct si_screen *sscreen,
 
        shader->prolog2 = si_get_shader_part(sscreen, &sscreen->gs_prologs,
                                            PIPE_SHADER_GEOMETRY, true,
-                                           &prolog_key, tm, debug,
+                                           &prolog_key, compiler, debug,
                                            si_build_gs_prolog_function,
                                            "Geometry Shader Prolog");
        return shader->prolog2 != NULL;
@@ -7897,7 +7897,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,
-                                     LLVMTargetMachineRef tm,
+                                     struct si_compiler *compiler,
                                      struct si_shader *shader,
                                      struct pipe_debug_callback *debug)
 {
@@ -7912,7 +7912,7 @@ static bool si_shader_select_ps_parts(struct si_screen *sscreen,
                shader->prolog =
                        si_get_shader_part(sscreen, &sscreen->ps_prologs,
                                           PIPE_SHADER_FRAGMENT, true,
-                                          &prolog_key, tm, debug,
+                                          &prolog_key, compiler, debug,
                                           si_build_ps_prolog_function,
                                           "Fragment Shader Prolog");
                if (!shader->prolog)
@@ -7925,7 +7925,7 @@ static bool si_shader_select_ps_parts(struct si_screen *sscreen,
        shader->epilog =
                si_get_shader_part(sscreen, &sscreen->ps_epilogs,
                                   PIPE_SHADER_FRAGMENT, false,
-                                  &epilog_key, tm, debug,
+                                  &epilog_key, compiler, debug,
                                   si_build_ps_epilog_function,
                                   "Fragment Shader Epilog");
        if (!shader->epilog)
@@ -8028,7 +8028,7 @@ static void si_fix_resource_usage(struct si_screen *sscreen,
        }
 }
 
-int si_shader_create(struct si_screen *sscreen, LLVMTargetMachineRef tm,
+int si_shader_create(struct si_screen *sscreen, struct si_compiler *compiler,
                     struct si_shader *shader,
                     struct pipe_debug_callback *debug)
 {
@@ -8046,7 +8046,7 @@ int si_shader_create(struct si_screen *sscreen, LLVMTargetMachineRef tm,
                /* Monolithic shader (compiled as a whole, has many variants,
                 * may take a long time to compile).
                 */
-               r = si_compile_tgsi_shader(sscreen, tm, shader, true, debug);
+               r = si_compile_tgsi_shader(sscreen, compiler, shader, true, debug);
                if (r)
                        return r;
        } else {
@@ -8086,21 +8086,21 @@ int si_shader_create(struct si_screen *sscreen, LLVMTargetMachineRef tm,
                /* Select prologs and/or epilogs. */
                switch (sel->type) {
                case PIPE_SHADER_VERTEX:
-                       if (!si_shader_select_vs_parts(sscreen, tm, shader, debug))
+                       if (!si_shader_select_vs_parts(sscreen, compiler, shader, debug))
                                return -1;
                        break;
                case PIPE_SHADER_TESS_CTRL:
-                       if (!si_shader_select_tcs_parts(sscreen, tm, shader, debug))
+                       if (!si_shader_select_tcs_parts(sscreen, compiler, shader, debug))
                                return -1;
                        break;
                case PIPE_SHADER_TESS_EVAL:
                        break;
                case PIPE_SHADER_GEOMETRY:
-                       if (!si_shader_select_gs_parts(sscreen, tm, shader, debug))
+                       if (!si_shader_select_gs_parts(sscreen, compiler, shader, debug))
                                return -1;
                        break;
                case PIPE_SHADER_FRAGMENT:
-                       if (!si_shader_select_ps_parts(sscreen, tm, shader, debug))
+                       if (!si_shader_select_ps_parts(sscreen, compiler, shader, debug))
                                return -1;
 
                        /* Make sure we have at least as many VGPRs as there
index c26ccaf..8c479d6 100644 (file)
@@ -311,11 +311,16 @@ enum {
 
 struct si_shader;
 
+/* Per-thread persistent LLVM objects. */
+struct si_compiler {
+       LLVMTargetMachineRef            tm;
+};
+
 /* 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). */
-       LLVMTargetMachineRef            tm;
+       struct si_compiler              *compiler;
 
        /* Used if thread_index == -1 or if debug.async is true. */
        struct pipe_debug_callback      debug;
@@ -646,15 +651,15 @@ struct si_shader_part {
 /* si_shader.c */
 struct si_shader *
 si_generate_gs_copy_shader(struct si_screen *sscreen,
-                          LLVMTargetMachineRef tm,
+                          struct si_compiler *compiler,
                           struct si_shader_selector *gs_selector,
                           struct pipe_debug_callback *debug);
 int si_compile_tgsi_shader(struct si_screen *sscreen,
-                          LLVMTargetMachineRef tm,
+                          struct si_compiler *compiler,
                           struct si_shader *shader,
                           bool is_monolithic,
                           struct pipe_debug_callback *debug);
-int si_shader_create(struct si_screen *sscreen, LLVMTargetMachineRef tm,
+int si_shader_create(struct si_screen *sscreen, struct si_compiler *compiler,
                     struct si_shader *shader,
                     struct pipe_debug_callback *debug);
 void si_shader_destroy(struct si_shader *shader);
index afcc14e..0a34717 100644 (file)
@@ -179,7 +179,7 @@ struct si_shader_context {
        /* CS */
        int param_block_size;
 
-       LLVMTargetMachineRef tm;
+       struct si_compiler *compiler;
 
        /* Preloaded descriptors. */
        LLVMValueRef esgs_ring;
@@ -221,7 +221,7 @@ si_shader_context_from_abi(struct ac_shader_abi *abi)
 }
 
 unsigned si_llvm_compile(LLVMModuleRef M, struct ac_shader_binary *binary,
-                        LLVMTargetMachineRef tm,
+                        struct si_compiler *compiler,
                         struct pipe_debug_callback *debug);
 
 LLVMTypeRef tgsi2llvmtype(struct lp_build_tgsi_context *bld_base,
@@ -236,7 +236,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,
-                         LLVMTargetMachineRef tm);
+                         struct si_compiler *compiler);
 void si_llvm_context_set_tgsi(struct si_shader_context *ctx,
                              struct si_shader *shader);
 
index acd7e0b..d0332a6 100644 (file)
@@ -99,7 +99,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,
-                        LLVMTargetMachineRef tm,
+                        struct si_compiler *compiler,
                         struct pipe_debug_callback *debug)
 {
        struct si_llvm_diagnostics diag;
@@ -119,8 +119,9 @@ unsigned si_llvm_compile(LLVMModuleRef M, struct ac_shader_binary *binary,
        LLVMContextSetDiagnosticHandler(llvm_ctx, si_diagnostic_handler, &diag);
 
        /* Compile IR*/
-       mem_err = LLVMTargetMachineEmitToMemoryBuffer(tm, M, LLVMObjectFile, &err,
-                                                                &out_buffer);
+       mem_err = LLVMTargetMachineEmitToMemoryBuffer(compiler->tm, M,
+                                                     LLVMObjectFile, &err,
+                                                     &out_buffer);
 
        /* Process Errors/Warnings */
        if (mem_err) {
@@ -992,7 +993,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,
-                         LLVMTargetMachineRef tm)
+                         struct si_compiler *compiler)
 {
        struct lp_type type;
 
@@ -1003,14 +1004,14 @@ void si_llvm_context_init(struct si_shader_context *ctx,
         */
        memset(ctx, 0, sizeof(*ctx));
        ctx->screen = sscreen;
-       ctx->tm = tm;
+       ctx->compiler = compiler;
 
        ctx->gallivm.context = LLVMContextCreate();
        ctx->gallivm.module = LLVMModuleCreateWithNameInContext("tgsi",
                                                ctx->gallivm.context);
        LLVMSetTarget(ctx->gallivm.module, "amdgcn--");
 
-       LLVMTargetDataRef data_layout = LLVMCreateTargetDataLayout(tm);
+       LLVMTargetDataRef data_layout = LLVMCreateTargetDataLayout(compiler->tm);
        char *data_layout_str = LLVMCopyStringRepOfTargetData(data_layout);
        LLVMSetDataLayout(ctx->gallivm.module, data_layout_str);
        LLVMDisposeTargetData(data_layout);
index f23ce09..2e215b9 100644 (file)
@@ -1488,26 +1488,26 @@ static void si_build_shader_variant(struct si_shader *shader,
 {
        struct si_shader_selector *sel = shader->selector;
        struct si_screen *sscreen = sel->screen;
-       LLVMTargetMachineRef tm;
+       struct si_compiler *compiler;
        struct pipe_debug_callback *debug = &shader->compiler_ctx_state.debug;
        int r;
 
        if (thread_index >= 0) {
                if (low_priority) {
-                       assert(thread_index < ARRAY_SIZE(sscreen->tm_low_priority));
-                       tm = sscreen->tm_low_priority[thread_index];
+                       assert(thread_index < ARRAY_SIZE(sscreen->compiler_lowp));
+                       compiler = &sscreen->compiler_lowp[thread_index];
                } else {
-                       assert(thread_index < ARRAY_SIZE(sscreen->tm));
-                       tm = sscreen->tm[thread_index];
+                       assert(thread_index < ARRAY_SIZE(sscreen->compiler));
+                       compiler = &sscreen->compiler[thread_index];
                }
                if (!debug->async)
                        debug = NULL;
        } else {
                assert(!low_priority);
-               tm = shader->compiler_ctx_state.tm;
+               compiler = shader->compiler_ctx_state.compiler;
        }
 
-       r = si_shader_create(sscreen, tm, shader, debug);
+       r = si_shader_create(sscreen, compiler, shader, debug);
        if (unlikely(r)) {
                PRINT_ERR("Failed to build shader variant (type=%u) %d\n",
                         sel->type, r);
@@ -1560,7 +1560,7 @@ static bool si_check_missing_main_part(struct si_screen *sscreen,
                main_part->key.as_es = key->as_es;
                main_part->key.as_ls = key->as_ls;
 
-               if (si_compile_tgsi_shader(sscreen, compiler_state->tm,
+               if (si_compile_tgsi_shader(sscreen, compiler_state->compiler,
                                           main_part, false,
                                           &compiler_state->debug) != 0) {
                        FREE(main_part);
@@ -1835,13 +1835,13 @@ 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;
-       LLVMTargetMachineRef tm;
+       struct si_compiler *compiler;
        struct pipe_debug_callback *debug = &sel->compiler_ctx_state.debug;
 
        assert(!debug->debug_message || debug->async);
        assert(thread_index >= 0);
-       assert(thread_index < ARRAY_SIZE(sscreen->tm));
-       tm = sscreen->tm[thread_index];
+       assert(thread_index < ARRAY_SIZE(sscreen->compiler));
+       compiler = &sscreen->compiler[thread_index];
 
        /* Compile the main shader part for use with a prolog and/or epilog.
         * If this fails, the driver will try to compile a monolithic shader
@@ -1879,7 +1879,7 @@ static void si_init_shader_selector_async(void *job, int thread_index)
                        mtx_unlock(&sscreen->shader_cache_mutex);
 
                        /* Compile the shader if it hasn't been loaded from the cache. */
-                       if (si_compile_tgsi_shader(sscreen, tm, shader, false,
+                       if (si_compile_tgsi_shader(sscreen, compiler, shader, false,
                                                   debug) != 0) {
                                FREE(shader);
                                FREE(ir_binary);
@@ -1942,7 +1942,7 @@ static void si_init_shader_selector_async(void *job, int thread_index)
 
        /* The GS copy shader is always pre-compiled. */
        if (sel->type == PIPE_SHADER_GEOMETRY) {
-               sel->gs_copy_shader = si_generate_gs_copy_shader(sscreen, tm, sel, debug);
+               sel->gs_copy_shader = si_generate_gs_copy_shader(sscreen, compiler, sel, debug);
                if (!sel->gs_copy_shader) {
                        fprintf(stderr, "radeonsi: can't create GS copy shader\n");
                        return;
@@ -3134,7 +3134,7 @@ bool si_update_shaders(struct si_context *sctx)
                old_ps ? old_ps->key.part.ps.epilog.spi_shader_col_format : 0;
        int r;
 
-       compiler_state.tm = sctx->tm;
+       compiler_state.compiler = &sctx->compiler;
        compiler_state.debug = sctx->debug;
        compiler_state.is_debug_context = sctx->is_debug;