Data Structure and Iterator Kung Fu in LLVM
Practical patterns, zero-copy views, and safe mutation loops for faster LLVM passes. Table of Contents Why LLVM ships its own containers Core Value Types (which own nothing) StringRef ArrayRef / MutableArrayRef Twine Small-Size Optimized Containers SmallVector<T, N> SmallString SmallPtrSet<T*, N> “Hashy” Workhorses DenseMap<KeyT, ValueT> / DenseSet Custom Keys providing DenseMapInfo<Key> with: StringMap Erasing While Iterating Arenas, Uniquing, and more BumpPtrAllocator FoldingSet Error handling the LLVM way IR-Centric Must-Knows Traversal Idioms Mutation Safety CFG Helpers Range and Iterator (Halloween!) Candy Choosing the Right Data Structure (A Decision Matrix) Common “Shooting Yourself in the Foot” Pitfalls Micro-Benchmarks Compile and Run Conclusion When to use SmallVector vs std::vector, why DenseMap feels like cheating, how StringRef & ArrayRef avoid copies, and the iterator tricks that make LLVM code elegant and fast. ...