Iterative-free program analysis

Program analysis is the heart of modern compilers. Most control flow analyses are reduced to the problem of finding a fixed point in a certain transition system, and such fixed point is commonly computed through an iterative procedure that repeats tracing until convergence.This paper proposes a new method to analyze programs through recursive graph traversals instead of iterative procedures, based on the fact that most programs (without spaghetti GOTO) have well-structured control flow graphs, graphs with bounded tree width. Our main techniques are; an algebraic construction of a control flow graph, called SP Term, which enables control flow analysis to be defined in a natural recursive form, and the Optimization Theorem, which enables us to compute optimal solution by dynamic programming.We illustrate our method with two examples; dead code detection and register allocation. Different from the traditional standard iterative solution, our dead code detection is described as a simple combination of bottom-up and top-down traversals on SP Term. Register allocation is more interesting, as it further requires optimality of the result. We show how the Optimization Theorem on SP Terms works to find an optimal register allocation as a certain dynamic programming.

[1]  Maarten M. Fokkinga Tupling and Mutumorphisms , 1989 .

[2]  Jeffrey D. Ullman,et al.  Characterizations of Reducible Flow Graphs , 1974, JACM.

[3]  Erik Poll,et al.  Algebra of Programming by Richard Bird and Oege de Moor, Prentice Hall, 1996 (dated 1997). , 1999 .

[4]  Hartmut Schmeck,et al.  Algebraic Characterization of Reducible Flowcharts , 1983, J. Comput. Syst. Sci..

[5]  Sampath Kannan,et al.  Register allocation in structured programs , 1995, SODA '95.

[6]  Katsuro Inoue,et al.  XML Detabase for Program Analysis Information. , 2002 .

[7]  Mizuhito Ogawa,et al.  Derivation of a Linear Algorithm for Mining Optimized Gain Association Rules , 2002 .

[8]  David A. Schmidt Data flow analysis is model checking of abstract interpretations , 1998, POPL '98.

[9]  Mikkel Thorup,et al.  All Structured Programs have Small Tree-Width and Good Register Allocation , 1998, Inf. Comput..

[10]  Frances E. Allen,et al.  Control-flow analysis , 2022 .

[11]  Hans L. Bodlaender,et al.  A linear time algorithm for finding tree-decompositions of small treewidth , 1993, STOC.

[12]  Jens Gustedt,et al.  Linear-time register allocation for a fixed number of registers , 1998, SODA '98.

[13]  Tim Sheard,et al.  Revisiting catamorphisms over datatypes with embedded functions (or, programs from outer space) , 1996, POPL '96.

[14]  Mizuhito Ogawa,et al.  Make it practical: a generic linear-time algorithm for solving maximum-weightsum problems , 2000, ICFP '00.

[15]  Bruno Courcelle,et al.  Graph expressions and graph rewritings , 1987, Mathematical systems theory.

[16]  Paul D. Seymour,et al.  Graph Minors. II. Algorithmic Aspects of Tree-Width , 1986, J. Algorithms.

[17]  Bruno Courcelle,et al.  An algebraic theory of graph reduction , 1993, JACM.

[18]  Bruno Courcelle,et al.  Graph Rewriting: An Algebraic and Logic Approach , 1991, Handbook of Theoretical Computer Science, Volume B: Formal Models and Sematics.

[19]  Richard S. Bird Maximum marking problems , 2001, J. Funct. Program..

[20]  Masato Takeichi,et al.  Generation of Efficient Programs for Solving Maximum Multi-marking Problems , 2001, SAIG.

[21]  Akihiko Takano,et al.  Tupling calculation eliminates multiple data traversals , 1997, ICFP '97.

[22]  Martin Erwig,et al.  Functional programming with graphs , 1997, ICFP '97.

[23]  Bruce A. Reed,et al.  An Improved Algorithm for Finding Tree Decompositions of Small Width , 1999, WG.

[24]  Eric Van Wyk,et al.  Universal Regular Path Queries , 2003, High. Order Symb. Comput..

[25]  Nobuji Saito,et al.  Linear-time computability of combinatorial problems on series-parallel graphs , 1982, JACM.

[26]  Craig A. Tovey,et al.  Automatic generation of linear-time algorithms from predicate calculus descriptions of problems on recursively constructed graph families , 1992, Algorithmica.

[27]  Eric Van Wyk,et al.  Proving correctness of compiler optimizations by temporal logic , 2002, POPL '02.

[28]  Jens Gustedt,et al.  The Treewidth of Java Programs , 2002, ALENEX.

[29]  Bernhard Steffen,et al.  Data Flow Analysis as Model Checking , 1990, TACS.

[30]  Richard S. Bird,et al.  Algebra of programming , 1997, Prentice Hall International series in computer science.

[31]  Alfred V. Aho,et al.  Compilers: Principles, Techniques, and Tools , 1986, Addison-Wesley series in computer science / World student series edition.

[32]  Donald E. Knuth,et al.  An empirical study of FORTRAN programs , 1971, Softw. Pract. Exp..

[33]  Gregory J. Chaitin,et al.  Register allocation & spilling via graph coloring , 1982, SIGPLAN '82.