Phase ordering problem - PowerPoint PPT Presentation

About This Presentation
Title:

Phase ordering problem

Description:

Optimizations can interact in mutually beneficial ways, and no ... const prop and pointer analysis [Pioli and Hind 99] Monolithic. Super-Analysis. Ideally... – PowerPoint PPT presentation

Number of Views:32
Avg rating:3.0/5.0
Slides: 59
Provided by: sorinl
Learn more at: https://cseweb.ucsd.edu
Category:
Tags: hind | ordering | phase | problem

less

Transcript and Presenter's Notes

Title: Phase ordering problem


1
Phase ordering problem
  • Optimizations can interact in mutually beneficial
    ways, and no order exploits all of these
    interactions.
  • Classic example constant propagation and
    unreachable code elimination.

x 11 DoSomething() y x // value of y?
x 11 if (x 11) DoSomething() else
DoSomethingElse() x x 1 y x
// value of y?
true
x 11 DoSomething() y 11
2
One known solution Iterate individual analyses
until the results dont change
x 11 do if (x 11)
DoSomething() else
DoSomethingElse() x x 1 while
(...) y x // value of y?
  • Compiler is slow.
  • In the presence of loops in the source program,
    might not yield best possible results.

3
Another known solution hand writtensuper-analysi
s
  • Examples
  • conditional constant propagation Wegman and
    Zadeck 91
  • class analysis, splitting and inlining Chambers
    and Ungar 90
  • const prop and pointer analysis Pioli and Hind
    99
  • Lose modularity
  • difficult to write, reuse, and extend such
    analyses

4
Ideally...
  • ... we want to
  • Write analyses modularly
  • Exploit mutually beneficial interactions
  • Have a fast compiler
  • We present a framework that achieves this.

5
The key to modular composition
  • Traditionally, optimizations are defined in two
    parts
  • A dataflow analysis.
  • Rules for transforming the program representation
    after the analysis is solved.
  • The key insight is to merge these two parts
  • Dataflow functions return either a dataflow value
    OR a replacement graph with which to replace the
    current statement.

6
Flow function returning a dataflow value
y 5
7
Flow function returning a dataflow value
...
y 5
PROPAGATE
..., y ? 5
8
Flow function returning a replacement graph
y x2
9
Flow function returning a replacement graph
Step 1 Initialize input edges with dataflow
information
Replacement graph
x ? 3
x ? 3
y x2
10
Flow function returning a replacement graph
Step 2 Perform recursive dataflow analysis on
the replacement graph
Step 1 Initialize input edges with dataflow
information
x ? 3
x ? 3
y x2
PROPAGATE
x ? 3, y ? 5
11
Flow function returning a replacement graph
Step 2 Perform recursive dataflow analysis on
the replacement graph
Step 1 Initialize input edges with dataflow
information
x ? 3
x ? 3
y x2
PROPAGATE
x ? 3, y ? 5
x ? 3, y ? 5
Step 3 Propagate dataflow information from
output edges.
12
Flow function returning a replacement graph
  • Replacement graphs
  • used to compute outgoing dataflow information for
    the current statement.
  • a convenient way of specifying what might
    otherwise be a complicated flow function.
  • Replacement graphs
  • used to compute outgoing dataflow information for
    the current statement.

x ? 3
y x2
x ? 3, y ? 5
13
Flow function returning a replacement graph
  • Soundness requirement
  • Replacement graph must have the same concrete
    semantics as the original statement, but only on
    concrete inputs that are consistent with the
    current dataflow facts.

x ? 3
y x2
x ? 3, y ? 5
14
Flow function returning a replacement graph
Lets assume weve reached a fixed point.
x ? 3
y x2
x ? 3, y ? 5
15
Flow function returning a replacement graph
Lets assume weve reached a fixed point.
x ? 3
y x2
y 5
x ? 3, y ? 5
16
Flow function returning a replacement graph
Lets assume weve reached a fixed point.
  • Replacement graphs
  • used to transform the program once a fixed point
    has been reached.

