Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
49 views
6 pages
CD Unit 5 QB Answers
Uploaded by
Akhil Vinnakota
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download
Save
Save cd unit 5 qb answers For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
0 ratings
0% found this document useful (0 votes)
49 views
6 pages
CD Unit 5 QB Answers
Uploaded by
Akhil Vinnakota
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Carousel Previous
Carousel Next
Download
Save
Save cd unit 5 qb answers For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
Download
Save cd unit 5 qb answers For Later
You are on page 1
/ 6
Search
Fullscreen
Unit-V Q.No. LONG ANSWERS QUESTION hoc ‘a, | Explain about the Position of machine dependent code 5 "| optimizer? 1 ‘What are the issues considered at the time of code 5 B. | optimization? Explain them. ‘a, | Explain about the register allocation and assignment with 5 an example. 2 Discuss the difference between machine dependent and ¥ B. | machine independent code optimization. A. | Write about basic block with an example. 5 3 Discuss about control flow graph with an example. 5 A. | Explain about the Position of code generator? 5 4 Which issues are considered at the time of code ji B. | generation? Explain them. Write a Three address code for the following control ‘statements: a. |} Simple it 5 ~ ii) Ifelse iii) While 5 Apply the Structure-Preserving Transformations (or) Peephole optimization (or) Principle sources of optimization for the following C code. B. | fori from 1 to 10 do 5 for j from 1 to 10 do ali, j] = 0.0; for i from 1 to 10 do afi, ] = 1.0;Machine dependant optimizations: Machine dependant optimizations are based on register allocation and utilization of special machine-instruction sequences. The criteria for code improvement transformations: 1. Simply stated, the best program transformations are those that yield the most benefit for the least effort. 2. The transformation must preserve the meaning of programs. That is, the optimization must not change the output produced by a program for a given input, or cause an error such as division by zero, that was not present in the original source program. At all times we take the “safe” approach of missing an opportunity to apply a transformation rather than risk changing what the program does. 3. A transformation must, on the average, speed up programs by a measurable amount. We are also interested in reducing the size of the compiled code although the size of the code has less importance than it once had. Not every transformation succeeds in improving every program, occasionally an “optimization” may slow down a program slightly. 4, The transformation must be worth the effort. It does not make sense for a compiler writer to expend the intellectual effort to implement a code improving transformation and to have the ‘compiler expend the additional time compiling source programs if this effort is not repaid when the target programs are executed. “Peephole” transformations of this kind are simple enough and beneficial enough to be included in any compiler. target Program Fig: Position of code optimizer An Organization for an Optimizing Compiler: 1. Flow analysis is a fundamental prerequisite for many important types of code improvement. 2. Generally control flow analysis precedes data flow analysis. Blog: anilkumarprathipati. wordpress.com 1 UNIT-V cD 3. Control flow analysis (CFA) represents flow of control usually in form of graphs, CFA constructs such as a. control flow graph b. Call graph 4, Data flow analysis (DFA) is the process of ascerting and collecting information prior to program execution about the possible modification, preservation, and use of certain entities (such as values or attributes of variables) in a computer program.2. CODE GENERATION ISSUES Code Generation Issues: ‘A code generator is expected to have an understanding of the target machine’s runtime environment and its instruction set. The code generator should take the following things (issues) into consideration to generate the code: ‘+ Target language: The code generator has to be aware of the nature of the target language for which the eode is to be transformed. That language may facilitate some machine-specific structions to help the compiler generate the code in a more convenient way. The target ‘machine can have either CISC or RISC processor architecture. ‘+ IR Type: Intermediate representation has various forms. It can be in Abstract Syntax Tree (AST) structure, Reverse Polish Notation, or 3-address code. ‘+ Selection of instruction: The code generator takes Intermediate Representation as input and ‘converts (maps) it into target machine’s instruction set. One representation can have many ways (instructions) to convert it, so it becomes the responsibility of the code generator to ‘choose the appropriate instructions wisely. ‘+ Register allocation: A program has a number of values to be maintained during the execution. The target machine’s architecture may not allow all of the values to be kept in the CPU memory or registers. Code generator decides what values to keep in the registers. Also, it decides the registers to be used to keep these values. + Ordering of instructions: At last, the code generator decides the order in which the instruction will be executed. It creates schedules for instructions to execute them. ‘The code generator has to track both the registers (for availability) and addresses (location of values) while generating the code. For both of them, the following two descriptors are used: «Register descriptor: Register descriptor is used to inform the code generator about the availability of registers. Register descriptor keeps track of values stored in each register. ‘Whenever a new register is required during code generation, this descriptor is consulted for register availability a Serer vile a a tli) yA dpa in bl at different locations while in execution. Address descriptors are used to keep track of ‘memory locations where the values of identifiers are stored. These locations may include CPU registers, heaps, stacks, memory or a combination of the mentioned locations. Code generator keeps both the descriptor updated in real-time, For a load statement, LD RI, x, the code generator: + Updates the Register Descriptor RI that has value of x and + Updates the Address Descriptor (x) to show that one instance of x is in RI. Example: dad := {a-b) + (a-c) + (a-c) Blog: anilkumarprathipati wordpress.com 2 UNIT-V cp Reaisre Generate | Desceirror registers empty RO contains t STATEMENTS tin RO RO contains & 1 contains ‘tin Ro win RY ge 598 88 Fig Register and Address descriptorWhat is the Difference Between Machine Dependent and Machine Independent Code Optimization? Machine dependent code optimization is applied to object code, applied to the intermediate code. ‘Machine dependent optimization ‘Machine independent code optimization does involves CPU registers and absolute, ‘not involve CPU registers or absolute memory references. memory references. Summary - Machine Dependent vs Machine Independent Code Optimization ‘Code optimization consists of two optimization techniques namely, machine dependent and machine independent code optimization. The difference between machine dependent and machine independent code optimization is, in machine dependent optimization it is applied to object code whereas, in machine independent code, the optimization is applied to intermediate code,Basic Block: Source codes generally have a number of instructions, which are always executed in sequence and are considered as the basic blocks of the code. These basic blocks do not have any jump statements among them, i.e., when the first instruction is executed, all the instructions in the same basic block will be executed in their sequence of appearance without losing the flow control of the program. ‘A program can have various constructs as basic blocks, like IF-THEN-ELSE, SWITCH- CASE conditional statements and loops such as DO- WHILE, FOR, and REPEAT-UNTIL, ete. Basic block identification ‘We may use the following algorithm to find the basic blocks in a program: ‘© Search header statements of all the basic blocks from where a basic block starts: ‘©. First statement of a program. (© Statements that are target of any branch (conditional/unconditional). © Statements that follow any branch statement. ‘© Header statements and the statements following them form a basic block. ‘A basic block does not include any header statement of any other basic block, Basic blocks are important concepts from both code generation and optimization point of view. Example Biog: anilkumarprathipati.wordpress.com 7 AE( => 2) ly =x) xt wext zy Source Code Canteal Flow Crank:Control Flow Graph: Basic blocks in a program can be represented by means of control flow graphs. A control flow graph depicts how the program control is being passed among the blocks. It is a useful tool that helps in optimization by help locating any unwanted loops in the program. Example: Bt ENTER: fame | y= 0; eee ra Be ~f eae ae Le 63 \ i iy a Ba | La tT B4 eee oF Basic Blocks Flow Graph ‘There are two types of basic block optimizations. They are: i, Structure-Preserving Transformations. ii, Algebraic Transformations i) Structure-Preserving Transformations (or) Principle Sources of optimization (or) Peephole optimization: The primary Structure-Preserving Transformation on basic blocks are: ‘a. Common sub-expression elimination . Copy propagation. ¢. Dead-code elimination. 4. Constant folding. €. Code motion. f. Induction-variable elimination. Ete. Blog: anilkumarprathipati.wordpress.com 8 unr ii) Algebraic Transformation Algebraic identities represent another important class of optimizations on basic blocks. This includes simplifying expressions or replacing expensive operation by cheaper ones i. reduction in strength, Another class of related optimizations is constant folding, Here we evaluate constant expressions at compile time and replace the constant expressions by their values. Thus the expression 2°3.14 would be replaced by 6.28. ‘The relational operators <=, >=, <, >, + and = sometimes generate unexpected common sub expressions. ‘Associative laws may also be applied to expose common sub expressions. Ifthe given example code is ‘void quicksort (m,n) int m,n; cp int js int vax; if (n<=m) return; /* fragment begins here */ fem 1; jams v=aln]; while(1) { do i=i+1; while ( afi]
v): Lil=x3 (In|; afn|=x; —/* fragment ends here */ quicksort (m,i); quicksort (i+1,n); x=alil; alil=aljl
You might also like
Ar20 Aus CD Unit V
PDF
No ratings yet
Ar20 Aus CD Unit V
17 pages
Chapter 6 Code Optimization and Code Generation Compress PDF
PDF
No ratings yet
Chapter 6 Code Optimization and Code Generation Compress PDF
45 pages
Compiler Design Code Generation
PDF
No ratings yet
Compiler Design Code Generation
4 pages
Acd 5
PDF
No ratings yet
Acd 5
9 pages
Chapter 8 Code Optimization and Code Generation
PDF
No ratings yet
Chapter 8 Code Optimization and Code Generation
58 pages
Codeoptimization-Module 4B
PDF
No ratings yet
Codeoptimization-Module 4B
66 pages
Compiler Design Lec-8Code Generation and Optimization
PDF
No ratings yet
Compiler Design Lec-8Code Generation and Optimization
46 pages
Unit 4
PDF
No ratings yet
Unit 4
4 pages
Chapter 7 Code Optimization and Code Generation
PDF
No ratings yet
Chapter 7 Code Optimization and Code Generation
7 pages
Code Optimization and Target Code Generation
PDF
No ratings yet
Code Optimization and Target Code Generation
24 pages
Unit 4
PDF
No ratings yet
Unit 4
19 pages
@@code Optim
PDF
No ratings yet
@@code Optim
20 pages
CD Unit - 5 Solutions
PDF
No ratings yet
CD Unit - 5 Solutions
26 pages
Compi Desi CHP 06&7
PDF
No ratings yet
Compi Desi CHP 06&7
25 pages
Unit V
PDF
No ratings yet
Unit V
21 pages
Code Generation and Optimization
PDF
No ratings yet
Code Generation and Optimization
42 pages
Code Generation and Code Optimization Eng 16
PDF
No ratings yet
Code Generation and Code Optimization Eng 16
11 pages
CC5
PDF
No ratings yet
CC5
5 pages
Unit 5 1 Basicblocks
PDF
No ratings yet
Unit 5 1 Basicblocks
39 pages
3 CO and CG
PDF
No ratings yet
3 CO and CG
11 pages
Acd-Unit 5
PDF
No ratings yet
Acd-Unit 5
50 pages
Unit 5 Cd.
PDF
No ratings yet
Unit 5 Cd.
27 pages
Chapter 6 Code Generation and Optimization
PDF
No ratings yet
Chapter 6 Code Generation and Optimization
34 pages
Code Optimization PDF
PDF
No ratings yet
Code Optimization PDF
25 pages
Code Generation: Issues in The Design of A Code Generator
PDF
No ratings yet
Code Generation: Issues in The Design of A Code Generator
33 pages
Compiler Design - Code Optimization
PDF
No ratings yet
Compiler Design - Code Optimization
6 pages
Lecture 8 - Code Generation
PDF
No ratings yet
Lecture 8 - Code Generation
19 pages
Optimization of Basic Blocks
PDF
No ratings yet
Optimization of Basic Blocks
13 pages
Sri Vidya College of Engineering and Technology Question Bank
PDF
No ratings yet
Sri Vidya College of Engineering and Technology Question Bank
5 pages
Pcs - 2m
PDF
No ratings yet
Pcs - 2m
6 pages
CD - CH6 - Introduction To Code Optimization
PDF
No ratings yet
CD - CH6 - Introduction To Code Optimization
19 pages
Unit Viii
PDF
No ratings yet
Unit Viii
16 pages
Experiment No 6 - DONE
PDF
No ratings yet
Experiment No 6 - DONE
8 pages
Compiler Design (Unit-5)
PDF
No ratings yet
Compiler Design (Unit-5)
22 pages
CD+-+CH 8
PDF
No ratings yet
CD+-+CH 8
17 pages
Chapter 10 - Code Generation
PDF
No ratings yet
Chapter 10 - Code Generation
31 pages
CD Uint5
PDF
No ratings yet
CD Uint5
16 pages
CD Unit 6
PDF
No ratings yet
CD Unit 6
27 pages
UNIT 4 - Chapter 1 in Compiler Design
PDF
No ratings yet
UNIT 4 - Chapter 1 in Compiler Design
51 pages
Code Generation
PDF
No ratings yet
Code Generation
43 pages
Code Generation and Instruction Selection Unit-8
PDF
No ratings yet
Code Generation and Instruction Selection Unit-8
6 pages
Issues in The Design of A Code Generator
PDF
No ratings yet
Issues in The Design of A Code Generator
4 pages
Automata Theory and Compiler Design-1
PDF
No ratings yet
Automata Theory and Compiler Design-1
38 pages
Code Generation I: Compiler Construction
PDF
No ratings yet
Code Generation I: Compiler Construction
28 pages
Unit 6
PDF
No ratings yet
Unit 6
80 pages
Ch8a Myppt
PDF
No ratings yet
Ch8a Myppt
42 pages
UNIT V CD Print
PDF
No ratings yet
UNIT V CD Print
9 pages
Darshan Sem7 170701 CD 2014
PDF
No ratings yet
Darshan Sem7 170701 CD 2014
81 pages
Unit V
PDF
No ratings yet
Unit V
11 pages
Atcd - Unit 5
PDF
No ratings yet
Atcd - Unit 5
10 pages
Unit V
PDF
No ratings yet
Unit V
42 pages
Ia3 1
PDF
No ratings yet
Ia3 1
11 pages
Code Generation (Autosaved)
PDF
No ratings yet
Code Generation (Autosaved)
48 pages
TSR Class Cd-Unit 5
PDF
No ratings yet
TSR Class Cd-Unit 5
153 pages
Code Optimization
PDF
No ratings yet
Code Optimization
15 pages
Unit 4
PDF
No ratings yet
Unit 4
16 pages
Unit VI Code Generation
PDF
No ratings yet
Unit VI Code Generation
29 pages
CH5 2
PDF
No ratings yet
CH5 2
24 pages
CH06
PDF
No ratings yet
CH06
28 pages