1 / 16

Generating Compiler Optimizations from Proofs

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.

asis
Télécharger la présentation

Generating Compiler Optimizations from Proofs

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Generating Compiler Optimizations from Proofs Ross Tate Michael Stepp Sorin Lerner University of California, San Diego

  2. 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

  3. 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

  4. 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);

  5. How it works

  6. 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

  7. 8 + 8 – 8 Translation Validator 8 + 8 – 8 = 8 8

  8. Generalized Proof ∃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

  9. Most General Optimization for this proof d + e – e Translation Validator Proof Generalizer Learned Optimization d by examining a proof of equivalence 8 + 8 – 8 8

  10. Abstract Algorithm • Formalized using category theory • Pushouts • Pullbacks • Pushout Completions • Different categories for different logics • Different representations of programs • Domains besides program optimizations Proof Generalizer

  11. Application &Evaluation

  12. Training the Optimizer • Need a more expressive logic • Program Expression Graphs [POPL ‘09] Translation Validator Proof Generalizer

  13. Training the Optimizer • 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!

  14. Speeding Up Optimization • 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

  15. Flexible Proof Generalization • Learn database query optimizations • Improve type error messages in Haskell • Assist with contract debugging in Spec# • Infer polymorphism in typed programs Proof Generalizer τ 

  16. Conclusion • Algorithm to learn compiler optimizations • from programmers • from superoptimizers • Abstract proof generalization algorithm • Applicable to other logics • Applicable to other domains Thank You

More Related