[llvm-dev] Spill code

Tim Northover via llvm-dev llvm-dev at lists.llvm.org
Thu May 5 19:21:26 PDT 2016


Hi Fateme,

On 5 May 2016 at 19:10, fateme Hoseini via llvm-dev
<llvm-dev at lists.llvm.org> wrote:
> Is it possible to add a spill code (a pair of store /load ) to the
> machinecode in a pass before the instruction emitter?

Do you mean during the SelectionDAG phase? If so, the very rough
outline would be something like:

  MachineFrameInfo *MFI = MF.getFrameInfo();
  int Idx = MFI->CreateStackObject(Size, Align);
  SDValue FI = DAG.getFrameIndex(Idx, PtrVT);
  DAG.getStore(Chain, DL, WhateverVal, FI);

The keyword to grep for in the existing code is probably
"CreateStackObject", possibly also "CreateFixedObject" (see later).
Various backends to something along those lines for arguments that get
passed in on the stack and so on.

> If so, how can I calculate the address (offset to the sp) for the spill store/load
> instructions?

The offset to SP during the function's execution isn't decided until
much later (LLVM may need more or less stack space depending on how
many spills *it* decides is necessary). For things that don't need to
have a fixed location, you usually don't need to know it early either
so you'd just use instructions referencing the FrameIndex. Later
passes will then fill in the offsets properly.

If you really, really want to you can use CreateFixedObject, which
will have a set position relative to SP immediately on function entry,
but you'd have to be aware of and handle that in XYZFrameLowering too,
I expect.

Cheers.

Tim.


More information about the llvm-dev mailing list