Contents

GNU Compiler Collection (GCC) Internals

This file documents the internals of the GNU compilers. Copyright © 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.

Short Contents

Introduction

1 Contributing to GCC Development

2 GCC and Portability

3 Interfacing to GCC Output

4 The GCC low-level runtime library

5 Language Front Ends in GCC

6 Source Tree Structure and Build System

7 Option specification files

8 Passes and Files of the Compiler

9 Trees: The intermediate representation used by the C and C++ front ends

10 Analysis and Optimization of GIMPLE Trees

11 Analysis and Representation of Loops

12 RTL Representation

13 Control Flow Graph

14 Machine Descriptions

15 Target Description Macros and Functions

16 Host Configuration

17 Makefile Fragments

18 collect2

19 Standard Header File Directories

20 Memory Management and Type Information

Funding Free Software

The GNU Project and GNU/Linux

GNU GENERAL PUBLIC LICENSE

GNU Free Documentation License

Contributors to GCC

Option Index

Concept Index

Table of Contents

Introduction

1 Contributing to GCC Development

2 GCC and Portability

3 Interfacing to GCC Output

4 The GCC low-level runtime library

4.1 Routines for integer arithmetic

4.1.1 Arithmetic functions

4.1.2 Comparison functions

4.1.3 Trapping arithmetic functions

4.1.4 Bit operations

4.2 Routines for floating point emulation

4.2.1 Arithmetic functions

4.2.2 Conversion functions

4.2.3 Comparison functions

4.2.4 Other floating-point functions

4.3 Routines for decimal floating point emulation

4.3.1 Arithmetic functions

4.3.2 Conversion functions

4.3.3 Comparison functions

4.4 Language-independent routines for exception handling

4.5 Miscellaneous runtime library routines

4.5.1 Cache control functions

5 Language Front Ends in GCC

6 Source Tree Structure and Build System

6.1 Configure Terms and History

6.2 Top Level Source Directory

6.3 The gcc Subdirectory

6.3.1 Subdirectories of gcc

6.3.2 Configuration in the gcc Directory

6.3.2.1 Scripts Used by configure

6.3.2.2 The config.build ; config.host ; and config.gcc Files

6.3.2.3 Files Created by configure

6.3.3 Build System in the gcc Directory

6.3.4 Makefile Targets

6.3.5 Library Source Files and Headers under the gcc Directory

6.3.6 Headers Installed by GCC

6.3.7 Building Documentation

6.3.7.1 Texinfo Manuals

6.3.7.2 Man Page Generation

6.3.7.3 Miscellaneous Documentation

6.3.8 Anatomy of a Language Front End

6.3.8.1 The Front End language Directory

6.3.8.2 The Front End config-lang.in File

6.3.9 Anatomy of a Target Back End

6.4 Testsuites

6.4.1 Idioms Used in Testsuite Code

6.4.2 Directives used within DejaGnu tests

6.4.3 Ada Language Testsuites

6.4.4 C Language Testsuites

6.4.5 The Java library testsuites.

6.4.6 Support for testing gcov

6.4.7 Support for testing profile-directed optimizations

6.4.8 Support for testing binary compatibility

7 Option specification files

7.1 Option file format

7.2 Option properties

8 Passes and Files of the Compiler

8.1 Parsing pass

8.2 Gimplification pass

8.3 Pass manager

8.4 Tree-SSA passes

8.5 RTL passes

9 Trees: The intermediate representation used by the C and C++ front ends

9.1 Deficiencies

9.2 Overview

9.2.1 Trees

9.2.2 Identifiers

9.2.3 Containers

9.3 Types

9.4 Scopes

9.4.1 Namespaces

9.4.2 Classes

9.5 Declarations

9.5.1 Working with declarations

9.5.2 Internal structure

9.5.2.1 Current structure hierarchy

9.5.2.2 Adding new DECL node types

9.6 Functions

9.6.1 Function Basics

9.6.2 Function Bodies

9.6.2.1 Statements

9.7 Attributes in trees

9.8 Expressions

10 Analysis and Optimization of GIMPLE Trees

10.1 GENERIC

10.2 GIMPLE

10.2.1 Interfaces

10.2.2 Temporaries

10.2.3 Expressions

10.2.3.1 Compound Expressions

10.2.3.2 Compound Lvalues

10.2.3.3 Conditional Expressions

10.2.3.4 Logical Operators

10.2.4 Statements

10.2.4.1 Blocks

10.2.4.2 Statement Sequences

10.2.4.3 Empty Statements

10.2.4.4 Loops

10.2.4.5 Selection Statements

10.2.4.6 Jumps

10.2.4.7 Cleanups

10.2.4.8 Exception Handling

10.2.5 GIMPLE Example

