[Mesa-dev] [PATCH 6/9] radeonsi: move data_layout into si_compiler

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


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

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

diff --git a/src/gallium/drivers/radeonsi/si_pipe.c b/src/gallium/drivers/radeonsi/si_pipe.c
index d125f5a1d95..09b9f588a6f 100644
--- a/src/gallium/drivers/radeonsi/si_pipe.c
+++ b/src/gallium/drivers/radeonsi/si_pipe.c
@@ -142,24 +142,33 @@ static void si_init_compiler(struct si_screen *sscreen,
 	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);
+
+	/* Get the data layout. */
+	LLVMTargetDataRef data_layout = LLVMCreateTargetDataLayout(compiler->tm);
+	if (!data_layout)
+		return;
+	compiler->data_layout = LLVMCopyStringRepOfTargetData(data_layout);
+	LLVMDisposeTargetData(data_layout);
 }
 
 static void si_destroy_compiler(struct si_compiler *compiler)
 {
+	if (compiler->data_layout)
+		LLVMDisposeMessage((char*)compiler->data_layout);
 	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
diff --git a/src/gallium/drivers/radeonsi/si_shader.h b/src/gallium/drivers/radeonsi/si_shader.h
index a0122d23910..94366f41204 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;
+	const char			*data_layout;
 	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;
 
diff --git a/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c b/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c
index 29b1e50dc47..a4c2a1f27ab 100644
--- a/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c
+++ b/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c
@@ -998,26 +998,21 @@ void si_llvm_context_init(struct si_shader_context *ctx,
 	 * helper functions in the gallivm module.
 	 */
 	memset(ctx, 0, sizeof(*ctx));
 	ctx->screen = sscreen;
 	ctx->compiler = compiler;
 
 	ctx->gallivm.context = LLVMContextCreate();
 	ctx->gallivm.module = LLVMModuleCreateWithNameInContext("tgsi",
 						ctx->gallivm.context);
 	LLVMSetTarget(ctx->gallivm.module, compiler->triple);
-
-	LLVMTargetDataRef data_layout = LLVMCreateTargetDataLayout(compiler->tm);
-	char *data_layout_str = LLVMCopyStringRepOfTargetData(data_layout);
-	LLVMSetDataLayout(ctx->gallivm.module, data_layout_str);
-	LLVMDisposeTargetData(data_layout);
-	LLVMDisposeMessage(data_layout_str);
+	LLVMSetDataLayout(ctx->gallivm.module, compiler->data_layout);
 
 	bool unsafe_fpmath = (sscreen->debug_flags & DBG(UNSAFE_MATH)) != 0;
 	enum ac_float_mode float_mode =
 		unsafe_fpmath ? AC_FLOAT_MODE_UNSAFE_FP_MATH :
 				AC_FLOAT_MODE_NO_SIGNED_ZEROS_FP_MATH;
 
 	ctx->gallivm.builder = ac_create_builder(ctx->gallivm.context,
 						 float_mode);
 
 	ac_llvm_context_init(&ctx->ac, ctx->gallivm.context,
-- 
2.17.0



More information about the mesa-dev mailing list