Download presentation

Presentation is loading. Please wait.

Published byDouglas Sommerfield Modified over 2 years ago

1
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Optimizing Compilers CISC 673 Spring 2009 Static Single Assignment John Cavazos University of Delaware

2
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT 2 Outline Def-use chains SSA-form dominators

3
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT 3 Def-Use Chain A tuple that connects 2 data-flow events is a chain Chains express data-flow relationships directly Chains provide a graphical representation Chains jump across unrelated code, simplifying search We can build chains efficiently Four interesting types of chains Def-Use chains are the most common

4
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT 4 Def-Use Chains Example

5
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT 5 Building Def-Use Chains To construct D EF -U SE chains, we solve reaching definitions ( YADFP ) A definition d of some variable v reaches an operation i if and only if i reads v and there is a v-clear path from d to i

6
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT D EF -U SE Chains Birth points x 17 - 4 x a + b x y - z x 13 z x * q s w - x Computes of three values here Computes of four values here Value is born here 17 - 4 y - z Value is born here 17 - 4 y - z 13 Value is born 17 - 4 y - z 13 a+b

7
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT D EF -U SE Chains Birth points x 17 - 4 x a + b x y - z x 13 z x * q s w - x We should be able to compute the values that we need with fewer meet operations, if only we can find these birth points. Need to identify birth points Need to insert some artifact to force the evaluation to follow the birth points Enter Static Single Assignment form

8
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT D EF -U SE Chains Making Birth Points Explicit x 0 17 - 4 x 5 a + b x 1 y - z x 3 13 z x 4 * q s w - x 6 There are three birth points for x

9
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT D EF -U SE Chains Making Birth Points Explicit x 0 17 - 4 x 5 a + b x 1 y - z x 3 13 z x 4 * q s w - x 6 x 2 Ø(x 1,x 0 ) x 4 Ø(x 3,x 2 ) x 6 Ø(x 5,x 4 ) Each needs a definition to reconcile the values of x Insert a ø-function at each birth point Rename values so each name is defined once Now, each use refers to one definition Static Single Assignment Form

10
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT 10 SSA Form Static single assignment each assignment to variable gets unique name all uses reached by that assignment are renamed exactly one def per use sparse program representation: use-def chain = (variable, [use 1, use 2 …])

11
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT High-Level Definition Each assignment to a variable is given a unique name All of the uses reached by that assignment are renamed Easy for straight-line code V 4 V 0 4 V + 5 V 0 + 5 V 6 V 1 6 V + 7 V 1 + 7

12
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT What About Control Flow? if (…) X 5X 3 Y X B1 B2B3 B4 if (…) X 0 5X 1 3 X 2 (X 0, X 1 ) Y 0 X 2 B1 B4 B2B3 Before SSA After SSA -nodes: combine values from distinct edges (join points)

13
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT What About Control Flow? X 1 X X + 1 B1 B2 X 0 1 X 1 (X 2, X 0 ) X 2 X 1 + 1 B1 B2 Before SSA After SSA

14
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT 14 -Functions At each join, add special assignment: “ function”: operands indicate which assignments reach join j th operand = j th predecessor If control reaches join from j th predecessor, then value of (R,S,…) is value of j th operand

15
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT 15 SSA Transformation, function if P then v = 4 else v = 6 /* use v */ if P then v 1 = 4 else v 2 = 6 V 3 = (v 1, v 2 ) /* use v3 */

16
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT 16 SSA Example II V = 1 while (v < 10) v = v + 1 1: v = 1 2: if (v < 10) 3: v = v + 1 4: goto 2

17
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT 17 Placing functions Safe to put functions for every variable at every join point But: inefficient – not necessarily sparse! loses information Goal: minimal nodes, subject to need

18
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT 18 Function Requirement Node Z needs function for v if: Z is convergence point for two paths both originating nodes contain assignments to v or also need functions for v v = 1v = 2 Z v 1 = 1v 2 = 2 v 3 = (v 1,v 2 ) Z

19
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT 19 Minimal Placement of functions Naïve computation of need is expensive: must examine all triples in graph Can be done in O(N) time Relies on dominance frontier computation [Cytron et al., 1991]

