This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
RFC: #pragma optimization_level
- From: Dale Johannesen <dalej at apple dot com>
- To: gcc List <gcc at gcc dot gnu dot org>
- Cc: Dale Johannesen <dalej at apple dot com>
- Date: Thu, 31 Mar 2005 16:51:56 -0800
- Subject: RFC: #pragma optimization_level
I've currently got the job of implementing pragma(s) to change
optimization level in the middle of a file. This has come up a few
times before,
http://gcc.gnu.org/ml/gcc/2001-06/msg01275.html
http://gcc.gnu.org/ml/gcc/2002-09/msg01171.html
http://gcc.gnu.org/ml/gcc/2003-01/msg00557.html
and so far nothing has been done, but the users who want
this feature have not gone away, so I will be doing it now.
The only real opposition to the idea was from Mark Mitchell, in
the earliest of these threads,
http://gcc.gnu.org/ml/gcc/2001-06/msg01395.html
So I guess question 1 is, Mark, do you feel negatively enough about this
feature to block its acceptance in mainline? If so, I'll go do this as
a local
patch, Geoff will complain a lot, and it will be done 4 times as fast :)
Let's assume for the sake of argument that Mark is OK with it.
Mark's message also raises some good questions about semantics.
My answers are:
- Flags that logically refer to a whole file at once cannot be changed.
In this category I know of -funit-at-a-time and -fmerge-constants; there
may be others I haven't found.
- When function A is inlined into B, the inlined copy is now part of B,
and
whatever flags were in effect at the beginning of B apply to it. (The
decision
whether to inline is also based on the flags in effect at the beginning
of B.)
- As a first cut I intend to allow only -O[0123s] to be specified in
the pragma,
as suggested by Geert Bosch. I don't think there's any reason this
couldn't
be extended to single flags.
Implementation: the general idea is
- at the beginning of parsing each function, record the flags currently
in effect
in (or pointed to from) the FUNC_DECL node.
- before optimizing/generating code for each function, reset the flags
from stored values.
As a first step I think I'll unify the various flags into a struct;
that seems like a good
janitor patch anyway.
(I should add that a requirement for me is CodeWarrior compatibility.
Their syntax is
#pragma optimization_level [01234]
#pragma optimize_for_size
Functionality doesn't have to match exactly, but ought to be more or
less the same.
CW's treatment of the interaction with inlining is as described above,
and I'd be averse
to changing that; their way is reasonable, and there's existing code
that depends on it.
For mainline I assume we'll need "GCC" to the syntax; that local change
is small compared
to making it work though.)
Comments?