Compiler 1o1, GNU, LLVM

This note covers the following points:

  • What GNU Compiler Collection (GCC) is
  • What LLVM is
  • How they differ philosophically and practically

1️⃣ GNU Compiler Collection (GCC)

What it is

GCC = GNU Compiler Collection

Originally:

  • A single C compiler (gcc)
    Now:
  • A collection of compilers for many languages

Languages GCC supports

  • C → gcc
  • C++ → g++
  • Fortran
  • Objective-C
  • Ada
  • more…

So:

g++ is just the C++ frontend of GCC

Architecture (conceptual)

C / C++ / Fortran source
        ↓
   Language frontend
        ↓
   GCC middle-end
        ↓
   GCC backend
        ↓
   Machine code

GCC is:

  • monolithic
  • tightly integrated
  • very mature
  • extremely optimized

Strengths of GCC

  • Excellent performance
  • Very stable
  • Supports many architectures
  • Industry standard for Linux

Weaknesses

  • Hard to extend
  • Hard to reuse parts
  • Error messages historically worse
  • Tooling ecosystem is weaker

LLVM collection

What it is

LLVM = Low Level Virtual Machine

Despite the name:

  • It’s not a VM
  • It’s a compiler infrastructure

LLVM is a collection of reusable compiler components.

Languages in the LLVM ecosystem

  • C / C++ → clang
  • Rust → rustc (uses LLVM backend)
  • Swift
  • Objective-C
  • parts of CUDA tooling
  • many others

Architecture (conceptual)

C / C++ source
        ↓
      clang
        ↓
  LLVM IR (intermediate form)
        ↓
  LLVM optimizer
        ↓
  LLVM backend
        ↓
  Machine code

Key idea:

LLVM has a clean, shared intermediate representation (IR)

This allows many languages to share:

  • optimizations
  • backends
  • tooling

Strengths of LLVM

  • Very modular
  • Excellent tooling
  • Clean APIs
  • Fast compile times
  • Best error messages

Weaknesses

  • Historically fewer supported architectures
  • Sometimes slightly worse raw performance (gap is small now)
  • CUDA support depends on NVIDIA integration

Philosophical difference (this is the core)

GCC philosophy

“One big compiler that does everything very well.”

  • Monolithic
  • Internals not designed for reuse
  • Focus on code generation quality

LLVM philosophy

“Many small reusable compiler parts.”

  • Modular
  • Frontends, optimizers, backends separated
  • Designed for tools, IDEs, and research

Why this difference matters to you

Editor tooling

  • clangd exists because LLVM exposes parsing & ASTs
  • GCC does not expose this cleanly

That’s why:

  • Neovim → clangd
  • VS Code → clangd
  • CLion → clang

CUDA situation

  • nvcc historically integrated with GCC
  • LLVM added CUDA support later
  • nvcc remains the authority
  • clang follows NVIDIA’s spec

That’s why:

  • clang can compile CUDA
  • but nvcc still controls CUDA

CMake preference

CMake works with both:

  • GCC toolchain
  • LLVM toolchain

But modern tooling leans LLVM-heavy because:

  • compile_commands.json
  • clangd
  • static analysis

Concrete comparison table

AspectGCC (g++, gcc)LLVM (clang)
DesignMonolithicModular
Main goalBest codegenReusable infrastructure
Error messagesOKExcellent
ToolingLimitedRich (clangd, tidy, format)
Compile speedSlowerFaster
Editor supportPoorExcellent
CUDA supportIndirect via nvccNative (partial)
Used by Rust

6️⃣ Why both still exist (important)

Neither “won”.

  • GCC:
    • still dominant in Linux distros
    • trusted for production builds
  • LLVM:
    • dominates tooling and editors
    • enables modern language ecosystems

They coexist because they optimize for different goals.


7️⃣ One-sentence summaries

  • GCC: “A powerful, traditional compiler suite focused on performance and stability”
  • LLVM: “A modern compiler infrastructure designed for reuse, tooling, and analysis”

8️⃣ Final mental model (remember this)

GCC is a factory
LLVM is a construction kit

Both produce code — but LLVM lets you see inside.

Leave a Reply

Your email address will not be published. Required fields are marked *