Re: Do not spill variables/registers on the stack

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2 February 2011 17:14, Stefan Schulze Frielinghaus
<stefan@xxxxxxxxxxxx> wrote:
> 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.
>

I am not quite sure what you are asking/trying to do but the register
keyword is used to tell the compiler keep this variable inside any
available registers which is useful if your going to use it alot in a
piece of code i would imagine it could speed up things alot.

If you take the keyword out the compiler doesnt assume anything and
goes for the safer option and put stuff in the stack which is just the
safe option of the compiler and since your compiling with -O0 i doubt
any optimizations are being passed and i dont know of any super
specific optimisation that would do what you want.

But have you tried comparing the outputs of what -O0 outputs to say -O2 ?

--Phil



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux