Abstract
Interprocedural program analysis is essential for modern software verification and optimization, yet it remains computationally demanding for large-scale applications. This paper presents a novel framework that achieves significant speedups by exploiting the "constant treewidth" property inherent in most human-written code. By combining tree decomposition with generalized algebraic semirings, the authors provide algorithms that reduce complex path-related queries—such as reachability and shortest paths—to near-constant time after a one-time preprocessing step.
Introduction
Modern static analysis tools rely on interprocedural analysis to detect memory leaks, perform alias analysis, and optimize code across function boundaries. These problems are typically modeled using Recursive State Machines (RSMs), which represent the control flow of programs containing recursion and nested function calls.
Two primary challenges hinder current approaches:
- Query Efficiency: While single-source queries are common, real-world tools often require multiple "pair queries" (e.g., determining if two pointers can ever alias). Standard methods are often too slow for repeated use.
- Structural Neglect: Most algorithms treat program control-flow graphs (CFGs) as arbitrary networks, ignoring the fact that structured programming constructs (loops, conditionals) result in graphs that are fundamentally tree-like, characterized by a low treewidth.
Methodology: Leveraging Structural Sparsity
The core of the proposed approach is the use of tree decomposition to break down complex program graphs into a tree of "bags" (small sets of nodes). This structural insight allows the authors to apply a dynamic programming approach to solve algebraic path properties using various semirings:
- Boolean Semiring: For reachability analysis.
- Tropical Semiring: For shortest path calculations.
- Viterbi Semiring: For determining the most probable execution paths.
The Preprocessing and Query Cycle
The algorithm operates in two phases:
- Preprocessing: The tree decomposition is processed bottom-up to summarize "U-shaped paths" (paths contained within a specific subtree). For interprocedural analysis, the RSMDistance algorithm propagates these summaries across function boundaries using a Bellman-Ford-like iteration over the call graph.
- Querying: Once preprocessed, the system can answer queries by identifying the lowest common ancestor of two nodes in the tree decomposition and combining their precomputed summaries. This reduces query time to $O(\log n)$ or $O(1)$.
Empirical Evaluation
The researchers validated their framework using the DaCapo benchmark suite, analyzing real-world Java applications like antlr and eclipse. Using the Soot framework, they extracted CFGs and confirmed that even massive programs maintain a remarkably low treewidth (typically between 1 and 4).
Key Results
The theoretical and empirical results demonstrate that structural optimization provides a significant advantage over general-purpose graph algorithms.
- Efficiency Gains: Preprocessing was found to be 1.5x to 4x faster than traditional all-pairs reachability methods.
- Query Speed: Shortest path queries, which traditionally take $O(n^4)$ time without preprocessing, were answered in linear or constant time.
- Scalability: By maintaining a space complexity of $O(n \log n)$, the approach remains practical for large codebases where quadratic space requirements would fail.
Conclusion and Future Work
By recognizing that program structure is inherently tree-like, this work provides a unified abstraction for a wide variety of static analysis problems. While current results focus on "same-context" queries (paths starting and ending with an empty call stack), future research aims to extend this to multi-entry/exit components and dynamic graph updates, where the analysis can be incrementally refreshed as code changes.
Summary updated