• Keine Ergebnisse gefunden

Removing Assignments to Dead Variables Example:

N/A
N/A
Protected

Academic year: 2022

Aktie "Removing Assignments to Dead Variables Example:"

Copied!
45
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

1 : x = y + 2;

2 : y = 5;

3 : x = y + 3;

The value of x at program points 1, 2 is over-written before it can be used.

Therefore, we call the variable x dead at these program points :-)

195

(2)

196

(3)

Formal Definition:

The variable x is called live at u along the path π starting at u relative to a set X of variables either:

if x ∈ X and π does not contain a definition of x; or:

if π can be decomposed into: π = π1 k π2 such that:

• k is a use of x ; and

• π1 does not contain a definition of x.

197

(4)

k = (_, lab, _) is defined by:

lab used defined

; ∅ ∅

Pos (e) Vars (e) ∅

Neg (e) Vars (e) ∅

x = e; Vars (e) {x}

x = M[e]; Vars (e) {x} M[e1] = e2; Vars (e1) ∪ Vars (e2) ∅

198

(5)

1

0 2 3

x = y + 2; y = 5; x = y + 3;

where X = ∅. Then we observe:

live dead 0 {y} {x} 1 ∅ {x, y} 2 {y} {x} 3 ∅ {x,y}

199

(6)

200

(7)

Question:

How can the sets of all dead/live variables be computed for every u ???

201

(8)

Question:

How can the sets of all dead/live variables be computed for every u ???

Idea:

For every edge k = (u, _,v) , define a function [[k]] which transforms the set of variables which are live at v into the set of variables which are live at u ...

202

(9)

[[;]]L = L

[[Pos(e)]] L = [[Neg(e)]] L = L ∪ Vars(e) [[x = e;]] L = (L\{x}) ∪ Vars(e)

[[x = M[e];]] L = (L\{x}) ∪ Vars(e)

[[M[e1] = e2;]] L = L ∪ Vars(e1) ∪ Vars(e2)

203

(10)

[[;]]L = L

[[Pos(e)]] L = [[Neg(e)]] L = L ∪ Vars(e) [[x = e;]] L = (L\{x}) ∪ Vars(e)

[[x = M[e];]] L = (L\{x}) ∪ Vars(e)

[[M[e1] = e2;]] L = L ∪ Vars(e1) ∪ Vars(e2)

[[k]] can again be composed to the effects of [[π]] of paths π = k1 . . . kr by:

[[π]] = [[k1]] ◦ . . . ◦ [[kr]]

204

(11)

205

(12)

206

(13)

{x, y}

207

(14)

{x, y}

{y}

208

(15)

{x, y}

{y}

209

(16)

{x, y}

{y}

{y}

210

(17)

... literally:

• The paths start in u :-)

==⇒ As partial ordering for L we use ⊑ = ⊆ .

• The set of variables which are live at program exit is given by the set X :-)

211

(18)

;

v v

x = e;

;

v v

x 6∈ L[v] x = M[e];

212

(19)

of variables which are live at the beginning of π :-)

→ Correctness of the transformation along a path: If the value of a variable is accessed, this variable is necessarily live. The value of dead variables thus is irrelevant :-)

→ Correctness of the transformation: In any execution of the

transformed programs, the live variables always receive the same values :-))

213

(20)

L[stop] ⊇ X

L[u] ⊇ [[k]] (L[v]) k = (u, _, v) edge

(2) Solving the constraint system by means of RR iteration.

Since L is finite, the iteration will terminate :-) (3) If the exit is (formally) reachable from every program

point, then the smallest solution L of the constraint

system equals L since all [[k]] are distributive :-))

214

(21)

L[stop] ⊇ X

L[u] ⊇ [[k]] (L[v]) k = (u, _, v) edge

(2) Solving the constraint system by means of RR iteration.

Since L is finite, the iteration will terminate :-) (3) If the exit is (formally) reachable from every program

point, then the smallest solution L of the constraint

system equals L since all [[k]] are distributive :-))

Caveat:

The information is propagated backwards !!!

215

(22)

7 x = x 1;

y = x y;

Pos(x > 1) Neg(x > 1)

6 3

4 5 2

y = 1;

1

M[R] = y;

L[0] ⊇ (L[1]\{x}) ∪ {I} L[1] ⊇ L[2]\{y}

L[2] ⊇ (L[6] ∪ {x}) ∪ (L[3] ∪ {x}) L[3] ⊇ (L[4]\{y}) ∪ {x, y}

L[4] ⊇ (L[5]\{x}) ∪ {x} L[5] ⊇ L[2]

L[6] ⊇ L[7] ∪ {y, R} L[7] ⊇ ∅

216

(23)

7 x = x 1;

y = x y;

Pos(x > 1) Neg(x > 1)

6 3

4 5 2

y = 1;

1

M[R] = y;

7 ∅

6 {y, R}

2 {x, y, R} dito 5 {x, y, R}

4 {x, y, R} 3 {x, y, R} 1 {x, R}

0 {I, R}

217

(24)

2

3 1

4

x = y + 1;

z = 2 ∗ x;

M[R] = y;

218

(25)

2

3 1

4

x = y + 1;

z = 2 ∗ x;

M[R] = y;

∅ y, R

219

(26)

2

3 1

4

x = y + 1;

