Skip to content

Frame Lowering 02 frame info

Mugundan edited this page Nov 27, 2026 · 1 revision

MachineFrameInfo

Relevant source files

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

`MachineFrameInfo` is the per-function table of stack objects. Each object has an index (the **frame index**), a size, an alignment, and, once PEI has run, an offset. Code refers to objects only by index (`%stack.0`, `%fixed-stack.1` in MIR) until frame index elimination replaces the index with a register and an offset.

Purpose and Scope

The kinds of objects, how they are created, and the function-wide flags frame lowering reads. The pass that assigns offsets is on The PEI Pass.

Object Kinds

Kind Created with Index Offset known when created? Example
Fixed object CreateFixedObject(Size, SPOffset, IsImmutable) (line 723) Negative Yes, relative to SP at function entry Incoming stack argument
Fixed spill object CreateFixedSpillStackObject (728) Negative Yes Some callee-saved slots
Stack object CreateStackObject(Size, Align, IsSpillSlot) (831) ≥ 0 No, PEI assigns it alloca, spill slot
Variable-sized object CreateVariableSizedObject(Align, Alloca) (851) ≥ 0 No; sets HasVarSizedObjects alloca i8, i64 %n

isFixedObjectIndex (732) tells them apart. Each object also has a stack ID (getStackID, 794): Default for normal memory, others (such as scalable vectors on AArch64) for objects laid out separately.

Sources: llvm/include/llvm/CodeGen/MachineFrameInfo.h:112-129, llvm/include/llvm/CodeGen/MachineFrameInfo.h:723-732, llvm/include/llvm/CodeGen/MachineFrameInfo.h:794, llvm/include/llvm/CodeGen/MachineFrameInfo.h:831-851

Where Objects Come From

flowchart TD
    LFA["LowerFormalArguments"] -->|"CreateFixedObject"| F["fixed objects (negative indices)"]
    FLI["FunctionLoweringInfo (static allocas)"] -->|"CreateStackObject"| S["stack objects"]
    DYN["dynamic alloca"] -->|"CreateVariableSizedObject"| V["variable-sized"]
    RA["spiller"] -->|"CreateSpillStackObject"| S
    PEI["PEI: assignCalleeSavedSpillSlots"] --> S
Loading

AArch64's LowerFormalArguments creates one fixed object per stack argument:

        int FI = MFI.CreateFixedObject(ArgSize, ArgOffset + BEAlign, true);

Sources: llvm/lib/Target/AArch64/AArch64ISelLowering.cpp:9515

Function-Wide Information

Accessor Line Meaning
hasVarSizedObjects() 371 Any dynamic alloca; usually forces a frame pointer
getObjectOffset(FI) 553 Offset from the incoming SP (valid after PEI)
getStackSize() / setStackSize() 612 / 615 Total frame size, set by PEI
getMaxAlign() 627 Largest object alignment; may force stack realignment
adjustsStack() 644 Function calls something or otherwise moves SP
getMaxCallFrameSize() 698 Largest outgoing argument area of any call
setCalleeSavedInfo() 863 List of callee-saved registers and their slots (CalleeSavedInfo, line 36)

These appear in the frameInfo: section of MIR. For the AArch64 withcall function after PEI:

  stackSize:       16
  adjustsStack:    true
  hasCalls:        true
  maxCallFrameSize: 0
  - { id: 0, name: '', type: spill-slot, offset: -8, size: 8, alignment: 8,
      stack-id: default, callee-saved-register: '$x19', callee-saved-restored: true,
  - { id: 1, name: '', type: spill-slot, offset: -16, size: 8, alignment: 8,
      stack-id: default, callee-saved-register: '$lr', callee-saved-restored: true,

Before PEI the same function had stackSize: 0 and an empty stack: list; the two callee-saved slots were added by PEI.

Sources: llvm/include/llvm/CodeGen/MachineFrameInfo.h:36, llvm/include/llvm/CodeGen/MachineFrameInfo.h:371, llvm/include/llvm/CodeGen/MachineFrameInfo.h:553-698, llvm/include/llvm/CodeGen/MachineFrameInfo.h:863

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