Skip to content

refactor(opt,common): move Cfg wrapper from opt to common - #21

Open
Boreas618 wants to merge 2 commits into
mainfrom
refactor/move-cfg-to-common
Open

refactor(opt,common): move Cfg wrapper from opt to common#21
Boreas618 wants to merge 2 commits into
mainfrom
refactor/move-cfg-to-common

Conversation

@Boreas618

Copy link
Copy Markdown
Contributor

Stacked on #18 (its base branch carries the asm renames; this PR's phi_lowering.rs diff 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. Cfg is a thin, generally useful wrapper (CfgNode for IR BasicBlock + a {labels, graph} bundle over common::graph) and now lives in common next to the graph utilities, so both opt (mem2reg) and asm (phi lowering) consume it from below.

  • src/opt/cfg.rssrc/common/cfg.rs, verbatim, now with dense rustdoc matching common/graph.rs (the opt version had none).
  • Import-path-only updates in opt::mem2reg and asm::phi_lowering; missing //! module docs added to opt/mem2reg.rs and opt/dominator.rs.
  • common's accepted coupling to ir is already documented in common/pass.rs.

Verified: cargo test 30/30 green.

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
Boreas618 force-pushed the refactor/move-cfg-to-common branch from 5c1803b to b4b1628 Compare August 1, 2026 11:00
@Boreas618
Boreas618 force-pushed the refactor/asm-backend-cleanup branch from bfc5d0d to a04f318 Compare August 1, 2026 11:09
@Boreas618
Boreas618 changed the base branch from refactor/asm-backend-cleanup to main August 1, 2026 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant