Top Banner
Presented by, M.Selva Vinitha B.E/CSE M.Kumarasamy college of engineering Karur.
19
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Issues in design_of_code_generator

Presented by,

M.Selva Vinitha

B.E/CSE

M.Kumarasamy college of engineering

Karur.

Page 2: Issues in design_of_code_generator

Code generator

Final phase of compiler design

Optimized intermediate code is provided as input

It generates target code

2/27/2015 2Issues in design of code generator

Page 3: Issues in design_of_code_generator

Code generation and Instruction Selection

4

Symboltable

input output

Frontend

IntermediateCode

generatorCode

generator

2/27/2015 Issues in design of code generator

Page 4: Issues in design_of_code_generator

Contd…

output code must be correct

output code must be of high quality

code generator should run efficiently

2/27/2015 4Issues in design of code generator

Page 5: Issues in design_of_code_generator

Pre-requisites Instruction set of target machine.

Instruction addressing modes.

No. of registers.

Configuration of ALU

2/27/2015 5Issues in design of code generator

Page 6: Issues in design_of_code_generator

Issues in the design of a code

generator

Input to the code generator

Memory management

Target programs

Instruction selection

Register allocation

Evaluation order

Approaches to code generation

2/27/2015 6Issues in design of code generator

Page 7: Issues in design_of_code_generator

Input to the code generator The intermediate representation of the source program

produced by the front end

Several choices for the intermediate language

Linear - postfix nottion

3 address - quadruples

Virtual machie - stack machine code

Graphical - syntax tree &dags

2/27/2015 7Issues in design of code generator

Page 8: Issues in design_of_code_generator

Memory management

Mapping names in the source program to addresses of data

objects in run-time memory

Done by the front end and the code generator.

A name in a three- address statement refers to a symbol-

table entry for the name.

A relative address can be determined

2/27/2015 8Issues in design of code generator

Page 9: Issues in design_of_code_generator

Target programs

Absolute machine language

Relocatable machine language

Assembly language

2/27/2015 9Issues in design of code generator

Page 10: Issues in design_of_code_generator

Contd..

Absolute machine language:

Produce an absolute machine language program

can be placed in a fixed location in memory and

immediately executed.

2/27/2015 10Issues in design of code generator

Page 11: Issues in design_of_code_generator

Contd..Relocatable machine language:

Producing a relocatable machine language program

subprograms to be compiled separately.

relocatable object modules can be linked together and loaded for execution by a linking loader.

must provide explicit relocation information to the loader, to link the separately compiled program segments.

2/27/2015 11Issues in design of code generator

Page 12: Issues in design_of_code_generator

Contd…Assembly language:

Producing an assembly language program

makes the process of code generation easier

2/27/2015 12Issues in design of code generator

Page 13: Issues in design_of_code_generator

Instruction selection

The factors to be considered during instruction selection are:

The uniformity and completeness of the instruction set.

Instruction speed and machine idioms.

Size of the instruction set.

2/27/2015 13Issues in design of code generator

Page 14: Issues in design_of_code_generator

Contd…Eg., for the following address code is:

a := b + cd := a + e

inefficient assembly code is:

MOV b, R0 R0 ← b

ADD c, R0 R0 ← c + R0

MOV R0, a a ← R0

MOV a, R0 R0 ← a

ADD e, R0 R0 ← e + R0

MOV R0 , d d ← R0

Here the fourth statement is redundant, and so is the third statement if ,

'a' is not subsequently used.

2/27/2015 14Issues in design of code generator

Page 15: Issues in design_of_code_generator

Register allocation

• Instructions with register operands are usually shorter and

faster

• Efficient utilization of registers is important in

generating good code.

2/27/2015 15Issues in design of code generator

Page 16: Issues in design_of_code_generator

Contd..Register allocation phase:

• Select the set of variables that will reside in registers

Register assignment phase:

• Pick the specific register that a variable will reside in.

2/27/2015 16Issues in design of code generator

Page 17: Issues in design_of_code_generator

Evaluation order The order in which computations are performed

Affect the efficiency of the target code.

Some computation orders require fewer registers to hold

intermediate results

2/27/2015 17Issues in design of code generator

Page 18: Issues in design_of_code_generator

Approaches to code generation Most important criteria for code generator is that it

produces correct code

Correctness takes on special signification

It contains a straightforward code generation algorithm

The output of such code generator can be improved by

peephole optimization technique

2/27/2015 18Issues in design of code generator

Page 19: Issues in design_of_code_generator

Conclusion

Output of code generator phase is dependent on:

Target language

Operating system

Memory management system

Instruction selection

Register allocation

Evaluation order

2/27/2015 19Issues in design of code generator