[Mesa-dev] [PATCH 4/9] radeonsi: move target_library_info into si_compiler

Marek Olšák maraeo at gmail.com
Tue Apr 17 00:52:15 UTC 2018


From: Marek Olšák <marek.olsak at amd.com>

---
 src/gallium/drivers/radeonsi/si_pipe.c              | 10 ++++++++++
 src/gallium/drivers/radeonsi/si_shader.h            |  1 +
 src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c |  7 ++-----
 3 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/src/gallium/drivers/radeonsi/si_pipe.c b/src/gallium/drivers/radeonsi/si_pipe.c
index ad813888597..482d667a7d4 100644
--- a/src/gallium/drivers/radeonsi/si_pipe.c
+++ b/src/gallium/drivers/radeonsi/si_pipe.c
@@ -22,20 +22,21 @@
  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  * USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
 
 #include "si_pipe.h"
 #include "si_public.h"
 #include "si_shader_internal.h"
 #include "sid.h"
 
 #include "radeon/radeon_uvd.h"
+#include "gallivm/lp_bld_misc.h"
 #include "util/disk_cache.h"
 #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"
@@ -106,24 +107,33 @@ 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, &compiler->triple);
+	if (!compiler->tm)
+		return;
+
+	compiler->target_library_info =
+		gallivm_create_target_library_info(compiler->triple);
+	if (!compiler->target_library_info)
+		return;
 }
 
 static void si_destroy_compiler(struct si_compiler *compiler)
 {
+	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)
 {
 	struct si_context *sctx = (struct si_context *)context;
diff --git a/src/gallium/drivers/radeonsi/si_shader.h b/src/gallium/drivers/radeonsi/si_shader.h
index e6205a204c1..8761bc7e7c9 100644
--- a/src/gallium/drivers/radeonsi/si_shader.h
+++ b/src/gallium/drivers/radeonsi/si_shader.h
@@ -308,20 +308,21 @@ enum {
 	SI_FIX_FETCH_RGB_16,
 	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;
 };
 
 /* 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 f354417b89e..86366f4063c 100644
--- a/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c
+++ b/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c
@@ -1206,33 +1206,31 @@ void si_llvm_create_func(struct si_shader_context *ctx,
 	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;
-	LLVMTargetLibraryInfoRef target_library_info;
 
 	/* 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();
 
-	target_library_info =
-		gallivm_create_target_library_info(ctx->compiler->triple);
-	LLVMAddTargetLibraryInfo(target_library_info, gallivm->passmgr);
+	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 */
@@ -1242,21 +1240,20 @@ void si_llvm_optimize_module(struct si_shader_context *ctx)
 	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);
 
 	LLVMDisposeBuilder(ctx->ac.builder);
 	LLVMDisposePassManager(gallivm->passmgr);
-	gallivm_dispose_target_library_info(target_library_info);
 }
 
 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