[llvm-dev] Register spilling in caller saved backend

Peter Bergner via llvm-dev llvm-dev at lists.llvm.org
Tue Sep 1 10:25:50 PDT 2015


On Tue, 2015-09-01 at 09:29 -0700, Jacques Pienaar via llvm-dev wrote:
> On Tue, Sep 1, 2015 at 9:13 AM, Philip Reames <listmail at philipreames.com> wrote:
>> What are you expectating here?  Are you expecting the backend to recognize
>> that foo doesn't actually clobber any registers?  I don't believe we do
>> that today.  Without callee saved registers, if the value 'i' needs to be
>> preserved across the call, it will need to be spilled.  There's no register
>> we can put it in without it being clobbered.
>
> Yes that was what I was hoping for as it seems that all the information
> is there to do that. So at the moment if there is a case such as this
> then the backend should have some designated callee saved registers.
> That makes sense if that information isn't being used at the moment
> then we can't know if the register will be clobbered or not and have
> to assume it will.

Some IBM compilers did this.  We called it register resurrection.
Basically you need a call graph, so this is limited to interprocedural
optimization or statically defined called functions (locally defined
like your example here is ok too, provided you are not compiling for
a shared library, since locally defined functions can be overridden).
You then need to do register allocation on the functions in the call
graph from the leaves up.  You can then promote some of the caller
saved registers for function foo() to callee saved if they were never
clobbered within foo().  This allows callers of foo() to see extra
callee saved registers at foo() call points.  Of course, you have to
assume the worst when you encounter recursion in your call graph.

Peter





More information about the llvm-dev mailing list