x ? 3
y 5
x ? 3, y ? 5
17
Iterative analysis example
Now, lets assume we havent reached a fixed
point.
x ? 3
x ? T
y x2
x ? 3, y ? 5
18
Iterative analysis example
Now, lets assume we havent reached a fixed
point.
x ? 3
x ? T
y x2
PROPAGATE
x ? 3, y ? 5
x ? T, y ? T
19
Branch folding example
if (x 11)
F
T
20
Branch folding example
x ? 11
x ? 11
if (x 11)
F
T
21
Branch folding example
x ? 11
x ? 11
if (x 11)
x ? 11
x ? 11
F
T
22
Branch folding example
x ? 11
if (x 11)
x ? 11
F
T
23
Composing several analyses
24
x new C
merge
b x instanceof C
if (b)
T
F
x new D
x x.foo()
merge
while()
25
x new C
PROPAGATE
PROPAGATE
PROPAGATE
PROPAGATE
x ? T
x ? C
T
T
merge
b x instanceof C
if (b)
T
F
x new D
x x.foo()
merge
while()
26
x new C
PROPAGATE
PROPAGATE
PROPAGATE
PROPAGATE
PROPAGATE
x ? T
x ? C
(x ? T, x ? C, T, T)
T
T
merge
b x instanceof C
if (b)
T
F
x new D
x x.foo()
merge
while()
27
x new C
(x ? T, x ? C, T, T)
merge
PROPAGATE
(x ? T, x ? C, T, T)
b x instanceof C
if (b)
T
F
x new D
x x.foo()
merge
while()
28
x new C
(x ? T, x ? C, T, T)
merge
(x ? T, x ? C, T, T)
b x instanceof C
PROPAGATE
x ? T, b ? T
if (b)
T
F
x new D
x x.foo()
merge
while()
29
x new C
(x ? T, x ? C, T, T)
merge
(x ? T, x ? C, T, T)
(x ? T, x ? C, T, T)
b x instanceof C
x ? T, b ? T
if (b)
T
F
x new D
x x.foo()
merge
while()
30
x new C
(x ? T, x ? C, T, T)
merge
(x ? T, x ? C, T, T)
b x instanceof C
(x ? T, x ? C, T, T)
PROPAGATE
if (b)
(x ? T, b ? true, x ? C, b ? Bool,
T, T)
T
F
x new D
x x.foo()
merge
while()
31
x new C
(x ? T, x ? C, T, T)
merge
(x ? T, x ? C, T, T)
b x instanceof C
(x ? T, x ? C, T, T)
if (b)
(x ? T, b ? true, x ? C, b ? Bool,
T, T)
(x ? T, b ? true, x ? C, b ? Bool,
T, T)
T
F
x new D
x x.foo()
merge
while()
32
x new C
(x ? T, x ? C, T, T)
merge
(x ? T, x ? C, T, T)
  • Replacement graph is analyzed by composed
    analysis.
  • When one analysis chooses a replacement graph,
    other analyses see it immediately.
  • Analyses communicate implicitly through graph
    transformations

