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 */
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);
+}
}
+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,
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);
+}
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.
*/
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 */