Binary size reduction is an increasingly important optimization objective for compilers. One emerging technique is function merging, where multiple similar functions are merged into one, thereby eliminating redundancy. The SOTA approach to perform the merging is based on sequence alignment, where functions are viewed as linear sequences of instructions that are then matched in a way maximizing their alignment. In this paper, we consider a significantly generalized formulation of the problem by allowing reordering of branches within each function, subsequently allowing for more flexible matching and better merging. We show that this makes the problem NP-hard, and thus we study it through the lens of parameterized algorithms and complexity, where we identify certain parameters of the input that govern its complexity. We look at two natural parameters: the branching factor and nesting depth of input functions. Concretely, our input consists of two functions $F_1, F_2,$ where each $F_i$ has size $n_i,$ branching factor $b_i,$ and nesting depth $d_i.$ Our task is to reorder the branches of $F_1$ and $F_2$ in a way that yields linearizations achieving the maximum sequence alignment. Let $n=\max(n_1, n_2),$ and define $b, d$ similarly. Our results are as follows: - A simple algorithm running in time $2^{O(bd)} n^2,$ establishing that the problem is fixed-parameter tractable (FPT) with respect to all four parameters $b_1,d_1, b_2, d_2.$ - An algorithm running in time $2^{O(bd_2)} n^7,$ showing that even when one of the functions has an unbounded nesting depth, the problem remains in FPT. - A hardness result showing that the problem is NP-hard even when constrained to constant $d_1, b_2, d_2.$ To the best of our knowledge, this is the first systematic study of function merging with branch reordering from an algorithmic or complexity-theoretic perspective.
翻译:二进制规模缩减已成为编译器日益重要的优化目标。其中一种新兴技术是函数合并,即将多个相似函数合并为一个,从而消除冗余。当前最先进的合并方法基于序列比对:将函数视为指令的线性序列,通过最大化对齐程度的方式进行匹配。本文考虑该问题的一个显著泛化形式,允许在每个函数内部对分支进行重排,从而支持更灵活的对齐与更优的合并。我们证明该问题具有NP难性,因此通过参数化算法与复杂性的视角进行研究,识别出决定问题复杂性的输入参数。我们考察两个自然参数:输入函数的分支因子与嵌套深度。具体地,输入包含两个函数$F_1, F_2$,其中每个$F_i$的规模为$n_i$,分支因子为$b_i$,嵌套深度为$d_i$。任务是重排$F_1$与$F_2$的分支,使得生成的线性化序列达到最大序列对齐。设$n=\max(n_1, n_2)$,并类似定义$b, d$。我们的研究成果如下:
- 一个运行时间为$2^{O(bd)} n^2$的简单算法,证明该问题关于四个参数$b_1,d_1,b_2,d_2$是固定参数可解(FPT)的。
- 一个运行时间为$2^{O(bd_2)} n^7$的算法,表明即使其中一个函数具有无界嵌套深度,问题仍属于FPT。
- 一个难度结果表明:即使在常数$d_1, b_2, d_2$约束下,该问题仍是NP难的。
据我们所知,这是从算法或计算复杂性角度对带分支重排的函数合并问题进行的首次系统性研究。