[llvm] [llvm] Replace SmallSet with SmallPtrSet (NFC) (PR #154068)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 18 06:58:30 PDT 2025


kazutakahirata wrote:

> > Since relying on the redirection
> > doesn't improve readability, this patch replaces SmallSet with
> > SmallPtrSet for pointer element types.
> 
> I don't really understand the motivation. Why is writing `SmallPtrSet<T*>` _better_ than `SmallSet<T*>`? Are you planning to remove the redirection?

Yes, eventually.

> As an alternative, how about removing explicit use of SmallPtrSet and always relying on SmallSet being specialized for pointer types? (Or do they have different performance characteristics, so you might want to explicitly choose one or the other?)

`SmallPtrSet` and `SmallSet` have very different performance characteristics.  `SmallPtrSet` uses linear search up to some size and then switches to the `DenseMap`-style open address hash table.  `SmallSet` also uses linear search up to some size but then switches to `std::map` unless the data type is a pointer, in which case we redirect to `SmallPtrSet`.


https://github.com/llvm/llvm-project/pull/154068


More information about the llvm-commits mailing list