10.2.6 Rough GIMPLE Grammar

10.3 Annotations

10.4 Statement Operands

10.4.1 Operand Iterators And Access Routines

10.4.2 Immediate Uses

10.5 Static Single Assignment

10.5.1 Preserving the SSA form

10.5.2 Preserving the virtual SSA form

10.5.3 Examining SSA_NAME nodes

10.5.4 Walking use-def chains

10.5.5 Walking the dominator tree

10.6 Alias analysis

11 Analysis and Representation of Loops

11.1 Loop representation

11.2 Loop querying

11.3 Loop manipulation

11.4 Loop-closed SSA form

11.5 Scalar evolutions

11.6 IV analysis on RTL

11.7 Number of iterations analysis

11.8 Data Dependency Analysis

11.9 Linear loop transformations framework

12 RTL Representation

12.1 RTL Object Types

12.2 RTL Classes and Formats

12.3 Access to Operands

12.4 Access to Special Operands

12.5 Flags in an RTL Expression

12.6 Machine Modes

12.7 Constant Expression Types

12.8 Registers and Memory

12.9 RTL Expressions for Arithmetic

12.10 Comparison Operations

12.11 Bit-Fields

12.12 Vector Operations

12.13 Conversions

12.14 Declarations

12.15 Side Effect Expressions

12.16 Embedded Side-Effects on Addresses

12.17 Assembler Instructions as Expressions

12.18 Insns

12.19 RTL Representation of Function-Call Insns

12.20 Structure Sharing Assumptions

12.21 Reading RTL

13 Control Flow Graph

13.1 Basic Blocks

13.2 Edges

13.3 Profile information

13.4 Maintaining the CFG

13.5 Liveness information

14 Machine Descriptions

14.1 Overview of How the Machine Description is Used

14.2 Everything about Instruction Patterns

14.3 Example of define_insn

14.4 RTL Template

14.5 Output Templates and Operand Substitution

14.6 C Statements for Assembler Output

14.7 Predicates

14.7.1 Machine-Independent Predicates

14.7.2 Defining Machine-Specific Predicates

14.8 Operand Constraints

14.8.1 Simple Constraints

14.8.2 Multiple Alternative Constraints

14.8.3 Register Class Preferences

14.8.4 Constraint Modifier Characters

14.8.5 Constraints for Particular Machines

14.8.6 Defining Machine-Specific Constraints

14.8.7 Testing constraints from C

14.9 Standard Pattern Names For Generation

14.10 When the Order of Patterns Matters

14.11 Interdependence of Patterns

14.12 Defining Jump Instruction Patterns

14.13 Defining Looping Instruction Patterns

14.14 Canonicalization of Instructions

14.15 Defining RTL Sequences for Code Generation

14.16 Defining How to Split Instructions

14.17 Including Patterns in Machine Descriptions.

14.17.1 RTL Generation Tool Options for Directory Search

14.18 Machine-Specific Peephole Optimizers

14.18.1 RTL to Text Peephole Optimizers

14.18.2 RTL to RTL Peephole Optimizers

14.19 Instruction Attributes

14.19.1 Defining Attributes and their Values

14.19.2 Attribute Expressions

14.19.3 Assigning Attribute Values to Insns

14.19.4 Example of Attribute Specifications

14.19.5 Computing the Length of an Insn

14.19.6 Constant Attributes

14.19.7 Delay Slot Scheduling

14.19.8 Specifying processor pipeline description

14.20 Conditional Execution

14.21 Constant Definitions

14.22 Macros

14.22.1 Mode Macros

14.22.1.1 Defining Mode Macros

14.22.1.2 Substitution in Mode Macros

14.22.1.3 Mode Macro Examples

14.22.2 Code Macros

15 Target Description Macros and Functions

15.1 The Global targetm Variable

15.2 Controlling the Compilation Driver, gcc

15.3 Run-time Target Specification

15.4 Defining data structures for per-function information.

15.5 Storage Layout

15.6 Layout of Source Language Data Types

15.7 Register Usage

15.7.1 Basic Characteristics of Registers

15.7.2 Order of Allocation of Registers

15.7.3 How Values Fit in Registers

15.7.4 Handling Leaf Functions

15.7.5 Registers That Form a Stack

15.8 Register Classes

15.9 Obsolete Macros for Defining Constraints

15.10 Stack Layout and Calling Conventions

15.10.1 Basic Stack Layout

15.10.2 Exception Handling Support

15.10.3 Specifying How Stack Checking is Done

15.10.4 Registers That Address the Stack Frame

15.10.5 Eliminating Frame Pointer and Arg Pointer

15.10.6 Passing Function Arguments on the Stack

15.10.7 Passing Arguments in Registers

