Unit Vcode Optimization and Code Generation
Unit Vcode Optimization and Code Generation
PART-A
Before After
b := z + y b := z + y
a := b a := b
x := 2 * a x := 2 * b
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
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.
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.
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.
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