0

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!

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Gaston
  • 537
  • 4
  • 10
  • There is `noinline` attribute or `#pragma noinline`, try use one of them. – 273K May 09 '22 at 15:25
  • 1
    Splitting it with `__attribute__((noinline))` (or _declspec if ICC supports that too) might stop the compiler from optimizing between halves of the function, e.g. defeating value-range info, constant-propagation, or other optimizations. Keep that in mind when you look at what the two parts are actually doing. – Peter Cordes May 09 '22 at 15:48
  • 1
    While you're fussing over that, try [*this*](https://stackoverflow.com/a/378024/23771). – Mike Dunlavey May 10 '22 at 12:14

1 Answers1

0

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
    // ...
}
Gaston
  • 537
  • 4
  • 10