Chapters¶
Twenty-five chapters in six parts, from lexing to instruction scheduling. The machine-readable source of this index is tools/course/chapters.yaml, and ./course status shows your progress through it.
Every chapter folder has the same shape (see docs/authoring/STYLE.md §2):
| File | What it is |
|---|---|
README.md |
Technique map: the problem, the family of techniques that solve it, who uses what, and a comparison table. Start here. |
lessons/NN-*.md |
One lesson per technique family, each with the nine depth-contract sections: algorithm, traced example, correctness, complexity, variants, real compilers, comparison, assessment. |
exercises.md |
Implementation steps for pebble/ and the comparison lab, with collapsible hints. |
flashcards.tsv |
Cards for ./course flash NN or Anki (./course flash export). |
quiz.yaml |
The theory test (hashed answers): ./course quiz NN. |
A chapter is done when its quiz score is at least 80 % and all of its implementation tests pass (./course test NN).
All 25 chapters are available. (./course status marks a chapter planned only if its entry in chapters.yaml says so; none does today.)
Part 0 — Orientation¶
| Ch | Chapter | What you learn | Drills |
|---|---|---|---|
| 0 | Compiler Architectures & Your Toolchain | Pipeline shapes, interpreters vs VMs vs AOT vs JIT, retargeting, and a first tour of the LLVM tools. | phases, stack-code, dispatch, tdiagram |
Part I — Front End¶
| Ch | Chapter | What you learn | Drills |
|---|---|---|---|
| 1 | Lexical Analysis | Regex to NFA to DFA, minimization, derivatives, maximal munch, context-sensitive and lossless lexing. | epsilon-closure, subset-construction, dfa-minimize, brzozowski-derivative, maximal-munch, utf8, lexer-modes |
| 2 | Grammars & Top-Down Parsing | CFGs and ambiguity, nullable/FIRST/FOLLOW, LL(1) tables, grammar transformations, recursive descent, ALL(*). | derivations, first-follow, ll1-table, left-recursion, predict-trace, lookahead |
| 3 | Bottom-Up Parsing | Shift-reduce, the LR family (LR(0), SLR, LALR, LR(1), IELR), conflicts, GLR and LR error recovery. | lr0-closure, lr-table, shift-reduce-trace, lalr-lookaheads, lr-classify |
| 4 | Parsing in Practice: Expressions, Other Paradigms, Recovery & Syntax Trees | Pratt and shunting-yard, PEG/packrat, Earley, resilient and incremental parsing, and syntax-tree design. | pratt-trace, shunting-yard, packrat-memo, earley-chart, cyk-table, paradigm-accepts |
| 5 | Names, Scopes & Semantic Analysis | Scoping, symbol-table designs, name-resolution strategies, attribute grammars and definite assignment. | resolve-scopes, attr-eval-order, definite-assignment, edit-distance |
| 6 | Type Systems & Type Checking | Typing judgments and soundness, syntax-directed vs bidirectional checking, subtyping, narrowing, generics. | typing-derivation, bidir-modes, subtype-query, progress-preservation, narrowing |
| 7 | Type Inference | Unification, Hindley-Milner (Algorithms W, J, M), constraint-based inference, and Swift's solver. | unification, hm-trace, generalization |
Part II — Intermediate Representations & LLVM¶
| Ch | Chapter | What you learn | Drills |
|---|---|---|---|
| 8 | The Design Space of Intermediate Representations | TAC, bytecode, CFG+SSA, block arguments, sea of nodes, CPS/ANF, MLIR; leaders, CFGs and traversal orders. | leaders, rpo, value-numbering, phi-to-block-args, tac-to-anf, stack-code |
| 9 | LLVM IR in Depth | Modules, types, SSA values, GEP in full, calls and attributes, metadata, and the verifier's invariants. | gep-offset, ir-validity, poison-propagation, flags |
| 10 | The LLVM C++ API | Ownership and intrusive lists, Value/User/Use and RAUW, IRBuilder, LLVM-style RTTI vs C++ RTTI vs variant, PatternMatch vs rule DSLs, ADTs, Error/Expected, interpreter vs MCJIT vs ORC. | use-lists, iterator-invalidation, irbuilder-fold, cast-semantics, pattern-match, densemap-probe, adt-costs, view-lifetime, must-check, jit-compile-set |
| 11 | Lowering & Code Generation: AST → PIR → LLVM IR | SSA generation (allocas + mem2reg, on-the-fly), jumping code, switch lowering, places vs values, aggregates and the ABI, safety checks, EH and closures (overview), runtime and linking; native executables. | jumping-code, switch-lowering, abi-classify |
Part III — Analysis Foundations & SSA¶
| Ch | Chapter | What you learn | Drills |
|---|---|---|---|
| 12 | Passes, Pass Managers & Testing Compilers | Pass-manager architectures, plugins, FileCheck/lit, differential testing, reduction, Alive2 and fuzzing. | pm-invalidation, filecheck-match, ddmin-trace, peephole-verify |
| 13 | Local Optimization & Transformation Correctness | Folding, peephole engines, canonicalization, LVN, reassociation, and poison/undef/freeze refinement. | lvn-table, rewrite-validity, magic-division, reassoc-ranks |
| 14 | Dataflow Analysis & Abstract Interpretation | Lattices and monotone frameworks, worklist and elimination solvers, the four classics, intervals, Datalog. | dataflow-table, worklist-trace, lattice-props, widening |
| 15 | Control-Flow Analysis: Dominance & Loops | Iterative, Cooper-Harvey-Kennedy and Lengauer-Tarjan dominators, frontiers, loop forests and reducibility. | dominators, rpo, lengauer-tarjan, dom-update, idf, post-dominance, natural-loops, loop-forms |
| 16 | Static Single Assignment Form | Minimal/pruned SSA, Cytron vs Braun construction, phi vs block arguments, destruction and SSA extensions. | phi-placement, ssa-renaming, parallel-copy, lost-copy-swap, idf |
Part IV — Optimization¶
| Ch | Chapter | What you learn | Drills |
|---|---|---|---|
| 17 | SSA-Based Scalar Optimizations | SCCP, ADCE, EarlyCSE and GVN variants, PRE/LCM, SimplifyCFG, and equality saturation. | sccp-trace, vn-partition, lcm-sets, adce-marking |
| 18 | Loop Optimizations | LICM, induction variables and SCEV, strength reduction, loop restructuring, dependence analysis, vectorization. | licm-legality, scev-form, trip-count, dependence-test, interchange-legal |
| 19 | Memory: Alias Analysis & Memory Optimizations | TBAA and BasicAA, Andersen vs Steensgaard, sensitivity choices, MemorySSA, DSE and load forwarding. | points-to-andersen, points-to-steensgaard, memoryssa-build, tbaa-query |
| 20 | Interprocedural & Whole-Program Optimization | Call graphs (CHA/RTA), SCC traversal, inlining cost models, IPSCCP, attribute inference, LTO and PGO. | scc-order, cha-rta, inline-decision, ifds-tabulation, funcattrs-fixpoint |
Part V — Back End¶
| Ch | Chapter | What you learn | Drills |
|---|---|---|---|
| 21 | Instruction Selection & the LLVM Code Generator | Maximal munch vs DP tiling, BURS, SelectionDAG vs GlobalISel, ISLE, TableGen and the MC layer. | munch-tiling, dp-tiling, legalization, calling-convention |
| 22 | Register Allocation | Local, Chaitin-Briggs/IRC, linear scan, SSA-based and PBQP allocation, and LLVM's greedy allocator. | interference-graph, chaitin-briggs, coalescing-test, linear-scan, belady, ssa-coloring, pbqp |
| 23 | Instruction Scheduling & Machine-Level Optimization | Dependence DAGs, list scheduling, trace/superblock scheduling, modulo scheduling, MachineScheduler, BOLT. | critical-path, list-schedule, trace-select, ifconvert, mii, modulo-table, code-layout |
Part VI — Capstone¶
| Ch | Chapter | What you learn | Drills |
|---|---|---|---|
| 24 | The Complete Pebble Compiler — and Beyond | Your own -O1 pipeline end to end, differential fuzzing, JIT designs, debug info, memory management. | pass-order, gc-roots, dwarf-location, refcount-trace |
Suggested paths¶
- Full course: chapters 0 → 24 in order.
- IR/optimization fast track: 0 → 8 → 9 → 10 → 12 → 13 → 14 → 15 → 16 → 17 → 18 → (19, 20) → 24. Build the front end from
solutions/(-DPEBBLE_USE_SOLUTION=…, see the course home) and come back to 1–7 and 11 later.