Information Technology Reference
In-Depth Information
for ( i = 1; i < = 100; i ++ ) { x = a × 100; y = y + i ; }
(a) A source loop
t = a × 100; for ( i = 1; i < = 100; i ++ ) { x = t ; y = y + i ; }
(b) The resulting code
FIGURE 17.6
Loop invariant example.
However, a loop induction variable elimination reduces the execution time by mov-
ing instructions from frequently executed program regions to infrequently executed
program regions (Chang, et al., 2006).
Induction variables are variables in a loop incremented by a constant amount
each time the loop iterates, and replaces the uses of an induction variable by another
induction variable, thereby eliminating the need to increment the variable on each
iteration of the loop. If the induction variable eliminated is needed after the loop is
exited, then its value can be derived from one of the remaining induction variables.
The following is an example of loop induction elimination in which the variable i is
the induction variable of the loop:
for (i=1,i < =10;i++)
a[i+1]=1;
an optimized version is
for (i=2,i < =11;i++)
a[j] = 1;
17.7.6
Removal of Dead Code
Another simple and easy way to decrease memory requirements in a system is through
the removal of dead code. Dead code is unnecessary, inoperative code. 36 Some types
of dead code are dead procedures, dead variables, dead parameters, dead return
values, dead event declarations, dead enumeration values, dead user-defined types,
dead classes, dead modules, and dead control.
A dead procedure is not called by any other procedure, which means that it is never
executed and is not required for any purpose. A dead variable is not read nor written.
It is completely useless, only taking up memory and a line or two of code. A dead
parameter is passed to a procedure but is not used by it. Passing parameters takes a
little bit of time during each call. Dead parameters can make a program slower. A
dead return value of a function is not stored or used by any of the callers. A dead event
does not fire, and a semidead event does not fire and its handlers are not executed. A
dead enumeration or constant value is not required by the program. A user-defined
type is a structure or record of one that is not used anywhere. A dead class is not used
36 http://www.aivosto.com/vbtips/deadcode.html
 
Search WWH ::




Custom Search