b x instanceof C
(x ? T, b ? true, x ? C, b ? Bool,
T, T)
if (b)
T
F
x new D
x x.foo()
merge
while()
33
x new C
(x ? T, x ? C, T, T)
merge
(x ? T, x ? C, T, T)
b x instanceof C
(x ? T, b ? true, x ? C, b ? Bool,
T, T)
s
if (b)
T
F
x new D
x x.foo()
merge
while()
34
x new C
(x ? T, x ? C, T, T)
merge
(x ? T, x ? C, T, T)
b x instanceof C
(x ? T, b ? true, x ? C, b ? Bool,
T, T)
s
s
if (b)
T
F
x new D
x x.foo()
merge
while()
35
x new C
(x ? T, x ? C, T, T)
merge
(x ? T, x ? C, T, T)
b x instanceof C
(x ? T, b ? true, x ? C, b ? Bool,
T, T)
s
s
s
if (b)
s
T
F
x new D
x x.foo()
merge
while()
36
x new C
(x ? T, x ? C, T, T)
merge
(x ? T, x ? C, T, T)
b x instanceof C
(x ? T, b ? true, x ? C, b ? Bool,
T, T)
s
s
if (b)
s
s
T
F
x new D
x x.foo()
merge
while()
37
x new C
(x ? T, x ? C, T, T)
merge
(x ? T, x ? C, T, T)
b x instanceof C
(x ? T, b ? true, x ? C, b ? Bool,
T, T)
if (b)
(x ? T, b ? true, x ? C, b ? Bool,
T, T)
T
F
x new D
x x.foo()
merge
while()
38
x new C
(x ? T, x ? C, T, T)
merge
(x ? T, x ? C, T, T)
b x instanceof C
(x ? T, b ? true, x ? C, b ? Bool,
T, T)
if (b)
(x ? T, b ? true, x ? C, b ? Bool,
T, T)
T
F
x new D
x x.foo()
merge
while()
39
x new C
(x ? T, x ? C, T, T)
merge
(x ? T, x ? C, T, T)
b x instanceof C
(x ? T, b ? true, x ? C, b ? Bool,
T, T)
if (b)
(x ? T, b ? true, x ? C, b ? Bool,
T, T)
T
F
x new D
x x.foo()
merge
while()
40
x new C
(x ? T, x ? C, T, T)
merge
(x ? T, x ? C, T, T)
b x instanceof C
(x ? T, b ? true, x ? C, b ? Bool,
T, T)
if (b)
(x ? T, b ? true, x ? C, b ? Bool,
T, T)
T
F
x new D
x x.foo()
merge
while()
41
x new C
(x ? T, x ? C, T, T)
merge
(x ? T, x ? C, T, T)
b x instanceof C
(x ? T, b ? true, x ? C, b ? Bool,
T, T)
if (b)
(x ? T, b ? true, x ? C, b ? Bool,
T, T)
s
s
T
F
x new D
x x.foo()
merge
while()
42
x new C
class C extends A A foo() return self
(x ? T, x ? C, T, T)
merge
s
s
(x ? T, x ? C, T, T)
b x instanceof C
(x ? T, b ? true, x ? C, b ? Bool,
T, T)
if (b)
(x ? T, b ? true, x ? C, b ? Bool,
T, T)
s
F
T
x new D
x x.foo()
merge
while()
43
x new C
(x ? T, x ? C, T, T)
merge
s
(x ? T, x ? C, T, T)
b x instanceof C
(x ? T, b ? true, x ? C, b ? Bool,
T, T)
if (b)
(x ? T, b ? true, x ? C, b ? Bool,
T, T)
s
F
T
x new D
x x.foo()
s
PROPAGATE
merge
s
while()
44
x new C
(x ? T, x ? C, T, T)
merge
s
(x ? T, x ? C, T, T)
b x instanceof C
(x ? T, b ? true, x ? C, b ? Bool,
T, T)
if (b)
(x ? T, b ? true, x ? C, b ? Bool,
T, T)
s
F
T
x new D
x x.foo()
s
merge
s
s
while()
45
x new C
(x ? T, x ? C, T, T)
merge
s
(x ? T, x ? C, T, T)
b x instanceof C
s
s
(x ? T, b ? true, x ? C, b ? Bool,
T, T)
if (b)
(x ? T, b ? true, x ? C, b ? Bool,
T, T)
s
F
T
x new D
x x.foo()
merge
while()
46
x new C
(x ? T, x ? C, T, T)
merge
s
(x ? T, x ? C, T, T)
b x instanceof C
s
(x ? T, b ? true, x ? C, b ? Bool,
T, T)
if (b)
(x ? T, b ? true, x ? C, b ? Bool,
T, T)
s
F
T
x new D
x x.foo()
(x ? T, b ? true, x ? C, b ? Bool,
T, T)
merge
while()
47
x new C
(x ? T, x ? C, T, T)
merge
(x ? T, x ? C, T, T)
b x instanceof C
(x ? T, b ? true, x ? C, b ? Bool,
T, T)
if (b)
(x ? T, b ? true, x ? C, b ? Bool,
T, T)
T
F
x x.foo()
x new D
(x ? T, b ? true, x ? C, b ? Bool,
T, T)
merge
while()
48
x new C
(x ? T, x ? C, T, T)
merge
(x ? T, x ? C, T, T)
b x instanceof C
(x ? T, b ? true, x ? C, b ? Bool,
T, T)
if (b)
(x ? T, b ? true, x ? C, b ? Bool,
T, T)
T
F
x x.foo()
x new D
(x ? T, b ? true, x ? C, b ? Bool,
T, T)
merge
PROPAGATE
(x ? T, b ? true, x ? C, b ? Bool,
T , T)
while()
49
x new C
(x ? T, x ? C, T, T)
(x ? T, x ? C, T, T)
merge
(x ? T, x ? C, T, T)
b x instanceof C
(x ? T, b ? true, x ? C, b ? Bool,
T, T)
if (b)
(x ? T, b ? true, x ? C, b ? Bool,
T, T)
T
F
x x.foo()
x new D
(x ? T, b ? true, x ? C, b ? Bool,
T, T)
merge
(x ? T, b ? true, x ? C, b ? Bool,
T , T)
while()
PROPAGATE
(x ? T, b ? true, x ? C, b ? Bool,
T, T)
50
x new C
(x ? T, x ? C, T, T)
(x ? T, x ? C, T, T)
merge
(x ? T, x ? C, T, T)
b x instanceof C
(x ? T, b ? true, x ? C, b ? Bool,
T, T)
if (b)
(x ? T, b ? true, x ? C, b ? Bool,
T, T)
T
F
x x.foo()
x new D
(x ? T, b ? true, x ? C, b ? Bool,
T, T)
merge
(x ? T, b ? true, x ? C, b ? Bool,
T , T)
while()
(x ? T, b ? true, x ? C, b ? Bool,
T, T)
51
x new C
merge
b x instanceof C
b true
if (b)
T
F
x x.foo()
x x
x new D
merge
while()
52
x new C
merge
b true
x x
merge
while()
53
  • Analyses are defined modularly and separately.
  • Combining them achieves the results of a
    monolithic analysis.
  • If the analyses were run separately in any order
    any number of times, no optimizations could be
    performed.

54
Analysis followed by transformations
55
Integrating analysis and transformations
56
Composing analyses and transformations
57
(No Transcript)
58
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com