Question about GCC's inliner

Lorenzo Binosi lorenzo.binosi@mail.polimi.it
Tue Nov 3 17:13:43 GMT 2020


Hi everyone,

I'm working on a project which goal is to recognize inlined methods of classes with templates(like vector, map, etc) when compiled with some optimizations(-O2, -O3, -Os). I'm figuring out and trying different heuristics in order to achieve this goal. At the moment what i'm trying to do is to understand which are the methods/functions that could be inlined or not inside a public method. For instance, let's consider the function "push_back" of the "vector" class:

void push_back(const value_type& __x)
{
    if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
    {
         _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish, __x);
         ++this->_M_impl._M_finish;
    }
    else
         _M_realloc_insert(end(), __x);
}

this method can call three different function:

  *    _Alloc_traits::construct: static function
  *   _M_realloc_insert: private method
  *   end(): very small function

The function end() is a very very small(making a call will lead to more space and more instructions) and i'm pretty sure the GCC's inliner always consider to inline it. Thus, i'm pretty sure i will never see the function call to the end() method, and so that part of the CFG will never change. However, the function _M_realloc_insert may be inlined or not depending of many aspects(how much time is called in different functions, if it's called once, how many istructions does it contains, etc). Finally, what i would like to get from GCC is a "report" of which functions are eligible to inlining, but not the ones that will be inlined for sure.

Googling i found an option which is "-fdump-ipa-inline-optimized". Compiling a simple .cpp like this one

#include <vector>
#include <stdio.h>

int main(int argc, char const *argv[])
{
    puts("Dummy main\n");
    return 0;
}

void wrapper(vector<int> obj, const std::vector<int>::value_type &p_1)
{
    obj.push_back(p_1);
}

with the command

g++ -O3 -fdump-ipa-inline-optimized main.cpp -o main

I get a debug file which is not clear for me, but i think is related to the GCC's inliner. It mentions which functions are inlinable along with scores, frequencies, summary, etc...
However, it doesn't mention the function "end()" and the function "_Alloc_traits::construct()". My questions finally are: can i safely consider that these functions are always inlined(considering always the same template which is, in this case, a 32 bit integer) in any program? If the previous answer is no, is there any way to get such result?

I know this is a complex topic and it really depends by the type of the template(s) and how the program is made, but i would like to understand if i can work under some assumptions(in this case the assumption is "always the same template").

Thank you  very much for your time.


More information about the Gcc-help mailing list