Docsity

Dataflow Analysis, Analysis of Predicated Code - Fall 2004 | EECS 583, Study notes of Electrical and Electronics Engineering

Partial preview of the text

Download Dataflow Analysis, Analysis of Predicated Code - Fall 2004 | EECS 583 and more Study notes Electrical and Electronics Engineering in PDF only on Docsity!

  • 1 -

Beyond Liveness or Upward Exposed Uses^ Y^ Upward exposed defs^ »^ IN = GEN + (OUT – KILL)^ »^ OUT = Union(IN(successors))^ »^ Walk ops reverse order^ y^

GEN += dest; KILL += dest Y Downward exposed uses » IN = Union(OUT(predecessors)) » OUT = GEN + (IN-KILL) » Walk ops forward order y GEN += src; KILL -= src; y GEN -= dest; KILL += dest; Y Downward exposed defs » IN = Union(OUT(predecessors)) » OUT = GEN + (IN-KILL) » Walk ops forward order y GEN += dest; KILL += dest;

  • 3 -

Generalized DF Analysis in Elcor^ Y^ Calculate all up/down info^ » delete_local_analysis_info_for_all_hbs_bbs(Region);^ » create_local_analysis_info_for_all_hbs_bbs(Region);^ » el_flow_compute_four_dataflow_sets(Region*,ANALYZE_ALLREG);^ » Generally only liveness useful for straight-line code^ » Other sets come into play when scheduling loops^ y^

Moving code across the backedge

  • 4 -

What About All Path Problems?^ Y^ Up to this point^ »^ Any path problems (maybe relations)^ y^

Definition reaches along some path y Some sequence of branches in which def reaches y Lots of defs of the same variable may reach a point » Use of Union operator

in meet function

Y^ All-path: Definition guaranteed to reach^ »^ Regardless of sequence of branches taken, def reaches^ »^ Can always count on this^ »^ Only 1 def can be guaranteed to reach^ »^ Availability (as opposed to reaching)^ y^ Available definitions^ y^ Available expressions (could also have reaching expressions, but notthat useful)

  • 6 -

Available Definition Analysis (Adefs)^ Y^ A definition d is available

at a point p if along all

paths

from d to p, d is not killed Y Remember, a definition of a variable is killed

between 2

points when there is another definition of that variablealong the path^ »^ r1 = r2 + r3 kills previous definitions of r1 Y Algorithm^ »^ Forward dataflow analysis as propagation occurs from defsdownwards^ »^ Use the Intersect function as the meet operator to guarantee theall-path requirement^ »^ GEN/KILL/IN/OUT similar to reaching defs^ y^ Initialization of IN/OUT is the tricky part

  • 7 -

Compute GEN/KILL Sets for each BB (Adefs)^ Exactly the same as reaching defs !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

for^ each basic block in the procedure, X, do^ GEN(X) = 0^ KILL(X) = 0^ for^ each operation in sequential order in X, op, do^ for^ each destination operand of op, dest, do^ G = op^ K = {all ops which define dest – op}^ GEN(X) = G + (GEN(X) – K)^ KILL(X) = K + (KILL(X) – G)^ endfor^ endfor endfor

  • 9 -

Example Adefs Calculation^ 1: r1 = MEM[r2+0]^ 2: r2 = r2 + 1^ 3: r3 = r1 * r4^ 4: r1 = r1 + 5^ 5: r3 = r5 – r1^ 6: r8 = r3 * 2

7: r7 = 0 8: r1 = r1 + 5 9: r7 = r1 - 6 10: r8 = r7 + r8 11: r1 = r3 – r8 12: r3 = r1 * 2

  • 10 -

Available Expression Analysis (Aexprs)^ Y^ An expression

is a RHS of an operation »^ r2 = r3 + r4, r3+r4 is an expression Y An expression e is available

at a point p if along all

paths

from e to p, e is not killed Y An expression is killed

between 2 points when one of its source operands are redefined^ »^ r1 = r2 + r3 kills all expressions involving r1 Y Algorithm^ »^ Forward dataflow analysis as propagation occurs from defsdownwards^ »^ Use the Intersect function as the meet operator to guarantee theall-path requirement^ »^ Looks exactly like adefs, except GEN/KILL/IN/OUT are theRHS’s of operations rather than the LHS’s

  • 12 -

Efficient Calculation of Dataflow^ Y^ Order basic blocks are visited is important (fasterconvergence)^ Y^ Forward analysis – DFS order^ »^ Visit a node only when all its predecessors have been visited^ »^ Visit(n)^ y^

mark n as visited y for each successor of n not yet visited, s, do^ X^ Visit (s) y postorder(n) = count y count += 1 » count = 1; Visit(entry) Y Backward analysis – PostDFS order » Visit a node only when all of its successors have been visited

  • 13 -

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

  • 15 -

Predicate Relation Analysis^ 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

p^ q r^ s t

  • 16 -

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}

  • 18 -

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

  • 19 -

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