A desirable organization for a compiler has a target machine independent, source language dependent front end, and a target machine dependent, source language independent back end. The two parts communicate through an intermediate representation (IR). The back end, also called a code generator, translates the IR to target machine instructions. The Graham-Glanville code generation method can be used as the basis for the code generator. The method uses a grammar of linearized instruction patterns to describe the target machine. An LR-like parser is used to cover the IR with instruction patterns. This dissertation develops the necessary techniques to make the Graham-Glanville approach a practical code generation method.
We describe a major experiment in which a production quality Graham-Glanville code generator was developed, retargeted to three different target machines, and used to translate real programs written in "C", Pascal and Fortran into good code for those machines. In the course of the experiment, we tested new code generation ideas, and developed several significant improvements to the method. A methodology is given to write machine description grammars to exploit the structure of the target machine. A syntactic approach has been developed, in which almost all semantic attributes required to select code are encoded directly into the grammar. This encoding simplifies the code generator, although it increases the size of the grammar. Tools are described that compensate for the grammatical size, and ease designing the grammar. The tools exploit properties of the IR, and encode attributes into the grammar. Despite the large grammars, the parser is quickly constructed by exploiting the observed properties of machine description grammars. A discussion of instances in which less than optimal code can be produced, and remedies for those instances is given. The aspects of the code generator design that facilitate retargeting are described. They include the use of IR transformations and the centralization of machine dependent information.
The retargeted code generators are compared with one another and with another code generator for the same front ends. An evaluation is given that demonstrates the success of our methods and the practicality of the Graham-Glanville approach.
Cited By
- Pelegrí-Llopart E and Graham S Optimal code generation for expression trees: an application BURS theory Proceedings of the 15th ACM SIGPLAN-SIGACT symposium on Principles of programming languages, (294-308)
- Spector D and Turner P (1987). Limitations of Graham-Glanville style code generation, ACM SIGPLAN Notices, 22:2, (100-107), Online publication date: 1-Feb-1987.
- Kessler P Discovering machine-specific code improvements Proceedings of the 1986 SIGPLAN symposium on Compiler construction, (249-254)
- Kessler P (2019). Discovering machine-specific code improvements, ACM SIGPLAN Notices, 21:7, (249-254), Online publication date: 1-Jul-1986.
- Hatcher P and Christopher T High-quality code generation via bottom-up tree pattern matching Proceedings of the 13th ACM SIGACT-SIGPLAN symposium on Principles of programming languages, (119-130)
- Aho A and Ganapathi M Efficient tree pattern matching (extended abstract) Proceedings of the 12th ACM SIGACT-SIGPLAN symposium on Principles of programming languages, (334-340)
- Aigrain P, Graham S, Henry R, McKusick M and Pelegri-Llopart E Experience with a Graham-Glanville style code generator Proceedings of the 1984 SIGPLAN symposium on Compiler construction, (13-24)
- Aigrain P, Graham S, Henry R, McKusick M and Pelegri-Llopart E (1984). Experience with a Graham-Glanville style code generator, ACM SIGPLAN Notices, 19:6, (13-24), Online publication date: 1-Jun-1984.
Recommendations
Using dynamic programming to generate optimized code in a Graham-Glanville style code generator
Proceedings of the SIGPLAN '84 symposium on compiler constructionWe have performed an investigation of using a dynamic programming to generate optimized code in a Graham-Glanville style code generator We use Earley's algorithm rather than an IR algorithm for parsing in the code generator Not only does the use of ...
Using dynamic programming to generate optimized code in a Graham-Glanville style code generator
SIGPLAN '84: Proceedings of the 1984 SIGPLAN symposium on Compiler constructionWe have performed an investigation of using a dynamic programming to generate optimized code in a Graham-Glanville style code generator We use Earley's algorithm rather than an IR algorithm for parsing in the code generator Not only does the use of ...
Extending Graham-Glanville techniques for optimal code generation
We propose a new technique for constructing code-generator generators, which combines the advantages of the Graham-Glanville parsing technique and the bottom-up tree parsing approach. Machine descriptions are similar to Yacc specifications. The ...