The G EM compiler needs to evaluate constant
expressions at compile time, wh ich is referred to as constant folding. GEM's i ntermediate language has m any IL operators and data types. A constant folder is thus a compl icated routine with many cases, and the compile-time and ru n-time results must be identical.
After writing our first, i ncomplete, handcrafted constant folder, we searched for a method to au to mate the process. No source language supported a l l the operators and data types o f the GEM !L. The key insight was that there is one language in which I L programs c a n be written precisely a n d tersely: the c; EM IL itself. Since GEM already embodies knowl edge of the code sequences to evaluate every JL operator, no other encoding is needed.
The automatic KFOLD bui lder is a special ized GE.vl compiler that uses the standard GEM back end
Digital Technical journal Vol. 4 No. 4 S[Jecial lssue 1992
Tbe GEM Optilnizing Cmnpiler System
but has a fron t end that compi l es only one program. The KFOLD bu i lder scans the GEM operator signa ture table and constructs a procedure that contains a m any-way conditional branch to select a case based on the IL operator specified in the argument list. Each case fetches operand values from the argument l ist, appl ies the operator, a nd returns the result. S ince most GEM I L tuples operate on several data types, additional subcases may be based on the operator type or resu l t type. We have already recov ered the investment in deve loping t he automatic KFOLD builder, a nd it significantly eases the task of retargeting GEM.
Conclusion
This p aper describes the current G EM compiler system. However, a portable, optimi zing compi ler provides many opportu nities that we have not yet exploited. Some enhancements planned for fu ture versions are:
• Additional I L operators and data types, to sup
port more languages
• Support for additional architecture and operat
i ng system combinations
• Dependence analysis, to enable some of the
fol lowing enhancements
• Loop transformations, to improve the use of the
memory hierarchy
• Software pipel i n i ng, to i ncrease para l lel ism in
vectorizable loops
• Better reordering of memory references duri ng
instruction sched u ling
• The scheduling of instructions into d ifferent
basic blocks
• The relaxing of the l i near restriction on the
lifetime model, i . e . , al lowing holes in register l ifetimes
The GEM compiler system has met demand i ng techn ical and time- to-market goa ls. The system has been success fu l ly retargeted and rehosted for the Alpha AXP and MIPS architectures and several oper ating environments. GEM supports a wide range of l anguages and prov ides h igh levels of optimization for each. The current version of GEM generates effi cient code for Alpha AXP systems, and the imple mentation is robust and flexible enough to support future improvements.
Acknowledgments
The authors wish to acknowledge the contribu tions of the fol lowing individuals to the design and implementation of the GEM compilers: Ron Brender, Patsy Griffin , Lucy Hamnett, Brian Koblenz, Dennis Murphy, Bob Peterson, Paul Winalski, Stan Whitlock (Fortran), Bevin Brett (Ada), and Farokh Morshed (C).
References
I . R . Sites, ed., Alpha Architecture Reference
Manual (Burlington, iVlA: Digital Press, 1992).
2. K. Cooper, M. Hall, and L. Torczon, "The Per ils of Interprocedural Knowledge," Rice COMP
TR90-132 (1990).
3. K. Cooper, M. H a l l , and L. Torczon, " Unex pected Side E ffects of I n l ine Substitu tion: A Case Study," TOPIAS ( March 1992): 22-32. 4. F Chow, " Minimizing Register Usage Penalty
at Procedure Cal ls," S!GPIAN '88 Conference on Program ming Language Design and
Implementation (June 1988): 85-94.
5. T. Lengauer and R. Tarjan, "A Fast Algorithm for F i nding Dominators in a Flowgraph," TOPIAS, voJ. 1 , no. 1 (July 1979): 121-141 . 6. ). Reif, " Symbol ic Interpretation in Almost Lin
ear Time," Conference Records of the Fifth ACIH Symposium on Principles of Program
ming Languages (1978): 76-83.
7. ). Reif and R. Tarjan, "Symbolic Program Anal ysis in Almost-Linear Time," SIAI'vl journal of
Computing, vol. 1 1 , no. 1 (February 1981):
81-93.
8. K. Harris and S. Hobbs, "VAX Fortran,"
Optimization in Compilers, ed. , F Al len,
B. Rosen, and F Zadek ( New York, NY: ACM Press, forthcoming).
9. R. Cattell , " Formalization and Automatic Derivation of Code Generators,'' Ph.D. thesis, CMU-CS-78 -1 15, Carnegie-Mel lon University, April 1978.
10. A. Aho and S. Johnson, "Optimal Code Gener ation for Expression Trees," journal of the AC!H, vol . 23, no. 3 (July 1976): 488-501. 1 1 . B . Leverett, " Register Allocation in Optimiz
ing Compilers," Ph.D. thesis, CMU-CS-81-103, Carnegie-Mel lon University, February 1981 .
12. W Wul f et al., The Design of an Optimizing
Compiler ( New York, l\1Y: American Elsevier
Publishing Co. , 1975).
13. B. Leverett et a l . , "An Overview of the Pro duction-Qual i ty Compiler-Compiler Project,"
Computer; vol . 13, no. 8 (August 1980): 38-49.
14. R. Johnsson , "An Approach to Global Register Al location,'' Ph.D. thesis, Carnegie-Mellon University, December 1975.
15. R. Sethi a nd ). U l lman, "The Generation of Optimal Code for Arithmetic Expressions,"
journal of the ACM, vol . 17, no. 4 (October,
1970): 715-728.
General Reference
•P Anklam et al., Engineering a Compiler (Bedford, MA: Digital Press, 1982).