Skip to main content
  • Courses
  • Programs
  • Help
    Getting Started Discussion Forums Help Center & FAQ
Saylor Academy
    Close
    Toggle search input
  • Log in or Sign up
Courses
Programs
Help
Getting Started
Discussion Forums
Help Center & FAQ
  • CS304: Compilers
  • Sections
  • Course Introduction
  • Unit 1: Introduction to Compilers
  • Unit 2: Formal Languages and Formal Grammar
  • Unit 3: Finite State Machines
  • Unit 4: Scanning and Lexical Analysis
  • Unit 5: Parsing and Syntax Analysis
  • Unit 6: Syntax Directed Translation and Semantic Analysis
  • Unit 7: Runtime Environment
  • Unit 8: Code Generation
  • Unit 9: Code Optimization
  • Unit 10: Compiler Verification and Validation
  • Unit 11: Compiler Summary and Next Steps
  • Final Exam
  • Resources
  • Activities
  • Quizzes
  • Home
  • My programs

CS304: Compilers

Competencies
  1. Home
  2. Courses
  3. (hidden)
  4. CS304: Compilers
  5. Sections
  6. Unit 9: Code Optimization

Learn new skills or earn credit towards a degree at your own pace with no deadlines, using free courses from Saylor Academy. We're committed to removing barriers to education and helping you build essential skills to advance your career goals. Start learning here, or check out our full course catalog.

Log in or Sign up to enroll in courses, track your progress, gain access to final exams, and get a free certificate of completion!

Sign up now
Back to course 'CS304: Compilers'
  • Unit 9: Code Optimization

    Simply compiling and executing a program is not enough to get the most out of your code. It is the optimization process that allows your code to run as effectively and efficiently as possible. In this unit, we will first take a look at optimization, learning what it is and why we are interested in it. Next, we will review different optimization categories, including Peephole, Local, Loop, Language Dependent, and Machine Dependent. We will conclude with a discussion of different optimization techniques. By the end of this unit, you will have a basic understanding of a wide range of optimization techniques and how they improve the effectiveness of your program.

    Completing this unit should take you approximately 22 hours.

    • Upon successful completion of this unit, you will be able to:

      • Define optimization.
      • Describe approaches and give examples of local optimizations.
      • Describe approaches and give examples of global optimizations.
      • Describe approaches and give examples of code optimizations.
    • 9.1: The What and Why of Code Optimizations

      • Torben Ægidius Mogensen's "Basics of Compiler Design, Chapter 11: Analysis and Optimisation" URL

        Read Chapter 11 through section 11.1.

    • 9.2: Fundamentals of Code Optimization

      • University of California, Berkeley: Paul Hilfinger's "Local Optimization" URL

        Read slides 1 through 8.

      • Massachusetts Institute of Technology: S. Amarasinghe and M. Rinard's "Introduction to Program Analysis and Optimization" URL

        Read these slides.

    • 9.3: Local Intermediate Code Optimizations: Definitions and Examples

      • Stanford University: Keith Schwarz's "IR Optimization" URL

        Read pages 1 through 10 of the handout, and the associated lecture notes, which are an excellent unified formal treatment of the topic.

    • 9.4: Global Intermediate Code Optimizations: Definitions and Examples

      • University of California, Berkeley: Paul Hilfinger's "Global Optimization" URL

        Read these slides. Global optimization uses forward analysis (e.g., constant propagation), which moves information forward, and backward analysis (e.g., liveness), which moves information backward. Note slide 5, which states that dynamic properties of a program are undecidable.

      • Stanford University: Keith Schwarz's "Code Optimization", "Global Optimization", and "Global Optimization II" URL

        • Code Optimization
        • Global Optimization
        • Global Optimization II

        Read these pages, which cover the material in more detail and present it in a unified formal way using semilattices.

      • Massachusetts Institute of Technology: S. Amarasinghe and M. Rinard's "Introduction to Dataflow Analysis" and "Foundations of Dataflow Analysis" URL

        • Introduction to Dataflow Analysis
        • Foundations of Dataflow Analysis

        Read these slides. They repeat some of the material from above readings. However, they are an excellent review, and go into detail on the formalism that underlies global optimizations.

    • 9.5: Code Optimization

      • Massachusetts Institute of Technology: S. Amarasinghe and M. Rinard's "Notes for Lectures 13-18" URL

        • Introduction to code optimization: instruction scheduling
        • Loop optimization: instruction scheduling
        • More loop optimizations
        • Register allocation
        • Parallelization
        • Memory optimization

        Read these slides. If you find a part that is helpful and adds to your knowledge of optimizations, read it. These slides repeat some of the material from above readings. However, they are an excellent review, concise and clear, and reinforce key points. They also provide additional examples.

    • 9.6: Verification and Validation of Code Optimization

      • Torben Ægidius Mogensen's "Basics of Compiler Design, Chapter 11: Analysis and Optimisation" URL

        Do Exercise 11.1 parts a) and b) on page 254.

        This exercise will give you some practice with code optimization and is based on Chapter 11, which covers analysis and optimization. The exercise uses common subexpression elimination as an example of optimization. You can check your answers against the Answer Key.

Skip Activities
Activities
  • QuizQuizzes
  • Resources
Skip Recent activity
Recent activity
Activity since Wednesday, January 25, 2023, 3:11 PM
Full report of recent activity...

No recent activity

Saylor Academy
  • About

  • Partners

  • Blog

  • Contact

Saylor Academy

© Saylor Academy 2010-2023 except as otherwise noted. Excluding course final exams, content authored by Saylor Academy is available under a Creative Commons Attribution 3.0 Unported license. Third-party materials are the copyright of their respective owners and shared under various licenses. See detailed licensing information.

Saylor Academy®, Saylor.org®, and Harnessing Technology to Make Education Free® are trade names of the Constitution Foundation, a 501(c)(3) organization through which our educational activities are conducted.

"CCBY"

Sitemap | Terms of Use | Privacy Policy

Data retention summary
Get the mobile app
Policies