|
9.2.5 Application of Reaching DefinitionsNot all uses of data flow analysis involve code optimization. We can use reaching definitions to detect possible uses of variables before they have been defined. Detecting (at compile time) statements that use a variable before its definition is a useful debugging aid. To adapt reaching definitions to solve this: (i) Introduce a new dummy block D that contains a definition of each variable used in the program. (ii) Place D before the Start node. (iii) Compute reaching definitions. (iv) If any definition in D reaches B where the variable is used, then we have a use before a definition. In some languages, we should print a warning. In other languages, however, a default initial value may be assumed, and although a warning message could be issued, it would be incorrect not generate the code for the program. |