gallivm: added aligned pointer get/set
authorJames Benton <jbenton@vmware.com>
Thu, 19 Apr 2012 12:13:17 +0000 (13:13 +0100)
committerJosé Fonseca <jfonseca@vmware.com>
Wed, 2 May 2012 09:12:48 +0000 (10:12 +0100)
src/gallium/auxiliary/gallivm/lp_bld_init.h
src/gallium/auxiliary/gallivm/lp_bld_misc.cpp
src/gallium/auxiliary/gallivm/lp_bld_struct.c
src/gallium/auxiliary/gallivm/lp_bld_struct.h

index f68bf75a8515df54506f97430b8ff914c84bacb1..5fc0f996c646357c04a163aba0b1178cafb4bd49 100644 (file)
@@ -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 */
index 68f8808f3effae419e6d18102bc9259350282f29..6c4586c421244414d0d9b0bf2c10dd480d99157e 100644 (file)
@@ -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);
+}
index 0dc2f24d10a2eb0695ede785e6a77de495f21450..cc248d15e97f362d50adbf1166bf226c062efd99 100644 (file)
@@ -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);
+}
index 11605c685f09d5b50b5a77879014ee72dc2f837f..6b7b4f2a6bf7d6949b0f001da9412fec27025ed0 100644 (file)
@@ -104,6 +104,18 @@ lp_build_pointer_get(LLVMBuilderRef builder,
                    LLVMValueRef ptr,
                    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.
  */
@@ -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 */