{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture-10

# lecture-10 - Control ow graphs and loop optimizations...

This preview shows pages 1–12. Sign up to view the full content.

Control flow graphs and loop optimizations Friday, October 21, 2011

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Agenda Building control flow graphs Low level loop optimizations Code motion Strength reduction Unrolling High level loop optimizations Loop fusion Loop interchange Loop tiling Friday, October 21, 2011
Moving beyond basic blocks Up until now, we have focused on single basic blocks What do we do if we want to consider larger units of computation Whole procedures? Whole program? Idea: capture control flow of a program How control transfers between basic blocks due to: Conditionals Loops Friday, October 21, 2011

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Representation Use standard three-address code Jump targets are labeled Also label beginning/end of functions Want to keep track of targets of jump statements Any statement whose execution may immediately follow execution of jump statement Explicit targets: targets mentioned in jump statement Implicit targets: statements that follow conditional jump statements The statement that gets executed if the branch is not taken Friday, October 21, 2011
Running example A = 4 t1 = A * B repeat { t2 = t1/C if (t2 W) { M = t1 * k t3 = M + I } H = I M = t3 - H } until (T3 0) Friday, October 21, 2011

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Running example 1 A = 4 2 t1 = A * B 3 L1 : t2 = t1 / C 4 if t2 < W goto L2 5 M = t1 * k 6 t3 = M + I 7 L2 : H = I 8 M = t3 - H 9 if t3 0 goto L3 10 goto L1 11 L3 : halt Friday, October 21, 2011
Control flow graphs Divides statements into basic blocks Basic block: a maximal sequence of statements I 0 , I 1 , I 2, ..., I n such that if I j and I j+1 are two adjacent statements in this sequence, then The execution of I j is always immediately followed by the execution of I j+1 The execution of I j+1 is always immediate preceded by the execution of I j Edges between basic blocks represent potential flow of control Friday, October 21, 2011

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CFG for running example A = 4 t1 = A * B L1: t2 = t1/c if t2 < W goto L2 M = t1 * k t3 = M + I L2: H = I M = t3 - H if t3 ! 0 goto L3 goto L1 L3: halt How do we build this automatically? Friday, October 21, 2011
Constructing a CFG To construct a CFG where each node is a basic block Identify leaders : first statement of a basic block In program order, construct a block by appending subsequent statements up to, but not including, the next leader Identifying leaders First statement in the program Explicit target of any conditional or unconditional branch Implicit target of any branch Friday, October 21, 2011

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Partitioning algorithm Input: set of statements, stat(i) = i th statement in input Output: set of leaders , set of basic blocks where block(x) is the set of statements in the block with leader x Algorithm leaders = {1} //Leaders always includes first statement for i = 1 to | n | //| n | = number of statements if stat(i) is a branch, then leaders = leaders all potential targets end for worklist = leaders while worklist not empty do x = remove earliest statement in worklist block(x) = { x } for ( i = x + 1 ; i |n| and i leaders ; i++) block(x) = block(x) {i} end for end while Friday, October 21, 2011
Running example 1 A = 4

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}