gallivm: Add some utility functions to set/get array elements too.
authorJosé Fonseca <jfonseca@vmware.com>
Fri, 3 Sep 2010 09:53:39 +0000 (10:53 +0100)
committerJosé Fonseca <jfonseca@vmware.com>
Sat, 11 Sep 2010 12:27:22 +0000 (13:27 +0100)
src/gallium/auxiliary/gallivm/lp_bld_struct.c
src/gallium/auxiliary/gallivm/lp_bld_struct.h

index 3998ac374fe8997dd50dc5554380dd792deb52f7..c25b2f6493c01f2bb644b1cd2844b68e6ecbe237 100644 (file)
@@ -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);
+}
index 147336edb4b3c60c18cd0771c5ef7df25fb2648c..f8b6dab4bfb22a68d1e02d2dd3bc1ab37010a51b 100644 (file)
@@ -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 */