Docsity

Analysis of Predicated Code - Lecture Slides | EECS 583, Study notes of Electrical and Electronics Engineering

Partial preview of the text

Download Analysis of Predicated Code - Lecture Slides | EECS 583 and more Study notes Electrical and Electronics Engineering in PDF only on Docsity!

  • EECS 583 – Lecture 10 Analysis of Predicated Code University of Michigan February 10,
  • 1 -

Analysis Problem in the Predicate Domain

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 x =a < b x = x =c != d^ = y^

x = = x^ = x

True True False u False p q

s r t v

Which definitions of x reach each use?

u

  • 3 -

Execution Traces/Sets^ Y^ Execution trace

  • record of boolean

values assigned to predicates duringan execution of a predicate block^ »^ 1 = all execution traces Y Execution set

for predicate p – set

of traces in which p is True^ »^ Denoted as P^ »^ P is a subset of 1 Y Code segment^ »^ Execution traces^ y^ trace^

p^ q^ r^ s^ t y e1 (^1 0 0 0 1) y e2 (^0 1 1 0 1) y e3 (^0 1 0 1 0) » Execution sets y P = {e1}, Q = {e2,e3}, R = {e2}, S= {e3}, T = {e1,e2}, 1 ={e1,e2,e3}

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

  • 4 -

Predicate Expressions^ Y^ Predicate expression

Execution set that is a derivedby combining the executionsets of individual predicatesusing operators: sum(+),difference(-), product(*)

trace^ p^ q^ r^ s t e1^1 0 0

1 e2^0 1 1

1 e3^0 1 0

0 P = {e1},Q = {e2,e3},R = {e2}S = {e3}T = {e1,e2}1 = {e1,e2,e3}P + S = {e1} + {e3} = {e1,e3}T – P = {e1,e2} – {e1} = {e2}

  • 6 -

Partitioning by a CMPP^ Y^ m,n = cmpp.un.uc (i < k) if u^ »^ If m or n is true, then u must be true^ »^ If m is true, then n must be false (+ the reverse)^ »^ If u is true, then one of m or n is true^ »^ If u is false, then both m and n are false^ Y^ Execution sets^ »^ M union N <= U^ »^ M intersect N = Null^ »^ U <= M union N^ Y^ U is partitioned into disjoint subsets M and N, U = M | N

u m n

  • 7 -

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

  • 9 -

Partition Graph^ Y^ Partition Graph

  • Directed

acyclic graph where nodesrepresent execution sets andedges represent partitionrelations between nodes^ »^ U = M | N^ »^ Edge from U to M^ »^ Edge from U to N^ »^ UÆM and U

ÆN denoted tocome from same partition

Y^ Complete

  • Contains a uniquenode having no predecessorsfrom which all nodes arereachable

p = (a<b) * true q = !(a<b) * true r = (c>d) * p s = !(c>d) * p u = (e!=5) * true v = !(e!=5) * true^1 p^ q^

u^ v r^ s

  • 10 -

Partition Graph Properties^ Y^ Root^ = unique node with nopredecessors^ Y^ Leaf^ = node with nosuccessors^ Y^ Ancestor

of P = any node onpath from root to P

Y^ Descendant

of P = any nodereachable from P

Y^ Level^ = shortest-path distancefrom 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^1 p^ q^ r^ s

u^ v

  • 12 -

Synthesizing New Partitions

1 p^ q r^ s (^16) p q r^ s

6 lca(p,r) = 1^ 1 – 6 = 1 – (p + r) = 1 – p – r = s Identify partition, U = M|N where U is not reachable from 1 If M,N are reachable from 1, then there exists a partition^ lca(M,N) = U|V, where V is the relative complement

of U with respect to lca(M,N)

  • 13 -

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

  • 15 -

PQS – Basic Functions (2)^ Y^ is_disjoint(P,E) = true if the execution set P*E = NULL^ »^ Property holds for some execution at a point under a predicate^ »^ 1: x = y + z if p^ »^ …^ »^ 2: t = x if q^ »^ 1 reaches 2 as long as p and q are not

disjoint

Y^ is_subset(P,E) = true if P is a subset of the execution setrepresented by E^ »^ Property holds for all executions at a point under a predicate^ »^ x = y + z if p^ »^ …^ »^ t = y + z if q^ »^ y+z available at the 2

nd^ operation only if q is a subset of p

  • 16 -

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

  • 18 -

Implementing PQS Functions in 1-dnf (2) lub_diff(E, p) = return Sum(qi-p) for all qi in E. 4 subcases^ 1. qi <= p^ Æ

qi removed, E += NULL 2. p <= qi Æ E += rel_cmpl(p,qi) 3. p,qi disjoint^ Æ^ E += qi 4. otherwise Æ^ E += approx_diff(p,q) /* q – p */ approx_diff(p,q)^ relative_complement(p, lca(p,q)) relative_complement(p,q)^ find a path from q to p^ E = false^ for each edge r

Æ^ s on path do let R = S|Ti be the partition containing rÆ^ s add Ti to E return E

(^1) t p^ q r^ s Examples: {q} – r =? {q} – p =? {t} – r =? {t} – s =?

  • 19 -

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