1 / 43

Control Dependence

Control Dependence. Control Dependence. Introduction Formal Definition Optimal Control Dependence Computation. Example. b is control dependent on a c is control dependent on a a and d are control dependent on START. START. a. c. b. d. CFG. END. Applications of CD.

alvis
Télécharger la présentation

Control Dependence

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Control Dependence

  2. Control Dependence • Introduction • Formal Definition • Optimal Control Dependence Computation

  3. Example • b is control dependent on a • c is control dependent on a • a and d are control dependent on START START a c b d CFG END

  4. Applications of CD • Dead code elimination • Scheduling (hyper-block formation) • Predication • …

  5. Simple Dead Code Elimination • Mark inherently live statement live • Store to memory, print, … • 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. • Remove everything that is not marked.

  6. Example • if (x > 0) { • 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’.

  7. Control Dependence • Introduction • Formal Definition • Optimal Control Dependence Computation

  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 Y to END, then X postdominates Y. • Postdominator Tree • END is the root • Any node Y other than END has ipdom(Y) as its parent • Parent, child, ancestor, descendant

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

  10. Example E S CFG ? ? Pdom Tree a b c e d E Control Dep Relation

  11. Example E S CFG e S b Pdom Tree a a d c b c e d E Control Dep Relation

  12. Example E S CFG e S b Pdom Tree a a d c b c e d E Control Dep Relation

  13. Control Dependence Queries • CD(e): set of nodes control dependent on edge e • CONDS(v): set of edges that node v is control dependent on

  14. Dominance Frontier • 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. • DF(Y) in CFG = conds(Y) in RCFG, where conds(Y) is the set of nodes that Y is control dependent on.

  15. S a b c d E Worst-case Size of CDR CFG Control Dependence Relation

  16. S a b c d E Worst-case Size of CDR CFG Control Dependence Relation Size = O(n2)

  17. Control Dependence • Introduction • Formal Definition • Optimal Linear Control Dependence Computation

  18. APT • APT: Augmented Postdominator Tree • 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 • Optimal control dependence computation • Solution: reduced control computation to a graph problem called Roman Chariots Problem

  19. Key Idea (I): Exploit Structure • How to avoid building the entire control dependence relation (O(n2))? • 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. • Pdom tree + endpoints of each control dependence path can be built in O(|E|) space and time

  20. E e S b a d c Example S CFG a Path Array Pdom Tree b c e d E Control Dep Relation

  21. E e S b a d c Example S CFG a Path Array Pdom Tree b c e d E Control Dep Relation

  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?

  23. Roman Chariots Problem Roma • CD(n): which cities are served by chariot n? • CONDS(w): which chariots serve city w? Milano Bologna Napoli Verona Venezia Pompeii Corleone

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

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

  26. E e S b a d c Key Idea (II): Caching • At each node in the tree, keep a list of chariot #’s whose bottom node is n. {?} {?}

  27. E e S b a d c Key Idea (II): Caching • At each node in the tree, keep a list of chariot #’s whose bottom node is n. {I} {II}

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

  29. Sorting Lists • Sort each list by decreasing length E a S b c d e {IV,III,II,I}

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

  31. Caching at All Nodes on Route • Sort each list by decreasing length E E a a {IV} b b {IV,III} c c {IV,III,II} d d {IV,III,II,I} e e {IV,III,II,I} {IV,III,II,I}

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

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

  34. Caching Rule • Boundary node: store all chariots serving node • Interior node: store all chariots whose bottom node is that node • Algorithm: bottom-up, greedy zone construction • Query time: |Av| + |Zv| ≤ (α + 1) |Av| • Space requirements ≤ |A| + |V| / α

  35. Constructing Zones (I) • Invariant: for any node v, |Zv| ≤ α|Av| + 1, where α is a design parameter. • Query time for CONDS(v) = O(|Av| + |Zv|) = O((α + 1)|Av| + 1) = O(|Av|)

  36. Constructing Zones (II) • 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 an interior node then • If (1 + ∑u є children(v) |Zu|) > α|Av| + 1 • then make v a boundary node • else make v an interior node

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

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

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

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

  41. APT (II) • L[v]: list pf chariots #’s/control dependences • 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) • Used in CONDS query

  42. Computational Complexity • Query time: (α + 1) * output-size • Space: |E| + |V|/α

  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/Papers/TOPLAS1997.pdf

More Related