一句话:通过大幅缩减搜索空间的最优内联穷举分析,揭示LLVM与最优内联的差距,并提出平均提升7%的自动调优内联策略。
函数内联是优化编译器的核心变换,但判断哪些内联决策有利十分困难,已有工作主要设计启发式,未系统研究最优内联。本文在 SPEC2017 上对最优内联进行实证分析:提出一种新形式化,将内联搜索空间从 2349 大幅缩减至 225,从而能对 1,135 个文件穷举评估所有内联选择。分析显示,以二进制大小为优化目标时,LLVM 最先进策略与最优内联存在显著差距。受此启发,作者提出一种简单有效的内联自动调优策略,在 SPEC2017 上平均优于最先进方法 7%(最高 28%),在 LLVM 自身源码上提升 15%,在 SQLite 源码上提升 10%。
Inlining is a core transformation in optimizing compilers. It replaces a function call (call site) with the body of the called function (callee). It helps reduce function call overhead and binary size, and more importantly, enables other optimizations. The problem of inlining has been extensively studied, but it is far from being solved; predicting which inlining decisions are beneficial is nontrivial due to interactions with the rest of the compiler pipeline. Previous work has mainly focused on designing heuristics for better inlining decisions and has not investigated optimal inlining, i.e., exhaustively finding the optimal inlining decisions. Optimal inlining is necessary for identifying and exploiting missed opportunities and evaluating the state of the art. This paper fills this gap through an extensive empirical analysis of optimal inlining using the SPEC2017 benchmark suite. Our novel formulation drastically reduces the inlining search space size (from 2349 down to 225) and allows us to exhaustively evaluate all inlining choices on 1,135 SPEC2017 files. We show a significant gap between the state-of-the-art strategy in LLVM and optimal inlining when optimizing for binary size, an important, deterministic metric independent of workload (in contrast to performance, another important metric). Inspired by our analysis, we introduce a simple, effective autotuning strategy for inlining that outperforms the state of the art by 7% on average (and up to 28%) on SPEC2017, 15% on the source code of LLVM itself, and 10% on the source code of SQLite. This work highlights the importance of exploring optimal inlining by providing new, actionable insight and an effective autotuning strategy that is of practical utility.