Skip to content

fbrv:refactor export dialect llvm - #70

Merged
nihalpasham merged 4 commits into
NVIDIA:mainfrom
fbrv:fbrv/refactor-export-dialect-llvm
May 24, 2026
Merged

nihalpasham merged 4 commits into
NVIDIA:mainfrom
fbrv:fbrv/refactor-export-dialect-llvm

Conversation

@fbrv

@fbrv fbrv commented May 20, 2026

Copy link
Copy Markdown
Contributor

Closes #59.
Splits crates/dialect-llvm/src/export.rs into a module tree (config, externs, state, names, module, function, ops, types, literals, metadata) with no semantic changes and no new abstraction layers.

ops.rs replaces the op_id == X::get_opid_static() chain with a typed LlvmOp<'op> enum dispatched via TryFrom<&dyn Op>, populated by the classify_op! macro. Adding an op requires one macro entry and one match arm.

fbrv and others added 4 commits May 20, 2026 04:53
Migrate the five `op_id == X::get_opid_static()` sites in the value-name
and predecessor-map pre-passes to use `downcast_ref::<X>()` directly.
This is the same primitive the `classify_op!` macro in ops.rs uses, so
the dispatch idiom is now consistent across the export module. Removes
the now-redundant `Operation::get_op::<X>().unwrap()` downcasts since
`downcast_ref` already returns the typed reference.

Also add a maintenance-contract doc comment to the `LlvmOp` enum
spelling out the four places that need touching when adding a new op,
and replace the bare `#[allow(dead_code)]` on the `Unreachable` variant
with a doc comment explaining the symmetry rationale.

Pure refactor: byte-identical .ll output across all 51 example kernels
before and after.
@nihalpasham
nihalpasham self-requested a review May 24, 2026 10:44
@nihalpasham nihalpasham added QoL-improvement Quality-of-life improvement; not a correctness fix refactor Internal restructuring with no behavior change labels May 24, 2026

@nihalpasham nihalpasham left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good. The split reads cleanly and LlvmOp + classify_op! is a tidy replacement for the long op_id chain.

I layered a small commit on top (c4f9803) that brings the value-name and predecessor-map pre-passes in function.rs into the same idiom: swapping the five op_id == X::get_opid_static() sites to downcast_ref::<X>(), the same primitive your macro uses internally.

Also added a maintenance-contract docstring on LlvmOp so future contributors know which four places to touch when adding an op.

Ps: Just to be sure, also smoketested this - to check .ll parity holds against main after normalizing for monomorphization ordering artifacts and it does.

@nihalpasham
nihalpasham merged commit 76a1d88 into NVIDIA:main May 24, 2026
meefs pushed a commit to meefs/cuda-oxide that referenced this pull request Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

QoL-improvement Quality-of-life improvement; not a correctness fix refactor Internal restructuring with no behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants