0% found this document useful (0 votes)
25 views9 pages

CS3501 CD Qb-Unit 5

CS3501 CD QB-UNIT 5

Uploaded by

paviganesh8789
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views9 pages

CS3501 CD Qb-Unit 5

CS3501 CD QB-UNIT 5

Uploaded by

paviganesh8789
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 9

DEPARTMENT OF COMPUTING TECHNOLOGIES

Name of the Faculty Member : Mrs.R.PAVITHRA


Designation and Department : ASSISTANT PROFESSOR / CT
Academic Year : 2024-2025(ODD)
Class : III -CSE
Subject with Code & Name : CS3501 – COMPILER DESIGN

QUESTION BANK

UNIT-V CODE OPTIMIZATION

Part -A
1. List out two properties of reducible flow graph. A/M 2012
 Reducible flow graphs are special flow graphs, for which several code
optimization transformations are especially easy to perform, loops are
unambiguously defined, dominators can be easily calculated.
 Data flow analysis problems can also be solved efficiently.

2. List the advantage and application of DAG. N/D 2012, M/J’2013


 We can automatically detect common sub expressions.
 We can determine the statements that compute the values, which could
be used outside the block.
 We can determine which identifiers have their values used in the block.

3. What are the uses of register and address descriptor in code generator? N/D
2012
 A register descriptor keeps track of what is currently in each register.
 An address descriptor keeps track of the location where the current
value of the name can be found at run time.

4. Define Live variable. N/D 2012


The framework is similar to reaching definitions, except that the transfer
function runs backward. A variable is live at the beginning of a block if it is
Page 1 of 9
either used before definition in the block or is live at the end of the block and not
redefined in the block.

5. What is data flow analysis ? N/D 2012, N/D’2014


Data-flow analysis" refers to a body of techniques that derive information
about the flow of data along program execution paths. For example, one way to
implement global common sub expression elimination requires us to determine
whether two textually identical expressions evaluate to the same value along any
possible execution path of the program.

6. Define Basic blocks and Flow graph.


M/J’2013, N/D’2014 Basic block
A sequence of consecutive statements which may be entered only at the
beginning and when entered are executed in sequence without halt or possibility
of branch , are called basic blocks.
Flow graph
 The basic block and their successor relationships shown by a directed
graph is called a flow graph.
 The nodes of a flow graph are the basic blocks.

7. What is constant folding ? M/J’2013


 We can eliminate both the test and printing from the object code. More
generally, deducing at compile time that the value of an expression is a
constant and using the constant instead is known as constant folding.
 One advantage of copy propagation is that it often turns the copy statement into
dead code.
 For example,
a=3.14157/2 can be replaced by
a=1.570 thereby eliminating a division operation.

8. What are the properties of optimizing compiler? M/J’2013, N/D’2013, M/J’2016


1. Transformation must preserve the meaning of programs.
2. Transformation must, on the average, speed up the programs by a
measurable amount
3. A Transformation must be worth the effort.

9. What is the Next-Use information? N/D’2013


If the name in a register is no longer needed, then we remove the name from
the register and the register can be used to store some other names.
Input: Basic block B of three-address statements
Output: At each statement i: x= y op z, we attach to i the liveliness
and next-uses of x, y and z.
Method: We start at the last statement of B and scan backwards.
Page 2 of 9
1. Attach to statement i the information currently found
in the symbol table regarding the next-use and
liveliness of x, y and z.
2. In the symbol table, set x to “not live” and “no next use”.
3. In the symbol table, set y and z to “live”, and next-uses of y and z to i.

10. Define Loop unrolling with an example. N/D’2013


In region-based scheduling, the boundary of a loop iteration is a barrier to
code motion. Operations from one iteration cannot overlap with those from
another. One simple but highly effective technique to mitigate this problem is
to unroll the loop a small number of times before code scheduling. A for-loop
such as

..
can be written as in Fig . 10.16(a) . Similarly, a
repeat-loop such as repeat
S;
unt il C

11. Name the techniques in loop optimization. M/J’2014


Three techniques are important
for loop optimization: code
motion, which moves code
outside a loop;
Induction-variable elimination, which we apply to replace variables from
inner loop. Reduction in strength, which replaces and expensive
operation by a cheaper one, such as a multiplication by an addition.

12. How would you represent the dummy blocks with no statements indicated in
global data flow analysis. M/J’2014
 We say that the beginning points of the dummy blocks at the entry and exit of
a statement‟s region are the beginning and end points, respectively, of the
statement. The equations are inductive, or syntax-directed, definition of the
sets in[S], out[S], gen[S], and kill[S] for all statements S.
13. Draw DAG to represent a[i] =b[i]; a[i] = &t. N/D’2014

Page 3 of 9
14. What role does the target machine play on the code generation phase of the
compiler? A/ M
Familiarity with the target machine and its instruction set is a
prerequisite for designing a good code generator.
The target computer is a byte-addressable machine
with 4 bytes to a word. It has n general-purpose
registers, R0, R1, . . . , Rn-1.
It has two-address instructions of the form:
op source, destination

