[Mesa-dev] [PATCH 05/14] radeonsi: fold surrounding code into si_llvm_finalize_module

Marek Olšák maraeo at gmail.com
Fri Apr 28 21:42:42 UTC 2017


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

and rename to si_llvm_optimize_module.
---
 src/gallium/drivers/radeonsi/si_shader.c            | 20 ++++----------------
 src/gallium/drivers/radeonsi/si_shader_internal.h   |  3 +--
 src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c | 10 +++++++---
 3 files changed, 12 insertions(+), 21 deletions(-)

diff --git a/src/gallium/drivers/radeonsi/si_shader.c b/src/gallium/drivers/radeonsi/si_shader.c
index 5ee8c6f..0fa91de 100644
--- a/src/gallium/drivers/radeonsi/si_shader.c
+++ b/src/gallium/drivers/radeonsi/si_shader.c
@@ -6985,27 +6985,22 @@ si_generate_gs_copy_shader(struct si_screen *sscreen,
 		if (stream == 0)
 			si_llvm_export_vs(bld_base, outputs, gsinfo->num_outputs);
 
 		LLVMBuildBr(builder, end_bb);
 	}
 
 	LLVMPositionBuilderAtEnd(builder, end_bb);
 
 	LLVMBuildRetVoid(gallivm->builder);
 
