summaryrefslogtreecommitdiffstats
path: root/src/gallium/auxiliary
diff options
context:
space:
mode:
authorJosé Fonseca <[email protected]>2010-09-03 11:53:48 +0100
committerJosé Fonseca <[email protected]>2010-09-11 13:27:38 +0100
commitc0d41d0404285df4f3a8728ddc3b451e54011c7a (patch)
treebeb630ced1fd13b3a816ed5704ede4460f17bf20 /src/gallium/auxiliary
parent225530f1f222152754521eb4708d6352cd179656 (diff)
gallivm: Helper functions for pointer indirection.
Diffstat (limited to 'src/gallium/auxiliary')
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_struct.c39
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_struct.h17
2 files changed, 56 insertions, 0 deletions
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_struct.c b/src/gallium/auxiliary/gallivm/lp_bld_struct.c
index c25b2f6493c..4693c2de6f9 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_struct.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_struct.c
@@ -49,6 +49,8 @@ lp_build_struct_get_ptr(LLVMBuilderRef builder,
{
LLVMValueRef indices[2];
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), "");
@@ -65,6 +67,8 @@ lp_build_struct_get(LLVMBuilderRef builder,
{
LLVMValueRef member_ptr;
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, "");
lp_build_name(res, "%s.%s", LLVMGetValueName(ptr), name);
@@ -79,6 +83,8 @@ lp_build_array_get_ptr(LLVMBuilderRef builder,
{
LLVMValueRef indices[2];
LLVMValueRef element_ptr;
+ assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind);
+ assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMArrayTypeKind);
indices[0] = LLVMConstInt(LLVMInt32Type(), 0, 0);
indices[1] = index;
element_ptr = LLVMBuildGEP(builder, ptr, indices, Elements(indices), "");
@@ -97,6 +103,8 @@ lp_build_array_get(LLVMBuilderRef builder,
{
LLVMValueRef element_ptr;
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, "");
#ifdef DEBUG
@@ -113,6 +121,37 @@ lp_build_array_set(LLVMBuilderRef builder,
LLVMValueRef value)
{
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);
}
+
+
+LLVMValueRef
+lp_build_pointer_get(LLVMBuilderRef builder,
+ LLVMValueRef ptr,
+ LLVMValueRef index)
+{
+ LLVMValueRef element_ptr;
+ LLVMValueRef res;
+ assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind);
+ element_ptr = LLVMBuildGEP(builder, ptr, &index, 1, "");
+ res = LLVMBuildLoad(builder, element_ptr, "");
+#ifdef DEBUG
+ lp_build_name(res, "%s[%s]", LLVMGetValueName(ptr), LLVMGetValueName(index));
+#endif
+ return res;
+}
+
+
+void
+lp_build_pointer_set(LLVMBuilderRef builder,
+ LLVMValueRef ptr,
+ LLVMValueRef index,
+ LLVMValueRef value)
+{
+ LLVMValueRef element_ptr;
+ element_ptr = LLVMBuildGEP(builder, ptr, &index, 1, "");
+ LLVMBuildStore(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 f8b6dab4bfb..eb87a8eee9e 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_struct.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_struct.h
@@ -96,4 +96,21 @@ lp_build_array_set(LLVMBuilderRef builder,
LLVMValueRef index,
LLVMValueRef value);
+/**
+ * Get the value of an array element.
+ */
+LLVMValueRef
+lp_build_pointer_get(LLVMBuilderRef builder,
+ LLVMValueRef ptr,
+ LLVMValueRef index);
+
+/**
+ * Set the value of an array element.
+ */
+void
+lp_build_pointer_set(LLVMBuilderRef builder,
+ LLVMValueRef ptr,
+ LLVMValueRef index,
+ LLVMValueRef value);
+
#endif /* !LP_BLD_STRUCT_H */