[Mesa-dev] [PATCH 10/31] radeonsi: pass the function name to si_llvm_create_func

Nicolai Hähnle nhaehnle at gmail.com
Mon Oct 31 22:10:57 UTC 2016


From: Nicolai Hähnle <nicolai.haehnle at amd.com>

We will use multiple functions in one module, so they should have
different names.
---
 src/gallium/drivers/radeonsi/si_shader.c            | 15 ++++++++-------
 src/gallium/drivers/radeonsi/si_shader_internal.h   |  1 +
 src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c |  3 ++-
 3 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/src/gallium/drivers/radeonsi/si_shader.c b/src/gallium/drivers/radeonsi/si_shader.c
index dcbcfbc..81c361e 100644
--- a/src/gallium/drivers/radeonsi/si_shader.c
+++ b/src/gallium/drivers/radeonsi/si_shader.c
@@ -5358,27 +5358,28 @@ static const struct lp_build_tgsi_action tex_action = {
 	.fetch_args = tex_fetch_args,
 	.emit = build_tex_intrinsic,
 };
 
 static const struct lp_build_tgsi_action interp_action = {
 	.fetch_args = interp_fetch_args,
 	.emit = build_interp_intrinsic,
 };
 
 static void si_create_function(struct si_shader_context *ctx,
+			       const char *name,
 			       LLVMTypeRef *returns, unsigned num_returns,
 			       LLVMTypeRef *params, unsigned num_params,
 			       int last_sgpr)
 {
 	int i;
 
-	si_llvm_create_func(ctx, returns, num_returns,
+	si_llvm_create_func(ctx, name, returns, num_returns,
 			    params, num_params);
 	si_llvm_shader_type(ctx->main_fn, ctx->type);
 	ctx->return_value = LLVMGetUndef(ctx->return_type);
 
 	for (i = 0; i <= last_sgpr; ++i) {
 		LLVMValueRef P = LLVMGetParam(ctx->main_fn, i);
 
 		/* The combination of:
 		 * - ByVal
 		 * - dereferenceable
@@ -5687,21 +5688,21 @@ static void create_function(struct si_shader_context *ctx)
 		params[SI_PARAM_THREAD_ID] = v3i32;
 		num_params = SI_PARAM_THREAD_ID + 1;
 		break;
 	default:
 		assert(0 && "unimplemented shader");
 		return;
 	}
 
 	assert(num_params <= ARRAY_SIZE(params));
 
-	si_create_function(ctx, returns, num_returns, params,
+	si_create_function(ctx, "main", returns, num_returns, params,
 			   num_params, last_sgpr);
 
 	/* Reserve register locations for VGPR inputs the PS prolog may need. */
 	if (ctx->type == PIPE_SHADER_FRAGMENT &&
 	    ctx->separate_prolog) {
 		si_llvm_add_attribute(ctx->main_fn,
 				      "InitialPSInputAddr",
 				      S_0286D0_PERSP_SAMPLE_ENA(1) |
 				      S_0286D0_PERSP_CENTER_ENA(1) |
 				      S_0286D0_PERSP_CENTROID_ENA(1) |
@@ -7023,21 +7024,21 @@ static bool si_compile_vs_prolog(struct si_screen *sscreen,
 	for (i = 0; i < 4; i++) {
 		params[num_params++] = ctx.i32;
 		returns[num_returns++] = ctx.f32;
 	}
 
 	/* Vertex load indices. */
 	for (i = 0; i <= key->vs_prolog.last_input; i++)
 		returns[num_returns++] = ctx.f32;
 
 	/* Create the function. */
-	si_create_function(&ctx, returns, num_returns, params,
+	si_create_function(&ctx, "vs_prolog", returns, num_returns, params,
 			   num_params, last_sgpr);
 	func = ctx.main_fn;
 
 	/* Copy inputs to outputs. This should be no-op, as the registers match,
 	 * but it will prevent the compiler from overwriting them unintentionally.
 	 */
 	ret = ctx.return_value;
 	for (i = 0; i < key->vs_prolog.num_input_sgprs; i++) {
 		LLVMValueRef p = LLVMGetParam(func, i);
 		ret = LLVMBuildInsertValue(gallivm->builder, ret, p, i, "");
@@ -7111,21 +7112,21 @@ static bool si_compile_vs_epilog(struct si_screen *sscreen,
 
 	/* Declare input VGPRs. */
 	num_params = key->vs_epilog.states.export_prim_id ?
 			   (VS_EPILOG_PRIMID_LOC + 1) : 0;
 	assert(num_params <= ARRAY_SIZE(params));
 
 	for (i = 0; i < num_params; i++)
 		params[i] = ctx.f32;
 
 	/* Create the function. */
-	si_create_function(&ctx, NULL, 0, params, num_params, -1);
+	si_create_function(&ctx, "vs_epilog", NULL, 0, params, num_params, -1);
 
 	/* Emit exports. */
 	if (key->vs_epilog.states.export_prim_id) {
 		struct lp_build_context *base = &bld_base->base;
 		struct lp_build_context *uint = &bld_base->uint_bld;
 		LLVMValueRef args[9];
 
 		args[0] = lp_build_const_int32(base->gallivm, 0x0); /* enabled channels */
 		args[1] = uint->zero; /* whether the EXEC mask is valid */
 		args[2] = uint->zero; /* DONE bit */
@@ -7281,21 +7282,21 @@ static bool si_compile_tcs_epilog(struct si_screen *sscreen,
 	params[ctx.param_oc_lds = SI_PARAM_TCS_OC_LDS] = ctx.i32;
 	params[SI_PARAM_TESS_FACTOR_OFFSET] = ctx.i32;
 	last_sgpr = SI_PARAM_TESS_FACTOR_OFFSET;
 	num_params = last_sgpr + 1;
 
 	params[num_params++] = ctx.i32; /* patch index within the wave (REL_PATCH_ID) */
 	params[num_params++] = ctx.i32; /* invocation ID within the patch */
 	params[num_params++] = ctx.i32; /* LDS offset where tess factors should be loaded from */
 
 	/* Create the function. */
-	si_create_function(&ctx, NULL, 0, params, num_params, last_sgpr);
+	si_create_function(&ctx, "tcs_epilog", NULL, 0, params, num_params, last_sgpr);
 	declare_tess_lds(&ctx);
 	func = ctx.main_fn;
 
 	si_write_tess_factors(bld_base,
 			      LLVMGetParam(func, last_sgpr + 1),
 			      LLVMGetParam(func, last_sgpr + 2),
 			      LLVMGetParam(func, last_sgpr + 3));
 
 	/* Compile. */
 	LLVMBuildRetVoid(gallivm->builder);
@@ -7373,21 +7374,21 @@ static bool si_compile_ps_prolog(struct si_screen *sscreen,
 	for (i = 0; i < key->ps_prolog.num_input_vgprs; i++)
 		params[num_params++] = ctx.f32;
 
 	/* Declare outputs (same as inputs + add colors if needed) */
 	num_returns = num_params;
 	num_color_channels = util_bitcount(key->ps_prolog.colors_read);
 	for (i = 0; i < num_color_channels; i++)
 		params[num_returns++] = ctx.f32;
 
 	/* Create the function. */
-	si_create_function(&ctx, params, num_returns, params,
+	si_create_function(&ctx, "ps_prolog", params, num_returns, params,
 			   num_params, last_sgpr);
 	func = ctx.main_fn;
 
 	/* Copy inputs to outputs. This should be no-op, as the registers match,
 	 * but it will prevent the compiler from overwriting them unintentionally.
 	 */
 	ret = ctx.return_value;
 	for (i = 0; i < num_params; i++) {
 		LLVMValueRef p = LLVMGetParam(func, i);
 		ret = LLVMBuildInsertValue(gallivm->builder, ret, p, i, "");
@@ -7638,21 +7639,21 @@ static bool si_compile_ps_epilog(struct si_screen *sscreen,
 
 	num_params = MAX2(num_params,
 			  last_sgpr + 1 + PS_EPILOG_SAMPLEMASK_MIN_LOC + 1);
 
 	assert(num_params <= ARRAY_SIZE(params));
 
 	for (i = last_sgpr + 1; i < num_params; i++)
 		params[i] = ctx.f32;
 
 	/* Create the function. */
-	si_create_function(&ctx, NULL, 0, params, num_params, last_sgpr);
+	si_create_function(&ctx, "ps_epilog", NULL, 0, params, num_params, last_sgpr);
 	/* Disable elimination of unused inputs. */
 	si_llvm_add_attribute(ctx.main_fn,
 				  "InitialPSInputAddr", 0xffffff);
 
 	/* Process colors. */
 	unsigned vgpr = last_sgpr + 1;
 	unsigned colors_written = key->ps_epilog.colors_written;
 	int last_color_export = -1;
 
 	/* Find the last color export. */
diff --git a/src/gallium/drivers/radeonsi/si_shader_internal.h b/src/gallium/drivers/radeonsi/si_shader_internal.h
index 7586373..2f5d346 100644
--- a/src/gallium/drivers/radeonsi/si_shader_internal.h
+++ b/src/gallium/drivers/radeonsi/si_shader_internal.h
@@ -187,20 +187,21 @@ LLVMValueRef bitcast(struct lp_build_tgsi_context *bld_base,
 LLVMValueRef si_llvm_bound_index(struct si_shader_context *ctx,
 				 LLVMValueRef index,
 				 unsigned num);
 
 void si_llvm_context_init(struct si_shader_context *ctx,
 			  const char *triple,
 			  const struct tgsi_shader_info *info,
 			  const struct tgsi_token *tokens);
 
 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);
 
 LLVMValueRef si_llvm_emit_fetch_64bit(struct lp_build_tgsi_context *bld_base,
 				      enum tgsi_opcode_type type,
diff --git a/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c b/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c
index 2d82574..b37f7e6 100644
--- a/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c
+++ b/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c
@@ -1297,37 +1297,38 @@ void si_llvm_context_init(struct si_shader_context *ctx, const char *triple,
 	bld_base->op_actions[TGSI_OPCODE_BRK].emit = brk_emit;
 	bld_base->op_actions[TGSI_OPCODE_CONT].emit = cont_emit;
 	bld_base->op_actions[TGSI_OPCODE_IF].emit = if_emit;
 	bld_base->op_actions[TGSI_OPCODE_UIF].emit = uif_emit;
 	bld_base->op_actions[TGSI_OPCODE_ELSE].emit = else_emit;
 	bld_base->op_actions[TGSI_OPCODE_ENDIF].emit = endif_emit;
 	bld_base->op_actions[TGSI_OPCODE_ENDLOOP].emit = endloop_emit;
 }
 
 void si_llvm_create_func(struct si_shader_context *ctx,
+			 const char *name,
 			 LLVMTypeRef *return_types, unsigned num_return_elems,
 			 LLVMTypeRef *ParamTypes, unsigned ParamCount)
 {
 	LLVMTypeRef main_fn_type, ret_type;
 	LLVMBasicBlockRef main_fn_body;
 
 	if (num_return_elems)
 		ret_type = LLVMStructTypeInContext(ctx->gallivm.context,
 						   return_types,
 						   num_return_elems, true);
 	else
 		ret_type = LLVMVoidTypeInContext(ctx->gallivm.context);
 
 	/* Setup the function */
 	ctx->return_type = ret_type;
 	main_fn_type = LLVMFunctionType(ret_type, ParamTypes, ParamCount, 0);
-	ctx->main_fn = LLVMAddFunction(ctx->gallivm.module, "main", main_fn_type);
+	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)
 {
 	struct gallivm_state *gallivm = ctx->soa.bld_base.base.gallivm;
 	const char *triple = LLVMGetTarget(gallivm->module);
-- 
2.7.4



More information about the mesa-dev mailing list