Various C / C++ compilers have #pragma
s to control optimization.
For example:
CodeWarrior
#pragma optimization_level 0
void func_no_opt()
{
// Some Work - not optimized
}
#pragma optimization_level 3
void func_full_opt()
{
// Some Work - optimized
}
MSVC
#pragma optimize("g", off)
void func_no_opt()
{
// Some Work - not optimized
}
#pragma optimize("g", on)
void func_full_opt()
{
// Some Work - optimized
}
#pragma optimize("", on)
void func_default_opt()
{
// Some Work - default optimizations
}
For purely performance reasons, I have a couple of functions that need to be optimized in all builds, including debug builds that are otherwise not optimized.
Is there a way in GCC (specifically 4.1.1) to do something similar to these other compilers? Unfortunately, GCC 4.4 is not supported on my target platform (proprietary hardware) so I can not use the optimize attribute -- i.e. __attribute__((optimize(...)))
.
Also, on the toolchain for this target platform, there is an auto-bulk-build tool; so it's also not possible to just split the functions off into a separate file and change the optimization parameters, since files within a project can be automatically combined for an increase in compilation and link speeds. I would have to make a separate library of just those functions and have it be linked-in in order to do the split-off method. This might be quite a bit more pain than it would be worth -- especially if there is a simpler method of accomplishing this.