Structural Operational Semantics for Control Flow Graph Machines

Compilers use control flow graph (CFG) representations of low-level programs because they are suited to program analysis and optimizations. However, formalizing the behavior and metatheory of CFG programs is non-trivial: CFG programs don't compose well, their semantics depends on auxiliary state, and, as a consequence, they do not enjoy a simple equational theory that can be used for reasoning about the correctness of program transformations. Lambda-calculus-based intermediate representations, in contrast, have well-understood operational semantics and metatheory, including rich equational theories, all of which makes them amenable to formal verification. This paper establishes a tight equivalence between (a variant of) Levy's call-by-push-value (CBPV) calculus and a control flow graph machine whose instructions are in static single assignment (SSA) form. The correspondence is made precise via a series of abstract machines that align the transitions of the structural operational semantics of the CBPV language with the computation steps of the SSA form. The target machine, which is derived from the CBPV language, accurately captures the execution model of control flow graphs, including direct jumps, mutually recursive code blocks, and multi-argument function calls, and the closure-free subset is similar to the SSA intermediate representations found in modern compilers such as LLVM and GCC. The definitions of all the language/abstract machine semantics and the theorems relating them are fully verified in Coq.

[1]  Olivier Danvy,et al.  A functional correspondence between evaluators and abstract machines , 2003, PPDP '03.

[2]  Mark N. Wegman,et al.  Efficiently computing static single assignment form and the control dependence graph , 1991, TOPL.

[3]  Mitchell Wand,et al.  Selective and lightweight closure conversion , 1994, POPL '94.

[4]  Manuel M. T. Chakravarty,et al.  A Functional Perspective on SSA Optimisation Algorithms , 2004, COCV@ETAPS.

[5]  Ramana Kumar,et al.  CakeML: a verified implementation of ML , 2014, POPL.

[6]  Gordon D. Plotkin,et al.  A structural approach to operational semantics , 2004, J. Log. Algebraic Methods Program..

[7]  Olivier Danvy,et al.  From Interpreter to Compiler and Virtual Machine: A Functional Derivation , 2003 .

[8]  Dale Miller,et al.  From operational semantics to abstract machines: preliminary results , 1990, LISP and Functional Programming.

[9]  Paul Blain Levy,et al.  Call-by-Push-Value: A Subsuming Paradigm , 1999, TLCA.

[10]  Andrew Kennedy,et al.  Compiling with continuations, continued , 2007, ICFP '07.

[11]  Olivier Danvy,et al.  Defunctionalized interpreters for programming languages , 2008, ICFP.

[12]  Benjamin C. Pierce,et al.  Advanced Topics In Types And Programming Languages , 2004 .

[13]  Xavier Leroy,et al.  A Formally Verified Compiler Back-end , 2009, Journal of Automated Reasoning.

[14]  Gert Smolka,et al.  A First-Order Functional Intermediate Language for Verified Compilers , 2015, ArXiv.

[15]  Richard Kelsey,et al.  A correspondence between continuation passing style and static single assignment form , 1995, IR '95.

[16]  Kenneth MacKenzie,et al.  Grail: a functional form for imperative mobile code , 2003, Electron. Notes Theor. Comput. Sci..

[17]  Stephen Weeks,et al.  Contification using dominators , 2001, ICFP '01.

[18]  Alfred V. Aho,et al.  Compilers: Principles, Techniques, and Tools , 1986, Addison-Wesley series in computer science / World student series edition.

[19]  Søren B. Lassen,et al.  A complete, co-inductive syntactic theory of sequential control and state , 2007, POPL '07.

[20]  Matthias Felleisen,et al.  Control operators, the SECD-machine, and the λ-calculus , 1987, Formal Description of Programming Concepts.

[21]  Jens Palsberg,et al.  Semantics and Algebraic Specification, Essays Dedicated to Peter D. Mosses on the Occasion of His 60th Birthday , 2009, Semantics and Algebraic Specification.

[22]  John H. Reppy Local CPS conversion in a direct-style compiler (extended abstract) , 2000 .

[23]  Andrew W. Appel,et al.  Shrinking lambda Expressions in Linear Time , 1997, J. Funct. Program..

[24]  Andrew W. Appel,et al.  Compiling with Continuations , 1991 .

[25]  Lasse R. Nielsen,et al.  Refocusing in Reduction Semantics , 2004 .

[26]  Andrew M. Pitts,et al.  Operational Semantics and Program Equivalence , 2000, APPSEM.

[27]  Mitchell Wand From interpreter to compiler: a representational derivation , 1985, Programs as Data Objects.

[28]  Steven S. Muchnick,et al.  Advanced Compiler Design and Implementation , 1997 .

[29]  Olivier Danvy A Journey from Interpreters to Compilers and Virtual Machines , 2003, GPCE.