Definitioncore
Data dependence
Also called flow dependence, anti-dependence, output dependence.
Two accesses to the same location, at least one a write, whose order must be kept; flow, anti and output by which access writes.
A data dependence is an ordering constraint between two runs of statements, called statement instances. Two instances depend on each other when both touch the same memory location, at least one of them writes it, and one runs before the other. A compiler may reorder the instances of a program only if it keeps the order of each dependent pair; this is the legality theorem. There are three kinds: flow, anti and output, by which of the two accesses writes. Data dependence differs from control dependence, which says whether an instance runs at all; the program dependence graph holds both.
Definition
Statement instances
A program runs a sequence of statement instances. In a loop nest of depth , statement runs once for each iteration vector in its domain , and names that run. The iterations run in lexicographic order , and the statements of one iteration run in the order of the text. Write when runs before in the original program:
where and are the parts of the vectors that belong to the loops common to and .
For an instance , let be the set of memory locations that reads and the set it writes. An array access has an affine access function: writes , and that is one element for each .
Dependence
There is a data dependence from to , written , when and some location satisfies one of these three cases:
| kind | condition | also called |
|---|---|---|
| flow | true dependence, read after write | |
| anti | write after read | |
| output | write after write |
The case is an input dependence (read after read). It does not constrain the order, because two reads give the same values in either order. Some compilers still record it, because it shows reuse of data in a cache.
is the source and is the sink. Between statements, holds when for some pair of instances. In the isl notation, each kind between two statements is a relation, for example { S[i] -> T[j] : ... }.
The definition is memory-based: it counts each pair that touches the same location, even when a third write lies between them. The value-based (dataflow) dependence keeps only the pair where the read gets its value from the write. The page Feautrier array dataflow analysis computes it exactly for affine programs.
Why the order matters
Flow dependences carry values: the sink reads what the source wrote. Anti and output dependences come from the reuse of a location. Renaming removes them: give the later write a new location, for example a private copy of an array per iteration (array privatization) or a new name per assignment (static single assignment form for scalars). For this reason anti and output dependences are also called false or name dependences.
In real code the compiler often does not know the exact locations. Two pointers may point to the same object; a subscript may depend on input data. A compiler then assumes a dependence unless an alias analysis or a dependence test proves that none exists. The computed relation is a superset of the true one. A superset is safe: it can block a legal transformation, but it never allows an illegal one.
Examples and non-examples
A loop with all three kinds
for i = 1 to 3:
S1: A[i+1] = A[i] + B[i]
S2: B[i] = A[i+1] + 1
S3: t = B[i+1]
The program runs nine instances, in the order . All 13 dependent pairs, grouped:
| from | to | kind | location | pairs | relation |
|---|---|---|---|---|---|
| flow | 3 | { S1[i] -> S2[i] : 1 <= i <= 3 } |
|||
| anti | 3 | { S1[i] -> S2[i] : 1 <= i <= 3 } |
|||
| flow | 2 | { S1[i] -> S1[i + 1] : 1 <= i <= 2 } |
|||
| anti | 2 | { S3[i] -> S2[i + 1] : 1 <= i <= 2 } |
|||
| output | 3 | { S3[i] -> S3[i'] : 1 <= i < i' <= 3 } |
- writes , and reads it in the same iteration: a flow dependence inside one iteration. reads in the next iteration: a flow dependence from one iteration to the next. The page loop-carried dependence names these two cases.
- reads before writes it: an anti dependence. If a transformation moved before , then would read the new value of .
- reads , and writes it later: an anti dependence.
- All three instances of write the scalar , so each pair is an output dependence, also the pair . The memory-based definition counts it. The value-based one does not, because writes between them. A private copy of per iteration removes all three.
- and both read . That is an input dependence, so it is not in the table.
Non-examples
X[2*i] = ...and... = X[2*i+1]in one loop never touch the same element, since an even number is never odd. There is no dependence. The GCD test proves this.- Two reads of the same element, as above: no dependence.
A[i] = ...and... = B[i]with distinct arrays and : no dependence, if the compiler knows that and do not overlap. In C, two pointer parameters can overlap, and then the compiler must assume a dependence.if c then x = 1andy = 2: here there is no data dependence. The first assignment is control dependent on the test ofc, which is a different relation.
Straight-line code
Without loops, each statement runs once. In a = b + c; b = a * 2; a = 7 the pairs are: flow from the first to the second statement on a, anti from the first to the second on b, anti from the second to the third on a, and output from the first to the third on a. Give the third a a new name: this removes the anti and the output dependence on a, and then the second and the third statements can run in either order.
Related definitions
- Bernstein's conditions. Bernstein (1966) stated when two program parts and can run in parallel: , and . These are the three kinds of dependence above, for two parts whose order is free.
- Dependence graph. The statements are the nodes, and there is an edge when for some pair of instances, labeled with the kind and with the distance or direction vectors. Kuck, Kuhn, Padua, Leasure and Wolfe (1981) made this graph the base of a compiler. Its strongly connected components decide loop distribution and vectorization.
- Loop-carried and loop-independent dependence. A dependence between two different iterations of a loop, or within one iteration. See loop-carried dependence.
- Dependence testing. The problem of deciding, for two array accesses in a loop nest, whether a dependence exists. See dependence testing.
- Reordering transformation and legality. A transformation that runs the same instances in another order. It keeps the meaning of the program if it keeps the order of each dependence. See legality of loop reordering.
- Def-use chains. For scalars, the flow dependences inside a procedure are what def-use chains and reaching definitions record.
References
- Randy Allen and Ken Kennedy, Optimizing Compilers for Modern Architectures, a Dependence-Based Approach, Morgan Kaufmann, 2002 (copyright 2001), Chapter 2 (dependence, the three kinds, reordering transformations, Section 2.2.3 with Theorem 2.2, the fundamental theorem of dependence)
- David J. Kuck, Robert H. Kuhn, David A. Padua, Bruce Leasure and Michael Wolfe, Dependence graphs and compiler optimizations, POPL 1981, pp. 207 to 218 (the dependence graph of a program, flow, anti and output dependence, and transformations that remove dependence arcs)
- A. J. Bernstein, Analysis of programs for parallel processing, IEEE Transactions on Electronic Computers EC-15(5), 1966, pp. 757 to 763 (the conditions on the input and output sets of two program parts that let them run in parallel)
- Alfred V. Aho, Monica S. Lam, Ravi Sethi and Jeffrey D. Ullman, Compilers, Principles, Techniques, and Tools, second edition, Addison-Wesley, 2007, Section 11.6 (array data-dependence analysis)
- Michael Wolfe, High Performance Compilers for Parallel Computing, Addison-Wesley, 1996, the chapter on data dependence (kinds of dependence, the dependence graph, dependence in loops)
Where this leads
- Affine scheduling
- Array privatization
- Dependence distance vector
- Dependence testing
- Array dataflow analysis
- Instruction scheduling
- Loop-carried dependence
- Loop distribution
- Loop fusion
- Legality of loop reordering
- Loop unrolling
- Polyhedral model
- Program dependence graph
- Program slicing
- Superword-level parallelism vectorization
- Software pipelining
- Strip mining
- Taint analysis
- Vectorization
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 1PQA1J Edit this page History Report an error Markdown