radeonsi: use ctx->ac.builder

Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
This commit is contained in:
Marek Olšák 2017-09-29 15:02:06 +02:00
parent 82dc72c8bd
commit d0751f6c1f
4 changed files with 342 additions and 422 deletions

File diff suppressed because it is too large Load diff

View file

@ -32,8 +32,9 @@ 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 = gallivm->builder;
LLVMBuilderRef builder = ctx->ac.builder;
unsigned i;
LLVMValueRef conds[TGSI_NUM_CHANNELS];
@ -60,7 +61,7 @@ static void kil_emit(const struct lp_build_tgsi_action *action,
struct lp_build_emit_data *emit_data)
{
struct si_shader_context *ctx = si_shader_context(bld_base);
LLVMBuilderRef builder = ctx->gallivm.builder;
LLVMBuilderRef builder = ctx->ac.builder;
if (ctx->postponed_kill) {
if (emit_data->inst->Instruction.Opcode == TGSI_OPCODE_KILL_IF) {
@ -93,7 +94,7 @@ static void emit_icmp(const struct lp_build_tgsi_action *action,
struct lp_build_emit_data *emit_data)
{
unsigned pred;
LLVMBuilderRef builder = bld_base->base.gallivm->builder;
struct si_shader_context *ctx = si_shader_context(bld_base);
LLVMContextRef context = bld_base->base.gallivm->context;
switch (emit_data->inst->Instruction.Opcode) {
@ -115,10 +116,10 @@ static void emit_icmp(const struct lp_build_tgsi_action *action,
break;
}
LLVMValueRef v = LLVMBuildICmp(builder, pred,
LLVMValueRef v = LLVMBuildICmp(ctx->ac.builder, pred,
emit_data->args[0], emit_data->args[1],"");
v = LLVMBuildSExtOrBitCast(builder, v,
v = LLVMBuildSExtOrBitCast(ctx->ac.builder, v,
LLVMInt32TypeInContext(context), "");
emit_data->output[emit_data->chan] = v;
@ -129,36 +130,34 @@ static void emit_ucmp(const struct lp_build_tgsi_action *action,
struct lp_build_emit_data *emit_data)
{
struct si_shader_context *ctx = si_shader_context(bld_base);
LLVMBuilderRef builder = bld_base->base.gallivm->builder;
LLVMValueRef arg0 = ac_to_integer(&ctx->ac, emit_data->args[0]);
LLVMValueRef v = LLVMBuildICmp(builder, LLVMIntNE, arg0,
LLVMValueRef v = LLVMBuildICmp(ctx->ac.builder, LLVMIntNE, arg0,
ctx->i32_0, "");
emit_data->output[emit_data->chan] =
LLVMBuildSelect(builder, v, emit_data->args[1], emit_data->args[2], "");
LLVMBuildSelect(ctx->ac.builder, v, emit_data->args[1], emit_data->args[2], "");
}
static void emit_cmp(const struct lp_build_tgsi_action *action,
struct lp_build_tgsi_context *bld_base,
struct lp_build_emit_data *emit_data)
{
LLVMBuilderRef builder = bld_base->base.gallivm->builder;
struct si_shader_context *ctx = si_shader_context(bld_base);
LLVMValueRef cond, *args = emit_data->args;
cond = LLVMBuildFCmp(builder, LLVMRealOLT, args[0],
cond = LLVMBuildFCmp(ctx->ac.builder, LLVMRealOLT, args[0],
bld_base->base.zero, "");
emit_data->output[emit_data->chan] =
LLVMBuildSelect(builder, cond, args[1], args[2], "");
LLVMBuildSelect(ctx->ac.builder, cond, args[1], args[2], "");
}
static void emit_set_cond(const struct lp_build_tgsi_action *action,
struct lp_build_tgsi_context *bld_base,
struct lp_build_emit_data *emit_data)
{
LLVMBuilderRef builder = bld_base->base.gallivm->builder;
struct si_shader_context *ctx = si_shader_context(bld_base);
LLVMRealPredicate pred;
LLVMValueRef cond;
@ -175,10 +174,10 @@ static void emit_set_cond(const struct lp_build_tgsi_action *action,
default: assert(!"unknown instruction"); pred = 0; break;
}
cond = LLVMBuildFCmp(builder,
cond = LLVMBuildFCmp(ctx->ac.builder,
pred, emit_data->args[0], emit_data->args[1], "");
emit_data->output[emit_data->chan] = LLVMBuildSelect(builder,
emit_data->output[emit_data->chan] = LLVMBuildSelect(ctx->ac.builder,
cond, bld_base->base.one, bld_base->base.zero, "");
}
@ -186,7 +185,7 @@ static void emit_fcmp(const struct lp_build_tgsi_action *action,
struct lp_build_tgsi_context *bld_base,
struct lp_build_emit_data *emit_data)
{
LLVMBuilderRef builder = bld_base->base.gallivm->builder;
struct si_shader_context *ctx = si_shader_context(bld_base);
LLVMContextRef context = bld_base->base.gallivm->context;
LLVMRealPredicate pred;
@ -201,10 +200,10 @@ static void emit_fcmp(const struct lp_build_tgsi_action *action,
default: assert(!"unknown instruction"); pred = 0; break;
}
LLVMValueRef v = LLVMBuildFCmp(builder, pred,
LLVMValueRef v = LLVMBuildFCmp(ctx->ac.builder, pred,
emit_data->args[0], emit_data->args[1],"");
v = LLVMBuildSExtOrBitCast(builder, v,
v = LLVMBuildSExtOrBitCast(ctx->ac.builder, v,
LLVMInt32TypeInContext(context), "");
emit_data->output[emit_data->chan] = v;
@ -214,7 +213,7 @@ static void emit_dcmp(const struct lp_build_tgsi_action *action,
struct lp_build_tgsi_context *bld_base,
struct lp_build_emit_data *emit_data)
{
LLVMBuilderRef builder = bld_base->base.gallivm->builder;
struct si_shader_context *ctx = si_shader_context(bld_base);
LLVMContextRef context = bld_base->base.gallivm->context;
LLVMRealPredicate pred;
@ -229,10 +228,10 @@ static void emit_dcmp(const struct lp_build_tgsi_action *action,
default: assert(!"unknown instruction"); pred = 0; break;
}
LLVMValueRef v = LLVMBuildFCmp(builder, pred,
LLVMValueRef v = LLVMBuildFCmp(ctx->ac.builder, pred,
emit_data->args[0], emit_data->args[1],"");
v = LLVMBuildSExtOrBitCast(builder, v,
v = LLVMBuildSExtOrBitCast(ctx->ac.builder, v,
LLVMInt32TypeInContext(context), "");
emit_data->output[emit_data->chan] = v;
@ -243,9 +242,8 @@ static void emit_not(const struct lp_build_tgsi_action *action,
struct lp_build_emit_data *emit_data)
{
struct si_shader_context *ctx = si_shader_context(bld_base);
LLVMBuilderRef builder = bld_base->base.gallivm->builder;
LLVMValueRef v = ac_to_integer(&ctx->ac, emit_data->args[0]);
emit_data->output[emit_data->chan] = LLVMBuildNot(builder, v, "");
emit_data->output[emit_data->chan] = LLVMBuildNot(ctx->ac.builder, v, "");
}
static void emit_arl(const struct lp_build_tgsi_action *action,
@ -253,9 +251,8 @@ static void emit_arl(const struct lp_build_tgsi_action *action,
struct lp_build_emit_data *emit_data)
{
struct si_shader_context *ctx = si_shader_context(bld_base);
LLVMBuilderRef builder = bld_base->base.gallivm->builder;
LLVMValueRef floor_index = lp_build_emit_llvm_unary(bld_base, TGSI_OPCODE_FLR, emit_data->args[0]);
emit_data->output[emit_data->chan] = LLVMBuildFPToSI(builder,
emit_data->output[emit_data->chan] = LLVMBuildFPToSI(ctx->ac.builder,
floor_index, ctx->i32, "");
}
@ -263,8 +260,8 @@ static void emit_and(const struct lp_build_tgsi_action *action,
struct lp_build_tgsi_context *bld_base,
struct lp_build_emit_data *emit_data)
{
LLVMBuilderRef builder = bld_base->base.gallivm->builder;
emit_data->output[emit_data->chan] = LLVMBuildAnd(builder,
struct si_shader_context *ctx = si_shader_context(bld_base);
emit_data->output[emit_data->chan] = LLVMBuildAnd(ctx->ac.builder,
emit_data->args[0], emit_data->args[1], "");
}
@ -272,8 +269,8 @@ static void emit_or(const struct lp_build_tgsi_action *action,
struct lp_build_tgsi_context *bld_base,
struct lp_build_emit_data *emit_data)
{
LLVMBuilderRef builder = bld_base->base.gallivm->builder;
emit_data->output[emit_data->chan] = LLVMBuildOr(builder,
struct si_shader_context *ctx = si_shader_context(bld_base);
emit_data->output[emit_data->chan] = LLVMBuildOr(ctx->ac.builder,
emit_data->args[0], emit_data->args[1], "");
}
@ -281,8 +278,8 @@ static void emit_uadd(const struct lp_build_tgsi_action *action,
struct lp_build_tgsi_context *bld_base,
struct lp_build_emit_data *emit_data)
{
LLVMBuilderRef builder = bld_base->base.gallivm->builder;
emit_data->output[emit_data->chan] = LLVMBuildAdd(builder,
struct si_shader_context *ctx = si_shader_context(bld_base);
emit_data->output[emit_data->chan] = LLVMBuildAdd(ctx->ac.builder,
emit_data->args[0], emit_data->args[1], "");
}
@ -290,8 +287,8 @@ static void emit_udiv(const struct lp_build_tgsi_action *action,
struct lp_build_tgsi_context *bld_base,
struct lp_build_emit_data *emit_data)
{
LLVMBuilderRef builder = bld_base->base.gallivm->builder;
emit_data->output[emit_data->chan] = LLVMBuildUDiv(builder,
struct si_shader_context *ctx = si_shader_context(bld_base);
emit_data->output[emit_data->chan] = LLVMBuildUDiv(ctx->ac.builder,
emit_data->args[0], emit_data->args[1], "");
}
@ -299,8 +296,8 @@ static void emit_idiv(const struct lp_build_tgsi_action *action,
struct lp_build_tgsi_context *bld_base,
struct lp_build_emit_data *emit_data)
{
LLVMBuilderRef builder = bld_base->base.gallivm->builder;
emit_data->output[emit_data->chan] = LLVMBuildSDiv(builder,
struct si_shader_context *ctx = si_shader_context(bld_base);
emit_data->output[emit_data->chan] = LLVMBuildSDiv(ctx->ac.builder,
emit_data->args[0], emit_data->args[1], "");
}
@ -308,8 +305,8 @@ static void emit_mod(const struct lp_build_tgsi_action *action,
struct lp_build_tgsi_context *bld_base,
struct lp_build_emit_data *emit_data)
{
LLVMBuilderRef builder = bld_base->base.gallivm->builder;
emit_data->output[emit_data->chan] = LLVMBuildSRem(builder,
struct si_shader_context *ctx = si_shader_context(bld_base);
emit_data->output[emit_data->chan] = LLVMBuildSRem(ctx->ac.builder,
emit_data->args[0], emit_data->args[1], "");
}
@ -317,8 +314,8 @@ static void emit_umod(const struct lp_build_tgsi_action *action,
struct lp_build_tgsi_context *bld_base,
struct lp_build_emit_data *emit_data)
{
LLVMBuilderRef builder = bld_base->base.gallivm->builder;
emit_data->output[emit_data->chan] = LLVMBuildURem(builder,
struct si_shader_context *ctx = si_shader_context(bld_base);
emit_data->output[emit_data->chan] = LLVMBuildURem(ctx->ac.builder,
emit_data->args[0], emit_data->args[1], "");
}
@ -326,8 +323,8 @@ static void emit_shl(const struct lp_build_tgsi_action *action,
struct lp_build_tgsi_context *bld_base,
struct lp_build_emit_data *emit_data)
{
LLVMBuilderRef builder = bld_base->base.gallivm->builder;
emit_data->output[emit_data->chan] = LLVMBuildShl(builder,
struct si_shader_context *ctx = si_shader_context(bld_base);
emit_data->output[emit_data->chan] = LLVMBuildShl(ctx->ac.builder,
emit_data->args[0], emit_data->args[1], "");
}
@ -335,16 +332,16 @@ static void emit_ushr(const struct lp_build_tgsi_action *action,
struct lp_build_tgsi_context *bld_base,
struct lp_build_emit_data *emit_data)
{
LLVMBuilderRef builder = bld_base->base.gallivm->builder;
emit_data->output[emit_data->chan] = LLVMBuildLShr(builder,
struct si_shader_context *ctx = si_shader_context(bld_base);
emit_data->output[emit_data->chan] = LLVMBuildLShr(ctx->ac.builder,
emit_data->args[0], emit_data->args[1], "");
}
static void emit_ishr(const struct lp_build_tgsi_action *action,
struct lp_build_tgsi_context *bld_base,
struct lp_build_emit_data *emit_data)
{
LLVMBuilderRef builder = bld_base->base.gallivm->builder;
emit_data->output[emit_data->chan] = LLVMBuildAShr(builder,
struct si_shader_context *ctx = si_shader_context(bld_base);
emit_data->output[emit_data->chan] = LLVMBuildAShr(ctx->ac.builder,
emit_data->args[0], emit_data->args[1], "");
}
@ -352,8 +349,8 @@ static void emit_xor(const struct lp_build_tgsi_action *action,
struct lp_build_tgsi_context *bld_base,
struct lp_build_emit_data *emit_data)
{
LLVMBuilderRef builder = bld_base->base.gallivm->builder;
emit_data->output[emit_data->chan] = LLVMBuildXor(builder,
struct si_shader_context *ctx = si_shader_context(bld_base);
emit_data->output[emit_data->chan] = LLVMBuildXor(ctx->ac.builder,
emit_data->args[0], emit_data->args[1], "");
}
@ -362,7 +359,7 @@ static void emit_ssg(const struct lp_build_tgsi_action *action,
struct lp_build_emit_data *emit_data)
{
struct si_shader_context *ctx = si_shader_context(bld_base);
LLVMBuilderRef builder = bld_base->base.gallivm->builder;
LLVMBuilderRef builder = ctx->ac.builder;
LLVMValueRef cmp, val;
@ -395,8 +392,8 @@ static void emit_ineg(const struct lp_build_tgsi_action *action,
struct lp_build_tgsi_context *bld_base,
struct lp_build_emit_data *emit_data)
{
LLVMBuilderRef builder = bld_base->base.gallivm->builder;
emit_data->output[emit_data->chan] = LLVMBuildNeg(builder,
struct si_shader_context *ctx = si_shader_context(bld_base);
emit_data->output[emit_data->chan] = LLVMBuildNeg(ctx->ac.builder,
emit_data->args[0], "");
}
@ -404,8 +401,8 @@ static void emit_dneg(const struct lp_build_tgsi_action *action,
struct lp_build_tgsi_context *bld_base,
struct lp_build_emit_data *emit_data)
{
LLVMBuilderRef builder = bld_base->base.gallivm->builder;
emit_data->output[emit_data->chan] = LLVMBuildFNeg(builder,
struct si_shader_context *ctx = si_shader_context(bld_base);
emit_data->output[emit_data->chan] = LLVMBuildFNeg(ctx->ac.builder,
emit_data->args[0], "");
}
@ -413,7 +410,7 @@ static void emit_frac(const struct lp_build_tgsi_action *action,
struct lp_build_tgsi_context *bld_base,
struct lp_build_emit_data *emit_data)
{
LLVMBuilderRef builder = bld_base->base.gallivm->builder;
struct si_shader_context *ctx = si_shader_context(bld_base);
char *intr;
if (emit_data->info->opcode == TGSI_OPCODE_FRC)
@ -425,10 +422,10 @@ static void emit_frac(const struct lp_build_tgsi_action *action,
return;
}
LLVMValueRef floor = lp_build_intrinsic(builder, intr, emit_data->dst_type,
LLVMValueRef floor = lp_build_intrinsic(ctx->ac.builder, intr, emit_data->dst_type,
&emit_data->args[0], 1,
LP_FUNC_ATTR_READNONE);
emit_data->output[emit_data->chan] = LLVMBuildFSub(builder,
emit_data->output[emit_data->chan] = LLVMBuildFSub(ctx->ac.builder,
emit_data->args[0], floor, "");
}
@ -436,8 +433,8 @@ static void emit_f2i(const struct lp_build_tgsi_action *action,
struct lp_build_tgsi_context *bld_base,
struct lp_build_emit_data *emit_data)
{
LLVMBuilderRef builder = bld_base->base.gallivm->builder;
emit_data->output[emit_data->chan] = LLVMBuildFPToSI(builder,
struct si_shader_context *ctx = si_shader_context(bld_base);
emit_data->output[emit_data->chan] = LLVMBuildFPToSI(ctx->ac.builder,
emit_data->args[0], bld_base->int_bld.elem_type, "");
}
@ -445,8 +442,8 @@ static void emit_f2u(const struct lp_build_tgsi_action *action,
struct lp_build_tgsi_context *bld_base,
struct lp_build_emit_data *emit_data)
{
LLVMBuilderRef builder = bld_base->base.gallivm->builder;
emit_data->output[emit_data->chan] = LLVMBuildFPToUI(builder,
struct si_shader_context *ctx = si_shader_context(bld_base);
emit_data->output[emit_data->chan] = LLVMBuildFPToUI(ctx->ac.builder,
emit_data->args[0], bld_base->uint_bld.elem_type, "");
}
@ -454,8 +451,8 @@ static void emit_i2f(const struct lp_build_tgsi_action *action,
struct lp_build_tgsi_context *bld_base,
struct lp_build_emit_data *emit_data)
{
LLVMBuilderRef builder = bld_base->base.gallivm->builder;
emit_data->output[emit_data->chan] = LLVMBuildSIToFP(builder,
struct si_shader_context *ctx = si_shader_context(bld_base);
emit_data->output[emit_data->chan] = LLVMBuildSIToFP(ctx->ac.builder,
emit_data->args[0], bld_base->base.elem_type, "");
}
@ -463,8 +460,8 @@ static void emit_u2f(const struct lp_build_tgsi_action *action,
struct lp_build_tgsi_context *bld_base,
struct lp_build_emit_data *emit_data)
{
LLVMBuilderRef builder = bld_base->base.gallivm->builder;
emit_data->output[emit_data->chan] = LLVMBuildUIToFP(builder,
struct si_shader_context *ctx = si_shader_context(bld_base);
emit_data->output[emit_data->chan] = LLVMBuildUIToFP(ctx->ac.builder,
emit_data->args[0], bld_base->base.elem_type, "");
}
@ -473,9 +470,9 @@ build_tgsi_intrinsic_nomem(const struct lp_build_tgsi_action *action,
struct lp_build_tgsi_context *bld_base,
struct lp_build_emit_data *emit_data)
{
struct lp_build_context *base = &bld_base->base;
struct si_shader_context *ctx = si_shader_context(bld_base);
emit_data->output[emit_data->chan] =
lp_build_intrinsic(base->gallivm->builder, action->intr_name,
lp_build_intrinsic(ctx->ac.builder, action->intr_name,
emit_data->dst_type, emit_data->args,
emit_data->arg_count, LP_FUNC_ATTR_READNONE);
}
@ -486,7 +483,7 @@ static void emit_bfi(const struct lp_build_tgsi_action *action,
{
struct si_shader_context *ctx = si_shader_context(bld_base);
struct gallivm_state *gallivm = bld_base->base.gallivm;
LLVMBuilderRef builder = gallivm->builder;
LLVMBuilderRef builder = ctx->ac.builder;
LLVMValueRef bfi_args[3];
LLVMValueRef bfi_sm5;
LLVMValueRef cond;
@ -530,8 +527,6 @@ static void emit_bfe(const struct lp_build_tgsi_action *action,
struct lp_build_emit_data *emit_data)
{
struct si_shader_context *ctx = si_shader_context(bld_base);
struct gallivm_state *gallivm = &ctx->gallivm;
LLVMBuilderRef builder = gallivm->builder;
LLVMValueRef bfe_sm5;
LLVMValueRef cond;
@ -540,10 +535,10 @@ static void emit_bfe(const struct lp_build_tgsi_action *action,
emit_data->info->opcode == TGSI_OPCODE_IBFE);
/* Correct for GLSL semantics. */
cond = LLVMBuildICmp(builder, LLVMIntUGE, emit_data->args[2],
cond = LLVMBuildICmp(ctx->ac.builder, LLVMIntUGE, emit_data->args[2],
LLVMConstInt(ctx->i32, 32, 0), "");
emit_data->output[emit_data->chan] =
LLVMBuildSelect(builder, cond, emit_data->args[0], bfe_sm5, "");
LLVMBuildSelect(ctx->ac.builder, cond, emit_data->args[0], bfe_sm5, "");
}
/* this is ffs in C */
@ -553,7 +548,6 @@ static void emit_lsb(const struct lp_build_tgsi_action *action,
{
struct si_shader_context *ctx = si_shader_context(bld_base);
struct gallivm_state *gallivm = bld_base->base.gallivm;
LLVMBuilderRef builder = gallivm->builder;
LLVMValueRef args[2] = {
emit_data->args[0],
@ -568,15 +562,15 @@ static void emit_lsb(const struct lp_build_tgsi_action *action,
};
LLVMValueRef lsb =
lp_build_intrinsic(gallivm->builder, "llvm.cttz.i32",
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(builder,
LLVMBuildICmp(builder, LLVMIntEQ, args[0],
LLVMBuildSelect(ctx->ac.builder,
LLVMBuildICmp(ctx->ac.builder, LLVMIntEQ, args[0],
ctx->i32_0, ""),
lp_build_const_int32(gallivm, -1), lsb, "");
}
@ -607,12 +601,12 @@ static void emit_iabs(const struct lp_build_tgsi_action *action,
struct lp_build_tgsi_context *bld_base,
struct lp_build_emit_data *emit_data)
{
LLVMBuilderRef builder = bld_base->base.gallivm->builder;
struct si_shader_context *ctx = si_shader_context(bld_base);
emit_data->output[emit_data->chan] =
lp_build_emit_llvm_binary(bld_base, TGSI_OPCODE_IMAX,
emit_data->args[0],
LLVMBuildNeg(builder,
LLVMBuildNeg(ctx->ac.builder,
emit_data->args[0], ""));
}
@ -620,7 +614,7 @@ static void emit_minmax_int(const struct lp_build_tgsi_action *action,
struct lp_build_tgsi_context *bld_base,
struct lp_build_emit_data *emit_data)
{
LLVMBuilderRef builder = bld_base->base.gallivm->builder;
struct si_shader_context *ctx = si_shader_context(bld_base);
LLVMIntPredicate op;
switch (emit_data->info->opcode) {
@ -645,8 +639,8 @@ static void emit_minmax_int(const struct lp_build_tgsi_action *action,
}
emit_data->output[emit_data->chan] =
LLVMBuildSelect(builder,
LLVMBuildICmp(builder, op, emit_data->args[0],
LLVMBuildSelect(ctx->ac.builder,
LLVMBuildICmp(ctx->ac.builder, op, emit_data->args[0],
emit_data->args[1], ""),
emit_data->args[0],
emit_data->args[1], "");
@ -687,7 +681,6 @@ static void emit_up2h(const struct lp_build_tgsi_action *action,
struct lp_build_emit_data *emit_data)
{
struct si_shader_context *ctx = si_shader_context(bld_base);
LLVMBuilderRef builder = bld_base->base.gallivm->builder;
LLVMContextRef context = bld_base->base.gallivm->context;
struct lp_build_context *uint_bld = &bld_base->uint_bld;
LLVMTypeRef i16;
@ -699,10 +692,10 @@ static void emit_up2h(const struct lp_build_tgsi_action *action,
input = emit_data->args[0];
for (i = 0; i < 2; i++) {
val = i == 1 ? LLVMBuildLShr(builder, input, const16, "") : input;
val = LLVMBuildTrunc(builder, val, i16, "");
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(builder, val, ctx->f32, "");
emit_data->output[i] = LLVMBuildFPExt(ctx->ac.builder, val, ctx->f32, "");
}
}
@ -713,7 +706,7 @@ static void emit_fdiv(const struct lp_build_tgsi_action *action,
struct si_shader_context *ctx = si_shader_context(bld_base);
emit_data->output[emit_data->chan] =
LLVMBuildFDiv(ctx->gallivm.builder,
LLVMBuildFDiv(ctx->ac.builder,
emit_data->args[0], emit_data->args[1], "");
/* Use v_rcp_f32 instead of precise division. */

View file

@ -46,8 +46,7 @@ static LLVMValueRef get_buffer_size(
LLVMValueRef descriptor)
{
struct si_shader_context *ctx = si_shader_context(bld_base);
struct gallivm_state *gallivm = &ctx->gallivm;
LLVMBuilderRef builder = gallivm->builder;
LLVMBuilderRef builder = ctx->ac.builder;
LLVMValueRef size =
LLVMBuildExtractElement(builder, descriptor,
LLVMConstInt(ctx->i32, 2, 0), "");
@ -118,14 +117,13 @@ static LLVMValueRef force_dcc_off(struct si_shader_context *ctx,
if (ctx->screen->b.chip_class <= CIK) {
return rsrc;
} else {
LLVMBuilderRef builder = ctx->gallivm.builder;
LLVMValueRef i32_6 = LLVMConstInt(ctx->i32, 6, 0);
LLVMValueRef i32_C = LLVMConstInt(ctx->i32, C_008F28_COMPRESSION_EN, 0);
LLVMValueRef tmp;
tmp = LLVMBuildExtractElement(builder, rsrc, i32_6, "");
tmp = LLVMBuildAnd(builder, tmp, i32_C, "");
return LLVMBuildInsertElement(builder, rsrc, tmp, i32_6, "");
tmp = LLVMBuildExtractElement(ctx->ac.builder, rsrc, i32_6, "");
tmp = LLVMBuildAnd(ctx->ac.builder, tmp, i32_C, "");
return LLVMBuildInsertElement(ctx->ac.builder, rsrc, tmp, i32_6, "");
}
}
@ -133,7 +131,7 @@ LLVMValueRef si_load_image_desc(struct si_shader_context *ctx,
LLVMValueRef list, LLVMValueRef index,
enum ac_descriptor_type desc_type, bool dcc_off)
{
LLVMBuilderRef builder = ctx->gallivm.builder;
LLVMBuilderRef builder = ctx->ac.builder;
LLVMValueRef rsrc;
if (desc_type == AC_DESC_BUFFER) {
@ -192,7 +190,7 @@ image_fetch_rsrc(
index = si_get_bounded_indirect_index(ctx, &image->Indirect,
image->Register.Index,
ctx->num_images);
index = LLVMBuildSub(ctx->gallivm.builder,
index = LLVMBuildSub(ctx->ac.builder,
LLVMConstInt(ctx->i32, SI_NUM_IMAGES - 1, 0),
index, "");
}
@ -201,9 +199,6 @@ image_fetch_rsrc(
/* Bindless descriptors are accessible from a different pair of
* user SGPR indices.
*/
struct gallivm_state *gallivm = &ctx->gallivm;
LLVMBuilderRef builder = gallivm->builder;
rsrc_ptr = LLVMGetParam(ctx->main_fn,
ctx->param_bindless_samplers_and_images);
index = lp_build_emit_fetch_src(bld_base, image,
@ -212,7 +207,7 @@ image_fetch_rsrc(
/* For simplicity, bindless image descriptors use fixed
* 16-dword slots for now.
*/
index = LLVMBuildMul(builder, index,
index = LLVMBuildMul(ctx->ac.builder, index,
LLVMConstInt(ctx->i32, 2, 0), "");
}
@ -228,7 +223,7 @@ static LLVMValueRef image_fetch_coords(
{
struct si_shader_context *ctx = si_shader_context(bld_base);
struct gallivm_state *gallivm = &ctx->gallivm;
LLVMBuilderRef builder = gallivm->builder;
LLVMBuilderRef builder = ctx->ac.builder;
unsigned target = inst->Memory.Texture;
unsigned num_coords = tgsi_util_get_texture_coord_dim(target);
LLVMValueRef coords[4];
@ -448,8 +443,7 @@ static LLVMValueRef get_memory_ptr(struct si_shader_context *ctx,
const struct tgsi_full_instruction *inst,
LLVMTypeRef type, int arg)
{
struct gallivm_state *gallivm = &ctx->gallivm;
LLVMBuilderRef builder = gallivm->builder;
LLVMBuilderRef builder = ctx->ac.builder;
LLVMValueRef offset, ptr;
int addr_space;
@ -470,7 +464,6 @@ static void load_emit_memory(
{
const struct tgsi_full_instruction *inst = emit_data->inst;
struct gallivm_state *gallivm = &ctx->gallivm;
LLVMBuilderRef builder = gallivm->builder;
unsigned writemask = inst->Dst[0].Register.WriteMask;
LLVMValueRef channels[4], ptr, derived_ptr, index;
int chan;
@ -484,8 +477,8 @@ static void load_emit_memory(
}
index = LLVMConstInt(ctx->i32, chan, 0);
derived_ptr = LLVMBuildGEP(builder, ptr, &index, 1, "");
channels[chan] = LLVMBuildLoad(builder, derived_ptr, "");
derived_ptr = LLVMBuildGEP(ctx->ac.builder, ptr, &index, 1, "");
channels[chan] = LLVMBuildLoad(ctx->ac.builder, derived_ptr, "");
}
emit_data->output[emit_data->chan] = lp_build_gather_values(gallivm, channels, 4);
}
@ -559,8 +552,7 @@ static void load_emit(
struct lp_build_emit_data *emit_data)
{
struct si_shader_context *ctx = si_shader_context(bld_base);
struct gallivm_state *gallivm = &ctx->gallivm;
LLVMBuilderRef builder = gallivm->builder;
LLVMBuilderRef builder = ctx->ac.builder;
const struct tgsi_full_instruction * inst = emit_data->inst;
const struct tgsi_shader_info *info = &ctx->shader->selector->info;
char intrinsic_name[64];
@ -683,8 +675,7 @@ static void store_emit_buffer(
bool writeonly_memory)
{
const struct tgsi_full_instruction *inst = emit_data->inst;
struct gallivm_state *gallivm = &ctx->gallivm;
LLVMBuilderRef builder = gallivm->builder;
LLVMBuilderRef builder = ctx->ac.builder;
LLVMValueRef base_data = emit_data->args[0];
LLVMValueRef base_offset = emit_data->args[3];
unsigned writemask = inst->Dst[0].Register.WriteMask;
@ -755,8 +746,7 @@ static void store_emit_memory(
struct lp_build_emit_data *emit_data)
{
const struct tgsi_full_instruction *inst = emit_data->inst;
struct gallivm_state *gallivm = &ctx->gallivm;
LLVMBuilderRef builder = gallivm->builder;
LLVMBuilderRef builder = ctx->ac.builder;
unsigned writemask = inst->Dst[0].Register.WriteMask;
LLVMValueRef ptr, derived_ptr, data, index;
int chan;
@ -780,8 +770,7 @@ static void store_emit(
struct lp_build_emit_data *emit_data)
{
struct si_shader_context *ctx = si_shader_context(bld_base);
struct gallivm_state *gallivm = &ctx->gallivm;
LLVMBuilderRef builder = gallivm->builder;
LLVMBuilderRef builder = ctx->ac.builder;
const struct tgsi_full_instruction * inst = emit_data->inst;
const struct tgsi_shader_info *info = &ctx->shader->selector->info;
unsigned target = inst->Memory.Texture;
@ -887,8 +876,7 @@ static void atomic_fetch_args(
static void atomic_emit_memory(struct si_shader_context *ctx,
struct lp_build_emit_data *emit_data) {
struct gallivm_state *gallivm = &ctx->gallivm;
LLVMBuilderRef builder = gallivm->builder;
LLVMBuilderRef builder = ctx->ac.builder;
const struct tgsi_full_instruction * inst = emit_data->inst;
LLVMValueRef ptr, result, arg;
@ -958,8 +946,7 @@ static void atomic_emit(
struct lp_build_emit_data *emit_data)
{
struct si_shader_context *ctx = si_shader_context(bld_base);
struct gallivm_state *gallivm = &ctx->gallivm;
LLVMBuilderRef builder = gallivm->builder;
LLVMBuilderRef builder = ctx->ac.builder;
const struct tgsi_full_instruction * inst = emit_data->inst;
char intrinsic_name[40];
LLVMValueRef tmp;
@ -1028,7 +1015,7 @@ static void set_tex_fetch_args(struct si_shader_context *ctx,
static LLVMValueRef fix_resinfo(struct si_shader_context *ctx,
unsigned target, LLVMValueRef out)
{
LLVMBuilderRef builder = ctx->gallivm.builder;
LLVMBuilderRef builder = ctx->ac.builder;
/* 1D textures are allocated and used as 2D on GFX9. */
if (ctx->screen->b.chip_class >= GFX9 &&
@ -1094,8 +1081,7 @@ static void resq_emit(
struct lp_build_emit_data *emit_data)
{
struct si_shader_context *ctx = si_shader_context(bld_base);
struct gallivm_state *gallivm = &ctx->gallivm;
LLVMBuilderRef builder = gallivm->builder;
LLVMBuilderRef builder = ctx->ac.builder;
const struct tgsi_full_instruction *inst = emit_data->inst;
LLVMValueRef out;
@ -1124,8 +1110,7 @@ LLVMValueRef si_load_sampler_desc(struct si_shader_context *ctx,
LLVMValueRef list, LLVMValueRef index,
enum ac_descriptor_type type)
{
struct gallivm_state *gallivm = &ctx->gallivm;
LLVMBuilderRef builder = gallivm->builder;
LLVMBuilderRef builder = ctx->ac.builder;
switch (type) {
case AC_DESC_IMAGE:
@ -1170,18 +1155,17 @@ LLVMValueRef si_load_sampler_desc(struct si_shader_context *ctx,
static LLVMValueRef sici_fix_sampler_aniso(struct si_shader_context *ctx,
LLVMValueRef res, LLVMValueRef samp)
{
LLVMBuilderRef builder = ctx->gallivm.builder;
LLVMValueRef img7, samp0;
if (ctx->screen->b.chip_class >= VI)
return samp;
img7 = LLVMBuildExtractElement(builder, res,
img7 = LLVMBuildExtractElement(ctx->ac.builder, res,
LLVMConstInt(ctx->i32, 7, 0), "");
samp0 = LLVMBuildExtractElement(builder, samp,
samp0 = LLVMBuildExtractElement(ctx->ac.builder, samp,
ctx->i32_0, "");
samp0 = LLVMBuildAnd(builder, samp0, img7, "");
return LLVMBuildInsertElement(builder, samp, samp0,
samp0 = LLVMBuildAnd(ctx->ac.builder, samp0, img7, "");
return LLVMBuildInsertElement(ctx->ac.builder, samp, samp0,
ctx->i32_0, "");
}
@ -1206,7 +1190,7 @@ static void tex_fetch_ptrs(
&reg->Indirect,
reg->Register.Index,
ctx->num_samplers);
index = LLVMBuildAdd(ctx->gallivm.builder, index,
index = LLVMBuildAdd(ctx->ac.builder, index,
LLVMConstInt(ctx->i32, SI_NUM_IMAGES / 2, 0), "");
} else {
index = LLVMConstInt(ctx->i32,
@ -1299,7 +1283,6 @@ static void tex_fetch_args(
struct lp_build_emit_data *emit_data)
{
struct si_shader_context *ctx = si_shader_context(bld_base);
struct gallivm_state *gallivm = &ctx->gallivm;
const struct tgsi_full_instruction *inst = emit_data->inst;
unsigned opcode = inst->Instruction.Opcode;
unsigned target = inst->Texture.Texture;
@ -1355,15 +1338,15 @@ static void tex_fetch_args(
for (chan = 0; chan < 3; chan++) {
offset[chan] = lp_build_emit_fetch_texoffset(bld_base,
emit_data->inst, 0, chan);
offset[chan] = LLVMBuildAnd(gallivm->builder, offset[chan],
offset[chan] = LLVMBuildAnd(ctx->ac.builder, offset[chan],
LLVMConstInt(ctx->i32, 0x3f, 0), "");
if (chan)
offset[chan] = LLVMBuildShl(gallivm->builder, offset[chan],
offset[chan] = LLVMBuildShl(ctx->ac.builder, offset[chan],
LLVMConstInt(ctx->i32, chan*8, 0), "");
}
pack = LLVMBuildOr(gallivm->builder, offset[0], offset[1], "");
pack = LLVMBuildOr(gallivm->builder, pack, offset[2], "");
pack = LLVMBuildOr(ctx->ac.builder, offset[0], offset[1], "");
pack = LLVMBuildOr(ctx->ac.builder, pack, offset[2], "");
address[count++] = pack;
}
@ -1398,13 +1381,13 @@ static void tex_fetch_args(
if (ctx->screen->b.chip_class >= VI) {
LLVMValueRef upgraded;
LLVMValueRef clamped;
upgraded = LLVMBuildExtractElement(gallivm->builder, samp_ptr,
upgraded = LLVMBuildExtractElement(ctx->ac.builder, samp_ptr,
LLVMConstInt(ctx->i32, 3, false), "");
upgraded = LLVMBuildLShr(gallivm->builder, upgraded,
upgraded = LLVMBuildLShr(ctx->ac.builder, upgraded,
LLVMConstInt(ctx->i32, 29, false), "");
upgraded = LLVMBuildTrunc(gallivm->builder, upgraded, ctx->i1, "");
upgraded = LLVMBuildTrunc(ctx->ac.builder, upgraded, ctx->i1, "");
clamped = ac_build_clamp(&ctx->ac, z);
z = LLVMBuildSelect(gallivm->builder, upgraded, clamped, z, "");
z = LLVMBuildSelect(ctx->ac.builder, upgraded, clamped, z, "");
}
address[count++] = z;
@ -1578,39 +1561,39 @@ static void tex_fetch_args(
/* Apply the formula. */
LLVMValueRef fmask =
LLVMBuildExtractElement(gallivm->builder,
LLVMBuildExtractElement(ctx->ac.builder,
txf_emit_data.output[0],
ctx->i32_0, "");
unsigned sample_chan = txf_count; /* the sample index is last */
LLVMValueRef sample_index4 =
LLVMBuildMul(gallivm->builder, address[sample_chan], four, "");
LLVMBuildMul(ctx->ac.builder, address[sample_chan], four, "");
LLVMValueRef shifted_fmask =
LLVMBuildLShr(gallivm->builder, fmask, sample_index4, "");
LLVMBuildLShr(ctx->ac.builder, fmask, sample_index4, "");
LLVMValueRef final_sample =
LLVMBuildAnd(gallivm->builder, shifted_fmask, F, "");
LLVMBuildAnd(ctx->ac.builder, shifted_fmask, F, "");
/* Don't rewrite the sample index if WORD1.DATA_FORMAT of the FMASK
* resource descriptor is 0 (invalid),
*/
LLVMValueRef fmask_desc =
LLVMBuildBitCast(gallivm->builder, fmask_ptr,
LLVMBuildBitCast(ctx->ac.builder, fmask_ptr,
ctx->v8i32, "");
LLVMValueRef fmask_word1 =
LLVMBuildExtractElement(gallivm->builder, fmask_desc,
LLVMBuildExtractElement(ctx->ac.builder, fmask_desc,
ctx->i32_1, "");
LLVMValueRef word1_is_nonzero =
LLVMBuildICmp(gallivm->builder, LLVMIntNE,
LLVMBuildICmp(ctx->ac.builder, LLVMIntNE,
fmask_word1, ctx->i32_0, "");
/* Replace the MSAA sample index. */
address[sample_chan] =
LLVMBuildSelect(gallivm->builder, word1_is_nonzero,
LLVMBuildSelect(ctx->ac.builder, word1_is_nonzero,
final_sample, address[sample_chan], "");
}
@ -1702,7 +1685,7 @@ si_lower_gather4_integer(struct si_shader_context *ctx,
unsigned target,
enum tgsi_return_type return_type)
{
LLVMBuilderRef builder = ctx->gallivm.builder;
LLVMBuilderRef builder = ctx->ac.builder;
LLVMValueRef wa_8888 = NULL;
LLVMValueRef coord = args->addr;
LLVMValueRef half_texel[2];
@ -1822,7 +1805,7 @@ si_fix_gather4_integer_result(struct si_shader_context *ctx,
enum tgsi_return_type return_type,
LLVMValueRef wa)
{
LLVMBuilderRef builder = ctx->gallivm.builder;
LLVMBuilderRef builder = ctx->ac.builder;
assert(return_type == TGSI_RETURN_TYPE_SINT ||
return_type == TGSI_RETURN_TYPE_UINT);
@ -1951,8 +1934,6 @@ static void si_llvm_emit_txqs(
struct lp_build_emit_data *emit_data)
{
struct si_shader_context *ctx = si_shader_context(bld_base);
struct gallivm_state *gallivm = &ctx->gallivm;
LLVMBuilderRef builder = gallivm->builder;
LLVMValueRef res, samples;
LLVMValueRef res_ptr, samp_ptr, fmask_ptr = NULL;
@ -1960,15 +1941,14 @@ static void si_llvm_emit_txqs(
/* Read the samples from the descriptor directly. */
res = LLVMBuildBitCast(builder, res_ptr, ctx->v8i32, "");
samples = LLVMBuildExtractElement(
builder, res,
LLVMConstInt(ctx->i32, 3, 0), "");
samples = LLVMBuildLShr(builder, samples,
res = LLVMBuildBitCast(ctx->ac.builder, res_ptr, ctx->v8i32, "");
samples = LLVMBuildExtractElement(ctx->ac.builder, res,
LLVMConstInt(ctx->i32, 3, 0), "");
samples = LLVMBuildLShr(ctx->ac.builder, samples,
LLVMConstInt(ctx->i32, 16, 0), "");
samples = LLVMBuildAnd(builder, samples,
samples = LLVMBuildAnd(ctx->ac.builder, samples,
LLVMConstInt(ctx->i32, 0xf, 0), "");
samples = LLVMBuildShl(builder, ctx->i32_1,
samples = LLVMBuildShl(ctx->ac.builder, ctx->i32_1,
samples, "");
emit_data->output[emit_data->chan] = samples;

View file

@ -187,11 +187,11 @@ LLVMTypeRef tgsi2llvmtype(struct lp_build_tgsi_context *bld_base,
LLVMValueRef bitcast(struct lp_build_tgsi_context *bld_base,
enum tgsi_opcode_type type, LLVMValueRef value)
{
LLVMBuilderRef builder = bld_base->base.gallivm->builder;
struct si_shader_context *ctx = si_shader_context(bld_base);
LLVMTypeRef dst_type = tgsi2llvmtype(bld_base, type);
if (dst_type)
return LLVMBuildBitCast(builder, value, dst_type, "");
return LLVMBuildBitCast(ctx->ac.builder, value, dst_type, "");
else
return value;
}
@ -204,8 +204,7 @@ LLVMValueRef si_llvm_bound_index(struct si_shader_context *ctx,
LLVMValueRef index,
unsigned num)
{
struct gallivm_state *gallivm = &ctx->gallivm;
LLVMBuilderRef builder = gallivm->builder;
LLVMBuilderRef builder = ctx->ac.builder;
LLVMValueRef c_max = LLVMConstInt(ctx->i32, num - 1, 0);
LLVMValueRef cc;
@ -271,6 +270,7 @@ static LLVMValueRef emit_swizzle(struct lp_build_tgsi_context *bld_base,
unsigned swizzle_z,
unsigned swizzle_w)
{
struct si_shader_context *ctx = si_shader_context(bld_base);
LLVMValueRef swizzles[4];
LLVMTypeRef i32t =
LLVMInt32TypeInContext(bld_base->base.gallivm->context);
@ -280,7 +280,7 @@ static LLVMValueRef emit_swizzle(struct lp_build_tgsi_context *bld_base,
swizzles[2] = LLVMConstInt(i32t, swizzle_z, 0);
swizzles[3] = LLVMConstInt(i32t, swizzle_w, 0);
return LLVMBuildShuffleVector(bld_base->base.gallivm->builder,
return LLVMBuildShuffleVector(ctx->ac.builder,
value,
LLVMGetUndef(LLVMTypeOf(value)),
LLVMConstVector(swizzles, 4), "");
@ -347,8 +347,7 @@ get_pointer_into_array(struct si_shader_context *ctx,
{
unsigned array_id;
struct tgsi_array_info *array;
struct gallivm_state *gallivm = &ctx->gallivm;
LLVMBuilderRef builder = gallivm->builder;
LLVMBuilderRef builder = ctx->ac.builder;
LLVMValueRef idxs[2];
LLVMValueRef index;
LLVMValueRef alloca;
@ -397,7 +396,7 @@ get_pointer_into_array(struct si_shader_context *ctx,
"");
idxs[0] = ctx->i32_0;
idxs[1] = index;
return LLVMBuildGEP(builder, alloca, idxs, 2, "");
return LLVMBuildGEP(ctx->ac.builder, alloca, idxs, 2, "");
}
LLVMValueRef
@ -407,16 +406,15 @@ si_llvm_emit_fetch_64bit(struct lp_build_tgsi_context *bld_base,
LLVMValueRef ptr2)
{
struct si_shader_context *ctx = si_shader_context(bld_base);
LLVMBuilderRef builder = bld_base->base.gallivm->builder;
LLVMValueRef result;
result = LLVMGetUndef(LLVMVectorType(LLVMIntTypeInContext(bld_base->base.gallivm->context, 32), bld_base->base.type.length * 2));
result = LLVMBuildInsertElement(builder,
result = LLVMBuildInsertElement(ctx->ac.builder,
result,
ac_to_integer(&ctx->ac, ptr),
ctx->i32_0, "");
result = LLVMBuildInsertElement(builder,
result = LLVMBuildInsertElement(ctx->ac.builder,
result,
ac_to_integer(&ctx->ac, ptr2),
ctx->i32_1, "");
@ -430,9 +428,6 @@ emit_array_fetch(struct lp_build_tgsi_context *bld_base,
unsigned swizzle)
{
struct si_shader_context *ctx = si_shader_context(bld_base);
LLVMBuilderRef builder = ctx->gallivm.builder;
unsigned i, size = range.Last - range.First + 1;
LLVMTypeRef vec = LLVMVectorType(tgsi2llvmtype(bld_base, type), size);
LLVMValueRef result = LLVMGetUndef(vec);
@ -443,7 +438,7 @@ emit_array_fetch(struct lp_build_tgsi_context *bld_base,
for (i = 0; i < size; ++i) {
tmp_reg.Register.Index = i + range.First;
LLVMValueRef temp = si_llvm_emit_fetch(bld_base, &tmp_reg, type, swizzle);
result = LLVMBuildInsertElement(builder, result, temp,
result = LLVMBuildInsertElement(ctx->ac.builder, result, temp,
LLVMConstInt(ctx->i32, i, 0), "array_vector");
}
return result;
@ -458,8 +453,7 @@ load_value_from_array(struct lp_build_tgsi_context *bld_base,
const struct tgsi_ind_register *reg_indirect)
{
struct si_shader_context *ctx = si_shader_context(bld_base);
struct gallivm_state *gallivm = &ctx->gallivm;
LLVMBuilderRef builder = gallivm->builder;
LLVMBuilderRef builder = ctx->ac.builder;
LLVMValueRef ptr;
ptr = get_pointer_into_array(ctx, file, swizzle, reg_index, reg_indirect);
@ -493,8 +487,7 @@ store_value_to_array(struct lp_build_tgsi_context *bld_base,
const struct tgsi_ind_register *reg_indirect)
{
struct si_shader_context *ctx = si_shader_context(bld_base);
struct gallivm_state *gallivm = &ctx->gallivm;
LLVMBuilderRef builder = gallivm->builder;
LLVMBuilderRef builder = ctx->ac.builder;
LLVMValueRef ptr;
ptr = get_pointer_into_array(ctx, file, chan_index, reg_index, reg_indirect);
@ -562,7 +555,7 @@ LLVMValueRef si_llvm_emit_fetch(struct lp_build_tgsi_context *bld_base,
unsigned swizzle)
{
struct si_shader_context *ctx = si_shader_context(bld_base);
LLVMBuilderRef builder = ctx->gallivm.builder;
LLVMBuilderRef builder = ctx->ac.builder;
LLVMValueRef result = NULL, ptr, ptr2;
if (swizzle == ~0) {
@ -660,7 +653,7 @@ static LLVMValueRef fetch_system_value(struct lp_build_tgsi_context *bld_base,
unsigned swizzle)
{
struct si_shader_context *ctx = si_shader_context(bld_base);
LLVMBuilderRef builder = ctx->gallivm.builder;
LLVMBuilderRef builder = ctx->ac.builder;
LLVMValueRef cval = ctx->system_values[reg->Register.Index];
if (tgsi_type_is_64bit(type)) {
@ -690,7 +683,7 @@ static void emit_declaration(struct lp_build_tgsi_context *bld_base,
const struct tgsi_full_declaration *decl)
{
struct si_shader_context *ctx = si_shader_context(bld_base);
LLVMBuilderRef builder = ctx->gallivm.builder;
LLVMBuilderRef builder = ctx->ac.builder;
unsigned first, last, i;
switch(decl->Declaration.File) {
case TGSI_FILE_ADDRESS:
@ -872,9 +865,8 @@ void si_llvm_emit_store(struct lp_build_tgsi_context *bld_base,
LLVMValueRef dst[4])
{
struct si_shader_context *ctx = si_shader_context(bld_base);
struct gallivm_state *gallivm = &ctx->gallivm;
const struct tgsi_full_dst_register *reg = &inst->Dst[index];
LLVMBuilderRef builder = ctx->gallivm.builder;
LLVMBuilderRef builder = ctx->ac.builder;
LLVMValueRef temp_ptr, temp_ptr2 = NULL;
bool is_vec_store = false;
enum tgsi_opcode_type dtype = tgsi_opcode_infer_dst_type(inst->Instruction.Opcode, index);
@ -890,7 +882,7 @@ void si_llvm_emit_store(struct lp_build_tgsi_context *bld_base,
while (writemask) {
unsigned chan = u_bit_scan(&writemask);
LLVMValueRef index = LLVMConstInt(ctx->i32, chan, 0);
values[chan] = LLVMBuildExtractElement(gallivm->builder,
values[chan] = LLVMBuildExtractElement(ctx->ac.builder,
dst[0], index, "");
}
bld_base->emit_store(bld_base, inst, info, index, values);
@ -1006,13 +998,12 @@ static void bgnloop_emit(const struct lp_build_tgsi_action *action,
struct lp_build_emit_data *emit_data)
{
struct si_shader_context *ctx = si_shader_context(bld_base);
struct gallivm_state *gallivm = &ctx->gallivm;
struct si_llvm_flow *flow = push_flow(ctx);
flow->loop_entry_block = append_basic_block(ctx, "LOOP");
flow->next_block = append_basic_block(ctx, "ENDLOOP");
set_basicblock_name(flow->loop_entry_block, "loop", bld_base->pc);
LLVMBuildBr(gallivm->builder, flow->loop_entry_block);
LLVMPositionBuilderAtEnd(gallivm->builder, flow->loop_entry_block);
LLVMBuildBr(ctx->ac.builder, flow->loop_entry_block);
LLVMPositionBuilderAtEnd(ctx->ac.builder, flow->loop_entry_block);
}
static void brk_emit(const struct lp_build_tgsi_action *action,
@ -1020,10 +1011,9 @@ static void brk_emit(const struct lp_build_tgsi_action *action,
struct lp_build_emit_data *emit_data)
{
struct si_shader_context *ctx = si_shader_context(bld_base);
struct gallivm_state *gallivm = &ctx->gallivm;
struct si_llvm_flow *flow = get_innermost_loop(ctx);
LLVMBuildBr(gallivm->builder, flow->next_block);
LLVMBuildBr(ctx->ac.builder, flow->next_block);
}
static void cont_emit(const struct lp_build_tgsi_action *action,
@ -1031,10 +1021,9 @@ static void cont_emit(const struct lp_build_tgsi_action *action,
struct lp_build_emit_data *emit_data)
{
struct si_shader_context *ctx = si_shader_context(bld_base);
struct gallivm_state *gallivm = &ctx->gallivm;
struct si_llvm_flow *flow = get_innermost_loop(ctx);
LLVMBuildBr(gallivm->builder, flow->loop_entry_block);
LLVMBuildBr(ctx->ac.builder, flow->loop_entry_block);
}
static void else_emit(const struct lp_build_tgsi_action *action,
@ -1042,16 +1031,15 @@ static void else_emit(const struct lp_build_tgsi_action *action,
struct lp_build_emit_data *emit_data)
{
struct si_shader_context *ctx = si_shader_context(bld_base);
struct gallivm_state *gallivm = &ctx->gallivm;
struct si_llvm_flow *current_branch = get_current_flow(ctx);
LLVMBasicBlockRef endif_block;
assert(!current_branch->loop_entry_block);
endif_block = append_basic_block(ctx, "ENDIF");
emit_default_branch(gallivm->builder, endif_block);
emit_default_branch(ctx->ac.builder, endif_block);
LLVMPositionBuilderAtEnd(gallivm->builder, current_branch->next_block);
LLVMPositionBuilderAtEnd(ctx->ac.builder, current_branch->next_block);
set_basicblock_name(current_branch->next_block, "else", bld_base->pc);
current_branch->next_block = endif_block;
@ -1062,13 +1050,12 @@ static void endif_emit(const struct lp_build_tgsi_action *action,
struct lp_build_emit_data *emit_data)
{
struct si_shader_context *ctx = si_shader_context(bld_base);
struct gallivm_state *gallivm = &ctx->gallivm;
struct si_llvm_flow *current_branch = get_current_flow(ctx);
assert(!current_branch->loop_entry_block);
emit_default_branch(gallivm->builder, current_branch->next_block);
LLVMPositionBuilderAtEnd(gallivm->builder, current_branch->next_block);
emit_default_branch(ctx->ac.builder, current_branch->next_block);
LLVMPositionBuilderAtEnd(ctx->ac.builder, current_branch->next_block);
set_basicblock_name(current_branch->next_block, "endif", bld_base->pc);
ctx->flow_depth--;
@ -1079,14 +1066,13 @@ static void endloop_emit(const struct lp_build_tgsi_action *action,
struct lp_build_emit_data *emit_data)
{
struct si_shader_context *ctx = si_shader_context(bld_base);
struct gallivm_state *gallivm = &ctx->gallivm;
struct si_llvm_flow *current_loop = get_current_flow(ctx);
assert(current_loop->loop_entry_block);
emit_default_branch(gallivm->builder, current_loop->loop_entry_block);
emit_default_branch(ctx->ac.builder, current_loop->loop_entry_block);
LLVMPositionBuilderAtEnd(gallivm->builder, current_loop->next_block);
LLVMPositionBuilderAtEnd(ctx->ac.builder, current_loop->next_block);
set_basicblock_name(current_loop->next_block, "endloop", bld_base->pc);
ctx->flow_depth--;
}
@ -1097,25 +1083,24 @@ static void if_cond_emit(const struct lp_build_tgsi_action *action,
LLVMValueRef cond)
{
struct si_shader_context *ctx = si_shader_context(bld_base);
struct gallivm_state *gallivm = &ctx->gallivm;
struct si_llvm_flow *flow = push_flow(ctx);
LLVMBasicBlockRef if_block;
if_block = append_basic_block(ctx, "IF");
flow->next_block = append_basic_block(ctx, "ELSE");
set_basicblock_name(if_block, "if", bld_base->pc);
LLVMBuildCondBr(gallivm->builder, cond, if_block, flow->next_block);
LLVMPositionBuilderAtEnd(gallivm->builder, if_block);
LLVMBuildCondBr(ctx->ac.builder, cond, if_block, flow->next_block);
LLVMPositionBuilderAtEnd(ctx->ac.builder, if_block);
}
static void if_emit(const struct lp_build_tgsi_action *action,
struct lp_build_tgsi_context *bld_base,
struct lp_build_emit_data *emit_data)
{
struct gallivm_state *gallivm = bld_base->base.gallivm;
struct si_shader_context *ctx = si_shader_context(bld_base);
LLVMValueRef cond;
cond = LLVMBuildFCmp(gallivm->builder, LLVMRealUNE,
cond = LLVMBuildFCmp(ctx->ac.builder, LLVMRealUNE,
emit_data->args[0],
bld_base->base.zero, "");
@ -1127,10 +1112,9 @@ static void uif_emit(const struct lp_build_tgsi_action *action,
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 cond;
cond = LLVMBuildICmp(gallivm->builder, LLVMIntNE,
cond = LLVMBuildICmp(ctx->ac.builder, LLVMIntNE,
ac_to_integer(&ctx->ac, emit_data->args[0]), ctx->i32_0, "");
if_cond_emit(action, bld_base, emit_data, cond);
@ -1334,7 +1318,7 @@ void si_llvm_create_func(struct si_shader_context *ctx,
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);
LLVMPositionBuilderAtEnd(ctx->ac.builder, main_fn_body);
real_shader_type = ctx->type;
@ -1410,7 +1394,7 @@ void si_llvm_optimize_module(struct si_shader_context *ctx)
/* Run the pass */
LLVMRunPassManager(gallivm->passmgr, ctx->gallivm.module);
LLVMDisposeBuilder(gallivm->builder);
LLVMDisposeBuilder(ctx->ac.builder);
LLVMDisposePassManager(gallivm->passmgr);
gallivm_dispose_target_library_info(target_library_info);
}