Definitioncore
Gen-kill dataflow problem
Also called bit-vector dataflow problem, gen-kill framework.
A dataflow problem whose transfer functions have the form f(x) = gen union (x minus kill), solved fast with bit vectors.
A gen-kill dataflow problem is a dataflow analysis whose facts are sets of items from a finite universe and whose transfer functions all have the form . The four classical problems, reaching definitions, live variable analysis, available expressions and very busy expressions, are of this form. The functions are closed under composition, so a whole block has one pair . They distribute over both union and intersection, so every gen-kill problem is a distributive dataflow framework and its computed answer equals the meet-over-all-paths solution. Each item is independent of the others, so a set fits in a bit vector and one transfer function costs a few word operations per items.
Definition
The dataflow pages use the meet convention: is a meet semilattice, means , and is the identity of meet and the start value.
Definition. Let be a finite set of items, with . A gen-kill problem over is a dataflow problem with:
- the domain $L = $ all subsets of ;
- the meet (a may problem: and the order is ) or (a must problem: and the order is );
- a direction, forward or backward, and a boundary value ;
- for each block two sets and the transfer function .
The height of is in both cases: a strict chain adds or removes one item per step.
| problem | items | direction | meet | of x = a op b |
of x = a op b |
boundary |
|---|---|---|---|---|---|---|
| reaching definitions | definitions | forward | this definition | the other definitions of x |
at the entry | |
| live variables | variables | backward | a, b |
x |
after ret |
|
| available expressions | expressions | forward | a op b, unless x is a or b |
expressions that read x |
at the entry | |
| very busy expressions | expressions | backward | a op b |
expressions that read x |
after ret |
In the two must problems , which is far from . In the may problems the usual is , but variants change it, such as the pseudo definitions at the entry for reaching definitions.
Composition. Applying and then gives
So the composition is the gen-kill function with and . The identity is . The functions therefore form a set that contains the identity and is closed under composition, as a monotone dataflow framework requires. A block's pair is the composition of its instructions in the direction of the analysis: first to last for a forward problem, last to first for a backward one.
Distributivity. For all :
where the first lines use and , and the last step of the second line is the law . So every gen-kill function distributes over the meet of a may problem and of a must problem alike. A distributive function is monotone, so a gen-kill problem is a distributive framework, and when every block is reachable from the start, the computed fixed point equals MOP.
Which set functions are gen-kill. Call on the subsets of bitwise if, for each item , whether depends only on whether . Then is a gen-kill function if and only if it is bitwise and monotone.
Proof. A gen-kill function is bitwise: holds if , fails if , and otherwise holds exactly when . It is monotone because it distributes. Conversely, let be bitwise and monotone. For each , the map from "" to "" is a monotone function from to , so it is the constant 0, the constant 1 or the identity; the fourth function, negation, is not monotone. Put in if it is the constant 1 and in if it is the constant 0. Then .
So the gen-kill problems are exactly the dataflow problems on sets in which items do not interact. This is what lets each item be solved on its own, as one graph reachability question.
Soundness and precision. Each of the four problems is sound by the argument on its page: every run follows a CFG path, and the fixed point is below the fact of every path. Since MFP = MOP, the only loss of precision is from CFG paths that no run takes.
Cost. Store each set as a vector of bits. With word size , the operations , and , the last as gen | (x & ~kill), cost word operations each. On a CFG with blocks and edges, the worklist dataflow algorithm changes each block value at most times, so it applies at most transfer functions and meets, for time. Gen-kill problems are also rapid, and round-robin iteration in reverse postorder stops after at most passes, where is the loop-connectedness depth of the CFG. This gives time; see the Kam-Ullman iteration bound. Space is words for the IN and OUT vectors and the and vectors.
Examples and non-examples
Composing a block. In the running example of dataflow analysis, block body is
body:
a = x * 2
u = i & 1
br u odd next
For available expressions, a = x * 2 has and , since s + a reads a. Then u = i & 1 has and . The composition is and . For live variables the same block is read from the end: the branch reads u, then u = i & 1 writes u and reads i, then a = x * 2 writes a and reads x. The composition is and ; u is not in because the block writes it before the branch reads it.
An instruction that reads what it writes. For available expressions, s = s + a computes s + a and then changes s, so . For very busy expressions, read backward, the same instruction has : the evaluation comes before the write.
Reaching definitions with pseudo definitions. Adding one pseudo definition per variable at the entry keeps the problem gen-kill; only and change.
Non-example: strongly live variables. The function of x = y + z, , is distributive, but whether depends on whether . It is not bitwise, so it is not gen-kill, and the items cannot be solved one at a time.
Non-example: points-to sets. In a may points-to analysis the fact is a set of pairs " may point to ". The instruction q = *p adds pairs for q that depend on which pairs of p are in the input. The function is not bitwise.
Non-example: constant propagation. The facts are maps from variables to a flat lattice, not sets, and the function of z = x + y is not even distributive. See constant propagation.
Related definitions
- Distributive dataflow framework: the wider class with , where MFP = MOP still holds.
- Monotone dataflow framework: the general class.
- Kam-Ullman iteration bound: the rapid property and the passes of round-robin iteration.
- IFDS framework: interprocedural analysis for distributive problems over finite sets, which includes the gen-kill problems.
- Datalog-based program analysis: a gen-kill problem is two Datalog rules per direction, with as a negated condition.
References
- Alfred V. Aho, Monica S. Lam, Ravi Sethi and Jeffrey D. Ullman, Compilers, Principles, Techniques, and Tools, second edition, Pearson Addison-Wesley, 2007, Section 9.2 (9.2.4 Reaching Definitions with the composition of gen and kill sets, 9.2.5 Live-Variable Analysis, 9.2.6 Available Expressions), Section 9.3.2 (Transfer Functions) and Section 9.6.7 (Speed of Convergence of Iterative Data-Flow Algorithms)
- Flemming Nielson, Hanne Riis Nielson and Chris Hankin, Principles of Program Analysis, Springer, 1999, Section 2.1 (the four classical analyses, each given by kill and gen functions) and Section 2.3 (Monotone Frameworks)
- John B. Kam and Jeffrey D. Ullman, Global data flow analysis and iterative algorithms, Journal of the ACM 23(1), 1976, 158-171, the whole paper (the analysis of round-robin iteration in depth-first order, which covers the bit-vector problems)
- Gary A. Kildall, A unified approach to global program optimization, Proceedings of the 1st ACM SIGACT-SIGPLAN Symposium on Principles of Programming Languages (POPL 1973), 194-206, the whole paper (distributive optimizing functions, of which gen-kill functions are the main example)
Where this leads
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag M3TQGG Edit this page History Report an error Markdown