15.10.8 How Scalar Function Values Are Returned

15.10.9 How Large Values Are Returned

15.10.10 Caller-Saves Register Allocation

15.10.11 Function Entry and Exit

15.10.12 Generating Code for Profiling

15.10.13 Permitting tail calls

15.10.14 Stack smashing protection

15.11 Implementing the Varargs Macros

15.12 Trampolines for Nested Functions

15.13 Implicit Calls to Library Routines

15.14 Addressing Modes

15.15 Anchored Addresses

15.16 Condition Code Status

15.17 Describing Relative Costs of Operations

15.18 Adjusting the Instruction Scheduler

15.19 Dividing the Output into Sections (Texts, Data, ... )

15.20 Position Independent Code

15.21 Defining the Output Assembler Language

15.21.1 The Overall Framework of an Assembler File

15.21.2 Output of Data

15.21.3 Output of Uninitialized Variables

15.21.4 Output and Generation of Labels

15.21.5 How Initialization Functions Are Handled

15.21.6 Macros Controlling Initialization Routines

15.21.7 Output of Assembler Instructions

15.21.8 Output of Dispatch Tables

15.21.9 Assembler Commands for Exception Regions

15.21.10 Assembler Commands for Alignment

15.22 Controlling Debugging Information Format

15.22.1 Macros Affecting All Debugging Formats

15.22.2 Specific Options for DBX Output

15.22.3 Open-Ended Hooks for DBX Format

15.22.4 File Names in DBX Format

15.22.5 Macros for SDB and DWARF Output

15.22.6 Macros for VMS Debug Format

15.23 Cross Compilation and Floating Point

15.24 Mode Switching Instructions

15.25 Defining target-specific uses of __attribute__

15.26 Defining coprocessor specifics for MIPS targets.

15.27 Parameters for Precompiled Header Validity Checking

15.28 C++ ABI parameters

15.29 Miscellaneous Parameters

16 Host Configuration

16.1 Host Common

16.2 Host Filesystem

16.3 Host Misc

17 Makefile Fragments

17.1 Target Makefile Fragments

17.2 Host Makefile Fragments

18 collect2

19 Standard Header File Directories

20 Memory Management and Type Information

20.1 The Inside of a GTY(())

20.2 Marking Roots for the Garbage Collector

20.3 Source Files Containing Type Information

Funding Free Software

The GNU Project and GNU/Linux

GNU GENERAL PUBLIC LICENSE

Preamble

Appendix: How to Apply These Terms to Your New Programs

GNU Free Documentation License

ADDENDUM: How to use this License for your documents

Contributors to GCC

Option Index

Concept Index

Next: Contributing ,
Up: (DIR)

Introduction

This manual documents the internals of the GNU compilers, including how to port them to new targets and some information about how to write front ends for new languages. It corresponds to GCC version 4.2.1. The use of the GNU compilers is documented in a separate manual. See Introduction .

This manual is mainly a reference manual rather than a tutorial. It discusses how to contribute to GCC (see Contributing ), the characteristics of the machines supported by GCC as hosts and targets (see Portability ), how GCC relates to the ABIs on such systems (see Interface ), and the characteristics of the languages for which GCC front ends are written (see Languages ). It then describes the GCC source tree structure and build system, some of the interfaces to GCC front ends, and how support for a target system is implemented in GCC.

Additional tutorial information is linked to from http://gcc.gnu.org/readings.html .

Contributing : How to contribute to testing and developing GCC.

Portability : Goals of GCC's portability features.

Interface : Function-call interface of GCC output.

Libgcc : Low-level runtime library used by GCC.

Languages : Languages for which GCC front ends are written.

Source Tree : GCC source tree structure and build system.

Options : Option specification files.

Passes : Order of passes, what they do, and what each file is for.

Trees : The source representation used by the C and C++ front ends.

RTL : The intermediate representation that most passes work on.

Control Flow : Maintaining and manipulating the control flow graph.

Tree SSA : Analysis and optimization of the tree representation.

Loop Analysis and Representation : Analysis and representation of loops

Machine Desc : How to write machine description instruction patterns.

Target Macros : How to write the machine description C macros and functions.

Host Config : Writing the xm- machine .h file.

Fragments : Writing the t- target and x- host files.

Collect2 : How collect2 works; how it finds ld .

Header Dirs : Understanding the standard header file directories.

Type Information : GCC's memory management; generating type information.

Funding : How to help assure funding for free software.

GNU Project : The GNU Project and GNU/Linux.

Copying : GNU General Public License says how you can copy and share GCC.

GNU Free Documentation License : How you can copy and share this manual.

Contributors : People who have contributed to GCC.

Option Index : Index to command line options.

Concept Index : Index of concepts and symbol names.