lecture-09-6up

# lecture-09-6up - Agenda Control ow graphs and loop...

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

Control fow graphs and loop optimizations Monday, November 8, 2010 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 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 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

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

View Full Document
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 C±G 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 C±G To construct a C±G 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 ±irst statement in the program Explicit target oF any conditional or unconditional branch Implicit target oF any branch Monday, November 8, 2010 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 ²rst 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.

## This note was uploaded on 02/19/2012 for the course ECE 468 taught by Professor Test during the Fall '08 term at Purdue University-West Lafayette.

### Page1 / 7

lecture-09-6up - Agenda Control ow graphs and loop...

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

View Full Document
Ask a homework question - tutors are online