Code Optimization Questions For Discussion
Code Optimization Questions For Discussion
Optimization
the following C code segmer
Conside
i ++)
0:1<n;
for (i=
x t (4 *j+5 * i);
y+ (7 +4 *j); (a)
4
3
[2006:2 Marks]
42 Some code optimizations are
carried out on the (
intermediate code because
a) They enhance the portability of the
to other complier
target processors
(6) Program analysis is more
accurate on
intermediate code than on machine code
) The information from data
cannot otherwise be used for
flow analysis
4.5
2011:2 Marks]
d) The information from the optimization
Consider the program
given below, in a
otherwise be used for
front end cannot structured pseudo-language with lexical block-
optimization and nesting of
procedures permitted. scoping
2008:1Mark] Program main;
A3 Which languages necessarily need Var..
allocation heap Procedure Al;
in the runtime
(a) Those that environment! Var
support
6) Those that use recursion Call A2;
) Those that allow
dynamic scoping End A1
a) Those that use dynamic data structure Procedure A2;
global variables Var.
Procedure A21;
44 Consider [2010:1Mark]
Var...
two binary operators T and with Call A1,
ne precedence of operator being lower than End A21
hat of the
operator 1. Operator T is right Call A21;
SsOCiative while operator is left associative. End A2
Which one of the Call A1;
ree for
following represents the parse
End main,
expression (731413'2)
524
GATE Previous Years
Solved Papers:
d=d* d;
SMADE
Consider the calling chain:
e =e* e
Main A1->A2-> A21 > A1
activation records along
with
The correet set of
their access links is given by 4.6 Suppose the instruction set
(a)
Mnin processor has only two registers architecture of
complier optimization is codeThemo only th
Al
moves statements from one allowod
A2
place to anoth hich
preserving correctness. What is # hil
A21 number of spills to memory in the
a) 0
cnmniled code?
1 1
FRAME
ACCESS
LINKS
(2 3
POINTER
(b) Main
FRAME
Al
[2013:2 Marks
POINTER A2 4.8 Which one of the following is FALSE?
(a) A basic block is a sequence of instructions
A21 ACCESS where control enters the sequence at the
LINKS
beginning and exits at the end.
Main (b) Available expression analysis can be usedfor
common subexpression elimination.
(c) Live variable analysis can be used for dead
code elimination.
A21
(d)x = 4x5 » 20 is an example of common
Al subexpression elimination.
FRAME ACCE SS
POINTER LINKS [2014 (Set-1):1Mark
[2012:2Marks]
4.9 Which one of the following is NOT performed
4.6 and 4.7
Common Data for Questions during compilation?
code segment is executed on a processor allocation
The following (a) Dynamic memory
in its instructions.
which allows only register operands b) Type checking
almost two source operands
Each instruction can have (c) Symbol table management
one destinations operand.
Assume that all
and (d) Inline expansion
variables are dead after this code segment. [2014 (Set-2):1Mark
c=a+b; ne
d=e * a 410 For a C accessing X[]5||k),
program
by a
code is generated
ecta folowing intermediate integer 13
x=c * c;
compiler. Assume that
the size of an
of a character
is 8 bits.
if(x> a){ 32 bits and the size
1,3=11 + to
14=13 + t12
The variables which are live both at the statement
in basic block 2 and at the statement in basic
h=X}t4)
of the following statements about the block 3 of the above control flow graph are
whede for the C program is CORRECT (a) p, s,u (b) r, s,u
declared as "int X[32]|32][8". (c)r,u (d) q, v
"nt X|4][1024]|[32.
Nis declared as
[2015 (Set-1): 2 Marks]
Xis declared as "char X[4][32][8r.
"char 4.14 The least number of
(d) Xis
declared a s X[32][16][2 temporary variables required
[2014 (Set-2): 2 Marks]
tO Create a three-address code in static single
aL.ioh of the following statements are CORRECT? assignment form for the expressionqtr/3+s-t
*
l l Whiet
MADE EAS
4.17 Consider the following code segment: 4.20 Consider the expression (a-1
Let X be the
equired by an nimum
optimal codenumber ot
any register spill) generat on r(vithot
egistora
architecture, in which
dh
algorithm for: a
EI- z;
)only load loadls
instructions have memory
can
and
The minimum number of total variables required arithmetic instructions haveoperands
can
atore
and fi
to convert the above code segment to static single
or immediate operands. The ont
val"sta
assignment form is Xs
2016 (Set-1):1 Mark] 2017 (Set-1):2 Markal
4.21 Consider the following
4.18 A student wrote two context-free grammars G1 grammar
and G2 for generating a single C-like array stmt if expr then expr
else expr,
declaration. The dimension of the array is at least expr term relop
term |term stmt o
term> id|number
one. For example.
id > alb|le
int a [10] [3];
number [0-9]
The grammars use D as the start symbol, and
where relop is a relational
use six terminal symbols int; id [] num. operator (e.g s.
..., 0 refers to the empty
Grammar G1 Grammar G2
then, else are terminals.
statement, and
And
D int L; D int L
L idE
Consider a
program P following the aboe
L i d [E
grammar containing ten if terminals.
E num] E E [num] number of control flow paths in Pis he
E> num] [E E [num For example, the program
Which of the grammars correctly generate the if e, then e, else e
declaration mentioned above?
has 2 control flow paths, e -e and
(a) Both G1 and G2 () Only G1 e e
() Only G2 d) Neither G1 nor G2 [2017 (Set-1):2 Marks
[2016 (Set-2):2 Marks]l 4.22 Consider the following C code segment:
4 P *c 44 P3 *c the followng
4.23 Inthe context of compilers, which of
P u *v P u is/are NOTan intermediate representationoue
91 Pt9 95Pt 94 source program?
( P a -b (d)P, a - b (a) Symbol table
41 Pa *c 9p *c (b) Three address code
P3u * v 9 2 u *U ()Control Flow Graph (CFG)
92P4t 93 d) Abstract Syntax Tree (AST) Mark)
:1
[2017 (Set-1):1 Mark] [2021 (Set-2)
puoE
EASY /
| Compile Design 527
tatement in
program, in the context
a
tiveness analysis, thefollowing sets are defined: 4.25 Consider the following ANSI C code segment:
b) OUTYS)=IN(S,) u OUT(S,)
OUTS)=IN(S,) Assume that the variable ypoints to a struct
OUTS) =IN(S)UUSE(S,) (allocated on the heap) containing two fields f1
and f2, and the local variables x,
[2021 (Set-2) :2 y, z, p, q, andi
Marks] are allotted registers. Common sub-expression
elimination (CSE) optimization is applied on the
code. The number of addition and
dereference
operations (of the form y >f1 or y > f2) in the
optimized code, respectively, are
a) 303 and 2 (6 403 and 102
203 and2 (d) 308 and 102
[2021 (Set-2) :2 Marks]