Skip to content

Metal: Split pointer conversion from IPO AS inference pass#827

Merged
maleadt merged 3 commits into
mainfrom
tb/split
Jun 3, 2026
Merged

Metal: Split pointer conversion from IPO AS inference pass#827
maleadt merged 3 commits into
mainfrom
tb/split

Conversation

@maleadt

@maleadt maleadt commented Jun 3, 2026

Copy link
Copy Markdown
Member

Also create a shared helper for a common rewriting operation.

maleadt and others added 2 commits June 3, 2026 10:41
The interprocedural address-space narrowing folded two concerns: undoing
Julia's pre-JuliaLang/julia#53687 lowering of `Ptr` arguments to integers
(the typed-pointer shim), and narrowing generic pointer parameters to a
specific space. Split them. Phase 1 (`convert_intptr_args!`, gated on
`VERSION < v"1.12.0-DEV.225"`) turns integer-image `Ptr` parameters back into
generic pointers, so Phase 2 narrows pointers with no integer-specific
handling -- the same code path for typed and opaque pointers. The shim is now
isolated, and deletable in one go once 1.12 is the minimum.

The gate is the Julia version rather than `supports_typed_pointers`, because
"`Ptr` lowered to an integer" and "LLVM uses typed pointers" are separate
switches: they agree on releases, but opaque pointers could be enabled while
`Ptr` is still passed as an integer.

Both phases share a `rewrite_parameters!` engine (clone the signature, rewrite
the call sites, per-parameter policy via closures). Also prune the dead self-
`bitcast` that `clone_into!` leaves on the new function, which the re-
processing across phases would otherwise trip over.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Changing a function's signature is the same dance everywhere -- create a new
function, reconstruct each changed argument on entry so the body is unchanged,
clone the body over, then erase the old function -- but it was open-coded in
every backend's argument-rewriting pass, each re-deriving the same workaround
for `clone_into!` dropping attributes on retargeted parameters.

Factor the mechanical part into `clone_with_converted_args!` and
`replace_function!` (utils.jl) and use them from the four passes whose
parameters map 1:1: Metal's address-space narrowing, the GCN byref-to-constant
and SPIR-V byval-to-pointer kernel-argument lowerings, and the
kernel-state-to-reference pass in irgen. The parts that genuinely differ --
which parameters change, how each is reconstructed, attribute handling, and
(only Metal's pass) rewriting call sites -- stay in the callers.

Left open-coded: `pass_by_reference!` (can drop ghost arguments, so parameters
aren't 1:1) and the two byval/byref passes that reattach attributes inside the
conversion loop, where the timing is entangled with `clone_into!`.

Net ~110 fewer lines; codegen tests pass for all backends on typed-pointer
(1.11) and opaque-pointer (1.12) builds.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@maleadt maleadt merged commit f42d1cf into main Jun 3, 2026
36 of 37 checks passed
@maleadt maleadt deleted the tb/split branch June 3, 2026 12:48
@codecov

codecov Bot commented Jun 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.19728% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.27%. Comparing base (8bd3aa7) to head (6da1ee6).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/metal.jl 93.87% 6 Missing ⚠️
src/irgen.jl 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #827      +/-   ##
==========================================
+ Coverage   79.04%   79.27%   +0.22%     
==========================================
  Files          25       25              
  Lines        4587     4516      -71     
==========================================
- Hits         3626     3580      -46     
+ Misses        961      936      -25     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant