Skip to content

Proposal: refactor dialect-llvm export.rs into fundamental building blocks #59

Closed

Description

@fbrv

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

Activity

  1. nihalpasham commented on May 15, 2026

    @nihalpasham
    Collaborator

    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.
  2. added
    enhancement
    llvm-export
    on May 15, 2026
  3. added a commit that references this issue on Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementllvm-export

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions