Skip to content

feat: dominance, SSA and def-use chains - #16

Merged
SizzleUnrlsd merged 2 commits into
mainfrom
feat/ssa
Sep 3, 2026
Merged

SizzleUnrlsd merged 2 commits into
mainfrom
feat/ssa

Conversation

@SizzleUnrlsd

Copy link
Copy Markdown
Contributor

Summary

Closes Phase 3 of docs/architecture.md: dominance (§5) and SSA (§7).

  • Acceptance tests first (test: define dominance, SSA and def-use behavior), implementation follows.
  • cfg/dominance.py: dominator tree with immediate dominators, children, dominance frontiers and iterated frontiers, computed with the Cooper–Harvey–Kennedy algorithm over reachable blocks. The same code on the reversed graph from a virtual EXIT gives post-dominators; the post-dominance frontier is control dependence. Exposed as cfg.dominance and cfg.post_dominance function analyses.
  • ir/ssa.py: SSAAnalysis (ir.ssa) derives a new immutable FunctionIR from PyIR and the dominator tree. Locals disappear, merges get Phi instructions placed on the iterated dominance frontier and pruned by liveness, for_next defines the loop variable, and a local read before any definition on some path reads an explicit Undefined value created once in the entry block. Only reachable blocks are kept; values are renumbered densely. SSA is a derived analysis rather than an in-place transformation, so Rule 3 (immutable IR) holds and the manager caches and invalidates it like any other result.
  • ir/defuse.py: DefUseAnalysis (ir.defuse) indexes definitions (parameter, instruction or terminator) and uses (instruction or terminator) of every SSA value.
  • IR model: Phi, Undefined, a result on ForNext, and generic operands() / substitute() on every instruction and terminator.
  • --emit-ir --ssa prints the §7 example exactly as the document shows it, with numbered values.

Part of #15. Left open there: nothing functional; the "SSA invalidates dependants" bullet is satisfied by the manager's declarative dependencies (SSAAnalysis requires PyIRAnalysis and DominanceAnalysis, DefUseAnalysis requires SSAAnalysis).

Closes #15

@SizzleUnrlsd SizzleUnrlsd mentioned this pull request Sep 3, 2026
5 tasks done
@SizzleUnrlsd SizzleUnrlsd self-assigned this Sep 3, 2026
@SizzleUnrlsd
SizzleUnrlsd merged commit 99476e2 into main Sep 3, 2026
6 checks passed
@SizzleUnrlsd
SizzleUnrlsd deleted the feat/ssa branch September 3, 2026 05:28
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.

Add dominators, SSA and def-use chains

1 participant