In this work, we focus on the Partial Constraint Satisfaction Problem (PCSP) over control-flow graphs (CFGs) of programs. PCSP serves as a generalization of the well-known Constraint Satisfaction Problem (CSP). In the CSP framework, we define a set of variables, a set of constraints, and a finite domain $D$ that encompasses all possible values for each variable. The objective is to assign a value to each variable in such a way that all constraints are satisfied. In the graph variant of CSP, an underlying graph is considered and we have one variable corresponding to each vertex of the graph and one or several constraints corresponding to each edge. In PCSPs, we allow for certain constraints to be violated at a specified cost, aiming to find a solution that minimizes the total cost. Numerous classical compiler optimization tasks can be framed as PCSPs over control-flow graphs. Examples include Register Allocation, Lifetime-optimal Speculative Partial Redundancy Elimination (LOSPRE), and Optimal Placement of Bank Selection Instructions. On the other hand, it is well-known that control-flow graphs of structured programs are sparse and decomposable in a variety of ways. In this work, we rely on the Series-Parallel-Loop (SPL) decompositions as introduced by~\cite{RegisterAllocation}. Our main contribution is a general algorithm for PCSPs over SPL graphs with a time complexity of \(O(|G| \cdot |D|^6)\), where \(|G|\) represents the size of the control-flow graph. Note that for any fixed domain $D,$ this yields a linear-time solution. Our algorithm can be seen as a generalization and unification of previous SPL-based approaches for register allocation and LOSPRE. In addition, we provide experimental results over another classical PCSP task, i.e. Optimal Bank Selection, achieving runtimes four times better than the previous state of the art.
翻译:本文聚焦于程序控制流图(CFG)上的部分约束满足问题(PCSP)。PCSP是经典约束满足问题(CSP)的推广形式。在CSP框架中,我们定义一组变量、一组约束以及包含所有变量可能取值的有限域$D$,目标是为每个变量赋值使得所有约束均被满足。在图形式的CSP中,考虑基础图结构,图中每个顶点对应一个变量,每条边对应一个或多个约束。在PCSP中,我们允许以特定代价违反部分约束,旨在寻找使总代价最小化的解。大量经典编译器优化任务可建模为控制流图上的PCSP问题,例如寄存器分配、生命周期最优的投机性部分冗余消除(LOSPRE)以及存储体选择指令的最优放置。另一方面,结构化程序的控制流图具有稀疏性且可通过多种方式分解。本研究基于~\cite{RegisterAllocation}提出的串并环(SPL)分解方法,主要贡献是提出针对SPL图PCSP的通用算法,其时间复杂度为\(O(|G| \cdot |D|^6)\),其中\(|G|\)表示控制流图的规模。需注意对于任意固定域$D$,该算法具有线性时间复杂度。本算法可视为先前基于SPL的寄存器分配与LOSPRE方法的推广与统一。此外,我们在另一经典PCSP任务——最优存储体选择上进行了实验验证,其运行速度较现有最优方法提升四倍。