Research

Research Areas.

Four layers of the compiler I am reading about and trying to understand. What I learn goes on the blog, with sources. “Research” here means a learner’s reading list, not lab work.

Intermediate Representation

How language-independent IRs are built so they are easy to analyse and transform.

  • SSA form and phi nodes
  • Control-flow graphs and dominator trees
  • Keeping type and borrow information through the IR
Related post: SSA Form: One Assignment per Variable
ssa.irIR
; phi picks a value by incoming blockjoin: %y = phi i32 [10, then], [20, else] %z = add i32 %y, 1 ret i32 %z

Optimization

How loop, memory and data-flow transforms make code faster and smaller.

  • Loop transforms: hoisting, unrolling, fusion
  • Inlining decisions
  • Safe bounds-check elimination
Related post: Hoisting Loop-Invariant Code
scale.rsOpt
fn scale_all(out: &mut [i32], data: &[i32], scale: i32) { let k = scale * 2; // hoisted out of the loop for i in 0..out.len() { out[i] = data[i] * k; }}

Code Generation

How IR gets lowered to the CPU through instruction selection, register allocation and scheduling.

  • Instruction selection and pattern matching
  • Register allocation and spilling
  • Instruction scheduling
Related post: Register Allocation: Fitting into a Few Slots
sum.sCodegen
.L_loop: add eax, dword ptr [rdi + 4*rcx] ; s += a[i] inc rcx cmp rsi, rcx jne .L_loop

Static Analysis

How bugs and undefined behaviour can be found without running the program.

  • Data-flow analysis
  • Integer overflow and bounds errors
  • Value ranges through abstract interpretation
Related post: What Does Rust's Borrow Checker Actually Check?
index.rsAnalysis
fn last_before(len: usize, offset: usize) -> usize { len - offset - 1}// warning: subtraction underflows when offset >= len// hint: use len.checked_sub(offset + 1)
Approach

How I Learn

No rush; every topic goes through these four small steps.

  1. 1

    Read

    I start from a source: a book, a paper or official docs.

  2. 2

    Try

    I write a tiny example to see it for myself.

  3. 3

    Check

    I compare what I understood with the source and fix my mistakes.

  4. 4

    Share

    I write it up on the blog with sources, in case it helps someone else.