Download presentation

Presentation is loading. Please wait.

Published byMae Knight Modified over 3 years ago

1
Stanford University CS243 Winter 2006 Wei Li 1 Control Dependence

2
CS243 Winter 2006 Stanford University 2 Control Dependence Introduction Introduction Formal Definition Formal Definition Optimal Control Dependence Computation Optimal Control Dependence Computation

3
CS243 Winter 2006 Stanford University 3 Example START a b c d END CFG b is control dependent on a c is control dependent on a a and d are control dependent on START

4
CS243 Winter 2006 Stanford University 4 Applications of CD Dead code elimination Dead code elimination Scheduling (hyper-block formation) Scheduling (hyper-block formation) Predication Predication …

5
CS243 Winter 2006 Stanford University 5 Simple Dead Code Elimination Mark inherently live statement live Mark inherently live statement live Store to memory, print, … Store to memory, print, … For each variable in these live statements, mark its definition statement live. For each variable in these live statements, mark its definition statement live. For each live statement, mark it live the node that it is control dependent on. For each live statement, mark it live the node that it is control dependent on. Remove everything that is not marked. Remove everything that is not marked.

6
CS243 Winter 2006 Stanford University 6 Example if (x > 0) { if (x > 0) { printf(“greater than zero”); printf(“greater than zero”); } The printf statement is inherently live. You also need to mark the “if (x>0)” live because the ‘print’ statement is control dependent on the ‘if’. The printf statement is inherently live. You also need to mark the “if (x>0)” live because the ‘print’ statement is control dependent on the ‘if’.

7
CS243 Winter 2006 Stanford University 7 Control Dependence Introduction Introduction Formal Definition Formal Definition Optimal Control Dependence Computation Optimal Control Dependence Computation

8
CS243 Winter 2006 Stanford University 8 Post-dominator Relation If X appears on every path from START to Y, then X dominates Y. If X appears on every path from START to Y, then X dominates Y. If X appears on every path from Y to END, then X postdominates Y. If X appears on every path from Y to END, then X postdominates Y. Postdominator Tree Postdominator Tree END is the root END is the root Any node Y other than END has ipdom(Y) as its parent Any node Y other than END has ipdom(Y) as its parent Parent, child, ancestor, descendant Parent, child, ancestor, descendant

9
CS243 Winter 2006 Stanford University 9 Control Dependence Relation There are two possible definitions. There are two possible definitions. Node w is control dependent on edge (u→v) if Node w is control dependent on edge (u→v) if w postdominates v w postdominates v If w ≠ u, w does not postdominate u If w ≠ u, w does not postdominate u Node w is control dependent on node u if there exists an edge u→v Node w is control dependent on node u if there exists an edge u→v w postdominates v w postdominates v If w ≠ u, w does not postdominate u If w ≠ u, w does not postdominate u

10
CS243 Winter 2006 Stanford University 10 Example S a b c d E CFG e E ? ? Pdom Tree abcde S→a b→c Control Dep Relation

11
CS243 Winter 2006 Stanford University 11 Example S a b c d E CFG e E e d S b c Pdom Tree a abcde S→a b→c Control Dep Relation

12
CS243 Winter 2006 Stanford University 12 Example S a b c d E CFG e E e d S b c Pdom Tree a abcde S→a √√√ b→c √√√ Control Dep Relation

13
CS243 Winter 2006 Stanford University 13 Control Dependence Queries CD(e): set of nodes control dependent on edge e CD(e): set of nodes control dependent on edge e CONDS(v): set of edges that node v is control dependent on CONDS(v): set of edges that node v is control dependent on

14
CS243 Winter 2006 Stanford University 14 Dominance Frontier Reverse control flow graph (RCFG) Reverse control flow graph (RCFG) Let X and Y be nodes in CFG. X in DF(Y) in CFG iff Y is control dependent on X in RCFG. Let X and Y be nodes in CFG. X in DF(Y) in CFG iff Y is control dependent on X in RCFG. DF(Y) in CFG = conds(Y) in RCFG, where conds(Y) is the set of nodes that Y is control dependent on. DF(Y) in CFG = conds(Y) in RCFG, where conds(Y) is the set of nodes that Y is control dependent on.

15
CS243 Winter 2006 Stanford University 15 Worst-case Size of CDR CFG abcd S→a d→a c→b Control Dependence Relation S a b c E d

16
CS243 Winter 2006 Stanford University 16 Worst-case Size of CDR CFG abcd S→a √√√√ d→a √√√√ c→b √√ Control Dependence Relation Size = O(n 2 ) S a b c E d

17
CS243 Winter 2006 Stanford University 17 Control Dependence Introduction Introduction Formal Definition Formal Definition Optimal Linear Control Dependence Computation Optimal Linear Control Dependence Computation

18
CS243 Winter 2006 Stanford University 18 APT APT: Augmented Postdominator Tree APT: Augmented Postdominator Tree which can be built in O(|E|) space and time which can be built in O(|E|) space and time which can be used to answer CD and CONDS queries in time proportional to output size which can be used to answer CD and CONDS queries in time proportional to output size Optimal control dependence computation Optimal control dependence computation Solution: reduced control computation to a graph problem called Roman Chariots Problem Solution: reduced control computation to a graph problem called Roman Chariots Problem

19
CS243 Winter 2006 Stanford University 19 Key Idea (I): Exploit Structure How to avoid building the entire control dependence relation (O(n 2 ))? How to avoid building the entire control dependence relation (O(n 2 ))? Nodes that are control dependent on an edge e form a simple path in the postdominator tree Nodes that are control dependent on an edge e form a simple path in the postdominator tree In a tree, a simple path is uniquely specified by its endpoints. In a tree, a simple path is uniquely specified by its endpoints. Pdom tree + endpoints of each control dependence path can be built in O(|E|) space and time Pdom tree + endpoints of each control dependence path can be built in O(|E|) space and time

20
CS243 Winter 2006 Stanford University 20 Example Epath S→a ? b→c ? S a b c d E CFG e Pdom Tree c E e d S b a Control Dep Relationabcde S→a √√√ b→c √√√ Path Array

21
CS243 Winter 2006 Stanford University 21 Example Epath S→a [a,e] b→c [c,b] S a b c d E CFG e Pdom Tree c E e d S b a Control Dep Relationabcde S→a √√√ b→c √√√ Path Array

22
CS243 Winter 2006 Stanford University 22 CD Queries How can we use the compact representation of the CDR (Control Dependence Relation) to answer queries for CD and CONDS sets in time proportional to output size? How can we use the compact representation of the CDR (Control Dependence Relation) to answer queries for CD and CONDS sets in time proportional to output size?

23
CS243 Winter 2006 Stanford University 23 Roman Chariots Problem CD(n): which cities are served by chariot n? CD(n): which cities are served by chariot n? CONDS(w): which chariots serve city w? CONDS(w): which chariots serve city w? Route # path I[Milano,Roma] II[Pompeii,Bologna] III[Venezia,Roma] Napoli Roma Milano Venezia Bologna Pompeii Verona Corleone

24
CS243 Winter 2006 Stanford University 24 CD(n): which cities are served by chariot n? Look up entry for chariot n in Route Array (say [x,y]) Look up entry for chariot n in Route Array (say [x,y]) Traverse nodes in tree T, starting at x and ending at y Traverse nodes in tree T, starting at x and ending at y Output all nodes encountered in traversal Output all nodes encountered in traversal Query time is proportional to output size Query time is proportional to output size

25
CS243 Winter 2006 Stanford University 25 CONDS(w): which chariots serve city w? For each chariot c in Route Array do For each chariot c in Route Array do Let route of c be [x,y]; Let route of c be [x,y]; If w is an ancestor of x and w is a descendant of y then If w is an ancestor of x and w is a descendant of y then Output c; Output c; Can we avoid examining all routes? Can we avoid examining all routes?

26
CS243 Winter 2006 Stanford University 26 Key Idea (II): Caching At each node in the tree, keep a list of chariot #’s whose bottom node is n. At each node in the tree, keep a list of chariot #’s whose bottom node is n. Chariot # route I[a,e] II[c,b] c E e d S b a {?}

27
CS243 Winter 2006 Stanford University 27 Key Idea (II): Caching At each node in the tree, keep a list of chariot #’s whose bottom node is n. At each node in the tree, keep a list of chariot #’s whose bottom node is n. Chariot # route I[a,e] II[c,b] c E e d S b a {I} {II}

28
CS243 Winter 2006 Stanford University 28 CONDS(w): which chariots serve city w? For each descendant d of w do For each descendant d of w do For each route c = [x,y] in list at d do For each route c = [x,y] in list at d do If w is a descendant of y then If w is a descendant of y then Output c; Output c; Query time is proportional to # of descendants + size of all lists at d Query time is proportional to # of descendants + size of all lists at d

29
CS243 Winter 2006 Stanford University 29 Sorting Lists Sort each list by decreasing length Sort each list by decreasing length Chariot # route I[e,d] II[e,c] III[e,b] IV[e,a] c E a d S b {IV,III,II,I} e

30
CS243 Winter 2006 Stanford University 30 CONDS(w): which chariots serve city w? For each descendant d of w do For each descendant d of w do For each route c = [x,y] in list at d do For each route c = [x,y] in list at d do If w is a descendant of y If w is a descendant of y then then Output c; Output c; else else break break Query time is proportional to size of output + # of descendants Query time is proportional to size of output + # of descendants

31
CS243 Winter 2006 Stanford University 31 Caching at All Nodes on Route Sort each list by decreasing length Sort each list by decreasing length c E a d b {IV,III,II,I} e c E a d b e {IV,III,II} {IV,III} {IV}

32
CS243 Winter 2006 Stanford University 32 Space Time Tradeoff Chariot # stored only at bottom node of the route Chariot # stored only at bottom node of the route Space: O(|V| + |A|) Space: O(|V| + |A|) Query Time: O(|V| + |Output|) Query Time: O(|V| + |Output|) Chariot # stored at all nodes on route Chariot # stored at all nodes on route Space: O(|V| * |A|) Space: O(|V| * |A|) Query Time: O(|Output|) Query Time: O(|Output|) V is the set of tree nodes, and A is the Route Array. V is the set of tree nodes, and A is the Route Array.

33
CS243 Winter 2006 Stanford University 33 Key idea (III): Caching Zones Divide tree into ZONES Divide tree into ZONES Nodes in Zone: Nodes in Zone: Boundary nodes: lowest nodes in zone Boundary nodes: lowest nodes in zone Interior nodes: all other nodes Interior nodes: all other nodes Query procedure: Query procedure: Visit only nodes below query node and in the same zone as query node Visit only nodes below query node and in the same zone as query node

34
CS243 Winter 2006 Stanford University 34 Caching Rule Boundary node: store all chariots serving node Boundary node: store all chariots serving node Interior node: store all chariots whose bottom node is that node Interior node: store all chariots whose bottom node is that node Algorithm: bottom-up, greedy zone construction Algorithm: bottom-up, greedy zone construction Query time: |A v | + |Z v | ≤ (α + 1) |A v | Query time: |A v | + |Z v | ≤ (α + 1) |A v | Space requirements ≤ |A| + |V| / α Space requirements ≤ |A| + |V| / α

35
CS243 Winter 2006 Stanford University 35 Constructing Zones (I) Invariant: for any node v, |Z v | ≤ α |A v | + 1, where α is a design parameter. Invariant: for any node v, |Z v | ≤ α |A v | + 1, where α is a design parameter. Query time for CONDS(v) Query time for CONDS(v) = O(|A v | + |Z v |) = O((α + 1)|A v | + 1) = O((α + 1)|A v | + 1) = O(|A v |) = O(|A v |)

36
CS243 Winter 2006 Stanford University 36 Constructing Zones (II) Build zones bottom-up, making them as large as possible without violating invariant Build zones bottom-up, making them as large as possible without violating invariant V is a leaf node, then make v a boundary node V is a leaf node, then make v a boundary node V is an interior node then V is an interior node then If (1 + ∑ u є children(v) |Z u |) > α |A v | + 1 If (1 + ∑ u є children(v) |Z u |) > α |A v | + 1 then make v a boundary node then make v a boundary node else make v an interior node else make v an interior node

37
CS243 Winter 2006 Stanford University 37 α = 1 (some caching) Zones: {a,b,c,d,e}, {f,g,h}, {E}, {S} Zones: {a,b,c,d,e}, {f,g,h}, {E}, {S} Boundary nodes: a, f, E, S Boundary nodes: a, f, E, S f c e b d {S→a, h→a} a g E h S 3 4 5 6 6 5 4 3 α |Av| + 1 {g→b} {f→c} {e→d} {} {S→a, h→a, g→a, f→c} {}

38
CS243 Winter 2006 Stanford University 38 α = >>(no caching) Zones: {a,b,c,d,e,f,g,h}, {E}, {S} Zones: {a,b,c,d,e,f,g,h}, {E}, {S} Boundary nodes: a, E, S Boundary nodes: a, E, S ∞ {} f c e b d {S→a, h→a} a g E h S ∞ α |Av| + 1 {g→b} {f→c} {e→d} {} ∞ ∞ ∞ ∞ ∞ ∞

39
CS243 Winter 2006 Stanford University 39 α = << (full caching) Zones: every node Zones: every node Boundary nodes: every node Boundary nodes: every node f c e b d {S→a, h→a} a g E h S 1 1 1 1 1 1 1 1 α |Av| + 1 {S→a, h→a, g→b} {S→a, h→a, g→b, f→c} {S→a, h→a, g→b, f→c, e→d} {S→a, h→a, g→a, f→c} {S→a, h→a, g→a} {S→a, h→a}

40
CS243 Winter 2006 Stanford University 40 APT (I) Postdominator tree with bidirectional edges Postdominator tree with bidirectional edges dfs-number[v]: integer dfs-number[v]: integer Used for ancestorship determination in CONDS query Used for ancestorship determination in CONDS query Boundary?[v]: boolean Boundary?[v]: boolean True if v is a boundary node, false otherwise True if v is a boundary node, false otherwise Used in CONDS query Used in CONDS query

41
CS243 Winter 2006 Stanford University 41 APT (II) L[v]: list pf chariots #’s/control dependences L[v]: list pf chariots #’s/control dependences Boundary node: all chariots serving v (all control dependences of v) Boundary node: all chariots serving v (all control dependences of v) Interior node: all chariots whose bottom node is v (all immediate control dependences of v) Interior node: all chariots whose bottom node is v (all immediate control dependences of v) Used in CONDS query Used in CONDS query

42
CS243 Winter 2006 Stanford University 42 Computational Complexity Query time: (α + 1) * output-size Query time: (α + 1) * output-size Space: |E| + |V|/α Space: |E| + |V|/α

43
CS243 Winter 2006 Stanford University 43 Reference “Optimal Control Dependence Computation and the Roman Chariots Problem”, Keshav Pingali, Gianfranco Bilardi, ACM Transactions on Programming Languages and Systems (TOPLAS), May 1997. http://iss.cs.cornell.edu/Publications/Pa pers/TOPLAS1997.pdf “Optimal Control Dependence Computation and the Roman Chariots Problem”, Keshav Pingali, Gianfranco Bilardi, ACM Transactions on Programming Languages and Systems (TOPLAS), May 1997. http://iss.cs.cornell.edu/Publications/Pa pers/TOPLAS1997.pdf

Similar presentations

OK

CS 206 Introduction to Computer Science II 03 / 25 / 2009 Instructor: Michael Eckmann.

CS 206 Introduction to Computer Science II 03 / 25 / 2009 Instructor: Michael Eckmann.

© 2018 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Free download ppt on probability for class 9 Ppt on nuclear family and joint family quotes Ppt on 60 years of indian parliament videos Topics for ppt on technology Ppt on world diabetes day images Ppt on world wide web Download ppt on uses of maths in daily life Ppt on save environment pictures Download ppt on palm island dubai Ppt on radio station