Mesa (master): gallivm: Helper functions for pointer indirection.

Jose Fonseca jrfonseca at kemper.freedesktop.org
Sat Sep 11 05:47:47 PDT 2010


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

Author: José Fonseca <jfonseca at vmware.com>
Date:   Fri Sep  3 11:53:48 2010 +0100

gallivm: Helper functions for pointer indirection.

---

 src/gallium/auxiliary/gallivm/lp_bld_struct.c |   39 +++++++++++++++++++++++++
 src/gallium/auxiliary/gallivm/lp_bld_struct.h |   17 +++++++++++
 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 c25b2f6..4693c2d 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 f8b6dab..eb87a8e 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 */



More information about the mesa-commit mailing list