20
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT 20 Dominators Before we do dominance frontiers, we need to discuss other dominance relationships x dominates y (x dom y) in CFG, all paths to y go through x Dom(v) = set of all nodes that dominate v Entry dominates every node Every node dominates itself Notice: in SSA form, a definition dominates its use

21
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT 21 Finding Dominators Dom(n) = {n} ∪ ( ∩ p ∈ PRED(n) Dom(p) ) Algorithm: DOM(Entry) = {Entry} For n ∈ V-{Entry} DOM(n) = V repeat changed = false for n ∈ V-{Entry} olddom = DOM(n) DOM(n) = {n} ∪ ( ∩ p ∈ PRED(n) DOM(p)) if DOM(n) olddom changed = true

22
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT 22 Dominator Algorithm Example Dom A (Entry) B CD E FG (Exit) Dom DOM(Entry) = {Entry} for v ∈ V-{Entry} DOM(v) = V repeat changed = false for n ∈ V-{Entry} olddom = DOM(n) DOM(n) = {n} ∪ ( ∩ p ∈ 2 PRED(n) DOM(p)) if DOM(n) olddom changed = true

23
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT 23 Dominator Algorithm Example Dom: A A (Entry) B CD E FG (Exit) Dom: A,B Dom: A, B, CDom: A, B, D Dom: A, B, E Dom: A, B, E GDom: A, B, E, F DOM(Entry) = {Entry} for v ∈ V-{Entry} DOM(v) = V repeat changed = false for n ∈ V-{Entry} olddom = DOM(n) DOM(n) = {n} ∪ ( ∩ p ∈ 2 PRED(n) DOM(p)) if DOM(n) olddom changed = true

24
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT 24 Other Dominators Strict dominators Dom!(v) = Dom(v) – {v} Immediate dominator Idom(v) = closest strict dominator of v Idom induces tree

25
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT 25 Dominator Example Dom Dom! Idom A (Entry) B CD E FG (Exit) Dom Dom! Idom Dom Dom! Idom Dom Dom! Idom Dom Dom! Idom Dom Dom! Idom Dom Dom! Idom

26
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT 26 Dominator Tree A (Entry) B CD E FG (Exit) A (Entry) B CD E FG (Exit)

27
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT 27 Inverse Dominators Dom -1 (v) = set of all nodes that v dominates

28
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT 28 Inverse Dominator Example A (Entry) B CD E FG (Exit) Dom(A):{A} Dom -1 (A): Dom(B):{A,B} Dom -1 (B): Dom(C):{A,B,C} Dom -1 (C): Dom(D):{A,B,D} Dom -1 (D): Dom(E):{A,B,E} Dom -1 (E): Dom(F):{A,B,E,F} Dom -1 (F): Dom(G):{A,B,E,G} Dom -1 (G):

29
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT 29 Finally: Dominance Frontiers! The dominance frontier DF(X) is set of all nodes Y such that: X dominates a predecessor of Y But X does not strictly dominate Y DF(X) = {Y|( ∃ P ∈ PRED(Y): X Dom P) and X Dom! Y} Intuitively: The fringe just beyond the region X dominates

30
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT 30 Why Dominance Frontiers Dominance frontier criterion: if node x contains def of a, then any node z in DF(x) needs a function for a intuition: at least two non-intersecting paths converge to z, and one path must contain node strictly dominated by x

31
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT 31 Dominance Frontier Example S X A B DF(X) = {Y|( ∃ P ∈ PRED(Y): X Dom P) and X Dom! Y) node y is in dominance frontier of node x if: x dominates predecessor of y but does not strictly dominate y

32
U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT 32 Next Time Computing dominance frontiers Computing SSA form

Similar presentations

OK

Generating SSA Form (mostly from Morgan). Why is SSA form useful? For many dataflow problems, SSA form enables sparse dataflow analysis that –yields the.

Generating SSA Form (mostly from Morgan). Why is SSA form useful? For many dataflow problems, SSA form enables sparse dataflow analysis that –yields the.

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on job rotation pros Ppt on edge detection algorithm Ppt on vegetarian and non vegetarian couples Download ppt on minimum wages act 1948 Jit ppt on manufacturing definition Ppt on marketing management Ppt on combination of resistance bands Convert free pdf to ppt online convert Ppt on marketing management of shampoo Ppt on conservation of natural resources for class 10