lecture-10-6up

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

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

View Full Document Right Arrow Icon
Control fow graphs and loop optimizations Friday, October 21, 2011 Agenda Building control fow 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 fow oF a program How control transFers between basic blocks due to: Conditionals Loops Friday, October 21, 2011 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 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
Background image of page 1

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

View Full DocumentRight Arrow Icon
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 Friday, October 21, 2011 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? Friday, October 21, 2011 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 Friday, October 21, 2011 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
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 7

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

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online