Вы находитесь на странице: 1из 5

Data Dependence Example

Definition
– Data dependences are constraints on the order in which statements may be
executed
We say statement s2 depends on s1 s1 a = b;
– Flow (true) dependence: s1 writes memory that s2 later reads (RAW) flow
s2 b = c + d;
– Anti-dependence: s1 reads memory that s2 later writes (WAR) anti
– Output dependences: s1 writes memory that s2 later writes (WAW)
s3 e = a + d; output
– Input dependences: s1 reads memory that s2 later reads (RAR)
s4 b = 3; input
True dependences
– Flow dependences represent actual flow of data s5 f = b * 2;
False dependences
– Anti- and output dependences reflect reuse of memory, not actual data
flow; can often be eliminated
CS553 Lecture Static Single Assignment Form 3 CS553 Lecture Static Single Assignment Form 4

Representing Data Dependences DU Chains

Implicitly Definition
– Using variable defs and uses – du chains link each def to its uses
– Pros: simple
– Cons: hides data dependence (analyses must find this info) Example

Def-use chains (du chains) s1 a = b;


– Link each def to its uses
– Pros: explicit; therefore fast s2 b = c + d; du chain
– Cons: must be computed and updated, space consuming
s3 e = a + d;
Alternate representations
s4 b = 3;
– e.g., Static single assignment form (SSA), dependence flow graphs
(DFG), value dependence graphs (VDG)
s5 f = b * 2;

CS553 Lecture Static Single Assignment Form 5 CS553 Lecture Static Single Assignment Form 6

1
UD Chains Role of Alternate Program Representations

Definition Advantage
– ud chains link each use to its defs – Allow analyses and transformations to be simpler & more efficient/effective

Example Disadvantage
– May not be “executable” (requires extra translations to and from)
s1 a = b; – May be expensive (in terms of time or space)

s2 b = c + d; ud chain Process

s3 e = a + d;
Original Code (RTL) Optimized Code (RTL)
s4 b = 3;
T1 T2
s5 f = b * 2; SSA Code1 SSA Code2 SSA Code3

CS553 Lecture Static Single Assignment Form 7 CS553 Lecture Static Single Assignment Form 8

Static Single Assignment (SSA) Form SSA and Control Flow

Idea Problem
– Each variable has only one static definition – A use may be reached by several definitions
– Makes it easier to reason about values instead of variables
– Similar to the notion of functional programming 1

Transformation to SSA
– Rename each definition 2 v := ... 3 v := ...
– Rename all uses reached by that assignment
1
Example 4 ...v...
v := ... v0 := ...
... := ... v ... ... := ... v0 ... 2 v0 :=... 3 v1 :=...
v := ... v1 := ...
... := ... v ... ... := ... v1 ...
4 ...v?...
What do we do when there’s control flow?
CS553 Lecture Static Single Assignment Form 9 CS553 Lecture Static Single Assignment Form 10

2
SSA and Control Flow (cont) Another Example

Merging Definitions
– φ-functions merge multiple reaching definitions

Example
1 v := 1 1 v0 := 1
1

2 v0 :=... 3 v1 :=... 2 v := v+1 v1 := φ(v0 ,v2 )


2
v2 := v1 +1

4
v2 := φ(v0 ,v1 )
...v2 ...

CS553 Lecture Static Single Assignment Form 11 CS553 Lecture Static Single Assignment Form 12

SSA vs. ud/du Chains SSA vs. ud/du Chains (cont)

SSA form is more constrained Worst case du-chains?

Advantages of SSA switch (c1) {


– More compact case 1: x = 1; break;
– Some analyses become simpler when each use has only one def case 2: x = 2; break;
– Value merging is explicit case 3: x = 3; break;
}
– Easier to update and manipulate?
x4 = φ(x1 , x2 , x3 )
Furthermore switch (c2) {
– Eliminates false dependences (simplifying context) case 1: y1 = x; break;
case 2: y2 = x; break;
for (i=0; i<n; i++) case 3: y3 = x; break;
A[i] = i; Unrelated uses of i are given case 4: y4 = x; break;
for (i=0; i<n; i++) different variable names }
m defs and n uses leads to m×n du chains
print(foo(i));

CS553 Lecture Static Single Assignment Form 13 CS553 Lecture Static Single Assignment Form 14

3
Transformation to SSA Form Where Do We Place φ-Functions?

Two steps Basic Rule


– Insert φ-functions – If two distinct (non-null) paths x→z and y→z converge at node z, and
– Rename variables nodes x and y contain definitions of variable v, then a
φ-function for v is inserted at z

x v1 :=... y v2 :=...

z v3 := φ(v1 ,v2 )
...v3 ...

CS553 Lecture Static Single Assignment Form 15 CS553 Lecture Static Single Assignment Form 16

Approaches to Placing φ-Functions Briggs Minimal vs. Pruned

Minimal v = v =
Briggs Minimal will add a
= v = v
– As few as possible subject to the basic rule φ function because v is live
across the blue edge, but Pruned
Briggs-Minimal = v SSA will not because the φ
– Same as minimal, except v must be live across some edge of the CFG function is dead

= φ(v0 ,v1 )
Pruned
– Same as minimal, except dead φ-functions are not inserted
v = v = Neither Briggs Minimal nor
= v = v Pruned SSA will place a
What’s the difference between Briggs Minimal and Pruned SSA?
φ function in this case because v
is not live across any CFG edge

Why would we ever use Briggs Minimal instead of Pruned SSA?


CS553 Lecture Static Single Assignment Form 17 CS553 Lecture Static Single Assignment Form 18

4
Concepts Next Time

Data dependences Assignments


– Three kinds of data dependences – HW1 due
– du-chains
Alternate representations Lecture
SSA form – SSA continued
Conversion to SSA form
– φ-function placement

CS553 Lecture Static Single Assignment Form 19 CS553 Lecture Static Single Assignment Form 20

Вам также может понравиться