refactor(opt,common): move Cfg wrapper from opt to common - #21
Open
Boreas618 wants to merge 2 commits into
Open
Conversation
The asm backend imported opt::cfg::Cfg, a backwards dependency of the
backend on the middle-end opt layer. Cfg is a thin, generally useful
wrapper -- the CfgNode impl for IR BasicBlocks plus a {labels, graph}
bundle over common::graph -- and belongs in common next to the graph
utilities, so both opt (mem2reg) and asm (phi lowering) consume it
from below. common already documents (src/common/pass.rs) that the
crate-internal layer may reference ir types.
The code moves verbatim, now with dense rustdoc matching
common/graph.rs (the opt version had none): src/opt/cfg.rs becomes
src/common/cfg.rs, declared as pub mod cfg in common.rs. Consumers
update their import paths only (opt::mem2reg, asm::phi_lowering).
Also adds the missing //! module docs to opt/mem2reg.rs and
opt/dominator.rs.
Stacked on refactor/asm-backend-cleanup (touches phi_lowering.rs,
which that PR renamed types in). cargo test: 30/30 green.
- trimmed the 41-line compute_idom algorithm tutorial to present-tense WHY (RPO rationale, entry sentinel, unreachable blocks), keeping the Cooper-Harvey-Kennedy reference (§10.2, §8.2) - removed 2 restatements/narrations: Optimizer::generate doc echoing its 3-line body, AllocaAnalysis::from_blocks paragraph narrating its two calls (§2.2, §5.1) - rewrote 2 comments for precision: dropped the temporal '(now-optimised)' framing on Optimizer::output; replaced the vague 'current implementation only supports scalar integers' with the concrete reason (phi placement hardcodes Dtype::I32) (§3, §8.1) - documented intersect with the chain-walk mechanism the trimmed essay described, preserving the information locally (§1.1)
Boreas618
force-pushed
the
refactor/move-cfg-to-common
branch
from
August 1, 2026 11:00
5c1803b to
b4b1628
Compare
Boreas618
force-pushed
the
refactor/asm-backend-cleanup
branch
from
August 1, 2026 11:09
bfc5d0d to
a04f318
Compare
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.
Stacked on #18 (its base branch carries the asm renames; this PR's
phi_lowering.rsdiff is import-path only).Fixes the backwards dependency found by the cross-layer audit: the asm backend imported
opt::cfg::Cfg— the backend depended on the middle-end.Cfgis a thin, generally useful wrapper (CfgNodefor IRBasicBlock+ a{labels, graph}bundle overcommon::graph) and now lives incommonnext to the graph utilities, so both opt (mem2reg) and asm (phi lowering) consume it from below.src/opt/cfg.rs→src/common/cfg.rs, verbatim, now with dense rustdoc matchingcommon/graph.rs(the opt version had none).opt::mem2regandasm::phi_lowering; missing//!module docs added toopt/mem2reg.rsandopt/dominator.rs.common's accepted coupling toiris already documented incommon/pass.rs.Verified:
cargo test30/30 green.