code-yeongyu / code-yeongyu/c11-compiler-zig-omo

[Sisyphus] phase-2 / zcc / Wave 6 — Optimization passes (minimal)

Open
#22 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
3
Forks
0
PR merge metrics
No merged PRs in 30d

Description

## Scope
Implement a minimal but effective optimization pass pipeline on the typed SSA IR.

## Deliverables
- `phase2/zcc/src/opt.zig` — optimization pass manager and individual passes.
- Passes required:
1. **mem2reg** — promote stack allocations to SSA registers where possible.
2. **SCCP** (sparse conditional constant propagation) — fold constants and unreachable branches.
3. **DCE** (dead code elimination) — remove unused instructions.
4. **Simple inlining** — inline small functions (size-bounded, e.g., ≤ 20 IR instructions).

## Success Criteria
1. `opt(0)` (no optimizations) and `opt(2)` (all passes) produce different IR sizes for every non-trivial reference file.
2. Observable behavior (stdout, stderr, exit code) of compiled programs is identical between `-O0` and `-O2` for all `phase1/c11-ref/*.c` test programs.
3. Pass manager runs passes in a fixed order and can be extended.

## Dependencies on Prior Waves
- **Wave 0–5** — IR must exist before it can be optimized.

## Suggested Role Assignment
`opt-engineer`

## Test Corpus Expectations
- IR-size regression: `-O2` IR is strictly smaller than `-O0` IR for `001..023`.
- Behavioral equivalence: compile and run `001..023` at both levels; compare outputs.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.