Restrict inlining when:
Generated code size limits are exceeded due to excessive inlining of functions. For example,
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 size increases because the function is inlined every time it
is called. However, the call sites must be different. For instance, inlining
does not lead to large code size if the function to be inlined is called
several times inside a loop.
You have limited RAM or stack space.
You can control inlining or disable inlining altogether. To disable inlining at the
command line, use the -O disable:inline
option of the
codegen
command. This option disables inlining for
all functions.
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 by 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 by 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
accommodate. 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 by using this configuration object.