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

Machine-Independent Optimizations IV CS308 Compiler Theory 1
Machine-Independent Optimizations Ⅳ CS308 Compiler Theory 1

Loops in Flow Graphs Loops are important because programs spend most of their time executing them Optimizations that improve the performance of loops can have a significant impact. CS308 Compiler Theory 2
Loops in Flow Graphs • Loops are important because programs spend most of their time execut ing t hem • Optimizations that improve the performance of loops can have a si ifi t i t ignifican t impac t. CS308 Compiler Theory 2

Dominators ●g Say node d of a flow graph dominates node n,written d dom n,if every path from the entry node of the flow graph to n goes through d. Every node dominates itself. Which nodes are dominated by each node? CS308 Compiler Theory 3
Dominators • Say node d of a flow graph dominates node n, written d dom n, if every path from th d f h fl h he entry node of the flow graph to n goes th h roug d. • Every node dominates itself. Which nodes are dominated by each node? CS308 Compiler Theory 3

Dominator Tree The entry node is the root Each node d dominates only its descendants in the tree. 2 3 6 8 10 CS308 Compiler Theory 4
Dominator Tree • The entry node is the root • Each node d dominates only its descendants in the tree. CS308 Compiler Theory 4

Finding Dominators D(n。)={no} For n∈N-{n。} D(n)=N; Change TRUE WHILE Change Change FALSE For n E N -no) { NewD ={n}U∩D(p) p∈P(n) f D(n)≠NewD Then { Change TRUE D (n )NewD } CS308 Compiler Theory 5
Finding Dominators ( ) { } 0 0 D n = n ; { } ( ) ; ( ) { } 0 0 0 WHIL E Chan g e Change TRUE For n N n D n N = ∈ − = { } ; { 0 Fo r n N n Change FALSE g ∈ − = { } ( ) { { } ( ) 0 NewD n D p N p P n = ∪ ∈ I ; { ( ) Change TRUE If D n NewD Then = ≠ } } D ( n ) = NewD ; CS308 Compiler Theory 5 }

Depth-First Ordering The route of the search in a depth-first search forms a depth-first spanning tree(DFST) 8 9 CS308 Compiler Theory 6
Depth-First Ordering • The route of the search in a depth-first search forms a depth-first spanni ( ng tree (DFST ). CS308 Compiler Theory 6

Depth-First Ordering void search(n){ mark n“visited”; for (each successor s of n) if(sis“unvisited'”){ add edge n→stoT; search(s); } dfnin c; 6 c=c-1; main() 8 T=①;/*set of edges*/ 10 for (each node n of G) mark n“unvisited”; c number of nodes of G; search(no); } CS308 Compiler Theory 7
Depth-First Ordering CS308 Compiler Theory 7

Edges in a Depth-First Spanning Tree Advancing edges:going from a node m to a proper descendant of m in the tree Retreating edges:going from a node m to an ancestor of m in the tree (possibly to m itself). Cross edges:edges m>n such that neither m nor n is an ancestor of the other in the DFST CS308 Compiler Theory 8
Edges in a Depth-First Spanning Tree • Advancing edges: going from a node m to a proper descendant of m in t he tree • Retreating edges: going from a node m to an ancestor of m in the tree ( ibl t it lf) (possibly to m itself) . • C d ross e dges: e dges m Æ n such th t ith i t f h th a t neither m nor n is an ances tor o f the other in the DFST CS308 Compiler Theory 8

Back Edges and Reducibility A back edge is an edge a >b whose head b dominates its tail a. For any flow graph,every back edge is retreating,but not every retreating edge is a back edge. A flow graph is said to be reducible if all its retreating edges in any depth-first spanning tree are also back edges. A flow graph is said to be reducible if all its retreating edges in any depth-first spanning tree are also back edges. CS308 Compiler Theory
Back Edges and Reducibility • A back edge is an edge a Æb whose head b dominates its tail a. • For any flow graph, every back edge is retreating, but not every retreating edge is a back edge. • A flow graph is said to be reducible if all its retreatin g edges in any depth-first spanning tree are also back edges. • A flow graph is said to be reducible if all its retreating edges in any depth -first spanning tree are also back edges first spanning tree are also back edges. CS308 Compiler Theory 9

Depth of a Flow Graph Given a depth-first spanning tree for the graph,the depth is the largest number of retreating edges on any cycle-free path. 10→7→4→3 Depth=3 0 9 CS308 Compiler Theory 10
Depth of a Flow Graph • Given a depth-first spanning tree for the graph, the depth is the largest numb f er o f retreatid l ng e dges on any cyc lefree pat h. 10 Æ 7 Æ4 Æ 3 Depth=3 CS308 Compiler Theory 10
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 上海交通大学:《编译原理》教学资源_教学资料_第九周讲义_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
- 上海交通大学:《程序设计思想与方法》课程教学资源(PPT课件讲稿)CT11 数据集合体.ppt
- 上海交通大学:《程序设计思想与方法》课程教学资源(PPT课件讲稿)CT10 类的定义.ppt
- 上海交通大学:《程序设计思想与方法》课程教学资源(PPT课件讲稿)CT09 模拟设计.ppt
- 上海交通大学:《程序设计思想与方法》课程教学资源(PPT课件讲稿)CT08 控制结构——循环语句.ppt
- 上海交通大学:《程序设计思想与方法》课程教学资源(PPT课件讲稿)CT07 控制结构——条件语句.ppt
- 上海交通大学:《程序设计思想与方法》课程教学资源(PPT课件讲稿)CT06 函数.ppt
- 上海交通大学:《程序设计思想与方法》课程教学资源(PPT课件讲稿)CT05 面向对象与图形编程.ppt
- 上海交通大学:《编译原理》教学资源_教学资料_第二周讲义_Lexical Analyzer.pdf
- 上海交通大学:《编译原理》教学资源_教学资料_第二周讲义_Syntax Analyzer.pdf
- 上海交通大学:《编译原理》教学资源_教学资料_第二周讲义_lex.pdf
- 上海交通大学:《编译原理》教学资源_教学资料_第五周讲义_Type Checking.pdf
- 上海交通大学:《编译原理》教学资源_教学资料_第八周讲义_Machine-Independent Optimizations Ⅰ.pdf
- 上海交通大学:《编译原理》教学资源_教学资料_第八周讲义_Machine-Independent Optimizations Ⅱ.pdf
- 上海交通大学:《编译原理》教学资源_教学资料_第八周讲义_Machine-Independent Optimizations Ⅲ.pdf
- 上海交通大学:《编译原理》教学资源_教学资料_第六周讲义_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