Mesa (master): gallivm: Add some utility functions to set/ get array elements too.

Jose Fonseca jrfonseca at kemper.freedesktop.org
Sat Sep 11 12:47:46 UTC 2010


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

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

gallivm: Add some utility functions to set/get array elements too.

---

 src/gallium/auxiliary/gallivm/lp_bld_struct.c |   46 +++++++++++++++++++++++++
 src/gallium/auxiliary/gallivm/lp_bld_struct.h |   24 +++++++++++++
 2 files changed, 70 insertions(+), 0 deletions(-)

diff --git a/src/gallium/auxiliary/gallivm/lp_bld_struct.c b/src/gallium/auxiliary/gallivm/lp_bld_struct.c
index 3998ac3..c25b2f6 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_struct.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_struct.c
@@ -70,3 +70,49 @@ lp_build_struct_get(LLVMBuilderRef builder,
    lp_build_name(res, "%s.%s", LLVMGetValueName(ptr), name);
    return res;
 }
+
+
+LLVMValueRef
+lp_build_array_get_ptr(LLVMBuilderRef builder,
+                       LLVMValueRef ptr,
+                       LLVMValueRef index)
+{
+   LLVMValueRef indices[2];
+   LLVMValueRef element_ptr;
+   indices[0] = LLVMConstInt(LLVMInt32Type(), 0, 0);
+   indices[1] = index;
+   element_ptr = LLVMBuildGEP(builder, ptr, indices, Elements(indices), "");
+#ifdef DEBUG
+   lp_build_name(element_ptr, "&%s[%s]",
+                 LLVMGetValueName(ptr), LLVMGetValueName(index));
+#endif
+   return element_ptr;
+}
+
+
+LLVMValueRef
+lp_build_array_get(LLVMBuilderRef builder,
+                   LLVMValueRef ptr,
+                   LLVMValueRef index)
+{
+   LLVMValueRef element_ptr;
+   LLVMValueRef res;
+   element_ptr = lp_build_array_get_ptr(builder, ptr, index);
+   res = LLVMBuildLoad(builder, element_ptr, "");
+#ifdef DEBUG
+   lp_build_name(res, "%s[%s]", LLVMGetValueName(ptr), LLVMGetValueName(index));
+#endif
+   return res;
+}
+
+
+void
+lp_build_array_set(LLVMBuilderRef builder,
+                   LLVMValueRef ptr,
+                   LLVMValueRef index,
+                   LLVMValueRef value)
+{
+   LLVMValueRef element_ptr;
+   element_ptr = lp_build_array_get_ptr(builder, ptr, index);
+   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 147336e..f8b6dab 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_struct.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_struct.h
@@ -71,5 +71,29 @@ lp_build_struct_get(LLVMBuilderRef builder,
                     unsigned member,
                     const char *name);
 
+/**
+ * Get value pointer to an array element.
+ */
+LLVMValueRef
+lp_build_array_get_ptr(LLVMBuilderRef builder,
+                       LLVMValueRef ptr,
+                       LLVMValueRef index);
+
+/**
+ * Get the value of an array element.
+ */
+LLVMValueRef
+lp_build_array_get(LLVMBuilderRef builder,
+                   LLVMValueRef ptr,
+                   LLVMValueRef index);
+
+/**
+ * Set the value of an array element.
+ */
+void
+lp_build_array_set(LLVMBuilderRef builder,
+                   LLVMValueRef ptr,
+                   LLVMValueRef index,
+                   LLVMValueRef value);
 
 #endif /* !LP_BLD_STRUCT_H */




More information about the mesa-commit mailing list