Code Optimization - Expert Talk
Code Optimization - Expert Talk
3. Language Processing
6. Reaching Definitions
7. Register Allocation
An optimization is a transformation that is expected
to improve program in some way.
• Opportunity
• Profitability
• Overhead
Scope of Code Optimization :
Code Optimization Examples:
Common Subexpression Elimination:
Common Subexpression Elimination:
t :=d + e
a := t b := t
c := t
Loop level Optimizations:
Loop level Optimizations:
DATA FLOW ANALYSIS
EXAMPLE CALCULATION (ITERATION -1)
EXAMPLE CALCULATION (ITERATION -1)
EXAMPLE CALCULATION (ITERATION -1)
b=a+2
c=b*b
b=c+1
return b * a
Register Allocation :Interference graph
b=a+2
c=b*b
b=c+1
b,a
return b * a
Register Allocation :Interference graph
b=a+2
c=b*b
a,c
b=c+1
b,a
return b * a
Register Allocation :Interference graph
b=a+2
b,a
c=b*b
a,c
b=c+1
b,a
return b * a
Register Allocation :Interference graph
eax
ebx
stack:
b c
d e
Coloring a graph
color register
eax
ebx
stack:
b c
c
d e
Coloring a graph
color register
eax
ebx
stack:
b c
e
c
d e
Coloring a graph
color register
eax
ebx
stack:
b c
a
e
c
d e
Coloring a graph
color register
eax
ebx
stack:
b
b c
a
e
c
d e
Coloring a graph
color register
eax
ebx
stack:
d
b c
b
a
e
c
d e
Coloring a graph
color register
eax
ebx
stack:
b c
b
a
e
c
d e
Coloring a graph
color register
eax
ebx
stack:
b c
a
e
c
d e
Coloring a graph
color register
eax
ebx
stack:
b c
e
c
d e
Coloring a graph
color register
eax
ebx
stack:
b c
c
d e
Coloring a graph
color register
eax
ebx
stack:
b c
d e
Final Thought: