DFA foundation
Simone Campanoni simonec@eecs.northwestern.edu
DFA foundation Simone Campanoni simonec@eecs.northwestern.edu We - - PowerPoint PPT Presentation
DFA foundation Simone Campanoni simonec@eecs.northwestern.edu We have seen several examples of DFAs Are they correct? Are they precise? Will they always terminate? How long will they take to converge? Outline Lattice and
Simone Campanoni simonec@eecs.northwestern.edu
b c d a e
b c d a
1 “lattice instance” per point
from the best one (T) to the worst one --most conservative one--(⊥)
T = no variable is alive = { } ⊥ = all variables are alive = V
to find the correct solution in a given point of the CFG
Apples, definitions, variables, expressions …
Conservativeness Precision
Conservativeness Precision
computed by data-flow analysis, and organize the domain of elements as a lattice
using lattice operations
flow values (e.g., an IN[] set)
T “best-case” information
e.g., Empty set
⊥ “worst-case” information
e.g., Universal set
If x ≤ y, then x is a conservative approximation of y
e.g., Superset
flow values (e.g., an IN[] set)
conservative approximation of y
for (each instruction i other than ENTRY) OUT[i] = { };
for (each instruction i other than ENTRY) OUT[i] = { };
Entry
Ventry
consider all possible paths from the entry to a given program point, compute the flow values at the end of each path, and then meet these values together
solution at each program point
Entry
Ventry
d1 d2 d3
BB0 BB1 BB2 Control flow 0-1-A Control flow 0-1-B Control flow 1-2-A Control flow 1-2-B
0-1-A, 1-2-A 0-1-A, 1-2-B 0-1-B, 1-2-A 0-1-B, 1-2-B VMOP
d1 d2 d3
IN[i] = ∪p a predecessor of i OUT[p];
Entry
Ventry
VMOP Vcorrect ≤
fs(Vp1 ∧ Vp2 ) ≤ fs(Vp1) ∧ fs(Vp2)
Let us compare Same function
fs is monotonic => MFP is correct!
the result of applying f to the “lesser” of the two members will be under the result of applying f to the “greater” of the two
leads to more conservative outputs (never more optimistic outputs)
If fs is monotonic, then the maximum number of times fs can be applied w/o reaching a fixed point is Height(V) – 1
if the fs is monotonic and the lattice has finite height
* is distributive over + 4 * (2 + 3) = 4 * (5) = 20 (4 * 2) + (4 * 3) = 8 + 12 = 20
i:v1 = 3 j:v2 = 4 …
i and j reach this point
k:v3 = v1 + v2
v1 = 3 v2 = 4 v3 = v1 + v2
v3 is 7
OUT OUT[EN [ENTRY] ] = = { }; fo for (each instruction i oth
er th than E ENTRY) O OUT[i] = { ] = { } }; do do { fo for (each instruction i oth
er th than E ENTRY) { { IN IN[i] = ] = ∪p a
a predecessor of i OUT
OUT[p]; ]; OUT OUT[i] = GEN ] = GEN[i] ] ∪ (I (IN[ N[i] ─ ─ KILL[i]) ]); } } } while (c (changes to any OUT occur); );
N=500 Worst case: 62,500,000,000 Optimized average case: 500 – 250,000
OUT OUT[EN [ENTRY] ] = = { }; fo for (each basic block B other than ENTRY) OUT[B] = { }; do do { fo for (each basic block B other than ENTRY) { IN IN[B] = ] = ∪p a
a predecessor of B OUT
OUT[p]; ]; OUT OUT[B]= GEN ]= GEN[B]∪ (I (IN[ N[B] ─ ─ KILL[B]) ]); } } } while (c (changes to any OUT occur); );
OUT OUT[EN [ENTRY] ] = = { }; fo for (each basic block B other than ENTRY) OUT[B] = { }; wo workList = all b = all bas asic ic b blo locks wh while ( ile (wo workList is isn’t empty) B B = pick k and remove a block k from wo workList
= OUT[B [B] ] IN IN[B] = ] = ∪p a
a predecessor of B OUT
OUT[p]; ]; OUT OUT[B]= GEN ]= GEN[B]∪ (I (IN[ N[B] ─ ─ KILL[B]) ]); if if (ol
!= OUT[B]) ) wo workList = = wo workList U U {all all successors of B} } }