- Research Article
1
- 10.1016/j.entcs.2007.02.064
Computing SSA Form with Matrices
- Jul 01, 2007
- Electronic Notes in Theoretical Computer Science
- Quan Hoang Nguyen
Computing SSA Form with Matrices
An optimizing compiler internal representation fundamentally affects the clarity, efficiency and feasibility of optimization algorithms employed by the compiler. Static Single Assignment (SSA) as a state-of-the-art program representation has great advantages though still can be improved. This dissertation explores the domain of single assignment beyond SSA, and presents two novel program representations: Future Gated Single Assignment (FGSA) and Recursive Future Predicated Form (RFPF). Both FGSA and RFPF embed control flow and data flow information, enabling efficient traversal program information and thus leading to better and simpler optimizations. We introduce future value concept, the designing base of both FGSA and RFPF, which permits a consumer instruction to be encountered before the producer of its source operand(s) in a control flow setting. We show that FGSA is efficiently computable by using a series T1/T2/TR transformation, yielding an expected linear time algorithm for combining together the construction of the pruned single assignment form and live analysis for both reducible and irreducible graphs. As a result, the approach results in an average reduction of 7.7%, with a maximum of 67% in the number of gating functions compared to the pruned SSA form on the SPEC2000 benchmark suite. We present a solid and near optimal framework to perform inverse transformation from single assignment programs. We demonstrate the importance of unrestricted code motion and present RFPF. We develop algorithms which enable instruction movement in acyclic, as well as cyclic regions, and show the ease to perform optimizations such as Partial Redundancy Elimination on RFPF.
Loading PDF
Computing SSA Form with Matrices
Computing SSA Form with Matrices
Anticipation‐based partial redundancy elimination for static single assignment form
Partial redundancy elimination (PRE) is a program transformation that identifies and eliminates expressions that are redundant on at least one (but not necessarily all) execution paths of a program without increasing any path length. Chow, Kennedy and co‐workers devised an algorithm (SSAPRE) for performing partial redundancy elimination on intermediate representations in static single assignment (SSA) form. The practicality of that algorithm is limited by the following concerns: (1) it makes assumptions about the namespace that are stronger than those of SSA form and that may not be valid if other optimizations have already been performed on the program; (2) if redundancies occur in nested expressions, the algorithm may expose but not eliminate them (requiring a second pass of the algorithm); (3) it misses cases covered by the state of the art in PRE; and (4) it is difficult to understand and implement. We present an algorithm (A‐SSAPRE) structurally similar to SSAPRE that uses anticipation rather than availability; this algorithm is simpler than SSAPRE, covers more cases, eliminates nested redundancies on a single pass, and makes no assumptions about the namespace. Copyright © 2004 John Wiley & Sons, Ltd.
Read moreA linear time algorithm for placing φ-nodes
Dataflow analysis framework based on Static Single Assignment (SSA) form and Sparse Evaluation Graphs (SEGs) demand fast computation of program points where data flow information must be merged, the so-called φ-nodes. In this paper, we present a surprisingly simple algorithm for computing φ-nodes for arbitrary flowgraphs (reducible or irreducible) that runs in linear time. We employ a novel program representation—the DJ graph—by augmenting the dominator tree of a flowgraph with edges which may lead to a potential “merge” of dataflow information. In searching for φ-nodes we never visit an edge in the DJ-graph more than once by guiding the search of nodes by their levels in the dominator tree.
Read morePractical improvements to the construction and destruction of static single assignment form
Static Single Assignment (SSA) form is a program representation that is becoming increasingly popular for compiler-based code optimization. In this paper, we address three problems that have arisen in our use of SSA form. Two are variations to the SSA construction algorithms presented by Cytron et al.1 The first variation is a version of SSA form that we call ‘semi-pruned’ SSA. It offers an attractive trade-off between the cost of global data-flow analysis required to build ‘pruned’ SSA and the large number of unused ϕ-functions found in minimal SSA. The second variation speeds up the program renaming process by efficiently manipulating the stacks of names used during renaming. Our improvement reduces the number of pushes performed, in addition to more efficiently locating the stacks that should be popped. To convert code in SSA form back into an executable form, the compiler must use an algorithm that replaces ϕ-functions with appropriately-placed copy instructions. The algorithm given by Cytron et al. for inserting copies produces incorrect results in some situations; particularly in cases like instruction scheduling, where the compiler may not be able to split ‘critical edges’, and in the aftermath of optimizations that aggressively rewrite the name space, like some forms of global value numbering.2 We present a new algorithm for inserting copy instructions to replace ϕ-functions. It fixes the problems that we have encountered with the original copy insertion algorithm. We present experimental results that demonstrate the effectiveness of the first two improvements not only during the construction of SSA form, but also in the time saved by subsequent optimization passes that use a smaller representation of the program. © 1998 John Wiley & Sons, Ltd.
Read moreLocality Based Static Single Assignment Partial Redundancy Elimination
The Partial Redundancy Elimination (PRE) is an important redundancy elimination transformation technique. Locality based Static Single Assignment Partial Redundancy Elimination method classifies expressions into three categories: Local, Confined and Other. In order to reduce optimization time, LSSAPRE removes unnecessary Φ’s during the Φ -Insertion phase itself, which is the first step of SSAPRE. The unnecessary Φ – assignments for the local and confined expressions can be easily identified and removed in Φ –Insertion step. Even though this LSSAPRE system has reasonably good performance, it is not considering the other category expression based data flow problems in SSA form. In this paper, tried to propose a new Locality based SSAPRE method to remove unnecessary Φ assignments for the other category expressions during Φ - Insertion step itself and thereby reducing the analysis time and optimization time required for SSAPRE algorithm. But it theoretically proved that only based on the concept of locality of expressions and the dominance/post dominance relationship, it is not possible to remove the unnecessary Φ assignments for other category expressions during Φ - Insertion step and it is not possible to reduce the analysis time required for the SSAPRE algorithm.KeywordsPartial Redundancy EliminationStatic Single Assignment formLocality of expressionDominance relationshipΦ-assignment
Read moreA Practical Improvement to the Partial Redundancy Elimination in SSA Form
Partial redundancy elimination (PRE) is an interesting compiler optimization because of its effectiveness and generality. Among many PRE algorithms, the one in static single assignment form (SSAPRE) has benefits over other bit-vector-based PRE algorithms. It preserves the properties of the SSA form after PRE and exploits the sparsity of the SSA form, resulting in reduced analysis and optimization time. This paper presents a practical improvement of the SSAPRE algorithm that further reduces the analysis and optimization time. The underlying idea is removing unnecessary <TEX>${\Phi}$</TEX>'s during the <TEX>${\Phi}$</TEX>-Insertion phase that is the first step of SSAPRE. We classify the expressions into three categories: confined expressions, local expressions, and the others. We show that unnecessary <TEX>${\Phi}$</TEX>'s for confined and local expressions can be easily detected and removed. We implement our locality-based SSAPRE algorithm in a C compiler and evaluate its effectiveness with 20 applications from SPEC benchmark suites. In our measurements, on average 91 of <TEX>${\Phi}$</TEX>'s identified by the original demand-driven SSAPRE algorithm are unnecessary for PRE. Pruning these unnecessary <TEX>${\Phi}$</TEX>'s in the <TEX>${\Phi}$</TEX>-Insertion phase makes our locality-based SSAPRE algorithm 1.8 times faster, on average, than the original SSAPRE algorithm.
Read moreDetecting Code Clones with Graph Neural Network and Flow-Augmented Abstract Syntax Tree
Code clones are semantically similar code fragments pairs that are syntactically similar or different. Detection of code clones can help to reduce the cost of software maintenance and prevent bugs. Numerous approaches of detecting code clones have been proposed previously, but most of them focus on detecting syntactic clones and do not work well on semantic clones with different syntactic features. To detect semantic clones, researchers have tried to adopt deep learning for code clone detection to automatically learn latent semantic features from data. Especially, to leverage grammar information, several approaches used abstract syntax trees (AST) as input and achieved significant progress on code clone benchmarks in various programming languages. However, these AST-based approaches still can not fully leverage the structural information of code fragments, especially semantic information such as control flow and data flow. To leverage control and data flow information, in this paper, we build a graph representation of programs called flow-augmented abstract syntax tree (FA-AST). We construct FA-AST by augmenting original ASTs with explicit control and data flow edges. Then we apply two different types of graph neural networks (GNN) on FA-AST to measure the similarity of code pairs. As far as we have concerned, we are the first to apply graph neural networks on the domain of code clone detection. We apply our FA-AST and graph neural networks on two Java datasets: Google Code Jam and BigCloneBench. Our approach outperforms the state-of-the-art approaches on both Google Code Jam and BigCloneBench tasks.
Read moreAlgorithms for computing the static single assignment form
The Static Single Assignment (SSA) form is a program representation used in many optimizing compilers. The key step in converting a program to SSA form is called ϕ-placement. Many algorithms for ϕ-placement have been proposed in the literature, but the relationships between these algorithms are not well understood.In this article, we propose a framework within which we systematically derive (i) properties of the SSA form and (ii) ϕ-placement algorithms. This framework is based on a new relation called merge which captures succinctly the structure of a program's control flow graph that is relevant to its SSA form. The ϕ-placement algorithms we derive include most of the ones described in the literature, as well as several new ones. We also evaluate experimentally the performance of some of these algorithms on the SPEC92 benchmarks.Some of the algorithms described here are optimal for a single variable. However, their repeated application is not necessarily optimal for multiple variables. We conclude the article by describing such an optimal algorithm, based on the transitive reduction of the merge relation, for multi-variable ϕ-placement in structured programs. The problem for general programs remains open.
Read moreLambda the Ultimate SSA: Optimizing Functional Programs in SSA
Static Single Assignment (SSA) is the workhorse of modern optimizing compilers for imperative programming languages. However, functional languages have been slow to adopt SSA and prefer to use intermediate representations based on minimal lambda calculi due to SSA’s inability to express higher-order constructs. We exploit a new SSA construct — regions — in order to express functional optimizations via classical SSA-based reasoning. Region optimization currently relies on ad-hoc analyses and transformations on imperative programs. These ad-hoc transformations are sufficient for imperative languages as regions are used in a limited fashion. In contrast, we use regions pervasively to model sub-expressions in our functional IR. This motivates us to systematize region optimizations. We extend classical SSA reasoning to regions for functional-style analyses and transformations. We implement a new SSA + regions based backend for LEAN4, a theorem prover that implements a purely functional, dependently typed programming language. Our backend is feature-complete and handles all constructs of LEAN4’s functional intermediate representation $\lambda _{\mathbf{rc}}$ within the SSA framework. We evaluate our proposed region optimizations by optimizing $\lambda_{\mathbf{rc}}$ within an SSA + regions based framework implemented in MLIR and demonstrating performance parity with the current LEAN4 backend. We believe our work will pave the way for a unified optimization framework capable of representing, analyzing, and optimizing both functional and imperative languages.
Read moreAn extensible program representation for object-oriented software
An extensible representation for object-oriented programs is presented. It is based on the concept of a program dependency graph and elaborated to include both control flow and data flow information. The representation takes advantage of the basic incremental philosophy of the object-oriented approach to develop a more compact representation that is useful with practical programs. The basic approach reported here provides a static view of an object-oriented program. The approach can be expanded to provide dynamic information for tools such as interactive debuggers and other runtime tools. The outline of this extension is also presented.
Read moreA Functional Perspective on SSA Optimisation Algorithms
A Functional Perspective on SSA Optimisation Algorithms
Dead code elimination technique in eclipse compiler for Java
Eclipse compiler for Java (ECJ) is open source incremented compiler. We reform features of ECJ, related to optimization technique called as dead code detection and elimination. ECJ identifies the dead code. We are extending this compiler to eliminate the dead code. In this paper we are describing the structure of ECJ. For dead code elimination approach we have used Single Static Assignment (SSA) strategy. After applying definition- use (DU) chain on SSA, we detect dead code and eliminate it. In this paper we are describing two algorithms: 1) To convert Java source code into SSA. 2) To eliminate dead code. Hence by implementing dead code elimination in ECJ, we are utilizing space and execution time of program which leads to improve efficiency of compiler.
Read moreSecuring the SSA Transform
Modern optimizing compilers use the single static assignment (SSA) format for programs, as it simplifies program analysis and transformation. A source program is converted to an equivalent SSA form before it is optimized. The conversion may, however, create a less secure program if fresh SSA variables inadvertently leak sensitive values that are masked in the original program. This work defines a mechanism to restore a program to its original security level after it has been converted to SSA form and modified further by a series of optimizing transformations. The final program is converted out of SSA form by grouping variables together in a manner that blocks any new leak introduced by the initial SSA conversion. The grouping relies on taint and leakage information about the original program, which is propagated through the optimizing transformations using refinement proofs.
Read moreOptymalizacja kodu przy wykorzystaniu algorytmu ssa w środowiskach maszyn wirtualnych
Artykuł ten skupia się na wybranych sposobach optymalizacji kodu, przeprowadzanych z użyciem techniki pojedynczego statycznego przypisania (SSA) ze szczególnym uwzględnieniem kontekstu najpopularniejszych obecnie środowisk maszyn wirtualnych. Przedstawiono podstawowe metody optymalizacji kodu, które opierają się na technice przekształcenia kodu do wspomnianej postaci. Zaprezentowano metodę konstrukcji grafów przepływu sterowania oraz skupiono się na możliwości jej wykorzystania do redukcji obliczeń. Na podstawie przykładowego kodu przedstawiono możliwość optymalizacji SSA w wiodących systemach maszyn wirtualnych Java VM, .NET Framework i Mono. Eksperymentalnie oceniono wpływ ręcznego wykonania optymalizacji przez programistę w odniesieniu do optymalizacji wykonywanej automatycznie przez kompilator JIT.
Read morePartial Value Number Redundancy Elimination
When exploiting instruction level parallelism in a runtime optimizing compiler, it is indispensable to quickly remove redundant computations and memory accesses to make resources available. We propose a fast and efficient algorithm called Partial Value Number Redundancy Elimination (PVNRE), which completely fuses Partial Redundancy Elimination (PRE) and Global Value Numbering (GVN). Using value numbers in the data-flow analyses, PVNRE can deal with data-dependent redundancy, and can quickly remove path-dependent partial redundancy by converting value numbers at join nodes on demand during the data-flow analyses. Compared with the naive combination of GVN, PRE, and copy propagation, PVNRE has a maximum 45% faster analyses speed, but the same optimizing power on SPECjvm98.
Read more