C++ Coroutines: Under the covers
summary
Shows how Clang lowers C++ coroutines to LLVM coroutine intrinsics and then, inside LLVM, splits a function into resume/destroy/initial pieces (a split into resume/destroy/initial transformation), uses inlining, SSA/SROA and devirtualization to elide heap allocations and inline away state, and demonstrates with a C generator and a take_until pipeline that O2 can make a coroutine disappear to a constant. Proposes a zero-overhead task/future design that keeps the promise in-frame, starts suspended, resumes callers at final suspend and avoids atomics and mutexes via heap elision.
AI-written summary · about
chapters (27)
- 0:00Title
- 0:30Magic act
- 2:27TakeUntil
- 5:17Debug
- 7:01Disassembly
- 9:39Compiler
- 11:48Superclasses
- 12:47C Coroutine
- 17:11Michelangelo
- 20:40Cleanup
- 24:15Inlining
- 24:37SRA
- 28:23Rocket joke
- 29:42Frontend optimizer
- 29:55optimizer
- 30:53coldgraph
- 31:40inliner
- 36:03heap allocation
- 37:11state of coroutines
- 39:27thanks
- 39:43future
- 40:27overhead
- 44:51result
- 45:54heap illusion
- 52:05more questions
- 52:40make optimization reliable
- 54:20is future implementation available online
related talks
58m“C++ Coroutines - a negative overhead abstraction"
01h 35mNo Compiler Required - Hand-Rolling C++20 Coroutines in C++17
48m“Coroutines: what can't they do?”
01h 20mCoroutines for Dummies
56mGenerators, Coroutines and Other Brain Unrolling Sweetness
01h 01mWhat We’ve Been Awaiting For? - How to Build a C++ Coroutine Type
31mGenerators, Coroutines and Other Brain Unrolling Sweetness
01h 05mImplementing async with coroutines and fibers - project Loom in C#
