Mesa (master): gallivm: added aligned pointer get/set

Jose Fonseca jrfonseca at kemper.freedesktop.org
Wed May 2 09:25:57 UTC 2012


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

Author: James Benton <jbenton at vmware.com>
Date:   Thu Apr 19 13:13:17 2012 +0100

gallivm: added aligned pointer get/set

---

 src/gallium/auxiliary/gallivm/lp_bld_init.h   |    7 +++++
 src/gallium/auxiliary/gallivm/lp_bld_misc.cpp |   15 +++++++++++
 src/gallium/auxiliary/gallivm/lp_bld_struct.c |   34 +++++++++++++++++++++++++
 src/gallium/auxiliary/gallivm/lp_bld_struct.h |   25 ++++++++++++++++++
 4 files changed, 81 insertions(+), 0 deletions(-)

diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.h b/src/gallium/auxiliary/gallivm/lp_bld_init.h
index f68bf75..5fc0f99 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_init.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_init.h
@@ -81,5 +81,12 @@ extern LLVMValueRef
 lp_build_load_volatile(LLVMBuilderRef B, LLVMValueRef PointerVal,
                        const char *Name);
 
+void
+lp_set_load_alignment(LLVMValueRef Inst,
+                       unsigned Align);
+
+void
+lp_set_store_alignment(LLVMValueRef Inst,
+		       unsigned Align);
 
 #endif /* !LP_BLD_INIT_H */
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp b/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
index 68f8808..6c4586c 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
+++ b/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
@@ -165,3 +165,18 @@ lp_build_load_volatile(LLVMBuilderRef B, LLVMValueRef PointerVal,
    return llvm::wrap(llvm::unwrap(B)->CreateLoad(llvm::unwrap(PointerVal), true, Name));
 }
 
+extern "C"
+void
+lp_set_load_alignment(LLVMValueRef Inst,
+                       unsigned Align)
+{
+   llvm::unwrap<llvm::LoadInst>(Inst)->setAlignment(Align);
+}
+
+extern "C"
+void
+lp_set_store_alignment(LLVMValueRef Inst,
+		       unsigned Align)
+{
+   llvm::unwrap<llvm::StoreInst>(Inst)->setAlignment(Align);
+}
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_struct.c b/src/gallium/auxiliary/gallivm/lp_bld_struct.c
index 0dc2f24..cc248d1 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_struct.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_struct.c
@@ -146,6 +146,25 @@ lp_build_pointer_get(LLVMBuilderRef builder,
 }
 
 
+LLVMValueRef
+lp_build_pointer_get_unaligned(LLVMBuilderRef builder,
+                               LLVMValueRef ptr,
+                               LLVMValueRef index,
+                               unsigned alignment)
+{
+   LLVMValueRef element_ptr;
+   LLVMValueRef res;
+   assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind);
+   element_ptr = LLVMBuildGEP(builder, ptr, &index, 1, "");
+   res = LLVMBuildLoad(builder, element_ptr, "");
+   lp_set_load_alignment(res, alignment);
+#ifdef DEBUG
+   lp_build_name(res, "%s[%s]", LLVMGetValueName(ptr), LLVMGetValueName(index));
+#endif
+   return res;
+}
+
+
 void
 lp_build_pointer_set(LLVMBuilderRef builder,
                      LLVMValueRef ptr,
@@ -156,3 +175,18 @@ lp_build_pointer_set(LLVMBuilderRef builder,
    element_ptr = LLVMBuildGEP(builder, ptr, &index, 1, "");
    LLVMBuildStore(builder, value, element_ptr);
 }
+
+
+void
+lp_build_pointer_set_unaligned(LLVMBuilderRef builder,
+                               LLVMValueRef ptr,
+                               LLVMValueRef index,
+                               LLVMValueRef value,
+                               unsigned alignment)
+{
+   LLVMValueRef element_ptr;
+   LLVMValueRef instr;
+   element_ptr = LLVMBuildGEP(builder, ptr, &index, 1, "");
+   instr = LLVMBuildStore(builder, value, element_ptr);
+   lp_set_store_alignment(instr, alignment);
+}
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_struct.h b/src/gallium/auxiliary/gallivm/lp_bld_struct.h
index 11605c6..6b7b4f2 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_struct.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_struct.h
@@ -105,6 +105,18 @@ lp_build_pointer_get(LLVMBuilderRef builder,
                    LLVMValueRef index);
 
 /**
+ * Get the value of an array element, with explicit alignment.
+ *
+ * If the element size is different from the alignment this will
+ * cause llvm to emit an unaligned load
+ */
+LLVMValueRef
+lp_build_pointer_get_unaligned(LLVMBuilderRef builder,
+                               LLVMValueRef ptr,
+                               LLVMValueRef index,
+                               unsigned alignment);
+
+/**
  * Set the value of an array element.
  */
 void
@@ -113,4 +125,17 @@ lp_build_pointer_set(LLVMBuilderRef builder,
                      LLVMValueRef index,
                      LLVMValueRef value);
 
+/**
+ * Set the value of an array element, with explicit alignment.
+ *
+ * If the element size is different from the alignment this will
+ * cause llvm to emit an unaligned store
+ */
+void
+lp_build_pointer_set_unaligned(LLVMBuilderRef builder,
+                               LLVMValueRef ptr,
+                               LLVMValueRef index,
+                               LLVMValueRef value,
+                               unsigned alignment);
+
 #endif /* !LP_BLD_STRUCT_H */




More information about the mesa-commit mailing list