Generating compiler optimizations from proofs
Download
1 / 16

Generating Compiler Optimizations from Proofs - PowerPoint PPT Presentation


  • 122 Views
  • Uploaded on

Generating Compiler Optimizations from Proofs. Ross Tate Michael Stepp Sorin Lerner University of California, San Diego. Optimizing by Hand. Original. Optimized. for (i = 0; i < 5 0 ; i++) for (j = 0; j < 5 0 ; j++) *(img++) = f(i, j); Executes more efficiently.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
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

Generating Compiler Optimizations from Proofs

Ross Tate

Michael Stepp

Sorin Lerner

University of California, San Diego


Optimizing by hand
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
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
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


8 + 8 – 8 important

Translation Validator

8 + 8 – 8 = 8

8


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


Learned optimization

Most General Optimization for this proof important

d + e – e

Translation Validator

Proof Generalizer

Learned Optimization

d

by examining a proof of equivalence

8 + 8 – 8

8


Abstract algorithm
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


Application evaluation

Application & importantEvaluation


Training the optimizer
Training the Optimizer important

  • Need a more expressive logic

    • Program Expression Graphs [POPL ‘09]

Translation Validator

Proof Generalizer


Training the optimizer1
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
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
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
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


ad