Repository navigation
Conversation
…uded Device code only reached LLVM with `alwaysinline`: `#[inline]` hints were dropped and `#[inline(never)]` became an ordinary function that `opt` was free to inline. Code that relies on a call boundary (to keep a helper's floating-point contraction identical across call sites, or to bound code size in a hot loop) could not express it. `InlineIntent` (`MirFuncOp::inline_intent`) records the Rust attribute on the imported function and the lowering maps it to LLVM function attributes: `#[inline]` -> `inlinehint`, `#[inline(always)]` -> `alwaysinline`, `#[inline(never)]` -> `noinline`, rendered through `llvm_func_attrs` like any other function attribute. The MirFuncOp verifier rejects an unknown keyword and any intent on a kernel entry (a `.entry` is never called, so an inline keyword on it has no meaning); a new test covers both rules. No inliner pass is added: `opt` honours the keywords. One `#[inline(never)]` is not carried: the one `#[device]` puts on the prefixed function of a device function with its own type or const parameters, so each monomorphization stays a separate item for the collector. It is a host-side boundary; as `noinline` it would keep every call and stop const-generic arguments from folding into their callers (the `const_generic` example checks that they fold). The macro's attribute comes first, so rustc keeps it and reports an inline attribute the user adds there as unused; on such functions a user's own inline attribute did not reach device code before this change and does not now. The match uses `opt_item_name`, so closures, which may carry `#[inline(never)]`, are handled like any other function. Signed-off-by: Alex Khal <joss13@gmail.com> Signed-off-by: ssoj13 <96214515+ssoj13@users.noreply.github.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Carry Rust's device-function inline intent through MIR into LLVM:
#[inline]becomesinlinehint,#[inline(always)]becomesalwaysinline, and#[inline(never)]becomesnoinline. Previously onlyalwaysinlinesurvived. The verifier rejects malformed intent and intent on kernel entries.Port of ansidium/cuda-rust-windows#11, independently adapted to NVIDIA main
bc46b1ffb. It preserves the recently added kernel reference-validity attributes and usesrustc_attr_ir::InlineAttr, the type in the pinned nightly-2026-10-11. Related: #188 and #189.The generic
#[device]collector boundary remains a deliberate exception: its macro-injectednoinlineis a host collection requirement and must not block device const-generic folding. This does not resolve user inline attributes being shadowed by that macro on generic functions (#1471).Verified on pinned nightly-2026-10-11, Linux/WSL2, CUDA 13.3 and RTX 3080 Ti:
-D warningspass for dialect-mir, llvm-export, mir-importer, mir-lower, mir-transforms and reserved-oxide-symbols.const_generic --arch sm_86(distinct VALUE=4/8 results) andaddressof_sharedarray --arch sm_86(pointer/device-call round trips and raw receiver checks pass).The original change was authored by Alex Khal with Claude Code. This adaptation and current verification were prepared with Codex; original attribution and DCO are preserved.