paperbot · PL 论文追踪

全部论文 待读 收藏

P2 A New Approach to Optimal Function Inlining for Code Size Minimization via E-graphs

基于 E-graph 的代码体积最小化最优函数内联新方法
OOPSLA 10(OOPSLA2)2026匹配度 3/10 · 论文属于编译优化与E-graph/等式饱和方向,关注函数内联和代码体积最小化,虽具备理论形式化与工程实现,但未涉及LLM/Agent、ML系统静态分析、浮点程序分析或贝叶斯程序分析等画像核心交叉方向。引用 1 inbox
Amir K. Goharshady, Chun Kit Lam, Andreas Pavlogiannis, Ahmed Khaled Zaher
crossref: 2026-10-02

AI 速览

一句话:将最优函数内联归约为 E-graph 提取,提出代码体积优化算法,比现有调优法快 20 倍且可互补。

函数内联可减少代码体积,但内联决策并非独立:局部启发式会错过死函数消除机会,而现有全局调优方法逐个调用点独立分析,难以发现组合收益。本文证明面向代码体积最小化的最优函数内联是 NP-hard,并提出基于 E-graph 的新方法,将其归约为 E-graph 提取问题;虽然提取本身也是 NP-hard,但稀疏实例已有高效求解器。作者在求解器基础上加入内联专用启发式,在 SPEC 基准上评估:代码体积降至 LLVM 的 95.34%,与 ASPLOS 2022 最优调优法的 95.24% 接近,运行时间快 20 倍;由于两种方法优势正交,结合使用可进一步降至 LLVM 的 93.94%。

问题
代码体积最小化中的函数内联具有全局依赖,现有局部启发式和独立调用点调优会错过死函数消除或组合优化机会;本文证明该最优内联问题是 NP-hard。
方法
将最优函数内联归约为 E-graph 提取,基于面向稀疏实例的高效提取求解器,并加入内联专用启发式来设计代码体积优化算法。
评估
在标准 SPEC 基准上与 LLVM 及 ASPLOS 2022 自动调优法比较:本方法达到 LLVM 的 95.34% 代码体积,接近 95.24%,运行快 20 倍,且与调优法结合可降至 93.94%。
原文摘要(Abstract)

Minimizing code size is a central problem in compiler optimization, especially in the context of embedded systems and mobile applications. One of the classical optimizations that has recently been adopted to reduce the output code size is function inlining, i.e. repeatedly replacing a function call site by the body of the called function. At first glance, the fact that inlining can help reduce code size is counter-intuitive. However, it enables two types of subsequent optimizations which can affect the code size significantly: (i) the intra-procedural optimizations performed within each function, which make use of the additional context provided by inlining, and (ii) the elimination of dead functions. Many existing heuristics, such as those used by LLVM, focus on a local size analysis based on a few call sites. Thus, they miss the global opportunities to remove dead functions. On the other hand, the current state-of-the-art approach of auto-tuning by Theodoridis et al. [ASPLOS 2022] focuses on global code size but inspects each call site independently in order to avoid a combinatorial explosion. However, inlining decisions are not independent in practice. It is possible that two inlining choices each increase code size on their own, but applying both of them together reduces the size. In this work, we show that the problem of optimal inlining for code size minimization is NP-hard. We then present a completely different approach to this problem. Our algorithm is based on equality graphs (e-graphs), which are a standard tool in automated theorem proving and have recently been adopted by the compiler optimization community as a key ingredient in equality saturation. We show that optimal function inlining can be reduced to e-graph extraction. Although e-graph extraction is also NP-hard, there are efficient solvers that can handle sparse instances of this problem [OOPSLA 2024]. We build upon these solvers and add further inlining-specific heuristics to design an algorithm for code size reduction. Finally, we present experimental results on the standard SPEC benchmarks. Compared with LLVM, our approach reduces the code size to 95.34%. This is competitive with the state-of-the-art auto-tuning method of [ASPLOS 2022], which achieves 95.24%. In terms of running time, our approach is 20x faster than auto-tuning. More importantly, due to the two methods having orthogonal strengths, applying both of them leads to a further significant improvement, reducing the code size to 93.94% of LLVM's output.

链接与引用

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

BibTeX
@article{paperbot12110,
  title = {A New Approach to Optimal Function Inlining for Code Size Minimization via E-graphs},
  author = {Amir K. Goharshady and Chun Kit Lam and Andreas Pavlogiannis and Ahmed Khaled Zaher},
  journal = {Proceedings of the ACM on Programming Languages},
  volume = {10},
  number = {OOPSLA2},
  year = {2026},
  doi = {10.1145/3839499}
}