Repository navigation
Register Allocation 11 tooling
Relevant source files
The following files were used as context for generating this wiki page:
Which options exist, which work in which kind of build, and a workflow for the common questions: why did this spill, why is this copy still here, and why did allocation fail.
Every option below was tried with the release llc built from the pinned commit (LLVM 24.0.0git, "Optimized build"):
| Option | Release llc
|
Notes |
|---|---|---|
-stop-before=P, -stop-after=P
|
Works | Print MIR as a .mir file and stop |
-print-before=P, -print-after=P
|
Works | Print MIR with slot indexes (32B, 48B, ...) and keep going |
-run-pass=P1,P2 |
Works | Run only these passes on a .mir input |
-verify-machineinstrs |
Works | Run the machine verifier after every pass |
-verify-regalloc |
Works | Extra verification inside the allocator |
-pass-remarks-missed=regalloc |
Works | Greedy's spill and reload counts per function and loop |
-regalloc=fast|basic|greedy|pbqp |
Works | Choose the allocator (which pipeline) |
-stress-regalloc=N |
Works | Limit every class to N registers |
-join-liveintervals=false |
Works | Disable the coalescer |
-split-spill-mode=default|size|speed, -lcr-max-depth=N
|
Work | Greedy tuning (Greedy options) |
-enable-subreg-liveness |
Accepted | Force sub-register liveness on |
-time-passes |
Works | Time spent in each pass, including the allocator |
-stats |
Accepted | Statistics are only collected in builds with statistics enabled |
-debug-pass=Structure |
Works | List the passes that run |
-debug-only=regalloc (and -debug-only=regalloc,register-coalescer,...) |
Not available ("Unknown command line argument") | Needs an assertions build: configure with -DLLVM_ENABLE_ASSERTIONS=ON
|
- Count spills:
llc ... -pass-remarks-missed=regalloc -o /dev/null. No remark means Greedy did not spill. AnySpillcomments in the assembly are then callee-saved saves (how to tell). - Look at the input to the allocator:
-stop-before=greedy. How many values are live at the hot point? Do they cross calls? - Look at its output:
-stop-after=virtregrewriter. Find theSTR...ui %stack.NandLDR...ui %stack.Ninstructions and the registers involved. - In an assertions build:
-debug-only=regalloc. It prints everyselectOrSplitdecision, with the interval, its weight, the stage, and whether it was assigned, evicted, split or spilled. - Experiments:
-regalloc=basic(no splitting) and-split-spill-mode=.... Also compare-O2with and without the scheduler's pressure tracking, by changing the input.
-
-stop-after=register-coalescer: is the copy still there? If yes, the coalescer refused it. Usual reasons are physical-register copies (kept as hints), no common sub-class, or ashouldCoalesceveto (coalescer). -
-stop-after=virtregrewriter: does the copy now have different registers on each side? Then the hint was broken, usually because the hinted register is busy (example:mov w0, w8in the loop walkthrough). - If the copy came from splitting, it sits at a split boundary: a block edge or around a call.
error: ran out of registers during register allocation or error: inline assembly requires more registers than available:
- Find the instruction: the error names the function; with an assertions build
-debug-only=regallocshows the last interval. - Check that instruction's operand constraints. Do too many operands need the same small class at once? Is there an early-clobber definition plus many uses?
- Check
getReservedRegs: did a recent change reserve too much (checklist)? - Try
-regalloc=basicand-regalloc=pbqp. If every allocator fails, the constraints are impossible. If only Greedy fails, see the last-chance recoloring limits (-lcr-max-depth,-lcr-max-interf).
llc -mtriple=aarch64 -O2 bug.ll -stop-before=greedy -o bug.mir
# edit bug.mir down to the smallest function that still fails
llc -mtriple=aarch64 -run-pass=greedy,virtregrewriter -verify-machineinstrs bug.mir -o -
Tried at the pinned commit on the loop example: the .mir round trip produced the same allocation as the full pipeline (renamable $w10 = LDRWroX renamable $x0, renamable $x9, 0, 1). Running just -run-pass=greedy leaves virtual registers in the output, assigned in VirtRegMap but not yet rewritten. Add virtregrewriter to see physical registers.
Turn it into a regression test with llvm/utils/update_mir_test_checks.py.
| You see | It means |
|---|---|
%5:gpr32 |
Virtual register 5, class gpr32
|
%15.sub_32 |
The sub_32 part of %15
|
$w0, $x19
|
Physical registers |
renamable $w8 |
Assigned by the allocator; may be renamed later |
killed, dead, undef
|
Last use; never-read definition; value does not matter (flags) |
csr_aarch64_aapcs on a call |
Register mask: registers outside it are clobbered |
%stack.3 |
Frame index; type: spill-slot in the stack: section means an allocator spill slot |
32B before an instruction |
Slot index (only in -print-* output; liveness) |
liveins: $w1, $x0 |
Physical registers live into the block (after the rewriter) |
TiedOpsRewritten, NoPHIs, NoVRegs
|
Function properties: which preparation steps have happened |
- Computer Architecture Overview
- Fundamentals: CPU, Memory and Instructions
- Pipelining
- Branches and Remedies
- Instruction-Level Parallelism
- Memory and Ordering
- Caches and Coherence
- Multicore
- Multithreading in Hardware
- SIMD and GPUs
- Glossary and Summary
- Hexagon Overview and Processor Properties
- ISA Fundamentals: Packets, Slots and Threads
- Registers
- Instruction Encoding and Mnemonics
- Data, Memory and Control Instructions
- Floating Point, HVX and Alignment
- Caches, MMU and Glossary
- Operating Systems Overview
- Processes
- Threads
- CPU Scheduling
- Synchronization
- Deadlock
- Memory Management
- Virtual Memory
- Files, Storage and I/O
- Kernel and System Calls
- Interview Q&A and Glossary
- C++ for LLVM Development: Overview
- C++ Basics
- Classes and RAII
- Ownership and Move Semantics
- Templates and Lambdas
- LLVM Data Structures (ADT)
- LLVM-Style RTTI: isa, cast, dyn_cast
- Errors, Output and Assertions
- Iterators and Ranges
- Building, Debugging and Exercises
- LLVM IR Overview
- Structure: Modules, Functions, Blocks and Values
- Type System
- Arithmetic, Bitwise and Cast Instructions
- Compare and Select
- Memory: alloca, load, store and getelementptr
- Control Flow: br, switch, ret and call
- SSA and Phi
- Control Flow Graph and Loops
- Dominance, Dominator Tree and Dominance Frontier
- Data-flow Analysis
- Writing an IR Pass
- Common Passes
- Exercises, Tooling and Glossary
- SelectionDAG Overview
- Pipeline, Phases and Traversal Orders
- Core Data Structures
- DAG Construction
- DAG Combiner
- Legalization
- Type Legalization
- Operation and Vector Legalization
- Instruction Selection
- TableGen Pattern Language
- Matcher Interpreter and Folding
- AArch64 Instruction Selection
- Scheduling and MIR Emission
- PHI Node Resolution
- AArch64 Walkthroughs
- Arithmetic and Data Movement
- Memory Instructions
- Control Flow and Calls
- End-to-End Example
- Tooling, Debugging and Extending
- Selector Comparison and Glossary
- Assignments: Build the Toy Backend
- Stage 1: Build Setup
- Stage 2: Target Registration
- Stage 3: TableGen Skeleton
- Stage 4: MC Layer for Assembly Output
- Stage 5: TargetMachine and Subtarget
- Stage 6: TargetLowering, Arguments and Returns
- Stage 7: Instruction Selection and the First Function
- Stage 8: Registers, Copies and Spills
- Stage 9: Frame Lowering
- Stage 10: Memory, Globals and Control Flow
- Stage 11: Calls
- Stage 12: Scheduling Model
- Stage 13: Object Files
- Stage 14: Capstone, a Complete Toy Backend
- Target Bring-up Overview
- Directory Layout, CMake and Registration
- The Target .td File
- TargetMachine and Subtarget
- TargetLowering Setup
- Calling Conventions
- Instructions and Instruction Selection
- Registers and Allocation Hooks
- Frame Lowering
- AsmPrinter and the MC Layer
- Scheduling
- A Minimal Toy Target
- Bring-up Checklist and AArch64 File Map
- Tooling and Glossary
- Calling Conventions Overview
- The CallingConv.td Language
- CCState and CCValAssign
- LowerFormalArguments
- LowerCall
- LowerReturn and CanLowerReturn
- Varargs, byval, sret and swifterror
- Tail Calls and Sibling Calls
- Custom Backend Guide and Checklist
- AArch64 Walkthroughs
- Tooling and Glossary
- Frame Lowering Overview
- MachineFrameInfo
- TargetFrameLowering Hooks
- The PEI Pass
- Callee-Saved Registers and Stack Layout
- Frame Index Elimination and the Register Scavenger
- Shrink Wrapping
- CFI and Unwind Information
- Custom Backend Guide and Checklist
- AArch64 Walkthroughs
- Tooling and Glossary
- MC Layer Overview
- Core Data Structures
- Streamers
- Assembler and Layout
- Fixups and Relocations
- Writing an MC Layer for a Custom Backend
- MCAsmInfo and the Instruction Printer
- Code Emitter
- AsmBackend and Object Writer
- Assembly Parser and Disassembler
- Bring-up Checklist and Common Failures
- Tooling and Glossary
- Register Allocation Overview
- The Register Allocation Pipeline
- Registers, Virtual Registers and Register Classes
- Liveness: Slot Indexes and Live Intervals
- Preparing Code for Allocation
- PHI Elimination and Two-Address Lowering
- Register Coalescer
- Allocation Framework
- The Register Allocators
- Fast Register Allocator
- Basic Register Allocator
- Greedy Register Allocator
- PBQP Register Allocator
- Spilling and Splitting
- Spill Weights and Copy Hints
- The Inline Spiller
- Live Range Splitting
- Rewriting and Post-RA Passes
- Writing Register Allocation Support for a Custom Backend
- Register Definitions in TableGen
- TargetRegisterInfo Hooks
- TargetInstrInfo Hooks
- Pass Pipeline Hooks
- Bring-up Checklist and Common Failures
- AArch64 Walkthroughs
- Tooling and Debugging
- Glossary and Where Do I Look