I have a function which does just few operations such as increments. I have declared that as inline
and with the __attribute__((hot))
.
Gcc Doc suggests following for hot
attribute:
The hot attribute is used to inform the compiler that a function is a hot spot of the compiled program. The function is optimized more aggressively and on many target it is placed into special subsection of the text section so all hot functions appears close together improving locality.
which can be interpreted as for non inline
hot functions they would be placed in lower address area of the process address map. But inline
functions calls are supposed be literally replaced by their code. So question is how does combination of inline
and hot
really works ?
See When should I write the keyword 'inline' for a function/method? for a pretty good explanation of the inline
keyword. It seems like a contradiction to declare a function as hot
and inline
; if the function is not defined in a header file, or is not defined in multiple compilation units then you should not declare it as inline
.
Indeed, the decision to replace the function call with the function definition and place it "in-line" is up to the compiler. So the combination of inline
and hot
likely just ignores the inline
part and places it in the text.hot
section of the program. The linker is the only part of the process that really cares about the inline
keyword, and then it doesn't necessarily do what you might think it does.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With