Implement Linear Scan Register Allocation With Spill Heuristics

Last updated: November 29, 2026

Quick Overview

Given live intervals for virtual registers as (name, start, end) and a fixed number of physical registers, assign each interval a register or mark it spilled using linear scan allocation, spilling the interval that lives longest when registers run out.

Arm
Coding & Algorithms
Software Engineer
Arm
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Given live intervals for virtual registers as (name, start, end) and a fixed number of physical registers, assign each interval a register or mark it spilled using linear scan allocation, spilling the interval that lives longest when registers run out.

Arm's compiler teams work on code generation for Cortex-A, Cortex-M and Neoverse targets, and register pressure is a constant concern, especially with only a handful of registers on M-profile cores. The interviewer wants the classic Poletto and Sarkar algorithm implemented cleanly and a sensible discussion of why the spill heuristic works.

What the Interviewer Expects
  • Sort intervals by start point
  • Keep an active list ordered by end point and expire finished intervals
  • Return registers to a free pool on expiry
  • Spill the interval with the furthest end when no register is free, possibly stealing its register
  • Analyse complexity and compare with graph coloring
Key Topics to Cover
register allocation
interval scheduling
greedy algorithms
compilers
sorted containers
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you handle intervals with holes, as LLVM's greedy allocator does?
  • How would you account for spill cost such as loop depth instead of just interval length?
  • How do fixed registers from the calling convention (x0 to x7 for arguments) fit in?
  • When is graph coloring worth its extra compile time?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Each interval is live from start to end inclusive. Two intervals conflict if they overlap. With k registers, no two simultaneously live intervals can share a register. Output a mapping to a regi...

High-Level Design

Walk intervals in order of start. Maintain active, intervals currently holding a register, sorted by end. Before handling a new interval, expire every active interval whose end is before the new sta...


Submit Your Answer
Markdown supported

Related Questions