aboutsummaryrefslogtreecommitdiffstats
path: root/src/gallium/auxiliary
diff options
context:
space:
mode:
authorJosé Fonseca <[email protected]>2012-02-23 09:48:08 +0000
committerJosé Fonseca <[email protected]>2012-05-02 10:24:34 +0100
commit9ad2cb18857c1cd75ab073e8662700d1761c20ac (patch)
treedee219085429ed7b0281e27a998e9bca42afebfc /src/gallium/auxiliary
parent6cd76b800bed70435f499c6c498a487a5056a731 (diff)
gallivm: Avoid LLVMAddGlobalMapping() in lp_bld_assert().
Brittle, complex, and unecesary. Just use function pointer constant.
Diffstat (limited to 'src/gallium/auxiliary')
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_assert.c40
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_assert.h2
2 files changed, 16 insertions, 26 deletions
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_assert.c b/src/gallium/auxiliary/gallivm/lp_bld_assert.c
index 449d0a7c014..37c142bd2ae 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_assert.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_assert.c
@@ -56,47 +56,37 @@ lp_assert(int condition, const char *msg)
* \param condition should be an 'i1' or 'i32' value
* \param msg a string to print if the assertion fails.
*/
-LLVMValueRef
+void
lp_build_assert(struct gallivm_state *gallivm,
LLVMValueRef condition,
const char *msg)
{
LLVMBuilderRef builder = gallivm->builder;
LLVMContextRef context = gallivm->context;
- LLVMModuleRef module = gallivm->module;
LLVMTypeRef arg_types[2];
- LLVMValueRef msg_string, assert_func, params[2], r;
+ LLVMTypeRef ret_type;
+ LLVMValueRef function;
+ LLVMValueRef args[2];
+ LLVMValueRef msg_string;
msg_string = lp_build_const_string(gallivm, msg);
+ ret_type = LLVMVoidTypeInContext(context);
arg_types[0] = LLVMInt32TypeInContext(context);
arg_types[1] = LLVMPointerType(LLVMInt8TypeInContext(context), 0);
- /* lookup the lp_assert function */
- assert_func = LLVMGetNamedFunction(module, "lp_assert");
-
- /* Create the assertion function if not found */
- if (!assert_func) {
- LLVMTypeRef func_type =
- LLVMFunctionType(LLVMVoidTypeInContext(context), arg_types, 2, 0);
-
- assert_func = LLVMAddFunction(module, "lp_assert", func_type);
- LLVMSetFunctionCallConv(assert_func, LLVMCCallConv);
- LLVMSetLinkage(assert_func, LLVMExternalLinkage);
- LLVMAddGlobalMapping(gallivm->engine, assert_func,
- func_to_pointer((func_pointer)lp_assert));
- }
- assert(assert_func);
+ function = lp_build_const_func_pointer(gallivm,
+ func_to_pointer((func_pointer)lp_assert),
+ ret_type, arg_types, Elements(arg_types),
+ "assert");
/* build function call param list */
- params[0] = LLVMBuildZExt(builder, condition, arg_types[0], "");
- params[1] = msg_string;
+ args[0] = LLVMBuildZExt(builder, condition, arg_types[0], "");
+ args[1] = msg_string;
/* check arg types */
- assert(LLVMTypeOf(params[0]) == arg_types[0]);
- assert(LLVMTypeOf(params[1]) == arg_types[1]);
-
- r = LLVMBuildCall(builder, assert_func, params, 2, "");
+ assert(LLVMTypeOf(args[0]) == arg_types[0]);
+ assert(LLVMTypeOf(args[1]) == arg_types[1]);
- return r;
+ LLVMBuildCall(builder, function, args, Elements(args), "");
}
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_assert.h b/src/gallium/auxiliary/gallivm/lp_bld_assert.h
index 1d2baab30a2..e377b59bbed 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_assert.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_assert.h
@@ -33,7 +33,7 @@
#include "lp_bld_init.h"
-LLVMValueRef
+void
lp_build_assert(struct gallivm_state *gallivm,
LLVMValueRef condition,
const char *msg);