skip to main content
10.1145/3578360.3580270acmconferencesArticle/Chapter ViewAbstractPublication PagesccConference Proceedingsconference-collections
research-article

Lazy Evaluation for the Lazy: Automatically Transforming Call-by-Value into Call-by-Need

Published: 17 February 2023 Publication History

Abstract

This paper introduces lazification, a code transformation technique that replaces strict with lazy evaluation of function parameters whenever such modification is deemed profitable. The transformation is designed for an imperative, low-level program representation. It involves a static analysis to identify function calls that are candidates for lazification, plus the generation of closures to be lazily activated. Code extraction uses an adaptation of the classic program slicing technique adjusted for the static single assignment representation. If lazification is guided by profiling information, then it can deliver speedups even on traditional benchmarks that are heavily optimized. We have implemented lazification on LLVM 14.0, and have applied it on the C/C++ programs from the LLVM test-suite and from SPEC CPU2017. We could observe statistically significant speedups over clang -O3 on some large programs, including a speedup of 11.1% on Prolang's Bison without profiling support and a speedup of 4.6% on SPEC CPU2017's perlbench (one of the largest programs in the SPEC collection) with profiling support.

References

[1]
Gagan Agrawal, Joel Saltz, and Raja Das. 1995. Interprocedural Partial Redundancy Elimination and Its Application to Distributed Memory Compilation. In PLDI. ACM, New York, NY, USA. 258–269. https://doi.org/10.1145/207110.207157
[2]
Andrei Alexandrescu. 2010. The D programming language. Addison-Wesley, Bostom, MA, US.
[3]
Andrew W. Appel and Jens Palsberg. 2003. Modern Compiler Implementation in Java (2nd ed.). Cambridge University Press, USA. isbn:052182060X
[4]
John W Backus, Friedrich L Bauer, Julien Green, Charles Katz, John McCarthy, Alan J Perlis, Heinz Rutishauser, Klaus Samelson, Bernard Vauquois, and Joseph Henry Wegstein. 1960. Report on the algorithmic language ALGOL 60. Commun. ACM, 3, 5 (1960), 299–314.
[5]
David W. Binkley and Keith Brian Gallagher. 1996. Program Slicing. In Advances in Computers, Marvin V. Zelkowitz (Ed.). 43, Elsevier, Amsterdam, The Netherlands. 1–50. issn:0065-2458 https://doi.org/10.1016/S0065-2458(08)60641-5
[6]
Edwin C. Brady. 2013. Idris, a general-purpose dependently typed programming language: Design and implementation. J. Funct. Program., 23, 5 (2013), 552–593. https://doi.org/10.1017/S095679681300018X
[7]
Edwin C. Brady. 2013. Idris: General Purpose Programming with Dependent Types. In PLPV. ACM, New York, NY, USA. 1–2. isbn:9781450318600 https://doi.org/10.1145/2428116.2428118
[8]
Zoran Budimlic, Keith D. Cooper, Timothy J. Harvey, Ken Kennedy, Timothy S. Oberg, and Steven W. Reeves. 2002. Fast Copy Coalescing and Live-Range Identification. In PLDI. ACM, New York, NY, USA. 25–32. isbn:1581134630 https://doi.org/10.1145/512529.512534
[9]
Geoffrey L. Burn, Chris Hankin, and Samson Abramsky. 1986. Strictness Analysis for Higher-Order Functions. Sci. Comput. Program., 7, C (1986), jun, 249–278. issn:0167-6423 https://doi.org/10.1016/0167-6423(86)90010-9
[10]
John M. Chambers. 2020. S, R, and Data Science. Proc. ACM Program. Lang., 4, HOPL (2020), Article 84, jun, 17 pages. https://doi.org/10.1145/3386334
[11]
Stephen Chang. 2013. Laziness by Need. In ESOP. Springer-Verlag, Berlin, Heidelberg. 81–100. isbn:9783642370359 https://doi.org/10.1007/978-3-642-37036-6_5
[12]
Stephen Chang and Matthias Felleisen. 2012. The Call-by-Need Lambda Calculus, Revisited. In ESOP. Springer-Verlag, Berlin, Heidelberg. 128–147. isbn:9783642288685 https://doi.org/10.1007/978-3-642-28869-2_7
[13]
Stephen Chang and Matthias Felleisen. 2014. Profiling for Laziness. SIGPLAN Not., 49, 1 (2014), jan, 349–360. issn:0362-1340 https://doi.org/10.1145/2578855.2535887
[14]
Yishen Chen, Charith Mendis, and Saman Amarasinghe. 2022. All You Need is Superword-Level Parallelism: Systematic Control-Flow Vectorization with SLP. In PLDI. ACM, New York, NY, USA. 301–315. isbn:9781450392655 https://doi.org/10.1145/3519939.3523701
[15]
Chris Clack and Simon L. Peyton Jones. 1985. Strictness analysis — a practical approach. In Functional Programming Languages and Computer Architecture, Jean-Pierre Jouannaud (Ed.). Springer Berlin Heidelberg, Berlin, Heidelberg. 35–49. isbn:978-3-540-39677-2
[16]
R. Cytron, J. Ferrante, B. K. Rosen, M. N. Wegman, and F. K. Zadeck. 1989. An Efficient Method of Computing Static Single Assignment Form. In POPL. ACM, New York, NY, USA. 25–35. isbn:0897912942 https://doi.org/10.1145/75277.75280
[17]
Jeanne Ferrante, Karl J. Ottenstein, and Joe D. Warren. 1987. The Program Dependence Graph and Its Use in Optimization. ACM Trans. Program. Lang. Syst., 9, 3 (1987), 319–349. issn:0164-0925 https://doi.org/10.1145/24039.24041
[18]
Breno Campos Ferreira Guimaraes. 2022. Automatically Transforming Call-by-Value into Call-by-Need. Master’s thesis. Universidade Federal de Minas Gerais.
[19]
Anders Hejlsberg, Mads Torgersen, Scott Wiltamuth, and Peter Golde. 2008. The C# programming language. Pearson Education, Hoboken, NJ, USA.
[20]
Yann Herklotz, Delphine Demange, and Sandrine Blazy. 2023. Mechanised Semantics for Gated Static Single Assignment. In CPP. ACM, New York, NY, USA. 1–15. https://doi.org/10.1145/3573105.3575681
[21]
Paul Hudak, John Hughes, Simon Peyton Jones, and Philip Wadler. 2007. A History of Haskell: Being Lazy with Class. In HOPL. ACM, New York, NY, USA. 12–1–12–55. isbn:9781595937667 https://doi.org/10.1145/1238844.1238856
[22]
Apple Inc. 2021. The Swift Programming Language. Apple Inc., Cupertino, CA, USA.
[23]
T.-M. Kuo and P. Mishra. 1987. On Strictness and Its Analysis. In POPL. ACM, New York, NY, USA. 144–155. isbn:0897912152 https://doi.org/10.1145/41625.41638
[24]
Chris Lattner and Vikram Adve. 2004. LLVM: A Compilation Framework for Lifelong Program Analysis and Transformation. In CGO. IEEE Computer Society, USA. 75. isbn:0769521029
[25]
Bruce J MacLennan. 1986. Principles of programming languages: design, evaluation, and implementation. Holt, Rinehart & Winston, New York, NY, US.
[26]
Alan Mycroft. 1981. Abstract interpretation and optimising transformations for applicative programs. Ph. D. Dissertation. University of Edimburgh.
[27]
Karl J. Ottenstein, Robert A. Ballance, and Arthur B. MacCabe. 1990. The Program Dependence Web: A Representation Supporting Control-, Data-, and Demand-Driven Interpretation of Imperative Languages. In PLDI. ACM, New York, NY, USA. 257–271. isbn:0897913647 https://doi.org/10.1145/93542.93578
[28]
Henry Gordon Rice. 1953. Classes of recursively enumerable sets and their decision problems. Trans. Amer. Math. Soc., 74, 2 (1953), 358–366. https://doi.org/10.2307/1990888
[29]
Lukas Stadler, Adam Welc, Christian Humer, and Mick Jordan. 2016. Optimizing R Language Execution via Aggressive Speculation. In DLS. ACM, New York, NY, USA. 84–95. isbn:9781450344456 https://doi.org/10.1145/2989225.2989236
[30]
Frank Tip. 1994. A Survey of Program Slicing Techniques. IBM T. J. Watson Research Center, NLD.
[31]
Peng Tu and David Padua. 1995. Efficient Building and Placing of Gating Functions. In PLDI. ACM, New York, NY, USA. 47–55. isbn:0897916972 https://doi.org/10.1145/207110.207115
[32]
David Turner. 1986. An overview of Miranda. ACM Sigplan Notices, 21, 12 (1986), 158–166.
[33]
Adriaan Van Wijngaarden, Barry J Mailloux, John EL Peck, Cornelius HA Koster, M Sintzoff, CH Lindsey, LGLT Meertens, and RG Fisker. 1969. Report on the algorithmic language ALGOL 68. Numer. Math., 14, 2 (1969), 79–218.
[34]
P. Wadler. 1988. Strictness Analysis Aids Time Analysis. In POPL. ACM, New York, NY, USA. 119–132. isbn:0897912527 https://doi.org/10.1145/73560.73571
[35]
Mark Weiser. 1984. Program Slicing. IEEE Transactions on Software Engineering, SE-10, 4 (1984), 352–357. https://doi.org/10.1109/TSE.1984.5010248
[36]
Baowen Xu, Ju Qian, Xiaofang Zhang, Zhongqiang Wu, and Lin Chen. 2005. A Brief Survey of Program Slicing. SIGSOFT Softw. Eng. Notes, 30, 2 (2005), mar, 1–36. issn:0163-5948 https://doi.org/10.1145/1050849.1050865
[37]
Guoqiang Zhang and Xipeng Shen. 2021. Best-Effort Lazy Evaluation for Python Software Built on APIs. In ECOOP (LIPIcs, Vol. 194). Schloss Dagstuhl, Leibniz-Zentrum für Informatik. 15:1–15:24. https://doi.org/10.4230/LIPIcs.ECOOP.2021.15
[38]
Yingzhou Zhang. 2021. SymPas: Symbolic Program Slicing. J. Comput. Sci. Technol., 36, 2 (2021), 397–418. https://doi.org/10.1007/s11390-020-9754-4
[39]
Peng Zhao and Jose Nelson Amaral. 2005. Function Outlining and Partial Inlining. In SBAC-PAD. IEEE Computer Society, USA. 101–108. isbn:076952446X https://doi.org/10.1109/CAHPC.2005.26

Cited By

View all

Index Terms

  1. Lazy Evaluation for the Lazy: Automatically Transforming Call-by-Value into Call-by-Need

    Recommendations

    Comments

    Information & Contributors

    Information

    Published In

    cover image ACM Conferences
    CC 2023: Proceedings of the 32nd ACM SIGPLAN International Conference on Compiler Construction
    February 2023
    249 pages
    ISBN:9798400700880
    DOI:10.1145/3578360
    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 the author(s) 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: 17 February 2023

    Permissions

    Request permissions for this article.

    Check for updates

    Author Tags

    1. code transformation
    2. lazy evaluation

    Qualifiers

    • Research-article

    Funding Sources

    Conference

    CC '23
    Sponsor:

    Contributors

    Other Metrics

    Bibliometrics & Citations

    Bibliometrics

    Article Metrics

    • 0
      Total Citations
    • 200
      Total Downloads
    • Downloads (Last 12 months)92
    • Downloads (Last 6 weeks)8
    Reflects downloads up to 14 Sep 2024

    Other Metrics

    Citations

    Cited By

    View all

    View Options

    Get Access

    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