Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch LLVM codegen of Ptr{T} to an actual pointer type. (#53687)
This PR switches our code generation for `Ptr{T}` from `i64` to an actual LLVM pointer type (`ptr` when using opaque pointers, an untyped `i8*` otherwise). The main motivation is to simplify `llvmcall` usage (doing away with the `inttoptr`/`ptrtoint` conversions), and also make it possible to simply use `ccall` to call intrinsics with `Ptr`-valued arguments (where we currently always need `llvmcall` for converting to an actual pointer). Changing codegen like this is a breaking change for `llvmcall` users, but I've added backwards compatibility and a deprecation warning. Before: ```llvm julia> @code_llvm pointer([]) define i64 @julia_pointer_1542(ptr noundef nonnull align 8 dereferenceable(24) %"x::Array") #0 { top: ; ┌ @ pointer.jl:65 within `cconvert` %0 = load ptr, ptr %"x::Array", align 8 ; └ ; ┌ @ pointer.jl:90 within `unsafe_convert` ; │┌ @ pointer.jl:30 within `convert` %bitcast_coercion = ptrtoint ptr %0 to i64 ret i64 %bitcast_coercion ; └└ } ``` After: ```llvm julia> @code_llvm pointer([]) define ptr @julia_pointer_3880(ptr noundef nonnull align 8 dereferenceable(24) %"x::Array") #0 { top: ; ┌ @ pointer.jl:65 within `cconvert` %0 = load ptr, ptr %"x::Array", align 8 ; └ ; ┌ @ pointer.jl:90 within `unsafe_convert` ; │┌ @ pointer.jl:30 within `convert` ret ptr %0 ; └└ } ``` This also simplifies "real code", e.g., when `ccall` converts an Array to a pointer, resulting in some more optimization opportunities.
- Loading branch information