Table of Contents
Fetching ...

Series-Parallel-Loop Decompositions of Control-flow Graphs

Xuran Cai, Amir Goharshady, S Hitarth, Chun Kit Lam

TL;DR

This paper introduces a grammar-based series-parallel-loop (SPL) decomposition that exactly captures control-flow graphs of structured programs, providing a targeted framework for dynamic programming that outperforms traditional treewidth-based methods. By defining SPL graphs and a grammatical decomposition aligned with program syntax, the authors develop faster algorithms for two core compiler optimizations: minimum-cost register allocation and lifetime-optimal speculative partial redundancy elimination (LOSPRE). The resulting DP approaches yield substantial empirical speedups, enabling spill-free allocations for real-world architectures (up to 20 registers) and roughly sixfold improvements for LOSPRE over prior treewidth-based techniques. These advances suggest a broader potential for SPL-based analyses to supersede treewidth/pathwidth in CFG-related optimization tasks, while also outlining directions for handling unstructured control flow and broader applications in compiler pipelines.

Abstract

Control-flow graphs (CFGs) of structured programs are well known to exhibit strong sparsity properties. Traditionally, this sparsity has been modeled using graph parameters such as treewidth and pathwidth, enabling the development of faster parameterized algorithms for tasks in compiler optimization, model checking, and program analysis. However, these parameters only approximate the structural constraints of CFGs: although every structured CFG has treewidth at most~7, many graphs with treewidth at most~7 cannot arise as CFGs. As a result, existing parameterized techniques are optimized for a substantially broader class of graphs than those encountered in practice. In this work, we introduce a new grammar-based decomposition framework that characterizes \emph{exactly} the class of control-flow graphs generated by structured programs. Our decomposition is intuitive, mirrors the syntactic structure of programs, and remains fully compatible with the dynamic-programming paradigm of treewidth-based methods. Using this framework, we design improved algorithms for two classical compiler optimization problems: \emph{Register Allocation} and \emph{Lifetime-Optimal Speculative Partial Redundancy Elimination (LOSPRE)}. Extensive experimental evaluation demonstrates significant performance improvements over previous state-of-the-art approaches, highlighting the benefits of using decompositions tailored specifically to CFGs.

Series-Parallel-Loop Decompositions of Control-flow Graphs

TL;DR

This paper introduces a grammar-based series-parallel-loop (SPL) decomposition that exactly captures control-flow graphs of structured programs, providing a targeted framework for dynamic programming that outperforms traditional treewidth-based methods. By defining SPL graphs and a grammatical decomposition aligned with program syntax, the authors develop faster algorithms for two core compiler optimizations: minimum-cost register allocation and lifetime-optimal speculative partial redundancy elimination (LOSPRE). The resulting DP approaches yield substantial empirical speedups, enabling spill-free allocations for real-world architectures (up to 20 registers) and roughly sixfold improvements for LOSPRE over prior treewidth-based techniques. These advances suggest a broader potential for SPL-based analyses to supersede treewidth/pathwidth in CFG-related optimization tasks, while also outlining directions for handling unstructured control flow and broader applications in compiler pipelines.

Abstract

Control-flow graphs (CFGs) of structured programs are well known to exhibit strong sparsity properties. Traditionally, this sparsity has been modeled using graph parameters such as treewidth and pathwidth, enabling the development of faster parameterized algorithms for tasks in compiler optimization, model checking, and program analysis. However, these parameters only approximate the structural constraints of CFGs: although every structured CFG has treewidth at most~7, many graphs with treewidth at most~7 cannot arise as CFGs. As a result, existing parameterized techniques are optimized for a substantially broader class of graphs than those encountered in practice. In this work, we introduce a new grammar-based decomposition framework that characterizes \emph{exactly} the class of control-flow graphs generated by structured programs. Our decomposition is intuitive, mirrors the syntactic structure of programs, and remains fully compatible with the dynamic-programming paradigm of treewidth-based methods. Using this framework, we design improved algorithms for two classical compiler optimization problems: \emph{Register Allocation} and \emph{Lifetime-Optimal Speculative Partial Redundancy Elimination (LOSPRE)}. Extensive experimental evaluation demonstrates significant performance improvements over previous state-of-the-art approaches, highlighting the benefits of using decompositions tailored specifically to CFGs.
Paper Structure (20 sections, 3 theorems, 31 equations, 12 figures)

This paper contains 20 sections, 3 theorems, 31 equations, 12 figures.

Key Result

Theorem 1

Given a program $P$ with variables $\mathbb{V}$ and control-flow graph $G=\textsf{cfg}(P),$ the number $r$ of available registers and a cost function $c(\cdot, \cdot)$ as input, our algorithm above finds an optimal allocation of registers, i.e. an optimal assignment function $f,$ in time $O(|G| \cdo

Figures (12)

  • Figure 1: A graph $G$ (left) and a tree decomposition of $G$ (right). This example is taken from DBLP:journals/pacmpl/ConradoGL23.
  • Figure 2: Atomic $\texttt{SPL}\xspace$ graphs: $A_\epsilon$ (left), $A_{\texttt{break}}$ (middle), and $A_{\texttt{continue}}$ (right).
  • Figure 6: A program $P$ (top left), its parse tree (top right), the corresponding parse tree of $G = \textsf{cfg}(P),$ aka the grammatical decomposition of $G$ (bottom left) and the graph $G = \textsf{cfg}(P)$ (bottom right). The edges of the graph are labeled according to the commands/conditions of the program.
  • Figure 7: An Example Program $P$ (top left), its control-flow graph $G = \textsf{cfg}(P)$ (top right) in which every vertex is labeled by its set of live variables in red, the interference graph $\mathbb I$ (bottom left), a coloring of all vertices of $\mathbb{I}$ with 4 colors corresponding to allocating all variables to 4 registers (bottom center), and a coloring of a subset of vertices of $\mathbb{I}$ with 3 colors corresponding to spilling the variables $a$ and $f$ (bottom right).
  • Figure 8: An example of LOSPRE. The use set is shown in gray, the invalidating set in orange, and the life set in green. The edges of the calculation set are shown in blue.
  • ...and 7 more figures

Theorems & Definitions (6)

  • Theorem 1
  • proof
  • Theorem 2
  • proof
  • Theorem 3
  • proof