Skip to main content
QUICK REVIEW

[论文解读] Structural Operational Semantics for Control Flow Graph Machines

Dmitri Garbuzov, William Mansky|arXiv (Cornell University)|May 14, 2018
Logic, programming, and type systems参考文献 18被引用 3
一句话总结

本文建立了 Levy 的推导-按值传递(CBPV)演算与以静态单赋值(SSA)形式运行的控制流图(CFG)机器之间的紧密、形式化验证的等价性。通过将 CBPV 的结构操作语义(SOS)转换与 CFG 执行步骤对齐,证明了 SSA CFG 与 CBPV 项等价,从而支持等式推理,并可通过高阶语言理论对低级优化进行形式化验证。

ABSTRACT

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.

研究动机与目标

  • 解决编译器中使用的控制流图(CFG)程序缺乏组合性、等式推理的问题。
  • 克服 CFG 在形式验证中因非组合结构、辅助状态和弱等式理论带来的局限性。
  • 在理解透彻的高阶操作语义(CBPV)与实际的低级中间表示(SSA CFG)之间建立正式桥梁。
  • 通过 CBPV 丰富的等式理论,实现对 CFG 级优化的机器可检查正确性证明。
  • 为可验证编译提供基础,表明 SSA CFG 与 CBPV 项在保持所有可观测行为的前提下是等价的。

提出的方法

  • 定义 Levy 的推导-按值传递(CBPV)演算的一个变体,配备结构操作语义(SOS),以支持组合性、等式推理。
  • 设计一种虚拟机,以静态单赋值(SSA)形式执行指令,建模直接跳转、多参数函数调用和互递归代码块。
  • 构建一系列中间抽象机器,逐步将静态可计算的约化与动态执行步骤分离。
  • 通过一系列形式推导,证明 CBPV SOS 转换与 CFG 机器执行步骤之间的逐步对应关系。
  • 在 Coq 中完全验证所有语义定义与等价定理,确保机器可检查的正确性。
  • 证明每个合法的 SSA CFG 均可唯一对应一个 CBPV 项,反之亦然,且该映射保持操作行为不变。

实验结果

研究问题

  • RQ1能否利用高阶语言理论,为控制流图(CFG)建立形式化、组合性的操作语义?
  • RQ2CBPV 的结构操作语义与 SSA 形 CFG 机器之间是否存在精确、可机器检查的对应关系?
  • RQ3能否通过对其对应 CBPV 项的推理,对 SSA CFG 上的程序变换进行形式化验证?
  • RQ4CBPV 与 SSA CFG 之间的等价性是否支持一个稳健的等式理论,以用于优化正确性的推理?
  • RQ5CFG 机器的无闭包子集能否准确建模现代编译器中间表示(如 LLVM 和 GCC 中的中间表示)?

主要发现

  • 建立了 CBPV 的结构操作语义与 SSA 形 CFG 机器之间的紧密、形式化验证的等价性,CBPV 约化的每一步均精确对应于机器指令的执行。
  • CFG 机器的无闭包片段与现代编译器(如 LLVM 和 GCC)使用的 SSA 中间表示同构。
  • 所有应用于 CFG 的优化,包括常量折叠、无用代码消除和相同分支简化,均通过底层 CBPV 等式理论被形式化证明为正确。
  • 该对应关系强于编译器正确性:它不仅保持了轨迹等价性或 bisimilarity,还保留了所有可观测等价性。
  • 从 CBPV 项到 SSA CFG 的映射是双射,意味着每个合法的 CFG 均唯一对应一个 CBPV 项,反之亦然。
  • 整个形式化过程,包括语义定义与等价定理,均在 Coq 中完全验证,支持对程序变换正确性的机器可检查证明。

更好的研究,从现在开始

从阅读论文到最终审阅,大幅缩短您的研究时间。

无需绑定信用卡

本解读由 AI 生成,并经人工编辑审核。