public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: Controlling the compile within the compiled file?
@ 2002-09-27  9:16 Ciaran O'Riordan
  0 siblings, 0 replies; 4+ messages in thread
From: Ciaran O'Riordan @ 2002-09-27  9:16 UTC (permalink / raw)
  To: dwilliss; +Cc: gcc-help

Shuki says:
> > >Can one instruct the gcc compiler to turn option on/off
> > >within the compiled code?

[snip: me saying No.]

Dave says:
>I don't think that's what Shuki meant by turning optimization
>on and off.  He doesn't want to reverse an optimization, just
>disable it.

You think he wants to disable the option at compile time? Not
within the compiled code. okay.  As far as I know the answer
to that question is also no. (solution/suggestion at end...)

>Some compilers let you use #pragma directives to disable optimizations
[...]
>Gcc is almost totally devoid of #pragmas, at least in 2.95.  I
>don't know about the current version.  I would definitely like to
>see some though.

The GCC committee considered #pragmas to be a broken at one time.
#pragmas have now been fixed (they can be contructed in macros and
have a namespace).  GCC has gotten used to not having #pragmas and
there are no plans to implement them for any widely used
functionality.  You may be looking for "function attributes", these
are generally the GCC replacement for #pragrmas, unfortunatly there
is no ((dont_optimise)) attribute.

A small few platform specifc #pragmas exist, purely for
compatibility with the native compiler for that platform.

I'd like to reiterate my original solution of hand picking the
optimisations you use rather than using the catch all -O1, -O2 or
-O3.  When you use 'gcc -O2', GCC enables about 35 optimisations
(all of which are listed and explained at:
http://gcc.gnu.org/onlinedocs/gcc-3.2/gcc/Optimize-Options.html#Optimize%20Options)

By doing a binary search, you should be able to figure out which
optimisation is causing the problem.  Use half of the optimisations.
If the program doesn't crash you can mark them as safe.  Add half of
the remaining optimisations and so on until you find the problem
causer.

If this brute force method is impractically tedious you could just
pick 5 or 10 optimisations that you think look good and test them
out.  Many of the optimisations have only slight effects.

Did any of this help?


_________________________________________________________________
MSN Photos is the easiest way to share and print your photos: 
http://photos.msn.com/support/worldwide.aspx

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Controlling the compile within the compiled file?
  2002-09-26 20:19 Ciaran O'Riordan
@ 2002-09-27  7:27 ` Dave Williss
  0 siblings, 0 replies; 4+ messages in thread
From: Dave Williss @ 2002-09-27  7:27 UTC (permalink / raw)
  To: gcc-help


From: "Ciaran O'Riordan" <ciaran_o_riordan@hotmail.com>


>
> >From: "Shuki Sasson" <shuki_sasson@hotmail.com>
> >
> >Hi all, I came across a problem with the optimizer (-O option) the -O0
> >option get rid of the problem.
> >A question:
> >Can one instruct the gcc compiler to turn option on/off within the
compiled
> >code?
>
> No.  Optimisation is a one-way function.
>
> If you have an expression in your code "(1 + 1)" the optimiser will
> replace this with "2".  The compiled program does not know that the
> programmer typed "(1 + 1)".  I know your talking about more complex
> code but the principle is the same.
>
> You'll have to recompile if you want to change the optimisations.
> If the problem occurs when you use "gcc -O", try -O2, -O3 or -Os.
> If the problem doesn't go away try specifying the optimisation
> switches yourself i.e. gcc -fforce-mem -fomit-frame-pointer (etc.)
>
> Hope this helps
>
I don't think that's what Shuki meant by turning optimization on and off.
He doesn't want to reverse an optimization, just disable it.

Some compilers let you use #pragma directives to disable optimizations
at the function level so that it _doesn't_ collapse "(1 + 1)" into "2".
Again,
that's just the trivial example.

Gcc is almost totally devoid of #pragmas, at least in 2.95.  I don't know
about the current version.  I would definitely like to see some though.

We have a library of several hundred modules that is compiled nightly
by an automated build script (run via cron) on several platforms.  It just
so happens that two of the modules need to be compiled for no optimization
on one platform (Mac OS X) or they cause programs to crash.  If we
could use #ifdefs to #pragma the optimizations out in the source, it would
be a lot easier than mucking around with the script that builds the
makefile.

----
Dave Williss
MicroImages, Inc.
perl -e 'print$i=pack(c5,(41*2),sqrt(7056),(unpack(c,H)-2),oct(115),10);'


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Controlling the compile within the compiled file?
@ 2002-09-26 20:19 Ciaran O'Riordan
  2002-09-27  7:27 ` Dave Williss
  0 siblings, 1 reply; 4+ messages in thread
From: Ciaran O'Riordan @ 2002-09-26 20:19 UTC (permalink / raw)
  To: shuki_sasson; +Cc: gcc-help


>From: "Shuki Sasson" <shuki_sasson@hotmail.com>
>
>Hi all, I came across a problem with the optimizer (-O option) the -O0 
>option get rid of the problem.

what is the problem with the optimizer?

>A question:
>Can one instruct the gcc compiler to turn option on/off within the compiled 
>code?

No.  Optimisation is a one-way function.

If you have an expression in your code "(1 + 1)" the optimiser will
replace this with "2".  The compiled program does not know that the
programmer typed "(1 + 1)".  I know your talking about more complex
code but the principle is the same.

You'll have to recompile if you want to change the optimisations.
If the problem occurs when you use "gcc -O", try -O2, -O3 or -Os.
If the problem doesn't go away try specifying the optimisation
switches yourself i.e. gcc -fforce-mem -fomit-frame-pointer (etc.)

Hope this helps

Ciaran O'Riordan

_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Controlling the compile within the compiled file?
@ 2002-09-25 15:55 Shuki Sasson
  0 siblings, 0 replies; 4+ messages in thread
From: Shuki Sasson @ 2002-09-25 15:55 UTC (permalink / raw)
  To: gcc-help



Hi all, I came across a problem with the optimizer (-O option) the -O0 
option get rid of the problem.
We are relying on the optimization for getting the best performance.

A question:
Can one instruct the gcc compiler to turn option on/off within the compiled 
code?


Thanks for the help,
Shuki

_________________________________________________________________
Join the worldÂ’s largest e-mail service with MSN Hotmail. 
http://www.hotmail.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2002-09-27 16:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-09-27  9:16 Controlling the compile within the compiled file? Ciaran O'Riordan
  -- strict thread matches above, loose matches on Subject: below --
2002-09-26 20:19 Ciaran O'Riordan
2002-09-27  7:27 ` Dave Williss
2002-09-25 15:55 Shuki Sasson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).