Skip to content

Layouts for targets whose data layout differs from Julia's - #21

Draft
vchuravy wants to merge 1 commit into
vc/jc-19-jitfrom
vc/jc-20-target-layouts
Draft

vchuravy wants to merge 1 commit into
vc/jc-19-jitfrom
vc/jc-20-target-layouts

Conversation

@vchuravy

Copy link
Copy Markdown
Contributor

Stacked on #20. GPUCompiler's corpus for codegen=:juliacodegen found this gap.

Julia lays out structs with the host's alignments, e.g. Int128 aligned to 16 bytes. A target whose data layout doesn't specify i128 aligns it to 8 (SPIR-V, Metal, BPF). There, { float, i128 } has 24 bytes while the Julia struct has 32, and the layout check rejected the struct with Unsupported.

When the LLVM struct's size or field offsets differ from Julia's, the layout is now a packed struct with the fields at Julia's offsets and byte arrays as padding, e.g. <{ float, [12 x i8], i128 }>. The field indices skip the padding, and constants zero it. Host layouts are unchanged.

Native code keeps { float, i128 } there and addresses fields by byte offset, which means it copies 32 bytes into a 24-byte alloca.

Tests (test/repr.jl):

  • the padded layout on SPIR-V, alone and nested;
  • the host layout is unchanged;
  • a SPIR-V module using such values (test_module_ir now takes a datalayout).

The full suite passes locally on 1.12 and nightly.

🤖 Generated with Claude Code

Julia lays out structs with the host's alignments, e.g. `Int128` aligned to
16 bytes. A target whose data layout doesn't say otherwise aligns `i128` to
8 (SPIR-V, Metal, BPF), so `{ float, i128 }` has 24 bytes there, where the
Julia struct has 32, and the layout check rejected such structs.

Such a struct is now a packed struct with the fields at Julia's offsets
and byte arrays as padding (`<{ float, [12 x i8], i128 }>`). The field
indices skip the padding, and constants zero it.

Found by GPUCompiler's corpus for `codegen=:juliacodegen`. Native code uses
`{ float, i128 }` there and addresses the fields by byte offset, copying 32
bytes into a 24-byte alloca. `test_module_ir` takes a `datalayout` for
targets whose back end LLVM lacks.

Assisted-by: Claude Code (Opus 5.5)
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