gallivm: use LLVM opaque pointers in lp_bld_intr.c
authorMihai Preda <mhpreda@gmail.com>
Mon, 2 May 2022 12:56:33 +0000 (15:56 +0300)
committerMihai Preda <42345-preda@users.noreply.gitlab.freedesktop.org>
Wed, 4 May 2022 20:00:33 +0000 (20:00 +0000)
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>

src/gallium/auxiliary/gallivm/lp_bld_intr.c
src/gallium/auxiliary/gallivm/lp_bld_intr.h

index 2ce723c..99f5c77 100644 (file)
@@ -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;
index ed90979..98dfb0d 100644 (file)
@@ -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);