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
.devcontainer
.github
base
cli
contrib
deps
doc
etc
src
stdlib
test
.buildkite-external-version -rw-r--r-- 5 bytes
.clang-format -rw-r--r-- 3.3 KB
.clangd -rw-r--r-- 114 bytes
.codecov.yml -rw-r--r-- 52 bytes
.git-blame-ignore-revs -rw-r--r-- 371 bytes
.gitattributes -rw-r--r-- 65 bytes
.gitignore -rw-r--r-- 571 bytes
.mailmap -rw-r--r-- 12.7 KB
CITATION.bib -rw-r--r-- 513 bytes
CITATION.cff -rw-r--r-- 1012 bytes
CONTRIBUTING.md -rw-r--r-- 23.4 KB
HISTORY.md -rw-r--r-- 388.1 KB
LICENSE.md -rw-r--r-- 1.3 KB
Make.inc -rw-r--r-- 56.0 KB
Makefile -rw-r--r-- 30.3 KB
NEWS.md -rw-r--r-- 4.4 KB
README.md -rw-r--r-- 7.4 KB
THIRDPARTY.md -rw-r--r-- 3.9 KB
VERSION -rw-r--r-- 11 bytes
julia.spdx.json -rw-r--r-- 37.8 KB
pkgimage.mk -rw-r--r-- 1.4 KB
sysimage.mk -rw-r--r-- 4.2 KB
typos.toml -rw-r--r-- 78 bytes

README.md

back to top