Induction Variables
description
Transcript of Induction Variables
![Page 1: Induction Variables](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815aa2550346895dc82a81/html5/thumbnails/1.jpg)
1
Induction Variables
Region-Based AnalysisMeet and Closure of Transfer FunctionsAffine Functions of Reference Variables
![Page 2: Induction Variables](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815aa2550346895dc82a81/html5/thumbnails/2.jpg)
2
Regions
A set of nodes N and edges E is a region if:
1. There is a header h in N that dominates all nodes in N.
2. If n ≠ h is in N, then all predecessors of n are also in N.
3. E consists of all edges between nodes in N, possibly excluding nodes that enter h.
![Page 3: Induction Variables](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815aa2550346895dc82a81/html5/thumbnails/3.jpg)
3
T1-T2 Reduction
For reducible flow graphs, we can “reduce” the graph by two region-creating transformations.
T1: Remove a loop from a node. T2: combine two nodes n and m
such that m’s only predecessor is n, and m is not the entry.
![Page 4: Induction Variables](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815aa2550346895dc82a81/html5/thumbnails/4.jpg)
4
Example: T1-T2 Reduction
1
35
24
T2
T2
![Page 5: Induction Variables](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815aa2550346895dc82a81/html5/thumbnails/5.jpg)
5
Example: T1-T2 Reduction
14
5
23 T1
![Page 6: Induction Variables](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815aa2550346895dc82a81/html5/thumbnails/6.jpg)
6
Example: T1-T2 Reduction
14
5
23
T2
![Page 7: Induction Variables](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815aa2550346895dc82a81/html5/thumbnails/7.jpg)
7
Example: T1-T2 Reduction
1234
5
T2
![Page 8: Induction Variables](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815aa2550346895dc82a81/html5/thumbnails/8.jpg)
8
Example: T1-T2 Reduction
12345 T1
![Page 9: Induction Variables](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815aa2550346895dc82a81/html5/thumbnails/9.jpg)
9
Example: T1-T2 Reduction
12345
![Page 10: Induction Variables](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815aa2550346895dc82a81/html5/thumbnails/10.jpg)
10
Regions Constructed During T1-T2 Reduction
Each node represents a set of nodes and edges of the original flow graph.
Each edge represents one or more edges of the original flow graph.
![Page 11: Induction Variables](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815aa2550346895dc82a81/html5/thumbnails/11.jpg)
11
Regions Constructed During T1-T2 Reduction ---
(2) T2: Take the union of the two sets
of nodes and edges. Then add edges represented by the edge between the two combined nodes.
T1: Add edges represented by the loop edge removed.
![Page 12: Induction Variables](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815aa2550346895dc82a81/html5/thumbnails/12.jpg)
12
Example: T1-T2 Reduction
1
3
5
24
![Page 13: Induction Variables](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815aa2550346895dc82a81/html5/thumbnails/13.jpg)
13
Region-Based Analysis --- (1)
First, compute for each region, smallest-to-largest, some transfer functions:
1. For region R with subregion S: fR,IN[S] = meet over paths from the header of R to the header of S, staying within R.
2. For each region R with exit block (= has a successor outside R) B, fR,OUT[B] = meet over paths within R from header of R to end of B.
![Page 14: Induction Variables](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815aa2550346895dc82a81/html5/thumbnails/14.jpg)
14
Example: Transfer Functions
1
3
5
24
R
S
fR,IN[S] = f1(f2f3)*
fS,OUT[2] = f2(f3f2)*
fR,OUT[2] = f1f2(f3f2)*f R,OUT[4] = f1f4
![Page 15: Induction Variables](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815aa2550346895dc82a81/html5/thumbnails/15.jpg)
15
Example: Meet
1
3
5
24
RT
fR,OUT[2] = f1f2(f3f2)*fR,OUT[4] = f1f4
fT,IN[5] = f1f4 ∧ f1f2(f3f2)*
![Page 16: Induction Variables](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815aa2550346895dc82a81/html5/thumbnails/16.jpg)
16
Additional Assumptions
We can take the meet of transfer functions. [f ∧ g](x) = f(x) ∧ g(x).
There is a closure f* for each transfer function f. f* = f0 ∧ f1 ∧ f2 ∧ …
• Note f0 = identity, f1 = f.
![Page 17: Induction Variables](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815aa2550346895dc82a81/html5/thumbnails/17.jpg)
17
Example: RD’s
Meet of transfer functions f(x) = (x - K) ∪ G and g(x) = (x - K’) ∪ G’ corresponds to the paths of f and g in parallel.
Thus, [f∪g](x) = (x – (K ∩ K’) ∪ (G ∪ G’)). f*(x) = x ∪ f(x) ∪ f(f(x)) ∪ … =
x ∪ (x – K) ∪ G ∪ (x - K ∪ G) – K ∪ G … = x ∪ G. f(x) f(f(x))
![Page 18: Induction Variables](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815aa2550346895dc82a81/html5/thumbnails/18.jpg)
18
Region-Based Analysis --- (2)
Finally, having computed fR’,IN[R]
R = entire flow graph; R’ = R plus dummy entry
proceed largest-to-smallest, computing IN[h], for the header h of each subregion.
Since every node is the header of some region, we have all the IN’s, from which we can compute the OUT’s.
![Page 19: Induction Variables](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815aa2550346895dc82a81/html5/thumbnails/19.jpg)
19
Example: Top-Down Finale
1
3
5
24
R
S
T
IN[1] = fR’,IN[R](vENTRY)
U IN[2] =fU,IN[S](IN[1])
IN[3] = fS,IN[3](IN[2])
![Page 20: Induction Variables](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815aa2550346895dc82a81/html5/thumbnails/20.jpg)
20
New Topic: Symbolic Analysis
Values V are mappings from variables to expressions of reference variables.
Example: m(a) = 2i; m(b) = i+j. i and j are the reference variables.
![Page 21: Induction Variables](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815aa2550346895dc82a81/html5/thumbnails/21.jpg)
21
Application to Induction Variables
Reference variables are basic induction variables = counts of the number of times around some loop.
V consists of affine mappings = each variable is mapped to either:
1. A linear function of the reference variables, or
2. NAA = “Not an affine” mapping, or3. UNDEF = top element = “nothing known.”
![Page 22: Induction Variables](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815aa2550346895dc82a81/html5/thumbnails/22.jpg)
22
Example: Affine Mapping
m(a) = 2i + 3j +4m(b) = NAAm(c) = 4i + 1m(d) = UNDEF
![Page 23: Induction Variables](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815aa2550346895dc82a81/html5/thumbnails/23.jpg)
23
Induction Variable Discovery
Natural application of region-based analysis.
Each loop is a region, and its induction variables can be discovered by a framework based on affine mappings.
In region-based analysis, you don’t even need the top element, UNDEF.
![Page 24: Induction Variables](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815aa2550346895dc82a81/html5/thumbnails/24.jpg)
24
Example: A Transfer Function
Let f be the transfer function associated with a block containing only a = a+10.
Let f(m) = m’. m’(a) = m(a) + 10. m’(x) = m(x) for all x ≠ a.
Book uses the notation f(m)(a) = m(a), etc., to avoid having to name f(m).
![Page 25: Induction Variables](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815aa2550346895dc82a81/html5/thumbnails/25.jpg)
25
Example: Meet
(f ∧ g)(m)(x) = f(m)(x) if f(m)(x) = g(m)(x). NAA otherwise.
Note: above assumes no occurrences of UNDEF. How would you treat the case where f(m)(x) or g(m)(x), or both, are UNDEF?
![Page 26: Induction Variables](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815aa2550346895dc82a81/html5/thumbnails/26.jpg)
26
Example: Some Analysis
a=b+3
b=a+2
a=a+5
B1
B5
B2
B4
B3 fB3(m)(a) = m(a)(b) = m(a)+2
fB2(m)(a) = m(a)+5(b) = m(b)
fB4(m)(a) = m(b)+3(b) = m(b)
R
fR,OUT[B4](m)(a) = m(a)+5(b) = m(a)+2
![Page 27: Induction Variables](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815aa2550346895dc82a81/html5/thumbnails/27.jpg)
27
Example: Meet
a=b+3
b=a+2
a=a+5
B1
B5
B2
B4
B3
fB2(m)(a) = m(a)+5(b) = m(b)
R
fR,OUT[B4](m)(a) = m(a)+5(b) = m(a)+2
S
fS,OUT[B5](m)(a) = m(a)+5(b) = NAA
![Page 28: Induction Variables](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815aa2550346895dc82a81/html5/thumbnails/28.jpg)
28
Handling Loop Regions
Treat the iteration count i as a basic induction variable.
If f(m)(x) = m(x)+c, then fi(m)(x) = m(x)+ci.
Some other cases, e.g., where m(x) is an affine function of basic induction variables, in book.
![Page 29: Induction Variables](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815aa2550346895dc82a81/html5/thumbnails/29.jpg)
29
Example: The Entire Loop
a=b+3
b=a+2
a=a+5
B1
B5
B2
B4
B3
S
fS,OUT[B5](m)(a) = m(a)+5(b) = NAA
T
fS,OUT[B5](m)(a) = m(a)+5i(b) = NAA
i
OUTi[B3](m)(a) = m(a)+5i(b) = m(a)+5i+2
OUTi[B4](m)(a) = m(a)+5i+5(b) = m(a)+5i+2
OUTi[B2](m)(a) = m(a)+5i+5(b) = NAA
OUTi[B5](m)(a) = m(a)+5i+5(b) = NAA
![Page 30: Induction Variables](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815aa2550346895dc82a81/html5/thumbnails/30.jpg)
30
Taking Advantage of Affine Expressions
Replace the loop counter variable by one of the induction variables (variables that are mapped to an affine expression of the loop count at the point were the loop count is tested).
![Page 31: Induction Variables](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815aa2550346895dc82a81/html5/thumbnails/31.jpg)
31
Example: Assume i is Loop Counter
i<10?
a=b+3
b=a+2
a=a+5
i=i+1
B1
B5
B2
B4
B3
i=0 a=30 Here, the value of a is
m(a)+5i, where m(a) is thevalue of a before enteringthe loop, and i is the numberof iterations of the loop so far.
Since a=30 when i=0,replace “i<10?” by“a<80?”.
If i is dead on exit fromthe loop, delete “i=i+1”and “i=0”.
![Page 32: Induction Variables](https://reader034.fdocuments.in/reader034/viewer/2022051402/56815aa2550346895dc82a81/html5/thumbnails/32.jpg)
32
Example: Revised Code
a<80?
a=b+3
b=a+2
a=a+5
B1
B5
B2
B4
B3
a=30