https://github.com/JuliaLang/julia
Revision 09400e4f5c3e31ba528c2dbcf8e1ccef2a66ce3d authored by Tim Besard on 21 March 2024, 12:10:08 UTC, committed by GitHub on 21 March 2024, 12:10:08 UTC
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.
1 parent 8e8b533
History
Tip revision: 09400e4f5c3e31ba528c2dbcf8e1ccef2a66ce3d authored by Tim Besard on 21 March 2024, 12:10:08 UTC
Switch LLVM codegen of Ptr{T} to an actual pointer type. (#53687)
Tip revision: 09400e4
File Mode Size
Dockerfile -rw-r--r-- 140 bytes
devcontainer.json -rw-r--r-- 134 bytes

back to top