DataflowAnalysis is a form of StaticAnalysis? of programs,
wherein the possible sources of values for variables are tracked and correlated.
This sort of analysis can lead to significant compile-time optimizations
by recognizing and exploiting
incidental commonalities among all the value sources.
Optimizations from DataflowAnalysis most commonly include entirely
avoiding runtime checks for operator validity.
Some examples:
- Null pointer checks can be avoided if the variable cannot have changed since the last time the it was checked for being null. Similarly if it cannot have changed since it was given a known non-null value.
- Range checks on numeric types can be avoided if the variable cannot have changed since an equally or more strict range check was done. (If I already checked j > 5, then the check j > 2 can be skipped.)
- Runtime type checks can be avoided (in languages that have them) if a value of known type if cast to a supertype and then back to the original.
Dataflow optimizations usually result in various amounts of code being omitted
from the compiled form of the program.
In extreme cases, entire blocks or methods can be omitted
if the compiler can prove that they are unreachable.
DesignByContract can dramatically increase the usefulness of DataflowAnalysis.