Commit 09400e4
authored
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.1 parent 8e8b533 commit 09400e4
File tree
12 files changed
+253
-97
lines changed- base
- compiler
- src
12 files changed
+253
-97
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
29 | 34 | | |
30 | 35 | | |
31 | 36 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
364 | 364 | | |
365 | 365 | | |
366 | 366 | | |
367 | | - | |
| 367 | + | |
368 | 368 | | |
369 | 369 | | |
370 | 370 | | |
371 | 371 | | |
372 | 372 | | |
373 | | - | |
| 373 | + | |
374 | 374 | | |
375 | 375 | | |
376 | 376 | | |
| |||
379 | 379 | | |
380 | 380 | | |
381 | 381 | | |
382 | | - | |
| 382 | + | |
383 | 383 | | |
384 | 384 | | |
385 | 385 | | |
| |||
388 | 388 | | |
389 | 389 | | |
390 | 390 | | |
391 | | - | |
| 391 | + | |
392 | 392 | | |
393 | 393 | | |
394 | 394 | | |
| |||
411 | 411 | | |
412 | 412 | | |
413 | 413 | | |
414 | | - | |
| 414 | + | |
415 | 415 | | |
416 | 416 | | |
417 | 417 | | |
418 | 418 | | |
419 | 419 | | |
420 | 420 | | |
421 | 421 | | |
422 | | - | |
| 422 | + | |
423 | 423 | | |
424 | 424 | | |
425 | 425 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
184 | 184 | | |
185 | 185 | | |
186 | 186 | | |
187 | | - | |
188 | | - | |
189 | 187 | | |
190 | 188 | | |
191 | 189 | | |
| |||
662 | 660 | | |
663 | 661 | | |
664 | 662 | | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
665 | 666 | | |
666 | 667 | | |
667 | 668 | | |
| |||
705 | 706 | | |
706 | 707 | | |
707 | 708 | | |
| 709 | + | |
| 710 | + | |
708 | 711 | | |
709 | 712 | | |
710 | 713 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
313 | 313 | | |
314 | 314 | | |
315 | 315 | | |
316 | | - | |
317 | | - | |
| 316 | + | |
| 317 | + | |
318 | 318 | | |
319 | 319 | | |
320 | 320 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
154 | 154 | | |
155 | 155 | | |
156 | 156 | | |
157 | | - | |
158 | | - | |
| 157 | + | |
159 | 158 | | |
160 | 159 | | |
161 | 160 | | |
| |||
0 commit comments