Giving hints to the compiler/optimizer (#pragma hint ...)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,
it would be nice to have a mechanism to let the programmer give hints to the compiler/optimizer.

Example:

for (size_t i = 1; i < vec.size(); ++i)
  ...

If the size of vec cannot change while in this code block, then one better would do this instead:

{
const size_t vec_sz = vec.size();
for (size_t i = 1; i < vec_sz; ++i)
  ...
}


But, IMO it would be much better if one could just give a hint to the compiler/optimizer instead:

#pragma hint const vec.size()
for (size_t i = 1; i < vec.size(); ++i)
  ...

Then the compiler/optimizer could cache the vec.size(), ie. fill a const (register) variable just once and use that instead, like in the previous manual version. (The manual version has of course the disadvantage that user has to define an additional variable and because of that, put the code in its own scope...)

So, passing such hints to the compiler/optimizer is IMO a good general way.
Would be nice if the gcc developers would implement such a mechanism.

Technically: such a "#pragma hint ..." would apply just to the next line of code, ie. automatically 'unhinting'.





[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux