Flow Grammars October 31, 1994 1 Flow grammars – a flow analysis methodology James S. Uhl and R. Nigel Horspool Dept. of Computer Science, University of Victoria P.O. Box 3055, Victoria, BC, Canada V8W 3P6 E-mail: juhl@csr.uvic.ca, nigelh@csr.uvic.ca Abstract: Flow grammars provide a new mechanism for modelling control flow in flow analyzers and code optimizers. Existing methods for representing control flow are inadequate in terms of both their generality and their accuracy. Flow grammars overcome these deficiencies and are well-suited to the specification and solution of data flow analysis problems. 1 Introduction Source programs must be subjected to sophisticated and extensive optimization to approach the full potential of modern computer architectures. Many powerful optimizations rely on static anal- ysis of the source code. Examples of such static analysis include: live variable analysis [7], vari- ous forms of constant propagation [10,20], and aliasing analysis [4]. All of these static analyses may be realized as instances of flow analysis problems. They share the following general frame- work [10]: 1. A model of the program defines points where information is to be determined, as well as how control may flow between those points at run-time. 2. A set of abstract states representing the desired static information is created. In the case of constant propagation, for example, each abstract state is a partial mapping from variable names to values. Generally this information space is a structured as a lattice or semi-lattice [5,10]. For some analyses, this set of states may even depend upon the structure of the model used to rep- resent the program [17]. 3. A set of flow equations relating the abstract state of the program at one point with the points that may immediately precede or follow it during execution. The goal is to find a least fix point solution to the set of equations. The solution is then used to guide the optimization process. This paper describes a new formalism which we call flow grammars, developed for use in the Flow Analysis Compiler Tool (FACT), an on-going research project at the University of Victoria