Skip to content

Use Julia dialect internally - #62938

Draft
vchuravy wants to merge 6 commits into
vc/llvm-dialects-tablegenfrom
vc/llvm-dialects-internal-usage
Draft

Use Julia dialect internally#62938
vchuravy wants to merge 6 commits into
vc/llvm-dialects-tablegenfrom
vc/llvm-dialects-internal-usage

Conversation

@vchuravy

Copy link
Copy Markdown
Member

Mechanical replacement and using the Julia dialect introduced up the stack.

Assisted-by: Claude


Stack created with GitHub Stacks CLIGive Feedback 💬

@vchuravy
vchuravy force-pushed the vc/llvm-dialects-internal-usage branch from 0f035e7 to 28bf4ec Compare August 31, 2026 15:08
Comment thread src/cgutils.cpp Outdated
Comment thread src/codegen.cpp
Comment thread src/llvm-alloc-opt.cpp Outdated
@@ -349,7 +349,7 @@ bool Optimizer::isSafepoint(Instruction *inst)
if (auto callee = call->getCalledFunction()) {
// Known functions emitted in codegen that are not safepoints
if (callee == pass.pointer_from_objref_func

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.

This should also be a dialect op

Comment thread src/llvm-cancellation-lowering.cpp Outdated
Comment thread src/llvm-pass-helpers.cpp Outdated
@vchuravy
vchuravy force-pushed the vc/llvm-dialects-internal-usage branch 2 times, most recently from 7cce10a to b605614 Compare August 31, 2026 17:52
@vchuravy
vchuravy force-pushed the vc/llvm-dialects-internal-usage branch from b605614 to 3b5aa5c Compare August 31, 2026 18:17
@vchuravy
vchuravy force-pushed the vc/llvm-dialects-internal-usage branch from 3b5aa5c to 0044949 Compare August 31, 2026 18:48
vchuravy and others added 6 commits August 31, 2026 21:08
Codegen builds the pseudo-intrinsics via llvm_dialects::Builder::create<Op>
and the passes recognize them with isa<Op>(call) instead of string or
function pointer comparisons.

The llvm_dialects::DialectContext required for op construction is owned by
jl_codegen_output_t, giving it exactly the lifetime of the module emission
state and keeping it inside the invalidation contract of llvm-dialects'
per-thread context cache.

The AddressSpace enum moves into the julia namespace next to the dialect;
the GC-rooting static analysis treats the julia and llvm_dialects
namespaces as safepoint-free, like the llvm namespace.

llvmcalltest.cpp includes llvm-codegen-shared.h and with it JuliaDialect.h,
so the test library depends on the tblgen-generated headers.

Assisted-by: Claude Code (Fable 5)
Claude-Session: https://claude.ai/code/session_013iurq91jyFwfKN8EbrcjL2
Switch codegen to building 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 via llvm_dialects::Builder. The handwritten
JuliaFunction declarations are removed; emit_jlcall selects the
trampoline with an enum instead of JuliaFunction pointers.

The GC invariant verifier recognizes the variadic ops (write_barrier,
the call family) via the generated op classes and skips their fixed
leading arguments by op kind rather than by declared parameter count.

Assisted-by: Claude Code (Fable 5)
Claude-Session: https://claude.ai/code/session_013iurq91jyFwfKN8EbrcjL2
Replace the single-owner llvm_dialects::DialectContext in
jl_codegen_output_t with julia::ScopedDialects, an RAII attachment backed
by a per-context refcounted registry. This lets the emission state and
the optimization passes attach the dialect to the same LLVMContext
independently; the last detachment destroys the underlying DialectContext
and erases the registry entry, so a reused context address starts clean.

Assisted-by: Claude Code (Fable 5)
Claude-Session: https://claude.ai/code/session_01C5vc8DuxsFWuP2UZGN4CCe
LateLowerGCFrame now creates julia.new_gc_frame, julia.push_gc_frame,
julia.get_gc_frame_slot, and julia.pop_gc_frame via
llvm_dialects::Builder, as do the queue_gc_root slow path in stock final
GC lowering and the julia.safepoint emission shared by the passes. The
GC lowering passes attach the dialect with a ScopedDialects for the
duration of their run.

julia.gc_alloc_bytes keeps its runtime-typed declaration: its size
parameter type is target dependent and the allocsize attribute requires
a non-varargs declaration, neither of which llvm-dialects can express
yet.

Assisted-by: Claude Code (Fable 5)
Add a JuliaDialectsVerifier module pass wrapping llvm_dialects::verify
and run it with the other verification passes (FORCE_ASSERTIONS builds),
so ill-formed uses of Julia dialect ops are caught at the pipeline
boundary. The pass is also registered for opt-based testing.

Assisted-by: Claude Code (Fable 5)
Convert the last two pseudo-intrinsics outside the dialect: codegen
emits `llvm.julia.gc_preserve_begin`/`_end` through the generated
builders, the passes recognize them with isa<julia::GCPreserveBegin/
GCPreserveEnd>, and AllocOpt recreates shrunken preserve regions through
the dialect builder (attaching the dialect for the duration of the
pass). The gc_preserve_begin_func/gc_preserve_end_func fields of
JuliaPassContext and their add_named_global registrations are retired;
only jl_pop_handler_noexcept, a plain runtime function, remains.

Assisted-by: Claude Code (Fable 5)
Claude-Session: https://claude.ai/code/session_01C5vc8DuxsFWuP2UZGN4CCe
@vchuravy
vchuravy force-pushed the vc/llvm-dialects-internal-usage branch from 0044949 to efa5083 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