refactor(ir): extract LoweringBuilder from lower_composite_ops_pass (plan 70, 1/3) - #2792
georgebisbas wants to merge 1 commit into
Conversation
lower_composite_ops_pass.cpp has grown to 2845 lines and carries every composite collective lowering rule in one translation unit, so each new collective lands hundreds of lines in the same file and any edit risks every other rule. Plan 70 pays this down by splitting per-collective translation units without touching pass order (the reorder alternative was rejected in hw-native-sys#1850). This is phase 1: move the shared LoweringBuilder scratchpad, its CommSetup result struct and the MakeNegation helper into a lower_composite/ module so the per-collective rules extracted next have a shared home to depend on. Pure code motion — the rules still resolve LoweringBuilder and CommSetup through using declarations, so no call site changes and no IR output changes. Mirrors public issue hw-native-sys#2632, which proposes the same split.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (4)
Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review. 📝 WalkthroughWalkthroughThe PR extracts ChangesComposite lowering builder
Priority: ⬇️ Low Estimated code review effort: 4 (Complex) | ~45 minutes Change: Refactor Sequence Diagram(s)sequenceDiagram
participant lower_composite_ops_pass
participant LoweringBuilder
participant IR_statement_buffer
lower_composite_ops_pass->>LoweringBuilder: construct lowering operations
LoweringBuilder->>IR_statement_buffer: append IR statements
lower_composite_ops_pass->>LoweringBuilder: TakeStmts()
LoweringBuilder-->>lower_composite_ops_pass: return buffered statements
Merge Risk: ⚪ Minimal · up to The extraction is integrated into the native build with no supported behavior regression identified, so it is ready to merge after normal checks. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 11.76% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 34 functions across 3 files. (1 skipped: 1 unsupported.)
Warning Git: CodeRabbit could not clone the repository, so clone-backed analysis was skipped and this review may be incomplete. Verify repository clone access, such as SSH credentials, before requesting another full review. If clone access is intentionally unavailable, use Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. A rabbit builds with careful paws Comment |
Phase 1 of 3 for plan 70 — splitting
lower_composite_ops_pass.cppinto per-collectivetranslation units. Mirrors public issue #2632, which proposes the same split.
Why
lower_composite_ops_pass.cpphad grown to 2845 lines holding every composite collectivelowering rule in one translation unit. 13 commits touched it in the last 60 days, so each new
collective lands hundreds of lines in the same file and any edit risks every other rule.
Plan 36 proposed reordering the pipeline instead; that was rejected in #1850. This is the
structural split without a reorder.
What this PR does
Moves the shared
LoweringBuilderscratchpad, itsCommSetupresult struct and theMakeNegationhelper into a newsrc/ir/transforms/lower_composite/module, so theper-collective rules extracted in the follow-ups have a shared home to depend on.
Pure code motion — the rules still resolve
LoweringBuilderandCommSetupthroughusingdeclarations, so there are no call-site changes and no IR output changes.
lower_composite_ops_pass.cpp: 2845 → 2356 lines.Stack
This is the first of three; they must land in order.
refactor/split-lower-composite-opsLoweringBuilderextractrefactor/split-lower-composite-ops-pr2refactor/split-lower-composite-ops-pr3End state: the pass file drops to 626 lines — dispatch table, mutator and
Pass()factory,plus the elementwise
tile.sin/tile.cosand MXtile.tquant_mxrules, which share no codewith the collectives and are out of scope here (see #2632, which documents all three domains).
Verification
Sim Docker (
pypto3-hw-native-sys:sim), mounted worktree +pip install --no-build-isolation,build parallelism capped:
clang-tidy(tests/lint/clang_tidy.py --diff-base origin/main) cleanpre-commitcleanEach phase of the stack was verified independently, not just the tip.
Not covered here
Distributed ST on NPU (
tests/st/distributed/, sim P=2/P=4) has not been run — that needshardware via
task-submit.