This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: ECE 468 Problem Set 7: Dataflow analysis 1. Show the results of running a reaching definition analysis on the following piece of code: For each line of code, show which definitions reach that line of code by indicating the line number the definition occurred in. 1: x = 4; 2: y = 7; L1 3: if (x > c) goto L4 4: if (y > 3) goto L2 5: a = x + 1; 6: y = x + 2; 7: goto L3 L2 8: y = x + 1; 9: x = x + 1; L3 10: x = x + 1; 11: goto L1; L4 12: halt Answer: To begin, let us build the statementlevel CFG for this program: 1 x = 4 y = 7 L1: if x > c goto L4 if y > 3 goto L2 a = x + 1 y = x + 2 goto L3 L2: y = x + 1 x = x + 1 L3: x = x + 1 goto L1 L4: halt For each statement, we begin by calculating the GEN and KILL sets. In the case of reaching definitions, the GEN set for a statement is the set of definitions (line number & variable) created in that statement. The KILL set is all other definitions of that variable. 2 Line # GEN KILL 1 [x, 1] [x, 9], [x, 10] 2 [y, 2] [y, 6], [y, 8] 3 4 5 [a, 5] 6 [y, 6] [y, 2], [y, 8] 7 8 [y, 8] [y, 2], [y, 6] 9 [x, 9] [x, 1], [x, 10] 10 [x, 10] [x, 1], [x, 9] 11 12 We now start calculating IN and OUT for each statement, according to dataflow equations. Reaching definitions is a forward analysis (because we care about what happened in the past), so the IN set for a statement is based on the predecessors’ OUT sets. Reaching definitions is also an anypath analysis, so at merge statements, we combine the incoming sets using set union: IN ( s ) = [ t ∈ pred ( s ) OUT ( t ) OUT ( s ) = GEN ( s ) ∪ ( IN ( s ) KILL ( s )) All the sets start as empty (no reaching definitions), and we start with the first statement in the program: IN (1) = {} OUT (1) = { [ x, 1] } Because changing OUT(1) might change the value of its successors, we next process statement 2: IN (2) = OUT (1) = { [ x, 1] } OUT (2) = { [ x, 1] , [ y, 2] } which then changes statement 3. Note that statement 3 has two predecessors, but OUT(11) is currently empty: IN (3) = OUT (2) ∪ OUT (11) = { [ x, 1] , [ y, 2] } OUT (3) = { [ x, 1] , [ y, 2] } 3 Statement 3 has two successors, statements 4 and 12, so we need to update both of their sets: IN (4) = OUT (3) = { [ x, 1] , [ y, 2] } OUT (4) = { [ x, 1] , [ y, 2] } IN (12) = OUT (3) = { [ x, 1] , [ y, 2] } OUT (12) = { [ x, 1] , [ y, 2] } Statement 4 has two successors, so we need to update statements 5 and 8:...
View
Full
Document
This note was uploaded on 02/19/2012 for the course ECE 468 taught by Professor Test during the Fall '08 term at Purdue.
 Fall '08
 TEST

Click to edit the document details