LTO, Devirtualization, and Virtual Tables

前端 未结 4 1016
难免孤独
难免孤独 2020-12-01 12:34

Comparing virtual functions in C++ and virtual tables in C, do compilers in general (and for sufficiently large projects) do as good a job at devirtualization?

Naive

4条回答
  •  猫巷女王i
    2020-12-01 13:22

    It depends on what you are comparing compiler inlining to. Compared to link time or profile guided or just in time optimizations, compilers have less information to use. With less information, the compile time optimizations will be more conservative (and do less inlining overall).

    A compiler will still generally be pretty decent at inlining virtual functions as it is equivalent to inlining function pointer calls (say, when you pass a free function to an STL algorithm function like sort or for_each).

提交回复
热议问题