SSA, control flow and dominance - Internet Explorer
Address
https://freetolearn.world/compiler-optimizer-reading-03.html
free to learn.world
← Compiler Optimizer

Static school reading · Terminal implementation

SSA, control flow and dominance

Read here, then implement your own optimizer in the learner project. This page does not execute code, save answers or award results. Use the terminal tools to preserve first attempts, source versions, help and revisions.

The named U08/U09 reduction defect has passed an independent focused public-interface recheck. The owner package’s broader pending-review statements describe its original scope; the complete documented terminal route has since been exercised in a source-aware owner run. Browser and human learning are not claimed.

Get the learner project on GitHub
Setup, nine lessons and contracts

SSA, control flow and dominance

A substituted value may be numerically right yet unavailable on a path. Implement dominators(program) so your optimizer can establish where a definition is usable.

Prerequisite: U01, directed graphs and sets. The supplied cfg utility returns predecessor and successor lists; you own the dominance analysis.

Compute availability across every path

Block A dominates block B when every entry-to-B path passes through A. Each block dominates itself. The entry dominates every reachable block.

For a diamond E → L/R → J, the dominator sets are E:{E}, L:{E,L}, R:{E,R}, J:{E,J}. Neither arm dominates J because the other arm supplies a path avoiding it.

A practical fixed-point procedure initializes entry to {entry} and every other reachable block to the set of all blocks. Repeatedly replace a non-entry block's set with itself plus the intersection of its predecessors' sets. Stop only when every set is unchanged. Initializing all non-entry blocks to just themselves would discard necessary facts rather than compute this solution.

Apply the procedure by hand to a graph with a backedge before coding. Return sorted arrays keyed by block ID; block storage order must not influence the answer.

Commit item 02a using question and answer.

A phi uses values on edges

A phi selects the value associated with the predecessor that actually transferred control. Its incoming values must be available at their own predecessor terminators, not necessarily on every path into the successor.

In a loop, a body-defined next counter can feed a header phi on the backedge even though the body does not dominate the first entry into the header. The initial incoming value handles that first entry.

All selected phi inputs are read from the predecessor environment before any new phi result is written. This matters when two loop variables exchange values. The supplied interpreter implements this rule; your analysis must not reject valid backedge uses.

Commit item 02b, then implement the analysis and run:

node cli.mjs check 02 work --help-used none

Transfer the analysis

Reorder the blocks of a valid program without changing its edges and check that dominance is unchanged. Add a second path into a join and reconsider which definitions remain available. In U03, use this relation before reusing an expression across blocks.

The independent supplied verifier checks SSA legality by a different graph method. It is an oracle for this workbench, not a substitute for implementing the target analysis.

Return to setup and delivery limits

Course overviewInternet
Mission.txt - Notepad

Learning without paywalls.

Find what people pay to learn.
Build a great course. Give it away.

One course at a time.

Usage & privacy

Start