Code generation based on formal BURS theory and heuristic search

Abstract. BURS theory provides a powerful mechanism to efficiently generate pattern matches in a given expression tree. BURS, which stands for bottom-up rewrite system, is based on term rewrite systems, to which costs are added. We formalise the underlying theory, and derive an algorithm that computes all pattern matches. This algorithm terminates if the term rewrite system is finite. We couple this algorithm with the well-known search algorithm A $^*$ that carries out pattern selection. The search algorithm is directed by a cost heuristic that estimates the minimum cost of code that has yet to be generated. The advantage of using a search algorithm is that we need to compute only those costs that may be part of an optimal rewrite sequence (and not the costs of all possible rewrite sequences as in dynamic programming). A system that implements the algorithms presented in this work has been built.

[1]  Reinhard Wilhelm,et al.  Tree automata for code selection , 1994, Acta Informatica.

[2]  Helmut Emmelmann Code Selection by Regularly Controlled Term Rewriting , 1991, Code Generation.

[3]  Christopher W. Fraser,et al.  Engineering a simple, efficient code-generator generator , 1992, LOPL.

[4]  Roderic Geoffrey Galton Cattell,et al.  Formalization and Automatic Derivation of Code Generators , 1982 .

[5]  Robert Giegerich Code Selection by Inversion of Order-Sorted Derivors , 1990, Theor. Comput. Sci..

[6]  Susan L. Graham,et al.  A new method for compiler code generation , 1978, POPL '78.

[7]  Alfred V. Aho,et al.  Code generation using tree matching and dynamic programming , 1989, ACM Trans. Program. Lang. Syst..

[8]  Robert Steven Glanville,et al.  A Machine Independent Algorithm for Code Generation and Its Use in Retargetable Compilers , 1977 .

[9]  Christoph M. Hoffmann,et al.  Pattern Matching in Trees , 1982, JACM.

[10]  Jean-Pierre Jouannaud,et al.  Rewrite Systems , 1991, Handbook of Theoretical Computer Science, Volume B: Formal Models and Sematics.

[11]  Alfred V. Aho,et al.  Code-generation for machines with multiregister operations , 1977, POPL '77.

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

[13]  Thomas W. Christopher,et al.  High-quality code generation via bottom-up tree pattern matching , 1986, POPL '86.

[14]  Robert Giegerich,et al.  Code Selection Techniques: Pattern Matching, Tree Parsing, and Inversion of Derivors , 1988, ESOP.

[15]  Nils J. Nilsson,et al.  Principles of Artificial Intelligence , 1980, IEEE Transactions on Pattern Analysis and Machine Intelligence.

[16]  Stefan Kurtz,et al.  Narrowing and Basic Forward Closures , 1992 .

[17]  Dhananjay M. Dhamdhere,et al.  Efficient Retargetable Code Generation Using Bottom-up Tree Pattern Matching , 1990, Comput. Lang..

[18]  Keith Price,et al.  Review of "Principles of Artificial Intelligence by Nils J. Nilsson", Tioga Publishing Company, Palo Alto, CA, ISBN 0-935382-01-1. , 1980, SGAR.

[19]  K. John Gough Bottom-up tree rewriting tool MBURG , 1996, SIGP.

[20]  R. G. G. Cattell,et al.  Code generation in a machine-independent compiler , 1979, SIGPLAN '79.

[21]  Vipin Kumar,et al.  Search in Artificial Intelligence , 1988, Symbolic Computation.

[22]  W FraserChristopher,et al.  Engineering a simple, efficient code-generator generator , 1992 .

[23]  Robert E. Tarjan,et al.  More Efficient Bottom-Up Multi-Pattern Matching in Trees , 1992, Theor. Comput. Sci..

[24]  Bruce R. Schatz,et al.  An Overview of the Production-Quality Compiler-Compiler Project , 1980, Computer.

[25]  Todd A. Proebsting BURS automata generation , 1995, TOPL.

[26]  Thomas W. Christopher,et al.  Using dynamic programming to generate optimized code in a Graham-Glanville style code generator , 1984, SIGPLAN '84.

[27]  David R. Chase,et al.  An improvement to bottom-up tree pattern matching , 1987, POPL '87.

[28]  Joost-Pieter Katoen,et al.  Bottum-up tree acceptors , 1988 .

[29]  Todd A. Proebsting,et al.  One-Pass, Optimal Tree Parsing - With Or Without Trees , 1996, CC.

[30]  Hans H. Kron,et al.  Tree templates and subtree transformational grammars. , 1975 .

[31]  R. G. G. Cattell,et al.  Automatic Derivation of Code Generators from Machine Descriptions , 1980, TOPL.

[32]  Eduardo Pelegri-Llopart,et al.  Rewrite systems, pattern matching, and code generation , 1988 .

[33]  Susan L. Graham,et al.  Optimal Code Generation for Expression Trees: An Application of BURS (bottom-Up Rewrite Systems) Theory , 1988 .

[34]  Helmut Emmelmann,et al.  BEG: a generator for efficient back ends , 1989, PLDI '89.

[35]  Reinhard Wilhelm,et al.  Two Tree Pattern Matchers for Code Selection , 1988, CC.

[36]  Christopher W. Fraser,et al.  BURG: fast optimal instruction selection and tree parsing , 1992, SIGP.

[37]  Alfred V. Aho,et al.  Optimal Code Generation for Expression Trees , 1976, J. ACM.