skip to main content

Deriving efficient program transformations from rewrite rules

Published:19 August 2021Publication History
Skip Abstract Section

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.

Skip Supplemental Material Section

Supplemental Material

Auxiliary Presentation Video

This is a presentation video of my talk at ICFP 2021 on our paper accepted in the research track, titled "Deriving Efficient Program Transformations From Rewrite Rules."

3473579.mp4

Presentation Videos

References

  1. 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 ScholarGoogle Scholar
  2. Andrew W. Appel. 1994. Loop headers in λ -calculus or CPS. Lisp and Symbolic Computation, 7, 4 (1994), 337–343.Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Andrew W. Appel and Trevor Jim. 1997. Shrinking lambda expressions in linear time. Journal of Functional Programming, 7, 5 (1997), 515–540.Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. 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 ScholarGoogle Scholar
  5. 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 ScholarGoogle Scholar
  6. Pierre Chambart, Mark Shinwell, Leo White, and Damien Doligez. 2016. Optimization with Flambda. https://caml.inria.fr/pub/docs/manual-ocaml/flambda.htmlGoogle ScholarGoogle Scholar
  7. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  8. Martin Erwig and Simon Peyton Jones. 2001. Pattern guards and transformational patterns. Electronic Notes in Theoretical Computer Science, 41, 1 (2001), 3.Google ScholarGoogle ScholarCross RefCross Ref
  9. Gérard Huet. 1997. Functional pearl. J. functional programming, 7, 5 (1997), 549–554.Google ScholarGoogle Scholar
  10. Andrew Kennedy. 2007. Compiling with Continuations, Continued. SIGPLAN Not., 42, 9 (2007), 177–190.Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  12. 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 ScholarGoogle Scholar
  13. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  14. David Lacey and Oege De Moor. 2001. Imperative program transformation by rewriting. In International Conference on Compiler Construction. 52–68.Google ScholarGoogle ScholarCross RefCross Ref
  15. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  16. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  17. Xavier Leroy. 2012. The CompCert verified compiler.Google ScholarGoogle Scholar
  18. William Mansky. 2014. Specifying and verifying program transformations with PTRANS. Ph.D. Dissertation. University of Illinois at Urbana-Champaign.Google ScholarGoogle Scholar
  19. Jacob Matthews and Robert Bruce Findler. 2007. Operational semantics for multi-language programs. ACM SIGPLAN Notices, 42, 1 (2007), 3–10.Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  21. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  22. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  23. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  24. 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 ScholarGoogle Scholar
  25. Matthieu Sozeau. 2010. Equations: A dependent pattern-matching compiler. In International Conference on Interactive Theorem Proving. 419–434.Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. 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 ScholarGoogle Scholar
  27. Guy L. Steele. 1978. Rabbit: a compiler for Scheme. MIT, Cambridge, MA.Google ScholarGoogle Scholar
  28. Gordon Stewart, Lennart Beringer, and Andrew W. Appel. 2012. Verified heap theorem prover by paramodulation. ACM SIGPLAN Notices, 47, 9 (2012), 3–14.Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  30. Steven WK Tjiang and John L Hennessy. 1992. Sharlit—a tool for building optimizers. ACM SIGPLAN Notices, 27, 7 (1992), 82–93.Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. Eelco Visser. 2004. Program transformation with Stratego/XT. In Domain-specific program generation. Springer, 216–238.Google ScholarGoogle Scholar
  32. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  33. 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 ScholarGoogle Scholar

Index Terms

  1. Deriving efficient program transformations from rewrite rules

    Recommendations

    Comments

    Login options

    Check if you have access through your login credentials or your institution to get full access on this article.

    Sign in

    Full Access

    PDF Format

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader
    About Cookies On This Site

    We use cookies to ensure that we give you the best experience on our website.

    Learn more

    Got it!