在 SSA 编译器中间表示中验证窥孔重写
Verifying Peephole Rewriting In SSA Compiler IRs
AI总结:
本文在 Lean 中形式化了一个通用的基于 SSA 的 IR 核心演算,并结合自动化策略与交互式定理证明,为 MLIR 生态系统中领域特定 IR 的窥孔重写提供形式化验证框架,通过位向量、结构化控制流和全同态加密三个用例验证了其有效性。
摘要:
现代编译器对领域特定推理的需求日益增长,这推动了基于静态单赋值(SSA)的定制中间表示(IR)的使用,例如 MLIR 编译器框架中的 IR。交互式定理证明器(ITP)为编译器的端到端验证提供了强有力的保证(例如 CompCert)。然而,现代编译器及其 IR 的演化速度使得与之同步进行证明工程的成本高得令人望而却步。尽管如此,范围明确的一键式自动化验证工具(例如用于 LLVM-IR 的 Alive 窥孔验证器)在 SMT 求解器能够提供高效(半)决策过程的领域中获得了认可。在本文中,我们旨在将自动化的便利性与 ITP 的多功能性结合起来,以验证跨领域特定 IR 的窥孔重写。我们形式化了一个基于 SSA 的 IR 核心演算,该演算对 IR 是通用的,并涵盖了所谓的区域(region,即 MLIR 生态系统中许多领域特定 IR 使用的嵌套作用域)。我们在 Lean 证明助手中的机械化实现提供了一个用户友好的前端,用于将 MLIR 语法翻译到我们的演算中。我们为定义和验证窥孔重写提供了脚手架,并提供了策略来消除我们 SSA 演算的抽象开销。我们证明了关于窥孔重写的正确性定理,以及两个经典的程序变换。为了评估我们的框架,我们考虑了来自 MLIR 生态系统的三个用例,它们涵盖了不同的抽象层次:(1)来自 LLVM 的位向量重写,(2)结构化控制流,以及(3)全同态加密。我们设想,我们的机械化实现为在新的领域特定 IR 上进行形式化验证的重写提供了基础。
英文摘要:
There is an increasing need for domain-specific reasoning in modern compilers. This has fueled the use of tailored intermediate representations (IRs) based on static single assignment (SSA), like in the MLIR compiler framework. Interactive theorem provers (ITPs) provide strong guarantees for the end-to-end verification of compilers (e.g., CompCert). However, modern compilers and their IRs evolve at a rate that makes proof engineering alongside them prohibitively expensive. Nevertheless, well-scoped push-button automated verification tools such as the Alive peephole verifier for LLVM-IR gained recognition in domains where SMT solvers offer efficient (semi) decision procedures. In this paper, we aim to combine the convenience of automation with the versatility of ITPs for verifying peephole rewrites across domain-specific IRs. We formalize a core calculus for SSA-based IRs that is generic over the IR and covers so-called regions (nested scoping used by many domain-specific IRs in the MLIR ecosystem). Our mechanization in the Lean proof assistant provides a user-friendly frontend for translating MLIR syntax into our calculus. We provide scaffolding for defining and verifying peephole rewrites, offering tactics to eliminate the abstraction overhead of our SSA calculus. We prove correctness theorems about peephole rewriting, as well as two classical program transformations. To evaluate our framework, we consider three use cases from the MLIR ecosystem that cover different levels of abstractions: (1) bitvector rewrites from LLVM, (2) structured control flow, and (3) fully homomorphic encryption. We envision that our mechanization provides a foundation for formally verified rewrites on new domain-specific IRs.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。