This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
To improve readability I wrapped some code in an interrupt in a function. I don't want the overhead of calling the function from the interrupt, so I put the function in the same C file, and declared the function as inline. However, whenever I compile the advice window tells me I should inline the function. I have tried using "__inline" as well as "inline", and I still get the same advice. I also made sure there are no calls to other functions inside the inlined functions. The following is the function:
inline void UartRecvByte(void);
...
inline void UartRecvByte(void)
{
...
//Do stuff
...
}
Is this function inlined, and should I just ignore the advice, or is something possibly preventing the function from being inlined?
The compiler inlines functions only when you build with optimization. What compiler are you using? Please show the build options as the compiler sees them.
Thanks and regards,
-George
Please see the section titled Using Inline Function Expansion in the MSP430 compiler manual.
Thanks and regards,
-George
In this case, the advice message should be enhanced to suggest enabling the optimizer. This is a usability issue.
Regarding inlining versus the optimization level, it works more like the following. (Note: this is a bit simplified.) Will a function be inlined?
opt level | inline keyword used | inline keyword not used |
---|---|---|
off | no | no |
0 | maybe | no |
1 | maybe | no |
2 | maybe | no |
3 | maybe | maybe |
4 | maybe | maybe |
Unfortunately, there is some muddled wording in section 2.11 of the compiler manual.
To expand on the table above: the optimiser stage of the compiler is where inlining happens, therefore you must use at least -o0 if you want inlining. Inlining of functions declared inline is not affected by optimisation for speed; the only reason the compiler will decline to inline such a function is if it thinks it risks crashing the compiler due to excessive function size.
Inlining for MSP (and C2000, but not C6000 or ARM) is complicated by an internal restriction that either all calls to a function be inlined, or none of them; it can't do just some. That's one motivation for the FUNC_ALWAYS_INLINE pragma, to override the compiler's estimate of risk. Of course, if the compiler does crash, the first suggestion will be to remove that pragma.
Auto-inlining does depend on optimisation level and optimisation for speed (and the size specified by --auto_inline) -- the compiler is picking functions that the user didn't indicate, and trying to improve speed while not costing too much in code size. We don't want that to happen by surprise, and there should be some control, hence the limits and restrictions.
Yes, the compiler shouldn't give confusing advice; we need to clean that up. Thanks for bringing the advice and documentation problems to light.