0% found this document useful (0 votes)
14 views4 pages

Unit Vcode Optimization and Code Generation

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

Unit Vcode Optimization and Code Generation

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

UNIT V CODE OPTIMIZATION AND CODE GENERATION

Principal Sources of Optimization-DAG- Optimization of Basic Blocks-Global Data Flow


Analysis-Efficient Data Flow Algorithms-Issues in Design of a Code Generator - A Simple
Code Generator Algorithm.

PART-A

1. What are basic blocks? NOV/DEC 2011, APRIL/MAY 2005, APRIL/MAY


2010,APRIL/MAY 2008, NOV/DEC 2014 ,MAY/JUNE 2013, A RIL/MAY 2017
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.
2. What do you mean by copy propagation? APRIL/M Y 2017
After the assignment of one variable to another, a reference to one variable may be replaced
with the value of the other variable. If w := x appears in a block, all subsequent uses of w can
be replaced with uses of x.

Before After

b := z + y b := z + y

a := b a := b

x := 2 * a x := 2 * b

3. What is a flow graph? NOV/DEC 2011. MAY/JUNE 2012,NOV/DEC 2014


APRIL/MAY 2008, MAY/JUNE 2013

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.

4. Mention the applications of DAGs. (Or) List the advantages of DAG. NOV/DEC
2012 , MAY/JUNE 2013

We can automatically detect common sub expressions. →e 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.

5. Write the three address code sequence for the assignment statement. MAY/JUNE
2016

d:=(a-b)+(a-c)+(a-c) t1=a-b
t2=a-c t3=t1+t2 t4=t3+t2
d=t4
6. What is meant by peephole optimization? MAY/JUNE 2007

Peephole optimization is a technique used in many compliers, in connection with the


optimization of either intermediate or object code. It is really an attempt to overcome the
difficulties encountered in syntax directed generation of code.

7. What are the issues in the design of code generators? NOV/DEC 2007

Input to the code generator Target programs memory management Instruction selection
Register allocation Choice of evaluation order Approaches to code generation.

8. What is register descriptor and address descriptor? NOV/DEC 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.

9. Define DAG. NOV/DEC 2007, MAY/JUNE 2007

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. nterior nodes are labeled
by an operator symbol. Nodes are also optionally given a sequence of identifiers for labels.

10.Name the techniques in Loop optimization. MAY/JUNE 2014

Code Motion, Induction variable elimination, Reduction in strength

11.Draw DAG to represent a[i]=b[i]; a[i]=&t; NOV/DEC 2014


12.Represent the following in flow graph NOV/DEC 2014 i=1; sum=0;while (i<=10)
{sum+=i;i++;}
13.How to perform register assignment for outer loops? MAY/JUNE 2012
Outer loop L1 contains an inner loop L2 names allocated registers in L2 need not be
allocated registers in L1- L2
14.Define local optimization. APRIL/MAY 2011
The optimization performed within a block of code is called a local optimization.
15.Define constant folding. MAY/JUNE 2013
Deducing at compile time that the value of an expression is a constant and using the
constant instead is known as constant folding.

16.What is code motion? APRIL/MAY 2004, MAY/JUNE 2007, APRIL/MAY-2008


