Function merging is a pivotal technique for reducing code size by combining identical or similar functions into a single function. While prior research has extensively explored this technique, it has not been assessed in conjunction with function outlining and linker's identical code folding, despite substantial common ground. The traditional approaches necessitate the complete intermediate representation to compare functions. Consequently, none of these approaches offer a scalable solution compatible with separate compilations while achieving global function merging, which is critical for large app development. In this paper, we introduce our global function merger, leveraging global merge information from previous code generation runs to optimistically create merging instances within each module context independently. Notably, our approach remains sound even when intermediate representations change, making it well-suited for distributed build environments. We present a comprehensive code generation framework that can run both the state-of-the-art global function outliner and our global function merger. These components complement each other, resulting in a positive impact on code size reduction. Our evaluation demonstrates that when integrating the global function merger with a state-of-the-art global function outliner that is fully optimized with ThinLTO, a further reduction of up to 3.5% in code size can be attained. This is in addition to the initial average reduction of 17.3% achieved through global function outlining for real-world iOS apps, all with minimal extra build time.
翻译:函数合并是一种通过将相同或相似的函数合并为单一函数来减小代码量的关键技术。尽管已有研究对此技术进行了广泛探索,但尚未将其与函数外提及链接器的相同代码折叠技术结合评估,尽管三者存在大量共通之处。传统方法需要完整的中间表示来比较函数,因此无法提供一种既支持分离编译又实现全局函数合并的可扩展方案,而这对于大型应用程序开发至关重要。本文提出的全局函数合并器,利用先前代码生成阶段的全局合并信息,在每个模块上下文中独立创建合并实例。值得注意的是,即使中间表示发生变化,我们的方法依然保持正确性,因此非常适合分布式构建环境。我们提出了一套全面的代码生成框架,能够同时运行最先进的全局函数外提器与本文的全局函数合并器。这些组件相互补充,在代码量缩减方面产生积极影响。实验评估表明,当将全局函数合并器与经ThinLTO充分优化的最先进全局函数外提器集成时,代码量可进一步缩减高达3.5%。这一成果基于真实iOS应用中通过全局函数外提实现平均17.3%初始缩减的基础上,且仅需极少的额外构建时间。