You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Proposal: refactor dialect-llvmexport.rs into fundamental building blocks #59
crates/dialect-llvm/src/export.rs is currently a large and difficult to navigate file. From a new contributor perspective, it appears to mix several responsibilities:
export/backend configuration
device extern declarations
module and metadata emission
exporter state and kernel bookkeeping
value naming and symbol normalization
type/literal formatting
function, block, and operation emission
lowering-adjacent logic, such as block argument to phi handling
This makes the file hard to understand, test and modify.
This issue proposes a conservative structural refactor: split export.rs into a small number of fundamental modules while preserving the generated LLVM IR output.
A possible first-step structure:
crates/dialect-llvm/src/export/
mod.rs // public API / high-level orchestration
config.rs // backend configuration
externs.rs // device extern declarations
state.rs // exporter state and kernel bookkeeping
names.rs // value names, block labels, symbol normalization
module.rs // module-level export flow
function.rs // function and basic block emission
ops.rs // operation emission
types.rs // LLVM type printing
literals.rs // constant/literal formatting
metadata.rs // nvvm annotations and version, llvm.used
Initial goals:
preserve current output exactly
reduce the size and scope of export.rs
make responsibilities clearer
avoid introducing a large abstraction layer
make future refactors easier to review
This should be a structural split rather than a semantic rewrite. Follow-ups can handle deeper changes, such as splitting operation emission by category or moving block argument to phi conversion out of the final textual printer.
CC: @nihalpasham
Thanks for the proposal. I think this would be a welcome addition.
I’d like the first step to be exactly the conservative split you’re proposing: modularize dialect-llvm export into clear building blocks while preserving the generated LLVM IR i.e. no semantic rewrite or new abstraction layer unless the split forces one.
This also sets up the next round of exporter work. Once module emission, metadata emission, names, type/literal printing, function/block emission, and op emission are separated, it becomes much easier to add richer metadata to the plain LLVM IR we currently produce in focused PRs.
Two follow-up areas I’d like us to keep in mind:
Performance metadata: parameter/function attributes such as readonly, nocapture, and noalias where they are actually sound. We need to be careful here because GPU kernel argument aliasing has Rust/LLVM semantic traps, especially around &mut and per-thread access.
Debug/tooling metadata: eventually we should have a place to emit DWARF/debug metadata and CUDA-relevant metadata so CUDA-GDB, NSYS, sanitizers, and related tooling have more useful information.
Activity
nihalpasham commentedon May 15, 2026
Thanks for the proposal. I think this would be a welcome addition.
I’d like the first step to be exactly the conservative split you’re proposing: modularize
dialect-llvmexport into clear building blocks while preserving the generated LLVM IR i.e. no semantic rewrite or new abstraction layer unless the split forces one.This also sets up the next round of exporter work. Once module emission, metadata emission, names, type/literal printing, function/block emission, and op emission are separated, it becomes much easier to add richer metadata to the plain LLVM IR we currently produce in focused PRs.
Two follow-up areas I’d like us to keep in mind:
readonly,nocapture, andnoaliaswhere they are actually sound. We need to be careful here because GPU kernel argument aliasing has Rust/LLVM semantic traps, especially around&mutand per-thread access.Refine cutile-macro error (NVIDIA#59)