ps5-sol - ECE 468 Problem Set 5: Dataflow analysis 1. Show...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the 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 Ill 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 out-sets to > , except for statement 1, whose in-set 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 1s out-set gets updated to 4 . Because the out-set has changed, all of statement 1s successors need to be processed. This causes statement 2s in-set to be changed to 4 , and its out-set to be changed to { 4 , 7 } . This causes statement 2s successors to be updated. Statement 3 has two predecessors: 2 and 11, so its in-set 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 in-set and its out-set. 12 has no successors12....
View Full Document

Page1 / 8

ps5-sol - ECE 468 Problem Set 5: Dataflow analysis 1. Show...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online