Constant propagation, Constant propagation -13 – National Instruments AutoCode NI MATRIX User Manual

Page 204

Advertising
background image

Chapter 7

Code Optimization

© National Instruments Corporation

7-13

AutoCode Reference

}

Y->model_5_1 = X->model_5_S1;

/* ---------------------------- Gain Block */

/* {model..2} */

model_2_1 = 2.0*U->model_1;

/* ---------------------------- Sum of Vectors */

/* {model..3} */

model_3_1 = model_2_1 - U->model_1;

/* ---------------------------- Gain Block */

/* {model..4} */

model_2_1 = 3.0*model_3_1;

/***** State Update. *****/

/* ---------------------------- Time Delay */

/* {model..5} */

XD->model_5_S1 = model_2_1;

In Example 7-7 (code generated without reuse option), each block has a
distinct and unique output variable. In Example 7-8 (code generated with
the maximal reuse option), the variable

model_2_1

, which is the output

variable for the block

model..2

, is used only in the computation for block

model..3

. It is free to be used again after the computation for

model..3

is complete, and in fact the generated code reuses the variable

model_2_1

as the output variable of the block

model..4

.

Constant Propagation

AutoCode supports an option to propagate constants in the generated
code. Source of constants in a model are typically algebraic and logical
expression blocks. For the sake of this optimization, you can partition all
of the blocks into two categories.

Blocks that can propagate constants

Blocks that cannot propagate constants

Most of the blocks from palettes such as ALG, PWL, LOG, TRG, and PEL,
belong to the first category (propagate constants), and if all of the inputs to
such blocks are constants, the output value is computed during compile
time, and no code is generated for such a block. The blocks belonging to
the second category (cannot propagate constants), are from other palettes
such as DYN, SGN, and NTP. These blocks do not propagate outputs even
if all of their inputs are constants. Code is generated for such blocks.

Advertising