A <italic>Rewrite System</italic> is a collection of <italic>rewrite rules</italic> of the form α β where α and β are tree patterns. A rewrite system can be extended by associating a cost with each rewrite rule, and by defining the cost of a rewrite sequence as the sum of the costs of all the rewrite rules in the sequence. The REACHABILITY problem for a rewrite system <italic>R</italic> is, given an input tree <italic>T</italic> and a fixed <italic>goal</italic> tree <italic>G</italic>, to determine if there exists a rewrite sequence in <italic>R</italic>, rewriting <italic>T</italic> into <italic>G</italic> and, if so, to obtain one such sequence. The C-REACHABILITY problem is similar except that the obtained sequence must have minimal cost among all those sequences writing <italic>T</italic> into <italic>G</italic>.
This paper introduces a class of rewrite systems called Bottom-Up Rewrite Systems (BURS), and a table-driven algorithm to solve REACHABILITY for member of the class. This algorithm is then modified to solve C-REACHABILITY and specialized for a subclass of BURS so that all cost manipulation is encoded into the tables and is not performed explicitly at solving time. The subclass extends the <italic>simple machine grammars</italic> [AGH84], rewrite systems used to describe target machine architectures for code generation, by allowing additional types of rewrite rules such as commutativity transformations.
A table-driven code generator based on solving C-REACHABILITY has been implemented and tested with several machine descriptions. The code generator solves C-REACHABILITY faster than a comparable solver based on Graham-Glanville techniques [AGH84] (a non-optimal technique), yet requires only slightly larger tables. The code generator runs much faster than recent proposals to solve C-REACHABILITY that use pattern matching and deal with costs explicitly at solving time [AGT86, HeD87, WeW86]. The BURS theory generalizes and unifies the bottom-up approaches of Henry/Damron [HeD87] and Weisgerber/Wilhelm [WeW86].
[1]
Philippe Aigrain,et al.
Experience with a Graham-Glanville style code generator
,
1984,
SIGPLAN '84.
[2]
Murray Hill,et al.
Yacc: Yet Another Compiler-Compiler
,
1978
.
[3]
Robert Rettig Henry.
Graham/glanville code generators (compiler, parser, programming language)
,
1984
.
[4]
M. F.,et al.
Bibliography
,
1985,
Experimental Gerontology.
[5]
james w.thatcher,et al.
tree automata: an informal survey
,
1974
.
[6]
David S. Johnson,et al.
Computers and Intractability: A Guide to the Theory of NP-Completeness
,
1978
.
[7]
David A. Patterson,et al.
Reduced instruction set computers
,
1985,
CACM.
[8]
S. E. Keller,et al.
Tree transformation techniques and experiences
,
1984,
SIGPLAN '84.
[9]
Reinhard Wilhelm,et al.
Two tree pattern matchers for code selection : (including targeting)
,
1986
.
[10]
David R. Chase,et al.
An improvement to bottom-up tree pattern matching
,
1987,
POPL '87.
[11]
Alfred V. Aho,et al.
Code Generation for Expressions with Common Subexpressions
,
1977,
J. ACM.
[12]
Susan L. Graham,et al.
A new method for compiler code generation
,
1978,
POPL '78.
[13]
Philip John Hatcher.
A tool for high-quality code generation (compiling)
,
1985
.
[14]
Thomas W. Christopher,et al.
High-quality code generation via bottom-up tree pattern matching
,
1986,
POPL '86.
[15]
Alfred V. Aho,et al.
Code generation using tree matching and dynamic programming
,
1989,
ACM Trans. Program. Lang. Syst..