Mesa (master): gallivm: Add a lp_build_const_func_pointer() helper.

Jose Fonseca jrfonseca at kemper.freedesktop.org
Wed May 2 09:25:58 UTC 2012


Module: Mesa
Branch: master
Commit: 6cd76b800bed70435f499c6c498a487a5056a731
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=6cd76b800bed70435f499c6c498a487a5056a731

Author: José Fonseca <jfonseca at vmware.com>
Date:   Thu Feb 23 09:21:26 2012 +0000

gallivm: Add a lp_build_const_func_pointer() helper.

To be reused in all places where we want to call C code.

---

 src/gallium/auxiliary/gallivm/lp_bld_const.c      |   29 +++++++++++++++++++++
 src/gallium/auxiliary/gallivm/lp_bld_const.h      |   10 +++++++
 src/gallium/auxiliary/gallivm/lp_bld_format_aos.c |   20 +++-----------
 3 files changed, 44 insertions(+), 15 deletions(-)

diff --git a/src/gallium/auxiliary/gallivm/lp_bld_const.c b/src/gallium/auxiliary/gallivm/lp_bld_const.c
index 9e9dc44..f0611b1 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_const.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_const.c
@@ -446,3 +446,32 @@ lp_build_const_string(struct gallivm_state *gallivm,
    string = LLVMConstBitCast(string, LLVMPointerType(i8, 0));
    return string;
 }
+
+
+/**
+ * Build a callable function pointer.
+ *
+ * We this casts instead of LLVMAddGlobalMapping()
+ * to work around a bug in LLVM 2.6, and for efficiency/simplicity.
+ */
+LLVMValueRef
+lp_build_const_func_pointer(struct gallivm_state *gallivm,
+                            const void *ptr,
+                            LLVMTypeRef ret_type,
+                            LLVMTypeRef *arg_types,
+                            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;
+}
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_const.h b/src/gallium/auxiliary/gallivm/lp_bld_const.h
index 34c3c69..2205616 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_const.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_const.h
@@ -153,4 +153,14 @@ LLVMValueRef
 lp_build_const_string(struct gallivm_state *gallivm,
                       const char *str);
 
+
+LLVMValueRef
+lp_build_const_func_pointer(struct gallivm_state *gallivm,
+                            const void *ptr,
+                            LLVMTypeRef ret_type,
+                            LLVMTypeRef *arg_types,
+                            unsigned num_args,
+                            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 82ab19e..e4b8da6 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_format_aos.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_format_aos.c
@@ -643,28 +643,18 @@ 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] = pf32t;
          arg_types[1] = pi8t;
          arg_types[2] = i32t;
          arg_types[3] = i32t;
-         function_type = LLVMFunctionType(ret_type, arg_types,
-                                          Elements(arg_types), 0);
 
-         /* Note: we're using this casting here instead of LLVMAddGlobalMapping()
-          * to work around a bug in LLVM 2.6, and for efficiency/simplicity.
-          */
-
-         /* make const pointer for the C fetch_rgba_float function */
-         function = lp_build_const_int_pointer(gallivm,
-            func_to_pointer((func_pointer) format_desc->fetch_rgba_float));
-
-         /* cast the callee pointer to the function's type */
-         function = LLVMBuildBitCast(builder, function,
-                                     LLVMPointerType(function_type, 0),
-                                     "cast callee");
+         function = lp_build_const_func_pointer(gallivm,
+                                                func_to_pointer((func_pointer) format_desc->fetch_rgba_float),
+                                                ret_type,
+                                                arg_types, Elements(arg_types),
+                                                format_desc->short_name);
       }
 
       tmp_ptr = lp_build_alloca(gallivm, f32x4t, "");




More information about the mesa-commit mailing list