gallivm: use LLVM opaque pointers in lp_bld_format_aos.c

Also extract lp_build_const_func_pointer_from_type() in lp_bld_const.h
taking explicit function type.

Acked-by: Marek Olšák <marek.olsak@amd.com>
Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15893>
This commit is contained in:
Mihai Preda 2022-05-02 15:41:12 +03:00 committed by Mihai Preda
parent 70e9db951d
commit 6867b184ca
3 changed files with 40 additions and 36 deletions

View file

@ -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);
}

View file

@ -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 */

View file

@ -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,