delorie.com/archives/browse.cgi | search |
From: | "Ben Peddell" <lightspeed85 AT hotmail DOT com> |
Newsgroups: | comp.os.msdos.djgpp,gnu.gcc.help,gnu.utils.help |
References: | <b54db9$252aq3$1 AT ID-79865 DOT news DOT dfncis DOT de> <Oejda.183$Zf2 DOT 42 AT read3 DOT inet DOT fi> <b568o6$258tun$1 AT ID-79865 DOT news DOT dfncis DOT de> |
Subject: | Re: gcc -O3 & gprof |
Lines: | 93 |
X-Priority: | 3 |
X-MSMail-Priority: | Normal |
X-Newsreader: | Microsoft Outlook Express 5.00.2615.200 |
X-MimeOLE: | Produced By Microsoft MimeOLE V5.00.2615.200 |
Message-ID: | <yJQda.3290$dE2.7621@newsfeeds.bigpond.com> |
Date: | Tue, 18 Mar 2003 22:18:16 +1000 |
NNTP-Posting-Host: | 144.139.175.207 |
X-Trace: | newsfeeds.bigpond.com 1048041438 144.139.175.207 (Wed, 19 Mar 2003 13:37:18 EST) |
NNTP-Posting-Date: | Wed, 19 Mar 2003 13:37:18 EST |
Organization: | Telstra BigPond Internet Services (http://www.bigpond.com) |
To: | djgpp AT delorie DOT com |
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
Reply-To: | djgpp AT delorie DOT com |
Alex Vinokur <alexvn AT bigfoot DOT com> wrote in message news:b568o6$258tun$1 AT ID-79865 DOT news DOT dfncis DOT de... > > "Tauno Voipio" <tauno DOT voipio AT iki DOT fi DOT SPAMBAIT_REMOVE DOT invalid> wrote in message news:Oejda.183$Zf2 DOT 42 AT read3 DOT inet DOT fi... > > > > "Alex Vinokur" <alexvn AT bigfoot DOT com> wrote in message > [snip] > > > > > > ========= C code : BEGIN ========= > > > /* File main.c */ > > > > > > int foo1 (int argc) { return argc; } > > > int foo2 (int argc) { return argc; } > > > > The optimisation -O3 inlines simple functions (like yours here). There are > > no calls to trace. > [snip] > > How can we see that ? > For instance, nm doesn't distinguish -O0, -O1, -O2, -O3. > > ==================== > Windows 2000 > DJGPP 2.03 > GNU gcc/g++ version 3.2.1 > GNU nm 2.13 > ==================== > > gcc -o a0.exe main.c -g -pg > nm a0.exe | grep foo > 000016d0 T _foo1 > 000016e2 T _foo2 > > gcc -O1 -o a1.exe main.c -g -pg > nm a1.exe | grep foo > 000016d0 T _foo1 > 000016e2 T _foo2 > > gcc -O2 -o a2.exe main.c -g -pg > nm a2.exe | grep foo > 000016d0 T _foo1 > 000016f0 T _foo2 > > gcc -O3 -o a3.exe main.c -g -pg > nm a3.exe | grep foo > 000016f0 T _foo1 > 00001710 T _foo2 > > ================================= > Alex Vinokur > mailto:alexvn AT connect DOT to > http://www.simtel.net/pub/oth/19088.html > ================================= > > > Because you did not declare the functions static, they were still included as discrete functions in the output (so that other modules can access them). However, the compiler has also inlined copies of those functions in main() (since the functions were so simple). Your code: ========= C code : BEGIN ========= /* File main.c */ int foo1 (int argc) { return argc; } int foo2 (int argc) { return argc; } int main(int argc) { return (foo1(argc) + foo2(argc)); } ========= C code : END =========== is optimized by -O3 so that it appears to be: ========= C code : BEGIN ========= /* File main.c */ int foo1 (int argc) { return argc; } int foo2 (int argc) { return argc; } int main(int argc) { return ((argc) + (argc)); } ========= C code : END ===========
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |