



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Main points of this exam are: Modern Optimising, Influence, Design, Modern Optimising Compilers, Parallel, Traditional Serial Code, Convert Traditional, Automatically Convert, Advantage, Disadvantage
Typology: Exams
1 / 7
This page cannot be seen from the preview
Don't miss anything!




Marks : 30 Time : 3 hours Instructions:
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.
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]
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]
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.
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.
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]
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.
nesting [1] call sequence [1] locals [1] formal parameters [1] actual parameters [1]
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
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 live-in and live-out sets for each of the following statements in a program, with the initial and final live sets indicated - assume live-in (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] [live-in: a, b]
1: if (a<b) 2: then c = a;
3: else c = b; 4: d = a + b + c;
[live-out: 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