radeonsi: merge si_compile_llvm and si_llvm_compile functions
authorMarek Olšák <marek.olsak@amd.com>
Wed, 15 Jan 2020 01:40:51 +0000 (20:40 -0500)
committerMarge Bot <eric+marge@anholt.net>
Wed, 15 Jan 2020 21:54:55 +0000 (21:54 +0000)
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3399>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3399>

src/gallium/drivers/radeonsi/si_shader.c
src/gallium/drivers/radeonsi/si_shader_internal.h
src/gallium/drivers/radeonsi/si_shader_llvm.c
src/gallium/drivers/radeonsi/si_shader_llvm_gs.c

index 49538e823f4ff84701e42e65c730d183ac358c06..766d25b396e5136ad96fc7527afd036ecaad6d81 100644 (file)
@@ -2086,74 +2086,6 @@ void si_shader_dump(struct si_screen *sscreen, struct si_shader *shader,
        si_shader_dump_stats(sscreen, shader, file, check_debug_option);
 }
 
-int si_compile_llvm(struct si_screen *sscreen,
-                   struct si_shader_binary *binary,
-                   struct ac_shader_config *conf,
-                   struct ac_llvm_compiler *compiler,
-                   LLVMModuleRef mod,
-                   struct pipe_debug_callback *debug,
-                   enum pipe_shader_type shader_type,
-                   unsigned wave_size,
-                   const char *name,
-                   bool less_optimized)
-{
-       unsigned count = p_atomic_inc_return(&sscreen->num_compilations);
-
-       if (si_can_dump_shader(sscreen, shader_type)) {
-               fprintf(stderr, "radeonsi: Compiling shader %d\n", count);
-
-               if (!(sscreen->debug_flags & (DBG(NO_IR) | DBG(PREOPT_IR)))) {
-                       fprintf(stderr, "%s LLVM IR:\n\n", name);
-                       ac_dump_module(mod);
-                       fprintf(stderr, "\n");
-               }
-       }
-
-       if (sscreen->record_llvm_ir) {
-               char *ir = LLVMPrintModuleToString(mod);
-               binary->llvm_ir_string = strdup(ir);
-               LLVMDisposeMessage(ir);
-       }
-
-       if (!si_replace_shader(count, binary)) {
-               unsigned r = si_llvm_compile(mod, binary, compiler, debug,
-                                            less_optimized, wave_size);
-               if (r)
-                       return r;
-       }
-
-       struct ac_rtld_binary rtld;
-       if (!ac_rtld_open(&rtld, (struct ac_rtld_open_info){
-                       .info = &sscreen->info,
-                       .shader_type = tgsi_processor_to_shader_stage(shader_type),
-                       .wave_size = wave_size,
-                       .num_parts = 1,
-                       .elf_ptrs = &binary->elf_buffer,
-                       .elf_sizes = &binary->elf_size }))
-               return -1;
-
-       bool ok = ac_rtld_read_config(&rtld, conf);
-       ac_rtld_close(&rtld);
-       if (!ok)
-               return -1;
-
-       /* Enable 64-bit and 16-bit denormals, because there is no performance
-        * cost.
-        *
-        * If denormals are enabled, all floating-point output modifiers are
-        * ignored.
-        *
-        * Don't enable denormals for 32-bit floats, because:
-        * - Floating-point output modifiers would be ignored by the hw.
-        * - Some opcodes don't support denormals, such as v_mad_f32. We would
-        *   have to stop using those.
-        * - GFX6 & GFX7 would be very slow.
-        */
-       conf->float_mode |= V_00B028_FP_64_DENORMS;
-
-       return 0;
-}
-
 static void si_dump_shader_key_vs(const struct si_shader_key *key,
                                  const struct si_vs_prolog_bits *prolog,
                                  const char *prefix, FILE *f)
