Intel® ISA Extensions
Use hardware-based isolation and memory encryption to provide more code protection in your solutions.

symbol information of icc with -O2 flag

Shilpa_B_
Beginner
626 Views

Hi I am using Pin-3.7 tool and would like to instrument a specific part of my code (Loop structure). As I was not able to mark the region of code of interest, I placed the code to be instrumented in a function (say "myfunc") and called it from the main.

I am using icc-19.0 compiler to compile my test program and using insmix.so tool to get the instruction mix count, which lists these counts function wise.

Just using icc with -g flag lists the instruction mix count of main function and "myfunc". However, when I compile test program using icc with -g -O2/-O3 the instruction mix counts are listed only for main function not for "myfunc".

So is the symbol information about the function lost with -O2/-O3 flag? What am I missing?

Is there any other way to instrument only a part of the code? say by marking a region.

Thanks,

Shilpa

0 Kudos
2 Replies
James_C_Intel2
Employee
626 Views

So is the symbol information about the function lost with -O2/-O3 flag? What am I missing?

If you simply moved your code of interest into a static function in the same source file as main, it's entirely possible that the compiler inlined it when you compile with optimization enabled (which does rather destroy the point of what you were trying to do!). 

There are a number of ways to prevent this

  1. Make your function extern, and put it into another file (so that the compiler cannot see it when it's compiling the caller).
  2. Give the function the __attribute__((noinline))
  3. Put #pragma noinline at the call site

https://godbolt.org/z/DpAkWM shows an example of using method 2. 

0 Kudos
Shilpa_B_
Beginner
626 Views

Thank you for the reply. Yes indeed the compiler was inlining the function. Using __attribute__((noinline)) for the function solved the problem.

Thanks again,

Shilpa

0 Kudos
Reply