skip to main content
10.1145/2628136.2628153acmconferencesArticle/Chapter ViewAbstractPublication PagesicfpConference Proceedingsconference-collections
research-article

Practical and effective higher-order optimizations

Published: 19 August 2014 Publication History

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

Cited By

View all
  • (2023)Better Defunctionalization through Lambda Set SpecializationProceedings of the ACM on Programming Languages10.1145/35912607:PLDI(977-1000)Online publication date: 6-Jun-2023
  • (2021)Newly-single and loving it: improving higher-order must-alias analysis with heap fragmentsProceedings of the ACM on Programming Languages10.1145/34736015:ICFP(1-28)Online publication date: 19-Aug-2021
  • (2019)Staged abstract interpreters: fast and modular whole-program analysis via meta-programmingProceedings of the ACM on Programming Languages10.1145/33605523:OOPSLA(1-32)Online publication date: 10-Oct-2019
  • Show More Cited By

Recommendations

Comments

Information & Contributors

Information

Published In

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
Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

Sponsors

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 19 August 2014

Permissions

Request permissions for this article.

Check for updates

Author Tags

  1. control-flow analysis
  2. inlining
  3. optimization

Qualifiers

  • Research-article

Funding Sources

Conference

ICFP'14
Sponsor:

Acceptance Rates

ICFP '14 Paper Acceptance Rate 28 of 85 submissions, 33%;
Overall Acceptance Rate 333 of 1,064 submissions, 31%

Upcoming Conference

ICFP '25
ACM SIGPLAN International Conference on Functional Programming
October 12 - 18, 2025
Singapore , Singapore

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)11
  • Downloads (Last 6 weeks)1
Reflects downloads up to 13 Dec 2024

Other Metrics

Citations

Cited By

View all
  • (2023)Better Defunctionalization through Lambda Set SpecializationProceedings of the ACM on Programming Languages10.1145/35912607:PLDI(977-1000)Online publication date: 6-Jun-2023
  • (2021)Newly-single and loving it: improving higher-order must-alias analysis with heap fragmentsProceedings of the ACM on Programming Languages10.1145/34736015:ICFP(1-28)Online publication date: 19-Aug-2021
  • (2019)Staged abstract interpreters: fast and modular whole-program analysis via meta-programmingProceedings of the ACM on Programming Languages10.1145/33605523:OOPSLA(1-32)Online publication date: 10-Oct-2019
  • (2018)Compiling with Continuations and LLVMElectronic Proceedings in Theoretical Computer Science10.4204/EPTCS.285.5285(131-142)Online publication date: 31-Dec-2018
  • (2017)A posteriori environment analysis with Pushdown Delta CFAACM SIGPLAN Notices10.1145/3093333.300989952:1(19-31)Online publication date: 1-Jan-2017
  • (2017)A posteriori environment analysis with Pushdown Delta CFAProceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages10.1145/3009837.3009899(19-31)Online publication date: 1-Jan-2017
  • (2017)Relative Store Fragments for Singleton AbstractionStatic Analysis10.1007/978-3-319-66706-5_6(106-127)Online publication date: 19-Aug-2017
  • (2015)Control Flow Analysis for SF Combinator CalculusElectronic Proceedings in Theoretical Computer Science10.4204/EPTCS.199.4199(51-67)Online publication date: 7-Dec-2015
  • (2021)Newly-single and loving it: improving higher-order must-alias analysis with heap fragmentsProceedings of the ACM on Programming Languages10.1145/34736015:ICFP(1-28)Online publication date: 19-Aug-2021

View Options

Login options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Media

Figures

Other

Tables

Share

Share

Share this Publication link

Share on social media