[llvm-dev] Spill code

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

On 5 May 2016 at 19:37, fateme Hoseini <hoseini.f at gmail.com> wrote:
> Thanks for your reply. My goal is to do some optimizations on the final
> assembly code. I want to do register renaming in the code hotspot and I need
> to spill some registers before entering some loops. And later, reload them
> after exiting the loop.

Ah, sorry. Much much later than SelectionDAG.

> My target architecture is ARM. I have a sample code like this:
> str r2, [sp, #8]            @ 4-byte Spill
> ldrb r2, [r4, r12]!
> and in another code
> str r1, [sp, #52]           @ 4-byte Spill
> and both of them are the first spills in the code. so why #8 in one and #52
> in the other?

I *think* the pass that assigns the offsets is in
lib/CodeGen/StackSlotColoring.cpp (not really my area). Most spills
are inserted by the register allocator, which also puts in FrameIndex
values to be resolved later. The code is pretty generic, so any given
spill-slot could end up anywhere.

If you knew early on how much space you'd need, you might still be
able to call "CreateStackObject", record the FrameIndex and then use
it later. The only question is whether you can call
XYZRegisterInfo::eliminateFrameIndex at that late stage yourself (I've
never had to try).]

> Now assume I want to spill some variable at the end of some basic blocks in
> a program, I should create a store and give it an offset, but how to decide
> what it should be.

If you're creating a self-contained island, you could just create more
offsets with push/pop. As long as there are no function calls, you
don't even need to worry about ABI SP alignment requirements.

Of course, in the big picture enhancing the register allocator so that
it does the job better is probably optimal.



More information about the llvm-dev mailing list