z = 2 ∗ x;

M[R] = y;

∅ y, R x, y, R

220

(27)

2

3 1

4

x = y + 1;

z = 2 ∗ x;

M[R] = y; y, R

∅ y, R x, y, R

221

(28)

2

3 1

4

2

3 1

4 x = y + 1;

z = 2 ∗ x;

M[R] = y; y, R

∅ y, R x, y, R

x = y + 1;

;

M[R] = y;

222

(29)

2

3 1

4

2

3 1

4 x = y + 1;

z = 2 ∗ x;

M[R] = y; y, R

∅ y, R x, y, R

x = y + 1;

;

M[R] = y; y, R

∅ y, R y, R

223

(30)

2

3 1

4

2

3 1

4

2

3 1

4 x = y + 1;

z = 2 ∗ x;

M[R] = y; y, R

∅ y, R x, y, R

x = y + 1;

;

M[R] = y; y, R

∅ y, R y, R

;

;

M[R] = y;

224

(31)

x is called truely live at u along a path π (relative to X), either if x ∈ X , π does not contain a definition of x; or

if π can be decomposed into π = π1 k π2 such that:

• k is a true use of x ;

• π1 does not contain any definition of x.

225

(32)

lab truely used

; ∅

Pos (e) Vars (e) Neg (e) Vars (e)

x = e; Vars (e) (∗)

x = M[e]; Vars (e) (∗) M[e1] = e2; Vars(e1) ∪ Vars(e2)

(∗) – given that x is truely live at v :-)

226

(33)

2

3

4

x = y + 1;

z = 2 ∗ x;

M[R] = y;

227

(34)

2

3

4

x = y + 1;

z = 2 ∗ x;

M[R] = y;

∅ y, R

228

(35)

2

3

4

x = y + 1;

z = 2 ∗ x;

M[R] = y;

∅ y, R y, R

229

(36)

2

3

4

x = y + 1;

z = 2 ∗ x;

M[R] = y;

∅ y, R y, R

230

(37)

2

3

4

2

3

4 x = y + 1;

z = 2 ∗ x;

M[R] = y;

;

;

M[R] = y;

∅ y, R y, R

231

(38)

[[Pos(e)]] L = [[Neg(e)]] L = L ∪ Vars(e) [[x = e;]] L = (L\{x}) ∪ (x ∈ L) ? Vars(e): ∅ [[x = M[e];]] L = (L\{x}) ∪ Vars(e) [[M[e1] = e2;]] L = L ∪ Vars(e1) ∪ Vars(e2)

232

(39)

[[Pos(e)]] L = [[Neg(e)]] L = L ∪ Vars(e) [[x = e;]] L = (L\{x}) ∪ (x ∈ L) ? Vars(e): ∅ [[x = M[e];]] L = (L\{x}) ∪ (x ∈ L) ? Vars(e): ∅ [[M[e1] = e2;]] L = L ∪ Vars(e1) ∪ Vars(e2)

233

(40)

• Nonetheless, they are distributive !!

234

(41)

• Nonetheless, they are distributive !!

To see this, consider for D = 2U , f y = (u ∈ y) ?b : ∅ We verify:

f (y1 ∪ y2) = (u ∈ y1 ∪ y2) ? b: ∅

= (u ∈ y1 ∨ u ∈ y2) ?b: ∅

= (u ∈ y1) ?b: ∅ ∪ (u ∈ y2) ? b: ∅

= f y1 ∪ f y2

235

(42)

• Nonetheless, they are distributive !!

To see this, consider for D = 2U , f y = (u ∈ y) ?b : ∅ We verify:

f (y1 ∪ y2) = (u ∈ y1 ∪ y2) ? b: ∅

= (u ∈ y1 ∨ u ∈ y2) ?b: ∅

= (u ∈ y1) ?b: ∅ ∪ (u ∈ y2) ? b: ∅

= f y1 ∪ f y2

==⇒ the constraint system yields the MOP :-))

236

(43)

True Liveness:

x = x − 1;

;

237

(44)

True Liveness:

x = x − 1;

;

∅ {x}

238

(45)

True Liveness:

x = x − 1;

;

239

Referenzen

ÄHNLICHE DOKUMENTE

The red-green government of Chancellor Gerhard Schröder enforced promotion of electricity produced from renewable energy sources and the gradual restriction of

The sarcophagi were by no means exclusive to underground tombs. They are also to be found among the ruins of the so-called funerary temples which have replaced the

The main feature of our approach is the fact, that we take into account the set of requirements, which are important for business application of a recommender. Thus, we construct

Für die Beschreibung des eigenen Feldes der Ethnografie gilt damit gleichermaßen wie für die Beschreibung von Forschungsfeldern: Das soziale Geschehen lässt sich nicht und soll

- In case you are applying for a travel grant for junior scientists: Does your supervisor still have collaborative projects with Senckenberg or the Alumnus/a respectively. (please

→ Correctness of the transformation along a path: If the value of a variable is accessed, this variable is necessarily live. The value of dead variables thus is irrelevant :-).

As already seen, the sampling window plays an important role in correctly forecast- ing losses during crisis times. A further important role is played by the degree of

Despite agents accumulate the wealth in time that is increasing due the returns of their portfolios, they make decisions upon the value of VaR of the four alternatives in time