User:Gso321/GCC/Internals

From Gentoo Wiki
Jump to:navigation Jump to:search
Note
GCC main code uses ISO C++14 and requires C++ understanding.

Explains GCC Internals in detailed documentation. GCC uses 3 main intermediate representation: GENERIC, GIMPLE, and RTL. GENRERIC is GCC's Abstract syntax tree and was designed for GCC frontend to convert. Some frontends, like C, directly tranlates to GIMPLE instead but this is much harder to do than GENERIC. GENERIC is turned to GIMPLE (GENERIC's Static Single Assignment), called "gimplifier". This is where most machine independent optimizations happen because it is portable across architectures. GIMPLE is converted to RTL, GCC's "assembly language" and where machine dependent optimizations can occur with -march=native. RTL is then converted to object file, which is a non executable assembly in machine code. The linker then finally links all object files into a file, usually a executable file. If Link time optimizations is enabled, the linker converts object files into GIMPLE and analyzes it as if it was a single translation unit (file).

Tree

GENERIC and GIMPLE is mainly made of tree as defined in gcc/coretypes.h. tree is actually a union of pointers and requires macros due to GCC historically being written in C. tree can be used to define functions, statements, and blocks.

LLVM C comparison

GENERIC/GIMPLE is compared to LLVM C to have easier understanding of GENERIC/GIMPLE.

Equivalence GENERIC/GIMPLE LLVM
Void type tree void_type_node; enum LLVMTypeKind LLVMVoidTypeKind;
Struct type RECORD_TYPE macro enum LLVMTypeKind LLVMStructTypeKind;