This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Do not spill variables/registers on the stack
- From: Ian Lance Taylor <iant at google dot com>
- To: Stefan Schulze Frielinghaus <stefan at seekline dot net>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Wed, 02 Feb 2011 14:04:56 -0800
- Subject: Re: Do not spill variables/registers on the stack
- References: <1296666863.5027.11.camel@vogon.seekline.net>
Stefan Schulze Frielinghaus <stefan@seekline.net> writes:
> I would like to compile my code with optimization level zero (-O0) and
> enable only one optimization which keeps most variables in registers if
> possible, i.e. does not spill them on the stack.
>
> At the moment I circumvent this problem by always stating that a
> variable should be in a register if possible:
>
> int main(void) {
> register int a = 1;
> register int b = -1;
>
> return a+b;
> }
>
> Compiling it with -O0 results in a binary where the variables a and b
> are in registers and are not spilled on the stack. If I remove the
> keyword "register", then the variables are spilled on the stack.
> I had a look at the man page but couldn't find a suitable optimization
> flag which prohibits this.
>
> Does someone has an idea?
What you want is to disable all optimizations other than register
allocation. That does not sound like a particularly useful feature for
gcc to provide, and in fact it does not provide it. You could do it by
changing gcc's source code.
Ian