From: Marek Olšák <[email protected]>

---
 src/gallium/drivers/radeonsi/si_shader.c           |  7 ++-
 src/gallium/drivers/radeonsi/si_shader_tgsi_alu.c  | 19 +++-----
 src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c  |  2 +-
 .../drivers/radeonsi/si_shader_tgsi_setup.c        | 52 ++++++++++------------
 4 files changed, 34 insertions(+), 46 deletions(-)

diff --git a/src/gallium/drivers/radeonsi/si_shader.c 
b/src/gallium/drivers/radeonsi/si_shader.c
index 74c11d3..d80d10c 100644
--- a/src/gallium/drivers/radeonsi/si_shader.c
+++ b/src/gallium/drivers/radeonsi/si_shader.c
@@ -453,21 +453,21 @@ static LLVMValueRef get_instance_index_for_fetch(
                            LLVMGetParam(ctx->main_fn, param_start_instance), 
"");
 }
 
 /* Bitcast <4 x float> to <2 x double>, extract the component, and convert
  * to float. */
 static LLVMValueRef extract_double_to_float(struct si_shader_context *ctx,
                                            LLVMValueRef vec4,
                                            unsigned double_index)
 {
        LLVMBuilderRef builder = ctx->ac.builder;
-       LLVMTypeRef f64 = LLVMDoubleTypeInContext(ctx->gallivm.context);
+       LLVMTypeRef f64 = LLVMDoubleTypeInContext(ctx->ac.context);
        LLVMValueRef dvec2 = LLVMBuildBitCast(builder, vec4,
                                              LLVMVectorType(f64, 2), "");
        LLVMValueRef index = LLVMConstInt(ctx->i32, double_index, 0);
        LLVMValueRef value = LLVMBuildExtractElement(builder, dvec2, index, "");
        return LLVMBuildFPTrunc(builder, value, ctx->f32, "");
 }
 
 void si_llvm_load_input_vs(
        struct si_shader_context *ctx,
        unsigned input_index,
@@ -5253,21 +5253,20 @@ static void si_llvm_build_ret(struct si_shader_context 
*ctx, LLVMValueRef ret)
 
 /* Generate code for the hardware VS shader stage to go with a geometry shader 
*/
 struct si_shader *
 si_generate_gs_copy_shader(struct si_screen *sscreen,
                           LLVMTargetMachineRef tm,
                           struct si_shader_selector *gs_selector,
                           struct pipe_debug_callback *debug)
 {
        struct si_shader_context ctx;
        struct si_shader *shader;
-       struct gallivm_state *gallivm = &ctx.gallivm;
        LLVMBuilderRef builder;
        struct lp_build_tgsi_context *bld_base = &ctx.bld_base;
        struct lp_build_context *uint = &bld_base->uint_bld;
        struct si_shader_output_values *outputs;
        struct tgsi_shader_info *gsinfo = &gs_selector->info;
        int i, r;
 
        outputs = MALLOC(gsinfo->num_outputs * sizeof(outputs[0]));
 
        if (!outputs)
@@ -5310,34 +5309,34 @@ si_generate_gs_copy_shader(struct si_screen *sscreen,
 
                for (int chan = 0; chan < 4; chan++) {
                        outputs[i].vertex_stream[chan] =
                                (gsinfo->output_streams[i] >> (2 * chan)) & 3;
                }
        }
 
        LLVMBasicBlockRef end_bb;
        LLVMValueRef switch_inst;
 
-       end_bb = LLVMAppendBasicBlockInContext(gallivm->context, ctx.main_fn, 
"end");
+       end_bb = LLVMAppendBasicBlockInContext(ctx.ac.context, ctx.main_fn, 
"end");
        switch_inst = LLVMBuildSwitch(builder, stream_id, end_bb, 4);
 
        for (int stream = 0; stream < 4; stream++) {
                LLVMBasicBlockRef bb;
                unsigned offset;
 
                if (!gsinfo->num_stream_output_components[stream])
                        continue;
 
                if (stream > 0 && !gs_selector->so.num_outputs)
                        continue;
 
-               bb = LLVMInsertBasicBlockInContext(gallivm->context, end_bb, 
"out");
+               bb = LLVMInsertBasicBlockInContext(ctx.ac.context, end_bb, 
"out");
                LLVMAddCase(switch_inst, LLVMConstInt(ctx.i32, stream, 0), bb);
                LLVMPositionBuilderAtEnd(builder, bb);
 
                /* Fetch vertex data from GSVS ring */
                offset = 0;
                for (i = 0; i < gsinfo->num_outputs; ++i) {
                        for (unsigned chan = 0; chan < 4; chan++) {
                                if (!(gsinfo->output_usagemask[i] & (1 << 
chan)) ||
                                    outputs[i].vertex_stream[chan] != stream) {
                                        outputs[i].values[chan] = 
ctx.bld_base.base.undef;
diff --git a/src/gallium/drivers/radeonsi/si_shader_tgsi_alu.c 
b/src/gallium/drivers/radeonsi/si_shader_tgsi_alu.c
index 443f0c9..242f056 100644
--- a/src/gallium/drivers/radeonsi/si_shader_tgsi_alu.c
+++ b/src/gallium/drivers/radeonsi/si_shader_tgsi_alu.c
@@ -42,21 +42,21 @@ static void kill_if_fetch_args(struct lp_build_tgsi_context 
*bld_base,
                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 = LLVMVoidTypeInContext(gallivm->context);
+       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),
                                        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)
 {
@@ -88,21 +88,20 @@ static void kil_emit(const struct lp_build_tgsi_action 
*action,
        else
                ac_build_kill(&ctx->ac, NULL);
 }
 
 static void emit_icmp(const struct lp_build_tgsi_action *action,
                      struct lp_build_tgsi_context *bld_base,
                      struct lp_build_emit_data *emit_data)
 {
        unsigned pred;
        struct si_shader_context *ctx = si_shader_context(bld_base);
-       LLVMContextRef context = bld_base->base.gallivm->context;
 
        switch (emit_data->inst->Instruction.Opcode) {
        case TGSI_OPCODE_USEQ:
        case TGSI_OPCODE_U64SEQ: pred = LLVMIntEQ; break;
        case TGSI_OPCODE_USNE:
        case TGSI_OPCODE_U64SNE: pred = LLVMIntNE; break;
        case TGSI_OPCODE_USGE:
        case TGSI_OPCODE_U64SGE: pred = LLVMIntUGE; break;
        case TGSI_OPCODE_USLT:
        case TGSI_OPCODE_U64SLT: pred = LLVMIntULT; break;
@@ -112,22 +111,21 @@ static void emit_icmp(const struct lp_build_tgsi_action 
*action,
        case TGSI_OPCODE_I64SLT: pred = LLVMIntSLT; break;
        default:
                assert(!"unknown instruction");
                pred = 0;
                break;
        }
 
        LLVMValueRef v = LLVMBuildICmp(ctx->ac.builder, pred,
                        emit_data->args[0], emit_data->args[1],"");
 
-       v = LLVMBuildSExtOrBitCast(ctx->ac.builder, v,
-                       LLVMInt32TypeInContext(context), "");
+       v = LLVMBuildSExtOrBitCast(ctx->ac.builder, v, ctx->i32, "");
 
        emit_data->output[emit_data->chan] = v;
 }
 
 static void emit_ucmp(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 arg0 = ac_to_integer(&ctx->ac, emit_data->args[0]);
@@ -179,67 +177,63 @@ static void emit_set_cond(const struct 
lp_build_tgsi_action *action,
 
        emit_data->output[emit_data->chan] = LLVMBuildSelect(ctx->ac.builder,
                cond, bld_base->base.one, bld_base->base.zero, "");
 }
 
 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)
 {
        struct si_shader_context *ctx = si_shader_context(bld_base);
-       LLVMContextRef context = bld_base->base.gallivm->context;
        LLVMRealPredicate pred;
 
        /* Use ordered for everything but NE (which is usual for
         * float comparisons)
         */
        switch (emit_data->inst->Instruction.Opcode) {
        case TGSI_OPCODE_FSEQ: pred = LLVMRealOEQ; break;
        case TGSI_OPCODE_FSGE: pred = LLVMRealOGE; break;
        case TGSI_OPCODE_FSLT: pred = LLVMRealOLT; break;
        case TGSI_OPCODE_FSNE: pred = LLVMRealUNE; break;
        default: assert(!"unknown instruction"); pred = 0; break;
        }
 
        LLVMValueRef v = LLVMBuildFCmp(ctx->ac.builder, pred,
                        emit_data->args[0], emit_data->args[1],"");
 
-       v = LLVMBuildSExtOrBitCast(ctx->ac.builder, v,
-                       LLVMInt32TypeInContext(context), "");
+       v = LLVMBuildSExtOrBitCast(ctx->ac.builder, v, ctx->i32, "");
 
        emit_data->output[emit_data->chan] = v;
 }
 
 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)
 {
        struct si_shader_context *ctx = si_shader_context(bld_base);
-       LLVMContextRef context = bld_base->base.gallivm->context;
        LLVMRealPredicate pred;
 
        /* Use ordered for everything but NE (which is usual for
         * float comparisons)
         */
        switch (emit_data->inst->Instruction.Opcode) {
        case TGSI_OPCODE_DSEQ: pred = LLVMRealOEQ; break;
        case TGSI_OPCODE_DSGE: pred = LLVMRealOGE; break;
        case TGSI_OPCODE_DSLT: pred = LLVMRealOLT; break;
        case TGSI_OPCODE_DSNE: pred = LLVMRealUNE; break;
        default: assert(!"unknown instruction"); pred = 0; break;
        }
 
        LLVMValueRef v = LLVMBuildFCmp(ctx->ac.builder, pred,
                        emit_data->args[0], emit_data->args[1],"");
 
-       v = LLVMBuildSExtOrBitCast(ctx->ac.builder, v,
-                       LLVMInt32TypeInContext(context), "");
+       v = LLVMBuildSExtOrBitCast(ctx->ac.builder, v, ctx->i32, "");
 
        emit_data->output[emit_data->chan] = v;
 }
 
 static void emit_not(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 v = ac_to_integer(&ctx->ac, emit_data->args[0]);
@@ -551,21 +545,21 @@ static void emit_lsb(const struct lp_build_tgsi_action 
*action,
        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.
                 */
-               LLVMConstInt(LLVMInt1TypeInContext(gallivm->context), 1, 0)
+               LLVMConstInt(ctx->i1, 1, 0)
        };
 
        LLVMValueRef lsb =
                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] =
@@ -674,27 +668,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);
-       LLVMContextRef context = bld_base->base.gallivm->context;
        struct lp_build_context *uint_bld = &bld_base->uint_bld;
        LLVMTypeRef i16;
        LLVMValueRef const16, input, val;
        unsigned i;
 
-       i16 = LLVMInt16TypeInContext(context);
+       i16 = LLVMInt16TypeInContext(ctx->ac.context);
        const16 = lp_build_const_int32(uint_bld->gallivm, 16);
        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_mem.c 
b/src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c
index 32c44ba..d7ba5c4 100644
--- a/src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c
+++ b/src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c
@@ -621,21 +621,21 @@ static void store_fetch_args(
 {
        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;
        struct tgsi_full_src_register memory;
        LLVMValueRef chans[4];
        LLVMValueRef data;
        LLVMValueRef rsrc;
        unsigned chan;
 
-       emit_data->dst_type = LLVMVoidTypeInContext(gallivm->context);
+       emit_data->dst_type = ctx->voidt;
 
        for (chan = 0; chan < 4; ++chan) {
                chans[chan] = lp_build_emit_fetch(bld_base, inst, 1, chan);
        }
        data = lp_build_gather_values(gallivm, chans, 4);
 
        emit_data->args[emit_data->arg_count++] = data;
 
        memory = tgsi_full_src_register_from_dst(&inst->Dst[0]);
 
diff --git a/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c 
b/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c
index 2ecb112..6a86681 100644
--- a/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c
+++ b/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c
@@ -158,34 +158,34 @@ unsigned si_llvm_compile(LLVMModuleRef M, struct 
ac_shader_binary *binary,
 
 out:
        if (diag.retval != 0)
                pipe_debug_message(debug, SHADER_INFO, "LLVM compile failed");
        return diag.retval;
 }
 
 LLVMTypeRef tgsi2llvmtype(struct lp_build_tgsi_context *bld_base,
                          enum tgsi_opcode_type type)
 {
-       LLVMContextRef ctx = bld_base->base.gallivm->context;
+       struct si_shader_context *ctx = si_shader_context(bld_base);
 
        switch (type) {
        case TGSI_TYPE_UNSIGNED:
        case TGSI_TYPE_SIGNED:
-               return LLVMInt32TypeInContext(ctx);
+               return ctx->i32;
        case TGSI_TYPE_UNSIGNED64:
        case TGSI_TYPE_SIGNED64:
-               return LLVMInt64TypeInContext(ctx);
+               return ctx->i64;
        case TGSI_TYPE_DOUBLE:
-               return LLVMDoubleTypeInContext(ctx);
+               return LLVMDoubleTypeInContext(ctx->ac.context);
        case TGSI_TYPE_UNTYPED:
        case TGSI_TYPE_FLOAT:
-               return LLVMFloatTypeInContext(ctx);
+               return ctx->f32;
        default: break;
        }
        return 0;
 }
 
 LLVMValueRef bitcast(struct lp_build_tgsi_context *bld_base,
                     enum tgsi_opcode_type type, LLVMValueRef value)
 {
        struct si_shader_context *ctx = si_shader_context(bld_base);
        LLVMTypeRef dst_type = tgsi2llvmtype(bld_base, type);
@@ -265,27 +265,25 @@ push_flow(struct si_shader_context *ctx)
 
 static LLVMValueRef emit_swizzle(struct lp_build_tgsi_context *bld_base,
                                 LLVMValueRef value,
                                 unsigned swizzle_x,
                                 unsigned swizzle_y,
                                 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);
 
-       swizzles[0] = LLVMConstInt(i32t, swizzle_x, 0);
-       swizzles[1] = LLVMConstInt(i32t, swizzle_y, 0);
-       swizzles[2] = LLVMConstInt(i32t, swizzle_z, 0);
-       swizzles[3] = LLVMConstInt(i32t, swizzle_w, 0);
+       swizzles[0] = LLVMConstInt(ctx->i32, swizzle_x, 0);
+       swizzles[1] = LLVMConstInt(ctx->i32, swizzle_y, 0);
+       swizzles[2] = LLVMConstInt(ctx->i32, swizzle_z, 0);
+       swizzles[3] = LLVMConstInt(ctx->i32, swizzle_w, 0);
 
        return LLVMBuildShuffleVector(ctx->ac.builder,
                                      value,
                                      LLVMGetUndef(LLVMTypeOf(value)),
                                      LLVMConstVector(swizzles, 4), "");
 }
 
 /**
  * Return the description of the array covering the given temporary register
  * index.
@@ -401,21 +399,21 @@ get_pointer_into_array(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)
 {
        struct si_shader_context *ctx = si_shader_context(bld_base);
        LLVMValueRef result;
 
-       result = 
LLVMGetUndef(LLVMVectorType(LLVMIntTypeInContext(bld_base->base.gallivm->context,
 32), bld_base->base.type.length * 2));
+       result = LLVMGetUndef(LLVMVectorType(ctx->i32, 
bld_base->base.type.length * 2));
 
        result = LLVMBuildInsertElement(ctx->ac.builder,
                                        result,
                                        ac_to_integer(&ctx->ac, ptr),
                                        ctx->i32_0, "");
        result = LLVMBuildInsertElement(ctx->ac.builder,
                                        result,
                                        ac_to_integer(&ctx->ac, ptr2),
                                        ctx->i32_1, "");
        return bitcast(bld_base, type, result);
@@ -962,32 +960,30 @@ static void set_basicblock_name(LLVMBasicBlockRef bb, 
const char *base, int pc)
         */
        snprintf(buf, sizeof(buf), "%s%d", base, pc - 1);
        LLVMSetValueName(LLVMBasicBlockAsValue(bb), buf);
 }
 
 /* Append a basic block at the level of the parent flow.
  */
 static LLVMBasicBlockRef append_basic_block(struct si_shader_context *ctx,
                                            const char *name)
 {
-       struct gallivm_state *gallivm = &ctx->gallivm;
-
        assert(ctx->flow_depth >= 1);
 
        if (ctx->flow_depth >= 2) {
                struct si_llvm_flow *flow = &ctx->flow[ctx->flow_depth - 2];
 
-               return LLVMInsertBasicBlockInContext(gallivm->context,
+               return LLVMInsertBasicBlockInContext(ctx->ac.context,
                                                     flow->next_block, name);
        }
 
-       return LLVMAppendBasicBlockInContext(gallivm->context, ctx->main_fn, 
name);
+       return LLVMAppendBasicBlockInContext(ctx->ac.context, ctx->main_fn, 
name);
 }
 
 /* Emit a branch to the given default target for the current block if
  * applicable -- that is, if the current block does not already contain a
  * branch from a break or continue.
  */
 static void emit_default_branch(LLVMBuilderRef builder, LLVMBasicBlockRef 
target)
 {
        if (!LLVMGetBasicBlockTerminator(LLVMGetInsertBlock(builder)))
                 LLVMBuildBr(builder, target);
@@ -1188,45 +1184,45 @@ void si_llvm_context_init(struct si_shader_context *ctx,
        lp_build_context_init(&ctx->bld_base.dbl_bld, &ctx->gallivm, type);
        lp_build_context_init(&ctx->bld_base.uint64_bld, &ctx->gallivm, 
lp_uint_type(type));
        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->gallivm.context,
+       ctx->fpmath_md_kind = LLVMGetMDKindIDInContext(ctx->ac.context,
                                                       "fpmath", 6);
        LLVMValueRef arg = lp_build_const_float(&ctx->gallivm, 2.5);
-       ctx->fpmath_md_2p5_ulp = LLVMMDNodeInContext(ctx->gallivm.context,
+       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;
        bld_base->op_actions[TGSI_OPCODE_ENDLOOP].emit = endloop_emit;
 
        si_shader_context_init_alu(&ctx->bld_base);
        si_shader_context_init_mem(ctx);
 
-       ctx->voidt = LLVMVoidTypeInContext(ctx->gallivm.context);
-       ctx->i1 = LLVMInt1TypeInContext(ctx->gallivm.context);
-       ctx->i8 = LLVMInt8TypeInContext(ctx->gallivm.context);
-       ctx->i32 = LLVMInt32TypeInContext(ctx->gallivm.context);
-       ctx->i64 = LLVMInt64TypeInContext(ctx->gallivm.context);
-       ctx->i128 = LLVMIntTypeInContext(ctx->gallivm.context, 128);
-       ctx->f32 = LLVMFloatTypeInContext(ctx->gallivm.context);
+       ctx->voidt = LLVMVoidTypeInContext(ctx->ac.context);
+       ctx->i1 = LLVMInt1TypeInContext(ctx->ac.context);
+       ctx->i8 = LLVMInt8TypeInContext(ctx->ac.context);
+       ctx->i32 = LLVMInt32TypeInContext(ctx->ac.context);
+       ctx->i64 = LLVMInt64TypeInContext(ctx->ac.context);
+       ctx->i128 = LLVMIntTypeInContext(ctx->ac.context, 128);
+       ctx->f32 = LLVMFloatTypeInContext(ctx->ac.context);
        ctx->v2i32 = LLVMVectorType(ctx->i32, 2);
        ctx->v4i32 = LLVMVectorType(ctx->i32, 4);
        ctx->v4f32 = LLVMVectorType(ctx->f32, 4);
        ctx->v8i32 = LLVMVectorType(ctx->i32, 8);
 
        ctx->i32_0 = LLVMConstInt(ctx->i32, 0, 0);
        ctx->i32_1 = LLVMConstInt(ctx->i32, 1, 0);
 }
 
 /* Set the context to a certain TGSI shader. Can be called repeatedly
@@ -1299,31 +1295,31 @@ 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;
        enum si_llvm_calling_convention call_conv;
        unsigned real_shader_type;
 
        if (num_return_elems)
-               ret_type = LLVMStructTypeInContext(ctx->gallivm.context,
+               ret_type = LLVMStructTypeInContext(ctx->ac.context,
                                                   return_types,
                                                   num_return_elems, true);
        else
-               ret_type = LLVMVoidTypeInContext(ctx->gallivm.context);
+               ret_type = ctx->voidt;
 
        /* 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,
+       main_fn_body = LLVMAppendBasicBlockInContext(ctx->ac.context,
                        ctx->main_fn, "main_body");
        LLVMPositionBuilderAtEnd(ctx->ac.builder, main_fn_body);
 
        real_shader_type = ctx->type;
 
        /* LS is merged into HS (TCS), and ES is merged into GS. */
        if (ctx->screen->b.chip_class >= GFX9) {
                if (ctx->shader->key.as_ls)
                        real_shader_type = PIPE_SHADER_TESS_CTRL;
                else if (ctx->shader->key.as_es)
-- 
2.7.4

_______________________________________________
mesa-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to