Docsity

Analysis of Predicated Code: Optimization and Predicate Relations in EECS 583 - Prof. Scot, Study notes of Electrical and Electronics Engineering

Partial preview of the text

Download Analysis of Predicated Code: Optimization and Predicate Relations in EECS 583 - Prof. Scot and more Study notes Electrical and Electronics Engineering in PDF only on Docsity!

EECS 583 – Lecture 8 Analysis of Predicated Code Optimization Introduction

University of Michigan February 4, 2004

  • 1 -

Recap - Two Types of Analysis Y

Predicate relation analysis^ »

Properties about the values thatpredicates can take on »^

Disjoint

= 2 predicates never

true at the same time »^

Superset

= 1 predicate true more

often »^

Subset

= 1 predicate true less

often »^

Predicate query system

Y

Predicate-sensitive dataflowanalysis^ »

Calculate dataflow informationon predicated code »^

GEN/KILL now occur on acertain predicate (not always)

t = pclearx =p,q = cmpp.uc.un (a<b)t = cmpp.oc(a<b)x =

if p

x =

if q

r,s = cmpp.un.uc(c!=d)

if q

t = cmpp.on(c!=d)

if q

x =

if s

= y

if r

= x

if t

= x

  • 3 -

Single-Target Sequential SSA Form t = pclear x = p,q = cmpp.uc.un (a<b) t = cmpp.oc(a<b) x =

if p

x =

if q

r,s = cmpp.un.uc(c!=d)

if q

t = cmpp.on(c!=d)

if q

x =

if s

= y

if r

= x

if t

= x

t1 = false x =

if true

p = !(a < b) * true q = (a < b) * true t2 = t1 + !(a<b) * true x =

if p

x =

if q

r = (c != d) * q s = !(c != d) * q t3 = t2 + (c != d) * q x =

if s

= y

if r

= x

if t

= x

if true

Note: t2 = p

  • 4 -

Generating Partition Relations

symbol

string

source

Predicate computations reordered to follow the paper p = !(a < b) * true q = (a < b) * true t1 = false t2 = t1 + !(a<b) * true t3 = t2 + (c != d) * q s = !(c != d) * q r = (c != d) * q

symbol

string

source

false

false,t

true

true

!(a<b)*

p,t

(a<b)*

q^

!(c=d)*

r

(c=d)*

s^

t

  • 6 -

Partition Graph Properties Y

Root

= unique node with no

predecessors

Y

Leaf

= node with no

successors

Y

Ancestor

of P = any node on

path from root to P

Y

Descendant

of P = any node

reachable from P

Y

Level

= shortest-path distance

from root^ »

Level(root) = 0

Y

Lowest common ancestor

node with largest level fromthe common ancestors

p = (a<b) * trueq = !(a<b) * truer = (c>d) * ps = !(c>d) * pu = (e!=5) * truev = !(e!=5) * true

p^

q

r^

s

u^

v

  • 7 -

Partition Graph of Earlier Example^ symbol

string

source

false

false,t

true

true

!(a<b)*

p,t

(a<b)*

q^

!(c=d)*

r

(c=d)*

s^

t

true p^

q r^

s

This graph is not complete, no unique root Solution – synthesize additional partitions that are consistent with already existing partitions

  • 9 -

Class Problem – Create the Partition Graph^ r = pclear^ x =^ p,q = cmpp.un.uc (a == b)^ x =

if p

x =

if q

r,s = cmpp.on.uc(c < d)

if p

r,t = cmpp.on.uc(e > f)

if s

u,v = cmpp.un.uc

if r

x =

if s

x =

if v

= x

if r

x =

if t

= x

  • 10 -

PQS – Basic Functions on Pred Expressions Y

lub_sum(P,E) = expression representing a smallest superset of theexecution set P+E

Y

glb_sum(P,E) = expression representing a greatest subset of theexecution set P+E^ »

Used for GEN function »^

x live under E, after use under P, x used under E+P »^

Liveness = any path, over approximation of execution set isconservative, thus use lub_sum

Y

lub_diff(E,P) = an expression representing a smallest superset of theexecution set E-P

Y

glb_diff(E,P) = an expression representing a greatest subset of theexecution set E-P^ »

Used for KILL function »^

x live under E, after a DEF of x under P, x now live under E-P »^

Again, lub_diff an over approximation for any path problem likeliveness

  • 12 -

Representing Predicate Expressions

Y

1-disjunctive normal form (1-dnf)^ »

Restrict predicate expressions to simple form^ y

Code efficiency, complexity

»^

Make conservative approximations when form does not allow theexact answer to be expressed

»^

Disjunctions of individual symbols^ y

P + Q

  • 13 -

Implementing PQS Functions in 1-dnf

1 p^

q r^

s

is_disjoint(p,q) = if there is a partition with p on 1 side, q on the other, then disjoint is_subset(p,q) = if q is an ancestor, then p is a subset lub_sum(p, E) = return p + qi for all qi in E. (Remove redundant/subsumed terms)

t

Examples:

Are p and s disjoint? Are t and p disjoint? Is r a subset of p? Is s a subset of q? s + {q} =? r + {s} =? p + {r,s} =?

  • 15 -

Predicate-Sensitive Dataflow Analysis

Y

Use liveness as representative example

Y

Representation without predicates^ »

On region entry/exit edges

»^

Set of live variables, {r1, r4, r10, r11}

»^

Could represent as a bitvector

Y

Now with predicates^ »

Variable no longer live/not-live

»^

Live for a set of executions

»^

For each variable, have predicate expression in each set^ y

Bitvector becomes vector of predicate expressions

  • 16 -

Predicate-Sensitive Liveness

Destination operands

GEN’

GEN’(x) = GEN(x) – Q KILL’(x) = KILL(x) + Q

x = y + 1 if q

Source (data) operands GEN’(y) = GEN(y) + Q KILL’(y) = KILL(y) - Q

GEN

Source (predicate) operands

backward analysis

GEN’(q) = GEN(q) + true = true KILL’(q) = KILL(q) – true = false

  • = lub_sum - = lub_diff
  • 18 -

What About ON/OC CMPP’s?

Destination operands

GEN’

GEN’(p) = GEN(p) – (a<1)Q KILL’(p) = KILL(p) + (a<1)Q

p = cmpp.on(a<1) if q

Source (data) operands GEN’(a) = GEN(a) + Q KILL’(a) = KILL(a) – Q

GEN

Source (predicate) operands

backward analysis

GEN’(q) = GEN(q) + true = true KILL’(q) = KILL(q) – true = false

  • 19 -

Liveness Example

1 p^

q r^

s

t = pclear x = p,q = cmpp.uc.un (a<b) t = cmpp.oc(a<b) x =

if p

x =

if q

r,s = cmpp.un.uc(c!=d)

if q

t = cmpp.on(c!=d)

if q

x =

if s

= y

if r

= x

if t

t

  1. GEN(x,y) = false, KILL(x,y) = true 2. GEN(x) = t, KILL(x) = s 3. GEN(y) = r, KILL(y) = p+s

backward analysis

  1. GEN(x) = t, KILL(x) = s 5. GEN(x) = p, KILL(x) = q 6. GEN(x) = false, KILL(x) = true 7. GEN(x) = false, KILL(x) = true