Abstract
An efficient optimizing compiler can perform many cascading rewrites in a single pass, using auxiliary data structures such as variable binding maps, delayed substitutions, and occurrence counts. Such optimizers often perform transformations according to relatively simple rewrite rules, but the subtle interactions between the data structures needed for efficiency make them tricky to write and trickier to prove correct. We present a system for semi-automatically deriving both an efficient program transformation and its correctness proof from a list of rewrite rules and specifications of the auxiliary data structures it requires. Dependent types ensure that the holes left behind by our system (for the user to fill in) are filled in correctly, allowing the user low-level control over the implementation without having to worry about getting it wrong. We implemented our system in Coq (though it could be implemented in other logics as well), and used it to write optimization passes that perform uncurrying, inlining, dead code elimination, and static evaluation of case expressions and record projections. The generated implementations are sometimes faster, and at most 40% slower, than hand-written counterparts on a small set of benchmarks; in some cases, they require significantly less code to write and prove correct.
Supplemental Material
- Abhishek Anand, Andrew W. Appel, Greg Morrisett, Zoe Paraskevopoulou, Randy Pollack, Olivier Savary Belanger, Matthieu Sozeau, and Matthew Weaver. 2017. CertiCoq: A verified compiler for Coq. In The Third International Workshop on Coq for Programming Languages (CoqPL).Google Scholar
- Andrew W. Appel. 1994. Loop headers in λ -calculus or CPS. Lisp and Symbolic Computation, 7, 4 (1994), 337–343.Google Scholar
Digital Library
- Andrew W. Appel and Trevor Jim. 1997. Shrinking lambda expressions in linear time. Journal of Functional Programming, 7, 5 (1997), 515–540.Google Scholar
Digital Library
- Andrew W. Appel and David B. MacQueen. 1991. Standard ML of New Jersey. In 3rd International Symp. on Prog. Lang. Implementation and Logic Programming, Martin Wirsing (Ed.). Springer-Verlag, New York. 1–13.Google Scholar
- Nick Benton, Andrew Kennedy, Sam Lindley, and Claudio Russo. 2004. Shrinking reductions in SML. NET. In Symposium on Implementation and Application of Functional Languages. 142–159.Google Scholar
- Pierre Chambart, Mark Shinwell, Leo White, and Damien Doligez. 2016. Optimization with Flambda. https://caml.inria.fr/pub/docs/manual-ocaml/flambda.htmlGoogle Scholar
- Ron Cytron, Jeanne Ferrante, Barry K. Rosen, Mark N. Wegman, and F. Kenneth Zadeck. 1991. Efficiently Computing Static Single Assignment Form and the Control Dependence Graph. ACM Transactions on Programming Languages and Systems, 13, 4 (1991), October, 451–490.Google Scholar
Digital Library
- Martin Erwig and Simon Peyton Jones. 2001. Pattern guards and transformational patterns. Electronic Notes in Theoretical Computer Science, 41, 1 (2001), 3.Google Scholar
Cross Ref
- Gérard Huet. 1997. Functional pearl. J. functional programming, 7, 5 (1997), 549–554.Google Scholar
- Andrew Kennedy. 2007. Compiling with Continuations, Continued. SIGPLAN Not., 42, 9 (2007), 177–190.Google Scholar
Digital Library
- Eugene E Kohlbecker and Mitchell Wand. 1987. Macro-by-example: Deriving syntactic transformations from their specifications. In Proceedings of the 14th ACM SIGACT-SIGPLAN symposium on Principles of programming languages. 77–84.Google Scholar
Digital Library
- D. Kranz, R. Kelsey, J. Rees, P. Hudak, J. Philbin, and N. Adams. 1986. ORBIT: An optimizing compiler for Scheme. SIGPLAN Notices (Proc. Sigplan ’86 Symp. on Compiler Construction), 21, 7 (1986), July, 219–33.Google Scholar
- Ramana Kumar, Magnus O Myreen, Michael Norrish, and Scott Owens. 2014. CakeML: a verified implementation of ML. ACM SIGPLAN Notices, 49, 1 (2014), 179–191.Google Scholar
Digital Library
- David Lacey and Oege De Moor. 2001. Imperative program transformation by rewriting. In International Conference on Compiler Construction. 52–68.Google Scholar
Cross Ref
- Sorin Lerner, Todd Millstein, and Craig Chambers. 2005. Cobalt: A language for writing provably-sound compiler optimizations. Electronic Notes in Theoretical Computer Science, 132, 1 (2005), 5–17.Google Scholar
Digital Library
- Sorin Lerner, Todd Millstein, Erika Rice, and Craig Chambers. 2005. Automated Soundness Proofs for Dataflow Analyses and Transformations via Local Rules. SIGPLAN Not., 40, 1 (2005), Jan., 364–377. issn:0362-1340 https://doi.org/10.1145/1047659.1040335 Google Scholar
Digital Library
- Xavier Leroy. 2012. The CompCert verified compiler.Google Scholar
- William Mansky. 2014. Specifying and verifying program transformations with PTRANS. Ph.D. Dissertation. University of Illinois at Urbana-Champaign.Google Scholar
- Jacob Matthews and Robert Bruce Findler. 2007. Operational semantics for multi-language programs. ACM SIGPLAN Notices, 42, 1 (2007), 3–10.Google Scholar
Digital Library
- Georg Neis, Chung-Kil Hur, Jan-Oliver Kaiser, Craig McLaughlin, Derek Dreyer, and Viktor Vafeiadis. 2015. Pilsner: a compositionally verified compiler for a higher-order imperative language. In Proceedings of the 20th ACM SIGPLAN International Conference on Functional Programming. 166–178.Google Scholar
Digital Library
- Simon Peyton Jones and Simon Marlow. 2002. Secrets of the Glasgow Haskell Compiler Inliner. J. Funct. Program., 12, 5 (2002), July, 393–434. issn:0956-7968 https://doi.org/10.1017/S0956796802004331 Google Scholar
Digital Library
- Reudismam Rolim, Gustavo Soares, Loris D’Antoni, Oleksandr Polozov, Sumit Gulwani, Rohit Gheyi, Ryo Suzuki, and Björn Hartmann. 2017. Learning syntactic program transformations from examples. In 2017 IEEE/ACM 39th International Conference on Software Engineering (ICSE). 404–415.Google Scholar
Digital Library
- Dipanwita Sarkar, Oscar Waddell, R Kent Dybvig, and EDUCATIONAL PEARL. 2005. A nanopass framework for compiler education. Journal of Functional Programming, 15, 5 (2005), 653.Google Scholar
Digital Library
- Olivier Savary Bélanger and Andrew W. Appel. 2017. Shrink fast correctly!. In Proceedings of the 19th International Symposium on Principles and Practice of Declarative Programming. 49–60.Google Scholar
- Matthieu Sozeau. 2010. Equations: A dependent pattern-matching compiler. In International Conference on Interactive Theorem Proving. 419–434.Google Scholar
Digital Library
- Matthieu Sozeau, Abhishek Anand, Simon Boulier, Cyril Cohen, Yannick Forster, Fabian Kunze, Gregory Malecha, Nicolas Tabareau, and Théo Winterhalter. 2020. The MetaCoq Project. Journal of Automated Reasoning, 1–53.Google Scholar
- Guy L. Steele. 1978. Rabbit: a compiler for Scheme. MIT, Cambridge, MA.Google Scholar
- Gordon Stewart, Lennart Beringer, and Andrew W. Appel. 2012. Verified heap theorem prover by paramodulation. ACM SIGPLAN Notices, 47, 9 (2012), 3–14.Google Scholar
Digital Library
- Ross Tate, Michael Stepp, and Sorin Lerner. 2010. Generating Compiler Optimizations from Proofs. SIGPLAN Not., 45, 1 (2010), Jan., 389–402. issn:0362-1340 https://doi.org/10.1145/1707801.1706345 Google Scholar
Digital Library
- Steven WK Tjiang and John L Hennessy. 1992. Sharlit—a tool for building optimizers. ACM SIGPLAN Notices, 27, 7 (1992), 82–93.Google Scholar
Digital Library
- Eelco Visser. 2004. Program transformation with Stratego/XT. In Domain-specific program generation. Springer, 216–238.Google Scholar
- Deborah L Whitfield and Mary Lou Soffa. 1997. An approach for exploring code improving transformations. ACM Transactions on Programming Languages and Systems (TOPLAS), 19, 6 (1997), 1053–1084.Google Scholar
Digital Library
- Xuejun Yang, Yang Chen, Eric Eide, and John Regehr. 2011. Finding and understanding bugs in C compilers. ACM SIGPLAN Notices (PLDI’11), 46, 6 (2011), 283–294.Google Scholar
Index Terms
Deriving efficient program transformations from rewrite rules
Recommendations
Domain-specific languages and program generation with meta-AspectJ
Meta-AspectJ (MAJ) is a language for generating AspectJ programs using code templates. MAJ itself is an extension of Java, so users can interleave arbitrary Java code with AspectJ code templates. MAJ is a structured metaprogramming tool: a well-typed ...
Reusable, generic program analyses and transformations
GPCE '09The optimizations in modern compilers are constructed for a predetermined set of primitive types. As a result, programmers are unable to exploit optimizations for user-defined types where these optimizations would be correct and beneficial. Moreover, ...
Program Transformation with Scoped Dynamic Rewrite Rules
Program Transformation: Theoretical Foundations and Basic Techniques. Part 2The applicability of term rewriting to program transformation is limited by the lack of control over rule application and by the context-free nature of rewrite rules. The first problem is addressed by languages supporting user-definable rewriting ...






Comments