GNU Compiler Collection Internals
Total Page:16
File Type:pdf, Size:1020Kb
GNU Compiler Collection Internals For gcc version 4.2.1 Richard M. Stallman and the GCC Developer Community Copyright c 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with the Invariant Sections being “GNU General Public License” and “Funding Free Software”, the Front-Cover texts being (a) (see below), and with the Back-Cover Texts being (b) (see below). A copy of the license is included in the section entitled “GNU Free Documentation License”. (a) The FSF’s Front-Cover Text is: A GNU Manual (b) The FSF’s Back-Cover Text is: You have freedom to copy and modify this GNU Manual, like GNU software. Copies published by the Free Software Foundation raise funds for GNU development. i Short Contents Introduction ...................................... 1 1 Contributing to GCC Development ................... 3 2 GCC and Portability ............................. 5 3 Interfacing to GCC Output ........................ 7 4 The GCC low-level runtime library ................... 9 5 Language Front Ends in GCC ...................... 21 6 Source Tree Structure and Build System ............... 23 7 Option specification files.......................... 51 8 Passes and Files of the Compiler .................... 55 9 Trees: The intermediate representation used by the C and C++ front ends ................................... 69 10 Analysis and Optimization of GIMPLE Trees .......... 107 11 Analysis and Representation of Loops ................ 131 12 RTL Representation ............................ 141 13 Control Flow Graph ............................ 189 14 Machine Descriptions ........................... 199 15 Target Description Macros and Functions ............. 293 16 Host Configuration ............................ 437 17 Makefile Fragments ............................ 441 18 collect2 ................................... 445 19 Standard Header File Directories ................... 447 20 Memory Management and Type Information ........... 449 Funding Free Software ............................. 455 The GNU Project and GNU/Linux..................... 457 GNU GENERAL PUBLIC LICENSE ................... 459 GNU Free Documentation License ..................... 465 Contributors to GCC .............................. 473 Option Index.................................... 489 Concept Index ................................... 491 ii GNU Compiler Collection (GCC) Internals iii Table of Contents Introduction .................................. 1 1 Contributing to GCC Development ......... 3 2 GCC and Portability ....................... 5 3 Interfacing to GCC Output................. 7 4 The GCC low-level runtime library ......... 9 4.1 Routines for integer arithmetic ............................... 9 4.1.1 Arithmetic functions .................................... 9 4.1.2 Comparison functions .................................. 10 4.1.3 Trapping arithmetic functions .......................... 11 4.1.4 Bit operations ......................................... 11 4.2 Routines for floating point emulation ........................ 12 4.2.1 Arithmetic functions ................................... 12 4.2.2 Conversion functions ................................... 13 4.2.3 Comparison functions .................................. 14 4.2.4 Other floating-point functions .......................... 16 4.3 Routines for decimal floating point emulation................. 16 4.3.1 Arithmetic functions ................................... 16 4.3.2 Conversion functions ................................... 17 4.3.3 Comparison functions .................................. 18 4.4 Language-independent routines for exception handling ........ 19 4.5 Miscellaneous runtime library routines ....................... 20 4.5.1 Cache control functions ................................ 20 5 Language Front Ends in GCC ............. 21 6 Source Tree Structure and Build System ... 23 6.1 Configure Terms and History ................................ 23 6.2 Top Level Source Directory ................................. 23 6.3 The ‘gcc’ Subdirectory ..................................... 24 6.3.1 Subdirectories of ‘gcc’ ................................. 25 6.3.2 Configuration in the ‘gcc’ Directory ..................... 25 6.3.2.1 Scripts Used by ‘configure’ ....................... 26 6.3.2.2 The ‘config.build’; ‘config.host’; and ‘config.gcc’ Files ................................................. 26 6.3.2.3 Files Created by configure........................ 26 6.3.3 Build System in the ‘gcc’ Directory ..................... 27 6.3.4 Makefile Targets ....................................... 27 iv GNU Compiler Collection (GCC) Internals 6.3.5 Library Source Files and Headers under the ‘gcc’ Directory ........................................................ 30 6.3.6 Headers Installed by GCC .............................. 30 6.3.7 Building Documentation ............................... 30 6.3.7.1 Texinfo Manuals .................................. 31 6.3.7.2 Man Page Generation ............................. 31 6.3.7.3 Miscellaneous Documentation ...................... 32 6.3.8 Anatomy of a Language Front End ...................... 33 6.3.8.1 The Front End ‘language’ Directory ............... 34 6.3.8.2 The Front End ‘config-lang.in’ File .............. 36 6.3.9 Anatomy of a Target Back End ......................... 37 6.4 Testsuites.................................................. 38 6.4.1 Idioms Used in Testsuite Code .......................... 38 6.4.2 Directives used within DejaGnu tests .................... 39 6.4.3 Ada Language Testsuites ............................... 43 6.4.4 C Language Testsuites ................................. 44 6.4.5 The Java library testsuites. ............................. 45 6.4.6 Support for testing gcov ............................... 46 6.4.7 Support for testing profile-directed optimizations ......... 47 6.4.8 Support for testing binary compatibility ................. 47 7 Option specification files .................. 51 7.1 Option file format .......................................... 51 7.2 Option properties .......................................... 51 8 Passes and Files of the Compiler........... 55 8.1 Parsing pass ............................................... 55 8.2 Gimplification pass ......................................... 56 8.3 Pass manager .............................................. 56 8.4 Tree-SSA passes............................................ 57 8.5 RTL passes ................................................ 63 9 Trees: The intermediate representation used by the C and C++ front ends ............... 69 9.1 Deficiencies ................................................ 69 9.2 Overview .................................................. 69 9.2.1 Trees ................................................. 70 9.2.2 Identifiers ............................................. 70 9.2.3 Containers ............................................ 71 9.3 Types ..................................................... 71 9.4 Scopes..................................................... 76 9.4.1 Namespaces ........................................... 76 9.4.2 Classes................................................ 77 9.5 Declarations ............................................... 79 9.5.1 Working with declarations .............................. 79 9.5.2 Internal structure ...................................... 81 9.5.2.1 Current structure hierarchy ........................ 82 v 9.5.2.2 Adding new DECL node types ..................... 83 9.6 Functions .................................................. 84 9.6.1 Function Basics........................................ 85 9.6.2 Function Bodies ....................................... 88 9.6.2.1 Statements ....................................... 88 9.7 Attributes in trees.......................................... 92 9.8 Expressions ................................................ 92 10 Analysis and Optimization of GIMPLE Trees ....................................... 107 10.1 GENERIC............................................... 107 10.2 GIMPLE ................................................ 107 10.2.1 Interfaces ........................................... 108 10.2.2 Temporaries......................................... 108 10.2.3 Expressions ......................................... 109 10.2.3.1 Compound Expressions .......................... 109 10.2.3.2 Compound Lvalues .............................. 109 10.2.3.3 Conditional Expressions ......................... 109 10.2.3.4 Logical Operators ............................... 110 10.2.4 Statements .......................................... 110 10.2.4.1 Blocks ......................................... 110 10.2.4.2 Statement Sequences ............................ 111 10.2.4.3 Empty Statements .............................. 111 10.2.4.4 Loops .......................................... 111 10.2.4.5 Selection Statements ............................ 111 10.2.4.6 Jumps ......................................... 111 10.2.4.7 Cleanups ....................................... 111 10.2.4.8 Exception Handling ............................. 112 10.2.5 GIMPLE Example ................................... 112 10.2.6 Rough GIMPLE Grammar ........................... 114 10.3 Annotations ............................................. 116 10.4 Statement Operands.....................................