From: Marek Olšák Date: Thu, 16 Aug 2018 00:43:12 +0000 (-0400) Subject: radeonsi: use ac_build_imad X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c401ead68a73a842eafe242899d010cfbcff1243;p=mesa.git radeonsi: use ac_build_imad Reviewed-by: Samuel Pitoiset --- diff --git a/src/gallium/drivers/radeonsi/si_shader.c b/src/gallium/drivers/radeonsi/si_shader.c index 29523474735..24ee45f578a 100644 --- a/src/gallium/drivers/radeonsi/si_shader.c +++ b/src/gallium/drivers/radeonsi/si_shader.c @@ -378,10 +378,7 @@ get_tcs_out_current_patch_offset(struct si_shader_context *ctx) LLVMValueRef patch_stride = get_tcs_out_patch_stride(ctx); LLVMValueRef rel_patch_id = get_rel_patch_id(ctx); - return LLVMBuildAdd(ctx->ac.builder, patch0_offset, - LLVMBuildMul(ctx->ac.builder, patch_stride, - rel_patch_id, ""), - ""); + return ac_build_imad(&ctx->ac, patch_stride, rel_patch_id, patch0_offset); } static LLVMValueRef @@ -392,10 +389,7 @@ get_tcs_out_current_patch_data_offset(struct si_shader_context *ctx) LLVMValueRef patch_stride = get_tcs_out_patch_stride(ctx); LLVMValueRef rel_patch_id = get_rel_patch_id(ctx); - return LLVMBuildAdd(ctx->ac.builder, patch0_patch_data_offset, - LLVMBuildMul(ctx->ac.builder, patch_stride, - rel_patch_id, ""), - ""); + return ac_build_imad(&ctx->ac, patch_stride, rel_patch_id, patch0_patch_data_offset); } static LLVMValueRef get_num_tcs_out_vertices(struct si_shader_context *ctx) @@ -815,12 +809,8 @@ LLVMValueRef si_get_indirect_index(struct si_shader_context *ctx, result = ac_to_integer(&ctx->ac, result); } - if (addr_mul != 1) - result = LLVMBuildMul(ctx->ac.builder, result, - LLVMConstInt(ctx->i32, addr_mul, 0), ""); - result = LLVMBuildAdd(ctx->ac.builder, result, - LLVMConstInt(ctx->i32, rel_index, 0), ""); - return result; + return ac_build_imad(&ctx->ac, result, LLVMConstInt(ctx->i32, addr_mul, 0), + LLVMConstInt(ctx->i32, rel_index, 0)); } /** @@ -847,15 +837,13 @@ static LLVMValueRef get_dw_address_from_generic_indices(struct si_shader_context bool is_patch) { if (vertex_dw_stride) { - base_addr = LLVMBuildAdd(ctx->ac.builder, base_addr, - LLVMBuildMul(ctx->ac.builder, vertex_index, - vertex_dw_stride, ""), ""); + base_addr = ac_build_imad(&ctx->ac, vertex_index, + vertex_dw_stride, base_addr); } if (param_index) { - base_addr = LLVMBuildAdd(ctx->ac.builder, base_addr, - LLVMBuildMul(ctx->ac.builder, param_index, - LLVMConstInt(ctx->i32, 4, 0), ""), ""); + base_addr = ac_build_imad(&ctx->ac, param_index, + LLVMConstInt(ctx->i32, 4, 0), base_addr); } int param = is_patch ? @@ -975,22 +963,15 @@ static LLVMValueRef get_tcs_tes_buffer_address(struct si_shader_context *ctx, constant16 = LLVMConstInt(ctx->i32, 16, 0); if (vertex_index) { - base_addr = LLVMBuildMul(ctx->ac.builder, rel_patch_id, - vertices_per_patch, ""); - - base_addr = LLVMBuildAdd(ctx->ac.builder, base_addr, - vertex_index, ""); - + base_addr = ac_build_imad(&ctx->ac, rel_patch_id, + vertices_per_patch, vertex_index); param_stride = total_vertices; } else { base_addr = rel_patch_id; param_stride = num_patches; } - base_addr = LLVMBuildAdd(ctx->ac.builder, base_addr, - LLVMBuildMul(ctx->ac.builder, param_index, - param_stride, ""), ""); - + base_addr = ac_build_imad(&ctx->ac, param_index, param_stride, base_addr); base_addr = LLVMBuildMul(ctx->ac.builder, base_addr, constant16, ""); if (!vertex_index) { @@ -2823,9 +2804,9 @@ static void si_llvm_emit_streamout(struct si_shader_context *ctx, ctx->param_streamout_offset[i]); so_offset = LLVMBuildMul(builder, so_offset, LLVMConstInt(ctx->i32, 4, 0), ""); - so_write_offset[i] = LLVMBuildMul(builder, so_write_index, - LLVMConstInt(ctx->i32, so->stride[i]*4, 0), ""); - so_write_offset[i] = LLVMBuildAdd(builder, so_write_offset[i], so_offset, ""); + so_write_offset[i] = ac_build_imad(&ctx->ac, so_write_index, + LLVMConstInt(ctx->i32, so->stride[i]*4, 0), + so_offset); } /* Write streamout data. */ @@ -3058,7 +3039,7 @@ static void si_copy_tcs_inputs(struct lp_build_tgsi_context *bld_base) { struct si_shader_context *ctx = si_shader_context(bld_base); LLVMValueRef invocation_id, buffer, buffer_offset; - LLVMValueRef lds_vertex_stride, lds_vertex_offset, lds_base; + LLVMValueRef lds_vertex_stride, lds_base; uint64_t inputs; invocation_id = unpack_llvm_param(ctx, ctx->abi.tcs_rel_ids, 8, 5); @@ -3066,10 +3047,9 @@ static void si_copy_tcs_inputs(struct lp_build_tgsi_context *bld_base) buffer_offset = LLVMGetParam(ctx->main_fn, ctx->param_tcs_offchip_offset); lds_vertex_stride = get_tcs_in_vertex_dw_stride(ctx); - lds_vertex_offset = LLVMBuildMul(ctx->ac.builder, invocation_id, - lds_vertex_stride, ""); lds_base = get_tcs_in_current_patch_offset(ctx); - lds_base = LLVMBuildAdd(ctx->ac.builder, lds_base, lds_vertex_offset, ""); + lds_base = ac_build_imad(&ctx->ac, invocation_id, lds_vertex_stride, + lds_base); inputs = ctx->shader->key.mono.u.ff_tcs_inputs_to_copy; while (inputs) { diff --git a/src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c b/src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c index 72faf755ade..54a0413e464 100644 --- a/src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c +++ b/src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c @@ -182,10 +182,8 @@ LLVMValueRef si_load_image_desc(struct si_shader_context *ctx, LLVMValueRef rsrc; if (desc_type == AC_DESC_BUFFER) { - index = LLVMBuildMul(builder, index, - LLVMConstInt(ctx->i32, 2, 0), ""); - index = LLVMBuildAdd(builder, index, - ctx->i32_1, ""); + index = ac_build_imad(&ctx->ac, index, LLVMConstInt(ctx->i32, 2, 0), + ctx->i32_1); list = LLVMBuildPointerCast(builder, list, ac_array_in_const32_addr_space(ctx->v4i32), ""); } else { @@ -988,20 +986,20 @@ LLVMValueRef si_load_sampler_desc(struct si_shader_context *ctx, break; case AC_DESC_BUFFER: /* The buffer is in [4:7]. */ - index = LLVMBuildMul(builder, index, LLVMConstInt(ctx->i32, 4, 0), ""); - index = LLVMBuildAdd(builder, index, ctx->i32_1, ""); + index = ac_build_imad(&ctx->ac, index, LLVMConstInt(ctx->i32, 4, 0), + ctx->i32_1); list = LLVMBuildPointerCast(builder, list, ac_array_in_const32_addr_space(ctx->v4i32), ""); break; case AC_DESC_FMASK: /* The FMASK is at [8:15]. */ - index = LLVMBuildMul(builder, index, LLVMConstInt(ctx->i32, 2, 0), ""); - index = LLVMBuildAdd(builder, index, ctx->i32_1, ""); + index = ac_build_imad(&ctx->ac, index, LLVMConstInt(ctx->i32, 2, 0), + ctx->i32_1); break; case AC_DESC_SAMPLER: /* The sampler state is at [12:15]. */ - index = LLVMBuildMul(builder, index, LLVMConstInt(ctx->i32, 4, 0), ""); - index = LLVMBuildAdd(builder, index, LLVMConstInt(ctx->i32, 3, 0), ""); + index = ac_build_imad(&ctx->ac, index, LLVMConstInt(ctx->i32, 4, 0), + LLVMConstInt(ctx->i32, 3, 0)); list = LLVMBuildPointerCast(builder, list, ac_array_in_const32_addr_space(ctx->v4i32), ""); break; diff --git a/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c b/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c index 975696d07ad..1f37b0ba37d 100644 --- a/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c +++ b/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c @@ -252,7 +252,6 @@ get_pointer_into_array(struct si_shader_context *ctx, { unsigned array_id; struct tgsi_array_info *array; - LLVMBuilderRef builder = ctx->ac.builder; LLVMValueRef idxs[2]; LLVMValueRef index; LLVMValueRef alloca; @@ -290,15 +289,10 @@ get_pointer_into_array(struct si_shader_context *ctx, */ index = si_llvm_bound_index(ctx, index, array->range.Last - array->range.First + 1); - index = LLVMBuildMul( - builder, index, - LLVMConstInt(ctx->i32, util_bitcount(array->writemask), 0), - ""); - index = LLVMBuildAdd( - builder, index, - LLVMConstInt(ctx->i32, - util_bitcount(array->writemask & ((1 << swizzle) - 1)), 0), - ""); + index = ac_build_imad(&ctx->ac, index, + LLVMConstInt(ctx->i32, util_bitcount(array->writemask), 0), + LLVMConstInt(ctx->i32, + util_bitcount(array->writemask & ((1 << swizzle) - 1)), 0)); idxs[0] = ctx->i32_0; idxs[1] = index; return LLVMBuildGEP(ctx->ac.builder, alloca, idxs, 2, "");