paperbot · PL 论文追踪

全部论文 待读 收藏

P2 Beyond Relooper: recursive translation of unstructured control flow to structured control flow (functional pearl)

超越 Relooper:将非结构化控制流递归翻译为结构化控制流(函数式珍珠)
ICFP 6(ICFP)2022匹配度 2/10 · 该论文属于编译器与函数式编程领域,研究非结构化控制流到结构化控制流的翻译,与用户核心关注的 AI×PL、静态分析/形式化验证、浮点程序分析或贝叶斯程序分析没有直接交集。仅作为 PL/编译背景有很弱的关联,且不涉及 LLM/Agent 或机器学习系统。引用 5 inbox
Norman Ramsey
crossref: 2026-09-10

AI 速览

一句话:提出单趟递归算法,将任意控制流图翻译为结构化控制流,并计划集成到 GHC。

许多编译器用任意有向图表示过程内控制流,但 JavaScript、WebAssembly 等目标语言只允许由循环、条件与多级 break/exit 构成的结构化控制流。Peterson、Kasami 和 Tokura 在 1973 年给出了任意控制流到结构化控制流的翻译,但原始版本需三趟,可能因此被 Emscripten 忽视。本文调整标准控制流分析,并借助函数式编程的递归函数、不可变 AST 与支配树,将该翻译与若干代码改进合并为单趟实现。该实现计划加入 Glasgow Haskell Compiler,且其单趟翻译、不可变表示和支配树使用比原版更易推理。

问题
许多编译器以任意有向图表示过程内控制流,但 JavaScript/WebAssembly 等目标语言只支持结构化控制流;如何高效且可推理地完成非结构化到结构化的翻译是问题。
方法
调整标准控制流分析,并采用递归函数、不可变抽象语法树和支配树,将 Peterson-Kasami-Tokura 式翻译实现为单趟。
评估
以函数式实现和设计论证表明单趟、不可变表示与支配树使算法比原始三趟版本更易推理;实现计划加入 GHC,摘要未报告定量评估。
原文摘要(Abstract)

In many compilers, control flow is represented using an arbitrary directed graph. But in some interesting target languages, including JavaScript and WebAssembly, intraprocedural control flow can be expressed only in structured ways, using loops, conditionals, and multilevel breaks or exits. As was shown by Peterson, Kasami, and Tokura in 1973, such structured control flow can be obtained by translating arbitrary control flow. The translation uses two standard analyses, but as published, it takes three passes—which may explain why it was overlooked by Emscripten, a popular compiler from C to JavaScript. By tweaking the analyses and by applying fundamental ideas from functional programming (recursive functions and immutable abstract-syntax trees), the translation, along with a couple of code improvements, can be implemented in a single pass. This new implementation is slated to be added to the Glasgow Haskell Compiler. Its single-pass translation, its immutable representation, and its use of dominator trees make it much easier to reason about than the original translation.

链接与引用

DOI 原文 · PDF(开放获取) ·

BibTeX
@article{paperbot1509,
  title = {Beyond Relooper: recursive translation of unstructured control flow to structured control flow (functional pearl)},
  author = {Norman Ramsey},
  journal = {Proceedings of the ACM on Programming Languages},
  volume = {6},
  number = {ICFP},
  year = {2022},
  doi = {10.1145/3547621}
}