Skip to content

Julia Dialect tablegen - #62937

Open
vchuravy wants to merge 4 commits into
vc/llvm-dialects-build-systemfrom
vc/llvm-dialects-tablegen
Open

Julia Dialect tablegen#62937
vchuravy wants to merge 4 commits into
vc/llvm-dialects-build-systemfrom
vc/llvm-dialects-tablegen

Conversation

@vchuravy

@vchuravy vchuravy commented Aug 31, 2026

Copy link
Copy Markdown
Member

This is the meat of the PR, specifying our pseudo-intrinsics as a tablegen file and formalizing attributes and so-forth.

Based on an old hand-written version of #52945 and then updated with Claude.

Assisted-by: Claude

TODO:

  • Intrinsics that return tokens
  • What should we do with the runtime functions (like jlnew)? They are functions we link against so we can't call them julia.x which is what llvm-dialects wants.

Stack created with GitHub Stacks CLIGive Feedback 💬

Comment thread src/JuliaDialect.td
let cppNamespace = "julia";
}

def JuliaValue : DialectType<JuliaDialect, "jlvalue"> {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gbaraldi this is already using the dialect type construct that we discussed today.

Comment thread src/JuliaDialect.td Outdated
Comment thread src/JuliaDialect.td
Comment on lines +361 to +372
def Safepoint : JuliaOp<"safepoint",
[Memory<[(readwrite ArgMem), (readwrite InaccessibleMem)]>,
NoUnwind]> {
let results = (outs);
let arguments = (ins Ptr:$signal_page);

let summary = "GC safepoint: potential stop-the-world synchronization point";
let description = [{
Loads from the GC signal page so that stopping the world can be triggered
by protecting it.
}];
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not technically a post GC lowering op, we can have it introduced much earlier

@vchuravy
vchuravy force-pushed the vc/llvm-dialects-tablegen branch 2 times, most recently from 05f20c9 to e3471e0 Compare August 31, 2026 18:17
@vchuravy
vchuravy force-pushed the vc/llvm-dialects-tablegen branch from e3471e0 to 0f974f9 Compare August 31, 2026 18:48
Specify the Julia-specific pseudo-intrinsics in src/JuliaDialect.td as
tblgen-generated op classes. The spec covers both dialect layers: the
codegen-level ops (julia.get_pgcstack, julia.get_pgcstack_or_new,
julia.gc_loaded) legal until LateLowerGCFrame, and the GC lowering ops
(julia.new_gc_frame etc.) produced by LateLowerGCFrame and consumed by
FinalLowerGC.

The generated declarations carry the same function names, types, and
attributes as the handwritten JuliaFunction definitions, so the emitted
IR is unchanged.

Assisted-by: Claude Code (Fable 5)
Claude-Session: https://claude.ai/code/session_013iurq91jyFwfKN8EbrcjL2
Add julia.typeof, julia.blackbox, julia.write_barrier,
julia.cancellation_point, julia.gcroot_flush, julia.pointer_from_objref,
the julia.call trampoline family, and julia.gc_alloc_obj to
JuliaDialect.td. Ops with variadic arguments (write_barrier, the call
family) declare a fully-varargs function type.

Not represented: llvm.julia.gc_preserve_begin/end (reserved llvm. prefix
and token result type, which llvm-dialects cannot express) and
jl_alloc_genericmemory_unchecked (a plain runtime call).

Assisted-by: Claude Code (Fable 5)
Claude-Session: https://claude.ai/code/session_013iurq91jyFwfKN8EbrcjL2
Use the AllocKind and AllocSize traits (GPUOpen-Drivers/llvm-dialects#145)
to carry the allockind("alloc") and allocsize(1) attributes of
julia.gc_alloc_obj and julia.gc_alloc_bytes in their dialect
specification instead of patching them in by hand. Since their size
argument type is target dependent (the datalayout's pointer-sized
integer), the ops are argument-overloaded and opt into
typedArgOverloadDeclaration so that their declarations keep fixed
parameters, which allocsize requires.

Assisted-by: Claude Code (Fable 5)
Claude-Session: https://claude.ai/code/session_01C5vc8DuxsFWuP2UZGN4CCe
Add GCPreserveBegin/GCPreserveEnd op definitions using llvm-dialects'
new useLlvmIntrinsicPrefix and TokenTy support: the ops keep their
existing `llvm.julia.gc_preserve_*` names (LLVM's IR verifier only
allows a token-returning function when it is an unknown intrinsic) and
their exact signatures, so the emitted IR is unchanged while the pair
gains generated op classes, builders and verifier coverage.

Assisted-by: Claude Code (Fable 5)
Claude-Session: https://claude.ai/code/session_01C5vc8DuxsFWuP2UZGN4CCe
@vchuravy
vchuravy force-pushed the vc/llvm-dialects-tablegen branch from 0f974f9 to e617902 Compare August 31, 2026 19:08
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