Docsity

Dataflow Analysis - The Basics - Lecture Notes | EECS 583, Study notes of Electrical and Electronics Engineering

Partial preview of the text

Download Dataflow Analysis - The Basics - Lecture Notes | EECS 583 and more Study notes Electrical and Electronics Engineering in PDF only on Docsity!

EECS 583 โ€“ Class 6 Dataflow Analysis - The Basics

University of Michigan September 24, 2007

  • 1 -

Reading Material

Todayโ€™s class

Compilers: Principles, Techniques, and Tools

A. Aho, R. Sethi, and J. Ullman, Addison-Wesley, 1988. (Sections: 10.5, 10.6, 10.9, 10.10)

Material for the next class

Compilers: Principles, Techniques, and Tools

A. Aho, R. Sethi, and J. Ullman, Addison-Wesley, 1988, 9.9, 10.2, 10.3, 10.

Material for next Monday (postponed from Wednes)

โ€œAnalysis Techniques for Predicated Codeโ€, R. Johnson and M. Schlansker, MICRO-29, 1996

  • 3 -

Dataflow Analysis Introduction

Pick an arbitrary point in the program Which VRs contain usefuldata values? (liveness or upwardexposed uses)Which definitions may reachthis point? (reaching defns)Which definitions are guaranteedto reach this point? (available defns)Which uses below are exposed?(downward exposed uses)

r1 = r2 + r r6 = r4 โ€“ r

r4 = 4r6 = 8

r6 = r2 + r r7 = r4 โ€“ r

Dataflow analysis

  • Collection of information

that summarizes the creation/destruction of values in a program. Used to identify legal optimization opportunities.

  • 4 -

Live Variable (Liveness) Analysis

Defn: For each point p in a program and each variable y,determine whether y can be used before being redefinedstarting at p

Algorithm sketch

For each BB, y is live if it is used before defined in the BB or it islive leaving the block

Backward dataflow analysis as propagation occurs from usesupwards to defs

4 sets

GEN = set of external variables consumed in the BB

KILL = set of external variable uses killed by the BB

y

equivalent to set of variables defined by the BB

IN = set of variables that are live at the entry point of a BB

OUT = set of variables that are live at the exit point of a BB

Example - GEN/KILL Computation

r1 = MEM[r2+0]

  • 7 -

Compute IN/OUT Sets for all BBs

initialize IN(X) to 0 for all basic blocks X change = 1 while

(change) do

change = 0 for

each basic block in procedure, X, do

old_IN = IN(X) OUT(X) = Union(IN(Y)) for all successors Y of X IN(X) = GEN(X) + (OUT(X) โ€“ KILL(X)) if

(old_IN != IN(X)) then

change = 1

endif

endfor

endfor

  • 9 -

Liveness in Elcor

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

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 -

Class Problem

r1 = 3 r2 = r3r3 = r

r1 = r1 + 1 r7 = r1 * r

r4 = r4 + 1

r4 = r3 + r

r8 = 8

r9 = r7 + r

Compute liveness

Calculate GEN/KILL for each BB Calculate IN/OUT for each BB

  • 12 -

Compute Rdef GEN/KILL Sets for each BB

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

GEN = set of definitions created by an operation KILL = set of definitions destroyed by an operation - Assume each operation only has 1 destination for simplicity

so just keep track of โ€œopsโ€..

Example Rdef GEN/KILL Calculation

r1 = MEM[r2+0]

Example Rdef IN/OUT Calculation

r1 = MEM[r2+0]

  • 16 -

Class Problem

r1 = 3 r2 = r3r3 = r

r1 = r1 + 1 r7 = r1 * r

r4 = r4 + 1

r4 = r3 + r

r8 = 8

r9 = r7 + r

Compute reaching defs

Calculate GEN/KILL for each BB Calculate IN/OUT for each BB

  • r8 = r1 * r r2 = MEM[r1 + 1] - r1 = r1 + - r3 = r5 โ€“ r - r7 = r3 * - r2 = - r7 = r1 + r - r3 = - r3 = r3 + r - r1 = r2 โ€“ r - r3 = r1 *
  • BB - BB - BB - BB
    • r8 = r1 * r r2 = MEM[r1 + 1] - r1 = r1 + - r3 = r5 โ€“ r - r7 = r3 * - r2 = - r7 = r1 + r - r3 = - r3 = r3 + r - r1 = r2 โ€“ r - r3 = r1 *
  • BB - BB - BB - BB
    • r8 = r1 * r r2 = MEM[r1 + 1] - r1 = r1 + - r3 = r5 โ€“ r - r7 = r3 * - r2 = - r7 = r1 + r - r3 = - r3 = r3 + r - r1 = r2 โ€“ r - r3 = r1 *
  • BB - BB - BB - BB
  • r1 = Example โ€“ DU/UD Chains
    • r2 = r3r3 = r
      • r1 = r1 +
        • r7 = r1 * r
          • r4 = r4 +
          • r4 = r
            • r8 =
              • r9 = r7 + r
  • 19 -

DU/UD Chains in Elcor

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

Accessing the info

Stored as an attribute on a Region

Reaching_defs_info rdi = get_reaching_defs_info(Region)

Reference (El_ref, Graph/ref.h)

Operand cross operation

More fine grain that operation (handles multiple dests/srcs)

ย™

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