Download presentation
Presentation is loading. Please wait.
Published byAlexina Cox Modified over 9 years ago
1
U NIVERSITY OF M ASSACHUSETTS, A MHERST D EPARTMENT OF C OMPUTER S CIENCE Advanced Compilers CMPSCI 710 Spring 2003 Dominators, etc. Emery Berger University of Massachusetts, Amherst
2
U NIVERSITY OF M ASSACHUSETTS, A MHERST D EPARTMENT OF C OMPUTER S CIENCE 2 Dominators, etc. Last time Live variable analysis backwards problem Constant propagation algorithms def-use chains Today SSA-form dominators
3
U NIVERSITY OF M ASSACHUSETTS, A MHERST D EPARTMENT OF C OMPUTER S CIENCE 3 Def-Use Chains: Problem switch (j) case x: i à 1; break; case y: i à 2; break; case z: i à 3; break; switch (k) case x: a à i; break; case y: b à i; break; case z: c à i; break; worst-case size of graph = O(D*U) = O(N 2 )
4
U NIVERSITY OF M ASSACHUSETTS, A MHERST D EPARTMENT OF C OMPUTER S CIENCE 4 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 …])
5
U NIVERSITY OF M ASSACHUSETTS, A MHERST D EPARTMENT OF C OMPUTER S CIENCE 5 SSA Transformations v à 4 à v+5 v à 6 à v+7 v 1 à 4 à v 1 +5 v 2 à 6 à v 2 +7 Easy for straight-line code, but what about control flow? New variable for each assignment, rename uses
6
U NIVERSITY OF M ASSACHUSETTS, A MHERST D EPARTMENT OF C OMPUTER S CIENCE 6 -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
7
U NIVERSITY OF M ASSACHUSETTS, A MHERST D EPARTMENT OF C OMPUTER S CIENCE 7 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 */
8
U NIVERSITY OF M ASSACHUSETTS, A MHERST D EPARTMENT OF C OMPUTER S CIENCE 8 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
9
U NIVERSITY OF M ASSACHUSETTS, A MHERST D EPARTMENT OF C OMPUTER S CIENCE 9 SSA Example III switch (j) case x: i à 1; break; case y: i à 2; break; case z: i à 3; break; switch (k) case x: a à i; break; case y: b à i; break; case z: c à i; break;
10
U NIVERSITY OF M ASSACHUSETTS, A MHERST D EPARTMENT OF C OMPUTER S CIENCE 10 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
11
U NIVERSITY OF M ASSACHUSETTS, A MHERST D EPARTMENT OF C OMPUTER S CIENCE 11 Function Requirement Node Z needs function for V if: Z is convergence point for two paths originating at different nodes 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
12
U NIVERSITY OF M ASSACHUSETTS, A MHERST D EPARTMENT OF C OMPUTER S CIENCE 12 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] Also can be used to compute control dependence graph
13
U NIVERSITY OF M ASSACHUSETTS, A MHERST D EPARTMENT OF C OMPUTER S CIENCE 13 Control Dependence Graph Identifies conditions affecting statement execution Statement is control dependent on branch if: one edge from branch definitely causes statement to execute another edge can cause statement to be skipped
14
U NIVERSITY OF M ASSACHUSETTS, A MHERST D EPARTMENT OF C OMPUTER S CIENCE 14 Control Dependence Example if (a == 1) q à 2 else if (a == 2) goto B goto A b à 1 A: c à 1 B: d à 1 if (a==1) q à 2 b à 1 c à 1 if (a==2) d à 1 then else
15
U NIVERSITY OF M ASSACHUSETTS, A MHERST D EPARTMENT OF C OMPUTER S CIENCE 15 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 vertices that dominate v Entry dominates every vertex Reflexive:a dom a Transitive:a dom b, b dom c ! a dom c Antisymmetric:a dom b, b dom a ! b=a Notice: in SSA form, a definition dominates its use
16
U NIVERSITY OF M ASSACHUSETTS, A MHERST D EPARTMENT OF C OMPUTER S CIENCE 16 Finding Dominators Dom(v) = {v} Å p 2 PRED(v) Dom(p) Algorithm: DOM(Entry) = {Entry} for v 2 V-{Entry} DOM(v) = V repeat changed = false for n 2 V-{Entry} olddom = DOM(n) DOM(n) = {n} [ ( Å p 2 PRED(n) DOM(p)) if DOM(n) olddom changed = true
17
U NIVERSITY OF M ASSACHUSETTS, A MHERST D EPARTMENT OF C OMPUTER S CIENCE 17 Dominator Algorithm Example Dom A (Entry) B CD E FG (Exit) Dom DOM(Entry) = {Entry} for v 2 V-{Entry} DOM(v) = V repeat changed = false for n 2 V-{Entry} olddom = DOM(n) DOM(n) = {n} [ ( Å p 2 PRED(n) DOM(p)) if DOM(n) \neq olddom changed = true
18
U NIVERSITY OF M ASSACHUSETTS, A MHERST D EPARTMENT OF C OMPUTER S CIENCE 18 Other Dominators Strict dominators Dom!(v) = Dom(v) – {v} antisymmetric & transitive Immediate dominator Idom(v) = closest strict dominator of v d Idom v if d Dom! v and 8 w 2 Dom!(v): w Dom d antisymmetric Idom induces tree
19
U NIVERSITY OF M ASSACHUSETTS, A MHERST D EPARTMENT OF C OMPUTER S CIENCE 19 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
20
U NIVERSITY OF M ASSACHUSETTS, A MHERST D EPARTMENT OF C OMPUTER S CIENCE 20 Dominator Tree A (Entry) B CD E FG (Exit) A (Entry) B CD E FG (Exit)
21
U NIVERSITY OF M ASSACHUSETTS, A MHERST D EPARTMENT OF C OMPUTER S CIENCE 21 Inverse Dominators Dom -1 (v) = set of all vertices dominated by v reflexive, antisymmetric, transitive
22
U NIVERSITY OF M ASSACHUSETTS, A MHERST D EPARTMENT OF C OMPUTER S CIENCE 22 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):
23
U NIVERSITY OF M ASSACHUSETTS, A MHERST D EPARTMENT OF C OMPUTER S CIENCE 23 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|( 9 P 2 PRED(Y): X Dom P) Æ q X Dom! Y)
24
U NIVERSITY OF M ASSACHUSETTS, A MHERST D EPARTMENT OF C OMPUTER S CIENCE 24 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
25
U NIVERSITY OF M ASSACHUSETTS, A MHERST D EPARTMENT OF C OMPUTER S CIENCE 25 Dominance Frontier Example S X A B DF(X) = {Y|( 9 P 2 PRED(Y): X Dom P) Æ q X Dom! Y) node y is in dominance frontier of node x if: x dominates predecessor of y but does not strictly dominate y
26
U NIVERSITY OF M ASSACHUSETTS, A MHERST D EPARTMENT OF C OMPUTER S CIENCE 26 Dominance Frontier Example Dom -1 SUCC(Dom -1 ) DF A (Entry) B CD E FG (Exit) Dom -1 SUCC(Dom -1 ) DF Dom -1 SUCC(Dom -1 ) DF Dom -1 SUCC(Dom -1 ) DF Dom -1 SUCC(Dom -1 ) DF Dom -1 SUCC(Dom -1 ) DF Dom -1 SUCC(Dom -1 ) DF DF(v) = SUCC(Dom -1 (v)) – Dom! -1 (v) where Dom! -1 (v) = Dom -1 (v) – {v}
27
U NIVERSITY OF M ASSACHUSETTS, A MHERST D EPARTMENT OF C OMPUTER S CIENCE 27 Next Time Computing dominance frontiers Computing SSA form
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.