radeonsi: move passmgr into si_compiler
authorMarek Olšák <marek.olsak@amd.com>
Mon, 9 Apr 2018 23:13:37 +0000 (19:13 -0400)
committerMarek Olšák <marek.olsak@amd.com>
Fri, 27 Apr 2018 21:56:04 +0000 (17:56 -0400)
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_pipe.c
src/gallium/drivers/radeonsi/si_pipe.h
src/gallium/drivers/radeonsi/si_shader.h
src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c

index 19b570e569e92e555b44b78eb13ddbb346cf2437..eeb7ff81f92d7f96da6f1598713835071412edc7 100644 (file)
 #include "vl/vl_decoder.h"
 #include "driver_ddebug/dd_util.h"
 
+#include <llvm-c/Transforms/IPO.h>
+#include <llvm-c/Transforms/Scalar.h>
+#if HAVE_LLVM >= 0x0700
+#include <llvm-c/Transforms/Utils.h>
+#endif
+
 static const struct debug_named_value debug_options[] = {
        /* Shader logging options: */
        { "vs", DBG(VS), "Print vertex shaders" },
@@ -121,10 +127,34 @@ static void si_init_compiler(struct si_screen *sscreen,
                gallivm_create_target_library_info(compiler->triple);
        if (!compiler->target_library_info)
                return;
+
+       compiler->passmgr = LLVMCreatePassManager();
+       if (!compiler->passmgr)
+               return;
+
+       LLVMAddTargetLibraryInfo(compiler->target_library_info,
+                                compiler->passmgr);
+
+       /* Add LLVM passes into the pass manager. */
+       if (sscreen->debug_flags & DBG(CHECK_IR))
+               LLVMAddVerifierPass(compiler->passmgr);
+
+       LLVMAddAlwaysInlinerPass(compiler->passmgr);
+       /* This pass should eliminate all the load and store instructions. */
+       LLVMAddPromoteMemoryToRegisterPass(compiler->passmgr);
+       LLVMAddScalarReplAggregatesPass(compiler->passmgr);
+       LLVMAddLICMPass(compiler->passmgr);
+       LLVMAddAggressiveDCEPass(compiler->passmgr);
+       LLVMAddCFGSimplificationPass(compiler->passmgr);
+       /* This is recommended by the instruction combining pass. */
+       LLVMAddEarlyCSEMemSSAPass(compiler->passmgr);
+       LLVMAddInstructionCombiningPass(compiler->passmgr);
 }
 
 static void si_destroy_compiler(struct si_compiler *compiler)
 {
+       if (compiler->passmgr)
+               LLVMDisposePassManager(compiler->passmgr);
        if (compiler->target_library_info)
                gallivm_dispose_target_library_info(compiler->target_library_info);
        if (compiler->tm)
index 54c9b725fcb5df21b1c1eae0c2be0f8aabc9803c..a67786c84d9b4445205a772811eb3333b527296e 100644 (file)
@@ -1391,13 +1391,6 @@ static inline bool si_can_dump_shader(struct si_screen *sscreen,
        return sscreen->debug_flags & (1 << processor);
 }
 
-static inline bool si_extra_shader_checks(struct si_screen *sscreen,
-                                         unsigned processor)
-{
-       return (sscreen->debug_flags & DBG(CHECK_IR)) ||
-              si_can_dump_shader(sscreen, processor);
-}
-
 static inline bool si_get_strmout_en(struct si_context *sctx)
 {
        return sctx->streamout.streamout_enabled ||
index 8761bc7e7c93eb73145a5a298626f715e0e48c08..a0122d239103ce75047ba9abf38e8360662aca11 100644 (file)
@@ -316,6 +316,7 @@ struct si_compiler {
        LLVMTargetMachineRef            tm;
        const char                      *triple;
        LLVMTargetLibraryInfoRef        target_library_info;
+       LLVMPassManagerRef              passmgr;
 };
 
 /* State of the context creating the shader object. */
index 86366f4063c95d374898fd934ff893708470e28a..29b1e50dc47d0206f425e8280edbadb71c5dcd09 100644 (file)
 #include "util/u_debug.h"
 
 #include <stdio.h>
-#include <llvm-c/Transforms/IPO.h>
-#include <llvm-c/Transforms/Scalar.h>
-#if HAVE_LLVM >= 0x0700
-#include <llvm-c/Transforms/Utils.h>
-#endif
 
 enum si_llvm_calling_convention {
        RADEON_LLVM_AMDGPU_VS = 87,
@@ -1212,41 +1207,14 @@ void si_llvm_create_func(struct si_shader_context *ctx,
 
 void si_llvm_optimize_module(struct si_shader_context *ctx)
 {
-       struct gallivm_state *gallivm = &ctx->gallivm;
-
        /* Dump LLVM IR before any optimization passes */
        if (ctx->screen->debug_flags & DBG(PREOPT_IR) &&
            si_can_dump_shader(ctx->screen, ctx->type))
                LLVMDumpModule(ctx->gallivm.module);
 
-       /* Create the pass manager */
-       gallivm->passmgr = LLVMCreatePassManager();
-
-       LLVMAddTargetLibraryInfo(ctx->compiler->target_library_info,
-                                gallivm->passmgr);
-
-       if (si_extra_shader_checks(ctx->screen, ctx->type))
-               LLVMAddVerifierPass(gallivm->passmgr);
-
-       LLVMAddAlwaysInlinerPass(gallivm->passmgr);
-
-       /* This pass should eliminate all the load and store instructions */
-       LLVMAddPromoteMemoryToRegisterPass(gallivm->passmgr);
-
-       /* Add some optimization passes */
-       LLVMAddScalarReplAggregatesPass(gallivm->passmgr);
-       LLVMAddLICMPass(gallivm->passmgr);
-       LLVMAddAggressiveDCEPass(gallivm->passmgr);
-       LLVMAddCFGSimplificationPass(gallivm->passmgr);
-       /* This is recommended by the instruction combining pass. */
-       LLVMAddEarlyCSEMemSSAPass(gallivm->passmgr);
-       LLVMAddInstructionCombiningPass(gallivm->passmgr);
-
        /* Run the pass */
-       LLVMRunPassManager(gallivm->passmgr, ctx->gallivm.module);
-
+       LLVMRunPassManager(ctx->compiler->passmgr, ctx->gallivm.module);
        LLVMDisposeBuilder(ctx->ac.builder);
-       LLVMDisposePassManager(gallivm->passmgr);
 }
 
 void si_llvm_dispose(struct si_shader_context *ctx)