Presentation is loading. Please wait.

Presentation is loading. Please wait.

Copyright 2003, Keith D. Cooper & Linda Torczon, all rights reserved.

Similar presentations


Presentation on theme: "Copyright 2003, Keith D. Cooper & Linda Torczon, all rights reserved."— Presentation transcript:

1 Definition-Use Chains COMP 512 Rice University Houston, Texas Fall 2003
Copyright 2003, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in Comp 512 at Rice University have explicit permission to make copies of these materials for their personal use.

2 Information Chains 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 chain Def-Use chains are the most common COMP 512, Fall 2003

3 Information Chains Example a  5 b  3 c  b + 2 d  a - 2 e  a + b
e  e + c e  13 def-use chains d is dead It has no use f  2 + e Write f COMP 512, Fall 2003 *

4 X  DEFS(A,y )  y  USES(A,x )
Notation Assume that,  operation i and each variable v, DEFS(v,i ) is the set of operations that may have defined v most recently before i, along some path in the CFG USES(v,i ) is the set of operations that may use the value of v computed at i, along some path in the CFG X  DEFS(A,y )  y  USES(A,x ) To construct DEF-USE 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 v-clear  no definition of v on the path Prior definition of v in same block  |DEFS(v,i )| = 1 No prior definition  |DEFS(v,i )| ≥ 1 The chains are non-local in this case COMP 512, Fall 2003

5 REACHES(n ) = ppreds(n) DEDEF(p )  (REACHES(p )  DEFKILL(p ))
Domain is |DEFINITIONS|, same as number of operations Reaching Definitions The equations REACHES(n0 ) = Ø REACHES(n ) = ppreds(n) DEDEF(p )  (REACHES(p )  DEFKILL(p )) REACHES(n ) is the set of definitions that reach block n DEDEF(n) is the set of definitions in n that reach the end of n DEFKILL(n) is the set of defs obscured by a new def in n Computing REACHES(n) Use any data-flow method (rapid framework) Zadeck shows a simple linear-time scheme Form of f is same as in AVAIL F.K. Zadeck, “Incremental data-flow analysis in a structured program editor,” Proceedings of the SIGPLAN 84 Conf. on Compiler Construction, June, 1984, pages COMP 512, Fall 2003 *

6 Building DEFS sets The Plan 1. Find basic blocks & build the CFG
2.  block b, compute REACHES(b) (to the fixed point) 3.  block b,  operation i,  referenced name v, Set DEFS(v,i ) according to the earlier rule A.) If there is a prior definition, d, of v in b DEFS(v,i )  d B.) Otherwise DEFS(v,i )  {d | d defines v & d  REACHES(b ) } To build USES Invert DEFS, or Solve reachable uses, and use the analogous construction COMP 512, Fall 2003

7 Building DEF-USE Chains
Miscellany Domain of REACHES is the set of definitions ( |operations|) Domain of DEFS & USES is also definitions Need a compact representation of DEFS & USES Detecting Anomalies DEFS(v,i ) = Ø implies use of a never initialized variable Add a definition for each v to n0 to detect larger set of anomalies If initial def  DEFS(v,i ) then  a path with no initialization And, how do we use these information chains? COMP 512, Fall 2003 *

8 Constant Propagation over DEF-USE Chains
Worklist  Ø For i  1 to number of operations if in1 of operation i is a constant ci then Value(in1,i )  ci else Value(in1,i )  T if in2 of operation i is a constant cj then Value(in2,i )  cj else Value(in2,i )  T if (Value(in1,i ) is a constant & Value(in2,i ) is a constant) then Value(out,i )  evaluate op i Worklist  Worklist  {i } else Value(out,i )  T Initialization Step while ( Worklist ≠ Ø) remove a definition i from WorkList for each j  USES(out,i ) set x so that out of i is inx of j Value(inx,j )  Value(inx,j )  Value(out,,i ) if (Value(in1,j ) is a constant & Value(in2,j ) is a constant) then Value(out,j )  evaluate op j Worklist  Worklist  {j } else if (Value(in1,j ) is  or Value(in2,j ) is ) then Value(out,j )   Propagation Step Any T left after fixed point derives from unitinitalized value: what should we do? COMP 512, Fall 2003

9 Constant Propagation over DEF-USE Chains
Optimism Optimism This version of the algorithm is an optimistic formulation Initializes values to Prior version used  (implicit ) Optimistic initializations Leads to i 12  = 12 12 12 Pessimistic initializations Leads to i 12  =  i  12 while ( … ) x  i * 17 j  i i  … i  j Clear that i is always 12 at def of x In general Optimism helps inside loops Largely a matter of initial value M.N. Wegman & F.K. Zadeck, Constant propagation with conditional branches, ACM TOPLAS, 13(2), April 1991, pages 181–210. * COMP 512, Fall 2003

10 Constant Propagation over DEF-USE Chains
Complexity Initial step takes O(1) time per operation Propagation takes |USES(v,i )| for each i pulled from Worklist Summing over all ops, becomes |edges in Def-Use graph| A definition can be on the worklist twice (lattice height) O(|operations| + |edges in DU graph|) Can we do better? Not on the def-use chains … Would like to compute  when new values are “born” Where control flow brings chains together … COMP 512, Fall 2003

11 Constant Propagation over DEF-USE Chains
Birth points Value is born here  y - z  y - z  13 Value is born  13  a+b 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 x  x  a + b x  y - z Computes  of three values here Computes  of four values here x  13 z  x * q s  w - x COMP 512, Fall 2003

12 Constant Propagation over DEF-USE Chains
Making Birth Points Explicit x0  There are three birth points for x x5  a + b x1  y - z x3  13 z  x4 * q s  w - x6 COMP 512, Fall 2003 *

13 Constant Propagation over DEF-USE Chains
Making Birth Points Explicit x0  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 x5  a + b x1  y - z x2  Ø(x1,x0) x4  Ø(x3,x2) x6  Ø(x5,x4) x3  13 z  x4 * q s  w - x6 COMP 512, Fall 2003 *

14 Constant Propagation over DEF-USE Chains
Making Birth Points Explicit x0  How do we build SSA form? Simple algorithm 1. Insert a ø at each join point for each name 2. Rename to get single definition & single use This produces Correct SSA form More ø’s than any other known algorithm for SSA construction The rest is optimization (!) DEF-USE chains on SSA form One def per use Meets occur at ø functions For CONSTANTS, 3 binary ’s x5  a + b x1  y - z x2  Ø(x1,x0) x4  Ø(x3,x2) x6  Ø(x5,x4) x3  13 z  x4 * q s  w - x6 Next class: SSA Construction COMP 512, Fall 2003 *


Download ppt "Copyright 2003, Keith D. Cooper & Linda Torczon, all rights reserved."

Similar presentations


Ads by Google