lecture-09

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

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

Control fow graphs and loop optimizations Monday, November 8, 2010

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

View Full Document
Agenda Building control fow graphs Low level loop optimizations Code motion Strength reduction Unrolling High level loop optimizations Loop Fusion Loop interchange Loop tiling Monday, November 8, 2010
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 fow of a program How control transfers between basic blocks due to: Conditionals Loops Monday, November 8, 2010

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 Monday, November 8, 2010
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) Monday, November 8, 2010

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 Monday, November 8, 2010
Control fow 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 fow oF control Monday, November 8, 2010

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? Monday, November 8, 2010
Constructing a CFG To construct a CFG where each node is a basic block Identify leaders : ±rst 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 Monday, November 8, 2010

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 Frst 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
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 38

lecture-09 - Control ow graphs and loop optimizations...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online