Академический Документы
Профессиональный Документы
Культура Документы
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
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
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
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
4
v2 := φ(v0 ,v1 )
...v2 ...
CS553 Lecture Static Single Assignment Form 11 CS553 Lecture Static Single Assignment Form 12
CS553 Lecture Static Single Assignment Form 13 CS553 Lecture Static Single Assignment Form 14
3
Transformation to SSA Form Where Do We Place φ-Functions?
x v1 :=... y v2 :=...
z v3 := φ(v1 ,v2 )
...v3 ...
CS553 Lecture Static Single Assignment Form 15 CS553 Lecture Static Single Assignment Form 16
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
4
Concepts Next Time
CS553 Lecture Static Single Assignment Form 19 CS553 Lecture Static Single Assignment Form 20