Restrict inlining when:
The size of generated code exceeds desired limits
due to excessive inlining of functions. Suppose that you include the
statement, coder.inline('always')
, inside a certain
function. You then call that function at many different sites in your
code. The generated code can be large due to the function being inlined
every time it is called.
The call sites must be different. For instance, inlining does not lead to large code if the function to be inlined is called several times inside a loop.
You have limited RAM or stack space.
You can use the MATLAB® Coder™ app or the command-line interface to control the maximum size of functions that can be inlined. The function size is measured in terms of an abstract number of instructions, not actual MATLAB instructions or instructions in the target processor. Experiment with this parameter to obtain the inlining behavior that you want.
Using the app, in the project settings dialog box, on the All Settings tab, set the value of the field, Inline threshold, to the maximum size that you want.
At the command line, create a codegen
configuration
object. Set the value of the property, InlineThreshold
,
to the maximum size that you want.
cfg = coder.config('lib');
cfg.InlineThreshold = 100;
Generate code using this configuration object.
You can use the MATLAB Coder app or the command-line interface to control the maximum size of functions after inlining. The function size is measured in terms of an abstract number of instructions, not actual MATLAB instructions or instructions in the target processor. Experiment with this parameter to obtain the inlining behavior that you want.
Using the app, in the project settings dialog box, on the All Settings tab, set the value of the field, Inline threshold max, to the maximum size that you want.
At the command line, create a codegen
configuration
object. Set the value of the property, InlineThresholdMax
,
to the maximum size that you want.
cfg = coder.config('lib');
cfg.InlineThresholdMax = 100;
Generate code using this configuration object.
Specifying a limit on the stack space constrains the amount
of inlining allowed. For out-of-line functions, stack space for variables
local to the function is released when the function returns. However,
for inlined functions, stack space remains occupied by the local variables
even after the function is executed. The value of the property, InlineStackLimit
,
is measured in bytes. Based on information from the target hardware
settings, the software estimates the number of stack variables that
a certain value of InlineStackLimit
can accomodate.
This estimate excludes possible C compiler optimizations such as putting
variables in registers.
You can use the MATLAB Coder app or the command-line interface to control the stack size limit on inlined functions.
Using the app, in the project settings dialog box, on the All Settings tab, set the value of the field, Inline stack limit, to the maximum size that you want.
At the command line, create a codegen
configuration
object. Set the value of the property, InlineThresholdMax
,
to the maximum size that you want.
cfg = coder.config('lib');
cfg.InlineStackLimit = 2000;
Generate code using this configuration object.