Chapter 7 Code Optimization
AutoCode Reference 7-4 ni.com
iinfo[1] = 0;
}
return;
EXEC_ERROR: ERROR_FLAG[1] = iinfo[0];
iinfo[0]=0;}}
AutoCode performs this optimization only if it is safe to do so. There
could be circumstances that could potentially prevent this optimization
from taking place. AutoCode looks for the presence of a
write-to-the-same-variable block between the Read from Variable block
statement and its use in later computations. AutoCode does not optimize
variable blocks under these circumstances, as doing so would change the
meaning of the program.
The subsystem code in Example 7-1 actually uses two global variable
blocks, namely var and var1. Example7-2 shows the code generated with
global variable block optimization turned on. While variable block var1
is used directly in the summation block computation, an extra variable
new_11_1 is used for the variable block var. This is because there is a
Write to Variable block (modifying var) present in between the Read from
Variable block and its use in a summation block.
Optimization of local and global variables can be controlled independently.
The command-line arguments -Olvarblk and -Ogvarblk bring about the
optimization of extra variables associated with the Read from local and
global variable blocks, respectively.
Notice that the global variable block optimization will work only if they are
not shared between subsystems or only if the -vbco option is not used.
The following items could prevent AutoCode from optimizing Read from
Variable blocks.
• Presence of Write to the same variable block in between a Read from
Variable block and its use.
• Existence of a Procedure SuperBlock (Writing to the variable block)
between the Read from Variable block and its use.
• A dynamic block is connected to a Read from Variable block, and there
is a Write to same variable block in the subsystem (or procedure).
Since state UPDATE is done toward the end of the subsystem, the
Write to Variable block comes in between the Read from Variable
block and its use (in the state update).
• A Read from Variable block is outside a while loop, and the block
reading this variable block is inside the loop. The loop also contains a