Allocating a fixed size object in a stack frame at a fixed offset

Hello everyone,

I am currently struggling with one problem while developing a customized compiler with LLVM for my current project, and I wonder whether there is someone who can offer a piece of advice.

I am trying to reserve a fixed size (16 bytes) of space in an X86 stack frame at a fixed offset.

(I found a similar discussion here:

Initially, I tried to allocate a stack object using MachineFrameInfo::CreateFixedObject() and MachineFrameInfo::CreateFixedSpillStackObject() in MachineFunctionPass that is pipelined in addPreRegAlloc() in llvm/lib/Target/X86/X86TargetMachine.cpp.

It worked fine for a very simple application, but I found that it does not reserve the stack space when there are spilled general-purpose registers in the stack. I need to reserve a stack space before the spilled registers. Is there any good way of doing this?

I would appreciate any pointer, hint, or tip.

Thank you so much,

Inho Cho

Hi Inho Cho,

it depends on where you need the space, and how you access it. The frame layout is created in the FrameLowering classes, so I would recommend to have a look at X86FrameLowering.

  • You can use the constructor parameter LocalAreaOffset to reserve a space between the SP on function entry, and the local area.
  • You can also use the CreateFixedObject(), e.g. in assignCalleeSavedSpillSlots().
  • You should also check orderFrameObjects() in the X86FrameLowering class, because this functions reorders stack objects.


1 Like