Skip to content

feat: SafeRegAlloc — stack-canonical register allocator for V1 correctness#129

Merged
egecanakincioglu merged 1 commit into
mainfrom
feat/safe-regalloc-core
Jun 6, 2026
Merged

feat: SafeRegAlloc — stack-canonical register allocator for V1 correctness#129
egecanakincioglu merged 1 commit into
mainfrom
feat/safe-regalloc-core

Conversation

@egecanakincioglu

Copy link
Copy Markdown
Owner

SafeRegAlloc — V1 correctness-first register allocator

Design

  • Every IR value lives in a unique stack slot (canonical location)
  • Registers are instruction-local scratch only
  • No spill/reload tracking, no live interval computation
  • No callee-saved register reuse across instructions

Core

  • allocate(fn): scans params + REG destinations, creates unique slots
  • frameSize(): totalSlots × 8 with 16-byte alignment
  • findOrCreate/getSlot/slotByName: slot management
  • slotOffset/slotOffsetByName: stack offset computation

Scratch Pool

  • RDI, RSI, RDX, RCX, R8, R9, R10, R11 (8 caller-saved regs)
  • RAX excluded — reserved for idiv/call-return/syscall-num
  • allocScratch/allocScratch2/allocScratch3: guaranteed distinct regs
  • resetScratch: instruction boundary cleanup

Safety Assertions

  • assertKnown(name): slot must exist before load/store
  • assertWritten(name): slot must be written before reload
  • assertClean(): no dirty scratch state at instruction boundary

Written Tracking

  • markWritten/markValueWritten/markAllParamsWritten: track initialization
  • isWritten/isValueWritten: query written state

Debug

  • dump(): full slot table with offsets, types, written flags

…tness

SafeRegAlloc: correctness-first allocator. Every IR value in unique stack slot.
Registers are instruction-local scratch only. No live value survives instruction boundary.
Implements allocate(), frameSize(), scratch pool, safety assertions, written tracking.
@egecanakincioglu egecanakincioglu merged commit ab60fb0 into main Jun 6, 2026
1 check passed
@egecanakincioglu egecanakincioglu deleted the feat/safe-regalloc-core branch June 6, 2026 01:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant