Lattice-Theoretic Data-Flow Framework and Intro to SSA Last Time - - PDF document

lattice theoretic data flow framework and intro to ssa
SMART_READER_LITE
LIVE PREVIEW

Lattice-Theoretic Data-Flow Framework and Intro to SSA Last Time - - PDF document

Lattice-Theoretic Data-Flow Framework and Intro to SSA Last Time Started lattice theoretic frameworks for Data-flow analysis [Aho,Sethi,Ullman,Lam] Today Complexity and correctness of IDFA Affect of program representation on


slide-1
SLIDE 1

1

CS553 Lecture Static Single Assignment Form 2

Lattice-Theoretic Data-Flow Framework and Intro to SSA

Last Time

– Started lattice theoretic frameworks for Data-flow analysis

Today

– Complexity and correctness of IDFA – Affect of program representation on data-flow analysis efficiency – Static single assignment (SSA) form – Program representation for sparse data-flow

Next Time

– SSA complications

[Aho,Sethi,Ullman,Lam]

CS553 Lecture Static Single Assignment Form 9

Bitwidth Analysis Paper

Why did we read this paper? Can all dataflow analyses be defined in terms of Gen and Kill? Do all dataflow analysis problems operate on sets? What questions arise from reading this paper?

slide-2
SLIDE 2

2

CS553 Lecture Static Single Assignment Form 10

Implementing Simple Constant Propagation

Standard worklist algorithm

– Identifies simple constants – For each program point, maintains one constant value for each variable – O(EV) (E is the number of edges in the CFG; V is number of variables) Solution −Exploit a sparse dependence representation (e.g., du-chains, SSA) Problem −Inefficient, since constants may have to be propagated through irrelevant nodes

x = 1 y = x

CS553 Lecture Static Single Assignment Form 11

Data Dependence

Definition

– Data dependences are constraints on the order in which statements may be executed

We say statement s2 depends on s1

– Flow (true) dependence: s1 writes memory that s2 later reads (RAW) – Anti-dependence: s1 reads memory that s2 later writes (WAR) – Output dependences: s1 writes memory that s2 later writes (WAW) – Input dependences: s1 reads memory that s2 later reads (RAR)

True dependences

– Flow dependences represent actual flow of data

False dependences

– Anti- and output dependences reflect reuse of memory, not actual data flow; can often be eliminated

slide-3
SLIDE 3

3

CS553 Lecture Static Single Assignment Form 12

Example

s1 a = b; s2 b = c + d; s3 e = a + d; s4 b = 3; s5 f = b * 2; flow anti

  • utput

input

CS553 Lecture Static Single Assignment Form 13

Representing Data Dependences

Implicitly

– Using variable defs and uses – Pros: simple – Cons: hides data dependence (analyses must find this info)

Def-use chains (du chains)

– Link each def to its uses – Pros: explicit; therefore fast – Cons: must be computed and updated, space consuming

Alternate representations

– e.g., Static single assignment form (SSA), dependence flow graphs (DFG), value dependence graphs (VDG)

slide-4
SLIDE 4

4

CS553 Lecture Static Single Assignment Form 14

DU Chains

Definition

– du chains link each def to its uses

Example

s1 a = b; s2 b = c + d; s3 e = a + d; s4 b = 3; s5 f = b * 2; du chain

CS553 Lecture Static Single Assignment Form 15

UD Chains

Definition

– ud chains link each use to its defs

Example

s1 a = b; s2 b = c + d; s3 e = a + d; s4 b = 3; s5 f = b * 2; ud chain

slide-5
SLIDE 5

5

CS553 Lecture Static Single Assignment Form 16

Static Single Assignment (SSA) Form

Idea

– Each variable has only one static definition – Makes it easier to reason about values instead of variables – Similar to the notion of functional programming

Transformation to SSA

– Rename each definition – Rename all uses reached by that assignment

Example

v := ... ... := ... v ... v := ... ... := ... v ... v0 := ... ... := ... v0 ... v1 := ... ... := ... v1 ... What do we do when there’s control flow?

CS553 Lecture Static Single Assignment Form 17

SSA and Control Flow (cont)

Merging Definitions

– φ-functions merge multiple reaching definitions

Example

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

4

v0 :=...

2

v1 :=...

3 1

slide-6
SLIDE 6

6

CS553 Lecture Static Single Assignment Form 18

Another Example

v := 1

1

v := v+1

2

v0 := 1

1

v1 := φ(v0,v2) v2 := v1+1

2

CS553 Lecture Static Single Assignment Form 19

SSA vs. ud/du Chains

SSA form is more constrained Advantages of SSA

– More compact – Some analyses become simpler when each use has only one def – Value merging is explicit – Easier to update and manipulate?

Furthermore

– Eliminates false dependences (simplifying context) for (i=0; i<n; i++) A[i] = i; for (i=0; i<n; i++) print(foo(i)); Unrelated uses of i are given different variable names

slide-7
SLIDE 7

7

CS553 Lecture Static Single Assignment Form 20

SSA vs. ud/du Chains (cont)

Worst case du-chains?

switch (c1) { case 1: x = 1; break; case 2: x = 2; break; case 3: x = 3; break; } switch (c2) { case 1: y1 = x; break; case 2: y2 = x; break; case 3: y3 = x; break; case 4: y4 = x; break; }

m defs and n uses leads to m×n du chains x4 = φ(x1, x2, x3)

CS553 Lecture Static Single Assignment Form 21

Reality Check

How can we handle aliasing in SSA? What about backward data-flow analysis problems? How do we transform SSA and generate code from SSA?

slide-8
SLIDE 8

8

CS553 Lecture Static Single Assignment Form 22

Concepts

Lattice-theoretic framework used to prove

– Correctness – Complexity – Accuracy

Data dependences

– Three kinds of data dependences – du-chains

Alternate representations

– du-chains – SSA

Reality check

– aliasing? – backward data-flow? – transforming from SSA to code?

CS553 Lecture Static Single Assignment Form 23

Next Time

Assignments

– Schedule for project 2 due Wednesday

Lecture

– Discuss those SSA reality checks