Repository navigation
feat(codegen): forward compiler-owned multi-result bundles - #888
Conversation
…rding A struct-wrapped bundle (e.g. the CuSimd wrapper the importer emits for multi-result intrinsics) read back in one piece via a field-addr plus a whole-array load resolves the replacement to one of the bundle's own construct ops. Forwarding that load and then erasing the bundle nodes left live uses of an erased operation, which panics in pliron's Operation::erase. Reject such replacements in analyze_projection so the plan falls back to the memory path. Also widen the pass unit fixture to a parameterized result width and add a positive 64-result forwarding test plus a 64-output ptx_asm! accept test (the trybuild suite only covered rejection at 65).
|
Gist: good pass, and it earns its keep: compiler-owned multi-result bundles stay in registers instead of bouncing through What I checked and did:
Also confirmed #399 stays open: that issue wants ordinary iterator-chain arrays in SSA, which this pass rules out by design. Update, measured evidence (pass on vs off, same commit): under the default pipeline the final PTX is byte-identical for tcgen05_matmul, gemm_sol, tcgen05, and vecadd; downstream |
|
Gist of the decision: taking this, and I want to be precise about why, since I measured it. Under the default pipeline this pass changes nothing today: final PTX is byte-identical with it on or off, because What I'm taking it for:
So: accepted for self-sufficiency and the escape hatch, with eyes open that default-pipeline PTX is unchanged today. If the pipeline ever routes around LLVM's optimizer, this pass is already sitting where it needs to be. |
…alves #965 missed (#972) #965 corrected this README's type and operation tables. It left the other two inventories on the same page, and both are stale in the same way -- one of them now contradicting the tables #965 just fixed. **Attributes: "four" -> seven.** `src/attributes.rs` has seven `#[pliron_attr(...)]` declarations; the table lists four. The three missing ones are all recent, and two pair directly with ops the README already lists: mir.fp16_attr MirFP16Attr `f16` constant values, paired with MirFP16Type mir.unroll UnrollAttr the factor carried by `mir.unroll_hint` mir.compiler_result_bundle CompilerResultBundleAttr the multi-result return ABI marker from #888 `mir.unroll` is the clearest case: #965 added `mir.unroll_hint` to the operations table, and the attribute that op exists to carry was three rows below, undocumented. **Source Layout tree.** It contradicts the page above it: types.rs "# 7 MIR types" -- the Types table now says nine attributes.rs "# 4 ... attributes" -- see above ops/ no `debug.rs` -- the Operations table now lists it src/ no `const_fold.rs`, `rust_intrinsics.rs`, `side_effects.rs` So a reader who trusted the tree came away with different numbers than a reader who trusted the tables, on one page. Three module comments were also narrower than their files (`control_flow` also carries unroll hints, `memory` also `memcpy`/`memmove`, `aggregate` also slices) -- all ops #965 added to the table without the tree following. Both inventories now state the rule that makes them checkable, as the operations table does: one row per `#[pliron_attr(...)]`, one tree entry per file. Verified by script against the tree: the attributes table matches all seven `(name, Rust type)` pairs exactly -- `MirCastKindAttr` is a `pub enum`, the rest are `pub struct` -- and the Source Layout tree matches `src/*.rs` plus `src/ops/*.rs` exactly, 19 files listed and 19 on disk, none missing and none invented. check-crate-inventory passes. Signed-off-by: Vyncint Ng <[email protected]>
Problem
tcgen05_ldreturning[u32; 32]) comes back from the importer as an aggregate bundle that gets spilled to stack memory, even though the compiler created it itself and knows it never escapes. Downstreamopt -O2cleans that up today, so the spill reaches final PTX only inCUDA_OXIDE_NO_OPT=1builds; the pass makes the compiler's own MIR output clean without leaning on LLVM to fix it:ptx_asm!capped outputs at 16, which is too small for tcgen05-scale loads.Fix
forward_compiler_result_bundles) runs before mem2reg and forwards each element read straight to the producing value, then deletes the bundle once every use is forwardedptx_asm!output arity from 16 to 64CuSimd::to_array()pattern) used to make the pass erase one of its own construct ops while it still had uses, which pliron panics on; that case now bails out to the memory pathGotchas
Testing and validation
ptx_asm!accept test sits next to the existing 65-output reject test; full cuda-macros and trybuild suites green