@@ -3130,8 +3062,7 @@ int si_compile_shader(struct si_screen *sscreen,
 
        /* Compile to bytecode. */
        r = si_compile_llvm(sscreen, &shader->binary, &shader->config, compiler,
-                           ctx.ac.module, debug, ctx.type, ctx.ac.wave_size,
-                           si_get_shader_name(shader),
+                           &ctx.ac, debug, ctx.type, si_get_shader_name(shader),
                            si_should_optimize_less(compiler, shader->selector));
        si_llvm_dispose(&ctx);
        if (r) {
@@ -3268,8 +3199,7 @@ si_get_shader_part(struct si_screen *sscreen,
        si_llvm_optimize_module(&ctx);
 
        if (si_compile_llvm(sscreen, &result->binary, &result->config, compiler,
-                           ctx.ac.module, debug, ctx.type, ctx.ac.wave_size,
-                           name, false)) {
+                           &ctx.ac, debug, ctx.type, name, false)) {
                FREE(result);
                result = NULL;
                goto out;
index e9b41e0ff16f6d46bf737caa9280eac753b4b98e..80011edb3d5dcb861be81e50fc125476bec07179 100644 (file)
@@ -204,10 +204,6 @@ si_shader_context_from_abi(struct ac_shader_abi *abi)
        return container_of(abi, ctx, abi);
 }
 
-unsigned si_llvm_compile(LLVMModuleRef M, struct si_shader_binary *binary,
-                        struct ac_llvm_compiler *compiler,
-                        struct pipe_debug_callback *debug,
-                        bool less_optimized, unsigned wave_size);
 void si_llvm_context_init(struct si_shader_context *ctx,
                          struct si_screen *sscreen,
                          struct ac_llvm_compiler *compiler,
@@ -292,10 +288,9 @@ int si_compile_llvm(struct si_screen *sscreen,
                    struct si_shader_binary *binary,
                    struct ac_shader_config *conf,
                    struct ac_llvm_compiler *compiler,
-                   LLVMModuleRef mod,
+                   struct ac_llvm_context *ac,
                    struct pipe_debug_callback *debug,
                    enum pipe_shader_type shader_type,
-                   unsigned wave_size,
                    const char *name,
                    bool less_optimized);
 void si_fix_resource_usage(struct si_screen *sscreen, struct si_shader *shader);
index 841c97b00bf13453ed5ffd88066c550a30e72ba3..539b2531ab7244ee25235cbac4dc98f046a39119 100644 (file)
 
 #include "si_shader_internal.h"
 #include "si_pipe.h"
+#include "ac_rtld.h"
+#include "sid.h"
+
+#include "tgsi/tgsi_from_mesa.h"
 #include "util/u_memory.h"
 
 struct si_llvm_diagnostics {
@@ -63,42 +67,86 @@ static void si_diagnostic_handler(LLVMDiagnosticInfoRef di, void *context)
        LLVMDisposeMessage(description);
 }
 
-/**
- * Compile an LLVM module to machine code.
- *
- * @returns 0 for success, 1 for failure
- */
-unsigned si_llvm_compile(LLVMModuleRef M, struct si_shader_binary *binary,
-                        struct ac_llvm_compiler *compiler,
-                        struct pipe_debug_callback *debug,
-                        bool less_optimized, unsigned wave_size)
+int si_compile_llvm(struct si_screen *sscreen,
+                   struct si_shader_binary *binary,
+                   struct ac_shader_config *conf,
+                   struct ac_llvm_compiler *compiler,
+                   struct ac_llvm_context *ac,
+                   struct pipe_debug_callback *debug,
+                   enum pipe_shader_type shader_type,
+                   const char *name,
+                   bool less_optimized)
 {
-       struct ac_compiler_passes *passes = compiler->passes;
+       unsigned count = p_atomic_inc_return(&sscreen->num_compilations);
+
+       if (si_can_dump_shader(sscreen, shader_type)) {
+               fprintf(stderr, "radeonsi: Compiling shader %d\n", count);
+
+               if (!(sscreen->debug_flags & (DBG(NO_IR) | DBG(PREOPT_IR)))) {
+                       fprintf(stderr, "%s LLVM IR:\n\n", name);
+                       ac_dump_module(ac->module);
+                       fprintf(stderr, "\n");
+               }
+       }
 
-       if (wave_size == 32)
-               passes = compiler->passes_wave32;
-       else if (less_optimized && compiler->low_opt_passes)
-               passes = compiler->low_opt_passes;
+       if (sscreen->record_llvm_ir) {
+               char *ir = LLVMPrintModuleToString(ac->module);
+               binary->llvm_ir_string = strdup(ir);
+               LLVMDisposeMessage(ir);
+       }
 
-       struct si_llvm_diagnostics diag;
-       LLVMContextRef llvm_ctx;
+       if (!si_replace_shader(count, binary)) {
+               struct ac_compiler_passes *passes = compiler->passes;
 
-       diag.debug = debug;
-       diag.retval = 0;
+               if (ac->wave_size == 32)
+                       passes = compiler->passes_wave32;
+               else if (less_optimized && compiler->low_opt_passes)
+                       passes = compiler->low_opt_passes;
 
-       /* Setup Diagnostic Handler*/
-       llvm_ctx = LLVMGetModuleContext(M);
+               struct si_llvm_diagnostics diag = {debug};
+               LLVMContextSetDiagnosticHandler(ac->context, si_diagnostic_handler, &diag);
 
-       LLVMContextSetDiagnosticHandler(llvm_ctx, si_diagnostic_handler, &diag);
+               if (!ac_compile_module_to_elf(passes, ac->module,
+                                             (char **)&binary->elf_buffer,
+                                             &binary->elf_size))
+                       diag.retval = 1;
 
-       /* Compile IR. */
-       if (!ac_compile_module_to_elf(passes, M, (char **)&binary->elf_buffer,
-                                     &binary->elf_size))
-               diag.retval = 1;
+               if (diag.retval != 0) {
+                       pipe_debug_message(debug, SHADER_INFO, "LLVM compilation failed");
+                       return diag.retval;
+               }
+       }
+
+       struct ac_rtld_binary rtld;
+       if (!ac_rtld_open(&rtld, (struct ac_rtld_open_info){
+                       .info = &sscreen->info,
+                       .shader_type = tgsi_processor_to_shader_stage(shader_type),
+                       .wave_size = ac->wave_size,
+                       .num_parts = 1,
+                       .elf_ptrs = &binary->elf_buffer,
+                       .elf_sizes = &binary->elf_size }))
+               return -1;
+
+       bool ok = ac_rtld_read_config(&rtld, conf);
+       ac_rtld_close(&rtld);
+       if (!ok)
+               return -1;
+
+       /* Enable 64-bit and 16-bit denormals, because there is no performance
+        * cost.
+        *
+        * If denormals are enabled, all floating-point output modifiers are
+        * ignored.
+        *
+        * Don't enable denormals for 32-bit floats, because:
+        * - Floating-point output modifiers would be ignored by the hw.
+        * - Some opcodes don't support denormals, such as v_mad_f32. We would
+        *   have to stop using those.
+        * - GFX6 & GFX7 would be very slow.
+        */
+       conf->float_mode |= V_00B028_FP_64_DENORMS;
 
-       if (diag.retval != 0)
-               pipe_debug_message(debug, SHADER_INFO, "LLVM compile failed");
-       return diag.retval;
+       return 0;
 }
 
 void si_shader_binary_clean(struct si_shader_binary *binary)
index 69dc7080a6c622bc773977ebcc50bcb809c0095f..a11748325dd367a729bf9389447892401418a5f2 100644 (file)
@@ -623,9 +623,8 @@ si_generate_gs_copy_shader(struct si_screen *sscreen,
 
        bool ok = false;
        if (si_compile_llvm(sscreen, &ctx.shader->binary,
-                           &ctx.shader->config, ctx.compiler,
-                           ctx.ac.module,
-                           debug, PIPE_SHADER_GEOMETRY, ctx.ac.wave_size,
+                           &ctx.shader->config, ctx.compiler, &ctx.ac,
+                           debug, PIPE_SHADER_GEOMETRY,
                            "GS Copy Shader", false) == 0) {
                if (si_can_dump_shader(sscreen, PIPE_SHADER_GEOMETRY))
                        fprintf(stderr, "GS Copy Shader:\n");