-	/* Dump LLVM IR before any optimization passes */
-	if (sscreen->b.debug_flags & DBG_PREOPT_IR &&
-	    r600_can_dump_shader(&sscreen->b, PIPE_SHADER_GEOMETRY))
-		ac_dump_module(ctx.gallivm.module);
-
-	si_llvm_finalize_module(&ctx,
-		r600_extra_shader_checks(&sscreen->b, PIPE_SHADER_GEOMETRY));
+	ctx.type = PIPE_SHADER_GEOMETRY; /* override for shader dumping */
+	si_llvm_optimize_module(&ctx);
 
 	r = si_compile_llvm(sscreen, &ctx.shader->binary,
 			    &ctx.shader->config, ctx.tm,
 			    ctx.gallivm.module,
 			    debug, PIPE_SHADER_GEOMETRY,
 			    "GS Copy Shader");
 	if (!r) {
 		if (r600_can_dump_shader(&sscreen->b, PIPE_SHADER_GEOMETRY))
 			fprintf(stderr, "GS Copy Shader:\n");
 		si_shader_dump(sscreen, ctx.shader, debug,
@@ -8122,27 +8117,21 @@ int si_compile_tgsi_shader(struct si_screen *sscreen,
 		}
 
 		si_get_ps_epilog_key(shader, &epilog_key);
 		si_build_ps_epilog_function(&ctx, &epilog_key);
 		parts[need_prolog ? 2 : 1] = ctx.main_fn;
 
 		si_build_wrapper_function(&ctx, parts, need_prolog ? 3 : 2,
 					  need_prolog ? 1 : 0, 0);
 	}
 
-	/* Dump LLVM IR before any optimization passes */
-	if (sscreen->b.debug_flags & DBG_PREOPT_IR &&
-	    r600_can_dump_shader(&sscreen->b, ctx.type))
-		LLVMDumpModule(ctx.gallivm.module);
-
-	si_llvm_finalize_module(&ctx,
-				    r600_extra_shader_checks(&sscreen->b, ctx.type));
+	si_llvm_optimize_module(&ctx);
 
 	/* Post-optimization transformations and analysis. */
 	si_eliminate_const_vs_outputs(&ctx);
 
 	if ((debug && debug->debug_message) ||
 	    r600_can_dump_shader(&sscreen->b, ctx.type))
 		si_count_scratch_private_memory(&ctx);
 
 	/* Compile to bytecode. */
 	r = si_compile_llvm(sscreen, &shader->binary, &shader->config, tm,
@@ -8297,22 +8286,21 @@ si_get_shader_part(struct si_screen *sscreen,
 		else
 			shader.key.part.ps.epilog = key->ps_epilog.states;
 		break;
 	default:
 		unreachable("bad shader part");
 	}
 
 	build(&ctx, key);
 
 	/* Compile. */
-	si_llvm_finalize_module(&ctx,
-		r600_extra_shader_checks(&sscreen->b, PIPE_SHADER_FRAGMENT));
+	si_llvm_optimize_module(&ctx);
 
 	if (si_compile_llvm(sscreen, &result->binary, &result->config, tm,
 			    gallivm->module, debug, ctx.type, name)) {
 		FREE(result);
 		result = NULL;
 		goto out;
 	}
 
 	result->next = *list;
 	*list = result;
diff --git a/src/gallium/drivers/radeonsi/si_shader_internal.h b/src/gallium/drivers/radeonsi/si_shader_internal.h
index 03bf83d..b54db20 100644
--- a/src/gallium/drivers/radeonsi/si_shader_internal.h
+++ b/src/gallium/drivers/radeonsi/si_shader_internal.h
@@ -264,22 +264,21 @@ void si_llvm_context_init(struct si_shader_context *ctx,
 void si_llvm_context_set_tgsi(struct si_shader_context *ctx,
 			      struct si_shader *shader);
 
 void si_llvm_create_func(struct si_shader_context *ctx,
 			 const char *name,
 			 LLVMTypeRef *return_types, unsigned num_return_elems,
 			 LLVMTypeRef *ParamTypes, unsigned ParamCount);
 
 void si_llvm_dispose(struct si_shader_context *ctx);
 
-void si_llvm_finalize_module(struct si_shader_context *ctx,
-			     bool run_verifier);
+void si_llvm_optimize_module(struct si_shader_context *ctx);
 
 LLVMValueRef si_llvm_emit_fetch_64bit(struct lp_build_tgsi_context *bld_base,
 				      enum tgsi_opcode_type type,
 				      LLVMValueRef ptr,
 				      LLVMValueRef ptr2);
 
 LLVMValueRef si_llvm_emit_fetch(struct lp_build_tgsi_context *bld_base,
 				const struct tgsi_full_src_register *reg,
 				enum tgsi_opcode_type type,
 				unsigned swizzle);
diff --git a/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c b/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c
index a2c7e67..2b0d600 100644
--- a/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c
+++ b/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c
@@ -1402,34 +1402,38 @@ void si_llvm_create_func(struct si_shader_context *ctx,
 
 	/* Setup the function */
 	ctx->return_type = ret_type;
 	main_fn_type = LLVMFunctionType(ret_type, ParamTypes, ParamCount, 0);
 	ctx->main_fn = LLVMAddFunction(ctx->gallivm.module, name, main_fn_type);
 	main_fn_body = LLVMAppendBasicBlockInContext(ctx->gallivm.context,
 			ctx->main_fn, "main_body");
 	LLVMPositionBuilderAtEnd(ctx->gallivm.builder, main_fn_body);
 }
 
-void si_llvm_finalize_module(struct si_shader_context *ctx,
-			     bool run_verifier)
+void si_llvm_optimize_module(struct si_shader_context *ctx)
 {
 	struct gallivm_state *gallivm = &ctx->gallivm;
 	const char *triple = LLVMGetTarget(gallivm->module);
 	LLVMTargetLibraryInfoRef target_library_info;
 
+	/* Dump LLVM IR before any optimization passes */
+	if (ctx->screen->b.debug_flags & DBG_PREOPT_IR &&
+	    r600_can_dump_shader(&ctx->screen->b, ctx->type))
+		LLVMDumpModule(ctx->gallivm.module);
+
 	/* Create the pass manager */
 	gallivm->passmgr = LLVMCreatePassManager();
 
 	target_library_info = gallivm_create_target_library_info(triple);
 	LLVMAddTargetLibraryInfo(target_library_info, gallivm->passmgr);
 
-	if (run_verifier)
+	if (r600_extra_shader_checks(&ctx->screen->b, 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);
-- 
2.7.4



More information about the mesa-dev mailing list