Download presentation

Presentation is loading. Please wait.

Published byGordon Coghill Modified about 1 year ago

1
1 SSA review Each definition has a unique name Each use refers to a single definition The compiler inserts -functions at points where different control flow paths meet. To find where -functions should be placed, we compute the Dominance Frontier of each BB Intuition: The nodes in the dominance frontier of B are destinations of the edges that leave an area dominated by B. Since those destinations are not dominated by B, there must be some other path from the entry to them. Therefore, they must be convergence points, and we need to place functions in them for any variables defined in B.

2
2 Dominance frontier algorithm compute the dominator tree for each X in a bottom-up traversal of the tree, do DF(X) := { } for each Y Succ (X) do if (idom (Y) X) then DF(X) := DF(X) {Y} end for for each Z in children(X) do for each W DF(Z) do if (idom (W) X) then DF(X) := DF(X) {Y} end for DF local DF up

3
3 Inserting -functions Intuition: If there is a definition for x in a basic block B, insert a - function in each basic block in DF(B). The -function should have as many arguments as the number of B's predecessors Algorithm sketch: Traverse all BBs and, for each variable x, note which BBs contain a definition of x. For each variable x Pick a BB n where x is defined Insert a -function for x in each m in DF(n) (unless it already contains one) Add m in the list of BBs where x is defined.

4
4 Renaming variables in -functions When the -functions are inserted, the variables involved are not named (subscripted). This is done at the next stage. Basics: The variables will be renamed by traversing the dominator tree in pre-order. We will use a stack for each variable, to keep track of the most recent definition After uses and definitions in a BB have been renamed, recurse on its children We pop the stack after we've been through the children of a BB in the dominator tree

5
5 Renaming variables in -functions for each global name i counter[i] 0 stack[i] Ø call Rename(B 0 ) NewName(n) i counter[n] counter[n] counter[n] + 1 push n i onto stack[n] return n i Rename(b) for each -function in b, x (…) rename x as NewName(x) for each operation “x y op z” in b rewrite y as top(stack[y]) rewrite z as top(stack[z]) rewrite x as NewName(x) for each successor of b in the CFG rewrite appropriate parameters for each child c of b in dom. tree Rename(c) for each operation “x y op z” in b pop(stack[x]) counter: keeps track of #defs stack: keeps track of subscript

6
6 read(n) a := 1 b := 1 n <= 1 i := 2 i<=n a := n b := b+1 a == b a := b+1 b := n return n B1 B2 B3 B4 B5 B6 B1 B2B6 B3 B4B5 B8 {B7}{B7,B8} {B3,B8} {B8} {} i:=i+1 B7 {B3} a b i defined in B1, B4, B5 nB1 B1, B4, B5 B2, B7 -functions in B7, B3, B8 B8, B3 usually, we insert a predecessor to exit and place the functions there exit B8

7
7 read(n) a := 1 b := 1 n <= 1 i := 2 i:= (i,i) a:= (a,a) b:= (b,b) i<=n a := n b := b+1 a == b a := b+1 b := n return n a:= (a,a) b:= (b,b) i:= (i,i) B1 B2 B3 B4 B5 B6 B1 B2B6 B3 B4B5 B8 {B7}{B7,B8} {B3,B8} {B8} {} a:= (a,a) b:= (b,b) i:=i+1 B7 {B3} a b i defined in B1, B4, B5 nB1 B1, B4, B5 B2, B7 -functions in B7, B3, B8 B8, B3 exit B8

8
8 read(n0) a0 := 1 b0 := 1 n0 <= 1 i := 2 i:= (i,i) a:= (a,a) b:= (b,b) i<=n a := n b := b+1 a == b a := b+1 b := n return n a:= (a,a) b:= (b,b) i:= (i,i) B1 B2 B3 B4 B5 B6 B1 B2B6 B3 B4B5 B8 {B7}{B7,B8} {B3,B8} {B8} {} a:= (a,a) b:= (b,b) i:=i+1 B7 {B3} Counters 0000 abni Stacks Before processing B1 Counters 1110 a a0a0 b0b0 n0n0 bni Stacks After processing B1 (but before recursive call) exit B8

9
9 read(n0) a0 := 1 b0 := 1 n0 <= 1 i0 := 2 i:= (i,i0) a:= (a,a0) b:= (b,b0) i<=n a := n b := b+1 a == b a := b+1 b := n return n a:= (a,a) b:= (b,b) i:= (i,i) B1 B2 B3 B4 B5 B6 B1 B2B6 B3 B4B5 B8 {B7}{B7,B8} {B3,B8} {B8} {} a:= (a,a) b:= (b,b) i:=i+1 B7 {B3} Counters 1110 a a0a0 b0b0 n0n0 bni Stacks Before processing B2 After processing B2 Counters 1111 a a0a0 b0b0 n0n0 bni Stacks i0i0 exit B8

