Finding the optimal pass sequence of compilation can lead to a significant reduction in program size and/or improvement in program efficiency. Prior works on compilation pass ordering have two major drawbacks. They either require an excessive budget (in terms of compilation steps) at compile time or fail to generalize to unseen programs. In this paper, for code-size reduction tasks, we propose a novel pipeline to find program-dependent pass sequences within 45 compilation calls. It first identifies a coreset of 50 pass sequences via greedy optimization of a submodular function, and then learns a policy with Graph Neural Network (GNN) to pick the optimal sequence by predicting the normalized values of the pass sequences in the coreset. Despite its simplicity, our pipeline outperforms the default -Oz flag by an average of 4.7% over a large collection (4683) of unseen code repositories from diverse domains across 14 datasets. In comparison, previous approaches like reinforcement learning on the raw pass sequence space may take days to train due to sparse reward, and may not generalize well in held-out ones from different domains. Our results demonstrate that existing human-designed compiler flags can be improved with a simple yet effective technique that transforms the raw action space into a small one with denser rewards.
翻译:寻找编译最优优化顺序能够显著减小程序尺寸并/或提升程序效率。先前关于编译优化排序的工作存在两大缺陷:要么在编译时需要过多开销(就编译步骤而言),要么无法泛化到未见过的程序。针对代码尺寸缩减任务,本文提出了一种新颖流程,可在45次编译调用内找到依赖程序的优化序列。该流程首先通过贪婪优化子模函数识别出50个优化序列构成的核心集,随后利用图神经网络(GNN)学习策略,通过预测核心集中优化序列的归一化值来选取最优序列。尽管方法简单,该流程在来自14个数据集、涵盖多领域的4683个未见代码仓库中,相较默认的-Oz编译标志平均实现了4.7%的改进。相比之下,基于原始优化序列空间的强化学习等方法可能因奖励稀疏而需数天训练,且难以良好泛化到不同领域的待测代码。我们的结果表明,通过将原始动作空间转换为奖励更密集的小型动作空间这一简单而有效的技术,可以改进现有的人工设计编译器标志。