Compiler Optimization Techniques - PowerPoint PPT Presentation

1 / 8
About This Presentation
Title:

Compiler Optimization Techniques

Description:

Replace slow operations with faster ones. Constant Evaluation ... How big should the peephole be? That is, how many instructions should we look at at once? ... – PowerPoint PPT presentation

Number of Views:127
Avg rating:3.0/5.0
Slides: 9
Provided by: webhome2
Category:

less

Transcript and Presenter's Notes

Title: Compiler Optimization Techniques


1
Compiler Optimization Techniques
2
How Do Compilers Work?
  • A compiler has roughly 4 phases
  • Lexing (or scanning)
  • Parsing
  • Semantic Analysis / Code Generation
  • Code Optimization

3
Optimization
  • Often the code generation phase will produce code
    which is correct, but not optimal.
  • The goal of the optimization phase is to produce
    code which is equivalent, but more efficient.
  • Efficient how?
  • Let's look at a few examples...

4
Optimization Types
  • There are two main types or categories of
    optimizations
  • Local (sometimes called peephole)
  • Global

5
Local Optimizations
  • Sometimes called peephole optimizations because
    it is like a small peephole is put overtop of the
    code
  • Examines small portions of code at a time

6
Local Optimizations
  • Strength Reduction
  • Replace slow operations with faster ones
  • Constant Evaluation
  • Evaluate mathematical expressions at compile time
    if possible
  • Dead Code Removal (eliminating unnecessary
    operations)

7
Global Optimizations
  • Look at large segments of code, function calls,
    if statements, while loops, etc for optimization
    opportunities

8
Peephole Optimization Tradeoffs
  • How big should the peephole be?
  • That is, how many instructions should we look at
    at once?
  • Too many optimization becomes very complicated
  • Too few miss out on optimization opportunities
Write a Comment
User Comments (0)
About PowerShow.com