Title: A Framework for Unrestricted Whole-Program Optimization
1A Framework for UnrestrictedWhole-Program
Optimization
- Spyridon Triantafyllis, Matthew J. Bridges,
Easwaran Raman, Guilherme Ottoni, David I. August - The Liberty Research Group
- Department of Computer Science
- Princeton University
2Procedure-Based Compilation
- Procedure-Based Compilation
- Pros
- Well Known
- Cons
- Can not exploit opportunities that cross
procedures
g()
h()
f(a,b,c)
if (EOB)
zxy f(x,y,5)
f(1,2,3)
fill B
dab
z
ret
3Interprocedural Analysis
- Interprocedural Analysis
- Sharir78 Morel78 Reps95
- Pros
- Increases available information
- Enables some optimization across procedure
boundaries - Cons
- Has to analyze the entire program
- Optimizations need to respect the procedure
boundary
g()
h()
f(a,b,c)
if (EOB)
zxy f(x,y,5)
f(1,2,3)
fill B
dab
z
ret
4Interprocedural Analysis Interprocedural Opti
- Interprocedural Analysis
- Sharir78 Morel78 Reps95
- Pros
- Increases available information
- Enables some optimization across procedure
boundaries - Cons
- Has to analyze the entire program
- Optimizations need to respect the procedure
boundary - Most optimizations will still be intraprocedural
g()
h()
f(a,b,c,z)
if (EOB)
zxy f(x,y,5,z)
f(1,2,3,2)
fill B
dz
z
ret
5Inlining
- Inlining
- Scheifler 77 Hwu89 Chang92
- Pros
- Increases optimization scope
- Enables specialization
- Doesnt require opti to understand
interprocedural concerns - Cons
- Hard limit on procedure size
- Unnecessary code growth
g()
zxy
if (EOB)
fill B
f(a,b,c)
if (EOB)
dz
fill B
h()
dab
jump
f(1,2,3)
z
ret
6Partial Inlining
- Partial Inlining
- Suganuma03Way00
- Pros
- Can alleviate some code growth
- Cons
- Gains are limited
g()
zxy
f()
fill B
if (EOB)
f()
return
f(a,b,c)
if (EOB)
dz
h()
fill B
dab
jump
f(1,2,3)
ret
z
7Why Procedures?
- Procedures
- Calling convention boundary
- Single-Entry, Single-Exit
- Pros
- Implicit correlated edges - context sensitivity
- Natural unit for divide conquer compilation
- Cons
- Optimized for software-engineering
- Restricts optimization
if (EOB)
zxy
fill B
dab
dz
z
ret
We dont have to use procedures!
8The Whole-Program CFG
- Retain useful traits of procedures
- Correlated edges
- Compilation unit
- Goal Obtain an optimizable whole-program
representation - Increase optimization scope
- Allow all opti to operate on increased scope
without change - Targeted code growth
if (EOB)
zxy
fill B
dab
z
jump
9The Whole-Program CFG
- Retain useful traits of procedures
- Correlated edges
- Compilation unit
- Goal Obtain an optimizable whole-program
representation - Increase optimization scope
- Allow all opti to operate on increased scope
without change - Targeted code growth
Represent calls and returns as special
control-flow transitions Sharir78
10Whole-Program Optimizations
- Optimization destroys the programs procedural
structure! - Example Superblock Formation Hwu92
- Unconventional call structures!
- Many-to-many call lt-gt return relation
- Must rediscover structure for summary edges
A
(1
B
B
(2
G
D
C
C
H
)2
E
E
)1
)1
F
F
11Analyzing the Whole-Program CFG
- Context-Sensitive
- Interprocedural AnalysisSharir78
- meet over all realizable paths
- Identify Entry-Exit Pairs (EEP)
- Correlated call return arcs
- Allows use of summary edges
- Blocks may belong to more than one EEP
A
(1
B
B
(2
G
D
C
C
H
)2
E
E
)1
)1
F
F
12Determining a Compilation Unit Region Formation
- Region Formation Hank95
- arbitrarily shaped, compiler-selected compilation
unit
A
(1
B
- Region Selection
- Select seed add neighbors
- (profile, structure, dataflow )
B
(2
G
D
- Success Criteria
- Optimizability vs. compile time
- Few too small or too big regions
- Intra-region transitions inter-region
transitions - Encapsulation
- Make regions independently optimizable
C
C
H
)2
E
E
)1
)1
F
F
Compiler is free to select its own optimization
units!
13Evaluation Framework The Velocity Compiler
Frontend
Frontend
Frontend
- Evaluation
- Inliner Opti. ported from IMPACT
- Targeting Itanium 2
Procedures
Procedures
Procedures
Inlining
WCFG
DetermineCompilation Unit
Region Form.
Regions
Procedures
Superblock
Superblock
Superblock
Classical ILP Optimizer
Classical ILP Optimizer
Classical ILP Optimizer
Optimize Compilation Unit
Scheduling
Scheduling
Scheduling
Executable
Executable
Executable
Baseline
Inlining
PBE
14Code Growth
1.45
1.23
Code Size
15Speedup - Train Input
1.07
16Conclusion
- Procedure boundaries restrict optimization!
- Ways to deal with procedures exist, but limited
- Interprocedural analysis opti Scales badly,
not always possible - Inlining Unnecessary Code growth
- Procedures are not the right compilation unit
- PBE offers unrestricted and practical
whole-program optimization - An expanded form of interprocedural analysis
- New region formation framework and heuristics
- An interprocedural region encapsulation method