Compiler Ch9
Compiler Ch9
Source
Intermediate Intermediate
program Front code Code code Code target
Symbol
table
Details depend on
– Target language
– Operating System
But following issues are inherent in all code
generation problems
– Memory management
– Instruction Selection
– Register allocation and
– Evaluation order
Input to the Code Generator
MOV b, R0
ADD c, R0
MOV R0,
MOV R0, aa If a is subsequently
used
MOV a,
MOV a, R0
R0
ADD e, R0
MOV R0, d
Instruction Selection (3)
t1 = a*a
t2 = a*b
This is a basic block
t3 = 2*t2
t4 = t1+t3
t5 = b*b
t 6 = t 4+ t5
Three address statement x = y + z is said to define x and to use y and z.
(1) prod = 0
(2) i = 1
B1
(3)
(3) tt11=4*I
=4*I
------------
------------
------------
------------
------------
------------
(11)
B2
(11) II =
= tt77
(12)
(12) If
If II <=
<= 20
20 goto
goto (3)
(3)
Transformation on Basic Block
a =b+c a =b+c
b=a–d b=a–d b is redefined
<
[] =
[]
* + 20
a b 4 i0 1
Exercise
x y
+ +
+ * - *
* * b b * * b b
a a * b a a * b
2 a 2 a
Answers
x y
+ +
+ * - *
* * b * * b b
a * a a * b
2 2 a
Answers
+ +
+ * -
* * b
a *
2
The End