Functions attributes can be specified only for function declaration (not definition). So, I can't specify attributes for nested function. For example:
//invalid line. hot_nested_function is invisible outside "some_function"
void hot_nested_function() __attribute__ ((hot));
//valid attribute for declaration
int some_function() __attribute__ ((hot));
int some_function(){
void hot_nested_function(){
//time critical code
}
for( int i=0; i<REPEAT_MANY_TIMES;i++)
hot_nested_function();
}
In such case, will be "hot_nested_function" optimized as "hot"?
UPD: On a dumb example, gcc (means gcc -O1
and higher optimisation level) replaces function calls by its body, for both of with and without __attribute__ ((hot))
(for nested function). Even nothing reminds about nested function.
UPD2: According to gcc.git/gcc/tree-nested.c, it resolves parent function references, external label jumps and so on. At next stage nested functions transforms to independent functions with inlining ability. But it is still unclear about parent function's attributes. Did they applying to nested?