An Overview of GCC

A Compiler


GCC (GNU Compiler Collection)


Three-stage structure and representations

Gcc Architecture


Representations

Gcc Architecture


Abstract Syntax Tree (AST)

AST 150%


Tree structure on GCC (function)

Function node| Function Body — | — Function Node 120% | Function Body

#

// Getter by GCC Pluging API
char* fnName = IDENTIFIER_POINTER(DECL_NAME(fnDecl));
tree fnBody = DECL_SAVED_TREE(fnDecl);

Tree structure on GCC (expression)

i = 3 * k + 7;

Expression nodes


GIMPLE


Example of GIMPLE

CPP

while (a<=7) {
   a = a + 1;
}

GIMPLE

goto <D.1197>;
<D.1196>:;
a = a + 1;
<D.1197>:;
if (a <= 7)
    goto <D.1196>;
else
    goto <D.1198>;
<D.1198>:;

SSA (Static Single Assignment)


RTL (Register Transfer Language)

# It is used to describe data flow at the register-transfer level of an architecture.


Front end

Deal with the programming language itself

  1. Scan the source file and parse it
  2. Generate AST
  3. Convert into a unified form called GENERIC
    • The generated ASTs is slightly different for each language

Middle end

Deal with the intermediate language

  1. Convert into another representation called GIMPLE
  2. Convert into the Static Single Assignment
  3. Process the SSA optimization passes
  4. Convert back to the GIMPLE form

Back end

Deal with the target system

  1. Convert into another representation called GIMPLE
  2. Process RTL optimization pass
  3. Generate the assembly code for the target architecture

GCC compiler generation framework

CGF 150%


Link Time Optimization


Reference