From 84ba15ac06285b5851e4363837ba57380c12d07a Mon Sep 17 00:00:00 2001 From: Mihai Preda Date: Mon, 2 May 2022 15:56:33 +0300 Subject: [PATCH] gallivm: use LLVM opaque pointers in lp_bld_intr.c MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Acked-by: Marek Olšák Acked-by: Pierre-Eric Pelloux-Prayer Part-of: --- src/gallium/auxiliary/gallivm/lp_bld_intr.c | 50 +++++++++++++++++------------ src/gallium/auxiliary/gallivm/lp_bld_intr.h | 5 +++ 2 files changed, 34 insertions(+), 21 deletions(-) diff --git a/src/gallium/auxiliary/gallivm/lp_bld_intr.c b/src/gallium/auxiliary/gallivm/lp_bld_intr.c index 2ce723c..99f5c77 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_intr.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_intr.c @@ -103,19 +103,13 @@ lp_format_intrinsic(char *name, LLVMValueRef -lp_declare_intrinsic(LLVMModuleRef module, - const char *name, - LLVMTypeRef ret_type, - LLVMTypeRef *arg_types, - unsigned num_args) +lp_declare_intrinsic_with_type(LLVMModuleRef module, + const char *name, + LLVMTypeRef function_type) { - LLVMTypeRef function_type; - LLVMValueRef function; - assert(!LLVMGetNamedFunction(module, name)); - function_type = LLVMFunctionType(ret_type, arg_types, num_args, 0); - function = LLVMAddFunction(module, name, function_type); + LLVMValueRef function = LLVMAddFunction(module, name, function_type); LLVMSetFunctionCallConv(function, LLVMCCallConv); LLVMSetLinkage(function, LLVMExternalLinkage); @@ -126,6 +120,18 @@ lp_declare_intrinsic(LLVMModuleRef module, } +LLVMValueRef +lp_declare_intrinsic(LLVMModuleRef module, + const char *name, + LLVMTypeRef ret_type, + LLVMTypeRef *arg_types, + unsigned num_args) +{ + LLVMTypeRef function_type = LLVMFunctionType(ret_type, arg_types, num_args, 0); + return lp_declare_intrinsic_with_type(module, name, function_type); +} + + #if LLVM_VERSION_MAJOR < 4 static LLVMAttribute lp_attr_to_llvm_attr(enum lp_func_attr attr) { @@ -232,19 +238,21 @@ lp_build_intrinsic(LLVMBuilderRef builder, bool set_callsite_attrs = LLVM_VERSION_MAJOR >= 4 && !(attr_mask & LP_FUNC_ATTR_LEGACY); - function = LLVMGetNamedFunction(module, name); - if(!function) { - LLVMTypeRef arg_types[LP_MAX_FUNC_ARGS]; - unsigned i; + LLVMTypeRef arg_types[LP_MAX_FUNC_ARGS]; + + assert(num_args <= LP_MAX_FUNC_ARGS); - assert(num_args <= LP_MAX_FUNC_ARGS); + for(unsigned i = 0; i < num_args; ++i) { + assert(args[i]); + arg_types[i] = LLVMTypeOf(args[i]); + } - for(i = 0; i < num_args; ++i) { - assert(args[i]); - arg_types[i] = LLVMTypeOf(args[i]); - } + LLVMTypeRef function_type = LLVMFunctionType(ret_type, arg_types, num_args, 0); - function = lp_declare_intrinsic(module, name, ret_type, arg_types, num_args); + function = LLVMGetNamedFunction(module, name); + + if(!function) { + function = lp_declare_intrinsic_with_type(module, name, function_type); /* * If llvm removes an intrinsic we use, we'll hit this abort (rather @@ -265,7 +273,7 @@ lp_build_intrinsic(LLVMBuilderRef builder, } } - call = LLVMBuildCall(builder, function, args, num_args, ""); + call = LLVMBuildCall2(builder, function_type, function, args, num_args, ""); if (set_callsite_attrs) lp_add_func_attributes(call, attr_mask); return call; diff --git a/src/gallium/auxiliary/gallivm/lp_bld_intr.h b/src/gallium/auxiliary/gallivm/lp_bld_intr.h index ed90979..98dfb0d 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_intr.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_intr.h @@ -78,6 +78,11 @@ lp_declare_intrinsic(LLVMModuleRef module, LLVMTypeRef *arg_types, unsigned num_args); +LLVMValueRef +lp_declare_intrinsic_with_type(LLVMModuleRef module, + const char *name, + LLVMTypeRef function_type); + void lp_add_function_attr(LLVMValueRef function_or_call, int attr_idx, enum lp_func_attr attr); -- 2.7.4