public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely.gcc@gmail.com>
To: Robert Matusewicz <matekm@gmail.com>
Cc: gcc-help <gcc-help@gcc.gnu.org>
Subject: Re: Playing with devirtualization in g++4.9
Date: Wed, 02 Apr 2014 17:04:00 -0000	[thread overview]
Message-ID: <CAH6eHdTgAZ3u-W=d3FOFrf1hrOK_U3Xbs1+5rFzUQtR4TC_xFA@mail.gmail.com> (raw)
In-Reply-To: <533C3FA1.1000305@gmail.com>

On 2 April 2014 17:49, 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

You can't turn on individual optimisations with just -fxxx switches.

If you don't enable optimisation with -On for n > 0 then no
optimisations happen, so you need at least -O -fdevirtualisation

> 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 don't know whether devirtualisation will actually stop the vtable
being emitted into the executable, or whether it just avoids
indirecting through the vtable for the call.

  reply	other threads:[~2014-04-02 17:04 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 [this message]
2014-04-02 17:05   ` Jonathan Wakely
2014-04-03 12:46 ` Markus Trippelsdorf

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='CAH6eHdTgAZ3u-W=d3FOFrf1hrOK_U3Xbs1+5rFzUQtR4TC_xFA@mail.gmail.com' \
    --to=jwakely.gcc@gmail.com \
    --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).