The New Framework for Loop Nest Optimization in GCC: from Prototyping to Evaluation

The New Framework for Loop Nest Optimization in GCC: from Prototyping to Evaluation

The New Framework for Loop Nest Optimization in GCC: from Prototyping to Evaluation Sebastian Pop1, Albert Cohen2, Pierre Jouvelot1, and Georges-Andr´eSilber1 1 Centre de recherche en informatique, Mines Paris, Fontainebleau, France 2 ALCHEMY group, INRIA Futurs, Orsay, France Abstract. This paper presents a practical prototyping tool for SSA transformations based on PROLOG, and a case study of its applicabil- ity using the New Framework for Loop Nest Optimization of the GNU Compiler Collection (GCC). Using this approach, we implemented an in- duction variable analysis in GCC and performed several experiments for assessing different issues: performance of the generated code, effective- ness of the analyzers and optimizers, compilation overhead, together with possible improvements. This evaluation, based on the SPEC CPU2000, MiBench and JavaGrande benchmarks on different architectures, suggests that our framework could be of valuable use in production compilers de- velopments such as GCC. 1 Introduction The GNU Compiler Collection (GCC) is the leading compiler suite for the free and open source software. The large set of target architectures and standard com- pliant front ends makes GCC the de facto compiler for portable developments and system design. However, until recently, GCC was not an option for high per- formance computing: it had infrastructure neither for data access restructuring nor for automatic parallelization. Furthermore, until recently, the compilation research community had no robust, universal, free, and industry-supported plat- form where new ideas in compiler technology can be implemented and tested on large scale programs written in standard programming languages. For more than a decade, the field of advanced compilation has been plagued by redundant development efforts on short-lived projects, with little impact on production en- vironments. In this paper, we propose an overview and a preliminary evaluation of the new infrastructure of GCC for analysis and loop nest optimizations. Based on this evaluation we intend to show the potential of GCC to address the needs of a free compiler in the compiler research and high performance computing communities. Modern compilers implement some of the sophisticated optimizations intro- duced for supercomputing applications [23, 3]. They provide performance models and transformations to improve fine-grain parallelism and to take into account Front−ends C C++ Java F95 Ada GENERIC GIMPLE Middle−end Induction variable analysis Data dependence analysis Scalar and Loop Nest Optimizations GIMPLE − SSA GIMPLE Back−end RTL Machine Description Asm Fig. 1. The infrastructure of GCC 4. the memory hierarchy. Most of these optimizations are loop-oriented and as- sume a high-level code representation with rich control and data structures: do loops with regular control, constant bounds and strides, typed arrays with linear subscripts. Yet these compilers are architecture-specific and designed by processor vendors, e.g., IBM, SGI, HP and Intel. In addition, the most advanced optimizations are limited to Fortran and C, and performance is dependent on the recognition of specific patterns in the source code. Some source-to-source com- pilers implement advanced loop transformations driven by architecture models and profiling [12]. However, good optimizations require manual efforts in the syntactic presentation of loops and array subscripts (avoiding, e.g., while loops, imperfect nests, linearized subscripts, pointers). In addition, the source-to-source approach is not suitable for low-level optimizations, including vectorization for SIMD instructions and software pipelining. It is also associated with pattern- based strategies that do not easily adapt to syntactic variations in the programs. Finally, these compilers require a huge implementation effort that cannot be matched by small development teams for general-purpose and/or free software compilers. Several projects demonstrated the interest of type enriched low-level repre- sentation [14]. They build on the normalization and simplicity of three-address code, adding data types, Static Single-Assignment (SSA) form [8,17] to ease data-flow analysis and scalar optimizations, and control and data annotations (loop nesting, heap structure, etc.). Recently, GCC 4 adopted such a represen- tation called GIMPLE [19,16], a three-address code derived from SIMPLE, the representation of the McCAT compiler [11]. The GIMPLE representation was proposed by Sebastian Pop and Diego Novillo, from RedHat, for minimizing the effort in the development and the maintenance of new analyzes and transforma- tions. GIMPLE is used for building the SSA representation that is then used by the analyzers and the scalar and loop nest optimizers. After these optimizations, the intermediate representation is translated into RTL, where machine-specific informations are added to the representation. Figure 1 presents the overall struc- ture of GCC. The front-ends C, C++, Java, Fortran95 and Ada are translating their intermediate representation to a common representation called GENERIC, then to GIMPLE that is eventually translated to RTL. Before presenting the loop optimizations that we will evaluate, we give an overview of the GIMPLE intermediate representation on which the loop optimizers are acting. A three-address representation like GIMPLE could seem not suitable to imple- ment program transformations for high performance: control-flow is represented by only two primitives, a conditional expression if, and a goto expression goto. Loops have to be discovered from the control-flow graph [2]. Although the num- ber of iterations is not captured by the GIMPLE representation, it is often dis- covered by analyzing the scalar variables involved in the loop exit conditions; this allows to compute precise information lost in the translation to a low-level representation, but it may also be useful when the source level does not expose enough syntactic information, e.g., in while loops, or loops with irregular con- trol constructs such as break or exceptions. In GIMPLE, subscript expressions, loop bounds and strides are spread across a number of elementary instructions and basic blocks, possibly far away from the original location in the source code. This is due to the translation to the low-level intermediate representation and to optimization phases such as dead-code elimination, partial redundancy elimina- tion, optimization of the control flow, invariant code motion, etc. However, the SSA form provides fast practical ways to extract information concerning values of scalar variables. We recall some SSA terminology [8, 17] to facilitate further discussions: the SSA graph is the graph of def-use chains in the SSA form; each assignment targets a unique variable; φ nodes occur at merge points of the control flow and restore the flow of values from the renamed variables. Assuming the natural loops [2] information has been recovered, φ nodes whose arguments are defined at different loop depths are called loop-φ nodes and they have a specific semantics related to a potentially recursive definition. With the following notations: – S[[e]] for the semantics of an expression e, – loopx − φ(b,c) for an SSA φ node defined in loop x, where b is defined in an enclosing loop y and c is defined in loop x, as illustrated in Figure 3, – ℓx for the integer-valued indices of loop x,0 ≤ ℓx <Nx, with Nx the number of iterations in loop x, – a(ℓx) for the value of variable a at iteration ℓx, we give the denotational semantics for a subset of the SSA expressions contained in an innermost loop x: b(ℓy), if ℓx = 0; S[[a = loopx − φ(b,c)]]ℓy = ∀ℓx 0 ≤ ℓx <Nx ∧ a(ℓx)= c(ℓx − 1), otherwise. S[[d = e]]ℓx = [d(ℓx)= e(ℓx)] S[[f = g + h]]ℓx = [f(ℓx)= g(ℓx)+ h(ℓx)] We illustrate the semantics of the SSA representation with two examples: Figure 2 illustrates the role of a φ node used for merging values assigned in different branches of a condition expression. Figure 3 presents the syntax and the semantics of a loop-φ node, variable a is self defined in the argument coming from the loop body. v = 5; a=5 if (E) if (E) { then b = 0 a = 5 v = 0; SSA Sem endif b = 0 } −−→ −−−→ c = φ(a, b) ... = v; b if E is true, ... = c c = (a otherwise. Fig. 2. Syntax and semantics of a condition-φ node. b= 0 f= 7 a(0) = b i = 0; begin1: a(x) = c(x − 1) for x > 0 s = 7; a = loop1-φ(b, c) a(x) = a(x − 1) + f(x − 1) for x > 0 do { SSA c=a+f Sem . if (E) i=i+s; −−→ −−−→ x−1 } while (E); then goto begin1 a(x) = b + f(j) for x ≥ 0 else goto end1 jX=0 endif a(x) = b + x · f for x ≥ 0 end1: a(x) = 7x for x ≥ 0 Fig. 3. Syntax and semantics of a loop-φ node. 2 Contributions We developed an analyzer [21] that matches common induction patterns on the SSA graph, based on an algorithm close to linear unification [20]. We develop this idea in Section 3 and give a practical framework for prototyping SSA analyzes and transformations in PROLOG [1], thus paving the way for more analysis and transformations in GCC. The analyzer that we presented in [21] builds a description of the scalar variables using a practical closed form representation: the chains of recurrences [4, 13, 22]. We presented in [21] some extensions for the chains of recurrences for solving practical problems that we encountered during the integration of our algorithm in GCC. Among these extensions we can cite the symbolic form of chains of recurrences that we called trees of recurrences TREC, enabling the expression of self-defined chains of recurrences, as for example the Fibbonacci sequence, or more generally, exponential evolutions expressed in the program only by additions. We have also proposed the peeled chains of recurrences, that list the first values of a sequence. Periodic sequences can naturally be represented using a combination of these two extensions, as a self-defined TREC listing the elements of the period.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    15 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us