Liveness Analysis - Code Generation - Exam, Exams of Computer Science

Main points of this exam are: Liveness Analysis, Influence, Design, Modern Optimising, Traditional Serial, Convert Traditional, Automatically Convert, Compiler, Code Run, Machine

Typology: Exams

2012/2013

Uploaded on 04/27/2013

balraj
balraj 🇮🇳

4.6

(8)

36 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
University of Cape Town
Department of Computer Science
CSC3003S Final Exam
2008
Marks : 30
Time : 3 hours
Instructions:
Answer all questions from Section A and 3 questions from Section B.
Show all calculations where applicable.
Section A [ Answer Question ONE – this is compulsory ]
Question 1 [ 10 marks ]
Multi-core CPUs can influence the design of modern optimising compilers. Firstly, the
compiler could automatically convert traditional serial code into a parallel form, where 2 or
more pieces of code run at the same time on different CPUs/cores. Secondly, the compiler itself
could perform its processing in parallel. Answer the following questions with this in mind.
1) Describe one advantage and one disadvantage of separating the compiler front-end from the
compiler back-end. [2]
ad: easier to retarget compiler to new machine [1], easier to apply optimisations to IR [1],
easier to build compiler for new language [1]
disad: more work [1] slower compilation [1]
2) Describe one advantage in having multiple distinct layers (frame generation, code generation,
instruction selection, liveness analysis, etc.) within the compiler back-end. [1]
easier to replace or change functionality in individual parts of compiler [1]
3) Static semantics should be checked before any code is generated. Discuss 2 examples of errors
that can be checked for. [2]
use before declaration [1] size mismatch [1] array index out of bounds [1] type incompatibility
[1] etc.
4) Describe 3 typical optimisations that a compiler can perform on generated IR code, assuming
the code being optimised runs on a single CPU/core. [3]
trace analysis [1] common subexpression elimination [1] constant folding [1] etc.
5) At which point/layer in the compilation process could the code being compiled be converted
into segments that may run in parallel (assuming this is done independently of source
language)? [1]
pf3
pf4
pf5

Partial preview of the text

Download Liveness Analysis - Code Generation - Exam and more Exams Computer Science in PDF only on Docsity!

University of Cape Town

Department of Computer Science

CSC3003S Final Exam

Marks : 30 Time : 3 hours Instructions:

  • Answer all questions from Section A and 3 questions from Section B.
  • Show all calculations where applicable. Section A [ Answer Question ONE – this is compulsory ] Question 1 [ 10 marks ] Multicore CPUs can influence the design of modern optimising compilers. Firstly, the compiler could automatically convert traditional serial code into a parallel form, where 2 or more pieces of code run at the same time on different CPUs/cores. Secondly, the compiler itself could perform its processing in parallel. Answer the following questions with this in mind.
  1. Describe one advantage and one disadvantage of separating the compiler frontend from the compiler backend. [2] ad: easier to retarget compiler to new machine [1], easier to apply optimisations to IR [1], easier to build compiler for new language [1] disad: more work [1] slower compilation [1]
  2. Describe one advantage in having multiple distinct layers (frame generation, code generation, instruction selection, liveness analysis, etc.) within the compiler backend. [1] easier to replace or change functionality in individual parts of compiler [1]
  3. Static semantics should be checked before any code is generated. Discuss 2 examples of errors that can be checked for. [2] use before declaration [1] size mismatch [1] array index out of bounds [1] type incompatibility [1] etc.
  4. Describe 3 typical optimisations that a compiler can perform on generated IR code, assuming the code being optimised runs on a single CPU/core. [3] trace analysis [1] common subexpression elimination [1] constant folding [1] etc.
  5. At which point/layer in the compilation process could the code being compiled be converted into segments that may run in parallel (assuming this is done independently of source language)? [1]

after code generation but before liveness analysis [1]

  1. Briefly describe one technique to exploit multiple cores in the compilation process itself. [1] after activation records, proceed in parallel [1] perform peephole optimisation in parallel [1] etc.

b) For the following program, first separate the code into basic blocks, then rearrange the blocks into traces and finally optimise the code by removing redundant jumps. Show each step separately. [5] Start: Statement Jump X Z: Statement Jump A X: Statement Jump Y A: Statement Y: Statement Jump Z (a) breaking into blocks [1] adding jump [1] Start: Statement Jump X Z: Statement Jump A X: Statement Jump Y A: Statement Jump Y Y: Statement Jump Z (b) sequence of statements [1] Start: Statement Jump X X: Statement Jump Y Y: Statement

Jump Z Z: Statement Jump A A: Statement Jump Y (c) removal of redundant jumps [1] retaining of all labels and final jump [1] Start: Statement X: Statement Y: Statement Z: Statement A: Statement Jump Y Question 6: Register Allocation [ 10 marks ] a) Use the iterative liveness analysis algorithm to calculate the livein and liveout sets for each of the following statements in a program, with the initial and final live sets indicated assume livein (succ ( d=a+b+c )) = {d}. Use the statement numbers provided. Show the succ, use, def and pairs of in/out sets. The last calculated in/out pair must be identical to the previous pair to indicate convergence. [6] [livein: a, b] 1: if (a<b) 2: then c = a; 3: else c = b; 4: d = a + b + c; [liveout: d] Hint: The relevant formula can be stated as follows: out[n] = union of in[s] for all successors s of n in[n] = union of use[n] and (out[n] – def[n]) Iteration 1 Iteration 2 Succ Use Def In Out In Out In:a,b If (a<b) 2,3 ab ab ab ab ab Then c = a 4 a c ab abc ab abc Else c = b 4 b c ab abc ab abc d = a+b+c abc d abc d abc d Out: d Succ [1], Use [1], Def [1], In [1], Out [1], last two iterations being equal [1]

This makes a and b of <K degree, so they can be simplified. [1] Popping the nodes off the stack, we can then assign: [1] A: R B: R C and D: R