coder.inline
Control inlining of a specific function in generated code
Description
coder.inline('always')
inlines
the current function in the generated code. Use the
coder.inline('always')
optimization directive to replace a function
call with the contents (body) of the called function. Inlining eliminates the overhead of a
function call and can create opportunities for further optimization of the generated C/C++
code. However, inlining can generate larger, more complex C/C++ code.
The coder.inline('always')
directive does not support the inlining
of:
entry-point functions.
recursive functions.
functions that contain
parfor
loops.functions called from
parfor
loops.
coder.inline('never')
prevents
inlining of the current function in the generated code. Use the
coder.inline('never')
directive when you want to simplify the mapping
between the MATLAB® source code and the generated code.
The coder.inline('never')
optimization directive does not prevent the
inlining of:
empty functions.
functions that return constant output.
To prevent inlining even in these situations, use the coder.ignoreConst
function on an input at the function call site in your
MATLAB code. For more information, see Resolve Issue: coder.inline('never') Does Not Prevent Inlining of Function.
coder.inline('default')
instructs the code generator to use
internal heuristics to determine whether to inline the current function. Usually, these
heuristics produce highly optimized code. Use coder.inline
explicitly in
your MATLAB functions only when you need to fine-tune these optimizations. For additional
guidelines, see Tips.
Examples
Tips
If you use the
codegen
or thefiaccel
(Fixed-Point Designer) command, you can disable inlining for all functions by using the-O disable:inline
option.If you generate C/C++ code by using the
codegen
command or the MATLAB Coder™ app, you might have different speed and readability requirements for the code generated for functions that you write and the code generated for MathWorks® functions. Certain additional global settings enable you to separately control the inlining behavior for these two parts of the generated code base and at the boundary between them. See Control Inlining to Fine-Tune Performance and Readability of Generated Code.
Extended Capabilities
Version History
Introduced in R2011a