Title: Adaptive Inlining
1Adaptive Inlining Keith D. Cooper and Todd
Waterman
Procedure Inlining
Adaptive Inlining
int f() int a g(1) return a int g(x)
if (x 0) return 0 else return
x1
Definition The process of replacing a call site
with a copy of the procedure body
We built a source-level inliner that exposes
inlining decisions at the command line.
Inline
int f() int a if (1 0) a 0
else a 1 1 return a int g(x)
if (x 0) return 0 else return x1
Example Inline all procedures in foo.c less than
25 statements or less than 100 statements and
within a loop
- Advantages
- Eliminate call overhead
- Facilitate other optimizations
inliner -C sclt25 lndgt0, sclt100 foo.c
Conditions are combined in conjunctive normal
form for expressability
Call-site properties are compared against
constants to form conditions
- Disadvantages
- Code growth
- Longer compile times
Optimize
We use the inliner in an adaptive system to find
good solutions for a specific program.
The Hard Part How do we select a set of
procedure calls that maximizes the advantages and
minimizes the disadvantages?
int f() return 2
- We carefully craft the search space for efficient
exploration - Set a basic form for the condition string
- sc lt A sc lt B, lnd gt 0 sc lt C, scc 1
clc lt D cpc gt E, sc lt F dcc gt G - Fix the granularity of parameters to keep the
search manageable - Further limit potential starting points to limit
excessive inlining -
Approaches to Inlining
- We explore the search space using a randomized
hill climber - Capable of quickly exploring the search space
- Restarts allow exploration of various areas
- Limited patience can allow more descents in
limited time
- There has been a great deal of research on
deciding which procedures to inline over the
years. - Static heuristics have traditionally been used
- Call sites are inlined if they meet a certain
condition - The same condition is used for all programs
- Heuristics are conservative to prevent bad
results from excessive inlining - Results have varied greatly between
architectures, languages, and
input programs - There is no consensus on how to make inlining
decisions
Results
- Adaptive inlining achieves the potential
improvement of procedure inlining - Produces faster executables than
- either GCC or no inlining
- Performance improves with more
- descents
- Different benchmarks require
- different descents, necessitating an
- adaptive approach
- Our approach Use adaptive compilation with
inlining to make the right inlining decisions for
a specific context - We can be more aggressive with inlining
decisions - Take advantage of todays faster hardware to
explore multiple methods of inlining
Comparison of adaptive inlining against GCC
inlining and no inlining
Step Vortex Parser Bzip2 Gzip Mcf
SC Increased 7.88 11.17 15.74 16.56 9.30
SC Decreased 9.07 19.68 21.30 15.95 22.10
Loop SC Increased 8.11 10.64 0.93 2.45 1.16
Loop SC Decreased 8.35 8.51 1.85 5.52 3.49
SCC SC Increased 13.60 10.11 23.15 6.75 20.93
SCC SC Decreased 5.25 8.51 12.04 7.36 34.88
CLC Increased 3.82 4.26 8.33 6.13 2.33
CLC Decreased 3.82 2.12 2.78 0.61 2.33
CPC Increased 3.58 5.32 2.78 6.13 2.33
CPC Decreased 4.06 1.59 4.63 14.72 1.16
CPC SC Increased 6.44 3.19 0.00 4.91 0.00
CPC SC Decreased 3.34 0.53 0.00 2.45 0.00
DCC Increased 18.85 4.26 1.85 0.61 0.00
DCC Decreased 3.82 10.11 4.63 9.82 0.00
Adaptive Compilation
Running time vs. number of evaluations for Vortex
using various adaptive approaches
Compiler
- Iterative Process
- Compile with initial set of decisions
- Evaluate code
- Use previous decisions and results to guide
future decisions
Adaptive Controller
Objective Function
Percentage of time each neighbor was chosen by
the hill climber