/
Generating Compiler Optimizations from Proofs Generating Compiler Optimizations from Proofs

Generating Compiler Optimizations from Proofs - PowerPoint Presentation

lois-ondreau
lois-ondreau . @lois-ondreau
Follow
345 views
Uploaded On 2018-09-21

Generating Compiler Optimizations from Proofs - PPT Presentation

Ross Tate Michael Stepp Sorin Lerner University of California San Diego Optimizing by Hand Original for i 0 i lt 50 i for j 0 j lt 50 j imgi50 j fi j ID: 674078

img proof fact generalizer proof img generalizer fact translation optimization compiler validator optimizations amp adds loop generalization optimized strength optimizer learn algorithm

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "Generating Compiler Optimizations from P..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Slide1

Generating Compiler Optimizations from Proofs

Ross Tate

Michael Stepp

Sorin Lerner

University of California, San DiegoSlide2

Optimizing by Hand

Original

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

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

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

Optimized

for (i = 0; i < 50; i++) for (j = 0; j < 50; j++) *(img++) = f(i, j);Executes more efficiently

Make the compiler do it!

Train the compiler to do it!

Many compilers do not perform this optimizationSlide3

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

])Generalizing OptimizationsOriginal

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++))

Generalize

h

is loop-invariant

use

does not modify i, j, or

img

GeneralizedSlide4

Generalizing Automatically

Original

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

for (j = 0; j < 50; j++) img[i*50 + j] = f(i, j);Optimized

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

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

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

How it worksSlide6

Proof Generalizer

Instantiation

Programmers can teach the compiler

w

ith just one concrete example

using a language they already know

Proof informs which details in the programs are actually important

Translation ValidatorSlide7

8 + 8 – 8 = 8

8 + 8 – 8

8

Translation ValidatorSlide8

Generalized Proof

x. x – x = 0

x,y. x = 0 ⇒

y + x = y

i) 8 – 8 = 0

ii) 8 + 8 – 8 = 8

Uses fact i

Adds fact ii

Adds fact i

Translation Validator

Proof Generalizer

Proof Generalizer

c,d

.

i) 8 – 8 = 0

8 + 8 – 8

8

ii) a = b

Uses fact i

Adds fact ii

Adds fact i

i) c = 0

a

b

i) c = 0

ii) a = b

i) c = 0

ii) d + c = b

i) c = 0

ii) d + c = d

d + c

c = 0

d + c = d

e

.

e

– e =

0

i) e – e = 0

i) e – e = 0

ii) d +

e – e

= d

d + e – e

d

Instantiation:

d,e

8

a

a

b

b

c

c

c

c

a = b

c = 0Slide9

Learned Optimization

d + e – e

d

Translation Validator

Proof Generalizer

8 + 8 – 8

8

Most General Optimization for this proof

b

y examining a proof of equivalenceSlide10

Abstract Algorithm

Formalized using category theory

PushoutsPullbacksPushout Completions

Different categories for different logicsDifferent representations of programsDomains besides program optimizations

Proof GeneralizerSlide11

Application &EvaluationSlide12

Translation Validator

Proof Generalizer

Training the Optimizer

Need a more expressive logic

Program Expression Graphs [POPL ‘09]Slide13

Training the Optimizer

Inter-Loop Strength & Bound Reduction

Loop Induction Strength & Bound ReductionPartial & Specialized Inlining

Temporary Object RemovalLoop Operation Factoring & DistributionEntire Loop Strength ReductionArray Copy PropagationDesign Pattern Overhead Reduction

As translation validation improves,so will optimization learning, for free!Slide14

We want

a

dvanced optimizationsthe speed of the rewriter

Speeding Up Optimization

Ran on a ray tracer

Rewriter produced high-quality code

Decomposer

Optimization Generalizer

Fast Rewriter

Advanced OptimizerSlide15

Flexible Proof Generalization

Learn database query optimizations

Improve type error messages in HaskellAssist with contract debugging in Spec#

Infer polymorphism in typed programs

τ

Proof GeneralizerSlide16

Conclusion

Algorithm to learn compiler optimizations

from programmersfrom superoptimizersAbstract proof

generalization algorithmApplicable to other logicsApplicable to other domains

Thank YouSlide17

Conclusion

Algorithm to learn compiler optimizations

from programmersfrom superoptimizersAbstract proof

generalization algorithmApplicable to other logicsApplicable to other domains

?

?

?