What is the method for optimizing individual functions in a file in GCC 4.1.1?

Various C / C ++ compilers have #pragmaoptimization controls.

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 features 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 cannot use the optimize attribute - ie __attribute__((optimize(...))).

, toolchain ; , . , . , , .

+3
2

, __attribute__((optimize(...))) - GCC. , GCC 4.1.1, , .

+4

GCC 4.4 , http://gcc.gnu.org/onlinedocs/gcc/Function-Specific-Option-Pragmas.html#Function-Specific-Option-Pragmas

#pragma GCC push_options
#pragma GCC optimize ("-O0")
int foo() {
  return bar;
}
#pragma GCC pop_options
+2

Source: https://habr.com/ru/post/1707905/


All Articles