Lecture_19 Code Generation
Lecture_19 Code Generation
Topics to be Covered
Code Generator
2. Target program
3. Memory management
4. Instruction selection
5. Register allocation
Design Issues in Code Generation
The following issues arise during the code generation phase:
The code generation phase just proceeds on an assumption that the input
is free from all syntactic and semantic errors, the necessary type checking
has taken place and the type-conversion operators have been inserted
wherever necessary.
Design Issues in Code Generation
Design Issues in Code Generation
3. Memory management:
Mapping the names in the source program to the addresses of data
objects is done by the front end and the code generator.
A name in the three address statements refers to the symbol table entry
for the name.
Then from the symbol table entry, a relative address can be determined
for the name.
•During Register allocation – we select only those set of variables that will
reside in the registers at each point in the program.
•Evaluation order – The code generator decides the order in which the
instruction will be executed. The order of computations affects the efficiency
of the target code.
Note: Among many computational orders, some will require only fewer
registers to hold the intermediate results. However, picking the best order in
the general case is a difficult NP-complete problem.
Basic Block
Basic Block
Example Of Not A Basic Block-
Three Address Code for the expression If A<B then 1 else 0 is-
Here, the statements do not execute in a sequence one after the other.
Thus, they do not form a basic block.
Rules for creating Basic Block
Any given code can be partitioned into basic blocks using the following rules-