Eliminate superfluous local variables (Expression folding)
Specify to fold expressions into single expression
Model Configuration Pane: Code Generation / Optimization
Description
The Eliminate superfluous local variables (Expression folding) parameter specifies whether to collapse block computations into single expressions instead of generating separate code statements and storage declarations for each block in the model.
Expression folding optimizes code to minimize the computation of intermediate results at block outputs and the storage of such results in temporary buffers or variables. Expression folding improves the efficiency of generated code, frequently achieving results that compare favorably to hand-optimized code. In many cases, entire groups of model computations fold into a single, highly optimized line of code.
You can use expression folding in your own inlined S-function blocks. For more information, see S-Functions That Support Expression Folding.
Category: Optimization
Dependencies
This parameter is enabled by Signal storage reuse.
Settings
on (default) | off- On
Enables expression folding.
Eliminates local variables, incorporating the information into the main code statement.
Improves code readability and efficiency.
- Off
Disables expression folding.
Examples
Recommended Settings
| Application | Setting |
|---|---|
| Debugging | Off |
| Traceability | No impact for simulation or during development Off for production code generation |
| Efficiency | On |
| Safety precaution | No impact |
Programmatic Use
Parameter: ExpressionFolding |
| Type: character vector |
Value: 'on' | 'off' |
Default: 'on' |
Version History
Introduced before R2006a
