Slides on Dataflow Analysis - Fall 2005 | EECS 583, Study notes of Electrical and Electronics Engineering

Material Type: Notes; Professor: Mahlke; Class: Advanced Compilers; Subject: Electrical Engineering And Computer Science; University: University of Michigan - Ann Arbor; Term: Winter 2005;

Typology: Study notes

Pre 2010

Uploaded on 09/02/2009

koofers-user-5ef-2
koofers-user-5ef-2 🇺🇸

9 documents

1 / 35

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
EECS 583 – Class 7
Dataflow Analysis
University of Michigan
January 31, 2005
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23

Partial preview of the text

Download Slides on Dataflow Analysis - Fall 2005 | EECS 583 and more Study notes Electrical and Electronics Engineering in PDF only on Docsity!

  • 1 -

Reading Material^ Y^ 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) Y Material for the next lecture » “Analysis Techniques for Predicated Code”, R. Johnson and M. Schlansker, MICRO-29, 1996

  • 3 -

Dataflow Analysis Introduction

Dataflow analysis^ – Collection of information that summarizes the creation/destruction of r1 = r2 + r3 values in a program. Used to identify legal r6 = r4 – r5 optimization opportunities.Pick an arbitrary point in the program^ Which VRs contain usefuldata values? (liveness or upward r4 = 4exposed uses) r6 = 8Which definitions may reachthis point? (reaching defns)Which definitions are guaranteed r6 = r2 + r3to reach this point? (available defns) r7 = r4 – r5Which uses below are exposed?(downward exposed uses)

  • 4 -

Live Variable (Liveness) Analysis^ Y^ Defn: For each point p in a program and each variable y,determine whether y can be used before being redefinedstarting at p^ Y^ 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^ Y^ 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

  • EECS 583 – Class 7 Dataflow Analysis University of Michigan January 31,
  • Example - GEN/KILL Computation BB1 r1 = MEM[r2+0] r2 = r2 + 1 r3 = r1 * r
  • GEN(1) = r2,r4 KILL(1) = r1,r
  • GEN(2) = r1,r5 r1 = r1 + 5 r3 = r5 – r1 r7 = r3 *
  • BB3 r2 = 0 r7 = 23 r1 =
  • KILL(2) = r3,r7 BB
  • GEN(3) = 0 KILL(3) = r1, r2, r
  • BB4 r3 = r3 + r7 GEN(4.3) = r3,r7,r8 r1 = r3 – r8 r3 = r1 *
  • KILL(4.3) = r1 GEN(4.2) = r3,r8 KILL(4.2) = r1 GEN(4.1) = r1 KILL(4.1) = r
  • 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^ 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 -

Class Problem

Compute liveness^ Calculate GEN/KILL for each BB r1 = 3^ Calculate IN/OUT for each BB r2 = r3 r3 = r r1 = r1 + 1 r7 = r1 * r2 r4 = r4 + 1 r4 = r3 + r2^ r8 = 8^ r9 = r7 + r

  • 12 -

Rdefs (2)^ Y^ Algorithm sketch^ » Forward dataflow analysis as propagation occurs fromdefs downwards^ » (Liveness was backwards!)^ Y^ 4 sets^ » GEN = set of definitions generated in the BB^ » KILL = set of definitions killed in the BB^ » IN = set of definitions reaching the BB entry^ » OUT = set of definitions reaching the BB exit

  • 13 -

Compute Rdef GEN/KILL Sets for each BB^ 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”..^ 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

  • 15 -

Compute Rdef IN/OUT Sets for all BBs^ IN = set of definitions reaching the entry of BB^ OUT = set of definitions leaving BB^ initialize IN(X) = 0 for all basic blocks X^ initialize OUT(X) = GEN(X) for all basic blocks X^ change = 1^ while^ (change) do^ change = 0^ for^ each basic block in procedure, X, do^ old_OUT = OUT(X)^ IN(X) = Union(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

  • 16 -

Example Rdef IN/OUT Calculation^ r1 = MEM[r2+0]^ r2 = r2 + 1^ r3 = r1 * r4^ r1 = r1 + 5^ r3 = r5 – r1^ r7 = r3 * 2

r2 = 0 r7 = 23 r1 = 4 r8 = r7 + 5 r1 = r3 – r8 r3 = r1 * 2

  • 18 -

DU/UD Chains^ Y^ Convenient way to access/use reaching defs info^ Y^ Def-Use chains^ » Given a def, what are all the possible consumers of theoperand produced^ » Maybe consumer^ Y^ Use-Def chains^ » Given a use, what are all the possible producers of theoperand consumed^ » Maybe producer

  • 19 -

Example – DU/UD Chains^ r1 = 3^ r2 = r3^ r3 = r4^ r1 = r1 + 1^ r7 = r1 * r2^ r4 = r4 + 1^

r4 = r3 r8 = 8 r9 = r7 + r