Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 4 May 2009 04:59:50 +1000
From:      Peter Jeremy <peter@vk2pj.dyndns.org>
To:        John Gemignani <john.gemignani@isilon.com>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: C99: Suggestions for style(9)
Message-ID:  <20090503185950.GA62081@server.vk2pj.dyndns.org>
In-Reply-To: <108501c9c8fe$3a30ab0e$72020a0a@desktop.isilon.com>
References:  <108501c9c8fe$3a30ab0e$72020a0a@desktop.isilon.com>

next in thread | previous in thread | raw e-mail | index | archive | help

--T4sUOijqQbZv57TR
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On 2009-Apr-29 12:10:44 -0700, John Gemignani <john.gemignani@isilon.com> w=
rote:=20
>Are local variables allocated on-the-fly on the stack or does the
>compiler preallocate the space on entry?

This is compiler and optimisation dependent.  As a general rule, if a
compiler is not performing any optimisation, it is likely to allocate
all variables on the stack.  An obvious code optimisation is to keep
variables in registers instead of storing them on the stack.

In the specific case of older gcc versions with optimisation enabled
(I'm not sure of the behaviour of gcc 4.x), gcc will immediately spill
(allocate on the stack) local variables that aren't eligible to be
held in registers (eg too large or the variable address is taken) and
allocate remaining variables to virtual registers.  During code
generation, virtual registers are mapped to physical registers and any
remaining virtual registers are allocated on the stack.

> If I have to delve into a
>crashdump, having the variables on the big entry allocation has been
>very helpful in the past.

OTOH, not caching variables in registers has a significant adverse
impact on performance.

--=20
Peter Jeremy

--T4sUOijqQbZv57TR
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.11 (FreeBSD)

iEYEARECAAYFAkn96aYACgkQ/opHv/APuIeUlQCghdfapFUS4oq1QlKxGhl+4Ui6
F9IAoLCv+iOrQcFdgTD2FCcmh6SAugca
=b42X
-----END PGP SIGNATURE-----

--T4sUOijqQbZv57TR--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20090503185950.GA62081>