Professional Documents
Culture Documents
Lecture 42
Lecture 42
Lecture 42
• Example 1: x=2 ....... y=x ....... z=x .......... x=x+1 ......... p=x
• For Example,
while (i <= limit-2) //limit is constant not changed and loop runs n times
t = limit-2
while (i <= t)
Apply code motion,
Strength Reduction
Loop Unrolling (for loop)
Loop Unrolling (for loop)
Home Exercise
• Apply loop unrolling to following construct,
• Our target computer models a three-address machine with load and store
operations, computation operations, jump operations, and conditional
jumps.
• Load operations: The instruction LD dst, addr loads the value in location
addr into location dst.
The Target Language...
• Store operations: The instruction ST x, r stores the value in register r into the
location x.
• The 3AC instruction if x < y goto L have equivalent machine code is,
• For each available register, a register descriptor keeps track of the variable
names whose current value is in that register. We assume that initially, all
register descriptors are empty. As the code generation progresses, each
register will hold the value of zero or more names.