SlideServe
Menu
Preferences
© SlideServe · v2026

Optimizing Compilers

lara avatar
17 slides · 372 Views · 170 likes · Sep 26, 2014

This document provides an in-depth exploration of optimizing compilers, detailing various strategies for code optimization while preserving program semantics. It covers critical concepts such as control flow analysis, data flow analysis, and program transformations. The discussion includes levels of code optimization—source, intermediate, and target code levels—and techniques like common subexpression elimination, copy propagation, dead code elimination, constant folding, and loop optimizations. Case studies further illustrate the practical applications of these techniques in improving program efficiency.

Optimizing Compilers - slide 1
01 / 17Optimizing Compilers
1 / 17

Download Presentation

Optimizing Compilers
An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

More Related Content

Presentation Transcript
  1. Optimizing Compilers Nai-Wei Lin Department of Computer Science and Information Engineering National Chung Cheng University

  2. Content • Introduction • Control flow analysis • Data flow analysis • Program transformations • Case studies

  3. Introduction

  4. Optimizing Compilers • Compilers that apply code-improving transformations • Must preserve the meaning of programs • Must improve programs by a measurable amount • Must be worth the effort

  5. Levels of Code Optimization • Source code level • profile programs, change algorithms, transform loops • Intermediate code level • analyze programs, inline procedure calls, improve loops, eliminate common subexpressions • Target code level • use machine characteristics, do peephole optimizations

  6. Organization of an Optimizing Compiler • Front end • Code optimization • control flow analysis • data flow analysis • code transformation • Code generation

  7. Program Transformations • Statement level • common-subexpression elimination, copy propagation, dead-code elimination, constant folding, constant propagation • Loop level • code motion, reduction in strength, induction variable elimination • Procedure level • inline expansion, tail recursion optimization

  8. Common Subexpression Elimination a = b + c b = a - d c = b + c d = a - d a = a + c c = a - d a = b + c b = a - d c = b + c d = b a = a + c c = a - d

  9. Copy Propagation a = b + c b = a - d c = b + c d = b a = a + c c = a - d a = b + c b = a - d c = b + c d = b a = a + c c = a - b

  10. Dead-Code Elimination a = b + c b = a - d c = b + c d = b a = a + c c = a - b a = b + c b = a - d c = b + c a = a + c c = a - b

  11. Constant Folding a = 4 * 2 b = a + 3 a = 8 b = a + 3

  12. Constant Propagation a = 8 b = a + 3 a = 8 b = 8 + 3

  13. Code Motion i = 0 f = n - 1 i = 0 L: t = 4 * i b = a[t] i = i + 1 if i < n- 1goto L L: t = 4 * i b = a[t] i = i + 1 if i < fgoto L

  14. Reduction in Strength i = 0 f = n - 1 t = -4 i = 0 f = n - 1 t = 4 * i b = a[t] i = i + 1 if i < f goto L t = t + 4 b = a[t] i = i + 1 if i < f goto L

  15. Induction Variable Elimination i = 0 f = n - 1 t = -4 i = 0 f = n - 1 t = -4 t = t + 4 b = a[t] ift < 4 * fgoto L t = t + 4 b = a[t] i = i + 1 ifi < fgoto L

  16. Inline Expansion p: a = c + d b = a + c param a param b call q, 2 c = d + e return q: d = sp[0] + sp[1] return p: a = c + d b = a + c d = a + b c = d + e return q: d = sp[0] + sp[1] return

  17. Tail Recursion Optimization p: a = sp[0] + c b = sp[1] + d param a param b call p, 2 return p: a = sp[0] + c b = sp[1] + d sp[0] = a sp[1] = b goto p return