[Mesa-dev] [PATCH 5/9] radeonsi: move passmgr into si_compiler
Marek Olšák
maraeo at gmail.com
Tue Apr 17 00:52:16 UTC 2018
From: Marek Olšák <marek.olsak at amd.com>
---
src/gallium/drivers/radeonsi/si_pipe.c | 30 ++++++++++++++++
src/gallium/drivers/radeonsi/si_pipe.h | 7 ----
src/gallium/drivers/radeonsi/si_shader.h | 1 +
.../drivers/radeonsi/si_shader_tgsi_setup.c | 34 +------------------
4 files changed, 32 insertions(+), 40 deletions(-)
diff --git a/src/gallium/drivers/radeonsi/si_pipe.c b/src/gallium/drivers/radeonsi/si_pipe.c
index 482d667a7d4..d125f5a1d95 100644
--- a/src/gallium/drivers/radeonsi/si_pipe.c
+++ b/src/gallium/drivers/radeonsi/si_pipe.c
@@ -34,20 +34,26 @@
#include "util/hash_table.h"
#include "util/u_log.h"
#include "util/u_memory.h"
#include "util/u_suballoc.h"
#include "util/u_tests.h"
#include "util/u_upload_mgr.h"
#include "util/xmlconfig.h"
#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" },
{ "ps", DBG(PS), "Print pixel shaders" },
{ "gs", DBG(GS), "Print geometry shaders" },
{ "tcs", DBG(TCS), "Print tessellation control shaders" },
{ "tes", DBG(TES), "Print tessellation evaluation shaders" },
{ "cs", DBG(CS), "Print compute shaders" },
{ "noir", DBG(NO_IR), "Don't print the LLVM IR"},
{ "notgsi", DBG(NO_TGSI), "Don't print the TGSI"},
@@ -114,24 +120,48 @@ static void si_init_compiler(struct si_screen *sscreen,
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 = 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)
LLVMDisposeTargetMachine(compiler->tm);
}
/*
* pipe_context
*/
static void si_destroy_context(struct pipe_context *context)
diff --git a/src/gallium/drivers/radeonsi/si_pipe.h b/src/gallium/drivers/radeonsi/si_pipe.h
index 54c9b725fcb..a67786c84d9 100644
--- a/src/gallium/drivers/radeonsi/si_pipe.h
+++ b/src/gallium/drivers/radeonsi/si_pipe.h
@@ -1384,27 +1384,20 @@ static inline struct si_shader* si_get_vs_state(struct si_context *sctx)
struct si_shader_ctx_state *vs = si_get_vs(sctx);
return vs->current ? vs->current : NULL;
}
static inline bool si_can_dump_shader(struct si_screen *sscreen,
unsigned processor)
{
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 ||
sctx->streamout.prims_gen_query_enabled;
}
static inline unsigned
si_optimal_tcc_alignment(struct si_context *sctx, unsigned upload_size)
{
unsigned alignment, tcc_cache_line_size;
diff --git a/src/gallium/drivers/radeonsi/si_shader.h b/src/gallium/drivers/radeonsi/si_shader.h
index 8761bc7e7c9..a0122d23910 100644
--- a/src/gallium/drivers/radeonsi/si_shader.h
+++ b/src/gallium/drivers/radeonsi/si_shader.h
@@ -309,20 +309,21 @@ enum {
SI_FIX_FETCH_RGB_16_INT,
};
struct si_shader;
/* Per-thread persistent LLVM objects. */
struct si_compiler {
LLVMTargetMachineRef tm;
const char *triple;
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;
/* Used if thread_index == -1 or if debug.async is true. */
struct pipe_debug_callback debug;
diff --git a/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c b/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c
index 86366f4063c..29b1e50dc47 100644
--- a/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c
+++ b/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c
@@ -32,25 +32,20 @@
#include "gallivm/lp_bld_intr.h"
#include "gallivm/lp_bld_misc.h"
#include "gallivm/lp_bld_swizzle.h"
#include "tgsi/tgsi_info.h"
#include "tgsi/tgsi_parse.h"
#include "util/u_math.h"
#include "util/u_memory.h"
#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,
RADEON_LLVM_AMDGPU_GS = 88,
RADEON_LLVM_AMDGPU_PS = 89,
RADEON_LLVM_AMDGPU_CS = 90,
RADEON_LLVM_AMDGPU_HS = 93,
};
struct si_llvm_diagnostics {
@@ -1205,55 +1200,28 @@ void si_llvm_create_func(struct si_shader_context *ctx,
break;
default:
unreachable("Unhandle shader type");
}
LLVMSetFunctionCallConv(ctx->main_fn, call_conv);
}
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)
{
LLVMDisposeModule(ctx->gallivm.module);
LLVMContextDispose(ctx->gallivm.context);
FREE(ctx->temp_arrays);
ctx->temp_arrays = NULL;
FREE(ctx->temp_array_allocas);
ctx->temp_array_allocas = NULL;
--
2.17.0
More information about the mesa-dev
mailing list