上海交通大学:《编译原理》教学资源_教学资料_第八周讲义_Machine-Independent Optimizations Ⅲ

Machine-Independent Optimizations III CS308 Compiler Theory 1
Machine-Independent Optimizations Ⅲ CS308 Compiler Theory 1

Partial-Redundancy Elimination Minimize the number of expression evaluations Consider all possible execution sequences in a flow graph,and look at the number of times an expression such as x +y is evaluated. 。 By moving around the places where x +y is evaluated and keeping the result in a temporary variable when necessary,we often can reduce the number of evaluations of this expression along many of the execution paths. CS308 Compiler Theory 2
Partial-Redundancy Elimination • Minimize the number of expression evaluations • Consider all possible execution sequences in a flow graph, and look at the number of times an expression such as x + y is evaluated. • By moving around the places where x + y is evaluated and keeping the result in a temporary variable when necessary, we often can reduce the number of evaluations of this expression along many of the execution number of evaluations of this expression along many of the execution paths. CS308 Compiler Theory 2

The Sources of Redundancy B B2 a =b+c b=7 B3 B2 a =b+c d=b+c a =b+c e b+c d b+c B B t =btc B3 t =b+c B3 b=7 t b+c t btc a t t =b+c a =t d =t d t (a) (b) (c) Figure 9.30:Examples of(a)global common subexpression,(b)loop-invariant code motion,(c)partial-redundancy elimination. 3
The Sources of Redundancy CS308 Compiler Theory 3

Global Common Subexpressions An expression b+c is redundant at point p,if it is an available expression at that point. The expression b +c has been computed along all paths reaching p,and the variables b and c were not redefined after the last expression was evaluated. CS308 Compiler Theory 4
Global Common Subexpressions • An expression b + c is redundant at point p, if it is an available expressi hi on at t hat po int. • The expression b + c has been computed along all paths reaching p, and th i bl b d t d fi d ft th l t i the var i ables b an d c were no t re d efine d after the las t express ion was evaluated. CS308 Compiler Theory 4

Loop-Invariant Expressions The expression b +c is loop invariant assuming neither the variable b nor c is redefined within the loop. We can optimize the program by replacing all the re-executions in a loop by a single calculation outside the loop CS308 Compiler Theory 5
Loop-Invariant Expressions • The expression b + c is loop invariant assuming neither the variable b nor c i d fi d i hi h l is re d efine d w i thin t he loop. • We can optimize the program by replacing all the re-executions in a loop by a single calculation outside the loop. CS308 Compiler Theory 5

Partially Redundant Expressions An example of a partially redundant expression is shown in Fig.9.30(c). The expression b+c in block B4 is redundant on the path Bl-B2-B4, but not on the path Bl-B3-B4. We can eliminate the redundancy on the former path by placing a computation of b+c in block B3 All the results of b+c are written into a temporary variable t,and the calculation in block B4 is replaced with t. Partial-redundancy elimination requires the placement of new expression computations. CS308 Compiler Theory 6
Partially Redundant Expressions • An example of a partially redundant expression is shown in Fig. 9.30(c). • The expression b + c in block B4 is redundant on the path Bl - B2 - B4 , but not on the path Bl - B3 - B4 . • We can eliminate the redundancy on the former path by placing a computation of b + c in block B3 . • All th lt f b + itt i t t i bl t d th All the results o f b + c are written i n to a temporary var i able t, an d the calculation in block B4 is replaced with t. • Partial-redundancy elimination requires the placement of new expression computations expression computations. CS308 Compiler Theory 6

Can All Redundancy Be Eliminated? Is it possible to eliminate all redundant computations along every path? -NO B B2 B3 B2 =b+c B3 a =b+c d =b+c t =b+c B6 B5 A critical edge of a flow graph is any edge d =t leading from a node with more than one successor to a node with more than one predecessor. CS308 Compiler Theory 7
Can All Redundancy Be Eliminated? • Is it possible to eliminate all redundant computations along every path? – NO A critical edge of a flow graph is any edge leading from a node with more than one CS308 Compiler Theory 7 successor to a node with more than one predecessor

Can All Redundancy Be Eliminated? a s b+c B2 a -b+c B3 t d b+c 86 B6 B s d■t d=b+c B6 B (a) (b) Figure 9.32:Code duplication to eliminate redundancies CS308 Compiler Theory 8
Can All Redundancy Be Eliminated? CS308 Compiler Theory 8

The Lazy-Code-Motion Problem It is desirable for programs optimized with a partial-redundancy- elimination algorithm to have the following properties: 1.All redundant computations of expressions that can be eliminated without code duplication are eliminated. 2.The optimized program does not perform any computation that is not in the original program execution. 3.Expressions are computed at the latest possible time We refer to the optimization of eliminating partial redundancy with the goal of delaying the computations as much as possible as lazy code motion. CS308 Compiler Theory
The Lazy-Code-Motion Problem • It is desirable for programs optimized with a partial-redundancyeli i i l i h li m inat ion a lgor i t hm to h h ave t he f ll i o ow ing propert ies: 1. All redundant computations of expressions that can be eliminated with t d ithou t co de d li ti li i t d duplication are eli m ina t e d. 2. The optimized program does not perform any computation that is not in the original program execution original program execution. 3. Expressions are computed at the latest possible time. • We refer to the optimization of eliminating partial redundancy with the goal of delaying the computations as much as possible as goal of delaying the computations as much as possible as lazy code lazy code motion. CS308 Compiler Theory 9

