diff --git a/src/gallium/auxiliary/gallivm/lp_bld_struct.c b/src/gallium/auxiliary/gallivm/lp_bld_struct.c index 408ac17e246..73c32cebadf 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_struct.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_struct.c @@ -234,6 +234,35 @@ lp_build_pointer_get_unaligned(LLVMBuilderRef builder, return res; } +LLVMValueRef +lp_build_pointer_get_unaligned2(LLVMBuilderRef builder, + LLVMTypeRef ptr_type, + LLVMValueRef ptr, + LLVMValueRef index, + unsigned alignment) +{ + LLVMValueRef element_ptr; + LLVMValueRef res; + assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind); + element_ptr = LLVMBuildGEP2(builder, ptr_type, ptr, &index, 1, ""); + res = LLVMBuildLoad2(builder, ptr_type, element_ptr, ""); + if (alignment) + LLVMSetAlignment(res, alignment); +#ifdef DEBUG + lp_build_name(res, "%s[%s]", LLVMGetValueName(ptr), LLVMGetValueName(index)); +#endif + return res; +} + + +LLVMValueRef +lp_build_pointer_get2(LLVMBuilderRef builder, + LLVMTypeRef ptr_type, + LLVMValueRef ptr, + LLVMValueRef index) +{ + return lp_build_pointer_get_unaligned2(builder, ptr_type, ptr, index, 0); +} void lp_build_pointer_set(LLVMBuilderRef builder, diff --git a/src/gallium/auxiliary/gallivm/lp_bld_struct.h b/src/gallium/auxiliary/gallivm/lp_bld_struct.h index d90bdf48d32..52d6020563b 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_struct.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_struct.h @@ -152,6 +152,30 @@ lp_build_pointer_get_unaligned(LLVMBuilderRef builder, LLVMValueRef index, unsigned alignment); +/** + * Get the value of an array element. + * This takes the explicit LLVM type of ptr, as required by LLVM-15 opaque-pointers. + */ +LLVMValueRef +lp_build_pointer_get2(LLVMBuilderRef builder, + LLVMTypeRef ptr_type, + LLVMValueRef ptr, + LLVMValueRef index); + +/** + * Get the value of an array element, with explicit alignment, and explicit type, + * This takes the explicit LLVM type of ptr, as required by LLVM-15 opaque-pointers. + * + * If the element size is different from the alignment this will + * cause llvm to emit an unaligned load + */ +LLVMValueRef +lp_build_pointer_get_unaligned2(LLVMBuilderRef builder, + LLVMTypeRef ptr_type, + LLVMValueRef ptr, + LLVMValueRef index, + unsigned alignment); + /** * Set the value of an array element. */