From 6867b184cac892e3f6aaf3fab3e0453bd784aaf7 Mon Sep 17 00:00:00 2001 From: Mihai Preda Date: Mon, 2 May 2022 15:41:12 +0300 Subject: [PATCH] gallivm: use LLVM opaque pointers in lp_bld_format_aos.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also extract lp_build_const_func_pointer_from_type() in lp_bld_const.h taking explicit function type. Acked-by: Marek Olšák Acked-by: Pierre-Eric Pelloux-Prayer Part-of: --- src/gallium/auxiliary/gallivm/lp_bld_const.c | 25 ++++++----- src/gallium/auxiliary/gallivm/lp_bld_const.h | 6 +++ .../auxiliary/gallivm/lp_bld_format_aos.c | 45 +++++++++---------- 3 files changed, 40 insertions(+), 36 deletions(-) diff --git a/src/gallium/auxiliary/gallivm/lp_bld_const.c b/src/gallium/auxiliary/gallivm/lp_bld_const.c index 4f4bddf44b8..7d9f3176ec1 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_const.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_const.c @@ -455,6 +455,17 @@ lp_build_const_string(struct gallivm_state *gallivm, return string; } +LLVMValueRef +lp_build_const_func_pointer_from_type(struct gallivm_state *gallivm, + const void *ptr, + LLVMTypeRef function_type, + const char *name) +{ + return LLVMBuildBitCast(gallivm->builder, + lp_build_const_int_pointer(gallivm, ptr), + LLVMPointerType(function_type, 0), + name); +} /** * Build a callable function pointer. @@ -470,16 +481,6 @@ lp_build_const_func_pointer(struct gallivm_state *gallivm, unsigned num_args, const char *name) { - LLVMTypeRef function_type; - LLVMValueRef function; - - function_type = LLVMFunctionType(ret_type, arg_types, num_args, 0); - - function = lp_build_const_int_pointer(gallivm, ptr); - - function = LLVMBuildBitCast(gallivm->builder, function, - LLVMPointerType(function_type, 0), - name); - - return function; + LLVMTypeRef function_type = LLVMFunctionType(ret_type, arg_types, num_args, 0); + return lp_build_const_func_pointer_from_type(gallivm, ptr, function_type, name); } diff --git a/src/gallium/auxiliary/gallivm/lp_bld_const.h b/src/gallium/auxiliary/gallivm/lp_bld_const.h index 385b5b02d03..d4098765f5e 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_const.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_const.h @@ -176,4 +176,10 @@ lp_build_const_func_pointer(struct gallivm_state *gallivm, const char *name); +LLVMValueRef +lp_build_const_func_pointer_from_type(struct gallivm_state *gallivm, + const void *ptr, + LLVMTypeRef function_type, + const char *name); + #endif /* !LP_BLD_CONST_H */ diff --git a/src/gallium/auxiliary/gallivm/lp_bld_format_aos.c b/src/gallium/auxiliary/gallivm/lp_bld_format_aos.c index 74fe1672b27..86cca0bb0e8 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_format_aos.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_format_aos.c @@ -820,6 +820,7 @@ lp_build_fetch_rgba_aos(struct gallivm_state *gallivm, * Declare and bind format_desc->fetch_rgba_8unorm(). */ + LLVMTypeRef function_type; { /* * Function to call looks like: @@ -827,7 +828,6 @@ lp_build_fetch_rgba_aos(struct gallivm_state *gallivm, */ LLVMTypeRef ret_type; LLVMTypeRef arg_types[4]; - LLVMTypeRef function_type; ret_type = LLVMVoidTypeInContext(gallivm->context); arg_types[0] = pi8t; @@ -836,19 +836,16 @@ lp_build_fetch_rgba_aos(struct gallivm_state *gallivm, arg_types[3] = i32t; function_type = LLVMFunctionType(ret_type, arg_types, ARRAY_SIZE(arg_types), 0); - - if (gallivm->cache) - gallivm->cache->dont_cache = true; - /* make const pointer for the C fetch_rgba_8unorm function */ - function = lp_build_const_int_pointer(gallivm, - func_to_pointer((func_pointer) unpack->fetch_rgba_8unorm)); - - /* cast the callee pointer to the function's type */ - function = LLVMBuildBitCast(builder, function, - LLVMPointerType(function_type, 0), - "cast callee"); } + if (gallivm->cache) + gallivm->cache->dont_cache = true; + /* make const pointer for the C fetch_rgba_8unorm function */ + function = lp_build_const_int_pointer(gallivm, + func_to_pointer((func_pointer) unpack->fetch_rgba_8unorm)); + /* cast the callee pointer to the function's type */ + function = LLVMBuildBitCast(builder, function, LLVMPointerType(function_type, 0), "cast callee"); + tmp_ptr = lp_build_alloca(gallivm, i32t, ""); res = LLVMGetUndef(LLVMVectorType(i32t, num_pixels)); @@ -875,9 +872,9 @@ lp_build_fetch_rgba_aos(struct gallivm_state *gallivm, args[3] = LLVMBuildExtractElement(builder, j, index, ""); } - LLVMBuildCall(builder, function, args, ARRAY_SIZE(args), ""); + LLVMBuildCall2(builder, function_type, function, args, ARRAY_SIZE(args), ""); - tmp = LLVMBuildLoad(builder, tmp_ptr, ""); + tmp = LLVMBuildLoad2(builder, i32t, tmp_ptr, ""); if (num_pixels == 1) { res = tmp; @@ -929,6 +926,7 @@ lp_build_fetch_rgba_aos(struct gallivm_state *gallivm, * Declare and bind unpack->fetch_rgba_float(). */ + LLVMTypeRef function_type = NULL; { /* * Function to call looks like: @@ -942,15 +940,14 @@ lp_build_fetch_rgba_aos(struct gallivm_state *gallivm, arg_types[1] = pi8t; arg_types[2] = i32t; arg_types[3] = i32t; - - if (gallivm->cache) - gallivm->cache->dont_cache = true; - function = lp_build_const_func_pointer(gallivm, - func_to_pointer((func_pointer) fetch_rgba), - ret_type, - arg_types, ARRAY_SIZE(arg_types), - format_desc->short_name); + function_type = LLVMFunctionType(ret_type, arg_types, ARRAY_SIZE(arg_types), 0); } + if (gallivm->cache) + gallivm->cache->dont_cache = true; + function = lp_build_const_func_pointer_from_type(gallivm, + func_to_pointer((func_pointer) fetch_rgba), + function_type, + format_desc->short_name); tmp_ptr = lp_build_alloca(gallivm, f32x4t, ""); @@ -976,9 +973,9 @@ lp_build_fetch_rgba_aos(struct gallivm_state *gallivm, args[3] = LLVMBuildExtractElement(builder, j, index, ""); } - LLVMBuildCall(builder, function, args, ARRAY_SIZE(args), ""); + LLVMBuildCall2(builder, function_type, function, args, ARRAY_SIZE(args), ""); - tmps[k] = LLVMBuildLoad(builder, tmp_ptr, ""); + tmps[k] = LLVMBuildLoad2(builder, f32x4t, tmp_ptr, ""); } lp_build_conv(gallivm,