Code motion is an important modification that decreases the amount of code in a loop.
17.What are the properties of optimizing compilers? MAY/JUNE 2016, MAY/JUNE
2013,NOV/DEC 2007, NOV/DEC 2017
o Transformation must preserve the meaning of programs. Transformation must, on
the average, speed up the programs by a measurable amount
o A Transformation must be worth the effort.
o The source code should be such that it should produce minimum amount of target
code. There should not be any unreachable code.
o Dead code should be completely removed from source language.
18.What is meant by Dead Code? Or Define Live variable?APRIL/MAY
2011,NOV/DEC 2012
A variable is live at a point in a program if its value can be used subsequently otherwise, it is
dead at that point. The statement that computes values that never get used is known Dead code
or useless code. .
19.When is a flow graph reducible? APRIL/MAY 2012 MAY/JUNE 2012
A flow graph is reducible if and only if we can partition the edges into two disjoint groups
often called the forward edges and back edges.
20.What is a cross complier? NOV/DEC 2007, MAY/JUNE 2014
A cross compiler is a compiler capable of creating executable code for a platform other than
the one on which the compiler is run. (ie). A compiler may run on one machine and produce
target code for another machine.
21.What is global data flow analysis? NOV/DEC 2014
It is a process in which the values are computed using data flow properties. They are available
expressions, reaching definition, live variable and busy variable.
22.How would you represent the dummy blocks with no statements indicated in global
data flow analysis? MAY/JUNE 2014
23.What is the use of algebraic identities in optimization of basic blocks?MAY/JUNE
2012
The algebraic identities are used in Peephole optimization techniques. Simple transformations
can be applied on the code in order to optimize it for ex: 2*a optimized to a + a.
24.List the characteristics of peephole optimization.NOV/DEC 2016
o Redundant instruction elimination
o Flow of control optimization
o Algebraic simplification
o Use of machine idioms
25.Identify the constructs for optimization in basic blocks. NOV/DEC 2016
 It is a linear piece of code.
 Analyzing and optimizing is easier.
 Has local scope - and hence effect is limited.
 Substantial enough, not to ignore it.
 Can be seen as part of a larger (global) optimization problem.

PART-B
1. What are the issues in design of a code generator? Explain in detail. MAY/JUNE 2016,
NOV/DEC 2007, Nov/Dec 2011, April/May 2012 , MAY/JUNE 2007 ,APRIL/MAY
2005 APRIL/MAY 2008,MAY/JUNE 2012, NOV/DEC 2016, APRIL/MAY
2017,NOV/DEC 2017
2. Define basic block. Write an algorithm to partition a sequence of three-address
statements into basic blocks. MAY/JUNE 2012, APRIL/MAY 2011, AP IL/MAY 2012
3. Explain in the DAG representation of the basic block with example. APRIL/MAY
2012 APRIL/MAY 2005, AP IL/MAY 2008, MAY/JUNE 2012,MAY/JUNE
2015, APRIL/MAY 2017
4. How to generate a code for a basic block from its dag representation? Explain.
APRIL/MAY 2011, NOV/DEC 2011
5. Explain the structure-preserving transformations for basic blocks.NOV/DEC 2011
6. Explain the simple code generation algorithm in detail. APRIL/MAY 2012,
MAY/JUNE 201γ, MAY/JUNE 2016, APRIL/MAY 2008 April/May 2011, NOV/DEC
2011, NOV/DEC 2012,MAY/JUNE 2012,
7. For the statement given, write three address statements and construct DAG.
MAY/JUNE 201γ Consider expression a = b * – c + b * – c
8. Explain the principle sources of code optimization in detail. MAY/JUNE 2016,
NOV/DEC 2011, MAY/JUNE 2012 ,MAY/JUNE 2007, ,MAY/JUNE 2009
,APRIL/MAY 2008, APRIL/MAY 2005, NOV/DEC 2014, MAY/JUNE 201γ
MAY/JUNE 2012, NOV/DEC 2017
9. Write about Data Flow Analysis of structural programs. NOV/DEC 2011, APRIL/MAY
2012, MAY/JUNE 2014 MAY/JUNE 201γ, MAY/JUNE 2012
10.Write an algorithm to construct the natural loop of a back edge.APRIL/MAY 2011
11.Explain in detail about code-improving transformations. ( APRIL/MAY 2011
12.Discuss in detail about global data flow analysis. NOV/DEC 2016
13. Explain three techniques for loop optimization with examples. NOV/DEC 2012,
MAY/JUNE 201γ, MAY/JUNE
14.Write an algorithm for constructing natural loop of a back edge. NOV/DEC 2016

You might also like