Reviewed-by: Marek Olšák <[email protected]> Marek
On Tue, Feb 6, 2018 at 5:58 AM, Timothy Arceri <[email protected]> wrote: > --- > src/amd/common/ac_llvm_build.c | 19 +++++++++++++++++++ > src/amd/common/ac_llvm_build.h | 3 +++ > src/amd/common/ac_nir_to_llvm.c | 34 ++++++++-------------------------- > 3 files changed, 30 insertions(+), 26 deletions(-) > > diff --git a/src/amd/common/ac_llvm_build.c b/src/amd/common/ac_llvm_build.c > index 6375b106f7..08c488775e 100644 > --- a/src/amd/common/ac_llvm_build.c > +++ b/src/amd/common/ac_llvm_build.c > @@ -128,6 +128,25 @@ ac_llvm_extract_elem(struct ac_llvm_context *ac, > LLVMConstInt(ac->i32, index, false), > ""); > } > > +int > +ac_get_elem_bits(struct ac_llvm_context *ctx, LLVMTypeRef type) > +{ > + if (LLVMGetTypeKind(type) == LLVMVectorTypeKind) > + type = LLVMGetElementType(type); > + > + if (LLVMGetTypeKind(type) == LLVMIntegerTypeKind) > + return LLVMGetIntTypeWidth(type); > + > + if (type == ctx->f16) > + return 16; > + if (type == ctx->f32) > + return 32; > + if (type == ctx->f64) > + return 64; > + > + unreachable("Unhandled type kind in get_elem_bits"); > +} > + > unsigned > ac_get_type_size(LLVMTypeRef type) > { > diff --git a/src/amd/common/ac_llvm_build.h b/src/amd/common/ac_llvm_build.h > index 78991b3e99..fa09bd10a5 100644 > --- a/src/amd/common/ac_llvm_build.h > +++ b/src/amd/common/ac_llvm_build.h > @@ -92,6 +92,9 @@ ac_llvm_context_init(struct ac_llvm_context *ctx, > LLVMContextRef context, > int > ac_get_llvm_num_components(LLVMValueRef value); > > +int > +ac_get_elem_bits(struct ac_llvm_context *ctx, LLVMTypeRef type); > + > LLVMValueRef > ac_llvm_extract_elem(struct ac_llvm_context *ac, > LLVMValueRef value, > diff --git a/src/amd/common/ac_nir_to_llvm.c b/src/amd/common/ac_nir_to_llvm.c > index e06a22f8a9..e284795fdc 100644 > --- a/src/amd/common/ac_nir_to_llvm.c > +++ b/src/amd/common/ac_nir_to_llvm.c > @@ -329,24 +329,6 @@ create_llvm_function(LLVMContextRef ctx, LLVMModuleRef > module, > return main_function; > } > > -static int get_elem_bits(struct ac_llvm_context *ctx, LLVMTypeRef type) > -{ > - if (LLVMGetTypeKind(type) == LLVMVectorTypeKind) > - type = LLVMGetElementType(type); > - > - if (LLVMGetTypeKind(type) == LLVMIntegerTypeKind) > - return LLVMGetIntTypeWidth(type); > - > - if (type == ctx->f16) > - return 16; > - if (type == ctx->f32) > - return 32; > - if (type == ctx->f64) > - return 64; > - > - unreachable("Unhandled type kind in get_elem_bits"); > -} > - > static LLVMValueRef unpack_param(struct ac_llvm_context *ctx, > LLVMValueRef param, unsigned rshift, > unsigned bitwidth) > @@ -1267,7 +1249,7 @@ static LLVMValueRef emit_intrin_1f_param(struct > ac_llvm_context *ctx, > }; > > MAYBE_UNUSED const int length = snprintf(name, sizeof(name), > "%s.f%d", intrin, > - get_elem_bits(ctx, > result_type)); > + ac_get_elem_bits(ctx, > result_type)); > assert(length < sizeof(name)); > return ac_build_intrinsic(ctx, name, result_type, params, 1, > AC_FUNC_ATTR_READNONE); > } > @@ -1284,7 +1266,7 @@ static LLVMValueRef emit_intrin_2f_param(struct > ac_llvm_context *ctx, > }; > > MAYBE_UNUSED const int length = snprintf(name, sizeof(name), > "%s.f%d", intrin, > - get_elem_bits(ctx, > result_type)); > + ac_get_elem_bits(ctx, > result_type)); > assert(length < sizeof(name)); > return ac_build_intrinsic(ctx, name, result_type, params, 2, > AC_FUNC_ATTR_READNONE); > } > @@ -1302,7 +1284,7 @@ static LLVMValueRef emit_intrin_3f_param(struct > ac_llvm_context *ctx, > }; > > MAYBE_UNUSED const int length = snprintf(name, sizeof(name), > "%s.f%d", intrin, > - get_elem_bits(ctx, > result_type)); > + ac_get_elem_bits(ctx, > result_type)); > assert(length < sizeof(name)); > return ac_build_intrinsic(ctx, name, result_type, params, 3, > AC_FUNC_ATTR_READNONE); > } > @@ -1922,7 +1904,7 @@ static void visit_alu(struct ac_nir_context *ctx, const > nir_alu_instr *instr) > result = ac_build_intrinsic(&ctx->ac, "llvm.bitreverse.i32", > ctx->ac.i32, src, 1, AC_FUNC_ATTR_READNONE); > break; > case nir_op_bit_count: > - if (get_elem_bits(&ctx->ac, LLVMTypeOf(src[0])) == 32) > + if (ac_get_elem_bits(&ctx->ac, LLVMTypeOf(src[0])) == 32) > result = ac_build_intrinsic(&ctx->ac, > "llvm.ctpop.i32", ctx->ac.i32, src, 1, AC_FUNC_ATTR_READNONE); > else { > result = ac_build_intrinsic(&ctx->ac, > "llvm.ctpop.i64", ctx->ac.i64, src, 1, AC_FUNC_ATTR_READNONE); > @@ -1966,7 +1948,7 @@ static void visit_alu(struct ac_nir_context *ctx, const > nir_alu_instr *instr) > case nir_op_u2u32: > case nir_op_u2u64: > src[0] = ac_to_integer(&ctx->ac, src[0]); > - if (get_elem_bits(&ctx->ac, LLVMTypeOf(src[0])) < > get_elem_bits(&ctx->ac, def_type)) > + if (ac_get_elem_bits(&ctx->ac, LLVMTypeOf(src[0])) < > ac_get_elem_bits(&ctx->ac, def_type)) > result = LLVMBuildZExt(ctx->ac.builder, src[0], > def_type, ""); > else > result = LLVMBuildTrunc(ctx->ac.builder, src[0], > def_type, ""); > @@ -1974,7 +1956,7 @@ static void visit_alu(struct ac_nir_context *ctx, const > nir_alu_instr *instr) > case nir_op_i2i32: > case nir_op_i2i64: > src[0] = ac_to_integer(&ctx->ac, src[0]); > - if (get_elem_bits(&ctx->ac, LLVMTypeOf(src[0])) < > get_elem_bits(&ctx->ac, def_type)) > + if (ac_get_elem_bits(&ctx->ac, LLVMTypeOf(src[0])) < > ac_get_elem_bits(&ctx->ac, def_type)) > result = LLVMBuildSExt(ctx->ac.builder, src[0], > def_type, ""); > else > result = LLVMBuildTrunc(ctx->ac.builder, src[0], > def_type, ""); > @@ -2465,7 +2447,7 @@ static void visit_store_ssbo(struct ac_nir_context *ctx, > const char *store_name; > LLVMValueRef src_data = get_src(ctx, instr->src[0]); > LLVMTypeRef data_type = ctx->ac.f32; > - int elem_size_mult = get_elem_bits(&ctx->ac, LLVMTypeOf(src_data)) / > 32; > + int elem_size_mult = ac_get_elem_bits(&ctx->ac, LLVMTypeOf(src_data)) > / 32; > int components_32bit = elem_size_mult * instr->num_components; > unsigned writemask = nir_intrinsic_write_mask(instr); > LLVMValueRef base_data, base_offset; > @@ -3271,7 +3253,7 @@ visit_store_var(struct ac_nir_context *ctx, > get_deref_offset(ctx, instr->variables[0], false, > NULL, NULL, &const_index, &indir_index); > > - if (get_elem_bits(&ctx->ac, LLVMTypeOf(src)) == 64) { > + if (ac_get_elem_bits(&ctx->ac, LLVMTypeOf(src)) == 64) { > > src = LLVMBuildBitCast(ctx->ac.builder, src, > LLVMVectorType(ctx->ac.f32, > ac_get_llvm_num_components(src) * 2), > -- > 2.14.3 > > _______________________________________________ > mesa-dev mailing list > [email protected] > https://lists.freedesktop.org/mailman/listinfo/mesa-dev _______________________________________________ mesa-dev mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/mesa-dev
