From: Markus Trippelsdorf <markus@trippelsdorf.de>
To: Robert Matusewicz <matekm@gmail.com>
Cc: gcc-help@gcc.gnu.org
Subject: Re: Playing with devirtualization in g++4.9
Date: Thu, 03 Apr 2014 12:46:00 -0000 [thread overview]
Message-ID: <20140403124616.GA2703@x4> (raw)
In-Reply-To: <533C3FA1.1000305@gmail.com>
On 2014.04.02 at 18:49 +0200, Robert Matusewicz wrote:
>
> I found that g++4.9.0 have -fdevirtualize switch and wanted to play with
> that feature for a while. I wrote simple, non-trivial program to check
> how g++ will behave in obvious case:
>
> ==== SOURCE BEGIN ====
> #include <iostream>
>
> class B final
> {
> public:
> virtual void test() { std::cout << "Test" << std::endl; }
> };
>
> int main()
> {
> B test;
> test.test();
> return 0;
> }
> ==== SOURCE ENDS ====
>
> I compiled this code with
>
> g++ -std=c++11 -fdevirtualize simple1.cpp
>
> and then objdumped symbols:
>
> objdump -t a.out | c++filt | grep vtable
>
> and noticed that vtable is present (I would expect it will be removed)
> 00000000006012c0 w O .bss 0000000000000058 vtable for
> __cxxabiv1::__class_type_info@@CXXABI_1.3
> 0000000000400b20 w O .rodata 0000000000000018 vtable for B
>
>
> I found some examples in testsuite (opt/ and ipa/) but for those
> examples I checked, I can "reproduce" devirtualization.
>
> Is there a documentation somewhere to see what is the current status of
> devirtualiztion in g++ 4.9? I mean, beside the source code. Or maybe
> someone could explain me why this case can't be devirtualized?
The best documentation is a series of blog posts from Honza, who
implemented the devirtualization machinery:
http://hubicka.blogspot.com/2014/01/devirtualization-in-c-part-1.html
http://hubicka.blogspot.com/2014/01/devirtualization-in-c-part-2-low-level.html
http://hubicka.blogspot.com/2014/02/devirtualization-in-c-part-3-building.html
http://hubicka.blogspot.com/2014/02/devirtualization-in-c-part-4-analyzing.html
As for your example, if you replace std::endl with "\n" gcc will
devirtualize the member function.
--
Markus
prev parent reply other threads:[~2014-04-03 12:46 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-02 16:49 Robert Matusewicz
2014-04-02 17:04 ` Jonathan Wakely
2014-04-02 17:05 ` Jonathan Wakely
2014-04-03 12:46 ` Markus Trippelsdorf [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140403124616.GA2703@x4 \
--to=markus@trippelsdorf.de \
--cc=gcc-help@gcc.gnu.org \
--cc=matekm@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).