10
10 i1i1 read(n0) a0 := 1 b0 := 1 n0 <= 1 i0 := 2 i1:= (i,i0) a1:= (a,a0) b1:= (b,b0) i1<= n0 a := n b := b+1 a == b a := b+1 b := n return n a:= (a,a) b:= (b,b) i:= (i,i) B1 B2 B3 B4 B5 B6 B1 B2B6 B3 B4B5 B8 {B7}{B7,B8} {B3,B8} {B8} {} a:= (a,a) b:= (b,b) i:=i+1 B7 {B3} After processing B3 Counters 2212 a n0n0 bni Stacks i0i0 Before processing B3 Counters 1111 a a0a0 b0b0 n0n0 bni Stacks i0i0 a1a1 b1b1 b0b0 a0a0 exit B8

11
11 read(n0) a0 := 1 b0 := 1 n0 <= 1 i0 := 2 i1:= (i,i0) a1:= (a,a0) b1:= (b,b0) i1<= n0 a := n b := b+1 a == b a2 := b1+1 b2 := n0 return n a:= (a,a) b:= (b,b) i:= (i,i) B1 B2 B3 B4 B5 B6 B1 B2B6 B3 B4B5 B8 {B7}{B7,B8} {B3,B8} {B8} {} a:= (a2,a) b:= (b2,b) i:=i+1 B7 {B3} After processing B4 While processing B4 i1i1 Counters 3312 a n0n0 bni Stacks i0i0 a1a1 b1b1 b0b0 a0a0 i1i1 Counters 3312 a n0n0 bni Stacks i0i0 a1a1 b1b1 b0b0 a0a0 a2a2 b2b2 exit B8

12
12 read(n0) a0 := 1 b0 := 1 n0 <= 1 i0 := 2 i1:= (i,i0) a1:= (a,a0) b1:= (b,b0) i1<= n0 a3 := n0 b3 := b1+1 a3 == b3 a2 := b1+1 b2 := n0 return n a:= (a3,a) b:= (b3,b) i:= (i1,i) B1 B2 B3 B4 B5 B6 B1 B2B6 B3 B4B5 B8 {B7}{B7,B8} {B3,B8} {B8} {} a:= (a2,a3) b:= (b2,b3) i:=i+1 B7 {B3} After processing B5 While processing B5 i1i1 Counters 4412 a n0n0 bni Stacks i0i0 a1a1 b1b1 b0b0 a0a0 i1i1 Counters 4412 a n0n0 bni Stacks i0i0 a1a1 b1b1 b0b0 a0a0 a3a3 b3b3 exit B8

13
13 read(n0) a0 := 1 b0 := 1 n0 <= 1 i0 := 2 i1:= (i2,i0) a1:= (a4,a0) b1:= (b4,b0) i1<= n0 a3 := n0 b3 := b1+1 a3 == b3 a2 := b1+1 b2 := n0 return n a:= (a3,a) b:= (b3,b) i:= (i1,i) B1 B2 B3 B4 B5 B6 B1 B2B6 B3 B4B5 B8 {B7}{B7,B8} {B3,B8} {B8} {} a4:= (a2,a3) b4:= (b2,b3) i2:=i1+1 B7 {B3} After processing B7 While processing B7 Counters 5513 a n0n0 bni Stacks b0b0 a0a0 i1i1 Counters 5513 a n0n0 bni Stacks i0i0 a1a1 b1b1 b0b0 a0a0 a4a4 b4b4 i2i2 exit B8

14
14 read(n0) a0 := 1 b0 := 1 n0 <= 1 i0 := 2 i1:= (i2,i0) a1:= (a4,a0) b1:= (b4,b0) i1<= n0 a3 := n0 b3 := b1+1 a3 == b3 a2 := b1+1 b2 := n0 return n0 a:= (a3,a0) b:= (b3,b0) i:= (i1,i) B1 B2 B3 B4 B5 B6 B1 B2B6 B3 B4B5 B8 {B7}{B7,B8} {B3,B8} {B8} {} a4:= (a2,a3) b4:= (b2,b3) i2:=i1+1 B7 {B3} After processing B6 Before processing B6 Counters 5513 a n0n0 bni Stacks b0b0 a0a0 Counters 5513 a n0n0 bni Stacks b0b0 a0a0 exit B8

15
15 read(n0) a0 := 1 b0 := 1 n0 <= 1 i0 := 2 i1:= (i2,i0) a1:= (a4,a0) b1:= (b4,b0) i1<= n0 a3 := n0 b3 := b1+1 a3 == b3 a2 := b1+1 b2 := n0 return n0 a5:= (a3,a0) b5:= (b3,b0 ) i3:= (i1,i) B1 B2 B3 B4 B5 B6 B1 B2B6 B3 B4B5 B8 {B7}{B7,B8} {B3,B8} {B8} {} a4:= (a2,a3) b4:= (b2,b3) i2:=i1+1 B7 {B3} After processing B8 While processing B8 Counters 6614 abni Stacks Counters 6614 a n0n0 bni Stacks i3i3 b0b0 a0a0 exit B8 a5a5 b5b5

Similar presentations

© 2016 SlidePlayer.com Inc.

All rights reserved.

Ads by Google