Search code examples
c++profilingcompiler-optimizationiccinlining

Force creation of method on intel compiler with optimization level 3


Working on a +95% C++ 11 code (the rest is C) that is generally used compiled w/ optimization level 3 we profiled it and found a really time-consuming method.

Toy code:

myClass::mainMethod()
{
    // do stuff here
    / ...
    // do more stuff here
    / ...
}

We splitted its inner sections into other methods in order to precisely measure which is the problematic part, e.g.

myClass::mainMethod()
{
    this->auxiliaryMethod1();
    this->auxiliaryMethod2();
}
myClass::auxiliaryMethod1()
{
    // do stuff here
    // ...
}
myClass::auxiliaryMethod2()
{
    // do more stuff here
    // ...
}

But the (intel) compiler is smart enough to notice this only usage and assemble it back together into a single method.

Besides this two obvious other possible solutions, i.e. compiling without optimization (irrealistic) and adding other spurious usages (a wasteful process), is there an intel compiler flag to indicate "please explicitly code this method into the class"???

Thanks!


Solution

  • As the comments suggested, splitting with attribute noinline did the trick.

    void __attribute__((noinline)) myClass::mainMethod()
    {
        this->auxiliaryMethod1();
        this->auxiliaryMethod2();
    }
    void __attribute__((noinline)) myClass::auxiliaryMethod1()
    {
        // do stuff here
        // ...
    }
    void __attribute__((noinline)) myClass::auxiliaryMethod2()
    {
        // do more stuff here
        // ...
    }