This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Playing with devirtualization in g++4.9
- From: Markus Trippelsdorf <markus at trippelsdorf dot de>
- To: Robert Matusewicz <matekm at gmail dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Thu, 3 Apr 2014 14:46:16 +0200
- Subject: Re: Playing with devirtualization in g++4.9
- Authentication-results: sourceware.org; auth=none
- References: <533C3FA1 dot 1000305 at gmail dot 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