gallivm/struct: add opaque ptr friendly pointer accessors.

These just add explicit types.

Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Mihai Preda <mhpreda@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18876>
This commit is contained in:
Dave Airlie 2022-09-26 13:47:15 +10:00 committed by Marge Bot
parent b61b1d5a4c
commit b36160689f
2 changed files with 53 additions and 0 deletions

View file

@ -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,

View file

@ -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.
*/