@@ -11518,18 +11518,20 @@ \section{Cyclic Control Flow and Dataflow Analysis}
1151811518Next let us consider dataflow analysis in general and discuss the
1151911519generic work list algorithm (figure~\ref{fig:generic-dataflow}).
1152011520%
11521- The algorithm has four parameters: the control-flow graph \code{G}, a
11521+ The algorithm has six parameters: the control-flow graph \code{G}, a
1152211522function \code{transfer} that applies the analysis to one block, and the
11523- \code{bottom} and \code{join} operators for the lattice of abstract
11524- states. The \code{analyze\_dataflow} function is formulated as a
11525- \emph{forward} dataflow analysis; that is, the inputs to the transfer
11526- function come from the predecessor nodes in the control-flow
11527- graph. However, liveness analysis is a \emph{backward} dataflow
11528- analysis, so in that case one must supply the \code{analyze\_dataflow}
11529- function with the transpose of the control-flow graph.
11530-
11531- The algorithm begins by creating the bottom mapping, represented by a
11532- hash table. It then pushes all the nodes in the control-flow graph
11523+ \code{bottom}, \code{join} operators for the lattice of abstract
11524+ states, a set \code{extremals} containing all nodes in the graph that
11525+ are extremal points, and the \code{iota} parameter which maps extremal
11526+ points, the entry and exit nodes for the program, to their initial values.
11527+ The \code{analyze\_dataflow} function is formulated as a \emph{forward}
11528+ dataflow analysis; that is, the inputs to the transfer function come from
11529+ the predecessor nodes in the control-flow graph. However, liveness analysis is a
11530+ \emph{backward} dataflow analysis, so in that case one must supply the
11531+ \code{analyze\_dataflow} function with the transpose of the control-flow graph.
11532+
11533+ The algorithm begins by creating the bottom and iota mappings, represented by
11534+ a hash table. It then pushes all the nodes in the control-flow graph
1153311535onto the work list (a queue). The algorithm repeats the \code{while}
1153411536loop as long as there are items in the work list. In each iteration, a
1153511537node is popped from the work list and processed. The \code{input} for
@@ -11543,10 +11545,12 @@ \section{Cyclic Control Flow and Dataflow Analysis}
1154311545\begin{tcolorbox}[colback=white]
1154411546{\if\edition\racketEd
1154511547\begin{lstlisting}
11546- (define (analyze_dataflow G transfer bottom join)
11548+ (define (analyze_dataflow G transfer bottom join extremals iota )
1154711549 (define mapping (make-hash))
1154811550 (for ([v (in-vertices G)])
11549- (dict-set! mapping v bottom))
11551+ (if (set-member? extremals v)
11552+ (dict-set! mapping v iota)
11553+ (dict-set! mapping v bottom)))
1155011554 (define worklist (make-queue))
1155111555 (for ([v (in-vertices G)])
1155211556 (enqueue! worklist v))
@@ -11566,9 +11570,9 @@ \section{Cyclic Control Flow and Dataflow Analysis}
1156611570\fi}
1156711571{\if\edition\pythonEd\pythonColor
1156811572\begin{lstlisting}
11569- def analyze_dataflow(G, transfer, bottom, join):
11573+ def analyze_dataflow(G, transfer, bottom, join, iota, extremal ):
1157011574 trans_G = transpose(G)
11571- mapping = dict((v, bottom ) for v in G.vertices())
11575+ mapping = dict((v, iota ) for v in G.vertices() if v in extremal else (v, bottom ))
1157211576 worklist = deque(G.vertices)
1157311577 while worklist:
1157411578 node = worklist.pop()
@@ -12008,6 +12012,13 @@ \section{Register Allocation}
1200812012 parameters: the label for the block to analyze and the live-after
1200912013 set for that block. The transfer function should return the
1201012014 live-before set for the block.
12015+ \item The fifth parameter \code{extremals} should be passed a set containing
12016+ all extremal relavent nodes in a graph. For liveness analysis, this should only
12017+ be the conclusion block, as a block will never jump to the prelude.
12018+ \item The sixth parameters \code{iota} should be passed a set for the initial
12019+ values of extremal points. For liveness analysis this should be a set
12020+ containing the registers \key{rax} and \key{rsp}, which coressponds to the
12021+ live before set of the conclusion.
1201112022 %
1201212023 \racket{Also, as a side effect, it should update the block's
1201312024 $\itm{info}$ with the liveness information for each instruction.}
0 commit comments