r600: add some missing cayman register defines
[mesa.git] / src / gallium / drivers / radeonsi / si_shader_tgsi_mem.c
index 0863876ed89687de443bad883e67bbe573a175c9..35ada5f93c83c850856ff477ad5074c19ec9a57a 100644 (file)
@@ -46,13 +46,12 @@ 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), "");
 
-       if (ctx->screen->b.chip_class == VI) {
+       if (ctx->screen->info.chip_class == VI) {
                /* On VI, the descriptor contains the size in bytes,
                 * but TXQ must return the size in elements.
                 * The stride is always non-zero for resources using TXQ.
@@ -82,7 +81,7 @@ shader_buffer_fetch_rsrc(struct si_shader_context *ctx,
                index = LLVMConstInt(ctx->i32, reg->Register.Index, false);
        } else {
                index = si_get_indirect_index(ctx, &reg->Indirect,
-                                             reg->Register.Index);
+                                             1, reg->Register.Index);
        }
 
        if (ubo)
@@ -91,17 +90,6 @@ shader_buffer_fetch_rsrc(struct si_shader_context *ctx,
                return ctx->abi.load_ssbo(&ctx->abi, index, false);
 }
 
-static bool tgsi_is_array_sampler(unsigned target)
-{
-       return target == TGSI_TEXTURE_1D_ARRAY ||
-              target == TGSI_TEXTURE_SHADOW1D_ARRAY ||
-              target == TGSI_TEXTURE_2D_ARRAY ||
-              target == TGSI_TEXTURE_SHADOW2D_ARRAY ||
-              target == TGSI_TEXTURE_CUBE_ARRAY ||
-              target == TGSI_TEXTURE_SHADOWCUBE_ARRAY ||
-              target == TGSI_TEXTURE_2D_ARRAY_MSAA;
-}
-
 static bool tgsi_is_array_image(unsigned target)
 {
        return target == TGSI_TEXTURE_3D ||
@@ -126,17 +114,16 @@ static bool tgsi_is_array_image(unsigned target)
 static LLVMValueRef force_dcc_off(struct si_shader_context *ctx,
                                  LLVMValueRef rsrc)
 {
-       if (ctx->screen->b.chip_class <= CIK) {
+       if (ctx->screen->info.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, "");
        }
 }
 
@@ -144,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) {
@@ -158,7 +145,7 @@ LLVMValueRef si_load_image_desc(struct si_shader_context *ctx,
                assert(desc_type == AC_DESC_IMAGE);
        }
 
-       rsrc = ac_build_indexed_load_const(&ctx->ac, list, index);
+       rsrc = ac_build_load_to_sgpr(&ctx->ac, list, index);
        if (dcc_off)
                rsrc = force_dcc_off(ctx, rsrc);
        return rsrc;
@@ -203,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, "");
        }
@@ -212,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,
@@ -223,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), "");
        }
 
@@ -238,8 +222,7 @@ static LLVMValueRef image_fetch_coords(
                unsigned src, LLVMValueRef desc)
 {
        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];
@@ -248,11 +231,11 @@ static LLVMValueRef image_fetch_coords(
 
        for (chan = 0; chan < num_coords; ++chan) {
                tmp = lp_build_emit_fetch(bld_base, inst, src, chan);
-               tmp = LLVMBuildBitCast(builder, tmp, ctx->i32, "");
+               tmp = ac_to_integer(&ctx->ac, tmp);
                coords[chan] = tmp;
        }
 
-       if (ctx->screen->b.chip_class >= GFX9) {
+       if (ctx->screen->info.chip_class >= GFX9) {
                /* 1D textures are allocated and used as 2D on GFX9. */
                if (target == TGSI_TEXTURE_1D) {
                        coords[1] = ctx->i32_0;
@@ -288,7 +271,7 @@ static LLVMValueRef image_fetch_coords(
                num_coords = 4;
        }
 
-       return lp_build_gather_values(gallivm, coords, num_coords);
+       return lp_build_gather_values(&ctx->gallivm, coords, num_coords);
 }
 
 /**
@@ -367,7 +350,6 @@ static void load_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 target = inst->Memory.Texture;
        LLVMValueRef rsrc;
@@ -376,7 +358,6 @@ static void load_fetch_args(
 
        if (inst->Src[0].Register.File == TGSI_FILE_BUFFER ||
                   inst->Src[0].Register.File == TGSI_FILE_CONSTBUF) {
-               LLVMBuilderRef builder = gallivm->builder;
                LLVMValueRef offset;
                LLVMValueRef tmp;
 
@@ -384,7 +365,7 @@ static void load_fetch_args(
                rsrc = shader_buffer_fetch_rsrc(ctx, &inst->Src[0], ubo);
 
                tmp = lp_build_emit_fetch(bld_base, inst, 1, 0);
-               offset = LLVMBuildBitCast(builder, tmp, ctx->i32, "");
+               offset = ac_to_integer(&ctx->ac, tmp);
 
                buffer_append_args(ctx, emit_data, rsrc, ctx->i32_0,
                                   offset, false, false);
@@ -461,15 +442,14 @@ 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;
 
        offset = lp_build_emit_fetch(&ctx->bld_base, inst, arg, 0);
-       offset = LLVMBuildBitCast(builder, offset, ctx->i32, "");
+       offset = ac_to_integer(&ctx->ac, offset);
 
-       ptr = ctx->shared_memory;
+       ptr = ctx->ac.lds;
        ptr = LLVMBuildGEP(builder, ptr, &offset, 1, "");
        addr_space = LLVMGetPointerAddressSpace(LLVMTypeOf(ptr));
        ptr = LLVMBuildBitCast(builder, ptr, LLVMPointerType(type, addr_space), "");
@@ -482,8 +462,6 @@ static void load_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;
        unsigned writemask = inst->Dst[0].Register.WriteMask;
        LLVMValueRef channels[4], ptr, derived_ptr, index;
        int chan;
@@ -497,10 +475,10 @@ 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);
+       emit_data->output[emit_data->chan] = lp_build_gather_values(&ctx->gallivm, channels, 4);
 }
 
 /**
@@ -572,8 +550,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];
@@ -630,8 +607,6 @@ static void store_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;
-       LLVMBuilderRef builder = gallivm->builder;
        const struct tgsi_full_instruction * inst = emit_data->inst;
        struct tgsi_full_src_register memory;
        LLVMValueRef chans[4];
@@ -639,12 +614,12 @@ static void store_fetch_args(
        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);
+       data = lp_build_gather_values(&ctx->gallivm, chans, 4);
 
        emit_data->args[emit_data->arg_count++] = data;
 
@@ -657,7 +632,7 @@ static void store_fetch_args(
                rsrc = shader_buffer_fetch_rsrc(ctx, &memory, false);
 
                tmp = lp_build_emit_fetch(bld_base, inst, 0, 0);
-               offset = LLVMBuildBitCast(builder, tmp, ctx->i32, "");
+               offset = ac_to_integer(&ctx->ac, tmp);
 
                buffer_append_args(ctx, emit_data, rsrc, ctx->i32_0,
                                   offset, false, false);
@@ -672,7 +647,7 @@ static void store_fetch_args(
                 * The only way to get unaligned stores in radeonsi is through
                 * shader images.
                 */
-               bool force_glc = ctx->screen->b.chip_class == SI;
+               bool force_glc = ctx->screen->info.chip_class == SI;
 
                image_fetch_rsrc(bld_base, &memory, true, target, &rsrc);
                coords = image_fetch_coords(bld_base, inst, 0, rsrc);
@@ -697,8 +672,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;
@@ -769,8 +743,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;
@@ -794,8 +767,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;
@@ -847,8 +819,6 @@ static void atomic_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;
-       LLVMBuilderRef builder = gallivm->builder;
        const struct tgsi_full_instruction * inst = emit_data->inst;
        LLVMValueRef data1, data2;
        LLVMValueRef rsrc;
@@ -857,11 +827,11 @@ static void atomic_fetch_args(
        emit_data->dst_type = ctx->f32;
 
        tmp = lp_build_emit_fetch(bld_base, inst, 2, 0);
-       data1 = LLVMBuildBitCast(builder, tmp, ctx->i32, "");
+       data1 = ac_to_integer(&ctx->ac, tmp);
 
        if (inst->Instruction.Opcode == TGSI_OPCODE_ATOMCAS) {
                tmp = lp_build_emit_fetch(bld_base, inst, 3, 0);
-               data2 = LLVMBuildBitCast(builder, tmp, ctx->i32, "");
+               data2 = ac_to_integer(&ctx->ac, tmp);
        }
 
        /* llvm.amdgcn.image/buffer.atomic.cmpswap reflect the hardware order
@@ -877,7 +847,7 @@ static void atomic_fetch_args(
                rsrc = shader_buffer_fetch_rsrc(ctx, &inst->Src[0], false);
 
                tmp = lp_build_emit_fetch(bld_base, inst, 1, 0);
-               offset = LLVMBuildBitCast(builder, tmp, ctx->i32, "");
+               offset = ac_to_integer(&ctx->ac, tmp);
 
                buffer_append_args(ctx, emit_data, rsrc, ctx->i32_0,
                                   offset, true, false);
@@ -903,22 +873,21 @@ 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;
 
        ptr = get_memory_ptr(ctx, inst, ctx->i32, 1);
 
        arg = lp_build_emit_fetch(&ctx->bld_base, inst, 2, 0);
-       arg = LLVMBuildBitCast(builder, arg, ctx->i32, "");
+       arg = ac_to_integer(&ctx->ac, arg);
 
        if (inst->Instruction.Opcode == TGSI_OPCODE_ATOMCAS) {
                LLVMValueRef new_data;
                new_data = lp_build_emit_fetch(&ctx->bld_base,
                                               inst, 3, 0);
 
-               new_data = LLVMBuildBitCast(builder, new_data, ctx->i32, "");
+               new_data = ac_to_integer(&ctx->ac, new_data);
 
                result = LLVMBuildAtomicCmpXchg(builder, ptr, arg, new_data,
                                       LLVMAtomicOrderingSequentiallyConsistent,
@@ -974,8 +943,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;
@@ -1007,8 +975,7 @@ static void atomic_emit(
        tmp = lp_build_intrinsic(
                builder, intrinsic_name, ctx->i32,
                emit_data->args, emit_data->arg_count, 0);
-       emit_data->output[emit_data->chan] =
-               LLVMBuildBitCast(builder, tmp, ctx->f32, "");
+       emit_data->output[emit_data->chan] = ac_to_float(&ctx->ac, tmp);
 }
 
 static void set_tex_fetch_args(struct si_shader_context *ctx,
@@ -1018,7 +985,6 @@ static void set_tex_fetch_args(struct si_shader_context *ctx,
                               LLVMValueRef *param, unsigned count,
                               unsigned dmask)
 {
-       struct gallivm_state *gallivm = &ctx->gallivm;
        struct ac_image_args args = {};
 
        /* Pad to power of two vector */
@@ -1026,7 +992,7 @@ static void set_tex_fetch_args(struct si_shader_context *ctx,
                param[count++] = LLVMGetUndef(ctx->i32);
 
        if (count > 1)
-               args.addr = lp_build_gather_values(gallivm, param, count);
+               args.addr = lp_build_gather_values(&ctx->gallivm, param, count);
        else
                args.addr = param[0];
 
@@ -1045,10 +1011,10 @@ 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 &&
+        if (ctx->screen->info.chip_class >= GFX9 &&
            (target == TGSI_TEXTURE_1D_ARRAY ||
             target == TGSI_TEXTURE_SHADOW1D_ARRAY)) {
                LLVMValueRef layers =
@@ -1111,8 +1077,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;
 
@@ -1141,8 +1106,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,7 +1134,7 @@ LLVMValueRef si_load_sampler_desc(struct si_shader_context *ctx,
                break;
        }
 
-       return ac_build_indexed_load_const(&ctx->ac, list, index);
+       return ac_build_load_to_sgpr(&ctx->ac, list, index);
 }
 
 /* Disable anisotropic filtering if BASE_LEVEL == LAST_LEVEL.
@@ -1187,18 +1151,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)
+       if (ctx->screen->info.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, "");
 }
 
@@ -1223,7 +1186,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,
@@ -1316,7 +1279,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;
@@ -1344,7 +1306,7 @@ static void tex_fetch_args(
 
        /* Fetch and project texture coordinates */
        coords[3] = lp_build_emit_fetch(bld_base, emit_data->inst, 0, TGSI_CHAN_W);
-       for (chan = 0; chan < 3; chan++ ) {
+       for (chan = 0; chan < 3; chan++) {
                coords[chan] = lp_build_emit_fetch(bld_base,
                                                   emit_data->inst, 0,
                                                   chan);
@@ -1356,7 +1318,7 @@ static void tex_fetch_args(
        }
 
        if (opcode == TGSI_OPCODE_TXP)
-               coords[3] = bld_base->base.one;
+               coords[3] = ctx->ac.f32_1;
 
        /* Pack offsets. */
        if (has_offset &&
@@ -1372,15 +1334,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;
        }
 
@@ -1412,16 +1374,16 @@ static void tex_fetch_args(
                 * so the depth comparison value isn't clamped for Z16 and
                 * Z24 anymore. Do it manually here.
                 */
-               if (ctx->screen->b.chip_class >= VI) {
+               if (ctx->screen->info.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;
@@ -1463,7 +1425,7 @@ static void tex_fetch_args(
                        num_src_deriv_channels = 1;
 
                        /* 1D textures are allocated and used as 2D on GFX9. */
-                       if (ctx->screen->b.chip_class >= GFX9) {
+                       if (ctx->screen->info.chip_class >= GFX9) {
                                num_dst_deriv_channels = 2;
                                num_deriv_channels = 2;
                        } else {
@@ -1484,7 +1446,7 @@ static void tex_fetch_args(
                        for (chan = num_src_deriv_channels;
                             chan < num_dst_deriv_channels; chan++)
                                derivs[param * num_dst_deriv_channels + chan] =
-                                       bld_base->base.zero;
+                                       ctx->ac.f32_0;
                }
        }
 
@@ -1501,7 +1463,7 @@ static void tex_fetch_args(
        } else if (tgsi_is_array_sampler(target) &&
                   opcode != TGSI_OPCODE_TXF &&
                   opcode != TGSI_OPCODE_TXF_LZ &&
-                  ctx->screen->b.chip_class <= VI) {
+                  ctx->screen->info.chip_class <= VI) {
                unsigned array_coord = target == TGSI_TEXTURE_1D_ARRAY ? 1 : 2;
                coords[array_coord] =
                        ac_build_intrinsic(&ctx->ac, "llvm.rint.f32", ctx->f32,
@@ -1520,7 +1482,7 @@ static void tex_fetch_args(
                address[count++] = coords[2];
 
        /* 1D textures are allocated and used as 2D on GFX9. */
-       if (ctx->screen->b.chip_class >= GFX9) {
+       if (ctx->screen->info.chip_class >= GFX9) {
                LLVMValueRef filler;
 
                /* Use 0.5, so that we don't sample the border color. */
@@ -1552,10 +1514,8 @@ static void tex_fetch_args(
                count = 16;
        }
 
-       for (chan = 0; chan < count; chan++ ) {
-               address[chan] = LLVMBuildBitCast(gallivm->builder,
-                                                address[chan], ctx->i32, "");
-       }
+       for (chan = 0; chan < count; chan++)
+               address[chan] = ac_to_integer(&ctx->ac, address[chan]);
 
        /* Adjust the sample index according to FMASK.
         *
@@ -1597,39 +1557,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], "");
        }
 
@@ -1721,7 +1681,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];
@@ -1821,9 +1781,9 @@ si_lower_gather4_integer(struct si_shader_context *ctx,
                LLVMValueRef index = LLVMConstInt(ctx->i32, coord_vgpr_index + c, 0);
 
                tmp = LLVMBuildExtractElement(builder, coord, index, "");
-               tmp = LLVMBuildBitCast(builder, tmp, ctx->f32, "");
+               tmp = ac_to_float(&ctx->ac, tmp);
                tmp = LLVMBuildFAdd(builder, tmp, half_texel[c], "");
-               tmp = LLVMBuildBitCast(builder, tmp, ctx->i32, "");
+               tmp = ac_to_integer(&ctx->ac, tmp);
                coord = LLVMBuildInsertElement(builder, coord, tmp, index, "");
        }
 
@@ -1841,7 +1801,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);
@@ -1857,7 +1817,7 @@ si_fix_gather4_integer_result(struct si_shader_context *ctx,
                        wa_value = LLVMBuildFPToUI(builder, value, ctx->i32, "");
                else
                        wa_value = LLVMBuildFPToSI(builder, value, ctx->i32, "");
-               wa_value = LLVMBuildBitCast(builder, wa_value, ctx->f32, "");
+               wa_value = ac_to_float(&ctx->ac, wa_value);
                value = LLVMBuildSelect(builder, wa, wa_value, value, "");
 
                result = LLVMBuildInsertElement(builder, result, value, chanv, "");
@@ -1940,7 +1900,7 @@ static void build_tex_intrinsic(const struct lp_build_tgsi_action *action,
        /* The hardware needs special lowering for Gather4 with integer formats. */
        LLVMValueRef gather4_int_result_workaround = NULL;
 
-       if (ctx->screen->b.chip_class <= VI &&
+       if (ctx->screen->info.chip_class <= VI &&
            opcode == TGSI_OPCODE_TG4) {
                assert(inst->Texture.ReturnType != TGSI_RETURN_TYPE_UNKNOWN);
 
@@ -1970,8 +1930,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;
 
@@ -1979,15 +1937,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;