Loading in 5 sec....

Generating Compiler Optimizations from ProofsPowerPoint Presentation

Generating Compiler Optimizations from Proofs

- By
**asis** - Follow User

- 126 Views
- Uploaded on

Download Presentation
## PowerPoint Slideshow about ' Generating Compiler Optimizations from Proofs' - asis

**An Image/Link below is provided (as is) to download presentation**

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript

### Generating Compiler Optimizations from Proofs

### Application & importantEvaluation

Ross Tate

Michael Stepp

Sorin Lerner

University of California, San Diego

Optimizing by Hand

Original

Optimized

for (i = 0; i < 50; i++)

for (j = 0; j < 50; j++)

*(img++) = f(i, j);

Executes more efficiently

for (i = 0; i < 50; i++)

for (j = 0; j < 50; j++)

img[i*50 + j] = f(i, j);

- Easier to understand

Make the compiler do it!

Train the compiler to do it!

Many compilers do not perform this optimization

Generalizing Optimizations

Original

Optimized

for (i = 0; i < 50; i++)

for (j = 0; j < 50; j++)

*(img++) = f(i, j);

for (i = 0; i < w; i++)

for (j = 0; j < h; j++)

use(*(img++))

for (i = 0; i < 50; i++)

for (j = 0; j < 50; j++)

img[i*50 + j] = f(i, j);

for (i = 0; i < w; i++)

for (j = 0; j < h; j++)

use(img[i*h+ j])

Generalize

Generalized

h is loop-invariant

use does not modify i, j, or img

Generalizing Automatically

Original

Optimized

for (i = 0; i < 50; i++)

for (j = 0; j < 50; j++)

*(img++) = f(i, j);

for (i = 0; i < 50; i++)

for (j = 0; j < 50; j++)

img[i*50 + j] = f(i, j);

Proof informs which details in the programs are actually important

Instantiation

Translation Validator

Proof Generalizer

- Programmers can teach the compiler
- with just one concrete example
- using a language they already know

Generalized Proof important

∃e.

e – e = 0

∃c,d.

c = 0

⇒

d + c = d

Uses fact i

Adds fact ii

Adds fact i

Translation Validator

Proof Generalizer

Proof Generalizer

a

d + e – e

d + c

c

a

∅

i) e – e = 0

i) c = 0

ii) a = b

i) c = 0

ii) a = b

i) c = 0

ii) d + c = b

i) c = 0

ii) d + c = d

i) e – e = 0

ii) d + e – e = d

c = 0

c

c

a = b

a

c

b

∀x. x – x = 0

∀x,y. x = 0 ⇒y + x = y

b

d

b

Instantiation: d,e↦ 8

Uses fact i

Adds fact ii

Adds fact i

8 + 8 – 8

∅

i) 8 – 8 = 0

i) 8 – 8 = 0

ii) 8 + 8 – 8 = 8

8

Most General Optimization for this proof important

d + e – e

Translation Validator

Proof Generalizer

Learned Optimizationd

by examining a proof of equivalence

8 + 8 – 8

8

Abstract Algorithm important

- Formalized using category theory
- Pushouts
- Pullbacks
- Pushout Completions

- Different categories for different logics
- Different representations of programs
- Domains besides program optimizations

Proof Generalizer

Training the Optimizer important

- Need a more expressive logic
- Program Expression Graphs [POPL ‘09]

Translation Validator

Proof Generalizer

Training the Optimizer important

- Inter-Loop Strength & Bound Reduction
- Loop Induction Strength & Bound Reduction
- Partial & Specialized Inlining
- Temporary Object Removal
- Loop Operation Factoring & Distribution
- Entire Loop Strength Reduction
- Array Copy Propagation
- Design Pattern Overhead Reduction

As translation validation improves,

so will optimization learning, for free!

Speeding Up Optimization important

- Ran on a ray tracer
- Rewriter produced high-quality code

Advanced Optimizer

Optimization Generalizer

- We want
- advanced optimizations
- the speed of the rewriter

Decomposer

Fast Rewriter

Flexible Proof Generalization important

- Learn database query optimizations
- Improve type error messages in Haskell
- Assist with contract debugging in Spec#
- Infer polymorphism in typed programs

Proof Generalizer

τ

Conclusion important

- Algorithm to learn compiler optimizations
- from programmers
- from superoptimizers

- Abstract proof generalization algorithm
- Applicable to other logics
- Applicable to other domains

Thank You

Download Presentation

Connecting to Server..