summaryrefslogtreecommitdiff
path: root/src/gallium/auxiliary/gallivm
diff options
context:
space:
mode:
authorBrian Paul <brianp@vmware.com>2010-11-30 16:07:52 -0700
committerBrian Paul <brianp@vmware.com>2010-11-30 16:35:12 -0700
commitefc82aef35a2aac5d2ed9774f6d28f2626796416 (patch)
tree72fe4482d72dbeb8e41b15793b21f38de62ef834 /src/gallium/auxiliary/gallivm
parent1f1375d4d876c2c85156e02a177254684446040b (diff)
gallivm/llvmpipe: squash merge of the llvm-context branch
This branch defines a gallivm_state structure which contains the LLVMBuilderRef, LLVMContextRef, etc. All data structures built with this object can be periodically freed during a "garbage collection" operation. The gallivm_state object has to be passed to most of the builder functions where LLVMBuilderRef used to be used. Conflicts: src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c src/gallium/drivers/llvmpipe/lp_state_setup.c
Diffstat (limited to 'src/gallium/auxiliary/gallivm')
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld.h29
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_arit.c289
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_assert.c21
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_assert.h4
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_bitarit.c4
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_const.c44
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_const.h30
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_conv.c100
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_conv.h8
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_debug.h1
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_flow.c123
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_flow.h41
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_format.h13
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_format_aos.c118
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_format_soa.c73
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_format_yuv.c115
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_gather.c41
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_gather.h6
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_init.c359
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_init.h39
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_intr.c14
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_intr.h7
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_logic.c45
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_logic.h2
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_pack.c84
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_pack.h14
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_printf.c39
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_printf.h13
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_quad.c11
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_sample.c169
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_sample.h28
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_sample_aos.c112
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c114
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_struct.c33
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_struct.h12
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_swizzle.c67
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_swizzle.h4
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_tgsi.h7
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_tgsi_aos.c47
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c159
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_type.c38
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_type.h14
42 files changed, 1484 insertions, 1007 deletions
diff --git a/src/gallium/auxiliary/gallivm/lp_bld.h b/src/gallium/auxiliary/gallivm/lp_bld.h
index 8103bc917f..ee05c6ba01 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld.h
@@ -55,4 +55,33 @@
#endif
+/**
+ * Redefine these LLVM entrypoints as invalid macros to make sure we
+ * don't accidentally use them. We need to use the functions which
+ * take an explicit LLVMContextRef parameter.
+ */
+#define LLVMInt1Type ILLEGAL_LLVM_FUNCTION
+#define LLVMInt8Type ILLEGAL_LLVM_FUNCTION
+#define LLVMInt16Type ILLEGAL_LLVM_FUNCTION
+#define LLVMInt32Type ILLEGAL_LLVM_FUNCTION
+#define LLVMInt64Type ILLEGAL_LLVM_FUNCTION
+#define LLVMIntType ILLEGAL_LLVM_FUNCTION
+#define LLVMFloatType ILLEGAL_LLVM_FUNCTION
+#define LLVMDoubleType ILLEGAL_LLVM_FUNCTION
+#define LLVMX86FP80Type ILLEGAL_LLVM_FUNCTION
+#define LLVMFP128Type ILLEGAL_LLVM_FUNCTION
+#define LLVMPPCFP128Type ILLEGAL_LLVM_FUNCTION
+#define LLVMStructType ILLEGAL_LLVM_FUNCTION
+#define LLVMVoidType ILLEGAL_LLVM_FUNCTION
+#define LLVMLabelType ILLEGAL_LLVM_FUNCTION
+#define LLVMOpaqueType ILLEGAL_LLVM_FUNCTION
+#define LLVMUnionType ILLEGAL_LLVM_FUNCTION
+#define LLVMMDString ILLEGAL_LLVM_FUNCTION
+#define LLVMMDNode ILLEGAL_LLVM_FUNCTION
+#define LLVMConstString ILLEGAL_LLVM_FUNCTION
+#define LLVMConstStruct ILLEGAL_LLVM_FUNCTION
+#define LLVMAppendBasicBlock ILLEGAL_LLVM_FUNCTION
+#define LLVMInsertBasicBlock ILLEGAL_LLVM_FUNCTION
+#define LLVMCreateBuilder ILLEGAL_LLVM_FUNCTION
+
#endif /* LP_BLD_H */
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_arit.c b/src/gallium/auxiliary/gallivm/lp_bld_arit.c
index f9a12a41a1..addedba441 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_arit.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_arit.c
@@ -53,6 +53,7 @@
#include "lp_bld_type.h"
#include "lp_bld_const.h"
+#include "lp_bld_init.h"
#include "lp_bld_intr.h"
#include "lp_bld_logic.h"
#include "lp_bld_pack.h"
@@ -107,7 +108,7 @@ lp_build_min_simple(struct lp_build_context *bld,
}
if(intrinsic)
- return lp_build_intrinsic_binary(bld->builder, intrinsic, lp_build_vec_type(bld->type), a, b);
+ return lp_build_intrinsic_binary(bld->builder, intrinsic, lp_build_vec_type(bld->gallivm, bld->type), a, b);
cond = lp_build_cmp(bld, PIPE_FUNC_LESS, a, b);
return lp_build_select(bld, cond, a, b);
@@ -156,7 +157,7 @@ lp_build_max_simple(struct lp_build_context *bld,
}
if(intrinsic)
- return lp_build_intrinsic_binary(bld->builder, intrinsic, lp_build_vec_type(bld->type), a, b);
+ return lp_build_intrinsic_binary(bld->builder, intrinsic, lp_build_vec_type(bld->gallivm, bld->type), a, b);
cond = lp_build_cmp(bld, PIPE_FUNC_GREATER, a, b);
return lp_build_select(bld, cond, a, b);
@@ -236,7 +237,7 @@ lp_build_add(struct lp_build_context *bld,
}
if(intrinsic)
- return lp_build_intrinsic_binary(bld->builder, intrinsic, lp_build_vec_type(bld->type), a, b);
+ return lp_build_intrinsic_binary(bld->builder, intrinsic, lp_build_vec_type(bld->gallivm, bld->type), a, b);
}
if(LLVMIsConstant(a) && LLVMIsConstant(b))
@@ -277,11 +278,11 @@ lp_build_sum_vector(struct lp_build_context *bld,
assert(!bld->type.norm);
- index = LLVMConstInt(LLVMInt32Type(), 0, 0);
+ index = lp_build_const_int32(bld->gallivm, 0);
res = LLVMBuildExtractElement(bld->builder, a, index, "");
for (i = 1; i < type.length; i++) {
- index = LLVMConstInt(LLVMInt32Type(), i, 0);
+ index = lp_build_const_int32(bld->gallivm, i);
if (type.floating)
res = LLVMBuildFAdd(bld->builder, res,
LLVMBuildExtractElement(bld->builder,
@@ -335,7 +336,7 @@ lp_build_sub(struct lp_build_context *bld,
}
if(intrinsic)
- return lp_build_intrinsic_binary(bld->builder, intrinsic, lp_build_vec_type(bld->type), a, b);
+ return lp_build_intrinsic_binary(bld->builder, intrinsic, lp_build_vec_type(bld->gallivm, bld->type), a, b);
}
if(LLVMIsConstant(a) && LLVMIsConstant(b))
@@ -398,10 +399,11 @@ lp_build_sub(struct lp_build_context *bld,
* http://www.stereopsis.com/doubleblend.html
*/
static LLVMValueRef
-lp_build_mul_u8n(LLVMBuilderRef builder,
+lp_build_mul_u8n(struct gallivm_state *gallivm,
struct lp_type i16_type,
LLVMValueRef a, LLVMValueRef b)
{
+ LLVMBuilderRef builder = gallivm->builder;
LLVMValueRef c8;
LLVMValueRef ab;
@@ -409,12 +411,12 @@ lp_build_mul_u8n(LLVMBuilderRef builder,
assert(lp_check_value(i16_type, a));
assert(lp_check_value(i16_type, b));
- c8 = lp_build_const_int_vec(i16_type, 8);
+ c8 = lp_build_const_int_vec(gallivm, i16_type, 8);
#if 0
/* a*b/255 ~= (a*(b + 1)) >> 256 */
- b = LLVMBuildAdd(builder, b, lp_build_const_int_vec(i16_type, 1), "");
+ b = LLVMBuildAdd(builder, b, lp_build_const_int_vec(gallium, i16_type, 1), "");
ab = LLVMBuildMul(builder, a, b, "");
#else
@@ -422,7 +424,7 @@ lp_build_mul_u8n(LLVMBuilderRef builder,
/* ab/255 ~= (ab + (ab >> 8) + 0x80) >> 8 */
ab = LLVMBuildMul(builder, a, b, "");
ab = LLVMBuildAdd(builder, ab, LLVMBuildLShr(builder, ab, c8, ""), "");
- ab = LLVMBuildAdd(builder, ab, lp_build_const_int_vec(i16_type, 0x80), "");
+ ab = LLVMBuildAdd(builder, ab, lp_build_const_int_vec(gallivm, i16_type, 0x80), "");
#endif
@@ -463,14 +465,14 @@ lp_build_mul(struct lp_build_context *bld,
struct lp_type i16_type = lp_wider_type(type);
LLVMValueRef al, ah, bl, bh, abl, abh, ab;
- lp_build_unpack2(bld->builder, type, i16_type, a, &al, &ah);
- lp_build_unpack2(bld->builder, type, i16_type, b, &bl, &bh);
+ lp_build_unpack2(bld->gallivm, type, i16_type, a, &al, &ah);
+ lp_build_unpack2(bld->gallivm, type, i16_type, b, &bl, &bh);
/* PMULLW, PSRLW, PADDW */
- abl = lp_build_mul_u8n(bld->builder, i16_type, al, bl);
- abh = lp_build_mul_u8n(bld->builder, i16_type, ah, bh);
+ abl = lp_build_mul_u8n(bld->gallivm, i16_type, al, bl);
+ abh = lp_build_mul_u8n(bld->gallivm, i16_type, ah, bh);
- ab = lp_build_pack2(bld->builder, i16_type, type, abl, abh);
+ ab = lp_build_pack2(bld->gallivm, i16_type, type, abl, abh);
return ab;
}
@@ -480,7 +482,7 @@ lp_build_mul(struct lp_build_context *bld,
}
if(type.fixed)
- shift = lp_build_const_int_vec(type, type.width/2);
+ shift = lp_build_const_int_vec(bld->gallivm, type, type.width/2);
else
shift = NULL;
@@ -550,20 +552,20 @@ lp_build_mul_imm(struct lp_build_context *bld,
* for Inf and NaN.
*/
unsigned mantissa = lp_mantissa(bld->type);
- factor = lp_build_const_int_vec(bld->type, (unsigned long long)shift << mantissa);
+ factor = lp_build_const_int_vec(bld->gallivm, bld->type, (unsigned long long)shift << mantissa);
a = LLVMBuildBitCast(bld->builder, a, lp_build_int_vec_type(bld->type), "");
a = LLVMBuildAdd(bld->builder, a, factor, "");
- a = LLVMBuildBitCast(bld->builder, a, lp_build_vec_type(bld->type), "");
+ a = LLVMBuildBitCast(bld->builder, a, lp_build_vec_type(bld->gallivm, bld->type), "");
return a;
#endif
}
else {
- factor = lp_build_const_vec(bld->type, shift);
+ factor = lp_build_const_vec(bld->gallivm, bld->type, shift);
return LLVMBuildShl(bld->builder, a, factor, "");
}
}
- factor = lp_build_const_vec(bld->type, (double)b);
+ factor = lp_build_const_vec(bld->gallivm, bld->type, (double)b);
return lp_build_mul(bld, a, factor);
}
@@ -642,7 +644,7 @@ lp_build_lerp_simple(struct lp_build_context *bld,
* but it will be wrong for other uses. Basically we need a more
* powerful lp_type, capable of further distinguishing the values
* interpretation from the value storage. */
- res = LLVMBuildAnd(bld->builder, res, lp_build_const_int_vec(bld->type, (1 << bld->type.width/2) - 1), "");
+ res = LLVMBuildAnd(bld->builder, res, lp_build_const_int_vec(bld->gallivm, bld->type, (1 << bld->type.width/2) - 1), "");
}
return res;
@@ -683,17 +685,17 @@ lp_build_lerp(struct lp_build_context *bld,
wide_type.width = type.width*2;
wide_type.length = type.length/2;
- lp_build_context_init(&wide_bld, bld->builder, wide_type);
+ lp_build_context_init(&wide_bld, bld->gallivm, wide_type);
- lp_build_unpack2(bld->builder, type, wide_type, x, &xl, &xh);
- lp_build_unpack2(bld->builder, type, wide_type, v0, &v0l, &v0h);
- lp_build_unpack2(bld->builder, type, wide_type, v1, &v1l, &v1h);
+ lp_build_unpack2(bld->gallivm, type, wide_type, x, &xl, &xh);
+ lp_build_unpack2(bld->gallivm, type, wide_type, v0, &v0l, &v0h);
+ lp_build_unpack2(bld->gallivm, type, wide_type, v1, &v1l, &v1h);
/*
* Scale x from [0, 255] to [0, 256]
*/
- shift = lp_build_const_int_vec(wide_type, type.width - 1);
+ shift = lp_build_const_int_vec(bld->gallivm, wide_type, type.width - 1);
xl = lp_build_add(&wide_bld, xl,
LLVMBuildAShr(bld->builder, xl, shift, ""));
@@ -707,7 +709,7 @@ lp_build_lerp(struct lp_build_context *bld,
resl = lp_build_lerp_simple(&wide_bld, xl, v0l, v1l);
resh = lp_build_lerp_simple(&wide_bld, xh, v0h, v1h);
- res = lp_build_pack2(bld->builder, wide_type, type, resl, resh);
+ res = lp_build_pack2(bld->gallivm, wide_type, type, resl, resh);
} else {
res = lp_build_lerp_simple(bld, x, v0, v1);
}
@@ -821,7 +823,7 @@ lp_build_abs(struct lp_build_context *bld,
LLVMValueRef a)
{
const struct lp_type type = bld->type;
- LLVMTypeRef vec_type = lp_build_vec_type(type);
+ LLVMTypeRef vec_type = lp_build_vec_type(bld->gallivm, type);
assert(lp_check_value(type, a));
@@ -830,9 +832,9 @@ lp_build_abs(struct lp_build_context *bld,
if(type.floating) {
/* Mask out the sign bit */
- LLVMTypeRef int_vec_type = lp_build_int_vec_type(type);
+ LLVMTypeRef int_vec_type = lp_build_int_vec_type(bld->gallivm, type);
unsigned long long absMask = ~(1ULL << (type.width - 1));
- LLVMValueRef mask = lp_build_const_int_vec(type, ((unsigned long long) absMask));
+ LLVMValueRef mask = lp_build_const_int_vec(bld->gallivm, type, ((unsigned long long) absMask));
a = LLVMBuildBitCast(bld->builder, a, int_vec_type, "");
a = LLVMBuildAnd(bld->builder, a, mask, "");
a = LLVMBuildBitCast(bld->builder, a, vec_type, "");
@@ -895,9 +897,9 @@ lp_build_sgn(struct lp_build_context *bld,
LLVMValueRef one;
unsigned long long maskBit = (unsigned long long)1 << (type.width - 1);
- int_type = lp_build_int_vec_type(type);
- vec_type = lp_build_vec_type(type);
- mask = lp_build_const_int_vec(type, maskBit);
+ int_type = lp_build_int_vec_type(bld->gallivm, type);
+ vec_type = lp_build_vec_type(bld->gallivm, type);
+ mask = lp_build_const_int_vec(bld->gallivm, type, maskBit);
/* Take the sign bit and add it to 1 constant */
sign = LLVMBuildBitCast(bld->builder, a, int_type, "");
@@ -908,7 +910,7 @@ lp_build_sgn(struct lp_build_context *bld,
}
else
{
- LLVMValueRef minus_one = lp_build_const_vec(type, -1.0);
+ LLVMValueRef minus_one = lp_build_const_vec(bld->gallivm, type, -1.0);
cond = lp_build_cmp(bld, PIPE_FUNC_GREATER, a, bld->zero);
res = lp_build_select(bld, cond, bld->one, minus_one);
}
@@ -932,10 +934,10 @@ lp_build_set_sign(struct lp_build_context *bld,
LLVMValueRef a, LLVMValueRef sign)
{
const struct lp_type type = bld->type;
- LLVMTypeRef int_vec_type = lp_build_int_vec_type(type);
- LLVMTypeRef vec_type = lp_build_vec_type(type);
- LLVMValueRef shift = lp_build_const_int_vec(type, type.width - 1);
- LLVMValueRef mask = lp_build_const_int_vec(type,
+ LLVMTypeRef int_vec_type = lp_build_int_vec_type(bld->gallivm, type);
+ LLVMTypeRef vec_type = lp_build_vec_type(bld->gallivm, type);
+ LLVMValueRef shift = lp_build_const_int_vec(bld->gallivm, type, type.width - 1);
+ LLVMValueRef mask = lp_build_const_int_vec(bld->gallivm, type,
~((unsigned long long) 1 << (type.width - 1)));
LLVMValueRef val, res;
@@ -965,7 +967,7 @@ lp_build_int_to_float(struct lp_build_context *bld,
LLVMValueRef a)
{
const struct lp_type type = bld->type;
- LLVMTypeRef vec_type = lp_build_vec_type(type);
+ LLVMTypeRef vec_type = lp_build_vec_type(bld->gallivm, type);
assert(type.floating);
@@ -995,7 +997,7 @@ lp_build_round_sse41(struct lp_build_context *bld,
enum lp_build_round_sse41_mode mode)
{
const struct lp_type type = bld->type;
- LLVMTypeRef i32t = LLVMInt32Type();
+ LLVMTypeRef i32t = LLVMInt32TypeInContext(bld->gallivm->context);
const char *intrinsic;
LLVMValueRef res;
@@ -1064,8 +1066,8 @@ lp_build_iround_nearest_sse2(struct lp_build_context *bld,
LLVMValueRef a)
{
const struct lp_type type = bld->type;
- LLVMTypeRef i32t = LLVMInt32Type();
- LLVMTypeRef ret_type = lp_build_int_vec_type(type);
+ LLVMTypeRef i32t = LLVMInt32TypeInContext(bld->gallivm->context);
+ LLVMTypeRef ret_type = lp_build_int_vec_type(bld->gallivm, type);
const char *intrinsic;
LLVMValueRef res;
@@ -1126,8 +1128,8 @@ lp_build_trunc(struct lp_build_context *bld,
return lp_build_round_sse41(bld, a, LP_BUILD_ROUND_SSE41_TRUNCATE);
}
else {
- LLVMTypeRef vec_type = lp_build_vec_type(type);
- LLVMTypeRef int_vec_type = lp_build_int_vec_type(type);
+ LLVMTypeRef vec_type = lp_build_vec_type(bld->gallivm, type);
+ LLVMTypeRef int_vec_type = lp_build_int_vec_type(bld->gallivm, type);
LLVMValueRef res;
res = LLVMBuildFPToSI(bld->builder, a, int_vec_type, "");
res = LLVMBuildSIToFP(bld->builder, res, vec_type, "");
@@ -1156,7 +1158,7 @@ lp_build_round(struct lp_build_context *bld,
return lp_build_round_sse41(bld, a, LP_BUILD_ROUND_SSE41_NEAREST);
}
else {
- LLVMTypeRef vec_type = lp_build_vec_type(type);
+ LLVMTypeRef vec_type = lp_build_vec_type(bld->gallivm, type);
LLVMValueRef res;
res = lp_build_iround(bld, a);
res = LLVMBuildSIToFP(bld->builder, res, vec_type, "");
@@ -1184,7 +1186,7 @@ lp_build_floor(struct lp_build_context *bld,
return lp_build_round_sse41(bld, a, LP_BUILD_ROUND_SSE41_FLOOR);
}
else {
- LLVMTypeRef vec_type = lp_build_vec_type(type);
+ LLVMTypeRef vec_type = lp_build_vec_type(bld->gallivm, type);
LLVMValueRef res;
res = lp_build_ifloor(bld, a);
res = LLVMBuildSIToFP(bld->builder, res, vec_type, "");
@@ -1212,7 +1214,7 @@ lp_build_ceil(struct lp_build_context *bld,
return lp_build_round_sse41(bld, a, LP_BUILD_ROUND_SSE41_CEIL);
}
else {
- LLVMTypeRef vec_type = lp_build_vec_type(type);
+ LLVMTypeRef vec_type = lp_build_vec_type(bld->gallivm, type);
LLVMValueRef res;
res = lp_build_iceil(bld, a);
res = LLVMBuildSIToFP(bld->builder, res, vec_type, "");
@@ -1244,7 +1246,7 @@ lp_build_itrunc(struct lp_build_context *bld,
LLVMValueRef a)
{
const struct lp_type type = bld->type;
- LLVMTypeRef int_vec_type = lp_build_int_vec_type(type);
+ LLVMTypeRef int_vec_type = lp_build_int_vec_type(bld->gallivm, type);
assert(type.floating);
assert(lp_check_value(type, a));
@@ -1282,11 +1284,12 @@ lp_build_iround(struct lp_build_context *bld,
else {
LLVMValueRef half;
- half = lp_build_const_vec(type, 0.5);
+ half = lp_build_const_vec(bld->gallivm, type, 0.5);
if (type.sign) {
LLVMTypeRef vec_type = bld->vec_type;
- LLVMValueRef mask = lp_build_const_int_vec(type, (unsigned long long)1 << (type.width - 1));
+ LLVMValueRef mask = lp_build_const_int_vec(bld->gallivm, type,
+ (unsigned long long)1 << (type.width - 1));
LLVMValueRef sign;
/* get sign bit */
@@ -1335,17 +1338,22 @@ lp_build_ifloor(struct lp_build_context *bld,
/* Take the sign bit and add it to 1 constant */
LLVMTypeRef vec_type = bld->vec_type;
unsigned mantissa = lp_mantissa(type);
- LLVMValueRef mask = lp_build_const_int_vec(type, (unsigned long long)1 << (type.width - 1));
+ LLVMValueRef mask = lp_build_const_int_vec(bld->gallivm, type,
+ (unsigned long long)1 << (type.width - 1));
LLVMValueRef sign;
LLVMValueRef offset;
/* sign = a < 0 ? ~0 : 0 */
sign = LLVMBuildBitCast(bld->builder, a, int_vec_type, "");
sign = LLVMBuildAnd(bld->builder, sign, mask, "");
- sign = LLVMBuildAShr(bld->builder, sign, lp_build_const_int_vec(type, type.width - 1), "ifloor.sign");
+ sign = LLVMBuildAShr(bld->builder, sign,
+ lp_build_const_int_vec(bld->gallivm, type,
+ type.width - 1),
+ "ifloor.sign");
/* offset = -0.99999(9)f */
- offset = lp_build_const_vec(type, -(double)(((unsigned long long)1 << mantissa) - 10)/((unsigned long long)1 << mantissa));
+ offset = lp_build_const_vec(bld->gallivm, type,
+ -(double)(((unsigned long long)1 << mantissa) - 10)/((unsigned long long)1 << mantissa));
offset = LLVMConstBitCast(offset, int_vec_type);
/* offset = a < 0 ? offset : 0.0f */
@@ -1389,16 +1397,21 @@ lp_build_iceil(struct lp_build_context *bld,
LLVMValueRef offset;
/* offset = 0.99999(9)f */
- offset = lp_build_const_vec(type, (double)(((unsigned long long)1 << mantissa) - 10)/((unsigned long long)1 << mantissa));
+ offset = lp_build_const_vec(bld->gallivm, type,
+ (double)(((unsigned long long)1 << mantissa) - 10)/((unsigned long long)1 << mantissa));
if (type.sign) {
- LLVMValueRef mask = lp_build_const_int_vec(type, (unsigned long long)1 << (type.width - 1));
+ LLVMValueRef mask = lp_build_const_int_vec(bld->gallivm, type,
+ (unsigned long long)1 << (type.width - 1));
LLVMValueRef sign;
/* sign = a < 0 ? 0 : ~0 */
sign = LLVMBuildBitCast(bld->builder, a, int_vec_type, "");
sign = LLVMBuildAnd(bld->builder, sign, mask, "");
- sign = LLVMBuildAShr(bld->builder, sign, lp_build_const_int_vec(type, type.width - 1), "iceil.sign");
+ sign = LLVMBuildAShr(bld->builder, sign,
+ lp_build_const_int_vec(bld->gallivm, type,
+ type.width - 1),
+ "iceil.sign");
sign = LLVMBuildNot(bld->builder, sign, "iceil.not");
/* offset = a < 0 ? 0.0 : offset */
@@ -1462,7 +1475,7 @@ lp_build_sqrt(struct lp_build_context *bld,
LLVMValueRef a)
{
const struct lp_type type = bld->type;
- LLVMTypeRef vec_type = lp_build_vec_type(type);
+ LLVMTypeRef vec_type = lp_build_vec_type(bld->gallivm, type);
char intrinsic[32];
assert(lp_check_value(type, a));
@@ -1496,7 +1509,7 @@ lp_build_rcp_refine(struct lp_build_context *bld,
LLVMValueRef a,
LLVMValueRef rcp_a)
{
- LLVMValueRef two = lp_build_const_vec(bld->type, 2.0);
+ LLVMValueRef two = lp_build_const_vec(bld->gallivm, bld->type, 2.0);
LLVMValueRef res;
res = LLVMBuildFMul(bld->builder, a, rcp_a, "");
@@ -1571,8 +1584,8 @@ lp_build_rsqrt_refine(struct lp_build_context *bld,
LLVMValueRef a,
LLVMValueRef rsqrt_a)
{
- LLVMValueRef half = lp_build_const_vec(bld->type, 0.5);
- LLVMValueRef three = lp_build_const_vec(bld->type, 3.0);
+ LLVMValueRef half = lp_build_const_vec(bld->gallivm, bld->type, 0.5);
+ LLVMValueRef three = lp_build_const_vec(bld->gallivm, bld->type, 3.0);
LLVMValueRef res;
res = LLVMBuildFMul(bld->builder, rsqrt_a, rsqrt_a, "");
@@ -1617,17 +1630,17 @@ lp_build_rsqrt(struct lp_build_context *bld,
static inline LLVMValueRef
-lp_build_const_v4si(unsigned long value)
+lp_build_const_v4si(struct gallivm_state *gallivm, unsigned long value)
{
- LLVMValueRef element = LLVMConstInt(LLVMInt32Type(), value, 0);
+ LLVMValueRef element = lp_build_const_int32(gallivm, value);
LLVMValueRef elements[4] = { element, element, element, element };
return LLVMConstVector(elements, 4);
}
static inline LLVMValueRef
-lp_build_const_v4sf(float value)
+lp_build_const_v4sf(struct gallivm_state *gallivm, float value)
{
- LLVMValueRef element = LLVMConstReal(LLVMFloatType(), value);
+ LLVMValueRef element = lp_build_const_float(gallivm, value);
LLVMValueRef elements[4] = { element, element, element, element };
return LLVMConstVector(elements, 4);
}
@@ -1640,17 +1653,18 @@ LLVMValueRef
lp_build_sin(struct lp_build_context *bld,
LLVMValueRef a)
{
+ struct gallivm_state *gallivm = bld->gallivm;
struct lp_type int_type = lp_int_type(bld->type);
LLVMBuilderRef b = bld->builder;
- LLVMTypeRef v4sf = LLVMVectorType(LLVMFloatType(), 4);
- LLVMTypeRef v4si = LLVMVectorType(LLVMInt32Type(), 4);
+ LLVMTypeRef v4sf = LLVMVectorType(LLVMFloatTypeInContext(bld->gallivm->context), 4);
+ LLVMTypeRef v4si = LLVMVectorType(LLVMInt32TypeInContext(bld->gallivm->context), 4);
/*
* take the absolute value,
* x = _mm_and_ps(x, *(v4sf*)_ps_inv_sign_mask);
*/
- LLVMValueRef inv_sig_mask = lp_build_const_v4si(~0x80000000);
+ LLVMValueRef inv_sig_mask = lp_build_const_v4si(bld->gallivm, ~0x80000000);
LLVMValueRef a_v4si = LLVMBuildBitCast(b, a, v4si, "a_v4si");
LLVMValueRef absi = LLVMBuildAnd(b, a_v4si, inv_sig_mask, "absi");
@@ -1660,7 +1674,7 @@ lp_build_sin(struct lp_build_context *bld,
* extract the sign bit (upper one)
* sign_bit = _mm_and_ps(sign_bit, *(v4sf*)_ps_sign_mask);
*/
- LLVMValueRef sig_mask = lp_build_const_v4si(0x80000000);
+ LLVMValueRef sig_mask = lp_build_const_v4si(bld->gallivm, 0x80000000);
LLVMValueRef sign_bit_i = LLVMBuildAnd(b, a_v4si, sig_mask, "sign_bit_i");
/*
@@ -1668,7 +1682,7 @@ lp_build_sin(struct lp_build_context *bld,
* y = _mm_mul_ps(x, *(v4sf*)_ps_cephes_FOPI);
*/
- LLVMValueRef FOPi = lp_build_const_v4sf(1.27323954473516);
+ LLVMValueRef FOPi = lp_build_const_v4sf(gallivm, 1.27323954473516);
LLVMValueRef scale_y = LLVMBuildFMul(b, x_abs, FOPi, "scale_y");
/*
@@ -1683,12 +1697,12 @@ lp_build_sin(struct lp_build_context *bld,
* emm2 = _mm_add_epi32(emm2, *(v4si*)_pi32_1);
*/
- LLVMValueRef all_one = lp_build_const_v4si(1);
+ LLVMValueRef all_one = lp_build_const_v4si(bld->gallivm, 1);
LLVMValueRef emm2_add = LLVMBuildAdd(b, emm2_i, all_one, "emm2_add");
/*
* emm2 = _mm_and_si128(emm2, *(v4si*)_pi32_inv1);
*/
- LLVMValueRef inv_one = lp_build_const_v4si(~1);
+ LLVMValueRef inv_one = lp_build_const_v4si(bld->gallivm, ~1);
LLVMValueRef emm2_and = LLVMBuildAnd(b, emm2_add, inv_one, "emm2_and");
/*
@@ -1699,13 +1713,13 @@ lp_build_sin(struct lp_build_context *bld,
/* get the swap sign flag
* emm0 = _mm_and_si128(emm2, *(v4si*)_pi32_4);
*/
- LLVMValueRef pi32_4 = lp_build_const_v4si(4);
+ LLVMValueRef pi32_4 = lp_build_const_v4si(bld->gallivm, 4);
LLVMValueRef emm0_and = LLVMBuildAnd(b, emm2_add, pi32_4, "emm0_and");
/*
* emm2 = _mm_slli_epi32(emm0, 29);
*/
- LLVMValueRef const_29 = lp_build_const_v4si(29);
+ LLVMValueRef const_29 = lp_build_const_v4si(bld->gallivm, 29);
LLVMValueRef swap_sign_bit = LLVMBuildShl(b, emm0_and, const_29, "swap_sign_bit");
/*
@@ -1718,10 +1732,11 @@ lp_build_sin(struct lp_build_context *bld,
* emm2 = _mm_cmpeq_epi32(emm2, _mm_setzero_si128());
*/
- LLVMValueRef pi32_2 = lp_build_const_v4si(2);
+ LLVMValueRef pi32_2 = lp_build_const_v4si(bld->gallivm, 2);
LLVMValueRef emm2_3 = LLVMBuildAnd(b, emm2_and, pi32_2, "emm2_3");
- LLVMValueRef poly_mask = lp_build_compare(b, int_type, PIPE_FUNC_EQUAL,
- emm2_3, lp_build_const_v4si(0));
+ LLVMValueRef poly_mask = lp_build_compare(bld->gallivm,
+ int_type, PIPE_FUNC_EQUAL,
+ emm2_3, lp_build_const_v4si(bld->gallivm, 0));
/*
* sign_bit = _mm_xor_ps(sign_bit, swap_sign_bit);
*/
@@ -1732,9 +1747,9 @@ lp_build_sin(struct lp_build_context *bld,
* _PS_CONST(minus_cephes_DP2, -2.4187564849853515625e-4);
* _PS_CONST(minus_cephes_DP3, -3.77489497744594108e-8);
*/
- LLVMValueRef DP1 = lp_build_const_v4sf(-0.78515625);
- LLVMValueRef DP2 = lp_build_const_v4sf(-2.4187564849853515625e-4);
- LLVMValueRef DP3 = lp_build_const_v4sf(-3.77489497744594108e-8);
+ LLVMValueRef DP1 = lp_build_const_v4sf(gallivm, -0.78515625);
+ LLVMValueRef DP2 = lp_build_const_v4sf(gallivm, -2.4187564849853515625e-4);
+ LLVMValueRef DP3 = lp_build_const_v4sf(gallivm, -3.77489497744594108e-8);
/*
* The magic pass: "Extended precision modular arithmetic"
@@ -1769,9 +1784,9 @@ lp_build_sin(struct lp_build_context *bld,
* _PS_CONST(coscof_p1, -1.388731625493765E-003);
* _PS_CONST(coscof_p2, 4.166664568298827E-002);
*/
- LLVMValueRef coscof_p0 = lp_build_const_v4sf(2.443315711809948E-005);
- LLVMValueRef coscof_p1 = lp_build_const_v4sf(-1.388731625493765E-003);
- LLVMValueRef coscof_p2 = lp_build_const_v4sf(4.166664568298827E-002);
+ LLVMValueRef coscof_p0 = lp_build_const_v4sf(gallivm, 2.443315711809948E-005);
+ LLVMValueRef coscof_p1 = lp_build_const_v4sf(gallivm, -1.388731625493765E-003);
+ LLVMValueRef coscof_p2 = lp_build_const_v4sf(gallivm, 4.166664568298827E-002);
/*
* y = *(v4sf*)_ps_coscof_p0;
@@ -1790,10 +1805,10 @@ lp_build_sin(struct lp_build_context *bld,
* y = _mm_sub_ps(y, tmp);
* y = _mm_add_ps(y, *(v4sf*)_ps_1);
*/
- LLVMValueRef half = lp_build_const_v4sf(0.5);
+ LLVMValueRef half = lp_build_const_v4sf(gallivm, 0.5);
LLVMValueRef tmp = LLVMBuildFMul(b, z, half, "tmp");
LLVMValueRef y_9 = LLVMBuildFSub(b, y_8, tmp, "y_8");
- LLVMValueRef one = lp_build_const_v4sf(1.0);
+ LLVMValueRef one = lp_build_const_v4sf(gallivm, 1.0);
LLVMValueRef y_10 = LLVMBuildFAdd(b, y_9, one, "y_9");
/*
@@ -1801,9 +1816,9 @@ lp_build_sin(struct lp_build_context *bld,
* _PS_CONST(sincof_p1, 8.3321608736E-3);
* _PS_CONST(sincof_p2, -1.6666654611E-1);
*/
- LLVMValueRef sincof_p0 = lp_build_const_v4sf(-1.9515295891E-4);
- LLVMValueRef sincof_p1 = lp_build_const_v4sf(8.3321608736E-3);
- LLVMValueRef sincof_p2 = lp_build_const_v4sf(-1.6666654611E-1);
+ LLVMValueRef sincof_p0 = lp_build_const_v4sf(gallivm, -1.9515295891E-4);
+ LLVMValueRef sincof_p1 = lp_build_const_v4sf(gallivm, 8.3321608736E-3);
+ LLVMValueRef sincof_p2 = lp_build_const_v4sf(gallivm, -1.6666654611E-1);
/*
* Evaluate the second polynom (Pi/4 <= x <= 0)
@@ -1836,7 +1851,7 @@ lp_build_sin(struct lp_build_context *bld,
LLVMValueRef y2_i = LLVMBuildBitCast(b, y2_9, v4si, "y2_i");
LLVMValueRef y_i = LLVMBuildBitCast(b, y_10, v4si, "y_i");
LLVMValueRef y2_and = LLVMBuildAnd(b, y2_i, poly_mask, "y2_and");
- LLVMValueRef inv = lp_build_const_v4si(~0);
+ LLVMValueRef inv = lp_build_const_v4si(bld->gallivm, ~0);
LLVMValueRef poly_mask_inv = LLVMBuildXor(b, poly_mask, inv, "poly_mask_inv");
LLVMValueRef y_and = LLVMBuildAnd(b, y_i, poly_mask_inv, "y_and");
LLVMValueRef y_combine = LLVMBuildAdd(b, y_and, y2_and, "y_combine");
@@ -1858,17 +1873,18 @@ LLVMValueRef
lp_build_cos(struct lp_build_context *bld,
LLVMValueRef a)
{
+ struct gallivm_state *gallivm = bld->gallivm;
struct lp_type int_type = lp_int_type(bld->type);
LLVMBuilderRef b = bld->builder;
- LLVMTypeRef v4sf = LLVMVectorType(LLVMFloatType(), 4);
- LLVMTypeRef v4si = LLVMVectorType(LLVMInt32Type(), 4);
+ LLVMTypeRef v4sf = LLVMVectorType(LLVMFloatTypeInContext(bld->gallivm->context), 4);
+ LLVMTypeRef v4si = LLVMVectorType(LLVMInt32TypeInContext(bld->gallivm->context), 4);
/*
* take the absolute value,
* x = _mm_and_ps(x, *(v4sf*)_ps_inv_sign_mask);
*/
- LLVMValueRef inv_sig_mask = lp_build_const_v4si(~0x80000000);
+ LLVMValueRef inv_sig_mask = lp_build_const_v4si(bld->gallivm, ~0x80000000);
LLVMValueRef a_v4si = LLVMBuildBitCast(b, a, v4si, "a_v4si");
LLVMValueRef absi = LLVMBuildAnd(b, a_v4si, inv_sig_mask, "absi");
@@ -1879,7 +1895,7 @@ lp_build_cos(struct lp_build_context *bld,
* y = _mm_mul_ps(x, *(v4sf*)_ps_cephes_FOPI);
*/
- LLVMValueRef FOPi = lp_build_const_v4sf(1.27323954473516);
+ LLVMValueRef FOPi = lp_build_const_v4sf(gallivm, 1.27323954473516);
LLVMValueRef scale_y = LLVMBuildFMul(b, x_abs, FOPi, "scale_y");
/*
@@ -1894,12 +1910,12 @@ lp_build_cos(struct lp_build_context *bld,
* emm2 = _mm_add_epi32(emm2, *(v4si*)_pi32_1);
*/
- LLVMValueRef all_one = lp_build_const_v4si(1);
+ LLVMValueRef all_one = lp_build_const_v4si(bld->gallivm, 1);
LLVMValueRef emm2_add = LLVMBuildAdd(b, emm2_i, all_one, "emm2_add");
/*
* emm2 = _mm_and_si128(emm2, *(v4si*)_pi32_inv1);
*/
- LLVMValueRef inv_one = lp_build_const_v4si(~1);
+ LLVMValueRef inv_one = lp_build_const_v4si(bld->gallivm, ~1);
LLVMValueRef emm2_and = LLVMBuildAnd(b, emm2_add, inv_one, "emm2_and");
/*
@@ -1911,22 +1927,22 @@ lp_build_cos(struct lp_build_context *bld,
/*
* emm2 = _mm_sub_epi32(emm2, *(v4si*)_pi32_2);
*/
- LLVMValueRef const_2 = lp_build_const_v4si(2);
+ LLVMValueRef const_2 = lp_build_const_v4si(bld->gallivm, 2);
LLVMValueRef emm2_2 = LLVMBuildSub(b, emm2_and, const_2, "emm2_2");
/* get the swap sign flag
* emm0 = _mm_andnot_si128(emm2, *(v4si*)_pi32_4);
*/
- LLVMValueRef inv = lp_build_const_v4si(~0);
+ LLVMValueRef inv = lp_build_const_v4si(bld->gallivm, ~0);
LLVMValueRef emm0_not = LLVMBuildXor(b, emm2_2, inv, "emm0_not");
- LLVMValueRef pi32_4 = lp_build_const_v4si(4);
+ LLVMValueRef pi32_4 = lp_build_const_v4si(bld->gallivm, 4);
LLVMValueRef emm0_and = LLVMBuildAnd(b, emm0_not, pi32_4, "emm0_and");
/*
* emm2 = _mm_slli_epi32(emm0, 29);
*/
- LLVMValueRef const_29 = lp_build_const_v4si(29);
+ LLVMValueRef const_29 = lp_build_const_v4si(bld->gallivm, 29);
LLVMValueRef sign_bit = LLVMBuildShl(b, emm0_and, const_29, "sign_bit");
/*
@@ -1939,19 +1955,20 @@ lp_build_cos(struct lp_build_context *bld,
* emm2 = _mm_cmpeq_epi32(emm2, _mm_setzero_si128());
*/
- LLVMValueRef pi32_2 = lp_build_const_v4si(2);
+ LLVMValueRef pi32_2 = lp_build_const_v4si(bld->gallivm, 2);
LLVMValueRef emm2_3 = LLVMBuildAnd(b, emm2_2, pi32_2, "emm2_3");
- LLVMValueRef poly_mask = lp_build_compare(b, int_type, PIPE_FUNC_EQUAL,
- emm2_3, lp_build_const_v4si(0));
+ LLVMValueRef poly_mask = lp_build_compare(bld->gallivm,
+ int_type, PIPE_FUNC_EQUAL,
+ emm2_3, lp_build_const_v4si(bld->gallivm, 0));
/*
* _PS_CONST(minus_cephes_DP1, -0.78515625);
* _PS_CONST(minus_cephes_DP2, -2.4187564849853515625e-4);
* _PS_CONST(minus_cephes_DP3, -3.77489497744594108e-8);
*/
- LLVMValueRef DP1 = lp_build_const_v4sf(-0.78515625);
- LLVMValueRef DP2 = lp_build_const_v4sf(-2.4187564849853515625e-4);
- LLVMValueRef DP3 = lp_build_const_v4sf(-3.77489497744594108e-8);
+ LLVMValueRef DP1 = lp_build_const_v4sf(gallivm, -0.78515625);
+ LLVMValueRef DP2 = lp_build_const_v4sf(gallivm, -2.4187564849853515625e-4);
+ LLVMValueRef DP3 = lp_build_const_v4sf(gallivm, -3.77489497744594108e-8);
/*
* The magic pass: "Extended precision modular arithmetic"
@@ -1986,9 +2003,9 @@ lp_build_cos(struct lp_build_context *bld,
* _PS_CONST(coscof_p1, -1.388731625493765E-003);
* _PS_CONST(coscof_p2, 4.166664568298827E-002);
*/
- LLVMValueRef coscof_p0 = lp_build_const_v4sf(2.443315711809948E-005);
- LLVMValueRef coscof_p1 = lp_build_const_v4sf(-1.388731625493765E-003);
- LLVMValueRef coscof_p2 = lp_build_const_v4sf(4.166664568298827E-002);
+ LLVMValueRef coscof_p0 = lp_build_const_v4sf(gallivm, 2.443315711809948E-005);
+ LLVMValueRef coscof_p1 = lp_build_const_v4sf(gallivm, -1.388731625493765E-003);
+ LLVMValueRef coscof_p2 = lp_build_const_v4sf(gallivm, 4.166664568298827E-002);
/*
* y = *(v4sf*)_ps_coscof_p0;
@@ -2007,10 +2024,10 @@ lp_build_cos(struct lp_build_context *bld,
* y = _mm_sub_ps(y, tmp);
* y = _mm_add_ps(y, *(v4sf*)_ps_1);
*/
- LLVMValueRef half = lp_build_const_v4sf(0.5);
+ LLVMValueRef half = lp_build_const_v4sf(gallivm, 0.5);
LLVMValueRef tmp = LLVMBuildFMul(b, z, half, "tmp");
LLVMValueRef y_9 = LLVMBuildFSub(b, y_8, tmp, "y_8");
- LLVMValueRef one = lp_build_const_v4sf(1.0);
+ LLVMValueRef one = lp_build_const_v4sf(gallivm, 1.0);
LLVMValueRef y_10 = LLVMBuildFAdd(b, y_9, one, "y_9");
/*
@@ -2018,9 +2035,9 @@ lp_build_cos(struct lp_build_context *bld,
* _PS_CONST(sincof_p1, 8.3321608736E-3);
* _PS_CONST(sincof_p2, -1.6666654611E-1);
*/
- LLVMValueRef sincof_p0 = lp_build_const_v4sf(-1.9515295891E-4);
- LLVMValueRef sincof_p1 = lp_build_const_v4sf(8.3321608736E-3);
- LLVMValueRef sincof_p2 = lp_build_const_v4sf(-1.6666654611E-1);
+ LLVMValueRef sincof_p0 = lp_build_const_v4sf(gallivm, -1.9515295891E-4);
+ LLVMValueRef sincof_p1 = lp_build_const_v4sf(gallivm, 8.3321608736E-3);
+ LLVMValueRef sincof_p2 = lp_build_const_v4sf(gallivm, -1.6666654611E-1);
/*
* Evaluate the second polynom (Pi/4 <= x <= 0)
@@ -2094,7 +2111,8 @@ lp_build_exp(struct lp_build_context *bld,
LLVMValueRef x)
{
/* log2(e) = 1/log(2) */
- LLVMValueRef log2e = lp_build_const_vec(bld->type, 1.4426950408889634);
+ LLVMValueRef log2e = lp_build_const_vec(bld->gallivm, bld->type,
+ 1.4426950408889634);
assert(lp_check_value(bld->type, x));
@@ -2110,7 +2128,8 @@ lp_build_log(struct lp_build_context *bld,
LLVMValueRef x)
{
/* log(2) */
- LLVMValueRef log2 = lp_build_const_vec(bld->type, 0.69314718055994529);
+ LLVMValueRef log2 = lp_build_const_vec(bld->gallivm, bld->type,
+ 0.69314718055994529);
assert(lp_check_value(bld->type, x));
@@ -2144,7 +2163,7 @@ lp_build_polynomial(struct lp_build_context *bld,
for (i = num_coeffs; i--; ) {
LLVMValueRef coeff;
- coeff = lp_build_const_vec(type, coeffs[i]);
+ coeff = lp_build_const_vec(bld->gallivm, type, coeffs[i]);
if(res)
res = lp_build_add(bld, coeff, lp_build_mul(bld, x, res));
@@ -2199,8 +2218,8 @@ lp_build_exp2_approx(struct lp_build_context *bld,
LLVMValueRef *p_exp2)
{
const struct lp_type type = bld->type;
- LLVMTypeRef vec_type = lp_build_vec_type(type);
- LLVMTypeRef int_vec_type = lp_build_int_vec_type(type);
+ LLVMTypeRef vec_type = lp_build_vec_type(bld->gallivm, type);
+ LLVMTypeRef int_vec_type = lp_build_int_vec_type(bld->gallivm, type);
LLVMValueRef ipart = NULL;
LLVMValueRef fpart = NULL;
LLVMValueRef expipart = NULL;
@@ -2219,8 +2238,8 @@ lp_build_exp2_approx(struct lp_build_context *bld,
assert(type.floating && type.width == 32);
- x = lp_build_min(bld, x, lp_build_const_vec(type, 129.0));
- x = lp_build_max(bld, x, lp_build_const_vec(type, -126.99999));
+ x = lp_build_min(bld, x, lp_build_const_vec(bld->gallivm, type, 129.0));
+ x = lp_build_max(bld, x, lp_build_const_vec(bld->gallivm, type, -126.99999));
/* ipart = floor(x) */
ipart = lp_build_floor(bld, x);
@@ -2232,8 +2251,10 @@ lp_build_exp2_approx(struct lp_build_context *bld,
if(p_exp2_int_part || p_exp2) {
/* expipart = (float) (1 << ipart) */
ipart = LLVMBuildFPToSI(bld->builder, ipart, int_vec_type, "");
- expipart = LLVMBuildAdd(bld->builder, ipart, lp_build_const_int_vec(type, 127), "");
- expipart = LLVMBuildShl(bld->builder, expipart, lp_build_const_int_vec(type, 23), "");
+ expipart = LLVMBuildAdd(bld->builder, ipart,
+ lp_build_const_int_vec(bld->gallivm, type, 127), "");
+ expipart = LLVMBuildShl(bld->builder, expipart,
+ lp_build_const_int_vec(bld->gallivm, type, 23), "");
expipart = LLVMBuildBitCast(bld->builder, expipart, vec_type, "");
}
@@ -2289,9 +2310,12 @@ lp_build_extract_exponent(struct lp_build_context *bld,
x = LLVMBuildBitCast(bld->builder, x, bld->int_vec_type, "");
- res = LLVMBuildLShr(bld->builder, x, lp_build_const_int_vec(type, mantissa), "");
- res = LLVMBuildAnd(bld->builder, res, lp_build_const_int_vec(type, 255), "");
- res = LLVMBuildSub(bld->builder, res, lp_build_const_int_vec(type, 127 - bias), "");
+ res = LLVMBuildLShr(bld->builder, x,
+ lp_build_const_int_vec(bld->gallivm, type, mantissa), "");
+ res = LLVMBuildAnd(bld->builder, res,
+ lp_build_const_int_vec(bld->gallivm, type, 255), "");
+ res = LLVMBuildSub(bld->builder, res,
+ lp_build_const_int_vec(bld->gallivm, type, 127 - bias), "");
return res;
}
@@ -2310,7 +2334,8 @@ lp_build_extract_mantissa(struct lp_build_context *bld,
{
const struct lp_type type = bld->type;
unsigned mantissa = lp_mantissa(type);
- LLVMValueRef mantmask = lp_build_const_int_vec(type, (1ULL << mantissa) - 1);
+ LLVMValueRef mantmask = lp_build_const_int_vec(bld->gallivm, type,
+ (1ULL << mantissa) - 1);
LLVMValueRef one = LLVMConstBitCast(bld->one, bld->int_vec_type);
LLVMValueRef res;
@@ -2375,11 +2400,11 @@ lp_build_log2_approx(struct lp_build_context *bld,
LLVMValueRef *p_log2)
{
const struct lp_type type = bld->type;
- LLVMTypeRef vec_type = lp_build_vec_type(type);
- LLVMTypeRef int_vec_type = lp_build_int_vec_type(type);
+ LLVMTypeRef vec_type = lp_build_vec_type(bld->gallivm, type);
+ LLVMTypeRef int_vec_type = lp_build_int_vec_type(bld->gallivm, type);
- LLVMValueRef expmask = lp_build_const_int_vec(type, 0x7f800000);
- LLVMValueRef mantmask = lp_build_const_int_vec(type, 0x007fffff);
+ LLVMValueRef expmask = lp_build_const_int_vec(bld->gallivm, type, 0x7f800000);
+ LLVMValueRef mantmask = lp_build_const_int_vec(bld->gallivm, type, 0x007fffff);
LLVMValueRef one = LLVMConstBitCast(bld->one, int_vec_type);
LLVMValueRef i = NULL;
@@ -2408,8 +2433,8 @@ lp_build_log2_approx(struct lp_build_context *bld,
}
if(p_floor_log2 || p_log2) {
- logexp = LLVMBuildLShr(bld->builder, exp, lp_build_const_int_vec(type, 23), "");
- logexp = LLVMBuildSub(bld->builder, logexp, lp_build_const_int_vec(type, 127), "");
+ logexp = LLVMBuildLShr(bld->builder, exp, lp_build_const_int_vec(bld->gallivm, type, 23), "");
+ logexp = LLVMBuildSub(bld->builder, logexp, lp_build_const_int_vec(bld->gallivm, type, 127), "");
logexp = LLVMBuildSIToFP(bld->builder, logexp, vec_type, "");
}
@@ -2493,7 +2518,7 @@ LLVMValueRef
lp_build_ilog2(struct lp_build_context *bld,
LLVMValueRef x)
{
- LLVMValueRef sqrt2 = lp_build_const_vec(bld->type, M_SQRT2);
+ LLVMValueRef sqrt2 = lp_build_const_vec(bld->gallivm, bld->type, M_SQRT2);
LLVMValueRef ipart;
assert(bld->type.floating);
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_assert.c b/src/gallium/auxiliary/gallivm/lp_bld_assert.c
index f2ebd868a8..9de5e8e7b5 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_assert.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_assert.c
@@ -56,20 +56,21 @@ lp_assert(int condition, const char *msg)
* \param msg a string to print if the assertion fails.
*/
LLVMValueRef
-lp_build_assert(LLVMBuilderRef builder, LLVMValueRef condition,
+lp_build_assert(struct gallivm_state *gallivm,
+ LLVMValueRef condition,
const char *msg)
{
- LLVMModuleRef module;
+ LLVMBuilderRef builder = gallivm->builder;
+ LLVMContextRef context = gallivm->context;
+ LLVMModuleRef module = gallivm->module;
LLVMTypeRef arg_types[2];
LLVMValueRef msg_string, assert_func, params[2], r;
- module = LLVMGetGlobalParent(LLVMGetBasicBlockParent(
- LLVMGetInsertBlock(builder)));
+ msg_string = lp_build_const_string_variable(module, context,
+ msg, strlen(msg) + 1);
- msg_string = lp_build_const_string_variable(module, msg, strlen(msg) + 1);
-
- arg_types[0] = LLVMInt32Type();
- arg_types[1] = LLVMPointerType(LLVMInt8Type(), 0);
+ arg_types[0] = LLVMInt32TypeInContext(context);
+ arg_types[1] = LLVMPointerType(LLVMInt8TypeInContext(context), 0);
/* lookup the lp_assert function */
assert_func = LLVMGetNamedFunction(module, "lp_assert");
@@ -77,12 +78,12 @@ lp_build_assert(LLVMBuilderRef builder, LLVMValueRef condition,
/* Create the assertion function if not found */
if (!assert_func) {
LLVMTypeRef func_type =
- LLVMFunctionType(LLVMVoidType(), arg_types, 2, 0);
+ LLVMFunctionType(LLVMVoidTypeInContext(context), arg_types, 2, 0);
assert_func = LLVMAddFunction(module, "lp_assert", func_type);
LLVMSetFunctionCallConv(assert_func, LLVMCCallConv);
LLVMSetLinkage(assert_func, LLVMExternalLinkage);
- LLVMAddGlobalMapping(lp_build_engine, assert_func,
+ LLVMAddGlobalMapping(gallivm->engine, assert_func,
func_to_pointer((func_pointer)lp_assert));
}
assert(assert_func);
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_assert.h b/src/gallium/auxiliary/gallivm/lp_bld_assert.h
index ddd879dc2c..1d2baab30a 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_assert.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_assert.h
@@ -30,10 +30,12 @@
#include "lp_bld.h"
+#include "lp_bld_init.h"
LLVMValueRef
-lp_build_assert(LLVMBuilderRef builder, LLVMValueRef condition,
+lp_build_assert(struct gallivm_state *gallivm,
+ LLVMValueRef condition,
const char *msg);
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_bitarit.c b/src/gallium/auxiliary/gallivm/lp_bld_bitarit.c
index 706479b4d5..fe7eeb61c4 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_bitarit.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_bitarit.c
@@ -169,7 +169,7 @@ lp_build_shr(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b)
LLVMValueRef
lp_build_shl_imm(struct lp_build_context *bld, LLVMValueRef a, unsigned imm)
{
- LLVMValueRef b = lp_build_const_int_vec(bld->type, imm);
+ LLVMValueRef b = lp_build_const_int_vec(bld->gallivm, bld->type, imm);
assert(imm <= bld->type.width);
return lp_build_shl(bld, a, b);
}
@@ -181,7 +181,7 @@ lp_build_shl_imm(struct lp_build_context *bld, LLVMValueRef a, unsigned imm)
LLVMValueRef
lp_build_shr_imm(struct lp_build_context *bld, LLVMValueRef a, unsigned imm)
{
- LLVMValueRef b = lp_build_const_int_vec(bld->type, imm);
+ LLVMValueRef b = lp_build_const_int_vec(bld->gallivm, bld->type, imm);
assert(imm <= bld->type.width);
return lp_build_shr(bld, a, b);
}
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_const.c b/src/gallium/auxiliary/gallivm/lp_bld_const.c
index dd839c0bea..6d8b7c26fc 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_const.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_const.c
@@ -39,6 +39,7 @@
#include "lp_bld_type.h"
#include "lp_bld_const.h"
+#include "lp_bld_init.h"
unsigned
@@ -211,31 +212,31 @@ lp_const_eps(struct lp_type type)
LLVMValueRef
-lp_build_undef(struct lp_type type)
+lp_build_undef(struct gallivm_state *gallivm, struct lp_type type)
{
- LLVMTypeRef vec_type = lp_build_vec_type(type);
+ LLVMTypeRef vec_type = lp_build_vec_type(gallivm, type);
return LLVMGetUndef(vec_type);
}
LLVMValueRef
-lp_build_zero(struct lp_type type)
+lp_build_zero(struct gallivm_state *gallivm, struct lp_type type)
{
if (type.length == 1) {
if (type.floating)
- return LLVMConstReal(LLVMFloatType(), 0.0);
+ return lp_build_const_float(gallivm, 0.0);
else
- return LLVMConstInt(LLVMIntType(type.width), 0, 0);
+ return LLVMConstInt(LLVMIntTypeInContext(gallivm->context, type.width), 0, 0);
}
else {
- LLVMTypeRef vec_type = lp_build_vec_type(type);
+ LLVMTypeRef vec_type = lp_build_vec_type(gallivm, type);
return LLVMConstNull(vec_type);
}
}
LLVMValueRef
-lp_build_one(struct lp_type type)
+lp_build_one(struct gallivm_state *gallivm, struct lp_type type)
{
LLVMTypeRef elem_type;
LLVMValueRef elems[LP_MAX_VECTOR_LENGTH];
@@ -243,7 +244,7 @@ lp_build_one(struct lp_type type)
assert(type.length <= LP_MAX_VECTOR_LENGTH);
- elem_type = lp_build_elem_type(type);
+ elem_type = lp_build_elem_type(gallivm, type);
if(type.floating)
elems[0] = LLVMConstReal(elem_type, 1.0);
@@ -283,10 +284,11 @@ lp_build_one(struct lp_type type)
* Build constant-valued element from a scalar value.
*/
LLVMValueRef
-lp_build_const_elem(struct lp_type type,
+lp_build_const_elem(struct gallivm_state *gallivm,
+ struct lp_type type,
double val)
{
- LLVMTypeRef elem_type = lp_build_elem_type(type);
+ LLVMTypeRef elem_type = lp_build_elem_type(gallivm, type);
LLVMValueRef elem;
if(type.floating) {
@@ -306,15 +308,15 @@ lp_build_const_elem(struct lp_type type,
* Build constant-valued vector from a scalar value.
*/
LLVMValueRef
-lp_build_const_vec(struct lp_type type,
+lp_build_const_vec(struct gallivm_state *gallivm, struct lp_type type,
double val)
{
if (type.length == 1) {
- return lp_build_const_elem(type, val);
+ return lp_build_const_elem(gallivm, type, val);
} else {
LLVMValueRef elems[LP_MAX_VECTOR_LENGTH];
unsigned i;
- elems[0] = lp_build_const_elem(type, val);
+ elems[0] = lp_build_const_elem(gallivm, type, val);
for(i = 1; i < type.length; ++i)
elems[i] = elems[0];
return LLVMConstVector(elems, type.length);
@@ -323,10 +325,10 @@ lp_build_const_vec(struct lp_type type,
LLVMValueRef
-lp_build_const_int_vec(struct lp_type type,
- long long val)
+lp_build_const_int_vec(struct gallivm_state *gallivm, struct lp_type type,
+ long long val)
{
- LLVMTypeRef elem_type = lp_build_int_elem_type(type);
+ LLVMTypeRef elem_type = lp_build_int_elem_type(gallivm, type);
LLVMValueRef elems[LP_MAX_VECTOR_LENGTH];
unsigned i;
@@ -343,7 +345,8 @@ lp_build_const_int_vec(struct lp_type type,
LLVMValueRef
-lp_build_const_aos(struct lp_type type,
+lp_build_const_aos(struct gallivm_state *gallivm,
+ struct lp_type type,
double r, double g, double b, double a,
const unsigned char *swizzle)
{
@@ -355,7 +358,7 @@ lp_build_const_aos(struct lp_type type,
assert(type.length % 4 == 0);
assert(type.length <= LP_MAX_VECTOR_LENGTH);
- elem_type = lp_build_elem_type(type);
+ elem_type = lp_build_elem_type(gallivm, type);
if(swizzle == NULL)
swizzle = default_swizzle;
@@ -386,10 +389,11 @@ lp_build_const_aos(struct lp_type type,
* @param mask TGSI_WRITEMASK_xxx
*/
LLVMValueRef
-lp_build_const_mask_aos(struct lp_type type,
+lp_build_const_mask_aos(struct gallivm_state *gallivm,
+ struct lp_type type,
unsigned mask)
{
- LLVMTypeRef elem_type = LLVMIntType(type.width);
+ LLVMTypeRef elem_type = LLVMIntTypeInContext(gallivm->context, type.width);
LLVMValueRef masks[LP_MAX_VECTOR_LENGTH];
unsigned i, j;
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_const.h b/src/gallium/auxiliary/gallivm/lp_bld_const.h
index 6b1fc590c1..c749a7a315 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_const.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_const.h
@@ -39,6 +39,7 @@
#include "pipe/p_compiler.h"
#include "gallivm/lp_bld.h"
+#include "gallivm/lp_bld_init.h"
@@ -73,46 +74,55 @@ lp_const_eps(struct lp_type type);
LLVMValueRef
-lp_build_undef(struct lp_type type);
+lp_build_undef(struct gallivm_state *gallivm, struct lp_type type);
LLVMValueRef
-lp_build_zero(struct lp_type type);
+lp_build_zero(struct gallivm_state *gallivm, struct lp_type type);
LLVMValueRef
-lp_build_one(struct lp_type type);
+lp_build_one(struct gallivm_state *gallivm, struct lp_type type);
LLVMValueRef
-lp_build_const_elem(struct lp_type type,
+lp_build_const_elem(struct gallivm_state *gallivm, struct lp_type type,
double val);
LLVMValueRef
-lp_build_const_vec(struct lp_type type, double val);
+lp_build_const_vec(struct gallivm_state *gallivm, struct lp_type type,
+ double val);
LLVMValueRef
-lp_build_const_int_vec(struct lp_type type, long long val);
+lp_build_const_int_vec(struct gallivm_state *gallivm,
+ struct lp_type type, long long val);
LLVMValueRef
-lp_build_const_aos(struct lp_type type,
+lp_build_const_aos(struct gallivm_state *gallivm, struct lp_type type,
double r, double g, double b, double a,
const unsigned char *swizzle);
LLVMValueRef
-lp_build_const_mask_aos(struct lp_type type,
+lp_build_const_mask_aos(struct gallivm_state *gallivm,
+ struct lp_type type,
unsigned mask);
static INLINE LLVMValueRef
-lp_build_const_int32(int i)
+lp_build_const_int32(struct gallivm_state *gallivm, int i)
{
- return LLVMConstInt(LLVMInt32Type(), i, 0);
+ return LLVMConstInt(LLVMInt32TypeInContext(gallivm->context), i, 0);
}
+static INLINE LLVMValueRef
+lp_build_const_float(struct gallivm_state *gallivm, float x)
+{
+ return LLVMConstReal(LLVMFloatTypeInContext(gallivm->context), x);
+}
+
#endif /* !LP_BLD_CONST_H */
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_conv.c b/src/gallium/auxiliary/gallivm/lp_bld_conv.c
index 6967dd2622..4797db22c5 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_conv.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_conv.c
@@ -89,12 +89,13 @@
* return { i32, i32, i32, i32 } where each value is in [0, 2^dst_width-1].
*/
LLVMValueRef
-lp_build_clamped_float_to_unsigned_norm(LLVMBuilderRef builder,
+lp_build_clamped_float_to_unsigned_norm(struct gallivm_state *gallivm,
struct lp_type src_type,
unsigned dst_width,
LLVMValueRef src)
{
- LLVMTypeRef int_vec_type = lp_build_int_vec_type(src_type);
+ LLVMBuilderRef builder = gallivm->builder;
+ LLVMTypeRef int_vec_type = lp_build_int_vec_type(gallivm, src_type);
LLVMValueRef res;
unsigned mantissa;
@@ -122,10 +123,11 @@ lp_build_clamped_float_to_unsigned_norm(LLVMBuilderRef builder,
scale = (double)mask/ubound;
bias = (double)(1ULL << (mantissa - dst_width));
- res = LLVMBuildFMul(builder, src, lp_build_const_vec(src_type, scale), "");
- res = LLVMBuildFAdd(builder, res, lp_build_const_vec(src_type, bias), "");
+ res = LLVMBuildFMul(builder, src, lp_build_const_vec(gallivm, src_type, scale), "");
+ res = LLVMBuildFAdd(builder, res, lp_build_const_vec(gallivm, src_type, bias), "");
res = LLVMBuildBitCast(builder, res, int_vec_type, "");
- res = LLVMBuildAnd(builder, res, lp_build_const_int_vec(src_type, mask), "");
+ res = LLVMBuildAnd(builder, res,
+ lp_build_const_int_vec(gallivm, src_type, mask), "");
}
else if (dst_width == (mantissa + 1)) {
/*
@@ -138,7 +140,8 @@ lp_build_clamped_float_to_unsigned_norm(LLVMBuilderRef builder,
scale = (double)((1ULL << dst_width) - 1);
- res = LLVMBuildFMul(builder, src, lp_build_const_vec(src_type, scale), "");
+ res = LLVMBuildFMul(builder, src,
+ lp_build_const_vec(gallivm, src_type, scale), "");
res = LLVMBuildFPToSI(builder, res, int_vec_type, "");
}
else {
@@ -166,7 +169,8 @@ lp_build_clamped_float_to_unsigned_norm(LLVMBuilderRef builder,
LLVMValueRef lshifted;
LLVMValueRef rshifted;
- res = LLVMBuildFMul(builder, src, lp_build_const_vec(src_type, scale), "");
+ res = LLVMBuildFMul(builder, src,
+ lp_build_const_vec(gallivm, src_type, scale), "");
res = LLVMBuildFPToSI(builder, res, int_vec_type, "");
/*
@@ -177,7 +181,8 @@ lp_build_clamped_float_to_unsigned_norm(LLVMBuilderRef builder,
*/
if (lshift) {
lshifted = LLVMBuildShl(builder, res,
- lp_build_const_int_vec(src_type, lshift), "");
+ lp_build_const_int_vec(gallivm, src_type,
+ lshift), "");
} else {
lshifted = res;
}
@@ -186,7 +191,8 @@ lp_build_clamped_float_to_unsigned_norm(LLVMBuilderRef builder,
* Align the most significant bit to the right.
*/
rshifted = LLVMBuildAShr(builder, res,
- lp_build_const_int_vec(src_type, rshift), "");
+ lp_build_const_int_vec(gallivm, src_type, rshift),
+ "");
/*
* Subtract the MSB to the LSB, therefore re-scaling from
@@ -206,13 +212,14 @@ lp_build_clamped_float_to_unsigned_norm(LLVMBuilderRef builder,
* return {float, float, float, float} with values in range [0, 1].
*/
LLVMValueRef
-lp_build_unsigned_norm_to_float(LLVMBuilderRef builder,
+lp_build_unsigned_norm_to_float(struct gallivm_state *gallivm,
unsigned src_width,
struct lp_type dst_type,
LLVMValueRef src)
{
- LLVMTypeRef vec_type = lp_build_vec_type(dst_type);
- LLVMTypeRef int_vec_type = lp_build_int_vec_type(dst_type);
+ LLVMBuilderRef builder = gallivm->builder;
+ LLVMTypeRef vec_type = lp_build_vec_type(gallivm, dst_type);
+ LLVMTypeRef int_vec_type = lp_build_int_vec_type(gallivm, dst_type);
LLVMValueRef bias_;
LLVMValueRef res;
unsigned mantissa;
@@ -230,7 +237,8 @@ lp_build_unsigned_norm_to_float(LLVMBuilderRef builder,
if (src_width == 8) {
scale = 1.0/255.0;
res = LLVMBuildSIToFP(builder, src, vec_type, "");
- res = LLVMBuildFMul(builder, res, lp_build_const_vec(dst_type, scale), "");
+ res = LLVMBuildFMul(builder, res,
+ lp_build_const_vec(gallivm, dst_type, scale), "");
return res;
}
@@ -247,10 +255,11 @@ lp_build_unsigned_norm_to_float(LLVMBuilderRef builder,
if(src_width > mantissa) {
int shift = src_width - mantissa;
- res = LLVMBuildLShr(builder, res, lp_build_const_int_vec(dst_type, shift), "");
+ res = LLVMBuildLShr(builder, res,
+ lp_build_const_int_vec(gallivm, dst_type, shift), "");
}
- bias_ = lp_build_const_vec(dst_type, bias);
+ bias_ = lp_build_const_vec(gallivm, dst_type, bias);
res = LLVMBuildOr(builder,
res,
@@ -259,7 +268,7 @@ lp_build_unsigned_norm_to_float(LLVMBuilderRef builder,
res = LLVMBuildBitCast(builder, res, vec_type, "");
res = LLVMBuildFSub(builder, res, bias_, "");
- res = LLVMBuildFMul(builder, res, lp_build_const_vec(dst_type, scale), "");
+ res = LLVMBuildFMul(builder, res, lp_build_const_vec(gallivm, dst_type, scale), "");
return res;
}
@@ -272,12 +281,13 @@ lp_build_unsigned_norm_to_float(LLVMBuilderRef builder,
* to the lp_type union.
*/
void
-lp_build_conv(LLVMBuilderRef builder,
+lp_build_conv(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
const LLVMValueRef *src, unsigned num_srcs,
LLVMValueRef *dst, unsigned num_dsts)
{
+ LLVMBuilderRef builder = gallivm->builder;
struct lp_type tmp_type;
LLVMValueRef tmp[LP_MAX_VECTOR_LENGTH];
unsigned num_tmps;
@@ -342,12 +352,12 @@ lp_build_conv(LLVMBuilderRef builder,
int32_type.length /= 4;
int32_type.sign = 1;
- src_vec_type = lp_build_vec_type(src_type);
- dst_vec_type = lp_build_vec_type(dst_type);
- int16_vec_type = lp_build_vec_type(int16_type);
- int32_vec_type = lp_build_vec_type(int32_type);
+ src_vec_type = lp_build_vec_type(gallivm, src_type);
+ dst_vec_type = lp_build_vec_type(gallivm, dst_type);
+ int16_vec_type = lp_build_vec_type(gallivm, int16_type);
+ int32_vec_type = lp_build_vec_type(gallivm, int32_type);
- const_255f = lp_build_const_vec(src_type, 255.0f);
+ const_255f = lp_build_const_vec(gallivm, src_type, 255.0f);
a = LLVMBuildFMul(builder, src[0], const_255f, "");
b = LLVMBuildFMul(builder, src[1], const_255f, "");
@@ -358,13 +368,14 @@ lp_build_conv(LLVMBuilderRef builder,
struct lp_build_context bld;
bld.builder = builder;
+ bld.gallivm = gallivm;
bld.type = src_type;
bld.vec_type = src_vec_type;
- bld.int_elem_type = lp_build_elem_type(int32_type);
+ bld.int_elem_type = lp_build_elem_type(gallivm, int32_type);
bld.int_vec_type = int32_vec_type;
- bld.undef = lp_build_undef(src_type);
- bld.zero = lp_build_zero(src_type);
- bld.one = lp_build_one(src_type);
+ bld.undef = lp_build_undef(gallivm, src_type);
+ bld.zero = lp_build_zero(gallivm, src_type);
+ bld.one = lp_build_one(gallivm, src_type);
src_int0 = lp_build_iround(&bld, a);
src_int1 = lp_build_iround(&bld, b);
@@ -372,9 +383,9 @@ lp_build_conv(LLVMBuilderRef builder,
src_int3 = lp_build_iround(&bld, d);
}
/* relying on clamping behavior of sse2 intrinsics here */
- lo = lp_build_pack2(builder, int32_type, int16_type, src_int0, src_int1);
- hi = lp_build_pack2(builder, int32_type, int16_type, src_int2, src_int3);
- dst[i] = lp_build_pack2(builder, int16_type, dst_type, lo, hi);
+ lo = lp_build_pack2(gallivm, int32_type, int16_type, src_int0, src_int1);
+ hi = lp_build_pack2(gallivm, int32_type, int16_type, src_int2, src_int3);
+ dst[i] = lp_build_pack2(gallivm, int16_type, dst_type, lo, hi);
}
return;
}
@@ -391,13 +402,13 @@ lp_build_conv(LLVMBuilderRef builder,
double dst_max = lp_const_max(dst_type);
LLVMValueRef thres;
- lp_build_context_init(&bld, builder, tmp_type);
+ lp_build_context_init(&bld, gallivm, tmp_type);
if(src_min < dst_min) {
if(dst_min == 0.0)
thres = bld.zero;
else
- thres = lp_build_const_vec(src_type, dst_min);
+ thres = lp_build_const_vec(gallivm, src_type, dst_min);
for(i = 0; i < num_tmps; ++i)
tmp[i] = lp_build_max(&bld, tmp[i], thres);
}
@@ -406,7 +417,7 @@ lp_build_conv(LLVMBuilderRef builder,
if(dst_max == 1.0)
thres = bld.one;
else
- thres = lp_build_const_vec(src_type, dst_max);
+ thres = lp_build_const_vec(gallivm, src_type, dst_max);
for(i = 0; i < num_tmps; ++i)
tmp[i] = lp_build_min(&bld, tmp[i], thres);
}
@@ -422,7 +433,7 @@ lp_build_conv(LLVMBuilderRef builder,
else if(tmp_type.floating) {
if(!dst_type.fixed && !dst_type.sign && dst_type.norm) {
for(i = 0; i < num_tmps; ++i) {
- tmp[i] = lp_build_clamped_float_to_unsigned_norm(builder,
+ tmp[i] = lp_build_clamped_float_to_unsigned_norm(gallivm,
tmp_type,
dst_type.width,
tmp[i]);
@@ -434,14 +445,14 @@ lp_build_conv(LLVMBuilderRef builder,
LLVMTypeRef tmp_vec_type;
if (dst_scale != 1.0) {
- LLVMValueRef scale = lp_build_const_vec(tmp_type, dst_scale);
+ LLVMValueRef scale = lp_build_const_vec(gallivm, tmp_type, dst_scale);
for(i = 0; i < num_tmps; ++i)
tmp[i] = LLVMBuildFMul(builder, tmp[i], scale, "");
}
/* Use an equally sized integer for intermediate computations */
tmp_type.floating = FALSE;
- tmp_vec_type = lp_build_vec_type(tmp_type);
+ tmp_vec_type = lp_build_vec_type(gallivm, tmp_type);
for(i = 0; i < num_tmps; ++i) {
#if 0
if(dst_type.sign)
@@ -461,7 +472,8 @@ lp_build_conv(LLVMBuilderRef builder,
/* FIXME: compensate different offsets too */
if(src_shift > dst_shift) {
- LLVMValueRef shift = lp_build_const_int_vec(tmp_type, src_shift - dst_shift);
+ LLVMValueRef shift = lp_build_const_int_vec(gallivm, tmp_type,
+ src_shift - dst_shift);
for(i = 0; i < num_tmps; ++i)
if(src_type.sign)
tmp[i] = LLVMBuildAShr(builder, tmp[i], shift, "");
@@ -485,7 +497,7 @@ lp_build_conv(LLVMBuilderRef builder,
new_type.width = dst_type.width;
new_type.length = dst_type.length;
- lp_build_resize(builder, tmp_type, new_type, tmp, num_srcs, tmp, num_dsts);
+ lp_build_resize(gallivm, tmp_type, new_type, tmp, num_srcs, tmp, num_dsts);
tmp_type = new_type;
num_tmps = num_dsts;
@@ -501,7 +513,7 @@ lp_build_conv(LLVMBuilderRef builder,
else if(!src_type.floating && dst_type.floating) {
if(!src_type.fixed && !src_type.sign && src_type.norm) {
for(i = 0; i < num_tmps; ++i) {
- tmp[i] = lp_build_unsigned_norm_to_float(builder,
+ tmp[i] = lp_build_unsigned_norm_to_float(gallivm,
src_type.width,
dst_type,
tmp[i]);
@@ -515,7 +527,7 @@ lp_build_conv(LLVMBuilderRef builder,
/* Use an equally sized integer for intermediate computations */
tmp_type.floating = TRUE;
tmp_type.sign = TRUE;
- tmp_vec_type = lp_build_vec_type(tmp_type);
+ tmp_vec_type = lp_build_vec_type(gallivm, tmp_type);
for(i = 0; i < num_tmps; ++i) {
#if 0
if(dst_type.sign)
@@ -529,7 +541,7 @@ lp_build_conv(LLVMBuilderRef builder,
}
if (src_scale != 1.0) {
- LLVMValueRef scale = lp_build_const_vec(tmp_type, 1.0/src_scale);
+ LLVMValueRef scale = lp_build_const_vec(gallivm, tmp_type, 1.0/src_scale);
for(i = 0; i < num_tmps; ++i)
tmp[i] = LLVMBuildFMul(builder, tmp[i], scale, "");
}
@@ -541,7 +553,7 @@ lp_build_conv(LLVMBuilderRef builder,
/* FIXME: compensate different offsets too */
if(src_shift < dst_shift) {
- LLVMValueRef shift = lp_build_const_int_vec(tmp_type, dst_shift - src_shift);
+ LLVMValueRef shift = lp_build_const_int_vec(gallivm, tmp_type, dst_shift - src_shift);
for(i = 0; i < num_tmps; ++i)
tmp[i] = LLVMBuildShl(builder, tmp[i], shift, "");
}
@@ -565,7 +577,7 @@ lp_build_conv(LLVMBuilderRef builder,
* This is basically a very trimmed down version of lp_build_conv.
*/
void
-lp_build_conv_mask(LLVMBuilderRef builder,
+lp_build_conv_mask(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
const LLVMValueRef *src, unsigned num_srcs,
@@ -599,11 +611,11 @@ lp_build_conv_mask(LLVMBuilderRef builder,
if(src_type.width > dst_type.width) {
assert(num_dsts == 1);
- dst[0] = lp_build_pack(builder, src_type, dst_type, TRUE, src, num_srcs);
+ dst[0] = lp_build_pack(gallivm, src_type, dst_type, TRUE, src, num_srcs);
}
else if(src_type.width < dst_type.width) {
assert(num_srcs == 1);
- lp_build_unpack(builder, src_type, dst_type, src[0], dst, num_dsts);
+ lp_build_unpack(gallivm, src_type, dst_type, src[0], dst, num_dsts);
}
else {
assert(num_srcs == num_dsts);
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_conv.h b/src/gallium/auxiliary/gallivm/lp_bld_conv.h
index 628831c3ad..cec655980f 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_conv.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_conv.h
@@ -44,27 +44,27 @@ struct lp_type;
LLVMValueRef
-lp_build_clamped_float_to_unsigned_norm(LLVMBuilderRef builder,
+lp_build_clamped_float_to_unsigned_norm(struct gallivm_state *gallivm,
struct lp_type src_type,
unsigned dst_width,
LLVMValueRef src);
LLVMValueRef
-lp_build_unsigned_norm_to_float(LLVMBuilderRef builder,
+lp_build_unsigned_norm_to_float(struct gallivm_state *gallivm,
unsigned src_width,
struct lp_type dst_type,
LLVMValueRef src);
void
-lp_build_conv(LLVMBuilderRef builder,
+lp_build_conv(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
const LLVMValueRef *srcs, unsigned num_srcs,
LLVMValueRef *dsts, unsigned num_dsts);
void
-lp_build_conv_mask(LLVMBuilderRef builder,
+lp_build_conv_mask(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
const LLVMValueRef *src, unsigned num_srcs,
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_debug.h b/src/gallium/auxiliary/gallivm/lp_bld_debug.h
index eb11dcd4ef..8a58f95b78 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_debug.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_debug.h
@@ -42,6 +42,7 @@
#define GALLIVM_DEBUG_NO_OPT (1 << 3)
#define GALLIVM_DEBUG_PERF (1 << 4)
#define GALLIVM_DEBUG_NO_BRILINEAR (1 << 5)
+#define GALLIVM_DEBUG_GC (1 << 6)
#ifdef DEBUG
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_flow.c b/src/gallium/auxiliary/gallivm/lp_bld_flow.c
index a2cee199a0..a9c9c7af10 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_flow.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_flow.c
@@ -34,6 +34,7 @@
#include "util/u_debug.h"
#include "util/u_memory.h"
+#include "lp_bld_init.h"
#include "lp_bld_type.h"
#include "lp_bld_flow.h"
@@ -51,25 +52,25 @@
* be used elsewhere.
*/
LLVMBasicBlockRef
-lp_build_insert_new_block(LLVMBuilderRef builder, const char *name)
+lp_build_insert_new_block(struct gallivm_state *gallivm, const char *name)
{
LLVMBasicBlockRef current_block;
LLVMBasicBlockRef next_block;
LLVMBasicBlockRef new_block;
/* get current basic block */
- current_block = LLVMGetInsertBlock(builder);
+ current_block = LLVMGetInsertBlock(gallivm->builder);
/* check if there's another block after this one */
next_block = LLVMGetNextBasicBlock(current_block);
if (next_block) {
/* insert the new block before the next block */
- new_block = LLVMInsertBasicBlock(next_block, name);
+ new_block = LLVMInsertBasicBlockInContext(gallivm->context, next_block, name);
}
else {
/* append new block after current block */
LLVMValueRef function = LLVMGetBasicBlockParent(current_block);
- new_block = LLVMAppendBasicBlock(function, name);
+ new_block = LLVMAppendBasicBlockInContext(gallivm->context, function, name);
}
return new_block;
@@ -82,12 +83,11 @@ lp_build_insert_new_block(LLVMBuilderRef builder, const char *name)
*/
void
lp_build_flow_skip_begin(struct lp_build_skip_context *skip,
- LLVMBuilderRef builder)
+ struct gallivm_state *gallivm)
{
- skip->builder = builder;
-
+ skip->gallivm = gallivm;
/* create new basic block */
- skip->block = lp_build_insert_new_block(skip->builder, "skip");
+ skip->block = lp_build_insert_new_block(gallivm, "skip");
}
@@ -101,12 +101,12 @@ lp_build_flow_skip_cond_break(struct lp_build_skip_context *skip,
{
LLVMBasicBlockRef new_block;
- new_block = lp_build_insert_new_block(skip->builder, "");
+ new_block = lp_build_insert_new_block(skip->gallivm, "");
/* if cond is true, goto skip->block, else goto new_block */
- LLVMBuildCondBr(skip->builder, cond, skip->block, new_block);
+ LLVMBuildCondBr(skip->gallivm->builder, cond, skip->block, new_block);
- LLVMPositionBuilderAtEnd(skip->builder, new_block);
+ LLVMPositionBuilderAtEnd(skip->gallivm->builder, new_block);
}
@@ -114,8 +114,8 @@ void
lp_build_flow_skip_end(struct lp_build_skip_context *skip)
{
/* goto block */
- LLVMBuildBr(skip->builder, skip->block);
- LLVMPositionBuilderAtEnd(skip->builder, skip->block);
+ LLVMBuildBr(skip->gallivm->builder, skip->block);
+ LLVMPositionBuilderAtEnd(skip->gallivm->builder, skip->block);
}
@@ -125,7 +125,7 @@ lp_build_flow_skip_end(struct lp_build_skip_context *skip)
void
lp_build_mask_check(struct lp_build_mask_context *mask)
{
- LLVMBuilderRef builder = mask->skip.builder;
+ LLVMBuilderRef builder = mask->skip.gallivm->builder;
LLVMValueRef value;
LLVMValueRef cond;
@@ -152,27 +152,27 @@ lp_build_mask_check(struct lp_build_mask_context *mask)
*/
void
lp_build_mask_begin(struct lp_build_mask_context *mask,
- LLVMBuilderRef builder,
+ struct gallivm_state *gallivm,
struct lp_type type,
LLVMValueRef value)
{
memset(mask, 0, sizeof *mask);
- mask->reg_type = LLVMIntType(type.width * type.length);
- mask->var = lp_build_alloca(builder,
- lp_build_int_vec_type(type),
+ mask->reg_type = LLVMIntTypeInContext(gallivm->context, type.width * type.length);
+ mask->var = lp_build_alloca(gallivm,
+ lp_build_int_vec_type(gallivm, type),
"execution_mask");
- LLVMBuildStore(builder, value, mask->var);
+ LLVMBuildStore(gallivm->builder, value, mask->var);
- lp_build_flow_skip_begin(&mask->skip, builder);
+ lp_build_flow_skip_begin(&mask->skip, gallivm);
}
LLVMValueRef
lp_build_mask_value(struct lp_build_mask_context *mask)
{
- return LLVMBuildLoad(mask->skip.builder, mask->var, "");
+ return LLVMBuildLoad(mask->skip.gallivm->builder, mask->var, "");
}
@@ -185,10 +185,10 @@ void
lp_build_mask_update(struct lp_build_mask_context *mask,
LLVMValueRef value)
{
- value = LLVMBuildAnd(mask->skip.builder,
+ value = LLVMBuildAnd(mask->skip.gallivm->builder,
lp_build_mask_value(mask),
value, "");
- LLVMBuildStore(mask->skip.builder, value, mask->var);
+ LLVMBuildStore(mask->skip.gallivm->builder, value, mask->var);
}
@@ -205,13 +205,17 @@ lp_build_mask_end(struct lp_build_mask_context *mask)
void
-lp_build_loop_begin(LLVMBuilderRef builder,
- LLVMValueRef start,
- struct lp_build_loop_state *state)
+lp_build_loop_begin(struct lp_build_loop_state *state,
+ struct gallivm_state *gallivm,
+ LLVMValueRef start)
+
{
- state->block = lp_build_insert_new_block(builder, "loop_begin");
+ LLVMBuilderRef builder = gallivm->builder;
+
+ state->block = lp_build_insert_new_block(gallivm, "loop_begin");
- state->counter_var = lp_build_alloca(builder, LLVMTypeOf(start), "loop_counter");
+ state->counter_var = lp_build_alloca(gallivm, LLVMTypeOf(start), "loop_counter");
+ state->gallivm = gallivm;
LLVMBuildStore(builder, start, state->counter_var);
@@ -224,12 +228,12 @@ lp_build_loop_begin(LLVMBuilderRef builder,
void
-lp_build_loop_end_cond(LLVMBuilderRef builder,
+lp_build_loop_end_cond(struct lp_build_loop_state *state,
LLVMValueRef end,
LLVMValueRef step,
- LLVMIntPredicate llvm_cond,
- struct lp_build_loop_state *state)
+ LLVMIntPredicate llvm_cond)
{
+ LLVMBuilderRef builder = state->gallivm->builder;
LLVMValueRef next;
LLVMValueRef cond;
LLVMBasicBlockRef after_block;
@@ -243,7 +247,7 @@ lp_build_loop_end_cond(LLVMBuilderRef builder,
cond = LLVMBuildICmp(builder, llvm_cond, next, end, "");
- after_block = lp_build_insert_new_block(builder, "loop_end");
+ after_block = lp_build_insert_new_block(state->gallivm, "loop_end");
LLVMBuildCondBr(builder, cond, after_block, state->block);
@@ -254,12 +258,11 @@ lp_build_loop_end_cond(LLVMBuilderRef builder,
void
-lp_build_loop_end(LLVMBuilderRef builder,
+lp_build_loop_end(struct lp_build_loop_state *state,
LLVMValueRef end,
- LLVMValueRef step,
- struct lp_build_loop_state *state)
+ LLVMValueRef step)
{
- lp_build_loop_end_cond(builder, end, step, LLVMIntNE, state);
+ lp_build_loop_end_cond(state, end, step, LLVMIntNE);
}
@@ -296,24 +299,27 @@ lp_build_loop_end(LLVMBuilderRef builder,
*/
void
lp_build_if(struct lp_build_if_state *ifthen,
- LLVMBuilderRef builder,
+ struct gallivm_state *gallivm,
LLVMValueRef condition)
{
- LLVMBasicBlockRef block = LLVMGetInsertBlock(builder);
+ LLVMBasicBlockRef block = LLVMGetInsertBlock(gallivm->builder);
memset(ifthen, 0, sizeof *ifthen);
- ifthen->builder = builder;
+ ifthen->gallivm = gallivm;
ifthen->condition = condition;
ifthen->entry_block = block;
/* create endif/merge basic block for the phi functions */
- ifthen->merge_block = lp_build_insert_new_block(builder, "endif-block");
+ ifthen->merge_block = lp_build_insert_new_block(gallivm, "endif-block");
/* create/insert true_block before merge_block */
- ifthen->true_block = LLVMInsertBasicBlock(ifthen->merge_block, "if-true-block");
+ ifthen->true_block =
+ LLVMInsertBasicBlockInContext(gallivm->context,
+ ifthen->merge_block,
+ "if-true-block");
/* successive code goes into the true block */
- LLVMPositionBuilderAtEnd(builder, ifthen->true_block);
+ LLVMPositionBuilderAtEnd(gallivm->builder, ifthen->true_block);
}
@@ -323,14 +329,19 @@ lp_build_if(struct lp_build_if_state *ifthen,
void
lp_build_else(struct lp_build_if_state *ifthen)
{
+ LLVMBuilderRef builder = ifthen->gallivm->builder;
+
/* Append an unconditional Br(anch) instruction on the true_block */
- LLVMBuildBr(ifthen->builder, ifthen->merge_block);
+ LLVMBuildBr(builder, ifthen->merge_block);
/* create/insert false_block before the merge block */
- ifthen->false_block = LLVMInsertBasicBlock(ifthen->merge_block, "if-false-block");
+ ifthen->false_block =
+ LLVMInsertBasicBlockInContext(ifthen->gallivm->context,
+ ifthen->merge_block,
+ "if-false-block");
/* successive code goes into the else block */
- LLVMPositionBuilderAtEnd(ifthen->builder, ifthen->false_block);
+ LLVMPositionBuilderAtEnd(builder, ifthen->false_block);
}
@@ -340,28 +351,30 @@ lp_build_else(struct lp_build_if_state *ifthen)
void
lp_build_endif(struct lp_build_if_state *ifthen)
{
+ LLVMBuilderRef builder = ifthen->gallivm->builder;
+
/* Insert branch to the merge block from current block */
- LLVMBuildBr(ifthen->builder, ifthen->merge_block);
+ LLVMBuildBr(builder, ifthen->merge_block);
/*
* Now patch in the various branch instructions.
*/
/* Insert the conditional branch instruction at the end of entry_block */
- LLVMPositionBuilderAtEnd(ifthen->builder, ifthen->entry_block);
+ LLVMPositionBuilderAtEnd(builder, ifthen->entry_block);
if (ifthen->false_block) {
/* we have an else clause */
- LLVMBuildCondBr(ifthen->builder, ifthen->condition,
+ LLVMBuildCondBr(builder, ifthen->condition,
ifthen->true_block, ifthen->false_block);
}
else {
/* no else clause */
- LLVMBuildCondBr(ifthen->builder, ifthen->condition,
+ LLVMBuildCondBr(builder, ifthen->condition,
ifthen->true_block, ifthen->merge_block);
}
/* Resume building code at end of the ifthen->merge_block */
- LLVMPositionBuilderAtEnd(ifthen->builder, ifthen->merge_block);
+ LLVMPositionBuilderAtEnd(builder, ifthen->merge_block);
}
@@ -381,15 +394,16 @@ lp_build_endif(struct lp_build_if_state *ifthen)
* - http://www.llvm.org/docs/tutorial/OCamlLangImpl7.html#memory
*/
LLVMValueRef
-lp_build_alloca(LLVMBuilderRef builder,
+lp_build_alloca(struct gallivm_state *gallivm,
LLVMTypeRef type,
const char *name)
{
+ LLVMBuilderRef builder = gallivm->builder;
LLVMBasicBlockRef current_block = LLVMGetInsertBlock(builder);
LLVMValueRef function = LLVMGetBasicBlockParent(current_block);
LLVMBasicBlockRef first_block = LLVMGetEntryBasicBlock(function);
LLVMValueRef first_instr = LLVMGetFirstInstruction(first_block);
- LLVMBuilderRef first_builder = LLVMCreateBuilder();
+ LLVMBuilderRef first_builder = LLVMCreateBuilderInContext(gallivm->context);
LLVMValueRef res;
if (first_instr) {
@@ -422,16 +436,17 @@ lp_build_alloca(LLVMBuilderRef builder,
* - http://www.llvm.org/docs/tutorial/OCamlLangImpl7.html#memory
*/
LLVMValueRef
-lp_build_array_alloca(LLVMBuilderRef builder,
+lp_build_array_alloca(struct gallivm_state *gallivm,
LLVMTypeRef type,
LLVMValueRef count,
const char *name)
{
+ LLVMBuilderRef builder = gallivm->builder;
LLVMBasicBlockRef current_block = LLVMGetInsertBlock(builder);
LLVMValueRef function = LLVMGetBasicBlockParent(current_block);
LLVMBasicBlockRef first_block = LLVMGetEntryBasicBlock(function);
LLVMValueRef first_instr = LLVMGetFirstInstruction(first_block);
- LLVMBuilderRef first_builder = LLVMCreateBuilder();
+ LLVMBuilderRef first_builder = LLVMCreateBuilderInContext(gallivm->context);
LLVMValueRef res;
if (first_instr) {
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_flow.h b/src/gallium/auxiliary/gallivm/lp_bld_flow.h
index e729ee6eaa..3cd5a9f42a 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_flow.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_flow.h
@@ -47,7 +47,7 @@ struct lp_type;
*/
struct lp_build_skip_context
{
- LLVMBuilderRef builder;
+ struct gallivm_state *gallivm;
/** Block to skip to */
LLVMBasicBlockRef block;
@@ -55,7 +55,7 @@ struct lp_build_skip_context
void
lp_build_flow_skip_begin(struct lp_build_skip_context *ctx,
- LLVMBuilderRef builder);
+ struct gallivm_state *gallivm);
void
lp_build_flow_skip_cond_break(struct lp_build_skip_context *ctx,
@@ -77,7 +77,7 @@ struct lp_build_mask_context
void
lp_build_mask_begin(struct lp_build_mask_context *mask,
- LLVMBuilderRef builder,
+ struct gallivm_state *gallivm,
struct lp_type type,
LLVMValueRef value);
@@ -107,31 +107,28 @@ lp_build_mask_end(struct lp_build_mask_context *mask);
*/
struct lp_build_loop_state
{
- LLVMBasicBlockRef block;
- LLVMValueRef counter_var;
- LLVMValueRef counter;
+ LLVMBasicBlockRef block;
+ LLVMValueRef counter_var;
+ LLVMValueRef counter;
+ struct gallivm_state *gallivm;
};
void
-lp_build_loop_begin(LLVMBuilderRef builder,
- LLVMValueRef start,
- struct lp_build_loop_state *state);
-
+lp_build_loop_begin(struct lp_build_loop_state *state,
+ struct gallivm_state *gallivm,
+ LLVMValueRef start);
void
-lp_build_loop_end(LLVMBuilderRef builder,
+lp_build_loop_end(struct lp_build_loop_state *state,
LLVMValueRef end,
- LLVMValueRef step,
- struct lp_build_loop_state *state);
+ LLVMValueRef step);
void
-lp_build_loop_end_cond(LLVMBuilderRef builder,
+lp_build_loop_end_cond(struct lp_build_loop_state *state,
LLVMValueRef end,
LLVMValueRef step,
- LLVMIntPredicate cond,
- struct lp_build_loop_state *state);
-
+ LLVMIntPredicate cond);
@@ -140,7 +137,7 @@ lp_build_loop_end_cond(LLVMBuilderRef builder,
*/
struct lp_build_if_state
{
- LLVMBuilderRef builder;
+ struct gallivm_state *gallivm;
LLVMValueRef condition;
LLVMBasicBlockRef entry_block;
LLVMBasicBlockRef true_block;
@@ -151,7 +148,7 @@ struct lp_build_if_state
void
lp_build_if(struct lp_build_if_state *ctx,
- LLVMBuilderRef builder,
+ struct gallivm_state *gallivm,
LLVMValueRef condition);
void
@@ -161,15 +158,15 @@ void
lp_build_endif(struct lp_build_if_state *ctx);
LLVMBasicBlockRef
-lp_build_insert_new_block(LLVMBuilderRef builder, const char *name);
+lp_build_insert_new_block(struct gallivm_state *gallivm, const char *name);
LLVMValueRef
-lp_build_alloca(LLVMBuilderRef builder,
+lp_build_alloca(struct gallivm_state *gallivm,
LLVMTypeRef type,
const char *name);
LLVMValueRef
-lp_build_array_alloca(LLVMBuilderRef builder,
+lp_build_array_alloca(struct gallivm_state *gallivm,
LLVMTypeRef type,
LLVMValueRef count,
const char *name);
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_format.h b/src/gallium/auxiliary/gallivm/lp_bld_format.h
index 60e22d727a..04142d905b 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_format.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_format.h
@@ -35,6 +35,7 @@
*/
#include "gallivm/lp_bld.h"
+#include "gallivm/lp_bld_init.h"
#include "pipe/p_format.h"
@@ -53,12 +54,12 @@ lp_build_format_swizzle_aos(const struct util_format_description *desc,
LLVMValueRef unswizzled);
LLVMValueRef
-lp_build_pack_rgba_aos(LLVMBuilderRef builder,
+lp_build_pack_rgba_aos(struct gallivm_state *gallivm,
const struct util_format_description *desc,
LLVMValueRef rgba);
LLVMValueRef
-lp_build_fetch_rgba_aos(LLVMBuilderRef builder,
+lp_build_fetch_rgba_aos(struct gallivm_state *gallivm,
const struct util_format_description *format_desc,
struct lp_type type,
LLVMValueRef base_ptr,
@@ -78,20 +79,20 @@ lp_build_format_swizzle_soa(const struct util_format_description *format_desc,
LLVMValueRef swizzled_out[4]);
void
-lp_build_unpack_rgba_soa(LLVMBuilderRef builder,
+lp_build_unpack_rgba_soa(struct gallivm_state *gallivm,
const struct util_format_description *format_desc,
struct lp_type type,
LLVMValueRef packed,
LLVMValueRef rgba_out[4]);
void
-lp_build_rgba8_to_f32_soa(LLVMBuilderRef builder,
+lp_build_rgba8_to_f32_soa(struct gallivm_state *gallivm,
struct lp_type dst_type,
LLVMValueRef packed,
LLVMValueRef *rgba);
void
-lp_build_fetch_rgba_soa(LLVMBuilderRef builder,
+lp_build_fetch_rgba_soa(struct gallivm_state *gallivm,
const struct util_format_description *format_desc,
struct lp_type type,
LLVMValueRef base_ptr,
@@ -106,7 +107,7 @@ lp_build_fetch_rgba_soa(LLVMBuilderRef builder,
LLVMValueRef
-lp_build_fetch_subsampled_rgba_aos(LLVMBuilderRef builder,
+lp_build_fetch_subsampled_rgba_aos(struct gallivm_state *gallivm,
const struct util_format_description *format_desc,
unsigned n,
LLVMValueRef base_ptr,
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_format_aos.c b/src/gallium/auxiliary/gallivm/lp_bld_format_aos.c
index 6b9189e1da..75d2e666f0 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_format_aos.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_format_aos.c
@@ -145,10 +145,11 @@ format_matches_type(const struct util_format_description *desc,
* @return RGBA in a float[4] or ubyte[4] or ushort[4] vector.
*/
static INLINE LLVMValueRef
-lp_build_unpack_arith_rgba_aos(LLVMBuilderRef builder,
+lp_build_unpack_arith_rgba_aos(struct gallivm_state *gallivm,
const struct util_format_description *desc,
LLVMValueRef packed)
{
+ LLVMBuilderRef builder = gallivm->builder;
LLVMValueRef shifted, casted, scaled, masked;
LLVMValueRef shifts[4];
LLVMValueRef masks[4];
@@ -167,21 +168,21 @@ lp_build_unpack_arith_rgba_aos(LLVMBuilderRef builder,
/* Do the intermediate integer computations with 32bit integers since it
* matches floating point size */
- assert (LLVMTypeOf(packed) == LLVMInt32Type());
+ assert (LLVMTypeOf(packed) == LLVMInt32TypeInContext(gallivm->context));
/* Broadcast the packed value to all four channels
* before: packed = BGRA
* after: packed = {BGRA, BGRA, BGRA, BGRA}
*/
packed = LLVMBuildInsertElement(builder,
- LLVMGetUndef(LLVMVectorType(LLVMInt32Type(), 4)),
+ LLVMGetUndef(LLVMVectorType(LLVMInt32TypeInContext(gallivm->context), 4)),
packed,
- LLVMConstNull(LLVMInt32Type()),
+ LLVMConstNull(LLVMInt32TypeInContext(gallivm->context)),
"");
packed = LLVMBuildShuffleVector(builder,
packed,
- LLVMGetUndef(LLVMVectorType(LLVMInt32Type(), 4)),
- LLVMConstNull(LLVMVectorType(LLVMInt32Type(), 4)),
+ LLVMGetUndef(LLVMVectorType(LLVMInt32TypeInContext(gallivm->context), 4)),
+ LLVMConstNull(LLVMVectorType(LLVMInt32TypeInContext(gallivm->context), 4)),
"");
/* Initialize vector constants */
@@ -194,9 +195,9 @@ lp_build_unpack_arith_rgba_aos(LLVMBuilderRef builder,
unsigned bits = desc->channel[i].size;
if (desc->channel[i].type == UTIL_FORMAT_TYPE_VOID) {
- shifts[i] = LLVMGetUndef(LLVMInt32Type());
- masks[i] = LLVMConstNull(LLVMInt32Type());
- scales[i] = LLVMConstNull(LLVMFloatType());
+ shifts[i] = LLVMGetUndef(LLVMInt32TypeInContext(gallivm->context));
+ masks[i] = LLVMConstNull(LLVMInt32TypeInContext(gallivm->context));
+ scales[i] = LLVMConstNull(LLVMFloatTypeInContext(gallivm->context));
}
else {
unsigned long long mask = (1ULL << bits) - 1;
@@ -207,15 +208,15 @@ lp_build_unpack_arith_rgba_aos(LLVMBuilderRef builder,
needs_uitofp = TRUE;
}
- shifts[i] = LLVMConstInt(LLVMInt32Type(), shift, 0);
- masks[i] = LLVMConstInt(LLVMInt32Type(), mask, 0);
+ shifts[i] = lp_build_const_int32(gallivm, shift);
+ masks[i] = lp_build_const_int32(gallivm, mask);
if (desc->channel[i].normalized) {
- scales[i] = LLVMConstReal(LLVMFloatType(), 1.0/mask);
+ scales[i] = lp_build_const_float(gallivm, 1.0 / mask);
normalized = TRUE;
}
else
- scales[i] = LLVMConstReal(LLVMFloatType(), 1.0);
+ scales[i] = lp_build_const_float(gallivm, 1.0);
}
shift += bits;
@@ -230,9 +231,9 @@ lp_build_unpack_arith_rgba_aos(LLVMBuilderRef builder,
if (!needs_uitofp) {
/* UIToFP can't be expressed in SSE2 */
- casted = LLVMBuildSIToFP(builder, masked, LLVMVectorType(LLVMFloatType(), 4), "");
+ casted = LLVMBuildSIToFP(builder, masked, LLVMVectorType(LLVMFloatTypeInContext(gallivm->context), 4), "");
} else {
- casted = LLVMBuildUIToFP(builder, masked, LLVMVectorType(LLVMFloatType(), 4), "");
+ casted = LLVMBuildUIToFP(builder, masked, LLVMVectorType(LLVMFloatTypeInContext(gallivm->context), 4), "");
}
/* At this point 'casted' may be a vector of floats such as
@@ -258,10 +259,11 @@ lp_build_unpack_arith_rgba_aos(LLVMBuilderRef builder,
* a time is rarely if ever needed.
*/
LLVMValueRef
-lp_build_pack_rgba_aos(LLVMBuilderRef builder,
+lp_build_pack_rgba_aos(struct gallivm_state *gallivm,
const struct util_format_description *desc,
LLVMValueRef rgba)
{
+ LLVMBuilderRef builder = gallivm->builder;
LLVMTypeRef type;
LLVMValueRef packed = NULL;
LLVMValueRef swizzles[4];
@@ -276,7 +278,7 @@ lp_build_pack_rgba_aos(LLVMBuilderRef builder,
assert(desc->block.width == 1);
assert(desc->block.height == 1);
- type = LLVMIntType(desc->block.bits);
+ type = LLVMIntTypeInContext(gallivm->context, desc->block.bits);
/* Unswizzle the color components into the source vector. */
for (i = 0; i < 4; ++i) {
@@ -285,13 +287,13 @@ lp_build_pack_rgba_aos(LLVMBuilderRef builder,
break;
}
if (j < 4)
- swizzles[i] = LLVMConstInt(LLVMInt32Type(), j, 0);
+ swizzles[i] = lp_build_const_int32(gallivm, j);
else
- swizzles[i] = LLVMGetUndef(LLVMInt32Type());
+ swizzles[i] = LLVMGetUndef(LLVMInt32TypeInContext(gallivm->context));
}
unswizzled = LLVMBuildShuffleVector(builder, rgba,
- LLVMGetUndef(LLVMVectorType(LLVMFloatType(), 4)),
+ LLVMGetUndef(LLVMVectorType(LLVMFloatTypeInContext(gallivm->context), 4)),
LLVMConstVector(swizzles, 4), "");
normalized = FALSE;
@@ -300,8 +302,8 @@ lp_build_pack_rgba_aos(LLVMBuilderRef builder,
unsigned bits = desc->channel[i].size;
if (desc->channel[i].type == UTIL_FORMAT_TYPE_VOID) {
- shifts[i] = LLVMGetUndef(LLVMInt32Type());
- scales[i] = LLVMGetUndef(LLVMFloatType());
+ shifts[i] = LLVMGetUndef(LLVMInt32TypeInContext(gallivm->context));
+ scales[i] = LLVMGetUndef(LLVMFloatTypeInContext(gallivm->context));
}
else {
unsigned mask = (1 << bits) - 1;
@@ -309,14 +311,14 @@ lp_build_pack_rgba_aos(LLVMBuilderRef builder,
assert(desc->channel[i].type == UTIL_FORMAT_TYPE_UNSIGNED);
assert(bits < 32);
- shifts[i] = LLVMConstInt(LLVMInt32Type(), shift, 0);
+ shifts[i] = lp_build_const_int32(gallivm, shift);
if (desc->channel[i].normalized) {
- scales[i] = LLVMConstReal(LLVMFloatType(), mask);
+ scales[i] = lp_build_const_float(gallivm, mask);
normalized = TRUE;
}
else
- scales[i] = LLVMConstReal(LLVMFloatType(), 1.0);
+ scales[i] = lp_build_const_float(gallivm, 1.0);
}
shift += bits;
@@ -327,14 +329,15 @@ lp_build_pack_rgba_aos(LLVMBuilderRef builder,
else
scaled = unswizzled;
- casted = LLVMBuildFPToSI(builder, scaled, LLVMVectorType(LLVMInt32Type(), 4), "");
+ casted = LLVMBuildFPToSI(builder, scaled, LLVMVectorType(LLVMInt32TypeInContext(gallivm->context), 4), "");
shifted = LLVMBuildShl(builder, casted, LLVMConstVector(shifts, 4), "");
/* Bitwise or all components */
for (i = 0; i < 4; ++i) {
if (desc->channel[i].type == UTIL_FORMAT_TYPE_UNSIGNED) {
- LLVMValueRef component = LLVMBuildExtractElement(builder, shifted, LLVMConstInt(LLVMInt32Type(), i, 0), "");
+ LLVMValueRef component = LLVMBuildExtractElement(builder, shifted,
+ lp_build_const_int32(gallivm, i), "");
if (packed)
packed = LLVMBuildOr(builder, packed, component, "");
else
@@ -343,7 +346,7 @@ lp_build_pack_rgba_aos(LLVMBuilderRef builder,
}
if (!packed)
- packed = LLVMGetUndef(LLVMInt32Type());
+ packed = LLVMGetUndef(LLVMInt32TypeInContext(gallivm->context));
if (desc->block.bits < 32)
packed = LLVMBuildTrunc(builder, packed, type, "");
@@ -364,7 +367,7 @@ lp_build_pack_rgba_aos(LLVMBuilderRef builder,
* \return a 4 element vector with the pixel's RGBA values.
*/
LLVMValueRef
-lp_build_fetch_rgba_aos(LLVMBuilderRef builder,
+lp_build_fetch_rgba_aos(struct gallivm_state *gallivm,
const struct util_format_description *format_desc,
struct lp_type type,
LLVMValueRef base_ptr,
@@ -372,13 +375,14 @@ lp_build_fetch_rgba_aos(LLVMBuilderRef builder,
LLVMValueRef i,
LLVMValueRef j)
{
+ LLVMBuilderRef builder = gallivm->builder;
unsigned num_pixels = type.length / 4;
struct lp_build_context bld;
assert(type.length <= LP_MAX_VECTOR_LENGTH);
assert(type.length % 4 == 0);
- lp_build_context_init(&bld, builder, type);
+ lp_build_context_init(&bld, gallivm, type);
/*
* Trivial case
@@ -397,13 +401,14 @@ lp_build_fetch_rgba_aos(LLVMBuilderRef builder,
* scaling or converting.
*/
- packed = lp_build_gather(builder, type.length/4,
+ packed = lp_build_gather(gallivm, type.length/4,
format_desc->block.bits, type.width*4,
base_ptr, offset);
assert(format_desc->block.bits <= type.width * type.length);
- packed = LLVMBuildBitCast(builder, packed, lp_build_vec_type(type), "");
+ packed = LLVMBuildBitCast(gallivm->builder, packed,
+ lp_build_vec_type(gallivm, type), "");
return lp_build_format_swizzle_aos(format_desc, &bld, packed);
}
@@ -435,11 +440,12 @@ lp_build_fetch_rgba_aos(LLVMBuilderRef builder,
for (k = 0; k < num_pixels; ++k) {
LLVMValueRef packed;
- packed = lp_build_gather_elem(builder, num_pixels,
+ packed = lp_build_gather_elem(gallivm, num_pixels,
format_desc->block.bits, 32,
base_ptr, offset, k);
- tmps[k] = lp_build_unpack_arith_rgba_aos(builder, format_desc,
+ tmps[k] = lp_build_unpack_arith_rgba_aos(gallivm,
+ format_desc,
packed);
}
@@ -455,7 +461,7 @@ lp_build_fetch_rgba_aos(LLVMBuilderRef builder,
__FUNCTION__, format_desc->short_name);
}
- lp_build_conv(builder,
+ lp_build_conv(gallivm,
lp_float32_vec4_type(),
type,
tmps, num_pixels, &res, 1);
@@ -476,14 +482,14 @@ lp_build_fetch_rgba_aos(LLVMBuilderRef builder,
tmp_type.length = num_pixels * 4;
tmp_type.norm = TRUE;
- tmp = lp_build_fetch_subsampled_rgba_aos(builder,
+ tmp = lp_build_fetch_subsampled_rgba_aos(gallivm,
format_desc,
num_pixels,
base_ptr,
offset,
i, j);
- lp_build_conv(builder,
+ lp_build_conv(gallivm,
tmp_type, type,
&tmp, 1, &tmp, 1);
@@ -505,11 +511,11 @@ lp_build_fetch_rgba_aos(LLVMBuilderRef builder,
* or incentive to optimize.
*/
- LLVMModuleRef module = LLVMGetGlobalParent(LLVMGetBasicBlockParent(LLVMGetInsertBlock(builder)));
+ LLVMModuleRef module = LLVMGetGlobalParent(LLVMGetBasicBlockParent(LLVMGetInsertBlock(gallivm->builder)));
char name[256];
- LLVMTypeRef i8t = LLVMInt8Type();
+ LLVMTypeRef i8t = LLVMInt8TypeInContext(gallivm->context);
LLVMTypeRef pi8t = LLVMPointerType(i8t, 0);
- LLVMTypeRef i32t = LLVMInt32Type();
+ LLVMTypeRef i32t = LLVMInt32TypeInContext(gallivm->context);
LLVMValueRef function;
LLVMValueRef tmp_ptr;
LLVMValueRef tmp;
@@ -533,10 +539,10 @@ lp_build_fetch_rgba_aos(LLVMBuilderRef builder,
LLVMTypeRef arg_types[4];
LLVMTypeRef function_type;
- ret_type = LLVMVoidType();
+ ret_type = LLVMVoidTypeInContext(gallivm->context);
arg_types[0] = pi8t;
arg_types[1] = pi8t;
- arg_types[3] = arg_types[2] = LLVMIntType(sizeof(unsigned) * 8);
+ arg_types[3] = arg_types[2] = LLVMIntTypeInContext(gallivm->context, sizeof(unsigned) * 8);
function_type = LLVMFunctionType(ret_type, arg_types, Elements(arg_types), 0);
function = LLVMAddFunction(module, name, function_type);
@@ -545,11 +551,11 @@ lp_build_fetch_rgba_aos(LLVMBuilderRef builder,
assert(LLVMIsDeclaration(function));
- LLVMAddGlobalMapping(lp_build_engine, function,
+ LLVMAddGlobalMapping(gallivm->engine, function,
func_to_pointer((func_pointer)format_desc->fetch_rgba_8unorm));
}
- tmp_ptr = lp_build_alloca(builder, i32t, "");
+ tmp_ptr = lp_build_alloca(gallivm, i32t, "");
res = LLVMGetUndef(LLVMVectorType(i32t, num_pixels));
@@ -559,11 +565,11 @@ lp_build_fetch_rgba_aos(LLVMBuilderRef builder,
*/
for (k = 0; k < num_pixels; ++k) {
- LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), k, 0);
+ LLVMValueRef index = lp_build_const_int32(gallivm, k);
LLVMValueRef args[4];
args[0] = LLVMBuildBitCast(builder, tmp_ptr, pi8t, "");
- args[1] = lp_build_gather_elem_ptr(builder, num_pixels,
+ args[1] = lp_build_gather_elem_ptr(gallivm, num_pixels,
base_ptr, offset, k);
if (num_pixels == 1) {
@@ -610,7 +616,7 @@ lp_build_fetch_rgba_aos(LLVMBuilderRef builder,
LLVMModuleRef module = LLVMGetGlobalParent(LLVMGetBasicBlockParent(LLVMGetInsertBlock(builder)));
char name[256];
- LLVMTypeRef f32t = LLVMFloatType();
+ LLVMTypeRef f32t = LLVMFloatTypeInContext(gallivm->context);
LLVMTypeRef f32x4t = LLVMVectorType(f32t, 4);
LLVMTypeRef pf32t = LLVMPointerType(f32t, 0);
LLVMValueRef function;
@@ -636,10 +642,10 @@ lp_build_fetch_rgba_aos(LLVMBuilderRef builder,
LLVMTypeRef arg_types[4];
LLVMTypeRef function_type;
- ret_type = LLVMVoidType();
+ ret_type = LLVMVoidTypeInContext(gallivm->context);
arg_types[0] = pf32t;
- arg_types[1] = LLVMPointerType(LLVMInt8Type(), 0);
- arg_types[3] = arg_types[2] = LLVMIntType(sizeof(unsigned) * 8);
+ arg_types[1] = LLVMPointerType(LLVMInt8TypeInContext(gallivm->context), 0);
+ arg_types[3] = arg_types[2] = LLVMIntTypeInContext(gallivm->context, sizeof(unsigned) * 8);
function_type = LLVMFunctionType(ret_type, arg_types, Elements(arg_types), 0);
function = LLVMAddFunction(module, name, function_type);
@@ -648,11 +654,11 @@ lp_build_fetch_rgba_aos(LLVMBuilderRef builder,
assert(LLVMIsDeclaration(function));
- LLVMAddGlobalMapping(lp_build_engine, function,
+ LLVMAddGlobalMapping(gallivm->engine, function,
func_to_pointer((func_pointer)format_desc->fetch_rgba_float));
}
- tmp_ptr = lp_build_alloca(builder, f32x4t, "");
+ tmp_ptr = lp_build_alloca(gallivm, f32x4t, "");
/*
* Invoke format_desc->fetch_rgba_float() for each pixel and insert the result
@@ -663,7 +669,7 @@ lp_build_fetch_rgba_aos(LLVMBuilderRef builder,
LLVMValueRef args[4];
args[0] = LLVMBuildBitCast(builder, tmp_ptr, pf32t, "");
- args[1] = lp_build_gather_elem_ptr(builder, num_pixels,
+ args[1] = lp_build_gather_elem_ptr(gallivm, num_pixels,
base_ptr, offset, k);
if (num_pixels == 1) {
@@ -671,7 +677,7 @@ lp_build_fetch_rgba_aos(LLVMBuilderRef builder,
args[3] = j;
}
else {
- LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), k, 0);
+ LLVMValueRef index = lp_build_const_int32(gallivm, k);
args[2] = LLVMBuildExtractElement(builder, i, index, "");
args[3] = LLVMBuildExtractElement(builder, j, index, "");
}
@@ -681,7 +687,7 @@ lp_build_fetch_rgba_aos(LLVMBuilderRef builder,
tmps[k] = LLVMBuildLoad(builder, tmp_ptr, "");
}
- lp_build_conv(builder,
+ lp_build_conv(gallivm,
lp_float32_vec4_type(),
type,
tmps, num_pixels, &res, 1);
@@ -690,5 +696,5 @@ lp_build_fetch_rgba_aos(LLVMBuilderRef builder,
}
assert(0);
- return lp_build_undef(type);
+ return lp_build_undef(gallivm, type);
}
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_format_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_format_soa.c
index ce7e54afc7..0a57b3ce79 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_format_soa.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_format_soa.c
@@ -97,12 +97,13 @@ lp_build_format_swizzle_soa(const struct util_format_description *format_desc,
* \param rgba_out returns the SoA R,G,B,A vectors
*/
void
-lp_build_unpack_rgba_soa(LLVMBuilderRef builder,
+lp_build_unpack_rgba_soa(struct gallivm_state *gallivm,
const struct util_format_description *format_desc,
struct lp_type type,
LLVMValueRef packed,
LLVMValueRef rgba_out[4])
{
+ LLVMBuilderRef builder = gallivm->builder;
struct lp_build_context bld;
LLVMValueRef inputs[4];
unsigned start;
@@ -116,7 +117,7 @@ lp_build_unpack_rgba_soa(LLVMBuilderRef builder,
assert(type.floating);
assert(type.width == 32);
- lp_build_context_init(&bld, builder, type);
+ lp_build_context_init(&bld, gallivm, type);
/* Decode the input vector components */
start = 0;
@@ -129,7 +130,7 @@ lp_build_unpack_rgba_soa(LLVMBuilderRef builder,
switch(format_desc->channel[chan].type) {
case UTIL_FORMAT_TYPE_VOID:
- input = lp_build_undef(type);
+ input = lp_build_undef(gallivm, type);
break;
case UTIL_FORMAT_TYPE_UNSIGNED:
@@ -138,7 +139,7 @@ lp_build_unpack_rgba_soa(LLVMBuilderRef builder,
*/
if (start) {
- input = LLVMBuildLShr(builder, input, lp_build_const_int_vec(type, start), "");
+ input = LLVMBuildLShr(builder, input, lp_build_const_int_vec(gallivm, type, start), "");
}
/*
@@ -147,7 +148,7 @@ lp_build_unpack_rgba_soa(LLVMBuilderRef builder,
if (stop < format_desc->block.bits) {
unsigned mask = ((unsigned long long)1 << width) - 1;
- input = LLVMBuildAnd(builder, input, lp_build_const_int_vec(type, mask), "");
+ input = LLVMBuildAnd(builder, input, lp_build_const_int_vec(gallivm, type, mask), "");
}
/*
@@ -156,14 +157,15 @@ lp_build_unpack_rgba_soa(LLVMBuilderRef builder,
if (type.floating) {
if(format_desc->channel[chan].normalized)
- input = lp_build_unsigned_norm_to_float(builder, width, type, input);
+ input = lp_build_unsigned_norm_to_float(gallivm, width, type, input);
else
- input = LLVMBuildSIToFP(builder, input, lp_build_vec_type(type), "");
+ input = LLVMBuildSIToFP(builder, input,
+ lp_build_vec_type(gallivm, type), "");
}
else {
/* FIXME */
assert(0);
- input = lp_build_undef(type);
+ input = lp_build_undef(gallivm, type);
}
break;
@@ -175,7 +177,7 @@ lp_build_unpack_rgba_soa(LLVMBuilderRef builder,
if (stop < type.width) {
unsigned bits = type.width - stop;
- LLVMValueRef bits_val = lp_build_const_int_vec(type, bits);
+ LLVMValueRef bits_val = lp_build_const_int_vec(gallivm, type, bits);
input = LLVMBuildShl(builder, input, bits_val, "");
}
@@ -185,7 +187,7 @@ lp_build_unpack_rgba_soa(LLVMBuilderRef builder,
if (format_desc->channel[chan].size < type.width) {
unsigned bits = type.width - format_desc->channel[chan].size;
- LLVMValueRef bits_val = lp_build_const_int_vec(type, bits);
+ LLVMValueRef bits_val = lp_build_const_int_vec(gallivm, type, bits);
input = LLVMBuildAShr(builder, input, bits_val, "");
}
@@ -194,17 +196,17 @@ lp_build_unpack_rgba_soa(LLVMBuilderRef builder,
*/
if (type.floating) {
- input = LLVMBuildSIToFP(builder, input, lp_build_vec_type(type), "");
+ input = LLVMBuildSIToFP(builder, input, lp_build_vec_type(gallivm, type), "");
if (format_desc->channel[chan].normalized) {
double scale = 1.0 / ((1 << (format_desc->channel[chan].size - 1)) - 1);
- LLVMValueRef scale_val = lp_build_const_vec(type, scale);
+ LLVMValueRef scale_val = lp_build_const_vec(gallivm, type, scale);
input = LLVMBuildFMul(builder, input, scale_val, "");
}
}
else {
/* FIXME */
assert(0);
- input = lp_build_undef(type);
+ input = lp_build_undef(gallivm, type);
}
break;
@@ -214,32 +216,32 @@ lp_build_unpack_rgba_soa(LLVMBuilderRef builder,
assert(start == 0);
assert(stop == 32);
assert(type.width == 32);
- input = LLVMBuildBitCast(builder, input, lp_build_vec_type(type), "");
+ input = LLVMBuildBitCast(builder, input, lp_build_vec_type(gallivm, type), "");
}
else {
/* FIXME */
assert(0);
- input = lp_build_undef(type);
+ input = lp_build_undef(gallivm, type);
}
break;
case UTIL_FORMAT_TYPE_FIXED:
if (type.floating) {
double scale = 1.0 / ((1 << (format_desc->channel[chan].size/2)) - 1);
- LLVMValueRef scale_val = lp_build_const_vec(type, scale);
- input = LLVMBuildSIToFP(builder, input, lp_build_vec_type(type), "");
+ LLVMValueRef scale_val = lp_build_const_vec(gallivm, type, scale);
+ input = LLVMBuildSIToFP(builder, input, lp_build_vec_type(gallivm, type), "");
input = LLVMBuildFMul(builder, input, scale_val, "");
}
else {
/* FIXME */
assert(0);
- input = lp_build_undef(type);
+ input = lp_build_undef(gallivm, type);
}
break;
default:
assert(0);
- input = lp_build_undef(type);
+ input = lp_build_undef(gallivm, type);
break;
}
@@ -253,16 +255,17 @@ lp_build_unpack_rgba_soa(LLVMBuilderRef builder,
void
-lp_build_rgba8_to_f32_soa(LLVMBuilderRef builder,
+lp_build_rgba8_to_f32_soa(struct gallivm_state *gallivm,
struct lp_type dst_type,
LLVMValueRef packed,
LLVMValueRef *rgba)
{
- LLVMValueRef mask = lp_build_const_int_vec(dst_type, 0xff);
+ LLVMBuilderRef builder = gallivm->builder;
+ LLVMValueRef mask = lp_build_const_int_vec(gallivm, dst_type, 0xff);
unsigned chan;
packed = LLVMBuildBitCast(builder, packed,
- lp_build_int_vec_type(dst_type), "");
+ lp_build_int_vec_type(gallivm, dst_type), "");
/* Decode the input vector components */
for (chan = 0; chan < 4; ++chan) {
@@ -274,12 +277,12 @@ lp_build_rgba8_to_f32_soa(LLVMBuilderRef builder,
if (start)
input = LLVMBuildLShr(builder, input,
- lp_build_const_int_vec(dst_type, start), "");
+ lp_build_const_int_vec(gallivm, dst_type, start), "");
if (stop < 32)
input = LLVMBuildAnd(builder, input, mask, "");
- input = lp_build_unsigned_norm_to_float(builder, 8, dst_type, input);
+ input = lp_build_unsigned_norm_to_float(gallivm, 8, dst_type, input);
rgba[chan] = input;
}
@@ -303,7 +306,7 @@ lp_build_rgba8_to_f32_soa(LLVMBuilderRef builder,
* be in [0, block_width-1] and j will be in [0, block_height-1].
*/
void
-lp_build_fetch_rgba_soa(LLVMBuilderRef builder,
+lp_build_fetch_rgba_soa(struct gallivm_state *gallivm,
const struct util_format_description *format_desc,
struct lp_type type,
LLVMValueRef base_ptr,
@@ -312,6 +315,7 @@ lp_build_fetch_rgba_soa(LLVMBuilderRef builder,
LLVMValueRef j,
LLVMValueRef rgba_out[4])
{
+ LLVMBuilderRef builder = gallivm->builder;
if (format_desc->layout == UTIL_FORMAT_LAYOUT_PLAIN &&
(format_desc->colorspace == UTIL_FORMAT_COLORSPACE_RGB ||
@@ -334,7 +338,7 @@ lp_build_fetch_rgba_soa(LLVMBuilderRef builder,
* gather the texels from the texture
* Ex: packed = {BGRA, BGRA, BGRA, BGRA}.
*/
- packed = lp_build_gather(builder,
+ packed = lp_build_gather(gallivm,
type.length,
format_desc->block.bits,
type.width,
@@ -343,7 +347,7 @@ lp_build_fetch_rgba_soa(LLVMBuilderRef builder,
/*
* convert texels to float rgba
*/
- lp_build_unpack_rgba_soa(builder,
+ lp_build_unpack_rgba_soa(gallivm,
format_desc,
type,
packed, rgba_out);
@@ -364,10 +368,10 @@ lp_build_fetch_rgba_soa(LLVMBuilderRef builder,
tmp_type.length = type.length * 4;
tmp_type.norm = TRUE;
- tmp = lp_build_fetch_rgba_aos(builder, format_desc, tmp_type,
+ tmp = lp_build_fetch_rgba_aos(gallivm, format_desc, tmp_type,
base_ptr, offset, i, j);
- lp_build_rgba8_to_f32_soa(builder,
+ lp_build_rgba8_to_f32_soa(gallivm,
type,
tmp,
rgba_out);
@@ -397,23 +401,24 @@ lp_build_fetch_rgba_soa(LLVMBuilderRef builder,
tmp_type.length = 4;
for (chan = 0; chan < 4; ++chan) {
- rgba_out[chan] = lp_build_undef(type);
+ rgba_out[chan] = lp_build_undef(gallivm, type);
}
/* loop over number of pixels */
for(k = 0; k < type.length; ++k) {
- LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), k, 0);
+ LLVMValueRef index = lp_build_const_int32(gallivm, k);
LLVMValueRef offset_elem;
LLVMValueRef i_elem, j_elem;
LLVMValueRef tmp;
- offset_elem = LLVMBuildExtractElement(builder, offset, index, "");
+ offset_elem = LLVMBuildExtractElement(builder, offset,
+ index, "");
i_elem = LLVMBuildExtractElement(builder, i, index, "");
j_elem = LLVMBuildExtractElement(builder, j, index, "");
/* Get a single float[4]={R,G,B,A} pixel */
- tmp = lp_build_fetch_rgba_aos(builder, format_desc, tmp_type,
+ tmp = lp_build_fetch_rgba_aos(gallivm, format_desc, tmp_type,
base_ptr, offset_elem,
i_elem, j_elem);
@@ -422,7 +427,7 @@ lp_build_fetch_rgba_soa(LLVMBuilderRef builder,
* position = 'index'.
*/
for (chan = 0; chan < 4; ++chan) {
- LLVMValueRef chan_val = LLVMConstInt(LLVMInt32Type(), chan, 0),
+ LLVMValueRef chan_val = lp_build_const_int32(gallivm, chan),
tmp_chan = LLVMBuildExtractElement(builder, tmp, chan_val, "");
rgba_out[chan] = LLVMBuildInsertElement(builder, rgba_out[chan],
tmp_chan, index, "");
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_format_yuv.c b/src/gallium/auxiliary/gallivm/lp_bld_format_yuv.c
index 2bce289555..cdf1956c09 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_format_yuv.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_format_yuv.c
@@ -43,6 +43,7 @@
#include "lp_bld_conv.h"
#include "lp_bld_gather.h"
#include "lp_bld_format.h"
+#include "lp_bld_init.h"
#include "lp_bld_logic.h"
/**
@@ -51,7 +52,7 @@
* @param i is a <n x i32> vector with the x pixel coordinate (0 or 1)
*/
static void
-uyvy_to_yuv_soa(LLVMBuilderRef builder,
+uyvy_to_yuv_soa(struct gallivm_state *gallivm,
unsigned n,
LLVMValueRef packed,
LLVMValueRef i,
@@ -59,6 +60,7 @@ uyvy_to_yuv_soa(LLVMBuilderRef builder,
LLVMValueRef *u,
LLVMValueRef *v)
{
+ LLVMBuilderRef builder = gallivm->builder;
struct lp_type type;
LLVMValueRef mask;
@@ -86,25 +88,25 @@ uyvy_to_yuv_soa(LLVMBuilderRef builder,
LLVMValueRef sel, tmp, tmp2;
struct lp_build_context bld32;
- lp_build_context_init(&bld32, builder, type);
+ lp_build_context_init(&bld32, gallivm, type);
- tmp = LLVMBuildLShr(builder, packed, lp_build_const_int_vec(type, 8), "");
- tmp2 = LLVMBuildLShr(builder, tmp, lp_build_const_int_vec(type, 16), "");
- sel = lp_build_compare(builder, type, PIPE_FUNC_EQUAL, i, lp_build_const_int_vec(type, 0));
+ tmp = LLVMBuildLShr(builder, packed, lp_build_const_int_vec(gallivm, type, 8), "");
+ tmp2 = LLVMBuildLShr(builder, tmp, lp_build_const_int_vec(gallivm, type, 16), "");
+ sel = lp_build_compare(gallivm, type, PIPE_FUNC_EQUAL, i, lp_build_const_int_vec(gallivm, type, 0));
*y = lp_build_select(&bld32, sel, tmp, tmp2);
} else
#endif
{
LLVMValueRef shift;
- shift = LLVMBuildMul(builder, i, lp_build_const_int_vec(type, 16), "");
- shift = LLVMBuildAdd(builder, shift, lp_build_const_int_vec(type, 8), "");
+ shift = LLVMBuildMul(builder, i, lp_build_const_int_vec(gallivm, type, 16), "");
+ shift = LLVMBuildAdd(builder, shift, lp_build_const_int_vec(gallivm, type, 8), "");
*y = LLVMBuildLShr(builder, packed, shift, "");
}
*u = packed;
- *v = LLVMBuildLShr(builder, packed, lp_build_const_int_vec(type, 16), "");
+ *v = LLVMBuildLShr(builder, packed, lp_build_const_int_vec(gallivm, type, 16), "");
- mask = lp_build_const_int_vec(type, 0xff);
+ mask = lp_build_const_int_vec(gallivm, type, 0xff);
*y = LLVMBuildAnd(builder, *y, mask, "y");
*u = LLVMBuildAnd(builder, *u, mask, "u");
@@ -118,7 +120,7 @@ uyvy_to_yuv_soa(LLVMBuilderRef builder,
* @param i is a <n x i32> vector with the x pixel coordinate (0 or 1)
*/
static void
-yuyv_to_yuv_soa(LLVMBuilderRef builder,
+yuyv_to_yuv_soa(struct gallivm_state *gallivm,
unsigned n,
LLVMValueRef packed,
LLVMValueRef i,
@@ -126,6 +128,7 @@ yuyv_to_yuv_soa(LLVMBuilderRef builder,
LLVMValueRef *u,
LLVMValueRef *v)
{
+ LLVMBuilderRef builder = gallivm->builder;
struct lp_type type;
LLVMValueRef mask;
@@ -153,23 +156,23 @@ yuyv_to_yuv_soa(LLVMBuilderRef builder,
LLVMValueRef sel, tmp;
struct lp_build_context bld32;
- lp_build_context_init(&bld32, builder, type);
+ lp_build_context_init(&bld32, gallivm, type);
- tmp = LLVMBuildLShr(builder, packed, lp_build_const_int_vec(type, 16), "");
- sel = lp_build_compare(builder, type, PIPE_FUNC_EQUAL, i, lp_build_const_int_vec(type, 0));
+ tmp = LLVMBuildLShr(builder, packed, lp_build_const_int_vec(gallivm, type, 16), "");
+ sel = lp_build_compare(gallivm, type, PIPE_FUNC_EQUAL, i, lp_build_const_int_vec(gallivm, type, 0));
*y = lp_build_select(&bld32, sel, packed, tmp);
} else
#endif
{
LLVMValueRef shift;
- shift = LLVMBuildMul(builder, i, lp_build_const_int_vec(type, 16), "");
+ shift = LLVMBuildMul(builder, i, lp_build_const_int_vec(gallivm, type, 16), "");
*y = LLVMBuildLShr(builder, packed, shift, "");
}
- *u = LLVMBuildLShr(builder, packed, lp_build_const_int_vec(type, 8), "");
- *v = LLVMBuildLShr(builder, packed, lp_build_const_int_vec(type, 24), "");
+ *u = LLVMBuildLShr(builder, packed, lp_build_const_int_vec(gallivm, type, 8), "");
+ *v = LLVMBuildLShr(builder, packed, lp_build_const_int_vec(gallivm, type, 24), "");
- mask = lp_build_const_int_vec(type, 0xff);
+ mask = lp_build_const_int_vec(gallivm, type, 0xff);
*y = LLVMBuildAnd(builder, *y, mask, "y");
*u = LLVMBuildAnd(builder, *u, mask, "u");
@@ -178,11 +181,12 @@ yuyv_to_yuv_soa(LLVMBuilderRef builder,
static INLINE void
-yuv_to_rgb_soa(LLVMBuilderRef builder,
+yuv_to_rgb_soa(struct gallivm_state *gallivm,
unsigned n,
LLVMValueRef y, LLVMValueRef u, LLVMValueRef v,
LLVMValueRef *r, LLVMValueRef *g, LLVMValueRef *b)
{
+ LLVMBuilderRef builder = gallivm->builder;
struct lp_type type;
struct lp_build_context bld;
@@ -203,7 +207,7 @@ yuv_to_rgb_soa(LLVMBuilderRef builder,
type.width = 32;
type.length = n;
- lp_build_context_init(&bld, builder, type);
+ lp_build_context_init(&bld, gallivm, type);
assert(lp_check_value(type, y));
assert(lp_check_value(type, u));
@@ -213,17 +217,17 @@ yuv_to_rgb_soa(LLVMBuilderRef builder,
* Constants
*/
- c0 = lp_build_const_int_vec(type, 0);
- c8 = lp_build_const_int_vec(type, 8);
- c16 = lp_build_const_int_vec(type, 16);
- c128 = lp_build_const_int_vec(type, 128);
- c255 = lp_build_const_int_vec(type, 255);
+ c0 = lp_build_const_int_vec(gallivm, type, 0);
+ c8 = lp_build_const_int_vec(gallivm, type, 8);
+ c16 = lp_build_const_int_vec(gallivm, type, 16);
+ c128 = lp_build_const_int_vec(gallivm, type, 128);
+ c255 = lp_build_const_int_vec(gallivm, type, 255);
- cy = lp_build_const_int_vec(type, 298);
- cug = lp_build_const_int_vec(type, -100);
- cub = lp_build_const_int_vec(type, 516);
- cvr = lp_build_const_int_vec(type, 409);
- cvg = lp_build_const_int_vec(type, -208);
+ cy = lp_build_const_int_vec(gallivm, type, 298);
+ cug = lp_build_const_int_vec(gallivm, type, -100);
+ cub = lp_build_const_int_vec(gallivm, type, 516);
+ cvr = lp_build_const_int_vec(gallivm, type, 409);
+ cvg = lp_build_const_int_vec(gallivm, type, -208);
/*
* y -= 16;
@@ -276,10 +280,11 @@ yuv_to_rgb_soa(LLVMBuilderRef builder,
static LLVMValueRef
-rgb_to_rgba_aos(LLVMBuilderRef builder,
+rgb_to_rgba_aos(struct gallivm_state *gallivm,
unsigned n,
LLVMValueRef r, LLVMValueRef g, LLVMValueRef b)
{
+ LLVMBuilderRef builder = gallivm->builder;
struct lp_type type;
LLVMValueRef a;
LLVMValueRef rgba;
@@ -298,9 +303,9 @@ rgb_to_rgba_aos(LLVMBuilderRef builder,
*/
r = r;
- g = LLVMBuildShl(builder, g, lp_build_const_int_vec(type, 8), "");
- b = LLVMBuildShl(builder, b, lp_build_const_int_vec(type, 16), "");
- a = lp_build_const_int_vec(type, 0xff000000);
+ g = LLVMBuildShl(builder, g, lp_build_const_int_vec(gallivm, type, 8), "");
+ b = LLVMBuildShl(builder, b, lp_build_const_int_vec(gallivm, type, 16), "");
+ a = lp_build_const_int_vec(gallivm, type, 0xff000000);
rgba = r;
rgba = LLVMBuildOr(builder, rgba, g, "");
@@ -308,7 +313,7 @@ rgb_to_rgba_aos(LLVMBuilderRef builder,
rgba = LLVMBuildOr(builder, rgba, a, "");
rgba = LLVMBuildBitCast(builder, rgba,
- LLVMVectorType(LLVMInt8Type(), 4*n), "");
+ LLVMVectorType(LLVMInt8TypeInContext(gallivm->context), 4*n), "");
return rgba;
}
@@ -318,7 +323,7 @@ rgb_to_rgba_aos(LLVMBuilderRef builder,
* Convert from <n x i32> packed UYVY to <4n x i8> RGBA AoS
*/
static LLVMValueRef
-uyvy_to_rgba_aos(LLVMBuilderRef builder,
+uyvy_to_rgba_aos(struct gallivm_state *gallivm,
unsigned n,
LLVMValueRef packed,
LLVMValueRef i)
@@ -327,9 +332,9 @@ uyvy_to_rgba_aos(LLVMBuilderRef builder,
LLVMValueRef r, g, b;
LLVMValueRef rgba;
- uyvy_to_yuv_soa(builder, n, packed, i, &y, &u, &v);
- yuv_to_rgb_soa(builder, n, y, u, v, &r, &g, &b);
- rgba = rgb_to_rgba_aos(builder, n, r, g, b);
+ uyvy_to_yuv_soa(gallivm, n, packed, i, &y, &u, &v);
+ yuv_to_rgb_soa(gallivm, n, y, u, v, &r, &g, &b);
+ rgba = rgb_to_rgba_aos(gallivm, n, r, g, b);
return rgba;
}
@@ -339,7 +344,7 @@ uyvy_to_rgba_aos(LLVMBuilderRef builder,
* Convert from <n x i32> packed YUYV to <4n x i8> RGBA AoS
*/
static LLVMValueRef
-yuyv_to_rgba_aos(LLVMBuilderRef builder,
+yuyv_to_rgba_aos(struct gallivm_state *gallivm,
unsigned n,
LLVMValueRef packed,
LLVMValueRef i)
@@ -348,9 +353,9 @@ yuyv_to_rgba_aos(LLVMBuilderRef builder,
LLVMValueRef r, g, b;
LLVMValueRef rgba;
- yuyv_to_yuv_soa(builder, n, packed, i, &y, &u, &v);
- yuv_to_rgb_soa(builder, n, y, u, v, &r, &g, &b);
- rgba = rgb_to_rgba_aos(builder, n, r, g, b);
+ yuyv_to_yuv_soa(gallivm, n, packed, i, &y, &u, &v);
+ yuv_to_rgb_soa(gallivm, n, y, u, v, &r, &g, &b);
+ rgba = rgb_to_rgba_aos(gallivm, n, r, g, b);
return rgba;
}
@@ -360,7 +365,7 @@ yuyv_to_rgba_aos(LLVMBuilderRef builder,
* Convert from <n x i32> packed RG_BG to <4n x i8> RGBA AoS
*/
static LLVMValueRef
-rgbg_to_rgba_aos(LLVMBuilderRef builder,
+rgbg_to_rgba_aos(struct gallivm_state *gallivm,
unsigned n,
LLVMValueRef packed,
LLVMValueRef i)
@@ -368,8 +373,8 @@ rgbg_to_rgba_aos(LLVMBuilderRef builder,
LLVMValueRef r, g, b;
LLVMValueRef rgba;
- uyvy_to_yuv_soa(builder, n, packed, i, &g, &r, &b);
- rgba = rgb_to_rgba_aos(builder, n, r, g, b);
+ uyvy_to_yuv_soa(gallivm, n, packed, i, &g, &r, &b);
+ rgba = rgb_to_rgba_aos(gallivm, n, r, g, b);
return rgba;
}
@@ -379,7 +384,7 @@ rgbg_to_rgba_aos(LLVMBuilderRef builder,
* Convert from <n x i32> packed GR_GB to <4n x i8> RGBA AoS
*/
static LLVMValueRef
-grgb_to_rgba_aos(LLVMBuilderRef builder,
+grgb_to_rgba_aos(struct gallivm_state *gallivm,
unsigned n,
LLVMValueRef packed,
LLVMValueRef i)
@@ -387,8 +392,8 @@ grgb_to_rgba_aos(LLVMBuilderRef builder,
LLVMValueRef r, g, b;
LLVMValueRef rgba;
- yuyv_to_yuv_soa(builder, n, packed, i, &g, &r, &b);
- rgba = rgb_to_rgba_aos(builder, n, r, g, b);
+ yuyv_to_yuv_soa(gallivm, n, packed, i, &g, &r, &b);
+ rgba = rgb_to_rgba_aos(gallivm, n, r, g, b);
return rgba;
}
@@ -401,7 +406,7 @@ grgb_to_rgba_aos(LLVMBuilderRef builder,
* @return a <4*n x i8> vector with the pixel RGBA values in AoS
*/
LLVMValueRef
-lp_build_fetch_subsampled_rgba_aos(LLVMBuilderRef builder,
+lp_build_fetch_subsampled_rgba_aos(struct gallivm_state *gallivm,
const struct util_format_description *format_desc,
unsigned n,
LLVMValueRef base_ptr,
@@ -417,26 +422,26 @@ lp_build_fetch_subsampled_rgba_aos(LLVMBuilderRef builder,
assert(format_desc->block.width == 2);
assert(format_desc->block.height == 1);
- packed = lp_build_gather(builder, n, 32, 32, base_ptr, offset);
+ packed = lp_build_gather(gallivm, n, 32, 32, base_ptr, offset);
(void)j;
switch (format_desc->format) {
case PIPE_FORMAT_UYVY:
- rgba = uyvy_to_rgba_aos(builder, n, packed, i);
+ rgba = uyvy_to_rgba_aos(gallivm, n, packed, i);
break;
case PIPE_FORMAT_YUYV:
- rgba = yuyv_to_rgba_aos(builder, n, packed, i);
+ rgba = yuyv_to_rgba_aos(gallivm, n, packed, i);
break;
case PIPE_FORMAT_R8G8_B8G8_UNORM:
- rgba = rgbg_to_rgba_aos(builder, n, packed, i);
+ rgba = rgbg_to_rgba_aos(gallivm, n, packed, i);
break;
case PIPE_FORMAT_G8R8_G8B8_UNORM:
- rgba = grgb_to_rgba_aos(builder, n, packed, i);
+ rgba = grgb_to_rgba_aos(gallivm, n, packed, i);
break;
default:
assert(0);
- rgba = LLVMGetUndef(LLVMVectorType(LLVMInt8Type(), 4*n));
+ rgba = LLVMGetUndef(LLVMVectorType(LLVMInt8TypeInContext(gallivm->context), 4*n));
break;
}
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_gather.c b/src/gallium/auxiliary/gallivm/lp_bld_gather.c
index d60472e065..0dc81b1abb 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_gather.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_gather.c
@@ -31,6 +31,7 @@
#include "lp_bld_const.h"
#include "lp_bld_format.h"
#include "lp_bld_gather.h"
+#include "lp_bld_init.h"
/**
@@ -39,7 +40,7 @@
* @sa lp_build_gather()
*/
LLVMValueRef
-lp_build_gather_elem_ptr(LLVMBuilderRef builder,
+lp_build_gather_elem_ptr(struct gallivm_state *gallivm,
unsigned length,
LLVMValueRef base_ptr,
LLVMValueRef offsets,
@@ -48,17 +49,17 @@ lp_build_gather_elem_ptr(LLVMBuilderRef builder,
LLVMValueRef offset;
LLVMValueRef ptr;
- assert(LLVMTypeOf(base_ptr) == LLVMPointerType(LLVMInt8Type(), 0));
+ assert(LLVMTypeOf(base_ptr) == LLVMPointerType(LLVMInt8TypeInContext(gallivm->context), 0));
if (length == 1) {
assert(i == 0);
offset = offsets;
} else {
- LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), i, 0);
- offset = LLVMBuildExtractElement(builder, offsets, index, "");
+ LLVMValueRef index = lp_build_const_int32(gallivm, i);
+ offset = LLVMBuildExtractElement(gallivm->builder, offsets, index, "");
}
- ptr = LLVMBuildGEP(builder, base_ptr, &offset, 1, "");
+ ptr = LLVMBuildGEP(gallivm->builder, base_ptr, &offset, 1, "");
return ptr;
}
@@ -70,7 +71,7 @@ lp_build_gather_elem_ptr(LLVMBuilderRef builder,
* @sa lp_build_gather()
*/
LLVMValueRef
-lp_build_gather_elem(LLVMBuilderRef builder,
+lp_build_gather_elem(struct gallivm_state *gallivm,
unsigned length,
unsigned src_width,
unsigned dst_width,
@@ -78,23 +79,23 @@ lp_build_gather_elem(LLVMBuilderRef builder,
LLVMValueRef offsets,
unsigned i)
{
- LLVMTypeRef src_type = LLVMIntType(src_width);
+ LLVMTypeRef src_type = LLVMIntTypeInContext(gallivm->context, src_width);
LLVMTypeRef src_ptr_type = LLVMPointerType(src_type, 0);
- LLVMTypeRef dst_elem_type = LLVMIntType(dst_width);
+ LLVMTypeRef dst_elem_type = LLVMIntTypeInContext(gallivm->context, dst_width);
LLVMValueRef ptr;
LLVMValueRef res;
- assert(LLVMTypeOf(base_ptr) == LLVMPointerType(LLVMInt8Type(), 0));
+ assert(LLVMTypeOf(base_ptr) == LLVMPointerType(LLVMInt8TypeInContext(gallivm->context), 0));
- ptr = lp_build_gather_elem_ptr(builder, length, base_ptr, offsets, i);
- ptr = LLVMBuildBitCast(builder, ptr, src_ptr_type, "");
- res = LLVMBuildLoad(builder, ptr, "");
+ ptr = lp_build_gather_elem_ptr(gallivm, length, base_ptr, offsets, i);
+ ptr = LLVMBuildBitCast(gallivm->builder, ptr, src_ptr_type, "");
+ res = LLVMBuildLoad(gallivm->builder, ptr, "");
assert(src_width <= dst_width);
if (src_width > dst_width)
- res = LLVMBuildTrunc(builder, res, dst_elem_type, "");
+ res = LLVMBuildTrunc(gallivm->builder, res, dst_elem_type, "");
if (src_width < dst_width)
- res = LLVMBuildZExt(builder, res, dst_elem_type, "");
+ res = LLVMBuildZExt(gallivm->builder, res, dst_elem_type, "");
return res;
}
@@ -112,7 +113,7 @@ lp_build_gather_elem(LLVMBuilderRef builder,
* @param offsets vector with offsets
*/
LLVMValueRef
-lp_build_gather(LLVMBuilderRef builder,
+lp_build_gather(struct gallivm_state *gallivm,
unsigned length,
unsigned src_width,
unsigned dst_width,
@@ -123,24 +124,24 @@ lp_build_gather(LLVMBuilderRef builder,
if (length == 1) {
/* Scalar */
- return lp_build_gather_elem(builder, length,
+ return lp_build_gather_elem(gallivm, length,
src_width, dst_width,
base_ptr, offsets, 0);
} else {
/* Vector */
- LLVMTypeRef dst_elem_type = LLVMIntType(dst_width);
+ LLVMTypeRef dst_elem_type = LLVMIntTypeInContext(gallivm->context, dst_width);
LLVMTypeRef dst_vec_type = LLVMVectorType(dst_elem_type, length);
unsigned i;
res = LLVMGetUndef(dst_vec_type);
for (i = 0; i < length; ++i) {
- LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), i, 0);
+ LLVMValueRef index = lp_build_const_int32(gallivm, i);
LLVMValueRef elem;
- elem = lp_build_gather_elem(builder, length,
+ elem = lp_build_gather_elem(gallivm, length,
src_width, dst_width,
base_ptr, offsets, i);
- res = LLVMBuildInsertElement(builder, res, elem, index, "");
+ res = LLVMBuildInsertElement(gallivm->builder, res, elem, index, "");
}
}
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_gather.h b/src/gallium/auxiliary/gallivm/lp_bld_gather.h
index 131af8ea07..5b04131730 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_gather.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_gather.h
@@ -34,14 +34,14 @@
LLVMValueRef
-lp_build_gather_elem_ptr(LLVMBuilderRef builder,
+lp_build_gather_elem_ptr(struct gallivm_state *gallivm,
unsigned length,
LLVMValueRef base_ptr,
LLVMValueRef offsets,
unsigned i);
LLVMValueRef
-lp_build_gather_elem(LLVMBuilderRef builder,
+lp_build_gather_elem(struct gallivm_state *gallivm,
unsigned length,
unsigned src_width,
unsigned dst_width,
@@ -50,7 +50,7 @@ lp_build_gather_elem(LLVMBuilderRef builder,
unsigned i);
LLVMValueRef
-lp_build_gather(LLVMBuilderRef builder,
+lp_build_gather(struct gallivm_state *gallivm,
unsigned length,
unsigned src_width,
unsigned dst_width,
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.c b/src/gallium/auxiliary/gallivm/lp_bld_init.c
index 0b9a6f745f..efe8d38b8f 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_init.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_init.c
@@ -29,6 +29,7 @@
#include "pipe/p_compiler.h"
#include "util/u_cpu_detect.h"
#include "util/u_debug.h"
+#include "util/u_memory.h"
#include "lp_bld_debug.h"
#include "lp_bld_init.h"
@@ -45,6 +46,7 @@ static const struct debug_named_value lp_bld_debug_flags[] = {
{ "nopt", GALLIVM_DEBUG_NO_OPT, NULL },
{ "perf", GALLIVM_DEBUG_PERF, NULL },
{ "no_brilinear", GALLIVM_DEBUG_NO_BRILINEAR, NULL },
+ { "gc", GALLIVM_DEBUG_GC, NULL },
DEBUG_NAMED_VALUE_END
};
@@ -52,11 +54,7 @@ DEBUG_GET_ONCE_FLAGS_OPTION(gallivm_debug, "GALLIVM_DEBUG", lp_bld_debug_flags,
#endif
-LLVMModuleRef lp_build_module = NULL;
-LLVMExecutionEngineRef lp_build_engine = NULL;
-LLVMModuleProviderRef lp_build_provider = NULL;
-LLVMTargetDataRef lp_build_target = NULL;
-LLVMPassManagerRef lp_build_pass = NULL;
+static boolean gallivm_initialized = FALSE;
/*
@@ -82,6 +80,19 @@ enum LLVM_CodeGenOpt_Level {
};
+/**
+ * LLVM 2.6 permits only one ExecutionEngine to be created. This is it.
+ */
+static LLVMExecutionEngineRef GlobalEngine = NULL;
+
+/**
+ * Same gallivm state shared by all contexts.
+ */
+static struct gallivm_state *GlobalGallivm = NULL;
+
+
+
+
extern void
lp_register_oprofile_jit_event_listener(LLVMExecutionEngineRef EE);
@@ -89,26 +100,148 @@ extern void
lp_set_target_options(void);
-void
-lp_build_init(void)
+
+/**
+ * Create the LLVM (optimization) pass manager and install
+ * relevant optimization passes.
+ * \return TRUE for success, FALSE for failure
+ */
+static boolean
+create_pass_manager(struct gallivm_state *gallivm)
{
-#ifdef DEBUG
- gallivm_debug = debug_get_option_gallivm_debug();
+ assert(!gallivm->passmgr);
+
+ gallivm->passmgr = LLVMCreateFunctionPassManager(gallivm->provider);
+ if (!gallivm->passmgr)
+ return FALSE;
+
+ LLVMAddTargetData(gallivm->target, gallivm->passmgr);
+
+ if ((gallivm_debug & GALLIVM_DEBUG_NO_OPT) == 0) {
+ /* These are the passes currently listed in llvm-c/Transforms/Scalar.h,
+ * but there are more on SVN.
+ * TODO: Add more passes.
+ */
+ LLVMAddCFGSimplificationPass(gallivm->passmgr);
+
+ if (HAVE_LLVM >= 0x207 && sizeof(void*) == 4) {
+ /* For LLVM >= 2.7 and 32-bit build, use this order of passes to
+ * avoid generating bad code.
+ * Test with piglit glsl-vs-sqrt-zero test.
+ */
+ LLVMAddConstantPropagationPass(gallivm->passmgr);
+ LLVMAddPromoteMemoryToRegisterPass(gallivm->passmgr);
+ }
+ else {
+ LLVMAddPromoteMemoryToRegisterPass(gallivm->passmgr);
+ LLVMAddConstantPropagationPass(gallivm->passmgr);
+ }
+
+ if (util_cpu_caps.has_sse4_1) {
+ /* FIXME: There is a bug in this pass, whereby the combination
+ * of fptosi and sitofp (necessary for trunc/floor/ceil/round
+ * implementation) somehow becomes invalid code.
+ */
+ LLVMAddInstructionCombiningPass(gallivm->passmgr);
+ }
+ LLVMAddGVNPass(gallivm->passmgr);
+ }
+ else {
+ /* We need at least this pass to prevent the backends to fail in
+ * unexpected ways.
+ */
+ LLVMAddPromoteMemoryToRegisterPass(gallivm->passmgr);
+ }
+
+ return TRUE;
+}
+
+
+/**
+ * Free gallivm object's LLVM allocations, but not the gallivm object itself.
+ */
+static void
+free_gallivm_state(struct gallivm_state *gallivm)
+{
+#if HAVE_LLVM >= 0x207 /* XXX or 0x208? */
+ /* This leads to crashes w/ some versions of LLVM */
+ LLVMModuleRef mod;
+ char *error;
+
+ if (gallivm->engine && gallivm->provider)
+ LLVMRemoveModuleProvider(gallivm->engine, gallivm->provider,
+ &mod, &error);
#endif
- lp_set_target_options();
+#if 0
+ /* XXX this seems to crash with all versions of LLVM */
+ if (gallivm->provider)
+ LLVMDisposeModuleProvider(gallivm->provider);
+#endif
- LLVMInitializeNativeTarget();
+ if (gallivm->passmgr)
+ LLVMDisposePassManager(gallivm->passmgr);
- LLVMLinkInJIT();
+#if HAVE_LLVM >= 0x207
+ if (gallivm->module)
+ LLVMDisposeModule(gallivm->module);
+#endif
+
+#if 0
+ /* Don't free the exec engine, it's a global/singleton */
+ if (gallivm->engine)
+ LLVMDisposeExecutionEngine(gallivm->engine);
+#endif
+
+#if 0
+ /* Don't free the TargetData, it's owned by the exec engine */
+ LLVMDisposeTargetData(gallivm->target);
+#endif
+
+ if (gallivm->context)
+ LLVMContextDispose(gallivm->context);
- if (!lp_build_module)
- lp_build_module = LLVMModuleCreateWithName("gallivm");
+ if (gallivm->builder)
+ LLVMDisposeBuilder(gallivm->builder);
+
+ gallivm->engine = NULL;
+ gallivm->target = NULL;
+ gallivm->module = NULL;
+ gallivm->provider = NULL;
+ gallivm->passmgr = NULL;
+ gallivm->context = NULL;
+ gallivm->builder = NULL;
+}
- if (!lp_build_provider)
- lp_build_provider = LLVMCreateModuleProviderForExistingModule(lp_build_module);
- if (!lp_build_engine) {
+/**
+ * Allocate gallivm LLVM objects.
+ * \return TRUE for success, FALSE for failure
+ */
+static boolean
+init_gallivm_state(struct gallivm_state *gallivm)
+{
+ assert(gallivm_initialized);
+ assert(!gallivm->context);
+ assert(!gallivm->module);
+ assert(!gallivm->provider);
+
+ gallivm->context = LLVMContextCreate();
+ if (!gallivm->context)
+ goto fail;
+
+ gallivm->module = LLVMModuleCreateWithNameInContext("gallivm",
+ gallivm->context);
+ if (!gallivm->module)
+ goto fail;
+
+ gallivm->provider =
+ LLVMCreateModuleProviderForExistingModule(gallivm->module);
+ if (!gallivm->provider)
+ goto fail;
+
+ if (!GlobalEngine) {
+ /* We can only create one LLVMExecutionEngine (w/ LLVM 2.6 anyway) */
enum LLVM_CodeGenOpt_Level optlevel;
char *error = NULL;
@@ -119,43 +252,152 @@ lp_build_init(void)
optlevel = Default;
}
- if (LLVMCreateJITCompiler(&lp_build_engine, lp_build_provider,
- (unsigned)optlevel, &error)) {
+ if (LLVMCreateJITCompiler(&GlobalEngine, gallivm->provider,
+ (unsigned) optlevel, &error)) {
_debug_printf("%s\n", error);
LLVMDisposeMessage(error);
- assert(0);
+ goto fail;
}
#if defined(DEBUG) || defined(PROFILE)
- lp_register_oprofile_jit_event_listener(lp_build_engine);
+ lp_register_oprofile_jit_event_listener(GlobalEngine);
#endif
}
- if (!lp_build_target)
- lp_build_target = LLVMGetExecutionEngineTargetData(lp_build_engine);
-
- if (!lp_build_pass) {
- lp_build_pass = LLVMCreateFunctionPassManager(lp_build_provider);
- LLVMAddTargetData(lp_build_target, lp_build_pass);
-
- if ((gallivm_debug & GALLIVM_DEBUG_NO_OPT) == 0) {
- /* These are the passes currently listed in llvm-c/Transforms/Scalar.h,
- * but there are more on SVN. */
- /* TODO: Add more passes */
- LLVMAddCFGSimplificationPass(lp_build_pass);
- LLVMAddPromoteMemoryToRegisterPass(lp_build_pass);
- LLVMAddConstantPropagationPass(lp_build_pass);
- LLVMAddInstructionCombiningPass(lp_build_pass);
- LLVMAddGVNPass(lp_build_pass);
- } else {
- /* We need at least this pass to prevent the backends to fail in
- * unexpected ways.
- */
- LLVMAddPromoteMemoryToRegisterPass(lp_build_pass);
+ gallivm->engine = GlobalEngine;
+
+ LLVMAddModuleProvider(gallivm->engine, gallivm->provider);//new
+
+ gallivm->target = LLVMGetExecutionEngineTargetData(gallivm->engine);
+ if (!gallivm->target)
+ goto fail;
+
+ if (!create_pass_manager(gallivm))
+ goto fail;
+
+ gallivm->builder = LLVMCreateBuilderInContext(gallivm->context);
+ if (!gallivm->builder)
+ goto fail;
+
+ return TRUE;
+
+fail:
+ free_gallivm_state(gallivm);
+ return FALSE;
+}
+
+
+struct callback
+{
+ garbage_collect_callback_func func;
+ void *cb_data;
+};
+
+
+#define MAX_CALLBACKS 32
+static struct callback Callbacks[MAX_CALLBACKS];
+static unsigned NumCallbacks = 0;
+
+
+/**
+ * Register a function with gallivm which will be called when we
+ * do garbage collection.
+ */
+void
+gallivm_register_garbage_collector_callback(garbage_collect_callback_func func,
+ void *cb_data)
+{
+ unsigned i;
+
+ for (i = 0; i < NumCallbacks; i++) {
+ if (Callbacks[i].func == func && Callbacks[i].cb_data == cb_data) {
+ /* already in list: no-op */
+ return;
+ }
+ }
+
+ assert(NumCallbacks < MAX_CALLBACKS);
+ if (NumCallbacks < MAX_CALLBACKS) {
+ Callbacks[NumCallbacks].func = func;
+ Callbacks[NumCallbacks].cb_data = cb_data;
+ NumCallbacks++;
+ }
+}
+
+
+/**
+ * Remove a callback.
+ */
+void
+gallivm_remove_garbage_collector_callback(garbage_collect_callback_func func,
+ void *cb_data)
+{
+ unsigned i;
+
+ for (i = 0; i < NumCallbacks; i++) {
+ if (Callbacks[i].func == func && Callbacks[i].cb_data == cb_data) {
+ /* found, now remove it */
+ NumCallbacks--;
+ for ( ; i < NumCallbacks; i++) {
+ Callbacks[i] = Callbacks[i + 1];
+ }
+ return;
}
}
+}
+
+
+/**
+ * Call the callback functions (which are typically in the
+ * draw module and llvmpipe driver.
+ */
+static void
+call_garbage_collector_callbacks(void)
+{
+ unsigned i;
+
+ for (i = 0; i < NumCallbacks; i++) {
+ Callbacks[i].func(Callbacks[i].cb_data);
+ }
+}
+
+
+
+/**
+ * Other gallium components using gallivm should call this periodically
+ * to let us do garbage collection (or at least try to free memory
+ * accumulated by the LLVM libraries).
+ */
+void
+gallivm_garbage_collect(struct gallivm_state *gallivm)
+{
+ if (gallivm->context) {
+ if (gallivm_debug & GALLIVM_DEBUG_GC)
+ debug_printf("***** Doing LLVM garbage collection\n");
+
+ call_garbage_collector_callbacks();
+ free_gallivm_state(gallivm);
+ init_gallivm_state(gallivm);
+ }
+}
+
+
+void
+lp_build_init(void)
+{
+#ifdef DEBUG
+ gallivm_debug = debug_get_option_gallivm_debug();
+#endif
+
+ lp_set_target_options();
+
+ LLVMInitializeNativeTarget();
+
+ LLVMLinkInJIT();
util_cpu_detect();
+
+ gallivm_initialized = TRUE;
#if 0
/* For simulating less capable machines */
@@ -166,6 +408,39 @@ lp_build_init(void)
}
+
+/**
+ * Create a new gallivm_state object.
+ * Note that we return a singleton.
+ */
+struct gallivm_state *
+gallivm_create(void)
+{
+ if (!GlobalGallivm) {
+ GlobalGallivm = CALLOC_STRUCT(gallivm_state);
+ if (GlobalGallivm) {
+ if (!init_gallivm_state(GlobalGallivm)) {
+ FREE(GlobalGallivm);
+ GlobalGallivm = NULL;
+ }
+ }
+ }
+ return GlobalGallivm;
+}
+
+
+/**
+ * Destroy a gallivm_state object.
+ */
+void
+gallivm_destroy(struct gallivm_state *gallivm)
+{
+ /* No-op: don't destroy the singleton */
+ (void) gallivm;
+}
+
+
+
/*
* Hack to allow the linking of release LLVM static libraries on a debug build.
*
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.h b/src/gallium/auxiliary/gallivm/lp_bld_init.h
index 0b4b1ca7d1..f68bf75a85 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_init.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_init.h
@@ -30,24 +30,53 @@
#define LP_BLD_INIT_H
+#include "pipe/p_compiler.h"
#include "lp_bld.h"
#include <llvm-c/ExecutionEngine.h>
-extern LLVMModuleRef lp_build_module;
-extern LLVMExecutionEngineRef lp_build_engine;
-extern LLVMModuleProviderRef lp_build_provider;
-extern LLVMTargetDataRef lp_build_target;
-extern LLVMPassManagerRef lp_build_pass;
+struct gallivm_state
+{
+ LLVMModuleRef module;
+ LLVMExecutionEngineRef engine;
+ LLVMModuleProviderRef provider;
+ LLVMTargetDataRef target;
+ LLVMPassManagerRef passmgr;
+ LLVMContextRef context;
+ LLVMBuilderRef builder;
+};
void
lp_build_init(void);
+
extern void
lp_func_delete_body(LLVMValueRef func);
+void
+gallivm_garbage_collect(struct gallivm_state *gallivm);
+
+
+typedef void (*garbage_collect_callback_func)(void *cb_data);
+
+void
+gallivm_register_garbage_collector_callback(garbage_collect_callback_func func,
+ void *cb_data);
+
+void
+gallivm_remove_garbage_collector_callback(garbage_collect_callback_func func,
+ void *cb_data);
+
+
+struct gallivm_state *
+gallivm_create(void);
+
+void
+gallivm_destroy(struct gallivm_state *gallivm);
+
+
extern LLVMValueRef
lp_build_load_volatile(LLVMBuilderRef B, LLVMValueRef PointerVal,
const char *Name);
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_intr.c b/src/gallium/auxiliary/gallivm/lp_bld_intr.c
index 9895749d56..518a01fdb9 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_intr.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_intr.c
@@ -46,6 +46,7 @@
#include "util/u_debug.h"
+#include "lp_bld_const.h"
#include "lp_bld_intr.h"
@@ -136,12 +137,13 @@ lp_build_intrinsic_binary(LLVMBuilderRef builder,
LLVMValueRef
-lp_build_intrinsic_map(LLVMBuilderRef builder,
+lp_build_intrinsic_map(struct gallivm_state *gallivm,
const char *name,
LLVMTypeRef ret_type,
LLVMValueRef *args,
unsigned num_args)
{
+ LLVMBuilderRef builder = gallivm->builder;
LLVMTypeRef ret_elem_type = LLVMGetElementType(ret_type);
unsigned n = LLVMGetVectorSize(ret_type);
unsigned i, j;
@@ -151,7 +153,7 @@ lp_build_intrinsic_map(LLVMBuilderRef builder,
res = LLVMGetUndef(ret_type);
for(i = 0; i < n; ++i) {
- LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), i, 0);
+ LLVMValueRef index = lp_build_const_int32(gallivm, i);
LLVMValueRef arg_elems[LP_MAX_FUNC_ARGS];
LLVMValueRef res_elem;
for(j = 0; j < num_args; ++j)
@@ -165,17 +167,17 @@ lp_build_intrinsic_map(LLVMBuilderRef builder,
LLVMValueRef
-lp_build_intrinsic_map_unary(LLVMBuilderRef builder,
+lp_build_intrinsic_map_unary(struct gallivm_state *gallivm,
const char *name,
LLVMTypeRef ret_type,
LLVMValueRef a)
{
- return lp_build_intrinsic_map(builder, name, ret_type, &a, 1);
+ return lp_build_intrinsic_map(gallivm, name, ret_type, &a, 1);
}
LLVMValueRef
-lp_build_intrinsic_map_binary(LLVMBuilderRef builder,
+lp_build_intrinsic_map_binary(struct gallivm_state *gallivm,
const char *name,
LLVMTypeRef ret_type,
LLVMValueRef a,
@@ -186,7 +188,7 @@ lp_build_intrinsic_map_binary(LLVMBuilderRef builder,
args[0] = a;
args[1] = b;
- return lp_build_intrinsic_map(builder, name, ret_type, args, 2);
+ return lp_build_intrinsic_map(gallivm, name, ret_type, args, 2);
}
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_intr.h b/src/gallium/auxiliary/gallivm/lp_bld_intr.h
index 977f767322..b73dd70036 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_intr.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_intr.h
@@ -38,6 +38,7 @@
#include "gallivm/lp_bld.h"
+#include "gallivm/lp_bld_init.h"
/**
@@ -77,7 +78,7 @@ lp_build_intrinsic_binary(LLVMBuilderRef builder,
LLVMValueRef
-lp_build_intrinsic_map(LLVMBuilderRef builder,
+lp_build_intrinsic_map(struct gallivm_state *gallivm,
const char *name,
LLVMTypeRef ret_type,
LLVMValueRef *args,
@@ -85,14 +86,14 @@ lp_build_intrinsic_map(LLVMBuilderRef builder,
LLVMValueRef
-lp_build_intrinsic_map_unary(LLVMBuilderRef builder,
+lp_build_intrinsic_map_unary(struct gallivm_state *gallivm,
const char *name,
LLVMTypeRef ret_type,
LLVMValueRef a);
LLVMValueRef
-lp_build_intrinsic_map_binary(LLVMBuilderRef builder,
+lp_build_intrinsic_map_binary(struct gallivm_state *gallivm,
const char *name,
LLVMTypeRef ret_type,
LLVMValueRef a,
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_logic.c b/src/gallium/auxiliary/gallivm/lp_bld_logic.c
index 026b60ac36..3251516a34 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_logic.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_logic.c
@@ -39,6 +39,7 @@
#include "lp_bld_type.h"
#include "lp_bld_const.h"
+#include "lp_bld_init.h"
#include "lp_bld_intr.h"
#include "lp_bld_debug.h"
#include "lp_bld_logic.h"
@@ -70,13 +71,14 @@
* The result values will be 0 for false or ~0 for true.
*/
LLVMValueRef
-lp_build_compare(LLVMBuilderRef builder,
+lp_build_compare(struct gallivm_state *gallivm,
const struct lp_type type,
unsigned func,
LLVMValueRef a,
LLVMValueRef b)
{
- LLVMTypeRef int_vec_type = lp_build_int_vec_type(type);
+ LLVMBuilderRef builder = gallivm->builder;
+ LLVMTypeRef int_vec_type = lp_build_int_vec_type(gallivm, type);
LLVMValueRef zeros = LLVMConstNull(int_vec_type);
LLVMValueRef ones = LLVMConstAllOnes(int_vec_type);
LLVMValueRef cond;
@@ -115,7 +117,7 @@ lp_build_compare(LLVMBuilderRef builder,
if(type.width * type.length == 128) {
if(type.floating && util_cpu_caps.has_sse) {
/* float[4] comparison */
- LLVMTypeRef vec_type = lp_build_vec_type(type);
+ LLVMTypeRef vec_type = lp_build_vec_type(gallivm, type);
LLVMValueRef args[3];
unsigned cc;
boolean swap;
@@ -144,7 +146,7 @@ lp_build_compare(LLVMBuilderRef builder,
break;
default:
assert(0);
- return lp_build_undef(type);
+ return lp_build_undef(gallivm, type);
}
if(swap) {
@@ -156,7 +158,7 @@ lp_build_compare(LLVMBuilderRef builder,
args[1] = b;
}
- args[2] = LLVMConstInt(LLVMInt8Type(), cc, 0);
+ args[2] = LLVMConstInt(LLVMInt8TypeInContext(gallivm->context), cc, 0);
res = lp_build_intrinsic(builder,
"llvm.x86.sse.cmp.ps",
vec_type,
@@ -185,7 +187,7 @@ lp_build_compare(LLVMBuilderRef builder,
const char *pcmpgt;
LLVMValueRef args[2];
LLVMValueRef res;
- LLVMTypeRef vec_type = lp_build_vec_type(type);
+ LLVMTypeRef vec_type = lp_build_vec_type(gallivm, type);
switch (type.width) {
case 8:
@@ -202,14 +204,14 @@ lp_build_compare(LLVMBuilderRef builder,
break;
default:
assert(0);
- return lp_build_undef(type);
+ return lp_build_undef(gallivm, type);
}
/* There are no unsigned comparison instructions. So flip the sign bit
* so that the results match.
*/
if (table[func].gt && !type.sign) {
- LLVMValueRef msb = lp_build_const_int_vec(type, (unsigned long long)1 << (type.width - 1));
+ LLVMValueRef msb = lp_build_const_int_vec(gallivm, type, (unsigned long long)1 << (type.width - 1));
a = LLVMBuildXor(builder, a, msb, "");
b = LLVMBuildXor(builder, b, msb, "");
}
@@ -270,7 +272,7 @@ lp_build_compare(LLVMBuilderRef builder,
break;
default:
assert(0);
- return lp_build_undef(type);
+ return lp_build_undef(gallivm, type);
}
#if HAVE_LLVM >= 0x0207
@@ -289,7 +291,7 @@ lp_build_compare(LLVMBuilderRef builder,
debug_printf("%s: warning: using slow element-wise float"
" vector comparison\n", __FUNCTION__);
for (i = 0; i < type.length; ++i) {
- LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), i, 0);
+ LLVMValueRef index = lp_build_const_int32(gallivm, i);
cond = LLVMBuildFCmp(builder, op,
LLVMBuildExtractElement(builder, a, index, ""),
LLVMBuildExtractElement(builder, b, index, ""),
@@ -326,7 +328,7 @@ lp_build_compare(LLVMBuilderRef builder,
break;
default:
assert(0);
- return lp_build_undef(type);
+ return lp_build_undef(gallivm, type);
}
#if HAVE_LLVM >= 0x0207
@@ -348,7 +350,7 @@ lp_build_compare(LLVMBuilderRef builder,
}
for(i = 0; i < type.length; ++i) {
- LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), i, 0);
+ LLVMValueRef index = lp_build_const_int32(gallivm, i);
cond = LLVMBuildICmp(builder, op,
LLVMBuildExtractElement(builder, a, index, ""),
LLVMBuildExtractElement(builder, b, index, ""),
@@ -379,7 +381,7 @@ lp_build_cmp(struct lp_build_context *bld,
LLVMValueRef a,
LLVMValueRef b)
{
- return lp_build_compare(bld->builder, bld->type, func, a, b);
+ return lp_build_compare(bld->gallivm, bld->type, func, a, b);
}
@@ -403,7 +405,7 @@ lp_build_select_bitwise(struct lp_build_context *bld,
}
if(type.floating) {
- LLVMTypeRef int_vec_type = lp_build_int_vec_type(type);
+ LLVMTypeRef int_vec_type = lp_build_int_vec_type(bld->gallivm, type);
a = LLVMBuildBitCast(bld->builder, a, int_vec_type, "");
b = LLVMBuildBitCast(bld->builder, b, int_vec_type, "");
}
@@ -420,7 +422,7 @@ lp_build_select_bitwise(struct lp_build_context *bld,
res = LLVMBuildOr(bld->builder, a, b, "");
if(type.floating) {
- LLVMTypeRef vec_type = lp_build_vec_type(type);
+ LLVMTypeRef vec_type = lp_build_vec_type(bld->gallivm, type);
res = LLVMBuildBitCast(bld->builder, res, vec_type, "");
}
@@ -440,6 +442,7 @@ lp_build_select(struct lp_build_context *bld,
LLVMValueRef a,
LLVMValueRef b)
{
+ LLVMContextRef lc = bld->gallivm->context;
struct lp_type type = bld->type;
LLVMValueRef res;
@@ -450,7 +453,7 @@ lp_build_select(struct lp_build_context *bld,
return a;
if (type.length == 1) {
- mask = LLVMBuildTrunc(bld->builder, mask, LLVMInt1Type(), "");
+ mask = LLVMBuildTrunc(bld->builder, mask, LLVMInt1TypeInContext(lc), "");
res = LLVMBuildSelect(bld->builder, mask, a, b, "");
}
else if (util_cpu_caps.has_sse4_1 &&
@@ -465,14 +468,14 @@ lp_build_select(struct lp_build_context *bld,
if (type.floating &&
type.width == 64) {
intrinsic = "llvm.x86.sse41.blendvpd";
- arg_type = LLVMVectorType(LLVMDoubleType(), 2);
+ arg_type = LLVMVectorType(LLVMDoubleTypeInContext(lc), 2);
} else if (type.floating &&
type.width == 32) {
intrinsic = "llvm.x86.sse41.blendvps";
- arg_type = LLVMVectorType(LLVMFloatType(), 4);
+ arg_type = LLVMVectorType(LLVMFloatTypeInContext(lc), 4);
} else {
intrinsic = "llvm.x86.sse41.pblendvb";
- arg_type = LLVMVectorType(LLVMInt8Type(), 16);
+ arg_type = LLVMVectorType(LLVMInt8TypeInContext(lc), 16);
}
if (arg_type != bld->int_vec_type) {
@@ -544,7 +547,7 @@ lp_build_select_aos(struct lp_build_context *bld,
/*
* Shuffle.
*/
- LLVMTypeRef elem_type = LLVMInt32Type();
+ LLVMTypeRef elem_type = LLVMInt32TypeInContext(bld->gallivm->context);
LLVMValueRef shuffles[LP_MAX_VECTOR_LENGTH];
for(j = 0; j < n; j += 4)
@@ -569,7 +572,7 @@ lp_build_select_aos(struct lp_build_context *bld,
return LLVMBuildSelect(bld->builder, LLVMConstVector(cond_vec, n), a, b, "");
#else
- LLVMValueRef mask_vec = lp_build_const_mask_aos(type, mask);
+ LLVMValueRef mask_vec = lp_build_const_mask_aos(bld->gallivm, type, mask);
return lp_build_select(bld, mask_vec, a, b);
#endif
}
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_logic.h b/src/gallium/auxiliary/gallivm/lp_bld_logic.h
index 141fb92058..ef33a65368 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_logic.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_logic.h
@@ -47,7 +47,7 @@ struct lp_build_context;
LLVMValueRef
-lp_build_compare(LLVMBuilderRef builder,
+lp_build_compare(struct gallivm_state *gallivm,
const struct lp_type type,
unsigned func,
LLVMValueRef a,
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_pack.c b/src/gallium/auxiliary/gallivm/lp_bld_pack.c
index f7eb7148ab..fde6bb594f 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_pack.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_pack.c
@@ -72,6 +72,7 @@
#include "lp_bld_type.h"
#include "lp_bld_const.h"
+#include "lp_bld_init.h"
#include "lp_bld_intr.h"
#include "lp_bld_arit.h"
#include "lp_bld_pack.h"
@@ -81,7 +82,8 @@
* Build shuffle vectors that match PUNPCKLxx and PUNPCKHxx instructions.
*/
static LLVMValueRef
-lp_build_const_unpack_shuffle(unsigned n, unsigned lo_hi)
+lp_build_const_unpack_shuffle(struct gallivm_state *gallivm,
+ unsigned n, unsigned lo_hi)
{
LLVMValueRef elems[LP_MAX_VECTOR_LENGTH];
unsigned i, j;
@@ -92,8 +94,8 @@ lp_build_const_unpack_shuffle(unsigned n, unsigned lo_hi)
/* TODO: cache results in a static table */
for(i = 0, j = lo_hi*n/2; i < n; i += 2, ++j) {
- elems[i + 0] = LLVMConstInt(LLVMInt32Type(), 0 + j, 0);
- elems[i + 1] = LLVMConstInt(LLVMInt32Type(), n + j, 0);
+ elems[i + 0] = lp_build_const_int32(gallivm, 0 + j);
+ elems[i + 1] = lp_build_const_int32(gallivm, n + j);
}
return LLVMConstVector(elems, n);
@@ -104,7 +106,7 @@ lp_build_const_unpack_shuffle(unsigned n, unsigned lo_hi)
* Build shuffle vectors that match PACKxx instructions.
*/
static LLVMValueRef
-lp_build_const_pack_shuffle(unsigned n)
+lp_build_const_pack_shuffle(struct gallivm_state *gallivm, unsigned n)
{
LLVMValueRef elems[LP_MAX_VECTOR_LENGTH];
unsigned i;
@@ -112,7 +114,7 @@ lp_build_const_pack_shuffle(unsigned n)
assert(n <= LP_MAX_VECTOR_LENGTH);
for(i = 0; i < n; ++i)
- elems[i] = LLVMConstInt(LLVMInt32Type(), 2*i, 0);
+ elems[i] = lp_build_const_int32(gallivm, 2*i);
return LLVMConstVector(elems, n);
}
@@ -124,7 +126,7 @@ lp_build_const_pack_shuffle(unsigned n)
* Matches the PUNPCKLxx and PUNPCKHxx SSE instructions.
*/
LLVMValueRef
-lp_build_interleave2(LLVMBuilderRef builder,
+lp_build_interleave2(struct gallivm_state *gallivm,
struct lp_type type,
LLVMValueRef a,
LLVMValueRef b,
@@ -132,9 +134,9 @@ lp_build_interleave2(LLVMBuilderRef builder,
{
LLVMValueRef shuffle;
- shuffle = lp_build_const_unpack_shuffle(type.length, lo_hi);
+ shuffle = lp_build_const_unpack_shuffle(gallivm, type.length, lo_hi);
- return LLVMBuildShuffleVector(builder, a, b, shuffle, "");
+ return LLVMBuildShuffleVector(gallivm->builder, a, b, shuffle, "");
}
@@ -145,13 +147,14 @@ lp_build_interleave2(LLVMBuilderRef builder,
* values themselves.
*/
void
-lp_build_unpack2(LLVMBuilderRef builder,
+lp_build_unpack2(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
LLVMValueRef src,
LLVMValueRef *dst_lo,
LLVMValueRef *dst_hi)
{
+ LLVMBuilderRef builder = gallivm->builder;
LLVMValueRef msb;
LLVMTypeRef dst_vec_type;
@@ -162,24 +165,24 @@ lp_build_unpack2(LLVMBuilderRef builder,
if(dst_type.sign && src_type.sign) {
/* Replicate the sign bit in the most significant bits */
- msb = LLVMBuildAShr(builder, src, lp_build_const_int_vec(src_type, src_type.width - 1), "");
+ msb = LLVMBuildAShr(builder, src, lp_build_const_int_vec(gallivm, src_type, src_type.width - 1), "");
}
else
/* Most significant bits always zero */
- msb = lp_build_zero(src_type);
+ msb = lp_build_zero(gallivm, src_type);
/* Interleave bits */
#ifdef PIPE_ARCH_LITTLE_ENDIAN
- *dst_lo = lp_build_interleave2(builder, src_type, src, msb, 0);
- *dst_hi = lp_build_interleave2(builder, src_type, src, msb, 1);
+ *dst_lo = lp_build_interleave2(gallivm, src_type, src, msb, 0);
+ *dst_hi = lp_build_interleave2(gallivm, src_type, src, msb, 1);
#else
- *dst_lo = lp_build_interleave2(builder, src_type, msb, src, 0);
- *dst_hi = lp_build_interleave2(builder, src_type, msb, src, 1);
+ *dst_lo = lp_build_interleave2(gallivm, src_type, msb, src, 0);
+ *dst_hi = lp_build_interleave2(gallivm, src_type, msb, src, 1);
#endif
/* Cast the result into the new type (twice as wide) */
- dst_vec_type = lp_build_vec_type(dst_type);
+ dst_vec_type = lp_build_vec_type(gallivm, dst_type);
*dst_lo = LLVMBuildBitCast(builder, *dst_lo, dst_vec_type, "");
*dst_hi = LLVMBuildBitCast(builder, *dst_hi, dst_vec_type, "");
@@ -193,7 +196,7 @@ lp_build_unpack2(LLVMBuilderRef builder,
* values themselves.
*/
void
-lp_build_unpack(LLVMBuilderRef builder,
+lp_build_unpack(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
LLVMValueRef src,
@@ -218,7 +221,7 @@ lp_build_unpack(LLVMBuilderRef builder,
tmp_type.length /= 2;
for(i = num_tmps; i--; ) {
- lp_build_unpack2(builder, src_type, tmp_type, dst[i], &dst[2*i + 0], &dst[2*i + 1]);
+ lp_build_unpack2(gallivm, src_type, tmp_type, dst[i], &dst[2*i + 0], &dst[2*i + 1]);
}
src_type = tmp_type;
@@ -247,16 +250,17 @@ lp_build_unpack(LLVMBuilderRef builder,
* lp_build_packs2 instead.
*/
LLVMValueRef
-lp_build_pack2(LLVMBuilderRef builder,
+lp_build_pack2(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
LLVMValueRef lo,
LLVMValueRef hi)
{
+ LLVMBuilderRef builder = gallivm->builder;
#if HAVE_LLVM < 0x0207
- LLVMTypeRef src_vec_type = lp_build_vec_type(src_type);
+ LLVMTypeRef src_vec_type = lp_build_vec_type(gallivm, src_type);
#endif
- LLVMTypeRef dst_vec_type = lp_build_vec_type(dst_type);
+ LLVMTypeRef dst_vec_type = lp_build_vec_type(gallivm, dst_type);
LLVMValueRef shuffle;
LLVMValueRef res = NULL;
@@ -318,7 +322,7 @@ lp_build_pack2(LLVMBuilderRef builder,
lo = LLVMBuildBitCast(builder, lo, dst_vec_type, "");
hi = LLVMBuildBitCast(builder, hi, dst_vec_type, "");
- shuffle = lp_build_const_pack_shuffle(dst_type.length);
+ shuffle = lp_build_const_pack_shuffle(gallivm, dst_type.length);
res = LLVMBuildShuffleVector(builder, lo, hi, shuffle, "");
@@ -334,7 +338,7 @@ lp_build_pack2(LLVMBuilderRef builder,
* destination type.
*/
LLVMValueRef
-lp_build_packs2(LLVMBuilderRef builder,
+lp_build_packs2(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
LLVMValueRef lo,
@@ -360,14 +364,14 @@ lp_build_packs2(LLVMBuilderRef builder,
if(clamp) {
struct lp_build_context bld;
unsigned dst_bits = dst_type.sign ? dst_type.width - 1 : dst_type.width;
- LLVMValueRef dst_max = lp_build_const_int_vec(src_type, ((unsigned long long)1 << dst_bits) - 1);
- lp_build_context_init(&bld, builder, src_type);
+ LLVMValueRef dst_max = lp_build_const_int_vec(gallivm, src_type, ((unsigned long long)1 << dst_bits) - 1);
+ lp_build_context_init(&bld, gallivm, src_type);
lo = lp_build_min(&bld, lo, dst_max);
hi = lp_build_min(&bld, hi, dst_max);
/* FIXME: What about lower bound? */
}
- return lp_build_pack2(builder, src_type, dst_type, lo, hi);
+ return lp_build_pack2(gallivm, src_type, dst_type, lo, hi);
}
@@ -377,13 +381,13 @@ lp_build_packs2(LLVMBuilderRef builder,
* TODO: Handle saturation consistently.
*/
LLVMValueRef
-lp_build_pack(LLVMBuilderRef builder,
+lp_build_pack(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
boolean clamped,
const LLVMValueRef *src, unsigned num_srcs)
{
- LLVMValueRef (*pack2)(LLVMBuilderRef builder,
+ LLVMValueRef (*pack2)(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
LLVMValueRef lo,
@@ -419,7 +423,8 @@ lp_build_pack(LLVMBuilderRef builder,
num_srcs /= 2;
for(i = 0; i < num_srcs; ++i)
- tmp[i] = pack2(builder, src_type, tmp_type, tmp[2*i + 0], tmp[2*i + 1]);
+ tmp[i] = pack2(gallivm, src_type, tmp_type,
+ tmp[2*i + 0], tmp[2*i + 1]);
src_type = tmp_type;
}
@@ -437,12 +442,13 @@ lp_build_pack(LLVMBuilderRef builder,
* intrinsics that do saturation.
*/
void
-lp_build_resize(LLVMBuilderRef builder,
+lp_build_resize(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
const LLVMValueRef *src, unsigned num_srcs,
LLVMValueRef *dst, unsigned num_dsts)
{
+ LLVMBuilderRef builder = gallivm->builder;
LLVMValueRef tmp[LP_MAX_VECTOR_LENGTH];
unsigned i;
@@ -482,7 +488,7 @@ lp_build_resize(LLVMBuilderRef builder,
* Register width remains constant -- use vector packing intrinsics
*/
- tmp[0] = lp_build_pack(builder, src_type, dst_type, TRUE, src, num_srcs);
+ tmp[0] = lp_build_pack(gallivm, src_type, dst_type, TRUE, src, num_srcs);
}
else {
/*
@@ -490,11 +496,11 @@ lp_build_resize(LLVMBuilderRef builder,
*/
assert(src_type.length == dst_type.length);
- tmp[0] = lp_build_undef(dst_type);
+ tmp[0] = lp_build_undef(gallivm, dst_type);
for (i = 0; i < dst_type.length; ++i) {
- LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), i, 0);
+ LLVMValueRef index = lp_build_const_int32(gallivm, i);
LLVMValueRef val = LLVMBuildExtractElement(builder, src[0], index, "");
- val = LLVMBuildTrunc(builder, val, lp_build_elem_type(dst_type), "");
+ val = LLVMBuildTrunc(builder, val, lp_build_elem_type(gallivm, dst_type), "");
tmp[0] = LLVMBuildInsertElement(builder, tmp[0], val, index, "");
}
}
@@ -510,7 +516,7 @@ lp_build_resize(LLVMBuilderRef builder,
/*
* Register width remains constant -- use vector unpack intrinsics
*/
- lp_build_unpack(builder, src_type, dst_type, src[0], tmp, num_dsts);
+ lp_build_unpack(gallivm, src_type, dst_type, src[0], tmp, num_dsts);
}
else {
/*
@@ -518,15 +524,15 @@ lp_build_resize(LLVMBuilderRef builder,
*/
assert(src_type.length == dst_type.length);
- tmp[0] = lp_build_undef(dst_type);
+ tmp[0] = lp_build_undef(gallivm, dst_type);
for (i = 0; i < dst_type.length; ++i) {
- LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), i, 0);
+ LLVMValueRef index = lp_build_const_int32(gallivm, i);
LLVMValueRef val = LLVMBuildExtractElement(builder, src[0], index, "");
if (src_type.sign && dst_type.sign) {
- val = LLVMBuildSExt(builder, val, lp_build_elem_type(dst_type), "");
+ val = LLVMBuildSExt(builder, val, lp_build_elem_type(gallivm, dst_type), "");
} else {
- val = LLVMBuildZExt(builder, val, lp_build_elem_type(dst_type), "");
+ val = LLVMBuildZExt(builder, val, lp_build_elem_type(gallivm, dst_type), "");
}
tmp[0] = LLVMBuildInsertElement(builder, tmp[0], val, index, "");
}
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_pack.h b/src/gallium/auxiliary/gallivm/lp_bld_pack.h
index e947b90d16..d58da4f01b 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_pack.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_pack.h
@@ -46,7 +46,7 @@ struct lp_type;
LLVMValueRef
-lp_build_interleave2(LLVMBuilderRef builder,
+lp_build_interleave2(struct gallivm_state *gallivm,
struct lp_type type,
LLVMValueRef a,
LLVMValueRef b,
@@ -54,7 +54,7 @@ lp_build_interleave2(LLVMBuilderRef builder,
void
-lp_build_unpack2(LLVMBuilderRef builder,
+lp_build_unpack2(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
LLVMValueRef src,
@@ -63,7 +63,7 @@ lp_build_unpack2(LLVMBuilderRef builder,
void
-lp_build_unpack(LLVMBuilderRef builder,
+lp_build_unpack(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
LLVMValueRef src,
@@ -71,7 +71,7 @@ lp_build_unpack(LLVMBuilderRef builder,
LLVMValueRef
-lp_build_packs2(LLVMBuilderRef builder,
+lp_build_packs2(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
LLVMValueRef lo,
@@ -79,7 +79,7 @@ lp_build_packs2(LLVMBuilderRef builder,
LLVMValueRef
-lp_build_pack2(LLVMBuilderRef builder,
+lp_build_pack2(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
LLVMValueRef lo,
@@ -87,7 +87,7 @@ lp_build_pack2(LLVMBuilderRef builder,
LLVMValueRef
-lp_build_pack(LLVMBuilderRef builder,
+lp_build_pack(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
boolean clamped,
@@ -95,7 +95,7 @@ lp_build_pack(LLVMBuilderRef builder,
void
-lp_build_resize(LLVMBuilderRef builder,
+lp_build_resize(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
const LLVMValueRef *src, unsigned num_srcs,
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_printf.c b/src/gallium/auxiliary/gallivm/lp_bld_printf.c
index f418e96aff..60cc6094f5 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_printf.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_printf.c
@@ -31,6 +31,8 @@
#include "util/u_memory.h"
#include "util/u_string.h"
#include "lp_bld_const.h"
+#include "lp_bld_init.h"
+#include "lp_bld_const.h"
#include "lp_bld_printf.h"
@@ -65,12 +67,14 @@ lp_get_printf_arg_count(const char *fmt)
}
LLVMValueRef
-lp_build_const_string_variable(LLVMModuleRef module, const char *str, int len)
+lp_build_const_string_variable(LLVMModuleRef module,
+ LLVMContextRef context,
+ const char *str, int len)
{
- LLVMValueRef string = LLVMAddGlobal(module, LLVMArrayType(LLVMInt8Type(), len + 1), "");
+ LLVMValueRef string = LLVMAddGlobal(module, LLVMArrayType(LLVMInt8TypeInContext(context), len + 1), "");
LLVMSetGlobalConstant(string, TRUE);
LLVMSetLinkage(string, LLVMInternalLinkage);
- LLVMSetInitializer(string, LLVMConstString(str, len + 1, TRUE));
+ LLVMSetInitializer(string, LLVMConstStringInContext(context, str, len + 1, TRUE));
return string;
}
@@ -83,15 +87,18 @@ lp_build_const_string_variable(LLVMModuleRef module, const char *str, int len)
* LLVMValueRef.
*/
LLVMValueRef
-lp_build_printf(LLVMBuilderRef builder, const char *fmt, ...)
+lp_build_printf(struct gallivm_state *gallivm, const char *fmt, ...)
{
va_list arglist;
int i = 0;
int argcount = lp_get_printf_arg_count(fmt);
- LLVMModuleRef module = LLVMGetGlobalParent(LLVMGetBasicBlockParent(LLVMGetInsertBlock(builder)));
+ LLVMBuilderRef builder = gallivm->builder;
+ LLVMContextRef context = gallivm->context;
+ LLVMModuleRef module = gallivm->module;
LLVMValueRef params[50];
- LLVMValueRef fmtarg = lp_build_const_string_variable(module, fmt, strlen(fmt) + 1);
- LLVMValueRef int0 = LLVMConstInt(LLVMInt32Type(), 0, 0);
+ LLVMValueRef fmtarg = lp_build_const_string_variable(module, context,
+ fmt, strlen(fmt) + 1);
+ LLVMValueRef int0 = lp_build_const_int32(gallivm, 0);
LLVMValueRef index[2];
LLVMValueRef func_printf = LLVMGetNamedFunction(module, "printf");
@@ -100,7 +107,7 @@ lp_build_printf(LLVMBuilderRef builder, const char *fmt, ...)
index[0] = index[1] = int0;
if (!func_printf) {
- LLVMTypeRef printf_type = LLVMFunctionType(LLVMIntType(32), NULL, 0, 1);
+ LLVMTypeRef printf_type = LLVMFunctionType(LLVMIntTypeInContext(context, 32), NULL, 0, 1);
func_printf = LLVMAddFunction(module, "printf", printf_type);
}
@@ -113,7 +120,7 @@ lp_build_printf(LLVMBuilderRef builder, const char *fmt, ...)
/* printf wants doubles, so lets convert so that
* we can actually print them */
if (LLVMGetTypeKind(type) == LLVMFloatTypeKind)
- val = LLVMBuildFPExt(builder, val, LLVMDoubleType(), "");
+ val = LLVMBuildFPExt(builder, val, LLVMDoubleTypeInContext(context), "");
params[i] = val;
}
va_end(arglist);
@@ -127,16 +134,18 @@ lp_build_printf(LLVMBuilderRef builder, const char *fmt, ...)
* Print a float[4] vector.
*/
LLVMValueRef
-lp_build_print_vec4(LLVMBuilderRef builder, const char *msg, LLVMValueRef vec)
+lp_build_print_vec4(struct gallivm_state *gallivm,
+ const char *msg, LLVMValueRef vec)
{
+ LLVMBuilderRef builder = gallivm->builder;
char format[1000];
LLVMValueRef x, y, z, w;
- x = LLVMBuildExtractElement(builder, vec, lp_build_const_int32(0), "");
- y = LLVMBuildExtractElement(builder, vec, lp_build_const_int32(1), "");
- z = LLVMBuildExtractElement(builder, vec, lp_build_const_int32(2), "");
- w = LLVMBuildExtractElement(builder, vec, lp_build_const_int32(3), "");
+ x = LLVMBuildExtractElement(builder, vec, lp_build_const_int32(gallivm, 0), "");
+ y = LLVMBuildExtractElement(builder, vec, lp_build_const_int32(gallivm, 1), "");
+ z = LLVMBuildExtractElement(builder, vec, lp_build_const_int32(gallivm, 2), "");
+ w = LLVMBuildExtractElement(builder, vec, lp_build_const_int32(gallivm, 3), "");
util_snprintf(format, sizeof(format), "%s %%f %%f %%f %%f\n", msg);
- return lp_build_printf(builder, format, x, y, z, w);
+ return lp_build_printf(gallivm, format, x, y, z, w);
}
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_printf.h b/src/gallium/auxiliary/gallivm/lp_bld_printf.h
index b6222c62eb..f6bb834869 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_printf.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_printf.h
@@ -31,12 +31,19 @@
#include "pipe/p_compiler.h"
#include "lp_bld.h"
+#include "lp_bld_init.h"
-LLVMValueRef lp_build_const_string_variable(LLVMModuleRef module, const char *str, int len);
-LLVMValueRef lp_build_printf(LLVMBuilderRef builder, const char *fmt, ...);
+
+LLVMValueRef lp_build_const_string_variable(LLVMModuleRef module,
+ LLVMContextRef context,
+ const char *str, int len);
+
+LLVMValueRef lp_build_printf(struct gallivm_state *gallivm,
+ const char *fmt, ...);
LLVMValueRef
-lp_build_print_vec4(LLVMBuilderRef builder, const char *msg, LLVMValueRef vec);
+lp_build_print_vec4(struct gallivm_state *gallivm,
+ const char *msg, LLVMValueRef vec);
#endif
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_quad.c b/src/gallium/auxiliary/gallivm/lp_bld_quad.c
index c18c8b4710..4ce2c4eccd 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_quad.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_quad.c
@@ -28,6 +28,7 @@
#include "lp_bld_type.h"
#include "lp_bld_arit.h"
+#include "lp_bld_const.h"
#include "lp_bld_swizzle.h"
#include "lp_bld_quad.h"
@@ -81,9 +82,8 @@ LLVMValueRef
lp_build_scalar_ddx(struct lp_build_context *bld,
LLVMValueRef a)
{
- LLVMTypeRef i32t = LLVMInt32Type();
- LLVMValueRef idx_left = LLVMConstInt(i32t, LP_BLD_QUAD_TOP_LEFT, 0);
- LLVMValueRef idx_right = LLVMConstInt(i32t, LP_BLD_QUAD_TOP_RIGHT, 0);
+ LLVMValueRef idx_left = lp_build_const_int32(bld->gallivm, LP_BLD_QUAD_TOP_LEFT);
+ LLVMValueRef idx_right = lp_build_const_int32(bld->gallivm, LP_BLD_QUAD_TOP_RIGHT);
LLVMValueRef a_left = LLVMBuildExtractElement(bld->builder, a, idx_left, "left");
LLVMValueRef a_right = LLVMBuildExtractElement(bld->builder, a, idx_right, "right");
if (bld->type.floating)
@@ -97,9 +97,8 @@ LLVMValueRef
lp_build_scalar_ddy(struct lp_build_context *bld,
LLVMValueRef a)
{
- LLVMTypeRef i32t = LLVMInt32Type();
- LLVMValueRef idx_top = LLVMConstInt(i32t, LP_BLD_QUAD_TOP_LEFT, 0);
- LLVMValueRef idx_bottom = LLVMConstInt(i32t, LP_BLD_QUAD_BOTTOM_LEFT, 0);
+ LLVMValueRef idx_top = lp_build_const_int32(bld->gallivm, LP_BLD_QUAD_TOP_LEFT);
+ LLVMValueRef idx_bottom = lp_build_const_int32(bld->gallivm, LP_BLD_QUAD_BOTTOM_LEFT);
LLVMValueRef a_top = LLVMBuildExtractElement(bld->builder, a, idx_top, "top");
LLVMValueRef a_bottom = LLVMBuildExtractElement(bld->builder, a, idx_bottom, "bottom");
if (bld->type.floating)
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample.c b/src/gallium/auxiliary/gallivm/lp_bld_sample.c
index 844d1d935b..771095f43a 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_sample.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_sample.c
@@ -190,7 +190,8 @@ lp_build_rho(struct lp_build_sample_context *bld,
struct lp_build_context *float_size_bld = &bld->float_size_bld;
struct lp_build_context *float_bld = &bld->float_bld;
const unsigned dims = bld->dims;
- LLVMTypeRef i32t = LLVMInt32Type();
+ LLVMBuilderRef builder = bld->gallivm->builder;
+ LLVMTypeRef i32t = LLVMInt32TypeInContext(bld->gallivm->context);
LLVMValueRef index0 = LLVMConstInt(i32t, 0, 0);
LLVMValueRef index1 = LLVMConstInt(i32t, 1, 0);
LLVMValueRef index2 = LLVMConstInt(i32t, 2, 0);
@@ -211,21 +212,21 @@ lp_build_rho(struct lp_build_sample_context *bld,
rho_x = float_size_bld->undef;
rho_y = float_size_bld->undef;
- rho_x = LLVMBuildInsertElement(bld->builder, rho_x, dsdx, index0, "");
- rho_y = LLVMBuildInsertElement(bld->builder, rho_y, dsdy, index0, "");
+ rho_x = LLVMBuildInsertElement(builder, rho_x, dsdx, index0, "");
+ rho_y = LLVMBuildInsertElement(builder, rho_y, dsdy, index0, "");
dtdx = ddx[1];
dtdy = ddy[1];
- rho_x = LLVMBuildInsertElement(bld->builder, rho_x, dtdx, index1, "");
- rho_y = LLVMBuildInsertElement(bld->builder, rho_y, dtdy, index1, "");
+ rho_x = LLVMBuildInsertElement(builder, rho_x, dtdx, index1, "");
+ rho_y = LLVMBuildInsertElement(builder, rho_y, dtdy, index1, "");
if (dims >= 3) {
drdx = ddx[2];
drdy = ddy[2];
- rho_x = LLVMBuildInsertElement(bld->builder, rho_x, drdx, index2, "");
- rho_y = LLVMBuildInsertElement(bld->builder, rho_y, drdy, index2, "");
+ rho_x = LLVMBuildInsertElement(builder, rho_x, drdx, index2, "");
+ rho_y = LLVMBuildInsertElement(builder, rho_y, drdy, index2, "");
}
}
@@ -245,13 +246,13 @@ lp_build_rho(struct lp_build_sample_context *bld,
if (dims >= 2) {
LLVMValueRef rho_s, rho_t, rho_r;
- rho_s = LLVMBuildExtractElement(bld->builder, rho_vec, index0, "");
- rho_t = LLVMBuildExtractElement(bld->builder, rho_vec, index1, "");
+ rho_s = LLVMBuildExtractElement(builder, rho_vec, index0, "");
+ rho_t = LLVMBuildExtractElement(builder, rho_vec, index1, "");
rho = lp_build_max(float_bld, rho_s, rho_t);
if (dims >= 3) {
- rho_r = LLVMBuildExtractElement(bld->builder, rho_vec, index0, "");
+ rho_r = LLVMBuildExtractElement(builder, rho_vec, index0, "");
rho = lp_build_max(float_bld, rho, rho_r);
}
}
@@ -304,19 +305,19 @@ lp_build_brilinear_lod(struct lp_build_context *bld,
double post_offset = 1 - factor;
if (0) {
- lp_build_printf(bld->builder, "lod = %f\n", lod);
+ lp_build_printf(bld->gallivm, "lod = %f\n", lod);
}
lod = lp_build_add(bld, lod,
- lp_build_const_vec(bld->type, pre_offset));
+ lp_build_const_vec(bld->gallivm, bld->type, pre_offset));
lp_build_ifloor_fract(bld, lod, out_lod_ipart, &lod_fpart);
lod_fpart = lp_build_mul(bld, lod_fpart,
- lp_build_const_vec(bld->type, factor));
+ lp_build_const_vec(bld->gallivm, bld->type, factor));
lod_fpart = lp_build_add(bld, lod_fpart,
- lp_build_const_vec(bld->type, post_offset));
+ lp_build_const_vec(bld->gallivm, bld->type, post_offset));
/*
* It's not necessary to clamp lod_fpart since:
@@ -327,8 +328,8 @@ lp_build_brilinear_lod(struct lp_build_context *bld,
*out_lod_fpart = lod_fpart;
if (0) {
- lp_build_printf(bld->builder, "lod_ipart = %i\n", *out_lod_ipart);
- lp_build_printf(bld->builder, "lod_fpart = %f\n\n", *out_lod_fpart);
+ lp_build_printf(bld->gallivm, "lod_ipart = %i\n", *out_lod_ipart);
+ lp_build_printf(bld->gallivm, "lod_fpart = %f\n\n", *out_lod_fpart);
}
}
@@ -363,7 +364,7 @@ lp_build_brilinear_rho(struct lp_build_context *bld,
* part will not need any post adjustments.
*/
rho = lp_build_mul(bld, rho,
- lp_build_const_vec(bld->type, pre_factor));
+ lp_build_const_vec(bld->gallivm, bld->type, pre_factor));
/* ipart = ifloor(log2(rho)) */
lod_ipart = lp_build_extract_exponent(bld, rho, 0);
@@ -372,10 +373,10 @@ lp_build_brilinear_rho(struct lp_build_context *bld,
lod_fpart = lp_build_extract_mantissa(bld, rho);
lod_fpart = lp_build_mul(bld, lod_fpart,
- lp_build_const_vec(bld->type, factor));
+ lp_build_const_vec(bld->gallivm, bld->type, factor));
lod_fpart = lp_build_add(bld, lod_fpart,
- lp_build_const_vec(bld->type, post_offset));
+ lp_build_const_vec(bld->gallivm, bld->type, post_offset));
/*
* Like lp_build_brilinear_lod, it's not necessary to clamp lod_fpart since:
@@ -413,6 +414,7 @@ lp_build_lod_selector(struct lp_build_sample_context *bld,
LLVMValueRef *out_lod_fpart)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
struct lp_build_context *float_bld = &bld->float_bld;
LLVMValueRef lod;
@@ -424,17 +426,17 @@ lp_build_lod_selector(struct lp_build_sample_context *bld,
* This is hit during mipmap generation.
*/
LLVMValueRef min_lod =
- bld->dynamic_state->min_lod(bld->dynamic_state, bld->builder, unit);
+ bld->dynamic_state->min_lod(bld->dynamic_state, bld->gallivm, unit);
lod = min_lod;
}
else {
LLVMValueRef sampler_lod_bias =
- bld->dynamic_state->lod_bias(bld->dynamic_state, bld->builder, unit);
- LLVMValueRef index0 = LLVMConstInt(LLVMInt32Type(), 0, 0);
+ bld->dynamic_state->lod_bias(bld->dynamic_state, bld->gallivm, unit);
+ LLVMValueRef index0 = lp_build_const_int32(bld->gallivm, 0);
if (explicit_lod) {
- lod = LLVMBuildExtractElement(bld->builder, explicit_lod,
+ lod = LLVMBuildExtractElement(builder, explicit_lod,
index0, "");
}
else {
@@ -479,27 +481,27 @@ lp_build_lod_selector(struct lp_build_sample_context *bld,
/* add shader lod bias */
if (lod_bias) {
- lod_bias = LLVMBuildExtractElement(bld->builder, lod_bias,
+ lod_bias = LLVMBuildExtractElement(builder, lod_bias,
index0, "");
- lod = LLVMBuildFAdd(bld->builder, lod, lod_bias, "shader_lod_bias");
+ lod = LLVMBuildFAdd(builder, lod, lod_bias, "shader_lod_bias");
}
}
/* add sampler lod bias */
if (bld->static_state->lod_bias_non_zero)
- lod = LLVMBuildFAdd(bld->builder, lod, sampler_lod_bias, "sampler_lod_bias");
+ lod = LLVMBuildFAdd(builder, lod, sampler_lod_bias, "sampler_lod_bias");
/* clamp lod */
if (bld->static_state->apply_max_lod) {
LLVMValueRef max_lod =
- bld->dynamic_state->max_lod(bld->dynamic_state, bld->builder, unit);
+ bld->dynamic_state->max_lod(bld->dynamic_state, bld->gallivm, unit);
lod = lp_build_min(float_bld, lod, max_lod);
}
if (bld->static_state->apply_min_lod) {
LLVMValueRef min_lod =
- bld->dynamic_state->min_lod(bld->dynamic_state, bld->builder, unit);
+ bld->dynamic_state->min_lod(bld->dynamic_state, bld->gallivm, unit);
lod = lp_build_max(float_bld, lod, min_lod);
}
@@ -542,10 +544,10 @@ lp_build_nearest_mip_level(struct lp_build_sample_context *bld,
struct lp_build_context *int_bld = &bld->int_bld;
LLVMValueRef last_level, level;
- LLVMValueRef zero = LLVMConstInt(LLVMInt32Type(), 0, 0);
+ LLVMValueRef zero = lp_build_const_int32(bld->gallivm, 0);
last_level = bld->dynamic_state->last_level(bld->dynamic_state,
- bld->builder, unit);
+ bld->gallivm, unit);
/* convert float lod to integer */
level = lod_ipart;
@@ -568,7 +570,7 @@ lp_build_linear_mip_levels(struct lp_build_sample_context *bld,
LLVMValueRef *level0_out,
LLVMValueRef *level1_out)
{
- LLVMBuilderRef builder = bld->builder;
+ LLVMBuilderRef builder = bld->gallivm->builder;
struct lp_build_context *int_bld = &bld->int_bld;
struct lp_build_context *float_bld = &bld->float_bld;
LLVMValueRef last_level;
@@ -579,7 +581,7 @@ lp_build_linear_mip_levels(struct lp_build_sample_context *bld,
*level1_out = lp_build_add(int_bld, lod_ipart, int_bld->one);
last_level = bld->dynamic_state->last_level(bld->dynamic_state,
- bld->builder, unit);
+ bld->gallivm, unit);
/*
* Clamp both lod_ipart and lod_ipart + 1 to [0, last_level], with the
@@ -630,11 +632,13 @@ LLVMValueRef
lp_build_get_mipmap_level(struct lp_build_sample_context *bld,
LLVMValueRef level)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
LLVMValueRef indexes[2], data_ptr;
- indexes[0] = LLVMConstInt(LLVMInt32Type(), 0, 0);
+
+ indexes[0] = lp_build_const_int32(bld->gallivm, 0);
indexes[1] = level;
- data_ptr = LLVMBuildGEP(bld->builder, bld->data_array, indexes, 2, "");
- data_ptr = LLVMBuildLoad(bld->builder, data_ptr, "");
+ data_ptr = LLVMBuildGEP(builder, bld->data_array, indexes, 2, "");
+ data_ptr = LLVMBuildLoad(builder, data_ptr, "");
return data_ptr;
}
@@ -643,7 +647,7 @@ LLVMValueRef
lp_build_get_const_mipmap_level(struct lp_build_sample_context *bld,
int level)
{
- LLVMValueRef lvl = LLVMConstInt(LLVMInt32Type(), level, 0);
+ LLVMValueRef lvl = lp_build_const_int32(bld->gallivm, level);
return lp_build_get_mipmap_level(bld, lvl);
}
@@ -682,11 +686,12 @@ static LLVMValueRef
lp_build_get_level_stride_vec(struct lp_build_sample_context *bld,
LLVMValueRef stride_array, LLVMValueRef level)
{
+ LLVMBuilderRef builder = bld->gallivm->builder;
LLVMValueRef indexes[2], stride;
- indexes[0] = LLVMConstInt(LLVMInt32Type(), 0, 0);
+ indexes[0] = lp_build_const_int32(bld->gallivm, 0);
indexes[1] = level;
- stride = LLVMBuildGEP(bld->builder, stride_array, indexes, 2, "");
- stride = LLVMBuildLoad(bld->builder, stride, "");
+ stride = LLVMBuildGEP(builder, stride_array, indexes, 2, "");
+ stride = LLVMBuildLoad(builder, stride, "");
stride = lp_build_broadcast_scalar(&bld->int_coord_bld, stride);
return stride;
}
@@ -747,21 +752,21 @@ lp_build_extract_image_sizes(struct lp_build_sample_context *bld,
LLVMValueRef *out_depth)
{
const unsigned dims = bld->dims;
- LLVMTypeRef i32t = LLVMInt32Type();
+ LLVMTypeRef i32t = LLVMInt32TypeInContext(bld->gallivm->context);
- *out_width = lp_build_extract_broadcast(bld->builder,
+ *out_width = lp_build_extract_broadcast(bld->gallivm,
size_type,
coord_type,
size,
LLVMConstInt(i32t, 0, 0));
if (dims >= 2) {
- *out_height = lp_build_extract_broadcast(bld->builder,
+ *out_height = lp_build_extract_broadcast(bld->gallivm,
size_type,
coord_type,
size,
LLVMConstInt(i32t, 1, 0));
if (dims == 3) {
- *out_depth = lp_build_extract_broadcast(bld->builder,
+ *out_depth = lp_build_extract_broadcast(bld->gallivm,
size_type,
coord_type,
size,
@@ -812,7 +817,7 @@ static LLVMValueRef
lp_build_cube_ima(struct lp_build_context *coord_bld, LLVMValueRef coord)
{
/* ima = -0.5 / abs(coord); */
- LLVMValueRef negHalf = lp_build_const_vec(coord_bld->type, -0.5);
+ LLVMValueRef negHalf = lp_build_const_vec(coord_bld->gallivm, coord_bld->type, -0.5);
LLVMValueRef absCoord = lp_build_abs(coord_bld, coord);
LLVMValueRef ima = lp_build_div(coord_bld, negHalf, absCoord);
return ima;
@@ -831,7 +836,7 @@ lp_build_cube_coord(struct lp_build_context *coord_bld,
LLVMValueRef coord, LLVMValueRef ima)
{
/* return negate(coord) * ima * sign + 0.5; */
- LLVMValueRef half = lp_build_const_vec(coord_bld->type, 0.5);
+ LLVMValueRef half = lp_build_const_vec(coord_bld->gallivm, coord_bld->type, 0.5);
LLVMValueRef res;
assert(negate_coord == +1 || negate_coord == -1);
@@ -859,12 +864,14 @@ lp_build_cube_face(struct lp_build_sample_context *bld,
LLVMValueRef major_coord,
unsigned pos_face, unsigned neg_face)
{
- LLVMValueRef cmp = LLVMBuildFCmp(bld->builder, LLVMRealUGE,
+ struct gallivm_state *gallivm = bld->gallivm;
+ LLVMBuilderRef builder = gallivm->builder;
+ LLVMValueRef cmp = LLVMBuildFCmp(builder, LLVMRealUGE,
major_coord,
bld->float_bld.zero, "");
- LLVMValueRef pos = LLVMConstInt(LLVMInt32Type(), pos_face, 0);
- LLVMValueRef neg = LLVMConstInt(LLVMInt32Type(), neg_face, 0);
- LLVMValueRef res = LLVMBuildSelect(bld->builder, cmp, pos, neg, "");
+ LLVMValueRef pos = lp_build_const_int32(gallivm, pos_face);
+ LLVMValueRef neg = lp_build_const_int32(gallivm, neg_face);
+ LLVMValueRef res = LLVMBuildSelect(builder, cmp, pos, neg, "");
return res;
}
@@ -884,9 +891,10 @@ lp_build_cube_lookup(struct lp_build_sample_context *bld,
{
struct lp_build_context *float_bld = &bld->float_bld;
struct lp_build_context *coord_bld = &bld->coord_bld;
+ LLVMBuilderRef builder = bld->gallivm->builder;
LLVMValueRef rx, ry, rz;
LLVMValueRef arx, ary, arz;
- LLVMValueRef c25 = LLVMConstReal(LLVMFloatType(), 0.25);
+ LLVMValueRef c25 = lp_build_const_float(bld->gallivm, 0.25);
LLVMValueRef arx_ge_ary, arx_ge_arz;
LLVMValueRef ary_ge_arx, ary_ge_arz;
LLVMValueRef arx_ge_ary_arz, ary_ge_arx_arz;
@@ -911,17 +919,17 @@ lp_build_cube_lookup(struct lp_build_sample_context *bld,
/*
* Compare sign/magnitude of rx,ry,rz to determine face
*/
- arx_ge_ary = LLVMBuildFCmp(bld->builder, LLVMRealUGE, arx, ary, "");
- arx_ge_arz = LLVMBuildFCmp(bld->builder, LLVMRealUGE, arx, arz, "");
- ary_ge_arx = LLVMBuildFCmp(bld->builder, LLVMRealUGE, ary, arx, "");
- ary_ge_arz = LLVMBuildFCmp(bld->builder, LLVMRealUGE, ary, arz, "");
+ arx_ge_ary = LLVMBuildFCmp(builder, LLVMRealUGE, arx, ary, "");
+ arx_ge_arz = LLVMBuildFCmp(builder, LLVMRealUGE, arx, arz, "");
+ ary_ge_arx = LLVMBuildFCmp(builder, LLVMRealUGE, ary, arx, "");
+ ary_ge_arz = LLVMBuildFCmp(builder, LLVMRealUGE, ary, arz, "");
- arx_ge_ary_arz = LLVMBuildAnd(bld->builder, arx_ge_ary, arx_ge_arz, "");
- ary_ge_arx_arz = LLVMBuildAnd(bld->builder, ary_ge_arx, ary_ge_arz, "");
+ arx_ge_ary_arz = LLVMBuildAnd(builder, arx_ge_ary, arx_ge_arz, "");
+ ary_ge_arx_arz = LLVMBuildAnd(builder, ary_ge_arx, ary_ge_arz, "");
- rx_pos = LLVMBuildFCmp(bld->builder, LLVMRealUGE, rx, float_bld->zero, "");
- ry_pos = LLVMBuildFCmp(bld->builder, LLVMRealUGE, ry, float_bld->zero, "");
- rz_pos = LLVMBuildFCmp(bld->builder, LLVMRealUGE, rz, float_bld->zero, "");
+ rx_pos = LLVMBuildFCmp(builder, LLVMRealUGE, rx, float_bld->zero, "");
+ ry_pos = LLVMBuildFCmp(builder, LLVMRealUGE, ry, float_bld->zero, "");
+ rz_pos = LLVMBuildFCmp(builder, LLVMRealUGE, rz, float_bld->zero, "");
{
struct lp_build_if_state if_ctx;
@@ -929,11 +937,11 @@ lp_build_cube_lookup(struct lp_build_sample_context *bld,
LLVMValueRef face_t_var;
LLVMValueRef face_var;
- face_s_var = lp_build_alloca(bld->builder, bld->coord_bld.vec_type, "face_s_var");
- face_t_var = lp_build_alloca(bld->builder, bld->coord_bld.vec_type, "face_t_var");
- face_var = lp_build_alloca(bld->builder, bld->int_bld.vec_type, "face_var");
+ face_s_var = lp_build_alloca(bld->gallivm, bld->coord_bld.vec_type, "face_s_var");
+ face_t_var = lp_build_alloca(bld->gallivm, bld->coord_bld.vec_type, "face_t_var");
+ face_var = lp_build_alloca(bld->gallivm, bld->int_bld.vec_type, "face_var");
- lp_build_if(&if_ctx, bld->builder, arx_ge_ary_arz);
+ lp_build_if(&if_ctx, bld->gallivm, arx_ge_ary_arz);
{
/* +/- X face */
LLVMValueRef sign = lp_build_sgn(float_bld, rx);
@@ -943,17 +951,17 @@ lp_build_cube_lookup(struct lp_build_sample_context *bld,
*face = lp_build_cube_face(bld, rx,
PIPE_TEX_FACE_POS_X,
PIPE_TEX_FACE_NEG_X);
- LLVMBuildStore(bld->builder, *face_s, face_s_var);
- LLVMBuildStore(bld->builder, *face_t, face_t_var);
- LLVMBuildStore(bld->builder, *face, face_var);
+ LLVMBuildStore(builder, *face_s, face_s_var);
+ LLVMBuildStore(builder, *face_t, face_t_var);
+ LLVMBuildStore(builder, *face, face_var);
}
lp_build_else(&if_ctx);
{
struct lp_build_if_state if_ctx2;
- ary_ge_arx_arz = LLVMBuildAnd(bld->builder, ary_ge_arx, ary_ge_arz, "");
+ ary_ge_arx_arz = LLVMBuildAnd(builder, ary_ge_arx, ary_ge_arz, "");
- lp_build_if(&if_ctx2, bld->builder, ary_ge_arx_arz);
+ lp_build_if(&if_ctx2, bld->gallivm, ary_ge_arx_arz);
{
/* +/- Y face */
LLVMValueRef sign = lp_build_sgn(float_bld, ry);
@@ -963,9 +971,9 @@ lp_build_cube_lookup(struct lp_build_sample_context *bld,
*face = lp_build_cube_face(bld, ry,
PIPE_TEX_FACE_POS_Y,
PIPE_TEX_FACE_NEG_Y);
- LLVMBuildStore(bld->builder, *face_s, face_s_var);
- LLVMBuildStore(bld->builder, *face_t, face_t_var);
- LLVMBuildStore(bld->builder, *face, face_var);
+ LLVMBuildStore(builder, *face_s, face_s_var);
+ LLVMBuildStore(builder, *face_t, face_t_var);
+ LLVMBuildStore(builder, *face, face_var);
}
lp_build_else(&if_ctx2);
{
@@ -977,18 +985,18 @@ lp_build_cube_lookup(struct lp_build_sample_context *bld,
*face = lp_build_cube_face(bld, rz,
PIPE_TEX_FACE_POS_Z,
PIPE_TEX_FACE_NEG_Z);
- LLVMBuildStore(bld->builder, *face_s, face_s_var);
- LLVMBuildStore(bld->builder, *face_t, face_t_var);
- LLVMBuildStore(bld->builder, *face, face_var);
+ LLVMBuildStore(builder, *face_s, face_s_var);
+ LLVMBuildStore(builder, *face_t, face_t_var);
+ LLVMBuildStore(builder, *face, face_var);
}
lp_build_endif(&if_ctx2);
}
lp_build_endif(&if_ctx);
- *face_s = LLVMBuildLoad(bld->builder, face_s_var, "face_s");
- *face_t = LLVMBuildLoad(bld->builder, face_t_var, "face_t");
- *face = LLVMBuildLoad(bld->builder, face_var, "face");
+ *face_s = LLVMBuildLoad(builder, face_s_var, "face_s");
+ *face_t = LLVMBuildLoad(builder, face_t_var, "face_t");
+ *face = LLVMBuildLoad(builder, face_var, "face");
}
}
@@ -1032,8 +1040,8 @@ lp_build_sample_partial_offset(struct lp_build_context *bld,
coord = LLVMBuildUDiv(bld->builder, coord, block_width, "");
#else
unsigned logbase2 = util_unsigned_logbase2(block_length);
- LLVMValueRef block_shift = lp_build_const_int_vec(bld->type, logbase2);
- LLVMValueRef block_mask = lp_build_const_int_vec(bld->type, block_length - 1);
+ LLVMValueRef block_shift = lp_build_const_int_vec(bld->gallivm, bld->type, logbase2);
+ LLVMValueRef block_mask = lp_build_const_int_vec(bld->gallivm, bld->type, block_length - 1);
subcoord = LLVMBuildAnd(bld->builder, coord, block_mask, "");
coord = LLVMBuildLShr(bld->builder, coord, block_shift, "");
#endif
@@ -1071,7 +1079,8 @@ lp_build_sample_offset(struct lp_build_context *bld,
LLVMValueRef x_stride;
LLVMValueRef offset;
- x_stride = lp_build_const_vec(bld->type, format_desc->block.bits/8);
+ x_stride = lp_build_const_vec(bld->gallivm, bld->type,
+ format_desc->block.bits/8);
lp_build_sample_partial_offset(bld,
format_desc->block.width,
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample.h b/src/gallium/auxiliary/gallivm/lp_bld_sample.h
index ffed27cee8..8c9d5df4e4 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_sample.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_sample.h
@@ -105,64 +105,64 @@ struct lp_sampler_dynamic_state
/** Obtain the base texture width (returns int32) */
LLVMValueRef
(*width)( const struct lp_sampler_dynamic_state *state,
- LLVMBuilderRef builder,
+ struct gallivm_state *gallivm,
unsigned unit);
/** Obtain the base texture height (returns int32) */
LLVMValueRef
(*height)( const struct lp_sampler_dynamic_state *state,
- LLVMBuilderRef builder,
+ struct gallivm_state *gallivm,
unsigned unit);
/** Obtain the base texture depth (returns int32) */
LLVMValueRef
(*depth)( const struct lp_sampler_dynamic_state *state,
- LLVMBuilderRef builder,
+ struct gallivm_state *gallivm,
unsigned unit);
/** Obtain the number of mipmap levels minus one (returns int32) */
LLVMValueRef
(*last_level)( const struct lp_sampler_dynamic_state *state,
- LLVMBuilderRef builder,
+ struct gallivm_state *gallivm,
unsigned unit);
/** Obtain stride in bytes between image rows/blocks (returns int32) */
LLVMValueRef
(*row_stride)( const struct lp_sampler_dynamic_state *state,
- LLVMBuilderRef builder,
+ struct gallivm_state *gallivm,
unsigned unit);
/** Obtain stride in bytes between image slices (returns int32) */
LLVMValueRef
(*img_stride)( const struct lp_sampler_dynamic_state *state,
- LLVMBuilderRef builder,
+ struct gallivm_state *gallivm,
unsigned unit);
/** Obtain pointer to array of pointers to mimpap levels */
LLVMValueRef
(*data_ptr)( const struct lp_sampler_dynamic_state *state,
- LLVMBuilderRef builder,
+ struct gallivm_state *gallivm,
unsigned unit);
/** Obtain texture min lod (returns float) */
LLVMValueRef
(*min_lod)(const struct lp_sampler_dynamic_state *state,
- LLVMBuilderRef builder, unsigned unit);
+ struct gallivm_state *gallivm, unsigned unit);
/** Obtain texture max lod (returns float) */
LLVMValueRef
(*max_lod)(const struct lp_sampler_dynamic_state *state,
- LLVMBuilderRef builder, unsigned unit);
+ struct gallivm_state *gallivm, unsigned unit);
/** Obtain texture lod bias (returns float) */
LLVMValueRef
(*lod_bias)(const struct lp_sampler_dynamic_state *state,
- LLVMBuilderRef builder, unsigned unit);
+ struct gallivm_state *gallivm, unsigned unit);
/** Obtain texture border color (returns ptr to float[4]) */
LLVMValueRef
(*border_color)(const struct lp_sampler_dynamic_state *state,
- LLVMBuilderRef builder, unsigned unit);
+ struct gallivm_state *gallivm, unsigned unit);
};
@@ -171,7 +171,7 @@ struct lp_sampler_dynamic_state
*/
struct lp_build_sample_context
{
- LLVMBuilderRef builder;
+ struct gallivm_state *gallivm;
const struct lp_sampler_static_state *static_state;
@@ -385,7 +385,7 @@ lp_build_sample_offset(struct lp_build_context *bld,
void
-lp_build_sample_soa(LLVMBuilderRef builder,
+lp_build_sample_soa(struct gallivm_state *gallivm,
const struct lp_sampler_static_state *static_state,
struct lp_sampler_dynamic_state *dynamic_state,
struct lp_type fp_type,
@@ -399,7 +399,7 @@ lp_build_sample_soa(LLVMBuilderRef builder,
LLVMValueRef texel_out[4]);
void
-lp_build_sample_nop(struct lp_type type,
+lp_build_sample_nop(struct gallivm_state *gallivm, struct lp_type type,
LLVMValueRef texel_out[4]);
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample_aos.c b/src/gallium/auxiliary/gallivm/lp_bld_sample_aos.c
index d6831a580b..991f6fa5ef 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_sample_aos.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_sample_aos.c
@@ -52,6 +52,7 @@
#include "lp_bld_flow.h"
#include "lp_bld_gather.h"
#include "lp_bld_format.h"
+#include "lp_bld_init.h"
#include "lp_bld_sample.h"
#include "lp_bld_sample_aos.h"
#include "lp_bld_quad.h"
@@ -82,6 +83,7 @@ lp_build_sample_wrap_nearest_int(struct lp_build_sample_context *bld,
LLVMValueRef *out_i)
{
struct lp_build_context *int_coord_bld = &bld->int_coord_bld;
+ LLVMBuilderRef builder = bld->gallivm->builder;
LLVMValueRef length_minus_one;
length_minus_one = lp_build_sub(int_coord_bld, length, int_coord_bld->one);
@@ -89,12 +91,12 @@ lp_build_sample_wrap_nearest_int(struct lp_build_sample_context *bld,
switch(wrap_mode) {
case PIPE_TEX_WRAP_REPEAT:
if(is_pot)
- coord = LLVMBuildAnd(bld->builder, coord, length_minus_one, "");
+ coord = LLVMBuildAnd(builder, coord, length_minus_one, "");
else {
/* Add a bias to the texcoord to handle negative coords */
LLVMValueRef bias = lp_build_mul_imm(int_coord_bld, length, 1024);
- coord = LLVMBuildAdd(bld->builder, coord, bias, "");
- coord = LLVMBuildURem(bld->builder, coord, length, "");
+ coord = LLVMBuildAdd(builder, coord, bias, "");
+ coord = LLVMBuildURem(builder, coord, length, "");
}
break;
@@ -147,6 +149,7 @@ lp_build_sample_wrap_linear_int(struct lp_build_sample_context *bld,
LLVMValueRef *i1)
{
struct lp_build_context *int_coord_bld = &bld->int_coord_bld;
+ LLVMBuilderRef builder = bld->gallivm->builder;
LLVMValueRef length_minus_one;
LLVMValueRef lmask, umask, mask;
@@ -195,39 +198,39 @@ lp_build_sample_wrap_linear_int(struct lp_build_sample_context *bld,
switch(wrap_mode) {
case PIPE_TEX_WRAP_REPEAT:
if (is_pot) {
- coord0 = LLVMBuildAnd(bld->builder, coord0, length_minus_one, "");
+ coord0 = LLVMBuildAnd(builder, coord0, length_minus_one, "");
}
else {
/* Add a bias to the texcoord to handle negative coords */
LLVMValueRef bias = lp_build_mul_imm(int_coord_bld, length, 1024);
- coord0 = LLVMBuildAdd(bld->builder, coord0, bias, "");
- coord0 = LLVMBuildURem(bld->builder, coord0, length, "");
+ coord0 = LLVMBuildAdd(builder, coord0, bias, "");
+ coord0 = LLVMBuildURem(builder, coord0, length, "");
}
- mask = lp_build_compare(bld->builder, int_coord_bld->type,
+ mask = lp_build_compare(bld->gallivm, int_coord_bld->type,
PIPE_FUNC_NOTEQUAL, coord0, length_minus_one);
*offset0 = lp_build_mul(int_coord_bld, coord0, stride);
- *offset1 = LLVMBuildAnd(bld->builder,
+ *offset1 = LLVMBuildAnd(builder,
lp_build_add(int_coord_bld, *offset0, stride),
mask, "");
break;
case PIPE_TEX_WRAP_CLAMP_TO_EDGE:
- lmask = lp_build_compare(int_coord_bld->builder, int_coord_bld->type,
+ lmask = lp_build_compare(int_coord_bld->gallivm, int_coord_bld->type,
PIPE_FUNC_GEQUAL, coord0, int_coord_bld->zero);
- umask = lp_build_compare(int_coord_bld->builder, int_coord_bld->type,
+ umask = lp_build_compare(int_coord_bld->gallivm, int_coord_bld->type,
PIPE_FUNC_LESS, coord0, length_minus_one);
coord0 = lp_build_select(int_coord_bld, lmask, coord0, int_coord_bld->zero);
coord0 = lp_build_select(int_coord_bld, umask, coord0, length_minus_one);
- mask = LLVMBuildAnd(bld->builder, lmask, umask, "");
+ mask = LLVMBuildAnd(builder, lmask, umask, "");
*offset0 = lp_build_mul(int_coord_bld, coord0, stride);
*offset1 = lp_build_add(int_coord_bld,
*offset0,
- LLVMBuildAnd(bld->builder, stride, mask, ""));
+ LLVMBuildAnd(builder, stride, mask, ""));
break;
case PIPE_TEX_WRAP_CLAMP:
@@ -263,7 +266,7 @@ lp_build_sample_image_nearest(struct lp_build_sample_context *bld,
LLVMValueRef *colors_hi)
{
const unsigned dims = bld->dims;
- LLVMBuilderRef builder = bld->builder;
+ LLVMBuilderRef builder = bld->gallivm->builder;
struct lp_build_context i32, h16, u8n;
LLVMTypeRef i32_vec_type, h16_vec_type, u8n_vec_type;
LLVMValueRef i32_c8;
@@ -273,13 +276,13 @@ lp_build_sample_image_nearest(struct lp_build_sample_context *bld,
LLVMValueRef x_offset, offset;
LLVMValueRef x_subcoord, y_subcoord, z_subcoord;
- lp_build_context_init(&i32, builder, lp_type_int_vec(32));
- lp_build_context_init(&h16, builder, lp_type_ufixed(16));
- lp_build_context_init(&u8n, builder, lp_type_unorm(8));
+ lp_build_context_init(&i32, bld->gallivm, lp_type_int_vec(32));
+ lp_build_context_init(&h16, bld->gallivm, lp_type_ufixed(16));
+ lp_build_context_init(&u8n, bld->gallivm, lp_type_unorm(8));
- i32_vec_type = lp_build_vec_type(i32.type);
- h16_vec_type = lp_build_vec_type(h16.type);
- u8n_vec_type = lp_build_vec_type(u8n.type);
+ i32_vec_type = lp_build_vec_type(bld->gallivm, i32.type);
+ h16_vec_type = lp_build_vec_type(bld->gallivm, h16.type);
+ u8n_vec_type = lp_build_vec_type(bld->gallivm, u8n.type);
lp_build_extract_image_sizes(bld,
bld->int_size_type,
@@ -317,7 +320,7 @@ lp_build_sample_image_nearest(struct lp_build_sample_context *bld,
r = LLVMBuildFPToSI(builder, r, i32_vec_type, "");
/* compute floor (shift right 8) */
- i32_c8 = lp_build_const_int_vec(i32.type, 8);
+ i32_c8 = lp_build_const_int_vec(bld->gallivm, i32.type, 8);
s_ipart = LLVMBuildAShr(builder, s, i32_c8, "");
if (dims >= 2)
t_ipart = LLVMBuildAShr(builder, t, i32_c8, "");
@@ -325,7 +328,8 @@ lp_build_sample_image_nearest(struct lp_build_sample_context *bld,
r_ipart = LLVMBuildAShr(builder, r, i32_c8, "");
/* get pixel, row, image strides */
- x_stride = lp_build_const_vec(bld->int_coord_bld.type,
+ x_stride = lp_build_const_vec(bld->gallivm,
+ bld->int_coord_bld.type,
bld->format_desc->block.bits/8);
/* Do texcoord wrapping, compute texel offset */
@@ -387,7 +391,7 @@ lp_build_sample_image_nearest(struct lp_build_sample_context *bld,
* Given the format is a rgba8, just read the pixels as is,
* without any swizzling. Swizzling will be done later.
*/
- rgba8 = lp_build_gather(bld->builder,
+ rgba8 = lp_build_gather(bld->gallivm,
bld->texel_type.length,
bld->format_desc->block.bits,
bld->texel_type.width,
@@ -396,7 +400,7 @@ lp_build_sample_image_nearest(struct lp_build_sample_context *bld,
rgba8 = LLVMBuildBitCast(builder, rgba8, u8n_vec_type, "");
}
else {
- rgba8 = lp_build_fetch_rgba_aos(bld->builder,
+ rgba8 = lp_build_fetch_rgba_aos(bld->gallivm,
bld->format_desc,
u8n.type,
data_ptr, offset,
@@ -405,7 +409,7 @@ lp_build_sample_image_nearest(struct lp_build_sample_context *bld,
}
/* Expand one 4*rgba8 to two 2*rgba16 */
- lp_build_unpack2(builder, u8n.type, h16.type,
+ lp_build_unpack2(bld->gallivm, u8n.type, h16.type,
rgba8,
colors_lo, colors_hi);
}
@@ -429,7 +433,7 @@ lp_build_sample_image_linear(struct lp_build_sample_context *bld,
LLVMValueRef *colors_hi)
{
const unsigned dims = bld->dims;
- LLVMBuilderRef builder = bld->builder;
+ LLVMBuilderRef builder = bld->gallivm->builder;
struct lp_build_context i32, h16, u8n;
LLVMTypeRef i32_vec_type, h16_vec_type, u8n_vec_type;
LLVMValueRef i32_c8, i32_c128, i32_c255;
@@ -450,13 +454,13 @@ lp_build_sample_image_linear(struct lp_build_sample_context *bld,
unsigned i, j, k;
unsigned numj, numk;
- lp_build_context_init(&i32, builder, lp_type_int_vec(32));
- lp_build_context_init(&h16, builder, lp_type_ufixed(16));
- lp_build_context_init(&u8n, builder, lp_type_unorm(8));
+ lp_build_context_init(&i32, bld->gallivm, lp_type_int_vec(32));
+ lp_build_context_init(&h16, bld->gallivm, lp_type_ufixed(16));
+ lp_build_context_init(&u8n, bld->gallivm, lp_type_unorm(8));
- i32_vec_type = lp_build_vec_type(i32.type);
- h16_vec_type = lp_build_vec_type(h16.type);
- u8n_vec_type = lp_build_vec_type(u8n.type);
+ i32_vec_type = lp_build_vec_type(bld->gallivm, i32.type);
+ h16_vec_type = lp_build_vec_type(bld->gallivm, h16.type);
+ u8n_vec_type = lp_build_vec_type(bld->gallivm, u8n.type);
lp_build_extract_image_sizes(bld,
bld->int_size_type,
@@ -494,7 +498,7 @@ lp_build_sample_image_linear(struct lp_build_sample_context *bld,
r = LLVMBuildFPToSI(builder, r, i32_vec_type, "");
/* subtract 0.5 (add -128) */
- i32_c128 = lp_build_const_int_vec(i32.type, -128);
+ i32_c128 = lp_build_const_int_vec(bld->gallivm, i32.type, -128);
s = LLVMBuildAdd(builder, s, i32_c128, "");
if (dims >= 2) {
t = LLVMBuildAdd(builder, t, i32_c128, "");
@@ -504,7 +508,7 @@ lp_build_sample_image_linear(struct lp_build_sample_context *bld,
}
/* compute floor (shift right 8) */
- i32_c8 = lp_build_const_int_vec(i32.type, 8);
+ i32_c8 = lp_build_const_int_vec(bld->gallivm, i32.type, 8);
s_ipart = LLVMBuildAShr(builder, s, i32_c8, "");
if (dims >= 2)
t_ipart = LLVMBuildAShr(builder, t, i32_c8, "");
@@ -512,7 +516,7 @@ lp_build_sample_image_linear(struct lp_build_sample_context *bld,
r_ipart = LLVMBuildAShr(builder, r, i32_c8, "");
/* compute fractional part (AND with 0xff) */
- i32_c255 = lp_build_const_int_vec(i32.type, 255);
+ i32_c255 = lp_build_const_int_vec(bld->gallivm, i32.type, 255);
s_fpart = LLVMBuildAnd(builder, s, i32_c255, "");
if (dims >= 2)
t_fpart = LLVMBuildAnd(builder, t, i32_c255, "");
@@ -520,7 +524,7 @@ lp_build_sample_image_linear(struct lp_build_sample_context *bld,
r_fpart = LLVMBuildAnd(builder, r, i32_c255, "");
/* get pixel, row and image strides */
- x_stride = lp_build_const_vec(bld->int_coord_bld.type,
+ x_stride = lp_build_const_vec(bld->gallivm, bld->int_coord_bld.type,
bld->format_desc->block.bits/8);
y_stride = row_stride_vec;
z_stride = img_stride_vec;
@@ -612,7 +616,7 @@ lp_build_sample_image_linear(struct lp_build_sample_context *bld,
r_fpart = LLVMBuildBitCast(builder, r_fpart, h16_vec_type, "");
{
- LLVMTypeRef elem_type = LLVMInt32Type();
+ LLVMTypeRef elem_type = LLVMInt32TypeInContext(bld->gallivm->context);
LLVMValueRef shuffles_lo[LP_MAX_VECTOR_LENGTH];
LLVMValueRef shuffles_hi[LP_MAX_VECTOR_LENGTH];
LLVMValueRef shuffle_lo;
@@ -685,7 +689,7 @@ lp_build_sample_image_linear(struct lp_build_sample_context *bld,
* Given the format is a rgba8, just read the pixels as is,
* without any swizzling. Swizzling will be done later.
*/
- rgba8 = lp_build_gather(bld->builder,
+ rgba8 = lp_build_gather(bld->gallivm,
bld->texel_type.length,
bld->format_desc->block.bits,
bld->texel_type.width,
@@ -694,7 +698,7 @@ lp_build_sample_image_linear(struct lp_build_sample_context *bld,
rgba8 = LLVMBuildBitCast(builder, rgba8, u8n_vec_type, "");
}
else {
- rgba8 = lp_build_fetch_rgba_aos(bld->builder,
+ rgba8 = lp_build_fetch_rgba_aos(bld->gallivm,
bld->format_desc,
u8n.type,
data_ptr, offset[k][j][i],
@@ -703,7 +707,7 @@ lp_build_sample_image_linear(struct lp_build_sample_context *bld,
}
/* Expand one 4*rgba8 to two 2*rgba16 */
- lp_build_unpack2(builder, u8n.type, h16.type,
+ lp_build_unpack2(bld->gallivm, u8n.type, h16.type,
rgba8,
&neighbors_lo[k][j][i], &neighbors_hi[k][j][i]);
}
@@ -790,7 +794,7 @@ lp_build_sample_mipmap(struct lp_build_sample_context *bld,
LLVMValueRef colors_lo_var,
LLVMValueRef colors_hi_var)
{
- LLVMBuilderRef builder = bld->builder;
+ LLVMBuilderRef builder = bld->gallivm->builder;
LLVMValueRef size0;
LLVMValueRef size1;
LLVMValueRef row_stride0_vec;
@@ -802,7 +806,6 @@ lp_build_sample_mipmap(struct lp_build_sample_context *bld,
LLVMValueRef colors0_lo, colors0_hi;
LLVMValueRef colors1_lo, colors1_hi;
-
/* sample the first mipmap level */
lp_build_mipmap_level_sizes(bld, ilevel0,
&size0,
@@ -829,8 +832,8 @@ lp_build_sample_mipmap(struct lp_build_sample_context *bld,
LLVMBuildStore(builder, colors0_hi, colors_hi_var);
if (mip_filter == PIPE_TEX_MIPFILTER_LINEAR) {
- LLVMValueRef h16_scale = LLVMConstReal(LLVMFloatType(), 256.0);
- LLVMTypeRef i32_type = LLVMIntType(32);
+ LLVMValueRef h16_scale = lp_build_const_float(bld->gallivm, 256.0);
+ LLVMTypeRef i32_type = LLVMIntTypeInContext(bld->gallivm->context, 32);
struct lp_build_if_state if_ctx;
LLVMValueRef need_lerp;
@@ -842,11 +845,11 @@ lp_build_sample_mipmap(struct lp_build_sample_context *bld,
lod_fpart, LLVMConstNull(i32_type),
"need_lerp");
- lp_build_if(&if_ctx, builder, need_lerp);
+ lp_build_if(&if_ctx, bld->gallivm, need_lerp);
{
struct lp_build_context h16_bld;
- lp_build_context_init(&h16_bld, builder, lp_type_ufixed(16));
+ lp_build_context_init(&h16_bld, bld->gallivm, lp_type_ufixed(16));
/* sample the second mipmap level */
lp_build_mipmap_level_sizes(bld, ilevel1,
@@ -885,7 +888,7 @@ lp_build_sample_mipmap(struct lp_build_sample_context *bld,
int i;
assert(h16_bld.type.length <= Elements(shuffles));
for (i = 0; i < h16_bld.type.length; i++)
- shuffles[i] = lp_build_const_int32(2 * (i & 1));
+ shuffles[i] = lp_build_const_int32(bld->gallivm, 2 * (i & 1));
shuffle = LLVMConstVector(shuffles, h16_bld.type.length);
lod_fpart = LLVMBuildShuffleVector(builder,
lod_fpart, lod_fpart,
@@ -925,7 +928,7 @@ lp_build_sample_aos(struct lp_build_sample_context *bld,
LLVMValueRef texel_out[4])
{
struct lp_build_context *int_bld = &bld->int_bld;
- LLVMBuilderRef builder = bld->builder;
+ LLVMBuilderRef builder = bld->gallivm->builder;
const unsigned mip_filter = bld->static_state->min_mip_filter;
const unsigned min_filter = bld->static_state->min_img_filter;
const unsigned mag_filter = bld->static_state->mag_img_filter;
@@ -936,8 +939,7 @@ lp_build_sample_aos(struct lp_build_sample_context *bld,
LLVMValueRef unswizzled[4];
LLVMValueRef face_ddx[4], face_ddy[4];
struct lp_build_context h16_bld;
- LLVMTypeRef i32t = LLVMInt32Type();
- LLVMValueRef i32t_zero = LLVMConstInt(i32t, 0, 0);
+ LLVMValueRef i32t_zero = lp_build_const_int32(bld->gallivm, 0);
/* we only support the common/simple wrap modes at this time */
assert(lp_is_simple_wrap_mode(bld->static_state->wrap_s));
@@ -948,7 +950,7 @@ lp_build_sample_aos(struct lp_build_sample_context *bld,
/* make 16-bit fixed-pt builder context */
- lp_build_context_init(&h16_bld, builder, lp_type_ufixed(16));
+ lp_build_context_init(&h16_bld, bld->gallivm, lp_type_ufixed(16));
/* cube face selection, compute pre-face coords, etc. */
if (bld->static_state->target == PIPE_TEXTURE_CUBE) {
@@ -1026,8 +1028,8 @@ lp_build_sample_aos(struct lp_build_sample_context *bld,
* Get/interpolate texture colors.
*/
- packed_lo = lp_build_alloca(builder, h16_bld.vec_type, "packed_lo");
- packed_hi = lp_build_alloca(builder, h16_bld.vec_type, "packed_hi");
+ packed_lo = lp_build_alloca(bld->gallivm, h16_bld.vec_type, "packed_lo");
+ packed_hi = lp_build_alloca(bld->gallivm, h16_bld.vec_type, "packed_hi");
if (min_filter == mag_filter) {
/* no need to distinquish between minification and magnification */
@@ -1048,7 +1050,7 @@ lp_build_sample_aos(struct lp_build_sample_context *bld,
minify = LLVMBuildICmp(builder, LLVMIntSGE,
lod_ipart, int_bld->zero, "");
- lp_build_if(&if_ctx, builder, minify);
+ lp_build_if(&if_ctx, bld->gallivm, minify);
{
/* Use the minification filter */
lp_build_sample_mipmap(bld,
@@ -1073,7 +1075,7 @@ lp_build_sample_aos(struct lp_build_sample_context *bld,
* combine the values stored in 'packed_lo' and 'packed_hi' variables
* into 'packed'
*/
- packed = lp_build_pack2(builder,
+ packed = lp_build_pack2(bld->gallivm,
h16_bld.type, lp_type_unorm(8),
LLVMBuildLoad(builder, packed_lo, ""),
LLVMBuildLoad(builder, packed_hi, ""));
@@ -1081,7 +1083,7 @@ lp_build_sample_aos(struct lp_build_sample_context *bld,
/*
* Convert to SoA and swizzle.
*/
- lp_build_rgba8_to_f32_soa(builder,
+ lp_build_rgba8_to_f32_soa(bld->gallivm,
bld->texel_type,
packed, unswizzled);
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c
index 53cc0c5f34..cf46e2be83 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c
@@ -84,6 +84,7 @@ lp_build_sample_texel_soa(struct lp_build_sample_context *bld,
const struct lp_sampler_static_state *static_state = bld->static_state;
const unsigned dims = bld->dims;
struct lp_build_context *int_coord_bld = &bld->int_coord_bld;
+ LLVMBuilderRef builder = bld->gallivm->builder;
LLVMValueRef offset;
LLVMValueRef i, j;
LLVMValueRef use_border = NULL;
@@ -95,7 +96,7 @@ lp_build_sample_texel_soa(struct lp_build_sample_context *bld,
LLVMValueRef b1, b2;
b1 = lp_build_cmp(int_coord_bld, PIPE_FUNC_LESS, x, int_coord_bld->zero);
b2 = lp_build_cmp(int_coord_bld, PIPE_FUNC_GEQUAL, x, width);
- use_border = LLVMBuildOr(bld->builder, b1, b2, "b1_or_b2");
+ use_border = LLVMBuildOr(builder, b1, b2, "b1_or_b2");
}
if (dims >= 2 &&
@@ -106,11 +107,11 @@ lp_build_sample_texel_soa(struct lp_build_sample_context *bld,
b1 = lp_build_cmp(int_coord_bld, PIPE_FUNC_LESS, y, int_coord_bld->zero);
b2 = lp_build_cmp(int_coord_bld, PIPE_FUNC_GEQUAL, y, height);
if (use_border) {
- use_border = LLVMBuildOr(bld->builder, use_border, b1, "ub_or_b1");
- use_border = LLVMBuildOr(bld->builder, use_border, b2, "ub_or_b2");
+ use_border = LLVMBuildOr(builder, use_border, b1, "ub_or_b1");
+ use_border = LLVMBuildOr(builder, use_border, b2, "ub_or_b2");
}
else {
- use_border = LLVMBuildOr(bld->builder, b1, b2, "b1_or_b2");
+ use_border = LLVMBuildOr(builder, b1, b2, "b1_or_b2");
}
}
@@ -122,11 +123,11 @@ lp_build_sample_texel_soa(struct lp_build_sample_context *bld,
b1 = lp_build_cmp(int_coord_bld, PIPE_FUNC_LESS, z, int_coord_bld->zero);
b2 = lp_build_cmp(int_coord_bld, PIPE_FUNC_GEQUAL, z, depth);
if (use_border) {
- use_border = LLVMBuildOr(bld->builder, use_border, b1, "ub_or_b1");
- use_border = LLVMBuildOr(bld->builder, use_border, b2, "ub_or_b2");
+ use_border = LLVMBuildOr(builder, use_border, b1, "ub_or_b1");
+ use_border = LLVMBuildOr(builder, use_border, b2, "ub_or_b2");
}
else {
- use_border = LLVMBuildOr(bld->builder, b1, b2, "b1_or_b2");
+ use_border = LLVMBuildOr(builder, b1, b2, "b1_or_b2");
}
}
@@ -148,7 +149,7 @@ lp_build_sample_texel_soa(struct lp_build_sample_context *bld,
offset = lp_build_andnot(&bld->int_coord_bld, offset, use_border);
}
- lp_build_fetch_rgba_soa(bld->builder,
+ lp_build_fetch_rgba_soa(bld->gallivm,
bld->format_desc,
bld->texel_type,
data_ptr, offset,
@@ -174,12 +175,12 @@ lp_build_sample_texel_soa(struct lp_build_sample_context *bld,
/* select texel color or border color depending on use_border */
LLVMValueRef border_color_ptr =
bld->dynamic_state->border_color(bld->dynamic_state,
- bld->builder, unit);
+ bld->gallivm, unit);
int chan;
for (chan = 0; chan < 4; chan++) {
LLVMValueRef border_chan =
- lp_build_array_get(bld->builder, border_color_ptr,
- lp_build_const_int32(chan));
+ lp_build_array_get(bld->gallivm, border_color_ptr,
+ lp_build_const_int32(bld->gallivm, chan));
LLVMValueRef border_chan_vec =
lp_build_broadcast_scalar(&bld->float_vec_bld, border_chan);
texel_out[chan] = lp_build_select(&bld->texel_bld, use_border,
@@ -205,7 +206,7 @@ lp_build_coord_mirror(struct lp_build_sample_context *bld,
lp_build_ifloor_fract(coord_bld, coord, &flr, &fract);
/* isOdd = flr & 1 */
- isOdd = LLVMBuildAnd(bld->builder, flr, int_coord_bld->one, "");
+ isOdd = LLVMBuildAnd(bld->gallivm->builder, flr, int_coord_bld->one, "");
/* make coord positive or negative depending on isOdd */
coord = lp_build_set_sign(coord_bld, fract, isOdd);
@@ -239,7 +240,8 @@ lp_build_sample_wrap_linear(struct lp_build_sample_context *bld,
{
struct lp_build_context *coord_bld = &bld->coord_bld;
struct lp_build_context *int_coord_bld = &bld->int_coord_bld;
- LLVMValueRef half = lp_build_const_vec(coord_bld->type, 0.5);
+ LLVMBuilderRef builder = bld->gallivm->builder;
+ LLVMValueRef half = lp_build_const_vec(bld->gallivm, coord_bld->type, 0.5);
LLVMValueRef length_minus_one = lp_build_sub(int_coord_bld, length, int_coord_bld->one);
LLVMValueRef coord0, coord1, weight;
@@ -253,18 +255,18 @@ lp_build_sample_wrap_linear(struct lp_build_sample_context *bld,
/* repeat wrap */
if (is_pot) {
coord1 = lp_build_add(int_coord_bld, coord0, int_coord_bld->one);
- coord0 = LLVMBuildAnd(bld->builder, coord0, length_minus_one, "");
- coord1 = LLVMBuildAnd(bld->builder, coord1, length_minus_one, "");
+ coord0 = LLVMBuildAnd(builder, coord0, length_minus_one, "");
+ coord1 = LLVMBuildAnd(builder, coord1, length_minus_one, "");
}
else {
/* Add a bias to the texcoord to handle negative coords */
LLVMValueRef bias = lp_build_mul_imm(int_coord_bld, length, 1024);
LLVMValueRef mask;
- coord0 = LLVMBuildAdd(bld->builder, coord0, bias, "");
- coord0 = LLVMBuildURem(bld->builder, coord0, length, "");
- mask = lp_build_compare(bld->builder, int_coord_bld->type,
+ coord0 = LLVMBuildAdd(builder, coord0, bias, "");
+ coord0 = LLVMBuildURem(builder, coord0, length, "");
+ mask = lp_build_compare(bld->gallivm, int_coord_bld->type,
PIPE_FUNC_NOTEQUAL, coord0, length_minus_one);
- coord1 = LLVMBuildAnd(bld->builder,
+ coord1 = LLVMBuildAnd(builder,
lp_build_add(int_coord_bld, coord0, int_coord_bld->one),
mask, "");
}
@@ -318,7 +320,7 @@ lp_build_sample_wrap_linear(struct lp_build_sample_context *bld,
}
/* was: clamp to [-0.5, length + 0.5], then sub 0.5 */
coord = lp_build_sub(coord_bld, coord, half);
- min = lp_build_const_vec(coord_bld->type, -1.0F);
+ min = lp_build_const_vec(bld->gallivm, coord_bld->type, -1.0F);
coord = lp_build_clamp(coord_bld, coord, min, length_f);
/* convert to int, compute lerp weight */
lp_build_ifloor_fract(coord_bld, coord, &coord0, &weight);
@@ -437,6 +439,7 @@ lp_build_sample_wrap_nearest(struct lp_build_sample_context *bld,
{
struct lp_build_context *coord_bld = &bld->coord_bld;
struct lp_build_context *int_coord_bld = &bld->int_coord_bld;
+ LLVMBuilderRef builder = bld->gallivm->builder;
LLVMValueRef length_minus_one = lp_build_sub(int_coord_bld, length, int_coord_bld->one);
LLVMValueRef icoord;
@@ -445,12 +448,12 @@ lp_build_sample_wrap_nearest(struct lp_build_sample_context *bld,
coord = lp_build_mul(coord_bld, coord, length_f);
icoord = lp_build_ifloor(coord_bld, coord);
if (is_pot)
- icoord = LLVMBuildAnd(bld->builder, icoord, length_minus_one, "");
+ icoord = LLVMBuildAnd(builder, icoord, length_minus_one, "");
else {
/* Add a bias to the texcoord to handle negative coords */
LLVMValueRef bias = lp_build_mul_imm(int_coord_bld, length, 1024);
- icoord = LLVMBuildAdd(bld->builder, icoord, bias, "");
- icoord = LLVMBuildURem(bld->builder, icoord, length, "");
+ icoord = LLVMBuildAdd(builder, icoord, bias, "");
+ icoord = LLVMBuildURem(builder, icoord, length, "");
}
break;
@@ -830,7 +833,7 @@ lp_build_sample_mipmap(struct lp_build_sample_context *bld,
LLVMValueRef lod_fpart,
LLVMValueRef *colors_out)
{
- LLVMBuilderRef builder = bld->builder;
+ LLVMBuilderRef builder = bld->gallivm->builder;
LLVMValueRef size0;
LLVMValueRef size1;
LLVMValueRef row_stride0_vec;
@@ -878,7 +881,7 @@ lp_build_sample_mipmap(struct lp_build_sample_context *bld,
bld->float_bld.zero,
"need_lerp");
- lp_build_if(&if_ctx, builder, need_lerp);
+ lp_build_if(&if_ctx, bld->gallivm, need_lerp);
{
/* sample the second mipmap level */
lp_build_mipmap_level_sizes(bld, ilevel1,
@@ -934,7 +937,7 @@ lp_build_sample_general(struct lp_build_sample_context *bld,
LLVMValueRef *colors_out)
{
struct lp_build_context *int_bld = &bld->int_bld;
- LLVMBuilderRef builder = bld->builder;
+ LLVMBuilderRef builder = bld->gallivm->builder;
const unsigned mip_filter = bld->static_state->min_mip_filter;
const unsigned min_filter = bld->static_state->min_img_filter;
const unsigned mag_filter = bld->static_state->mag_img_filter;
@@ -942,8 +945,7 @@ lp_build_sample_general(struct lp_build_sample_context *bld,
LLVMValueRef ilevel0, ilevel1 = NULL;
LLVMValueRef face_ddx[4], face_ddy[4];
LLVMValueRef texels[4];
- LLVMTypeRef i32t = LLVMInt32Type();
- LLVMValueRef i32t_zero = LLVMConstInt(i32t, 0, 0);
+ LLVMValueRef i32t_zero = lp_build_const_int32(bld->gallivm, 0);
unsigned chan;
/*
@@ -1030,7 +1032,7 @@ lp_build_sample_general(struct lp_build_sample_context *bld,
*/
for (chan = 0; chan < 4; ++chan) {
- texels[chan] = lp_build_alloca(builder, bld->texel_bld.vec_type, "");
+ texels[chan] = lp_build_alloca(bld->gallivm, bld->texel_bld.vec_type, "");
lp_build_name(texels[chan], "sampler%u_texel_%c_var", unit, "xyzw"[chan]);
}
@@ -1053,7 +1055,7 @@ lp_build_sample_general(struct lp_build_sample_context *bld,
minify = LLVMBuildICmp(builder, LLVMIntSGE,
lod_ipart, int_bld->zero, "");
- lp_build_if(&if_ctx, builder, minify);
+ lp_build_if(&if_ctx, bld->gallivm, minify);
{
/* Use the minification filter */
lp_build_sample_mipmap(bld, unit,
@@ -1092,6 +1094,7 @@ lp_build_sample_compare(struct lp_build_sample_context *bld,
LLVMValueRef texel[4])
{
struct lp_build_context *texel_bld = &bld->texel_bld;
+ LLVMBuilderRef builder = bld->gallivm->builder;
LLVMValueRef res;
const unsigned chan = 0;
@@ -1100,11 +1103,10 @@ lp_build_sample_compare(struct lp_build_sample_context *bld,
/* debug code */
if (0) {
- LLVMValueRef indx = lp_build_const_int32(0);
- LLVMValueRef coord = LLVMBuildExtractElement(bld->builder, p, indx, "");
- LLVMValueRef tex = LLVMBuildExtractElement(bld->builder,
- texel[chan], indx, "");
- lp_build_printf(bld->builder, "shadow compare coord %f to texture %f\n",
+ LLVMValueRef indx = lp_build_const_int32(bld->gallivm, 0);
+ LLVMValueRef coord = LLVMBuildExtractElement(builder, p, indx, "");
+ LLVMValueRef tex = LLVMBuildExtractElement(builder, texel[chan], indx, "");
+ lp_build_printf(bld->gallivm, "shadow compare coord %f to texture %f\n",
coord, tex);
}
@@ -1126,10 +1128,10 @@ lp_build_sample_compare(struct lp_build_sample_context *bld,
* For debugging.
*/
void
-lp_build_sample_nop(struct lp_type type,
+lp_build_sample_nop(struct gallivm_state *gallivm, struct lp_type type,
LLVMValueRef texel_out[4])
{
- LLVMValueRef one = lp_build_one(type);
+ LLVMValueRef one = lp_build_one(gallivm, type);
unsigned chan;
for (chan = 0; chan < 4; chan++) {
@@ -1147,7 +1149,7 @@ lp_build_sample_nop(struct lp_type type,
* \param ddy partial derivatives of (s,t,r,q) with respect to y
*/
void
-lp_build_sample_soa(LLVMBuilderRef builder,
+lp_build_sample_soa(struct gallivm_state *gallivm,
const struct lp_sampler_static_state *static_state,
struct lp_sampler_dynamic_state *dynamic_state,
struct lp_type type,
@@ -1162,8 +1164,8 @@ lp_build_sample_soa(LLVMBuilderRef builder,
{
unsigned dims = texture_dims(static_state->target);
struct lp_build_sample_context bld;
- LLVMTypeRef i32t = LLVMInt32Type();
-
+ LLVMTypeRef i32t = LLVMInt32TypeInContext(gallivm->context);
+ LLVMBuilderRef builder = gallivm->builder;
LLVMValueRef s;
LLVMValueRef t;
LLVMValueRef r;
@@ -1178,7 +1180,7 @@ lp_build_sample_soa(LLVMBuilderRef builder,
/* Setup our build context */
memset(&bld, 0, sizeof bld);
- bld.builder = builder;
+ bld.gallivm = gallivm;
bld.static_state = static_state;
bld.dynamic_state = dynamic_state;
bld.format_desc = util_format_description(static_state->format);
@@ -1195,22 +1197,22 @@ lp_build_sample_soa(LLVMBuilderRef builder,
float_vec_type = lp_type_float_vec(32);
- lp_build_context_init(&bld.float_bld, builder, bld.float_type);
- lp_build_context_init(&bld.float_vec_bld, builder, float_vec_type);
- lp_build_context_init(&bld.int_bld, builder, bld.int_type);
- lp_build_context_init(&bld.coord_bld, builder, bld.coord_type);
- lp_build_context_init(&bld.int_coord_bld, builder, bld.int_coord_type);
- lp_build_context_init(&bld.int_size_bld, builder, bld.int_size_type);
- lp_build_context_init(&bld.float_size_bld, builder, bld.float_size_type);
- lp_build_context_init(&bld.texel_bld, builder, bld.texel_type);
+ lp_build_context_init(&bld.float_bld, gallivm, bld.float_type);
+ lp_build_context_init(&bld.float_vec_bld, gallivm, float_vec_type);
+ lp_build_context_init(&bld.int_bld, gallivm, bld.int_type);
+ lp_build_context_init(&bld.coord_bld, gallivm, bld.coord_type);
+ lp_build_context_init(&bld.int_coord_bld, gallivm, bld.int_coord_type);
+ lp_build_context_init(&bld.int_size_bld, gallivm, bld.int_size_type);
+ lp_build_context_init(&bld.float_size_bld, gallivm, bld.float_size_type);
+ lp_build_context_init(&bld.texel_bld, gallivm, bld.texel_type);
/* Get the dynamic state */
- bld.width = dynamic_state->width(dynamic_state, builder, unit);
- bld.height = dynamic_state->height(dynamic_state, builder, unit);
- bld.depth = dynamic_state->depth(dynamic_state, builder, unit);
- bld.row_stride_array = dynamic_state->row_stride(dynamic_state, builder, unit);
- bld.img_stride_array = dynamic_state->img_stride(dynamic_state, builder, unit);
- bld.data_array = dynamic_state->data_ptr(dynamic_state, builder, unit);
+ bld.width = dynamic_state->width(dynamic_state, gallivm, unit);
+ bld.height = dynamic_state->height(dynamic_state, gallivm, unit);
+ bld.depth = dynamic_state->depth(dynamic_state, gallivm, unit);
+ bld.row_stride_array = dynamic_state->row_stride(dynamic_state, gallivm, unit);
+ bld.img_stride_array = dynamic_state->img_stride(dynamic_state, gallivm, unit);
+ bld.data_array = dynamic_state->data_ptr(dynamic_state, gallivm, unit);
/* Note that data_array is an array[level] of pointers to texture images */
s = coords[0];
@@ -1236,7 +1238,7 @@ lp_build_sample_soa(LLVMBuilderRef builder,
if (0) {
/* For debug: no-op texture sampling */
- lp_build_sample_nop(bld.texel_type, texel_out);
+ lp_build_sample_nop(gallivm, bld.texel_type, texel_out);
}
else if (util_format_fits_8unorm(bld.format_desc) &&
lp_is_simple_wrap_mode(static_state->wrap_s) &&
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_struct.c b/src/gallium/auxiliary/gallivm/lp_bld_struct.c
index 4693c2de6f..0dc2f24d10 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_struct.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_struct.c
@@ -37,12 +37,13 @@
#include "util/u_debug.h"
#include "util/u_memory.h"
+#include "lp_bld_const.h"
#include "lp_bld_debug.h"
#include "lp_bld_struct.h"
LLVMValueRef
-lp_build_struct_get_ptr(LLVMBuilderRef builder,
+lp_build_struct_get_ptr(struct gallivm_state *gallivm,
LLVMValueRef ptr,
unsigned member,
const char *name)
@@ -51,16 +52,16 @@ lp_build_struct_get_ptr(LLVMBuilderRef builder,
LLVMValueRef member_ptr;
assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind);
assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMStructTypeKind);
- indices[0] = LLVMConstInt(LLVMInt32Type(), 0, 0);
- indices[1] = LLVMConstInt(LLVMInt32Type(), member, 0);
- member_ptr = LLVMBuildGEP(builder, ptr, indices, Elements(indices), "");
+ indices[0] = lp_build_const_int32(gallivm, 0);
+ indices[1] = lp_build_const_int32(gallivm, member);
+ member_ptr = LLVMBuildGEP(gallivm->builder, ptr, indices, Elements(indices), "");
lp_build_name(member_ptr, "%s.%s_ptr", LLVMGetValueName(ptr), name);
return member_ptr;
}
LLVMValueRef
-lp_build_struct_get(LLVMBuilderRef builder,
+lp_build_struct_get(struct gallivm_state *gallivm,
LLVMValueRef ptr,
unsigned member,
const char *name)
@@ -69,15 +70,15 @@ lp_build_struct_get(LLVMBuilderRef builder,
LLVMValueRef res;
assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind);
assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMStructTypeKind);
- member_ptr = lp_build_struct_get_ptr(builder, ptr, member, name);
- res = LLVMBuildLoad(builder, member_ptr, "");
+ member_ptr = lp_build_struct_get_ptr(gallivm, ptr, member, name);
+ res = LLVMBuildLoad(gallivm->builder, member_ptr, "");
lp_build_name(res, "%s.%s", LLVMGetValueName(ptr), name);
return res;
}
LLVMValueRef
-lp_build_array_get_ptr(LLVMBuilderRef builder,
+lp_build_array_get_ptr(struct gallivm_state *gallivm,
LLVMValueRef ptr,
LLVMValueRef index)
{
@@ -85,9 +86,9 @@ lp_build_array_get_ptr(LLVMBuilderRef builder,
LLVMValueRef element_ptr;
assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind);
assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMArrayTypeKind);
- indices[0] = LLVMConstInt(LLVMInt32Type(), 0, 0);
+ indices[0] = lp_build_const_int32(gallivm, 0);
indices[1] = index;
- element_ptr = LLVMBuildGEP(builder, ptr, indices, Elements(indices), "");
+ element_ptr = LLVMBuildGEP(gallivm->builder, ptr, indices, Elements(indices), "");
#ifdef DEBUG
lp_build_name(element_ptr, "&%s[%s]",
LLVMGetValueName(ptr), LLVMGetValueName(index));
@@ -97,7 +98,7 @@ lp_build_array_get_ptr(LLVMBuilderRef builder,
LLVMValueRef
-lp_build_array_get(LLVMBuilderRef builder,
+lp_build_array_get(struct gallivm_state *gallivm,
LLVMValueRef ptr,
LLVMValueRef index)
{
@@ -105,8 +106,8 @@ lp_build_array_get(LLVMBuilderRef builder,
LLVMValueRef res;
assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind);
assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMArrayTypeKind);
- element_ptr = lp_build_array_get_ptr(builder, ptr, index);
- res = LLVMBuildLoad(builder, element_ptr, "");
+ element_ptr = lp_build_array_get_ptr(gallivm, ptr, index);
+ res = LLVMBuildLoad(gallivm->builder, element_ptr, "");
#ifdef DEBUG
lp_build_name(res, "%s[%s]", LLVMGetValueName(ptr), LLVMGetValueName(index));
#endif
@@ -115,7 +116,7 @@ lp_build_array_get(LLVMBuilderRef builder,
void
-lp_build_array_set(LLVMBuilderRef builder,
+lp_build_array_set(struct gallivm_state *gallivm,
LLVMValueRef ptr,
LLVMValueRef index,
LLVMValueRef value)
@@ -123,8 +124,8 @@ lp_build_array_set(LLVMBuilderRef builder,
LLVMValueRef element_ptr;
assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind);
assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMArrayTypeKind);
- element_ptr = lp_build_array_get_ptr(builder, ptr, index);
- LLVMBuildStore(builder, value, element_ptr);
+ element_ptr = lp_build_array_get_ptr(gallivm, ptr, index);
+ LLVMBuildStore(gallivm->builder, value, element_ptr);
}
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_struct.h b/src/gallium/auxiliary/gallivm/lp_bld_struct.h
index eb87a8eee9..11605c685f 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_struct.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_struct.h
@@ -38,7 +38,7 @@
#include "gallivm/lp_bld.h"
-#include <llvm-c/Target.h>
+#include "gallivm/lp_bld_init.h"
#include "util/u_debug.h"
#include "util/u_memory.h"
@@ -57,7 +57,7 @@
* Get value pointer to a structure member.
*/
LLVMValueRef
-lp_build_struct_get_ptr(LLVMBuilderRef builder,
+lp_build_struct_get_ptr(struct gallivm_state *gallivm,
LLVMValueRef ptr,
unsigned member,
const char *name);
@@ -66,7 +66,7 @@ lp_build_struct_get_ptr(LLVMBuilderRef builder,
* Get the value of a structure member.
*/
LLVMValueRef
-lp_build_struct_get(LLVMBuilderRef builder,
+lp_build_struct_get(struct gallivm_state *gallivm,
LLVMValueRef ptr,
unsigned member,
const char *name);
@@ -75,7 +75,7 @@ lp_build_struct_get(LLVMBuilderRef builder,
* Get value pointer to an array element.
*/
LLVMValueRef
-lp_build_array_get_ptr(LLVMBuilderRef builder,
+lp_build_array_get_ptr(struct gallivm_state *gallivm,
LLVMValueRef ptr,
LLVMValueRef index);
@@ -83,7 +83,7 @@ lp_build_array_get_ptr(LLVMBuilderRef builder,
* Get the value of an array element.
*/
LLVMValueRef
-lp_build_array_get(LLVMBuilderRef builder,
+lp_build_array_get(struct gallivm_state *gallivm,
LLVMValueRef ptr,
LLVMValueRef index);
@@ -91,7 +91,7 @@ lp_build_array_get(LLVMBuilderRef builder,
* Set the value of an array element.
*/
void
-lp_build_array_set(LLVMBuilderRef builder,
+lp_build_array_set(struct gallivm_state *gallivm,
LLVMValueRef ptr,
LLVMValueRef index,
LLVMValueRef value);
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_swizzle.c b/src/gallium/auxiliary/gallivm/lp_bld_swizzle.c
index 4685a90e41..93f9dea0ac 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_swizzle.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_swizzle.c
@@ -37,12 +37,13 @@
#include "lp_bld_type.h"
#include "lp_bld_const.h"
+#include "lp_bld_init.h"
#include "lp_bld_logic.h"
#include "lp_bld_swizzle.h"
LLVMValueRef
-lp_build_broadcast(LLVMBuilderRef builder,
+lp_build_broadcast(struct gallivm_state *gallivm,
LLVMTypeRef vec_type,
LLVMValueRef scalar)
{
@@ -52,8 +53,8 @@ lp_build_broadcast(LLVMBuilderRef builder,
res = LLVMGetUndef(vec_type);
for(i = 0; i < n; ++i) {
- LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), i, 0);
- res = LLVMBuildInsertElement(builder, res, scalar, index, "");
+ LLVMValueRef index = lp_build_const_int32(gallivm, i);
+ res = LLVMBuildInsertElement(gallivm->builder, res, scalar, index, "");
}
return res;
@@ -83,15 +84,15 @@ lp_build_broadcast_scalar(struct lp_build_context *bld,
i32_vec_type.length = type.length;
res = LLVMBuildInsertElement(bld->builder, bld->undef, scalar,
- LLVMConstInt(LLVMInt32Type(), 0, 0), "");
+ lp_build_const_int32(bld->gallivm, 0), "");
res = LLVMBuildShuffleVector(bld->builder, res, bld->undef,
- lp_build_const_int_vec(i32_vec_type, 0), "");
+ lp_build_const_int_vec(bld->gallivm, i32_vec_type, 0), "");
#else
/* XXX: The above path provokes a bug in LLVM 2.6 */
unsigned i;
res = bld->undef;
for(i = 0; i < type.length; ++i) {
- LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), i, 0);
+ LLVMValueRef index = lp_build_const_int32(bld->gallivm, i);
res = LLVMBuildInsertElement(bld->builder, res, scalar, index, "");
}
#endif
@@ -104,13 +105,13 @@ lp_build_broadcast_scalar(struct lp_build_context *bld,
* Combined extract and broadcast (or a mere shuffle when the two types match)
*/
LLVMValueRef
-lp_build_extract_broadcast(LLVMBuilderRef builder,
+lp_build_extract_broadcast(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
LLVMValueRef vector,
LLVMValueRef index)
{
- LLVMTypeRef i32t = LLVMInt32Type();
+ LLVMTypeRef i32t = LLVMInt32TypeInContext(gallivm->context);
LLVMValueRef res;
assert(src_type.floating == dst_type.floating);
@@ -132,8 +133,8 @@ lp_build_extract_broadcast(LLVMBuilderRef builder,
* Broadcast scalar -> vector.
*/
- res = lp_build_broadcast(builder,
- lp_build_vec_type(dst_type),
+ res = lp_build_broadcast(gallivm,
+ lp_build_vec_type(gallivm, dst_type),
vector);
}
}
@@ -144,16 +145,16 @@ lp_build_extract_broadcast(LLVMBuilderRef builder,
*/
LLVMValueRef shuffle;
- shuffle = lp_build_broadcast(builder,
+ shuffle = lp_build_broadcast(gallivm,
LLVMVectorType(i32t, dst_type.length),
index);
- res = LLVMBuildShuffleVector(builder, vector,
- LLVMGetUndef(lp_build_vec_type(dst_type)),
+ res = LLVMBuildShuffleVector(gallivm->builder, vector,
+ LLVMGetUndef(lp_build_vec_type(gallivm, dst_type)),
shuffle, "");
}
else {
LLVMValueRef scalar;
- scalar = LLVMBuildExtractElement(builder, vector, index, "");
+ scalar = LLVMBuildExtractElement(gallivm->builder, vector, index, "");
if (dst_type.length == 1) {
/*
* Trivial extract scalar from vector.
@@ -166,8 +167,8 @@ lp_build_extract_broadcast(LLVMBuilderRef builder,
* General case of different sized vectors.
*/
- res = lp_build_broadcast(builder,
- lp_build_vec_type(dst_type),
+ res = lp_build_broadcast(gallivm,
+ lp_build_vec_type(gallivm, dst_type),
vector);
}
}
@@ -199,7 +200,7 @@ lp_build_swizzle_scalar_aos(struct lp_build_context *bld,
/*
* Shuffle.
*/
- LLVMTypeRef elem_type = LLVMInt32Type();
+ LLVMTypeRef elem_type = LLVMInt32TypeInContext(bld->gallivm->context);
LLVMValueRef shuffles[LP_MAX_VECTOR_LENGTH];
for(j = 0; j < n; j += 4)
@@ -227,7 +228,8 @@ lp_build_swizzle_scalar_aos(struct lp_build_context *bld,
unsigned i;
a = LLVMBuildAnd(bld->builder, a,
- lp_build_const_mask_aos(type, 1 << channel), "");
+ lp_build_const_mask_aos(bld->gallivm,
+ type, 1 << channel), "");
/*
* Build a type where each element is an integer that cover the four
@@ -239,7 +241,7 @@ lp_build_swizzle_scalar_aos(struct lp_build_context *bld,
type4.width *= 4;
type4.length /= 4;
- a = LLVMBuildBitCast(bld->builder, a, lp_build_vec_type(type4), "");
+ a = LLVMBuildBitCast(bld->builder, a, lp_build_vec_type(bld->gallivm, type4), "");
for(i = 0; i < 2; ++i) {
LLVMValueRef tmp = NULL;
@@ -250,16 +252,16 @@ lp_build_swizzle_scalar_aos(struct lp_build_context *bld,
#endif
if(shift > 0)
- tmp = LLVMBuildLShr(bld->builder, a, lp_build_const_int_vec(type4, shift*type.width), "");
+ tmp = LLVMBuildLShr(bld->builder, a, lp_build_const_int_vec(bld->gallivm, type4, shift*type.width), "");
if(shift < 0)
- tmp = LLVMBuildShl(bld->builder, a, lp_build_const_int_vec(type4, -shift*type.width), "");
+ tmp = LLVMBuildShl(bld->builder, a, lp_build_const_int_vec(bld->gallivm, type4, -shift*type.width), "");
assert(tmp);
if(tmp)
a = LLVMBuildOr(bld->builder, a, tmp, "");
}
- return LLVMBuildBitCast(bld->builder, a, lp_build_vec_type(type), "");
+ return LLVMBuildBitCast(bld->builder, a, lp_build_vec_type(bld->gallivm, type), "");
}
}
@@ -303,8 +305,8 @@ lp_build_swizzle_aos(struct lp_build_context *bld,
/*
* Shuffle.
*/
- LLVMValueRef undef = LLVMGetUndef(lp_build_elem_type(type));
- LLVMTypeRef i32t = LLVMInt32Type();
+ LLVMValueRef undef = LLVMGetUndef(lp_build_elem_type(bld->gallivm, type));
+ LLVMTypeRef i32t = LLVMInt32TypeInContext(bld->gallivm->context);
LLVMValueRef shuffles[LP_MAX_VECTOR_LENGTH];
LLVMValueRef aux[LP_MAX_VECTOR_LENGTH];
@@ -326,13 +328,13 @@ lp_build_swizzle_aos(struct lp_build_context *bld,
case PIPE_SWIZZLE_ZERO:
shuffle = type.length + 0;
if (!aux[0]) {
- aux[0] = lp_build_const_elem(type, 0.0);
+ aux[0] = lp_build_const_elem(bld->gallivm, type, 0.0);
}
break;
case PIPE_SWIZZLE_ONE:
shuffle = type.length + 1;
if (!aux[1]) {
- aux[1] = lp_build_const_elem(type, 1.0);
+ aux[1] = lp_build_const_elem(bld->gallivm, type, 1.0);
}
break;
}
@@ -387,8 +389,8 @@ lp_build_swizzle_aos(struct lp_build_context *bld,
type4.width *= 4;
type4.length /= 4;
- a = LLVMBuildBitCast(bld->builder, a, lp_build_vec_type(type4), "");
- res = LLVMBuildBitCast(bld->builder, res, lp_build_vec_type(type4), "");
+ a = LLVMBuildBitCast(bld->builder, a, lp_build_vec_type(bld->gallivm, type4), "");
+ res = LLVMBuildBitCast(bld->builder, res, lp_build_vec_type(bld->gallivm, type4), "");
/*
* Mask and shift the channels, trying to group as many channels in the
@@ -415,13 +417,13 @@ lp_build_swizzle_aos(struct lp_build_context *bld,
debug_printf("shift = %i, mask = 0x%08llx\n", shift, mask);
masked = LLVMBuildAnd(bld->builder, a,
- lp_build_const_int_vec(type4, mask), "");
+ lp_build_const_int_vec(bld->gallivm, type4, mask), "");
if (shift > 0) {
shifted = LLVMBuildShl(bld->builder, masked,
- lp_build_const_int_vec(type4, shift*type.width), "");
+ lp_build_const_int_vec(bld->gallivm, type4, shift*type.width), "");
} else if (shift < 0) {
shifted = LLVMBuildLShr(bld->builder, masked,
- lp_build_const_int_vec(type4, -shift*type.width), "");
+ lp_build_const_int_vec(bld->gallivm, type4, -shift*type.width), "");
} else {
shifted = masked;
}
@@ -430,7 +432,8 @@ lp_build_swizzle_aos(struct lp_build_context *bld,
}
}
- return LLVMBuildBitCast(bld->builder, res, lp_build_vec_type(type), "");
+ return LLVMBuildBitCast(bld->builder, res,
+ lp_build_vec_type(bld->gallivm, type), "");
}
}
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_swizzle.h b/src/gallium/auxiliary/gallivm/lp_bld_swizzle.h
index fdea8442ae..c366a65103 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_swizzle.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_swizzle.h
@@ -45,7 +45,7 @@ struct lp_build_context;
LLVMValueRef
-lp_build_broadcast(LLVMBuilderRef builder,
+lp_build_broadcast(struct gallivm_state *gallivm,
LLVMTypeRef vec_type,
LLVMValueRef scalar);
@@ -56,7 +56,7 @@ lp_build_broadcast_scalar(struct lp_build_context *bld,
LLVMValueRef
-lp_build_extract_broadcast(LLVMBuilderRef builder,
+lp_build_extract_broadcast(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
LLVMValueRef vector,
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h b/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h
index a4d3b750c3..40186befb9 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h
@@ -46,6 +46,7 @@ struct tgsi_shader_info;
struct lp_type;
struct lp_build_context;
struct lp_build_mask_context;
+struct gallivm_state;
enum lp_build_tex_modifier {
@@ -141,7 +142,7 @@ struct lp_build_sampler_soa
void
(*emit_fetch_texel)( const struct lp_build_sampler_soa *sampler,
- LLVMBuilderRef builder,
+ struct gallivm_state *gallivm,
struct lp_type type,
unsigned unit,
unsigned num_coords,
@@ -174,7 +175,7 @@ lp_build_tgsi_info(const struct tgsi_token *tokens,
void
-lp_build_tgsi_soa(LLVMBuilderRef builder,
+lp_build_tgsi_soa(struct gallivm_state *gallivm,
const struct tgsi_token *tokens,
struct lp_type type,
struct lp_build_mask_context *mask,
@@ -187,7 +188,7 @@ lp_build_tgsi_soa(LLVMBuilderRef builder,
void
-lp_build_tgsi_aos(LLVMBuilderRef builder,
+lp_build_tgsi_aos(struct gallivm_state *gallivm,
const struct tgsi_token *tokens,
struct lp_type type,
const unsigned char swizzles[4],
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_aos.c b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_aos.c
index c3c082b2b9..9dfc6098cc 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_aos.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_aos.c
@@ -175,9 +175,7 @@ emit_fetch(
LLVMValueRef scalar;
LLVMValueRef swizzle;
- index = LLVMConstInt(LLVMInt32Type(),
- reg->Register.Index*4 + chan,
- 0);
+ index = lp_build_const_int32(bld->base.gallivm, reg->Register.Index * 4 + chan);
scalar_ptr = LLVMBuildGEP(bld->base.builder, bld->consts_ptr,
&index, 1, "");
@@ -190,7 +188,7 @@ emit_fetch(
* NOTE: constants array is always assumed to be RGBA
*/
- swizzle = LLVMConstInt(LLVMInt32Type(), chan, 0);
+ swizzle = lp_build_const_int32(bld->base.gallivm, chan);
res = LLVMBuildInsertElement(bld->base.builder, res, scalar, swizzle, "");
}
@@ -206,7 +204,7 @@ emit_fetch(
unsigned i;
for (chan = 0; chan < 4; ++chan) {
- shuffles[chan] = LLVMConstInt(LLVMInt32Type(), chan, 0);
+ shuffles[chan] = lp_build_const_int32(bld->base.gallivm, chan);
}
for (i = 4; i < type.length; ++i) {
@@ -299,7 +297,7 @@ emit_store(
break;
case TGSI_SAT_MINUS_PLUS_ONE:
- value = lp_build_max(&bld->base, value, lp_build_const_vec(bld->base.type, -1.0));
+ value = lp_build_max(&bld->base, value, lp_build_const_vec(bld->base.gallivm, bld->base.type, -1.0));
value = lp_build_min(&bld->base, value, bld->base.one);
break;
@@ -350,7 +348,7 @@ emit_store(
/*
* Convert the value to an integer mask.
*/
- pred = lp_build_compare(bld->base.builder,
+ pred = lp_build_compare(bld->base.gallivm,
bld->base.type,
PIPE_FUNC_NOTEQUAL,
pred,
@@ -380,7 +378,8 @@ emit_store(
if (reg->Register.WriteMask != TGSI_WRITEMASK_XYZW) {
LLVMValueRef writemask;
- writemask = lp_build_const_mask_aos(bld->base.type, reg->Register.WriteMask);
+ writemask = lp_build_const_mask_aos(bld->base.gallivm, bld->base.type,
+ reg->Register.WriteMask);
if (mask) {
mask = LLVMBuildAnd(bld->base.builder, mask, writemask, "");
@@ -454,7 +453,8 @@ emit_declaration(
struct lp_build_tgsi_aos_context *bld,
const struct tgsi_full_declaration *decl)
{
- LLVMTypeRef vec_type = lp_build_vec_type(bld->base.type);
+ struct gallivm_state *gallivm = bld->base.gallivm;
+ LLVMTypeRef vec_type = lp_build_vec_type(bld->base.gallivm, bld->base.type);
unsigned first = decl->Range.First;
unsigned last = decl->Range.Last;
@@ -465,31 +465,26 @@ emit_declaration(
case TGSI_FILE_TEMPORARY:
assert(idx < LP_MAX_TGSI_TEMPS);
if (bld->indirect_files & (1 << TGSI_FILE_TEMPORARY)) {
- LLVMValueRef array_size = LLVMConstInt(LLVMInt32Type(),
- last + 1, 0);
- bld->temps_array = lp_build_array_alloca(bld->base.builder,
+ LLVMValueRef array_size = lp_build_const_int32(gallivm, last + 1);
+ bld->temps_array = lp_build_array_alloca(bld->base.gallivm,
vec_type, array_size, "");
} else {
- bld->temps[idx] = lp_build_alloca(bld->base.builder,
- vec_type, "");
+ bld->temps[idx] = lp_build_alloca(gallivm, vec_type, "");
}
break;
case TGSI_FILE_OUTPUT:
- bld->outputs[idx] = lp_build_alloca(bld->base.builder,
- vec_type, "");
+ bld->outputs[idx] = lp_build_alloca(gallivm, vec_type, "");
break;
case TGSI_FILE_ADDRESS:
assert(idx < LP_MAX_TGSI_ADDRS);
- bld->addr[idx] = lp_build_alloca(bld->base.builder,
- vec_type, "");
+ bld->addr[idx] = lp_build_alloca(gallivm, vec_type, "");
break;
case TGSI_FILE_PREDICATE:
assert(idx < LP_MAX_TGSI_PREDS);
- bld->preds[idx] = lp_build_alloca(bld->base.builder,
- vec_type, "");
+ bld->preds[idx] = lp_build_alloca(gallivm, vec_type, "");
break;
default:
@@ -644,7 +639,7 @@ emit_instruction(
src0 = emit_fetch(bld, inst, 0);
src1 = emit_fetch(bld, inst, 1);
src2 = emit_fetch(bld, inst, 2);
- tmp1 = lp_build_const_vec(bld->base.type, 0.5);
+ tmp1 = lp_build_const_vec(bld->base.gallivm, bld->base.type, 0.5);
tmp0 = lp_build_cmp(&bld->base, PIPE_FUNC_GREATER, src2, tmp1);
dst0 = lp_build_select(&bld->base, tmp0, src0, src1);
break;
@@ -1039,7 +1034,7 @@ emit_instruction(
void
-lp_build_tgsi_aos(LLVMBuilderRef builder,
+lp_build_tgsi_aos(struct gallivm_state *gallivm,
const struct tgsi_token *tokens,
struct lp_type type,
const unsigned char swizzles[4],
@@ -1058,8 +1053,8 @@ lp_build_tgsi_aos(LLVMBuilderRef builder,
/* Setup build context */
memset(&bld, 0, sizeof bld);
- lp_build_context_init(&bld.base, builder, type);
- lp_build_context_init(&bld.int_bld, builder, lp_int_type(type));
+ lp_build_context_init(&bld.base, gallivm, type);
+ lp_build_context_init(&bld.int_bld, gallivm, lp_int_type(type));
for (chan = 0; chan < 4; ++chan) {
bld.swizzles[chan] = swizzles[chan];
@@ -1131,7 +1126,7 @@ lp_build_tgsi_aos(LLVMBuilderRef builder,
imm[swizzle] = parse.FullToken.FullImmediate.u[chan].Float;
}
bld.immediates[num_immediates] =
- lp_build_const_aos(type,
+ lp_build_const_aos(gallivm, type,
imm[0], imm[1], imm[2], imm[3],
NULL);
num_immediates++;
@@ -1156,7 +1151,7 @@ lp_build_tgsi_aos(LLVMBuilderRef builder,
}
if (0) {
- LLVMBasicBlockRef block = LLVMGetInsertBlock(builder);
+ LLVMBasicBlockRef block = LLVMGetInsertBlock(gallivm->builder);
LLVMValueRef function = LLVMGetBasicBlockParent(block);
debug_printf("11111111111111111111111111111 \n");
tgsi_dump(tokens, 0);
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c
index 2f658195b2..66904e9749 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c
@@ -51,6 +51,7 @@
#include "lp_bld_arit.h"
#include "lp_bld_bitarit.h"
#include "lp_bld_gather.h"
+#include "lp_bld_init.h"
#include "lp_bld_logic.h"
#include "lp_bld_swizzle.h"
#include "lp_bld_flow.h"
@@ -175,7 +176,7 @@ static void lp_exec_mask_init(struct lp_exec_mask *mask, struct lp_build_context
mask->loop_stack_size = 0;
mask->call_stack_size = 0;
- mask->int_vec_type = lp_build_int_vec_type(mask->bld->type);
+ mask->int_vec_type = lp_build_int_vec_type(bld->gallivm, mask->bld->type);
mask->exec_mask = mask->ret_mask = mask->break_mask = mask->cont_mask = mask->cond_mask =
LLVMConstAllOnes(mask->int_vec_type);
}
@@ -268,10 +269,10 @@ static void lp_exec_bgnloop(struct lp_exec_mask *mask)
mask->loop_stack[mask->loop_stack_size].break_var = mask->break_var;
++mask->loop_stack_size;
- mask->break_var = lp_build_alloca(mask->bld->builder, mask->int_vec_type, "");
+ mask->break_var = lp_build_alloca(mask->bld->gallivm, mask->int_vec_type, "");
LLVMBuildStore(mask->bld->builder, mask->break_mask, mask->break_var);
- mask->loop_block = lp_build_insert_new_block(mask->bld->builder, "bgnloop");
+ mask->loop_block = lp_build_insert_new_block(mask->bld->gallivm, "bgnloop");
LLVMBuildBr(mask->bld->builder, mask->loop_block);
LLVMPositionBuilderAtEnd(mask->bld->builder, mask->loop_block);
@@ -307,11 +308,13 @@ static void lp_exec_continue(struct lp_exec_mask *mask)
}
-static void lp_exec_endloop(struct lp_exec_mask *mask)
+static void lp_exec_endloop(struct gallivm_state *gallivm,
+ struct lp_exec_mask *mask)
{
LLVMBasicBlockRef endloop;
- LLVMTypeRef reg_type = LLVMIntType(mask->bld->type.width*
- mask->bld->type.length);
+ LLVMTypeRef reg_type = LLVMIntTypeInContext(gallivm->context,
+ mask->bld->type.width *
+ mask->bld->type.length);
LLVMValueRef i1cond;
assert(mask->break_mask);
@@ -336,7 +339,7 @@ static void lp_exec_endloop(struct lp_exec_mask *mask)
LLVMBuildBitCast(mask->bld->builder, mask->exec_mask, reg_type, ""),
LLVMConstNull(reg_type), "");
- endloop = lp_build_insert_new_block(mask->bld->builder, "endloop");
+ endloop = lp_build_insert_new_block(mask->bld->gallivm, "endloop");
LLVMBuildCondBr(mask->bld->builder,
i1cond, mask->loop_block, endloop);
@@ -443,7 +446,7 @@ get_temp_ptr(struct lp_build_tgsi_soa_context *bld,
{
assert(chan < 4);
if (bld->indirect_files & (1 << TGSI_FILE_TEMPORARY)) {
- LLVMValueRef lindex = lp_build_const_int32(index * 4 + chan);
+ LLVMValueRef lindex = lp_build_const_int32(bld->base.gallivm, index * 4 + chan);
return LLVMBuildGEP(bld->base.builder, bld->temps_array, &lindex, 1, "");
}
else {
@@ -464,7 +467,8 @@ get_output_ptr(struct lp_build_tgsi_soa_context *bld,
{
assert(chan < 4);
if (bld->indirect_files & (1 << TGSI_FILE_OUTPUT)) {
- LLVMValueRef lindex = lp_build_const_int32(index * 4 + chan);
+ LLVMValueRef lindex = lp_build_const_int32(bld->base.gallivm,
+ index * 4 + chan);
return LLVMBuildGEP(bld->base.builder, bld->outputs_array, &lindex, 1, "");
}
else {
@@ -489,7 +493,7 @@ build_gather(struct lp_build_tgsi_soa_context *bld,
* Loop over elements of index_vec, load scalar value, insert it into 'res'.
*/
for (i = 0; i < bld->base.type.length; i++) {
- LLVMValueRef ii = LLVMConstInt(LLVMInt32Type(), i, 0);
+ LLVMValueRef ii = lp_build_const_int32(bld->base.gallivm, i);
LLVMValueRef index = LLVMBuildExtractElement(bld->base.builder,
indexes, ii, "");
LLVMValueRef scalar_ptr = LLVMBuildGEP(bld->base.builder, base_ptr,
@@ -514,6 +518,7 @@ emit_mask_scatter(struct lp_build_tgsi_soa_context *bld,
struct lp_exec_mask *mask,
LLVMValueRef pred)
{
+ struct gallivm_state *gallivm = bld->base.gallivm;
LLVMBuilderRef builder = bld->base.builder;
unsigned i;
@@ -531,7 +536,7 @@ emit_mask_scatter(struct lp_build_tgsi_soa_context *bld,
* Loop over elements of index_vec, store scalar value.
*/
for (i = 0; i < bld->base.type.length; i++) {
- LLVMValueRef ii = LLVMConstInt(LLVMInt32Type(), i, 0);
+ LLVMValueRef ii = lp_build_const_int32(gallivm, i);
LLVMValueRef index = LLVMBuildExtractElement(builder, indexes, ii, "");
LLVMValueRef scalar_ptr = LLVMBuildGEP(builder, base_ptr, &index, 1, "scatter_ptr");
LLVMValueRef val = LLVMBuildExtractElement(builder, values, ii, "scatter_val");
@@ -539,7 +544,7 @@ emit_mask_scatter(struct lp_build_tgsi_soa_context *bld,
LLVMBuildExtractElement(builder, pred, ii, "scatter_pred") : NULL;
if (0)
- lp_build_printf(builder, "scatter %d: val %f at %d %p\n",
+ lp_build_printf(gallivm, "scatter %d: val %f at %d %p\n",
ii, val, index, scalar_ptr);
if (scalar_pred) {
@@ -576,7 +581,7 @@ get_indirect_index(struct lp_build_tgsi_soa_context *bld,
assert(bld->indirect_files & (1 << reg_file));
- base = lp_build_const_int_vec(uint_bld->type, reg_index);
+ base = lp_build_const_int_vec(bld->base.gallivm, uint_bld->type, reg_index);
assert(swizzle < 4);
rel = LLVMBuildLoad(bld->base.builder,
@@ -590,7 +595,8 @@ get_indirect_index(struct lp_build_tgsi_soa_context *bld,
index = lp_build_add(uint_bld, base, rel);
- max_index = lp_build_const_int_vec(uint_bld->type,
+ max_index = lp_build_const_int_vec(bld->base.gallivm,
+ uint_bld->type,
bld->info->file_max[reg_file]);
assert(!uint_bld->type.sign);
@@ -610,6 +616,7 @@ emit_fetch(
unsigned src_op,
const unsigned chan_index )
{
+ struct gallivm_state *gallivm = bld->base.gallivm;
struct lp_build_context *uint_bld = &bld->uint_bld;
const struct tgsi_full_src_register *reg = &inst->Src[src_op];
const unsigned swizzle =
@@ -635,7 +642,7 @@ emit_fetch(
case TGSI_FILE_CONSTANT:
if (reg->Register.Indirect) {
LLVMValueRef swizzle_vec =
- lp_build_const_int_vec(uint_bld->type, swizzle);
+ lp_build_const_int_vec(bld->base.gallivm, uint_bld->type, swizzle);
LLVMValueRef index_vec; /* index into the const buffer */
/* index_vec = indirect_index * 4 + swizzle */
@@ -649,7 +656,7 @@ emit_fetch(
LLVMValueRef index; /* index into the const buffer */
LLVMValueRef scalar, scalar_ptr;
- index = lp_build_const_int32(reg->Register.Index*4 + swizzle);
+ index = lp_build_const_int32(gallivm, reg->Register.Index*4 + swizzle);
scalar_ptr = LLVMBuildGEP(bld->base.builder, bld->consts_ptr,
&index, 1, "");
@@ -667,9 +674,9 @@ emit_fetch(
case TGSI_FILE_INPUT:
if (reg->Register.Indirect) {
LLVMValueRef swizzle_vec =
- lp_build_const_int_vec(uint_bld->type, swizzle);
+ lp_build_const_int_vec(gallivm, uint_bld->type, swizzle);
LLVMValueRef length_vec =
- lp_build_const_int_vec(uint_bld->type, bld->base.type.length);
+ lp_build_const_int_vec(gallivm, uint_bld->type, bld->base.type.length);
LLVMValueRef index_vec; /* index into the const buffer */
LLVMValueRef inputs_array;
LLVMTypeRef float4_ptr_type;
@@ -680,7 +687,7 @@ emit_fetch(
index_vec = lp_build_mul(uint_bld, index_vec, length_vec);
/* cast inputs_array pointer to float* */
- float4_ptr_type = LLVMPointerType(LLVMFloatType(), 0);
+ float4_ptr_type = LLVMPointerType(LLVMFloatTypeInContext(gallivm->context), 0);
inputs_array = LLVMBuildBitCast(uint_bld->builder, bld->inputs_array,
float4_ptr_type, "");
@@ -688,7 +695,8 @@ emit_fetch(
res = build_gather(bld, inputs_array, index_vec);
} else {
if (bld->indirect_files & (1 << TGSI_FILE_INPUT)) {
- LLVMValueRef lindex = lp_build_const_int32(reg->Register.Index * 4 + swizzle);
+ LLVMValueRef lindex = lp_build_const_int32(gallivm,
+ reg->Register.Index * 4 + swizzle);
LLVMValueRef input_ptr = LLVMBuildGEP(bld->base.builder,
bld->inputs_array, &lindex, 1, "");
res = LLVMBuildLoad(bld->base.builder, input_ptr, "");
@@ -703,9 +711,10 @@ emit_fetch(
case TGSI_FILE_TEMPORARY:
if (reg->Register.Indirect) {
LLVMValueRef swizzle_vec =
- lp_build_const_int_vec(uint_bld->type, swizzle);
+ lp_build_const_int_vec(bld->base.gallivm, uint_bld->type, swizzle);
LLVMValueRef length_vec =
- lp_build_const_int_vec(uint_bld->type, bld->base.type.length);
+ lp_build_const_int_vec(bld->base.gallivm, uint_bld->type,
+ bld->base.type.length);
LLVMValueRef index_vec; /* index into the const buffer */
LLVMValueRef temps_array;
LLVMTypeRef float4_ptr_type;
@@ -716,7 +725,7 @@ emit_fetch(
index_vec = lp_build_mul(uint_bld, index_vec, length_vec);
/* cast temps_array pointer to float* */
- float4_ptr_type = LLVMPointerType(LLVMFloatType(), 0);
+ float4_ptr_type = LLVMPointerType(LLVMFloatTypeInContext(bld->base.gallivm->context), 0);
temps_array = LLVMBuildBitCast(uint_bld->builder, bld->temps_array,
float4_ptr_type, "");
@@ -835,7 +844,7 @@ emit_fetch_predicate(
* is needlessly causing two comparisons due to storing the intermediate
* result as float vector instead of an integer mask vector.
*/
- value = lp_build_compare(bld->base.builder,
+ value = lp_build_compare(bld->base.gallivm,
bld->base.type,
PIPE_FUNC_NOTEQUAL,
value,
@@ -866,6 +875,7 @@ emit_store(
LLVMValueRef pred,
LLVMValueRef value)
{
+ struct gallivm_state *gallivm = bld->base.gallivm;
const struct tgsi_full_dst_register *reg = &inst->Dst[index];
struct lp_build_context *uint_bld = &bld->uint_bld;
LLVMValueRef indirect_index = NULL;
@@ -880,7 +890,7 @@ emit_store(
break;
case TGSI_SAT_MINUS_PLUS_ONE:
- value = lp_build_max(&bld->base, value, lp_build_const_vec(bld->base.type, -1.0));
+ value = lp_build_max(&bld->base, value, lp_build_const_vec(bld->base.gallivm, bld->base.type, -1.0));
value = lp_build_min(&bld->base, value, bld->base.one);
break;
@@ -902,9 +912,9 @@ emit_store(
if (reg->Register.Indirect) {
LLVMBuilderRef builder = bld->base.builder;
LLVMValueRef chan_vec =
- lp_build_const_int_vec(uint_bld->type, chan_index);
+ lp_build_const_int_vec(gallivm, uint_bld->type, chan_index);
LLVMValueRef length_vec =
- lp_build_const_int_vec(uint_bld->type, bld->base.type.length);
+ lp_build_const_int_vec(gallivm, uint_bld->type, bld->base.type.length);
LLVMValueRef index_vec; /* indexes into the temp registers */
LLVMValueRef outputs_array;
LLVMValueRef pixel_offsets;
@@ -914,7 +924,7 @@ emit_store(
/* build pixel offset vector: {0, 1, 2, 3, ...} */
pixel_offsets = uint_bld->undef;
for (i = 0; i < bld->base.type.length; i++) {
- LLVMValueRef ii = lp_build_const_int32(i);
+ LLVMValueRef ii = lp_build_const_int32(gallivm, i);
pixel_offsets = LLVMBuildInsertElement(builder, pixel_offsets,
ii, ii, "");
}
@@ -925,7 +935,8 @@ emit_store(
index_vec = lp_build_mul(uint_bld, index_vec, length_vec);
index_vec = lp_build_add(uint_bld, index_vec, pixel_offsets);
- float_ptr_type = LLVMPointerType(LLVMFloatType(), 0);
+ float_ptr_type =
+ LLVMPointerType(LLVMFloatTypeInContext(gallivm->context), 0);
outputs_array = LLVMBuildBitCast(builder, bld->outputs_array,
float_ptr_type, "");
@@ -944,9 +955,10 @@ emit_store(
if (reg->Register.Indirect) {
LLVMBuilderRef builder = bld->base.builder;
LLVMValueRef chan_vec =
- lp_build_const_int_vec(uint_bld->type, chan_index);
+ lp_build_const_int_vec(gallivm, uint_bld->type, chan_index);
LLVMValueRef length_vec =
- lp_build_const_int_vec(uint_bld->type, bld->base.type.length);
+ lp_build_const_int_vec(gallivm, uint_bld->type,
+ bld->base.type.length);
LLVMValueRef index_vec; /* indexes into the temp registers */
LLVMValueRef temps_array;
LLVMValueRef pixel_offsets;
@@ -956,7 +968,7 @@ emit_store(
/* build pixel offset vector: {0, 1, 2, 3, ...} */
pixel_offsets = uint_bld->undef;
for (i = 0; i < bld->base.type.length; i++) {
- LLVMValueRef ii = lp_build_const_int32(i);
+ LLVMValueRef ii = lp_build_const_int32(gallivm, i);
pixel_offsets = LLVMBuildInsertElement(builder, pixel_offsets,
ii, ii, "");
}
@@ -967,7 +979,8 @@ emit_store(
index_vec = lp_build_mul(uint_bld, index_vec, length_vec);
index_vec = lp_build_add(uint_bld, index_vec, pixel_offsets);
- float_ptr_type = LLVMPointerType(LLVMFloatType(), 0);
+ float_ptr_type =
+ LLVMPointerType(LLVMFloatTypeInContext(gallivm->context), 0);
temps_array = LLVMBuildBitCast(builder, bld->temps_array,
float_ptr_type, "");
@@ -1073,8 +1086,7 @@ emit_tex( struct lp_build_tgsi_soa_context *bld,
}
if (modifier == LP_BLD_TEX_MODIFIER_EXPLICIT_DERIV) {
- LLVMTypeRef i32t = LLVMInt32Type();
- LLVMValueRef index0 = LLVMConstInt(i32t, 0, 0);
+ LLVMValueRef index0 = lp_build_const_int32(bld->base.gallivm, 0);
for (i = 0; i < num_coords; i++) {
LLVMValueRef src1 = emit_fetch( bld, inst, 1, i );
LLVMValueRef src2 = emit_fetch( bld, inst, 2, i );
@@ -1095,7 +1107,7 @@ emit_tex( struct lp_build_tgsi_soa_context *bld,
}
bld->sampler->emit_fetch_texel(bld->sampler,
- bld->base.builder,
+ bld->base.gallivm,
bld->base.type,
unit, num_coords, coords,
ddx, ddy,
@@ -1234,21 +1246,22 @@ emit_kilp(struct lp_build_tgsi_soa_context *bld,
static void
emit_dump_temps(struct lp_build_tgsi_soa_context *bld)
{
- LLVMBuilderRef builder = bld->base.builder;
+ struct gallivm_state *gallivm = bld->base.gallivm;
+ LLVMBuilderRef builder = gallivm->builder;
LLVMValueRef temp_ptr;
- LLVMValueRef i0 = lp_build_const_int32(0);
- LLVMValueRef i1 = lp_build_const_int32(1);
- LLVMValueRef i2 = lp_build_const_int32(2);
- LLVMValueRef i3 = lp_build_const_int32(3);
+ LLVMValueRef i0 = lp_build_const_int32(gallivm, 0);
+ LLVMValueRef i1 = lp_build_const_int32(gallivm, 1);
+ LLVMValueRef i2 = lp_build_const_int32(gallivm, 2);
+ LLVMValueRef i3 = lp_build_const_int32(gallivm, 3);
int index;
int n = bld->info->file_max[TGSI_FILE_TEMPORARY];
for (index = 0; index < n; index++) {
- LLVMValueRef idx = lp_build_const_int32(index);
+ LLVMValueRef idx = lp_build_const_int32(gallivm, index);
LLVMValueRef v[4][4], res;
int chan;
- lp_build_printf(builder, "TEMP[%d]:\n", idx);
+ lp_build_printf(gallivm, "TEMP[%d]:\n", idx);
for (chan = 0; chan < 4; chan++) {
temp_ptr = get_temp_ptr(bld, index, chan);
@@ -1259,13 +1272,13 @@ emit_dump_temps(struct lp_build_tgsi_soa_context *bld)
v[chan][3] = LLVMBuildExtractElement(builder, res, i3, "");
}
- lp_build_printf(builder, " X: %f %f %f %f\n",
+ lp_build_printf(gallivm, " X: %f %f %f %f\n",
v[0][0], v[0][1], v[0][2], v[0][3]);
- lp_build_printf(builder, " Y: %f %f %f %f\n",
+ lp_build_printf(gallivm, " Y: %f %f %f %f\n",
v[1][0], v[1][1], v[1][2], v[1][3]);
- lp_build_printf(builder, " Z: %f %f %f %f\n",
+ lp_build_printf(gallivm, " Z: %f %f %f %f\n",
v[2][0], v[2][1], v[2][2], v[2][3]);
- lp_build_printf(builder, " W: %f %f %f %f\n",
+ lp_build_printf(gallivm, " W: %f %f %f %f\n",
v[3][0], v[3][1], v[3][2], v[3][3]);
}
}
@@ -1277,6 +1290,7 @@ emit_declaration(
struct lp_build_tgsi_soa_context *bld,
const struct tgsi_full_declaration *decl)
{
+ struct gallivm_state *gallivm = bld->base.gallivm;
LLVMTypeRef vec_type = bld->base.vec_type;
const unsigned first = decl->Range.First;
const unsigned last = decl->Range.Last;
@@ -1289,15 +1303,14 @@ emit_declaration(
assert(idx < LP_MAX_TGSI_TEMPS);
if (!(bld->indirect_files & (1 << TGSI_FILE_TEMPORARY))) {
for (i = 0; i < NUM_CHANNELS; i++)
- bld->temps[idx][i] = lp_build_alloca(bld->base.builder,
- vec_type, "temp");
+ bld->temps[idx][i] = lp_build_alloca(gallivm, vec_type, "temp");
}
break;
case TGSI_FILE_OUTPUT:
if (!(bld->indirect_files & (1 << TGSI_FILE_OUTPUT))) {
for (i = 0; i < NUM_CHANNELS; i++)
- bld->outputs[idx][i] = lp_build_alloca(bld->base.builder,
+ bld->outputs[idx][i] = lp_build_alloca(gallivm,
vec_type, "output");
}
break;
@@ -1305,15 +1318,14 @@ emit_declaration(
case TGSI_FILE_ADDRESS:
assert(idx < LP_MAX_TGSI_ADDRS);
for (i = 0; i < NUM_CHANNELS; i++)
- bld->addr[idx][i] = lp_build_alloca(bld->base.builder,
- vec_type, "addr");
+ bld->addr[idx][i] = lp_build_alloca(gallivm, vec_type, "addr");
break;
case TGSI_FILE_PREDICATE:
assert(idx < LP_MAX_TGSI_PREDS);
for (i = 0; i < NUM_CHANNELS; i++)
- bld->preds[idx][i] = lp_build_alloca(bld->base.builder,
- vec_type, "predicate");
+ bld->preds[idx][i] = lp_build_alloca(gallivm, vec_type,
+ "predicate");
break;
default:
@@ -1639,7 +1651,7 @@ emit_instruction(
src0 = emit_fetch( bld, inst, 0, chan_index );
src1 = emit_fetch( bld, inst, 1, chan_index );
src2 = emit_fetch( bld, inst, 2, chan_index );
- tmp1 = lp_build_const_vec(bld->base.type, 0.5);
+ tmp1 = lp_build_const_vec(bld->base.gallivm, bld->base.type, 0.5);
tmp0 = lp_build_cmp( &bld->base, PIPE_FUNC_GREATER, src2, tmp1);
dst0[chan_index] = lp_build_select( &bld->base, tmp0, src0, src1 );
}
@@ -2151,7 +2163,7 @@ emit_instruction(
break;
case TGSI_OPCODE_ENDLOOP:
- lp_exec_endloop(&bld->exec_mask);
+ lp_exec_endloop(bld->base.gallivm, &bld->exec_mask);
break;
case TGSI_OPCODE_ENDSUB:
@@ -2284,7 +2296,7 @@ emit_instruction(
void
-lp_build_tgsi_soa(LLVMBuilderRef builder,
+lp_build_tgsi_soa(struct gallivm_state *gallivm,
const struct tgsi_token *tokens,
struct lp_type type,
struct lp_build_mask_context *mask,
@@ -2312,9 +2324,9 @@ lp_build_tgsi_soa(LLVMBuilderRef builder,
/* Setup build context */
memset(&bld, 0, sizeof bld);
- lp_build_context_init(&bld.base, builder, type);
- lp_build_context_init(&bld.uint_bld, builder, lp_uint_type(type));
- lp_build_context_init(&bld.elem_bld, builder, lp_elem_type(type));
+ lp_build_context_init(&bld.base, gallivm, type);
+ lp_build_context_init(&bld.uint_bld, gallivm, lp_uint_type(type));
+ lp_build_context_init(&bld.elem_bld, gallivm, lp_elem_type(type));
bld.mask = mask;
bld.pos = pos;
bld.inputs = inputs;
@@ -2334,17 +2346,19 @@ lp_build_tgsi_soa(LLVMBuilderRef builder,
lp_exec_mask_init(&bld.exec_mask, &bld.base);
if (bld.indirect_files & (1 << TGSI_FILE_TEMPORARY)) {
- LLVMValueRef array_size = LLVMConstInt(LLVMInt32Type(),
- info->file_max[TGSI_FILE_TEMPORARY]*4 + 4, 0);
- bld.temps_array = lp_build_array_alloca(bld.base.builder,
+ LLVMValueRef array_size =
+ lp_build_const_int32(gallivm,
+ info->file_max[TGSI_FILE_TEMPORARY] * 4 + 4);
+ bld.temps_array = lp_build_array_alloca(gallivm,
bld.base.vec_type, array_size,
"temp_array");
}
if (bld.indirect_files & (1 << TGSI_FILE_OUTPUT)) {
- LLVMValueRef array_size = LLVMConstInt(LLVMInt32Type(),
- info->file_max[TGSI_FILE_OUTPUT]*4 + 4, 0);
- bld.outputs_array = lp_build_array_alloca(bld.base.builder,
+ LLVMValueRef array_size =
+ lp_build_const_int32(gallivm,
+ info->file_max[TGSI_FILE_OUTPUT] * 4 + 4);
+ bld.outputs_array = lp_build_array_alloca(gallivm,
bld.base.vec_type, array_size,
"output_array");
}
@@ -2354,9 +2368,9 @@ lp_build_tgsi_soa(LLVMBuilderRef builder,
if (bld.indirect_files & (1 << TGSI_FILE_INPUT)) {
unsigned index, chan;
LLVMTypeRef vec_type = bld.base.vec_type;
- LLVMValueRef array_size = LLVMConstInt(LLVMInt32Type(),
- info->file_max[TGSI_FILE_INPUT]*4 + 4, 0);
- bld.inputs_array = lp_build_array_alloca(bld.base.builder,
+ LLVMValueRef array_size =
+ lp_build_const_int32(gallivm, info->file_max[TGSI_FILE_INPUT]*4 + 4);
+ bld.inputs_array = lp_build_array_alloca(gallivm,
vec_type, array_size,
"input_array");
@@ -2364,7 +2378,8 @@ lp_build_tgsi_soa(LLVMBuilderRef builder,
for (index = 0; index < info->num_inputs; ++index) {
for (chan = 0; chan < NUM_CHANNELS; ++chan) {
- LLVMValueRef lindex = lp_build_const_int32(index * 4 + chan);
+ LLVMValueRef lindex =
+ lp_build_const_int32(gallivm, index * 4 + chan);
LLVMValueRef input_ptr =
LLVMBuildGEP(bld.base.builder, bld.inputs_array,
&lindex, 1, "");
@@ -2420,7 +2435,7 @@ lp_build_tgsi_soa(LLVMBuilderRef builder,
assert(num_immediates < LP_MAX_TGSI_IMMEDIATES);
for( i = 0; i < size; ++i )
bld.immediates[num_immediates][i] =
- lp_build_const_vec(type, parse.FullToken.FullImmediate.u[i].Float);
+ lp_build_const_vec(gallivm, type, parse.FullToken.FullImmediate.u[i].Float);
for( i = size; i < 4; ++i )
bld.immediates[num_immediates][i] = bld.base.undef;
num_immediates++;
@@ -2457,7 +2472,7 @@ lp_build_tgsi_soa(LLVMBuilderRef builder,
}
if (0) {
- LLVMBasicBlockRef block = LLVMGetInsertBlock(builder);
+ LLVMBasicBlockRef block = LLVMGetInsertBlock(gallivm->builder);
LLVMValueRef function = LLVMGetBasicBlockParent(block);
debug_printf("11111111111111111111111111111 \n");
tgsi_dump(tokens, 0);
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_type.c b/src/gallium/auxiliary/gallivm/lp_bld_type.c
index 5205c7ada9..ee61646766 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_type.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_type.c
@@ -30,34 +30,35 @@
#include "lp_bld_type.h"
#include "lp_bld_const.h"
+#include "lp_bld_init.h"
LLVMTypeRef
-lp_build_elem_type(struct lp_type type)
+lp_build_elem_type(struct gallivm_state *gallivm, struct lp_type type)
{
if (type.floating) {
switch(type.width) {
case 32:
- return LLVMFloatType();
+ return LLVMFloatTypeInContext(gallivm->context);
break;
case 64:
- return LLVMDoubleType();
+ return LLVMDoubleTypeInContext(gallivm->context);
break;
default:
assert(0);
- return LLVMFloatType();
+ return LLVMFloatTypeInContext(gallivm->context);
}
}
else {
- return LLVMIntType(type.width);
+ return LLVMIntTypeInContext(gallivm->context, type.width);
}
}
LLVMTypeRef
-lp_build_vec_type(struct lp_type type)
+lp_build_vec_type(struct gallivm_state *gallivm,struct lp_type type)
{
- LLVMTypeRef elem_type = lp_build_elem_type(type);
+ LLVMTypeRef elem_type = lp_build_elem_type(gallivm, type);
if (type.length == 1)
return elem_type;
else
@@ -149,16 +150,16 @@ lp_check_value(struct lp_type type, LLVMValueRef val)
LLVMTypeRef
-lp_build_int_elem_type(struct lp_type type)
+lp_build_int_elem_type(struct gallivm_state *gallivm, struct lp_type type)
{
- return LLVMIntType(type.width);
+ return LLVMIntTypeInContext(gallivm->context, type.width);
}
LLVMTypeRef
-lp_build_int_vec_type(struct lp_type type)
+lp_build_int_vec_type(struct gallivm_state *gallivm, struct lp_type type)
{
- LLVMTypeRef elem_type = lp_build_int_elem_type(type);
+ LLVMTypeRef elem_type = lp_build_int_elem_type(gallivm, type);
if (type.length == 1)
return elem_type;
else
@@ -170,7 +171,7 @@ lp_build_int_vec_type(struct lp_type type)
* Build int32[4] vector type
*/
LLVMTypeRef
-lp_build_int32_vec4_type(void)
+lp_build_int32_vec4_type(struct gallivm_state *gallivm)
{
struct lp_type t;
LLVMTypeRef type;
@@ -182,7 +183,7 @@ lp_build_int32_vec4_type(void)
t.width = 32; /* 32-bit int */
t.length = 4; /* 4 elements per vector */
- type = lp_build_int_elem_type(t);
+ type = lp_build_int_elem_type(gallivm, t);
return LLVMVectorType(type, t.length);
}
@@ -383,15 +384,16 @@ lp_dump_llvmtype(LLVMTypeRef t)
void
lp_build_context_init(struct lp_build_context *bld,
- LLVMBuilderRef builder,
+ struct gallivm_state *gallivm,
struct lp_type type)
{
- bld->builder = builder;
+ bld->gallivm = gallivm;
+ bld->builder = gallivm->builder;
bld->type = type;
- bld->int_elem_type = lp_build_int_elem_type(type);
+ bld->int_elem_type = lp_build_int_elem_type(gallivm, type);
if (type.floating)
- bld->elem_type = lp_build_elem_type(type);
+ bld->elem_type = lp_build_elem_type(gallivm, type);
else
bld->elem_type = bld->int_elem_type;
@@ -406,5 +408,5 @@ lp_build_context_init(struct lp_build_context *bld,
bld->undef = LLVMGetUndef(bld->vec_type);
bld->zero = LLVMConstNull(bld->vec_type);
- bld->one = lp_build_one(type);
+ bld->one = lp_build_one(gallivm, type);
}
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_type.h b/src/gallium/auxiliary/gallivm/lp_bld_type.h
index a135d0df84..e62e90d638 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_type.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_type.h
@@ -122,6 +122,8 @@ struct lp_build_context
{
LLVMBuilderRef builder;
+ struct gallivm_state *gallivm;
+
/**
* This not only describes the input/output LLVM types, but also whether
* to normalize/clamp the results.
@@ -285,11 +287,11 @@ lp_type_ufixed(unsigned width)
LLVMTypeRef
-lp_build_elem_type(struct lp_type type);
+lp_build_elem_type(struct gallivm_state *gallivm, struct lp_type type);
LLVMTypeRef
-lp_build_vec_type(struct lp_type type);
+lp_build_vec_type(struct gallivm_state *gallivm, struct lp_type type);
boolean
@@ -305,15 +307,15 @@ lp_check_value(struct lp_type type, LLVMValueRef val);
LLVMTypeRef
-lp_build_int_elem_type(struct lp_type type);
+lp_build_int_elem_type(struct gallivm_state *gallivm, struct lp_type type);
LLVMTypeRef
-lp_build_int_vec_type(struct lp_type type);
+lp_build_int_vec_type(struct gallivm_state *gallivm, struct lp_type type);
LLVMTypeRef
-lp_build_int32_vec4_type(void);
+lp_build_int32_vec4_type(struct gallivm_state *gallivm);
static INLINE struct lp_type
@@ -394,7 +396,7 @@ lp_dump_llvmtype(LLVMTypeRef t);
void
lp_build_context_init(struct lp_build_context *bld,
- LLVMBuilderRef builder,
+ struct gallivm_state *gallivm,
struct lp_type type);