Bug 39341 - Feature request: function attribute to save all used registers
Summary: Feature request: function attribute to save all used registers
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: unknown
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2009-03-02 11:29 UTC by Alessandro Pignotti
Modified: 2009-03-03 16:08 UTC (History)
1 user (show)

See Also:
Host: x86/x86_64
Known to work:
Known to fail:
Last reconfirmed:


Note You need to log in before you can comment on or make changes to this bug.
Description Alessandro Pignotti 2009-03-02 11:29:12 UTC
It would be useful to interface C functions with code written in raw assembly to have a function attribute to make a function save and restore every used registers, even flags register if possible.

This should not cause big problems because such special functions will still _respect_ the ABI, but would not _expect_ the code around to be so fair.
Comment 1 Falk Hueffner 2009-03-02 11:43:00 UTC
Why not just use -fcall-saved-reg for the relevant registers?
Comment 2 Alessandro Pignotti 2009-03-02 11:54:07 UTC
Using -fcall-saved-reg for every reg is a very heavy syntax, and would not work on flags register. I think that a per function attribute would be better. It seems that this feature is actually supported for a couple of architectures (for example blackfin) with the attribute 'saveall'
Comment 3 Andrew Pinski 2009-03-02 13:39:07 UTC
First the target needs support for saving those registers.  Does it make sense to mark the TOC register as being saved?  How about the thread local storage register being saved?

Why not used use ABI correctly?  Because the raw assembly is just violating the ABI.  There is a reason why ABIs exist in the first place :).
Comment 4 Alessandro Pignotti 2009-03-03 16:08:26 UTC
i'm afraid i'm only experienced with x86/x86_64 and, to a lesser extent, MIPS. so i'm marking this request as x86 specific.

For my purpose it would be enough to save all gp registers, excluding those that has a special meaning, for example the stack pointer. (%r[a-d]x, %r[ds]i, %r[9-15])