-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMore Examples of Data Flow Analysis.tex
181 lines (118 loc) · 3.86 KB
/
More Examples of Data Flow Analysis.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
\section{More Examples of Data Flow Analysis: Global Common Sub-expression Elimination; Constant Propagation/Folding}
If we care about the past, what happened before, then it is a forward problem (entry).
\subsection{Available Expression Analysis}
\begin{definition}{Availability of an Expression E at point P}
E is available at P if every path to P in the flow graph
\begin{itemize}
\item E must be calculated at least once
\item no variable in E redefined after the last evaluation
\end{itemize}
\end{definition}
\begin{figure}[h]
\centering
\includegraphics[width=0.3\textwidth]{p24.png}
\caption{}
\label{fig:p24}
\end{figure}
\subsubsection{Examples}
In \ref{fig:p24} $a-b$, $c+d$ is not available at the last BB. But $x+y$ is.
\begin{figure}[h]
\centering
\includegraphics[width=0.3\textwidth]{p25.png}
\caption{}
\label{fig:p25}
\end{figure}
In \ref{fig:p25} , $4*i$ is available for both cases.
\begin{figure}[h]
\centering
\includegraphics[width=0.3\textwidth]{p26.png}
\caption{}
\label{fig:p26}
\end{figure}
In \ref{fig:p26}, we show that calculate transfer functions for complete basic blocks by composing individual instruction transfer functions.
\begin{figure}[h]
\centering
\includegraphics[width=0.3\textwidth]{p27.png}
\caption{}
\label{fig:p27}
\end{figure}
\subsection{Eliminating CSEs}
\begin{itemize}
\item Step1: Value Numbering
\item Step2: Available expression
\item Step3: If CSE is an "available expression", then transform the code.
\end{itemize}
\begin{figure}[h]
\centering
\includegraphics[width=0.3\textwidth]{p28.png}
\caption{}
\label{fig:p28}
\end{figure}
If we only use value numbering to eliminate common expression in \ref{fig:p28}, we will see that this will just add a lot of new work and no income. But if we calculate Available expression in \ref{fig:p29}, we can find that $x+y$ is such one and can do some optimization.
\begin{figure}[h]
\centering
\includegraphics[width=0.3\textwidth]{p29.png}
\caption{}
\label{fig:p29}
\end{figure}
\begin{note}{How to deal with Textually identical expression?\ref{fig:p30}}
Just sort the operands.
But for textually different expressions that may be equivalent \ref{fig:p31}, we had better do copy propagation first.
\end{note}
\begin{figure}[h]
\centering
\includegraphics[width=0.3\textwidth]{p30.png}
\caption{}
\label{fig:p30}
\end{figure}
\begin{figure}[h]
\centering
\includegraphics[width=0.3\textwidth]{p31.png}
\caption{}
\label{fig:p31}
\end{figure}
\subsubsection{Summary}
\begin{figure}[h]
\centering
\includegraphics[width=0.3\textwidth]{p32.png}
\caption{}
\label{fig:p32}
\end{figure}
\subsection{Constant Propagation/Folding}
\begin{figure}[h]
\centering
\includegraphics[width=0.3\textwidth]{p33.png}
\caption{}
\label{fig:p33}
\end{figure}
\subsubsection{Meet Operator in Table Form}
\begin{figure}[h]
\centering
\includegraphics[width=0.3\textwidth]{p34.png}
\caption{}
\label{fig:p34}
\end{figure}
\subsubsection{Example}
\begin{figure}[h]
\centering
\includegraphics[width=0.3\textwidth]{p35.png}
\caption{}
\label{fig:p35}
\end{figure}
On the other path in \ref{fig:p35}, x is uninitialized. When we have undefined behavior, hopefully the front end of the compiler should complain about it, but if it doesn't, the optimizer is free to do whatever it wants to do.
\subsubsection{Transfer Function}
\begin{figure}[h]
\centering
\includegraphics[width=0.3\textwidth]{p36.png}
\caption{}
\label{fig:p36}
\end{figure}
It is not distributive in \ref{fig:p37}.
\begin{figure}[h]
\centering
\includegraphics[width=0.3\textwidth]{p37.png}
\caption{}
\label{fig:p37}
\end{figure}
\subsection{Copy Propagation}
\subsection{Dead Code Elimination}