Docsity

Dataflow Analysis and Optimal Control in EECS 583 – Lecture 8 at University of Michigan - , Study notes of Electrical and Electronics Engineering

Partial preview of the text

Download Dataflow Analysis and Optimal Control in EECS 583 – Lecture 8 at University of Michigan - and more Study notes Electrical and Electronics Engineering in PDF only on Docsity!

  • 1 -

Last time^ Y^ Liveness – variables that containuseful values (i.e., they areconsumed)»^ USE = used before defined»^ DEF = defined»^ IN = USE + (OUT-DEF)»^ OUT = Union(IN(successors))»^ backward dataflow»^ any-path relation»^ variable-level info on edges

r1 = r2 + r3r6 = r4 – r

r4 = 4r6 = 8 r6 = r2 + r3r7 = r4 – r

r2, r3, r5are live r2, r3, r4, r5are live

  • 3 -

Generalizing dataflow analysis^ Y^ Transfer function^ »^ How information is changed by “something” (BB)^ »^ OUT = GEN + (IN – KILL) /* forward analysis */^ »^ IN = GEN + (OUT – KILL)

/* backward analysis */

Y^ Meet function^ »^ How information from multiple paths is combined^ »^ IN = Union(OUT(predecessors))

/* forward analysis */

»^ OUT = Union(IN(successors)) /* backward analysis */ Y Generalized dataflow algorithm »^ while (change)^ y^ change = false^ y^ for each BB^ X^ apply meet function^ X^ apply transfer functions^ X^ if any changes

Æ^ change = true

  • 4 -

Liveness using GEN/KILL^ Y^ Liveness = upward exposed uses

for^ each basic block in the procedure, X, do^ up_use_GEN(X) = 0^ up_use_KILL(X) = 0^ for^ each operation in reverse sequential order in X, op, do^ for^ each destination operand of op, dest, do^ up_use_GEN(X) -= dest^ up_use_KILL(X)

+= dest endfor for^ each source operand of op, src, do^ up_use_GEN(X) += src^ up_use_KILL(X) -= src endfor endfor endfor

  • 6 -

Beyond liveness (upward exposed uses)^ Y^ Upward exposed defs^ »^ Walk ops reverse order^ y^ GEN += dest; KILL += dest^ »^ IN = GEN + (OUT – KILL)^ »^ OUT = Union(IN(successors))^ 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;

  • 9 -

Liveness in Elcor^ Y^ Calculating the info^ »^ delete_local_analysis_info_for_all_hbs_bbs(Region);^ »^ create_local_analysis_info_for_all_hbs_bbs(Region);^ y^ Analysis/pred_analysis.cpp^ y^ Calculates intra-BB info (i.e., GEN/KILL)^ »^ el_flow_compute_liveness(Region, ANALYZE_ALLREG);^ y^ Analysis/flow_analysis_solver.cpp^ y^ Applies meet/transfer functions to compute IN/OUT^ »^ Generally liveness always done on a Procedure^ Y^ Accessing the info^ »^ Stored as an attribute on Control edges from branches^ »^ Liveness_info live = get_liveness_info(Edge*);^ »^ Liveness_info

Æ^ List »^ Iterate over it, check for membership, etc.

  • 10 -

Liveness in Elcor (2)^ 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

  • 12 -

Example DU/UD chains^ 1: r1 = MEM[r2+0]^ 2: r2 = r2 + 1^ 3: r3 = r1 * r4^ 4: r1 = r1 + 5^ 5: r3 = r5 – r1^ 6: r7 = r3 * 2

7: r7 = r6 8: r2 = 0 9: r7 = r7 + 1 10: r8 = r7 + 5 11: r1 = r3 – r8 12: r3 = r1 * 2

  • 13 -

DU/UD chains in Elcor^ Y^ Calculating the info (Analysis/reaching_defs_solver.cpp)^ »^ Compute liveness first on the procedure^ »^ El_do_reaching_defs(Region*, ANALYZE_ALLREG)^ »^ Generally, done on small region, like BB or HB^ Y^ Accessing the info^ »^ Stored as an attribute on a Region^ »^ Reaching_defs_info rdi = get_reaching_defs_info(Region)^ Y^ Reference (El_ref, Graph/ref.h)^ »^ Operand cross operation^ »^ More fine grain that operation (handles multiple dests/srcs)^ Y^ Given a ref^ »^ List<El_ref> &defs = rdi->get_ud_chain(ref)^ y^ Should be a src ref^ »^ List<El_ref> &uses = rdi->get_du_chain(ref)^ y^ Should be a dest ref

  • 15 -

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, butnot that useful)

  • 16 -

Reaching vs available definitions^ 1:r1 = r2 + r3^ 2:r6 = r4 – r

1,2 reach^ 1,2 available^ 3:r4 = 4^ 4:r6 = 8 5:r6 = r2 + r36:r7 = r4 – r

1,2,3,4 reach1 available 1,2 reach 1,2 available

1,3,4 reach 1,3,4 available

  • 18 -

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

  • 19 -

Compute IN/OUT sets for all BBs (adefs)^ U = universal set of all operations in the Procedure^ IN(0) = 0^ OUT(0) = GEN(0)^ for each basic block in procedure, W, (W != 0), do

IN(W) = 0 OUT(W) = U – KILL(W) change = 1 while^ (change) do change = 0 for^ each basic block in procedure, X, do^ old_OUT = OUT(X)^ IN(X) = Intersect(OUT(Y)) for all predecessors Y of X^ OUT(X) = GEN(X) + (IN(X) – KILL(X))^ if^ (old_OUT != OUT(X)) then^ change = 1^ endif endfor endfor