Skip to content

Assignments 09 regalloc

Mugundan edited this page Nov 27, 2026 · 1 revision

Stage 8: Registers, Copies and Spills

Relevant source files

The following files were used as context for generating this wiki page:

Make the register allocator work under pressure.

Purpose and Scope

copyPhysReg, storeRegToStackSlot, loadRegFromStackSlot, isLoadFromStackSlot/isStoreToStackSlot, correct reserved registers.

Read First

Tasks

  1. copyPhysReg emits addi rd, rs, 0 (or an or).
  2. Spill/reload use sw/lw with a frame-index operand pair (FI, 0).
  3. Reserve sp; reserve r11 only when hasFP.

Tests

Write a function that keeps 20 values live at once (sum of 20 loaded values used twice). With -O2, MIR after greedy must contain spill slots and assembly must contain reloads, and the result must be correct when run in a simulator if you have one.

Done When

  • High-pressure test compiles at -O0 (fast allocator) and -O2 (greedy)
  • No use of reserved registers

Next: stage 9. All Toy code and expected output on this page are illustrative, not LLVM source and not tool output; your exact output may differ.

Start here

Computer Organization & Architecture

Hexagon ISA

Operating Systems

C++ for LLVM Development

LLVM IR

SelectionDAG

Backend Assignments

Target Bring-up

Calling Conventions

Frame Lowering

MC Layer

Register Allocation

Scheduling

Clone this wiki locally