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 5: Dataflow analysis 1. Show the results of running a liveness 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: b = a + x; 7: goto L3 L2 8: a = a + x; 9: b = x + 1; L3 10: y = a + b; 11: goto L1; L4 12: halt Answer: We will show the results of the available expression analysis below; the liveness analysis proceeds similarly, but with GEN and KILL determined by the variables used and defined in a statement, and the analysis run backwards. 2. Show the results of running an available expression analysis on the code, by indicat ing which expressions are available at each instruction. Answer: First, we determine the successors and predecessors for each instruction. We can do this by building the control flow graph, but I’ll just present the same information in a table: 1 Instruction Predecessors Successors 1 None 2 2 1 3 3 2, 11 4, 12 4 3 5, 8 5 4 6 6 5 7 7 6 10 8 4 9 9 8 10 10 7, 9 11 11 10 3 12 3 None We then build the GEN and KILL sets for each instruction. Note that the expressions in the program are: 4 , 7 , x > c , y > 3 , x + 1 , a + x and a + b . Instruction GEN KILL 1 4 x + 1 , a + x 2 7 y > 3 3 x > c None 4 y > 3 None 5 x + 1 a + x , a + b 6 a + x a + b 7 None None 8 None a + x , a + b 9 x + 1 a + b 10 a + b y > 3 11 None None 12 None None Recall that this is a forward analysis. We initialize all of the available expression in and outsets to > , except for statement 1, whose inset is initialized to ∅ . 2 Instruction IN OUT 1 ∅ > 2 > > 3 > > 4 > > 5 > > 6 > > 7 > > 8 > > 9 > > 10 > > 11 > > 12 > > We then begin updating the in and out sets, starting from statement 1. Statement 1’s outset gets updated to 4 . Because the outset has changed, all of statement 1’s successors need to be processed. This causes statement 2’s inset to be changed to 4 , and its outset to be changed to { 4 , 7 } . This causes statement 2’s successors to be updated. Statement 3 has two predecessors: 2 and 11, so its inset is updated to { 4 , 7 } ∩> , leading to the following situation: Instruction IN OUT 1 ∅ 4 2 4 4 , 7 3 4 , 7 4 , 7 , x > c 4 > > 5 > > 6 > > 7 > > 8 > > 9 > > 10 > > 11 > > 12 > > We must now process all successors of statement 3, which means we must process 4 and 12. We first process 12, updating its inset and its outset. 12 has no successors12....
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