The Lazy-Code-Motion Problem ·Full Redundancy An expression e in block B is redundant if along all paths reaching B,e has been evaluated and the operands of e have not been redefined subsequently. Let sbe the set of blocks,each containing expression e,that renders e in B redundant. -The set of edges leaving the blocks in Smust necessarily form a cutset,which if removed,disconnects block B from the entry of the program. Moreover,no operands of e are redefined along the paths that lead from the blocks in S to B. CS308 Compiler Theory 10
The Lazy-Code-Motion Problem • Full Redundancy – An expression e in block B is redundant if along all paths reaching B, e has been evaluated and the operands of e have not been redefined subsequently. – Let S be the set of blocks each containing expression be the set of blocks, each containing expression e, that renders that renders e in B redundant. – The set of edges leaving the blocks in S must necessarily form a cutset, which if removed di bl k d, disconnects bloc k B f h fh rom t he entry o f t he program. – Moreover, no operands of e are redefined along the paths that lead from the blocks in S to B. CS308 Compiler Theory 10
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 上海交通大学:《编译原理》教学资源_教学资料_第八周讲义_Machine-Independent Optimizations Ⅱ.pdf
- 上海交通大学:《编译原理》教学资源_教学资料_第八周讲义_Machine-Independent Optimizations Ⅰ.pdf
- 上海交通大学:《编译原理》教学资源_教学资料_第五周讲义_Type Checking.pdf
- 上海交通大学:《编译原理》教学资源_教学资料_第二周讲义_lex.pdf
- 上海交通大学:《编译原理》教学资源_教学资料_第二周讲义_Syntax Analyzer.pdf
- 上海交通大学:《编译原理》教学资源_教学资料_第二周讲义_Lexical Analyzer.pdf
- 上海交通大学:《编译原理》教学资源_教学资料_第九周讲义_Machine-Independent Optimizations Ⅳ.pdf
- 上海交通大学:《编译原理》教学资源_教学资料_第九周讲义_CS308 Compiler Theor.pdf
- 上海交通大学:《编译原理》教学资源_教学资料_第九周讲义_CS308 Compiler Theor.pdf
- 上海交通大学:《编译原理》教学资源_教学资料_第三周讲义_Bottom-Up Parsing.pdf
- 上海交通大学:《编译原理》教学资源_教学资料_第三周讲义_Top-Down Parsing.pdf
- 上海交通大学:《编译原理》教学资源_教学资料_第七周讲义_Code Generation Ⅱ.pdf
- 上海交通大学:《编译原理》教学资源_教学资料_第一周讲义_A Simple Syntax-Directed Translator.pdf
- 上海交通大学:《编译原理》教学资源_教学资料_第一周讲义_Introduction to Compilin.pdf
- 上海交通大学:《编译原理》教学资源_教学资料_第一周讲义_Parameter Passing Mechanisms.pdf
- 上海交通大学:《编译原理》教学资源_教学资料_第一周讲义_CS308 Compiler Theory.pdf
- 上海交通大学:《程序设计思想与方法》课程教学资源(PPT课件讲稿)CT15 并发与多线程.ppt
- 上海交通大学:《程序设计思想与方法》课程教学资源(PPT课件讲稿)CT14 Python GUI工具包:Tkinter.ppt
- 上海交通大学:《程序设计思想与方法》课程教学资源(PPT课件讲稿)CT13 算法设计分析.ppt
- 上海交通大学:《程序设计思想与方法》课程教学资源(PPT课件讲稿)CT12 面向对象设计.ppt
- 上海交通大学:《编译原理》教学资源_教学资料_第六周讲义_Intermediate Code Generation.pdf
- 上海交通大学:《编译原理》教学资源_教学资料_第六周讲义_Heap Management.pdf
- 上海交通大学:《编译原理》教学资源_教学资料_第六周讲义_Run-Time Environments.pdf
- 上海交通大学:《编译原理》教学资源_教学资料_第四周讲义_Syntax-Directed Translation.pdf
- 上海交通大学:《计算机辅助设计》教学资源_Product Visualization.doc
- 上海交通大学:《科学计算》课程教学资源(英文讲义)Lecture Note 1:Introduction, calculus review and computer representation of numbers.pdf
- 上海交通大学:《科学计算》课程教学资源(英文讲义)Lecture Note 2:Solution of nonlinear equations.pdf
- 上海交通大学:《科学计算》课程教学资源(英文讲义)Lecture Note 3:Polynomial Interpolation.pdf
- 上海交通大学:《科学计算》课程教学资源(英文讲义)Lecture Note 4:Numerical differentiation and integration.pdf
- 上海交通大学:《程序设计思想与方法》课程教学资源(上机课)第一次上机_第一次上机内容_10.18.doc
- 上海交通大学:《程序设计思想与方法》课程教学资源(上机课)第一次上机_第一次上机内容_10.18.pdf
- 上海交通大学:《程序设计思想与方法》课程教学资源(上机课)第三次上机_python第三次上机.doc
- 上海交通大学:《程序设计思想与方法》课程教学资源(上机课)第三次上机_Python第三次上机解析-update.doc
- 上海交通大学:《程序设计思想与方法》课程教学资源(上机课)第五次上机_第五次上机.doc
- 上海交通大学:《程序设计思想与方法》课程教学资源(上机课)第四次上机_Python第四次上机题目.doc
- 上海交通大学:《程序设计思想与方法》课程教学资源_作业_第一次作业内容要求.doc
- 上海交通大学:《程序设计思想与方法》课程教学资源_作业_第一次作业内容要求.pdf
- 上海交通大学:《程序设计思想与方法》课程教学资源_参考教材_HowToThink-Python.pdf
- 上海交通大学:《程序设计思想与方法》课程教学资源_参考教材_参考教材-2002版-PythonProgrammingBook.pdf
- 上海交通大学:《程序设计思想与方法》课程教学资源_参考教材_参考教材-python-programming.pdf