Advertisement

Higher-Order and Symbolic Computation

, Volume 17, Issue 3, pp 173–206 | Cite as

Compiler Optimization Correctness by Temporal Logic

  • David Lacey
  • Neil D. Jones
  • Eric Van Wyk
  • Carl Christian Frederiksen
Open Access
Article

Abstract

Rewrite rules with side conditions can elegantly express many classical compiler optimizations for imperative programming languages. In this paper, programs are written in an intermediate language and transformation-enabling side conditions are specified in a temporal logic suitable for describing program data flow.

The purpose of this paper is to show how such transformations may be proven correct. Our methodology is illustrated by three familiar optimizations: dead code elimination, constant folding, and code motion. A transformation is correct if whenever it can be applied to a program, the original and transformed programs are semantically equivalent, i.e., they compute the same input-output function. The proofs of semantic equivalence inductively show that a transformation-specific bisimulation relation holds between the original and transformed program computations.

compiler verification optimizing compilers temporal logic model checking 

References

  1. 1.
    Abramsky, S. and Hankin, C. Abstract Interpretation of Declarative Languages. Ellis-Horwood, 1987.Google Scholar
  2. 2.
    Aho, A.V., Sethi, R., and Ullman, J.D. Compilers: Principles, Techniques, and Tools. Addison Wesley, 1986.Google Scholar
  3. 3.
    Assmann, U. How to uniformly specify program analysis and transformation. In Proc. 6th International Conference on Compiler Construction (CC'96), vol. 1060 of Lecture Notes in Computer Science, Springer-Verlag, 1996, pp. 121-135.Google Scholar
  4. 4.
    Clarke, E.M., Emerson, E.A., and Sistla, A.P. Automatic verification of finite-state concurrent systems using temporal logic specifications. ACM Transactions on Programming Languages and Systems (TOPLAS), 8(2) (1986) 244-263.Google Scholar
  5. 5.
    Cleaveland, R. and Jackson, D. In Proceedings of First ACM SIGPLAN Workshop on Automated Analysis of Software. Paris, France, Jan. 1997.Google Scholar
  6. 6.
    Cousot, P. Semantic foundations of program analysis. In Program Flow Analysis: Theory and Applications, S.S. Muchnick and N.D. Jones (Eds.), Englewood Cliffs, NJ, Prentice Hall, 1981, chap. 10, pp. 303-342.Google Scholar
  7. 7.
    Cousot, P. and Cousot, R. Abstract interpretation: A unified lattice model for static analysis of programs by construction or approximation of fix-points. In Fourth ACM Symposium on Principles of Programming Languages, Los Angeles, California, January 1977, New York, ACM, 1977, pp. 238-252.Google Scholar
  8. 8.
    Cousot, P. and Cousot, R. Systematic design of program transformations by abstract interpretation. In Proc. of 29th ACM Symposium on Principles of Programming Languages, ACM, 2000, pp. 178-190.Google Scholar
  9. 9.
    Cousot, P. and Cousot, R. Systematic design of program transformation frameworks by abstract interpretation. In Proc. of the 29th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, Portland, Oregon, ACM Press, 2002, pp. 178-190.Google Scholar
  10. 10.
    Frederiksen, C.C. Correctness of classical compiler optimizations using CTL. Unpublished TOPPS report, University of Copenhagen, 2001. www.diku.dk/research-groups/topps/bibliography/2001.html#D-443.Google Scholar
  11. 11.
    Frederiksen, C.C. Correctness of classical compiler optimizations using CTL logic. In Compiler Optimization meets Compiler Verification (COCV), Satellite workshop at ETAPS 2002.Google Scholar
  12. 12.
    Hafer, Th. and Thomas, W. Computation tree logic CTL* and path quantifiers in the monadic theory of the binary tree. In Automata, Languages and Programming Proceedings, ICALP'87, vol. 267 of Lecture Notes in Computer Science, Springer-Verlag, 1987, pp. 267-279.Google Scholar
  13. 13.
    Havelund, K. Stepwise Development of a Denotational Stack Semantics. M.Sc. thesis, University of Copenhagen, 1984.Google Scholar
  14. 14.
    Hecht, M. Flow Analysis of Computer Programs. North-Holland, 1977.Google Scholar
  15. 15.
    Jones, N.D. (Ed.), Semantics-Directed Compiler Generation, vol. 94 of Lecture Notes in Computer Science, Springer-Verlag, 1980.Google Scholar
  16. 16.
    Jones, N.D. Semantique: Semantic-based program manipulation techniques. In Bulletin European Association for Theoretical Computer Science, 39 (1989) 74-83.Google Scholar
  17. 17.
    Jones, N.D. and Nielson, F. Abstract interpretation: A semantics-based tool for program analysis. In Handbook of Logic in Computer Science, S. Abramsky, D. Gabbay, and T. Maibaum (Eds.), Oxford University Press, 1994, pp. 527-629.Google Scholar
  18. 18.
    Knoop, J., Rüthing, O., and Steffen, B. Optimal code motion: Theory and practice. ACM Transactions on Programming Languages and Systems (TOPLAS), 16(4) (1994) 1117-1155.Google Scholar
  19. 19.
    Kozen, D. and Patron, M. Certification of compiler optimizations using Kleene algebra with tests. In Proceedings of the 1st International Conference on Computational Logic (CL2000), J. Lloyd, V. Dahl, U. Furbach, M. Kerber, K.-K. Lau, C. Palamidessi, L.M. Pereira, Y. Sagiv, and P.J. Stuckey (Eds.), Lecture Notes in Artificial Intelligence, vol. 1861, Springer-Verlag, London, 2000, pp. 568-582.Google Scholar
  20. 20.
    Kripke, S. Semantical analysis of modal logic i: Normal modal propositional calculi. Zeitschrift f. Math. Logik und Grundlagen d. Math., 9 (1963).Google Scholar
  21. 21.
    Kupferman, O. and Pnueli, A. Once and for all. In Proc. 10th IEEE Symposium on Logic in Computer Science, San Diego, 1995, pp. 25-35.Google Scholar
  22. 22.
    Lacey, D. Program transformation using temporal logic specification. DPhil Thesis (forthcoming). Oxford University Computing Laboratory, 2003.Google Scholar
  23. 23.
    Lacey, D. and de Moor, O. Imperative program transformation by rewriting. In Proc. 10th International Conf. on Compiler Construction, vol. 1113 of Lecture Notes in Computer Science, Springer-Verlag, 2001, pp. 52-68.Google Scholar
  24. 24.
    Lacey, D., Jones, N.D., Van Wyk, E. and Frederiksen, C.C. Proving correctness of compiler optimizations by temporal logic. In 29th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, 2002, pp. 283-294.Google Scholar
  25. 25.
    Lerner, S., Grove, D., and Chambers, C. Composing dataflow analyses and transformations. In 29th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, 2002, pp. 283-294.Google Scholar
  26. 26.
    Lerner, S., Millstein, T., and Chambers, C. Automatically proving correctness of compiler optimizations. Technical Report UW-CSE-02-11-02, University of Washington, 2002.Google Scholar
  27. 27.
    Milne, R. and Strachey, C. A Theory of Programming Language Semantics. Chapman and Hall, 1976.Google Scholar
  28. 28.
    Muchnick, S.S. Advanced Compiler Design and Implementation. Morgan Kaufmann, 1997.Google Scholar
  29. 29.
    Muchnick, S.S. and Jones, N.D. (Eds.), Program Flow Analysis: Theory and Applications. Englewood Cliffs, NJ, Prentice Hall, 1981.Google Scholar
  30. 30.
    Nielson, F. Semantic Foundations of Data Flow Analysis. M.Sc. thesis, Aarhus University, DAIMI PB-131, 1981Google Scholar
  31. 31.
    Nielson, F. A denotational framework for data flow analysis. Acta Informatica, 18 (1982) 265-287.Google Scholar
  32. 32.
    Nielson, F., Nielson, H.R., and Hankin, C. Principles of Program Analysis. Springer-Verlag, 1999.Google Scholar
  33. 33.
    Pinter, S.S. and Wolper, P. A temporal logic for reasoning about partially ordered computations. In Proc. 3rd ACM Symposium on Principles of Distributed Computing, 1984, pp. 28-37.Google Scholar
  34. 34.
    Podelski, A., Steffen, B., and Vardi, M. Schloss Ringberg Seminar: Model Checking and Program Analysis. Workshop, Feb. 2000, Bavaria.Google Scholar
  35. 35.
    Rus, T. and Van Wyk, E. Using model checking in a parallelizing compiler. Parallel Processing Letters, 8(4) (1998) 459-471.Google Scholar
  36. 36.
    Schmidt, D.A. Data-flow analysis is model checking of abstract interpretations. In Proc. of 25th ACM Symposium on Principles of Programming Languages, ACM, 1998.Google Scholar
  37. 37.
    Schmidt, D.A. and Steffen, B. Program analysis as model checking of abstract interpretations. In Proc. of 5th Static Analysis Symposium, G. Levi (Ed.), Pisa, vol. 1503 of Lecture Notes in Computer Science, Springer-Verlag, 1998.Google Scholar
  38. 38.
    SRI International. The PVS specification and verification system http://pvs.csl.sri.com/Google Scholar
  39. 39.
    Steckler, P.A. and Wand, M. Lightweight closure conversion. ACM Transactions on Programming Languages and Systems, ACM, 19(1) (1997) 48-86.Google Scholar
  40. 40.
    Steffen, B. Data flow analysis as model checking. In Proc. of 1st International Conference on Theoretical Aspects of Computer Software (TACS'91), Heidelberg, vol. 526 of Lecture Notes in Computer Science, Springer-Verlag, 1991, pp. 346-364.Google Scholar
  41. 41.
    Steffen, B. Generating data flow analysis algorithms from modal specifications. In Science of Computer Programming, 1993, vol. 21, pp. 115-139.Google Scholar
  42. 42.
    Steffen, B., Claßen, A., Klein, M., Knoop, J., and Margaria, T. The fixpoint analysis machine. In Proc. of the 6th International Conference on Concurrency Theory (CONCUR'95), J. Lee and S. Smolka (Eds.), Philadelphia, Pennsylvania (USA), vol. 962 of Lecture Notes in Computer Science, Springer-Verlag, 1995, pp. 72-87.Google Scholar
  43. 43.
    Visser, E., Benaissa, Z., and Tolmach, A. Building program optimizers with rewriting strategies. In Proc. of ACM SIGPLAN International Conference on Functional Programming (ICFP'98), ACM, 1998, pp. 13-26.Google Scholar
  44. 44.
    Whitfield, D. and Soffa, M.L. Automatic generation of global optimisers. In Proc. of ACM SIGPLAN on Program Language Design and Implementation (PLDI'91), ACM, 1991, pp. 120-129.Google Scholar
  45. 45.
    Whitfield, D. and Soffa, M.L. An approach for exploring code-improving transformations. In ACM Transactions on Programming Languages and Systems, ACM, 1997, vol. 19,no. 6, pp. 1053-1084.Google Scholar
  46. 46.
    Winskel, G. The Formal Semantics of Programming Languages. Boston, MA, the MIT Press, 1993.Google Scholar
  47. 47.
    Wolper, P. On the relation of programs and computations to models of temporal logic. In Proc. Temporal Logic in Specification, vol. 398 of Lecture Notes in Computer Science, Springer-Verlag, 1987, pp. 75-123.Google Scholar

Copyright information

© Kluwer Academic Publishers 2004

Authors and Affiliations

  • David Lacey
    • 1
  • Neil D. Jones
    • 2
  • Eric Van Wyk
    • 3
  • Carl Christian Frederiksen
    • 4
  1. 1.University of WarwickUK
  2. 2.University of CopenhagenDenmark
  3. 3.University of MinnesotaUSA
  4. 4.University of TokyoJapan

Personalised recommendations