← Back to list
Lex Fridman PodcastPodcast13 May 2019Source: lexfridman.comHost: Lex Fridman

Chris Lattner: Compilers, LLVM, Swift, TPU, and ML Accelerators

In plain words

This podcast features Chris Lattner, creator of LLVM and Swift, now at Google working on AI chips. He says compilers are like translators between human code and machine language. LLVM's biggest win isn't a technical breakthrough—it's that rivals like Apple, Google, and NVIDIA all share the same compiler infrastructure instead of building their own. Swift started as a weekend hobby project, then became Apple's official language for safety. Three key things mentioned: LLVM (19 years old, still widely used), Swift (Python interop in just 1,200 lines of code), and TPU (Google's AI chip using bfloat16, a cheaper and more efficient number format).

AI SummaryAI-generated · may contain errors · verify against the original

Chris Lattner discussed compiler technology, LLVM, Swift, TPUs, and ML accelerators on the Lex Fridman Podcast. The core argument is that compilers are a key technology connecting hardware and software to generate efficient code. Key conclusions include: Lattner created the LLVM compiler infrastruct

~14 min full read · 9 sections
Deep Analysis

This Issue at a Glance

Chris Lattner (founder of LLVM, creator of Swift, former VP of Autopilot Software at Tesla, currently Senior Director at Google) delves into the essence of compiler technology on the Lex Fridman podcast — a compiler is the bridge connecting human intent with machine execution, and its core challenge is not algorithmic innovation but software engineering: enabling hundreds of people to collaborate on building modular, reusable infrastructure. Lattner argues that LLVM’s greatest contribution is not a specific optimization breakthrough, but rather its standardized and modular design, which allows competitors such as Apple, Google, NVIDIA, and AMD to collaborate on shared infrastructure. This model is now being replicated in the machine learning compiler space by the MLIR project.


Theme 1: The Essence of a Compiler — A Bridge from Human Intent to Machine Execution

Chris Lattner argues that the core task of a compiler is to establish a translation channel between the "abstraction level humans desire" and the "level at which hardware actually executes."

  • Three-Layer Architecture: A compiler is typically divided into a front end (language-specific, e.g., Clang parsing C/C++), a middle end (optimizer, language-agnostic), and a back end (hardware-specific, generating machine code). LLVM standardizes the middle and back ends, enabling different languages such as Swift, Julia, Rust, and C/C++ to share the same optimization and code generation infrastructure.
  • Intermediate Representation (IR): The front end parses source code into an Abstract Syntax Tree (AST) and then "lowers" it into an Intermediate Representation in the form of a Control Flow Graph (CFG). The IR is language-agnostic — language-specific features like JavaScript's "falsy" concept remain in the front end, while the middle-end optimizer only needs to process the unified IR.
  • Driven by Hardware Diversity: Traditional chips like x86, ARM, and PowerPC, along with ML accelerators such as GPUs and TPUs, force compilers to continuously adapt to new hardware. Lattner emphasizes: "Both hardware and software are becoming more complex on their respective ends, and the compiler is the system in the middle that must understand both sides simultaneously."

Key Analogy: Lattner compares compilers to neural networks — both transform representations across different abstraction levels. However, compilers typically use only a few types of representations and perform multiple iterative transformations, whereas neural networks generate a large number of different representations through multiple layers.


Theme 2: The Secret to LLVM’s Success—Not Algorithmic Breakthroughs, but Engineering and Community

Lattner believes that LLVM’s most profound contribution is not an innovation in compiler algorithms, but rather enabling competitors to collaborate on shared infrastructure through modular design.

  • Origin: LLVM began as Lattner’s master’s project at the University of Illinois, initially just for “fun”—he originally planned to earn a non-thesis master’s degree in one year and return to work, but was “technically sniped” into staying for five years. The team initially consisted only of himself, his advisor, and 2–3 graduate students.
  • Modular Design: LLVM’s core design principle is modularity—for example, Lattner wrote a register allocator, which later “people much smarter than me” could replace entirely. This stands in stark contrast to GCC: GCC’s global variables and tightly coupled design make replacing subsystems extremely difficult.
  • Competitor Collaboration: Companies such as Apple, Google, AMD, Intel, NVIDIA, and Cray are commercial competitors, yet they all collaborate on LLVM. Lattner explains: “This is not out of goodwill, but because the infrastructure is too expensive—no single company, not even a giant, is willing to implement it all on its own.” LLVM now has approximately 150 different optimization passes.
  • Community Governance: LLVM employs a hierarchical code owner system, where hardware vendors naturally become responsible for their specific hardware portions. Lattner remains the nominal top-level owner, but his main work is mediating technical disagreements rather than reviewing every patch. The LLVM Foundation (a non-profit organization) handles business and event matters but does not interfere with technical direction.
  • Unexpected Applications: Sony uses LLVM for graphics compilation in its film production pipeline, achieving better visual effects—“This is a hallmark of good infrastructure: being used in ways the designer never anticipated.”

Data Point: LLVM is now 19 years old, older than GCC was at the time of LLVM’s birth. Lattner still has an order of magnitude more patches than anyone else.


Theme 3: The Birth of Swift — From "Impossible" to "Must-Do"

Lattner describes Swift's origins: from a "weekend project" to a "heretical idea," ultimately becoming a reality due to the non-negotiable requirement of memory safety.

  • Starting Point: In 2010, Clang's C++ support had just been completed. Lattner felt that C++ was "ugly in many ways" and began exploring "something better" in his spare time—without telling anyone and without any ambition.
  • Internal Resistance: At the time, Apple's software team "loved Objective-C"—many leaders came from NeXT, and engineers were hired precisely because they liked Objective-C. The idea of creating a new language was seen as "heretical." Lattner notes: "The success of the iPhone was attributed to Objective-C, not despite it."
  • Key Turning Point: Objective-C's C-based pointer system had fundamental memory safety issues. Lattner argued: "If you remove pointers, it's no longer Objective-C. You cannot fix memory safety without fundamentally changing the language." This realization ultimately convinced the team.
  • Design Philosophy: Swift's core design principle is "progressive complexity exposure"—starting with a single line of code like `print("hello world")`, then gradually introducing variables, control flow, functions, classes, generics, and modules. Lattner emphasizes that this is unusual for a compiled language: "You can write firmware in Swift, but it has a very high-level feel."
  • Dynamic Compilation Capability: Swift is not just statically compiled—in Colab or Jupyter, it is actually dynamically compiled: each line of code passes through the Swift compiler frontend, optimizer, and JIT compilation into machine code, then injected into a running process. Lattner stresses: "This is not accidental; Swift was designed for this from the start."

Python Interoperability: Swift achieves Python interoperability, such as `import numpy`, by introducing two language features: "dynamic member lookup" and "dynamic call." The implementation consists of only about 1,200 lines of pure Swift code—it creates a Python object type and then calls the Python interpreter through C interoperability.


Theme 4: Swift for TensorFlow—Redefining the Division of Labor in the ML Compiler Stack

Lattner argues that the fundamental difference between Swift for TensorFlow and Python bindings is that Swift can modify the language itself to optimize the human-machine division of labor, whereas Python is constrained by "what can be done with libraries."

  • TensorFlow is essentially a compiler: It takes a model and makes it run fast on hardware—this is what a compiler does. It has a frontend, optimizers, and multiple backends.
  • Python's limitations: Python's ML ecosystem represents "the best that can be achieved with Python libraries"—no language features have been added specifically for ML (the matrix multiplication operator being an exception). Automatic differentiation requires manual management via `tf.GradientTape`.
  • Swift's advantages:
  • Type system: The compiler can automatically build computation graphs, perform fusion, and optimize, without manual intervention from the programmer.
  • Language-integrated automatic differentiation: Swift for TensorFlow is implementing automatic differentiation at the language level, reusing source-to-source transformation techniques from the Fortran era of the 1970s—including optimizations like numerical stability fixes. This requires the ability to "see the entire function," which is impossible with op-by-op eager execution.
  • MLIR project: Lattner describes it as "LLVM 2.0"—it learns from both the successes and mistakes of LLVM, aiming to provide a shared infrastructure for multiple compilers in the TensorFlow ecosystem (Google XLA, NVIDIA TensorRT, Intel nGraph). MLIR has not yet been open-sourced but is expected to be released within a few months.

Theme 5: TPU and Hardware-Software Co-Design

Lattner uses bfloat16 as an example to illustrate that the TPU’s success stems from the co-design of hardware, software, and algorithms.

  • Origin of bfloat16: It initially came from a compression scheme developed by the research team to optimize network weight transmission—it has a smaller mantissa and a larger exponent, offering lower precision but the ability to represent a wider range of values. In ML, this can actually improve generalization.
  • Hardware advantage: The area and latency of a multiplier are proportional to the square of the mantissa bits and linearly related to the exponent bits—bfloat16 is therefore cheaper (in terms of chip area and power consumption) than standard float16.
  • Third-generation TPU: A large liquid-cooled system with 100 petaflops. Lattner emphasizes: "We haven’t run out of ideas." Hardware production cycles span several years, while algorithms are constantly evolving—one must place bets and decide how to optimally allocate transistors.

Theme 6: The Tesla Experience — The Power of Vision vs. the Reality of High Turnover

Lattner’s assessment of Tesla is contradictory: he respects Elon Musk’s visionary ability, yet also experienced "unprecedented high turnover."

  • Transition from Hardware 1 to Hardware 2: Hardware 1 was initially designed for simple automation features (e.g., traffic-aware cruise control), but later experienced "feature creep" into driver-assistance functions like lane keeping. The core challenge of Hardware 2 was shifting from a third-party vision stack to an in-house vision stack — Lattner was primarily involved in this transition.
  • Assessment of Elon Musk: "Elon can attract top talent because he has a very clear vision of the future, making people believe in it and willing to work toward it. I deeply respect the power of that vision. There are many people standing on street corners saying 'we’re going to Mars,' but only a very few can make others believe, build a path, and achieve it. I don’t respect all of his methods, but I respect that aspect immensely."
  • Work Intensity: Lattner defines "hard work" not merely as long hours, but as balancing short-term delivery with long-term thinking. At Apple, he freed himself by cultivating teams and leadership, allowing him to "think a bit crazily about the next thing."

Mentioned Positions

Position Analyst View Key Data
LLVM Bullish (creator perspective) 19-year history, approximately 150 optimization passes, community includes Apple/Google/AMD/Intel/NVIDIA/Cray
Clang Bullish C/C++/ObjC frontend, Google is now the primary contributor
Swift Bullish (creator perspective) Started in 2010, Python interoperability requires only 1,200 lines of code
TensorFlow Bullish Open-sourcing is considered a "milestone moment in software history"
TPU (Google) Bullish Third-generation 100 petaflops liquid-cooled system, bfloat16 format
Tesla Autopilot Neutral (experience description) Transition from Hardware 1 to Hardware 2, shifted from third-party vision stack to in-house development
GCC Neutral comparison Performance "so close to LLVM that it doesn't matter," but less modular than LLVM
XLA (Google) Positive mention TensorFlow's compiler system
TensorRT (NVIDIA) Positive mention Hardware-specific compiler
nGraph (Intel) Positive mention Hardware-specific compiler

Judgments Worth Remembering

1. "LLVM's greatest contribution is not algorithmic innovation, but enabling competitors to collaborate on shared infrastructure" (Chris Lattner) — Apple, Google, AMD, Intel, NVIDIA, and other companies jointly invested in LLVM because "the infrastructure is too expensive for any single company to implement entirely on its own."

2. "Swift was not born because Objective-C was bad, but because memory safety could not be fixed without changing the language" (Chris Lattner) — Objective-C is built on C's pointer system; removing pointers would mean it is no longer Objective-C. This insight was key to convincing the "Objective-C enthusiasts" inside Apple.

3. "Compilers and neural networks are conceptually similar — both transform representations at different levels of abstraction, but compilers use only a few representations and perform multiple iterative transformations" (Chris Lattner) — This analogy reveals the deep connection between ML compilers (e.g., TensorFlow) and classical compilers.

4. "Python's ML ecosystem is 'the best you can do with libraries,' while Swift can change the language itself to optimize the human-machine division of labor" (Chris Lattner) — Swift for TensorFlow, through language-integrated automatic differentiation and a type system, allows the compiler to automatically build computation graphs and perform fusion optimizations, without manual intervention from the programmer.

5. "bfloat16 has a smaller mantissa and a larger exponent — reduced precision but expanded range, which may improve generalization in ML, while being cheaper in hardware (multiplier area is proportional to the square of the mantissa bit width)" (Chris Lattner) — This is a classic case of hardware-software-algorithm co-design, originally stemming from network weight compression research and later etched into TPU silicon.

6. "MLIR is 'LLVM 2.0' — it learns from LLVM's successes and mistakes, providing shared infrastructure for multiple compilers in the TensorFlow ecosystem" (Chris Lattner) — MLIR aims to allow systems like XLA, TensorRT, and nGraph to share code, avoiding reinventing the wheel.

7. "Elon Musk can attract top talent because he has a very clear vision of the future and makes people believe in it — many people in the world say 'we are going to Mars,' but very few can make others believe and actually achieve it" (Chris Lattner) — Lattner respects the power of vision but explicitly states he "does not respect all of his methods."

8. "Compilers are the last comprehensive course — they bring together algorithms, data structures, and software engineering, and you must continuously build on the same codebase throughout the semester, living with your own decisions" (Chris Lattner) — This is the root of Lattner's attraction to compilers and also explains why compiler engineers are so scarce.