Academia.eduAcademia.edu

Outline

Basics of Compiler Design Anniversary edition

Abstract
sparkles

AI

The text provides an overview of compiler design, explaining the role of compilers in translating high-level programming languages into machine language. It outlines the advantages of using high-level languages for programming, such as ease of development and error detection by compilers, while also discussing the inherent performance trade-offs. Key phases of compilation are introduced, including lexical analysis and syntax analysis, which structure the compilation process.

References (81)

  1. Caller-saves versus callee-saves . . . . . . . . . . . . . . . . . .
  2. 5 Using registers to pass parameters . . . . . . . . . . . . . . . . .
  3. 6 Interaction with the register allocator . . . . . . . . . . . . . . . .
  4. 7 Accessing non-local variables . . . . . . . . . . . . . . . . . . . 10.7.1 Global variables . . . . . . . . . . . . . . . . . . . . . . 10.7.2 Call-by-reference parameters . . . . . . . . . . . . . . . . 10.7.3 Nested scopes . . . . . . . . . . . . . . . . . . . . . . . .
  5. 8 Variants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10.8.1 Variable-sized frames . . . . . . . . . . . . . . . . . . . . 10.8.2 Variable number of parameters . . . . . . . . . . . . . . . 10.8.3 Direction of stack-growth and position of FP . . . . . . . 10.8.4 Register stacks . . . . . . . . . . . . . . . . . . . . . . . 10.8.5 Functions as values . . . . . . . . . . . . . . . . . . . . .
  6. 9 Further reading . . . . . . . . . . . . . . . . . . . . . . . . . . . Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Analysis and optimisation 11.1 Data-flow analysis . . . . . . . . . . . . . . . . . . . . . . . . . . 11.2 Common subexpression elimination . . . . . . . . . . . . . . . . 11.2.1 Available assignments . . . . . . . . . . . . . . . . . . . 11.2.2 Example of available-assignments analysis . . . . . . . .
  7. 2.3 Using available assignment analysis for common subex- pression elimination . . . . . . . . . . . . . . . . . . . .
  8. 3 Jump-to-jump elimination . . . . . . . . . . . . . . . . . . . . .
  9. 4 Index-check elimination . . . . . . . . . . . . . . . . . . . . . .
  10. 5 Limitations of data-flow analyses . . . . . . . . . . . . . . . . . .
  11. 6 Loop optimisations . . . . . . . . . . . . . . . . . . . . . . . . . 11.6.1 Code hoisting . . . . . . . . . . . . . . . . . . . . . . . . 11.6.2 Memory prefetching . . . . . . . . . . . . . . . . . . . .
  12. 7 Optimisations for function calls . . . . . . . . . . . . . . . . . . . 11.7.1 Inlining . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.7.2 Tail-call optimisation . . . . . . . . . . . . . . . . . . . .
  13. 8 Specialisation . . . . . . . . . . . . . . . . . . . . . . . . . . . .
  14. 9 Further reading . . . . . . . . . . . . . . . . . . . . . . . . . . . Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 Memory management 12.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.2 Static allocation . . . . . . . . . . . . . . . . . . . . . . . . . . . 12.2.1 Limitations . . . . . . . . . . . . . . . . . . . . . . . . .
  15. 3 Stack allocation . . . . . . . . . . . . . . . . . . . . . . . . . . .
  16. 3 succ, gen and kill for the program in figure 9.2 . . . . . . . . . . .
  17. Fixed-point iteration for liveness analysis . . . . . . . . . . . . .
  18. 5 Interference graph for the program in figure 9.2 . . . . . . . . . .
  19. 9 Colouring of the graph in figure 9.8 . . . . . . . . . . . . . . . .
  20. 1 Simple activation record layout . . . . . . . . . . . . . . . . . . .
  21. 2 Prologue and epilogue for the frame layout shown in figure 10.1 . 10.3 Call sequence for x := CALL f (a 1 , . . . , a n ) using the frame layout shown in figure 10.1 . . . . . . . . . . . . . . . . . . . . . . . . .
  22. 4 Activation record layout for callee-saves . . . . . . . . . . . . . .
  23. 5 Prologue and epilogue for callee-saves . . . . . . . . . . . . . . .
  24. 6 Call sequence for x := CALL f (a 1 , . . . , a n ) for callee-saves . . . . .
  25. 7 Possible division of registers for 16-register architecture . . . . . .
  26. 8 Activation record layout for the register division shown in figure 10.7216 10.
  27. 9 Prologue and epilogue for the register division shown in figure 10.7 10.10Call sequence for x := CALL f (a 1 , . . . , a n ) for the register division shown in figure 10.7 . . . . . . . . . . . . . . . . . . . . . . . . .
  28. 11Example of nested scopes in Pascal . . . . . . . . . . . . . . . . . 10.12Adding an explicit frame-pointer to the program from figure 10.11 10.13Activation record with static link . . . . . . . . . . . . . . . . . .
  29. 14Activation records for f and g from figure 10.11 . . . . . . . . . .
  30. 1 Gen and kill sets for available assignments . . . . . . . . . . . . .
  31. 2 Example program for available-assignments analysis . . . . . . .
  32. 3 pred, gen and kill for the program in figure 11.2 . . . . . . . . . .
  33. Fixed-point iteration for available-assignment analysis . . . . . .
  34. 5 The program in figure 11.2 after common subexpression elimination. 11.6 Equations for index-check elimination . . . . . . . . . . . . . . .
  35. 7 Intermediate code for for-loop with index check . . . . . . . . . .
  36. 1 Operations on a free list . . . . . . . . . . . . . . . . . . . . . . . Bibliography
  37. A. Aasa. Precedences in specification and implementations of programming languages. In J. Maluszyński and M. Wirsing, editors, Proceedings of the Third International Symposium on Programming Language Implementation and Logic Programming, number 528 in LNCS, pages 183-194. Springer Verlag, 1991.
  38. Harold Abelson, Gerald Jay Sussman, and Julie Sussman. Structure and In- terpretation of Computer Programs. MIT Press, 1996. Also downloadable from http://mitpress.mit.edu/sicp/full-text/sicp/book/.
  39. Alfred V. Aho, John E. Hopcroft, and Jeffrey D. Ullman. The Design and Analysis of Computer Algorithms. Addison-Wesley, 1974.
  40. Alfred V. Aho, Monica S. Lam, Ravi Sethi, and Jeffrey D. Ullman. Compilers; Principles, Techniques and Tools. Addison-Wesley, 2007. Newer edition of [5].
  41. Alfred V. Aho, Ravi Sethi, and Jeffrey D. Ullman. Compilers; Principles, Techniques and Tools. Addison-Wesley, 1986. Rereleased in extended form as [4].
  42. Hassan Aït-Kaci. Warren's Abstract Machine -A Tutorial Reconstruction. MIT Press, 1991.
  43. John R. Allen and Ken Kennedy. Optimizing compilers for modern architec- tures: a dependence-based approach. Morgan Kaufmann, 2001.
  44. Andrew W. Appel. Compiling with Continuations. Cambridge University Press, 1992.
  45. Andrew W. Appel. Modern Compiler Implementation in ML. Cambridge University Press, 1998.
  46. H. Boehm and M. Weiser. Garbage collection in an uncooperative environ- ment. Software Practice and Experience, 18(9):807-820, 1988.
  47. H. Bratman. An alternative form of the 'UNCOL' diagram. Communications of the ACM, 4(3):142, 1961.
  48. Preston Briggs. Register Allocation via Graph Coloring, Tech. Rept. CPC- TR94517-S. PhD thesis, Rice University, Center for Research on Parallel Computation, Apr. 1992.
  49. J. A. Brzozowski. Derivatives of regular expressions. Journal of the ACM, 1(4):481-494, 1964.
  50. Noam Chomsky. Three models for the description of language. IRE Transac- tions on Information Theory, IT-2(3):113-124, 1956.
  51. J. Earley and H. Sturgis. A formalism for translator interactions. Communi- cations of the ACM, 13:607-617, 1970.
  52. Peter Naur (ed.). Revised report on the algorithmic language Algol 60. Com- munications of the ACM, 6(1):1-17, 1963.
  53. John Hatcliff, Torben Mogensen, and Peter Thiemann (Eds.). Partial Eval- uation: Practice and Theory, volume 1706 of Lecture Notes in Computer Science. Springer Verlag, 1999.
  54. Raymond J. Hookway and Mark A. Herdeg. Digital fx!32: Combining emulation and binary translation. http://www.cs.tufts.edu/comp/150PAT/optimization/DTJP01PF.pdf, 1997.
  55. John E. Hopcroft, Rajeev Motwani, and Jeffrey D. Ullman. Introduction to Automata Theory, Languages and Computation, 2nd ed. Addison-Wesley, 2001.
  56. Kathleen Jensen and Niklaus Wirth. Pascal User Manual and Report (2nd ed.). Springer-Verlag, 1975.
  57. Neil D. Peyton Jones, Carsten Gomard, and Peter Sestoft. Partial Evaluation and Automatic Program Generation. Prentice Hall, 1993.
  58. Richard E. Jones and Rafael Dueire Lins. Garbage Collection: Algorithms for Automatic Dynamic Memory Management. John Wiley, 1996.
  59. Simon L. Peyton Jones and David Lester. Implementing Functional Lan- guages -A Tutorial. Prentice Hall, 1992.
  60. J. P. Keller and R. Paige. Program derivation with verified transformations - a case study. Communications in Pure and Applied Mathematics, 48(9-10), 1996.
  61. B. W. Kerninghan and D. M. Ritchie. The C Programming Language. Prentice-Hall, 1978.
  62. Donald Knuth. The Art of Computer Programming, Volume 1: Fundamental Algorithms. Addison-Wesley, 1997.
  63. James Larus. Assembler, linkers and the spim simulator. http://pages.cs.wisc.edu/∼larus/HP AppA.pdf, 1998.
  64. M. E. Lesk. Lex: a Lexical Analyzer Generator. Technical Report 39, AT&T Bell Laboratories, Murray Hill, N. J., 1975.
  65. T. Lindholm and F. Yellin. The Java Virtual Machine Specification, 2nd ed. Addison-Wesley, Reading, Massachusetts, 1999.
  66. John McCarthy, Paul W. Abrahams, Daniel J. Edwards, Timothy P. Hart, and Michael I. Levin. LISP 1.5 Programmer's Manual. The M.I.T. Press, 1962.
  67. R. McNaughton and H. Yamada. Regular expressions and state graphs for automata. IEEE Transactions on Electronic Computers, 9(1):39-47, 1960.
  68. Robin Milner. A theory of type polymorphism in programming. Journal of Computational Systems Science, 17(3):348-375, 1978.
  69. Robin Milner. Communication and Concurrency. Prentice-Hall, 1989.
  70. Torben AE. Mogensen, David A. Schmidt, and I. Hal Sudborough, editors. The essence of computation: complexity, analysis, transformation. Springer- Verlag New York, Inc., New York, NY, USA, 2002.
  71. Steven S. Muchnick. Advanced Compiler Design and Implementation. Mor- gan Kaufmann, 1997.
  72. Flemming Nielson, Hanne R. Nielson, and Chris Hankin. Principles of Pro- gram Analysis. Springer-Verlag New York, Inc., Secaucus, NJ, USA, 1999.
  73. Chris Okasaki. Purely Functional Data Structures. Cambridge University Press, 1998.
  74. Scott Owens, John Reppy, and Aaron Turon. Regular-expression derivatives re-examined. J. Funct. Program., 19(2):173-190, 2009.
  75. David A. Patterson and John L. Hennessy. Computer Organization & Design, the Hardware/Software Interface. Morgan Kaufmann, 1998.
  76. Vern Paxson. Flex, version 2.5, a fast scanner generator. http://www.gnu.org/software/flex/manual/html_mono/flex.html, 1995.
  77. G. L. Steele and G. J. Sussman. The Art of the Interpreter or, The Modularity Complex. Technical Report AIM-453, Massachusetts Institute of Technology, Cambridge, MA, USA, 1978.
  78. Mikkel Thorup. All structured programs have small tree-width and good reg- ister allocation. Information and Computation, 142(2):159-181, 1998.
  79. Mads Tofte and Jean-Pierre Talpin. Region-based memory management, 1997.
  80. Paul R. Wilson. Uniprocessor garbage collection techniques. In IWMM '92: Proceedings of the International Workshop on Memory Management, pages 1-42, London, UK, 1992. Springer-Verlag.
  81. Niklaus Wirth. The design of a Pascal compiler. Software -Practice and Experience, 1(4):309-333, 1971.