skip to main content
research-article

Practical and effective higher-order optimizations

Published:19 August 2014Publication History
Skip Abstract Section

Abstract

Inlining is an optimization that replaces a call to a function with that function's body. This optimization not only reduces the overhead of a function call, but can expose additional optimization opportunities to the compiler, such as removing redundant operations or unused conditional branches. Another optimization, copy propagation, replaces a redundant copy of a still-live variable with the original. Copy propagation can reduce the total number of live variables, reducing register pressure and memory usage, and possibly eliminating redundant memory-to-memory copies. In practice, both of these optimizations are implemented in nearly every modern compiler.

These two optimizations are practical to implement and effective in first-order languages, but in languages with lexically-scoped first-class functions (aka, closures), these optimizations are not available to code programmed in a higher-order style. With higher-order functions, the analysis challenge has been that the environment at the call site must be the same as at the closure capture location, up to the free variables, or the meaning of the program may change. Olin Shivers' 1991 dissertation called this family of optimizations superΒ and he proposed one analysis technique, called reflow, to support these optimizations. Unfortunately, reflow has proven too expensive to implement in practice. Because these higher-order optimizations are not available in functional-language compilers, programmers studiously avoid uses of higher-order values that cannot be optimized (particularly in compiler benchmarks).

This paper provides the first practical and effective technique for superΒ (higher-order) inlining and copy propagation, which we call unchanged variable analysis. We show that this technique is practical by implementing it in the context of a real compiler for an ML-family language and showing that the required analyses have costs below 3% of the total compilation time. This technique's effectiveness is shown through a set of benchmarks and example programs, where this analysis exposes additional potential optimization sites.

References

  1. Ashley, J. M. and R. K. Dybvig. A practical and flexible flow analysis for higher-order languages. ACM TOPLAS, 20(4), July 1998, pp. 845--868. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Appel, A. W. and D. B. MacQueen. Standard ML of New Jersey. In PLIP '91, vol. 528 of LNCS. Springer-Verlag, New York, NY, August 1991, pp. 1--26.Google ScholarGoogle ScholarCross RefCross Ref
  3. Barber, C. B., D. P. Dobkin, and H. Huhdanpaa. The quickhull algorithm for convex hulls. ACM TOMS, 22(4), 1996, pp. 469--483. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Bergstrom, L. Arity raising and control-flow analysis in Manticore. Master's dissertation, University of Chicago, November 2009. Available from http://manticore.cs.uchicago.edu.Google ScholarGoogle Scholar
  5. Barnes, J. and P. Hut. A hierarchical O(N logN) force calculation algorithm. Nature, 324, December 1986, pp. 446--449.Google ScholarGoogle ScholarCross RefCross Ref
  6. Cejtin, H., S. Jagannathan, and S. Weeks. Flow-directed closure conversion for typed languages. In ESOP '00. Springer-Verlag, 2000, pp. 56--71. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. CLBG. The computer language benchmarks game, 2013. Available from http://benchmarksgame.alioth.debian.org/.Google ScholarGoogle Scholar
  8. Danvy, O. and A. Filinski. Representing control: A study of the CPS transformation. MSCS, 2(4), 1992, pp. 361--391.Google ScholarGoogle Scholar
  9. Fluet, M., N. Ford, M. Rainey, J. Reppy, A. Shaw, and Y. Xiao. Status Report: The Manticore Project. In ML '07. ACM, October 2007, pp. 15--24. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Fluet, M., M. Rainey, J. Reppy, and A. Shaw. Implicitly-threaded parallelism in Manticore. JFP, 20(5-6), 2011, pp. 537--576. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. George, L., F. Guillame, and J. Reppy. A portable and optimizing back end for the SML/NJ compiler. In CC '94, April 1994, pp. 83--97. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. GHC. Barnes Hut benchmark written in Haskell. Available from http://darcs.haskell.org/packages/ndp/examples/barnesHut/.Google ScholarGoogle Scholar
  13. Hinze, R. Constructing red-black trees. In WAAAPL'99: Workshop on Algorithmic Aspects of Advanced Programming Languages, Paris, France, 1999. pp. 89--99.Google ScholarGoogle Scholar
  14. Hudak, P. A semantic model of reference counting and its abstraction (detailed summary). In LFP '86, Cambridge, Massachusetts, USA, 1986. ACM, pp. 351--363. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Midtgaard, J. Control-flow analysis of functional programs. ACM Comp. Surveys, 44(3), June 2012, pp. 10:1--10:33. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. Might, M. Shape analysis in the absence of pointers and structure. In VMCAI '10, Madrid, Spain, 2010. Springer-Verlag, pp. 263--278. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. Might, M. and O. Shivers. Environment analysis via ΔCFA. In POPL '06, Charleston, South Carolina, USA, 2006. ACM, pp. 127--140. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Nikhil, R. S. ID Language Reference Manual. Laboratory for Computer Science, MIT, Cambridge, MA, July 1991.Google ScholarGoogle Scholar
  19. Nielson, F., H. R. Nielson, and C. Hankin. Principles of Program Analysis. Springer-Verlag, New York, NY, 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Nuutila, E. An efficient transitive closure algorithm for cyclic digraphs. IPL, 52, 1994. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. Peyton Jones, S. and S. Marlow. Secrets of the Glasgow Haskell Compiler inliner. JFP, 12(5), July 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. Reps, T., S. Horwitz, and M. Sagiv. Precise interprocedural dataflow analysis via graph reachability. In POPL '95, San Francisco, 1995. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Reppy, J. and Y. Xiao. Specialization of CML message-passing primitives. In POPL '07. ACM, January 2007, pp. 315--326. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. Scandal Project. A library of parallel algorithms written NESL. Available from http://www.cs.cmu.edu/~scandal/nesl/algorithms.html.Google ScholarGoogle Scholar
  25. Serrano, M. Control flow analysis: a functional languages compilation paradigm. In SAC '95, Nashville, Tennessee, United States, 1995. ACM, pp. 118--122. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. Shivers, O. Control-flow analysis of higher-order languages. Ph.D. dissertation, School of C.S., CMU, Pittsburgh, PA, May 1991. Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. Shivers, O. and M. Might. Continuations and transducer composition. In PLDI '06, Ottawa, Ontario, Canada, 2006. ACM, pp. 295--307. Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. Tarjan, R. Depth-first search and linear graph algorithms. SIAM JC, 1(2), 1972, pp. 146--160.Google ScholarGoogle ScholarCross RefCross Ref
  29. Warshall, S. A theorem on boolean matrices. JACM, 9(1), January 1962. Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. Waddell, O. and R. K. Dybvig. Fast and effective procedure inlining. In SAS '97, LNCS. Springer-Verlag, 1997, pp. 35--52. Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. Weeks, S. Whole program compilation in MLton. Invited talk at ML '06 Workshop, September 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Practical and effective higher-order optimizations

    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

    • Published in

      cover image ACM SIGPLAN Notices
      ACM SIGPLAN Notices  Volume 49, Issue 9
      ICFP '14
      September 2014
      361 pages
      ISSN:0362-1340
      EISSN:1558-1160
      DOI:10.1145/2692915
      Issue’s Table of Contents
      • cover image ACM Conferences
        ICFP '14: Proceedings of the 19th ACM SIGPLAN international conference on Functional programming
        August 2014
        390 pages
        ISBN:9781450328739
        DOI:10.1145/2628136

      Copyright © 2014 ACM

      Publisher

      Association for Computing Machinery

      New York, NY, United States

      Publication History

      • Published: 19 August 2014

      Check for updates

      Qualifiers

      • research-article

    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!