Global data flow analysis
Based on the local information a compiler can perform some optimizations. For example, consider the following code:
Some optimization needs more global information. For example, consider the following code:
In this code, at line 3 the initial assignment is useless and x +1 expression can be simplified as 7.
But it is less obvious that how a compiler can discover these facts by looking only at one or two consecutive statements. A more global analysis is required so that the compiler knows the following things at each point in the program:
Data flow analysis is used to discover this kind of property. The data flow analysis can be performed on the program's control flow graph (CFG).
The control flow graph of a program is used to determine those parts of a program to which a particular value assigned to a variable might propagate.