where, op is an op-code, and source and


destination are data fields. It has the following
op-codes :

MOV (move
source to
destination)
ADD (add
source to
destination)

SUB (subtract source from destination)

The source and destination of an instruction are specified by


combining registers and memory locations with address modes.

15. Generate code for the following C statement assuming three


registers are available: x=a/(b+c)-d*(e+f) A/ M’2015
Three address code:
t1= e+f
t2=b+c t3=a/t2

Page 4 of 9
t4=d*t1 t5=t3-
t4 x=t5

Assembly Code
(Target Code):
MOV e, R1

ADD f,R1
MOV b,R2
ADD c,R2

MOV a,R3 DIV


R3,R2 MUL d,R1
SUB R1,R2 MOV
R2,x

16. Write the algorithm that orders the DAG nodes for generating optimal target
code. A/ M’2015
The heuristic ordering algorithm attempts to make the evaluation of
a node immediately follow the evaluation of its leftmost argument.
The algorithm shown below produces the ordering in reverse.
Algorithm:
1. while unlisted interior nodes remain do begin
2. select an unlisted node n, all of whose parents have been listed;
3. list n;
4. while the leftmost child m of n has no unlisted parents and is not a
leaf
do begin
5. list m;
6. n:=m
e
n
d

e
n
d

17. Define Dead code elimination. N/D’2015


Page 5 of 9
A variable is live at a point in a program if its value can be used
subsequently; otherwise t values never get used. While the programmer is
unlikely to introduce any dead
code intentionally, it may appear as the result of previous
transformations. An optimization can be done by
eliminating dead code.
Example:
i=0;
if(i=1)
{
a=b+5;
}
Here, „if‟ statement is dead code because this condition will never get
satisfied.
18. What are the issues in the design of code
generator? N/D’2015
The following issues arise during the code generation
phase :
1. Input to code generator
2. Target program
3. Memory management
4. Instruction selection
5. Register allocation
6. Evaluation order
19. What are the global common sub expressions? N/D’2015
An occurrence of an expression E is called a common sub-expression if E
was previously computed, and the values of variables in E have not changed
since the previous computation. We can avoid recomputing the expression if
we can use the previously computed value.
For example
t1: =4*i t2: =a [t1]
t3: =4*j t4:=4*i t5: =n
t6: =b [t4] +t5
The above code can be optimized using the common sub-expression
elimination as t1: =4*i
t2: =a [t1] t3:
=4*j t5: =n
t6: =b [t1] +t5
The common sub expression t 4: =4*i is eliminated as its computation is
already in t1. And value of i is not been changed from definition to use.

20. What is DAG? M/J’2016


Page 6 of 9
 A DAG for a basic block is a directed acyclic graph with the
following labels on nodes: Leaves are labeled by unique identifiers,
either variable names or constants.
Interior nodes are labeled by an operator symbol.
Nodes are also optionally given a sequence of identifiers for labels to
store the computed values.
 DAGs are useful data structures for implementing transformations on basic
blocks.
 It gives a picture of how the value computed by a statement is used in
subsequent statements.
 It provides a good way of determining common sub - expressions.

PART B

1. Explain the principal sources of code optimization in detail


(Nov/Dec 2023/2021)
2. Discuss the DAG representation of the basic block with example
(Nov/Dec 2023)
3. How the data flow optimization can be done and compare the features

(Nov/Dec 2023)
4. Explain various issues in the design of code generator. (Nov/Dec 2021)
5. Write note on simple code generator. (Nov/Dec 2021)
6. Explain in detail about Global Data flow analysis of structural programs.
(16) (Nov/Dec 2016)
7. For the flow graph shown below, write the three address code and
construct the DAG. (8)
M/J’2013

t1 = 4*i (2) t2 = a[t1]

t3 = 4 *i (4) t4 = b[t2]

t5= t2 * t4

t6 = prod + t5
Page 7 of 9
prod = t6

t7 = i+1

i = t7

if i<=20 goto (1)

8. Write short notes on structure preserving transformation of basic blocks.


(8) NOV/DEC2013, N/D’2014, N/D’2015

9. Construct DAG and three address statement for the following C Program.
N/D’2013, N/D’2014
i=1; s=0;
while(i<=10)
{
s=s+a[i][i] i=i+1;
}
10. Define a directed acyclic graph. Construct a DAG and write the sequence
of instructions for the expression a+a*(b-c)+(b-c)*d. (16)MAY/JUNE 14

Page 8 of 9
11. Explain the steps carried out for generating code from DAGs with an example.
(8) N/D’2015
12. Discuss about the following:
 Copy Propagation ii) Dead-code Elimination and iii) Code
motion(6) NOV/DEC2012, MAY/JUNE 2012
13. Explain peephole optimization. (8) NOV/DEC2013 ,NOV/DEC2012,
MAY/JUNE 2012

STAFF INCHARGE HOD

Page 9 of 9

You might also like