[Mesa-dev] [PATCH 07/11] radeonsi: don't use lp_build_const_*

Marek Olšák maraeo at gmail.com
Fri Sep 29 14:49:51 UTC 2017


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

---
 src/gallium/drivers/radeonsi/si_shader_tgsi_alu.c   | 12 ++++--------
 src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c |  2 +-
 2 files changed, 5 insertions(+), 9 deletions(-)

diff --git a/src/gallium/drivers/radeonsi/si_shader_tgsi_alu.c b/src/gallium/drivers/radeonsi/si_shader_tgsi_alu.c
index 242f056..972b26f 100644
--- a/src/gallium/drivers/radeonsi/si_shader_tgsi_alu.c
+++ b/src/gallium/drivers/radeonsi/si_shader_tgsi_alu.c
@@ -26,40 +26,39 @@
 #include "gallivm/lp_bld_intr.h"
 #include "gallivm/lp_bld_gather.h"
 #include "tgsi/tgsi_parse.h"
 #include "amd/common/ac_llvm_build.h"
 
 static void kill_if_fetch_args(struct lp_build_tgsi_context *bld_base,
 			       struct lp_build_emit_data *emit_data)
 {
 	const struct tgsi_full_instruction *inst = emit_data->inst;
 	struct si_shader_context *ctx = si_shader_context(bld_base);
-	struct gallivm_state *gallivm = bld_base->base.gallivm;
 	LLVMBuilderRef builder = ctx->ac.builder;
 	unsigned i;
 	LLVMValueRef conds[TGSI_NUM_CHANNELS];
 
 	for (i = 0; i < TGSI_NUM_CHANNELS; i++) {
 		LLVMValueRef value = lp_build_emit_fetch(bld_base, inst, 0, i);
 		conds[i] = LLVMBuildFCmp(builder, LLVMRealOLT, value,
 					bld_base->base.zero, "");
 	}
 
 	/* Or the conditions together */
 	for (i = TGSI_NUM_CHANNELS - 1; i > 0; i--) {
 		conds[i - 1] = LLVMBuildOr(builder, conds[i], conds[i - 1], "");
 	}
 
 	emit_data->dst_type = ctx->voidt;
 	emit_data->arg_count = 1;
 	emit_data->args[0] = LLVMBuildSelect(builder, conds[0],
-					lp_build_const_float(gallivm, -1.0f),
+					LLVMConstReal(ctx->f32, -1.0f),
 					bld_base->base.zero, "");
 }
 
 static void kil_emit(const struct lp_build_tgsi_action *action,
 		     struct lp_build_tgsi_context *bld_base,
 		     struct lp_build_emit_data *emit_data)
 {
 	struct si_shader_context *ctx = si_shader_context(bld_base);
 	LLVMBuilderRef builder = ctx->ac.builder;
 
@@ -469,21 +468,20 @@ build_tgsi_intrinsic_nomem(const struct lp_build_tgsi_action *action,
 		lp_build_intrinsic(ctx->ac.builder, action->intr_name,
 				   emit_data->dst_type, emit_data->args,
 				   emit_data->arg_count, LP_FUNC_ATTR_READNONE);
 }
 
 static void emit_bfi(const struct lp_build_tgsi_action *action,
 		     struct lp_build_tgsi_context *bld_base,
 		     struct lp_build_emit_data *emit_data)
 {
 	struct si_shader_context *ctx = si_shader_context(bld_base);
-	struct gallivm_state *gallivm = bld_base->base.gallivm;
 	LLVMBuilderRef builder = ctx->ac.builder;
 	LLVMValueRef bfi_args[3];
 	LLVMValueRef bfi_sm5;
 	LLVMValueRef cond;
 
 	// Calculate the bitmask: (((1 << src3) - 1) << src2
 	bfi_args[0] = LLVMBuildShl(builder,
 				   LLVMBuildSub(builder,
 						LLVMBuildShl(builder,
 							     ctx->i32_1,
@@ -504,21 +502,21 @@ static void emit_bfi(const struct lp_build_tgsi_action *action,
 		LLVMBuildXor(builder, bfi_args[2],
 			LLVMBuildAnd(builder, bfi_args[0],
 				LLVMBuildXor(builder, bfi_args[1], bfi_args[2],
 					     ""), ""), "");
 
 	/* Since shifts of >= 32 bits are undefined in LLVM IR, the backend
 	 * uses the convenient V_BFI lowering for the above, which follows SM5
 	 * and disagrees with GLSL semantics when bits (src3) is 32.
 	 */
 	cond = LLVMBuildICmp(builder, LLVMIntUGE, emit_data->args[3],
-			     lp_build_const_int32(gallivm, 32), "");
+			     LLVMConstInt(ctx->i32, 32, 0), "");
 	emit_data->output[emit_data->chan] =
 		LLVMBuildSelect(builder, cond, emit_data->args[1], bfi_sm5, "");
 }
 
 static void emit_bfe(const struct lp_build_tgsi_action *action,
 		     struct lp_build_tgsi_context *bld_base,
 		     struct lp_build_emit_data *emit_data)
 {
 	struct si_shader_context *ctx = si_shader_context(bld_base);
 	LLVMValueRef bfe_sm5;
@@ -534,21 +532,20 @@ static void emit_bfe(const struct lp_build_tgsi_action *action,
 	emit_data->output[emit_data->chan] =
 		LLVMBuildSelect(ctx->ac.builder, cond, emit_data->args[0], bfe_sm5, "");
 }
 
 /* this is ffs in C */
 static void emit_lsb(const struct lp_build_tgsi_action *action,
 		     struct lp_build_tgsi_context *bld_base,
 		     struct lp_build_emit_data *emit_data)
 {
 	struct si_shader_context *ctx = si_shader_context(bld_base);
-	struct gallivm_state *gallivm = bld_base->base.gallivm;
 	LLVMValueRef args[2] = {
 		emit_data->args[0],
 
 		/* The value of 1 means that ffs(x=0) = undef, so LLVM won't
 		 * add special code to check for x=0. The reason is that
 		 * the LLVM behavior for x=0 is different from what we
 		 * need here. However, LLVM also assumes that ffs(x) is
 		 * in [0, 31], but GLSL expects that ffs(0) = -1, so
 		 * a conditional assignment to handle 0 is still required.
 		 */
@@ -559,21 +556,21 @@ static void emit_lsb(const struct lp_build_tgsi_action *action,
 		lp_build_intrinsic(ctx->ac.builder, "llvm.cttz.i32",
 				emit_data->dst_type, args, ARRAY_SIZE(args),
 				LP_FUNC_ATTR_READNONE);
 
 	/* TODO: We need an intrinsic to skip this conditional. */
 	/* Check for zero: */
 	emit_data->output[emit_data->chan] =
 		LLVMBuildSelect(ctx->ac.builder,
 				LLVMBuildICmp(ctx->ac.builder, LLVMIntEQ, args[0],
 					      ctx->i32_0, ""),
-				lp_build_const_int32(gallivm, -1), lsb, "");
+				LLVMConstInt(ctx->i32, -1, 0), lsb, "");
 }
 
 /* Find the last bit set. */
 static void emit_umsb(const struct lp_build_tgsi_action *action,
 		      struct lp_build_tgsi_context *bld_base,
 		      struct lp_build_emit_data *emit_data)
 {
 	struct si_shader_context *ctx = si_shader_context(bld_base);
 
 	emit_data->output[emit_data->chan] =
@@ -668,27 +665,26 @@ static void up2h_fetch_args(struct lp_build_tgsi_context *bld_base,
 {
 	emit_data->args[0] = lp_build_emit_fetch(bld_base, emit_data->inst,
 						 0, TGSI_CHAN_X);
 }
 
 static void emit_up2h(const struct lp_build_tgsi_action *action,
 		      struct lp_build_tgsi_context *bld_base,
 		      struct lp_build_emit_data *emit_data)
 {
 	struct si_shader_context *ctx = si_shader_context(bld_base);
-	struct lp_build_context *uint_bld = &bld_base->uint_bld;
 	LLVMTypeRef i16;
 	LLVMValueRef const16, input, val;
 	unsigned i;
 
 	i16 = LLVMInt16TypeInContext(ctx->ac.context);
-	const16 = lp_build_const_int32(uint_bld->gallivm, 16);
+	const16 = LLVMConstInt(ctx->i32, 16, 0);
 	input = emit_data->args[0];
 
 	for (i = 0; i < 2; i++) {
 		val = i == 1 ? LLVMBuildLShr(ctx->ac.builder, input, const16, "") : input;
 		val = LLVMBuildTrunc(ctx->ac.builder, val, i16, "");
 		val = ac_to_float(&ctx->ac, val);
 		emit_data->output[i] = LLVMBuildFPExt(ctx->ac.builder, val, ctx->f32, "");
 	}
 }
 
diff --git a/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c b/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c
index 6a86681..87f51a8 100644
--- a/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c
+++ b/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c
@@ -1186,21 +1186,21 @@ void si_llvm_context_init(struct si_shader_context *ctx,
 	lp_build_context_init(&ctx->bld_base.int64_bld, &ctx->gallivm, lp_int_type(type));
 
 	bld_base->soa = 1;
 	bld_base->emit_swizzle = emit_swizzle;
 	bld_base->emit_declaration = emit_declaration;
 	bld_base->emit_immediate = emit_immediate;
 
 	/* metadata allowing 2.5 ULP */
 	ctx->fpmath_md_kind = LLVMGetMDKindIDInContext(ctx->ac.context,
 						       "fpmath", 6);
-	LLVMValueRef arg = lp_build_const_float(&ctx->gallivm, 2.5);
+	LLVMValueRef arg = LLVMConstReal(ctx->f32, 2.5);
 	ctx->fpmath_md_2p5_ulp = LLVMMDNodeInContext(ctx->ac.context,
 						     &arg, 1);
 
 	bld_base->op_actions[TGSI_OPCODE_BGNLOOP].emit = bgnloop_emit;
 	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;
-- 
2.7.4



More information about the mesa-dev mailing list